macro-agent 0.2.4 → 0.2.6
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/LICENSE +1 -1
- package/README.md +30 -56
- package/dist/acp/websocket-server.d.ts +6 -0
- package/dist/acp/websocket-server.d.ts.map +1 -1
- package/dist/acp/websocket-server.js +13 -0
- package/dist/acp/websocket-server.js.map +1 -1
- package/dist/acp/websocket-stream.d.ts +30 -0
- package/dist/acp/websocket-stream.d.ts.map +1 -0
- package/dist/acp/websocket-stream.js +118 -0
- package/dist/acp/websocket-stream.js.map +1 -0
- package/dist/activity/deduplication.d.ts +85 -0
- package/dist/activity/deduplication.d.ts.map +1 -0
- package/dist/activity/deduplication.js +149 -0
- package/dist/activity/deduplication.js.map +1 -0
- package/dist/activity/index.d.ts +16 -0
- package/dist/activity/index.d.ts.map +1 -0
- package/dist/activity/index.js +17 -0
- package/dist/activity/index.js.map +1 -0
- package/dist/activity/relevance.d.ts +81 -0
- package/dist/activity/relevance.d.ts.map +1 -0
- package/dist/activity/relevance.js +161 -0
- package/dist/activity/relevance.js.map +1 -0
- package/dist/activity/types.d.ts +169 -0
- package/dist/activity/types.d.ts.map +1 -0
- package/dist/activity/types.js +33 -0
- package/dist/activity/types.js.map +1 -0
- package/dist/activity/watcher.d.ts +64 -0
- package/dist/activity/watcher.d.ts.map +1 -0
- package/dist/activity/watcher.js +212 -0
- package/dist/activity/watcher.js.map +1 -0
- package/dist/adapters/federation.d.ts +8 -1
- package/dist/adapters/federation.d.ts.map +1 -1
- package/dist/adapters/federation.js +33 -2
- package/dist/adapters/federation.js.map +1 -1
- package/dist/agent/agent-manager-v2.d.ts.map +1 -1
- package/dist/agent/agent-manager-v2.js +189 -67
- package/dist/agent/agent-manager-v2.js.map +1 -1
- package/dist/agent/agent-manager.d.ts +17 -0
- package/dist/agent/agent-manager.d.ts.map +1 -1
- package/dist/agent/agent-manager.js.map +1 -1
- package/dist/agent/types.d.ts +21 -2
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/agent/wake.d.ts +85 -0
- package/dist/agent/wake.d.ts.map +1 -0
- package/dist/agent/wake.js +278 -0
- package/dist/agent/wake.js.map +1 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +41 -25
- package/dist/api/server.js.map +1 -1
- package/dist/api/types.d.ts +6 -0
- package/dist/api/types.d.ts.map +1 -1
- package/dist/auth/server-auth.d.ts +43 -0
- package/dist/auth/server-auth.d.ts.map +1 -0
- package/dist/auth/server-auth.js +80 -0
- package/dist/auth/server-auth.js.map +1 -0
- package/dist/auth/token.d.ts +4 -0
- package/dist/auth/token.d.ts.map +1 -1
- package/dist/auth/token.js +7 -6
- package/dist/auth/token.js.map +1 -1
- package/dist/boot-v2.d.ts +6 -3
- package/dist/boot-v2.d.ts.map +1 -1
- package/dist/boot-v2.js +44 -25
- package/dist/boot-v2.js.map +1 -1
- package/dist/cognitive/macro-agent-backend.d.ts.map +1 -1
- package/dist/cognitive/macro-agent-backend.js +37 -8
- package/dist/cognitive/macro-agent-backend.js.map +1 -1
- package/dist/cognitive/team-lifecycle.d.ts +82 -0
- package/dist/cognitive/team-lifecycle.d.ts.map +1 -0
- package/dist/cognitive/team-lifecycle.js +121 -0
- package/dist/cognitive/team-lifecycle.js.map +1 -0
- package/dist/cognitive/trajectory-extractor.d.ts +25 -0
- package/dist/cognitive/trajectory-extractor.d.ts.map +1 -0
- package/dist/cognitive/trajectory-extractor.js +134 -0
- package/dist/cognitive/trajectory-extractor.js.map +1 -0
- package/dist/cognitive/types.d.ts +24 -0
- package/dist/cognitive/types.d.ts.map +1 -1
- package/dist/control/control-server.d.ts.map +1 -1
- package/dist/control/control-server.js +10 -0
- package/dist/control/control-server.js.map +1 -1
- package/dist/dispatch/mail-inbound-consumer.d.ts.map +1 -1
- package/dist/dispatch/mail-inbound-consumer.js +43 -10
- package/dist/dispatch/mail-inbound-consumer.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/lifecycle/handlers/generic.d.ts +27 -0
- package/dist/lifecycle/handlers/generic.d.ts.map +1 -0
- package/dist/lifecycle/handlers/generic.js +56 -0
- package/dist/lifecycle/handlers/generic.js.map +1 -0
- package/dist/lifecycle/handlers/index.d.ts +51 -0
- package/dist/lifecycle/handlers/index.d.ts.map +1 -0
- package/dist/lifecycle/handlers/index.js +110 -0
- package/dist/lifecycle/handlers/index.js.map +1 -0
- package/dist/lifecycle/handlers/integrator.d.ts +81 -0
- package/dist/lifecycle/handlers/integrator.d.ts.map +1 -0
- package/dist/lifecycle/handlers/integrator.js +451 -0
- package/dist/lifecycle/handlers/integrator.js.map +1 -0
- package/dist/lifecycle/handlers/monitor.d.ts +29 -0
- package/dist/lifecycle/handlers/monitor.d.ts.map +1 -0
- package/dist/lifecycle/handlers/monitor.js +79 -0
- package/dist/lifecycle/handlers/monitor.js.map +1 -0
- package/dist/lifecycle/handlers/worker.d.ts +56 -0
- package/dist/lifecycle/handlers/worker.d.ts.map +1 -0
- package/dist/lifecycle/handlers/worker.js +381 -0
- package/dist/lifecycle/handlers/worker.js.map +1 -0
- package/dist/lifecycle/handlers-v2.d.ts +0 -2
- package/dist/lifecycle/handlers-v2.d.ts.map +1 -1
- package/dist/lifecycle/handlers-v2.js +4 -55
- package/dist/lifecycle/handlers-v2.js.map +1 -1
- package/dist/mail/conversation-map.d.ts +33 -0
- package/dist/mail/conversation-map.d.ts.map +1 -0
- package/dist/mail/conversation-map.js +61 -0
- package/dist/mail/conversation-map.js.map +1 -0
- package/dist/mail/index.d.ts +11 -0
- package/dist/mail/index.d.ts.map +1 -0
- package/dist/mail/index.js +11 -0
- package/dist/mail/index.js.map +1 -0
- package/dist/mail/mail-service.d.ts +85 -0
- package/dist/mail/mail-service.d.ts.map +1 -0
- package/dist/mail/mail-service.js +121 -0
- package/dist/mail/mail-service.js.map +1 -0
- package/dist/mail/stores/eventstore-conversation-store.d.ts +40 -0
- package/dist/mail/stores/eventstore-conversation-store.d.ts.map +1 -0
- package/dist/mail/stores/eventstore-conversation-store.js +131 -0
- package/dist/mail/stores/eventstore-conversation-store.js.map +1 -0
- package/dist/mail/stores/eventstore-participant-store.d.ts +43 -0
- package/dist/mail/stores/eventstore-participant-store.d.ts.map +1 -0
- package/dist/mail/stores/eventstore-participant-store.js +145 -0
- package/dist/mail/stores/eventstore-participant-store.js.map +1 -0
- package/dist/mail/stores/eventstore-thread-store.d.ts +46 -0
- package/dist/mail/stores/eventstore-thread-store.d.ts.map +1 -0
- package/dist/mail/stores/eventstore-thread-store.js +118 -0
- package/dist/mail/stores/eventstore-thread-store.js.map +1 -0
- package/dist/mail/stores/eventstore-turn-store.d.ts +47 -0
- package/dist/mail/stores/eventstore-turn-store.d.ts.map +1 -0
- package/dist/mail/stores/eventstore-turn-store.js +153 -0
- package/dist/mail/stores/eventstore-turn-store.js.map +1 -0
- package/dist/mail/stores/index.d.ts +12 -0
- package/dist/mail/stores/index.d.ts.map +1 -0
- package/dist/mail/stores/index.js +12 -0
- package/dist/mail/stores/index.js.map +1 -0
- package/dist/mail/stores/types.d.ts +146 -0
- package/dist/mail/stores/types.d.ts.map +1 -0
- package/dist/mail/stores/types.js +13 -0
- package/dist/mail/stores/types.js.map +1 -0
- package/dist/mail/turn-recorder.d.ts +30 -0
- package/dist/mail/turn-recorder.d.ts.map +1 -0
- package/dist/mail/turn-recorder.js +98 -0
- package/dist/mail/turn-recorder.js.map +1 -0
- package/dist/map/adapter/acp-over-map.d.ts +115 -0
- package/dist/map/adapter/acp-over-map.d.ts.map +1 -0
- package/dist/map/adapter/acp-over-map.js +1024 -0
- package/dist/map/adapter/acp-over-map.js.map +1 -0
- package/dist/map/adapter/connection-manager.d.ts +150 -0
- package/dist/map/adapter/connection-manager.d.ts.map +1 -0
- package/dist/map/adapter/connection-manager.js +207 -0
- package/dist/map/adapter/connection-manager.js.map +1 -0
- package/dist/map/adapter/event-log.d.ts +87 -0
- package/dist/map/adapter/event-log.d.ts.map +1 -0
- package/dist/map/adapter/event-log.js +122 -0
- package/dist/map/adapter/event-log.js.map +1 -0
- package/dist/map/adapter/event-translator.d.ts +85 -0
- package/dist/map/adapter/event-translator.d.ts.map +1 -0
- package/dist/map/adapter/event-translator.js +295 -0
- package/dist/map/adapter/event-translator.js.map +1 -0
- package/dist/map/adapter/extensions/agent-detection.d.ts +49 -0
- package/dist/map/adapter/extensions/agent-detection.d.ts.map +1 -0
- package/dist/map/adapter/extensions/agent-detection.js +91 -0
- package/dist/map/adapter/extensions/agent-detection.js.map +1 -0
- package/dist/map/adapter/extensions/agent-lifecycle.d.ts +82 -0
- package/dist/map/adapter/extensions/agent-lifecycle.d.ts.map +1 -0
- package/dist/map/adapter/extensions/agent-lifecycle.js +164 -0
- package/dist/map/adapter/extensions/agent-lifecycle.js.map +1 -0
- package/dist/map/adapter/extensions/cognitive.d.ts +27 -0
- package/dist/map/adapter/extensions/cognitive.d.ts.map +1 -0
- package/dist/map/adapter/extensions/cognitive.js +158 -0
- package/dist/map/adapter/extensions/cognitive.js.map +1 -0
- package/dist/map/adapter/extensions/index.d.ts +95 -0
- package/dist/map/adapter/extensions/index.d.ts.map +1 -0
- package/dist/map/adapter/extensions/index.js +228 -0
- package/dist/map/adapter/extensions/index.js.map +1 -0
- package/dist/map/adapter/extensions/mcp-bridge.d.ts +57 -0
- package/dist/map/adapter/extensions/mcp-bridge.d.ts.map +1 -0
- package/dist/map/adapter/extensions/mcp-bridge.js +745 -0
- package/dist/map/adapter/extensions/mcp-bridge.js.map +1 -0
- package/dist/map/adapter/extensions/resume.d.ts +47 -0
- package/dist/map/adapter/extensions/resume.d.ts.map +1 -0
- package/dist/map/adapter/extensions/resume.js +59 -0
- package/dist/map/adapter/extensions/resume.js.map +1 -0
- package/dist/map/adapter/extensions/streams.d.ts +95 -0
- package/dist/map/adapter/extensions/streams.d.ts.map +1 -0
- package/dist/map/adapter/extensions/streams.js +515 -0
- package/dist/map/adapter/extensions/streams.js.map +1 -0
- package/dist/map/adapter/extensions/task.d.ts +40 -0
- package/dist/map/adapter/extensions/task.d.ts.map +1 -0
- package/dist/map/adapter/extensions/task.js +197 -0
- package/dist/map/adapter/extensions/task.js.map +1 -0
- package/dist/map/adapter/extensions/update-metadata.d.ts +29 -0
- package/dist/map/adapter/extensions/update-metadata.d.ts.map +1 -0
- package/dist/map/adapter/extensions/update-metadata.js +67 -0
- package/dist/map/adapter/extensions/update-metadata.js.map +1 -0
- package/dist/map/adapter/extensions/wake.d.ts +60 -0
- package/dist/map/adapter/extensions/wake.d.ts.map +1 -0
- package/dist/map/adapter/extensions/wake.js +144 -0
- package/dist/map/adapter/extensions/wake.js.map +1 -0
- package/dist/map/adapter/extensions/workspace-files.d.ts +42 -0
- package/dist/map/adapter/extensions/workspace-files.d.ts.map +1 -0
- package/dist/map/adapter/extensions/workspace-files.js +338 -0
- package/dist/map/adapter/extensions/workspace-files.js.map +1 -0
- package/dist/map/adapter/extensions/workspace.d.ts +57 -0
- package/dist/map/adapter/extensions/workspace.d.ts.map +1 -0
- package/dist/map/adapter/extensions/workspace.js +81 -0
- package/dist/map/adapter/extensions/workspace.js.map +1 -0
- package/dist/map/adapter/index.d.ts +20 -0
- package/dist/map/adapter/index.d.ts.map +1 -0
- package/dist/map/adapter/index.js +40 -0
- package/dist/map/adapter/index.js.map +1 -0
- package/dist/map/adapter/interface.d.ts +450 -0
- package/dist/map/adapter/interface.d.ts.map +1 -0
- package/dist/map/adapter/interface.js +24 -0
- package/dist/map/adapter/interface.js.map +1 -0
- package/dist/map/adapter/mail-handler-adapter.d.ts +27 -0
- package/dist/map/adapter/mail-handler-adapter.d.ts.map +1 -0
- package/dist/map/adapter/mail-handler-adapter.js +292 -0
- package/dist/map/adapter/mail-handler-adapter.js.map +1 -0
- package/dist/map/adapter/map-adapter.d.ts +200 -0
- package/dist/map/adapter/map-adapter.d.ts.map +1 -0
- package/dist/map/adapter/map-adapter.js +1199 -0
- package/dist/map/adapter/map-adapter.js.map +1 -0
- package/dist/map/adapter/rpc-handler.d.ts +263 -0
- package/dist/map/adapter/rpc-handler.d.ts.map +1 -0
- package/dist/map/adapter/rpc-handler.js +365 -0
- package/dist/map/adapter/rpc-handler.js.map +1 -0
- package/dist/map/adapter/subscription-manager.d.ts +174 -0
- package/dist/map/adapter/subscription-manager.d.ts.map +1 -0
- package/dist/map/adapter/subscription-manager.js +248 -0
- package/dist/map/adapter/subscription-manager.js.map +1 -0
- package/dist/map/adapter/types.d.ts +194 -0
- package/dist/map/adapter/types.d.ts.map +1 -0
- package/dist/map/adapter/types.js +27 -0
- package/dist/map/adapter/types.js.map +1 -0
- package/dist/map/adapter/websocket-integration.d.ts +113 -0
- package/dist/map/adapter/websocket-integration.d.ts.map +1 -0
- package/dist/map/adapter/websocket-integration.js +134 -0
- package/dist/map/adapter/websocket-integration.js.map +1 -0
- package/dist/map/cascade-action-handler.d.ts.map +1 -1
- package/dist/map/cascade-action-handler.js +19 -5
- package/dist/map/cascade-action-handler.js.map +1 -1
- package/dist/map/federation/envelope.d.ts +98 -0
- package/dist/map/federation/envelope.d.ts.map +1 -0
- package/dist/map/federation/envelope.js +160 -0
- package/dist/map/federation/envelope.js.map +1 -0
- package/dist/map/federation/federation-handler.d.ts +50 -0
- package/dist/map/federation/federation-handler.d.ts.map +1 -0
- package/dist/map/federation/federation-handler.js +306 -0
- package/dist/map/federation/federation-handler.js.map +1 -0
- package/dist/map/federation/index.d.ts +14 -0
- package/dist/map/federation/index.d.ts.map +1 -0
- package/dist/map/federation/index.js +13 -0
- package/dist/map/federation/index.js.map +1 -0
- package/dist/map/federation/types.d.ts +239 -0
- package/dist/map/federation/types.d.ts.map +1 -0
- package/dist/map/federation/types.js +23 -0
- package/dist/map/federation/types.js.map +1 -0
- package/dist/map/mail-bridge.d.ts +7 -0
- package/dist/map/mail-bridge.d.ts.map +1 -1
- package/dist/map/mail-bridge.js +39 -9
- package/dist/map/mail-bridge.js.map +1 -1
- package/dist/map/server.d.ts.map +1 -1
- package/dist/map/server.js +17 -2
- package/dist/map/server.js.map +1 -1
- package/dist/map/types.d.ts +6 -0
- package/dist/map/types.d.ts.map +1 -1
- package/dist/mcp/map-client.d.ts +39 -0
- package/dist/mcp/map-client.d.ts.map +1 -0
- package/dist/mcp/map-client.js +129 -0
- package/dist/mcp/map-client.js.map +1 -0
- package/dist/mcp/mcp-server.d.ts +72 -0
- package/dist/mcp/mcp-server.d.ts.map +1 -0
- package/dist/mcp/mcp-server.js +1027 -0
- package/dist/mcp/mcp-server.js.map +1 -0
- package/dist/mcp/tools/claim_task.d.ts +35 -0
- package/dist/mcp/tools/claim_task.d.ts.map +1 -0
- package/dist/mcp/tools/claim_task.js +58 -0
- package/dist/mcp/tools/claim_task.js.map +1 -0
- package/dist/mcp/tools/done-v2.d.ts +0 -1
- package/dist/mcp/tools/done-v2.d.ts.map +1 -1
- package/dist/mcp/tools/done-v2.js +0 -1
- package/dist/mcp/tools/done-v2.js.map +1 -1
- package/dist/mcp/tools/done.d.ts +102 -0
- package/dist/mcp/tools/done.d.ts.map +1 -0
- package/dist/mcp/tools/done.js +253 -0
- package/dist/mcp/tools/done.js.map +1 -0
- package/dist/mcp/tools/inject_context.d.ts +61 -0
- package/dist/mcp/tools/inject_context.d.ts.map +1 -0
- package/dist/mcp/tools/inject_context.js +123 -0
- package/dist/mcp/tools/inject_context.js.map +1 -0
- package/dist/mcp/tools/list_claimable_tasks.d.ts +38 -0
- package/dist/mcp/tools/list_claimable_tasks.d.ts.map +1 -0
- package/dist/mcp/tools/list_claimable_tasks.js +63 -0
- package/dist/mcp/tools/list_claimable_tasks.js.map +1 -0
- package/dist/mcp/tools/unclaim_task.d.ts +31 -0
- package/dist/mcp/tools/unclaim_task.d.ts.map +1 -0
- package/dist/mcp/tools/unclaim_task.js +47 -0
- package/dist/mcp/tools/unclaim_task.js.map +1 -0
- package/dist/mcp/tools/wait_for_activity.d.ts +60 -0
- package/dist/mcp/tools/wait_for_activity.d.ts.map +1 -0
- package/dist/mcp/tools/wait_for_activity.js +135 -0
- package/dist/mcp/tools/wait_for_activity.js.map +1 -0
- package/dist/monitor/health-check-service.d.ts +143 -0
- package/dist/monitor/health-check-service.d.ts.map +1 -0
- package/dist/monitor/health-check-service.js +240 -0
- package/dist/monitor/health-check-service.js.map +1 -0
- package/dist/monitor/index.d.ts +14 -0
- package/dist/monitor/index.d.ts.map +1 -0
- package/dist/monitor/index.js +14 -0
- package/dist/monitor/index.js.map +1 -0
- package/dist/monitor/stall-detector.d.ts +109 -0
- package/dist/monitor/stall-detector.d.ts.map +1 -0
- package/dist/monitor/stall-detector.js +152 -0
- package/dist/monitor/stall-detector.js.map +1 -0
- package/dist/peer/capability-manager.d.ts +56 -0
- package/dist/peer/capability-manager.d.ts.map +1 -0
- package/dist/peer/capability-manager.js +186 -0
- package/dist/peer/capability-manager.js.map +1 -0
- package/dist/peer/encapsulation-manager.d.ts +190 -0
- package/dist/peer/encapsulation-manager.d.ts.map +1 -0
- package/dist/peer/encapsulation-manager.js +486 -0
- package/dist/peer/encapsulation-manager.js.map +1 -0
- package/dist/peer/federation-manager.d.ts +223 -0
- package/dist/peer/federation-manager.d.ts.map +1 -0
- package/dist/peer/federation-manager.js +528 -0
- package/dist/peer/federation-manager.js.map +1 -0
- package/dist/peer/hierarchy-errors.d.ts +208 -0
- package/dist/peer/hierarchy-errors.d.ts.map +1 -0
- package/dist/peer/hierarchy-errors.js +268 -0
- package/dist/peer/hierarchy-errors.js.map +1 -0
- package/dist/peer/hierarchy-protocol.d.ts +159 -0
- package/dist/peer/hierarchy-protocol.d.ts.map +1 -0
- package/dist/peer/hierarchy-protocol.js +142 -0
- package/dist/peer/hierarchy-protocol.js.map +1 -0
- package/dist/peer/index.d.ts +15 -0
- package/dist/peer/index.d.ts.map +1 -0
- package/dist/peer/index.js +15 -0
- package/dist/peer/index.js.map +1 -0
- package/dist/peer/peer-manager.d.ts +99 -0
- package/dist/peer/peer-manager.d.ts.map +1 -0
- package/dist/peer/peer-manager.js +333 -0
- package/dist/peer/peer-manager.js.map +1 -0
- package/dist/peer/task-delegation.d.ts +189 -0
- package/dist/peer/task-delegation.d.ts.map +1 -0
- package/dist/peer/task-delegation.js +303 -0
- package/dist/peer/task-delegation.js.map +1 -0
- package/dist/peer/transports/index.d.ts +8 -0
- package/dist/peer/transports/index.d.ts.map +1 -0
- package/dist/peer/transports/index.js +8 -0
- package/dist/peer/transports/index.js.map +1 -0
- package/dist/peer/transports/local-transport.d.ts +56 -0
- package/dist/peer/transports/local-transport.d.ts.map +1 -0
- package/dist/peer/transports/local-transport.js +263 -0
- package/dist/peer/transports/local-transport.js.map +1 -0
- package/dist/peer/transports/websocket-transport.d.ts +86 -0
- package/dist/peer/transports/websocket-transport.d.ts.map +1 -0
- package/dist/peer/transports/websocket-transport.js +338 -0
- package/dist/peer/transports/websocket-transport.js.map +1 -0
- package/dist/peer/types.d.ts +268 -0
- package/dist/peer/types.d.ts.map +1 -0
- package/dist/peer/types.js +36 -0
- package/dist/peer/types.js.map +1 -0
- package/dist/router/address-resolver.d.ts +102 -0
- package/dist/router/address-resolver.d.ts.map +1 -0
- package/dist/router/address-resolver.js +198 -0
- package/dist/router/address-resolver.js.map +1 -0
- package/dist/router/broadcast.d.ts +53 -0
- package/dist/router/broadcast.d.ts.map +1 -0
- package/dist/router/broadcast.js +75 -0
- package/dist/router/broadcast.js.map +1 -0
- package/dist/router/channels.d.ts +148 -0
- package/dist/router/channels.d.ts.map +1 -0
- package/dist/router/channels.js +126 -0
- package/dist/router/channels.js.map +1 -0
- package/dist/router/index.d.ts +21 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +18 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/message-router.d.ts +197 -0
- package/dist/router/message-router.d.ts.map +1 -0
- package/dist/router/message-router.js +903 -0
- package/dist/router/message-router.js.map +1 -0
- package/dist/router/message-types.d.ts +183 -0
- package/dist/router/message-types.d.ts.map +1 -0
- package/dist/router/message-types.js +79 -0
- package/dist/router/message-types.js.map +1 -0
- package/dist/router/role-resolver.d.ts +67 -0
- package/dist/router/role-resolver.d.ts.map +1 -0
- package/dist/router/role-resolver.js +106 -0
- package/dist/router/role-resolver.js.map +1 -0
- package/dist/router/signals.d.ts +253 -0
- package/dist/router/signals.d.ts.map +1 -0
- package/dist/router/signals.js +53 -0
- package/dist/router/signals.js.map +1 -0
- package/dist/router/types.d.ts +191 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +34 -0
- package/dist/router/types.js.map +1 -0
- package/dist/router/wake.d.ts +111 -0
- package/dist/router/wake.d.ts.map +1 -0
- package/dist/router/wake.js +180 -0
- package/dist/router/wake.js.map +1 -0
- package/dist/server/combined-server.d.ts +95 -0
- package/dist/server/combined-server.d.ts.map +1 -0
- package/dist/server/combined-server.js +335 -0
- package/dist/server/combined-server.js.map +1 -0
- package/dist/steering/index.d.ts +11 -0
- package/dist/steering/index.d.ts.map +1 -0
- package/dist/steering/index.js +11 -0
- package/dist/steering/index.js.map +1 -0
- package/dist/steering/inject.d.ts +39 -0
- package/dist/steering/inject.d.ts.map +1 -0
- package/dist/steering/inject.js +197 -0
- package/dist/steering/inject.js.map +1 -0
- package/dist/steering/types.d.ts +100 -0
- package/dist/steering/types.d.ts.map +1 -0
- package/dist/steering/types.js +11 -0
- package/dist/steering/types.js.map +1 -0
- package/dist/store/backends/index.d.ts +11 -0
- package/dist/store/backends/index.d.ts.map +1 -0
- package/dist/store/backends/index.js +15 -0
- package/dist/store/backends/index.js.map +1 -0
- package/dist/store/backends/json-backend.d.ts +23 -0
- package/dist/store/backends/json-backend.d.ts.map +1 -0
- package/dist/store/backends/json-backend.js +220 -0
- package/dist/store/backends/json-backend.js.map +1 -0
- package/dist/store/backends/memory-backend.d.ts +12 -0
- package/dist/store/backends/memory-backend.d.ts.map +1 -0
- package/dist/store/backends/memory-backend.js +205 -0
- package/dist/store/backends/memory-backend.js.map +1 -0
- package/dist/store/backends/sqlite-backend.d.ts +27 -0
- package/dist/store/backends/sqlite-backend.d.ts.map +1 -0
- package/dist/store/backends/sqlite-backend.js +231 -0
- package/dist/store/backends/sqlite-backend.js.map +1 -0
- package/dist/store/backends/tinybase-backend.d.ts +22 -0
- package/dist/store/backends/tinybase-backend.d.ts.map +1 -0
- package/dist/store/backends/tinybase-backend.js +203 -0
- package/dist/store/backends/tinybase-backend.js.map +1 -0
- package/dist/store/backends/types.d.ts +175 -0
- package/dist/store/backends/types.d.ts.map +1 -0
- package/dist/store/backends/types.js +28 -0
- package/dist/store/backends/types.js.map +1 -0
- package/dist/store/event-store.d.ts +128 -0
- package/dist/store/event-store.d.ts.map +1 -0
- package/dist/store/event-store.js +1751 -0
- package/dist/store/event-store.js.map +1 -0
- package/dist/store/instance.d.ts +290 -0
- package/dist/store/instance.d.ts.map +1 -0
- package/dist/store/instance.js +363 -0
- package/dist/store/instance.js.map +1 -0
- package/dist/store/migrations.d.ts +41 -0
- package/dist/store/migrations.d.ts.map +1 -0
- package/dist/store/migrations.js +79 -0
- package/dist/store/migrations.js.map +1 -0
- package/dist/store/test-utils.d.ts +63 -0
- package/dist/store/test-utils.d.ts.map +1 -0
- package/dist/store/test-utils.js +63 -0
- package/dist/store/test-utils.js.map +1 -0
- package/dist/store/types/config.d.ts +16 -0
- package/dist/store/types/config.d.ts.map +1 -0
- package/dist/store/types/config.js +8 -0
- package/dist/store/types/config.js.map +1 -0
- package/dist/store/types/conversations.d.ts +91 -0
- package/dist/store/types/conversations.d.ts.map +1 -0
- package/dist/store/types/conversations.js +8 -0
- package/dist/store/types/conversations.js.map +1 -0
- package/dist/store/types/sessions.d.ts +44 -0
- package/dist/store/types/sessions.d.ts.map +1 -0
- package/dist/store/types/sessions.js +9 -0
- package/dist/store/types/sessions.js.map +1 -0
- package/dist/store/types.d.ts +115 -0
- package/dist/store/types.d.ts.map +1 -0
- package/dist/store/types.js +6 -0
- package/dist/store/types.js.map +1 -0
- package/dist/task/backend/index.d.ts +93 -0
- package/dist/task/backend/index.d.ts.map +1 -0
- package/dist/task/backend/index.js +178 -0
- package/dist/task/backend/index.js.map +1 -0
- package/dist/task/backend/memory.d.ts +70 -0
- package/dist/task/backend/memory.d.ts.map +1 -0
- package/dist/task/backend/memory.js +621 -0
- package/dist/task/backend/memory.js.map +1 -0
- package/dist/task/backend/opentasks/backend.d.ts +140 -0
- package/dist/task/backend/opentasks/backend.d.ts.map +1 -0
- package/dist/task/backend/opentasks/backend.js +1023 -0
- package/dist/task/backend/opentasks/backend.js.map +1 -0
- package/dist/task/backend/opentasks/client.d.ts +337 -0
- package/dist/task/backend/opentasks/client.d.ts.map +1 -0
- package/dist/task/backend/opentasks/client.js +225 -0
- package/dist/task/backend/opentasks/client.js.map +1 -0
- package/dist/task/backend/opentasks/daemon-manager.d.ts +89 -0
- package/dist/task/backend/opentasks/daemon-manager.d.ts.map +1 -0
- package/dist/task/backend/opentasks/daemon-manager.js +195 -0
- package/dist/task/backend/opentasks/daemon-manager.js.map +1 -0
- package/dist/task/backend/opentasks/index.d.ts +21 -0
- package/dist/task/backend/opentasks/index.d.ts.map +1 -0
- package/dist/task/backend/opentasks/index.js +21 -0
- package/dist/task/backend/opentasks/index.js.map +1 -0
- package/dist/task/backend/opentasks/mapping.d.ts +48 -0
- package/dist/task/backend/opentasks/mapping.d.ts.map +1 -0
- package/dist/task/backend/opentasks/mapping.js +77 -0
- package/dist/task/backend/opentasks/mapping.js.map +1 -0
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts +54 -0
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.d.ts.map +1 -0
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.js +88 -0
- package/dist/task/backend/sudocode/__tests__/integration/test-utils.js.map +1 -0
- package/dist/task/backend/sudocode/backend.d.ts +155 -0
- package/dist/task/backend/sudocode/backend.d.ts.map +1 -0
- package/dist/task/backend/sudocode/backend.js +942 -0
- package/dist/task/backend/sudocode/backend.js.map +1 -0
- package/dist/task/backend/sudocode/client.d.ts +303 -0
- package/dist/task/backend/sudocode/client.d.ts.map +1 -0
- package/dist/task/backend/sudocode/client.js +101 -0
- package/dist/task/backend/sudocode/client.js.map +1 -0
- package/dist/task/backend/sudocode/index.d.ts +19 -0
- package/dist/task/backend/sudocode/index.d.ts.map +1 -0
- package/dist/task/backend/sudocode/index.js +17 -0
- package/dist/task/backend/sudocode/index.js.map +1 -0
- package/dist/task/backend/sudocode/mapping.d.ts +51 -0
- package/dist/task/backend/sudocode/mapping.d.ts.map +1 -0
- package/dist/task/backend/sudocode/mapping.js +86 -0
- package/dist/task/backend/sudocode/mapping.js.map +1 -0
- package/dist/task/backend/sudocode/server-client.d.ts +56 -0
- package/dist/task/backend/sudocode/server-client.d.ts.map +1 -0
- package/dist/task/backend/sudocode/server-client.js +367 -0
- package/dist/task/backend/sudocode/server-client.js.map +1 -0
- package/dist/task/backend/sudocode/standalone-client.d.ts +91 -0
- package/dist/task/backend/sudocode/standalone-client.d.ts.map +1 -0
- package/dist/task/backend/sudocode/standalone-client.js +476 -0
- package/dist/task/backend/sudocode/standalone-client.js.map +1 -0
- package/dist/task/backend/sudocode/sync-policy.d.ts +166 -0
- package/dist/task/backend/sudocode/sync-policy.d.ts.map +1 -0
- package/dist/task/backend/sudocode/sync-policy.js +221 -0
- package/dist/task/backend/sudocode/sync-policy.js.map +1 -0
- package/dist/task/backend/sudocode/tools.d.ts +87 -0
- package/dist/task/backend/sudocode/tools.d.ts.map +1 -0
- package/dist/task/backend/sudocode/tools.js +743 -0
- package/dist/task/backend/sudocode/tools.js.map +1 -0
- package/dist/task/backend/tool-provider.d.ts +56 -0
- package/dist/task/backend/tool-provider.d.ts.map +1 -0
- package/dist/task/backend/tool-provider.js +424 -0
- package/dist/task/backend/tool-provider.js.map +1 -0
- package/dist/task/backend/types.d.ts +297 -0
- package/dist/task/backend/types.d.ts.map +1 -0
- package/dist/task/backend/types.js +27 -0
- package/dist/task/backend/types.js.map +1 -0
- package/dist/task/backend/unified-tool-provider.d.ts +57 -0
- package/dist/task/backend/unified-tool-provider.d.ts.map +1 -0
- package/dist/task/backend/unified-tool-provider.js +623 -0
- package/dist/task/backend/unified-tool-provider.js.map +1 -0
- package/dist/task/index.d.ts +7 -0
- package/dist/task/index.d.ts.map +1 -0
- package/dist/task/index.js +7 -0
- package/dist/task/index.js.map +1 -0
- package/dist/task/retry-policy.d.ts +89 -0
- package/dist/task/retry-policy.d.ts.map +1 -0
- package/dist/task/retry-policy.js +160 -0
- package/dist/task/retry-policy.js.map +1 -0
- package/dist/task/task-manager.d.ts +70 -0
- package/dist/task/task-manager.d.ts.map +1 -0
- package/dist/task/task-manager.js +319 -0
- package/dist/task/task-manager.js.map +1 -0
- package/dist/task/types.d.ts +72 -0
- package/dist/task/types.d.ts.map +1 -0
- package/dist/task/types.js +33 -0
- package/dist/task/types.js.map +1 -0
- package/dist/teams/team-loader.d.ts +2 -1
- package/dist/teams/team-loader.d.ts.map +1 -1
- package/dist/teams/team-loader.js +2 -1
- package/dist/teams/team-loader.js.map +1 -1
- package/dist/teams/team-manager.d.ts +101 -0
- package/dist/teams/team-manager.d.ts.map +1 -0
- package/dist/teams/team-manager.js +260 -0
- package/dist/teams/team-manager.js.map +1 -0
- package/dist/teams/team-runtime-v2.d.ts +0 -3
- package/dist/teams/team-runtime-v2.d.ts.map +1 -1
- package/dist/teams/team-runtime-v2.js +31 -93
- package/dist/teams/team-runtime-v2.js.map +1 -1
- package/dist/teams/team-runtime.d.ts +245 -0
- package/dist/teams/team-runtime.d.ts.map +1 -0
- package/dist/teams/team-runtime.js +1023 -0
- package/dist/teams/team-runtime.js.map +1 -0
- package/dist/trigger/router/index.d.ts +11 -0
- package/dist/trigger/router/index.d.ts.map +1 -0
- package/dist/trigger/router/index.js +10 -0
- package/dist/trigger/router/index.js.map +1 -0
- package/dist/trigger/router/strategies/ai-router-strategy.d.ts +34 -0
- package/dist/trigger/router/strategies/ai-router-strategy.d.ts.map +1 -0
- package/dist/trigger/router/strategies/ai-router-strategy.js +359 -0
- package/dist/trigger/router/strategies/ai-router-strategy.js.map +1 -0
- package/dist/trigger/router/strategies/direct-strategy.d.ts +32 -0
- package/dist/trigger/router/strategies/direct-strategy.d.ts.map +1 -0
- package/dist/trigger/router/strategies/direct-strategy.js +119 -0
- package/dist/trigger/router/strategies/direct-strategy.js.map +1 -0
- package/dist/trigger/router/strategies/index.d.ts +11 -0
- package/dist/trigger/router/strategies/index.d.ts.map +1 -0
- package/dist/trigger/router/strategies/index.js +11 -0
- package/dist/trigger/router/strategies/index.js.map +1 -0
- package/dist/trigger/router/strategies/role-strategy.d.ts +39 -0
- package/dist/trigger/router/strategies/role-strategy.d.ts.map +1 -0
- package/dist/trigger/router/strategies/role-strategy.js +207 -0
- package/dist/trigger/router/strategies/role-strategy.js.map +1 -0
- package/dist/trigger/router/trigger-router.d.ts +54 -0
- package/dist/trigger/router/trigger-router.d.ts.map +1 -0
- package/dist/trigger/router/trigger-router.js +362 -0
- package/dist/trigger/router/trigger-router.js.map +1 -0
- package/dist/trigger/router/types.d.ts +225 -0
- package/dist/trigger/router/types.d.ts.map +1 -0
- package/dist/trigger/router/types.js +10 -0
- package/dist/trigger/router/types.js.map +1 -0
- package/dist/trigger/sources/cron/cron-service.d.ts.map +1 -1
- package/dist/trigger/sources/cron/cron-service.js +6 -3
- package/dist/trigger/sources/cron/cron-service.js.map +1 -1
- package/dist/trigger/trigger-system.d.ts +77 -0
- package/dist/trigger/trigger-system.d.ts.map +1 -0
- package/dist/trigger/trigger-system.js +84 -0
- package/dist/trigger/trigger-system.js.map +1 -0
- package/dist/util/git-safety.d.ts +33 -0
- package/dist/util/git-safety.d.ts.map +1 -0
- package/dist/util/git-safety.js +94 -0
- package/dist/util/git-safety.js.map +1 -0
- package/dist/workspace/index.d.ts +0 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +0 -2
- package/dist/workspace/index.js.map +1 -1
- package/dist/workspace/landing/direct-push.d.ts.map +1 -1
- package/dist/workspace/landing/direct-push.js +22 -7
- package/dist/workspace/landing/direct-push.js.map +1 -1
- package/dist/workspace/landing/queue-to-branch.d.ts.map +1 -1
- package/dist/workspace/landing/queue-to-branch.js +1 -3
- package/dist/workspace/landing/queue-to-branch.js.map +1 -1
- package/dist/workspace/types.d.ts +0 -13
- package/dist/workspace/types.d.ts.map +1 -1
- package/dist/workspace/workspace-manager.d.ts +0 -11
- package/dist/workspace/workspace-manager.d.ts.map +1 -1
- package/dist/workspace/workspace-manager.js +0 -30
- package/dist/workspace/workspace-manager.js.map +1 -1
- package/package.json +28 -2
- package/templates/teams/self-driving/prompts/grinder.md +1 -0
- package/templates/teams/self-driving/prompts/judge.md +1 -0
- package/templates/teams/self-driving/prompts/planner.md +1 -0
- package/templates/teams/self-driving/roles/grinder.yaml +15 -0
- package/templates/teams/self-driving/roles/judge.yaml +10 -0
- package/templates/teams/self-driving/roles/planner.yaml +16 -0
- package/.claude/commands/openspec/apply.md +0 -23
- package/.claude/commands/openspec/archive.md +0 -27
- package/.claude/commands/openspec/proposal.md +0 -28
- package/.claude/settings.json +0 -133
- package/.gitattributes +0 -3
- package/.opentasks/config.json +0 -9
- package/.opentasks/graph.jsonl +0 -0
- package/.sessionlog/settings.json +0 -4
- package/.sudocode/issues.jsonl +0 -183
- package/.sudocode/specs.jsonl +0 -56
- package/AGENTS.md +0 -18
- package/CLAUDE.md +0 -923
- package/docs/architecture.md +0 -508
- package/docs/configuration.md +0 -323
- package/docs/conflict-recovery.md +0 -472
- package/docs/design/task-dispatcher.md +0 -880
- package/docs/design-subsystem-extraction.md +0 -627
- package/docs/git-cascade-integration-gaps.md +0 -678
- package/docs/implementation-details.md +0 -1127
- package/docs/implementation-summary.md +0 -448
- package/docs/lifecycle-events-design.md +0 -111
- package/docs/mail-integration.md +0 -608
- package/docs/openhive-capability-summary.md +0 -415
- package/docs/openhive-integration.md +0 -415
- package/docs/plan-self-driving-support.md +0 -433
- package/docs/roadmap-v2-gaps.md +0 -216
- package/docs/spec-self-driving-support.md +0 -462
- package/docs/team-templates.md +0 -860
- package/docs/teams.md +0 -306
- package/docs/trigger-system-design.md +0 -333
- package/docs/troubleshooting.md +0 -489
- package/docs/workspace-interfaces.md +0 -731
- package/docs/workspace-redesign-plan.md +0 -302
- package/examples/distributed-peer-communication.ts +0 -202
- package/examples/local-peer-communication.ts +0 -165
- package/index.js +0 -2
- package/mvp_docs/agent-execution-system.md +0 -347
- package/mvp_docs/agent-interface.md +0 -580
- package/mvp_docs/data-structures.md +0 -701
- package/mvp_docs/dynamic-meta-orchestration.md +0 -116
- package/mvp_docs/multi-agent-interaction-design.md +0 -779
- package/mvp_docs/mvp-implementation-plan.md +0 -1148
- package/renovate.json5 +0 -6
- package/scripts/test-acp-integration.ts +0 -422
- package/src/__tests__/boot-v2.test.ts +0 -631
- package/src/__tests__/e2e/acp-over-map-live.e2e.test.ts +0 -496
- package/src/__tests__/e2e/acp-over-map.e2e.test.ts +0 -457
- package/src/__tests__/e2e/agent-lifecycle.e2e.test.ts +0 -770
- package/src/__tests__/e2e/auto-sync.e2e.test.ts +0 -257
- package/src/__tests__/e2e/bootstrap.e2e.test.ts +0 -319
- package/src/__tests__/e2e/cascade-rebase.e2e.test.ts +0 -254
- package/src/__tests__/e2e/cc-swarm-bridge.e2e.test.ts +0 -253
- package/src/__tests__/e2e/cli-run.e2e.test.ts +0 -167
- package/src/__tests__/e2e/cognitive-workspace.e2e.test.ts +0 -282
- package/src/__tests__/e2e/dispatch-coordination.e2e.test.ts +0 -495
- package/src/__tests__/e2e/dispatch-live.e2e.test.ts +0 -564
- package/src/__tests__/e2e/dispatch-opentasks.e2e.test.ts +0 -496
- package/src/__tests__/e2e/dispatch-phase2-live.e2e.test.ts +0 -456
- package/src/__tests__/e2e/dispatch-phase2.e2e.test.ts +0 -386
- package/src/__tests__/e2e/dispatch.e2e.test.ts +0 -376
- package/src/__tests__/e2e/done-scenarios.e2e.test.ts +0 -322
- package/src/__tests__/e2e/live-agent.e2e.test.ts +0 -1330
- package/src/__tests__/e2e/map-server.e2e.test.ts +0 -128
- package/src/__tests__/e2e/map-sidecar.e2e.test.ts +0 -139
- package/src/__tests__/e2e/opentasks-integration.e2e.test.ts +0 -280
- package/src/__tests__/e2e/pull-mode.e2e.test.ts +0 -632
- package/src/__tests__/e2e/resume-continue.e2e.test.ts +0 -312
- package/src/__tests__/e2e/self-driving-v3.e2e.test.ts +0 -197
- package/src/__tests__/e2e/spawn-resolver.e2e.test.ts +0 -200
- package/src/__tests__/e2e/swarmkit-integration.e2e.test.ts +0 -562
- package/src/__tests__/e2e/swarmkit-live.e2e.test.ts +0 -1049
- package/src/__tests__/e2e/trajectory-tracking.e2e.test.ts +0 -258
- package/src/__tests__/e2e/trigger-wake.e2e.test.ts +0 -257
- package/src/__tests__/e2e/workspace-lifecycle.e2e.test.ts +0 -383
- package/src/__tests__/e2e/workspace-v3.e2e.test.ts +0 -413
- package/src/acp/__tests__/claude-code-replay.test.ts +0 -225
- package/src/acp/__tests__/macro-agent.test.ts +0 -387
- package/src/acp/__tests__/session-mapper.test.ts +0 -152
- package/src/acp/__tests__/websocket-server.test.ts +0 -194
- package/src/acp/claude-code-replay.ts +0 -208
- package/src/acp/index.ts +0 -32
- package/src/acp/macro-agent.ts +0 -995
- package/src/acp/map-bridge.ts +0 -193
- package/src/acp/session-mapper.ts +0 -116
- package/src/acp/types.ts +0 -99
- package/src/acp/websocket-server.ts +0 -213
- package/src/adapters/__tests__/federation.test.ts +0 -256
- package/src/adapters/__tests__/inbox-adapter.test.ts +0 -316
- package/src/adapters/__tests__/tasks-adapter.test.ts +0 -270
- package/src/adapters/federation.ts +0 -185
- package/src/adapters/inbox-adapter.ts +0 -292
- package/src/adapters/inbox-client-adapter.ts +0 -173
- package/src/adapters/index.ts +0 -44
- package/src/adapters/opentasks-daemon.ts +0 -252
- package/src/adapters/tasks-adapter.ts +0 -330
- package/src/adapters/types.ts +0 -286
- package/src/agent/__tests__/agent-manager-topology.test.ts +0 -73
- package/src/agent/__tests__/agent-manager-v2.permission-interception.test.ts +0 -296
- package/src/agent/__tests__/agent-manager-v2.permissions.test.ts +0 -233
- package/src/agent/__tests__/agent-manager-v2.test.ts +0 -614
- package/src/agent/__tests__/agent-store.test.ts +0 -465
- package/src/agent/__tests__/task-ref-resolution.test.ts +0 -231
- package/src/agent/agent-manager-v2.ts +0 -2021
- package/src/agent/agent-manager.ts +0 -386
- package/src/agent/agent-store.ts +0 -409
- package/src/agent/index.ts +0 -7
- package/src/agent/prompts/coordinator-signals.ts +0 -115
- package/src/agent/prompts/index.ts +0 -7
- package/src/agent/system-prompt.ts +0 -298
- package/src/agent/types.ts +0 -459
- package/src/agent-detection/__tests__/command-builder.test.ts +0 -336
- package/src/agent-detection/__tests__/detector.test.ts +0 -768
- package/src/agent-detection/__tests__/registry.test.ts +0 -254
- package/src/agent-detection/command-builder.ts +0 -90
- package/src/agent-detection/detector.ts +0 -307
- package/src/agent-detection/index.ts +0 -36
- package/src/agent-detection/registry.ts +0 -200
- package/src/agent-detection/types.ts +0 -184
- package/src/api/__tests__/server.test.ts +0 -292
- package/src/api/index.ts +0 -8
- package/src/api/server.ts +0 -380
- package/src/api/types.ts +0 -39
- package/src/auth/__tests__/token.test.ts +0 -100
- package/src/auth/index.ts +0 -1
- package/src/auth/token.ts +0 -82
- package/src/boot-v2.ts +0 -1343
- package/src/cli/__tests__/stable-instance-id.test.ts +0 -57
- package/src/cli/acp.ts +0 -101
- package/src/cli/inbox-mcp-proxy.ts +0 -56
- package/src/cli/index.ts +0 -566
- package/src/cli/mcp.ts +0 -305
- package/src/cli/parse-args.ts +0 -54
- package/src/cli/stable-instance-id.ts +0 -14
- package/src/cognitive/__tests__/macro-agent-backend.test.ts +0 -520
- package/src/cognitive/__tests__/session-converter.test.ts +0 -423
- package/src/cognitive/__tests__/workspace-handler.test.ts +0 -221
- package/src/cognitive/analyst-role.ts +0 -59
- package/src/cognitive/index.ts +0 -49
- package/src/cognitive/macro-agent-backend.ts +0 -370
- package/src/cognitive/session-converter.ts +0 -151
- package/src/cognitive/types.ts +0 -163
- package/src/cognitive/workspace-handler.ts +0 -163
- package/src/config/index.ts +0 -9
- package/src/config/project-config.ts +0 -294
- package/src/control/__tests__/control-resilience.test.ts +0 -251
- package/src/control/__tests__/control-socket.test.ts +0 -240
- package/src/control/control-client.ts +0 -337
- package/src/control/control-server.ts +0 -298
- package/src/control/index.ts +0 -17
- package/src/control/types.ts +0 -95
- package/src/dispatch/CLAUDE.md +0 -129
- package/src/dispatch/__tests__/loadout-translation.test.ts +0 -141
- package/src/dispatch/__tests__/mail-inbound-consumer.integration.test.ts +0 -519
- package/src/dispatch/__tests__/mail-inbound-consumer.test.ts +0 -800
- package/src/dispatch/__tests__/mail-inbound-reuse-consumer.test.ts +0 -575
- package/src/dispatch/__tests__/permission-evaluator.test.ts +0 -196
- package/src/dispatch/__tests__/permission-overlay.test.ts +0 -56
- package/src/dispatch/__tests__/permissions-handler.test.ts +0 -168
- package/src/dispatch/__tests__/spawn-agent-handler.test.ts +0 -282
- package/src/dispatch/loadout-translation.ts +0 -138
- package/src/dispatch/mail-inbound-consumer.ts +0 -560
- package/src/dispatch/mail-inbound-reuse-consumer.ts +0 -479
- package/src/dispatch/permission-evaluator.ts +0 -191
- package/src/dispatch/permission-overlay.ts +0 -89
- package/src/dispatch/permissions-handler.ts +0 -112
- package/src/dispatch/spawn-agent-handler.ts +0 -160
- package/src/index.ts +0 -115
- package/src/integrations/__tests__/context-builder.test.ts +0 -218
- package/src/integrations/__tests__/sessionlog.test.ts +0 -498
- package/src/integrations/__tests__/skilltree.test.ts +0 -136
- package/src/integrations/context-builder.ts +0 -280
- package/src/integrations/sessionlog.ts +0 -194
- package/src/integrations/skilltree.ts +0 -184
- package/src/lifecycle/__tests__/cascade-consolidation.test.ts +0 -240
- package/src/lifecycle/__tests__/handlers-v2.test.ts +0 -565
- package/src/lifecycle/cascade.ts +0 -335
- package/src/lifecycle/cleanup.ts +0 -373
- package/src/lifecycle/handlers-v2.ts +0 -508
- package/src/lifecycle/index.ts +0 -76
- package/src/lifecycle/types.ts +0 -260
- package/src/map/__tests__/cascade-bridge.test.ts +0 -229
- package/src/map/__tests__/cascade-diff-server.test.ts +0 -434
- package/src/map/__tests__/emit-event.test.ts +0 -71
- package/src/map/__tests__/lifecycle-bridge.test.ts +0 -430
- package/src/map/__tests__/mail-bridge.test.ts +0 -284
- package/src/map/__tests__/permission-forwarding.test.ts +0 -143
- package/src/map/__tests__/sidecar-diff-install-smoke.test.ts +0 -90
- package/src/map/__tests__/sidecar-integration.test.ts +0 -190
- package/src/map/__tests__/task-bridge.test.ts +0 -153
- package/src/map/__tests__/trajectory-reporter.test.ts +0 -173
- package/src/map/acp-bridge.ts +0 -293
- package/src/map/cascade-action-handler.ts +0 -205
- package/src/map/cascade-bridge.ts +0 -339
- package/src/map/cascade-diff-server.ts +0 -404
- package/src/map/cc-swarm-hooks.ts +0 -242
- package/src/map/coordination-handler.ts +0 -232
- package/src/map/index.ts +0 -18
- package/src/map/lifecycle-bridge.ts +0 -236
- package/src/map/mail-bridge.ts +0 -215
- package/src/map/repo-workspace.ts +0 -82
- package/src/map/server.ts +0 -758
- package/src/map/sidecar.ts +0 -826
- package/src/map/task-bridge.ts +0 -89
- package/src/map/trajectory-reporter.ts +0 -124
- package/src/map/types.ts +0 -304
- package/src/mcp/__tests__/mcp-server-v2.test.ts +0 -236
- package/src/mcp/index.ts +0 -6
- package/src/mcp/mcp-server-v2.ts +0 -485
- package/src/mcp/tools/done-v2.ts +0 -213
- package/src/mcp/types.ts +0 -432
- package/src/metrics/__tests__/metrics.test.ts +0 -205
- package/src/metrics/index.ts +0 -13
- package/src/metrics/metrics.ts +0 -151
- package/src/metrics/types.ts +0 -63
- package/src/roles/__tests__/config-loader.test.ts +0 -540
- package/src/roles/builtin/coordinator.ts +0 -75
- package/src/roles/builtin/generic.ts +0 -39
- package/src/roles/builtin/index.ts +0 -51
- package/src/roles/builtin/integrator.ts +0 -62
- package/src/roles/builtin/monitor.ts +0 -65
- package/src/roles/builtin/worker.ts +0 -134
- package/src/roles/capabilities.ts +0 -257
- package/src/roles/config-loader.ts +0 -405
- package/src/roles/index.ts +0 -141
- package/src/roles/registry.ts +0 -713
- package/src/roles/types.ts +0 -344
- package/src/store/index.ts +0 -8
- package/src/store/types/agents.ts +0 -69
- package/src/store/types/events.ts +0 -91
- package/src/store/types/index.ts +0 -9
- package/src/store/types/messages.ts +0 -32
- package/src/store/types/primitives.ts +0 -9
- package/src/store/types/tasks.ts +0 -124
- package/src/teams/__tests__/team-manager-v2.test.ts +0 -425
- package/src/teams/__tests__/team-runtime-v2.test.ts +0 -402
- package/src/teams/index.ts +0 -29
- package/src/teams/seed-defaults.ts +0 -83
- package/src/teams/team-loader.ts +0 -476
- package/src/teams/team-manager-v2.ts +0 -343
- package/src/teams/team-runtime-v2.ts +0 -920
- package/src/teams/types.ts +0 -276
- package/src/trigger/__tests__/cron-service.test.ts +0 -548
- package/src/trigger/__tests__/scheduler.test.ts +0 -371
- package/src/trigger/__tests__/system-event-queue.test.ts +0 -147
- package/src/trigger/__tests__/trigger-system-v2.test.ts +0 -257
- package/src/trigger/__tests__/wake-manager.test.ts +0 -356
- package/src/trigger/__tests__/webhook-handler.test.ts +0 -567
- package/src/trigger/index.ts +0 -110
- package/src/trigger/queue/index.ts +0 -21
- package/src/trigger/queue/system-event-queue.ts +0 -232
- package/src/trigger/queue/types.ts +0 -149
- package/src/trigger/sources/cron/cron-service.ts +0 -499
- package/src/trigger/sources/cron/index.ts +0 -41
- package/src/trigger/sources/cron/scheduler.ts +0 -344
- package/src/trigger/sources/cron/types.ts +0 -333
- package/src/trigger/sources/index.ts +0 -10
- package/src/trigger/sources/webhook/index.ts +0 -25
- package/src/trigger/sources/webhook/types.ts +0 -205
- package/src/trigger/sources/webhook/webhook-handler.ts +0 -410
- package/src/trigger/strategies/ai-router.ts +0 -170
- package/src/trigger/trigger-system-v2.ts +0 -536
- package/src/trigger/types.ts +0 -228
- package/src/trigger/wake/index.ts +0 -22
- package/src/trigger/wake/types.ts +0 -162
- package/src/trigger/wake/wake-manager.ts +0 -390
- package/src/workspace/__tests__/git-cascade-adapter.test.ts +0 -563
- package/src/workspace/__tests__/land-dispatch.test.ts +0 -214
- package/src/workspace/__tests__/self-driving-yaml.test.ts +0 -122
- package/src/workspace/__tests__/shared-worktree-refcount.test.ts +0 -154
- package/src/workspace/__tests__/standalone-mode.test.ts +0 -118
- package/src/workspace/__tests__/workspace-manager-v3.test.ts +0 -245
- package/src/workspace/__tests__/yaml-schema.test.ts +0 -210
- package/src/workspace/config.ts +0 -165
- package/src/workspace/git-cascade-adapter.ts +0 -1213
- package/src/workspace/index.ts +0 -110
- package/src/workspace/landing/__tests__/strategies.test.ts +0 -184
- package/src/workspace/landing/direct-push.ts +0 -91
- package/src/workspace/landing/index.ts +0 -40
- package/src/workspace/landing/merge-to-parent.ts +0 -229
- package/src/workspace/landing/optimistic-push.ts +0 -36
- package/src/workspace/landing/queue-to-branch.ts +0 -108
- package/src/workspace/merge-queue/__tests__/conflict-resolution-git.e2e.test.ts +0 -641
- package/src/workspace/merge-queue/__tests__/conflict-resolution.test.ts +0 -707
- package/src/workspace/merge-queue/__tests__/merge-queue-concurrent.test.ts +0 -628
- package/src/workspace/merge-queue/__tests__/merge-queue-edge-cases.test.ts +0 -1217
- package/src/workspace/merge-queue/__tests__/merge-queue.test.ts +0 -506
- package/src/workspace/merge-queue/__tests__/real-git-operations.e2e.test.ts +0 -556
- package/src/workspace/merge-queue/__tests__/resolver-flow.test.ts +0 -472
- package/src/workspace/merge-queue/index.ts +0 -38
- package/src/workspace/merge-queue/merge-queue.ts +0 -585
- package/src/workspace/merge-queue/schema.ts +0 -98
- package/src/workspace/merge-queue/types.ts +0 -316
- package/src/workspace/pool/__tests__/worktree-pool.integration.test.ts +0 -1281
- package/src/workspace/pool/__tests__/worktree-pool.test.ts +0 -590
- package/src/workspace/pool/index.ts +0 -26
- package/src/workspace/pool/types.ts +0 -276
- package/src/workspace/pool/worktree-pool.ts +0 -659
- package/src/workspace/recovery/__tests__/auto-resolve-integration.test.ts +0 -127
- package/src/workspace/recovery/__tests__/spawn-resolver.test.ts +0 -139
- package/src/workspace/recovery/__tests__/strategies.test.ts +0 -145
- package/src/workspace/recovery/abandon.ts +0 -51
- package/src/workspace/recovery/auto-resolve.ts +0 -119
- package/src/workspace/recovery/defer.ts +0 -23
- package/src/workspace/recovery/escalate.ts +0 -30
- package/src/workspace/recovery/index.ts +0 -58
- package/src/workspace/recovery/spawn-resolver.ts +0 -152
- package/src/workspace/recovery/types.ts +0 -54
- package/src/workspace/strategies/index.ts +0 -18
- package/src/workspace/strategies/optimistic.ts +0 -139
- package/src/workspace/strategies/queue.ts +0 -81
- package/src/workspace/strategies/registry.ts +0 -89
- package/src/workspace/strategies/trunk.ts +0 -123
- package/src/workspace/strategies/types.ts +0 -145
- package/src/workspace/topology/__tests__/yaml-driven.test.ts +0 -345
- package/src/workspace/topology/index.ts +0 -18
- package/src/workspace/topology/no-workspace.ts +0 -39
- package/src/workspace/topology/types.ts +0 -116
- package/src/workspace/topology/yaml-driven.ts +0 -316
- package/src/workspace/types-v3.ts +0 -162
- package/src/workspace/types.ts +0 -541
- package/src/workspace/workspace-manager.ts +0 -1577
- package/src/workspace/yaml-schema.ts +0 -216
- package/test_fixtures/README.md +0 -425
- package/test_fixtures/fixtures/behaviors/coordinators.ts +0 -196
- package/test_fixtures/fixtures/behaviors/index.ts +0 -62
- package/test_fixtures/fixtures/behaviors/integrators.ts +0 -143
- package/test_fixtures/fixtures/behaviors/monitors.ts +0 -199
- package/test_fixtures/fixtures/behaviors/workers.ts +0 -348
- package/test_fixtures/fixtures/index.ts +0 -7
- package/test_fixtures/fixtures/projects/index.ts +0 -23
- package/test_fixtures/fixtures/projects/project-with-specs.ts +0 -44
- package/test_fixtures/fixtures/projects/typescript-project.ts +0 -200
- package/test_fixtures/fixtures/repos/index.ts +0 -6
- package/test_fixtures/fixtures/repos/temp-repo-factory.ts +0 -299
- package/test_fixtures/fixtures/repos/types.ts +0 -174
- package/test_fixtures/harness/assertions/harness-assertions.ts +0 -752
- package/test_fixtures/harness/assertions/index.ts +0 -8
- package/test_fixtures/harness/index.ts +0 -15
- package/test_fixtures/harness/simulator/agent-simulator.ts +0 -768
- package/test_fixtures/harness/simulator/behavior-executor.ts +0 -580
- package/test_fixtures/harness/simulator/index.ts +0 -14
- package/test_fixtures/harness/simulator/types.ts +0 -459
- package/test_fixtures/harness/test-harness.ts +0 -770
- package/test_fixtures/harness/timing/event-stepper.ts +0 -344
- package/test_fixtures/harness/timing/index.ts +0 -8
- package/tsconfig.json +0 -21
- package/vitest.config.ts +0 -30
- package/vitest.e2e.config.ts +0 -28
- package/vitest.setup.ts +0 -12
|
@@ -0,0 +1,1027 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server Factory
|
|
3
|
+
*
|
|
4
|
+
* Creates per-agent MCP server instances with context baked in.
|
|
5
|
+
* Each agent gets its own MCP server with tools that know the calling agent's identity.
|
|
6
|
+
*/
|
|
7
|
+
import * as fs from "fs";
|
|
8
|
+
import * as path from "path";
|
|
9
|
+
import * as os from "os";
|
|
10
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { MCPToolError } from "./types.js";
|
|
14
|
+
import { DoneSchema, createDoneHandler, DONE_TOOL_INFO, } from "./tools/done.js";
|
|
15
|
+
import { WaitForActivitySchema, createWaitForActivityHandler, WAIT_FOR_ACTIVITY_TOOL_INFO, } from "./tools/wait_for_activity.js";
|
|
16
|
+
import { InjectContextSchema, createInjectContextHandler, formatInjectContextResult, INJECT_CONTEXT_TOOL_INFO, } from "./tools/inject_context.js";
|
|
17
|
+
import { ClaimTaskSchema, createClaimTaskHandler, CLAIM_TASK_TOOL_INFO, } from "./tools/claim_task.js";
|
|
18
|
+
import { UnclaimTaskSchema, createUnclaimTaskHandler, UNCLAIM_TASK_TOOL_INFO, } from "./tools/unclaim_task.js";
|
|
19
|
+
import { ListClaimableTasksSchema, createListClaimableTasksHandler, LIST_CLAIMABLE_TASKS_TOOL_INFO, } from "./tools/list_claimable_tasks.js";
|
|
20
|
+
import { DefaultRoleRegistry } from "../roles/registry.js";
|
|
21
|
+
import { isToolAllowedForRole, getRequiredCapabilityForTool, } from "../roles/registry.js";
|
|
22
|
+
// Debug logging to file (since stderr doesn't show up from MCP subprocess)
|
|
23
|
+
const debugLogPath = path.join(os.tmpdir(), "macro-agent-mcp-debug.log");
|
|
24
|
+
function debugLog(message) {
|
|
25
|
+
const timestamp = new Date().toISOString();
|
|
26
|
+
const line = `[${timestamp}] ${message}\n`;
|
|
27
|
+
fs.appendFileSync(debugLogPath, line);
|
|
28
|
+
console.error(message); // Also log to stderr in case it's visible
|
|
29
|
+
}
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────
|
|
31
|
+
// Schema Definitions (using Zod for MCP SDK compatibility)
|
|
32
|
+
// ─────────────────────────────────────────────────────────────────
|
|
33
|
+
const SpawnAgentSchema = {
|
|
34
|
+
task: z.string().describe("Task description for the child agent"),
|
|
35
|
+
subscribe_parent: z
|
|
36
|
+
.boolean()
|
|
37
|
+
.optional()
|
|
38
|
+
.default(true)
|
|
39
|
+
.describe("Whether parent subscribes to child's subtree"),
|
|
40
|
+
topics: z
|
|
41
|
+
.array(z.string())
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Additional topics for child to subscribe to"),
|
|
44
|
+
config: z
|
|
45
|
+
.object({
|
|
46
|
+
model: z.string().optional(),
|
|
47
|
+
maxTokens: z.number().optional(),
|
|
48
|
+
temperature: z.number().optional(),
|
|
49
|
+
})
|
|
50
|
+
.optional()
|
|
51
|
+
.describe("Custom config for the child agent"),
|
|
52
|
+
cwd: z
|
|
53
|
+
.string()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe("Working directory for the spawned agent (defaults to parent's cwd)"),
|
|
56
|
+
};
|
|
57
|
+
const EmitStatusSchema = {
|
|
58
|
+
status_type: z
|
|
59
|
+
.enum(["started", "checkpoint", "completed", "failed", "blocked"])
|
|
60
|
+
.describe("Type of status update"),
|
|
61
|
+
summary: z.string().describe("Human-readable summary"),
|
|
62
|
+
details: z
|
|
63
|
+
.record(z.string(), z.unknown())
|
|
64
|
+
.optional()
|
|
65
|
+
.describe("Additional structured details"),
|
|
66
|
+
complete_task: z
|
|
67
|
+
.boolean()
|
|
68
|
+
.optional()
|
|
69
|
+
.describe("If true and status_type is 'completed', also mark task as completed"),
|
|
70
|
+
};
|
|
71
|
+
const SendMessageSchema = {
|
|
72
|
+
to: z
|
|
73
|
+
.object({
|
|
74
|
+
agent_id: z.string().optional(),
|
|
75
|
+
task_id: z.string().optional(),
|
|
76
|
+
topic: z.string().optional(),
|
|
77
|
+
})
|
|
78
|
+
.describe("Message target"),
|
|
79
|
+
content: z.string().describe("Message content"),
|
|
80
|
+
correlation_id: z.string().optional().describe("Optional correlation ID for threading"),
|
|
81
|
+
};
|
|
82
|
+
const CheckMessagesSchema = {
|
|
83
|
+
limit: z
|
|
84
|
+
.number()
|
|
85
|
+
.optional()
|
|
86
|
+
.default(10)
|
|
87
|
+
.describe("Maximum number of messages to return"),
|
|
88
|
+
include_acknowledged: z
|
|
89
|
+
.boolean()
|
|
90
|
+
.optional()
|
|
91
|
+
.default(false)
|
|
92
|
+
.describe("Include acknowledged messages"),
|
|
93
|
+
};
|
|
94
|
+
const QueryIndexSchema = {
|
|
95
|
+
type: z.enum(["agents", "tasks", "all"]).describe("Type of entities to search"),
|
|
96
|
+
filter: z
|
|
97
|
+
.object({
|
|
98
|
+
state: z.enum(["running", "stopped", "spawning"]).optional(),
|
|
99
|
+
status: z
|
|
100
|
+
.enum(["pending", "assigned", "in_progress", "completed", "failed"])
|
|
101
|
+
.optional(),
|
|
102
|
+
parent: z.string().nullable().optional(),
|
|
103
|
+
})
|
|
104
|
+
.optional()
|
|
105
|
+
.describe("Filter criteria"),
|
|
106
|
+
search: z.string().optional().describe("Text search query"),
|
|
107
|
+
limit: z.number().optional().default(20).describe("Maximum results"),
|
|
108
|
+
offset: z.number().optional().default(0).describe("Offset for pagination"),
|
|
109
|
+
};
|
|
110
|
+
const GetHierarchySchema = {
|
|
111
|
+
root: z.string().optional().describe("Root agent ID (defaults to caller's hierarchy root)"),
|
|
112
|
+
depth: z.number().optional().describe("Maximum depth to traverse"),
|
|
113
|
+
};
|
|
114
|
+
const GetAgentSummarySchema = {
|
|
115
|
+
agent_id: z.string().describe("Agent ID to look up"),
|
|
116
|
+
};
|
|
117
|
+
const StopAgentSchema = {
|
|
118
|
+
agent_id: z.string().describe("Agent ID to stop (must be in caller's subtree)"),
|
|
119
|
+
reason: z
|
|
120
|
+
.enum(["completed", "failed", "cancelled"])
|
|
121
|
+
.optional()
|
|
122
|
+
.default("cancelled")
|
|
123
|
+
.describe("Reason for stopping"),
|
|
124
|
+
};
|
|
125
|
+
// ─────────────────────────────────────────────────────────────────
|
|
126
|
+
// Peer Communication Schemas
|
|
127
|
+
// ─────────────────────────────────────────────────────────────────
|
|
128
|
+
const SendPeerMessageSchema = {
|
|
129
|
+
to: z.string().describe("Target peer address ('peerId' or 'peerId/agentId')"),
|
|
130
|
+
type: z.string().describe("Message type for routing/handling"),
|
|
131
|
+
payload: z.unknown().describe("Message payload"),
|
|
132
|
+
correlation_id: z.string().optional().describe("Optional correlation ID for relating messages"),
|
|
133
|
+
};
|
|
134
|
+
const SendPeerRequestSchema = {
|
|
135
|
+
to: z.string().describe("Target peer address ('peerId' or 'peerId/agentId')"),
|
|
136
|
+
method: z.string().describe("Request method name"),
|
|
137
|
+
params: z.unknown().optional().describe("Request parameters"),
|
|
138
|
+
timeout: z.number().optional().describe("Timeout hint in milliseconds"),
|
|
139
|
+
};
|
|
140
|
+
const RespondToPeerRequestSchema = {
|
|
141
|
+
request_id: z.string().describe("ID of the request to respond to"),
|
|
142
|
+
result: z.unknown().optional().describe("Success result (mutually exclusive with error)"),
|
|
143
|
+
error: z
|
|
144
|
+
.object({
|
|
145
|
+
code: z.number(),
|
|
146
|
+
message: z.string(),
|
|
147
|
+
data: z.unknown().optional(),
|
|
148
|
+
})
|
|
149
|
+
.optional()
|
|
150
|
+
.describe("Error response (mutually exclusive with result)"),
|
|
151
|
+
};
|
|
152
|
+
// ─────────────────────────────────────────────────────────────────
|
|
153
|
+
// Factory Function
|
|
154
|
+
// ─────────────────────────────────────────────────────────────────
|
|
155
|
+
/**
|
|
156
|
+
* Creates an MCP server instance for a specific agent.
|
|
157
|
+
* The context (agent_id, session_id, etc.) is baked into all tool handlers.
|
|
158
|
+
*/
|
|
159
|
+
export function createMCPServer(context, services, config = {}) {
|
|
160
|
+
const { name = "macro-agent-mcp", version = "1.0.0" } = config;
|
|
161
|
+
const { eventStore, agentManager, taskManager, messageRouter, peerManager, activityWatcher, taskToolProvider, roleRegistry = new DefaultRoleRegistry() } = services;
|
|
162
|
+
// Get excluded tools from tool provider (if any)
|
|
163
|
+
const excludedTools = new Set(taskToolProvider?.getExcludedTools?.() ?? []);
|
|
164
|
+
// ─────────────────────────────────────────────────────────────────
|
|
165
|
+
// Role-Based Tool Filtering
|
|
166
|
+
// ─────────────────────────────────────────────────────────────────
|
|
167
|
+
// Get agent's role and resolve it
|
|
168
|
+
const agent = eventStore.getAgent(context.agent_id);
|
|
169
|
+
const agentRole = agent?.role ?? "worker"; // Default to worker if no role
|
|
170
|
+
const resolvedRole = roleRegistry.resolveRole(agentRole);
|
|
171
|
+
debugLog(`[MCP] Agent ${context.agent_id} has role '${agentRole}'`);
|
|
172
|
+
debugLog(`[MCP] Resolved role capabilities: ${resolvedRole.capabilities?.join(", ") ?? "none"}`);
|
|
173
|
+
/**
|
|
174
|
+
* Check if a tool should be registered based on role permissions
|
|
175
|
+
*/
|
|
176
|
+
function shouldRegisterTool(toolName) {
|
|
177
|
+
// Check backend exclusions first
|
|
178
|
+
if (excludedTools.has(toolName)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
// Check role-based permissions
|
|
182
|
+
const allowed = isToolAllowedForRole(toolName, resolvedRole);
|
|
183
|
+
if (!allowed) {
|
|
184
|
+
const requiredCapability = getRequiredCapabilityForTool(toolName);
|
|
185
|
+
debugLog(`[MCP] Tool '${toolName}' not allowed for role '${agentRole}'` +
|
|
186
|
+
(requiredCapability ? ` (requires: ${requiredCapability})` : ""));
|
|
187
|
+
}
|
|
188
|
+
return allowed;
|
|
189
|
+
}
|
|
190
|
+
// Create MCP server
|
|
191
|
+
const server = new McpServer({ name, version }, {
|
|
192
|
+
capabilities: {
|
|
193
|
+
tools: {},
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
// ─────────────────────────────────────────────────────────────────
|
|
197
|
+
// Tool: spawn_agent
|
|
198
|
+
// ─────────────────────────────────────────────────────────────────
|
|
199
|
+
if (shouldRegisterTool("spawn_agent")) {
|
|
200
|
+
server.registerTool("spawn_agent", {
|
|
201
|
+
description: "Spawn a child agent to work on a subtask",
|
|
202
|
+
inputSchema: SpawnAgentSchema,
|
|
203
|
+
}, async (args) => {
|
|
204
|
+
try {
|
|
205
|
+
// Diagnostic logging to help debug parent-not-found issues
|
|
206
|
+
// First, reload from SQLite to ensure we have the latest data
|
|
207
|
+
await eventStore.reload();
|
|
208
|
+
const parentAgent = eventStore.getAgent(context.agent_id);
|
|
209
|
+
const allAgents = eventStore.listAgents();
|
|
210
|
+
debugLog(`[MCP spawn_agent] Called by agent ${context.agent_id}`);
|
|
211
|
+
debugLog(`[MCP spawn_agent] Parent exists in eventStore (after reload): ${!!parentAgent}`);
|
|
212
|
+
debugLog(`[MCP spawn_agent] Total agents in eventStore: ${allAgents.length}`);
|
|
213
|
+
debugLog(`[MCP spawn_agent] instancePath: ${eventStore.instancePath}`);
|
|
214
|
+
if (allAgents.length > 0) {
|
|
215
|
+
debugLog(`[MCP spawn_agent] Agent IDs: ${allAgents.map(a => a.id).join(', ')}`);
|
|
216
|
+
}
|
|
217
|
+
// Inherit the parent's permission mode so sub-agents respect
|
|
218
|
+
// the same mode (e.g., "interactive") set during initialization.
|
|
219
|
+
// Read from env var since the MCP server is a separate process
|
|
220
|
+
// without access to the macro-agent server's in-memory state.
|
|
221
|
+
const parentPermissionMode = process.env.MACRO_PERMISSION_MODE;
|
|
222
|
+
const spawned = await agentManager.spawn({
|
|
223
|
+
task: args.task,
|
|
224
|
+
parent: context.agent_id,
|
|
225
|
+
subscribeParent: args.subscribe_parent ?? true,
|
|
226
|
+
topics: args.topics ?? [],
|
|
227
|
+
config: args.config,
|
|
228
|
+
cwd: args.cwd ?? context.cwd,
|
|
229
|
+
permissionMode: (parentPermissionMode || undefined),
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
content: [
|
|
233
|
+
{
|
|
234
|
+
type: "text",
|
|
235
|
+
text: JSON.stringify({
|
|
236
|
+
agent_id: spawned.id,
|
|
237
|
+
name: spawned.agent.name,
|
|
238
|
+
task_id: spawned.agent.task_id,
|
|
239
|
+
session_id: spawned.session_id,
|
|
240
|
+
}),
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
// Log more details on failure
|
|
247
|
+
debugLog(`[MCP spawn_agent] FAILED: ${error}`);
|
|
248
|
+
const allAgentsOnError = eventStore.listAgents();
|
|
249
|
+
debugLog(`[MCP spawn_agent] Agents at time of error: ${allAgentsOnError.map(a => a.id).join(', ')}`);
|
|
250
|
+
throw new MCPToolError(`Failed to spawn agent: ${error}`, "SPAWN_FAILED");
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
// ─────────────────────────────────────────────────────────────────
|
|
255
|
+
// Tool: emit_status
|
|
256
|
+
// ─────────────────────────────────────────────────────────────────
|
|
257
|
+
if (shouldRegisterTool("emit_status")) {
|
|
258
|
+
server.registerTool("emit_status", {
|
|
259
|
+
description: "Report a status milestone (started, checkpoint, completed, failed, blocked)",
|
|
260
|
+
inputSchema: EmitStatusSchema,
|
|
261
|
+
}, async (args) => {
|
|
262
|
+
// Emit status event
|
|
263
|
+
const event = eventStore.emit({
|
|
264
|
+
type: "status",
|
|
265
|
+
source: { agent_id: context.agent_id },
|
|
266
|
+
payload: {
|
|
267
|
+
status_type: args.status_type,
|
|
268
|
+
summary: args.summary,
|
|
269
|
+
details: args.details,
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
let taskUpdated = false;
|
|
273
|
+
// If complete_task is true and status is completed, update task
|
|
274
|
+
if (args.complete_task && args.status_type === "completed" && context.task_id) {
|
|
275
|
+
try {
|
|
276
|
+
taskManager.updateStatus(context.task_id, "completed");
|
|
277
|
+
taskUpdated = true;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// Task may not exist or already completed
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// Also update task for failed status if complete_task is true
|
|
284
|
+
if (args.complete_task && args.status_type === "failed" && context.task_id) {
|
|
285
|
+
try {
|
|
286
|
+
taskManager.updateStatus(context.task_id, "failed");
|
|
287
|
+
taskUpdated = true;
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
// Task may not exist
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
// Persist immediately so parent process can detect status via EventStore reload.
|
|
294
|
+
// Required when MCP subprocess runs with disableAutoSave.
|
|
295
|
+
await eventStore.persist();
|
|
296
|
+
return {
|
|
297
|
+
content: [
|
|
298
|
+
{
|
|
299
|
+
type: "text",
|
|
300
|
+
text: JSON.stringify({
|
|
301
|
+
event_id: event.id,
|
|
302
|
+
task_updated: taskUpdated,
|
|
303
|
+
}),
|
|
304
|
+
},
|
|
305
|
+
],
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
// ─────────────────────────────────────────────────────────────────
|
|
310
|
+
// Tool: send_message
|
|
311
|
+
// ─────────────────────────────────────────────────────────────────
|
|
312
|
+
if (shouldRegisterTool("send_message")) {
|
|
313
|
+
server.registerTool("send_message", {
|
|
314
|
+
description: "Send a message to another agent, task, or topic",
|
|
315
|
+
inputSchema: SendMessageSchema,
|
|
316
|
+
}, async (args) => {
|
|
317
|
+
try {
|
|
318
|
+
// Convert legacy target format to MAP Address
|
|
319
|
+
const to = args.to.agent_id
|
|
320
|
+
? { agent: args.to.agent_id }
|
|
321
|
+
: args.to.task_id
|
|
322
|
+
? { task: args.to.task_id }
|
|
323
|
+
: args.to.topic
|
|
324
|
+
? { scope: args.to.topic }
|
|
325
|
+
: null;
|
|
326
|
+
if (!to) {
|
|
327
|
+
throw new MCPToolError("Must specify one of: agent_id, task_id, or topic", "INVALID_INPUT");
|
|
328
|
+
}
|
|
329
|
+
const result = await messageRouter.sendToAddress({
|
|
330
|
+
from: context.agent_id,
|
|
331
|
+
to,
|
|
332
|
+
content: args.content,
|
|
333
|
+
options: args.correlation_id ? { correlationId: args.correlation_id } : undefined,
|
|
334
|
+
});
|
|
335
|
+
return {
|
|
336
|
+
content: [
|
|
337
|
+
{
|
|
338
|
+
type: "text",
|
|
339
|
+
text: JSON.stringify({
|
|
340
|
+
message_id: result.id,
|
|
341
|
+
delivered_to: result.delivered.length,
|
|
342
|
+
}),
|
|
343
|
+
},
|
|
344
|
+
],
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
throw new MCPToolError(`Failed to send message: ${error}`, "ROUTING_FAILED");
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
// ─────────────────────────────────────────────────────────────────
|
|
353
|
+
// Tool: check_messages
|
|
354
|
+
// ─────────────────────────────────────────────────────────────────
|
|
355
|
+
if (shouldRegisterTool("check_messages")) {
|
|
356
|
+
server.registerTool("check_messages", {
|
|
357
|
+
description: "Check pending messages in your inbox (includes both internal and peer messages)",
|
|
358
|
+
inputSchema: CheckMessagesSchema,
|
|
359
|
+
}, async (args) => {
|
|
360
|
+
const limit = args.limit ?? 10;
|
|
361
|
+
// Get internal messages
|
|
362
|
+
const internalMessages = messageRouter.getMessages(context.agent_id, {
|
|
363
|
+
limit: limit,
|
|
364
|
+
includeAcknowledged: args.include_acknowledged ?? false,
|
|
365
|
+
});
|
|
366
|
+
const formattedInternalMessages = internalMessages.map((msg) => {
|
|
367
|
+
const fromAgent = msg.from.agent_id ? agentManager.get(msg.from.agent_id) : undefined;
|
|
368
|
+
return {
|
|
369
|
+
id: msg.id,
|
|
370
|
+
from: `agent:${msg.from.agent_id}`,
|
|
371
|
+
from_name: fromAgent?.name,
|
|
372
|
+
content: msg.content.length > 500 ? msg.content.substring(0, 500) : msg.content,
|
|
373
|
+
timestamp: msg.timestamp,
|
|
374
|
+
truncated: msg.truncated || msg.content.length > 500,
|
|
375
|
+
correlation_id: msg.correlation_id,
|
|
376
|
+
};
|
|
377
|
+
});
|
|
378
|
+
// Get peer messages if peerManager is available
|
|
379
|
+
let formattedPeerMessages = [];
|
|
380
|
+
if (peerManager) {
|
|
381
|
+
const peerMessages = peerManager.getPeerMessages(context.agent_id);
|
|
382
|
+
formattedPeerMessages = peerMessages.map((msg) => ({
|
|
383
|
+
id: msg.id,
|
|
384
|
+
from: msg.from, // Already prefixed with "peer:"
|
|
385
|
+
content: typeof msg.payload === "string"
|
|
386
|
+
? msg.payload.length > 500 ? msg.payload.substring(0, 500) : msg.payload
|
|
387
|
+
: JSON.stringify(msg.payload).substring(0, 500),
|
|
388
|
+
timestamp: msg.timestamp,
|
|
389
|
+
truncated: typeof msg.payload === "string" ? msg.payload.length > 500 : false,
|
|
390
|
+
correlation_id: msg.correlationId,
|
|
391
|
+
is_request: msg.isRequest,
|
|
392
|
+
request_id: msg.requestId,
|
|
393
|
+
}));
|
|
394
|
+
}
|
|
395
|
+
// Combine and sort by timestamp
|
|
396
|
+
const allFormattedMessages = [...formattedInternalMessages, ...formattedPeerMessages]
|
|
397
|
+
.sort((a, b) => a.timestamp - b.timestamp)
|
|
398
|
+
.slice(0, limit);
|
|
399
|
+
// Get total pending counts
|
|
400
|
+
const allInternalMessages = messageRouter.getMessages(context.agent_id, {
|
|
401
|
+
limit: 1000,
|
|
402
|
+
includeAcknowledged: false,
|
|
403
|
+
});
|
|
404
|
+
const allPeerMessages = peerManager ? peerManager.getPeerMessages(context.agent_id) : [];
|
|
405
|
+
return {
|
|
406
|
+
content: [
|
|
407
|
+
{
|
|
408
|
+
type: "text",
|
|
409
|
+
text: JSON.stringify({
|
|
410
|
+
messages: allFormattedMessages,
|
|
411
|
+
total_pending: allInternalMessages.length + allPeerMessages.length,
|
|
412
|
+
}),
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
};
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
// ─────────────────────────────────────────────────────────────────
|
|
419
|
+
// Tool: query_index (always allowed - observability)
|
|
420
|
+
// ─────────────────────────────────────────────────────────────────
|
|
421
|
+
if (shouldRegisterTool("query_index")) {
|
|
422
|
+
server.registerTool("query_index", {
|
|
423
|
+
description: "Search for agents and tasks",
|
|
424
|
+
inputSchema: QueryIndexSchema,
|
|
425
|
+
}, async (args) => {
|
|
426
|
+
const entries = [];
|
|
427
|
+
const limit = args.limit ?? 20;
|
|
428
|
+
const offset = args.offset ?? 0;
|
|
429
|
+
const search = args.search?.toLowerCase();
|
|
430
|
+
// Query agents
|
|
431
|
+
if (args.type === "agents" || args.type === "all") {
|
|
432
|
+
let agents = agentManager.list();
|
|
433
|
+
// Apply filters
|
|
434
|
+
if (args.filter?.state) {
|
|
435
|
+
agents = agents.filter((a) => a.state === args.filter.state);
|
|
436
|
+
}
|
|
437
|
+
if (args.filter?.parent !== undefined) {
|
|
438
|
+
agents = agents.filter((a) => a.parent === args.filter.parent);
|
|
439
|
+
}
|
|
440
|
+
// Apply search
|
|
441
|
+
if (search) {
|
|
442
|
+
agents = agents.filter((a) => a.id.toLowerCase().includes(search) ||
|
|
443
|
+
a.name?.toLowerCase().includes(search) ||
|
|
444
|
+
a.task?.toLowerCase().includes(search));
|
|
445
|
+
}
|
|
446
|
+
for (const agent of agents) {
|
|
447
|
+
entries.push({
|
|
448
|
+
type: "agent",
|
|
449
|
+
id: agent.id,
|
|
450
|
+
name: agent.name,
|
|
451
|
+
summary: agent.task ?? "No task description",
|
|
452
|
+
state: agent.state,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// Query tasks
|
|
457
|
+
if (args.type === "tasks" || args.type === "all") {
|
|
458
|
+
let tasks = taskManager.list();
|
|
459
|
+
// Apply filters
|
|
460
|
+
if (args.filter?.status) {
|
|
461
|
+
tasks = tasks.filter((t) => t.status === args.filter.status);
|
|
462
|
+
}
|
|
463
|
+
// Apply search
|
|
464
|
+
if (search) {
|
|
465
|
+
tasks = tasks.filter((t) => t.id.toLowerCase().includes(search) ||
|
|
466
|
+
t.description.toLowerCase().includes(search));
|
|
467
|
+
}
|
|
468
|
+
for (const task of tasks) {
|
|
469
|
+
entries.push({
|
|
470
|
+
type: "task",
|
|
471
|
+
id: task.id,
|
|
472
|
+
summary: task.description,
|
|
473
|
+
status: task.status,
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// Apply pagination
|
|
478
|
+
const paginatedEntries = entries.slice(offset, offset + limit);
|
|
479
|
+
return {
|
|
480
|
+
content: [
|
|
481
|
+
{
|
|
482
|
+
type: "text",
|
|
483
|
+
text: JSON.stringify({
|
|
484
|
+
entries: paginatedEntries,
|
|
485
|
+
total: entries.length,
|
|
486
|
+
has_more: offset + limit < entries.length,
|
|
487
|
+
}),
|
|
488
|
+
},
|
|
489
|
+
],
|
|
490
|
+
};
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
// ─────────────────────────────────────────────────────────────────
|
|
494
|
+
// Tool: get_hierarchy (always allowed - observability)
|
|
495
|
+
// ─────────────────────────────────────────────────────────────────
|
|
496
|
+
if (shouldRegisterTool("get_hierarchy")) {
|
|
497
|
+
server.registerTool("get_hierarchy", {
|
|
498
|
+
description: "View the agent hierarchy tree",
|
|
499
|
+
inputSchema: GetHierarchySchema,
|
|
500
|
+
}, async (args) => {
|
|
501
|
+
// Determine root
|
|
502
|
+
let rootId;
|
|
503
|
+
if (args.root) {
|
|
504
|
+
rootId = args.root;
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
// Use caller's root (walk up lineage)
|
|
508
|
+
rootId = context.lineage.length > 0 ? context.lineage[0] : context.agent_id;
|
|
509
|
+
}
|
|
510
|
+
const hierarchy = agentManager.getHierarchy(rootId);
|
|
511
|
+
if (!hierarchy) {
|
|
512
|
+
throw new MCPToolError(`Agent not found: ${rootId}`, "AGENT_NOT_FOUND");
|
|
513
|
+
}
|
|
514
|
+
// Convert to output format with depth limit
|
|
515
|
+
function buildNode(node, currentDepth) {
|
|
516
|
+
const shouldIncludeChildren = args.depth === undefined || currentDepth < args.depth;
|
|
517
|
+
return {
|
|
518
|
+
agent_id: node.agent.id,
|
|
519
|
+
name: node.agent.name,
|
|
520
|
+
task: node.agent.task ?? "No task",
|
|
521
|
+
state: node.agent.state,
|
|
522
|
+
children: shouldIncludeChildren
|
|
523
|
+
? node.children.map((c) => buildNode(c, currentDepth + 1))
|
|
524
|
+
: [],
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
const tree = buildNode(hierarchy.root, 1);
|
|
528
|
+
return {
|
|
529
|
+
content: [
|
|
530
|
+
{
|
|
531
|
+
type: "text",
|
|
532
|
+
text: JSON.stringify({
|
|
533
|
+
tree,
|
|
534
|
+
depth: hierarchy.depth,
|
|
535
|
+
total_agents: hierarchy.totalAgents,
|
|
536
|
+
}),
|
|
537
|
+
},
|
|
538
|
+
],
|
|
539
|
+
};
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
// ─────────────────────────────────────────────────────────────────
|
|
543
|
+
// Tool: get_agent_summary (always allowed - observability)
|
|
544
|
+
// ─────────────────────────────────────────────────────────────────
|
|
545
|
+
if (shouldRegisterTool("get_agent_summary")) {
|
|
546
|
+
server.registerTool("get_agent_summary", {
|
|
547
|
+
description: "Get detailed summary of a specific agent",
|
|
548
|
+
inputSchema: GetAgentSummarySchema,
|
|
549
|
+
}, async (args) => {
|
|
550
|
+
const agent = agentManager.get(args.agent_id);
|
|
551
|
+
if (!agent) {
|
|
552
|
+
throw new MCPToolError(`Agent not found: ${args.agent_id}`, "AGENT_NOT_FOUND");
|
|
553
|
+
}
|
|
554
|
+
// Get children count
|
|
555
|
+
const children = agentManager.getChildren(args.agent_id);
|
|
556
|
+
// Get recent status from events
|
|
557
|
+
const statusEvents = eventStore.query({
|
|
558
|
+
type: "status",
|
|
559
|
+
source_agent_id: args.agent_id,
|
|
560
|
+
limit: 1,
|
|
561
|
+
});
|
|
562
|
+
const recentStatus = statusEvents.length > 0
|
|
563
|
+
? {
|
|
564
|
+
type: statusEvents[0].payload.status_type,
|
|
565
|
+
summary: statusEvents[0].payload.summary,
|
|
566
|
+
timestamp: statusEvents[0].timestamp,
|
|
567
|
+
}
|
|
568
|
+
: undefined;
|
|
569
|
+
// Use stopped_at, started_at, or created_at as last activity
|
|
570
|
+
const lastActivity = agent.stopped_at ?? agent.started_at ?? agent.created_at;
|
|
571
|
+
return {
|
|
572
|
+
content: [
|
|
573
|
+
{
|
|
574
|
+
type: "text",
|
|
575
|
+
text: JSON.stringify({
|
|
576
|
+
id: agent.id,
|
|
577
|
+
name: agent.name,
|
|
578
|
+
session_id: agent.session_id,
|
|
579
|
+
task: agent.task ?? "No task",
|
|
580
|
+
state: agent.state,
|
|
581
|
+
parent: agent.parent,
|
|
582
|
+
children_count: children.length,
|
|
583
|
+
last_activity: lastActivity,
|
|
584
|
+
recent_status: recentStatus,
|
|
585
|
+
}),
|
|
586
|
+
},
|
|
587
|
+
],
|
|
588
|
+
};
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
// ─────────────────────────────────────────────────────────────────
|
|
592
|
+
// Tool: stop_agent (requires agent.terminate capability)
|
|
593
|
+
// ─────────────────────────────────────────────────────────────────
|
|
594
|
+
if (shouldRegisterTool("stop_agent")) {
|
|
595
|
+
server.registerTool("stop_agent", {
|
|
596
|
+
description: "Stop a child agent in your subtree",
|
|
597
|
+
inputSchema: StopAgentSchema,
|
|
598
|
+
}, async (args) => {
|
|
599
|
+
const targetAgent = agentManager.get(args.agent_id);
|
|
600
|
+
if (!targetAgent) {
|
|
601
|
+
throw new MCPToolError(`Agent not found: ${args.agent_id}`, "AGENT_NOT_FOUND");
|
|
602
|
+
}
|
|
603
|
+
// Check if target is in caller's subtree
|
|
604
|
+
// Target must have caller in its lineage
|
|
605
|
+
const isInSubtree = args.agent_id === context.agent_id || // Can stop self
|
|
606
|
+
targetAgent.lineage?.includes(context.agent_id);
|
|
607
|
+
if (!isInSubtree) {
|
|
608
|
+
throw new MCPToolError(`Cannot stop agent outside your subtree: ${args.agent_id}`, "NOT_IN_SUBTREE");
|
|
609
|
+
}
|
|
610
|
+
// Collect all agents that will be stopped (target + descendants)
|
|
611
|
+
const stoppedAgents = [];
|
|
612
|
+
async function stopRecursive(agentId) {
|
|
613
|
+
const agent = agentManager.get(agentId);
|
|
614
|
+
if (!agent || agent.state === "stopped")
|
|
615
|
+
return;
|
|
616
|
+
// Stop children first
|
|
617
|
+
const children = agentManager.getChildren(agentId);
|
|
618
|
+
for (const child of children) {
|
|
619
|
+
await stopRecursive(child.id);
|
|
620
|
+
}
|
|
621
|
+
// Capture name before stopping
|
|
622
|
+
const agentName = agent.name;
|
|
623
|
+
await agentManager.terminate(agentId, args.reason ?? "cancelled");
|
|
624
|
+
stoppedAgents.push({ agent_id: agentId, name: agentName });
|
|
625
|
+
}
|
|
626
|
+
await stopRecursive(args.agent_id);
|
|
627
|
+
return {
|
|
628
|
+
content: [
|
|
629
|
+
{
|
|
630
|
+
type: "text",
|
|
631
|
+
text: JSON.stringify({
|
|
632
|
+
success: true,
|
|
633
|
+
stopped_agents: stoppedAgents,
|
|
634
|
+
}),
|
|
635
|
+
},
|
|
636
|
+
],
|
|
637
|
+
};
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
// ─────────────────────────────────────────────────────────────────
|
|
641
|
+
// Tool: send_peer_message (requires msg.send capability)
|
|
642
|
+
// ─────────────────────────────────────────────────────────────────
|
|
643
|
+
if (shouldRegisterTool("send_peer_message")) {
|
|
644
|
+
server.registerTool("send_peer_message", {
|
|
645
|
+
description: "Send a fire-and-forget message to another macro-agent (peer)",
|
|
646
|
+
inputSchema: SendPeerMessageSchema,
|
|
647
|
+
}, async (args) => {
|
|
648
|
+
if (!peerManager || !peerManager.hasTransport()) {
|
|
649
|
+
throw new MCPToolError("Peer communication not available - no transport registered", "NO_PEER_TRANSPORT");
|
|
650
|
+
}
|
|
651
|
+
try {
|
|
652
|
+
await peerManager.sendMessage(context.agent_id, args.to, {
|
|
653
|
+
type: args.type,
|
|
654
|
+
payload: args.payload,
|
|
655
|
+
metadata: args.correlation_id ? { correlationId: args.correlation_id } : undefined,
|
|
656
|
+
});
|
|
657
|
+
return {
|
|
658
|
+
content: [
|
|
659
|
+
{
|
|
660
|
+
type: "text",
|
|
661
|
+
text: JSON.stringify({
|
|
662
|
+
success: true,
|
|
663
|
+
timestamp: Date.now(),
|
|
664
|
+
}),
|
|
665
|
+
},
|
|
666
|
+
],
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
throw new MCPToolError(`Failed to send peer message: ${error}`, "ROUTING_FAILED");
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
// ─────────────────────────────────────────────────────────────────
|
|
675
|
+
// Tool: send_peer_request (always allowed - needs response)
|
|
676
|
+
// ─────────────────────────────────────────────────────────────────
|
|
677
|
+
if (shouldRegisterTool("send_peer_request")) {
|
|
678
|
+
server.registerTool("send_peer_request", {
|
|
679
|
+
description: "Send a request to another macro-agent (peer) and wait for response",
|
|
680
|
+
inputSchema: SendPeerRequestSchema,
|
|
681
|
+
}, async (args) => {
|
|
682
|
+
if (!peerManager || !peerManager.hasTransport()) {
|
|
683
|
+
throw new MCPToolError("Peer communication not available - no transport registered", "NO_PEER_TRANSPORT");
|
|
684
|
+
}
|
|
685
|
+
try {
|
|
686
|
+
const response = await peerManager.sendRequest(context.agent_id, args.to, {
|
|
687
|
+
method: args.method,
|
|
688
|
+
params: args.params,
|
|
689
|
+
timeout: args.timeout,
|
|
690
|
+
});
|
|
691
|
+
return {
|
|
692
|
+
content: [
|
|
693
|
+
{
|
|
694
|
+
type: "text",
|
|
695
|
+
text: JSON.stringify(response),
|
|
696
|
+
},
|
|
697
|
+
],
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
throw new MCPToolError(`Failed to send peer request: ${error}`, "ROUTING_FAILED");
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
}
|
|
705
|
+
// ─────────────────────────────────────────────────────────────────
|
|
706
|
+
// Tool: respond_to_peer_request (always allowed - needs to respond)
|
|
707
|
+
// ─────────────────────────────────────────────────────────────────
|
|
708
|
+
if (shouldRegisterTool("respond_to_peer_request")) {
|
|
709
|
+
server.registerTool("respond_to_peer_request", {
|
|
710
|
+
description: "Respond to an incoming peer request",
|
|
711
|
+
inputSchema: RespondToPeerRequestSchema,
|
|
712
|
+
}, async (args) => {
|
|
713
|
+
if (!peerManager) {
|
|
714
|
+
throw new MCPToolError("Peer communication not available - no transport registered", "NO_PEER_TRANSPORT");
|
|
715
|
+
}
|
|
716
|
+
try {
|
|
717
|
+
peerManager.respondToRequest(context.agent_id, args.request_id, {
|
|
718
|
+
result: args.result,
|
|
719
|
+
error: args.error,
|
|
720
|
+
});
|
|
721
|
+
return {
|
|
722
|
+
content: [
|
|
723
|
+
{
|
|
724
|
+
type: "text",
|
|
725
|
+
text: JSON.stringify({
|
|
726
|
+
success: true,
|
|
727
|
+
}),
|
|
728
|
+
},
|
|
729
|
+
],
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
catch (error) {
|
|
733
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
734
|
+
if (errorMessage.includes("not found")) {
|
|
735
|
+
throw new MCPToolError(`Request not found: ${args.request_id}`, "PEER_REQUEST_NOT_FOUND");
|
|
736
|
+
}
|
|
737
|
+
throw new MCPToolError(`Failed to respond to peer request: ${error}`, "INVALID_INPUT");
|
|
738
|
+
}
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
// ─────────────────────────────────────────────────────────────────
|
|
742
|
+
// Tool: wait_for_activity (always allowed - observability)
|
|
743
|
+
// ─────────────────────────────────────────────────────────────────
|
|
744
|
+
if (activityWatcher && shouldRegisterTool("wait_for_activity")) {
|
|
745
|
+
server.registerTool(WAIT_FOR_ACTIVITY_TOOL_INFO.name, {
|
|
746
|
+
description: WAIT_FOR_ACTIVITY_TOOL_INFO.description,
|
|
747
|
+
inputSchema: WaitForActivitySchema,
|
|
748
|
+
}, async (args) => {
|
|
749
|
+
const handler = createWaitForActivityHandler(context, { activityWatcher });
|
|
750
|
+
try {
|
|
751
|
+
const result = await handler(args);
|
|
752
|
+
return {
|
|
753
|
+
content: [
|
|
754
|
+
{
|
|
755
|
+
type: "text",
|
|
756
|
+
text: JSON.stringify(result),
|
|
757
|
+
},
|
|
758
|
+
],
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
catch (error) {
|
|
762
|
+
throw new MCPToolError(`Failed to wait for activity: ${error instanceof Error ? error.message : error}`, "WAIT_FAILED");
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
// ─────────────────────────────────────────────────────────────────
|
|
767
|
+
// Tool: done (requires lifecycle.done capability)
|
|
768
|
+
// ─────────────────────────────────────────────────────────────────
|
|
769
|
+
if (shouldRegisterTool("done")) {
|
|
770
|
+
server.registerTool(DONE_TOOL_INFO.name, {
|
|
771
|
+
description: DONE_TOOL_INFO.description,
|
|
772
|
+
inputSchema: DoneSchema,
|
|
773
|
+
}, async (args) => {
|
|
774
|
+
debugLog(`[MCP done] Tool called by agent ${context.agent_id} with args: ${JSON.stringify(args)}`);
|
|
775
|
+
const doneHandler = createDoneHandler(context, {
|
|
776
|
+
eventStore,
|
|
777
|
+
agentManager,
|
|
778
|
+
messageRouter,
|
|
779
|
+
taskManager,
|
|
780
|
+
roleRegistry,
|
|
781
|
+
integrationStrategy: services.integrationStrategy,
|
|
782
|
+
taskMode: services.taskMode,
|
|
783
|
+
workspaceManager: services.workspaceManager,
|
|
784
|
+
});
|
|
785
|
+
try {
|
|
786
|
+
const result = await doneHandler(args);
|
|
787
|
+
// Persist events emitted by the done handler (MERGE_REQUEST, WORKER_DONE, etc.)
|
|
788
|
+
// so the main process polling can see them via EventStore reload.
|
|
789
|
+
try {
|
|
790
|
+
await eventStore.persist();
|
|
791
|
+
}
|
|
792
|
+
catch {
|
|
793
|
+
// Best-effort — events may still be picked up on next reload
|
|
794
|
+
}
|
|
795
|
+
// If shouldTerminate is true, schedule termination after this tool returns
|
|
796
|
+
// The agent will be terminated after the tool execution completes
|
|
797
|
+
if (result.shouldTerminate) {
|
|
798
|
+
// Schedule termination via agentManager
|
|
799
|
+
// We use setImmediate to ensure the tool response is sent first
|
|
800
|
+
setImmediate(async () => {
|
|
801
|
+
try {
|
|
802
|
+
await agentManager.terminate(context.agent_id, "completed");
|
|
803
|
+
}
|
|
804
|
+
catch (error) {
|
|
805
|
+
debugLog(`[MCP done] Failed to terminate agent ${context.agent_id}: ${error}`);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
return {
|
|
810
|
+
content: [
|
|
811
|
+
{
|
|
812
|
+
type: "text",
|
|
813
|
+
text: JSON.stringify(result),
|
|
814
|
+
},
|
|
815
|
+
],
|
|
816
|
+
};
|
|
817
|
+
}
|
|
818
|
+
catch (error) {
|
|
819
|
+
throw new MCPToolError(`Failed to execute done: ${error instanceof Error ? error.message : error}`, "INVALID_INPUT");
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
// ─────────────────────────────────────────────────────────────────
|
|
824
|
+
// Tools: claim_task, unclaim_task, list_claimable_tasks (pull model)
|
|
825
|
+
// ─────────────────────────────────────────────────────────────────
|
|
826
|
+
if (services.taskBackend && services.taskMode === "pull" && shouldRegisterTool("claim_task")) {
|
|
827
|
+
server.registerTool(CLAIM_TASK_TOOL_INFO.name, {
|
|
828
|
+
description: CLAIM_TASK_TOOL_INFO.description,
|
|
829
|
+
inputSchema: ClaimTaskSchema,
|
|
830
|
+
}, async (args) => {
|
|
831
|
+
const handler = createClaimTaskHandler(context, {
|
|
832
|
+
taskBackend: services.taskBackend,
|
|
833
|
+
});
|
|
834
|
+
const result = await handler(args);
|
|
835
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
if (services.taskBackend && services.taskMode === "pull" && shouldRegisterTool("unclaim_task")) {
|
|
839
|
+
server.registerTool(UNCLAIM_TASK_TOOL_INFO.name, {
|
|
840
|
+
description: UNCLAIM_TASK_TOOL_INFO.description,
|
|
841
|
+
inputSchema: UnclaimTaskSchema,
|
|
842
|
+
}, async (args) => {
|
|
843
|
+
const handler = createUnclaimTaskHandler(context, {
|
|
844
|
+
taskBackend: services.taskBackend,
|
|
845
|
+
});
|
|
846
|
+
const result = await handler(args);
|
|
847
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
if (services.taskBackend && services.taskMode === "pull" && shouldRegisterTool("list_claimable_tasks")) {
|
|
851
|
+
server.registerTool(LIST_CLAIMABLE_TASKS_TOOL_INFO.name, {
|
|
852
|
+
description: LIST_CLAIMABLE_TASKS_TOOL_INFO.description,
|
|
853
|
+
inputSchema: ListClaimableTasksSchema,
|
|
854
|
+
}, async (args) => {
|
|
855
|
+
const handler = createListClaimableTasksHandler(context, {
|
|
856
|
+
taskBackend: services.taskBackend,
|
|
857
|
+
});
|
|
858
|
+
const result = await handler(args);
|
|
859
|
+
return { content: [{ type: "text", text: JSON.stringify(result) }] };
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
// ─────────────────────────────────────────────────────────────────
|
|
863
|
+
// Tool: inject_context (always allowed - parent-to-child communication)
|
|
864
|
+
// ─────────────────────────────────────────────────────────────────
|
|
865
|
+
if (shouldRegisterTool("inject_context")) {
|
|
866
|
+
server.registerTool(INJECT_CONTEXT_TOOL_INFO.name, {
|
|
867
|
+
description: INJECT_CONTEXT_TOOL_INFO.description,
|
|
868
|
+
inputSchema: InjectContextSchema,
|
|
869
|
+
}, async (args) => {
|
|
870
|
+
const handler = createInjectContextHandler({ agentManager, messageRouter }, context.agent_id);
|
|
871
|
+
try {
|
|
872
|
+
const result = await handler(args);
|
|
873
|
+
return formatInjectContextResult(result);
|
|
874
|
+
}
|
|
875
|
+
catch (error) {
|
|
876
|
+
throw new MCPToolError(`Failed to inject context: ${error instanceof Error ? error.message : error}`, "ROUTING_FAILED");
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
// ─────────────────────────────────────────────────────────────────
|
|
881
|
+
// Task Tool Provider (dynamic tools from backend)
|
|
882
|
+
// ─────────────────────────────────────────────────────────────────
|
|
883
|
+
if (taskToolProvider) {
|
|
884
|
+
const providerTools = taskToolProvider.getTools();
|
|
885
|
+
let registeredCount = 0;
|
|
886
|
+
for (const tool of providerTools) {
|
|
887
|
+
// Check role permissions for each dynamic tool
|
|
888
|
+
if (!shouldRegisterTool(tool.name)) {
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
891
|
+
// Use z.record for flexible input since tool providers define their own schemas
|
|
892
|
+
// The actual validation is done by the tool handler
|
|
893
|
+
server.registerTool(tool.name, {
|
|
894
|
+
description: tool.description,
|
|
895
|
+
inputSchema: {
|
|
896
|
+
params: z.record(z.string(), z.unknown()).optional()
|
|
897
|
+
.describe("Tool parameters (validated by the tool handler)"),
|
|
898
|
+
},
|
|
899
|
+
}, async (args) => {
|
|
900
|
+
try {
|
|
901
|
+
// Pass the params to the handler, or an empty object if not provided
|
|
902
|
+
const result = await tool.handler(args.params ?? args);
|
|
903
|
+
return {
|
|
904
|
+
content: [
|
|
905
|
+
{
|
|
906
|
+
type: "text",
|
|
907
|
+
text: JSON.stringify(result),
|
|
908
|
+
},
|
|
909
|
+
],
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
catch (error) {
|
|
913
|
+
throw new MCPToolError(`Failed to execute ${tool.name}: ${error instanceof Error ? error.message : error}`, "INVALID_INPUT");
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
registeredCount++;
|
|
917
|
+
}
|
|
918
|
+
debugLog(`[MCP] Registered ${registeredCount}/${providerTools.length} tools from task tool provider (filtered by role)`);
|
|
919
|
+
}
|
|
920
|
+
// ─────────────────────────────────────────────────────────────────
|
|
921
|
+
// Server Lifecycle
|
|
922
|
+
// ─────────────────────────────────────────────────────────────────
|
|
923
|
+
let transport = null;
|
|
924
|
+
async function start() {
|
|
925
|
+
transport = new StdioServerTransport();
|
|
926
|
+
await server.connect(transport);
|
|
927
|
+
}
|
|
928
|
+
async function close() {
|
|
929
|
+
if (transport) {
|
|
930
|
+
await server.close();
|
|
931
|
+
transport = null;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return {
|
|
935
|
+
server,
|
|
936
|
+
start,
|
|
937
|
+
close,
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Creates a thin-client MCP server where every tool handler calls
|
|
942
|
+
* the main server via MAP WebSocket RPC instead of using local services.
|
|
943
|
+
*
|
|
944
|
+
* Tool schemas, descriptions, and role filtering remain the same.
|
|
945
|
+
* Only the handler bodies change — they forward to `_macro/mcp/*` extensions.
|
|
946
|
+
*/
|
|
947
|
+
export function createMCPServerThinClient(context, mapCallFn, config = {}) {
|
|
948
|
+
const { name = "macro-agent-mcp", version = "1.0.0" } = config;
|
|
949
|
+
const server = new McpServer({ name, version }, { capabilities: { tools: {} } });
|
|
950
|
+
/**
|
|
951
|
+
* Helper: wrap args with agent context for the bridge handler.
|
|
952
|
+
*/
|
|
953
|
+
function withContext(args) {
|
|
954
|
+
return { ...args, context };
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Helper: create a tool handler that forwards to a MAP bridge extension.
|
|
958
|
+
*/
|
|
959
|
+
function bridgeTool(toolName, schema, description, mapMethod, options) {
|
|
960
|
+
server.registerTool(toolName, { description, inputSchema: schema }, async (args) => {
|
|
961
|
+
try {
|
|
962
|
+
const result = await mapCallFn(mapMethod, withContext(args), options);
|
|
963
|
+
return {
|
|
964
|
+
content: [{ type: "text", text: JSON.stringify(result) }],
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
catch (error) {
|
|
968
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
969
|
+
throw new MCPToolError(`${toolName} failed: ${message}`, "ROUTING_FAILED");
|
|
970
|
+
}
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
// Register all tools pointing to their _macro/mcp/* bridge counterparts
|
|
974
|
+
bridgeTool("spawn_agent", SpawnAgentSchema, "Spawn a child agent to work on a subtask", "_macro/mcp/spawn_agent");
|
|
975
|
+
bridgeTool("emit_status", EmitStatusSchema, "Report a status milestone (started, checkpoint, completed, failed, blocked)", "_macro/mcp/emit_status");
|
|
976
|
+
bridgeTool("send_message", SendMessageSchema, "Send a message to another agent, task, or topic", "_macro/mcp/send_message");
|
|
977
|
+
bridgeTool("check_messages", CheckMessagesSchema, "Check pending messages in your inbox", "_macro/mcp/check_messages");
|
|
978
|
+
bridgeTool("query_index", QueryIndexSchema, "Search for agents and tasks", "_macro/mcp/query_index");
|
|
979
|
+
bridgeTool("get_hierarchy", GetHierarchySchema, "View the agent hierarchy tree", "_macro/mcp/get_hierarchy");
|
|
980
|
+
bridgeTool("get_agent_summary", GetAgentSummarySchema, "Get detailed summary of a specific agent", "_macro/mcp/get_agent_summary");
|
|
981
|
+
bridgeTool("stop_agent", StopAgentSchema, "Stop a child agent in your subtree", "_macro/mcp/stop_agent");
|
|
982
|
+
bridgeTool("done", DoneSchema, DONE_TOOL_INFO.description, "_macro/mcp/done");
|
|
983
|
+
bridgeTool("inject_context", InjectContextSchema, INJECT_CONTEXT_TOOL_INFO.description, "_macro/mcp/inject_context");
|
|
984
|
+
bridgeTool("wait_for_activity", WaitForActivitySchema, WAIT_FOR_ACTIVITY_TOOL_INFO.description, "_macro/mcp/wait_for_activity", { timeoutMs: 65000 }); // Extra buffer for long-poll
|
|
985
|
+
bridgeTool("claim_task", ClaimTaskSchema, CLAIM_TASK_TOOL_INFO.description, "_macro/mcp/claim_task");
|
|
986
|
+
bridgeTool("unclaim_task", UnclaimTaskSchema, UNCLAIM_TASK_TOOL_INFO.description, "_macro/mcp/unclaim_task");
|
|
987
|
+
bridgeTool("list_claimable_tasks", ListClaimableTasksSchema, LIST_CLAIMABLE_TASKS_TOOL_INFO.description, "_macro/mcp/list_claimable_tasks");
|
|
988
|
+
bridgeTool("send_peer_message", SendPeerMessageSchema, "Send a fire-and-forget message to another macro-agent (peer)", "_macro/mcp/send_peer_message");
|
|
989
|
+
bridgeTool("send_peer_request", SendPeerRequestSchema, "Send a request to another macro-agent (peer) and wait for response", "_macro/mcp/send_peer_request");
|
|
990
|
+
bridgeTool("respond_to_peer_request", RespondToPeerRequestSchema, "Respond to an incoming peer request", "_macro/mcp/respond_to_peer_request");
|
|
991
|
+
// ─────────────────────────────────────────────────────────────────
|
|
992
|
+
// Server Lifecycle
|
|
993
|
+
// ─────────────────────────────────────────────────────────────────
|
|
994
|
+
let transport = null;
|
|
995
|
+
async function start() {
|
|
996
|
+
// Discover dynamic task tools from the server before connecting.
|
|
997
|
+
// This ensures we only register tools the server actually supports
|
|
998
|
+
// (e.g. memory backend = 4 tools, OpenTasks = 7 tools, none = 0).
|
|
999
|
+
try {
|
|
1000
|
+
const result = await mapCallFn("_macro/mcp/task_tools_list", withContext({}));
|
|
1001
|
+
if (result?.tools?.length > 0) {
|
|
1002
|
+
const DynamicTaskParamsSchema = {
|
|
1003
|
+
params: z.record(z.string(), z.unknown()).optional()
|
|
1004
|
+
.describe("Tool parameters (validated by the server-side handler)"),
|
|
1005
|
+
};
|
|
1006
|
+
for (const tool of result.tools) {
|
|
1007
|
+
bridgeTool(tool.name, DynamicTaskParamsSchema, tool.description, `_macro/mcp/task_tool/${tool.name}`);
|
|
1008
|
+
}
|
|
1009
|
+
debugLog(`[MCP] Registered ${result.tools.length} dynamic task tools from server`);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
catch (error) {
|
|
1013
|
+
// Server may not support task tools — continue without them
|
|
1014
|
+
debugLog(`[MCP] Failed to discover task tools: ${error instanceof Error ? error.message : error}`);
|
|
1015
|
+
}
|
|
1016
|
+
transport = new StdioServerTransport();
|
|
1017
|
+
await server.connect(transport);
|
|
1018
|
+
}
|
|
1019
|
+
async function close() {
|
|
1020
|
+
if (transport) {
|
|
1021
|
+
await server.close();
|
|
1022
|
+
transport = null;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
return { server, start, close };
|
|
1026
|
+
}
|
|
1027
|
+
//# sourceMappingURL=mcp-server.js.map
|