@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,226 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.askAt = askAt;
4
- exports.ask = ask;
5
- exports.certificateProblem = certificateProblem;
6
- /**
7
- * The one door, from this side of it.
8
- *
9
- * ── Why this file replaced four others ────────────────────────────────────
10
- *
11
- * This tool used to decide for itself. It carried the whole decision, the
12
- * retry behavior of every model, the cost of a wrong answer and the price
13
- * list, and it worked out the winner on the customer's own laptop.
14
- *
15
- * That is our method, and a package on a public registry is readable by anyone
16
- * who installs it, forever. So none of it lives here any more. The tool sends
17
- * what it is about to do and receives a decision. Everything that makes the
18
- * decision stays on our servers.
19
- *
20
- * The rule, from the owner: anything a client installs is thin; anything
21
- * model-related runs on our server. What is left here is the network call and
22
- * the shape of the reply, which is not a secret and cannot be one.
23
- */
24
- const connection_1 = require("./connection");
25
- const version_1 = require("./version");
26
- /**
27
- * A decision that decides nothing, for when the door cannot be reached.
28
- *
29
- * Fail open, rule 10. The tool must never cost somebody their work because our
30
- * server is slow or down: no model means the caller runs what it was going to
31
- * run, and the reason is recorded rather than hidden.
32
- */
33
- function openFailure(intent, callingModel, why) {
34
- return {
35
- // The intent the caller ASKED for, echoed back. Returning 'decide' for a
36
- // failed catalog call made a caller switching on the intent read the
37
- // placeholder as a real answer to a different question.
38
- intent,
39
- client: 'cli',
40
- decision: {
41
- model: null,
42
- would_have_used: callingModel || '',
43
- tier: 'standard',
44
- signals: [],
45
- confident: false,
46
- rung: null,
47
- rationale: why,
48
- },
49
- answer: null,
50
- receipt: null,
51
- ran_on: null,
52
- cost_usd: null,
53
- would_have_cost_usd: null,
54
- saved_usd: null,
55
- estimated: false,
56
- details_url: null,
57
- providers: [],
58
- stored: false,
59
- signed_out: false,
60
- message: why,
61
- // We never heard back, so we know nothing about what this workspace serves.
62
- // `served` stays true: the failure is `ok: false`, and conflating the two
63
- // would tell a person their workspace is out of date when it is simply
64
- // unreachable.
65
- served: true,
66
- // Nothing in this placeholder was established, because nobody answered.
67
- complete: false,
68
- // Nothing was granted either, and a caller that reads `granted` must not
69
- // see the default of true on a reply that never came from anywhere.
70
- granted: false,
71
- intents: [],
72
- session: null,
73
- job: null,
74
- // The whole reason this field exists. We never heard from the workspace,
75
- // so every field above is this client's placeholder and not something the
76
- // workspace said. A caller that reads an empty `providers` as "you have no
77
- // keys" is the fault that sent somebody with four working keys into a form
78
- // asking them to paste one.
79
- ok: false,
80
- };
81
- }
82
- /**
83
- * The same door, at an address this machine is not signed in to yet.
84
- *
85
- * Signing in is the one thing that cannot present a credential, because it is
86
- * what mints one. So it needs a way to reach the door before a connection file
87
- * exists. Everything else about the call is identical, which is the point: one
88
- * door, and the credential is a header on it rather than a different address.
89
- */
90
- async function askAt(url, input, tenant) {
91
- return post(url, input, undefined, tenant);
92
- }
93
- async function ask(input) {
94
- const conn = (0, connection_1.readConnection)();
95
- if (!conn?.url || !conn.workspaceKey) {
96
- return openFailure(input.intent, input.callingModel, 'this machine is not signed in');
97
- }
98
- return post(conn.url, input, conn.workspaceKey, conn.tenant);
99
- }
100
- async function post(url, input, credential, tenant) {
101
- const conn = { url, workspaceKey: credential, tenant };
102
- const headers = { 'content-type': 'application/json' };
103
- // No credential on a sign in, because signing in is what mints one. Sending
104
- // `Bearer undefined` made the door reject the request before it could reach
105
- // the handler that does not need one.
106
- if (conn.workspaceKey)
107
- headers.authorization = `Bearer ${conn.workspaceKey}`;
108
- if (conn.tenant)
109
- headers['X-Tenant-ID'] = conn.tenant;
110
- // Which tool is asking, so the service can say when a feature needs a newer
111
- // one (manual 1.7). It decides; this only says what it is.
112
- headers['X-Comprism-Version'] = version_1.COMPRISM_VERSION;
113
- // Forwarded, never written to disk: the customer's money stays the
114
- // customer's, and we hold no secret of theirs on their behalf.
115
- if (input.providerKey)
116
- headers['X-Anthropic-Key'] = input.providerKey;
117
- try {
118
- const res = await fetch(`${conn.url.replace(/\/+$/, '')}/api/v1/dev/gateway`, {
119
- method: 'POST',
120
- headers,
121
- // Never waits forever. A service that restarts mid request, or a network
122
- // that goes quiet, answers as unreachable (Appendix B, 6) rather than
123
- // leaving the terminal hanging. Longer for a question a model answers.
124
- signal: AbortSignal.timeout(['answer', 'decide', 'compact', 'transcribe'].includes(input.intent)
125
- ? 300_000 : 120_000),
126
- body: JSON.stringify({
127
- intent: input.intent,
128
- client: 'cli',
129
- prompt: input.prompt,
130
- calling_model: input.callingModel ?? null,
131
- context_tokens: input.contextTokens ?? 0,
132
- fresh_context: input.freshContext ?? true,
133
- tokens_in: input.tokensIn ?? null,
134
- tokens_out: input.tokensOut ?? null,
135
- ...(input.provider ? { provider: input.provider } : {}),
136
- ...(input.key ? { key: input.key } : {}),
137
- ...(input.resumeJobId ? { resume_job_id: input.resumeJobId } : {}),
138
- ...(input.password ? { password: input.password } : {}),
139
- ...(input.challenge ? { challenge: input.challenge } : {}),
140
- ...(input.code ? { code: input.code } : {}),
141
- ...(input.deviceToken ? { device_token: input.deviceToken } : {}),
142
- ...(input.machineLabel ? { machine_label: input.machineLabel } : {}),
143
- ...(input.spendSession ? { spend_session: input.spendSession } : {}),
144
- ...(input.project ? { project: input.project } : {}),
145
- ...(input.op ? { op: input.op } : {}),
146
- ...(input.payload ? { payload: input.payload } : {}),
147
- ...(input.commandsPayload ? { commands_payload: input.commandsPayload } : {}),
148
- ...(input.sessionsPayload ? { sessions_payload: input.sessionsPayload } : {}),
149
- ...(input.jobsPayload ? { jobs_payload: input.jobsPayload } : {}),
150
- ...(input.agentsPayload ? { agents_payload: input.agentsPayload } : {}),
151
- ...(input.tzMinutes !== undefined ? { tz_minutes: input.tzMinutes } : {}),
152
- ...(input.skillsPayload ? { skills_payload: input.skillsPayload } : {}),
153
- ...(input.integrationsPayload ? { integrations_payload: input.integrationsPayload } : {}),
154
- ...(input.pluginsPayload ? { plugins_payload: input.pluginsPayload } : {}),
155
- ...(input.permissionsPayload ? { permissions_payload: input.permissionsPayload } : {}),
156
- ...(input.jobId ? { job_id: input.jobId } : {}),
157
- ...(input.graphOp ? { graph_op: input.graphOp } : {}),
158
- ...(input.workspace ? { workspace: input.workspace } : {}),
159
- ...(input.graphPayload ? { graph_payload: input.graphPayload } : {}),
160
- ...(input.attachment ? { attachment: input.attachment } : {}),
161
- ...(input.attachments?.length ? { attachments: input.attachments } : {}),
162
- }),
163
- });
164
- if (!res.ok) {
165
- // The workspace's OWN words, when it gave any. A bare status number told
166
- // a person nothing: "403" was really "this product is for organization
167
- // workspaces and yours is an individual account", which is actionable,
168
- // and the number was not. An auth failure carries no body here, so
169
- // nothing echoes a credential back.
170
- let why = `the service answered ${res.status}`;
171
- try {
172
- const body = (await res.json());
173
- if (body.detail?.message)
174
- why = body.detail.message;
175
- }
176
- catch { /* no body, so the status stays the reason */ }
177
- const failed = openFailure(input.intent, input.callingModel, why);
178
- // 422 IS AN OLD WORKSPACE, NOT A BROKEN ONE.
179
- //
180
- // A build that predates the intent list rejects an unknown intent with a
181
- // validation error before its handler runs. Reported as an ordinary
182
- // failure, that stopped a coding job against a workspace whose own
183
- // credential path was alive and would have worked. Newer builds answer
184
- // 200 with `served: false` and never reach this line.
185
- if (res.status === 422)
186
- return { ...failed, served: false, httpStatus: res.status };
187
- return { ...failed, httpStatus: res.status };
188
- }
189
- // `ok` is this client's own marker and the server never sends it: it
190
- // records that the workspace answered at all. Set here, on the one path
191
- // where that is true, so no caller has to infer it from an empty field.
192
- const reply = (await res.json());
193
- if (reply.reason === 'upgrade') {
194
- // Said before any work starts or anything is charged, and the number is
195
- // Appendix B's 10 (manual 1.7).
196
- process.stderr.write(` ${String(reply.message || 'This needs a newer comprism. Run comprism update.').split('\n').join('\n ')}\n`);
197
- process.exit(10);
198
- }
199
- return { ...reply, ok: true };
200
- }
201
- catch (e) {
202
- // A certificate problem is said as one, with the setting to change, never
203
- // as "could not be reached" (manual 1.11).
204
- return openFailure(input.intent, input.callingModel, certificateProblem(e) ?? 'the service could not be reached');
205
- }
206
- }
207
- /** The certificate codes Node reports when a company's own authority is not
208
- * trusted, or a certificate is wrong (manual 1.11). */
209
- const CERT_CODES = new Set(["UNABLE_TO_VERIFY_LEAF_SIGNATURE", "SELF_SIGNED_CERT_IN_CHAIN",
210
- "DEPTH_ZERO_SELF_SIGNED_CERT", "UNABLE_TO_GET_ISSUER_CERT", "UNABLE_TO_GET_ISSUER_CERT_LOCALLY",
211
- "CERT_HAS_EXPIRED", "ERR_TLS_CERT_ALTNAME_INVALID", "CERT_UNTRUSTED"]);
212
- /** A sentence for a certificate failure, or null when the failure was not one. */
213
- function certificateProblem(e) {
214
- let cause = e;
215
- for (let i = 0; i < 4 && cause; i += 1) {
216
- const code = cause.code;
217
- if (code && CERT_CODES.has(code)) {
218
- const file = process.env.NODE_EXTRA_CA_CERTS;
219
- return `a certificate problem (${code}): the service's certificate is not trusted on this machine. `
220
- + (file ? `NODE_EXTRA_CA_CERTS is ${file}; check it holds your company's certificate authority.`
221
- : "If your company uses its own certificate authority, set NODE_EXTRA_CA_CERTS to its certificate file.");
222
- }
223
- cause = cause.cause;
224
- }
225
- return null;
226
- }
@@ -1,24 +0,0 @@
1
- export declare function historyFile(): string;
2
- export declare class History {
3
- /** Newest first, as shown on the prompt line. Shared with the reader, which
4
- * walks it with Up and Down. */
5
- readonly entries: string[];
6
- /** Newest first, as sent. What the file holds. */
7
- private saved;
8
- /** The company's rule: true keeps, false removes, null (the service could
9
- * not be asked) keeps this session's requests in memory and leaves any
10
- * file exactly as it is. */
11
- private keep;
12
- /** Begin a session under the company's rule. */
13
- start(keep: boolean | null): void;
14
- private off;
15
- /** `history off`: nothing is remembered, in memory or on disk. */
16
- disable(): void;
17
- /** Remember one request. `shown` is how it looked at the prompt, paste
18
- * labels included; `sent` is what was sent. */
19
- add(shown: string, sent: string): void;
20
- /** End the session. Without permission to keep, nothing is left behind. */
21
- finish(): void;
22
- private write;
23
- private remove;
24
- }
@@ -1,137 +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.History = void 0;
37
- exports.historyFile = historyFile;
38
- /**
39
- * Earlier requests, for Up, Down and Ctrl+R (manual 6.5).
40
- *
41
- * Always kept in memory for the session. Kept on this machine between sessions
42
- * only when the service says the company lets prompt text be kept, and then in
43
- * one file, `history` in the tool's own folder, readable by this account only.
44
- * When the company does not, the file is removed at the start and at the end of
45
- * the session, so a rule changed by an administrator is honored by the next
46
- * session without anybody deleting anything by hand.
47
- *
48
- * The decision is the service's (`commands` intent, `keep_history`). This file
49
- * only does what it was told.
50
- */
51
- const fs = __importStar(require("node:fs"));
52
- const path = __importStar(require("node:path"));
53
- const config_1 = require("./config");
54
- const keyboard_1 = require("./keyboard");
55
- /** How many requests are remembered. */
56
- const MAX_ENTRIES = 500;
57
- /** A request longer than this is remembered for the session only. A 1,000
58
- * line paste is not something to replay from a file next week. */
59
- const MAX_SAVED_CHARS = 4000;
60
- function historyFile() {
61
- return path.join((0, config_1.homeDir)(), 'history');
62
- }
63
- class History {
64
- /** Newest first, as shown on the prompt line. Shared with the reader, which
65
- * walks it with Up and Down. */
66
- entries = [];
67
- /** Newest first, as sent. What the file holds. */
68
- saved = [];
69
- /** The company's rule: true keeps, false removes, null (the service could
70
- * not be asked) keeps this session's requests in memory and leaves any
71
- * file exactly as it is. */
72
- keep = null;
73
- /** Begin a session under the company's rule. */
74
- start(keep) {
75
- this.keep = keep;
76
- if (keep === false)
77
- this.remove();
78
- if (keep !== true)
79
- return;
80
- try {
81
- const lines = fs.readFileSync(historyFile(), 'utf8').split('\n').filter(Boolean);
82
- for (const line of lines) {
83
- try {
84
- const text = JSON.parse(line);
85
- if (typeof text === 'string')
86
- this.saved.push(text);
87
- }
88
- catch { /* a damaged line is skipped, not fatal */ }
89
- }
90
- }
91
- catch { /* no file yet */ }
92
- this.saved = this.saved.slice(0, MAX_ENTRIES);
93
- this.entries.splice(0, this.entries.length, ...this.saved.map(keyboard_1.asOneLine));
94
- }
95
- off = false;
96
- /** `history off`: nothing is remembered, in memory or on disk. */
97
- disable() {
98
- this.off = true;
99
- this.entries.splice(0);
100
- }
101
- /** Remember one request. `shown` is how it looked at the prompt, paste
102
- * labels included; `sent` is what was sent. */
103
- add(shown, sent) {
104
- const line = (0, keyboard_1.asOneLine)(shown).trim();
105
- if (!line || this.off)
106
- return;
107
- const at = this.entries.indexOf(line);
108
- if (at !== -1)
109
- this.entries.splice(at, 1);
110
- this.entries.unshift(line);
111
- this.entries.splice(MAX_ENTRIES);
112
- if (this.keep !== true || sent.length > MAX_SAVED_CHARS)
113
- return;
114
- this.saved = [sent, ...this.saved.filter((s) => s !== sent)].slice(0, MAX_ENTRIES);
115
- this.write();
116
- }
117
- /** End the session. Without permission to keep, nothing is left behind. */
118
- finish() {
119
- if (this.keep === false)
120
- this.remove();
121
- }
122
- write() {
123
- try {
124
- fs.mkdirSync((0, config_1.homeDir)(), { recursive: true, mode: 0o700 });
125
- const body = this.saved.map((s) => JSON.stringify(s)).join('\n') + '\n';
126
- fs.writeFileSync(historyFile(), body, { mode: 0o600 });
127
- }
128
- catch { /* a history that could not be written costs typing, nothing more */ }
129
- }
130
- remove() {
131
- try {
132
- fs.rmSync(historyFile(), { force: true });
133
- }
134
- catch { /* already gone */ }
135
- }
136
- }
137
- exports.History = History;
package/out/lib/ide.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export interface EditorLink {
2
- folder: string;
3
- context(): Promise<{
4
- file?: string;
5
- selection?: {
6
- text: string;
7
- from: number;
8
- to: number;
9
- };
10
- problems?: string[];
11
- } | null>;
12
- diff(name: string, input: Record<string, unknown>): Promise<void>;
13
- open(file: string, line?: number): Promise<void>;
14
- }
15
- export declare function lockFolder(): string;
16
- /** The VS Code window whose folder holds `root`, if one is running. */
17
- export declare function findEditor(root: string): EditorLink | null;
18
- /** The selected lines, as the panel sends them (VS Code manual 3.3). */
19
- export declare function selectionText(ctx: Awaited<ReturnType<EditorLink["context"]>>): string;
package/out/lib/ide.js DELETED
@@ -1,131 +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.lockFolder = lockFolder;
37
- exports.findEditor = findEditor;
38
- exports.selectionText = selectionText;
39
- /**
40
- * The terminal tool, joined to a VS Code window (VS Code manual 9.12).
41
- *
42
- * When the CompletionPrism extension is running it leaves a small file in
43
- * `~/.completionprism/ide/` naming a port on this machine and a secret. This
44
- * finds the file for the folder the job is in, and asks that window three
45
- * things: what is open and selected, to show a proposed change in its diff
46
- * view, and to open a file at a line.
47
- *
48
- * It is CompletionPrism's own connection: its own folder, its own secret, only
49
- * this user's files. It never looks for, or speaks to, another tool's editor
50
- * connection.
51
- */
52
- const fs = __importStar(require("fs"));
53
- const os = __importStar(require("os"));
54
- const path = __importStar(require("path"));
55
- function alive(pid) {
56
- try {
57
- process.kill(pid, 0);
58
- return true;
59
- }
60
- catch {
61
- return false;
62
- }
63
- }
64
- function lockFolder() {
65
- return path.join(os.homedir(), ".completionprism", "ide");
66
- }
67
- /** The VS Code window whose folder holds `root`, if one is running. */
68
- function findEditor(root) {
69
- let names = [];
70
- try {
71
- names = fs.readdirSync(lockFolder()).filter((n) => n.endsWith(".json"));
72
- }
73
- catch {
74
- return null;
75
- }
76
- const here = path.resolve(root);
77
- for (const name of names) {
78
- let lock;
79
- try {
80
- lock = JSON.parse(fs.readFileSync(path.join(lockFolder(), name), "utf8"));
81
- }
82
- catch {
83
- continue;
84
- }
85
- if (!lock.port || !lock.token || !alive(lock.pid))
86
- continue;
87
- const folder = lock.folders.find((f) => here === f || here.startsWith(f + path.sep));
88
- if (!folder)
89
- continue;
90
- const call = async (what, body) => {
91
- const res = await fetch(`http://127.0.0.1:${lock.port}/${what}`, {
92
- method: "POST",
93
- headers: { "content-type": "application/json", "x-completionprism-token": lock.token },
94
- body: JSON.stringify(body),
95
- signal: AbortSignal.timeout(2000),
96
- });
97
- return res.ok ? res.json() : null;
98
- };
99
- return {
100
- folder,
101
- context: async () => {
102
- try {
103
- return (await call("context", {}));
104
- }
105
- catch {
106
- return null;
107
- }
108
- },
109
- diff: async (tool, input) => {
110
- try {
111
- await call("diff", { name: tool, input, root: here });
112
- }
113
- catch { /* the terminal still shows it */ }
114
- },
115
- open: async (file, line) => {
116
- try {
117
- await call("open", { path: file, line, root: here });
118
- }
119
- catch { /* nothing to open it in */ }
120
- },
121
- };
122
- }
123
- return null;
124
- }
125
- /** The selected lines, as the panel sends them (VS Code manual 3.3). */
126
- function selectionText(ctx) {
127
- if (!ctx?.selection?.text || !ctx.file)
128
- return "";
129
- const { from, to, text } = ctx.selection;
130
- return `\n\nSelected lines ${from} to ${to} of ${ctx.file}:\n\`\`\`\n${text}\n\`\`\``;
131
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * The keystrokes a session's reader never sees on their own (manual 6.2, 6.3,
3
- * 6.5).
4
- *
5
- * Node's line reader edits one line well and knows nothing about a paste: every
6
- * line break inside a pasted stack trace reached it as Enter, so a 240 line
7
- * paste was sent as 240 requests, each billed. It also has no Alt+Enter and no
8
- * search of earlier requests.
9
- *
10
- * So the session's reader reads from this filter instead of from the keyboard.
11
- * The filter passes ordinary typing straight through and handles four things
12
- * itself:
13
- *
14
- * * A paste, bracketed by the terminal, becomes one piece of the request. The
15
- * reader is given a short label, `[pasted 240 lines]`, that can be edited
16
- * around like any word, and the label is swapped back for the exact text,
17
- * tabs and trailing spaces included, when the request is sent.
18
- * * A terminal that does not bracket pastes still delivers a paste in one read,
19
- * so several lines arriving in one read are treated the same way. A person
20
- * typing never produces a line break followed by more text in one read.
21
- * * Alt+Enter continues the request on a new line, exactly as `\` then Enter.
22
- * * Ctrl+R searches earlier requests; Enter puts the match at the prompt to be
23
- * edited or sent, and Esc or Ctrl+C puts back what was there.
24
- *
25
- * Nothing here is written anywhere. Pieces live in memory for the session.
26
- */
27
- import { PassThrough } from 'node:stream';
28
- import type readline from 'node:readline';
29
- /** Stands for a line break inside a request shown on one line, such as a
30
- * recalled request. Turned back into a line break when it is sent. */
31
- export declare const LINE_BREAK = "\u2424";
32
- /** A request as it is shown on one editable line. */
33
- export declare function asOneLine(text: string): string;
34
- export declare class Keyboard {
35
- private readonly history;
36
- /** What the session's reader reads. */
37
- readonly input: PassThrough;
38
- private readonly decoder;
39
- private pieces;
40
- private pasting;
41
- private carry;
42
- private continued;
43
- private search;
44
- private reader;
45
- private listening;
46
- private readonly onData;
47
- /** Esc on its own (manual 6.7). Returns true when it was used, so the key
48
- * goes no further; false passes it to the reader as before. */
49
- onEscape: (() => boolean) | null;
50
- /** The command list under the prompt (manual 6.4): Up, Down, Enter and Tab
51
- * go to it while it is showing. Returns true when it used the key. */
52
- onMenuKey: ((key: 'up' | 'down' | 'enter' | 'tab') => boolean) | null;
53
- /** Ctrl+O, the short or full view (manual 6.9). */
54
- onFullView: (() => void) | null;
55
- /** Ctrl+G, the request in your own editor (manual 6.6). */
56
- onEditor: (() => void) | null;
57
- /** Ctrl+V, the clipboard's picture, where the terminal passes it (3.4). */
58
- onPasteImage: (() => void) | null;
59
- /** `keys vi` (manual 6.10): Esc at the prompt enters normal mode. */
60
- vi: boolean;
61
- private normal;
62
- private pendingD;
63
- /** `history` is the session's earlier requests, newest first, as shown. */
64
- constructor(history: () => string[]);
65
- /** The reader whose line a search edits. */
66
- bind(reader: readline.Interface | null): void;
67
- /**
68
- * Start reading the keyboard. Raw, because the reader no longer holds the
69
- * keyboard itself and so cannot switch it; bracketed, so the terminal marks
70
- * where a paste begins and ends.
71
- */
72
- attach(): void;
73
- /**
74
- * Stop reading, and give the keyboard back exactly as it was found, for a
75
- * command that asks its own question and for the shell afterwards. A shell
76
- * left with bracketed paste on prints markers around everything pasted.
77
- */
78
- detach(): void;
79
- /** True once after Alt+Enter, so the line just ended continues the request. */
80
- takeContinued(): boolean;
81
- /** The request as it will be sent: every paste label swapped for its text,
82
- * and every shown line break made a real one again. */
83
- expand(text: string): string;
84
- /** Feed raw keyboard text. Public so a test can type without a terminal. */
85
- take(s: string): void;
86
- private forward;
87
- /** Typing, outside a bracketed paste. */
88
- private keys;
89
- private paste;
90
- private viKeys;
91
- private editable;
92
- private startSearch;
93
- private match;
94
- private drawSearch;
95
- private setLine;
96
- private endSearch;
97
- private searchKeys;
98
- }