@andorra-labs/code 0.1.16 → 0.1.17

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 (188) hide show
  1. package/dist/src/acp-agent.d.ts +6 -0
  2. package/dist/src/acp-agent.js +15 -4
  3. package/dist/src/agent-execution.js +11 -8
  4. package/dist/src/agent-mcp-catalog.js +1 -0
  5. package/dist/src/agent-mcp.d.ts +3 -0
  6. package/dist/src/agent-mcp.js +33 -1
  7. package/dist/src/andorra/entry.d.ts +10 -0
  8. package/dist/src/andorra/entry.js +18 -4
  9. package/dist/src/andorra/hosted.d.ts +2 -1
  10. package/dist/src/andorra/hosted.js +2 -1
  11. package/dist/src/andorra/notices.d.ts +5 -0
  12. package/dist/src/andorra/notices.js +7 -0
  13. package/dist/src/andorra/state.d.ts +3 -2
  14. package/dist/src/andorra/state.js +4 -4
  15. package/dist/src/andorra/terminal.js +7 -2
  16. package/dist/src/anthropic-credentials.js +2 -0
  17. package/dist/src/app-server/error.d.ts +5 -0
  18. package/dist/src/app-server/error.js +7 -0
  19. package/dist/src/app-server/protocol.d.ts +19 -44
  20. package/dist/src/app-server/protocol.js +5 -1
  21. package/dist/src/app-server/workspace.d.ts +89 -0
  22. package/dist/src/app-server/workspace.js +457 -11
  23. package/dist/src/app-server.d.ts +358 -32
  24. package/dist/src/app-server.js +2429 -509
  25. package/dist/src/bridge/cloud.d.ts +27 -0
  26. package/dist/src/bridge/cloud.js +187 -0
  27. package/dist/src/bridge/command.d.ts +30 -0
  28. package/dist/src/bridge/command.js +347 -0
  29. package/dist/src/bridge/control.d.ts +68 -0
  30. package/dist/src/bridge/control.js +233 -0
  31. package/dist/src/bridge/engines.d.ts +90 -0
  32. package/dist/src/bridge/engines.js +601 -0
  33. package/dist/src/bridge/host-ops.d.ts +9 -0
  34. package/dist/src/bridge/host-ops.js +129 -0
  35. package/dist/src/bridge/host.d.ts +47 -0
  36. package/dist/src/bridge/host.js +540 -0
  37. package/dist/src/bridge/link.d.ts +38 -0
  38. package/dist/src/bridge/link.js +508 -0
  39. package/dist/src/bridge/login-link.d.ts +29 -0
  40. package/dist/src/bridge/login-link.js +54 -0
  41. package/dist/src/bridge/protocol.d.ts +136 -0
  42. package/dist/src/bridge/protocol.js +11 -0
  43. package/dist/src/bridge/store.d.ts +12 -0
  44. package/dist/src/bridge/store.js +61 -0
  45. package/dist/src/bridge/wording.d.ts +6 -0
  46. package/dist/src/bridge/wording.js +10 -0
  47. package/dist/src/browser-server.js +7 -1
  48. package/dist/src/browser-ui/tokens.css +1 -1
  49. package/dist/src/change-authors.d.ts +41 -0
  50. package/dist/src/change-authors.js +146 -0
  51. package/dist/src/cli.js +182 -32
  52. package/dist/src/coding-tools.js +15 -15
  53. package/dist/src/command-screens.d.ts +6 -0
  54. package/dist/src/command-screens.js +14 -11
  55. package/dist/src/commands.d.ts +14 -2
  56. package/dist/src/compaction-phrases.js +1 -1
  57. package/dist/src/completion.js +82 -5
  58. package/dist/src/config.d.ts +71 -3
  59. package/dist/src/config.js +202 -77
  60. package/dist/src/deadline.js +13 -1
  61. package/dist/src/decision/checks.js +1 -1
  62. package/dist/src/decision/requestPhrases.js +0 -1
  63. package/dist/src/default-graph.js +1 -1
  64. package/dist/src/file-diff.d.ts +4 -0
  65. package/dist/src/file-diff.js +2 -1
  66. package/dist/src/github-app/agent-writes.d.ts +102 -0
  67. package/dist/src/github-app/agent-writes.js +320 -0
  68. package/dist/src/github-app/client.d.ts +349 -0
  69. package/dist/src/github-app/client.js +810 -0
  70. package/dist/src/github-app/event-source.d.ts +208 -0
  71. package/dist/src/github-app/event-source.js +684 -0
  72. package/dist/src/github-app/metrics.d.ts +32 -0
  73. package/dist/src/github-app/metrics.js +49 -0
  74. package/dist/src/github-app/review-loop.d.ts +274 -0
  75. package/dist/src/github-app/review-loop.js +1177 -0
  76. package/dist/src/github-app/review-node.d.ts +81 -0
  77. package/dist/src/github-app/review-node.js +205 -0
  78. package/dist/src/github-app/review-post.d.ts +73 -0
  79. package/dist/src/github-app/review-post.js +139 -0
  80. package/dist/src/github-app/review-text.d.ts +107 -0
  81. package/dist/src/github-app/review-text.js +1133 -0
  82. package/dist/src/github-app/review-threads.d.ts +47 -0
  83. package/dist/src/github-app/review-threads.js +107 -0
  84. package/dist/src/github-app/reviewer.d.ts +121 -0
  85. package/dist/src/github-app/reviewer.js +598 -0
  86. package/dist/src/github-app/store.d.ts +59 -0
  87. package/dist/src/github-app/store.js +148 -0
  88. package/dist/src/github-app/triggers.d.ts +141 -0
  89. package/dist/src/github-app/triggers.js +441 -0
  90. package/dist/src/github-names.d.ts +8 -0
  91. package/dist/src/github-names.js +8 -0
  92. package/dist/src/glob-search.d.ts +61 -0
  93. package/dist/src/glob-search.js +180 -0
  94. package/dist/src/graph-health.js +6 -1
  95. package/dist/src/graph-manager-chat.js +1 -1
  96. package/dist/src/graph-preview.d.ts +46 -0
  97. package/dist/src/graph-preview.js +55 -0
  98. package/dist/src/graph-provider-portability.js +2 -1
  99. package/dist/src/graph-runner.js +64 -3
  100. package/dist/src/graph-server.js +3 -3
  101. package/dist/src/graph-sync.js +3 -3
  102. package/dist/src/graph-ui/app.js +91 -7
  103. package/dist/src/graph-ui/icons.js +2 -1
  104. package/dist/src/graph-ui/studio.js +15 -1
  105. package/dist/src/graph-ui/tokens.css +1 -1
  106. package/dist/src/graphs.d.ts +34 -1
  107. package/dist/src/graphs.js +158 -14
  108. package/dist/src/image-input.d.ts +16 -0
  109. package/dist/src/image-input.js +41 -0
  110. package/dist/src/membership.d.ts +10 -0
  111. package/dist/src/membership.js +19 -4
  112. package/dist/src/model-health-cache.js +1 -1
  113. package/dist/src/model-metadata.d.ts +6 -0
  114. package/dist/src/model-metadata.js +35 -15
  115. package/dist/src/model-relay/local.d.ts +116 -0
  116. package/dist/src/model-relay/local.js +468 -0
  117. package/dist/src/model-relay/remote.d.ts +129 -0
  118. package/dist/src/model-relay/remote.js +252 -0
  119. package/dist/src/model-relay/runs.d.ts +34 -0
  120. package/dist/src/model-relay/runs.js +146 -0
  121. package/dist/src/model-relay/wire.d.ts +5 -0
  122. package/dist/src/model-relay/wire.js +5 -0
  123. package/dist/src/project-registry.d.ts +21 -0
  124. package/dist/src/project-registry.js +74 -0
  125. package/dist/src/provider-import.d.ts +0 -12
  126. package/dist/src/provider-import.js +7 -195
  127. package/dist/src/providers.d.ts +23 -2
  128. package/dist/src/providers.js +25 -4
  129. package/dist/src/pull-request-logs.d.ts +12 -1
  130. package/dist/src/pull-request-logs.js +14 -3
  131. package/dist/src/pull-requests.d.ts +327 -7
  132. package/dist/src/pull-requests.js +429 -51
  133. package/dist/src/react-runtime.js +1 -1
  134. package/dist/src/remote/engine-pool.d.ts +88 -4
  135. package/dist/src/remote/engine-pool.js +366 -89
  136. package/dist/src/remote/roots.d.ts +19 -0
  137. package/dist/src/remote/roots.js +45 -7
  138. package/dist/src/remote/types.d.ts +0 -44
  139. package/dist/src/run-control.d.ts +7 -0
  140. package/dist/src/run-control.js +23 -0
  141. package/dist/src/run-records.d.ts +7 -2
  142. package/dist/src/run-records.js +71 -6
  143. package/dist/src/runtime.d.ts +5 -1
  144. package/dist/src/runtime.js +10 -2
  145. package/dist/src/session-changes.d.ts +35 -0
  146. package/dist/src/session-changes.js +194 -6
  147. package/dist/src/session-monitor.js +2 -1
  148. package/dist/src/session-reaper.d.ts +1 -1
  149. package/dist/src/session-reaper.js +6 -1
  150. package/dist/src/session-summary.d.ts +2 -1
  151. package/dist/src/session-summary.js +2 -1
  152. package/dist/src/sessions.d.ts +11 -1
  153. package/dist/src/sessions.js +17 -4
  154. package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
  155. package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
  156. package/dist/src/skills/bundled/provenance.json +2 -2
  157. package/dist/src/skills/runtime-skills.js +1 -1
  158. package/dist/src/telemetry/emitter.d.ts +15 -0
  159. package/dist/src/telemetry/emitter.js +35 -1
  160. package/dist/src/telemetry/schema.d.ts +25 -2
  161. package/dist/src/telemetry/schema.js +52 -4
  162. package/dist/src/telemetry/surface.d.ts +2 -1
  163. package/dist/src/telemetry/surface.js +4 -1
  164. package/dist/src/terminal-ui.d.ts +1 -0
  165. package/dist/src/terminal-ui.js +10 -3
  166. package/dist/src/test-edit-guard.d.ts +7 -0
  167. package/dist/src/test-edit-guard.js +49 -1
  168. package/dist/src/timers.d.ts +2 -0
  169. package/dist/src/tools.js +59 -9
  170. package/package.json +6 -1
  171. package/dist/src/remote/cert.d.ts +0 -11
  172. package/dist/src/remote/cert.js +0 -87
  173. package/dist/src/remote/client.d.ts +0 -119
  174. package/dist/src/remote/client.js +0 -544
  175. package/dist/src/remote/command.d.ts +0 -4
  176. package/dist/src/remote/command.js +0 -194
  177. package/dist/src/remote/errors.d.ts +0 -11
  178. package/dist/src/remote/errors.js +0 -14
  179. package/dist/src/remote/network.d.ts +0 -22
  180. package/dist/src/remote/network.js +0 -102
  181. package/dist/src/remote/pairing.d.ts +0 -63
  182. package/dist/src/remote/pairing.js +0 -299
  183. package/dist/src/remote/pem.d.ts +0 -2
  184. package/dist/src/remote/pem.js +0 -7
  185. package/dist/src/remote/serve.d.ts +0 -68
  186. package/dist/src/remote/serve.js +0 -244
  187. package/dist/src/remote/server.d.ts +0 -21
  188. package/dist/src/remote/server.js +0 -406
