@andorra-labs/code 0.1.5 → 0.1.6

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 (164) hide show
  1. package/dist/src/account-presentation.js +3 -3
  2. package/dist/src/agent-execution.d.ts +2 -0
  3. package/dist/src/agent-execution.js +126 -20
  4. package/dist/src/agent-mcp.d.ts +18 -1
  5. package/dist/src/agent-mcp.js +103 -8
  6. package/dist/src/app-server/protocol.d.ts +33 -3
  7. package/dist/src/app-server/protocol.js +14 -1
  8. package/dist/src/app-server/workspace.d.ts +1 -0
  9. package/dist/src/app-server/workspace.js +7 -1
  10. package/dist/src/app-server.d.ts +115 -41
  11. package/dist/src/app-server.js +1229 -219
  12. package/dist/src/automation-runner.d.ts +9 -0
  13. package/dist/src/automation-runner.js +22 -1
  14. package/dist/src/automation-tool.js +8 -1
  15. package/dist/src/automations.js +1 -1
  16. package/dist/src/browser-captcha-tool.d.ts +54 -0
  17. package/dist/src/browser-captcha-tool.js +374 -0
  18. package/dist/src/browser-panel-tool.d.ts +7 -0
  19. package/dist/src/browser-panel-tool.js +74 -3
  20. package/dist/src/browser-runner.js +19 -4
  21. package/dist/src/browser-server.js +21 -1
  22. package/dist/src/browser-session.d.ts +16 -0
  23. package/dist/src/browser-session.js +35 -0
  24. package/dist/src/browser-ui/app.js +193 -3
  25. package/dist/src/browser-ui/style.css +15 -1
  26. package/dist/src/browser-view.d.ts +72 -4
  27. package/dist/src/browser-view.js +229 -17
  28. package/dist/src/capabilities.js +13 -2
  29. package/dist/src/capsolver.d.ts +60 -0
  30. package/dist/src/capsolver.js +101 -0
  31. package/dist/src/claude-provider.d.ts +6 -0
  32. package/dist/src/claude-provider.js +34 -3
  33. package/dist/src/cli-executable.d.ts +33 -0
  34. package/dist/src/cli-executable.js +64 -0
  35. package/dist/src/cli-process.d.ts +47 -0
  36. package/dist/src/cli-process.js +113 -0
  37. package/dist/src/cli-sign-in.d.ts +68 -0
  38. package/dist/src/cli-sign-in.js +224 -0
  39. package/dist/src/cli.js +53 -22
  40. package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +1 -1
  41. package/dist/src/code-intelligence/CodeIntelligenceManager.js +5 -5
  42. package/dist/src/coding-tools.js +44 -5
  43. package/dist/src/command-output-tap.d.ts +16 -0
  44. package/dist/src/command-output-tap.js +45 -0
  45. package/dist/src/command-screens.js +3 -3
  46. package/dist/src/commands.d.ts +10 -1
  47. package/dist/src/commands.js +7 -7
  48. package/dist/src/completion.d.ts +23 -5
  49. package/dist/src/completion.js +334 -17
  50. package/dist/src/config.d.ts +13 -0
  51. package/dist/src/config.js +28 -2
  52. package/dist/src/deadline.js +6 -0
  53. package/dist/src/extensions.d.ts +1 -0
  54. package/dist/src/extensions.js +16 -3
  55. package/dist/src/graph-provider-portability.js +2 -2
  56. package/dist/src/graph-quota.d.ts +1 -1
  57. package/dist/src/graph-quota.js +1 -1
  58. package/dist/src/graph-runner.js +35 -21
  59. package/dist/src/graph-selection.d.ts +6 -0
  60. package/dist/src/graph-selection.js +10 -0
  61. package/dist/src/graph-server.d.ts +7 -0
  62. package/dist/src/graph-server.js +61 -3
  63. package/dist/src/graph-sync.d.ts +50 -0
  64. package/dist/src/graph-sync.js +383 -12
  65. package/dist/src/graph-ui/app.js +61 -8
  66. package/dist/src/graph-ui/icons.js +1 -0
  67. package/dist/src/graph-ui/index.html +1 -1
  68. package/dist/src/graph-ui/skill-picker.js +242 -0
  69. package/dist/src/graph-ui/style.css +19 -0
  70. package/dist/src/graphs.d.ts +46 -4
  71. package/dist/src/graphs.js +152 -27
  72. package/dist/src/grok-provider.d.ts +50 -0
  73. package/dist/src/grok-provider.js +186 -0
  74. package/dist/src/handoffs.d.ts +13 -0
  75. package/dist/src/handoffs.js +31 -1
  76. package/dist/src/managed-sign-in.d.ts +38 -0
  77. package/dist/src/managed-sign-in.js +169 -0
  78. package/dist/src/markdown.d.ts +5 -0
  79. package/dist/src/markdown.js +5 -2
  80. package/dist/src/mcp.js +11 -0
  81. package/dist/src/membership.d.ts +8 -1
  82. package/dist/src/membership.js +15 -5
  83. package/dist/src/model-metadata.js +14 -2
  84. package/dist/src/model-override.d.ts +10 -0
  85. package/dist/src/model-override.js +20 -0
  86. package/dist/src/opencode-cli-provider.d.ts +122 -0
  87. package/dist/src/opencode-cli-provider.js +415 -0
  88. package/dist/src/opencode-provider.js +23 -8
  89. package/dist/src/palette.d.ts +2 -0
  90. package/dist/src/palette.js +2 -0
  91. package/dist/src/permissions.d.ts +19 -1
  92. package/dist/src/permissions.js +30 -1
  93. package/dist/src/powershell-pool.d.ts +2 -2
  94. package/dist/src/powershell-pool.js +18 -5
  95. package/dist/src/provider-connection.js +36 -0
  96. package/dist/src/provider-engine.d.ts +2 -1
  97. package/dist/src/provider-engine.js +64 -13
  98. package/dist/src/provider-import.js +6 -1
  99. package/dist/src/provider-settings.js +22 -3
  100. package/dist/src/providers.d.ts +12 -1
  101. package/dist/src/providers.js +27 -8
  102. package/dist/src/pull-requests.d.ts +111 -17
  103. package/dist/src/pull-requests.js +308 -76
  104. package/dist/src/qa/qa-authorize.js +9 -1
  105. package/dist/src/react-runtime.js +76 -5
  106. package/dist/src/remote/engine-pool.js +1 -1
  107. package/dist/src/run-progress.js +6 -1
  108. package/dist/src/run-records.d.ts +133 -27
  109. package/dist/src/run-records.js +320 -40
  110. package/dist/src/runtime.d.ts +38 -1
  111. package/dist/src/runtime.js +27 -4
  112. package/dist/src/save-lock.d.ts +11 -0
  113. package/dist/src/save-lock.js +29 -2
  114. package/dist/src/sessions.js +4 -1
  115. package/dist/src/shell.js +4 -1
  116. package/dist/src/side-panel.d.ts +1 -1
  117. package/dist/src/side-panel.js +1 -1
  118. package/dist/src/skill-commands.d.ts +2 -0
  119. package/dist/src/skill-commands.js +2 -0
  120. package/dist/src/skills/bundled/create-agent/SKILL.md +81 -0
  121. package/dist/src/skills/bundled/create-skill/SKILL.md +81 -0
  122. package/dist/src/skills/bundled/doctor/SKILL.md +43 -0
  123. package/dist/src/skills/bundled/graph-manager/SKILL.md +97 -0
  124. package/dist/src/skills/bundled/graph-manager/errors.md +38 -0
  125. package/dist/src/skills/bundled/graph-manager/patterns.md +78 -0
  126. package/dist/src/skills/bundled/manage-mcp/SKILL.md +75 -0
  127. package/dist/src/skills/bundled/manage-mcp/probe.md +165 -0
  128. package/dist/src/skills/bundled/manage-skills/SKILL.md +67 -0
  129. package/dist/src/skills/bundled/provenance.json +50 -0
  130. package/dist/src/skills/bundled/write-instructions/SKILL.md +42 -0
  131. package/dist/src/skills/invocable-skills.d.ts +41 -0
  132. package/dist/src/skills/invocable-skills.js +49 -0
  133. package/dist/src/skills/prompt-skills.d.ts +1 -0
  134. package/dist/src/skills/prompt-skills.js +33 -0
  135. package/dist/src/skills/runtime-skills.d.ts +4 -0
  136. package/dist/src/skills/runtime-skills.js +21 -0
  137. package/dist/src/structured-step.d.ts +55 -0
  138. package/dist/src/structured-step.js +85 -0
  139. package/dist/src/subagent-run.d.ts +1 -1
  140. package/dist/src/subagent-run.js +29 -33
  141. package/dist/src/telemetry/schema.d.ts +2 -2
  142. package/dist/src/telemetry/schema.js +3 -2
  143. package/dist/src/terminal-ui.d.ts +29 -0
  144. package/dist/src/terminal-ui.js +112 -28
  145. package/dist/src/timers.d.ts +21 -2
  146. package/dist/src/timers.js +12 -4
  147. package/dist/src/tool-names.d.ts +18 -0
  148. package/dist/src/tool-names.js +26 -0
  149. package/dist/src/tools.js +45 -11
  150. package/dist/src/trajectory.js +32 -12
  151. package/dist/src/types.d.ts +23 -0
  152. package/docs/agents/mcp-server.md +13 -1
  153. package/docs/agents/subagent-mode.md +7 -4
  154. package/docs/concepts/security.md +2 -0
  155. package/docs/getting-started/configure-providers.md +29 -2
  156. package/docs/guides/browser.md +12 -0
  157. package/docs/guides/desktop-app.md +10 -3
  158. package/docs/guides/graph-builder.md +8 -0
  159. package/docs/reference/config.md +2 -2
  160. package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +125 -0
  161. package/docs/superpowers/specs/2026-11-01-pr-section-design.md +7 -0
  162. package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +206 -0
  163. package/package.json +1 -1
  164. package/tests/permissions-test-plan.md +2 -1
