@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,606 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.workspaceUrl = workspaceUrl;
40
- exports.cmdLogin = cmdLogin;
41
- /**
42
- * `comprism login` — the whole sign in, asked one question at a time.
43
- *
44
- * ── Why this replaced what was there ──────────────────────────────────────
45
- *
46
- * Signing in used to mean typing this, correctly, from memory:
47
- *
48
- * comprism connect --url https://base-tenant.completionprism.illuminis.ai --email you@company.com
49
- *
50
- * A new customer does not know their workspace address, has never seen that
51
- * flag, and gets no second chance at a first impression. Worse, if their
52
- * account required a second factor the command refused outright and told them
53
- * to go and find a token in a browser, which meant the terminal product was
54
- * unreachable for every account a security team had done the right thing to.
55
- *
56
- * So: one word, then two questions, then the code if their account asks for one.
57
- *
58
- * comprism login
59
- * email: you@acme.com
60
- * password: ••••••••
61
- * code: 123456
62
- *
63
- * THE WORKSPACE IS NOT ASKED FOR. It is looked up from the email's domain,
64
- * which the product already does for the browser sign in: a domain maps to at
65
- * most one workspace, enforced by a unique index, so there is never a choice to
66
- * put in front of anybody. An unknown domain, which is what a personal email
67
- * is, resolves to the shared individuals workspace, because that is exactly
68
- * where signing up puts it.
69
- *
70
- * The lookup reads the workspace registry and never the user list, so it cannot
71
- * be used to find out who has an account.
72
- *
73
- * `--workspace` still works, for a person whose company runs a workspace under
74
- * a domain that is not in their email, and for our own testing.
75
- */
76
- const node_os_1 = __importDefault(require("node:os"));
77
- const connection_1 = require("../lib/connection");
78
- const gateway_1 = require("../lib/gateway");
79
- const ui = __importStar(require("../lib/ui"));
80
- const prompt_1 = require("../lib/prompt");
81
- const words_1 = require("../lib/words");
82
- const out = (s = '') => process.stdout.write(s + '\n');
83
- /** Where a named workspace lives. One format, stated once. */
84
- const WORKSPACE_DOMAIN = 'completionprism.illuminis.ai';
85
- /**
86
- * Turn what a person typed into the address of their workspace.
87
- *
88
- * Accepts the workspace name, which is the normal case, and also a full URL or
89
- * a bare host, because somebody who was given a link will paste the link. All
90
- * three arrive at the same place rather than at an error message.
91
- */
92
- function workspaceUrl(typed) {
93
- const value = typed.trim().replace(/\/+$/, '');
94
- if (/^https?:\/\//i.test(value))
95
- return value;
96
- // A host with a port, or a machine on this network, is already an address.
97
- // Without this, `localhost:8009` had our domain appended to it and the
98
- // command reported a network problem for what was really a parsing one.
99
- if (/^(localhost|127\.0\.0\.1)(:\d+)?$/i.test(value))
100
- return `http://${value}`;
101
- if (value.includes(':'))
102
- return `http://${value}`;
103
- if (value.includes('.'))
104
- return `https://${value}`;
105
- return `https://${value}.${WORKSPACE_DOMAIN}`;
106
- }
107
- /**
108
- * Where an organization signs in. A full address is used as typed. A bare name
109
- * is turned into its address by the service, so every client follows one rule
110
- * (service catalog 1).
111
- */
112
- async function addressOf(typed) {
113
- const value = typed.trim().replace(/\/+$/, '');
114
- if (/^[A-Za-z0-9][A-Za-z0-9-]{0,62}$/.test(value) && value.toLowerCase() !== 'localhost') {
115
- const reply = await (0, gateway_1.askAt)(`https://${WORKSPACE_DOMAIN}`, { intent: 'resolve_workspace', prompt: value });
116
- const url = reply.session?.workspace_url;
117
- if (url)
118
- return url.replace(/\/+$/, '');
119
- }
120
- return workspaceUrl(value);
121
- }
122
- /** Localhost needs the tenant named, because there is no subdomain to read. */
123
- function tenantFor(url, typed, flagged) {
124
- if (flagged)
125
- return flagged;
126
- if (!/localhost|127\.0\.0\.1/.test(url))
127
- return undefined;
128
- // There is no subdomain on a local address to read the tenant from, so the
129
- // developer tenant is assumed unless one was named.
130
- return 'base-tenant';
131
- }
132
- async function post(url, path, body, tenant) {
133
- const headers = { 'content-type': 'application/json' };
134
- if (tenant)
135
- headers['X-Tenant-ID'] = tenant;
136
- const res = await fetch(`${url}${path}`, {
137
- method: 'POST', headers, body: JSON.stringify(body),
138
- });
139
- let json = {};
140
- try {
141
- json = (await res.json());
142
- }
143
- catch { /* non-JSON body */ }
144
- return { status: res.status, json };
145
- }
146
- const DEVICE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code';
147
- /** The built in public client the portal accepts for this product's CLI. */
148
- const CLIENT_ID = 'completionprism-cli';
149
- function headersFor(tenant) {
150
- return tenant ? { 'X-Tenant-ID': tenant } : {};
151
- }
152
- /** Whether this workspace's company signs in through its own identity provider. */
153
- async function usesCompanyLogin(url, tenant) {
154
- try {
155
- const res = await fetch(`${url}/api/v1/auth/sso/providers`, { headers: headersFor(tenant) });
156
- if (!res.ok)
157
- return false;
158
- const body = await res.json();
159
- return (body.providers?.length ?? 0) > 0 && body.password_enabled === false;
160
- }
161
- catch {
162
- return false;
163
- }
164
- }
165
- function openInBrowser(address) {
166
- const { spawn } = require('node:child_process');
167
- const [cmd, argv] = process.platform === 'darwin' ? ['open', [address]]
168
- : process.platform === 'win32' ? ['cmd', ['/c', 'start', '', address]]
169
- : ['xdg-open', [address]];
170
- try {
171
- spawn(cmd, argv, { stdio: 'ignore', detached: true }).on('error', () => { }).unref();
172
- }
173
- catch { /* the address is printed as well */ }
174
- }
175
- /** The portal's own device sign in: approve in a browser, get a token back. */
176
- async function approveInBrowser(url, tenant, noBrowser) {
177
- const form = (fields) => ({
178
- method: 'POST',
179
- headers: { ...headersFor(tenant), 'content-type': 'application/x-www-form-urlencoded' },
180
- body: new URLSearchParams(fields).toString(),
181
- });
182
- let started;
183
- try {
184
- const res = await fetch(`${url}/oauth/device_authorization`, form({ client_id: CLIENT_ID, scope: 'api:read api:write' }));
185
- if (!res.ok) {
186
- out(ui.fail(res.status === 404 || res.status === 405
187
- ? 'That organization is running a build without browser sign in.'
188
- : 'The organization would not start a browser sign in.'));
189
- return '';
190
- }
191
- started = await res.json();
192
- }
193
- catch {
194
- out(ui.fail(`Could not reach ${url}. Check your connection and try again.`));
195
- return '';
196
- }
197
- out();
198
- if (noBrowser) {
199
- out(` On any device, open ${ui.c.bold(started.verification_uri)}`);
200
- out(` and enter the code ${ui.c.bold(started.user_code)}`);
201
- }
202
- else {
203
- out(ui.info('Your company signs in through its own login page. Opening your browser.'));
204
- out(` If it does not open, go to ${started.verification_uri_complete}`);
205
- out(` and confirm the code ${ui.c.bold(started.user_code)}`);
206
- openInBrowser(started.verification_uri_complete);
207
- }
208
- out(ui.c.dim(' waiting for you to approve it there...'));
209
- const deadline = Date.now() + Math.max(30, started.expires_in || 600) * 1000;
210
- let wait = Math.max(1, started.interval || 5);
211
- while (Date.now() < deadline) {
212
- await new Promise((r) => setTimeout(r, wait * 1000));
213
- let res;
214
- try {
215
- res = await fetch(`${url}/oauth/token`, form({ grant_type: DEVICE_GRANT, device_code: started.device_code, client_id: CLIENT_ID }));
216
- }
217
- catch {
218
- continue;
219
- }
220
- const body = await res.json().catch(() => ({}));
221
- if (res.ok && body.access_token)
222
- return body.access_token;
223
- if (body.error === 'authorization_pending')
224
- continue;
225
- if (body.error === 'slow_down') {
226
- wait += 5;
227
- continue;
228
- }
229
- out(ui.fail(body.error === 'access_denied' ? 'The sign in was declined in the browser.'
230
- : 'That sign in was not approved.'));
231
- return '';
232
- }
233
- out(ui.fail('That code expired before it was approved. Run comprism login again.'));
234
- return '';
235
- }
236
- async function runLogin(args) {
237
- // SIGN IN WITH AN INSTALL KEY (web manual 12.1). The key made on the
238
- // Install and setup page is this machine's credential, so setup is the one
239
- // command the page shows and nothing is typed. It needs no terminal, because
240
- // the install script runs it on a pipe.
241
- const keyAt = args.indexOf('--key');
242
- if (keyAt >= 0)
243
- return loginWithKey(args[keyAt + 1], args);
244
- // Password and second factor entry require a person at a terminal. Do not
245
- // open readline on a pipe: it can wait forever, or exit successfully at EOF
246
- // without signing in. Check before workspace lookup or reading credentials.
247
- if (process.stdin.isTTY !== true) {
248
- out(ui.fail('Signing in requires an interactive terminal.'));
249
- out(' Run comprism login in a terminal, then run your command again.');
250
- process.exitCode = 1;
251
- return;
252
- }
253
- // Under the session's own mark when the session is about to open, so the
254
- // name is not drawn twice in a row.
255
- out(args.includes('--into-session') ? ` ${ui.c.bold('Sign in')}` : ui.banner('Sign in'));
256
- out();
257
- // Flags still work, for a script or a second machine. A person gets asked.
258
- const flag = (name) => {
259
- const i = args.indexOf(name);
260
- return i >= 0 ? args[i + 1] : undefined;
261
- };
262
- // THE LAST PERSON, OFFERED. Signing in again is Enter: the email and the
263
- // workspace they used last time, exactly as they were, so a local workspace
264
- // stays local instead of being looked up again and sent to production.
265
- const { readLast, saveLast, forgetLast, savedPassword, savePassword, forgetPassword, keychainAvailable } = await Promise.resolve().then(() => __importStar(require('../lib/lastlogin')));
266
- if (args.includes('--forget')) {
267
- forgetLast();
268
- out(ui.ok('The last sign in and any saved password on this Mac are forgotten.'));
269
- out();
270
- return;
271
- }
272
- const last = flag('--username') || flag('--email') || (flag('--organization') || flag('--workspace')) ? null : readLast();
273
- if (last) {
274
- out(` ${ui.c.dim('last time')} ${ui.c.bold(last.email)} ${ui.c.dim('at')} ${ui.c.bold(last.workspace)}`);
275
- out(` ${ui.c.dim('press Enter to sign in as them, or type another email')}`);
276
- }
277
- const typedEmail = flag('--username') || flag('--email') || await (0, prompt_1.askOrCancel)(' email: ');
278
- // Ctrl+C is "never mind", not "yes, the last person".
279
- if (typedEmail === null) {
280
- out();
281
- out(ui.c.dim(' sign in canceled'));
282
- out();
283
- return;
284
- }
285
- const username = typedEmail || last?.email || '';
286
- const again = Boolean(last && username === last.email);
287
- if (!username) {
288
- out(ui.fail('An email address is needed.'));
289
- out();
290
- process.exitCode = 1;
291
- return;
292
- }
293
- // Where this person's workspace is. Asked of the product, not of them.
294
- let typedWorkspace = (flag('--organization') || flag('--workspace')) || (again ? last?.workspace : undefined);
295
- // Captured BEFORE the email lookup can fill it in. A workspace the product
296
- // worked out is not a workspace the person typed, and only the second may be
297
- // a local address. See the fence in `writeConnection`. The last sign in
298
- // counts as typed only if it was typed then.
299
- const typedByHand = Boolean((flag('--organization') || flag('--workspace'))) || Boolean(again && last?.typed);
300
- if (!typedWorkspace) {
301
- const live = new ui.LiveIndicator();
302
- live.start('finding your organization');
303
- try {
304
- typedWorkspace = (await resolveWorkspace(username)) || undefined;
305
- }
306
- finally {
307
- live.stop();
308
- }
309
- // The indicator clears its own line but leaves the cursor mid-row, so the
310
- // next prompt landed after a run of blanks.
311
- process.stdout.write('\r');
312
- if (!typedWorkspace) {
313
- out();
314
- out(ui.fail('No organization is registered for that email address.'));
315
- out(` ${ui.c.dim('if your company uses a different domain, pass --organization <name>')}`);
316
- out();
317
- process.exitCode = 1;
318
- return;
319
- }
320
- }
321
- const url = await addressOf(typedWorkspace);
322
- const tenant = tenantFor(url, typedWorkspace, flag('--tenant'));
323
- // Said before the password is asked for, so a person can see which company
324
- // they are about to sign in to (manual 1.3).
325
- out(` organization: ${url}`);
326
- // COMPANY LOGIN (manual 1.10). A workspace whose company signs in through
327
- // its own identity provider is signed in to in a browser; this tool never
328
- // sees that password. `--device` is the same thing for a machine with no
329
- // browser: a short code to approve from any other device.
330
- const byCompany = args.includes('--device') || args.includes('--browser')
331
- || await usesCompanyLogin(url, tenant);
332
- const deviceToken = byCompany ? await approveInBrowser(url, tenant, args.includes('--device')) : '';
333
- if (byCompany && !deviceToken) {
334
- out();
335
- process.exitCode = 1;
336
- return;
337
- }
338
- // The keychain first, when the person chose to keep it there last time.
339
- const kept = byCompany ? null : savedPassword(username, typedWorkspace);
340
- if (kept)
341
- out(` ${ui.c.dim('password: from your Mac keychain')}`);
342
- const password = byCompany ? '' : kept || await (0, prompt_1.askHidden)(' password: ');
343
- if (!byCompany && !password) {
344
- out(ui.fail('A password is needed.'));
345
- out();
346
- process.exitCode = 1;
347
- return;
348
- }
349
- // EVERYTHING BELOW GOES THROUGH THE ONE SERVICE.
350
- //
351
- // This used to call three separate addresses in sequence: sign in, second
352
- // factor, then machine enrollment. Three doors for one act, and the tool had
353
- // to know the order to knock on them in, which is product logic living on a
354
- // customer's laptop. It is now one question, asked twice only when a second
355
- // factor is genuinely required.
356
- let signedIn = null;
357
- let signInMessage = '';
358
- {
359
- let reply = await (0, gateway_1.askAt)(url, {
360
- intent: 'sign_in', prompt: username, password, deviceToken,
361
- machineLabel: `comprism on ${node_os_1.default.hostname()}`,
362
- }, tenant);
363
- if (reply.served === false) {
364
- out();
365
- out(ui.fail('That organization is running a build that cannot sign you in yet.'));
366
- out(` ${ui.c.dim(reply.message || 'the organization is behind this copy of the tool')}`);
367
- out();
368
- process.exitCode = 1;
369
- return;
370
- }
371
- if (!reply.ok) {
372
- out();
373
- out(ui.fail(reply.httpStatus
374
- ? (reply.message || 'The service refused the sign in request.')
375
- : `Could not reach ${url}. Check your connection and try again.`));
376
- out();
377
- process.exitCode = 1;
378
- return;
379
- }
380
- // A second factor is a normal ANSWER, not a failure. This is the whole
381
- // reason the command exists: an older one gave up here and sent people to a
382
- // browser to find a token by hand.
383
- if (reply.sign_in?.needs_second_factor && reply.sign_in.challenge) {
384
- out();
385
- out(ui.info('This account uses a second step. Check your authenticator app or your email.'));
386
- const code = await (0, prompt_1.askHidden)(' code from your authenticator app: ');
387
- if (!code) {
388
- out(ui.fail('A code is needed to finish signing in.'));
389
- out();
390
- process.exitCode = 1;
391
- return;
392
- }
393
- reply = await (0, gateway_1.askAt)(url, {
394
- intent: 'sign_in', prompt: username,
395
- challenge: reply.sign_in.challenge, code,
396
- machineLabel: `comprism on ${node_os_1.default.hostname()}`,
397
- }, tenant);
398
- if (!reply.ok || !reply.sign_in?.token) {
399
- out();
400
- out(ui.fail(reply.message || 'That code was not accepted. Codes expire after a few minutes.'));
401
- out();
402
- process.exitCode = 1;
403
- return;
404
- }
405
- }
406
- if (!reply.sign_in?.token) {
407
- // A kept password that no longer works is removed, so the next sign in
408
- // asks for the new one instead of failing the same way again.
409
- if (kept)
410
- forgetPassword(username, typedWorkspace);
411
- out();
412
- out(ui.fail(reply.message || 'That username and password were not accepted.'));
413
- out(` ${ui.c.dim('check the organization name too: a right password in the wrong organization looks the same')}`);
414
- out();
415
- process.exitCode = 1;
416
- return;
417
- }
418
- signedIn = reply.sign_in;
419
- signInMessage = reply.message || '';
420
- if (reply.complete === false && reply.message) {
421
- // Signed in, but something about it is incomplete. Said, not swallowed.
422
- out();
423
- out(ui.warn(reply.message));
424
- }
425
- }
426
- const token = signedIn?.token;
427
- if (!token) {
428
- out();
429
- out(ui.fail('Sign in succeeded but no session came back.'));
430
- out();
431
- process.exitCode = 1;
432
- return;
433
- }
434
- // A previous credential may belong to another account or workspace, or
435
- // have been revoked during this sign in. Only retain the newly issued key.
436
- const existing = (0, connection_1.readConnection)();
437
- const workspaceKey = signedIn?.machine_credential || undefined;
438
- // `typedByHand` is the second half of the fence in `writeConnection`. It is
439
- // true only when the person put the address on this command line, in this
440
- // run. A workspace resolved from their email domain, or an address a server
441
- // handed back, can never install a laptop address however convincingly it
442
- // asks.
443
- try {
444
- (0, connection_1.writeConnection)({
445
- // The address the SERVER says it answers on, UNLESS the person named one
446
- // themselves on this command line.
447
- //
448
- // Preferring the server is right for everybody who did not type an
449
- // address: a tool that stores its own guess can never be told by anybody
450
- // that the guess was wrong, which is how a machine sat pointed at a dead
451
- // port for an evening. It is exactly wrong for somebody who DID type one.
452
- // They typed it because they meant it, and the server, being asked where
453
- // it lives, answers with its public address and quietly replaces the one
454
- // they chose. That made testing a change against a local copy impossible:
455
- // sign in, and the tool went straight back to production.
456
- url: (typedByHand && url) || signedIn?.workspace_url || url,
457
- token,
458
- ...(tenant ? { tenant } : {}),
459
- ...(workspaceKey ? { workspaceKey } : {}),
460
- everyMinutes: existing?.everyMinutes ?? 5,
461
- connectedAt: existing?.connectedAt || new Date().toISOString(),
462
- }, typedByHand);
463
- }
464
- catch (err) {
465
- out();
466
- out(ui.fail(err instanceof Error ? err.message : (0, words_1.word)('addressRefused')));
467
- out();
468
- process.exitCode = 1;
469
- return;
470
- }
471
- // So a new terminal presents the key just issued, not the last one or none.
472
- for (const profile of (await Promise.resolve().then(() => __importStar(require('./install')))).finishSetup())
473
- out(` Finishing setup: added one line to ${profile}`);
474
- // Remembered for next time: who, and where, exactly as used now.
475
- saveLast({ email: username, workspace: typedWorkspace, typed: typedByHand });
476
- if (!byCompany && !kept && password && keychainAvailable()) {
477
- const keep = (await (0, prompt_1.ask)(' keep your password in your Mac keychain, so next time is just Enter? (y/n) '))
478
- .trim().toLowerCase();
479
- if (keep === 'y' || keep === 'yes') {
480
- out(savePassword(username, typedWorkspace, password)
481
- ? ` ${ui.c.dim('kept in your keychain; remove it with')} ${ui.c.bold('comprism login --forget')}`
482
- : ` ${ui.c.dim('the keychain would not take it; you will be asked next time')}`);
483
- }
484
- }
485
- out();
486
- // Where this machine will actually talk to: the address typed, when one was.
487
- const where = (typedByHand && url) || signedIn?.workspace_url || url;
488
- const onLaptop = /localhost|127\.0\.0\.1/.test(where);
489
- out(ui.ok(`Signed in as ${ui.c.bold(username)} ${onLaptop
490
- ? `on this laptop (${ui.c.bold(where.replace(/^https?:\/\//, ''))})`
491
- : `at ${ui.c.bold(where)}`}.`));
492
- if (workspaceKey) {
493
- out(` ${ui.c.dim('This machine is enrolled and can be revoked from Administration.')}`);
494
- // Straight into the welcome screen, so the first thing after signing in is
495
- // where they are rather than another instruction.
496
- // Unless the session is about to open, which draws it itself.
497
- if (!args.includes('--into-session')) {
498
- const { showWelcome } = await Promise.resolve().then(() => __importStar(require('./welcome')));
499
- await showWelcome();
500
- }
501
- }
502
- else {
503
- process.exitCode = 1;
504
- out(ui.warn('Signed in, but this machine could not be enrolled.'));
505
- // The workspace's OWN reason, carried back with the sign in. It used to
506
- // come from a local variable set by a separate call, which meant a blank
507
- // line whenever that call had not been the thing that failed.
508
- out(` ${ui.c.dim(signInMessage || 'the organization did not say why')}`);
509
- out(` ${ui.c.dim('you are signed in; this machine cannot ask for work until it is enrolled')}`);
510
- }
511
- out();
512
- }
513
- /** Enrol this machine with an install key: checked with the service, then kept. */
514
- async function loginWithKey(key, args) {
515
- const flag = (name) => {
516
- const i = args.indexOf(name);
517
- return i >= 0 ? args[i + 1] : undefined;
518
- };
519
- const typed = (flag('--organization') || flag('--workspace'));
520
- if (!key || !typed) {
521
- out(ui.fail('Signing in with a key needs the key and the organization: comprism login --key <key> --organization <address>'));
522
- process.exitCode = 1;
523
- return;
524
- }
525
- const url = await addressOf(typed);
526
- const tenant = tenantFor(url, typed, flag('--tenant'));
527
- const { ask: askWith } = await Promise.resolve().then(() => __importStar(require('../lib/gateway')));
528
- const existing = (0, connection_1.readConnection)();
529
- try {
530
- (0, connection_1.writeConnection)({
531
- url, token: '', workspaceKey: key, ...(tenant ? { tenant } : {}),
532
- everyMinutes: existing?.everyMinutes ?? 5,
533
- connectedAt: new Date().toISOString(),
534
- }, true);
535
- }
536
- catch (err) {
537
- out(ui.fail(err instanceof Error ? err.message : (0, words_1.word)('addressRefused')));
538
- process.exitCode = 1;
539
- return;
540
- }
541
- const reply = await askWith({ intent: 'catalog', prompt: '' });
542
- if (!reply.ok) {
543
- if (existing)
544
- (0, connection_1.writeConnection)(existing, true);
545
- out(ui.fail(reply.message || `That key was not accepted by ${url}.`));
546
- out(` ${ui.c.dim('make a new one on the Install and setup page')}`);
547
- process.exitCode = 1;
548
- return;
549
- }
550
- for (const profile of (await Promise.resolve().then(() => __importStar(require('./install')))).finishSetup())
551
- out(` Finishing setup: added one line to ${profile}`);
552
- out(ui.ok(`This machine is enrolled at ${ui.c.bold(url)}.`));
553
- out(` ${ui.c.dim('It can be revoked from Developers, Install and setup.')}`);
554
- }
555
- /**
556
- * Which workspace an email belongs to.
557
- *
558
- * Asked of the app root, which is tenant-agnostic by design and serves this
559
- * exact question for the browser sign in. Returns the workspace name, or null
560
- * when the product cannot place the address.
561
- */
562
- async function resolveWorkspace(email) {
563
- // ONE root, and it is production.
564
- //
565
- // This list used to put `http://localhost:8009` first whenever COMPRISM_DEV
566
- // was set. An environment variable exported once, in a shell profile or by a
567
- // test, then silently redirected every future sign in on that machine to a
568
- // port that is usually not listening. That is half of how a developer's own
569
- // machine came to be pointed at his laptop on 17 September 2026, reporting
570
- // that his account had no keys while four were stored and active.
571
- //
572
- // Working against a local server is still supported and is now something a
573
- // person SAYS rather than something an environment does to them:
574
- // `comprism login --organization localhost:8009`.
575
- // ASKED OF THE ONE SERVICE, at the product's own address.
576
- //
577
- // This used to post to the authentication route directly, which made the
578
- // lookup a second door the tool had to know about and knock on in the right
579
- // order. It is now an intent like every other, answered without a credential
580
- // because a person looking for their workspace does not have one yet.
581
- const root = `https://${WORKSPACE_DOMAIN}`;
582
- const reply = await (0, gateway_1.askAt)(root, { intent: 'resolve_workspace', prompt: email });
583
- if (!reply.ok || reply.served === false || reply.complete === false) {
584
- throw new Error(reply.message || 'Your organization could not be looked up. Try again later.');
585
- }
586
- const url = reply.session?.workspace_url;
587
- if (!url)
588
- return null;
589
- try {
590
- // The answer is a sign-in address. Its host is the workspace address.
591
- return new URL(url).host;
592
- }
593
- catch {
594
- return null;
595
- }
596
- }
597
- async function cmdLogin(args) {
598
- try {
599
- await runLogin(args);
600
- }
601
- finally {
602
- // Always, on every path. A reader left open holds the terminal and the
603
- // command appears to hang after it has finished its work.
604
- (0, prompt_1.closePrompt)();
605
- }
606
- }
@@ -1,3 +0,0 @@
1
- /** `comprism memory add` and the session word `remember`. */
2
- export declare function addNote(text: string): Promise<number>;
3
- export declare function cmdMemory(args: string[]): Promise<number>;