@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
@@ -51,10 +51,10 @@ const child_process_1 = require("child_process");
51
51
  const fs = __importStar(require("fs"));
52
52
  const os = __importStar(require("os"));
53
53
  const path = __importStar(require("path"));
54
- const self_1 = require("../lib/self");
54
+ const self_1 = require("../runtime/self");
55
55
  /** The reader script, beside the built code in both a checkout and an install. */
56
56
  function scriptPath() {
57
- return (0, self_1.shippedFile)("read_python.py", path.resolve(__dirname, "..", "..", "scripts", "read_python.py"));
57
+ return (0, self_1.shippedFile)("read_python.py", path.resolve(__dirname, "..", "..", "..", "scripts", "read_python.py"));
58
58
  }
59
59
  let interpreter;
60
60
  /** Which Python this machine has, or null. Asked once per process. */
@@ -47,7 +47,7 @@ const fs = __importStar(require("fs"));
47
47
  const path = __importStar(require("path"));
48
48
  const paths_1 = require("./paths");
49
49
  const shell_1 = require("./shell");
50
- const self_1 = require("../lib/self");
50
+ const self_1 = require("../runtime/self");
51
51
  /** A program from the project's own node_modules, walking up, then the PATH. */
52
52
  function findTool(root, name) {
53
53
  const exts = process.platform === "win32" ? [".cmd", ".exe", ""] : [""];
@@ -109,7 +109,7 @@ async function runHooks(root, hooks, ctx) {
109
109
  root,
110
110
  timeoutMs: secs * 1000,
111
111
  input,
112
- label: `hook: ${hook.command}`,
112
+ label: `hook: ${hook.command}`, // client-strings-allowed: the hook's own command, shown verbatim in the job log
113
113
  extraEnv: {
114
114
  [exports.IN_HOOK]: "1",
115
115
  COMPRISM_WHEN: ctx.when,
@@ -62,7 +62,7 @@ const fs = __importStar(require("fs"));
62
62
  const http = __importStar(require("http"));
63
63
  const net = __importStar(require("net"));
64
64
  const os = __importStar(require("os"));
65
- const self_1 = require("../lib/self");
65
+ const self_1 = require("../runtime/self");
66
66
  /** Which sandbox this machine offers, or why none. */
67
67
  function availability() {
68
68
  const has = (file, args) => {
@@ -0,0 +1,339 @@
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.connectedFolders = connectedFolders;
37
+ exports.currentFolder = currentFolder;
38
+ exports.perform = perform;
39
+ exports.openLine = openLine;
40
+ /**
41
+ * The line to the server: the machine helper every installed client opens
42
+ * while it runs (Work module build spec, section 2, "The line to the computer").
43
+ *
44
+ * The client opens one WebSocket to `/api/v1/front-door/prism_machine` with its sign
45
+ * in, this computer's name and its client kind. The server sends orders
46
+ * `{id, op, args}`; this answers `{id, ok, result}` or `{id, ok:false, error}`.
47
+ *
48
+ * It does only what it is ordered, and only inside folders the person
49
+ * connected. Which folders those are is the server's answer (this computer's
50
+ * source in `workspaces/list`), asked again for every order; nothing is
51
+ * kept here. It decides nothing else: no list of workspaces, no current one.
52
+ *
53
+ * Shared by the terminal and the VS Code extension, which loads the compiled
54
+ * copy, so there is one helper and not two.
55
+ */
56
+ const fs = __importStar(require("node:fs"));
57
+ const os = __importStar(require("node:os"));
58
+ const path = __importStar(require("node:path"));
59
+ const index_1 = require("../executor/index");
60
+ const steps_1 = require("../terminal/steps");
61
+ const jobs_1 = require("../terminal/jobs");
62
+ function headers(opts, token) {
63
+ const h = {
64
+ 'content-type': 'application/json', authorization: `Bearer ${token}`, 'X-Comprism-Client': opts.client,
65
+ };
66
+ if (opts.tenant)
67
+ h['X-Tenant-ID'] = opts.tenant;
68
+ return h;
69
+ }
70
+ /** The folders the person connected on this computer, from the server. */
71
+ async function connectedFolders(opts) {
72
+ const token = await opts.token();
73
+ if (!token)
74
+ return [];
75
+ const res = await fetch(`${opts.baseUrl.replace(/\/+$/, '')}/api/v1/front-door/workspaces/list`, {
76
+ method: 'POST', headers: headers(opts, token), body: '{}', signal: AbortSignal.timeout(15_000),
77
+ });
78
+ if (!res.ok)
79
+ return [];
80
+ const body = (await res.json());
81
+ const here = os.hostname();
82
+ const out = [];
83
+ for (const s of body.sources ?? []) {
84
+ if (s.kind !== 'computer' || (s.machine && s.machine !== here))
85
+ continue;
86
+ for (const w of s.workspaces ?? []) {
87
+ if (typeof w.path === 'string' && path.isAbsolute(w.path))
88
+ out.push(path.resolve(w.path));
89
+ }
90
+ }
91
+ return out;
92
+ }
93
+ function within(folder, target) {
94
+ const rel = path.relative(folder, target);
95
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
96
+ }
97
+ /** The server's current workspace folder, when it is on this computer: the
98
+ * folder a coding job's file actions work in. */
99
+ async function currentFolder(opts) {
100
+ const token = await opts.token();
101
+ if (!token)
102
+ return null;
103
+ const res = await fetch(`${opts.baseUrl.replace(/\/+$/, '')}/api/v1/front-door/workspaces/list`, {
104
+ method: 'POST', headers: headers(opts, token), body: '{}', signal: AbortSignal.timeout(15_000),
105
+ });
106
+ if (!res.ok)
107
+ return null;
108
+ const c = (await res.json()).current;
109
+ if (!c?.path || !path.isAbsolute(c.path) || (c.machine && c.machine !== os.hostname()))
110
+ return null;
111
+ return path.resolve(c.path);
112
+ }
113
+ const REFUSED = 'Refused: that place is not inside a folder you connected on this computer.';
114
+ /** Carry out one order. Refused unless its place is inside a connected folder;
115
+ * a new workspace's folder (make_dir, ordered as the workspace is created)
116
+ * may also be made anywhere in the person's own home folder. */
117
+ async function perform(order, folders, jobRoot) {
118
+ const args = order.args ?? {};
119
+ if (order.op === 'terminal') {
120
+ // A step of the terminal tool's own on this computer, ordered by the
121
+ // server's computer service: `{step, args}`, run from the fixed list.
122
+ try {
123
+ return { id: order.id, ok: true, result: await (0, steps_1.runStep)(String(args.step ?? ''), (args.args ?? {})) };
124
+ }
125
+ catch (error) {
126
+ return { id: order.id, ok: false, error: String(error.message ?? error) };
127
+ }
128
+ }
129
+ const abs = (v) => (typeof v === 'string' && path.isAbsolute(v) ? path.resolve(v) : null);
130
+ if (order.op === 'tool' && typeof args.job === 'string' && args.job) {
131
+ // A terminal job's action, ordered by the server for the job it opened on
132
+ // this computer, on that job's own executor.
133
+ const root = abs(args.root) ?? jobRoot ?? null;
134
+ if (!root)
135
+ return { id: order.id, ok: false, error: REFUSED };
136
+ try {
137
+ return { id: order.id, ok: true, result: await (0, jobs_1.jobAction)(args.job, root, String(args.name ?? ''), (args.input ?? {}), args.hooks) };
138
+ }
139
+ catch (error) {
140
+ return { id: order.id, ok: true, result: { content: String(error.message ?? error), is_error: true } };
141
+ }
142
+ }
143
+ if (order.op === 'tool') {
144
+ // A coding job's file action: `{name, input}`, run in the current
145
+ // workspace's folder, as the job's own executor runs it.
146
+ const root = abs(args.root) ?? jobRoot ?? null;
147
+ if (!root || !folders.some((f) => within(f, root)))
148
+ return { id: order.id, ok: false, error: REFUSED };
149
+ const engine = new index_1.NativeExecutor({ root });
150
+ try {
151
+ const done = await engine.execute(String(args.name ?? ''), (args.input ?? {}));
152
+ return { id: order.id, ok: true, result: { content: done.content, is_error: Boolean(done.isError),
153
+ summary: done.summary ?? null, facts: done.facts ?? null } };
154
+ }
155
+ catch (error) {
156
+ return { id: order.id, ok: true, result: { content: String(error.message ?? error), is_error: true } };
157
+ }
158
+ finally {
159
+ engine.close();
160
+ }
161
+ }
162
+ const root = abs(args.root);
163
+ const target = abs(args.path);
164
+ const where = root ?? target;
165
+ const home = where ? folders.find((f) => within(f, where))
166
+ ?? (order.op === 'make_dir' && within(os.homedir(), where) && where !== os.homedir() ? where : undefined) : undefined;
167
+ if (!where || !home)
168
+ return { id: order.id, ok: false, error: REFUSED };
169
+ try {
170
+ if (order.op === 'list_dir') {
171
+ const entries = fs.readdirSync(where, { withFileTypes: true })
172
+ .filter((e) => !e.name.startsWith('.'))
173
+ .map((e) => {
174
+ const folder = e.isDirectory();
175
+ let size;
176
+ if (!folder) {
177
+ try {
178
+ size = fs.statSync(path.join(where, e.name)).size;
179
+ }
180
+ catch { /* gone since listed */ }
181
+ }
182
+ return { name: e.name, kind: folder ? 'folder' : 'file', ...(size !== undefined ? { size } : {}) };
183
+ })
184
+ .sort((a, b) => (a.kind === b.kind ? a.name.localeCompare(b.name) : a.kind === 'folder' ? -1 : 1));
185
+ return { id: order.id, ok: true, result: { entries } };
186
+ }
187
+ if (order.op === 'make_dir') {
188
+ fs.mkdirSync(where, { recursive: true });
189
+ return { id: order.id, ok: true, result: { path: where } };
190
+ }
191
+ // A coding job's file action, rooted in the folder the server named (or
192
+ // the connected folder holding the path), exactly as a job runs it.
193
+ const { root: _root, ...rest } = args;
194
+ void _root;
195
+ if (!root && target)
196
+ rest.path = path.relative(home, target) || '.';
197
+ const engine = new index_1.NativeExecutor({ root: root ?? home });
198
+ try {
199
+ const done = await engine.execute(order.op, rest);
200
+ return { id: order.id, ok: !done.isError, result: done, ...(done.isError ? { error: String(done.content ?? '') } : {}) };
201
+ }
202
+ finally {
203
+ engine.close();
204
+ }
205
+ }
206
+ catch (error) {
207
+ return { id: order.id, ok: false, error: String(error.message ?? error) };
208
+ }
209
+ }
210
+ /**
211
+ * Open the line and keep it open: reconnect after a drop, with a growing
212
+ * pause, until `stop()`.
213
+ */
214
+ function openLine(opts) {
215
+ const Ctor = globalThis.WebSocket;
216
+ const log = opts.log ?? (() => undefined);
217
+ let sock = null;
218
+ let stopped = false;
219
+ let pause = 1000;
220
+ let timer = null;
221
+ let up = false;
222
+ if (!Ctor) {
223
+ log('The line to the server could not open: this runtime has no WebSocket.');
224
+ return { stop: () => undefined, connected: () => false, ready: async () => false };
225
+ }
226
+ const again = () => {
227
+ if (stopped)
228
+ return;
229
+ timer = setTimeout(() => void connect(), pause);
230
+ timer.unref?.();
231
+ pause = Math.min(pause * 2, 30_000);
232
+ };
233
+ const connect = async () => {
234
+ if (stopped)
235
+ return;
236
+ let token;
237
+ try {
238
+ token = await opts.token();
239
+ }
240
+ catch {
241
+ token = null;
242
+ }
243
+ if (!token) {
244
+ again();
245
+ return;
246
+ }
247
+ const url = new URL(`${opts.baseUrl.replace(/\/+$/, '')}/api/v1/front-door/prism_machine`);
248
+ url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
249
+ url.searchParams.set('machine', os.hostname());
250
+ url.searchParams.set('client', opts.client);
251
+ if (opts.tenant)
252
+ url.searchParams.set('tenant', opts.tenant);
253
+ let s;
254
+ try {
255
+ s = new Ctor(url.toString());
256
+ }
257
+ catch (error) {
258
+ log(`The line to the server could not open: ${String(error.message ?? error)}`);
259
+ again();
260
+ return;
261
+ }
262
+ sock = s;
263
+ s.onopen = () => {
264
+ pause = 1000;
265
+ // The sign in goes in this first message, never in the address, so it
266
+ // is not written to any log of addresses.
267
+ s.send(JSON.stringify({ type: 'hello', token, machine: os.hostname(), client: opts.client,
268
+ capabilities: new index_1.NativeExecutor({ root: os.homedir() }).capabilities }));
269
+ };
270
+ s.onmessage = (e) => void (async () => {
271
+ let msg;
272
+ try {
273
+ msg = JSON.parse(String(e.data));
274
+ }
275
+ catch {
276
+ return;
277
+ }
278
+ if (msg.type === 'ping') {
279
+ s.send(JSON.stringify({ type: 'pong' }));
280
+ return;
281
+ }
282
+ if (msg.type === 'ready') {
283
+ up = true;
284
+ log(`Line to the server open as ${os.hostname()} (${opts.client}).`);
285
+ return;
286
+ }
287
+ if (typeof msg.id !== 'string' || typeof msg.op !== 'string')
288
+ return;
289
+ const order = msg;
290
+ let answer;
291
+ try {
292
+ // A terminal step never reads the folders, and asking costs seconds on
293
+ // every order.
294
+ const forJob = order.op === 'tool' && typeof order.args?.job === 'string' && Boolean(order.args.job);
295
+ const folders = order.op === 'terminal' || forJob ? [] : await connectedFolders(opts);
296
+ // The server names the folder on every job order; ask only when it did not.
297
+ const named = typeof order.args?.root === 'string' && path.isAbsolute(order.args.root);
298
+ answer = await perform(order, folders, order.op === 'tool' && !named ? await currentFolder(opts) : null);
299
+ }
300
+ catch (error) {
301
+ answer = { id: order.id, ok: false, error: String(error.message ?? error) };
302
+ }
303
+ log(`Order ${order.op}: ${answer.ok ? 'done' : `refused, ${answer.error}`}`);
304
+ if (s.readyState === 1)
305
+ s.send(JSON.stringify(answer));
306
+ })();
307
+ s.onerror = () => undefined;
308
+ s.onclose = () => {
309
+ if (up)
310
+ log('Line to the server closed; reconnecting.');
311
+ up = false;
312
+ sock = null;
313
+ again();
314
+ };
315
+ };
316
+ void connect();
317
+ return {
318
+ ready: (ms = 15_000) => new Promise((resolve) => {
319
+ const began = Date.now();
320
+ const look = () => { if (up)
321
+ resolve(true);
322
+ else if (stopped || Date.now() - began > ms)
323
+ resolve(false);
324
+ else
325
+ setTimeout(look, 50); };
326
+ look();
327
+ }),
328
+ stop: () => {
329
+ stopped = true;
330
+ if (timer)
331
+ clearTimeout(timer);
332
+ try {
333
+ sock?.close();
334
+ }
335
+ catch { /* already closed */ }
336
+ },
337
+ connected: () => up,
338
+ };
339
+ }
@@ -33,25 +33,16 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.cmdPrivacy = cmdPrivacy;
36
+ exports.HOME_DIR_NAME = void 0;
37
+ exports.homeDir = homeDir;
37
38
  /**
38
- * `comprism privacy` (manual 2.13): what your company keeps about your work,
39
- * exactly as the service and the portal state it.
39
+ * The tool's own folder on this computer, where it keeps its settings, its
40
+ * copies of shipped files and its programs. One answer for every client that
41
+ * carries the machine services.
40
42
  */
41
- const gateway_1 = require("../lib/gateway");
42
- const ui = __importStar(require("../lib/ui"));
43
- const out = (s = "") => process.stdout.write(s + "\n");
44
- async function cmdPrivacy() {
45
- const reply = await (0, gateway_1.ask)({ intent: "privacy", prompt: "" });
46
- if (!reply.ok || reply.served === false) {
47
- out(ui.fail(reply.served === false
48
- ? "Your organization is running an older build that does not answer this yet."
49
- : `Your organization could not be reached: ${reply.message || "no answer"}`));
50
- return 1;
51
- }
52
- out();
53
- for (const line of reply.lines ?? [])
54
- out(line);
55
- out();
56
- return 0;
43
+ const os = __importStar(require("os"));
44
+ const path = __importStar(require("path"));
45
+ exports.HOME_DIR_NAME = ".comprism";
46
+ function homeDir() {
47
+ return process.env.COMPRISM_HOME || path.join(os.homedir(), exports.HOME_DIR_NAME);
57
48
  }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.REQUIREMENTS = void 0;
7
+ exports.present = present;
8
+ exports.howToInstall = howToInstall;
9
+ exports.check = check;
10
+ /**
11
+ * What the machine services need on a computer before they can do their work:
12
+ * git for the git actions, a PDF reader for PDFs (service catalog, machine
13
+ * services). Kept with the engine, not with one client, because the terminal,
14
+ * VS Code and desktop all carry the same engine. Checked on the computer itself,
15
+ * and at install time, before anyone has signed in.
16
+ */
17
+ const node_child_process_1 = require("node:child_process");
18
+ const node_os_1 = __importDefault(require("node:os"));
19
+ exports.REQUIREMENTS = [
20
+ {
21
+ purpose: 'working with a repository',
22
+ anyOf: ['git'],
23
+ without: 'reading, branching and committing a project',
24
+ essential: false,
25
+ },
26
+ {
27
+ purpose: 'reading a PDF you already have',
28
+ // Three ways to do the same job. The first keeps the layout, the second is
29
+ // close, the third is usually there on any machine with Python at all.
30
+ anyOf: ['pdftotext', 'mutool', 'python3'],
31
+ without: 'reading a specification or a contract that arrived as a PDF',
32
+ essential: false,
33
+ },
34
+ ];
35
+ /** Is this program on the machine, by name, without running anything of theirs. */
36
+ function present(program) {
37
+ try {
38
+ // Windows has no /usr/bin/env, so every program read as missing there.
39
+ if (node_os_1.default.platform() === 'win32')
40
+ (0, node_child_process_1.execFileSync)('where', [program], { stdio: 'ignore' });
41
+ else
42
+ (0, node_child_process_1.execFileSync)('/usr/bin/env', ['which', program], { stdio: 'ignore' });
43
+ return true;
44
+ }
45
+ catch {
46
+ return false;
47
+ }
48
+ }
49
+ /**
50
+ * The one command that installs what is missing, for the machine it is on.
51
+ *
52
+ * Named per platform rather than guessed: telling somebody on Ubuntu to run a
53
+ * Homebrew command is worse than saying nothing, because they now have to work
54
+ * out that the instruction was wrong before they can work out what is right.
55
+ */
56
+ function howToInstall(missing) {
57
+ if (missing.length === 0)
58
+ return '';
59
+ const platform = node_os_1.default.platform();
60
+ const parts = missing.map((m) => (m === 'pdftotext' ? 'poppler' : m));
61
+ if (platform === 'darwin')
62
+ return `brew install ${parts.join(' ')}`;
63
+ if (platform === 'linux') {
64
+ const apt = missing.map((m) => (m === 'pdftotext' ? 'poppler-utils' : m));
65
+ return `sudo apt-get install -y ${apt.join(' ')}`;
66
+ }
67
+ if (platform === 'win32')
68
+ return `winget install ${parts.join(' ')}`;
69
+ return `install: ${parts.join(', ')}`;
70
+ }
71
+ /** What this machine can and cannot do, and how to close the gap. */
72
+ function check() {
73
+ const lines = [];
74
+ const missing = [];
75
+ for (const req of exports.REQUIREMENTS) {
76
+ const found = req.anyOf.find(present);
77
+ if (found) {
78
+ lines.push(` ready ${req.purpose}`);
79
+ }
80
+ else {
81
+ // The FIRST of the alternatives is the one named, because a list of three
82
+ // equivalent programs is a decision nobody wants to make about a thing
83
+ // they did not know they needed.
84
+ missing.push(req.anyOf[0]);
85
+ lines.push(` missing ${req.purpose}, so ${req.without} will not work`);
86
+ }
87
+ }
88
+ return { ready: missing.length === 0, lines, fix: howToInstall(missing) };
89
+ }
@@ -38,6 +38,7 @@ exports.standaloneBinDir = standaloneBinDir;
38
38
  exports.installMethod = installMethod;
39
39
  exports.selfLaunch = selfLaunch;
40
40
  exports.shippedFile = shippedFile;
41
+ exports.relaunchThroughProxy = relaunchThroughProxy;
41
42
  /**
42
43
  * How this copy of the tool was installed, and how it starts another copy of
43
44
  * itself (manual 1.1).
@@ -52,7 +53,7 @@ exports.shippedFile = shippedFile;
52
53
  */
53
54
  const fs = __importStar(require("fs"));
54
55
  const path = __importStar(require("path"));
55
- const config_1 = require("./config");
56
+ const home_1 = require("./home");
56
57
  let sea;
57
58
  /** True when running as the ready to run program rather than under Node. */
58
59
  function isStandalone() {
@@ -69,7 +70,7 @@ function isStandalone() {
69
70
  }
70
71
  /** Where the install script keeps the program: `~/.comprism/bin`. */
71
72
  function standaloneBinDir() {
72
- return path.join((0, config_1.homeDir)(), "bin");
73
+ return path.join((0, home_1.homeDir)(), "bin");
73
74
  }
74
75
  /**
75
76
  * Which of the three install options put this copy here.
@@ -108,7 +109,7 @@ function selfLaunch(args, nodeFlags = []) {
108
109
  function shippedFile(name, packagePath) {
109
110
  if (!isStandalone())
110
111
  return packagePath;
111
- const target = path.join((0, config_1.homeDir)(), "assets", name);
112
+ const target = path.join((0, home_1.homeDir)(), "assets", name);
112
113
  try {
113
114
  // eslint-disable-next-line @typescript-eslint/no-require-imports
114
115
  const text = require("node:sea").getAsset(name, "utf8");
@@ -122,3 +123,24 @@ function shippedFile(name, packagePath) {
122
123
  }
123
124
  return target;
124
125
  }
126
+ /**
127
+ * Behind a company proxy (manual 1.11): Node uses HTTPS_PROXY and NO_PROXY for
128
+ * its own requests only when NODE_USE_ENV_PROXY is set as it starts, so the
129
+ * tool starts itself once more with it set, before the server can be reached
130
+ * at all. Nothing changes without a proxy. True when it ran the second copy.
131
+ */
132
+ function relaunchThroughProxy() {
133
+ const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY || process.env.http_proxy;
134
+ if (!proxy || process.env.NODE_USE_ENV_PROXY)
135
+ return false;
136
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
137
+ const { spawnSync } = require("child_process");
138
+ // Node 22 calls its proxy support experimental and says so on every start;
139
+ // that one notice is not the person's concern.
140
+ const [cmd, argv] = selfLaunch(process.argv.slice(2), ["--disable-warning=UNDICI-EHPA"]);
141
+ const r = spawnSync(cmd, argv, {
142
+ stdio: "inherit", env: { ...process.env, NODE_USE_ENV_PROXY: "1", ...(isStandalone() ? { NODE_NO_WARNINGS: "1" } : {}) },
143
+ });
144
+ process.exitCode = r.status ?? (r.signal === "SIGINT" ? 130 : 1);
145
+ return true;
146
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quietOutput = quietOutput;
4
+ exports.jobExecutor = jobExecutor;
5
+ exports.jobAction = jobAction;
6
+ exports.jobSandbox = jobSandbox;
7
+ exports.jobStopForeground = jobStopForeground;
8
+ exports.jobClose = jobClose;
9
+ /**
10
+ * A terminal coding job's executor on this computer, kept for the whole job.
11
+ *
12
+ * The server orders each of the job's file actions and commands over the
13
+ * machine line (`tool`, naming the job); they run here on one executor per job,
14
+ * so its sandbox and the processes it started last as long as the job does.
15
+ * The helper runs inside the tool's own process, so a command's output is
16
+ * drawn straight in the person's terminal while it runs.
17
+ */
18
+ const index_1 = require("../executor/index");
19
+ const sandbox_1 = require("../executor/sandbox");
20
+ const jobs = new Map();
21
+ /** Show a command's output while it runs, unless the job is headless. */
22
+ let stream = (chunk) => process.stdout.write(chunk);
23
+ function quietOutput() { stream = null; }
24
+ /** The executor for a job, made the first time the server names it. */
25
+ function jobExecutor(job, root, added = []) {
26
+ let found = jobs.get(job);
27
+ if (!found) {
28
+ found = new index_1.NativeExecutor({ root, added, onOutput: (chunk) => stream?.(chunk) });
29
+ jobs.set(job, found);
30
+ }
31
+ return found;
32
+ }
33
+ /** Run one of the job's actions. */
34
+ async function jobAction(job, root, name, input, hooks) {
35
+ const engine = jobExecutor(job, root);
36
+ const done = await engine.execute(name, input, hooks);
37
+ return { content: done.content, is_error: Boolean(done.isError), summary: done.summary ?? null,
38
+ facts: done.facts ?? null, tests_passed: engine.lastTestsPassed ?? null };
39
+ }
40
+ /** Turn the sandbox on for a job, with its allowed addresses. */
41
+ async function jobSandbox(job, root, added, allow) {
42
+ const system = (0, sandbox_1.availability)().system;
43
+ if (!system)
44
+ return { on: false };
45
+ const engine = jobExecutor(job, root, added);
46
+ const box = new sandbox_1.Sandbox(system, root, added);
47
+ box.setAllowed(allow);
48
+ await box.start();
49
+ engine.sandbox = box;
50
+ return { on: true };
51
+ }
52
+ /** Stop what is running in the foreground (Ctrl+C on a job). */
53
+ function jobStopForeground() {
54
+ (0, index_1.stopForeground)();
55
+ return { stopped: true };
56
+ }
57
+ /** End a job: close its executor, and stop its processes unless kept. */
58
+ function jobClose(job, keepProcesses) {
59
+ const engine = jobs.get(job);
60
+ jobs.delete(job);
61
+ const stopped = keepProcesses ? [] : (0, index_1.stopEverything)();
62
+ if (engine) {
63
+ engine.close();
64
+ engine.toolServers.stopAll();
65
+ }
66
+ return { stopped };
67
+ }