@namzu/sdk 0.1.8 → 0.3.0
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/CHANGELOG.md +69 -2
- package/dist/agents/ReactiveAgent.d.ts.map +1 -1
- package/dist/agents/ReactiveAgent.js +5 -2
- package/dist/agents/ReactiveAgent.js.map +1 -1
- package/dist/agents/RouterAgent.d.ts.map +1 -1
- package/dist/agents/RouterAgent.js +3 -0
- package/dist/agents/RouterAgent.js.map +1 -1
- package/dist/agents/SupervisorAgent.d.ts.map +1 -1
- package/dist/agents/SupervisorAgent.js +21 -5
- package/dist/agents/SupervisorAgent.js.map +1 -1
- package/dist/bridge/a2a/index.d.ts +1 -1
- package/dist/bridge/a2a/index.d.ts.map +1 -1
- package/dist/bridge/a2a/index.js +1 -1
- package/dist/bridge/a2a/index.js.map +1 -1
- package/dist/bridge/a2a/mapper.d.ts.map +1 -1
- package/dist/bridge/a2a/mapper.js +6 -0
- package/dist/bridge/a2a/mapper.js.map +1 -1
- package/dist/bridge/a2a/message.d.ts +0 -2
- package/dist/bridge/a2a/message.d.ts.map +1 -1
- package/dist/bridge/a2a/message.js +0 -26
- package/dist/bridge/a2a/message.js.map +1 -1
- package/dist/bridge/a2a/task.d.ts +5 -4
- package/dist/bridge/a2a/task.d.ts.map +1 -1
- package/dist/bridge/a2a/task.js +4 -4
- package/dist/bridge/a2a/task.js.map +1 -1
- package/dist/bridge/sse/mapper.d.ts.map +1 -1
- package/dist/bridge/sse/mapper.js +6 -0
- package/dist/bridge/sse/mapper.js.map +1 -1
- package/dist/constants/a2a/index.d.ts +2 -2
- package/dist/constants/a2a/index.d.ts.map +1 -1
- package/dist/constants/a2a/index.js.map +1 -1
- package/dist/contracts/api.d.ts +14 -27
- package/dist/contracts/api.d.ts.map +1 -1
- package/dist/contracts/ids.d.ts +1 -1
- package/dist/contracts/ids.d.ts.map +1 -1
- package/dist/contracts/index.d.ts +3 -3
- package/dist/contracts/index.d.ts.map +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/schemas.d.ts +1 -31
- package/dist/contracts/schemas.d.ts.map +1 -1
- package/dist/contracts/schemas.js +1 -7
- package/dist/contracts/schemas.js.map +1 -1
- package/dist/gateway/local.d.ts.map +1 -1
- package/dist/gateway/local.js +6 -0
- package/dist/gateway/local.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/manager/agent/__tests__/lifecycle.test.d.ts +2 -0
- package/dist/manager/agent/__tests__/lifecycle.test.d.ts.map +1 -0
- package/dist/manager/agent/__tests__/lifecycle.test.js +316 -0
- package/dist/manager/agent/__tests__/lifecycle.test.js.map +1 -0
- package/dist/manager/agent/lifecycle.d.ts +67 -3
- package/dist/manager/agent/lifecycle.d.ts.map +1 -1
- package/dist/manager/agent/lifecycle.js +375 -14
- package/dist/manager/agent/lifecycle.js.map +1 -1
- package/dist/manager/index.d.ts +2 -0
- package/dist/manager/index.d.ts.map +1 -1
- package/dist/manager/index.js +1 -0
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/run/persistence.d.ts +10 -1
- package/dist/manager/run/persistence.d.ts.map +1 -1
- package/dist/manager/run/persistence.js +20 -0
- package/dist/manager/run/persistence.js.map +1 -1
- package/dist/manager/thread/__tests__/lifecycle.test.d.ts +2 -0
- package/dist/manager/thread/__tests__/lifecycle.test.d.ts.map +1 -0
- package/dist/manager/thread/__tests__/lifecycle.test.js +216 -0
- package/dist/manager/thread/__tests__/lifecycle.test.js.map +1 -0
- package/dist/manager/thread/lifecycle.d.ts +105 -0
- package/dist/manager/thread/lifecycle.d.ts.map +1 -0
- package/dist/manager/thread/lifecycle.js +186 -0
- package/dist/manager/thread/lifecycle.js.map +1 -0
- package/dist/rag/retriever.js +2 -2
- package/dist/run/reporter.d.ts.map +1 -1
- package/dist/run/reporter.js +25 -0
- package/dist/run/reporter.js.map +1 -1
- package/dist/runtime/query/__tests__/context.test.d.ts +2 -0
- package/dist/runtime/query/__tests__/context.test.d.ts.map +1 -0
- package/dist/runtime/query/__tests__/context.test.js +85 -0
- package/dist/runtime/query/__tests__/context.test.js.map +1 -0
- package/dist/runtime/query/context-cache.d.ts +3 -3
- package/dist/runtime/query/context-cache.d.ts.map +1 -1
- package/dist/runtime/query/context-cache.js +2 -2
- package/dist/runtime/query/context-cache.js.map +1 -1
- package/dist/runtime/query/context.d.ts +45 -1
- package/dist/runtime/query/context.d.ts.map +1 -1
- package/dist/runtime/query/context.js +50 -8
- package/dist/runtime/query/context.js.map +1 -1
- package/dist/runtime/query/events.d.ts.map +1 -1
- package/dist/runtime/query/events.js +8 -0
- package/dist/runtime/query/events.js.map +1 -1
- package/dist/runtime/query/index.d.ts +22 -1
- package/dist/runtime/query/index.d.ts.map +1 -1
- package/dist/runtime/query/index.js +11 -0
- package/dist/runtime/query/index.js.map +1 -1
- package/dist/session/__tests__/integration/_fixtures.d.ts +122 -0
- package/dist/session/__tests__/integration/_fixtures.d.ts.map +1 -0
- package/dist/session/__tests__/integration/_fixtures.js +215 -0
- package/dist/session/__tests__/integration/_fixtures.js.map +1 -0
- package/dist/session/__tests__/integration/archive-gate.test.d.ts +15 -0
- package/dist/session/__tests__/integration/archive-gate.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/archive-gate.test.js +214 -0
- package/dist/session/__tests__/integration/archive-gate.test.js.map +1 -0
- package/dist/session/__tests__/integration/capacity-caps.test.d.ts +13 -0
- package/dist/session/__tests__/integration/capacity-caps.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/capacity-caps.test.js +123 -0
- package/dist/session/__tests__/integration/capacity-caps.test.js.map +1 -0
- package/dist/session/__tests__/integration/e2e-spawn.test.d.ts +18 -0
- package/dist/session/__tests__/integration/e2e-spawn.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/e2e-spawn.test.js +238 -0
- package/dist/session/__tests__/integration/e2e-spawn.test.js.map +1 -0
- package/dist/session/__tests__/integration/event-stream-ordering.test.d.ts +15 -0
- package/dist/session/__tests__/integration/event-stream-ordering.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/event-stream-ordering.test.js +330 -0
- package/dist/session/__tests__/integration/event-stream-ordering.test.js.map +1 -0
- package/dist/session/__tests__/integration/handoff-broadcast-e2e.test.d.ts +12 -0
- package/dist/session/__tests__/integration/handoff-broadcast-e2e.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/handoff-broadcast-e2e.test.js +182 -0
- package/dist/session/__tests__/integration/handoff-broadcast-e2e.test.js.map +1 -0
- package/dist/session/__tests__/integration/handoff-illegal-transition.test.d.ts +18 -0
- package/dist/session/__tests__/integration/handoff-illegal-transition.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/handoff-illegal-transition.test.js +156 -0
- package/dist/session/__tests__/integration/handoff-illegal-transition.test.js.map +1 -0
- package/dist/session/__tests__/integration/handoff-single-e2e.test.d.ts +15 -0
- package/dist/session/__tests__/integration/handoff-single-e2e.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/handoff-single-e2e.test.js +179 -0
- package/dist/session/__tests__/integration/handoff-single-e2e.test.js.map +1 -0
- package/dist/session/__tests__/integration/hierarchy-lifecycle.test.d.ts +12 -0
- package/dist/session/__tests__/integration/hierarchy-lifecycle.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/hierarchy-lifecycle.test.js +158 -0
- package/dist/session/__tests__/integration/hierarchy-lifecycle.test.js.map +1 -0
- package/dist/session/__tests__/integration/migration-filesystem.test.d.ts +11 -0
- package/dist/session/__tests__/integration/migration-filesystem.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/migration-filesystem.test.js +140 -0
- package/dist/session/__tests__/integration/migration-filesystem.test.js.map +1 -0
- package/dist/session/__tests__/integration/migration-id-prefix.test.d.ts +13 -0
- package/dist/session/__tests__/integration/migration-id-prefix.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/migration-id-prefix.test.js +84 -0
- package/dist/session/__tests__/integration/migration-id-prefix.test.js.map +1 -0
- package/dist/session/__tests__/integration/prev-artifact-dag.test.d.ts +14 -0
- package/dist/session/__tests__/integration/prev-artifact-dag.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/prev-artifact-dag.test.js +242 -0
- package/dist/session/__tests__/integration/prev-artifact-dag.test.js.map +1 -0
- package/dist/session/__tests__/integration/retention-archive.test.d.ts +12 -0
- package/dist/session/__tests__/integration/retention-archive.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/retention-archive.test.js +187 -0
- package/dist/session/__tests__/integration/retention-archive.test.js.map +1 -0
- package/dist/session/__tests__/integration/spawn-rollback.test.d.ts +26 -0
- package/dist/session/__tests__/integration/spawn-rollback.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/spawn-rollback.test.js +236 -0
- package/dist/session/__tests__/integration/spawn-rollback.test.js.map +1 -0
- package/dist/session/__tests__/integration/summary-materialization-e2e.test.d.ts +18 -0
- package/dist/session/__tests__/integration/summary-materialization-e2e.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/summary-materialization-e2e.test.js +201 -0
- package/dist/session/__tests__/integration/summary-materialization-e2e.test.js.map +1 -0
- package/dist/session/__tests__/integration/tenant-isolation.test.d.ts +14 -0
- package/dist/session/__tests__/integration/tenant-isolation.test.d.ts.map +1 -0
- package/dist/session/__tests__/integration/tenant-isolation.test.js +189 -0
- package/dist/session/__tests__/integration/tenant-isolation.test.js.map +1 -0
- package/dist/session/errors.d.ts +139 -0
- package/dist/session/errors.d.ts.map +1 -0
- package/dist/session/errors.js +107 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/events/index.d.ts +4 -0
- package/dist/session/events/index.d.ts.map +1 -0
- package/dist/session/events/index.js +8 -0
- package/dist/session/events/index.js.map +1 -0
- package/dist/session/events/schema-version.d.ts +13 -0
- package/dist/session/events/schema-version.d.ts.map +1 -0
- package/dist/session/events/schema-version.js +12 -0
- package/dist/session/events/schema-version.js.map +1 -0
- package/dist/session/events/types.d.ts +64 -0
- package/dist/session/events/types.d.ts.map +1 -0
- package/dist/session/events/types.js +2 -0
- package/dist/session/events/types.js.map +1 -0
- package/dist/session/handoff/__tests__/broadcast.test.d.ts +2 -0
- package/dist/session/handoff/__tests__/broadcast.test.d.ts.map +1 -0
- package/dist/session/handoff/__tests__/broadcast.test.js +261 -0
- package/dist/session/handoff/__tests__/broadcast.test.js.map +1 -0
- package/dist/session/handoff/__tests__/capacity.test.d.ts +2 -0
- package/dist/session/handoff/__tests__/capacity.test.d.ts.map +1 -0
- package/dist/session/handoff/__tests__/capacity.test.js +103 -0
- package/dist/session/handoff/__tests__/capacity.test.js.map +1 -0
- package/dist/session/handoff/__tests__/single.test.d.ts +2 -0
- package/dist/session/handoff/__tests__/single.test.d.ts.map +1 -0
- package/dist/session/handoff/__tests__/single.test.js +239 -0
- package/dist/session/handoff/__tests__/single.test.js.map +1 -0
- package/dist/session/handoff/assignment.d.ts +71 -0
- package/dist/session/handoff/assignment.d.ts.map +1 -0
- package/dist/session/handoff/assignment.js +11 -0
- package/dist/session/handoff/assignment.js.map +1 -0
- package/dist/session/handoff/broadcast.d.ts +54 -0
- package/dist/session/handoff/broadcast.d.ts.map +1 -0
- package/dist/session/handoff/broadcast.js +311 -0
- package/dist/session/handoff/broadcast.js.map +1 -0
- package/dist/session/handoff/capacity.d.ts +66 -0
- package/dist/session/handoff/capacity.d.ts.map +1 -0
- package/dist/session/handoff/capacity.js +60 -0
- package/dist/session/handoff/capacity.js.map +1 -0
- package/dist/session/handoff/events.d.ts +66 -0
- package/dist/session/handoff/events.d.ts.map +1 -0
- package/dist/session/handoff/events.js +13 -0
- package/dist/session/handoff/events.js.map +1 -0
- package/dist/session/handoff/index.d.ts +12 -0
- package/dist/session/handoff/index.d.ts.map +1 -0
- package/dist/session/handoff/index.js +9 -0
- package/dist/session/handoff/index.js.map +1 -0
- package/dist/session/handoff/single.d.ts +69 -0
- package/dist/session/handoff/single.d.ts.map +1 -0
- package/dist/session/handoff/single.js +229 -0
- package/dist/session/handoff/single.js.map +1 -0
- package/dist/session/handoff/version.d.ts +52 -0
- package/dist/session/handoff/version.d.ts.map +1 -0
- package/dist/session/handoff/version.js +36 -0
- package/dist/session/handoff/version.js.map +1 -0
- package/dist/session/hierarchy/__tests__/session.test.d.ts +2 -0
- package/dist/session/hierarchy/__tests__/session.test.d.ts.map +1 -0
- package/dist/session/hierarchy/__tests__/session.test.js +69 -0
- package/dist/session/hierarchy/__tests__/session.test.js.map +1 -0
- package/dist/session/hierarchy/actor.d.ts +26 -0
- package/dist/session/hierarchy/actor.d.ts.map +1 -0
- package/dist/session/hierarchy/actor.js +2 -0
- package/dist/session/hierarchy/actor.js.map +1 -0
- package/dist/session/hierarchy/index.d.ts +9 -0
- package/dist/session/hierarchy/index.d.ts.map +1 -0
- package/dist/session/hierarchy/index.js +4 -0
- package/dist/session/hierarchy/index.js.map +1 -0
- package/dist/session/hierarchy/lineage.d.ts +15 -0
- package/dist/session/hierarchy/lineage.d.ts.map +1 -0
- package/dist/session/hierarchy/lineage.js +2 -0
- package/dist/session/hierarchy/lineage.js.map +1 -0
- package/dist/session/hierarchy/project.d.ts +40 -0
- package/dist/session/hierarchy/project.d.ts.map +1 -0
- package/dist/session/hierarchy/project.js +2 -0
- package/dist/session/hierarchy/project.js.map +1 -0
- package/dist/session/hierarchy/session.d.ts +71 -0
- package/dist/session/hierarchy/session.d.ts.map +1 -0
- package/dist/session/hierarchy/session.js +51 -0
- package/dist/session/hierarchy/session.js.map +1 -0
- package/dist/session/hierarchy/sub-session.d.ts +76 -0
- package/dist/session/hierarchy/sub-session.d.ts.map +1 -0
- package/dist/session/hierarchy/sub-session.js +2 -0
- package/dist/session/hierarchy/sub-session.js.map +1 -0
- package/dist/session/hierarchy/tenant.d.ts +13 -0
- package/dist/session/hierarchy/tenant.d.ts.map +1 -0
- package/dist/session/hierarchy/tenant.js +2 -0
- package/dist/session/hierarchy/tenant.js.map +1 -0
- package/dist/session/hierarchy/thread.d.ts +54 -0
- package/dist/session/hierarchy/thread.d.ts.map +1 -0
- package/dist/session/hierarchy/thread.js +2 -0
- package/dist/session/hierarchy/thread.js.map +1 -0
- package/dist/session/index.d.ts +10 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +15 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/intervention/__tests__/prev-artifact.test.d.ts +2 -0
- package/dist/session/intervention/__tests__/prev-artifact.test.d.ts.map +1 -0
- package/dist/session/intervention/__tests__/prev-artifact.test.js +179 -0
- package/dist/session/intervention/__tests__/prev-artifact.test.js.map +1 -0
- package/dist/session/intervention/index.d.ts +3 -0
- package/dist/session/intervention/index.d.ts.map +1 -0
- package/dist/session/intervention/index.js +8 -0
- package/dist/session/intervention/index.js.map +1 -0
- package/dist/session/intervention/prev-artifact.d.ts +103 -0
- package/dist/session/intervention/prev-artifact.d.ts.map +1 -0
- package/dist/session/intervention/prev-artifact.js +112 -0
- package/dist/session/intervention/prev-artifact.js.map +1 -0
- package/dist/session/migration/__tests__/filesystem.test.d.ts +2 -0
- package/dist/session/migration/__tests__/filesystem.test.d.ts.map +1 -0
- package/dist/session/migration/__tests__/filesystem.test.js +188 -0
- package/dist/session/migration/__tests__/filesystem.test.js.map +1 -0
- package/dist/session/migration/__tests__/id-prefix.test.d.ts +2 -0
- package/dist/session/migration/__tests__/id-prefix.test.d.ts.map +1 -0
- package/dist/session/migration/__tests__/id-prefix.test.js +83 -0
- package/dist/session/migration/__tests__/id-prefix.test.js.map +1 -0
- package/dist/session/migration/__tests__/marker.test.d.ts +2 -0
- package/dist/session/migration/__tests__/marker.test.d.ts.map +1 -0
- package/dist/session/migration/__tests__/marker.test.js +75 -0
- package/dist/session/migration/__tests__/marker.test.js.map +1 -0
- package/dist/session/migration/errors.d.ts +26 -0
- package/dist/session/migration/errors.d.ts.map +1 -0
- package/dist/session/migration/errors.js +22 -0
- package/dist/session/migration/errors.js.map +1 -0
- package/dist/session/migration/filesystem.d.ts +94 -0
- package/dist/session/migration/filesystem.d.ts.map +1 -0
- package/dist/session/migration/filesystem.js +319 -0
- package/dist/session/migration/filesystem.js.map +1 -0
- package/dist/session/migration/id-prefix.d.ts +93 -0
- package/dist/session/migration/id-prefix.d.ts.map +1 -0
- package/dist/session/migration/id-prefix.js +111 -0
- package/dist/session/migration/id-prefix.js.map +1 -0
- package/dist/session/migration/index.d.ts +8 -0
- package/dist/session/migration/index.d.ts.map +1 -0
- package/dist/session/migration/index.js +8 -0
- package/dist/session/migration/index.js.map +1 -0
- package/dist/session/migration/marker.d.ts +57 -0
- package/dist/session/migration/marker.d.ts.map +1 -0
- package/dist/session/migration/marker.js +111 -0
- package/dist/session/migration/marker.js.map +1 -0
- package/dist/session/retention/__tests__/archive.test.d.ts +2 -0
- package/dist/session/retention/__tests__/archive.test.d.ts.map +1 -0
- package/dist/session/retention/__tests__/archive.test.js +253 -0
- package/dist/session/retention/__tests__/archive.test.js.map +1 -0
- package/dist/session/retention/__tests__/disk-backend.test.d.ts +2 -0
- package/dist/session/retention/__tests__/disk-backend.test.d.ts.map +1 -0
- package/dist/session/retention/__tests__/disk-backend.test.js +154 -0
- package/dist/session/retention/__tests__/disk-backend.test.js.map +1 -0
- package/dist/session/retention/archive-backend-ref.d.ts +18 -0
- package/dist/session/retention/archive-backend-ref.d.ts.map +1 -0
- package/dist/session/retention/archive-backend-ref.js +2 -0
- package/dist/session/retention/archive-backend-ref.js.map +1 -0
- package/dist/session/retention/archive.d.ts +130 -0
- package/dist/session/retention/archive.d.ts.map +1 -0
- package/dist/session/retention/archive.js +203 -0
- package/dist/session/retention/archive.js.map +1 -0
- package/dist/session/retention/backend.d.ts +101 -0
- package/dist/session/retention/backend.d.ts.map +1 -0
- package/dist/session/retention/backend.js +15 -0
- package/dist/session/retention/backend.js.map +1 -0
- package/dist/session/retention/disk-backend.d.ts +59 -0
- package/dist/session/retention/disk-backend.d.ts.map +1 -0
- package/dist/session/retention/disk-backend.js +236 -0
- package/dist/session/retention/disk-backend.js.map +1 -0
- package/dist/session/retention/index.d.ts +9 -0
- package/dist/session/retention/index.d.ts.map +1 -0
- package/dist/session/retention/index.js +6 -0
- package/dist/session/retention/index.js.map +1 -0
- package/dist/session/retention/policy.d.ts +49 -0
- package/dist/session/retention/policy.d.ts.map +1 -0
- package/dist/session/retention/policy.js +21 -0
- package/dist/session/retention/policy.js.map +1 -0
- package/dist/session/summary/__tests__/materialize.test.d.ts +2 -0
- package/dist/session/summary/__tests__/materialize.test.d.ts.map +1 -0
- package/dist/session/summary/__tests__/materialize.test.js +270 -0
- package/dist/session/summary/__tests__/materialize.test.js.map +1 -0
- package/dist/session/summary/deliverable.d.ts +74 -0
- package/dist/session/summary/deliverable.d.ts.map +1 -0
- package/dist/session/summary/deliverable.js +20 -0
- package/dist/session/summary/deliverable.js.map +1 -0
- package/dist/session/summary/index.d.ts +6 -0
- package/dist/session/summary/index.d.ts.map +1 -0
- package/dist/session/summary/index.js +9 -0
- package/dist/session/summary/index.js.map +1 -0
- package/dist/session/summary/materialize.d.ts +82 -0
- package/dist/session/summary/materialize.d.ts.map +1 -0
- package/dist/session/summary/materialize.js +117 -0
- package/dist/session/summary/materialize.js.map +1 -0
- package/dist/session/summary/ref.d.ts +91 -0
- package/dist/session/summary/ref.d.ts.map +1 -0
- package/dist/session/summary/ref.js +51 -0
- package/dist/session/summary/ref.js.map +1 -0
- package/dist/session/workspace/__tests__/git-worktree.test.d.ts +2 -0
- package/dist/session/workspace/__tests__/git-worktree.test.d.ts.map +1 -0
- package/dist/session/workspace/__tests__/git-worktree.test.js +244 -0
- package/dist/session/workspace/__tests__/git-worktree.test.js.map +1 -0
- package/dist/session/workspace/__tests__/path-builder.test.d.ts +2 -0
- package/dist/session/workspace/__tests__/path-builder.test.d.ts.map +1 -0
- package/dist/session/workspace/__tests__/path-builder.test.js +37 -0
- package/dist/session/workspace/__tests__/path-builder.test.js.map +1 -0
- package/dist/session/workspace/driver.d.ts +55 -0
- package/dist/session/workspace/driver.d.ts.map +1 -0
- package/dist/session/workspace/driver.js +12 -0
- package/dist/session/workspace/driver.js.map +1 -0
- package/dist/session/workspace/git-worktree.d.ts +65 -0
- package/dist/session/workspace/git-worktree.d.ts.map +1 -0
- package/dist/session/workspace/git-worktree.js +156 -0
- package/dist/session/workspace/git-worktree.js.map +1 -0
- package/dist/session/workspace/index.d.ts +8 -0
- package/dist/session/workspace/index.d.ts.map +1 -0
- package/dist/session/workspace/index.js +7 -0
- package/dist/session/workspace/index.js.map +1 -0
- package/dist/session/workspace/path-builder.d.ts +50 -0
- package/dist/session/workspace/path-builder.d.ts.map +1 -0
- package/dist/session/workspace/path-builder.js +50 -0
- package/dist/session/workspace/path-builder.js.map +1 -0
- package/dist/session/workspace/ref.d.ts +46 -0
- package/dist/session/workspace/ref.d.ts.map +1 -0
- package/dist/session/workspace/ref.js +11 -0
- package/dist/session/workspace/ref.js.map +1 -0
- package/dist/session/workspace/registry.d.ts +26 -0
- package/dist/session/workspace/registry.d.ts.map +1 -0
- package/dist/session/workspace/registry.js +35 -0
- package/dist/session/workspace/registry.js.map +1 -0
- package/dist/store/index.d.ts +0 -2
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +0 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/session/__tests__/disk.test.d.ts +2 -0
- package/dist/store/session/__tests__/disk.test.d.ts.map +1 -0
- package/dist/store/session/__tests__/disk.test.js +267 -0
- package/dist/store/session/__tests__/disk.test.js.map +1 -0
- package/dist/store/session/__tests__/memory.test.d.ts +2 -0
- package/dist/store/session/__tests__/memory.test.d.ts.map +1 -0
- package/dist/store/session/__tests__/memory.test.js +258 -0
- package/dist/store/session/__tests__/memory.test.js.map +1 -0
- package/dist/store/session/disk.d.ts +86 -0
- package/dist/store/session/disk.d.ts.map +1 -0
- package/dist/store/session/disk.js +818 -0
- package/dist/store/session/disk.js.map +1 -0
- package/dist/store/session/index.d.ts +7 -0
- package/dist/store/session/index.d.ts.map +1 -0
- package/dist/store/session/index.js +10 -0
- package/dist/store/session/index.js.map +1 -0
- package/dist/store/session/linkage.d.ts +38 -0
- package/dist/store/session/linkage.d.ts.map +1 -0
- package/dist/store/session/linkage.js +64 -0
- package/dist/store/session/linkage.js.map +1 -0
- package/dist/store/session/memory.d.ts +49 -0
- package/dist/store/session/memory.d.ts.map +1 -0
- package/dist/store/session/memory.js +335 -0
- package/dist/store/session/memory.js.map +1 -0
- package/dist/store/session/messages.d.ts +20 -0
- package/dist/store/session/messages.d.ts.map +1 -0
- package/dist/store/session/messages.js +12 -0
- package/dist/store/session/messages.js.map +1 -0
- package/dist/store/thread/disk.d.ts +41 -0
- package/dist/store/thread/disk.d.ts.map +1 -0
- package/dist/store/thread/disk.js +229 -0
- package/dist/store/thread/disk.js.map +1 -0
- package/dist/store/thread/index.d.ts +4 -0
- package/dist/store/thread/index.d.ts.map +1 -0
- package/dist/store/thread/index.js +6 -0
- package/dist/store/thread/index.js.map +1 -0
- package/dist/store/thread/memory.d.ts +23 -0
- package/dist/store/thread/memory.d.ts.map +1 -0
- package/dist/store/thread/memory.js +90 -0
- package/dist/store/thread/memory.js.map +1 -0
- package/dist/tools/builtins/__tests__/structuredOutput.example.d.ts +1 -1
- package/dist/types/agent/base.d.ts +24 -1
- package/dist/types/agent/base.d.ts.map +1 -1
- package/dist/types/agent/factory.d.ts +8 -2
- package/dist/types/agent/factory.d.ts.map +1 -1
- package/dist/types/agent/task.d.ts +57 -2
- package/dist/types/agent/task.d.ts.map +1 -1
- package/dist/types/agent/task.js.map +1 -1
- package/dist/types/ids/index.d.ts +22 -3
- package/dist/types/ids/index.d.ts.map +1 -1
- package/dist/types/ids/index.js +8 -1
- package/dist/types/ids/index.js.map +1 -1
- package/dist/types/invocation/__tests__/state.test.js +36 -29
- package/dist/types/invocation/__tests__/state.test.js.map +1 -1
- package/dist/types/invocation/index.d.ts +20 -4
- package/dist/types/invocation/index.d.ts.map +1 -1
- package/dist/types/invocation/index.js +10 -7
- package/dist/types/invocation/index.js.map +1 -1
- package/dist/types/rag/retrieval.d.ts +4 -3
- package/dist/types/rag/retrieval.d.ts.map +1 -1
- package/dist/types/run/config.d.ts +12 -1
- package/dist/types/run/config.d.ts.map +1 -1
- package/dist/types/run/events.d.ts +26 -1
- package/dist/types/run/events.d.ts.map +1 -1
- package/dist/types/run/index.d.ts.map +1 -1
- package/dist/types/run/index.js +8 -0
- package/dist/types/run/index.js.map +1 -1
- package/dist/types/run/metadata.d.ts +12 -2
- package/dist/types/run/metadata.d.ts.map +1 -1
- package/dist/types/run/status.d.ts +26 -0
- package/dist/types/run/status.d.ts.map +1 -0
- package/dist/types/run/status.js +2 -0
- package/dist/types/run/status.js.map +1 -0
- package/dist/types/session/ids.d.ts +9 -0
- package/dist/types/session/ids.d.ts.map +1 -0
- package/dist/types/session/ids.js +9 -0
- package/dist/types/session/ids.js.map +1 -0
- package/dist/types/session/index.d.ts +3 -0
- package/dist/types/session/index.d.ts.map +1 -0
- package/dist/types/session/index.js +5 -0
- package/dist/types/session/index.js.map +1 -0
- package/dist/types/session/store.d.ts +210 -0
- package/dist/types/session/store.d.ts.map +1 -0
- package/dist/types/session/store.js +9 -0
- package/dist/types/session/store.js.map +1 -0
- package/dist/types/thread/index.d.ts +2 -0
- package/dist/types/thread/index.d.ts.map +1 -0
- package/dist/types/thread/index.js +5 -0
- package/dist/types/thread/index.js.map +1 -0
- package/dist/types/thread/store.d.ts +86 -0
- package/dist/types/thread/store.d.ts.map +1 -0
- package/dist/types/thread/store.js +22 -0
- package/dist/types/thread/store.js.map +1 -0
- package/dist/utils/id.d.ts +8 -2
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +22 -4
- package/dist/utils/id.js.map +1 -1
- package/package.json +6 -11
- package/src/agents/ReactiveAgent.ts +7 -2
- package/src/agents/RouterAgent.ts +5 -0
- package/src/agents/SupervisorAgent.ts +29 -6
- package/src/bridge/a2a/index.ts +0 -1
- package/src/bridge/a2a/mapper.ts +7 -0
- package/src/bridge/a2a/message.ts +0 -32
- package/src/bridge/a2a/task.ts +9 -8
- package/src/bridge/sse/mapper.ts +8 -1
- package/src/constants/a2a/index.ts +2 -2
- package/src/contracts/api.ts +14 -30
- package/src/contracts/ids.ts +1 -1
- package/src/contracts/index.ts +3 -7
- package/src/contracts/schemas.ts +1 -8
- package/src/gateway/local.ts +6 -0
- package/src/index.ts +14 -4
- package/src/manager/agent/__tests__/lifecycle.test.ts +473 -0
- package/src/manager/agent/lifecycle.ts +515 -21
- package/src/manager/index.ts +3 -0
- package/src/manager/run/persistence.ts +26 -1
- package/src/manager/thread/__tests__/lifecycle.test.ts +286 -0
- package/src/manager/thread/lifecycle.ts +217 -0
- package/src/rag/retriever.ts +2 -2
- package/src/run/reporter.ts +28 -0
- package/src/runtime/query/__tests__/context.test.ts +102 -0
- package/src/runtime/query/context-cache.ts +4 -4
- package/src/runtime/query/context.ts +98 -9
- package/src/runtime/query/events.ts +8 -0
- package/src/runtime/query/index.ts +38 -1
- package/src/session/__tests__/integration/_fixtures.ts +310 -0
- package/src/session/__tests__/integration/archive-gate.test.ts +288 -0
- package/src/session/__tests__/integration/capacity-caps.test.ts +171 -0
- package/src/session/__tests__/integration/e2e-spawn.test.ts +296 -0
- package/src/session/__tests__/integration/event-stream-ordering.test.ts +410 -0
- package/src/session/__tests__/integration/handoff-broadcast-e2e.test.ts +271 -0
- package/src/session/__tests__/integration/handoff-illegal-transition.test.ts +214 -0
- package/src/session/__tests__/integration/handoff-single-e2e.test.ts +251 -0
- package/src/session/__tests__/integration/hierarchy-lifecycle.test.ts +240 -0
- package/src/session/__tests__/integration/migration-filesystem.test.ts +209 -0
- package/src/session/__tests__/integration/migration-id-prefix.test.ts +101 -0
- package/src/session/__tests__/integration/prev-artifact-dag.test.ts +325 -0
- package/src/session/__tests__/integration/retention-archive.test.ts +233 -0
- package/src/session/__tests__/integration/spawn-rollback.test.ts +313 -0
- package/src/session/__tests__/integration/summary-materialization-e2e.test.ts +239 -0
- package/src/session/__tests__/integration/tenant-isolation.test.ts +292 -0
- package/src/session/errors.ts +159 -0
- package/src/session/events/index.ts +16 -0
- package/src/session/events/schema-version.ts +13 -0
- package/src/session/events/types.ts +71 -0
- package/src/session/handoff/__tests__/broadcast.test.ts +378 -0
- package/src/session/handoff/__tests__/capacity.test.ts +129 -0
- package/src/session/handoff/__tests__/single.test.ts +333 -0
- package/src/session/handoff/assignment.ts +74 -0
- package/src/session/handoff/broadcast.ts +406 -0
- package/src/session/handoff/capacity.ts +121 -0
- package/src/session/handoff/events.ts +72 -0
- package/src/session/handoff/index.ts +29 -0
- package/src/session/handoff/single.ts +310 -0
- package/src/session/handoff/version.ts +59 -0
- package/src/session/hierarchy/__tests__/session.test.ts +100 -0
- package/src/session/hierarchy/actor.ts +17 -0
- package/src/session/hierarchy/index.ts +18 -0
- package/src/session/hierarchy/lineage.ts +15 -0
- package/src/session/hierarchy/project.ts +41 -0
- package/src/session/hierarchy/session.ts +109 -0
- package/src/session/hierarchy/sub-session.ts +92 -0
- package/src/session/hierarchy/tenant.ts +13 -0
- package/src/session/hierarchy/thread.ts +55 -0
- package/src/session/index.ts +15 -0
- package/src/session/intervention/__tests__/prev-artifact.test.ts +234 -0
- package/src/session/intervention/index.ts +16 -0
- package/src/session/intervention/prev-artifact.ts +180 -0
- package/src/session/migration/__tests__/filesystem.test.ts +263 -0
- package/src/session/migration/__tests__/id-prefix.test.ts +101 -0
- package/src/session/migration/__tests__/marker.test.ts +84 -0
- package/src/session/migration/errors.ts +23 -0
- package/src/session/migration/filesystem.ts +401 -0
- package/src/session/migration/id-prefix.ts +141 -0
- package/src/session/migration/index.ts +38 -0
- package/src/session/migration/marker.ts +131 -0
- package/src/session/retention/__tests__/archive.test.ts +318 -0
- package/src/session/retention/__tests__/disk-backend.test.ts +180 -0
- package/src/session/retention/archive-backend-ref.ts +17 -0
- package/src/session/retention/archive.ts +281 -0
- package/src/session/retention/backend.ts +107 -0
- package/src/session/retention/disk-backend.ts +304 -0
- package/src/session/retention/index.ts +16 -0
- package/src/session/retention/policy.ts +53 -0
- package/src/session/summary/__tests__/materialize.test.ts +343 -0
- package/src/session/summary/deliverable.ts +84 -0
- package/src/session/summary/index.ts +31 -0
- package/src/session/summary/materialize.ts +169 -0
- package/src/session/summary/ref.ts +104 -0
- package/src/session/workspace/__tests__/git-worktree.test.ts +258 -0
- package/src/session/workspace/__tests__/path-builder.test.ts +51 -0
- package/src/session/workspace/driver.ts +60 -0
- package/src/session/workspace/git-worktree.ts +209 -0
- package/src/session/workspace/index.ts +25 -0
- package/src/session/workspace/path-builder.ts +71 -0
- package/src/session/workspace/ref.ts +50 -0
- package/src/session/workspace/registry.ts +42 -0
- package/src/store/index.ts +0 -3
- package/src/store/session/__tests__/disk.test.ts +397 -0
- package/src/store/session/__tests__/memory.test.ts +402 -0
- package/src/store/session/disk.ts +976 -0
- package/src/store/session/index.ts +13 -0
- package/src/store/session/linkage.ts +80 -0
- package/src/store/session/memory.ts +412 -0
- package/src/store/session/messages.ts +21 -0
- package/src/store/thread/disk.ts +261 -0
- package/src/store/thread/index.ts +7 -0
- package/src/store/thread/memory.ts +104 -0
- package/src/types/agent/base.ts +27 -1
- package/src/types/agent/factory.ts +8 -3
- package/src/types/agent/task.ts +66 -2
- package/src/types/ids/index.ts +34 -3
- package/src/types/invocation/__tests__/state.test.ts +37 -29
- package/src/types/invocation/index.ts +26 -10
- package/src/types/rag/retrieval.ts +4 -3
- package/src/types/run/config.ts +13 -1
- package/src/types/run/events.ts +36 -1
- package/src/types/run/index.ts +8 -0
- package/src/types/run/metadata.ts +12 -2
- package/src/types/run/status.ts +33 -0
- package/src/types/session/ids.ts +23 -0
- package/src/types/session/index.ts +27 -0
- package/src/types/session/store.ts +252 -0
- package/src/types/thread/index.ts +5 -0
- package/src/types/thread/store.ts +92 -0
- package/src/utils/id.ts +34 -4
- package/dist/store/conversation/memory.d.ts +0 -21
- package/dist/store/conversation/memory.d.ts.map +0 -1
- package/dist/store/conversation/memory.js +0 -86
- package/dist/store/conversation/memory.js.map +0 -1
- package/dist/types/conversation/index.d.ts +0 -7
- package/dist/types/conversation/index.d.ts.map +0 -1
- package/dist/types/conversation/index.js +0 -2
- package/dist/types/conversation/index.js.map +0 -1
- package/src/store/conversation/memory.ts +0 -121
- package/src/types/conversation/index.ts +0 -8
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { AGENT_MANAGER_DEFAULTS } from '../../constants/agent/index.js'
|
|
2
2
|
import { EMPTY_TOKEN_USAGE } from '../../constants/limits.js'
|
|
3
3
|
import type { AgentRegistry } from '../../registry/agent/definitions.js'
|
|
4
|
+
import { RUN_EVENT_SCHEMA_VERSION } from '../../session/events/schema-version.js'
|
|
5
|
+
import {
|
|
6
|
+
type CapacityValidator,
|
|
7
|
+
DelegationCapacityExceeded,
|
|
8
|
+
} from '../../session/handoff/capacity.js'
|
|
9
|
+
import type { ActorRef } from '../../session/hierarchy/actor.js'
|
|
10
|
+
import type { Lineage } from '../../session/hierarchy/lineage.js'
|
|
11
|
+
import type { SessionSummaryMaterializer } from '../../session/summary/materialize.js'
|
|
12
|
+
import type { SessionSummaryOutcome } from '../../session/summary/ref.js'
|
|
13
|
+
import type { WorkspaceRef } from '../../session/workspace/ref.js'
|
|
14
|
+
import type { WorkspaceBackendRegistry } from '../../session/workspace/registry.js'
|
|
4
15
|
import type { BaseAgentConfig, BaseAgentResult } from '../../types/agent/base.js'
|
|
5
16
|
import type {
|
|
6
17
|
AgentLifecycleEvent,
|
|
@@ -14,33 +25,88 @@ import type {
|
|
|
14
25
|
SendMessageOptions,
|
|
15
26
|
} from '../../types/agent/task.js'
|
|
16
27
|
import { isTerminalAgentTaskState } from '../../types/agent/task.js'
|
|
17
|
-
import type { RunId, TaskId } from '../../types/ids/index.js'
|
|
28
|
+
import type { AgentId, RunId, SessionId, TaskId, TenantId } from '../../types/ids/index.js'
|
|
18
29
|
import type { Message } from '../../types/message/index.js'
|
|
30
|
+
import type { RunEvent, RunEventListener } from '../../types/run/events.js'
|
|
31
|
+
import type { SubSessionId } from '../../types/session/ids.js'
|
|
32
|
+
import type { SessionStore } from '../../types/session/store.js'
|
|
19
33
|
import { createChildAbortController } from '../../utils/abort.js'
|
|
20
34
|
import { ZERO_COST } from '../../utils/cost.js'
|
|
21
35
|
import { toErrorMessage } from '../../utils/error.js'
|
|
22
36
|
import { generateTaskId } from '../../utils/id.js'
|
|
23
37
|
import { type Logger, getRootLogger } from '../../utils/logger.js'
|
|
38
|
+
import type { ThreadManager } from '../thread/lifecycle.js'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Dependencies threaded into {@link AgentManager}. Phase 6 promoted the
|
|
42
|
+
* SubSession + Session + WorkspaceRef triple to mandatory spawn primitives —
|
|
43
|
+
* these collaborators replace the old `Object.assign({sourceAgentId,
|
|
44
|
+
* parentTaskId})` loose-cast cadence with a typed {@link Lineage} +
|
|
45
|
+
* {@link SessionSummaryMaterializer} closure of the parent→child message gap.
|
|
46
|
+
*
|
|
47
|
+
* Phase 9 Known Delta #5: fields are now unconditional required. The legacy
|
|
48
|
+
* "run without deps" compat branch was removed; every `AgentManager` consumer
|
|
49
|
+
* (SDK internals, `@namzu/agents`, `@namzu/api`, `@namzu/cli`) MUST wire the
|
|
50
|
+
* full set before instantiating. Convention #0 (no workarounds): the
|
|
51
|
+
* partially-wired mode was a migration-window bridge; 0.2.0 closes it.
|
|
52
|
+
*
|
|
53
|
+
* `workspaceRegistry` is required but may be empty — spawns without a
|
|
54
|
+
* registered workspace backend still succeed with `workspaceRef: undefined`
|
|
55
|
+
* (the runtime uses `.has(backend)` to gate provisioning). This keeps the
|
|
56
|
+
* registry deny-by-default while matching pattern doc §7.1 (lazy workspace
|
|
57
|
+
* provisioning).
|
|
58
|
+
*/
|
|
59
|
+
export interface AgentManagerDeps {
|
|
60
|
+
readonly sessionStore: SessionStore
|
|
61
|
+
readonly workspaceRegistry: WorkspaceBackendRegistry
|
|
62
|
+
readonly summaryMaterializer: SessionSummaryMaterializer
|
|
63
|
+
readonly capacity: CapacityValidator
|
|
64
|
+
/**
|
|
65
|
+
* Gate session creation on the parent Thread being `'open'` via
|
|
66
|
+
* {@link ThreadManager.requireOpen}. Added in Phase 2.6 to close the
|
|
67
|
+
* archive-gate gap flagged by the Phase 2.5 commit: without this,
|
|
68
|
+
* `ThreadManager.archive` was best-effort because spawn could still
|
|
69
|
+
* attach a live session under an archived Thread.
|
|
70
|
+
*/
|
|
71
|
+
readonly threadManager: ThreadManager
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface ChildSpawnRecord {
|
|
75
|
+
subSessionId: SubSessionId
|
|
76
|
+
childSessionId: SessionId
|
|
77
|
+
tenantId: TenantId
|
|
78
|
+
parentSessionId: SessionId
|
|
79
|
+
rootSessionId: SessionId
|
|
80
|
+
childDepth: number
|
|
81
|
+
workspaceRef?: WorkspaceRef
|
|
82
|
+
}
|
|
24
83
|
|
|
25
84
|
export class AgentManager {
|
|
26
85
|
private registry: AgentRegistry
|
|
27
86
|
private instances: Map<TaskId, AgentTask> = new Map()
|
|
87
|
+
private spawnRecords: Map<TaskId, ChildSpawnRecord> = new Map()
|
|
28
88
|
private completionCallbacks: Map<TaskId, Array<() => void>> = new Map()
|
|
29
89
|
private listeners: AgentLifecycleListener[] = []
|
|
30
90
|
private log: Logger
|
|
31
91
|
private config: Readonly<AgentManagerConfig>
|
|
32
92
|
private evictionTimers: Map<TaskId, ReturnType<typeof setTimeout>> = new Map()
|
|
93
|
+
private deps: AgentManagerDeps
|
|
33
94
|
|
|
34
|
-
constructor(
|
|
95
|
+
constructor(
|
|
96
|
+
registry: AgentRegistry,
|
|
97
|
+
config: Partial<AgentManagerConfig> | undefined,
|
|
98
|
+
deps: AgentManagerDeps,
|
|
99
|
+
) {
|
|
35
100
|
this.registry = registry
|
|
36
101
|
this.config = { ...AGENT_MANAGER_DEFAULTS, ...config }
|
|
37
102
|
this.log = getRootLogger().child({ component: 'AgentManager' })
|
|
103
|
+
this.deps = deps
|
|
38
104
|
}
|
|
39
105
|
|
|
40
106
|
async sendMessage(
|
|
41
107
|
options: SendMessageOptions,
|
|
42
108
|
context: AgentTaskContext,
|
|
43
|
-
listener?:
|
|
109
|
+
listener?: RunEventListener,
|
|
44
110
|
): Promise<AgentTask> {
|
|
45
111
|
if (context.depth >= this.config.maxDepth) {
|
|
46
112
|
throw new Error(
|
|
@@ -48,6 +114,12 @@ export class AgentManager {
|
|
|
48
114
|
)
|
|
49
115
|
}
|
|
50
116
|
|
|
117
|
+
if (options.tenantId !== context.tenantId) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Tenant mismatch: options.tenantId=${options.tenantId} differs from context.tenantId=${context.tenantId}. Cross-tenant spawn rejected (Convention #17).`,
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
51
123
|
const agent = this.registry.resolve(options.agentId)
|
|
52
124
|
|
|
53
125
|
const childAbortController = createChildAbortController(context.parentAbortController)
|
|
@@ -61,13 +133,40 @@ export class AgentManager {
|
|
|
61
133
|
)
|
|
62
134
|
context.budgetTracker.remaining -= allocatedTokens
|
|
63
135
|
|
|
136
|
+
// Phase 6: SubSession + child Session + WorkspaceRef triple. Happens
|
|
137
|
+
// before taskId minting so a capacity failure short-circuits cleanly
|
|
138
|
+
// with no observable state change.
|
|
139
|
+
const spawnRecord = await this.provisionSpawn(options, context)
|
|
140
|
+
|
|
64
141
|
const taskId = generateTaskId()
|
|
142
|
+
|
|
143
|
+
const childParentActor: ActorRef = {
|
|
144
|
+
kind: 'agent',
|
|
145
|
+
agentId: context.parentAgentId as AgentId,
|
|
146
|
+
tenantId: context.tenantId,
|
|
147
|
+
parentActor: context.parentActor,
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const childContext: AgentTaskContext = {
|
|
151
|
+
parentRunId: context.parentRunId,
|
|
152
|
+
parentAgentId: context.parentAgentId,
|
|
153
|
+
parentAbortController: context.parentAbortController,
|
|
154
|
+
depth: context.depth + 1,
|
|
155
|
+
budgetTracker: context.budgetTracker,
|
|
156
|
+
factoryOptions: context.factoryOptions,
|
|
157
|
+
tenantId: context.tenantId,
|
|
158
|
+
threadId: context.threadId,
|
|
159
|
+
sessionId: spawnRecord.childSessionId,
|
|
160
|
+
projectId: context.projectId,
|
|
161
|
+
parentActor: childParentActor,
|
|
162
|
+
}
|
|
163
|
+
|
|
65
164
|
const agentTask: AgentTask = {
|
|
66
165
|
taskId,
|
|
67
166
|
agentId: options.agentId,
|
|
68
167
|
agent,
|
|
69
168
|
childAbortController,
|
|
70
|
-
context,
|
|
169
|
+
context: childContext,
|
|
71
170
|
state: 'pending',
|
|
72
171
|
pendingMessages: [],
|
|
73
172
|
createdAt: Date.now(),
|
|
@@ -75,6 +174,7 @@ export class AgentManager {
|
|
|
75
174
|
}
|
|
76
175
|
|
|
77
176
|
this.instances.set(taskId, agentTask)
|
|
177
|
+
this.spawnRecords.set(taskId, spawnRecord)
|
|
78
178
|
this.emit({
|
|
79
179
|
type: 'pending',
|
|
80
180
|
taskId,
|
|
@@ -92,17 +192,37 @@ export class AgentManager {
|
|
|
92
192
|
childAgentId: options.agentId,
|
|
93
193
|
depth: context.depth,
|
|
94
194
|
})
|
|
195
|
+
|
|
196
|
+
const lineage: Lineage = {
|
|
197
|
+
parentSessionId: spawnRecord.parentSessionId,
|
|
198
|
+
rootSessionId: spawnRecord.rootSessionId,
|
|
199
|
+
depth: spawnRecord.childDepth,
|
|
200
|
+
}
|
|
201
|
+
listener({
|
|
202
|
+
type: 'subsession_spawned',
|
|
203
|
+
runId: context.parentRunId,
|
|
204
|
+
subSessionId: spawnRecord.subSessionId,
|
|
205
|
+
parentSessionId: spawnRecord.parentSessionId,
|
|
206
|
+
spawnedBy: context.parentActor,
|
|
207
|
+
lineage,
|
|
208
|
+
schemaVersion: RUN_EVENT_SCHEMA_VERSION,
|
|
209
|
+
at: new Date(),
|
|
210
|
+
})
|
|
95
211
|
}
|
|
96
212
|
this.log.info(`Agent task pending: ${taskId} (${options.agentId}, depth=${context.depth})`)
|
|
97
213
|
|
|
98
214
|
const definition = this.registry.getOrThrow(options.agentId)
|
|
99
215
|
let childConfig: BaseAgentConfig
|
|
100
|
-
if (definition.configBuilder
|
|
216
|
+
if (definition.configBuilder) {
|
|
217
|
+
// Call the configBuilder regardless of whether factoryOptions were
|
|
218
|
+
// supplied. BYO-provider flows (Bedrock IAM, custom ProviderRegistry)
|
|
219
|
+
// commonly omit factoryOptions because the provider resolves its own
|
|
220
|
+
// credentials; the builder still needs to run to wire provider+tools.
|
|
221
|
+
// Defaults: empty factoryOptions when omitted; configOverrides win.
|
|
101
222
|
childConfig = await definition.configBuilder({
|
|
102
|
-
...context.factoryOptions,
|
|
223
|
+
...(context.factoryOptions ?? {}),
|
|
103
224
|
tokenBudget: allocatedTokens,
|
|
104
225
|
timeoutMs: options.budgetAllocation?.timeoutMs ?? context.budgetTracker.remaining,
|
|
105
|
-
threadId: context.threadId as string | undefined,
|
|
106
226
|
parentRunId: context.parentRunId as string | undefined,
|
|
107
227
|
depth: context.depth + 1,
|
|
108
228
|
...options.configOverrides,
|
|
@@ -111,8 +231,16 @@ export class AgentManager {
|
|
|
111
231
|
if (!childConfig.contextLevel && definition.contextLevel) {
|
|
112
232
|
childConfig.contextLevel = definition.contextLevel
|
|
113
233
|
}
|
|
234
|
+
|
|
235
|
+
// Propagate session-hierarchy scoping onto the child config. The
|
|
236
|
+
// configBuilder may not have been updated to emit these yet; we
|
|
237
|
+
// stamp them here so query() sees them regardless.
|
|
238
|
+
childConfig.sessionId = spawnRecord?.childSessionId ?? context.sessionId
|
|
239
|
+
childConfig.threadId = context.threadId
|
|
240
|
+
childConfig.projectId = context.projectId
|
|
241
|
+
childConfig.tenantId = context.tenantId
|
|
114
242
|
} else {
|
|
115
|
-
this.log.warn('No configBuilder
|
|
243
|
+
this.log.warn('No configBuilder, using bare config', {
|
|
116
244
|
agentId: options.agentId,
|
|
117
245
|
})
|
|
118
246
|
childConfig = {
|
|
@@ -123,7 +251,10 @@ export class AgentManager {
|
|
|
123
251
|
maxIterations: options.configOverrides?.maxIterations,
|
|
124
252
|
maxResponseTokens: options.configOverrides?.maxResponseTokens,
|
|
125
253
|
env: options.configOverrides?.env,
|
|
254
|
+
sessionId: spawnRecord.childSessionId,
|
|
126
255
|
threadId: context.threadId,
|
|
256
|
+
projectId: context.projectId,
|
|
257
|
+
tenantId: context.tenantId,
|
|
127
258
|
parentRunId: context.parentRunId,
|
|
128
259
|
depth: context.depth + 1,
|
|
129
260
|
}
|
|
@@ -193,6 +324,10 @@ export class AgentManager {
|
|
|
193
324
|
return this.instances.get(taskId)
|
|
194
325
|
}
|
|
195
326
|
|
|
327
|
+
getSpawnRecord(taskId: TaskId): ChildSpawnRecord | undefined {
|
|
328
|
+
return this.spawnRecords.get(taskId)
|
|
329
|
+
}
|
|
330
|
+
|
|
196
331
|
listByParent(parentRunId: RunId): AgentTask[] {
|
|
197
332
|
return Array.from(this.instances.values()).filter((t) => t.context.parentRunId === parentRunId)
|
|
198
333
|
}
|
|
@@ -223,6 +358,7 @@ export class AgentManager {
|
|
|
223
358
|
if (isTerminalAgentTaskState(agentTask.state)) {
|
|
224
359
|
this.clearEvictionTimer(taskId)
|
|
225
360
|
this.instances.delete(taskId)
|
|
361
|
+
this.spawnRecords.delete(taskId)
|
|
226
362
|
}
|
|
227
363
|
}
|
|
228
364
|
}
|
|
@@ -233,14 +369,174 @@ export class AgentManager {
|
|
|
233
369
|
}
|
|
234
370
|
this.cancelAll('' as RunId)
|
|
235
371
|
this.instances.clear()
|
|
372
|
+
this.spawnRecords.clear()
|
|
236
373
|
this.listeners.length = 0
|
|
237
374
|
}
|
|
238
375
|
|
|
376
|
+
private async provisionSpawn(
|
|
377
|
+
options: SendMessageOptions,
|
|
378
|
+
context: AgentTaskContext,
|
|
379
|
+
): Promise<ChildSpawnRecord> {
|
|
380
|
+
// Phase 9: deps are unconditional required. Every spawn produces a
|
|
381
|
+
// SubSession + Session + WorkspaceRef triple (Convention #0: no
|
|
382
|
+
// partial/legacy path).
|
|
383
|
+
const store = this.deps.sessionStore
|
|
384
|
+
|
|
385
|
+
// Thread archive gate — runs FIRST so an archived thread fails fastest
|
|
386
|
+
// with the correct error (not DelegationCapacityExceeded or a project
|
|
387
|
+
// lookup error). Phase 2.6 closes the gap the Phase 2.5 commit
|
|
388
|
+
// flagged: without it, `ThreadManager.archive` could be undermined by
|
|
389
|
+
// a concurrent spawn landing a live session post-archival.
|
|
390
|
+
// Scope: this gate enforces the archive invariant at the production
|
|
391
|
+
// ingress path (AgentManager.sendMessage + handoff flows). Direct
|
|
392
|
+
// callers of `SessionStore.createSession` bypass it — the store layer
|
|
393
|
+
// is intentionally unaware of thread status to preserve its
|
|
394
|
+
// single-responsibility boundary.
|
|
395
|
+
await this.deps.threadManager.requireOpen(context.threadId, context.tenantId)
|
|
396
|
+
|
|
397
|
+
// Parent session cross-check: validate that `options.parentSessionId`
|
|
398
|
+
// exists for this tenant AND lives under the same thread as the
|
|
399
|
+
// context. A mismatched `context.threadId` would otherwise attach the
|
|
400
|
+
// child's sub-session edge to a parent in a different thread —
|
|
401
|
+
// corrupting the hierarchy invariant (cross-thread spawn is forbidden
|
|
402
|
+
// by design). Mirrors the `source.threadId === assignment.threadId`
|
|
403
|
+
// check in handoff (Phase 2.4).
|
|
404
|
+
const parentSession = await store.getSession(options.parentSessionId, context.tenantId)
|
|
405
|
+
if (!parentSession) {
|
|
406
|
+
throw new Error(
|
|
407
|
+
`Parent session ${options.parentSessionId} not found for tenant ${context.tenantId} — spawn rejected`,
|
|
408
|
+
)
|
|
409
|
+
}
|
|
410
|
+
if (parentSession.threadId !== context.threadId) {
|
|
411
|
+
throw new Error(
|
|
412
|
+
`Thread mismatch on spawn: parent session ${parentSession.id} is on thread ${parentSession.threadId}, but context.threadId=${context.threadId}. Cross-thread spawn is forbidden (session-hierarchy.md §6.3).`,
|
|
413
|
+
)
|
|
414
|
+
}
|
|
415
|
+
if (parentSession.projectId !== context.projectId) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
`Project mismatch on spawn: parent session ${parentSession.id} is on project ${parentSession.projectId}, but context.projectId=${context.projectId}.`,
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const project = await store.getProject(context.projectId, context.tenantId)
|
|
422
|
+
if (!project) {
|
|
423
|
+
throw new Error(
|
|
424
|
+
`Project ${context.projectId} not found for tenant ${context.tenantId} — spawn rejected`,
|
|
425
|
+
)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Capacity: depth + width. Depth uses the parent session's ancestry
|
|
429
|
+
// chain; width counts existing direct children of the parent.
|
|
430
|
+
await this.deps.capacity.validateDepth(
|
|
431
|
+
options.parentSessionId,
|
|
432
|
+
project.config.maxDelegationDepth,
|
|
433
|
+
context.tenantId,
|
|
434
|
+
)
|
|
435
|
+
await this.deps.capacity.validateWidth(
|
|
436
|
+
options.parentSessionId,
|
|
437
|
+
1,
|
|
438
|
+
project.config.maxDelegationWidth,
|
|
439
|
+
context.tenantId,
|
|
440
|
+
)
|
|
441
|
+
|
|
442
|
+
// Ancestry walk gives both the child depth and the root session id
|
|
443
|
+
// attached to every sub-session event from here down.
|
|
444
|
+
const parentAncestry = await store.getAncestry(options.parentSessionId, context.tenantId)
|
|
445
|
+
const rootSessionId = parentAncestry[0] ?? options.parentSessionId
|
|
446
|
+
const childDepth = parentAncestry.length
|
|
447
|
+
|
|
448
|
+
const childActor: ActorRef = {
|
|
449
|
+
kind: 'agent',
|
|
450
|
+
agentId: options.agentId as AgentId,
|
|
451
|
+
tenantId: context.tenantId,
|
|
452
|
+
parentActor: context.parentActor,
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Child session inherits the parent's threadId verbatim (cross-thread
|
|
456
|
+
// spawn is forbidden by design — a delegated sub-agent stays on the
|
|
457
|
+
// same topic). Phase 2.6 elides the previous parent-session read by
|
|
458
|
+
// carrying `threadId` on `AgentTaskContext`.
|
|
459
|
+
const childSession = await store.createSession(
|
|
460
|
+
{
|
|
461
|
+
threadId: context.threadId,
|
|
462
|
+
projectId: context.projectId,
|
|
463
|
+
currentActor: childActor,
|
|
464
|
+
},
|
|
465
|
+
context.tenantId,
|
|
466
|
+
)
|
|
467
|
+
|
|
468
|
+
// Compensating rollback wraps every mutation after createSession so a
|
|
469
|
+
// mid-flight failure (status flip, subsession insert, workspace driver)
|
|
470
|
+
// leaves no orphan child session. Codex SPAWN-ROLLBACK critique (Phase
|
|
471
|
+
// 2 review, 2026-04-18): without this, `workspaceRegistry.get().create`
|
|
472
|
+
// throwing — or a concurrent `updateSession` race — strands an
|
|
473
|
+
// `active` child session with no subsession edge, invisible to the
|
|
474
|
+
// parent but counted against `maxDelegationWidth`.
|
|
475
|
+
let subSession: Awaited<ReturnType<typeof store.createSubSession>> | undefined
|
|
476
|
+
let workspaceRef: WorkspaceRef | undefined
|
|
477
|
+
try {
|
|
478
|
+
// Flip to 'active' so the materializer's atomic write + status flip
|
|
479
|
+
// lands on terminal — §5.3: pending→active→idle.
|
|
480
|
+
await store.updateSession({ ...childSession, status: 'active' }, context.tenantId)
|
|
481
|
+
|
|
482
|
+
subSession = await store.createSubSession(
|
|
483
|
+
{
|
|
484
|
+
parentSessionId: options.parentSessionId,
|
|
485
|
+
childSessionId: childSession.id,
|
|
486
|
+
kind: 'agent_spawn',
|
|
487
|
+
spawnedBy: context.parentActor,
|
|
488
|
+
failureMode: 'delegate',
|
|
489
|
+
completionMode: 'summary_ref',
|
|
490
|
+
},
|
|
491
|
+
context.tenantId,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
// Workspace provisioning — best-effort. When the requested backend
|
|
495
|
+
// is registered we create a new workspace for the child; failures
|
|
496
|
+
// surface as WorkspaceBackendError and abort the spawn (Convention
|
|
497
|
+
// #0: no silent fallback). Pattern doc §7.1 allows lazy
|
|
498
|
+
// provisioning: an unregistered backend leaves `workspaceRef:
|
|
499
|
+
// undefined` on the spawn record, not a hard error — the registry
|
|
500
|
+
// is the capability surface.
|
|
501
|
+
const backend = options.workspaceBackend ?? 'git-worktree'
|
|
502
|
+
if (this.deps.workspaceRegistry.has(backend)) {
|
|
503
|
+
const driver = this.deps.workspaceRegistry.get(backend)
|
|
504
|
+
workspaceRef = await driver.create({ label: subSession.id })
|
|
505
|
+
}
|
|
506
|
+
} catch (err) {
|
|
507
|
+
// Compensating rollback order is mandated by the store's
|
|
508
|
+
// deny-by-default cascade policy (Convention #5): `deleteSession`
|
|
509
|
+
// throws when any subsession still references it, so the subsession
|
|
510
|
+
// record must be removed first. No failed-subsession audit row is
|
|
511
|
+
// kept — the `subsession_spawned` run event never fired (we aborted
|
|
512
|
+
// before `buildSpawnRecord`), so no observer is expecting one, and
|
|
513
|
+
// leaving a `status: 'failed'` breadcrumb would be a dangling
|
|
514
|
+
// record with no corresponding emission. The original `err` is the
|
|
515
|
+
// caller-visible signal; cleanup errors are swallowed so they
|
|
516
|
+
// cannot mask it.
|
|
517
|
+
if (subSession !== undefined) {
|
|
518
|
+
await store.deleteSubSession(subSession.id, context.tenantId).catch(() => undefined)
|
|
519
|
+
}
|
|
520
|
+
await store.deleteSession(childSession.id, context.tenantId).catch(() => undefined)
|
|
521
|
+
throw err
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
return {
|
|
525
|
+
subSessionId: subSession.id,
|
|
526
|
+
childSessionId: childSession.id,
|
|
527
|
+
tenantId: context.tenantId,
|
|
528
|
+
parentSessionId: options.parentSessionId,
|
|
529
|
+
rootSessionId,
|
|
530
|
+
childDepth,
|
|
531
|
+
workspaceRef,
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
239
535
|
private async runChild(
|
|
240
536
|
agentTask: AgentTask,
|
|
241
537
|
options: SendMessageOptions,
|
|
242
538
|
childConfig: BaseAgentConfig,
|
|
243
|
-
listener?:
|
|
539
|
+
listener?: RunEventListener,
|
|
244
540
|
): Promise<void> {
|
|
245
541
|
this.updateState(agentTask.taskId, 'running')
|
|
246
542
|
this.emit({ type: 'running', taskId: agentTask.taskId })
|
|
@@ -250,17 +546,135 @@ export class AgentManager {
|
|
|
250
546
|
signal: agentTask.childAbortController.signal,
|
|
251
547
|
}
|
|
252
548
|
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
549
|
+
const spawnRecord = this.spawnRecords.get(agentTask.taskId)
|
|
550
|
+
const childListener = this.wrapChildListener(listener, spawnRecord)
|
|
551
|
+
|
|
552
|
+
const result = await agentTask.agent.run(input, childConfig, childListener)
|
|
553
|
+
await this.finalizeChild(agentTask, result)
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Wraps the parent listener so every event emitted from the child's run
|
|
558
|
+
* carries the session-hierarchy `lineage` + `schemaVersion: 2` stamp.
|
|
559
|
+
* Replaces the old `Object.assign({sourceAgentId, parentTaskId}, event)`
|
|
560
|
+
* loose-cast pattern entirely — the types now encode the linkage.
|
|
561
|
+
*/
|
|
562
|
+
private wrapChildListener(
|
|
563
|
+
listener: RunEventListener | undefined,
|
|
564
|
+
spawnRecord: ChildSpawnRecord | undefined,
|
|
565
|
+
): RunEventListener | undefined {
|
|
566
|
+
if (!listener) return undefined
|
|
567
|
+
if (!spawnRecord) return listener
|
|
568
|
+
|
|
569
|
+
const lineage: Lineage = {
|
|
570
|
+
parentSessionId: spawnRecord.parentSessionId,
|
|
571
|
+
rootSessionId: spawnRecord.rootSessionId,
|
|
572
|
+
depth: spawnRecord.childDepth,
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return async (event: RunEvent): Promise<void> => {
|
|
576
|
+
const stamped: RunEvent = {
|
|
577
|
+
...(event as RunEvent),
|
|
578
|
+
lineage,
|
|
579
|
+
schemaVersion: RUN_EVENT_SCHEMA_VERSION,
|
|
580
|
+
} as RunEvent
|
|
581
|
+
await listener(stamped)
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
private async finalizeChild(agentTask: AgentTask, result: BaseAgentResult): Promise<void> {
|
|
586
|
+
const spawnRecord = this.spawnRecords.get(agentTask.taskId)
|
|
587
|
+
|
|
588
|
+
// Kernel terminalization (§8.1): Materializer seals the summary and
|
|
589
|
+
// atomically flips the child session active→idle. Only run when the
|
|
590
|
+
// child actually succeeded; failed sub-sessions skip materialization
|
|
591
|
+
// and transition the sub-session record to 'failed' (§5.5).
|
|
592
|
+
if (spawnRecord) {
|
|
593
|
+
const store = this.deps.sessionStore
|
|
594
|
+
try {
|
|
595
|
+
if (result.status === 'completed') {
|
|
596
|
+
const outcome: SessionSummaryOutcome = deriveOutcome(result)
|
|
597
|
+
const agentSummary = deriveAgentSummary(result)
|
|
598
|
+
const summary = await this.deps.summaryMaterializer.materialize({
|
|
599
|
+
sessionId: spawnRecord.childSessionId,
|
|
600
|
+
tenantId: spawnRecord.tenantId,
|
|
601
|
+
finalOutcome: outcome,
|
|
602
|
+
agentSummary,
|
|
603
|
+
declaredDeliverables: [],
|
|
604
|
+
keyDecisions: [],
|
|
258
605
|
})
|
|
259
|
-
|
|
606
|
+
|
|
607
|
+
const subSession = await store.getSubSession(
|
|
608
|
+
spawnRecord.subSessionId,
|
|
609
|
+
spawnRecord.tenantId,
|
|
610
|
+
)
|
|
611
|
+
if (subSession) {
|
|
612
|
+
await store.updateSubSession(
|
|
613
|
+
{ ...subSession, status: 'idle', summaryRef: summary.id },
|
|
614
|
+
spawnRecord.tenantId,
|
|
615
|
+
)
|
|
616
|
+
}
|
|
617
|
+
} else {
|
|
618
|
+
// Non-success: mark sub-session failed and, when we own a
|
|
619
|
+
// workspace, dispose it. Dispose errors are logged but not
|
|
620
|
+
// propagated — the sub-session state is already persisted.
|
|
621
|
+
const subSession = await store.getSubSession(
|
|
622
|
+
spawnRecord.subSessionId,
|
|
623
|
+
spawnRecord.tenantId,
|
|
624
|
+
)
|
|
625
|
+
if (subSession) {
|
|
626
|
+
await store.updateSubSession({ ...subSession, status: 'failed' }, spawnRecord.tenantId)
|
|
627
|
+
}
|
|
628
|
+
if (spawnRecord.workspaceRef) {
|
|
629
|
+
const backend = spawnRecord.workspaceRef.meta.backend
|
|
630
|
+
if (this.deps.workspaceRegistry.has(backend)) {
|
|
631
|
+
await this.deps.workspaceRegistry
|
|
632
|
+
.get(backend)
|
|
633
|
+
.dispose(spawnRecord.workspaceRef)
|
|
634
|
+
.catch((disposeErr) => {
|
|
635
|
+
this.log.warn('Workspace dispose failed', {
|
|
636
|
+
backend,
|
|
637
|
+
error: toErrorMessage(disposeErr),
|
|
638
|
+
})
|
|
639
|
+
})
|
|
640
|
+
}
|
|
641
|
+
}
|
|
260
642
|
}
|
|
261
|
-
|
|
643
|
+
} catch (err) {
|
|
644
|
+
this.log.error('Sub-session finalization failed', {
|
|
645
|
+
taskId: agentTask.taskId,
|
|
646
|
+
error: toErrorMessage(err),
|
|
647
|
+
})
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// Emit subsession_idled event on success before marking the task
|
|
652
|
+
// completed — consumers expect the ordering `run_completed (child) →
|
|
653
|
+
// subsession_idled → run_completed (parent)` per §10.5.
|
|
654
|
+
if (spawnRecord && agentTask.runEventListener && result.status === 'completed') {
|
|
655
|
+
const lineage: Lineage = {
|
|
656
|
+
parentSessionId: spawnRecord.parentSessionId,
|
|
657
|
+
rootSessionId: spawnRecord.rootSessionId,
|
|
658
|
+
depth: spawnRecord.childDepth,
|
|
659
|
+
}
|
|
660
|
+
try {
|
|
661
|
+
await agentTask.runEventListener({
|
|
662
|
+
type: 'subsession_idled',
|
|
663
|
+
runId: agentTask.context.parentRunId,
|
|
664
|
+
subSessionId: spawnRecord.subSessionId,
|
|
665
|
+
parentSessionId: spawnRecord.parentSessionId,
|
|
666
|
+
lineage,
|
|
667
|
+
schemaVersion: RUN_EVENT_SCHEMA_VERSION,
|
|
668
|
+
at: new Date(),
|
|
669
|
+
})
|
|
670
|
+
} catch (err) {
|
|
671
|
+
this.log.error('subsession_idled emission error', {
|
|
672
|
+
taskId: agentTask.taskId,
|
|
673
|
+
error: toErrorMessage(err),
|
|
674
|
+
})
|
|
675
|
+
}
|
|
676
|
+
}
|
|
262
677
|
|
|
263
|
-
const result = await agentTask.agent.run(input, childConfig, childListener)
|
|
264
678
|
this.markCompleted(agentTask.taskId, result)
|
|
265
679
|
}
|
|
266
680
|
|
|
@@ -307,10 +721,45 @@ export class AgentManager {
|
|
|
307
721
|
error,
|
|
308
722
|
})
|
|
309
723
|
this.log.error(`Agent task failed: ${taskId}`, { error })
|
|
724
|
+
|
|
725
|
+
// Best-effort: mark sub-session failed + dispose workspace. The result
|
|
726
|
+
// emission path already synthesized a failure result above.
|
|
727
|
+
const spawnRecord = this.spawnRecords.get(taskId)
|
|
728
|
+
if (spawnRecord) {
|
|
729
|
+
this.failSubSession(spawnRecord).catch((err) => {
|
|
730
|
+
this.log.warn('SubSession failure update failed', {
|
|
731
|
+
taskId,
|
|
732
|
+
error: toErrorMessage(err),
|
|
733
|
+
})
|
|
734
|
+
})
|
|
735
|
+
}
|
|
736
|
+
|
|
310
737
|
this.scheduleEviction(taskId)
|
|
311
738
|
this.resolveCompletionCallbacks(taskId)
|
|
312
739
|
}
|
|
313
740
|
|
|
741
|
+
private async failSubSession(spawnRecord: ChildSpawnRecord): Promise<void> {
|
|
742
|
+
const subSession = await this.deps.sessionStore.getSubSession(
|
|
743
|
+
spawnRecord.subSessionId,
|
|
744
|
+
spawnRecord.tenantId,
|
|
745
|
+
)
|
|
746
|
+
if (subSession && subSession.status !== 'failed') {
|
|
747
|
+
await this.deps.sessionStore.updateSubSession(
|
|
748
|
+
{ ...subSession, status: 'failed' },
|
|
749
|
+
spawnRecord.tenantId,
|
|
750
|
+
)
|
|
751
|
+
}
|
|
752
|
+
if (spawnRecord.workspaceRef) {
|
|
753
|
+
const backend = spawnRecord.workspaceRef.meta.backend
|
|
754
|
+
if (this.deps.workspaceRegistry.has(backend)) {
|
|
755
|
+
await this.deps.workspaceRegistry
|
|
756
|
+
.get(backend)
|
|
757
|
+
.dispose(spawnRecord.workspaceRef)
|
|
758
|
+
.catch(() => undefined)
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
314
763
|
private markCanceled(taskId: TaskId): void {
|
|
315
764
|
const agentTask = this.instances.get(taskId)
|
|
316
765
|
if (!agentTask || isTerminalAgentTaskState(agentTask.state)) return
|
|
@@ -351,6 +800,7 @@ export class AgentManager {
|
|
|
351
800
|
|
|
352
801
|
const timer = setTimeout(() => {
|
|
353
802
|
this.instances.delete(taskId)
|
|
803
|
+
this.spawnRecords.delete(taskId)
|
|
354
804
|
this.evictionTimers.delete(taskId)
|
|
355
805
|
this.log.info(`Agent task evicted: ${taskId}`)
|
|
356
806
|
}, this.config.evictionMs)
|
|
@@ -387,10 +837,7 @@ export class AgentManager {
|
|
|
387
837
|
}
|
|
388
838
|
}
|
|
389
839
|
|
|
390
|
-
private emitRunEvent(
|
|
391
|
-
agentTask: AgentTask,
|
|
392
|
-
event: import('../../types/run/events.js').RunEvent,
|
|
393
|
-
): void {
|
|
840
|
+
private emitRunEvent(agentTask: AgentTask, event: RunEvent): void {
|
|
394
841
|
if (!agentTask.runEventListener) return
|
|
395
842
|
try {
|
|
396
843
|
agentTask.runEventListener(event)
|
|
@@ -403,3 +850,50 @@ export class AgentManager {
|
|
|
403
850
|
}
|
|
404
851
|
}
|
|
405
852
|
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* Maps a {@link BaseAgentResult} to {@link SessionSummaryOutcome}. Phase 6
|
|
856
|
+
* INTERPRETATION: `completed` → `succeeded`; any other status → `failed`.
|
|
857
|
+
* A dedicated `partial` signal requires structured-output contracts on the
|
|
858
|
+
* child's terminal turn (§8.1) which lands in a later phase.
|
|
859
|
+
*/
|
|
860
|
+
function deriveOutcome(result: BaseAgentResult): SessionSummaryOutcome {
|
|
861
|
+
if (result.status === 'completed') {
|
|
862
|
+
return { status: 'succeeded' }
|
|
863
|
+
}
|
|
864
|
+
const verdict = result.lastError ?? String(result.status)
|
|
865
|
+
return { status: 'failed', verdict }
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
const SUMMARY_FALLBACK_MAX_CHARS = 4000
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Pulls the agent's own narration from the final assistant message. §8.1:
|
|
872
|
+
* agents may register a structured-output contract for this; when absent
|
|
873
|
+
* we fall back to the last text block. Bounded by the summary char cap so
|
|
874
|
+
* the materializer never rejects on length at this seam.
|
|
875
|
+
*/
|
|
876
|
+
function deriveAgentSummary(result: BaseAgentResult): string {
|
|
877
|
+
const fromResult = result.result?.trim()
|
|
878
|
+
if (fromResult) {
|
|
879
|
+
return fromResult.length > SUMMARY_FALLBACK_MAX_CHARS
|
|
880
|
+
? fromResult.slice(0, SUMMARY_FALLBACK_MAX_CHARS)
|
|
881
|
+
: fromResult
|
|
882
|
+
}
|
|
883
|
+
for (let i = result.messages.length - 1; i >= 0; i--) {
|
|
884
|
+
const msg = result.messages[i]
|
|
885
|
+
if (msg?.role === 'assistant') {
|
|
886
|
+
const content = typeof msg.content === 'string' ? msg.content : ''
|
|
887
|
+
if (content.trim().length > 0) {
|
|
888
|
+
return content.length > SUMMARY_FALLBACK_MAX_CHARS
|
|
889
|
+
? content.slice(0, SUMMARY_FALLBACK_MAX_CHARS)
|
|
890
|
+
: content
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
return ''
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// Re-export the capacity-violation type so downstream consumers that import
|
|
898
|
+
// via the AgentManager module surface don't reach into session/handoff/.
|
|
899
|
+
export { DelegationCapacityExceeded }
|
package/src/manager/index.ts
CHANGED
|
@@ -16,4 +16,7 @@ export type {
|
|
|
16
16
|
export { PlanManager } from './plan/lifecycle.js'
|
|
17
17
|
export type { PlanEvent, PlanEventListener, PlanApprovalHandler } from './plan/lifecycle.js'
|
|
18
18
|
|
|
19
|
+
export { ThreadManager } from './thread/lifecycle.js'
|
|
20
|
+
export type { ThreadManagerDeps } from './thread/lifecycle.js'
|
|
21
|
+
|
|
19
22
|
export { AgentManager } from './agent/lifecycle.js'
|