@staix/agent-hub 0.35.0 → 0.37.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 +43 -0
- package/README.md +25 -4
- package/THIRD_PARTY_NOTICES.md +0 -18
- package/docs/agent-notes/README.md +71 -1
- package/docs/agent-notes/adapters.md +5 -2
- package/docs/agent-notes/bus.md +1 -0
- package/docs/agent-notes/daemon.md +7 -6
- package/docs/agent-notes/local-worker.md +1 -0
- package/docs/agent-notes/models.md +5 -3
- package/docs/agent-notes/tasks.md +9 -2
- package/docs/agent-notes/tests.md +1 -1
- package/docs/contracts/companion-cli-v1.json +70 -0
- package/docs/design/adapters.md +115 -2
- package/docs/design/agent-hub-architecture.md +10 -2
- package/docs/design/bus.md +8 -0
- package/docs/design/execution-reference.md +171 -11
- package/docs/design/guidance-experiments.md +438 -0
- package/docs/design/guidance-probes.md +802 -0
- package/docs/design/model-routes.md +1053 -0
- package/docs/design/supervision.md +121 -0
- package/docs/design/task-board.md +111 -0
- package/docs/dogfood.md +24 -15
- package/docs/events.md +20 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +366 -133
- package/docs/profiles.md +2 -2
- package/docs/quickstart.md +114 -3
- package/docs/research.md +5 -3
- package/docs/sdlc.md +113 -7
- package/docs/security.md +88 -6
- package/docs/specs/2026-09-19-agent-hub-design.md +14 -11
- package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
- package/docs/verification/2026-10-25-qwen-dual-output-t0.md +22 -0
- package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
- package/docs/verification/2026-11-09-qwen-0270-acp.md +181 -0
- package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +61 -0
- package/docs/verification/2026-11-10-0.36.0.md +59 -0
- package/docs/verification/2026-11-10-claude-implementer-2.1.322.md +59 -0
- package/docs/verification/2026-11-10-qwen-0270-dual-output.md +367 -0
- package/docs/verification/2026-11-10-qwen-0271-dual-output.md +101 -0
- package/docs/verification/2026-11-11-0.37.0.md +40 -0
- package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
- package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
- package/docs/verification/claude-shell-wrapper-native.py +1 -1
- package/docs/verified.json +27 -27
- package/package.json +3 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +3570 -1800
- package/plugins/agent-hub/server.js +4112 -1913
- package/src/adapters/channel-peer.ts +7 -1
- package/src/adapters/claude-channel.ts +7 -4
- package/src/adapters/compat.ts +10 -10
- package/src/adapters/local-probe.ts +174 -0
- package/src/adapters/local-worker.ts +233 -22
- package/src/adapters/qwen-dual.ts +324 -44
- package/src/cli/console-state.ts +25 -6
- package/src/cli/console-versions.ts +99 -0
- package/src/cli/console.ts +13 -1
- package/src/cli/guidance.ts +67 -0
- package/src/cli/help.ts +12 -4
- package/src/cli/identity.ts +10 -3
- package/src/cli/init-prompt.ts +15 -2
- package/src/cli/init-required-checks.ts +122 -0
- package/src/cli/init-settings.ts +10 -4
- package/src/cli/init.ts +39 -3
- package/src/cli/install-paths.ts +7 -2
- package/src/cli/lineage.ts +78 -0
- package/src/cli/main.ts +171 -14
- package/src/cli/runtime-version-warning.ts +2 -2
- package/src/cli/sdlc-output.ts +9 -5
- package/src/cli/setup-research.ts +10 -0
- package/src/hub/autonomy-defaults.ts +20 -9
- package/src/hub/board.ts +346 -4
- package/src/hub/build-entry.ts +11 -0
- package/src/hub/bus.ts +12 -0
- package/src/hub/ci-watch.ts +4 -4
- package/src/hub/config-apply.ts +6 -3
- package/src/hub/config-trust.ts +7 -1
- package/src/hub/control-client.ts +5 -2
- package/src/hub/daemon.ts +508 -26
- package/src/hub/delivery-hints.ts +4 -2
- package/src/hub/delivery-journal.ts +50 -2
- package/src/hub/delivery-public.ts +51 -0
- package/src/hub/dogfood-profile.ts +8 -4
- package/src/hub/events.ts +3 -2
- package/src/hub/execution-lineage-owner.ts +272 -0
- package/src/hub/execution-lineage.ts +52 -8
- package/src/hub/execution-links.ts +85 -0
- package/src/hub/guidance-probe-store.ts +713 -0
- package/src/hub/guidance-probes.ts +358 -0
- package/src/hub/guidance-variants.ts +398 -0
- package/src/hub/handoff.ts +1 -0
- package/src/hub/hub-tools.ts +43 -2
- package/src/hub/inference.ts +18 -5
- package/src/hub/manager.ts +44 -2
- package/src/hub/memory-policy.ts +2 -2
- package/src/hub/operational-authority.ts +13 -1
- package/src/hub/peers.ts +6 -1
- package/src/hub/planning.ts +1 -1
- package/src/hub/ports.ts +1 -1
- package/src/hub/progress.ts +47 -23
- package/src/hub/report.ts +2 -0
- package/src/hub/research.ts +1 -0
- package/src/hub/restart.ts +20 -0
- package/src/hub/roles.ts +26 -0
- package/src/hub/routing.ts +4 -1
- package/src/hub/sdlc-merge.ts +39 -1
- package/src/hub/sdlc-release-authorization.ts +139 -17
- package/src/hub/sdlc-release-policy.ts +100 -0
- package/src/hub/sdlc-release.ts +60 -8
- package/src/hub/sdlc.ts +62 -11
- package/src/hub/settings.ts +2 -0
- package/src/hub/supervision-proposals.ts +405 -0
- package/src/hub/supervision-rules.ts +388 -0
- package/src/hub/supervision.ts +2 -0
- package/src/hub/task-approval.ts +2 -2
- package/src/hub/task-repository.ts +5 -0
- package/src/hub/tasks.ts +917 -53
- package/src/local/probe-errors.ts +28 -0
- package/src/local/probe-sandbox.ts +224 -0
- package/src/local/probe-types.ts +108 -0
- package/src/local/probe-workspace.ts +237 -0
- package/src/local/sandbox.ts +71 -2
- package/src/local/tools.ts +135 -9
- package/src/memory/capture.ts +2 -2
- package/src/models/relay.ts +9 -2
- package/src/models/route/advisor-trigger.ts +88 -0
- package/src/models/route/config.ts +39 -8
- package/src/models/route/conversation-view.ts +179 -0
- package/src/models/route/decision-evidence.ts +1 -1
- package/src/models/route/decision.ts +193 -26
- package/src/models/route/escalation-control.ts +30 -0
- package/src/models/route/hub-prompts.ts +97 -0
- package/src/models/route/judge-choice.ts +155 -0
- package/src/models/route/judge-replies.ts +102 -0
- package/src/models/route/labels.ts +14 -70
- package/src/models/route/observation-signals.ts +250 -0
- package/src/models/route/plan-execute-choice.ts +27 -0
- package/src/models/route/relay-selector.ts +10 -9
- package/src/models/route/runtime.ts +129 -60
- package/src/models/route/stage-diagnostics.ts +22 -0
- package/src/models/route/stage-evidence.ts +55 -0
- package/src/models/route/stage-fallback.ts +58 -0
- package/src/models/route/stage-input.ts +155 -0
- package/src/models/route/stage.ts +5 -147
- package/src/models/route/turn-state.ts +77 -0
- package/src/omniroute/client.ts +3 -0
- package/src/ui/guidance-panel.ts +156 -0
- package/src/ui/guidance-view.ts +43 -0
- package/src/ui/lineage-view.ts +34 -0
- package/src/ui/plugin.ts +141 -27
- package/src/version.ts +4 -0
- package/templates/adec/README.md +32 -0
- package/templates/adec/ahub.plan-execute.json +23 -0
- package/templates/adec/ahub.stage.json +23 -0
- package/LICENSES/Apache-2.0.txt +0 -204
- package/src/models/route/advisor.ts +0 -102
- package/src/models/route/escalation.ts +0 -82
- package/src/models/route/judge.ts +0 -23
- package/src/models/route/normalize.ts +0 -103
- package/src/models/route/plan-execute.ts +0 -52
- package/src/models/route/prompts.ts +0 -8
- package/src/models/route/signals.ts +0 -247
- package/src/models/route/state.ts +0 -54
- package/src/models/route/text.ts +0 -61
|
@@ -7,7 +7,7 @@ import type { ClaudeChannelEvidence } from "./claude-channel-evidence.ts";
|
|
|
7
7
|
/** Only the control socket operations the peer owns; authentication remains in the daemon. */
|
|
8
8
|
export interface ChannelSocket {
|
|
9
9
|
readyState: number;
|
|
10
|
-
data: { launchId?: string; protocol?: number; standbyId?: string; retainStandby?: boolean; clientPid?: number; channel?: boolean; channelEvidence?: ClaudeChannelEvidence; cwd?: string; peerGeneration?: string | number; detachedByPerson?: boolean };
|
|
10
|
+
data: { launchId?: string; protocol?: number; standbyId?: string; retainStandby?: boolean; clientPid?: number; clientVersion?: string; channel?: boolean; channelEvidence?: ClaudeChannelEvidence; cwd?: string; peerGeneration?: string | number; detachedByPerson?: boolean };
|
|
11
11
|
send(data: string): unknown;
|
|
12
12
|
close(code?: number, reason?: string): void;
|
|
13
13
|
}
|
|
@@ -137,6 +137,12 @@ export class WsPeer extends BasePeer {
|
|
|
137
137
|
},
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
/** #1385: whether a client is attached and the agent-hub version its hello reported (validated at hello). Display only. */
|
|
141
|
+
get hubClient(): { attached: boolean; version?: string } {
|
|
142
|
+
const sock = this.sock;
|
|
143
|
+
if (!sock || sock.readyState !== WebSocket.OPEN) return { attached: false };
|
|
144
|
+
return sock.data.clientVersion ? { attached: true, version: sock.data.clientVersion } : { attached: true };
|
|
145
|
+
}
|
|
140
146
|
/** A hello that has not finished its preface yet. The peer reads as offline until then, and a session standing by
|
|
141
147
|
* for the id must not take it from a claimant that is still arriving. */
|
|
142
148
|
get claiming(): boolean {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { renderHeldInbox } from "../hub/delivery-public.ts";
|
|
1
2
|
import { realPath } from "../hub/project.ts";
|
|
2
3
|
import { readInstanceConfig } from "../hub/instance-config.ts";
|
|
3
4
|
import { effectiveInstanceRoles } from "../hub/instances.ts";
|
|
@@ -479,11 +480,12 @@ async function callTool(req: { params: { name: string; arguments?: Record<string
|
|
|
479
480
|
return text(result.ok ? "delivery completed" : `not completed: ${result.error}`);
|
|
480
481
|
}
|
|
481
482
|
if (name === "hub_inbox" && (!toolsMode || permissionTool)) {
|
|
482
|
-
let remote: string[] = [], notice = "", polling = "", counted = false, heldHint = "", metadataWarning = "", heldMetadata: unknown;
|
|
483
|
+
let remote: string[] = [], notice = "", polling = "", counted = false, heldHint = "", metadataWarning = "", heldBodies = "", heldMetadata: unknown;
|
|
483
484
|
if (hub) {
|
|
484
485
|
try {
|
|
485
486
|
const res = await hub.request({ t: "inbox" });
|
|
486
487
|
heldMetadata = res.held;
|
|
488
|
+
try { heldBodies = renderHeldInbox(res.heldRead); } catch { heldBodies = "Held message bodies are unavailable; inspect the queue before repeating an action."; }
|
|
487
489
|
const metadataUnavailable = heldMetadataUnavailable(res.held);
|
|
488
490
|
heldHint = renderHeldHint(res.held, Date.now(), !deliveryOnly);
|
|
489
491
|
if (metadataUnavailable) metadataWarning = `Delivery confirmation metadata is unavailable; inspect ahub queue list --peer ${sanitize(peerId)} before deciding whether anything is waiting.`;
|
|
@@ -492,7 +494,7 @@ async function callTool(req: { params: { name: string; arguments?: Record<string
|
|
|
492
494
|
else {
|
|
493
495
|
pendingQueued = { queued: typeof res.waiting === "number" ? res.waiting : 0, important: typeof res.waitingImportant === "number" ? res.waitingImportant : 0 };
|
|
494
496
|
remote = (res.envs as Envelope[]).map(frame);
|
|
495
|
-
if (!heldHint && Number.isSafeInteger(res.pollingAdvice?.count) && res.pollingAdvice.count >= 3 && Number.isSafeInteger(res.pollingAdvice?.minutes) && res.pollingAdvice.minutes >= 0 && res.pollingAdvice.minutes <= 10) polling = `[polling detected] ${res.pollingAdvice.count} empty reads in ${res.pollingAdvice.minutes} min with no assigned work: end your turn`;
|
|
497
|
+
if (!heldHint && !heldBodies && Number.isSafeInteger(res.pollingAdvice?.count) && res.pollingAdvice.count >= 3 && Number.isSafeInteger(res.pollingAdvice?.minutes) && res.pollingAdvice.minutes >= 0 && res.pollingAdvice.minutes <= 10) polling = `[polling detected] ${res.pollingAdvice.count} empty reads in ${res.pollingAdvice.minutes} min with no assigned work: end your turn`;
|
|
496
498
|
// #713: a pull drains what fits one read; what is left is said plainly, with what to do about it. The count already says how many remain, so the pending hint adds only the important ones (#221).
|
|
497
499
|
if (res.waiting) { notice = `(${res.waiting} more waiting: call hub_inbox again before you start work)`; counted = true; }
|
|
498
500
|
}
|
|
@@ -503,13 +505,14 @@ async function callTool(req: { params: { name: string; arguments?: Record<string
|
|
|
503
505
|
if (notice) out.push(notice);
|
|
504
506
|
if (heldHint) out.push(heldHint);
|
|
505
507
|
if (metadataWarning) out.push(metadataWarning);
|
|
506
|
-
let body = out.length ? out.join("\n\n") : "(no queued hub messages)\nNothing is waiting. Do not poll: if you have no assigned task, report and end your turn; new work waits here for your next boundary.";
|
|
508
|
+
let body = out.length ? out.join("\n\n") : heldBodies ? "(no queued hub messages)" : "(no queued hub messages)\nNothing is waiting. Do not poll: if you have no assigned task, report and end your turn; new work waits here for your next boundary.";
|
|
507
509
|
if (out.length === 1 && out[0] === heldHint && heldHint && heldMetadataNeedsReviewOnly(heldMetadata)) {
|
|
508
510
|
body = `(no queued hub messages)\n\n${body}`;
|
|
509
511
|
}
|
|
510
512
|
const result = text(polling ? `${body}\n${polling}` : body);
|
|
513
|
+
if (heldBodies) result.content.push({ type: "text", text: heldBodies });
|
|
511
514
|
if (counted) Object.defineProperty(result, QUEUED_COUNTED, { value: true });
|
|
512
|
-
if (heldHint || metadataWarning) Object.defineProperty(result, HELD_HINT_INCLUDED, { value: true });
|
|
515
|
+
if (heldHint || heldBodies || metadataWarning) Object.defineProperty(result, HELD_HINT_INCLUDED, { value: true });
|
|
513
516
|
return detached === "detached by the person" ? { ...result, isError: true } : result;
|
|
514
517
|
}
|
|
515
518
|
if (name === "hub_send") {
|
package/src/adapters/compat.ts
CHANGED
|
@@ -34,11 +34,11 @@ export const COMPAT = {
|
|
|
34
34
|
parse: out => plain(out.trim()),
|
|
35
35
|
trustNote: "The model-free extension load, RPC session identity and managed tool receipt path were checked on 1.4.0 and 1.5.0. Permissions remain host-owned; account-backed inference and another version's extension contract are unverified.",
|
|
36
36
|
receipt: "docs/verification/2026-11-03-pi-150-compat.md" },
|
|
37
|
-
// Transport receipts: docs/verification/2026-10-23-headless-claude-permissions.md; 2.1.310: docs/verification/2026-10-26-claude-implementer-2.1.310.md; 2.1.314 (transport and wrapper): docs/verification/2026-10-31-claude-implementer-2.1.314.md; 2.1.316: docs/verification/2026-10-31-claude-implementer-2.1.316.md; 2.1.318: docs/verification/2026-11-05-claude-implementer-2.1.318.md; 2.1.319: docs/verification/2026-11-06-claude-implementer-2.1.319.md; host-wrapper receipt below repeats with them.
|
|
38
|
-
"claude-implementer": { label: "Claude headless implementer", verified: ["2.1.309", "2.1.310", "2.1.314", "2.1.316", "2.1.318", "2.1.319"], gate: "contract", probe: ["claude", "--version"],
|
|
37
|
+
// Transport receipts: docs/verification/2026-10-23-headless-claude-permissions.md; 2.1.310: docs/verification/2026-10-26-claude-implementer-2.1.310.md; 2.1.314 (transport and wrapper): docs/verification/2026-10-31-claude-implementer-2.1.314.md; 2.1.316: docs/verification/2026-10-31-claude-implementer-2.1.316.md; 2.1.318: docs/verification/2026-11-05-claude-implementer-2.1.318.md; 2.1.319: docs/verification/2026-11-06-claude-implementer-2.1.319.md; 2.1.322: docs/verification/2026-11-10-claude-implementer-2.1.322.md; host-wrapper receipt below repeats with them.
|
|
38
|
+
"claude-implementer": { label: "Claude headless implementer", verified: ["2.1.309", "2.1.310", "2.1.314", "2.1.316", "2.1.318", "2.1.319", "2.1.322"], gate: "contract", probe: ["claude", "--version"],
|
|
39
39
|
parse: out => plain(out.trim().replace(/ \(Claude Code\)$/, "")),
|
|
40
40
|
trustNote: "The native prompt-tool transport and host-wrapper rewrite, environment isolation and replay contract have isolated receipts. No dontAsk/bypass fallback exists; another version's permission or rewrite behavior is unverified.",
|
|
41
|
-
receipt: "docs/verification/2026-11-
|
|
41
|
+
receipt: "docs/verification/2026-11-10-claude-implementer-2.1.322.md" },
|
|
42
42
|
// 0.163.0 receipt: docs/verification/2026-10-22-codex-reviewer-isolation.md; 0.164.0 receipt: docs/verification/2026-10-24-codex-0164-reviewer-isolation.md; 0.166.0: docs/verification/2026-10-31-codex-0166-reviewer-isolation.md; 0.167.0 model-free only, not verified until its model-backed run: docs/verification/2026-11-06-codex-0167-reviewer-isolation.md
|
|
43
43
|
"codex-review": { label: "Codex reviewer (codex-cli)", verified: ["0.146.0", "0.163.0", "0.164.0", "0.166.0"], gate: "isolation", probe: ["codex", "--version"], config: "codex_bin",
|
|
44
44
|
parse: out => plain(out.trim().replace(/^codex-cli /, "")),
|
|
@@ -62,16 +62,16 @@ export const COMPAT = {
|
|
|
62
62
|
parse: out => plain(out.trim()),
|
|
63
63
|
trustNote: "Exact 1.5.3 repeats the account-free CLI/plugin MCP, hooks, normal close and actual-launcher nonce legs; existing 1.4.x verified receipts remain unchanged. Other 1.5.x versions, real model/account behavior, headless ACP and native permission mappings remain unverified.",
|
|
64
64
|
receipt: "docs/verification/2026-11-08-agy-1.5.3.md" },
|
|
65
|
-
qwen: { label: "Qwen Code", verified: ["0.25.0", "0.26.0", "0.26.1", "0.26.4", "0.26.5", "0.26.8", "0.26.9"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
65
|
+
qwen: { label: "Qwen Code", verified: ["0.25.0", "0.26.0", "0.26.1", "0.26.4", "0.26.5", "0.26.8", "0.26.9", "0.27.0"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
66
66
|
parse: out => plain(out.trim()),
|
|
67
|
-
trustNote: "Native ACP identity, mode ids and permission callbacks were re-checked without inference on 0.26.4, 0.26.5 and 0.26.8 (macOS arm64 and Linux x86_64); exact 0.26.9
|
|
68
|
-
receipt: "docs/verification/2026-11-
|
|
69
|
-
// Receipt: docs/verification/2026-10-
|
|
67
|
+
trustNote: "Native ACP identity, mode ids and permission callbacks were re-checked without inference on 0.26.4, 0.26.5 and 0.26.8 (macOS arm64 and Linux x86_64); exact 0.26.9 and 0.27.0 repeat those account-free probes on macOS arm64. Real model turns and Linux repetition of those versions remain unverified. The historical A/B/B setter result did not identify the third request's purpose. Exact 0.26.9 and 0.27.0 pass isolated suggestions-off A/B/clear/A probes; production live-setter admission stays unavailable pending a separate decision. Another version may change those contracts.",
|
|
68
|
+
receipt: "docs/verification/2026-11-09-qwen-0270-acp.md" },
|
|
69
|
+
// Receipt: docs/verification/2026-11-10-qwen-0271-dual-output.md. The dual-output contract (input file, event file, can_use_tool control requests) is its own entry:
|
|
70
70
|
// the ACP receipts of the headless `qwen` entry say nothing about it, so that entry is not widened and this one carries no `line`.
|
|
71
|
-
"qwen-dual": { label: "Qwen Code dual-output TUI", verified: ["0.26.1"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
71
|
+
"qwen-dual": { label: "Qwen Code dual-output TUI", verified: ["0.26.1", "0.27.0", "0.27.1"], gate: "contract", probe: ["qwen", "--version"], config: "qwen_cmd",
|
|
72
72
|
parse: out => plain(out.trim()),
|
|
73
|
-
trustNote: "
|
|
74
|
-
receipt: "docs/verification/2026-10-
|
|
73
|
+
trustNote: "Exact 0.27.0 and 0.27.1 each repeat normal-Bus Q2 and account-free normal-mode Q3/Q5/Q6/Q7 on macOS arm64 against a matched control (0.26.1, then 0.27.0). Existing deny and external-stop limits remain. Real model/account turns, Linux and lifetime containment remain unverified; direct busy-submit characterization is separate from normal-Bus Q2.",
|
|
74
|
+
receipt: "docs/verification/2026-11-10-qwen-0271-dual-output.md" },
|
|
75
75
|
} as const satisfies Record<string, CompatPolicy>;
|
|
76
76
|
export type CompatId = keyof typeof COMPAT;
|
|
77
77
|
type CommandConfig = { codex_bin: string; jcode_cmd: string[]; qwen_cmd: string[]; pi?: { cmd: string[] } };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { LocalPeer, localProbeFingerprints, prepareLocalProbeInput } from "./local-worker.ts";
|
|
3
|
+
import { GUIDANCE_PROBE_LIMITS, GUIDANCE_PROBE_MODEL, guidanceProbeCanonical, guidanceProbeManifestKey, probeHash,
|
|
4
|
+
type ProbeFakeLaunch, type ProbeFakeObservation, type ProbeReservation, type ProbeResourceCharges, type ProbeSlot, type ProbeStoredState } from "../hub/guidance-probes.ts";
|
|
5
|
+
import { materializeProbeWorkspace, probeWorkspaceCurrent, PROBE_WORKSPACE_LIMITS,
|
|
6
|
+
type ProbeWorkspace } from "../local/probe-workspace.ts";
|
|
7
|
+
import { ProbeConfinementError, requireProbeConfinement, verifyProbeConfinement, type ProbeConfinement } from "../local/probe-sandbox.ts";
|
|
8
|
+
import { ProbeLocalError, probeLocalEffect, type ProbeLocalAdapter, type ProbeLocalAdapterOptions, type ProbeLocalEffectScope,
|
|
9
|
+
type ProbeLocalSource, type ProbePreparedLocalInput } from "../local/probe-types.ts";
|
|
10
|
+
|
|
11
|
+
interface Prepared {
|
|
12
|
+
state: ProbeStoredState;
|
|
13
|
+
slot: ProbeSlot;
|
|
14
|
+
guidance: string;
|
|
15
|
+
source: ProbeLocalSource;
|
|
16
|
+
input: ProbePreparedLocalInput;
|
|
17
|
+
}
|
|
18
|
+
interface Owned {
|
|
19
|
+
reservation: ProbeReservation;
|
|
20
|
+
controller: AbortController;
|
|
21
|
+
promise?: Promise<ProbeFakeObservation>;
|
|
22
|
+
peer?: LocalPeer;
|
|
23
|
+
workspace?: ProbeWorkspace;
|
|
24
|
+
confinement?: ProbeConfinement;
|
|
25
|
+
closeUnknown?: () => Promise<void>;
|
|
26
|
+
closed: boolean;
|
|
27
|
+
closeFailed?: boolean;
|
|
28
|
+
}
|
|
29
|
+
const bytesHash = (bytes: Uint8Array) => createHash("sha256").update(bytes).digest("hex");
|
|
30
|
+
const reservationKey = (reservation: ProbeReservation) => probeHash(guidanceProbeCanonical(reservation));
|
|
31
|
+
const positiveCharge = (charges: ProbeResourceCharges) => Object.values(charges).some(value => typeof value === "number" && value > 0);
|
|
32
|
+
function freeze<T>(value: T): T {
|
|
33
|
+
if (value && typeof value === "object") { for (const child of Object.values(value)) freeze(child); Object.freeze(value); }
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Constructor-only host adapter. No runtime, configuration or wire path selects this factory. */
|
|
38
|
+
export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOptions): ProbeLocalAdapter {
|
|
39
|
+
if (options.fixture && options.fixture.evidence !== "fixture_only") throw new ProbeLocalError("invalid");
|
|
40
|
+
const current = options.current.bind(options), resolveInput = options.resolveInput.bind(options), permit = options.permit.bind(options), omni = options.omni;
|
|
41
|
+
const workspaceOwned = options.workspaceOwned?.bind(options);
|
|
42
|
+
const fixture = options.fixture && Object.freeze({ materialize: options.fixture.materialize.bind(options.fixture), confine: options.fixture.confine.bind(options.fixture) });
|
|
43
|
+
const config = Object.freeze({ maxSteps: options.config.maxSteps, maxOutputTokens: options.config.maxOutputTokens,
|
|
44
|
+
...(options.config.tokenUpperBound === undefined ? {} : { tokenUpperBound: options.config.tokenUpperBound }) });
|
|
45
|
+
const prepared = new Map<string, Prepared>(), owned = new Map<string, Owned>(), completed = new WeakSet<ProbeReservation>();
|
|
46
|
+
const prepare = async (state: ProbeStoredState, slot: ProbeSlot, guidance: string): Promise<Prepared> => {
|
|
47
|
+
current();
|
|
48
|
+
state = freeze(JSON.parse(JSON.stringify(state)) as ProbeStoredState);
|
|
49
|
+
slot = freeze({ ...slot });
|
|
50
|
+
const resolved = await resolveInput(state, slot); current();
|
|
51
|
+
const source: ProbeLocalSource = { files: resolved.files.map(file => ({ dataId: file.dataId, relative: file.relative, sha256: file.sha256, bytes: Buffer.from(file.bytes) })),
|
|
52
|
+
verifySource: resolved.verifySource, ...(resolved.sourceTree ? { sourceTree: { repo: resolved.sourceTree.repo, tree: { ...resolved.sourceTree.tree }, files: resolved.sourceTree.files.map(file => ({ ...file })) } } : {}) };
|
|
53
|
+
const ids = new Set<string>(), policy = state.registration.snapshots.dataPolicy, role = policy.roles[slot.role];
|
|
54
|
+
for (const file of source.files) {
|
|
55
|
+
const declared = policy.admittedData.find(item => item.id === file.dataId);
|
|
56
|
+
if (ids.has(file.dataId) || !role.dataIds.includes(file.dataId) || !declared || declared.sha256 !== file.sha256
|
|
57
|
+
|| declared.bytes !== file.bytes.byteLength || bytesHash(file.bytes) !== file.sha256 || file.bytes.byteLength > PROBE_WORKSPACE_LIMITS.fileBytes)
|
|
58
|
+
throw new ProbeLocalError("invalid");
|
|
59
|
+
ids.add(file.dataId);
|
|
60
|
+
}
|
|
61
|
+
if (source.sourceTree && guidanceProbeCanonical(source.sourceTree.tree) !== guidanceProbeCanonical(state.registration.manifest.inputs.codeTree))
|
|
62
|
+
throw new ProbeLocalError("drift");
|
|
63
|
+
const descriptors = source.files.map(file => ({ dataId: file.dataId, relative: file.relative, sha256: file.sha256, bytes: file.bytes.byteLength }));
|
|
64
|
+
const input = freeze(prepareLocalProbeInput(state, slot, guidance, descriptors, config)), record = { state, slot, guidance, source, input };
|
|
65
|
+
if (slot.role === "worker" && slot.arm !== "baseline") {
|
|
66
|
+
const baseline = [...state.sessions].reverse().find(session => session.state === "closed_fixture" && session.coverage.coverageVerified
|
|
67
|
+
&& state.registration.manifest.slots.some(item => item.id === session.slotId && item.role === "worker" && item.arm === "baseline"));
|
|
68
|
+
const baselineSlot = baseline && state.registration.manifest.slots.find(item => item.id === baseline.slotId);
|
|
69
|
+
if (!baselineSlot || baseline?.state !== "closed_fixture" || !baseline.coverage.coverageVerified
|
|
70
|
+
|| baseline.coverage.inputFrameSha256 !== prepareLocalProbeInput(state, baselineSlot, state.binding.baselineGuidance, descriptors, config).inputSha256)
|
|
71
|
+
throw new ProbeLocalError("drift");
|
|
72
|
+
}
|
|
73
|
+
const key = `${guidanceProbeManifestKey(state.registration.manifest)}:${slot.id}`;
|
|
74
|
+
prepared.delete(key); prepared.set(key, record);
|
|
75
|
+
// Only preparation entries are evicted; no retained execution, budget or experiment is reset.
|
|
76
|
+
while (prepared.size > GUIDANCE_PROBE_LIMITS.slots) prepared.delete(prepared.keys().next().value!);
|
|
77
|
+
return record;
|
|
78
|
+
};
|
|
79
|
+
const close = async (entry: Owned, retry = false): Promise<void> => {
|
|
80
|
+
if (entry.closed) return;
|
|
81
|
+
if (entry.closeFailed && !retry) throw new ProbeLocalError("interrupted");
|
|
82
|
+
try {
|
|
83
|
+
if (entry.peer) await entry.peer.stopProbe();
|
|
84
|
+
else if (entry.confinement) await entry.confinement.stop();
|
|
85
|
+
if (entry.closeUnknown) await entry.closeUnknown();
|
|
86
|
+
entry.closed = true;
|
|
87
|
+
} catch { entry.closeFailed = true; throw new ProbeLocalError("interrupted"); }
|
|
88
|
+
};
|
|
89
|
+
const observation = (input: ProbeFakeLaunch, ready: Prepared, servedModel: string | null, outcome: ProbeFakeObservation["outcome"], usage: ProbeFakeObservation["usage"]): ProbeFakeObservation => ({
|
|
90
|
+
reservation: input.reservation, outcome, servedModel, inputFrameHash: ready.input.inputSha256,
|
|
91
|
+
workerEffectiveInputHash: input.slot.role === "worker" ? ready.input.inputSha256 : null,
|
|
92
|
+
nonGuidanceInputSha256: input.slot.role === "worker" ? ready.input.nonGuidanceInputSha256 : null,
|
|
93
|
+
candidateArtifactSha256: null, usage,
|
|
94
|
+
});
|
|
95
|
+
return {
|
|
96
|
+
prepareWorkerFrame: async (state, slot, guidance) => {
|
|
97
|
+
const record = await prepare(state, slot, guidance);
|
|
98
|
+
return { inputFrame: record.input.inputFrame, nonGuidanceInputSha256: record.input.nonGuidanceInputSha256 };
|
|
99
|
+
},
|
|
100
|
+
prepareEditorFrame: async (state, slot) => (await prepare(state, slot, state.binding.baselineGuidance)).input.inputFrame,
|
|
101
|
+
ports: {
|
|
102
|
+
launch(input, effects, signal) {
|
|
103
|
+
current();
|
|
104
|
+
const key = `${guidanceProbeManifestKey(input.manifest)}:${input.slot.id}`, ready = prepared.get(key), id = reservationKey(input.reservation);
|
|
105
|
+
if (!ready || owned.has(id) || signal.aborted || input.purpose !== "guidance_probe" || ready.input.role !== input.slot.role
|
|
106
|
+
|| input.inputFrame !== ready.input.inputFrame || input.inputSha256 !== ready.input.inputSha256
|
|
107
|
+
|| input.slot.role === "worker" && input.nonGuidanceInputSha256 !== ready.input.nonGuidanceInputSha256)
|
|
108
|
+
return Promise.reject(new ProbeLocalError("drift"));
|
|
109
|
+
prepared.delete(key);
|
|
110
|
+
const entry: Owned = { reservation: input.reservation, controller: new AbortController(), closed: false };
|
|
111
|
+
owned.set(id, entry);
|
|
112
|
+
const abort = () => entry.controller.abort(); signal.addEventListener("abort", abort, { once: true });
|
|
113
|
+
let sequence = 0;
|
|
114
|
+
const sourceCurrent = () => {
|
|
115
|
+
if (signal.aborted || entry.controller.signal.aborted || entry.closed) throw new ProbeLocalError("interrupted");
|
|
116
|
+
effects.current(); current();
|
|
117
|
+
const actual = localProbeFingerprints(config), expected = input.manifest.runtime;
|
|
118
|
+
if (actual.runtimeSha256 !== expected.runtimeSha256 || actual.toolsetSha256 !== expected.toolsetSha256 || actual.modelConfigSha256 !== expected.modelConfigSha256)
|
|
119
|
+
throw new ProbeLocalError("drift");
|
|
120
|
+
};
|
|
121
|
+
const accounting: ProbeLocalEffectScope = { effects, next: () => sequence++, current: () => {
|
|
122
|
+
sourceCurrent();
|
|
123
|
+
if (entry.workspace && !fixture) {
|
|
124
|
+
if (entry.confinement) requireProbeConfinement(entry.confinement, entry.workspace);
|
|
125
|
+
else probeWorkspaceCurrent(entry.workspace);
|
|
126
|
+
}
|
|
127
|
+
} };
|
|
128
|
+
const reserve = async (charges: ProbeResourceCharges, descriptor: string): Promise<void> => {
|
|
129
|
+
if (!positiveCharge(charges)) return;
|
|
130
|
+
await probeLocalEffect(accounting, "resources", descriptor, charges, undefined, async () => ({ value: undefined, usage: 0 }));
|
|
131
|
+
};
|
|
132
|
+
entry.promise = Promise.resolve().then(async () => {
|
|
133
|
+
accounting.current();
|
|
134
|
+
const workspaceInput = { role: input.slot.role, policy: ready.state.registration.snapshots.dataPolicy, files: ready.source.files,
|
|
135
|
+
...(ready.source.sourceTree ? { sourceTree: ready.source.sourceTree } : {}), verifySource: ready.source.verifySource,
|
|
136
|
+
reserveStorage: (bytes: number) => reserve({ scratchBytes: bytes }, "probe-workspace-storage"), current: sourceCurrent,
|
|
137
|
+
maxBytes: PROBE_WORKSPACE_LIMITS.workspaceBytes };
|
|
138
|
+
entry.workspace = await (fixture ? fixture.materialize(workspaceInput) : materializeProbeWorkspace(workspaceInput));
|
|
139
|
+
workspaceOwned?.(entry.workspace);
|
|
140
|
+
accounting.current();
|
|
141
|
+
if (entry.workspace.role !== input.slot.role || JSON.stringify(entry.workspace.files) !== JSON.stringify(ready.input.files)) throw new ProbeLocalError("drift");
|
|
142
|
+
entry.confinement = await (fixture ? fixture.confine(entry.workspace) : verifyProbeConfinement(entry.workspace, entry.controller.signal));
|
|
143
|
+
if (entry.confinement.workspace !== entry.workspace) throw new ProbeLocalError("drift");
|
|
144
|
+
accounting.current();
|
|
145
|
+
entry.peer = new LocalPeer("local", { cwd: entry.workspace.root, omni, fixedModel: GUIDANCE_PROBE_MODEL,
|
|
146
|
+
maxSteps: config.maxSteps, tools: { deny: [], permit } }, entry.confinement, fixture ? "fixture_only" : undefined);
|
|
147
|
+
const result = await entry.peer.runProbe({ purpose: "guidance_probe", prepared: ready.input, workspace: entry.workspace,
|
|
148
|
+
confinement: entry.confinement, config, accounting, reserve }, entry.controller.signal);
|
|
149
|
+
accounting.current(); await close(entry);
|
|
150
|
+
effects.current(); current();
|
|
151
|
+
return observation(input, ready, result.servedModel, result.complete ? "closed_fixture" : "failed_known", result.usageKnown ? "known_fixture" : "unknown");
|
|
152
|
+
}).catch(async error => {
|
|
153
|
+
if (error instanceof ProbeConfinementError) entry.closeUnknown = error.stop;
|
|
154
|
+
try { await close(entry); }
|
|
155
|
+
catch { throw new ProbeLocalError("interrupted"); }
|
|
156
|
+
return observation(input, ready, entry.peer?.probeObservation().servedModel ?? null, "unknown", "unknown");
|
|
157
|
+
}).finally(() => {
|
|
158
|
+
signal.removeEventListener("abort", abort);
|
|
159
|
+
if (entry.closed) { completed.add(entry.reservation); owned.delete(id); }
|
|
160
|
+
});
|
|
161
|
+
return entry.promise;
|
|
162
|
+
},
|
|
163
|
+
async stop(input) {
|
|
164
|
+
const entry = owned.get(reservationKey(input.reservation));
|
|
165
|
+
if (!entry) return { reservation: input.reservation, stopped: completed.has(input.reservation) ? "known_fixture" : "unknown" };
|
|
166
|
+
entry.controller.abort();
|
|
167
|
+
await entry.promise?.catch(() => {});
|
|
168
|
+
await close(entry, true);
|
|
169
|
+
completed.add(entry.reservation); owned.delete(reservationKey(entry.reservation));
|
|
170
|
+
return { reservation: input.reservation, stopped: "known_fixture" };
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|