@illuminis/comprism 0.1.8 → 2.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 (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 +130 -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 -1232
  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
@@ -0,0 +1,212 @@
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.keychainAvailable = void 0;
37
+ exports.readSignIn = readSignIn;
38
+ exports.writeSignIn = writeSignIn;
39
+ exports.clearSignIn = clearSignIn;
40
+ exports.readLast = readLast;
41
+ exports.saveLast = saveLast;
42
+ exports.forgetLast = forgetLast;
43
+ exports.savedPassword = savedPassword;
44
+ exports.savePassword = savePassword;
45
+ exports.forgetPassword = forgetPassword;
46
+ exports.openAddress = openAddress;
47
+ /**
48
+ * Device helper: the terminal tool's sign in, kept in this computer's key store.
49
+ *
50
+ * The one thing the tool keeps on the computer, and the reason: it is the sign
51
+ * in credential (the workspace address, the tenant and the keys that sign this
52
+ * computer in), and it is needed before the server can be asked anything. On a
53
+ * Mac it lives in the person's login keychain; elsewhere, where there is no key
54
+ * store the tool can reach without extra software, in one owner readable file.
55
+ * The last sign in (email and workspace, so signing in again is one key) and a
56
+ * password the person chose to save sit beside it, in the same place.
57
+ *
58
+ * Loaded only by the tool's starting file, which hands it to the sign in code.
59
+ */
60
+ const cp = __importStar(require("node:child_process"));
61
+ const fs = __importStar(require("node:fs"));
62
+ const os = __importStar(require("node:os"));
63
+ const path = __importStar(require("node:path"));
64
+ const home_1 = require("../runtime/home");
65
+ const KEYCHAIN = process.platform === 'darwin' && !process.env.COMPRISM_HOME;
66
+ const ACCOUNT = (() => { try {
67
+ return os.userInfo().username;
68
+ }
69
+ catch {
70
+ return 'comprism';
71
+ } })();
72
+ const ITEM = { connection: 'CompletionPrism sign in', last: 'CompletionPrism last sign in' };
73
+ const cache = new Map();
74
+ function file(item) {
75
+ return path.join((0, home_1.homeDir)(), item === 'connection' ? 'connection.json' : 'last-login.json');
76
+ }
77
+ function readFileItem(item) {
78
+ try {
79
+ return fs.readFileSync(file(item), 'utf8');
80
+ }
81
+ catch {
82
+ return null;
83
+ }
84
+ }
85
+ function writeFileItem(item, text) {
86
+ fs.mkdirSync((0, home_1.homeDir)(), { recursive: true, mode: 0o700 });
87
+ fs.writeFileSync(file(item), text, { mode: 0o600 });
88
+ try {
89
+ fs.chmodSync(file(item), 0o600);
90
+ }
91
+ catch { /* a filesystem without modes */ }
92
+ }
93
+ function security(args) {
94
+ const r = cp.spawnSync('security', args, { encoding: 'utf8' });
95
+ return { ok: r.status === 0, out: String(r.stdout ?? '').replace(/\n$/, '') };
96
+ }
97
+ function readItem(item) {
98
+ if (cache.has(item))
99
+ return cache.get(item) ?? null;
100
+ let got = null;
101
+ if (KEYCHAIN) {
102
+ const r = security(['find-generic-password', '-a', ACCOUNT, '-s', ITEM[item], '-w']);
103
+ got = r.ok ? r.out : null;
104
+ // A sign in kept in a file by an earlier version (or by the editor
105
+ // extension, which still reads it there) is copied into the keychain.
106
+ if (got === null) {
107
+ const old = readFileItem(item);
108
+ if (old !== null) {
109
+ try {
110
+ writeItem(item, old);
111
+ }
112
+ catch { /* read from the file meanwhile */ }
113
+ got = old;
114
+ }
115
+ }
116
+ }
117
+ else {
118
+ got = readFileItem(item);
119
+ }
120
+ cache.set(item, got);
121
+ return got;
122
+ }
123
+ function writeItem(item, text) {
124
+ if (KEYCHAIN) {
125
+ const r = security(['add-generic-password', '-U', '-a', ACCOUNT, '-s', ITEM[item], '-l', ITEM[item], '-w', text]);
126
+ if (!r.ok)
127
+ throw new Error('The sign in could not be kept in this computer\'s keychain.');
128
+ }
129
+ else {
130
+ writeFileItem(item, text);
131
+ }
132
+ cache.set(item, text);
133
+ }
134
+ function clearItem(item) {
135
+ if (KEYCHAIN)
136
+ security(['delete-generic-password', '-a', ACCOUNT, '-s', ITEM[item]]);
137
+ try {
138
+ fs.rmSync(file(item), { force: true });
139
+ }
140
+ catch { /* already gone */ }
141
+ cache.set(item, null);
142
+ }
143
+ function readJson(item) {
144
+ const text = readItem(item);
145
+ if (!text)
146
+ return null;
147
+ try {
148
+ return JSON.parse(text);
149
+ }
150
+ catch {
151
+ return null;
152
+ }
153
+ }
154
+ /** The kept sign in, or null. */
155
+ function readSignIn() { return readJson('connection'); }
156
+ /** Keep the sign in. */
157
+ function writeSignIn(value) { writeItem('connection', `${JSON.stringify(value, null, 2)}\n`); }
158
+ /** Forget the sign in. */
159
+ function clearSignIn() {
160
+ try {
161
+ clearItem('connection');
162
+ return true;
163
+ }
164
+ catch {
165
+ return false;
166
+ }
167
+ }
168
+ /** Who signed in last here, or null. */
169
+ function readLast() { return readJson('last'); }
170
+ function saveLast(value) {
171
+ try {
172
+ writeItem('last', JSON.stringify(value));
173
+ }
174
+ catch { /* the next sign in asks */ }
175
+ }
176
+ function forgetLast() {
177
+ try {
178
+ clearItem('last');
179
+ }
180
+ catch { /* nothing kept */ }
181
+ }
182
+ /** A password the person chose to keep, in the Mac's own keychain. */
183
+ const passwordItem = (workspace) => `CompletionPrism ${workspace}`;
184
+ const keychainAvailable = () => process.platform === 'darwin';
185
+ exports.keychainAvailable = keychainAvailable;
186
+ function savedPassword(email, workspace) {
187
+ if (!(0, exports.keychainAvailable)() || !email || !workspace)
188
+ return null;
189
+ const r = security(['find-generic-password', '-a', email, '-s', passwordItem(workspace), '-w']);
190
+ return r.ok ? r.out : null;
191
+ }
192
+ function savePassword(email, workspace, password) {
193
+ if (!(0, exports.keychainAvailable)())
194
+ return false;
195
+ return security(['add-generic-password', '-U', '-a', email, '-s', passwordItem(workspace),
196
+ '-l', passwordItem(workspace), '-w', password]).ok;
197
+ }
198
+ function forgetPassword(email, workspace) {
199
+ if (!(0, exports.keychainAvailable)())
200
+ return;
201
+ security(['delete-generic-password', '-a', email, '-s', passwordItem(workspace)]);
202
+ }
203
+ /** Open the sign in page in the person's browser: part of signing in, before
204
+ * there is a line to the server. The address is one argument, never a shell string. */
205
+ function openAddress(url) {
206
+ if (process.env.COMPRISM_NO_BROWSER === '1')
207
+ return;
208
+ const [cmd, argv] = process.platform === 'darwin' ? ['open', [url]]
209
+ : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
210
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- opens a sign in address, one argument, no shell
211
+ cp.spawn(cmd, argv, { stdio: 'ignore', detached: true }).on('error', () => undefined).unref();
212
+ }
@@ -0,0 +1,460 @@
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.STEPS = void 0;
37
+ exports.runStep = runStep;
38
+ /**
39
+ * The terminal tool's steps on this computer: the fixed list the machine line
40
+ * runs when the server orders one.
41
+ *
42
+ * Nothing goes around the server (owner, October 17, 2026). The server's
43
+ * computer service orders a step by name over the machine line
44
+ * (`op: "terminal"`, `{step, args}`); the line handler (`../line`) looks the
45
+ * step up here, runs it and answers. Nothing here runs at a client's call, and
46
+ * nothing here decides anything: which program, which file and when are the
47
+ * server's, sent in `args`.
48
+ *
49
+ * The helper runs inside the tool's own process, so a program ordered with
50
+ * `stdio: "inherit"` (an editor, an update) draws in the person's terminal.
51
+ */
52
+ const cp = __importStar(require("node:child_process"));
53
+ const fs = __importStar(require("node:fs"));
54
+ const os = __importStar(require("node:os"));
55
+ const path = __importStar(require("node:path"));
56
+ const clipboard_1 = require("./clipboard");
57
+ const project_1 = require("../folder/project");
58
+ const sandbox_1 = require("../executor/sandbox");
59
+ const build_1 = require("../codemap/build");
60
+ const needs_1 = require("../runtime/needs");
61
+ const voice_1 = require("./voice");
62
+ const files_1 = require("../executor/files");
63
+ const hooks_1 = require("../executor/hooks");
64
+ const toolservers_1 = require("../executor/toolservers");
65
+ const jobs_1 = require("./jobs");
66
+ const shell_1 = require("../executor/shell");
67
+ const self_1 = require("../runtime/self");
68
+ const home_1 = require("../runtime/home");
69
+ const str = (v) => (typeof v === 'string' ? v : '');
70
+ const list = (v) => (Array.isArray(v) ? v.map(String) : []);
71
+ const env = (v) => v && typeof v === 'object' ? { ...process.env, ...v } : undefined;
72
+ /** `~` and the tool's own home folder (`@home`), written by the server as markers. */
73
+ function where(v) {
74
+ const p = str(v);
75
+ if (p === '~' || p.startsWith('~/'))
76
+ return path.join(os.homedir(), p.slice(1));
77
+ if (p === '@home' || p.startsWith('@home/'))
78
+ return path.join((0, home_1.homeDir)(), p.slice(5));
79
+ return p;
80
+ }
81
+ function stdio(v) {
82
+ return v === 'inherit' || v === 'ignore' ? v : 'pipe';
83
+ }
84
+ /** Start a program, its output to a log file when named; returns its process. */
85
+ function launch(program, argv, a) {
86
+ const log = a.log ? fs.openSync(where(a.log), 'a') : null;
87
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- the server's ordered program, every value its own argument
88
+ const child = cp.spawn(program, argv, {
89
+ cwd: a.cwd ? where(a.cwd) : undefined, env: env(a.env), detached: Boolean(a.detached),
90
+ stdio: log !== null ? ['ignore', log, log] : stdio(a.stdio ?? 'ignore'),
91
+ });
92
+ if (a.pid_file && child.pid)
93
+ fs.writeFileSync(where(a.pid_file), String(child.pid));
94
+ return child;
95
+ }
96
+ function waitFor(child) {
97
+ return new Promise((resolve) => {
98
+ child.on('exit', (status, signal) => resolve({ status, signal }));
99
+ child.on('error', () => resolve({ status: 1, signal: null }));
100
+ });
101
+ }
102
+ exports.STEPS = {
103
+ // ── programs ──────────────────────────────────────────────────────────────
104
+ /** Run a program to the end: `{program, args, cwd, env, stdio, timeout, shell, input}`. */
105
+ run: (a) => {
106
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- the server's ordered program, every value its own argument
107
+ const r = cp.spawnSync(str(a.program), list(a.args), {
108
+ cwd: a.cwd ? where(a.cwd) : undefined, env: env(a.env), encoding: 'utf8', stdio: stdio(a.stdio),
109
+ timeout: typeof a.timeout === 'number' ? a.timeout : undefined, shell: Boolean(a.shell),
110
+ input: typeof a.input === 'string' ? a.input : undefined, maxBuffer: 64 * 1024 * 1024,
111
+ });
112
+ return { status: r.error ? null : r.status, signal: r.signal, stdout: r.stdout ?? '', stderr: r.stderr ?? '',
113
+ missing: r.error?.code === 'ENOENT',
114
+ error: r.error ? String(r.error.message) : null };
115
+ },
116
+ /** Start a program and leave it running: `{program, args, cwd, env, detached, log, pid_file}`. */
117
+ start: (a) => {
118
+ const child = launch(str(a.program), list(a.args), a);
119
+ child.on('error', () => undefined);
120
+ if (a.detached)
121
+ child.unref();
122
+ return { pid: child.pid ?? null };
123
+ },
124
+ /** Start this tool once more and leave it running: `{args, node_flags, env, detached, log, pid_file}`. */
125
+ start_self: (a) => {
126
+ const [program, argv] = (0, self_1.selfLaunch)(list(a.args), list(a.node_flags));
127
+ const child = launch(program, argv, a);
128
+ child.on('error', () => undefined);
129
+ if (a.detached)
130
+ child.unref();
131
+ return { pid: child.pid ?? null };
132
+ },
133
+ /** Run this tool once more and wait for it: `{args, node_flags, env, stdio}`. */
134
+ run_self: async (a) => {
135
+ const [program, argv] = (0, self_1.selfLaunch)(list(a.args), list(a.node_flags));
136
+ return waitFor(launch(program, argv, { ...a, stdio: a.stdio ?? 'inherit' }));
137
+ },
138
+ /** Stop a process this tool started: `{pid}`. */
139
+ stop_process: (a) => {
140
+ try {
141
+ process.kill(Number(a.pid));
142
+ return { stopped: true };
143
+ }
144
+ catch {
145
+ return { stopped: false };
146
+ }
147
+ },
148
+ /** How this copy of the tool was installed, and where things are on this computer. */
149
+ self: () => ({ standalone: (0, self_1.isStandalone)(), method: (0, self_1.installMethod)(), pid: process.pid,
150
+ platform: process.platform, home: (0, home_1.homeDir)(), user_home: os.homedir(), tmp: os.tmpdir() }),
151
+ // ── files ─────────────────────────────────────────────────────────────────
152
+ /** Write a file: `{path, text | base64, mode}`. */
153
+ write_file: (a) => {
154
+ const data = typeof a.base64 === 'string' ? Buffer.from(a.base64, 'base64') : str(a.text);
155
+ fs.writeFileSync(where(a.path), data, typeof a.mode === 'number' ? { mode: a.mode } : undefined);
156
+ if (typeof a.mode === 'number') {
157
+ try {
158
+ fs.chmodSync(where(a.path), a.mode);
159
+ }
160
+ catch { /* no modes here */ }
161
+ }
162
+ return { path: where(a.path) };
163
+ },
164
+ append_file: (a) => { fs.appendFileSync(where(a.path), str(a.text)); return { path: where(a.path) }; },
165
+ copy_file: (a) => { fs.copyFileSync(where(a.from), where(a.to)); return { path: where(a.to) }; },
166
+ rename: (a) => { fs.renameSync(where(a.from), where(a.to)); return { path: where(a.to) }; },
167
+ /** Remove a file or a folder and what is in it; nothing when it is gone. */
168
+ remove: (a) => {
169
+ fs.rmSync(where(a.path), { recursive: a.recursive !== false, force: a.force !== false });
170
+ return { removed: true };
171
+ },
172
+ /** Make a folder: `{path, mode, new}`; `new` refuses one already there. */
173
+ make_dir: (a) => {
174
+ if (a.new)
175
+ fs.mkdirSync(where(a.path));
176
+ else
177
+ fs.mkdirSync(where(a.path), { recursive: true, ...(typeof a.mode === 'number' ? { mode: a.mode } : {}) });
178
+ if (typeof a.mode === 'number') {
179
+ try {
180
+ fs.chmodSync(where(a.path), a.mode);
181
+ }
182
+ catch { /* no modes here */ }
183
+ }
184
+ return { path: where(a.path) };
185
+ },
186
+ /** A fresh scratch folder: in the temporary folder, or beside a full path prefix. */
187
+ scratch_dir: (a) => {
188
+ const prefix = where(a.prefix) || 'comprism-';
189
+ return { path: fs.mkdtempSync(path.isAbsolute(prefix) ? prefix : path.join(os.tmpdir(), prefix)) };
190
+ },
191
+ // ── the project ───────────────────────────────────────────────────────────
192
+ /** The project a folder belongs to: `{start, added}`. */
193
+ project_facts: (a) => (0, project_1.resolveProject)(where(a.start), list(a.added).map(where)),
194
+ /** A folder the person named, or the reason it cannot be used: `{path}`. */
195
+ check_folder: (a) => (0, project_1.checkFolder)(str(a.path)),
196
+ /** The code map: which files the project has and their stamps: `{root}`. */
197
+ codemap_state: (a) => (0, build_1.projectState)(where(a.root)),
198
+ /** The code map: the facts of these files: `{root, rels, known}`. */
199
+ codemap_read: (a) => (0, build_1.readFacts)(where(a.root), Array.isArray(a.rels) ? list(a.rels) : undefined, Array.isArray(a.known) ? list(a.known) : undefined),
200
+ /** The code map: which languages this computer can read. */
201
+ codemap_readers: () => (0, build_1.readers)(),
202
+ /** A coding job: turn its sandbox on: `{job, root, added, allow}`. */
203
+ job_sandbox: (a) => (0, jobs_1.jobSandbox)(str(a.job), where(a.root), list(a.added), list(a.allow)),
204
+ /** A coding job: stop what runs in the foreground. */
205
+ job_stop_foreground: () => (0, jobs_1.jobStopForeground)(),
206
+ /** A coding job: end it: `{job, keep_processes}`. */
207
+ job_close: (a) => (0, jobs_1.jobClose)(str(a.job), Boolean(a.keep_processes)),
208
+ /** A headless job: keep commands' output off the screen. */
209
+ job_quiet: () => { (0, jobs_1.quietOutput)(); return { quiet: true }; },
210
+ /** The processes the tool started that are still running. */
211
+ processes: () => ({ processes: (0, shell_1.listProcesses)() }),
212
+ /** Stop one of them: `{id}`. */
213
+ process_stop: (a) => (0, shell_1.stopProcess)(str(a.id)),
214
+ /** Stop every process the tool started; what was stopped. */
215
+ stop_all: () => ({ stopped: (0, shell_1.stopEverything)() }),
216
+ /** A command's kept output: `{n}`. */
217
+ process_output: (a) => (0, shell_1.keptOutput)(Number(a.n)) ?? null,
218
+ /** What the work may need installed here, and the command to add it. */
219
+ requirements: () => ({ readiness: (0, needs_1.check)(), pdf: (needs_1.REQUIREMENTS[1]?.anyOf ?? []).some(needs_1.present),
220
+ pdf_without: needs_1.REQUIREMENTS[1]?.without ?? '',
221
+ how_to: { git: (0, needs_1.howToInstall)(['git']), ripgrep: (0, needs_1.howToInstall)(['ripgrep']), pdftotext: (0, needs_1.howToInstall)(['pdftotext']) } }),
222
+ /** A program's version, or null when it is not installed: `{program, args}`. */
223
+ program_version: (a) => {
224
+ try {
225
+ const text = cp.execFileSync(str(a.program), list(a.args), { stdio: ['ignore', 'pipe', 'ignore'] }).toString();
226
+ return { version: text.match(/\d+\.\d+(\.\d+)?/)?.[0] ?? '' };
227
+ }
228
+ catch {
229
+ return { version: null };
230
+ }
231
+ },
232
+ /** Live words from the microphone: `{server, key}`, then state and stop by `{id}`. */
233
+ voice_live_start: (a) => (0, voice_1.liveStart)(str(a.server), str(a.key), str(a.listen ?? '')),
234
+ voice_live_state: (a) => (0, voice_1.liveState)(str(a.id)),
235
+ voice_live_stop: (a) => (0, voice_1.liveStop)(str(a.id)),
236
+ /** A plain recording: why it cannot work, start, stop by `{id}`, delete by `{file}`. */
237
+ voice_missing: () => (0, voice_1.recordMissing)(),
238
+ voice_start: () => (0, voice_1.recordStart)(),
239
+ voice_stop: (a) => (0, voice_1.recordStop)(str(a.id)),
240
+ voice_discard: (a) => (0, voice_1.recordDiscard)(where(a.file)),
241
+ /** One of the executor's own checked file actions in a project: `{root, name, input}`. */
242
+ file_action: (a) => {
243
+ const r = (0, files_1.performFileAction)(where(a.root), str(a.name), (a.input ?? {}));
244
+ return { content: r.content, is_error: Boolean(r.isError) };
245
+ },
246
+ /** The project's settings files that may hold hooks: `{root}`. */
247
+ hook_files: (a) => ({ files: (0, hooks_1.hookFiles)(where(a.root)), inside: (0, hooks_1.insideHook)() }),
248
+ /** Run the hooks the server chose, and report: `{root, hooks, when, action, args}`. */
249
+ hooks_run: async (a) => {
250
+ if ((0, hooks_1.insideHook)())
251
+ return { inside: true, lines: [], refused: false, detail: '', failed: 0 };
252
+ const done = await (0, hooks_1.runHooks)(where(a.root), (a.hooks ?? []), {
253
+ when: str(a.when), action: str(a.action) || undefined, args: (a.args ?? {})
254
+ });
255
+ return { inside: false, lines: (0, hooks_1.reportLines)(done), refused: Boolean(done.refusedBy), detail: done.detail ?? '',
256
+ failed: done.failed.length };
257
+ },
258
+ /** Ask local tool servers which tools they offer: `{root, servers: [{name, command}]}`. */
259
+ tool_servers_list: async (a) => {
260
+ const servers = new toolservers_1.ToolServers(where(a.root));
261
+ const results = {};
262
+ try {
263
+ for (const p of (a.servers ?? [])) {
264
+ const r = await servers.list(p.name, p.command);
265
+ results[p.name] = r.isError ? { error: r.content } : JSON.parse(r.content);
266
+ }
267
+ }
268
+ finally {
269
+ servers.stopAll();
270
+ }
271
+ return { results };
272
+ },
273
+ /** Whether jobs can run in the system sandbox here. */
274
+ sandbox_available: () => (0, sandbox_1.availability)(),
275
+ // ── the desktop ───────────────────────────────────────────────────────────
276
+ /** Save the clipboard's picture to a new temporary folder: `{n}`. */
277
+ clipboard_image: (a) => (0, clipboard_1.readClipboardImage)(Number(a.n) || 1),
278
+ /** Remove a paste's temporary folder. */
279
+ clipboard_discard: (a) => { (0, clipboard_1.discard)(where(a.folder)); return { removed: true }; },
280
+ /** Is a program on this computer's path: `{name}`. */
281
+ has_program: (a) => {
282
+ const r = cp.spawnSync(process.platform === 'win32' ? 'where' : 'which', [str(a.name)], { stdio: 'ignore' });
283
+ return { present: r.status === 0 };
284
+ },
285
+ /** Show a desktop notice: `{message}`. */
286
+ notify: (a) => {
287
+ const args = process.platform === 'darwin'
288
+ ? ['-e', `display notification ${JSON.stringify(str(a.message))} with title "comprism"`]
289
+ : ['comprism', str(a.message)];
290
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- a fixed program, the message one argument
291
+ cp.spawn(process.platform === 'darwin' ? 'osascript' : 'notify-send', args, { stdio: 'ignore', detached: true }).on('error', () => undefined).unref();
292
+ return { shown: true };
293
+ },
294
+ /** Open a web address in the person's browser: `{url}`. */
295
+ open_address: (a) => {
296
+ if (process.env.COMPRISM_NO_BROWSER === '1')
297
+ return { opened: false };
298
+ const url = str(a.url);
299
+ const [cmd, argv] = process.platform === 'darwin' ? ['open', [url]]
300
+ : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : ['xdg-open', [url]];
301
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process -- the address is one argument, never a shell string
302
+ cp.spawn(cmd, argv, { stdio: 'ignore', detached: true }).on('error', () => undefined).unref();
303
+ return { opened: true };
304
+ },
305
+ /** The operating system's name and version, as a person reads it. */
306
+ system_name: () => {
307
+ try {
308
+ if (process.platform === 'darwin') {
309
+ const v = cp.execFileSync('sw_vers', ['-productVersion'], { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
310
+ return { name: `macOS ${v} ${os.arch()}` };
311
+ }
312
+ if (process.platform === 'linux') {
313
+ const m = fs.readFileSync('/etc/os-release', 'utf8').match(/^PRETTY_NAME="?([^"\n]+)"?/m);
314
+ return { name: `${m ? m[1] : 'Linux'} ${os.arch()}` };
315
+ }
316
+ if (process.platform === 'win32')
317
+ return { name: `${os.version()} ${os.arch()}` };
318
+ }
319
+ catch { /* the plain name below */ }
320
+ return { name: `${os.type()} ${os.release()} ${os.arch()}` };
321
+ },
322
+ // ── reading, on the server's order (device service, `prism_device/read`) ──
323
+ /** Read one file or folder the server named and checked:
324
+ * `{path, as: text|bytes|names|entries|exists|tree|count|folder, limits}`.
325
+ * Answers `{found, ...}`; a missing place is `{found: false}`, never an error. */
326
+ read: (a) => readPlace(where(a.path), str(a.as) || 'text', (a.limits ?? {})),
327
+ };
328
+ /** The folders a listing of a whole project never walks into. */
329
+ const NOT_WALKED = new Set(['node_modules', '.git', 'dist', 'build', 'out', '__pycache__', '.venv', 'venv']);
330
+ function readPlace(p, as, limits) {
331
+ let st;
332
+ try {
333
+ st = fs.statSync(p);
334
+ }
335
+ catch {
336
+ return { found: false };
337
+ }
338
+ const folder = st.isDirectory();
339
+ if (as === 'exists')
340
+ return { found: true, folder };
341
+ if (as === 'text')
342
+ return folder ? { found: false } : { found: true, text: fs.readFileSync(p, 'utf8') };
343
+ if (as === 'bytes')
344
+ return folder ? { found: false } : { found: true, bytes: fs.readFileSync(p).toString('base64') };
345
+ if (!folder)
346
+ return { found: false };
347
+ if (as === 'names')
348
+ return { found: true, names: fs.readdirSync(p) };
349
+ if (as === 'entries') {
350
+ return { found: true, entries: fs.readdirSync(p, { withFileTypes: true }).map((e) => ({
351
+ name: e.name, kind: e.isDirectory() ? 'folder' : e.isFile() ? 'file' : 'other'
352
+ })) };
353
+ }
354
+ if (as === 'tree') {
355
+ // Every file below, relative and `/` separated, bounded so Tab stays quick.
356
+ const names = [];
357
+ const walk = (dir) => {
358
+ if (names.length >= 5000)
359
+ return;
360
+ let entries;
361
+ try {
362
+ entries = fs.readdirSync(dir, { withFileTypes: true });
363
+ }
364
+ catch {
365
+ return;
366
+ }
367
+ for (const e of entries) {
368
+ if (names.length >= 5000)
369
+ return;
370
+ if (e.isDirectory()) {
371
+ if (!e.name.startsWith('.') && !NOT_WALKED.has(e.name))
372
+ walk(path.join(dir, e.name));
373
+ }
374
+ else if (e.isFile())
375
+ names.push(path.relative(p, path.join(dir, e.name)).split(path.sep).join('/'));
376
+ }
377
+ };
378
+ walk(p);
379
+ return { found: true, names };
380
+ }
381
+ if (as === 'count') {
382
+ // Folders and files below, hidden ones and installed packages skipped, to a ceiling.
383
+ const count = { folders: 0, files: 0, more: false };
384
+ const stack = [p];
385
+ while (stack.length) {
386
+ if (count.folders + count.files >= 50000) {
387
+ count.more = true;
388
+ break;
389
+ }
390
+ const dir = stack.pop();
391
+ let entries;
392
+ try {
393
+ entries = fs.readdirSync(dir, { withFileTypes: true });
394
+ }
395
+ catch {
396
+ continue;
397
+ }
398
+ for (const e of entries) {
399
+ if (e.name.startsWith('.') || e.name === 'node_modules')
400
+ continue;
401
+ if (e.isDirectory()) {
402
+ count.folders += 1;
403
+ stack.push(path.join(dir, e.name));
404
+ }
405
+ else if (e.isFile())
406
+ count.files += 1;
407
+ }
408
+ }
409
+ return { found: true, count };
410
+ }
411
+ if (as === 'folder') {
412
+ // Every text file inside, by path, within the limits the server set.
413
+ const files = {};
414
+ const max = limits.max_files ?? 200;
415
+ const skip = new Set(limits.skip ?? []);
416
+ const walk = (dir, rel, depth) => {
417
+ let entries;
418
+ try {
419
+ entries = fs.readdirSync(dir, { withFileTypes: true });
420
+ }
421
+ catch {
422
+ return;
423
+ }
424
+ for (const e of entries) {
425
+ if (Object.keys(files).length >= max)
426
+ return;
427
+ if (skip.has(e.name) || (limits.skip_hidden && e.name.startsWith('.')))
428
+ continue;
429
+ const full = path.join(dir, e.name);
430
+ const inside = rel ? `${rel}/${e.name}` : e.name;
431
+ if (e.isDirectory()) {
432
+ const limit = limits.depth ?? -1;
433
+ if (limit < 0 || depth < limit)
434
+ walk(full, inside, depth + 1);
435
+ continue;
436
+ }
437
+ if (!e.isFile())
438
+ continue;
439
+ try {
440
+ if (fs.statSync(full).size > (limits.max_bytes ?? 50_000))
441
+ continue;
442
+ const text = fs.readFileSync(full, 'utf8');
443
+ if (!text.includes('\u0000'))
444
+ files[inside] = text;
445
+ }
446
+ catch { /* unreadable: left out */ }
447
+ }
448
+ };
449
+ walk(p, '', 0);
450
+ return { found: true, files };
451
+ }
452
+ throw new Error(`${as} is not a way this computer reads a place.`);
453
+ }
454
+ /** Run one ordered step. */
455
+ async function runStep(step, args) {
456
+ const fn = Object.prototype.hasOwnProperty.call(exports.STEPS, step) ? exports.STEPS[step] : undefined;
457
+ if (!fn)
458
+ throw new Error(`${step} is not on this computer's list.`);
459
+ return fn(args ?? {});
460
+ }