@@ -6,4 +6,23 @@ export interface AuthorizedRoot {
6
6
  kind: 'project' | 'share';
7
7
  }
8
8
  export declare function projectRootId(realPath: string): string;
9
+ /** Whether `path` is `folder` or lies inside it, compared by path segment (and without case on Windows). */
10
+ export declare function isInsideFolder(folder: string, path: string): boolean;
11
+ /** The folders this machine shares through `andorra bridge folders`, by real path; missing ones are left out. */
12
+ export declare function sharedFolders(config: Config): Promise<AuthorizedRoot[]>;
13
+ /**
14
+ * The real path of the directory at `path` when it lies inside a shared folder; `undefined` when it does not exist.
15
+ * Throws `outside` when the directory, or the path as written, is not inside any shared folder. Symbolic links are
16
+ * resolved first, so a link inside a folder that points out of it is outside.
17
+ */
18
+ export declare function directoryInsideFolders(folders: AuthorizedRoot[], path: string): Promise<{
19
+ inside: true;
20
+ path: string;
21
+ } | {
22
+ inside: false;
23
+ } | undefined>;
24
+ /**
25
+ * What a desktop may reach on this machine: the shared folders, plus the configured projects whose real path lies
26
+ * inside one of them. With no folders shared, nothing.
27
+ */
9
28
  export declare function authorizedRoots(config: Config): Promise<AuthorizedRoot[]>;
