@andorra-labs/code 0.1.9 → 0.1.10

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 (96) hide show
  1. package/dist/src/agent-execution.js +20 -0
  2. package/dist/src/app-server/protocol.d.ts +108 -1
  3. package/dist/src/app-server/protocol.js +8 -1
  4. package/dist/src/app-server.d.ts +25 -0
  5. package/dist/src/app-server.js +156 -11
  6. package/dist/src/auth/index.d.ts +1 -1
  7. package/dist/src/auth/index.js +1 -1
  8. package/dist/src/auth/store.d.ts +17 -1
  9. package/dist/src/auth/store.js +25 -2
  10. package/dist/src/browser-ui/app.js +19 -19
  11. package/dist/src/browser-ui/index.html +7 -7
  12. package/dist/src/cli.js +10 -5
  13. package/dist/src/commands.d.ts +1 -1
  14. package/dist/src/commands.js +1 -1
  15. package/dist/src/completion-gates.js +1 -1
  16. package/dist/src/completion.d.ts +1 -1
  17. package/dist/src/completion.js +1 -1
  18. package/dist/src/decision/checks.js +1 -1
  19. package/dist/src/file-diff.d.ts +105 -0
  20. package/dist/src/file-diff.js +244 -0
  21. package/dist/src/graph-manager-chat.js +15 -15
  22. package/dist/src/graph-server.js +9 -9
  23. package/dist/src/graph-ui/app.js +123 -118
  24. package/dist/src/graph-ui/embed.js +9 -9
  25. package/dist/src/graph-ui/icons.js +1 -0
  26. package/dist/src/graph-ui/index.html +3 -3
  27. package/dist/src/graph-ui/manager-state.js +3 -3
  28. package/dist/src/graph-ui/manager.js +14 -14
  29. package/dist/src/graph-ui/skill-picker.js +6 -6
  30. package/dist/src/graph-ui/studio-canvas.js +15 -15
  31. package/dist/src/graph-ui/studio.js +40 -40
  32. package/dist/src/graph-ui/style.css +3 -1
  33. package/dist/src/graph-ui/theme.js +2 -2
  34. package/dist/src/graphs.d.ts +7 -1
  35. package/dist/src/graphs.js +12 -2
  36. package/dist/src/mcp.d.ts +75 -0
  37. package/dist/src/mcp.js +240 -8
  38. package/dist/src/membership-errors.js +1 -1
  39. package/dist/src/provider-keys.d.ts +5 -1
  40. package/dist/src/provider-keys.js +7 -3
  41. package/dist/src/provider-settings.d.ts +4 -1
  42. package/dist/src/provider-settings.js +46 -5
  43. package/dist/src/qa/guidance.js +6 -19
  44. package/dist/src/qa/index.d.ts +0 -2
  45. package/dist/src/qa/index.js +0 -2
  46. package/dist/src/qa/profile/QaProfile.d.ts +5 -1
  47. package/dist/src/qa/profile/QaProfile.js +6 -2
  48. package/dist/src/qa/tools.d.ts +19 -1
  49. package/dist/src/qa/tools.js +20 -145
  50. package/dist/src/react-runtime.js +13 -2
  51. package/dist/src/remote/engine-pool.js +18 -6
  52. package/dist/src/screen-selection.d.ts +38 -0
  53. package/dist/src/screen-selection.js +103 -0
  54. package/dist/src/session-changes.d.ts +117 -0
  55. package/dist/src/session-changes.js +796 -0
  56. package/dist/src/stall-recovery.d.ts +11 -0
  57. package/dist/src/stall-recovery.js +12 -0
  58. package/dist/src/telemetry/schema.d.ts +1 -1
  59. package/dist/src/telemetry/schema.js +1 -2
  60. package/dist/src/terminal-ui.d.ts +64 -20
  61. package/dist/src/terminal-ui.js +310 -80
  62. package/dist/src/tool-diff-stats.d.ts +9 -0
  63. package/dist/src/tool-diff-stats.js +20 -0
  64. package/dist/src/tool-names.d.ts +1 -1
  65. package/dist/src/tool-result-filter.js +1 -1
  66. package/dist/src/tools.js +26 -2
  67. package/dist/src/transcript.d.ts +11 -0
  68. package/dist/src/transcript.js +14 -2
  69. package/dist/src/types.d.ts +6 -0
  70. package/docs/guides/desktop-app.md +1 -1
  71. package/docs/guides/tui.md +9 -9
  72. package/package.json +1 -1
  73. package/dist/src/qa/api/http-runner.d.ts +0 -3
  74. package/dist/src/qa/api/http-runner.js +0 -47
  75. package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
  76. package/dist/src/qa/git/ChangeDetector.js +0 -177
  77. package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
  78. package/dist/src/qa/git/DiffReviewer.js +0 -115
  79. package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
  80. package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
  81. package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
  82. package/dist/src/qa/orchestrator/MergeGate.js +0 -40
  83. package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
  84. package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
  85. package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
  86. package/dist/src/qa/runners/CommandRunner.js +0 -96
  87. package/dist/src/qa/runners/TestRunner.d.ts +0 -21
  88. package/dist/src/qa/runners/TestRunner.js +0 -66
  89. package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
  90. package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
  91. package/dist/src/qa/runtime-detect.d.ts +0 -10
  92. package/dist/src/qa/runtime-detect.js +0 -72
  93. package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
  94. package/dist/src/qa/security/DependencyScanner.js +0 -167
  95. package/dist/src/qa/security/SecretScanner.d.ts +0 -3
  96. package/dist/src/qa/security/SecretScanner.js +0 -55
