@staix/agent-hub 0.42.0 → 0.43.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 (48) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +2 -1
  3. package/docs/adding-an-ai-tool.md +2 -0
  4. package/docs/agent-notes/tasks.md +1 -1
  5. package/docs/agent-notes/tests.md +1 -1
  6. package/docs/design/adapters.md +3 -0
  7. package/docs/design/bus.md +2 -0
  8. package/docs/design/task-board.md +6 -0
  9. package/docs/dogfood.md +5 -1
  10. package/docs/memory.md +5 -3
  11. package/docs/operations.md +64 -4
  12. package/docs/quickstart.md +12 -2
  13. package/docs/sdlc.md +1 -1
  14. package/docs/security.md +1 -1
  15. package/docs/verification/2026-11-18-0.43.0.md +56 -0
  16. package/docs/verified.json +23 -23
  17. package/package.json +2 -2
  18. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  19. package/plugins/agent-hub/kimi-hook.js +307 -117
  20. package/plugins/agent-hub/server.js +307 -117
  21. package/src/adapters/claude-implementer.ts +11 -1
  22. package/src/adapters/claude-print-child.ts +4 -1
  23. package/src/adapters/conformance/fakes/acp-server.ts +2 -1
  24. package/src/adapters/conformance/fakes/app-server.ts +1 -1
  25. package/src/adapters/local-worker.ts +7 -3
  26. package/src/adapters/reviewer-print.ts +3 -1
  27. package/src/cli/help.ts +3 -3
  28. package/src/cli/identity.ts +2 -0
  29. package/src/cli/main.ts +56 -4
  30. package/src/cli/upgrade-output.ts +43 -2
  31. package/src/cli/upgrade-stopped.ts +162 -0
  32. package/src/cli/upgrade-wait.ts +37 -0
  33. package/src/hub/board.ts +4 -2
  34. package/src/hub/config-apply.ts +1 -0
  35. package/src/hub/daemon.ts +75 -13
  36. package/src/hub/envelope.ts +1 -0
  37. package/src/hub/handoff.ts +14 -0
  38. package/src/hub/questions.ts +7 -0
  39. package/src/hub/recovery-store.ts +39 -0
  40. package/src/hub/research-record.ts +2 -1
  41. package/src/hub/runtime-capture-prune.ts +114 -3
  42. package/src/hub/runtime-prune-health.ts +6 -2
  43. package/src/hub/sdlc-metrics.ts +2 -2
  44. package/src/hub/settings.ts +2 -0
  45. package/src/hub/task-sweep.ts +6 -2
  46. package/src/hub/tasks.ts +8 -3
  47. package/src/hub/turn-attribution.ts +46 -0
  48. package/templates/AGENTS.block.md +1 -1
@@ -50,7 +50,7 @@ export function taskSweepConfig(input: unknown): TaskSweepConfig {
50
50
  }
51
51
 
52
52
  /** Pure time/kind ladder; Tasks decides whether the responsible peer is available. */
