@bli-cockpit/cli 0.2.237 → 0.2.238
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/dist/adapters/attribution-core-fallbacks.js +15 -11
- package/dist/adapters/attribution-core-score.js +111 -87
- package/dist/adapters/car-state.js +38 -35
- package/dist/adapters/claude-attribution-discovery.js +81 -56
- package/dist/adapters/claude-attribution-score.js +108 -94
- package/dist/adapters/claude-attribution-signals.js +52 -42
- package/dist/adapters/codex-attribution.js +42 -33
- package/dist/adapters/codex-session-signals.js +11 -9
- package/dist/adapters/git-state.js +56 -50
- package/dist/adapters/local-sources.js +52 -43
- package/dist/adapters/raw-evidence-git-diff.js +4 -2
- package/dist/adapters/raw-evidence-sanitize.js +15 -12
- package/dist/adapters/raw-evidence-transcript-file.js +32 -31
- package/dist/autostart-self-heal.js +18 -2
- package/dist/commands/agent-session-report.js +51 -59
- package/dist/commands/agent-setup-observed.js +30 -23
- package/dist/commands/agent-setup.js +96 -45
- package/dist/commands/autostart-heal.js +8 -2
- package/dist/commands/autostart-reading.js +3 -0
- package/dist/commands/backfill-evidence-outcomes.js +9 -6
- package/dist/commands/backfill-issues.js +3 -0
- package/dist/commands/backfill-scan.js +27 -22
- package/dist/commands/backfill-upload.js +69 -60
- package/dist/commands/backfill.js +26 -21
- package/dist/commands/brief-done.js +4 -1
- package/dist/commands/brief-edit.js +71 -46
- package/dist/commands/cal-detail.js +35 -0
- package/dist/commands/cal-overlay.js +73 -30
- package/dist/commands/cal.js +36 -23
- package/dist/commands/clean.js +4 -1
- package/dist/commands/docs-read.js +5 -2
- package/dist/commands/doctor-backfill.js +88 -71
- package/dist/commands/doctor-pipeline.js +59 -46
- package/dist/commands/heartbeat-post.js +116 -0
- package/dist/commands/heartbeat-token-lock.js +46 -33
- package/dist/commands/heartbeat.js +43 -125
- package/dist/commands/install-update.js +17 -15
- package/dist/commands/issue-show.js +27 -28
- package/dist/commands/issue-write.js +70 -23
- package/dist/commands/issue.js +68 -37
- package/dist/commands/jarvis-live-answer.js +99 -0
- package/dist/commands/jarvis-render.js +1 -94
- package/dist/commands/jarvis-trace.js +30 -22
- package/dist/commands/jarvis-turn-report.js +124 -0
- package/dist/commands/jarvis-turn.js +108 -182
- package/dist/commands/jarvis.js +26 -17
- package/dist/commands/local-args-collector-setup.js +82 -84
- package/dist/commands/local-args-collector-work.js +37 -38
- package/dist/commands/local-args-tower-admin.js +155 -142
- package/dist/commands/local-args-tower-cal.js +52 -50
- package/dist/commands/local-args-tower-careers.js +73 -54
- package/dist/commands/local-args-tower-docs-msg.js +55 -45
- package/dist/commands/local-args-tower-github.js +26 -20
- package/dist/commands/local-args-tower-hits.js +32 -20
- package/dist/commands/local-args-tower-manager.js +85 -4
- package/dist/commands/local-args-tower-memory.js +139 -117
- package/dist/commands/local-args-tower-notes.js +346 -0
- package/dist/commands/local-args-tower-pages.js +100 -378
- package/dist/commands/local-args-tower-settings.js +28 -29
- package/dist/commands/local-args-tower-work.js +52 -33
- package/dist/commands/local-args.js +80 -129
- package/dist/commands/local-help-commands-tower-ops.js +15 -4
- package/dist/commands/local-help-commands-tower.js +6 -2
- package/dist/commands/local-help-commands.js +342 -341
- package/dist/commands/local-help.js +87 -83
- package/dist/commands/local-run-guards.js +100 -0
- package/dist/commands/local.js +137 -206
- package/dist/commands/login.js +13 -9
- package/dist/commands/logs.js +55 -38
- package/dist/commands/mail-attachments.js +44 -26
- package/dist/commands/manager-render-home.js +208 -0
- package/dist/commands/manager-render.js +7 -3
- package/dist/commands/manager-requests.js +33 -0
- package/dist/commands/manager.js +39 -5
- package/dist/commands/memory-consolidation.js +18 -9
- package/dist/commands/memory-daemon-probe.js +37 -28
- package/dist/commands/memory-install-config.js +64 -60
- package/dist/commands/memory-install.js +21 -41
- package/dist/commands/memory-requeue.js +26 -19
- package/dist/commands/memory-rules.js +26 -18
- package/dist/commands/memory-search-print.js +26 -0
- package/dist/commands/memory-store.js +14 -30
- package/dist/commands/memory-verb-list.js +49 -48
- package/dist/commands/notes-accounts.js +49 -32
- package/dist/commands/notes-sync-loop.js +115 -89
- package/dist/commands/notes-wisprflow-login.js +44 -23
- package/dist/commands/notes-writes.js +115 -100
- package/dist/commands/notes.js +33 -55
- package/dist/commands/onboard-flows.js +69 -51
- package/dist/commands/onboard.js +11 -9
- package/dist/commands/ops-render-memory.js +10 -7
- package/dist/commands/ops-render.js +33 -30
- package/dist/commands/ops.js +3 -0
- package/dist/commands/public-root.js +1 -1
- package/dist/commands/session-sync-outside-roots.js +40 -36
- package/dist/commands/session-sync-plan.js +14 -10
- package/dist/commands/session-sync-upload.js +24 -22
- package/dist/commands/session-sync.js +19 -8
- package/dist/commands/slack.js +25 -16
- package/dist/commands/sources-check.js +13 -7
- package/dist/commands/sources-discovery.js +25 -17
- package/dist/commands/sources-verdict.js +19 -18
- package/dist/commands/speed.js +23 -19
- package/dist/commands/start.js +20 -16
- package/dist/commands/sync-doctor.js +52 -48
- package/dist/commands/sync.js +22 -16
- package/dist/commands/usage-telemetry-toml.js +71 -45
- package/dist/commands/usage.js +91 -67
- package/dist/commands/workbook-render.js +10 -7
- package/dist/evidence-reconcile-client.js +75 -64
- package/dist/evidence-redelivery-plan.js +37 -34
- package/dist/evidence-redelivery.js +32 -29
- package/dist/evidence-transcripts-client.js +20 -20
- package/dist/evidence-upload-object.js +86 -89
- package/dist/evidence-upload-plan.js +94 -83
- package/dist/evidence-upload-terminal.js +45 -50
- package/dist/image-description-session.js +156 -159
- package/dist/local-state-pairing-code.js +39 -31
- package/dist/local-state-status.js +9 -2
- package/dist/onboarding-roots.js +5 -8
- package/dist/process-runner.js +8 -8
- package/dist/raw-evidence-gc.js +33 -38
- package/dist/raw-evidence-stuck-summary.js +7 -14
- package/dist/repo-identity.js +26 -23
- package/dist/scheduled-self-update.js +11 -15
- package/dist/second-install.js +3 -0
- package/dist/slim/codex-rules.js +23 -36
- package/dist/sync-lock.js +5 -15
- package/dist/tower-client.js +36 -53
- package/dist/tower-stream.js +7 -24
- package/dist/upload-agent-artifacts.js +58 -64
- package/dist/upload-envelope-build.js +60 -59
- package/dist/upload-evidence-delivery-reconcile.js +58 -56
- package/dist/upload-evidence-delivery-summary.js +32 -34
- package/dist/upload-ingest-receipt.js +20 -23
- package/dist/upload-session-reports-queue.js +4 -1
- package/dist/upload-session-reports-wire.js +64 -68
- package/dist/upload-sync.js +171 -157
- package/package.json +2 -2
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { writeLine } from "./cli-io.js";
|
|
2
|
+
import { buildJarvisAnswerEnvelope } from "./jarvis-answer-envelope.js";
|
|
3
|
+
import { clientTimingFields, latencyFields, latencyLogFields, writeModelReceipt, writeRevision, writeTraceBlock, } from "./jarvis-render.js";
|
|
4
|
+
export function printJsonTurn(settled) {
|
|
5
|
+
const { context, io, body, trace, sent, turn, startedAt, preRequestMs } = settled;
|
|
6
|
+
writeLine(io.stdout, JSON.stringify({
|
|
7
|
+
// BLI-3732: the shared envelope FIRST — `answer`, `sources`,
|
|
8
|
+
// `turn_id`, `thread_id`, `trace_thread_id`, `degraded`,
|
|
9
|
+
// `degraded_reasons` — so a script here and an agent on the
|
|
10
|
+
// `jarvis_ask` MCP tool read one contract for one turn. The keys
|
|
11
|
+
// below it are the ones this command has always printed and are
|
|
12
|
+
// untouched; `reply` and `answer` are the same string.
|
|
13
|
+
...buildJarvisAnswerEnvelope({
|
|
14
|
+
reply: body.reply,
|
|
15
|
+
thread: body.thread ?? context.command.thread,
|
|
16
|
+
traceId: body.traceId,
|
|
17
|
+
traceThread: body.traceThread,
|
|
18
|
+
modelFallback: body.model?.fallback,
|
|
19
|
+
revised: body.revised,
|
|
20
|
+
trace,
|
|
21
|
+
proposalId: body.proposalId,
|
|
22
|
+
// BLI-3787: the sentence beside it — what a person must do next when
|
|
23
|
+
// the arm proposed something, and when it refused instead.
|
|
24
|
+
nextAction: body.nextAction,
|
|
25
|
+
// BLI-3770: the door's own structured citations. Absent from a
|
|
26
|
+
// dashboard that predates it, and the envelope falls back to
|
|
27
|
+
// reading the answer's own `Source:` lines when it is.
|
|
28
|
+
sources: body.sources,
|
|
29
|
+
}),
|
|
30
|
+
reply: body.reply,
|
|
31
|
+
thread: body.thread ?? context.command.thread,
|
|
32
|
+
model: body.model ?? null,
|
|
33
|
+
trace,
|
|
34
|
+
subject: body.subject ?? null,
|
|
35
|
+
// BLI-3582: the server's own split of the wait. `null` from a
|
|
36
|
+
// dashboard that does not measure it yet.
|
|
37
|
+
latency: latencyFields(body.latency),
|
|
38
|
+
// BLI-3591: this side's own half of the same wait, so a consumer can
|
|
39
|
+
// put the whole journey together without a stopwatch of its own.
|
|
40
|
+
clientLatency: {
|
|
41
|
+
bootMs: context.boot.bootMs,
|
|
42
|
+
sessionMs: context.boot.sessionMs,
|
|
43
|
+
promptMs: context.boot.promptMs,
|
|
44
|
+
preRequestMs,
|
|
45
|
+
respondedMs: sent.respondedMs,
|
|
46
|
+
firstByteMs: turn.timing.firstByteMs,
|
|
47
|
+
firstFrameMs: turn.timing.firstFrameMs,
|
|
48
|
+
firstTokenMs: turn.timing.firstTokenMs,
|
|
49
|
+
elapsedMs: Date.now() - startedAt,
|
|
50
|
+
},
|
|
51
|
+
...(body.traceId ? { traceId: body.traceId } : {}),
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
export function printTerminalTurn(settled, live) {
|
|
55
|
+
const { context, io, body, trace, liveTraceLines } = settled;
|
|
56
|
+
const subject = body.subject?.displayName ? ` (${body.subject.displayName})` : "";
|
|
57
|
+
// BLI-3517: when the answer streamed, `settle` prints only what the live
|
|
58
|
+
// words did not already say — and says so out loud when the grounding gate
|
|
59
|
+
// took some of them back. When nothing streamed it prints the whole reply
|
|
60
|
+
// through `writeReply`, which is byte-for-byte what this command printed
|
|
61
|
+
// before, BLI-3570's dim link line included.
|
|
62
|
+
live.settle(body.reply, subject, body.revised === true);
|
|
63
|
+
// BLI-3567: what the correction did to the answer above, printed under
|
|
64
|
+
// this turn's reply because that is the only place a terminal has.
|
|
65
|
+
if (body.revision)
|
|
66
|
+
writeRevision(context.command, io, body.revision);
|
|
67
|
+
// Only when nothing was drawn live — otherwise every tool would print twice.
|
|
68
|
+
if (liveTraceLines === 0)
|
|
69
|
+
writeTraceBlock(io, trace);
|
|
70
|
+
writeModelReceipt(io, body.model);
|
|
71
|
+
}
|
|
72
|
+
export function logAnsweredTurn(settled) {
|
|
73
|
+
const { context, io, prompt, body, trace, attachment, sent, turn, startedAt, preRequestMs, liveTraceLines } = settled;
|
|
74
|
+
writeLine(io.stderr, `[jarvis cli] answered ${JSON.stringify({
|
|
75
|
+
prompt_length: prompt.length,
|
|
76
|
+
reply_length: body.reply.length,
|
|
77
|
+
trace_steps: trace?.length ?? 0,
|
|
78
|
+
trace_failed: trace?.filter((step) => step.status === "failed").length ?? 0,
|
|
79
|
+
model_requested: context.command.model ?? null,
|
|
80
|
+
elapsed_ms: Date.now() - startedAt,
|
|
81
|
+
// BLI-3786: `minted` is a conversation the DOOR opened for this call
|
|
82
|
+
// because nothing named one — read off the answer rather than guessed
|
|
83
|
+
// from the name, so this side keeps no copy of the server's rule. Never
|
|
84
|
+
// the thread name itself.
|
|
85
|
+
thread: body.thread && body.thread !== context.command.thread
|
|
86
|
+
? "minted"
|
|
87
|
+
: context.command.thread === "main"
|
|
88
|
+
? "default"
|
|
89
|
+
: "named",
|
|
90
|
+
subject: context.command.subject ? "selected" : "caller",
|
|
91
|
+
image_attached: attachment !== null,
|
|
92
|
+
image_byte_size: attachment?.bytes.byteLength ?? null,
|
|
93
|
+
streamed: turn.streamed,
|
|
94
|
+
live_trace_lines: liveTraceLines,
|
|
95
|
+
// BLI-3517: whether the words arrived live, and whether the settled
|
|
96
|
+
// answer superseded them. `streamed_chars: 0` against a streaming
|
|
97
|
+
// dashboard means the answer landed all at once.
|
|
98
|
+
streamed_chars: turn.draft.length,
|
|
99
|
+
revised: body.revised === true,
|
|
100
|
+
// BLI-3567: whether this turn was told there was an answer above it, and
|
|
101
|
+
// what the correction did to it. `sent_previous_answer: false` is a
|
|
102
|
+
// one-shot turn; a status with no revision at all is a dashboard that
|
|
103
|
+
// predates the step.
|
|
104
|
+
sent_previous_answer: Boolean(context.previous),
|
|
105
|
+
revision: body.revision?.status ?? null,
|
|
106
|
+
revision_reason: body.revision?.reason ?? null,
|
|
107
|
+
// BLI-3582: `elapsed_ms` above is the whole wait as this side felt it;
|
|
108
|
+
// these three say which part of it was the dashboard's prep, which was
|
|
109
|
+
// the model's first token, and how long the socket stayed silent before
|
|
110
|
+
// the first byte. All null against a dashboard that does not send them.
|
|
111
|
+
...latencyLogFields(body.latency),
|
|
112
|
+
// BLI-3591: the terminal's own half, on the same line, so the gap
|
|
113
|
+
// between the dashboard's first token and the first character a person
|
|
114
|
+
// sees stops being a mystery with nobody's name on it. `boot_ms` and
|
|
115
|
+
// `session_ms` are process facts (identical on every turn of an
|
|
116
|
+
// interactive session); the rest are this turn's, measured from the
|
|
117
|
+
// moment the turn started.
|
|
118
|
+
...clientTimingFields(context.boot, {
|
|
119
|
+
preRequestMs,
|
|
120
|
+
respondedMs: sent.respondedMs,
|
|
121
|
+
timing: turn.timing,
|
|
122
|
+
}),
|
|
123
|
+
})}`);
|
|
124
|
+
}
|
|
@@ -7,33 +7,20 @@
|
|
|
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";
|
|
11
10
|
import { readAttachedImage } from "./jarvis-attachment.js";
|
|
11
|
+
import { logAnsweredTurn, printJsonTurn, printTerminalTurn, } from "./jarvis-turn-report.js";
|
|
12
|
+
import { createLiveAnswer } from "./jarvis-live-answer.js";
|
|
12
13
|
import { rememberTurnTrace } from "./jarvis-trace.js";
|
|
13
14
|
import { towerFailureDetail, towerJsonRequest, towerRequest } from "../tower-client.js";
|
|
14
15
|
import { readTowerTurn, streamFailureDetail } from "../tower-stream.js";
|
|
15
|
-
import { activityToTrace, agentSurface, ANSWER_UPDATING_LINE, buildAttachmentForm,
|
|
16
|
+
import { activityToTrace, agentSurface, ANSWER_UPDATING_LINE, buildAttachmentForm, TURN_DEADLINE_MS, writeActivityLine, writeAttachmentRefusal, writeFailure, } from "./jarvis-render.js";
|
|
17
|
+
const FAILED_TURN = { exitCode: 1, reply: null };
|
|
16
18
|
export async function sendOneTurn(context, prompt, io) {
|
|
17
19
|
const startedAt = Date.now();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
let attachment = null;
|
|
23
|
-
if (context.command.imagePath) {
|
|
24
|
-
const read = await readAttachedImage(context.command.imagePath);
|
|
25
|
-
if (!read.ok) {
|
|
26
|
-
writeAttachmentRefusal(context.command, io, read.refusal, context.command.imagePath);
|
|
27
|
-
return { exitCode: 1, reply: null };
|
|
28
|
-
}
|
|
29
|
-
attachment = read;
|
|
30
|
-
}
|
|
31
|
-
// BLI-3457: streaming is the default. A dashboard that has not shipped the
|
|
32
|
-
// NDJSON half yet answers `application/json`, which the reader takes as a
|
|
33
|
-
// single final event and names `stream_not_available` — so the terminal
|
|
34
|
-
// works against both server versions with no flag.
|
|
35
|
-
const wantsStream = context.command.stream !== false;
|
|
36
|
-
const log = (line) => writeLine(io.stderr, line);
|
|
20
|
+
const attached = await readTurnAttachment(context.command, io);
|
|
21
|
+
if (!attached.ok)
|
|
22
|
+
return FAILED_TURN;
|
|
23
|
+
const { attachment } = attached;
|
|
37
24
|
// BLI-3591: everything this turn did before the question left the machine.
|
|
38
25
|
// There is no self-update probe, no floor check and no settings fetch on
|
|
39
26
|
// this path — the ONLY awaits between the command starting and the POST are
|
|
@@ -41,12 +28,57 @@ export async function sendOneTurn(context, prompt, io) {
|
|
|
41
28
|
// all three are named. If this number is ever large, the step that made it
|
|
42
29
|
// large is on the same line.
|
|
43
30
|
const preRequestMs = Date.now() - startedAt;
|
|
31
|
+
const log = (line) => writeLine(io.stderr, line);
|
|
32
|
+
const sent = await postTurn(context, io, prompt, attachment, log);
|
|
33
|
+
if (!sent)
|
|
34
|
+
return FAILED_TURN;
|
|
35
|
+
const read = await readStreamedTurn(context, io, sent, startedAt, log);
|
|
36
|
+
if (!read.ok)
|
|
37
|
+
return FAILED_TURN;
|
|
38
|
+
const { turn, liveTraceLines } = read;
|
|
39
|
+
const body = turn.final;
|
|
40
|
+
const httpStatus = typeof turn.final.httpStatus === "number" ? turn.final.httpStatus : sent.response.status;
|
|
41
|
+
if (httpStatus >= 400 || !body.ok || !body.reply) {
|
|
42
|
+
read.live.abandon();
|
|
43
|
+
const reason = body.error ?? body.reply ?? `http_${httpStatus}`;
|
|
44
|
+
writeFailure(context.command, io, "turn_failed", reason);
|
|
45
|
+
return FAILED_TURN;
|
|
46
|
+
}
|
|
47
|
+
// A streaming server may leave the settled trace out of the final event
|
|
48
|
+
// because it already sent every step live; the activity we collected is that
|
|
49
|
+
// same trace, so `--json` still gets one.
|
|
50
|
+
const trace = body.trace ?? activityToTrace(turn.activity);
|
|
51
|
+
// BLI-3560: bookmark this turn so `cockpit jarvis --trace last` can open its
|
|
52
|
+
// step tree. Written before the reply is printed for no reason other than
|
|
53
|
+
// keeping the failure — which is only ever a stderr line — above the answer
|
|
54
|
+
// rather than after it.
|
|
55
|
+
await rememberTurnTrace({ traceId: body.traceId ?? null, threadId: body.traceThread ?? null }, io, context.command.homeDir);
|
|
56
|
+
const settled = {
|
|
57
|
+
context, io, prompt, body: body, trace, attachment, sent, turn,
|
|
58
|
+
startedAt, preRequestMs, liveTraceLines: liveTraceLines(),
|
|
59
|
+
};
|
|
60
|
+
if (context.command.json) {
|
|
61
|
+
printJsonTurn(settled);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
printTerminalTurn(settled, read.live);
|
|
65
|
+
}
|
|
66
|
+
logAnsweredTurn(settled);
|
|
67
|
+
return { exitCode: 0, reply: body.reply };
|
|
68
|
+
}
|
|
69
|
+
/** Posts the question to the dashboard; null (after saying why) when the request failed. */
|
|
70
|
+
async function postTurn(context, io, prompt, attachment, log) {
|
|
71
|
+
// BLI-3457: streaming is the default. A dashboard that has not shipped the
|
|
72
|
+
// NDJSON half yet answers `application/json`, which the reader takes as a
|
|
73
|
+
// single final event and names `stream_not_available` — so the terminal
|
|
74
|
+
// works against both server versions with no flag.
|
|
75
|
+
const wantsStream = context.command.stream !== false;
|
|
44
76
|
// BLI-3755: never silently. A script that asked for the code is a script
|
|
45
77
|
// that can spend a human's approval, and the one line saying so is here.
|
|
46
78
|
if (context.command.json && context.command.showApprovalCode) {
|
|
47
79
|
log("[jarvis] approval code requested by a --json caller (--show-approval-code)");
|
|
48
80
|
}
|
|
49
|
-
const
|
|
81
|
+
const sent = await towerRequest({
|
|
50
82
|
dashboardUrl: context.dashboardUrl,
|
|
51
83
|
path: "/api/jarvis/cli",
|
|
52
84
|
deviceToken: context.deviceToken,
|
|
@@ -56,40 +88,67 @@ export async function sendOneTurn(context, prompt, io) {
|
|
|
56
88
|
headers: wantsStream ? { accept: "application/x-ndjson" } : {},
|
|
57
89
|
body: attachment
|
|
58
90
|
? buildAttachmentForm(context.command, prompt, attachment)
|
|
59
|
-
:
|
|
60
|
-
question: prompt,
|
|
61
|
-
thread: context.command.thread,
|
|
62
|
-
subject: context.command.subject,
|
|
63
|
-
model: context.command.model,
|
|
64
|
-
// BLI-3484: which day's page this turn is about. Sent verbatim — the
|
|
65
|
-
// dashboard decides what counts as a date and whose day it is.
|
|
66
|
-
date: context.command.date,
|
|
67
|
-
// BLI-3567: the answer this session last printed, so a correction can
|
|
68
|
-
// rewrite the paragraph it contradicts. Absent on a one-shot turn and
|
|
69
|
-
// on the first turn of a session, which is how the dashboard knows
|
|
70
|
-
// there is nothing above to revise.
|
|
71
|
-
previousAnswer: context.previous?.answer,
|
|
72
|
-
previousQuestion: context.previous?.question,
|
|
73
|
-
// BLI-3755: who is reading this answer. A `--json` turn is a
|
|
74
|
-
// PROGRAM's, so the coding arm withholds its approval code and
|
|
75
|
-
// answers with a proposal id instead; an interactive turn is a
|
|
76
|
-
// person's and is unchanged. `--show-approval-code` opts a script
|
|
77
|
-
// back in, and says so on stderr below.
|
|
78
|
-
surface: agentSurface(context.command) ? "agent" : undefined,
|
|
79
|
-
},
|
|
91
|
+
: buildQuestionBody(context, prompt),
|
|
80
92
|
log,
|
|
81
93
|
});
|
|
82
|
-
if (!
|
|
83
|
-
writeFailure(context.command, io,
|
|
84
|
-
return
|
|
94
|
+
if (!sent.ok) {
|
|
95
|
+
writeFailure(context.command, io, sent.reason, towerFailureDetail(sent.reason, sent.detail));
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return sent;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* BLI-3414: an attached file is read and locally screened (exists,
|
|
102
|
+
* readable, a supported extension, under the byte ceiling) BEFORE any
|
|
103
|
+
* network call — a refusal here never reaches the dashboard and is
|
|
104
|
+
* terminal, same discipline as the panel's own attached-image gate.
|
|
105
|
+
*/
|
|
106
|
+
async function readTurnAttachment(command, io) {
|
|
107
|
+
if (!command.imagePath)
|
|
108
|
+
return { ok: true, attachment: null };
|
|
109
|
+
const read = await readAttachedImage(command.imagePath);
|
|
110
|
+
if (!read.ok) {
|
|
111
|
+
writeAttachmentRefusal(command, io, read.refusal, command.imagePath);
|
|
112
|
+
return { ok: false };
|
|
85
113
|
}
|
|
114
|
+
return { ok: true, attachment: read };
|
|
115
|
+
}
|
|
116
|
+
function buildQuestionBody(context, prompt) {
|
|
117
|
+
return {
|
|
118
|
+
question: prompt,
|
|
119
|
+
thread: context.command.thread,
|
|
120
|
+
subject: context.command.subject,
|
|
121
|
+
model: context.command.model,
|
|
122
|
+
// BLI-3484: which day's page this turn is about. Sent verbatim — the
|
|
123
|
+
// dashboard decides what counts as a date and whose day it is.
|
|
124
|
+
date: context.command.date,
|
|
125
|
+
// BLI-3567: the answer this session last printed, so a correction can
|
|
126
|
+
// rewrite the paragraph it contradicts. Absent on a one-shot turn and
|
|
127
|
+
// on the first turn of a session, which is how the dashboard knows
|
|
128
|
+
// there is nothing above to revise.
|
|
129
|
+
previousAnswer: context.previous?.answer,
|
|
130
|
+
previousQuestion: context.previous?.question,
|
|
131
|
+
// BLI-3755: who is reading this answer. A `--json` turn is a
|
|
132
|
+
// PROGRAM's, so the coding arm withholds its approval code and
|
|
133
|
+
// answers with a proposal id instead; an interactive turn is a
|
|
134
|
+
// person's and is unchanged. `--show-approval-code` opts a script
|
|
135
|
+
// back in, and says so on stderr below.
|
|
136
|
+
surface: agentSurface(context.command) ? "agent" : undefined,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Reads the turn off the wire, drawing live words and trace rows as they land.
|
|
141
|
+
* `liveTraceLines` is a function because the count keeps growing until the
|
|
142
|
+
* stream ends; it is read once, after.
|
|
143
|
+
*/
|
|
144
|
+
async function readStreamedTurn(context, io, sent, startedAt, log) {
|
|
86
145
|
// Live trace lines go to a person as they land, never to a `--json`
|
|
87
146
|
// consumer: that contract is exactly one object on stdout, so the events are
|
|
88
147
|
// buffered and folded into the final payload instead. The same rule governs
|
|
89
148
|
// the answer's own words (BLI-3517): `--json` stays exactly one object.
|
|
90
149
|
let liveTraceLines = 0;
|
|
91
150
|
const live = createLiveAnswer(context.command, io);
|
|
92
|
-
const turn = await readTowerTurn(
|
|
151
|
+
const turn = await readTowerTurn(sent.response, {
|
|
93
152
|
startedAt,
|
|
94
153
|
log,
|
|
95
154
|
onActivity: (event) => {
|
|
@@ -122,142 +181,9 @@ export async function sendOneTurn(context, prompt, io) {
|
|
|
122
181
|
if (!turn.ok) {
|
|
123
182
|
live.abandon();
|
|
124
183
|
writeFailure(context.command, io, turn.reason, streamFailureDetail(turn.reason, turn.detail));
|
|
125
|
-
return {
|
|
126
|
-
}
|
|
127
|
-
const body = turn.final;
|
|
128
|
-
const httpStatus = typeof turn.final.httpStatus === "number" ? turn.final.httpStatus : requested.response.status;
|
|
129
|
-
if (httpStatus >= 400 || !body.ok || !body.reply) {
|
|
130
|
-
live.abandon();
|
|
131
|
-
const reason = body.error ?? body.reply ?? `http_${httpStatus}`;
|
|
132
|
-
writeFailure(context.command, io, "turn_failed", reason);
|
|
133
|
-
return { exitCode: 1, reply: null };
|
|
184
|
+
return { ok: false };
|
|
134
185
|
}
|
|
135
|
-
|
|
136
|
-
// because it already sent every step live; the activity we collected is that
|
|
137
|
-
// same trace, so `--json` still gets one.
|
|
138
|
-
const trace = body.trace ?? activityToTrace(turn.activity);
|
|
139
|
-
// BLI-3560: bookmark this turn so `cockpit jarvis --trace last` can open its
|
|
140
|
-
// step tree. Written before the reply is printed for no reason other than
|
|
141
|
-
// keeping the failure — which is only ever a stderr line — above the answer
|
|
142
|
-
// rather than after it.
|
|
143
|
-
await rememberTurnTrace({ traceId: body.traceId ?? null, threadId: body.traceThread ?? null }, io, context.command.homeDir);
|
|
144
|
-
if (context.command.json) {
|
|
145
|
-
writeLine(io.stdout, JSON.stringify({
|
|
146
|
-
// BLI-3732: the shared envelope FIRST — `answer`, `sources`,
|
|
147
|
-
// `turn_id`, `thread_id`, `trace_thread_id`, `degraded`,
|
|
148
|
-
// `degraded_reasons` — so a script here and an agent on the
|
|
149
|
-
// `jarvis_ask` MCP tool read one contract for one turn. The keys
|
|
150
|
-
// below it are the ones this command has always printed and are
|
|
151
|
-
// untouched; `reply` and `answer` are the same string.
|
|
152
|
-
...buildJarvisAnswerEnvelope({
|
|
153
|
-
reply: body.reply,
|
|
154
|
-
thread: body.thread ?? context.command.thread,
|
|
155
|
-
traceId: body.traceId,
|
|
156
|
-
traceThread: body.traceThread,
|
|
157
|
-
modelFallback: body.model?.fallback,
|
|
158
|
-
revised: body.revised,
|
|
159
|
-
trace,
|
|
160
|
-
proposalId: body.proposalId,
|
|
161
|
-
// BLI-3787: the sentence beside it — what a person must do next when
|
|
162
|
-
// the arm proposed something, and when it refused instead.
|
|
163
|
-
nextAction: body.nextAction,
|
|
164
|
-
// BLI-3770: the door's own structured citations. Absent from a
|
|
165
|
-
// dashboard that predates it, and the envelope falls back to
|
|
166
|
-
// reading the answer's own `Source:` lines when it is.
|
|
167
|
-
sources: body.sources,
|
|
168
|
-
}),
|
|
169
|
-
reply: body.reply,
|
|
170
|
-
thread: body.thread ?? context.command.thread,
|
|
171
|
-
model: body.model ?? null,
|
|
172
|
-
trace,
|
|
173
|
-
subject: body.subject ?? null,
|
|
174
|
-
// BLI-3582: the server's own split of the wait. `null` from a
|
|
175
|
-
// dashboard that does not measure it yet.
|
|
176
|
-
latency: latencyFields(body.latency),
|
|
177
|
-
// BLI-3591: this side's own half of the same wait, so a consumer can
|
|
178
|
-
// put the whole journey together without a stopwatch of its own.
|
|
179
|
-
clientLatency: {
|
|
180
|
-
bootMs: context.boot.bootMs,
|
|
181
|
-
sessionMs: context.boot.sessionMs,
|
|
182
|
-
promptMs: context.boot.promptMs,
|
|
183
|
-
preRequestMs,
|
|
184
|
-
respondedMs: requested.respondedMs,
|
|
185
|
-
firstByteMs: turn.timing.firstByteMs,
|
|
186
|
-
firstFrameMs: turn.timing.firstFrameMs,
|
|
187
|
-
firstTokenMs: turn.timing.firstTokenMs,
|
|
188
|
-
elapsedMs: Date.now() - startedAt,
|
|
189
|
-
},
|
|
190
|
-
...(body.traceId ? { traceId: body.traceId } : {}),
|
|
191
|
-
}));
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
const subject = body.subject?.displayName ? ` (${body.subject.displayName})` : "";
|
|
195
|
-
// BLI-3517: when the answer streamed, `settle` prints only what the live
|
|
196
|
-
// words did not already say — and says so out loud when the grounding gate
|
|
197
|
-
// took some of them back. When nothing streamed it prints the whole reply
|
|
198
|
-
// through `writeReply`, which is byte-for-byte what this command printed
|
|
199
|
-
// before, BLI-3570's dim link line included.
|
|
200
|
-
live.settle(body.reply, subject, body.revised === true);
|
|
201
|
-
// BLI-3567: what the correction did to the answer above, printed under
|
|
202
|
-
// this turn's reply because that is the only place a terminal has.
|
|
203
|
-
if (body.revision)
|
|
204
|
-
writeRevision(context.command, io, body.revision);
|
|
205
|
-
// Only when nothing was drawn live — otherwise every tool would print twice.
|
|
206
|
-
if (liveTraceLines === 0)
|
|
207
|
-
writeTraceBlock(io, trace);
|
|
208
|
-
writeModelReceipt(io, body.model);
|
|
209
|
-
}
|
|
210
|
-
writeLine(io.stderr, `[jarvis cli] answered ${JSON.stringify({
|
|
211
|
-
prompt_length: prompt.length,
|
|
212
|
-
reply_length: body.reply.length,
|
|
213
|
-
trace_steps: trace?.length ?? 0,
|
|
214
|
-
trace_failed: trace?.filter((step) => step.status === "failed").length ?? 0,
|
|
215
|
-
model_requested: context.command.model ?? null,
|
|
216
|
-
elapsed_ms: Date.now() - startedAt,
|
|
217
|
-
// BLI-3786: `minted` is a conversation the DOOR opened for this call
|
|
218
|
-
// because nothing named one — read off the answer rather than guessed
|
|
219
|
-
// from the name, so this side keeps no copy of the server's rule. Never
|
|
220
|
-
// the thread name itself.
|
|
221
|
-
thread: body.thread && body.thread !== context.command.thread
|
|
222
|
-
? "minted"
|
|
223
|
-
: context.command.thread === "main"
|
|
224
|
-
? "default"
|
|
225
|
-
: "named",
|
|
226
|
-
subject: context.command.subject ? "selected" : "caller",
|
|
227
|
-
image_attached: attachment !== null,
|
|
228
|
-
image_byte_size: attachment?.bytes.byteLength ?? null,
|
|
229
|
-
streamed: turn.streamed,
|
|
230
|
-
live_trace_lines: liveTraceLines,
|
|
231
|
-
// BLI-3517: whether the words arrived live, and whether the settled
|
|
232
|
-
// answer superseded them. `streamed_chars: 0` against a streaming
|
|
233
|
-
// dashboard means the answer landed all at once.
|
|
234
|
-
streamed_chars: turn.draft.length,
|
|
235
|
-
revised: body.revised === true,
|
|
236
|
-
// BLI-3567: whether this turn was told there was an answer above it, and
|
|
237
|
-
// what the correction did to it. `sent_previous_answer: false` is a
|
|
238
|
-
// one-shot turn; a status with no revision at all is a dashboard that
|
|
239
|
-
// predates the step.
|
|
240
|
-
sent_previous_answer: Boolean(context.previous),
|
|
241
|
-
revision: body.revision?.status ?? null,
|
|
242
|
-
revision_reason: body.revision?.reason ?? null,
|
|
243
|
-
// BLI-3582: `elapsed_ms` above is the whole wait as this side felt it;
|
|
244
|
-
// these three say which part of it was the dashboard's prep, which was
|
|
245
|
-
// the model's first token, and how long the socket stayed silent before
|
|
246
|
-
// the first byte. All null against a dashboard that does not send them.
|
|
247
|
-
...latencyLogFields(body.latency),
|
|
248
|
-
// BLI-3591: the terminal's own half, on the same line, so the gap
|
|
249
|
-
// between the dashboard's first token and the first character a person
|
|
250
|
-
// sees stops being a mystery with nobody's name on it. `boot_ms` and
|
|
251
|
-
// `session_ms` are process facts (identical on every turn of an
|
|
252
|
-
// interactive session); the rest are this turn's, measured from the
|
|
253
|
-
// moment the turn started.
|
|
254
|
-
...clientTimingFields(context.boot, {
|
|
255
|
-
preRequestMs,
|
|
256
|
-
respondedMs: requested.respondedMs,
|
|
257
|
-
timing: turn.timing,
|
|
258
|
-
}),
|
|
259
|
-
})}`);
|
|
260
|
-
return { exitCode: 0, reply: body.reply };
|
|
186
|
+
return { ok: true, turn, live, liveTraceLines: () => liveTraceLines };
|
|
261
187
|
}
|
|
262
188
|
/**
|
|
263
189
|
* `--threads` and `--thread <name> --history`.
|
package/dist/commands/jarvis.js
CHANGED
|
@@ -57,29 +57,38 @@ export async function runJarvis(command, io) {
|
|
|
57
57
|
homeDir: command.homeDir,
|
|
58
58
|
}, io);
|
|
59
59
|
}
|
|
60
|
+
const connection = { dashboardUrl, deviceToken: session.device_token, bootMs, sessionMs };
|
|
60
61
|
const promptStartedAt = Date.now();
|
|
61
62
|
const oneShotPrompt = await resolveOneShotPrompt(command, io);
|
|
62
63
|
if (oneShotPrompt !== null) {
|
|
63
|
-
|
|
64
|
-
// answer — so it sends no previous answer and nothing is ever revised. The
|
|
65
|
-
// `sent_previous_answer: false` field on the answered line says so.
|
|
66
|
-
const turn = await sendOneTurn({
|
|
67
|
-
command,
|
|
68
|
-
dashboardUrl,
|
|
69
|
-
deviceToken: session.device_token,
|
|
70
|
-
boot: {
|
|
71
|
-
bootMs,
|
|
72
|
-
sessionMs,
|
|
73
|
-
// Only meaningful when the question was piped; an argument costs
|
|
74
|
-
// nothing to read and reporting a stdin wait for it would be a lie.
|
|
75
|
-
promptMs: command.prompt ? null : Date.now() - promptStartedAt,
|
|
76
|
-
},
|
|
77
|
-
}, oneShotPrompt, io);
|
|
78
|
-
return turn.exitCode;
|
|
64
|
+
return sendOneShotTurn(command, io, connection, oneShotPrompt, promptStartedAt);
|
|
79
65
|
}
|
|
80
66
|
if (command.json) {
|
|
81
67
|
throw new Error("cockpit jarvis --json needs --prompt, positional text, or piped stdin.");
|
|
82
68
|
}
|
|
69
|
+
return chatInTerminal(command, io, connection);
|
|
70
|
+
}
|
|
71
|
+
async function sendOneShotTurn(command, io, connection, prompt, promptStartedAt) {
|
|
72
|
+
// A one-shot turn has nothing above it — this process printed no earlier
|
|
73
|
+
// answer — so it sends no previous answer and nothing is ever revised. The
|
|
74
|
+
// `sent_previous_answer: false` field on the answered line says so.
|
|
75
|
+
const turn = await sendOneTurn({
|
|
76
|
+
command,
|
|
77
|
+
dashboardUrl: connection.dashboardUrl,
|
|
78
|
+
deviceToken: connection.deviceToken,
|
|
79
|
+
boot: {
|
|
80
|
+
bootMs: connection.bootMs,
|
|
81
|
+
sessionMs: connection.sessionMs,
|
|
82
|
+
// Only meaningful when the question was piped; an argument costs
|
|
83
|
+
// nothing to read and reporting a stdin wait for it would be a lie.
|
|
84
|
+
promptMs: command.prompt ? null : Date.now() - promptStartedAt,
|
|
85
|
+
},
|
|
86
|
+
}, prompt, io);
|
|
87
|
+
return turn.exitCode;
|
|
88
|
+
}
|
|
89
|
+
/** The interactive loop: read a line, send it as a turn, repeat until `/exit`. */
|
|
90
|
+
async function chatInTerminal(command, io, connection) {
|
|
91
|
+
const { dashboardUrl, deviceToken, bootMs, sessionMs } = connection;
|
|
83
92
|
writeLine(io.stdout, "JARVIS terminal chat. Type /exit to leave.");
|
|
84
93
|
// BLI-3567: the answer this session last printed, and the question it
|
|
85
94
|
// answered. It is what a correction typed on the next line can rewrite —
|
|
@@ -97,7 +106,7 @@ export async function runJarvis(command, io) {
|
|
|
97
106
|
const turn = await sendOneTurn({
|
|
98
107
|
command,
|
|
99
108
|
dashboardUrl,
|
|
100
|
-
deviceToken
|
|
109
|
+
deviceToken,
|
|
101
110
|
// The typing wait belongs to the person, not to the turn, so no prompt
|
|
102
111
|
// span is reported for an interactive turn.
|
|
103
112
|
boot: { bootMs, sessionMs, promptMs: null },
|