@@ -890,13 +890,33 @@ export async function executeAgentNode(node, options) {
890
890
  }
891
891
  ctx.signal.throwIfAborted();
892
892
  assertPlanMutationAllowed(ctx);
893
+ // The review record (Keep / Undo) keeps what each landed path holds before the patch writes or
894
+ // removes it, the same way an Edit's write is recorded, and holds its lock while the patch is applied
895
+ // so an Undo cannot interleave with the landing. A landing that does not land records nothing.
896
+ const recording = ctx.fileChanges ? await ctx.fileChanges.beforeWrite(files.map(file => join(prepared.landing.root, ...file.split('/')))).catch(() => undefined) : undefined;
897
+ const locked = recording ? await recording.begin().then(() => true, () => false) : false;
898
+ // The lock can wait behind an Undo; a stop or a switch to Plan mode in that wait still decides, and
899
+ // is refused exactly as it is just above, with the lock given back.
900
+ try {
901
+ ctx.signal.throwIfAborted();
902
+ assertPlanMutationAllowed(ctx);
903
+ }
904
+ catch (error) {
905
+ if (locked)
906
+ await recording.abort().catch(() => { });
907
+ throw error;
908
+ }
893
909
  let result;
894
910
  try {
895
911
  result = await applyLanding(prepared.landing, ctx.signal);
896
912
  }
897
913
  catch (error) {
914
+ if (locked)
915
+ await recording.abort().catch(() => { });
898
916
  return failed(error);
899
917
  }
918
+ if (locked)
919
+ await (result.landed ? recording.commit() : recording.abort()).catch(() => { });
900
920
  if (result.landed) {
901
921
  change.state = 'landed';
902
922
  change.landedFiles = result.files;
@@ -44,7 +44,7 @@ export declare const APP_SERVER_PROTOCOL_VERSION = 2;
44
44
  * one when a client omits it. An engine without it rebuilds a replaced entry from its own field
45
45
  * list, so a save through it silently drops the rename and every surface falls back to the id; a
46
46
  * client that can show the field must refuse the write first. */
47
- export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.resume.model", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser", "config.webSearch", "background.tasks", "workspace.warm", "browser.cookies.firefox", "sessions.compact"];
47
+ export declare const APP_SERVER_CAPABILITIES: readonly ["run.start.runPermissions", "automations", "providers.models", "providers.test", "providers.test.model", "providers.streamIdleTimeout", "providers.modelContextWindows", "providers.name", "providers.claude", "providers.claudeAuth", "providers.grok", "providers.opencode", "providers.auth.submit", "providers.opencodeGo", "providers.discover.draft", "providers.codexAuth", "providers.codexAuth.logout", "providers.codexAccounts", "providers.anthropicConsole", "run.resume.direction", "run.resume.model", "run.steer", "run.overrideAllNodes", "run.setModel", "run.setModel.node", "run.setPermissions", "run.start.continueSession", "run.start.entryHistory", "remote.owner.projects", "remote.workspaces.probe", "remote.engine.relay", "remote.hosting.device.grant", "extensions.manage", "extensions.resources", "skills.invoke", "mcp.manage", "mcp.edit", "mcp.status", "runs.files", "sessions.files", "account.profile", "sessions.stats", "sessions.usage", "config.analytics", "config.analytics.planGate", "sessions.trajectory", "config.externalSubagent", "config.decisions", "browser.view", "attachments.read", "config.general", "sessions.pullRequest", "browser.view.go", "config.browser", "config.webSearch", "background.tasks", "workspace.warm", "browser.cookies.firefox", "sessions.compact", "sessions.changes"];
48
48
  /** One client call. `params` is omitted only for calls that take no arguments. */
