Past (Perfect Continuous)

ref – https://www.natterandramble.co.uk/past-perfect-continuous-timeline-form-uses/

[had] + [been] + [present participle]

The past perfect continuous tense is used just like the past (perfect), except it describes ongoing actions that happened in the past instead of a one-time occurence. It’s often used with the words when, until, and before to connect it to another past action.

The past perfect continuous is a verb tense that indicates something that

began in the past, continued in the past, and also ended at a defined point in the past

note:

The past perfect tense uses the past participle—in this case, been—with the word had. Unlike the present perfect tense, the word had is used regardless of what the subject is.

For example, had been is correct in both of these sentences despite the fact that one sentence has a singular subject and the other has a plural subject:

The cat had been quiet all morning.
The cats had been quiet all morning.

It is combined with the present participle of verbs to form the past perfect continuous tense. For example:

By the time I arrived, they had been [waiting for hours] (present particple of verb ‘wait’).

Other Examples

[He had been drinking milk out the carton] when [Mom walked into the kitchen].

Both
His milk drinking began in the past, continued in the past, and ended at a defined point in the past when his Mom walked into the kitchen.

I [had] [been] [working at the company] for five years when I got the promotion.

He began workking at the compnay, continued in the past, and ended that line of work when he got the promotion.

Before he got his first job as a writer, he [had] [been] [working as a proofreader].

He began as a proofreader, continued in the past, and ended at a defined point in the past when he got his job as a writer.

I [had] [been] [living on my friend’s couch] for a year until they kicked me out.

The person began living at his friend’s couch, continued in the past, and ended in the past, when they kicked him out.

We [had] [been] [trying to open the door] for five minutes when Jane found her key

We tried opening the door in the past, continued in the past, and ended in the past when Jane found her keys.

It [had] [been] [raining hard] for several hours and the streets were very wet.

It started to rain, continued to rain, and after several hours, it stopped raining. Due to this, the streets were very wet.

Her friends [had] [been] [thinking of calling the police] when she walked in.

Her friends considered calling the police, which started in the past, continued in the past, and ended in the past at the exact point when she walked in.