@bolloon/bolloon-agent 0.1.36 → 0.1.38
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/package.json +2 -2
- package/.auto-evolve-calls +0 -1
- package/.last-auto-evolve-baseline +0 -1
- package/.playwright-mcp/page-2026-06-16T07-51-45-706Z.yml +0 -130
- package/.playwright-mcp/page-2026-06-16T07-56-44-116Z.yml +0 -131
- package/Bolloon.md +0 -144
- package/Dive-into/CITATION.cff +0 -17
- package/Dive-into/LICENSE +0 -25
- package/Dive-into/README.md +0 -598
- package/Dive-into/README_zh.md +0 -599
- package/Dive-into/assets/context.png +0 -0
- package/Dive-into/assets/extensibility.png +0 -0
- package/Dive-into/assets/iteration.png +0 -0
- package/Dive-into/assets/layered_architecture.png +0 -0
- package/Dive-into/assets/main_structure.png +0 -0
- package/Dive-into/assets/permission.png +0 -0
- package/Dive-into/assets/session_compact.png +0 -0
- package/Dive-into/assets/subagent.png +0 -0
- package/Dive-into/paper/Dive_into_Claude_Code.pdf +0 -0
- package/dist/agents/constraint-layer.js.map +0 -1
- package/dist/agents/pi-sdk.js.map +0 -1
- package/dist/agents/workflow-engine.js.map +0 -1
- package/dist/bollharness/src/index.js +0 -5
- package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_api_types.js +0 -45
- package/dist/bollharness/src/scripts/checks/check_artifact_link.js +0 -146
- package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +0 -135
- package/dist/bollharness/src/scripts/checks/check_doc_links.js +0 -31
- package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +0 -34
- package/dist/bollharness/src/scripts/checks/check_hook_installed.js +0 -63
- package/dist/bollharness/src/scripts/checks/check_issue_closure.js +0 -41
- package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_security.js +0 -48
- package/dist/bollharness/src/scripts/checks/check_skill_parity.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_versions.js +0 -6
- package/dist/bollharness/src/scripts/checks/finding.js +0 -13
- package/dist/bollharness/src/scripts/checks/next_decision_number.js +0 -20
- package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +0 -6
- package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +0 -8
- package/dist/bollharness/src/scripts/context_router.js +0 -67
- package/dist/bollharness/src/scripts/deploy-guard.js +0 -157
- package/dist/bollharness/src/scripts/guard-feedback.js +0 -192
- package/dist/bollharness/src/scripts/guard_router.js +0 -158
- package/dist/bollharness/src/scripts/hooks/_hook_output.js +0 -6
- package/dist/bollharness/src/scripts/hooks/auto-python3.js +0 -6
- package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +0 -6
- package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +0 -6
- package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +0 -92
- package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +0 -63
- package/dist/bollharness/src/scripts/hooks/inbox-ack.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-validate.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +0 -6
- package/dist/bollharness/src/scripts/hooks/initializer-agent.js +0 -6
- package/dist/bollharness/src/scripts/hooks/loop-detection.js +0 -73
- package/dist/bollharness/src/scripts/hooks/owner-guard.js +0 -6
- package/dist/bollharness/src/scripts/hooks/precompact.js +0 -6
- package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +0 -6
- package/dist/bollharness/src/scripts/hooks/risk-tracker.js +0 -108
- package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +0 -6
- package/dist/bollharness/src/scripts/hooks/session-reflection.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +0 -7
- package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +0 -157
- package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +0 -6
- package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +0 -10
- package/dist/bollharness/src/scripts/install/install-trust-token.js +0 -7
- package/dist/bollharness/src/scripts/install/multi_project_registry.js +0 -9
- package/dist/bollharness/src/scripts/install/phase2_auto.js +0 -21
- package/dist/bollharness/src/scripts/install/pre_commit_installer.js +0 -6
- package/dist/bollharness/src/scripts/install/tier_selector.js +0 -7
- package/dist/bollharness/src/scripts/install/transcript_miner.js +0 -7
- package/dist/bollharness/src/scripts/lib/claim_patterns.js +0 -10
- package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +0 -12
- package/dist/bollharness/src/scripts/sanitize.js +0 -6
- package/dist/bollharness-integration/context-router-judgment.js.map +0 -1
- package/dist/bollharness-integration/context-router.js.map +0 -1
- package/dist/bollharness-integration/gate-state-machine.js.map +0 -1
- package/dist/bollharness-integration/gate-transition-hooks.js.map +0 -1
- package/dist/bollharness-integration/guard-checker.js.map +0 -1
- package/dist/bollharness-integration/index.js.map +0 -1
- package/dist/bollharness-integration/integration.js.map +0 -1
- package/dist/bollharness-integration/llm/pi-ai.d.ts +0 -60
- package/dist/bollharness-integration/pi-ecosystem-colony/index.d.ts +0 -153
- package/dist/bollharness-integration/pi-ecosystem-goals/index.d.ts +0 -136
- package/dist/bollharness-integration/pi-ecosystem-judgment/decision.d.ts +0 -117
- package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.d.ts +0 -78
- package/dist/bollharness-integration/pi-ecosystem-judgment/index.d.ts +0 -139
- package/dist/bollharness-integration/pi-ecosystem-mcp/index.d.ts +0 -127
- package/dist/bollharness-integration/pi-ecosystem-subagents/index.d.ts +0 -95
- package/dist/bollharness-integration/skill-adapter.js.map +0 -1
- package/dist/constraint-runtime/src/_archive_helper.js +0 -9
- package/dist/constraint-runtime/src/agent/coordinator.js +0 -48
- package/dist/constraint-runtime/src/agent/index.js +0 -1
- package/dist/constraint-runtime/src/assistant/index.js +0 -12
- package/dist/constraint-runtime/src/bootstrap/index.js +0 -12
- package/dist/constraint-runtime/src/bootstrap_graph.js +0 -13
- package/dist/constraint-runtime/src/bridge/index.js +0 -12
- package/dist/constraint-runtime/src/buddy/index.js +0 -12
- package/dist/constraint-runtime/src/cli/index.js +0 -12
- package/dist/constraint-runtime/src/command_graph.js +0 -10
- package/dist/constraint-runtime/src/commands.js +0 -60
- package/dist/constraint-runtime/src/components/index.js +0 -12
- package/dist/constraint-runtime/src/constants/index.js +0 -12
- package/dist/constraint-runtime/src/constraint/budget.js +0 -22
- package/dist/constraint-runtime/src/constraint/budget.js.map +0 -1
- package/dist/constraint-runtime/src/constraint/index.js +0 -2
- package/dist/constraint-runtime/src/constraint/permission.js +0 -20
- package/dist/constraint-runtime/src/constraint/permission.js.map +0 -1
- package/dist/constraint-runtime/src/context.js +0 -30
- package/dist/constraint-runtime/src/coordinator/index.js +0 -12
- package/dist/constraint-runtime/src/cost_hook.js +0 -4
- package/dist/constraint-runtime/src/cost_tracker.js +0 -8
- package/dist/constraint-runtime/src/deferred_init.js +0 -10
- package/dist/constraint-runtime/src/direct_modes.js +0 -6
- package/dist/constraint-runtime/src/dynamic-tool-loader.js +0 -85
- package/dist/constraint-runtime/src/entrypoints/index.js +0 -12
- package/dist/constraint-runtime/src/execution_registry.js +0 -44
- package/dist/constraint-runtime/src/history.js +0 -9
- package/dist/constraint-runtime/src/hooks/index.js +0 -12
- package/dist/constraint-runtime/src/index.js +0 -26
- package/dist/constraint-runtime/src/ink.js +0 -4
- package/dist/constraint-runtime/src/keybindings/index.js +0 -12
- package/dist/constraint-runtime/src/memdir/index.js +0 -12
- package/dist/constraint-runtime/src/migrations/index.js +0 -12
- package/dist/constraint-runtime/src/models.js +0 -1
- package/dist/constraint-runtime/src/models.js.map +0 -1
- package/dist/constraint-runtime/src/moreright/index.js +0 -12
- package/dist/constraint-runtime/src/native_ts/index.js +0 -12
- package/dist/constraint-runtime/src/output_styles/index.js +0 -12
- package/dist/constraint-runtime/src/parity_audit.js +0 -12
- package/dist/constraint-runtime/src/plugins/index.js +0 -12
- package/dist/constraint-runtime/src/port_manifest.js +0 -11
- package/dist/constraint-runtime/src/prefetch.js +0 -9
- package/dist/constraint-runtime/src/query.js +0 -1
- package/dist/constraint-runtime/src/remote/index.js +0 -12
- package/dist/constraint-runtime/src/remote_runtime.js +0 -9
- package/dist/constraint-runtime/src/runtime/index.js +0 -1
- package/dist/constraint-runtime/src/runtime/session.js +0 -35
- package/dist/constraint-runtime/src/schemas/index.js +0 -12
- package/dist/constraint-runtime/src/screens/index.js +0 -12
- package/dist/constraint-runtime/src/server/index.js +0 -12
- package/dist/constraint-runtime/src/services/index.js +0 -12
- package/dist/constraint-runtime/src/session_store.js +0 -22
- package/dist/constraint-runtime/src/setup.js +0 -30
- package/dist/constraint-runtime/src/skills/index.js +0 -1
- package/dist/constraint-runtime/src/skills/skill-registry.js +0 -28
- package/dist/constraint-runtime/src/state/index.js +0 -12
- package/dist/constraint-runtime/src/system_init.js +0 -20
- package/dist/constraint-runtime/src/thinking/engine.js +0 -42
- package/dist/constraint-runtime/src/thinking/index.js +0 -1
- package/dist/constraint-runtime/src/tool_pool.js +0 -8
- package/dist/constraint-runtime/src/tools/OpenCLI/execAdapter.js +0 -7
- package/dist/constraint-runtime/src/tools/OpenCLI/listAdapters.js +0 -7
- package/dist/constraint-runtime/src/tools/OpenCLI/runCommand.js +0 -7
- package/dist/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
- package/dist/constraint-runtime/src/tools/SafeSDK/confirmTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/createTransaction.js +0 -8
- package/dist/constraint-runtime/src/tools/SafeSDK/deploySafe.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/executeTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/getBalance.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/proposeTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/WalletTools/autoPay.js +0 -29
- package/dist/constraint-runtime/src/tools/WalletTools/createWallet.js +0 -10
- package/dist/constraint-runtime/src/tools/WalletTools/getBalance.js +0 -13
- package/dist/constraint-runtime/src/tools/WalletTools/importWallet.js +0 -22
- package/dist/constraint-runtime/src/tools/WalletTools/sendTransaction.js +0 -25
- package/dist/constraint-runtime/src/tools/WalletTools/signMessage.js +0 -10
- package/dist/constraint-runtime/src/tools/WalletTools/transferToken.js +0 -25
- package/dist/constraint-runtime/src/tools.js +0 -80
- package/dist/constraint-runtime/src/transcript.js +0 -19
- package/dist/constraint-runtime/src/types/index.js +0 -12
- package/dist/constraint-runtime/src/upstream_proxy/index.js +0 -12
- package/dist/constraint-runtime/src/utils/index.js +0 -12
- package/dist/constraint-runtime/src/vim/index.js +0 -12
- package/dist/constraint-runtime/src/voice/index.js +0 -12
- package/dist/constraints/index.js.map +0 -1
- package/dist/documents/reader.js.map +0 -1
- package/dist/llm/config-store.js.map +0 -1
- package/dist/llm/pi-ai.js.map +0 -1
- package/dist/network/agent-network.js.map +0 -1
- package/dist/network/iroh-integration.js.map +0 -1
- package/dist/network/iroh-transport.js.map +0 -1
- package/dist/network/p2p.js.map +0 -1
- package/dist/network/storage/adapters/json-adapter.js.map +0 -1
- package/dist/pi-ecosystem-colony/index.js.map +0 -1
- package/dist/pi-ecosystem-goals/index.js.map +0 -1
- package/dist/pi-ecosystem-judgment/decision.js.map +0 -1
- package/dist/pi-ecosystem-judgment/distillation.js.map +0 -1
- package/dist/pi-ecosystem-judgment/human-value-store.js.map +0 -1
- package/dist/pi-ecosystem-judgment/index.js.map +0 -1
- package/dist/pi-ecosystem-judgment/value-injection.js.map +0 -1
- package/dist/pi-ecosystem-mcp/index.js.map +0 -1
- package/dist/pi-ecosystem-subagents/index.js.map +0 -1
- package/dist/social/ant-colony/AdaptiveHeartbeat.js.map +0 -1
- package/dist/social/ant-colony/PheromoneEngine.js.map +0 -1
- package/dist/social/ant-colony/types.js.map +0 -1
- package/dist/social/channels/ChannelManager.js.map +0 -1
- package/dist/social/channels/DiapChannelBridge.js.map +0 -1
- package/dist/social/channels/InterestMatcher.js.map +0 -1
- package/dist/social/channels/types.js.map +0 -1
- package/dist/social/global-shared-context.js.map +0 -1
- package/dist/social/heartbeat.js.map +0 -1
- package/lefthook.yml +0 -33
- package/scripts/auto-evolve-loop.ts +0 -481
- package/scripts/build-web.ts +0 -116
- package/scripts/diff-reviewer.ts +0 -159
- package/scripts/validate-system-prompt.ts +0 -142
- package/scripts/weekly-report.ts +0 -364
- package/src/agents/agent-manifest-protocol.ts +0 -117
- package/src/agents/constraint-layer.ts +0 -309
- package/src/agents/iroh-secret.ts +0 -32
- package/src/agents/p2p-chat-tools.ts +0 -383
- package/src/agents/p2p-document-tools.ts +0 -347
- package/src/agents/permission-mode.ts +0 -127
- package/src/agents/pi-sdk.ts +0 -2895
- package/src/agents/pre-tool-validator.ts +0 -213
- package/src/agents/protocol.ts +0 -398
- package/src/agents/shell-guard.ts +0 -417
- package/src/agents/shell-tool.ts +0 -103
- package/src/agents/skill-loader.ts +0 -202
- package/src/agents/subagent-manager.ts +0 -553
- package/src/agents/workflow-engine.ts +0 -332
- package/src/agents/workflow-pivot-loop.ts +0 -766
- package/src/bollharness/.sanitize-report.json +0 -13
- package/src/bollharness/CLAUDE.md +0 -73
- package/src/bollharness/LICENSE +0 -21
- package/src/bollharness/README.md +0 -143
- package/src/bollharness/README.zh-CN.md +0 -131
- package/src/bollharness/package.json +0 -20
- package/src/bollharness/reference/SOURCE-COMMIT.txt +0 -3
- package/src/bollharness/reference/boll-reference/scripts/hooks/.sanitize-report.json +0 -12
- package/src/bollharness/reference/boll-reference/scripts/hooks/find-boll-root.sh +0 -27
- package/src/bollharness/reference/boll-reference/scripts/hooks/precompact.sh +0 -57
- package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +0 -57
- package/src/bollharness/schemas/metrics-jsonl-allowlist.json +0 -67
- package/src/bollharness/scripts/checks/next_decision_number.sh +0 -48
- package/src/bollharness/scripts/ci/count-components.sh +0 -65
- package/src/bollharness/scripts/context-fragments/artifact-linkage.md +0 -14
- package/src/bollharness/scripts/context-fragments/auth-consumers.md +0 -17
- package/src/bollharness/scripts/context-fragments/bridge-constitution.md +0 -13
- package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +0 -18
- package/src/bollharness/scripts/context-fragments/closure-checklist.md +0 -13
- package/src/bollharness/scripts/context-fragments/contract-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/db-shared-structures.md +0 -15
- package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +0 -19
- package/src/bollharness/scripts/context-fragments/general-dev-principles.md +0 -11
- package/src/bollharness/scripts/context-fragments/issue-first.md +0 -8
- package/src/bollharness/scripts/context-fragments/mcp-parity.md +0 -16
- package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +0 -108
- package/src/bollharness/scripts/context-fragments/protocol-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/run-events-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/scene-fidelity.md +0 -13
- package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +0 -15
- package/src/bollharness/scripts/context-fragments/two-language.md +0 -15
- package/src/bollharness/scripts/context-fragments/version-sources.md +0 -14
- package/src/bollharness/scripts/hooks/find-project-root.sh +0 -47
- package/src/bollharness/scripts/hooks/inbox-poll.sh +0 -78
- package/src/bollharness/scripts/hooks/precompact.sh +0 -56
- package/src/bollharness/scripts/hooks/stop-evaluator.md +0 -83
- package/src/bollharness/scripts/sync-from-upstream.sh +0 -281
- package/src/bollharness/src/index.ts +0 -5
- package/src/bollharness/src/scripts/checks/check_adr_plan_numbering.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_api_types.ts +0 -52
- package/src/bollharness/src/scripts/checks/check_artifact_link.ts +0 -156
- package/src/bollharness/src/scripts/checks/check_bridge_deps.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_bugfix_binding.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_bugfix_binding_ci.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_doc_file_references.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_doc_freshness.ts +0 -141
- package/src/bollharness/src/scripts/checks/check_doc_links.ts +0 -36
- package/src/bollharness/src/scripts/checks/check_file_existence_claims.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_fragment_integrity.ts +0 -40
- package/src/bollharness/src/scripts/checks/check_hook_installed.ts +0 -70
- package/src/bollharness/src/scripts/checks/check_issue_closure.ts +0 -51
- package/src/bollharness/src/scripts/checks/check_mcp_parity.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_security.ts +0 -54
- package/src/bollharness/src/scripts/checks/check_skill_parity.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_versions.ts +0 -11
- package/src/bollharness/src/scripts/checks/finding.ts +0 -35
- package/src/bollharness/src/scripts/checks/next_decision_number.ts +0 -24
- package/src/bollharness/src/scripts/checks/regenerate_magic_docs.ts +0 -11
- package/src/bollharness/src/scripts/ci/detect_rebaseline_triggers.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_subprocess_cfg.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_verify_artifacts.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_yaml_schema.ts +0 -14
- package/src/bollharness/src/scripts/context_router.ts +0 -76
- package/src/bollharness/src/scripts/deploy-guard.ts +0 -182
- package/src/bollharness/src/scripts/guard-feedback.ts +0 -215
- package/src/bollharness/src/scripts/guard_router.ts +0 -194
- package/src/bollharness/src/scripts/hooks/_hook_output.js +0 -3
- package/src/bollharness/src/scripts/hooks/_hook_output.ts +0 -11
- package/src/bollharness/src/scripts/hooks/auto-python3.ts +0 -10
- package/src/bollharness/src/scripts/hooks/deploy-progress-on-session-end.ts +0 -10
- package/src/bollharness/src/scripts/hooks/failure-analyzer.ts +0 -10
- package/src/bollharness/src/scripts/hooks/gate-judgment-inject.ts +0 -111
- package/src/bollharness/src/scripts/hooks/gate-transition-judgment.ts +0 -74
- package/src/bollharness/src/scripts/hooks/inbox-ack.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-inject-on-start.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-validate.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-write-ledger.ts +0 -10
- package/src/bollharness/src/scripts/hooks/initializer-agent.ts +0 -10
- package/src/bollharness/src/scripts/hooks/loop-detection.ts +0 -83
- package/src/bollharness/src/scripts/hooks/owner-guard.ts +0 -10
- package/src/bollharness/src/scripts/hooks/precompact.ts +0 -10
- package/src/bollharness/src/scripts/hooks/review-agent-gatekeeper.ts +0 -10
- package/src/bollharness/src/scripts/hooks/risk-tracker.ts +0 -121
- package/src/bollharness/src/scripts/hooks/sanitize-on-read.ts +0 -10
- package/src/bollharness/src/scripts/hooks/session-reflection.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-magic-docs.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-reset-risk.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-toolkit-reminder.ts +0 -12
- package/src/bollharness/src/scripts/hooks/stop-evaluator.ts +0 -164
- package/src/bollharness/src/scripts/hooks/tool-call-counter.ts +0 -10
- package/src/bollharness/src/scripts/hooks/trace-analyzer.ts +0 -14
- package/src/bollharness/src/scripts/install/install-trust-token.ts +0 -13
- package/src/bollharness/src/scripts/install/multi_project_registry.ts +0 -13
- package/src/bollharness/src/scripts/install/phase2_auto.ts +0 -28
- package/src/bollharness/src/scripts/install/pre_commit_installer.ts +0 -10
- package/src/bollharness/src/scripts/install/tier_selector.ts +0 -10
- package/src/bollharness/src/scripts/install/transcript_miner.ts +0 -13
- package/src/bollharness/src/scripts/lib/claim_patterns.ts +0 -11
- package/src/bollharness/src/scripts/lib/sanitize_patterns.ts +0 -13
- package/src/bollharness/src/scripts/sanitize.ts +0 -9
- package/src/bollharness/templates/persona/default.json +0 -19
- package/src/bollharness/templates/scaffold/.gitignore.append +0 -16
- package/src/bollharness/templates/scaffold/CLAUDE.md +0 -89
- package/src/bollharness-integration/channel-judgment-engine.ts +0 -634
- package/src/bollharness-integration/context-chain-router.ts +0 -474
- package/src/bollharness-integration/context-router-judgment.ts +0 -339
- package/src/bollharness-integration/context-router.ts +0 -583
- package/src/bollharness-integration/gate-state-machine.ts +0 -444
- package/src/bollharness-integration/gate-transition-hooks.ts +0 -137
- package/src/bollharness-integration/guard-checker.ts +0 -451
- package/src/bollharness-integration/index.ts +0 -195
- package/src/bollharness-integration/integration.ts +0 -538
- package/src/bollharness-integration/judgment-prompts.yaml +0 -535
- package/src/bollharness-integration/llm-judgment-engine.ts +0 -712
- package/src/bollharness-integration/skill-adapter.ts +0 -646
- package/src/bootstrap/bootstrap.ts +0 -135
- package/src/bootstrap/context-collector.ts +0 -371
- package/src/bootstrap/context-hierarchy.ts +0 -283
- package/src/bootstrap/lifecycle-hooks.ts +0 -289
- package/src/bootstrap/project-context.ts +0 -171
- package/src/cli/interface.ts +0 -211
- package/src/cli-entry.ts +0 -304
- package/src/constraints/index.ts +0 -6
- package/src/context-compaction/auto-compact.ts +0 -153
- package/src/context-compaction/budget-gate.ts +0 -32
- package/src/context-compaction/budget-reduce.ts +0 -37
- package/src/context-compaction/context-collapse.ts +0 -72
- package/src/context-compaction/index.ts +0 -24
- package/src/context-compaction/microcompact.ts +0 -54
- package/src/context-compaction/pipeline.ts +0 -133
- package/src/context-compaction/snip.ts +0 -51
- package/src/context-compaction/token-estimator.ts +0 -36
- package/src/context-compaction/types.ts +0 -99
- package/src/documents/reader.ts +0 -85
- package/src/documents/store.ts +0 -252
- package/src/electron-preload.ts +0 -25
- package/src/electron.ts +0 -200
- package/src/heartbeat/DaemonManager.ts +0 -283
- package/src/heartbeat/HealthMonitor.ts +0 -317
- package/src/heartbeat/StartupVerifier.ts +0 -223
- package/src/heartbeat/Watchdog.ts +0 -208
- package/src/heartbeat/index.ts +0 -109
- package/src/heartbeat/self-improve-bus.ts +0 -110
- package/src/heartbeat/types.ts +0 -82
- package/src/index.ts +0 -1724
- package/src/llm/audio-config-store.ts +0 -246
- package/src/llm/config-store.ts +0 -400
- package/src/llm/llm-judgment-client.ts +0 -471
- package/src/llm/pi-ai.ts +0 -653
- package/src/llm/system-prompt/health.ts +0 -159
- package/src/llm/system-prompt/layers/channel/local.md +0 -14
- package/src/llm/system-prompt/layers/channel/p2p-agent.md +0 -18
- package/src/llm/system-prompt/layers/channel/p2p-visitor.md +0 -19
- package/src/llm/system-prompt/layers/core/artifacts_storage.md +0 -89
- package/src/llm/system-prompt/layers/core/evenhandedness.md +0 -21
- package/src/llm/system-prompt/layers/core/hibs_reminders.md +0 -15
- package/src/llm/system-prompt/layers/core/identity.md +0 -37
- package/src/llm/system-prompt/layers/core/knowledge.md +0 -17
- package/src/llm/system-prompt/layers/core/memory_system.md +0 -12
- package/src/llm/system-prompt/layers/core/network_filesystem.md +0 -28
- package/src/llm/system-prompt/layers/core/refusal.md +0 -37
- package/src/llm/system-prompt/layers/core/tone.md +0 -31
- package/src/llm/system-prompt/layers/core/tools.thin.md +0 -13
- package/src/llm/system-prompt/layers/core/wellbeing.md +0 -41
- package/src/llm/system-prompt/layers/role/architect.md +0 -20
- package/src/llm/system-prompt/layers/role/expert.md +0 -19
- package/src/llm/system-prompt/layers/role/implementer.md +0 -15
- package/src/llm/system-prompt/layers/role/security.md +0 -15
- package/src/llm/system-prompt/layers/tool/artifacts.md +0 -72
- package/src/llm/system-prompt/layers/tool/bash.md +0 -25
- package/src/llm/system-prompt/layers/tool/hibs_api.md +0 -171
- package/src/llm/system-prompt/layers/tool/image_search.md +0 -70
- package/src/llm/system-prompt/layers/tool/manifest.md +0 -89
- package/src/llm/system-prompt/layers/tool/mcp_apps.md +0 -53
- package/src/llm/system-prompt/layers/tool/web_search.md +0 -83
- package/src/llm/system-prompt/registry.ts +0 -325
- package/src/llm/system-prompt/strip-hibsml.ts +0 -52
- package/src/llm/tool-manifest/ask_user_input.ts +0 -37
- package/src/llm/tool-manifest/bash.ts +0 -25
- package/src/llm/tool-manifest/create_file.ts +0 -26
- package/src/llm/tool-manifest/fetch_sports_data.ts +0 -28
- package/src/llm/tool-manifest/image_search.ts +0 -26
- package/src/llm/tool-manifest/index.ts +0 -88
- package/src/llm/tool-manifest/mcp.ts +0 -46
- package/src/llm/tool-manifest/message_compose.ts +0 -33
- package/src/llm/tool-manifest/places.ts +0 -86
- package/src/llm/tool-manifest/present_files.ts +0 -23
- package/src/llm/tool-manifest/recipe.ts +0 -42
- package/src/llm/tool-manifest/recommend_apps.ts +0 -25
- package/src/llm/tool-manifest/str_replace.ts +0 -29
- package/src/llm/tool-manifest/types.ts +0 -52
- package/src/llm/tool-manifest/view.ts +0 -26
- package/src/llm/tool-manifest/weather.ts +0 -29
- package/src/llm/tool-manifest/web.ts +0 -54
- package/src/llm/video-config-store.ts +0 -257
- package/src/network/agent-network.ts +0 -800
- package/src/network/hybrid-messenger.ts +0 -199
- package/src/network/iroh-bootstrap.ts +0 -57
- package/src/network/iroh-discovery.ts +0 -208
- package/src/network/iroh-integration.ts +0 -158
- package/src/network/iroh-transport.ts +0 -637
- package/src/network/known-peers.ts +0 -102
- package/src/network/p2p-direct.ts +0 -262
- package/src/network/p2p-secret.ts +0 -153
- package/src/network/p2p.ts +0 -964
- package/src/network/source-intent-broadcaster.ts +0 -242
- package/src/network/source-intent.ts +0 -167
- package/src/network/storage/adapters/json-adapter.ts +0 -454
- package/src/network/storage/index.ts +0 -203
- package/src/network/storage/types.ts +0 -166
- package/src/security/builtin-guards.ts +0 -162
- package/src/security/context-router-tool.ts +0 -122
- package/src/security/input-scanner.ts +0 -287
- package/src/security/react-harness.ts +0 -177
- package/src/security/tool-gate.ts +0 -294
- package/src/social/ant-colony/index.js +0 -19
- package/src/social/channels/ChannelManager.ts +0 -485
- package/src/social/channels/DiapChannelBridge.ts +0 -501
- package/src/social/channels/InterestMatcher.ts +0 -189
- package/src/social/channels/agent-workflow-config.json +0 -214
- package/src/social/channels/agent-workflow-config.yaml +0 -334
- package/src/social/channels/channel-agent-session.ts +0 -407
- package/src/social/channels/channel-heartbeat-agent.ts +0 -622
- package/src/social/channels/diap-doc-parser.ts +0 -282
- package/src/social/channels/harness-workflow-integrator.ts +0 -594
- package/src/social/channels/index.ts +0 -22
- package/src/social/channels/types.ts +0 -115
- package/src/social/global-shared-context.ts +0 -506
- package/src/social/heartbeat.ts +0 -1057
- package/src/social/persona/enhanced-persona.ts +0 -359
- package/src/types.d.ts +0 -12
- package/src/utils/auto-evolve-policy.ts +0 -138
- package/src/utils/auto-update.ts +0 -482
- package/src/utils/clamp.ts +0 -5
- package/src/web/agent-delegate-server.ts +0 -148
- package/src/web/api-config.html +0 -520
- package/src/web/client.js +0 -2352
- package/src/web/client.ts +0 -4326
- package/src/web/components/p2p/P2PModal.tsx +0 -416
- package/src/web/components/p2p/index.ts +0 -566
- package/src/web/components/p2p/index.tsx +0 -297
- package/src/web/components/p2p/p2p-connection.ts +0 -338
- package/src/web/components/p2p/p2p-identity.ts +0 -92
- package/src/web/components/p2p/p2p-manager.ts +0 -147
- package/src/web/components/p2p/p2p-messages.ts +0 -219
- package/src/web/components/p2p/p2p-modal.ts +0 -685
- package/src/web/components/p2p/p2p-store-memory.ts +0 -162
- package/src/web/components/p2p/p2p-tools.ts +0 -315
- package/src/web/components/p2p/types.ts +0 -170
- package/src/web/components/wallet-viem.mjs +0 -118
- package/src/web/design.md +0 -99
- package/src/web/icons/apple-touch-icon.png +0 -0
- package/src/web/icons/favicon-16x16.png +0 -0
- package/src/web/icons/favicon-192x192.png +0 -0
- package/src/web/icons/favicon-32x32.png +0 -0
- package/src/web/icons/favicon-48x48.png +0 -0
- package/src/web/icons/favicon-512x512.png +0 -0
- package/src/web/icons/favicon.icns +0 -0
- package/src/web/icons/favicon.ico +0 -0
- package/src/web/icons/icon.png +0 -0
- package/src/web/icons/image.png +0 -0
- package/src/web/index.html +0 -373
- package/src/web/iroh-delegate-transport.ts +0 -139
- package/src/web/manifest.json +0 -21
- package/src/web/server.ts +0 -5731
- package/src/web/style.css +0 -4737
- package/src/web/ui/message-renderer.ts +0 -540
- package/src/web/ui/step-timeline.ts +0 -394
- package/staging/auto-evolve/clean-001/.review-verdict +0 -9
- package/staging/auto-evolve/clean-001/clean-001.patch +0 -14
- package/staging/auto-evolve/e2e-001/.patch-id +0 -1
- package/staging/auto-evolve/e2e-001/.review-verdict +0 -12
- package/staging/auto-evolve/e2e-001/e2e-001.patch +0 -11
- package/staging/auto-evolve/test-bad/.review-verdict +0 -12
- package/staging/auto-evolve/test-bad/test-bad.patch +0 -11
- package/test-results/.last-run.json +0 -6
- package/test-results/src-test-web-loop-status-b-5734c-atus-bar-/346/230/276/347/244/272-spinner-/344/270/215/346/230/276/347/244/272/345/276/252/347/216/257/350/256/241/346/225/260/error-context.md +0 -285
- package/tsconfig.cli.json +0 -16
- package/tsconfig.electron.json +0 -20
- package/tsconfig.json +0 -18
package/src/index.ts
DELETED
|
@@ -1,1724 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HyperswarmCommunicator,
|
|
3
|
-
createHyperswarmCommunicator,
|
|
4
|
-
createTopic,
|
|
5
|
-
KeyManager,
|
|
6
|
-
AgentAuthManager,
|
|
7
|
-
AgentVerificationManager,
|
|
8
|
-
createVerificationManager,
|
|
9
|
-
type P2PMessage,
|
|
10
|
-
type P2PConnection,
|
|
11
|
-
} from '@diap/sdk';
|
|
12
|
-
import { irohTransport } from './network/iroh-transport.js';
|
|
13
|
-
import { HybridMessenger } from './network/hybrid-messenger.js';
|
|
14
|
-
import * as ed25519 from '@noble/ed25519';
|
|
15
|
-
import { sha512 } from '@noble/hashes/sha2.js';
|
|
16
|
-
import * as fs from 'fs/promises';
|
|
17
|
-
import * as path from 'path';
|
|
18
|
-
import { documentReader } from './documents/reader.js';
|
|
19
|
-
import { initMinimax } from './constraints/index.js';
|
|
20
|
-
import { createAgentSession } from './agents/pi-sdk.js';
|
|
21
|
-
import { createSubAgentManager } from './agents/subagent-manager.js';
|
|
22
|
-
import { getGlobalSharedContext } from './social/global-shared-context.js';
|
|
23
|
-
import { BollharnessIntegration, createBollharnessIntegration } from './bollharness-integration/index.js';
|
|
24
|
-
import * as readline from 'readline';
|
|
25
|
-
// 启动时自动检查更新已禁用 (改用 --update-check / --update-now 显式触发)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const RESET = '\x1b[0m';
|
|
29
|
-
const BOLD = '\x1b[1m';
|
|
30
|
-
const DIM = '\x1b[2m';
|
|
31
|
-
const CYAN = '\x1b[36m';
|
|
32
|
-
const GREEN = '\x1b[32m';
|
|
33
|
-
const YELLOW = '\x1b[33m';
|
|
34
|
-
const BLUE = '\x1b[34m';
|
|
35
|
-
const MAGENTA = '\x1b[35m';
|
|
36
|
-
const WHITE = '\x1b[37m';
|
|
37
|
-
const GRAY = '\x1b[90m';
|
|
38
|
-
const BG_WHITE = '\x1b[47m';
|
|
39
|
-
const BG_BLUE = '\x1b[44m';
|
|
40
|
-
const BLACK = '\x1b[30m';
|
|
41
|
-
const MOVE_UP = '\x1b[A';
|
|
42
|
-
const CLEAR_LINE = '\x1b[2K';
|
|
43
|
-
const HIDE_CURSOR = '\x1b[?25l';
|
|
44
|
-
const SHOW_CURSOR = '\x1b[?25h';
|
|
45
|
-
|
|
46
|
-
const s = {
|
|
47
|
-
banner: () => console.log(`\n${CYAN}${BOLD}
|
|
48
|
-
╔═══════════════════════════════════════════╗
|
|
49
|
-
║ ${WHITE}🤖 Bolloon ${CYAN} ║
|
|
50
|
-
║ ${WHITE}P2P AI Document Processor${CYAN} ║
|
|
51
|
-
╚═══════════════════════════════════════════╝${RESET}\n`),
|
|
52
|
-
|
|
53
|
-
step: (num: number, total: number, text: string, status?: 'ok' | 'loading' | 'warn' | 'error') => {
|
|
54
|
-
const check = status === 'ok' ? `${GREEN}✓` :
|
|
55
|
-
status === 'loading' ? `${YELLOW}⟳` :
|
|
56
|
-
status === 'warn' ? `${YELLOW}⚠` :
|
|
57
|
-
status === 'error' ? `${MAGENTA}✗` :
|
|
58
|
-
`${CYAN}●`;
|
|
59
|
-
console.log(` ${check} ${WHITE}[${num}/${total}]${GRAY} ${text}${RESET}`);
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
success: (text: string) => console.log(` ${GREEN}✓${RESET} ${text}`),
|
|
63
|
-
warn: (text: string) => console.log(` ${YELLOW}⚠${RESET} ${text}`),
|
|
64
|
-
error: (text: string) => console.log(` ${MAGENTA}✗${RESET} ${text}`),
|
|
65
|
-
info: (text: string) => console.log(` ${CYAN}●${RESET} ${text}`),
|
|
66
|
-
|
|
67
|
-
section: (title: string) => {
|
|
68
|
-
console.log(`\n${BLUE}━━━ ${WHITE}${BOLD}${title}${RESET} ${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}`);
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
divider: () => console.log(`\n${GRAY}${'─'.repeat(50)}${RESET}\n`),
|
|
72
|
-
|
|
73
|
-
prompt: (text: string) => console.log(`\n${CYAN}❯ ${WHITE}${text}${RESET}`),
|
|
74
|
-
|
|
75
|
-
response: (label: string, content: string) => {
|
|
76
|
-
console.log(`\n${GREEN}${label}${RESET}\n${content}\n`);
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
agentCard: (agent: { name: string; id: string; status: string; capabilities: string[]; did?: string }) => {
|
|
80
|
-
const statusColor = agent.status === 'active' ? GREEN :
|
|
81
|
-
agent.status === 'idle' ? YELLOW :
|
|
82
|
-
agent.status === 'busy' ? MAGENTA : GRAY;
|
|
83
|
-
console.log(` ${WHITE}${BOLD}${agent.name}${RESET}`);
|
|
84
|
-
console.log(` ${GRAY}ID:${RESET} ${agent.id}`);
|
|
85
|
-
console.log(` ${GRAY}状态:${RESET} ${statusColor}${agent.status}${RESET}`);
|
|
86
|
-
console.log(` ${GRAY}能力:${RESET} ${agent.capabilities.join(', ')}`);
|
|
87
|
-
if (agent.did) console.log(` ${GRAY}DID:${RESET} ${agent.did}`);
|
|
88
|
-
console.log();
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
Thinking: () => {
|
|
92
|
-
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
93
|
-
let i = 0;
|
|
94
|
-
return setInterval(() => {
|
|
95
|
-
process.stdout.write(`\r ${YELLOW}${frames[i++ % frames.length]} 思考中...${RESET} `);
|
|
96
|
-
}, 80);
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
clearThinking: (interval: ReturnType<typeof setInterval>) => {
|
|
100
|
-
clearInterval(interval);
|
|
101
|
-
process.stdout.write('\r' + ' '.repeat(30) + '\r');
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
dialog: async (title: string, promptText: string): Promise<string> => {
|
|
105
|
-
return new Promise((resolve) => {
|
|
106
|
-
const rl = readline.createInterface({
|
|
107
|
-
input: process.stdin,
|
|
108
|
-
output: process.stdout
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
rl.question(`${CYAN}❯ ${RESET}`, (input) => {
|
|
112
|
-
rl.close();
|
|
113
|
-
resolve(input.trim());
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// @ts-ignore - noble/ed25519 v3 requires sha512 to be set
|
|
120
|
-
(ed25519.hashes as any).sha512 = sha512;
|
|
121
|
-
|
|
122
|
-
// ---------------------------------------------------------------------------
|
|
123
|
-
// Message envelope
|
|
124
|
-
// Sender wraps: DID:<hex_did>|{"id":"...","type":"summarize|improve","documentPath":"...","requirements":"..."}
|
|
125
|
-
// So receiver can verify identity before dispatching
|
|
126
|
-
// ---------------------------------------------------------------------------
|
|
127
|
-
|
|
128
|
-
type TaskType = 'summarize' | 'improve';
|
|
129
|
-
|
|
130
|
-
interface RpcTask {
|
|
131
|
-
id: string;
|
|
132
|
-
type: TaskType;
|
|
133
|
-
documentPath?: string;
|
|
134
|
-
requirements?: string;
|
|
135
|
-
from: string; // DID of sender, extracted from message prefix
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
// Harness loop ─ poll-free event-driven (Hyperswarm DHT 自动推送)
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
|
-
|
|
142
|
-
/** 原始 Hyperswarm stream 缓存; HyperswarmCommunicator.sendToConnection 只打日志不写流 */
|
|
143
|
-
const rawStreams = new Map<string, any>();
|
|
144
|
-
|
|
145
|
-
function sendRawMsg(conn: P2PConnection, text: string): void {
|
|
146
|
-
const raw = rawStreams.get(conn as any);
|
|
147
|
-
if (raw && raw.writable) raw.write(Buffer.from(text));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// ---------------------------------------------------------------------------
|
|
151
|
-
// DIAP 身份初始化 ─ KeyManager → DID → DID Builder → IPFS publish
|
|
152
|
-
// ---------------------------------------------------------------------------
|
|
153
|
-
|
|
154
|
-
function getUserName(): string {
|
|
155
|
-
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
156
|
-
const match = home.match(/\/Users\/(\w+)/);
|
|
157
|
-
if (match) return match[1];
|
|
158
|
-
const user = process.env.USERNAME || process.env.USER || 'user';
|
|
159
|
-
return user.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async function bootstrapIdentity(): Promise<{ keypair: import('@diap/sdk').KeyPair; did: string; name: string }> {
|
|
163
|
-
s.step(1, 5, '生成 DIAP 身份', 'loading');
|
|
164
|
-
const kp = KeyManager.generate();
|
|
165
|
-
const did = kp.did;
|
|
166
|
-
const username = getUserName();
|
|
167
|
-
const suffix = did.split(':').pop()?.substring(0, 4);
|
|
168
|
-
const name = `blln-${username}-${suffix}`;
|
|
169
|
-
console.log(` ${GRAY}DID:${RESET} ${did}`);
|
|
170
|
-
console.log(` ${GRAY}名称:${RESET} ${name}`);
|
|
171
|
-
s.step(1, 5, '生成 DIAP 身份', 'ok');
|
|
172
|
-
return { keypair: kp, did, name };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function publishDID(name: string, kp: import('@diap/sdk').KeyPair): Promise<{ cid?: string; ipnsName?: string }> {
|
|
176
|
-
s.step(2, 5, '发布 DID → IPFS (后台)', 'loading');
|
|
177
|
-
|
|
178
|
-
return new Promise((resolve) => {
|
|
179
|
-
const attempt = async () => {
|
|
180
|
-
let lastLogTime = 0;
|
|
181
|
-
const retryWithBackoff = async (retries: number): Promise<void> => {
|
|
182
|
-
try {
|
|
183
|
-
const auth = await AgentAuthManager.newWithRemoteIpfs('http://127.0.0.1:5001', 'http://127.0.0.1:8080');
|
|
184
|
-
const result = await auth.registerAgent({ name, services: [] }, kp, '');
|
|
185
|
-
s.step(2, 5, '发布 DID → IPFS', 'ok');
|
|
186
|
-
resolve({ cid: result.cid });
|
|
187
|
-
} catch (e: any) {
|
|
188
|
-
const now = Date.now();
|
|
189
|
-
if (now - lastLogTime > 30000) {
|
|
190
|
-
process.stdout.write(` ${YELLOW}⏳ IPNS发布中 (失败${retries}次), 后台重试...${RESET}\r`);
|
|
191
|
-
lastLogTime = now;
|
|
192
|
-
}
|
|
193
|
-
if (retries < 10) {
|
|
194
|
-
setTimeout(() => retryWithBackoff(retries + 1), 60000);
|
|
195
|
-
} else {
|
|
196
|
-
process.stdout.write(` ${YELLOW}⚠ IPNS发布重试结束,本地模式运行${RESET}\n`);
|
|
197
|
-
resolve({});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
setTimeout(() => retryWithBackoff(1), 100);
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
attempt();
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
// ---------------------------------------------------------------------------
|
|
210
|
-
// P2P 节点初始化
|
|
211
|
-
// ---------------------------------------------------------------------------
|
|
212
|
-
|
|
213
|
-
async function bootstrapP2P(
|
|
214
|
-
verifier: AgentVerificationManager,
|
|
215
|
-
): Promise<HyperswarmCommunicator> {
|
|
216
|
-
s.step(3, 5, '启动 P2P 网络', 'loading');
|
|
217
|
-
const rawSeed = crypto.getRandomValues(new Uint8Array(32));
|
|
218
|
-
const seed: any = rawSeed;
|
|
219
|
-
const comm = createHyperswarmCommunicator({ server: true, client: true, autoConnect: true, maxConnections: 50, seed });
|
|
220
|
-
|
|
221
|
-
comm.on('connection', (conn: P2PConnection) => {
|
|
222
|
-
const shortId = conn.publicKey.substring(0, 8);
|
|
223
|
-
s.info(`🔌 连接: ${shortId}...`);
|
|
224
|
-
const all: Map<string, P2PConnection> = (comm as any).connections as Map<string, P2PConnection>;
|
|
225
|
-
for (const [k, v] of all) {
|
|
226
|
-
if (v.publicKey === conn.publicKey) {
|
|
227
|
-
rawStreams.set(v['id'], (comm as any)['__pendingStream']);
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
comm.on('message', async (msg: P2PMessage, conn: P2PConnection) => {
|
|
234
|
-
const content = new TextDecoder().decode(msg.content);
|
|
235
|
-
const shortId = conn.publicKey.substring(0, 8);
|
|
236
|
-
s.prompt(`📩 收到 ${shortId}: ${content.substring(0, 50)}...`);
|
|
237
|
-
const reply = await dispatchTask(content);
|
|
238
|
-
sendRawMsg(conn, reply);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
await comm.start();
|
|
242
|
-
const topic = createTopic('bolloon-agent-harness') as Buffer;
|
|
243
|
-
await comm.joinTopic(topic);
|
|
244
|
-
console.log(` ${GRAY}主题:${RESET} ${topic.slice(0, 8).toString('hex')}...`);
|
|
245
|
-
s.step(3, 5, '启动 P2P 网络', 'ok');
|
|
246
|
-
return comm;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
// ---------------------------------------------------------------------------
|
|
250
|
-
// iroh/Hybrid P2P 初始化
|
|
251
|
-
// ---------------------------------------------------------------------------
|
|
252
|
-
|
|
253
|
-
async function bootstrapIroh(keypair: any, name: string): Promise<void> {
|
|
254
|
-
s.step(4, 5, '启动 iroh P2P', 'loading');
|
|
255
|
-
|
|
256
|
-
try {
|
|
257
|
-
const node = await irohTransport.start();
|
|
258
|
-
console.log(` ${GRAY}iroh:${RESET} ${node.nodeId.substring(0, 16)}...`);
|
|
259
|
-
|
|
260
|
-
hybridMessenger = new HybridMessenger({
|
|
261
|
-
preferIrohForLarge: true,
|
|
262
|
-
largeThresholdBytes: 64 * 1024,
|
|
263
|
-
enableRelay: true,
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
hybridMessenger.onMessage('task', async (msg) => {
|
|
267
|
-
console.log(`[iroh] Task from ${msg.from.substring(0, 12)}...: ${new TextDecoder().decode(msg.payload).substring(0, 50)}...`);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
hybridMessenger.onMessage('blob', async (msg) => {
|
|
271
|
-
console.log(`[iroh] Blob from ${msg.from.substring(0, 12)}...: ${msg.payload.length} bytes`);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
hybridMessenger.onMessage('response', async (msg) => {
|
|
275
|
-
console.log(`[iroh] Response from ${msg.from.substring(0, 12)}...`);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
if (agentIdentity) {
|
|
279
|
-
agentIdentity.irohNodeId = node.nodeId;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
s.step(4, 5, '启动 iroh P2P', 'ok');
|
|
283
|
-
} catch (e: any) {
|
|
284
|
-
s.step(4, 5, '启动 iroh P2P', 'warn');
|
|
285
|
-
console.log(` ${YELLOW}iroh 启动失败: ${e.message}${RESET}`);
|
|
286
|
-
console.log(` ${GRAY}继续使用 Hyperswarm P2P${RESET}`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// ---------------------------------------------------------------------------
|
|
291
|
-
// Agent 懒加载
|
|
292
|
-
// ---------------------------------------------------------------------------
|
|
293
|
-
|
|
294
|
-
let agent: Awaited<ReturnType<typeof createAgentSession>> | null = null;
|
|
295
|
-
let harness: BollharnessIntegration | null = null;
|
|
296
|
-
let hybridMessenger: HybridMessenger | null = null;
|
|
297
|
-
let agentIdentity: {
|
|
298
|
-
did: string;
|
|
299
|
-
name: string;
|
|
300
|
-
publicKey: string;
|
|
301
|
-
peerId?: string;
|
|
302
|
-
p2pChannel?: string;
|
|
303
|
-
cid?: string;
|
|
304
|
-
ipnsName?: string;
|
|
305
|
-
irohNodeId?: string;
|
|
306
|
-
} | null = null;
|
|
307
|
-
|
|
308
|
-
async function getAgent() {
|
|
309
|
-
if (!agent) {
|
|
310
|
-
const identityDoc = agentIdentity ? {
|
|
311
|
-
did: agentIdentity.did,
|
|
312
|
-
name: agentIdentity.name,
|
|
313
|
-
publicKey: agentIdentity.publicKey,
|
|
314
|
-
createdAt: Date.now(),
|
|
315
|
-
peerId: agentIdentity.peerId,
|
|
316
|
-
p2pChannel: agentIdentity.p2pChannel,
|
|
317
|
-
cid: agentIdentity.cid,
|
|
318
|
-
ipnsName: agentIdentity.ipnsName
|
|
319
|
-
} : undefined;
|
|
320
|
-
agent = await createAgentSession({
|
|
321
|
-
cwd: process.cwd(),
|
|
322
|
-
peerId: 'harness',
|
|
323
|
-
identityDoc
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
return agent;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// ---------------------------------------------------------------------------
|
|
330
|
-
// Dispatch
|
|
331
|
-
// ---------------------------------------------------------------------------
|
|
332
|
-
|
|
333
|
-
async function dispatchTask(raw: string): Promise<string> {
|
|
334
|
-
const body = raw.startsWith('DID:') ? raw.split('|', 1)[1] || '' : raw;
|
|
335
|
-
const task = safeParse<RpcTask>(body);
|
|
336
|
-
if (!task) return `ERR|${JSON.stringify({ code: 'bad_format' })}`;
|
|
337
|
-
|
|
338
|
-
console.log(`\n📥 [${task.type}] from=${task.from?.substring(0, 18)}... id=${task.id}`);
|
|
339
|
-
try {
|
|
340
|
-
switch (task.type) {
|
|
341
|
-
case 'summarize':
|
|
342
|
-
return await handleSummarize(task);
|
|
343
|
-
case 'improve':
|
|
344
|
-
return await handleImprove(task);
|
|
345
|
-
default:
|
|
346
|
-
return `ERR|${JSON.stringify({ code: 'unknown', type: task.type })}`;
|
|
347
|
-
}
|
|
348
|
-
} catch (e: any) {
|
|
349
|
-
return `ERR|${JSON.stringify({ code: 'error', msg: e.message })}`;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async function handleSummarize(task: RpcTask): Promise<string> {
|
|
354
|
-
if (!task.documentPath) return `ERR|${JSON.stringify({ code: 'no_path' })}`;
|
|
355
|
-
const a = await getAgent();
|
|
356
|
-
const { summary, qualityScore } = await a.summarizeDocument(task.documentPath);
|
|
357
|
-
console.log(` ✅ 质量=${(qualityScore * 10).toFixed(1)}/10`);
|
|
358
|
-
return `OK|${JSON.stringify({ id: task.id, type: 'summarize', qualityScore, summary })}`;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
async function handleImprove(task: RpcTask): Promise<string> {
|
|
362
|
-
if (!task.documentPath || !task.requirements) {
|
|
363
|
-
return `ERR|${JSON.stringify({ code: 'no_path_or_req' })}`;
|
|
364
|
-
}
|
|
365
|
-
const a = await getAgent();
|
|
366
|
-
const res = await a.improveDocument({
|
|
367
|
-
originalPath: task.documentPath,
|
|
368
|
-
requirements: task.requirements,
|
|
369
|
-
context: `来自节点: ${task.from}`,
|
|
370
|
-
});
|
|
371
|
-
const ok = res.improved ?? false;
|
|
372
|
-
console.log(` ✅ 改进${ok ? '成功' : '失败'} 质量=${(res.qualityScore * 10).toFixed(1)}/10 自动发送=${res.shouldAutoSend}`);
|
|
373
|
-
return `OK|${JSON.stringify({
|
|
374
|
-
id: task.id, type: 'improve', improved: ok,
|
|
375
|
-
qualityScore: res.qualityScore, shouldAutoSend: res.shouldAutoSend,
|
|
376
|
-
newContent: res.newContent,
|
|
377
|
-
})}`;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// ---------------------------------------------------------------------------
|
|
381
|
-
// Utils
|
|
382
|
-
// ---------------------------------------------------------------------------
|
|
383
|
-
|
|
384
|
-
function safeParse<T>(s: string): T | null {
|
|
385
|
-
try { return JSON.parse(s) as T; } catch { return null; }
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function rpcErr(code: string, msg: string): string {
|
|
389
|
-
return `ERR|${JSON.stringify({ code, msg })}`;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// ---------------------------------------------------------------------------
|
|
393
|
-
// CLI with persistent bottom prompt
|
|
394
|
-
// ---------------------------------------------------------------------------
|
|
395
|
-
|
|
396
|
-
const SAVE_CURSOR = '\x1b[s';
|
|
397
|
-
const RESTORE_CURSOR = '\x1b[u';
|
|
398
|
-
const MOVE_TO_BOTTOM = '\x1b[999A';
|
|
399
|
-
const HIDE_CURSOR_SEQ = '\x1b[?25l';
|
|
400
|
-
const SHOW_CURSOR_SEQ = '\x1b[?25h';
|
|
401
|
-
const MOVE_UP_1 = '\x1b[1A';
|
|
402
|
-
|
|
403
|
-
let isRunning = false;
|
|
404
|
-
let currentInput = '';
|
|
405
|
-
let promptVisible = false;
|
|
406
|
-
|
|
407
|
-
function getTermHeight(): number {
|
|
408
|
-
return process.stdout.rows || 24;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function moveCursorToBottom(): void {
|
|
412
|
-
const height = getTermHeight();
|
|
413
|
-
process.stdout.write(`\x1b[${height};1H`);
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
function showBottomPrompt(): void {
|
|
417
|
-
if (!isRunning) return;
|
|
418
|
-
promptVisible = true;
|
|
419
|
-
process.stdout.write(SAVE_CURSOR);
|
|
420
|
-
moveCursorToBottom();
|
|
421
|
-
process.stdout.write(`${CYAN}❯ ${RESET}${currentInput}${HIDE_CURSOR_SEQ}`);
|
|
422
|
-
process.stdout.write(RESTORE_CURSOR);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
function clearPromptLine(): void {
|
|
426
|
-
if (!promptVisible) return;
|
|
427
|
-
process.stdout.write(SAVE_CURSOR);
|
|
428
|
-
moveCursorToBottom();
|
|
429
|
-
process.stdout.write(CLEAR_LINE);
|
|
430
|
-
process.stdout.write(RESTORE_CURSOR);
|
|
431
|
-
promptVisible = false;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
function startCLI(comm: HyperswarmCommunicator): void {
|
|
435
|
-
isRunning = true;
|
|
436
|
-
currentInput = '';
|
|
437
|
-
promptVisible = false;
|
|
438
|
-
|
|
439
|
-
try {
|
|
440
|
-
(process.stdin as any).setRawMode(true);
|
|
441
|
-
} catch {
|
|
442
|
-
}
|
|
443
|
-
readline.emitKeypressEvents(process.stdin);
|
|
444
|
-
|
|
445
|
-
process.stdout.write(CLEAR_LINE);
|
|
446
|
-
showBottomPrompt();
|
|
447
|
-
|
|
448
|
-
const promptTimer = setInterval(() => {
|
|
449
|
-
if (isRunning && promptVisible) {
|
|
450
|
-
showBottomPrompt();
|
|
451
|
-
}
|
|
452
|
-
}, 500);
|
|
453
|
-
|
|
454
|
-
const handleInput = (chunk: Buffer, key: { name: string; ctrl: boolean }) => {
|
|
455
|
-
if (!isRunning) return;
|
|
456
|
-
|
|
457
|
-
if (key.ctrl && key.name === 'c') {
|
|
458
|
-
clearPromptLine();
|
|
459
|
-
process.stdout.write(`\n${CYAN}👋 再见!${RESET}\n`);
|
|
460
|
-
try { (process.stdin as any).setRawMode(false); } catch {}
|
|
461
|
-
clearInterval(promptTimer);
|
|
462
|
-
process.exit(0);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (key.name === 'return') {
|
|
467
|
-
const trimmed = currentInput.trim();
|
|
468
|
-
currentInput = '';
|
|
469
|
-
clearPromptLine();
|
|
470
|
-
|
|
471
|
-
if (trimmed) {
|
|
472
|
-
process.stdout.write('\n');
|
|
473
|
-
processInput(trimmed, comm).then(() => {
|
|
474
|
-
if (isRunning) showBottomPrompt();
|
|
475
|
-
});
|
|
476
|
-
} else {
|
|
477
|
-
showBottomPrompt();
|
|
478
|
-
}
|
|
479
|
-
return;
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
if (key.name === 'backspace') {
|
|
483
|
-
if (currentInput.length > 0) {
|
|
484
|
-
currentInput = currentInput.slice(0, -1);
|
|
485
|
-
showBottomPrompt();
|
|
486
|
-
}
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
if (key.name === 'escape' || (key.ctrl && key.name === 'u')) {
|
|
491
|
-
currentInput = '';
|
|
492
|
-
showBottomPrompt();
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
if (key.name === 'tab') {
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
if (key.name && key.name.length === 1) {
|
|
501
|
-
currentInput += chunk.toString();
|
|
502
|
-
showBottomPrompt();
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
process.stdin.on('data', handleInput);
|
|
507
|
-
|
|
508
|
-
process.on('exit', () => {
|
|
509
|
-
isRunning = false;
|
|
510
|
-
process.stdout.write(SHOW_CURSOR_SEQ);
|
|
511
|
-
});
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
async function processInput(input: string, comm: HyperswarmCommunicator): Promise<void> {
|
|
515
|
-
const trimmed = input.trim();
|
|
516
|
-
|
|
517
|
-
if (trimmed === '退出' || trimmed === 'exit' || trimmed === 'quit') {
|
|
518
|
-
clearPromptLine();
|
|
519
|
-
process.stdout.write(`${CYAN}👋 再见!${RESET}\n`);
|
|
520
|
-
isRunning = false;
|
|
521
|
-
process.stdin.destroy();
|
|
522
|
-
comm.stop();
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (trimmed.toLowerCase() === 'peers') {
|
|
527
|
-
const peers = comm.getConnections();
|
|
528
|
-
process.stdout.write(`${GRAY}已连接节点: ${peers.length}${RESET}\n`);
|
|
529
|
-
for (const c of peers) {
|
|
530
|
-
process.stdout.write(` ${GRAY}·${RESET} ${c.publicKey.substring(0, 16)}...\n`);
|
|
531
|
-
}
|
|
532
|
-
return;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
if (trimmed.toLowerCase() === 'iroh') {
|
|
536
|
-
const nodeId = irohTransport.getNodeId();
|
|
537
|
-
const running = irohTransport.isRunning();
|
|
538
|
-
const peers = irohTransport.getPeers();
|
|
539
|
-
process.stdout.write(`${GRAY}iroh 状态:${RESET}\n`);
|
|
540
|
-
process.stdout.write(` ${GRAY}运行中:${RESET} ${running ? '是' : '否'}\n`);
|
|
541
|
-
process.stdout.write(` ${GRAY}Node ID:${RESET} ${nodeId ? nodeId.substring(0, 24) + '...' : 'N/A'}\n`);
|
|
542
|
-
process.stdout.write(` ${GRAY}已知节点:${RESET} ${peers.length}\n`);
|
|
543
|
-
if (hybridMessenger) {
|
|
544
|
-
process.stdout.write(` ${GRAY}HybridMessenger:${RESET} 就绪\n`);
|
|
545
|
-
}
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
try {
|
|
550
|
-
const a = await getAgent();
|
|
551
|
-
const thinking = setInterval(() => {
|
|
552
|
-
if (!isRunning) return;
|
|
553
|
-
process.stdout.write('\r \x1b[33m⟳\x1b[0m 思考中... \x1b[?25l');
|
|
554
|
-
}, 80);
|
|
555
|
-
const response = await a.prompt(trimmed);
|
|
556
|
-
clearInterval(thinking);
|
|
557
|
-
process.stdout.write('\r' + ' '.repeat(30) + '\r');
|
|
558
|
-
process.stdout.write(`${response}\n`);
|
|
559
|
-
} catch (e: any) {
|
|
560
|
-
if (!e.message?.includes('ERR_USE_AFTER_CLOSE') && !e.message?.includes('write after end')) {
|
|
561
|
-
process.stdout.write(`${MAGENTA}❌ ${e.message}${RESET}\n`);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
// ---------------------------------------------------------------------------
|
|
567
|
-
// Non-Interactive Mode (for AI consumption)
|
|
568
|
-
// ---------------------------------------------------------------------------
|
|
569
|
-
|
|
570
|
-
interface NonInteractiveResult {
|
|
571
|
-
success: boolean;
|
|
572
|
-
response?: string;
|
|
573
|
-
error?: string;
|
|
574
|
-
metadata?: {
|
|
575
|
-
duration?: number;
|
|
576
|
-
qualityScore?: number;
|
|
577
|
-
peers?: number;
|
|
578
|
-
file?: string;
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
const AVAILABLE_TOOLS = [
|
|
583
|
-
{ name: 'read_document', description: '读取文档 (txt, md, pdf, docx)', example: '--read <file>' },
|
|
584
|
-
{ name: 'summarize_document', description: '总结文档内容', example: '--summarize <file>' },
|
|
585
|
-
{ name: 'improve_document', description: '改进文档内容', example: '--improve <file> <requirements>' },
|
|
586
|
-
{ name: 'list_peers', description: '列出已连接的对等节点', example: '--peers' },
|
|
587
|
-
{ name: 'send_message', description: '向对等节点发送消息', example: '--send <peerId> <message>' },
|
|
588
|
-
{ name: 'broadcast_message', description: '广播消息到所有节点', example: '--broadcast <message>' },
|
|
589
|
-
{ name: 'get_identity', description: '获取当前智能体身份', example: '--identity' },
|
|
590
|
-
{ name: 'get_operation_logs', description: '获取操作日志', example: '--logs' },
|
|
591
|
-
{ name: 'search_files', description: '搜索文件', example: '--search <keyword>' },
|
|
592
|
-
{ name: 'prompt', description: '通用 AI 对话', example: '--prompt <text>' },
|
|
593
|
-
{ name: 'list_agents', description: '列出所有 SubAgent', example: '--agents' },
|
|
594
|
-
{ name: 'register_agent', description: '注册新 SubAgent', example: '--register-agent <name> [capabilities...]' },
|
|
595
|
-
{ name: 'delegate_task', description: '委派任务给最佳 Agent', example: '--delegate <task> [capabilities...]' },
|
|
596
|
-
{ name: 'global_context', description: '显示全局共享上下文', example: '--context' },
|
|
597
|
-
{ name: 'global_agents', description: '显示全局 Agent 注册表', example: '--global-agents' },
|
|
598
|
-
{ name: 'add_action', description: '添加用户行动到共享上下文', example: '--add-action <content> [importance]' },
|
|
599
|
-
{ name: 'harness_init', description: '初始化 Bollharness 治理框架', example: '--harness-init' },
|
|
600
|
-
{ name: 'harness_gate', description: '显示当前 Gate 状态', example: '--harness-gate' },
|
|
601
|
-
{ name: 'harness_transition', description: '执行 Gate 转移', example: '--harness-transition [PASS|BLOCK]' },
|
|
602
|
-
{ name: 'harness_skill', description: '执行 Harness Skill', example: '--harness-skill <name> [action]' },
|
|
603
|
-
{ name: 'harness_classify', description: '分类变更类型', example: '--harness-classify <description>' },
|
|
604
|
-
{ name: 'harness_context', description: '获取文件上下文', example: '--harness-context <file>' },
|
|
605
|
-
{ name: 'harness_check', description: '执行 Guard 检查', example: '--harness-check <file>' },
|
|
606
|
-
{ name: 'update_check', description: '检查 npm 包更新', example: '--update-check' },
|
|
607
|
-
{ name: 'update_now', description: '立即更新到最新版本', example: '--update-now [package]' },
|
|
608
|
-
];
|
|
609
|
-
|
|
610
|
-
async function runToolCommand(
|
|
611
|
-
tool: string,
|
|
612
|
-
args: string[],
|
|
613
|
-
outputJson: boolean,
|
|
614
|
-
comm: HyperswarmCommunicator
|
|
615
|
-
): Promise<void> {
|
|
616
|
-
const a = await getAgent();
|
|
617
|
-
const startTime = Date.now();
|
|
618
|
-
let response: string;
|
|
619
|
-
let error: string | undefined;
|
|
620
|
-
let metadata: NonInteractiveResult['metadata'] = {
|
|
621
|
-
peers: comm?.getConnections().length || 0
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
const toolLabels: Record<string, string> = {
|
|
625
|
-
'read': '读取文档',
|
|
626
|
-
'summarize': '总结文档',
|
|
627
|
-
'improve': '改进文档',
|
|
628
|
-
'prompt': 'AI 对话',
|
|
629
|
-
'agents': '列出 Agent',
|
|
630
|
-
'register-agent': '注册 Agent',
|
|
631
|
-
'delegate': '委派任务',
|
|
632
|
-
'context': '全局上下文',
|
|
633
|
-
'global-agents': 'Agent 注册表',
|
|
634
|
-
'add-action': '添加行动',
|
|
635
|
-
'peers': '列出节点',
|
|
636
|
-
'broadcast': '广播消息',
|
|
637
|
-
'identity': '显示身份',
|
|
638
|
-
'logs': '操作日志',
|
|
639
|
-
'tools': '可用工具'
|
|
640
|
-
};
|
|
641
|
-
|
|
642
|
-
const label = toolLabels[tool] || tool;
|
|
643
|
-
const thinking = s.Thinking();
|
|
644
|
-
|
|
645
|
-
try {
|
|
646
|
-
switch (tool) {
|
|
647
|
-
case 'read': {
|
|
648
|
-
const [filePath] = args;
|
|
649
|
-
if (!filePath) {
|
|
650
|
-
response = '错误: 缺少文件路径参数';
|
|
651
|
-
error = response;
|
|
652
|
-
break;
|
|
653
|
-
}
|
|
654
|
-
const content = await documentReader.read(filePath);
|
|
655
|
-
response = `${GREEN}📄 ${content.metadata.filename}${RESET}\n${GRAY}大小: ${content.metadata.size} 字节${RESET}\n\n${content.text}`;
|
|
656
|
-
break;
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
case 'summarize': {
|
|
660
|
-
const [filePath, ...ctx] = args;
|
|
661
|
-
if (!filePath) {
|
|
662
|
-
response = '错误: 缺少文件路径参数';
|
|
663
|
-
error = response;
|
|
664
|
-
break;
|
|
665
|
-
}
|
|
666
|
-
const result = await a.summarizeDocument(filePath, ctx.join(' '));
|
|
667
|
-
response = `📝 摘要:\n${result.summary}\n\n质量评分: ${(result.qualityScore * 10).toFixed(1)}/10`;
|
|
668
|
-
metadata.qualityScore = result.qualityScore;
|
|
669
|
-
break;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
case 'improve': {
|
|
673
|
-
const [filePath, ...req] = args;
|
|
674
|
-
if (!filePath || req.length === 0) {
|
|
675
|
-
response = '错误: 缺少文件路径或需求参数';
|
|
676
|
-
error = response;
|
|
677
|
-
break;
|
|
678
|
-
}
|
|
679
|
-
const result = await a.improveDocument({
|
|
680
|
-
originalPath: filePath,
|
|
681
|
-
requirements: req.join(' ')
|
|
682
|
-
});
|
|
683
|
-
response = result.newContent || '';
|
|
684
|
-
if (!result.improved) {
|
|
685
|
-
response = '错误: 改进失败';
|
|
686
|
-
error = response;
|
|
687
|
-
}
|
|
688
|
-
metadata.qualityScore = result.qualityScore;
|
|
689
|
-
break;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
case 'peers': {
|
|
693
|
-
const peers = comm?.getConnections() || [];
|
|
694
|
-
if (peers.length === 0) {
|
|
695
|
-
response = '当前无连接的对等节点';
|
|
696
|
-
} else {
|
|
697
|
-
response = `已连接节点 (${peers.length}):\n${peers.map((c: P2PConnection) => ` · ${c.publicKey.substring(0, 16)}...`).join('\n')}`;
|
|
698
|
-
}
|
|
699
|
-
break;
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
case 'iroh': {
|
|
703
|
-
const nodeId = irohTransport.getNodeId();
|
|
704
|
-
const running = irohTransport.isRunning();
|
|
705
|
-
const irohPeers = irohTransport.getPeers();
|
|
706
|
-
const messenger = hybridMessenger ? 'HybridMessenger 就绪' : 'HybridMessenger 未初始化';
|
|
707
|
-
response = `iroh P2P 状态:
|
|
708
|
-
运行中: ${running ? '是' : '否'}
|
|
709
|
-
Node ID: ${nodeId ? nodeId.substring(0, 32) + '...' : 'N/A'}
|
|
710
|
-
已知节点: ${irohPeers.length}
|
|
711
|
-
${messenger}`;
|
|
712
|
-
break;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
case 'identity': {
|
|
716
|
-
const identity = a.getIdentity();
|
|
717
|
-
response = JSON.stringify(identity, null, 2);
|
|
718
|
-
break;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
case 'logs': {
|
|
722
|
-
const logs = (a as any).getOperationLogs?.() || [];
|
|
723
|
-
response = logs.length === 0
|
|
724
|
-
? '暂无操作日志'
|
|
725
|
-
: logs.map((l: { timestamp: number; status: string; action: string }) => `[${new Date(l.timestamp).toISOString()}] ${l.status}: ${l.action}`).join('\n');
|
|
726
|
-
break;
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
case 'search': {
|
|
730
|
-
const [keyword] = args;
|
|
731
|
-
if (!keyword) {
|
|
732
|
-
response = '错误: 缺少搜索关键词';
|
|
733
|
-
error = response;
|
|
734
|
-
break;
|
|
735
|
-
}
|
|
736
|
-
response = `搜索功能开发中,关键字: ${keyword}`;
|
|
737
|
-
break;
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
case 'broadcast': {
|
|
741
|
-
const [message] = args;
|
|
742
|
-
if (!message) {
|
|
743
|
-
response = '错误: 缺少广播消息内容';
|
|
744
|
-
error = response;
|
|
745
|
-
break;
|
|
746
|
-
}
|
|
747
|
-
await a.broadcast(message);
|
|
748
|
-
response = `广播已发送: ${message.substring(0, 50)}...`;
|
|
749
|
-
break;
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
case 'send': {
|
|
753
|
-
const [peerId, ...messageParts] = args;
|
|
754
|
-
if (!peerId || messageParts.length === 0) {
|
|
755
|
-
response = '错误: 缺少节点ID或消息内容';
|
|
756
|
-
error = response;
|
|
757
|
-
break;
|
|
758
|
-
}
|
|
759
|
-
await a.sendMessage(peerId, messageParts.join(' '));
|
|
760
|
-
response = `消息已发送到 ${peerId.substring(0, 16)}...`;
|
|
761
|
-
break;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
case 'prompt': {
|
|
765
|
-
const [text] = args;
|
|
766
|
-
if (!text) {
|
|
767
|
-
response = '错误: 缺少 prompt 文本';
|
|
768
|
-
error = response;
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
771
|
-
response = await a.prompt(text);
|
|
772
|
-
break;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
case 'tools': {
|
|
776
|
-
response = '🛠️ 可用工具:\n\n' + AVAILABLE_TOOLS.map(t =>
|
|
777
|
-
` ${t.name}\n ${t.description}\n 示例: ${t.example}`
|
|
778
|
-
).join('\n\n');
|
|
779
|
-
break;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// ==================== Bollharness Commands ====================
|
|
783
|
-
|
|
784
|
-
case 'harness-init': {
|
|
785
|
-
harness = createBollharnessIntegration();
|
|
786
|
-
const skills = harness!.listSkills();
|
|
787
|
-
const harnessSkills = harness!.listHarnessSkills();
|
|
788
|
-
response = `✅ Bollharness 初始化成功\n\n` +
|
|
789
|
-
`已加载 Skills: ${skills.length}\n` +
|
|
790
|
-
`已加载 Harness Skills: ${harnessSkills.length}\n\n` +
|
|
791
|
-
`Skills:\n${skills.map(s => ` - ${s.name}: ${s.description}`).join('\n')}\n\n` +
|
|
792
|
-
`Gates: 0-8 (8-Gate 工作流)`;
|
|
793
|
-
break;
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
case 'harness-gate': {
|
|
797
|
-
if (!harness) {
|
|
798
|
-
harness = createBollharnessIntegration();
|
|
799
|
-
}
|
|
800
|
-
const gate = harness!.getCurrentGate();
|
|
801
|
-
const gatePack = harness!.getGatePack();
|
|
802
|
-
const blockers = (gatePack.blockers as string[]) || [];
|
|
803
|
-
response = `🚪 当前 Gate: ${gate}\n\n` +
|
|
804
|
-
`Entry: ${gatePack.entry_satisfied ? '✅ 满足' : '❌ 未满足'}\n` +
|
|
805
|
-
`要求产物: ${gatePack.required_artifact}\n` +
|
|
806
|
-
`下一步 Skill: ${gatePack.required_next_skill}\n` +
|
|
807
|
-
`Blockers: ${blockers.length > 0 ? blockers.join(', ') : '无'}`;
|
|
808
|
-
break;
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
case 'harness-transition': {
|
|
812
|
-
if (!harness) {
|
|
813
|
-
harness = createBollharnessIntegration();
|
|
814
|
-
}
|
|
815
|
-
const [verdict] = args;
|
|
816
|
-
const result = await harness!.transitionGate(
|
|
817
|
-
verdict ? { verdict: verdict as 'PASS' | 'BLOCK', details: '' } : undefined
|
|
818
|
-
);
|
|
819
|
-
const transitionBlockers = (result.transition as { blockers?: string[] })?.blockers || [];
|
|
820
|
-
response = `🔄 Gate 转移: ${result.success ? '✅ 成功' : '❌ 失败'}\n` +
|
|
821
|
-
`Blockers: ${transitionBlockers.length > 0 ? transitionBlockers.join(', ') : '无'}`;
|
|
822
|
-
break;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
case 'harness-skill': {
|
|
826
|
-
if (!harness) {
|
|
827
|
-
harness = createBollharnessIntegration();
|
|
828
|
-
}
|
|
829
|
-
const [skillName, action] = args;
|
|
830
|
-
if (!skillName) {
|
|
831
|
-
const skills = harness!.listSkills();
|
|
832
|
-
response = `📋 可用 Skills (${skills.length}):\n\n` +
|
|
833
|
-
skills.map(s => ` ${s.name}: ${s.description}`).join('\n');
|
|
834
|
-
break;
|
|
835
|
-
}
|
|
836
|
-
const result = await harness!.executeSkill(skillName, { action: action || 'get_gate' });
|
|
837
|
-
response = `🎯 Skill '${skillName}' 执行结果:\n\n${result.result || result.error}`;
|
|
838
|
-
break;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
case 'harness-classify': {
|
|
842
|
-
if (!harness) {
|
|
843
|
-
harness = createBollharnessIntegration();
|
|
844
|
-
}
|
|
845
|
-
const [description] = args;
|
|
846
|
-
if (!description) {
|
|
847
|
-
response = '用法: --harness-classify <变更描述>';
|
|
848
|
-
error = response;
|
|
849
|
-
break;
|
|
850
|
-
}
|
|
851
|
-
const result = harness!.classifyChange(description);
|
|
852
|
-
response = `📊 变更分类: ${result.classification}\n` +
|
|
853
|
-
`最小路径: ${result.minimum_gates}\n` +
|
|
854
|
-
`快速通道: ${result.fast_track ? '✅ 可用' : '❌ 不可用'}`;
|
|
855
|
-
break;
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
case 'harness-context': {
|
|
859
|
-
if (!harness) {
|
|
860
|
-
harness = createBollharnessIntegration();
|
|
861
|
-
}
|
|
862
|
-
const [filePath] = args;
|
|
863
|
-
if (!filePath) {
|
|
864
|
-
response = '用法: --harness-context <文件路径>';
|
|
865
|
-
error = response;
|
|
866
|
-
break;
|
|
867
|
-
}
|
|
868
|
-
const context = harness!.getContext(filePath);
|
|
869
|
-
response = `📄 文件: ${filePath}\n\n上下文:\n${context || '无匹配上下文'}`;
|
|
870
|
-
break;
|
|
871
|
-
}
|
|
872
|
-
|
|
873
|
-
case 'harness-check': {
|
|
874
|
-
if (!harness) {
|
|
875
|
-
harness = createBollharnessIntegration();
|
|
876
|
-
}
|
|
877
|
-
const [filePath] = args;
|
|
878
|
-
if (!filePath) {
|
|
879
|
-
response = '用法: --harness-check <文件路径>';
|
|
880
|
-
error = response;
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
const result = await harness!.processFileEdit(filePath);
|
|
884
|
-
response = `🔍 Guard 检查: ${filePath}\n\n` +
|
|
885
|
-
`通过: ${result.success ? '✅' : '❌'}\n` +
|
|
886
|
-
`错误: ${result.errors.length > 0 ? result.errors.join('\n') : '无'}`;
|
|
887
|
-
break;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
case 'harness-archive': {
|
|
891
|
-
const a = await getAgent();
|
|
892
|
-
const sessionHarness = (a as any).getHarness?.();
|
|
893
|
-
if (sessionHarness) {
|
|
894
|
-
(a as any).archiveToHarness?.();
|
|
895
|
-
response = `📦 Session 已归档到 Pi SDK Harness`;
|
|
896
|
-
} else {
|
|
897
|
-
if (!harness) {
|
|
898
|
-
harness = createBollharnessIntegration();
|
|
899
|
-
}
|
|
900
|
-
const logs = (a as any).getOperationLogs?.() || [];
|
|
901
|
-
const archive = harness.archiveSession(logs);
|
|
902
|
-
response = `📦 Session 已归档:\n` +
|
|
903
|
-
`ID: ${archive.id}\n` +
|
|
904
|
-
`Gate: ${archive.gate}\n` +
|
|
905
|
-
`动作数: ${archive.actionCount}\n` +
|
|
906
|
-
`摘要: ${archive.summary}`;
|
|
907
|
-
}
|
|
908
|
-
break;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
case 'harness-sessions': {
|
|
912
|
-
const a = await getAgent();
|
|
913
|
-
const sessionHarness = (a as any).getHarness?.();
|
|
914
|
-
if (sessionHarness) {
|
|
915
|
-
harness = sessionHarness;
|
|
916
|
-
}
|
|
917
|
-
if (!harness) {
|
|
918
|
-
harness = createBollharnessIntegration();
|
|
919
|
-
}
|
|
920
|
-
const archives = harness.getSessionArchives();
|
|
921
|
-
if (archives.length === 0) {
|
|
922
|
-
response = '暂无 Session 归档记录';
|
|
923
|
-
break;
|
|
924
|
-
}
|
|
925
|
-
response = `📜 Session 归档记录 (${archives.length}):\n\n`;
|
|
926
|
-
for (const archive of archives.slice(-10)) {
|
|
927
|
-
response += `### ${archive.id}\n`;
|
|
928
|
-
response += `Gate: ${archive.gate} | 动作: ${archive.actionCount}\n`;
|
|
929
|
-
response += `摘要: ${archive.summary}\n\n`;
|
|
930
|
-
}
|
|
931
|
-
break;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
case 'harness-session-context': {
|
|
935
|
-
const a = await getAgent();
|
|
936
|
-
const sessionHarness = (a as any).getHarness?.();
|
|
937
|
-
if (sessionHarness) {
|
|
938
|
-
const [sessionId] = args;
|
|
939
|
-
const context = sessionHarness.getSessionContext(sessionId || undefined);
|
|
940
|
-
response = `📄 Pi SDK Session 上下文:\n\n${context}`;
|
|
941
|
-
} else {
|
|
942
|
-
if (!harness) {
|
|
943
|
-
harness = createBollharnessIntegration();
|
|
944
|
-
}
|
|
945
|
-
const [sessionId] = args;
|
|
946
|
-
const context = harness.getSessionContext(sessionId || undefined);
|
|
947
|
-
response = `📄 Session 上下文:\n\n${context}`;
|
|
948
|
-
}
|
|
949
|
-
break;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
case 'agents': {
|
|
953
|
-
const manager = await createSubAgentManager();
|
|
954
|
-
const agents = await manager.getAllAgents();
|
|
955
|
-
if (agents.length === 0) {
|
|
956
|
-
response = '暂无注册的 SubAgent';
|
|
957
|
-
} else {
|
|
958
|
-
response = `📋 已注册 SubAgent (${agents.length}):\n\n`;
|
|
959
|
-
for (const agent of agents) {
|
|
960
|
-
response += ` [${agent.status}] ${agent.name} (${agent.id})\n`;
|
|
961
|
-
response += ` 能力: ${agent.capabilities.join(', ')}\n`;
|
|
962
|
-
response += ` DID: ${agent.did || 'N/A'}\n\n`;
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
break;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
case 'register-agent': {
|
|
969
|
-
const [name, ...capabilities] = args;
|
|
970
|
-
if (!name) {
|
|
971
|
-
response = '用法: --register-agent <name> [capability1] [capability2] ...';
|
|
972
|
-
error = response;
|
|
973
|
-
break;
|
|
974
|
-
}
|
|
975
|
-
const manager = await createSubAgentManager();
|
|
976
|
-
const agent = await manager.registerAgent({
|
|
977
|
-
name,
|
|
978
|
-
capabilities: capabilities.length > 0 ? capabilities : ['general'],
|
|
979
|
-
did: `did:local:${Date.now()}`
|
|
980
|
-
});
|
|
981
|
-
response = `✅ SubAgent 注册成功:\n ID: ${agent.id}\n 名称: ${agent.name}\n 能力: ${agent.capabilities.join(', ')}`;
|
|
982
|
-
break;
|
|
983
|
-
}
|
|
984
|
-
|
|
985
|
-
case 'delegate': {
|
|
986
|
-
const [taskDesc, ...requiredCaps] = args;
|
|
987
|
-
if (!taskDesc) {
|
|
988
|
-
response = '用法: --delegate <任务描述> [能力要求1] [能力要求2] ...';
|
|
989
|
-
error = response;
|
|
990
|
-
break;
|
|
991
|
-
}
|
|
992
|
-
const manager = await createSubAgentManager();
|
|
993
|
-
const a = await getAgent();
|
|
994
|
-
const { task, agent } = await manager.delegateTask(
|
|
995
|
-
'cli-user',
|
|
996
|
-
taskDesc,
|
|
997
|
-
requiredCaps.length > 0 ? requiredCaps : ['general']
|
|
998
|
-
);
|
|
999
|
-
if (agent) {
|
|
1000
|
-
response = `✅ 任务已委派:\n 任务ID: ${task.id}\n 执行Agent: ${agent.name} (${agent.id})\n 状态: ${task.status}`;
|
|
1001
|
-
} else {
|
|
1002
|
-
response = `⚠️ 未找到合适的Agent,任务已创建:\n 任务ID: ${task.id}\n 状态: ${task.status}`;
|
|
1003
|
-
}
|
|
1004
|
-
break;
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
case 'context': {
|
|
1008
|
-
const ctx = await getGlobalSharedContext();
|
|
1009
|
-
response = await ctx.getContextSummary();
|
|
1010
|
-
break;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
case 'global-agents': {
|
|
1014
|
-
const ctx = await getGlobalSharedContext();
|
|
1015
|
-
const agents = await ctx.getAllAgents();
|
|
1016
|
-
if (agents.length === 0) {
|
|
1017
|
-
response = '全局注册表暂无 Agent';
|
|
1018
|
-
} else {
|
|
1019
|
-
response = `🌐 全局 Agent 注册表 (${agents.length}):\n\n`;
|
|
1020
|
-
for (const agent of agents) {
|
|
1021
|
-
response += ` [${agent.status}] ${agent.name || agent.agentId}\n`;
|
|
1022
|
-
response += ` ID: ${agent.agentId}\n`;
|
|
1023
|
-
response += ` DID: ${agent.did || 'N/A'}\n`;
|
|
1024
|
-
response += ` 能力: ${agent.capabilities.join(', ')}\n\n`;
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
break;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
case 'add-action': {
|
|
1031
|
-
const [content, importance] = args;
|
|
1032
|
-
if (!content) {
|
|
1033
|
-
response = '用法: --add-action <内容> [重要性(1-10)]';
|
|
1034
|
-
error = response;
|
|
1035
|
-
break;
|
|
1036
|
-
}
|
|
1037
|
-
const ctx = await getGlobalSharedContext();
|
|
1038
|
-
await ctx.addUserAction(content, undefined, undefined, parseInt(importance || '5', 10));
|
|
1039
|
-
response = `✅ 已添加用户行动: ${content.substring(0, 50)}...`;
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
// ==================== Update Commands ====================
|
|
1044
|
-
|
|
1045
|
-
case 'update-check': {
|
|
1046
|
-
const { checkForUpdates } = await import('./utils/auto-update.js');
|
|
1047
|
-
const info = await checkForUpdates();
|
|
1048
|
-
if (info && info.outdated) {
|
|
1049
|
-
response = `📦 发现更新可用:\n\n` +
|
|
1050
|
-
`当前版本: ${info.version}\n` +
|
|
1051
|
-
`最新版本: ${info.latest}\n\n` +
|
|
1052
|
-
`待更新包:\n${info.packages.map(p => ` - ${p.name}: ${p.current} → ${p.latest}`).join('\n')}\n\n` +
|
|
1053
|
-
`运行 --update-now 进行更新`;
|
|
1054
|
-
} else {
|
|
1055
|
-
response = `✅ 已是最新版本 (${info?.version || 'unknown'})`;
|
|
1056
|
-
}
|
|
1057
|
-
break;
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
case 'update-now': {
|
|
1061
|
-
const { performUpdate } = await import('./utils/auto-update.js');
|
|
1062
|
-
const packages = args.length > 0 ? args : undefined;
|
|
1063
|
-
const result = await performUpdate(packages as string[] | undefined);
|
|
1064
|
-
if (result.success) {
|
|
1065
|
-
response = `✅ 更新成功${result.updatedPackages ? `: ${result.updatedPackages.join(', ')}` : ''}`;
|
|
1066
|
-
if (result.updated) {
|
|
1067
|
-
response += `\n\n${YELLOW}请重新启动应用以使用新版本${RESET}`;
|
|
1068
|
-
}
|
|
1069
|
-
} else {
|
|
1070
|
-
response = `❌ 更新失败: ${result.error}`;
|
|
1071
|
-
error = response;
|
|
1072
|
-
}
|
|
1073
|
-
break;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
default:
|
|
1077
|
-
response = `错误: 未知工具 "${tool}"`;
|
|
1078
|
-
error = response;
|
|
1079
|
-
}
|
|
1080
|
-
} catch (e: any) {
|
|
1081
|
-
response = `错误: ${e.message}`;
|
|
1082
|
-
error = response;
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
metadata.duration = Date.now() - startTime;
|
|
1086
|
-
|
|
1087
|
-
s.clearThinking(thinking);
|
|
1088
|
-
|
|
1089
|
-
if (outputJson) {
|
|
1090
|
-
const result: NonInteractiveResult = {
|
|
1091
|
-
success: !error,
|
|
1092
|
-
response,
|
|
1093
|
-
error,
|
|
1094
|
-
metadata
|
|
1095
|
-
};
|
|
1096
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1097
|
-
} else {
|
|
1098
|
-
if (error) {
|
|
1099
|
-
s.divider();
|
|
1100
|
-
console.log(`${MAGENTA}${error}${RESET}\n`);
|
|
1101
|
-
} else {
|
|
1102
|
-
s.divider();
|
|
1103
|
-
console.log(`${response}\n`);
|
|
1104
|
-
}
|
|
1105
|
-
console.log(`${GRAY}耗时: ${metadata.duration}ms${RESET}`);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
async function runNonInteractive(
|
|
1110
|
-
args: ParsedArgs,
|
|
1111
|
-
comm: HyperswarmCommunicator
|
|
1112
|
-
): Promise<void> {
|
|
1113
|
-
const { prompt, json, output, tool, toolArgs } = args;
|
|
1114
|
-
|
|
1115
|
-
if (output) {
|
|
1116
|
-
const originalLog = console.log;
|
|
1117
|
-
let outputBuffer = '';
|
|
1118
|
-
console.log = (...params: any[]) => {
|
|
1119
|
-
outputBuffer += params.join(' ') + '\n';
|
|
1120
|
-
};
|
|
1121
|
-
|
|
1122
|
-
if (tool) {
|
|
1123
|
-
await runToolCommand(tool, toolArgs, false, comm);
|
|
1124
|
-
} else if (prompt) {
|
|
1125
|
-
const a = await getAgent();
|
|
1126
|
-
console.log(await a.prompt(prompt));
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
console.log = originalLog;
|
|
1130
|
-
await fs.writeFile(output, outputBuffer.trim(), 'utf-8');
|
|
1131
|
-
console.log(`✅ 结果已保存到: ${output}`);
|
|
1132
|
-
return;
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
if (tool === 'prompt' && prompt) {
|
|
1136
|
-
// 2026-06-15: --prompt "text" 走直接调 a.prompt(prompt) 路径, 避开 runToolCommand
|
|
1137
|
-
// (case 'prompt' 内的 [text] = args 从 toolArgs 取值是空数组, 永远报"缺少 prompt 文本"是 CLI bug)
|
|
1138
|
-
const startTime = Date.now();
|
|
1139
|
-
const a = await getAgent();
|
|
1140
|
-
try {
|
|
1141
|
-
const response = await a.prompt(prompt);
|
|
1142
|
-
const elapsed = Date.now() - startTime;
|
|
1143
|
-
if (json) {
|
|
1144
|
-
console.log(JSON.stringify({ success: true, response, elapsedMs: elapsed }, null, 2));
|
|
1145
|
-
} else {
|
|
1146
|
-
console.log(response);
|
|
1147
|
-
console.log(`\n耗时: ${elapsed}ms`);
|
|
1148
|
-
}
|
|
1149
|
-
} catch (e: any) {
|
|
1150
|
-
const error = e?.message || String(e);
|
|
1151
|
-
if (json) {
|
|
1152
|
-
console.log(JSON.stringify({ success: false, error }, null, 2));
|
|
1153
|
-
} else {
|
|
1154
|
-
console.log(`\n错误: ${error}`);
|
|
1155
|
-
}
|
|
1156
|
-
process.exit(1);
|
|
1157
|
-
}
|
|
1158
|
-
return;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
if (tool) {
|
|
1162
|
-
await runToolCommand(tool, toolArgs, !!json, comm);
|
|
1163
|
-
} else if (prompt) {
|
|
1164
|
-
const startTime = Date.now();
|
|
1165
|
-
const a = await getAgent();
|
|
1166
|
-
let response: string;
|
|
1167
|
-
try {
|
|
1168
|
-
response = await a.prompt(prompt);
|
|
1169
|
-
} catch (e: any) {
|
|
1170
|
-
response = `错误: ${e.message}`;
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
const duration = Date.now() - startTime;
|
|
1174
|
-
const peers = comm?.getConnections().length || 0;
|
|
1175
|
-
|
|
1176
|
-
if (json) {
|
|
1177
|
-
const result: NonInteractiveResult = {
|
|
1178
|
-
success: !response.startsWith('错误:'),
|
|
1179
|
-
response,
|
|
1180
|
-
error: response.startsWith('错误:') ? response : undefined,
|
|
1181
|
-
metadata: { duration, peers }
|
|
1182
|
-
};
|
|
1183
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1184
|
-
} else {
|
|
1185
|
-
console.log(response);
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
|
|
1190
|
-
interface ParsedArgs {
|
|
1191
|
-
prompt?: string;
|
|
1192
|
-
json?: boolean;
|
|
1193
|
-
web?: boolean;
|
|
1194
|
-
help?: boolean;
|
|
1195
|
-
tools?: boolean;
|
|
1196
|
-
read?: boolean;
|
|
1197
|
-
summarize?: boolean;
|
|
1198
|
-
improve?: boolean;
|
|
1199
|
-
peers?: boolean;
|
|
1200
|
-
iroh?: boolean;
|
|
1201
|
-
identity?: boolean;
|
|
1202
|
-
logs?: boolean;
|
|
1203
|
-
broadcast?: boolean;
|
|
1204
|
-
send?: boolean;
|
|
1205
|
-
search?: boolean;
|
|
1206
|
-
model?: string;
|
|
1207
|
-
output?: string;
|
|
1208
|
-
tool?: string;
|
|
1209
|
-
toolArgs: string[];
|
|
1210
|
-
agents?: boolean;
|
|
1211
|
-
registerAgent?: boolean;
|
|
1212
|
-
delegate?: boolean;
|
|
1213
|
-
context?: boolean;
|
|
1214
|
-
globalAgents?: boolean;
|
|
1215
|
-
addAction?: boolean;
|
|
1216
|
-
tui?: boolean;
|
|
1217
|
-
updateCheck?: boolean;
|
|
1218
|
-
updateNow?: boolean;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
function parseArgs(): ParsedArgs {
|
|
1222
|
-
const args = process.argv.slice(2);
|
|
1223
|
-
const result: ParsedArgs = { toolArgs: [] };
|
|
1224
|
-
|
|
1225
|
-
for (let i = 0; i < args.length; i++) {
|
|
1226
|
-
const arg = args[i];
|
|
1227
|
-
|
|
1228
|
-
switch (arg) {
|
|
1229
|
-
case '--prompt':
|
|
1230
|
-
case '-p':
|
|
1231
|
-
result.prompt = args[++i];
|
|
1232
|
-
result.tool = 'prompt';
|
|
1233
|
-
break;
|
|
1234
|
-
case '--json':
|
|
1235
|
-
case '-j':
|
|
1236
|
-
result.json = true;
|
|
1237
|
-
break;
|
|
1238
|
-
case '--web':
|
|
1239
|
-
result.web = true;
|
|
1240
|
-
break;
|
|
1241
|
-
case '--help':
|
|
1242
|
-
case '-h':
|
|
1243
|
-
result.help = true;
|
|
1244
|
-
break;
|
|
1245
|
-
case '--tools':
|
|
1246
|
-
result.tools = true;
|
|
1247
|
-
result.tool = 'tools';
|
|
1248
|
-
break;
|
|
1249
|
-
case '--read':
|
|
1250
|
-
result.read = true;
|
|
1251
|
-
result.tool = 'read';
|
|
1252
|
-
result.toolArgs = [args[++i]].filter(Boolean);
|
|
1253
|
-
break;
|
|
1254
|
-
case '--summarize':
|
|
1255
|
-
result.summarize = true;
|
|
1256
|
-
result.tool = 'summarize';
|
|
1257
|
-
const summarizeArgs: string[] = [];
|
|
1258
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1259
|
-
summarizeArgs.push(args[++i]);
|
|
1260
|
-
}
|
|
1261
|
-
result.toolArgs = summarizeArgs;
|
|
1262
|
-
break;
|
|
1263
|
-
case '--improve':
|
|
1264
|
-
result.improve = true;
|
|
1265
|
-
result.tool = 'improve';
|
|
1266
|
-
const improveArgs: string[] = [];
|
|
1267
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1268
|
-
improveArgs.push(args[++i]);
|
|
1269
|
-
}
|
|
1270
|
-
result.toolArgs = improveArgs;
|
|
1271
|
-
break;
|
|
1272
|
-
case '--peers':
|
|
1273
|
-
result.peers = true;
|
|
1274
|
-
result.tool = 'peers';
|
|
1275
|
-
break;
|
|
1276
|
-
case '--iroh':
|
|
1277
|
-
result.iroh = true;
|
|
1278
|
-
result.tool = 'iroh';
|
|
1279
|
-
break;
|
|
1280
|
-
case '--identity':
|
|
1281
|
-
result.identity = true;
|
|
1282
|
-
result.tool = 'identity';
|
|
1283
|
-
break;
|
|
1284
|
-
case '--logs':
|
|
1285
|
-
result.logs = true;
|
|
1286
|
-
result.tool = 'logs';
|
|
1287
|
-
break;
|
|
1288
|
-
case '--broadcast':
|
|
1289
|
-
result.broadcast = true;
|
|
1290
|
-
result.tool = 'broadcast';
|
|
1291
|
-
result.toolArgs = [args[++i]].filter(Boolean);
|
|
1292
|
-
break;
|
|
1293
|
-
case '--send':
|
|
1294
|
-
result.send = true;
|
|
1295
|
-
result.tool = 'send';
|
|
1296
|
-
const sendArgs: string[] = [];
|
|
1297
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1298
|
-
sendArgs.push(args[++i]);
|
|
1299
|
-
}
|
|
1300
|
-
result.toolArgs = sendArgs;
|
|
1301
|
-
break;
|
|
1302
|
-
case '--search':
|
|
1303
|
-
result.search = true;
|
|
1304
|
-
result.tool = 'search';
|
|
1305
|
-
result.toolArgs = [args[++i]].filter(Boolean);
|
|
1306
|
-
break;
|
|
1307
|
-
case '--agents':
|
|
1308
|
-
result.agents = true;
|
|
1309
|
-
result.tool = 'agents';
|
|
1310
|
-
break;
|
|
1311
|
-
case '--register-agent':
|
|
1312
|
-
result.registerAgent = true;
|
|
1313
|
-
result.tool = 'register-agent';
|
|
1314
|
-
const regArgs: string[] = [];
|
|
1315
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1316
|
-
regArgs.push(args[++i]);
|
|
1317
|
-
}
|
|
1318
|
-
result.toolArgs = regArgs;
|
|
1319
|
-
break;
|
|
1320
|
-
case '--delegate':
|
|
1321
|
-
result.delegate = true;
|
|
1322
|
-
result.tool = 'delegate';
|
|
1323
|
-
const delArgs: string[] = [];
|
|
1324
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1325
|
-
delArgs.push(args[++i]);
|
|
1326
|
-
}
|
|
1327
|
-
result.toolArgs = delArgs;
|
|
1328
|
-
break;
|
|
1329
|
-
case '--context':
|
|
1330
|
-
result.context = true;
|
|
1331
|
-
result.tool = 'context';
|
|
1332
|
-
break;
|
|
1333
|
-
case '--global-agents':
|
|
1334
|
-
result.globalAgents = true;
|
|
1335
|
-
result.tool = 'global-agents';
|
|
1336
|
-
break;
|
|
1337
|
-
case '--add-action':
|
|
1338
|
-
result.addAction = true;
|
|
1339
|
-
result.tool = 'add-action';
|
|
1340
|
-
const actionArgs: string[] = [];
|
|
1341
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1342
|
-
actionArgs.push(args[++i]);
|
|
1343
|
-
}
|
|
1344
|
-
result.toolArgs = actionArgs;
|
|
1345
|
-
break;
|
|
1346
|
-
case '--harness-init':
|
|
1347
|
-
result.tool = 'harness-init';
|
|
1348
|
-
break;
|
|
1349
|
-
case '--harness-gate':
|
|
1350
|
-
result.tool = 'harness-gate';
|
|
1351
|
-
break;
|
|
1352
|
-
case '--harness-transition':
|
|
1353
|
-
result.tool = 'harness-transition';
|
|
1354
|
-
const transitionArgs: string[] = [];
|
|
1355
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1356
|
-
transitionArgs.push(args[++i]);
|
|
1357
|
-
}
|
|
1358
|
-
result.toolArgs = transitionArgs;
|
|
1359
|
-
break;
|
|
1360
|
-
case '--harness-skill':
|
|
1361
|
-
result.tool = 'harness-skill';
|
|
1362
|
-
const skillArgs: string[] = [];
|
|
1363
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1364
|
-
skillArgs.push(args[++i]);
|
|
1365
|
-
}
|
|
1366
|
-
result.toolArgs = skillArgs;
|
|
1367
|
-
break;
|
|
1368
|
-
case '--harness-classify':
|
|
1369
|
-
result.tool = 'harness-classify';
|
|
1370
|
-
const classifyArgs: string[] = [];
|
|
1371
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1372
|
-
classifyArgs.push(args[++i]);
|
|
1373
|
-
}
|
|
1374
|
-
result.toolArgs = classifyArgs;
|
|
1375
|
-
break;
|
|
1376
|
-
case '--harness-context':
|
|
1377
|
-
result.tool = 'harness-context';
|
|
1378
|
-
const contextArgs: string[] = [];
|
|
1379
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1380
|
-
contextArgs.push(args[++i]);
|
|
1381
|
-
}
|
|
1382
|
-
result.toolArgs = contextArgs;
|
|
1383
|
-
break;
|
|
1384
|
-
case '--harness-check':
|
|
1385
|
-
result.tool = 'harness-check';
|
|
1386
|
-
const checkArgs: string[] = [];
|
|
1387
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1388
|
-
checkArgs.push(args[++i]);
|
|
1389
|
-
}
|
|
1390
|
-
result.toolArgs = checkArgs;
|
|
1391
|
-
break;
|
|
1392
|
-
case '--harness-archive':
|
|
1393
|
-
result.tool = 'harness-archive';
|
|
1394
|
-
break;
|
|
1395
|
-
case '--harness-sessions':
|
|
1396
|
-
result.tool = 'harness-sessions';
|
|
1397
|
-
break;
|
|
1398
|
-
case '--harness-session-context':
|
|
1399
|
-
result.tool = 'harness-session-context';
|
|
1400
|
-
const sessionArgs: string[] = [];
|
|
1401
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1402
|
-
sessionArgs.push(args[++i]);
|
|
1403
|
-
}
|
|
1404
|
-
result.toolArgs = sessionArgs;
|
|
1405
|
-
break;
|
|
1406
|
-
case '--update-check':
|
|
1407
|
-
result.updateCheck = true;
|
|
1408
|
-
result.tool = 'update-check';
|
|
1409
|
-
break;
|
|
1410
|
-
case '--update-now':
|
|
1411
|
-
result.updateNow = true;
|
|
1412
|
-
result.tool = 'update-now';
|
|
1413
|
-
const updateArgs: string[] = [];
|
|
1414
|
-
while (i + 1 < args.length && !args[i + 1].startsWith('-')) {
|
|
1415
|
-
updateArgs.push(args[++i]);
|
|
1416
|
-
}
|
|
1417
|
-
result.toolArgs = updateArgs;
|
|
1418
|
-
break;
|
|
1419
|
-
case '--tui':
|
|
1420
|
-
result.tui = true;
|
|
1421
|
-
break;
|
|
1422
|
-
case '--model':
|
|
1423
|
-
result.model = args[++i];
|
|
1424
|
-
break;
|
|
1425
|
-
case '--output':
|
|
1426
|
-
case '-o':
|
|
1427
|
-
result.output = args[++i];
|
|
1428
|
-
break;
|
|
1429
|
-
case '--':
|
|
1430
|
-
result.toolArgs = args.slice(i + 1);
|
|
1431
|
-
i = args.length;
|
|
1432
|
-
break;
|
|
1433
|
-
default:
|
|
1434
|
-
if (!arg.startsWith('-') && !result.prompt && !result.tool) {
|
|
1435
|
-
result.prompt = arg;
|
|
1436
|
-
result.tool = 'prompt';
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
return result;
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
function printHelp(): void {
|
|
1445
|
-
console.log(`
|
|
1446
|
-
🤖 Bolloon Agent - AI 可调用文档处理智能体
|
|
1447
|
-
|
|
1448
|
-
用法:
|
|
1449
|
-
npx tsx src/index.ts [选项] [参数]
|
|
1450
|
-
|
|
1451
|
-
选项:
|
|
1452
|
-
# 文档处理
|
|
1453
|
-
--read <file> 读取文档 (txt, md, pdf, docx)
|
|
1454
|
-
--summarize <file> [ctx] 总结文档,可选上下文
|
|
1455
|
-
--improve <file> <req> 改进文档,req 为改进要求
|
|
1456
|
-
|
|
1457
|
-
# P2P 网络
|
|
1458
|
-
--peers 列出已连接的对等节点
|
|
1459
|
-
--broadcast <msg> 广播消息到所有节点
|
|
1460
|
-
--send <peerId> <msg> 向指定节点发送消息
|
|
1461
|
-
|
|
1462
|
-
# 智能体
|
|
1463
|
-
--identity 显示当前智能体身份
|
|
1464
|
-
--logs 显示操作日志
|
|
1465
|
-
--search <keyword> 搜索文件
|
|
1466
|
-
--tools 显示所有可用工具
|
|
1467
|
-
|
|
1468
|
-
# SubAgent 管理
|
|
1469
|
-
--agents 列出所有 SubAgent
|
|
1470
|
-
--register-agent <name> [cap1] [cap2]... 注册新 SubAgent
|
|
1471
|
-
--delegate <任务描述> [能力要求...] 委派任务给最佳 Agent
|
|
1472
|
-
|
|
1473
|
-
# 全局共享上下文
|
|
1474
|
-
--context 显示全局共享上下文摘要
|
|
1475
|
-
--global-agents 显示全局 Agent 注册表
|
|
1476
|
-
--add-action <内容> [重要性] 添加用户行动到共享上下文
|
|
1477
|
-
|
|
1478
|
-
# Bollharness 治理框架
|
|
1479
|
-
--harness-init 初始化 Bollharness 治理框架
|
|
1480
|
-
--harness-gate 显示当前 Gate 状态
|
|
1481
|
-
--harness-transition [PASS|BLOCK] 执行 Gate 转移
|
|
1482
|
-
--harness-skill <name> [action] 执行 Harness Skill
|
|
1483
|
-
--harness-classify <描述> 分类变更类型
|
|
1484
|
-
--harness-context <file> 获取文件上下文
|
|
1485
|
-
--harness-check <file> 执行 Guard 检查
|
|
1486
|
-
--harness-archive 归档当前 Session 到 Harness
|
|
1487
|
-
--harness-sessions 列出 Session 归档记录
|
|
1488
|
-
--harness-session-context [id] 获取 Session 上下文
|
|
1489
|
-
|
|
1490
|
-
# 自动更新
|
|
1491
|
-
--update-check 检查 npm 包更新
|
|
1492
|
-
--update-now [pkg] 更新到最新版本
|
|
1493
|
-
|
|
1494
|
-
# AI 对话
|
|
1495
|
-
--prompt, -p <text> 通用 AI 对话(默认)
|
|
1496
|
-
--model <name> 指定使用的模型
|
|
1497
|
-
|
|
1498
|
-
# 输出控制
|
|
1499
|
-
--json, -j 输出 JSON 格式
|
|
1500
|
-
--output, -o <file> 结果保存到文件
|
|
1501
|
-
--web 启动 Web UI 模式
|
|
1502
|
-
--help, -h 显示帮助信息
|
|
1503
|
-
|
|
1504
|
-
示例:
|
|
1505
|
-
# 文档处理
|
|
1506
|
-
npx tsx src/index.ts --read 想法.md
|
|
1507
|
-
npx tsx src/index.ts --summarize docs/想法.md
|
|
1508
|
-
npx tsx src/index.ts --improve docs/README.md "让内容更简洁"
|
|
1509
|
-
npx tsx src/index.ts --read 想法.md -o summary.txt
|
|
1510
|
-
|
|
1511
|
-
# P2P 网络
|
|
1512
|
-
npx tsx src/index.ts --peers
|
|
1513
|
-
npx tsx src/index.ts --broadcast "Hello everyone"
|
|
1514
|
-
npx tsx src/index.ts --send QmABC... "私信内容"
|
|
1515
|
-
|
|
1516
|
-
# AI 对话
|
|
1517
|
-
npx tsx src/index.ts --prompt "总结 README.md"
|
|
1518
|
-
npx tsx src/index.ts -p "分析这个项目" -j
|
|
1519
|
-
|
|
1520
|
-
# 交互模式
|
|
1521
|
-
npx tsx src/index.ts
|
|
1522
|
-
|
|
1523
|
-
# Web 模式
|
|
1524
|
-
npx tsx src/index.ts --web
|
|
1525
|
-
|
|
1526
|
-
环境变量:
|
|
1527
|
-
MINIMAX_API_KEY MiniMax API 密钥
|
|
1528
|
-
DEEPSEEK_API_KEY DeepSeek API 密钥
|
|
1529
|
-
KIMI_API_KEY / MOONSHOT_API_KEY Kimi/Moonshot API 密钥
|
|
1530
|
-
GLM_API_KEY / ZHIPU_API_KEY 智谱 GLM API 密钥
|
|
1531
|
-
QWEN_API_KEY / DASHSCOPE_API_KEY 通义千问 API 密钥
|
|
1532
|
-
OPENAI_API_KEY OpenAI API 密钥(Pi SDK)
|
|
1533
|
-
ANTHROPIC_API_KEY Anthropic API 密钥(Pi SDK)
|
|
1534
|
-
PORT Web 服务端口(默认 54188)
|
|
1535
|
-
`);
|
|
1536
|
-
}
|
|
1537
|
-
|
|
1538
|
-
// ---------------------------------------------------------------------------
|
|
1539
|
-
// Entry point
|
|
1540
|
-
// ---------------------------------------------------------------------------
|
|
1541
|
-
|
|
1542
|
-
async function main() {
|
|
1543
|
-
const args = parseArgs();
|
|
1544
|
-
|
|
1545
|
-
if (args.help) {
|
|
1546
|
-
printHelp();
|
|
1547
|
-
process.exit(0);
|
|
1548
|
-
}
|
|
1549
|
-
|
|
1550
|
-
// 自动更新已禁用: 启动时不再自动检查/安装更新.
|
|
1551
|
-
// 想手动检查: bolloon --update-check
|
|
1552
|
-
// 想手动更新: bolloon --update-now [package]
|
|
1553
|
-
// 想完全屏蔽 (CI / sandbox): BOLLOON_SKIP_UPDATE=true
|
|
1554
|
-
|
|
1555
|
-
const mode = args.web ? 'web' : 'cli';
|
|
1556
|
-
const isNonInteractive = !!(args.tool || args.prompt);
|
|
1557
|
-
const isTuiMode = mode === 'cli' && !isNonInteractive && args.tui;
|
|
1558
|
-
|
|
1559
|
-
const originalLog = console.log;
|
|
1560
|
-
const originalInfo = console.info;
|
|
1561
|
-
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
1562
|
-
|
|
1563
|
-
const isSdkLog = (msg: string): boolean => {
|
|
1564
|
-
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(msg);
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
|
-
if (isTuiMode) {
|
|
1568
|
-
console.log = (...args: any[]) => {
|
|
1569
|
-
const msg = args.join(' ');
|
|
1570
|
-
if (isSdkLog(msg)) return;
|
|
1571
|
-
originalLog.apply(console, args);
|
|
1572
|
-
};
|
|
1573
|
-
console.info = (...args: any[]) => {
|
|
1574
|
-
const msg = args.join(' ');
|
|
1575
|
-
if (isSdkLog(msg)) return;
|
|
1576
|
-
originalInfo.apply(console, args);
|
|
1577
|
-
};
|
|
1578
|
-
process.stdout.write = (chunk: any, ...args: any[]) => {
|
|
1579
|
-
const msg = String(chunk);
|
|
1580
|
-
if (isSdkLog(msg)) return true;
|
|
1581
|
-
return originalStdoutWrite(chunk, ...args);
|
|
1582
|
-
};
|
|
1583
|
-
}
|
|
1584
|
-
|
|
1585
|
-
if (isNonInteractive) {
|
|
1586
|
-
console.error = () => {};
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
s.banner();
|
|
1590
|
-
|
|
1591
|
-
s.section('系统初始化');
|
|
1592
|
-
|
|
1593
|
-
const hasOpenAI = !!process.env.OPENAI_API_KEY;
|
|
1594
|
-
// 2026-06-15: 修复 — 之前 anthropic 401 是因为 shell env 残留的旧 ANTHROPIC_API_KEY 抢了 provider 选择
|
|
1595
|
-
// 用 BOLLOON_LLM_PROVIDER env 显式覆盖, 否则还是按 env hasXxx 顺序自动选
|
|
1596
|
-
const hasAnthropic = !!process.env.ANTHROPIC_API_KEY && !process.env.BOLLOON_LLM_PROVIDER;
|
|
1597
|
-
const hasMinimax = !!process.env.MINIMAX_API_KEY;
|
|
1598
|
-
const hasDeepSeek = !!process.env.DEEPSEEK_API_KEY;
|
|
1599
|
-
const hasKimi = !!(process.env.KIMI_API_KEY || process.env.MOONSHOT_API_KEY);
|
|
1600
|
-
const hasGlm = !!(process.env.GLM_API_KEY || process.env.ZHIPU_API_KEY);
|
|
1601
|
-
const hasQwen = !!(process.env.QWEN_API_KEY || process.env.DASHSCOPE_API_KEY);
|
|
1602
|
-
const hasOpenRouter = !!process.env.OPENROUTER_API_KEY;
|
|
1603
|
-
const hasGemini = !!process.env.GEMINI_API_KEY;
|
|
1604
|
-
const hasOllama = !!process.env.OLLAMA_BASE_URL;
|
|
1605
|
-
|
|
1606
|
-
const llmProvider = hasOpenAI ? 'OpenAI' :
|
|
1607
|
-
hasAnthropic ? 'Anthropic' :
|
|
1608
|
-
hasOpenRouter ? 'OpenRouter' :
|
|
1609
|
-
hasGemini ? 'Gemini' :
|
|
1610
|
-
hasOllama ? 'Ollama' :
|
|
1611
|
-
hasMinimax ? 'MiniMax' :
|
|
1612
|
-
hasDeepSeek ? 'DeepSeek' :
|
|
1613
|
-
hasKimi ? 'Kimi' :
|
|
1614
|
-
hasGlm ? 'GLM' :
|
|
1615
|
-
hasQwen ? 'Qwen' : null;
|
|
1616
|
-
|
|
1617
|
-
if (llmProvider) {
|
|
1618
|
-
s.step(0, 4, `LLM: ${llmProvider}`, 'ok');
|
|
1619
|
-
initMinimax({ provider: llmProvider.toLowerCase() as any });
|
|
1620
|
-
} else {
|
|
1621
|
-
s.step(0, 4, 'LLM: 未配置', 'warn');
|
|
1622
|
-
if (isNonInteractive) {
|
|
1623
|
-
s.warn('未设置任何 LLM API Key,功能受限');
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
|
|
1627
|
-
const { keypair, did, name } = await bootstrapIdentity();
|
|
1628
|
-
agentIdentity = { did, name, publicKey: Buffer.from(keypair.publicKey).toString('hex') };
|
|
1629
|
-
|
|
1630
|
-
publishDID(name, keypair).then(({ cid, ipnsName }) => {
|
|
1631
|
-
if (cid) agentIdentity!.cid = cid;
|
|
1632
|
-
if (ipnsName) agentIdentity!.ipnsName = ipnsName;
|
|
1633
|
-
}).catch(() => {});
|
|
1634
|
-
|
|
1635
|
-
const verifier = createVerificationManager();
|
|
1636
|
-
let comm: HyperswarmCommunicator | null = null;
|
|
1637
|
-
|
|
1638
|
-
try {
|
|
1639
|
-
if (mode === 'web') {
|
|
1640
|
-
bootstrapP2P(verifier).then(c => {
|
|
1641
|
-
comm = c;
|
|
1642
|
-
const connections = c.getConnections();
|
|
1643
|
-
if (connections.length > 0) {
|
|
1644
|
-
agentIdentity!.peerId = connections[0].publicKey;
|
|
1645
|
-
agentIdentity!.p2pChannel = 'bolloon-agent-harness';
|
|
1646
|
-
}
|
|
1647
|
-
}).catch(err => {
|
|
1648
|
-
s.warn(`P2P Web 模式启动失败: ${err.message}`);
|
|
1649
|
-
});
|
|
1650
|
-
} else {
|
|
1651
|
-
comm = await bootstrapP2P(verifier);
|
|
1652
|
-
const connections = comm.getConnections();
|
|
1653
|
-
if (connections.length > 0) {
|
|
1654
|
-
agentIdentity.peerId = connections[0].publicKey;
|
|
1655
|
-
agentIdentity.p2pChannel = 'bolloon-agent-harness';
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
} catch (err: any) {
|
|
1659
|
-
s.warn(`P2P 初始化失败: ${err.message}`);
|
|
1660
|
-
s.warn('将使用无 P2P 模式运行');
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
await bootstrapIroh(keypair, name);
|
|
1664
|
-
|
|
1665
|
-
// Bolloon Bootstrap: 启动扫描 + Context 收集 + 挂定时任务
|
|
1666
|
-
// 失败静默 (主流程不被阻塞)
|
|
1667
|
-
try {
|
|
1668
|
-
const { bootstrapBolloon } = await import('./pi-ecosystem-judgment/human-value-pipeline.js');
|
|
1669
|
-
s.info('正在 bootstrap bolloon 上下文...');
|
|
1670
|
-
const bs = await bootstrapBolloon({ cwd: process.cwd() });
|
|
1671
|
-
s.info(`Bootstrap 完成 (${bs.durationMs}ms, ${bs.errors.length} 个非致命错误)`);
|
|
1672
|
-
} catch (err: any) {
|
|
1673
|
-
s.warn(`Bootstrap 失败 (非致命, 主流程继续): ${err.message}`);
|
|
1674
|
-
}
|
|
1675
|
-
|
|
1676
|
-
s.divider();
|
|
1677
|
-
|
|
1678
|
-
if (mode === 'web') {
|
|
1679
|
-
const port = parseInt(process.env.PORT || '54188');
|
|
1680
|
-
// 2026-06-16: BOLLOON_DEV_MODE=1 或 selfImprove=true 启动项 → 开发者模式, 启用自迭代 (健康监控+自改总线)
|
|
1681
|
-
// 默认用户模式: 不自迭代, 自改卡片不自动出现, 仍可 POST /api/self-improve/trigger 手动触发
|
|
1682
|
-
const selfImprove = process.env.BOLLOON_DEV_MODE === '1' || process.env.BOLLOON_DEV_MODE === 'true';
|
|
1683
|
-
if (selfImprove) {
|
|
1684
|
-
console.log('[startup] BOLLOON_DEV_MODE=1, 开发者模式: 自迭代已启用');
|
|
1685
|
-
}
|
|
1686
|
-
const { createWebServer, openBrowser } = await import('./web/server.js');
|
|
1687
|
-
|
|
1688
|
-
s.info(`启动 Web 服务端口 ${port}...`);
|
|
1689
|
-
const { port: actualPort } = await createWebServer(port, { selfImprove });
|
|
1690
|
-
|
|
1691
|
-
s.success(`浏览器已打开 → http://localhost:${actualPort}`);
|
|
1692
|
-
openBrowser(`http://localhost:${actualPort}`);
|
|
1693
|
-
} else if (isNonInteractive) {
|
|
1694
|
-
console.log = originalLog;
|
|
1695
|
-
console.info = originalInfo;
|
|
1696
|
-
process.stdout.write = originalStdoutWrite;
|
|
1697
|
-
s.info('执行命令...');
|
|
1698
|
-
console.log();
|
|
1699
|
-
await runNonInteractive(args, comm!);
|
|
1700
|
-
comm?.stop();
|
|
1701
|
-
process.exit(0);
|
|
1702
|
-
} else {
|
|
1703
|
-
s.section('对话模式');
|
|
1704
|
-
console.log(`${GRAY}输入命令即可开始对话,示例:${RESET}\n`);
|
|
1705
|
-
console.log(` ${CYAN}读取 想法.md${RESET} ${GRAY}- 读取文档${RESET}`);
|
|
1706
|
-
console.log(` ${CYAN}总结 文档.md${RESET} ${GRAY}- 总结文档${RESET}`);
|
|
1707
|
-
console.log(` ${CYAN}--agents${RESET} ${GRAY}- 查看 SubAgent${RESET}`);
|
|
1708
|
-
console.log(` ${CYAN}--context${RESET} ${GRAY}- 查看全局上下文${RESET}`);
|
|
1709
|
-
console.log(` ${CYAN}--delegate 任务 coding${RESET} ${GRAY}- 委派任务${RESET}`);
|
|
1710
|
-
console.log(` ${CYAN}peers${RESET} ${GRAY}- 查看 P2P 节点${RESET}`);
|
|
1711
|
-
console.log(` ${CYAN}iroh${RESET} ${GRAY}- 查看 iroh 状态${RESET}`);
|
|
1712
|
-
console.log(` ${CYAN}退出${RESET} ${GRAY}- 结束对话${RESET}\n`);
|
|
1713
|
-
|
|
1714
|
-
if (!isTuiMode) {
|
|
1715
|
-
console.log = originalLog;
|
|
1716
|
-
console.info = originalInfo;
|
|
1717
|
-
process.stdout.write = originalStdoutWrite;
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
startCLI(comm!);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
|
|
1724
|
-
main().catch(e => { console.error('Fatal:', e); process.exit(1); });
|