49
49
  export interface AppServerRequest {
50
50
  id: number | string;
@@ -357,6 +357,113 @@ export interface AppServerUsageAnalytics {
357
357
  filesScanned: number;
358
358
  windowDays: number;
359
359
  }
360
+ /**
361
+ * A file's change as a diff with line numbers on both sides (see `src/file-diff.ts`). The hunk counts
362
+ * describe the whole hunk; when the bound cut the diff, `lines` stops short and `hiddenLines` says how
363
+ * many diff lines were left out.
364
+ */
365
+ export interface AppServerFileDiffLine {
366
+ kind: 'context' | 'add' | 'del';
367
+ text: string;
368
+ oldLine?: number;
369
+ newLine?: number;
370
+ noNewline?: true;
371
+ clipped?: true;
372
+ }
373
+ export interface AppServerFileDiffHunk {
374
+ oldStart: number;
375
+ oldLines: number;
376
+ newStart: number;
377
+ newLines: number;
378
+ lines: AppServerFileDiffLine[];
379
+ }
380
+ export interface AppServerFileDiff {
381
+ hunks: AppServerFileDiffHunk[];
382
+ hiddenLines: number;
383
+ }
384
+ /**
385
+ * One file the agent changed in a session since the person last reviewed it (`sessions.changes.*`).
386
+ *
387
+ * The change is measured from the content the file held before the first unreviewed agent write to the
388
+ * file as it is now, so it is the file's real change, every edit of it together — not one call's
389
+ * request. `path` is relative to the session's workspace, with `/` separators.
390
+ */
391
+ export interface AppServerSessionFileChange {
392
+ path: string;
393
+ status: 'added' | 'modified' | 'deleted';
394
+ linesAdded: number;
395
+ linesRemoved: number;
396
+ /** Either side is not UTF-8 text: there is no line diff, and the counts are 0. */
397
+ binary?: true;
398
+ /** A side is too large to line-diff; the counts are a coarse measure. */
399
+ tooLarge?: true;
400
+ /**
401
+ * The permission bits changed, as three octal digits (`"644"` → `"755"`): a landing can change only a
402
+ * file's executable bit, which then is the whole change and its diff has no hunks. Never on Windows,
403
+ * where the mode stands for nothing the tools change, and never for an added or deleted file.
404
+ */
405
+ modeChange?: {
406
+ from: string;
407
+ to: string;
408
+ };
409
+ /**
410
+ * The line terminators changed (`lf`, `crlf`, or `mixed` for both). A diff line drops its terminator, so a
411
+ * converted line reads as removed and added with the same text; this says why.
412
+ */
413
+ lineEndings?: {
414
+ from: 'lf' | 'crlf' | 'mixed';
415
+ to: 'lf' | 'crlf' | 'mixed';
416
+ };
417
+ /**
418
+ * The file changed on disk after the agent last wrote it — another program, or the person. Undo then
419
+ * refuses the file unless asked with `force`. Only `list` and `get` read the disk for it; an event
420
+ * describes the file as the agent's last write left it.
421
+ */
422
+ changedOnDisk?: true;
423
+ /** Whether Undo can restore the file: false when its earlier content was too large to keep. */
424
+ undoable: boolean;
425
+ /**
426
+ * The session revision of the write that last changed this file's entry, so it rises with every change and
427
+ * never repeats for a path, even after the file was kept or undone and changed again: a client tells a diff
428
+ * it holds is out of date by comparing it.
429
+ */
430
+ version: number;
431
+ firstChangedAt: string;
432
+ updatedAt: string;
433
+ /**
434
+ * `list` and `get` only: the diff from the earlier content to the file as it is now, or `null` for a
435
+ * binary or too-large file. Absent from the event, which carries the summary alone. A diff with no hunks
436
+ * is a change no line shows: an empty file created or deleted, or only `modeChange`.
437
+ */
438
+ diff?: AppServerFileDiff | null;
439
+ }
440
+ /** A session's pending set, as `sessions.changes.list` answers it and `session.changes.updated` reports it. */
441
+ export interface AppServerSessionChanges {
442
+ sessionId: string;
443
+ /** Raised by every change to the pending set, in every engine that shares the home: newer is larger. */
444
+ revision: number;
445
+ changes: AppServerSessionFileChange[];
446
+ }
447
+ /** Why Undo left a file as it is. `changed-on-disk` yields to `force`; `no-baseline` never does. */
448
+ export interface AppServerSessionChangeConflict {
449
+ path: string;
450
+ reason: 'changed-on-disk' | 'no-baseline';
451
+ message: string;
452
+ }
453
+ export interface AppServerSessionChangesKept extends AppServerSessionChanges {
454
+ kept: string[];
455
+ }
456
+ export interface AppServerSessionChangesUndone extends AppServerSessionChanges {
457
+ /** Files restored to their earlier content (a file the agent created is removed, one it deleted recreated). */
458
+ reverted: string[];
459
+ /** Files Undo refused. Without `force`, one `changed-on-disk` conflict means nothing was reverted. */
460
+ conflicts: AppServerSessionChangeConflict[];
461
+ /** Files whose restore failed on disk; they stay pending. */
462
+ failed: {
463
+ path: string;
464
+ message: string;
465
+ }[];
466
+ }
360
467
  export interface AppServerSessionSummary {
361
468
  id: string;
362
469
  name: string;
@@ -123,4 +123,11 @@ export const APP_SERVER_PROTOCOL_VERSION = 2;
123
123
  // `background.tasks`: `background.list` answers the AsyncProcess jobs and qa.terminal sessions this
124
124
  // engine holds, `background.stop` ends one, and `background.updated` carries the whole list whenever
125
125
  // it changes. An engine without it answers `unknown-method` and sends no such event.
126
- export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.resume.model', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser', 'config.webSearch', 'background.tasks', 'workspace.warm', 'browser.cookies.firefox', 'sessions.compact'];
126
+ // `sessions.changes`: the engine keeps each session's agent file writes for review since the person last
127
+ // reviewed them. `sessions.changes.list` answers the pending files with their diffs, `sessions.changes.get`
128
+ // one file's whole diff, `sessions.changes.keep` accepts files and `sessions.changes.undo` restores them
129
+ // (refusing a file changed on disk since the agent's write unless `force`), and `session.changes.updated`
130
+ // carries the pending set, without diffs, whenever it changes. A completed Write or Edit also reports its
131
+ // own change as `fileDiff` on `node.tool.completed`. An engine without it answers `unknown-method` and sends
132
+ // neither, so a window on such an engine shows no review bar and no Keep or Undo.
133
+ export const APP_SERVER_CAPABILITIES = ['run.start.runPermissions', 'automations', 'providers.models', 'providers.test', 'providers.test.model', 'providers.streamIdleTimeout', 'providers.modelContextWindows', 'providers.name', 'providers.claude', 'providers.claudeAuth', 'providers.grok', 'providers.opencode', 'providers.auth.submit', 'providers.opencodeGo', 'providers.discover.draft', 'providers.codexAuth', 'providers.codexAuth.logout', 'providers.codexAccounts', 'providers.anthropicConsole', 'run.resume.direction', 'run.resume.model', 'run.steer', 'run.overrideAllNodes', 'run.setModel', 'run.setModel.node', 'run.setPermissions', 'run.start.continueSession', 'run.start.entryHistory', 'remote.owner.projects', 'remote.workspaces.probe', 'remote.engine.relay', 'remote.hosting.device.grant', 'extensions.manage', 'extensions.resources', 'skills.invoke', 'mcp.manage', 'mcp.edit', 'mcp.status', 'runs.files', 'sessions.files', 'account.profile', 'sessions.stats', 'sessions.usage', 'config.analytics', 'config.analytics.planGate', 'sessions.trajectory', 'config.externalSubagent', 'config.decisions', 'browser.view', 'attachments.read', 'config.general', 'sessions.pullRequest', 'browser.view.go', 'config.browser', 'config.webSearch', 'background.tasks', 'workspace.warm', 'browser.cookies.firefox', 'sessions.compact', 'sessions.changes'];
@@ -144,6 +144,8 @@ export declare class AppServer {
144
144
  private readonly gh;
145
145
  /** Polls the PRs whose sessions asked for Auto-fix; one engine per home actually polls. */
146
146
  private readonly pullRequestWatcher;
147
+ /** The files each session's agent changed since the person last reviewed them (Keep / Undo). */
148
+ private readonly sessionChanges;
147
149
  /** The wakes this engine armed for Auto-fix, checked against the PR record again before delivery. */
148
150
  private readonly autoFixWakes;
149
151
  /**
@@ -396,6 +398,27 @@ export declare class AppServer {
396
398
  private setExtensionEnabled;
397
399
  /** Preserve MCP credentials when toggling or deleting an existing entry. */
398
400
  private mutateMcp;
401
+ /**
402
+ * One configured MCP server as an edit form can show it: the command and its arguments, or the
403
+ * endpoint, and the *names* of its environment variables and headers. Their values are secrets
404
+ * the engine never returns; an edit keeps a saved value by naming it (see mergeMcpEdit). The
405
+ * endpoint is returned without its query string, which can hold a credential.
406
+ */
407
+ private mcpServerView;
408
+ /**
409
+ * Check one configured MCP server, on the person's explicit request ("Check Connection"): start
410
+ * it, ask for its tools, stop it, and record the answer beside the ones tasks record. A server that
411
+ * is turned off is reported off without being started. A stdio server starts in the workspace the
412
+ * caller names, as it would for a task there, or the home folder. A page never calls this on its
413
+ * own: a task asks before it connects a server, and opening Settings is not that consent.
414
+ */
415
+ private mcpStatus;
416
+ /**
417
+ * What each configured server last answered, without starting anything: the status a task's
418
+ * connection or an explicit check recorded, while it still describes the server's current
419
+ * definition. An edited server, and one never connected, has none ("Not checked").
420
+ */
421
+ private mcpStatuses;
399
422
  /**
400
423
  * Apply one provider change inside the serialized configuration transaction.
401
424
  *
@@ -1038,6 +1061,8 @@ export declare class AppServer {
1038
1061
  private updateSessionSkill;
1039
1062
  /** Say what a session is waiting on. An empty list is a real answer: it is what ends a wait. */
1040
1063
  private emitPullRequest;
1064
+ /** The pending set as a change left it, without diffs: a client reads those with `sessions.changes.list`. */
1065
+ private emitSessionChanges;
1041
1066
  /**
1042
1067
  * Start tracking `ref` for the session. A PR already tracked under the same URL keeps its settings, so a
1043
1068
  * repeated `gh pr create` (which reports the existing PR) never switches off what the user turned on.
@@ -5,7 +5,7 @@ import { ModelHealthCache } from './model-health-cache.js';
5
5
  import { mkdir, readFile, realpath, rm, stat, writeFile } from 'node:fs/promises';
6
6
  import { homedir } from 'node:os';
7
7
  import { fileURLToPath } from 'node:url';
8
- import { join, resolve } from 'node:path';
8
+ import { isAbsolute, join, resolve } from 'node:path';
9
9
  import { changeConfigFile, configDirectory, ConfigConflictError, loadConfig, reconcileSubagentPair, resolveCodeIntelConfig, resolveConfiguredLimits, validateMcpServer, checkSearxngUrl, validateWebSearchConfig, WEB_SEARCH_FIELDS, WEB_SEARCH_KEY_FIELDS, WEB_SEARCH_PROVIDERS } from './config.js';
10
10
  import { isUnlimitedAlias } from './limits.js';
11
11
  import { isPermissionMode, workspacePermissionKey } from './permissions.js';
@@ -62,7 +62,8 @@ import { attachmentReferenceBlock, loadResolvedImages, parsePendingAttachments,
62
62
  import { extensionSnapshot, listBundles, installBundle, removeBundle, removeBundleTransactional, setBundleEnabled, listSkillResources, readSkillResource, writeSkillResource, resolveSkillInvocation } from './extensions.js';
63
63
  import { isBuiltinSlashCommand } from './skill-commands.js';
64
64
  import { copySessionSkill, readSessionSkill, removeSessionSkill, setSessionSkillPaused, skillForRun } from './session-skills.js';
65
- import { connectMcpServers, mcpCatalogStore } from './mcp.js';
65
+ import { LIST_DIFF_LINES, MAX_DIFF_LINES, SessionChangeStore } from './session-changes.js';
66
+ import { connectMcpServers, mcpCatalogStore, mcpDefinitionKey, mcpStatusStore, mcpTaskStatusReporter, mergeMcpEdit, probeMcpServer } from './mcp.js';
66
67
  import { loadWorkspaceInstructions } from './workspace-instructions.js';
67
68
  import { DAY_MS, planAutoArchive } from './session-reaper.js';
68
69
  import { disposeAllQaProcesses, disposeAllQaPtys, onBackgroundChange } from './qa/index.js';
@@ -341,9 +342,50 @@ function identifier(value, name) {
341
342
  throw new AppServerError('invalid-params', `${name} must be an identifier of up to 128 word characters`);
342
343
  return value;
343
344
  }
345
+ /**
346
+ * An MCP server's id. It matches validateConfig: an existing id has no 100/128-character limit, and
347
+ * a narrower check here would make valid stored servers impossible to manage.
348
+ */
349
+ function mcpServerId(value) {
350
+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]+$/.test(value) || ['__proto__', 'constructor', 'prototype'].includes(value)) {
351
+ throw new AppServerError('invalid-params', 'MCP id must contain only letters, numbers, underscores or hyphens');
352
+ }
353
+ return value;
354
+ }
344
355
  function optionalIdentifier(value, name) {
345
356
  return value === undefined ? undefined : identifier(value, name);
346
357
  }
