@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,637 +0,0 @@
|
|
|
1
|
-
import { Endpoint, Connection } from '@rayhanadev/iroh';
|
|
2
|
-
import * as crypto from 'crypto';
|
|
3
|
-
import { loadOrCreateIrohSecret } from '../agents/iroh-secret.js';
|
|
4
|
-
|
|
5
|
-
export interface IrohMessage {
|
|
6
|
-
type: string;
|
|
7
|
-
payload: Uint8Array;
|
|
8
|
-
from: string;
|
|
9
|
-
requestId?: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type IrohMessageHandler = (msg: IrohMessage) => void;
|
|
13
|
-
|
|
14
|
-
const IROH_ALPN = 'bolloon/iroh/1';
|
|
15
|
-
|
|
16
|
-
export interface IrohPeer {
|
|
17
|
-
nodeId: string;
|
|
18
|
-
lastSeen: number;
|
|
19
|
-
connected: boolean;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// 导入存储层类型
|
|
23
|
-
interface OfflineMessage {
|
|
24
|
-
id: string;
|
|
25
|
-
targetNodeId: string;
|
|
26
|
-
type: string;
|
|
27
|
-
payload: string; // Base64
|
|
28
|
-
createdAt: number;
|
|
29
|
-
transport: 'iroh' | 'libp2p';
|
|
30
|
-
retryCount: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface PendingResponse {
|
|
34
|
-
id: string;
|
|
35
|
-
requestId: string;
|
|
36
|
-
type: string;
|
|
37
|
-
payload: string;
|
|
38
|
-
fromNodeId: string;
|
|
39
|
-
timestamp: number;
|
|
40
|
-
timeout: number;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
interface LocalPendingRequest {
|
|
44
|
-
requestId: string;
|
|
45
|
-
type: string;
|
|
46
|
-
payload: Uint8Array;
|
|
47
|
-
timestamp: number;
|
|
48
|
-
resolve: (response: Uint8Array) => void;
|
|
49
|
-
reject: (error: Error) => void;
|
|
50
|
-
timeout: ReturnType<typeof setTimeout>;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
interface MessageStore {
|
|
54
|
-
saveMessage(msg: any): Promise<any>;
|
|
55
|
-
enqueueOfflineMessage(msg: Omit<OfflineMessage, 'id'>): Promise<OfflineMessage>;
|
|
56
|
-
getOfflineMessages(targetNodeId: string): Promise<OfflineMessage[]>;
|
|
57
|
-
dequeueOfflineMessage(id: string): Promise<void>;
|
|
58
|
-
incrementOfflineRetry(id: string): Promise<void>;
|
|
59
|
-
getPendingOfflineCount(): Promise<number>;
|
|
60
|
-
getAllOfflineTargets(): Promise<string[]>;
|
|
61
|
-
savePendingResponse(req: Omit<PendingResponse, 'id'>): Promise<PendingResponse>;
|
|
62
|
-
getPendingResponse(requestId: string): Promise<PendingResponse | null>;
|
|
63
|
-
removePendingResponse(requestId: string): Promise<void>;
|
|
64
|
-
initialize(): Promise<void>;
|
|
65
|
-
shutdown(): Promise<void>;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export class IrohTransport {
|
|
69
|
-
private endpoint: Endpoint | null = null;
|
|
70
|
-
private messageHandlers: Map<string, IrohMessageHandler> = new Map();
|
|
71
|
-
private running: boolean = false;
|
|
72
|
-
private ownNodeId: string | null = null;
|
|
73
|
-
private peers: Map<string, IrohPeer> = new Map();
|
|
74
|
-
private connectTimeoutMs: number = 10000;
|
|
75
|
-
private acceptLoop: ReturnType<typeof setInterval> | null = null;
|
|
76
|
-
|
|
77
|
-
// 新增: 存储层
|
|
78
|
-
private messageStore: MessageStore | null = null;
|
|
79
|
-
private offlineDeliveryInterval: ReturnType<typeof setInterval> | null = null;
|
|
80
|
-
private requestTimeoutMs: number = 30000;
|
|
81
|
-
|
|
82
|
-
// 新增: 待响应请求 (内存缓存)
|
|
83
|
-
private pendingRequests: Map<string, LocalPendingRequest> = new Map();
|
|
84
|
-
private requestIdToNodeId: Map<string, string> = new Map();
|
|
85
|
-
|
|
86
|
-
async start(secretKey?: string, enablePersistence = false): Promise<{ nodeId: string; addr: string }> {
|
|
87
|
-
if (this.endpoint && this.ownNodeId) {
|
|
88
|
-
// 已启动,返回当前信息
|
|
89
|
-
return {
|
|
90
|
-
nodeId: this.ownNodeId,
|
|
91
|
-
addr: this.ownNodeId // iroh 没有 listenAddresses,用 nodeId 作为 addr
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 若调用方未传 secretKey,从 ~/.bolloon/iroh-secret-{role}.json 落盘/读取
|
|
96
|
-
// role 可通过 IROH_ROLE 环境变量覆盖, 方便同机起多个实例 (A/B 跨用户测试)
|
|
97
|
-
// 不设 IROH_ROLE 时 = 'default', 与旧行为一致
|
|
98
|
-
if (!secretKey) {
|
|
99
|
-
const role = process.env.IROH_ROLE || 'default';
|
|
100
|
-
try {
|
|
101
|
-
const sec = loadOrCreateIrohSecret(role);
|
|
102
|
-
// iroh binding 的 secretKey 字段是 hex 字符串 (32 字节 Ed25519 种子)
|
|
103
|
-
secretKey = Buffer.from(sec.secretKey).toString('hex');
|
|
104
|
-
console.log(`[IrohTransport] ${sec.reused ? '复用' : '新建'} iroh-secret-${role}.json (createdAt=${sec.createdAt})`);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
console.warn('[IrohTransport] iroh-secret 加载失败, 将使用临时身份:', e);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const options: any = { alpns: [IROH_ALPN] };
|
|
111
|
-
if (secretKey) {
|
|
112
|
-
options.secretKey = secretKey;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this.endpoint = await Endpoint.createWithOptions(options);
|
|
116
|
-
this.ownNodeId = this.endpoint.nodeId();
|
|
117
|
-
await this.endpoint.online();
|
|
118
|
-
this.running = true;
|
|
119
|
-
|
|
120
|
-
console.log('[IrohTransport] Started, node:', this.ownNodeId.substring(0, 16) + '...');
|
|
121
|
-
|
|
122
|
-
// 初始化存储层 (如果启用)
|
|
123
|
-
if (enablePersistence) {
|
|
124
|
-
this.messageStore = await this.createMessageStore();
|
|
125
|
-
await this.messageStore.initialize();
|
|
126
|
-
this.startOfflineDeliveryLoop();
|
|
127
|
-
console.log('[IrohTransport] Persistence enabled');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.startAcceptLoop();
|
|
131
|
-
|
|
132
|
-
return {
|
|
133
|
-
nodeId: this.endpoint.nodeId(),
|
|
134
|
-
addr: this.ownNodeId // iroh 没有 addr(),用 nodeId
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private async createMessageStore(): Promise<MessageStore> {
|
|
139
|
-
// 动态导入 JSON 存储适配器
|
|
140
|
-
try {
|
|
141
|
-
const { JsonMessageStore } = await import('./storage/adapters/json-adapter.js');
|
|
142
|
-
const path = await import('path');
|
|
143
|
-
const baseDir = path.join(process.env.HOME || '/tmp', '.bolloon', 'messages-iroh');
|
|
144
|
-
return new JsonMessageStore({ baseDir });
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.warn('[IrohTransport] Failed to load JSON adapter, using in-memory store');
|
|
147
|
-
return this.createInMemoryStore();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
private createInMemoryStore(): MessageStore {
|
|
152
|
-
const offlineQueues: Map<string, OfflineMessage[]> = new Map();
|
|
153
|
-
const pendingResponses: Map<string, PendingResponse> = new Map();
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
async saveMessage() {},
|
|
157
|
-
async enqueueOfflineMessage(msg) {
|
|
158
|
-
const id = crypto.randomUUID();
|
|
159
|
-
const offline = { ...msg, id };
|
|
160
|
-
const queue = offlineQueues.get(msg.targetNodeId) || [];
|
|
161
|
-
queue.push(offline);
|
|
162
|
-
offlineQueues.set(msg.targetNodeId, queue);
|
|
163
|
-
return offline;
|
|
164
|
-
},
|
|
165
|
-
async getOfflineMessages(targetNodeId) {
|
|
166
|
-
return offlineQueues.get(targetNodeId) || [];
|
|
167
|
-
},
|
|
168
|
-
async dequeueOfflineMessage(id) {
|
|
169
|
-
for (const [nodeId, queue] of offlineQueues.entries()) {
|
|
170
|
-
const idx = queue.findIndex(m => m.id === id);
|
|
171
|
-
if (idx >= 0) {
|
|
172
|
-
queue.splice(idx, 1);
|
|
173
|
-
offlineQueues.set(nodeId, queue);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
async incrementOfflineRetry(id) {
|
|
179
|
-
for (const queue of offlineQueues.values()) {
|
|
180
|
-
const msg = queue.find(m => m.id === id);
|
|
181
|
-
if (msg) {
|
|
182
|
-
msg.retryCount++;
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
async getPendingOfflineCount() {
|
|
188
|
-
let count = 0;
|
|
189
|
-
for (const queue of offlineQueues.values()) count += queue.length;
|
|
190
|
-
return count;
|
|
191
|
-
},
|
|
192
|
-
async getAllOfflineTargets() {
|
|
193
|
-
return Array.from(offlineQueues.keys());
|
|
194
|
-
},
|
|
195
|
-
async savePendingResponse(req) {
|
|
196
|
-
const id = crypto.randomUUID();
|
|
197
|
-
const pending = { ...req, id };
|
|
198
|
-
pendingResponses.set(req.requestId, pending);
|
|
199
|
-
return pending;
|
|
200
|
-
},
|
|
201
|
-
async getPendingResponse(requestId) {
|
|
202
|
-
return pendingResponses.get(requestId) || null;
|
|
203
|
-
},
|
|
204
|
-
async removePendingResponse(requestId) {
|
|
205
|
-
pendingResponses.delete(requestId);
|
|
206
|
-
},
|
|
207
|
-
async initialize() {},
|
|
208
|
-
async shutdown() {
|
|
209
|
-
offlineQueues.clear();
|
|
210
|
-
pendingResponses.clear();
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
private startOfflineDeliveryLoop(): void {
|
|
216
|
-
if (!this.messageStore) return;
|
|
217
|
-
|
|
218
|
-
this.offlineDeliveryInterval = setInterval(async () => {
|
|
219
|
-
// 遍历所有有离线消息的目标节点(不仅是"已连接"的)
|
|
220
|
-
// 这样目标节点一旦在线(accept 连接)就能拿到离线消息
|
|
221
|
-
const allTargets = await this.messageStore!.getAllOfflineTargets();
|
|
222
|
-
const connectedPeers = this.getConnectedPeers();
|
|
223
|
-
// 合并:已连接 + 有离线消息但未连接(也会去尝试 connect)
|
|
224
|
-
const targets = new Set<string>([...connectedPeers, ...allTargets]);
|
|
225
|
-
|
|
226
|
-
for (const peerId of targets) {
|
|
227
|
-
const offlineMsgs = await this.messageStore!.getOfflineMessages(peerId);
|
|
228
|
-
|
|
229
|
-
for (const msg of offlineMsgs) {
|
|
230
|
-
if (msg.retryCount >= 10) {
|
|
231
|
-
// 超过最大重试次数,丢弃
|
|
232
|
-
await this.messageStore!.dequeueOfflineMessage(msg.id);
|
|
233
|
-
console.log(`[IrohTransport] Dropped offline message after ${msg.retryCount} retries`);
|
|
234
|
-
continue;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
const payload = Uint8Array.from(atob(msg.payload), c => c.charCodeAt(0));
|
|
239
|
-
const success = await this.sendMessageDirect(peerId, msg.type, payload);
|
|
240
|
-
|
|
241
|
-
if (success) {
|
|
242
|
-
await this.messageStore!.dequeueOfflineMessage(msg.id);
|
|
243
|
-
console.log(`[IrohTransport] Delivered offline message to ${peerId.substring(0, 12)}...`);
|
|
244
|
-
} else {
|
|
245
|
-
await this.messageStore!.incrementOfflineRetry(msg.id);
|
|
246
|
-
}
|
|
247
|
-
} catch {
|
|
248
|
-
await this.messageStore!.incrementOfflineRetry(msg.id);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}, 5000);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
private startAcceptLoop(): void {
|
|
256
|
-
if (!this.endpoint) return;
|
|
257
|
-
|
|
258
|
-
this.acceptLoop = setInterval(async () => {
|
|
259
|
-
if (!this.endpoint || !this.running) return;
|
|
260
|
-
|
|
261
|
-
try {
|
|
262
|
-
const conn = await this.endpoint.accept();
|
|
263
|
-
if (conn) {
|
|
264
|
-
this.handleConnection(conn);
|
|
265
|
-
}
|
|
266
|
-
} catch {
|
|
267
|
-
// Silently ignore during shutdown
|
|
268
|
-
}
|
|
269
|
-
}, 100);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
private async handleConnection(conn: Connection): Promise<void> {
|
|
273
|
-
const remoteNodeId = conn.remoteNodeId();
|
|
274
|
-
this.updatePeer(remoteNodeId, true);
|
|
275
|
-
|
|
276
|
-
try {
|
|
277
|
-
const { recv } = await conn.acceptBi();
|
|
278
|
-
const data = await recv.readToEnd(64 * 1024);
|
|
279
|
-
|
|
280
|
-
if (data.length > 0) {
|
|
281
|
-
const text = new TextDecoder().decode(data);
|
|
282
|
-
const colonIdx = text.indexOf(':');
|
|
283
|
-
|
|
284
|
-
let type: string;
|
|
285
|
-
let payload: Uint8Array;
|
|
286
|
-
let requestId: string | undefined;
|
|
287
|
-
|
|
288
|
-
// 检查是否是请求/响应消息
|
|
289
|
-
if (text.startsWith('REQ:')) {
|
|
290
|
-
// Request: REQ:<requestId>:<type>:<payload>
|
|
291
|
-
const parts = text.substring(4).split(':');
|
|
292
|
-
requestId = parts[0];
|
|
293
|
-
type = parts[1] || 'request';
|
|
294
|
-
const payloadStr = parts.slice(2).join(':');
|
|
295
|
-
payload = new TextEncoder().encode(payloadStr);
|
|
296
|
-
|
|
297
|
-
// 保存请求信息,以便稍后响应
|
|
298
|
-
if (requestId) {
|
|
299
|
-
this.requestIdToNodeId.set(requestId, remoteNodeId);
|
|
300
|
-
}
|
|
301
|
-
} else if (text.startsWith('RESP:')) {
|
|
302
|
-
// Response: RESP:<requestId>:<payload>
|
|
303
|
-
const parts = text.substring(5).split(':');
|
|
304
|
-
requestId = parts[0];
|
|
305
|
-
type = 'RESPONSE';
|
|
306
|
-
payload = new TextEncoder().encode(parts.slice(1).join(':'));
|
|
307
|
-
|
|
308
|
-
// 处理响应 - 解决 pending request
|
|
309
|
-
this.handleResponse(requestId!, payload);
|
|
310
|
-
} else {
|
|
311
|
-
type = colonIdx > 0 ? text.substring(0, colonIdx) : 'raw';
|
|
312
|
-
payload = new TextEncoder().encode(text.substring(colonIdx + 1));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const handler = this.messageHandlers.get(type);
|
|
316
|
-
if (handler) {
|
|
317
|
-
handler({ type, payload, from: remoteNodeId, requestId });
|
|
318
|
-
} else if (this.messageHandlers.has('*')) {
|
|
319
|
-
this.messageHandlers.get('*')!({ type, payload, from: remoteNodeId, requestId });
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
} catch {
|
|
323
|
-
// Connection closed
|
|
324
|
-
} finally {
|
|
325
|
-
try { conn.close(); } catch {}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
private handleResponse(requestId: string, responseData: Uint8Array): void {
|
|
330
|
-
const pending = this.pendingRequests.get(requestId);
|
|
331
|
-
if (pending) {
|
|
332
|
-
clearTimeout(pending.timeout);
|
|
333
|
-
pending.resolve(responseData);
|
|
334
|
-
this.pendingRequests.delete(requestId);
|
|
335
|
-
console.log(`[IrohTransport] Response received for request ${requestId}`);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// 如果有持久化存储,也从那里删除
|
|
339
|
-
if (this.messageStore) {
|
|
340
|
-
this.messageStore.removePendingResponse(requestId);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
private updatePeer(nodeId: string, connected: boolean): void {
|
|
345
|
-
const existing = this.peers.get(nodeId);
|
|
346
|
-
this.peers.set(nodeId, {
|
|
347
|
-
nodeId,
|
|
348
|
-
lastSeen: Date.now(),
|
|
349
|
-
connected: existing?.connected || connected,
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
async connect(targetNodeId: string): Promise<boolean> {
|
|
354
|
-
if (!this.endpoint) {
|
|
355
|
-
throw new Error('IrohTransport not started');
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
try {
|
|
359
|
-
const conn = await this.connectWithTimeout(targetNodeId);
|
|
360
|
-
if (!conn) {
|
|
361
|
-
console.warn('[IrohTransport] Connection timeout to', targetNodeId.substring(0, 12) + '...');
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
this.updatePeer(targetNodeId, true);
|
|
366
|
-
conn.close();
|
|
367
|
-
return true;
|
|
368
|
-
} catch (e) {
|
|
369
|
-
console.warn('[IrohTransport] Connect failed:', e);
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
private async connectWithTimeout(nodeId: string): Promise<any> {
|
|
375
|
-
if (!this.endpoint) return null;
|
|
376
|
-
|
|
377
|
-
const connectPromise = this.endpoint.connect(nodeId, IROH_ALPN);
|
|
378
|
-
const timeout = new Promise<null>((resolve) =>
|
|
379
|
-
setTimeout(() => resolve(null), this.connectTimeoutMs)
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
return Promise.race([connectPromise, timeout]);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
async sendMessage(targetNodeId: string, type: string, payload: Uint8Array): Promise<boolean> {
|
|
386
|
-
const success = await this.sendMessageDirect(targetNodeId, type, payload);
|
|
387
|
-
|
|
388
|
-
// 如果发送失败且启用了持久化,存入离线队列
|
|
389
|
-
if (!success && this.messageStore) {
|
|
390
|
-
console.log(`[IrohTransport] Message send failed, enqueuing for offline delivery`);
|
|
391
|
-
const payloadBase64 = btoa(String.fromCharCode(...payload));
|
|
392
|
-
|
|
393
|
-
await this.messageStore.enqueueOfflineMessage({
|
|
394
|
-
targetNodeId,
|
|
395
|
-
type,
|
|
396
|
-
payload: payloadBase64,
|
|
397
|
-
createdAt: Date.now(),
|
|
398
|
-
transport: 'iroh',
|
|
399
|
-
retryCount: 0,
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
return success;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
private async sendMessageDirect(targetNodeId: string, type: string, payload: Uint8Array): Promise<boolean> {
|
|
407
|
-
if (!this.endpoint) {
|
|
408
|
-
throw new Error('IrohTransport not started');
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
try {
|
|
412
|
-
const conn = await this.connectWithTimeout(targetNodeId);
|
|
413
|
-
if (!conn) {
|
|
414
|
-
return false;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const { send } = await conn.openBi();
|
|
418
|
-
const message = type + ':' + new TextDecoder().decode(payload);
|
|
419
|
-
await send.writeAll(Buffer.from(message));
|
|
420
|
-
await send.finish();
|
|
421
|
-
conn.close();
|
|
422
|
-
|
|
423
|
-
this.updatePeer(targetNodeId, true);
|
|
424
|
-
return true;
|
|
425
|
-
} catch (e) {
|
|
426
|
-
console.warn('[IrohTransport] Send failed:', e);
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
async requestResponse(
|
|
432
|
-
targetNodeId: string,
|
|
433
|
-
type: string,
|
|
434
|
-
payload: Uint8Array,
|
|
435
|
-
timeoutMs?: number
|
|
436
|
-
): Promise<Uint8Array | null> {
|
|
437
|
-
if (!this.endpoint) {
|
|
438
|
-
throw new Error('IrohTransport not started');
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
const timeout = timeoutMs || this.requestTimeoutMs;
|
|
442
|
-
const requestId = crypto.randomUUID();
|
|
443
|
-
|
|
444
|
-
return new Promise(async (resolve, reject) => {
|
|
445
|
-
const timer = setTimeout(() => {
|
|
446
|
-
this.pendingRequests.delete(requestId);
|
|
447
|
-
if (this.messageStore) {
|
|
448
|
-
this.messageStore.removePendingResponse(requestId);
|
|
449
|
-
}
|
|
450
|
-
reject(new Error(`Request ${requestId} timed out after ${timeout}ms`));
|
|
451
|
-
}, timeout);
|
|
452
|
-
|
|
453
|
-
this.pendingRequests.set(requestId, {
|
|
454
|
-
requestId,
|
|
455
|
-
type,
|
|
456
|
-
payload,
|
|
457
|
-
timestamp: Date.now(),
|
|
458
|
-
resolve,
|
|
459
|
-
reject,
|
|
460
|
-
timeout: timer,
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
// 保存到持久化存储
|
|
464
|
-
if (this.messageStore) {
|
|
465
|
-
await this.messageStore.savePendingResponse({
|
|
466
|
-
requestId,
|
|
467
|
-
type,
|
|
468
|
-
payload: new TextDecoder().decode(payload),
|
|
469
|
-
fromNodeId: this.ownNodeId!,
|
|
470
|
-
timestamp: Date.now(),
|
|
471
|
-
timeout,
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// 尝试发送请求
|
|
476
|
-
try {
|
|
477
|
-
const conn = await this.connectWithTimeout(targetNodeId);
|
|
478
|
-
if (!conn) {
|
|
479
|
-
clearTimeout(timer);
|
|
480
|
-
this.pendingRequests.delete(requestId);
|
|
481
|
-
resolve(null);
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
const { send, recv } = await conn.openBi();
|
|
486
|
-
const requestMsg = `REQ:${requestId}:${type}:${new TextDecoder().decode(payload)}`;
|
|
487
|
-
await send.writeAll(Buffer.from(requestMsg));
|
|
488
|
-
await send.finish();
|
|
489
|
-
|
|
490
|
-
// 等待响应,带超时
|
|
491
|
-
// 注意: server sendResponse 后会关闭连接,导致 readToEnd 以 "connection lost" 错误 reject
|
|
492
|
-
// 这里我们把 readToEnd 的错误吞掉(视为流结束),只有超时才视为失败
|
|
493
|
-
const response = await Promise.race([
|
|
494
|
-
recv.readToEnd(64 * 1024).catch(() => new Uint8Array(0)),
|
|
495
|
-
new Promise<null>((_, rejectTimeout) =>
|
|
496
|
-
setTimeout(() => rejectTimeout(new Error('timeout')), timeout)
|
|
497
|
-
),
|
|
498
|
-
]);
|
|
499
|
-
|
|
500
|
-
conn.close();
|
|
501
|
-
clearTimeout(timer);
|
|
502
|
-
this.pendingRequests.delete(requestId);
|
|
503
|
-
|
|
504
|
-
if (this.messageStore) {
|
|
505
|
-
this.messageStore.removePendingResponse(requestId);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
if (response) {
|
|
509
|
-
resolve(response);
|
|
510
|
-
} else {
|
|
511
|
-
resolve(null);
|
|
512
|
-
}
|
|
513
|
-
} catch (e) {
|
|
514
|
-
clearTimeout(timer);
|
|
515
|
-
this.pendingRequests.delete(requestId);
|
|
516
|
-
reject(e);
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
async sendResponse(requestId: string, type: string, responsePayload: string): Promise<boolean> {
|
|
522
|
-
const targetNodeId = this.requestIdToNodeId.get(requestId);
|
|
523
|
-
if (!targetNodeId) {
|
|
524
|
-
console.warn(`[IrohTransport] No target node for request ${requestId}`);
|
|
525
|
-
return false;
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
try {
|
|
529
|
-
const conn = await this.connectWithTimeout(targetNodeId);
|
|
530
|
-
if (!conn) return false;
|
|
531
|
-
|
|
532
|
-
const { send } = await conn.openBi();
|
|
533
|
-
const responseMsg = `RESP:${requestId}:${responsePayload}`;
|
|
534
|
-
await send.writeAll(Buffer.from(responseMsg));
|
|
535
|
-
await send.finish();
|
|
536
|
-
conn.close();
|
|
537
|
-
|
|
538
|
-
this.requestIdToNodeId.delete(requestId);
|
|
539
|
-
console.log(`[IrohTransport] Sent response for request ${requestId}`);
|
|
540
|
-
return true;
|
|
541
|
-
} catch (e) {
|
|
542
|
-
console.warn(`[IrohTransport] Failed to send response:`, e);
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
async broadcast(type: string, payload: Uint8Array): Promise<void> {
|
|
548
|
-
const peers = Array.from(this.peers.keys());
|
|
549
|
-
const promises = peers.map((peerId) =>
|
|
550
|
-
this.sendMessage(peerId, type, payload).catch(() => false)
|
|
551
|
-
);
|
|
552
|
-
await Promise.all(promises);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
onMessage(type: string, handler: IrohMessageHandler): void {
|
|
556
|
-
this.messageHandlers.set(type, handler);
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
getNodeId(): string | null {
|
|
560
|
-
return this.ownNodeId;
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* v3: 返回 iroh endpoint 完整地址字符串 (含 relay URL)
|
|
565
|
-
* 这是 connect() 真正需要的"网络地址", 光有 nodeId 不足以建连
|
|
566
|
-
* 如果 endpoint 还没 online, 返回纯 nodeId
|
|
567
|
-
*/
|
|
568
|
-
getEndpointAddr(): string | null {
|
|
569
|
-
if (!this.endpoint) return null;
|
|
570
|
-
try {
|
|
571
|
-
return this.endpoint.addr();
|
|
572
|
-
} catch (e) {
|
|
573
|
-
return this.endpoint.nodeId();
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
getPeers(): IrohPeer[] {
|
|
578
|
-
return Array.from(this.peers.values());
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
getConnectedPeers(): string[] {
|
|
582
|
-
return Array.from(this.peers.values())
|
|
583
|
-
.filter((p) => p.connected)
|
|
584
|
-
.map((p) => p.nodeId);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
isRunning(): boolean {
|
|
588
|
-
return this.running;
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
setConnectTimeout(ms: number): void {
|
|
592
|
-
this.connectTimeoutMs = ms;
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
getPendingOfflineCount(): number {
|
|
596
|
-
if (!this.messageStore) return 0;
|
|
597
|
-
return this.messageStore.getPendingOfflineCount() as unknown as number;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
async shutdown(): Promise<void> {
|
|
601
|
-
this.running = false;
|
|
602
|
-
|
|
603
|
-
if (this.offlineDeliveryInterval) {
|
|
604
|
-
clearInterval(this.offlineDeliveryInterval);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
if (this.acceptLoop) {
|
|
608
|
-
clearInterval(this.acceptLoop);
|
|
609
|
-
this.acceptLoop = null;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// 清理 pending requests
|
|
613
|
-
for (const [id, pending] of this.pendingRequests) {
|
|
614
|
-
clearTimeout(pending.timeout);
|
|
615
|
-
pending.reject(new Error('Shutting down'));
|
|
616
|
-
}
|
|
617
|
-
this.pendingRequests.clear();
|
|
618
|
-
|
|
619
|
-
if (this.messageStore) {
|
|
620
|
-
await this.messageStore.shutdown();
|
|
621
|
-
this.messageStore = null;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (this.endpoint) {
|
|
625
|
-
try {
|
|
626
|
-
await this.endpoint.close();
|
|
627
|
-
} catch {}
|
|
628
|
-
this.endpoint = null;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
this.peers.clear();
|
|
632
|
-
this.ownNodeId = null;
|
|
633
|
-
console.log('[IrohTransport] Shut down');
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
export const irohTransport = new IrohTransport();
|