@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
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { c } from './colors.js';
|
|
3
|
+
import { MARGIN, contentWidth } from './composer-layout.js';
|
|
4
|
+
import { clip, stripControl, wrapText } from './conversation.js';
|
|
5
|
+
import { INDENT, cardField, cardHeader, cardWidth } from './agent-cards.js';
|
|
6
|
+
import { displayCommand } from '../services/command-policy.js';
|
|
7
|
+
export const ACTIVITY = {
|
|
8
|
+
IDLE: 'Ready', THINKING: 'Thinking', INSPECTING: 'Inspecting repository', SEARCHING: 'Searching repository', READING: 'Reading files', PLANNING: 'Creating plan', PROPOSAL_READY: 'Change proposed', WAITING_FOR_MUTATION_APPROVAL: 'Waiting for change approval', APPLYING: 'Applying changes', VALIDATION_PENDING: 'Validation pending', WAITING_FOR_COMMAND_APPROVAL: 'Waiting for command approval', RUNNING_COMMAND: 'Running command', ANALYZING_FAILURE: 'Analyzing failure', CORRECTION_PROPOSED: 'Correction proposed', WAITING_FOR_CORRECTION_APPROVAL: 'Waiting for correction approval', RETESTING: 'Retesting', COMPLETED: 'Completed', FAILED: 'Failed', CANCELLED: 'Cancelled', UNRESOLVED: 'Unresolved'
|
|
9
|
+
};
|
|
10
|
+
export function workflowActivity(snapshot) {
|
|
11
|
+
const state = String(snapshot.state), correction = Number(snapshot.corrections) > 0;
|
|
12
|
+
if (state === 'COMPLETED')
|
|
13
|
+
return 'Validation passed · awaiting completion';
|
|
14
|
+
if (state === 'READING')
|
|
15
|
+
return correction ? 'Preparing correction' : 'Preparing changes';
|
|
16
|
+
if (state === 'APPLYING' || state === 'REAPPLYING') {
|
|
17
|
+
const validation = snapshot.validation;
|
|
18
|
+
if (validation?.some(v => v.status === 'PENDING_REVIEW'))
|
|
19
|
+
return correction ? 'Retest required' : 'Validation pending';
|
|
20
|
+
return correction ? 'Applying correction' : 'Applying changes';
|
|
21
|
+
}
|
|
22
|
+
const names = { TASK_RECEIVED: 'Thinking', INSPECTING: 'Inspecting repository', PLANNING: 'Creating plan', CAPABILITY_CHECK: 'Checking execution capability', READING: correction ? 'Preparing correction' : 'Preparing changes', PROPOSING: 'Change proposed', AWAITING_APPROVAL: 'Waiting for change approval', APPLYING: correction ? 'Applying correction' : 'Applying changes', TESTING: 'Running validation', ANALYZING_FAILURE: 'Analyzing failure', CORRECTIVE_PROPOSAL: 'Correction proposed', CORRECTIVE_APPROVAL: 'Waiting for correction approval', REAPPLYING: 'Applying correction', RETESTING: 'Retesting', COMPLETED: 'Completed', FAILED: 'Failed', CANCELLED: 'Cancelled', UNRESOLVED: 'Unresolved' };
|
|
23
|
+
return names[state] ?? 'Thinking';
|
|
24
|
+
}
|
|
25
|
+
const commandLabel = (t) => typeof t.program === 'string' ? `${displayCommand(t.program, Array.isArray(t.args) ? t.args.map(String) : [])}${t.cwd && t.cwd !== '.' ? ` · ${t.cwd}` : ''}` : '';
|
|
26
|
+
/** The recorded analysis text, from the workflow's own "Failure analysis (…): …" line. */
|
|
27
|
+
export function analysisExplanation(lines) {
|
|
28
|
+
const m = /^Failure analysis \(([^)]+)\):\s*([\s\S]*)$/.exec(stripControl(lines.join(' ')));
|
|
29
|
+
return { classification: m?.[1] ?? 'recorded', explanation: m?.[2] ?? stripControl(lines.join(' ')) };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The PLAN card: the workflow's own structured plan (snapshot.plan), not a copy.
|
|
33
|
+
* "Root cause" appears only where the workflow recorded one — the failure
|
|
34
|
+
* analysis behind a corrective plan. An initial plan has no such field, so it
|
|
35
|
+
* shows the planned expected behavior instead of inventing a cause.
|
|
36
|
+
*/
|
|
37
|
+
export function renderAgentPlan(snapshot, opts = {}) {
|
|
38
|
+
const plan = snapshot.plan;
|
|
39
|
+
if (!plan)
|
|
40
|
+
return [];
|
|
41
|
+
const corrective = Number(snapshot.corrections) > 0;
|
|
42
|
+
const rows = [...cardHeader(corrective ? 'CORRECTIVE PLAN' : 'PLAN', c.title)];
|
|
43
|
+
rows.push(...cardField('Task', clip(stripControl(plan.summary), 240)));
|
|
44
|
+
const inv = plan.investigation;
|
|
45
|
+
if (corrective && opts.rootCause)
|
|
46
|
+
rows.push(...cardField('Root cause', clip(stripControl(opts.rootCause), 240)));
|
|
47
|
+
else if (inv) {
|
|
48
|
+
// The investigation the workflow verified, symptom first: where it shows, why, where to change.
|
|
49
|
+
rows.push(...cardField('Symptom', clip(stripControl(inv.symptom), 200), c.dim));
|
|
50
|
+
rows.push(...cardField('Path', inv.execution_path.slice(0, 8).map(s => s.symbol ? `${s.path} · ${s.symbol}` : s.path), c.file));
|
|
51
|
+
rows.push(...cardField('Root cause', clip(stripControl(inv.root_cause), 240)));
|
|
52
|
+
rows.push(...cardField('Change at', `${inv.change_location.path}${inv.change_location.symbol ? ` · ${inv.change_location.symbol}` : ''}`, c.file));
|
|
53
|
+
if (inv.evidence?.length)
|
|
54
|
+
rows.push(...cardField('Evidence', inv.evidence.slice(0, 4).map(e => clip(stripControl(`${e.path}${e.lines ? `:${e.lines}` : ''} — ${e.note}`), 160)), c.dim));
|
|
55
|
+
if (inv.ruled_out?.length)
|
|
56
|
+
rows.push(...cardField('Ruled out', inv.ruled_out.slice(0, 4).map(r => clip(stripControl(`${r.path} — ${r.reason}`), 160)), c.dim));
|
|
57
|
+
}
|
|
58
|
+
else if (plan.expected)
|
|
59
|
+
rows.push(...cardField('Expected', clip(stripControl(plan.expected), 200), c.dim));
|
|
60
|
+
rows.push(...cardField('Files', plan.files.slice(0, 8).map(f => f.path), c.file));
|
|
61
|
+
if (plan.files.length > 8)
|
|
62
|
+
rows.push(INDENT + c.dim(`+${plan.files.length - 8} more planned files`));
|
|
63
|
+
rows.push(...cardField('Validation', plan.tests.slice(0, 3).map(t => commandLabel(t)).filter(Boolean)));
|
|
64
|
+
if (plan.risks)
|
|
65
|
+
rows.push(...cardField('Risk', clip(stripControl(plan.risks), 160), c.dim));
|
|
66
|
+
rows.push('');
|
|
67
|
+
return rows;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The analysis the workflow recorded after a failed validation — classification
|
|
71
|
+
* and the stated evidence, as recorded by coding_workflow(analyze). It is the
|
|
72
|
+
* tool's input, shown as an operational record, not hidden reasoning.
|
|
73
|
+
*/
|
|
74
|
+
export function renderFailureAnalysis(lines) {
|
|
75
|
+
const { classification, explanation } = analysisExplanation(lines);
|
|
76
|
+
const out = ['', MARGIN + c.title('Analyzing failure…'), MARGIN + ' ' + c.ok('✓ ') + c.value('Failure evidence captured') + c.dim(` · ${classification}`)];
|
|
77
|
+
for (const line of wrapText(explanation, cardWidth() - 2))
|
|
78
|
+
out.push(INDENT + ' ' + c.dim(line));
|
|
79
|
+
out.push(MARGIN + c.dim('Fresh reads and a new plan come next; any correction needs its own approval.'), '');
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
/** Called only after the shell's existing interrupt/acknowledged-finish guard. */
|
|
83
|
+
export function renderAgentOutcome(snapshot, ctx = {}) {
|
|
84
|
+
if (!snapshot.plan)
|
|
85
|
+
return [];
|
|
86
|
+
const plan = snapshot.plan;
|
|
87
|
+
const state = String(snapshot.state), files = Array.isArray(snapshot.files) ? snapshot.files.map(String) : [];
|
|
88
|
+
const validation = (snapshot.validation ?? []);
|
|
89
|
+
const corrections = Number(snapshot.corrections) || 0;
|
|
90
|
+
const applied = ctx.applied ?? [];
|
|
91
|
+
// A person's "no" is a decision, not a failure (the workflow still records
|
|
92
|
+
// FAILED), and an invalidated change is a safety stop. Each already has its
|
|
93
|
+
// own card at the moment it happened (CHANGE REJECTED / CHANGE INVALIDATED),
|
|
94
|
+
// so the turn ends there — no second card, and never "Failed".
|
|
95
|
+
if (ctx.declined && applied.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
const changed = files.length ? files : [...new Set(applied.map(a => a.rel))];
|
|
98
|
+
const commands = validation.map(t => commandLabel(t) + (t.status ? ` — ${t.status === 'PASSED' ? 'passed' : t.status === 'FAILED' ? 'failed' : 'not completed'}` : '')).filter(Boolean);
|
|
99
|
+
if (state === 'COMPLETED') {
|
|
100
|
+
// The validation counts arrive as "3 passed · 0 failed"; one fact per line.
|
|
101
|
+
const counts = (ctx.validationCounts ?? '').split(' · ').filter(Boolean);
|
|
102
|
+
const changes = `${changed.length} file${changed.length === 1 ? '' : 's'} modified${applied.length > changed.length ? ` · ${applied.length} approved changes` : ''}`;
|
|
103
|
+
return [...cardHeader('✓ COMPLETED', c.ok),
|
|
104
|
+
...cardField('Task', clip(stripControl(ctx.task ?? plan.summary), 200)),
|
|
105
|
+
...cardField('Changes', changes),
|
|
106
|
+
...cardField('Validation', [...validation.map(commandLabel).filter(Boolean), ...counts]),
|
|
107
|
+
...cardField('Corrections', String(corrections)),
|
|
108
|
+
...cardField('Files modified', changed.slice(0, 8), c.file),
|
|
109
|
+
...(changed.length > 8 ? [INDENT + c.dim(`+${changed.length - 8} more`)] : []),
|
|
110
|
+
...cardField('Operation IDs', applied.map(a => a.operationId), c.dim),
|
|
111
|
+
'', MARGIN + c.ok('✓ ') + c.value(validation.length && validation.every(v => v.status === 'PASSED') ? 'The issue has been fixed and verified.' : 'The task completed.'), ''];
|
|
112
|
+
}
|
|
113
|
+
const title = state === 'CANCELLED' ? '⊘ CANCELLED' : state === 'FAILED' ? '✗ FAILED' : '! UNRESOLVED';
|
|
114
|
+
const reason = state === 'CANCELLED' ? 'The turn stopped. Review retained changes before continuing.' : state === 'FAILED' ? 'The workflow stopped. Review the step above, then start a new task.' : 'Required validation or acknowledgment is incomplete. Nothing resumes automatically.';
|
|
115
|
+
return [...cardHeader(title, state === 'CANCELLED' ? c.warn : c.err), ...wrapText(reason, cardWidth()).map(l => MARGIN + c.dim(l)),
|
|
116
|
+
...cardField('Applied', applied.map(a => `${a.rel} · +${a.added} −${a.removed} · ${a.operationId}`), c.file),
|
|
117
|
+
...cardField('Validation', commands), ''];
|
|
118
|
+
}
|
|
119
|
+
export function toolActivity(name, args, root) {
|
|
120
|
+
// A search is named by what it looks for; its directory only narrows it.
|
|
121
|
+
if (name === 'search_files' && typeof args.query === 'string')
|
|
122
|
+
return clip(`Searching ${stripControl(args.query)}${typeof args.path === 'string' && args.path ? ` in ${stripControl(args.path)}` : ''}`, contentWidth() - 6);
|
|
123
|
+
if (name === 'find_symbol' && typeof args.name === 'string')
|
|
124
|
+
return clip(`Finding definition ${stripControl(args.name)}`, contentWidth() - 6);
|
|
125
|
+
if (name === 'find_references' && typeof args.name === 'string')
|
|
126
|
+
return clip(`Finding usages ${stripControl(args.name)}`, contentWidth() - 6);
|
|
127
|
+
const raw = String(args.path ?? args.query ?? args.pattern ?? args.reference ?? args.revision ?? '');
|
|
128
|
+
const value = path.isAbsolute(raw) && !path.relative(root, raw).startsWith('..') ? path.relative(root, raw) : raw;
|
|
129
|
+
const labels = { read_file: 'Reading', search_files: 'Searching', list_files: 'Inspecting repository', find_files: 'Finding files', git_log: 'Reading history', git_blame: 'Reading blame', git_show: 'Reading commit', git_status: 'Inspecting repository', git_diff: 'Inspecting changes', resolve_local_file: 'Finding file', code_outline: 'Outlining', coding_workflow: args.action === 'analyze' ? 'Analyzing failure' : args.action === 'plan' ? 'Creating plan' : 'Checking workflow', run_command: 'Preparing command', edit_file: 'Preparing change', write_file: 'Preparing change', create_file: 'Preparing change', delete_file: 'Preparing deletion', revert_change: 'Preparing revert' };
|
|
130
|
+
return clip(`${labels[name] ?? 'Inspecting'}${value ? ' ' + stripControl(value) : ''}`, contentWidth() - 6);
|
|
131
|
+
}
|
package/dist/ui/approval.js
CHANGED
|
@@ -15,14 +15,21 @@ function countdown(msLeft) {
|
|
|
15
15
|
* the policy underneath.
|
|
16
16
|
*/
|
|
17
17
|
export function approvalFrame(question, msLeft) {
|
|
18
|
-
const hint = c.dim("Enter or ") +
|
|
18
|
+
const hint = c.dim("Type y + Enter to approve · empty Enter or ") +
|
|
19
19
|
c.key("n") +
|
|
20
20
|
c.dim(" declines · ") +
|
|
21
21
|
c.key("Ctrl+C") +
|
|
22
22
|
c.dim(" stops the turn · declines on its own in ") +
|
|
23
23
|
c.dim(countdown(msLeft));
|
|
24
|
-
const short = c.dim("Enter/") + c.key("n") + c.dim(" declines · ") + c.key("Ctrl+C") + c.dim(" stops · ") + c.dim(countdown(msLeft));
|
|
24
|
+
const short = c.dim("y + Enter approves · Enter/") + c.key("n") + c.dim(" declines · ") + c.key("Ctrl+C") + c.dim(" stops · ") + c.dim(countdown(msLeft));
|
|
25
25
|
const room = contentWidth() - 6;
|
|
26
|
+
if (contentWidth() < 70)
|
|
27
|
+
return [
|
|
28
|
+
MARGIN + c.title(question),
|
|
29
|
+
MARGIN + c.dim("y + Enter approves"),
|
|
30
|
+
MARGIN + c.dim("Enter/n declines"),
|
|
31
|
+
MARGIN + c.dim(`Ctrl+C stops · ${countdown(msLeft)}`)
|
|
32
|
+
];
|
|
26
33
|
return [
|
|
27
34
|
MARGIN + " " + c.warn("?") + " " + c.title(question) + " " + c.dim("(y/N)"),
|
|
28
35
|
MARGIN + " " + (visibleWidth(hint) <= room ? hint : short)
|
|
@@ -32,37 +39,59 @@ export function askApproval(opts) {
|
|
|
32
39
|
return new Promise((resolve) => {
|
|
33
40
|
const deadline = Date.now() + opts.timeoutMs;
|
|
34
41
|
let done = false;
|
|
42
|
+
let candidate = false;
|
|
43
|
+
let confirming = false;
|
|
35
44
|
const paint = () => screenTransient(approvalFrame(opts.question, deadline - Date.now()));
|
|
36
45
|
const finish = (value) => {
|
|
37
46
|
if (done)
|
|
38
47
|
return;
|
|
39
48
|
done = true;
|
|
40
49
|
clearInterval(timer);
|
|
50
|
+
process.stdout.removeListener("resize", paint);
|
|
41
51
|
opts.signal?.removeEventListener?.("abort", onAbort);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
setImmediate(() => {
|
|
53
|
+
release();
|
|
54
|
+
screenTransient([]);
|
|
55
|
+
resolve(value);
|
|
56
|
+
});
|
|
45
57
|
};
|
|
46
58
|
function onAbort() {
|
|
47
59
|
finish("cancel");
|
|
48
60
|
}
|
|
49
61
|
const onKey = (str, key) => {
|
|
50
|
-
if (!key && !str)
|
|
62
|
+
if (done || (!key && !str))
|
|
51
63
|
return;
|
|
64
|
+
if (Date.now() >= deadline)
|
|
65
|
+
return finish("timeout");
|
|
66
|
+
if (opts.signal?.aborted)
|
|
67
|
+
return finish("cancel");
|
|
52
68
|
if (key?.ctrl && (key.name === "c" || key.name === "d"))
|
|
53
69
|
return finish("cancel");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (key?.name === "end")
|
|
59
|
-
return screenScrollToBottom();
|
|
60
|
-
if (str === "y" || str === "Y")
|
|
61
|
-
return finish("approve");
|
|
62
|
-
if (str === "n" || str === "N" || key?.name === "escape")
|
|
70
|
+
// Never interpret a prefix of text/paste as consent. Drain this input
|
|
71
|
+
// burst before resolving so trailing characters cannot approve another
|
|
72
|
+
// prompt. No input text is retained or rendered.
|
|
73
|
+
if (confirming)
|
|
63
74
|
return finish("reject");
|
|
64
|
-
if (key?.
|
|
75
|
+
if (key?.ctrl || key?.meta)
|
|
65
76
|
return finish("reject");
|
|
77
|
+
if (!candidate && ["up", "down", "left", "right", "home"].includes(key?.name ?? ""))
|
|
78
|
+
return;
|
|
79
|
+
if (!candidate && key?.name === "pageup")
|
|
80
|
+
return screenScrollPage(1);
|
|
81
|
+
if (!candidate && key?.name === "pagedown")
|
|
82
|
+
return screenScrollPage(-1);
|
|
83
|
+
if (!candidate && key?.name === "end")
|
|
84
|
+
return screenScrollToBottom();
|
|
85
|
+
if ((str === "y" || str === "Y") && !candidate) {
|
|
86
|
+
candidate = true;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if ((key?.name === "return" || key?.name === "enter") && candidate) {
|
|
90
|
+
confirming = true;
|
|
91
|
+
setImmediate(() => finish(Date.now() >= deadline ? "timeout" : opts.signal?.aborted ? "cancel" : "approve"));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
finish("reject");
|
|
66
95
|
};
|
|
67
96
|
const release = captureKeys(onKey);
|
|
68
97
|
const timer = setInterval(() => {
|
|
@@ -75,6 +104,7 @@ export function askApproval(opts) {
|
|
|
75
104
|
if (opts.signal?.aborted)
|
|
76
105
|
return finish("cancel");
|
|
77
106
|
opts.signal?.addEventListener?.("abort", onAbort, { once: true });
|
|
107
|
+
process.stdout.on("resize", paint);
|
|
78
108
|
screenScrollToBottom();
|
|
79
109
|
paint();
|
|
80
110
|
});
|
package/dist/ui/banner.js
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
import chalk from "chalk";
|
|
2
2
|
import { line } from "../services/output.js";
|
|
3
|
-
import { branchLabel,
|
|
3
|
+
import { branchLabel, getWorkspace } from "../services/workspace.js";
|
|
4
4
|
import { modeLabelShort, modelLabelShort } from "../shell/shell-chat.js";
|
|
5
5
|
import { c } from "./colors.js";
|
|
6
|
+
import { clip } from "./conversation.js";
|
|
7
|
+
import { contentWidth, MARGIN } from "./composer-layout.js";
|
|
6
8
|
import { WORDMARK } from "./logo.js";
|
|
7
9
|
import { BRAND_HEX } from "./theme.js";
|
|
8
|
-
const MARGIN = " ";
|
|
9
|
-
const LABEL_WIDTH = 13;
|
|
10
|
-
/** Visible width of a block of lines. */
|
|
11
|
-
function blockWidth(block) {
|
|
12
|
-
return Math.max(...block.split("\n").map((l) => [...l].length));
|
|
13
|
-
}
|
|
14
|
-
/** True when the terminal is too narrow for the block wordmark. */
|
|
15
|
-
function isNarrow() {
|
|
16
|
-
return (process.stdout.columns ?? 80) < 2 + blockWidth(WORDMARK) + 2;
|
|
17
|
-
}
|
|
18
|
-
// ── Theme-color gradient across the wordmark (subtle; follows the accent) ──────
|
|
19
10
|
function hexToRgb(h) {
|
|
20
11
|
const n = parseInt(h.slice(1), 16);
|
|
21
12
|
return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
|
|
@@ -26,87 +17,40 @@ function lerpHex(a, b, t) {
|
|
|
26
17
|
const mix = (x, y) => Math.round(x + (y - x) * t);
|
|
27
18
|
return "#" + [mix(ar, br), mix(ag, bg), mix(ab, bb)].map((v) => v.toString(16).padStart(2, "0")).join("");
|
|
28
19
|
}
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* branding, so it stays green and does NOT follow the runtime /color accent. */
|
|
32
|
-
function gradientWordmark(lines) {
|
|
33
|
-
const from = BRAND_HEX;
|
|
34
|
-
const to = lerpHex(from, "#ffffff", 0.5); // lighten toward white on the right
|
|
35
|
-
const maxW = Math.max(1, ...lines.map((l) => [...l].length));
|
|
36
|
-
return lines.map((line) => [...line].map((ch, i) => (ch === " " ? ch : chalk.hex(lerpHex(from, to, i / maxW))(ch))).join(""));
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* The brand lockup lines (already colored): the CARRIER block wordmark with a
|
|
40
|
-
* subtle theme-color gradient. Shared by the startup banner and first-run
|
|
41
|
-
* welcome.
|
|
42
|
-
*/
|
|
20
|
+
/** The CARRIER OS block wordmark with a brand-green → lighter gradient, or a
|
|
21
|
+
* one-line mark when the terminal is too narrow for it. */
|
|
43
22
|
export function renderBrandmark() {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return MARGIN + c.label(label.padEnd(LABEL_WIDTH)) + c.value(value);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Where you are, in three lines: the project, its Git state, and the path.
|
|
54
|
-
*
|
|
55
|
-
* This is the first thing the CLI has ever known about the local machine, and
|
|
56
|
-
* the banner is where it belongs — it answers "what am I pointed at?" before
|
|
57
|
-
* the first prompt, rather than making someone run a command to find out.
|
|
58
|
-
*
|
|
59
|
-
* Failure is silent by design. A machine without Git, or a folder Git refuses
|
|
60
|
-
* to read, still gets a Workspace and a Path; only the Git line changes. The
|
|
61
|
-
* caller already wraps this, but the shell must open regardless.
|
|
62
|
-
*/
|
|
63
|
-
function workspaceLines() {
|
|
64
|
-
const ws = getWorkspace();
|
|
65
|
-
const repo = ws.repository;
|
|
66
|
-
const out = [kvLine("Workspace", ws.project.name)];
|
|
67
|
-
if (repo.state === "detected") {
|
|
68
|
-
const branch = branchLabel(repo) ?? "unknown";
|
|
69
|
-
const status = statusLabel(repo);
|
|
70
|
-
// "Clean" adds nothing at a glance — the absence of a count already says
|
|
71
|
-
// it. Only a dirty tree, or an unknown one, is worth the extra words.
|
|
72
|
-
const suffix = status && status !== "Clean" ? ` ${c.dim("·")} ${status}` : "";
|
|
73
|
-
out.push(kvLine("Git", branch) + suffix);
|
|
74
|
-
}
|
|
75
|
-
else if (repo.state === "unavailable") {
|
|
76
|
-
out.push(kvLine("Git", "Unavailable"));
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
out.push(kvLine("Git", "Not detected"));
|
|
80
|
-
}
|
|
81
|
-
// Budget: margin + label column + a little slack, so a deep path shortens
|
|
82
|
-
// instead of wrapping the banner onto a second line.
|
|
83
|
-
const width = Math.max(24, (process.stdout.columns ?? 80) - MARGIN.length - LABEL_WIDTH - 2);
|
|
84
|
-
out.push(kvLine("Path", fitPath(ws.cwd, width)));
|
|
85
|
-
out.push("");
|
|
86
|
-
return out;
|
|
23
|
+
const rows = WORDMARK.split("\n");
|
|
24
|
+
const width = Math.max(1, ...rows.map((l) => [...l].length));
|
|
25
|
+
if ((process.stdout.columns ?? 80) < MARGIN.length + width + 2)
|
|
26
|
+
return [MARGIN + c.title("CarrierOS")];
|
|
27
|
+
const to = lerpHex(BRAND_HEX, "#ffffff", 0.5);
|
|
28
|
+
return rows.map((row) => MARGIN + [...row].map((ch, i) => (ch === " " ? ch : chalk.hex(lerpHex(BRAND_HEX, to, i / width))(ch))).join(""));
|
|
87
29
|
}
|
|
88
30
|
export function renderWelcomeBanner(ctx, opts = {}) {
|
|
89
31
|
try {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (opts.notices?.length)
|
|
99
|
-
out.push("");
|
|
100
|
-
out.push(MARGIN + c.hint("Type ") + c.key("/help") + c.hint(" for available commands."));
|
|
101
|
-
// Emit through `line()` so, in the interactive shell, the banner lands in the
|
|
102
|
-
// transcript region above the pinned composer (not written over it).
|
|
103
|
-
for (const l of out)
|
|
32
|
+
const ws = getWorkspace();
|
|
33
|
+
const branch = branchLabel(ws.repository);
|
|
34
|
+
// Where the agent will work, stated plainly before the first prompt: the
|
|
35
|
+
// signed-in state (a stored credential; the server checks it on use), the
|
|
36
|
+
// repository this folder resolves to, and its branch.
|
|
37
|
+
const row = (label, value) => MARGIN + c.dim(label.padEnd(12)) + c.value(clip(value, Math.max(8, contentWidth() - 12 - MARGIN.length)));
|
|
38
|
+
line("");
|
|
39
|
+
for (const l of renderBrandmark())
|
|
104
40
|
line(l);
|
|
41
|
+
line("");
|
|
42
|
+
line(MARGIN + c.ok("Authenticated ✓"));
|
|
43
|
+
line(row("Repository", ws.project.name));
|
|
44
|
+
if (branch)
|
|
45
|
+
line(row("Branch", branch));
|
|
46
|
+
line(row("Model", modelLabelShort(ctx)));
|
|
47
|
+
line(row("Mode", modeLabelShort(ctx)));
|
|
48
|
+
for (const notice of opts.notices ?? [])
|
|
49
|
+
line(MARGIN + clip(notice, contentWidth()));
|
|
50
|
+
line(MARGIN + c.dim("Describe a bug or a change in plain words · /help for commands"));
|
|
51
|
+
line("");
|
|
105
52
|
}
|
|
106
53
|
catch {
|
|
107
|
-
|
|
108
|
-
line();
|
|
109
|
-
line(` ${c.wordmark("Carrier OS")} ${c.subtitle("CLI")}`);
|
|
110
|
-
line();
|
|
54
|
+
line(MARGIN + c.title("CarrierOS"));
|
|
111
55
|
}
|
|
112
56
|
}
|