prismalens 0.2.0 → 0.4.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/README.md +29 -13
- package/dist/bin/prismalens.js +39 -50
- package/dist/chunk-2Z7QZSIS.js +20 -0
- package/dist/chunk-5BT3XQOG.js +2990 -0
- package/dist/chunk-6N4PHBII.js +30 -0
- package/dist/chunk-CTKCK7QT.js +387 -0
- package/dist/chunk-CVSS5JPC.js +130 -0
- package/dist/chunk-HPE5CTO4.js +22 -0
- package/dist/chunk-PTBCAI34.js +34 -0
- package/dist/chunk-PVQVFRIV.js +452 -0
- package/dist/chunk-QDK5PAI3.js +155 -0
- package/dist/chunk-SSEIMBQ2.js +204 -0
- package/dist/chunk-TGP6QTFO.js +156 -0
- package/dist/chunk-V6M6ISKI.js +161 -0
- package/dist/chunk-XH6DIKTA.js +83 -0
- package/dist/src/cli/auth.js +112 -101
- package/dist/src/cli/doctor.js +184 -187
- package/dist/src/cli/flags.js +6 -29
- package/dist/src/cli/grouping.js +16 -227
- package/dist/src/cli/init.js +58 -52
- package/dist/src/cli/investigate.js +23 -465
- package/dist/src/cli/listen.js +550 -286
- package/dist/src/cli/report.js +70 -67
- package/dist/src/cli/serve.js +260 -30
- package/dist/src/cli/status.js +87 -86
- package/package.json +16 -7
- package/dist/bin/prismalens.d.ts +0 -3
- package/dist/bin/prismalens.d.ts.map +0 -1
- package/dist/bin/prismalens.js.map +0 -1
- package/dist/src/cli/auth.d.ts +0 -3
- package/dist/src/cli/auth.d.ts.map +0 -1
- package/dist/src/cli/auth.js.map +0 -1
- package/dist/src/cli/doctor.d.ts +0 -18
- package/dist/src/cli/doctor.d.ts.map +0 -1
- package/dist/src/cli/doctor.js.map +0 -1
- package/dist/src/cli/flags.d.ts +0 -2
- package/dist/src/cli/flags.d.ts.map +0 -1
- package/dist/src/cli/flags.js.map +0 -1
- package/dist/src/cli/grouping.d.ts +0 -18
- package/dist/src/cli/grouping.d.ts.map +0 -1
- package/dist/src/cli/grouping.js.map +0 -1
- package/dist/src/cli/init.d.ts +0 -3
- package/dist/src/cli/init.d.ts.map +0 -1
- package/dist/src/cli/init.js.map +0 -1
- package/dist/src/cli/investigate.d.ts +0 -115
- package/dist/src/cli/investigate.d.ts.map +0 -1
- package/dist/src/cli/investigate.js.map +0 -1
- package/dist/src/cli/listen.d.ts +0 -56
- package/dist/src/cli/listen.d.ts.map +0 -1
- package/dist/src/cli/listen.js.map +0 -1
- package/dist/src/cli/report.d.ts +0 -24
- package/dist/src/cli/report.d.ts.map +0 -1
- package/dist/src/cli/report.js.map +0 -1
- package/dist/src/cli/serve.d.ts +0 -3
- package/dist/src/cli/serve.d.ts.map +0 -1
- package/dist/src/cli/serve.js.map +0 -1
- package/dist/src/cli/status.d.ts +0 -19
- package/dist/src/cli/status.d.ts.map +0 -1
- package/dist/src/cli/status.js.map +0 -1
- package/dist/src/config/loader.d.ts +0 -22
- package/dist/src/config/loader.d.ts.map +0 -1
- package/dist/src/config/loader.js +0 -193
- package/dist/src/config/loader.js.map +0 -1
- package/dist/src/config/schema.d.ts +0 -463
- package/dist/src/config/schema.d.ts.map +0 -1
- package/dist/src/config/schema.js +0 -217
- package/dist/src/config/schema.js.map +0 -1
- package/dist/src/core/caps.d.ts +0 -36
- package/dist/src/core/caps.d.ts.map +0 -1
- package/dist/src/core/caps.js +0 -36
- package/dist/src/core/caps.js.map +0 -1
- package/dist/src/core/db.d.ts +0 -3
- package/dist/src/core/db.d.ts.map +0 -1
- package/dist/src/core/db.js +0 -105
- package/dist/src/core/db.js.map +0 -1
- package/dist/src/core/detect-repo.d.ts +0 -4
- package/dist/src/core/detect-repo.d.ts.map +0 -1
- package/dist/src/core/detect-repo.js +0 -28
- package/dist/src/core/detect-repo.js.map +0 -1
- package/dist/src/core/file-session-store.d.ts +0 -10
- package/dist/src/core/file-session-store.d.ts.map +0 -1
- package/dist/src/core/file-session-store.js +0 -34
- package/dist/src/core/file-session-store.js.map +0 -1
- package/dist/src/core/parse-stdin.d.ts +0 -2
- package/dist/src/core/parse-stdin.d.ts.map +0 -1
- package/dist/src/core/parse-stdin.js +0 -21
- package/dist/src/core/parse-stdin.js.map +0 -1
- package/dist/src/core/run-investigation.d.ts +0 -54
- package/dist/src/core/run-investigation.d.ts.map +0 -1
- package/dist/src/core/run-investigation.js +0 -200
- package/dist/src/core/run-investigation.js.map +0 -1
- package/dist/src/core/session.d.ts +0 -63
- package/dist/src/core/session.d.ts.map +0 -1
- package/dist/src/core/session.js +0 -45
- package/dist/src/core/session.js.map +0 -1
- package/dist/src/core/slack-notify.d.ts +0 -9
- package/dist/src/core/slack-notify.d.ts.map +0 -1
- package/dist/src/core/slack-notify.js +0 -57
- package/dist/src/core/slack-notify.js.map +0 -1
- package/dist/src/core/sqlite-session-store.d.ts +0 -39
- package/dist/src/core/sqlite-session-store.d.ts.map +0 -1
- package/dist/src/core/sqlite-session-store.js +0 -239
- package/dist/src/core/sqlite-session-store.js.map +0 -1
- package/dist/src/http/server.d.ts +0 -31
- package/dist/src/http/server.d.ts.map +0 -1
- package/dist/src/http/server.js +0 -164
- package/dist/src/http/server.js.map +0 -1
- package/dist/src/jsonrpc/server.d.ts +0 -15
- package/dist/src/jsonrpc/server.d.ts.map +0 -1
- package/dist/src/jsonrpc/server.js +0 -244
- package/dist/src/jsonrpc/server.js.map +0 -1
- package/dist/src/jsonrpc/types.d.ts +0 -12
- package/dist/src/jsonrpc/types.d.ts.map +0 -1
- package/dist/src/jsonrpc/types.js +0 -4
- package/dist/src/jsonrpc/types.js.map +0 -1
- package/dist/src/version.d.ts +0 -8
- package/dist/src/version.d.ts.map +0 -1
- package/dist/src/version.js +0 -27
- package/dist/src/version.js.map +0 -1
|
@@ -1,466 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
import { join, resolve } from "node:path";
|
|
25
|
-
import { HARNESS_REGISTRY } from "@prismalens/config/harness";
|
|
26
|
-
import { INVESTIGATION_DEFAULTS } from "@prismalens/config/investigation";
|
|
27
|
-
import { conductRun, resolveSandbox, SANDBOX_MODES, } from "@prismalens/engine";
|
|
28
|
-
import { defineCommand } from "citty";
|
|
29
|
-
import consola from "consola";
|
|
30
|
-
import { loadConfig } from "../config/loader.js";
|
|
31
|
-
import { resolveRepoSlug } from "../core/detect-repo.js";
|
|
32
|
-
import { createFileSessionStore } from "../core/file-session-store.js";
|
|
33
|
-
import { parseStdin } from "../core/parse-stdin.js";
|
|
34
|
-
import { resolveInvestigation, } from "../core/run-investigation.js";
|
|
35
|
-
import { createSessionManager } from "../core/session.js";
|
|
36
|
-
import { assertKnownFlags } from "./flags.js";
|
|
37
|
-
export default defineCommand({
|
|
38
|
-
meta: {
|
|
39
|
-
name: "investigate",
|
|
40
|
-
description: "Run a root-cause investigation of a firing alert (two-tier engine, ADR-0008).\n\nExamples:\n $ pl investigate -q 'Why did the database crash?' --max-turns 30",
|
|
41
|
-
},
|
|
42
|
-
args: {
|
|
43
|
-
repo: {
|
|
44
|
-
type: "string",
|
|
45
|
-
description: "Path to the repository the harness investigates (its cwd). Defaults to the current directory.",
|
|
46
|
-
},
|
|
47
|
-
query: {
|
|
48
|
-
type: "string",
|
|
49
|
-
alias: "q",
|
|
50
|
-
description: "Investigate a synthesized alert from this one-line description (alternative to piping a FiringAlert JSON on stdin).",
|
|
51
|
-
},
|
|
52
|
-
config: {
|
|
53
|
-
type: "string",
|
|
54
|
-
description: "Path to a prismalens.config.yaml (skips the upward config search).",
|
|
55
|
-
},
|
|
56
|
-
model: {
|
|
57
|
-
type: "string",
|
|
58
|
-
description: "Override agent.model — a bare model id, e.g. gpt-oss:120b.",
|
|
59
|
-
},
|
|
60
|
-
harness: {
|
|
61
|
-
type: "enum",
|
|
62
|
-
options: ["deepagents", "claude-code", "codex"],
|
|
63
|
-
description: "Tier-2 harness backend. Defaults to agent.default in config.",
|
|
64
|
-
},
|
|
65
|
-
mode: {
|
|
66
|
-
type: "enum",
|
|
67
|
-
options: ["read-only", "supervised", "auto", "dangerous"],
|
|
68
|
-
description: "Permission posture the harness runs under (ADR-0017). Defaults to agent.permissions.mode in config (read-only).",
|
|
69
|
-
},
|
|
70
|
-
dangerouslySkipPermissions: {
|
|
71
|
-
type: "boolean",
|
|
72
|
-
default: false,
|
|
73
|
-
description: "Alias for --mode dangerous.",
|
|
74
|
-
},
|
|
75
|
-
sandbox: {
|
|
76
|
-
type: "enum",
|
|
77
|
-
options: [...SANDBOX_MODES],
|
|
78
|
-
description: "Isolation boundary the harness runs in (ADR-0020): process (cooperative floor), srt (enforced), or auto. Defaults to agent.sandbox in config (auto — srt when its egress bridge is healthy, else the process floor).",
|
|
79
|
-
},
|
|
80
|
-
service: {
|
|
81
|
-
type: "string",
|
|
82
|
-
description: "Select the service context by name from `services` in config (overrides the alert's service label).",
|
|
83
|
-
},
|
|
84
|
-
json: {
|
|
85
|
-
type: "boolean",
|
|
86
|
-
default: false,
|
|
87
|
-
description: "Print the InvestigationReport as JSON to stdout (suppresses the human renderer).",
|
|
88
|
-
},
|
|
89
|
-
output: {
|
|
90
|
-
type: "string",
|
|
91
|
-
description: "Write the InvestigationReport JSON to this file.",
|
|
92
|
-
},
|
|
93
|
-
quiet: {
|
|
94
|
-
type: "boolean",
|
|
95
|
-
default: false,
|
|
96
|
-
description: "Suppress progress + the human renderer (errors still go to stderr).",
|
|
97
|
-
},
|
|
98
|
-
"max-turns": {
|
|
99
|
-
type: "string",
|
|
100
|
-
description: "Per-run turn ceiling for the default harness.",
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
async run({ args, cmd }) {
|
|
104
|
-
try {
|
|
105
|
-
assertKnownFlags(args, cmd);
|
|
106
|
-
const json = Boolean(args.json);
|
|
107
|
-
// In --json mode stdout must be machine-clean, so suppress all info-level
|
|
108
|
-
// chatter (consola routes info/log/success to stdout, warn/error to stderr).
|
|
109
|
-
// The AI SDK's stdout warning banner is disabled bin-wide (bin/prismalens.ts).
|
|
110
|
-
const quiet = Boolean(args.quiet) || json;
|
|
111
|
-
const info = (msg) => {
|
|
112
|
-
if (!quiet)
|
|
113
|
-
consola.info(msg);
|
|
114
|
-
};
|
|
115
|
-
const success = (msg) => {
|
|
116
|
-
if (!quiet)
|
|
117
|
-
consola.success(msg);
|
|
118
|
-
};
|
|
119
|
-
// One-line live timeline entries (no consola icon, so the stream reads cleanly).
|
|
120
|
-
const line = (msg) => {
|
|
121
|
-
if (!quiet)
|
|
122
|
-
consola.log(msg);
|
|
123
|
-
};
|
|
124
|
-
// (1) Resolve the seed alert + config + harness + reduce model. The seed is a
|
|
125
|
-
// piped FiringAlert JSON (the stdin channel) or, failing that, --query.
|
|
126
|
-
const piped = await parseStdin();
|
|
127
|
-
// cwd = --repo (a local repo path) else the current directory.
|
|
128
|
-
const cwd = args.repo ? resolve(args.repo) : process.cwd();
|
|
129
|
-
// Load + merge config (global → project → CLI overrides); --model overrides agent.model.
|
|
130
|
-
const config = await loadConfig({
|
|
131
|
-
...(args.config ? { configPath: args.config } : {}),
|
|
132
|
-
cwd,
|
|
133
|
-
cliOverrides: { ...(args.model ? { model: args.model } : {}) },
|
|
134
|
-
});
|
|
135
|
-
const maxTurns = args["max-turns"]
|
|
136
|
-
? Number(args["max-turns"])
|
|
137
|
-
: config.agent.max_turns;
|
|
138
|
-
// Session label: config `repo` (owner/name) wins; else git auto-detect; else none.
|
|
139
|
-
const repoSlug = await resolveRepoSlug(config.repo, cwd);
|
|
140
|
-
// The single posture dial (ADR-0017): --dangerously-skip-permissions wins over
|
|
141
|
-
// --mode, aliasing straight to "dangerous".
|
|
142
|
-
const permissionMode = args.dangerouslySkipPermissions
|
|
143
|
-
? "dangerous"
|
|
144
|
-
: args.mode;
|
|
145
|
-
// Resolve the isolation boundary (ADR-0020): --sandbox wins over agent.sandbox.
|
|
146
|
-
// Only ACP-transport harnesses are spawned as a child the engine can place
|
|
147
|
-
// inside a boundary (the Agent SDK harness runs in-process). Fail fast ONLY when
|
|
148
|
-
// the mode DEMANDS an enforced boundary (`srt`/`e2b`) a non-ACP harness cannot
|
|
149
|
-
// honour (ADR-0017 — never claim an enforcement that would not apply). `auto` and
|
|
150
|
-
// `process` with a non-ACP harness run WITHOUT a sandbox silently: `auto` means
|
|
151
|
-
// best-effort, and the best available for an in-process harness is none — nothing
|
|
152
|
-
// is claimed, so nothing is dishonest. The sandbox is CALLER-OWNED — destroyed in
|
|
153
|
-
// the finally.
|
|
154
|
-
const harnessName = args.harness ?? config.agent.default;
|
|
155
|
-
const sandboxMode = args.sandbox ?? config.agent.sandbox;
|
|
156
|
-
let selection = null;
|
|
157
|
-
try {
|
|
158
|
-
const resolvedSandbox = await resolveRunSandbox(harnessName, sandboxMode, config);
|
|
159
|
-
selection = resolvedSandbox.selection;
|
|
160
|
-
// Honest fidelity (ADR-0017): a silent degrade would mislead — name it, with
|
|
161
|
-
// the self-check's reason (srt absent, or its egress bridge dead — B.1.1).
|
|
162
|
-
// An EXPECTED degrade (WSL: known-unreliable bridge, probe skipped) logs
|
|
163
|
-
// calmly instead of warning on every dev-machine run.
|
|
164
|
-
if (selection && resolvedSandbox.degradeReason) {
|
|
165
|
-
if (resolvedSandbox.degradeExpected) {
|
|
166
|
-
info(`Sandbox: ${selection.actual} (${resolvedSandbox.degradeReason}).`);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
consola.warn(`Sandbox 'auto' degraded to the ${selection.actual} (cooperative, not an OS boundary): ${resolvedSandbox.degradeReason}.`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else if (selection?.actual === "srt") {
|
|
173
|
-
info("Sandbox: srt (enforced OS boundary).");
|
|
174
|
-
}
|
|
175
|
-
const resolved = resolveInvestigation({
|
|
176
|
-
...(piped ? { alert: piped } : {}),
|
|
177
|
-
...(args.query ? { query: args.query } : {}),
|
|
178
|
-
...(args.repo ? { repo: args.repo } : {}),
|
|
179
|
-
...(args.harness ? { harness: args.harness } : {}),
|
|
180
|
-
...(args.service ? { service: args.service } : {}),
|
|
181
|
-
...(permissionMode ? { permissionMode } : {}),
|
|
182
|
-
...(selection
|
|
183
|
-
? {
|
|
184
|
-
sandbox: selection.sandbox,
|
|
185
|
-
requestedSandbox: selection.requested,
|
|
186
|
-
}
|
|
187
|
-
: {}),
|
|
188
|
-
...(maxTurns ? { maxTurns } : {}),
|
|
189
|
-
}, config);
|
|
190
|
-
const { context, harness, synth, fidelity, maxBranches } = resolved;
|
|
191
|
-
const primaryAlert = context.alerts[0];
|
|
192
|
-
if (!synth.configured) {
|
|
193
|
-
info("No Tier-1 provider configured (checked env + _FILE for: ANTHROPIC_API_KEY, OPENAI_API_KEY, GOOGLE_API_KEY, GROQ_API_KEY, OLLAMA_API_KEY) — reports will be RAW harness pass-through (un-synthesized). This is supported.");
|
|
194
|
-
}
|
|
195
|
-
// (2) Create the run workspace + session under workspace.base_dir, wrapped as
|
|
196
|
-
// a conductRun store adapter (ADR-0018).
|
|
197
|
-
const runId = randomUUID();
|
|
198
|
-
const sessions = createSessionManager(config.workspace.base_dir);
|
|
199
|
-
const fileSession = createFileSessionStore(sessions, {
|
|
200
|
-
runId,
|
|
201
|
-
alertname: primaryAlert.alertname,
|
|
202
|
-
agent: harnessName,
|
|
203
|
-
...(repoSlug ? { repo: repoSlug } : {}),
|
|
204
|
-
});
|
|
205
|
-
info(`Investigating "${primaryAlert.alertname}" with ${harnessName} in ${cwd} (run ${runId})`);
|
|
206
|
-
// (3) Drive the supervisor LIVE via the shared conductor: print a one-line
|
|
207
|
-
// timeline entry per event; conductRun owns persistence + the terminal
|
|
208
|
-
// report/no-evidence/error outcome.
|
|
209
|
-
const outcome = await conductRun({
|
|
210
|
-
context,
|
|
211
|
-
harness,
|
|
212
|
-
synth,
|
|
213
|
-
fidelity,
|
|
214
|
-
runId,
|
|
215
|
-
...(maxBranches !== undefined ? { maxBranches } : {}),
|
|
216
|
-
}, {
|
|
217
|
-
sink: (event) => {
|
|
218
|
-
const entry = liveTimelineEntry(event);
|
|
219
|
-
if (entry)
|
|
220
|
-
line(entry);
|
|
221
|
-
},
|
|
222
|
-
store: fileSession.store,
|
|
223
|
-
});
|
|
224
|
-
if (!outcome.report) {
|
|
225
|
-
consola.error(outcome.error);
|
|
226
|
-
process.exitCode = 1;
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const report = outcome.report;
|
|
230
|
-
// (4) Output. --output writes report JSON to a file; --json prints it to
|
|
231
|
-
// stdout; otherwise render the ordered-evidence report for humans.
|
|
232
|
-
if (args.output) {
|
|
233
|
-
const outPath = resolve(args.output);
|
|
234
|
-
await writeFile(outPath, `${JSON.stringify(report, null, 2)}\n`, "utf-8");
|
|
235
|
-
success(`Report written to ${outPath}`);
|
|
236
|
-
}
|
|
237
|
-
if (json) {
|
|
238
|
-
process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
241
|
-
if (!quiet) {
|
|
242
|
-
renderReport(report);
|
|
243
|
-
success(`Report saved to ${join(fileSession.workspacePath(), "report.json")}`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
finally {
|
|
247
|
-
// The command owns the resolved boundary's lifecycle (ADR-0020) — tear it
|
|
248
|
-
// down whichever way the run exited (report, no-evidence, error, or throw).
|
|
249
|
-
if (selection)
|
|
250
|
-
await selection.sandbox.destroy();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
catch (err) {
|
|
254
|
-
consola.error(err instanceof Error ? err.message : String(err));
|
|
255
|
-
process.exit(1);
|
|
256
|
-
}
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
/**
|
|
260
|
-
* The egress allowlist for an enforced sandbox (ADR-0020: allowlist, not closed) — the
|
|
261
|
-
* hostnames of every surface the harness will ACTUALLY contact: its own LLM endpoint
|
|
262
|
-
* (BYO-key baseURL, env override included) PLUS the read-only telemetry + log surfaces.
|
|
263
|
-
* The LLM + telemetry hosts carry the SAME `INVESTIGATION_DEFAULTS` fallback the request
|
|
264
|
-
* assembly applies (`run-investigation`), because an unset config field still resolves to
|
|
265
|
-
* a default the harness queries — omitting it hard-denied the model call and default
|
|
266
|
-
* telemetry, so every branch failed with no report. Mirrors the worker's
|
|
267
|
-
* `deriveWorkerAllowedHosts`. Non-URL values are skipped (no egress hole from a malformed
|
|
268
|
-
* endpoint); the `process` floor ignores this.
|
|
269
|
-
*/
|
|
270
|
-
export function collectAllowedDomains(config) {
|
|
271
|
-
// The LLM endpoint the harness itself calls (BYO-key, ADR-0006): env override wins,
|
|
272
|
-
// else the shared synth default — the SAME resolution as `run-investigation`.
|
|
273
|
-
const llmBaseUrl = process.env.OLLAMA_BASE_URL ??
|
|
274
|
-
process.env.OPENAI_BASE_URL ??
|
|
275
|
-
INVESTIGATION_DEFAULTS.synth.baseURL;
|
|
276
|
-
const urls = [
|
|
277
|
-
llmBaseUrl,
|
|
278
|
-
config.telemetry.prometheusUrl ??
|
|
279
|
-
INVESTIGATION_DEFAULTS.telemetry.prometheusUrl,
|
|
280
|
-
config.telemetry.alertmanagerUrl ??
|
|
281
|
-
INVESTIGATION_DEFAULTS.telemetry.alertmanagerUrl,
|
|
282
|
-
config.telemetry.apiUrl ?? INVESTIGATION_DEFAULTS.telemetry.apiUrl,
|
|
283
|
-
config.logs.url,
|
|
284
|
-
];
|
|
285
|
-
const hosts = new Set();
|
|
286
|
-
for (const url of urls) {
|
|
287
|
-
if (!url)
|
|
288
|
-
continue;
|
|
289
|
-
try {
|
|
290
|
-
hosts.add(new URL(url).hostname);
|
|
291
|
-
}
|
|
292
|
-
catch {
|
|
293
|
-
// not a parseable URL — skip; no egress hole from a malformed endpoint
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return [...hosts];
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Resolve the isolation boundary for a run (ADR-0020/0017) — the single sandbox-resolution
|
|
300
|
-
* path shared by the `investigate` command and the JSON-RPC `serve` handler, so both honour
|
|
301
|
-
* `agent.sandbox` (and `--sandbox`) with identical semantics. Guards first: a mode that
|
|
302
|
-
* DEMANDS enforcement (`srt`/`e2b`) on a non-ACP (in-process) harness THROWS — the caller
|
|
303
|
-
* maps it to its own channel (CLI stderr+exit, or a JSON-RPC error), never a silent floor.
|
|
304
|
-
* Then resolves a boundary ONLY for an ACP harness; an in-process harness returns a null
|
|
305
|
-
* selection (it runs on the cooperative floor, claiming nothing — nothing dishonest). The
|
|
306
|
-
* returned `selection` is CALLER-OWNED — destroy it after the run. `degradeReason` is the
|
|
307
|
-
* honest note when `auto` fell short of srt (present only on a degrade).
|
|
308
|
-
*/
|
|
309
|
-
export async function resolveRunSandbox(harness, mode, config) {
|
|
310
|
-
const guard = resolveSandboxGuard(harness, mode);
|
|
311
|
-
if (guard.blocked) {
|
|
312
|
-
throw new Error(`Harness "${harness}" cannot run inside an enforced sandbox (${mode}) yet ` +
|
|
313
|
-
`— it is not spawned as a child process. Use the auto or process sandbox ` +
|
|
314
|
-
`mode (no enforced boundary), or an ACP harness (deepagents).`);
|
|
315
|
-
}
|
|
316
|
-
if (!guard.takesSandbox)
|
|
317
|
-
return { selection: null, degradeReason: null, degradeExpected: false };
|
|
318
|
-
const probeUrl = firstProbeUrl(config);
|
|
319
|
-
const selection = await resolveSandbox(mode, {
|
|
320
|
-
allowedDomains: collectAllowedDomains(config),
|
|
321
|
-
...(probeUrl ? { probeUrl } : {}),
|
|
322
|
-
});
|
|
323
|
-
const degradeReason = mode === "auto" && selection.actual !== "srt"
|
|
324
|
-
? (selection.degradeReason ?? "srt unavailable")
|
|
325
|
-
: null;
|
|
326
|
-
return {
|
|
327
|
-
selection,
|
|
328
|
-
degradeReason,
|
|
329
|
-
degradeExpected: selection.degradeExpected ?? false,
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* The egress SELF-CHECK target (ADR-0020 B.1.1): the FIRST configured, parseable FULL URL
|
|
334
|
-
* among the telemetry + log surfaces — handed to `auto` as `probeUrl` so its throwaway srt
|
|
335
|
-
* boundary curls a REAL endpoint (not a fabricated `https://<host>/`). Kept as a full URL
|
|
336
|
-
* on purpose (path/port matter for the probe); `undefined` when nothing is configured, in
|
|
337
|
-
* which case `auto` floors rather than standing up a zero-egress boundary (FIX 6).
|
|
338
|
-
*/
|
|
339
|
-
function firstProbeUrl(config) {
|
|
340
|
-
const urls = [
|
|
341
|
-
config.telemetry.prometheusUrl,
|
|
342
|
-
config.telemetry.alertmanagerUrl,
|
|
343
|
-
config.telemetry.apiUrl,
|
|
344
|
-
config.logs.url,
|
|
345
|
-
];
|
|
346
|
-
for (const url of urls) {
|
|
347
|
-
if (!url)
|
|
348
|
-
continue;
|
|
349
|
-
try {
|
|
350
|
-
return new URL(url).href;
|
|
351
|
-
}
|
|
352
|
-
catch {
|
|
353
|
-
// not a parseable URL — skip; a malformed endpoint is no probe target
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
return undefined;
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* The sandbox guard (ADR-0020/0017), mirrored in the worker's `harnessTakesSandbox`: only
|
|
360
|
-
* ACP-transport harnesses are spawned as a child the engine can place inside a boundary.
|
|
361
|
-
* Returns whether this harness `takesSandbox` and whether the request is `blocked` — the
|
|
362
|
-
* fail-fast case where a mode that DEMANDS an enforced boundary (`srt`/`e2b`) was asked of a
|
|
363
|
-
* non-ACP harness. `auto`/`process` are never blocked: they run WITHOUT a sandbox on an
|
|
364
|
-
* in-process harness, claiming nothing, so nothing is dishonest.
|
|
365
|
-
*/
|
|
366
|
-
export function resolveSandboxGuard(harness, mode) {
|
|
367
|
-
const takesSandbox = HARNESS_REGISTRY[harness]?.transport === "acp";
|
|
368
|
-
const demandsEnforcedBoundary = mode === "srt" || mode === "e2b";
|
|
369
|
-
return { takesSandbox, blocked: !takesSandbox && demandsEnforcedBoundary };
|
|
370
|
-
}
|
|
371
|
-
// ---------------------------------------------------------------------------
|
|
372
|
-
// Live timeline (one line per streamed canonical event)
|
|
373
|
-
// ---------------------------------------------------------------------------
|
|
374
|
-
/**
|
|
375
|
-
* Render one live-timeline line for a streamed canonical event, or null when the
|
|
376
|
-
* event carries nothing worth a line (an agent_step with neither text nor calls).
|
|
377
|
-
* The terminal `report` event is captured by the caller, not lined here.
|
|
378
|
-
* Exported for the `listen` path, which prints the same timeline per webhook run.
|
|
379
|
-
*/
|
|
380
|
-
export function liveTimelineEntry(event) {
|
|
381
|
-
switch (event.kind) {
|
|
382
|
-
case "agent_step": {
|
|
383
|
-
const firstLine = event.text.trim().split("\n", 1)[0]?.trim() ?? "";
|
|
384
|
-
const n = event.toolCalls.length;
|
|
385
|
-
if (!firstLine && n === 0)
|
|
386
|
-
return null;
|
|
387
|
-
const calls = n > 0 ? ` + ${n} tool call${n === 1 ? "" : "s"}` : "";
|
|
388
|
-
return `• ${firstLine}${calls}`;
|
|
389
|
-
}
|
|
390
|
-
case "tool_result":
|
|
391
|
-
return ` ${event.result.ok ? "ok" : "ERR"} ${event.result.source}`;
|
|
392
|
-
case "branch_done":
|
|
393
|
-
return ` [branch ${event.reason}]`;
|
|
394
|
-
case "error":
|
|
395
|
-
return ` [error] ${event.message}`;
|
|
396
|
-
default:
|
|
397
|
-
return null;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
// ---------------------------------------------------------------------------
|
|
401
|
-
// Terminal renderer (ordered-evidence report, ADR-0002)
|
|
402
|
-
// ---------------------------------------------------------------------------
|
|
403
|
-
const HYPOTHESIS_MARK = {
|
|
404
|
-
confirmed: "[confirmed]",
|
|
405
|
-
supported: "[supported]",
|
|
406
|
-
speculative: "[speculative]",
|
|
407
|
-
refuted: "[refuted]",
|
|
1
|
+
import {
|
|
2
|
+
collectAllowedDomains,
|
|
3
|
+
investigate_default,
|
|
4
|
+
liveTimelineEntry,
|
|
5
|
+
resolveRunSandbox,
|
|
6
|
+
resolveSandboxGuard
|
|
7
|
+
} from "../../chunk-PVQVFRIV.js";
|
|
8
|
+
import "../../chunk-V6M6ISKI.js";
|
|
9
|
+
import "../../chunk-CTKCK7QT.js";
|
|
10
|
+
import "../../chunk-QDK5PAI3.js";
|
|
11
|
+
import "../../chunk-CVSS5JPC.js";
|
|
12
|
+
import "../../chunk-TGP6QTFO.js";
|
|
13
|
+
import "../../chunk-PTBCAI34.js";
|
|
14
|
+
import "../../chunk-5BT3XQOG.js";
|
|
15
|
+
import "../../chunk-6N4PHBII.js";
|
|
16
|
+
import "../../chunk-XH6DIKTA.js";
|
|
17
|
+
import "../../chunk-2Z7QZSIS.js";
|
|
18
|
+
export {
|
|
19
|
+
collectAllowedDomains,
|
|
20
|
+
investigate_default as default,
|
|
21
|
+
liveTimelineEntry,
|
|
22
|
+
resolveRunSandbox,
|
|
23
|
+
resolveSandboxGuard
|
|
408
24
|
};
|
|
409
|
-
function renderReport(report) {
|
|
410
|
-
consola.log("");
|
|
411
|
-
consola.log("=== Investigation Report ===");
|
|
412
|
-
consola.log(report.summary);
|
|
413
|
-
consola.log("");
|
|
414
|
-
if (report.rootCause) {
|
|
415
|
-
const cat = report.rootCauseCategory
|
|
416
|
-
? ` [${report.rootCauseCategory}]`
|
|
417
|
-
: "";
|
|
418
|
-
consola.log(`Root cause${cat}:`);
|
|
419
|
-
consola.log(` ${report.rootCause}`);
|
|
420
|
-
}
|
|
421
|
-
else {
|
|
422
|
-
consola.log("Root cause: not determined");
|
|
423
|
-
}
|
|
424
|
-
if (report.hypotheses.length > 0) {
|
|
425
|
-
consola.log("");
|
|
426
|
-
consola.log("Hypotheses (most -> least plausible):");
|
|
427
|
-
report.hypotheses.forEach((h, i) => {
|
|
428
|
-
renderHypothesis(h, i + 1);
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
if (report.ruledOut.length > 0) {
|
|
432
|
-
consola.log("");
|
|
433
|
-
consola.log("Ruled out:");
|
|
434
|
-
for (const r of report.ruledOut)
|
|
435
|
-
renderRuledOut(r);
|
|
436
|
-
}
|
|
437
|
-
const { queried, notQueried } = report.coverage;
|
|
438
|
-
if (queried.length > 0 || notQueried.length > 0) {
|
|
439
|
-
consola.log("");
|
|
440
|
-
consola.log(`Coverage: ${queried.length} source(s) queried, ${notQueried.length} not queried.`);
|
|
441
|
-
}
|
|
442
|
-
if (report.nextSteps.length > 0) {
|
|
443
|
-
consola.log("");
|
|
444
|
-
consola.log("Next steps:");
|
|
445
|
-
for (const s of report.nextSteps)
|
|
446
|
-
renderNextStep(s);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
function renderHypothesis(h, n) {
|
|
450
|
-
consola.log(` ${n}. ${HYPOTHESIS_MARK[h.status]} ${h.statement}`);
|
|
451
|
-
for (const e of h.evidence) {
|
|
452
|
-
const sign = e.direction === "supports" ? "+" : "-";
|
|
453
|
-
consola.log(` ${sign} (${e.status}) ${e.observation} [${e.source}]`);
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
function renderRuledOut(r) {
|
|
457
|
-
consola.log(` x ${r.statement} — ${r.why}`);
|
|
458
|
-
for (const e of r.evidence) {
|
|
459
|
-
consola.log(` - (${e.status}) ${e.observation} [${e.source}]`);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
function renderNextStep(s) {
|
|
463
|
-
const prio = s.priority ? `[${s.priority}] ` : "";
|
|
464
|
-
consola.log(` * ${prio}${s.title}: ${s.detail}`);
|
|
465
|
-
}
|
|
466
|
-
//# sourceMappingURL=investigate.js.map
|