@andorra-labs/code 0.1.17 → 0.1.19

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 (313) hide show
  1. package/dist/src/account-jev-savings.d.ts +4 -0
  2. package/dist/src/account-jev-savings.js +92 -0
  3. package/dist/src/acp-agent.js +2 -2
  4. package/dist/src/agent-execution.js +441 -53
  5. package/dist/src/agent-mcp.js +7 -1
  6. package/dist/src/agent-modifiers.js +5 -7
  7. package/dist/src/analytics.d.ts +19 -1
  8. package/dist/src/analytics.js +9 -1
  9. package/dist/src/andorra/entry.js +15 -6
  10. package/dist/src/andorra/errors.js +3 -0
  11. package/dist/src/andorra/hosted.d.ts +8 -0
  12. package/dist/src/andorra/hosted.js +22 -3
  13. package/dist/src/andorra/streams.d.ts +49 -0
  14. package/dist/src/andorra/streams.js +98 -0
  15. package/dist/src/antigravity-acp.d.ts +28 -0
  16. package/dist/src/antigravity-acp.js +150 -0
  17. package/dist/src/antigravity-terminal.d.ts +2 -0
  18. package/dist/src/antigravity-terminal.js +214 -0
  19. package/dist/src/app-server/adaptive-routing-settings.d.ts +37 -0
  20. package/dist/src/app-server/adaptive-routing-settings.js +69 -0
  21. package/dist/src/app-server/artifact.d.ts +14 -0
  22. package/dist/src/app-server/artifact.js +46 -0
  23. package/dist/src/app-server/legal-protocol.d.ts +33 -0
  24. package/dist/src/app-server/legal-protocol.js +16 -0
  25. package/dist/src/app-server/protocol.d.ts +34 -3
  26. package/dist/src/app-server/protocol.js +3 -1
  27. package/dist/src/app-server/telemetry-protocol.d.ts +53 -0
  28. package/dist/src/app-server/telemetry-protocol.js +2 -0
  29. package/dist/src/app-server/telemetry.d.ts +38 -0
  30. package/dist/src/app-server/telemetry.js +163 -0
  31. package/dist/src/app-server/workspace.d.ts +21 -0
  32. package/dist/src/app-server/workspace.js +192 -10
  33. package/dist/src/app-server.d.ts +82 -26
  34. package/dist/src/app-server.js +1573 -417
  35. package/dist/src/attachments.d.ts +10 -0
  36. package/dist/src/attachments.js +102 -7
  37. package/dist/src/auth/AuthManager.d.ts +11 -2
  38. package/dist/src/auth/AuthManager.js +56 -13
  39. package/dist/src/auth/index.d.ts +5 -1
  40. package/dist/src/auth/index.js +8 -1
  41. package/dist/src/auth/lifecycle.d.ts +13 -0
  42. package/dist/src/auth/lifecycle.js +109 -0
  43. package/dist/src/auth/store.d.ts +1 -0
  44. package/dist/src/auth/store.js +12 -0
  45. package/dist/src/auth/types.d.ts +12 -0
  46. package/dist/src/automation-runner.js +2 -0
  47. package/dist/src/automation-service.js +7 -2
  48. package/dist/src/automation-tool.js +2 -1
  49. package/dist/src/benchmark-scores.d.ts +88 -0
  50. package/dist/src/benchmark-scores.js +302 -0
  51. package/dist/src/bridge/command.js +16 -1
  52. package/dist/src/bridge/control.d.ts +3 -1
  53. package/dist/src/bridge/control.js +9 -3
  54. package/dist/src/bridge/engines.d.ts +2 -0
  55. package/dist/src/bridge/engines.js +9 -0
  56. package/dist/src/bridge/github.d.ts +108 -0
  57. package/dist/src/bridge/github.js +378 -0
  58. package/dist/src/bridge/host-ops.d.ts +3 -3
  59. package/dist/src/bridge/host-ops.js +14 -2
  60. package/dist/src/bridge/host.d.ts +2 -0
  61. package/dist/src/bridge/host.js +70 -16
  62. package/dist/src/bridge/protocol.d.ts +1 -0
  63. package/dist/src/bridge/protocol.js +1 -0
  64. package/dist/src/browser-panel-tool.d.ts +12 -0
  65. package/dist/src/browser-panel-tool.js +30 -3
  66. package/dist/src/browser-runner.js +53 -62
  67. package/dist/src/browser-server.js +10 -4
  68. package/dist/src/browser-session.d.ts +14 -0
  69. package/dist/src/browser-session.js +57 -12
  70. package/dist/src/browser-view.d.ts +40 -1
  71. package/dist/src/browser-view.js +163 -9
  72. package/dist/src/browser-window-style.d.ts +27 -0
  73. package/dist/src/browser-window-style.js +244 -0
  74. package/dist/src/bug-report-attachments.d.ts +48 -0
  75. package/dist/src/bug-report-attachments.js +327 -0
  76. package/dist/src/bug-report.d.ts +23 -3
  77. package/dist/src/bug-report.js +72 -9
  78. package/dist/src/claude-provider.d.ts +1 -0
  79. package/dist/src/claude-provider.js +77 -36
  80. package/dist/src/cli.d.ts +1 -3
  81. package/dist/src/cli.js +245 -62
  82. package/dist/src/codex-provider.d.ts +1 -0
  83. package/dist/src/codex-provider.js +44 -8
  84. package/dist/src/coding-tools.d.ts +1 -0
  85. package/dist/src/coding-tools.js +28 -7
  86. package/dist/src/command-screens.d.ts +1 -1
  87. package/dist/src/command-screens.js +2 -2
  88. package/dist/src/commands.d.ts +9 -2
  89. package/dist/src/commands.js +69 -64
  90. package/dist/src/completion.js +13 -7
  91. package/dist/src/config.d.ts +14 -3
  92. package/dist/src/config.js +57 -17
  93. package/dist/src/context-budget.d.ts +11 -2
  94. package/dist/src/context-budget.js +38 -4
  95. package/dist/src/context-compaction.d.ts +10 -8
  96. package/dist/src/context-compaction.js +23 -24
  97. package/dist/src/deadline.js +1 -1
  98. package/dist/src/decision/DecisionEngine.d.ts +2 -0
  99. package/dist/src/decision/DecisionManager.d.ts +16 -0
  100. package/dist/src/decision/DecisionManager.js +75 -2
  101. package/dist/src/decision/applyTaskKind.d.ts +8 -0
  102. package/dist/src/decision/applyTaskKind.js +53 -0
  103. package/dist/src/decision/applyToolMenu.js +6 -2
  104. package/dist/src/decision/hostedPolicy.js +6 -3
  105. package/dist/src/decision/optimizationPolicy.d.ts +10 -0
  106. package/dist/src/decision/optimizationPolicy.js +23 -3
  107. package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +4 -1
  108. package/dist/src/decision/providers/AndorraDecisionProvider.js +29 -7
  109. package/dist/src/decision/providers/index.js +1 -1
  110. package/dist/src/decision/taskKind.d.ts +52 -0
  111. package/dist/src/decision/taskKind.js +76 -0
  112. package/dist/src/decision/toolFamilies.js +1 -1
  113. package/dist/src/decision/types.d.ts +3 -1
  114. package/dist/src/default-graph.js +1 -1
  115. package/dist/src/efficiency.d.ts +80 -1
  116. package/dist/src/efficiency.js +119 -4
  117. package/dist/src/effort-routing.d.ts +27 -0
  118. package/dist/src/effort-routing.js +34 -0
  119. package/dist/src/evidence.d.ts +110 -0
  120. package/dist/src/evidence.js +195 -0
  121. package/dist/src/extensions.d.ts +2 -0
  122. package/dist/src/extensions.js +30 -20
  123. package/dist/src/github-app/agent-writes.d.ts +1 -1
  124. package/dist/src/github-app/agent-writes.js +1 -1
  125. package/dist/src/github-app/client.d.ts +19 -0
  126. package/dist/src/github-app/client.js +21 -1
  127. package/dist/src/github-app/event-source.d.ts +0 -5
  128. package/dist/src/github-app/event-source.js +1 -31
  129. package/dist/src/github-app/metrics.d.ts +2 -5
  130. package/dist/src/github-app/metrics.js +2 -14
  131. package/dist/src/github-app/review-loop.d.ts +5 -5
  132. package/dist/src/github-app/review-loop.js +1 -1
  133. package/dist/src/github-app/review-node.d.ts +2 -2
  134. package/dist/src/github-app/triggers.d.ts +3 -3
  135. package/dist/src/github-names.d.ts +7 -0
  136. package/dist/src/github-names.js +7 -0
  137. package/dist/src/glob-search.d.ts +1 -0
  138. package/dist/src/glob-search.js +3 -0
  139. package/dist/src/google-provider.d.ts +5 -28
  140. package/dist/src/google-provider.js +6 -141
  141. package/dist/src/graph-editor-session.d.ts +1 -0
  142. package/dist/src/graph-editor-session.js +2 -0
  143. package/dist/src/graph-health.js +3 -1
  144. package/dist/src/graph-preview.d.ts +2 -0
  145. package/dist/src/graph-preview.js +1 -0
  146. package/dist/src/graph-runner.js +20 -14
  147. package/dist/src/graph-selection.d.ts +3 -1
  148. package/dist/src/graph-selection.js +2 -2
  149. package/dist/src/graph-server.d.ts +8 -1
  150. package/dist/src/graph-server.js +49 -12
  151. package/dist/src/graph-sync.d.ts +2 -1
  152. package/dist/src/graph-sync.js +13 -0
  153. package/dist/src/graph-ui/app.js +49 -8
  154. package/dist/src/graph-ui/index.html +1 -1
  155. package/dist/src/graphs.d.ts +23 -1
  156. package/dist/src/graphs.js +58 -7
  157. package/dist/src/grok-provider.js +17 -14
  158. package/dist/src/hardened-runtime.js +39 -25
  159. package/dist/src/jev-savings.d.ts +4 -0
  160. package/dist/src/jev-savings.js +13 -0
  161. package/dist/src/legal/client.d.ts +25 -0
  162. package/dist/src/legal/client.js +47 -0
  163. package/dist/src/legal/command.d.ts +13 -0
  164. package/dist/src/legal/command.js +98 -0
  165. package/dist/src/legal/documents.d.ts +2 -0
  166. package/dist/src/legal/documents.js +14 -0
  167. package/dist/src/legal/gate.d.ts +13 -0
  168. package/dist/src/legal/gate.js +96 -0
  169. package/dist/src/legal/manifest.d.ts +21 -0
  170. package/dist/src/legal/manifest.js +23 -0
  171. package/dist/src/legal/receipt.d.ts +13 -0
  172. package/dist/src/legal/receipt.js +137 -0
  173. package/dist/src/legal/release.d.ts +27 -0
  174. package/dist/src/legal/release.js +28 -0
  175. package/dist/src/managed-sign-in.d.ts +0 -1
  176. package/dist/src/managed-sign-in.js +0 -13
  177. package/dist/src/membership.d.ts +27 -1
  178. package/dist/src/membership.js +139 -7
  179. package/dist/src/model-health-cache.js +1 -1
  180. package/dist/src/model-metadata.js +3 -7
  181. package/dist/src/model-override.d.ts +2 -1
  182. package/dist/src/model-override.js +9 -0
  183. package/dist/src/model-pool.d.ts +99 -0
  184. package/dist/src/model-pool.js +136 -0
  185. package/dist/src/model-relay/local.js +5 -0
  186. package/dist/src/model-relay/remote.d.ts +2 -0
  187. package/dist/src/model-relay/remote.js +4 -0
  188. package/dist/src/model-tiers.d.ts +16 -1
  189. package/dist/src/model-tiers.js +31 -7
  190. package/dist/src/opencode-cli-provider.js +59 -56
  191. package/dist/src/opencode-provider.js +16 -13
  192. package/dist/src/permissions.d.ts +5 -0
  193. package/dist/src/permissions.js +7 -0
  194. package/dist/src/plan-pass.js +2 -1
  195. package/dist/src/pool-scores.d.ts +45 -0
  196. package/dist/src/pool-scores.js +40 -0
  197. package/dist/src/provider-connection.js +3 -17
  198. package/dist/src/provider-engine.d.ts +13 -1
  199. package/dist/src/provider-engine.js +116 -12
  200. package/dist/src/provider-request-error.d.ts +8 -0
  201. package/dist/src/provider-request-error.js +12 -0
  202. package/dist/src/provider-settings.d.ts +1 -1
  203. package/dist/src/provider-settings.js +36 -18
  204. package/dist/src/provider-turn-deadline.d.ts +39 -0
  205. package/dist/src/provider-turn-deadline.js +139 -0
  206. package/dist/src/providers.d.ts +8 -9
  207. package/dist/src/providers.js +211 -150
  208. package/dist/src/pull-request-merge.d.ts +1 -8
  209. package/dist/src/pull-request-merge.js +0 -4
  210. package/dist/src/pull-requests.d.ts +83 -57
  211. package/dist/src/pull-requests.js +266 -225
  212. package/dist/src/qa/runtime/ProcessManager.d.ts +5 -1
  213. package/dist/src/qa/runtime/ProcessManager.js +9 -3
  214. package/dist/src/react-runtime.js +245 -71
  215. package/dist/src/reasoning-probe-cloud.d.ts +10 -0
  216. package/dist/src/reasoning-probe-cloud.js +209 -0
  217. package/dist/src/remote/engine-pool.d.ts +3 -0
  218. package/dist/src/remote/engine-pool.js +88 -21
  219. package/dist/src/remote/recovery.d.ts +6 -0
  220. package/dist/src/remote/recovery.js +37 -0
  221. package/dist/src/run-records.d.ts +13 -3
  222. package/dist/src/run-records.js +59 -34
  223. package/dist/src/runtime.d.ts +47 -2
  224. package/dist/src/runtime.js +33 -7
  225. package/dist/src/session-summary.d.ts +8 -0
  226. package/dist/src/session-summary.js +34 -0
  227. package/dist/src/sessions.d.ts +32 -0
  228. package/dist/src/sessions.js +65 -3
  229. package/dist/src/shell.js +6 -0
  230. package/dist/src/side-panel.js +36 -2
  231. package/dist/src/sign-in-detection.d.ts +1 -1
  232. package/dist/src/sign-in-detection.js +4 -10
  233. package/dist/src/sign-in-offer.js +1 -1
  234. package/dist/src/skill-commands.js +1 -1
  235. package/dist/src/skills/bundled/bug-report/SKILL.md +51 -7
  236. package/dist/src/skills/bundled/graph-manager/SKILL.md +2 -2
  237. package/dist/src/skills/bundled/graph-manager/patterns.md +13 -19
  238. package/dist/src/skills/bundled/provenance.json +3 -3
  239. package/dist/src/subagent-run.js +50 -50
  240. package/dist/src/subscription-usage.d.ts +50 -0
  241. package/dist/src/subscription-usage.js +92 -0
  242. package/dist/src/task-checkout.d.ts +157 -0
  243. package/dist/src/task-checkout.js +628 -0
  244. package/dist/src/telemetry/access.d.ts +18 -0
  245. package/dist/src/telemetry/access.js +43 -0
  246. package/dist/src/telemetry/aggregate.d.ts +18 -2
  247. package/dist/src/telemetry/aggregate.js +22 -9
  248. package/dist/src/telemetry/capture-core.d.ts +33 -14
  249. package/dist/src/telemetry/capture-core.js +124 -25
  250. package/dist/src/telemetry/capture.d.ts +3 -2
  251. package/dist/src/telemetry/capture.js +21 -1
  252. package/dist/src/telemetry/decision-capture.js +4 -0
  253. package/dist/src/telemetry/emitter.d.ts +6 -7
  254. package/dist/src/telemetry/emitter.js +124 -29
  255. package/dist/src/telemetry/gate.d.ts +41 -2
  256. package/dist/src/telemetry/gate.js +89 -4
  257. package/dist/src/telemetry/home.d.ts +1 -0
  258. package/dist/src/telemetry/home.js +20 -0
  259. package/dist/src/telemetry/identity.d.ts +6 -3
  260. package/dist/src/telemetry/identity.js +19 -6
  261. package/dist/src/telemetry/lifecycle.d.ts +8 -0
  262. package/dist/src/telemetry/lifecycle.js +76 -0
  263. package/dist/src/telemetry/outbox.d.ts +13 -8
  264. package/dist/src/telemetry/outbox.js +68 -12
  265. package/dist/src/telemetry/permission-command.d.ts +38 -0
  266. package/dist/src/telemetry/permission-command.js +208 -0
  267. package/dist/src/telemetry/permission.d.ts +168 -0
  268. package/dist/src/telemetry/permission.js +662 -0
  269. package/dist/src/telemetry/record-installation.d.ts +1 -0
  270. package/dist/src/telemetry/record-installation.js +9 -0
  271. package/dist/src/telemetry/region-data.d.ts +12 -0
  272. package/dist/src/telemetry/region-data.js +1314 -0
  273. package/dist/src/telemetry/region.d.ts +34 -0
  274. package/dist/src/telemetry/region.js +87 -0
  275. package/dist/src/telemetry/run-privacy.d.ts +11 -0
  276. package/dist/src/telemetry/run-privacy.js +165 -0
  277. package/dist/src/telemetry/schema.d.ts +27 -6
  278. package/dist/src/telemetry/schema.js +109 -14
  279. package/dist/src/telemetry/state.d.ts +11 -7
  280. package/dist/src/telemetry/state.js +39 -6
  281. package/dist/src/telemetry/surface.d.ts +20 -3
  282. package/dist/src/telemetry/surface.js +71 -15
  283. package/dist/src/telemetry/uploader.d.ts +6 -11
  284. package/dist/src/telemetry/uploader.js +72 -46
  285. package/dist/src/telemetry/uploads.d.ts +5 -1
  286. package/dist/src/telemetry/uploads.js +25 -6
  287. package/dist/src/telemetry/version.d.ts +5 -0
  288. package/dist/src/telemetry/version.js +34 -0
  289. package/dist/src/telemetry/workspace.d.ts +4 -1
  290. package/dist/src/telemetry/workspace.js +18 -3
  291. package/dist/src/terminal-ui.d.ts +3 -0
  292. package/dist/src/terminal-ui.js +48 -6
  293. package/dist/src/test-edit-guard.d.ts +30 -0
  294. package/dist/src/test-edit-guard.js +167 -2
  295. package/dist/src/thinking-level-detect.d.ts +13 -0
  296. package/dist/src/thinking-level-detect.js +52 -0
  297. package/dist/src/thinking-levels.d.ts +30 -0
  298. package/dist/src/thinking-levels.js +131 -0
  299. package/dist/src/timers.d.ts +3 -0
  300. package/dist/src/todos.d.ts +2 -1
  301. package/dist/src/todos.js +24 -4
  302. package/dist/src/tool-argument-coercion.d.ts +7 -0
  303. package/dist/src/tool-argument-coercion.js +49 -0
  304. package/dist/src/tool-catalog.d.ts +2 -2
  305. package/dist/src/tool-catalog.js +1 -1
  306. package/dist/src/tools.js +67 -22
  307. package/dist/src/transcript.js +3 -2
  308. package/dist/src/types.d.ts +48 -1
  309. package/dist/src/update.js +4 -0
  310. package/dist/src/usage-analytics.d.ts +7 -0
  311. package/dist/src/usage-analytics.js +85 -13
  312. package/dist/telemetry-consent-v1 +1 -0
  313. package/package.json +97 -96
