pi-daddy 0.15.0 → 0.17.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.
- package/CHANGELOG.md +119 -0
- package/README.md +46 -12
- package/dist/chain.d.ts +94 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +161 -0
- package/dist/chain.js.map +1 -0
- package/dist/cli.js +0 -0
- package/dist/delegate.d.ts.map +1 -1
- package/dist/delegate.js +6 -2
- package/dist/delegate.js.map +1 -1
- package/dist/executor.d.ts +38 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +93 -0
- package/dist/executor.js.map +1 -0
- package/dist/fanout.d.ts +9 -0
- package/dist/fanout.d.ts.map +1 -1
- package/dist/fanout.js +9 -0
- package/dist/fanout.js.map +1 -1
- package/dist/herdr-cli.d.ts +78 -0
- package/dist/herdr-cli.d.ts.map +1 -0
- package/dist/herdr-cli.js +113 -0
- package/dist/herdr-cli.js.map +1 -0
- package/dist/herdr-name.d.ts +37 -0
- package/dist/herdr-name.d.ts.map +1 -0
- package/dist/herdr-name.js +59 -0
- package/dist/herdr-name.js.map +1 -0
- package/dist/herdr-poll.d.ts +104 -0
- package/dist/herdr-poll.d.ts.map +1 -0
- package/dist/herdr-poll.js +150 -0
- package/dist/herdr-poll.js.map +1 -0
- package/dist/herdr-stage.d.ts +40 -0
- package/dist/herdr-stage.d.ts.map +1 -0
- package/dist/herdr-stage.js +54 -0
- package/dist/herdr-stage.js.map +1 -0
- package/dist/ledger-report.d.ts +18 -0
- package/dist/ledger-report.d.ts.map +1 -1
- package/dist/ledger-report.js +10 -0
- package/dist/ledger-report.js.map +1 -1
- package/dist/ledger.d.ts +31 -0
- package/dist/ledger.d.ts.map +1 -1
- package/dist/ledger.js +2 -0
- package/dist/ledger.js.map +1 -1
- package/dist/pane-reaper.d.ts +66 -4
- package/dist/pane-reaper.d.ts.map +1 -1
- package/dist/pane-reaper.js +131 -9
- package/dist/pane-reaper.js.map +1 -1
- package/dist/progress.d.ts +96 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +167 -0
- package/dist/progress.js.map +1 -0
- package/dist/run-child.d.ts +27 -0
- package/dist/run-child.d.ts.map +1 -1
- package/dist/run-child.js +84 -7
- package/dist/run-child.js.map +1 -1
- package/dist/run-herdr.d.ts +41 -28
- package/dist/run-herdr.d.ts.map +1 -1
- package/dist/run-herdr.js +150 -167
- package/dist/run-herdr.js.map +1 -1
- package/extensions/delegate-chain.ts +357 -0
- package/extensions/delegation.ts +100 -2
- package/extensions/grants-command.ts +26 -1
- package/extensions/grants.ts +85 -163
- package/extensions/run-delegation.ts +130 -13
- package/extensions/session-report.ts +231 -0
- package/extensions/session.ts +63 -11
- package/extensions/tripwire.ts +44 -0
- package/package.json +21 -1
- package/src/chain.ts +174 -0
- package/src/delegate.ts +6 -2
- package/src/executor.ts +122 -0
- package/src/fanout.ts +10 -0
- package/src/herdr-cli.ts +125 -0
- package/src/herdr-name.ts +61 -0
- package/src/herdr-poll.ts +185 -0
- package/src/herdr-stage.ts +55 -0
- package/src/ledger-report.ts +21 -0
- package/src/ledger.ts +33 -0
- package/src/pane-reaper.ts +147 -9
- package/src/progress.ts +206 -0
- package/src/run-child.ts +96 -7
- package/src/run-herdr.ts +170 -174
package/dist/executor.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which executor runs a governed child — ADR-0031.
|
|
3
|
+
*
|
|
4
|
+
* `PI_GRANTS_HERDR` is three-state, and **absent means probe**. That reverses ADR-0016 point 6's opt-in, and
|
|
5
|
+
* the reversal is narrower than it sounds: nothing is detected from `herdr` being on `PATH` (option C, rejected
|
|
6
|
+
* by name), only from a server that *answered*. The grant, the depth bound, the gate and `--tools` enforcement
|
|
7
|
+
* are identical either way — `planSpawn` produces one plan and both executors enforce it.
|
|
8
|
+
*
|
|
9
|
+
* **Pure on purpose.** The probe is I/O and lives in `herdr-cli.ts`; the DECISION is a table, and a table that
|
|
10
|
+
* fits on one screen is the only reason a reversal like this is reviewable at all.
|
|
11
|
+
*
|
|
12
|
+
* The disclosure string is part of the return value rather than composed at the call site, because ADR-0031's
|
|
13
|
+
* defence against "this relocates silently" is that every outcome says what it chose AND what to set instead.
|
|
14
|
+
* Two call sites composing that separately is how one of them comes to omit it (R-28).
|
|
15
|
+
*/
|
|
16
|
+
export const ENV_HERDR = "PI_GRANTS_HERDR";
|
|
17
|
+
/** `0` is the one value that needs no probe: the operator ruled herdr out, so asking is pure cost. */
|
|
18
|
+
export function needsProbe(raw) {
|
|
19
|
+
return raw === undefined || raw === "1";
|
|
20
|
+
}
|
|
21
|
+
export function chooseExecutor(raw, probe) {
|
|
22
|
+
if (raw === "0") {
|
|
23
|
+
return {
|
|
24
|
+
kind: "process",
|
|
25
|
+
forced: true,
|
|
26
|
+
probed: false,
|
|
27
|
+
disclosure: "captured subprocess (PI_GRANTS_HERDR=0) — children have no terminal",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (raw === "1") {
|
|
31
|
+
if (probe?.ok) {
|
|
32
|
+
return { kind: "herdr", forced: true, probed: true, disclosure: "herdr panes (PI_GRANTS_HERDR=1)" };
|
|
33
|
+
}
|
|
34
|
+
// Refusal, not fallback — the operator's decision of 2026-08-17, against the alternative of falling back
|
|
35
|
+
// loudly. A fallback nobody reads is R-25's shape; refusing keeps the ledger unable to name a child that
|
|
36
|
+
// ran somewhere nobody chose. A `null` probe lands here too: if the probe failed so badly it produced no
|
|
37
|
+
// result, herdr was still demanded, and failing closed means refusing.
|
|
38
|
+
const why = probe?.error ?? "the herdr probe did not succeed";
|
|
39
|
+
return {
|
|
40
|
+
kind: "herdr",
|
|
41
|
+
forced: true,
|
|
42
|
+
probed: true,
|
|
43
|
+
refusal: `PI_GRANTS_HERDR=1 demands the herdr executor and herdr is not answering (${why}). ` +
|
|
44
|
+
`Delegation is refused rather than quietly relocated to a captured subprocess, so this session's ` +
|
|
45
|
+
`ledger can never contain a child that ran somewhere nobody chose. Start herdr, or unset ` +
|
|
46
|
+
`PI_GRANTS_HERDR to let this session probe, or set PI_GRANTS_HERDR=0 to choose subprocesses.`,
|
|
47
|
+
disclosure: `herdr panes DEMANDED but unreachable (${why}) — every delegation will refuse`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (raw !== undefined) {
|
|
51
|
+
// Rule 8: fail closed and be loud. An unrecognised value must not relocate a run, and must not break
|
|
52
|
+
// delegation either — the operator meant *something*, and the dependency-free executor is the safe read.
|
|
53
|
+
// The empty string lands here rather than with `undefined`, which keeps absent-versus-empty
|
|
54
|
+
// distinguishable exactly as `PI_GRANTS_GATED` does.
|
|
55
|
+
return {
|
|
56
|
+
kind: "process",
|
|
57
|
+
forced: false,
|
|
58
|
+
probed: probe !== null,
|
|
59
|
+
disclosure: `captured subprocess — PI_GRANTS_HERDR is set to an unrecognised value and was ignored. ` +
|
|
60
|
+
`Use 1 (demand herdr panes), 0 (demand subprocesses), or unset it to probe.`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (probe?.ok) {
|
|
64
|
+
return { kind: "herdr", forced: false, probed: true, disclosure: "herdr panes (probed — herdr is answering)" };
|
|
65
|
+
}
|
|
66
|
+
if (probe === null) {
|
|
67
|
+
// **The pre-probe seed, and it must not claim a probe happened.** `createGrantsSession` builds a choice
|
|
68
|
+
// synchronously with `probe: null` because S-5 forces the factory to run before any hook; `resolveExecutor`
|
|
69
|
+
// replaces it during `session_start`. This branch previously fell through to the one below and reported
|
|
70
|
+
// `probed: true` with the word "(probed)" in its disclosure — a fabricated observation, indistinguishable
|
|
71
|
+
// from a real negative probe.
|
|
72
|
+
//
|
|
73
|
+
// Unreachable in practice today (pi awaits the `session_start` emit before the first prompt, verified by a
|
|
74
|
+
// reviewer against real pi), which is exactly why it is worth making honest rather than leaving to be
|
|
75
|
+
// discovered: if a throw ever strands a session on this reading, the disclosure should say so.
|
|
76
|
+
return {
|
|
77
|
+
kind: "process",
|
|
78
|
+
forced: false,
|
|
79
|
+
probed: false,
|
|
80
|
+
disclosure: "not yet probed — settling at session start",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
kind: "process",
|
|
85
|
+
forced: false,
|
|
86
|
+
probed: true,
|
|
87
|
+
// Names the remedy on the same line as the state. The gap that produced ADR-0031 was not that the
|
|
88
|
+
// operator could not see which executor ran — it was that seeing it would not have told them what to do.
|
|
89
|
+
disclosure: `captured subprocess (probed — no herdr answering${probe?.error ? `: ${probe.error}` : ""}). ` +
|
|
90
|
+
`Set PI_GRANTS_HERDR=1 to demand panes.`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../src/executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,CAAC,MAAM,SAAS,GAAG,iBAAiB,CAAC;AAqB3C,sGAAsG;AACtG,MAAM,UAAU,UAAU,CAAC,GAAuB;IAChD,OAAO,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,GAAG,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,GAAuB,EAAE,KAAwB;IAC9E,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO;YACL,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,KAAK;YACb,UAAU,EAAE,qEAAqE;SAClF,CAAC;IACJ,CAAC;IAED,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,KAAK,EAAE,EAAE,EAAE,CAAC;YACd,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,iCAAiC,EAAE,CAAC;QACtG,CAAC;QACD,yGAAyG;QACzG,yGAAyG;QACzG,yGAAy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,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK;YAC9F,wCAAwC;KAC3C,CAAC;AACJ,CAAC"}
|
package/dist/fanout.d.ts
CHANGED
|
@@ -28,6 +28,15 @@ export declare const DEFAULT_FANOUT_BUDGET = 8;
|
|
|
28
28
|
* the total bound. Both are needed because they answer different questions.
|
|
29
29
|
*/
|
|
30
30
|
export declare const MAX_CHILDREN_PER_CALL = 8;
|
|
31
|
+
/**
|
|
32
|
+
* Steps a single `delegate_chain` may contain — ADR-0033.
|
|
33
|
+
*
|
|
34
|
+
* **Derived from `MAX_CHILDREN_PER_CALL` so the two cannot drift.** A chain is not concurrent, so the blast-radius
|
|
35
|
+
* argument for that constant does not apply directly; what does apply is that one tool call should not be able to
|
|
36
|
+
* create an unbounded number of descendants, and eight is already a long pipeline. Sharing the number also means an
|
|
37
|
+
* operator learns one bound rather than two.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MAX_CHAIN_STEPS = 8;
|
|
31
40
|
/** Read the budget from the environment, failing to the default on absent *or* malformed input. */
|
|
32
41
|
export declare function budgetFromEnv(raw: string | undefined): number;
|
|
33
42
|
export interface BudgetSplit {
|
package/dist/fanout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fanout.d.ts","sourceRoot":"","sources":["../src/fanout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAM7D;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAmBtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpE"}
|
|
1
|
+
{"version":3,"file":"fanout.d.ts","sourceRoot":"","sources":["../src/fanout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,oGAAoG;AACpG,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,IAAwB,CAAC;AAErD,mGAAmG;AACnG,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAM7D;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,CAmBtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEpE"}
|
package/dist/fanout.js
CHANGED
|
@@ -29,6 +29,15 @@ export const DEFAULT_FANOUT_BUDGET = 8;
|
|
|
29
29
|
* the total bound. Both are needed because they answer different questions.
|
|
30
30
|
*/
|
|
31
31
|
export const MAX_CHILDREN_PER_CALL = 8;
|
|
32
|
+
/**
|
|
33
|
+
* Steps a single `delegate_chain` may contain — ADR-0033.
|
|
34
|
+
*
|
|
35
|
+
* **Derived from `MAX_CHILDREN_PER_CALL` so the two cannot drift.** A chain is not concurrent, so the blast-radius
|
|
36
|
+
* argument for that constant does not apply directly; what does apply is that one tool call should not be able to
|
|
37
|
+
* create an unbounded number of descendants, and eight is already a long pipeline. Sharing the number also means an
|
|
38
|
+
* operator learns one bound rather than two.
|
|
39
|
+
*/
|
|
40
|
+
export const MAX_CHAIN_STEPS = MAX_CHILDREN_PER_CALL;
|
|
32
41
|
/** Read the budget from the environment, failing to the default on absent *or* malformed input. */
|
|
33
42
|
export function budgetFromEnv(raw) {
|
|
34
43
|
const parsed = parseBound(raw);
|
package/dist/fanout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fanout.js","sourceRoot":"","sources":["../src/fanout.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,oGAAoG;AACpG,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC,mGAAmG;AACnG,MAAM,UAAU,aAAa,CAAC,GAAuB;IACnD,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,wGAAwG;IACxG,sGAAsG;IACtG,yDAAyD;IACzD,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,MAAM,CAAC;AAClG,CAAC;AASD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,KAAa;IACvD,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,oCAAoC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAChG,IAAI,KAAK,GAAG,qBAAqB,EAAE,CAAC;QAClC,OAAO;YAC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qB,CAAC,CAAC,CAAC,MAAM,CAAC;AAClG,CAAC;AASD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,KAAa;IACvD,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,oCAAoC,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;IAChG,IAAI,KAAK,GAAG,qBAAqB,EAAE,CAAC;QAClC,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EAAE,GAAG,KAAK,2CAA2C,qBAAqB,EAAE;YAClF,QAAQ,EAAE,CAAC;SACZ,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,GAAG,KAAK,EAAE,CAAC;QACnB,OAAO;YACL,EAAE,EAAE,KAAK;YACT,MAAM,EACJ,6BAA6B,KAAK,wBAAwB,MAAM,6BAA6B;gBAC7F,mEAAmE;YACrE,QAAQ,EAAE,CAAC;SACZ,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;AACtE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,KAAa;IAC1D,OAAO,GAAG,QAAQ,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Talking to herdr: one command, one JSON envelope, plus the two questions ADR-0031 needs answered.
|
|
3
|
+
*
|
|
4
|
+
* Lifted out of `src/run-herdr.ts`, which was at 357 of the 400-line ceiling and gains output polling under
|
|
5
|
+
* ADR-0032. But the split is not only about lines: **the probe is not an executor concern**. It runs at session
|
|
6
|
+
* start, before any delegation exists, to decide *which* executor a session will use — so leaving it inside the
|
|
7
|
+
* herdr executor would mean the session imported the thing it was deciding whether to use.
|
|
8
|
+
*
|
|
9
|
+
* Every rule here is tested against an injected `exec`, so the suite stays fast, pi-free and herdr-free. The
|
|
10
|
+
* facts the fakes reproduce were measured against real herdr 0.7.5 (`docs/probes/g16-herdr`).
|
|
11
|
+
*/
|
|
12
|
+
/** One herdr CLI invocation. Injectable so every rule below is testable without herdr installed. */
|
|
13
|
+
export type HerdrExec = (args: string[]) => Promise<{
|
|
14
|
+
code: number | null;
|
|
15
|
+
stdout: string;
|
|
16
|
+
stderr: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const defaultExec: HerdrExec;
|
|
19
|
+
/**
|
|
20
|
+
* Parse herdr's JSON envelope. Every command replies `{id, result}` or `{id, error:{code,message}}`.
|
|
21
|
+
*
|
|
22
|
+
* `stderr` is folded into the message because the first end-to-end run failed with an EMPTY stdout and the
|
|
23
|
+
* real reason on stderr, producing the useless diagnostic "unparseable herdr reply: ". A wrapper that
|
|
24
|
+
* hides the substrate's own error message costs more time than it saves.
|
|
25
|
+
*/
|
|
26
|
+
export declare function parseReply(reply: {
|
|
27
|
+
stdout: string;
|
|
28
|
+
stderr: string;
|
|
29
|
+
}): {
|
|
30
|
+
result?: Record<string, unknown>;
|
|
31
|
+
error?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Bound on the session-start probe. Short: it sits in front of the operator's first prompt. */
|
|
34
|
+
export declare const PROBE_TIMEOUT_MS = 2000;
|
|
35
|
+
export interface HerdrProbe {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
/** herdr's own words when it is not reachable. Carried so the disclosure line can name the reason. */
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Is there a herdr server that will answer right now? — ADR-0031's selection input.
|
|
42
|
+
*
|
|
43
|
+
* **`tab list`, not `which herdr`.** ADR-0031 rejects `PATH` detection as option C by name: a binary on `PATH`
|
|
44
|
+
* with no server behind it would make every delegation fail at `tab create`, on a path the operator never
|
|
45
|
+
* chose, and the diagnostic would arrive at the first delegation rather than at startup. Only a parsed
|
|
46
|
+
* `result` envelope counts as reachable; an `error` envelope, a non-JSON reply, a timeout and a throwing
|
|
47
|
+
* `exec` are all "not reachable" with the reason preserved.
|
|
48
|
+
*
|
|
49
|
+
* **Zero tabs is a successful answer**, deliberately: a fresh herdr with nothing open is reachable.
|
|
50
|
+
*
|
|
51
|
+
* Never throws. A probe that threw out of `session_start` would cancel every control after it, which is
|
|
52
|
+
* R-60's shape exactly — and this one runs *before* the line that discloses what it decided.
|
|
53
|
+
*/
|
|
54
|
+
export declare function probeHerdr(options?: {
|
|
55
|
+
exec?: HerdrExec;
|
|
56
|
+
timeoutMs?: number;
|
|
57
|
+
}): Promise<HerdrProbe>;
|
|
58
|
+
/** herdr's own variable, set in every pane it creates. Measured 2026-08-17; documented nowhere. */
|
|
59
|
+
export declare const ENV_PARENT_WORKSPACE = "HERDR_WORKSPACE_ID";
|
|
60
|
+
/** The operator's explicit override. Defined here because this is the only module that reads it. */
|
|
61
|
+
export declare const ENV_HERDR_WORKSPACE = "PI_GRANTS_HERDR_WORKSPACE";
|
|
62
|
+
/**
|
|
63
|
+
* Which herdr workspace a governed child's pane belongs in.
|
|
64
|
+
*
|
|
65
|
+
* **Defaults to the parent's own workspace.** herdr tells a pane which workspace it is in
|
|
66
|
+
* (`HERDR_WORKSPACE_ID`, alongside `HERDR_TAB_ID` and `HERDR_PANE_ID`), and a child placed in a *different*
|
|
67
|
+
* workspace from the pi session that spawned it turns "switch between them" into a workspace hop — which is
|
|
68
|
+
* the entire feature ADR-0032 exists to deliver. The previous behaviour was "omitted lets herdr choose",
|
|
69
|
+
* which is that failure by default on any machine with more than one workspace.
|
|
70
|
+
*
|
|
71
|
+
* `PI_GRANTS_HERDR_WORKSPACE` still wins: it is the operator saying so explicitly, and an explicit answer
|
|
72
|
+
* beating an inference is this package's standing rule (ADR-0030 says it about the grant itself).
|
|
73
|
+
*
|
|
74
|
+
* Blank is treated as absent rather than passed through — `--workspace ""` is not a workspace, and it would
|
|
75
|
+
* fail `tab create` on a path nobody chose.
|
|
76
|
+
*/
|
|
77
|
+
export declare function resolveWorkspace(env: NodeJS.ProcessEnv): string | undefined;
|
|
78
|
+
//# sourceMappingURL=herdr-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"herdr-cli.d.ts","sourceRoot":"","sources":["../src/herdr-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,oGAAoG;AACpG,MAAM,MAAM,SAAS,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAE7G,eAAO,MAAM,WAAW,EAAE,SAatB,CAAC;AAEL;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAW1H;AAED,gGAAgG;AAChG,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,OAAO,CAAC;IACZ,sGAAsG;IACtG,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAsB5G;AAED,mGAAmG;AACnG,eAAO,MAAM,oBAAoB,uBAAuB,CAAC;AAEzD,oGAAoG;AACpG,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS,CAI3E"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Talking to herdr: one command, one JSON envelope, plus the two questions ADR-0031 needs answered.
|
|
3
|
+
*
|
|
4
|
+
* Lifted out of `src/run-herdr.ts`, which was at 357 of the 400-line ceiling and gains output polling under
|
|
5
|
+
* ADR-0032. But the split is not only about lines: **the probe is not an executor concern**. It runs at session
|
|
6
|
+
* start, before any delegation exists, to decide *which* executor a session will use — so leaving it inside the
|
|
7
|
+
* herdr executor would mean the session imported the thing it was deciding whether to use.
|
|
8
|
+
*
|
|
9
|
+
* Every rule here is tested against an injected `exec`, so the suite stays fast, pi-free and herdr-free. The
|
|
10
|
+
* facts the fakes reproduce were measured against real herdr 0.7.5 (`docs/probes/g16-herdr`).
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from "node:child_process";
|
|
13
|
+
export const defaultExec = (args) => new Promise((settle) => {
|
|
14
|
+
execFile("herdr", args, { maxBuffer: 32 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
15
|
+
const raw = error?.code;
|
|
16
|
+
const code = typeof raw === "number" ? raw : error ? 1 : 0;
|
|
17
|
+
// **A string `code` is a spawn failure, and it used to be thrown away.** `ENOENT` — herdr not installed —
|
|
18
|
+
// arrives as `code: "ENOENT"`, so the numeric test failed, the message was dropped, and an operator with
|
|
19
|
+
// `PI_GRANTS_HERDR=1` on a machine without herdr was told *"herdr is not answering (unparseable herdr
|
|
20
|
+
// reply: (no output))"* rather than that the binary is missing. Rule 8 wants the loud version, and this is
|
|
21
|
+
// the first diagnostic such an operator meets.
|
|
22
|
+
const spawnFailure = typeof raw === "string" ? `herdr could not be run (${raw}): ${error?.message ?? ""}` : "";
|
|
23
|
+
settle({ code, stdout: String(stdout), stderr: spawnFailure || String(stderr) });
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Parse herdr's JSON envelope. Every command replies `{id, result}` or `{id, error:{code,message}}`.
|
|
28
|
+
*
|
|
29
|
+
* `stderr` is folded into the message because the first end-to-end run failed with an EMPTY stdout and the
|
|
30
|
+
* real reason on stderr, producing the useless diagnostic "unparseable herdr reply: ". A wrapper that
|
|
31
|
+
* hides the substrate's own error message costs more time than it saves.
|
|
32
|
+
*/
|
|
33
|
+
export function parseReply(reply) {
|
|
34
|
+
try {
|
|
35
|
+
const parsed = JSON.parse(reply.stdout);
|
|
36
|
+
if (parsed.error)
|
|
37
|
+
return { error: parsed.error.message ?? parsed.error.code ?? "herdr reported an error" };
|
|
38
|
+
return { result: parsed.result };
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// A non-JSON reply is a herdr-version or PATH problem, not a governance decision. Surfaced as a spawn
|
|
42
|
+
// error so the caller reports "could not start" rather than "the child produced nothing".
|
|
43
|
+
const detail = [reply.stdout.trim(), reply.stderr.trim()].filter((t) => t.length > 0).join(" | ");
|
|
44
|
+
return { error: `unparseable herdr reply: ${detail.slice(0, 300) || "(no output)"}` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Bound on the session-start probe. Short: it sits in front of the operator's first prompt. */
|
|
48
|
+
export const PROBE_TIMEOUT_MS = 2000;
|
|
49
|
+
/**
|
|
50
|
+
* Is there a herdr server that will answer right now? — ADR-0031's selection input.
|
|
51
|
+
*
|
|
52
|
+
* **`tab list`, not `which herdr`.** ADR-0031 rejects `PATH` detection as option C by name: a binary on `PATH`
|
|
53
|
+
* with no server behind it would make every delegation fail at `tab create`, on a path the operator never
|
|
54
|
+
* chose, and the diagnostic would arrive at the first delegation rather than at startup. Only a parsed
|
|
55
|
+
* `result` envelope counts as reachable; an `error` envelope, a non-JSON reply, a timeout and a throwing
|
|
56
|
+
* `exec` are all "not reachable" with the reason preserved.
|
|
57
|
+
*
|
|
58
|
+
* **Zero tabs is a successful answer**, deliberately: a fresh herdr with nothing open is reachable.
|
|
59
|
+
*
|
|
60
|
+
* Never throws. A probe that threw out of `session_start` would cancel every control after it, which is
|
|
61
|
+
* R-60's shape exactly — and this one runs *before* the line that discloses what it decided.
|
|
62
|
+
*/
|
|
63
|
+
export async function probeHerdr(options = {}) {
|
|
64
|
+
const exec = options.exec ?? defaultExec;
|
|
65
|
+
const timeoutMs = options.timeoutMs ?? PROBE_TIMEOUT_MS;
|
|
66
|
+
let timer;
|
|
67
|
+
try {
|
|
68
|
+
return await Promise.race([
|
|
69
|
+
exec(["tab", "list"]).then((reply) => {
|
|
70
|
+
const parsed = parseReply(reply);
|
|
71
|
+
return parsed.error ? { ok: false, error: parsed.error } : { ok: true };
|
|
72
|
+
}),
|
|
73
|
+
new Promise((settle) => {
|
|
74
|
+
timer = setTimeout(() => settle({ ok: false, error: `probe timed out after ${timeoutMs}ms` }), timeoutMs);
|
|
75
|
+
}),
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
return { ok: false, error: String(error) };
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
// Cleared whichever branch won, so a fast probe does not hold the event loop open for the timeout's
|
|
83
|
+
// remainder — which would add up to two seconds to every `node --test` run of this file.
|
|
84
|
+
if (timer)
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/** herdr's own variable, set in every pane it creates. Measured 2026-08-17; documented nowhere. */
|
|
89
|
+
export const ENV_PARENT_WORKSPACE = "HERDR_WORKSPACE_ID";
|
|
90
|
+
/** The operator's explicit override. Defined here because this is the only module that reads it. */
|
|
91
|
+
export const ENV_HERDR_WORKSPACE = "PI_GRANTS_HERDR_WORKSPACE";
|
|
92
|
+
/**
|
|
93
|
+
* Which herdr workspace a governed child's pane belongs in.
|
|
94
|
+
*
|
|
95
|
+
* **Defaults to the parent's own workspace.** herdr tells a pane which workspace it is in
|
|
96
|
+
* (`HERDR_WORKSPACE_ID`, alongside `HERDR_TAB_ID` and `HERDR_PANE_ID`), and a child placed in a *different*
|
|
97
|
+
* workspace from the pi session that spawned it turns "switch between them" into a workspace hop — which is
|
|
98
|
+
* the entire feature ADR-0032 exists to deliver. The previous behaviour was "omitted lets herdr choose",
|
|
99
|
+
* which is that failure by default on any machine with more than one workspace.
|
|
100
|
+
*
|
|
101
|
+
* `PI_GRANTS_HERDR_WORKSPACE` still wins: it is the operator saying so explicitly, and an explicit answer
|
|
102
|
+
* beating an inference is this package's standing rule (ADR-0030 says it about the grant itself).
|
|
103
|
+
*
|
|
104
|
+
* Blank is treated as absent rather than passed through — `--workspace ""` is not a workspace, and it would
|
|
105
|
+
* fail `tab create` on a path nobody chose.
|
|
106
|
+
*/
|
|
107
|
+
export function resolveWorkspace(env) {
|
|
108
|
+
const explicit = env[ENV_HERDR_WORKSPACE]?.trim();
|
|
109
|
+
if (explicit)
|
|
110
|
+
return explicit;
|
|
111
|
+
return env[ENV_PARENT_WORKSPACE]?.trim() || undefined;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=herdr-cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"herdr-cli.js","sourceRoot":"","sources":["../src/herdr-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAK9C,MAAM,CAAC,MAAM,WAAW,GAAc,CAAC,IAAI,EAAE,EAAE,CAC7C,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;IACrB,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;QACjF,MAAM,GAAG,GAAI,KAAmC,EAAE,IAAI,CAAC;QACvD,MAAM,IAAI,GAAG,OAAO,GAAG,KA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I,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAED,mGAAmG;AACnG,MAAM,CAAC,MAAM,oBAAoB,GAAG,oBAAoB,CAAC;AAEzD,oGAAoG;AACpG,MAAM,CAAC,MAAM,mBAAmB,GAAG,2BAA2B,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAsB;IACrD,MAAM,QAAQ,GAAG,GAAG,CAAC,mBAAmB,CAAC,EAAE,IAAI,EAAE,CAAC;IAClD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,OAAO,GAAG,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming a herdr agent: the grammar herdr enforces, and uniqueness it does not.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `src/run-herdr.ts` at the 400-line ceiling, and a real seam: both rules below come from **herdr's
|
|
5
|
+
* own validation and lifecycle**, not from anything this package decides. Two shipping defects lived here, and
|
|
6
|
+
* both were invisible to every test because the unit fake accepts whatever name it is handed and the integration
|
|
7
|
+
* suite never reaches a real herdr spawn. They surfaced from two real spawns against the live daemon.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Make a herdr agent name that is **valid** and cannot collide with a live one.
|
|
11
|
+
*
|
|
12
|
+
* **Validity is a separate, PRE-EXISTING defect, and it is the more serious half.** Callers build a name as
|
|
13
|
+
* `${definition}-${childId}`, and a ledger child id is hierarchical — `d0.1`, `d0.1.2` (ADR-0008/F8). Those dots
|
|
14
|
+
* are **not in herdr's grammar**, so `agent start review-d0.1 …` is rejected with `invalid_agent_name`. Every
|
|
15
|
+
* `delegate({agent})` on the herdr path has therefore failed at `agent start` since the executor was written.
|
|
16
|
+
*
|
|
17
|
+
* Nothing could see it. The unit fake accepts any name it is handed, and the integration suite never reaches a
|
|
18
|
+
* real herdr spawn — so both were green while the feature could not work. It surfaced only by running two real
|
|
19
|
+
* spawns against the live daemon, which is the argument for doing that at all.
|
|
20
|
+
*
|
|
21
|
+
* **Measured, and a shipping defect without it.** herdr binds an agent name to its **tab**, and only closing
|
|
22
|
+
* the tab frees the name: a second `agent start` with a name still held returns
|
|
23
|
+
* `agent_name_taken: agent <name> is already used; … tab_id=…`. `herdr agent stop` does not exist (see
|
|
24
|
+
* `cleanup`), so nothing else releases it.
|
|
25
|
+
*
|
|
26
|
+
* Callers build a name from the definition and the ledger child id — and for a plain blocking `delegate` that
|
|
27
|
+
* id is **constant** (`d0.1`, index 0 of the session), so every delegation in a session asked for the same
|
|
28
|
+
* name. That was harmless while the pane closed at the end of each call. Once ADR-0032 kept panes alive to
|
|
29
|
+
* `agent_settled`, the **first** delegation of a turn worked and every later one failed with
|
|
30
|
+
* `agent_name_taken`, on the executor ADR-0031 had just made the default.
|
|
31
|
+
*
|
|
32
|
+
* Uniquified HERE rather than at the call site, so no caller can forget: the constraint belongs to herdr, and
|
|
33
|
+
* this module is the only thing that talks to herdr. The suffix is a counter rather than a random token so a
|
|
34
|
+
* pane label stays readable and reproducible within a run.
|
|
35
|
+
*/
|
|
36
|
+
export declare function uniqueAgentName(base: string): string;
|
|
37
|
+
//# sourceMappingURL=herdr-name.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"herdr-name.d.ts","sourceRoot":"","sources":["../src/herdr-name.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAaH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAapD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming a herdr agent: the grammar herdr enforces, and uniqueness it does not.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `src/run-herdr.ts` at the 400-line ceiling, and a real seam: both rules below come from **herdr's
|
|
5
|
+
* own validation and lifecycle**, not from anything this package decides. Two shipping defects lived here, and
|
|
6
|
+
* both were invisible to every test because the unit fake accepts whatever name it is handed and the integration
|
|
7
|
+
* suite never reaches a real herdr spawn. They surfaced from two real spawns against the live daemon.
|
|
8
|
+
*/
|
|
9
|
+
/** Monotonic within this process. See `uniqueAgentName`. */
|
|
10
|
+
let spawnSeq = 0;
|
|
11
|
+
/**
|
|
12
|
+
* herdr's agent-name grammar, measured from its own rejection message.
|
|
13
|
+
*
|
|
14
|
+
* `agent name must start with a lowercase letter and contain only lowercase letters, digits, '-' or '_'
|
|
15
|
+
* (1-32 characters)`.
|
|
16
|
+
*/
|
|
17
|
+
const AGENT_NAME_MAX = 32;
|
|
18
|
+
/**
|
|
19
|
+
* Make a herdr agent name that is **valid** and cannot collide with a live one.
|
|
20
|
+
*
|
|
21
|
+
* **Validity is a separate, PRE-EXISTING defect, and it is the more serious half.** Callers build a name as
|
|
22
|
+
* `${definition}-${childId}`, and a ledger child id is hierarchical — `d0.1`, `d0.1.2` (ADR-0008/F8). Those dots
|
|
23
|
+
* are **not in herdr's grammar**, so `agent start review-d0.1 …` is rejected with `invalid_agent_name`. Every
|
|
24
|
+
* `delegate({agent})` on the herdr path has therefore failed at `agent start` since the executor was written.
|
|
25
|
+
*
|
|
26
|
+
* Nothing could see it. The unit fake accepts any name it is handed, and the integration suite never reaches a
|
|
27
|
+
* real herdr spawn — so both were green while the feature could not work. It surfaced only by running two real
|
|
28
|
+
* spawns against the live daemon, which is the argument for doing that at all.
|
|
29
|
+
*
|
|
30
|
+
* **Measured, and a shipping defect without it.** herdr binds an agent name to its **tab**, and only closing
|
|
31
|
+
* the tab frees the name: a second `agent start` with a name still held returns
|
|
32
|
+
* `agent_name_taken: agent <name> is already used; … tab_id=…`. `herdr agent stop` does not exist (see
|
|
33
|
+
* `cleanup`), so nothing else releases it.
|
|
34
|
+
*
|
|
35
|
+
* Callers build a name from the definition and the ledger child id — and for a plain blocking `delegate` that
|
|
36
|
+
* id is **constant** (`d0.1`, index 0 of the session), so every delegation in a session asked for the same
|
|
37
|
+
* name. That was harmless while the pane closed at the end of each call. Once ADR-0032 kept panes alive to
|
|
38
|
+
* `agent_settled`, the **first** delegation of a turn worked and every later one failed with
|
|
39
|
+
* `agent_name_taken`, on the executor ADR-0031 had just made the default.
|
|
40
|
+
*
|
|
41
|
+
* Uniquified HERE rather than at the call site, so no caller can forget: the constraint belongs to herdr, and
|
|
42
|
+
* this module is the only thing that talks to herdr. The suffix is a counter rather than a random token so a
|
|
43
|
+
* pane label stays readable and reproducible within a run.
|
|
44
|
+
*/
|
|
45
|
+
export function uniqueAgentName(base) {
|
|
46
|
+
spawnSeq += 1;
|
|
47
|
+
const suffix = `-${spawnSeq}`;
|
|
48
|
+
const cleaned = base
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.replace(/[^a-z0-9_-]+/g, "-") // dots from a child id, and anything else outside the grammar
|
|
51
|
+
.replace(/-{2,}/g, "-")
|
|
52
|
+
.replace(/^[^a-z]+/, ""); // must START with a lowercase letter, so a leading digit or dash goes
|
|
53
|
+
// Truncated so the whole name fits, and trimmed of a trailing separator so the join stays readable. The
|
|
54
|
+
// fallback covers a base that sanitises to nothing at all (a definition named entirely in non-Latin script).
|
|
55
|
+
const room = AGENT_NAME_MAX - suffix.length;
|
|
56
|
+
const head = cleaned.slice(0, room).replace(/[-_]+$/, "") || "agent";
|
|
57
|
+
return `${head}${suffix}`;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=herdr-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"herdr-name.js","sourceRoot":"","sources":["../src/herdr-name.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,4DAA4D;AAC5D,IAAI,QAAQ,GAAG,CAAC,CAAC;AAEjB;;;;;GAKG;AACH,MAAM,cAAc,GAAG,EAAE,CAAC;AAE1B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,QAAQ,IAAI,CAAC,CAAC;IACd,MAAM,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,IAAI;SACjB,WAAW,EAAE;SACb,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC,8DAA8D;SAC5F,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,sEAAsE;IAClG,wGAAwG;IACxG,6GAA6G;IAC7G,MAAM,IAAI,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC;IACrE,OAAO,GAAG,IAAI,GAAG,MAAM,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Waiting for a herdr agent to settle, and reading what it printed on the way.
|
|
3
|
+
*
|
|
4
|
+
* Split out of `src/run-herdr.ts` when that file hit **404 of the 400-line ceiling** adding ADR-0032's output
|
|
5
|
+
* polling. The seam was named in the plan before it was needed, and it is a real one: this module is about
|
|
6
|
+
* *observing* an agent, `run-herdr.ts` is about *starting and cleaning up after* one. Nothing here creates or
|
|
7
|
+
* destroys anything.
|
|
8
|
+
*
|
|
9
|
+
* The two facts it is built on were measured against real herdr 0.7.5 (`docs/probes/g16-herdr`) and both are
|
|
10
|
+
* counter-intuitive enough to be worth the module comment: `agent wait --until idle` matches the state the
|
|
11
|
+
* agent was **already** in, and `agent read` is the one command that does **not** return a JSON envelope.
|
|
12
|
+
*/
|
|
13
|
+
import { type HerdrExec } from "./herdr-cli.ts";
|
|
14
|
+
/**
|
|
15
|
+
* What `waitForSettled` needs from a run request.
|
|
16
|
+
*
|
|
17
|
+
* Declared here rather than importing `HerdrRunRequest`, which would make the two modules mutually dependent
|
|
18
|
+
* for no benefit. `HerdrRunRequest` satisfies it structurally, so the call site needs no adapter.
|
|
19
|
+
*/
|
|
20
|
+
export interface PollTarget {
|
|
21
|
+
/** herdr agent name. */
|
|
22
|
+
name: string;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
/**
|
|
25
|
+
* The pane's last few lines, re-reported on every poll — a SNAPSHOT, not a stream (ADR-0032).
|
|
26
|
+
*
|
|
27
|
+
* The consumer must **replace** what it holds rather than append. `agent read` returns a snapshot of a
|
|
28
|
+
* bounded terminal, and treating it as append-only is what produced an 89,000× amplification; see
|
|
29
|
+
* `tailLines`.
|
|
30
|
+
*/
|
|
31
|
+
onSnapshot?: (lines: string[]) => void;
|
|
32
|
+
/** How many lines the display wants. Bounds the per-poll cost regardless of how big the pane is. */
|
|
33
|
+
snapshotLines?: number;
|
|
34
|
+
/** Poll cadence override. Exists so tests do not wait `POLL_INTERVAL_MS` per state transition. */
|
|
35
|
+
pollIntervalMs?: number;
|
|
36
|
+
}
|
|
37
|
+
/** How often to poll `agent get` while waiting for the child to settle. */
|
|
38
|
+
export declare const POLL_INTERVAL_MS = 750;
|
|
39
|
+
/** Lines of pane tail reported per poll. Matches the status block's own tail, so nothing is fetched unused. */
|
|
40
|
+
export declare const DEFAULT_SNAPSHOT_LINES = 3;
|
|
41
|
+
/**
|
|
42
|
+
* Wait for the child to settle, without accepting the state it was already in.
|
|
43
|
+
*
|
|
44
|
+
* **R-33, measured.** `herdr agent wait --until idle` called right after `agent prompt` returned
|
|
45
|
+
* *immediately*, matching the agent's **pre-existing** idle state with `state_change_seq` unchanged — a
|
|
46
|
+
* reply indistinguishable from a completed run. For fan-out that is not an inconvenience but a
|
|
47
|
+
* correctness bug: an orchestrator would "collect" N children that never ran and merge N empty results
|
|
48
|
+
* into a confident summary (R-03 with a new cause).
|
|
49
|
+
*
|
|
50
|
+
* So this polls `agent get` and requires **both** that the status is terminal **and** that
|
|
51
|
+
* `state_change_seq` has advanced past the value observed before prompting. `agent wait` is deliberately
|
|
52
|
+
* not used at all: its contract cannot express "settled *after* this point".
|
|
53
|
+
*/
|
|
54
|
+
export declare function waitForSettled(exec: HerdrExec, request: PollTarget, before: number, deadline: number, maxOutputBytes: number): Promise<{
|
|
55
|
+
status?: string;
|
|
56
|
+
timedOut?: boolean;
|
|
57
|
+
aborted?: boolean;
|
|
58
|
+
spawnError?: string;
|
|
59
|
+
}>;
|
|
60
|
+
/**
|
|
61
|
+
* The last `keep` non-blank lines of a pane snapshot — what the display actually needs.
|
|
62
|
+
*
|
|
63
|
+
* **This replaces a `newSuffix` diff, and the replacement is a correction rather than a tune-up.** The old
|
|
64
|
+
* design treated `agent read` as a *stream* and tried to report only what was new, by testing whether the new
|
|
65
|
+
* text extended the old. That is wrong about the substrate: `agent read` returns a **snapshot of a bounded
|
|
66
|
+
* terminal**, and a snapshot is not an append-only log. Two ordinary things break the prefix test forever —
|
|
67
|
+
* the pane **scrolling** (its top lines are gone, so the new text is not an extension of the old) and
|
|
68
|
+
* `readPane` **truncating to the tail** past `maxOutputBytes` (each read is a different window of a growing
|
|
69
|
+
* buffer). Once either happens, every poll reported the whole buffer.
|
|
70
|
+
*
|
|
71
|
+
* Measured before the fix: **51 MiB streamed for ~600 bytes of real output — 89,000× amplification** in 37
|
|
72
|
+
* seconds, per child, with a scrolling pane also delivering the same real lines three times each. The old
|
|
73
|
+
* docstring named that exact failure as the thing it prevented.
|
|
74
|
+
*
|
|
75
|
+
* So the herdr path now reports a **bounded snapshot** and the consumer *replaces* rather than appends. There
|
|
76
|
+
* is no diff to get wrong, the per-poll cost is `keep` lines regardless of buffer size, and a scrolling pane
|
|
77
|
+
* simply shows its current tail — which is what a human looking at that pane would see.
|
|
78
|
+
*/
|
|
79
|
+
export declare function tailLines(snapshot: string, keep: number): string[];
|
|
80
|
+
/**
|
|
81
|
+
* Read the pane's contents.
|
|
82
|
+
*
|
|
83
|
+
* `agent read` is the ONE command that does not return herdr's JSON envelope — it writes the terminal's
|
|
84
|
+
* text straight to stdout. Running it through `parseReply` turned every successful read into
|
|
85
|
+
* "unparseable herdr reply", i.e. reported the child's actual answer as a failure to read it. Found by the
|
|
86
|
+
* end-to-end run; the unit fake had been written to the envelope shape and so agreed with the bug.
|
|
87
|
+
*
|
|
88
|
+
* A JSON envelope is still accepted first, because an `error` reply here IS JSON and must not be mistaken
|
|
89
|
+
* for terminal output.
|
|
90
|
+
*
|
|
91
|
+
* **`readFailed` is separate from `text`, and that separation is the fix for an R-03 defect.** A failed read
|
|
92
|
+
* used to return its own diagnostic *as* `text` — so `runHerdrPane` returned
|
|
93
|
+
* `[grants] could not read the agent pane: pane is gone` **as the child's answer, with `code: 0`**, and the
|
|
94
|
+
* orchestrator read a failure message as a completed sub-agent's report. Measured. It mattered little when this
|
|
95
|
+
* ran once per child; ADR-0032 made it run on every poll, up to 800 times for a ten-minute child, so a
|
|
96
|
+
* transient failure went from unlikely to expected. The caller must now decide, and it cannot do so by
|
|
97
|
+
* inspecting a string.
|
|
98
|
+
*/
|
|
99
|
+
export declare function readPane(exec: HerdrExec, name: string, maxOutputBytes: number): Promise<{
|
|
100
|
+
text: string;
|
|
101
|
+
truncated: boolean;
|
|
102
|
+
readFailed?: string;
|
|
103
|
+
}>;
|
|
104
|
+
//# sourceMappingURL=herdr-poll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"herdr-poll.d.ts","sourceRoot":"","sources":["../src/herdr-poll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAc,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,wBAAwB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,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