@bli-cockpit/cli 0.2.58 → 0.2.59

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.
Files changed (39) hide show
  1. package/dist/commands/browser-open.js +88 -0
  2. package/dist/commands/docs.js +27 -6
  3. package/dist/commands/doctor-report.js +17 -1
  4. package/dist/commands/doctor.js +12 -2
  5. package/dist/commands/heartbeat.js +65 -1
  6. package/dist/commands/jarvis-answer-envelope.js +80 -0
  7. package/dist/commands/jarvis-turn.js +16 -1
  8. package/dist/commands/jarvis.js +3 -0
  9. package/dist/commands/local-args-collector-setup.js +17 -0
  10. package/dist/commands/local-args-tower-admin.js +12 -2
  11. package/dist/commands/local-args-tower-docs-msg.js +95 -6
  12. package/dist/commands/local-args-tower-search.js +50 -0
  13. package/dist/commands/local-args-tower.js +4 -1
  14. package/dist/commands/local-args.js +24 -13
  15. package/dist/commands/local-command-shapes.js +12 -0
  16. package/dist/commands/local-help-commands.js +643 -0
  17. package/dist/commands/local-help.js +8 -581
  18. package/dist/commands/local.js +3 -0
  19. package/dist/commands/login.js +91 -8
  20. package/dist/commands/memory-install-claude.js +35 -15
  21. package/dist/commands/memory-install-codex-hooks.js +200 -0
  22. package/dist/commands/memory-install-codex.js +12 -2
  23. package/dist/commands/memory-install-receipt.js +222 -0
  24. package/dist/commands/memory-install-report.js +25 -1
  25. package/dist/commands/memory-install.js +76 -2
  26. package/dist/commands/msg.js +85 -2
  27. package/dist/commands/onboard-completion.js +47 -0
  28. package/dist/commands/onboard-setup.js +82 -2
  29. package/dist/commands/ops-render-memory.js +76 -0
  30. package/dist/commands/ops-render.js +1 -0
  31. package/dist/commands/ops.js +56 -1
  32. package/dist/commands/public-root.js +1 -1
  33. package/dist/commands/search.js +122 -0
  34. package/dist/commands/setup-receipt-lines.js +71 -0
  35. package/dist/commands/setup-receipt.js +241 -0
  36. package/dist/commands/status.js +20 -1
  37. package/dist/local-state-pairing-code.js +200 -0
  38. package/dist/local-state.js +6 -0
  39. package/package.json +4 -4
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Opening a URL in the person's own browser (BLI-3731).
3
+ *
4
+ * One sign-in means the terminal hands the browser a link. That is the whole
5
+ * job here, and it follows the same discipline `commands/editor.ts` wrote down
6
+ * for spawning a program on somebody's behalf:
7
+ *
8
+ * 1. **`spawnSync` with an ARRAY of arguments and `shell: false`.** Nothing is
9
+ * interpolated into a command line, ever.
10
+ * 2. **Windows does NOT go through `cmd /c start`.** `start` is a cmd builtin,
11
+ * so reaching it means handing cmd.exe a string it re-parses — and `&` in a
12
+ * query string is a command separator there. `rundll32 url.dll,
13
+ * FileProtocolHandler <url>` takes the URL as one argv and never sees a
14
+ * shell. (Our own URL has no `&` today; the point is that it cannot ever
15
+ * matter.)
16
+ * 3. **The URL is validated before it is spawned.** Only `https:` and a
17
+ * loopback `http:` are opened, so a bad dashboard URL cannot turn into a
18
+ * `file:` or a custom protocol handler.
19
+ *
20
+ * Opening is BEST EFFORT and never fatal: the caller has already printed the
21
+ * link, so a machine with no browser — an SSH session, a locked-down Windows
22
+ * host — loses nothing but a convenience. Every branch returns a reason label,
23
+ * success included, and the caller logs it.
24
+ */
25
+ import { spawnSync } from "node:child_process";
26
+ /** `https:` anywhere, `http:` only on loopback — a dev dashboard is the reason. */
27
+ export function isOpenableUrl(url) {
28
+ let parsed;
29
+ try {
30
+ parsed = new URL(url);
31
+ }
32
+ catch {
33
+ return false;
34
+ }
35
+ if (parsed.protocol === "https:")
36
+ return true;
37
+ return (parsed.protocol === "http:" &&
38
+ (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1"));
39
+ }
40
+ export function openInBrowser(url, options = {}) {
41
+ if (!isOpenableUrl(url)) {
42
+ return {
43
+ ok: false,
44
+ reason: "url_not_openable",
45
+ detail: "Only https:// (or http:// on localhost) links are opened.",
46
+ };
47
+ }
48
+ const platform = options.platform ?? process.platform;
49
+ const spawnImpl = options.spawn ?? spawnSync;
50
+ const opener = openerFor(platform, url);
51
+ if (!opener) {
52
+ return {
53
+ ok: false,
54
+ reason: "no_opener_for_platform",
55
+ detail: `No known browser opener for ${platform}; open the link by hand.`,
56
+ };
57
+ }
58
+ const result = spawnImpl(opener.program, opener.args, {
59
+ stdio: "ignore",
60
+ shell: false,
61
+ });
62
+ if (result.error) {
63
+ return {
64
+ ok: false,
65
+ reason: "opener_not_started",
66
+ detail: `${opener.program} could not be started; open the link by hand.`,
67
+ };
68
+ }
69
+ if (typeof result.status === "number" && result.status !== 0) {
70
+ return {
71
+ ok: false,
72
+ reason: "opener_exited_nonzero",
73
+ detail: `${opener.program} exited ${result.status}; open the link by hand.`,
74
+ };
75
+ }
76
+ return { ok: true, reason: "launched", program: opener.program };
77
+ }
78
+ function openerFor(platform, url) {
79
+ if (platform === "darwin")
80
+ return { program: "open", args: [url] };
81
+ if (platform === "win32") {
82
+ // See rule 2 in the header: never `cmd /c start`.
83
+ return { program: "rundll32.exe", args: ["url.dll,FileProtocolHandler", url] };
84
+ }
85
+ if (platform === "linux")
86
+ return { program: "xdg-open", args: [url] };
87
+ return null;
88
+ }
@@ -14,6 +14,14 @@
14
14
  * /api/docs/documents` already returns — the same read `docs list` prints,
15
15
  * never a second query the server does not already answer.
16
16
  *
17
+ * THE LIST IS METADATA (BLI-3737). It carries id, slug, title, visibility,
18
+ * parent, author, updated_at and `body_chars` — never a body. On 2026-09-05
19
+ * `cockpit docs list --json` answered 603,779 bytes for 155 documents,
20
+ * because the door's select still carried `body_markdown`; an agent had to
21
+ * spend the whole library to learn 155 titles. `--parent`, `--query` and
22
+ * `--limit` ride to the door as query parameters, so the narrowing happens in
23
+ * the database rather than here.
24
+ *
17
25
  * A refusal keeps the door's own `reason` label verbatim (`agent-door.ts`):
18
26
  * `needs_rls_client`, `document_not_found_or_unreadable`,
19
27
  * `document_not_writable`, `title_too_long`, `content_too_long`,
@@ -30,7 +38,7 @@ export async function runDocs(command, io) {
30
38
  const door = await openAgentDoor("docs", command, io);
31
39
  switch (command.action) {
32
40
  case "list":
33
- return listDocs(door);
41
+ return listDocs(command, door);
34
42
  case "tree":
35
43
  return treeDocs(door);
36
44
  case "read":
@@ -41,9 +49,21 @@ export async function runDocs(command, io) {
41
49
  return updateDoc(command, door);
42
50
  }
43
51
  }
44
- async function listDocs(door) {
52
+ /** `--parent`, `--query`, `--limit` as the door's own query parameters (BLI-3737). */
53
+ export function docsListPath(command) {
54
+ const params = new URLSearchParams();
55
+ if (command.parentId)
56
+ params.set("parent_id", command.parentId);
57
+ if (command.query)
58
+ params.set("query", command.query);
59
+ if (command.limit !== undefined)
60
+ params.set("limit", String(command.limit));
61
+ const search = params.toString();
62
+ return search.length > 0 ? `/api/docs/documents?${search}` : "/api/docs/documents";
63
+ }
64
+ async function listDocs(command, door) {
45
65
  const answer = await askAgentDoor(door, {
46
- path: "/api/docs/documents",
66
+ path: docsListPath(command),
47
67
  method: "GET",
48
68
  label: "docs list",
49
69
  timeoutMs: READ_DEADLINE_MS,
@@ -54,14 +74,15 @@ async function listDocs(door) {
54
74
  if (door.json)
55
75
  return emitAgentDoor(door, { ok: true, documents });
56
76
  if (documents.length === 0) {
57
- writeLine(door.io.stdout, "No documents.");
77
+ writeLine(door.io.stdout, command.query ? `No document matches "${command.query}".` : "No documents.");
58
78
  return 0;
59
79
  }
60
80
  for (const doc of documents) {
61
- writeLine(door.io.stdout, `${doc.id} ${doc.visibility.padEnd(7)} ${doc.slug ?? "(no slug)"} ${doc.title}`);
81
+ const size = typeof doc.body_chars === "number" ? `${doc.body_chars}c`.padStart(8) : " ?";
82
+ writeLine(door.io.stdout, `${doc.id} ${doc.visibility.padEnd(7)} ${size} ${doc.slug ?? "(no slug)"} ${doc.title}`);
62
83
  }
63
84
  writeLine(door.io.stdout, "");
64
- writeLine(door.io.stdout, `${documents.length} document(s).`);
85
+ writeLine(door.io.stdout, `${documents.length} document(s). Bodies come from \`cockpit docs read <id|slug>\`.`);
65
86
  return 0;
66
87
  }
