maka-agent 0.2.0-dev.76.20261009 → 0.2.0-dev.78.20261010
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 +1 -1
- package/README.zh-CN.md +3 -3
- package/dist/pi-tui-pickers.js +5 -2
- package/dist/pi-tui-runner.js +211 -33
- package/dist/runtime-host-session-driver.js +91 -13
- package/dist/session-catalog-limits.js +22 -0
- package/dist/session-driver.js +10 -0
- package/dist/tui-copy-catalog.js +15 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/bot-chat-settings.js +3 -0
- package/node_modules/@maka/core/dist/bot-events.js +1 -8
- package/node_modules/@maka/core/dist/local-memory.js +38 -1
- package/node_modules/@maka/core/dist/scheduled-task.js +14 -15
- package/node_modules/@maka/core/dist/session.js +3 -0
- package/node_modules/@maka/core/dist/text-sanitize.js +8 -3
- package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +115 -17
- package/node_modules/@maka/runtime/dist/agent-run.js +11 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +11 -0
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +13 -5
- package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +29 -1
- package/node_modules/@maka/runtime/dist/computer-use-observation-text.js +22 -0
- package/node_modules/@maka/runtime/dist/conversation-copy-agent-output.js +227 -0
- package/node_modules/@maka/runtime/dist/conversation-copy.js +176 -46
- package/node_modules/@maka/runtime/dist/file-stable-write.js +15 -3
- package/node_modules/@maka/runtime/dist/filesystem-worker/resource-resolver.js +3 -1
- package/node_modules/@maka/runtime/dist/model-adapter.js +20 -1
- package/node_modules/@maka/runtime/dist/network/proxy-test.js +28 -1
- package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +13 -2
- package/node_modules/@maka/runtime/dist/owned-child-process.js +209 -0
- package/node_modules/@maka/runtime/dist/owned-process-main.js +183 -0
- package/node_modules/@maka/runtime/dist/pipe-process-driver.js +19 -25
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +216 -8
- package/node_modules/@maka/runtime/dist/sandbox-boundary-tool.js +12 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +156 -17
- package/node_modules/@maka/runtime/dist/shell-exec.js +18 -20
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +2 -1
- package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +279 -8
- package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +209 -37
- package/node_modules/@maka/runtime/dist/tool-availability.js +55 -18
- package/node_modules/@maka/runtime/dist/tool-call-snapshot.js +142 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +27 -84
- package/node_modules/@maka/runtime/dist/workers/{filesystem-worker.js → filesystem-worker.mjs} +12 -1
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +30 -6
- package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
- package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +44 -13
- package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -0
- package/node_modules/@maka/runtime-host/dist/client/wsl-environment.js +4 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +46 -9
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +1 -13
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +4 -7
- package/node_modules/@maka/runtime-host/dist/server/archive-retention-coordinator.js +81 -105
- package/node_modules/@maka/runtime-host/dist/server/candidate.js +47 -40
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +87 -67
- package/node_modules/@maka/runtime-host/dist/server/execution-service.js +5 -1
- package/node_modules/@maka/runtime-host/dist/server/host-maintenance-guards.js +95 -0
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +18 -8
- package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +32 -3
- package/node_modules/@maka/runtime-host/dist/server/project-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +109 -8
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +20 -3
- package/node_modules/@maka/runtime-host/dist/server/session-background-activity.js +71 -0
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +8 -4
- package/node_modules/@maka/runtime-host/dist/server/session-interaction-activity.js +78 -0
- package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +56 -0
- package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +16 -2
- package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +19 -24
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +74 -19
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +6 -99
- package/node_modules/@maka/runtime-host/dist/server/workhub-target-execution-authority.js +14 -126
- package/node_modules/@maka/storage/dist/context-offload-store.js +8 -3
- package/node_modules/@maka/storage/dist/git-entry.js +142 -5
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +54 -19
- package/package.json +2 -2
|
@@ -16,21 +16,12 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
// Runtime's shared shell runner. It streams stdout/stderr into a
|
|
22
|
-
// BashTailBuffer (keeping only the last `maxRetainedChars` per stream) and lets
|
|
23
|
-
// the command run to completion regardless of output size.
|
|
24
|
-
//
|
|
25
|
-
// It is the dumb core: it always RESOLVES with shell facts, rejecting only when
|
|
26
|
-
// the process cannot be spawned at all. Each caller maps those facts to its own
|
|
27
|
-
// contract.
|
|
28
|
-
import { spawn } from 'node:child_process';
|
|
19
|
+
import { spawnOwnedProcess } from './owned-child-process.js';
|
|
29
20
|
import { buildShellSpawnPlan, defaultShellPlan } from './shell-detect.js';
|
|
30
21
|
import { BashTailBuffer } from './bash-tail-buffer.js';
|
|
31
22
|
import { DEFAULT_PROCESS_TERMINATION_GRACE_MS } from './process-tree-terminator.js';
|
|
32
23
|
import { DEFAULT_PROCESS_IO_DRAIN_TIMEOUT_MS, manageChildProcessLifecycle, } from './child-process-lifecycle.js';
|
|
33
|
-
import {
|
|
24
|
+
import { closeChildFdSources, writeChildFdInputs } from './child-fd-input.js';
|
|
34
25
|
// Per-stream cap on the output RETAINED for the result (~1MB). This only bounds
|
|
35
26
|
// what is kept to return. The tool layer preserves this result for durable
|
|
36
27
|
// storage; unified result pruning bounds its model projection.
|
|
@@ -85,18 +76,17 @@ function runSpawnedProcessWithBoundedTail(program, args, useShellOption, options
|
|
|
85
76
|
}
|
|
86
77
|
return new Promise((resolvePromise, reject) => {
|
|
87
78
|
let child;
|
|
79
|
+
let admitted;
|
|
88
80
|
try {
|
|
89
|
-
child =
|
|
81
|
+
({ child, ready: admitted } = spawnOwnedProcess({
|
|
82
|
+
program,
|
|
83
|
+
args,
|
|
90
84
|
cwd: options.cwd,
|
|
91
85
|
env: options.env,
|
|
92
86
|
shell: useShellOption,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
// process-table snapshot.
|
|
97
|
-
// Windows has no process groups; taskkill /T owns the equivalent cleanup.
|
|
98
|
-
detached: process.platform !== 'win32',
|
|
99
|
-
});
|
|
87
|
+
stdin: stdin === undefined ? 'ignore' : 'pipe',
|
|
88
|
+
fdInputs: options.fdInputs,
|
|
89
|
+
}));
|
|
100
90
|
}
|
|
101
91
|
finally {
|
|
102
92
|
closeChildFdSources(options.fdInputs);
|
|
@@ -124,7 +114,15 @@ function runSpawnedProcessWithBoundedTail(program, args, useShellOption, options
|
|
|
124
114
|
ioDrainTimeoutMs,
|
|
125
115
|
});
|
|
126
116
|
void lifecycle.completion.then(resolveOnce, rejectOnce);
|
|
127
|
-
|
|
117
|
+
// The budget is the command's, as with a direct spawn: start it once the
|
|
118
|
+
// supervisor has admitted the command. A supervisor that never admits it
|
|
119
|
+
// fails through its own startup timeout.
|
|
120
|
+
let timer;
|
|
121
|
+
void admitted.then(() => {
|
|
122
|
+
if (settled || termination)
|
|
123
|
+
return;
|
|
124
|
+
timer = setTimeout(() => beginTermination({ timedOut: true }), options.timeoutMs);
|
|
125
|
+
}, () => { });
|
|
128
126
|
const abort = () => beginTermination({ aborted: true });
|
|
129
127
|
if (options.abortSignal) {
|
|
130
128
|
if (options.abortSignal.aborted)
|
|
@@ -777,7 +777,8 @@ export class ShellRunProcessManager {
|
|
|
777
777
|
}
|
|
778
778
|
}
|
|
779
779
|
processPidPatch(live) {
|
|
780
|
-
|
|
780
|
+
// A pipe command runs under an owning supervisor; report the command itself.
|
|
781
|
+
const pid = live.mode === 'pipes' ? live.driver.commandPid : live.driver.pid;
|
|
781
782
|
return pid !== undefined && Number.isSafeInteger(pid) && pid > 0 ? { pid } : {};
|
|
782
783
|
}
|
|
783
784
|
onPipeData(live, stream, data) {
|
|
@@ -21,7 +21,7 @@ import { decodeAgentGraphIntentClaim } from '@maka/core/agent-graph-control';
|
|
|
21
21
|
import { AGENT_GRAPH_OUTPUT_PREVIEW_MAX_CODE_POINTS, readCommittedAgentGraphProjection, } from './stream-graph-projection.js';
|
|
22
22
|
import { hydrateAgentGraphInputHandoffs, renderAgentGraphScheduledWorkPrompt, } from './stream-graph-handoff.js';
|
|
23
23
|
import { buildAgentGraphReadinessSnapshot as buildReadinessSnapshot } from './stream-graph-readiness.js';
|
|
24
|
-
import { reconcileAgentGraphSchedule, } from './stream-graph-schedule-reconcile.js';
|
|
24
|
+
import { reconcileAgentGraphSchedule, scheduledWorkIntentId, } from './stream-graph-schedule-reconcile.js';
|
|
25
25
|
import { AGENT_GRAPH_CLIENT_TERMINAL_PAGE_SIZE, advanceMaterializedAgentGraphClientProjection, buildAgentGraphClientSnapshot, decodeAgentGraphTerminalCursor, decodeMaterializedAgentGraphClientActivity, decodeMaterializedAgentGraphClientSnapshot, decodeMaterializedAgentGraphOperatorInspection, materializeAgentGraphClientProjection, materializedAgentGraphTerminalHistoryPage, } from './stream-graph-read-model.js';
|
|
26
26
|
import { buildAgentGraphSupervisorTools, projectAgentGraphSchedule, } from './stream-graph-supervisor-tools.js';
|
|
27
27
|
import { stableHash } from './request-shape.js';
|
|
@@ -50,6 +50,10 @@ export class AgentGraphCoordinator {
|
|
|
50
50
|
#input;
|
|
51
51
|
#drivers = new Map();
|
|
52
52
|
#clientSubscriptions = new Set();
|
|
53
|
+
#activityEpochs = new Map();
|
|
54
|
+
#currentDrivers = new Map();
|
|
55
|
+
#activityDriversByChildSession = new Map();
|
|
56
|
+
#publishedActivity = new Map();
|
|
53
57
|
#drainTask;
|
|
54
58
|
#closed = false;
|
|
55
59
|
constructor(input) {
|
|
@@ -63,6 +67,181 @@ export class AgentGraphCoordinator {
|
|
|
63
67
|
}
|
|
64
68
|
this.#input = { ...input, maxNewActivations };
|
|
65
69
|
}
|
|
70
|
+
/** Execution activity, distinct from an open graph or a completed supervisor Turn. */
|
|
71
|
+
readSessionActivity(rootSessionId) {
|
|
72
|
+
const driver = this.#currentDrivers.get(rootSessionId);
|
|
73
|
+
if (this.#closed || !driver || driver.closed)
|
|
74
|
+
return 'idle';
|
|
75
|
+
if (driver.stopping)
|
|
76
|
+
return 'running';
|
|
77
|
+
if (driver.paused)
|
|
78
|
+
return driver.stopFailed ? 'blocked' : 'idle';
|
|
79
|
+
const hasLiveWork = Boolean(driver.task || driver.requested || driver.clientProjectionTask);
|
|
80
|
+
// After execution settles, a failed projection cannot establish that its
|
|
81
|
+
// cached running or waiting state is still current.
|
|
82
|
+
if (!hasLiveWork && (driver.lastError !== undefined || driver.clientProjectionDirty))
|
|
83
|
+
return 'blocked';
|
|
84
|
+
if (driver.activityProjection === 'waiting_for_user')
|
|
85
|
+
return 'waiting_for_user';
|
|
86
|
+
return hasLiveWork ? 'running' : driver.activityProjection;
|
|
87
|
+
}
|
|
88
|
+
/** An authoritative child interaction snapshot changed; never schedules graph work. */
|
|
89
|
+
refreshSessionInteractionActivity(childSessionId) {
|
|
90
|
+
const driver = this.#activityDriversByChildSession.get(childSessionId);
|
|
91
|
+
if (this.#closed ||
|
|
92
|
+
!driver ||
|
|
93
|
+
driver.closed ||
|
|
94
|
+
this.#currentDrivers.get(driver.rootSessionId) !== driver)
|
|
95
|
+
return;
|
|
96
|
+
driver.activityProjection = this.#projectActivityFacts(driver);
|
|
97
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
98
|
+
}
|
|
99
|
+
#projectActivityFacts(driver) {
|
|
100
|
+
let unfinishedWork = [...driver.activityRequestedIntentIds].some((intentId) => !driver.activityClaims.has(intentId));
|
|
101
|
+
const requestedTurns = new Map();
|
|
102
|
+
for (const [intentId, claim] of driver.activityClaims) {
|
|
103
|
+
const requested = driver.activityRequestedIntentIds.has(intentId);
|
|
104
|
+
if (!requested && !driver.activityGraphClosed)
|
|
105
|
+
continue;
|
|
106
|
+
let turns = requestedTurns.get(claim.targetOperatorId);
|
|
107
|
+
if (!turns)
|
|
108
|
+
requestedTurns.set(claim.targetOperatorId, (turns = new Set()));
|
|
109
|
+
turns.add(claim.targetTurnId);
|
|
110
|
+
const status = driver.activityTurnStatuses
|
|
111
|
+
.get(claim.targetOperatorId)
|
|
112
|
+
?.get(claim.targetTurnId);
|
|
113
|
+
if (requested && status !== 'completed')
|
|
114
|
+
unfinishedWork = true;
|
|
115
|
+
if (status && ['completed', 'failed', 'aborted', 'cancelled'].includes(status))
|
|
116
|
+
continue;
|
|
117
|
+
// Host interactions can precede any SessionEvent or derived graph projection.
|
|
118
|
+
// The committed claim identifies their owner without implying that a new run started.
|
|
119
|
+
const pending = this.#input.readTurnPendingInteractionCount?.(claim.targetSessionId, claim.targetTurnId);
|
|
120
|
+
if (pending !== undefined && pending > 0)
|
|
121
|
+
return 'waiting_for_user';
|
|
122
|
+
}
|
|
123
|
+
let running = false;
|
|
124
|
+
for (const [operatorId, operator] of driver.activityOperators) {
|
|
125
|
+
let status = operator.status;
|
|
126
|
+
const terminal = ['completed', 'failed', 'aborted', 'cancelled'].includes(status);
|
|
127
|
+
if (operator.turnId && !terminal) {
|
|
128
|
+
// Runtime events omit some settlements, including producer withdrawal.
|
|
129
|
+
const pending = this.#input.readTurnPendingInteractionCount?.(operator.childSessionId, operator.turnId);
|
|
130
|
+
if (pending !== undefined) {
|
|
131
|
+
if (pending > 0)
|
|
132
|
+
status = 'blocked';
|
|
133
|
+
else if (status === 'blocked')
|
|
134
|
+
status = 'running';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Sharing an operator does not make a stopped Turn part of its new work.
|
|
138
|
+
const ownsWork = operator.turnId !== undefined &&
|
|
139
|
+
requestedTurns.get(operatorId)?.has(operator.turnId) === true;
|
|
140
|
+
if (status === 'blocked' && (ownsWork || driver.activityGraphClosed)) {
|
|
141
|
+
return 'waiting_for_user';
|
|
142
|
+
}
|
|
143
|
+
if (status === 'running')
|
|
144
|
+
running = true;
|
|
145
|
+
}
|
|
146
|
+
if (running)
|
|
147
|
+
return 'running';
|
|
148
|
+
if (driver.activityGraphClosed)
|
|
149
|
+
return 'idle';
|
|
150
|
+
return driver.activityHasFailures || unfinishedWork ? 'blocked' : 'idle';
|
|
151
|
+
}
|
|
152
|
+
#observeActivitySchedule(driver, schedule) {
|
|
153
|
+
if (schedule.revision < driver.activityScheduleRevision)
|
|
154
|
+
return;
|
|
155
|
+
driver.activityScheduleRevision = schedule.revision;
|
|
156
|
+
driver.activityRequestedIntentIds = new Set(schedule.work
|
|
157
|
+
.filter((work) => work.status === 'requested')
|
|
158
|
+
.map((work) => scheduledWorkIntentId(driver.graphId, work.workId)));
|
|
159
|
+
driver.activityGraphClosed = schedule.closed;
|
|
160
|
+
}
|
|
161
|
+
#observeActivityClaim(driver, claim) {
|
|
162
|
+
if (driver.closed || this.#closed)
|
|
163
|
+
return;
|
|
164
|
+
driver.activityClaims.set(claim.intentId, {
|
|
165
|
+
targetOperatorId: claim.targetOperatorId,
|
|
166
|
+
targetSessionId: claim.targetSessionId,
|
|
167
|
+
targetTurnId: claim.targetTurnId,
|
|
168
|
+
});
|
|
169
|
+
if (this.#currentDrivers.get(driver.rootSessionId) === driver) {
|
|
170
|
+
this.#activityDriversByChildSession.set(claim.targetSessionId, driver);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
#publishSessionActivity(rootSessionId) {
|
|
174
|
+
const activity = this.readSessionActivity(rootSessionId);
|
|
175
|
+
if ((this.#publishedActivity.get(rootSessionId) ?? 'idle') === activity)
|
|
176
|
+
return;
|
|
177
|
+
if (activity === 'idle')
|
|
178
|
+
this.#publishedActivity.delete(rootSessionId);
|
|
179
|
+
else
|
|
180
|
+
this.#publishedActivity.set(rootSessionId, activity);
|
|
181
|
+
try {
|
|
182
|
+
this.#input.onSessionActivityChanged?.(rootSessionId);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// Presentation observers cannot change graph execution.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
#observeActivityProjection(driver, snapshot, operators, fullInput) {
|
|
189
|
+
if (fullInput) {
|
|
190
|
+
this.#clearActivityOperators(driver);
|
|
191
|
+
this.#observeActivitySchedule(driver, projectAgentGraphSchedule(driver.graphId, fullInput.scheduleUpdates));
|
|
192
|
+
for (const claim of fullInput.observation.claims)
|
|
193
|
+
this.#observeActivityClaim(driver, claim);
|
|
194
|
+
// The full ordered records include every physical handoff run. The latest
|
|
195
|
+
// activation in each logical Turn supplies that work's execution status.
|
|
196
|
+
for (const record of fullInput.observation.projection.records) {
|
|
197
|
+
const status = fullInput.observation.projection.state.operators[record.operatorId]?.activations[record.activationId]?.status;
|
|
198
|
+
if (status === undefined)
|
|
199
|
+
continue;
|
|
200
|
+
let turns = driver.activityTurnStatuses.get(record.operatorId);
|
|
201
|
+
if (!turns)
|
|
202
|
+
driver.activityTurnStatuses.set(record.operatorId, (turns = new Map()));
|
|
203
|
+
turns.set(record.source.turnId, status);
|
|
204
|
+
}
|
|
205
|
+
// An earlier observation cannot erase a claim that onReady has already witnessed.
|
|
206
|
+
for (const claim of driver.activityClaims.values()) {
|
|
207
|
+
if (!driver.closed && this.#currentDrivers.get(driver.rootSessionId) === driver) {
|
|
208
|
+
this.#activityDriversByChildSession.set(claim.targetSessionId, driver);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const operator of operators) {
|
|
213
|
+
driver.activityOperators.set(operator.operatorId, {
|
|
214
|
+
status: operator.status,
|
|
215
|
+
childSessionId: operator.childSessionId,
|
|
216
|
+
turnId: operator.currentActivation?.run.turnId,
|
|
217
|
+
});
|
|
218
|
+
if (!driver.closed && this.#currentDrivers.get(driver.rootSessionId) === driver) {
|
|
219
|
+
this.#activityDriversByChildSession.set(operator.childSessionId, driver);
|
|
220
|
+
}
|
|
221
|
+
if (!fullInput && operator.currentActivation?.run.turnId) {
|
|
222
|
+
let turns = driver.activityTurnStatuses.get(operator.operatorId);
|
|
223
|
+
if (!turns)
|
|
224
|
+
driver.activityTurnStatuses.set(operator.operatorId, (turns = new Map()));
|
|
225
|
+
turns.set(operator.currentActivation.run.turnId, operator.currentActivation.status);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
driver.activityHasFailures = snapshot.reconciliationFailures.length > 0;
|
|
229
|
+
driver.activityProjection = this.#projectActivityFacts(driver);
|
|
230
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
231
|
+
}
|
|
232
|
+
#clearActivityOperators(driver) {
|
|
233
|
+
for (const operator of driver.activityOperators.values()) {
|
|
234
|
+
if (this.#activityDriversByChildSession.get(operator.childSessionId) === driver) {
|
|
235
|
+
this.#activityDriversByChildSession.delete(operator.childSessionId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
for (const claim of driver.activityClaims.values()) {
|
|
239
|
+
if (this.#activityDriversByChildSession.get(claim.targetSessionId) === driver) {
|
|
240
|
+
this.#activityDriversByChildSession.delete(claim.targetSessionId);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
driver.activityOperators.clear();
|
|
244
|
+
}
|
|
66
245
|
/**
|
|
67
246
|
* Return the supervisor-only tools for an ordinary root Session.
|
|
68
247
|
*
|
|
@@ -295,6 +474,8 @@ export class AgentGraphCoordinator {
|
|
|
295
474
|
try {
|
|
296
475
|
driver.lastError = undefined;
|
|
297
476
|
driver.paused = false;
|
|
477
|
+
for (const listener of driver.scheduleChangeListeners)
|
|
478
|
+
listener();
|
|
298
479
|
this.#requestDrive(driver);
|
|
299
480
|
// An epoch handover must not redirect this caller to the next driver.
|
|
300
481
|
while (driver.task)
|
|
@@ -442,8 +623,10 @@ export class AgentGraphCoordinator {
|
|
|
442
623
|
driver.stopGeneration += 1;
|
|
443
624
|
driver.paused = true;
|
|
444
625
|
driver.stopping = true;
|
|
626
|
+
driver.stopFailed = false;
|
|
445
627
|
driver.requested = false;
|
|
446
628
|
driver.abortController?.abort();
|
|
629
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
447
630
|
const failures = [];
|
|
448
631
|
const activeTask = driver.task;
|
|
449
632
|
try {
|
|
@@ -462,6 +645,8 @@ export class AgentGraphCoordinator {
|
|
|
462
645
|
}
|
|
463
646
|
finally {
|
|
464
647
|
driver.stopping = false;
|
|
648
|
+
driver.stopFailed = failures.length > 0;
|
|
649
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
465
650
|
}
|
|
466
651
|
throwCollectedFailures(`Failed to stop agent graph ${driver.graphId}`, failures);
|
|
467
652
|
await this.#repairClientProjectionBestEffort(driver);
|
|
@@ -474,6 +659,7 @@ export class AgentGraphCoordinator {
|
|
|
474
659
|
for (const driver of this.#drivers.values()) {
|
|
475
660
|
driver.closed = true;
|
|
476
661
|
driver.abortController?.abort();
|
|
662
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
477
663
|
}
|
|
478
664
|
this.#drainTask = Promise.allSettled([...this.#drivers.values()].map(async (driver) => {
|
|
479
665
|
const failures = [];
|
|
@@ -505,6 +691,12 @@ export class AgentGraphCoordinator {
|
|
|
505
691
|
this.beginDrain();
|
|
506
692
|
const failures = await (this.#drainTask ?? Promise.resolve([]));
|
|
507
693
|
this.#clientSubscriptions.clear();
|
|
694
|
+
for (const driver of this.#drivers.values()) {
|
|
695
|
+
this.#clearActivityOperators(driver);
|
|
696
|
+
driver.activityRequestedIntentIds.clear();
|
|
697
|
+
driver.activityClaims.clear();
|
|
698
|
+
driver.activityTurnStatuses.clear();
|
|
699
|
+
}
|
|
508
700
|
throwCollectedFailures('Failed to close one or more agent graph coordinators', failures);
|
|
509
701
|
}
|
|
510
702
|
async #drive(driver) {
|
|
@@ -562,6 +754,11 @@ export class AgentGraphCoordinator {
|
|
|
562
754
|
newId: this.#input.newId,
|
|
563
755
|
maxNewActivations: this.#input.maxNewActivations,
|
|
564
756
|
observeGraph: (topology) => this.#observeTopology(topology),
|
|
757
|
+
onScheduleObserved: (schedule) => {
|
|
758
|
+
this.#observeActivitySchedule(driver, schedule);
|
|
759
|
+
driver.activityProjection = this.#projectActivityFacts(driver);
|
|
760
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
761
|
+
},
|
|
565
762
|
resolveSelectedResultInputs: (selected) => this.#resolveSelectedResultInputs(driver.rootSessionId, driver.graphId, selected),
|
|
566
763
|
hydrateInputHandoffs: (records) => hydrateAgentGraphInputHandoffs({
|
|
567
764
|
records,
|
|
@@ -577,6 +774,10 @@ export class AgentGraphCoordinator {
|
|
|
577
774
|
}),
|
|
578
775
|
renderPrompt: this.#input.renderPrompt ?? renderAgentGraphScheduledWorkPrompt,
|
|
579
776
|
abortSignal,
|
|
777
|
+
subscribeToScheduleChanges: (listener) => {
|
|
778
|
+
driver.scheduleChangeListeners.add(listener);
|
|
779
|
+
return () => driver.scheduleChangeListeners.delete(listener);
|
|
780
|
+
},
|
|
580
781
|
supervisor: {
|
|
581
782
|
onObservation: (observation) => {
|
|
582
783
|
this.#queueClientProjectionUpdate(driver, async () => {
|
|
@@ -586,6 +787,11 @@ export class AgentGraphCoordinator {
|
|
|
586
787
|
void notify(this.#input.supervisor?.onObservation, observation);
|
|
587
788
|
},
|
|
588
789
|
onActivationReady: (activation) => {
|
|
790
|
+
// Readiness also observes already-completed claims during reconciliation.
|
|
791
|
+
// The driver owns startup activity; only Runtime projections describe an activation.
|
|
792
|
+
this.#observeActivityClaim(driver, activation.claim);
|
|
793
|
+
driver.activityProjection = this.#projectActivityFacts(driver);
|
|
794
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
589
795
|
const generation = driver.activeDriveGeneration;
|
|
590
796
|
if (generation !== undefined) {
|
|
591
797
|
for (const waiter of driver.yieldWaiters) {
|
|
@@ -622,6 +828,9 @@ export class AgentGraphCoordinator {
|
|
|
622
828
|
void notify(this.#input.supervisor?.onRuntimeEvent, event);
|
|
623
829
|
},
|
|
624
830
|
onReconciliationFailure: (failure) => {
|
|
831
|
+
if (!failure.work && !failure.targetId) {
|
|
832
|
+
void notify(this.#input.onError, driver.rootSessionId, failure.error);
|
|
833
|
+
}
|
|
625
834
|
this.#queueClientProjectionUpdate(driver, async () => {
|
|
626
835
|
await this.#mergeReconciliationFailure(driver, failure);
|
|
627
836
|
await notify(this.#input.onCheckpoint, driver.rootSessionId);
|
|
@@ -675,8 +884,10 @@ export class AgentGraphCoordinator {
|
|
|
675
884
|
return existing;
|
|
676
885
|
}
|
|
677
886
|
const rebuilt = await this.#rebuildClientProjection(rootSessionId, graphId);
|
|
678
|
-
if (driver)
|
|
887
|
+
if (driver) {
|
|
679
888
|
driver.clientProjectionDirty = false;
|
|
889
|
+
this.#publishSessionActivity(rootSessionId);
|
|
890
|
+
}
|
|
680
891
|
return rebuilt;
|
|
681
892
|
}
|
|
682
893
|
async #rebuildClientProjection(rootSessionId, graphId) {
|
|
@@ -737,12 +948,15 @@ export class AgentGraphCoordinator {
|
|
|
737
948
|
const existingFailures = existingReconciliationFailures(existing?.payload);
|
|
738
949
|
const requestedWorkIds = new Set(result.schedule.work.filter((work) => work.status === 'requested').map((work) => work.workId));
|
|
739
950
|
const successfulWorkIds = new Set(result.dispatches.map((dispatch) => dispatch.intent.readinessId));
|
|
951
|
+
const stoppedTargetIds = new Set(result.stops.map((stop) => stop.targetId));
|
|
740
952
|
const failuresByWorkId = new Map(existingFailures
|
|
741
|
-
.filter((failure) =>
|
|
953
|
+
.filter((failure) => failure.phase === 'stop'
|
|
954
|
+
? !stoppedTargetIds.has(failure.workId)
|
|
955
|
+
: requestedWorkIds.has(failure.workId) && !successfulWorkIds.has(failure.workId))
|
|
742
956
|
.map((failure) => [failure.workId, failure]));
|
|
743
957
|
for (const failure of result.failures) {
|
|
744
958
|
const projected = durableReconciliationFailure(failure);
|
|
745
|
-
if (projected && requestedWorkIds.has(projected.workId)) {
|
|
959
|
+
if (projected && (projected.phase === 'stop' || requestedWorkIds.has(projected.workId))) {
|
|
746
960
|
failuresByWorkId.set(projected.workId, projected);
|
|
747
961
|
}
|
|
748
962
|
}
|
|
@@ -775,7 +989,7 @@ export class AgentGraphCoordinator {
|
|
|
775
989
|
throw new AgentGraphClientProjectionConflictError(`Agent graph client projection ${driver.graphId} kept changing while recording failures`);
|
|
776
990
|
}
|
|
777
991
|
async #commitClientProjection(input, materialization, expectedSnapshotVersion) {
|
|
778
|
-
|
|
992
|
+
const committed = await this.#input.controlStore.commitAgentGraphClientProjection({
|
|
779
993
|
schemaVersion: AGENT_GRAPH_CLIENT_PROJECTION_SCHEMA_VERSION,
|
|
780
994
|
graphId: input.graphId,
|
|
781
995
|
rootSessionId: input.rootSessionId,
|
|
@@ -797,6 +1011,11 @@ export class AgentGraphCoordinator {
|
|
|
797
1011
|
eventTime: activity.eventTime,
|
|
798
1012
|
})),
|
|
799
1013
|
});
|
|
1014
|
+
const driver = this.#drivers.get(input.graphId);
|
|
1015
|
+
if (driver && committed.snapshotVersion === materialization.snapshot.snapshotVersion) {
|
|
1016
|
+
this.#observeActivityProjection(driver, materialization.snapshot, materialization.operators.map(({ operator }) => operator), input);
|
|
1017
|
+
}
|
|
1018
|
+
return committed;
|
|
800
1019
|
}
|
|
801
1020
|
#queueClientProjectionUpdate(driver, operation, authoritative = false) {
|
|
802
1021
|
const previous = driver.clientProjectionTask ?? Promise.resolve();
|
|
@@ -817,6 +1036,7 @@ export class AgentGraphCoordinator {
|
|
|
817
1036
|
}
|
|
818
1037
|
});
|
|
819
1038
|
driver.clientProjectionTask = task;
|
|
1039
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
820
1040
|
void task
|
|
821
1041
|
.catch(() => {
|
|
822
1042
|
// Failure state and reporting are owned inside the serialized task.
|
|
@@ -824,6 +1044,7 @@ export class AgentGraphCoordinator {
|
|
|
824
1044
|
.finally(() => {
|
|
825
1045
|
if (driver.clientProjectionTask === task) {
|
|
826
1046
|
driver.clientProjectionTask = undefined;
|
|
1047
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
827
1048
|
}
|
|
828
1049
|
});
|
|
829
1050
|
}
|
|
@@ -902,6 +1123,9 @@ export class AgentGraphCoordinator {
|
|
|
902
1123
|
driver.clientProjectionDirty = true;
|
|
903
1124
|
await notify(this.#input.onError, driver.rootSessionId, error);
|
|
904
1125
|
}
|
|
1126
|
+
finally {
|
|
1127
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
1128
|
+
}
|
|
905
1129
|
}
|
|
906
1130
|
async #advanceClientProjection(driver, event, activationHadError, sampleStartedAt) {
|
|
907
1131
|
for (let attempt = 0; attempt < MAX_CLIENT_PROJECTION_COMMIT_ATTEMPTS; attempt += 1) {
|
|
@@ -955,6 +1179,8 @@ export class AgentGraphCoordinator {
|
|
|
955
1179
|
...(advanced.activity ? { incrementalRecordId: advanced.activity.recordId } : {}),
|
|
956
1180
|
});
|
|
957
1181
|
if (committed.snapshotVersion === advanced.snapshot.snapshotVersion) {
|
|
1182
|
+
this.#observeActivityClaim(driver, event.claim);
|
|
1183
|
+
this.#observeActivityProjection(driver, advanced.snapshot, [advanced.operator.operator]);
|
|
958
1184
|
this.#notifyClientChanged(driver, 'runtime_activity');
|
|
959
1185
|
return { before: snapshot, after: advanced.snapshot };
|
|
960
1186
|
}
|
|
@@ -1080,10 +1306,12 @@ export class AgentGraphCoordinator {
|
|
|
1080
1306
|
createdAt: 0,
|
|
1081
1307
|
};
|
|
1082
1308
|
}
|
|
1083
|
-
|
|
1309
|
+
const binding = await this.#input.epochStore.resolveCurrentAgentGraphEpoch({
|
|
1084
1310
|
rootSessionId,
|
|
1085
1311
|
legacyGraphId: agentGraphIdForRootSession(rootSessionId),
|
|
1086
1312
|
});
|
|
1313
|
+
this.#observeActivityEpoch(binding);
|
|
1314
|
+
return binding;
|
|
1087
1315
|
}
|
|
1088
1316
|
async currentGraphId(rootSessionId) {
|
|
1089
1317
|
return (await this.currentGraphEpoch(rootSessionId)).graphId;
|
|
@@ -1097,12 +1325,25 @@ export class AgentGraphCoordinator {
|
|
|
1097
1325
|
throw new Error('Agent graph epoch binding belongs to another root Session');
|
|
1098
1326
|
}
|
|
1099
1327
|
const nextGraphId = agentGraphIdForRootSessionEpoch(rootSessionId, basis.epoch + 1);
|
|
1100
|
-
|
|
1328
|
+
const binding = await this.#input.epochStore.advanceAgentGraphEpoch({
|
|
1101
1329
|
rootSessionId,
|
|
1102
1330
|
expectedEpoch: basis.epoch,
|
|
1103
1331
|
expectedGraphId: basis.graphId,
|
|
1104
1332
|
nextGraphId,
|
|
1105
1333
|
});
|
|
1334
|
+
this.#observeActivityEpoch(binding);
|
|
1335
|
+
return binding;
|
|
1336
|
+
}
|
|
1337
|
+
#observeActivityEpoch(binding) {
|
|
1338
|
+
const previous = this.#activityEpochs.get(binding.rootSessionId);
|
|
1339
|
+
if (previous && previous.epoch >= binding.epoch)
|
|
1340
|
+
return;
|
|
1341
|
+
this.#activityEpochs.set(binding.rootSessionId, binding);
|
|
1342
|
+
const driver = this.#currentDrivers.get(binding.rootSessionId);
|
|
1343
|
+
if (driver && driver.graphId !== binding.graphId) {
|
|
1344
|
+
this.#currentDrivers.delete(binding.rootSessionId);
|
|
1345
|
+
this.#publishSessionActivity(binding.rootSessionId);
|
|
1346
|
+
}
|
|
1106
1347
|
}
|
|
1107
1348
|
async beginNextGraphEpoch(rootSessionId, withSupervisorWakesSuppressed) {
|
|
1108
1349
|
const current = await this.currentGraphEpoch(rootSessionId);
|
|
@@ -1136,11 +1377,16 @@ export class AgentGraphCoordinator {
|
|
|
1136
1377
|
// Cleanup belongs to the old epoch; its teardown I/O must not block the next.
|
|
1137
1378
|
driver.closed = true;
|
|
1138
1379
|
driver.requested = false;
|
|
1380
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
1139
1381
|
await Promise.allSettled([driver.task, driver.stopTask]);
|
|
1140
1382
|
await this.#waitForClientProjectionUpdates(driver);
|
|
1141
1383
|
if (driver.reconciliationReaders === 0)
|
|
1142
1384
|
driver.lastResult = undefined;
|
|
1143
1385
|
driver.runtimeFailureRunIds.clear();
|
|
1386
|
+
this.#clearActivityOperators(driver);
|
|
1387
|
+
driver.activityRequestedIntentIds.clear();
|
|
1388
|
+
driver.activityClaims.clear();
|
|
1389
|
+
driver.activityTurnStatuses.clear();
|
|
1144
1390
|
// Keep the lightweight driver for projection repair and close diagnostics.
|
|
1145
1391
|
}
|
|
1146
1392
|
async #readSessionStateForGraph(rootSessionId, graphId) {
|
|
@@ -1203,6 +1449,10 @@ export class AgentGraphCoordinator {
|
|
|
1203
1449
|
if (existing.rootSessionId !== rootSessionId) {
|
|
1204
1450
|
throw new Error(`Agent graph ${graphId} is already bound to another root Session`);
|
|
1205
1451
|
}
|
|
1452
|
+
if (!existing.closed &&
|
|
1453
|
+
(!this.#input.epochStore || this.#activityEpochs.get(rootSessionId)?.graphId === graphId)) {
|
|
1454
|
+
this.#currentDrivers.set(rootSessionId, existing);
|
|
1455
|
+
}
|
|
1206
1456
|
return existing;
|
|
1207
1457
|
}
|
|
1208
1458
|
const created = {
|
|
@@ -1211,6 +1461,7 @@ export class AgentGraphCoordinator {
|
|
|
1211
1461
|
requested: false,
|
|
1212
1462
|
paused: false,
|
|
1213
1463
|
stopping: false,
|
|
1464
|
+
stopFailed: false,
|
|
1214
1465
|
stopGeneration: 0,
|
|
1215
1466
|
driveGeneration: 0,
|
|
1216
1467
|
closed: false,
|
|
@@ -1220,8 +1471,20 @@ export class AgentGraphCoordinator {
|
|
|
1220
1471
|
pendingOutputDeltas: new Map(),
|
|
1221
1472
|
runtimeFailureRunIds: new Set(),
|
|
1222
1473
|
yieldWaiters: new Set(),
|
|
1474
|
+
scheduleChangeListeners: new Set(),
|
|
1475
|
+
activityOperators: new Map(),
|
|
1476
|
+
activityRequestedIntentIds: new Set(),
|
|
1477
|
+
activityClaims: new Map(),
|
|
1478
|
+
activityTurnStatuses: new Map(),
|
|
1479
|
+
activityScheduleRevision: 0,
|
|
1480
|
+
activityGraphClosed: false,
|
|
1481
|
+
activityHasFailures: false,
|
|
1482
|
+
activityProjection: 'idle',
|
|
1223
1483
|
};
|
|
1224
1484
|
this.#drivers.set(graphId, created);
|
|
1485
|
+
if (!this.#input.epochStore || this.#activityEpochs.get(rootSessionId)?.graphId === graphId) {
|
|
1486
|
+
this.#currentDrivers.set(rootSessionId, created);
|
|
1487
|
+
}
|
|
1225
1488
|
return created;
|
|
1226
1489
|
}
|
|
1227
1490
|
async #wake(rootSessionId) {
|
|
@@ -1230,6 +1493,8 @@ export class AgentGraphCoordinator {
|
|
|
1230
1493
|
if (driver.stopping)
|
|
1231
1494
|
return;
|
|
1232
1495
|
driver.paused = false;
|
|
1496
|
+
for (const listener of driver.scheduleChangeListeners)
|
|
1497
|
+
listener();
|
|
1233
1498
|
this.#requestDrive(driver);
|
|
1234
1499
|
}
|
|
1235
1500
|
catch (error) {
|
|
@@ -1245,14 +1510,18 @@ export class AgentGraphCoordinator {
|
|
|
1245
1510
|
return;
|
|
1246
1511
|
}
|
|
1247
1512
|
driver.paused = false;
|
|
1513
|
+
for (const listener of driver.scheduleChangeListeners)
|
|
1514
|
+
listener();
|
|
1248
1515
|
this.#requestDrive(driver);
|
|
1249
1516
|
}
|
|
1250
1517
|
#requestDrive(driver) {
|
|
1251
1518
|
if (driver.closed || this.#closed)
|
|
1252
1519
|
return;
|
|
1253
1520
|
driver.requested = true;
|
|
1254
|
-
if (driver.task)
|
|
1521
|
+
if (driver.task) {
|
|
1522
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
1255
1523
|
return;
|
|
1524
|
+
}
|
|
1256
1525
|
const residency = this.#input.acquireResidency?.(driver.rootSessionId);
|
|
1257
1526
|
driver.task = this.#drive(driver).finally(() => {
|
|
1258
1527
|
driver.task = undefined;
|
|
@@ -1260,7 +1529,9 @@ export class AgentGraphCoordinator {
|
|
|
1260
1529
|
if (driver.requested && !driver.paused && !driver.closed && !this.#closed) {
|
|
1261
1530
|
this.#requestDrive(driver);
|
|
1262
1531
|
}
|
|
1532
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
1263
1533
|
});
|
|
1534
|
+
this.#publishSessionActivity(driver.rootSessionId);
|
|
1264
1535
|
}
|
|
1265
1536
|
#prepareYieldPermit(driver) {
|
|
1266
1537
|
let resolveProof;
|