@carrieros/cli-staging 0.0.0-stage → 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 +6 -2
- package/dist/commands/attach.js +45 -0
- package/dist/commands/auth.js +60 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +182 -0
- package/dist/commands/context.js +200 -0
- package/dist/commands/doctor.js +119 -0
- package/dist/commands/files.js +94 -0
- package/dist/commands/help.js +37 -0
- package/dist/commands/history.js +112 -0
- package/dist/commands/login.js +62 -0
- package/dist/commands/logout.js +26 -0
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +64 -0
- package/dist/commands/models.js +28 -0
- package/dist/commands/modes.js +30 -0
- package/dist/commands/permissions.js +78 -0
- package/dist/commands/project.js +106 -0
- package/dist/commands/repo.js +146 -0
- package/dist/commands/repos.js +61 -0
- package/dist/commands/review.js +92 -0
- package/dist/commands/scope.js +155 -0
- package/dist/commands/search.js +92 -0
- package/dist/commands/sessions.js +282 -0
- package/dist/commands/settings.js +160 -0
- package/dist/commands/update.js +285 -0
- package/dist/commands/upload.js +223 -0
- package/dist/commands/usage.js +229 -0
- package/dist/commands/version.js +26 -0
- package/dist/commands/whoami.js +44 -0
- package/dist/ide/editor-context.js +275 -0
- package/dist/ide/ide-session.js +364 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +132 -0
- package/dist/services/api.js +441 -0
- package/dist/services/auth-origin.js +20 -0
- package/dist/services/auto-update.js +221 -0
- package/dist/services/chat-stream.js +168 -0
- package/dist/services/checkpoints.js +278 -0
- package/dist/services/client-tools.js +356 -0
- 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 +273 -0
- package/dist/services/command-policy.js +434 -0
- package/dist/services/config.js +384 -0
- package/dist/services/container-runner.js +254 -0
- package/dist/services/container-supervisor.js +38 -0
- package/dist/services/context.js +416 -0
- package/dist/services/device-auth.js +288 -0
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -0
- package/dist/services/execution-platform.js +30 -0
- package/dist/services/file-detect.js +104 -0
- package/dist/services/file-resolver.js +199 -0
- package/dist/services/file-upload.js +126 -0
- package/dist/services/folder-key.js +22 -0
- package/dist/services/git-tools.js +429 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +85 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/instruction-resolver.js +54 -0
- package/dist/services/job-helper.js +328 -0
- package/dist/services/local-files.js +639 -0
- package/dist/services/local-tools.js +937 -0
- package/dist/services/login-flow.js +156 -0
- package/dist/services/meta.js +42 -0
- package/dist/services/mutation-coordinator.js +327 -0
- package/dist/services/mutation-groups.js +309 -0
- package/dist/services/mutation-recovery.js +159 -0
- package/dist/services/mutations.js +679 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +62 -0
- package/dist/services/packaged-update.js +403 -0
- package/dist/services/packaged.js +39 -0
- package/dist/services/permission-mode.js +78 -0
- package/dist/services/process-runner.js +412 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/result-reconciliation.js +49 -0
- package/dist/services/secure-store.js +217 -0
- package/dist/services/session-resolver.js +115 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/spinner.js +40 -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 +730 -0
- package/dist/services/workspace-registry.js +310 -0
- package/dist/services/workspace.js +580 -0
- package/dist/shell/shell-chat.js +1622 -0
- package/dist/shell/shell-commands.js +411 -0
- package/dist/shell/shell-prompt.js +110 -0
- package/dist/shell/shell-renderer.js +51 -0
- package/dist/shell/shell-router.js +37 -0
- package/dist/shell/shell.js +414 -0
- package/dist/shell/task-context-view.js +40 -0
- package/dist/staging.js +5 -0
- package/dist/types/index.js +6 -0
- package/dist/ui/agent-cards.js +111 -0
- package/dist/ui/agent-presentation.js +131 -0
- package/dist/ui/approval.js +111 -0
- package/dist/ui/banner.js +56 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +334 -0
- package/dist/ui/chat-renderer.js +463 -0
- package/dist/ui/code-block.js +52 -0
- package/dist/ui/color-picker.js +100 -0
- package/dist/ui/colors.js +55 -0
- package/dist/ui/command-details.js +11 -0
- package/dist/ui/command-filter.js +92 -0
- package/dist/ui/command-item.js +6 -0
- package/dist/ui/command-palette.js +383 -0
- package/dist/ui/command-registry.js +128 -0
- package/dist/ui/command-renderer.js +55 -0
- package/dist/ui/command-review.js +187 -0
- package/dist/ui/composer-layout.js +74 -0
- package/dist/ui/conversation.js +450 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +141 -0
- package/dist/ui/logo.js +58 -0
- package/dist/ui/markdown.js +205 -0
- package/dist/ui/message.js +21 -0
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +297 -0
- package/dist/ui/select.js +284 -0
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/spinner.js +23 -0
- package/dist/ui/sticky-stream.js +64 -0
- package/dist/ui/task-context-card.js +99 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/theme.js +80 -0
- package/dist/ui/trust.js +88 -0
- package/dist/ui/ui.js +101 -0
- package/package.json +33 -4
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Carrier OS CLI — Staging
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Staging-only build of the Carrier OS CLI. It always uses the Carrier OS staging API (`https://api.carrieros.site/v1`) for login, authentication and API requests. It stores credentials and local CLI state separately from the production CLI.
|
|
4
|
+
|
|
5
|
+
Install with `npm install --global @carrieros/cli-staging`, then run `cos-staging`.
|
|
6
|
+
|
|
7
|
+
Do not use this package for production accounts or production data.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { errorLine, info, line, success } from "../services/output.js";
|
|
2
|
+
import { c } from "../ui/colors.js";
|
|
3
|
+
/**
|
|
4
|
+
* `cos attach [file]` — attach a previously-uploaded file to the conversation so
|
|
5
|
+
* the next chat includes it. Matches by filename or file id; defaults to the most
|
|
6
|
+
* recent upload. Thin client: it only flips a local attachment flag (the file_id
|
|
7
|
+
* rides along on the next /v1/chat) — no upload, no backend change.
|
|
8
|
+
*/
|
|
9
|
+
export function registerAttach(program, ctx) {
|
|
10
|
+
program
|
|
11
|
+
.command("attach")
|
|
12
|
+
.description("Attach a previously-uploaded file to the conversation")
|
|
13
|
+
.argument("[file]", "filename or id of an upload (defaults to the most recent)")
|
|
14
|
+
.action((fileArg) => {
|
|
15
|
+
const uploads = ctx.config.get("uploads") ?? [];
|
|
16
|
+
if (uploads.length === 0) {
|
|
17
|
+
errorLine("No uploads yet. Upload one with `cos upload <file>`.");
|
|
18
|
+
process.exitCode = 1;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
let target = uploads[0]; // most recent
|
|
22
|
+
if (fileArg) {
|
|
23
|
+
const q = fileArg.toLowerCase();
|
|
24
|
+
const found = uploads.find((u) => u.file_id === fileArg ||
|
|
25
|
+
u.file_id.startsWith(fileArg) ||
|
|
26
|
+
u.filename.toLowerCase() === q);
|
|
27
|
+
if (!found) {
|
|
28
|
+
errorLine(`No upload matches "${fileArg}". Run \`cos files\` to see your uploads.`);
|
|
29
|
+
process.exitCode = 1;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
target = found;
|
|
33
|
+
}
|
|
34
|
+
if (ctx.attachedFileIds.includes(target.file_id)) {
|
|
35
|
+
info(`${target.filename} is already attached.`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
ctx.attachFile(target.file_id);
|
|
39
|
+
line();
|
|
40
|
+
success(`Attached ${target.filename}`);
|
|
41
|
+
line();
|
|
42
|
+
line(" " + c.dim("Ready to chat about it."));
|
|
43
|
+
line();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ApiError } from "../services/api.js";
|
|
2
|
+
import { DEFAULT_API_URL } from "../services/config.js";
|
|
3
|
+
import { getCliContext } from "../services/device-auth.js";
|
|
4
|
+
import { heading, info, kv, line, warn } from "../services/output.js";
|
|
5
|
+
import { withSpinner } from "../services/spinner.js";
|
|
6
|
+
/**
|
|
7
|
+
* `cos auth status` — report whether this machine has a valid session and, if
|
|
8
|
+
* so, the account + active workspace/project it is bound to. Verifies live
|
|
9
|
+
* against the server, falling back to the cached context when offline.
|
|
10
|
+
*/
|
|
11
|
+
export function registerAuth(program, ctx) {
|
|
12
|
+
const auth = program.command("auth").description("Inspect the current session");
|
|
13
|
+
auth
|
|
14
|
+
.command("status")
|
|
15
|
+
.description("Show whether you are signed in, and the active context")
|
|
16
|
+
.action(async () => {
|
|
17
|
+
const apiUrl = ctx.config.get("apiUrl") ?? DEFAULT_API_URL;
|
|
18
|
+
if (!ctx.config.isAuthenticated) {
|
|
19
|
+
heading("Authentication");
|
|
20
|
+
kv("Status", "Signed out");
|
|
21
|
+
kv("Endpoint", apiUrl);
|
|
22
|
+
line();
|
|
23
|
+
info("Run `cos login` to sign in through your browser.");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const c = await withSpinner("Checking session…", () => getCliContext(apiUrl, ctx.authProvider()));
|
|
28
|
+
heading("Authentication");
|
|
29
|
+
kv("Status", "Signed in");
|
|
30
|
+
kv("Endpoint", apiUrl);
|
|
31
|
+
if (c.account)
|
|
32
|
+
kv("Account", c.account.email);
|
|
33
|
+
if (c.workspace)
|
|
34
|
+
kv("Workspace", `${c.workspace.name} (${c.workspace.slug})`);
|
|
35
|
+
if (c.project)
|
|
36
|
+
kv("Project", `${c.project.name} · ${c.project.environment}`);
|
|
37
|
+
line();
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
const auth = ctx.config.get("auth");
|
|
41
|
+
heading("Authentication");
|
|
42
|
+
if (err instanceof ApiError && err.status === 401) {
|
|
43
|
+
kv("Status", "Session expired");
|
|
44
|
+
line();
|
|
45
|
+
info("Run `cos login` to sign in again.");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
warn(`Could not reach the server (${err instanceof ApiError ? err.code : "error"}); showing cached details.`);
|
|
49
|
+
kv("Status", "Signed in (cached)");
|
|
50
|
+
kv("Endpoint", apiUrl);
|
|
51
|
+
if (auth?.account)
|
|
52
|
+
kv("Account", auth.account.email);
|
|
53
|
+
if (auth?.workspace)
|
|
54
|
+
kv("Workspace", auth.workspace.name);
|
|
55
|
+
if (auth?.project)
|
|
56
|
+
kv("Project", auth.project.name);
|
|
57
|
+
line();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { ApiError } from "../services/api.js";
|
|
2
|
+
import { errorLine, line } from "../services/output.js";
|
|
3
|
+
import { withSpinner } from "../services/spinner.js";
|
|
4
|
+
import { showBtwPanel } from "../ui/btw-overlay.js";
|
|
5
|
+
import { c } from "../ui/colors.js";
|
|
6
|
+
/**
|
|
7
|
+
* `/btw <question>` — a side question about the current conversation.
|
|
8
|
+
*
|
|
9
|
+
* Answered from the conversation's context and shown in a temporary panel. It
|
|
10
|
+
* is NOT a chat turn: nothing is written to the session, which is why it calls
|
|
11
|
+
* POST /v1/sessions/:id/ask rather than /v1/chat (that endpoint always persists
|
|
12
|
+
* both turns).
|
|
13
|
+
*
|
|
14
|
+
* Everything the normal chat path adds — model/mode selection, attachments,
|
|
15
|
+
* web search, fast mode, HIPWR — is deliberately absent from the request. The
|
|
16
|
+
* backend route has no access to any of it either, so a side question cannot
|
|
17
|
+
* quietly become a real one.
|
|
18
|
+
*/
|
|
19
|
+
export async function askSideQuestion(ctx, client, question,
|
|
20
|
+
/**
|
|
21
|
+
* True while a main turn is rendering. The turn owns the transient region for
|
|
22
|
+
* its word-by-word reveal, so the answer is COMMITTED to the transcript
|
|
23
|
+
* instead of shown as a dismissible panel — two owners of that region would
|
|
24
|
+
* overwrite each other. It stays visually distinct either way.
|
|
25
|
+
*/
|
|
26
|
+
inlineOnly = false) {
|
|
27
|
+
const trimmed = question.trim();
|
|
28
|
+
if (!trimmed) {
|
|
29
|
+
errorLine("Usage: /btw <question>");
|
|
30
|
+
line(" " + c.dim("Ask about this conversation without adding to it, e.g."));
|
|
31
|
+
line(" " + c.cmd("/btw which file did we decide on?"));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const sessionId = ctx.config.get("sessionId");
|
|
35
|
+
if (!sessionId) {
|
|
36
|
+
errorLine("No active conversation to ask about.");
|
|
37
|
+
line(" " + c.dim("Send a message first, or pick one with ") + c.cmd("/sessions") + c.dim("."));
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Echo the side question so the transcript shows what was asked, distinct
|
|
41
|
+
// from a normal turn's "❯ message".
|
|
42
|
+
line();
|
|
43
|
+
line(" " +
|
|
44
|
+
c.magic("↳ BTW: ") +
|
|
45
|
+
c.dim(trimmed) +
|
|
46
|
+
// Without a spinner (see below) this is the only sign it is working.
|
|
47
|
+
(inlineOnly ? c.dim(" · thinking…") : ""));
|
|
48
|
+
try {
|
|
49
|
+
// No spinner while a main turn is running. Its activity timeline repaints
|
|
50
|
+
// the transient region every 80ms and so does withSpinner — two writers
|
|
51
|
+
// alternating in the same region is a visible flicker for the whole
|
|
52
|
+
// request. The committed "↳ BTW:" line above already shows it is in flight.
|
|
53
|
+
const result = inlineOnly
|
|
54
|
+
? await client.askAboutSession(sessionId, trimmed)
|
|
55
|
+
: await withSpinner(c.dim("By the way…"), () => client.askAboutSession(sessionId, trimmed));
|
|
56
|
+
await showBtwPanel({ answer: result.answer, note: `Answered by ${result.model}.` }, { commit: inlineOnly });
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// A failed aside must never read like a failed conversation — say plainly
|
|
60
|
+
// that the conversation is untouched, and let them carry on.
|
|
61
|
+
const message = err instanceof ApiError
|
|
62
|
+
? err.code === "NETWORK_ERROR"
|
|
63
|
+
? "Could not reach the API."
|
|
64
|
+
: err.message
|
|
65
|
+
: "Unable to answer this side question.";
|
|
66
|
+
await showBtwPanel({ answer: null, error: message }, { commit: inlineOnly });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** `cos btw <question...>` — the same side question outside the shell. */
|
|
70
|
+
export function registerBtw(program, ctx) {
|
|
71
|
+
program
|
|
72
|
+
.command("btw")
|
|
73
|
+
.description("Ask a quick side question without adding it to the conversation")
|
|
74
|
+
.argument("[question...]", "what to ask about the current conversation")
|
|
75
|
+
.action(async (words) => {
|
|
76
|
+
await askSideQuestion(ctx, ctx.requireAuth(), (words ?? []).join(" "));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { confirm } from "@inquirer/prompts";
|
|
3
|
+
import { readJournal } from "../services/checkpoints.js";
|
|
4
|
+
import { activeRepository, inWorkspaceMode, listRepositories, resolveRepository } from "../services/workspace-registry.js";
|
|
5
|
+
import { APPROVAL_TIMEOUT_MS, MutationError, applyPlan, planMutation } from "../services/mutations.js";
|
|
6
|
+
import { errorLine, line, timeAgo } from "../services/output.js";
|
|
7
|
+
import { renderGroup } from "../ui/change-review.js";
|
|
8
|
+
import { c } from "../ui/colors.js";
|
|
9
|
+
import { approveInScreen, inScreen } from "../ui/screen-prompt.js";
|
|
10
|
+
import { sectionHeader } from "../ui/ui.js";
|
|
11
|
+
/**
|
|
12
|
+
* `cos changes` and `cos undo` — the local record of approved file changes.
|
|
13
|
+
*
|
|
14
|
+
* Both read the change journal the CLI keeps in its own app-data folder. Undo
|
|
15
|
+
* is itself a change: it is planned, shown as a diff and approved exactly like
|
|
16
|
+
* one the model proposed, and it refuses when the file has moved on since.
|
|
17
|
+
*/
|
|
18
|
+
export function registerChanges(program, ctx) {
|
|
19
|
+
program
|
|
20
|
+
.command("changes")
|
|
21
|
+
.description("List file changes Carrier OS applied in this project")
|
|
22
|
+
.action(() => showChanges());
|
|
23
|
+
program
|
|
24
|
+
.command("undo")
|
|
25
|
+
.argument("[operation]", "operation id to undo (defaults to the latest)")
|
|
26
|
+
.option("--repo <repository>", "undo in a named repository instead of the active one")
|
|
27
|
+
.description("Undo the latest file change Carrier OS applied")
|
|
28
|
+
.action(async (operation, options) => {
|
|
29
|
+
let client;
|
|
30
|
+
try {
|
|
31
|
+
client = ctx.config.isAuthenticated ? ctx.requireAuth() : undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
client = undefined;
|
|
35
|
+
}
|
|
36
|
+
await runUndo(client, operation, options?.repo);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
const VERB = {
|
|
40
|
+
create_file: "created",
|
|
41
|
+
write_file: "overwrote",
|
|
42
|
+
edit_file: "edited",
|
|
43
|
+
delete_file: "deleted",
|
|
44
|
+
revert_change: "reverted"
|
|
45
|
+
};
|
|
46
|
+
function entryLines(e, indent) {
|
|
47
|
+
const state = e.status === "ROLLED_BACK" ? c.warn("undone") : e.status === "FAILED" ? c.err("failed") : c.ok("applied");
|
|
48
|
+
line(indent + state + " " + c.value(VERB[e.action] ?? e.action) + " " + c.file(e.path) +
|
|
49
|
+
c.dim(` +${e.added} −${e.removed} · ${timeAgo(e.created_at)}`));
|
|
50
|
+
line(indent + " " + c.dim(e.operation_id) + (e.reverts ? c.dim(` (undid ${e.reverts})`) : ""));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The change journal.
|
|
54
|
+
*
|
|
55
|
+
* Each repository keeps its own journal, and the list says so rather than
|
|
56
|
+
* merging them: two repositories can hold the same relative path, and an undo
|
|
57
|
+
* only ever applies within one repository, so a single flat list would invite
|
|
58
|
+
* exactly the mistake the split prevents.
|
|
59
|
+
*/
|
|
60
|
+
export function showChanges(limit = 20) {
|
|
61
|
+
const repositories = inWorkspaceMode() ? listRepositories() : [activeRepository()];
|
|
62
|
+
const groups = repositories
|
|
63
|
+
.map((repo) => ({ repo, entries: readJournal(repo.root).slice(-limit).reverse() }))
|
|
64
|
+
.filter((g) => g.entries.length > 0);
|
|
65
|
+
line(sectionHeader("Changes"));
|
|
66
|
+
if (groups.length === 0) {
|
|
67
|
+
line(" " + c.dim(inWorkspaceMode() ? "No file changes have been applied in this workspace." : "No file changes have been applied in this project."));
|
|
68
|
+
line();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const multi = inWorkspaceMode();
|
|
72
|
+
for (const g of groups) {
|
|
73
|
+
if (multi) {
|
|
74
|
+
line(" " + c.title(g.repo.name) + (g.repo.id === activeRepository().id ? c.dim(" (active)") : ""));
|
|
75
|
+
for (const e of g.entries)
|
|
76
|
+
entryLines(e, " ");
|
|
77
|
+
line();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
for (const e of g.entries)
|
|
81
|
+
entryLines(e, " ");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!multi)
|
|
85
|
+
line();
|
|
86
|
+
line(" " + c.dim("Undo the latest with ") + c.cmd("/undo") + c.dim(", or a specific one with ") + c.cmd("/undo <operation id>"));
|
|
87
|
+
if (multi) {
|
|
88
|
+
line(" " + c.dim("Undo in another repository with ") + c.cmd("/undo --repo <name>") + c.dim(" — never across repositories."));
|
|
89
|
+
}
|
|
90
|
+
line();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Undo one applied change, with the same diff-and-approve step as any change.
|
|
94
|
+
*
|
|
95
|
+
* The repository is resolved FIRST and explicitly. `/undo` means "the latest
|
|
96
|
+
* change in the active repository"; undoing one somewhere else takes
|
|
97
|
+
* `--repo <name>`, so a change in another repository is never undone because it
|
|
98
|
+
* happened to be the most recent thing anywhere.
|
|
99
|
+
*/
|
|
100
|
+
export async function runUndo(client, operationId, repository) {
|
|
101
|
+
const id = `undo_${crypto.randomBytes(12).toString("hex")}`;
|
|
102
|
+
let handle;
|
|
103
|
+
try {
|
|
104
|
+
handle = repository ? resolveRepository(repository) : activeRepository();
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
errorLine(err.message);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
let plan;
|
|
111
|
+
try {
|
|
112
|
+
plan = planMutation({
|
|
113
|
+
tool_call_id: id,
|
|
114
|
+
name: "revert_change",
|
|
115
|
+
arguments: {
|
|
116
|
+
operation_id: operationId?.trim() || undefined,
|
|
117
|
+
repository: repository ? handle.name : undefined,
|
|
118
|
+
reason: "Undo requested with /undo."
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
const e = err;
|
|
124
|
+
line();
|
|
125
|
+
line(" " + c.warn("⊘") + " " + c.dim(e.message));
|
|
126
|
+
line();
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
for (const l of renderGroup([plan]))
|
|
130
|
+
line(l);
|
|
131
|
+
let approved;
|
|
132
|
+
if (inScreen()) {
|
|
133
|
+
approved = (await approveInScreen({ question: "Undo this change?", timeoutMs: APPROVAL_TIMEOUT_MS })) === "approve";
|
|
134
|
+
}
|
|
135
|
+
else if (process.stdin.isTTY) {
|
|
136
|
+
try {
|
|
137
|
+
approved = await confirm({ message: "Undo this change?", default: false });
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
approved = false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
approved = false; // nobody to ask — never undo unattended
|
|
145
|
+
}
|
|
146
|
+
if (!approved) {
|
|
147
|
+
line(" " + c.warn("⊘") + " " + c.dim("Not undone — nothing changed."));
|
|
148
|
+
line();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const applied = applyPlan(plan);
|
|
153
|
+
line(" " + c.ok("✓") + " " + c.value(`Restored ${applied.rel}`) + c.dim(` (undid ${plan.reverts})`));
|
|
154
|
+
line();
|
|
155
|
+
// The server audit is best-effort and metadata-only; the undo already happened.
|
|
156
|
+
if (client && plan.reverts && /^ct_/.test(plan.reverts)) {
|
|
157
|
+
await client
|
|
158
|
+
.recordMutationAudit({ operation_id: plan.reverts, status: "ROLLED_BACK", checkpoint_id: applied.checkpointId })
|
|
159
|
+
.catch(() => undefined);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
const e = err instanceof MutationError ? err : new MutationError("WRITE_FAILED", err.message);
|
|
164
|
+
line(" " + c.err("✗") + " " + c.value(e.message));
|
|
165
|
+
line();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { info, line, printBanner } from "../services/output.js";
|
|
4
|
+
import { clearActiveSession, listSessions } from "../services/session-resolver.js";
|
|
5
|
+
import { showContext } from "./context.js";
|
|
6
|
+
import { showHistory } from "./history.js";
|
|
7
|
+
import { newSession, pickSession, renderSessionList, switchTo } from "./sessions.js";
|
|
8
|
+
import { chatTurn, chatTypeLabelShort, loadModels, loadModes, modeLabelShort, modelLabelShort, armWebSearch, isWebSearchStateArg, openSource, pickChatType, pickMode, pickModel, searchNow, setChatType, setFast, setHighPower, setMode, setModel, setWebSearch, showSources, loadFastModel } from "../shell/shell-chat.js";
|
|
9
|
+
/**
|
|
10
|
+
* `cos chat` — a focused interactive REPL over POST /v1/chat. (The full
|
|
11
|
+
* shell — `cos` with no command — is a superset with every slash command.)
|
|
12
|
+
* All chat/mode/model logic is shared via shell-chat.ts; this is just the loop.
|
|
13
|
+
*/
|
|
14
|
+
export function registerChat(program, ctx) {
|
|
15
|
+
program
|
|
16
|
+
.command("chat")
|
|
17
|
+
.description("Start a focused interactive chat session")
|
|
18
|
+
.argument("[message...]", "an optional first message to send immediately (uses attached files)")
|
|
19
|
+
.option("-m, --mode <mode>", "Carrier mode (general, code, research, …)")
|
|
20
|
+
.option("--model <model>", "provider model override (e.g. gpt-5.5); 'auto' to clear")
|
|
21
|
+
.option("--standard", "start in Standard chat (the default)")
|
|
22
|
+
.action(async (messageParts, opts) => {
|
|
23
|
+
// Mode follows the chat type (Carrier → General, Standard → saved or
|
|
24
|
+
// Auto); an explicit -m flag overrides it for this run.
|
|
25
|
+
if (opts.mode)
|
|
26
|
+
ctx.config.set("mode", opts.mode);
|
|
27
|
+
if (opts.model !== undefined)
|
|
28
|
+
ctx.config.set("model", opts.model === "auto" ? "" : opts.model);
|
|
29
|
+
// Standard is the default; --standard explicitly clears the active
|
|
30
|
+
// session so its next message starts a fresh Standard conversation.
|
|
31
|
+
if (opts.standard)
|
|
32
|
+
ctx.setChatType("standard");
|
|
33
|
+
// e.g. `cos chat "Summarize this file"` — send it right away (with any
|
|
34
|
+
// attached file_ids), then continue into the REPL for follow-ups.
|
|
35
|
+
const initial = (messageParts ?? []).join(" ").trim();
|
|
36
|
+
await runChat(ctx, initial || undefined);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export async function runChat(ctx, initialMessage) {
|
|
40
|
+
const client = ctx.requireAuth();
|
|
41
|
+
// Preload modes + models so the banner can show friendly labels (best-effort).
|
|
42
|
+
await Promise.all([loadModels(client).catch(() => []), loadModes(client).catch(() => []), loadFastModel(client)]);
|
|
43
|
+
printBanner(ctx.config.get("scope"), modeLabelShort(ctx), modelLabelShort(ctx));
|
|
44
|
+
info(`${chatTypeLabelShort(ctx)} · type /chat to switch (carrier / standard)`);
|
|
45
|
+
// A message passed on the command line (`cos chat "…"`) is sent immediately —
|
|
46
|
+
// with any attached files — before the interactive loop takes over.
|
|
47
|
+
if (initialMessage) {
|
|
48
|
+
await chatTurn(ctx, client, initialMessage);
|
|
49
|
+
}
|
|
50
|
+
for (;;) {
|
|
51
|
+
let message;
|
|
52
|
+
try {
|
|
53
|
+
message = (await input({ message: chalk.cyan(">") })).trim();
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
line();
|
|
57
|
+
info("Session ended.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (!message)
|
|
61
|
+
continue;
|
|
62
|
+
// Parse by the first word so /models and /model aren't shadowed by /mode.
|
|
63
|
+
const cmdWord = message.split(/\s+/)[0].toLowerCase();
|
|
64
|
+
const argStr = message.slice(cmdWord.length).trim();
|
|
65
|
+
if (cmdWord === "/exit" || cmdWord === "/quit") {
|
|
66
|
+
info("Session ended.");
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (cmdWord === "/help") {
|
|
70
|
+
printSlashHelp();
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (cmdWord === "/new") {
|
|
74
|
+
await newSession(ctx, argStr.trim());
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (cmdWord === "/clear") {
|
|
78
|
+
clearActiveSession(ctx);
|
|
79
|
+
info("Cleared. Your next message starts a fresh session.");
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (cmdWord === "/sessions") {
|
|
83
|
+
const { conversations, total } = await listSessions(ctx, client, { limit: 20 });
|
|
84
|
+
renderSessionList(conversations, ctx.config.get("sessionId"), total);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (cmdWord === "/session") {
|
|
88
|
+
if (!argStr.trim())
|
|
89
|
+
await pickSession(ctx, client);
|
|
90
|
+
else
|
|
91
|
+
await switchTo(ctx, client, argStr.trim());
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (cmdWord === "/history") {
|
|
95
|
+
await showHistory(ctx, client, argStr.trim() || undefined);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (cmdWord === "/context") {
|
|
99
|
+
await showContext(ctx, client);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (cmdWord === "/chat") {
|
|
103
|
+
setChatType(ctx, argStr);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (cmdWord === "/switch") {
|
|
107
|
+
if (argStr.trim())
|
|
108
|
+
setChatType(ctx, argStr);
|
|
109
|
+
else
|
|
110
|
+
await pickChatType(ctx);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (cmdWord === "/modes") {
|
|
114
|
+
await pickMode(ctx, client);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (cmdWord === "/mode") {
|
|
118
|
+
await setMode(ctx, client, argStr);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (cmdWord === "/models") {
|
|
122
|
+
await pickModel(ctx, client);
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (cmdWord === "/model") {
|
|
126
|
+
await setModel(ctx, client, argStr);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (cmdWord === "/websearch" || cmdWord === "/web") {
|
|
130
|
+
if (!argStr)
|
|
131
|
+
armWebSearch(ctx);
|
|
132
|
+
else if (isWebSearchStateArg(argStr))
|
|
133
|
+
setWebSearch(ctx, argStr);
|
|
134
|
+
else
|
|
135
|
+
await searchNow(ctx, client, argStr);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (cmdWord === "/fast") {
|
|
139
|
+
await setFast(ctx, argStr, client);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (cmdWord === "/hipwr" || cmdWord === "/highpower") {
|
|
143
|
+
setHighPower(ctx, argStr);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (cmdWord === "/sources") {
|
|
147
|
+
showSources(ctx);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (cmdWord === "/open") {
|
|
151
|
+
openSource(ctx, argStr);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
await chatTurn(ctx, client, message);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function printSlashHelp() {
|
|
158
|
+
line();
|
|
159
|
+
line(chalk.dim(" In-chat commands:"));
|
|
160
|
+
line(` ${chalk.cyan("/switch")} switch chat: Carrier ⇄ Standard (picker)`);
|
|
161
|
+
line(` ${chalk.cyan("/chat")} switch experience: /chat carrier | /chat standard`);
|
|
162
|
+
line(` ${chalk.cyan("/modes")} list Carrier modes (behavior)`);
|
|
163
|
+
line(` ${chalk.cyan("/mode <id>")} switch Carrier mode (e.g. /mode code)`);
|
|
164
|
+
line(` ${chalk.cyan("/models")} list provider models (GPT, Grok, …)`);
|
|
165
|
+
line(` ${chalk.cyan("/model <id>")} set model override (e.g. gpt-5.5), or /model auto`);
|
|
166
|
+
line(` ${chalk.cyan("/websearch")} search the web on your next message`);
|
|
167
|
+
line(` ${chalk.cyan("/websearch <q>")} search for something right now`);
|
|
168
|
+
line(` ${chalk.cyan("/fast")} toggle fast mode (quicker, less refinement)`);
|
|
169
|
+
line(` ${chalk.cyan("/hipwr")} toggle High Power (4-pass refinement)`);
|
|
170
|
+
line(` ${chalk.cyan("/sources")} sources from the last search`);
|
|
171
|
+
line(` ${chalk.cyan("/open <n>")} open a source in your browser`);
|
|
172
|
+
line();
|
|
173
|
+
line(` ${chalk.cyan("/new [title]")} start a new conversation`);
|
|
174
|
+
line(` ${chalk.cyan("/sessions")} list conversations, numbered`);
|
|
175
|
+
line(` ${chalk.cyan("/session <n>")} continue session n`);
|
|
176
|
+
line(` ${chalk.cyan("/history [n]")} transcript of n (or the active session)`);
|
|
177
|
+
line(` ${chalk.cyan("/context")} what your next message is sent with`);
|
|
178
|
+
line(` ${chalk.cyan("/session")} show the current session id`);
|
|
179
|
+
line(` ${chalk.cyan("/help")} show this help`);
|
|
180
|
+
line(` ${chalk.cyan("/exit")} leave the chat`);
|
|
181
|
+
line();
|
|
182
|
+
}
|