@@ -1,4 +1,4 @@
1
- import { appendFile, link, mkdir, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
1
+ import { appendFile, link, mkdir, readFile, readdir, rename, rm, stat, truncate, writeFile } from 'node:fs/promises';
2
2
  import { randomUUID } from 'node:crypto';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { acquireSaveLock, SaveLockBusyError } from './save-lock.js';
@@ -1086,16 +1086,16 @@ export function runRecordPath(directory, runId, extension) {
1086
1086
  return join(runRecordsDirectory(directory), `${runId}.${extension}`);
1087
1087
  }
1088
1088
  /**
1089
- * Record that a run's journal stopped accepting events, durably and separately from the sink that
1090
- * failed.
1089
+ * Record that a run's journal is missing events, durably and separately from the sink that failed.
1091
1090
  *
1092
- * The journal is rewritten for every runtime event, and the engine deliberately keeps running when
1093
- * one append fails (a full disk must not kill the user's work). What it must not keep is the
1094
- * pretence that the file is a complete account: the lines after the failure are present, so the
1095
- * gap is invisible to a reader — a crashed attempt would replay to a position missing whichever
1096
- * completion the failure ate, and resume by repeating it. This marker is the failure's own record
1097
- * (best effort: if even it cannot be written, the resume read of the record's flag is what stands),
1098
- * and `journalWriteFailed` is what a resume consults before trusting the lineage.
1091
+ * The engine deliberately keeps running when an append fails (a full disk must not kill the user's
1092
+ * work), and the journal writer holds what it could not write and writes it once the file accepts
1093
+ * appends again. This marker covers the window in between and the cases that never close: the
1094
+ * process dying while events are still held, or the writer giving some up. The lines after such a
1095
+ * gap are present, so nothing in the file itself reveals it. The writer removes the marker once
1096
+ * everything it held has landed (best effort both ways: if the marker cannot be written, the
1097
+ * record's own flag is what stands), and `journalWriteFailed` is what a resume reads to warn that a
1098
+ * step may repeat.
1099
1099
  */
1100
1100
  export async function noteJournalWriteFailure(directory, runId, detail) {
1101
1101
  try {
@@ -1105,9 +1105,9 @@ export async function noteJournalWriteFailure(directory, runId, detail) {
1105
1105
  catch { /* the marker is best effort; the record's own flag covers a write that failed here */ }
1106
1106
  }
1107
1107
  /**
1108
- * Whether a run's journal is known to be incomplete — the marker the sink left, or the flag the
1109
- * attempt's result record carries. An attempt whose journal is incomplete is never a resume source:
1110
- * replaying it would reconstruct a position whose missing events repeat completed work.
1108
+ * Whether a run's journal is known to be incomplete: the marker the writer left, or the flag the
1109
+ * attempt's result record carries. A resume still continues such an attempt (a session must
1110
+ * always be resumable), but it tells the user that a step the missing events recorded may repeat.
1111
1111
  */
1112
1112
  export async function journalWriteFailed(directory, runId) {
1113
1113
  try {
@@ -1123,45 +1123,325 @@ export async function journalWriteFailed(directory, runId) {
1123
1123
  return false;
1124
1124
  }
1125
1125
  }
1126
+ /** How much a journal writer holds in memory while its file refuses appends, before it gives up. */
1127
+ const MAX_HELD_JOURNAL_BYTES = 16 * 1024 * 1024;
1126
1128
  /**
1127
- * Record that a run's checkpoints stopped being written, durably and separately from the sink
1128
- * that failed.
1129
+ * The journal sink for one run: ordered appends that leave no silent hole.
1129
1130
  *
1130
- * A checkpoint is the conversation a resume re-enters a node with: the node's own messages at the
1131
- * moment it stopped. A write that failed leaves that conversation unwritten, so a resume would
1132
- * re-enter the node from its opening task and repeat the tool calls it had already made — the
1133
- * same harm a hole in the journal does, reached through a different file. The engine keeps the
1134
- * run working (a full disk must not kill the user's work), but the attempt stops being a resume
1135
- * source. This marker is the failure's own record (best effort: if even it cannot be written, the
1136
- * resume read of the record's flag is what stands), and `checkpointWriteFailed` is what a resume
1137
- * consults before trusting the lineage.
1131
+ * The filesystem does not finish concurrent appends in the order they were started, so events are
1132
+ * written one after another. An event the file refuses (a full disk, most often) is held rather
1133
+ * than dropped, and each later event first retries everything held, oldest first. A disk that
1134
+ * fills for a minute and is then freed leaves a complete journal behind, not a permanently
1135
+ * untrusted one.
1136
+ *
1137
+ * A failed append can still have written part of its line, so after any failed write the next one
1138
+ * measures the file before it appends anything. When the file grew past the length the writer last
1139
+ * knew to be whole lines, it is cut back first, so a retried event neither merges with its own torn
1140
+ * fragment nor appears twice. While the file cannot be measured (or is not a regular file), nothing
1141
+ * is appended: the events stay held, and the journal cannot be reported complete. When even the cut
1142
+ * fails, the next line starts on a fresh line and the journal is reported as no longer complete: the
1143
+ * fragment cannot be told apart from an event that really ran. The same holds when the file turns
1144
+ * out shorter than the lines already written to it: something else cut it, and those lines are gone.
1145
+ *
1146
+ * While anything is held, or after anything was given up, the run's `journal-error` marker says
1147
+ * so. Events are given up only when what is held passes `maxHeldBytes`. Once everything held has
1148
+ * landed and nothing was given up, the writer removes the marker again.
1138
1149
  */
1139
- export async function noteCheckpointWriteFailure(directory, runId, detail) {
1140
- try {
1141
- await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1142
- await appendFile(runRecordPath(directory, runId, 'checkpoint-error'), `${new Date().toISOString()}\t${detail.replace(/[\r\n]+/g, ' ')}\n`, { mode: 0o600 });
1143
- }
1144
- catch { /* the marker is best effort; the record's own flag covers a write that failed here */ }
1150
+ export function createRunJournalWriter(directory, runId, options = {}) {
1151
+ const path = runRecordPath(directory, runId, 'jsonl');
1152
+ const files = {
1153
+ appendFile: (target, data) => appendFile(target, data, { mode: 0o600 }),
1154
+ truncate: (target, size) => truncate(target, size),
1155
+ size: async (target) => {
1156
+ try {
1157
+ const info = await stat(target);
1158
+ return info.isFile() ? info.size : undefined;
1159
+ }
1160
+ catch (error) {
1161
+ if (error.code === 'ENOENT')
1162
+ return 0;
1163
+ throw error;
1164
+ }
1165
+ },
1166
+ mkdir: async (target) => { await mkdir(target, { recursive: true, mode: 0o700 }); },
1167
+ ...options.files,
1168
+ };
1169
+ const limit = options.maxHeldBytes ?? MAX_HELD_JOURNAL_BYTES;
1170
+ const held = [];
1171
+ let heldBytes = 0;
1172
+ // The file's length as far as this writer knows it: every byte before it is part of a whole line,
1173
+ // unless `separate` says a fragment the writer could not cut is at the end. Unknown until the
1174
+ // first write measures the file.
1175
+ let size;
1176
+ // The next line must start on a fresh line, because a torn fragment is still at the end of the file.
1177
+ let separate = false;
1178
+ // An event was given up, or a torn fragment could not be cut: the journal can no longer prove it is
1179
+ // a complete account, however many later appends succeed.
1180
+ let lost = false;
1181
+ // A write failed since the last time everything held reached the file.
1182
+ let failing = false;
1183
+ // The last write failed, so the file's end is not known to be where `size` says: it may hold a
1184
+ // fragment of the refused line, or have changed since. The next write measures it first.
1185
+ let unverified = false;
1186
+ let chain = Promise.resolve();
1187
+ const writeLine = async (line) => {
1188
+ if (size === undefined || unverified) {
1189
+ // A measurement that fails throws before anything is appended: the line stays held, and the
1190
+ // next write measures again.
1191
+ const actual = await files.size(path);
1192
+ if (actual === undefined) {
1193
+ throw Object.assign(new Error('The run journal path is not a regular file'), { code: 'EISDIR' });
1194
+ }
1195
+ if (size === undefined) {
1196
+ size = actual;
1197
+ }
1198
+ else if (actual > size) {
1199
+ // `size` only grows when an append succeeds, so it is still the length before the refused
1200
+ // one: everything past it is a torn fragment of a line that is still held.
1201
+ try {
1202
+ await files.truncate(path, size);
1203
+ }
1204
+ catch {
1205
+ size = actual;
1206
+ separate = true;
1207
+ lost = true;
1208
+ }
1209
+ }
1210
+ else if (actual < size) {
1211
+ // Something else cut the file, and lines this writer had written are gone.
1212
+ size = actual;
1213
+ separate = true;
1214
+ lost = true;
1215
+ }
1216
+ unverified = false;
1217
+ }
1218
+ const data = separate ? `\n${line}` : line;
1219
+ try {
1220
+ await files.appendFile(path, data);
1221
+ }
1222
+ catch (error) {
1223
+ // A configuration home that has never held a run has no `runs/` directory yet. Nothing was
1224
+ // written, so the append is simply repeated once the directory exists.
1225
+ if (error.code !== 'ENOENT')
1226
+ throw error;
1227
+ await files.mkdir(runRecordsDirectory(directory));
1228
+ await files.appendFile(path, data);
1229
+ }
1230
+ size += Buffer.byteLength(data);
1231
+ separate = false;
1232
+ };
1233
+ const drain = async () => {
1234
+ while (held.length > 0) {
1235
+ const line = held[0];
1236
+ try {
1237
+ await writeLine(line);
1238
+ }
1239
+ catch (error) {
1240
+ // Whatever failed, the file is measured before the next append rather than here: a probe
1241
+ // that fails right after a torn append must not let a later retry write after the fragment.
1242
+ unverified = true;
1243
+ throw error;
1244
+ }
1245
+ held.shift();
1246
+ heldBytes -= Buffer.byteLength(line);
1247
+ }
1248
+ };
1249
+ const attempt = async () => {
1250
+ try {
1251
+ await drain();
1252
+ if (failing && !lost) {
1253
+ // Everything the file refused has now landed, in order: the journal is a complete account
1254
+ // again, and the marker that said otherwise goes.
1255
+ failing = false;
1256
+ await rm(runRecordPath(directory, runId, 'journal-error'), { force: true }).catch(() => { });
1257
+ }
1258
+ }
1259
+ catch (error) {
1260
+ failing = true;
1261
+ if (heldBytes > limit) {
1262
+ // Holding more would trade the user's memory for a journal that is already late. What is
1263
+ // held is given up, and the marker stays for good.
1264
+ held.length = 0;
1265
+ heldBytes = 0;
1266
+ lost = true;
1267
+ }
1268
+ await noteJournalWriteFailure(directory, runId, error instanceof Error ? error.message : String(error));
1269
+ try {
1270
+ options.onFailure?.(error);
1271
+ }
1272
+ catch { /* a reporter that throws must not break the chain */ }
1273
+ }
1274
+ };
1275
+ return {
1276
+ append(event) {
1277
+ // Serialized now, not when the chain reaches it: the event is recorded as it was when it
1278
+ // happened, even if its object is changed while earlier appends are still landing.
1279
+ let line;
1280
+ let unserializable;
1281
+ try {
1282
+ line = `${JSON.stringify(event)}\n`;
1283
+ }
1284
+ catch (error) {
1285
+ unserializable = error;
1286
+ }
1287
+ chain = chain.then(async () => {
1288
+ if (line === undefined) {
1289
+ // An event that cannot be serialized can never be written, so it is a gap like any other.
1290
+ failing = true;
1291
+ lost = true;
1292
+ await noteJournalWriteFailure(directory, runId, unserializable instanceof Error ? unserializable.message : String(unserializable));
1293
+ try {
1294
+ options.onFailure?.(unserializable);
1295
+ }
1296
+ catch { /* a reporter that throws must not break the chain */ }
1297
+ return;
1298
+ }
1299
+ held.push(line);
1300
+ heldBytes += Buffer.byteLength(line);
1301
+ await attempt();
1302
+ });
1303
+ return chain;
1304
+ },
1305
+ async settle() {
1306
+ chain = chain.then(async () => { if (held.length > 0)
1307
+ await attempt(); });
1308
+ await chain;
1309
+ return held.length === 0 && !lost;
1310
+ },
1311
+ get intact() { return held.length === 0 && !lost; },
1312
+ };
1313
+ }
1314
+ /** A visit as the record and the marker carry it: no `generation` key when the writer did not know it. */
1315
+ function checkpointVisit(nodeId, generation) {
1316
+ return generation === undefined ? { nodeId } : { nodeId, generation };
1317
+ }
1318
+ /**
1319
+ * One marker line: when, which visit (as JSON, so any node id survives the tab-separated format),
1320
+ * and what failed. Lines from builds that predate the visit column carry the detail in the second
1321
+ * field, which never parses as a visit, so their node is unknown.
1322
+ */
1323
+ function checkpointFailureLine(visit, detail) {
1324
+ return `${new Date().toISOString()}\t${JSON.stringify(visit)}\t${detail.replace(/[\r\n\t]+/g, ' ')}\n`;
1325
+ }
1326
+ /** A visit read back from a record or a marker, or `undefined` when the value is not one. */
1327
+ function parseCheckpointVisit(value) {
1328
+ if (typeof value !== 'object' || value === null)
1329
+ return undefined;
1330
+ const { nodeId, generation } = value;
1331
+ if (typeof nodeId !== 'string' || !nodeId)
1332
+ return undefined;
1333
+ if (generation !== undefined && !(typeof generation === 'number' && Number.isSafeInteger(generation) && generation >= 0))
1334
+ return undefined;
1335
+ return checkpointVisit(nodeId, generation);
1145
1336
  }
1146
1337
  /**
1147
- * Whether a run's checkpoints are known to be incomplete — the marker the sink left, or the flag
1148
- * the attempt's result record carries. An attempt whose checkpoint could not be written is never
1149
- * a resume source: the resume would re-enter the node from its opening task and repeat the work
1150
- * that node had already done.
1338
+ * Track one run's checkpoint writes. The caller reports every write's outcome in the order the
1339
+ * writes ran (the checkpoint writers already serialize them). The run's final record carries
1340
+ * `checkpointIntegrity: 'failed'` and the `failures` list while `intact` is false.
1341
+ */
1342
+ export function createCheckpointFailureTracker(directory, runId) {
1343
+ const marker = runRecordPath(directory, runId, 'checkpoint-error');
1344
+ const failures = new Map();
1345
+ const key = (visit) => JSON.stringify([visit.nodeId, visit.generation ?? null]);
1346
+ return {
1347
+ async failed(visit, error) {
1348
+ const recorded = checkpointVisit(visit.nodeId, visit.generation);
1349
+ const line = checkpointFailureLine(recorded, error instanceof Error ? error.message : String(error));
1350
+ failures.set(key(recorded), { visit: recorded, line });
1351
+ try {
1352
+ await mkdir(runRecordsDirectory(directory), { recursive: true, mode: 0o700 });
1353
+ await appendFile(marker, line, { mode: 0o600 });
1354
+ }
1355
+ catch { /* the marker is best effort; the final record carries the whole list */ }
1356
+ },
1357
+ async succeeded(visit) {
1358
+ if (!failures.delete(key(visit)))
1359
+ return;
1360
+ try {
1361
+ if (failures.size === 0)
1362
+ await rm(marker, { force: true });
1363
+ else
1364
+ await writeFile(marker, [...failures.values()].map(entry => entry.line).join(''), { mode: 0o600 });
1365
+ }
1366
+ catch { /* a marker left behind only adds a warning to a later resume */ }
1367
+ },
1368
+ get intact() { return failures.size === 0; },
1369
+ get failures() { return [...failures.values()].map(entry => ({ ...entry.visit })); },
1370
+ };
1371
+ }
1372
+ /**
1373
+ * Whether a run's checkpoints are known to be incomplete: the record's flag, or the marker the
1374
+ * tracker left. A resume still continues such an attempt, and tells the user that a visit whose
1375
+ * conversation was not saved may repeat work.
1151
1376
  */
1152
1377
  export async function checkpointWriteFailed(directory, runId) {
1378
+ return (await checkpointFailure(directory, runId)) !== undefined;
1379
+ }
1380
+ /**
1381
+ * The checkpoint failure a run left unhealed: `undefined` when there is none.
1382
+ *
1383
+ * The final record comes first. It is written once every checkpoint write has settled, from the
1384
+ * tracker itself, so its list is the whole failure set — while the marker is appended as failures
1385
+ * happen, and the same full disk that failed a checkpoint can fail the marker line naming it. A
1386
+ * record that is flagged but carries no list (a build that predates the list) therefore names
1387
+ * nothing and dates nothing: its marker may be missing the very failure that matters. Only a run
1388
+ * with no final record (one that crashed) is read from its marker, best effort.
1389
+ *
1390
+ * `visits` is absent when the failures cannot be named. `at` lets a resume see that a checkpoint
1391
+ * saved after the newest failure already replaced whatever the failed write would have written.
1392
+ */
1393
+ export async function checkpointFailure(directory, runId) {
1394
+ let record;
1153
1395
  try {
1154
- await stat(runRecordPath(directory, runId, 'checkpoint-error'));
1155
- return true;
1396
+ record = JSON.parse(await readFile(runRecordPath(directory, runId, 'json'), 'utf8'));
1156
1397
  }
1157
- catch { /* no marker: the record flag is the only other account */ }
1398
+ catch {
1399
+ record = undefined;
1400
+ }
1401
+ if (record?.checkpointIntegrity === 'failed') {
1402
+ const listed = Array.isArray(record.checkpointFailures) ? record.checkpointFailures.map(parseCheckpointVisit) : undefined;
1403
+ return listed !== undefined && listed.length > 0 && listed.every(visit => visit !== undefined)
1404
+ ? { visits: listed } : {};
1405
+ }
1406
+ let text;
1158
1407
  try {
1159
- const value = JSON.parse(await readFile(runRecordPath(directory, runId, 'json'), 'utf8'));
1160
- return value.checkpointIntegrity === 'failed';
1408
+ text = await readFile(runRecordPath(directory, runId, 'checkpoint-error'), 'utf8');
1161
1409
  }
1162
- catch {
1163
- return false;
1410
+ catch (error) {
1411
+ // A marker that exists but cannot be read is still a failure, only an unnamed one.
1412
+ return error.code === 'ENOENT' ? undefined : {};
1413
+ }
1414
+ const visits = new Map();
1415
+ let named = true;
1416
+ let at;
1417
+ let dated = true;
1418
+ for (const line of text.split('\n')) {
1419
+ if (!line.trim())
1420
+ continue;
1421
+ const [time, field] = line.split('\t');
1422
+ if (time !== undefined && !Number.isNaN(Date.parse(time))) {
1423
+ if (at === undefined || Date.parse(time) > Date.parse(at))
1424
+ at = time;
1425
+ }
1426
+ else
1427
+ dated = false;
1428
+ let parsed;
1429
+ try {
1430
+ parsed = JSON.parse(field ?? '');
1431
+ }
1432
+ catch {
1433
+ parsed = undefined;
1434
+ }
1435
+ const visit = parseCheckpointVisit(parsed);
1436
+ if (visit === undefined)
1437
+ named = false;
1438
+ else
1439
+ visits.set(JSON.stringify([visit.nodeId, visit.generation ?? null]), visit);
1164
1440
  }
1441
+ return {
1442
+ ...(named && visits.size > 0 ? { visits: [...visits.values()] } : {}),
1443
+ ...(dated && at !== undefined ? { at } : {}),
1444
+ };
1165
1445
  }
1166
1446
  /**
1167
1447
  * The checkpoint file for one node of a run: `<runId>.checkpoint.<node-key>`.
@@ -10,7 +10,7 @@ import type { DecisionManager } from './decision/DecisionManager.js';
10
10
  import type { DecisionBatch } from './decision/types.js';
11
11
  export declare const DEFAULT_GRAPH: Readonly<{
12
12
  id: "default";
13
- name: "Software Engineer";
13
+ name: "Andorra Agent";
14
14
  revision: "1";
15
15
  nodes: readonly (Readonly<{
16
16
  id: "engineer";
@@ -149,13 +149,24 @@ export interface AgentContinuationState {
149
149
  * the reference text alone (the pixels were sent with the turn that owned them and are not
150
150
  * re-attached), so the block must not claim an image input.
151
151
  */
152
+ /**
153
+ * How a `set_timer` reminder reads to the model: the agent's own note to itself, never the user's words.
154
+ *
155
+ * Used where it is delivered (a live steer, or the direction of a continuation) and where a retained turn is
156
+ * rendered again later, so a reminder the agent wrote can never come back as an instruction the user gave.
157
+ */
158
+ export declare function timerReminderText(prompt: string): string;
159
+ /** What delivered a retained turn's message instead of the user, as `ConversationTurn.wake` records it. */
160
+ type RetainedWake = 'timer' | 'auto-fix';
152
161
  export declare function turnModelTask(turn: {
153
162
  task: string;
154
163
  direction?: string;
164
+ wake?: RetainedWake;
155
165
  attachments?: readonly UserAttachmentRef[];
156
166
  steers?: {
157
167
  text: string;
158
168
  attachments?: readonly UserAttachmentRef[];
169
+ wake?: RetainedWake;
159
170
  }[];
160
171
  }): string;
161
172
  export interface RunOptions {
@@ -247,6 +258,7 @@ export interface RunOptions {
247
258
  onUsage?: (usage: Usage, origin?: {
248
259
  invocationId?: string;
249
260
  final?: boolean;
261
+ localModel?: boolean;
250
262
  }) => void;
251
263
  subagentId?: string;
252
264
  /**
@@ -335,6 +347,21 @@ export interface ResolvedGraphModel {
335
347
  baseUrl?: string;
336
348
  }
337
349
  export interface GraphRunOptions extends RunOptions {
350
+ /**
351
+ * Whether an installed skill, enabled or not, answers to a `/name` (the extension snapshot's
352
+ * `claimsSkillName`). A node prompt naming one that this node cannot load reports it as missing
353
+ * rather than falling back to an Andorra skill of the same short name.
354
+ */
355
+ installedSkillClaims?: (name: string) => boolean;
356
+ /**
357
+ * Pull messages meant for one graph node only, polled by every running node at its turn boundaries.
358
+ *
359
+ * `getSteeringMessages` is one queue that a single branch of a parallel group reads at a time, which is right
360
+ * for what the user types into the run and wrong for a `set_timer` reminder: that belongs to the node that set
361
+ * it, and a sibling branch that happened to own the shared queue would read it instead. Leaving it unset keeps
362
+ * the shared queue as the only source.
363
+ */
364
+ getNodeSteeringMessages?: (nodeId: string, signal: AbortSignal) => Promise<Message[]>;
338
365
  decisionManager?: import('./decision/DecisionManager.js').DecisionManager;
339
366
  /**
340
367
  * Set by the run policy: an Agent node uses `decisionManager` only when it sets `jevEnabled: true`,
@@ -354,6 +381,16 @@ export interface GraphRunOptions extends RunOptions {
354
381
  * the configured default and an opted-in router may re-tier a node that pins nothing itself.
355
382
  */
356
383
  modelPinned?: boolean;
384
+ /**
385
+ * Seed `history` into the first agent node the run starts — the entry node, or the first agent
386
+ * after an entry that is not one — whatever its own `contextPolicy.history` says.
387
+ *
388
+ * Set when a session switches to another graph: the new graph starts from its entry node, and its
389
+ * first agent is told what the session did before, since nothing else of the earlier work carries
390
+ * over. Only that first fresh activation gets the history; a visit that re-enters a saved
391
+ * conversation already holds it, and every later activation keeps its own policy.
392
+ */
393
+ entryHistory?: boolean;
357
394
  /** The configured providers' ids and model lists, for validating adaptive-routing tiers. */
358
395
  configuredModels?: {
359
396
  id: string;
@@ -1,8 +1,9 @@
1
1
  import { attachmentReferenceBlock } from './attachments.js';
2
2
  import { createRunTelemetry, recordModelUse } from './telemetry/capture.js';
3
3
  import { pricingFor } from './model-tiers.js';
4
+ import { bucketEndpoint } from './telemetry/schema.js';
4
5
  export const DEFAULT_GRAPH = Object.freeze({
5
- id: 'default', name: 'Software Engineer', revision: '1',
6
+ id: 'default', name: 'Andorra Agent', revision: '1',
6
7
  nodes: Object.freeze([
7
8
  Object.freeze({ id: 'engineer', type: 'agent', executor: 'react-basic' }),
8
9
  Object.freeze({ id: 'done', type: 'end' }),
@@ -25,14 +26,30 @@ export { DEFAULT_LIMITS, LIMIT_KEYS, isUnlimited, isUnlimitedAlias, resolveLimit
25
26
  * the reference text alone (the pixels were sent with the turn that owned them and are not
26
27
  * re-attached), so the block must not claim an image input.
27
28
  */
29
+ /**
30
+ * How a `set_timer` reminder reads to the model: the agent's own note to itself, never the user's words.
31
+ *
32
+ * Used where it is delivered (a live steer, or the direction of a continuation) and where a retained turn is
33
+ * rendered again later, so a reminder the agent wrote can never come back as an instruction the user gave.
34
+ */
35
+ export function timerReminderText(prompt) {
36
+ return `[Timer] A reminder you set for yourself with set_timer (not a message from the user): ${prompt}`;
37
+ }
28
38
  export function turnModelTask(turn) {
29
- const text = turn.direction === undefined ? turn.task : `${turn.task}\n\nDirection given when the attempt continued: ${turn.direction}`;
39
+ // A wake's message keeps its provenance in every later request: the agent's own reminder (or the comments an
40
+ // Auto-fix wake brought) must not be replayed as something the user asked for.
41
+ const woken = (message) => turn.wake === 'auto-fix' ? `Delivered by Auto-fix (not a message from the user): ${message}` : timerReminderText(message);
42
+ const text = turn.direction === undefined
43
+ ? (turn.wake === undefined ? turn.task : woken(turn.task))
44
+ : `${turn.task}\n\n${turn.wake === undefined ? `Direction given when the attempt continued: ${turn.direction}` : `Delivered when the attempt continued: ${woken(turn.direction)}`}`;
30
45
  // A steer was read inside the turn that was running, so it renders as part of that turn rather
31
46
  // than as a turn of its own — the model sees the instruction that redirected the work it is
32
47
  // reading about. Files a steer carried are named without claiming image inputs, exactly as the
33
48
  // turn's own attachments are.
34
49
  const withSteers = (turn.steers ?? []).reduce((text, steer) => {
35
- const line = `\n\nSteering message the user sent while this attempt ran: ${steer.text}`;
50
+ const line = steer.wake === undefined
51
+ ? `\n\nSteering message the user sent while this attempt ran: ${steer.text}`
52
+ : `\n\nRead while this attempt ran: ${timerReminderText(steer.text)}`;
36
53
  const refs = steer.attachments?.length ? `\n\n${attachmentReferenceBlock(steer.attachments, { imagesIncluded: false })}` : '';
37
54
  return `${text}${line}${refs}`;
38
55
  }, text);
@@ -44,7 +61,13 @@ export async function generateWithUsage(options, result, request) {
44
61
  // Every delta from this one request carries the request's identity, so a consumer that
45
62
  // pairs completions with the window they opened (the footer's token-speed meter) can do
46
63
  // so without guessing across concurrent requests.
47
- const origin = request.context?.invocationId ? { invocationId: request.context.invocationId } : undefined;
64
+ // Endpoint placement, not protocol: OpenAI-compatible requests may be local or hosted.
65
+ // Unknown endpoints are deliberately not counted as local cache measurements.
66
+ const localModel = bucketEndpoint(options.telemetryIdentity?.baseUrl) === 'local';
67
+ const origin = request.context?.invocationId || localModel ? {
68
+ ...(request.context?.invocationId ? { invocationId: request.context.invocationId } : {}),
69
+ ...(localModel ? { localModel: true } : {}),
70
+ } : undefined;
48
71
  const add = (delta, final = false) => {
49
72
  for (const target of [result.usage, ...(options.budget ? [options.budget.usage] : [])]) {
50
73
  target.requests += delta.requests;
@@ -5,5 +5,16 @@ export declare class SaveLockBusyError extends Error {
5
5
  export declare function acquireSaveLock(folder: string, options?: {
6
6
  legacyGraceMs?: number;
7
7
  }): Promise<() => Promise<void>>;
8
+ /**
9
+ * Remove a folder whose save lock the caller holds.
10
+ *
11
+ * The lock itself lives inside the folder, so removing in place takes the lock away before the
12
+ * walk finishes and lets a concurrent writer acquire a replacement in the still-present
13
+ * directory — its revision then races the removal's deletes and renames, and a pending unlink
14
+ * can take the writer's just-published latest pointer. The folder leaves the live path in one
15
+ * rename while the lock is held, and the detached tree is removed where no writer can reach it.
16
+ * `onDetached` runs in that window (a test seam for racing a writer).
17
+ */
18
+ export declare function removeLockedFolder(folder: string, onDetached?: () => Promise<void>): Promise<void>;
8
19
  /** A crash may leave a numbered snapshot before latest.json was published. Keep its bytes for inspection. */
9
20
  export declare function archiveUnpublishedSnapshot(folder: string, revision: number): Promise<void>;
@@ -1,7 +1,7 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
2
  import { hostname } from 'node:os';
3
- import { join } from 'node:path';
4
- import { link, mkdir, readFile, rename, rmdir, stat, unlink, writeFile } from 'node:fs/promises';
3
+ import { basename, dirname, join } from 'node:path';
4
+ import { link, mkdir, readFile, rename, rm, rmdir, stat, unlink, writeFile } from 'node:fs/promises';
5
5
  export class SaveLockBusyError extends Error {
6
6
  constructor() { super('Another save is in progress. Retry after it finishes.'); this.name = 'SaveLockBusyError'; }
7
7
  }
@@ -161,6 +161,33 @@ export async function acquireSaveLock(folder, options = {}) {
161
161
  throw error; });
162
162
  };
163
163
  }
164
+ /**
165
+ * Remove a folder whose save lock the caller holds.
166
+ *
167
+ * The lock itself lives inside the folder, so removing in place takes the lock away before the
168
+ * walk finishes and lets a concurrent writer acquire a replacement in the still-present
169
+ * directory — its revision then races the removal's deletes and renames, and a pending unlink
170
+ * can take the writer's just-published latest pointer. The folder leaves the live path in one
171
+ * rename while the lock is held, and the detached tree is removed where no writer can reach it.
172
+ * `onDetached` runs in that window (a test seam for racing a writer).
173
+ */
174
+ export async function removeLockedFolder(folder, onDetached) {
175
+ const detached = join(dirname(folder), `.removing-${basename(folder)}-${randomUUID()}`);
176
+ try {
177
+ await rename(folder, detached);
178
+ }
179
+ catch (error) {
180
+ if (error.code !== 'ENOENT')
181
+ throw error;
182
+ return;
183
+ }
184
+ try {
185
+ await onDetached?.();
186
+ }
187
+ finally {
188
+ await rm(detached, { recursive: true, force: true });
189
+ }
190
+ }
164
191
  /** A crash may leave a numbered snapshot before latest.json was published. Keep its bytes for inspection. */
165
192
  export async function archiveUnpublishedSnapshot(folder, revision) {
166
193
  let latest = 0;
@@ -174,7 +174,10 @@ export function validSavedSession(value) {
174
174
  const counter = value[key];
175
175
  return typeof counter === 'number' && Number.isFinite(counter) && counter >= 0;
176
176
  })
177
- && validCounter(value.cacheRead) && validCounter(value.cacheWrite);
177
+ && validCounter(value.cacheRead) && validCounter(value.cacheWrite)
178
+ && validCounter(value.localCacheInputTokens)
179
+ && validCounter(value.localCacheReadTokens)
180
+ && (value.localCacheReadTokens ?? 0) <= (value.localCacheInputTokens ?? 0);
178
181
  // A lineage's points are cumulative snapshots of the work: each one is at least the one before
179
182
  // it, none of them is more than the record's own totals, and none of them counts more turns
180
183
  // than the record has. A record that breaks these would make the totals drop a turn or a
package/dist/src/shell.js CHANGED
@@ -121,7 +121,10 @@ async function stopPosix(child, marker) {
121
121
  /** Cleanup runs in the host: never discover its executable through cwd or PATH. */
122
122
  export async function resolveTrustedTaskkill(workspace, env = process.env) {
123
123
  const failure = () => new Error('Shell cleanup requires a validated absolute SystemRoot\\System32\\taskkill.exe outside the workspace. No PATH fallback is allowed.');
124
- const systemRoot = env.SystemRoot;
124
+ // Windows variable names ignore case, but a plain-object copy of the environment keeps the spelling
125
+ // it was given: Git Bash exports SYSTEMROOT. Spellings that disagree are ambiguous and refused.
126
+ const spellings = new Set(Object.entries(env).filter(([key]) => key.toLowerCase() === 'systemroot').map(([, value]) => value));
127
+ const systemRoot = spellings.size === 1 ? [...spellings][0] : undefined;
125
128
  // Reject relative, network and device namespaces before probing the filesystem.
126
129
  if (!systemRoot || !/^[a-z]:[\\/]/i.test(systemRoot) || systemRoot.slice(2).includes(':'))
127
130
  throw failure();
@@ -122,7 +122,7 @@ export declare const panelWidth: (columns: number) => number;
122
122
  /**
123
123
  * Whether the selected graph is a custom one.
124
124
  *
125
- * The built-in Software Engineer harness is stored under `'default'` (and answers to its own
125
+ * The built-in Andorra Agent harness is stored under `'default'` (and answers to its own
126
126
  * id when a graph file was never written), so both spell the default; anything else is a
127
127
  * user-authored graph, which is what the zoom section exists for.
128
128
  */
@@ -30,7 +30,7 @@ export const panelWidth = (columns) => Math.min(44, Math.max(28, Math.floor(colu
30
30
  /**
31
31
  * Whether the selected graph is a custom one.
32
32
  *
33
- * The built-in Software Engineer harness is stored under `'default'` (and answers to its own
33
+ * The built-in Andorra Agent harness is stored under `'default'` (and answers to its own
34
34
  * id when a graph file was never written), so both spell the default; anything else is a
35
35
  * user-authored graph, which is what the zoom section exists for.
36
36
  */