53
- export function nextSweep(task: Task, config: TaskSweepConfig, now: number, ready = true): SweepRecord | undefined {
53
+ export function nextSweep(task: Task, config: TaskSweepConfig, now: number, ready = true, questionWait?: { open: boolean; settled?: number }): SweepRecord | undefined {
54
54
  if (!config.enabled || !Number.isFinite(now)) return undefined;
55
55
  // #1176: a person-run leg waits on the person, so no idle step ever escalates it to an agent.
56
56
  if (task.needsPerson) return undefined;
@@ -61,7 +61,10 @@ export function nextSweep(task: Task, config: TaskSweepConfig, now: number, read
61
61
  let activity = task.history.length - 1;
62
62
  while (activity >= 0 && (task.history[activity]?.sweep || task.history[activity]?.event === "memory reference started")) activity--;
63
63
  let at = task.history[activity]?.at ?? task.created;
64
+ let questionSettled: number | undefined;
64
65
  if (kind === "idle-owner") {
66
+ if (questionWait?.open) return undefined;
67
+ if (questionWait?.settled !== undefined && questionWait.settled > at) { questionSettled = questionWait.settled; at = questionSettled; }
65
68
  // #1454: a pending wait suspends the ladder; once it passes, the ladder restarts from `until`, not from the activity before it.
66
69
  const wait = taskWait(task);
67
70
  if (wait) {
@@ -71,7 +74,8 @@ export function nextSweep(task: Task, config: TaskSweepConfig, now: number, read
71
74
  }
72
75
  const threshold = kind === "ready-unassigned" ? config.ready_min ?? 60 : kind === "unaccepted-assignment" ? config.unaccepted_min : kind === "idle-owner" ? config.idle_min : config.review_min;
73
76
  if (now - at < threshold * 60_000) return undefined;
74
- const previous = task.history.flatMap((h) => h.sweep?.kind === kind && h.sweep.activity === activity ? [h.sweep] : []).at(-1);
77
+ let previous = task.history.flatMap((h) => h.sweep?.kind === kind && h.sweep.activity === activity ? [h.sweep] : []).at(-1);
78
+ if (questionSettled !== undefined && previous && previous.at <= questionSettled) previous = undefined;
75
79
  if (previous && (previous.step === 3 || now - previous.at < config.ladder_min * 60_000)) return undefined;
76
80
  return { kind, activity, step: previous ? (previous.step + 1) as 2 | 3 : 1, at: now };
77
81
  }
package/src/hub/tasks.ts CHANGED
@@ -167,6 +167,8 @@ export interface AuditView extends AuditSummary {
167
167
  notUpdated?: string[];
168
168
  }
169
169
  export interface TasksDeps {
170
+ /** Timing-only owner question evidence for the idle-owner ladder. */
171
+ ownerQuestionWait?: (task: number, peer: PeerId) => { open: boolean; settled?: number } | undefined;
170
172
  /** Private host-owned probe ledger and fixture ports. No configuration, wire or model-selected runner. */
171
173
  guidanceProbes?: {
172
174
  store: GuidanceProbeStore;
@@ -974,7 +976,8 @@ export class Tasks {
974
976
  for (const task of this.d.board.list()) {
975
977
  if (this.d.sweepHeld?.() || this.d.bus.isRecoveryHeld || this.d.bus.storageError) break;
976
978
  if (!task.owner && this.personUnassigned(task)) continue;
977
- const finding = nextSweep(task, config, now, this.waitsFor(task).length === 0 && !plannedStartPending(task, now));
979
+ const questionWait = task.state === "in_progress" && task.owner ? this.d.ownerQuestionWait?.(task.id, task.owner) : undefined;
980
+ const finding = nextSweep(task, config, now, this.waitsFor(task).length === 0 && !plannedStartPending(task, now), questionWait);
978
981
  if (!finding || this.waitsFor(task).length || this.isChecking(task.id) || this.silentFor(task.id)) continue;
979
982
  if (finding.kind === "ready-unassigned") {
980
983
  this.d.board.update(task.id, HUB, "idle sweep", {}, undefined, { sweep: finding });
@@ -6775,7 +6778,7 @@ export class Tasks {
6775
6778
  }
6776
6779
  const rows = this.d.board.list();
6777
6780
  const tasks: MetricTask[] = rows.map(task => ({ id: task.id, private: this.isPii(task), history: task.history.map(entry => ({ at: entry.at, event: entry.event,
6778
- ...(entry.reviewCost?.head ? { requestHead: entry.reviewCost.head } : {}), ...(entry.reviewFindings?.head ? { verdictHead: entry.reviewFindings.head } : {}), ...(entry.evidenceOnly ? { evidenceOnly: true as const } : {}) })) }));
6781
+ ...(entry.event === "done" && (entry.requestHead ?? entry.reviewCost?.head ?? entry.specReport?.head) ? { requestHead: entry.requestHead ?? entry.reviewCost?.head ?? entry.specReport?.head } : {}), ...(entry.reviewFindings?.head ? { verdictHead: entry.reviewFindings.head } : {}), ...(entry.evidenceOnly ? { evidenceOnly: true as const } : {}) })) }));
6779
6782
  const visibleIds = new Set(rows.filter(task => !this.isPii(task)).map(task => task.id));
6780
6783
  const byKind: Record<string, number> = {};
6781
6784
  for (const stall of this.stalled()) if (visibleIds.has(stall.task)) byKind[stall.cause.kind] = (byKind[stall.cause.kind] ?? 0) + 1;
@@ -9138,6 +9141,8 @@ export class Tasks {
9138
9141
  if (specInspection?.report?.head && !completedRefs.commit) completedRefs.commit = specInspection.report.head;
9139
9142
  if (specInspection?.report && specInspection.repo && !completedRefs.repo) completedRefs.repo = specInspection.repo;
9140
9143
  const storedRefs = { ...task.refs, ...completedRefs };
9144
+ const requestedHead = completedRefs.commit ?? admission?.head ?? specInspection?.report?.head;
9145
+ const requestHead = requestedHead && /^[a-f0-9]{40}$/.test(requestedHead) ? requestedHead : undefined;
9141
9146
  if (specInspection) {
9142
9147
  if (asyncCheckCompletion) {
9143
9148
  if (this.refreshAsyncSpecInspection(specInspection, { ...task, refs: storedRefs }, by)) { this.requestSpecRefile(task); return task; }
@@ -9148,7 +9153,7 @@ export class Tasks {
9148
9153
  const capacity = this.capacityBefore(task);
9149
9154
  reviewObserverExcluded ||= this.reviewObserverTurn(by, task.id);
9150
9155
  const quotaWaiting = selection?.reviewSelection?.quotaWait !== undefined;
9151
- const next = this.d.board.update(task.id, by, "done", { codeSymbols: this.observedCodeSymbols({ ...task, refs: storedRefs }), state: reviewer ? "in_review" : "approved", ...(selection || refresh?.state === "approved" ? { reviewer: quotaWaiting ? null : reviewer ?? USER } : {}), ...(task.sdlc ? { sdlc: { ...task.sdlc, stage: lifecycleStage(this.d.sdlc?.config() ?? sdlcConfig(undefined), reviewer ? "review" : "merge") } } : {}), refs: completedRefs }, checkOutput ? `${routedSummary ?? ""}\n${checkOutput}`.trim() : routedSummary, { ...(resolvedReviewComments?.length ? { resolvedReviewComments: this.reviewCommentResolve(by, task, resolvedReviewComments) } : {}), ...this.planObservation(task), withheld: withheld || undefined, ...(specInspection?.report ? { specReport: specInspection.report, specRefBinding: this.specRefBinding({ refs: storedRefs }) } : {}), ...(noWrites ? { noWrites: true as const } : {}), ...this.reviewMetadata(selection, { ...task, state: "in_review", refs: storedRefs }), ...(reviewCost ? { reviewCost } : {}), ...(records ? { deliverables: records } : {}) }, task.history.length, HOST_CODE_SYMBOLS);
9156
+ const next = this.d.board.update(task.id, by, "done", { codeSymbols: this.observedCodeSymbols({ ...task, refs: storedRefs }), state: reviewer ? "in_review" : "approved", ...(selection || refresh?.state === "approved" ? { reviewer: quotaWaiting ? null : reviewer ?? USER } : {}), ...(task.sdlc ? { sdlc: { ...task.sdlc, stage: lifecycleStage(this.d.sdlc?.config() ?? sdlcConfig(undefined), reviewer ? "review" : "merge") } } : {}), refs: completedRefs }, checkOutput ? `${routedSummary ?? ""}\n${checkOutput}`.trim() : routedSummary, { ...(resolvedReviewComments?.length ? { resolvedReviewComments: this.reviewCommentResolve(by, task, resolvedReviewComments) } : {}), ...this.planObservation(task), withheld: withheld || undefined, ...(specInspection?.report ? { specReport: specInspection.report, specRefBinding: this.specRefBinding({ refs: storedRefs }) } : {}), ...(noWrites ? { noWrites: true as const } : {}), ...this.reviewMetadata(selection, { ...task, state: "in_review", refs: storedRefs }), ...(reviewCost ? { reviewCost } : {}), ...(requestHead ? { requestHead } : {}), ...(records ? { deliverables: records } : {}) }, task.history.length, HOST_CODE_SYMBOLS);
9152
9157
  this.queueReviewWritten(next);
9153
9158
  this.writePlannerNotices(next, capacity, next.state === "approved");
9154
9159
  this.ciWatchers.cancel(next.id); this.heldReviews.delete(next.id); // a newer head or a move ends the old head's watcher (#785 P1b)
@@ -0,0 +1,46 @@
1
+ import { HUB, USER, type Envelope } from "./envelope.ts";
2
+
3
+ export type TurnTrigger = "assign" | "review" | "message" | "manual" | "schedule";
4
+ export interface TurnAttribution { task?: number; attempt?: string; trigger?: TurnTrigger; private?: boolean; cloud?: boolean }
5
+
6
+ /** Hints are not authority: only emit a task when the host's turn context is unambiguous. */
7
+ export function turnAttribution(envs: readonly Envelope[], options: { task?: number; cloud?: boolean; scheduled?: (task: number) => boolean | undefined } = {}): TurnAttribution {
8
+ let invalidTask = false;
9
+ const refs = new Set(envs.flatMap(env => {
10
+ const value = env.refs?.task;
11
+ if (value === undefined) return [];
12
+ if (!/^[1-9][0-9]*$/.test(value)) { invalidTask = true; return []; }
13
+ const id = Number(value);
14
+ if (!Number.isSafeInteger(id)) { invalidTask = true; return []; }
15
+ return [id];
16
+ }));
17
+ const task = options.task === undefined || invalidTask ? undefined : refs.size === 1 ? [...refs][0] : refs.size === 0 ? options.task : undefined;
18
+ const validTask = task !== undefined && Number.isSafeInteger(task) && task > 0 && (options.task === undefined || task === options.task);
19
+ let scheduled: boolean | undefined;
20
+ if (validTask && options.scheduled) try { scheduled = options.scheduled(task); } catch { /* Unknown provenance yields no assignment trigger. */ }
21
+ let uncertainTrigger = false;
22
+ const triggers = new Set(envs.flatMap(env => {
23
+ if (env.from === HUB && env.kind === "review") return ["review" as const];
24
+ if (env.from === HUB && env.kind === "task" && env.refs?.taskOffer !== undefined) {
25
+ if (scheduled === undefined) { uncertainTrigger = true; return []; }
26
+ return [scheduled ? "schedule" as const : "assign" as const];
27
+ }
28
+ if (env.from === USER) return ["manual" as const];
29
+ if (env.kind === "chat" && env.from !== HUB) return ["message" as const];
30
+ return [];
31
+ }));
32
+ return { ...(validTask ? { task } : {}), ...(!uncertainTrigger && triggers.size === 1 ? { trigger: [...triggers][0]! } : {}),
33
+ ...(envs.some(env => env.private) ? { private: true } : {}), ...(options.cloud ? { cloud: true } : {}) };
34
+ }
35
+
36
+ /** Strip inherited/configured hints and add only validated host-provided values. */
37
+ export function applyTurnAttribution(source: NodeJS.ProcessEnv, context?: TurnAttribution): NodeJS.ProcessEnv {
38
+ const env = { ...source };
39
+ delete env.AGENTHUB_TASK_ID; delete env.AGENTHUB_ATTEMPT_ID; delete env.AGENTHUB_TRIGGER;
40
+ const hidden = context?.private === true && context.cloud === true;
41
+ const hasTask = !hidden && context?.task !== undefined && Number.isSafeInteger(context.task) && context.task > 0;
42
+ if (hasTask) env.AGENTHUB_TASK_ID = String(context!.task);
43
+ if (hasTask && typeof context?.attempt === "string" && /^ra-[0-9a-f]{12}$/.test(context.attempt)) env.AGENTHUB_ATTEMPT_ID = context.attempt;
44
+ if (context?.trigger && ["assign", "review", "message", "manual", "schedule"].includes(context.trigger)) env.AGENTHUB_TRIGGER = context.trigger;
45
+ return env;
46
+ }
@@ -6,7 +6,7 @@ This project runs agent-hub: other coding agents and the hub console user reach
6
6
  - Receiving: Claude Code started with `ahub claude` gets hub messages as `<channel source="agent-hub">` tags and answers with `hub_send` (pass `reply_to` with the message id). Codex, headless Kimi, Qwen and Jcode, Pi and the local worker get them as prompts in which each message starts with a `[agent-hub message from` line, and the final answer of the turn is shared with the other agents. Any other session (a Claude session started otherwise, Antigravity `agy`, Kimi in its own TUI) is pull-only: read with `hub_inbox`, share with `hub_send`.
7
7
  - Pull-only sessions: call `hub_inbox` when starting work, between steps of longer work (after each commit, test run or finished sub-step), and before reporting; a hub tool result says when important messages are waiting. `hub_inbox` also reads a channel session's missed pushes. In the agy TUI the hub tools can be missing on the first turn: if no `hub_*` tool is listed, say so, end the turn and use them from the next turn; never report the hub as unavailable from the first turn alone.
8
8
  - Read the kind of each message. Only `hub` items with kind `presence` are shared memory for reference, not requests. Its `task`, `review`, and `budget` items are workflow events: check the task board and your assigned role, then use the appropriate hub tools within the user's authorized scope.
9
- - What you share is a conclusion, never tool output, and every answer costs the other agents a turn. If a message needs no answer, do no work and do not acknowledge it. Unmarked answers are batched into digests. Start with `[IMPORTANT]` only when the others must see it now (a blocker, or a changed contract or path that invalidates their current work), addressed with `to`.
9
+ - What you share is a conclusion, never tool output, and every answer costs the other agents a turn. If a message needs no answer, do no work and do not acknowledge it. A peer whose final answer is shared (see Receiving) ends such a turn with exactly `[FYI]`, which sends nothing. Unmarked answers are batched into digests. Start with `[IMPORTANT]` only when the others must see it now (a blocker, or a changed contract or path that invalidates their current work), addressed with `to`.
10
10
  - Do not use `[FYI]` for PR ready, done, submitted, ruling needed, blocker, or changed contract or path messages: each requires recipient action. Use `[FYI]` only for progress or information needing no action; it is recorded and costs nobody a turn. `hub_task_done` and `hub_review` already notify assigned recipients; no duplicate chat is needed.
11
11
  - When the hub or a refusal gives a command for the person to run, pass it on exactly as printed, with every flag and the `cd` prefix. If a value is missing, read it first (`ahub queue show <id>` for a delivery) and fill it in; never give the person a shortened command or a `<placeholder>`.
12
12
  - The task board is the record of who does what: `hub_task_propose`, `hub_task_accept` / `hub_task_decline`, `hub_task_done`, `hub_review`, `hub_task_list`. `.agenthub/config.json` `roles` says who plans, implements, verifies and reviews.