@illuminis/comprism 0.1.7 → 2.4.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.
Files changed (225) hide show
  1. package/out/{graph → build/machine/codemap}/read-python.js +2 -2
  2. package/out/{executor → build/machine/executor}/diagnostics.js +1 -1
  3. package/out/{executor → build/machine/executor}/hooks.js +1 -1
  4. package/out/{executor → build/machine/executor}/sandbox.js +1 -1
  5. package/out/build/machine/line/index.js +339 -0
  6. package/out/{commands/privacy.js → build/machine/runtime/home.js} +10 -19
  7. package/out/build/machine/runtime/needs.js +89 -0
  8. package/out/{lib → build/machine/runtime}/self.js +25 -3
  9. package/out/build/machine/terminal/jobs.js +67 -0
  10. package/out/build/machine/terminal/sign-in.js +212 -0
  11. package/out/build/machine/terminal/steps.js +460 -0
  12. package/out/build/machine/terminal/voice.js +136 -0
  13. package/out/build/machine/voice/record.js +286 -0
  14. package/out/cli-start.js +128 -0
  15. package/out/machine/line/index.js +339 -0
  16. package/out/machine/runtime/self.js +22 -0
  17. package/out/machine/terminal/clipboard.js +182 -0
  18. package/out/machine/terminal/jobs.js +67 -0
  19. package/out/machine/terminal/sign-in.js +212 -0
  20. package/out/machine/terminal/steps.js +460 -0
  21. package/out/machine/terminal/voice.js +136 -0
  22. package/out/machine/voice/record.js +79 -1
  23. package/out/native/dictate +0 -0
  24. package/out/server.generated.js +6 -0
  25. package/package.json +8 -40
  26. package/README.md +0 -343
  27. package/out/agent/command.d.ts +0 -157
  28. package/out/agent/command.js +0 -454
  29. package/out/agent/render.d.ts +0 -169
  30. package/out/agent/render.js +0 -689
  31. package/out/agent/session.d.ts +0 -334
  32. package/out/agent/session.js +0 -1223
  33. package/out/commands/agents.d.ts +0 -2
  34. package/out/commands/agents.js +0 -79
  35. package/out/commands/ask.d.ts +0 -1
  36. package/out/commands/ask.js +0 -222
  37. package/out/commands/codemap.d.ts +0 -2
  38. package/out/commands/codemap.js +0 -151
  39. package/out/commands/commands-thin.d.ts +0 -39
  40. package/out/commands/commands-thin.js +0 -244
  41. package/out/commands/config.d.ts +0 -1
  42. package/out/commands/config.js +0 -138
  43. package/out/commands/cost.d.ts +0 -1
  44. package/out/commands/cost.js +0 -167
  45. package/out/commands/decisionEngine.d.ts +0 -1
  46. package/out/commands/decisionEngine.js +0 -66
  47. package/out/commands/hooks.d.ts +0 -1
  48. package/out/commands/hooks.js +0 -83
  49. package/out/commands/install.d.ts +0 -206
  50. package/out/commands/install.js +0 -738
  51. package/out/commands/instructions.d.ts +0 -1
  52. package/out/commands/instructions.js +0 -113
  53. package/out/commands/integrations.d.ts +0 -3
  54. package/out/commands/integrations.js +0 -215
  55. package/out/commands/jobs.d.ts +0 -5
  56. package/out/commands/jobs.js +0 -157
  57. package/out/commands/keys.d.ts +0 -55
  58. package/out/commands/keys.js +0 -344
  59. package/out/commands/login.d.ts +0 -9
  60. package/out/commands/login.js +0 -606
  61. package/out/commands/memory.d.ts +0 -3
  62. package/out/commands/memory.js +0 -113
  63. package/out/commands/permissions.d.ts +0 -1
  64. package/out/commands/permissions.js +0 -94
  65. package/out/commands/plugins.d.ts +0 -4
  66. package/out/commands/plugins.js +0 -192
  67. package/out/commands/privacy.d.ts +0 -1
  68. package/out/commands/providerKey.d.ts +0 -32
  69. package/out/commands/providerKey.js +0 -108
  70. package/out/commands/repl.d.ts +0 -12
  71. package/out/commands/repl.js +0 -2303
  72. package/out/commands/report.d.ts +0 -39
  73. package/out/commands/report.js +0 -115
  74. package/out/commands/review.d.ts +0 -5
  75. package/out/commands/review.js +0 -223
  76. package/out/commands/sessions.d.ts +0 -23
  77. package/out/commands/sessions.js +0 -115
  78. package/out/commands/settings.d.ts +0 -23
  79. package/out/commands/settings.js +0 -153
  80. package/out/commands/skills.d.ts +0 -21
  81. package/out/commands/skills.js +0 -207
  82. package/out/commands/unattended.d.ts +0 -7
  83. package/out/commands/unattended.js +0 -351
  84. package/out/commands/update.d.ts +0 -1
  85. package/out/commands/update.js +0 -123
  86. package/out/commands/welcome.d.ts +0 -25
  87. package/out/commands/welcome.js +0 -223
  88. package/out/commands/worktrees.d.ts +0 -5
  89. package/out/commands/worktrees.js +0 -186
  90. package/out/executor/browser.d.ts +0 -14
  91. package/out/executor/diagnostics.d.ts +0 -2
  92. package/out/executor/documents.d.ts +0 -40
  93. package/out/executor/files.d.ts +0 -2
  94. package/out/executor/git.d.ts +0 -48
  95. package/out/executor/hooks.d.ts +0 -51
  96. package/out/executor/index.d.ts +0 -45
  97. package/out/executor/notebook.d.ts +0 -2
  98. package/out/executor/paths.d.ts +0 -20
  99. package/out/executor/sandbox.d.ts +0 -40
  100. package/out/executor/shell.d.ts +0 -86
  101. package/out/executor/toolservers.d.ts +0 -20
  102. package/out/executor/worktree.d.ts +0 -9
  103. package/out/graph/build.d.ts +0 -45
  104. package/out/graph/facts.d.ts +0 -47
  105. package/out/graph/files.d.ts +0 -45
  106. package/out/graph/read-locales.d.ts +0 -29
  107. package/out/graph/read-python.d.ts +0 -11
  108. package/out/graph/read-typescript.d.ts +0 -16
  109. package/out/graph/sync.d.ts +0 -66
  110. package/out/graph/sync.js +0 -242
  111. package/out/lib/attach.d.ts +0 -106
  112. package/out/lib/attach.js +0 -396
  113. package/out/lib/clipboard.d.ts +0 -23
  114. package/out/lib/commandlist.d.ts +0 -20
  115. package/out/lib/commandlist.js +0 -58
  116. package/out/lib/config.d.ts +0 -94
  117. package/out/lib/config.js +0 -197
  118. package/out/lib/connection.d.ts +0 -73
  119. package/out/lib/connection.js +0 -188
  120. package/out/lib/decision.d.ts +0 -22
  121. package/out/lib/decision.js +0 -50
  122. package/out/lib/fingerprint.d.ts +0 -25
  123. package/out/lib/fingerprint.js +0 -58
  124. package/out/lib/gateway.d.ts +0 -427
  125. package/out/lib/gateway.js +0 -226
  126. package/out/lib/history.d.ts +0 -24
  127. package/out/lib/history.js +0 -137
  128. package/out/lib/ide.d.ts +0 -19
  129. package/out/lib/ide.js +0 -131
  130. package/out/lib/keyboard.d.ts +0 -98
  131. package/out/lib/keyboard.js +0 -390
  132. package/out/lib/lastlogin.d.ts +0 -14
  133. package/out/lib/lastlogin.js +0 -105
  134. package/out/lib/machine.d.ts +0 -21
  135. package/out/lib/machine.js +0 -91
  136. package/out/lib/notify.d.ts +0 -4
  137. package/out/lib/notify.js +0 -52
  138. package/out/lib/output.d.ts +0 -48
  139. package/out/lib/output.js +0 -108
  140. package/out/lib/picker.d.ts +0 -1
  141. package/out/lib/picker.js +0 -158
  142. package/out/lib/project-ops.d.ts +0 -19
  143. package/out/lib/project-ops.js +0 -146
  144. package/out/lib/project.d.ts +0 -28
  145. package/out/lib/prompt.d.ts +0 -37
  146. package/out/lib/prompt.js +0 -142
  147. package/out/lib/queue.d.ts +0 -13
  148. package/out/lib/queue.js +0 -116
  149. package/out/lib/readiness.d.ts +0 -22
  150. package/out/lib/readiness.js +0 -207
  151. package/out/lib/self.d.ts +0 -23
  152. package/out/lib/servicecommand.d.ts +0 -14
  153. package/out/lib/servicecommand.js +0 -74
  154. package/out/lib/sessions.d.ts +0 -19
  155. package/out/lib/sessions.js +0 -221
  156. package/out/lib/startcache.d.ts +0 -13
  157. package/out/lib/startcache.js +0 -78
  158. package/out/lib/stdin.d.ts +0 -32
  159. package/out/lib/stdin.js +0 -117
  160. package/out/lib/store.d.ts +0 -40
  161. package/out/lib/store.js +0 -138
  162. package/out/lib/sync.d.ts +0 -18
  163. package/out/lib/sync.js +0 -81
  164. package/out/lib/types.d.ts +0 -417
  165. package/out/lib/types.js +0 -21
  166. package/out/lib/ui.d.ts +0 -123
  167. package/out/lib/ui.js +0 -299
  168. package/out/lib/version.d.ts +0 -23
  169. package/out/lib/version.js +0 -46
  170. package/out/lib/voice.d.ts +0 -49
  171. package/out/lib/voice.js +0 -236
  172. package/out/lib/words.d.ts +0 -20
  173. package/out/lib/words.js +0 -27
  174. package/out/machine/codemap/build.d.ts +0 -45
  175. package/out/machine/codemap/facts.d.ts +0 -47
  176. package/out/machine/codemap/files.d.ts +0 -45
  177. package/out/machine/codemap/read-locales.d.ts +0 -29
  178. package/out/machine/codemap/read-python.d.ts +0 -11
  179. package/out/machine/codemap/read-typescript.d.ts +0 -16
  180. package/out/machine/executor/browser.d.ts +0 -14
  181. package/out/machine/executor/diagnostics.d.ts +0 -2
  182. package/out/machine/executor/documents.d.ts +0 -40
  183. package/out/machine/executor/files.d.ts +0 -2
  184. package/out/machine/executor/git.d.ts +0 -48
  185. package/out/machine/executor/hooks.d.ts +0 -51
  186. package/out/machine/executor/index.d.ts +0 -45
  187. package/out/machine/executor/notebook.d.ts +0 -2
  188. package/out/machine/executor/paths.d.ts +0 -20
  189. package/out/machine/executor/sandbox.d.ts +0 -40
  190. package/out/machine/executor/shell.d.ts +0 -86
  191. package/out/machine/executor/toolservers.d.ts +0 -20
  192. package/out/machine/executor/worktree.d.ts +0 -9
  193. package/out/machine/folder/project.d.ts +0 -28
  194. package/out/machine/runtime/home.d.ts +0 -2
  195. package/out/machine/runtime/needs.d.ts +0 -30
  196. package/out/machine/runtime/self.d.ts +0 -23
  197. package/out/machine/voice/record.d.ts +0 -38
  198. package/out/postinstall.d.ts +0 -2
  199. package/out/postinstall.js +0 -120
  200. package/out/providers/anthropic.d.ts +0 -22
  201. package/out/providers/anthropic.js +0 -80
  202. package/out/providers/index.d.ts +0 -8
  203. package/out/providers/index.js +0 -84
  204. package/out/providers/openai.d.ts +0 -11
  205. package/out/providers/openai.js +0 -57
  206. package/out/thin.d.ts +0 -2
  207. package/out/thin.js +0 -855
  208. package/scripts/read_python.py +0 -270
  209. /package/out/{graph → build/machine/codemap}/build.js +0 -0
  210. /package/out/{graph → build/machine/codemap}/facts.js +0 -0
  211. /package/out/{graph → build/machine/codemap}/files.js +0 -0
  212. /package/out/{graph → build/machine/codemap}/read-locales.js +0 -0
  213. /package/out/{graph → build/machine/codemap}/read-typescript.js +0 -0
  214. /package/out/{executor → build/machine/executor}/browser.js +0 -0
  215. /package/out/{executor → build/machine/executor}/documents.js +0 -0
  216. /package/out/{executor → build/machine/executor}/files.js +0 -0
  217. /package/out/{executor → build/machine/executor}/git.js +0 -0
  218. /package/out/{executor → build/machine/executor}/index.js +0 -0
  219. /package/out/{executor → build/machine/executor}/notebook.js +0 -0
  220. /package/out/{executor → build/machine/executor}/paths.js +0 -0
  221. /package/out/{executor → build/machine/executor}/shell.js +0 -0
  222. /package/out/{executor → build/machine/executor}/toolservers.js +0 -0
  223. /package/out/{executor → build/machine/executor}/worktree.js +0 -0
  224. /package/out/{lib → build/machine/folder}/project.js +0 -0
  225. /package/out/{lib → build/machine/terminal}/clipboard.js +0 -0
