@andorra-labs/code 0.1.10 → 0.1.12
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 +31 -205
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/dist/src/agent-execution.js +50 -2
- package/dist/src/agent-mcp.js +5 -0
- package/dist/src/app-server/protocol.d.ts +9 -1
- package/dist/src/app-server/protocol.js +1 -1
- package/dist/src/app-server.d.ts +49 -1
- package/dist/src/app-server.js +353 -64
- package/dist/src/automation-service.js +1 -1
- package/dist/src/browser-panel-tool.d.ts +24 -3
- package/dist/src/browser-panel-tool.js +80 -6
- package/dist/src/browser-runner.js +3 -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 +237 -15
- package/dist/src/browser-ui/index.html +5 -5
- package/dist/src/browser-ui/style.css +110 -65
- package/dist/src/browser-ui/tokens.css +27 -26
- package/dist/src/browser-view.d.ts +16 -0
- package/dist/src/browser-view.js +38 -2
- package/dist/src/claude-provider.js +15 -2
- package/dist/src/cli.d.ts +2 -1
- package/dist/src/cli.js +175 -43
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +1 -1
- package/dist/src/codex-provider.js +6 -3
- package/dist/src/coding-tools.d.ts +26 -1
- package/dist/src/coding-tools.js +104 -33
- package/dist/src/command-screens.js +1 -1
- package/dist/src/commands.js +1 -1
- package/dist/src/completion-gates.d.ts +42 -7
- package/dist/src/completion-gates.js +55 -9
- package/dist/src/completion.d.ts +51 -1
- package/dist/src/completion.js +164 -5
- package/dist/src/config.d.ts +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -0
- package/dist/src/decision/PreparedSteps.js +1 -1
- package/dist/src/delegation-changes.js +19 -2
- package/dist/src/diff-preview.d.ts +1 -0
- package/dist/src/diff-preview.js +12 -3
- package/dist/src/engine-streams.d.ts +22 -0
- package/dist/src/engine-streams.js +16 -0
- package/dist/src/extensions.js +17 -6
- package/dist/src/file-read-key.d.ts +8 -0
- package/dist/src/file-read-key.js +12 -0
- package/dist/src/graph-editor-session.js +2 -1
- package/dist/src/graph-health.d.ts +21 -0
- package/dist/src/graph-health.js +46 -0
- package/dist/src/graph-manager-chat.d.ts +52 -3
- package/dist/src/graph-manager-chat.js +62 -17
- package/dist/src/graph-runner.js +62 -5
- package/dist/src/graph-server.d.ts +1 -1
- package/dist/src/graph-server.js +48 -27
- 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 +362 -123
- package/dist/src/graph-ui/controls.css +95 -22
- package/dist/src/graph-ui/controls.js +31 -1
- package/dist/src/graph-ui/embed.js +62 -13
- package/dist/src/graph-ui/icons.js +7 -0
- package/dist/src/graph-ui/index.html +4 -4
- package/dist/src/graph-ui/manager-state.js +143 -5
- package/dist/src/graph-ui/manager.css +21 -20
- package/dist/src/graph-ui/manager.js +337 -75
- package/dist/src/graph-ui/model-picker.js +279 -0
- package/dist/src/graph-ui/provider-glyphs/alibaba-cloud.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/anthropic.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/aws-bedrock.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/claude.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/deepseek.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/fireworks.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/kimi.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/minimax.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/opencode.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/openrouter.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xai.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/xiaomi-mimo.png +0 -0
- package/dist/src/graph-ui/provider-glyphs/zai.png +0 -0
- package/dist/src/graph-ui/skill-picker.js +1 -1
- package/dist/src/graph-ui/studio-canvas.js +8 -8
- package/dist/src/graph-ui/studio.css +18 -15
- package/dist/src/graph-ui/studio.js +92 -35
- package/dist/src/graph-ui/style.css +122 -79
- package/dist/src/graph-ui/theme.js +2 -2
- package/dist/src/graph-ui/tokens.css +33 -29
- package/dist/src/graphs.d.ts +5 -2
- package/dist/src/graphs.js +10 -9
- package/dist/src/mcp.d.ts +52 -14
- package/dist/src/mcp.js +285 -128
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- package/dist/src/memory/ProjectMemory.d.ts +77 -0
- package/dist/src/memory/ProjectMemory.js +310 -0
- package/dist/src/memory/index.d.ts +1 -0
- package/dist/src/memory/index.js +1 -0
- package/dist/src/opencode-provider.js +5 -6
- package/dist/src/package-name.d.ts +3 -0
- package/dist/src/package-name.js +3 -0
- package/dist/src/provider-engine.js +2 -2
- package/dist/src/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/qa/runtime/PtyManager.js +2 -1
- package/dist/src/react-runtime.js +137 -22
- 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/cert.d.ts +1 -1
- package/dist/src/remote/cert.js +2 -7
- package/dist/src/remote/client.js +1 -1
- package/dist/src/remote/pem.d.ts +6 -0
- package/dist/src/remote/pem.js +11 -0
- package/dist/src/run-records.js +49 -10
- package/dist/src/runtime.d.ts +21 -0
- package/dist/src/runtime.js +10 -1
- package/dist/src/session-changes.d.ts +6 -1
- package/dist/src/session-changes.js +13 -5
- package/dist/src/sessions.d.ts +3 -1
- package/dist/src/sessions.js +5 -3
- package/dist/src/side-panel.d.ts +6 -1
- package/dist/src/side-panel.js +12 -10
- package/dist/src/sign-in-detection.d.ts +82 -0
- package/dist/src/sign-in-detection.js +197 -0
- package/dist/src/sign-in-offer.d.ts +35 -0
- package/dist/src/sign-in-offer.js +116 -0
- 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 +59 -7
- 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.d.ts +6 -0
- package/dist/src/skills/runtime-skills.js +16 -3
- package/dist/src/stall-recovery.d.ts +6 -2
- package/dist/src/stall-recovery.js +7 -2
- package/dist/src/stray-files.d.ts +14 -0
- package/dist/src/stray-files.js +81 -0
- package/dist/src/subagent-run.js +6 -1
- package/dist/src/terminal-ui.d.ts +1 -1
- package/dist/src/terminal-ui.js +11 -5
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- package/dist/src/tool-activity.js +1 -1
- package/dist/src/tool-schema-compatibility.d.ts +7 -2
- package/dist/src/tool-schema-compatibility.js +8 -4
- package/dist/src/tools.js +92 -7
- package/dist/src/transcript.d.ts +5 -0
- package/dist/src/transcript.js +12 -4
- package/dist/src/types.d.ts +8 -0
- package/dist/src/untracked-file-removal.d.ts +3 -0
- package/dist/src/untracked-file-removal.js +125 -0
- package/dist/src/update-check.js +1 -1
- package/dist/src/update.d.ts +11 -1
- package/dist/src/update.js +27 -5
- package/dist/src/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- package/dist/src/workspace-git-metadata.d.ts +15 -0
- package/dist/src/workspace-git-metadata.js +50 -1
- package/dist/src/workspace-instructions.js +1 -1
- package/package.json +6 -26
- 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
|
@@ -8,7 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
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';
|
|
@@ -16,6 +16,7 @@ import { testProviderConnection } from './provider-connection.js';
|
|
|
16
16
|
import { CodexAccountAuth } from './codex-browser-auth.js';
|
|
17
17
|
import { AnthropicConsoleAuth, droppedAnthropicAccounts } from './anthropic-console-auth.js';
|
|
18
18
|
import { claudeSignIn, grokSignIn, OpenCodeSignIn } from './managed-sign-in.js';
|
|
19
|
+
import { applySignInImports, detectSignIns, isDetectableSignInType } from './sign-in-detection.js';
|
|
19
20
|
import { OPENCODE_BASE_URL, sharedOpenCodeServer } from './opencode-cli-provider.js';
|
|
20
21
|
import { GROK_BASE_URL } from './grok-provider.js';
|
|
21
22
|
import { anthropicAccountHome } from './anthropic-credentials.js';
|
|
@@ -40,11 +41,11 @@ import { writePendingAgentInteraction, removePendingAgentInteraction } from './s
|
|
|
40
41
|
import { summarizeSessionPrompt, titleRequestSupported } from './session-summary.js';
|
|
41
42
|
import { createTools } from './tools.js';
|
|
42
43
|
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';
|
|
44
|
+
import { confirmAutoFixWake, isFinishedPullRequest, markAutoFixDelivered, withoutPendingFix, newPullRequest, parsePullRequestUrl, PullRequestCreateDetector, pullRequestNeedsWatch, pullRequestSettings, PullRequestWatcher, readPullRequest, removePullRequest, runGh, applyPullRequestSettingsAsReadableAccount, noAccountMessage, readPullRequestAsAnyAccount, withPullRequest, writePullRequest } from './pull-requests.js';
|
|
44
45
|
import { AutomationStore } from './automations.js';
|
|
45
46
|
import { executeAutomation } from './automation-runner.js';
|
|
46
47
|
import { automationService, automationServiceRunning, reconcileAutomationService } from './automation-service.js';
|
|
47
|
-
import { runGraph, stopReasonPhrase, timerReminderText } from './runtime.js';
|
|
48
|
+
import { runGraph, stopReasonPhrase, timerReminderText, wakeMessageText } from './runtime.js';
|
|
48
49
|
import { configuredSurface, createRunHandle, drainTelemetry, graphShape, reportInterruptedRuns, reportRunFinished, reportRunStarted, reportSessionStarted } from './telemetry/surface.js';
|
|
49
50
|
import { telemetryGate } from './telemetry/gate.js';
|
|
50
51
|
import { analyticsGenerationFor, resolveAnalyticsConfig } from './analytics.js';
|
|
@@ -71,6 +72,7 @@ import { BackgroundTasks } from './background-tasks.js';
|
|
|
71
72
|
import { disposePooledPowerShell } from './powershell-pool.js';
|
|
72
73
|
import { TodoStore } from './todos.js';
|
|
73
74
|
import { LocalToolMemory } from './memory/LocalToolMemory.js';
|
|
75
|
+
import { ProjectMemory } from './memory/ProjectMemory.js';
|
|
74
76
|
import { CodeIntelligenceManager } from './code-intelligence/CodeIntelligenceManager.js';
|
|
75
77
|
import { startGraphServer } from './graph-server.js';
|
|
76
78
|
import { createSessionTrajectory } from './trajectory.js';
|
|
@@ -78,7 +80,7 @@ import { readUsageAnalytics } from './usage-analytics.js';
|
|
|
78
80
|
import { TerminalFlow, TerminalManager } from './app-server/terminal.js';
|
|
79
81
|
import { BrowserViewManager, browserViewUrl } from './browser-view.js';
|
|
80
82
|
import { listFirefoxProfiles, readFirefoxCookies } from './firefox-cookies.js';
|
|
81
|
-
import { createBrowserIncognitoTool, createBrowserPanelTool, runPanelOperation, validatePanelArguments } from './browser-panel-tool.js';
|
|
83
|
+
import { createBrowserIncognitoTool, createBrowserPanelTool, createPanelBrowserHold, runPanelOperation, validatePanelArguments } from './browser-panel-tool.js';
|
|
82
84
|
import { resolveCapsolverKey } from './capsolver.js';
|
|
83
85
|
import { resolveWebSearchProvider } from './web-search.js';
|
|
84
86
|
import { checkoutBranch, gitDiff, gitStatus, listBranches, listExtensions, listRuns, readRun, readSessionTrajectory, runRecordFile, sessionTrajectoryFile, readTree, readWorkspaceFile, summarizeMcpServer, workspaceRoot } from './app-server/workspace.js';
|
|
@@ -164,7 +166,7 @@ const RELAY_LONG_DEADLINE_MS = 1_260_000;
|
|
|
164
166
|
*/
|
|
165
167
|
const MAX_RESUME_LINEAGE = 32;
|
|
166
168
|
/** Fields a client may change through `config.set`. Anything else is rejected rather than merged. */
|
|
167
|
-
const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser', 'webSearch'];
|
|
169
|
+
const EDITABLE_CONFIG_KEYS = ['provider', 'providers', 'graph', 'graphSelections', 'jevEnabled', 'decisions', 'commandMemory', 'projectMemory', 'limits', 'workspacePermissions', 'mcpServers', 'extensions', 'memory', 'codeIntel', 'externalSubagent', 'analytics', 'systemPromptOverride', 'autoArchiveDays', 'browser', 'webSearch'];
|
|
168
170
|
function message(error) { return error instanceof Error ? error.message : String(error); }
|
|
169
171
|
/** Project an owned authentication result instead of forwarding any official CLI payload wholesale. */
|
|
170
172
|
function providerAuthView(view, includeUrl) {
|
|
@@ -489,6 +491,8 @@ function configView(config, analytics) {
|
|
|
489
491
|
...(config.jevEnabled === undefined ? {} : { jevEnabled: config.jevEnabled }),
|
|
490
492
|
...(config.decisions === undefined ? {} : { decisions: structuredClone(config.decisions) }),
|
|
491
493
|
...(config.commandMemory === undefined ? {} : { commandMemory: config.commandMemory }),
|
|
494
|
+
...(config.codeIntel === undefined ? {} : { codeIntel: structuredClone(config.codeIntel) }),
|
|
495
|
+
...(config.projectMemory === undefined ? {} : { projectMemory: config.projectMemory }),
|
|
492
496
|
...(config.analytics === undefined && analytics === undefined ? {} : { analytics: { ...config.analytics, ...(analytics === undefined ? {} : { plan: analytics.plan, canOptOut: analytics.canOptOut }) } }),
|
|
493
497
|
...(config.limits === undefined ? {} : { limits: { ...config.limits } }),
|
|
494
498
|
...(config.workspacePermissions === undefined ? {} : { workspacePermissions: config.workspacePermissions }),
|
|
@@ -806,6 +810,8 @@ function wakeProvenance(wake, node) {
|
|
|
806
810
|
return {};
|
|
807
811
|
return { wake, ...(typeof node === 'string' && node ? { node } : {}) };
|
|
808
812
|
}
|
|
813
|
+
/** A review wait reads the shared PR record every this many seconds, for what another engine saved there. */
|
|
814
|
+
const REVIEW_WAIT_RECORD_TICKS = 5;
|
|
809
815
|
export function isFinalWakeRefusal(error) {
|
|
810
816
|
return error instanceof AppServerError
|
|
811
817
|
&& (error.code === 'invalid-params' || error.code === 'not-found' || error.code === 'remote'
|
|
@@ -921,6 +927,9 @@ export class AppServer {
|
|
|
921
927
|
claudeSignIn;
|
|
922
928
|
grokSignIn;
|
|
923
929
|
openCodeSignIn;
|
|
930
|
+
signInProbes;
|
|
931
|
+
/** The last detection of each tool: an import names a type and a model, and is checked against this. */
|
|
932
|
+
detectedSignIns = new Map();
|
|
924
933
|
/** Retires a removed provider's slot home; a seam so a test never has to spawn the Codex CLI. */
|
|
925
934
|
retireCodexAccount;
|
|
926
935
|
/** The `gh` the pull request settings and watcher run through. */
|
|
@@ -931,6 +940,14 @@ export class AppServer {
|
|
|
931
940
|
sessionChanges;
|
|
932
941
|
/** The wakes this engine armed for Auto-fix, checked against the PR record again before delivery. */
|
|
933
942
|
autoFixWakes = new Set();
|
|
943
|
+
/**
|
|
944
|
+
* A run of the session waiting inside the `pull_request` tool's `await_review` for its PR's next review, by
|
|
945
|
+
* session: the review comments the watcher finds go to it instead of to a wake, and it hears when the PR is
|
|
946
|
+
* merged, closed, dismissed or has Auto-fix switched off.
|
|
947
|
+
*/
|
|
948
|
+
reviewWaiters = new Map();
|
|
949
|
+
/** Sessions whose review wait is reserved and still being prepared (`awaitReview`). */
|
|
950
|
+
reviewWaitsStarting = new Set();
|
|
934
951
|
/**
|
|
935
952
|
* The account's graph sync, so a graph saved on another machine is listed here too. A first pass that
|
|
936
953
|
* outlasts the listing's bounded wait publishes `graphs.changed`: that listing already answered from
|
|
@@ -1105,12 +1122,13 @@ export class AppServer {
|
|
|
1105
1122
|
this.claudeSignIn = options.managedSignIn?.claude ?? claudeSignIn();
|
|
1106
1123
|
this.grokSignIn = options.managedSignIn?.grok ?? grokSignIn();
|
|
1107
1124
|
this.openCodeSignIn = options.managedSignIn?.opencode ?? new OpenCodeSignIn();
|
|
1125
|
+
this.signInProbes = options.signInProbes;
|
|
1108
1126
|
this.retireCodexAccount = options.removeCodexAccount ?? removeCodexAccount;
|
|
1109
1127
|
this.gh = options.gh ?? runGh;
|
|
1110
1128
|
this.pullRequestWatcher = new PullRequestWatcher({
|
|
1111
1129
|
home: this.directory, gh: this.gh, intervalMs: options.pullRequestPollMs,
|
|
1112
1130
|
onUpdated: (sessionId, pullRequest) => this.emitPullRequest(sessionId, pullRequest),
|
|
1113
|
-
wake: (sessionId, prompt, carry) => this.wakeForPullRequest(sessionId, prompt, carry),
|
|
1131
|
+
wake: (sessionId, prompt, carry, origin) => this.wakeForPullRequest(sessionId, prompt, carry, origin),
|
|
1114
1132
|
wakePending: id => this.timers.list().some(timer => timer.id === id),
|
|
1115
1133
|
log: (level, detail) => this.log(level, detail),
|
|
1116
1134
|
});
|
|
@@ -1375,6 +1393,8 @@ export class AppServer {
|
|
|
1375
1393
|
case 'providers.update': return this.updateProviders(params);
|
|
1376
1394
|
case 'providers.discover': return this.discoverModels(params);
|
|
1377
1395
|
case 'providers.test': return this.testProviderEndpoint(params);
|
|
1396
|
+
case 'providers.detectSignIns': return this.detectProviderSignIns(params);
|
|
1397
|
+
case 'providers.importSignIns': return this.importProviderSignIns(params);
|
|
1378
1398
|
case 'providers.auth.status': return this.providerAuth('status', params);
|
|
1379
1399
|
case 'providers.auth.start': return this.providerAuth('start', params);
|
|
1380
1400
|
case 'providers.auth.cancel': return this.providerAuth('cancel', params);
|
|
@@ -1447,7 +1467,10 @@ export class AppServer {
|
|
|
1447
1467
|
case 'timers.list': return this.listTimers();
|
|
1448
1468
|
case 'run.start': return this.startRun(params);
|
|
1449
1469
|
case 'workspace.warm': return this.warmWorkspace(params);
|
|
1450
|
-
|
|
1470
|
+
// A person pressing Resume is asking for the work to continue, and the attempt they resume most
|
|
1471
|
+
// often stopped because it spent its budget; restoring that spent budget would stop the new run
|
|
1472
|
+
// before it took a turn, so a run that ran out of time could never be resumed at all.
|
|
1473
|
+
case 'run.resume': return this.resumeRun(params, { freshAllowance: true });
|
|
1451
1474
|
case 'run.cancel': return this.cancelRun(params.runId);
|
|
1452
1475
|
case 'run.setModel': return this.setRunModel(params);
|
|
1453
1476
|
case 'run.setPermissions': return this.setRunPermissions(params);
|
|
@@ -2389,6 +2412,66 @@ export class AppServer {
|
|
|
2389
2412
|
throw new AppServerError('network', message(error));
|
|
2390
2413
|
}
|
|
2391
2414
|
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Which vendor CLIs on this machine are signed in and have no provider yet.
|
|
2417
|
+
*
|
|
2418
|
+
* Local-client only, like the sign-ins themselves: these logins belong to this machine. Only display
|
|
2419
|
+
* fields and model ids are answered; a probe that fails says nothing rather than surfacing CLI output.
|
|
2420
|
+
*/
|
|
2421
|
+
async detectProviderSignIns(params) {
|
|
2422
|
+
const skip = params.skip;
|
|
2423
|
+
if (Object.keys(params).some(key => key !== 'skip') || (skip !== undefined && (!Array.isArray(skip) || skip.length > 8 || skip.some(type => !isDetectableSignInType(type))))) {
|
|
2424
|
+
throw new AppServerError('invalid-params', 'Sign-in detection accepts only skip, a list of claude, codex, grok or opencode.');
|
|
2425
|
+
}
|
|
2426
|
+
const config = await loadConfig(this.directory);
|
|
2427
|
+
const { signIns } = await this.operation(60_000, signal => detectSignIns(config, signal, {
|
|
2428
|
+
...(skip === undefined ? {} : { skip: skip }), ...(this.signInProbes ? { probes: this.signInProbes } : {}),
|
|
2429
|
+
}));
|
|
2430
|
+
for (const found of signIns)
|
|
2431
|
+
this.detectedSignIns.set(found.type, found);
|
|
2432
|
+
return { signIns };
|
|
2433
|
+
}
|
|
2434
|
+
/** Add the chosen detected sign-ins as providers; each must name a tool and model the last detection reported. */
|
|
2435
|
+
async importProviderSignIns(params) {
|
|
2436
|
+
const list = params.imports;
|
|
2437
|
+
const refuse = () => { throw new AppServerError('invalid-params', 'Those accounts are no longer available to add. Look for signed-in accounts again, then choose from that list.'); };
|
|
2438
|
+
if (Object.keys(params).some(key => key !== 'imports') || !Array.isArray(list) || !list.length || list.length > 4)
|
|
2439
|
+
refuse();
|
|
2440
|
+
const imports = [];
|
|
2441
|
+
const detected = [];
|
|
2442
|
+
for (const value of list) {
|
|
2443
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
2444
|
+
refuse();
|
|
2445
|
+
const item = value;
|
|
2446
|
+
if (Object.keys(item).some(key => key !== 'type' && key !== 'model') || !isDetectableSignInType(item.type) || typeof item.model !== 'string')
|
|
2447
|
+
refuse();
|
|
2448
|
+
const type = item.type;
|
|
2449
|
+
const found = this.detectedSignIns.get(type);
|
|
2450
|
+
if (!found || !found.models.includes(item.model) || imports.some(entry => entry.type === type))
|
|
2451
|
+
refuse();
|
|
2452
|
+
imports.push({ type, model: item.model });
|
|
2453
|
+
detected.push(found);
|
|
2454
|
+
}
|
|
2455
|
+
let added = [];
|
|
2456
|
+
const saved = await this.serializeConfig(async () => {
|
|
2457
|
+
try {
|
|
2458
|
+
return await changeConfigFile(this.directory, current => {
|
|
2459
|
+
const applied = applySignInImports(current, detected, imports);
|
|
2460
|
+
added = applied.added;
|
|
2461
|
+
return applied.config;
|
|
2462
|
+
});
|
|
2463
|
+
}
|
|
2464
|
+
catch (error) {
|
|
2465
|
+
throw error instanceof ConfigConflictError ? new AppServerError('busy', message(error)) : new AppServerError('invalid-params', message(error));
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
for (const entry of imports)
|
|
2469
|
+
this.detectedSignIns.delete(entry.type);
|
|
2470
|
+
const view = await this.analyticsConfigView(saved);
|
|
2471
|
+
if (added.length)
|
|
2472
|
+
this.emit('config.changed', { config: view });
|
|
2473
|
+
return { config: view, added };
|
|
2474
|
+
}
|
|
2392
2475
|
/** Local-client only. The remote engine relay deliberately does not admit these methods. */
|
|
2393
2476
|
async providerAuth(action, params) {
|
|
2394
2477
|
if (params.providerType === 'claude' || params.providerType === 'grok' || params.providerType === 'opencode')
|
|
@@ -2726,7 +2809,7 @@ export class AppServer {
|
|
|
2726
2809
|
return value;
|
|
2727
2810
|
}
|
|
2728
2811
|
catch {
|
|
2729
|
-
throw new AppServerError('not-found', 'That
|
|
2812
|
+
throw new AppServerError('not-found', 'That task no longer exists');
|
|
2730
2813
|
}
|
|
2731
2814
|
}
|
|
2732
2815
|
/**
|
|
@@ -2769,7 +2852,7 @@ export class AppServer {
|
|
|
2769
2852
|
}
|
|
2770
2853
|
catch (error) {
|
|
2771
2854
|
if (error instanceof SessionMutationLockHeldError)
|
|
2772
|
-
throw new AppServerError('busy', 'That
|
|
2855
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
2773
2856
|
throw error;
|
|
2774
2857
|
}
|
|
2775
2858
|
try {
|
|
@@ -2797,7 +2880,7 @@ export class AppServer {
|
|
|
2797
2880
|
// already read. `this.starting` is exactly that window (it is set synchronously by every start),
|
|
2798
2881
|
// and `this.startingSession` names the session a resumed run is being prepared for.
|
|
2799
2882
|
if (this.startingSession === id || this.starting)
|
|
2800
|
-
throw new AppServerError('busy', 'That
|
|
2883
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to begin, then rename it.');
|
|
2801
2884
|
// A run in flight no longer holds the name shut: the finalizer builds its save from the record
|
|
2802
2885
|
// captured at startup, but `saveFinalizedSession` re-reads under the shared per-session mutation
|
|
2803
2886
|
// lock and keeps the user-editable fields from disk, so a rename accepted now survives the run.
|
|
@@ -2813,7 +2896,7 @@ export class AppServer {
|
|
|
2813
2896
|
// the lock on purpose: a second window's mutation may have landed while this one queued, and
|
|
2814
2897
|
// building the new record from a pre-lock snapshot would drop it.
|
|
2815
2898
|
if (await sessionHasOpenRun(this.directory, id, ownRunId === undefined ? {} : { ignoreRunId: ownRunId }))
|
|
2816
|
-
throw new AppServerError('busy', 'That
|
|
2899
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then rename it.');
|
|
2817
2900
|
const record = await this.readSession(id);
|
|
2818
2901
|
// `renamed` pins the name: the automatic titling that names a session from its first prompt reads
|
|
2819
2902
|
// it and leaves a name the user chose alone, so the rename is not a temporary state.
|
|
@@ -2833,12 +2916,12 @@ export class AppServer {
|
|
|
2833
2916
|
async compactSession(params) {
|
|
2834
2917
|
const id = identifier(params.id, 'id');
|
|
2835
2918
|
if (this.startingSession === id || this.starting)
|
|
2836
|
-
throw new AppServerError('busy', 'That
|
|
2919
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to finish, then compact it.');
|
|
2837
2920
|
if (this.run?.sessionId === id || this.finishingSessionId === id)
|
|
2838
|
-
throw new AppServerError('busy', 'That
|
|
2921
|
+
throw new AppServerError('busy', 'That task is running. Stop the run or wait for it to finish, then compact it.');
|
|
2839
2922
|
return this.withSessionMutation(id, async () => {
|
|
2840
2923
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2841
|
-
throw new AppServerError('busy', 'That
|
|
2924
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then compact it.');
|
|
2842
2925
|
const record = await this.readSession(id);
|
|
2843
2926
|
// An in-flight marker is a claim recovery reads, never something to summarize away.
|
|
2844
2927
|
const turns = (record.contextHistory ?? record.history ?? []).filter(turn => turn.completion?.status !== 'running');
|
|
@@ -2914,12 +2997,12 @@ export class AppServer {
|
|
|
2914
2997
|
throw new AppServerError('invalid-params', 'archived must be a boolean');
|
|
2915
2998
|
const archived = params.archived;
|
|
2916
2999
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2917
|
-
throw new AppServerError('busy', 'That
|
|
3000
|
+
throw new AppServerError('busy', 'That task is running. Stop the run or wait for it to finish, then archive it.');
|
|
2918
3001
|
return this.withSessionMutation(id, async () => {
|
|
2919
3002
|
// Cross-process guard, same reasoning as the rename above: an archive accepted while another
|
|
2920
3003
|
// engine owns the session's run is silently reverted when that run saves its captured record.
|
|
2921
3004
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2922
|
-
throw new AppServerError('busy', 'That
|
|
3005
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run or wait for it to finish, then archive it.');
|
|
2923
3006
|
// Fresh inside the lock: reading before another window's queued mutation ran would build the
|
|
2924
3007
|
// new record from a snapshot that never saw it, and the save would drop the other change.
|
|
2925
3008
|
const record = await this.readSession(id);
|
|
@@ -2937,12 +3020,12 @@ export class AppServer {
|
|
|
2937
3020
|
// The preparation window counts as running: a delete accepted there would be undone by the
|
|
2938
3021
|
// resumed run saving the record it read — recreating the session the user removed.
|
|
2939
3022
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2940
|
-
throw new AppServerError('busy', 'That
|
|
3023
|
+
throw new AppServerError('busy', 'That task is running. Stop the run before deleting it.');
|
|
2941
3024
|
return this.withSessionMutation(id, async () => {
|
|
2942
3025
|
// Same cross-process reasoning as rename and archive: the other engine's finalize would save the
|
|
2943
3026
|
// record it captured and recreate the session the user just deleted.
|
|
2944
3027
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2945
|
-
throw new AppServerError('busy', 'That
|
|
3028
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run before deleting it.');
|
|
2946
3029
|
// The record goes first. Dropping the wakes before the snapshot is removed would discard pending work on a
|
|
2947
3030
|
// delete that then fails: the session stays on the rail, its row keeps drawing a clock, and the prompts
|
|
2948
3031
|
// behind it can never fire. Nothing this call owns is given up until the removal really happened — and a
|
|
@@ -3354,7 +3437,7 @@ export class AppServer {
|
|
|
3354
3437
|
}
|
|
3355
3438
|
catch (error) {
|
|
3356
3439
|
if (error instanceof SessionMutationLockHeldError)
|
|
3357
|
-
throw new AppServerError('busy', 'That
|
|
3440
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
3358
3441
|
throw error;
|
|
3359
3442
|
}
|
|
3360
3443
|
}
|
|
@@ -3745,10 +3828,10 @@ export class AppServer {
|
|
|
3745
3828
|
}
|
|
3746
3829
|
}
|
|
3747
3830
|
lineage = [...chain];
|
|
3748
|
-
// A timer continuation
|
|
3749
|
-
//
|
|
3750
|
-
//
|
|
3751
|
-
//
|
|
3831
|
+
// A Resume (or a timer continuation, the agent coming back on its own deadline) usually continues an
|
|
3832
|
+
// attempt that stopped because it ran out of budget. Restored as-is, a spent allowance would end the
|
|
3833
|
+
// node before it took a turn, so the resume would be refused or stop at once. It gets a fresh
|
|
3834
|
+
// allowance instead: every restored conversation keeps all its messages
|
|
3752
3835
|
// and the completed work stays completed (nothing is replayed), but the counters it spent are cleared
|
|
3753
3836
|
// and the lineage's tool spend no longer counts against the new run.
|
|
3754
3837
|
if (internal?.freshAllowance === true) {
|
|
@@ -4052,9 +4135,9 @@ export class AppServer {
|
|
|
4052
4135
|
// identity-less (legacy) entry falls back to the complete-message rule.
|
|
4053
4136
|
if (entry.id !== undefined && (!Array.isArray(checkpoint.steeringDelivered) || !checkpoint.steeringDelivered.includes(entry.id)))
|
|
4054
4137
|
return false;
|
|
4055
|
-
// A
|
|
4056
|
-
// conversation that received it carries.
|
|
4057
|
-
return carriesText(asUserMessages(messages), entry.wake
|
|
4138
|
+
// A wake's direction reached the node in its marked wording (the agent's own reminder, or the comments
|
|
4139
|
+
// Auto-fix brought), so that is the text a conversation that received it carries.
|
|
4140
|
+
return carriesText(asUserMessages(messages), wakeMessageText(entry.wake, entry.direction));
|
|
4058
4141
|
};
|
|
4059
4142
|
const checkpointProves = (checkpoint, entry) => {
|
|
4060
4143
|
const parallel = graph.nodes[checkpoint.nodeId]?.modifiers?.parallel;
|
|
@@ -4154,6 +4237,13 @@ export class AppServer {
|
|
|
4154
4237
|
if (![...reachable].some(nodeId => graph.nodes[nodeId]?.type === 'agent')) {
|
|
4155
4238
|
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.');
|
|
4156
4239
|
}
|
|
4240
|
+
// A wake's direction is addressed to one node (the one that set the timer, or switched Auto-fix on), and
|
|
4241
|
+
// only that node reads it. When the edited graph no longer has it as an agent the resumed frontier can
|
|
4242
|
+
// reach, every other reader skips the message, so the continuation would settle the wake unread.
|
|
4243
|
+
const addressed = internal?.wake !== undefined ? internal.wakeNode : undefined;
|
|
4244
|
+
if (addressed !== undefined && (graph.nodes[addressed]?.type !== 'agent' || !reachable.has(addressed))) {
|
|
4245
|
+
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.');
|
|
4246
|
+
}
|
|
4157
4247
|
}
|
|
4158
4248
|
armedCarried = (internal?.carried ?? []).filter(entry => !reenteredCheckpoints.some(checkpoint => checkpointProves(checkpoint, entry)));
|
|
4159
4249
|
}
|
|
@@ -4232,9 +4322,10 @@ export class AppServer {
|
|
|
4232
4322
|
// mark goes with the text it describes: the task of a fresh start, or the direction of a continuation - a
|
|
4233
4323
|
// continuation whose direction was proven delivered by an earlier attempt opens with no text to mark.
|
|
4234
4324
|
const wake = internal?.wake !== undefined && (internal.resumedFrom === undefined || resumedDirection !== undefined) ? internal.wake : undefined;
|
|
4235
|
-
// The node a
|
|
4236
|
-
// resume that recovers the direction still knows
|
|
4237
|
-
|
|
4325
|
+
// The node a wake's continuation direction belongs to (the node that set a timer, or the one that switched
|
|
4326
|
+
// Auto-fix on): read only by that node, and recorded so a later resume that recovers the direction still knows
|
|
4327
|
+
// whose it is.
|
|
4328
|
+
const directionNode = wake !== undefined && resumedDirection !== undefined ? internal?.wakeNode : undefined;
|
|
4238
4329
|
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 }) };
|
|
4239
4330
|
// The marker lands in both arrays, exactly as the CLI's persistence path writes it: `history` is
|
|
4240
4331
|
// the transcript a client reads, and `contextHistory` is the model context a later run seeds
|
|
@@ -4370,7 +4461,7 @@ export class AppServer {
|
|
|
4370
4461
|
{
|
|
4371
4462
|
const continues = new Set([runId, ...lineage]);
|
|
4372
4463
|
for (const timer of this.timers.list(record.id)) {
|
|
4373
|
-
if (timer
|
|
4464
|
+
if (!this.nodeReminder(timer) || continues.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
4374
4465
|
continue;
|
|
4375
4466
|
this.spendWake(timer, 'a newer turn in this session replaced the attempt that set it');
|
|
4376
4467
|
}
|
|
@@ -4396,7 +4487,7 @@ export class AppServer {
|
|
|
4396
4487
|
// one as such would rewrite the session's skill and undo a pause or removal made since the stop.
|
|
4397
4488
|
const invocationText = internal?.resumedFrom === undefined ? task
|
|
4398
4489
|
: internal.recoveredDirection === true || internal.wake !== undefined ? undefined : internal.direction;
|
|
4399
|
-
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 }) })
|
|
4490
|
+
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 }) })
|
|
4400
4491
|
.catch(error => this.log('error', `Run ${runId} failed: ${message(error)}`));
|
|
4401
4492
|
// The finally sits outside the awaited chain so the settle can name the exact promise this
|
|
4402
4493
|
// attempt owns: the finalizer now releases the live-run slot before the terminal events, so a
|
|
@@ -4518,8 +4609,10 @@ export class AppServer {
|
|
|
4518
4609
|
this.sessionTitles.clear();
|
|
4519
4610
|
}
|
|
4520
4611
|
async executeRun(input) {
|
|
4521
|
-
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;
|
|
4612
|
+
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;
|
|
4522
4613
|
const signal = controller.signal;
|
|
4614
|
+
// Keeps a panel browser the agent drove open while this attempt lives; stopped in the finally below.
|
|
4615
|
+
const panelHold = createPanelBrowserHold(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined);
|
|
4523
4616
|
const liveRun = this.run?.runId === runId ? this.run : undefined;
|
|
4524
4617
|
if (liveRun)
|
|
4525
4618
|
liveRun.graphSelection = selection;
|
|
@@ -4637,15 +4730,16 @@ export class AppServer {
|
|
|
4637
4730
|
for (const entry of carriedDirections ?? []) {
|
|
4638
4731
|
const refs = entry.attachments ?? [];
|
|
4639
4732
|
const images = refs.length ? await loadResolvedImages(this.directory, root, refs) : [];
|
|
4640
|
-
const said = entry.wake
|
|
4641
|
-
arm(entry.wake ===
|
|
4733
|
+
const said = wakeMessageText(entry.wake, entry.direction);
|
|
4734
|
+
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 });
|
|
4642
4735
|
}
|
|
4643
4736
|
if (direction !== undefined) {
|
|
4644
4737
|
const refs = attachments?.refs ?? [];
|
|
4645
4738
|
const images = attachments?.images ?? [];
|
|
4646
|
-
// A continuation a
|
|
4647
|
-
|
|
4648
|
-
|
|
4739
|
+
// A continuation a wake delivered opens with the agent's own reminder (or Auto-fix's comments), read as one
|
|
4740
|
+
// rather than as the user's words, by the node the wake is addressed to.
|
|
4741
|
+
const said = wakeMessageText(wake, direction);
|
|
4742
|
+
arm(wake === undefined ? undefined : directionNode, { ...(ownDirectionId === undefined ? {} : { id: ownDirectionId }), content: refs.length ? `${said}\n\n${attachmentReferenceBlock(refs, { imagesIncluded: images.length > 0 })}` : said, images });
|
|
4649
4743
|
}
|
|
4650
4744
|
const steering = armed.length === 0 ? undefined : armed;
|
|
4651
4745
|
// The messages the user typed into the live attempt, in the order the runtime read them. Each
|
|
@@ -4662,6 +4756,7 @@ export class AppServer {
|
|
|
4662
4756
|
};
|
|
4663
4757
|
let mcp;
|
|
4664
4758
|
let commandMemory;
|
|
4759
|
+
let projectMemory;
|
|
4665
4760
|
let result;
|
|
4666
4761
|
let failure;
|
|
4667
4762
|
let runConfig;
|
|
@@ -4961,6 +5056,8 @@ export class AppServer {
|
|
|
4961
5056
|
bootMark('run.exec.extensions.loaded');
|
|
4962
5057
|
if (config.commandMemory !== false)
|
|
4963
5058
|
commandMemory = await LocalToolMemory.open({ directory: this.directory, workspace: root });
|
|
5059
|
+
if (config.projectMemory !== false)
|
|
5060
|
+
projectMemory = await ProjectMemory.open({ home: this.directory, workspace: root });
|
|
4964
5061
|
// The run's own spooled attachments plus every replayed history turn's, readable under any
|
|
4965
5062
|
// permission mode: the user attached them, and the reference blocks the model reads name
|
|
4966
5063
|
// those very files — a follow-up with no new attachment still tells the model to read them.
|
|
@@ -5020,8 +5117,9 @@ export class AppServer {
|
|
|
5020
5117
|
timers: this.timers, sessionScope: input.record.id, wakesArmed, automationDirectory: this.directory,
|
|
5021
5118
|
wakeCarry,
|
|
5022
5119
|
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
|
-
|
|
5120
|
+
// Every write the run makes to a workspace file is kept for review under the session it belongs to,
|
|
5121
|
+
// unless the run has Full Access when the write lands: that mode asks nothing, a Keep included.
|
|
5122
|
+
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'),
|
|
5025
5123
|
};
|
|
5026
5124
|
bootMark('run.exec.mcp.connect.start');
|
|
5027
5125
|
// The health verdict is watched while the servers connect, not after: a server can wait on the
|
|
@@ -5078,11 +5176,11 @@ export class AppServer {
|
|
|
5078
5176
|
// desktop relay to the engine that does. It is keyed to the saved session id both the pane
|
|
5079
5177
|
// and this run's browser events already use, so agent-driven tabs are the pane's tabs. The
|
|
5080
5178
|
// CLI builds its toolset without an app-server and never sees it.
|
|
5081
|
-
tools: [...createTools(), createBrowserPanelTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined),
|
|
5082
|
-
createBrowserIncognitoTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined), ...extension.tools, ...(mcp?.tools ?? [])], installedSkillClaims: extension.claimsSkillName, history: contextSeed,
|
|
5179
|
+
tools: [...createTools(), createBrowserPanelTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined, panelHold),
|
|
5180
|
+
createBrowserIncognitoTool(this.browserViews, input.record.id, panelBrowserRelay ? this.panelBrowserRelayFor(input.record.id) : undefined, panelHold), ...extension.tools, ...(mcp?.tools ?? [])], installedSkillClaims: extension.claimsSkillName, history: contextSeed,
|
|
5083
5181
|
...(runSkill.skill ? { inheritedSkills: [runSkill.skill.id], skillInvocationInstruction: runSkill.skill.instruction } : {}),
|
|
5084
5182
|
instructions: `${await loadWorkspaceInstructions(root, signal, config.systemPromptOverride)}${extension.instructions}`,
|
|
5085
|
-
codeIntel, todoStore: new TodoStore(), ...(commandMemory ? { commandMemory } : {}),
|
|
5183
|
+
codeIntel, todoStore: new TodoStore(), ...(commandMemory ? { commandMemory } : {}), ...(projectMemory ? { projectMemory } : {}),
|
|
5086
5184
|
limits: resolveConfiguredLimits(config),
|
|
5087
5185
|
...hostedDecisionPolicy(membership, config.jevEnabled !== false, config.decisions),
|
|
5088
5186
|
...(config.efficiency ? { efficiency: config.efficiency } : {}),
|
|
@@ -5090,6 +5188,7 @@ export class AppServer {
|
|
|
5090
5188
|
// choices; adaptive routing leaves them alone.
|
|
5091
5189
|
modelPinned: modelPinned || overrideAllNodes,
|
|
5092
5190
|
...(entryHistory ? { entryHistory: true } : {}),
|
|
5191
|
+
...(startNode === undefined ? {} : { startNode }),
|
|
5093
5192
|
configuredModels: config.providers.map(item => ({ id: item.id, model: item.model, ...(item.models ? { models: [...item.models] } : {}) })),
|
|
5094
5193
|
// The executor resolves its own model rather than reusing `adapter`, so the task's effort is
|
|
5095
5194
|
// handed to it as well — for the run's own provider and model only: a node that pins another
|
|
@@ -5201,8 +5300,9 @@ export class AppServer {
|
|
|
5201
5300
|
}
|
|
5202
5301
|
// A `gh pr create` the agent ran puts the PR it opened on the session's Plan card.
|
|
5203
5302
|
const created = pullRequestDetector.observe(event);
|
|
5303
|
+
const attachingNode = typeof event.data?.nodeId === 'string' && event.data.nodeId ? event.data.nodeId : undefined;
|
|
5204
5304
|
if (created)
|
|
5205
|
-
void this.attachPullRequest(input.record.id, created, {}, wakeCarry).catch(error => this.log('warn', `Could not attach ${created.url}: ${message(error)}`));
|
|
5305
|
+
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)}`));
|
|
5206
5306
|
},
|
|
5207
5307
|
onUsage: (delta, origin) => {
|
|
5208
5308
|
foldUsage(runUsage, delta);
|
|
@@ -5278,6 +5378,7 @@ export class AppServer {
|
|
|
5278
5378
|
failure = error;
|
|
5279
5379
|
}
|
|
5280
5380
|
finally {
|
|
5381
|
+
panelHold.stop();
|
|
5281
5382
|
// A setup step that failed leaves the model preflight in flight; a run that reached the graph
|
|
5282
5383
|
// settled it long ago, and this is then a no-op.
|
|
5283
5384
|
healthAbort.abort();
|
|
@@ -7398,6 +7499,138 @@ export class AppServer {
|
|
|
7398
7499
|
/** Say what a session is waiting on. An empty list is a real answer: it is what ends a wait. */
|
|
7399
7500
|
emitPullRequest(sessionId, pullRequest) {
|
|
7400
7501
|
this.emit('session.pullRequest.updated', { sessionId, pullRequest: pullRequestForClients(pullRequest) });
|
|
7502
|
+
// Every change to the record passes here, so a run waiting on its review hears the ones that end the wait.
|
|
7503
|
+
const waiter = this.reviewWaiters.get(sessionId);
|
|
7504
|
+
if (!waiter)
|
|
7505
|
+
return;
|
|
7506
|
+
if (pullRequest === null)
|
|
7507
|
+
waiter({ kind: 'none' });
|
|
7508
|
+
else if (isFinishedPullRequest(pullRequest.state))
|
|
7509
|
+
waiter({ kind: 'finished', pullRequest });
|
|
7510
|
+
else if (!pullRequest.autoFix)
|
|
7511
|
+
waiter({ kind: 'off', pullRequest });
|
|
7512
|
+
}
|
|
7513
|
+
/**
|
|
7514
|
+
* Hold the calling run until its PR's next review: the comments the watcher finds are handed to it as the Auto-fix
|
|
7515
|
+
* prompt would be, instead of being armed as a wake. A wake already armed for comments it has not delivered is
|
|
7516
|
+
* taken at once. `origin` (the waiting node) becomes the node later Auto-fix wakes go to, since it owns the loop.
|
|
7517
|
+
*/
|
|
7518
|
+
async awaitReview(sessionId, signal, timeoutMs, origin) {
|
|
7519
|
+
if (signal.aborted)
|
|
7520
|
+
return { kind: 'aborted' };
|
|
7521
|
+
// The session's one wait is reserved before anything yields: two branches calling at once must not both pass
|
|
7522
|
+
// this check and have the second waiter replace the first.
|
|
7523
|
+
if (this.reviewWaiters.has(sessionId) || this.reviewWaitsStarting.has(sessionId))
|
|
7524
|
+
throw new Error('Another call in this session is already waiting for this pull request review.');
|
|
7525
|
+
this.reviewWaitsStarting.add(sessionId);
|
|
7526
|
+
try {
|
|
7527
|
+
if (origin !== undefined) {
|
|
7528
|
+
await withPullRequest(this.directory, sessionId, async () => {
|
|
7529
|
+
const current = await readPullRequest(this.directory, sessionId);
|
|
7530
|
+
if (!current || (current.origin?.runId === origin.runId && current.origin.nodeId === origin.nodeId))
|
|
7531
|
+
return;
|
|
7532
|
+
await writePullRequest(this.directory, sessionId, { ...current, origin: { runId: origin.runId, nodeId: origin.nodeId }, updatedAt: new Date().toISOString() });
|
|
7533
|
+
});
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
finally {
|
|
7537
|
+
this.reviewWaitsStarting.delete(sessionId);
|
|
7538
|
+
}
|
|
7539
|
+
// Nothing yields between the reservation's release above and the waiter's install below.
|
|
7540
|
+
return await new Promise(resolve => {
|
|
7541
|
+
let settled = false;
|
|
7542
|
+
const finish = (ended) => {
|
|
7543
|
+
if (settled)
|
|
7544
|
+
return false;
|
|
7545
|
+
settled = true;
|
|
7546
|
+
clearTimeout(timeout);
|
|
7547
|
+
clearInterval(ticks);
|
|
7548
|
+
signal.removeEventListener('abort', aborted);
|
|
7549
|
+
if (this.reviewWaiters.get(sessionId) === finish)
|
|
7550
|
+
this.reviewWaiters.delete(sessionId);
|
|
7551
|
+
resolve(ended);
|
|
7552
|
+
return true;
|
|
7553
|
+
};
|
|
7554
|
+
const aborted = () => { finish({ kind: 'aborted' }); };
|
|
7555
|
+
const timeout = setTimeout(() => finish({ kind: 'timeout' }), timeoutMs);
|
|
7556
|
+
// The record is the shared answer: comments another engine's watcher found (it holds the watcher's lease, so
|
|
7557
|
+
// this engine's poll finds nothing), and a merge, close or switch-off saved by any engine.
|
|
7558
|
+
const fromRecord = () => {
|
|
7559
|
+
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)}`));
|
|
7560
|
+
};
|
|
7561
|
+
// A message the user types into the run is read only at the next turn boundary, which a wait never reaches:
|
|
7562
|
+
// the wait ends so the agent can read it. Wakes queued as steers are the run's own reminders, not the user.
|
|
7563
|
+
let tick = 0;
|
|
7564
|
+
const ticks = setInterval(() => {
|
|
7565
|
+
const live = this.run;
|
|
7566
|
+
if (live?.sessionId === sessionId && live.steers.some(entry => entry.wake === undefined))
|
|
7567
|
+
finish({ kind: 'steered' });
|
|
7568
|
+
else if (++tick % REVIEW_WAIT_RECORD_TICKS === 0)
|
|
7569
|
+
fromRecord();
|
|
7570
|
+
}, 1_000);
|
|
7571
|
+
timeout.unref?.();
|
|
7572
|
+
ticks.unref?.();
|
|
7573
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
7574
|
+
// Stopped while the origin was being saved: a listener added to an aborted signal never fires.
|
|
7575
|
+
if (signal.aborted) {
|
|
7576
|
+
finish({ kind: 'aborted' });
|
|
7577
|
+
return;
|
|
7578
|
+
}
|
|
7579
|
+
this.reviewWaiters.set(sessionId, finish);
|
|
7580
|
+
fromRecord();
|
|
7581
|
+
// Look now rather than at the next tick: comments may already be waiting.
|
|
7582
|
+
void this.pullRequestWatcher.poll();
|
|
7583
|
+
});
|
|
7584
|
+
}
|
|
7585
|
+
/**
|
|
7586
|
+
* What the session's PR record says a review wait should end with, handed to `deliver`: the PR is gone, finished or
|
|
7587
|
+
* has Auto-fix off, or it holds comments found and not yet carried by a run. Those are taken under the lock, handed
|
|
7588
|
+
* over first and only then marked handled, so a wait that ended meanwhile never loses them. A wake this engine is
|
|
7589
|
+
* delivering now is left to that delivery.
|
|
7590
|
+
*/
|
|
7591
|
+
async reviewWaitFromRecord(sessionId, deliver) {
|
|
7592
|
+
const taken = await withPullRequest(this.directory, sessionId, async () => {
|
|
7593
|
+
const current = await readPullRequest(this.directory, sessionId);
|
|
7594
|
+
if (!current) {
|
|
7595
|
+
deliver({ kind: 'none' });
|
|
7596
|
+
return undefined;
|
|
7597
|
+
}
|
|
7598
|
+
if (isFinishedPullRequest(current.state)) {
|
|
7599
|
+
deliver({ kind: 'finished', pullRequest: current });
|
|
7600
|
+
return undefined;
|
|
7601
|
+
}
|
|
7602
|
+
if (!current.autoFix) {
|
|
7603
|
+
deliver({ kind: 'off', pullRequest: current });
|
|
7604
|
+
return undefined;
|
|
7605
|
+
}
|
|
7606
|
+
const pending = current.pendingFix;
|
|
7607
|
+
if (pending === undefined || this.timers.isHeld(pending.wakeId))
|
|
7608
|
+
return undefined;
|
|
7609
|
+
const prompt = pending.prompt ?? this.timers.get(pending.wakeId)?.prompt;
|
|
7610
|
+
if (prompt === undefined || !deliver({ kind: 'comments', prompt }))
|
|
7611
|
+
return undefined;
|
|
7612
|
+
// A wake this engine armed for them is now answered. One another engine armed is dropped there at delivery,
|
|
7613
|
+
// which finds the record no longer asking for it (`confirmAutoFixWake`).
|
|
7614
|
+
if (this.autoFixWakes.has(pending.wakeId))
|
|
7615
|
+
this.cancelAutoFixWake(sessionId, pending.wakeId);
|
|
7616
|
+
const { pendingFix: _pending, ...rest } = current;
|
|
7617
|
+
const next = { ...rest, handledThrough: pending.through, updatedAt: new Date().toISOString() };
|
|
7618
|
+
await writePullRequest(this.directory, sessionId, next);
|
|
7619
|
+
return next;
|
|
7620
|
+
});
|
|
7621
|
+
if (taken)
|
|
7622
|
+
this.emitPullRequest(sessionId, taken);
|
|
7623
|
+
}
|
|
7624
|
+
/** A run now carries the Auto-fix prompt behind `wakeId`: its comments are handled. */
|
|
7625
|
+
async recordAutoFixDelivered(sessionId, wakeId) {
|
|
7626
|
+
try {
|
|
7627
|
+
const pullRequest = await markAutoFixDelivered(this.directory, sessionId, wakeId);
|
|
7628
|
+
if (pullRequest)
|
|
7629
|
+
this.emitPullRequest(sessionId, pullRequest);
|
|
7630
|
+
}
|
|
7631
|
+
catch (error) {
|
|
7632
|
+
this.log('warn', `Could not record the Auto-fix delivery for session ${sessionId}: ${message(error)}`);
|
|
7633
|
+
}
|
|
7401
7634
|
}
|
|
7402
7635
|
/** The pending set as a change left it, without diffs: a client reads those with `sessions.changes.list`. */
|
|
7403
7636
|
emitSessionChanges(changes) {
|
|
@@ -7407,7 +7640,7 @@ export class AppServer {
|
|
|
7407
7640
|
* Start tracking `ref` for the session. A PR already tracked under the same URL keeps its settings, so a
|
|
7408
7641
|
* repeated `gh pr create` (which reports the existing PR) never switches off what the user turned on.
|
|
7409
7642
|
*/
|
|
7410
|
-
async attachPullRequest(sessionId, ref, settings = {}, carry) {
|
|
7643
|
+
async attachPullRequest(sessionId, ref, settings = {}, carry, origin) {
|
|
7411
7644
|
const attached = await withPullRequest(this.directory, sessionId, async () => {
|
|
7412
7645
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7413
7646
|
let next = current?.url === ref.url ? current : newPullRequest(ref);
|
|
@@ -7427,6 +7660,9 @@ export class AppServer {
|
|
|
7427
7660
|
// The run that attached it names the graph, model and effort an Auto-fix run continues under.
|
|
7428
7661
|
if (carry !== undefined)
|
|
7429
7662
|
next = { ...next, carry: structuredClone(carry) };
|
|
7663
|
+
// The node Auto-fix wakes: the one that switches it on, or the one that attached the PR when none has yet.
|
|
7664
|
+
if (origin !== undefined && (settings.autoFix === true || next.origin === undefined))
|
|
7665
|
+
next = { ...next, origin: { runId: origin.runId, nodeId: origin.nodeId } };
|
|
7430
7666
|
if (Object.keys(settings).length)
|
|
7431
7667
|
next = await applyPullRequestSettingsAsReadableAccount(this.gh, next, settings);
|
|
7432
7668
|
await writePullRequest(this.directory, sessionId, next);
|
|
@@ -7437,7 +7673,7 @@ export class AppServer {
|
|
|
7437
7673
|
void this.pullRequestWatcher.poll();
|
|
7438
7674
|
return attached;
|
|
7439
7675
|
}
|
|
7440
|
-
async updatePullRequest(sessionId, settings, carry) {
|
|
7676
|
+
async updatePullRequest(sessionId, settings, carry, origin) {
|
|
7441
7677
|
const updated = await withPullRequest(this.directory, sessionId, async () => {
|
|
7442
7678
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7443
7679
|
if (!current)
|
|
@@ -7451,6 +7687,9 @@ export class AppServer {
|
|
|
7451
7687
|
}
|
|
7452
7688
|
if (carry !== undefined)
|
|
7453
7689
|
next = { ...next, carry: structuredClone(carry) };
|
|
7690
|
+
// The node that switches Auto-fix on is the one its prompts go back to.
|
|
7691
|
+
if (origin !== undefined && settings.autoFix === true)
|
|
7692
|
+
next = { ...next, origin: { runId: origin.runId, nodeId: origin.nodeId } };
|
|
7454
7693
|
// Auto-fix switched off: a wake it already armed is no longer the user's wish.
|
|
7455
7694
|
if (!next.autoFix && next.pendingFix) {
|
|
7456
7695
|
this.cancelAutoFixWake(sessionId, next.pendingFix.wakeId);
|
|
@@ -7488,23 +7727,34 @@ export class AppServer {
|
|
|
7488
7727
|
pullRequestControl(sessionId, carry) {
|
|
7489
7728
|
return {
|
|
7490
7729
|
status: () => readPullRequest(this.directory, sessionId),
|
|
7491
|
-
attach: (url, settings) => {
|
|
7730
|
+
attach: (url, settings, origin) => {
|
|
7492
7731
|
const ref = parsePullRequestUrl(url);
|
|
7493
7732
|
if (!ref)
|
|
7494
7733
|
throw new Error('url must be a GitHub pull request URL, https://github.com/<owner>/<repo>/pull/<number>');
|
|
7495
|
-
return this.attachPullRequest(sessionId, ref, settings, carry);
|
|
7734
|
+
return this.attachPullRequest(sessionId, ref, settings, carry, origin);
|
|
7496
7735
|
},
|
|
7497
|
-
update: settings => this.updatePullRequest(sessionId, settings, carry),
|
|
7736
|
+
update: (settings, origin) => this.updatePullRequest(sessionId, settings, carry, origin),
|
|
7737
|
+
awaitReview: (signal, timeoutMs, origin) => this.awaitReview(sessionId, signal, timeoutMs, origin),
|
|
7498
7738
|
dismiss: () => this.dismissPullRequest(sessionId),
|
|
7499
7739
|
};
|
|
7500
7740
|
}
|
|
7501
7741
|
/**
|
|
7502
7742
|
* Hand an Auto-fix prompt to the session through the same wake a `set_timer` arms, under the selections the
|
|
7503
7743
|
* session's PR was configured from: without them the continuation would run under whatever graph and model
|
|
7504
|
-
* the configuration names today, with different tools than the work it is fixing.
|
|
7744
|
+
* the configuration names today, with different tools than the work it is fixing. `origin` addresses the prompt to
|
|
7745
|
+
* the graph node that switched Auto-fix on (`deliverDueTimers`), rather than to the graph's entry node.
|
|
7505
7746
|
*/
|
|
7506
|
-
wakeForPullRequest(sessionId, prompt, carry) {
|
|
7507
|
-
|
|
7747
|
+
wakeForPullRequest(sessionId, prompt, carry, origin) {
|
|
7748
|
+
// A run waiting on this review takes the prompt itself, and no wake is armed. The watcher records the id as the
|
|
7749
|
+
// pending fix under the lock it holds now; the delivery mark queues behind that lock and moves the handled mark.
|
|
7750
|
+
const waiter = this.reviewWaiters.get(sessionId);
|
|
7751
|
+
if (waiter) {
|
|
7752
|
+
const id = `review-${randomUUID()}`;
|
|
7753
|
+
waiter({ kind: 'comments', prompt });
|
|
7754
|
+
void this.recordAutoFixDelivered(sessionId, id);
|
|
7755
|
+
return id;
|
|
7756
|
+
}
|
|
7757
|
+
const timer = this.timers.arm(1, prompt, sessionId, carry, origin);
|
|
7508
7758
|
this.autoFixWakes.add(timer.id);
|
|
7509
7759
|
this.emitTimers(sessionId);
|
|
7510
7760
|
this.armTimerCheck();
|
|
@@ -7585,6 +7835,17 @@ export class AppServer {
|
|
|
7585
7835
|
this.emit('timers.spent', { sessionId, timerId: timer.id, prompt: timer.prompt, reason });
|
|
7586
7836
|
this.emitTimers(sessionId);
|
|
7587
7837
|
}
|
|
7838
|
+
/**
|
|
7839
|
+
* Whether a wake is a `set_timer` reminder a graph node set about the work it was doing. Those belong to that work:
|
|
7840
|
+
* they are read by the node while its attempt runs, and spent once the node or the attempt is done with it.
|
|
7841
|
+
*
|
|
7842
|
+
* An Auto-fix wake also names a node (the one that switched Auto-fix on), but only as its address: review comments
|
|
7843
|
+
* are new work that outlives the attempt that turned Auto-fix on, so they are never spent with it and always wait
|
|
7844
|
+
* for the engine to be free (`deliverDueTimers`).
|
|
7845
|
+
*/
|
|
7846
|
+
nodeReminder(timer) {
|
|
7847
|
+
return timer.origin !== undefined && !this.autoFixWakes.has(timer.id);
|
|
7848
|
+
}
|
|
7588
7849
|
/**
|
|
7589
7850
|
* Spend the session's node-armed wakes that belong to an attempt in `attempts` and satisfy `spent`.
|
|
7590
7851
|
*
|
|
@@ -7593,7 +7854,7 @@ export class AppServer {
|
|
|
7593
7854
|
*/
|
|
7594
7855
|
spendAttemptWakes(sessionId, attempts, reason, spent = () => true) {
|
|
7595
7856
|
for (const timer of this.timers.list(sessionId)) {
|
|
7596
|
-
if (timer
|
|
7857
|
+
if (!this.nodeReminder(timer) || !attempts.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
7597
7858
|
continue;
|
|
7598
7859
|
if (spent(timer.origin))
|
|
7599
7860
|
this.spendWake(timer, reason);
|
|
@@ -7611,7 +7872,7 @@ export class AppServer {
|
|
|
7611
7872
|
return;
|
|
7612
7873
|
const own = new Set([live.runId, ...(live.lineage ?? [])]);
|
|
7613
7874
|
for (;;) {
|
|
7614
|
-
const timer = this.timers.takeDueOne(Date.now(), live.sessionId, candidate => candidate
|
|
7875
|
+
const timer = this.timers.takeDueOne(Date.now(), live.sessionId, candidate => this.nodeReminder(candidate) && own.has(candidate.origin.runId));
|
|
7615
7876
|
if (timer === undefined)
|
|
7616
7877
|
return;
|
|
7617
7878
|
const at = new Date().toISOString();
|
|
@@ -7673,7 +7934,10 @@ export class AppServer {
|
|
|
7673
7934
|
return { wait: 'its attempt is still running in another engine' };
|
|
7674
7935
|
// The node finished after the reminder was set: what it was waiting on is behind it, and continuing the
|
|
7675
7936
|
// attempt from wherever it stopped would hand the reminder to work it was never about.
|
|
7676
|
-
|
|
7937
|
+
// An Auto-fix wake is addressed to a node rather than armed in the middle of its work, so any completion of that
|
|
7938
|
+
// node counts: an attempt that stopped after the node finished would re-enter elsewhere, and the comments,
|
|
7939
|
+
// addressed to a node that never runs again, would go unread. It starts at the node instead.
|
|
7940
|
+
const armedAt = this.autoFixWakes.has(timer.id) ? Number.NEGATIVE_INFINITY : timer.fireAt - timer.seconds * 1_000;
|
|
7677
7941
|
for (const attempt of chain) {
|
|
7678
7942
|
const journal = await readFile(runRecordPath(this.directory, attempt, 'jsonl'), 'utf8').catch(() => '');
|
|
7679
7943
|
for (const line of journal.split('\n')) {
|
|
@@ -7799,7 +8063,13 @@ export class AppServer {
|
|
|
7799
8063
|
// A wake a graph node armed goes back to that node's work: as a continuation of the attempt it armed, from
|
|
7800
8064
|
// that node's checkpoint. One with nothing left to continue is spent, never started as a new task that
|
|
7801
8065
|
// enters the graph at its entry node with the agent's reminder for a prompt.
|
|
8066
|
+
//
|
|
8067
|
+
// An Auto-fix wake goes to the node that switched Auto-fix on, never to the entry node: into that node's
|
|
8068
|
+
// stopped attempt when there is one to continue, and otherwise as a new run of the session that starts at
|
|
8069
|
+
// that node. Review comments are work that is still owed when that attempt is over, so it is never spent.
|
|
8070
|
+
const autoFix = this.autoFixWakes.has(timer.id);
|
|
7802
8071
|
let resume;
|
|
8072
|
+
let startNode;
|
|
7803
8073
|
if (timer.origin !== undefined) {
|
|
7804
8074
|
let plan;
|
|
7805
8075
|
try {
|
|
@@ -7814,13 +8084,18 @@ export class AppServer {
|
|
|
7814
8084
|
this.log('info', `Self-wake ${timer.id} waits: ${plan.wait}`);
|
|
7815
8085
|
continue;
|
|
7816
8086
|
}
|
|
7817
|
-
if ('spent' in plan) {
|
|
8087
|
+
if ('spent' in plan && !autoFix) {
|
|
7818
8088
|
this.spendWake(timer, plan.spent);
|
|
7819
8089
|
continue;
|
|
7820
8090
|
}
|
|
7821
|
-
resume
|
|
8091
|
+
if ('resume' in plan)
|
|
8092
|
+
resume = plan.resume;
|
|
8093
|
+
else
|
|
8094
|
+
startNode = timer.origin.nodeId;
|
|
7822
8095
|
}
|
|
7823
|
-
this.log('info', resume
|
|
8096
|
+
this.log('info', resume !== undefined ? `Delivering self-wake ${timer.id} to session ${sessionId} as a continuation of ${resume}`
|
|
8097
|
+
: startNode !== undefined ? `Delivering self-wake ${timer.id} to session ${sessionId} at node ${startNode}`
|
|
8098
|
+
: `Delivering self-wake ${timer.id} to session ${sessionId}`);
|
|
7824
8099
|
// The row keeps saying the session is waiting until a run is really there to carry the prompt. The list
|
|
7825
8100
|
// is republished after the attempt rather than before it, so there is no moment between the deadline and
|
|
7826
8101
|
// `run.started` in which the session reads as done with the user while its prompt has gone nowhere.
|
|
@@ -7834,13 +8109,25 @@ export class AppServer {
|
|
|
7834
8109
|
// The continuation runs under the attempt's own recorded selections (`resumeRun` reads them from its
|
|
7835
8110
|
// record), with the reminder as the direction the re-entered node reads at its first turn boundary.
|
|
7836
8111
|
// Only the panel relay is this engine's own and not the record's, so it rides along.
|
|
7837
|
-
|
|
7838
|
-
|
|
8112
|
+
try {
|
|
8113
|
+
await this.resumeRun({ runId: resume, direction: timer.prompt,
|
|
8114
|
+
...(carry?.panelBrowserRelay === true ? { panelBrowserRelay: true } : {}) }, { wake: autoFix ? 'auto-fix' : 'timer', wakeNode: timer.origin.nodeId, freshAllowance: true });
|
|
8115
|
+
}
|
|
8116
|
+
catch (error) {
|
|
8117
|
+
// A reminder with nothing to continue is spent below. Review comments are still owed: they start at
|
|
8118
|
+
// the node instead.
|
|
8119
|
+
if (!autoFix || !isFinalWakeRefusal(error))
|
|
8120
|
+
throw error;
|
|
8121
|
+
this.log('info', `Auto-fix wake ${timer.id} starts at node ${timer.origin.nodeId}: ${resume} could not be continued (${message(error)})`);
|
|
8122
|
+
resume = undefined;
|
|
8123
|
+
startNode = timer.origin.nodeId;
|
|
8124
|
+
}
|
|
7839
8125
|
}
|
|
7840
|
-
|
|
7841
|
-
//
|
|
7842
|
-
//
|
|
7843
|
-
//
|
|
8126
|
+
if (resume === undefined) {
|
|
8127
|
+
// An Auto-fix wake with no attempt to continue starts at the node it is addressed to, and a wake no graph
|
|
8128
|
+
// node armed (an Auto-fix wake from a PR no node configured, or one held from before wakes named their
|
|
8129
|
+
// node) starts at the entry the way it always did. It carries the selections of the run that armed it
|
|
8130
|
+
// (see `WakeCarry`): starting it with only the workspace, session and prompt would hand it whatever the
|
|
7844
8131
|
// configuration says today.
|
|
7845
8132
|
await this.startRun({ workspace: record.workspace, sessionId, task: timer.prompt,
|
|
7846
8133
|
...(carry?.graph === undefined ? {} : { graph: carry.graph }),
|
|
@@ -7850,7 +8137,7 @@ export class AppServer {
|
|
|
7850
8137
|
...(carry?.overrideAllNodes === undefined ? {} : { overrideAllNodes: carry.overrideAllNodes }),
|
|
7851
8138
|
...(carry?.panelBrowserRelay === undefined ? {} : { panelBrowserRelay: carry.panelBrowserRelay }),
|
|
7852
8139
|
...(carry?.input === undefined ? {} : { input: carry.input }),
|
|
7853
|
-
...(carry?.state === undefined ? {} : { state: carry.state }) }, { sameSession: sessionId, wake:
|
|
8140
|
+
...(carry?.state === undefined ? {} : { state: carry.state }) }, { sameSession: sessionId, wake: autoFix ? 'auto-fix' : 'timer', ...(startNode === undefined ? {} : { startNode }) });
|
|
7854
8141
|
}
|
|
7855
8142
|
// Given: a run of this session carries the prompt, so the wake is no longer owed and the row stops waiting.
|
|
7856
8143
|
this.timers.settle(timer.id);
|
|
@@ -7975,6 +8262,8 @@ export class AppServer {
|
|
|
7975
8262
|
if (this.automationCheck)
|
|
7976
8263
|
clearInterval(this.automationCheck);
|
|
7977
8264
|
await this.pullRequestWatcher.stop().catch(() => { });
|
|
8265
|
+
for (const waiter of [...this.reviewWaiters.values()])
|
|
8266
|
+
waiter({ kind: 'aborted' });
|
|
7978
8267
|
if (this.autoArchiveCheck)
|
|
7979
8268
|
clearInterval(this.autoArchiveCheck);
|
|
7980
8269
|
this.automationController.abort();
|