@andorra-labs/code 0.1.9 → 0.1.11
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.
- package/README.md +28 -208
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/dist/src/agent-execution.js +56 -0
- package/dist/src/app-server/protocol.d.ts +109 -1
- package/dist/src/app-server/protocol.js +8 -1
- package/dist/src/app-server.d.ts +59 -1
- package/dist/src/app-server.js +418 -63
- package/dist/src/auth/index.d.ts +1 -1
- package/dist/src/auth/index.js +1 -1
- package/dist/src/auth/store.d.ts +17 -1
- package/dist/src/auth/store.js +25 -2
- package/dist/src/automation-service.js +1 -1
- package/dist/src/browser-session.d.ts +8 -0
- package/dist/src/browser-session.js +27 -1
- package/dist/src/browser-ui/app.js +255 -33
- package/dist/src/browser-ui/index.html +9 -9
- package/dist/src/browser-ui/style.css +110 -65
- package/dist/src/browser-ui/tokens.css +27 -26
- package/dist/src/cli.js +10 -5
- package/dist/src/coding-tools.d.ts +24 -0
- package/dist/src/coding-tools.js +71 -8
- package/dist/src/command-screens.js +1 -1
- package/dist/src/commands.d.ts +1 -1
- package/dist/src/commands.js +2 -2
- package/dist/src/completion-gates.d.ts +42 -7
- package/dist/src/completion-gates.js +55 -9
- package/dist/src/completion.d.ts +9 -1
- package/dist/src/completion.js +20 -2
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -0
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/file-diff.d.ts +105 -0
- package/dist/src/file-diff.js +244 -0
- package/dist/src/graph-manager-chat.js +4 -4
- package/dist/src/graph-runner.js +39 -2
- package/dist/src/graph-sync.d.ts +8 -0
- package/dist/src/graph-sync.js +54 -3
- package/dist/src/graph-tool.js +1 -1
- package/dist/src/graph-ui/app.js +303 -129
- package/dist/src/graph-ui/controls.css +43 -22
- package/dist/src/graph-ui/controls.js +31 -1
- package/dist/src/graph-ui/embed.js +56 -7
- package/dist/src/graph-ui/icons.js +5 -0
- package/dist/src/graph-ui/index.html +3 -3
- package/dist/src/graph-ui/manager-state.js +2 -2
- package/dist/src/graph-ui/manager.css +19 -18
- package/dist/src/graph-ui/manager.js +5 -5
- package/dist/src/graph-ui/skill-picker.js +5 -5
- package/dist/src/graph-ui/studio-canvas.js +16 -16
- package/dist/src/graph-ui/studio.css +18 -15
- package/dist/src/graph-ui/studio.js +99 -42
- package/dist/src/graph-ui/style.css +125 -80
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +33 -29
- package/dist/src/graphs.d.ts +10 -3
- package/dist/src/graphs.js +15 -4
- package/dist/src/mcp.d.ts +75 -0
- package/dist/src/mcp.js +240 -8
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- package/dist/src/provider-keys.d.ts +5 -1
- package/dist/src/provider-keys.js +7 -3
- package/dist/src/provider-settings.d.ts +4 -1
- package/dist/src/provider-settings.js +46 -5
- package/dist/src/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/qa/guidance.js +6 -19
- package/dist/src/qa/index.d.ts +0 -2
- package/dist/src/qa/index.js +0 -2
- package/dist/src/qa/profile/QaProfile.d.ts +5 -1
- package/dist/src/qa/profile/QaProfile.js +6 -2
- package/dist/src/qa/tools.d.ts +19 -1
- package/dist/src/qa/tools.js +20 -145
- package/dist/src/react-runtime.js +134 -16
- package/dist/src/read-document-doc.d.ts +20 -0
- package/dist/src/read-document-doc.js +524 -0
- package/dist/src/read-document-docx.d.ts +21 -0
- package/dist/src/read-document-docx.js +584 -0
- package/dist/src/read-document-text.d.ts +29 -0
- package/dist/src/read-document-text.js +67 -0
- package/dist/src/read-document-tool.d.ts +48 -0
- package/dist/src/read-document-tool.js +162 -0
- package/dist/src/read-document.d.ts +78 -0
- package/dist/src/read-document.js +353 -0
- package/dist/src/read-image.d.ts +29 -2
- package/dist/src/read-image.js +42 -17
- package/dist/src/remote/engine-pool.js +18 -6
- package/dist/src/runtime.d.ts +19 -0
- package/dist/src/runtime.js +10 -1
- package/dist/src/screen-selection.d.ts +38 -0
- package/dist/src/screen-selection.js +103 -0
- package/dist/src/session-changes.d.ts +122 -0
- package/dist/src/session-changes.js +804 -0
- package/dist/src/side-panel.d.ts +6 -1
- package/dist/src/side-panel.js +12 -10
- package/dist/src/skills/bundled/create-skill/SKILL.md +1 -1
- package/dist/src/skills/bundled/diagram/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/SKILL.md +37 -3
- package/dist/src/skills/bundled/graph-manager/patterns.md +27 -0
- package/dist/src/skills/bundled/provenance.json +4 -4
- package/dist/src/skills/runtime-skills.js +3 -3
- package/dist/src/stall-recovery.d.ts +15 -0
- package/dist/src/stall-recovery.js +17 -0
- package/dist/src/telemetry/schema.d.ts +1 -1
- package/dist/src/telemetry/schema.js +1 -2
- package/dist/src/terminal-ui.d.ts +64 -20
- package/dist/src/terminal-ui.js +312 -82
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- package/dist/src/tool-diff-stats.d.ts +9 -0
- package/dist/src/tool-diff-stats.js +20 -0
- package/dist/src/tool-names.d.ts +1 -1
- package/dist/src/tool-result-filter.js +1 -1
- package/dist/src/tools.js +118 -9
- package/dist/src/transcript.d.ts +11 -0
- package/dist/src/transcript.js +15 -3
- package/dist/src/types.d.ts +12 -0
- package/dist/src/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- package/package.json +6 -26
- package/dist/src/qa/api/http-runner.d.ts +0 -3
- package/dist/src/qa/api/http-runner.js +0 -47
- package/dist/src/qa/git/ChangeDetector.d.ts +0 -26
- package/dist/src/qa/git/ChangeDetector.js +0 -177
- package/dist/src/qa/git/DiffReviewer.d.ts +0 -28
- package/dist/src/qa/git/DiffReviewer.js +0 -115
- package/dist/src/qa/orchestrator/ChangeClassifier.d.ts +0 -14
- package/dist/src/qa/orchestrator/ChangeClassifier.js +0 -28
- package/dist/src/qa/orchestrator/MergeGate.d.ts +0 -14
- package/dist/src/qa/orchestrator/MergeGate.js +0 -40
- package/dist/src/qa/orchestrator/QaOrchestrator.d.ts +0 -79
- package/dist/src/qa/orchestrator/QaOrchestrator.js +0 -373
- package/dist/src/qa/runners/CommandRunner.d.ts +0 -22
- package/dist/src/qa/runners/CommandRunner.js +0 -96
- package/dist/src/qa/runners/TestRunner.d.ts +0 -21
- package/dist/src/qa/runners/TestRunner.js +0 -66
- package/dist/src/qa/runtime/RuntimeSmoke.d.ts +0 -11
- package/dist/src/qa/runtime/RuntimeSmoke.js +0 -78
- package/dist/src/qa/runtime-detect.d.ts +0 -10
- package/dist/src/qa/runtime-detect.js +0 -72
- package/dist/src/qa/security/DependencyScanner.d.ts +0 -19
- package/dist/src/qa/security/DependencyScanner.js +0 -167
- package/dist/src/qa/security/SecretScanner.d.ts +0 -3
- package/dist/src/qa/security/SecretScanner.js +0 -55
- package/docs/README.md +0 -36
- package/docs/agents/README.md +0 -62
- package/docs/agents/install-for-agents.md +0 -56
- package/docs/agents/mcp-server.md +0 -212
- package/docs/agents/subagent-mode.md +0 -149
- package/docs/concepts/README.md +0 -47
- package/docs/concepts/jev-actionable-routing.md +0 -113
- package/docs/concepts/jev-decision-thresholds.md +0 -412
- package/docs/concepts/jev-efficiency.md +0 -217
- package/docs/concepts/jev-eval-2026-11-01.md +0 -78
- package/docs/concepts/limits.md +0 -52
- package/docs/concepts/memory.md +0 -10
- package/docs/concepts/security.md +0 -50
- package/docs/concepts/workspace-instructions.md +0 -29
- package/docs/getting-started/README.md +0 -82
- package/docs/getting-started/accounts.md +0 -78
- package/docs/getting-started/configure-providers.md +0 -132
- package/docs/guides/README.md +0 -13
- package/docs/guides/browser.md +0 -39
- package/docs/guides/desktop-app.md +0 -414
- package/docs/guides/extensions.md +0 -102
- package/docs/guides/graph-builder.md +0 -116
- package/docs/guides/headless.md +0 -46
- package/docs/guides/tui.md +0 -75
- package/docs/guides/update.md +0 -70
- package/docs/guides/web-search.md +0 -51
- package/docs/guides/windows-code-signing.md +0 -319
- package/docs/llms.txt +0 -45
- package/docs/reference/README.md +0 -7
- package/docs/reference/cli.md +0 -76
- package/docs/reference/config.md +0 -91
- package/docs/reference/slash-commands.md +0 -59
- package/docs/superpowers/plans/2026-11-01-claude-console-sign-in.md +0 -111
- package/docs/superpowers/plans/2026-11-01-jev-node-opt-in.md +0 -910
- package/docs/superpowers/plans/2026-11-02-workflow-pane.md +0 -398
- package/docs/superpowers/plans/2026-11-06-graph-soft-delete.md +0 -125
- package/docs/superpowers/plans/2026-11-09-orchestrator-delegation.md +0 -295
- package/docs/superpowers/plans/2026-11-13-graph-manager-chat.md +0 -203
- package/docs/superpowers/plans/2026-11-14-jev-fair-use-pricing.md +0 -79
- package/docs/superpowers/specs/2026-10-31-work-line-summary-design.md +0 -50
- package/docs/superpowers/specs/2026-11-01-claude-console-sign-in-design.md +0 -176
- package/docs/superpowers/specs/2026-11-01-jev-node-opt-in-design.md +0 -164
- package/docs/superpowers/specs/2026-11-01-pr-section-design.md +0 -111
- package/docs/superpowers/specs/2026-11-02-workflow-pane-design.md +0 -130
- package/docs/superpowers/specs/2026-11-06-bundled-skills-design.md +0 -206
- package/docs/superpowers/specs/2026-11-09-orchestrator-delegation-design.md +0 -291
- package/docs/superpowers/specs/2026-11-13-graph-manager-chat-design.md +0 -182
- package/docs/superpowers/specs/2026-11-14-jev-fair-use-pricing-design.md +0 -156
- package/scripts/jev-efficiency-eval.mjs +0 -187
- package/scripts/jev-efficiency-live.mjs +0 -193
- package/scripts/zcode-engine-replay.mjs +0 -223
- package/tests/agent-centric-mcp-test-plan.md +0 -208
- package/tests/analytics-settings-test-plan.md +0 -165
- package/tests/browser-cli-smoke.mjs +0 -276
- package/tests/browser-test-plan.md +0 -280
- package/tests/chat-side-panel-test-plan.md +0 -309
- package/tests/decision-engine-test-plan.md +0 -163
- package/tests/default-active-jev-test-plan.md +0 -85
- package/tests/harness-extensions-test-plan.md +0 -113
- package/tests/jev-all-decisions-test-plan.md +0 -156
- package/tests/jev-efficiency/criteria.json +0 -158
- package/tests/jev-efficiency/workloads.mjs +0 -242
- package/tests/jev-efficiency-test-plan.md +0 -198
- package/tests/permissions-sandbox-probe.mjs +0 -74
- package/tests/permissions-test-plan.md +0 -191
- package/tests/product-telemetry-test-plan.md +0 -536
- package/tests/thinking-stream-preview-test-plan.md +0 -136
- package/tests/zcode-react-engine-test-plan.md +0 -396
package/dist/src/app-server.js
CHANGED
|
@@ -5,10 +5,10 @@ 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
|
-
import { isPermissionMode, workspacePermissionKey } from './permissions.js';
|
|
11
|
+
import { isPermissionMode, permissionMode as livePermissionMode, workspacePermissionKey } from './permissions.js';
|
|
12
12
|
import { RunControl } from './run-control.js';
|
|
13
13
|
import { allocateCodexAccountSlots, createAdapter, isSignInProviderType, providerLabel, providerSecrets, resolveProviderApiKey, REASONING_EFFORTS } from './providers.js';
|
|
14
14
|
import { droppedCodexSlots, removeCodexAccount } from './codex-auth.js';
|
|
@@ -40,11 +40,11 @@ import { writePendingAgentInteraction, removePendingAgentInteraction } from './s
|
|
|
40
40
|
import { summarizeSessionPrompt, titleRequestSupported } from './session-summary.js';
|
|
41
41
|
import { createTools } from './tools.js';
|
|
42
42
|
import { TimerRegistry, WAKE_RETRY_MS } from './timers.js';
|
|
43
|
-
import { confirmAutoFixWake, markAutoFixDelivered, withoutPendingFix, newPullRequest, parsePullRequestUrl, PullRequestCreateDetector, pullRequestNeedsWatch, pullRequestSettings, PullRequestWatcher, readPullRequest, removePullRequest, runGh, applyPullRequestSettingsAsReadableAccount, noAccountMessage, readPullRequestAsAnyAccount, withPullRequest, writePullRequest } from './pull-requests.js';
|
|
43
|
+
import { confirmAutoFixWake, isFinishedPullRequest, markAutoFixDelivered, withoutPendingFix, newPullRequest, parsePullRequestUrl, PullRequestCreateDetector, pullRequestNeedsWatch, pullRequestSettings, PullRequestWatcher, readPullRequest, removePullRequest, runGh, applyPullRequestSettingsAsReadableAccount, noAccountMessage, readPullRequestAsAnyAccount, withPullRequest, writePullRequest } from './pull-requests.js';
|
|
44
44
|
import { AutomationStore } from './automations.js';
|
|
45
45
|
import { executeAutomation } from './automation-runner.js';
|
|
46
46
|
import { automationService, automationServiceRunning, reconcileAutomationService } from './automation-service.js';
|
|
47
|
-
import { runGraph, stopReasonPhrase, timerReminderText } from './runtime.js';
|
|
47
|
+
import { runGraph, stopReasonPhrase, timerReminderText, wakeMessageText } from './runtime.js';
|
|
48
48
|
import { configuredSurface, createRunHandle, drainTelemetry, graphShape, reportInterruptedRuns, reportRunFinished, reportRunStarted, reportSessionStarted } from './telemetry/surface.js';
|
|
49
49
|
import { telemetryGate } from './telemetry/gate.js';
|
|
50
50
|
import { analyticsGenerationFor, resolveAnalyticsConfig } from './analytics.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 {
|
|
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)
|
|
@@ -764,6 +806,8 @@ function wakeProvenance(wake, node) {
|
|
|
764
806
|
return {};
|
|
765
807
|
return { wake, ...(typeof node === 'string' && node ? { node } : {}) };
|
|
766
808
|
}
|
|
809
|
+
/** A review wait reads the shared PR record every this many seconds, for what another engine saved there. */
|
|
810
|
+
const REVIEW_WAIT_RECORD_TICKS = 5;
|
|
767
811
|
export function isFinalWakeRefusal(error) {
|
|
768
812
|
return error instanceof AppServerError
|
|
769
813
|
&& (error.code === 'invalid-params' || error.code === 'not-found' || error.code === 'remote'
|
|
@@ -885,8 +929,18 @@ export class AppServer {
|
|
|
885
929
|
gh;
|
|
886
930
|
/** Polls the PRs whose sessions asked for Auto-fix; one engine per home actually polls. */
|
|
887
931
|
pullRequestWatcher;
|
|
932
|
+
/** The files each session's agent changed since the person last reviewed them (Keep / Undo). */
|
|
933
|
+
sessionChanges;
|
|
888
934
|
/** The wakes this engine armed for Auto-fix, checked against the PR record again before delivery. */
|
|
889
935
|
autoFixWakes = new Set();
|
|
936
|
+
/**
|
|
937
|
+
* A run of the session waiting inside the `pull_request` tool's `await_review` for its PR's next review, by
|
|
938
|
+
* session: the review comments the watcher finds go to it instead of to a wake, and it hears when the PR is
|
|
939
|
+
* merged, closed, dismissed or has Auto-fix switched off.
|
|
940
|
+
*/
|
|
941
|
+
reviewWaiters = new Map();
|
|
942
|
+
/** Sessions whose review wait is reserved and still being prepared (`awaitReview`). */
|
|
943
|
+
reviewWaitsStarting = new Set();
|
|
890
944
|
/**
|
|
891
945
|
* The account's graph sync, so a graph saved on another machine is listed here too. A first pass that
|
|
892
946
|
* outlasts the listing's bounded wait publishes `graphs.changed`: that listing already answered from
|
|
@@ -1049,6 +1103,7 @@ export class AppServer {
|
|
|
1049
1103
|
onStop;
|
|
1050
1104
|
constructor(options) {
|
|
1051
1105
|
this.directory = options.directory ?? configDirectory();
|
|
1106
|
+
this.sessionChanges = new SessionChangeStore(this.directory);
|
|
1052
1107
|
this.output = options.output;
|
|
1053
1108
|
this.error = options.error;
|
|
1054
1109
|
this.checkGraphHealth = options.checkGraphHealth ?? checkGraphModelHealth;
|
|
@@ -1065,7 +1120,7 @@ export class AppServer {
|
|
|
1065
1120
|
this.pullRequestWatcher = new PullRequestWatcher({
|
|
1066
1121
|
home: this.directory, gh: this.gh, intervalMs: options.pullRequestPollMs,
|
|
1067
1122
|
onUpdated: (sessionId, pullRequest) => this.emitPullRequest(sessionId, pullRequest),
|
|
1068
|
-
wake: (sessionId, prompt, carry) => this.wakeForPullRequest(sessionId, prompt, carry),
|
|
1123
|
+
wake: (sessionId, prompt, carry, origin) => this.wakeForPullRequest(sessionId, prompt, carry, origin),
|
|
1069
1124
|
wakePending: id => this.timers.list().some(timer => timer.id === id),
|
|
1070
1125
|
log: (level, detail) => this.log(level, detail),
|
|
1071
1126
|
});
|
|
@@ -1378,6 +1433,25 @@ export class AppServer {
|
|
|
1378
1433
|
case 'sessions.pullRequest.dismiss':
|
|
1379
1434
|
await this.dismissPullRequest(identifier(params.id, 'id'));
|
|
1380
1435
|
return {};
|
|
1436
|
+
case 'sessions.changes.list': return this.sessionChanges.list(changesSessionId(params.id), diffLines(params.maxLines, LIST_DIFF_LINES));
|
|
1437
|
+
case 'sessions.changes.get': {
|
|
1438
|
+
const id = changesSessionId(params.id);
|
|
1439
|
+
return { sessionId: id, ...await this.sessionChanges.get(id, changePath(params.path, 'path'), diffLines(params.maxLines, MAX_DIFF_LINES)) };
|
|
1440
|
+
}
|
|
1441
|
+
case 'sessions.changes.keep': {
|
|
1442
|
+
const answer = await this.sessionChanges.keep(changesSessionId(params.id), changePaths(params));
|
|
1443
|
+
if (answer.kept.length)
|
|
1444
|
+
this.emitSessionChanges(answer);
|
|
1445
|
+
return answer;
|
|
1446
|
+
}
|
|
1447
|
+
case 'sessions.changes.undo': {
|
|
1448
|
+
if (params.force !== undefined && typeof params.force !== 'boolean')
|
|
1449
|
+
throw new AppServerError('invalid-params', 'force must be a boolean');
|
|
1450
|
+
const answer = await this.sessionChanges.undo(changesSessionId(params.id), changePaths(params), params.force === true);
|
|
1451
|
+
if (answer.reverted.length)
|
|
1452
|
+
this.emitSessionChanges(answer);
|
|
1453
|
+
return answer;
|
|
1454
|
+
}
|
|
1381
1455
|
case 'sessions.skill.get': return { skill: (await readSessionSkill(this.directory, identifier(params.id, 'id'))) ?? null };
|
|
1382
1456
|
case 'sessions.skill.update': return { skill: (await this.updateSessionSkill(identifier(params.id, 'id'), params)) ?? null };
|
|
1383
1457
|
case 'timers.list': return this.listTimers();
|
|
@@ -1662,6 +1736,9 @@ export class AppServer {
|
|
|
1662
1736
|
case 'extensions.remove': return this.removeExtension(params);
|
|
1663
1737
|
case 'extensions.setEnabled': return this.setExtensionEnabled(params);
|
|
1664
1738
|
case 'mcp.mutate': return this.mutateMcp(params);
|
|
1739
|
+
case 'mcp.get': return this.mcpServerView(params);
|
|
1740
|
+
case 'mcp.status': return this.mcpStatus(params);
|
|
1741
|
+
case 'mcp.statuses': return this.mcpStatuses();
|
|
1665
1742
|
case 'projects.list': return { projects: await this.listProjects() };
|
|
1666
1743
|
case 'projects.add': return this.addProject(params);
|
|
1667
1744
|
case 'projects.remove': return this.removeProject(params);
|
|
@@ -2046,15 +2123,10 @@ export class AppServer {
|
|
|
2046
2123
|
}
|
|
2047
2124
|
/** Preserve MCP credentials when toggling or deleting an existing entry. */
|
|
2048
2125
|
async mutateMcp(params) {
|
|
2049
|
-
|
|
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
|
-
}
|
|
2126
|
+
const id = mcpServerId(params.id);
|
|
2055
2127
|
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');
|
|
2128
|
+
if (action !== 'add' && action !== 'update' && action !== 'remove' && action !== 'setEnabled') {
|
|
2129
|
+
throw new AppServerError('invalid-params', 'action must be add, update, remove or setEnabled');
|
|
2058
2130
|
}
|
|
2059
2131
|
if (action === 'setEnabled' && typeof params.enabled !== 'boolean') {
|
|
2060
2132
|
throw new AppServerError('invalid-params', 'enabled must be a boolean');
|
|
@@ -2077,6 +2149,18 @@ export class AppServer {
|
|
|
2077
2149
|
throw new AppServerError('busy', `MCP server ${id} already exists. Remove it before replacing it.`);
|
|
2078
2150
|
servers[id] = server;
|
|
2079
2151
|
}
|
|
2152
|
+
else if (action === 'update') {
|
|
2153
|
+
if (!exists)
|
|
2154
|
+
throw new AppServerError('not-found', `MCP server ${id} does not exist`);
|
|
2155
|
+
// Saved secrets never leave the engine, so an edit names the ones it keeps instead of
|
|
2156
|
+
// sending them back: see mergeMcpEdit.
|
|
2157
|
+
try {
|
|
2158
|
+
servers[id] = mergeMcpEdit(servers[id], params.server);
|
|
2159
|
+
}
|
|
2160
|
+
catch (error) {
|
|
2161
|
+
throw new AppServerError('invalid-params', message(error));
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2080
2164
|
else {
|
|
2081
2165
|
if (!exists)
|
|
2082
2166
|
throw new AppServerError('not-found', `MCP server ${id} does not exist`);
|
|
@@ -2092,6 +2176,68 @@ export class AppServer {
|
|
|
2092
2176
|
return { id };
|
|
2093
2177
|
});
|
|
2094
2178
|
}
|
|
2179
|
+
/**
|
|
2180
|
+
* One configured MCP server as an edit form can show it: the command and its arguments, or the
|
|
2181
|
+
* endpoint, and the *names* of its environment variables and headers. Their values are secrets
|
|
2182
|
+
* the engine never returns; an edit keeps a saved value by naming it (see mergeMcpEdit). The
|
|
2183
|
+
* endpoint is returned without its query string, which can hold a credential.
|
|
2184
|
+
*/
|
|
2185
|
+
async mcpServerView(params) {
|
|
2186
|
+
const id = mcpServerId(params.id);
|
|
2187
|
+
const servers = (await loadConfig(this.directory)).mcpServers ?? {};
|
|
2188
|
+
if (!Object.prototype.hasOwnProperty.call(servers, id))
|
|
2189
|
+
throw new AppServerError('not-found', `MCP server ${id} does not exist`);
|
|
2190
|
+
const server = servers[id];
|
|
2191
|
+
const enabled = server.enabled !== false;
|
|
2192
|
+
if (server.transport === 'stdio') {
|
|
2193
|
+
return { id, transport: 'stdio', enabled, command: server.command, args: server.args ?? [], envKeys: Object.keys(server.env ?? {}) };
|
|
2194
|
+
}
|
|
2195
|
+
const url = new URL(server.url);
|
|
2196
|
+
const query = url.search !== '';
|
|
2197
|
+
url.search = '';
|
|
2198
|
+
return { id, transport: 'http', enabled, url: url.href, ...(query ? { urlQuery: true } : {}), headerKeys: Object.keys(server.headers ?? {}) };
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Check one configured MCP server, on the person's explicit request ("Check Connection"): start
|
|
2202
|
+
* it, ask for its tools, stop it, and record the answer beside the ones tasks record. A server that
|
|
2203
|
+
* is turned off is reported off without being started. A stdio server starts in the workspace the
|
|
2204
|
+
* caller names, as it would for a task there, or the home folder. A page never calls this on its
|
|
2205
|
+
* own: a task asks before it connects a server, and opening Settings is not that consent.
|
|
2206
|
+
*/
|
|
2207
|
+
async mcpStatus(params) {
|
|
2208
|
+
const id = mcpServerId(params.id);
|
|
2209
|
+
const servers = (await loadConfig(this.directory)).mcpServers ?? {};
|
|
2210
|
+
if (!Object.prototype.hasOwnProperty.call(servers, id))
|
|
2211
|
+
throw new AppServerError('not-found', `MCP server ${id} does not exist`);
|
|
2212
|
+
const server = servers[id];
|
|
2213
|
+
if (server.enabled === false)
|
|
2214
|
+
return { id, state: 'off' };
|
|
2215
|
+
const named = typeof params.workspace === 'string' && isAbsolute(params.workspace) ? params.workspace : undefined;
|
|
2216
|
+
const workspace = named !== undefined && await stat(named).then(entry => entry.isDirectory(), () => false) ? named : homedir();
|
|
2217
|
+
const result = await probeMcpServer(server, workspace);
|
|
2218
|
+
const checkedAt = new Date();
|
|
2219
|
+
await mcpStatusStore(this.directory).record(id, server, result, 'check', checkedAt).catch(() => undefined);
|
|
2220
|
+
return { id, ...result, checkedAt: checkedAt.toISOString(), source: 'check' };
|
|
2221
|
+
}
|
|
2222
|
+
/**
|
|
2223
|
+
* What each configured server last answered, without starting anything: the status a task's
|
|
2224
|
+
* connection or an explicit check recorded, while it still describes the server's current
|
|
2225
|
+
* definition. An edited server, and one never connected, has none ("Not checked").
|
|
2226
|
+
*/
|
|
2227
|
+
async mcpStatuses() {
|
|
2228
|
+
const servers = (await loadConfig(this.directory)).mcpServers ?? {};
|
|
2229
|
+
const statuses = {};
|
|
2230
|
+
for (const record of await mcpStatusStore(this.directory).list()) {
|
|
2231
|
+
if (!Object.prototype.hasOwnProperty.call(servers, record.id))
|
|
2232
|
+
continue;
|
|
2233
|
+
const server = servers[record.id];
|
|
2234
|
+
if (mcpDefinitionKey(server) !== record.definition)
|
|
2235
|
+
continue;
|
|
2236
|
+
const { id: _id, definition: _definition, ...status } = record;
|
|
2237
|
+
statuses[record.id] = status;
|
|
2238
|
+
}
|
|
2239
|
+
return { statuses };
|
|
2240
|
+
}
|
|
2095
2241
|
/**
|
|
2096
2242
|
* Apply one provider change inside the serialized configuration transaction.
|
|
2097
2243
|
*
|
|
@@ -2590,7 +2736,7 @@ export class AppServer {
|
|
|
2590
2736
|
return value;
|
|
2591
2737
|
}
|
|
2592
2738
|
catch {
|
|
2593
|
-
throw new AppServerError('not-found', 'That
|
|
2739
|
+
throw new AppServerError('not-found', 'That task no longer exists');
|
|
2594
2740
|
}
|
|
2595
2741
|
}
|
|
2596
2742
|
/**
|
|
@@ -2633,7 +2779,7 @@ export class AppServer {
|
|
|
2633
2779
|
}
|
|
2634
2780
|
catch (error) {
|
|
2635
2781
|
if (error instanceof SessionMutationLockHeldError)
|
|
2636
|
-
throw new AppServerError('busy', 'That
|
|
2782
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
2637
2783
|
throw error;
|
|
2638
2784
|
}
|
|
2639
2785
|
try {
|
|
@@ -2661,7 +2807,7 @@ export class AppServer {
|
|
|
2661
2807
|
// already read. `this.starting` is exactly that window (it is set synchronously by every start),
|
|
2662
2808
|
// and `this.startingSession` names the session a resumed run is being prepared for.
|
|
2663
2809
|
if (this.startingSession === id || this.starting)
|
|
2664
|
-
throw new AppServerError('busy', 'That
|
|
2810
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to begin, then rename it.');
|
|
2665
2811
|
// A run in flight no longer holds the name shut: the finalizer builds its save from the record
|
|
2666
2812
|
// captured at startup, but `saveFinalizedSession` re-reads under the shared per-session mutation
|
|
2667
2813
|
// lock and keeps the user-editable fields from disk, so a rename accepted now survives the run.
|
|
@@ -2677,7 +2823,7 @@ export class AppServer {
|
|
|
2677
2823
|
// the lock on purpose: a second window's mutation may have landed while this one queued, and
|
|
2678
2824
|
// building the new record from a pre-lock snapshot would drop it.
|
|
2679
2825
|
if (await sessionHasOpenRun(this.directory, id, ownRunId === undefined ? {} : { ignoreRunId: ownRunId }))
|
|
2680
|
-
throw new AppServerError('busy', 'That
|
|
2826
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then rename it.');
|
|
2681
2827
|
const record = await this.readSession(id);
|
|
2682
2828
|
// `renamed` pins the name: the automatic titling that names a session from its first prompt reads
|
|
2683
2829
|
// it and leaves a name the user chose alone, so the rename is not a temporary state.
|
|
@@ -2697,12 +2843,12 @@ export class AppServer {
|
|
|
2697
2843
|
async compactSession(params) {
|
|
2698
2844
|
const id = identifier(params.id, 'id');
|
|
2699
2845
|
if (this.startingSession === id || this.starting)
|
|
2700
|
-
throw new AppServerError('busy', 'That
|
|
2846
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to finish, then compact it.');
|
|
2701
2847
|
if (this.run?.sessionId === id || this.finishingSessionId === id)
|
|
2702
|
-
throw new AppServerError('busy', 'That
|
|
2848
|
+
throw new AppServerError('busy', 'That task is running. Stop the run or wait for it to finish, then compact it.');
|
|
2703
2849
|
return this.withSessionMutation(id, async () => {
|
|
2704
2850
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2705
|
-
throw new AppServerError('busy', 'That
|
|
2851
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then compact it.');
|
|
2706
2852
|
const record = await this.readSession(id);
|
|
2707
2853
|
// An in-flight marker is a claim recovery reads, never something to summarize away.
|
|
2708
2854
|
const turns = (record.contextHistory ?? record.history ?? []).filter(turn => turn.completion?.status !== 'running');
|
|
@@ -2778,12 +2924,12 @@ export class AppServer {
|
|
|
2778
2924
|
throw new AppServerError('invalid-params', 'archived must be a boolean');
|
|
2779
2925
|
const archived = params.archived;
|
|
2780
2926
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2781
|
-
throw new AppServerError('busy', 'That
|
|
2927
|
+
throw new AppServerError('busy', 'That task is running. Stop the run or wait for it to finish, then archive it.');
|
|
2782
2928
|
return this.withSessionMutation(id, async () => {
|
|
2783
2929
|
// Cross-process guard, same reasoning as the rename above: an archive accepted while another
|
|
2784
2930
|
// engine owns the session's run is silently reverted when that run saves its captured record.
|
|
2785
2931
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2786
|
-
throw new AppServerError('busy', 'That
|
|
2932
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then archive it.');
|
|
2787
2933
|
// Fresh inside the lock: reading before another window's queued mutation ran would build the
|
|
2788
2934
|
// new record from a snapshot that never saw it, and the save would drop the other change.
|
|
2789
2935
|
const record = await this.readSession(id);
|
|
@@ -2801,12 +2947,12 @@ export class AppServer {
|
|
|
2801
2947
|
// The preparation window counts as running: a delete accepted there would be undone by the
|
|
2802
2948
|
// resumed run saving the record it read — recreating the session the user removed.
|
|
2803
2949
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2804
|
-
throw new AppServerError('busy', 'That
|
|
2950
|
+
throw new AppServerError('busy', 'That task is running. Stop the run before deleting it.');
|
|
2805
2951
|
return this.withSessionMutation(id, async () => {
|
|
2806
2952
|
// Same cross-process reasoning as rename and archive: the other engine's finalize would save the
|
|
2807
2953
|
// record it captured and recreate the session the user just deleted.
|
|
2808
2954
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2809
|
-
throw new AppServerError('busy', 'That
|
|
2955
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run before deleting it.');
|
|
2810
2956
|
// The record goes first. Dropping the wakes before the snapshot is removed would discard pending work on a
|
|
2811
2957
|
// delete that then fails: the session stays on the rail, its row keeps drawing a clock, and the prompts
|
|
2812
2958
|
// behind it can never fire. Nothing this call owns is given up until the removal really happened — and a
|
|
@@ -2825,6 +2971,9 @@ export class AppServer {
|
|
|
2825
2971
|
// Its pull request stops being watched with it: an Auto-fix wake has no conversation left to land in.
|
|
2826
2972
|
await removePullRequest(this.directory, id).catch(() => { });
|
|
2827
2973
|
await removeSessionSkill(this.directory, id).catch(() => { });
|
|
2974
|
+
// The stored originals of its unreviewed changes go too: nothing can ask to undo them any more.
|
|
2975
|
+
if (/^[A-Za-z0-9_-]{1,128}$/.test(id))
|
|
2976
|
+
await this.sessionChanges.remove(id).catch(() => { });
|
|
2828
2977
|
this.emit('session.removed', { id });
|
|
2829
2978
|
return { removed: true };
|
|
2830
2979
|
});
|
|
@@ -3215,7 +3364,7 @@ export class AppServer {
|
|
|
3215
3364
|
}
|
|
3216
3365
|
catch (error) {
|
|
3217
3366
|
if (error instanceof SessionMutationLockHeldError)
|
|
3218
|
-
throw new AppServerError('busy', 'That
|
|
3367
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
3219
3368
|
throw error;
|
|
3220
3369
|
}
|
|
3221
3370
|
}
|
|
@@ -3913,9 +4062,9 @@ export class AppServer {
|
|
|
3913
4062
|
// identity-less (legacy) entry falls back to the complete-message rule.
|
|
3914
4063
|
if (entry.id !== undefined && (!Array.isArray(checkpoint.steeringDelivered) || !checkpoint.steeringDelivered.includes(entry.id)))
|
|
3915
4064
|
return false;
|
|
3916
|
-
// A
|
|
3917
|
-
// conversation that received it carries.
|
|
3918
|
-
return carriesText(asUserMessages(messages), entry.wake
|
|
4065
|
+
// A wake's direction reached the node in its marked wording (the agent's own reminder, or the comments
|
|
4066
|
+
// Auto-fix brought), so that is the text a conversation that received it carries.
|
|
4067
|
+
return carriesText(asUserMessages(messages), wakeMessageText(entry.wake, entry.direction));
|
|
3919
4068
|
};
|
|
3920
4069
|
const checkpointProves = (checkpoint, entry) => {
|
|
3921
4070
|
const parallel = graph.nodes[checkpoint.nodeId]?.modifiers?.parallel;
|
|
@@ -4015,6 +4164,13 @@ export class AppServer {
|
|
|
4015
4164
|
if (![...reachable].some(nodeId => graph.nodes[nodeId]?.type === 'agent')) {
|
|
4016
4165
|
throw new AppServerError('nothing-to-continue', 'That attempt has only steps left that no message can steer, so a resume would record your instruction beside work that never reads it. Send it as a new task instead.');
|
|
4017
4166
|
}
|
|
4167
|
+
// A wake's direction is addressed to one node (the one that set the timer, or switched Auto-fix on), and
|
|
4168
|
+
// only that node reads it. When the edited graph no longer has it as an agent the resumed frontier can
|
|
4169
|
+
// reach, every other reader skips the message, so the continuation would settle the wake unread.
|
|
4170
|
+
const addressed = internal?.wake !== undefined ? internal.wakeNode : undefined;
|
|
4171
|
+
if (addressed !== undefined && (graph.nodes[addressed]?.type !== 'agent' || !reachable.has(addressed))) {
|
|
4172
|
+
throw new AppServerError('nothing-to-continue', 'The node this wake is addressed to cannot run in that attempt any more, so a resume would deliver it to no one. Send it as a new task instead.');
|
|
4173
|
+
}
|
|
4018
4174
|
}
|
|
4019
4175
|
armedCarried = (internal?.carried ?? []).filter(entry => !reenteredCheckpoints.some(checkpoint => checkpointProves(checkpoint, entry)));
|
|
4020
4176
|
}
|
|
@@ -4093,9 +4249,10 @@ export class AppServer {
|
|
|
4093
4249
|
// mark goes with the text it describes: the task of a fresh start, or the direction of a continuation - a
|
|
4094
4250
|
// continuation whose direction was proven delivered by an earlier attempt opens with no text to mark.
|
|
4095
4251
|
const wake = internal?.wake !== undefined && (internal.resumedFrom === undefined || resumedDirection !== undefined) ? internal.wake : undefined;
|
|
4096
|
-
// The node a
|
|
4097
|
-
// resume that recovers the direction still knows
|
|
4098
|
-
|
|
4252
|
+
// The node a wake's continuation direction belongs to (the node that set a timer, or the one that switched
|
|
4253
|
+
// Auto-fix on): read only by that node, and recorded so a later resume that recovers the direction still knows
|
|
4254
|
+
// whose it is.
|
|
4255
|
+
const directionNode = wake !== undefined && resumedDirection !== undefined ? internal?.wakeNode : undefined;
|
|
4099
4256
|
const marker = { task, completion: { summary: RUNNING_TURN_SUMMARY, tests: [], status: 'running' }, runId, ...(internal?.resumedFrom === undefined ? {} : { resumed: true }), ...(resumedDirection === undefined ? {} : { direction: resumedDirection }), ...(attachments?.refs.length ? { attachments: attachments.refs } : {}), ...(wake === undefined ? {} : { wake }) };
|
|
4100
4257
|
// The marker lands in both arrays, exactly as the CLI's persistence path writes it: `history` is
|
|
4101
4258
|
// the transcript a client reads, and `contextHistory` is the model context a later run seeds
|
|
@@ -4231,7 +4388,7 @@ export class AppServer {
|
|
|
4231
4388
|
{
|
|
4232
4389
|
const continues = new Set([runId, ...lineage]);
|
|
4233
4390
|
for (const timer of this.timers.list(record.id)) {
|
|
4234
|
-
if (timer
|
|
4391
|
+
if (!this.nodeReminder(timer) || continues.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
4235
4392
|
continue;
|
|
4236
4393
|
this.spendWake(timer, 'a newer turn in this session replaced the attempt that set it');
|
|
4237
4394
|
}
|
|
@@ -4257,7 +4414,7 @@ export class AppServer {
|
|
|
4257
4414
|
// one as such would rewrite the session's skill and undo a pause or removal made since the stop.
|
|
4258
4415
|
const invocationText = internal?.resumedFrom === undefined ? task
|
|
4259
4416
|
: internal.recoveredDirection === true || internal.wake !== undefined ? undefined : internal.direction;
|
|
4260
|
-
const runTask = this.executeRun({ runId, startedAt, telemetryRunId, ...(accountSubject ? { accountSubject } : {}), ...(invocationText === undefined ? {} : { invocationText }), task, selection, providerId: provider.id, modelId, root, permissions: effective, liveSteers, ...(internal?.inheritedPermissions === undefined ? {} : { boundPermissions: internal.inheritedPermissions }), ...(effort === undefined ? {} : { reasoningEffort: effort }), ...(overrideAllNodes ? { overrideAllNodes: true } : {}), ...(modelPinned ? { modelPinned: true } : {}), ...(nodeModelOverrides === undefined ? {} : { nodeModelOverrides }), ...(panelRelay ? { panelBrowserRelay: true } : {}), ...(entryHistory ? { entryHistory: true } : {}), ...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }), ...(automationContext === undefined ? {} : { automationContext }), ...(resumedDirection === undefined ? {} : { direction: resumedDirection }), ...(wake === undefined ? {} : { wake }), ...(directionNode === undefined ? {} : { directionNode }), ...(armedCarried.length === 0 ? {} : { carriedDirections: armedCarried, pendingDirections: armedCarried.map(entry => ({ runId: entry.runId, direction: entry.direction, ...(entry.id === undefined ? {} : { id: entry.id }), ...wakeProvenance(entry.wake, entry.node) })) }), ownDirectionId: `${runId}#own`, ...(seedExclusions.length === 0 ? {} : { armedRunIds: seedExclusions }), ...(openingAttachments === undefined ? {} : { openingAttachments }), record, controller, ...(attachments === undefined ? {} : { attachments }), ...(internal?.resumedFrom === undefined ? {} : { resumedFrom: internal.resumedFrom }), ...(resumeFrom === undefined ? {} : { resumeFrom }), lineage, ...(lineageArtifacts === undefined ? {} : { lineageArtifacts }), ...(resumedGraph === undefined ? {} : { prepared: resumedGraph }) })
|
|
4417
|
+
const runTask = this.executeRun({ runId, startedAt, telemetryRunId, ...(accountSubject ? { accountSubject } : {}), ...(invocationText === undefined ? {} : { invocationText }), task, selection, providerId: provider.id, modelId, root, permissions: effective, liveSteers, ...(internal?.inheritedPermissions === undefined ? {} : { boundPermissions: internal.inheritedPermissions }), ...(effort === undefined ? {} : { reasoningEffort: effort }), ...(overrideAllNodes ? { overrideAllNodes: true } : {}), ...(modelPinned ? { modelPinned: true } : {}), ...(nodeModelOverrides === undefined ? {} : { nodeModelOverrides }), ...(panelRelay ? { panelBrowserRelay: true } : {}), ...(entryHistory ? { entryHistory: true } : {}), ...(runInput === undefined ? {} : { runInput }), ...(runState === undefined ? {} : { runState }), ...(automationContext === undefined ? {} : { automationContext }), ...(resumedDirection === undefined ? {} : { direction: resumedDirection }), ...(wake === undefined ? {} : { wake }), ...(directionNode === undefined ? {} : { directionNode }), ...(internal?.startNode === undefined ? {} : { startNode: internal.startNode }), ...(armedCarried.length === 0 ? {} : { carriedDirections: armedCarried, pendingDirections: armedCarried.map(entry => ({ runId: entry.runId, direction: entry.direction, ...(entry.id === undefined ? {} : { id: entry.id }), ...wakeProvenance(entry.wake, entry.node) })) }), ownDirectionId: `${runId}#own`, ...(seedExclusions.length === 0 ? {} : { armedRunIds: seedExclusions }), ...(openingAttachments === undefined ? {} : { openingAttachments }), record, controller, ...(attachments === undefined ? {} : { attachments }), ...(internal?.resumedFrom === undefined ? {} : { resumedFrom: internal.resumedFrom }), ...(resumeFrom === undefined ? {} : { resumeFrom }), lineage, ...(lineageArtifacts === undefined ? {} : { lineageArtifacts }), ...(resumedGraph === undefined ? {} : { prepared: resumedGraph }) })
|
|
4261
4418
|
.catch(error => this.log('error', `Run ${runId} failed: ${message(error)}`));
|
|
4262
4419
|
// The finally sits outside the awaited chain so the settle can name the exact promise this
|
|
4263
4420
|
// attempt owns: the finalizer now releases the live-run slot before the terminal events, so a
|
|
@@ -4379,7 +4536,7 @@ export class AppServer {
|
|
|
4379
4536
|
this.sessionTitles.clear();
|
|
4380
4537
|
}
|
|
4381
4538
|
async executeRun(input) {
|
|
4382
|
-
const { runId, startedAt, telemetryRunId, accountSubject, task, selection, providerId, modelId, root, permissions, liveSteers, boundPermissions, reasoningEffort, overrideAllNodes = false, modelPinned = overrideAllNodes, panelBrowserRelay = false, entryHistory = false, runInput, runState, automationContext, direction, wake, carriedDirections, ownDirectionId, armedRunIds, pendingDirections, directionNode, controller, attachments, openingAttachments, resumedFrom, resumeFrom, lineage, lineageArtifacts, prepared, nodeModelOverrides } = input;
|
|
4539
|
+
const { runId, startedAt, telemetryRunId, accountSubject, task, selection, providerId, modelId, root, permissions, liveSteers, boundPermissions, reasoningEffort, overrideAllNodes = false, modelPinned = overrideAllNodes, panelBrowserRelay = false, entryHistory = false, runInput, runState, automationContext, direction, wake, carriedDirections, ownDirectionId, armedRunIds, pendingDirections, directionNode, startNode, controller, attachments, openingAttachments, resumedFrom, resumeFrom, lineage, lineageArtifacts, prepared, nodeModelOverrides } = input;
|
|
4383
4540
|
const signal = controller.signal;
|
|
4384
4541
|
const liveRun = this.run?.runId === runId ? this.run : undefined;
|
|
4385
4542
|
if (liveRun)
|
|
@@ -4498,15 +4655,16 @@ export class AppServer {
|
|
|
4498
4655
|
for (const entry of carriedDirections ?? []) {
|
|
4499
4656
|
const refs = entry.attachments ?? [];
|
|
4500
4657
|
const images = refs.length ? await loadResolvedImages(this.directory, root, refs) : [];
|
|
4501
|
-
const said = entry.wake
|
|
4502
|
-
arm(entry.wake ===
|
|
4658
|
+
const said = wakeMessageText(entry.wake, entry.direction);
|
|
4659
|
+
arm(entry.wake === undefined ? undefined : entry.node, { ...(entry.id === undefined ? {} : { id: entry.id }), content: refs.length ? `${said}\n\n${attachmentReferenceBlock(refs, { imagesIncluded: images.length > 0 })}` : said, images });
|
|
4503
4660
|
}
|
|
4504
4661
|
if (direction !== undefined) {
|
|
4505
4662
|
const refs = attachments?.refs ?? [];
|
|
4506
4663
|
const images = attachments?.images ?? [];
|
|
4507
|
-
// A continuation a
|
|
4508
|
-
|
|
4509
|
-
|
|
4664
|
+
// A continuation a wake delivered opens with the agent's own reminder (or Auto-fix's comments), read as one
|
|
4665
|
+
// rather than as the user's words, by the node the wake is addressed to.
|
|
4666
|
+
const said = wakeMessageText(wake, direction);
|
|
4667
|
+
arm(wake === undefined ? undefined : directionNode, { ...(ownDirectionId === undefined ? {} : { id: ownDirectionId }), content: refs.length ? `${said}\n\n${attachmentReferenceBlock(refs, { imagesIncluded: images.length > 0 })}` : said, images });
|
|
4510
4668
|
}
|
|
4511
4669
|
const steering = armed.length === 0 ? undefined : armed;
|
|
4512
4670
|
// The messages the user typed into the live attempt, in the order the runtime read them. Each
|
|
@@ -4881,6 +5039,9 @@ export class AppServer {
|
|
|
4881
5039
|
timers: this.timers, sessionScope: input.record.id, wakesArmed, automationDirectory: this.directory,
|
|
4882
5040
|
wakeCarry,
|
|
4883
5041
|
pullRequests: this.pullRequestControl(input.record.id, wakeCarry),
|
|
5042
|
+
// Every write the run makes to a workspace file is kept for review under the session it belongs to,
|
|
5043
|
+
// unless the run has Full Access when the write lands: that mode asks nothing, a Keep included.
|
|
5044
|
+
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)}`), () => livePermissionMode(toolContext) !== 'full-access'),
|
|
4884
5045
|
};
|
|
4885
5046
|
bootMark('run.exec.mcp.connect.start');
|
|
4886
5047
|
// The health verdict is watched while the servers connect, not after: a server can wait on the
|
|
@@ -4899,7 +5060,7 @@ export class AppServer {
|
|
|
4899
5060
|
// until a model calls one of those tools, and that call waits for the connection.
|
|
4900
5061
|
const servers = graphMcpServers(graph.id, extension.servers);
|
|
4901
5062
|
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) })
|
|
5063
|
+
? 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
5064
|
: Promise.resolve(undefined);
|
|
4904
5065
|
try {
|
|
4905
5066
|
mcp = await Promise.race([connecting, healthGate.then(() => connecting)]);
|
|
@@ -4949,6 +5110,7 @@ export class AppServer {
|
|
|
4949
5110
|
// choices; adaptive routing leaves them alone.
|
|
4950
5111
|
modelPinned: modelPinned || overrideAllNodes,
|
|
4951
5112
|
...(entryHistory ? { entryHistory: true } : {}),
|
|
5113
|
+
...(startNode === undefined ? {} : { startNode }),
|
|
4952
5114
|
configuredModels: config.providers.map(item => ({ id: item.id, model: item.model, ...(item.models ? { models: [...item.models] } : {}) })),
|
|
4953
5115
|
// The executor resolves its own model rather than reusing `adapter`, so the task's effort is
|
|
4954
5116
|
// handed to it as well — for the run's own provider and model only: a node that pins another
|
|
@@ -5060,8 +5222,9 @@ export class AppServer {
|
|
|
5060
5222
|
}
|
|
5061
5223
|
// A `gh pr create` the agent ran puts the PR it opened on the session's Plan card.
|
|
5062
5224
|
const created = pullRequestDetector.observe(event);
|
|
5225
|
+
const attachingNode = typeof event.data?.nodeId === 'string' && event.data.nodeId ? event.data.nodeId : undefined;
|
|
5063
5226
|
if (created)
|
|
5064
|
-
void this.attachPullRequest(input.record.id, created, {}, wakeCarry).catch(error => this.log('warn', `Could not attach ${created.url}: ${message(error)}`));
|
|
5227
|
+
void this.attachPullRequest(input.record.id, created, {}, wakeCarry, attachingNode === undefined ? undefined : { runId, nodeId: attachingNode }).catch(error => this.log('warn', `Could not attach ${created.url}: ${message(error)}`));
|
|
5065
5228
|
},
|
|
5066
5229
|
onUsage: (delta, origin) => {
|
|
5067
5230
|
foldUsage(runUsage, delta);
|
|
@@ -7257,12 +7420,148 @@ export class AppServer {
|
|
|
7257
7420
|
/** Say what a session is waiting on. An empty list is a real answer: it is what ends a wait. */
|
|
7258
7421
|
emitPullRequest(sessionId, pullRequest) {
|
|
7259
7422
|
this.emit('session.pullRequest.updated', { sessionId, pullRequest: pullRequestForClients(pullRequest) });
|
|
7423
|
+
// Every change to the record passes here, so a run waiting on its review hears the ones that end the wait.
|
|
7424
|
+
const waiter = this.reviewWaiters.get(sessionId);
|
|
7425
|
+
if (!waiter)
|
|
7426
|
+
return;
|
|
7427
|
+
if (pullRequest === null)
|
|
7428
|
+
waiter({ kind: 'none' });
|
|
7429
|
+
else if (isFinishedPullRequest(pullRequest.state))
|
|
7430
|
+
waiter({ kind: 'finished', pullRequest });
|
|
7431
|
+
else if (!pullRequest.autoFix)
|
|
7432
|
+
waiter({ kind: 'off', pullRequest });
|
|
7433
|
+
}
|
|
7434
|
+
/**
|
|
7435
|
+
* Hold the calling run until its PR's next review: the comments the watcher finds are handed to it as the Auto-fix
|
|
7436
|
+
* prompt would be, instead of being armed as a wake. A wake already armed for comments it has not delivered is
|
|
7437
|
+
* taken at once. `origin` (the waiting node) becomes the node later Auto-fix wakes go to, since it owns the loop.
|
|
7438
|
+
*/
|
|
7439
|
+
async awaitReview(sessionId, signal, timeoutMs, origin) {
|
|
7440
|
+
if (signal.aborted)
|
|
7441
|
+
return { kind: 'aborted' };
|
|
7442
|
+
// The session's one wait is reserved before anything yields: two branches calling at once must not both pass
|
|
7443
|
+
// this check and have the second waiter replace the first.
|
|
7444
|
+
if (this.reviewWaiters.has(sessionId) || this.reviewWaitsStarting.has(sessionId))
|
|
7445
|
+
throw new Error('Another call in this session is already waiting for this pull request review.');
|
|
7446
|
+
this.reviewWaitsStarting.add(sessionId);
|
|
7447
|
+
try {
|
|
7448
|
+
if (origin !== undefined) {
|
|
7449
|
+
await withPullRequest(this.directory, sessionId, async () => {
|
|
7450
|
+
const current = await readPullRequest(this.directory, sessionId);
|
|
7451
|
+
if (!current || (current.origin?.runId === origin.runId && current.origin.nodeId === origin.nodeId))
|
|
7452
|
+
return;
|
|
7453
|
+
await writePullRequest(this.directory, sessionId, { ...current, origin: { runId: origin.runId, nodeId: origin.nodeId }, updatedAt: new Date().toISOString() });
|
|
7454
|
+
});
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
finally {
|
|
7458
|
+
this.reviewWaitsStarting.delete(sessionId);
|
|
7459
|
+
}
|
|
7460
|
+
// Nothing yields between the reservation's release above and the waiter's install below.
|
|
7461
|
+
return await new Promise(resolve => {
|
|
7462
|
+
let settled = false;
|
|
7463
|
+
const finish = (ended) => {
|
|
7464
|
+
if (settled)
|
|
7465
|
+
return false;
|
|
7466
|
+
settled = true;
|
|
7467
|
+
clearTimeout(timeout);
|
|
7468
|
+
clearInterval(ticks);
|
|
7469
|
+
signal.removeEventListener('abort', aborted);
|
|
7470
|
+
if (this.reviewWaiters.get(sessionId) === finish)
|
|
7471
|
+
this.reviewWaiters.delete(sessionId);
|
|
7472
|
+
resolve(ended);
|
|
7473
|
+
return true;
|
|
7474
|
+
};
|
|
7475
|
+
const aborted = () => { finish({ kind: 'aborted' }); };
|
|
7476
|
+
const timeout = setTimeout(() => finish({ kind: 'timeout' }), timeoutMs);
|
|
7477
|
+
// The record is the shared answer: comments another engine's watcher found (it holds the watcher's lease, so
|
|
7478
|
+
// this engine's poll finds nothing), and a merge, close or switch-off saved by any engine.
|
|
7479
|
+
const fromRecord = () => {
|
|
7480
|
+
void this.reviewWaitFromRecord(sessionId, finish).catch(error => this.log('warn', `Could not read the pull request of session ${sessionId} for a review wait: ${message(error)}`));
|
|
7481
|
+
};
|
|
7482
|
+
// A message the user types into the run is read only at the next turn boundary, which a wait never reaches:
|
|
7483
|
+
// the wait ends so the agent can read it. Wakes queued as steers are the run's own reminders, not the user.
|
|
7484
|
+
let tick = 0;
|
|
7485
|
+
const ticks = setInterval(() => {
|
|
7486
|
+
const live = this.run;
|
|
7487
|
+
if (live?.sessionId === sessionId && live.steers.some(entry => entry.wake === undefined))
|
|
7488
|
+
finish({ kind: 'steered' });
|
|
7489
|
+
else if (++tick % REVIEW_WAIT_RECORD_TICKS === 0)
|
|
7490
|
+
fromRecord();
|
|
7491
|
+
}, 1_000);
|
|
7492
|
+
timeout.unref?.();
|
|
7493
|
+
ticks.unref?.();
|
|
7494
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
7495
|
+
// Stopped while the origin was being saved: a listener added to an aborted signal never fires.
|
|
7496
|
+
if (signal.aborted) {
|
|
7497
|
+
finish({ kind: 'aborted' });
|
|
7498
|
+
return;
|
|
7499
|
+
}
|
|
7500
|
+
this.reviewWaiters.set(sessionId, finish);
|
|
7501
|
+
fromRecord();
|
|
7502
|
+
// Look now rather than at the next tick: comments may already be waiting.
|
|
7503
|
+
void this.pullRequestWatcher.poll();
|
|
7504
|
+
});
|
|
7505
|
+
}
|
|
7506
|
+
/**
|
|
7507
|
+
* What the session's PR record says a review wait should end with, handed to `deliver`: the PR is gone, finished or
|
|
7508
|
+
* has Auto-fix off, or it holds comments found and not yet carried by a run. Those are taken under the lock, handed
|
|
7509
|
+
* over first and only then marked handled, so a wait that ended meanwhile never loses them. A wake this engine is
|
|
7510
|
+
* delivering now is left to that delivery.
|
|
7511
|
+
*/
|
|
7512
|
+
async reviewWaitFromRecord(sessionId, deliver) {
|
|
7513
|
+
const taken = await withPullRequest(this.directory, sessionId, async () => {
|
|
7514
|
+
const current = await readPullRequest(this.directory, sessionId);
|
|
7515
|
+
if (!current) {
|
|
7516
|
+
deliver({ kind: 'none' });
|
|
7517
|
+
return undefined;
|
|
7518
|
+
}
|
|
7519
|
+
if (isFinishedPullRequest(current.state)) {
|
|
7520
|
+
deliver({ kind: 'finished', pullRequest: current });
|
|
7521
|
+
return undefined;
|
|
7522
|
+
}
|
|
7523
|
+
if (!current.autoFix) {
|
|
7524
|
+
deliver({ kind: 'off', pullRequest: current });
|
|
7525
|
+
return undefined;
|
|
7526
|
+
}
|
|
7527
|
+
const pending = current.pendingFix;
|
|
7528
|
+
if (pending === undefined || this.timers.isHeld(pending.wakeId))
|
|
7529
|
+
return undefined;
|
|
7530
|
+
const prompt = pending.prompt ?? this.timers.get(pending.wakeId)?.prompt;
|
|
7531
|
+
if (prompt === undefined || !deliver({ kind: 'comments', prompt }))
|
|
7532
|
+
return undefined;
|
|
7533
|
+
// A wake this engine armed for them is now answered. One another engine armed is dropped there at delivery,
|
|
7534
|
+
// which finds the record no longer asking for it (`confirmAutoFixWake`).
|
|
7535
|
+
if (this.autoFixWakes.has(pending.wakeId))
|
|
7536
|
+
this.cancelAutoFixWake(sessionId, pending.wakeId);
|
|
7537
|
+
const { pendingFix: _pending, ...rest } = current;
|
|
7538
|
+
const next = { ...rest, handledThrough: pending.through, updatedAt: new Date().toISOString() };
|
|
7539
|
+
await writePullRequest(this.directory, sessionId, next);
|
|
7540
|
+
return next;
|
|
7541
|
+
});
|
|
7542
|
+
if (taken)
|
|
7543
|
+
this.emitPullRequest(sessionId, taken);
|
|
7544
|
+
}
|
|
7545
|
+
/** A run now carries the Auto-fix prompt behind `wakeId`: its comments are handled. */
|
|
7546
|
+
async recordAutoFixDelivered(sessionId, wakeId) {
|
|
7547
|
+
try {
|
|
7548
|
+
const pullRequest = await markAutoFixDelivered(this.directory, sessionId, wakeId);
|
|
7549
|
+
if (pullRequest)
|
|
7550
|
+
this.emitPullRequest(sessionId, pullRequest);
|
|
7551
|
+
}
|
|
7552
|
+
catch (error) {
|
|
7553
|
+
this.log('warn', `Could not record the Auto-fix delivery for session ${sessionId}: ${message(error)}`);
|
|
7554
|
+
}
|
|
7555
|
+
}
|
|
7556
|
+
/** The pending set as a change left it, without diffs: a client reads those with `sessions.changes.list`. */
|
|
7557
|
+
emitSessionChanges(changes) {
|
|
7558
|
+
this.emit('session.changes.updated', { sessionId: changes.sessionId, revision: changes.revision, changes: changes.changes });
|
|
7260
7559
|
}
|
|
7261
7560
|
/**
|
|
7262
7561
|
* Start tracking `ref` for the session. A PR already tracked under the same URL keeps its settings, so a
|
|
7263
7562
|
* repeated `gh pr create` (which reports the existing PR) never switches off what the user turned on.
|
|
7264
7563
|
*/
|
|
7265
|
-
async attachPullRequest(sessionId, ref, settings = {}, carry) {
|
|
7564
|
+
async attachPullRequest(sessionId, ref, settings = {}, carry, origin) {
|
|
7266
7565
|
const attached = await withPullRequest(this.directory, sessionId, async () => {
|
|
7267
7566
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7268
7567
|
let next = current?.url === ref.url ? current : newPullRequest(ref);
|
|
@@ -7282,6 +7581,9 @@ export class AppServer {
|
|
|
7282
7581
|
// The run that attached it names the graph, model and effort an Auto-fix run continues under.
|
|
7283
7582
|
if (carry !== undefined)
|
|
7284
7583
|
next = { ...next, carry: structuredClone(carry) };
|
|
7584
|
+
// The node Auto-fix wakes: the one that switches it on, or the one that attached the PR when none has yet.
|
|
7585
|
+
if (origin !== undefined && (settings.autoFix === true || next.origin === undefined))
|
|
7586
|
+
next = { ...next, origin: { runId: origin.runId, nodeId: origin.nodeId } };
|
|
7285
7587
|
if (Object.keys(settings).length)
|
|
7286
7588
|
next = await applyPullRequestSettingsAsReadableAccount(this.gh, next, settings);
|
|
7287
7589
|
await writePullRequest(this.directory, sessionId, next);
|
|
@@ -7292,7 +7594,7 @@ export class AppServer {
|
|
|
7292
7594
|
void this.pullRequestWatcher.poll();
|
|
7293
7595
|
return attached;
|
|
7294
7596
|
}
|
|
7295
|
-
async updatePullRequest(sessionId, settings, carry) {
|
|
7597
|
+
async updatePullRequest(sessionId, settings, carry, origin) {
|
|
7296
7598
|
const updated = await withPullRequest(this.directory, sessionId, async () => {
|
|
7297
7599
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7298
7600
|
if (!current)
|
|
@@ -7306,6 +7608,9 @@ export class AppServer {
|
|
|
7306
7608
|
}
|
|
7307
7609
|
if (carry !== undefined)
|
|
7308
7610
|
next = { ...next, carry: structuredClone(carry) };
|
|
7611
|
+
// The node that switches Auto-fix on is the one its prompts go back to.
|
|
7612
|
+
if (origin !== undefined && settings.autoFix === true)
|
|
7613
|
+
next = { ...next, origin: { runId: origin.runId, nodeId: origin.nodeId } };
|
|
7309
7614
|
// Auto-fix switched off: a wake it already armed is no longer the user's wish.
|
|
7310
7615
|
if (!next.autoFix && next.pendingFix) {
|
|
7311
7616
|
this.cancelAutoFixWake(sessionId, next.pendingFix.wakeId);
|
|
@@ -7343,23 +7648,34 @@ export class AppServer {
|
|
|
7343
7648
|
pullRequestControl(sessionId, carry) {
|
|
7344
7649
|
return {
|
|
7345
7650
|
status: () => readPullRequest(this.directory, sessionId),
|
|
7346
|
-
attach: (url, settings) => {
|
|
7651
|
+
attach: (url, settings, origin) => {
|
|
7347
7652
|
const ref = parsePullRequestUrl(url);
|
|
7348
7653
|
if (!ref)
|
|
7349
7654
|
throw new Error('url must be a GitHub pull request URL, https://github.com/<owner>/<repo>/pull/<number>');
|
|
7350
|
-
return this.attachPullRequest(sessionId, ref, settings, carry);
|
|
7655
|
+
return this.attachPullRequest(sessionId, ref, settings, carry, origin);
|
|
7351
7656
|
},
|
|
7352
|
-
update: settings => this.updatePullRequest(sessionId, settings, carry),
|
|
7657
|
+
update: (settings, origin) => this.updatePullRequest(sessionId, settings, carry, origin),
|
|
7658
|
+
awaitReview: (signal, timeoutMs, origin) => this.awaitReview(sessionId, signal, timeoutMs, origin),
|
|
7353
7659
|
dismiss: () => this.dismissPullRequest(sessionId),
|
|
7354
7660
|
};
|
|
7355
7661
|
}
|
|
7356
7662
|
/**
|
|
7357
7663
|
* Hand an Auto-fix prompt to the session through the same wake a `set_timer` arms, under the selections the
|
|
7358
7664
|
* session's PR was configured from: without them the continuation would run under whatever graph and model
|
|
7359
|
-
* the configuration names today, with different tools than the work it is fixing.
|
|
7665
|
+
* the configuration names today, with different tools than the work it is fixing. `origin` addresses the prompt to
|
|
7666
|
+
* the graph node that switched Auto-fix on (`deliverDueTimers`), rather than to the graph's entry node.
|
|
7360
7667
|
*/
|
|
7361
|
-
wakeForPullRequest(sessionId, prompt, carry) {
|
|
7362
|
-
|
|
7668
|
+
wakeForPullRequest(sessionId, prompt, carry, origin) {
|
|
7669
|
+
// A run waiting on this review takes the prompt itself, and no wake is armed. The watcher records the id as the
|
|
7670
|
+
// pending fix under the lock it holds now; the delivery mark queues behind that lock and moves the handled mark.
|
|
7671
|
+
const waiter = this.reviewWaiters.get(sessionId);
|
|
7672
|
+
if (waiter) {
|
|
7673
|
+
const id = `review-${randomUUID()}`;
|
|
7674
|
+
waiter({ kind: 'comments', prompt });
|
|
7675
|
+
void this.recordAutoFixDelivered(sessionId, id);
|
|
7676
|
+
return id;
|
|
7677
|
+
}
|
|
7678
|
+
const timer = this.timers.arm(1, prompt, sessionId, carry, origin);
|
|
7363
7679
|
this.autoFixWakes.add(timer.id);
|
|
7364
7680
|
this.emitTimers(sessionId);
|
|
7365
7681
|
this.armTimerCheck();
|
|
@@ -7440,6 +7756,17 @@ export class AppServer {
|
|
|
7440
7756
|
this.emit('timers.spent', { sessionId, timerId: timer.id, prompt: timer.prompt, reason });
|
|
7441
7757
|
this.emitTimers(sessionId);
|
|
7442
7758
|
}
|
|
7759
|
+
/**
|
|
7760
|
+
* Whether a wake is a `set_timer` reminder a graph node set about the work it was doing. Those belong to that work:
|
|
7761
|
+
* they are read by the node while its attempt runs, and spent once the node or the attempt is done with it.
|
|
7762
|
+
*
|
|
7763
|
+
* An Auto-fix wake also names a node (the one that switched Auto-fix on), but only as its address: review comments
|
|
7764
|
+
* are new work that outlives the attempt that turned Auto-fix on, so they are never spent with it and always wait
|
|
7765
|
+
* for the engine to be free (`deliverDueTimers`).
|
|
7766
|
+
*/
|
|
7767
|
+
nodeReminder(timer) {
|
|
7768
|
+
return timer.origin !== undefined && !this.autoFixWakes.has(timer.id);
|
|
7769
|
+
}
|
|
7443
7770
|
/**
|
|
7444
7771
|
* Spend the session's node-armed wakes that belong to an attempt in `attempts` and satisfy `spent`.
|
|
7445
7772
|
*
|
|
@@ -7448,7 +7775,7 @@ export class AppServer {
|
|
|
7448
7775
|
*/
|
|
7449
7776
|
spendAttemptWakes(sessionId, attempts, reason, spent = () => true) {
|
|
7450
7777
|
for (const timer of this.timers.list(sessionId)) {
|
|
7451
|
-
if (timer
|
|
7778
|
+
if (!this.nodeReminder(timer) || !attempts.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
7452
7779
|
continue;
|
|
7453
7780
|
if (spent(timer.origin))
|
|
7454
7781
|
this.spendWake(timer, reason);
|
|
@@ -7466,7 +7793,7 @@ export class AppServer {
|
|
|
7466
7793
|
return;
|
|
7467
7794
|
const own = new Set([live.runId, ...(live.lineage ?? [])]);
|
|
7468
7795
|
for (;;) {
|
|
7469
|
-
const timer = this.timers.takeDueOne(Date.now(), live.sessionId, candidate => candidate
|
|
7796
|
+
const timer = this.timers.takeDueOne(Date.now(), live.sessionId, candidate => this.nodeReminder(candidate) && own.has(candidate.origin.runId));
|
|
7470
7797
|
if (timer === undefined)
|
|
7471
7798
|
return;
|
|
7472
7799
|
const at = new Date().toISOString();
|
|
@@ -7528,7 +7855,10 @@ export class AppServer {
|
|
|
7528
7855
|
return { wait: 'its attempt is still running in another engine' };
|
|
7529
7856
|
// The node finished after the reminder was set: what it was waiting on is behind it, and continuing the
|
|
7530
7857
|
// attempt from wherever it stopped would hand the reminder to work it was never about.
|
|
7531
|
-
|
|
7858
|
+
// An Auto-fix wake is addressed to a node rather than armed in the middle of its work, so any completion of that
|
|
7859
|
+
// node counts: an attempt that stopped after the node finished would re-enter elsewhere, and the comments,
|
|
7860
|
+
// addressed to a node that never runs again, would go unread. It starts at the node instead.
|
|
7861
|
+
const armedAt = this.autoFixWakes.has(timer.id) ? Number.NEGATIVE_INFINITY : timer.fireAt - timer.seconds * 1_000;
|
|
7532
7862
|
for (const attempt of chain) {
|
|
7533
7863
|
const journal = await readFile(runRecordPath(this.directory, attempt, 'jsonl'), 'utf8').catch(() => '');
|
|
7534
7864
|
for (const line of journal.split('\n')) {
|
|
@@ -7654,7 +7984,13 @@ export class AppServer {
|
|
|
7654
7984
|
// A wake a graph node armed goes back to that node's work: as a continuation of the attempt it armed, from
|
|
7655
7985
|
// that node's checkpoint. One with nothing left to continue is spent, never started as a new task that
|
|
7656
7986
|
// enters the graph at its entry node with the agent's reminder for a prompt.
|
|
7987
|
+
//
|
|
7988
|
+
// An Auto-fix wake goes to the node that switched Auto-fix on, never to the entry node: into that node's
|
|
7989
|
+
// stopped attempt when there is one to continue, and otherwise as a new run of the session that starts at
|
|
7990
|
+
// that node. Review comments are work that is still owed when that attempt is over, so it is never spent.
|
|
7991
|
+
const autoFix = this.autoFixWakes.has(timer.id);
|
|
7657
7992
|
let resume;
|
|
7993
|
+
let startNode;
|
|
7658
7994
|
if (timer.origin !== undefined) {
|
|
7659
7995
|
let plan;
|
|
7660
7996
|
try {
|
|
@@ -7669,13 +8005,18 @@ export class AppServer {
|
|
|
7669
8005
|
this.log('info', `Self-wake ${timer.id} waits: ${plan.wait}`);
|
|
7670
8006
|
continue;
|
|
7671
8007
|
}
|
|
7672
|
-
if ('spent' in plan) {
|
|
8008
|
+
if ('spent' in plan && !autoFix) {
|
|
7673
8009
|
this.spendWake(timer, plan.spent);
|
|
7674
8010
|
continue;
|
|
7675
8011
|
}
|
|
7676
|
-
resume
|
|
8012
|
+
if ('resume' in plan)
|
|
8013
|
+
resume = plan.resume;
|
|
8014
|
+
else
|
|
8015
|
+
startNode = timer.origin.nodeId;
|
|
7677
8016
|
}
|
|
7678
|
-
this.log('info', resume
|
|
8017
|
+
this.log('info', resume !== undefined ? `Delivering self-wake ${timer.id} to session ${sessionId} as a continuation of ${resume}`
|
|
8018
|
+
: startNode !== undefined ? `Delivering self-wake ${timer.id} to session ${sessionId} at node ${startNode}`
|
|
8019
|
+
: `Delivering self-wake ${timer.id} to session ${sessionId}`);
|
|
7679
8020
|
// The row keeps saying the session is waiting until a run is really there to carry the prompt. The list
|
|
7680
8021
|
// is republished after the attempt rather than before it, so there is no moment between the deadline and
|
|
7681
8022
|
// `run.started` in which the session reads as done with the user while its prompt has gone nowhere.
|
|
@@ -7689,13 +8030,25 @@ export class AppServer {
|
|
|
7689
8030
|
// The continuation runs under the attempt's own recorded selections (`resumeRun` reads them from its
|
|
7690
8031
|
// record), with the reminder as the direction the re-entered node reads at its first turn boundary.
|
|
7691
8032
|
// Only the panel relay is this engine's own and not the record's, so it rides along.
|
|
7692
|
-
|
|
7693
|
-
|
|
8033
|
+
try {
|
|
8034
|
+
await this.resumeRun({ runId: resume, direction: timer.prompt,
|
|
8035
|
+
...(carry?.panelBrowserRelay === true ? { panelBrowserRelay: true } : {}) }, { wake: autoFix ? 'auto-fix' : 'timer', wakeNode: timer.origin.nodeId, freshAllowance: true });
|
|
8036
|
+
}
|
|
8037
|
+
catch (error) {
|
|
8038
|
+
// A reminder with nothing to continue is spent below. Review comments are still owed: they start at
|
|
8039
|
+
// the node instead.
|
|
8040
|
+
if (!autoFix || !isFinalWakeRefusal(error))
|
|
8041
|
+
throw error;
|
|
8042
|
+
this.log('info', `Auto-fix wake ${timer.id} starts at node ${timer.origin.nodeId}: ${resume} could not be continued (${message(error)})`);
|
|
8043
|
+
resume = undefined;
|
|
8044
|
+
startNode = timer.origin.nodeId;
|
|
8045
|
+
}
|
|
7694
8046
|
}
|
|
7695
|
-
|
|
7696
|
-
//
|
|
7697
|
-
//
|
|
7698
|
-
//
|
|
8047
|
+
if (resume === undefined) {
|
|
8048
|
+
// An Auto-fix wake with no attempt to continue starts at the node it is addressed to, and a wake no graph
|
|
8049
|
+
// node armed (an Auto-fix wake from a PR no node configured, or one held from before wakes named their
|
|
8050
|
+
// node) starts at the entry the way it always did. It carries the selections of the run that armed it
|
|
8051
|
+
// (see `WakeCarry`): starting it with only the workspace, session and prompt would hand it whatever the
|
|
7699
8052
|
// configuration says today.
|
|
7700
8053
|
await this.startRun({ workspace: record.workspace, sessionId, task: timer.prompt,
|
|
7701
8054
|
...(carry?.graph === undefined ? {} : { graph: carry.graph }),
|
|
@@ -7705,7 +8058,7 @@ export class AppServer {
|
|
|
7705
8058
|
...(carry?.overrideAllNodes === undefined ? {} : { overrideAllNodes: carry.overrideAllNodes }),
|
|
7706
8059
|
...(carry?.panelBrowserRelay === undefined ? {} : { panelBrowserRelay: carry.panelBrowserRelay }),
|
|
7707
8060
|
...(carry?.input === undefined ? {} : { input: carry.input }),
|
|
7708
|
-
...(carry?.state === undefined ? {} : { state: carry.state }) }, { sameSession: sessionId, wake:
|
|
8061
|
+
...(carry?.state === undefined ? {} : { state: carry.state }) }, { sameSession: sessionId, wake: autoFix ? 'auto-fix' : 'timer', ...(startNode === undefined ? {} : { startNode }) });
|
|
7709
8062
|
}
|
|
7710
8063
|
// Given: a run of this session carries the prompt, so the wake is no longer owed and the row stops waiting.
|
|
7711
8064
|
this.timers.settle(timer.id);
|
|
@@ -7830,6 +8183,8 @@ export class AppServer {
|
|
|
7830
8183
|
if (this.automationCheck)
|
|
7831
8184
|
clearInterval(this.automationCheck);
|
|
7832
8185
|
await this.pullRequestWatcher.stop().catch(() => { });
|
|
8186
|
+
for (const waiter of [...this.reviewWaiters.values()])
|
|
8187
|
+
waiter({ kind: 'aborted' });
|
|
7833
8188
|
if (this.autoArchiveCheck)
|
|
7834
8189
|
clearInterval(this.autoArchiveCheck);
|
|
7835
8190
|
this.automationController.abort();
|