@bolloon/bolloon-agent 0.1.36 → 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/dist/web/client.js +2861 -3746
- package/dist/web/components/p2p/index.js +226 -264
- package/dist/web/ui/message-renderer.js +323 -434
- package/dist/web/ui/step-timeline.js +255 -351
- package/package.json +2 -2
- package/.auto-evolve-calls +0 -1
- package/.last-auto-evolve-baseline +0 -1
- package/.playwright-mcp/page-2026-06-16T07-51-45-706Z.yml +0 -130
- package/.playwright-mcp/page-2026-06-16T07-56-44-116Z.yml +0 -131
- package/Bolloon.md +0 -144
- package/Dive-into/CITATION.cff +0 -17
- package/Dive-into/LICENSE +0 -25
- package/Dive-into/README.md +0 -598
- package/Dive-into/README_zh.md +0 -599
- package/Dive-into/assets/context.png +0 -0
- package/Dive-into/assets/extensibility.png +0 -0
- package/Dive-into/assets/iteration.png +0 -0
- package/Dive-into/assets/layered_architecture.png +0 -0
- package/Dive-into/assets/main_structure.png +0 -0
- package/Dive-into/assets/permission.png +0 -0
- package/Dive-into/assets/session_compact.png +0 -0
- package/Dive-into/assets/subagent.png +0 -0
- package/Dive-into/paper/Dive_into_Claude_Code.pdf +0 -0
- package/dist/agents/constraint-layer.js.map +0 -1
- package/dist/agents/pi-sdk.js.map +0 -1
- package/dist/agents/workflow-engine.js.map +0 -1
- package/dist/bollharness/src/index.js +0 -5
- package/dist/bollharness/src/scripts/checks/check_adr_plan_numbering.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_api_types.js +0 -45
- package/dist/bollharness/src/scripts/checks/check_artifact_link.js +0 -146
- package/dist/bollharness/src/scripts/checks/check_bridge_deps.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_bugfix_binding_ci.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_doc_file_references.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_doc_freshness.js +0 -135
- package/dist/bollharness/src/scripts/checks/check_doc_links.js +0 -31
- package/dist/bollharness/src/scripts/checks/check_file_existence_claims.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_fragment_integrity.js +0 -34
- package/dist/bollharness/src/scripts/checks/check_hook_installed.js +0 -63
- package/dist/bollharness/src/scripts/checks/check_issue_closure.js +0 -41
- package/dist/bollharness/src/scripts/checks/check_mcp_parity.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_security.js +0 -48
- package/dist/bollharness/src/scripts/checks/check_skill_parity.js +0 -6
- package/dist/bollharness/src/scripts/checks/check_versions.js +0 -6
- package/dist/bollharness/src/scripts/checks/finding.js +0 -13
- package/dist/bollharness/src/scripts/checks/next_decision_number.js +0 -20
- package/dist/bollharness/src/scripts/checks/regenerate_magic_docs.js +0 -6
- package/dist/bollharness/src/scripts/ci/detect_rebaseline_triggers.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_subprocess_cfg.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_verify_artifacts.js +0 -8
- package/dist/bollharness/src/scripts/ci/scan_yaml_schema.js +0 -8
- package/dist/bollharness/src/scripts/context_router.js +0 -67
- package/dist/bollharness/src/scripts/deploy-guard.js +0 -157
- package/dist/bollharness/src/scripts/guard-feedback.js +0 -192
- package/dist/bollharness/src/scripts/guard_router.js +0 -158
- package/dist/bollharness/src/scripts/hooks/_hook_output.js +0 -6
- package/dist/bollharness/src/scripts/hooks/auto-python3.js +0 -6
- package/dist/bollharness/src/scripts/hooks/deploy-progress-on-session-end.js +0 -6
- package/dist/bollharness/src/scripts/hooks/failure-analyzer.js +0 -6
- package/dist/bollharness/src/scripts/hooks/gate-judgment-inject.js +0 -92
- package/dist/bollharness/src/scripts/hooks/gate-transition-judgment.js +0 -63
- package/dist/bollharness/src/scripts/hooks/inbox-ack.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-inject-on-start.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-validate.js +0 -6
- package/dist/bollharness/src/scripts/hooks/inbox-write-ledger.js +0 -6
- package/dist/bollharness/src/scripts/hooks/initializer-agent.js +0 -6
- package/dist/bollharness/src/scripts/hooks/loop-detection.js +0 -73
- package/dist/bollharness/src/scripts/hooks/owner-guard.js +0 -6
- package/dist/bollharness/src/scripts/hooks/precompact.js +0 -6
- package/dist/bollharness/src/scripts/hooks/review-agent-gatekeeper.js +0 -6
- package/dist/bollharness/src/scripts/hooks/risk-tracker.js +0 -108
- package/dist/bollharness/src/scripts/hooks/sanitize-on-read.js +0 -6
- package/dist/bollharness/src/scripts/hooks/session-reflection.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-magic-docs.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-reset-risk.js +0 -7
- package/dist/bollharness/src/scripts/hooks/session-start-toolkit-reminder.js +0 -7
- package/dist/bollharness/src/scripts/hooks/stop-evaluator.js +0 -157
- package/dist/bollharness/src/scripts/hooks/tool-call-counter.js +0 -6
- package/dist/bollharness/src/scripts/hooks/trace-analyzer.js +0 -10
- package/dist/bollharness/src/scripts/install/install-trust-token.js +0 -7
- package/dist/bollharness/src/scripts/install/multi_project_registry.js +0 -9
- package/dist/bollharness/src/scripts/install/phase2_auto.js +0 -21
- package/dist/bollharness/src/scripts/install/pre_commit_installer.js +0 -6
- package/dist/bollharness/src/scripts/install/tier_selector.js +0 -7
- package/dist/bollharness/src/scripts/install/transcript_miner.js +0 -7
- package/dist/bollharness/src/scripts/lib/claim_patterns.js +0 -10
- package/dist/bollharness/src/scripts/lib/sanitize_patterns.js +0 -12
- package/dist/bollharness/src/scripts/sanitize.js +0 -6
- package/dist/bollharness-integration/context-router-judgment.js.map +0 -1
- package/dist/bollharness-integration/context-router.js.map +0 -1
- package/dist/bollharness-integration/gate-state-machine.js.map +0 -1
- package/dist/bollharness-integration/gate-transition-hooks.js.map +0 -1
- package/dist/bollharness-integration/guard-checker.js.map +0 -1
- package/dist/bollharness-integration/index.js.map +0 -1
- package/dist/bollharness-integration/integration.js.map +0 -1
- package/dist/bollharness-integration/llm/pi-ai.d.ts +0 -60
- package/dist/bollharness-integration/pi-ecosystem-colony/index.d.ts +0 -153
- package/dist/bollharness-integration/pi-ecosystem-goals/index.d.ts +0 -136
- package/dist/bollharness-integration/pi-ecosystem-judgment/decision.d.ts +0 -117
- package/dist/bollharness-integration/pi-ecosystem-judgment/distillation.d.ts +0 -78
- package/dist/bollharness-integration/pi-ecosystem-judgment/index.d.ts +0 -139
- package/dist/bollharness-integration/pi-ecosystem-mcp/index.d.ts +0 -127
- package/dist/bollharness-integration/pi-ecosystem-subagents/index.d.ts +0 -95
- package/dist/bollharness-integration/skill-adapter.js.map +0 -1
- package/dist/constraint-runtime/src/_archive_helper.js +0 -9
- package/dist/constraint-runtime/src/agent/coordinator.js +0 -48
- package/dist/constraint-runtime/src/agent/index.js +0 -1
- package/dist/constraint-runtime/src/assistant/index.js +0 -12
- package/dist/constraint-runtime/src/bootstrap/index.js +0 -12
- package/dist/constraint-runtime/src/bootstrap_graph.js +0 -13
- package/dist/constraint-runtime/src/bridge/index.js +0 -12
- package/dist/constraint-runtime/src/buddy/index.js +0 -12
- package/dist/constraint-runtime/src/cli/index.js +0 -12
- package/dist/constraint-runtime/src/command_graph.js +0 -10
- package/dist/constraint-runtime/src/commands.js +0 -60
- package/dist/constraint-runtime/src/components/index.js +0 -12
- package/dist/constraint-runtime/src/constants/index.js +0 -12
- package/dist/constraint-runtime/src/constraint/budget.js +0 -22
- package/dist/constraint-runtime/src/constraint/budget.js.map +0 -1
- package/dist/constraint-runtime/src/constraint/index.js +0 -2
- package/dist/constraint-runtime/src/constraint/permission.js +0 -20
- package/dist/constraint-runtime/src/constraint/permission.js.map +0 -1
- package/dist/constraint-runtime/src/context.js +0 -30
- package/dist/constraint-runtime/src/coordinator/index.js +0 -12
- package/dist/constraint-runtime/src/cost_hook.js +0 -4
- package/dist/constraint-runtime/src/cost_tracker.js +0 -8
- package/dist/constraint-runtime/src/deferred_init.js +0 -10
- package/dist/constraint-runtime/src/direct_modes.js +0 -6
- package/dist/constraint-runtime/src/dynamic-tool-loader.js +0 -85
- package/dist/constraint-runtime/src/entrypoints/index.js +0 -12
- package/dist/constraint-runtime/src/execution_registry.js +0 -44
- package/dist/constraint-runtime/src/history.js +0 -9
- package/dist/constraint-runtime/src/hooks/index.js +0 -12
- package/dist/constraint-runtime/src/index.js +0 -26
- package/dist/constraint-runtime/src/ink.js +0 -4
- package/dist/constraint-runtime/src/keybindings/index.js +0 -12
- package/dist/constraint-runtime/src/memdir/index.js +0 -12
- package/dist/constraint-runtime/src/migrations/index.js +0 -12
- package/dist/constraint-runtime/src/models.js +0 -1
- package/dist/constraint-runtime/src/models.js.map +0 -1
- package/dist/constraint-runtime/src/moreright/index.js +0 -12
- package/dist/constraint-runtime/src/native_ts/index.js +0 -12
- package/dist/constraint-runtime/src/output_styles/index.js +0 -12
- package/dist/constraint-runtime/src/parity_audit.js +0 -12
- package/dist/constraint-runtime/src/plugins/index.js +0 -12
- package/dist/constraint-runtime/src/port_manifest.js +0 -11
- package/dist/constraint-runtime/src/prefetch.js +0 -9
- package/dist/constraint-runtime/src/query.js +0 -1
- package/dist/constraint-runtime/src/remote/index.js +0 -12
- package/dist/constraint-runtime/src/remote_runtime.js +0 -9
- package/dist/constraint-runtime/src/runtime/index.js +0 -1
- package/dist/constraint-runtime/src/runtime/session.js +0 -35
- package/dist/constraint-runtime/src/schemas/index.js +0 -12
- package/dist/constraint-runtime/src/screens/index.js +0 -12
- package/dist/constraint-runtime/src/server/index.js +0 -12
- package/dist/constraint-runtime/src/services/index.js +0 -12
- package/dist/constraint-runtime/src/session_store.js +0 -22
- package/dist/constraint-runtime/src/setup.js +0 -30
- package/dist/constraint-runtime/src/skills/index.js +0 -1
- package/dist/constraint-runtime/src/skills/skill-registry.js +0 -28
- package/dist/constraint-runtime/src/state/index.js +0 -12
- package/dist/constraint-runtime/src/system_init.js +0 -20
- package/dist/constraint-runtime/src/thinking/engine.js +0 -42
- package/dist/constraint-runtime/src/thinking/index.js +0 -1
- package/dist/constraint-runtime/src/tool_pool.js +0 -8
- package/dist/constraint-runtime/src/tools/OpenCLI/execAdapter.js +0 -7
- package/dist/constraint-runtime/src/tools/OpenCLI/listAdapters.js +0 -7
- package/dist/constraint-runtime/src/tools/OpenCLI/runCommand.js +0 -7
- package/dist/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +0 -5
- package/dist/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +0 -6
- package/dist/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +0 -4
- package/dist/constraint-runtime/src/tools/SafeSDK/confirmTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/createTransaction.js +0 -8
- package/dist/constraint-runtime/src/tools/SafeSDK/deploySafe.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/executeTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/getBalance.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/getPendingTransactions.js +0 -6
- package/dist/constraint-runtime/src/tools/SafeSDK/proposeTransaction.js +0 -6
- package/dist/constraint-runtime/src/tools/WalletTools/autoPay.js +0 -29
- package/dist/constraint-runtime/src/tools/WalletTools/createWallet.js +0 -10
- package/dist/constraint-runtime/src/tools/WalletTools/getBalance.js +0 -13
- package/dist/constraint-runtime/src/tools/WalletTools/importWallet.js +0 -22
- package/dist/constraint-runtime/src/tools/WalletTools/sendTransaction.js +0 -25
- package/dist/constraint-runtime/src/tools/WalletTools/signMessage.js +0 -10
- package/dist/constraint-runtime/src/tools/WalletTools/transferToken.js +0 -25
- package/dist/constraint-runtime/src/tools.js +0 -80
- package/dist/constraint-runtime/src/transcript.js +0 -19
- package/dist/constraint-runtime/src/types/index.js +0 -12
- package/dist/constraint-runtime/src/upstream_proxy/index.js +0 -12
- package/dist/constraint-runtime/src/utils/index.js +0 -12
- package/dist/constraint-runtime/src/vim/index.js +0 -12
- package/dist/constraint-runtime/src/voice/index.js +0 -12
- package/dist/constraints/index.js.map +0 -1
- package/dist/documents/reader.js.map +0 -1
- package/dist/llm/config-store.js.map +0 -1
- package/dist/llm/pi-ai.js.map +0 -1
- package/dist/network/agent-network.js.map +0 -1
- package/dist/network/iroh-integration.js.map +0 -1
- package/dist/network/iroh-transport.js.map +0 -1
- package/dist/network/p2p.js.map +0 -1
- package/dist/network/storage/adapters/json-adapter.js.map +0 -1
- package/dist/pi-ecosystem-colony/index.js.map +0 -1
- package/dist/pi-ecosystem-goals/index.js.map +0 -1
- package/dist/pi-ecosystem-judgment/decision.js.map +0 -1
- package/dist/pi-ecosystem-judgment/distillation.js.map +0 -1
- package/dist/pi-ecosystem-judgment/human-value-store.js.map +0 -1
- package/dist/pi-ecosystem-judgment/index.js.map +0 -1
- package/dist/pi-ecosystem-judgment/value-injection.js.map +0 -1
- package/dist/pi-ecosystem-mcp/index.js.map +0 -1
- package/dist/pi-ecosystem-subagents/index.js.map +0 -1
- package/dist/social/ant-colony/AdaptiveHeartbeat.js.map +0 -1
- package/dist/social/ant-colony/PheromoneEngine.js.map +0 -1
- package/dist/social/ant-colony/types.js.map +0 -1
- package/dist/social/channels/ChannelManager.js.map +0 -1
- package/dist/social/channels/DiapChannelBridge.js.map +0 -1
- package/dist/social/channels/InterestMatcher.js.map +0 -1
- package/dist/social/channels/types.js.map +0 -1
- package/dist/social/global-shared-context.js.map +0 -1
- package/dist/social/heartbeat.js.map +0 -1
- package/dist/web/components/p2p/P2PModal.js +0 -188
- package/dist/web/components/p2p/p2p-modal.js +0 -657
- package/dist/web/components/p2p/p2p-tools.js +0 -248
- package/lefthook.yml +0 -33
- package/scripts/auto-evolve-loop.ts +0 -481
- 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 -116
- package/scripts/detect-schema-changes.sh +0 -48
- package/scripts/diff-reviewer.ts +0 -159
- package/scripts/postinstall.js +0 -153
- package/scripts/validate-system-prompt.ts +0 -142
- package/scripts/weekly-report.ts +0 -364
- package/src/agents/agent-manifest-protocol.ts +0 -117
- package/src/agents/constraint-layer.ts +0 -309
- package/src/agents/iroh-secret.ts +0 -32
- package/src/agents/p2p-chat-tools.ts +0 -383
- package/src/agents/p2p-document-tools.ts +0 -347
- package/src/agents/permission-mode.ts +0 -127
- package/src/agents/pi-sdk.ts +0 -2895
- package/src/agents/pre-tool-validator.ts +0 -213
- package/src/agents/protocol.ts +0 -398
- package/src/agents/shell-guard.ts +0 -417
- package/src/agents/shell-tool.ts +0 -103
- package/src/agents/skill-loader.ts +0 -202
- package/src/agents/subagent-manager.ts +0 -553
- package/src/agents/workflow-engine.ts +0 -332
- package/src/agents/workflow-pivot-loop.ts +0 -766
- package/src/bollharness/.sanitize-report.json +0 -13
- package/src/bollharness/CLAUDE.md +0 -73
- package/src/bollharness/LICENSE +0 -21
- package/src/bollharness/README.md +0 -143
- package/src/bollharness/README.zh-CN.md +0 -131
- package/src/bollharness/package.json +0 -20
- package/src/bollharness/reference/SOURCE-COMMIT.txt +0 -3
- package/src/bollharness/reference/boll-reference/scripts/hooks/.sanitize-report.json +0 -12
- package/src/bollharness/reference/boll-reference/scripts/hooks/find-boll-root.sh +0 -27
- package/src/bollharness/reference/boll-reference/scripts/hooks/precompact.sh +0 -57
- package/src/bollharness/reference/boll-reference/scripts/hooks/stop-evaluator.md +0 -57
- package/src/bollharness/schemas/metrics-jsonl-allowlist.json +0 -67
- package/src/bollharness/scripts/checks/next_decision_number.sh +0 -48
- package/src/bollharness/scripts/ci/count-components.sh +0 -65
- package/src/bollharness/scripts/context-fragments/artifact-linkage.md +0 -14
- package/src/bollharness/scripts/context-fragments/auth-consumers.md +0 -17
- package/src/bollharness/scripts/context-fragments/bridge-constitution.md +0 -13
- package/src/bollharness/scripts/context-fragments/catalyst-distributed.md +0 -18
- package/src/bollharness/scripts/context-fragments/closure-checklist.md +0 -13
- package/src/bollharness/scripts/context-fragments/contract-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/db-shared-structures.md +0 -15
- package/src/bollharness/scripts/context-fragments/fixed-three-layers.md +0 -19
- package/src/bollharness/scripts/context-fragments/general-dev-principles.md +0 -11
- package/src/bollharness/scripts/context-fragments/issue-first.md +0 -8
- package/src/bollharness/scripts/context-fragments/mcp-parity.md +0 -16
- package/src/bollharness/scripts/context-fragments/pi-agent-operations.md +0 -108
- package/src/bollharness/scripts/context-fragments/protocol-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/run-events-consumers.md +0 -15
- package/src/bollharness/scripts/context-fragments/scene-fidelity.md +0 -13
- package/src/bollharness/scripts/context-fragments/truth-source-hierarchy.md +0 -15
- package/src/bollharness/scripts/context-fragments/two-language.md +0 -15
- package/src/bollharness/scripts/context-fragments/version-sources.md +0 -14
- package/src/bollharness/scripts/hooks/find-project-root.sh +0 -47
- package/src/bollharness/scripts/hooks/inbox-poll.sh +0 -78
- package/src/bollharness/scripts/hooks/precompact.sh +0 -56
- package/src/bollharness/scripts/hooks/stop-evaluator.md +0 -83
- package/src/bollharness/scripts/sync-from-upstream.sh +0 -281
- package/src/bollharness/src/index.ts +0 -5
- package/src/bollharness/src/scripts/checks/check_adr_plan_numbering.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_api_types.ts +0 -52
- package/src/bollharness/src/scripts/checks/check_artifact_link.ts +0 -156
- package/src/bollharness/src/scripts/checks/check_bridge_deps.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_bugfix_binding.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_bugfix_binding_ci.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_doc_file_references.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_doc_freshness.ts +0 -141
- package/src/bollharness/src/scripts/checks/check_doc_links.ts +0 -36
- package/src/bollharness/src/scripts/checks/check_file_existence_claims.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_fragment_integrity.ts +0 -40
- package/src/bollharness/src/scripts/checks/check_hook_installed.ts +0 -70
- package/src/bollharness/src/scripts/checks/check_issue_closure.ts +0 -51
- package/src/bollharness/src/scripts/checks/check_mcp_parity.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_security.ts +0 -54
- package/src/bollharness/src/scripts/checks/check_skill_parity.ts +0 -11
- package/src/bollharness/src/scripts/checks/check_versions.ts +0 -11
- package/src/bollharness/src/scripts/checks/finding.ts +0 -35
- package/src/bollharness/src/scripts/checks/next_decision_number.ts +0 -24
- package/src/bollharness/src/scripts/checks/regenerate_magic_docs.ts +0 -11
- package/src/bollharness/src/scripts/ci/detect_rebaseline_triggers.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_subprocess_cfg.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_verify_artifacts.ts +0 -14
- package/src/bollharness/src/scripts/ci/scan_yaml_schema.ts +0 -14
- package/src/bollharness/src/scripts/context_router.ts +0 -76
- package/src/bollharness/src/scripts/deploy-guard.ts +0 -182
- package/src/bollharness/src/scripts/guard-feedback.ts +0 -215
- package/src/bollharness/src/scripts/guard_router.ts +0 -194
- package/src/bollharness/src/scripts/hooks/_hook_output.js +0 -3
- package/src/bollharness/src/scripts/hooks/_hook_output.ts +0 -11
- package/src/bollharness/src/scripts/hooks/auto-python3.ts +0 -10
- package/src/bollharness/src/scripts/hooks/deploy-progress-on-session-end.ts +0 -10
- package/src/bollharness/src/scripts/hooks/failure-analyzer.ts +0 -10
- package/src/bollharness/src/scripts/hooks/gate-judgment-inject.ts +0 -111
- package/src/bollharness/src/scripts/hooks/gate-transition-judgment.ts +0 -74
- package/src/bollharness/src/scripts/hooks/inbox-ack.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-inject-on-start.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-validate.ts +0 -10
- package/src/bollharness/src/scripts/hooks/inbox-write-ledger.ts +0 -10
- package/src/bollharness/src/scripts/hooks/initializer-agent.ts +0 -10
- package/src/bollharness/src/scripts/hooks/loop-detection.ts +0 -83
- package/src/bollharness/src/scripts/hooks/owner-guard.ts +0 -10
- package/src/bollharness/src/scripts/hooks/precompact.ts +0 -10
- package/src/bollharness/src/scripts/hooks/review-agent-gatekeeper.ts +0 -10
- package/src/bollharness/src/scripts/hooks/risk-tracker.ts +0 -121
- package/src/bollharness/src/scripts/hooks/sanitize-on-read.ts +0 -10
- package/src/bollharness/src/scripts/hooks/session-reflection.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-magic-docs.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-reset-risk.ts +0 -12
- package/src/bollharness/src/scripts/hooks/session-start-toolkit-reminder.ts +0 -12
- package/src/bollharness/src/scripts/hooks/stop-evaluator.ts +0 -164
- package/src/bollharness/src/scripts/hooks/tool-call-counter.ts +0 -10
- package/src/bollharness/src/scripts/hooks/trace-analyzer.ts +0 -14
- package/src/bollharness/src/scripts/install/install-trust-token.ts +0 -13
- package/src/bollharness/src/scripts/install/multi_project_registry.ts +0 -13
- package/src/bollharness/src/scripts/install/phase2_auto.ts +0 -28
- package/src/bollharness/src/scripts/install/pre_commit_installer.ts +0 -10
- package/src/bollharness/src/scripts/install/tier_selector.ts +0 -10
- package/src/bollharness/src/scripts/install/transcript_miner.ts +0 -13
- package/src/bollharness/src/scripts/lib/claim_patterns.ts +0 -11
- package/src/bollharness/src/scripts/lib/sanitize_patterns.ts +0 -13
- package/src/bollharness/src/scripts/sanitize.ts +0 -9
- package/src/bollharness/templates/persona/default.json +0 -19
- package/src/bollharness/templates/scaffold/.gitignore.append +0 -16
- package/src/bollharness/templates/scaffold/CLAUDE.md +0 -89
- package/src/bollharness-integration/channel-judgment-engine.ts +0 -634
- package/src/bollharness-integration/context-chain-router.ts +0 -474
- package/src/bollharness-integration/context-router-judgment.ts +0 -339
- package/src/bollharness-integration/context-router.ts +0 -583
- package/src/bollharness-integration/gate-state-machine.ts +0 -444
- package/src/bollharness-integration/gate-transition-hooks.ts +0 -137
- package/src/bollharness-integration/guard-checker.ts +0 -451
- package/src/bollharness-integration/index.ts +0 -195
- package/src/bollharness-integration/integration.ts +0 -538
- package/src/bollharness-integration/judgment-prompts.yaml +0 -535
- package/src/bollharness-integration/llm-judgment-engine.ts +0 -712
- package/src/bollharness-integration/skill-adapter.ts +0 -646
- package/src/bootstrap/bootstrap.ts +0 -135
- package/src/bootstrap/context-collector.ts +0 -371
- package/src/bootstrap/context-hierarchy.ts +0 -283
- package/src/bootstrap/lifecycle-hooks.ts +0 -289
- package/src/bootstrap/project-context.ts +0 -171
- package/src/cli/interface.ts +0 -211
- package/src/cli-entry.ts +0 -304
- package/src/constraints/index.ts +0 -6
- package/src/context-compaction/auto-compact.ts +0 -153
- package/src/context-compaction/budget-gate.ts +0 -32
- package/src/context-compaction/budget-reduce.ts +0 -37
- package/src/context-compaction/context-collapse.ts +0 -72
- package/src/context-compaction/index.ts +0 -24
- package/src/context-compaction/microcompact.ts +0 -54
- package/src/context-compaction/pipeline.ts +0 -133
- package/src/context-compaction/snip.ts +0 -51
- package/src/context-compaction/token-estimator.ts +0 -36
- package/src/context-compaction/types.ts +0 -99
- package/src/documents/reader.ts +0 -85
- package/src/documents/store.ts +0 -252
- package/src/electron-preload.ts +0 -25
- package/src/electron.ts +0 -200
- package/src/heartbeat/DaemonManager.ts +0 -283
- package/src/heartbeat/HealthMonitor.ts +0 -317
- package/src/heartbeat/StartupVerifier.ts +0 -223
- package/src/heartbeat/Watchdog.ts +0 -208
- package/src/heartbeat/index.ts +0 -109
- package/src/heartbeat/self-improve-bus.ts +0 -110
- package/src/heartbeat/types.ts +0 -82
- package/src/index.ts +0 -1724
- package/src/llm/audio-config-store.ts +0 -246
- package/src/llm/config-store.ts +0 -400
- package/src/llm/llm-judgment-client.ts +0 -471
- package/src/llm/pi-ai.ts +0 -653
- package/src/llm/system-prompt/health.ts +0 -159
- package/src/llm/system-prompt/layers/channel/local.md +0 -14
- package/src/llm/system-prompt/layers/channel/p2p-agent.md +0 -18
- package/src/llm/system-prompt/layers/channel/p2p-visitor.md +0 -19
- package/src/llm/system-prompt/layers/core/artifacts_storage.md +0 -89
- package/src/llm/system-prompt/layers/core/evenhandedness.md +0 -21
- package/src/llm/system-prompt/layers/core/hibs_reminders.md +0 -15
- package/src/llm/system-prompt/layers/core/identity.md +0 -37
- package/src/llm/system-prompt/layers/core/knowledge.md +0 -17
- package/src/llm/system-prompt/layers/core/memory_system.md +0 -12
- package/src/llm/system-prompt/layers/core/network_filesystem.md +0 -28
- package/src/llm/system-prompt/layers/core/refusal.md +0 -37
- package/src/llm/system-prompt/layers/core/tone.md +0 -31
- package/src/llm/system-prompt/layers/core/tools.thin.md +0 -13
- package/src/llm/system-prompt/layers/core/wellbeing.md +0 -41
- package/src/llm/system-prompt/layers/role/architect.md +0 -20
- package/src/llm/system-prompt/layers/role/expert.md +0 -19
- package/src/llm/system-prompt/layers/role/implementer.md +0 -15
- package/src/llm/system-prompt/layers/role/security.md +0 -15
- package/src/llm/system-prompt/layers/tool/artifacts.md +0 -72
- package/src/llm/system-prompt/layers/tool/bash.md +0 -25
- package/src/llm/system-prompt/layers/tool/hibs_api.md +0 -171
- package/src/llm/system-prompt/layers/tool/image_search.md +0 -70
- package/src/llm/system-prompt/layers/tool/manifest.md +0 -89
- package/src/llm/system-prompt/layers/tool/mcp_apps.md +0 -53
- package/src/llm/system-prompt/layers/tool/web_search.md +0 -83
- package/src/llm/system-prompt/registry.ts +0 -325
- package/src/llm/system-prompt/strip-hibsml.ts +0 -52
- package/src/llm/tool-manifest/ask_user_input.ts +0 -37
- package/src/llm/tool-manifest/bash.ts +0 -25
- package/src/llm/tool-manifest/create_file.ts +0 -26
- package/src/llm/tool-manifest/fetch_sports_data.ts +0 -28
- package/src/llm/tool-manifest/image_search.ts +0 -26
- package/src/llm/tool-manifest/index.ts +0 -88
- package/src/llm/tool-manifest/mcp.ts +0 -46
- package/src/llm/tool-manifest/message_compose.ts +0 -33
- package/src/llm/tool-manifest/places.ts +0 -86
- package/src/llm/tool-manifest/present_files.ts +0 -23
- package/src/llm/tool-manifest/recipe.ts +0 -42
- package/src/llm/tool-manifest/recommend_apps.ts +0 -25
- package/src/llm/tool-manifest/str_replace.ts +0 -29
- package/src/llm/tool-manifest/types.ts +0 -52
- package/src/llm/tool-manifest/view.ts +0 -26
- package/src/llm/tool-manifest/weather.ts +0 -29
- package/src/llm/tool-manifest/web.ts +0 -54
- package/src/llm/video-config-store.ts +0 -257
- package/src/network/agent-network.ts +0 -800
- package/src/network/hybrid-messenger.ts +0 -199
- package/src/network/iroh-bootstrap.ts +0 -57
- package/src/network/iroh-discovery.ts +0 -208
- package/src/network/iroh-integration.ts +0 -158
- package/src/network/iroh-transport.ts +0 -637
- package/src/network/known-peers.ts +0 -102
- package/src/network/p2p-direct.ts +0 -262
- package/src/network/p2p-secret.ts +0 -153
- package/src/network/p2p.ts +0 -964
- package/src/network/source-intent-broadcaster.ts +0 -242
- package/src/network/source-intent.ts +0 -167
- package/src/network/storage/adapters/json-adapter.ts +0 -454
- package/src/network/storage/index.ts +0 -203
- package/src/network/storage/types.ts +0 -166
- package/src/security/builtin-guards.ts +0 -162
- package/src/security/context-router-tool.ts +0 -122
- package/src/security/input-scanner.ts +0 -287
- package/src/security/react-harness.ts +0 -177
- package/src/security/tool-gate.ts +0 -294
- package/src/social/ant-colony/index.js +0 -19
- package/src/social/channels/ChannelManager.ts +0 -485
- package/src/social/channels/DiapChannelBridge.ts +0 -501
- package/src/social/channels/InterestMatcher.ts +0 -189
- package/src/social/channels/agent-workflow-config.json +0 -214
- package/src/social/channels/agent-workflow-config.yaml +0 -334
- package/src/social/channels/channel-agent-session.ts +0 -407
- package/src/social/channels/channel-heartbeat-agent.ts +0 -622
- package/src/social/channels/diap-doc-parser.ts +0 -282
- package/src/social/channels/harness-workflow-integrator.ts +0 -594
- package/src/social/channels/index.ts +0 -22
- package/src/social/channels/types.ts +0 -115
- package/src/social/global-shared-context.ts +0 -506
- package/src/social/heartbeat.ts +0 -1057
- package/src/social/persona/enhanced-persona.ts +0 -359
- package/src/types.d.ts +0 -12
- package/src/utils/auto-evolve-policy.ts +0 -138
- package/src/utils/auto-update.ts +0 -482
- package/src/utils/clamp.ts +0 -5
- package/src/web/agent-delegate-server.ts +0 -148
- package/src/web/api-config.html +0 -520
- package/src/web/client.js +0 -2352
- package/src/web/client.ts +0 -4326
- package/src/web/components/p2p/P2PModal.tsx +0 -416
- package/src/web/components/p2p/index.ts +0 -566
- package/src/web/components/p2p/index.tsx +0 -297
- package/src/web/components/p2p/p2p-connection.ts +0 -338
- package/src/web/components/p2p/p2p-identity.ts +0 -92
- package/src/web/components/p2p/p2p-manager.ts +0 -147
- package/src/web/components/p2p/p2p-messages.ts +0 -219
- package/src/web/components/p2p/p2p-modal.ts +0 -685
- package/src/web/components/p2p/p2p-store-memory.ts +0 -162
- package/src/web/components/p2p/p2p-tools.ts +0 -315
- package/src/web/components/p2p/types.ts +0 -170
- package/src/web/components/wallet-viem.mjs +0 -118
- package/src/web/design.md +0 -99
- package/src/web/icons/apple-touch-icon.png +0 -0
- package/src/web/icons/favicon-16x16.png +0 -0
- package/src/web/icons/favicon-192x192.png +0 -0
- package/src/web/icons/favicon-32x32.png +0 -0
- package/src/web/icons/favicon-48x48.png +0 -0
- package/src/web/icons/favicon-512x512.png +0 -0
- package/src/web/icons/favicon.icns +0 -0
- package/src/web/icons/favicon.ico +0 -0
- package/src/web/icons/icon.png +0 -0
- package/src/web/icons/image.png +0 -0
- package/src/web/index.html +0 -373
- package/src/web/iroh-delegate-transport.ts +0 -139
- package/src/web/manifest.json +0 -21
- package/src/web/server.ts +0 -5731
- package/src/web/style.css +0 -4737
- package/src/web/ui/message-renderer.ts +0 -540
- package/src/web/ui/step-timeline.ts +0 -394
- package/staging/auto-evolve/clean-001/.review-verdict +0 -9
- package/staging/auto-evolve/clean-001/clean-001.patch +0 -14
- package/staging/auto-evolve/e2e-001/.patch-id +0 -1
- package/staging/auto-evolve/e2e-001/.review-verdict +0 -12
- package/staging/auto-evolve/e2e-001/e2e-001.patch +0 -11
- package/staging/auto-evolve/test-bad/.review-verdict +0 -12
- package/staging/auto-evolve/test-bad/test-bad.patch +0 -11
- package/test-results/.last-run.json +0 -6
- package/test-results/src-test-web-loop-status-b-5734c-atus-bar-/346/230/276/347/244/272-spinner-/344/270/215/346/230/276/347/244/272/345/276/252/347/216/257/350/256/241/346/225/260/error-context.md +0 -285
- package/tsconfig.cli.json +0 -16
- package/tsconfig.electron.json +0 -20
- package/tsconfig.json +0 -18
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context Hierarchy — 4 级 Bolloon.md 查找 + 合并优先级
|
|
3
|
-
*
|
|
4
|
-
* 设计: 严格对齐 Claude Code 论文 4 级层次
|
|
5
|
-
* 1. Managed — /etc/bolloon/Bolloon.md (企业 IT 部署, 系统级)
|
|
6
|
-
* 2. User — ~/.bolloon/Bolloon.md (用户级, 跨项目)
|
|
7
|
-
* 3. Project — <cwd>/Bolloon.md 或 .claude/rules/*.md
|
|
8
|
-
* 4. Local — <cwd>/CLAUDE.local.md (个人覆盖, .gitignore)
|
|
9
|
-
*
|
|
10
|
-
* 注入约定 (论文):
|
|
11
|
-
* - 拼到 system prompt 顶部 (作为 user context, 概率性遵守)
|
|
12
|
-
* - 不混入 user 消息 (避免 prompt injection)
|
|
13
|
-
* - 截断时反向砍 local → project → user → managed (优先保 managed, 因为是 bolloon 自身约束)
|
|
14
|
-
*
|
|
15
|
-
* 兼容:
|
|
16
|
-
* - 同时识别 Bolloon.md 和 Bolloon.md (论文用前者, bolloon 历史用后者)
|
|
17
|
-
* - 文件名按优先级: Bolloon.md > Bolloon.md
|
|
18
|
-
*
|
|
19
|
-
* 失败静默: 任何 IO 错误 → 返回 null, 不阻塞主流程.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
import * as fs from 'fs/promises';
|
|
23
|
-
import * as os from 'os';
|
|
24
|
-
import * as path from 'path';
|
|
25
|
-
|
|
26
|
-
// ============================================================
|
|
27
|
-
// 4 级路径配置
|
|
28
|
-
// ============================================================
|
|
29
|
-
|
|
30
|
-
export interface HierarchyPaths {
|
|
31
|
-
managed: string; // /etc/bolloon/Bolloon.md
|
|
32
|
-
user: string; // ~/.bolloon/Bolloon.md
|
|
33
|
-
project: string; // <cwd>/Bolloon.md
|
|
34
|
-
projectRulesDir: string; // <cwd>/.claude/rules/
|
|
35
|
-
local: string; // <cwd>/CLAUDE.local.md
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface HierarchyChars {
|
|
39
|
-
managed: number;
|
|
40
|
-
user: number;
|
|
41
|
-
project: number;
|
|
42
|
-
local: number;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface HierarchyLimits {
|
|
46
|
-
paths?: Partial<HierarchyPaths>;
|
|
47
|
-
maxChars?: Partial<HierarchyChars>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const DEFAULT_PATHS: HierarchyPaths = {
|
|
51
|
-
managed: '/etc/bolloon/Bolloon.md',
|
|
52
|
-
user: '', // 用 resolveUserPath 填
|
|
53
|
-
project: '', // 用 resolveProjectPaths 填
|
|
54
|
-
projectRulesDir: '',
|
|
55
|
-
local: '',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 单层字符上限 (P-Action 4 收紧, 阶段 0 把 4 级层次控制在 ≤ 2KB).
|
|
60
|
-
* 反向截断策略保证 managed 优先, 单层超限由 truncate() 截断.
|
|
61
|
-
*/
|
|
62
|
-
export const DEFAULT_MAX_CHARS: HierarchyChars = {
|
|
63
|
-
managed: 700, // 1500 → 700, 保 bolloon 自身约束
|
|
64
|
-
user: 500, // 1500 → 500, 跨项目偏好
|
|
65
|
-
project: 500, // 2500 → 500, 项目规则
|
|
66
|
-
local: 300, // 1500 → 300, 个人覆盖
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// ============================================================
|
|
70
|
-
// 路径解析
|
|
71
|
-
// ============================================================
|
|
72
|
-
|
|
73
|
-
export function resolveUserPath(home?: string): string {
|
|
74
|
-
const h = home ?? process.env.HOME ?? os.homedir() ?? '/tmp';
|
|
75
|
-
return path.join(h, '.bolloon', 'Bolloon.md');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function resolveProjectPaths(cwd: string): { project: string; projectRulesDir: string; local: string } {
|
|
79
|
-
return {
|
|
80
|
-
project: path.join(cwd, 'Bolloon.md'),
|
|
81
|
-
projectRulesDir: path.join(cwd, '.claude', 'rules'),
|
|
82
|
-
local: path.join(cwd, 'CLAUDE.local.md'),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// ============================================================
|
|
87
|
-
// 单层读取 (优先 Bolloon.md, fallback Bolloon.md)
|
|
88
|
-
// ============================================================
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 读 1 个文件路径, 失败/缺失返回 null.
|
|
92
|
-
* 字符上限由调用方截断 (这里只负责读全文).
|
|
93
|
-
*/
|
|
94
|
-
async function readRuleFile(filePath: string): Promise<string | null> {
|
|
95
|
-
try {
|
|
96
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
97
|
-
return content.length > 0 ? content : null;
|
|
98
|
-
} catch {
|
|
99
|
-
return null;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 读 project 层: 优先 Bolloon.md, fallback Bolloon.md, 最后尝试 .claude/rules/*.md
|
|
105
|
-
*/
|
|
106
|
-
async function readProjectLayer(projectPath: string, projectRulesDir: string, maxChars: number): Promise<string | null> {
|
|
107
|
-
// 1. Bolloon.md
|
|
108
|
-
let content = await readRuleFile(projectPath);
|
|
109
|
-
if (content) return truncate(content, maxChars);
|
|
110
|
-
|
|
111
|
-
// 2. Bolloon.md (向后兼容)
|
|
112
|
-
const bolloonMdPath = path.join(path.dirname(projectPath), 'Bolloon.md');
|
|
113
|
-
content = await readRuleFile(bolloonMdPath);
|
|
114
|
-
if (content) return truncate(content, maxChars);
|
|
115
|
-
|
|
116
|
-
// 3. .claude/rules/*.md (合并所有)
|
|
117
|
-
try {
|
|
118
|
-
const entries = await fs.readdir(projectRulesDir, { withFileTypes: true });
|
|
119
|
-
const ruleFiles = entries
|
|
120
|
-
.filter((e) => e.isFile() && e.name.endsWith('.md'))
|
|
121
|
-
.map((e) => path.join(projectRulesDir, e.name))
|
|
122
|
-
.sort();
|
|
123
|
-
if (ruleFiles.length > 0) {
|
|
124
|
-
const parts: string[] = [];
|
|
125
|
-
let total = 0;
|
|
126
|
-
for (const f of ruleFiles) {
|
|
127
|
-
const c = await readRuleFile(f);
|
|
128
|
-
if (c) {
|
|
129
|
-
parts.push(`### ${path.basename(f, '.md')}\n${c}`);
|
|
130
|
-
total += c.length;
|
|
131
|
-
if (total >= maxChars) break;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (parts.length > 0) return truncate(parts.join('\n\n'), maxChars);
|
|
135
|
-
}
|
|
136
|
-
} catch { /* dir 不存在 */ }
|
|
137
|
-
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ============================================================
|
|
142
|
-
// 4 层收集
|
|
143
|
-
// ============================================================
|
|
144
|
-
|
|
145
|
-
export interface HierarchyLayers {
|
|
146
|
-
managed: string | null; // /etc/bolloon/Bolloon.md
|
|
147
|
-
user: string | null; // ~/.bolloon/Bolloon.md
|
|
148
|
-
project: string | null; // <cwd>/Bolloon.md
|
|
149
|
-
local: string | null; // <cwd>/CLAUDE.local.md
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface CollectHierarchyOptions {
|
|
153
|
-
cwd: string;
|
|
154
|
-
limits?: HierarchyLimits;
|
|
155
|
-
/** 覆盖 HOME (测试用) */
|
|
156
|
-
home?: string;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* 并行读 4 层, 任何一层失败 = null (不阻塞其他).
|
|
161
|
-
*/
|
|
162
|
-
export async function collectHierarchyLayers(opts: CollectHierarchyOptions): Promise<HierarchyLayers> {
|
|
163
|
-
const limits: HierarchyLimits['maxChars'] = { ...DEFAULT_MAX_CHARS, ...(opts.limits?.maxChars ?? {}) };
|
|
164
|
-
|
|
165
|
-
const home = opts.home ?? process.env.HOME ?? os.homedir() ?? '/tmp';
|
|
166
|
-
const managedPath = opts.limits?.paths?.managed ?? DEFAULT_PATHS.managed;
|
|
167
|
-
const userPath = opts.limits?.paths?.user ?? resolveUserPath(home);
|
|
168
|
-
const projectPath = opts.limits?.paths?.project ?? path.join(opts.cwd, 'Bolloon.md');
|
|
169
|
-
const projectRulesDir = opts.limits?.paths?.projectRulesDir ?? path.join(opts.cwd, '.claude', 'rules');
|
|
170
|
-
const localPath = opts.limits?.paths?.local ?? path.join(opts.cwd, 'CLAUDE.local.md');
|
|
171
|
-
|
|
172
|
-
const [managed, user, project, local] = await Promise.all([
|
|
173
|
-
readRuleFile(managedPath).then((c) => c ? truncate(c, limits.managed!) : null),
|
|
174
|
-
readRuleFile(userPath).then((c) => c ? truncate(c, limits.user!) : null),
|
|
175
|
-
readProjectLayer(projectPath, projectRulesDir, limits.project!),
|
|
176
|
-
readRuleFile(localPath).then((c) => c ? truncate(c, limits.local!) : null),
|
|
177
|
-
]);
|
|
178
|
-
|
|
179
|
-
return { managed, user, project, local };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// ============================================================
|
|
183
|
-
// 合并 + 截断
|
|
184
|
-
// ============================================================
|
|
185
|
-
|
|
186
|
-
export interface MergeOptions {
|
|
187
|
-
/** 总字符上限 (默认 8000, 之前 project-context.ts 用 4000) */
|
|
188
|
-
maxChars?: number;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 4 级合并总字符上限 (P-Action 4 收紧, ≤ 2KB ≈ 500 tokens).
|
|
193
|
-
* 反向截断 (local → project → user → managed) 保证 managed 不丢.
|
|
194
|
-
*/
|
|
195
|
-
export const DEFAULT_MERGE_MAX_CHARS = 2000;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* 按 4 级顺序 (managed → user → project → local) 拼接为 markdown 片段.
|
|
199
|
-
*
|
|
200
|
-
* 截断策略: 反向砍 (local → project → user → managed), 优先保 managed.
|
|
201
|
-
* - 总长 < maxChars: 不截断
|
|
202
|
-
* - 总长 ≥ maxChars: 按 (local, project, user) 顺序逐步砍到 firstParagraphs=1
|
|
203
|
-
* - 最后只保 managed (bolloon 自身约束不能丢)
|
|
204
|
-
*/
|
|
205
|
-
export function mergeHierarchyLayers(layers: HierarchyLayers, opts: MergeOptions = {}): string {
|
|
206
|
-
const maxChars = opts.maxChars ?? DEFAULT_MERGE_MAX_CHARS;
|
|
207
|
-
const parts: string[] = [];
|
|
208
|
-
const labels: Array<[keyof HierarchyLayers, string]> = [
|
|
209
|
-
['managed', '管理规则 (Managed)'],
|
|
210
|
-
['user', '用户规则 (User)'],
|
|
211
|
-
['project', '项目规则 (Project)'],
|
|
212
|
-
['local', '本地规则 (Local)'],
|
|
213
|
-
];
|
|
214
|
-
|
|
215
|
-
for (const [key, label] of labels) {
|
|
216
|
-
const content = layers[key];
|
|
217
|
-
if (content) {
|
|
218
|
-
parts.push(`## ${label}\n\n${content}`);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (parts.length === 0) return '';
|
|
223
|
-
let result = parts.join('\n\n---\n\n');
|
|
224
|
-
if (result.length <= maxChars) return result;
|
|
225
|
-
|
|
226
|
-
// 超限: 反向砍 (local → project → user), 二级回退到 firstParagraphs=1
|
|
227
|
-
return truncateMerged(layers, maxChars);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function truncateMerged(layers: HierarchyLayers, maxChars: number): string {
|
|
231
|
-
const order: Array<[keyof HierarchyLayers, string]> = [
|
|
232
|
-
['local', '本地规则 (Local)'],
|
|
233
|
-
['project', '项目规则 (Project)'],
|
|
234
|
-
['user', '用户规则 (User)'],
|
|
235
|
-
['managed', '管理规则 (Managed)'],
|
|
236
|
-
];
|
|
237
|
-
const capped: HierarchyLayers = { ...layers };
|
|
238
|
-
// 反复压缩, 直到总长 ≤ maxChars
|
|
239
|
-
let depth = 0; // 0=原始, 1=firstParagraphs=1, 2=砍半
|
|
240
|
-
while (depth < 3) {
|
|
241
|
-
const parts: string[] = [];
|
|
242
|
-
for (const [key, label] of order) {
|
|
243
|
-
const c = capped[key];
|
|
244
|
-
if (!c) continue;
|
|
245
|
-
let text = c;
|
|
246
|
-
if (depth === 1) text = firstParagraphs(c, 1);
|
|
247
|
-
if (depth === 2) text = firstParagraphs(c, 1, Math.floor(maxChars / 4));
|
|
248
|
-
parts.push(`## ${label}\n\n${text}`);
|
|
249
|
-
}
|
|
250
|
-
const joined = parts.reverse().join('\n\n---\n\n'); // 恢复 managed → user → project → local
|
|
251
|
-
if (joined.length <= maxChars) return joined;
|
|
252
|
-
depth++;
|
|
253
|
-
}
|
|
254
|
-
// 最后保 managed 一行
|
|
255
|
-
return `## 管理规则 (Managed)\n\n${firstParagraphs(layers.managed ?? '(无)', 1, maxChars - 50)}`;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// ============================================================
|
|
259
|
-
// 工具
|
|
260
|
-
// ============================================================
|
|
261
|
-
|
|
262
|
-
function truncate(s: string, maxChars: number): string {
|
|
263
|
-
if (s.length <= maxChars) return s;
|
|
264
|
-
return s.substring(0, maxChars) + '\n... (truncated)';
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function firstParagraphs(text: string, count: number, maxLen?: number): string {
|
|
268
|
-
const paragraphs = text.split(/\n\s*\n/).filter((p) => p.trim().length > 0);
|
|
269
|
-
let result = paragraphs.slice(0, count).join('\n\n');
|
|
270
|
-
if (maxLen && result.length > maxLen) {
|
|
271
|
-
result = result.substring(0, maxLen) + '...';
|
|
272
|
-
}
|
|
273
|
-
return result;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// ============================================================
|
|
277
|
-
// 测试钩子
|
|
278
|
-
// ============================================================
|
|
279
|
-
|
|
280
|
-
/** 重置模块级状态 (供测试). 当前无状态, 保留为占位. */
|
|
281
|
-
export function _resetHierarchyForTest(): void {
|
|
282
|
-
// no-op (collect 是纯函数, 但保留 API 一致)
|
|
283
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lifecycle Hooks — SessionStart / Stop / PreToolUse
|
|
3
|
-
*
|
|
4
|
-
* 失败静默: 任意 hook 挂掉不抛错, 仅 console.warn.
|
|
5
|
-
* 任何调用方都可以放心 await, 不会阻塞主对话.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as fs from 'fs/promises';
|
|
9
|
-
import * as os from 'os';
|
|
10
|
-
import * as path from 'path';
|
|
11
|
-
import { getCachedBolloonContext, clearBolloonContextCache } from './context-collector.js';
|
|
12
|
-
import { formatContextForSystemPrompt } from './project-context.js';
|
|
13
|
-
|
|
14
|
-
// ============================================================
|
|
15
|
-
// SessionStart
|
|
16
|
-
// ============================================================
|
|
17
|
-
|
|
18
|
-
export interface SessionStartOptions {
|
|
19
|
-
/** channelId 暂时不传到 context (单 channel 维度, plan 范围) */
|
|
20
|
-
channelId?: string;
|
|
21
|
-
/** 工作目录, 默认 process.cwd() */
|
|
22
|
-
cwd?: string;
|
|
23
|
-
/** 强制重扫, 跳过 24h 缓存 */
|
|
24
|
-
force?: boolean;
|
|
25
|
-
/** system prompt 片段字符上限 */
|
|
26
|
-
maxChars?: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface SessionStartResult {
|
|
30
|
-
/** 拼到 system prompt 头部的 markdown 文本 */
|
|
31
|
-
systemAddition: string;
|
|
32
|
-
/** 收集耗时 ms */
|
|
33
|
-
collectMs: number;
|
|
34
|
-
/** 是否被截断 */
|
|
35
|
-
truncated: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
let lastSessionStartAt = 0;
|
|
39
|
-
const MIN_INTERVAL_MS = 5000; // 同一进程 5s 内最多触发一次, 防止循环
|
|
40
|
-
|
|
41
|
-
export async function onSessionStart(opts: SessionStartOptions = {}): Promise<SessionStartResult> {
|
|
42
|
-
const start = Date.now();
|
|
43
|
-
if (start - lastSessionStartAt < MIN_INTERVAL_MS) {
|
|
44
|
-
// 限流: 返回空 (调用方已经有缓存, 不需要重算)
|
|
45
|
-
return { systemAddition: '', collectMs: 0, truncated: false };
|
|
46
|
-
}
|
|
47
|
-
lastSessionStartAt = start;
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const ctx = await getCachedBolloonContext(
|
|
51
|
-
{ cwd: opts.cwd ?? process.cwd() },
|
|
52
|
-
opts.force ?? false
|
|
53
|
-
);
|
|
54
|
-
let systemAddition = formatContextForSystemPrompt(ctx, { maxChars: opts.maxChars });
|
|
55
|
-
// 在头部加 channel 标识 (供 LLM 知道当前对话归属)
|
|
56
|
-
if (opts.channelId) {
|
|
57
|
-
systemAddition = `# 当前 channel: ${opts.channelId}\n\n` + systemAddition;
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
systemAddition,
|
|
61
|
-
collectMs: Date.now() - start,
|
|
62
|
-
truncated: systemAddition.length > 0 && systemAddition.includes('截断模式'),
|
|
63
|
-
};
|
|
64
|
-
} catch (err) {
|
|
65
|
-
console.warn('[lifecycle-hooks] onSessionStart failed (silent):', err);
|
|
66
|
-
return { systemAddition: '', collectMs: Date.now() - start, truncated: false };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function clearSessionStartCache(): void {
|
|
71
|
-
lastSessionStartAt = 0;
|
|
72
|
-
clearBolloonContextCache();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ============================================================
|
|
76
|
-
// Stop
|
|
77
|
-
// ============================================================
|
|
78
|
-
|
|
79
|
-
export interface StopOptions {
|
|
80
|
-
channelId: string;
|
|
81
|
-
messages?: number;
|
|
82
|
-
durationMs: number;
|
|
83
|
-
/** 注入门使用过的 judgment ids (供审计) */
|
|
84
|
-
usedJudgmentIds?: string[];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export interface StopResult {
|
|
88
|
-
persisted: boolean;
|
|
89
|
-
path: string | null;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const STOP_LOG = (os.homedir() || process.env.HOME || '/tmp') + '/.bolloon/sessions';
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 把本次 session 摘要写 ~/.bolloon/sessions/<channelId>/last-stop.json
|
|
96
|
-
* 不重复写完整 session 持久化 (已由 createWebServer 内的 saveSession 处理)
|
|
97
|
-
*/
|
|
98
|
-
export async function onStop(opts: StopOptions): Promise<StopResult> {
|
|
99
|
-
try {
|
|
100
|
-
const dir = path.join(STOP_LOG, sanitizeChannelId(opts.channelId));
|
|
101
|
-
await fs.mkdir(dir, { recursive: true });
|
|
102
|
-
const file = path.join(dir, 'last-stop.json');
|
|
103
|
-
const entry = {
|
|
104
|
-
ts: new Date().toISOString(),
|
|
105
|
-
channelId: opts.channelId,
|
|
106
|
-
messages: opts.messages ?? 0,
|
|
107
|
-
durationMs: opts.durationMs,
|
|
108
|
-
usedJudgmentIds: opts.usedJudgmentIds ?? [],
|
|
109
|
-
};
|
|
110
|
-
await fs.writeFile(file, JSON.stringify(entry, null, 2), 'utf-8');
|
|
111
|
-
return { persisted: true, path: file };
|
|
112
|
-
} catch (err) {
|
|
113
|
-
console.warn('[lifecycle-hooks] onStop failed (silent):', err);
|
|
114
|
-
return { persisted: false, path: null };
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function sanitizeChannelId(id: string): string {
|
|
119
|
-
// 防止路径穿越
|
|
120
|
-
return id.replace(/[^a-zA-Z0-9_-]/g, '_').slice(0, 64);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// ============================================================
|
|
124
|
-
// PreToolUse (P2: 4 步链式 validator + permission mode)
|
|
125
|
-
// ============================================================
|
|
126
|
-
|
|
127
|
-
import { resolvePermissionMode, type PermissionMode } from '../agents/permission-mode.js';
|
|
128
|
-
import { validatePreToolUse } from '../agents/pre-tool-validator.js';
|
|
129
|
-
|
|
130
|
-
export interface PreToolUseOptions {
|
|
131
|
-
tool: string;
|
|
132
|
-
args: Record<string, unknown>;
|
|
133
|
-
/** 可选, 不传则用 env BOLLOON_PERM_MODE 或 default */
|
|
134
|
-
permissionMode?: PermissionMode;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface PreToolUseResult {
|
|
138
|
-
allowed: boolean;
|
|
139
|
-
reason?: string;
|
|
140
|
-
/** P2: 哪一步拒绝的, 供 audit log */
|
|
141
|
-
rejectedBy?: 'mode' | 'blacklist' | 'shell-guard' | 'schema';
|
|
142
|
-
mode: PermissionMode;
|
|
143
|
-
shellGuardRetained?: boolean;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* PreToolUse: 4 步链式 validator
|
|
148
|
-
* 1. modeGate (bypassPermissions + 非 shell 直接放行)
|
|
149
|
-
* 2. blacklistGate (6 模式危险命令)
|
|
150
|
-
* 3. shellGuardGate (路径黑名单, 绕过 mode 永远生效)
|
|
151
|
-
* 4. schemaGate (第一版 stub: always allow)
|
|
152
|
-
*
|
|
153
|
-
* 向后兼容: 不传 permissionMode → 默认 'default' (env BOLLOON_PERM_MODE 仍生效)
|
|
154
|
-
* 失败静默: 任何异常 → allowed: true (与原行为一致)
|
|
155
|
-
*/
|
|
156
|
-
export async function onPreToolUse(opts: PreToolUseOptions): Promise<PreToolUseResult> {
|
|
157
|
-
try {
|
|
158
|
-
const mode = resolvePermissionMode({ permissionMode: opts.permissionMode });
|
|
159
|
-
return validatePreToolUse(opts.tool, opts.args || {}, mode);
|
|
160
|
-
} catch (err) {
|
|
161
|
-
console.warn('[lifecycle-hooks] onPreToolUse failed (silent, allowing):', err);
|
|
162
|
-
return { allowed: true, mode: 'default' }; // 失败放行 (不阻塞)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// ============================================================
|
|
167
|
-
// 测试辅助: 获取 STOP_LOG 路径 (供测试覆盖路径)
|
|
168
|
-
// ============================================================
|
|
169
|
-
|
|
170
|
-
export function getStopLogPathForTest(): string {
|
|
171
|
-
return STOP_LOG;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// ============================================================
|
|
175
|
-
// PostToolUse (P+ : 工具调用后审计)
|
|
176
|
-
// ============================================================
|
|
177
|
-
|
|
178
|
-
export interface PostToolUseOptions {
|
|
179
|
-
tool: string;
|
|
180
|
-
args: Record<string, unknown>;
|
|
181
|
-
result: { success: boolean; output?: string; error?: string };
|
|
182
|
-
durationMs?: number;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export interface PostToolUseResult {
|
|
186
|
-
/** 是否允许继续 (false = abort 整个 ReAct 循环) */
|
|
187
|
-
continue: boolean;
|
|
188
|
-
reason?: string;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* PostToolUse: 工具调用后审计
|
|
193
|
-
* 默认 always continue. 项目可挂 shell-guard audit log / judgment 注入门 / 监控门
|
|
194
|
-
* 失败静默: 任何异常 → continue: true (不阻塞主循环)
|
|
195
|
-
*/
|
|
196
|
-
export async function onPostToolUse(opts: PostToolUseOptions): Promise<PostToolUseResult> {
|
|
197
|
-
try {
|
|
198
|
-
// 审计日志: 写 ~/.bolloon/sessions/post-tool-audit.jsonl
|
|
199
|
-
const fs = await import('fs/promises');
|
|
200
|
-
const os = await import('os');
|
|
201
|
-
const path = await import('path');
|
|
202
|
-
const file = path.join(
|
|
203
|
-
process.env.HOME || os.homedir() || '/tmp',
|
|
204
|
-
'.bolloon', 'sessions', 'post-tool-audit.jsonl'
|
|
205
|
-
);
|
|
206
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
207
|
-
const entry = {
|
|
208
|
-
ts: new Date().toISOString(),
|
|
209
|
-
tool: opts.tool,
|
|
210
|
-
success: opts.result.success,
|
|
211
|
-
durationMs: opts.durationMs ?? 0,
|
|
212
|
-
// 不写 args (可能含密钥), 只写 result 的 success/error
|
|
213
|
-
error: opts.result.error?.substring(0, 200) || null,
|
|
214
|
-
};
|
|
215
|
-
await fs.appendFile(file, JSON.stringify(entry) + '\n', 'utf-8').catch(() => { /* ignore */ });
|
|
216
|
-
return { continue: true };
|
|
217
|
-
} catch (err) {
|
|
218
|
-
console.warn('[lifecycle-hooks] onPostToolUse failed (silent, allowing):', err);
|
|
219
|
-
return { continue: true };
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// ============================================================
|
|
224
|
-
// JudgmentInjected (bolloon 独有 : 注入门使用时审计)
|
|
225
|
-
// ============================================================
|
|
226
|
-
|
|
227
|
-
export interface JudgmentInjectedOptions {
|
|
228
|
-
judgmentIds: string[];
|
|
229
|
-
channelId?: string;
|
|
230
|
-
userInput?: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export async function onJudgmentInjected(opts: JudgmentInjectedOptions): Promise<void> {
|
|
234
|
-
try {
|
|
235
|
-
const fs = await import('fs/promises');
|
|
236
|
-
const os = await import('os');
|
|
237
|
-
const path = await import('path');
|
|
238
|
-
const file = path.join(
|
|
239
|
-
process.env.HOME || os.homedir() || '/tmp',
|
|
240
|
-
'.bolloon', 'sessions', 'judgment-injected.jsonl'
|
|
241
|
-
);
|
|
242
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
243
|
-
const entry = {
|
|
244
|
-
ts: new Date().toISOString(),
|
|
245
|
-
channelId: opts.channelId || 'unknown',
|
|
246
|
-
judgmentIds: opts.judgmentIds,
|
|
247
|
-
userInputSnippet: (opts.userInput || '').substring(0, 200),
|
|
248
|
-
};
|
|
249
|
-
await fs.appendFile(file, JSON.stringify(entry) + '\n', 'utf-8').catch(() => { /* ignore */ });
|
|
250
|
-
} catch (err) {
|
|
251
|
-
console.warn('[lifecycle-hooks] onJudgmentInjected failed (silent):', err);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// ============================================================
|
|
256
|
-
// MonitorViolation (bolloon 独有 : 监控门审计违规)
|
|
257
|
-
// ============================================================
|
|
258
|
-
|
|
259
|
-
export interface MonitorViolationOptions {
|
|
260
|
-
channelId?: string;
|
|
261
|
-
judgmentId: string;
|
|
262
|
-
rule: string;
|
|
263
|
-
actualBehavior: string;
|
|
264
|
-
severity: 'low' | 'medium' | 'high';
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
export async function onMonitorViolation(opts: MonitorViolationOptions): Promise<void> {
|
|
268
|
-
try {
|
|
269
|
-
const fs = await import('fs/promises');
|
|
270
|
-
const os = await import('os');
|
|
271
|
-
const path = await import('path');
|
|
272
|
-
const file = path.join(
|
|
273
|
-
process.env.HOME || os.homedir() || '/tmp',
|
|
274
|
-
'.bolloon', 'sessions', 'monitor-violation.jsonl'
|
|
275
|
-
);
|
|
276
|
-
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
277
|
-
const entry = {
|
|
278
|
-
ts: new Date().toISOString(),
|
|
279
|
-
channelId: opts.channelId || 'unknown',
|
|
280
|
-
judgmentId: opts.judgmentId,
|
|
281
|
-
rule: opts.rule.substring(0, 200),
|
|
282
|
-
actualBehavior: opts.actualBehavior.substring(0, 200),
|
|
283
|
-
severity: opts.severity,
|
|
284
|
-
};
|
|
285
|
-
await fs.appendFile(file, JSON.stringify(entry) + '\n', 'utf-8').catch(() => { /* ignore */ });
|
|
286
|
-
} catch (err) {
|
|
287
|
-
console.warn('[lifecycle-hooks] onMonitorViolation failed (silent):', err);
|
|
288
|
-
}
|
|
289
|
-
}
|