@staix/agent-hub 0.43.0 → 0.45.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +3 -8
  3. package/docs/agent-notes/adapters.md +2 -2
  4. package/docs/agent-notes/daemon.md +4 -4
  5. package/docs/agent-notes/local-worker.md +2 -1
  6. package/docs/agent-notes/security-review.md +1 -1
  7. package/docs/agent-notes/tasks.md +5 -2
  8. package/docs/agent-notes/tests.md +4 -3
  9. package/docs/design/adapters.md +4 -2
  10. package/docs/design/agent-hub-architecture.md +2 -0
  11. package/docs/design/agent-hub.md +1 -1
  12. package/docs/design/roadmap.md +75 -2
  13. package/docs/design/supervision.md +34 -2
  14. package/docs/design/task-board.md +36 -2
  15. package/docs/dogfood.md +20 -5
  16. package/docs/events.md +9 -3
  17. package/docs/influences.md +7 -0
  18. package/docs/memory.md +4 -4
  19. package/docs/operations.md +84 -31
  20. package/docs/quickstart.md +14 -2
  21. package/docs/research.md +18 -0
  22. package/docs/roadmap.json +4 -0
  23. package/docs/roadmap.md +9 -0
  24. package/docs/sdlc.md +19 -4
  25. package/docs/security.md +4 -4
  26. package/docs/verification/2026-11-11-supervision-pilot-1221.md +864 -0
  27. package/docs/verification/2026-11-19-0.44.0.md +60 -0
  28. package/docs/verification/2026-11-19-claude-implementer-2.1.328.md +49 -0
  29. package/docs/verification/2026-11-20-claude-implementer-2.1.329.md +49 -0
  30. package/docs/verification/2026-11-20-sdlc-metrics-diagnosis.md +7 -0
  31. package/docs/verification/2026-11-21-0.45.0.md +69 -0
  32. package/docs/verification/2026-11-22-codex-0171-reviewer-isolation.md +47 -0
  33. package/docs/verified.json +32 -26
  34. package/package.json +2 -2
  35. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  36. package/plugins/agent-hub/kimi-hook.js +585 -264
  37. package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
  38. package/plugins/agent-hub/server.js +629 -293
  39. package/scripts/check-docs.mjs +9 -1
  40. package/src/adapters/acp.ts +11 -1
  41. package/src/adapters/compat.ts +3 -3
  42. package/src/adapters/definitions/builtin-metadata.ts +2 -2
  43. package/src/adapters/definitions/native-context.ts +10 -0
  44. package/src/adapters/jcode.ts +10 -0
  45. package/src/adapters/local-worker.ts +3 -2
  46. package/src/adapters/pi.ts +15 -4
  47. package/src/cli/console-state.ts +3 -1
  48. package/src/cli/help.ts +3 -1
  49. package/src/cli/identity.ts +2 -1
  50. package/src/cli/main.ts +12 -6
  51. package/src/cli/output.ts +2 -2
  52. package/src/cli/recovery-package.ts +16 -3
  53. package/src/cli/roadmap-write.ts +59 -0
  54. package/src/cli/roadmap.ts +81 -4
  55. package/src/cli/sdlc-output.ts +11 -1
  56. package/src/cli/upgrade-runtime.ts +10 -6
  57. package/src/cli/upgrade.ts +9 -3
  58. package/src/hub/agent-mem-range.ts +43 -0
  59. package/src/hub/board.ts +116 -2
  60. package/src/hub/bus.ts +4 -0
  61. package/src/hub/check-runner.ts +25 -1
  62. package/src/hub/claude-shell-wrapper.ts +2 -1
  63. package/src/hub/config-apply.ts +4 -2
  64. package/src/hub/config-trust.ts +1 -1
  65. package/src/hub/context-window.ts +1 -1
  66. package/src/hub/control-write-trace.ts +39 -2
  67. package/src/hub/cost-governance.ts +11 -7
  68. package/src/hub/daemon.ts +318 -53
  69. package/src/hub/dogfood-read.ts +4 -2
  70. package/src/hub/edit-guard.ts +100 -0
  71. package/src/hub/events.ts +79 -8
  72. package/src/hub/facts.ts +85 -2
  73. package/src/hub/hub-tools.ts +3 -1
  74. package/src/hub/lifecycle.ts +6 -1
  75. package/src/hub/log-rotation.ts +130 -0
  76. package/src/hub/memory-profile.ts +137 -21
  77. package/src/hub/no-writes.ts +1 -0
  78. package/src/hub/operational-authority.ts +3 -2
  79. package/src/hub/operational-settings.ts +2 -2
  80. package/src/hub/quota-events.ts +40 -0
  81. package/src/hub/recovery-store.ts +70 -24
  82. package/src/hub/report.ts +1 -1
  83. package/src/hub/research-experiments.ts +132 -0
  84. package/src/hub/research-quality.ts +13 -3
  85. package/src/hub/research-record.ts +38 -2
  86. package/src/hub/research.ts +128 -28
  87. package/src/hub/restart.ts +49 -2
  88. package/src/hub/roadmap-check.ts +65 -0
  89. package/src/hub/roadmap-decompose.ts +80 -0
  90. package/src/hub/roadmap-export.ts +27 -0
  91. package/src/hub/roadmap-sync.ts +97 -0
  92. package/src/hub/roadmap.ts +40 -0
  93. package/src/hub/runtime-capture-prune.ts +9 -1
  94. package/src/hub/runtime-prune-health.ts +5 -1
  95. package/src/hub/sdlc-branch-ci.ts +128 -0
  96. package/src/hub/sdlc-merge.ts +12 -5
  97. package/src/hub/sdlc-metrics.ts +33 -10
  98. package/src/hub/sdlc.ts +90 -10
  99. package/src/hub/settings.ts +1 -0
  100. package/src/hub/snapshots.ts +56 -1
  101. package/src/hub/startup-event-seeds.ts +21 -15
  102. package/src/hub/startup-timing.ts +3 -1
  103. package/src/hub/supervision-proposals.ts +10 -2
  104. package/src/hub/supervision-rules.ts +27 -4
  105. package/src/hub/supervision.ts +7 -0
  106. package/src/hub/task-pr.ts +47 -0
  107. package/src/hub/task-shell-command.ts +124 -0
  108. package/src/hub/task-worktree.ts +18 -11
  109. package/src/hub/tasks.ts +617 -45
  110. package/src/hub/usage-rollup.ts +35 -20
  111. package/src/hub/worktree-shelf.ts +2 -1
  112. package/src/local/sandbox.ts +2 -1
  113. package/src/local/shell-environment.ts +6 -0
  114. package/src/local/tools.ts +13 -1
  115. package/src/memory/brief.ts +10 -1
  116. package/src/memory/client.ts +3 -2
  117. package/src/pi/extension.ts +15 -3
  118. package/src/pi/tool-receipts.ts +26 -0
