@staix/agent-hub 0.36.0 → 0.38.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 +27 -0
- package/README.md +6 -2
- package/THIRD_PARTY_NOTICES.md +0 -18
- package/docs/agent-notes/README.md +13 -3
- package/docs/agent-notes/daemon.md +4 -4
- package/docs/agent-notes/local-worker.md +1 -0
- package/docs/agent-notes/models.md +2 -1
- package/docs/agent-notes/tasks.md +1 -1
- package/docs/agent-notes/tests.md +1 -2
- package/docs/contracts/companion-cli-v1.json +70 -0
- package/docs/design/adapters.md +43 -2
- package/docs/design/agent-hub-architecture.md +9 -1
- package/docs/design/guidance-probes.md +1167 -0
- package/docs/design/model-routes.md +437 -12
- package/docs/dogfood.md +12 -13
- package/docs/events.md +20 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +123 -151
- package/docs/profiles.md +1 -1
- package/docs/quickstart.md +15 -3
- package/docs/research.md +1 -1
- package/docs/sdlc.md +5 -3
- package/docs/security.md +25 -1
- package/docs/specs/2026-09-19-agent-hub-design.md +9 -7
- package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
- package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
- package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +21 -6
- package/docs/verification/2026-11-11-0.37.0.md +40 -0
- package/docs/verification/2026-11-11-0.38.0.md +41 -0
- package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
- package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
- package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
- package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
- package/docs/verified.json +25 -25
- package/package.json +3 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +2403 -1444
- package/plugins/agent-hub/server.js +2480 -1509
- package/src/adapters/channel-peer.ts +7 -1
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +1 -1
- package/src/adapters/local-probe.ts +233 -0
- package/src/adapters/local-worker.ts +232 -21
- 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/help.ts +2 -1
- package/src/cli/init.ts +3 -1
- package/src/cli/install-paths.ts +7 -2
- package/src/cli/main.ts +78 -7
- package/src/cli/output.ts +8 -4
- package/src/cli/runtime-version-warning.ts +2 -2
- package/src/cli/sdlc-output.ts +9 -5
- package/src/cli/upgrade-runtime.ts +1 -1
- package/src/hub/bus.ts +2 -2
- package/src/hub/config-apply.ts +4 -2
- package/src/hub/config-trust.ts +6 -1
- package/src/hub/control-client.ts +5 -2
- package/src/hub/daemon.ts +195 -13
- package/src/hub/envelope.ts +6 -1
- package/src/hub/events.ts +3 -2
- package/src/hub/guidance-probe-store.ts +1044 -0
- package/src/hub/guidance-probes.ts +692 -0
- package/src/hub/inference.ts +18 -5
- package/src/hub/manager.ts +24 -1
- package/src/hub/operational-authority.ts +14 -1
- package/src/hub/peers.ts +5 -0
- package/src/hub/person-command.ts +25 -0
- package/src/hub/ports.ts +1 -1
- package/src/hub/progress.ts +23 -16
- package/src/hub/report.ts +2 -0
- package/src/hub/research.ts +1 -0
- package/src/hub/restart.ts +7 -0
- package/src/hub/sdlc-release-authorization.ts +139 -17
- package/src/hub/sdlc-release-policy.ts +100 -0
- package/src/hub/sdlc-release.ts +59 -7
- package/src/hub/supervision.ts +3 -2
- package/src/hub/tasks.ts +363 -7
- package/src/local/probe-errors.ts +28 -0
- package/src/local/probe-sandbox.ts +224 -0
- package/src/local/probe-types.ts +110 -0
- package/src/local/probe-workspace.ts +426 -0
- package/src/local/sandbox.ts +71 -2
- package/src/local/tools.ts +135 -9
- package/src/models/route/advisor-trigger.ts +88 -0
- package/src/models/route/config.ts +21 -17
- package/src/models/route/conversation-view.ts +179 -0
- package/src/models/route/decision-evidence.ts +1 -1
- package/src/models/route/decision.ts +114 -19
- 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 +2 -2
- package/src/models/route/runtime.ts +115 -52
- package/src/models/route/turn-state.ts +77 -0
- package/src/omniroute/client.ts +3 -0
- package/src/ui/guidance-panel.ts +34 -2
- package/src/ui/guidance-view.ts +33 -0
- package/src/ui/plugin.ts +80 -23
- package/src/version.ts +4 -0
- package/templates/AGENTS.block.md +14 -14
- 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/templates/profiles/general.json +1 -1
- package/templates/profiles/research.json +1 -1
- package/templates/profiles/writing.json +1 -1
- 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 {
|
|
@@ -18,7 +18,7 @@ import { toolWriteOperation } from "../hub/tool-request.ts";
|
|
|
18
18
|
import { channelProject } from "../hub/channel-project.ts";
|
|
19
19
|
import { VERSION } from "../version.ts";
|
|
20
20
|
import { IMPLEMENTER_HUB_TOOL_NAMES, IMPLEMENTER_PERMISSION_TOOL, ACTIONABLE_MESSAGE_INSTRUCTION, projectConductorTools, projectToolList, CONDUCTOR_TOOL_NAMES, DEFAULT_ROLES, roleContract, TASK_TOOL_NAMES, TASK_TOOLS, profileTaskTools } from "../hub/hub-tools.ts";
|
|
21
|
-
import { frame, replyParent, sanitize, HUB_MESSAGE_INSTRUCTION, type Envelope } from "../hub/envelope.ts";
|
|
21
|
+
import { frame, replyParent, sanitize, HUB_MESSAGE_INSTRUCTION, PERSON_COMMAND_INSTRUCTION, type Envelope } from "../hub/envelope.ts";
|
|
22
22
|
import { renderHeldHint } from "../hub/delivery-hints.ts";
|
|
23
23
|
import { acceptsNativePermissionRequest, buildNativePermissionProbe, NATIVE_PERMISSION_PROBE_MAX_PER_LAUNCH } from "../hub/native-permission-request.ts";
|
|
24
24
|
import { currentClaudeChannelEvidence } from "./claude-channel-evidence.ts";
|
|
@@ -170,6 +170,7 @@ const INSTRUCTIONS = [
|
|
|
170
170
|
: []),
|
|
171
171
|
HUB_MESSAGE_INSTRUCTION,
|
|
172
172
|
ACTIONABLE_MESSAGE_INSTRUCTION,
|
|
173
|
+
PERSON_COMMAND_INSTRUCTION,
|
|
173
174
|
"Start a hub_send text with [IMPORTANT] only when the recipient must see it now (it interrupts a running Codex turn), with [FYI] for a note that needs nobody's turn. Unmarked messages are batched.",
|
|
174
175
|
"Do not acknowledge messages that need no answer; every hub_send costs the other agents a turn.",
|
|
175
176
|
...(channel ? ["If a push was missed or a tool result reports queued important messages, call hub_inbox to read the daemon queue and any local failed-push buffer."] : []),
|
package/src/adapters/compat.ts
CHANGED
|
@@ -64,7 +64,7 @@ export const COMPAT = {
|
|
|
64
64
|
receipt: "docs/verification/2026-11-08-agy-1.5.3.md" },
|
|
65
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 and 0.27.0 repeat those account-free probes on macOS arm64. Real model turns and Linux repetition of those versions remain unverified. The
|
|
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
68
|
receipt: "docs/verification/2026-11-09-qwen-0270-acp.md" },
|
|
69
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`.
|
|
@@ -0,0 +1,233 @@
|
|
|
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 ProbeMeasuredSession, type ProbeReceiptLimit, type ProbeReservation, type ProbeRetainedRecord, type ProbeResourceCharges, type ProbeSlot, type ProbeStoredState } from "../hub/guidance-probes.ts";
|
|
5
|
+
import { collectProbeOutput, materializeProbeWorkspace, probeWorkspaceCurrent, PROBE_WORKSPACE_LIMITS, removeRetained, retainProbeOutput,
|
|
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
|
+
/** Output collected and retained once, after the stop reported quiescence and before the host releases the workspace. */
|
|
29
|
+
harvest?: { output: ProbeMeasuredSession["output"]; scratchBytes: number; limits: ProbeReceiptLimit[]; retained?: ProbeMeasuredSession["retained"] };
|
|
30
|
+
}
|
|
31
|
+
const bytesHash = (bytes: Uint8Array) => createHash("sha256").update(bytes).digest("hex");
|
|
32
|
+
const reservationKey = (reservation: ProbeReservation) => probeHash(guidanceProbeCanonical(reservation));
|
|
33
|
+
const positiveCharge = (charges: ProbeResourceCharges) => Object.values(charges).some(value => typeof value === "number" && value > 0);
|
|
34
|
+
function freeze<T>(value: T): T {
|
|
35
|
+
if (value && typeof value === "object") { for (const child of Object.values(value)) freeze(child); Object.freeze(value); }
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Constructor-only host adapter. No runtime, configuration or wire path selects this factory. */
|
|
40
|
+
export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOptions): ProbeLocalAdapter {
|
|
41
|
+
if (options.fixture && options.fixture.evidence !== "fixture_only") throw new ProbeLocalError("invalid");
|
|
42
|
+
const current = options.current.bind(options), resolveInput = options.resolveInput.bind(options), permit = options.permit.bind(options), omni = options.omni;
|
|
43
|
+
const workspaceOwned = options.workspaceOwned?.bind(options);
|
|
44
|
+
const retentionRoot = options.retentionRoot;
|
|
45
|
+
const fixture = options.fixture && Object.freeze({ materialize: options.fixture.materialize.bind(options.fixture), confine: options.fixture.confine.bind(options.fixture) });
|
|
46
|
+
const config = Object.freeze({ maxSteps: options.config.maxSteps, maxOutputTokens: options.config.maxOutputTokens,
|
|
47
|
+
...(options.config.tokenUpperBound === undefined ? {} : { tokenUpperBound: options.config.tokenUpperBound }) });
|
|
48
|
+
const prepared = new Map<string, Prepared>(), owned = new Map<string, Owned>(), completed = new WeakSet<ProbeReservation>();
|
|
49
|
+
// Every retention directory this adapter created, by canonical record. `discardRetained` removes only a record that is still exactly one of these: the host
|
|
50
|
+
// can hand back nothing else, so a forged or altered record never reaches a delete. Removal is by the identity captured at creation (`removeRetained`).
|
|
51
|
+
const retainedHere = new Map<string, ProbeRetainedRecord>();
|
|
52
|
+
const prepare = async (state: ProbeStoredState, slot: ProbeSlot, guidance: string): Promise<Prepared> => {
|
|
53
|
+
current();
|
|
54
|
+
state = freeze(JSON.parse(JSON.stringify(state)) as ProbeStoredState);
|
|
55
|
+
slot = freeze({ ...slot });
|
|
56
|
+
const resolved = await resolveInput(state, slot); current();
|
|
57
|
+
const source: ProbeLocalSource = { files: resolved.files.map(file => ({ dataId: file.dataId, relative: file.relative, sha256: file.sha256, bytes: Buffer.from(file.bytes) })),
|
|
58
|
+
verifySource: resolved.verifySource, ...(resolved.sourceTree ? { sourceTree: { repo: resolved.sourceTree.repo, tree: { ...resolved.sourceTree.tree }, files: resolved.sourceTree.files.map(file => ({ ...file })) } } : {}) };
|
|
59
|
+
const ids = new Set<string>(), policy = state.registration.snapshots.dataPolicy, role = policy.roles[slot.role];
|
|
60
|
+
for (const file of source.files) {
|
|
61
|
+
const declared = policy.admittedData.find(item => item.id === file.dataId);
|
|
62
|
+
if (ids.has(file.dataId) || !role.dataIds.includes(file.dataId) || !declared || declared.sha256 !== file.sha256
|
|
63
|
+
|| declared.bytes !== file.bytes.byteLength || bytesHash(file.bytes) !== file.sha256 || file.bytes.byteLength > PROBE_WORKSPACE_LIMITS.fileBytes)
|
|
64
|
+
throw new ProbeLocalError("invalid");
|
|
65
|
+
ids.add(file.dataId);
|
|
66
|
+
}
|
|
67
|
+
if (source.sourceTree && guidanceProbeCanonical(source.sourceTree.tree) !== guidanceProbeCanonical(state.registration.manifest.inputs.codeTree))
|
|
68
|
+
throw new ProbeLocalError("drift");
|
|
69
|
+
const descriptors = source.files.map(file => ({ dataId: file.dataId, relative: file.relative, sha256: file.sha256, bytes: file.bytes.byteLength }));
|
|
70
|
+
const input = freeze(prepareLocalProbeInput(state, slot, guidance, descriptors, config)), record = { state, slot, guidance, source, input };
|
|
71
|
+
if (slot.role === "worker" && slot.arm !== "baseline") {
|
|
72
|
+
const baseline = [...state.sessions].reverse().find(session => session.state === "closed_fixture" && session.coverage.coverageVerified
|
|
73
|
+
&& state.registration.manifest.slots.some(item => item.id === session.slotId && item.role === "worker" && item.arm === "baseline"));
|
|
74
|
+
const baselineSlot = baseline && state.registration.manifest.slots.find(item => item.id === baseline.slotId);
|
|
75
|
+
if (!baselineSlot || baseline?.state !== "closed_fixture" || !baseline.coverage.coverageVerified
|
|
76
|
+
|| baseline.coverage.inputFrameSha256 !== prepareLocalProbeInput(state, baselineSlot, state.binding.baselineGuidance, descriptors, config).inputSha256)
|
|
77
|
+
throw new ProbeLocalError("drift");
|
|
78
|
+
}
|
|
79
|
+
const key = `${guidanceProbeManifestKey(state.registration.manifest)}:${slot.id}`;
|
|
80
|
+
prepared.delete(key); prepared.set(key, record);
|
|
81
|
+
// Only preparation entries are evicted; no retained execution, budget or experiment is reset.
|
|
82
|
+
while (prepared.size > GUIDANCE_PROBE_LIMITS.slots) prepared.delete(prepared.keys().next().value!);
|
|
83
|
+
return record;
|
|
84
|
+
};
|
|
85
|
+
const close = async (entry: Owned, retry = false): Promise<void> => {
|
|
86
|
+
if (entry.closed) return;
|
|
87
|
+
if (entry.closeFailed && !retry) throw new ProbeLocalError("interrupted");
|
|
88
|
+
try {
|
|
89
|
+
if (entry.peer) await entry.peer.stopProbe();
|
|
90
|
+
else if (entry.confinement) await entry.confinement.stop();
|
|
91
|
+
if (entry.closeUnknown) await entry.closeUnknown();
|
|
92
|
+
entry.closed = true;
|
|
93
|
+
} catch { entry.closeFailed = true; throw new ProbeLocalError("interrupted"); }
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Collect, then retain, the declared output. This runs only AFTER `close` returned: the peer and the confinement have then reported quiescence, so no
|
|
97
|
+
* child can still be writing (the contract's Sealing order), and before the host releases the workspace it owns. When the stop failed or is uncertain
|
|
98
|
+
* nothing is read at all: the output of a process tree that may still be running is not evidence. It never throws: a failure is recorded as a limit,
|
|
99
|
+
* which can only keep the receipt from being a success. The declared caps hold here too: past either, nothing is retained and the receipt carries
|
|
100
|
+
* `storage_over_cap`.
|
|
101
|
+
*/
|
|
102
|
+
const harvestOutput = (entry: Owned, ready: Prepared): void => {
|
|
103
|
+
if (entry.harvest || !entry.workspace) return;
|
|
104
|
+
if (!entry.closed || entry.closeFailed) { entry.harvest = { output: { v: 1, entries: [], excluded: [], totalBytes: 0 }, scratchBytes: 0, limits: ["output_truncated"] }; return; }
|
|
105
|
+
const limits = ready.state.registration.manifest.limits;
|
|
106
|
+
try {
|
|
107
|
+
const collected = collectProbeOutput(entry.workspace, limits.outputBytes);
|
|
108
|
+
const harvest: NonNullable<Owned["harvest"]> = { output: collected.manifest, scratchBytes: collected.scratchBytes, limits: [] };
|
|
109
|
+
// Scratch deeper than the walk limit was not fully measured: treat its size as unknown, which is over the cap.
|
|
110
|
+
const over = collected.scratchUnmeasured || collected.scratchBytes > limits.scratchBytes || collected.manifest.totalBytes > limits.outputBytes;
|
|
111
|
+
if (over) harvest.limits.push("storage_over_cap");
|
|
112
|
+
else if (retentionRoot && collected.manifest.entries.length > 0) {
|
|
113
|
+
try {
|
|
114
|
+
harvest.retained = retainProbeOutput(entry.workspace, collected, retentionRoot);
|
|
115
|
+
retainedHere.set(guidanceProbeCanonical(harvest.retained), harvest.retained);
|
|
116
|
+
// The host discards right after the launch returns, so only recent records matter; a sealed one is never asked for again. Bounded, oldest first.
|
|
117
|
+
while (retainedHere.size > GUIDANCE_PROBE_LIMITS.slots) retainedHere.delete(retainedHere.keys().next().value!);
|
|
118
|
+
} catch { harvest.limits.push("output_truncated"); }
|
|
119
|
+
}
|
|
120
|
+
entry.harvest = harvest;
|
|
121
|
+
} catch { entry.harvest = { output: { v: 1, entries: [], excluded: [], totalBytes: 0 }, scratchBytes: 0, limits: ["output_truncated"] }; }
|
|
122
|
+
};
|
|
123
|
+
/** The host's own fingerprints at seal time, never the declaration's. Null when they cannot be read, which the Store treats as unverified coverage. */
|
|
124
|
+
const hostRuntime = (): ProbeMeasuredSession["runtime"] => {
|
|
125
|
+
try { const actual = localProbeFingerprints(config); return { runtimeSha256: actual.runtimeSha256, toolsetSha256: actual.toolsetSha256, modelConfigSha256: actual.modelConfigSha256 }; }
|
|
126
|
+
catch { return null; }
|
|
127
|
+
};
|
|
128
|
+
const measuredSession = (entry: Owned, servedModel: string | null, flags: { unavailable: boolean }): Omit<ProbeMeasuredSession, "startedAt"> => ({
|
|
129
|
+
servedModel, workerEffectiveInputSha256: null, nonGuidanceInputSha256: null, runtime: hostRuntime(),
|
|
130
|
+
teardownVerified: entry.closed && !entry.closeFailed, cancelled: entry.controller.signal.aborted, timedOut: false, unavailable: flags.unavailable,
|
|
131
|
+
limits: entry.harvest?.limits ?? [], scratchBytes: entry.harvest?.scratchBytes ?? 0,
|
|
132
|
+
output: entry.harvest?.output ?? { v: 1, entries: [], excluded: [], totalBytes: 0 }, ...(entry.harvest?.retained ? { retained: entry.harvest.retained } : {}),
|
|
133
|
+
});
|
|
134
|
+
const observation = (input: ProbeFakeLaunch, ready: Prepared, servedModel: string | null, outcome: ProbeFakeObservation["outcome"], usage: ProbeFakeObservation["usage"],
|
|
135
|
+
entry?: Owned, unavailable = false): ProbeFakeObservation => ({
|
|
136
|
+
reservation: input.reservation, outcome, servedModel, inputFrameHash: ready.input.inputSha256,
|
|
137
|
+
workerEffectiveInputHash: input.slot.role === "worker" ? ready.input.inputSha256 : null,
|
|
138
|
+
nonGuidanceInputSha256: input.slot.role === "worker" ? ready.input.nonGuidanceInputSha256 : null,
|
|
139
|
+
candidateArtifactSha256: null, usage,
|
|
140
|
+
...(entry ? { measured: { ...measuredSession(entry, servedModel, { unavailable }),
|
|
141
|
+
workerEffectiveInputSha256: input.slot.role === "worker" ? ready.input.inputSha256 : null,
|
|
142
|
+
nonGuidanceInputSha256: input.slot.role === "worker" ? ready.input.nonGuidanceInputSha256 : null } } : {}),
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
prepareWorkerFrame: async (state, slot, guidance) => {
|
|
146
|
+
const record = await prepare(state, slot, guidance);
|
|
147
|
+
return { inputFrame: record.input.inputFrame, nonGuidanceInputSha256: record.input.nonGuidanceInputSha256 };
|
|
148
|
+
},
|
|
149
|
+
prepareEditorFrame: async (state, slot) => (await prepare(state, slot, state.binding.baselineGuidance)).input.inputFrame,
|
|
150
|
+
ports: {
|
|
151
|
+
launch(input, effects, signal) {
|
|
152
|
+
current();
|
|
153
|
+
const key = `${guidanceProbeManifestKey(input.manifest)}:${input.slot.id}`, ready = prepared.get(key), id = reservationKey(input.reservation);
|
|
154
|
+
if (!ready || owned.has(id) || signal.aborted || input.purpose !== "guidance_probe" || ready.input.role !== input.slot.role
|
|
155
|
+
|| input.inputFrame !== ready.input.inputFrame || input.inputSha256 !== ready.input.inputSha256
|
|
156
|
+
|| input.slot.role === "worker" && input.nonGuidanceInputSha256 !== ready.input.nonGuidanceInputSha256)
|
|
157
|
+
return Promise.reject(new ProbeLocalError("drift"));
|
|
158
|
+
prepared.delete(key);
|
|
159
|
+
const entry: Owned = { reservation: input.reservation, controller: new AbortController(), closed: false };
|
|
160
|
+
owned.set(id, entry);
|
|
161
|
+
const abort = () => entry.controller.abort(); signal.addEventListener("abort", abort, { once: true });
|
|
162
|
+
let sequence = 0;
|
|
163
|
+
const sourceCurrent = () => {
|
|
164
|
+
if (signal.aborted || entry.controller.signal.aborted || entry.closed) throw new ProbeLocalError("interrupted");
|
|
165
|
+
effects.current(); current();
|
|
166
|
+
const actual = localProbeFingerprints(config), expected = input.manifest.runtime;
|
|
167
|
+
if (actual.runtimeSha256 !== expected.runtimeSha256 || actual.toolsetSha256 !== expected.toolsetSha256 || actual.modelConfigSha256 !== expected.modelConfigSha256)
|
|
168
|
+
throw new ProbeLocalError("drift");
|
|
169
|
+
};
|
|
170
|
+
const accounting: ProbeLocalEffectScope = { effects, next: () => sequence++, current: () => {
|
|
171
|
+
sourceCurrent();
|
|
172
|
+
if (entry.workspace && !fixture) {
|
|
173
|
+
if (entry.confinement) requireProbeConfinement(entry.confinement, entry.workspace);
|
|
174
|
+
else probeWorkspaceCurrent(entry.workspace);
|
|
175
|
+
}
|
|
176
|
+
} };
|
|
177
|
+
const reserve = async (charges: ProbeResourceCharges, descriptor: string): Promise<void> => {
|
|
178
|
+
if (!positiveCharge(charges)) return;
|
|
179
|
+
await probeLocalEffect(accounting, "resources", descriptor, charges, undefined, async () => ({ value: undefined, usage: 0 }));
|
|
180
|
+
};
|
|
181
|
+
entry.promise = Promise.resolve().then(async () => {
|
|
182
|
+
accounting.current();
|
|
183
|
+
const workspaceInput = { role: input.slot.role, policy: ready.state.registration.snapshots.dataPolicy, files: ready.source.files,
|
|
184
|
+
...(ready.source.sourceTree ? { sourceTree: ready.source.sourceTree } : {}), verifySource: ready.source.verifySource,
|
|
185
|
+
reserveStorage: (bytes: number) => reserve({ scratchBytes: bytes }, "probe-workspace-storage"), current: sourceCurrent,
|
|
186
|
+
maxBytes: PROBE_WORKSPACE_LIMITS.workspaceBytes };
|
|
187
|
+
entry.workspace = await (fixture ? fixture.materialize(workspaceInput) : materializeProbeWorkspace(workspaceInput));
|
|
188
|
+
workspaceOwned?.(entry.workspace);
|
|
189
|
+
accounting.current();
|
|
190
|
+
if (entry.workspace.role !== input.slot.role || JSON.stringify(entry.workspace.files) !== JSON.stringify(ready.input.files)) throw new ProbeLocalError("drift");
|
|
191
|
+
entry.confinement = await (fixture ? fixture.confine(entry.workspace) : verifyProbeConfinement(entry.workspace, entry.controller.signal));
|
|
192
|
+
if (entry.confinement.workspace !== entry.workspace) throw new ProbeLocalError("drift");
|
|
193
|
+
accounting.current();
|
|
194
|
+
entry.peer = new LocalPeer("local", { cwd: entry.workspace.root, omni, fixedModel: GUIDANCE_PROBE_MODEL,
|
|
195
|
+
maxSteps: config.maxSteps, tools: { deny: [], permit } }, entry.confinement, fixture ? "fixture_only" : undefined);
|
|
196
|
+
const result = await entry.peer.runProbe({ purpose: "guidance_probe", prepared: ready.input, workspace: entry.workspace,
|
|
197
|
+
confinement: entry.confinement, config, accounting, reserve }, entry.controller.signal);
|
|
198
|
+
accounting.current(); await close(entry); harvestOutput(entry, ready);
|
|
199
|
+
effects.current(); current();
|
|
200
|
+
return observation(input, ready, result.servedModel, result.complete ? "closed_fixture" : "failed_known", result.usageKnown ? "known_fixture" : "unknown", entry);
|
|
201
|
+
}).catch(async error => {
|
|
202
|
+
if (error instanceof ProbeConfinementError) entry.closeUnknown = error.stop;
|
|
203
|
+
try { await close(entry); }
|
|
204
|
+
catch { throw new ProbeLocalError("interrupted"); }
|
|
205
|
+
// Only after the stop confirmed quiescence, and only while the workspace is still ours: a drifted workspace is read by identity or not at all.
|
|
206
|
+
harvestOutput(entry, ready);
|
|
207
|
+
// `unavailable` means the session could not start: a confinement error before any peer existed. Once a peer ran, the Store treats it as unknown or failed.
|
|
208
|
+
return observation(input, ready, entry.peer?.probeObservation().servedModel ?? null, "unknown", "unknown", entry, error instanceof ProbeConfinementError && !entry.peer);
|
|
209
|
+
}).finally(() => {
|
|
210
|
+
signal.removeEventListener("abort", abort);
|
|
211
|
+
if (entry.closed) { completed.add(entry.reservation); owned.delete(id); }
|
|
212
|
+
});
|
|
213
|
+
return entry.promise;
|
|
214
|
+
},
|
|
215
|
+
discardRetained(record) {
|
|
216
|
+
// Only what this adapter retained and has not yet handed to a receipt. A record that is not exactly one of ours is ignored, never deleted.
|
|
217
|
+
const key = guidanceProbeCanonical(record), ours = retainedHere.get(key);
|
|
218
|
+
if (!ours) return;
|
|
219
|
+
retainedHere.delete(key);
|
|
220
|
+
try { removeRetained(ours, true); } catch { /* the identity checks inside leave a replaced name alone; a failure leaves the directory for the person's prune preview */ }
|
|
221
|
+
},
|
|
222
|
+
async stop(input) {
|
|
223
|
+
const entry = owned.get(reservationKey(input.reservation));
|
|
224
|
+
if (!entry) return { reservation: input.reservation, stopped: completed.has(input.reservation) ? "known_fixture" : "unknown" };
|
|
225
|
+
entry.controller.abort();
|
|
226
|
+
await entry.promise?.catch(() => {});
|
|
227
|
+
await close(entry, true);
|
|
228
|
+
completed.add(entry.reservation); owned.delete(reservationKey(entry.reservation));
|
|
229
|
+
return { reservation: input.reservation, stopped: "known_fixture" };
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
}
|