67
88
  function renderTree(nodes, io, depth) {
@@ -1,4 +1,5 @@
1
1
  import { redactedHealthDetail } from "../health-detail.js";
2
+ import { setupReceiptBlock } from "./setup-receipt-lines.js";
2
3
  export function ok(id, code, message) {
3
4
  return { id, status: "ok", code, message };
4
5
  }
@@ -37,7 +38,9 @@ export async function maybeReportDoctorEvents(context, rows) {
37
38
  io: context.io,
38
39
  });
39
40
  }
40
- export function writeDoctorOutput(command, io, rows) {
41
+ export function writeDoctorOutput(command, io, rows,
42
+ /** BLI-3731. Absent means it could not be read; doctor says so rather than nothing. */
43
+ setupReceipt) {
41
44
  if (command.json) {
42
45
  writeLine(io.stdout, JSON.stringify({
43
46
  status: rows.some((row) => row.status === "fail" || row.hardStop)
@@ -45,6 +48,8 @@ export function writeDoctorOutput(command, io, rows) {
45
48
  : "pass",
46
49
  dry_run: command.dryRun,
47
50
  steps: rows,
51
+ setup_receipt: setupReceipt?.receipt ?? null,
52
+ memory_install: setupReceipt?.memory ?? null,
48
53
  }, null, 2));
49
54
  return;
50
55
  }
@@ -61,6 +66,17 @@ export function writeDoctorOutput(command, io, rows) {
61
66
  writeLine(io.stderr, `${row.id}:`);
62
67
  writeLine(io.stderr, row.message);
63
68
  }
69
+ // BLI-3731. The invariant table says whether collection is healthy; this
70
+ // says whether the machine is CONNECTED — the browser sign-in, the device
71
+ // session, both agent hosts and the scheduler, every word read back off this
72
+ // host. Printed last because it is what a person came to check on day one.
73
+ writeLine(io.stdout, "");
74
+ writeLine(io.stdout, "Connected:");
75
+ for (const line of setupReceipt
76
+ ? setupReceiptBlock(setupReceipt, { indent: " " })
77
+ : [" unknown — this machine could not be read this run."]) {
78
+ writeLine(io.stdout, line);
79
+ }
64
80
  }
65
81
  function doctorEvent(row) {
66
82
  const status = row.status === "fail" || row.hardStop
@@ -2,6 +2,7 @@ import { checkSingleInstallState, fixAuthState, fixRootState, readAuthState, rea
2
2
  import { backfillCompletionStepState, checkBackfillState, checkDiskState, checkGcState, checkSyncState, fixBackfillState, fixDiskState, fixGcState, fixSyncState, syncBacklogDrainingVerdict, } from "./doctor-pipeline.js";
3
3
  import { checkAutostartState, checkMemoryState, fixAutostartState, fixMemoryState, } from "./doctor-registration.js";
4
4
  import { dryRunPreview, isInteractiveDoctorFix, maybeReportDoctorEvents, writeDoctorOutput, } from "./doctor-report.js";
5
+ import { refreshSetupReceipt } from "./setup-receipt.js";
5
6
  import { checkCliLatest, fixCliLatest, latestCliVersionFromNpm, reexecDoctor, } from "./doctor-update.js";
6
7
  export async function runDoctor(command, io, hooks, overrides = {}) {
7
8
  const deps = { ...defaultDoctorDeps(hooks), ...overrides };
@@ -40,12 +41,15 @@ export async function runDoctorWithDeps(command, io, deps) {
40
41
  break;
41
42
  if (fixed.reexecExitCode !== undefined) {
42
43
  await maybeReportDoctorEvents(context, rows);
43
- writeDoctorOutput(command, io, rows);
44
+ writeDoctorOutput(command, io, rows, await deps.readSetupReceipt(context));
44
45
  return fixed.reexecExitCode;
45
46
  }
46
47
  }
47
48
  await maybeReportDoctorEvents(context, rows);
48
- writeDoctorOutput(command, io, rows);
49
+ // Doctor is the surface a person opens when something is wrong, so it
50
+ // re-READS the machine rather than quoting a cache — and caching what it
51
+ // read is what keeps the 15-minute heartbeat from paying for the probe.
52
+ writeDoctorOutput(command, io, rows, await deps.readSetupReceipt(context));
49
53
  return rows.some((row) => row.status === "fail" || row.hardStop) ? 1 : 0;
50
54
  }
51
55
  function doctorInvariants() {
@@ -129,6 +133,12 @@ function defaultDoctorDeps(hooks) {
129
133
  fixDisk: fixDiskState,
130
134
  checkSync: checkSyncState,
131
135
  fixSync: fixSyncState,
136
+ readSetupReceipt: (context) => refreshSetupReceipt(context.io, {
137
+ ...(context.command.homeDir ? { homeDir: context.command.homeDir } : {}),
138
+ ...(context.command.dashboardUrl
139
+ ? { dashboardUrl: context.command.dashboardUrl }
140
+ : {}),
141
+ }),
132
142
  };
133
143
  }
134
144
  // Re-exported so every consumer keeps importing from `./doctor.js` regardless
@@ -23,10 +23,12 @@ import crypto from "node:crypto";
23
23
  import fs from "node:fs";
24
24
  import os from "node:os";
25
25
  import path from "node:path";
26
- import { COLLECTOR_HEARTBEAT_SCHEMA_VERSION, } from "@bli-cockpit/telemetry-core";
26
+ import { COLLECTOR_HEARTBEAT_SCHEMA_VERSION, MemoryInstallReceiptSchema, memoryInstallGaps, setupReceiptGaps, } from "@bli-cockpit/telemetry-core";
27
+ import { readCachedSetupReceipt } from "./setup-receipt.js";
27
28
  import { describeError } from "../health-detail.js";
28
29
  import { shouldSuppressFleetReceipts, } from "../dev-build.js";
29
30
  import { getCollectorRuntimePaths, readLocalCollectorSessionFile, LOCAL_COLLECTOR_VERSION, } from "../local-state.js";
31
+ import { readMemoryReceiptFile } from "./memory-install-receipt.js";
30
32
  const HEARTBEAT_TIMEOUT_MS = 5_000;
31
33
  /**
32
34
  * The label form of one approved root.
@@ -108,8 +110,40 @@ export function buildCollectorHeartbeat(options) {
108
110
  ...(typeof options.facts.sessionsPendingUpload === "number"
109
111
  ? { sessions_pending_upload: options.facts.sessionsPendingUpload }
110
112
  : {}),
113
+ ...(options.memoryInstall ? { memory_install: options.memoryInstall } : {}),
114
+ ...(options.setupReceipt ? { setup_receipt: options.setupReceipt } : {}),
111
115
  };
112
116
  }
117
+ /**
118
+ * The cached memory receipt for this tick, or null with a named reason
119
+ * (BLI-3729).
120
+ *
121
+ * Reads the file `cockpit memory install` / `cockpit memory status` left
122
+ * behind; it does NOT re-inspect the host configs, which would cost five file
123
+ * reads and a `--print-config` spawn every fifteen minutes to re-prove a state
124
+ * that changes about once a month. The reason is returned rather than logged
125
+ * here so the ONE heartbeat log line carries it.
126
+ */
127
+ export async function readHeartbeatMemoryReceipt(options) {
128
+ const paths = getCollectorRuntimePaths(options.homeDir);
129
+ const result = await readMemoryReceiptFile({
130
+ stateDir: paths.state_dir,
131
+ readText: async (file) => {
132
+ try {
133
+ return await fs.promises.readFile(file, "utf8");
134
+ }
135
+ catch {
136
+ return null;
137
+ }
138
+ },
139
+ ...(options.now ? { now: options.now } : {}),
140
+ parse: (value) => {
141
+ const parsed = MemoryInstallReceiptSchema.safeParse(value);
142
+ return parsed.success ? parsed.data : null;
143
+ },
144
+ });
145
+ return { receipt: result.receipt, reason: result.reason };
146
+ }
113
147
  /**
114
148
  * Sends the heartbeat. Returns whether it landed; never throws.
115
149
  *
@@ -148,10 +182,34 @@ export async function sendCollectorHeartbeatBestEffort(options) {
148
182
  }));
149
183
  return false;
150
184
  }
185
+ const memory = await readHeartbeatMemoryReceipt({
186
+ ...(options.homeDir ? { homeDir: options.homeDir } : {}),
187
+ ...(options.now ? { now: options.now } : {}),
188
+ }).catch(() => ({ receipt: null, reason: "receipt_read_threw" }));
189
+ // BLI-3731. Read the CACHE, never re-probe: computing the receipt costs five
190
+ // file reads and a `--print-config` spawn, and these facts change about
191
+ // monthly. `cockpit memory install`, `onboard` and `doctor` refresh it; a
192
+ // tick only carries it. Both branches say something, because "the ops board
193
+ // shows no receipt for this machine" has two very different causes.
194
+ const setupReceipt = await readCachedSetupReceipt(options.homeDir, options.now ?? new Date());
195
+ console.error(setupReceipt
196
+ ? "[heartbeat] carrying this machine's setup receipt"
197
+ : "[heartbeat] no usable setup receipt to carry; the ops board keeps the last one it has", JSON.stringify(setupReceipt
198
+ ? {
199
+ reason: "setup_receipt_cached",
200
+ gap_count: setupReceiptGaps(setupReceipt).length,
201
+ gaps: setupReceiptGaps(setupReceipt),
202
+ }
203
+ : {
204
+ reason: "setup_receipt_absent_or_stale",
205
+ next_action: "run `cockpit doctor` to refresh it",
206
+ }));
151
207
  const heartbeat = buildCollectorHeartbeat({
152
208
  roots: options.roots,
153
209
  facts: options.facts,
210
+ setupReceipt,
154
211
  ...(options.now ? { now: options.now } : {}),
212
+ memoryInstall: memory.receipt,
155
213
  });
156
214
  const controller = new AbortController();
157
215
  const timeout = setTimeout(() => controller.abort(), HEARTBEAT_TIMEOUT_MS);
@@ -184,6 +242,12 @@ export async function sendCollectorHeartbeatBestEffort(options) {
184
242
  sessions_outside_root: heartbeat.sessions_outside_root ?? null,
185
243
  sessions_new_this_tick: heartbeat.sessions_new_this_tick ?? null,
186
244
  sessions_pending_upload: heartbeat.sessions_pending_upload ?? null,
245
+ // BLI-3729. Both branches: a tick that reports no receipt says WHY,
246
+ // and a tick that reports one says whether memory is fully on. "Is BLI
247
+ // Memory switched on for this machine?" is now answerable from
248
+ // sync.err.log alone.
249
+ memory_receipt: memory.reason,
250
+ memory_gaps: memory.receipt ? memoryInstallGaps(memory.receipt) : null,
187
251
  }));
188
252
  return true;
189
253
  }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The ONE shape a JARVIS answer wears when nobody is reading it with their
3
+ * eyes (BLI-3732).
4
+ *
5
+ * `cockpit jarvis --json` and the `bli-tower` MCP server's `jarvis_ask` reach
6
+ * the same door (`POST /api/jarvis/cli`) with the same device token and get
7
+ * the same reply body back. Before this file they described that body two
8
+ * different ways, so a script and an agent read two contracts for one turn.
9
+ * Now both build this envelope, and the five fields a consumer actually asks
10
+ * for — the answer, where it came from, which turn it was, which conversation
11
+ * it belongs to, and whether anything about it was second-rate — have one
12
+ * spelling each.
13
+ *
14
+ * ## Where the second copy is, and why
15
+ *
16
+ * `packages/bli-cockpit-mcp/src/jarvis-answer-envelope.ts` is a deliberate
17
+ * copy of this file. That package declares no dependency on this one — see
18
+ * `packages/bli-cockpit-mcp/src/agent-door-session.ts`, whose own header makes
19
+ * the same call for the same reason — so the shape is duplicated rather than
20
+ * imported. Both copies are pinned by a test on the same literal key list
21
+ * (`JARVIS_ANSWER_ENVELOPE_KEYS` below), so a field added on one side and not
22
+ * the other fails a suite instead of drifting quietly.
23
+ *
24
+ * ## What `--json` still prints
25
+ *
26
+ * These keys are ADDED to what `cockpit jarvis --json` already printed; the
27
+ * older `reply` / `thread` / `traceId` / `model` / `trace` / `latency` /
28
+ * `clientLatency` keys are untouched, because scripts already read them and a
29
+ * one-contract ticket that broke the contract would be a joke.
30
+ */
31
+ /**
32
+ * Every key of the envelope, in the order it is written. The literal list IS
33
+ * the contract: both copies assert against it, so a drift is a red suite.
34
+ */
35
+ export const JARVIS_ANSWER_ENVELOPE_KEYS = [
36
+ "ok",
37
+ "answer",
38
+ "sources",
39
+ "turn_id",
40
+ "thread_id",
41
+ "trace_thread_id",
42
+ "degraded",
43
+ "degraded_reasons",
44
+ ];
45
+ /** A `Source:` line, as the grounding gate renders it into the answer. */
46
+ const SOURCE_LINE = /^\s*Source:\s*\S/;
47
+ /**
48
+ * The `Source:` lines inside an answer. Pure string work on what the server
49
+ * already sent — this side never decides what a source IS, it only finds the
50
+ * lines the server wrote, so a new citation kind needs no change here.
51
+ */
52
+ export function extractSourceLines(answer) {
53
+ return answer
54
+ .split("\n")
55
+ .map((line) => line.trim())
56
+ .filter((line) => SOURCE_LINE.test(line));
57
+ }
58
+ export function buildJarvisAnswerEnvelope(input) {
59
+ const reasons = [];
60
+ if (input.modelFallback === true)
61
+ reasons.push("model_fallback");
62
+ if (input.revised === true)
63
+ reasons.push("answer_revised");
64
+ if ((input.trace ?? []).some((step) => step?.status === "failed")) {
65
+ reasons.push("tool_step_failed");
66
+ }
67
+ const turnId = input.traceId ?? null;
68
+ if (!turnId)
69
+ reasons.push("no_turn_id");
70
+ return {
71
+ ok: true,
72
+ answer: input.reply,
73
+ sources: extractSourceLines(input.reply),
74
+ turn_id: turnId,
75
+ thread_id: input.thread ?? null,
76
+ trace_thread_id: input.traceThread ?? null,
77
+ degraded: reasons.length > 0,
78
+ degraded_reasons: reasons,
79
+ };
80
+ }
@@ -7,6 +7,7 @@
7
7
  * `jarvis-render.ts` — imported one direction only.
8
8
  */
9
9
  import { colorEnabled, dim, writeLine } from "./cli-io.js";
10
+ import { buildJarvisAnswerEnvelope } from "./jarvis-answer-envelope.js";
10
11
  import { readAttachedImage } from "./jarvis-attachment.js";
11
12
  import { rememberTurnTrace } from "./jarvis-trace.js";
12
13
  import { towerFailureDetail, towerJsonRequest, towerRequest } from "../tower-client.js";
@@ -131,7 +132,21 @@ export async function sendOneTurn(context, prompt, io) {
131
132
  await rememberTurnTrace({ traceId: body.traceId ?? null, threadId: body.traceThread ?? null }, io, context.command.homeDir);
132
133
  if (context.command.json) {
133
134
  writeLine(io.stdout, JSON.stringify({
134
- ok: true,
135
+ // BLI-3732: the shared envelope FIRST — `answer`, `sources`,
136
+ // `turn_id`, `thread_id`, `trace_thread_id`, `degraded`,
137
+ // `degraded_reasons` — so a script here and an agent on the
138
+ // `jarvis_ask` MCP tool read one contract for one turn. The keys
139
+ // below it are the ones this command has always printed and are
140
+ // untouched; `reply` and `answer` are the same string.
141
+ ...buildJarvisAnswerEnvelope({
142
+ reply: body.reply,
143
+ thread: body.thread ?? context.command.thread,
144
+ traceId: body.traceId,
145
+ traceThread: body.traceThread,
146
+ modelFallback: body.model?.fallback,
147
+ revised: body.revised,
148
+ trace,
149
+ }),
135
150
  reply: body.reply,
136
151
  thread: body.thread ?? context.command.thread,
137
152
  model: body.model ?? null,
@@ -12,6 +12,9 @@
12
12
  * - `jarvis-contracts.ts` — the parsed `cockpit jarvis` command type, and the
13
13
  * loose reply shapes read off `/api/jarvis/cli`, `--threads` and
14
14
  * `--history`.
15
+ * - `jarvis-answer-envelope.ts` — the shape `--json` prints (BLI-3732), which
16
+ * is the same shape the `bli-tower` MCP server's `jarvis_ask` returns, so a
17
+ * script and an agent read one contract for one turn.
15
18
  * - `jarvis-turn.ts` — the turn engine: `sendOneTurn` (attach, request,
16
19
  * stream, settle, print, log — the one send for both a one-shot invocation
17
20
  * and the interactive loop below) and `readHistory` (`--threads` /
@@ -31,6 +31,11 @@ function parseOnboardLikeArgs(args, command) {
31
31
  "--max-depth",
32
32
  "--max-repos",
33
33
  "--allow-home-root",
34
+ // BLI-3731, the one-sign-in ceremony. Same three flags as `login`, so a
35
+ // person who learned them on one door does not relearn them on another.
36
+ "--pair",
37
+ "--no-browser",
38
+ "--legacy-pair",
34
39
  ],
35
40
  valueFlags: [
36
41
  "--home",
@@ -45,6 +50,7 @@ function parseOnboardLikeArgs(args, command) {
45
50
  "--timeout-ms",
46
51
  "--max-depth",
47
52
  "--max-repos",
53
+ "--pair",
48
54
  ],
49
55
  });
50
56
  assertNoPositionals(values.positionals, command);
@@ -65,6 +71,9 @@ function parseOnboardLikeArgs(args, command) {
65
71
  maxDepth: optionalPositiveInteger(values.flags.get("--max-depth"), "--max-depth"),
66
72
  maxRepos: optionalPositiveInteger(values.flags.get("--max-repos"), "--max-repos"),
67
73
  allowHomeRoot: values.booleans.has("--allow-home-root"),
74
+ noBrowser: values.booleans.has("--no-browser"),
75
+ legacyPair: values.booleans.has("--legacy-pair"),
76
+ pairCode: optionalNonEmpty(values.flags.get("--pair")),
68
77
  };
69
78
  }
70
79
  export function parseOnboardArgs(args) {
@@ -210,6 +219,10 @@ export function parseLoginArgs(args) {
210
219
  "--no-auth",
211
220
  "--poll-interval-ms",
212
221
  "--timeout-ms",
222
+ // BLI-3731, the one-sign-in ceremony.
223
+ "--pair",
224
+ "--no-browser",
225
+ "--legacy-pair",
213
226
  ],
214
227
  valueFlags: [
215
228
  "--home",
@@ -218,6 +231,7 @@ export function parseLoginArgs(args) {
218
231
  "--device-name",
219
232
  "--poll-interval-ms",
220
233
  "--timeout-ms",
234
+ "--pair",
221
235
  ],
222
236
  });
223
237
  assertNoPositionals(values.positionals, "login");
@@ -231,6 +245,9 @@ export function parseLoginArgs(args) {
231
245
  noAuth: values.booleans.has("--no-auth"),
232
246
  pollIntervalMs: optionalPositiveInteger(values.flags.get("--poll-interval-ms"), "--poll-interval-ms"),
233
247
  timeoutMs: optionalPositiveInteger(values.flags.get("--timeout-ms"), "--timeout-ms"),
248
+ pairCode: optionalNonEmpty(values.flags.get("--pair")),
249
+ noBrowser: values.booleans.has("--no-browser"),
250
+ legacyPair: values.booleans.has("--legacy-pair"),
234
251
  };
235
252
  }
236
253
  export function parseLogoutArgs(args) {
@@ -48,7 +48,7 @@ export function parseScoutArgs(args) {
48
48
  return { kind: "scout", action: rawAction, experimentRef, ...base };
49
49
  }
50
50
  /**
51
- * `cockpit ops status [--job <id>] [--skips]` and
51
+ * `cockpit ops status [--job <id>] [--skips] [--memory [--memory-days N]]` and
52
52
  * `cockpit ops recompile --person <p> [--dry-run]` (BLI-3462).
53
53
  *
54
54
  * There is deliberately **no `--cadence`** on `recompile`. The compile path
@@ -64,11 +64,13 @@ export function parseOpsArgs(args) {
64
64
  "--dashboard-url",
65
65
  "--job",
66
66
  "--skips",
67
+ "--memory",
68
+ "--memory-days",
67
69
  "--person",
68
70
  "--dry-run",
69
71
  "--json",
70
72
  ],
71
- valueFlags: ["--home", "--dashboard-url", "--job", "--person"],
73
+ valueFlags: ["--home", "--dashboard-url", "--job", "--person", "--memory-days"],
72
74
  });
73
75
  if (values.positionals.length > 1) {
74
76
  throw new Error("ops accepts one action: status or recompile.");
@@ -83,11 +85,19 @@ export function parseOpsArgs(args) {
83
85
  json: values.booleans.has("--json"),
84
86
  };
85
87
  if (rawAction === "status") {
88
+ // BLI-3729: `--memory-days N` implies `--memory`, because asking for a
89
+ // window and getting nothing back is the silent breakage BLI-2490 forbids.
90
+ const memoryDays = optionalNonEmpty(values.flags.get("--memory-days"));
91
+ if (memoryDays !== undefined && !/^[0-9]{1,2}$/u.test(memoryDays)) {
92
+ throw new Error("ops --memory-days takes a whole number of days, 1 to 30.");
93
+ }
86
94
  return {
87
95
  kind: "ops",
88
96
  action: "status",
89
97
  job: optionalNonEmpty(values.flags.get("--job")),
90
98
  skips: values.booleans.has("--skips"),
99
+ memory: values.booleans.has("--memory") || memoryDays !== undefined,
100
+ ...(memoryDays === undefined ? {} : { memoryDays: Number(memoryDays) }),
91
101
  ...base,
92
102
  };
93
103
  }