@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.
Files changed (89) hide show
  1. package/README.md +89 -15
  2. package/dist/commands/chat.js +6 -6
  3. package/dist/commands/context.js +40 -0
  4. package/dist/commands/doctor.js +34 -14
  5. package/dist/commands/logout.js +2 -0
  6. package/dist/commands/permissions.js +78 -0
  7. package/dist/commands/scope.js +9 -6
  8. package/dist/commands/sessions.js +5 -0
  9. package/dist/commands/settings.js +83 -10
  10. package/dist/commands/update.js +177 -51
  11. package/dist/commands/usage.js +10 -8
  12. package/dist/commands/version.js +1 -3
  13. package/dist/commands/whoami.js +12 -9
  14. package/dist/ide/editor-context.js +115 -12
  15. package/dist/ide/ide-session.js +288 -18
  16. package/dist/ide/tool-host.js +6 -6
  17. package/dist/main.js +10 -1
  18. package/dist/services/api.js +183 -15
  19. package/dist/services/auth-origin.js +20 -0
  20. package/dist/services/auto-update.js +221 -0
  21. package/dist/services/chat-stream.js +26 -3
  22. package/dist/services/checkpoints.js +176 -14
  23. package/dist/services/client-tools.js +123 -27
  24. package/dist/services/code-intel.js +243 -0
  25. package/dist/services/code-symbols.js +94 -0
  26. package/dist/services/coding-workflow.js +554 -0
  27. package/dist/services/command-coordinator.js +85 -12
  28. package/dist/services/command-policy.js +34 -4
  29. package/dist/services/config.js +96 -11
  30. package/dist/services/container-runner.js +254 -0
  31. package/dist/services/container-supervisor.js +38 -0
  32. package/dist/services/context.js +98 -25
  33. package/dist/services/device-auth.js +33 -6
  34. package/dist/services/execution-platform.js +30 -0
  35. package/dist/services/file-resolver.js +1 -1
  36. package/dist/services/folder-key.js +22 -0
  37. package/dist/services/git-tools.js +181 -0
  38. package/dist/services/helper-bin.js +56 -35
  39. package/dist/services/instruction-resolver.js +54 -0
  40. package/dist/services/job-helper.js +31 -10
  41. package/dist/services/local-files.js +148 -26
  42. package/dist/services/local-tools.js +540 -35
  43. package/dist/services/login-flow.js +44 -13
  44. package/dist/services/meta.js +27 -0
  45. package/dist/services/mutation-coordinator.js +186 -20
  46. package/dist/services/mutation-groups.js +309 -0
  47. package/dist/services/mutation-recovery.js +159 -0
  48. package/dist/services/mutations.js +264 -78
  49. package/dist/services/packaged-update.js +403 -0
  50. package/dist/services/packaged.js +15 -0
  51. package/dist/services/permission-mode.js +78 -0
  52. package/dist/services/process-runner.js +7 -1
  53. package/dist/services/project-context.js +4 -4
  54. package/dist/services/result-reconciliation.js +49 -0
  55. package/dist/services/secure-store.js +21 -1
  56. package/dist/services/session-resolver.js +7 -0
  57. package/dist/services/supported-runtime.js +59 -0
  58. package/dist/services/task-context.js +212 -0
  59. package/dist/services/task-snapshot.js +38 -0
  60. package/dist/services/tool-result-outbox.js +195 -0
  61. package/dist/services/update.js +457 -13
  62. package/dist/services/workspace-registry.js +4 -3
  63. package/dist/services/workspace.js +8 -1
  64. package/dist/shell/shell-chat.js +320 -34
  65. package/dist/shell/shell-commands.js +47 -5
  66. package/dist/shell/shell-prompt.js +21 -11
  67. package/dist/shell/shell-renderer.js +1 -1
  68. package/dist/shell/shell.js +107 -20
  69. package/dist/shell/task-context-view.js +40 -0
  70. package/dist/ui/agent-cards.js +111 -0
  71. package/dist/ui/agent-presentation.js +131 -0
  72. package/dist/ui/approval.js +46 -16
  73. package/dist/ui/banner.js +31 -87
  74. package/dist/ui/change-review.js +293 -46
  75. package/dist/ui/chat-renderer.js +6 -6
  76. package/dist/ui/colors.js +9 -9
  77. package/dist/ui/command-details.js +11 -0
  78. package/dist/ui/command-palette.js +27 -10
  79. package/dist/ui/command-registry.js +11 -4
  80. package/dist/ui/command-review.js +77 -28
  81. package/dist/ui/composer-layout.js +26 -20
  82. package/dist/ui/conversation.js +77 -25
  83. package/dist/ui/live.js +1 -1
  84. package/dist/ui/screen.js +19 -11
  85. package/dist/ui/select.js +6 -0
  86. package/dist/ui/task-context-card.js +99 -0
  87. package/dist/ui/trust.js +7 -12
  88. package/dist/ui/ui.js +23 -0
  89. package/package.json +9 -5
