run402 4.20.0 → 4.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `waitFor` — the one poll loop (attention-architecture Wave E).
3
+ *
4
+ * Every wait on this platform is the same shape: fetch a fact, ask whether it
5
+ * has reached the state you need, sleep, repeat, stop at a deadline. Before
6
+ * this helper the shape was hand-rolled three times (escalations'
7
+ * `raiseAndWait`, the CLI's `--wait`, room catch-up polling), and each copy
8
+ * had to re-decide the one contract that matters:
9
+ *
10
+ * **Silence is an answer.** On timeout, `waitFor` RETURNS the last observed
11
+ * state — it never throws. A thrown timeout invites `catch`-and-proceed,
12
+ * which quietly converts "nobody answered" into consent. Returning the
13
+ * still-unsettled state forces the caller to look at it and decide, with
14
+ * "nothing happened" as a visible input rather than an exception it
15
+ * swallowed. (This is the same reason an exhausted escalation rests OPEN and
16
+ * a deploy gate must not auto-approve on timeout.)
17
+ */
18
+ export interface WaitForOptions {
19
+ /** Delay between polls. Clamped to ≥1s so a tight loop cannot hammer the API. */
20
+ pollMs?: number;
21
+ /** Total budget. When it elapses, the LAST OBSERVED state is returned. */
22
+ timeoutMs?: number;
23
+ /**
24
+ * Called after each poll with the latest state — progress reporting
25
+ * (a CLI prints to stderr here) without owning the loop.
26
+ */
27
+ onPoll?: (state: unknown, elapsedMs: number) => void;
28
+ }
29
+ export interface WaitForResult<T> {
30
+ state: T;
31
+ /** True when `predicate` accepted `state`; false means the wait timed out. */
32
+ settled: boolean;
33
+ elapsedMs: number;
34
+ polls: number;
35
+ }
36
+ /**
37
+ * Poll `fetch` until `predicate(state)` is true or the timeout elapses.
38
+ *
39
+ * The initial state is fetched immediately (a wait that starts already
40
+ * settled costs one call and zero sleeps). A `fetch` rejection propagates —
41
+ * an API failure is not silence and must not be mistaken for it.
42
+ */
43
+ export declare function waitFor<T>(fetchState: () => Promise<T>, predicate: (state: T) => boolean, opts?: WaitForOptions): Promise<WaitForResult<T>>;
44
+ //# sourceMappingURL=wait.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.d.ts","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,cAAc;IAC7B,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACtD;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,CAAC;IACT,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAC7B,UAAU,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC5B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,EAChC,IAAI,GAAE,cAAmB,GACxB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAsB3B"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * `waitFor` — the one poll loop (attention-architecture Wave E).
3
+ *
4
+ * Every wait on this platform is the same shape: fetch a fact, ask whether it
5
+ * has reached the state you need, sleep, repeat, stop at a deadline. Before
6
+ * this helper the shape was hand-rolled three times (escalations'
7
+ * `raiseAndWait`, the CLI's `--wait`, room catch-up polling), and each copy
8
+ * had to re-decide the one contract that matters:
9
+ *
10
+ * **Silence is an answer.** On timeout, `waitFor` RETURNS the last observed
11
+ * state — it never throws. A thrown timeout invites `catch`-and-proceed,
12
+ * which quietly converts "nobody answered" into consent. Returning the
13
+ * still-unsettled state forces the caller to look at it and decide, with
14
+ * "nothing happened" as a visible input rather than an exception it
15
+ * swallowed. (This is the same reason an exhausted escalation rests OPEN and
16
+ * a deploy gate must not auto-approve on timeout.)
17
+ */
18
+ /**
19
+ * Poll `fetch` until `predicate(state)` is true or the timeout elapses.
20
+ *
21
+ * The initial state is fetched immediately (a wait that starts already
22
+ * settled costs one call and zero sleeps). A `fetch` rejection propagates —
23
+ * an API failure is not silence and must not be mistaken for it.
24
+ */
25
+ export async function waitFor(fetchState, predicate, opts = {}) {
26
+ const pollMs = Math.max(opts.pollMs ?? 30_000, 1_000);
27
+ const timeoutMs = opts.timeoutMs ?? 60 * 60 * 1000;
28
+ const startedAt = Date.now();
29
+ let polls = 1;
30
+ let state = await fetchState();
31
+ opts.onPoll?.(state, Date.now() - startedAt);
32
+ while (!predicate(state) && Date.now() - startedAt + pollMs <= timeoutMs) {
33
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
34
+ polls++;
35
+ state = await fetchState();
36
+ opts.onPoll?.(state, Date.now() - startedAt);
37
+ }
38
+ return {
39
+ state,
40
+ settled: predicate(state),
41
+ elapsedMs: Date.now() - startedAt,
42
+ polls,
43
+ };
44
+ }
45
+ //# sourceMappingURL=wait.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.js","sourceRoot":"","sources":["../src/wait.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAsBH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,UAA4B,EAC5B,SAAgC,EAChC,OAAuB,EAAE;IAEzB,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,EAAE,KAAK,CAAC,CAAC;IACtD,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IACnD,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,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