@staix/agent-hub 0.47.0 → 0.48.1
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 +10 -0
- package/README.md +5 -3
- package/docs/agent-notes/daemon.md +1 -1
- package/docs/agent-notes/tasks.md +1 -0
- package/docs/design/guidance-probes.md +12 -0
- package/docs/design/roadmap.md +1 -1
- package/docs/dogfood.md +1 -1
- package/docs/operations.md +32 -1
- package/docs/quickstart.md +13 -1
- package/docs/security.md +13 -5
- package/docs/verification/2026-11-26-0.48.0.md +45 -0
- package/docs/verification/2026-11-27-0.48.1.md +37 -0
- package/docs/verified.json +20 -20
- package/package.json +1 -1
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +20 -6
- package/plugins/agent-hub/server.js +20 -6
- package/src/adapters/local-probe.ts +59 -14
- package/src/adapters/local-worker.ts +18 -6
- package/src/cli/help.ts +1 -1
- package/src/cli/main.ts +2 -2
- package/src/hub/control-client.ts +1 -1
- package/src/hub/daemon.ts +20 -2
- package/src/hub/guidance-probe-store.ts +51 -10
- package/src/hub/guidance-probes.ts +25 -7
- package/src/hub/supervision.ts +19 -6
- package/src/hub/tasks.ts +45 -16
- package/src/local/probe-types.ts +1 -0
- package/src/local/probe-workspace.ts +49 -0
- package/src/omniroute/client.ts +19 -3
- package/src/ui/guidance-panel.ts +2 -2
- package/src/ui/guidance-view.ts +4 -2
|
@@ -14799,7 +14799,7 @@ var package_default;
|
|
|
14799
14799
|
var init_package = __esm(() => {
|
|
14800
14800
|
package_default = {
|
|
14801
14801
|
name: "@staix/agent-hub",
|
|
14802
|
-
version: "0.
|
|
14802
|
+
version: "0.48.1",
|
|
14803
14803
|
description: "Native multi-agent hub: Claude Code, Codex, Kimi Code, Pi and local inference as peers in one project",
|
|
14804
14804
|
license: "MIT",
|
|
14805
14805
|
type: "module",
|
|
@@ -20110,6 +20110,7 @@ var init_local_worker = __esm(() => {
|
|
|
20110
20110
|
probeCalls = 0;
|
|
20111
20111
|
probeServedModel = null;
|
|
20112
20112
|
probeServedExact = false;
|
|
20113
|
+
probeProviderResponded = false;
|
|
20113
20114
|
probeUsageKnown = true;
|
|
20114
20115
|
probeToolPlan;
|
|
20115
20116
|
probePermits = new Set;
|
|
@@ -20248,7 +20249,12 @@ var init_local_worker = __esm(() => {
|
|
|
20248
20249
|
await this.probeConfinement?.stop();
|
|
20249
20250
|
}
|
|
20250
20251
|
probeObservation() {
|
|
20251
|
-
return {
|
|
20252
|
+
return {
|
|
20253
|
+
servedModel: this.probeServedModel,
|
|
20254
|
+
servedModelExact: this.probeServedExact,
|
|
20255
|
+
usageKnown: this.probeUsageKnown,
|
|
20256
|
+
providerResponded: this.probeProviderResponded
|
|
20257
|
+
};
|
|
20252
20258
|
}
|
|
20253
20259
|
async deliver(envs, deliveryId) {
|
|
20254
20260
|
if (this.probeConfinement)
|
|
@@ -20688,15 +20694,23 @@ var init_local_worker = __esm(() => {
|
|
|
20688
20694
|
const upper = probe.config.tokenUpperBound, inputBytes = Buffer.byteLength(frame, "utf8");
|
|
20689
20695
|
if (upper !== undefined && (probe.config.maxOutputTokens > upper || inputBytes > upper - probe.config.maxOutputTokens))
|
|
20690
20696
|
throw new ProbeToolRefusal("token_ceiling");
|
|
20691
|
-
const
|
|
20697
|
+
const reservedTokens = probe.pinnedChat ? inputBytes + probe.config.maxOutputTokens : upper;
|
|
20698
|
+
const result = await probeLocalEffect(probe.accounting, "model_calls", frame, first ? undefined : { inputBytes }, reservedTokens, async (signal) => {
|
|
20692
20699
|
if (signal.aborted || this.abort?.signal.aborted)
|
|
20693
20700
|
throw new ProbeLocalError("interrupted");
|
|
20694
|
-
const value = await this.opts.omni.chat(body, { signal: this.abort.signal });
|
|
20701
|
+
const value = probe.pinnedChat ? await probe.pinnedChat(body, this.abort.signal) : await this.opts.omni.chat(body, { signal: this.abort.signal });
|
|
20702
|
+
if (probe.pinnedChat) {
|
|
20703
|
+
this.probeProviderResponded = true;
|
|
20704
|
+
this.probeServedExact = value.servedModelExact === true;
|
|
20705
|
+
this.probeServedModel = value.servedModel === GUIDANCE_PROBE_MODEL && !this.probeServedExact ? null : value.servedModel ?? null;
|
|
20706
|
+
}
|
|
20695
20707
|
return { value, usage: probeObservedTokens(value) };
|
|
20696
20708
|
});
|
|
20697
20709
|
this.probeCalls++;
|
|
20698
|
-
|
|
20699
|
-
|
|
20710
|
+
if (!probe.pinnedChat) {
|
|
20711
|
+
this.probeServedModel = result.servedModel ?? null;
|
|
20712
|
+
this.probeServedExact = result.servedModelExact === true;
|
|
20713
|
+
}
|
|
20700
20714
|
this.probeUsageKnown = this.probeUsageKnown && probeObservedTokens(result) !== null;
|
|
20701
20715
|
if (!this.probeUsageKnown)
|
|
20702
20716
|
throw new ProbeLocalError("usage");
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { hubGitSync } from "../hub/git.ts";
|
|
2
3
|
import { LocalPeer, localProbeFingerprints, prepareLocalProbeInput } from "./local-worker.ts";
|
|
3
|
-
import { GUIDANCE_PROBE_LIMITS, GUIDANCE_PROBE_MODEL, guidanceProbeCanonical, guidanceProbeManifestKey, probeHash,
|
|
4
|
+
import { GUIDANCE_PROBE_LIMITS, GUIDANCE_PROBE_LIVE_LIMITS, GUIDANCE_PROBE_MODEL, guidanceProbeCanonical, guidanceProbeManifestKey, probeHash,
|
|
4
5
|
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
|
+
import { collectProbeOutput, materializeProbeWorkspace, probeWorkspaceCurrent, PROBE_WORKSPACE_LIMITS, releaseEmptyProbeWorkspace, removeRetained, retainProbeOutput,
|
|
6
7
|
type ProbeWorkspace } from "../local/probe-workspace.ts";
|
|
7
8
|
import { ProbeConfinementError, requireProbeConfinement, verifyProbeConfinement, type ProbeConfinement } from "../local/probe-sandbox.ts";
|
|
8
9
|
import { ProbeLocalError, probeLocalEffect, type ProbeLocalAdapter, type ProbeLocalAdapterOptions, type ProbeLocalEffectScope,
|
|
@@ -25,6 +26,9 @@ interface Owned {
|
|
|
25
26
|
closeUnknown?: () => Promise<void>;
|
|
26
27
|
closed: boolean;
|
|
27
28
|
closeFailed?: boolean;
|
|
29
|
+
timedOut?: boolean;
|
|
30
|
+
releaseAttempted?: boolean;
|
|
31
|
+
releaseFailed?: boolean;
|
|
28
32
|
/** Output collected and retained once, after the stop reported quiescence and before the host releases the workspace. */
|
|
29
33
|
harvest?: { output: ProbeMeasuredSession["output"]; scratchBytes: number; limits: ProbeReceiptLimit[]; retained?: ProbeMeasuredSession["retained"] };
|
|
30
34
|
}
|
|
@@ -36,8 +40,32 @@ function freeze<T>(value: T): T {
|
|
|
36
40
|
return value;
|
|
37
41
|
}
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
const LIVE_GUIDANCE_PROBE_CONFIG = Object.freeze({ maxSteps: GUIDANCE_PROBE_LIVE_LIMITS.modelCalls, maxOutputTokens: GUIDANCE_PROBE_LIVE_LIMITS.maxOutputTokens, tokenUpperBound: GUIDANCE_PROBE_LIVE_LIMITS.tokens });
|
|
44
|
+
|
|
45
|
+
/** The initial live leg materializes only the empty tree and no admitted files. */
|
|
46
|
+
export function createLiveGuidanceProbeLocalAdapter(
|
|
47
|
+
options: Omit<ProbeLocalAdapterOptions, "fixture" | "config" | "resolveInput"> & { cwd: string },
|
|
48
|
+
): ProbeLocalAdapter {
|
|
49
|
+
return createLocalAdapter({ ...options, config: LIVE_GUIDANCE_PROBE_CONFIG,
|
|
50
|
+
resolveInput(state, slot) {
|
|
51
|
+
const { manifest, snapshots } = state.registration;
|
|
52
|
+
const { objectFormat, oid } = manifest.inputs.codeTree;
|
|
53
|
+
if (slot.role !== "worker" || snapshots.dataPolicy.admittedData.length || snapshots.dataPolicy.roles.worker.dataIds.length
|
|
54
|
+
|| oid !== createHash(objectFormat).update("tree 0").update(Buffer.alloc(1)).digest("hex")) throw new ProbeLocalError("invalid");
|
|
55
|
+
const format = hubGitSync(["-C", options.cwd, "rev-parse", "--show-object-format"], { encoding: "utf8", timeout: 5000, maxBuffer: 1024 });
|
|
56
|
+
if (format.error || format.status !== 0 || format.stdout.trim() !== objectFormat) throw new ProbeLocalError("drift");
|
|
57
|
+
return { files: [], verifySource: () => { throw new ProbeLocalError("invalid"); } };
|
|
58
|
+
},
|
|
59
|
+
}, true);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Constructor-only fixture adapter. */
|
|
40
63
|
export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOptions): ProbeLocalAdapter {
|
|
64
|
+
return createLocalAdapter(options, false);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function createLocalAdapter(options: ProbeLocalAdapterOptions, live: boolean): ProbeLocalAdapter {
|
|
68
|
+
if (live && options.fixture) throw new ProbeLocalError("invalid");
|
|
41
69
|
if (options.fixture && options.fixture.evidence !== "fixture_only") throw new ProbeLocalError("invalid");
|
|
42
70
|
const current = options.current.bind(options), resolveInput = options.resolveInput.bind(options), permit = options.permit.bind(options), omni = options.omni;
|
|
43
71
|
const workspaceOwned = options.workspaceOwned?.bind(options);
|
|
@@ -127,20 +155,30 @@ export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOption
|
|
|
127
155
|
};
|
|
128
156
|
const measuredSession = (entry: Owned, servedModel: string | null, flags: { unavailable: boolean }): Omit<ProbeMeasuredSession, "startedAt"> => ({
|
|
129
157
|
servedModel, workerEffectiveInputSha256: null, nonGuidanceInputSha256: null, runtime: hostRuntime(),
|
|
130
|
-
teardownVerified: entry.closed && !entry.closeFailed, cancelled: entry.controller.signal.aborted
|
|
158
|
+
teardownVerified: entry.closed && !entry.closeFailed && !entry.releaseFailed, cancelled: entry.controller.signal.aborted && !entry.timedOut,
|
|
159
|
+
timedOut: entry.timedOut === true, unavailable: flags.unavailable,
|
|
131
160
|
limits: entry.harvest?.limits ?? [], scratchBytes: entry.harvest?.scratchBytes ?? 0,
|
|
132
161
|
output: entry.harvest?.output ?? { v: 1, entries: [], excluded: [], totalBytes: 0 }, ...(entry.harvest?.retained ? { retained: entry.harvest.retained } : {}),
|
|
133
162
|
});
|
|
163
|
+
const release = (entry: Owned): void => {
|
|
164
|
+
if (!live || !entry.workspace || !entry.closed || entry.releaseAttempted) return;
|
|
165
|
+
entry.releaseAttempted = true;
|
|
166
|
+
try { releaseEmptyProbeWorkspace(entry.workspace); }
|
|
167
|
+
catch { entry.releaseFailed = true; }
|
|
168
|
+
};
|
|
134
169
|
const observation = (input: ProbeFakeLaunch, ready: Prepared, servedModel: string | null, outcome: ProbeFakeObservation["outcome"], usage: ProbeFakeObservation["usage"],
|
|
135
|
-
entry?: Owned, unavailable = false): ProbeFakeObservation =>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
170
|
+
entry?: Owned, unavailable = false): ProbeFakeObservation => {
|
|
171
|
+
const delivered = input.slot.role === "worker" && (!live || entry?.peer?.probeObservation().providerResponded);
|
|
172
|
+
return {
|
|
173
|
+
reservation: input.reservation, outcome, servedModel, inputFrameHash: ready.input.inputSha256,
|
|
174
|
+
workerEffectiveInputHash: input.slot.role === "worker" ? ready.input.inputSha256 : null,
|
|
175
|
+
nonGuidanceInputSha256: input.slot.role === "worker" ? ready.input.nonGuidanceInputSha256 : null,
|
|
176
|
+
candidateArtifactSha256: null, usage,
|
|
177
|
+
...(entry ? { measured: { ...measuredSession(entry, servedModel, { unavailable }),
|
|
178
|
+
workerEffectiveInputSha256: delivered ? ready.input.inputSha256 : null,
|
|
179
|
+
nonGuidanceInputSha256: delivered ? ready.input.nonGuidanceInputSha256 : null } } : {}),
|
|
180
|
+
};
|
|
181
|
+
};
|
|
144
182
|
return {
|
|
145
183
|
prepareWorkerFrame: async (state, slot, guidance) => {
|
|
146
184
|
const record = await prepare(state, slot, guidance);
|
|
@@ -159,6 +197,8 @@ export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOption
|
|
|
159
197
|
const entry: Owned = { reservation: input.reservation, controller: new AbortController(), closed: false };
|
|
160
198
|
owned.set(id, entry);
|
|
161
199
|
const abort = () => entry.controller.abort(); signal.addEventListener("abort", abort, { once: true });
|
|
200
|
+
const timeout = live ? setTimeout(() => { entry.timedOut = true; abort(); }, GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) : undefined;
|
|
201
|
+
timeout?.unref?.();
|
|
162
202
|
let sequence = 0;
|
|
163
203
|
const sourceCurrent = () => {
|
|
164
204
|
if (signal.aborted || entry.controller.signal.aborted || entry.closed) throw new ProbeLocalError("interrupted");
|
|
@@ -191,11 +231,14 @@ export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOption
|
|
|
191
231
|
entry.confinement = await (fixture ? fixture.confine(entry.workspace) : verifyProbeConfinement(entry.workspace, entry.controller.signal));
|
|
192
232
|
if (entry.confinement.workspace !== entry.workspace) throw new ProbeLocalError("drift");
|
|
193
233
|
accounting.current();
|
|
234
|
+
const chat = live ? await omni.pinCampusChat(GUIDANCE_PROBE_MODEL) : undefined;
|
|
235
|
+
accounting.current();
|
|
194
236
|
entry.peer = new LocalPeer("local", { cwd: entry.workspace.root, omni, fixedModel: GUIDANCE_PROBE_MODEL,
|
|
195
237
|
maxSteps: config.maxSteps, tools: { deny: [], permit } }, entry.confinement, fixture ? "fixture_only" : undefined);
|
|
196
238
|
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);
|
|
239
|
+
confinement: entry.confinement, config, accounting, reserve, ...(chat ? { pinnedChat: chat } : {}) }, entry.controller.signal);
|
|
198
240
|
accounting.current(); await close(entry); harvestOutput(entry, ready);
|
|
241
|
+
release(entry);
|
|
199
242
|
effects.current(); current();
|
|
200
243
|
return observation(input, ready, result.servedModel, result.complete ? "closed_fixture" : "failed_known", result.usageKnown ? "known_fixture" : "unknown", entry);
|
|
201
244
|
}).catch(async error => {
|
|
@@ -204,9 +247,11 @@ export function createGuidanceProbeLocalAdapter(options: ProbeLocalAdapterOption
|
|
|
204
247
|
catch { throw new ProbeLocalError("interrupted"); }
|
|
205
248
|
// 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
249
|
harvestOutput(entry, ready);
|
|
250
|
+
release(entry);
|
|
207
251
|
// `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
252
|
return observation(input, ready, entry.peer?.probeObservation().servedModel ?? null, "unknown", "unknown", entry, error instanceof ProbeConfinementError && !entry.peer);
|
|
209
253
|
}).finally(() => {
|
|
254
|
+
clearTimeout(timeout);
|
|
210
255
|
signal.removeEventListener("abort", abort);
|
|
211
256
|
if (entry.closed) { completed.add(entry.reservation); owned.delete(id); }
|
|
212
257
|
});
|
|
@@ -232,6 +232,7 @@ export class LocalPeer extends BasePeer {
|
|
|
232
232
|
private probeCalls = 0;
|
|
233
233
|
private probeServedModel: string | null = null;
|
|
234
234
|
private probeServedExact = false;
|
|
235
|
+
private probeProviderResponded = false;
|
|
235
236
|
private probeUsageKnown = true;
|
|
236
237
|
private probeToolPlan: ProbeToolResourcePlan | undefined;
|
|
237
238
|
private readonly probePermits = new Set<Promise<unknown>>();
|
|
@@ -348,8 +349,9 @@ export class LocalPeer extends BasePeer {
|
|
|
348
349
|
}
|
|
349
350
|
|
|
350
351
|
/** Private adapter bookkeeping, not an ordinary usage/status observer. */
|
|
351
|
-
probeObservation(): Pick<ProbeLocalResult, "servedModel" | "servedModelExact" | "usageKnown"> {
|
|
352
|
-
return { servedModel: this.probeServedModel, servedModelExact: this.probeServedExact, usageKnown: this.probeUsageKnown
|
|
352
|
+
probeObservation(): Pick<ProbeLocalResult, "servedModel" | "servedModelExact" | "usageKnown"> & { providerResponded: boolean } {
|
|
353
|
+
return { servedModel: this.probeServedModel, servedModelExact: this.probeServedExact, usageKnown: this.probeUsageKnown,
|
|
354
|
+
providerResponded: this.probeProviderResponded };
|
|
353
355
|
}
|
|
354
356
|
|
|
355
357
|
/** Resolves once the turn is claimed; a turn that cannot reach any model hands the envelopes back through onFailed. */
|
|
@@ -708,15 +710,25 @@ export class LocalPeer extends BasePeer {
|
|
|
708
710
|
const upper = probe.config.tokenUpperBound, inputBytes = Buffer.byteLength(frame, "utf8");
|
|
709
711
|
if (upper !== undefined && (probe.config.maxOutputTokens > upper || inputBytes > upper - probe.config.maxOutputTokens))
|
|
710
712
|
throw new ProbeToolRefusal("token_ceiling");
|
|
713
|
+
const reservedTokens = probe.pinnedChat ? inputBytes + probe.config.maxOutputTokens : upper;
|
|
711
714
|
const result = await probeLocalEffect(probe.accounting, "model_calls", frame, first ? undefined : { inputBytes },
|
|
712
|
-
|
|
715
|
+
reservedTokens, async signal => {
|
|
713
716
|
if (signal.aborted || this.abort?.signal.aborted) throw new ProbeLocalError("interrupted");
|
|
714
|
-
const value =
|
|
717
|
+
const value = probe.pinnedChat
|
|
718
|
+
? await probe.pinnedChat(body, this.abort!.signal)
|
|
719
|
+
: await this.opts.omni.chat(body, { signal: this.abort!.signal });
|
|
720
|
+
if (probe.pinnedChat) {
|
|
721
|
+
this.probeProviderResponded = true;
|
|
722
|
+
this.probeServedExact = value.servedModelExact === true;
|
|
723
|
+
this.probeServedModel = value.servedModel === GUIDANCE_PROBE_MODEL && !this.probeServedExact ? null : value.servedModel ?? null;
|
|
724
|
+
}
|
|
715
725
|
return { value, usage: probeObservedTokens(value) };
|
|
716
726
|
});
|
|
717
727
|
this.probeCalls++;
|
|
718
|
-
|
|
719
|
-
|
|
728
|
+
if (!probe.pinnedChat) {
|
|
729
|
+
this.probeServedModel = result.servedModel ?? null;
|
|
730
|
+
this.probeServedExact = result.servedModelExact === true;
|
|
731
|
+
}
|
|
720
732
|
this.probeUsageKnown = this.probeUsageKnown && probeObservedTokens(result) !== null;
|
|
721
733
|
if (!this.probeUsageKnown) throw new ProbeLocalError("usage");
|
|
722
734
|
if (result.servedModel !== GUIDANCE_PROBE_MODEL || result.servedModelExact !== true) throw new ProbeLocalError("model");
|
package/src/cli/help.ts
CHANGED
|
@@ -178,7 +178,7 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
|
|
|
178
178
|
["ahub budget execution configure <config.json> [--reason <text>] | disable <id> [--json] [--color=auto|always|never]", "opt-in limits on model calls, tool calls, time and tokens for pi and local; an optional reason is kept with the person and the time"],
|
|
179
179
|
]],
|
|
180
180
|
["History and reports", [
|
|
181
|
-
[`ahub guidance probe ${Object.values(GUIDANCE_PROBE_USAGE).join(" | ")}`, "person or configured conductor only: bounded T1 declaration and
|
|
181
|
+
[`ahub guidance probe ${Object.values(GUIDANCE_PROBE_USAGE).join(" | ")}`, "person or configured conductor only: bounded T1 declaration and probe lifecycle; receipts reads the sealed receipts, the outcome denominator and the comparability reasons, read-only; live execution only for the id the hub was started with in AGENTHUB_LIVE_GUIDANCE_PROBE_ID, started by the conductor"],
|
|
182
182
|
["ahub guidance create --file <json> [--json]", "record a bounded immutable advisory proposal through current task authority; no activation or probe"],
|
|
183
183
|
["ahub guidance list --task <n> --task-created <ms> [--cursor <token>] [--json]", "bounded guidance metadata pages; withdrawn history and withheld fields remain explicit"],
|
|
184
184
|
["ahub guidance show --task <n> --task-created <ms> --id <hash> [--json]", "screened editable-section diff selected by existing variant id, never a displayed experiment label"],
|
package/src/cli/main.ts
CHANGED
|
@@ -1435,7 +1435,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1435
1435
|
const { parseGuidanceCommand, validateGuidancePageReply, validateGuidanceDiffReply, validateGuidanceReceipt, renderGuidance, renderGuidanceReceipt } = await import("./guidance.ts");
|
|
1436
1436
|
const { parseGuidanceVariantV1, GUIDANCE_RECORD_MAX_BYTES } = await import("../hub/guidance-variants.ts");
|
|
1437
1437
|
const { parseGuidanceProbeSubcommand, parseGuidanceProbeRegistration, GUIDANCE_PROBE_REGISTRATION_BYTES,
|
|
1438
|
-
parseGuidanceProbePublicReceipt, parseGuidanceProbePublicStatus, parseGuidanceProbeReceiptExport } = await import("../hub/guidance-probes.ts");
|
|
1438
|
+
parseGuidanceProbePublicReceipt, parseGuidanceProbePublicStatus, parseGuidanceProbeReceiptExport, GUIDANCE_PROBE_LIVE_LIMITS, GUIDANCE_PROBE_STOP_TIMEOUT_MS } = await import("../hub/guidance-probes.ts");
|
|
1439
1439
|
const { guidanceProbeStatusLines } = await import("../ui/guidance-view.ts");
|
|
1440
1440
|
let probeCommand;
|
|
1441
1441
|
try { probeCommand = parseGuidanceProbeSubcommand(args); } catch { return fail(guidanceProbeUsage(args)); }
|
|
@@ -1464,7 +1464,7 @@ const commands: Record<string, () => Promise<void> | void> = {
|
|
|
1464
1464
|
: probeCommand.op === "cancel" ? { t: "guidance_probe_cancel", id: probeCommand.id, revision: probeCommand.revision }
|
|
1465
1465
|
: probeCommand.op === "receipts" ? { t: "guidance_probe_receipts", id: probeCommand.id }
|
|
1466
1466
|
: { t: "guidance_probe_show", id: probeCommand.id };
|
|
1467
|
-
const result = await hub.request(request);
|
|
1467
|
+
const result = await hub.request(request, probeCommand.op === "start" ? GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs + GUIDANCE_PROBE_STOP_TIMEOUT_MS : undefined);
|
|
1468
1468
|
if (result.ok !== true) {
|
|
1469
1469
|
const detail = terminalText(result.error ?? "guidance probe outcome is unconfirmed").replace(/[\r\n]+/g, " ").slice(0, 512);
|
|
1470
1470
|
const nextStep = probeCommand.op === "register" ? "" : `; inspect ahub guidance probe show --id ${probeCommand.id} before any explicit retry`;
|
|
@@ -23,7 +23,7 @@ export const PROTOCOL = 17;
|
|
|
23
23
|
/** The descriptor's legacy protocol field remains this floor for previous published clients. */
|
|
24
24
|
export const PROTOCOL_MIN = 16;
|
|
25
25
|
// Literal metadata is read without executing a recovery target; consistency is pinned in tests.
|
|
26
|
-
export const DAEMON_FEATURES = ["instructed_intent", "instructed_exact", "roadmap", "roadmap_instructed", "guidance_views", "guidance_variants", "guidance_probes", "guidance_probe_receipts", "execution_lineage", "model_overrides", "visuals", "project_autonomy", "conductor_recovery", "encrypted_rooms", "external_adapter_instances", "external_adapter_modules", "configured_acp", "configured_print", "native_hook_launch", "task_cancel", "invocation", "recovery_deferred_hub", "peer_instances", "role_stages", "task_planners", "release_trains", "reviewer_pool", "reviewer_quota", "native_tui_launch", "terminal_owner", "cli_audit_delegated", "action_policy_floor", "calendar_schedules", "research_records", "research_dispatch", "research_dropped_offers", "research_experiments", "research_comparisons", "research_runners", "task_handoff", "session_identity", "schema_guard", "design_specs", "queue_discard_states", "tool_write_idempotency", "research_evidence", "research_synthesis", "research_evidence_withdrawal", "advisor_surveys", "review_comments", "questions", "accepted_delivery_settlement", "completions", "review_observer_input_state", "task_handoff_key", "task_handoff_seq", "peer_takeover", "spec_readbacks"] as const;
|
|
26
|
+
export const DAEMON_FEATURES = ["instructed_intent", "instructed_exact", "roadmap", "roadmap_instructed", "guidance_views", "guidance_variants", "guidance_probes", "guidance_probe_receipts", "guidance_probe_live", "execution_lineage", "model_overrides", "visuals", "project_autonomy", "conductor_recovery", "encrypted_rooms", "external_adapter_instances", "external_adapter_modules", "configured_acp", "configured_print", "native_hook_launch", "task_cancel", "invocation", "recovery_deferred_hub", "peer_instances", "role_stages", "task_planners", "release_trains", "reviewer_pool", "reviewer_quota", "native_tui_launch", "terminal_owner", "cli_audit_delegated", "action_policy_floor", "calendar_schedules", "research_records", "research_dispatch", "research_dropped_offers", "research_experiments", "research_comparisons", "research_runners", "task_handoff", "session_identity", "schema_guard", "design_specs", "queue_discard_states", "tool_write_idempotency", "research_evidence", "research_synthesis", "research_evidence_withdrawal", "advisor_surveys", "review_comments", "questions", "accepted_delivery_settlement", "completions", "review_observer_input_state", "task_handoff_key", "task_handoff_seq", "peer_takeover", "spec_readbacks"] as const;
|
|
27
27
|
/** Protocols a current coordinator may authenticate while upgrading a running source. */
|
|
28
28
|
export const RECOVERY_SOURCE_PROTOCOLS = [9, 10, 11, 12, 13, 14, 15, 16, PROTOCOL] as const;
|
|
29
29
|
|
package/src/hub/daemon.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { piFailureText } from "./pi-failure.ts";
|
|
|
5
5
|
import { nativeReviewerQuota } from "../adapters/definitions/native-quota.ts";
|
|
6
6
|
import { parseGuidanceCreateInput, parseGuidanceIdQuery } from "./guidance-variants.ts";
|
|
7
7
|
import { GuidanceProbeStore } from "./guidance-probe-store.ts";
|
|
8
|
-
import { GuidanceProbeError, probeSessionGeneration, type ProbePublicReceipt, type ProbePublicStatus, type ProbeReceiptExport } from "./guidance-probes.ts";
|
|
8
|
+
import { GuidanceProbeError, probeSessionGeneration, probeSha256, type ProbePublicReceipt, type ProbePublicStatus, type ProbeReceiptExport } from "./guidance-probes.ts";
|
|
9
9
|
import { executionText, EXECUTION_REFERENCE_LIMITS } from "./execution-reference.ts";
|
|
10
10
|
import { publicDeliveryBodies } from "./delivery-public.ts";
|
|
11
11
|
import { GeneratedNoteRegistry, type GeneratedNoteProof } from "../memory/record-provenance.ts";
|
|
@@ -187,6 +187,7 @@ import { taskShellSandboxRestrictions } from "./task-shell-sandbox.ts";
|
|
|
187
187
|
import { hostShellEnvironment } from "../local/shell-environment.ts";
|
|
188
188
|
import { hubGitArgv, hubGitEnv, hubGitSync } from "./git.ts";
|
|
189
189
|
import { isLocalPeer, type LocalPeer } from "../adapters/local-worker.ts";
|
|
190
|
+
import { createLiveGuidanceProbeLocalAdapter } from "../adapters/local-probe.ts";
|
|
190
191
|
import { isClaudeImplementerPeer } from "../adapters/claude-implementer.ts";
|
|
191
192
|
import { isReviewerPrintPeer, reviewerNoVerdictLine, reviewerUnavailableReason, ReviewerUnavailableError, REVIEWER_FALLBACK_UNCONFIRMED, type ReviewerPrintPeer } from "../adapters/reviewer-print.ts";
|
|
192
193
|
import type { OwnedInputContext } from "../adapters/claude-print-child.ts";
|
|
@@ -2764,6 +2765,7 @@ export async function startDaemon(opts: DaemonOptions) {
|
|
|
2764
2765
|
tasks: () => board.list(), publicTitle: (task) => tasks.publicTitle(task), isPrivate: (task) => tasks.isPii(task),
|
|
2765
2766
|
approvalAgeMs: () => (config.conductor?.approval_wait_s ?? 30) * 1000,
|
|
2766
2767
|
readRound: (peer) => conductorHolds.readRound(peer), writeRound: (peer, signature) => conductorHolds.writeRound(peer, signature),
|
|
2768
|
+
revision: () => board.statusRevision(), task: (id) => board.get(id), // #1738: the 1 s tick and every task change check the round
|
|
2767
2769
|
emit: (notice) => {
|
|
2768
2770
|
if (stopping || recoveryActive()) return false;
|
|
2769
2771
|
return bus.publish(newEnvelope(HUB, notice.body, { to: [notice.peer], kind: notice.kind, priority: notice.priority,
|
|
@@ -3093,10 +3095,22 @@ export async function startDaemon(opts: DaemonOptions) {
|
|
|
3093
3095
|
let releaseReportPolicy: ((head: string, repo: string) => ReleaseReportPolicy | undefined) | undefined;
|
|
3094
3096
|
let questionStore!: QuestionStore;
|
|
3095
3097
|
startupTimings.mark("task_ports");
|
|
3098
|
+
const liveProbeId = process.env.AGENTHUB_LIVE_GUIDANCE_PROBE_ID;
|
|
3099
|
+
const liveProbe = probeSha256(liveProbeId) ? {
|
|
3100
|
+
id: liveProbeId,
|
|
3101
|
+
adapter: createLiveGuidanceProbeLocalAdapter({
|
|
3102
|
+
cwd: opts.cwd, omni: new OmniRoute(config.omniroute), permit: async () => false,
|
|
3103
|
+
current: () => {
|
|
3104
|
+
if (process.env.AGENTHUB_LIVE_GUIDANCE_PROBE_ID !== liveProbeId)
|
|
3105
|
+
// refusal:by-design human-authority: only the host operator can restore the startup selection
|
|
3106
|
+
throw new PreEffectToolRefusal("live guidance probe selection changed");
|
|
3107
|
+
},
|
|
3108
|
+
}),
|
|
3109
|
+
} : undefined;
|
|
3096
3110
|
const tasks: Tasks = new Tasks({
|
|
3097
3111
|
taskTokens: () => Object.fromEntries(usageRollup.query({ by: "task" }).rows.flatMap(row => /^\d+$/.test(row.key) ? [[Number(row.key), row.counted.value]] : [])),
|
|
3098
3112
|
ownerQuestionWait: (task, peer) => questionStore?.ownerWait(task, peer),
|
|
3099
|
-
guidanceProbes: { store: guidanceProbeStore, session: by => {
|
|
3113
|
+
guidanceProbes: { store: guidanceProbeStore, ...(liveProbe ? { live: liveProbe } : {}), session: by => {
|
|
3100
3114
|
const request = guidanceProbeRequestContext.getStore();
|
|
3101
3115
|
return request?.actor === by ? { generation: request.generation, nativeSession: request.nativeSession,
|
|
3102
3116
|
requestConnectionId: request.requestConnectionId, current: request.current } : undefined;
|
|
@@ -11731,6 +11745,10 @@ export async function startDaemon(opts: DaemonOptions) {
|
|
|
11731
11745
|
}
|
|
11732
11746
|
catch { return "instructed mode compatibility is unknown; choose a supporting daemon"; }
|
|
11733
11747
|
}
|
|
11748
|
+
if (!Array.isArray(msg.targetFeatures) || !msg.targetFeatures.includes("guidance_probe_live")) {
|
|
11749
|
+
try { if (guidanceProbeStore.hasLiveRecords()) return "target lacks guidance_probe_live; retained live guidance probe state requires a supporting daemon"; }
|
|
11750
|
+
catch { return "live guidance probe compatibility is unknown; inspect retained probe state or choose a supporting target"; }
|
|
11751
|
+
}
|
|
11734
11752
|
if (!Array.isArray(msg.targetFeatures) || !msg.targetFeatures.includes("guidance_probes")) {
|
|
11735
11753
|
try { if (guidanceProbeStore.hasRecords()) return "target lacks guidance_probes; retained probe declarations or held work require a supporting daemon; choose a target advertising guidance_probes"; }
|
|
11736
11754
|
catch { return "guidance probe compatibility is unknown; inspect retained probe state or choose a supporting target"; }
|
|
@@ -2,7 +2,7 @@ import { openHubDatabase, type Database } from "./db-schema.ts";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { GUIDANCE_ROLE_MAX_BYTES } from "./guidance-variants.ts";
|
|
4
4
|
import { executionText, EXECUTION_REFERENCE_LIMITS } from "./execution-reference.ts";
|
|
5
|
-
import { GUIDANCE_PROBE_LIMITS, GUIDANCE_PROBE_SESSION_BYTES, GUIDANCE_PROBE_MODEL, GuidanceProbeError, guidanceProbeCanonical, guidanceProbeManifestKey,
|
|
5
|
+
import { GUIDANCE_PROBE_LIMITS, GUIDANCE_PROBE_LIVE_LIMITS, isLiveGuidanceProbeManifest, GUIDANCE_PROBE_SESSION_BYTES, GUIDANCE_PROBE_MODEL, GuidanceProbeError, guidanceProbeCanonical, guidanceProbeManifestKey,
|
|
6
6
|
parseGuidanceProbeRegistration, guidanceProbeWorkerFrame, guidanceProbeNonGuidanceInputHash, probeHash, probeInteger, probeSha256, probeSessionGeneration,
|
|
7
7
|
type ProbeRegistrationV1, type ProbeHostBinding, type ProbeKey, type ProbeReceipt, type ProbeStoredState,
|
|
8
8
|
type ProbeCounters, type ProbeSession, type ProbeSessionAdmission, type ProbeAdmissionRecheck,
|
|
@@ -173,6 +173,19 @@ export class GuidanceProbeStore {
|
|
|
173
173
|
return row.present === 1;
|
|
174
174
|
} catch (error) { if (error instanceof GuidanceProbeError) throw error; return fail("storage"); }
|
|
175
175
|
}
|
|
176
|
+
hasLiveRecords(): boolean {
|
|
177
|
+
try {
|
|
178
|
+
// A malformed or oversized row cannot prove that an older daemon may safely take over.
|
|
179
|
+
const row = this.db.query(`SELECT EXISTS(SELECT 1 FROM guidance_probe_sessions WHERE
|
|
180
|
+
CASE WHEN typeof(body)='text' AND length(CAST(body AS BLOB))<=? AND json_valid(body)
|
|
181
|
+
THEN json_type(body,'$.live') IS NOT NULL ELSE 1 END)
|
|
182
|
+
OR EXISTS(SELECT 1 FROM guidance_probe_receipts WHERE
|
|
183
|
+
CASE WHEN typeof(body)='text' AND length(CAST(body AS BLOB))<=? AND json_valid(body)
|
|
184
|
+
THEN json_type(body,'$.mode') IS NOT NULL ELSE 1 END) AS present`)
|
|
185
|
+
.get(GUIDANCE_PROBE_SESSION_BYTES, PROBE_RECEIPT_ROW_BYTES) as { present: number };
|
|
186
|
+
return row.present === 1;
|
|
187
|
+
} catch { return fail("storage"); }
|
|
188
|
+
}
|
|
176
189
|
private transaction<T>(action: () => T): T {
|
|
177
190
|
try { return this.db.transaction(action).immediate(); }
|
|
178
191
|
catch (error) { if (error instanceof GuidanceProbeError) throw error; throw new GuidanceProbeError("storage"); }
|
|
@@ -215,7 +228,11 @@ export class GuidanceProbeStore {
|
|
|
215
228
|
|| !["planned", "reserved", "running", "failed_known", "closed_fixture", "not_needed", "unknown_held"].includes(session.state)
|
|
216
229
|
|| session.candidateArtifactSha256 !== null && !probeSha256(session.candidateArtifactSha256)) return fail("storage");
|
|
217
230
|
const fields = Object.keys(session);
|
|
218
|
-
if (fields.some(name => !["slotId", "generation", "revision", "state", "candidateArtifactSha256", "child", "host", "effect", "start", "coverage", "closeCause"].includes(name))
|
|
231
|
+
if (fields.some(name => !["slotId", "generation", "revision", "state", "candidateArtifactSha256", "child", "host", "effect", "start", "coverage", "closeCause", "live"].includes(name))
|
|
232
|
+
|| session.live !== undefined && (!session.live || !same(Object.keys(session.live).sort(), ["reservedAt", "tokensReserved"])
|
|
233
|
+
|| !isLiveGuidanceProbeManifest(registration.manifest) || ["planned", "not_needed"].includes(session.state)
|
|
234
|
+
|| !probeInteger(session.live.reservedAt) || !probeInteger(session.live.tokensReserved)
|
|
235
|
+
|| session.live.tokensReserved > GUIDANCE_PROBE_LIVE_LIMITS.tokens)
|
|
219
236
|
|| session.closeCause !== undefined && !["none", "cancel", "elapsed", "hold", "crash"].includes(session.closeCause)
|
|
220
237
|
|| !Object.hasOwn(session, "effect") || ["planned", "not_needed"].includes(session.state)
|
|
221
238
|
&& (session.effect !== null || session.host !== undefined || session.child !== undefined || session.start !== undefined || session.generation !== 0 || session.revision !== 0 || session.candidateArtifactSha256 !== null)
|
|
@@ -264,6 +281,11 @@ export class GuidanceProbeStore {
|
|
|
264
281
|
}
|
|
265
282
|
sessionCanonical(session); return session;
|
|
266
283
|
});
|
|
284
|
+
const liveSessions = sessions.filter(item => item.live);
|
|
285
|
+
if (liveSessions.length && (sessions.some(item => item.host && !item.live)
|
|
286
|
+
|| liveSessions.some(item => item.coverage.modelCalls > GUIDANCE_PROBE_LIVE_LIMITS.modelCalls
|
|
287
|
+
|| item.live!.reservedAt < checkedInteger(row.first_reserved) || item.live!.reservedAt > checkedInteger(row.last_wall))
|
|
288
|
+
|| liveSessions.reduce((sum, item) => sum + item.live!.tokensReserved, 0) !== totals.tokensReserved)) return fail("storage");
|
|
267
289
|
if (sessions.reduce((sum, item) => increment(sum, item.coverage.modelCalls), 0) !== totals.modelCalls
|
|
268
290
|
|| sessions.reduce((sum, item) => increment(sum, item.coverage.toolCalls), 0) !== totals.toolCalls) return fail("storage");
|
|
269
291
|
if (row.first_reserved_valid !== 1 || row.last_wall_valid !== 1 || !["declared", "active", "closing", "closed_fixture", "failed_fixture", "unknown_held"].includes(row.state as string)) return fail("storage");
|
|
@@ -356,7 +378,7 @@ export class GuidanceProbeStore {
|
|
|
356
378
|
const expected: ProbeStartSelector = { requestedRevision: input.expectedRevision, slotId: replay.slotId, variantId: input.child?.variantId ?? null,
|
|
357
379
|
inputFrameSha256: replay.start!.inputFrameSha256, inputFrameBytes: replay.start!.inputFrameBytes,
|
|
358
380
|
actor: input.host.actor, sessionGeneration: input.host.sessionGeneration, nativeSession: input.host.nativeSession, requestConnectionId: input.host.requestConnectionId };
|
|
359
|
-
if (!same(replay.start, expected) || !sameChild(replay.child, input.child)) return fail("changed");
|
|
381
|
+
if ((input.mode === "live") !== !!replay.live || !same(replay.start, expected) || !sameChild(replay.child, input.child)) return fail("changed");
|
|
360
382
|
if (input.preparedFrame && (input.preparedFrame.slotId !== replay.slotId || input.preparedFrame.sha256 !== expected.inputFrameSha256
|
|
361
383
|
|| input.preparedFrame.bytes !== expected.inputFrameBytes)) return fail("changed");
|
|
362
384
|
return { kind: "existing", receipt: receipt(state, true) };
|
|
@@ -367,6 +389,8 @@ export class GuidanceProbeStore {
|
|
|
367
389
|
const lane = lanes[0]; if (lane && (lane.manifestId !== input.key.id || lane.slotId !== null)) return fail("held");
|
|
368
390
|
const index = state.sessions.findIndex(item => item.state === "planned"), session = state.sessions[index]; if (!session) return fail("held");
|
|
369
391
|
const slot = state.registration.manifest.slots[index]!, previous = state.sessions[index - 1];
|
|
392
|
+
if (input.mode !== undefined && input.mode !== "live" || previous && (input.mode === "live") !== !!previous.live) return fail("changed");
|
|
393
|
+
if (input.mode === "live" && !isLiveGuidanceProbeManifest(state.registration.manifest)) return fail("invalid");
|
|
370
394
|
const frame = input.preparedFrame;
|
|
371
395
|
if (frame && (frame.slotId !== slot.id || !probeSha256(frame.sha256) || !probeInteger(frame.bytes) || frame.bytes === 0)) return fail("invalid");
|
|
372
396
|
if (frame) charge(state, "inputBytes", frame.bytes, state.registration.manifest.limits.inputBytes);
|
|
@@ -382,6 +406,7 @@ export class GuidanceProbeStore {
|
|
|
382
406
|
charge(state, slot.role === "worker" ? "workerAttempts" : "editorAttempts", 1, slot.role === "worker" ? GUIDANCE_PROBE_LIMITS.workerAttempts : GUIDANCE_PROBE_LIMITS.editorAttempts);
|
|
383
407
|
session.host = input.host; session.generation = increment(session.generation); session.revision = increment(session.revision); session.state = "reserved";
|
|
384
408
|
session.coverage = sessionCoverage(frame);
|
|
409
|
+
if (input.mode === "live") session.live = { reservedAt: now, tokensReserved: 0 };
|
|
385
410
|
session.start = { requestedRevision: input.expectedRevision, slotId: slot.id, variantId: input.child?.variantId ?? null,
|
|
386
411
|
inputFrameSha256: frame?.sha256 ?? null, inputFrameBytes: frame?.bytes ?? 0,
|
|
387
412
|
actor: input.host.actor, sessionGeneration: input.host.sessionGeneration, nativeSession: input.host.nativeSession, requestConnectionId: input.host.requestConnectionId };
|
|
@@ -404,6 +429,7 @@ export class GuidanceProbeStore {
|
|
|
404
429
|
if (state.cancelRequested || state.receipt.state !== "active" || state.admissionHold !== "none") return fail("held");
|
|
405
430
|
const now = this.now();
|
|
406
431
|
if (this.clockLost(reservation.key, state, now)) return receipt(state);
|
|
432
|
+
if (session.live && now - session.live.reservedAt >= GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) return fail("budget");
|
|
407
433
|
elapsed(state, now); this.save(reservation.key, state); return receipt(state);
|
|
408
434
|
});
|
|
409
435
|
}
|
|
@@ -417,6 +443,7 @@ export class GuidanceProbeStore {
|
|
|
417
443
|
if (session.coverage.launchExposed) return receipt(state, true);
|
|
418
444
|
const now = this.now();
|
|
419
445
|
if (this.clockLost(reservation.key, state, now)) return receipt(state);
|
|
446
|
+
if (session.live && now - session.live.reservedAt >= GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) return fail("budget");
|
|
420
447
|
elapsed(state, now);
|
|
421
448
|
session.coverage.launchExposed = true; advance(state); this.save(reservation.key, state); return receipt(state);
|
|
422
449
|
});
|
|
@@ -443,6 +470,15 @@ export class GuidanceProbeStore {
|
|
|
443
470
|
const limits = state.registration.manifest.limits;
|
|
444
471
|
const names = { model_calls: ["modelCalls", limits.modelCalls], tool_calls: ["toolCalls", limits.toolCalls], tokens: ["tokensReserved", limits.tokens], input_bytes: ["inputBytes", limits.inputBytes], scratch_bytes: ["scratchBytes", limits.scratchBytes], output_bytes: ["outputBytes", limits.outputBytes] } as const;
|
|
445
472
|
const target = names[input.unit]; if (!target || target[1] === undefined) return fail("budget");
|
|
473
|
+
if (session.live && now - session.live.reservedAt >= GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) return fail("budget");
|
|
474
|
+
if (session.live && input.unit === "tokens") return fail("invalid");
|
|
475
|
+
if (session.live && input.unit === "model_calls") {
|
|
476
|
+
const reserved = input.reservedTokens;
|
|
477
|
+
if (reserved === undefined || !probeInteger(reserved) || reserved === 0
|
|
478
|
+
|| session.coverage.modelCalls + input.amount > GUIDANCE_PROBE_LIVE_LIMITS.modelCalls
|
|
479
|
+
|| session.live.tokensReserved + reserved > GUIDANCE_PROBE_LIVE_LIMITS.tokens) return fail("budget");
|
|
480
|
+
session.live.tokensReserved += reserved;
|
|
481
|
+
}
|
|
446
482
|
const extra = resourceCharges(input.charges);
|
|
447
483
|
charge(state, target[0], input.amount, target[1]);
|
|
448
484
|
chargeResources(state, extra);
|
|
@@ -506,6 +542,7 @@ export class GuidanceProbeStore {
|
|
|
506
542
|
if (this.clockLost(input.reservation.key, state, now)) return receipt(state);
|
|
507
543
|
elapsed(state, now);
|
|
508
544
|
if (input.candidateArtifactSha256 !== null && !probeSha256(input.candidateArtifactSha256)) return fail("invalid");
|
|
545
|
+
if (session.live && now - session.live.reservedAt >= GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) hold(state, "elapsed");
|
|
509
546
|
const covered = session.coverage.launchExposed && !!session.coverage.inputFrameSha256 && session.coverage.modelCalls > 0
|
|
510
547
|
&& session.coverage.modelUsageKnown === session.coverage.modelCalls && session.coverage.toolUsageKnown === session.coverage.toolCalls
|
|
511
548
|
&& !session.coverage.usageUnknown;
|
|
@@ -597,7 +634,7 @@ export class GuidanceProbeStore {
|
|
|
597
634
|
// A receipt describes a session that reached a settled state, at the generation and revision it was reserved at.
|
|
598
635
|
const settled = session && !["planned", "not_needed", "reserved", "running"].includes(session.state);
|
|
599
636
|
// A receipt describes a settled session at the generation AND revision it was reserved at, and its state must be one that session could produce.
|
|
600
|
-
if (!session || !settled || value.generation !== session.generation || value.revision !== session.revision
|
|
637
|
+
if (!session || !settled || value.generation !== session.generation || value.revision !== session.revision || (value.mode === "live") !== !!session.live
|
|
601
638
|
|| value.state === "succeeded" && (session.state !== "closed_fixture" || !session.coverage.coverageVerified)
|
|
602
639
|
|| value.state === "failed" && session.state !== "failed_known"
|
|
603
640
|
|| value.state === "unavailable" && !["failed_known", "unknown_held"].includes(session.state)) return fail("storage");
|
|
@@ -652,7 +689,7 @@ export class GuidanceProbeStore {
|
|
|
652
689
|
const manifest = state.registration.manifest;
|
|
653
690
|
const wallEnd = this.now();
|
|
654
691
|
const existing = this.readReceipts(key).find(item => item.slotId === reservation.slotId);
|
|
655
|
-
const built = this.buildReceipt(state, session, measured, wallEnd);
|
|
692
|
+
const built = this.buildReceipt(state, session, measured, existing?.endedAt ?? wallEnd);
|
|
656
693
|
if (existing) {
|
|
657
694
|
const { digest: _a, ...left } = existing, { digest: _b, ...right } = built;
|
|
658
695
|
// Replays are allowed to differ only by the instant they were built at; every measured fact must match.
|
|
@@ -697,7 +734,7 @@ export class GuidanceProbeStore {
|
|
|
697
734
|
let outcome: ProbeReceiptState;
|
|
698
735
|
if (!measured.teardownVerified || cause === "crash") outcome = "unknown";
|
|
699
736
|
else if (cause === "cancel" || measured.cancelled) outcome = "cancelled";
|
|
700
|
-
else if (cause === "elapsed" || measured.timedOut) outcome = "timed_out";
|
|
737
|
+
else if (cause === "elapsed" || measured.timedOut || session.live && endedAt - session.live.reservedAt >= GUIDANCE_PROBE_LIVE_LIMITS.elapsedMs) outcome = "timed_out";
|
|
701
738
|
// `unavailable` means the session could not start. Once any model or tool call ran, a confinement error is a failure or an unknown, never unavailable.
|
|
702
739
|
else if (measured.unavailable && coverage.modelCalls === 0 && coverage.toolCalls === 0) outcome = "unavailable";
|
|
703
740
|
else if (session.state === "failed_known") outcome = "failed";
|
|
@@ -706,7 +743,7 @@ export class GuidanceProbeStore {
|
|
|
706
743
|
// A success needs every condition of the contract's Sealing section; any gap downgrades it, it never stays a success.
|
|
707
744
|
if (outcome === "succeeded" && (limits.size > 0 || measured.servedModel !== manifest.model.requested || session.state !== "closed_fixture")) outcome = "unknown";
|
|
708
745
|
const output = capOutput(measured.output, manifest.limits.outputBytes);
|
|
709
|
-
const body: Omit<ProbeReceiptV1, "digest"> = { v: 1, experimentId: manifest.experimentId, slotId: session.slotId, generation: session.generation, revision: session.revision,
|
|
746
|
+
const body: Omit<ProbeReceiptV1, "digest"> = { v: 1, ...(session.live ? { mode: "live" as const } : {}), experimentId: manifest.experimentId, slotId: session.slotId, generation: session.generation, revision: session.revision,
|
|
710
747
|
requestedModel: manifest.model.requested, servedModel: measured.servedModel, inputFrameSha256: coverage.inputFrameSha256,
|
|
711
748
|
workerEffectiveInputSha256: slot.role === "worker" ? measured.workerEffectiveInputSha256 : null, nonGuidanceInputSha256: slot.role === "worker" ? measured.nonGuidanceInputSha256 : null,
|
|
712
749
|
guidanceSha256: slot.arm === "baseline" ? manifest.guidance.baselineSha256 : session.child?.guidanceSha256 ?? null,
|
|
@@ -889,6 +926,7 @@ function unmeasuredSession(startedAt: number, servedModel: string | null): Probe
|
|
|
889
926
|
export class GuidanceProbeFixtureHost {
|
|
890
927
|
constructor(private readonly store: GuidanceProbeStore, private readonly options: {
|
|
891
928
|
ports?: GuidanceProbeFakePorts;
|
|
929
|
+
mode?: "live";
|
|
892
930
|
revalidate: () => ProbeAdmissionRecheck;
|
|
893
931
|
now: () => number;
|
|
894
932
|
prepareEditorFrame?: (state: ProbeStoredState, slot: ProbeSlot) => string | Promise<string>;
|
|
@@ -898,7 +936,7 @@ export class GuidanceProbeFixtureHost {
|
|
|
898
936
|
async start(input: ProbeSessionAdmission, signal: AbortSignal): Promise<ProbeReceipt> {
|
|
899
937
|
const ports = this.options.ports;
|
|
900
938
|
// Production T1 stops here, before even selecting/binding a child or reserving a slot.
|
|
901
|
-
if (!ports) return fail("runner");
|
|
939
|
+
if (!ports || input.mode !== this.options.mode) return fail("runner");
|
|
902
940
|
if (signal.aborted) return fail("held");
|
|
903
941
|
const current = this.store.read(input.key); if (!current) return fail("changed");
|
|
904
942
|
const original = this.store.startSelector(input.key, input.expectedRevision);
|
|
@@ -972,7 +1010,7 @@ export class GuidanceProbeFixtureHost {
|
|
|
972
1010
|
const observation = launch.observation;
|
|
973
1011
|
observed = observation;
|
|
974
1012
|
const matched = this.matchObservation(observation, reservation, frame, slot.role === "worker");
|
|
975
|
-
if (!matched) this.store.latchHold(reservation, "observation");
|
|
1013
|
+
if (!matched || input.mode === "live" && observation.servedModel !== GUIDANCE_PROBE_MODEL) this.store.latchHold(reservation, "observation");
|
|
976
1014
|
// Settlement and receipt are one transaction (the contract's Sealing step 3): a session is never visible as settled without its receipt. An
|
|
977
1015
|
// observation that carries no measurement, or that did not match, is sealed with the conservative one: teardown not verified, nothing observed.
|
|
978
1016
|
const measured: ProbeMeasuredSession = matched && observation.measured ? { ...observation.measured, startedAt } : unmeasuredSession(startedAt, matched ? observation.servedModel : null);
|
|
@@ -999,7 +1037,10 @@ export class GuidanceProbeFixtureHost {
|
|
|
999
1037
|
private matchObservation(value: ProbeFakeObservation, reservation: ProbeReservation,
|
|
1000
1038
|
frame: { inputFrame: string; nonGuidanceInputSha256: string }, worker: boolean): boolean {
|
|
1001
1039
|
return !!value && same(value.reservation, reservation) && ["closed_fixture", "failed_known", "unknown"].includes(value.outcome)
|
|
1002
|
-
&& value.servedModel === GUIDANCE_PROBE_MODEL
|
|
1040
|
+
&& (value.servedModel === GUIDANCE_PROBE_MODEL || this.options.mode === "live"
|
|
1041
|
+
&& (value.servedModel === null || typeof value.servedModel === "string" && Buffer.byteLength(value.servedModel) <= 256))
|
|
1042
|
+
&& (this.options.mode !== "live" || !value.measured || value.servedModel === value.measured.servedModel)
|
|
1043
|
+
&& value.inputFrameHash === probeHash(frame.inputFrame)
|
|
1003
1044
|
&& (worker ? value.workerEffectiveInputHash === probeHash(frame.inputFrame) && value.nonGuidanceInputSha256 === frame.nonGuidanceInputSha256
|
|
1004
1045
|
: value.workerEffectiveInputHash === null && value.nonGuidanceInputSha256 === null)
|
|
1005
1046
|
&& (value.candidateArtifactSha256 === null || probeSha256(value.candidateArtifactSha256));
|