@@ -0,0 +1,99 @@
1
+ import { c } from "./colors.js";
2
+ import { MARGIN } from "./composer-layout.js";
3
+ import { INDENT, cardHeader, cardWidth } from "./agent-cards.js";
4
+ import { clip, stripControl, wrapText } from "./conversation.js";
5
+ /**
6
+ * Task Context presentation: a compact card when a conversation with earlier
7
+ * coding work is resumed, and one restored-context line when a coding turn
8
+ * starts in it. Never the whole context — the existing workflow cards remain
9
+ * the primary record of what happens in the turn.
10
+ */
11
+ const STATE_WORDS = { COMPLETED: "Completed", UNRESOLVED: "Unresolved" };
12
+ const RUN_WORDS = { passed: "passed", failed: "failed", not_approved: "not approved", not_run: "not run", cancelled: "cancelled", timed_out: "timed out", pending: "pending", unresolved: "unresolved", completed: "ran" };
13
+ const LABEL = 13;
14
+ /** `Label value`, with a long value wrapped under itself rather than clipped. */
15
+ function field(name, value) {
16
+ const room = Math.max(12, cardWidth() - LABEL - 2);
17
+ const pad = MARGIN + " ".repeat(LABEL + 2);
18
+ return wrapText(stripControl(value), room).map((part, i) => (i === 0 ? MARGIN + c.dim(name.padEnd(LABEL) + " ") : pad) + c.value(part));
19
+ }
20
+ /** Dim prose that wraps at the card width. */
21
+ const note = (text, prefix = INDENT) => wrapText(text, Math.max(12, cardWidth() - (prefix.length - INDENT.length))).map((l) => prefix + c.dim(l));
22
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
23
+ function filesLine(ctx, state) {
24
+ const t = ctx.current;
25
+ const read = t.investigation.files.length + t.investigation.files_omitted;
26
+ const changed = state.filter((e) => e.status !== "unchanged").length;
27
+ const parts = [`${plural(read, "file")} read`];
28
+ if (t.changes.applied)
29
+ parts.push(`${t.changes.applied} changed by the task`);
30
+ if (changed)
31
+ parts.push(`${changed} changed on disk since`);
32
+ return parts.join(" · ");
33
+ }
34
+ function testsLine(ctx) {
35
+ const last = ctx.current.validation.runs.at(-1);
36
+ if (!last)
37
+ return "none run";
38
+ return `${last.command ?? "command"} ${RUN_WORDS[last.outcome] ?? last.outcome}`;
39
+ }
40
+ const relevantFiles = (ctx) => ctx.current.references ? ctx.current.references.items.length + ctx.current.references.omitted : ctx.current.investigation.files.length + ctx.current.investigation.files_omitted;
41
+ const previousChanges = (ctx) => ctx.current.changes.applied + ctx.earlier_tasks.reduce((n, e) => n + e.files_changed.length, 0);
42
+ /** "shop · main", and whether it is the repository the earlier work used. */
43
+ function repositoryLine(name, repo) {
44
+ const where = repo?.branch ? `${name} · ${repo.branch}` : name;
45
+ if (repo?.same_repository === false)
46
+ return `${where} — a different repository than the earlier work`;
47
+ return where;
48
+ }
49
+ /**
50
+ * Shown when the CLI starts (or resumes) into a conversation with earlier
51
+ * coding work. Small by design: what is being continued, and that the context
52
+ * — never an approval or an operation — was restored.
53
+ */
54
+ export function renderTaskContextCard(ctx, state = [], repo) {
55
+ const t = ctx.current;
56
+ const out = [...cardHeader("CONTINUING TASK")];
57
+ out.push(...field("Repository", repositoryLine(t.repository ?? repo?.name ?? "this repository", repo)));
58
+ out.push(...field("Previous task", t.title));
59
+ const status = STATE_WORDS[t.verified_state] ?? t.verified_state;
60
+ out.push(...field("Status", t.workflow_state && t.verified_state !== "COMPLETED" ? `${status} · workflow ${t.workflow_state}` : status));
61
+ out.push(...field("Files", filesLine(ctx, state)));
62
+ if (t.corrections_total)
63
+ out.push(...field("Corrections", String(t.corrections_total)));
64
+ out.push(...field("Tests", testsLine(ctx)));
65
+ if (t.pending_operations.length) {
66
+ out.push(...field("Unresolved", `${plural(t.pending_operations.length, "operation")} — never resumed; propose again to continue`));
67
+ }
68
+ if (ctx.earlier_tasks.length)
69
+ out.push(...field("Earlier", plural(ctx.earlier_tasks.length + ctx.earlier_tasks_omitted, "task")));
70
+ out.push(repo?.same_repository === false
71
+ ? MARGIN + c.warn("Context not reused: this is a different repository.")
72
+ : MARGIN + c.ok("Context restored ✓"));
73
+ out.push(...note("Context only: files are read again and every change needs new approval.", MARGIN));
74
+ return out;
75
+ }
76
+ /**
77
+ * A small note at the start of a coding turn in a conversation that has a Task
78
+ * Context — never the context itself. Previous changes counts the applied
79
+ * changes the platform recorded across this conversation's coding tasks.
80
+ */
81
+ export function renderTaskContextRestored(ctx, state = [], repository, repo) {
82
+ const t = ctx.current;
83
+ const changedOnDisk = state.filter((e) => e.status !== "unchanged").length;
84
+ const row = (name, value) => MARGIN + " " + c.dim(name.padEnd(18)) + c.value(clip(stripControl(value), Math.max(8, cardWidth() - 20)));
85
+ if (repo?.same_repository === false) {
86
+ return ["", MARGIN + c.warn("Previous task context not reused"), row("Repository", repo.branch ? `${repo.name} · ${repo.branch}` : repo.name),
87
+ ...note("This is a different repository than the earlier work, so this task starts fresh.", MARGIN + " ")];
88
+ }
89
+ return [
90
+ "",
91
+ MARGIN + c.title("Using previous task context"),
92
+ row("Repository", repositoryLine(t.repository ?? repository ?? "this repository", repo)),
93
+ row("Previous task", t.title),
94
+ row("Relevant files", String(relevantFiles(ctx))),
95
+ row("Previous changes", String(previousChanges(ctx))),
96
+ ...(changedOnDisk ? [row("Changed on disk", `${changedOnDisk} file${changedOnDisk === 1 ? "" : "s"} since then`)] : []),
97
+ ...note("Context only: files are read again and every change needs new approval.", MARGIN + " ")
98
+ ];
99
+ }
package/dist/ui/trust.js CHANGED
@@ -1,4 +1,4 @@
1
- import path from "node:path";
1
+ import { folderKey, isTrustedFolder } from "../services/folder-key.js";
2
2
  import { c } from "./colors.js";
