@andorra-labs/code 0.1.10 → 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 +36 -0
- package/dist/src/app-server/protocol.d.ts +1 -0
- package/dist/src/app-server.d.ts +34 -1
- package/dist/src/app-server.js +264 -54
- 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 +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/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.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 +8 -0
- package/dist/src/completion.js +19 -1
- package/dist/src/dashboard-view.js +2 -2
- package/dist/src/deadline.js +4 -0
- package/dist/src/graph-manager-chat.js +13 -13
- package/dist/src/graph-runner.js +39 -2
- package/dist/src/graph-server.js +9 -9
- 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 +262 -93
- 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 +62 -13
- package/dist/src/graph-ui/icons.js +4 -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 +11 -11
- 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 +3 -2
- package/dist/src/graphs.js +3 -2
- package/dist/src/membership-errors.d.ts +7 -1
- package/dist/src/membership-errors.js +9 -3
- package/dist/src/pull-requests.d.ts +42 -6
- package/dist/src/pull-requests.js +11 -3
- package/dist/src/react-runtime.js +121 -14
- 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/runtime.d.ts +19 -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/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 +6 -2
- package/dist/src/stall-recovery.js +7 -2
- package/dist/src/terminal-ui.js +2 -2
- package/dist/src/time-limit.d.ts +53 -0
- package/dist/src/time-limit.js +79 -0
- package/dist/src/tools.js +92 -7
- package/dist/src/transcript.js +1 -1
- package/dist/src/types.d.ts +6 -0
- package/dist/src/usage-analytics.d.ts +3 -1
- package/dist/src/usage-analytics.js +16 -2
- 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';
|
|
@@ -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';
|
|
@@ -806,6 +806,8 @@ function wakeProvenance(wake, node) {
|
|
|
806
806
|
return {};
|
|
807
807
|
return { wake, ...(typeof node === 'string' && node ? { node } : {}) };
|
|
808
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;
|
|
809
811
|
export function isFinalWakeRefusal(error) {
|
|
810
812
|
return error instanceof AppServerError
|
|
811
813
|
&& (error.code === 'invalid-params' || error.code === 'not-found' || error.code === 'remote'
|
|
@@ -931,6 +933,14 @@ export class AppServer {
|
|
|
931
933
|
sessionChanges;
|
|
932
934
|
/** The wakes this engine armed for Auto-fix, checked against the PR record again before delivery. */
|
|
933
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();
|
|
934
944
|
/**
|
|
935
945
|
* The account's graph sync, so a graph saved on another machine is listed here too. A first pass that
|
|
936
946
|
* outlasts the listing's bounded wait publishes `graphs.changed`: that listing already answered from
|
|
@@ -1110,7 +1120,7 @@ export class AppServer {
|
|
|
1110
1120
|
this.pullRequestWatcher = new PullRequestWatcher({
|
|
1111
1121
|
home: this.directory, gh: this.gh, intervalMs: options.pullRequestPollMs,
|
|
1112
1122
|
onUpdated: (sessionId, pullRequest) => this.emitPullRequest(sessionId, pullRequest),
|
|
1113
|
-
wake: (sessionId, prompt, carry) => this.wakeForPullRequest(sessionId, prompt, carry),
|
|
1123
|
+
wake: (sessionId, prompt, carry, origin) => this.wakeForPullRequest(sessionId, prompt, carry, origin),
|
|
1114
1124
|
wakePending: id => this.timers.list().some(timer => timer.id === id),
|
|
1115
1125
|
log: (level, detail) => this.log(level, detail),
|
|
1116
1126
|
});
|
|
@@ -2726,7 +2736,7 @@ export class AppServer {
|
|
|
2726
2736
|
return value;
|
|
2727
2737
|
}
|
|
2728
2738
|
catch {
|
|
2729
|
-
throw new AppServerError('not-found', 'That
|
|
2739
|
+
throw new AppServerError('not-found', 'That task no longer exists');
|
|
2730
2740
|
}
|
|
2731
2741
|
}
|
|
2732
2742
|
/**
|
|
@@ -2769,7 +2779,7 @@ export class AppServer {
|
|
|
2769
2779
|
}
|
|
2770
2780
|
catch (error) {
|
|
2771
2781
|
if (error instanceof SessionMutationLockHeldError)
|
|
2772
|
-
throw new AppServerError('busy', 'That
|
|
2782
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
2773
2783
|
throw error;
|
|
2774
2784
|
}
|
|
2775
2785
|
try {
|
|
@@ -2797,7 +2807,7 @@ export class AppServer {
|
|
|
2797
2807
|
// already read. `this.starting` is exactly that window (it is set synchronously by every start),
|
|
2798
2808
|
// and `this.startingSession` names the session a resumed run is being prepared for.
|
|
2799
2809
|
if (this.startingSession === id || this.starting)
|
|
2800
|
-
throw new AppServerError('busy', 'That
|
|
2810
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to begin, then rename it.');
|
|
2801
2811
|
// A run in flight no longer holds the name shut: the finalizer builds its save from the record
|
|
2802
2812
|
// captured at startup, but `saveFinalizedSession` re-reads under the shared per-session mutation
|
|
2803
2813
|
// lock and keeps the user-editable fields from disk, so a rename accepted now survives the run.
|
|
@@ -2813,7 +2823,7 @@ export class AppServer {
|
|
|
2813
2823
|
// the lock on purpose: a second window's mutation may have landed while this one queued, and
|
|
2814
2824
|
// building the new record from a pre-lock snapshot would drop it.
|
|
2815
2825
|
if (await sessionHasOpenRun(this.directory, id, ownRunId === undefined ? {} : { ignoreRunId: ownRunId }))
|
|
2816
|
-
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.');
|
|
2817
2827
|
const record = await this.readSession(id);
|
|
2818
2828
|
// `renamed` pins the name: the automatic titling that names a session from its first prompt reads
|
|
2819
2829
|
// it and leaves a name the user chose alone, so the rename is not a temporary state.
|
|
@@ -2833,12 +2843,12 @@ export class AppServer {
|
|
|
2833
2843
|
async compactSession(params) {
|
|
2834
2844
|
const id = identifier(params.id, 'id');
|
|
2835
2845
|
if (this.startingSession === id || this.starting)
|
|
2836
|
-
throw new AppServerError('busy', 'That
|
|
2846
|
+
throw new AppServerError('busy', 'That task is starting. Wait for it to finish, then compact it.');
|
|
2837
2847
|
if (this.run?.sessionId === id || this.finishingSessionId === id)
|
|
2838
|
-
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.');
|
|
2839
2849
|
return this.withSessionMutation(id, async () => {
|
|
2840
2850
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2841
|
-
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.');
|
|
2842
2852
|
const record = await this.readSession(id);
|
|
2843
2853
|
// An in-flight marker is a claim recovery reads, never something to summarize away.
|
|
2844
2854
|
const turns = (record.contextHistory ?? record.history ?? []).filter(turn => turn.completion?.status !== 'running');
|
|
@@ -2914,12 +2924,12 @@ export class AppServer {
|
|
|
2914
2924
|
throw new AppServerError('invalid-params', 'archived must be a boolean');
|
|
2915
2925
|
const archived = params.archived;
|
|
2916
2926
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2917
|
-
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.');
|
|
2918
2928
|
return this.withSessionMutation(id, async () => {
|
|
2919
2929
|
// Cross-process guard, same reasoning as the rename above: an archive accepted while another
|
|
2920
2930
|
// engine owns the session's run is silently reverted when that run saves its captured record.
|
|
2921
2931
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2922
|
-
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.');
|
|
2923
2933
|
// Fresh inside the lock: reading before another window's queued mutation ran would build the
|
|
2924
2934
|
// new record from a snapshot that never saw it, and the save would drop the other change.
|
|
2925
2935
|
const record = await this.readSession(id);
|
|
@@ -2937,12 +2947,12 @@ export class AppServer {
|
|
|
2937
2947
|
// The preparation window counts as running: a delete accepted there would be undone by the
|
|
2938
2948
|
// resumed run saving the record it read — recreating the session the user removed.
|
|
2939
2949
|
if (this.run?.sessionId === id || this.startingSession === id || this.starting)
|
|
2940
|
-
throw new AppServerError('busy', 'That
|
|
2950
|
+
throw new AppServerError('busy', 'That task is running. Stop the run before deleting it.');
|
|
2941
2951
|
return this.withSessionMutation(id, async () => {
|
|
2942
2952
|
// Same cross-process reasoning as rename and archive: the other engine's finalize would save the
|
|
2943
2953
|
// record it captured and recreate the session the user just deleted.
|
|
2944
2954
|
if (await sessionHasOpenRun(this.directory, id))
|
|
2945
|
-
throw new AppServerError('busy', 'That
|
|
2955
|
+
throw new AppServerError('busy', 'That task is running in another window. Stop the run before deleting it.');
|
|
2946
2956
|
// The record goes first. Dropping the wakes before the snapshot is removed would discard pending work on a
|
|
2947
2957
|
// delete that then fails: the session stays on the rail, its row keeps drawing a clock, and the prompts
|
|
2948
2958
|
// behind it can never fire. Nothing this call owns is given up until the removal really happened — and a
|
|
@@ -3354,7 +3364,7 @@ export class AppServer {
|
|
|
3354
3364
|
}
|
|
3355
3365
|
catch (error) {
|
|
3356
3366
|
if (error instanceof SessionMutationLockHeldError)
|
|
3357
|
-
throw new AppServerError('busy', 'That
|
|
3367
|
+
throw new AppServerError('busy', 'That task is being changed in another window. Wait a moment, then try again.');
|
|
3358
3368
|
throw error;
|
|
3359
3369
|
}
|
|
3360
3370
|
}
|
|
@@ -4052,9 +4062,9 @@ export class AppServer {
|
|
|
4052
4062
|
// identity-less (legacy) entry falls back to the complete-message rule.
|
|
4053
4063
|
if (entry.id !== undefined && (!Array.isArray(checkpoint.steeringDelivered) || !checkpoint.steeringDelivered.includes(entry.id)))
|
|
4054
4064
|
return false;
|
|
4055
|
-
// A
|
|
4056
|
-
// conversation that received it carries.
|
|
4057
|
-
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));
|
|
4058
4068
|
};
|
|
4059
4069
|
const checkpointProves = (checkpoint, entry) => {
|
|
4060
4070
|
const parallel = graph.nodes[checkpoint.nodeId]?.modifiers?.parallel;
|
|
@@ -4154,6 +4164,13 @@ export class AppServer {
|
|
|
4154
4164
|
if (![...reachable].some(nodeId => graph.nodes[nodeId]?.type === 'agent')) {
|
|
4155
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.');
|
|
4156
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
|
+
}
|
|
4157
4174
|
}
|
|
4158
4175
|
armedCarried = (internal?.carried ?? []).filter(entry => !reenteredCheckpoints.some(checkpoint => checkpointProves(checkpoint, entry)));
|
|
4159
4176
|
}
|
|
@@ -4232,9 +4249,10 @@ export class AppServer {
|
|
|
4232
4249
|
// mark goes with the text it describes: the task of a fresh start, or the direction of a continuation - a
|
|
4233
4250
|
// continuation whose direction was proven delivered by an earlier attempt opens with no text to mark.
|
|
4234
4251
|
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
|
-
|
|
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;
|
|
4238
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 }) };
|
|
4239
4257
|
// The marker lands in both arrays, exactly as the CLI's persistence path writes it: `history` is
|
|
4240
4258
|
// the transcript a client reads, and `contextHistory` is the model context a later run seeds
|
|
@@ -4370,7 +4388,7 @@ export class AppServer {
|
|
|
4370
4388
|
{
|
|
4371
4389
|
const continues = new Set([runId, ...lineage]);
|
|
4372
4390
|
for (const timer of this.timers.list(record.id)) {
|
|
4373
|
-
if (timer
|
|
4391
|
+
if (!this.nodeReminder(timer) || continues.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
4374
4392
|
continue;
|
|
4375
4393
|
this.spendWake(timer, 'a newer turn in this session replaced the attempt that set it');
|
|
4376
4394
|
}
|
|
@@ -4396,7 +4414,7 @@ export class AppServer {
|
|
|
4396
4414
|
// one as such would rewrite the session's skill and undo a pause or removal made since the stop.
|
|
4397
4415
|
const invocationText = internal?.resumedFrom === undefined ? task
|
|
4398
4416
|
: 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 }) })
|
|
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 }) })
|
|
4400
4418
|
.catch(error => this.log('error', `Run ${runId} failed: ${message(error)}`));
|
|
4401
4419
|
// The finally sits outside the awaited chain so the settle can name the exact promise this
|
|
4402
4420
|
// attempt owns: the finalizer now releases the live-run slot before the terminal events, so a
|
|
@@ -4518,7 +4536,7 @@ export class AppServer {
|
|
|
4518
4536
|
this.sessionTitles.clear();
|
|
4519
4537
|
}
|
|
4520
4538
|
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;
|
|
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;
|
|
4522
4540
|
const signal = controller.signal;
|
|
4523
4541
|
const liveRun = this.run?.runId === runId ? this.run : undefined;
|
|
4524
4542
|
if (liveRun)
|
|
@@ -4637,15 +4655,16 @@ export class AppServer {
|
|
|
4637
4655
|
for (const entry of carriedDirections ?? []) {
|
|
4638
4656
|
const refs = entry.attachments ?? [];
|
|
4639
4657
|
const images = refs.length ? await loadResolvedImages(this.directory, root, refs) : [];
|
|
4640
|
-
const said = entry.wake
|
|
4641
|
-
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 });
|
|
4642
4660
|
}
|
|
4643
4661
|
if (direction !== undefined) {
|
|
4644
4662
|
const refs = attachments?.refs ?? [];
|
|
4645
4663
|
const images = attachments?.images ?? [];
|
|
4646
|
-
// A continuation a
|
|
4647
|
-
|
|
4648
|
-
|
|
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 });
|
|
4649
4668
|
}
|
|
4650
4669
|
const steering = armed.length === 0 ? undefined : armed;
|
|
4651
4670
|
// The messages the user typed into the live attempt, in the order the runtime read them. Each
|
|
@@ -5020,8 +5039,9 @@ export class AppServer {
|
|
|
5020
5039
|
timers: this.timers, sessionScope: input.record.id, wakesArmed, automationDirectory: this.directory,
|
|
5021
5040
|
wakeCarry,
|
|
5022
5041
|
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
|
-
|
|
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'),
|
|
5025
5045
|
};
|
|
5026
5046
|
bootMark('run.exec.mcp.connect.start');
|
|
5027
5047
|
// The health verdict is watched while the servers connect, not after: a server can wait on the
|
|
@@ -5090,6 +5110,7 @@ export class AppServer {
|
|
|
5090
5110
|
// choices; adaptive routing leaves them alone.
|
|
5091
5111
|
modelPinned: modelPinned || overrideAllNodes,
|
|
5092
5112
|
...(entryHistory ? { entryHistory: true } : {}),
|
|
5113
|
+
...(startNode === undefined ? {} : { startNode }),
|
|
5093
5114
|
configuredModels: config.providers.map(item => ({ id: item.id, model: item.model, ...(item.models ? { models: [...item.models] } : {}) })),
|
|
5094
5115
|
// The executor resolves its own model rather than reusing `adapter`, so the task's effort is
|
|
5095
5116
|
// handed to it as well — for the run's own provider and model only: a node that pins another
|
|
@@ -5201,8 +5222,9 @@ export class AppServer {
|
|
|
5201
5222
|
}
|
|
5202
5223
|
// A `gh pr create` the agent ran puts the PR it opened on the session's Plan card.
|
|
5203
5224
|
const created = pullRequestDetector.observe(event);
|
|
5225
|
+
const attachingNode = typeof event.data?.nodeId === 'string' && event.data.nodeId ? event.data.nodeId : undefined;
|
|
5204
5226
|
if (created)
|
|
5205
|
-
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)}`));
|
|
5206
5228
|
},
|
|
5207
5229
|
onUsage: (delta, origin) => {
|
|
5208
5230
|
foldUsage(runUsage, delta);
|
|
@@ -7398,6 +7420,138 @@ export class AppServer {
|
|
|
7398
7420
|
/** Say what a session is waiting on. An empty list is a real answer: it is what ends a wait. */
|
|
7399
7421
|
emitPullRequest(sessionId, pullRequest) {
|
|
7400
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
|
+
}
|
|
7401
7555
|
}
|
|
7402
7556
|
/** The pending set as a change left it, without diffs: a client reads those with `sessions.changes.list`. */
|
|
7403
7557
|
emitSessionChanges(changes) {
|
|
@@ -7407,7 +7561,7 @@ export class AppServer {
|
|
|
7407
7561
|
* Start tracking `ref` for the session. A PR already tracked under the same URL keeps its settings, so a
|
|
7408
7562
|
* repeated `gh pr create` (which reports the existing PR) never switches off what the user turned on.
|
|
7409
7563
|
*/
|
|
7410
|
-
async attachPullRequest(sessionId, ref, settings = {}, carry) {
|
|
7564
|
+
async attachPullRequest(sessionId, ref, settings = {}, carry, origin) {
|
|
7411
7565
|
const attached = await withPullRequest(this.directory, sessionId, async () => {
|
|
7412
7566
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7413
7567
|
let next = current?.url === ref.url ? current : newPullRequest(ref);
|
|
@@ -7427,6 +7581,9 @@ export class AppServer {
|
|
|
7427
7581
|
// The run that attached it names the graph, model and effort an Auto-fix run continues under.
|
|
7428
7582
|
if (carry !== undefined)
|
|
7429
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 } };
|
|
7430
7587
|
if (Object.keys(settings).length)
|
|
7431
7588
|
next = await applyPullRequestSettingsAsReadableAccount(this.gh, next, settings);
|
|
7432
7589
|
await writePullRequest(this.directory, sessionId, next);
|
|
@@ -7437,7 +7594,7 @@ export class AppServer {
|
|
|
7437
7594
|
void this.pullRequestWatcher.poll();
|
|
7438
7595
|
return attached;
|
|
7439
7596
|
}
|
|
7440
|
-
async updatePullRequest(sessionId, settings, carry) {
|
|
7597
|
+
async updatePullRequest(sessionId, settings, carry, origin) {
|
|
7441
7598
|
const updated = await withPullRequest(this.directory, sessionId, async () => {
|
|
7442
7599
|
const current = await readPullRequest(this.directory, sessionId);
|
|
7443
7600
|
if (!current)
|
|
@@ -7451,6 +7608,9 @@ export class AppServer {
|
|
|
7451
7608
|
}
|
|
7452
7609
|
if (carry !== undefined)
|
|
7453
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 } };
|
|
7454
7614
|
// Auto-fix switched off: a wake it already armed is no longer the user's wish.
|
|
7455
7615
|
if (!next.autoFix && next.pendingFix) {
|
|
7456
7616
|
this.cancelAutoFixWake(sessionId, next.pendingFix.wakeId);
|
|
@@ -7488,23 +7648,34 @@ export class AppServer {
|
|
|
7488
7648
|
pullRequestControl(sessionId, carry) {
|
|
7489
7649
|
return {
|
|
7490
7650
|
status: () => readPullRequest(this.directory, sessionId),
|
|
7491
|
-
attach: (url, settings) => {
|
|
7651
|
+
attach: (url, settings, origin) => {
|
|
7492
7652
|
const ref = parsePullRequestUrl(url);
|
|
7493
7653
|
if (!ref)
|
|
7494
7654
|
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);
|
|
7655
|
+
return this.attachPullRequest(sessionId, ref, settings, carry, origin);
|
|
7496
7656
|
},
|
|
7497
|
-
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),
|
|
7498
7659
|
dismiss: () => this.dismissPullRequest(sessionId),
|
|
7499
7660
|
};
|
|
7500
7661
|
}
|
|
7501
7662
|
/**
|
|
7502
7663
|
* Hand an Auto-fix prompt to the session through the same wake a `set_timer` arms, under the selections the
|
|
7503
7664
|
* 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.
|
|
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.
|
|
7505
7667
|
*/
|
|
7506
|
-
wakeForPullRequest(sessionId, prompt, carry) {
|
|
7507
|
-
|
|
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);
|
|
7508
7679
|
this.autoFixWakes.add(timer.id);
|
|
7509
7680
|
this.emitTimers(sessionId);
|
|
7510
7681
|
this.armTimerCheck();
|
|
@@ -7585,6 +7756,17 @@ export class AppServer {
|
|
|
7585
7756
|
this.emit('timers.spent', { sessionId, timerId: timer.id, prompt: timer.prompt, reason });
|
|
7586
7757
|
this.emitTimers(sessionId);
|
|
7587
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
|
+
}
|
|
7588
7770
|
/**
|
|
7589
7771
|
* Spend the session's node-armed wakes that belong to an attempt in `attempts` and satisfy `spent`.
|
|
7590
7772
|
*
|
|
@@ -7593,7 +7775,7 @@ export class AppServer {
|
|
|
7593
7775
|
*/
|
|
7594
7776
|
spendAttemptWakes(sessionId, attempts, reason, spent = () => true) {
|
|
7595
7777
|
for (const timer of this.timers.list(sessionId)) {
|
|
7596
|
-
if (timer
|
|
7778
|
+
if (!this.nodeReminder(timer) || !attempts.has(timer.origin.runId) || this.timers.isHeld(timer.id))
|
|
7597
7779
|
continue;
|
|
7598
7780
|
if (spent(timer.origin))
|
|
7599
7781
|
this.spendWake(timer, reason);
|
|
@@ -7611,7 +7793,7 @@ export class AppServer {
|
|
|
7611
7793
|
return;
|
|
7612
7794
|
const own = new Set([live.runId, ...(live.lineage ?? [])]);
|
|
7613
7795
|
for (;;) {
|
|
7614
|
-
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));
|
|
7615
7797
|
if (timer === undefined)
|
|
7616
7798
|
return;
|
|
7617
7799
|
const at = new Date().toISOString();
|
|
@@ -7673,7 +7855,10 @@ export class AppServer {
|
|
|
7673
7855
|
return { wait: 'its attempt is still running in another engine' };
|
|
7674
7856
|
// The node finished after the reminder was set: what it was waiting on is behind it, and continuing the
|
|
7675
7857
|
// attempt from wherever it stopped would hand the reminder to work it was never about.
|
|
7676
|
-
|
|
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;
|
|
7677
7862
|
for (const attempt of chain) {
|
|
7678
7863
|
const journal = await readFile(runRecordPath(this.directory, attempt, 'jsonl'), 'utf8').catch(() => '');
|
|
7679
7864
|
for (const line of journal.split('\n')) {
|
|
@@ -7799,7 +7984,13 @@ export class AppServer {
|
|
|
7799
7984
|
// A wake a graph node armed goes back to that node's work: as a continuation of the attempt it armed, from
|
|
7800
7985
|
// that node's checkpoint. One with nothing left to continue is spent, never started as a new task that
|
|
7801
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);
|
|
7802
7992
|
let resume;
|
|
7993
|
+
let startNode;
|
|
7803
7994
|
if (timer.origin !== undefined) {
|
|
7804
7995
|
let plan;
|
|
7805
7996
|
try {
|
|
@@ -7814,13 +8005,18 @@ export class AppServer {
|
|
|
7814
8005
|
this.log('info', `Self-wake ${timer.id} waits: ${plan.wait}`);
|
|
7815
8006
|
continue;
|
|
7816
8007
|
}
|
|
7817
|
-
if ('spent' in plan) {
|
|
8008
|
+
if ('spent' in plan && !autoFix) {
|
|
7818
8009
|
this.spendWake(timer, plan.spent);
|
|
7819
8010
|
continue;
|
|
7820
8011
|
}
|
|
7821
|
-
resume
|
|
8012
|
+
if ('resume' in plan)
|
|
8013
|
+
resume = plan.resume;
|
|
8014
|
+
else
|
|
8015
|
+
startNode = timer.origin.nodeId;
|
|
7822
8016
|
}
|
|
7823
|
-
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}`);
|
|
7824
8020
|
// The row keeps saying the session is waiting until a run is really there to carry the prompt. The list
|
|
7825
8021
|
// is republished after the attempt rather than before it, so there is no moment between the deadline and
|
|
7826
8022
|
// `run.started` in which the session reads as done with the user while its prompt has gone nowhere.
|
|
@@ -7834,13 +8030,25 @@ export class AppServer {
|
|
|
7834
8030
|
// The continuation runs under the attempt's own recorded selections (`resumeRun` reads them from its
|
|
7835
8031
|
// record), with the reminder as the direction the re-entered node reads at its first turn boundary.
|
|
7836
8032
|
// Only the panel relay is this engine's own and not the record's, so it rides along.
|
|
7837
|
-
|
|
7838
|
-
|
|
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
|
+
}
|
|
7839
8046
|
}
|
|
7840
|
-
|
|
7841
|
-
//
|
|
7842
|
-
//
|
|
7843
|
-
//
|
|
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
|
|
7844
8052
|
// configuration says today.
|
|
7845
8053
|
await this.startRun({ workspace: record.workspace, sessionId, task: timer.prompt,
|
|
7846
8054
|
...(carry?.graph === undefined ? {} : { graph: carry.graph }),
|
|
@@ -7850,7 +8058,7 @@ export class AppServer {
|
|
|
7850
8058
|
...(carry?.overrideAllNodes === undefined ? {} : { overrideAllNodes: carry.overrideAllNodes }),
|
|
7851
8059
|
...(carry?.panelBrowserRelay === undefined ? {} : { panelBrowserRelay: carry.panelBrowserRelay }),
|
|
7852
8060
|
...(carry?.input === undefined ? {} : { input: carry.input }),
|
|
7853
|
-
...(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 }) });
|
|
7854
8062
|
}
|
|
7855
8063
|
// Given: a run of this session carries the prompt, so the wake is no longer owed and the row stops waiting.
|
|
7856
8064
|
this.timers.settle(timer.id);
|
|
@@ -7975,6 +8183,8 @@ export class AppServer {
|
|
|
7975
8183
|
if (this.automationCheck)
|
|
7976
8184
|
clearInterval(this.automationCheck);
|
|
7977
8185
|
await this.pullRequestWatcher.stop().catch(() => { });
|
|
8186
|
+
for (const waiter of [...this.reviewWaiters.values()])
|
|
8187
|
+
waiter({ kind: 'aborted' });
|
|
7978
8188
|
if (this.autoArchiveCheck)
|
|
7979
8189
|
clearInterval(this.autoArchiveCheck);
|
|
7980
8190
|
this.automationController.abort();
|