358
+ /** A session the review record may hold a file for: its ids are file stems, never paths. */
359
+ function changesSessionId(value) {
360
+ if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
361
+ throw new AppServerError('invalid-params', 'id must be a session id');
362
+ return value;
363
+ }
364
+ /** One workspace-relative path of a pending change, as `sessions.changes.list` spells it. */
365
+ function changePath(value, name) {
366
+ if (typeof value !== 'string' || !value || value.length > 4096 || value.includes('\0'))
367
+ throw new AppServerError('invalid-params', `${name} must be a path the pending set lists`);
368
+ return value;
369
+ }
370
+ /** `path` names one file, `paths` several; neither means every pending file. */
371
+ function changePaths(params) {
372
+ if (params.path !== undefined && params.paths !== undefined)
373
+ throw new AppServerError('invalid-params', 'Name the files with path or paths, not both');
374
+ if (params.path !== undefined)
375
+ return [changePath(params.path, 'path')];
376
+ if (params.paths === undefined)
377
+ return undefined;
378
+ if (!Array.isArray(params.paths) || params.paths.length > 10_000)
379
+ throw new AppServerError('invalid-params', 'paths must be a list of paths the pending set lists');
380
+ return params.paths.map(entry => changePath(entry, 'paths'));
381
+ }
382
+ function diffLines(value, fallback) {
383
+ if (value === undefined)
384
+ return fallback;
385
+ if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0 || value > MAX_DIFF_LINES)
386
+ throw new AppServerError('invalid-params', `maxLines must be an integer from 0 to ${MAX_DIFF_LINES}`);
387
+ return value;
388
+ }
347
389
  /** A panel navigation target: HTTP(S) only, as the isolated browser will open it. */