3
3
  import { pickFromList } from "./select.js";
4
4
  /**
@@ -10,15 +10,10 @@ import { pickFromList } from "./select.js";
10
10
  * `cos upload` reads paths directly — so a bare filename can send a local file
11
11
  * to the Carrier OS API. The answer is remembered per folder in the CLI config.
12
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
- }
13
+ /** Trust keys are canonical folder identities — see services/folder-key.ts. */
14
+ const normalize = folderKey;
20
15
  export function isTrusted(config, dir = process.cwd()) {
21
- return (config.get("trustedFolders") ?? []).includes(normalize(dir));
16
+ return isTrustedFolder(config.get("trustedFolders") ?? [], dir);
22
17
  }
23
18
  export function trustFolder(config, dir = process.cwd()) {
24
19
  const key = normalize(dir);
@@ -51,7 +46,7 @@ export function workspaceTrustLines(dir, width) {
51
46
  const body = (text) => wrap(text, width).map((l) => " " + c.value(l));
52
47
  return [
53
48
  " " + c.warn("─".repeat(width)),
54
- " " + c.warn.bold("Accessing workspace:"),
49
+ " " + c.warn.bold("Accessing local repository:"),
55
50
  "",
56
51
  " " + c.title(dir),
57
52
  "",
@@ -59,9 +54,9 @@ export function workspaceTrustLines(dir, width) {
59
54
  "(Like your own code, a well-known open source project, or work from your team). " +
60
55
  "If not, take a moment to review what's in this folder first."),
61
56
  "",
62
- ...body("Carrier OS'll be able to read files here and upload them to your workspace when you reference them."),
57
+ ...body("Carrier OS can read referenced files in this repository and send their contents to Carrier OS using your signed-in user account and CLI device session. File changes and commands require their own approval."),
63
58
  "",
64
- " " + c.dim("Security guide ") + c.dim(SECURITY_GUIDE_URL)
59
+ ...body("Normal CLI login uses your CarrierOS account. No Developer Platform workspace, project or API key is required.")
65
60
  ];
66
61
  }
67
62
  /**
package/dist/ui/ui.js CHANGED
@@ -22,6 +22,29 @@ export function termWidth(fallback = 80) {
22
22
  const w = process.stdout.columns;
23
23
  return w && w > 0 ? w : fallback;
24
24
  }
25
+ const UNITS = [[1e9, "B"], [1e6, "M"], [1e3, "K"]];
26
+ /**
27
+ * A large number the way dashboards show it: 12.47K, 1.25M — at most two
28
+ * decimals, trailing zeros dropped. Below 1,000, `small` formats it.
29
+ */
30
+ export function compactNumber(n, small) {
31
+ for (const [size, unit] of UNITS) {
32
+ // 999.996 rounds to 1,000.00 — that is "1K", not "1,000.00".
33
+ if (Math.abs(n) >= size * 0.999995)
34
+ return (n / size).toLocaleString("en-US", { maximumFractionDigits: 2 }) + unit;
35
+ }
36
+ return small(n);
37
+ }
38
+ /**
39
+ * A credit amount, everywhere credits appear: compact from 1,000 up (12.47K,
40
+ * 1.25M) and two decimals below it (23.67). A non-zero amount too small to
41
+ * show reads "<0.01" rather than a misleading "0.00".
42
+ */
43
+ export function formatCredits(n) {
44
+ if (n !== 0 && Math.abs(n) < 0.005)
45
+ return "<0.01";
46
+ return compactNumber(n, (v) => v.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 2 }));
47
+ }
25
48
  /** Visible length of a string, ignoring ANSI color codes. */
