@staix/agent-hub 0.36.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +6 -2
- package/THIRD_PARTY_NOTICES.md +0 -18
- package/docs/agent-notes/README.md +13 -3
- package/docs/agent-notes/daemon.md +4 -4
- package/docs/agent-notes/local-worker.md +1 -0
- package/docs/agent-notes/models.md +2 -1
- package/docs/agent-notes/tasks.md +1 -1
- package/docs/agent-notes/tests.md +1 -2
- package/docs/contracts/companion-cli-v1.json +70 -0
- package/docs/design/adapters.md +43 -2
- package/docs/design/agent-hub-architecture.md +9 -1
- package/docs/design/guidance-probes.md +1167 -0
- package/docs/design/model-routes.md +437 -12
- package/docs/dogfood.md +12 -13
- package/docs/events.md +20 -1
- package/docs/memory.md +3 -3
- package/docs/operations.md +123 -151
- package/docs/profiles.md +1 -1
- package/docs/quickstart.md +15 -3
- package/docs/research.md +1 -1
- package/docs/sdlc.md +5 -3
- package/docs/security.md +25 -1
- package/docs/specs/2026-09-19-agent-hub-design.md +9 -7
- package/docs/specs/2026-10-04-switchyard-source-port-design.md +3 -1
- package/docs/verification/2026-11-08-qwen-0269-model-setter-1317.md +25 -11
- package/docs/verification/2026-11-09-qwen-0270-model-setter-1317.md +21 -6
- package/docs/verification/2026-11-11-0.37.0.md +40 -0
- package/docs/verification/2026-11-11-0.38.0.md +41 -0
- package/docs/verification/2026-11-11-guidance-probe-t2-1226.md +153 -0
- package/docs/verification/2026-11-11-guidance-probe-t3-1226.md +85 -0
- package/docs/verification/2026-11-11-guidance-probe-t4-1226.md +65 -0
- package/docs/verification/2026-11-11-qwen-setter-suggestions-off.md +167 -0
- package/docs/verified.json +25 -25
- package/package.json +3 -4
- package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
- package/plugins/agent-hub/kimi-hook.js +2403 -1444
- package/plugins/agent-hub/server.js +2480 -1509
- package/src/adapters/channel-peer.ts +7 -1
- package/src/adapters/claude-channel.ts +2 -1
- package/src/adapters/compat.ts +1 -1
- package/src/adapters/local-probe.ts +233 -0
- package/src/adapters/local-worker.ts +232 -21
- package/src/cli/console-state.ts +25 -6
- package/src/cli/console-versions.ts +99 -0
- package/src/cli/console.ts +13 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/init.ts +3 -1
- package/src/cli/install-paths.ts +7 -2
- package/src/cli/main.ts +78 -7
- package/src/cli/output.ts +8 -4
- package/src/cli/runtime-version-warning.ts +2 -2
- package/src/cli/sdlc-output.ts +9 -5
- package/src/cli/upgrade-runtime.ts +1 -1
- package/src/hub/bus.ts +2 -2
- package/src/hub/config-apply.ts +4 -2
- package/src/hub/config-trust.ts +6 -1
- package/src/hub/control-client.ts +5 -2
- package/src/hub/daemon.ts +195 -13
- package/src/hub/envelope.ts +6 -1
- package/src/hub/events.ts +3 -2
- package/src/hub/guidance-probe-store.ts +1044 -0
- package/src/hub/guidance-probes.ts +692 -0
- package/src/hub/inference.ts +18 -5
- package/src/hub/manager.ts +24 -1
- package/src/hub/operational-authority.ts +14 -1
- package/src/hub/peers.ts +5 -0
- package/src/hub/person-command.ts +25 -0
- package/src/hub/ports.ts +1 -1
- package/src/hub/progress.ts +23 -16
- package/src/hub/report.ts +2 -0
- package/src/hub/research.ts +1 -0
- package/src/hub/restart.ts +7 -0
- package/src/hub/sdlc-release-authorization.ts +139 -17
- package/src/hub/sdlc-release-policy.ts +100 -0
- package/src/hub/sdlc-release.ts +59 -7
- package/src/hub/supervision.ts +3 -2
- package/src/hub/tasks.ts +363 -7
- package/src/local/probe-errors.ts +28 -0
- package/src/local/probe-sandbox.ts +224 -0
- package/src/local/probe-types.ts +110 -0
- package/src/local/probe-workspace.ts +426 -0
- package/src/local/sandbox.ts +71 -2
- package/src/local/tools.ts +135 -9
- package/src/models/route/advisor-trigger.ts +88 -0
- package/src/models/route/config.ts +21 -17
- package/src/models/route/conversation-view.ts +179 -0
- package/src/models/route/decision-evidence.ts +1 -1
- package/src/models/route/decision.ts +114 -19
- package/src/models/route/escalation-control.ts +30 -0
- package/src/models/route/hub-prompts.ts +97 -0
- package/src/models/route/judge-choice.ts +155 -0
- package/src/models/route/judge-replies.ts +102 -0
- package/src/models/route/labels.ts +14 -70
- package/src/models/route/observation-signals.ts +250 -0
- package/src/models/route/plan-execute-choice.ts +27 -0
- package/src/models/route/relay-selector.ts +2 -2
- package/src/models/route/runtime.ts +115 -52
- package/src/models/route/turn-state.ts +77 -0
- package/src/omniroute/client.ts +3 -0
- package/src/ui/guidance-panel.ts +34 -2
- package/src/ui/guidance-view.ts +33 -0
- package/src/ui/plugin.ts +80 -23
- package/src/version.ts +4 -0
- package/templates/AGENTS.block.md +14 -14
- package/templates/adec/README.md +32 -0
- package/templates/adec/ahub.plan-execute.json +23 -0
- package/templates/adec/ahub.stage.json +23 -0
- package/templates/profiles/general.json +1 -1
- package/templates/profiles/research.json +1 -1
- package/templates/profiles/writing.json +1 -1
- package/LICENSES/Apache-2.0.txt +0 -204
- package/src/models/route/advisor.ts +0 -102
- package/src/models/route/escalation.ts +0 -82
- package/src/models/route/judge.ts +0 -23
- package/src/models/route/normalize.ts +0 -103
- package/src/models/route/plan-execute.ts +0 -52
- package/src/models/route/prompts.ts +0 -8
- package/src/models/route/signals.ts +0 -247
- package/src/models/route/state.ts +0 -54
- package/src/models/route/text.ts +0 -61
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { closeSync, constants, fstatSync, linkSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, rmdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { realPath } from "../hub/project.ts";
|
|
5
|
+
import { sbplString } from "./deny.ts";
|
|
6
|
+
import { profile, sandboxAvailable, sandboxedExec } from "./sandbox.ts";
|
|
7
|
+
import { ProbeToolRefusal } from "./probe-errors.ts";
|
|
8
|
+
import { probeWorkspaceCurrent, probeWorkspacePhysical, probeWorkspacePrivateRoot, probeWorkspaceTemporaryRoot, reserveProbeWorkspaceStorage, type ProbeWorkspace } from "./probe-workspace.ts";
|
|
9
|
+
|
|
10
|
+
export interface ProbeConfinement {
|
|
11
|
+
readonly workspace: ProbeWorkspace;
|
|
12
|
+
readonly profile: string;
|
|
13
|
+
readonly env: Readonly<Record<string, string>>;
|
|
14
|
+
stop(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** An uncertain command retains this owned stop handle; callers must join it before workspace cleanup. */
|
|
17
|
+
export class ProbeConfinementError extends ProbeToolRefusal {
|
|
18
|
+
constructor(readonly stop: () => Promise<void> = async () => {},
|
|
19
|
+
/** Private proof-only diagnostic, never copied into a public probe receipt or ordinary observer. */
|
|
20
|
+
readonly diagnostic?: { stage: "control" | "lane" | "cleanup"; code: number | null; output: string }) {
|
|
21
|
+
super("confinement_unavailable");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
interface ProofState { workspace: ProbeWorkspace; profile: string; digest: string; current(): void; stop(): Promise<void> }
|
|
25
|
+
interface OwnedProofPath { file: string; dev: number; ino: number; directory: boolean; optional?: boolean; removed?: boolean }
|
|
26
|
+
const proofs = new WeakMap<ProbeConfinement, ProofState>();
|
|
27
|
+
let proofOwner: { workspace: ProbeWorkspace; stop(): Promise<void> } | undefined;
|
|
28
|
+
const digest = (value: string): string => createHash("sha256").update(value).digest("hex");
|
|
29
|
+
const q = sbplString;
|
|
30
|
+
const literal = (value: string) => `(literal ${q(value)})`;
|
|
31
|
+
const subpath = (value: string) => `(subpath ${q(value)})`;
|
|
32
|
+
const outside = (filters: readonly string[]): string => `(require-all ${filters.map(filter => `(require-not ${filter})`).join(" ")})`;
|
|
33
|
+
const PROOF_TIMEOUT_MS = 5000;
|
|
34
|
+
const PROOF_TOKEN = "probe-boundary-canary";
|
|
35
|
+
// /bin/bash: on macOS /bin/sh is a stub that re-execs /bin/bash as its variant (/private/var/select/sh), so the proof's own `sh -c` cannot start without it.
|
|
36
|
+
// Only this model-free proof runs these programs: probe dispatch refuses bash and git before any command (test "probe dispatch refuses all invented non-file calls"),
|
|
37
|
+
// so the grant widens the profile, not what a probe tool can do.
|
|
38
|
+
const COMMANDS = ["/bin/sh", "/bin/cat", "/bin/ln", "/bin/mv", "/usr/bin/nc", "/bin/bash"] as const;
|
|
39
|
+
const SH_VARIANT_SELECTOR = "/private/var/select/sh";
|
|
40
|
+
|
|
41
|
+
function restrictedProfile(workspace: ProbeWorkspace, controlPort?: number): string {
|
|
42
|
+
probeWorkspaceCurrent(workspace);
|
|
43
|
+
const programs = [...new Set(COMMANDS.flatMap(file => [file, realPath(file)]))];
|
|
44
|
+
// Never grant all of /System: its Volumes/Data aliases can lead back to operator files.
|
|
45
|
+
const systemData = ["/System/Library", "/usr/lib", "/private/var/db/dyld",
|
|
46
|
+
"/System/Volumes/Preboot/Cryptexes/OS/System/Library", "/System/Volumes/Preboot/Cryptexes/OS/usr/lib"];
|
|
47
|
+
// literal("/") is the root directory node only, not its children: dyld reads that node's data at every process start, and without it every program
|
|
48
|
+
// (nc, sh, cat) aborts with SIGABRT before it runs (bisected with plain sandbox-exec on macOS 27.0.1). No other grant rides on it.
|
|
49
|
+
const data = [literal("/"), subpath(workspace.root), ...systemData.map(subpath),
|
|
50
|
+
...programs.map(literal), literal(SH_VARIANT_SELECTOR), literal("/dev/null"), literal("/dev/random"), literal("/dev/urandom")];
|
|
51
|
+
// Traversal metadata is permitted only for ancestors of an actual runtime or owned role root.
|
|
52
|
+
const ancestors = new Set<string>(["/"]);
|
|
53
|
+
for (const root of [workspace.root, ...programs, SH_VARIANT_SELECTOR, ...systemData]) {
|
|
54
|
+
for (let parent = dirname(root); ; parent = dirname(parent)) { ancestors.add(parent); if (parent === "/") break; }
|
|
55
|
+
}
|
|
56
|
+
return [profile(workspace.root, controlPort === undefined ? false : { proxyPort: controlPort }),
|
|
57
|
+
`(deny file-read-data ${outside(data)})`,
|
|
58
|
+
`(deny file-read-metadata ${outside([...data, ...[...ancestors].map(literal)])})`,
|
|
59
|
+
`(deny file-write* ${outside([literal("/dev/null"), ...workspace.allowedWrites.map(subpath)])})`,
|
|
60
|
+
`(deny process-exec ${outside(programs.map(literal))})`,
|
|
61
|
+
...(controlPort === undefined ? ["(deny network*)"] : []),
|
|
62
|
+
].join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Consume only an in-memory proof minted for these exact owned paths and this current role. */
|
|
66
|
+
export function requireProbeConfinement(proof: ProbeConfinement, workspace: ProbeWorkspace): void {
|
|
67
|
+
const state = proofs.get(proof);
|
|
68
|
+
if (!state || state.workspace !== workspace || proof.workspace !== workspace || proof.profile !== state.profile
|
|
69
|
+
|| digest(JSON.stringify(proof.env)) !== state.digest) throw new ProbeConfinementError();
|
|
70
|
+
state.current();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Model-free proof under the same lane profile. Unsupported or failed native proof is never a fixture pass. */
|
|
74
|
+
export async function verifyProbeConfinement(workspace: ProbeWorkspace, signal?: AbortSignal): Promise<ProbeConfinement> {
|
|
75
|
+
if (!sandboxAvailable() || proofOwner || signal?.aborted) throw new ProbeConfinementError();
|
|
76
|
+
probeWorkspaceCurrent(workspace);
|
|
77
|
+
const pending = new Set<() => Promise<void>>();
|
|
78
|
+
let active: Promise<unknown> | undefined;
|
|
79
|
+
let closed = false;
|
|
80
|
+
let cleaned = false;
|
|
81
|
+
const owned = new Map<string, OwnedProofPath>();
|
|
82
|
+
const remember = (file: string, directory: boolean): OwnedProofPath => {
|
|
83
|
+
const stat = lstatSync(file);
|
|
84
|
+
if (stat.isSymbolicLink() || (directory ? !stat.isDirectory() : !stat.isFile())) throw new Error("probe setup resource ownership unavailable");
|
|
85
|
+
const identity = { file, dev: stat.dev, ino: stat.ino, directory }; owned.set(file, identity); return identity;
|
|
86
|
+
};
|
|
87
|
+
const requireOwned = (identity: OwnedProofPath): boolean => {
|
|
88
|
+
const stat = lstatSync(identity.file, { throwIfNoEntry: false });
|
|
89
|
+
if (!stat && identity.optional) return false;
|
|
90
|
+
if (!stat || stat.isSymbolicLink() || (identity.directory ? !stat.isDirectory() : !stat.isFile()) || stat.dev !== identity.dev || stat.ino !== identity.ino) {
|
|
91
|
+
throw new Error("probe setup resource ownership changed; retained for inspection");
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
};
|
|
95
|
+
const cleanup = () => {
|
|
96
|
+
// Cleanup needs physical ownership, never the withdrawn actor/privacy execution authority.
|
|
97
|
+
probeWorkspacePhysical(workspace);
|
|
98
|
+
if (cleaned) return;
|
|
99
|
+
for (const identity of owned.values()) if (!identity.removed) requireOwned(identity);
|
|
100
|
+
for (const identity of owned.values()) if (!identity.directory && !identity.removed) {
|
|
101
|
+
probeWorkspacePhysical(workspace); if (requireOwned(identity)) rmSync(identity.file); identity.removed = true;
|
|
102
|
+
}
|
|
103
|
+
for (const identity of [...owned.values()].filter(entry => entry.directory).sort((a, b) => b.file.length - a.file.length)) if (!identity.removed) {
|
|
104
|
+
probeWorkspacePhysical(workspace); requireOwned(identity); rmdirSync(identity.file); identity.removed = true;
|
|
105
|
+
}
|
|
106
|
+
cleaned = true;
|
|
107
|
+
};
|
|
108
|
+
const stop = async () => {
|
|
109
|
+
closed = true;
|
|
110
|
+
if (active) await active;
|
|
111
|
+
for (const close of [...pending]) { await close(); pending.delete(close); }
|
|
112
|
+
cleanup();
|
|
113
|
+
if (proofOwner?.workspace === workspace) proofOwner = undefined;
|
|
114
|
+
};
|
|
115
|
+
proofOwner = { workspace, stop };
|
|
116
|
+
let server: ReturnType<typeof Bun.serve> | undefined;
|
|
117
|
+
let retained = false;
|
|
118
|
+
try {
|
|
119
|
+
const laneProfile = restrictedProfile(workspace);
|
|
120
|
+
const env = Object.freeze({ PATH: "/usr/bin:/bin:/usr/sbin:/sbin", HOME: workspace.home, LANG: "C", TERM: "dumb" });
|
|
121
|
+
const privateRoot = probeWorkspacePrivateRoot(workspace), temporaryRoot = probeWorkspaceTemporaryRoot(workspace);
|
|
122
|
+
const roots = new Set([privateRoot, workspace.root, workspace.home, workspace.scratch, workspace.output]);
|
|
123
|
+
const directory = (file: string): void => {
|
|
124
|
+
probeWorkspacePhysical(workspace);
|
|
125
|
+
const identity = owned.get(file);
|
|
126
|
+
if (identity) { requireOwned(identity); return; }
|
|
127
|
+
if (roots.has(file)) return;
|
|
128
|
+
if (lstatSync(file, { throwIfNoEntry: false })) throw new ProbeConfinementError(stop);
|
|
129
|
+
directory(dirname(file)); mkdirSync(file, { mode: 0o700 }); remember(file, true);
|
|
130
|
+
};
|
|
131
|
+
const write = (file: string) => {
|
|
132
|
+
directory(dirname(file));
|
|
133
|
+
const fd = openSync(file, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
|
|
134
|
+
try {
|
|
135
|
+
const stat = fstatSync(fd); owned.set(file, { file, dev: stat.dev, ino: stat.ino, directory: false });
|
|
136
|
+
writeFileSync(fd, PROOF_TOKEN);
|
|
137
|
+
} finally { closeSync(fd); }
|
|
138
|
+
};
|
|
139
|
+
const labels = ["evaluator", "future-task", "other-arm", "control-receipt", ".git/objects/canary", "operator-file", "parent", "sibling"];
|
|
140
|
+
const retainedBytes = Buffer.byteLength(PROOF_TOKEN) * (labels.length + 4);
|
|
141
|
+
await reserveProbeWorkspaceStorage(workspace, retainedBytes);
|
|
142
|
+
probeWorkspaceCurrent(workspace);
|
|
143
|
+
if (signal?.aborted) throw new ProbeConfinementError(stop);
|
|
144
|
+
const privateProof = realPath(mkdtempSync(join(privateRoot, "boundary-"))), positiveRoot = realPath(mkdtempSync(join(workspace.root, ".boundary-")));
|
|
145
|
+
remember(privateProof, true); remember(positiveRoot, true);
|
|
146
|
+
const readable = join(positiveRoot, "readable"), homeCanary = join(workspace.home, "credential-canary");
|
|
147
|
+
write(readable); write(homeCanary);
|
|
148
|
+
const readableIdentity = owned.get(readable)!;
|
|
149
|
+
const hostLink = join(privateProof, "host-link-control"); linkSync(readable, hostLink);
|
|
150
|
+
const hostIdentity = remember(hostLink, false); requireOwned(hostIdentity); rmSync(hostLink); hostIdentity.removed = true;
|
|
151
|
+
const negatives = labels.map(label => join(privateProof!, label));
|
|
152
|
+
for (const file of negatives) write(file);
|
|
153
|
+
negatives.push(homeCanary);
|
|
154
|
+
const writableRoot = workspace.allowedWrites[0];
|
|
155
|
+
let writeControl: string | undefined, aliasControl: string | undefined;
|
|
156
|
+
if (writableRoot) {
|
|
157
|
+
directory(writableRoot);
|
|
158
|
+
writeControl = join(writableRoot, ".probe-write-control"); write(writeControl);
|
|
159
|
+
aliasControl = join(writableRoot, ".probe-alias-control");
|
|
160
|
+
owned.set(aliasControl, { ...readableIdentity, file: aliasControl, optional: true });
|
|
161
|
+
}
|
|
162
|
+
let networkRequests = 0;
|
|
163
|
+
server = Bun.serve({ hostname: "127.0.0.1", port: 0, fetch: request => {
|
|
164
|
+
if (request.headers.has("origin")) return new Response("Origin refused", { status: 403 });
|
|
165
|
+
networkRequests++; return new Response(PROOF_TOKEN);
|
|
166
|
+
} });
|
|
167
|
+
const positive = await fetch(`http://127.0.0.1:${server.port}/`, { signal: AbortSignal.timeout(PROOF_TIMEOUT_MS) });
|
|
168
|
+
if (await positive.text() !== PROOF_TOKEN || networkRequests !== 1) throw new ProbeConfinementError(stop);
|
|
169
|
+
if (signal?.aborted) throw new ProbeConfinementError(stop);
|
|
170
|
+
networkRequests = 0;
|
|
171
|
+
const run = async (argv: string[], commandProfile: string) => {
|
|
172
|
+
probeWorkspaceCurrent(workspace);
|
|
173
|
+
const command = sandboxedExec(argv, {
|
|
174
|
+
cwd: workspace.root, profile: commandProfile, env: { ...env }, timeoutMs: PROOF_TIMEOUT_MS, ...(signal ? { signal } : {}),
|
|
175
|
+
probe: { workspaceRoot: workspace.root, temporaryRoot, home: workspace.home, current: () => probeWorkspaceCurrent(workspace), physical: () => probeWorkspacePhysical(workspace) },
|
|
176
|
+
});
|
|
177
|
+
active = command;
|
|
178
|
+
const result = await command; active = undefined;
|
|
179
|
+
if (!result.quiescent) { if (result.stop) pending.add(result.stop); retained = true;
|
|
180
|
+
throw new ProbeConfinementError(stop, { stage: "cleanup", code: result.code, output: result.output.slice(0, 1024) }); }
|
|
181
|
+
probeWorkspaceCurrent(workspace);
|
|
182
|
+
return result;
|
|
183
|
+
};
|
|
184
|
+
// Same utility and runtime constraints, with a single owned-loopback grant only for this positive control.
|
|
185
|
+
const control = await run(["/usr/bin/nc", "-n", "-z", "-G", "1", "-w", "1", "127.0.0.1", String(server.port)], restrictedProfile(workspace, server.port));
|
|
186
|
+
if (control.code !== 0 || signal?.aborted) throw new ProbeConfinementError(stop, { stage: "control", code: control.code, output: control.output.slice(0, 1024) });
|
|
187
|
+
const script = [
|
|
188
|
+
'set -eu',
|
|
189
|
+
'[ "$(/bin/cat "$1")" = "probe-boundary-canary" ] || exit 11',
|
|
190
|
+
'if [ "$2" = /dev/null ]; then printf x > /dev/null; else printf probe-boundary-canary > "$2"; fi',
|
|
191
|
+
'[ -z "${OMNIROUTE_API_KEY-}${AWS_ACCESS_KEY_ID-}${AGENTHUB_CONTROL_TOKEN-}${HTTPS_PROXY-}${CODEX_THREAD_ID-}${AGENTHUB_PEER_ID-}" ] || exit 12',
|
|
192
|
+
'readable="$1"; writable="$2"',
|
|
193
|
+
'printf "PERMITTED\\n"',
|
|
194
|
+
'port="$3"; alias="$4"; shift 4',
|
|
195
|
+
'for file do if /bin/cat "$file" >/dev/null 2>&1; then exit 14; fi; if (printf bad > "$file") 2>/dev/null; then exit 15; fi; done',
|
|
196
|
+
'first="$1"; if /bin/ln "$first" "$first.link" >/dev/null 2>&1; then exit 17; fi',
|
|
197
|
+
'if /bin/ln -s "$first" "$first.alias" >/dev/null 2>&1; then exit 18; fi',
|
|
198
|
+
'if /bin/mv "$first" "$first.moved" >/dev/null 2>&1; then exit 19; fi',
|
|
199
|
+
'if [ "$alias" != /dev/null ]; then if /bin/ln "$readable" "$alias" >/dev/null 2>&1; then if (printf bad > "$alias") 2>/dev/null; then exit 20; fi; fi; fi',
|
|
200
|
+
'if /usr/bin/nc -n -z -G 1 -w 1 127.0.0.1 "$port" >/dev/null 2>&1; then exit 16; fi',
|
|
201
|
+
'printf "DENIED\\n"',
|
|
202
|
+
].join("\n");
|
|
203
|
+
probeWorkspaceCurrent(workspace);
|
|
204
|
+
const result = await run(["/bin/sh", "-c", script, "proof", readable, writeControl ?? "/dev/null", String(server.port), aliasControl ?? "/dev/null", ...negatives], laneProfile);
|
|
205
|
+
probeWorkspaceCurrent(workspace);
|
|
206
|
+
if (result.code !== 0 || result.output.trim() !== "PERMITTED\nDENIED" || networkRequests !== 0 || signal?.aborted)
|
|
207
|
+
throw new ProbeConfinementError(stop, { stage: "lane", code: result.code, output: result.output.slice(0, 1024) });
|
|
208
|
+
if (negatives.some(file => readFileSync(file, "utf8") !== PROOF_TOKEN)) throw new ProbeConfinementError(stop);
|
|
209
|
+
if (readFileSync(readable, "utf8") !== PROOF_TOKEN) throw new ProbeConfinementError(stop);
|
|
210
|
+
if (writeControl && readFileSync(writeControl, "utf8") !== PROOF_TOKEN) throw new ProbeConfinementError(stop);
|
|
211
|
+
const proof: ProbeConfinement = Object.freeze({ workspace, profile: laneProfile, env, stop });
|
|
212
|
+
proofs.set(proof, { workspace, profile: laneProfile, digest: digest(JSON.stringify(env)), current: () => { if (closed) throw new ProbeConfinementError(stop); probeWorkspaceCurrent(workspace); }, stop });
|
|
213
|
+
return proof;
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error instanceof ProbeConfinementError) throw error;
|
|
216
|
+
throw new ProbeConfinementError(stop);
|
|
217
|
+
} finally {
|
|
218
|
+
if (server) await server.stop(true);
|
|
219
|
+
if (!retained) {
|
|
220
|
+
try { cleanup(); if (proofOwner?.workspace === workspace) proofOwner = undefined; }
|
|
221
|
+
catch { throw new ProbeConfinementError(stop); }
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { ChatMessage, ChatResult, OmniRoute } from "../omniroute/client.ts";
|
|
2
|
+
import type { ProbeFakeEffects, ProbeResourceCharges, ProbeSlot, ProbeStoredState, ProbeWorkerFramePreparer } from "../hub/guidance-probes.ts";
|
|
3
|
+
import type { ProbeConfinement } from "./probe-sandbox.ts";
|
|
4
|
+
import type { ProbeMaterializedFile, ProbeWorkspace, ProbeWorkspaceInput } from "./probe-workspace.ts";
|
|
5
|
+
import type { ToolContext } from "./tools.ts";
|
|
6
|
+
import { guidanceProbeCanonical, probeHash } from "../hub/guidance-probes.ts";
|
|
7
|
+
|
|
8
|
+
export class ProbeLocalError extends Error {
|
|
9
|
+
constructor(readonly reason: "invalid" | "drift" | "model" | "usage" | "interrupted") {
|
|
10
|
+
super({ invalid: "guidance probe input or capability is invalid; ask the host to rebuild the admitted input before retrying",
|
|
11
|
+
drift: "guidance probe input or runtime changed; retain this session and preregister matching inputs before retrying",
|
|
12
|
+
model: "guidance probe served-model identity is changed or unverified; inspect model provenance and admit a matching session without fallback",
|
|
13
|
+
usage: "guidance probe model usage is missing or unknown; retain unknown cost and inspect provider accounting before retrying",
|
|
14
|
+
interrupted: "guidance probe authority or owned work stopped; join the owned stop and inspect retained state before retrying" }[reason]);
|
|
15
|
+
this.name = "ProbeLocalError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ProbeLocalModelConfig {
|
|
20
|
+
maxSteps: number;
|
|
21
|
+
maxOutputTokens: number;
|
|
22
|
+
/** Trusted frozen upper bound for the entire call, not an output-token cap. */
|
|
23
|
+
tokenUpperBound?: number;
|
|
24
|
+
}
|
|
25
|
+
export interface ProbeLocalRequest {
|
|
26
|
+
model: string;
|
|
27
|
+
messages: ChatMessage[];
|
|
28
|
+
tools: unknown[];
|
|
29
|
+
max_tokens: number;
|
|
30
|
+
stream: false;
|
|
31
|
+
}
|
|
32
|
+
export interface ProbePreparedLocalInput {
|
|
33
|
+
inputFrame: string;
|
|
34
|
+
inputSha256: string;
|
|
35
|
+
nonGuidanceInputSha256: string;
|
|
36
|
+
request: ProbeLocalRequest;
|
|
37
|
+
role: ProbeSlot["role"];
|
|
38
|
+
files: readonly { dataId: string; relative: string; sha256: string; bytes: number }[];
|
|
39
|
+
}
|
|
40
|
+
export interface ProbeLocalEffectScope {
|
|
41
|
+
effects: ProbeFakeEffects;
|
|
42
|
+
next(): number;
|
|
43
|
+
current(): void;
|
|
44
|
+
}
|
|
45
|
+
export interface ProbeLocalSession {
|
|
46
|
+
purpose: "guidance_probe";
|
|
47
|
+
prepared: ProbePreparedLocalInput;
|
|
48
|
+
workspace: ProbeWorkspace;
|
|
49
|
+
confinement: ProbeConfinement;
|
|
50
|
+
config: Readonly<ProbeLocalModelConfig>;
|
|
51
|
+
accounting: ProbeLocalEffectScope;
|
|
52
|
+
reserve(charges: ProbeResourceCharges, descriptor: string): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface ProbeLocalResult {
|
|
55
|
+
answer: string;
|
|
56
|
+
complete: boolean;
|
|
57
|
+
servedModel: string | null;
|
|
58
|
+
servedModelExact: boolean;
|
|
59
|
+
usageKnown: boolean;
|
|
60
|
+
/** Known pre-effect refusal metadata, not a fabricated model answer or token-usage observation. */
|
|
61
|
+
refusal?: "token_ceiling";
|
|
62
|
+
reason?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ProbeLocalSource {
|
|
65
|
+
files: readonly ProbeMaterializedFile[];
|
|
66
|
+
sourceTree?: ProbeWorkspaceInput["sourceTree"];
|
|
67
|
+
verifySource: ProbeWorkspaceInput["verifySource"];
|
|
68
|
+
}
|
|
69
|
+
export interface ProbeLocalFixturePorts {
|
|
70
|
+
evidence: "fixture_only";
|
|
71
|
+
materialize(input: ProbeWorkspaceInput): Promise<ProbeWorkspace>;
|
|
72
|
+
confine(workspace: ProbeWorkspace): Promise<ProbeConfinement>;
|
|
73
|
+
}
|
|
74
|
+
export interface ProbeLocalAdapterOptions {
|
|
75
|
+
omni: OmniRoute;
|
|
76
|
+
config: Readonly<ProbeLocalModelConfig>;
|
|
77
|
+
permit: ToolContext["permit"];
|
|
78
|
+
resolveInput(state: ProbeStoredState, slot: ProbeSlot): ProbeLocalSource | Promise<ProbeLocalSource>;
|
|
79
|
+
current(): void;
|
|
80
|
+
/** Private minted-resource ownership notification, never an ordinary observer or authority source. */
|
|
81
|
+
workspaceOwned?: (workspace: ProbeWorkspace) => void;
|
|
82
|
+
/** Host-owned directory (outside every workspace) where a session's declared output is retained. Without it nothing is retained, only hashed. */
|
|
83
|
+
retentionRoot?: string;
|
|
84
|
+
fixture?: ProbeLocalFixturePorts;
|
|
85
|
+
}
|
|
86
|
+
export interface ProbeLocalAdapter {
|
|
87
|
+
prepareWorkerFrame: ProbeWorkerFramePreparer;
|
|
88
|
+
prepareEditorFrame(state: ProbeStoredState, slot: ProbeSlot): Promise<string>;
|
|
89
|
+
ports: import("../hub/guidance-probes.ts").GuidanceProbeFakePorts;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export const probeObservedTokens = (result: ChatResult): number | null => {
|
|
93
|
+
const total = result.usage?.totalTokens;
|
|
94
|
+
return typeof total === "number" && Number.isSafeInteger(total) && total >= 0 ? total : null;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export async function probeLocalEffect<T>(scope: ProbeLocalEffectScope, unit: "model_calls" | "tool_calls" | "resources", descriptor: string,
|
|
98
|
+
charges: ProbeResourceCharges | undefined, reservedTokens: number | undefined,
|
|
99
|
+
effect: (signal: AbortSignal) => Promise<{ value: T; usage: number | null }>): Promise<T> {
|
|
100
|
+
scope.current();
|
|
101
|
+
const request = { sequence: scope.next(), unit, descriptorSha256: probeHash(descriptor),
|
|
102
|
+
...(charges ? { charges } : {}), ...(reservedTokens === undefined ? {} : { reservedTokens }) };
|
|
103
|
+
const result = await scope.effects.runEffect(request, async signal => {
|
|
104
|
+
scope.current();
|
|
105
|
+
const observed = await effect(signal);
|
|
106
|
+
return { ...observed, observationSha256: probeHash(guidanceProbeCanonical({ request, usage: observed.usage })) };
|
|
107
|
+
});
|
|
108
|
+
if (result.kind !== "executed") throw new ProbeLocalError("interrupted");
|
|
109
|
+
return result.value;
|
|
110
|
+
}
|