348
390
  function viewUrl(value) {
349
391
  if (typeof value !== 'string' || !value)
@@ -885,6 +927,8 @@ export class AppServer {
885
927
  gh;
886
928
  /** Polls the PRs whose sessions asked for Auto-fix; one engine per home actually polls. */
887
929
  pullRequestWatcher;
930
+ /** The files each session's agent changed since the person last reviewed them (Keep / Undo). */
931
+ sessionChanges;
888
932
  /** The wakes this engine armed for Auto-fix, checked against the PR record again before delivery. */
889
933
  autoFixWakes = new Set();
890
934
  /**
@@ -1049,6 +1093,7 @@ export class AppServer {
1049
1093
  onStop;
1050
1094
  constructor(options) {
1051
1095
  this.directory = options.directory ?? configDirectory();
1096
+ this.sessionChanges = new SessionChangeStore(this.directory);
1052
1097
  this.output = options.output;
1053
1098
  this.error = options.error;
1054
1099
  this.checkGraphHealth = options.checkGraphHealth ?? checkGraphModelHealth;
@@ -1378,6 +1423,25 @@ export class AppServer {
1378
1423
  case 'sessions.pullRequest.dismiss':
1379
1424
  await this.dismissPullRequest(identifier(params.id, 'id'));
1380
1425
  return {};
1426
+ case 'sessions.changes.list': return this.sessionChanges.list(changesSessionId(params.id), diffLines(params.maxLines, LIST_DIFF_LINES));
1427
+ case 'sessions.changes.get': {
1428
+ const id = changesSessionId(params.id);
1429
+ return { sessionId: id, ...await this.sessionChanges.get(id, changePath(params.path, 'path'), diffLines(params.maxLines, MAX_DIFF_LINES)) };
1430
+ }
1431
+ case 'sessions.changes.keep': {
1432
+ const answer = await this.sessionChanges.keep(changesSessionId(params.id), changePaths(params));
1433
+ if (answer.kept.length)
1434
+ this.emitSessionChanges(answer);
1435
+ return answer;
1436
+ }
1437
+ case 'sessions.changes.undo': {
1438
+ if (params.force !== undefined && typeof params.force !== 'boolean')
1439
+ throw new AppServerError('invalid-params', 'force must be a boolean');
1440
+ const answer = await this.sessionChanges.undo(changesSessionId(params.id), changePaths(params), params.force === true);
1441
+ if (answer.reverted.length)
1442
+ this.emitSessionChanges(answer);
1443
+ return answer;
1444
+ }
1381
1445
  case 'sessions.skill.get': return { skill: (await readSessionSkill(this.directory, identifier(params.id, 'id'))) ?? null };
1382
1446
  case 'sessions.skill.update': return { skill: (await this.updateSessionSkill(identifier(params.id, 'id'), params)) ?? null };
1383
1447
  case 'timers.list': return this.listTimers();
@@ -1662,6 +1726,9 @@ export class AppServer {
1662
1726
  case 'extensions.remove': return this.removeExtension(params);
1663
1727
  case 'extensions.setEnabled': return this.setExtensionEnabled(params);
1664
1728
  case 'mcp.mutate': return this.mutateMcp(params);
1729
+ case 'mcp.get': return this.mcpServerView(params);
1730
+ case 'mcp.status': return this.mcpStatus(params);
1731
+ case 'mcp.statuses': return this.mcpStatuses();
1665
1732
  case 'projects.list': return { projects: await this.listProjects() };
1666
1733
  case 'projects.add': return this.addProject(params);
1667
1734
  case 'projects.remove': return this.removeProject(params);
@@ -2046,15 +2113,10 @@ export class AppServer {
2046
2113
  }
2047
2114
  /** Preserve MCP credentials when toggling or deleting an existing entry. */
2048
2115
  async mutateMcp(params) {
2049
- // Match validateConfig: existing MCP IDs have no 100/128-character limit.
2050
- // A narrower RPC check would make valid stored servers impossible to manage.
2051
- const id = params.id;
2052
- if (typeof id !== 'string' || !/^[A-Za-z0-9_-]+$/.test(id) || ['__proto__', 'constructor', 'prototype'].includes(id)) {
2053
- throw new AppServerError('invalid-params', 'MCP id must contain only letters, numbers, underscores or hyphens');
2054
- }
2116
+ const id = mcpServerId(params.id);
2055
2117
  const action = params.action;
2056
- if (action !== 'add' && action !== 'remove' && action !== 'setEnabled') {
2057
- throw new AppServerError('invalid-params', 'action must be add, remove or setEnabled');
2118
+ if (action !== 'add' && action !== 'update' && action !== 'remove' && action !== 'setEnabled') {
2119
+ throw new AppServerError('invalid-params', 'action must be add, update, remove or setEnabled');
2058
2120
  }
2059
2121
  if (action === 'setEnabled' && typeof params.enabled !== 'boolean') {
2060
2122
  throw new AppServerError('invalid-params', 'enabled must be a boolean');
@@ -2077,6 +2139,18 @@ export class AppServer {
2077
2139
  throw new AppServerError('busy', `MCP server ${id} already exists. Remove it before replacing it.`);
2078
2140
  servers[id] = server;
2079
2141
  }
2142
+ else if (action === 'update') {
2143
+ if (!exists)
2144
+ throw new AppServerError('not-found', `MCP server ${id} does not exist`);
2145
+ // Saved secrets never leave the engine, so an edit names the ones it keeps instead of
2146
+ // sending them back: see mergeMcpEdit.
2147
+ try {
2148
+ servers[id] = mergeMcpEdit(servers[id], params.server);
2149
+ }
2150
+ catch (error) {
2151
+ throw new AppServerError('invalid-params', message(error));
2152
+ }
2153
+ }
2080
2154
  else {
2081
2155
  if (!exists)
2082
2156
  throw new AppServerError('not-found', `MCP server ${id} does not exist`);
@@ -2092,6 +2166,68 @@ export class AppServer {
2092
2166
  return { id };
2093
2167
  });
2094
2168
  }
2169
+ /**
2170
+ * One configured MCP server as an edit form can show it: the command and its arguments, or the
2171
+ * endpoint, and the *names* of its environment variables and headers. Their values are secrets
2172
+ * the engine never returns; an edit keeps a saved value by naming it (see mergeMcpEdit). The
2173
+ * endpoint is returned without its query string, which can hold a credential.
2174
+ */
2175
+ async mcpServerView(params) {
2176
+ const id = mcpServerId(params.id);
2177
+ const servers = (await loadConfig(this.directory)).mcpServers ?? {};
2178
+ if (!Object.prototype.hasOwnProperty.call(servers, id))
2179
+ throw new AppServerError('not-found', `MCP server ${id} does not exist`);
2180
+ const server = servers[id];
2181
+ const enabled = server.enabled !== false;
2182
+ if (server.transport === 'stdio') {
2183
+ return { id, transport: 'stdio', enabled, command: server.command, args: server.args ?? [], envKeys: Object.keys(server.env ?? {}) };
2184
+ }
2185
+ const url = new URL(server.url);
2186
+ const query = url.search !== '';
2187
+ url.search = '';
2188
+ return { id, transport: 'http', enabled, url: url.href, ...(query ? { urlQuery: true } : {}), headerKeys: Object.keys(server.headers ?? {}) };
2189
+ }
2190
+ /**
2191
+ * Check one configured MCP server, on the person's explicit request ("Check Connection"): start
2192
+ * it, ask for its tools, stop it, and record the answer beside the ones tasks record. A server that
2193
+ * is turned off is reported off without being started. A stdio server starts in the workspace the
2194
+ * caller names, as it would for a task there, or the home folder. A page never calls this on its
2195
+ * own: a task asks before it connects a server, and opening Settings is not that consent.
2196
+ */
2197
+ async mcpStatus(params) {
2198
+ const id = mcpServerId(params.id);
2199
+ const servers = (await loadConfig(this.directory)).mcpServers ?? {};
2200
+ if (!Object.prototype.hasOwnProperty.call(servers, id))
2201
+ throw new AppServerError('not-found', `MCP server ${id} does not exist`);
2202
+ const server = servers[id];
2203
+ if (server.enabled === false)
2204
+ return { id, state: 'off' };
2205
+ const named = typeof params.workspace === 'string' && isAbsolute(params.workspace) ? params.workspace : undefined;
2206
+ const workspace = named !== undefined && await stat(named).then(entry => entry.isDirectory(), () => false) ? named : homedir();
2207
+ const result = await probeMcpServer(server, workspace);
2208
+ const checkedAt = new Date();
2209
+ await mcpStatusStore(this.directory).record(id, server, result, 'check', checkedAt).catch(() => undefined);
2210
+ return { id, ...result, checkedAt: checkedAt.toISOString(), source: 'check' };
2211
+ }
2212
+ /**
2213
+ * What each configured server last answered, without starting anything: the status a task's
2214
+ * connection or an explicit check recorded, while it still describes the server's current
2215
+ * definition. An edited server, and one never connected, has none ("Not checked").
2216
+ */
2217
+ async mcpStatuses() {
2218
+ const servers = (await loadConfig(this.directory)).mcpServers ?? {};
2219
+ const statuses = {};
2220
+ for (const record of await mcpStatusStore(this.directory).list()) {
2221
+ if (!Object.prototype.hasOwnProperty.call(servers, record.id))
2222
+ continue;
2223
+ const server = servers[record.id];
2224
+ if (mcpDefinitionKey(server) !== record.definition)
2225
+ continue;
2226
+ const { id: _id, definition: _definition, ...status } = record;
2227
+ statuses[record.id] = status;
2228
+ }
2229
+ return { statuses };
2230
+ }
2095
2231
  /**
2096
2232
  * Apply one provider change inside the serialized configuration transaction.
2097
2233
  *
@@ -2825,6 +2961,9 @@ export class AppServer {
2825
2961
  // Its pull request stops being watched with it: an Auto-fix wake has no conversation left to land in.
2826
2962
  await removePullRequest(this.directory, id).catch(() => { });
2827
2963
  await removeSessionSkill(this.directory, id).catch(() => { });
2964
+ // The stored originals of its unreviewed changes go too: nothing can ask to undo them any more.
2965
+ if (/^[A-Za-z0-9_-]{1,128}$/.test(id))
2966
+ await this.sessionChanges.remove(id).catch(() => { });
2828
2967
  this.emit('session.removed', { id });
2829
2968
  return { removed: true };
2830
2969
  });
@@ -4881,6 +5020,8 @@ export class AppServer {
4881
5020
  timers: this.timers, sessionScope: input.record.id, wakesArmed, automationDirectory: this.directory,
4882
5021
  wakeCarry,
4883
5022
  pullRequests: this.pullRequestControl(input.record.id, wakeCarry),
5023
+ // Every write the run makes to a workspace file is kept for review under the session it belongs to.
5024
+ fileChanges: this.sessionChanges.recorder(input.record.id, root, changes => this.emitSessionChanges(changes), error => this.log('warn', `Could not record a file change for review: ${message(error)}`)),
4884
5025
  };
4885
5026
  bootMark('run.exec.mcp.connect.start');
4886
5027
  // The health verdict is watched while the servers connect, not after: a server can wait on the
@@ -4899,7 +5040,7 @@ export class AppServer {
4899
5040
  // until a model calls one of those tools, and that call waits for the connection.
4900
5041
  const servers = graphMcpServers(graph.id, extension.servers);
4901
5042
  const connecting = Object.keys(servers).length
4902
- ? connectMcpServers(servers, { ...toolContext, signal: setupSignal, userSignal: setupSignal }, detail => this.emit('log', { level: 'info', message: detail }), setupSignal, { catalogs: mcpCatalogStore(this.directory) })
5043
+ ? connectMcpServers(servers, { ...toolContext, signal: setupSignal, userSignal: setupSignal }, detail => this.emit('log', { level: 'info', message: detail }), setupSignal, { catalogs: mcpCatalogStore(this.directory), status: mcpTaskStatusReporter(this.directory) })
4903
5044
  : Promise.resolve(undefined);
4904
5045
  try {
4905
5046
  mcp = await Promise.race([connecting, healthGate.then(() => connecting)]);
@@ -7258,6 +7399,10 @@ export class AppServer {
7258
7399
  emitPullRequest(sessionId, pullRequest) {
7259
7400
  this.emit('session.pullRequest.updated', { sessionId, pullRequest: pullRequestForClients(pullRequest) });
7260
7401
  }
7402
+ /** The pending set as a change left it, without diffs: a client reads those with `sessions.changes.list`. */
7403
+ emitSessionChanges(changes) {
7404
+ this.emit('session.changes.updated', { sessionId: changes.sessionId, revision: changes.revision, changes: changes.changes });
7405
+ }
7261
7406
  /**
7262
7407
  * Start tracking `ref` for the session. A PR already tracked under the same URL keeps its settings, so a
7263
7408
  * repeated `gh pr create` (which reports the existing PR) never switches off what the user turned on.
@@ -3,7 +3,7 @@ import type { AuthConfiguration, AuthError } from './types.js';
3
3
  export * from './types.js';
4
4
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
5
  export { credentialIdentity } from './AuthManager.js';
6
- export { KeyringCredentialStore, KeyringAbsentError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
6
+ export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
7
7
  export declare function getAuthConfiguration(): AuthConfiguration;
8
8
  /**
9
9
  * Report an automatic sign-out: the account service rejected the stored refresh token, so the
@@ -3,7 +3,7 @@ import { AuthManager } from './AuthManager.js';
3
3
  export * from './types.js';
4
4
  export { AuthManager, AUTH_REFRESH_BUDGET_MS } from './AuthManager.js';
5
5
  export { credentialIdentity } from './AuthManager.js';
6
- export { KeyringCredentialStore, KeyringAbsentError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
6
+ export { KeyringCredentialStore, KeyringAbsentError, KeyringUnreachableError, FileCredentialStore, FallbackCredentialStore, createCredentialStore } from './store.js';
7
7
  export function getAuthConfiguration() { return { ...AUTH_DEPLOYMENT }; }
8
8
  let manager;
9
9
  let signOutReporter;
@@ -18,6 +18,21 @@ export declare class KeyringAbsentError extends AuthError {
18
18
  cause?: unknown;
19
19
  });
20
20
  }
21
+ /**
22
+ * A keyring that exists but is locked, and that this session has no way to unlock: a desktop Linux
23
+ * machine reached over SSH, whose login keyring nobody unlocked at the console. Its unlock prompt
24
+ * needs a display, so every read fails the same way until someone unlocks it at the machine.
25
+ *
26
+ * It holds nothing this process can reach, so it is handled like a machine without a store: reads
27
+ * and sign-ins fall back to the owner-only file, and a sign-out does not fail on tokens it cannot
28
+ * touch. A session with a display keeps reporting a locked keyring, because there the user can
29
+ * unlock it and a dismissed prompt is a choice.
30
+ */
31
+ export declare class KeyringUnreachableError extends KeyringAbsentError {
32
+ constructor(options?: {
33
+ cause?: unknown;
34
+ });
35
+ }
21
36
  /** The OS credential store service that Andorra sign-ins are saved under, one scope per identity. */
22
37
  export declare const SIGN_IN_SERVICE = "Andorra Code";
23
38
  /** Lazy native loading keeps offline BYOK usable on machines without a credential service. */
@@ -142,7 +157,8 @@ export declare class FallbackCredentialStore implements CredentialStore {
142
157
  * Unlike reads and writes, a keyring clear never falls back just because it failed: a keyring
143
158
  * that committed its tombstone and then could not delete an old token chunk still holds that
144
159
  * token, and switching to the file would report a sign-out that left it behind. Only a keyring
145
- * that cannot even be read holds nothing to clear, which is a machine without one.
160
+ * that cannot even be read holds nothing to clear: a machine without one, or a locked one this
161
+ * session has no display to unlock (its tokens stay for the console to clear).
146
162
  *
147
163
  * The other store is cleared too. A reachable keyring is cleared whether or not a session reads
148
164
  * back from it, because an interrupted keyring write leaves token chunks without the manifest
@@ -21,6 +21,25 @@ export class KeyringAbsentError extends AuthError {
21
21
  * A locked collection, a dismissed unlock prompt or any other failure is a store that exists.
22
22
  */
23
23
  const ABSENT_KEYRING = /not provided by any \.service files|org\.freedesktop\.DBus\.Error\.ServiceUnknown|dbus-daemon autolaunch|set your DBUS_SESSION_BUS_ADDRESS|Failed to connect to socket/i;
24
+ /**
25
+ * A keyring that exists but is locked, and that this session has no way to unlock: a desktop Linux
26
+ * machine reached over SSH, whose login keyring nobody unlocked at the console. Its unlock prompt
27
+ * needs a display, so every read fails the same way until someone unlocks it at the machine.
28
+ *
29
+ * It holds nothing this process can reach, so it is handled like a machine without a store: reads
30
+ * and sign-ins fall back to the owner-only file, and a sign-out does not fail on tokens it cannot
31
+ * touch. A session with a display keeps reporting a locked keyring, because there the user can
32
+ * unlock it and a dismissed prompt is a choice.
33
+ */
34
+ export class KeyringUnreachableError extends KeyringAbsentError {
35
+ constructor(options) { super('The OS credential store is locked, and this session has no display to unlock it on.', options); this.name = 'KeyringUnreachableError'; }
36
+ }
37
+ /** The errors a locked Secret Service collection gives through @napi-rs/keyring, or its dismissed unlock prompt. */
38
+ const LOCKED_KEYRING = /collection is locked|org\.freedesktop\.Secret\.Error\.IsLocked|prompt (?:was )?dismissed/i;
39
+ /** Whether this session can show the Secret Service unlock prompt: only a graphical session can. */
40
+ function canPromptToUnlock(environment = process.env) {
41
+ return Boolean(environment.DISPLAY || environment.WAYLAND_DISPLAY);
42
+ }
24
43
  function errorText(error) {
25
44
  const parts = [];
26
45
  for (let current = error, depth = 0; current && depth < 6; depth++) {
@@ -33,8 +52,11 @@ function errorText(error) {
33
52
  function keyringFailure(error, message) {
34
53
  if (error instanceof KeyringAbsentError)
35
54
  return error;
36
- if (ABSENT_KEYRING.test(errorText(error)))
55
+ const text = errorText(error);
56
+ if (ABSENT_KEYRING.test(text))
37
57
  return new KeyringAbsentError(undefined, { cause: error });
58
+ if (LOCKED_KEYRING.test(text) && !canPromptToUnlock())
59
+ return new KeyringUnreachableError({ cause: error });
38
60
  return new AuthError('storage', message, { cause: error });
39
61
  }
40
62
  const LOCKED_HINT = 'Unlock it and retry, or set ANDORRA_CREDENTIAL_STORE=file to keep the session in an owner-only file instead.';
@@ -374,7 +396,8 @@ export class FallbackCredentialStore {
374
396
  * Unlike reads and writes, a keyring clear never falls back just because it failed: a keyring
375
397
  * that committed its tombstone and then could not delete an old token chunk still holds that
376
398
  * token, and switching to the file would report a sign-out that left it behind. Only a keyring
377
- * that cannot even be read holds nothing to clear, which is a machine without one.
399
+ * that cannot even be read holds nothing to clear: a machine without one, or a locked one this
400
+ * session has no display to unlock (its tokens stay for the console to clear).
378
401
  *
379
402
  * The other store is cleared too. A reachable keyring is cleared whether or not a session reads
380
403
  * back from it, because an interrupted keyring write leaves token chunks without the manifest