@@ -1,6 +1,6 @@
1
1
  import { createHash } from 'node:crypto';
2
2
  import { realpath, stat } from 'node:fs/promises';
3
- import { basename } from 'node:path';
3
+ import { basename, isAbsolute, relative, sep } from 'node:path';
4
4
  export function projectRootId(realPath) {
5
5
  const canonical = process.platform === 'win32' ? realPath.toLowerCase() : realPath;
6
6
  return `proj-${createHash('sha256').update(canonical).digest('hex').slice(0, 16)}`;
@@ -15,22 +15,60 @@ async function directoryAt(path) {
15
15
  return undefined;
16
16
  }
17
17
  }
18
+ /** Whether `path` is `folder` or lies inside it, compared by path segment (and without case on Windows). */
19
+ export function isInsideFolder(folder, path) {
20
+ const fold = (value) => process.platform === 'win32' ? value.toLowerCase() : value;
21
+ const rel = relative(fold(folder), fold(path));
22
+ if (rel === '')
23
+ return true;
24
+ return !isAbsolute(rel) && rel.split(sep)[0] !== '..';
25
+ }
26
+ /** The folders this machine shares through `andorra bridge folders`, by real path; missing ones are left out. */
27
+ export async function sharedFolders(config) {
28
+ const folders = [];
29
+ const seen = new Set();
30
+ for (const share of config.bridge?.folders ?? []) {
31
+ const realPath = await directoryAt(share.path);
32
+ if (!realPath || seen.has(realPath))
33
+ continue;
34
+ seen.add(realPath);
35
+ folders.push({ id: `share-${share.id}`, label: share.label?.trim() || basename(realPath) || realPath, path: realPath, kind: 'share' });
36
+ }
37
+ return folders;
38
+ }
39
+ /**
40
+ * The real path of the directory at `path` when it lies inside a shared folder; `undefined` when it does not exist.
41
+ * Throws `outside` when the directory, or the path as written, is not inside any shared folder. Symbolic links are
42
+ * resolved first, so a link inside a folder that points out of it is outside.
43
+ */
44
+ export async function directoryInsideFolders(folders, path) {
45
+ const actual = await directoryAt(path);
46
+ if (actual === undefined)
47
+ return folders.some(folder => isInsideFolder(folder.path, path)) ? undefined : { inside: false };
48
+ return folders.some(folder => isInsideFolder(folder.path, actual)) ? { inside: true, path: actual } : { inside: false };
49
+ }
50
+ /**
51
+ * What a desktop may reach on this machine: the shared folders, plus the configured projects whose real path lies
52
+ * inside one of them. With no folders shared, nothing.
53
+ */
18
54
  export async function authorizedRoots(config) {
55
+ const folders = await sharedFolders(config);
56
+ if (folders.length === 0)
57
+ return [];
19
58
  const roots = [];
20
59
  const seen = new Set();
21
60
  for (const project of config.projects ?? []) {
22
61
  const realPath = await directoryAt(project.path);
23
- if (!realPath || seen.has(realPath))
62
+ if (!realPath || seen.has(realPath) || !folders.some(folder => isInsideFolder(folder.path, realPath)))
24
63
  continue;
25
64
  seen.add(realPath);
26
65
  roots.push({ id: projectRootId(realPath), label: project.name?.trim() || basename(realPath) || realPath, path: realPath, kind: 'project' });
27
66
  }
28
- for (const share of config.remote?.hosting?.shares ?? []) {
29
- const realPath = await directoryAt(share.path);
30
- if (!realPath || seen.has(realPath))
67
+ for (const folder of folders) {
68
+ if (seen.has(folder.path))
31
69
  continue;
32
- seen.add(realPath);
33
- roots.push({ id: `share-${share.id}`, label: share.label?.trim() || basename(realPath) || realPath, path: realPath, kind: 'share' });
70
+ seen.add(folder.path);
71
+ roots.push(folder);
34
72
  }
35
73
  return roots;
36
74
  }
@@ -1,52 +1,8 @@
1
- export type RemoteTransport = 'https' | 'http';
2
- export type RemoteGrant = 'browse' | 'full';
3
- export interface RemoteDevice {
4
- id: string;
5
- token: string;
6
- label?: string;
7
- addedAt: string;
8
- lastSeenAt?: string;
9
- grant?: RemoteGrant;
10
- }
11
- export interface RemoteInvitation {
12
- token: string;
13
- createdAt: string;
14
- expiresAt: string;
15
- redeemedAt?: string;
16
- grant?: RemoteGrant;
17
- }
18
1
  export interface RemoteShare {
19
2
  id: string;
20
3
  path: string;
21
4
  label?: string;
22
5
  }
23
- export interface RemoteHosting {
24
- installId?: string;
25
- port?: number;
26
- transport?: RemoteTransport;
27
- invitation?: RemoteInvitation | null;
28
- devices?: RemoteDevice[];
29
- shares?: RemoteShare[];
30
- }
31
- export interface RemoteWorkspace {
32
- id: string;
33
- nickname: string;
34
- hosts: string[];
35
- host?: string;
36
- port: number;
37
- transport: RemoteTransport;
38
- fingerprint: string;
39
- certPem: string;
40
- token: string;
41
- hostname?: string;
42
- platform?: string;
43
- version?: string;
44
- addedAt: string;
45
- }
46
- export interface RemoteConfig {
47
- hosting?: RemoteHosting;
48
- workspaces?: RemoteWorkspace[];
49
- }
50
6
  export interface ProjectEntry {
51
7
  path: string;
52
8
  name?: string;
@@ -5,11 +5,18 @@ export declare class RunControl {
5
5
  private readonly directions;
6
6
  private compactionPending;
7
7
  private readonly steerListeners;
8
+ private budgetHolds;
9
+ private readonly holdListeners;
8
10
  yolo?: boolean;
9
11
  permissions?: import('./permissions.js').PermissionMode;
10
12
  get isPaused(): boolean;
11
13
  get signal(): AbortSignal;
12
14
  get revision(): number;
15
+ /** Whether the run's wall-time budgets are held, for example while a model request waits for a desktop to take it. */
16
+ get budgetsHeld(): boolean;
17
+ onBudgetHold(listener: (held: boolean) => void): () => void;
18
+ /** Holds every budget bound to this run until the returned function is called (once; holds nest). */
19
+ holdBudgets(): () => void;
13
20
  /** Whether a /compact made during the run is still waiting for an agent to act on it. */
14
21
  get compactionRequested(): boolean;
15
22
  /** Hands a pending /compact to the agent that will act on it; true once per request (repeats before it is taken merge). */
@@ -5,11 +5,34 @@ export class RunControl {
5
5
  directions = [];
6
6
  compactionPending = false;
7
7
  steerListeners = new Map();
8
+ budgetHolds = 0;
9
+ holdListeners = new Set();
8
10
  yolo;
9
11
  permissions;
10
12
  get isPaused() { return this.paused; }
11
13
  get signal() { return this.controller.signal; }
12
14
  get revision() { return this.directions.length; }
15
+ /** Whether the run's wall-time budgets are held, for example while a model request waits for a desktop to take it. */
16
+ get budgetsHeld() { return this.budgetHolds > 0; }
17
+ onBudgetHold(listener) {
18
+ this.holdListeners.add(listener);
19
+ return () => { this.holdListeners.delete(listener); };
20
+ }
21
+ /** Holds every budget bound to this run until the returned function is called (once; holds nest). */
22
+ holdBudgets() {
23
+ if (this.budgetHolds++ === 0)
24
+ for (const listener of [...this.holdListeners])
25
+ listener(true);
26
+ let released = false;
27
+ return () => {
28
+ if (released)
29
+ return;
30
+ released = true;
31
+ if (--this.budgetHolds === 0)
32
+ for (const listener of [...this.holdListeners])
33
+ listener(false);
34
+ };
35
+ }
13
36
  /** Whether a /compact made during the run is still waiting for an agent to act on it. */
14
37
  get compactionRequested() { return this.compactionPending; }
15
38
  /** Hands a pending /compact to the agent that will act on it; true once per request (repeats before it is taken merge). */
@@ -19,12 +19,12 @@ export interface OpenRunRecord {
19
19
  permissions?: string;
20
20
  resumedFrom?: string;
21
21
  direction?: string;
22
- wake?: 'timer' | 'auto-fix' | 'fix-checks';
22
+ wake?: 'timer' | 'auto-fix' | 'fix-checks' | 'mention' | 'andorra-review';
23
23
  pendingDirections?: {
24
24
  runId: string;
25
25
  direction: string;
26
26
  id?: string;
27
- wake?: 'timer' | 'auto-fix' | 'fix-checks';
27
+ wake?: 'timer' | 'auto-fix' | 'fix-checks' | 'mention' | 'andorra-review';
28
28
  node?: string;
29
29
  }[];
30
30
  directionNode?: string;
@@ -106,6 +106,11 @@ export declare function sessionsWithOpenRunClaims(directory: string, sessions?:
106
106
  export declare function sessionHasOpenRun(directory: string, sessionId: string, options?: {
107
107
  ignoreRunId?: string;
108
108
  }): Promise<boolean>;
109
+ /**
110
+ * Whether one run is still open: its claim is there and its process is live. Read only, unlike `sessionHasOpenRun`: a
111
+ * stale claim is left for that sweep. An unreadable claim counts as open.
112
+ */
113
+ export declare function runIsOpen(directory: string, runId: string): Promise<boolean>;
109
114
  export declare function sessionHasArmedWake(directory: string, sessionId: string): Promise<boolean>;
110
115
  export declare function writeWakeClaim(directory: string, sessionId: string, timerId: string): Promise<void>;
111
116
  export declare function clearWakeClaim(directory: string, sessionId: string, timerId: string): Promise<void>;
@@ -232,7 +232,8 @@ async function markOpenRunsInterrupted(directory, onlyRunIds, skipOwnProcess = f
232
232
  await unlock();
233
233
  continue;
234
234
  }
235
- const interrupted = { ...current, status: 'interrupted', telemetryPending: true, reason: 'the engine stopped while this run was active', endedAt: new Date().toISOString() };
235
+ const measured = plainObject(current.usage) ? undefined : await journalRunUsage(directory, runId);
236
+ const interrupted = { ...current, status: 'interrupted', telemetryPending: true, reason: 'the engine stopped while this run was active', endedAt: new Date().toISOString(), ...(measured === undefined ? {} : { usage: measured }) };
236
237
  try {
237
238
  await writeSessionSnapshot(path, JSON.stringify(interrupted, null, 2) + '\n');
238
239
  }
@@ -461,6 +462,24 @@ export async function sessionHasOpenRun(directory, sessionId, options = {}) {
461
462
  }
462
463
  return false;
463
464
  }
465
+ /**
466
+ * Whether one run is still open: its claim is there and its process is live. Read only, unlike `sessionHasOpenRun`: a
467
+ * stale claim is left for that sweep. An unreadable claim counts as open.
468
+ */
469
+ export async function runIsOpen(directory, runId) {
470
+ let claim;
471
+ try {
472
+ claim = JSON.parse(await readFile(runRecordPath(directory, runId, 'open-run'), 'utf8'));
473
+ }
474
+ catch (error) {
475
+ return error.code !== 'ENOENT';
476
+ }
477
+ if (!claim || typeof claim !== 'object' || claim.runId !== runId)
478
+ return true;
479
+ if (await claimOutlivedItsRun(directory, claim))
480
+ return false;
481
+ return claimOwnerIsLive(typeof claim.pid === 'number' ? claim.pid : undefined, claim.startedAt);
482
+ }
464
483
  export async function sessionHasArmedWake(directory, sessionId) {
465
484
  const runs = runRecordsDirectory(directory);
466
485
  let names;
@@ -674,14 +693,21 @@ async function upgradeSessionMarkers(directory, only) {
674
693
  }
675
694
  if (known && !usageFolded.has(runId)) {
676
695
  usageFolded.add(runId);
677
- foldRecordUsage(session, record.usage);
696
+ foldRecordUsage(session, plainObject(record.usage) ? record.usage : await journalRunUsage(directory, runId));
678
697
  }
679
698
  }
680
699
  else {
681
700
  completion.summary = INTERRUPTED_TURN_SUMMARY;
682
701
  completion.status = 'interrupted';
683
- if (known)
684
- await synthesizeInterruptedRecord(directory, runId, typeof session.id === 'string' && validSessionFile(session.id) ? session.id : undefined);
702
+ if (known) {
703
+ // No finished record carries this run's usage, so the journal's last measurement stands in for it.
704
+ const measured = await journalRunUsage(directory, runId);
705
+ if (!usageFolded.has(runId)) {
706
+ usageFolded.add(runId);
707
+ foldRecordUsage(session, measured);
708
+ }
709
+ await synthesizeInterruptedRecord(directory, runId, typeof session.id === 'string' && validSessionFile(session.id) ? session.id : undefined, measured);
710
+ }
685
711
  }
686
712
  changed += 1;
687
713
  }
@@ -722,7 +748,46 @@ async function readRunRecord(directory, runId) {
722
748
  return undefined;
723
749
  }
724
750
  }
725
- async function synthesizeInterruptedRecord(directory, runId, sessionId) {
751
+ /**
752
+ * What a run had spent when its journal stopped: the run-wide total stamped on its last recorded model
753
+ * completion. An engine that dies mid-run never writes the finished record that normally carries this.
754
+ */
755
+ async function journalRunUsage(directory, runId) {
756
+ let lines;
757
+ try {
758
+ lines = (await readFile(runRecordPath(directory, runId, 'jsonl'), 'utf8')).split('\n');
759
+ }
760
+ catch {
761
+ return undefined;
762
+ }
763
+ const count = (value) => typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : undefined;
764
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
765
+ const line = lines[index];
766
+ if (!line.includes('"agent.model.completed"'))
767
+ continue;
768
+ let total;
769
+ try {
770
+ const event = JSON.parse(line);
771
+ if (event.type !== 'agent.model.completed')
772
+ continue;
773
+ total = event.data?.graphUsage;
774
+ }
775
+ catch {
776
+ continue;
777
+ }
778
+ if (!plainObject(total))
779
+ continue;
780
+ const stamped = total;
781
+ const inputTokens = count(stamped.inputTokens), outputTokens = count(stamped.outputTokens);
782
+ if (inputTokens === undefined || outputTokens === undefined)
783
+ continue;
784
+ const cacheRead = count(stamped.cacheRead), cacheWrite = count(stamped.cacheWrite);
785
+ return { requests: count(stamped.requests) ?? 0, inputTokens, outputTokens,
786
+ ...(cacheRead === undefined ? {} : { cacheRead }), ...(cacheWrite === undefined ? {} : { cacheWrite }) };
787
+ }
788
+ return undefined;
789
+ }
790
+ async function synthesizeInterruptedRecord(directory, runId, sessionId, usage) {
726
791
  if (await readRunRecord(directory, runId) !== undefined)
727
792
  return;
728
793
  await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
@@ -737,7 +802,7 @@ async function synthesizeInterruptedRecord(directory, runId, sessionId) {
737
802
  try {
738
803
  await writeSessionSnapshot(runRecordPath(directory, runId, 'json'), JSON.stringify({
739
804
  id: runId, status: 'interrupted', reason: 'the engine stopped before the run was recorded', startedAt,
740
- ...(sessionId === undefined ? {} : { sessionId }), usage: { inputTokens: 0, outputTokens: 0, requests: 0 }, toolCalls: 0,
805
+ ...(sessionId === undefined ? {} : { sessionId }), usage: usage ?? { inputTokens: 0, outputTokens: 0, requests: 0 }, toolCalls: 0,
741
806
  }, null, 2) + '\n');
742
807
  }
743
808
  catch { }
@@ -113,15 +113,17 @@ export interface AgentContinuationState {
113
113
  };
114
114
  }
115
115
  export declare function timerReminderText(prompt: string): string;
116
- type RetainedWake = 'timer' | 'auto-fix' | 'fix-checks';
116
+ type RetainedWake = 'timer' | 'auto-fix' | 'fix-checks' | 'mention' | 'andorra-review';
117
117
  export declare function wakeMessageText(wake: RetainedWake | undefined, message: string): string;
118
118
  export declare function turnModelTask(turn: {
119
119
  task: string;
120
+ note?: string;
120
121
  direction?: string;
121
122
  wake?: RetainedWake;
122
123
  attachments?: readonly UserAttachmentRef[];
123
124
  steers?: {
124
125
  text: string;
126
+ note?: string;
125
127
  attachments?: readonly UserAttachmentRef[];
126
128
  wake?: RetainedWake;
127
129
  subagentId?: string;
@@ -268,5 +270,7 @@ export interface GraphRunOptions extends RunOptions {
268
270
  progress: import('./run-progress.js').RunProgress;
269
271
  checkpoints?: import('./run-progress.js').RunCheckpoint[];
270
272
  };
273
+ /** Runs an Andorra review node's rounds on the task's PR; without it such a node leaves through `stopped` (`unavailable`). */
274
+ reviewNode?: import('./github-app/review-node.js').ReviewNodeService;
271
275
  }
272
276
  export { runGraph } from './graph-runner.js';
@@ -22,17 +22,25 @@ export function wakeMessageText(wake, message) {
22
22
  // The person pressed Fix with Agent in the PR tab; the text is the engine's, built from GitHub's checks.
23
23
  if (wake === 'fix-checks')
24
24
  return `Sent by the user with Fix with Agent in the PR tab: ${message}`;
25
+ // The person mentioned the App's bot on the task's PR; the text is the engine's, and the comment is read with gh.
26
+ if (wake === 'mention')
27
+ return `Delivered for a mention on GitHub (not typed in this chat): ${message}`;
28
+ // The review loop posted a round with findings; the text is the engine's, and the findings are read with gh.
29
+ if (wake === 'andorra-review')
30
+ return `Delivered by Andorra review (not a message from the user): ${message}`;
25
31
  return wake === 'timer' ? timerReminderText(message) : message;
26
32
  }
27
33
  export function turnModelTask(turn) {
28
34
  const woken = (message) => wakeMessageText(turn.wake ?? 'timer', message);
29
- const text = turn.direction === undefined
35
+ const said = turn.direction === undefined
30
36
  ? (turn.wake === undefined ? turn.task : woken(turn.task))
31
37
  : `${turn.task}\n\n${turn.wake === undefined ? `Direction given when the attempt continued: ${turn.direction}` : `Delivered when the attempt continued: ${woken(turn.direction)}`}`;
38
+ // The turn's note (`run.note`) was given to the agent with the message, so later turns replay it too.
39
+ const text = turn.note ? `${said}\n\n${turn.note}` : said;
32
40
  // A message the user sent to a subagent was never for this agent, so it is not replayed to it.
33
41
  const withSteers = (turn.steers ?? []).filter(steer => steer.subagentId === undefined).reduce((text, steer) => {
34
42
  const line = steer.wake === undefined
35
- ? `\n\nSteering message the user sent while this attempt ran: ${steer.text}`
43
+ ? `\n\nSteering message the user sent while this attempt ran: ${steer.text}${steer.note ? `\n\n${steer.note}` : ''}`
36
44
  : `\n\nRead while this attempt ran: ${timerReminderText(steer.text)}`;
37
45
  const refs = steer.attachments?.length ? `\n\n${attachmentReferenceBlock(steer.attachments, { imagesIncluded: false })}` : '';
38
46
  return `${text}${line}${refs}`;
@@ -18,6 +18,16 @@ export interface FileWriteRecording {
18
18
  export interface FileChangeRecorder {
19
19
  beforeWrite(targets: string | readonly string[]): Promise<FileWriteRecording | undefined>;
20
20
  }
21
+ export type UserWriteResult = {
22
+ written: true;
23
+ hash: string;
24
+ size: number;
25
+ changes?: AppServerSessionChanges;
26
+ } | {
27
+ written: false;
28
+ reason: 'changed' | 'deleted';
29
+ hash?: string;
30
+ };
21
31
  export declare class SessionChangeStore {
22
32
  private readonly home;
23
33
  private readonly baselineLimit;
@@ -31,6 +41,14 @@ export declare class SessionChangeStore {
31
41
  recorder(sessionId: string, workspace: string, onChange: (changes: AppServerSessionChanges) => void, onError?: (error: unknown) => void, review?: () => boolean): FileChangeRecorder;
32
42
  private recordWrites;
33
43
  private recordWrite;
44
+ /**
45
+ * The agent's side of a file after a write (see `agentSide`). The person's first save over the agent's work keeps the
46
+ * file as the save found it; their later saves change nothing. An agent write to a file the person edited keeps what
47
+ * it wrote, and which of the person's lines it carried over. A file only the person changed has none.
48
+ */
49
+ private nextAgentSide;
50
+ /** The texts that tell the person's lines from the agent's, or undefined when the file's record cannot. */
51
+ private authorTexts;
34
52
  pending(sessionId: string): Promise<AppServerSessionChanges>;
35
53
  list(sessionId: string, maxLines?: number): Promise<AppServerSessionChanges>;
36
54
  get(sessionId: string, relative: string, maxLines?: number): Promise<{
@@ -41,6 +59,23 @@ export declare class SessionChangeStore {
41
59
  keep(sessionId: string, paths?: readonly string[]): Promise<AppServerSessionChangesKept>;
42
60
  undo(sessionId: string, paths?: readonly string[], force?: boolean): Promise<AppServerSessionChangesUndone>;
43
61
  private undoLocked;
62
+ /** The person's lines in the file now, as ranges, or undefined when they cannot be told apart. */
63
+ private userLinesNow;
44
64
  private restore;
65
+ /**
66
+ * Saves a file from the Files tab, only if it still holds what the person loaded (`expectedHash`, the SHA-256 of its
67
+ * bytes), so a save never replaces a newer copy the agent wrote. The file is written in place (its mode, owner and
68
+ * links stay), under the same per-file lock the agent's writes take. With a session, the save is recorded as the
69
+ * person's in that session's changes: the record of the written content moves with it, so the file is not reported
70
+ * "changed on disk", and a file the agent never touched becomes a change of theirs.
71
+ */
72
+ userWrite(input: {
73
+ sessionId?: string;
74
+ root: string;
75
+ relative: string;
76
+ bytes: Buffer;
77
+ expectedHash: string;
78
+ onError?: (error: unknown) => void;
79
+ }): Promise<UserWriteResult>;
45
80
  remove(sessionId: string): Promise<void>;
46
81
  }