@carrieros/cli 0.3.0 → 0.4.1
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 +89 -15
- package/dist/commands/chat.js +6 -6
- package/dist/commands/context.js +40 -0
- package/dist/commands/doctor.js +34 -14
- package/dist/commands/logout.js +2 -0
- package/dist/commands/permissions.js +78 -0
- package/dist/commands/scope.js +9 -6
- package/dist/commands/sessions.js +5 -0
- package/dist/commands/settings.js +83 -10
- package/dist/commands/update.js +177 -51
- package/dist/commands/usage.js +10 -8
- package/dist/commands/version.js +1 -3
- package/dist/commands/whoami.js +12 -9
- package/dist/ide/editor-context.js +115 -12
- package/dist/ide/ide-session.js +288 -18
- package/dist/ide/tool-host.js +6 -6
- package/dist/main.js +10 -1
- package/dist/services/api.js +183 -15
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/auto-update.js +221 -0
- package/dist/services/chat-stream.js +26 -3
- package/dist/services/checkpoints.js +176 -14
- package/dist/services/client-tools.js +123 -27
- 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 +96 -11
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +98 -25
- package/dist/services/device-auth.js +33 -6
- 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 +44 -13
- package/dist/services/meta.js +27 -0
- 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 +78 -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 +7 -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 +457 -13
- package/dist/services/workspace-registry.js +4 -3
- package/dist/services/workspace.js +8 -1
- package/dist/shell/shell-chat.js +320 -34
- package/dist/shell/shell-commands.js +47 -5
- package/dist/shell/shell-prompt.js +21 -11
- package/dist/shell/shell-renderer.js +1 -1
- package/dist/shell/shell.js +107 -20
- 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 +11 -4
- 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 +9 -5
package/dist/shell/shell-chat.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
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";
|
|
8
19
|
import { sleep, withSpinner } from "../services/spinner.js";
|
|
9
20
|
import { c } from "../ui/colors.js";
|
|
10
21
|
import { renderProjectBrief, workspaceContextHint } from "../services/project-context.js";
|
|
11
|
-
import { declaredClientTools, declaredCommandTools, declaredMutationTools, handleClientToolCall, submitWithRetry } from "../services/client-tools.js";
|
|
22
|
+
import { declaredClientTools, declaredCommandTools, declaredMutationTools, handleClientToolCall, localCommandsState, submitWithRetry } from "../services/client-tools.js";
|
|
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";
|
|
@@ -85,7 +119,11 @@ const ERROR_HINTS = {
|
|
|
85
119
|
// Context overflow: a new conversation is the one reliable fix, and a
|
|
86
120
|
// roomier model is the other.
|
|
87
121
|
MCAI_BLOCKED: "/new",
|
|
122
|
+
// The model's context limit cannot be verified (a server configuration
|
|
123
|
+
// gap): another model is the fix, not a shorter message.
|
|
124
|
+
MCAI_UNVERIFIED: "/model",
|
|
88
125
|
SESSION_NOT_FOUND: "/sessions",
|
|
126
|
+
CARRIER_CHAT_MAINTENANCE: "/switch standard",
|
|
89
127
|
// Out of credit on this model — pick another rather than retrying into the
|
|
90
128
|
// same wall. (The server substitutes when it can; this is when it couldn't.)
|
|
91
129
|
PROVIDER_EXHAUSTED: "/model",
|
|
@@ -193,7 +231,11 @@ function errorDetail(err) {
|
|
|
193
231
|
if (err.code === "INSUFFICIENT_CREDITS") {
|
|
194
232
|
return "Nothing was charged for this message.";
|
|
195
233
|
}
|
|
196
|
-
|
|
234
|
+
if (err.code === "TASK_TOO_LARGE_FOR_MODEL") {
|
|
235
|
+
return "Try splitting the coding work into smaller steps and send them one at a time.";
|
|
236
|
+
}
|
|
237
|
+
// The server's structured reason names the kind of provider failure.
|
|
238
|
+
return err.reason ? `${PROVIDER_ERROR_REASONS[err.reason]} · Error code: ${err.code}` : `Error code: ${err.code}`;
|
|
197
239
|
}
|
|
198
240
|
/** Render an API failure with its cause and the command that addresses it. */
|
|
199
241
|
function renderApiError(err) {
|
|
@@ -205,11 +247,48 @@ function renderApiError(err) {
|
|
|
205
247
|
renderError("Something went wrong", err.message);
|
|
206
248
|
return;
|
|
207
249
|
}
|
|
250
|
+
if (err.code === "CARRIER_CHAT_MAINTENANCE") {
|
|
251
|
+
showCarrierMaintenance();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
208
254
|
// Running out of credits is a state to act on, not a fault — a red × made a
|
|
209
255
|
// billing prompt look like a crash.
|
|
210
256
|
const tone = err.code === "INSUFFICIENT_CREDITS" ? "warn" : "error";
|
|
211
257
|
renderError(errorTitle(err), errorDetail(err), ERROR_HINTS[err.code], tone);
|
|
212
258
|
}
|
|
259
|
+
/** The API owns availability and session identity. A stored Standard session
|
|
260
|
+
* cannot be continued under a Carrier label (or vice versa). The old chat is
|
|
261
|
+
* untouched and remains available through /sessions. */
|
|
262
|
+
export async function syncChatAvailability(ctx, client) {
|
|
263
|
+
const sessionId = ctx.config.get("sessionId");
|
|
264
|
+
const state = await client.chatAvailability(sessionId);
|
|
265
|
+
ctx.carrierMaintenance = state.carrier_chat_maintenance;
|
|
266
|
+
if (sessionId && state.session_chat_type !== ctx.chatType) {
|
|
267
|
+
ctx.config.set("sessionId", undefined);
|
|
268
|
+
ctx.config.set("sessionTitle", undefined);
|
|
269
|
+
line(" " + c.warn("⚠") + " " + c.dim("The saved chat belongs to another chat type. It remains in /sessions; a new chat will start here."));
|
|
270
|
+
}
|
|
271
|
+
return state;
|
|
272
|
+
}
|
|
273
|
+
export function showCarrierMaintenance() {
|
|
274
|
+
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");
|
|
275
|
+
}
|
|
276
|
+
/** Checks immediately before any model turn; the initial shell banner is only
|
|
277
|
+
* advisory, because the admin can change the switch while the CLI stays open. */
|
|
278
|
+
async function allowChatTurn(ctx, client) {
|
|
279
|
+
try {
|
|
280
|
+
const state = await syncChatAvailability(ctx, client);
|
|
281
|
+
if (ctx.chatType === "carrier" && state.carrier_chat_maintenance) {
|
|
282
|
+
showCarrierMaintenance();
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
catch (err) {
|
|
288
|
+
renderApiError(err);
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
213
292
|
/**
|
|
214
293
|
* Cache a newly-created conversation's title for the footer. Best-effort and
|
|
215
294
|
* deliberately un-awaited — a title is cosmetic, so it must never delay a reply
|
|
@@ -319,6 +398,8 @@ function withProjectContext(ctx, message) {
|
|
|
319
398
|
}
|
|
320
399
|
}
|
|
321
400
|
export async function chatTurn(ctx, client, message, opts = {}) {
|
|
401
|
+
if (!(await allowChatTurn(ctx, client)))
|
|
402
|
+
return;
|
|
322
403
|
// SIA rewrites the prompt, so it has to resolve before EITHER render path
|
|
323
404
|
// starts — the merged text is what gets echoed, sent and stored. A read-only
|
|
324
405
|
// task (a review) is fixed, not an ambiguous request, so it never clarifies.
|
|
@@ -339,7 +420,7 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
339
420
|
}
|
|
340
421
|
message = result.prompt;
|
|
341
422
|
}
|
|
342
|
-
const useLiveBar = opts.footer !== undefined && process.stdout.isTTY;
|
|
423
|
+
const useLiveBar = opts.footer !== undefined && process.stdout.isTTY && process.env.TERM !== "dumb";
|
|
343
424
|
if (useLiveBar) {
|
|
344
425
|
await chatTurnLive(ctx, client, message, opts.footer ?? "", opts.webSearch, echoed, opts.signal, { readOnly: opts.readOnly, sendAs: opts.sendAs });
|
|
345
426
|
return;
|
|
@@ -387,6 +468,7 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
387
468
|
// Persist the session so the conversation continues across turns/invocations.
|
|
388
469
|
if (result.session_id && result.session_id !== sessionId) {
|
|
389
470
|
ctx.config.set("sessionId", result.session_id);
|
|
471
|
+
rememberPermissionMode(ctx.config);
|
|
390
472
|
// The chat response carries no title, and the backend generates one from
|
|
391
473
|
// the first message — fetch it once, in the background, so the footer can
|
|
392
474
|
// name the conversation without delaying the reply. Failure is silent:
|
|
@@ -415,7 +497,10 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
415
497
|
}
|
|
416
498
|
catch (err) {
|
|
417
499
|
spinner.stop();
|
|
418
|
-
|
|
500
|
+
if (signal.aborted)
|
|
501
|
+
line(" ⊘ Cancelled — the turn stopped.");
|
|
502
|
+
else
|
|
503
|
+
renderApiError(err);
|
|
419
504
|
}
|
|
420
505
|
finally {
|
|
421
506
|
// Always detach, so the composer's own Ctrl+C (arm-then-exit) works again.
|
|
@@ -423,9 +508,11 @@ export async function chatTurn(ctx, client, message, opts = {}) {
|
|
|
423
508
|
}
|
|
424
509
|
}
|
|
425
510
|
/** What the prompt asks, in the plan's own terms. */
|
|
426
|
-
function approvalQuestion(plans) {
|
|
511
|
+
function approvalQuestion(plans, correction = false) {
|
|
512
|
+
if (correction)
|
|
513
|
+
return plans.length > 1 ? `Approve all ${plans.length} corrective changes?` : "Approve this correction?";
|
|
427
514
|
if (plans.length > 1)
|
|
428
|
-
return `
|
|
515
|
+
return `Approve all ${plans.length} changes?`;
|
|
429
516
|
switch (plans[0]?.name) {
|
|
430
517
|
case "revert_change":
|
|
431
518
|
return "Undo this change?";
|
|
@@ -434,7 +521,7 @@ function approvalQuestion(plans) {
|
|
|
434
521
|
case "create_file":
|
|
435
522
|
return "Create this file?";
|
|
436
523
|
default:
|
|
437
|
-
return "
|
|
524
|
+
return "Approve this change?";
|
|
438
525
|
}
|
|
439
526
|
}
|
|
440
527
|
/** "Running the project tests" reads better than the argv on an activity line. */
|
|
@@ -464,6 +551,7 @@ turnOpts = {}) {
|
|
|
464
551
|
const model = currentModelId(ctx);
|
|
465
552
|
const sessionId = ctx.config.get("sessionId");
|
|
466
553
|
const webSearch = webSearchOverride ?? ctx.effectiveWebSearch;
|
|
554
|
+
clearCommandDetails(ctx);
|
|
467
555
|
const live = startLiveComposer(footer);
|
|
468
556
|
// One owner for everything this turn draws: the user's message, activity,
|
|
469
557
|
// approval cards, command output and the answer (see ui/conversation.ts).
|
|
@@ -503,23 +591,112 @@ turnOpts = {}) {
|
|
|
503
591
|
};
|
|
504
592
|
// A read-only turn (a review) offers NEITHER mutation nor command tools, so
|
|
505
593
|
// the model cannot change files or run commands whatever the prompt says.
|
|
506
|
-
|
|
594
|
+
// Plan mode uses the same gate. The mode is fixed for the turn, so switching
|
|
595
|
+
// it while a review is open never changes what this turn may do.
|
|
596
|
+
const permissionMode = getPermissionMode(ctx.config);
|
|
597
|
+
const permission = permissionPolicy(permissionMode);
|
|
598
|
+
const mutationTools = turnOpts.readOnly || !permission.changeTools ? undefined : declaredMutationTools(ctx);
|
|
599
|
+
const commandTools = turnOpts.readOnly || !permission.commands ? undefined : declaredCommandTools(ctx, undefined, permissionMode === "auto");
|
|
600
|
+
const commandState = localCommandsState(ctx, undefined, permissionMode === "auto");
|
|
601
|
+
const commandHint = turnOpts.readOnly
|
|
602
|
+
? "[LOCAL TOOL AVAILABILITY] This is a read-only turn; terminal commands are unavailable."
|
|
603
|
+
: !permission.commands
|
|
604
|
+
? "[LOCAL TOOL AVAILABILITY] Plan permission mode is active; terminal commands are unavailable."
|
|
605
|
+
: commandTools
|
|
606
|
+
? "[LOCAL TOOL AVAILABILITY] run_command is available. Manual/Accept Edits require command approval; Auto runs locally permitted commands without an individual prompt."
|
|
607
|
+
: !commandState.enabled
|
|
608
|
+
? ctx.config.get("localCommandsEnabled") === false
|
|
609
|
+
? "[LOCAL TOOL AVAILABILITY] Local commands were explicitly disabled with `/settings commands off`; the model has no run_command tool."
|
|
610
|
+
: "[LOCAL TOOL AVAILABILITY] Local commands are off. In Manual or Accept Edits, enable them with `/settings commands on`; selecting Auto opts in for the session."
|
|
611
|
+
: `[LOCAL TOOL AVAILABILITY] run_command is unavailable: ${commandState.blockedBy ?? "the interactive command tool is not available in this session"}. Do not claim that a command ran.`;
|
|
612
|
+
let taskView;
|
|
613
|
+
// What the final card needs that the workflow snapshot does not carry: why a
|
|
614
|
+
// change stopped (from the coordinator's recorded result codes) and the last
|
|
615
|
+
// validation's counts (from the actual command output). Display only.
|
|
616
|
+
const turnOutcome = {};
|
|
617
|
+
// Complete reads delivered to the model this turn. Tool results are not
|
|
618
|
+
// replayed into later turns, so reuse never outlives the turn.
|
|
619
|
+
const readCache = new TurnReadCache();
|
|
620
|
+
const workflow = mutationTools ? new CodingWorkflow(async () => {
|
|
621
|
+
if (!commandTools)
|
|
622
|
+
throw new Error("Secure verification commands are unavailable. Enable local commands and configure the required runtime before planning changes.");
|
|
623
|
+
const contract = executionContract();
|
|
624
|
+
if (contract.capability === "UNSUPPORTED")
|
|
625
|
+
throw new Error(contract.prerequisite);
|
|
626
|
+
if (contract.capability === "ISOLATED_RUNTIME_REQUIRED")
|
|
627
|
+
await verifyContainerRuntime(containerRuntime());
|
|
628
|
+
else
|
|
629
|
+
ensureJobHelper();
|
|
630
|
+
return contract;
|
|
631
|
+
}, lines => {
|
|
632
|
+
// Close the investigation step first, so its record sits ABOVE the plan it led to.
|
|
633
|
+
if (lines[0]?.startsWith("Plan:")) {
|
|
634
|
+
ui.stepEnd();
|
|
635
|
+
const snap = workflow.snapshot();
|
|
636
|
+
if (!turnOutcome.task && !Number(snap.corrections))
|
|
637
|
+
turnOutcome.task = snap.plan?.summary;
|
|
638
|
+
ui.commit(renderAgentPlan(snap, { rootCause: turnOutcome.rootCause }));
|
|
639
|
+
}
|
|
640
|
+
else if (lines[0]?.startsWith("Failure analysis")) {
|
|
641
|
+
ui.stepEnd();
|
|
642
|
+
turnOutcome.rootCause = analysisExplanation(lines).explanation;
|
|
643
|
+
ui.commit(renderFailureAnalysis(lines));
|
|
644
|
+
}
|
|
645
|
+
taskView?.refresh();
|
|
646
|
+
}, { signal, recoveryScope: () => client.mutationRecoveryScope(), onReadsInvalidated: () => readCache.invalidate() }) : undefined;
|
|
647
|
+
taskView = workflow ? new ActiveChangeView(() => workflow.snapshot(), screenTask) : undefined;
|
|
507
648
|
const mutations = mutationTools
|
|
508
649
|
? createMutationCoordinator({
|
|
509
|
-
|
|
650
|
+
signal,
|
|
651
|
+
approvalContext: () => workflow?.approvalContext(),
|
|
652
|
+
recoveryScope: () => client.mutationRecoveryScope(),
|
|
653
|
+
validatePlans: plans => workflow?.beforeMutation(plans),
|
|
654
|
+
approveEditsByPolicy: () => permission.approveEditsByPolicy,
|
|
655
|
+
// Recorded before delivery: an immediate reply finds the change already recorded.
|
|
656
|
+
record: payload => workflow?.mutationResult(payload),
|
|
657
|
+
submit: async (payload) => {
|
|
658
|
+
await submitWithRetry(client, payload);
|
|
659
|
+
taskView?.result(payload);
|
|
660
|
+
const code = payload.ok ? undefined : payload.error?.code;
|
|
661
|
+
if (code === "MUTATION_REJECTED" || code === "STALE_FILE") {
|
|
662
|
+
turnOutcome.declined = code === "MUTATION_REJECTED" ? "rejected" : "invalidated";
|
|
663
|
+
turnOutcome.declinedOperations = [...(turnOutcome.declinedOperations ?? []), payload.tool_call_id];
|
|
664
|
+
}
|
|
665
|
+
},
|
|
510
666
|
ui: {
|
|
511
667
|
review: (plans) => withTerminal(() => ui.borrow(async () => {
|
|
512
668
|
ui.stepEnd();
|
|
513
|
-
|
|
514
|
-
const
|
|
515
|
-
|
|
669
|
+
taskView?.review(plans);
|
|
670
|
+
const snapshot = workflow?.snapshot();
|
|
671
|
+
const planned = snapshot?.plan?.files ?? [];
|
|
672
|
+
const applied = (snapshot?.files ?? []);
|
|
673
|
+
const remaining = planned.filter(file => !applied.includes(file.path) && !plans.some(plan => plan.rel === file.path)).length;
|
|
674
|
+
ui.commit(renderGroup(plans, Number(snapshot?.corrections ?? 0) > 0, remaining, workspaceRoot()));
|
|
675
|
+
const question = approvalQuestion(plans, Number(snapshot?.corrections ?? 0) > 0);
|
|
676
|
+
const answer = await approveInScreen({ question, timeoutMs: APPROVAL_TIMEOUT_MS, signal });
|
|
677
|
+
workflow?.approval(answer);
|
|
678
|
+
taskView?.decision(plans, answer);
|
|
679
|
+
return answer;
|
|
516
680
|
})),
|
|
681
|
+
// Accept Edits: the same review card, marked as approved by the session's
|
|
682
|
+
// policy instead of asking; the coordinator's checks still follow.
|
|
683
|
+
approvedByPolicy: (plans) => {
|
|
684
|
+
ui.stepEnd();
|
|
685
|
+
taskView?.review(plans);
|
|
686
|
+
ui.commit([...renderGroup(plans, false, 0, workspaceRoot()), " " + c.accent("✓ Approved by " + permissionModeLabel(getPermissionMode(ctx.config))) + c.dim(getPermissionMode(ctx.config) === "auto" ? " — locally permitted commands run too; /settings commands off blocks them · /permissions to change" : " — commands still ask · /permissions to change"), ""]);
|
|
687
|
+
workflow?.approval("approve");
|
|
688
|
+
taskView?.decision(plans, "approve");
|
|
689
|
+
},
|
|
517
690
|
note: (lines) => ui.commit([...renderChangeSummary(lines), ""]),
|
|
691
|
+
noLongerValid: (rels) => { turnOutcome.declinedFiles = rels; ui.commit(renderNoLongerValid(rels)); },
|
|
692
|
+
rejected: (plans) => { turnOutcome.declinedFiles = plans.map((p) => p.rel); ui.commit(renderChangeRejected(plans)); },
|
|
693
|
+
// Refused before review (could not be planned, or blocked): say so, and why.
|
|
694
|
+
refused: (r) => ui.commit([` ${c.warn("⚠")} ${c.value("Change proposal refused")}${r.files.length ? c.dim(` · ${r.files.join(", ")}`) : ""}`, ` ${c.dim(r.message)}`, ""]),
|
|
518
695
|
cancelTurn: abort
|
|
519
696
|
}
|
|
520
697
|
})
|
|
521
698
|
: undefined;
|
|
522
|
-
|
|
699
|
+
let lastCommandOutput;
|
|
523
700
|
let commands;
|
|
524
701
|
if (commandTools) {
|
|
525
702
|
const auth = ctx.config.get("auth");
|
|
@@ -527,25 +704,73 @@ turnOpts = {}) {
|
|
|
527
704
|
root: workspaceRoot(),
|
|
528
705
|
signal,
|
|
529
706
|
withTerminal,
|
|
707
|
+
recoveryScope: () => client.mutationRecoveryScope(),
|
|
708
|
+
approvalContext: () => workflow?.approvalContext(),
|
|
530
709
|
cliSecrets: [auth?.accessToken, auth?.refreshToken, ctx.config.get("secretKey")].filter((v) => typeof v === "string"),
|
|
531
|
-
submit: (payload) =>
|
|
710
|
+
submit: async (payload) => {
|
|
711
|
+
await submitWithRetry(client, payload);
|
|
712
|
+
const wasAnalyzing = workflow?.state === "ANALYZING_FAILURE";
|
|
713
|
+
workflow?.commandResult(payload);
|
|
714
|
+
if (workflow && !wasAnalyzing && workflow.state === "ANALYZING_FAILURE")
|
|
715
|
+
ui.commit(renderValidationFailed(workflow.snapshot(), turnOutcome.validationCounts, turnOutcome.failure));
|
|
716
|
+
taskView?.refresh();
|
|
717
|
+
},
|
|
532
718
|
ui: {
|
|
533
|
-
review: (decision, reason, repository) => ui.borrow(async () => {
|
|
719
|
+
review: (decision, reason, repository, operationId) => ui.borrow(async () => {
|
|
534
720
|
ui.stepEnd();
|
|
535
|
-
|
|
721
|
+
// Auto: locally admitted commands are approved by the session's policy, and say so.
|
|
722
|
+
if (permission.approveCommandByPolicy(decision.tier)) {
|
|
723
|
+
ui.commit([" " + c.ok("✓") + " " + c.dim("Auto: running ") + c.cmd(displayCommand(decision.program, decision.args)) + c.dim(" without asking (contained, " + decision.tier + ").")]);
|
|
724
|
+
return "approve";
|
|
725
|
+
}
|
|
726
|
+
taskView?.commandStatus(`Review: ${displayCommand(decision.program, decision.args)}`);
|
|
727
|
+
ui.commit(renderCommandReview(decision, reason, repository, executionContract(), workspaceRoot(), operationId));
|
|
536
728
|
return approveInScreen({ question: "Run this command?", timeoutMs: APPROVAL_TIMEOUT_MS, signal });
|
|
537
729
|
}),
|
|
538
|
-
started: (decision) =>
|
|
730
|
+
started: (decision) => {
|
|
731
|
+
taskView?.commandStatus(`Running: ${displayCommand(decision.program, decision.args)}`);
|
|
732
|
+
ui.commandStarted(commandActivityLabel(decision), displayCommand(decision.program, decision.effectiveArgs));
|
|
733
|
+
},
|
|
539
734
|
output: (_stream, text) => ui.commandOutput(text),
|
|
540
735
|
finished: ({ decision, result, errorCode, message: detail }) => {
|
|
736
|
+
if (result) {
|
|
737
|
+
turnOutcome.validationCounts = summariseOutput(result.output) || undefined;
|
|
738
|
+
turnOutcome.failure = parseTestReport(result.output).failure;
|
|
739
|
+
}
|
|
740
|
+
taskView?.commandStatus(renderCommandSummary(decision, result, errorCode, detail).join(" "));
|
|
741
|
+
if (result)
|
|
742
|
+
lastCommandOutput = result.output;
|
|
743
|
+
if (result)
|
|
744
|
+
rememberCommandDetails(ctx, JSON.stringify([client.mutationRecoveryScope(), ctx.config.get("sessionId"), workspaceRoot()]), result.output);
|
|
541
745
|
ui.commandEnded();
|
|
542
|
-
ui.commit([...renderCommandSummary(decision, result, errorCode, detail), ""]);
|
|
543
|
-
ui.status("thinking", "
|
|
746
|
+
ui.commit([...renderCommandSummary(decision, result, errorCode, detail), ...(result ? [" /details shows the full bounded command output."] : []), ""]);
|
|
747
|
+
ui.status("thinking", "Thinking");
|
|
544
748
|
},
|
|
545
749
|
cancelTurn: abort
|
|
546
750
|
}
|
|
547
751
|
});
|
|
548
752
|
}
|
|
753
|
+
// Task Context (services/task-context.ts, server clientTools/taskContext.js).
|
|
754
|
+
// A coding turn in a conversation with earlier coding work: show that the
|
|
755
|
+
// previous task's context was restored, and tell the server which of the
|
|
756
|
+
// files it inspected changed on disk since. Context only — nothing here
|
|
757
|
+
// skips a read, restores an approval or resumes an operation.
|
|
758
|
+
const taskFiles = workflow ? new TaskFileLedger() : undefined;
|
|
759
|
+
const ownerScope = workflow ? client.mutationRecoveryScope() : undefined;
|
|
760
|
+
const repoContext = workflow ? repositoryContext(ownerScope, sessionId) : null;
|
|
761
|
+
// A different repository than the earlier work used: its file report would
|
|
762
|
+
// describe other code, so it is not sent; the server is told the repository changed.
|
|
763
|
+
const repoState = workflow && sessionId && repoContext?.same_repository !== false ? repositoryState(ownerScope, sessionId) : [];
|
|
764
|
+
if (workflow && sessionId) {
|
|
765
|
+
const restored = await fetchTaskContext(client, sessionId);
|
|
766
|
+
if (restored && !signal.aborted)
|
|
767
|
+
ui.commit(renderTaskContextRestored(restored, repoState, repoContext?.name ?? (() => { try {
|
|
768
|
+
return getWorkspace().project.name;
|
|
769
|
+
}
|
|
770
|
+
catch {
|
|
771
|
+
return undefined;
|
|
772
|
+
} })(), repoContext));
|
|
773
|
+
}
|
|
549
774
|
// request_started + request_sent: fire the real call immediately, then the
|
|
550
775
|
// brief client-side steps play over the actual wait. Settle it eagerly so a
|
|
551
776
|
// rejection during the steps is never an unhandled rejection.
|
|
@@ -558,7 +783,7 @@ turnOpts = {}) {
|
|
|
558
783
|
const settled = client
|
|
559
784
|
.chatStream({
|
|
560
785
|
mode,
|
|
561
|
-
message: turnOpts.sendAs ?? withProjectContext(ctx, message)
|
|
786
|
+
message: `${turnOpts.sendAs ?? withProjectContext(ctx, message)}\n\n${commandHint}`,
|
|
562
787
|
session_id: sessionId,
|
|
563
788
|
model: model || undefined,
|
|
564
789
|
chat_type: ctx.chatType,
|
|
@@ -566,9 +791,11 @@ turnOpts = {}) {
|
|
|
566
791
|
speed: ctx.fast ? "fast" : undefined,
|
|
567
792
|
high_power: ctx.highPower ? true : undefined,
|
|
568
793
|
file_ids: attached.length ? attached : undefined,
|
|
569
|
-
client_tools: declaredClientTools(ctx),
|
|
794
|
+
client_tools: workflow ? [...(declaredClientTools(ctx) ?? []), "coding_workflow"] : declaredClientTools(ctx),
|
|
570
795
|
client_mutation_tools: mutationTools,
|
|
571
|
-
client_command_tools: commandTools
|
|
796
|
+
client_command_tools: commandTools,
|
|
797
|
+
repository_state: repoState.length ? repoState : undefined,
|
|
798
|
+
repository_context: repoContext ?? undefined
|
|
572
799
|
}, {
|
|
573
800
|
onDelta: (delta) => {
|
|
574
801
|
if (signal.aborted)
|
|
@@ -576,15 +803,31 @@ turnOpts = {}) {
|
|
|
576
803
|
streamed += delta;
|
|
577
804
|
ui.writing(streamed.slice(shown));
|
|
578
805
|
},
|
|
579
|
-
onClientToolCall: (call) => {
|
|
806
|
+
onClientToolCall: async (call) => {
|
|
580
807
|
// Whatever the model said before asking for this tool belongs above it.
|
|
581
808
|
say();
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
809
|
+
const activity = toolActivity(call.name, call.arguments ?? {}, workspaceRoot());
|
|
810
|
+
ui.status("thinking", activity);
|
|
811
|
+
await handleClientToolCall(ctx, client, call, {
|
|
812
|
+
onStart: (_label, tool) => ui.toolStart(activity, toolKind(tool)),
|
|
813
|
+
onDone: (_label, ok, tool, detail) => {
|
|
814
|
+
if (ok)
|
|
815
|
+
taskFiles?.touch(call.name, call.arguments);
|
|
816
|
+
ui.toolEnd(activity, toolKind(tool), toolSummary(tool, ok, detail), ok);
|
|
817
|
+
taskView?.refresh();
|
|
818
|
+
if (workflow)
|
|
819
|
+
ui.status("thinking", workflowActivity(workflow.snapshot()));
|
|
820
|
+
},
|
|
821
|
+
workflow,
|
|
822
|
+
readCache,
|
|
585
823
|
mutations,
|
|
586
|
-
commands
|
|
824
|
+
commands,
|
|
825
|
+
// A refused proposal ends its step visibly, with the engine's reason.
|
|
826
|
+
onRefused: (r) => ui.toolEnd(activity, toolKind(call.name), `refused — ${r.reason}`, false)
|
|
587
827
|
});
|
|
828
|
+
taskView?.refresh();
|
|
829
|
+
if (workflow)
|
|
830
|
+
ui.status("thinking", workflowActivity(workflow.snapshot()));
|
|
588
831
|
}
|
|
589
832
|
}, signal)
|
|
590
833
|
.then((r) => ({ ok: true, r }))
|
|
@@ -603,6 +846,7 @@ turnOpts = {}) {
|
|
|
603
846
|
ctx.disarmWebSearch(); // spend the one-shot arm
|
|
604
847
|
if (result.session_id && result.session_id !== sessionId) {
|
|
605
848
|
ctx.config.set("sessionId", result.session_id);
|
|
849
|
+
rememberPermissionMode(ctx.config);
|
|
606
850
|
// The chat response carries no title, and the backend generates one from
|
|
607
851
|
// the first message — fetch it once, in the background, so the footer can
|
|
608
852
|
// name the conversation without delaying the reply. Failure is silent:
|
|
@@ -614,7 +858,12 @@ turnOpts = {}) {
|
|
|
614
858
|
// staying visible the whole time. Finished lines commit above the bar.
|
|
615
859
|
const sources = result.sources ?? [];
|
|
616
860
|
ctx.recordSearch(sources);
|
|
861
|
+
if (lastCommandOutput !== undefined)
|
|
862
|
+
rememberCommandDetails(ctx, JSON.stringify([client.mutationRecoveryScope(), ctx.config.get("sessionId"), workspaceRoot()]), lastCommandOutput);
|
|
617
863
|
say(result.response); // the final message — anything not already narrated
|
|
864
|
+
workflow?.interrupt();
|
|
865
|
+
if (workflow)
|
|
866
|
+
ui.commit(renderAgentOutcome(workflow.snapshot(), { ...turnOutcome, applied: mutations?.applied }));
|
|
618
867
|
const swapped = noteModelSubstitution(ctx, result.model);
|
|
619
868
|
if (swapped)
|
|
620
869
|
live.commit([" " + c.warn("!") + " " + c.dim(swapped)]);
|
|
@@ -630,14 +879,26 @@ turnOpts = {}) {
|
|
|
630
879
|
live.stop();
|
|
631
880
|
}
|
|
632
881
|
catch (err) {
|
|
882
|
+
workflow?.interrupt();
|
|
883
|
+
if (workflow)
|
|
884
|
+
ui.commit(renderAgentOutcome(workflow.snapshot(), { ...turnOutcome, applied: mutations?.applied }));
|
|
633
885
|
ui.stepEnd();
|
|
634
886
|
ui.stop();
|
|
635
887
|
live.stop();
|
|
636
|
-
|
|
888
|
+
if (signal.aborted)
|
|
889
|
+
line(" ⊘ Cancelled — the turn stopped.");
|
|
890
|
+
else
|
|
891
|
+
renderApiError(err);
|
|
637
892
|
}
|
|
638
893
|
finally {
|
|
639
894
|
// Always detach, so the composer's own Ctrl+C (arm-then-exit) works again.
|
|
895
|
+
taskView?.clear();
|
|
640
896
|
stopWatching();
|
|
897
|
+
// Hash what this turn read or changed, as it is on disk NOW, for the next
|
|
898
|
+
// turn's freshness report. Also after a failed or cancelled turn: an
|
|
899
|
+
// applied change is on disk either way.
|
|
900
|
+
taskFiles?.touchApplied(mutations?.applied ?? []);
|
|
901
|
+
taskFiles?.commit(ownerScope, ctx.config.get("sessionId"));
|
|
641
902
|
}
|
|
642
903
|
}
|
|
643
904
|
// ── Chat type (Carrier Chat vs Standard) ──────────────────────────────────────
|
|
@@ -905,7 +1166,7 @@ function onOff(arg) {
|
|
|
905
1166
|
return null;
|
|
906
1167
|
}
|
|
907
1168
|
/** `/fast` toggles, `/fast on|off` sets. */
|
|
908
|
-
export function setFast(ctx, arg) {
|
|
1169
|
+
export async function setFast(ctx, arg, client) {
|
|
909
1170
|
const raw = arg.trim();
|
|
910
1171
|
const next = raw ? onOff(raw) : !ctx.fast;
|
|
911
1172
|
if (next === null) {
|
|
@@ -921,10 +1182,24 @@ export function setFast(ctx, arg) {
|
|
|
921
1182
|
line(" " + c.dim("Run ") + c.cmd("/switch standard") + c.dim(" first."));
|
|
922
1183
|
return;
|
|
923
1184
|
}
|
|
1185
|
+
// As on the web: Fast Mode runs the admin's Fast model, which is text-only.
|
|
1186
|
+
let fast = null;
|
|
1187
|
+
if (next) {
|
|
1188
|
+
fast = client ? await loadFastModel(client) : null;
|
|
1189
|
+
if (!fast) {
|
|
1190
|
+
errorLine("Fast mode isn't available right now — the server has no Fast Mode model.");
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
if (ctx.attachedFileIds.length) {
|
|
1194
|
+
errorLine("Fast mode can't read files — its model is text-only.");
|
|
1195
|
+
line(" " + c.dim("Run ") + c.cmd("/detach") + c.dim(" first, then ") + c.cmd("/fast") + c.dim("."));
|
|
1196
|
+
return;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
924
1199
|
ctx.setFast(next);
|
|
925
1200
|
info(next
|
|
926
|
-
?
|
|
927
|
-
: "Fast mode off — standard pipeline depth.");
|
|
1201
|
+
? `Fast mode on — ${fast.label}, quicker replies, less refinement. /model is locked until /fast off.`
|
|
1202
|
+
: "Fast mode off — standard pipeline depth, your chosen model.");
|
|
928
1203
|
}
|
|
929
1204
|
/** `/hipwr` toggles, `/hipwr on|off` sets. Warns when the mode won't run it. */
|
|
930
1205
|
export function setHighPower(ctx, arg) {
|
|
@@ -1105,6 +1380,10 @@ export async function setMode(ctx, client, arg) {
|
|
|
1105
1380
|
*/
|
|
1106
1381
|
export async function chatInputWithFiles(ctx, client, input, footer, signal) {
|
|
1107
1382
|
const { files, prompt, rejected } = detectLocalFiles(input);
|
|
1383
|
+
// File uploads are writes too. Check before attaching anything, and let
|
|
1384
|
+
// chatTurn recheck before sending in case the admin flips the switch mid-upload.
|
|
1385
|
+
if (files.length > 0 && !(await allowChatTurn(ctx, client)))
|
|
1386
|
+
return;
|
|
1108
1387
|
for (const r of rejected) {
|
|
1109
1388
|
line(" " + c.warn("!") + " " + c.dim(`Not attached — outside this project: ${r}`));
|
|
1110
1389
|
}
|
|
@@ -1225,6 +1504,13 @@ export async function showModels(ctx, client) {
|
|
|
1225
1504
|
}
|
|
1226
1505
|
}
|
|
1227
1506
|
export async function setModel(ctx, client, arg) {
|
|
1507
|
+
// Fast Mode picks the model (the server's Fast model), as the web locks its picker.
|
|
1508
|
+
if (fastInEffect(ctx)) {
|
|
1509
|
+
const fast = await loadFastModel(client);
|
|
1510
|
+
errorLine(`Fast mode is on — it runs on ${fast?.label ?? "the Fast Mode model"}.`);
|
|
1511
|
+
line(" " + c.dim("Run ") + c.cmd("/fast off") + c.dim(" to choose a model."));
|
|
1512
|
+
return;
|
|
1513
|
+
}
|
|
1228
1514
|
const id = arg.trim().toLowerCase();
|
|
1229
1515
|
if (!id) {
|
|
1230
1516
|
await pickModel(ctx, client);
|