@@ -1,157 +0,0 @@
1
- import { type JobResult } from "./session";
2
- import { type OutputChoice } from "../lib/output";
3
- export interface AgentArgs {
4
- request: string[];
5
- /** Inside a session: background processes outlive this job and are stopped
6
- * when the session ends (manual 5.13). */
7
- keepProcesses?: boolean;
8
- /** Seconds each command may run before it is stopped (manual 5.12). */
9
- timeout?: number;
10
- /** Start from this GitHub issue (manual 5.20). */
11
- issue?: number;
12
- /** Lead the team defined under this name (manual 5.27). */
13
- team?: string;
14
- /** A review, not a request: the instruction is the service's (manual 5.19). */
15
- review?: {
16
- pr?: number;
17
- post?: boolean;
18
- };
19
- /** Start it and hand the terminal back. See `runDetached` for what this can
20
- * and cannot do. */
21
- background?: boolean;
22
- mode?: string;
23
- plan?: boolean;
24
- /** The person read the plan and said build it. Changes to files in this
25
- * project then happen without being asked about one at a time. Commands and
26
- * publishing are still asked about. */
27
- approvePlan?: boolean;
28
- model?: string;
29
- /** Run `model` and nothing else, whatever the router would prefer. */
30
- pin?: boolean;
31
- maxSpend?: number;
32
- /** Stop after this many steps (manual 4.13). */
33
- maxSteps?: number;
34
- /** No new step after this many minutes (manual 10.7). */
35
- maxMinutes?: number;
36
- /** Reasoning effort: low, medium or high (manual 4.18). */
37
- effort?: string;
38
- /** Run commands in the operating system's sandbox (manual 4.12). */
39
- sandbox?: boolean;
40
- /** `--allow "python3 grade.py"`, repeatable. Exact commands, pre approved. */
41
- allow?: string[];
42
- yes?: boolean;
43
- resume?: string;
44
- /**
45
- * Go without the code map for this job, whatever the company setting says.
46
- *
47
- * Two people need it and both are legitimate. The corpus study, because a run
48
- * with a map and a run without one are two different quantities and averaging
49
- * them would flatter whichever arm happened to have one. And anybody who
50
- * suspects the map and wants the files read directly.
51
- */
52
- noMap?: boolean;
53
- /** The job this question follows on from, so the agent knows what was
54
- * already said. Not the same as `resume`, which re-enters a job that stopped
55
- * part way; this is the ordinary next question in a conversation. */
56
- continuesJob?: string;
57
- /** Which conversation this job belongs to, so the server files it under the
58
- * session the person is actually in rather than under their whole day. */
59
- conversationId?: string;
60
- cwd?: string;
61
- /** Other folders the person named with `--add-folder` or `folders add`
62
- * (manual 2.3). Nothing else ever becomes an allowed folder. */
63
- addFolders?: string[];
64
- /**
65
- * Ask the person a yes or no question.
66
- *
67
- * Supplied by a caller that already owns the keyboard, so a session and the
68
- * agent never open two readers on it. Two readers divide the typing between
69
- * them and the second one reads nothing, which is how a request to run a
70
- * command inside a session came back refused with nobody having declined it.
71
- *
72
- * Absent, the agent opens its own reader exactly as it always has, which is
73
- * what the standalone command wants.
74
- */
75
- confirm?: (question: string) => Promise<boolean>;
76
- /** A line of text from the same lent keyboard, for the plan question and the
77
- * agent's questions. Null means Ctrl+C. */
78
- prompt?: (question: string) => Promise<string | null>;
79
- /**
80
- * Files already uploaded, to be put in front of this question.
81
- *
82
- * Ids, never contents: the file was read by the server when it was attached,
83
- * and what it holds is text with a half-hour life. Sending the bytes again
84
- * here would be sending them twice and storing them nowhere useful.
85
- */
86
- attachments?: string[];
87
- /** Names of files the person named that could not be attached, so the
88
- * agent is told rather than left to guess (manual 3.10). */
89
- leftOut?: string[];
90
- /** The terminal to ask approval questions at when standard input is a
91
- * pipe (manual 3.9). Never the pipe itself. */
92
- keyboard?: NodeJS.ReadableStream | null;
93
- /**
94
- * Handed a way to stop the job, as soon as there is one to stop.
95
- *
96
- * For a caller that owns the keyboard and therefore also owns Ctrl+C. This
97
- * command stops a job on its own SIGINT handler, and a caller holding a
98
- * readline interface never lets that handler fire, so without this the job
99
- * carried on after the person asked to leave and the session closed reporting
100
- * a cost of nothing on work it had already paid for.
101
- */
102
- /** Handed the controls the moment the job starts: stop it, or say something
103
- * to it while it runs. A caller that owns the keyboard needs both, because
104
- * a person watching a job go the wrong way at step three should be able to
105
- * correct it rather than stop it and start again. */
106
- onStarted?: (controls: JobControls) => void;
107
- /** `--output` and `--quiet`, and whether standard output is a terminal
108
- * (manual 10.2, 10.3). Absent inside a session, which always draws. */
109
- output?: OutputChoice;
110
- /** `--schema`: the answer must be JSON of this shape (manual 10.5). */
111
- answerSchema?: Record<string, unknown>;
112
- /** A queued job this runner claimed (10.17 to 10.19); the service holds
113
- * its request, mode and limits. */
114
- queuedJob?: string;
115
- /** `--config`: settings read as if they were the project file (10.8). */
116
- settingsConfig?: Record<string, unknown>;
117
- /** `--no-personal`: leave out personal settings and instructions (10.8). */
118
- noPersonal?: boolean;
119
- /** Start in the full view (manual 6.9), because Ctrl+O was pressed earlier. */
120
- fullView?: boolean;
121
- /**
122
- * Told what the job cost, once it has finished.
123
- *
124
- * The command itself only needs an exit code, so that is still what this
125
- * returns. A session running several jobs needs the figures as well, to keep
126
- * a running total: without them it showed every session as zero spent and
127
- * zero saved, which is the one number this product cannot get wrong.
128
- *
129
- * Not called when the job never started, because there is nothing to add.
130
- */
131
- onFinished?: (result: JobResult) => void;
132
- }
133
- export declare const MODES: string[];
134
- /** What a caller holding the keyboard can do to a running job (manual 6.7 to
135
- * 6.9). Every one of them is a message to the service, which decides. */
136
- export interface JobControls {
137
- cancel: () => void;
138
- steer: (text: string) => void;
139
- pause: () => void;
140
- carryOn: (text: string) => void;
141
- isPaused: () => boolean;
142
- queue: (clear: boolean) => void;
143
- setFull: (on: boolean) => void;
144
- /** Helpers running now, as the service reported them (manual 5.25). */
145
- helpers: () => Array<{
146
- id: string;
147
- question: string;
148
- agent?: string | null;
149
- }>;
150
- /** `stop h2`: the service stops that helper, the rest carry on. */
151
- stopHelper: (id: string) => void;
152
- /** The job's id, once the service has issued it. */
153
- jobId: () => string | undefined;
154
- }
155
- export declare function runAgent(args: AgentArgs): Promise<number>;
156
- /** The help text. Written to be read by somebody who has not read anything else. */
157
- export declare const AGENT_HELP: string;
@@ -1,454 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.AGENT_HELP = exports.MODES = void 0;
37
- exports.runAgent = runAgent;
38
- /**
39
- * `comprism work` — the coding agent, from a terminal.
40
- *
41
- * Specification: docs/modules/CODING_AGENT_BUILD_SPECIFICATION.md, register
42
- * items A6 (interactive), A7 (scriptable), C14 (resume) and L2 (how to install
43
- * it).
44
- *
45
- * ## Two shapes, one session
46
- *
47
- * With a person at the keyboard, approvals are asked, Ctrl+C stops the run
48
- * rather than killing the process, and anything typed while it works joins the
49
- * next step.
50
- *
51
- * With `--yes` or no terminal attached, nobody is asked anything. The
52
- * permission mode has to have settled it in advance, and an action that would
53
- * need an approval is refused rather than assumed. **Silence is never consent**:
54
- * a script that needs to change files says so by choosing a mode that allows it.
55
- */
56
- const fs = __importStar(require("fs"));
57
- const readline = __importStar(require("readline"));
58
- const connection_1 = require("../lib/connection");
59
- const project_1 = require("../machine/folder/project");
60
- const session_1 = require("./session");
61
- const ui = __importStar(require("./render"));
62
- const output_1 = require("../lib/output");
63
- const self_1 = require("../machine/runtime/self");
64
- /** The WebSocket the session needs is a global from Node 22.
65
- *
66
- * Checked here with a message somebody can act on. Without it the failure is
67
- * `WebSocket is not defined` from inside a library, which reads as a broken
68
- * install rather than an old runtime. */
69
- function requireWebSocket() {
70
- if (typeof globalThis.WebSocket === "function")
71
- return true;
72
- process.stderr.write(ui.red(" This needs Node 22 or newer.") +
73
- ui.dim(` You are on ${process.version}. Upgrade Node and try again.\n`));
74
- return false;
75
- }
76
- exports.MODES = ["read_only", "approve_writes", "auto_edit", "full_auto"];
77
- /**
78
- * Start a job, hand the terminal back, and keep working.
79
- *
80
- * Specification register item C15.
81
- *
82
- * **What this honestly is, and is not.** The job continues without somebody
83
- * watching it, and it writes to a log they can follow or ignore. The machine has
84
- * to stay on, because the actions run HERE: reading and changing files is done
85
- * by this process on this disk, and no amount of server-side cleverness moves
86
- * that. A laptop that goes to sleep pauses the job, and the job says so when it
87
- * wakes.
88
- *
89
- * Anything needing an approval is refused rather than waited on, for the same
90
- * reason `--yes` refuses: nobody is there, and treating silence as consent would
91
- * let a job change files nobody ever saw. So a background job is only useful in
92
- * a permission mode that settles it in advance, and the command says so rather
93
- * than letting somebody find out an hour later.
94
- */
95
- async function runDetached(args) {
96
- const { spawn } = await Promise.resolve().then(() => __importStar(require("child_process")));
97
- const os = await Promise.resolve().then(() => __importStar(require("os")));
98
- const pathMod = await Promise.resolve().then(() => __importStar(require("path")));
99
- const mode = args.mode ?? "approve_writes";
100
- if (mode === "approve_writes" || mode === "read_only") {
101
- process.stderr.write(ui.red(" A background job cannot ask you anything, so in this mode it "
102
- + "would refuse every change.\n")
103
- + ui.dim(" Use --mode auto_edit or --mode full_auto, or run it in the "
104
- + "foreground.\n"));
105
- return 1;
106
- }
107
- const logPath = pathMod.join(os.tmpdir(), `comprism-agent-${Date.now()}.log`);
108
- const log = fs.openSync(logPath, "a");
109
- // Detached, with its own process group, so closing the terminal does not take
110
- // the job with it. `unref` is what actually lets this process exit.
111
- const child = spawn(...(0, self_1.selfLaunch)([
112
- "agent",
113
- ...args.request,
114
- "--mode", mode, "--yes",
115
- ...(args.model ? ["--model", args.model] : []),
116
- ...(args.pin ? ["--pin"] : []),
117
- ...(args.maxSpend ? ["--max-spend", String(args.maxSpend)] : []),
118
- ...(args.timeout ? ["--timeout", String(args.timeout)] : []),
119
- ...(args.allow ?? []).flatMap((c) => ["--allow", c]),
120
- ...(args.cwd ? ["--cwd", args.cwd] : []),
121
- ...(args.addFolders ?? []).flatMap((f) => ["--add-folder", f]),
122
- ]), {
123
- detached: true, stdio: ["ignore", log, log],
124
- // Marked, so the job is recorded as a background job and its log can be
125
- // found again by `comprism jobs attach` (manual 5.14).
126
- env: { ...process.env, NO_COLOR: "1", COMPRISM_BACKGROUND: "1", COMPRISM_JOB_LOG: logPath },
127
- });
128
- child.unref();
129
- process.stdout.write(ui.green(` Started in the background as process ${child.pid}.\n`)
130
- + ui.dim(" comprism jobs lists it; comprism jobs attach <job> watches it.\n")
131
- + ui.dim(` Follow it: tail -f ${logPath}\n`)
132
- + ui.dim(" It keeps working while you do something else. This machine has "
133
- + "to stay awake: the files are here, so the work is too.\n"));
134
- return 0;
135
- }
136
- async function runAgent(args) {
137
- const output = args.output;
138
- const json = output?.format === "json";
139
- const streaming = output?.format === "stream";
140
- // A stream is lines the service built, printed as they come (manual 10.4).
141
- // If the program reading it goes away, the job is stopped and the exit is
142
- // 141, with nothing said about it.
143
- let pipeClosed = false;
144
- let finishedLine = false;
145
- let stopJob = null;
146
- const emit = (items) => {
147
- for (const item of items) {
148
- if (pipeClosed)
149
- return;
150
- if (item.event === "job_finished")
151
- finishedLine = true;
152
- process.stdout.write(JSON.stringify(item) + "\n");
153
- }
154
- };
155
- if (streaming) {
156
- process.stdout.on("error", (e) => {
157
- if (e.code !== "EPIPE")
158
- return;
159
- pipeClosed = true;
160
- stopJob?.();
161
- });
162
- }
163
- /** An ending the service never saw: its number, and with --output json the
164
- * result object in its published shape (manual 10.3, Appendix B). */
165
- const ended = (reason, why) => {
166
- if (json)
167
- (0, output_1.printJson)((0, output_1.localResult)(reason, why));
168
- if (streaming)
169
- emit([{ event: "job_finished", ...(0, output_1.localResult)(reason, why) }]);
170
- return (0, output_1.exitFor)(reason);
171
- };
172
- // A folder that does not exist is refused before anything runs or is charged
173
- // (manual 2.1, exit 2 in Appendix B).
174
- const folders = [];
175
- for (const raw of [args.cwd ?? process.cwd(), ...(args.addFolders ?? [])]) {
176
- const found = (0, project_1.checkFolder)(raw);
177
- if (!found.ok) {
178
- process.stderr.write(ui.red(` ${found.why}`) + ui.dim(" Nothing ran and nothing was charged.\n"));
179
- return 2;
180
- }
181
- folders.push(found.path);
182
- }
183
- const [startFolder, ...added] = folders;
184
- if (!requireWebSocket())
185
- return 1;
186
- if (args.background)
187
- return runDetached({ ...args, cwd: startFolder, addFolders: added });
188
- const connection = (0, connection_1.readConnection)();
189
- if (!connection?.url) {
190
- process.stderr.write(
191
- // The command named here MUST be one this tool actually has. It said
192
- // `comprism login`, which has never existed, so the one instruction a
193
- // brand new user is given was a dead end.
194
- ui.red(" Not signed in.") +
195
- ui.dim(" Run `comprism login` first.\n"));
196
- return ended("signed_out", "Not signed in. Run comprism login first.");
197
- }
198
- // The machine credential, not the session token. The session token belongs to
199
- // a browser sign-in and is short lived; this is the long-lived credential
200
- // minted for this laptop, listed in the portal beside every other machine and
201
- // revocable on its own. A job running for twenty minutes must not stop
202
- // because a browser session expired somewhere else.
203
- const credential = connection.workspaceKey;
204
- if (!credential) {
205
- process.stderr.write(ui.red(" This machine has no workspace key.") +
206
- ui.dim(" Run `comprism connect` again to mint one.\n"));
207
- return ended("signed_out", "This machine has no workspace key. Run comprism connect again.");
208
- }
209
- const project = (0, project_1.resolveProject)(startFolder, added);
210
- const root = project.root;
211
- // Absent means the settings decide (manual 2.10): the service resolves the
212
- // mode from the local and project settings files and your account.
213
- const mode = args.mode;
214
- if (mode !== undefined && !exports.MODES.includes(mode)) {
215
- process.stderr.write(ui.red(` ${mode} is not a permission mode.`) +
216
- ui.dim(` One of: ${exports.MODES.join(", ")}\n`));
217
- return ended("usage", `${mode} is not a permission mode.`);
218
- }
219
- // `--sandbox` never runs without one (manual 4.12): refused before anything
220
- // runs or is charged.
221
- if (args.sandbox) {
222
- const { availability } = await Promise.resolve().then(() => __importStar(require("../machine/executor/sandbox")));
223
- const found = availability();
224
- if (!found.system) {
225
- process.stderr.write(ui.red(` --sandbox cannot start: ${found.why}.`)
226
- + ui.dim(" Nothing ran and nothing was charged.\n"));
227
- return 1;
228
- }
229
- }
230
- const request = args.request.join(" ").trim();
231
- if (!request && !args.resume) {
232
- process.stderr.write(ui.dim(" Say what you want done.\n"));
233
- return 1;
234
- }
235
- // Headless when asked for, and also when there is no terminal at all: piped
236
- // into a script, nobody is there to answer an approval, and pretending
237
- // otherwise would hang the pipeline until it timed out.
238
- //
239
- // Standard input that is a pipe is material, never answers (manual 3.9):
240
- // questions then go to the terminal the caller opened, and with none the
241
- // job is unattended.
242
- const questions = process.stdin.isTTY
243
- ? process.stdin : args.keyboard ?? null;
244
- const headless = Boolean(args.yes) || !questions;
245
- // ONE reader for the whole job when nobody lent a keyboard: it carries what
246
- // is typed while the agent works, and it answers questions and approvals.
247
- // Two readers on one keyboard divide the typing, so an answer also arrived
248
- // as a correction to the job.
249
- let steering = null;
250
- let waiting = null;
251
- const ownPrompt = (question) => new Promise((resolve) => {
252
- process.stdout.write(` ${question} `);
253
- waiting = resolve;
254
- });
255
- const lent = args.confirm || headless ? {} : {
256
- prompt: ownPrompt,
257
- confirm: async (question) => /^y(es)?$/i.test(((await ownPrompt(question)) ?? "").trim()),
258
- };
259
- // With standard output going to a script, everything the job says on the
260
- // way goes to standard error, and only the result goes to standard output
261
- // (manual 10.2). `--quiet` drops the progress altogether.
262
- const toErr = output ? (0, output_1.progressToErr)(output) : false;
263
- const write = output?.quiet || streaming ? () => undefined
264
- : toErr ? (s) => { process.stderr.write(s); } : (s) => { process.stdout.write(s); };
265
- const session = new session_1.TerminalSession({
266
- baseUrl: connection.url,
267
- credential,
268
- root,
269
- project,
270
- permissionMode: mode,
271
- planOnly: Boolean(args.plan),
272
- planApproved: Boolean(args.approvePlan),
273
- model: args.model,
274
- pinModel: Boolean(args.pin),
275
- maxSpendUsd: args.maxSpend,
276
- maxSteps: args.maxSteps,
277
- maxMinutes: args.maxMinutes,
278
- effort: args.effort,
279
- sandbox: Boolean(args.sandbox),
280
- commandTimeoutS: args.timeout,
281
- issue: args.issue,
282
- team: args.team,
283
- review: args.review,
284
- keepProcesses: Boolean(args.keepProcesses),
285
- approvedCommands: args.allow ?? [],
286
- attachmentIds: args.attachments ?? [],
287
- leftOut: args.leftOut ?? [],
288
- headless,
289
- confirm: args.confirm,
290
- prompt: args.prompt,
291
- ...lent,
292
- resumeJobId: args.resume,
293
- continuesJob: args.continuesJob,
294
- conversationId: args.conversationId,
295
- withoutMap: Boolean(args.noMap),
296
- ...(args.answerSchema ? { answerSchema: args.answerSchema } : {}),
297
- ...(args.queuedJob ? { queuedJob: args.queuedJob } : {}),
298
- ...(args.settingsConfig ? { settingsConfig: args.settingsConfig } : {}),
299
- noPersonal: Boolean(args.noPersonal),
300
- ...(streaming ? { onStream: emit } : {}),
301
- }, write);
302
- stopJob = () => session.cancel();
303
- // Ctrl+C stops the JOB, not the process. Killing the process would leave the
304
- // job running on the server with nothing watching it, and whatever the agent
305
- // had started on this machine would carry on unsupervised.
306
- let interrupted = false;
307
- const onInterrupt = () => {
308
- interrupted = true;
309
- // Ctrl+C at a question answers it as stopped, then stops the job.
310
- const w = waiting;
311
- waiting = null;
312
- if (w) {
313
- process.stdout.write("\n");
314
- w(null);
315
- }
316
- session.cancel();
317
- };
318
- process.on("SIGINT", onInterrupt);
319
- session.full = Boolean(args.fullView);
320
- args.onStarted?.({
321
- cancel: () => session.cancel(),
322
- steer: (text) => session.steer(text),
323
- pause: () => session.pause(),
324
- carryOn: (text) => session.carryOn(text),
325
- isPaused: () => session.paused,
326
- queue: (clear) => session.queue(clear),
327
- setFull: (on) => { session.full = on; },
328
- jobId: () => session.jobId,
329
- helpers: () => [...session.helpers.values()],
330
- stopHelper: (id) => session.stopHelper(id),
331
- });
332
- // Anything typed while it works. Not a prompt, deliberately: the run is
333
- // printing, and a prompt competing with it for the same lines is unreadable.
334
- //
335
- // Skipped entirely when the caller lent us a keyboard. The whole point of
336
- // `confirm` is that one component owns the terminal; opening a reader here as
337
- // well would put the same two owners back on it by another door, and the
338
- // caller is the one already reading what gets typed.
339
- if (!headless && !args.confirm) {
340
- steering = readline.createInterface({ input: questions, terminal: false });
341
- steering.on("line", (line) => {
342
- const w = waiting;
343
- if (w) {
344
- waiting = null;
345
- w(line);
346
- return;
347
- }
348
- const text = line.trim();
349
- if (text)
350
- session.steer(text);
351
- });
352
- }
353
- try {
354
- const result = await session.run(request);
355
- args.onFinished?.(result);
356
- // A job on its own is its session, and it has ended (manual 7.3).
357
- if (!args.keepProcesses && args.conversationId) {
358
- const { review } = await Promise.resolve().then(() => __importStar(require("../commands/review")));
359
- await review("session_ended", { session_id: args.conversationId }).catch(() => undefined);
360
- }
361
- // How it ended is the service's reason word; the number comes from the
362
- // table the service sent with it (manual 10.6, Appendix B). The only
363
- // endings decided here are the ones the service could not see: a dropped
364
- // connection with an action in doubt (8.9), Ctrl+C, and never reaching it.
365
- const reason = result.outcome === "unknown" ? "unknown"
366
- : interrupted ? "interrupted"
367
- : result.ending?.reason ?? result.refusalReason
368
- ?? (result.outcome === "finished" ? "done" : "incomplete");
369
- if (pipeClosed)
370
- return (0, output_1.exitFor)("output_closed", result.exitStatus);
371
- const code = (0, output_1.exitFor)(reason, result.exitStatus);
372
- if (streaming) {
373
- // A job refused before it started has sent no stream, so its end is
374
- // the service's result for the refusal.
375
- if (!finishedLine) {
376
- emit([{ event: "job_finished", ...(result.result ?? (0, output_1.localResult)(reason, result.detail ?? reason)) }]);
377
- }
378
- if (code !== 0)
379
- process.stderr.write(` ${result.ending?.line ?? result.detail ?? reason}\n`);
380
- }
381
- else if (json) {
382
- (0, output_1.printJson)(result.result && reason !== "unknown" && !interrupted
383
- ? result.result : (0, output_1.localResult)(reason, result.detail ?? reason));
384
- }
385
- else if (toErr) {
386
- // The final summary, and nothing else, on standard output (10.2).
387
- const summary = result.ending?.line ?? result.detail ?? "";
388
- if (summary)
389
- process.stdout.write(`${summary}\n`);
390
- if (result.text.trim() && result.text.trim() !== summary)
391
- process.stdout.write(`${result.text.trim()}\n`);
392
- }
393
- if (code !== 0 && output?.quiet) {
394
- // A number other than 0 comes with a one line reason on standard error.
395
- process.stderr.write(` ${result.ending?.line ?? result.detail ?? reason}\n`);
396
- }
397
- return code;
398
- }
399
- catch (err) {
400
- // The live connection never opened: the service could not be reached
401
- // (manual 10.14, exit 6).
402
- process.stderr.write(ui.red(` ${err.message}\n`));
403
- return ended("unreachable", err.message);
404
- }
405
- finally {
406
- process.off("SIGINT", onInterrupt);
407
- steering?.close();
408
- }
409
- }
410
- /** The help text. Written to be read by somebody who has not read anything else. */
411
- exports.AGENT_HELP = `
412
- ${ui.bold("comprism work")} — a coding agent in your terminal
413
-
414
- comprism work "add a test for the parser and make it pass"
415
-
416
- ${ui.bold("What it does")}
417
- Reads your workspace, changes files, runs commands and runs your tests. It
418
- shows you every change as it makes it, asks before deleting a file or
419
- running a command, and can undo the whole job. Each step is routed to whichever
420
- model finishes the work for least, and the receipt at the end says what it
421
- cost.
422
-
423
- ${ui.bold("Options")}
424
- --mode <mode> read_only, approve_writes (default), auto_edit, full_auto
425
- --worktree <name> work in a separate copy of the repository on its own branch
426
- --plan work out what it would do and change nothing
427
- --approve-plan you read the plan and want it built. Files change without
428
- being asked about one at a time; commands still ask
429
- --model <id> tell it which model you are running, so the receipt can
430
- price the saving against it. It may still move you up
431
- --no-optimize Optimize off: run --model and nothing else (also --pin)
432
- --max-spend <usd> stop at this much rather than running on
433
- --max-steps <n> stop after this many steps
434
- --max-minutes <n> start no new step after this many minutes
435
- --effort <level> low, medium or high: how carefully the model thinks
436
- --sandbox run commands in the operating system's sandbox
437
- --timeout <secs> time limit for each command, two minutes unless set
438
- --issue <n> start from GitHub issue n; its text is information only
439
- --team <name> lead the team defined in .completionprism/teams/<name>.md
440
- --allow "<cmd>" approve one exact command up front, repeatable. The only
441
- way an unattended run can verify its own work
442
- --yes never ask; anything needing approval is refused instead
443
- --background start it and get your terminal back; it keeps working
444
- --resume <job> carry on from a job you already started
445
- --cwd <path> work in this folder rather than the current one
446
- --cloud run it on a CompletionPrism worker with a copy of the
447
- repository; comprism --resume <session> brings it back
448
- --add-folder <path> also allow this folder, repeatable
449
- --no-map do not use the code map for this job; read the files
450
-
451
- ${ui.bold("While it runs")}
452
- Ctrl+C stops the job. Anything you type joins the next step, so you can
453
- correct it without starting again.
454
- `;