@bolloon/bolloon-agent 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +462 -0
- package/dist/agents/constraint-layer.js +211 -0
- package/dist/agents/constraint-layer.js.map +1 -0
- package/dist/agents/pi-sdk.js +1199 -0
- package/dist/agents/pi-sdk.js.map +1 -0
- package/dist/agents/protocol.js +229 -0
- package/dist/agents/subagent-manager.js +361 -0
- package/dist/agents/workflow-engine.js +222 -0
- package/dist/agents/workflow-engine.js.map +1 -0
- package/dist/bollharness-integration/bollharness-integration/context-router-judgment.d.ts +48 -0
- package/dist/bollharness-integration/bollharness-integration/context-router-judgment.js +261 -0
- package/dist/bollharness-integration/bollharness-integration/context-router.d.ts +110 -0
- package/dist/bollharness-integration/bollharness-integration/context-router.js +542 -0
- package/dist/bollharness-integration/bollharness-integration/gate-state-machine.d.ts +87 -0
- package/dist/bollharness-integration/bollharness-integration/gate-state-machine.js +231 -0
- package/dist/bollharness-integration/bollharness-integration/gate-transition-hooks.d.ts +30 -0
- package/dist/bollharness-integration/bollharness-integration/gate-transition-hooks.js +91 -0
- package/dist/bollharness-integration/bollharness-integration/guard-checker.d.ts +105 -0
- package/dist/bollharness-integration/bollharness-integration/guard-checker.js +353 -0
- package/dist/bollharness-integration/bollharness-integration/index.d.ts +66 -0
- package/dist/bollharness-integration/bollharness-integration/index.js +32 -0
- package/dist/bollharness-integration/bollharness-integration/integration.d.ts +219 -0
- package/dist/bollharness-integration/bollharness-integration/integration.js +420 -0
- package/dist/bollharness-integration/bollharness-integration/skill-adapter.d.ts +151 -0
- package/dist/bollharness-integration/bollharness-integration/skill-adapter.js +518 -0
- package/dist/bollharness-integration/context-router-judgment.js +269 -0
- package/dist/bollharness-integration/context-router-judgment.js.map +1 -0
- package/dist/bollharness-integration/context-router.js +584 -0
- package/dist/bollharness-integration/context-router.js.map +1 -0
- package/dist/bollharness-integration/gate-state-machine.js +349 -0
- package/dist/bollharness-integration/gate-state-machine.js.map +1 -0
- package/dist/bollharness-integration/gate-transition-hooks.js +136 -0
- package/dist/bollharness-integration/gate-transition-hooks.js.map +1 -0
- package/dist/bollharness-integration/guard-checker.js +400 -0
- package/dist/bollharness-integration/guard-checker.js.map +1 -0
- package/dist/bollharness-integration/index.js +142 -0
- package/dist/bollharness-integration/index.js.map +1 -0
- package/dist/bollharness-integration/integration.js +427 -0
- package/dist/bollharness-integration/integration.js.map +1 -0
- package/dist/bollharness-integration/llm/pi-ai.d.ts +60 -0
- package/dist/bollharness-integration/llm/pi-ai.js +397 -0
- package/dist/bollharness-integration/pi-ecosystem-colony/index.d.ts +153 -0
- package/dist/bollharness-integration/pi-ecosystem-colony/index.js +365 -0
- package/dist/bollharness-integration/pi-ecosystem-goals/index.d.ts +136 -0
- package/dist/bollharness-integration/pi-ecosystem-goals/index.js +458 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/decision.d.ts +117 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/decision.js +300 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.d.ts +78 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.js +291 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/index.d.ts +139 -0
- package/dist/bollharness-integration/pi-ecosystem-judgment/index.js +445 -0
- package/dist/bollharness-integration/pi-ecosystem-mcp/index.d.ts +127 -0
- package/dist/bollharness-integration/pi-ecosystem-mcp/index.js +331 -0
- package/dist/bollharness-integration/pi-ecosystem-subagents/index.d.ts +95 -0
- package/dist/bollharness-integration/pi-ecosystem-subagents/index.js +303 -0
- package/dist/bollharness-integration/skill-adapter.js +564 -0
- package/dist/bollharness-integration/skill-adapter.js.map +1 -0
- package/dist/cli/interface.js +181 -0
- package/dist/constraint-runtime/src/_archive_helper.js +9 -0
- package/dist/constraint-runtime/src/agent/coordinator.js +48 -0
- package/dist/constraint-runtime/src/agent/index.js +1 -0
- package/dist/constraint-runtime/src/assistant/index.js +12 -0
- package/dist/constraint-runtime/src/bootstrap/index.js +12 -0
- package/dist/constraint-runtime/src/bootstrap_graph.js +13 -0
- package/dist/constraint-runtime/src/bridge/index.js +12 -0
- package/dist/constraint-runtime/src/buddy/index.js +12 -0
- package/dist/constraint-runtime/src/cli/index.js +12 -0
- package/dist/constraint-runtime/src/command_graph.js +10 -0
- package/dist/constraint-runtime/src/commands.js +50 -0
- package/dist/constraint-runtime/src/components/index.js +12 -0
- package/dist/constraint-runtime/src/constants/index.js +12 -0
- package/dist/constraint-runtime/src/constraint/budget.js +27 -0
- package/dist/constraint-runtime/src/constraint/budget.js.map +1 -0
- package/dist/constraint-runtime/src/constraint/index.js +2 -0
- package/dist/constraint-runtime/src/constraint/permission.js +25 -0
- package/dist/constraint-runtime/src/constraint/permission.js.map +1 -0
- package/dist/constraint-runtime/src/context.js +30 -0
- package/dist/constraint-runtime/src/coordinator/index.js +12 -0
- package/dist/constraint-runtime/src/cost_hook.js +4 -0
- package/dist/constraint-runtime/src/cost_tracker.js +8 -0
- package/dist/constraint-runtime/src/deferred_init.js +10 -0
- package/dist/constraint-runtime/src/direct_modes.js +6 -0
- package/dist/constraint-runtime/src/dynamic-tool-loader.js +85 -0
- package/dist/constraint-runtime/src/entrypoints/index.js +12 -0
- package/dist/constraint-runtime/src/execution_registry.js +44 -0
- package/dist/constraint-runtime/src/history.js +9 -0
- package/dist/constraint-runtime/src/hooks/index.js +12 -0
- package/dist/constraint-runtime/src/index.js +26 -0
- package/dist/constraint-runtime/src/ink.js +4 -0
- package/dist/constraint-runtime/src/keybindings/index.js +12 -0
- package/dist/constraint-runtime/src/memdir/index.js +12 -0
- package/dist/constraint-runtime/src/migrations/index.js +12 -0
- package/dist/constraint-runtime/src/models.js +3 -0
- package/dist/constraint-runtime/src/models.js.map +1 -0
- package/dist/constraint-runtime/src/moreright/index.js +12 -0
- package/dist/constraint-runtime/src/native_ts/index.js +12 -0
- package/dist/constraint-runtime/src/output_styles/index.js +12 -0
- package/dist/constraint-runtime/src/parity_audit.js +12 -0
- package/dist/constraint-runtime/src/plugins/index.js +12 -0
- package/dist/constraint-runtime/src/port_manifest.js +11 -0
- package/dist/constraint-runtime/src/prefetch.js +9 -0
- package/dist/constraint-runtime/src/query.js +1 -0
- package/dist/constraint-runtime/src/remote/index.js +12 -0
- package/dist/constraint-runtime/src/remote_runtime.js +9 -0
- package/dist/constraint-runtime/src/runtime/index.js +1 -0
- package/dist/constraint-runtime/src/runtime/session.js +35 -0
- package/dist/constraint-runtime/src/schemas/index.js +12 -0
- package/dist/constraint-runtime/src/screens/index.js +12 -0
- package/dist/constraint-runtime/src/server/index.js +12 -0
- package/dist/constraint-runtime/src/services/index.js +12 -0
- package/dist/constraint-runtime/src/session_store.js +22 -0
- package/dist/constraint-runtime/src/setup.js +30 -0
- package/dist/constraint-runtime/src/skills/index.js +1 -0
- package/dist/constraint-runtime/src/skills/skill-registry.js +28 -0
- package/dist/constraint-runtime/src/state/index.js +12 -0
- package/dist/constraint-runtime/src/system_init.js +20 -0
- package/dist/constraint-runtime/src/thinking/engine.js +42 -0
- package/dist/constraint-runtime/src/thinking/index.js +1 -0
- package/dist/constraint-runtime/src/tool_pool.js +8 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/execAdapter.js +7 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/listAdapters.js +7 -0
- package/dist/constraint-runtime/src/tools/OpenCLI/runCommand.js +7 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +5 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +6 -0
- package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +4 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/confirmTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/createTransaction.js +8 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/deploySafe.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/executeTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/getBalance.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.js +6 -0
- package/dist/constraint-runtime/src/tools/SafeSDK/proposeTransaction.js +6 -0
- package/dist/constraint-runtime/src/tools/WalletTools/autoPay.js +29 -0
- package/dist/constraint-runtime/src/tools/WalletTools/createWallet.js +10 -0
- package/dist/constraint-runtime/src/tools/WalletTools/getBalance.js +13 -0
- package/dist/constraint-runtime/src/tools/WalletTools/importWallet.js +22 -0
- package/dist/constraint-runtime/src/tools/WalletTools/sendTransaction.js +25 -0
- package/dist/constraint-runtime/src/tools/WalletTools/signMessage.js +10 -0
- package/dist/constraint-runtime/src/tools/WalletTools/transferToken.js +25 -0
- package/dist/constraint-runtime/src/tools.js +70 -0
- package/dist/constraint-runtime/src/transcript.js +19 -0
- package/dist/constraint-runtime/src/types/index.js +12 -0
- package/dist/constraint-runtime/src/upstream_proxy/index.js +12 -0
- package/dist/constraint-runtime/src/utils/index.js +12 -0
- package/dist/constraint-runtime/src/vim/index.js +12 -0
- package/dist/constraint-runtime/src/voice/index.js +12 -0
- package/dist/constraint-runtime/tests/agent.test.js +16 -0
- package/dist/constraint-runtime/tests/constraint.test.js +41 -0
- package/dist/constraint-runtime/tests/skill.test.js +19 -0
- package/dist/constraint-runtime/tests/thinking.test.js +22 -0
- package/dist/constraints/commands.js +100 -0
- package/dist/constraints/index.js +11 -0
- package/dist/constraints/index.js.map +1 -0
- package/dist/constraints/permissions.js +37 -0
- package/dist/constraints/runtime.js +135 -0
- package/dist/constraints/session.js +48 -0
- package/dist/constraints/system-init.js +51 -0
- package/dist/constraints/tools.js +104 -0
- package/dist/documents/reader.js +104 -0
- package/dist/documents/reader.js.map +1 -0
- package/dist/electron-preload.js +15 -0
- package/dist/electron-preload.js.map +1 -0
- package/dist/electron.js +206 -0
- package/dist/electron.js.map +1 -0
- package/dist/index.js +1053 -0
- package/dist/llm/config-store.js +301 -0
- package/dist/llm/config-store.js.map +1 -0
- package/dist/llm/minimax-provider.js +46 -0
- package/dist/llm/minimax.js +45 -0
- package/dist/llm/pi-ai.js +471 -0
- package/dist/llm/pi-ai.js.map +1 -0
- package/dist/network/agent-network.js +692 -0
- package/dist/network/agent-network.js.map +1 -0
- package/dist/network/iroh-integration.js +117 -0
- package/dist/network/iroh-integration.js.map +1 -0
- package/dist/network/iroh-transport.js +506 -0
- package/dist/network/iroh-transport.js.map +1 -0
- package/dist/network/p2p.js +864 -0
- package/dist/network/p2p.js.map +1 -0
- package/dist/network/storage/adapters/json-adapter.js +401 -0
- package/dist/network/storage/adapters/json-adapter.js.map +1 -0
- package/dist/pi-ecosystem-colony/index.js +426 -0
- package/dist/pi-ecosystem-colony/index.js.map +1 -0
- package/dist/pi-ecosystem-goals/index.js +512 -0
- package/dist/pi-ecosystem-goals/index.js.map +1 -0
- package/dist/pi-ecosystem-judgment/decision.js +318 -0
- package/dist/pi-ecosystem-judgment/decision.js.map +1 -0
- package/dist/pi-ecosystem-judgment/distillation.js +304 -0
- package/dist/pi-ecosystem-judgment/distillation.js.map +1 -0
- package/dist/pi-ecosystem-judgment/human-value-store.js +463 -0
- package/dist/pi-ecosystem-judgment/human-value-store.js.map +1 -0
- package/dist/pi-ecosystem-judgment/index.js +581 -0
- package/dist/pi-ecosystem-judgment/index.js.map +1 -0
- package/dist/pi-ecosystem-judgment/value-injection.js +592 -0
- package/dist/pi-ecosystem-judgment/value-injection.js.map +1 -0
- package/dist/pi-ecosystem-mcp/index.js +385 -0
- package/dist/pi-ecosystem-mcp/index.js.map +1 -0
- package/dist/pi-ecosystem-subagents/index.js +352 -0
- package/dist/pi-ecosystem-subagents/index.js.map +1 -0
- package/dist/runtime/context/minimax-prompt.js +178 -0
- package/dist/runtime/context/sys-prompt.js +1 -0
- package/dist/social/ant-colony/AdaptiveHeartbeat.js +106 -0
- package/dist/social/ant-colony/AdaptiveHeartbeat.js.map +1 -0
- package/dist/social/ant-colony/PheromoneEngine.js +265 -0
- package/dist/social/ant-colony/PheromoneEngine.js.map +1 -0
- package/dist/social/ant-colony/types.js +28 -0
- package/dist/social/ant-colony/types.js.map +1 -0
- package/dist/social/channels/ChannelManager.js +444 -0
- package/dist/social/channels/ChannelManager.js.map +1 -0
- package/dist/social/channels/DiapChannelBridge.js +451 -0
- package/dist/social/channels/DiapChannelBridge.js.map +1 -0
- package/dist/social/channels/InterestMatcher.js +135 -0
- package/dist/social/channels/InterestMatcher.js.map +1 -0
- package/dist/social/channels/types.js +21 -0
- package/dist/social/channels/types.js.map +1 -0
- package/dist/social/global-shared-context.js +368 -0
- package/dist/social/global-shared-context.js.map +1 -0
- package/dist/social/heartbeat.js +865 -0
- package/dist/social/heartbeat.js.map +1 -0
- package/dist/test/constraint-layer.test.js +164 -0
- package/dist/test/global-shared-context.test.js +315 -0
- package/dist/test/pi-sdk.test.js +47 -0
- package/dist/test/set-persona.test.js +38 -0
- package/dist/test/subagent-manager.test.js +276 -0
- package/dist/test/workflow-engine.test.js +87 -0
- package/dist/web/api-config.html +265 -0
- package/dist/web/client.js +1401 -0
- package/dist/web/components/p2p/index.js +357 -0
- package/dist/web/components/p2p/p2p-connection.js +161 -0
- package/dist/web/components/p2p/p2p-identity.js +78 -0
- package/dist/web/components/p2p/p2p-manager.js +82 -0
- package/dist/web/components/p2p/p2p-messages.js +186 -0
- package/dist/web/components/p2p/p2p-store-memory.js +129 -0
- package/dist/web/components/p2p/types.js +23 -0
- package/dist/web/index.html +192 -0
- package/dist/web/server.js +1647 -0
- package/dist/web/server.js.map +1 -0
- package/dist/web/style.css +3260 -0
- package/dist/workflows/collaboration.js +374 -0
- package/dist/workflows/index.js +54 -0
- package/docs/agent-communication.md +333 -0
- package/docs/plans/2026-05-15-document-agent-design.md +479 -0
- package/docs/plans/2026-05-15-document-agent-implementation-plan.md +792 -0
- package/docs/plans/2026-05-16-chat-ui-design.md +86 -0
- package/docs/plans/2026-05-16-constraint-runtime-design.md +106 -0
- package/docs/plans/2026-05-16-constraint-runtime-implementation.md +441 -0
- package/docs//346/225/260/345/255/246/350/276/205/345/212/251/346/231/272/350/203/275/344/275/223-/346/240/270/345/277/203/346/225/210/346/236/234/345/256/232/344/271/211.md +287 -0
- package/package.json +121 -0
- package/scripts/build-web.ts +61 -0
- package/src/agents/constraint-layer.ts +309 -0
- package/src/agents/pi-sdk.ts +1591 -0
- package/src/agents/protocol.ts +304 -0
- package/src/agents/subagent-manager.ts +553 -0
- package/src/agents/workflow-engine.ts +332 -0
- package/src/bollharness/.boll/CLAUDE.md.template +34 -0
- package/src/bollharness/.boll/MANIFEST.yaml +213 -0
- package/src/bollharness/.boll/active-review-agents/.gitkeep +0 -0
- package/src/bollharness/.boll/agents/review-base.yaml +108 -0
- package/src/bollharness/.boll/deploy-allowlist.yaml +38 -0
- package/src/bollharness/.boll/inbox/schema/message-v1.json +99 -0
- package/src/bollharness/.boll/install-staging/.gitkeep +0 -0
- package/src/bollharness/.boll/issue-adapter.yaml +31 -0
- package/src/bollharness/.boll/plugins/boll-mode-toolkit/contracts/mode-contract.md +85 -0
- package/src/bollharness/.boll/plugins/boll-review-toolkit/contracts/evidence-packet-schema.json +102 -0
- package/src/bollharness/.boll/plugins/boll-review-toolkit/contracts/review-contract.yaml +247 -0
- package/src/bollharness/.boll/rules/backend-routes.md +31 -0
- package/src/bollharness/.boll/rules/closure-semantics.md +30 -0
- package/src/bollharness/.boll/rules/env-vars.md +32 -0
- package/src/bollharness/.boll/rules/hanis-protocol.md +145 -0
- package/src/bollharness/.boll/rules/repo-structure.md +42 -0
- package/src/bollharness/.boll/rules/review-agent-isolation.md +73 -0
- package/src/bollharness/.boll/rules/source-of-truth.md +33 -0
- package/src/bollharness/.boll/settings.json +180 -0
- package/src/bollharness/.boll/settings.json.template +31 -0
- package/src/bollharness/.boll/skills/arch/SKILL.md +372 -0
- package/src/bollharness/.boll/skills/bug-pipeline/SKILL.md +168 -0
- package/src/bollharness/.boll/skills/bug-triage/SKILL.md +161 -0
- package/src/bollharness/.boll/skills/context-chains/SKILL.md +250 -0
- package/src/bollharness/.boll/skills/context-chains/context-chain-index.md +48 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/code_change_extractor.ts +142 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/debugging_extractor.ts +126 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/design_extractor.ts +148 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/planning_extractor.ts +162 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/question_extractor.ts +116 -0
- package/src/bollharness/.boll/skills/context-chains/work-type-extractors/review_extractor.ts +136 -0
- package/src/bollharness/.boll/skills/crystal-learn/SKILL.md +93 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-0.md +34 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-1.md +34 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-2.md +35 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-3.md +34 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-4.md +43 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-5.md +34 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-6.md +37 -0
- package/src/bollharness/.boll/skills/crystal-learn/invariants/INV-7.md +46 -0
- package/src/bollharness/.boll/skills/guardian-fixer/PROMPT.md +415 -0
- package/src/bollharness/.boll/skills/guardian-fixer/SKILL.md +320 -0
- package/src/bollharness/.boll/skills/harness-dev/SKILL.md +93 -0
- package/src/bollharness/.boll/skills/harness-dev/examples/README.md +227 -0
- package/src/bollharness/.boll/skills/harness-dev-handoff/SKILL.md +165 -0
- package/src/bollharness/.boll/skills/harness-eng/SKILL.md +110 -0
- package/src/bollharness/.boll/skills/harness-eng-test/SKILL.md +79 -0
- package/src/bollharness/.boll/skills/harness-lab/SKILL.md +170 -0
- package/src/bollharness/.boll/skills/harness-ops/SKILL.md +57 -0
- package/src/bollharness/.boll/skills/harness-voice/SKILL.md +183 -0
- package/src/bollharness/.boll/skills/judgment/SKILL.md +115 -0
- package/src/bollharness/.boll/skills/lead/SKILL.md +245 -0
- package/src/bollharness/.boll/skills/lead/install-wow-harness.md +77 -0
- package/src/bollharness/.boll/skills/lead/ref-review-sop.md +91 -0
- package/src/bollharness/.boll/skills/lead/ref-stages.md +129 -0
- package/src/bollharness/.boll/skills/skill-discovery/SKILL.md +169 -0
- package/src/bollharness/.boll/skills/task-arch/SKILL.md +106 -0
- package/src/bollharness/.boll/skills/toolkit/SKILL.md +57 -0
- package/src/bollharness/.boll/tasks/.gitkeep +0 -0
- package/src/bollharness/.boll/toolkit-index.yaml +112 -0
- package/src/bollharness/.claude/agents/review-base.yaml +108 -0
- package/src/bollharness/.claude/plugins/boll-mode-toolkit/.claude-plugin/plugin.json +44 -0
- package/src/bollharness/.claude/plugins/boll-review-toolkit/.claude-plugin/plugin.json +24 -0
- package/src/bollharness/.claude/plugins/boll-review-toolkit/contracts/evidence-packet-schema.json +102 -0
- package/src/bollharness/.claude/plugins/boll-review-toolkit/contracts/review-contract.yaml +247 -0
- package/src/bollharness/.claude/settings.json +157 -0
- package/src/bollharness/.claude/skills/arch/SKILL.md +64 -0
- package/src/bollharness/.claude/skills/crystal-learn/SKILL.md +93 -0
- package/src/bollharness/.claude/skills/guardian-fixer/PROMPT.md +44 -0
- package/src/bollharness/.claude/skills/guardian-fixer/SKILL.md +324 -0
- package/src/bollharness/.claude/skills/harness-dev/SKILL.md +93 -0
- package/src/bollharness/.claude/skills/harness-dev/examples/README.md +17 -0
- package/src/bollharness/.claude/skills/harness-dev-handoff/SKILL.md +165 -0
- package/src/bollharness/.claude/skills/harness-eng/SKILL.md +183 -0
- package/src/bollharness/.claude/skills/harness-eng-test/SKILL.md +57 -0
- package/src/bollharness/.claude/skills/harness-ops/SKILL.md +57 -0
- package/src/bollharness/.claude/skills/harness-voice/SKILL.md +84 -0
- package/src/bollharness/.claude/skills/lead/INDEX.md +28 -0
- package/src/bollharness/.claude/skills/lead/SKILL.md +24 -0
- package/src/bollharness/.claude/skills/lead/install-wow-harness.md +77 -0
- package/src/bollharness/.claude/skills/lead/ref-review-sop.md +48 -0
- package/src/bollharness/.claude/skills/lead/ref-stages.md +58 -0
- package/src/bollharness/.claude/skills/plan-lock/SKILL.md +74 -0
- package/src/bollharness/.claude/skills/skill-discovery/SKILL.md +120 -0
- package/src/bollharness/.claude/skills/task-arch/SKILL.md +106 -0
- package/src/bollharness/.claude/skills/toolkit/SKILL.md +57 -0
- package/src/bollharness/.claude/skills/toolkit/list.sh +92 -0
- package/src/bollharness/.githooks/pre-commit +21 -0
- package/src/bollharness/.github/workflows/ci.yml +88 -0
- package/src/bollharness/.sanitize-report.json +13 -0
- package/src/bollharness/CLAUDE.md +73 -0
- package/src/bollharness/LICENSE +21 -0
- package/src/bollharness/README.md +143 -0
- package/src/bollharness/README.zh-CN.md +131 -0
- package/src/bollharness/docs/decisions/ADR-030-guard-signal-protocol-and-governance-reload.md +1076 -0
- package/src/bollharness/docs/decisions/ADR-038-harness-optimization-strategy.md +2039 -0
- package/src/bollharness/docs/decisions/ADR-041-codex-claude-code-division-of-labor.md +128 -0
- package/src/bollharness/docs/decisions/ADR-H1-crystal-learn-revival.md +188 -0
- package/src/bollharness/docs/decisions/ADR-H2-identity-isolation.md +183 -0
- package/src/bollharness/docs/decisions/ADR-H3-memory-scope.md +133 -0
- package/src/bollharness/docs/decisions/ADR-H4-prompt-governance.md +146 -0
- package/src/bollharness/docs/decisions/ADR-H5-gate-quantization.md +212 -0
- package/src/bollharness/docs/decisions/ADR-H6-state-file-health.md +211 -0
- package/src/bollharness/docs/decisions/ADR-H8-issue-and-doc-compliance.md +202 -0
- package/src/bollharness/docs/decisions/ADR-H9-mailbox.md +231 -0
- package/src/bollharness/docs/decisions/PLAN-H1-crystal-learn-revival.md +270 -0
- package/src/bollharness/docs/decisions/PLAN-H2-identity-isolation.md +291 -0
- package/src/bollharness/docs/decisions/PLAN-H3-memory-scope.md +228 -0
- package/src/bollharness/docs/decisions/PLAN-H4-prompt-governance.md +227 -0
- package/src/bollharness/docs/decisions/PLAN-H5-gate-quantization.md +239 -0
- package/src/bollharness/docs/decisions/PLAN-H6-state-file-health.md +325 -0
- package/src/bollharness/docs/decisions/PLAN-H8-issue-and-doc-compliance.md +242 -0
- package/src/bollharness/docs/decisions/PLAN-H9-mailbox.md +378 -0
- package/src/bollharness/docs/launch-article-en.md +276 -0
- package/src/bollharness/docs/launch-article-zh.md +305 -0
- package/src/bollharness/docs/practice.html +356 -0
- package/src/bollharness/docs/practice.md +82 -0
- package/src/bollharness/docs/research/round-1/README.md +11 -0
- package/src/bollharness/docs/research/round-2/README.md +11 -0
- package/src/bollharness/docs/research/round-3/README.md +11 -0
- package/src/bollharness/docs/research/round-4/README.md +11 -0
- package/src/bollharness/docs/research/round-5/README.md +11 -0
- package/src/bollharness/docs/research/round-6/README.md +11 -0
- package/src/bollharness/package-lock.json +48 -0
- package/src/bollharness/package.json +20 -0
- package/src/bollharness/reference/SOURCE-COMMIT.txt +3 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/backend-routes.md +268 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/bridge.md +20 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/closure-semantics.md +30 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/coaching.md +13 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/env-vars.md +50 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/hackathon.md +12 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/repo-structure.md +184 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/review-agent-isolation.md +112 -0
- package/src/bollharness/reference/boll-reference/.claude/rules/scenes.md +12 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/arch/SKILL.md +551 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-animation/SKILL.md +26 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-bridge/SKILL.md +227 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-bridge/agents/openai.yaml +4 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-bridge/references/bridge-failure-taxonomy.md +142 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-bridge/references/bridge-validation-ladder.md +107 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-crystal/SKILL.md +893 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-crystal-learn/SKILL.md +89 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-dev/SKILL.md +93 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-dev/examples/README.md +209 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-dev-handoff/SKILL.md +165 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng/SKILL.md +110 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng-frontend/SKILL.md +203 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng-hdc/SKILL.md +27 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng-orchestrator/SKILL.md +28 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng-prompt/SKILL.md +27 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-eng-test/SKILL.md +79 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-lab/SKILL.md +372 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-run/SKILL.md +437 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-ux-appstore/SKILL.md +27 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/boll-voice/SKILL.md +442 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/guardian-fixer/PROMPT.md +421 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/guardian-fixer/SKILL.md +326 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/lead/SKILL.md +155 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/lead/ref-review-sop.md +91 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/lead/ref-stages.md +129 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/nature-designer/output/skill-map-preview.png +0 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/nature-designer/output/skill-map-v2.png +0 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/nature-designer/output/skill-map-v3.png +0 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/nature-designer/output/skill-map-v4.png +0 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/plan-lock/SKILL.md +425 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/plan-lock/ref-three-checks.md +62 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/plan-lock/ref-wp-templates.md +78 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/task-arch/SKILL.md +76 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-graph/SKILL.md +57 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-graph/beads-graph.sh +153 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-init/SKILL.md +52 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-init/beads-auto-link.sh +76 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-sync/SKILL.md +50 -0
- package/src/bollharness/reference/boll-reference/.claude/skills/vibedevteam-sync/beads-sync-proj.sh +108 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/AGENT-PROFILE.md +151 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/COST-STRUCTURE.md +56 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/INDEX.md +76 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/MODULE1-INTENT-FIELD.md +116 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/MODULE2-CRYSTALLIZATION.md +200 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/PRINCIPLES.md +84 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/PROTOCOL-CORE.md +209 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/VISION.md +181 -0
- package/src/bollharness/reference/boll-reference/docs/architecture/discussions/D-01-MARKET-SCENE-PROTOCOL.md +754 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/.sanitize-report.json +12 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/find-boll-root.sh +27 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/precompact.sh +57 -0
- package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +57 -0
- package/src/bollharness/schemas/metrics-jsonl-allowlist.json +67 -0
- package/src/bollharness/scripts/checks/next_decision_number.sh +48 -0
- package/src/bollharness/scripts/ci/count-components.sh +65 -0
- package/src/bollharness/scripts/context-fragments/artifact-linkage.md +14 -0
- package/src/bollharness/scripts/context-fragments/auth-consumers.md +17 -0
- package/src/bollharness/scripts/context-fragments/bridge-constitution.md +13 -0
- package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +18 -0
- package/src/bollharness/scripts/context-fragments/closure-checklist.md +13 -0
- package/src/bollharness/scripts/context-fragments/contract-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/db-shared-structures.md +15 -0
- package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +19 -0
- package/src/bollharness/scripts/context-fragments/general-dev-principles.md +11 -0
- package/src/bollharness/scripts/context-fragments/issue-first.md +8 -0
- package/src/bollharness/scripts/context-fragments/mcp-parity.md +16 -0
- package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +74 -0
- package/src/bollharness/scripts/context-fragments/protocol-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/run-events-consumers.md +15 -0
- package/src/bollharness/scripts/context-fragments/scene-fidelity.md +13 -0
- package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +15 -0
- package/src/bollharness/scripts/context-fragments/two-language.md +15 -0
- package/src/bollharness/scripts/context-fragments/version-sources.md +14 -0
- package/src/bollharness/scripts/hooks/find-project-root.sh +47 -0
- package/src/bollharness/scripts/hooks/inbox-poll.sh +78 -0
- package/src/bollharness/scripts/hooks/precompact.sh +56 -0
- package/src/bollharness/scripts/hooks/stop-evaluator.md +83 -0
- package/src/bollharness/scripts/sync-from-upstream.sh +281 -0
- package/src/bollharness/src/index.ts +5 -0
- package/src/bollharness/src/scripts/checks/check_adr_plan_numbering.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_api_types.ts +52 -0
- package/src/bollharness/src/scripts/checks/check_artifact_link.ts +156 -0
- package/src/bollharness/src/scripts/checks/check_bridge_deps.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_bugfix_binding.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_bugfix_binding_ci.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_doc_file_references.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_doc_freshness.ts +141 -0
- package/src/bollharness/src/scripts/checks/check_doc_links.ts +36 -0
- package/src/bollharness/src/scripts/checks/check_file_existence_claims.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_fragment_integrity.ts +40 -0
- package/src/bollharness/src/scripts/checks/check_hook_installed.ts +70 -0
- package/src/bollharness/src/scripts/checks/check_issue_closure.ts +51 -0
- package/src/bollharness/src/scripts/checks/check_mcp_parity.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_security.ts +54 -0
- package/src/bollharness/src/scripts/checks/check_skill_parity.ts +11 -0
- package/src/bollharness/src/scripts/checks/check_versions.ts +11 -0
- package/src/bollharness/src/scripts/checks/finding.ts +35 -0
- package/src/bollharness/src/scripts/checks/next_decision_number.ts +24 -0
- package/src/bollharness/src/scripts/checks/regenerate_magic_docs.ts +11 -0
- package/src/bollharness/src/scripts/ci/detect_rebaseline_triggers.ts +14 -0
- package/src/bollharness/src/scripts/ci/scan_subprocess_cfg.ts +14 -0
- package/src/bollharness/src/scripts/ci/scan_verify_artifacts.ts +14 -0
- package/src/bollharness/src/scripts/ci/scan_yaml_schema.ts +14 -0
- package/src/bollharness/src/scripts/context_router.ts +76 -0
- package/src/bollharness/src/scripts/deploy-guard.ts +182 -0
- package/src/bollharness/src/scripts/guard-feedback.ts +215 -0
- package/src/bollharness/src/scripts/guard_router.ts +194 -0
- package/src/bollharness/src/scripts/hooks/_hook_output.js +3 -0
- package/src/bollharness/src/scripts/hooks/_hook_output.ts +11 -0
- package/src/bollharness/src/scripts/hooks/auto-python3.ts +10 -0
- package/src/bollharness/src/scripts/hooks/deploy-progress-on-session-end.ts +10 -0
- package/src/bollharness/src/scripts/hooks/failure-analyzer.ts +10 -0
- package/src/bollharness/src/scripts/hooks/gate-judgment-inject.ts +111 -0
- package/src/bollharness/src/scripts/hooks/gate-transition-judgment.ts +74 -0
- package/src/bollharness/src/scripts/hooks/inbox-ack.ts +10 -0
- package/src/bollharness/src/scripts/hooks/inbox-inject-on-start.ts +10 -0
- package/src/bollharness/src/scripts/hooks/inbox-validate.ts +10 -0
- package/src/bollharness/src/scripts/hooks/inbox-write-ledger.ts +10 -0
- package/src/bollharness/src/scripts/hooks/initializer-agent.ts +10 -0
- package/src/bollharness/src/scripts/hooks/loop-detection.ts +83 -0
- package/src/bollharness/src/scripts/hooks/owner-guard.ts +10 -0
- package/src/bollharness/src/scripts/hooks/precompact.ts +10 -0
- package/src/bollharness/src/scripts/hooks/review-agent-gatekeeper.ts +10 -0
- package/src/bollharness/src/scripts/hooks/risk-tracker.ts +121 -0
- package/src/bollharness/src/scripts/hooks/sanitize-on-read.ts +10 -0
- package/src/bollharness/src/scripts/hooks/session-reflection.ts +12 -0
- package/src/bollharness/src/scripts/hooks/session-start-magic-docs.ts +12 -0
- package/src/bollharness/src/scripts/hooks/session-start-reset-risk.ts +12 -0
- package/src/bollharness/src/scripts/hooks/session-start-toolkit-reminder.ts +12 -0
- package/src/bollharness/src/scripts/hooks/stop-evaluator.ts +164 -0
- package/src/bollharness/src/scripts/hooks/tool-call-counter.ts +10 -0
- package/src/bollharness/src/scripts/hooks/trace-analyzer.ts +14 -0
- package/src/bollharness/src/scripts/install/install-trust-token.ts +13 -0
- package/src/bollharness/src/scripts/install/multi_project_registry.ts +13 -0
- package/src/bollharness/src/scripts/install/phase2_auto.ts +28 -0
- package/src/bollharness/src/scripts/install/pre_commit_installer.ts +10 -0
- package/src/bollharness/src/scripts/install/tier_selector.ts +10 -0
- package/src/bollharness/src/scripts/install/transcript_miner.ts +13 -0
- package/src/bollharness/src/scripts/lib/claim_patterns.ts +11 -0
- package/src/bollharness/src/scripts/lib/sanitize_patterns.ts +13 -0
- package/src/bollharness/src/scripts/sanitize.ts +9 -0
- package/src/bollharness/templates/persona/default.json +19 -0
- package/src/bollharness/templates/scaffold/.boll/guard/.gitkeep +0 -0
- package/src/bollharness/templates/scaffold/.boll/metrics/.gitkeep +0 -0
- package/src/bollharness/templates/scaffold/.boll/state/.gitkeep +0 -0
- package/src/bollharness/templates/scaffold/.gitignore.append +16 -0
- package/src/bollharness/templates/scaffold/CLAUDE.md +89 -0
- package/src/bollharness/templates/scaffold/docs/INDEX.md +3 -0
- package/src/bollharness/templates/scaffold/docs/decisions/ADR_TEMPLATE.md +38 -0
- package/src/bollharness/templates/scaffold/docs/decisions/PLAN_TEMPLATE.md +45 -0
- package/src/bollharness/templates/scaffold/docs/decisions/tasks/.gitkeep +2 -0
- package/src/bollharness/templates/scaffold/docs/issues/.gitkeep +0 -0
- package/src/bollharness/templates/scaffold/docs/issues/GUARD_ISSUE_TEMPLATE.md +35 -0
- package/src/bollharness/templates/scaffold/docs/issues/ISSUE_TEMPLATE.md +51 -0
- package/src/bollharness/tsconfig.json +26 -0
- package/src/bollharness-integration/channel-judgment-engine.ts +634 -0
- package/src/bollharness-integration/context-chain-router.ts +474 -0
- package/src/bollharness-integration/context-router-judgment.ts +339 -0
- package/src/bollharness-integration/context-router.ts +583 -0
- package/src/bollharness-integration/gate-state-machine.ts +444 -0
- package/src/bollharness-integration/gate-transition-hooks.ts +137 -0
- package/src/bollharness-integration/guard-checker.ts +451 -0
- package/src/bollharness-integration/index.ts +219 -0
- package/src/bollharness-integration/integration.ts +538 -0
- package/src/bollharness-integration/judgment-prompts.yaml +535 -0
- package/src/bollharness-integration/llm-judgment-engine.ts +712 -0
- package/src/bollharness-integration/skill-adapter.ts +646 -0
- package/src/cli/interface.ts +211 -0
- package/src/constraint-runtime/package-lock.json +48 -0
- package/src/constraint-runtime/package.json +34 -0
- package/src/constraint-runtime/src/_archive_helper.ts +16 -0
- package/src/constraint-runtime/src/agent/coordinator.ts +71 -0
- package/src/constraint-runtime/src/agent/index.ts +1 -0
- package/src/constraint-runtime/src/assistant/index.ts +15 -0
- package/src/constraint-runtime/src/bootstrap/index.ts +15 -0
- package/src/constraint-runtime/src/bootstrap_graph.ts +17 -0
- package/src/constraint-runtime/src/bridge/index.ts +15 -0
- package/src/constraint-runtime/src/buddy/index.ts +15 -0
- package/src/constraint-runtime/src/cli/index.ts +15 -0
- package/src/constraint-runtime/src/command_graph.ts +20 -0
- package/src/constraint-runtime/src/commands.ts +83 -0
- package/src/constraint-runtime/src/components/index.ts +15 -0
- package/src/constraint-runtime/src/constants/index.ts +15 -0
- package/src/constraint-runtime/src/constraint/budget.ts +25 -0
- package/src/constraint-runtime/src/constraint/index.ts +3 -0
- package/src/constraint-runtime/src/constraint/permission.ts +28 -0
- package/src/constraint-runtime/src/context.ts +45 -0
- package/src/constraint-runtime/src/coordinator/index.ts +15 -0
- package/src/constraint-runtime/src/cost_hook.ts +6 -0
- package/src/constraint-runtime/src/cost_tracker.ts +9 -0
- package/src/constraint-runtime/src/deferred_init.ts +18 -0
- package/src/constraint-runtime/src/direct_modes.ts +13 -0
- package/src/constraint-runtime/src/dynamic-tool-loader.ts +115 -0
- package/src/constraint-runtime/src/entrypoints/index.ts +15 -0
- package/src/constraint-runtime/src/execution_registry.ts +41 -0
- package/src/constraint-runtime/src/history.ts +16 -0
- package/src/constraint-runtime/src/hooks/index.ts +15 -0
- package/src/constraint-runtime/src/index.ts +28 -0
- package/src/constraint-runtime/src/ink.ts +4 -0
- package/src/constraint-runtime/src/keybindings/index.ts +15 -0
- package/src/constraint-runtime/src/memdir/index.ts +15 -0
- package/src/constraint-runtime/src/migrations/index.ts +15 -0
- package/src/constraint-runtime/src/models.ts +49 -0
- package/src/constraint-runtime/src/moreright/index.ts +15 -0
- package/src/constraint-runtime/src/native_ts/index.ts +15 -0
- package/src/constraint-runtime/src/output_styles/index.ts +15 -0
- package/src/constraint-runtime/src/parity_audit.ts +23 -0
- package/src/constraint-runtime/src/plugins/index.ts +15 -0
- package/src/constraint-runtime/src/port_manifest.ts +20 -0
- package/src/constraint-runtime/src/prefetch.ts +17 -0
- package/src/constraint-runtime/src/query.ts +7 -0
- package/src/constraint-runtime/src/reference_data/archive_surface_snapshot.json +63 -0
- package/src/constraint-runtime/src/reference_data/commands_snapshot.json +1037 -0
- package/src/constraint-runtime/src/reference_data/subsystems/OpenCLI.json +10 -0
- package/src/constraint-runtime/src/reference_data/subsystems/PolymarketSDK.json +12 -0
- package/src/constraint-runtime/src/reference_data/subsystems/SafeSDK.json +14 -0
- package/src/constraint-runtime/src/reference_data/subsystems/assistant.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/bootstrap.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/bridge.json +32 -0
- package/src/constraint-runtime/src/reference_data/subsystems/buddy.json +13 -0
- package/src/constraint-runtime/src/reference_data/subsystems/cli.json +26 -0
- package/src/constraint-runtime/src/reference_data/subsystems/components.json +32 -0
- package/src/constraint-runtime/src/reference_data/subsystems/constants.json +28 -0
- package/src/constraint-runtime/src/reference_data/subsystems/coordinator.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/entrypoints.json +15 -0
- package/src/constraint-runtime/src/reference_data/subsystems/hooks.json +32 -0
- package/src/constraint-runtime/src/reference_data/subsystems/keybindings.json +21 -0
- package/src/constraint-runtime/src/reference_data/subsystems/memdir.json +15 -0
- package/src/constraint-runtime/src/reference_data/subsystems/migrations.json +18 -0
- package/src/constraint-runtime/src/reference_data/subsystems/moreright.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/native_ts.json +11 -0
- package/src/constraint-runtime/src/reference_data/subsystems/outputStyles.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/plugins.json +9 -0
- package/src/constraint-runtime/src/reference_data/subsystems/remote.json +11 -0
- package/src/constraint-runtime/src/reference_data/subsystems/schemas.json +8 -0
- package/src/constraint-runtime/src/reference_data/subsystems/screens.json +10 -0
- package/src/constraint-runtime/src/reference_data/subsystems/server.json +10 -0
- package/src/constraint-runtime/src/reference_data/subsystems/services.json +32 -0
- package/src/constraint-runtime/src/reference_data/subsystems/skills.json +27 -0
- package/src/constraint-runtime/src/reference_data/subsystems/state.json +13 -0
- package/src/constraint-runtime/src/reference_data/subsystems/types.json +18 -0
- package/src/constraint-runtime/src/reference_data/subsystems/upstreamproxy.json +9 -0
- package/src/constraint-runtime/src/reference_data/subsystems/utils.json +32 -0
- package/src/constraint-runtime/src/reference_data/subsystems/vim.json +12 -0
- package/src/constraint-runtime/src/reference_data/subsystems/voice.json +8 -0
- package/src/constraint-runtime/src/reference_data/tools_snapshot.json +1042 -0
- package/src/constraint-runtime/src/remote/index.ts +15 -0
- package/src/constraint-runtime/src/remote_runtime.ts +17 -0
- package/src/constraint-runtime/src/runtime/index.ts +1 -0
- package/src/constraint-runtime/src/runtime/session.ts +42 -0
- package/src/constraint-runtime/src/schemas/index.ts +15 -0
- package/src/constraint-runtime/src/screens/index.ts +15 -0
- package/src/constraint-runtime/src/server/index.ts +15 -0
- package/src/constraint-runtime/src/services/index.ts +15 -0
- package/src/constraint-runtime/src/session_store.ts +32 -0
- package/src/constraint-runtime/src/setup.ts +50 -0
- package/src/constraint-runtime/src/skills/index.ts +1 -0
- package/src/constraint-runtime/src/skills/skill-registry.ts +40 -0
- package/src/constraint-runtime/src/state/index.ts +15 -0
- package/src/constraint-runtime/src/system_init.ts +21 -0
- package/src/constraint-runtime/src/thinking/engine.ts +61 -0
- package/src/constraint-runtime/src/thinking/index.ts +1 -0
- package/src/constraint-runtime/src/tool_pool.ts +20 -0
- package/src/constraint-runtime/src/tools/OpenCLI/execAdapter.ts +12 -0
- package/src/constraint-runtime/src/tools/OpenCLI/listAdapters.ts +12 -0
- package/src/constraint-runtime/src/tools/OpenCLI/runCommand.ts +13 -0
- package/src/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.ts +10 -0
- package/src/constraint-runtime/src/tools/PolymarketSDK/createOrder.ts +13 -0
- package/src/constraint-runtime/src/tools/PolymarketSDK/getMarket.ts +14 -0
- package/src/constraint-runtime/src/tools/PolymarketSDK/getOrders.ts +10 -0
- package/src/constraint-runtime/src/tools/PolymarketSDK/listMarkets.ts +24 -0
- package/src/constraint-runtime/src/tools/SafeSDK/confirmTransaction.ts +13 -0
- package/src/constraint-runtime/src/tools/SafeSDK/createTransaction.ts +23 -0
- package/src/constraint-runtime/src/tools/SafeSDK/deploySafe.ts +12 -0
- package/src/constraint-runtime/src/tools/SafeSDK/executeTransaction.ts +12 -0
- package/src/constraint-runtime/src/tools/SafeSDK/getBalance.ts +10 -0
- package/src/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.ts +10 -0
- package/src/constraint-runtime/src/tools/SafeSDK/proposeTransaction.ts +14 -0
- package/src/constraint-runtime/src/tools/WalletTools/autoPay.ts +58 -0
- package/src/constraint-runtime/src/tools/WalletTools/createWallet.ts +19 -0
- package/src/constraint-runtime/src/tools/WalletTools/getBalance.ts +28 -0
- package/src/constraint-runtime/src/tools/WalletTools/importWallet.ts +34 -0
- package/src/constraint-runtime/src/tools/WalletTools/sendTransaction.ts +50 -0
- package/src/constraint-runtime/src/tools/WalletTools/signMessage.ts +23 -0
- package/src/constraint-runtime/src/tools/WalletTools/transferToken.ts +49 -0
- package/src/constraint-runtime/src/tools.ts +100 -0
- package/src/constraint-runtime/src/transcript.ts +23 -0
- package/src/constraint-runtime/src/types/index.ts +15 -0
- package/src/constraint-runtime/src/upstream_proxy/index.ts +15 -0
- package/src/constraint-runtime/src/utils/index.ts +15 -0
- package/src/constraint-runtime/src/vim/index.ts +15 -0
- package/src/constraint-runtime/src/voice/index.ts +15 -0
- package/src/constraint-runtime/tests/agent.test.ts +20 -0
- package/src/constraint-runtime/tests/constraint.test.ts +47 -0
- package/src/constraint-runtime/tests/skill.test.ts +23 -0
- package/src/constraint-runtime/tests/thinking.test.ts +28 -0
- package/src/constraint-runtime/tsconfig.json +13 -0
- package/src/constraints/index.ts +6 -0
- package/src/documents/reader.ts +80 -0
- package/src/electron-preload.ts +25 -0
- package/src/electron.ts +200 -0
- package/src/index.ts +1606 -0
- package/src/llm/config-store.ts +312 -0
- package/src/llm/llm-judgment-client.ts +470 -0
- package/src/llm/pi-ai.ts +522 -0
- package/src/network/agent-network.ts +800 -0
- package/src/network/hybrid-messenger.ts +199 -0
- package/src/network/iroh-bootstrap.ts +57 -0
- package/src/network/iroh-discovery.ts +207 -0
- package/src/network/iroh-integration.ts +158 -0
- package/src/network/iroh-transport.ts +594 -0
- package/src/network/p2p.ts +963 -0
- package/src/network/storage/adapters/json-adapter.ts +439 -0
- package/src/network/storage/index.ts +187 -0
- package/src/network/storage/types.ts +166 -0
- package/src/pi-ecosystem/index.ts +453 -0
- package/src/pi-ecosystem-colony/index.ts +482 -0
- package/src/pi-ecosystem-goals/index.ts +585 -0
- package/src/pi-ecosystem-judgment/decision.ts +431 -0
- package/src/pi-ecosystem-judgment/distillation.ts +398 -0
- package/src/pi-ecosystem-judgment/human-value-store.ts +580 -0
- package/src/pi-ecosystem-judgment/index.ts +678 -0
- package/src/pi-ecosystem-judgment/value-injection.ts +744 -0
- package/src/pi-ecosystem-mcp/index.ts +427 -0
- package/src/pi-ecosystem-subagents/index.ts +408 -0
- package/src/social/ant-colony/AdaptiveHeartbeat.ts +131 -0
- package/src/social/ant-colony/PheromoneEngine.ts +302 -0
- package/src/social/ant-colony/index.ts +18 -0
- package/src/social/ant-colony/types.ts +94 -0
- package/src/social/channels/ChannelManager.ts +485 -0
- package/src/social/channels/DiapChannelBridge.ts +501 -0
- package/src/social/channels/InterestMatcher.ts +189 -0
- package/src/social/channels/agent-workflow-config.json +214 -0
- package/src/social/channels/agent-workflow-config.yaml +334 -0
- package/src/social/channels/channel-agent-session.ts +407 -0
- package/src/social/channels/channel-heartbeat-agent.ts +622 -0
- package/src/social/channels/diap-doc-parser.ts +282 -0
- package/src/social/channels/harness-workflow-integrator.ts +594 -0
- package/src/social/channels/index.ts +22 -0
- package/src/social/channels/types.ts +115 -0
- package/src/social/global-shared-context.ts +506 -0
- package/src/social/heartbeat.ts +1041 -0
- package/src/social/persona/enhanced-persona.ts +359 -0
- package/src/test/ai-judgment-test.ts +92 -0
- package/src/test/bollharness-integration.test.ts +398 -0
- package/src/test/channel-agent-multi-dialogue.ts +265 -0
- package/src/test/channel-heartbeat-agent-test.ts +244 -0
- package/src/test/constraint-layer.test.ts +191 -0
- package/src/test/diap-identity-test.ts +222 -0
- package/src/test/diap-quick-test.ts +73 -0
- package/src/test/global-shared-context.test.ts +393 -0
- package/src/test/harness-judgment-injection.test.ts +353 -0
- package/src/test/harness-workflow-integrator-test.ts +285 -0
- package/src/test/human-value-store.test.ts +316 -0
- package/src/test/hybrid-integration-test.ts +126 -0
- package/src/test/hybrid-messenger-verify.ts +68 -0
- package/src/test/iroh-bistream-debug.ts +50 -0
- package/src/test/iroh-communication.test.ts +81 -0
- package/src/test/iroh-debug-test.ts +69 -0
- package/src/test/iroh-diap-test.ts +90 -0
- package/src/test/iroh-direct-connect.ts +65 -0
- package/src/test/iroh-e2e-fixed.ts +106 -0
- package/src/test/iroh-e2e-same-process.ts +83 -0
- package/src/test/iroh-e2e.ts +83 -0
- package/src/test/iroh-final-e2e.ts +84 -0
- package/src/test/iroh-relay-test.ts +46 -0
- package/src/test/iroh-simple-test.ts +49 -0
- package/src/test/iroh-transport-verify.ts +60 -0
- package/src/test/iroh-transport.test.ts +47 -0
- package/src/test/iroh-two-nodes.ts +87 -0
- package/src/test/iroh-verify.ts +55 -0
- package/src/test/judgment-decision.test.ts +373 -0
- package/src/test/llm-judgment-integration.test.ts +257 -0
- package/src/test/p2p-agent-complex-dialogue.ts +490 -0
- package/src/test/p2p-agent-dialogue.ts +423 -0
- package/src/test/p2p-agent-full-bidirectional.ts +686 -0
- package/src/test/p2p-agent-harness-flow.ts +562 -0
- package/src/test/p2p-agent-harness-single.ts +175 -0
- package/src/test/p2p-ai-dialogue-test.ts +374 -0
- package/src/test/p2p-cid-connect-test.ts +245 -0
- package/src/test/p2p-connect-receiver.ts +85 -0
- package/src/test/p2p-iroh-test.ts +214 -0
- package/src/test/p2p-minimal-test.ts +264 -0
- package/src/test/p2p-node-1.ts +172 -0
- package/src/test/p2p-node-2.ts +172 -0
- package/src/test/p2p-server.ts +335 -0
- package/src/test/p2p-two-nodes-test.ts +542 -0
- package/src/test/pi-sdk.test.ts +47 -0
- package/src/test/set-persona.ts +56 -0
- package/src/test/simple.test.ts +11 -0
- package/src/test/storage-integration.test.ts +191 -0
- package/src/test/subagent-manager.test.ts +392 -0
- package/src/test/test-gate-flow.test.ts +92 -0
- package/src/test/workflow-engine.test.ts +101 -0
- package/src/web/api-config.html +265 -0
- package/src/web/client.js +1401 -0
- package/src/web/components/p2p/P2PModal.tsx +328 -0
- package/src/web/components/p2p/index.ts +404 -0
- package/src/web/components/p2p/index.tsx +297 -0
- package/src/web/components/p2p/p2p-connection.ts +186 -0
- package/src/web/components/p2p/p2p-identity.ts +92 -0
- package/src/web/components/p2p/p2p-manager.ts +109 -0
- package/src/web/components/p2p/p2p-messages.ts +219 -0
- package/src/web/components/p2p/p2p-modal.ts +685 -0
- package/src/web/components/p2p/p2p-store-memory.ts +162 -0
- package/src/web/components/p2p/types.ts +112 -0
- package/src/web/design.md +99 -0
- package/src/web/index.html +192 -0
- package/src/web/server.ts +1878 -0
- package/src/web/style.css +3260 -0
- package/src/workflows/collaboration.ts +455 -0
- package/src/workflows/index.ts +64 -0
- package/tsconfig.electron.json +20 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +12 -0
- package//346/203/263/346/263/225.md +79 -0
|
@@ -0,0 +1,1591 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi-SDK - Agent Session for Document Processing
|
|
3
|
+
* Part of OpenClaw dual-layer architecture
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as fs from 'fs/promises';
|
|
7
|
+
import * as fsSync from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { documentReader, DocumentContent } from '../documents/reader.js';
|
|
10
|
+
import { getMinimax } from '../constraints/index.js';
|
|
11
|
+
import { p2pNetwork } from '../network/p2p.js';
|
|
12
|
+
import { ConstraintLayer, WorkflowContext } from './constraint-layer.js';
|
|
13
|
+
import { WorkflowEngine, WorkflowStep, StepResult, Workflow } from './workflow-engine.js';
|
|
14
|
+
import { DeepThinkingEngine, AgentCoordinator, type ThinkResult, type AgentResult } from '@bolloon/constraint-runtime';
|
|
15
|
+
import {
|
|
16
|
+
DiscoveredAgentsManager,
|
|
17
|
+
SocialHeartbeat,
|
|
18
|
+
createSocialHeartbeat,
|
|
19
|
+
getSocialHeartbeat,
|
|
20
|
+
type PersonaDoc,
|
|
21
|
+
type DiscoveredAgent,
|
|
22
|
+
type SessionChannel,
|
|
23
|
+
type SessionMessage,
|
|
24
|
+
type SocialSessionProvider
|
|
25
|
+
} from '../social/heartbeat.js';
|
|
26
|
+
import {
|
|
27
|
+
GlobalSharedContextManager,
|
|
28
|
+
createGlobalSharedContext,
|
|
29
|
+
getGlobalSharedContext,
|
|
30
|
+
type ActionSummary,
|
|
31
|
+
type AgentInfo,
|
|
32
|
+
type CooperationTask,
|
|
33
|
+
type CooperationType,
|
|
34
|
+
type GlobalSharedContext
|
|
35
|
+
} from '../social/global-shared-context.js';
|
|
36
|
+
import { Session, SkillRegistry, saveSession, loadSession, type Skill, type StoredSession } from '@bolloon/constraint-runtime';
|
|
37
|
+
|
|
38
|
+
// Pi Ecosystem Integration (lazy imports - initialized on demand)
|
|
39
|
+
// Functions from: createGoal, getCurrentGoal, completeCurrentGoal, failCurrentGoal, getGoalStats, getQueueSummary
|
|
40
|
+
|
|
41
|
+
export interface AgentSessionConfig {
|
|
42
|
+
cwd: string;
|
|
43
|
+
peerId?: string;
|
|
44
|
+
identityDoc?: IdentityDoc;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface IdentityDoc {
|
|
48
|
+
did: string;
|
|
49
|
+
name: string;
|
|
50
|
+
publicKey: string;
|
|
51
|
+
createdAt: number;
|
|
52
|
+
peerId?: string;
|
|
53
|
+
p2pChannel?: string;
|
|
54
|
+
cid?: string;
|
|
55
|
+
ipnsName?: string;
|
|
56
|
+
walletAddress?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface ImprovementRequest {
|
|
60
|
+
originalPath: string;
|
|
61
|
+
requirements: string;
|
|
62
|
+
context?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type { WorkflowStep, StepResult, Workflow } from './workflow-engine.js';
|
|
66
|
+
export type { ActionSummary, AgentInfo, CooperationTask, CooperationType } from '../social/global-shared-context.js';
|
|
67
|
+
|
|
68
|
+
export interface PiSessionState {
|
|
69
|
+
id: string;
|
|
70
|
+
agentId: string;
|
|
71
|
+
cwd: string;
|
|
72
|
+
startedAt: string;
|
|
73
|
+
lastActive: string;
|
|
74
|
+
tokenUsage?: {
|
|
75
|
+
promptTokens: number;
|
|
76
|
+
completionTokens: number;
|
|
77
|
+
totalTokens: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface PiMemory {
|
|
82
|
+
workingMemory: string[];
|
|
83
|
+
summarizedMemory: string[];
|
|
84
|
+
fileContext: Map<string, string>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const SHARED_SESSION_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'sessions');
|
|
88
|
+
const PERSONA_PATH = path.join(process.env.HOME || '/tmp', '.bolloon', 'persona.json');
|
|
89
|
+
|
|
90
|
+
export class PiSessionManager implements SocialSessionProvider {
|
|
91
|
+
private session: Session;
|
|
92
|
+
private state: PiSessionState;
|
|
93
|
+
private memory: PiMemory;
|
|
94
|
+
private persona: PersonaDoc | null = null;
|
|
95
|
+
private channels: Map<string, SessionChannel> = new Map();
|
|
96
|
+
private channelsPath: string;
|
|
97
|
+
private initialized: boolean = false;
|
|
98
|
+
private sessionDir: string;
|
|
99
|
+
private cwd: string;
|
|
100
|
+
private sharedContext: GlobalSharedContextManager;
|
|
101
|
+
private agentId: string;
|
|
102
|
+
|
|
103
|
+
constructor(agentId: string, cwd: string) {
|
|
104
|
+
this.cwd = cwd;
|
|
105
|
+
this.sessionDir = path.join(cwd, '.port_sessions');
|
|
106
|
+
this.agentId = agentId;
|
|
107
|
+
|
|
108
|
+
const sessionId = `pi-session-${Date.now()}`;
|
|
109
|
+
this.session = new Session(sessionId);
|
|
110
|
+
|
|
111
|
+
this.state = {
|
|
112
|
+
id: sessionId,
|
|
113
|
+
agentId,
|
|
114
|
+
cwd,
|
|
115
|
+
startedAt: new Date().toISOString(),
|
|
116
|
+
lastActive: new Date().toISOString()
|
|
117
|
+
};
|
|
118
|
+
this.memory = {
|
|
119
|
+
workingMemory: [],
|
|
120
|
+
summarizedMemory: [],
|
|
121
|
+
fileContext: new Map()
|
|
122
|
+
};
|
|
123
|
+
this.channelsPath = path.join(SHARED_SESSION_PATH, 'pi-channels.json');
|
|
124
|
+
this.sharedContext = getGlobalSharedContext();
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get sessionId(): string {
|
|
128
|
+
return this.session.sessionId;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get turnCount(): number {
|
|
132
|
+
return this.session.turnCount;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
addSessionMessage(msg: string): void {
|
|
136
|
+
this.session.addMessage(msg);
|
|
137
|
+
this.persistSession();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
getSessionHistory(): string[] {
|
|
141
|
+
return this.session.history;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
setSessionContext(key: string, value: unknown): void {
|
|
145
|
+
this.session.setContext(key, value);
|
|
146
|
+
this.persistSession();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getSessionContext(key: string): unknown {
|
|
150
|
+
return this.session.getContext(key);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private persistSession(): void {
|
|
154
|
+
try {
|
|
155
|
+
const stored: StoredSession = {
|
|
156
|
+
sessionId: this.session.sessionId,
|
|
157
|
+
messages: this.session.history,
|
|
158
|
+
inputTokens: 0,
|
|
159
|
+
outputTokens: 0
|
|
160
|
+
};
|
|
161
|
+
saveSession(stored);
|
|
162
|
+
} catch (e) {
|
|
163
|
+
console.warn('Failed to persist session:', e);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private loadPersistedSession(): void {
|
|
168
|
+
try {
|
|
169
|
+
const sessionId = this.state.id;
|
|
170
|
+
const stored = loadSession(sessionId);
|
|
171
|
+
for (const msg of stored.messages) {
|
|
172
|
+
this.session.addMessage(msg);
|
|
173
|
+
}
|
|
174
|
+
} catch {
|
|
175
|
+
// No persisted session found, start fresh
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
async initialize(): Promise<void> {
|
|
180
|
+
if (this.initialized) return;
|
|
181
|
+
await fs.mkdir(SHARED_SESSION_PATH, { recursive: true });
|
|
182
|
+
await fs.mkdir(this.sessionDir, { recursive: true });
|
|
183
|
+
this.persona = await this.loadPersona();
|
|
184
|
+
await this.loadChannels();
|
|
185
|
+
this.loadPersistedSession();
|
|
186
|
+
await this.sharedContext.initialize();
|
|
187
|
+
|
|
188
|
+
await this.sharedContext.registerAgent({
|
|
189
|
+
agentId: this.agentId,
|
|
190
|
+
sessionId: this.sessionId,
|
|
191
|
+
channelId: 'system',
|
|
192
|
+
capabilities: this.persona?.capabilities || [],
|
|
193
|
+
status: 'active',
|
|
194
|
+
name: this.persona?.name,
|
|
195
|
+
persona: this.persona ? {
|
|
196
|
+
name: this.persona.name,
|
|
197
|
+
description: this.persona.description,
|
|
198
|
+
capabilities: this.persona.capabilities
|
|
199
|
+
} : undefined
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
this.initialized = true;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
private async loadPersona(): Promise<PersonaDoc | null> {
|
|
206
|
+
try {
|
|
207
|
+
const data = await fs.readFile(PERSONA_PATH, 'utf-8');
|
|
208
|
+
return JSON.parse(data) as PersonaDoc;
|
|
209
|
+
} catch {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private async loadChannels(): Promise<void> {
|
|
215
|
+
try {
|
|
216
|
+
const data = await fs.readFile(this.channelsPath, 'utf-8');
|
|
217
|
+
const channelsArray: SessionChannel[] = JSON.parse(data);
|
|
218
|
+
this.channels.clear();
|
|
219
|
+
for (const channel of channelsArray) {
|
|
220
|
+
this.channels.set(channel.id, channel);
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
this.channels.clear();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async saveChannels(): Promise<void> {
|
|
228
|
+
const channelsArray = Array.from(this.channels.values());
|
|
229
|
+
await fs.writeFile(this.channelsPath, JSON.stringify(channelsArray, null, 2));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async savePersona(persona: PersonaDoc): Promise<void> {
|
|
233
|
+
await fs.writeFile(PERSONA_PATH, JSON.stringify(persona, null, 2));
|
|
234
|
+
this.persona = persona;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getPersona(): PersonaDoc | null {
|
|
238
|
+
return this.persona;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
getState(): PiSessionState {
|
|
242
|
+
return { ...this.state, lastActive: new Date().toISOString() };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getMemory(): PiMemory {
|
|
246
|
+
return this.memory;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
addToWorkingMemory(content: string): void {
|
|
250
|
+
this.memory.workingMemory.push(content);
|
|
251
|
+
if (this.memory.workingMemory.length > 100) {
|
|
252
|
+
this.memory.workingMemory = this.memory.workingMemory.slice(-100);
|
|
253
|
+
}
|
|
254
|
+
this.state.lastActive = new Date().toISOString();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
addSummarizedMemory(content: string): void {
|
|
258
|
+
this.memory.summarizedMemory.push(content);
|
|
259
|
+
if (this.memory.summarizedMemory.length > 50) {
|
|
260
|
+
this.memory.summarizedMemory = this.memory.summarizedMemory.slice(-50);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
addFileContext(filePath: string, content: string): void {
|
|
265
|
+
this.memory.fileContext.set(filePath, content);
|
|
266
|
+
if (this.memory.fileContext.size > 20) {
|
|
267
|
+
const entries = Array.from(this.memory.fileContext.entries());
|
|
268
|
+
this.memory.fileContext = new Map(entries.slice(-20));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
updateTokenUsage(promptTokens: number, completionTokens: number): void {
|
|
273
|
+
this.state.tokenUsage = {
|
|
274
|
+
promptTokens: (this.state.tokenUsage?.promptTokens || 0) + promptTokens,
|
|
275
|
+
completionTokens: (this.state.tokenUsage?.completionTokens || 0) + completionTokens,
|
|
276
|
+
totalTokens: (this.state.tokenUsage?.totalTokens || 0) + promptTokens + completionTokens
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async addMessage(channelId: string, message: SessionMessage): Promise<void> {
|
|
281
|
+
await this.initialize();
|
|
282
|
+
|
|
283
|
+
if (!this.channels.has(channelId)) {
|
|
284
|
+
this.channels.set(channelId, {
|
|
285
|
+
id: channelId,
|
|
286
|
+
name: channelId,
|
|
287
|
+
messages: [],
|
|
288
|
+
createdAt: new Date().toISOString(),
|
|
289
|
+
updatedAt: new Date().toISOString()
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const channel = this.channels.get(channelId)!;
|
|
294
|
+
channel.messages.push(message);
|
|
295
|
+
channel.updatedAt = new Date().toISOString();
|
|
296
|
+
await this.saveChannels();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async getChannelMessages(channelId: string): Promise<SessionMessage[]> {
|
|
300
|
+
await this.initialize();
|
|
301
|
+
return this.channels.get(channelId)?.messages || [];
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
async createChannel(name: string, peerInfo?: { peerId?: string; peerDid?: string; peerName?: string }, persona?: PersonaDoc): Promise<SessionChannel> {
|
|
305
|
+
await this.initialize();
|
|
306
|
+
|
|
307
|
+
const channelId = `ch_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
308
|
+
const channel: SessionChannel = {
|
|
309
|
+
id: channelId,
|
|
310
|
+
name,
|
|
311
|
+
messages: [],
|
|
312
|
+
createdAt: new Date().toISOString(),
|
|
313
|
+
updatedAt: new Date().toISOString(),
|
|
314
|
+
...peerInfo,
|
|
315
|
+
persona: persona || undefined
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
this.channels.set(channelId, channel);
|
|
319
|
+
await this.saveChannels();
|
|
320
|
+
return channel;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async getOrCreatePeerChannel(peerDid: string, peerName: string, persona?: PersonaDoc): Promise<SessionChannel> {
|
|
324
|
+
await this.initialize();
|
|
325
|
+
|
|
326
|
+
for (const channel of this.channels.values()) {
|
|
327
|
+
if (channel.peerDid === peerDid) {
|
|
328
|
+
return channel;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return this.createChannel(`与 ${peerName} 的对话`, {
|
|
333
|
+
peerDid,
|
|
334
|
+
peerName
|
|
335
|
+
}, persona);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async setChannelInfo(channelId: string, info: Partial<SessionChannel>): Promise<void> {
|
|
339
|
+
await this.initialize();
|
|
340
|
+
const channel = this.channels.get(channelId);
|
|
341
|
+
if (channel) {
|
|
342
|
+
Object.assign(channel, info, { updatedAt: new Date().toISOString() });
|
|
343
|
+
await this.saveChannels();
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
getAllChannels(): SessionChannel[] {
|
|
348
|
+
return Array.from(this.channels.values());
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
getChannelPersona(channelId: string): PersonaDoc | undefined {
|
|
352
|
+
return this.channels.get(channelId)?.persona;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
async setChannelPersona(channelId: string, persona: PersonaDoc): Promise<void> {
|
|
356
|
+
await this.initialize();
|
|
357
|
+
const channel = this.channels.get(channelId);
|
|
358
|
+
if (channel) {
|
|
359
|
+
channel.persona = persona;
|
|
360
|
+
channel.updatedAt = new Date().toISOString();
|
|
361
|
+
await this.saveChannels();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async addUserActionToSharedContext(content: string, importance?: number): Promise<void> {
|
|
366
|
+
await this.initialize();
|
|
367
|
+
await this.sharedContext.addUserAction(content, this.agentId, undefined, importance);
|
|
368
|
+
await this.sharedContext.updateAgentStatus(this.agentId, 'active');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async addSharedKnowledge(knowledge: string): Promise<void> {
|
|
372
|
+
await this.initialize();
|
|
373
|
+
await this.sharedContext.addSharedKnowledge(knowledge);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
async getRecentActionsSummary(count?: number): Promise<string> {
|
|
377
|
+
return this.sharedContext.getRecentActionsSummary(count);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async getSharedKnowledge(): Promise<string[]> {
|
|
381
|
+
return this.sharedContext.getSharedKnowledge();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
async getGlobalContext(): Promise<GlobalSharedContext> {
|
|
385
|
+
return this.sharedContext.getFullContext();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
async getGlobalContextSummary(): Promise<string> {
|
|
389
|
+
return this.sharedContext.getContextSummary();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async createCooperation(
|
|
393
|
+
type: CooperationType,
|
|
394
|
+
task: string,
|
|
395
|
+
toAgentId?: string,
|
|
396
|
+
context?: string
|
|
397
|
+
): Promise<CooperationTask> {
|
|
398
|
+
await this.initialize();
|
|
399
|
+
return this.sharedContext.createCooperation(type, this.agentId, task, toAgentId, context);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async getPendingCooperations(): Promise<CooperationTask[]> {
|
|
403
|
+
return this.sharedContext.getPendingCooperations(this.agentId);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
async updateCooperationStatus(
|
|
407
|
+
cooperationId: string,
|
|
408
|
+
status: 'pending' | 'in_progress' | 'done' | 'failed',
|
|
409
|
+
result?: string
|
|
410
|
+
): Promise<void> {
|
|
411
|
+
await this.sharedContext.updateCooperationStatus(cooperationId, status, result);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
async getAllRegisteredAgents(): Promise<AgentInfo[]> {
|
|
415
|
+
return this.sharedContext.getAllAgents();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async findAgentByCapability(capability: string): Promise<AgentInfo[]> {
|
|
419
|
+
return this.sharedContext.findAgentByCapability(capability);
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async getCooperation(cooperationId: string): Promise<CooperationTask | undefined> {
|
|
423
|
+
return this.sharedContext.getCooperation(cooperationId);
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
async updateAgentStatusInRegistry(status: 'active' | 'idle' | 'busy'): Promise<void> {
|
|
427
|
+
await this.sharedContext.updateAgentStatus(this.agentId, status);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export interface Tool {
|
|
432
|
+
name: string;
|
|
433
|
+
description: string;
|
|
434
|
+
parameters: Record<string, string>;
|
|
435
|
+
execute: (args: Record<string, string>) => Promise<ToolResult>;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export interface ToolResult {
|
|
439
|
+
success: boolean;
|
|
440
|
+
output?: string;
|
|
441
|
+
error?: string;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
interface Message {
|
|
445
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
446
|
+
content: string;
|
|
447
|
+
toolCall?: {
|
|
448
|
+
name: string;
|
|
449
|
+
args: Record<string, string>;
|
|
450
|
+
};
|
|
451
|
+
toolResult?: ToolResult;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export interface StreamCallback {
|
|
455
|
+
(event: StreamEvent): void;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
export interface StreamEvent {
|
|
459
|
+
type: 'status' | 'thinking' | 'tool' | 'token' | 'done' | 'error';
|
|
460
|
+
content: string;
|
|
461
|
+
tool?: string;
|
|
462
|
+
data?: unknown;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const TOOL_DEFINITIONS = `
|
|
466
|
+
可用工具:
|
|
467
|
+
1. read_document(path) - 读取文档内容,支持 .txt, .md, .pdf, .docx
|
|
468
|
+
2. summarize_document(path, context?) - 总结文档内容,可选提供上下文
|
|
469
|
+
3. improve_document(path, requirements) - 改进文档,需提供文件路径和改进要求
|
|
470
|
+
4. list_peers() - 列出已连接的对等节点
|
|
471
|
+
5. send_message(peer_id, message) - 向指定对等节点发送消息
|
|
472
|
+
6. broadcast_message(message) - 向所有对等节点广播消息
|
|
473
|
+
7. get_identity() - 获取当前智能体身份信息
|
|
474
|
+
8. set_persona(persona_json) - 更新智能体 persona,包含 name、description、personality、greeting 等
|
|
475
|
+
9. run_workflow(steps) - 执行预定义工作流
|
|
476
|
+
10. get_operation_logs() - 获取操作日志
|
|
477
|
+
`;
|
|
478
|
+
|
|
479
|
+
export interface HeartbeatConfig {
|
|
480
|
+
intervalMs: number;
|
|
481
|
+
peerDiscoveryEnabled: boolean;
|
|
482
|
+
ipnsResolveEnabled: boolean;
|
|
483
|
+
autoSocialEnabled: boolean;
|
|
484
|
+
greetingMessage?: string;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export interface AgentSession {
|
|
488
|
+
prompt(input: string): Promise<string>;
|
|
489
|
+
promptStream(input: string, onStream: StreamCallback): Promise<string>;
|
|
490
|
+
suggestRename(messages: { type: string; content: string }[]): Promise<string | null>;
|
|
491
|
+
readDocument(filePath: string): Promise<string>;
|
|
492
|
+
summarizeDocument(filePath: string, context?: string): Promise<{
|
|
493
|
+
summary: string;
|
|
494
|
+
qualityScore: number;
|
|
495
|
+
}>;
|
|
496
|
+
improveDocument(request: ImprovementRequest): Promise<{
|
|
497
|
+
improved: boolean;
|
|
498
|
+
newContent?: string;
|
|
499
|
+
qualityScore: number;
|
|
500
|
+
shouldAutoSend: boolean;
|
|
501
|
+
}>;
|
|
502
|
+
runWorkflow(workflow: WorkflowStep[]): Promise<Workflow>;
|
|
503
|
+
getPeers(): string[];
|
|
504
|
+
sendMessage(peerId: string, message: string): Promise<void>;
|
|
505
|
+
broadcast(message: string): Promise<void>;
|
|
506
|
+
getIdentity(): IdentityDoc;
|
|
507
|
+
updateIdentity(updates: Partial<IdentityDoc>): void;
|
|
508
|
+
getSessionState(): PiSessionState;
|
|
509
|
+
getMemory(): PiMemory;
|
|
510
|
+
getPersona(): PersonaDoc | null;
|
|
511
|
+
setPersona(persona: PersonaDoc): Promise<void>;
|
|
512
|
+
getDiscoveredAgents(): DiscoveredAgent[];
|
|
513
|
+
getSocialChannels(): SessionChannel[];
|
|
514
|
+
sendSocialMessage(channelId: string, content: string): Promise<void>;
|
|
515
|
+
startSocialHeartbeat(config?: Partial<HeartbeatConfig>): Promise<void>;
|
|
516
|
+
stopSocialHeartbeat(): void;
|
|
517
|
+
addUserAction(content: string, importance?: number): Promise<void>;
|
|
518
|
+
addSharedKnowledge(knowledge: string): Promise<void>;
|
|
519
|
+
getRecentActionsSummary(count?: number): Promise<string>;
|
|
520
|
+
getSharedKnowledge(): Promise<string[]>;
|
|
521
|
+
getGlobalContextSummary(): Promise<string>;
|
|
522
|
+
createCooperation(type: CooperationType, task: string, toAgentId?: string, context?: string): Promise<CooperationTask>;
|
|
523
|
+
getPendingCooperations(): Promise<CooperationTask[]>;
|
|
524
|
+
updateCooperationStatus(cooperationId: string, status: 'pending' | 'in_progress' | 'done' | 'failed', result?: string): Promise<void>;
|
|
525
|
+
getAllRegisteredAgents(): Promise<AgentInfo[]>;
|
|
526
|
+
findAgentByCapability(capability: string): Promise<AgentInfo[]>;
|
|
527
|
+
archiveToHarness(): void;
|
|
528
|
+
getHarnessContext(): string;
|
|
529
|
+
isHarnessEnabled(): boolean;
|
|
530
|
+
getHarness(): any;
|
|
531
|
+
getOperationLog(): Array<{ timestamp: number; action: string; args: any; result: any; status: string }>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
class PiAgentSession implements AgentSession {
|
|
535
|
+
private cwd: string;
|
|
536
|
+
private peerId: string;
|
|
537
|
+
private identity: IdentityDoc;
|
|
538
|
+
private persona: PersonaDoc | null = null;
|
|
539
|
+
private minimaxAvailable = false;
|
|
540
|
+
private workflows: Map<string, Workflow> = new Map();
|
|
541
|
+
private constraintLayer: ConstraintLayer;
|
|
542
|
+
private workflowEngine: WorkflowEngine;
|
|
543
|
+
private sessionManager: PiSessionManager;
|
|
544
|
+
private agentsManager: DiscoveredAgentsManager;
|
|
545
|
+
private socialHeartbeat: SocialHeartbeat | null = null;
|
|
546
|
+
private messageHistory: Message[] = [];
|
|
547
|
+
private tools: Map<string, Tool> = new Map();
|
|
548
|
+
private skillRegistry: SkillRegistry = new SkillRegistry();
|
|
549
|
+
private readonly MAX_REACT_ITERATIONS = 10;
|
|
550
|
+
private thinkingEngine = new DeepThinkingEngine(3);
|
|
551
|
+
private coordinator = new AgentCoordinator(3);
|
|
552
|
+
private harness: any = null;
|
|
553
|
+
private harnessEnabled = false;
|
|
554
|
+
|
|
555
|
+
constructor(config: AgentSessionConfig) {
|
|
556
|
+
this.cwd = config.cwd;
|
|
557
|
+
this.peerId = config.peerId || 'local';
|
|
558
|
+
this.identity = config.identityDoc || this.createDefaultIdentity();
|
|
559
|
+
this.minimaxAvailable = this.checkMinimax();
|
|
560
|
+
this.constraintLayer = new ConstraintLayer();
|
|
561
|
+
this.workflowEngine = new WorkflowEngine(this.constraintLayer);
|
|
562
|
+
this.sessionManager = new PiSessionManager(this.identity.did, this.cwd);
|
|
563
|
+
this.agentsManager = new DiscoveredAgentsManager();
|
|
564
|
+
this.initSession();
|
|
565
|
+
this.registerTools();
|
|
566
|
+
this.initHarness();
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private async initHarness(): Promise<void> {
|
|
570
|
+
try {
|
|
571
|
+
const { createBollharnessIntegration } = await import('../bollharness-integration/index.js');
|
|
572
|
+
this.harness = createBollharnessIntegration();
|
|
573
|
+
this.harnessEnabled = true;
|
|
574
|
+
} catch (e) {
|
|
575
|
+
console.warn('[PiAgentSession] Harness initialization failed:', e);
|
|
576
|
+
this.harnessEnabled = false;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private registerTools(): void {
|
|
581
|
+
this.tools.set('read_document', {
|
|
582
|
+
name: 'read_document',
|
|
583
|
+
description: '读取文档内容,支持 .txt, .md, .pdf, .docx 格式',
|
|
584
|
+
parameters: { path: '文件路径' },
|
|
585
|
+
execute: async (args) => {
|
|
586
|
+
try {
|
|
587
|
+
const content = await documentReader.read(args.path);
|
|
588
|
+
return {
|
|
589
|
+
success: true,
|
|
590
|
+
output: `📄 ${content.metadata.filename}\n大小: ${content.metadata.size} 字节\n\n${content.text.substring(0, 1000)}${content.text.length > 1000 ? '...' : ''}`
|
|
591
|
+
};
|
|
592
|
+
} catch (e) {
|
|
593
|
+
return { success: false, error: String(e) };
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
this.tools.set('summarize_document', {
|
|
599
|
+
name: 'summarize_document',
|
|
600
|
+
description: '总结文档内容,分析并生成摘要',
|
|
601
|
+
parameters: { path: '文件路径', context: '可选上下文信息' },
|
|
602
|
+
execute: async (args) => {
|
|
603
|
+
try {
|
|
604
|
+
if (!this.minimaxAvailable) {
|
|
605
|
+
return { success: false, error: 'LLM未初始化,请设置 MINIMAX_API_KEY' };
|
|
606
|
+
}
|
|
607
|
+
const result = await this.summarizeDocument(args.path, args.context);
|
|
608
|
+
return {
|
|
609
|
+
success: true,
|
|
610
|
+
output: `📝 摘要:\n${result.summary}\n\n质量评分: ${(result.qualityScore * 10).toFixed(1)}/10`
|
|
611
|
+
};
|
|
612
|
+
} catch (e) {
|
|
613
|
+
return { success: false, error: String(e) };
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
this.tools.set('improve_document', {
|
|
619
|
+
name: 'improve_document',
|
|
620
|
+
description: '根据要求改进文档内容',
|
|
621
|
+
parameters: { path: '文件路径', requirements: '改进要求' },
|
|
622
|
+
execute: async (args) => {
|
|
623
|
+
try {
|
|
624
|
+
if (!this.minimaxAvailable) {
|
|
625
|
+
return { success: false, error: 'LLM未初始化,请设置 MINIMAX_API_KEY' };
|
|
626
|
+
}
|
|
627
|
+
const result = await this.improveDocument({
|
|
628
|
+
originalPath: args.path,
|
|
629
|
+
requirements: args.requirements
|
|
630
|
+
});
|
|
631
|
+
return {
|
|
632
|
+
success: true,
|
|
633
|
+
output: `✅ 改进${result.improved ? '成功' : '失败'}\n质量评分: ${(result.qualityScore * 10).toFixed(1)}/10\n${result.newContent ? '\n改进内容:\n' + result.newContent.substring(0, 500) + '...' : ''}`
|
|
634
|
+
};
|
|
635
|
+
} catch (e) {
|
|
636
|
+
return { success: false, error: String(e) };
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
this.tools.set('list_peers', {
|
|
642
|
+
name: 'list_peers',
|
|
643
|
+
description: '列出已连接的对等节点',
|
|
644
|
+
parameters: {},
|
|
645
|
+
execute: async () => {
|
|
646
|
+
const peers = p2pNetwork.getPeers();
|
|
647
|
+
if (peers.length === 0) {
|
|
648
|
+
return { success: true, output: '当前无连接的对等节点' };
|
|
649
|
+
}
|
|
650
|
+
return { success: true, output: `已连接节点 (${peers.length}):\n${peers.map(p => ` - ${p}`).join('\n')}` };
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
this.tools.set('send_message', {
|
|
655
|
+
name: 'send_message',
|
|
656
|
+
description: '向指定对等节点发送消息',
|
|
657
|
+
parameters: { peer_id: '对等节点ID', message: '消息内容' },
|
|
658
|
+
execute: async (args) => {
|
|
659
|
+
try {
|
|
660
|
+
await p2pNetwork.sendMessage(args.peer_id, 'message', args.message);
|
|
661
|
+
return { success: true, output: `消息已发送到 ${args.peer_id}` };
|
|
662
|
+
} catch (e) {
|
|
663
|
+
return { success: false, error: String(e) };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
this.tools.set('broadcast_message', {
|
|
669
|
+
name: 'broadcast_message',
|
|
670
|
+
description: '向所有对等节点广播消息',
|
|
671
|
+
parameters: { message: '消息内容' },
|
|
672
|
+
execute: async (args) => {
|
|
673
|
+
try {
|
|
674
|
+
await p2pNetwork.broadcast('message', args.message);
|
|
675
|
+
return { success: true, output: '消息已广播到所有节点' };
|
|
676
|
+
} catch (e) {
|
|
677
|
+
return { success: false, error: String(e) };
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
this.tools.set('get_identity', {
|
|
683
|
+
name: 'get_identity',
|
|
684
|
+
description: '获取当前智能体身份信息',
|
|
685
|
+
parameters: {},
|
|
686
|
+
execute: async () => {
|
|
687
|
+
const id = this.getIdentity();
|
|
688
|
+
const extraInfo = id.cid ? `\nCID: ${id.cid}` : '';
|
|
689
|
+
const ipnsInfo = id.ipnsName ? `\nIPNS: ${id.ipnsName}` : '';
|
|
690
|
+
return {
|
|
691
|
+
success: true,
|
|
692
|
+
output: `DID: ${id.did}\n名称: ${id.name}\n公钥: ${id.publicKey}${extraInfo}${ipnsInfo}\n创建时间: ${new Date(id.createdAt).toISOString()}`
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
this.tools.set('set_persona', {
|
|
698
|
+
name: 'set_persona',
|
|
699
|
+
description: '更新智能体的 persona 信息,包括名字、描述、性格等',
|
|
700
|
+
parameters: { persona_json: 'Persona JSON 对象,包含 name、description、personality、greeting 等字段' },
|
|
701
|
+
execute: async (args) => {
|
|
702
|
+
try {
|
|
703
|
+
const personaData = typeof args.persona_json === 'string' ? JSON.parse(args.persona_json) : args.persona_json;
|
|
704
|
+
const now = new Date().toISOString();
|
|
705
|
+
const newPersona: PersonaDoc = {
|
|
706
|
+
name: personaData.name || this.identity.name,
|
|
707
|
+
description: personaData.description || '',
|
|
708
|
+
capabilities: personaData.capabilities || [],
|
|
709
|
+
personality: personaData.personality || '',
|
|
710
|
+
greeting: personaData.greeting || '',
|
|
711
|
+
interests: personaData.interests || [],
|
|
712
|
+
createdAt: this.persona?.createdAt || now,
|
|
713
|
+
updatedAt: now
|
|
714
|
+
};
|
|
715
|
+
await this.setPersona(newPersona);
|
|
716
|
+
this.persona = newPersona;
|
|
717
|
+
if (newPersona.name) {
|
|
718
|
+
this.identity.name = newPersona.name;
|
|
719
|
+
}
|
|
720
|
+
return { success: true, output: `Persona 已更新:\n名称: ${newPersona.name}\n描述: ${newPersona.description}\n性格: ${newPersona.personality}` };
|
|
721
|
+
} catch (e) {
|
|
722
|
+
return { success: false, error: `更新 persona 失败: ${String(e)}` };
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
this.tools.set('get_operation_logs', {
|
|
728
|
+
name: 'get_operation_logs',
|
|
729
|
+
description: '获取约束层的操作日志',
|
|
730
|
+
parameters: {},
|
|
731
|
+
execute: async () => {
|
|
732
|
+
const logs = this.constraintLayer.getLogs();
|
|
733
|
+
if (logs.length === 0) {
|
|
734
|
+
return { success: true, output: '暂无操作日志' };
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
success: true,
|
|
738
|
+
output: `操作日志 (${logs.length} 条):\n${logs.slice(-10).map(l => `[${new Date(l.timestamp).toISOString()}] ${l.action} - ${l.status}`).join('\n')}`
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
private getToolDefinitions(): string {
|
|
745
|
+
const defs: string[] = ['可用工具:'];
|
|
746
|
+
for (const tool of this.tools.values()) {
|
|
747
|
+
const params = Object.entries(tool.parameters).map(([k, v]) => `${k}: ${v}`).join(', ');
|
|
748
|
+
defs.push(`- ${tool.name}(${params}) - ${tool.description}`);
|
|
749
|
+
}
|
|
750
|
+
return defs.join('\n');
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
private async initSession(): Promise<void> {
|
|
754
|
+
await this.sessionManager.initialize();
|
|
755
|
+
await this.agentsManager.initialize();
|
|
756
|
+
|
|
757
|
+
this.persona = this.sessionManager.getPersona();
|
|
758
|
+
if (this.persona?.name) {
|
|
759
|
+
this.identity.name = this.persona.name;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private createDefaultIdentity(): IdentityDoc {
|
|
764
|
+
return {
|
|
765
|
+
did: `did:pi:${this.peerId.substring(0, 16)}`,
|
|
766
|
+
name: `Agent-${this.peerId.substring(0, 8)}`,
|
|
767
|
+
publicKey: this.peerId,
|
|
768
|
+
createdAt: Date.now()
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
private checkMinimax(): boolean {
|
|
773
|
+
try {
|
|
774
|
+
getMinimax();
|
|
775
|
+
return true;
|
|
776
|
+
} catch {
|
|
777
|
+
return false;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
async prompt(input: string): Promise<string> {
|
|
782
|
+
this.minimaxAvailable = this.checkMinimax();
|
|
783
|
+
|
|
784
|
+
this.messageHistory.push({
|
|
785
|
+
role: 'user',
|
|
786
|
+
content: input
|
|
787
|
+
});
|
|
788
|
+
|
|
789
|
+
if (!this.minimaxAvailable) {
|
|
790
|
+
const response = await this.handleFallback(input);
|
|
791
|
+
this.messageHistory.push({ role: 'assistant', content: response });
|
|
792
|
+
return response;
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return this.runReActLoop();
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
async promptStream(input: string, onStream: StreamCallback): Promise<string> {
|
|
799
|
+
this.minimaxAvailable = this.checkMinimax();
|
|
800
|
+
|
|
801
|
+
this.messageHistory.push({
|
|
802
|
+
role: 'user',
|
|
803
|
+
content: input
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
onStream({ type: 'thinking', content: '🤔 思考中...' });
|
|
807
|
+
|
|
808
|
+
if (!this.minimaxAvailable) {
|
|
809
|
+
const response = await this.handleFallback(input);
|
|
810
|
+
this.messageHistory.push({ role: 'assistant', content: response });
|
|
811
|
+
onStream({ type: 'done', content: '' });
|
|
812
|
+
return response;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
const result = await this.runReActLoop();
|
|
816
|
+
onStream({ type: 'done', content: '' });
|
|
817
|
+
return result;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
private async runReActLoop(): Promise<string> {
|
|
821
|
+
const llm = getMinimax();
|
|
822
|
+
let iteration = 0;
|
|
823
|
+
let finalResponse = '';
|
|
824
|
+
|
|
825
|
+
while (iteration < this.MAX_REACT_ITERATIONS) {
|
|
826
|
+
iteration++;
|
|
827
|
+
|
|
828
|
+
const context = this.buildContext();
|
|
829
|
+
const toolDefs = this.getToolDefinitions();
|
|
830
|
+
|
|
831
|
+
const personaSection = this.persona ? `
|
|
832
|
+
角色描述: ${this.persona.description || '无'}
|
|
833
|
+
性格特点: ${this.persona.personality || '无'}
|
|
834
|
+
问候语: ${this.persona.greeting || '无'}
|
|
835
|
+
` : '';
|
|
836
|
+
|
|
837
|
+
const systemPrompt = `你是 ${this.identity.name},基于ReAct (Reasoning + Acting)模式工作。${personaSection}
|
|
838
|
+
当前工作目录: ${this.cwd}
|
|
839
|
+
当前身份: ${this.identity.name} (${this.identity.did})
|
|
840
|
+
|
|
841
|
+
${toolDefs}
|
|
842
|
+
|
|
843
|
+
工作模式:
|
|
844
|
+
1. 理解用户自然语言请求
|
|
845
|
+
2. 分析需要哪些工具来完成
|
|
846
|
+
3. 按顺序调用工具并观察结果
|
|
847
|
+
4. 根据观察结果决定下一步
|
|
848
|
+
5. 最终给出完整回答
|
|
849
|
+
|
|
850
|
+
重要:
|
|
851
|
+
- 每次只调用一个工具
|
|
852
|
+
- 仔细分析工具返回结果
|
|
853
|
+
- 如果任务完成,返回完整回答
|
|
854
|
+
- 如果需要更多信息,继续调用工具`;
|
|
855
|
+
|
|
856
|
+
const response = await llm.chat(context, systemPrompt);
|
|
857
|
+
const reply = response.reply.trim();
|
|
858
|
+
|
|
859
|
+
if (this.isFinalResponse(reply)) {
|
|
860
|
+
finalResponse = this.extractFinalAnswer(reply);
|
|
861
|
+
break;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
const toolCall = this.parseToolCall(reply);
|
|
865
|
+
if (toolCall) {
|
|
866
|
+
this.messageHistory.push({
|
|
867
|
+
role: 'assistant',
|
|
868
|
+
content: reply,
|
|
869
|
+
toolCall
|
|
870
|
+
});
|
|
871
|
+
|
|
872
|
+
const tool = this.tools.get(toolCall.name);
|
|
873
|
+
if (!tool) {
|
|
874
|
+
const errorResult: ToolResult = { success: false, error: `未知工具: ${toolCall.name}` };
|
|
875
|
+
this.messageHistory.push({ role: 'tool', content: JSON.stringify(errorResult), toolResult: errorResult });
|
|
876
|
+
this.logToHarness(toolCall.name, toolCall.args, errorResult);
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
const result = await tool.execute(toolCall.args);
|
|
881
|
+
this.messageHistory.push({ role: 'tool', content: JSON.stringify(result), toolResult: result });
|
|
882
|
+
this.logToHarness(toolCall.name, toolCall.args, result);
|
|
883
|
+
|
|
884
|
+
if (!result.success && result.error) {
|
|
885
|
+
console.warn(`Tool ${toolCall.name} error: ${result.error}`);
|
|
886
|
+
}
|
|
887
|
+
} else {
|
|
888
|
+
this.messageHistory.push({ role: 'assistant', content: reply });
|
|
889
|
+
finalResponse = reply;
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
if (!finalResponse) {
|
|
895
|
+
finalResponse = '任务处理超时,请尝试更具体的请求。';
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const now = new Date().toISOString();
|
|
899
|
+
const identityPrefix = `${this.identity.name} | bolloon 智能体
|
|
900
|
+
<environment_details>
|
|
901
|
+
Current time: ${now}
|
|
902
|
+
Working directory: ${this.cwd}
|
|
903
|
+
Workspace root folder: ${this.cwd}
|
|
904
|
+
</environment_details>
|
|
905
|
+
`;
|
|
906
|
+
finalResponse = identityPrefix + finalResponse;
|
|
907
|
+
|
|
908
|
+
this.messageHistory.push({ role: 'assistant', content: finalResponse });
|
|
909
|
+
return finalResponse;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
async deepThink(prompt: string): Promise<{ result: ThinkResult; response: string }> {
|
|
913
|
+
const result = await this.thinkingEngine.think(prompt);
|
|
914
|
+
let response = `深度思考完成(${result.depth}层):\n\n`;
|
|
915
|
+
for (const step of result.steps) {
|
|
916
|
+
response += `第${step.step}步: ${step.thought}\n`;
|
|
917
|
+
if (step.reflection) {
|
|
918
|
+
response += ` 反思: ${step.reflection}\n`;
|
|
919
|
+
}
|
|
920
|
+
if (step.improvement) {
|
|
921
|
+
response += ` 改进: ${step.improvement}\n`;
|
|
922
|
+
}
|
|
923
|
+
response += '\n';
|
|
924
|
+
}
|
|
925
|
+
response += `最终输出: ${result.finalOutput}`;
|
|
926
|
+
return { result, response };
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
async processDocumentsInParallel(
|
|
930
|
+
paths: string[],
|
|
931
|
+
operation: 'summarize' | 'improve',
|
|
932
|
+
requirements?: string
|
|
933
|
+
): Promise<{ outputs: string[]; success: boolean }> {
|
|
934
|
+
if (paths.length === 0) {
|
|
935
|
+
return { outputs: [], success: true };
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
const subtasks = paths.map((filePath, index) => ({
|
|
939
|
+
id: `doc-${index}`,
|
|
940
|
+
description: `${operation}:${filePath}${requirements ? `:${requirements}` : ''}`,
|
|
941
|
+
priority: index
|
|
942
|
+
}));
|
|
943
|
+
|
|
944
|
+
const dispatchPrompts = subtasks.map(t => t.description);
|
|
945
|
+
const results = await this.coordinator.dispatch(dispatchPrompts.join(' ||| '), paths.length);
|
|
946
|
+
|
|
947
|
+
const outputs: string[] = [];
|
|
948
|
+
let allSuccess = true;
|
|
949
|
+
|
|
950
|
+
for (let i = 0; i < paths.length; i++) {
|
|
951
|
+
const result = results.find((r: AgentResult) => r.taskId === `task-${i}`);
|
|
952
|
+
if (result) {
|
|
953
|
+
outputs.push(result.output);
|
|
954
|
+
if (!result.success) allSuccess = false;
|
|
955
|
+
} else {
|
|
956
|
+
outputs.push(`No result for ${paths[i]}`);
|
|
957
|
+
allSuccess = false;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
return { outputs, success: allSuccess };
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
private buildContext(): string {
|
|
965
|
+
const recentMessages = this.messageHistory.slice(-10);
|
|
966
|
+
return recentMessages.map(m => {
|
|
967
|
+
if (m.role === 'user') return `用户: ${m.content}`;
|
|
968
|
+
if (m.role === 'assistant') return `助手: ${m.content}`;
|
|
969
|
+
if (m.role === 'tool') {
|
|
970
|
+
const result = m.toolResult ? JSON.stringify(m.toolResult) : m.content;
|
|
971
|
+
return `工具结果: ${result}`;
|
|
972
|
+
}
|
|
973
|
+
return m.content;
|
|
974
|
+
}).join('\n');
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
private isFinalResponse(content: string): boolean {
|
|
978
|
+
const finalMarkers = ['最终回答', '完成', '答案如下', '结果是', 'final', 'answer:'];
|
|
979
|
+
const lower = content.toLowerCase();
|
|
980
|
+
// 更保守的判断:只有明确标记最终回答,且回复较短时才认为是最终回复
|
|
981
|
+
if (content.includes('✅') && content.length < 200 && finalMarkers.some(m => lower.includes(m))) {
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
return finalMarkers.some(m => lower.includes(m));
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
private extractFinalAnswer(content: string): string {
|
|
988
|
+
// 移除任何 tool call 标记(保持完整回复)
|
|
989
|
+
let cleaned = content
|
|
990
|
+
.replace(/调用工具[::]\s*\w+\s*\([^)]*\)/g, '')
|
|
991
|
+
.replace(/使用工具[::]\s*\w+\s*\([^)]*\)/g, '')
|
|
992
|
+
.replace(/tool[_\w]*[::]\s*\w+\s*\([^)]*\)/gi, '')
|
|
993
|
+
.trim();
|
|
994
|
+
|
|
995
|
+
const lines = cleaned.split('\n');
|
|
996
|
+
const answerStart = lines.findIndex(l =>
|
|
997
|
+
['最终回答', '完成', '答案如下', '结果是', 'final', 'answer:'].some(m => l.toLowerCase().includes(m))
|
|
998
|
+
);
|
|
999
|
+
if (answerStart >= 0) {
|
|
1000
|
+
return lines.slice(answerStart + 1).join('\n').trim();
|
|
1001
|
+
}
|
|
1002
|
+
return cleaned;
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
private parseToolCall(content: string): { name: string; args: Record<string, string> } | null {
|
|
1006
|
+
const patterns = [
|
|
1007
|
+
/调用工具[::]\s*(\w+)\s*\(([^)]*)\)/,
|
|
1008
|
+
/使用工具[::]\s*(\w+)\s*\(([^)]*)\)/,
|
|
1009
|
+
/tool[_\w]*[::]\s*(\w+)\s*\(([^)]*)\)/i,
|
|
1010
|
+
/(\w+)\s*\(\s*([^)]*)\s*\)/
|
|
1011
|
+
];
|
|
1012
|
+
|
|
1013
|
+
for (const pattern of patterns) {
|
|
1014
|
+
const match = content.match(pattern);
|
|
1015
|
+
if (match) {
|
|
1016
|
+
const name = match[1];
|
|
1017
|
+
const argsStr = match[2] || '';
|
|
1018
|
+
const args: Record<string, string> = {};
|
|
1019
|
+
|
|
1020
|
+
const argPairs = argsStr.split(',').map(s => s.trim()).filter(Boolean);
|
|
1021
|
+
for (const pair of argPairs) {
|
|
1022
|
+
const [key, ...valueParts] = pair.split(':').map(s => s.trim().replace(/['"]/g, ''));
|
|
1023
|
+
if (key) {
|
|
1024
|
+
args[key] = valueParts.join(':') || '';
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (this.tools.has(name) || this.tools.has(name.replace(/_/g, '_'))) {
|
|
1029
|
+
return { name, args };
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return null;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
private async handleFallback(input: string): Promise<string> {
|
|
1037
|
+
const lowerInput = input.toLowerCase();
|
|
1038
|
+
const parts = input.trim().split(/\s+/);
|
|
1039
|
+
const cmd = parts[0].toLowerCase();
|
|
1040
|
+
const args = parts.slice(1).join(' ');
|
|
1041
|
+
|
|
1042
|
+
if (cmd.includes('读取') || cmd === 'read' || cmd === 'read_document') {
|
|
1043
|
+
if (args) return await this.readDocument(args);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
if (cmd.includes('总结') || cmd === 'summary' || cmd === 'summarize') {
|
|
1047
|
+
if (args) return await this.summarizeText(args);
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
if (cmd.includes('改进') || cmd === 'improve' || cmd === 'improve_document') {
|
|
1051
|
+
const match = input.match(/改进[^\w]+(.+)/i) || input.match(/improve\s+(.+)/i);
|
|
1052
|
+
if (match) {
|
|
1053
|
+
return `改进需要LLM支持,请设置 MINIMAX_API_KEY 环境变量。\n文件: ${match[1]}`;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
if (cmd.includes('节点') || cmd === 'peers' || cmd === 'list_peers') {
|
|
1058
|
+
return this.listPeers();
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (cmd.includes('身份') || cmd === 'identity' || cmd === 'get_identity') {
|
|
1062
|
+
return JSON.stringify(this.getIdentity(), null, 2);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
if (cmd.includes('日志') || cmd === 'logs') {
|
|
1066
|
+
const logs = this.constraintLayer.getLogs();
|
|
1067
|
+
if (logs.length === 0) return '暂无操作日志';
|
|
1068
|
+
return logs.slice(-5).map(l => `[${new Date(l.timestamp).toISOString()}] ${l.action}`).join('\n');
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
return this.getDefaultResponse(input);
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
private static OPERATIONS_REFERENCE: string | null = null;
|
|
1075
|
+
|
|
1076
|
+
private static getOperationsReference(): string {
|
|
1077
|
+
if (this.OPERATIONS_REFERENCE === null) {
|
|
1078
|
+
try {
|
|
1079
|
+
const refPath = path.join(process.cwd(), 'src', 'bollharness', 'scripts', 'context-fragments', 'pi-agent-operations.md');
|
|
1080
|
+
this.OPERATIONS_REFERENCE = fsSync.readFileSync(refPath, 'utf-8');
|
|
1081
|
+
} catch {
|
|
1082
|
+
this.OPERATIONS_REFERENCE = '';
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
return this.OPERATIONS_REFERENCE;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
private getDefaultResponse(input: string): string {
|
|
1089
|
+
const operationsRef = PiAgentSession.getOperationsReference();
|
|
1090
|
+
|
|
1091
|
+
if (operationsRef) {
|
|
1092
|
+
return `收到了: "${input}"
|
|
1093
|
+
|
|
1094
|
+
我是一个判断力处理智能体,支持自然语言交互。
|
|
1095
|
+
|
|
1096
|
+
可用操作(直接说出即可):
|
|
1097
|
+
${this.extractOperationsFromRef(operationsRef)}
|
|
1098
|
+
|
|
1099
|
+
示例请求:
|
|
1100
|
+
- "读取 src/index.ts 文件"
|
|
1101
|
+
- "总结一下 README.md"
|
|
1102
|
+
- "查看当前连接了哪些节点"
|
|
1103
|
+
- "向 QmABC... 发送测试消息"`;
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
return `收到了: "${input}"
|
|
1107
|
+
|
|
1108
|
+
我是一个判断力处理智能体,支持自然语言交互。
|
|
1109
|
+
|
|
1110
|
+
可用操作(直接说出即可):
|
|
1111
|
+
- "读取 README.md" - 读取并分析文档
|
|
1112
|
+
- "总结文档" - 总结文档内容
|
|
1113
|
+
- "改进文档,按照X要求" - 改进文档
|
|
1114
|
+
- "查看节点" - 查看已连接的对等节点
|
|
1115
|
+
- "向X发送消息Y" - 向对等节点发送消息
|
|
1116
|
+
- "广播消息X" - 广播消息到所有节点
|
|
1117
|
+
- "查看身份" - 查看当前智能体身份
|
|
1118
|
+
- "查看日志" - 查看最近操作日志
|
|
1119
|
+
|
|
1120
|
+
示例请求:
|
|
1121
|
+
- "读取 src/index.ts 文件"
|
|
1122
|
+
- "总结一下 README.md"
|
|
1123
|
+
- "查看当前连接了哪些节点"
|
|
1124
|
+
- "向 QmABC... 发送测试消息"`;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
private extractOperationsFromRef(ref: string): string {
|
|
1128
|
+
const lines = ref.split('\n');
|
|
1129
|
+
const inOperationsSection = false;
|
|
1130
|
+
const operationLines: string[] = [];
|
|
1131
|
+
|
|
1132
|
+
for (let i = 0; i < lines.length; i++) {
|
|
1133
|
+
const line = lines[i];
|
|
1134
|
+
if (line.startsWith('## 可用操作')) {
|
|
1135
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
1136
|
+
const opLine = lines[j];
|
|
1137
|
+
if (opLine.startsWith('## ') || opLine.startsWith('#')) break;
|
|
1138
|
+
if (opLine.includes('|') && !opLine.startsWith('|')) {
|
|
1139
|
+
const parts = opLine.split('|').map(p => p.trim());
|
|
1140
|
+
if (parts.length >= 3 && parts[1] && parts[2]) {
|
|
1141
|
+
operationLines.push(` - "${parts[1]}" - ${parts[2]}`);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
return operationLines.length > 0 ? operationLines.join('\n') :
|
|
1150
|
+
` - "读取 README.md" - 读取并分析文档
|
|
1151
|
+
- "总结文档" - 总结文档内容
|
|
1152
|
+
- "改进文档,按照X要求" - 改进文档
|
|
1153
|
+
- "查看节点" - 查看已连接的对等节点
|
|
1154
|
+
- "向X发送消息Y" - 向对等节点发送消息
|
|
1155
|
+
- "广播消息X" - 广播消息到所有节点
|
|
1156
|
+
- "查看身份" - 查看当前智能体身份
|
|
1157
|
+
- "查看日志" - 查看最近操作日志`;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
async suggestRename(messages: { type: string; content: string }[]): Promise<string | null> {
|
|
1161
|
+
if (!this.minimaxAvailable || messages.length < 2) {
|
|
1162
|
+
return null;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
const conversation = messages.map(m => `${m.type === 'user' ? '用户' : '助手'}: ${m.content}`).join('\n');
|
|
1166
|
+
const llm = getMinimax();
|
|
1167
|
+
|
|
1168
|
+
try {
|
|
1169
|
+
const response = await llm.chat(
|
|
1170
|
+
`根据以下对话内容,为这个对话生成一个简短的名称(不超过20个字):\n\n${conversation}\n\n直接输出名称,不要其他解释。`,
|
|
1171
|
+
'命名建议'
|
|
1172
|
+
);
|
|
1173
|
+
|
|
1174
|
+
const name = response.reply.trim();
|
|
1175
|
+
if (name && name.length <= 20 && name !== '智能体') {
|
|
1176
|
+
return `Agent | ${name}`;
|
|
1177
|
+
}
|
|
1178
|
+
} catch {
|
|
1179
|
+
// ignore
|
|
1180
|
+
}
|
|
1181
|
+
return null;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
private async summarizeText(text: string): Promise<string> {
|
|
1185
|
+
if (!this.minimaxAvailable) {
|
|
1186
|
+
return '⚠️ LLM未初始化,请设置 MINIMAX_API_KEY 环境变量';
|
|
1187
|
+
}
|
|
1188
|
+
const llm = getMinimax();
|
|
1189
|
+
const result = await llm.summarize(text);
|
|
1190
|
+
return `📝 摘要:\n${result.summary}\n\n质量评分: ${(result.qualityScore * 10).toFixed(1)}/10`;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
async readDocument(filePath: string): Promise<string> {
|
|
1194
|
+
const content = await documentReader.read(filePath);
|
|
1195
|
+
this.sessionManager.addFileContext(filePath, content.text.substring(0, 1000));
|
|
1196
|
+
return `📄 ${content.metadata.filename}\n大小: ${content.metadata.size} 字节\n\n${content.text.substring(0, 500)}...`;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
async summarizeDocument(filePath: string, context?: string): Promise<{
|
|
1200
|
+
summary: string;
|
|
1201
|
+
qualityScore: number;
|
|
1202
|
+
}> {
|
|
1203
|
+
if (!this.minimaxAvailable) {
|
|
1204
|
+
return {
|
|
1205
|
+
summary: '⚠️ LLM未初始化,请设置 MINIMAX_API_KEY 环境变量',
|
|
1206
|
+
qualityScore: 0
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const content = await documentReader.read(filePath);
|
|
1211
|
+
this.sessionManager.addFileContext(filePath, content.text.substring(0, 1000));
|
|
1212
|
+
const llm = getMinimax();
|
|
1213
|
+
const chunks = documentReader.chunk(content.text);
|
|
1214
|
+
const summaries: string[] = [];
|
|
1215
|
+
let totalQuality = 0;
|
|
1216
|
+
|
|
1217
|
+
for (const chunk of chunks) {
|
|
1218
|
+
const result = await llm.summarize(chunk, context);
|
|
1219
|
+
summaries.push(result.summary);
|
|
1220
|
+
totalQuality += result.qualityScore;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
const avgQuality = totalQuality / chunks.length;
|
|
1224
|
+
return {
|
|
1225
|
+
summary: summaries.join('\n\n'),
|
|
1226
|
+
qualityScore: avgQuality
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
async improveDocument(request: ImprovementRequest): Promise<{
|
|
1231
|
+
improved: boolean;
|
|
1232
|
+
newContent?: string;
|
|
1233
|
+
qualityScore: number;
|
|
1234
|
+
shouldAutoSend: boolean;
|
|
1235
|
+
}> {
|
|
1236
|
+
if (!this.minimaxAvailable) {
|
|
1237
|
+
return {
|
|
1238
|
+
improved: false,
|
|
1239
|
+
qualityScore: 0,
|
|
1240
|
+
shouldAutoSend: false
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
const content = await documentReader.read(request.originalPath);
|
|
1245
|
+
const llm = getMinimax();
|
|
1246
|
+
const improvedResult = await llm.summarize(content.text + '\n\n改进要求: ' + request.requirements, request.context);
|
|
1247
|
+
const shouldAutoSend = await llm.shouldAutoSend(improvedResult.qualityScore, 0.7);
|
|
1248
|
+
|
|
1249
|
+
return {
|
|
1250
|
+
improved: true,
|
|
1251
|
+
newContent: improvedResult.summary,
|
|
1252
|
+
qualityScore: improvedResult.qualityScore,
|
|
1253
|
+
shouldAutoSend
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
async runWorkflow(steps: WorkflowStep[]): Promise<Workflow> {
|
|
1258
|
+
const context: WorkflowContext = {
|
|
1259
|
+
peers: this.getPeers(),
|
|
1260
|
+
logs: []
|
|
1261
|
+
};
|
|
1262
|
+
|
|
1263
|
+
const checkResult = await this.constraintLayer.checkGuardrails(context);
|
|
1264
|
+
if (!checkResult.passed && checkResult.blocked) {
|
|
1265
|
+
console.warn(`Guardrail blocked: ${checkResult.blocked.name}`);
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
return this.workflowEngine.executeWorkflow(steps, context);
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
async summarizeDocumentWorkflow(filePath: string, targetPeer?: string): Promise<Workflow> {
|
|
1272
|
+
const steps: WorkflowStep[] = [
|
|
1273
|
+
{
|
|
1274
|
+
id: 'read',
|
|
1275
|
+
type: 'read',
|
|
1276
|
+
config: { path: filePath },
|
|
1277
|
+
retry: { max: 3, current: 0, backoffMs: 1000 },
|
|
1278
|
+
onFail: 'abort'
|
|
1279
|
+
},
|
|
1280
|
+
{
|
|
1281
|
+
id: 'summarize',
|
|
1282
|
+
type: 'summarize',
|
|
1283
|
+
config: { context: `File: ${filePath}` },
|
|
1284
|
+
retry: { max: 3, current: 0, backoffMs: 1000 },
|
|
1285
|
+
onFail: 'skip',
|
|
1286
|
+
guardrail: (ctx) => Promise.resolve(ctx.qualityScore !== undefined && ctx.qualityScore >= 0.5)
|
|
1287
|
+
}
|
|
1288
|
+
];
|
|
1289
|
+
|
|
1290
|
+
if (targetPeer) {
|
|
1291
|
+
steps.push({
|
|
1292
|
+
id: 'send',
|
|
1293
|
+
type: 'send',
|
|
1294
|
+
config: { peerId: targetPeer },
|
|
1295
|
+
retry: { max: 2, current: 0, backoffMs: 2000 },
|
|
1296
|
+
onFail: 'skip'
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
return this.runWorkflow(steps);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
async improveAndSendWorkflow(filePath: string, requirements: string, targetPeer: string): Promise<Workflow> {
|
|
1304
|
+
const steps: WorkflowStep[] = [
|
|
1305
|
+
{
|
|
1306
|
+
id: 'read',
|
|
1307
|
+
type: 'read',
|
|
1308
|
+
config: { path: filePath },
|
|
1309
|
+
retry: { max: 3, current: 0, backoffMs: 1000 },
|
|
1310
|
+
onFail: 'abort'
|
|
1311
|
+
},
|
|
1312
|
+
{
|
|
1313
|
+
id: 'improve',
|
|
1314
|
+
type: 'improve',
|
|
1315
|
+
config: { requirements, context: `File: ${filePath}` },
|
|
1316
|
+
retry: { max: 2, current: 0, backoffMs: 1500 },
|
|
1317
|
+
onFail: 'skip'
|
|
1318
|
+
},
|
|
1319
|
+
{
|
|
1320
|
+
id: 'send',
|
|
1321
|
+
type: 'send',
|
|
1322
|
+
config: { peerId: targetPeer, message: '改进后的文档' },
|
|
1323
|
+
retry: { max: 2, current: 0, backoffMs: 2000 },
|
|
1324
|
+
onFail: 'skip'
|
|
1325
|
+
}
|
|
1326
|
+
];
|
|
1327
|
+
|
|
1328
|
+
return this.runWorkflow(steps);
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
getOperationLogs(): { timestamp: number; action: string; details: Record<string, unknown>; status: string }[] {
|
|
1332
|
+
return this.constraintLayer.getLogs();
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
private listPeers(): string {
|
|
1336
|
+
const peers = p2pNetwork.getPeers();
|
|
1337
|
+
if (peers.length === 0) {
|
|
1338
|
+
return '当前无连接的对等节点';
|
|
1339
|
+
}
|
|
1340
|
+
return `已连接节点 (${peers.length}):\n${peers.map(p => ` - ${p}`).join('\n')}`;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
getPeers(): string[] {
|
|
1344
|
+
return p2pNetwork.getPeers();
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
async sendMessage(peerId: string, message: string): Promise<void> {
|
|
1348
|
+
await p2pNetwork.sendMessage(peerId, 'message', message);
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
async broadcast(message: string): Promise<void> {
|
|
1352
|
+
await p2pNetwork.broadcast('message', message);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
getIdentity(): IdentityDoc {
|
|
1356
|
+
return { ...this.identity };
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
updateIdentity(updates: Partial<IdentityDoc>): void {
|
|
1360
|
+
this.identity = { ...this.identity, ...updates };
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
getSessionState(): PiSessionState {
|
|
1364
|
+
return this.sessionManager.getState();
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
getMemory(): PiMemory {
|
|
1368
|
+
return this.sessionManager.getMemory();
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
getPersona(): PersonaDoc | null {
|
|
1372
|
+
return this.sessionManager.getPersona();
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
async setPersona(persona: PersonaDoc): Promise<void> {
|
|
1376
|
+
await this.sessionManager.savePersona(persona);
|
|
1377
|
+
this.persona = persona;
|
|
1378
|
+
if (persona.name) {
|
|
1379
|
+
this.identity.name = persona.name;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
getDiscoveredAgents(): DiscoveredAgent[] {
|
|
1384
|
+
return this.agentsManager.getAllAgents();
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
getSocialChannels(): SessionChannel[] {
|
|
1388
|
+
return this.sessionManager.getAllChannels();
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
async sendSocialMessage(channelId: string, content: string): Promise<void> {
|
|
1392
|
+
const message: SessionMessage = {
|
|
1393
|
+
id: crypto.randomUUID(),
|
|
1394
|
+
type: 'ai',
|
|
1395
|
+
content,
|
|
1396
|
+
sender: 'self',
|
|
1397
|
+
timestamp: new Date().toISOString(),
|
|
1398
|
+
agentId: this.identity.did
|
|
1399
|
+
};
|
|
1400
|
+
|
|
1401
|
+
await this.sessionManager.addMessage(channelId, message);
|
|
1402
|
+
|
|
1403
|
+
const channels = this.sessionManager.getAllChannels();
|
|
1404
|
+
const channel = channels.find(c => c.id === channelId);
|
|
1405
|
+
if (channel?.peerDid) {
|
|
1406
|
+
const agent = this.agentsManager.getAgent(channel.peerDid);
|
|
1407
|
+
if (agent) {
|
|
1408
|
+
const comm = (global as any).hyperswarmComm;
|
|
1409
|
+
if (comm) {
|
|
1410
|
+
const connections = comm.getConnections?.() || [];
|
|
1411
|
+
for (const conn of connections) {
|
|
1412
|
+
if (conn.publicKey === agent.peerId) {
|
|
1413
|
+
const data = new TextEncoder().encode(`social|${JSON.stringify({ from: this.identity.did, message: content })}`);
|
|
1414
|
+
comm.sendToConnection?.(conn, data);
|
|
1415
|
+
break;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
async startSocialHeartbeat(config?: Partial<HeartbeatConfig>): Promise<void> {
|
|
1424
|
+
if (this.socialHeartbeat) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
this.socialHeartbeat = await createSocialHeartbeat(this.sessionManager, this.agentsManager, config);
|
|
1428
|
+
this.socialHeartbeat.setOnAgentDiscovered((agent) => {
|
|
1429
|
+
console.log(`[Agent] 发现新智能体: ${agent.name}`);
|
|
1430
|
+
});
|
|
1431
|
+
this.socialHeartbeat.setOnSocialMessage((fromDid, message, channelId) => {
|
|
1432
|
+
console.log(`[Agent] 收到来自 ${fromDid} 的社交消息: ${message.substring(0, 50)}...`);
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
stopSocialHeartbeat(): void {
|
|
1437
|
+
if (this.socialHeartbeat) {
|
|
1438
|
+
this.socialHeartbeat.stop();
|
|
1439
|
+
this.socialHeartbeat = null;
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
getSkillRegistry(): SkillRegistry {
|
|
1444
|
+
return this.skillRegistry;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
registerSkill(skill: Skill): void {
|
|
1448
|
+
this.skillRegistry.register(skill);
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
async executeSkill(name: string, params: Record<string, unknown>): Promise<string> {
|
|
1452
|
+
return this.skillRegistry.execute(name, params);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
async addUserAction(content: string, importance?: number): Promise<void> {
|
|
1456
|
+
await this.sessionManager.addUserActionToSharedContext(content, importance);
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
async addSharedKnowledge(knowledge: string): Promise<void> {
|
|
1460
|
+
await this.sessionManager.addSharedKnowledge(knowledge);
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
async getRecentActionsSummary(count?: number): Promise<string> {
|
|
1464
|
+
return this.sessionManager.getRecentActionsSummary(count);
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
async getSharedKnowledge(): Promise<string[]> {
|
|
1468
|
+
return this.sessionManager.getSharedKnowledge();
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
async getGlobalContextSummary(): Promise<string> {
|
|
1472
|
+
return this.sessionManager.getGlobalContextSummary();
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
async createCooperation(
|
|
1476
|
+
type: CooperationType,
|
|
1477
|
+
task: string,
|
|
1478
|
+
toAgentId?: string,
|
|
1479
|
+
context?: string
|
|
1480
|
+
): Promise<CooperationTask> {
|
|
1481
|
+
return this.sessionManager.createCooperation(type, task, toAgentId, context);
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
async getPendingCooperations(): Promise<CooperationTask[]> {
|
|
1485
|
+
return this.sessionManager.getPendingCooperations();
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
async updateCooperationStatus(
|
|
1489
|
+
cooperationId: string,
|
|
1490
|
+
status: 'pending' | 'in_progress' | 'done' | 'failed',
|
|
1491
|
+
result?: string
|
|
1492
|
+
): Promise<void> {
|
|
1493
|
+
return this.sessionManager.updateCooperationStatus(cooperationId, status, result);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
async getAllRegisteredAgents(): Promise<AgentInfo[]> {
|
|
1497
|
+
return this.sessionManager.getAllRegisteredAgents();
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
async findAgentByCapability(capability: string): Promise<AgentInfo[]> {
|
|
1501
|
+
return this.sessionManager.findAgentByCapability(capability);
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// ==================== Harness Integration ====================
|
|
1505
|
+
|
|
1506
|
+
private operationLog: Array<{ timestamp: number; action: string; args: any; result: any; status: string }> = [];
|
|
1507
|
+
|
|
1508
|
+
private logToHarness(action: string, args: any, result: any): void {
|
|
1509
|
+
if (!this.harnessEnabled || !this.harness) return;
|
|
1510
|
+
|
|
1511
|
+
this.operationLog.push({
|
|
1512
|
+
timestamp: Date.now(),
|
|
1513
|
+
action,
|
|
1514
|
+
args,
|
|
1515
|
+
result,
|
|
1516
|
+
status: result.success ? 'ok' : 'error'
|
|
1517
|
+
});
|
|
1518
|
+
|
|
1519
|
+
if (this.operationLog.length >= 10) {
|
|
1520
|
+
this.archiveToHarness();
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
archiveToHarness(): void {
|
|
1525
|
+
if (!this.harnessEnabled || !this.harness || this.operationLog.length === 0) return;
|
|
1526
|
+
|
|
1527
|
+
this.harness.archiveSession(this.operationLog);
|
|
1528
|
+
this.operationLog = [];
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
getHarnessContext(): string {
|
|
1532
|
+
if (!this.harnessEnabled || !this.harness) {
|
|
1533
|
+
return 'Harness not available';
|
|
1534
|
+
}
|
|
1535
|
+
return this.harness.getSessionContext();
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
isHarnessEnabled(): boolean {
|
|
1539
|
+
return this.harnessEnabled;
|
|
1540
|
+
}
|
|
1541
|
+
|
|
1542
|
+
getHarness(): any {
|
|
1543
|
+
return this.harness;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
getOperationLog(): Array<{ timestamp: number; action: string; args: any; result: any; status: string }> {
|
|
1547
|
+
return [...this.operationLog];
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
let sessionInstance: AgentSession | null = null;
|
|
1552
|
+
let lastIdentityDid: string | null = null;
|
|
1553
|
+
|
|
1554
|
+
export async function createAgentSession(config: AgentSessionConfig): Promise<AgentSession> {
|
|
1555
|
+
const incomingDid = config.identityDoc?.did;
|
|
1556
|
+
|
|
1557
|
+
// 如果有新的 DID,强制重建 session
|
|
1558
|
+
if (sessionInstance && lastIdentityDid && incomingDid && lastIdentityDid !== incomingDid) {
|
|
1559
|
+
console.log(`[createAgentSession] DID 变化 ${lastIdentityDid} -> ${incomingDid},重建 session`);
|
|
1560
|
+
sessionInstance = null;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
if (sessionInstance) {
|
|
1564
|
+
// 检查是否需要更新 identity
|
|
1565
|
+
const currentDid = sessionInstance.getIdentity().did;
|
|
1566
|
+
if (incomingDid && currentDid !== incomingDid) {
|
|
1567
|
+
console.log(`[createAgentSession] 更新 identity: ${currentDid} -> ${incomingDid}`);
|
|
1568
|
+
sessionInstance.updateIdentity({
|
|
1569
|
+
did: incomingDid,
|
|
1570
|
+
name: config.identityDoc?.name || sessionInstance.getIdentity().name,
|
|
1571
|
+
publicKey: config.identityDoc?.publicKey || '',
|
|
1572
|
+
createdAt: Date.now()
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
return sessionInstance;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
sessionInstance = new PiAgentSession(config);
|
|
1579
|
+
lastIdentityDid = config.identityDoc?.did || null;
|
|
1580
|
+
console.log(`[createAgentSession] 新建 session, DID=${lastIdentityDid}`);
|
|
1581
|
+
return sessionInstance;
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
export function getAgentSession(): AgentSession | null {
|
|
1585
|
+
return sessionInstance;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1588
|
+
export function resetAgentSession(): void {
|
|
1589
|
+
sessionInstance = null;
|
|
1590
|
+
lastIdentityDid = null;
|
|
1591
|
+
}
|