@bolloon/bolloon-agent 0.1.35 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/agents/p2p-chat-tools.js +6 -6
- package/dist/agents/permission-mode.js +115 -0
- package/dist/agents/pi-sdk.js +435 -25
- package/dist/agents/pre-tool-validator.js +194 -0
- package/dist/agents/workflow-pivot-loop.js +113 -12
- package/dist/bollharness-integration/context-router.js +2 -2
- package/dist/bollharness-integration/guard-checker.js +1 -1
- package/dist/bootstrap/bootstrap.js +3 -0
- package/dist/bootstrap/context-collector.js +17 -1
- package/dist/bootstrap/context-hierarchy.js +218 -0
- package/dist/bootstrap/lifecycle-hooks.js +86 -24
- package/dist/bootstrap/project-context.js +10 -3
- package/dist/context-compaction/auto-compact.js +144 -0
- package/dist/context-compaction/budget-gate.js +28 -0
- package/dist/context-compaction/budget-reduce.js +35 -0
- package/dist/context-compaction/context-collapse.js +66 -0
- package/dist/context-compaction/index.js +21 -0
- package/dist/context-compaction/microcompact.js +51 -0
- package/dist/context-compaction/pipeline.js +123 -0
- package/dist/context-compaction/snip.js +45 -0
- package/dist/context-compaction/token-estimator.js +35 -0
- package/dist/context-compaction/types.js +19 -0
- package/dist/heartbeat/HealthMonitor.js +3 -2
- package/dist/index.js +38 -2
- package/dist/llm/llm-judgment-client.js +32 -30
- package/dist/llm/pi-ai.js +103 -16
- package/dist/llm/system-prompt/health.js +129 -0
- package/dist/llm/system-prompt/registry.js +246 -0
- package/dist/llm/system-prompt/strip-hibsml.js +51 -0
- package/dist/llm/tool-manifest/ask_user_input.js +35 -0
- package/dist/llm/tool-manifest/bash.js +23 -0
- package/dist/llm/tool-manifest/create_file.js +24 -0
- package/dist/llm/tool-manifest/fetch_sports_data.js +26 -0
- package/dist/llm/tool-manifest/image_search.js +24 -0
- package/dist/llm/tool-manifest/index.js +69 -0
- package/dist/llm/tool-manifest/mcp.js +43 -0
- package/dist/llm/tool-manifest/message_compose.js +31 -0
- package/dist/llm/tool-manifest/places.js +83 -0
- package/dist/llm/tool-manifest/present_files.js +21 -0
- package/dist/llm/tool-manifest/recipe.js +40 -0
- package/dist/llm/tool-manifest/recommend_apps.js +23 -0
- package/dist/llm/tool-manifest/str_replace.js +27 -0
- package/dist/llm/tool-manifest/types.js +7 -0
- package/dist/llm/tool-manifest/view.js +24 -0
- package/dist/llm/tool-manifest/weather.js +27 -0
- package/dist/llm/tool-manifest/web.js +51 -0
- package/dist/network/p2p-direct.js +23 -0
- package/dist/network/source-intent-broadcaster.js +203 -0
- package/dist/network/source-intent.js +100 -0
- package/dist/pi-ecosystem-judgment/adaptive-scan.js +48 -0
- package/dist/pi-ecosystem-judgment/injection-gate.js +54 -12
- package/dist/pi-ecosystem-judgment/value-injection.js +8 -2
- package/dist/security/context-router-tool.js +1 -1
- package/dist/security/input-scanner.js +223 -0
- package/dist/web/client.js +3089 -4458
- package/dist/web/index.html +58 -67
- package/dist/web/server.js +299 -117
- package/dist/web/style.css +531 -249
- package/dist/web/ui/message-renderer.js +352 -0
- package/dist/web/ui/step-timeline.js +279 -0
- package/package.json +2 -2
- package/.auto-evolve-calls +0 -1
- package/.last-auto-evolve-baseline +0 -1
- package/Bolloon.md +0 -103
- 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 -29
- package/scripts/auto-evolve-loop.ts +0 -376
- package/scripts/auto-evolve-oneshot.sh +0 -155
- package/scripts/auto-evolve-snapshot.sh +0 -136
- package/scripts/build-cli.js +0 -216
- package/scripts/build-web.ts +0 -82
- package/scripts/detect-schema-changes.sh +0 -48
- package/scripts/diff-reviewer.ts +0 -159
- package/scripts/postinstall.js +0 -153
- 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/pi-sdk.ts +0 -2462
- 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 -675
- 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 -132
- package/src/bootstrap/context-collector.ts +0 -342
- package/src/bootstrap/lifecycle-hooks.ts +0 -176
- package/src/bootstrap/project-context.ts +0 -163
- package/src/cli/interface.ts +0 -211
- package/src/cli-entry.ts +0 -304
- package/src/constraints/index.ts +0 -6
- 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 -316
- 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 -1690
- 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 -470
- package/src/llm/pi-ai.ts +0 -558
- 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 -240
- package/src/network/p2p-secret.ts +0 -153
- package/src/network/p2p.ts +0 -964
- 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/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 -4898
- 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 -382
- package/src/web/iroh-delegate-transport.ts +0 -139
- package/src/web/manifest.json +0 -21
- package/src/web/server.ts +0 -5571
- package/src/web/style.css +0 -4455
- 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/tsconfig.cli.json +0 -16
- package/tsconfig.electron.json +0 -20
- package/tsconfig.json +0 -18
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DaemonManager - 守护进程管理器
|
|
3
|
-
* 支持自动重启、日志轮转、PID 管理
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import * as fs from 'fs/promises';
|
|
7
|
-
import * as path from 'path';
|
|
8
|
-
import type { DaemonConfig } from './types.js';
|
|
9
|
-
|
|
10
|
-
export interface DaemonState {
|
|
11
|
-
pid: number;
|
|
12
|
-
startedAt: number;
|
|
13
|
-
restartCount: number;
|
|
14
|
-
lastRestartAt?: number;
|
|
15
|
-
lastError?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class DaemonManager {
|
|
19
|
-
private config: Required<DaemonConfig>;
|
|
20
|
-
private state: DaemonState | null = null;
|
|
21
|
-
private stopRequested: boolean = false;
|
|
22
|
-
private isChildProcess: boolean = false;
|
|
23
|
-
|
|
24
|
-
constructor(config: Partial<DaemonConfig> = {}) {
|
|
25
|
-
this.config = {
|
|
26
|
-
maxRestarts: config.maxRestarts || 5,
|
|
27
|
-
restartDelayMs: config.restartDelayMs || 5000,
|
|
28
|
-
logFile: config.logFile || path.join(process.env.HOME || '/tmp', '.bolloon', 'daemon.log'),
|
|
29
|
-
pidFile: config.pidFile || path.join(process.env.HOME || '/tmp', '.bolloon', 'daemon.pid')
|
|
30
|
-
};
|
|
31
|
-
this.isChildProcess = process.env.BOLLOON_DAEMON_CHILD === '1';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 获取当前守护进程状态
|
|
36
|
-
*/
|
|
37
|
-
async getState(): Promise<DaemonState | null> {
|
|
38
|
-
try {
|
|
39
|
-
const pidData = await fs.readFile(this.config.pidFile, 'utf-8');
|
|
40
|
-
const pid = parseInt(pidData.trim(), 10);
|
|
41
|
-
|
|
42
|
-
if (isNaN(pid)) return null;
|
|
43
|
-
|
|
44
|
-
// 检查进程是否仍在运行
|
|
45
|
-
try {
|
|
46
|
-
process.kill(pid, 0); // Signal 0 只是检查进程是否存在
|
|
47
|
-
return { ...this.state!, pid };
|
|
48
|
-
} catch {
|
|
49
|
-
// 进程不存在
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
} catch {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* 检查是否已有守护进程在运行
|
|
59
|
-
*/
|
|
60
|
-
async isRunning(): Promise<boolean> {
|
|
61
|
-
const state = await this.getState();
|
|
62
|
-
return state !== null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 保存 PID 文件
|
|
67
|
-
*/
|
|
68
|
-
private async savePid(): Promise<void> {
|
|
69
|
-
await fs.mkdir(path.dirname(this.config.pidFile), { recursive: true });
|
|
70
|
-
await fs.writeFile(this.config.pidFile, String(process.pid));
|
|
71
|
-
console.log(`[Daemon] PID saved: ${process.pid}`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 删除 PID 文件
|
|
76
|
-
*/
|
|
77
|
-
async clearPid(): Promise<void> {
|
|
78
|
-
try {
|
|
79
|
-
await fs.unlink(this.config.pidFile);
|
|
80
|
-
} catch {
|
|
81
|
-
// 忽略删除失败
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 写入日志
|
|
87
|
-
*/
|
|
88
|
-
private async writeLog(message: string): Promise<void> {
|
|
89
|
-
if (!this.config.logFile) return;
|
|
90
|
-
|
|
91
|
-
try {
|
|
92
|
-
await fs.mkdir(path.dirname(this.config.logFile), { recursive: true });
|
|
93
|
-
const timestamp = new Date().toISOString();
|
|
94
|
-
await fs.appendFile(this.config.logFile, `[${timestamp}] ${message}\n`);
|
|
95
|
-
} catch {
|
|
96
|
-
// 忽略日志写入失败
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 启动主进程(父进程调用)
|
|
102
|
-
*/
|
|
103
|
-
async spawn(processArgv: string[] = process.argv): Promise<void> {
|
|
104
|
-
// 检查是否已在运行
|
|
105
|
-
if (await this.isRunning()) {
|
|
106
|
-
console.log('[Daemon] Already running, pid:', (await this.getState())?.pid);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
this.state = {
|
|
111
|
-
pid: process.pid,
|
|
112
|
-
startedAt: Date.now(),
|
|
113
|
-
restartCount: 0
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
await this.savePid();
|
|
117
|
-
await this.writeLog('Daemon started');
|
|
118
|
-
|
|
119
|
-
// 设置优雅退出
|
|
120
|
-
this.setupGracefulShutdown();
|
|
121
|
-
|
|
122
|
-
// 注册信号处理
|
|
123
|
-
this.setupSignalHandlers();
|
|
124
|
-
|
|
125
|
-
console.log('[Daemon] Manager initialized');
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 启动子进程并管理其生命周期
|
|
130
|
-
*/
|
|
131
|
-
async runWithAutoRestart(childArgs: string[]): Promise<void> {
|
|
132
|
-
if (!this.isChildProcess) {
|
|
133
|
-
// 父进程:启动子进程
|
|
134
|
-
await this.runChildProcess(childArgs);
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 子进程:正常运行主程序
|
|
139
|
-
console.log('[Daemon] Running as child process');
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 启动子进程
|
|
144
|
-
*/
|
|
145
|
-
private async runChildProcess(childArgs: string[]): Promise<void> {
|
|
146
|
-
const { spawn } = await import('child_process');
|
|
147
|
-
let consecutiveFailures = 0;
|
|
148
|
-
|
|
149
|
-
while (!this.stopRequested && consecutiveFailures < this.config.maxRestarts) {
|
|
150
|
-
console.log(`[Daemon] Spawning child process (attempt ${consecutiveFailures + 1}/${this.config.maxRestarts})`);
|
|
151
|
-
|
|
152
|
-
const child = spawn(process.execPath, childArgs, {
|
|
153
|
-
stdio: 'inherit',
|
|
154
|
-
env: { ...process.env, BOLLOON_DAEMON_CHILD: '1' }
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
child.on('exit', async (code, signal) => {
|
|
158
|
-
const reason = signal || `exit code ${code}`;
|
|
159
|
-
console.log(`[Daemon] Child exited: ${reason}`);
|
|
160
|
-
|
|
161
|
-
if (this.stopRequested) {
|
|
162
|
-
console.log('[Daemon] Stop requested, not restarting');
|
|
163
|
-
await this.clearPid();
|
|
164
|
-
process.exit(0);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
consecutiveFailures++;
|
|
168
|
-
this.state = {
|
|
169
|
-
...this.state!,
|
|
170
|
-
restartCount: consecutiveFailures,
|
|
171
|
-
lastRestartAt: Date.now(),
|
|
172
|
-
lastError: reason
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
if (consecutiveFailures < this.config.maxRestarts) {
|
|
176
|
-
console.log(`[Daemon] Restarting in ${this.config.restartDelayMs}ms...`);
|
|
177
|
-
await this.writeLog(`Child exited ${reason}, restarting (${consecutiveFailures}/${this.config.maxRestarts})`);
|
|
178
|
-
|
|
179
|
-
await new Promise(resolve => setTimeout(resolve, this.config.restartDelayMs));
|
|
180
|
-
// 继续 while 循环,重启子进程
|
|
181
|
-
} else {
|
|
182
|
-
console.error('[Daemon] Max restarts reached, giving up');
|
|
183
|
-
await this.writeLog(`Max restarts reached (${this.config.maxRestarts})`);
|
|
184
|
-
await this.clearPid();
|
|
185
|
-
process.exit(1);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
child.on('error', async (err) => {
|
|
190
|
-
console.error('[Daemon] Child process error:', err.message);
|
|
191
|
-
await this.writeLog(`Child error: ${err.message}`);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// 等待子进程退出
|
|
195
|
-
await new Promise<void>((resolve) => {
|
|
196
|
-
child.on('exit', () => resolve());
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* 设置优雅退出
|
|
203
|
-
*/
|
|
204
|
-
private setupGracefulShutdown(): void {
|
|
205
|
-
let isShuttingDown = false;
|
|
206
|
-
|
|
207
|
-
const shutdown = async () => {
|
|
208
|
-
if (isShuttingDown) return;
|
|
209
|
-
isShuttingDown = true;
|
|
210
|
-
|
|
211
|
-
console.log('[Daemon] Graceful shutdown...');
|
|
212
|
-
await this.writeLog('Graceful shutdown');
|
|
213
|
-
this.stopRequested = true;
|
|
214
|
-
|
|
215
|
-
await this.clearPid();
|
|
216
|
-
process.exit(0);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
process.on('SIGTERM', shutdown);
|
|
220
|
-
process.on('SIGINT', shutdown);
|
|
221
|
-
process.on('uncaughtException', async (err) => {
|
|
222
|
-
console.error('[Daemon] Uncaught exception:', err);
|
|
223
|
-
await this.writeLog(`Uncaught exception: ${err.message}`);
|
|
224
|
-
await shutdown();
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* 设置信号处理
|
|
230
|
-
*/
|
|
231
|
-
private setupSignalHandlers(): void {
|
|
232
|
-
process.on('SIGHUP', () => {
|
|
233
|
-
console.log('[Daemon] Received SIGHUP, reloading...');
|
|
234
|
-
// 可以实现配置重载逻辑
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* 请求停止守护进程
|
|
240
|
-
*/
|
|
241
|
-
async stop(): Promise<void> {
|
|
242
|
-
const state = await this.getState();
|
|
243
|
-
if (state) {
|
|
244
|
-
console.log(`[Daemon] Sending SIGTERM to pid ${state.pid}`);
|
|
245
|
-
try {
|
|
246
|
-
process.kill(state.pid, 'SIGTERM');
|
|
247
|
-
} catch {
|
|
248
|
-
console.log('[Daemon] Process not found, clearing PID');
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
await this.clearPid();
|
|
252
|
-
this.stopRequested = true;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* 获取重启次数
|
|
257
|
-
*/
|
|
258
|
-
async getRestartCount(): Promise<number> {
|
|
259
|
-
return this.state?.restartCount || 0;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* 检查是否可以继续重启
|
|
264
|
-
*/
|
|
265
|
-
canRestart(): boolean {
|
|
266
|
-
return (this.state?.restartCount || 0) < this.config.maxRestarts;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 全局实例
|
|
271
|
-
let daemonManagerInstance: DaemonManager | null = null;
|
|
272
|
-
|
|
273
|
-
export function getDaemonManager(): DaemonManager {
|
|
274
|
-
if (!daemonManagerInstance) {
|
|
275
|
-
daemonManagerInstance = new DaemonManager();
|
|
276
|
-
}
|
|
277
|
-
return daemonManagerInstance;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
export function createDaemonManager(config?: Partial<DaemonConfig>): DaemonManager {
|
|
281
|
-
daemonManagerInstance = new DaemonManager(config);
|
|
282
|
-
return daemonManagerInstance;
|
|
283
|
-
}
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HealthMonitor - 健康检查核心
|
|
3
|
-
* 监控 P2P、Iroh、LLM、内存等关键指标
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { HealthStatus, HealthCheckResult, HealthCheckProvider } from './types.js';
|
|
7
|
-
import { getMinimax } from '../constraints/index.js';
|
|
8
|
-
|
|
9
|
-
export class HealthMonitor implements HealthCheckProvider {
|
|
10
|
-
private lastHeartbeatTime: number = Date.now();
|
|
11
|
-
private checkIntervalId: ReturnType<typeof setInterval> | null = null;
|
|
12
|
-
private onStatusChange?: (status: HealthStatus) => void;
|
|
13
|
-
|
|
14
|
-
constructor(private config: {
|
|
15
|
-
checkIntervalMs?: number;
|
|
16
|
-
onStatusChange?: (status: HealthStatus) => void;
|
|
17
|
-
} = {}) {
|
|
18
|
-
this.onStatusChange = config.onStatusChange;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 执行完整健康检查
|
|
23
|
-
*/
|
|
24
|
-
async check(): Promise<HealthStatus> {
|
|
25
|
-
const checks: HealthStatus['checks'] = {
|
|
26
|
-
p2p: await this.checkP2P(),
|
|
27
|
-
iroh: await this.checkIroh(),
|
|
28
|
-
llm: await this.checkLLM(),
|
|
29
|
-
memory: await this.checkMemory(),
|
|
30
|
-
heartbeat: await this.checkHeartbeat()
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// 计算整体状态
|
|
34
|
-
const errors = Object.values(checks).filter(c => c.status === 'error').length;
|
|
35
|
-
let status: HealthStatus['status'] = 'healthy';
|
|
36
|
-
if (errors >= 3) {
|
|
37
|
-
status = 'unhealthy';
|
|
38
|
-
} else if (errors >= 1) {
|
|
39
|
-
status = 'degraded';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const healthStatus: HealthStatus = {
|
|
43
|
-
status,
|
|
44
|
-
timestamp: new Date().toISOString(),
|
|
45
|
-
uptime_seconds: process.uptime(),
|
|
46
|
-
checks,
|
|
47
|
-
recommendations: this.generateRecommendations(checks)
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
this.onStatusChange?.(healthStatus);
|
|
51
|
-
return healthStatus;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 检查 P2P 连接状态
|
|
56
|
-
*/
|
|
57
|
-
async checkP2P(): Promise<HealthCheckResult> {
|
|
58
|
-
const start = Date.now();
|
|
59
|
-
try {
|
|
60
|
-
// 从全局状态获取 HyperswarmCommunicator
|
|
61
|
-
const comm = (global as any).hyperswarmComm;
|
|
62
|
-
if (!comm) {
|
|
63
|
-
return { status: 'ok', message: 'P2P not initialized yet', latency_ms: Date.now() - start };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const connections = comm.getConnections?.() || [];
|
|
67
|
-
return {
|
|
68
|
-
status: 'ok',
|
|
69
|
-
message: `Connected to ${connections.length} peers`,
|
|
70
|
-
details: { peer_count: connections.length },
|
|
71
|
-
latency_ms: Date.now() - start
|
|
72
|
-
};
|
|
73
|
-
} catch (err: any) {
|
|
74
|
-
return { status: 'error', message: err.message, latency_ms: Date.now() - start };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 检查 Iroh 节点状态
|
|
80
|
-
*/
|
|
81
|
-
async checkIroh(): Promise<HealthCheckResult> {
|
|
82
|
-
const start = Date.now();
|
|
83
|
-
try {
|
|
84
|
-
const { irohTransport } = await import('../network/iroh-transport.js');
|
|
85
|
-
|
|
86
|
-
if (!irohTransport.isRunning?.()) {
|
|
87
|
-
return { status: 'error', message: 'Iroh not running', latency_ms: Date.now() - start };
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const nodeId = irohTransport.getNodeId?.() || '';
|
|
91
|
-
const peers = irohTransport.getPeers?.() || [];
|
|
92
|
-
const pendingOffline = irohTransport.getPendingOfflineCount?.() || 0;
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
status: 'ok',
|
|
96
|
-
message: `Iroh running, ${peers.length} peers`,
|
|
97
|
-
details: {
|
|
98
|
-
nodeId: nodeId.substring(0, 16) + '...',
|
|
99
|
-
peer_count: peers.length,
|
|
100
|
-
pending_offline_messages: pendingOffline
|
|
101
|
-
},
|
|
102
|
-
latency_ms: Date.now() - start
|
|
103
|
-
};
|
|
104
|
-
} catch (err: any) {
|
|
105
|
-
return { status: 'error', message: err.message, latency_ms: Date.now() - start };
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* 检查 LLM 连接状态
|
|
111
|
-
*/
|
|
112
|
-
async checkLLM(): Promise<HealthCheckResult> {
|
|
113
|
-
const start = Date.now();
|
|
114
|
-
try {
|
|
115
|
-
const minimax = getMinimax();
|
|
116
|
-
|
|
117
|
-
if (!minimax) {
|
|
118
|
-
return { status: 'error', message: 'LLM not initialized', latency_ms: Date.now() - start };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// 执行 ping 测试
|
|
122
|
-
const latency = await this.pingLLM(minimax);
|
|
123
|
-
return {
|
|
124
|
-
status: 'ok',
|
|
125
|
-
message: 'LLM responsive',
|
|
126
|
-
details: { latency_ms: latency },
|
|
127
|
-
latency_ms: Date.now() - start
|
|
128
|
-
};
|
|
129
|
-
} catch (err: any) {
|
|
130
|
-
return { status: 'error', message: err.message, latency_ms: Date.now() - start };
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 检查内存使用
|
|
136
|
-
*/
|
|
137
|
-
async checkMemory(): Promise<HealthCheckResult> {
|
|
138
|
-
const start = Date.now();
|
|
139
|
-
try {
|
|
140
|
-
const usage = process.memoryUsage();
|
|
141
|
-
const heapUsedPercent = (usage.heapUsed / usage.heapTotal) * 100;
|
|
142
|
-
const rssPercent = (usage.rss / (1024 * 1024 * 1024)) * 100; // GB
|
|
143
|
-
|
|
144
|
-
// 获取系统总内存 (macOS/Linux)
|
|
145
|
-
let systemMemoryPercent = 0;
|
|
146
|
-
try {
|
|
147
|
-
if (process.platform === 'darwin' || process.platform === 'linux') {
|
|
148
|
-
const { execSync } = require('child_process');
|
|
149
|
-
if (process.platform === 'darwin') {
|
|
150
|
-
const total = execSync('sysctl -n hw.memsize').toString().trim();
|
|
151
|
-
const free = execSync('vm_stat | grep "Pages free" | awk \'{print $3}\' | tr -d "."');
|
|
152
|
-
const pageSize = execSync('sysctl -n vm.pagesize').toString().trim();
|
|
153
|
-
systemMemoryPercent = ((parseInt(free) * parseInt(pageSize)) / parseInt(total)) * 100;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
} catch {
|
|
157
|
-
// 忽略系统内存获取失败
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const isHealthy = heapUsedPercent < 80;
|
|
161
|
-
|
|
162
|
-
return {
|
|
163
|
-
status: isHealthy ? 'ok' : 'error',
|
|
164
|
-
message: isHealthy ? 'Memory usage normal' : 'Memory usage high',
|
|
165
|
-
details: {
|
|
166
|
-
heap_used_mb: Math.round(usage.heapUsed / 1024 / 1024),
|
|
167
|
-
heap_total_mb: Math.round(usage.heapTotal / 1024 / 1024),
|
|
168
|
-
heap_used_percent: Math.round(heapUsedPercent * 10) / 10,
|
|
169
|
-
rss_mb: Math.round(usage.rss / 1024 / 1024)
|
|
170
|
-
},
|
|
171
|
-
latency_ms: Date.now() - start
|
|
172
|
-
};
|
|
173
|
-
} catch (err: any) {
|
|
174
|
-
return { status: 'error', message: err.message, latency_ms: Date.now() - start };
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 检查心跳活跃度
|
|
180
|
-
*/
|
|
181
|
-
async checkHeartbeat(): Promise<HealthCheckResult> {
|
|
182
|
-
const start = Date.now();
|
|
183
|
-
const elapsed = Date.now() - this.lastHeartbeatTime;
|
|
184
|
-
|
|
185
|
-
// 获取 SocialHeartbeat 状态
|
|
186
|
-
const heartbeat = (global as any).socialHeartbeat;
|
|
187
|
-
let agentsCount = 0;
|
|
188
|
-
let antColonyEnabled = false;
|
|
189
|
-
|
|
190
|
-
if (heartbeat) {
|
|
191
|
-
const agents = heartbeat.getDiscoveredAgents?.();
|
|
192
|
-
agentsCount = agents?.length || 0;
|
|
193
|
-
antColonyEnabled = heartbeat.isAntColonyEnabled?.() || false;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
status: elapsed < 60000 ? 'ok' : 'error',
|
|
198
|
-
message: elapsed < 60000
|
|
199
|
-
? `Heartbeat active ${Math.round(elapsed / 1000)}s ago`
|
|
200
|
-
: 'Heartbeat inactive for > 60s',
|
|
201
|
-
details: {
|
|
202
|
-
last_heartbeat_ms: elapsed,
|
|
203
|
-
discovered_agents: agentsCount,
|
|
204
|
-
ant_colony_enabled: antColonyEnabled
|
|
205
|
-
},
|
|
206
|
-
latency_ms: Date.now() - start
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 记录心跳活跃
|
|
212
|
-
*/
|
|
213
|
-
recordHeartbeat(): void {
|
|
214
|
-
this.lastHeartbeatTime = Date.now();
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* 获取当前状态(不执行检查)
|
|
219
|
-
*/
|
|
220
|
-
getQuickStatus(): { status: string; lastHeartbeat: number; memoryUsage: number } {
|
|
221
|
-
const usage = process.memoryUsage();
|
|
222
|
-
return {
|
|
223
|
-
status: 'active',
|
|
224
|
-
lastHeartbeat: this.lastHeartbeatTime,
|
|
225
|
-
memoryUsage: Math.round((usage.heapUsed / usage.heapTotal) * 100)
|
|
226
|
-
};
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* 生成健康建议
|
|
231
|
-
*/
|
|
232
|
-
private generateRecommendations(checks: HealthStatus['checks']): string[] {
|
|
233
|
-
const recommendations: string[] = [];
|
|
234
|
-
|
|
235
|
-
if (checks.p2p.status === 'error') {
|
|
236
|
-
recommendations.push('P2P 连接失败,建议检查网络');
|
|
237
|
-
}
|
|
238
|
-
if (checks.iroh.status === 'error') {
|
|
239
|
-
recommendations.push('Iroh 节点未运行,消息可能无法发送');
|
|
240
|
-
}
|
|
241
|
-
if (checks.llm.status === 'error') {
|
|
242
|
-
recommendations.push('LLM 连接失败,检查 API 密钥配置');
|
|
243
|
-
}
|
|
244
|
-
if (checks.memory.status === 'error') {
|
|
245
|
-
recommendations.push('内存使用率过高,考虑重启服务');
|
|
246
|
-
}
|
|
247
|
-
if (checks.heartbeat.status === 'error') {
|
|
248
|
-
recommendations.push('心跳长时间未活跃,检查系统是否卡死');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return recommendations;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Ping LLM 测试响应
|
|
256
|
-
*/
|
|
257
|
-
private async pingLLM(minimax: any): Promise<number> {
|
|
258
|
-
const start = Date.now();
|
|
259
|
-
try {
|
|
260
|
-
// 简单的 chat 测试
|
|
261
|
-
if (minimax.chat) {
|
|
262
|
-
await minimax.chat('ping', 'test', { maxTokens: 1 });
|
|
263
|
-
} else if (minimax.ping) {
|
|
264
|
-
await minimax.ping();
|
|
265
|
-
}
|
|
266
|
-
return Date.now() - start;
|
|
267
|
-
} catch {
|
|
268
|
-
// 如果 ping 失败,返回一个较大的值但不是错误
|
|
269
|
-
return Date.now() - start;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* 开始定期健康检查
|
|
275
|
-
*/
|
|
276
|
-
startPeriodicCheck(intervalMs: number = 60000, callback?: (status: HealthStatus) => void): void {
|
|
277
|
-
if (this.checkIntervalId) {
|
|
278
|
-
clearInterval(this.checkIntervalId);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const checkFn = async () => {
|
|
282
|
-
const status = await this.check();
|
|
283
|
-
callback?.(status);
|
|
284
|
-
this.onStatusChange?.(status);
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
this.checkIntervalId = setInterval(checkFn, intervalMs);
|
|
288
|
-
// 立即执行一次
|
|
289
|
-
checkFn();
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* 停止定期检查
|
|
294
|
-
*/
|
|
295
|
-
stopPeriodicCheck(): void {
|
|
296
|
-
if (this.checkIntervalId) {
|
|
297
|
-
clearInterval(this.checkIntervalId);
|
|
298
|
-
this.checkIntervalId = null;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
// 全局实例
|
|
304
|
-
let healthMonitorInstance: HealthMonitor | null = null;
|
|
305
|
-
|
|
306
|
-
export function getHealthMonitor(): HealthMonitor {
|
|
307
|
-
if (!healthMonitorInstance) {
|
|
308
|
-
healthMonitorInstance = new HealthMonitor();
|
|
309
|
-
}
|
|
310
|
-
return healthMonitorInstance;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export function createHealthMonitor(config?: { onStatusChange?: (status: HealthStatus) => void }): HealthMonitor {
|
|
314
|
-
healthMonitorInstance = new HealthMonitor(config);
|
|
315
|
-
return healthMonitorInstance;
|
|
316
|
-
}
|