@staix/agent-hub 0.44.0 → 0.46.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 +66 -0
- package/README.md +12 -11
- package/docs/adding-an-ai-tool.md +1 -0
- package/docs/agent-notes/adapters.md +35 -6
- package/docs/agent-notes/budget.md +2 -1
- package/docs/agent-notes/daemon.md +5 -1
- package/docs/agent-notes/local-worker.md +1 -1
- package/docs/agent-notes/security-review.md +3 -2
- package/docs/agent-notes/tasks.md +6 -2
- package/docs/agent-notes/tests.md +4 -3
- package/docs/design/adapters.md +20 -2
- package/docs/design/agent-hub-architecture.md +12 -0
- package/docs/design/agent-hub.md +1 -1
- package/docs/design/cli-output.md +2 -0
- package/docs/design/roadmap.md +158 -4
- package/docs/design/supervision.md +21 -1
- package/docs/design/task-board.md +32 -4
- package/docs/dogfood.md +28 -4
- package/docs/events.md +7 -3
- package/docs/influences.md +7 -0
- package/docs/memory.md +4 -4
- package/docs/operations.md +151 -36
- package/docs/quickstart.md +16 -4
- package/docs/research.md +16 -0
- package/docs/roadmap.json +4 -0
- package/docs/roadmap.md +9 -0
- package/docs/sdlc.md +15 -3
- package/docs/security.md +9 -7
- package/docs/smoke.md +1 -1
- package/docs/verification/2026-11-05-hardcoded-values-classification-rules.md +28 -0
- package/docs/verification/2026-11-19-claude-implementer-2.1.328.md +49 -0
- package/docs/verification/2026-11-20-claude-implementer-2.1.329.md +49 -0
- package/docs/verification/2026-11-20-sdlc-metrics-diagnosis.md +7 -0
- package/docs/verification/2026-11-21-0.45.0.md +69 -0
- package/docs/verification/2026-11-22-agy-1.5.14.md +27 -0
- package/docs/verification/2026-11-22-claude-instruction-hook.md +35 -0
- package/docs/verification/2026-11-22-codex-0171-reviewer-isolation.md +47 -0
- package/docs/verification/2026-11-22-instructed-ipc.md +9 -0
- package/docs/verification/2026-11-22-jcode-1.0.3.md +71 -0
- package/docs/verification/2026-11-22-jcode-separate-home.md +14 -0
- package/docs/verification/2026-11-22-qwen-0283-acp.md +28 -0
- package/docs/verification/2026-11-22-qwen-0283-dual-output.md +33 -0
- package/docs/verification/2026-11-22-roadmap-r5-view-receipt.md +63 -0
- package/docs/verification/2026-11-23-0.46.0.md +44 -0
- package/docs/verification/assets/1483-r5-detail-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-detail-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-1440-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-390-light.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-dark.png +0 -0
- package/docs/verification/assets/1483-r5-view-820-light.png +0 -0
- package/docs/verified.json +33 -27
- package/package.json +3 -2
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +4743 -4048
- package/plugins/agent-hub/kimi-review-policy-worker.js +5 -5
- package/plugins/agent-hub/server.js +1641 -1265
- package/plugins/agent-hub/skills/ahub/SKILL.md +17 -0
- package/plugins/agent-hub/skills/ahub-manage/SKILL.md +37 -0
- package/plugins/agent-hub/skills/ahub-status/SKILL.md +14 -0
- package/plugins/agent-hub/skills/ahub-use/SKILL.md +12 -0
- package/scripts/check-docs.mjs +9 -1
- package/src/adapters/acp.ts +11 -1
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +15 -14
- package/src/adapters/definitions/builtin-metadata.ts +2 -2
- package/src/adapters/definitions/native-cli-claude-setup.ts +9 -1
- package/src/adapters/definitions/native-cli-doctor.ts +8 -5
- package/src/adapters/definitions/native-cli-jcode-home-init.ts +158 -0
- package/src/adapters/definitions/native-cli-jcode-home.ts +72 -0
- package/src/adapters/definitions/native-cli-jcode-mcp.ts +20 -0
- package/src/adapters/definitions/native-cli-skills.ts +29 -0
- package/src/adapters/definitions/native-context.ts +10 -0
- package/src/adapters/jcode.ts +10 -0
- package/src/adapters/local-worker.ts +3 -2
- package/src/adapters/pi.ts +15 -4
- package/src/cli/claude-profile-hook.ts +40 -3
- package/src/cli/console-state.ts +58 -27
- package/src/cli/console-usage.ts +5 -3
- package/src/cli/console.ts +35 -4
- package/src/cli/help.ts +17 -10
- package/src/cli/identity.ts +4 -2
- package/src/cli/instruction-hook.ts +28 -0
- package/src/cli/jcode-mcp.ts +2 -1
- package/src/cli/main.js +8 -0
- package/src/cli/main.ts +149 -23
- package/src/cli/output-standard.ts +3 -55
- package/src/cli/output.ts +8 -2
- package/src/cli/recovery-package.ts +62 -13
- package/src/cli/roadmap-write.ts +59 -0
- package/src/cli/roadmap.ts +115 -4
- package/src/cli/sdlc-output.ts +4 -0
- package/src/cli/setup-homes.ts +1 -0
- package/src/cli/setup.ts +1 -1
- package/src/cli/skills-install.ts +463 -0
- package/src/cli/task-output.ts +1 -1
- package/src/cli/upgrade-presentation-flags.ts +1 -1
- package/src/cli/upgrade-runtime.ts +10 -6
- package/src/hub/agent-mem-range.ts +43 -0
- package/src/hub/board.ts +144 -5
- package/src/hub/budget-projection.ts +99 -0
- package/src/hub/check-runner.ts +25 -1
- package/src/hub/claude-launch-proof.ts +5 -1
- package/src/hub/conductor.ts +8 -3
- package/src/hub/config-apply.ts +6 -3
- package/src/hub/config-tier.ts +1 -1
- package/src/hub/config-trust.ts +1 -1
- package/src/hub/context-window.ts +1 -1
- package/src/hub/control-client.ts +9 -2
- package/src/hub/cost-governance.ts +11 -7
- package/src/hub/daemon.ts +707 -53
- package/src/hub/dogfood-read.ts +4 -2
- package/src/hub/edit-guard.ts +100 -0
- package/src/hub/events.ts +80 -9
- package/src/hub/execution-budget.ts +29 -8
- package/src/hub/facts.ts +57 -4
- package/src/hub/hub-tools.ts +3 -1
- package/src/hub/inference.ts +1 -1
- package/src/hub/instances.ts +10 -1
- package/src/hub/instructed-exact.ts +95 -0
- package/src/hub/instructed-intent.ts +64 -0
- package/src/hub/instructed-ipc.ts +33 -0
- package/src/hub/instructed-runtime.ts +19 -0
- package/src/hub/instruction-receipt.ts +218 -0
- package/src/hub/lifecycle.ts +6 -1
- package/src/hub/log-rotation.ts +130 -0
- package/src/hub/manager.ts +46 -3
- package/src/hub/memory-profile.ts +137 -21
- package/src/hub/no-writes.ts +1 -0
- package/src/hub/operational-authority.ts +3 -2
- package/src/hub/operational-settings.ts +2 -2
- package/src/hub/recovery-store.ts +49 -21
- package/src/hub/registry.ts +1 -1
- package/src/hub/research-experiments.ts +132 -0
- package/src/hub/research-quality.ts +8 -2
- package/src/hub/research-record.ts +35 -0
- package/src/hub/research.ts +128 -28
- package/src/hub/roadmap-check.ts +65 -0
- package/src/hub/roadmap-decompose.ts +139 -0
- package/src/hub/roadmap-export.ts +27 -0
- package/src/hub/roadmap-sync.ts +97 -0
- package/src/hub/roadmap.ts +59 -1
- package/src/hub/routing.ts +18 -1
- package/src/hub/runtime-capture-prune.ts +2 -1
- package/src/hub/sdlc-branch-ci.ts +128 -0
- package/src/hub/sdlc-merge.ts +6 -3
- package/src/hub/sdlc-metrics.ts +19 -5
- package/src/hub/sdlc.ts +73 -5
- package/src/hub/settings.ts +3 -1
- package/src/hub/snapshots.ts +13 -1
- package/src/hub/startup-event-seeds.ts +21 -15
- package/src/hub/startup-timing.ts +3 -1
- package/src/hub/supervision-proposals.ts +10 -2
- package/src/hub/supervision-rules.ts +26 -3
- package/src/hub/supervision.ts +7 -0
- package/src/hub/task-pr.ts +47 -0
- package/src/hub/task-worktree.ts +18 -11
- package/src/hub/tasks.ts +694 -44
- package/src/hub/ui.ts +6 -2
- package/src/hub/usage-rollup.ts +77 -22
- package/src/local/tools.ts +13 -1
- package/src/memory/client.ts +3 -2
- package/src/pi/extension.ts +15 -3
- package/src/pi/tool-receipts.ts +26 -0
- package/src/ui/index.html +342 -8
- package/src/ui/plugin.ts +6 -2
- package/src/ui/roadmap-model.ts +70 -0
package/src/hub/dogfood-read.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { claimListId } from "./board.ts";
|
|
2
|
+
import { segmentsOf } from "./log-rotation.ts";
|
|
2
3
|
import { closeSync, constants, fstatSync, openSync, readSync } from "node:fs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { Database } from "bun:sqlite";
|
|
@@ -32,7 +33,8 @@ export function dogfoodLines(file: string, cap = DOGFOOD_BYTE_CAP): Source<strin
|
|
|
32
33
|
if (start) { const newline = text.indexOf("\n"); text = newline < 0 ? "" : text.slice(newline + 1); }
|
|
33
34
|
const whole = text.endsWith("\n") || !text;
|
|
34
35
|
if (!whole) text = text.slice(0,Math.max(0,text.lastIndexOf("\n") + 1));
|
|
35
|
-
|
|
36
|
+
// #1546: rotated segments hold older history this tail never reads, so the read is not whole once the log has rotated.
|
|
37
|
+
return source(text.split("\n").filter(Boolean), !start && n === stat.size && whole && !segmentsOf(file).some(segment => !segment.live));
|
|
36
38
|
} catch { return missing([]); }
|
|
37
39
|
finally { if (fd !== undefined) closeSync(fd); }
|
|
38
40
|
}
|
|
@@ -247,7 +249,7 @@ export async function dogfoodPrs(repo: string, tasks: Source<DogfoodTask[]>, sin
|
|
|
247
249
|
}
|
|
248
250
|
} catch { /* Missing or incomplete recorded heads cannot certify CI. */ }
|
|
249
251
|
return reply;
|
|
250
|
-
});
|
|
252
|
+
}, undefined, undefined, undefined, true);
|
|
251
253
|
const row: DogfoodPr = cost ?? {repo,pr:item.number,state:"MERGED",mergedAt:date(item.mergedAt),complete:false};
|
|
252
254
|
const linked = runsComplete ? runs.filter((r:any)=>date(r.created_at)!<=row.mergedAt!) : [];
|
|
253
255
|
if (runsComplete) {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { isAbsolute, relative } from "node:path";
|
|
4
|
+
import { MAX_RECEIPTS_PER_PEER, type Facts } from "./facts.ts";
|
|
5
|
+
import { MAX_OBSERVATIONS } from "./supervision-rules.ts";
|
|
6
|
+
import { classifyShellWrite } from "./task-shell-command.ts";
|
|
7
|
+
import { PreEffectToolRefusal } from "./tool-refusal.ts";
|
|
8
|
+
|
|
9
|
+
export type EditGuardArm = "baseline" | "route_guard" | "occ_guard" | "combined_guard";
|
|
10
|
+
export type EditGuardAvailability = "admitted" | "unavailable";
|
|
11
|
+
export function parseEditGovernance(raw: unknown): { arm: EditGuardArm } {
|
|
12
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw) || Object.keys(raw).some(key => key !== "arm")) throw new Error("edit_governance requires an arm");
|
|
13
|
+
const arm = (raw as { arm?: unknown }).arm;
|
|
14
|
+
if (arm !== "baseline" && arm !== "route_guard" && arm !== "occ_guard" && arm !== "combined_guard") throw new Error("edit_governance.arm is invalid");
|
|
15
|
+
return { arm };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A host-bound tool transaction. The caller owns the peer, task, generation and policy checks. */
|
|
19
|
+
export function editGuard(input: { root: string; peer: string; task: number; turn: string; ownerEpoch: string; arm: () => EditGuardArm; current: () => boolean; facts: Facts; evidence?: EditEvidence; revision?: string; changed?: () => void; observeShell?: () => boolean }) {
|
|
20
|
+
const name = (file: string) => {
|
|
21
|
+
const result = relative(input.root, file);
|
|
22
|
+
if (!result || isAbsolute(result) || result === ".." || result.startsWith("../")) throw new PreEffectToolRefusal("edit guard target unavailable; inspect the task before retrying");
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
const current = () => {
|
|
26
|
+
let valid = false; try { valid = input.current(); } catch { /* unknown authority refuses */ }
|
|
27
|
+
if (!valid) throw new PreEffectToolRefusal("edit guard authority changed; inspect the task before retrying");
|
|
28
|
+
};
|
|
29
|
+
const changed = () => { try { input.changed?.(); } catch { /* optional observation */ } };
|
|
30
|
+
const digest = (bytes: Buffer) => createHash("sha256").update(bytes).digest("hex");
|
|
31
|
+
return {
|
|
32
|
+
read(file: string, bytes: Buffer, full: boolean): void {
|
|
33
|
+
current(); input.facts.recordRead(input.peer, input.task, name(file), { sha256: digest(bytes), scope: full ? "full" : "partial", turnId: input.turn, ownerEpoch: input.ownerEpoch });
|
|
34
|
+
if (full && input.revision) input.evidence?.diagnosticRead(input.task, input.revision);
|
|
35
|
+
changed();
|
|
36
|
+
},
|
|
37
|
+
write(file: string): boolean | undefined {
|
|
38
|
+
current(); const arm = input.arm(), path = name(file); let hash: string;
|
|
39
|
+
try { hash = digest(readFileSync(file)); } catch (error) {
|
|
40
|
+
const code = (error as NodeJS.ErrnoException)?.code;
|
|
41
|
+
current();
|
|
42
|
+
if (code === "ENOENT") return true;
|
|
43
|
+
if (arm === "occ_guard" || arm === "combined_guard") {
|
|
44
|
+
const cause = typeof code === "string" && /^[A-Z][A-Z0-9_]{0,31}$/.test(code) ? code : "unavailable";
|
|
45
|
+
throw new PreEffectToolRefusal(`edit guard cannot read the current file (${cause}); inspect it before retrying`);
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
current();
|
|
50
|
+
const receipt = input.facts.readReceipt(input.peer, input.task, path);
|
|
51
|
+
const unverified = !receipt || receipt.ownerEpoch !== input.ownerEpoch || receipt.sha256 !== hash;
|
|
52
|
+
if (unverified && (arm === "occ_guard" || arm === "combined_guard")) throw new PreEffectToolRefusal(`blind or stale write refused; current sha256 ${hash}; re-read the file before retrying`);
|
|
53
|
+
return unverified;
|
|
54
|
+
},
|
|
55
|
+
written(file: string, unverified: boolean | undefined): void {
|
|
56
|
+
if (input.current() && input.revision) { input.evidence?.write(input.task, input.revision, name(file), unverified === true); changed(); }
|
|
57
|
+
},
|
|
58
|
+
shell(command: string): (() => void) | undefined {
|
|
59
|
+
current(); const arm = input.arm(), classified = classifyShellWrite(command);
|
|
60
|
+
if ((arm === "route_guard" || arm === "combined_guard") && classified.kind === "write") throw new PreEffectToolRefusal("shell write refused by route guard; use the dedicated edit tool");
|
|
61
|
+
if (!input.observeShell?.()) return undefined;
|
|
62
|
+
if (classified.kind === "unknown") { if (input.revision) input.evidence?.unknownShell(input.task, input.revision); changed(); return undefined; }
|
|
63
|
+
if (classified.kind !== "write") return undefined;
|
|
64
|
+
const id = randomUUID(), args = { command };
|
|
65
|
+
try { input.facts.preTool(input.peer, id, "Bash", args); } catch { return undefined; }
|
|
66
|
+
return () => { if (input.current()) input.facts.postTool(input.peer, id, "Bash", args); };
|
|
67
|
+
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Bounded, in-memory evidence. File identifiers never leave this store. */
|
|
73
|
+
export class EditEvidence {
|
|
74
|
+
private readonly rows = new Map<number, { revision: string; unverified: number; unknownShell: number; failed: boolean; cascading: Set<string> }>();
|
|
75
|
+
private row(task: number, revision: string) {
|
|
76
|
+
let row = this.rows.get(task);
|
|
77
|
+
if (!row || row.revision !== revision) {
|
|
78
|
+
row = { revision, unverified: 0, unknownShell: 0, failed: false, cascading: new Set() };
|
|
79
|
+
this.rows.delete(task); this.rows.set(task, row);
|
|
80
|
+
while (this.rows.size > MAX_OBSERVATIONS) this.rows.delete(this.rows.keys().next().value as number);
|
|
81
|
+
}
|
|
82
|
+
return row;
|
|
83
|
+
}
|
|
84
|
+
unknownShell(task: number, revision: string): void { const row = this.row(task, revision); row.unknownShell = Math.min(MAX_RECEIPTS_PER_PEER, row.unknownShell + 1); }
|
|
85
|
+
check(task: number, revision: string, result: "failed" | "passed"): void {
|
|
86
|
+
const row = this.row(task, revision); row.failed = result === "failed"; row.cascading.clear();
|
|
87
|
+
}
|
|
88
|
+
diagnosticRead(task: number, revision: string): void { const row = this.row(task, revision); row.failed = false; row.cascading.clear(); }
|
|
89
|
+
write(task: number, revision: string, file: string, unverified: boolean): void {
|
|
90
|
+
const row = this.row(task, revision);
|
|
91
|
+
if (unverified) row.unverified = Math.min(MAX_RECEIPTS_PER_PEER, row.unverified + 1);
|
|
92
|
+
if (row.failed && row.cascading.size < MAX_RECEIPTS_PER_PEER) row.cascading.add(createHash("sha256").update(file).digest("hex"));
|
|
93
|
+
}
|
|
94
|
+
snapshot(task: number, revision: string) {
|
|
95
|
+
const row = this.rows.get(task);
|
|
96
|
+
return row?.revision === revision ? { task, revision, unverified: row.unverified, unknownShell: row.unknownShell, cascading: row.cascading.size } : undefined;
|
|
97
|
+
}
|
|
98
|
+
close(task: number): void { this.rows.delete(task); }
|
|
99
|
+
reset(): void { this.rows.clear(); }
|
|
100
|
+
}
|
package/src/hub/events.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { appendFileSync, closeSync, existsSync, fstatSync, openSync, readFileSync, readSync } from "node:fs";
|
|
2
2
|
import type { TaskAttribution } from "./attribution.ts";
|
|
3
|
+
import { segmentsOf, streamEnd } from "./log-rotation.ts";
|
|
3
4
|
import type { PeerId } from "./envelope.ts";
|
|
4
5
|
import type { StageSwitchTrace as SwitchTrace } from "../models/route/stage-fallback.ts";
|
|
5
6
|
import type { ScreenRecord } from "./inference.ts";
|
|
@@ -24,6 +25,24 @@ export function turnModelFields(observed: unknown): { model: string; modelEviden
|
|
|
24
25
|
return label !== undefined && isModelEvidence(evidence) ? { model: label, modelEvidence: evidence } : {};
|
|
25
26
|
}
|
|
26
27
|
|
|
28
|
+
/** #1556 T2: the closed, text-free edit counts a turn may add to `turn_end` (only when it modified files). `e` is the edit tool [total, verifiedFull, partialOnly, blindOrStale, occRejected], `s` the shell route [total, verifiedFull, partialOnly, blindOrStale, blockedByGuard], `u` tree writes no stream attributed. Counts only: never a path, a command or text. */
|
|
29
|
+
export const EDIT_OBS = ["hook", "stream", "tree"] as const;
|
|
30
|
+
export const EDIT_ARMS = ["baseline", "soft_guidance", "route_guard", "occ_guard", "combined_guard", "shadow"] as const;
|
|
31
|
+
export type EditCounts = [number, number, number, number, number];
|
|
32
|
+
export interface TurnEdits { obs: (typeof EDIT_OBS)[number]; arm?: (typeof EDIT_ARMS)[number]; e?: EditCounts; s?: EditCounts; u?: number; fe?: number; rev?: number }
|
|
33
|
+
const EDIT_MAX = 1_000_000;
|
|
34
|
+
const editCount = (v: unknown): v is number => typeof v === "number" && Number.isSafeInteger(v) && v >= 0 && v <= EDIT_MAX;
|
|
35
|
+
const editCounts = (v: unknown): EditCounts | undefined => Array.isArray(v) && v.length === 5 && v.every(editCount) ? (v as EditCounts).slice() as EditCounts : undefined;
|
|
36
|
+
/** Rebuilds `turn_end.edits` from an untrusted value, field by field: a field that is not exactly the closed shape is dropped whole, and a value with no valid `obs` is dropped altogether. */
|
|
37
|
+
export function turnEdits(raw: unknown): TurnEdits | undefined {
|
|
38
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
39
|
+
const r = raw as Record<string, unknown>;
|
|
40
|
+
if (!(EDIT_OBS as readonly unknown[]).includes(r.obs)) return undefined;
|
|
41
|
+
const e = editCounts(r.e), s = editCounts(r.s);
|
|
42
|
+
return { obs: r.obs as TurnEdits["obs"], ...((EDIT_ARMS as readonly unknown[]).includes(r.arm) ? { arm: r.arm as TurnEdits["arm"] } : {}), ...(e ? { e } : {}), ...(s ? { s } : {}),
|
|
43
|
+
...(editCount(r.u) ? { u: r.u } : {}), ...(editCount(r.fe) ? { fe: r.fe } : {}), ...(editCount(r.rev) ? { rev: r.rev } : {}) };
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
/** Bumped whenever a field changes meaning or goes away; new fields and new types do not bump it. */
|
|
28
47
|
export const EVENTS_SCHEMA = 1;
|
|
29
48
|
|
|
@@ -77,10 +96,10 @@ export type HubEvent =
|
|
|
77
96
|
| { type: "state"; peer: string; state: string }
|
|
78
97
|
| { type: "turn_start"; peer: string; turn: string }
|
|
79
98
|
| { type: "native_thread"; peer: string; thread: string; fresh: boolean }
|
|
80
|
-
| ({ type: "turn_end"; peer: string; turn: string; ms: number; tokens?: number; files?: number; snapshotMs?: number; preparedRoles?: RoleIdentity[] | null; model?: string; modelEvidence?: ModelEvidence } & Partial<TaskAttribution>)
|
|
99
|
+
| ({ type: "turn_end"; peer: string; turn: string; ms: number; tokens?: number; files?: number; snapshotMs?: number; preparedRoles?: RoleIdentity[] | null; model?: string; modelEvidence?: ModelEvidence; edits?: TurnEdits } & Partial<TaskAttribution>)
|
|
81
100
|
| { type: "native_turn_end"; peer: string; id?: string; reason?: "user_canceled" | "error" | "max_invocations" | "max_forced_invocations" | "max_token_budget_exceeded" | "terminal_step_type" | "terminal_custom_hook" }
|
|
82
101
|
| { type: "conduct"; peer: string; action: string; task?: number; target?: string }
|
|
83
|
-
| ({ type: "agent_cli"; peer: string; command: string; refused: boolean; delegated?: true; instructed?: true } & Partial<TaskAttribution>)
|
|
102
|
+
| ({ type: "agent_cli"; peer: string; command: string; refused: boolean; delegated?: true; instructed?: true; instructionReceipt?: string } & Partial<TaskAttribution>)
|
|
84
103
|
| ({ type: "permission"; id: string; peer: string; event: "requested" | "answered" | "expired" | "cancelled"; latencyMs?: number; surface?: "console" | "dashboard" | "terminal"; option?: "allow_once" | "allow_always" | "reject_once" | "reject_always" } & Partial<TaskAttribution>)
|
|
85
104
|
/** #1053: one question a peer asked the person, and how it ended. Counts, ids and a closed reason only: never a prompt, an option, an answer or other text. */
|
|
86
105
|
| ({ type: "question"; set: string; peer: string; event: "asked" | "answered" | "pending" | "superseded" | "cancelled" | "expired" | "unavailable"; latencyMs?: number; surface?: "terminal" | "console" | "dashboard" | "acon" | "conductor"; person?: string; reason?: "superseded" | "stopped" | "turn_aborted" | "session_changed" | "expired" | "unattended"; questions?: number; private?: boolean } & Partial<TaskAttribution>)
|
|
@@ -164,15 +183,67 @@ export function tokenDeltas(): (peer: string, total: number, session: string) =>
|
|
|
164
183
|
}
|
|
165
184
|
|
|
166
185
|
/**
|
|
167
|
-
* Events at or after `since` (ms), skipping lines a crash cut short.
|
|
168
|
-
*
|
|
186
|
+
* Events at or after `since` (ms), skipping lines a crash cut short. Reads every rotated segment (`log-rotation.ts`, #1546) oldest first and then the live file, so rotation never hides history from a reader;
|
|
187
|
+
* the segment list is read again afterwards and the read repeated if a rotation moved the live file meanwhile.
|
|
169
188
|
*/
|
|
170
189
|
export function readEvents(file: string, since = 0): StampedEvent[] {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
190
|
+
for (let attempt = 0; ; attempt++) {
|
|
191
|
+
const segments = segmentsOf(file), out: StampedEvent[] = [];
|
|
192
|
+
for (const segment of segments) {
|
|
193
|
+
let text: string;
|
|
194
|
+
try { text = readFileSync(segment.path, "utf8"); } catch { continue; } // moved by a rotation since the listing: the check below repeats the read
|
|
195
|
+
for (const line of text.split("\n")) { const event = parseEventLine(line, since); if (event !== undefined) out.push(event); }
|
|
196
|
+
}
|
|
197
|
+
const again = segmentsOf(file);
|
|
198
|
+
if (attempt >= 3 || (again.length === segments.length && again.every((segment, i) => segment.path === segments[i]!.path && segment.start === segments[i]!.start))) return out;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* #1555 AC5, #1546: the whole lines of the event log (its rotated segments and the live file make one byte stream: an offset is a position in that stream, so it keeps its meaning across a rotation) from byte `from` up to byte `to` (default: the end), each with the byte offset it starts at, read in bounded chunks, never the file from byte 0 unless `from` is 0.
|
|
204
|
+
* A trailing piece with no newline yet is not a line: it is left for the pass that sees its end. Returns the offset after the last whole line, which is where the next pass starts.
|
|
205
|
+
* A line is the bytes between two `\n`, so a multi-byte character never splits one.
|
|
206
|
+
* Bytes below the oldest kept segment are gone: a `from` below it starts at the oldest segment. A trailing piece with no newline can only be the live file's last bytes.
|
|
207
|
+
*/
|
|
208
|
+
export function scanEventLines(file: string, from: number, each: (line: string, offset: number) => void, to = Infinity): number {
|
|
209
|
+
const segments = segmentsOf(file);
|
|
210
|
+
if (!segments.length) return from;
|
|
211
|
+
let position = Math.max(from, segments[0]!.start);
|
|
212
|
+
const end = Math.min(streamEnd(segments), to);
|
|
213
|
+
for (const segment of segments) {
|
|
214
|
+
const segmentEnd = Math.min(segment.start + segment.size, end);
|
|
215
|
+
if (segmentEnd <= position) continue;
|
|
216
|
+
if (segment.start >= end) break;
|
|
217
|
+
position = segment.start + scanFileLines(segment.path, position - segment.start, (line, offset) => each(line, segment.start + offset), segmentEnd - segment.start);
|
|
218
|
+
if (position < segmentEnd) break; // a trailing piece with no newline yet: the next pass sees its end
|
|
219
|
+
}
|
|
220
|
+
return position;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function scanFileLines(file: string, from: number, each: (line: string, offset: number) => void, to: number): number {
|
|
224
|
+
if (!existsSync(file)) return from;
|
|
225
|
+
const fd = openSync(file, "r");
|
|
226
|
+
try {
|
|
227
|
+
const end = Math.min(fstatSync(fd).size, to);
|
|
228
|
+
const chunk = Buffer.alloc(1 << 20);
|
|
229
|
+
let pending = Buffer.alloc(0), base = from, at = from;
|
|
230
|
+
while (at < end) {
|
|
231
|
+
const n = readSync(fd, chunk, 0, Math.min(chunk.length, end - at), at);
|
|
232
|
+
if (n <= 0) break;
|
|
233
|
+
at += n;
|
|
234
|
+
const data = pending.length ? Buffer.concat([pending, chunk.subarray(0, n)]) : Buffer.from(chunk.subarray(0, n));
|
|
235
|
+
let lineStart = 0;
|
|
236
|
+
for (let nl = data.indexOf(0x0a, lineStart); nl >= 0; nl = data.indexOf(0x0a, lineStart)) {
|
|
237
|
+
each(data.toString("utf8", lineStart, nl), base + lineStart);
|
|
238
|
+
lineStart = nl + 1;
|
|
239
|
+
}
|
|
240
|
+
base += lineStart;
|
|
241
|
+
pending = data.subarray(lineStart);
|
|
242
|
+
}
|
|
243
|
+
return base;
|
|
244
|
+
} finally {
|
|
245
|
+
closeSync(fd);
|
|
246
|
+
}
|
|
176
247
|
}
|
|
177
248
|
|
|
178
249
|
/** The historical event-reader predicate, shared without adding shape or line-size restrictions. */
|
|
@@ -11,11 +11,19 @@ export interface ExecutionBudgetConfig {
|
|
|
11
11
|
peers: string[];
|
|
12
12
|
limits: ExecutionBudgetLimits;
|
|
13
13
|
}
|
|
14
|
+
/** #1513 AC3: a person's reason for reconfiguring a budget, kept with who gave it and when. */
|
|
15
|
+
export interface ExecutionOverride {
|
|
16
|
+
reason: string;
|
|
17
|
+
by: string;
|
|
18
|
+
at: number;
|
|
19
|
+
}
|
|
14
20
|
export interface ExecutionBudgetStatus extends ExecutionBudgetConfig {
|
|
15
21
|
used: Partial<Record<ExecutionUnit, number>>;
|
|
16
22
|
units: Partial<Record<ExecutionUnit, { used: number; limit: number; remaining: number; reason?: "exhausted" | "unknown_usage" }>>;
|
|
17
23
|
createdAt: number;
|
|
18
24
|
updatedAt: number;
|
|
25
|
+
/** The last reasoned override. A configure without a reason leaves it as it was. */
|
|
26
|
+
override?: ExecutionOverride;
|
|
19
27
|
}
|
|
20
28
|
export interface ExecutionBudgetDecision {
|
|
21
29
|
allowed: boolean;
|
|
@@ -48,9 +56,16 @@ export class ExecutionBudget {
|
|
|
48
56
|
this.db.run(`CREATE TABLE IF NOT EXISTS execution_budgets (
|
|
49
57
|
id TEXT PRIMARY KEY, kind TEXT NOT NULL, task_id INTEGER, peers TEXT NOT NULL,
|
|
50
58
|
limits TEXT NOT NULL, used TEXT NOT NULL, created_at INTEGER NOT NULL, updated_at INTEGER NOT NULL)`);
|
|
59
|
+
// #1513: a table created before the override column exists still opens, and keeps its rows.
|
|
60
|
+
const columns = this.db.query("PRAGMA table_info(execution_budgets)").all() as { name: string }[];
|
|
61
|
+
if (!columns.some(column => column.name === "last_override")) this.db.run("ALTER TABLE execution_budgets ADD COLUMN last_override TEXT");
|
|
51
62
|
}
|
|
52
63
|
|
|
53
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A configure with a reason records it with the actor and the time, and the caller's `by` is only ever
|
|
66
|
+
* `person`: the console is the one writer of an execution budget.
|
|
67
|
+
*/
|
|
68
|
+
configure(input: ExecutionBudgetConfig, meta: { reason?: string; by?: string } = {}): ExecutionBudgetStatus {
|
|
54
69
|
if (!input.id || input.id.length > 200) throw new Error("execution budget id is invalid");
|
|
55
70
|
if (input.kind !== "task" && input.kind !== "run") throw new Error("execution budget kind must be task or run");
|
|
56
71
|
if (input.kind === "task" && (!Number.isSafeInteger(input.taskId) || input.taskId! < 1)) throw new Error("task budget requires a positive task id");
|
|
@@ -60,13 +75,17 @@ export class ExecutionBudget {
|
|
|
60
75
|
if (unsupported.length) throw new Error(`execution budgets require instrumented peers (pi, local); unsupported: ${unsupported.join(", ")}`);
|
|
61
76
|
const limits = validLimits(input.limits ?? {});
|
|
62
77
|
if (!Object.keys(limits).length) throw new Error("execution budget requires at least one supported limit");
|
|
78
|
+
const reason = meta.reason === undefined ? undefined : String(meta.reason).trim();
|
|
79
|
+
if (reason !== undefined && reason.length > 280) throw new Error("execution budget reason is at most 280 characters");
|
|
63
80
|
const now = Date.now();
|
|
64
|
-
const existing = this.db.query("SELECT kind,task_id FROM execution_budgets WHERE id=?").get(input.id) as { kind: string; task_id: number | null } | undefined;
|
|
81
|
+
const existing = this.db.query("SELECT kind,task_id,last_override FROM execution_budgets WHERE id=?").get(input.id) as { kind: string; task_id: number | null; last_override: string | null } | undefined;
|
|
65
82
|
if (existing && (existing.kind !== input.kind || existing.task_id !== (input.taskId ?? null))) throw new Error("execution budget id is already bound to another scope");
|
|
66
|
-
this
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
// A configure without a reason keeps the last one: the row answers "why is this limit what it is", not "what did the last call say".
|
|
84
|
+
const lastOverride = reason ? JSON.stringify({ reason, by: meta.by ?? "person", at: now }) : existing?.last_override ?? null;
|
|
85
|
+
this.db.query(`INSERT INTO execution_budgets (id,kind,task_id,peers,limits,used,created_at,updated_at,last_override)
|
|
86
|
+
VALUES (?,?,?,?,?,'{}',?,?,?) ON CONFLICT(id) DO UPDATE SET kind=excluded.kind,task_id=excluded.task_id,
|
|
87
|
+
peers=excluded.peers,limits=excluded.limits,updated_at=excluded.updated_at,last_override=excluded.last_override`).run(
|
|
88
|
+
input.id, input.kind, input.taskId ?? null, JSON.stringify(peers), JSON.stringify(limits), now, now, lastOverride,
|
|
70
89
|
);
|
|
71
90
|
return this.status(input.id) as ExecutionBudgetStatus;
|
|
72
91
|
}
|
|
@@ -147,7 +166,7 @@ export class ExecutionBudget {
|
|
|
147
166
|
close(): void { this.db.close(); }
|
|
148
167
|
}
|
|
149
168
|
|
|
150
|
-
interface BudgetRow { id: string; kind: "task"|"run"; task_id: number | null; peers: string; limits: string; used: string; created_at: number; updated_at: number }
|
|
169
|
+
interface BudgetRow { id: string; kind: "task"|"run"; task_id: number | null; peers: string; limits: string; used: string; created_at: number; updated_at: number; last_override?: string | null }
|
|
151
170
|
function fromRow(row: BudgetRow): ExecutionBudgetStatus {
|
|
152
171
|
const limits = JSON.parse(row.limits) as ExecutionBudgetLimits;
|
|
153
172
|
const used = JSON.parse(row.used) as Partial<Record<ExecutionUnit, number>>;
|
|
@@ -157,5 +176,7 @@ function fromRow(row: BudgetRow): ExecutionBudgetStatus {
|
|
|
157
176
|
const current = used[unit] ?? 0, remaining = Math.max(0, limit - current);
|
|
158
177
|
units[unit] = { used: current, limit, remaining, ...((unit === "tokens" && remaining > 0) ? { reason: "unknown_usage" as const } : (remaining === 0 ? { reason: "exhausted" as const } : {})) };
|
|
159
178
|
}
|
|
160
|
-
|
|
179
|
+
const override = row.last_override ? JSON.parse(row.last_override) as ExecutionOverride : undefined;
|
|
180
|
+
return { id: row.id, kind: row.kind, ...(row.task_id === null ? {} : { taskId: row.task_id }), peers: JSON.parse(row.peers), limits, used, units, createdAt: row.created_at, updatedAt: row.updated_at,
|
|
181
|
+
...(override && typeof override.reason === "string" && typeof override.by === "string" && typeof override.at === "number" ? { override } : {}) };
|
|
161
182
|
}
|
package/src/hub/facts.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { isDenied } from "../local/deny.ts";
|
|
|
8
8
|
import { hubGitArgv, hubGitEnv } from "./git.ts";
|
|
9
9
|
import { realPath } from "./project.ts";
|
|
10
10
|
import { insideRoot } from "./path-policy.ts";
|
|
11
|
+
import { classifyShellWrite } from "./task-shell-command.ts";
|
|
12
|
+
import type { EditCounts, TurnEdits } from "./events.ts";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Turn-free facts (issue #108): what changed in an owner's files since it last acknowledged them, as a diff with who
|
|
@@ -88,6 +90,12 @@ export interface FactsOptions {
|
|
|
88
90
|
deny?: string[];
|
|
89
91
|
/** Configured private paths are never read or shown as automatic facts. */
|
|
90
92
|
privatePath?: (path: string) => boolean;
|
|
93
|
+
/** Optional host-only edit evidence; callbacks never decide whether a tool ran. */
|
|
94
|
+
onEdit?: (peer: PeerId, file: string, route: "edit" | "shell", grade: 1 | 2 | 3 | undefined) => void;
|
|
95
|
+
onDiagnosticRead?: (peer: PeerId) => void;
|
|
96
|
+
onUnknownShell?: (peer: PeerId) => void;
|
|
97
|
+
/** Active public task for edit evidence when no turn-free cohort exists. */
|
|
98
|
+
editTask?: (peer: PeerId) => number | undefined;
|
|
91
99
|
/** Bounded machine-local projection; absent retains raw/binary behavior. */
|
|
92
100
|
projection?: (file: string) => import("./text-projection.ts").ProjectedText | undefined;
|
|
93
101
|
}
|
|
@@ -140,7 +148,7 @@ export interface Offered {
|
|
|
140
148
|
}
|
|
141
149
|
|
|
142
150
|
export const MAX_RECEIPTS_PER_PEER = 256;
|
|
143
|
-
export interface ReadReceipt { sha256: string; scope: "full" | "partial"; at: number; turnId: string }
|
|
151
|
+
export interface ReadReceipt { sha256: string; scope: "full" | "partial"; at: number; turnId: string; ownerEpoch?: string }
|
|
144
152
|
|
|
145
153
|
export class Facts {
|
|
146
154
|
private readonly latest = new Map<string, Version>();
|
|
@@ -183,7 +191,7 @@ export class Facts {
|
|
|
183
191
|
*/
|
|
184
192
|
private readonly firstSeen = new Map<PeerId, Map<string, Version>>();
|
|
185
193
|
/** A tool call's observation before it ran, by Claude's tool use id. */
|
|
186
|
-
private readonly before = new Map<string, { peer: PeerId; file?: string; version?: Version }>();
|
|
194
|
+
private readonly before = new Map<string, { peer: PeerId; file?: string; version?: Version; shell?: { file: string; version: Version }[] }>();
|
|
187
195
|
/** Peers whose coverage notice went out in this tracking epoch. */
|
|
188
196
|
private readonly covered = new Set<PeerId>();
|
|
189
197
|
/** Each peer's native session or thread: a new one starts its views over. */
|
|
@@ -300,6 +308,7 @@ export class Facts {
|
|
|
300
308
|
this.unfollowed.clear(); // what was seen is forgotten: a notice about it would be stale
|
|
301
309
|
this.writes.clear();
|
|
302
310
|
this.receipts.clear();
|
|
311
|
+
this.tally.clear();
|
|
303
312
|
this.epoch = Date.now();
|
|
304
313
|
}
|
|
305
314
|
|
|
@@ -317,6 +326,30 @@ export class Facts {
|
|
|
317
326
|
return this.receipts.get(peer)?.get(`${task}\0${path}`);
|
|
318
327
|
}
|
|
319
328
|
|
|
329
|
+
/** #1556 T2: counts of the writes the hook saw this turn, per peer; counts only, never a path or a command. Memory only, cleared at `takeEdits`, `closeTask`-independent. */
|
|
330
|
+
private readonly tally = new Map<PeerId, { obs: "hook" | "stream"; e: EditCounts; s: EditCounts }>();
|
|
331
|
+
/** Grade one write of `path` for `peer`: 1 verified full read, 2 partial read only, 3 blind or stale, undefined when the pre-image is unknown (counted in the total only, never guessed). */
|
|
332
|
+
private grade(peer: PeerId, path: string, pre: string | undefined): 1 | 2 | 3 | undefined {
|
|
333
|
+
if (pre === undefined) return undefined;
|
|
334
|
+
const task = this.o.editTask?.(peer) ?? this.o.scope(peer)?.task?.id;
|
|
335
|
+
const r = task === undefined ? undefined : this.readReceipt(peer, task, path);
|
|
336
|
+
if (!r) return 3;
|
|
337
|
+
if (createHash("sha256").update(pre).digest("hex") !== r.sha256) return 3;
|
|
338
|
+
return r.scope === "full" ? 1 : 2;
|
|
339
|
+
}
|
|
340
|
+
private count(peer: PeerId, route: "e" | "s", grade: 1 | 2 | 3 | undefined, obs: "hook" | "stream" = "hook"): void {
|
|
341
|
+
let t = this.tally.get(peer);
|
|
342
|
+
if (!t) this.tally.set(peer, (t = { obs, e: [0, 0, 0, 0, 0], s: [0, 0, 0, 0, 0] }));
|
|
343
|
+
t[route][0]++;
|
|
344
|
+
if (grade !== undefined) t[route][grade]++;
|
|
345
|
+
}
|
|
346
|
+
/** The counts for the turn that just ended, or undefined when no write was seen (a read-only turn adds no field). Clears them. */
|
|
347
|
+
takeEdits(peer: PeerId): TurnEdits | undefined {
|
|
348
|
+
const t = this.tally.get(peer);
|
|
349
|
+
this.tally.delete(peer);
|
|
350
|
+
return t ? { obs: t.obs, ...(t.e[0] ? { e: t.e } : {}), ...(t.s[0] ? { s: t.s } : {}) } : undefined;
|
|
351
|
+
}
|
|
352
|
+
|
|
320
353
|
/** The task closed: its receipts go. */
|
|
321
354
|
closeTask(task: number): void {
|
|
322
355
|
for (const m of this.receipts.values()) for (const k of [...m.keys()]) if (k.startsWith(`${task}\0`)) m.delete(k);
|
|
@@ -328,6 +361,7 @@ export class Facts {
|
|
|
328
361
|
const was = this.sessions.get(peer);
|
|
329
362
|
this.sessions.set(peer, id);
|
|
330
363
|
if (was === undefined || was === id) return;
|
|
364
|
+
this.receipts.delete(peer);
|
|
331
365
|
this.accepted.delete(peer);
|
|
332
366
|
this.plansAccepted.delete(peer);
|
|
333
367
|
this.offers.delete(peer);
|
|
@@ -579,7 +613,10 @@ export class Facts {
|
|
|
579
613
|
const file = path ? this.rel(path) : undefined;
|
|
580
614
|
const version = file ? this.observe(file) : undefined;
|
|
581
615
|
if (toolUseId) {
|
|
582
|
-
|
|
616
|
+
const shell = tool === "Bash" && typeof input.command === "string" ? classifyShellWrite(input.command) : undefined;
|
|
617
|
+
if (shell?.kind === "unknown") try { this.o.onUnknownShell?.(peer); } catch { /* observation only */ }
|
|
618
|
+
const targets = shell?.kind === "write" ? shell.targets.flatMap(target => { const name = this.rel(target); return name ? [{ file: name, version: this.observe(name) }] : []; }) : [];
|
|
619
|
+
this.before.set(toolUseId, { peer, ...(file ? { file } : {}), ...(version ? { version } : {}), ...(targets.length ? { shell: targets } : {}) });
|
|
583
620
|
if (this.before.size > 256) this.before.delete(this.before.keys().next().value as string);
|
|
584
621
|
}
|
|
585
622
|
}
|
|
@@ -600,22 +637,34 @@ export class Facts {
|
|
|
600
637
|
this.wrote(peer, file);
|
|
601
638
|
const expected = !pre.version.projected && this.latest.get(file)?.hash === pre.version.hash ? applyEdit(pre.version.text, tool, input) : undefined;
|
|
602
639
|
const version = this.observe(file, expected === undefined ? undefined : { peer, expected: sha1(expected) });
|
|
640
|
+
if (pre.peer === peer && expected !== undefined && sha1(expected) === version.hash && version.hash !== pre.version.hash) {
|
|
641
|
+
const grade = this.grade(peer, file, pre.version.text); this.count(peer, "e", grade);
|
|
642
|
+
try { this.o.onEdit?.(peer, file, "edit", grade); } catch { /* observation cannot change a tool result */ }
|
|
643
|
+
}
|
|
603
644
|
const last = this.transitions.get(file)?.at(-1);
|
|
604
645
|
if (last?.seq === version.seq && last.by === peer && this.view(peer).get(file)?.hash === pre.version.hash) this.view(peer).set(file, version);
|
|
605
646
|
return this.observeAll();
|
|
606
647
|
}
|
|
607
648
|
if (tool === "Read") {
|
|
608
649
|
// #1556 T1: a read receipt per (peer, task, path), memory only. Unknown text (large or unreadable file) records nothing, never a guess.
|
|
609
|
-
const task = this.o.scope(peer)?.task?.id;
|
|
650
|
+
const task = this.o.editTask?.(peer) ?? this.o.scope(peer)?.task?.id;
|
|
610
651
|
if (task !== undefined && pre.version.text !== undefined) {
|
|
611
652
|
this.recordRead(peer, task, file, { sha256: createHash("sha256").update(pre.version.text).digest("hex"), scope: input.offset === undefined && input.limit === undefined && readWhole(pre.version.text) ? "full" : "partial", turnId: toolUseId ?? "" });
|
|
612
653
|
}
|
|
613
654
|
const version = this.observe(file);
|
|
655
|
+
if (pre.version.text !== undefined && version.hash === pre.version.hash && input.offset === undefined && input.limit === undefined && readWhole(pre.version.text)) try { this.o.onDiagnosticRead?.(peer); } catch { /* observation only */ }
|
|
614
656
|
// Only a whole read of an unchanged file says what the peer saw: no offset or limit, and nothing Read cuts.
|
|
615
657
|
if (!pre.version.projected && version.hash === pre.version.hash && input.offset === undefined && input.limit === undefined && readWhole(pre.version.text)) this.view(peer).set(file, version);
|
|
616
658
|
return this.observeAll();
|
|
617
659
|
}
|
|
618
660
|
}
|
|
661
|
+
if (tool === "Bash" && pre?.peer === peer && pre.shell) {
|
|
662
|
+
// Count each observed file modification, not a command that may touch several files or no file.
|
|
663
|
+
for (const target of pre.shell) if (this.load(target.file).hash !== target.version.hash) {
|
|
664
|
+
const grade = this.grade(peer, target.file, target.version.text); this.count(peer, "s", grade);
|
|
665
|
+
try { this.o.onEdit?.(peer, target.file, "shell", grade); } catch { /* observation only */ }
|
|
666
|
+
}
|
|
667
|
+
}
|
|
619
668
|
this.observeAll();
|
|
620
669
|
}
|
|
621
670
|
|
|
@@ -641,6 +690,10 @@ export class Facts {
|
|
|
641
690
|
this.wrote(peer, file);
|
|
642
691
|
const now = this.load(file);
|
|
643
692
|
const matches = was && !was.projected && !now.projected ? codexEffect(was.text, now, change, (a, b) => this.diff(a, b)) : false;
|
|
693
|
+
if (matches && was && was.hash !== now.hash) {
|
|
694
|
+
const grade = this.grade(peer, file, was.text); this.count(peer, "e", grade, "stream");
|
|
695
|
+
try { this.o.onEdit?.(peer, file, "edit", grade); } catch { /* observation only */ }
|
|
696
|
+
}
|
|
644
697
|
const version = this.observe(file, matches ? { peer, expected: now.hash } : undefined);
|
|
645
698
|
const last = this.transitions.get(file)?.at(-1);
|
|
646
699
|
if (was && last?.seq === version.seq && last.by === peer && this.view(peer).get(file)?.hash === was.hash) this.view(peer).set(file, version);
|
package/src/hub/hub-tools.ts
CHANGED
|
@@ -238,8 +238,10 @@ export const CAPABILITY_TOOLS = new Set(["hub_capabilities", "hub_capabilities_p
|
|
|
238
238
|
export const TASK_TOOLS: HubTool[] = [
|
|
239
239
|
tool("hub_roadmap_list", "Read public milestones with computed task/issue/spec/train progress. Private work is a count only; unknown evidence stays unknown. Read only, with no GitHub or model call.", {}),
|
|
240
240
|
tool("hub_roadmap_show", "Read a milestone's public links, inherited membership and computed progress. Inspect this before editing and copy its current revision. Private tasks are counts only.", { id: { type: "integer", minimum: 1 } }, ["id"]),
|
|
241
|
+
tool("hub_roadmap_check", "Read roadmap drift findings and unknown evidence. Private tasks stay withheld; no writes are made.", {}),
|
|
241
242
|
tool("hub_roadmap_unplaced", "Read the open GitHub issues, open board tasks and active/draft specs that no live milestone places, each with why. Private tasks are a count only. partial: true means the GitHub read stopped early or a list was cut, so the lists are a lower bound; unavailable names evidence that could not be read. Read only: no write, no model call. Optional repo is owner/name.", { repo: { type: "string", maxLength: MILESTONE_LIMITS.issue } }),
|
|
242
243
|
tool("hub_roadmap_triage", "Ask the hub's model to suggest a milestone (or a new one) for unplaced work. Each suggestion cites the milestone and item words it matched and is saved as a pending model answer; nothing is linked until hub_roadmap_edit accept. Configured planner or unique conductor only. list: true reads the pending public suggestions without a model call and is open to any agent.", { repo: { type: "string", maxLength: MILESTONE_LIMITS.issue }, list: { type: "boolean" } }),
|
|
244
|
+
tool("hub_roadmap_decompose", "Ask the hub's model to decompose one milestone into parts, from its outcome, the specs it links and the issues it links. Each part cites linked ids and says whether it needs a spec issue or goes straight to a task; the answer is saved as a pending model answer and nothing is linked, intaken or published. Pass accept with one part's number to hold that part as an intake draft instead: it is linked to the milestone, carries the part's spec-issue or task kind, and is offered to nobody until the person releases it with ahub intake approve. Pass publish true to preview the GitHub issues the milestone's held drafts would create (one per held spec part; a task part is its own held task, a released draft is skipped and a private part is only counted) without writing anything; publish true with apply true and the preview's confirm creates them behind roadmap.github_write and links each to the milestone, so a person or the configured conductor with that gate is required. Configured planner or unique conductor only. On refusal inspect hub_roadmap_show and correct the named input.", { id: { type: "integer", minimum: 1 }, accept: { type: "integer", minimum: 1 }, publish: { type: "boolean" }, apply: { type: "boolean" }, confirm: { type: "string", description: "the fingerprint the publish preview printed; required with apply" } }, ["id"]),
|
|
243
245
|
tool("hub_roadmap_edit", "Create or change a milestone. Configured planner or unique conductor only; done/dropped are person-only. new/edit take fields; edit also needs the current revision. Link kinds are spec/issue/task/release; issue refs are owner/repo#N. accept applies exactly one pending triage suggestion through link (creating its proposed milestone first); reject drops it. No GitHub write, task assignment or model call. On refusal inspect hub_roadmap_show and correct the named input.", {
|
|
244
246
|
op: { type: "string", enum: ["new", "edit", "link", "unlink", "order", "state", "accept", "reject"] }, id: { type: "integer", minimum: 1 }, revision: { type: "integer", minimum: 0 }, suggestion: { type: "integer", minimum: 1, description: "accept or reject: a pending suggestion id from hub_roadmap_triage" },
|
|
245
247
|
fields: { type: "object", additionalProperties: false, properties: {
|
|
@@ -284,7 +286,7 @@ export const TASK_TOOLS: HubTool[] = [
|
|
|
284
286
|
tool("hub_task_propose", "Put a piece of work on the shared task board. The hub assigns an owner by class (routing.toml) unless you name one. Classes: plan, implement, bulk_edit, test, review, summarize, triage. Name the class when you know it; without one the hub tries to pick it. Name yourself as owner to claim work nobody assigned you: it starts in progress. Put the paths the work touches in refs, set refs.repo for work in another repository, and when you claim work, a plan; the hub says when they overlap another open task.", { title: str, class: { type: "string", enum: ["plan", "implement", "bulk_edit", "test", "review", "summarize", "triage"] }, detail: str, role: { type: "string", description: "catalog role id for this task class; guidance only, no routing or authority change" }, refs, plan, owner: { type: "string", description: "peer id; yours to claim the work, omit to let the hub route it. With after, the owner is reserved: offered the task first once it is ready" }, after: { type: "array", items: { type: "integer" }, description: "ids of tasks that must be approved first; until then this one waits, offered to nobody, and cannot be claimed" }, backlog: { type: "boolean", description: "stage unoffered work; owner is only a reservation, even when naming yourself" }, urgent: { type: "boolean", description: "hand it over even when its owner is paused for quota only briefly" }, needs_network: { type: "boolean", description: "the work needs the network (a package registry, git fetch or push, an API); it is never offered to a peer whose shell has none" }, needs_worktree: { type: "boolean", description: "the work needs its own git worktree on a task branch (the repository rule); it is never offered to a sandboxed peer, which cannot create one" }, goal: { type: "string", description: "id of this project's long-term task (ahub goal list) the work is part of" } }, ["title"]),
|
|
285
287
|
tool("hub_task_accept", "Take a task that was assigned to you, with your plan for it. Set refs.repo for work in another repository; acceptance may correct only that repository metadata.", { id, plan: acceptPlan, refs: { ...refs, properties: { repo: refs.properties.repo } } }, ["id"]),
|
|
286
288
|
tool("hub_task_cancel", "Cancel proposed/backlog work you proposed as its configured planner, including work an owner accepted and then declined while it has no execution, branch, commit or PR evidence; work with any such evidence is person-only. The configured conductor may also cancel a task another project handed this one that nobody has accepted. Keeps history and does not stop a native turn or delete files.", { id, reason: str, superseded_by: str, revision: { type: "integer", minimum: 0 } }, ["id", "reason"]),
|
|
287
|
-
tool("hub_task_decline", "Pass on a task assigned to you; the hub offers it to the next peer. A plain decline is a lasting refusal: you are never offered this task again. Pass capacity: true
|
|
289
|
+
tool("hub_task_decline", "Pass on a task assigned to you; the hub offers it to the next peer. A plain decline is a lasting refusal: you are never offered this task again. Pass capacity: true whenever the reason is load: you are busy, at your WIP cap or running a job. You are then skipped until you next report idle, and the task goes back to its planner or the next peer. Leave capacity off only for \"I should never own this\".", { id, reason: str, capacity: { type: "boolean" } }, ["id"]),
|
|
288
290
|
tool("hub_task_done", "Mark your task finished. It goes to its reviewer with your summary and refs; no duplicate hub_send chat is needed. When re-filing work after review, set refs.commit to the new full SHA; summary text does not change the review head. If a covering spec is unchanged, update it or provide spec_ack with a public reason for each unchanged spec. When the project configures a check for its class, the hub runs it first and the result comes as a task message: a failed check keeps the task with you.", { id, summary: { type: "string", description: "what changed, why, and the check you ran with its result" }, refs, deliverables: deliverablesSchema, spec_ack: specAck, resolved: { type: "array", maxItems: 64, uniqueItems: true, items: str, description: "Sent person comment ids addressed by this admitted completion; this is an owner claim, not check or verdict proof" } }, ["id", "summary"]),
|
|
289
291
|
tool("hub_sdlc_record", "Record artifact ids or claimed local checks on your task. This grants no authority or external-check evidence. Only its owner/reviewer or the person may record; only its reviewer/person may name a reviewed head or phase checklist. Phase evidence refs are content hashes, not external verification.", { id, receipt: { type: "object", properties: { deliverables: deliverablesSchema, stage: { type: "string", enum: ["spec", "plan", "implement", "review", "verify", "merge", "release"] }, repo: str, issue: id, pr: id, localHead: str, localResult: { type: "string", enum: ["passed", "failed", "unknown"] }, reviewedHead: str, phase: { type: "object", properties: { id: str, head: str, tasks: { type: "array", maxItems: 64, items: { type: "object", properties: { id, after: { type: "array", maxItems: 16, items: id } }, required: ["id", "after"], additionalProperties: false } }, criteria: { type: "array", maxItems: 32, items: { type: "object", properties: { id: str, required: { type: "boolean" }, result: { type: "string", enum: ["verified", "failed", "unverified"] }, refs: { type: "array", maxItems: 8, items: str } }, required: ["id", "required", "result", "refs"], additionalProperties: false } } }, required: ["id", "tasks", "criteria"], additionalProperties: false } }, additionalProperties: false } }, ["id", "receipt"]),
|
|
290
292
|
tool("hub_task_list", "The task board, newest updated first, 50 compact rows (id, state, owner, reviewer, title) per call. The reply is {tasks, total, next?}: pass next as cursor for the following page. Use ids for full rows of specific tasks, or detail: true for full rows of a page. PII tasks show as [pii].", { state: { type: "string", enum: ["proposed", "in_progress", "in_review", "approved", "changes_requested", "cancelled"] }, ready: { type: "boolean", description: "only proposed tasks with nothing left to wait for" }, limit: { type: "integer", minimum: 1, maximum: 200, description: "rows per page, default 50" }, cursor: { type: "string", description: "the next value from the previous reply, unchanged" }, ids: { type: "array", minItems: 1, maxItems: 200, items: { type: "integer", minimum: 1 }, description: "full rows for exactly these task numbers; no paging" }, detail: { type: "boolean", description: "full rows instead of compact rows" } }),
|
package/src/hub/inference.ts
CHANGED
|
@@ -214,7 +214,7 @@ export interface PiiScreenDeps {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
/** With triage (8 s) and a brief (2 x 2 s), a proposal answers within 20 s, under the plugin's 30 s control timeout. */
|
|
217
|
-
const SCREEN_TIMEOUT_MS = 8_000;
|
|
217
|
+
export const SCREEN_TIMEOUT_MS = 8_000;
|
|
218
218
|
/** On campus, the share of the deadline the on-device model gets before the gateway takes over (a cold load, an error). */
|
|
219
219
|
const DEVICE_SHARE = 0.6;
|
|
220
220
|
/**
|
package/src/hub/instances.ts
CHANGED
|
@@ -19,11 +19,13 @@ export interface InstanceConfig {
|
|
|
19
19
|
readOnly?: boolean;
|
|
20
20
|
/** Jcode instances (#685): their own native data home, and optional model selection. A headless Claude implementer also takes `model` (#844). Machine-local, never editable from settings. */
|
|
21
21
|
jcode_home?: string;
|
|
22
|
+
/** Names of jcode MCP servers `ahub doctor` accepts for this instance; absent inherits the top-level list (#1621). */
|
|
23
|
+
jcode_mcp_allow?: string[];
|
|
22
24
|
provider?: string;
|
|
23
25
|
model?: string;
|
|
24
26
|
provider_profile?: string;
|
|
25
27
|
}
|
|
26
|
-
const JCODE_FIELDS = ["jcode_home", "provider", "model", "provider_profile"] as const;
|
|
28
|
+
const JCODE_FIELDS = ["jcode_home", "jcode_mcp_allow", "provider", "model", "provider_profile"] as const;
|
|
27
29
|
/** At most this many extra Jcode instances per project (#685). */
|
|
28
30
|
export const MAX_JCODE_INSTANCES = 8;
|
|
29
31
|
/** A flag value jcode takes as one argv word: bounded, printable, no spaces. */
|
|
@@ -58,6 +60,12 @@ function roles(value: unknown, field: string): string[] {
|
|
|
58
60
|
return out;
|
|
59
61
|
}
|
|
60
62
|
|
|
63
|
+
/** A jcode MCP allowlist (#1621): an array of nonempty, control-free names of at most 256 bytes, at most 64 of them. */
|
|
64
|
+
export function mcpAllowNames(value: unknown, field: string): string[] {
|
|
65
|
+
if (!Array.isArray(value) || value.length > 64 || value.some(name => typeof name !== "string" || !name.trim() || Buffer.byteLength(name) > 256 || /\p{Cc}/u.test(name))) return fail(field, "must be an array of at most 64 nonempty control-free server names");
|
|
66
|
+
return [...value] as string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
61
69
|
/** The Jcode-only fields of one declaration (#685). Only the validated values are copied; nothing is read twice. */
|
|
62
70
|
function jcodeInstanceFields(entry: Record<string, PropertyDescriptor>, path: string): Partial<InstanceConfig> {
|
|
63
71
|
const home: unknown = entry.jcode_home?.value;
|
|
@@ -70,6 +78,7 @@ function jcodeInstanceFields(entry: Record<string, PropertyDescriptor>, path: st
|
|
|
70
78
|
if (!isNativeModelToken(word)) return fail(`${path}.${key}`, "must be one bounded printable word without spaces");
|
|
71
79
|
out[key] = word;
|
|
72
80
|
}
|
|
81
|
+
if (entry.jcode_mcp_allow) out.jcode_mcp_allow = mcpAllowNames(entry.jcode_mcp_allow.value, `${path}.jcode_mcp_allow`);
|
|
73
82
|
if (entry.start_mode && entry.start_mode.value !== "headless") return fail(`${path}.start_mode`, "a Jcode instance starts headless");
|
|
74
83
|
return out;
|
|
75
84
|
}
|