26
49
  export function visibleLen(s) {
27
50
  // eslint-disable-next-line no-control-regex
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carrieros/cli",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
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",
@@ -18,18 +18,20 @@
18
18
  "scripts": {
19
19
  "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
20
20
  "prebuild": "npm run clean",
21
- "build": "tsc -p tsconfig.json",
21
+ "build": "tsc -p tsconfig.json && node -e \"require('node:fs').chmodSync('dist/main.js', 0o755)\"",
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",
26
+ "prepack": "npm run build",
27
+ "package:staging": "npm run build && node scripts/package-staging.mjs",
27
28
  "test:pty": "npm run build && node test/acceptance/pty-selftest.mjs",
29
+ "test:execution": "npm run build && node scripts/validate-execution.mjs",
28
30
  "test:acceptance": "npm run build && node test/acceptance/live-acceptance.mjs",
29
31
  "build:helpers": "node scripts/build-helpers.mjs",
30
32
  "bundle": "npm run build && node scripts/bundle.mjs",
31
33
  "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})\"",
34
+ "package:win": "node scripts/package-win.mjs",
33
35
  "test:exe": "node test/acceptance/packaged-exe.mjs",
34
36
  "rehash-helpers": "node scripts/rehash-helpers.mjs"
35
37
  },
@@ -63,12 +65,14 @@
63
65
  "chalk": "^5.3.0",
64
66
  "commander": "^12.1.0",
65
67
  "form-data": "^4.0.1",
66
- "ora": "^8.1.1"
68
+ "ora": "^8.1.1",
69
+ "string-width": "7.2.0"
67
70
  },
68
71
  "devDependencies": {
69
72
  "@lydell/node-pty": "^1.2.0-beta.15",
70
73
  "@types/node": "^22.10.2",
71
74
  "esbuild": "^0.28.2",
75
+ "postject": "1.0.0-alpha.6",
72
76
  "tsx": "^4.19.2",
73
77
  "typescript": "^5.7.2"
74
78
  }