@illuminis/comprism 0.1.8 → 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 -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
@@ -1,106 +0,0 @@
1
- /** One file that was found, and what the server made of it. */
2
- export interface Attached {
3
- id: string;
4
- filename: string;
5
- /** What the extractor called it: `pdf`, `png`, `text` and so on. */
6
- format: string;
7
- /** Characters of text pulled out. Zero for a picture, which is not a failure. */
8
- chars: number;
9
- /** The text was longer than one turn can carry and was cut. */
10
- truncated: boolean;
11
- isImage: boolean;
12
- /** Bytes on disk, which the job record keeps (manual 3.11). */
13
- sizeBytes: number;
14
- /** What the service says about the file after its name, worded by the
15
- * service so every client shows the same line (manual 3.1 and 3.6). */
16
- summary: string;
17
- }
18
- /** Why one named file was left out, in the service's fixed list (manual 3.10). */
19
- export interface Problem {
20
- code: string;
21
- message: string;
22
- }
23
- /** A path somebody named, before anything has been read. */
24
- export interface Mention {
25
- /** Exactly as it appeared, so it can be taken back out of the sentence. */
26
- raw: string;
27
- /** Resolved and unescaped. */
28
- file: string;
29
- /** As the person wrote it, unescaped, for the messages they read. */
30
- shown: string;
31
- /** Set when the file cannot be attached; nothing is sent for it. */
32
- problem?: Problem;
33
- }
34
- /**
35
- * Take the shell's escaping back off a path.
36
- *
37
- * A dragged file arrives as `/Users/me/My\ Report.pdf`, and a pasted one is
38
- * often in quotes. Both are the shell's way of saying "this is one thing", and
39
- * neither is part of the name.
40
- *
41
- * On Windows a backslash is the folder separator and never an escape: its
42
- * terminals quote a dragged path instead. Stripping backslashes there turned
43
- * `C:\Users\me\notes.txt` into `C:Usersmenotes.txt`, which was the Windows
44
- * failure found in prompt 01.
45
- */
46
- export declare function unescapePath(token: string, platform?: string): string;
47
- /**
48
- * What stops a file being attached, checked on this machine before anything is
49
- * sent (manual 3.10). Only the four facts the service cannot see: whether the
50
- * file is there, is a folder, can be read, or is a link to nothing.
51
- */
52
- export declare function localProblem(file: string, shown: string): Problem | undefined;
53
- /**
54
- * Every file the typed line points at, in the order they were named.
55
- *
56
- * Anything after an `@` is a request to attach, so a problem with it is
57
- * reported. Any other path (absolute, `~/`, `./`, `../`, quoted) that is not a
58
- * readable file is left alone and stays part of the question: somebody writing
59
- * about a path they plan to create, or a folder they want looked at, is doing
60
- * something perfectly ordinary.
61
- */
62
- export declare function mentions(line: string, root: string, here?: string, platform?: string): Mention[];
63
- /** The line begins with an absolute path to something on the disk, as a
64
- * dragged file does, rather than with a slashed command word. */
65
- export declare function startsWithPath(line: string, platform?: string): boolean;
66
- /**
67
- * The question with the long paths taken out and the file names left in.
68
- *
69
- * "summarize @/Users/me/Downloads/Q3 Board Pack.pdf" is a worse question than
70
- * "summarize Q3 Board Pack.pdf", and the second is what the model should be
71
- * reading: the file is already in front of it under that name, so the path adds
72
- * nothing but a place for the model to try to open something it cannot reach.
73
- */
74
- export declare function withoutPaths(line: string, found: Mention[]): string;
75
- /** The line with every mention taken out: empty when it named files and said
76
- * nothing else, which is a drag and drop waiting for its question. */
77
- export declare function withoutMentions(line: string, found: Mention[]): string;
78
- /**
79
- * Hand the files to the server and get back the ids the question will carry.
80
- *
81
- * One at a time and in order, because the caps are per file and a refusal names
82
- * which file it is refusing. The service is asked first, by name and size, so a
83
- * program file or a file over the limit is refused before a byte of it moves.
84
- * A file that cannot be read does not stop the others.
85
- */
86
- export declare function upload(baseUrl: string, credential: string, files: string[]): Promise<{
87
- attached: Attached[];
88
- refused: {
89
- file: string;
90
- why: string;
91
- code?: string;
92
- }[];
93
- }>;
94
- /** One `attached` line per file, names in a column, as manual 3.1 shows. */
95
- export declare function describe(items: Attached[]): string[];
96
- /** The waiting list, numbered for `detach N` (manual 3.6). */
97
- export declare function listing(items: Attached[]): string[];
98
- /**
99
- * File names from the project for Tab after `@` (manual 3.1).
100
- *
101
- * A bounded walk, because a completion that takes a second is one nobody uses.
102
- */
103
- export declare function projectFiles(root: string, limit?: number): string[];
104
- /** What Tab completes the line to, in readline's shape: the choices, and the
105
- * part of the line they replace. */
106
- export declare function completeAt(line: string, files: () => string[]): [string[], string];
package/out/lib/attach.js DELETED
@@ -1,396 +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.unescapePath = unescapePath;
37
- exports.localProblem = localProblem;
38
- exports.mentions = mentions;
39
- exports.startsWithPath = startsWithPath;
40
- exports.withoutPaths = withoutPaths;
41
- exports.withoutMentions = withoutMentions;
42
- exports.upload = upload;
43
- exports.describe = describe;
44
- exports.listing = listing;
45
- exports.projectFiles = projectFiles;
46
- exports.completeAt = completeAt;
47
- /**
48
- * Files handed to a question, from a terminal.
49
- *
50
- * ── What a person actually does ───────────────────────────────────────────
51
- *
52
- * They drag a file onto the terminal window. Every terminal answers that by
53
- * typing the file's path at the cursor, with spaces backslash-escaped, which is
54
- * why a path is not simply "the text up to the next space". Or they type `@`
55
- * and a path, which is what everybody who has used one of these tools expects.
56
- *
57
- * Both end up here, and both mean the same thing: read this, it is what my
58
- * question is about.
59
- *
60
- * ── Why the file is uploaded and not just named ───────────────────────────
61
- *
62
- * The agent can already open any file inside the folder it is working in, so
63
- * naming one would have been cheaper. It would also have been wrong three ways:
64
- * a screenshot is not text and could never be read that way, a PDF or a
65
- * spreadsheet needs extracting before it means anything, and a file somewhere
66
- * else on the disk is outside the folder the agent is allowed to touch. A
67
- * person who attaches a file has said they want it read, so it is read.
68
- *
69
- * The reading happens on the server, by the same component the web composer
70
- * uses. Nothing is stored: the text lives in memory for half an hour and then
71
- * it is gone.
72
- *
73
- * ── What counts as a path, and what deliberately does not ─────────────────
74
- *
75
- * Only something said on purpose. An absolute path, a path starting `~/`, `./`
76
- * or `../`, anything quoted, and anything after an `@`. A bare word like
77
- * `package.json` mentioned in a sentence is NOT attached, even when a file of
78
- * that name is sitting right there: the agent can open it itself for nothing,
79
- * and silently uploading every filename somebody mentions would surprise them
80
- * and charge them for it.
81
- */
82
- const fs = __importStar(require("node:fs"));
83
- const os = __importStar(require("node:os"));
84
- const path = __importStar(require("node:path"));
85
- const gateway_1 = require("./gateway");
86
- const words_1 = require("./words");
87
- /**
88
- * Take the shell's escaping back off a path.
89
- *
90
- * A dragged file arrives as `/Users/me/My\ Report.pdf`, and a pasted one is
91
- * often in quotes. Both are the shell's way of saying "this is one thing", and
92
- * neither is part of the name.
93
- *
94
- * On Windows a backslash is the folder separator and never an escape: its
95
- * terminals quote a dragged path instead. Stripping backslashes there turned
96
- * `C:\Users\me\notes.txt` into `C:Usersmenotes.txt`, which was the Windows
97
- * failure found in prompt 01.
98
- */
99
- function unescapePath(token, platform = process.platform) {
100
- let out = token.trim();
101
- if ((out.startsWith('"') && out.endsWith('"') && out.length > 1)
102
- || (out.startsWith("'") && out.endsWith("'") && out.length > 1)) {
103
- out = out.slice(1, -1);
104
- }
105
- else if (platform !== 'win32') {
106
- out = out.replace(/\\(.)/g, '$1');
107
- }
108
- return out;
109
- }
110
- const WINDOWS_ABSOLUTE = /^(?:[A-Za-z]:[\\/]|\\\\)/;
111
- /**
112
- * Where a named path points.
113
- *
114
- * `~/` is this person's home folder. `./` and `../` start from the folder they
115
- * are in. Anything else relative starts from the project root (manual 3.1).
116
- */
117
- function expand(file, root, here) {
118
- const home = os.homedir();
119
- if (file === '~')
120
- return home;
121
- if (file.startsWith('~/') || file.startsWith('~\\'))
122
- return path.join(home, file.slice(2));
123
- if (path.isAbsolute(file) || WINDOWS_ABSOLUTE.test(file))
124
- return path.resolve(file);
125
- if (/^\.\.?[\\/]/.test(file))
126
- return path.resolve(here, file);
127
- return path.resolve(root, file);
128
- }
129
- /**
130
- * What stops a file being attached, checked on this machine before anything is
131
- * sent (manual 3.10). Only the four facts the service cannot see: whether the
132
- * file is there, is a folder, can be read, or is a link to nothing.
133
- */
134
- function localProblem(file, shown) {
135
- let link;
136
- try {
137
- link = fs.lstatSync(file);
138
- }
139
- catch {
140
- return { code: 'not_found', message: (0, words_1.word)('fileNotFound', { file: shown }) };
141
- }
142
- let stat;
143
- try {
144
- stat = fs.statSync(file);
145
- }
146
- catch {
147
- return link.isSymbolicLink()
148
- ? { code: 'broken_link', message: `${shown} points to a file that does not exist` }
149
- : { code: 'unreadable', message: (0, words_1.word)('fileNoPermission', { file: shown }) };
150
- }
151
- if (stat.isDirectory()) {
152
- return {
153
- code: 'folder',
154
- message: `${shown} is a folder. Attach the files you need, or ask the agent to look in it.`,
155
- };
156
- }
157
- try {
158
- fs.closeSync(fs.openSync(file, 'r'));
159
- }
160
- catch {
161
- return { code: 'unreadable', message: (0, words_1.word)('fileNoPermission', { file: shown }) };
162
- }
163
- return undefined;
164
- }
165
- /** Something is on the disk at this path, even a link to nothing. */
166
- function present(file) {
167
- try {
168
- fs.lstatSync(file);
169
- return true;
170
- }
171
- catch {
172
- return false;
173
- }
174
- }
175
- /**
176
- * Every file the typed line points at, in the order they were named.
177
- *
178
- * Anything after an `@` is a request to attach, so a problem with it is
179
- * reported. Any other path (absolute, `~/`, `./`, `../`, quoted) that is not a
180
- * readable file is left alone and stays part of the question: somebody writing
181
- * about a path they plan to create, or a folder they want looked at, is doing
182
- * something perfectly ordinary.
183
- */
184
- function mentions(line, root, here = root, platform = process.platform) {
185
- const found = [];
186
- const seen = new Set();
187
- const consider = (raw, candidate, asked) => {
188
- const shown = unescapePath(candidate, platform);
189
- if (!shown)
190
- return false;
191
- const file = expand(shown, root, here);
192
- if (seen.has(file))
193
- return true;
194
- const problem = localProblem(file, shown);
195
- // A path in a sentence is only attached when it is a readable file, or a
196
- // link to nothing (which is plainly a file the person meant).
197
- if (!asked && problem && problem.code !== 'broken_link')
198
- return false;
199
- seen.add(file);
200
- found.push({ raw, file, shown, ...(problem ? { problem } : {}) });
201
- return true;
202
- };
203
- // Quoted first, because a quoted path may contain the spaces that would
204
- // otherwise end a token, and the quotes are the person saying exactly that.
205
- // An `@` straight before the quotes belongs to the same mention.
206
- for (const m of line.matchAll(/(@?)(?:"([^"]+)"|'([^']+)')/g)) {
207
- consider(m[0], `"${m[2] ?? m[3] ?? ''}"`, m[1] === '@');
208
- }
209
- // Then `@`, which is treated generously on purpose.
210
- //
211
- // A dragged file arrives escaped and a pasted one is usually quoted, but
212
- // somebody who TYPES `@` and then a folder with a space in its name has said
213
- // what they mean as plainly as it can be said. So everything after the `@` is
214
- // tried, then the last word is dropped and it is tried again, until something
215
- // on the disk turns up or the words run out. `@/Users/me/My Report.md in one
216
- // line` finds the report and leaves the rest of the sentence alone. When
217
- // nothing turns up, the first word is what was named, and it is not found.
218
- // Every `@`, each with the rest of the line after it. A single match of
219
- // "@ to end of line" swallowed every later `@` on the same line, so
220
- // `@a.txt @b.txt` only ever looked at the first.
221
- for (const m of line.matchAll(/(?:^|\s)@(?=[^\s"'])/g)) {
222
- const rest = (line.slice((m.index ?? 0) + m[0].length).split(/\r?\n/)[0]) ?? '';
223
- let hit = false;
224
- // Punctuation that closes a sentence is tried off as well as on, because
225
- // `@layout.png,` means layout.png. Tried second, so a name that really
226
- // ends in one of these is still found first.
227
- const trimmed = (text) => text.replace(/[,.:;!?)\]]+$/, '');
228
- for (let end = rest.length; end > 0 && !hit; end = rest.lastIndexOf(' ', end - 1)) {
229
- for (const candidate of new Set([rest.slice(0, end), trimmed(rest.slice(0, end))])) {
230
- if (!candidate || !present(expand(unescapePath(candidate, platform), root, here)))
231
- continue;
232
- hit = consider(`@${candidate}`, candidate, true);
233
- break;
234
- }
235
- }
236
- if (!hit) {
237
- const word = (platform === 'win32' ? /^\S+/ : /^(?:\\.|[^\s\\])+/).exec(rest)?.[0];
238
- const named = word ? trimmed(word) || word : '';
239
- if (named)
240
- consider(`@${named}`, named, true);
241
- }
242
- }
243
- // Then every run of non-space, with `\ ` counting as part of the run rather
244
- // than as the end of it (except on Windows, where a backslash is a folder).
245
- // This is the dragged-file case.
246
- const runs = platform === 'win32' ? /\S+/g : /(?:\\.|[^\s\\])+/g;
247
- for (const m of line.matchAll(runs)) {
248
- const raw = m[0];
249
- if (!raw || raw.startsWith('@') || raw.startsWith('"') || raw.startsWith("'"))
250
- continue;
251
- const deliberate = /^[/~]/.test(raw) || /^\.\.?[\\/]/.test(raw)
252
- || WINDOWS_ABSOLUTE.test(raw);
253
- if (!deliberate)
254
- continue;
255
- consider(raw, raw, false);
256
- }
257
- return found;
258
- }
259
- /** The line begins with an absolute path to something on the disk, as a
260
- * dragged file does, rather than with a slashed command word. */
261
- function startsWithPath(line, platform = process.platform) {
262
- const first = (platform === 'win32' ? /^\S+/ : /^(?:\\.|[^\s\\])+/).exec(line.trim())?.[0];
263
- if (!first || !first.startsWith('/') || first.indexOf('/', 1) < 0)
264
- return false;
265
- return present(unescapePath(first, platform));
266
- }
267
- /**
268
- * The question with the long paths taken out and the file names left in.
269
- *
270
- * "summarize @/Users/me/Downloads/Q3 Board Pack.pdf" is a worse question than
271
- * "summarize Q3 Board Pack.pdf", and the second is what the model should be
272
- * reading: the file is already in front of it under that name, so the path adds
273
- * nothing but a place for the model to try to open something it cannot reach.
274
- */
275
- function withoutPaths(line, found) {
276
- let out = line;
277
- for (const m of found)
278
- out = out.replace(m.raw, path.basename(m.file));
279
- return out.replace(/\s{2,}/g, ' ').trim();
280
- }
281
- /** The line with every mention taken out: empty when it named files and said
282
- * nothing else, which is a drag and drop waiting for its question. */
283
- function withoutMentions(line, found) {
284
- let out = line;
285
- for (const m of found)
286
- out = out.replace(m.raw, ' ');
287
- return out.replace(/\s+/g, ' ').trim();
288
- }
289
- function fromServer(row) {
290
- return {
291
- id: row.id, filename: row.filename, format: row.format,
292
- chars: row.chars, truncated: row.truncated, isImage: row.is_image,
293
- sizeBytes: row.size_bytes ?? 0,
294
- // An older service sent no summary. The bare facts, never a local verdict.
295
- summary: row.summary
296
- ?? (row.is_image ? row.format : `${row.format} ${row.chars} chars`),
297
- };
298
- }
299
- /**
300
- * Hand the files to the server and get back the ids the question will carry.
301
- *
302
- * One at a time and in order, because the caps are per file and a refusal names
303
- * which file it is refusing. The service is asked first, by name and size, so a
304
- * program file or a file over the limit is refused before a byte of it moves.
305
- * A file that cannot be read does not stop the others.
306
- */
307
- async function upload(baseUrl, credential, files) {
308
- const root = baseUrl.replace(/\/+$/, '');
309
- const attached = [];
310
- const refused = [];
311
- for (const file of files) {
312
- try {
313
- const name = path.basename(file);
314
- const size = fs.statSync(file).size;
315
- const granted = await (0, gateway_1.ask)({
316
- intent: 'attach', prompt: '', attachment: { filename: name, size_bytes: size },
317
- });
318
- if (granted.ok && granted.served !== false && granted.granted === false) {
319
- refused.push({ file, why: granted.message || `${name} was not accepted`,
320
- code: granted.refusal ?? undefined });
321
- continue;
322
- }
323
- const pass = granted.ok && granted.served !== false ? granted.upload : null;
324
- const where = pass?.upload_path || '/api/v1/agent/attachments';
325
- const form = new FormData();
326
- form.append('file', new Blob([fs.readFileSync(file)]), name);
327
- const res = await fetch(`${root}${where}${pass?.ticket ? `?ticket=${encodeURIComponent(pass.ticket)}` : ''}`, { method: 'POST', headers: { Authorization: `Bearer ${credential}` }, body: form });
328
- if (!res.ok) {
329
- const body = await res.json().catch(() => ({}));
330
- refused.push({ file, why: body.detail || `the server said ${res.status}`, code: body.code });
331
- continue;
332
- }
333
- attached.push(fromServer(await res.json()));
334
- }
335
- catch (err) {
336
- refused.push({ file, why: err.message });
337
- }
338
- }
339
- return { attached, refused };
340
- }
341
- /** One `attached` line per file, names in a column, as manual 3.1 shows. */
342
- function describe(items) {
343
- const width = Math.max(0, ...items.map((a) => a.filename.length));
344
- return items.map((a) => `attached ${a.filename.padEnd(width)} ${a.summary}`);
345
- }
346
- /** The waiting list, numbered for `detach N` (manual 3.6). */
347
- function listing(items) {
348
- const width = Math.max(0, ...items.map((a) => a.filename.length));
349
- return items.map((a, i) => `${String(i + 1).padStart(2)} ${a.filename.padEnd(width)} ${a.summary}`);
350
- }
351
- /** Folders never offered by Tab: nobody attaches from them. */
352
- const SKIP = new Set(['node_modules', '.git', 'dist', 'build', 'out', '__pycache__', '.venv', 'venv']);
353
- /**
354
- * File names from the project for Tab after `@` (manual 3.1).
355
- *
356
- * A bounded walk, because a completion that takes a second is one nobody uses.
357
- */
358
- function projectFiles(root, limit = 5000) {
359
- const out = [];
360
- const walk = (dir) => {
361
- if (out.length >= limit)
362
- return;
363
- let entries;
364
- try {
365
- entries = fs.readdirSync(dir, { withFileTypes: true });
366
- }
367
- catch {
368
- return;
369
- }
370
- for (const entry of entries) {
371
- if (out.length >= limit)
372
- return;
373
- if (entry.isDirectory()) {
374
- if (entry.name.startsWith('.') || SKIP.has(entry.name))
375
- continue;
376
- walk(path.join(dir, entry.name));
377
- }
378
- else if (entry.isFile()) {
379
- out.push(path.relative(root, path.join(dir, entry.name)).split(path.sep).join('/'));
380
- }
381
- }
382
- };
383
- walk(root);
384
- return out.sort();
385
- }
386
- /** What Tab completes the line to, in readline's shape: the choices, and the
387
- * part of the line they replace. */
388
- function completeAt(line, files) {
389
- const m = /(?:^|\s)(@[^\s]*)$/.exec(line);
390
- if (!m)
391
- return [[], line];
392
- const typed = m[1];
393
- const prefix = typed.slice(1);
394
- const hits = files().filter((f) => f.startsWith(prefix)).map((f) => `@${f}`);
395
- return [hits.slice(0, 200), typed];
396
- }
@@ -1,23 +0,0 @@
1
- /** What reading the clipboard came to. */
2
- export type Clip = {
3
- ok: true;
4
- file: string;
5
- folder: string;
6
- } | {
7
- ok: false;
8
- why: string;
9
- };
10
- /** Runs one program and reports its exit, output and whether it was found.
11
- * With `out`, the program's output is written to that file as bytes. */
12
- export type Runner = (file: string, args: string[], out?: string) => Promise<{
13
- code: number;
14
- stdout: string;
15
- missing: boolean;
16
- }>;
17
- /**
18
- * Save the clipboard's picture as `clipboard-N.png` in a new temporary folder.
19
- * `n` numbers the pastes in one session, so three screenshots are three names.
20
- */
21
- export declare function readClipboardImage(n: number, exec?: Runner, platform?: string): Promise<Clip>;
22
- /** Remove a paste's temporary folder. Always called, whatever happened. */
23
- export declare function discard(folder: string): void;
@@ -1,20 +0,0 @@
1
- export interface Listed {
2
- name: string;
3
- description: string;
4
- /** `session`, `workspace skill`, `company skill`, `workspace command`, ... */
5
- source: string;
6
- }
7
- export interface CommandList {
8
- /** False when the service could not be asked. Nothing below is then known. */
9
- ok: boolean;
10
- items: Listed[];
11
- /** Words the service knows that this version of the tool does not run. */
12
- needsUpdate: string[];
13
- /** Whether typed requests may be kept on this machine between sessions. */
14
- keepHistory: boolean;
15
- }
16
- export declare function readOne(root: string, rel: string): string | null;
17
- export declare function listOne(root: string, rel: string): string[] | null;
18
- /** Ask the service for this project's list. `words` are the session words
19
- * this tool runs. */
20
- export declare function fetchCommandList(root: string, words: string[]): Promise<CommandList>;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readOne = readOne;
4
- exports.listOne = listOne;
5
- exports.fetchCommandList = fetchCommandList;
6
- /**
7
- * The session's command and skill list, as the service decides it (manual 6.4).
8
- *
9
- * The service names each file or folder it needs from the project and this
10
- * reads it, inside the project and through the executor's own checks, so a
11
- * secrets file is never sent and nothing outside the project is read. It asks
12
- * again with what it was given until it has what it needs. Every choice about
13
- * what counts as a skill, what it is called and what its line says is made on
14
- * the service.
15
- */
16
- const files_1 = require("../machine/executor/files");
17
- const gateway_1 = require("./gateway");
18
- const ROUNDS = 6;
19
- const MAX_CHARS = 8000;
20
- function readOne(root, rel) {
21
- const r = (0, files_1.performFileAction)(root, 'read_file', { path: rel });
22
- return r.isError ? null : r.content.slice(0, MAX_CHARS);
23
- }
24
- function listOne(root, rel) {
25
- const r = (0, files_1.performFileAction)(root, 'list_dir', { path: rel });
26
- if (r.isError)
27
- return null;
28
- return r.content === '(empty)' ? [] : r.content.split('\n').filter(Boolean);
29
- }
30
- /** Ask the service for this project's list. `words` are the session words
31
- * this tool runs. */
32
- async function fetchCommandList(root, words) {
33
- const files = {};
34
- const listings = {};
35
- for (let round = 0; round < ROUNDS; round += 1) {
36
- const reply = await (0, gateway_1.ask)({
37
- intent: 'commands', prompt: '',
38
- commandsPayload: { words, round, files, listings, project: root, forwards: true },
39
- });
40
- const body = reply.commands;
41
- if (!reply.ok || reply.served === false || !body) {
42
- return { ok: false, items: [], needsUpdate: [], keepHistory: false };
43
- }
44
- if (!body.wants) {
45
- return {
46
- ok: true,
47
- items: body.items ?? [],
48
- needsUpdate: body.needs_update ?? [],
49
- keepHistory: body.keep_history === true,
50
- };
51
- }
52
- for (const p of body.wants.read ?? [])
53
- files[p] = readOne(root, p);
54
- for (const f of body.wants.list ?? [])
55
- listings[f] = listOne(root, f);
56
- }
57
- return { ok: false, items: [], needsUpdate: [], keepHistory: false };
58
- }