@xenosystem/agent-interface-host 0.1.18 → 0.1.21
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/dist/acp/AcpAgentRegistryService.d.ts.map +1 -1
- package/dist/acp/AcpAgentRegistryService.js +55 -1
- package/dist/acp/AcpAgentRegistryService.js.map +1 -1
- package/dist/acp/AcpProviderModelService.d.ts.map +1 -1
- package/dist/acp/AcpProviderModelService.js +5 -1
- package/dist/acp/AcpProviderModelService.js.map +1 -1
- package/dist/acp/AcpRuntimeEventMapper.d.ts.map +1 -1
- package/dist/acp/AcpRuntimeEventMapper.js +10 -0
- package/dist/acp/AcpRuntimeEventMapper.js.map +1 -1
- package/dist/developmentCoordinationNode.d.ts +10 -0
- package/dist/developmentCoordinationNode.d.ts.map +1 -0
- package/dist/developmentCoordinationNode.js +12 -0
- package/dist/developmentCoordinationNode.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +323 -6
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts +1 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +1 -0
- package/dist/node.js.map +1 -1
- package/dist/provider/ProviderLaneService.d.ts +2 -1
- package/dist/provider/ProviderLaneService.d.ts.map +1 -1
- package/dist/provider/ProviderLaneService.js +10 -0
- package/dist/provider/ProviderLaneService.js.map +1 -1
- package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts +2 -2
- package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts.map +1 -1
- package/dist/subagents/HostTurnSubagentExecutionAdapter.js +68 -5
- package/dist/subagents/HostTurnSubagentExecutionAdapter.js.map +1 -1
- package/dist/subagents/SubagentRunService.d.ts.map +1 -1
- package/dist/subagents/SubagentRunService.js +15 -1
- package/dist/subagents/SubagentRunService.js.map +1 -1
- package/dist/subagents/SubagentScheduler.d.ts +1 -0
- package/dist/subagents/SubagentScheduler.d.ts.map +1 -1
- package/dist/subagents/SubagentScheduler.js +37 -0
- package/dist/subagents/SubagentScheduler.js.map +1 -1
- package/dist/subagents/TeamAgentRouter.d.ts.map +1 -1
- package/dist/subagents/TeamAgentRouter.js +5 -2
- package/dist/subagents/TeamAgentRouter.js.map +1 -1
- package/dist/subagents/subagentRunPort.d.ts +14 -2
- package/dist/subagents/subagentRunPort.d.ts.map +1 -1
- package/dist/subagents/subagentRunPort.js +18 -0
- package/dist/subagents/subagentRunPort.js.map +1 -1
- package/dist/subagents/subagentTypes.d.ts +2 -0
- package/dist/subagents/subagentTypes.d.ts.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -21,6 +21,14 @@ import { RunObservationService } from './observation/RunObservationService.js';
|
|
|
21
21
|
import { RunIsolationService } from './isolation/RunIsolationService.js';
|
|
22
22
|
import { IntakeService } from './intake/IntakeService.js';
|
|
23
23
|
import { WorkspaceKnowledgeService } from './knowledge/WorkspaceKnowledgeService.js';
|
|
24
|
+
const DEVELOPMENT_COORDINATION_MODULE = '@xenosystem/agent-sdk/coordination';
|
|
25
|
+
let developmentCoordinationModulePromise;
|
|
26
|
+
function loadDevelopmentCoordinationModule() {
|
|
27
|
+
// Keep the Node-only durable store out of browser fixture bundles. Electron,
|
|
28
|
+
// Hub, and service hosts resolve this module only when the capability is used.
|
|
29
|
+
developmentCoordinationModulePromise ??= import(/* @vite-ignore */ DEVELOPMENT_COORDINATION_MODULE);
|
|
30
|
+
return developmentCoordinationModulePromise;
|
|
31
|
+
}
|
|
24
32
|
import { AgentSessionService } from './session/AgentSessionService.js';
|
|
25
33
|
import { createBufferedSessionPty } from './session/bufferedSessionPty.js';
|
|
26
34
|
import { createNativeTuiSessionPty } from './session/nativeTuiSessionPty.js';
|
|
@@ -58,6 +66,8 @@ export class AgentHostCoordinator {
|
|
|
58
66
|
sdkControlService;
|
|
59
67
|
engineeringControlService;
|
|
60
68
|
coordinationService;
|
|
69
|
+
developmentCoordinationStore;
|
|
70
|
+
developmentCoordinationLeases = new Map();
|
|
61
71
|
/**
|
|
62
72
|
* Run id -> the conversation that run belongs to.
|
|
63
73
|
*
|
|
@@ -131,7 +141,7 @@ export class AgentHostCoordinator {
|
|
|
131
141
|
providerCatalogFingerprint = '';
|
|
132
142
|
providerCatalogRefresh = null;
|
|
133
143
|
constructor(options) {
|
|
134
|
-
const { providers, providerCatalogLoader, runtimeEvents, runtimeEventRepository, stateRepository, workspaceService, interactionService, permissionPolicyService, interruptedTurnStore, turnAdmissionPolicy, turnAbandonGraceMs, sdkControlService, engineeringControlService, providerLaneService, turnExecutionAdapters, coordinationService, runObservationService, runIsolationService, runObservationBinder, sessionService, nativeTuiLane, acpAgentRegistry, intakeService, knowledgeService, acpApprovalService, subagentRuns, resolveRunId, ...hostOptions } = options;
|
|
144
|
+
const { providers, providerCatalogLoader, runtimeEvents, runtimeEventRepository, stateRepository, workspaceService, interactionService, permissionPolicyService, interruptedTurnStore, turnAdmissionPolicy, turnAbandonGraceMs, sdkControlService, engineeringControlService, providerLaneService, turnExecutionAdapters, coordinationService, developmentCoordinationStore, runObservationService, runIsolationService, runObservationBinder, sessionService, nativeTuiLane, acpAgentRegistry, intakeService, knowledgeService, acpApprovalService, subagentRuns, resolveRunId, ...hostOptions } = options;
|
|
135
145
|
if (runtimeEventRepository && runtimeEvents && runtimeEvents.length > 0) {
|
|
136
146
|
throw new Error('Seeded runtimeEvents cannot be combined with a durable runtimeEventRepository.');
|
|
137
147
|
}
|
|
@@ -151,6 +161,7 @@ export class AgentHostCoordinator {
|
|
|
151
161
|
this.providerLaneService?.setEventSink?.((type, payload) => this.publish(type, payload));
|
|
152
162
|
this.providerLaneService?.start?.();
|
|
153
163
|
this.coordinationService = coordinationService;
|
|
164
|
+
this.developmentCoordinationStore = developmentCoordinationStore;
|
|
154
165
|
// A turn's run identity, if the request carries one. `subagentRunId` first:
|
|
155
166
|
// a subagent IS a distinct run with its own claims, so folding it into its
|
|
156
167
|
// parent conversation would let two runs share one lock holder.
|
|
@@ -1472,6 +1483,111 @@ export class AgentHostCoordinator {
|
|
|
1472
1483
|
if (method === 'coordination.policy.set') {
|
|
1473
1484
|
return this.setCoordinationInboundPolicy(input);
|
|
1474
1485
|
}
|
|
1486
|
+
if (method === 'coordination.state.get') {
|
|
1487
|
+
const request = input;
|
|
1488
|
+
this.assertSdkControlClient(request);
|
|
1489
|
+
const coordination = await loadDevelopmentCoordinationModule();
|
|
1490
|
+
const coordinationStore = this.developmentCoordinationStore ??= new coordination.DurableXenoCoordinationStore();
|
|
1491
|
+
const outcome = await coordination.executeXenoCoordinationAction(coordinationStore, {
|
|
1492
|
+
action: 'state.get',
|
|
1493
|
+
sessionId: request.sessionId,
|
|
1494
|
+
});
|
|
1495
|
+
return {
|
|
1496
|
+
schemaVersion: 1,
|
|
1497
|
+
sessionId: outcome.sessionId,
|
|
1498
|
+
result: outcome.result,
|
|
1499
|
+
state: outcome.state,
|
|
1500
|
+
};
|
|
1501
|
+
}
|
|
1502
|
+
if (method === 'coordination.action') {
|
|
1503
|
+
const request = input;
|
|
1504
|
+
this.assertConnectedClient(request.command.client, 'changing development coordination state');
|
|
1505
|
+
const clientId = request.command.client.instanceId;
|
|
1506
|
+
const leaseKey = `${clientId}\u0000${request.sessionId}`;
|
|
1507
|
+
const ownerId = `interface:${clientId}`;
|
|
1508
|
+
const coordination = await loadDevelopmentCoordinationModule();
|
|
1509
|
+
const coordinationStore = this.developmentCoordinationStore ??= new coordination.DurableXenoCoordinationStore();
|
|
1510
|
+
let result;
|
|
1511
|
+
let state;
|
|
1512
|
+
if (request.action === 'ownership.acquire') {
|
|
1513
|
+
let lease = this.developmentCoordinationLeases.get(leaseKey);
|
|
1514
|
+
if (!lease) {
|
|
1515
|
+
lease = new coordination.XenoExecutionLeaseSession({
|
|
1516
|
+
store: coordinationStore,
|
|
1517
|
+
sessionId: request.sessionId,
|
|
1518
|
+
ownerId,
|
|
1519
|
+
});
|
|
1520
|
+
this.developmentCoordinationLeases.set(leaseKey, lease);
|
|
1521
|
+
}
|
|
1522
|
+
result = await lease.start();
|
|
1523
|
+
state = await coordinationStore.getSessionState(request.sessionId);
|
|
1524
|
+
}
|
|
1525
|
+
else if (request.action === 'ownership.renew') {
|
|
1526
|
+
const lease = this.developmentCoordinationLeases.get(leaseKey);
|
|
1527
|
+
if (!lease)
|
|
1528
|
+
throw new AgentHostProtocolError('invalid_response', 'This interface client does not own the session lease.');
|
|
1529
|
+
result = await lease.assertOwned();
|
|
1530
|
+
state = await coordinationStore.getSessionState(request.sessionId);
|
|
1531
|
+
}
|
|
1532
|
+
else if (request.action === 'ownership.release') {
|
|
1533
|
+
const lease = this.developmentCoordinationLeases.get(leaseKey);
|
|
1534
|
+
if (!lease)
|
|
1535
|
+
throw new AgentHostProtocolError('invalid_response', 'This interface client does not own the session lease.');
|
|
1536
|
+
result = lease.currentOwner;
|
|
1537
|
+
await lease.stop();
|
|
1538
|
+
this.developmentCoordinationLeases.delete(leaseKey);
|
|
1539
|
+
state = await coordinationStore.getSessionState(request.sessionId);
|
|
1540
|
+
}
|
|
1541
|
+
else if (request.action === 'handoff.create') {
|
|
1542
|
+
const lease = this.developmentCoordinationLeases.get(leaseKey);
|
|
1543
|
+
if (!lease)
|
|
1544
|
+
throw new AgentHostProtocolError('invalid_response', 'Acquire this session before preparing a handoff.');
|
|
1545
|
+
const payload = request.payload ?? {};
|
|
1546
|
+
result = await lease.prepareHandoff({
|
|
1547
|
+
...(typeof payload.targetOwnerId === 'string' ? { targetOwnerId: payload.targetOwnerId } : {}),
|
|
1548
|
+
...(typeof payload.goalId === 'string' ? { goalId: payload.goalId } : {}),
|
|
1549
|
+
...(typeof payload.loopId === 'string' ? { loopId: payload.loopId } : {}),
|
|
1550
|
+
...(typeof payload.workspace === 'string' ? { workspace: payload.workspace } : {}),
|
|
1551
|
+
...(typeof payload.branch === 'string' ? { branch: payload.branch } : {}),
|
|
1552
|
+
});
|
|
1553
|
+
state = await coordinationStore.getSessionState(request.sessionId);
|
|
1554
|
+
}
|
|
1555
|
+
else if (request.action === 'handoff.claim') {
|
|
1556
|
+
const handoffId = request.payload?.handoffId;
|
|
1557
|
+
if (typeof handoffId !== 'string' || !handoffId.trim())
|
|
1558
|
+
throw new AgentHostProtocolError('invalid_response', 'handoffId is required');
|
|
1559
|
+
const existing = this.developmentCoordinationLeases.get(leaseKey);
|
|
1560
|
+
if (existing)
|
|
1561
|
+
await existing.stop({ release: false });
|
|
1562
|
+
const lease = new coordination.XenoExecutionLeaseSession({
|
|
1563
|
+
store: coordinationStore,
|
|
1564
|
+
sessionId: request.sessionId,
|
|
1565
|
+
ownerId,
|
|
1566
|
+
claimHandoffId: handoffId,
|
|
1567
|
+
});
|
|
1568
|
+
this.developmentCoordinationLeases.set(leaseKey, lease);
|
|
1569
|
+
result = await lease.start();
|
|
1570
|
+
state = await coordinationStore.getSessionState(request.sessionId);
|
|
1571
|
+
}
|
|
1572
|
+
else {
|
|
1573
|
+
const outcome = await coordination.executeXenoCoordinationAction(coordinationStore, {
|
|
1574
|
+
action: request.action,
|
|
1575
|
+
sessionId: request.sessionId,
|
|
1576
|
+
...(request.payload ? { payload: request.payload } : {}),
|
|
1577
|
+
});
|
|
1578
|
+
result = outcome.result;
|
|
1579
|
+
state = outcome.state;
|
|
1580
|
+
}
|
|
1581
|
+
const event = state.events.at(-1);
|
|
1582
|
+
if (event)
|
|
1583
|
+
this.publish('coordination.event', safeDevelopmentCoordinationEvent(event));
|
|
1584
|
+
return {
|
|
1585
|
+
schemaVersion: 1,
|
|
1586
|
+
sessionId: request.sessionId,
|
|
1587
|
+
result,
|
|
1588
|
+
state,
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1475
1591
|
if (method === 'workspace.application.grant') {
|
|
1476
1592
|
// Deliberately NOT behind `assertWorkspaceClient`, matching
|
|
1477
1593
|
// `workspace.access.grant` beside it: granting is how a client comes to
|
|
@@ -1627,6 +1743,12 @@ export class AgentHostCoordinator {
|
|
|
1627
1743
|
if (method === 'subagent.run.cancel') {
|
|
1628
1744
|
return this.cancelSubagentRun(input);
|
|
1629
1745
|
}
|
|
1746
|
+
if (method === 'subagent.scheduler.status') {
|
|
1747
|
+
return this.readSubagentSchedulerStatus();
|
|
1748
|
+
}
|
|
1749
|
+
if (method === 'subagent.scheduler.recover') {
|
|
1750
|
+
return this.recoverSubagentRuns(input);
|
|
1751
|
+
}
|
|
1630
1752
|
if (method === 'fleet.view') {
|
|
1631
1753
|
return this.readFleetView(input);
|
|
1632
1754
|
}
|
|
@@ -1785,6 +1907,12 @@ export class AgentHostCoordinator {
|
|
|
1785
1907
|
releaseClient(instanceId) {
|
|
1786
1908
|
this.connectedClients.delete(instanceId);
|
|
1787
1909
|
this.clientCapabilities.delete(instanceId);
|
|
1910
|
+
for (const [key, lease] of this.developmentCoordinationLeases) {
|
|
1911
|
+
if (!key.startsWith(`${instanceId}\u0000`))
|
|
1912
|
+
continue;
|
|
1913
|
+
this.developmentCoordinationLeases.delete(key);
|
|
1914
|
+
void lease.stop();
|
|
1915
|
+
}
|
|
1788
1916
|
}
|
|
1789
1917
|
/**
|
|
1790
1918
|
* Is there a connected client that can put a question to a person and answer it?
|
|
@@ -1820,6 +1948,8 @@ export class AgentHostCoordinator {
|
|
|
1820
1948
|
active.controller.abort('The XENO Agent host is shutting down.');
|
|
1821
1949
|
}
|
|
1822
1950
|
this.activeTurns.clear();
|
|
1951
|
+
await Promise.all([...this.developmentCoordinationLeases.values()].map((lease) => lease.stop()));
|
|
1952
|
+
this.developmentCoordinationLeases.clear();
|
|
1823
1953
|
await Promise.all([...this.turnExecutionAdapters.values()].map(async (adapter) => {
|
|
1824
1954
|
await adapter.close?.();
|
|
1825
1955
|
}));
|
|
@@ -1938,14 +2068,63 @@ export class AgentHostCoordinator {
|
|
|
1938
2068
|
* missing-scheduler refusal above: the parent turn may simply not have started yet, and
|
|
1939
2069
|
* freezing that answer would replay it forever against a retry that would now succeed.
|
|
1940
2070
|
*/
|
|
2071
|
+
const hostParentWorkspace = this.parentTurnWorkspace(input);
|
|
2072
|
+
/**
|
|
2073
|
+
* A CLI-coordinated delegated turn has no provider turn on this host: the parent fan-out and
|
|
2074
|
+
* aggregation deliberately remain in the CLI while only the children execute here. Before
|
|
2075
|
+
* `parentWorkspace` existed that meant the host saw no parent authority, inherited nothing,
|
|
2076
|
+
* and launched every child in an isolated scratch directory. Delegation completed, but no
|
|
2077
|
+
* child could read the repository it had been asked to inspect.
|
|
2078
|
+
*
|
|
2079
|
+
* A live host parent is still the source of truth. If an external coordinator also declares
|
|
2080
|
+
* authority, first bound that declaration by the host-owned parent so it can only narrow it.
|
|
2081
|
+
* With no live host parent, the explicit declaration is the parent bound; this has the same
|
|
2082
|
+
* trust boundary as a connected surface starting a top-level turn with a workspace.
|
|
2083
|
+
*/
|
|
2084
|
+
const externalParentBound = hostParentWorkspace && input.parentWorkspace
|
|
2085
|
+
? boundSubagentWorkspace({ requested: input.parentWorkspace, parent: hostParentWorkspace })
|
|
2086
|
+
: undefined;
|
|
2087
|
+
if (externalParentBound && !externalParentBound.granted) {
|
|
2088
|
+
return { success: false, safeError: externalParentBound.safeError };
|
|
2089
|
+
}
|
|
2090
|
+
if (input.parentWorkspace && !hostParentWorkspace) {
|
|
2091
|
+
return {
|
|
2092
|
+
success: false,
|
|
2093
|
+
safeError: 'External parent workspace authority must first be bound to this host conversation.',
|
|
2094
|
+
};
|
|
2095
|
+
}
|
|
2096
|
+
const effectiveParentWorkspace = externalParentBound?.workspace
|
|
2097
|
+
?? hostParentWorkspace;
|
|
1941
2098
|
const bound = boundSubagentWorkspace({
|
|
1942
2099
|
...(input.workspace === undefined ? {} : { requested: input.workspace }),
|
|
1943
|
-
...(
|
|
1944
|
-
? {}
|
|
1945
|
-
: { parent: this.parentTurnWorkspace(input) }),
|
|
2100
|
+
...(effectiveParentWorkspace === undefined ? {} : { parent: effectiveParentWorkspace }),
|
|
1946
2101
|
});
|
|
1947
2102
|
if (!bound.granted)
|
|
1948
2103
|
return { success: false, safeError: bound.safeError };
|
|
2104
|
+
const parentDepth = Number.isFinite(input.parentDepth) ? Math.max(0, Math.floor(input.parentDepth ?? 0)) : 0;
|
|
2105
|
+
const maxChildDepth = Number.isFinite(input.policy?.maxChildDepth)
|
|
2106
|
+
? Math.max(1, Math.floor(input.policy?.maxChildDepth ?? 1))
|
|
2107
|
+
: 4;
|
|
2108
|
+
const depth = parentDepth + 1;
|
|
2109
|
+
if (depth > maxChildDepth) {
|
|
2110
|
+
return { success: false, safeError: `Subagent depth ${depth} exceeds the configured maximum ${maxChildDepth}.` };
|
|
2111
|
+
}
|
|
2112
|
+
const contextAttachmentIds = (input.contextAttachmentIds ?? []).filter((id) => typeof id === 'string' && id.trim());
|
|
2113
|
+
const contextAttachmentLimit = Number.isFinite(input.policy?.contextAttachmentLimit)
|
|
2114
|
+
? Math.max(0, Math.floor(input.policy?.contextAttachmentLimit ?? 0))
|
|
2115
|
+
: 20;
|
|
2116
|
+
if (contextAttachmentIds.length > contextAttachmentLimit) {
|
|
2117
|
+
return { success: false, safeError: `Subagent context exceeds the configured attachment limit ${contextAttachmentLimit}.` };
|
|
2118
|
+
}
|
|
2119
|
+
const delegationPolicy = {
|
|
2120
|
+
...(input.policy?.maxTokens === undefined ? {} : { maxTokens: input.policy.maxTokens }),
|
|
2121
|
+
...(input.policy?.maxCredits === undefined ? {} : { maxCredits: input.policy.maxCredits }),
|
|
2122
|
+
...(input.policy?.maxRuntimeMs === undefined ? {} : { maxRuntimeMs: input.policy.maxRuntimeMs }),
|
|
2123
|
+
maxConcurrentChildRuns: Math.max(1, Math.floor(input.policy?.maxConcurrentChildRuns ?? 1)),
|
|
2124
|
+
maxChildDepth,
|
|
2125
|
+
allowFurtherDelegation: input.policy?.allowFurtherDelegation !== false,
|
|
2126
|
+
cancellationPropagation: input.policy?.cancellationPropagation !== false,
|
|
2127
|
+
};
|
|
1949
2128
|
const created = this.subagentRuns.createRun({
|
|
1950
2129
|
...(bound.workspace === undefined ? {} : { workspace: bound.workspace }),
|
|
1951
2130
|
parentConversationId: input.parentConversationId,
|
|
@@ -1960,9 +2139,46 @@ export class AgentHostCoordinator {
|
|
|
1960
2139
|
...(input.requiredCapabilities === undefined
|
|
1961
2140
|
? {}
|
|
1962
2141
|
: { requiredCapabilities: [...input.requiredCapabilities] }),
|
|
2142
|
+
...(input.policy?.maxTokens === undefined && input.policy?.maxCredits === undefined
|
|
2143
|
+
? {}
|
|
2144
|
+
: {
|
|
2145
|
+
budget: {
|
|
2146
|
+
...(input.policy?.maxTokens === undefined ? {} : { maxTokens: input.policy.maxTokens }),
|
|
2147
|
+
...(input.policy?.maxCredits === undefined ? {} : { maxCredits: input.policy.maxCredits }),
|
|
2148
|
+
},
|
|
2149
|
+
}),
|
|
2150
|
+
queue: {
|
|
2151
|
+
priority: Number.isFinite(input.queue?.priority) ? Math.floor(input.queue?.priority ?? 0) : 0,
|
|
2152
|
+
slotKey: input.queue?.slotKey?.trim() || `${input.workspaceId}:${input.teamId}:${input.childAgentId}`,
|
|
2153
|
+
maxConcurrentRuns: Math.max(1, Math.floor(input.queue?.maxConcurrentRuns ?? delegationPolicy.maxConcurrentChildRuns)),
|
|
2154
|
+
},
|
|
2155
|
+
delegation: {
|
|
2156
|
+
routerVersion: 1,
|
|
2157
|
+
routedAt: Date.now(),
|
|
2158
|
+
parentConversationId: input.parentConversationId,
|
|
2159
|
+
...(input.parentRequestId === undefined ? {} : { parentRequestId: input.parentRequestId }),
|
|
2160
|
+
parentAgentId: input.parentAgentId,
|
|
2161
|
+
targetAgentId: input.childAgentId,
|
|
2162
|
+
workspaceId: input.workspaceId,
|
|
2163
|
+
teamId: input.teamId,
|
|
2164
|
+
contextAttachmentIds,
|
|
2165
|
+
expectedArtifacts: [...(input.expectedArtifacts ?? ['answer'])],
|
|
2166
|
+
policy: delegationPolicy,
|
|
2167
|
+
depth,
|
|
2168
|
+
},
|
|
1963
2169
|
});
|
|
1964
2170
|
const result = created.success && created.run
|
|
1965
|
-
? {
|
|
2171
|
+
? {
|
|
2172
|
+
success: true,
|
|
2173
|
+
run: summariseSubagentRun(created.run),
|
|
2174
|
+
hostManaged: true,
|
|
2175
|
+
route: {
|
|
2176
|
+
allowedDirectories: [bound.workspace?.primaryDirectory, ...(bound.workspace?.additionalDirectories ?? [])]
|
|
2177
|
+
.filter((directory) => typeof directory === 'string' && !!directory),
|
|
2178
|
+
maxConcurrentChildRuns: delegationPolicy.maxConcurrentChildRuns,
|
|
2179
|
+
},
|
|
2180
|
+
policy: { ...input.policy },
|
|
2181
|
+
}
|
|
1966
2182
|
: { success: false, safeError: created.error ?? 'The subagent run could not be created.' };
|
|
1967
2183
|
this.commandResults.set(commandKey, {
|
|
1968
2184
|
method: 'subagent.run.create',
|
|
@@ -1988,7 +2204,11 @@ export class AgentHostCoordinator {
|
|
|
1988
2204
|
if (context.workspace)
|
|
1989
2205
|
return context.workspace;
|
|
1990
2206
|
}
|
|
1991
|
-
|
|
2207
|
+
// External coordinators (for example the CLI fan-out reducer) do not run a parent model turn
|
|
2208
|
+
// on this host. They must bind their durable coordination conversation first; the provider
|
|
2209
|
+
// lane service then supplies host-owned workspace authority instead of trusting a caller-
|
|
2210
|
+
// supplied path declaration.
|
|
2211
|
+
return this.providerLaneService?.getConversationWorkspace?.(input.parentConversationId);
|
|
1992
2212
|
}
|
|
1993
2213
|
listSubagentRuns(input) {
|
|
1994
2214
|
if (!this.subagentRuns) {
|
|
@@ -1996,11 +2216,14 @@ export class AgentHostCoordinator {
|
|
|
1996
2216
|
}
|
|
1997
2217
|
const listed = this.subagentRuns.listRuns({
|
|
1998
2218
|
...(input.parentConversationId === undefined ? {} : { parentConversationId: input.parentConversationId }),
|
|
2219
|
+
...(input.parentAgentId === undefined ? {} : { parentAgentId: input.parentAgentId }),
|
|
2220
|
+
...(input.childConversationId === undefined ? {} : { childConversationId: input.childConversationId }),
|
|
1999
2221
|
...(input.childAgentId === undefined ? {} : { childAgentId: input.childAgentId }),
|
|
2000
2222
|
...(input.workspaceId === undefined ? {} : { workspaceId: input.workspaceId }),
|
|
2001
2223
|
...(input.teamId === undefined ? {} : { teamId: input.teamId }),
|
|
2002
2224
|
...(input.status === undefined ? {} : { status: input.status }),
|
|
2003
2225
|
...(input.activeOnly === undefined ? {} : { activeOnly: input.activeOnly }),
|
|
2226
|
+
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
2004
2227
|
});
|
|
2005
2228
|
return listed.success
|
|
2006
2229
|
? { success: true, runs: listed.runs.map(summariseSubagentRun) }
|
|
@@ -2021,6 +2244,73 @@ export class AgentHostCoordinator {
|
|
|
2021
2244
|
? { success: true, run: summariseSubagentRun(cancelled.run) }
|
|
2022
2245
|
: { success: false, safeError: cancelled.error ?? 'The subagent run could not be cancelled.' };
|
|
2023
2246
|
}
|
|
2247
|
+
readSubagentSchedulerStatus() {
|
|
2248
|
+
if (!this.subagentRuns) {
|
|
2249
|
+
return { success: false, safeError: 'This Agent host has no subagent scheduler mounted.' };
|
|
2250
|
+
}
|
|
2251
|
+
const status = this.subagentRuns.status();
|
|
2252
|
+
return {
|
|
2253
|
+
success: true,
|
|
2254
|
+
status: {
|
|
2255
|
+
running: status.running,
|
|
2256
|
+
intervalMs: status.intervalMs,
|
|
2257
|
+
...(status.lastSweepAt === undefined ? {} : { lastSweepAt: status.lastSweepAt }),
|
|
2258
|
+
lastRecovered: status.lastRecovered,
|
|
2259
|
+
lastFailed: status.lastFailed,
|
|
2260
|
+
lastTimedOut: status.lastTimedOut,
|
|
2261
|
+
lastStale: status.lastStale,
|
|
2262
|
+
...(status.lastError === undefined ? {} : { lastError: status.lastError }),
|
|
2263
|
+
lastChangedRunIds: [...status.lastChangedRunIds],
|
|
2264
|
+
adapterIds: [...status.adapterIds],
|
|
2265
|
+
adapterStatuses: status.adapterStatuses.map((adapter) => ({
|
|
2266
|
+
id: adapter.id,
|
|
2267
|
+
version: adapter.version,
|
|
2268
|
+
availability: adapter.availability,
|
|
2269
|
+
capabilities: [...adapter.capabilities],
|
|
2270
|
+
...(adapter.degradedReason === undefined ? {} : { degradedReason: adapter.degradedReason }),
|
|
2271
|
+
})),
|
|
2272
|
+
adapterAvailable: status.adapterAvailable,
|
|
2273
|
+
adapterDegraded: status.adapterDegraded,
|
|
2274
|
+
...(status.adapterDegradedReason === undefined ? {} : { adapterDegradedReason: status.adapterDegradedReason }),
|
|
2275
|
+
pendingRunIds: [...status.pendingRunIds],
|
|
2276
|
+
runningRunIds: [...status.runningRunIds],
|
|
2277
|
+
launchableRunIds: [...status.launchableRunIds],
|
|
2278
|
+
},
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
recoverSubagentRuns(input) {
|
|
2282
|
+
if (!this.isConnectedClient(input.command.client)) {
|
|
2283
|
+
return { success: false, recovered: 0, failed: 0, timedOut: 0, stale: 0, runs: [], safeError: 'The requesting surface must complete the host handshake first.' };
|
|
2284
|
+
}
|
|
2285
|
+
if (!this.subagentRuns) {
|
|
2286
|
+
return { success: false, recovered: 0, failed: 0, timedOut: 0, stale: 0, runs: [], safeError: 'This Agent host has no subagent scheduler mounted.' };
|
|
2287
|
+
}
|
|
2288
|
+
const commandKey = this.commandKey('subagent.scheduler.recover', input.command);
|
|
2289
|
+
const fingerprint = commandFingerprint(input);
|
|
2290
|
+
const prior = this.commandResults.get(commandKey);
|
|
2291
|
+
if (prior) {
|
|
2292
|
+
if (prior.method !== 'subagent.scheduler.recover' || prior.fingerprint !== fingerprint) {
|
|
2293
|
+
return { success: false, recovered: 0, failed: 0, timedOut: 0, stale: 0, runs: [], safeError: 'This idempotency key was already used for a different command.' };
|
|
2294
|
+
}
|
|
2295
|
+
return structuredClone(prior.result);
|
|
2296
|
+
}
|
|
2297
|
+
const recovered = this.subagentRuns.recover();
|
|
2298
|
+
const result = {
|
|
2299
|
+
success: recovered.success,
|
|
2300
|
+
recovered: recovered.recovered,
|
|
2301
|
+
failed: recovered.failed,
|
|
2302
|
+
timedOut: recovered.timedOut,
|
|
2303
|
+
stale: recovered.stale,
|
|
2304
|
+
runs: recovered.runs.map(summariseSubagentRun),
|
|
2305
|
+
...(recovered.error ? { safeError: recovered.error } : {}),
|
|
2306
|
+
};
|
|
2307
|
+
this.commandResults.set(commandKey, {
|
|
2308
|
+
method: 'subagent.scheduler.recover',
|
|
2309
|
+
fingerprint,
|
|
2310
|
+
result: structuredClone(result),
|
|
2311
|
+
});
|
|
2312
|
+
return result;
|
|
2313
|
+
}
|
|
2024
2314
|
/** Remember a timer owned by this turn, so settling can cancel it. */
|
|
2025
2315
|
trackTurnTimer(activeKey, timer) {
|
|
2026
2316
|
const timers = this.turnTimers.get(activeKey);
|
|
@@ -3266,6 +3556,33 @@ function fingerprintProviders(providers) {
|
|
|
3266
3556
|
.map((provider) => cloneProvider(provider))
|
|
3267
3557
|
.sort((left, right) => left.id.localeCompare(right.id)));
|
|
3268
3558
|
}
|
|
3559
|
+
/**
|
|
3560
|
+
* Host events are broadcast to every connected surface and are marked safe.
|
|
3561
|
+
* Canonical coordination state may contain an objective, steering text, or a
|
|
3562
|
+
* lease capability, so notifications carry only lifecycle facts. An
|
|
3563
|
+
* authenticated surface retrieves the detailed state explicitly.
|
|
3564
|
+
*/
|
|
3565
|
+
function safeDevelopmentCoordinationEvent(event) {
|
|
3566
|
+
const safeData = {};
|
|
3567
|
+
for (const key of ['status', 'previous', 'phase', 'number', 'epoch']) {
|
|
3568
|
+
const value = event.data[key];
|
|
3569
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean')
|
|
3570
|
+
safeData[key] = value;
|
|
3571
|
+
}
|
|
3572
|
+
return {
|
|
3573
|
+
schemaVersion: event.schemaVersion,
|
|
3574
|
+
id: event.id,
|
|
3575
|
+
sequence: event.sequence,
|
|
3576
|
+
type: event.type,
|
|
3577
|
+
sessionId: event.sessionId,
|
|
3578
|
+
...(event.goalId ? { goalId: event.goalId } : {}),
|
|
3579
|
+
...(event.loopId ? { loopId: event.loopId } : {}),
|
|
3580
|
+
...(event.handoffId ? { handoffId: event.handoffId } : {}),
|
|
3581
|
+
...(event.ownerId ? { ownerId: event.ownerId } : {}),
|
|
3582
|
+
timestamp: event.timestamp,
|
|
3583
|
+
data: safeData,
|
|
3584
|
+
};
|
|
3585
|
+
}
|
|
3269
3586
|
function assertRuntimeEventForHost(value) {
|
|
3270
3587
|
if (!isAgentRuntimeEventEnvelope(value)) {
|
|
3271
3588
|
throw new AgentHostProtocolError('invalid_response', 'Runtime event does not satisfy the host contract.');
|