@carrieros/cli 0.2.0 → 0.3.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 +142 -57
- package/dist/commands/attach.js +45 -0
- package/dist/commands/btw.js +78 -0
- package/dist/commands/changes.js +167 -0
- package/dist/commands/chat.js +80 -14
- package/dist/commands/context.js +160 -0
- package/dist/commands/doctor.js +46 -1
- package/dist/commands/files.js +84 -23
- package/dist/commands/help.js +1 -0
- package/dist/commands/history.js +88 -23
- package/dist/commands/login.js +31 -7
- package/dist/commands/memory.js +162 -0
- package/dist/commands/mode-model.js +39 -3
- package/dist/commands/modes.js +4 -1
- 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/search.js +92 -0
- package/dist/commands/sessions.js +219 -65
- package/dist/commands/settings.js +87 -0
- package/dist/commands/update.js +159 -0
- package/dist/commands/upload.js +204 -31
- package/dist/commands/usage.js +212 -16
- package/dist/ide/editor-context.js +172 -0
- package/dist/ide/ide-session.js +94 -0
- package/dist/ide/tool-host.js +109 -0
- package/dist/main.js +26 -1
- package/dist/services/api.js +140 -6
- package/dist/services/chat-stream.js +145 -0
- package/dist/services/checkpoints.js +116 -0
- package/dist/services/client-tools.js +260 -0
- package/dist/services/command-coordinator.js +200 -0
- package/dist/services/command-policy.js +404 -0
- package/dist/services/config.js +247 -22
- package/dist/services/context.js +265 -20
- package/dist/services/device-auth.js +42 -30
- package/dist/services/diff.js +196 -0
- package/dist/services/env-policy.js +108 -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/git-tools.js +248 -0
- package/dist/services/glob-match.js +164 -0
- package/dist/services/helper-bin.js +64 -0
- package/dist/services/ignore-rules.js +189 -0
- package/dist/services/job-helper.js +307 -0
- package/dist/services/local-files.js +517 -0
- package/dist/services/local-tools.js +432 -0
- package/dist/services/login-flow.js +15 -8
- package/dist/services/meta.js +3 -1
- package/dist/services/mutation-coordinator.js +161 -0
- package/dist/services/mutations.js +493 -0
- package/dist/services/open-url.js +68 -0
- package/dist/services/output.js +5 -2
- package/dist/services/packaged.js +24 -0
- package/dist/services/process-runner.js +406 -0
- package/dist/services/project-context.js +298 -0
- package/dist/services/redaction.js +201 -0
- package/dist/services/secure-store.js +197 -0
- package/dist/services/session-resolver.js +108 -0
- package/dist/services/sia.js +51 -0
- package/dist/services/update.js +286 -0
- package/dist/services/workspace-registry.js +309 -0
- package/dist/services/workspace.js +573 -0
- package/dist/shell/shell-chat.js +1028 -57
- package/dist/shell/shell-commands.js +200 -11
- package/dist/shell/shell-prompt.js +81 -8
- package/dist/shell/shell-renderer.js +7 -19
- package/dist/shell/shell-router.js +19 -3
- package/dist/shell/shell.js +185 -17
- package/dist/types/index.js +3 -1
- package/dist/ui/approval.js +81 -0
- package/dist/ui/banner.js +39 -0
- package/dist/ui/btw-overlay.js +230 -0
- package/dist/ui/change-review.js +87 -0
- package/dist/ui/chat-renderer.js +206 -13
- package/dist/ui/colors.js +4 -0
- package/dist/ui/command-filter.js +26 -5
- package/dist/ui/command-palette.js +17 -4
- package/dist/ui/command-registry.js +84 -9
- package/dist/ui/command-review.js +138 -0
- package/dist/ui/composer-layout.js +41 -0
- package/dist/ui/conversation.js +398 -0
- package/dist/ui/interrupt.js +35 -0
- package/dist/ui/live.js +3 -1
- package/dist/ui/markdown.js +63 -9
- package/dist/ui/message.js +14 -31
- package/dist/ui/screen-prompt.js +181 -0
- package/dist/ui/screen.js +1 -1
- package/dist/ui/select.js +185 -29
- package/dist/ui/sia-qa.js +213 -0
- package/dist/ui/text-prompt.js +74 -0
- package/dist/ui/trust.js +93 -0
- package/dist/ui/ui.js +4 -1
- package/package.json +13 -2
- package/dist/ui/activity.js +0 -77
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { ApiError } from "../services/api.js";
|
|
2
|
+
import { buildStructuredIntent } from "../services/sia.js";
|
|
3
|
+
import { line } from "../services/output.js";
|
|
4
|
+
import { withSpinner } from "../services/spinner.js";
|
|
5
|
+
import { c } from "./colors.js";
|
|
6
|
+
import { pickFromList, SELECT_BACK } from "./select.js";
|
|
7
|
+
import { askTextInScreen, inScreen, pickInScreen } from "./screen-prompt.js";
|
|
8
|
+
import { askText } from "./text-prompt.js";
|
|
9
|
+
/**
|
|
10
|
+
* Inside the shell, prompts draw into the transcript so the banner and the
|
|
11
|
+
* conversation stay visible above them. Outside it (`cos chat`, a pipe) there
|
|
12
|
+
* is no screen engine, so the terminal-owning versions are used instead.
|
|
13
|
+
*/
|
|
14
|
+
const ask = (opts) => inScreen() ? pickInScreen(opts) : pickFromList(opts);
|
|
15
|
+
/**
|
|
16
|
+
* SIA clarification — the terminal counterpart of the website's Q&A overlay.
|
|
17
|
+
*
|
|
18
|
+
* Before an ambiguous prompt is sent, the API is asked what it would need to
|
|
19
|
+
* know; the answers are appended to the prompt and THAT is what gets sent. The
|
|
20
|
+
* questions are a way to write a better prompt, not a separate request — see
|
|
21
|
+
* services/sia.ts for the merge format both clients share.
|
|
22
|
+
*
|
|
23
|
+
* Failures are non-blocking but NOT silent. If the API is unreachable or
|
|
24
|
+
* refuses, the original prompt still goes out — clarification must never be the
|
|
25
|
+
* reason a message can't be sent — but one dim line says so, because with SIA
|
|
26
|
+
* on by default a swallowed error is indistinguishable from the backend
|
|
27
|
+
* deciding no clarification was needed.
|
|
28
|
+
*/
|
|
29
|
+
/** Sentinel values that can't collide with a real option value. */
|
|
30
|
+
const OTHER = "\u0000other";
|
|
31
|
+
const SKIP = "\u0000skip";
|
|
32
|
+
const unchanged = (prompt) => ({ prompt, cancelled: false });
|
|
33
|
+
/** Options for one question, plus the two escapes every question offers. */
|
|
34
|
+
function choicesFor(q) {
|
|
35
|
+
const base = q.type === "yn"
|
|
36
|
+
? [
|
|
37
|
+
{ value: "true", label: "Yes" },
|
|
38
|
+
{ value: "false", label: "No" }
|
|
39
|
+
]
|
|
40
|
+
: (q.options ?? []).map((o) => ({
|
|
41
|
+
value: o.value,
|
|
42
|
+
label: o.label,
|
|
43
|
+
description: o.description
|
|
44
|
+
}));
|
|
45
|
+
// No descriptions on these two: the labels already say it, and every
|
|
46
|
+
// description is a row taken from the answers that need one.
|
|
47
|
+
return [...base, { value: OTHER, label: "Other…" }, { value: SKIP, label: "Skip this question" }];
|
|
48
|
+
}
|
|
49
|
+
/** Word-wrap to `width` columns. */
|
|
50
|
+
function wrap(text, width) {
|
|
51
|
+
const w = Math.max(20, width);
|
|
52
|
+
const out = [];
|
|
53
|
+
let cur = "";
|
|
54
|
+
for (const word of text.trim().split(/\s+/).filter(Boolean)) {
|
|
55
|
+
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
56
|
+
out.push(cur);
|
|
57
|
+
cur = word;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (cur)
|
|
64
|
+
out.push(cur);
|
|
65
|
+
return out.length ? out : [""];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The block above the options.
|
|
69
|
+
*
|
|
70
|
+
* It restates the prompt on EVERY question, which is not redundancy: a picker
|
|
71
|
+
* takes over the terminal from the shell's screen engine, so the banner and the
|
|
72
|
+
* echoed message are in a buffer the user cannot scroll back to while answering.
|
|
73
|
+
* Without this, the questions appear with no visible sign of what they are about.
|
|
74
|
+
*/
|
|
75
|
+
/** Wrap, then hard-limit to `max` lines, marking the cut on the last one. */
|
|
76
|
+
function clampLines(text, width, max) {
|
|
77
|
+
const lines = wrap(text, width);
|
|
78
|
+
if (lines.length <= max)
|
|
79
|
+
return lines;
|
|
80
|
+
const shown = lines.slice(0, max);
|
|
81
|
+
shown[max - 1] = shown[max - 1].replace(/.{0,2}$/, "…");
|
|
82
|
+
return shown;
|
|
83
|
+
}
|
|
84
|
+
function siaHeader(prompt, q, index, total) {
|
|
85
|
+
return (width) => {
|
|
86
|
+
// Every row here is a row of your conversation pushed off screen, and the
|
|
87
|
+
// transcript only gets terminal-height minus the composer. So both blocks
|
|
88
|
+
// are capped: one line to recognise your own message, three for the
|
|
89
|
+
// question — the model pads these to 1-3 sentences and the ask is at the
|
|
90
|
+
// front. The options and their descriptions are what the rows are for.
|
|
91
|
+
const promptLine = clampLines(prompt, width - 2, 1);
|
|
92
|
+
return [
|
|
93
|
+
" " + c.brand("─".repeat(width)),
|
|
94
|
+
" " + c.dim("❯ ") + c.dim(promptLine[0]),
|
|
95
|
+
"",
|
|
96
|
+
" " + c.brand.bold(`Question ${index + 1} of ${total}`),
|
|
97
|
+
...clampLines(q.text, width, 3).map((l) => " " + c.value(l))
|
|
98
|
+
];
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Index of the choice matching an already-given answer, so stepping back lands
|
|
102
|
+
* on what was picked last time rather than resetting to the top. */
|
|
103
|
+
function initialIndex(choices, previous) {
|
|
104
|
+
if (previous === undefined)
|
|
105
|
+
return 0;
|
|
106
|
+
const want = typeof previous === "boolean" ? String(previous) : previous;
|
|
107
|
+
const at = choices.findIndex((ch) => ch.value === want);
|
|
108
|
+
return at === -1 ? 0 : at;
|
|
109
|
+
}
|
|
110
|
+
/** Ask one question. null = cancelled, "back" = step to the previous question. */
|
|
111
|
+
async function askOne(prompt, q, index, total, previous, canGoBack) {
|
|
112
|
+
const heading = `Question ${index + 1} of ${total}`;
|
|
113
|
+
// An "open" question has nothing to pick from — go straight to free text.
|
|
114
|
+
// There is no list to press ← in, so it is the one step without back.
|
|
115
|
+
if (q.type === "open") {
|
|
116
|
+
const typed = inScreen()
|
|
117
|
+
? await askTextInScreen(siaHeader(prompt, q, index, total), q.placeholder)
|
|
118
|
+
: await askText(`${heading} ${q.text}`, q.placeholder ?? "Enter to skip");
|
|
119
|
+
return { answer: typed };
|
|
120
|
+
}
|
|
121
|
+
const choices = choicesFor(q);
|
|
122
|
+
const picked = await ask({
|
|
123
|
+
title: heading,
|
|
124
|
+
header: siaHeader(prompt, q, index, total),
|
|
125
|
+
choices,
|
|
126
|
+
initial: initialIndex(choices, previous),
|
|
127
|
+
allowBack: canGoBack,
|
|
128
|
+
// "prev/next" rather than "question": it says you can move BOTH ways
|
|
129
|
+
// through the set, which the noun alone left you to guess.
|
|
130
|
+
backHint: "prev/next question",
|
|
131
|
+
// The descriptions ARE the decision here — a clipped one hides what's
|
|
132
|
+
// being chosen between.
|
|
133
|
+
stacked: true,
|
|
134
|
+
// Esc abandons the message, which "cancel" badly understates when the row
|
|
135
|
+
// above it says "Skip this question".
|
|
136
|
+
cancelHint: "discard message"
|
|
137
|
+
});
|
|
138
|
+
// Esc / Ctrl+C. The website treats Esc as "send it anyway", but in a terminal
|
|
139
|
+
// that gesture means abort — and sending a prompt someone tried to cancel
|
|
140
|
+
// spends real money. So it stops the turn, and "Skip this question" is the
|
|
141
|
+
// explicit way to move past one.
|
|
142
|
+
if (picked === null)
|
|
143
|
+
return null;
|
|
144
|
+
if (picked === SELECT_BACK)
|
|
145
|
+
return "back";
|
|
146
|
+
if (picked === SKIP)
|
|
147
|
+
return { answer: null };
|
|
148
|
+
if (picked === OTHER) {
|
|
149
|
+
const typed = inScreen()
|
|
150
|
+
? await askTextInScreen(siaHeader(prompt, q, index, total), q.placeholder)
|
|
151
|
+
: await askText(q.text, q.placeholder ?? "Your answer");
|
|
152
|
+
return { answer: typed };
|
|
153
|
+
}
|
|
154
|
+
if (q.type === "yn")
|
|
155
|
+
return { answer: picked === "true" };
|
|
156
|
+
return { answer: picked };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Run the clarification pass for `message`.
|
|
160
|
+
*
|
|
161
|
+
* @param onLookup called when the API round-trip starts, so a caller with a
|
|
162
|
+
* pinned composer can clear its own status area first.
|
|
163
|
+
*/
|
|
164
|
+
export async function clarifyIntent(client, message, onLookup) {
|
|
165
|
+
onLookup?.();
|
|
166
|
+
let questions;
|
|
167
|
+
try {
|
|
168
|
+
const res = await withSpinner(c.dim("Clarifying intent…"), () => client.siaQuestions(message));
|
|
169
|
+
if (res.skip || res.questions.length === 0)
|
|
170
|
+
return unchanged(message);
|
|
171
|
+
questions = res.questions;
|
|
172
|
+
}
|
|
173
|
+
catch (err) {
|
|
174
|
+
// Unreachable, unauthorized, rate-limited — none of it should block a chat,
|
|
175
|
+
// so the prompt still goes out unchanged.
|
|
176
|
+
//
|
|
177
|
+
// But it must not be SILENT. With SIA on by default, a swallowed failure is
|
|
178
|
+
// indistinguishable from the backend deciding no clarification was needed —
|
|
179
|
+
// so an expired token looks exactly like SIA working correctly, forever.
|
|
180
|
+
// One dim line is enough to tell the two apart.
|
|
181
|
+
line(" " +
|
|
182
|
+
c.dim("↳ SIA unavailable — sending as typed. ") +
|
|
183
|
+
c.dim(err instanceof ApiError ? "(" + err.code + ")" : ""));
|
|
184
|
+
return unchanged(message);
|
|
185
|
+
}
|
|
186
|
+
// No "a few questions first" banner: it would be written into the shell's
|
|
187
|
+
// transcript, which the picker is about to suspend — so it would be invisible
|
|
188
|
+
// during the Q&A and a stray line afterwards. The count lives in each
|
|
189
|
+
// question's own header instead.
|
|
190
|
+
//
|
|
191
|
+
// A cursor rather than a for-loop: ← steps back, and answers survive the
|
|
192
|
+
// round trip so revisiting a question shows what you already chose.
|
|
193
|
+
const answers = {};
|
|
194
|
+
let i = 0;
|
|
195
|
+
while (i < questions.length) {
|
|
196
|
+
const q = questions[i];
|
|
197
|
+
const result = await askOne(message, q, i, questions.length, answers[q.key], i > 0);
|
|
198
|
+
if (result === null)
|
|
199
|
+
return { prompt: message, cancelled: true };
|
|
200
|
+
if (result === "back") {
|
|
201
|
+
i -= 1;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
// Skipping clears any earlier answer — otherwise going back to un-answer a
|
|
205
|
+
// question would silently keep the old value in the prompt.
|
|
206
|
+
if (result.answer === null)
|
|
207
|
+
delete answers[q.key];
|
|
208
|
+
else
|
|
209
|
+
answers[q.key] = result.answer;
|
|
210
|
+
i += 1;
|
|
211
|
+
}
|
|
212
|
+
return { prompt: buildStructuredIntent(message, answers), cancelled: false };
|
|
213
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { resumeScreen, screenActive, suspendScreen } from "./screen.js";
|
|
4
|
+
import { termWidth } from "./ui.js";
|
|
5
|
+
/** Word-wrap to `width` columns. */
|
|
6
|
+
function wrap(text, width) {
|
|
7
|
+
const w = Math.max(20, width);
|
|
8
|
+
const lines = [];
|
|
9
|
+
let cur = "";
|
|
10
|
+
for (const word of text.trim().split(/\s+/).filter(Boolean)) {
|
|
11
|
+
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
12
|
+
lines.push(cur);
|
|
13
|
+
cur = word;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (cur)
|
|
20
|
+
lines.push(cur);
|
|
21
|
+
return lines.length ? lines : [""];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A one-line free-text prompt, for the places a list can't answer the question
|
|
25
|
+
* — SIA's "open" questions and the "Other…" escape on every other type.
|
|
26
|
+
*
|
|
27
|
+
* Deliberately NOT @inquirer: the picker next door avoids it because handing
|
|
28
|
+
* stdin back and forth froze the composer, and this has to interleave with the
|
|
29
|
+
* same pinned-composer engine. Cooked mode is restored for the duration so
|
|
30
|
+
* readline owns line editing (backspace, arrows, paste), then handed back.
|
|
31
|
+
*
|
|
32
|
+
* Resolves the trimmed answer, or null if it was empty or cancelled.
|
|
33
|
+
*/
|
|
34
|
+
export function askText(label, placeholder) {
|
|
35
|
+
const stdin = process.stdin;
|
|
36
|
+
const stdout = process.stdout;
|
|
37
|
+
if (!stdin.isTTY)
|
|
38
|
+
return Promise.resolve(null);
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
const suspended = screenActive();
|
|
41
|
+
if (suspended)
|
|
42
|
+
suspendScreen();
|
|
43
|
+
// The picker leaves keypress listeners and raw mode behind; readline needs
|
|
44
|
+
// neither, and a stale listener would eat the typed characters.
|
|
45
|
+
stdin.removeAllListeners("keypress");
|
|
46
|
+
const prevRaw = stdin.isRaw ?? false;
|
|
47
|
+
if (stdin.isTTY)
|
|
48
|
+
stdin.setRawMode(false);
|
|
49
|
+
stdin.resume();
|
|
50
|
+
// Wrap to the terminal, at word boundaries. A SIA question is a full
|
|
51
|
+
// sentence or three, and left raw the terminal breaks it mid-word.
|
|
52
|
+
const width = Math.min(termWidth() - 4, 92);
|
|
53
|
+
stdout.write("\n");
|
|
54
|
+
for (const l of wrap(label, width))
|
|
55
|
+
stdout.write(" " + c.title(l) + "\n");
|
|
56
|
+
if (placeholder)
|
|
57
|
+
stdout.write(" " + c.dim(placeholder) + "\n");
|
|
58
|
+
const rl = readline.createInterface({ input: stdin, output: stdout, terminal: true });
|
|
59
|
+
let settled = false;
|
|
60
|
+
const finish = (value) => {
|
|
61
|
+
if (settled)
|
|
62
|
+
return;
|
|
63
|
+
settled = true;
|
|
64
|
+
rl.close();
|
|
65
|
+
if (stdin.isTTY)
|
|
66
|
+
stdin.setRawMode(prevRaw);
|
|
67
|
+
if (suspended)
|
|
68
|
+
resumeScreen();
|
|
69
|
+
resolve(value);
|
|
70
|
+
};
|
|
71
|
+
rl.question(" " + c.brandFixed("❯ "), (answer) => finish(answer.trim() || null));
|
|
72
|
+
rl.on("SIGINT", () => finish(null));
|
|
73
|
+
});
|
|
74
|
+
}
|
package/dist/ui/trust.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { pickFromList } from "./select.js";
|
|
4
|
+
/**
|
|
5
|
+
* Workspace trust — the safety check shown the first time the CLI is opened in
|
|
6
|
+
* a folder, before anything reads from it.
|
|
7
|
+
*
|
|
8
|
+
* This is not decoration. `detectLocalFiles` resolves a leading token in your
|
|
9
|
+
* message against the current directory and uploads any file it matches, and
|
|
10
|
+
* `cos upload` reads paths directly — so a bare filename can send a local file
|
|
11
|
+
* to the Carrier OS API. The answer is remembered per folder in the CLI config.
|
|
12
|
+
*/
|
|
13
|
+
/** Where the trust decision is explained. Update if a dedicated page lands. */
|
|
14
|
+
const SECURITY_GUIDE_URL = "https://platform.carrieros.ai/docs";
|
|
15
|
+
/** Windows paths are case-insensitive, so compare on a normalized form. */
|
|
16
|
+
function normalize(dir) {
|
|
17
|
+
const resolved = path.resolve(dir);
|
|
18
|
+
return process.platform === "win32" ? resolved.toLowerCase() : resolved;
|
|
19
|
+
}
|
|
20
|
+
export function isTrusted(config, dir = process.cwd()) {
|
|
21
|
+
return (config.get("trustedFolders") ?? []).includes(normalize(dir));
|
|
22
|
+
}
|
|
23
|
+
export function trustFolder(config, dir = process.cwd()) {
|
|
24
|
+
const key = normalize(dir);
|
|
25
|
+
const list = config.get("trustedFolders") ?? [];
|
|
26
|
+
if (list.includes(key))
|
|
27
|
+
return;
|
|
28
|
+
// Bounded so the config can't grow without limit; oldest entries drop first.
|
|
29
|
+
config.set("trustedFolders", [...list, key].slice(-200));
|
|
30
|
+
}
|
|
31
|
+
/** Plain-text word wrap. No ANSI here — color is applied per whole line below. */
|
|
32
|
+
function wrap(text, width) {
|
|
33
|
+
const w = Math.max(20, width);
|
|
34
|
+
const lines = [];
|
|
35
|
+
let cur = "";
|
|
36
|
+
for (const word of text.trim().split(/\s+/).filter(Boolean)) {
|
|
37
|
+
if (cur && cur.length + 1 + word.length > w) {
|
|
38
|
+
lines.push(cur);
|
|
39
|
+
cur = word;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (cur)
|
|
46
|
+
lines.push(cur);
|
|
47
|
+
return lines;
|
|
48
|
+
}
|
|
49
|
+
/** Exported so the screen can be rendered without a TTY (preview / tests). */
|
|
50
|
+
export function workspaceTrustLines(dir, width) {
|
|
51
|
+
const body = (text) => wrap(text, width).map((l) => " " + c.value(l));
|
|
52
|
+
return [
|
|
53
|
+
" " + c.warn("─".repeat(width)),
|
|
54
|
+
" " + c.warn.bold("Accessing workspace:"),
|
|
55
|
+
"",
|
|
56
|
+
" " + c.title(dir),
|
|
57
|
+
"",
|
|
58
|
+
...body("Quick safety check: Is this a project you created or one you trust? " +
|
|
59
|
+
"(Like your own code, a well-known open source project, or work from your team). " +
|
|
60
|
+
"If not, take a moment to review what's in this folder first."),
|
|
61
|
+
"",
|
|
62
|
+
...body("Carrier OS'll be able to read files here and upload them to your workspace when you reference them."),
|
|
63
|
+
"",
|
|
64
|
+
" " + c.dim("Security guide ") + c.dim(SECURITY_GUIDE_URL)
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Ask once per folder. Returns false only when the user declines, which callers
|
|
69
|
+
* treat as "exit without doing anything".
|
|
70
|
+
*
|
|
71
|
+
* Non-TTY runs (pipes, CI) can't answer a prompt, so they proceed — the check
|
|
72
|
+
* is a guard for interactive use, not an authorization boundary.
|
|
73
|
+
*/
|
|
74
|
+
export async function ensureWorkspaceTrust(config, dir = process.cwd()) {
|
|
75
|
+
if (!process.stdin.isTTY)
|
|
76
|
+
return true;
|
|
77
|
+
if (isTrusted(config, dir))
|
|
78
|
+
return true;
|
|
79
|
+
const choice = await pickFromList({
|
|
80
|
+
title: "",
|
|
81
|
+
header: (width) => workspaceTrustLines(dir, width),
|
|
82
|
+
choices: [
|
|
83
|
+
{ value: "trust", label: "Yes, I trust this folder" },
|
|
84
|
+
{ value: "exit", label: "No, exit" }
|
|
85
|
+
],
|
|
86
|
+
initial: 0,
|
|
87
|
+
confirmOnNumber: true
|
|
88
|
+
});
|
|
89
|
+
if (choice !== "trust")
|
|
90
|
+
return false;
|
|
91
|
+
trustFolder(config, dir);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
package/dist/ui/ui.js
CHANGED
|
@@ -8,7 +8,10 @@ import { c } from "./colors.js";
|
|
|
8
8
|
export const icon = {
|
|
9
9
|
ok: c.ok("✓"),
|
|
10
10
|
warn: c.warn("!"),
|
|
11
|
-
|
|
11
|
+
// Informational lines are context, not status — a muted corner-down-right
|
|
12
|
+
// reads as "and then this happened" instead of competing with ✓ / ! / ✕ for
|
|
13
|
+
// attention. U+21B3 is in the base arrows block, so it renders everywhere.
|
|
14
|
+
info: c.dim("↳"),
|
|
12
15
|
err: c.err("✕"),
|
|
13
16
|
bullet: c.accent("•"),
|
|
14
17
|
arrow: c.dim("›"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carrieros/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Carrier OS command-line interface — an interactive shell plus commands for the Carrier OS developer platform (chat, sessions, files, usage) over the public /v1 API.",
|
|
6
6
|
"type": "module",
|
|
@@ -22,7 +22,16 @@
|
|
|
22
22
|
"dev": "tsx src/main.ts",
|
|
23
23
|
"start": "node dist/main.js",
|
|
24
24
|
"typecheck": "tsc --noEmit",
|
|
25
|
-
"
|
|
25
|
+
"test": "npm run build && node --test \"test/*.test.mjs\"",
|
|
26
|
+
"prepare": "npm run build",
|
|
27
|
+
"test:pty": "npm run build && node test/acceptance/pty-selftest.mjs",
|
|
28
|
+
"test:acceptance": "npm run build && node test/acceptance/live-acceptance.mjs",
|
|
29
|
+
"build:helpers": "node scripts/build-helpers.mjs",
|
|
30
|
+
"bundle": "npm run build && node scripts/bundle.mjs",
|
|
31
|
+
"sea:blob": "node --experimental-sea-config sea-config.json",
|
|
32
|
+
"package:win": "npm run bundle && npm run sea:blob && node -e \"require('fs').copyFileSync(process.execPath,'build/cos.exe')\" && npx --yes postject build/cos.exe NODE_SEA_BLOB build/cos.blob --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 && npm run build:helpers && node -e \"require('fs').cpSync('vendor/bin','build',{recursive:true})\"",
|
|
33
|
+
"test:exe": "node test/acceptance/packaged-exe.mjs",
|
|
34
|
+
"rehash-helpers": "node scripts/rehash-helpers.mjs"
|
|
26
35
|
},
|
|
27
36
|
"keywords": [
|
|
28
37
|
"carrieros",
|
|
@@ -57,7 +66,9 @@
|
|
|
57
66
|
"ora": "^8.1.1"
|
|
58
67
|
},
|
|
59
68
|
"devDependencies": {
|
|
69
|
+
"@lydell/node-pty": "^1.2.0-beta.15",
|
|
60
70
|
"@types/node": "^22.10.2",
|
|
71
|
+
"esbuild": "^0.28.2",
|
|
61
72
|
"tsx": "^4.19.2",
|
|
62
73
|
"typescript": "^5.7.2"
|
|
63
74
|
}
|
package/dist/ui/activity.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { c } from "./colors.js";
|
|
2
|
-
import { MARGIN } from "./composer-layout.js";
|
|
3
|
-
/**
|
|
4
|
-
* A live activity timeline — the "thinking" phase, Claude-style but TRUTHFUL to
|
|
5
|
-
* the Carrier OS architecture. The CLI only talks to the public API, so steps
|
|
6
|
-
* reflect what actually happens (understand the request → select the Carrier
|
|
7
|
-
* mode → route to the API → wait for the model), never fabricated file/tool
|
|
8
|
-
* actions.
|
|
9
|
-
*
|
|
10
|
-
* It renders into the composer's transient status region: completed steps dim to
|
|
11
|
-
* a ●, and only the current step spins. The shell drives it by emitting phase
|
|
12
|
-
* events (request_started → mode_selected → request_sent → waiting → done),
|
|
13
|
-
* which map 1:1 to `step()` calls — new backend capabilities (search, files,
|
|
14
|
-
* vision, agents…) plug in as extra steps without changing this renderer.
|
|
15
|
-
*/
|
|
16
|
-
const FRAMES = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏";
|
|
17
|
-
export function startActivity(live) {
|
|
18
|
-
const steps = [];
|
|
19
|
-
let frame = 0;
|
|
20
|
-
const paint = () => {
|
|
21
|
-
live.setStatus(steps.map((s, i) => {
|
|
22
|
-
const active = !s.done && i === steps.length - 1;
|
|
23
|
-
const marker = s.done
|
|
24
|
-
? c.dim("●")
|
|
25
|
-
: active
|
|
26
|
-
? c.brand(FRAMES[frame % FRAMES.length])
|
|
27
|
-
: c.dim("○");
|
|
28
|
-
return MARGIN + marker + " " + c.dim(active ? `${s.label}…` : s.label);
|
|
29
|
-
}));
|
|
30
|
-
};
|
|
31
|
-
const timer = setInterval(() => {
|
|
32
|
-
frame++;
|
|
33
|
-
paint();
|
|
34
|
-
}, 90);
|
|
35
|
-
timer.unref?.();
|
|
36
|
-
return {
|
|
37
|
-
step(label) {
|
|
38
|
-
if (steps.length)
|
|
39
|
-
steps[steps.length - 1].done = true;
|
|
40
|
-
steps.push({ label, done: false });
|
|
41
|
-
paint();
|
|
42
|
-
},
|
|
43
|
-
done() {
|
|
44
|
-
for (const s of steps)
|
|
45
|
-
s.done = true;
|
|
46
|
-
paint();
|
|
47
|
-
},
|
|
48
|
-
stop() {
|
|
49
|
-
clearInterval(timer);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Truthful activity steps for a chat turn, flavored by the Carrier mode. The
|
|
55
|
-
* FIRST steps are brief client-side phases; the LAST step is the one that spins
|
|
56
|
-
* while genuinely awaiting the model's response.
|
|
57
|
-
*/
|
|
58
|
-
export function chatActivitySteps(modeLabel) {
|
|
59
|
-
const lower = modeLabel.toLowerCase();
|
|
60
|
-
if (lower === "code" || lower === "debug") {
|
|
61
|
-
return ["Detecting coding task", `Selecting ${modeLabel} mode`, "Routing to Carrier OS", "Generating solution"];
|
|
62
|
-
}
|
|
63
|
-
if (lower === "research") {
|
|
64
|
-
return [
|
|
65
|
-
"Understanding your request",
|
|
66
|
-
`Selecting ${modeLabel} mode`,
|
|
67
|
-
"Routing to Carrier OS",
|
|
68
|
-
"Synthesizing response"
|
|
69
|
-
];
|
|
70
|
-
}
|
|
71
|
-
return [
|
|
72
|
-
"Understanding your request",
|
|
73
|
-
`Selecting ${modeLabel} mode`,
|
|
74
|
-
"Routing to Carrier OS",
|
|
75
|
-
"Waiting for the model"
|
|
76
|
-
];
|
|
77
|
-
}
|