@xenosystem/agent-interface-host 0.1.19 → 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.
Files changed (33) hide show
  1. package/dist/acp/AcpAgentRegistryService.d.ts.map +1 -1
  2. package/dist/acp/AcpAgentRegistryService.js +55 -1
  3. package/dist/acp/AcpAgentRegistryService.js.map +1 -1
  4. package/dist/acp/AcpProviderModelService.d.ts.map +1 -1
  5. package/dist/acp/AcpProviderModelService.js +5 -1
  6. package/dist/acp/AcpProviderModelService.js.map +1 -1
  7. package/dist/developmentCoordinationNode.d.ts +10 -0
  8. package/dist/developmentCoordinationNode.d.ts.map +1 -0
  9. package/dist/developmentCoordinationNode.js +12 -0
  10. package/dist/developmentCoordinationNode.js.map +1 -0
  11. package/dist/index.d.ts +13 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +185 -5
  14. package/dist/index.js.map +1 -1
  15. package/dist/node.d.ts +1 -0
  16. package/dist/node.d.ts.map +1 -1
  17. package/dist/node.js +1 -0
  18. package/dist/node.js.map +1 -1
  19. package/dist/provider/ProviderLaneService.d.ts +2 -1
  20. package/dist/provider/ProviderLaneService.d.ts.map +1 -1
  21. package/dist/provider/ProviderLaneService.js +10 -0
  22. package/dist/provider/ProviderLaneService.js.map +1 -1
  23. package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts +2 -2
  24. package/dist/subagents/HostTurnSubagentExecutionAdapter.d.ts.map +1 -1
  25. package/dist/subagents/HostTurnSubagentExecutionAdapter.js +41 -0
  26. package/dist/subagents/HostTurnSubagentExecutionAdapter.js.map +1 -1
  27. package/dist/subagents/SubagentRunService.d.ts.map +1 -1
  28. package/dist/subagents/SubagentRunService.js +13 -1
  29. package/dist/subagents/SubagentRunService.js.map +1 -1
  30. package/dist/subagents/subagentRunPort.d.ts.map +1 -1
  31. package/dist/subagents/subagentRunPort.js +2 -0
  32. package/dist/subagents/subagentRunPort.js.map +1 -1
  33. 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
@@ -1791,6 +1907,12 @@ export class AgentHostCoordinator {
1791
1907
  releaseClient(instanceId) {
1792
1908
  this.connectedClients.delete(instanceId);
1793
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
+ }
1794
1916
  }
1795
1917
  /**
1796
1918
  * Is there a connected client that can put a question to a person and answer it?
@@ -1826,6 +1948,8 @@ export class AgentHostCoordinator {
1826
1948
  active.controller.abort('The XENO Agent host is shutting down.');
1827
1949
  }
1828
1950
  this.activeTurns.clear();
1951
+ await Promise.all([...this.developmentCoordinationLeases.values()].map((lease) => lease.stop()));
1952
+ this.developmentCoordinationLeases.clear();
1829
1953
  await Promise.all([...this.turnExecutionAdapters.values()].map(async (adapter) => {
1830
1954
  await adapter.close?.();
1831
1955
  }));
@@ -1944,11 +2068,36 @@ export class AgentHostCoordinator {
1944
2068
  * missing-scheduler refusal above: the parent turn may simply not have started yet, and
1945
2069
  * freezing that answer would replay it forever against a retry that would now succeed.
1946
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;
1947
2098
  const bound = boundSubagentWorkspace({
1948
2099
  ...(input.workspace === undefined ? {} : { requested: input.workspace }),
1949
- ...(this.parentTurnWorkspace(input) === undefined
1950
- ? {}
1951
- : { parent: this.parentTurnWorkspace(input) }),
2100
+ ...(effectiveParentWorkspace === undefined ? {} : { parent: effectiveParentWorkspace }),
1952
2101
  });
1953
2102
  if (!bound.granted)
1954
2103
  return { success: false, safeError: bound.safeError };
@@ -2055,7 +2204,11 @@ export class AgentHostCoordinator {
2055
2204
  if (context.workspace)
2056
2205
  return context.workspace;
2057
2206
  }
2058
- return undefined;
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);
2059
2212
  }
2060
2213
  listSubagentRuns(input) {
2061
2214
  if (!this.subagentRuns) {
@@ -3403,6 +3556,33 @@ function fingerprintProviders(providers) {
3403
3556
  .map((provider) => cloneProvider(provider))
3404
3557
  .sort((left, right) => left.id.localeCompare(right.id)));
3405
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
+ }
3406
3586
  function assertRuntimeEventForHost(value) {
3407
3587
  if (!isAgentRuntimeEventEnvelope(value)) {
3408
3588
  throw new AgentHostProtocolError('invalid_response', 'Runtime event does not satisfy the host contract.');