@staix/agent-hub 0.36.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 +17 -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 +802 -0
- package/docs/design/model-routes.md +437 -12
- package/docs/dogfood.md +11 -13
- package/docs/events.md +20 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +112 -148
- package/docs/quickstart.md +9 -3
- package/docs/research.md +1 -1
- package/docs/sdlc.md +5 -3
- package/docs/security.md +21 -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-guidance-probe-t2-1226.md +153 -0
- package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
- package/docs/verified.json +24 -24
- package/package.json +3 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +2373 -1436
- package/plugins/agent-hub/server.js +2445 -1497
- package/src/adapters/channel-peer.ts +7 -1
- package/src/adapters/compat.ts +1 -1
- package/src/adapters/local-probe.ts +174 -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/install-paths.ts +7 -2
- package/src/cli/main.ts +60 -4
- package/src/cli/runtime-version-warning.ts +2 -2
- package/src/cli/sdlc-output.ts +9 -5
- 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 +169 -9
- package/src/hub/events.ts +3 -2
- package/src/hub/guidance-probe-store.ts +713 -0
- package/src/hub/guidance-probes.ts +358 -0
- package/src/hub/inference.ts +18 -5
- package/src/hub/operational-authority.ts +13 -1
- package/src/hub/peers.ts +5 -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/tasks.ts +317 -6
- 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/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/plugin.ts +70 -20
- 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
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { types } from "node:util";
|
|
3
|
+
import { executionText, EXECUTION_REFERENCE_LIMITS } from "./execution-reference.ts";
|
|
4
|
+
|
|
5
|
+
/** Published V1 format/admission bounds, not native execution guarantees. */
|
|
6
|
+
export const GUIDANCE_PROBE_LIMITS = Object.freeze({ recordBytes: 32768, snapshotBytes: 32768,
|
|
7
|
+
storageBytes: 1073741824, workerAttempts: 4, editorAttempts: 5, slots: 9, hashLength: 64 });
|
|
8
|
+
const registrationScaffoldBytes = Buffer.byteLength(JSON.stringify({ manifest: 0, snapshots: { task: "", baselineContext: "", dataPolicy: 0, systemPolicy: "", improverContext: "" } }));
|
|
9
|
+
/** Closed composition bounds, separate from each admitted manifest/snapshot ceiling. */
|
|
10
|
+
export const GUIDANCE_PROBE_REGISTRATION_BYTES = GUIDANCE_PROBE_LIMITS.recordBytes + GUIDANCE_PROBE_LIMITS.snapshotBytes
|
|
11
|
+
+ 4 * 2 * GUIDANCE_PROBE_LIMITS.snapshotBytes + registrationScaffoldBytes;
|
|
12
|
+
export const GUIDANCE_PROBE_SESSION_BYTES = 4 * GUIDANCE_PROBE_LIMITS.recordBytes;
|
|
13
|
+
export const GUIDANCE_PROBE_STOP_TIMEOUT_MS = 5000;
|
|
14
|
+
export const GUIDANCE_PROBE_FENCE_INTERVAL_MS = 250;
|
|
15
|
+
export const GUIDANCE_PROBE_MODEL = "qwen27b/qwen3.8-27b";
|
|
16
|
+
export type ProbeInteger = number;
|
|
17
|
+
export type ProbeSha256 = string;
|
|
18
|
+
export type ProbeId = string;
|
|
19
|
+
export type ProbeTree = { objectFormat: "sha1"; oid: string } | { objectFormat: "sha256"; oid: string };
|
|
20
|
+
export interface ProbeSnapshotRef { sha256: string; bytes: number }
|
|
21
|
+
export interface ProbeRoleIdentity { id: string; layer: "shipped" | "project"; baselineSha256: string }
|
|
22
|
+
export type ProbeArm = "baseline" | "candidate1" | "candidate2" | "successor";
|
|
23
|
+
export type ProbeStage = "baseline" | "proposal1" | "candidate1" | "proposal2" | "candidate2" | "compose" | "successor" | "select" | "reflect";
|
|
24
|
+
export interface ProbeSlot { id: string; stage: ProbeStage; role: "worker" | "proposal" | "compose" | "select" | "reflect"; arm: ProbeArm | "none"; retryOf?: string }
|
|
25
|
+
export interface GuidanceProbeManifestV1 {
|
|
26
|
+
v: 1; projectKey: string; experimentId: string;
|
|
27
|
+
task: { id: number; created: number; flowRevision: number };
|
|
28
|
+
role: ProbeRoleIdentity;
|
|
29
|
+
inputs: { task: ProbeSnapshotRef; baselineContext: ProbeSnapshotRef; dataPolicy: ProbeSnapshotRef; systemPolicy: ProbeSnapshotRef; codeTree: ProbeTree };
|
|
30
|
+
runtime: { runtimeSha256: string; toolsetSha256: string; modelConfigSha256: string };
|
|
31
|
+
model: { requested: typeof GUIDANCE_PROBE_MODEL; expectedServed: typeof GUIDANCE_PROBE_MODEL };
|
|
32
|
+
guidance: { baselineSha256: string };
|
|
33
|
+
improverContextHash?: string; improverContextBytes?: number;
|
|
34
|
+
slots: readonly ProbeSlot[];
|
|
35
|
+
limits: { modelCalls: number; toolCalls: number; elapsedMs: number; tokens?: number; inputBytes: number; scratchBytes: number; outputBytes: number };
|
|
36
|
+
taskOrderSeed?: number;
|
|
37
|
+
}
|
|
38
|
+
export interface ProbeDataPolicyV1 {
|
|
39
|
+
v: 1;
|
|
40
|
+
allowedWrites: readonly { root: "scratch" | "output"; relative: string }[];
|
|
41
|
+
admittedData: readonly { id: string; sha256: string; bytes: number }[];
|
|
42
|
+
roles: {
|
|
43
|
+
worker: { dataIds: readonly string[]; guidanceOnlyExperience: true };
|
|
44
|
+
proposal: { dataIds: readonly string[]; improverContext: boolean };
|
|
45
|
+
compose: { dataIds: readonly string[]; improverContext: boolean };
|
|
46
|
+
select: { dataIds: readonly string[]; anonymizedDeliverables: true };
|
|
47
|
+
reflect: { dataIds: readonly string[]; closedRoundOnly: true };
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface ProbePrivateSnapshots { task: string; baselineContext: string; dataPolicy: ProbeDataPolicyV1; systemPolicy: string; improverContext?: string }
|
|
51
|
+
export interface ProbeRegistrationV1 { manifest: GuidanceProbeManifestV1; snapshots: ProbePrivateSnapshots }
|
|
52
|
+
export type ProbeState = "declared" | "active" | "closing" | "closed_fixture" | "failed_fixture" | "unknown_held";
|
|
53
|
+
export type ProbeSessionState = "planned" | "reserved" | "running" | "failed_known" | "closed_fixture" | "not_needed" | "unknown_held";
|
|
54
|
+
export type ProbeBudgetUnit = "model_calls" | "tool_calls" | "tokens" | "input_bytes" | "scratch_bytes" | "output_bytes";
|
|
55
|
+
export interface ProbeKey { projectKey: string; id: string }
|
|
56
|
+
export interface ProbeHostBinding {
|
|
57
|
+
projectKey: string; actor: string; task: { id: number; created: number; flowRevision: number }; role: ProbeRoleIdentity;
|
|
58
|
+
baselineGuidance: string; sessionGeneration: number | string; nativeSession: string | null; requestConnectionId: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ProbeChildBinding {
|
|
61
|
+
variantId: string; candidateSha256: string; guidanceSha256: string; task: ProbeHostBinding["task"]; role: ProbeRoleIdentity; guidance: string;
|
|
62
|
+
authoring: "admitted_fixture" | "uncontrolled"; sourceSessionId: string | null;
|
|
63
|
+
}
|
|
64
|
+
export interface ProbeAdmissionRecheck { host: ProbeHostBinding; child?: ProbeChildBinding }
|
|
65
|
+
/** Hash/size of the exact frame built once by the trusted host before atomic admission. */
|
|
66
|
+
export interface ProbePreparedFrame { slotId: string; sha256: string; bytes: number }
|
|
67
|
+
export interface ProbePreparedWorkerFrame { inputFrame: string; nonGuidanceInputSha256: string }
|
|
68
|
+
export type ProbeWorkerFramePreparer = (state: ProbeStoredState, slot: ProbeSlot, guidance: string) => ProbePreparedWorkerFrame | Promise<ProbePreparedWorkerFrame>;
|
|
69
|
+
export interface ProbeResourceCharges { inputBytes?: number; scratchBytes?: number; outputBytes?: number }
|
|
70
|
+
export interface ProbeSessionAdmission {
|
|
71
|
+
key: ProbeKey; expectedRevision: number; host: ProbeHostBinding; child?: ProbeChildBinding; preparedFrame?: ProbePreparedFrame; now: number;
|
|
72
|
+
}
|
|
73
|
+
export interface ProbeReservation { key: ProbeKey; slotId: string; generation: number; revision: number }
|
|
74
|
+
export interface ProbeStartSelector {
|
|
75
|
+
requestedRevision: number; slotId: string; variantId: string | null; inputFrameSha256: string | null; inputFrameBytes: number;
|
|
76
|
+
actor: string; sessionGeneration: number | string; nativeSession: string | null; requestConnectionId: string;
|
|
77
|
+
}
|
|
78
|
+
export interface ProbeReceipt { id: string; revision: number; state: ProbeState; already: boolean }
|
|
79
|
+
export type ProbeReservationResult = { kind: "granted"; reservation: ProbeReservation } | { kind: "existing"; receipt: ProbeReceipt };
|
|
80
|
+
export interface ProbeEffectAdmission { reservation: ProbeReservation; sequence: number; unit: ProbeBudgetUnit; amount: number; reservedTokens?: number; charges?: ProbeResourceCharges; descriptorSha256: string; now: number }
|
|
81
|
+
export type ProbeEffectAdmissionResult = { kind: "granted"; admission: ProbeEffectAdmission } | { kind: "existing"; state: "pending" | "settled" | "unknown" };
|
|
82
|
+
export interface ProbeEffectSettlement { admission: ProbeEffectAdmission; outcome: "settled" | "unknown" }
|
|
83
|
+
export interface ProbeSessionSettlement { reservation: ProbeReservation; outcome: "closed_fixture" | "failed_known" | "unknown"; candidateArtifactSha256: string | null; now: number }
|
|
84
|
+
export interface ProbeSessionCoverage {
|
|
85
|
+
inputFrameSha256: string | null; inputFrameBytes: number; launchExposed: boolean; preLaunchFailure: boolean;
|
|
86
|
+
modelCalls: number; modelUsageKnown: number; toolCalls: number; toolUsageKnown: number;
|
|
87
|
+
usageUnknown: boolean; coverageVerified: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface ProbeUsageObservation { admission: ProbeEffectAdmission; observed: number | null; observationSha256: string }
|
|
90
|
+
export interface ProbeCancellation { key: ProbeKey; expectedRevision: number; host: ProbeHostBinding }
|
|
91
|
+
export interface ProbeCounters {
|
|
92
|
+
workerAttempts: number; editorAttempts: number; modelCalls: number; toolCalls: number; tokensReserved: number; tokensObservedKnown: number;
|
|
93
|
+
inputBytes: number; scratchBytes: number; outputBytes: number; elapsedHighWaterMs: number; usageUnknown: boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface ProbeSession {
|
|
96
|
+
slotId: string; generation: number; revision: number; state: ProbeSessionState; candidateArtifactSha256: string | null;
|
|
97
|
+
child?: ProbeChildBinding;
|
|
98
|
+
start?: ProbeStartSelector;
|
|
99
|
+
coverage: ProbeSessionCoverage;
|
|
100
|
+
}
|
|
101
|
+
export interface ProbeStoredState {
|
|
102
|
+
registration: ProbeRegistrationV1; binding: ProbeHostBinding; receipt: ProbeReceipt; counters: ProbeCounters;
|
|
103
|
+
firstReservedAt: number | null; admissionHold: "none" | "elapsed" | "observation" | "usage"; cancelRequested: boolean; notNeeded: number; sessions: readonly ProbeSession[];
|
|
104
|
+
}
|
|
105
|
+
export interface ProbeIntegrity { experiments: number; sessions: number; digest: string }
|
|
106
|
+
export interface ProbeFakeLaunch { reservation: ProbeReservation; slot: ProbeSlot; manifest: GuidanceProbeManifestV1; inputFrame: string; inputSha256: string; nonGuidanceInputSha256: string; purpose: "guidance_probe" }
|
|
107
|
+
export interface ProbeFakeObservation {
|
|
108
|
+
reservation: ProbeReservation; outcome: "closed_fixture" | "failed_known" | "unknown"; servedModel: string | null;
|
|
109
|
+
inputFrameHash: string | null;
|
|
110
|
+
workerEffectiveInputHash: string | null; nonGuidanceInputSha256: string | null; candidateArtifactSha256: string | null; usage: "known_fixture" | "unknown";
|
|
111
|
+
}
|
|
112
|
+
export interface ProbeFakeStop { reservation: ProbeReservation }
|
|
113
|
+
export interface ProbeFakeStopObservation { reservation: ProbeReservation; stopped: "known_fixture" | "unknown" }
|
|
114
|
+
export interface ProbeFakeEffectRequest { sequence: number; unit: "model_calls" | "tool_calls" | "resources"; descriptorSha256: string; reservedTokens?: number; charges?: ProbeResourceCharges }
|
|
115
|
+
export interface ProbeFakeEffectValue<T> { value: T; usage: number | null; observationSha256: string }
|
|
116
|
+
export type ProbeFakeEffectResult<T> = { kind: "executed"; value: T } | { kind: "existing"; state: "pending" | "settled" | "unknown" };
|
|
117
|
+
export interface ProbeFakeEffects {
|
|
118
|
+
/** Fresh captured actor/G1/ledger fence; no authority is reconstructed from metadata. */
|
|
119
|
+
current(): void;
|
|
120
|
+
runEffect<T>(request: ProbeFakeEffectRequest, effect: (signal: AbortSignal) => Promise<ProbeFakeEffectValue<T>>): Promise<ProbeFakeEffectResult<T>>;
|
|
121
|
+
}
|
|
122
|
+
/** Host test constructor only: never selected by manifest, configuration or a wire field. */
|
|
123
|
+
export interface GuidanceProbeFakePorts {
|
|
124
|
+
launch(input: ProbeFakeLaunch, effects: ProbeFakeEffects, signal: AbortSignal): Promise<ProbeFakeObservation>;
|
|
125
|
+
stop(input: ProbeFakeStop, signal: AbortSignal): Promise<ProbeFakeStopObservation>;
|
|
126
|
+
}
|
|
127
|
+
export interface ProbePublicReceipt extends ProbeReceipt { experimentId: string; taskId: number; evidence: "declaration" | "fixture" | "unknown" }
|
|
128
|
+
export interface ProbePublicStatus extends ProbePublicReceipt { counters: ProbeCounters; cancelRequested: boolean; notNeeded: number; comparable: boolean; authoring: "admitted_fixture" | "uncontrolled" | "unknown" }
|
|
129
|
+
export type GuidanceProbeCommand = { op: "register"; file: string; json: boolean }
|
|
130
|
+
| { op: "start"; id: string; revision: number; variantId?: string; json: boolean }
|
|
131
|
+
| { op: "show"; id: string; json: boolean } | { op: "cancel"; id: string; revision: number; json: boolean };
|
|
132
|
+
|
|
133
|
+
export class GuidanceProbeError extends Error {
|
|
134
|
+
constructor(readonly reason: "invalid" | "changed" | "budget" | "held" | "runner" | "storage") {
|
|
135
|
+
super({ invalid: "invalid probe fields or bounds; reload the closed V1 declaration before retrying",
|
|
136
|
+
changed: "probe binding or revision changed; read the current task, G1 and probe before retrying",
|
|
137
|
+
budget: "probe aggregate budget is exhausted or unknown; inspect the retained accounting before a separate experiment",
|
|
138
|
+
held: "probe outcome is uncertain or already active; inspect retained state without replaying work",
|
|
139
|
+
runner: "probe runner is unavailable in production T1; use fake-only fixtures, not a live launch",
|
|
140
|
+
storage: "probe storage is invalid or unavailable; inspect retained probe state before retrying" }[reason]);
|
|
141
|
+
this.name = "GuidanceProbeError";
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const invalid = (): never => { throw new GuidanceProbeError("invalid"); };
|
|
145
|
+
export const probeHash = (text: string): string => createHash("sha256").update(text, "utf8").digest("hex");
|
|
146
|
+
export const probeInteger = (value: unknown): value is number => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
147
|
+
export const probeSha256 = (value: unknown): value is string => typeof value === "string" && value.length === GUIDANCE_PROBE_LIMITS.hashLength && /^[a-f0-9]+$/.test(value);
|
|
148
|
+
const identity = (value: unknown): value is string => executionText(value, EXECUTION_REFERENCE_LIMITS.id) && !/\p{Cf}/u.test(value);
|
|
149
|
+
export const probeSessionGeneration = (value: unknown): value is number | string => probeInteger(value) || identity(value);
|
|
150
|
+
const required = (condition: unknown): void => { if (!condition) invalid(); };
|
|
151
|
+
|
|
152
|
+
/** Bounded inert copy: no getter, iterator, proxy, toJSON, sparse array or cycle is evaluated. */
|
|
153
|
+
function inert(value: unknown, maximum: number): unknown {
|
|
154
|
+
let remaining = maximum;
|
|
155
|
+
const seen = new Set<object>();
|
|
156
|
+
const charge = (bytes: number) => { remaining -= bytes; if (remaining < 0) invalid(); };
|
|
157
|
+
const copy = (item: unknown): unknown => {
|
|
158
|
+
if (item === null || typeof item === "boolean" || typeof item === "number" && Number.isFinite(item)) { charge(Buffer.byteLength(JSON.stringify(item))); return item; }
|
|
159
|
+
if (typeof item === "string") { if (item.length > remaining) invalid(); charge(Buffer.byteLength(JSON.stringify(item))); return item; }
|
|
160
|
+
if (!item || typeof item !== "object" || types.isProxy(item) || seen.has(item)) return invalid();
|
|
161
|
+
const array = Array.isArray(item), proto = Object.getPrototypeOf(item);
|
|
162
|
+
if (array ? proto !== Array.prototype : proto !== Object.prototype && proto !== null) return invalid();
|
|
163
|
+
const keys = Reflect.ownKeys(item);
|
|
164
|
+
if (keys.length > remaining) return invalid();
|
|
165
|
+
seen.add(item); charge(2);
|
|
166
|
+
if (array) {
|
|
167
|
+
const length = Object.getOwnPropertyDescriptor(item, "length")?.value;
|
|
168
|
+
if (!probeInteger(length) || keys.length !== length + 1) return invalid();
|
|
169
|
+
const result: unknown[] = [];
|
|
170
|
+
for (let index = 0; index < length; index++) {
|
|
171
|
+
const field = Object.getOwnPropertyDescriptor(item, String(index));
|
|
172
|
+
if (!field || !("value" in field) || !field.enumerable) return invalid();
|
|
173
|
+
if (index) charge(1); result.push(copy(field.value));
|
|
174
|
+
}
|
|
175
|
+
seen.delete(item); return result;
|
|
176
|
+
}
|
|
177
|
+
const result: Record<string, unknown> = Object.create(null);
|
|
178
|
+
let index = 0;
|
|
179
|
+
for (const key of keys) {
|
|
180
|
+
if (typeof key !== "string") return invalid();
|
|
181
|
+
const field = Object.getOwnPropertyDescriptor(item, key);
|
|
182
|
+
if (!field || !("value" in field) || !field.enumerable) return invalid();
|
|
183
|
+
charge(Buffer.byteLength(JSON.stringify(key)) + 1 + (index++ ? 1 : 0)); result[key] = copy(field.value);
|
|
184
|
+
}
|
|
185
|
+
seen.delete(item); return result;
|
|
186
|
+
};
|
|
187
|
+
return copy(value);
|
|
188
|
+
}
|
|
189
|
+
function object(value: unknown, keys: readonly string[], optional: readonly string[] = []): Record<string, unknown> {
|
|
190
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return invalid();
|
|
191
|
+
const fields = value as Record<string, unknown>;
|
|
192
|
+
if (Object.keys(fields).some(key => !keys.includes(key) && !optional.includes(key)) || keys.some(key => !Object.hasOwn(fields, key))) return invalid();
|
|
193
|
+
return fields;
|
|
194
|
+
}
|
|
195
|
+
function canonical(value: unknown): string {
|
|
196
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
197
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical((value as Record<string, unknown>)[key])}`).join(",")}}`;
|
|
198
|
+
return JSON.stringify(value);
|
|
199
|
+
}
|
|
200
|
+
export const guidanceProbeCanonical = (value: unknown, maximum: number = GUIDANCE_PROBE_LIMITS.recordBytes): string => canonical(inert(value, maximum));
|
|
201
|
+
function ref(value: unknown): void { const fields = object(value, ["sha256", "bytes"]); required(probeSha256(fields.sha256) && probeInteger(fields.bytes) && fields.bytes <= GUIDANCE_PROBE_LIMITS.snapshotBytes); }
|
|
202
|
+
function role(value: unknown): void { const fields = object(value, ["id", "layer", "baselineSha256"]); required(identity(fields.id) && ["shipped", "project"].includes(fields.layer as string) && probeSha256(fields.baselineSha256)); }
|
|
203
|
+
const graph: readonly [ProbeStage, ProbeSlot["role"], ProbeSlot["arm"]][] = [
|
|
204
|
+
["baseline", "worker", "baseline"], ["proposal1", "proposal", "none"], ["candidate1", "worker", "candidate1"],
|
|
205
|
+
["proposal2", "proposal", "none"], ["candidate2", "worker", "candidate2"], ["compose", "compose", "none"],
|
|
206
|
+
["successor", "worker", "successor"], ["select", "select", "none"], ["reflect", "reflect", "none"] ];
|
|
207
|
+
function slots(value: unknown): void {
|
|
208
|
+
required(Array.isArray(value) && value.length > 0 && value.length <= GUIDANCE_PROBE_LIMITS.slots);
|
|
209
|
+
const list = value as ProbeSlot[], ids = new Set<string>(), counts = new Map<string, number>();
|
|
210
|
+
let last = -1;
|
|
211
|
+
for (const slot of list) {
|
|
212
|
+
const fields = object(slot, ["id", "stage", "role", "arm"], ["retryOf"]), position = graph.findIndex(item => item[0] === fields.stage);
|
|
213
|
+
required(identity(fields.id) && !ids.has(fields.id as string) && position >= 0);
|
|
214
|
+
required(graph[position]![1] === fields.role && graph[position]![2] === fields.arm);
|
|
215
|
+
if (Object.hasOwn(fields, "retryOf")) {
|
|
216
|
+
const prior = list[ids.size - 1];
|
|
217
|
+
required(identity(fields.retryOf) && prior && prior.id === fields.retryOf && prior.stage === fields.stage && position === last);
|
|
218
|
+
} else { required(position > last); last = position; }
|
|
219
|
+
ids.add(slot.id); counts.set(slot.role, (counts.get(slot.role) ?? 0) + 1);
|
|
220
|
+
}
|
|
221
|
+
required(list[0]!.stage === "baseline" && list.some(item => item.stage === "candidate1"));
|
|
222
|
+
required(!list.some(item => item.stage === "proposal2") || list.some(item => item.stage === "candidate2"));
|
|
223
|
+
required(!list.some(item => item.stage === "compose") || list.some(item => item.stage === "successor"));
|
|
224
|
+
required((counts.get("worker") ?? 0) <= GUIDANCE_PROBE_LIMITS.workerAttempts && (counts.get("proposal") ?? 0) <= 2
|
|
225
|
+
&& ["compose", "select", "reflect"].every(key => (counts.get(key) ?? 0) <= 1)
|
|
226
|
+
&& list.filter(item => item.role !== "worker").length <= GUIDANCE_PROBE_LIMITS.editorAttempts);
|
|
227
|
+
}
|
|
228
|
+
function manifest(value: unknown): GuidanceProbeManifestV1 {
|
|
229
|
+
const fields = object(value, ["v", "projectKey", "experimentId", "task", "role", "inputs", "runtime", "model", "guidance", "slots", "limits"], ["improverContextHash", "improverContextBytes", "taskOrderSeed"]);
|
|
230
|
+
required(fields.v === 1 && identity(fields.projectKey) && identity(fields.experimentId));
|
|
231
|
+
const task = object(fields.task, ["id", "created", "flowRevision"]); required(probeInteger(task.id) && task.id > 0 && probeInteger(task.created) && probeInteger(task.flowRevision)); role(fields.role);
|
|
232
|
+
const inputs = object(fields.inputs, ["task", "baselineContext", "dataPolicy", "systemPolicy", "codeTree"]);
|
|
233
|
+
for (const key of ["task", "baselineContext", "dataPolicy", "systemPolicy"]) ref(inputs[key]);
|
|
234
|
+
const tree = object(inputs.codeTree, ["objectFormat", "oid"]), oidLength = tree.objectFormat === "sha1" ? 40 : tree.objectFormat === "sha256" ? GUIDANCE_PROBE_LIMITS.hashLength : 0;
|
|
235
|
+
required(typeof tree.oid === "string" && oidLength > 0 && tree.oid.length === oidLength && /^[a-f0-9]+$/.test(tree.oid));
|
|
236
|
+
const runtime = object(fields.runtime, ["runtimeSha256", "toolsetSha256", "modelConfigSha256"]); required(Object.values(runtime).every(probeSha256));
|
|
237
|
+
const model = object(fields.model, ["requested", "expectedServed"]); required(model.requested === GUIDANCE_PROBE_MODEL && model.expectedServed === GUIDANCE_PROBE_MODEL);
|
|
238
|
+
required(probeSha256(object(fields.guidance, ["baselineSha256"]).baselineSha256));
|
|
239
|
+
const limits = object(fields.limits, ["modelCalls", "toolCalls", "elapsedMs", "inputBytes", "scratchBytes", "outputBytes"], ["tokens"]);
|
|
240
|
+
required(Object.values(limits).every(probeInteger));
|
|
241
|
+
let bytes = GUIDANCE_PROBE_LIMITS.storageBytes;
|
|
242
|
+
for (const key of ["inputBytes", "scratchBytes", "outputBytes"]) { required((limits[key] as number) <= bytes); bytes -= limits[key] as number; }
|
|
243
|
+
required(Object.hasOwn(fields, "improverContextHash") === Object.hasOwn(fields, "improverContextBytes"));
|
|
244
|
+
if (Object.hasOwn(fields, "improverContextHash")) { required(probeSha256(fields.improverContextHash)); required(probeInteger(fields.improverContextBytes) && fields.improverContextBytes <= GUIDANCE_PROBE_LIMITS.snapshotBytes); }
|
|
245
|
+
if (Object.hasOwn(fields, "taskOrderSeed")) required(probeInteger(fields.taskOrderSeed));
|
|
246
|
+
slots(fields.slots);
|
|
247
|
+
return fields as unknown as GuidanceProbeManifestV1;
|
|
248
|
+
}
|
|
249
|
+
export function parseGuidanceProbeManifest(value: unknown): GuidanceProbeManifestV1 | undefined {
|
|
250
|
+
try { return manifest(inert(value, GUIDANCE_PROBE_LIMITS.recordBytes)); } catch { return undefined; }
|
|
251
|
+
}
|
|
252
|
+
export function guidanceProbeManifestKey(value: GuidanceProbeManifestV1): string {
|
|
253
|
+
const parsed = parseGuidanceProbeManifest(value); if (!parsed) return invalid();
|
|
254
|
+
return probeHash(`agent-hub.guidance-probe.v1\n${guidanceProbeCanonical(parsed)}`);
|
|
255
|
+
}
|
|
256
|
+
function policy(value: unknown): ProbeDataPolicyV1 {
|
|
257
|
+
const fields = object(value, ["v", "allowedWrites", "admittedData", "roles"]); required(fields.v === 1 && Array.isArray(fields.allowedWrites) && Array.isArray(fields.admittedData));
|
|
258
|
+
const ids = new Set<string>(), writes = new Set<string>();
|
|
259
|
+
for (const write of fields.allowedWrites as unknown[]) {
|
|
260
|
+
const row = object(write, ["root", "relative"]); required(["scratch", "output"].includes(row.root as string) && identity(row.relative));
|
|
261
|
+
const name = row.relative as string; required(!name.includes("\\") && !name.startsWith("/") && !/^[a-z]:/i.test(name) && name.split("/").every(part => part && part !== "." && part !== ".."));
|
|
262
|
+
const key = `${row.root}/${name}`; required(!writes.has(key)); writes.add(key);
|
|
263
|
+
}
|
|
264
|
+
for (const data of fields.admittedData as unknown[]) { const row = object(data, ["id", "sha256", "bytes"]); required(identity(row.id) && !ids.has(row.id as string) && probeSha256(row.sha256) && probeInteger(row.bytes)); ids.add(row.id as string); }
|
|
265
|
+
const roles = object(fields.roles, ["worker", "proposal", "compose", "select", "reflect"]);
|
|
266
|
+
for (const [name, flag] of [["worker", "guidanceOnlyExperience"], ["proposal", "improverContext"], ["compose", "improverContext"], ["select", "anonymizedDeliverables"], ["reflect", "closedRoundOnly"]] as const) {
|
|
267
|
+
const row = object(roles[name], ["dataIds", flag]); required(Array.isArray(row.dataIds) && typeof row[flag] === "boolean" && (flag === "improverContext" || row[flag] === true));
|
|
268
|
+
const used = new Set<string>(); for (const id of row.dataIds as unknown[]) { required(identity(id) && ids.has(id as string) && !used.has(id as string)); used.add(id as string); }
|
|
269
|
+
}
|
|
270
|
+
return fields as unknown as ProbeDataPolicyV1;
|
|
271
|
+
}
|
|
272
|
+
export function parseGuidanceProbeRegistration(value: unknown): ProbeRegistrationV1 | undefined {
|
|
273
|
+
try {
|
|
274
|
+
// Inspect envelope/snapshot descriptors before any potentially large nested traversal.
|
|
275
|
+
if (!value || typeof value !== "object" || types.isProxy(value) || Array.isArray(value)
|
|
276
|
+
|| ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return undefined;
|
|
277
|
+
const names = Reflect.ownKeys(value);
|
|
278
|
+
if (names.length !== 2 || !names.includes("manifest") || !names.includes("snapshots")) return undefined;
|
|
279
|
+
const envelope = Object.getOwnPropertyDescriptors(value);
|
|
280
|
+
if (Object.values(envelope).some(item => !("value" in item) || !item.enumerable)) return undefined;
|
|
281
|
+
const parsed = parseGuidanceProbeManifest(envelope.manifest?.value); if (!parsed) return undefined;
|
|
282
|
+
const raw = envelope.snapshots?.value;
|
|
283
|
+
if (!raw || typeof raw !== "object" || types.isProxy(raw) || Array.isArray(raw) || ![Object.prototype, null].includes(Object.getPrototypeOf(raw))) return undefined;
|
|
284
|
+
const snapshots: Record<string, unknown> = Object.create(null), keys = Reflect.ownKeys(raw);
|
|
285
|
+
if (keys.length > 5) return undefined;
|
|
286
|
+
for (const key of keys) {
|
|
287
|
+
if (typeof key !== "string" || !["task", "baselineContext", "dataPolicy", "systemPolicy", "improverContext"].includes(key)) return undefined;
|
|
288
|
+
const descriptor = Object.getOwnPropertyDescriptor(raw, key); if (!descriptor || !("value" in descriptor) || !descriptor.enumerable) return undefined;
|
|
289
|
+
if (key === "dataPolicy") snapshots[key] = policy(inert(descriptor.value, GUIDANCE_PROBE_LIMITS.snapshotBytes));
|
|
290
|
+
else { const text = descriptor.value; required(typeof text === "string" && Buffer.byteLength(text) <= GUIDANCE_PROBE_LIMITS.snapshotBytes
|
|
291
|
+
&& !/[\p{Cc}\p{Cs}]/u.test(text.replace(/[\t\r\n]/g, ""))); snapshots[key] = text; }
|
|
292
|
+
}
|
|
293
|
+
object(snapshots, ["task", "baselineContext", "dataPolicy", "systemPolicy"], ["improverContext"]);
|
|
294
|
+
required(Object.hasOwn(snapshots, "improverContext") === Object.hasOwn(parsed, "improverContextHash"));
|
|
295
|
+
let total = 0;
|
|
296
|
+
for (const key of ["task", "baselineContext", "dataPolicy", "systemPolicy", "improverContext"] as const) {
|
|
297
|
+
if (!Object.hasOwn(snapshots, key)) continue;
|
|
298
|
+
const text = key === "dataPolicy" ? guidanceProbeCanonical(snapshots[key]) : snapshots[key] as string;
|
|
299
|
+
const expected = key === "improverContext" ? { sha256: parsed.improverContextHash, bytes: parsed.improverContextBytes } : parsed.inputs[key];
|
|
300
|
+
required(Buffer.byteLength(text) === expected.bytes && probeHash(text) === expected.sha256); total += Buffer.byteLength(text);
|
|
301
|
+
}
|
|
302
|
+
required(total <= parsed.limits.inputBytes);
|
|
303
|
+
const result = { manifest: parsed, snapshots: snapshots as unknown as ProbePrivateSnapshots };
|
|
304
|
+
if (Buffer.byteLength(JSON.stringify(result)) > GUIDANCE_PROBE_REGISTRATION_BYTES) return undefined;
|
|
305
|
+
return result;
|
|
306
|
+
} catch { return undefined; }
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function parseGuidanceProbeCommand(args: readonly string[]): GuidanceProbeCommand | undefined {
|
|
310
|
+
const op = args[0]; if (!["register", "start", "show", "cancel"].includes(op ?? "")) return undefined;
|
|
311
|
+
const fields = new Map<string, string>(), allowed = op === "register" ? ["--file"] : op === "show" ? ["--id"] : op === "start" ? ["--id", "--revision", "--variant"] : ["--id", "--revision"];
|
|
312
|
+
let json = false;
|
|
313
|
+
for (let index = 1; index < args.length; index++) {
|
|
314
|
+
const key = args[index]!; if (key === "--json" && !json) { json = true; continue; }
|
|
315
|
+
const value = args[++index]; if (!allowed.includes(key) || fields.has(key) || !value || value.startsWith("--")) return undefined; fields.set(key, value);
|
|
316
|
+
}
|
|
317
|
+
if (op === "register") return fields.has("--file") ? { op, file: fields.get("--file")!, json } : undefined;
|
|
318
|
+
const id = fields.get("--id"); if (!probeSha256(id)) return undefined;
|
|
319
|
+
if (op === "show") return { op, id, json };
|
|
320
|
+
const raw = fields.get("--revision"), revision = raw && /^(?:0|[1-9][0-9]*)$/.test(raw) ? Number(raw) : NaN;
|
|
321
|
+
if (!probeInteger(revision)) return undefined;
|
|
322
|
+
if (op === "cancel") return { op, id, revision, json };
|
|
323
|
+
const variantId = fields.get("--variant"); if (variantId !== undefined && !probeSha256(variantId)) return undefined;
|
|
324
|
+
return { op: "start", id, revision, ...(variantId === undefined ? {} : { variantId }), json };
|
|
325
|
+
}
|
|
326
|
+
export function parseGuidanceProbeSubcommand(args: readonly string[]): GuidanceProbeCommand | undefined {
|
|
327
|
+
if (args[0] !== "probe") return undefined;
|
|
328
|
+
return parseGuidanceProbeCommand(args.slice(1)) ?? invalid();
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const probeStates: readonly ProbeState[] = ["declared", "active", "closing", "closed_fixture", "failed_fixture", "unknown_held"];
|
|
332
|
+
const publicEvidence = (value: unknown): value is ProbePublicReceipt["evidence"] => ["declaration", "fixture", "unknown"].includes(value as string);
|
|
333
|
+
function publicReceipt(value: unknown, status: boolean): ProbePublicReceipt | ProbePublicStatus | undefined {
|
|
334
|
+
try {
|
|
335
|
+
const extra = status ? ["counters", "cancelRequested", "notNeeded", "comparable", "authoring"] : [];
|
|
336
|
+
const fields = object(value, ["id", "revision", "state", "already", "taskId", "experimentId", "evidence", ...extra]);
|
|
337
|
+
required(probeSha256(fields.id) && probeInteger(fields.revision) && probeStates.includes(fields.state as ProbeState)
|
|
338
|
+
&& typeof fields.already === "boolean" && probeInteger(fields.taskId) && fields.taskId > 0
|
|
339
|
+
&& typeof fields.experimentId === "string" && fields.experimentId.length <= 256 && publicEvidence(fields.evidence));
|
|
340
|
+
if (!status) return fields as unknown as ProbePublicReceipt;
|
|
341
|
+
const counters = object(fields.counters, ["workerAttempts", "editorAttempts", "modelCalls", "toolCalls", "tokensReserved", "tokensObservedKnown",
|
|
342
|
+
"inputBytes", "scratchBytes", "outputBytes", "elapsedHighWaterMs", "usageUnknown"]);
|
|
343
|
+
required(Object.entries(counters).every(([key, item]) => key === "usageUnknown" ? typeof item === "boolean" : probeInteger(item))
|
|
344
|
+
&& typeof fields.cancelRequested === "boolean" && probeInteger(fields.notNeeded) && typeof fields.comparable === "boolean"
|
|
345
|
+
&& ["admitted_fixture", "uncontrolled", "unknown"].includes(fields.authoring as string));
|
|
346
|
+
return fields as unknown as ProbePublicStatus;
|
|
347
|
+
} catch { return undefined; }
|
|
348
|
+
}
|
|
349
|
+
export const parseGuidanceProbePublicReceipt = (value: unknown): ProbePublicReceipt | undefined => publicReceipt(value, false) as ProbePublicReceipt | undefined;
|
|
350
|
+
export const parseGuidanceProbePublicStatus = (value: unknown): ProbePublicStatus | undefined => publicReceipt(value, true) as ProbePublicStatus | undefined;
|
|
351
|
+
|
|
352
|
+
/** Explicit worker-visible bytes; no host identity, arm label or improver side channel. */
|
|
353
|
+
export function guidanceProbeWorkerFrame(task: string, baselineContext: string, systemPolicy: string, guidance: string): string {
|
|
354
|
+
if ([task, baselineContext, systemPolicy].some(text => typeof text !== "string" || Buffer.byteLength(text) > GUIDANCE_PROBE_LIMITS.snapshotBytes)
|
|
355
|
+
|| typeof guidance !== "string") return invalid();
|
|
356
|
+
return JSON.stringify({ task, baselineContext, systemPolicy, guidance });
|
|
357
|
+
}
|
|
358
|
+
export const guidanceProbeNonGuidanceInputHash = (task: string, baselineContext: string, systemPolicy: string): string => probeHash(JSON.stringify({ task, baselineContext, systemPolicy }));
|
package/src/hub/inference.ts
CHANGED
|
@@ -3,8 +3,10 @@ import type { MlxHandle } from "../models/mlx.ts";
|
|
|
3
3
|
import type { ChatMessage, OmniRoute } from "../omniroute/client.ts";
|
|
4
4
|
import { CLASSES, type TaskClass } from "./board.ts";
|
|
5
5
|
import { DIGEST, newEnvelope, type Envelope } from "./envelope.ts";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
6
|
+
import { buildEscalationRequest } from "../models/route/hub-prompts.ts";
|
|
7
|
+
import { captureJudgeConversation } from "../models/route/conversation-view.ts";
|
|
8
|
+
import { parseEscalationReply, type EscalationReply } from "../models/route/judge-replies.ts";
|
|
9
|
+
import type { ProgressConversation } from "./progress.ts";
|
|
8
10
|
|
|
9
11
|
export interface InferenceConfig {
|
|
10
12
|
enabled: boolean;
|
|
@@ -148,8 +150,19 @@ export class Inference {
|
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
/** A closed escalation verdict, or no verdict when inference is unavailable or malformed. */
|
|
151
|
-
async escalate(conversation:
|
|
152
|
-
|
|
153
|
+
async escalate(conversation: ProgressConversation, turn: number): Promise<EscalationReply | undefined> {
|
|
154
|
+
// This grouped shape is produced by ProgressObserver, not accepted from native model JSON.
|
|
155
|
+
const messages: ChatMessage[] = conversation.instructions.map(content => ({ role: "system", content }));
|
|
156
|
+
for (const frame of conversation.messages) {
|
|
157
|
+
messages.push({ role: frame.role, content: frame.content, ...(frame.toolCalls.length ? {
|
|
158
|
+
tool_calls: frame.toolCalls.map(call => ({ id: call.id, type: "function" as const,
|
|
159
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) } })),
|
|
160
|
+
} : {}) });
|
|
161
|
+
for (const result of frame.toolResults) messages.push({ role: "tool", tool_call_id: result.toolCallId,
|
|
162
|
+
content: result.content, ...(result.isError === undefined ? {} : { is_error: result.isError }) });
|
|
163
|
+
}
|
|
164
|
+
const request = buildEscalationRequest(captureJudgeConversation(messages), turn);
|
|
165
|
+
if (!request) return undefined;
|
|
153
166
|
const user = request.messages[0]?.content;
|
|
154
167
|
if (!user) return undefined;
|
|
155
168
|
const answer = await this.complete(
|
|
@@ -162,7 +175,7 @@ export class Inference {
|
|
|
162
175
|
"new_evidence (boolean, true only for fresh distinct observations) and reason (short string). Return escalate false and category none when evidence is insufficient.",
|
|
163
176
|
user, request.maxOutputTokens,
|
|
164
177
|
);
|
|
165
|
-
return answer ?
|
|
178
|
+
return answer ? parseEscalationReply(answer) : undefined;
|
|
166
179
|
}
|
|
167
180
|
}
|
|
168
181
|
|
|
@@ -32,7 +32,7 @@ export type ConductorLocalAction = typeof CONDUCTOR_LOCAL_ACTIONS[number];
|
|
|
32
32
|
export const conductorLocalAction = (value:unknown): value is ConductorLocalAction => typeof value==="string" && (CONDUCTOR_LOCAL_ACTIONS as readonly string[]).includes(value);
|
|
33
33
|
/** Daemon-authorized labels. Recovery labels pass the initial role check, then require their separate per-operation proof. */
|
|
34
34
|
export const CONDUCTOR_DAEMON_OPERATIONS = ["roster add","roster remove","stop","queue show","queue resolve","queue discard","settings set","doctor orphans kill","logs","export",
|
|
35
|
-
"board import","intake approve","schedule run","schedule pause","schedule resume","goal link","task unassign","restart","upgrade","recovery resume","recovery abort"] as const;
|
|
35
|
+
"board import","intake approve","schedule run","schedule pause","schedule resume","goal link","task unassign","guidance probe register","guidance probe start","guidance probe show","guidance probe cancel","restart","upgrade","recovery resume","recovery abort"] as const;
|
|
36
36
|
/**
|
|
37
37
|
* #933: forms whose effect runs in the CLI process itself (local files). The daemon admits and audits them once at the handshake (`admit`),
|
|
38
38
|
* after the CLI has validated their arguments. Recovery-bearing restart/upgrade forms use the separate source-issued continuation proof.
|
|
@@ -91,6 +91,14 @@ export function conductorOperation(command:string,args:readonly string[]): Condu
|
|
|
91
91
|
if (command==="intake" && sub==="approve" && words.length===2) return "intake approve";
|
|
92
92
|
if (command==="schedule" && (sub==="run" || sub==="pause" || sub==="resume")) return `schedule ${sub}`;
|
|
93
93
|
if (command==="goal" && args.find(arg=>arg!=="--json")==="link") return "goal link";
|
|
94
|
+
if (command === "guidance" && args[0] === "probe") {
|
|
95
|
+
switch (args[1]) {
|
|
96
|
+
case "register": return "guidance probe register";
|
|
97
|
+
case "start": return "guidance probe start";
|
|
98
|
+
case "show": return "guidance probe show";
|
|
99
|
+
case "cancel": return "guidance probe cancel";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
94
102
|
return undefined;
|
|
95
103
|
}
|
|
96
104
|
|
|
@@ -119,6 +127,10 @@ export function operationalRequestLabel(value:unknown):string|undefined {
|
|
|
119
127
|
if(message.t==="peer_stop")return "stop";
|
|
120
128
|
if(message.t==="goal_link")return "goal link";
|
|
121
129
|
if(message.t==="task" && typeof message.op==="string" && Object.hasOwn(CONDUCTOR_TASK_OPS,message.op))return CONDUCTOR_TASK_OPS[message.op];
|
|
130
|
+
if (typeof message.t === "string" && message.t.startsWith("guidance_probe_")) {
|
|
131
|
+
const operation = message.t.slice("guidance_probe_".length);
|
|
132
|
+
return ["register", "start", "show", "cancel"].includes(operation) ? `guidance probe ${operation}` : undefined;
|
|
133
|
+
}
|
|
122
134
|
if(message.t==="queue" && typeof message.op==="string" && ["show","resolve","discard"].includes(message.op))return `queue ${message.op}`;
|
|
123
135
|
if(message.t==="settings_set"||message.t==="settings_preview")return "settings set";
|
|
124
136
|
return undefined;
|
package/src/hub/peers.ts
CHANGED
|
@@ -53,6 +53,11 @@ export interface PeerAdapter {
|
|
|
53
53
|
readonly standbySessions?: readonly PeerStandbySession[];
|
|
54
54
|
/** The current owner's attachment facts, for display only; absent unless a socket is attached and no newer claim is arriving (#1310). */
|
|
55
55
|
readonly ownerAttachment?: PeerOwnerAttachment;
|
|
56
|
+
/**
|
|
57
|
+
* #1385: the agent-hub client this peer runs in another process, for display only. Absent means the adapter runs inside the daemon, so it runs the daemon's own code; `attached` false
|
|
58
|
+
* means no client is attached now, and an attached client without `version` did not report one. Never admission, compatibility or authorization evidence.
|
|
59
|
+
*/
|
|
60
|
+
readonly hubClient?: { attached: boolean; version?: string };
|
|
56
61
|
/** Person-authorized takeover port. The host still performs its own admission and claim fences. */
|
|
57
62
|
takeover?(standbyId: string | undefined, eligible: (socket: object) => boolean): PeerTakeoverClaim | undefined;
|
|
58
63
|
/** Exact transport ownership check for guarding a selected standby through its asynchronous preface. */
|
package/src/hub/ports.ts
CHANGED
|
@@ -10,7 +10,7 @@ export const CONTROL = 0;
|
|
|
10
10
|
export const CODEX_APP = 1;
|
|
11
11
|
export const CODEX_PROXY = 2;
|
|
12
12
|
/** Reserved after sidecar retirement (#553); never bind this offset or move later allocations. */
|
|
13
|
-
export const
|
|
13
|
+
export const RESERVED_SIDECAR = 3;
|
|
14
14
|
|
|
15
15
|
/** SQLite-backed project allocation; an explicit JSON path retains the legacy utility API under a lock. */
|
|
16
16
|
export function allocatePorts(projectDir: string, registry?: string): number {
|
package/src/hub/progress.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EscalationControl } from "../models/route/escalation-control.ts";
|
|
2
|
+
import type { EscalationCategory, EscalationReply } from "../models/route/judge-replies.ts";
|
|
2
3
|
import { diagnoseStageResult } from "../models/route/stage-diagnostics.ts";
|
|
3
|
-
import {
|
|
4
|
-
import type { Conversation } from "../models/route/normalize.ts";
|
|
4
|
+
import { repeatedObservationFailure, failureFingerprint as fingerprint, type ToolObservation } from "../models/route/observation-signals.ts";
|
|
5
5
|
import type { HubEvent } from "./events.ts";
|
|
6
6
|
import type { Task } from "./board.ts";
|
|
7
7
|
|
|
@@ -10,7 +10,19 @@ const MAX_STATES = 256;
|
|
|
10
10
|
const MAX_OBSERVATIONS = 28;
|
|
11
11
|
const MAX_TEXT = 500;
|
|
12
12
|
|
|
13
|
-
type NativeToolObservation = ToolObservation & { turn?: string };
|
|
13
|
+
export type NativeToolObservation = ToolObservation & { turn?: string };
|
|
14
|
+
|
|
15
|
+
/** The host-owned progress factory's grouped record, not a provider normalizer schema. */
|
|
16
|
+
export interface ProgressConversation {
|
|
17
|
+
instructions: string[];
|
|
18
|
+
instructionRoles: "system"[];
|
|
19
|
+
messages: {
|
|
20
|
+
role: "user" | "assistant";
|
|
21
|
+
content: string;
|
|
22
|
+
toolCalls: { id: string; name: string; arguments: { command?: string } }[];
|
|
23
|
+
toolResults: { toolCallId: string; content: string; isError?: boolean }[];
|
|
24
|
+
}[];
|
|
25
|
+
}
|
|
14
26
|
|
|
15
27
|
/** Normalize only completed Codex work observations; event payloads and unrelated item text are ignored. */
|
|
16
28
|
export function normalizeCodexObservation(value: unknown): ToolObservation | undefined {
|
|
@@ -40,7 +52,7 @@ interface ProgressState {
|
|
|
40
52
|
task: number;
|
|
41
53
|
at: number;
|
|
42
54
|
observations: NativeToolObservation[];
|
|
43
|
-
escalation:
|
|
55
|
+
escalation: EscalationControl;
|
|
44
56
|
generation: number;
|
|
45
57
|
checking: boolean;
|
|
46
58
|
attemptedTurns: Set<string>;
|
|
@@ -81,7 +93,7 @@ export interface ProgressDeps {
|
|
|
81
93
|
tasks(): Task[];
|
|
82
94
|
/** The same project-wide gate used for turn-free facts: no observation while any PII task is open. */
|
|
83
95
|
isPrivate(): boolean;
|
|
84
|
-
inference: { escalate(conversation:
|
|
96
|
+
inference: { escalate(conversation: ProgressConversation, turn: number): Promise<EscalationReply | undefined> };
|
|
85
97
|
emit(event: HubEvent): void;
|
|
86
98
|
notify(line: string): void;
|
|
87
99
|
now?: () => number;
|
|
@@ -162,8 +174,7 @@ export class ProgressObserver {
|
|
|
162
174
|
|
|
163
175
|
private judgeEligible(state: ProgressState): boolean {
|
|
164
176
|
if (!latestNativeTurn(state.observations) || state.escalation.snapshot().latched) return false;
|
|
165
|
-
const
|
|
166
|
-
const repeatedAcrossTurns = signals.repeatedFailure && repeatedFailureAcrossTurns(state.observations);
|
|
177
|
+
const repeatedAcrossTurns = repeatedObservationFailure(state.observations) === true && repeatedFailureAcrossTurns(state.observations);
|
|
167
178
|
return repeatedAcrossTurns || progressDimensions(state.observations).spinning > 0;
|
|
168
179
|
}
|
|
169
180
|
|
|
@@ -188,7 +199,7 @@ export class ProgressObserver {
|
|
|
188
199
|
let state = this.states.get(id);
|
|
189
200
|
if (!state) {
|
|
190
201
|
if (this.states.size >= MAX_STATES) this.states.delete(this.states.keys().next().value!);
|
|
191
|
-
state = { peer, task, at: this.now(), observations: [], escalation: new
|
|
202
|
+
state = { peer, task, at: this.now(), observations: [], escalation: new EscalationControl(), generation: 0, checking: false, attemptedTurns: new Set(), turn: 0 };
|
|
192
203
|
this.states.set(id, state);
|
|
193
204
|
}
|
|
194
205
|
return state;
|
|
@@ -233,17 +244,13 @@ function repeatedFailureAcrossTurns(observations: readonly NativeToolObservation
|
|
|
233
244
|
return [...turnsByFingerprint.values()].some((turns) => turns.size >= 2);
|
|
234
245
|
}
|
|
235
246
|
|
|
236
|
-
function signalsFor(observations: readonly NativeToolObservation[]): ToolSignals {
|
|
237
|
-
return extractToolSignalsFromObservations(observations, knownTurns(observations).length);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
247
|
function pruneAttemptedTurns(state: ProgressState): void {
|
|
241
248
|
const active = new Set(knownTurns(state.observations));
|
|
242
249
|
for (const turn of state.attemptedTurns) if (!active.has(turn)) state.attemptedTurns.delete(turn);
|
|
243
250
|
}
|
|
244
251
|
|
|
245
|
-
function conversation(observations: readonly NativeToolObservation[], task: Task):
|
|
246
|
-
const frames = new Map<string, { role: "assistant"; content: string; toolCalls: { id: string; name: string; arguments:
|
|
252
|
+
function conversation(observations: readonly NativeToolObservation[], task: Task): ProgressConversation {
|
|
253
|
+
const frames = new Map<string, { role: "assistant"; content: string; toolCalls: { id: string; name: string; arguments: { command?: string } }[]; toolResults: { toolCallId: string; content: string; isError?: boolean }[] }>();
|
|
247
254
|
let nextCall = 0;
|
|
248
255
|
for (const item of observations) {
|
|
249
256
|
const nativeTurn = validTurn(item.turn);
|
|
@@ -264,5 +271,5 @@ function conversation(observations: readonly NativeToolObservation[], task: Task
|
|
|
264
271
|
};
|
|
265
272
|
}
|
|
266
273
|
|
|
267
|
-
export type ProgressVerdict =
|
|
274
|
+
export type ProgressVerdict = EscalationReply;
|
|
268
275
|
export type ProgressCategory = Exclude<EscalationCategory, "none">;
|
package/src/hub/report.ts
CHANGED
|
@@ -114,6 +114,7 @@ export function summarize(events: StampedEvent[]): Report {
|
|
|
114
114
|
const seenSupervision = new Set<string>();
|
|
115
115
|
const lastTier = new Map<string, string>();
|
|
116
116
|
for (const e of events) {
|
|
117
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
117
118
|
r.from ??= e.at;
|
|
118
119
|
r.to = e.at;
|
|
119
120
|
switch (e.type) {
|
|
@@ -304,6 +305,7 @@ export function summarizeByTask(events: StampedEvent[]): TaskReport {
|
|
|
304
305
|
const seenUsage = new Set<string>();
|
|
305
306
|
// Resolve latest class/outcome before rolling usage up: usage may precede the task's history in a slice.
|
|
306
307
|
for (const e of events) {
|
|
308
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
307
309
|
r.from ??= e.at; r.to = e.at;
|
|
308
310
|
if (startsAttribution(e) && reportingSince === null) reportingSince = Date.parse(e.at);
|
|
309
311
|
if (e.type !== "task") continue;
|
package/src/hub/research.ts
CHANGED
|
@@ -157,6 +157,7 @@ export function taskRecords(events: StampedEvent[], projectId: string, writer: T
|
|
|
157
157
|
else delete a.tooling[peer]; // a fingerprint of an earlier attachment does not describe this work: unknown until one comes
|
|
158
158
|
};
|
|
159
159
|
for (const e of events) {
|
|
160
|
+
if (e.type === "route" && e.decisionTarget === "judge") continue;
|
|
160
161
|
// A crash writes no offline: a new run is a new attachment, and no fingerprint from before it describes later work.
|
|
161
162
|
if (e.type === "hub_start") { online.clear(); tooling.clear(); if (startsAttribution(e)) personReportingSince ??= Date.parse(e.at); continue; }
|
|
162
163
|
if (e.type === "state") {
|
package/src/hub/restart.ts
CHANGED
|
@@ -48,6 +48,7 @@ export interface RestartSnapshot {
|
|
|
48
48
|
budgetDigest: string;
|
|
49
49
|
modelOverrides?: { count: number; digest: string };
|
|
50
50
|
guidanceVariants?: { experiments: number; variants: number; digest: string };
|
|
51
|
+
guidanceProbes?: { experiments: number; sessions: number; digest: string };
|
|
51
52
|
executionReferences?: { count: number; digest: string };
|
|
52
53
|
/** Whole captured binding set; portable identities are covered alongside queue/board integrity. */
|
|
53
54
|
externalBindingsDigest?: string;
|
|
@@ -122,6 +123,12 @@ export function readRestartSnapshot(stateDir: string, expected: RestartReadExpec
|
|
|
122
123
|
|| !Number.isSafeInteger(value.experiments) || value.experiments < 0 || !Number.isSafeInteger(value.variants) || value.variants < value.experiments
|
|
123
124
|
|| typeof value.digest !== "string" || value.digest.length !== 64 || !/^[a-f0-9]{64}$/.test(value.digest)) return undefined;
|
|
124
125
|
}
|
|
126
|
+
if (s.integrity && Object.hasOwn(s.integrity, "guidanceProbes")) {
|
|
127
|
+
const value = s.integrity.guidanceProbes;
|
|
128
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "digest,experiments,sessions"
|
|
129
|
+
|| !Number.isSafeInteger(value.experiments) || value.experiments < 0 || !Number.isSafeInteger(value.sessions) || value.sessions < value.experiments
|
|
130
|
+
|| typeof value.digest !== "string" || value.digest.length !== 64 || !/^[a-f0-9]{64}$/.test(value.digest)) return undefined;
|
|
131
|
+
}
|
|
125
132
|
if (s.integrity && Object.hasOwn(s.integrity, "executionReferences")) {
|
|
126
133
|
const value = s.integrity.executionReferences;
|
|
127
134
|
if (!value || typeof value !== "object" || Array.isArray(value) || Object.keys(value).sort().join(",") !== "count,digest"
|