@@ -83,3 +83,127 @@ export function taskShellCommand(command: unknown, binding: TaskShellBinding): T
83
83
  const file = flags.get("--body-file")!;
84
84
  return literalPath(file) ? result("pr-create", "gh", [file]) : undefined;
85
85
  }
86
+
87
+ export interface ShellWriteClass { kind: "write" | "read" | "unknown"; targets: string[] }
88
+
89
+ const SINK = /^(?:\/dev\/(?:null|stdout|stderr|tty)|&\d+|-)$/;
90
+ const unq = (w: string) => w.replace(/^(['"])(.*)\1$/, "$2");
91
+
92
+ /** Words of one simple command, quotes kept whole (a quoted `>` is not a redirection). */
93
+ function words(cmd: string): string[] | undefined {
94
+ const out: string[] = [];
95
+ let cur = "", q = "";
96
+ for (const c of cmd) {
97
+ if (q) { cur += c; if (c === q) q = ""; continue; }
98
+ if (c === "'" || c === '"') { q = c; cur += c; continue; }
99
+ if (/\s/.test(c)) { if (cur) out.push(cur), (cur = ""); continue; }
100
+ if (c === "`" || c === "$") return undefined; // substitution: not guessed
101
+ if (c === ">" && cur && !/^\d+$/.test(cur) && !/[>&]$/.test(cur)) { out.push(cur); cur = ""; } // `echo hi>f`: the redirection is its own word
102
+ cur += c;
103
+ }
104
+ if (q) return undefined;
105
+ if (cur) out.push(cur);
106
+ return out;
107
+ }
108
+
109
+ const CODE_RUNNER = /(?:^|[\s|;&(])(?:sh|bash|zsh|dash|ksh|python[\d.]*|node|bun|deno|ruby|perl|php)(?:\s|$)/;
110
+
111
+ /**
112
+ * One quote-aware pass: split only at unquoted newline, `;`, `&&`, `||` and `|`, and find `<<WORD` only outside quotes.
113
+ * A heredoc body is data and is skipped, unless its start line runs a shell or interpreter (then it is code) or it
114
+ * never ends: both are unknown. Unbalanced quotes are unknown too.
115
+ */
116
+ function segment(command: string): { parts: string[]; unknown: boolean } {
117
+ const parts: string[] = [];
118
+ let cur = "", q = "", unknown = false, lineStart = 0;
119
+ const heredocs: { word: string; strip: boolean }[] = [];
120
+ const push = () => { if (cur.trim()) parts.push(cur); cur = ""; };
121
+ for (let i = 0; i < command.length; i++) {
122
+ const c = command[i]!;
123
+ if (q) {
124
+ cur += c;
125
+ if (c === "\\" && q === '"' && i + 1 < command.length) cur += command[++i]!;
126
+ else if (c === q) q = "";
127
+ continue;
128
+ }
129
+ if (c === "\\" && i + 1 < command.length) { cur += c + command[++i]!; continue; }
130
+ if (c === "'" || c === '"') { q = c; cur += c; continue; }
131
+ if (c === "<" && command[i + 1] === "<" && command[i + 2] !== "<") {
132
+ const m = /^<<(-?)[ \t]*(?:'([^']+)'|"([^"]+)"|([A-Za-z_][A-Za-z0-9_]*))/.exec(command.slice(i));
133
+ if (m) { heredocs.push({ word: (m[2] ?? m[3] ?? m[4])!, strip: m[1] === "-" }); cur += " "; i += m[0].length - 1; continue; }
134
+ unknown = true; cur += c; continue;
135
+ }
136
+ if (c === "\n") {
137
+ const line = command.slice(lineStart, i);
138
+ push();
139
+ if (heredocs.length) {
140
+ if (CODE_RUNNER.test(line)) unknown = true;
141
+ for (const h of heredocs) {
142
+ let ended = false;
143
+ while (i + 1 < command.length) {
144
+ const end = command.indexOf("\n", i + 1);
145
+ const text = command.slice(i + 1, end < 0 ? command.length : end);
146
+ i = end < 0 ? command.length : end;
147
+ if ((h.strip ? text.replace(/^\t+/, "") : text) === h.word) { ended = true; break; }
148
+ }
149
+ if (!ended) unknown = true;
150
+ }
151
+ heredocs.length = 0;
152
+ }
153
+ lineStart = i + 1;
154
+ continue;
155
+ }
156
+ if (c === ";") { push(); continue; }
157
+ if ((c === "&" || c === "|") && command[i + 1] === c) { push(); i++; continue; }
158
+ if (c === "|") { push(); continue; }
159
+ cur += c;
160
+ }
161
+ if (q) unknown = true;
162
+ if (heredocs.length) { unknown = true; if (CODE_RUNNER.test(command.slice(lineStart))) unknown = true; }
163
+ push();
164
+ return { parts, unknown };
165
+ }
166
+
167
+ /**
168
+ * Pure classifier of in-place shell writes (#1556 T1, observation only). A write is named only when certain;
169
+ * anything it cannot parse is unknown, never a guess. Targets under /tmp or /dev sinks are not worktree writes.
170
+ */
171
+ export function classifyShellWrite(command: string): ShellWriteClass {
172
+ const targets: string[] = [];
173
+ const seg = segment(command);
174
+ let unknown = seg.unknown;
175
+ for (const part of seg.parts) {
176
+ const w = words(part);
177
+ if (!w) { unknown = true; continue; }
178
+ for (let i = 0; i < w.length; i++) {
179
+ const m = /^(\d*)(>>?|&>>?)(.*)$/.exec(w[i]!);
180
+ if (!m || w[i]!.startsWith("'") || w[i]!.startsWith('"')) continue;
181
+ const t = unq(m[3] || w[++i] || "");
182
+ if (!t || SINK.test(t) || /^>?&\d*$/.test(m[3] ?? "") || /^&/.test(t)) continue;
183
+ targets.push(t);
184
+ }
185
+ const args = w.filter((x) => !/^\d*(>>?|&>>?)/.test(x));
186
+ const head = args[0] === "sudo" || args[0] === "env" ? args.slice(1) : args;
187
+ const [c, ...rest] = head;
188
+ const files = rest.filter((x) => !x.startsWith("-")).map(unq);
189
+ if (!c) continue;
190
+ if (c === "sed" && rest.some((x) => /^-[a-zA-Z]*i/.test(x) || x.startsWith("--in-place"))) {
191
+ // -e/-f/--expression make every positional a file; an unusual suffix form is not guessed: unknown, never a wrong target.
192
+ if (rest.some((x) => /^-[a-zA-Z]*[ef]/.test(x) || x.startsWith("--expression") || x.startsWith("--file"))) unknown = true;
193
+ else targets.push(...files.filter((x) => x !== "").slice(1));
194
+ }
195
+ else if (c === "perl" && rest.some((x) => /^-[a-zA-Z]*i/.test(x))) targets.push(...files.slice(1));
196
+ else if (c === "awk" && rest.includes("inplace") && rest.includes("-i")) targets.push(...files.slice(1).filter((x) => x !== "inplace"));
197
+ else if (c === "tee") targets.push(...files);
198
+ else if (c === "dd") { for (const x of rest) if (x.startsWith("of=")) targets.push(unq(x.slice(3))); }
199
+ else if (c === "cp" || c === "mv" || c === "install") { if (files.length) targets.push(files[files.length - 1]!); }
200
+ else if (c === "patch") targets.push(...files);
201
+ else if (c === "git" && rest[0] === "apply" && !rest.includes("--check")) targets.push("(git apply)");
202
+ else if (/^(python3?|node|bun|ruby|perl)$/.test(c) && rest.some((x) => x === "-c" || x === "-e")) {
203
+ if (/write_text|write\(|writeFile|fs\.write|open\([^)]*['"][wa]|File\.write/.test(part)) unknown = true;
204
+ }
205
+ }
206
+ const real = targets.filter((t) => !/^\/(?:tmp|private\/tmp|var\/folders)\//.test(t));
207
+ if (real.length) return { kind: "write", targets: real };
208
+ return { kind: unknown ? "unknown" : "read", targets: [] };
209
+ }
@@ -13,7 +13,7 @@ import type { DependencyPreparation } from "../pi/task-dependencies.ts";
13
13
  /**
14
14
  * #1115: a hub-sandboxed peer (Pi, the local worker) cannot run `git worktree add` or commit, because its profile refuses `.git` writes that
15
15
  * matter (#270). The hub makes the task worktree for it at the fixed root `.worktrees/<peer>-<task>`, the peer edits files there, and the hub
16
- * stages, commits and pushes at `hub_task_done`. The sandbox profile is NOT changed. It already lets a sandboxed command write
16
+ * stages, commits and pushes at `hub_task_done` or before an isolated check. The sandbox profile is NOT changed. It already lets a sandboxed command write
17
17
  * `.git/worktrees/<name>/{HEAD,index}` and `.git/refs/heads` (#864 only closes config, hooks, commondir and packs), so this module never trusts
18
18
  * what the peer could have written there: the base commit is recorded at creation, and a hub commit needs the worktree still registered at
19
19
  * its path, HEAD still the task branch, and the branch tip still the recorded base (or the hub's own previous commit).
@@ -31,7 +31,7 @@ export const taskWorktreeBranch = (peer: PeerId, task: number): string => `task/
31
31
  export interface TaskWorktreeEntry { peer: string; task: number; path: string; branch: string; base: string; /** The hub's own last commit on the branch, once it made one. */ head?: string }
32
32
  export type TaskWorktreeAvailability = { ok: true } | { ok: false; reason: string; next: string };
33
33
  export type TaskWorktreeResult = { ok: true; path: string; branch: string; base: string; created: boolean } | { ok: false; reason: string };
34
- export type TaskWorktreeCommit = { ok: true; commit: string; branch: string; pushed: boolean; note?: string } | { ok: false; reason: string; commit?: string };
34
+ export type TaskWorktreeCommit = { ok: true; commit: string; branch: string; pushed: boolean; note?: string } | { ok: false; reason: string; commit?: string; uncertain?: true };
35
35
  export interface TaskWorktreeRemoval { removed: boolean; branchDeleted: boolean; kept?: string }
36
36
 
37
37
  export interface TaskWorktreePort {
@@ -43,7 +43,7 @@ export interface TaskWorktreePort {
43
43
  prepareDependencies?(input: { peer: PeerId; task: number; current: () => boolean }): Promise<void>;
44
44
  preparesDependencies?(peer: PeerId): boolean;
45
45
  dependencyState?(peer: PeerId, task: number): DependencyPreparation | undefined;
46
- commitAndPush(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit>;
46
+ commitAndPush(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit>;
47
47
  remove(input: { peer: PeerId; task: number }): TaskWorktreeRemoval;
48
48
  }
49
49
 
@@ -255,16 +255,19 @@ export class TaskWorktrees implements TaskWorktreePort {
255
255
  return { ok: true, path, branch, base, created: true };
256
256
  }
257
257
 
258
- /** One hub commit at a time per worktree: a repeated or parallel `hub_task_done` queues behind the first. */
259
- commitAndPush(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit> {
258
+ /** One hub commit at a time per worktree: a repeated or parallel check or `hub_task_done` queues behind the first. */
259
+ commitAndPush(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit> {
260
260
  const next = this.chain.then(() => this.commit(input), () => this.commit(input));
261
261
  this.chain = next.catch(() => undefined);
262
262
  return next;
263
263
  }
264
264
 
265
- private async commit(input: { peer: PeerId; task: number; title: string }): Promise<TaskWorktreeCommit> {
265
+ private async commit(input: { peer: PeerId; task: number; title: string; current?: () => boolean }): Promise<TaskWorktreeCommit> {
266
266
  const { peer, task } = input;
267
- const fail = (reason: string, commit?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(commit ? { commit } : {}) });
267
+ const current = () => !input.current || input.current();
268
+ let uncertain = false;
269
+ const fail = (reason: string, commit?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(commit ? { commit } : {}), ...(uncertain ? { uncertain: true as const } : {}) });
270
+ if (!current()) return fail("task authority changed before the worktree commit");
268
271
  let records: Record<string, TaskWorktreeEntry>;
269
272
  try { records = this.readRecords(); } catch (error) { return fail((error as Error).message); }
270
273
  const entry = records[this.key(peer, task)];
@@ -296,8 +299,9 @@ export class TaskWorktrees implements TaskWorktreePort {
296
299
  if (raw.status !== 0) return fail("the staged change could not be listed");
297
300
  const parts = raw.stdout.split("\0").filter(Boolean), changed: { mode: string; path: string }[] = [];
298
301
  for (let i = 0; i + 1 < parts.length; i += 2) { const meta = /^:(\d{6}) (\d{6}) /.exec(parts[i]!); if (!meta) return fail("the staged change has an unreadable entry"); changed.push({ mode: meta[2]!, path: parts[i + 1]! }); }
302
+ if (!current()) return fail("task authority changed before the worktree commit");
299
303
  // Nothing new since the hub's own commit: this is a retry after a failed push, so push the commit it already made.
300
- if (!changed.length && entry.head) return this.push(path, branch, entry.head, peer);
304
+ if (!changed.length && entry.head) return this.push(path, branch, entry.head, peer, current);
301
305
  if (!changed.length) return fail(`no changes under ${path}: edit files there, then call hub_task_done again`);
302
306
  if (changed.length > MAX_PATHS) return fail(`${changed.length} paths changed, more than the ${MAX_PATHS} the hub commits for a sandboxed peer; split the work into smaller tasks`);
303
307
  // 3. The same path policy a person's grant uses: the denylist, the agent and hub write names, and (when the policy is on) the instruction files.
@@ -305,8 +309,10 @@ export class TaskWorktrees implements TaskWorktreePort {
305
309
  const refused = changed.filter(c => c.mode === "160000" || isDenied(c.path, deny) || !grantablePath(path, join(path, c.path), c.path, protect));
306
310
  if (refused.length) return fail(`the hub will not commit ${refused.length} changed path${refused.length === 1 ? "" : "s"} (${refused.slice(0, 3).map(c => shown(c.path, 60)).join(", ")}): a secret, a git or hub or agent configuration name, a protected instruction file or a submodule. Revert ${refused.length === 1 ? "it" : "them"} in the worktree and call hub_task_done again`);
307
311
  this.o.beforeCommit?.();
312
+ if (!current()) return fail("task authority changed before the worktree commit");
308
313
  // 4. The commit object is made from the validated tree by the hub (no hook, no signing, no index read), and the branch moves to it only if it still sits at the recorded tip.
309
314
  const title = shown(input.title, 200) || `task ${task}`;
315
+ uncertain = true; // Git may have written an object or moved the branch even if a later step fails.
310
316
  const made = this.git(["-c", `user.name=${peer}`, "-c", `user.email=${peer}@agent-hub.invalid`, "-c", "commit.gpgSign=false", "commit-tree", tree, "-p", expectedTip, "-m", title, "-m", `Task #${task} by ${peer}. Committed by the hub for a sandboxed peer.`], path), commit = made.stdout.trim();
311
317
  if (made.status !== 0 || !SHA.test(commit)) return fail(`git commit-tree failed: ${shown(made.stderr)}`);
312
318
  if (this.git(["update-ref", `refs/heads/${branch}`, commit, expectedTip], path).status !== 0) return fail(`${branch} moved while the hub was committing; nothing was kept. Decline the task so the hub clears it`);
@@ -315,13 +321,14 @@ export class TaskWorktrees implements TaskWorktreePort {
315
321
  // there is clean and `remove` can tell finished work from uncommitted work. Nothing is ever committed from it.
316
322
  this.git(["read-tree", commit], path); this.git(["update-index", "-q", "--refresh"], path);
317
323
  try { this.mutate(current => { current[this.key(peer, task)] = { ...(current[this.key(peer, task)] ?? entry), head: commit }; }); } catch { return fail("the commit was made but the hub could not record it; call hub_task_done again", commit); }
318
- return this.push(path, branch, commit, peer);
324
+ return this.push(path, branch, commit, peer, current);
319
325
  } finally { rmSync(index, { force: true }); }
320
326
  }
321
327
 
322
328
  /** 5. One explicit refspec for this branch, only to an origin that is this project's repository. */
323
- private async push(path: string, branch: string, commit: string, _peer: PeerId): Promise<TaskWorktreeCommit> {
324
- const fail = (reason: string, sha?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(sha ? { commit: sha } : {}) });
329
+ private async push(path: string, branch: string, commit: string, _peer: PeerId, current: () => boolean): Promise<TaskWorktreeCommit> {
330
+ const fail = (reason: string, sha?: string): TaskWorktreeCommit => ({ ok: false, reason, ...(sha ? { commit: sha } : {}), uncertain: true });
331
+ if (!current()) return fail("task authority changed after the worktree commit; the commit was kept", commit);
325
332
  if (this.tip(branch) !== commit) return fail(`${branch} no longer points at the hub's commit ${commit.slice(0, 12)}; the hub will not push it. Decline the task so the hub clears it`);
326
333
  const urls = [...this.git(["remote", "get-url", "--push", "--all", "origin"], path).stdout.trim().split("\n"), ...this.git(["remote", "get-url", "--all", "origin"], path).stdout.trim().split("\n")].filter(Boolean);
327
334
  const verdict = this.o.pushAllowed?.(urls);