@@ -11,6 +11,14 @@ export type PendingAttachment = {
11
11
  } | {
12
12
  kind: 'file';
13
13
  path: string;
14
+ } | {
15
+ kind: 'upload';
16
+ name: string;
17
+ dataBase64: string;
18
+ } | {
19
+ kind: 'stored-file';
20
+ name: string;
21
+ spoolId: string;
14
22
  };
15
23
  export interface UserAttachmentRef {
16
24
  id: string;
@@ -61,4 +69,6 @@ export declare function parseAppleScriptHex(text: string): string;
61
69
  export declare function readClipboardImage(): Promise<Buffer | undefined>;
62
70
  export declare function writeClipboardText(text: string): Promise<void>;
63
71
  export declare function parsePendingAttachments(value: unknown): PendingAttachment[];
72
+ /** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
73
+ export declare function cloudAttachments(value: unknown): Promise<PendingAttachment[]>;
64
74
  export declare function defaultAttachmentsHome(): string;
@@ -1,12 +1,13 @@
1
1
  import { execFile } from 'node:child_process';
2
- import { existsSync, statSync } from 'node:fs';
3
- import { mkdir, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
2
+ import { constants, existsSync, statSync } from 'node:fs';
3
+ import { mkdir, open, readFile, readdir, realpath, rm, rename, stat, writeFile } from 'node:fs/promises';
4
4
  import { homedir } from 'node:os';
5
5
  import { join, relative, resolve, basename, dirname, isAbsolute, sep } from 'node:path';
6
6
  import { randomUUID } from 'node:crypto';
7
7
  export const MAX_ATTACHMENTS = 10;
8
8
  export const MAX_TEXT_ATTACHMENT_CHARS = 1_000_000;
9
9
  export const MAX_IMAGE_ATTACHMENT_BYTES = 5 * 1024 * 1024;
10
+ const MAX_CLOUD_ATTACHMENT_WIRE_BYTES = 12 * 1024 * 1024;
10
11
  export const PASTE_ATTACH_LINES = 24;
11
12
  export const PASTE_ATTACH_CHARS = 2_000;
12
13
  const MAX_PATH_PASTE_LINES = 8;
@@ -78,6 +79,8 @@ export function attachmentLabel(pending) {
78
79
  return pending.path;
79
80
  }
80
81
  }
82
+ if (pending.kind === 'upload' || pending.kind === 'stored-file')
83
+ return pending.name;
81
84
  if (pending.kind === 'image') {
82
85
  const bytes = Math.floor(pending.dataBase64.length * 3 / 4);
83
86
  return `${pending.name ?? 'clipboard.png'} (${formatBytes(bytes)})`;
@@ -132,6 +135,14 @@ export async function resolveAttachments(home, workspace, pendings, createdSpool
132
135
  refs.push({ id, kind: 'image', name, path, bytes: data.length, mimeType: pending.mimeType });
133
136
  images.push({ mimeType: pending.mimeType, data: data.toString('base64') });
134
137
  }
138
+ else if (pending.kind === 'upload' || pending.kind === 'stored-file') {
139
+ const data = pending.kind === 'upload' ? Buffer.from(pending.dataBase64, 'base64') : await readStoredAttachment(home, pending);
140
+ const name = sanitizeName(pending.name, 'attachment');
141
+ const { id, path } = await spool(home, name, file => writeFile(file, data, { mode: 0o600 }));
142
+ spooled.push({ path });
143
+ createdSpools?.push(dirname(path));
144
+ refs.push({ id, kind: 'file', name, path, bytes: data.length });
145
+ }
135
146
  else {
136
147
  const path = resolve(pending.path);
137
148
  const info = await stat(path).catch(() => undefined);
@@ -172,15 +183,24 @@ export function attachmentReferenceBlock(refs, options = {}) {
172
183
  }
173
184
  const SPOOL_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
174
185
  export async function attachmentReadRoots(home, refs) {
186
+ if (refs.length === 0)
187
+ return [];
175
188
  const base = attachmentsDirectory(home);
189
+ const canonicalBase = await realpath(base).catch(() => undefined);
190
+ if (canonicalBase === undefined)
191
+ return [];
176
192
  const roots = new Set();
177
193
  for (const ref of refs) {
178
- if (ref.kind === 'file')
179
- continue;
180
194
  const directory = dirname(ref.path);
181
- if (!SPOOL_ID.test(basename(directory)) || !pathInside(directory, base))
195
+ const spoolId = basename(directory);
196
+ if (!SPOOL_ID.test(spoolId) || relative(base, directory) !== spoolId)
197
+ continue;
198
+ // Uploaded files use the spool id as their ref id. Ordinary path attachments have independent ids.
199
+ if (ref.kind === 'file' && (ref.directory || ref.id !== spoolId))
182
200
  continue;
183
- roots.add(await realpath(directory).catch(() => directory));
201
+ const canonicalDirectory = await realpath(directory).catch(() => undefined);
202
+ if (canonicalDirectory !== undefined && relative(canonicalBase, canonicalDirectory) === spoolId)
203
+ roots.add(canonicalDirectory);
184
204
  }
185
205
  return [...roots];
186
206
  }
@@ -334,13 +354,88 @@ export function parsePendingAttachments(value) {
334
354
  throw new Error(`attachments[${index}] exceeds the ${formatBytes(MAX_IMAGE_ATTACHMENT_BYTES)} image limit`);
335
355
  return { kind: 'image', ...(name === undefined ? {} : { name }), mimeType: record.mimeType, dataBase64: record.dataBase64 };
336
356
  }
357
+ if (record.kind === 'stored-file') {
358
+ if (name === undefined || !validStoredAttachment(record.spoolId, name))
359
+ throw new Error(`attachments[${index}] must identify a stored attachment`);
360
+ return { kind: 'stored-file', name, spoolId: record.spoolId };
361
+ }
362
+ if (record.kind === 'upload') {
363
+ if (!name || typeof record.dataBase64 !== 'string' || record.dataBase64.length > Math.ceil(MAX_IMAGE_ATTACHMENT_BYTES / 3) * 4) {
364
+ throw new Error(`attachments[${index}] must be a named file up to 5 MB`);
365
+ }
366
+ const data = Buffer.from(record.dataBase64, 'base64');
367
+ if (data.length > MAX_IMAGE_ATTACHMENT_BYTES || data.toString('base64') !== record.dataBase64) {
368
+ throw new Error(`attachments[${index}] has invalid file data`);
369
+ }
370
+ return { kind: 'upload', name, dataBase64: record.dataBase64 };
371
+ }
337
372
  if (record.kind === 'file') {
338
373
  if (typeof record.path !== 'string' || !record.path.trim())
339
374
  throw new Error(`attachments[${index}].path must be a filesystem path`);
340
375
  return { kind: 'file', path: record.path };
341
376
  }
342
- throw new Error(`attachments[${index}].kind must be text, image, or file`);
377
+ throw new Error(`attachments[${index}].kind must be text, image, file, upload, or stored-file`);
343
378
  });
344
379
  }
380
+ /** Turn desktop paths into attachment data before the request crosses the Cloud relay. */
381
+ export async function cloudAttachments(value) {
382
+ const attachments = [];
383
+ let bytes = 2;
384
+ for (const pending of parsePendingAttachments(value)) {
385
+ let attachment = pending;
386
+ if (pending.kind === 'file') {
387
+ const name = basename(pending.path);
388
+ const data = await readAttachmentFile(pending.path, name);
389
+ const mimeType = imageSignatureMime(data);
390
+ const dataBase64 = data.toString('base64');
391
+ attachment = mimeType === undefined ? { kind: 'upload', name, dataBase64 } : { kind: 'image', name, mimeType, dataBase64 };
392
+ }
393
+ bytes += Buffer.byteLength(JSON.stringify(attachment)) + 1;
394
+ if (bytes > MAX_CLOUD_ATTACHMENT_WIRE_BYTES)
395
+ throw new Error('These attachments exceed the combined Cloud transfer limit. Send fewer attachments at a time.');
396
+ attachments.push(attachment);
397
+ }
398
+ return attachments;
399
+ }
400
+ function validStoredAttachment(spoolId, name) {
401
+ return typeof spoolId === 'string' && SPOOL_ID.test(spoolId) && name !== '' && sanitizeName(name, '') === name;
402
+ }
403
+ /** Resolve a returned attachment on the engine that created its spool, using its id and name only. */
404
+ async function readStoredAttachment(home, pending) {
405
+ const { name, spoolId } = pending;
406
+ if (!validStoredAttachment(spoolId, name))
407
+ throw new Error('Invalid stored attachment reference.');
408
+ const base = await realpath(attachmentsDirectory(home)).catch(() => undefined);
409
+ const entry = base === undefined ? undefined : await realpath(join(base, spoolId, name)).catch(() => undefined);
410
+ if (base === undefined || entry === undefined || relative(base, entry) !== join(spoolId, name)) {
411
+ throw new Error(`Attachment ${name} is no longer available on Cloud. Attach it again to resend.`);
412
+ }
413
+ return readAttachmentFile(entry, name);
414
+ }
415
+ async function readAttachmentFile(path, name) {
416
+ const file = await open(path, constants.O_RDONLY | constants.O_NONBLOCK)
417
+ .catch(() => { throw new Error(`Could not open attachment ${name}.`); });
418
+ try {
419
+ const info = await file.stat();
420
+ if (!info.isFile())
421
+ throw new Error(`Attach individual files to Cloud. ${name} is not a regular file.`);
422
+ if (info.size > MAX_IMAGE_ATTACHMENT_BYTES)
423
+ throw new Error(`${name} exceeds the 5 MB Cloud file limit.`);
424
+ const buffer = Buffer.alloc(info.size + 1);
425
+ let length = 0;
426
+ while (length < buffer.length) {
427
+ const { bytesRead } = await file.read(buffer, length, buffer.length - length, length);
428
+ if (bytesRead === 0)
429
+ break;
430
+ length += bytesRead;
431
+ }
432
+ if (length !== info.size)
433
+ throw new Error(`${name} changed while it was being attached. Try again.`);
434
+ return buffer.subarray(0, length);
435
+ }
436
+ finally {
437
+ await file.close();
438
+ }
439
+ }
345
440
  const throwName = (index) => { throw new Error(`attachments[${index}].name must be a string`); };
346
441
  export function defaultAttachmentsHome() { return process.env.ANDORRACODE_HOME || join(homedir(), '.andorracode'); }
@@ -1,4 +1,4 @@
1
- import { AuthError, type AuthConfiguration, type AuthStatus, type CredentialStore } from './types.js';
1
+ import { AuthError, type AuthConfiguration, type AuthStatus, type AuthState, type CredentialStore } from './types.js';
2
2
  import { type CredentialJournal } from './store.js';
3
3
  export interface OtherSignIn {
4
4
  read(): Promise<string | undefined>;
@@ -14,12 +14,15 @@ export declare class AuthManager {
14
14
  private readonly store;
15
15
  private readonly fetch;
16
16
  private readonly keys;
17
+ private readonly lifecycle;
18
+ private readonly identity;
17
19
  private readonly journal?;
18
20
  private unsaved?;
19
21
  private unsavedIsShared;
20
22
  private unsavedRetires;
21
23
  constructor(options: {
22
24
  config: AuthConfiguration;
25
+ home?: string;
23
26
  store?: CredentialStore;
24
27
  journal?: CredentialJournal;
25
28
  fetch?: typeof fetch;
@@ -69,5 +72,11 @@ export declare class AuthManager {
69
72
  token: string;
70
73
  subject: string;
71
74
  }>;
72
- status(signal?: AbortSignal): Promise<AuthStatus>;
75
+ /** Necessary auth lifecycle state, not an analytics preference. Outages never manufacture logout. */
76
+ deliberatelySignedOut(signal?: AbortSignal): Promise<boolean>;
77
+ /** No network, preference or recovery writes. Legacy empty stores are known signed out, too. */
78
+ state(signal?: AbortSignal): Promise<AuthState>;
79
+ status(signal?: AbortSignal, options?: {
80
+ readOnly?: boolean;
81
+ }): Promise<AuthStatus>;
73
82
  }
@@ -1,8 +1,10 @@
1
1
  import { randomBytes, randomUUID, createHash, timingSafeEqual } from 'node:crypto';
2
- import { resolve } from 'node:path';
2
+ import { join, resolve } from 'node:path';
3
+ import { homedir } from 'node:os';
3
4
  import { createRemoteJWKSet, customFetch, jwtVerify } from 'jose';
4
5
  import { AuthError } from './types.js';
5
6
  import { createCredentialJournal, createCredentialStore, credentialScope, KeyringAbsentError, KeyringCredentialStore, keyringScopes } from './store.js';
7
+ import { AuthLifecycle } from './lifecycle.js';
6
8
  import { withAuthLock } from './lock.js';
7
9
  import { browserUnavailableReason, openBrowser, receiveAuthorizationCode } from './callback.js';
8
10
  const tokenDigest = (token) => token === undefined ? '' : createHash('sha256').update(token).digest('hex');
@@ -110,6 +112,8 @@ export class AuthManager {
110
112
  store;
111
113
  fetch;
112
114
  keys;
115
+ lifecycle;
116
+ identity;
113
117
  journal;
114
118
  unsaved;
115
119
  unsavedIsShared = false;
@@ -118,15 +122,20 @@ export class AuthManager {
118
122
  this.options = options;
119
123
  validateAuthConfiguration(options.config);
120
124
  this.config = { ...options.config };
121
- this.store = options.store ?? createCredentialStore(credentialIdentity(this.config));
122
- this.journal = options.journal ?? (options.store ? undefined : createCredentialJournal(credentialIdentity(this.config)));
125
+ const defaultHome = process.env.ANDORRACODE_HOME || join(homedir(), '.andorracode');
126
+ const home = options.home ?? defaultHome;
127
+ const environment = resolve(home) === resolve(defaultHome) ? process.env : { ...process.env, ANDORRACODE_HOME: home };
128
+ this.identity = credentialIdentity(this.config, environment);
129
+ this.store = options.store ?? createCredentialStore(this.identity, environment);
130
+ this.lifecycle = new AuthLifecycle(home, credentialScope(this.identity));
131
+ this.journal = options.journal ?? (options.store ? undefined : createCredentialJournal(this.identity, environment));
123
132
  this.fetch = options.fetch ?? globalThis.fetch;
124
133
  this.keys = createRemoteJWKSet(new URL(`${this.config.issuer}/.well-known/jwks.json`), { timeoutDuration: 5000, [customFetch]: (url, init) => this.fetch(url, init) });
125
134
  }
126
135
  locked(operation, signal) { return withAuthLock(operation, signal, this.options.lockPort, AUTH_LOCK_WAIT_MS); }
127
- async read() {
128
- const text = await this.store.read();
129
- if (!text)
136
+ async read(forState = false) {
137
+ const text = await (forState && this.store.readForState ? this.store.readForState() : this.store.read());
138
+ if (text === undefined)
130
139
  return { version: 1, generation: randomUUID() };
131
140
  try {
132
141
  const value = JSON.parse(text);
@@ -275,6 +284,9 @@ export class AuthManager {
275
284
  }
276
285
  replacedToken = current.session?.refreshToken;
277
286
  await this.forget();
287
+ // Commit/rollback is settled before retiring logout state. Cleanup failure must not revoke
288
+ // the newly committed token; a stale marker has no authority beside a usable session.
289
+ await this.lifecycle.retire().catch(() => { });
278
290
  }, signal);
279
291
  }
280
292
  catch (error) {
@@ -317,7 +329,8 @@ export class AuthManager {
317
329
  throw new AuthError('cancelled', 'Authentication cancelled.');
318
330
  const journalled = (await this.journalled())?.session.refreshToken;
319
331
  const unsaved = this.unsaved?.session.refreshToken;
320
- await this.store.clear(JSON.stringify({ version: 1, generation: randomUUID() }));
332
+ const generation = randomUUID();
333
+ await this.store.clear(JSON.stringify({ version: 1, generation, deliberateSignOut: true }));
321
334
  this.unsaved = undefined;
322
335
  let cleanup;
323
336
  try {
@@ -327,11 +340,17 @@ export class AuthManager {
327
340
  cleanup = error;
328
341
  }
329
342
  const own = [...new Set([token, previous, journalled, unsaved].filter((value) => Boolean(value)))];
343
+ try {
344
+ await this.lifecycle.recordSignOut(generation);
345
+ }
346
+ catch (error) {
347
+ cleanup ??= error;
348
+ }
330
349
  if (!options.everywhere)
331
350
  return { own, cleanup };
332
351
  let others;
333
352
  try {
334
- others = await abortable((this.options.otherSignIns ?? otherKeyringSignIns)(credentialScope(credentialIdentity(this.config))), signal);
353
+ others = await abortable((this.options.otherSignIns ?? otherKeyringSignIns)(credentialScope(this.identity)), signal);
335
354
  }
336
355
  catch (failure) {
337
356
  if (signal?.aborted || (failure instanceof AuthError && failure.code === 'cancelled'))
@@ -467,10 +486,10 @@ export class AuthManager {
467
486
  await persist(next);
468
487
  return next;
469
488
  }
470
- async current(signal) {
489
+ async current(signal, persist = true, forState = false) {
471
490
  let stored;
472
491
  try {
473
- stored = await abortable(this.read(), signal);
492
+ stored = await abortable(this.read(forState), signal);
474
493
  }
475
494
  catch (error) {
476
495
  if (signal?.aborted || !(error instanceof AuthError && error.code === 'storage') || !(await this.pending()))
@@ -480,10 +499,13 @@ export class AuthManager {
480
499
  if (!pending)
481
500
  return stored;
482
501
  if (stored && (stored.generation !== pending.generation || tokenDigest(stored.session?.refreshToken) !== pending.replaces)) {
483
- await this.forget();
502
+ if (persist)
503
+ await this.forget();
484
504
  return stored;
485
505
  }
486
506
  const recovered = { version: 1, generation: pending.generation, session: pending.session };
507
+ if (!persist)
508
+ return recovered; // Display-only reads must never repair credential storage.
487
509
  try {
488
510
  await this.store.write(JSON.stringify(recovered));
489
511
  await this.forget();
@@ -594,7 +616,28 @@ export class AuthManager {
594
616
  async credential(signal) {
595
617
  return this.locked(() => this.tokenAndSubject(signal), signal);
596
618
  }
597
- async status(signal) {
598
- return this.locked(async () => { const session = (await this.current(signal)).session; return session && session.refreshExpiresAt > Date.now() ? { signedIn: true, subject: session.subject, expiresAt: session.expiresAt } : { signedIn: false }; }, signal);
619
+ /** Necessary auth lifecycle state, not an analytics preference. Outages never manufacture logout. */
620
+ async deliberatelySignedOut(signal) {
621
+ return this.locked(async () => { const value = await this.current(signal, false, true); return !value.session && (value.deliberateSignOut === true || await abortable(this.lifecycle.signedOut(), signal)); }, signal);
622
+ }
623
+ /** No network, preference or recovery writes. Legacy empty stores are known signed out, too. */
624
+ async state(signal) {
625
+ try {
626
+ return await this.locked(async () => {
627
+ const value = await this.current(signal, false, true);
628
+ if (value.session && value.session.refreshExpiresAt > Date.now())
629
+ return { state: 'signed-in', subject: value.session.subject };
630
+ const deliberate = value.deliberateSignOut === true || await abortable(this.lifecycle.signedOut(), signal);
631
+ return { state: 'signed-out', deliberate };
632
+ }, signal);
633
+ }
634
+ catch (error) {
635
+ if (signal?.aborted || (error instanceof AuthError && error.code === 'cancelled'))
636
+ throw error;
637
+ return { state: 'unavailable' };
638
+ }
639
+ }
640
+ async status(signal, options = {}) {
641
+ return this.locked(async () => { const session = (await this.current(signal, !options.readOnly)).session; return session && session.refreshExpiresAt > Date.now() ? { signedIn: true, subject: session.subject, expiresAt: session.expiresAt } : { signedIn: false }; }, signal);
599
642
  }
600
643
  }
@@ -21,4 +21,8 @@ export declare const getCredential: (signal?: AbortSignal) => Promise<{
21
21
  token: string;
22
22
  subject: string;
23
23
  }>;
24
- export declare const getAuthStatus: (signal?: AbortSignal) => Promise<import("./types.js").AuthStatus>;
24
+ export declare const wasDeliberatelySignedOut: () => Promise<boolean>;
25
+ export declare const getAuthState: (signal?: AbortSignal, home?: string) => Promise<import("./types.js").AuthState>;
26
+ export declare const getAuthStatus: (signal?: AbortSignal, options?: {
27
+ readOnly?: boolean;
28
+ }) => Promise<import("./types.js").AuthStatus>;
@@ -1,5 +1,7 @@
1
1
  import { AUTH_DEPLOYMENT } from './deployment.js';
2
2
  import { AuthManager } from './AuthManager.js';
3
+ import { resolve, join } from 'node:path';
4
+ import { homedir } from 'node:os';
3
5
  export * from './types.js';
4
6
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
7
  export { credentialIdentity } from './AuthManager.js';
@@ -13,4 +15,9 @@ export const login = (options = {}) => auth().login(options);
13
15
  export const logout = (signal, options) => auth().logout(signal, options);
14
16
  export const getAccessToken = (signal) => auth().getAccessToken(signal);
15
17
  export const getCredential = (signal) => auth().credential(signal);
16
- export const getAuthStatus = (signal) => auth().status(signal);
18
+ export const wasDeliberatelySignedOut = () => auth().deliberatelySignedOut();
19
+ export const getAuthState = (signal, home) => {
20
+ const currentHome = process.env.ANDORRACODE_HOME || join(homedir(), '.andorracode');
21
+ return (!home || resolve(home) === resolve(currentHome) ? auth() : new AuthManager({ config: getAuthConfiguration(), home })).state(signal);
22
+ };
23
+ export const getAuthStatus = (signal, options) => auth().status(signal, options);
@@ -0,0 +1,13 @@
1
+ /** Non-secret state, independent of the keyring's deliberately ephemeral token-free envelope.
2
+ * All mutations run inside AuthManager's existing cross-process lifecycle lock. The configured
3
+ * root may itself be a link; entries below it must be private, owned and never links. */
4
+ export declare class AuthLifecycle {
5
+ private readonly home;
6
+ private readonly scope;
7
+ constructor(home: string, scope: string);
8
+ private path;
9
+ private privateOwner;
10
+ signedOut(): Promise<boolean>;
11
+ recordSignOut(generation: string): Promise<void>;
12
+ retire(): Promise<void>;
13
+ }
@@ -0,0 +1,109 @@
1
+ import { constants } from 'node:fs';
2
+ import { lstat, mkdir, open, rename, unlink } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { randomUUID } from 'node:crypto';
5
+ import { AuthError } from './types.js';
6
+ /** Non-secret state, independent of the keyring's deliberately ephemeral token-free envelope.
7
+ * All mutations run inside AuthManager's existing cross-process lifecycle lock. The configured
8
+ * root may itself be a link; entries below it must be private, owned and never links. */
9
+ export class AuthLifecycle {
10
+ home;
11
+ scope;
12
+ constructor(home, scope) {
13
+ this.home = home;
14
+ this.scope = scope;
15
+ }
16
+ async path(create = false) {
17
+ if (create)
18
+ await mkdir(this.home, { recursive: true, mode: 0o700 });
19
+ const directory = join(this.home, 'auth');
20
+ if (create)
21
+ await mkdir(directory, { mode: 0o700 }).catch(error => { if (error.code !== 'EEXIST')
22
+ throw error; });
23
+ const info = await lstat(directory);
24
+ if (!info.isDirectory() || info.isSymbolicLink() || !this.privateOwner(info))
25
+ throw new Error('Unsafe auth lifecycle directory');
26
+ return join(directory, `signed-out-${this.scope}.json`);
27
+ }
28
+ privateOwner(info) {
29
+ return process.platform === 'win32' || ((info.mode & 0o077) === 0 && (!process.getuid || info.uid === process.getuid()));
30
+ }
31
+ async signedOut() {
32
+ try {
33
+ const path = await this.path();
34
+ const entry = await lstat(path);
35
+ if (!entry.isFile() || entry.isSymbolicLink())
36
+ throw new Error('Unsafe auth lifecycle entry');
37
+ const file = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0));
38
+ try {
39
+ const info = await file.stat();
40
+ if (!info.isFile() || !this.privateOwner(info) || info.size > 1024)
41
+ throw new Error('Invalid auth lifecycle entry');
42
+ const buffer = Buffer.alloc(1025);
43
+ let bytesRead = 0;
44
+ for (;;) {
45
+ const part = await file.read(buffer, bytesRead, buffer.length - bytesRead, null);
46
+ bytesRead += part.bytesRead;
47
+ if (!part.bytesRead || bytesRead > 1024)
48
+ break;
49
+ }
50
+ if (bytesRead > 1024)
51
+ throw new Error('Invalid auth lifecycle entry');
52
+ const value = JSON.parse(buffer.subarray(0, bytesRead).toString('utf8'));
53
+ if (value.version !== 1 || value.scope !== this.scope || typeof value.generation !== 'string' || !value.generation || value.generation.length > 100 || value.event !== 'signed-out')
54
+ throw new Error('Invalid auth lifecycle entry');
55
+ return true;
56
+ }
57
+ finally {
58
+ await file.close();
59
+ }
60
+ }
61
+ catch (error) {
62
+ if (error.code === 'ENOENT')
63
+ return false;
64
+ throw new AuthError('storage', 'Unable to read the non-secret sign-out state. Check the installation auth directory.', { cause: error });
65
+ }
66
+ }
67
+ async recordSignOut(generation) {
68
+ let temporary;
69
+ try {
70
+ const path = await this.path(true);
71
+ temporary = `${path}.${randomUUID()}.tmp`;
72
+ const file = await open(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | (constants.O_NOFOLLOW ?? 0), 0o600);
73
+ try {
74
+ await file.writeFile(JSON.stringify({ version: 1, scope: this.scope, generation, event: 'signed-out' }) + '\n');
75
+ await file.sync();
76
+ }
77
+ finally {
78
+ await file.close();
79
+ }
80
+ // rename replaces the entry, never its link target. No credentials or account subject here.
81
+ await rename(temporary, path);
82
+ if (process.platform !== 'win32') {
83
+ const directory = await open(join(this.home, 'auth'), constants.O_RDONLY);
84
+ try {
85
+ await directory.sync();
86
+ }
87
+ finally {
88
+ await directory.close();
89
+ }
90
+ }
91
+ }
92
+ catch (error) {
93
+ throw new AuthError('storage', 'Credentials cleared, but the non-secret sign-out state could not be saved. Retry logout.', { cause: error });
94
+ }
95
+ finally {
96
+ if (temporary)
97
+ await unlink(temporary).catch(() => { });
98
+ }
99
+ }
100
+ async retire() {
101
+ try {
102
+ await unlink(await this.path());
103
+ }
104
+ catch (error) {
105
+ if (error.code !== 'ENOENT')
106
+ throw error;
107
+ }
108
+ }
109
+ }
@@ -65,6 +65,7 @@ export declare class FallbackCredentialStore implements CredentialStore {
65
65
  private keyringOr;
66
66
  private clearReachableKeyring;
67
67
  read(): Promise<string | undefined>;
68
+ readForState(): Promise<string | undefined>;
68
69
  write(value: string): Promise<void>;
69
70
  previous(): Promise<string | undefined>;
70
71
  clear(tombstone: string): Promise<void>;
@@ -289,6 +289,18 @@ export class FallbackCredentialStore {
289
289
  }
290
290
  }
291
291
  read() { return this.keyringOr(store => store.read()); }
292
+ async readForState() {
293
+ if (await this.useFile())
294
+ return this.file.read();
295
+ try {
296
+ return await this.keyring.read();
297
+ }
298
+ catch (error) {
299
+ if (this.mode !== 'auto' || !this.fallback || !(error instanceof KeyringAbsentError) || error instanceof KeyringUnreachableError)
300
+ throw error;
301
+ return this.file.read();
302
+ }
303
+ }
292
304
  write(value) { return this.keyringOr(store => store.write(value)); }
293
305
  async previous() {
294
306
  const inactive = await this.useFile() ? this.keyring : this.file;
@@ -17,6 +17,16 @@ export interface AuthStatus {
17
17
  expiresAt?: number;
18
18
  storage?: CredentialLocation;
19
19
  }
20
+ /** Read-only lifecycle authority. Missing identity is NOT evidence of an empty credential store. */
21
+ export type AuthState = {
22
+ state: 'signed-in';
23
+ subject: string;
24
+ } | {
25
+ state: 'signed-out';
26
+ deliberate: boolean;
27
+ } | {
28
+ state: 'unavailable';
29
+ };
20
30
  export declare class AuthError extends Error {
21
31
  readonly code: 'configuration' | 'storage' | 'busy' | 'cancelled' | 'callback' | 'network' | 'invalid_token' | 'login_required' | 'superseded';
22
32
  constructor(code: 'configuration' | 'storage' | 'busy' | 'cancelled' | 'callback' | 'network' | 'invalid_token' | 'login_required' | 'superseded', message: string, options?: {
@@ -25,6 +35,8 @@ export declare class AuthError extends Error {
25
35
  }
26
36
  export interface CredentialStore {
27
37
  read(): Promise<string | undefined>;
38
+ /** Like read, but a locked/unreachable keyring must not masquerade as an empty fallback file. */
39
+ readForState?(): Promise<string | undefined>;
28
40
  write(value: string): Promise<void>;
29
41
  clear(tombstone: string): Promise<void>;
30
42
  location?(): Promise<CredentialLocation>;
@@ -1,4 +1,5 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { requireLegalAcceptance } from './legal/gate.js';
2
3
  import { fileURLToPath } from 'node:url';
3
4
  import { createInterface } from 'node:readline';
4
5
  import { resolve } from 'node:path';
@@ -19,6 +20,7 @@ export function automationRunContext(job) {
19
20
  }
20
21
  export async function executeAutomation(job, signal, directory = configDirectory()) {
21
22
  signal.throwIfAborted();
23
+ await requireLegalAcceptance(directory);
22
24
  directory = resolve(directory);
23
25
  const cli = fileURLToPath(new URL('./cli.js', import.meta.url));
24
26
  const child = spawn(process.execPath, [cli, 'app-server', '--stdio'], {
@@ -140,13 +140,18 @@ export function upgradedAutomationTaskXml(task, directory, node, cli) {
140
140
  || win32.basename(oldNode).toLowerCase() !== 'node.exe'
141
141
  || win32.basename(win32.dirname(oldRoot)).toLowerCase() !== 'engine')
142
142
  return;
143
+ // When moving to a bundle, only retarget a task from the same Desktop installation.
144
+ const newEngine = win32.dirname(newRoot);
145
+ if (win32.basename(newEngine).toLowerCase() === 'engine'
146
+ && windowsPath(win32.dirname(oldRoot)) !== windowsPath(newEngine))
147
+ return;
143
148
  const oldArgs = [win32.join(oldRoot, 'dist', 'src', 'cli.js'), 'automations', 'serve', '--home', resolve(directory)].map(windowsArgument).join(' ');
144
149
  const comparableArgs = (value) => value.replaceAll('\\\\?\\', '').toLowerCase();
145
150
  if (comparableArgs(unxml(argumentsFields[0][1])) !== comparableArgs(oldArgs))
146
151
  return;
147
152
  const args = [cli, 'automations', 'serve', '--home', resolve(directory)].map(windowsArgument).join(' ');
148
- return task.replace(commands[0][0], `<Command>${xml(node)}</Command>`)
149
- .replace(argumentsFields[0][0], `<Arguments>${xml(args)}</Arguments>`);
153
+ return task.replace(commands[0][0], () => `<Command>${xml(node)}</Command>`)
154
+ .replace(argumentsFields[0][0], () => `<Arguments>${xml(args)}</Arguments>`);
150
155
  }
151
156
  export async function reconcileAutomationService(directory = configDirectory(), host = {
152
157
  platform: process.platform,
@@ -46,7 +46,8 @@ export function createAutomationTool() {
46
46
  }
47
47
  const { action: _action, id: _id, ...input } = args;
48
48
  if (args.action === 'create') {
49
- input.project ??= context.workspace;
49
+ // Filed under the task's project, not under the worktree the task happens to work in.
50
+ input.project ??= context.project ?? context.workspace;
50
51
  input.execution = { ...context.wakeCarry, permissions: permissionMode(context) ?? 'ask-for-approval' };
51
52
  input.execution = Object.fromEntries(Object.entries(input.execution).filter(([key]) => ['provider', 'model', 'graph', 'permissions', 'reasoningEffort'].includes(key)));
52
53
  assertPlanMutationAllowed(context);