@carrieros/cli 0.3.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 +34 -13
- package/dist/commands/chat.js +3 -3
- package/dist/commands/context.js +40 -0
- package/dist/commands/doctor.js +27 -12
- package/dist/commands/logout.js +1 -0
- package/dist/commands/permissions.js +77 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/sessions.js +5 -0
- package/dist/commands/settings.js +8 -1
- package/dist/commands/update.js +79 -9
- package/dist/commands/usage.js +5 -5
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +115 -12
- package/dist/ide/ide-session.js +274 -13
- package/dist/ide/tool-host.js +2 -2
- package/dist/main.js +0 -0
- package/dist/services/api.js +178 -12
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/chat-stream.js +26 -3
- package/dist/services/checkpoints.js +176 -14
- package/dist/services/client-tools.js +113 -21
- package/dist/services/code-intel.js +243 -0
- package/dist/services/code-symbols.js +94 -0
- package/dist/services/coding-workflow.js +554 -0
- package/dist/services/command-coordinator.js +85 -12
- package/dist/services/command-policy.js +34 -4
- package/dist/services/config.js +67 -5
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +45 -17
- package/dist/services/device-auth.js +30 -5
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-resolver.js +1 -1
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +181 -0
- package/dist/services/helper-bin.js +56 -35
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +31 -10
- package/dist/services/local-files.js +148 -26
- package/dist/services/local-tools.js +540 -35
- package/dist/services/login-flow.js +43 -12
- package/dist/services/mutation-coordinator.js +186 -20
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +264 -78
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +15 -0
- package/dist/services/permission-mode.js +60 -0
- package/dist/services/process-runner.js +7 -1
- package/dist/services/project-context.js +4 -4
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +21 -1
- package/dist/services/session-resolver.js +5 -0
- package/dist/services/supported-runtime.js +59 -0
- package/dist/services/task-context.js +212 -0
- package/dist/services/task-snapshot.js +38 -0
- package/dist/services/tool-result-outbox.js +195 -0
- package/dist/services/update.js +37 -12
- package/dist/services/workspace-registry.js +4 -3
- package/dist/services/workspace.js +8 -1
- package/dist/shell/shell-chat.js +299 -32
- package/dist/shell/shell-commands.js +46 -4
- package/dist/shell/shell-prompt.js +21 -11
- package/dist/shell/shell-renderer.js +1 -1
- package/dist/shell/shell.js +69 -7
- package/dist/shell/task-context-view.js +40 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +46 -16
- package/dist/ui/banner.js +31 -87
- package/dist/ui/change-review.js +293 -46
- package/dist/ui/chat-renderer.js +6 -6
- package/dist/ui/colors.js +9 -9
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-palette.js +27 -10
- package/dist/ui/command-registry.js +9 -2
- package/dist/ui/command-review.js +77 -28
- package/dist/ui/composer-layout.js +26 -20
- package/dist/ui/conversation.js +77 -25
- package/dist/ui/live.js +1 -1
- package/dist/ui/screen.js +19 -11
- package/dist/ui/select.js +6 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/trust.js +7 -12
- package/dist/ui/ui.js +23 -0
- package/package.json +8 -5
package/dist/shell/shell-chat.js
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { rememberCommandDetails, clearCommandDetails } from "../ui/command-details.js";
|
|
2
|
+
import { getPermissionMode, permissionModeLabel, permissionPolicy, rememberPermissionMode } from "../services/permission-mode.js";
|
|
3
|
+
import { analysisExplanation, renderAgentPlan, renderAgentOutcome, renderFailureAnalysis, workflowActivity, toolActivity } from "../ui/agent-presentation.js";
|
|
4
|
+
import { ActiveChangeView } from "../ui/change-review.js";
|
|
5
|
+
import { screenTask } from "../ui/screen.js";
|
|
6
|
+
import { CodingWorkflow } from "../services/coding-workflow.js";
|
|
7
|
+
import { TurnReadCache } from "../services/local-tools.js";
|
|
8
|
+
import { containerRuntime, verifyContainerRuntime } from "../services/container-runner.js";
|
|
9
|
+
import { executionContract } from "../services/execution-platform.js";
|
|
10
|
+
import { ensureJobHelper } from "../services/job-helper.js";
|
|
1
11
|
import fs from "node:fs";
|
|
2
12
|
import path from "node:path";
|
|
3
13
|
import chalk from "chalk";
|
|
4
14
|
import { ApiError } from "../services/api.js";
|
|
15
|
+
import { PROVIDER_ERROR_REASONS } from "../services/chat-stream.js";
|
|
5
16
|
import { capitalize, errorLine, info, line, success } from "../services/output.js";
|
|
6
17
|
import { detectLocalFiles } from "../services/file-detect.js";
|
|
7
18
|
import { fileTypeLabel, formatSize, uploadAndAttach, UploadError } from "../services/file-upload.js";
|
|
@@ -12,13 +23,13 @@ import { declaredClientTools, declaredCommandTools, declaredMutationTools, handl
|
|
|
12
23
|
import { APPROVAL_TIMEOUT_MS } from "../services/mutations.js";
|
|
13
24
|
import { createRenderer, toolKind, toolSummary } from "../ui/conversation.js";
|
|
14
25
|
import { watchForInterrupt } from "../ui/interrupt.js";
|
|
15
|
-
import { renderChangeSummary, renderGroup } from "../ui/change-review.js";
|
|
26
|
+
import { renderChangeRejected, renderChangeSummary, renderGroup, renderNoLongerValid, renderValidationFailed } from "../ui/change-review.js";
|
|
16
27
|
import { approveInScreen } from "../ui/screen-prompt.js";
|
|
17
28
|
import { createMutationCoordinator } from "../services/mutation-coordinator.js";
|
|
18
29
|
import { createCommandCoordinator } from "../services/command-coordinator.js";
|
|
19
30
|
import { displayCommand } from "../services/command-policy.js";
|
|
20
31
|
import { workspaceRoot } from "../services/local-files.js";
|
|
21
|
-
import { renderCommandReview, renderCommandSummary } from "../ui/command-review.js";
|
|
32
|
+
import { parseTestReport, renderCommandReview, renderCommandSummary, summariseOutput } from "../ui/command-review.js";
|
|
22
33
|
import { checkUrl, openUrl } from "../services/open-url.js";
|
|
23
34
|
import { renderAllSources, renderComplete, memoryMarkerLine, renderCompleteLive, renderError, renderSources, renderSourcesLive, renderUserMessage, searchCompletionLine, startThinking, streamAssistant } from "../ui/chat-renderer.js";
|
|
24
35
|
import { startLiveComposer } from "../ui/live.js";
|
|
@@ -26,6 +37,10 @@ import { pickFromList } from "../ui/select.js";
|
|
|
26
37
|
import { clarifyIntent } from "../ui/sia-qa.js";
|
|
27
38
|
import { parseSiaContext } from "../services/sia.js";
|
|
28
39
|
import { isMemoryMarker } from "../types/index.js";
|
|
40
|
+
import { TaskFileLedger, repositoryContext, repositoryState } from "../services/task-context.js";
|
|
41
|
+
import { getWorkspace } from "../services/workspace.js";
|
|
42
|
+
import { renderTaskContextRestored } from "../ui/task-context-card.js";
|
|
43
|
+
import { fetchTaskContext } from "./task-context-view.js";
|
|
29
44
|
// Shared by the `chat` command REPL and the interactive shell so chat, mode and
|
|
30
45
|
// model logic lives in exactly one place (no duplicated business logic).
|
|
31
46
|
export const AUTO_LABEL = "Auto (mode default)";
|
|
@@ -41,8 +56,27 @@ export async function loadModels(client) {
|
|
|
41
56
|
export function currentModelId(ctx) {
|
|
42
57
|
return ctx.config.get("model") ?? "";
|
|
43
58
|
}
|
|
44
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The model Fast Mode runs on — the admin's choice, as the server names it
|
|
61
|
+
* (GET /v1/chat/availability), e.g. "Qwen 3.8 27B". Null when the server can't
|
|
62
|
+
* serve Fast Mode; undefined until asked.
|
|
63
|
+
*/
|
|
64
|
+
let fastModelCache;
|
|
65
|
+
export async function loadFastModel(client) {
|
|
66
|
+
if (fastModelCache !== undefined)
|
|
67
|
+
return fastModelCache;
|
|
68
|
+
const fm = (await client.chatAvailability().catch(() => null))?.fast_mode;
|
|
69
|
+
fastModelCache = fm?.available && fm.model ? { id: fm.model, label: fm.label || fm.model } : null;
|
|
70
|
+
return fastModelCache;
|
|
71
|
+
}
|
|
72
|
+
/** Fast Mode is on and in effect (Standard chat only). */
|
|
73
|
+
export function fastInEffect(ctx) {
|
|
74
|
+
return ctx.fast && ctx.chatType === "standard";
|
|
75
|
+
}
|
|
76
|
+
/** Short label for the prompt/banner ("Auto" or e.g. "GPT-5.5"); with Fast Mode on, the Fast model. */
|
|
45
77
|
export function modelLabelShort(ctx) {
|
|
78
|
+
if (fastInEffect(ctx) && fastModelCache)
|
|
79
|
+
return fastModelCache.label;
|
|
46
80
|
const id = currentModelId(ctx);
|
|
47
81
|
if (!id)
|
|
48
82
|
return "Auto";
|
|
@@ -86,6 +120,7 @@ const ERROR_HINTS = {
|
|
|
86
120
|
// roomier model is the other.
|
|
87
121
|
MCAI_BLOCKED: "/new",
|
|
88
122
|
SESSION_NOT_FOUND: "/sessions",
|
|
123
|
+
CARRIER_CHAT_MAINTENANCE: "/switch standard",
|
|
89
124
|
// Out of credit on this model — pick another rather than retrying into the
|
|
90
125
|
// same wall. (The server substitutes when it can; this is when it couldn't.)
|
|
91
126
|
PROVIDER_EXHAUSTED: "/model",
|
|
@@ -193,7 +228,8 @@ function errorDetail(err) {
|
|
|
193
228
|
if (err.code === "INSUFFICIENT_CREDITS") {
|
|
194
229
|
return "Nothing was charged for this message.";
|
|
195
230
|
}
|
|
196
|
-
|
|
231
|
+
// The server's structured reason names the kind of provider failure.
|
|
232
|
+
return err.reason ? `${PROVIDER_ERROR_REASONS[err.reason]} · Error code: ${err.code}` : `Error code: ${err.code}`;
|
|
197
233
|
}
|
|
198
234
|
/** Render an API failure with its cause and the command that addresses it. */
|
|
199
235
|
function renderApiError(err) {
|
|
@@ -205,11 +241,48 @@ function renderApiError(err) {
|
|
|
205
241
|
renderError("Something went wrong", err.message);
|
|
206
242
|
return;
|
|
207
243
|
}
|
|
244
|
+
if (err.code === "CARRIER_CHAT_MAINTENANCE") {
|
|
245
|
+
showCarrierMaintenance();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
208
248
|
// Running out of credits is a state to act on, not a fault — a red × made a
|
|
209
249
|
// billing prompt look like a crash.
|
|
210
250
|
const tone = err.code === "INSUFFICIENT_CREDITS" ? "warn" : "error";
|
|
211
251
|
renderError(errorTitle(err), errorDetail(err), ERROR_HINTS[err.code], tone);
|
|
212
252
|
}
|
|
253
|
+
/** The API owns availability and session identity. A stored Standard session
|
|
254
|
+
* cannot be continued under a Carrier label (or vice versa). The old chat is
|
|
255
|
+
* untouched and remains available through /sessions. */
|
|
256
|
+
export async function syncChatAvailability(ctx, client) {
|
|
257
|
+
const sessionId = ctx.config.get("sessionId");
|
|
258
|
+
const state = await client.chatAvailability(sessionId);
|
|
259
|
+
ctx.carrierMaintenance = state.carrier_chat_maintenance;
|
|
260
|
+
if (sessionId && state.session_chat_type !== ctx.chatType) {
|
|
261
|
+
ctx.config.set("sessionId", undefined);
|
|
262
|
+
ctx.config.set("sessionTitle", undefined);
|
|
263
|
+
line(" " + c.warn("⚠") + " " + c.dim("The saved chat belongs to another chat type. It remains in /sessions; a new chat will start here."));
|
|
264
|
+
}
|
|
265
|
+
return state;
|
|
266
|
+
}
|
|
267
|
+
export function showCarrierMaintenance() {
|
|
268
|
+
renderError("Carrier Chat is under maintenance", "Sending is paused while we upgrade it. You can still read existing chats. It'll be back — and a lot more powerful.", "/switch standard", "warn");
|
|
269
|
+
}
|
|
270
|
+
/** Checks immediately before any model turn; the initial shell banner is only
|
|
271
|
+
* advisory, because the admin can change the switch while the CLI stays open. */
|
|
272
|
+
async function allowChatTurn(ctx, client) {
|
|
273
|
+
try {
|
|
274
|
+
const state = await syncChatAvailability(ctx, client);
|
|
275
|
+
if (ctx.chatType === "carrier" && state.carrier_chat_maintenance) {
|
|
276
|
+
showCarrierMaintenance();
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
renderApiError(err);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
213
286
|
/**
|
|
214
287
|
* Cache a newly-created conversation's title for the footer. Best-effort and
|
|
215
288
|
* deliberately un-awaited — a title is cosmetic, so it must never delay a reply
|
|
@@ -319,6 +392,8 @@ function withProjectContext(ctx, message) {
|
|
|
319
392
|
}
|
|
320
393
|
}
|
|
321
394
|
export async function chatTurn(ctx, client, message, opts = {}) {
|
|
395
|
+
if (!(await allowChatTurn(ctx, client)))
|
|
396
|
+
return;
|
|
322
397
|
// SIA rewrites the prompt, so it has to resolve before EITHER render path
|
|
323
398
|
// starts — the merged text is what gets echoed, sent and stored. A read-only
|
|
324
399
|
// task (a review) is fixed, not an ambiguous request, so it never clarifies.
|
|
@@ -339,7 +414,7 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
339
414
|
}
|
|
340
415
|
message = result.prompt;
|
|
341
416
|
}
|
|
342
|
-
const useLiveBar = opts.footer !== undefined && process.stdout.isTTY;
|
|
417
|
+
const useLiveBar = opts.footer !== undefined && process.stdout.isTTY && process.env.TERM !== "dumb";
|
|
343
418
|
if (useLiveBar) {
|
|
344
419
|
await chatTurnLive(ctx, client, message, opts.footer ?? "", opts.webSearch, echoed, opts.signal, { readOnly: opts.readOnly, sendAs: opts.sendAs });
|
|
345
420
|
return;
|
|
@@ -387,6 +462,7 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
387
462
|
// Persist the session so the conversation continues across turns/invocations.
|
|
388
463
|
if (result.session_id && result.session_id !== sessionId) {
|
|
389
464
|
ctx.config.set("sessionId", result.session_id);
|
|
465
|
+
rememberPermissionMode(ctx.config);
|
|
390
466
|
// The chat response carries no title, and the backend generates one from
|
|
391
467
|
// the first message — fetch it once, in the background, so the footer can
|
|
392
468
|
// name the conversation without delaying the reply. Failure is silent:
|
|
@@ -415,7 +491,10 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
415
491
|
}
|
|
416
492
|
catch (err) {
|
|
417
493
|
spinner.stop();
|
|
418
|
-
|
|
494
|
+
if (signal.aborted)
|
|
495
|
+
line(" ⊘ Cancelled — the turn stopped.");
|
|
496
|
+
else
|
|
497
|
+
renderApiError(err);
|
|
419
498
|
}
|
|
420
499
|
finally {
|
|
421
500
|
// Always detach, so the composer's own Ctrl+C (arm-then-exit) works again.
|
|
@@ -423,9 +502,11 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
423
502
|
}
|
|
424
503
|
}
|
|
425
504
|
/** What the prompt asks, in the plan's own terms. */
|
|
426
|
-
function approvalQuestion(plans) {
|
|
505
|
+
function approvalQuestion(plans, correction = false) {
|
|
506
|
+
if (correction)
|
|
507
|
+
return plans.length > 1 ? `Approve all ${plans.length} corrective changes?` : "Approve this correction?";
|
|
427
508
|
if (plans.length > 1)
|
|
428
|
-
return `
|
|
509
|
+
return `Approve all ${plans.length} changes?`;
|
|
429
510
|
switch (plans[0]?.name) {
|
|
430
511
|
case "revert_change":
|
|
431
512
|
return "Undo this change?";
|
|
@@ -434,7 +515,7 @@ function approvalQuestion(plans) {
|
|
|
434
515
|
case "create_file":
|
|
435
516
|
return "Create this file?";
|
|
436
517
|
default:
|
|
437
|
-
return "
|
|
518
|
+
return "Approve this change?";
|
|
438
519
|
}
|
|
439
520
|
}
|
|
440
521
|
/** "Running the project tests" reads better than the argv on an activity line. */
|
|
@@ -464,6 +545,7 @@ turnOpts = {}) {
|
|
|
464
545
|
const model = currentModelId(ctx);
|
|
465
546
|
const sessionId = ctx.config.get("sessionId");
|
|
466
547
|
const webSearch = webSearchOverride ?? ctx.effectiveWebSearch;
|
|
548
|
+
clearCommandDetails(ctx);
|
|
467
549
|
const live = startLiveComposer(footer);
|
|
468
550
|
// One owner for everything this turn draws: the user's message, activity,
|
|
469
551
|
// approval cards, command output and the answer (see ui/conversation.ts).
|
|
@@ -503,23 +585,99 @@ turnOpts = {}) {
|
|
|
503
585
|
};
|
|
504
586
|
// A read-only turn (a review) offers NEITHER mutation nor command tools, so
|
|
505
587
|
// the model cannot change files or run commands whatever the prompt says.
|
|
506
|
-
|
|
588
|
+
// Plan mode uses the same gate. The mode is fixed for the turn, so switching
|
|
589
|
+
// it while a review is open never changes what this turn may do.
|
|
590
|
+
const permission = permissionPolicy(getPermissionMode(ctx.config));
|
|
591
|
+
const mutationTools = turnOpts.readOnly || !permission.changeTools ? undefined : declaredMutationTools(ctx);
|
|
592
|
+
const commandTools = turnOpts.readOnly || !permission.commands ? undefined : declaredCommandTools(ctx);
|
|
593
|
+
let taskView;
|
|
594
|
+
// What the final card needs that the workflow snapshot does not carry: why a
|
|
595
|
+
// change stopped (from the coordinator's recorded result codes) and the last
|
|
596
|
+
// validation's counts (from the actual command output). Display only.
|
|
597
|
+
const turnOutcome = {};
|
|
598
|
+
// Complete reads delivered to the model this turn. Tool results are not
|
|
599
|
+
// replayed into later turns, so reuse never outlives the turn.
|
|
600
|
+
const readCache = new TurnReadCache();
|
|
601
|
+
const workflow = mutationTools ? new CodingWorkflow(async () => {
|
|
602
|
+
if (!commandTools)
|
|
603
|
+
throw new Error("Secure verification commands are unavailable. Enable local commands and configure the required runtime before planning changes.");
|
|
604
|
+
const contract = executionContract();
|
|
605
|
+
if (contract.capability === "UNSUPPORTED")
|
|
606
|
+
throw new Error(contract.prerequisite);
|
|
607
|
+
if (contract.capability === "ISOLATED_RUNTIME_REQUIRED")
|
|
608
|
+
await verifyContainerRuntime(containerRuntime());
|
|
609
|
+
else
|
|
610
|
+
ensureJobHelper();
|
|
611
|
+
return contract;
|
|
612
|
+
}, lines => {
|
|
613
|
+
// Close the investigation step first, so its record sits ABOVE the plan it led to.
|
|
614
|
+
if (lines[0]?.startsWith("Plan:")) {
|
|
615
|
+
ui.stepEnd();
|
|
616
|
+
const snap = workflow.snapshot();
|
|
617
|
+
if (!turnOutcome.task && !Number(snap.corrections))
|
|
618
|
+
turnOutcome.task = snap.plan?.summary;
|
|
619
|
+
ui.commit(renderAgentPlan(snap, { rootCause: turnOutcome.rootCause }));
|
|
620
|
+
}
|
|
621
|
+
else if (lines[0]?.startsWith("Failure analysis")) {
|
|
622
|
+
ui.stepEnd();
|
|
623
|
+
turnOutcome.rootCause = analysisExplanation(lines).explanation;
|
|
624
|
+
ui.commit(renderFailureAnalysis(lines));
|
|
625
|
+
}
|
|
626
|
+
taskView?.refresh();
|
|
627
|
+
}, { signal, recoveryScope: () => client.mutationRecoveryScope(), onReadsInvalidated: () => readCache.invalidate() }) : undefined;
|
|
628
|
+
taskView = workflow ? new ActiveChangeView(() => workflow.snapshot(), screenTask) : undefined;
|
|
507
629
|
const mutations = mutationTools
|
|
508
630
|
? createMutationCoordinator({
|
|
509
|
-
|
|
631
|
+
signal,
|
|
632
|
+
approvalContext: () => workflow?.approvalContext(),
|
|
633
|
+
recoveryScope: () => client.mutationRecoveryScope(),
|
|
634
|
+
validatePlans: plans => workflow?.beforeMutation(plans),
|
|
635
|
+
approveEditsByPolicy: () => permission.approveEditsByPolicy,
|
|
636
|
+
// Recorded before delivery: an immediate reply finds the change already recorded.
|
|
637
|
+
record: payload => workflow?.mutationResult(payload),
|
|
638
|
+
submit: async (payload) => {
|
|
639
|
+
await submitWithRetry(client, payload);
|
|
640
|
+
taskView?.result(payload);
|
|
641
|
+
const code = payload.ok ? undefined : payload.error?.code;
|
|
642
|
+
if (code === "MUTATION_REJECTED" || code === "STALE_FILE") {
|
|
643
|
+
turnOutcome.declined = code === "MUTATION_REJECTED" ? "rejected" : "invalidated";
|
|
644
|
+
turnOutcome.declinedOperations = [...(turnOutcome.declinedOperations ?? []), payload.tool_call_id];
|
|
645
|
+
}
|
|
646
|
+
},
|
|
510
647
|
ui: {
|
|
511
648
|
review: (plans) => withTerminal(() => ui.borrow(async () => {
|
|
512
649
|
ui.stepEnd();
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
650
|
+
taskView?.review(plans);
|
|
651
|
+
const snapshot = workflow?.snapshot();
|
|
652
|
+
const planned = snapshot?.plan?.files ?? [];
|
|
653
|
+
const applied = (snapshot?.files ?? []);
|
|
654
|
+
const remaining = planned.filter(file => !applied.includes(file.path) && !plans.some(plan => plan.rel === file.path)).length;
|
|
655
|
+
ui.commit(renderGroup(plans, Number(snapshot?.corrections ?? 0) > 0, remaining, workspaceRoot()));
|
|
656
|
+
const question = approvalQuestion(plans, Number(snapshot?.corrections ?? 0) > 0);
|
|
657
|
+
const answer = await approveInScreen({ question, timeoutMs: APPROVAL_TIMEOUT_MS, signal });
|
|
658
|
+
workflow?.approval(answer);
|
|
659
|
+
taskView?.decision(plans, answer);
|
|
660
|
+
return answer;
|
|
516
661
|
})),
|
|
662
|
+
// Accept Edits: the same review card, marked as approved by the session's
|
|
663
|
+
// policy instead of asking; the coordinator's checks still follow.
|
|
664
|
+
approvedByPolicy: (plans) => {
|
|
665
|
+
ui.stepEnd();
|
|
666
|
+
taskView?.review(plans);
|
|
667
|
+
ui.commit([...renderGroup(plans, false, 0, workspaceRoot()), " " + c.accent("✓ Approved by " + permissionModeLabel(getPermissionMode(ctx.config))) + c.dim(getPermissionMode(ctx.config) === "auto" ? " — test commands run too; writes/installs ask · /permissions to change" : " — commands still ask · /permissions to change"), ""]);
|
|
668
|
+
workflow?.approval("approve");
|
|
669
|
+
taskView?.decision(plans, "approve");
|
|
670
|
+
},
|
|
517
671
|
note: (lines) => ui.commit([...renderChangeSummary(lines), ""]),
|
|
672
|
+
noLongerValid: (rels) => { turnOutcome.declinedFiles = rels; ui.commit(renderNoLongerValid(rels)); },
|
|
673
|
+
rejected: (plans) => { turnOutcome.declinedFiles = plans.map((p) => p.rel); ui.commit(renderChangeRejected(plans)); },
|
|
674
|
+
// Refused before review (could not be planned, or blocked): say so, and why.
|
|
675
|
+
refused: (r) => ui.commit([` ${c.warn("⚠")} ${c.value("Change proposal refused")}${r.files.length ? c.dim(` · ${r.files.join(", ")}`) : ""}`, ` ${c.dim(r.message)}`, ""]),
|
|
518
676
|
cancelTurn: abort
|
|
519
677
|
}
|
|
520
678
|
})
|
|
521
679
|
: undefined;
|
|
522
|
-
|
|
680
|
+
let lastCommandOutput;
|
|
523
681
|
let commands;
|
|
524
682
|
if (commandTools) {
|
|
525
683
|
const auth = ctx.config.get("auth");
|
|
@@ -527,25 +685,73 @@ turnOpts = {}) {
|
|
|
527
685
|
root: workspaceRoot(),
|
|
528
686
|
signal,
|
|
529
687
|
withTerminal,
|
|
688
|
+
recoveryScope: () => client.mutationRecoveryScope(),
|
|
689
|
+
approvalContext: () => workflow?.approvalContext(),
|
|
530
690
|
cliSecrets: [auth?.accessToken, auth?.refreshToken, ctx.config.get("secretKey")].filter((v) => typeof v === "string"),
|
|
531
|
-
submit: (payload) =>
|
|
691
|
+
submit: async (payload) => {
|
|
692
|
+
await submitWithRetry(client, payload);
|
|
693
|
+
const wasAnalyzing = workflow?.state === "ANALYZING_FAILURE";
|
|
694
|
+
workflow?.commandResult(payload);
|
|
695
|
+
if (workflow && !wasAnalyzing && workflow.state === "ANALYZING_FAILURE")
|
|
696
|
+
ui.commit(renderValidationFailed(workflow.snapshot(), turnOutcome.validationCounts, turnOutcome.failure));
|
|
697
|
+
taskView?.refresh();
|
|
698
|
+
},
|
|
532
699
|
ui: {
|
|
533
|
-
review: (decision, reason, repository) => ui.borrow(async () => {
|
|
700
|
+
review: (decision, reason, repository, operationId) => ui.borrow(async () => {
|
|
534
701
|
ui.stepEnd();
|
|
535
|
-
|
|
702
|
+
// Auto: a contained R0/R1 command is approved by the session's policy, and says so.
|
|
703
|
+
if (permission.approveCommandByPolicy(decision.tier)) {
|
|
704
|
+
ui.commit([" " + c.ok("✓") + " " + c.dim("Auto: running ") + c.cmd(displayCommand(decision.program, decision.args)) + c.dim(" without asking (contained, " + decision.tier + ").")]);
|
|
705
|
+
return "approve";
|
|
706
|
+
}
|
|
707
|
+
taskView?.commandStatus(`Review: ${displayCommand(decision.program, decision.args)}`);
|
|
708
|
+
ui.commit(renderCommandReview(decision, reason, repository, executionContract(), workspaceRoot(), operationId));
|
|
536
709
|
return approveInScreen({ question: "Run this command?", timeoutMs: APPROVAL_TIMEOUT_MS, signal });
|
|
537
710
|
}),
|
|
538
|
-
started: (decision) =>
|
|
711
|
+
started: (decision) => {
|
|
712
|
+
taskView?.commandStatus(`Running: ${displayCommand(decision.program, decision.args)}`);
|
|
713
|
+
ui.commandStarted(commandActivityLabel(decision), displayCommand(decision.program, decision.effectiveArgs));
|
|
714
|
+
},
|
|
539
715
|
output: (_stream, text) => ui.commandOutput(text),
|
|
540
716
|
finished: ({ decision, result, errorCode, message: detail }) => {
|
|
717
|
+
if (result) {
|
|
718
|
+
turnOutcome.validationCounts = summariseOutput(result.output) || undefined;
|
|
719
|
+
turnOutcome.failure = parseTestReport(result.output).failure;
|
|
720
|
+
}
|
|
721
|
+
taskView?.commandStatus(renderCommandSummary(decision, result, errorCode, detail).join(" "));
|
|
722
|
+
if (result)
|
|
723
|
+
lastCommandOutput = result.output;
|
|
724
|
+
if (result)
|
|
725
|
+
rememberCommandDetails(ctx, JSON.stringify([client.mutationRecoveryScope(), ctx.config.get("sessionId"), workspaceRoot()]), result.output);
|
|
541
726
|
ui.commandEnded();
|
|
542
|
-
ui.commit([...renderCommandSummary(decision, result, errorCode, detail), ""]);
|
|
727
|
+
ui.commit([...renderCommandSummary(decision, result, errorCode, detail), ...(result ? [" /details shows the full bounded command output."] : []), ""]);
|
|
543
728
|
ui.status("thinking", "Working");
|
|
544
729
|
},
|
|
545
730
|
cancelTurn: abort
|
|
546
731
|
}
|
|
547
732
|
});
|
|
548
733
|
}
|
|
734
|
+
// Task Context (services/task-context.ts, server clientTools/taskContext.js).
|
|
735
|
+
// A coding turn in a conversation with earlier coding work: show that the
|
|
736
|
+
// previous task's context was restored, and tell the server which of the
|
|
737
|
+
// files it inspected changed on disk since. Context only — nothing here
|
|
738
|
+
// skips a read, restores an approval or resumes an operation.
|
|
739
|
+
const taskFiles = workflow ? new TaskFileLedger() : undefined;
|
|
740
|
+
const ownerScope = workflow ? client.mutationRecoveryScope() : undefined;
|
|
741
|
+
const repoContext = workflow ? repositoryContext(ownerScope, sessionId) : null;
|
|
742
|
+
// A different repository than the earlier work used: its file report would
|
|
743
|
+
// describe other code, so it is not sent; the server is told the repository changed.
|
|
744
|
+
const repoState = workflow && sessionId && repoContext?.same_repository !== false ? repositoryState(ownerScope, sessionId) : [];
|
|
745
|
+
if (workflow && sessionId) {
|
|
746
|
+
const restored = await fetchTaskContext(client, sessionId);
|
|
747
|
+
if (restored && !signal.aborted)
|
|
748
|
+
ui.commit(renderTaskContextRestored(restored, repoState, repoContext?.name ?? (() => { try {
|
|
749
|
+
return getWorkspace().project.name;
|
|
750
|
+
}
|
|
751
|
+
catch {
|
|
752
|
+
return undefined;
|
|
753
|
+
} })(), repoContext));
|
|
754
|
+
}
|
|
549
755
|
// request_started + request_sent: fire the real call immediately, then the
|
|
550
756
|
// brief client-side steps play over the actual wait. Settle it eagerly so a
|
|
551
757
|
// rejection during the steps is never an unhandled rejection.
|
|
@@ -566,9 +772,11 @@ turnOpts = {}) {
|
|
|
566
772
|
speed: ctx.fast ? "fast" : undefined,
|
|
567
773
|
high_power: ctx.highPower ? true : undefined,
|
|
568
774
|
file_ids: attached.length ? attached : undefined,
|
|
569
|
-
client_tools: declaredClientTools(ctx),
|
|
775
|
+
client_tools: workflow ? [...(declaredClientTools(ctx) ?? []), "coding_workflow"] : declaredClientTools(ctx),
|
|
570
776
|
client_mutation_tools: mutationTools,
|
|
571
|
-
client_command_tools: commandTools
|
|
777
|
+
client_command_tools: commandTools,
|
|
778
|
+
repository_state: repoState.length ? repoState : undefined,
|
|
779
|
+
repository_context: repoContext ?? undefined
|
|
572
780
|
}, {
|
|
573
781
|
onDelta: (delta) => {
|
|
574
782
|
if (signal.aborted)
|
|
@@ -576,15 +784,31 @@ turnOpts = {}) {
|
|
|
576
784
|
streamed += delta;
|
|
577
785
|
ui.writing(streamed.slice(shown));
|
|
578
786
|
},
|
|
579
|
-
onClientToolCall: (call) => {
|
|
787
|
+
onClientToolCall: async (call) => {
|
|
580
788
|
// Whatever the model said before asking for this tool belongs above it.
|
|
581
789
|
say();
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
790
|
+
const activity = toolActivity(call.name, call.arguments ?? {}, workspaceRoot());
|
|
791
|
+
ui.status("thinking", activity);
|
|
792
|
+
await handleClientToolCall(ctx, client, call, {
|
|
793
|
+
onStart: (_label, tool) => ui.toolStart(activity, toolKind(tool)),
|
|
794
|
+
onDone: (_label, ok, tool, detail) => {
|
|
795
|
+
if (ok)
|
|
796
|
+
taskFiles?.touch(call.name, call.arguments);
|
|
797
|
+
ui.toolEnd(activity, toolKind(tool), toolSummary(tool, ok, detail), ok);
|
|
798
|
+
taskView?.refresh();
|
|
799
|
+
if (workflow)
|
|
800
|
+
ui.status("thinking", workflowActivity(workflow.snapshot()));
|
|
801
|
+
},
|
|
802
|
+
workflow,
|
|
803
|
+
readCache,
|
|
585
804
|
mutations,
|
|
586
|
-
commands
|
|
805
|
+
commands,
|
|
806
|
+
// A refused proposal ends its step visibly, with the engine's reason.
|
|
807
|
+
onRefused: (r) => ui.toolEnd(activity, toolKind(call.name), `refused — ${r.reason}`, false)
|
|
587
808
|
});
|
|
809
|
+
taskView?.refresh();
|
|
810
|
+
if (workflow)
|
|
811
|
+
ui.status("thinking", workflowActivity(workflow.snapshot()));
|
|
588
812
|
}
|
|
589
813
|
}, signal)
|
|
590
814
|
.then((r) => ({ ok: true, r }))
|
|
@@ -592,7 +816,7 @@ turnOpts = {}) {
|
|
|
592
816
|
try {
|
|
593
817
|
// One honest line instead of a scripted checklist: the turn is waiting on
|
|
594
818
|
// the model until something real (a tool call, a delta) says otherwise.
|
|
595
|
-
ui.status("thinking", webSearch === true ? "Searching the web" : ctx.highPower ? "Thinking (high power)" : "Thinking");
|
|
819
|
+
ui.status("thinking", webSearch === true ? "Searching the web" : ctx.highPower ? "Thinking (high power)" : workflow ? "Agent is working" : "Thinking");
|
|
596
820
|
const outcome = await settled;
|
|
597
821
|
ui.stepEnd();
|
|
598
822
|
ui.stop(); // the live region is done; what remains is committed below
|
|
@@ -603,6 +827,7 @@ turnOpts = {}) {
|
|
|
603
827
|
ctx.disarmWebSearch(); // spend the one-shot arm
|
|
604
828
|
if (result.session_id && result.session_id !== sessionId) {
|
|
605
829
|
ctx.config.set("sessionId", result.session_id);
|
|
830
|
+
rememberPermissionMode(ctx.config);
|
|
606
831
|
// The chat response carries no title, and the backend generates one from
|
|
607
832
|
// the first message — fetch it once, in the background, so the footer can
|
|
608
833
|
// name the conversation without delaying the reply. Failure is silent:
|
|
@@ -614,7 +839,12 @@ turnOpts = {}) {
|
|
|
614
839
|
// staying visible the whole time. Finished lines commit above the bar.
|
|
615
840
|
const sources = result.sources ?? [];
|
|
616
841
|
ctx.recordSearch(sources);
|
|
842
|
+
if (lastCommandOutput !== undefined)
|
|
843
|
+
rememberCommandDetails(ctx, JSON.stringify([client.mutationRecoveryScope(), ctx.config.get("sessionId"), workspaceRoot()]), lastCommandOutput);
|
|
617
844
|
say(result.response); // the final message — anything not already narrated
|
|
845
|
+
workflow?.interrupt();
|
|
846
|
+
if (workflow)
|
|
847
|
+
ui.commit(renderAgentOutcome(workflow.snapshot(), { ...turnOutcome, applied: mutations?.applied }));
|
|
618
848
|
const swapped = noteModelSubstitution(ctx, result.model);
|
|
619
849
|
if (swapped)
|
|
620
850
|
live.commit([" " + c.warn("!") + " " + c.dim(swapped)]);
|
|
@@ -630,14 +860,26 @@ turnOpts = {}) {
|
|
|
630
860
|
live.stop();
|
|
631
861
|
}
|
|
632
862
|
catch (err) {
|
|
863
|
+
workflow?.interrupt();
|
|
864
|
+
if (workflow)
|
|
865
|
+
ui.commit(renderAgentOutcome(workflow.snapshot(), { ...turnOutcome, applied: mutations?.applied }));
|
|
633
866
|
ui.stepEnd();
|
|
634
867
|
ui.stop();
|
|
635
868
|
live.stop();
|
|
636
|
-
|
|
869
|
+
if (signal.aborted)
|
|
870
|
+
line(" ⊘ Cancelled — the turn stopped.");
|
|
871
|
+
else
|
|
872
|
+
renderApiError(err);
|
|
637
873
|
}
|
|
638
874
|
finally {
|
|
639
875
|
// Always detach, so the composer's own Ctrl+C (arm-then-exit) works again.
|
|
876
|
+
taskView?.clear();
|
|
640
877
|
stopWatching();
|
|
878
|
+
// Hash what this turn read or changed, as it is on disk NOW, for the next
|
|
879
|
+
// turn's freshness report. Also after a failed or cancelled turn: an
|
|
880
|
+
// applied change is on disk either way.
|
|
881
|
+
taskFiles?.touchApplied(mutations?.applied ?? []);
|
|
882
|
+
taskFiles?.commit(ownerScope, ctx.config.get("sessionId"));
|
|
641
883
|
}
|
|
642
884
|
}
|
|
643
885
|
// ── Chat type (Carrier Chat vs Standard) ──────────────────────────────────────
|
|
@@ -905,7 +1147,7 @@ function onOff(arg) {
|
|
|
905
1147
|
return null;
|
|
906
1148
|
}
|
|
907
1149
|
/** `/fast` toggles, `/fast on|off` sets. */
|
|
908
|
-
export function setFast(ctx, arg) {
|
|
1150
|
+
export async function setFast(ctx, arg, client) {
|
|
909
1151
|
const raw = arg.trim();
|
|
910
1152
|
const next = raw ? onOff(raw) : !ctx.fast;
|
|
911
1153
|
if (next === null) {
|
|
@@ -921,10 +1163,24 @@ export function setFast(ctx, arg) {
|
|
|
921
1163
|
line(" " + c.dim("Run ") + c.cmd("/switch standard") + c.dim(" first."));
|
|
922
1164
|
return;
|
|
923
1165
|
}
|
|
1166
|
+
// As on the web: Fast Mode runs the admin's Fast model, which is text-only.
|
|
1167
|
+
let fast = null;
|
|
1168
|
+
if (next) {
|
|
1169
|
+
fast = client ? await loadFastModel(client) : null;
|
|
1170
|
+
if (!fast) {
|
|
1171
|
+
errorLine("Fast mode isn't available right now — the server has no Fast Mode model.");
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
if (ctx.attachedFileIds.length) {
|
|
1175
|
+
errorLine("Fast mode can't read files — its model is text-only.");
|
|
1176
|
+
line(" " + c.dim("Run ") + c.cmd("/detach") + c.dim(" first, then ") + c.cmd("/fast") + c.dim("."));
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
924
1180
|
ctx.setFast(next);
|
|
925
1181
|
info(next
|
|
926
|
-
?
|
|
927
|
-
: "Fast mode off — standard pipeline depth.");
|
|
1182
|
+
? `Fast mode on — ${fast.label}, quicker replies, less refinement. /model is locked until /fast off.`
|
|
1183
|
+
: "Fast mode off — standard pipeline depth, your chosen model.");
|
|
928
1184
|
}
|
|
929
1185
|
/** `/hipwr` toggles, `/hipwr on|off` sets. Warns when the mode won't run it. */
|
|
930
1186
|
export function setHighPower(ctx, arg) {
|
|
@@ -1105,6 +1361,10 @@ export async function setMode(ctx, client, arg) {
|
|
|
1105
1361
|
*/
|
|
1106
1362
|
export async function chatInputWithFiles(ctx, client, input, footer, signal) {
|
|
1107
1363
|
const { files, prompt, rejected } = detectLocalFiles(input);
|
|
1364
|
+
// File uploads are writes too. Check before attaching anything, and let
|
|
1365
|
+
// chatTurn recheck before sending in case the admin flips the switch mid-upload.
|
|
1366
|
+
if (files.length > 0 && !(await allowChatTurn(ctx, client)))
|
|
1367
|
+
return;
|
|
1108
1368
|
for (const r of rejected) {
|
|
1109
1369
|
line(" " + c.warn("!") + " " + c.dim(`Not attached — outside this project: ${r}`));
|
|
1110
1370
|
}
|
|
@@ -1225,6 +1485,13 @@ export async function showModels(ctx, client) {
|
|
|
1225
1485
|
}
|
|
1226
1486
|
}
|
|
1227
1487
|
export async function setModel(ctx, client, arg) {
|
|
1488
|
+
// Fast Mode picks the model (the server's Fast model), as the web locks its picker.
|
|
1489
|
+
if (fastInEffect(ctx)) {
|
|
1490
|
+
const fast = await loadFastModel(client);
|
|
1491
|
+
errorLine(`Fast mode is on — it runs on ${fast?.label ?? "the Fast Mode model"}.`);
|
|
1492
|
+
line(" " + c.dim("Run ") + c.cmd("/fast off") + c.dim(" to choose a model."));
|
|
1493
|
+
return;
|
|
1494
|
+
}
|
|
1228
1495
|
const id = arg.trim().toLowerCase();
|
|
1229
1496
|
if (!id) {
|
|
1230
1497
|
await pickModel(ctx, client);
|