@bolloon/bolloon-agent 0.4.28 → 0.4.30
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/bin/bolloon.cjs +18 -148
- package/bin/bolloon.cmd +6 -3
- package/dist/agents/contacts/chain.js +579 -0
- package/dist/agents/contacts/cli.js +158 -0
- package/dist/agents/contacts/consent.js +124 -0
- package/dist/agents/contacts/grant-payload.js +45 -0
- package/dist/agents/contacts/grants.js +451 -0
- package/dist/agents/contacts/policy.js +264 -0
- package/dist/agents/contacts/preview-types.js +6 -0
- package/dist/agents/contacts/providers.js +341 -0
- package/dist/agents/contacts/store.js +326 -0
- package/dist/agents/contacts/tools.js +154 -0
- package/dist/agents/contacts/types.js +148 -0
- package/dist/agents/pi-sdk-tools.js +3 -1
- package/dist/agents/pi-sdk.js +14 -1
- package/dist/cli/update-commands.js +349 -0
- package/dist/cli-entry.js +41 -55
- package/dist/electron-build/agents/agent-gateway.js +169 -0
- package/dist/electron-build/agents/agent-gateway.js.map +1 -0
- package/dist/electron-build/agents/agent-identity-store.js +212 -0
- package/dist/electron-build/agents/agent-identity-store.js.map +1 -0
- package/dist/electron-build/agents/agent-identity.js +196 -0
- package/dist/electron-build/agents/agent-identity.js.map +1 -0
- package/dist/electron-build/agents/agent-manifest-protocol.js +151 -0
- package/dist/electron-build/agents/agent-manifest-protocol.js.map +1 -0
- package/dist/electron-build/agents/agent-registry.js +217 -0
- package/dist/electron-build/agents/agent-registry.js.map +1 -0
- package/dist/electron-build/agents/agent-reputation.js +60 -0
- package/dist/electron-build/agents/agent-reputation.js.map +1 -0
- package/dist/electron-build/agents/agent-service-client.js +186 -0
- package/dist/electron-build/agents/agent-service-client.js.map +1 -0
- package/dist/electron-build/agents/browser-cdp.js +765 -0
- package/dist/electron-build/agents/browser-cdp.js.map +1 -0
- package/dist/electron-build/agents/computer-use.js +341 -0
- package/dist/electron-build/agents/computer-use.js.map +1 -0
- package/dist/electron-build/agents/constraint-layer.js +210 -0
- package/dist/electron-build/agents/constraint-layer.js.map +1 -0
- package/dist/electron-build/agents/contacts/chain.js +619 -0
- package/dist/electron-build/agents/contacts/chain.js.map +1 -0
- package/dist/electron-build/agents/contacts/consent.js +163 -0
- package/dist/electron-build/agents/contacts/consent.js.map +1 -0
- package/dist/electron-build/agents/contacts/grant-payload.js +52 -0
- package/dist/electron-build/agents/contacts/grant-payload.js.map +1 -0
- package/dist/electron-build/agents/contacts/grants.js +500 -0
- package/dist/electron-build/agents/contacts/grants.js.map +1 -0
- package/dist/electron-build/agents/contacts/policy.js +271 -0
- package/dist/electron-build/agents/contacts/policy.js.map +1 -0
- package/dist/electron-build/agents/contacts/preview-types.js +8 -0
- package/dist/electron-build/agents/contacts/preview-types.js.map +1 -0
- package/dist/electron-build/agents/contacts/providers.js +384 -0
- package/dist/electron-build/agents/contacts/providers.js.map +1 -0
- package/dist/electron-build/agents/contacts/store.js +370 -0
- package/dist/electron-build/agents/contacts/store.js.map +1 -0
- package/dist/electron-build/agents/contacts/tools.js +159 -0
- package/dist/electron-build/agents/contacts/tools.js.map +1 -0
- package/dist/electron-build/agents/contacts/types.js +166 -0
- package/dist/electron-build/agents/contacts/types.js.map +1 -0
- package/dist/electron-build/agents/decision-store.js +292 -0
- package/dist/electron-build/agents/decision-store.js.map +1 -0
- package/dist/electron-build/agents/deny-pipeline.js +125 -0
- package/dist/electron-build/agents/deny-pipeline.js.map +1 -0
- package/dist/electron-build/agents/economic-policy.js +172 -0
- package/dist/electron-build/agents/economic-policy.js.map +1 -0
- package/dist/electron-build/agents/error-classifier.js +125 -0
- package/dist/electron-build/agents/error-classifier.js.map +1 -0
- package/dist/electron-build/agents/execution-supervisor.js +539 -0
- package/dist/electron-build/agents/execution-supervisor.js.map +1 -0
- package/dist/electron-build/agents/external-events.js +171 -0
- package/dist/electron-build/agents/external-events.js.map +1 -0
- package/dist/electron-build/agents/gateway-join.js +315 -0
- package/dist/electron-build/agents/gateway-join.js.map +1 -0
- package/dist/electron-build/agents/gateway-network.js +505 -0
- package/dist/electron-build/agents/gateway-network.js.map +1 -0
- package/dist/electron-build/agents/goal-criteria.js +133 -0
- package/dist/electron-build/agents/goal-criteria.js.map +1 -0
- package/dist/electron-build/agents/goal-resume.js +364 -0
- package/dist/electron-build/agents/goal-resume.js.map +1 -0
- package/dist/electron-build/agents/goal-store.js +587 -0
- package/dist/electron-build/agents/goal-store.js.map +1 -0
- package/dist/electron-build/agents/intent-classifier.js +104 -0
- package/dist/electron-build/agents/intent-classifier.js.map +1 -0
- package/dist/electron-build/agents/iroh-secret.js +70 -0
- package/dist/electron-build/agents/iroh-secret.js.map +1 -0
- package/dist/electron-build/agents/loop-review.js +101 -0
- package/dist/electron-build/agents/loop-review.js.map +1 -0
- package/dist/electron-build/agents/memory-recall.js +154 -0
- package/dist/electron-build/agents/memory-recall.js.map +1 -0
- package/dist/electron-build/agents/p2p-document-tools.js +328 -0
- package/dist/electron-build/agents/p2p-document-tools.js.map +1 -0
- package/dist/electron-build/agents/parse-tool-call.js +564 -0
- package/dist/electron-build/agents/parse-tool-call.js.map +1 -0
- package/dist/electron-build/agents/patch-tool.js +205 -0
- package/dist/electron-build/agents/patch-tool.js.map +1 -0
- package/dist/electron-build/agents/payment-approval.js +183 -0
- package/dist/electron-build/agents/payment-approval.js.map +1 -0
- package/dist/electron-build/agents/payment-gate.js +139 -0
- package/dist/electron-build/agents/payment-gate.js.map +1 -0
- package/dist/electron-build/agents/permission-mode.js +124 -0
- package/dist/electron-build/agents/permission-mode.js.map +1 -0
- package/dist/electron-build/agents/pi-harness.js +268 -0
- package/dist/electron-build/agents/pi-harness.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-session-factory.js +117 -0
- package/dist/electron-build/agents/pi-sdk-session-factory.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-session-manager.js +335 -0
- package/dist/electron-build/agents/pi-sdk-session-manager.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-tools.js +4042 -0
- package/dist/electron-build/agents/pi-sdk-tools.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk-types.js +17 -0
- package/dist/electron-build/agents/pi-sdk-types.js.map +1 -0
- package/dist/electron-build/agents/pi-sdk.js +3335 -0
- package/dist/electron-build/agents/pi-sdk.js.map +1 -0
- package/dist/electron-build/agents/plan-store.js +212 -0
- package/dist/electron-build/agents/plan-store.js.map +1 -0
- package/dist/electron-build/agents/pre-tool-validator.js +200 -0
- package/dist/electron-build/agents/pre-tool-validator.js.map +1 -0
- package/dist/electron-build/agents/process-runner.js +148 -0
- package/dist/electron-build/agents/process-runner.js.map +1 -0
- package/dist/electron-build/agents/react-loop.js +131 -0
- package/dist/electron-build/agents/react-loop.js.map +1 -0
- package/dist/electron-build/agents/resource-store.js +180 -0
- package/dist/electron-build/agents/resource-store.js.map +1 -0
- package/dist/electron-build/agents/resource-token.js +118 -0
- package/dist/electron-build/agents/resource-token.js.map +1 -0
- package/dist/electron-build/agents/resource-wallet.js +84 -0
- package/dist/electron-build/agents/resource-wallet.js.map +1 -0
- package/dist/electron-build/agents/run-store.js +854 -0
- package/dist/electron-build/agents/run-store.js.map +1 -0
- package/dist/electron-build/agents/runner-resolver.js +267 -0
- package/dist/electron-build/agents/runner-resolver.js.map +1 -0
- package/dist/electron-build/agents/session-store.js +294 -0
- package/dist/electron-build/agents/session-store.js.map +1 -0
- package/dist/electron-build/agents/shell-guard.js +465 -0
- package/dist/electron-build/agents/shell-guard.js.map +1 -0
- package/dist/electron-build/agents/shell-tool.js +102 -0
- package/dist/electron-build/agents/shell-tool.js.map +1 -0
- package/dist/electron-build/agents/skill-loader.js +216 -0
- package/dist/electron-build/agents/skill-loader.js.map +1 -0
- package/dist/electron-build/agents/skill-readiness.js +174 -0
- package/dist/electron-build/agents/skill-readiness.js.map +1 -0
- package/dist/electron-build/agents/skill-share.js +394 -0
- package/dist/electron-build/agents/skill-share.js.map +1 -0
- package/dist/electron-build/agents/skill-supervisor-link.js +75 -0
- package/dist/electron-build/agents/skill-supervisor-link.js.map +1 -0
- package/dist/electron-build/agents/skill-writer.js +347 -0
- package/dist/electron-build/agents/skill-writer.js.map +1 -0
- package/dist/electron-build/agents/skills-manager.js +763 -0
- package/dist/electron-build/agents/skills-manager.js.map +1 -0
- package/dist/electron-build/agents/supervisor-host.js +294 -0
- package/dist/electron-build/agents/supervisor-host.js.map +1 -0
- package/dist/electron-build/agents/task/local-seller.js +188 -0
- package/dist/electron-build/agents/task/local-seller.js.map +1 -0
- package/dist/electron-build/agents/task/report-card.js +152 -0
- package/dist/electron-build/agents/task/report-card.js.map +1 -0
- package/dist/electron-build/agents/task/resource-advisor.js +222 -0
- package/dist/electron-build/agents/task/resource-advisor.js.map +1 -0
- package/dist/electron-build/agents/task/task-budget.js +111 -0
- package/dist/electron-build/agents/task/task-budget.js.map +1 -0
- package/dist/electron-build/agents/task/task-runner.js +670 -0
- package/dist/electron-build/agents/task/task-runner.js.map +1 -0
- package/dist/electron-build/agents/task-state.js +266 -0
- package/dist/electron-build/agents/task-state.js.map +1 -0
- package/dist/electron-build/agents/tool-registry.js +141 -0
- package/dist/electron-build/agents/tool-registry.js.map +1 -0
- package/dist/electron-build/agents/treasury-bridge.js +165 -0
- package/dist/electron-build/agents/treasury-bridge.js.map +1 -0
- package/dist/electron-build/agents/user-questions.js +223 -0
- package/dist/electron-build/agents/user-questions.js.map +1 -0
- package/dist/electron-build/agents/verify-recipe.js +90 -0
- package/dist/electron-build/agents/verify-recipe.js.map +1 -0
- package/dist/electron-build/agents/workflow-engine.js +222 -0
- package/dist/electron-build/agents/workflow-engine.js.map +1 -0
- package/dist/electron-build/agents/workflow-pivot-loop.js +988 -0
- package/dist/electron-build/agents/workflow-pivot-loop.js.map +1 -0
- package/dist/electron-build/agents/write-staging.js +133 -0
- package/dist/electron-build/agents/write-staging.js.map +1 -0
- package/dist/electron-build/agents/x402/goal-run-bridge.js +115 -0
- package/dist/electron-build/agents/x402/goal-run-bridge.js.map +1 -0
- package/dist/electron-build/agents/x402/milestone-settlement.js +163 -0
- package/dist/electron-build/agents/x402/milestone-settlement.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-protocol.js +274 -0
- package/dist/electron-build/agents/x402/paid-info-protocol.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-store.js +409 -0
- package/dist/electron-build/agents/x402/paid-info-store.js.map +1 -0
- package/dist/electron-build/agents/x402/paid-info-tools.js +346 -0
- package/dist/electron-build/agents/x402/paid-info-tools.js.map +1 -0
- package/dist/electron-build/agents/x402/payment-recovery.js +330 -0
- package/dist/electron-build/agents/x402/payment-recovery.js.map +1 -0
- package/dist/electron-build/agents/x402/resource-contract.js +533 -0
- package/dist/electron-build/agents/x402/resource-contract.js.map +1 -0
- package/dist/electron-build/agents/x402/settlement-state.js +432 -0
- package/dist/electron-build/agents/x402/settlement-state.js.map +1 -0
- package/dist/electron-build/agents/x402/trade.js +294 -0
- package/dist/electron-build/agents/x402/trade.js.map +1 -0
- package/dist/electron-build/agents/x402/transaction-protocol.js +109 -0
- package/dist/electron-build/agents/x402/transaction-protocol.js.map +1 -0
- package/dist/electron-build/agents/x402/transaction-store.js +404 -0
- package/dist/electron-build/agents/x402/transaction-store.js.map +1 -0
- package/dist/electron-build/agents/x402/x402Pay.js +377 -0
- package/dist/electron-build/agents/x402/x402Pay.js.map +1 -0
- package/dist/electron-build/bollharness-integration/context-router-judgment.js +269 -0
- package/dist/electron-build/bollharness-integration/context-router-judgment.js.map +1 -0
- package/dist/electron-build/bollharness-integration/context-router.js +584 -0
- package/dist/electron-build/bollharness-integration/context-router.js.map +1 -0
- package/dist/electron-build/bollharness-integration/gate-state-machine.js +362 -0
- package/dist/electron-build/bollharness-integration/gate-state-machine.js.map +1 -0
- package/dist/electron-build/bollharness-integration/gate-transition-hooks.js +136 -0
- package/dist/electron-build/bollharness-integration/gate-transition-hooks.js.map +1 -0
- package/dist/electron-build/bollharness-integration/guard-checker.js +400 -0
- package/dist/electron-build/bollharness-integration/guard-checker.js.map +1 -0
- package/dist/electron-build/bollharness-integration/index.js +123 -0
- package/dist/electron-build/bollharness-integration/index.js.map +1 -0
- package/dist/electron-build/bollharness-integration/integration.js +531 -0
- package/dist/electron-build/bollharness-integration/integration.js.map +1 -0
- package/dist/electron-build/bollharness-integration/skill-adapter.js +608 -0
- package/dist/electron-build/bollharness-integration/skill-adapter.js.map +1 -0
- package/dist/electron-build/bootstrap/bootstrap.js +173 -0
- package/dist/electron-build/bootstrap/bootstrap.js.map +1 -0
- package/dist/electron-build/bootstrap/context-collector.js +358 -0
- package/dist/electron-build/bootstrap/context-collector.js.map +1 -0
- package/dist/electron-build/bootstrap/context-hierarchy.js +262 -0
- package/dist/electron-build/bootstrap/context-hierarchy.js.map +1 -0
- package/dist/electron-build/bootstrap/context-manager.js +211 -0
- package/dist/electron-build/bootstrap/context-manager.js.map +1 -0
- package/dist/electron-build/bootstrap/context-os.js +277 -0
- package/dist/electron-build/bootstrap/context-os.js.map +1 -0
- package/dist/electron-build/bootstrap/event-log.js +203 -0
- package/dist/electron-build/bootstrap/event-log.js.map +1 -0
- package/dist/electron-build/bootstrap/exhaust-scrubber.js +277 -0
- package/dist/electron-build/bootstrap/exhaust-scrubber.js.map +1 -0
- package/dist/electron-build/bootstrap/lifecycle-hooks.js +282 -0
- package/dist/electron-build/bootstrap/lifecycle-hooks.js.map +1 -0
- package/dist/electron-build/bootstrap/memory-compressor.js +377 -0
- package/dist/electron-build/bootstrap/memory-compressor.js.map +1 -0
- package/dist/electron-build/bootstrap/persona-loader.js +219 -0
- package/dist/electron-build/bootstrap/persona-loader.js.map +1 -0
- package/dist/electron-build/bootstrap/project-context.js +162 -0
- package/dist/electron-build/bootstrap/project-context.js.map +1 -0
- package/dist/electron-build/bootstrap/project-state.js +205 -0
- package/dist/electron-build/bootstrap/project-state.js.map +1 -0
- package/dist/electron-build/bootstrap/session-window.js +162 -0
- package/dist/electron-build/bootstrap/session-window.js.map +1 -0
- package/dist/electron-build/bootstrap/vector-index.js +291 -0
- package/dist/electron-build/bootstrap/vector-index.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js +22 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/cancelOrder.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/clobShared.js +86 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/clobShared.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/createOrder.js +37 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/createOrder.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getMarket.js +20 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getMarket.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getOrders.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/getOrders.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js +28 -0
- package/dist/electron-build/constraint-runtime/src/tools/PolymarketSDK/listMarkets.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/SafeSDK/deploySafe.js +10 -0
- package/dist/electron-build/constraint-runtime/src/tools/SafeSDK/deploySafe.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/autoPay.js +68 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/autoPay.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/createWallet.js +14 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/createWallet.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/getBalance.js +17 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/getBalance.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/importWallet.js +59 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/importWallet.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/sendTransaction.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/sendTransaction.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/signMessage.js +14 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/signMessage.js.map +1 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/transferToken.js +29 -0
- package/dist/electron-build/constraint-runtime/src/tools/WalletTools/transferToken.js.map +1 -0
- package/dist/electron-build/constraints/index.js +11 -0
- package/dist/electron-build/constraints/index.js.map +1 -0
- package/dist/electron-build/context-compaction/auto-compact.js +182 -0
- package/dist/electron-build/context-compaction/auto-compact.js.map +1 -0
- package/dist/electron-build/context-compaction/budget-gate.js +32 -0
- package/dist/electron-build/context-compaction/budget-gate.js.map +1 -0
- package/dist/electron-build/context-compaction/budget-reduce.js +39 -0
- package/dist/electron-build/context-compaction/budget-reduce.js.map +1 -0
- package/dist/electron-build/context-compaction/context-collapse.js +71 -0
- package/dist/electron-build/context-compaction/context-collapse.js.map +1 -0
- package/dist/electron-build/context-compaction/index.js +38 -0
- package/dist/electron-build/context-compaction/index.js.map +1 -0
- package/dist/electron-build/context-compaction/microcompact.js +55 -0
- package/dist/electron-build/context-compaction/microcompact.js.map +1 -0
- package/dist/electron-build/context-compaction/pipeline.js +128 -0
- package/dist/electron-build/context-compaction/pipeline.js.map +1 -0
- package/dist/electron-build/context-compaction/snip.js +50 -0
- package/dist/electron-build/context-compaction/snip.js.map +1 -0
- package/dist/electron-build/context-compaction/token-estimator.js +40 -0
- package/dist/electron-build/context-compaction/token-estimator.js.map +1 -0
- package/dist/electron-build/context-compaction/types.js +21 -0
- package/dist/electron-build/context-compaction/types.js.map +1 -0
- package/dist/electron-build/cron/tick-lock.js +247 -0
- package/dist/electron-build/cron/tick-lock.js.map +1 -0
- package/dist/electron-build/documents/reader.js +131 -0
- package/dist/electron-build/documents/reader.js.map +1 -0
- package/dist/electron-build/documents/store.js +220 -0
- package/dist/electron-build/documents/store.js.map +1 -0
- package/dist/electron-build/external-engines/delegate-handle.js +76 -0
- package/dist/electron-build/external-engines/delegate-handle.js.map +1 -0
- package/dist/electron-build/external-engines/delegate.js +225 -0
- package/dist/electron-build/external-engines/delegate.js.map +1 -0
- package/dist/electron-build/external-engines/discovery.js +448 -0
- package/dist/electron-build/external-engines/discovery.js.map +1 -0
- package/dist/electron-build/external-engines/types.js +13 -0
- package/dist/electron-build/external-engines/types.js.map +1 -0
- package/dist/electron-build/hooks/hooks-engine.js +367 -0
- package/dist/electron-build/hooks/hooks-engine.js.map +1 -0
- package/dist/electron-build/judgeness/reflect.js +100 -0
- package/dist/electron-build/judgeness/reflect.js.map +1 -0
- package/dist/electron-build/judgeness/store.js +536 -0
- package/dist/electron-build/judgeness/store.js.map +1 -0
- package/dist/electron-build/judgeness/types.js +21 -0
- package/dist/electron-build/judgeness/types.js.map +1 -0
- package/dist/electron-build/llm/config-store.js +551 -0
- package/dist/electron-build/llm/config-store.js.map +1 -0
- package/dist/electron-build/llm/error-lessons.js +76 -0
- package/dist/electron-build/llm/error-lessons.js.map +1 -0
- package/dist/electron-build/llm/pi-ai.js +830 -0
- package/dist/electron-build/llm/pi-ai.js.map +1 -0
- package/dist/electron-build/llm/system-prompt/registry.js +318 -0
- package/dist/electron-build/llm/system-prompt/registry.js.map +1 -0
- package/dist/electron-build/llm/system-prompt/strip-hibsml.js +55 -0
- package/dist/electron-build/llm/system-prompt/strip-hibsml.js.map +1 -0
- package/dist/electron-build/locales/en.js +32 -0
- package/dist/electron-build/locales/en.js.map +1 -0
- package/dist/electron-build/locales/zh.js +30 -0
- package/dist/electron-build/locales/zh.js.map +1 -0
- package/dist/electron-build/lsp/lsp-manager.js +327 -0
- package/dist/electron-build/lsp/lsp-manager.js.map +1 -0
- package/dist/electron-build/lsp/lsp-tools.js +226 -0
- package/dist/electron-build/lsp/lsp-tools.js.map +1 -0
- package/dist/electron-build/migration/external-agent-migrator.js +451 -0
- package/dist/electron-build/migration/external-agent-migrator.js.map +1 -0
- package/dist/electron-build/network/agent-network.js +775 -0
- package/dist/electron-build/network/agent-network.js.map +1 -0
- package/dist/electron-build/network/goal-event-bridge.js +62 -0
- package/dist/electron-build/network/goal-event-bridge.js.map +1 -0
- package/dist/electron-build/network/iroh-integration.js +117 -0
- package/dist/electron-build/network/iroh-integration.js.map +1 -0
- package/dist/electron-build/network/iroh-transport.js +550 -0
- package/dist/electron-build/network/iroh-transport.js.map +1 -0
- package/dist/electron-build/network/p2p.js +1103 -0
- package/dist/electron-build/network/p2p.js.map +1 -0
- package/dist/electron-build/network/storage/adapters/json-adapter.js +416 -0
- package/dist/electron-build/network/storage/adapters/json-adapter.js.map +1 -0
- package/dist/electron-build/network/storage/types.js +18 -0
- package/dist/electron-build/network/storage/types.js.map +1 -0
- package/dist/electron-build/orbitdb/agent-tools.js +402 -0
- package/dist/electron-build/orbitdb/agent-tools.js.map +1 -0
- package/dist/electron-build/orbitdb/cid-database.js +284 -0
- package/dist/electron-build/orbitdb/cid-database.js.map +1 -0
- package/dist/electron-build/orbitdb/context-store.js +99 -0
- package/dist/electron-build/orbitdb/context-store.js.map +1 -0
- package/dist/electron-build/orbitdb/ipfs-node.js +120 -0
- package/dist/electron-build/orbitdb/ipfs-node.js.map +1 -0
- package/dist/electron-build/orbitdb/kanban-store.js +299 -0
- package/dist/electron-build/orbitdb/kanban-store.js.map +1 -0
- package/dist/electron-build/orbitdb/task-store.js +155 -0
- package/dist/electron-build/orbitdb/task-store.js.map +1 -0
- package/dist/electron-build/orbitdb/trajectory-store.js +194 -0
- package/dist/electron-build/orbitdb/trajectory-store.js.map +1 -0
- package/dist/electron-build/orbitdb/ui-cid.js +77 -0
- package/dist/electron-build/orbitdb/ui-cid.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-a2ui/index.js +89 -0
- package/dist/electron-build/pi-ecosystem-a2ui/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-goals/index.js +512 -0
- package/dist/electron-build/pi-ecosystem-goals/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/adaptive-scan.js +325 -0
- package/dist/electron-build/pi-ecosystem-judgment/adaptive-scan.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/causal-judge.js +492 -0
- package/dist/electron-build/pi-ecosystem-judgment/causal-judge.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/cleanup.js +167 -0
- package/dist/electron-build/pi-ecosystem-judgment/cleanup.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/decision.js +321 -0
- package/dist/electron-build/pi-ecosystem-judgment/decision.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/detect-hook.js +175 -0
- package/dist/electron-build/pi-ecosystem-judgment/detect-hook.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/distill-prompt.js +232 -0
- package/dist/electron-build/pi-ecosystem-judgment/distill-prompt.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/distillation.js +304 -0
- package/dist/electron-build/pi-ecosystem-judgment/distillation.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/evolve-judgment.js +176 -0
- package/dist/electron-build/pi-ecosystem-judgment/evolve-judgment.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-pipeline.js +65 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-pipeline.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-store.js +808 -0
- package/dist/electron-build/pi-ecosystem-judgment/human-value-store.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/index.js +508 -0
- package/dist/electron-build/pi-ecosystem-judgment/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/injection-gate.js +334 -0
- package/dist/electron-build/pi-ecosystem-judgment/injection-gate.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/monitor-gate.js +228 -0
- package/dist/electron-build/pi-ecosystem-judgment/monitor-gate.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-judgment/value-injection.js +598 -0
- package/dist/electron-build/pi-ecosystem-judgment/value-injection.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-mcp/index.js +643 -0
- package/dist/electron-build/pi-ecosystem-mcp/index.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-mcp/ui-tools.js +116 -0
- package/dist/electron-build/pi-ecosystem-mcp/ui-tools.js.map +1 -0
- package/dist/electron-build/pi-ecosystem-subagents/index.js +352 -0
- package/dist/electron-build/pi-ecosystem-subagents/index.js.map +1 -0
- package/dist/electron-build/security/builtin-guards.js +133 -0
- package/dist/electron-build/security/builtin-guards.js.map +1 -0
- package/dist/electron-build/security/context-router-tool.js +111 -0
- package/dist/electron-build/security/context-router-tool.js.map +1 -0
- package/dist/electron-build/security/input-scanner.js +263 -0
- package/dist/electron-build/security/input-scanner.js.map +1 -0
- package/dist/electron-build/security/react-harness.js +148 -0
- package/dist/electron-build/security/react-harness.js.map +1 -0
- package/dist/electron-build/security/tool-gate.js +291 -0
- package/dist/electron-build/security/tool-gate.js.map +1 -0
- package/dist/electron-build/setup/setup-store.js +648 -0
- package/dist/electron-build/setup/setup-store.js.map +1 -0
- package/dist/electron-build/social/channels/ChannelManager.js +444 -0
- package/dist/electron-build/social/channels/ChannelManager.js.map +1 -0
- package/dist/electron-build/social/channels/DiapChannelBridge.js +451 -0
- package/dist/electron-build/social/channels/DiapChannelBridge.js.map +1 -0
- package/dist/electron-build/social/channels/InterestMatcher.js +135 -0
- package/dist/electron-build/social/channels/InterestMatcher.js.map +1 -0
- package/dist/electron-build/social/channels/types.js +21 -0
- package/dist/electron-build/social/channels/types.js.map +1 -0
- package/dist/electron-build/social/global-shared-context.js +368 -0
- package/dist/electron-build/social/global-shared-context.js.map +1 -0
- package/dist/electron-build/social/heartbeat.js +882 -0
- package/dist/electron-build/social/heartbeat.js.map +1 -0
- package/dist/electron-build/storage/did-catalog-bridge.js +314 -0
- package/dist/electron-build/storage/did-catalog-bridge.js.map +1 -0
- package/dist/electron-build/storage/did-catalog.js +272 -0
- package/dist/electron-build/storage/did-catalog.js.map +1 -0
- package/dist/electron-build/utils/auto-update.js +140 -558
- package/dist/electron-build/utils/auto-update.js.map +1 -1
- package/dist/electron-build/utils/module-context.js +98 -0
- package/dist/electron-build/utils/module-context.js.map +1 -0
- package/dist/electron-build/utils/runtime-bootstrap.js +745 -0
- package/dist/electron-build/utils/runtime-bootstrap.js.map +1 -0
- package/dist/electron-build/utils/update-manager.js +770 -0
- package/dist/electron-build/utils/update-manager.js.map +1 -0
- package/dist/electron-build/utils/update-state.js +406 -0
- package/dist/electron-build/utils/update-state.js.map +1 -0
- package/dist/electron-build/utils/version-info.js +562 -0
- package/dist/electron-build/utils/version-info.js.map +1 -0
- package/dist/electron-build/web/i18n.js +146 -0
- package/dist/electron-build/web/i18n.js.map +1 -0
- package/dist/electron-build/web/routes-x402-info.js +232 -0
- package/dist/electron-build/web/routes-x402-info.js.map +1 -0
- package/dist/electron-build/web/server-storage.js +390 -0
- package/dist/electron-build/web/server-storage.js.map +1 -0
- package/dist/electron-build/web/server-types.js +52 -0
- package/dist/electron-build/web/server-types.js.map +1 -0
- package/dist/electron-build/web/task-deps.js +41 -0
- package/dist/electron-build/web/task-deps.js.map +1 -0
- package/dist/index.js +58 -27
- package/dist/llm/system-prompt/registry.js +6 -3
- package/dist/security/tool-gate.js +4 -0
- package/dist/utils/auto-update.js +138 -525
- package/dist/utils/module-context.js +59 -0
- package/dist/utils/runtime-bootstrap.js +682 -0
- package/dist/utils/update-cli.js +82 -0
- package/dist/utils/update-health.js +401 -0
- package/dist/utils/update-manager.js +716 -0
- package/dist/utils/update-state.js +353 -0
- package/dist/utils/version-info.js +510 -0
- package/dist/web/mobile-contacts.js +329 -0
- package/dist/web/mobile-core.js +481 -15
- package/dist/web/mobile.html +32 -0
- package/dist/web/mobile.js +139 -0
- package/dist/web/routes-contacts.js +420 -0
- package/dist/web/server.js +5 -0
- package/package.json +1 -1
- package/scripts/build-cli.js +32 -151
- package/scripts/postinstall.js +153 -76
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Human Value Store - 存储人类判断价值观的机制
|
|
4
|
+
*
|
|
5
|
+
* 核心概念:
|
|
6
|
+
* - 人类判断不是规则,而是价值观表达
|
|
7
|
+
* - 价值观通过具体决策体现,而非抽象陈述
|
|
8
|
+
* - 存储结构化的人类决策,用于价值注入
|
|
9
|
+
*
|
|
10
|
+
* 存储格式:
|
|
11
|
+
* - decision: 具体决策内容
|
|
12
|
+
* - reason: 决策理由(价值观体现)
|
|
13
|
+
* - context: 决策场景
|
|
14
|
+
* - outcome: 决策结果
|
|
15
|
+
* - values: 提取的价值观标签
|
|
16
|
+
*/
|
|
17
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(o, k2, desc);
|
|
24
|
+
}) : (function(o, m, k, k2) {
|
|
25
|
+
if (k2 === undefined) k2 = k;
|
|
26
|
+
o[k2] = m[k];
|
|
27
|
+
}));
|
|
28
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
+
}) : function(o, v) {
|
|
31
|
+
o["default"] = v;
|
|
32
|
+
});
|
|
33
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
34
|
+
var ownKeys = function(o) {
|
|
35
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
36
|
+
var ar = [];
|
|
37
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
38
|
+
return ar;
|
|
39
|
+
};
|
|
40
|
+
return ownKeys(o);
|
|
41
|
+
};
|
|
42
|
+
return function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
46
|
+
__setModuleDefault(result, mod);
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.DEFAULT_TTL_DAYS = void 0;
|
|
52
|
+
exports.initializeValueStore = initializeValueStore;
|
|
53
|
+
exports.migrateJudgmentInPlace = migrateJudgmentInPlace;
|
|
54
|
+
exports.migrateJudgmentImmutable = migrateJudgmentImmutable;
|
|
55
|
+
exports.storeHumanJudgment = storeHumanJudgment;
|
|
56
|
+
exports.learnFromTrajectory = learnFromTrajectory;
|
|
57
|
+
exports.learnFromFeedback = learnFromFeedback;
|
|
58
|
+
exports.learnFromCorrection = learnFromCorrection;
|
|
59
|
+
exports.updateJudgment = updateJudgment;
|
|
60
|
+
exports.listJudgmentsByStatus = listJudgmentsByStatus;
|
|
61
|
+
exports.hashDecision = hashDecision;
|
|
62
|
+
exports.findRecentSimilarDecisions = findRecentSimilarDecisions;
|
|
63
|
+
exports.batchUpdateJudgments = batchUpdateJudgments;
|
|
64
|
+
exports.updateJudgmentStatus = updateJudgmentStatus;
|
|
65
|
+
exports.deleteJudgment = deleteJudgment;
|
|
66
|
+
exports.loadAllJudgments = loadAllJudgments;
|
|
67
|
+
exports.getRelevantValues = getRelevantValues;
|
|
68
|
+
exports.getValueProfile = getValueProfile;
|
|
69
|
+
exports.getPriorityRules = getPriorityRules;
|
|
70
|
+
exports.getValueStats = getValueStats;
|
|
71
|
+
exports.clearCache = clearCache;
|
|
72
|
+
const fs = __importStar(require("fs/promises"));
|
|
73
|
+
const os = __importStar(require("os"));
|
|
74
|
+
const path = __importStar(require("path"));
|
|
75
|
+
const crypto_1 = require("crypto");
|
|
76
|
+
// 2026-07-06: 模块级 const 改成 getter 函数 — vitest 会预设 process.env.HOME 为真实 home,
|
|
77
|
+
// 在测试 beforeAll 修改 HOME 前已经捕获路径, 之前所有 test fixture 都污染 ~/.bolloon.
|
|
78
|
+
// 改成运行时 getter 才能正确响应 test override, 不再污染真实数据.
|
|
79
|
+
function getValueStoreDir() {
|
|
80
|
+
return path.join(process.env.HOME || os.homedir() || '/tmp', '.bolloon', 'human-values');
|
|
81
|
+
}
|
|
82
|
+
function getJudgmentsFile() {
|
|
83
|
+
return path.join(getValueStoreDir(), 'judgments.json');
|
|
84
|
+
}
|
|
85
|
+
function getProfileFile() {
|
|
86
|
+
return path.join(getValueStoreDir(), 'profile.json');
|
|
87
|
+
}
|
|
88
|
+
function getPatternsFile() {
|
|
89
|
+
return path.join(getValueStoreDir(), 'patterns.json');
|
|
90
|
+
}
|
|
91
|
+
function getCounterfactualFile() {
|
|
92
|
+
return path.join(getValueStoreDir(), 'counterfactual-audit.jsonl');
|
|
93
|
+
}
|
|
94
|
+
// In-memory cache
|
|
95
|
+
let judgmentCache = [];
|
|
96
|
+
let valueProfileCache = new Map();
|
|
97
|
+
let initialized = false;
|
|
98
|
+
function generateId() {
|
|
99
|
+
return `hv-${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
|
|
100
|
+
}
|
|
101
|
+
// ============================================================
|
|
102
|
+
// 存储操作
|
|
103
|
+
// ============================================================
|
|
104
|
+
/**
|
|
105
|
+
* 初始化存储(创建目录和空文件)
|
|
106
|
+
*/
|
|
107
|
+
async function initializeValueStore() {
|
|
108
|
+
if (initialized)
|
|
109
|
+
return;
|
|
110
|
+
try {
|
|
111
|
+
await fs.mkdir(getValueStoreDir(), { recursive: true });
|
|
112
|
+
try {
|
|
113
|
+
await fs.access(getJudgmentsFile());
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
await fs.writeFile(getJudgmentsFile(), JSON.stringify([], null, 2), 'utf-8');
|
|
117
|
+
}
|
|
118
|
+
initialized = true;
|
|
119
|
+
console.log('[HumanValueStore] Initialized at', getValueStoreDir());
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error('[HumanValueStore] Initialization failed:', error);
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// ============================================================
|
|
127
|
+
// 阶段 2: Causal-judge 4 字段 migration
|
|
128
|
+
// ============================================================
|
|
129
|
+
/** TTL 默认 90 天 (用户可在 createUI 显式覆盖) */
|
|
130
|
+
exports.DEFAULT_TTL_DAYS = 90;
|
|
131
|
+
/** 已 migration 标记 (避免每次 loadAllJudgments 都重写盘) */
|
|
132
|
+
let migratedOnce = false;
|
|
133
|
+
/**
|
|
134
|
+
* 给老数据补 4 字段默认值 (in-place).
|
|
135
|
+
* - expiresAt: createdAt + 90 天
|
|
136
|
+
* - appliesTo: undefined (适用所有)
|
|
137
|
+
* - conflictWith: []
|
|
138
|
+
* - causalChain: undefined
|
|
139
|
+
*
|
|
140
|
+
* 返回 true 表示这次实际有 migration (写盘时持久化), false 表示无变化
|
|
141
|
+
*/
|
|
142
|
+
function migrateJudgmentInPlace(j) {
|
|
143
|
+
let changed = false;
|
|
144
|
+
if (j.expiresAt === undefined) {
|
|
145
|
+
const base = new Date(j.timestamp || Date.now());
|
|
146
|
+
base.setDate(base.getDate() + exports.DEFAULT_TTL_DAYS);
|
|
147
|
+
j.expiresAt = base.toISOString();
|
|
148
|
+
changed = true;
|
|
149
|
+
}
|
|
150
|
+
if (j.conflictWith === undefined) {
|
|
151
|
+
j.conflictWith = [];
|
|
152
|
+
changed = true;
|
|
153
|
+
}
|
|
154
|
+
// appliesTo / causalChain 留空不补 (语义性, 由 causal-judge 自动填)
|
|
155
|
+
return changed;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* 不可变版本: 返回新对象, 不 mutate 原 j. 供测试/谨慎场景用.
|
|
159
|
+
*/
|
|
160
|
+
function migrateJudgmentImmutable(j) {
|
|
161
|
+
const next = { ...j };
|
|
162
|
+
migrateJudgmentInPlace(next);
|
|
163
|
+
return next;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 存储人类判断
|
|
167
|
+
*/
|
|
168
|
+
async function storeHumanJudgment(judgment) {
|
|
169
|
+
const now = new Date().toISOString();
|
|
170
|
+
// 阶段 2: 4 字段默认值补全 (新 judgment)
|
|
171
|
+
if (!judgment.expiresAt) {
|
|
172
|
+
const expireDate = new Date();
|
|
173
|
+
expireDate.setDate(expireDate.getDate() + exports.DEFAULT_TTL_DAYS);
|
|
174
|
+
judgment.expiresAt = expireDate.toISOString();
|
|
175
|
+
}
|
|
176
|
+
if (!Array.isArray(judgment.conflictWith)) {
|
|
177
|
+
judgment.conflictWith = [];
|
|
178
|
+
}
|
|
179
|
+
// 留空: appliesTo / causalChain 由后续 causal-judge 自动填
|
|
180
|
+
// 2026-07-06: 写入时质量门 — 检测到测试灌水数据, 默认 status='rejected' 静默丢弃
|
|
181
|
+
// 启发式集见 ./cleanup.ts. 既不抛错(避免 D-hook 阻塞), 也不污染 active set.
|
|
182
|
+
// 注意: 只在 isJunkJudgment 命中时显式设 status; 其余情况下让 migration layer 填默认 'active'
|
|
183
|
+
// 这样老 schema migration 测试 (验 j.status === undefined) 不会被破坏.
|
|
184
|
+
let initialStatus = undefined;
|
|
185
|
+
try {
|
|
186
|
+
const { isJunkJudgment } = await Promise.resolve().then(() => __importStar(require('./cleanup.js')));
|
|
187
|
+
if (isJunkJudgment({ ...judgment, id: '', timestamp: '' })) {
|
|
188
|
+
console.warn(`[HumanValueStore] junk detected, marking rejected: "${String(judgment.decision).substring(0, 40)}..."`);
|
|
189
|
+
initialStatus = 'rejected';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch { /* cleanup module load failed - allow store */ }
|
|
193
|
+
const fullJudgment = {
|
|
194
|
+
...judgment,
|
|
195
|
+
id: generateId(),
|
|
196
|
+
timestamp: now,
|
|
197
|
+
...(initialStatus ? { status: initialStatus } : {}),
|
|
198
|
+
};
|
|
199
|
+
// 加载现有判断
|
|
200
|
+
const judgments = await loadAllJudgments();
|
|
201
|
+
judgments.push(fullJudgment);
|
|
202
|
+
// 保存
|
|
203
|
+
await saveJudgments(judgments);
|
|
204
|
+
// 更新价值画像
|
|
205
|
+
await updateValueProfile(fullJudgment);
|
|
206
|
+
console.log(`[HumanValueStore] Stored judgment ${fullJudgment.id}: ${fullJudgment.decision.substring(0, 50)}...`);
|
|
207
|
+
return fullJudgment;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* 从决策结果学习(轨迹学习)
|
|
211
|
+
*/
|
|
212
|
+
async function learnFromTrajectory(trajectory) {
|
|
213
|
+
// 提取价值观
|
|
214
|
+
const values = extractValuesFromTrajectory(trajectory);
|
|
215
|
+
return storeHumanJudgment({
|
|
216
|
+
decision: trajectory.chosen_action,
|
|
217
|
+
decision_type: trajectory.approved ? 'approve' : 'reject',
|
|
218
|
+
reasons: [trajectory.outcome],
|
|
219
|
+
values_derived: values,
|
|
220
|
+
context: inferContext(trajectory.situation),
|
|
221
|
+
outcome: {
|
|
222
|
+
approved: trajectory.approved,
|
|
223
|
+
feedback: trajectory.outcome
|
|
224
|
+
},
|
|
225
|
+
metadata: {
|
|
226
|
+
source: 'trajectory',
|
|
227
|
+
confidence: trajectory.approved ? 0.9 : 0.7,
|
|
228
|
+
revisable: true
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* 从批准/拒绝学习
|
|
234
|
+
*/
|
|
235
|
+
async function learnFromFeedback(action, approved, reason) {
|
|
236
|
+
return storeHumanJudgment({
|
|
237
|
+
decision: action,
|
|
238
|
+
decision_type: approved ? 'approve' : 'reject',
|
|
239
|
+
reasons: reason ? [reason] : [],
|
|
240
|
+
values_derived: approved ? inferPositiveValues(action) : inferNegativeValues(action),
|
|
241
|
+
context: inferContext(action),
|
|
242
|
+
outcome: { approved },
|
|
243
|
+
metadata: {
|
|
244
|
+
source: 'explicit',
|
|
245
|
+
confidence: 0.8,
|
|
246
|
+
revisable: true
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 从建议修正学习
|
|
252
|
+
*/
|
|
253
|
+
async function learnFromCorrection(original, corrected, reason) {
|
|
254
|
+
return storeHumanJudgment({
|
|
255
|
+
decision: corrected,
|
|
256
|
+
decision_type: 'modify',
|
|
257
|
+
reasons: [reason],
|
|
258
|
+
values_derived: extractValuesFromCorrection(original, corrected),
|
|
259
|
+
context: inferContext(original),
|
|
260
|
+
outcome: { approved: true, revised: true },
|
|
261
|
+
metadata: {
|
|
262
|
+
source: 'trajectory',
|
|
263
|
+
confidence: 0.85,
|
|
264
|
+
revisable: false
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
// ============================================================
|
|
269
|
+
// 读取操作
|
|
270
|
+
// ============================================================
|
|
271
|
+
/**
|
|
272
|
+
* 修改一个判断 (手动编辑). 允许改: decision, reasons, context, values_derived, decision_type, confidence.
|
|
273
|
+
* 不能改 id, timestamp (id 不暴露, 靠 id 查).
|
|
274
|
+
*/
|
|
275
|
+
async function updateJudgment(id, patch) {
|
|
276
|
+
const judgments = await loadAllJudgments();
|
|
277
|
+
const idx = judgments.findIndex((j) => j.id === id);
|
|
278
|
+
if (idx < 0)
|
|
279
|
+
return null;
|
|
280
|
+
const cur = judgments[idx];
|
|
281
|
+
const next = {
|
|
282
|
+
...cur,
|
|
283
|
+
...(patch.decision !== undefined ? { decision: patch.decision } : {}),
|
|
284
|
+
...(patch.decision_type !== undefined ? { decision_type: patch.decision_type } : {}),
|
|
285
|
+
...(patch.reasons !== undefined ? { reasons: patch.reasons } : {}),
|
|
286
|
+
...(patch.values_derived !== undefined ? { values_derived: patch.values_derived } : {}),
|
|
287
|
+
...(patch.context !== undefined ? { context: { ...cur.context, ...patch.context } } : {}),
|
|
288
|
+
...(patch.outcome !== undefined ? { outcome: { ...cur.outcome, ...patch.outcome } } : {}),
|
|
289
|
+
...(patch.status !== undefined ? { status: patch.status } : {}),
|
|
290
|
+
...(patch.supersededBy !== undefined ? { supersededBy: patch.supersededBy } : {}),
|
|
291
|
+
...(patch.evolutionReason !== undefined ? { evolutionReason: patch.evolutionReason } : {}),
|
|
292
|
+
...(patch.evolvedAt !== undefined ? { evolvedAt: patch.evolvedAt } : {}),
|
|
293
|
+
};
|
|
294
|
+
judgments[idx] = next;
|
|
295
|
+
await saveJudgments(judgments);
|
|
296
|
+
// 价值画像缓存失效 (内容变了画像也得重算)
|
|
297
|
+
valueProfileCache.clear();
|
|
298
|
+
return next;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 按 status 过滤查询 (用于判断力库的 active/superseded tab)
|
|
302
|
+
* status='all' 或不传 → 返回所有
|
|
303
|
+
*/
|
|
304
|
+
async function listJudgmentsByStatus(status) {
|
|
305
|
+
const judgments = await loadAllJudgments();
|
|
306
|
+
if (!status || status === 'all')
|
|
307
|
+
return judgments;
|
|
308
|
+
return judgments.filter((j) => (j.status ?? 'active') === status);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* 内容 hash 用于去重窗口 (24h 滑窗内撞 hash 视为重复)
|
|
312
|
+
* 归一化: 去标点 + 折叠空白 + lowercase
|
|
313
|
+
* 64-bit 截断: 1 万条库碰撞率 < 1e-13, 够用
|
|
314
|
+
*/
|
|
315
|
+
function hashDecision(decision) {
|
|
316
|
+
const normalized = decision
|
|
317
|
+
.toLowerCase()
|
|
318
|
+
.replace(/[\s,.,。、!?!?""''()()::;;\-—_]/g, '')
|
|
319
|
+
.trim();
|
|
320
|
+
return (0, crypto_1.createHash)('sha256').update(normalized).digest('hex').slice(0, 16);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* 在 withinMs 时间内查找与 decision hash 相同的判断力
|
|
324
|
+
* - 默认扫全库 (100 条库 < 1ms, 不建索引)
|
|
325
|
+
* - 可按 channelId 隔离 (判断力的 context.domain 是 'channel:xxx' 格式)
|
|
326
|
+
* - 当前实现只做精确 hash 匹配, 不做相似度评分; 撞 hash 即视为重复
|
|
327
|
+
*/
|
|
328
|
+
async function findRecentSimilarDecisions(decision, withinMs, options) {
|
|
329
|
+
const judgments = await loadAllJudgments();
|
|
330
|
+
const targetHash = hashDecision(decision);
|
|
331
|
+
const cutoff = Date.now() - withinMs;
|
|
332
|
+
const statusFilter = options?.status ?? 'all';
|
|
333
|
+
const wantChannel = options?.channelId ? `channel:${options.channelId}` : null;
|
|
334
|
+
const out = [];
|
|
335
|
+
for (const j of judgments) {
|
|
336
|
+
if (statusFilter !== 'all' && (j.status ?? 'active') !== statusFilter)
|
|
337
|
+
continue;
|
|
338
|
+
if (new Date(j.timestamp).getTime() <= cutoff)
|
|
339
|
+
continue;
|
|
340
|
+
if (wantChannel) {
|
|
341
|
+
const jChannel = j.context?.domain;
|
|
342
|
+
if (jChannel !== wantChannel)
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (hashDecision(j.decision) === targetHash) {
|
|
346
|
+
out.push({ id: j.id, decision: j.decision, timestamp: j.timestamp, similarity: 1.0 });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return out;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* 批量更新 (用于演化对齐后批量标 superseded)
|
|
353
|
+
* 写完文件 + 清缓存
|
|
354
|
+
* 返回成功更新的条数
|
|
355
|
+
*/
|
|
356
|
+
async function batchUpdateJudgments(updates) {
|
|
357
|
+
const judgments = await loadAllJudgments();
|
|
358
|
+
const notFound = [];
|
|
359
|
+
let updated = 0;
|
|
360
|
+
const next = judgments.map((cur) => {
|
|
361
|
+
const u = updates.find((x) => x.id === cur.id);
|
|
362
|
+
if (!u)
|
|
363
|
+
return cur;
|
|
364
|
+
updated++;
|
|
365
|
+
return { ...cur, ...u.patch };
|
|
366
|
+
});
|
|
367
|
+
for (const u of updates) {
|
|
368
|
+
if (!judgments.some((j) => j.id === u.id))
|
|
369
|
+
notFound.push(u.id);
|
|
370
|
+
}
|
|
371
|
+
if (updated > 0) {
|
|
372
|
+
await saveJudgments(next);
|
|
373
|
+
valueProfileCache.clear();
|
|
374
|
+
}
|
|
375
|
+
return { updated, notFound };
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* 更新单条 judgment (给"标记 rejected"等用)
|
|
379
|
+
* id 不变; 不能改 id, timestamp
|
|
380
|
+
* 允许改的字段: decision, decision_type, reasons, values_derived, context, outcome, status, supersededBy, evolutionReason, evolvedAt
|
|
381
|
+
*/
|
|
382
|
+
async function updateJudgmentStatus(id, status, extra) {
|
|
383
|
+
return updateJudgment(id, {
|
|
384
|
+
status,
|
|
385
|
+
...(extra?.supersededBy !== undefined ? { supersededBy: extra.supersededBy } : {}),
|
|
386
|
+
...(extra?.evolutionReason !== undefined ? { evolutionReason: extra.evolutionReason } : {}),
|
|
387
|
+
...(extra ? { evolvedAt: new Date().toISOString() } : {}),
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* 删除一个判断.
|
|
392
|
+
*/
|
|
393
|
+
async function deleteJudgment(id) {
|
|
394
|
+
const judgments = await loadAllJudgments();
|
|
395
|
+
const idx = judgments.findIndex((j) => j.id === id);
|
|
396
|
+
if (idx < 0)
|
|
397
|
+
return false;
|
|
398
|
+
judgments.splice(idx, 1);
|
|
399
|
+
await saveJudgments(judgments);
|
|
400
|
+
valueProfileCache.clear();
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 加载所有人类判断
|
|
405
|
+
*/
|
|
406
|
+
async function loadAllJudgments() {
|
|
407
|
+
if (!initialized) {
|
|
408
|
+
await initializeValueStore();
|
|
409
|
+
}
|
|
410
|
+
if (judgmentCache.length > 0) {
|
|
411
|
+
// 早返回路径也要确保每条都有 status (防御性, 防止 saveJudgments 路径异常)
|
|
412
|
+
const needs = judgmentCache.some((j) => j.status === undefined);
|
|
413
|
+
if (needs) {
|
|
414
|
+
judgmentCache = judgmentCache.map((j) => j.status === undefined ? { ...j, status: 'active' } : j);
|
|
415
|
+
}
|
|
416
|
+
// 阶段 2: 4 字段 migration (in-place, 仅一次)
|
|
417
|
+
if (!migratedOnce) {
|
|
418
|
+
let anyChanged = false;
|
|
419
|
+
judgmentCache.forEach((j) => {
|
|
420
|
+
if (migrateJudgmentInPlace(j))
|
|
421
|
+
anyChanged = true;
|
|
422
|
+
});
|
|
423
|
+
if (anyChanged) {
|
|
424
|
+
await saveJudgments(judgmentCache).catch(() => { });
|
|
425
|
+
}
|
|
426
|
+
migratedOnce = true;
|
|
427
|
+
}
|
|
428
|
+
return [...judgmentCache];
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
const content = await fs.readFile(getJudgmentsFile(), 'utf-8');
|
|
432
|
+
const parsed = JSON.parse(content);
|
|
433
|
+
judgmentCache = parsed.map((j) => (j.status === undefined ? { ...j, status: 'active' } : j));
|
|
434
|
+
// 阶段 2: 4 字段 migration (in-place, 仅一次)
|
|
435
|
+
if (!migratedOnce) {
|
|
436
|
+
let anyChanged = false;
|
|
437
|
+
judgmentCache.forEach((j) => {
|
|
438
|
+
if (migrateJudgmentInPlace(j))
|
|
439
|
+
anyChanged = true;
|
|
440
|
+
});
|
|
441
|
+
if (anyChanged) {
|
|
442
|
+
await saveJudgments(judgmentCache).catch(() => { });
|
|
443
|
+
}
|
|
444
|
+
migratedOnce = true;
|
|
445
|
+
}
|
|
446
|
+
return [...judgmentCache];
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
judgmentCache = [];
|
|
450
|
+
return [];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* 获取相关价值观
|
|
455
|
+
* 两路召回 (P2 升级):
|
|
456
|
+
* 1. 关键词匹配 (精确, 高权重)
|
|
457
|
+
* 2. bigram 软相似度 (措辞改写也能命中, 低权重)
|
|
458
|
+
* - 关键词完全匹配 → weight 不衰减
|
|
459
|
+
* - 软相似 > 0.4 → weight * 0.7 (留作辅助, 不冲掉精确命中)
|
|
460
|
+
*/
|
|
461
|
+
async function getRelevantValues(context, domain, currentTool) {
|
|
462
|
+
const allJudgments = await loadAllJudgments();
|
|
463
|
+
// 2026-07-06: 过滤 active — 之前 superseded/rejected 也会进检索, 污染上下文
|
|
464
|
+
// 配合 storeHumanJudgment 写入时设 status='rejected' 拦截 junk data (见 cleanup.ts)
|
|
465
|
+
const judgments = allJudgments.filter((j) => (j.status ?? 'active') === 'active');
|
|
466
|
+
const keywords = context.split(/[\s,,、]+/).filter(k => k.length >= 2);
|
|
467
|
+
const contextLower = context.toLowerCase();
|
|
468
|
+
const relevant = [];
|
|
469
|
+
for (const j of judgments) {
|
|
470
|
+
if (domain && j.context.domain !== domain)
|
|
471
|
+
continue;
|
|
472
|
+
// 阶段 2: appliesTo 路由 — 不匹配当前 tool 类别的 judgment 直接跳过
|
|
473
|
+
// appliesTo 为空 / undefined = 适用所有 (默认)
|
|
474
|
+
if (currentTool && Array.isArray(j.appliesTo) && j.appliesTo.length > 0) {
|
|
475
|
+
if (!j.appliesTo.includes(currentTool))
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
let matched = false;
|
|
479
|
+
let soft = 0;
|
|
480
|
+
if (keywords.length === 0) {
|
|
481
|
+
if (j.decision.toLowerCase().includes(contextLower) ||
|
|
482
|
+
j.reasons.some(r => r.toLowerCase().includes(contextLower)) ||
|
|
483
|
+
j.values_derived.some(v => v.value.toLowerCase().includes(contextLower))) {
|
|
484
|
+
matched = true;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
const decisionLower = j.decision.toLowerCase();
|
|
489
|
+
const reasonsLower = j.reasons.map(r => r.toLowerCase());
|
|
490
|
+
// values_derived[i].value 也是索引一部分 (如 'security-first', 'privacy-first')
|
|
491
|
+
const valueTokens = j.values_derived.map(v => v.value.toLowerCase());
|
|
492
|
+
for (const kw of keywords) {
|
|
493
|
+
const kwLower = kw.toLowerCase();
|
|
494
|
+
if (decisionLower.includes(kwLower) ||
|
|
495
|
+
reasonsLower.some(r => r.includes(kwLower)) ||
|
|
496
|
+
valueTokens.some(vt => vt.includes(kwLower))) {
|
|
497
|
+
matched = true;
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
// P2: 软相似度召回 — 关键词没命中, 但 bigram 相似度阈值
|
|
501
|
+
// - 长句 (>8 字符): 阈值 0.4 (合理召回, 不易误触)
|
|
502
|
+
// - 短句 (≤8 字符): 阈值 0.15 (bigram 模式天然偏低, 放宽避免漏召)
|
|
503
|
+
const threshold = kw.length > 8 ? 0.4 : 0.15;
|
|
504
|
+
const simA = softBigramSimilarity(kw, j.decision);
|
|
505
|
+
const simReason = Math.max(0, ...j.reasons.map(r => softBigramSimilarity(kw, r)));
|
|
506
|
+
const simValue = Math.max(0, ...valueTokens.map(vt => softBigramSimilarity(kw, vt)));
|
|
507
|
+
const best = Math.max(simA, simReason, simValue);
|
|
508
|
+
if (best > threshold)
|
|
509
|
+
soft = Math.max(soft, best);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (matched)
|
|
514
|
+
relevant.push({ j, softWeight: 1.0 });
|
|
515
|
+
else if (soft > 0)
|
|
516
|
+
relevant.push({ j, softWeight: soft });
|
|
517
|
+
}
|
|
518
|
+
const valueMap = new Map();
|
|
519
|
+
for (const { j, softWeight } of relevant) {
|
|
520
|
+
for (const v of j.values_derived) {
|
|
521
|
+
const key = `${v.category}:${v.value}`;
|
|
522
|
+
const existing = valueMap.get(key);
|
|
523
|
+
if (existing) {
|
|
524
|
+
existing.count++;
|
|
525
|
+
existing.tag.weight = Math.min(1, existing.tag.weight + 0.1);
|
|
526
|
+
existing.softFactor = Math.max(existing.softFactor, softWeight);
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
529
|
+
valueMap.set(key, {
|
|
530
|
+
tag: { ...v },
|
|
531
|
+
count: 1,
|
|
532
|
+
softFactor: softWeight,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return Array.from(valueMap.values())
|
|
538
|
+
.map(({ tag, count, softFactor }) => ({
|
|
539
|
+
...tag,
|
|
540
|
+
// 软命中: 额外乘 0.7 衰减, 避免冲掉精确命中的排序
|
|
541
|
+
weight: tag.weight * Math.min(1, count / 3) * (softFactor >= 0.999 ? 1.0 : 0.7),
|
|
542
|
+
}))
|
|
543
|
+
.sort((a, b) => b.weight - a.weight)
|
|
544
|
+
.slice(0, 10);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* P2 软相似度: 用于"关键词未命中但措辞相近"的兜底召回
|
|
548
|
+
* - 与 evolve-judgment.ts 的 jaccardSimilarity 算法一致 (避免循环依赖, inline 一份)
|
|
549
|
+
* - 短句 (<8 字符) 走 bigram, 长句走单字 set
|
|
550
|
+
*/
|
|
551
|
+
function softBigramSimilarity(a, b) {
|
|
552
|
+
if (!a || !b)
|
|
553
|
+
return 0;
|
|
554
|
+
const normalize = (s) => s.toLowerCase().replace(/[\s,.,。、!?!?""''()()::;;\-—_]/g, '').trim();
|
|
555
|
+
const textA = normalize(a);
|
|
556
|
+
const textB = normalize(b);
|
|
557
|
+
if (textA.length === 0 || textB.length === 0)
|
|
558
|
+
return 0;
|
|
559
|
+
const grams = (s) => {
|
|
560
|
+
if (s.length < 8) {
|
|
561
|
+
const out = new Set();
|
|
562
|
+
for (let i = 0; i < s.length - 1; i++)
|
|
563
|
+
out.add(s.slice(i, i + 2));
|
|
564
|
+
for (const c of s)
|
|
565
|
+
out.add(c);
|
|
566
|
+
return out;
|
|
567
|
+
}
|
|
568
|
+
return new Set(s);
|
|
569
|
+
};
|
|
570
|
+
const setA = grams(textA);
|
|
571
|
+
const setB = grams(textB);
|
|
572
|
+
let inter = 0;
|
|
573
|
+
for (const c of setA)
|
|
574
|
+
if (setB.has(c))
|
|
575
|
+
inter++;
|
|
576
|
+
const union = setA.size + setB.size - inter;
|
|
577
|
+
return union === 0 ? 0 : inter / union;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* 获取价值画像
|
|
581
|
+
*/
|
|
582
|
+
async function getValueProfile(agentId) {
|
|
583
|
+
if (valueProfileCache.has(agentId)) {
|
|
584
|
+
return valueProfileCache.get(agentId);
|
|
585
|
+
}
|
|
586
|
+
const judgments = await loadAllJudgments();
|
|
587
|
+
const agentJudgments = judgments.filter(j => j.metadata.source !== 'trajectory' || j.id.includes(agentId));
|
|
588
|
+
const profile = buildValueProfile(agentId, agentJudgments);
|
|
589
|
+
valueProfileCache.set(agentId, profile);
|
|
590
|
+
return profile;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* 获取优先级规则
|
|
594
|
+
*/
|
|
595
|
+
async function getPriorityRules() {
|
|
596
|
+
const judgments = await loadAllJudgments();
|
|
597
|
+
const seen = new Set();
|
|
598
|
+
return judgments
|
|
599
|
+
.filter(j => {
|
|
600
|
+
if (j.metadata.confidence <= 0.7)
|
|
601
|
+
return false;
|
|
602
|
+
const key = `${j.context.domain}:${j.decision}`;
|
|
603
|
+
if (seen.has(key))
|
|
604
|
+
return false;
|
|
605
|
+
seen.add(key);
|
|
606
|
+
return true;
|
|
607
|
+
})
|
|
608
|
+
.map(j => ({
|
|
609
|
+
when: j.context.domain,
|
|
610
|
+
prefer: j.decision,
|
|
611
|
+
reason: j.reasons[0] || 'No reason provided',
|
|
612
|
+
weight: j.metadata.confidence
|
|
613
|
+
}))
|
|
614
|
+
.slice(0, 20);
|
|
615
|
+
}
|
|
616
|
+
// ============================================================
|
|
617
|
+
// 私有函数
|
|
618
|
+
// ============================================================
|
|
619
|
+
async function saveJudgments(judgments) {
|
|
620
|
+
await fs.mkdir(getValueStoreDir(), { recursive: true });
|
|
621
|
+
await fs.writeFile(getJudgmentsFile(), JSON.stringify(judgments, null, 2), 'utf-8');
|
|
622
|
+
// 让 loadAllJudgments 下次重新读盘, 避免缓存与磁盘脱节
|
|
623
|
+
// 同时在写盘时也补 status 默认值, 防止 loadAllJudgments 走早返回路径时绕过迁移
|
|
624
|
+
// 关键: 用浅拷贝 + spread 避免 mutate 入参 (storeHumanJudgment 返回的 fullJudgment 也会被改)
|
|
625
|
+
judgmentCache = judgments.map((j) => {
|
|
626
|
+
const next = { ...j };
|
|
627
|
+
if (next.status === undefined)
|
|
628
|
+
next.status = 'active';
|
|
629
|
+
migrateJudgmentInPlace(next);
|
|
630
|
+
return next;
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
function buildValueProfile(agentId, judgments) {
|
|
634
|
+
const profile = {
|
|
635
|
+
agent_id: agentId,
|
|
636
|
+
decision_count: judgments.length,
|
|
637
|
+
quality_focus: 0.5,
|
|
638
|
+
efficiency_focus: 0.5,
|
|
639
|
+
safety_focus: 0.5,
|
|
640
|
+
collaboration_focus: 0.5,
|
|
641
|
+
learning_focus: 0.5,
|
|
642
|
+
priority_rules: [],
|
|
643
|
+
decision_patterns: [],
|
|
644
|
+
preferences: [],
|
|
645
|
+
last_updated: new Date().toISOString()
|
|
646
|
+
};
|
|
647
|
+
// 计算各维度权重
|
|
648
|
+
const dimensionCounts = {};
|
|
649
|
+
for (const j of judgments) {
|
|
650
|
+
for (const v of j.values_derived) {
|
|
651
|
+
dimensionCounts[`${v.category}_${v.value}`] =
|
|
652
|
+
(dimensionCounts[`${v.category}_${v.value}`] || 0) + v.weight;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
// 更新各维度分数
|
|
656
|
+
for (const [key, weight] of Object.entries(dimensionCounts)) {
|
|
657
|
+
const [category] = key.split('_');
|
|
658
|
+
const dimensionKey = `${category}_focus`;
|
|
659
|
+
if (dimensionKey in profile) {
|
|
660
|
+
profile[dimensionKey] = Math.min(1, weight / judgments.length);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
// 提取决策模式
|
|
664
|
+
const patternMap = new Map();
|
|
665
|
+
for (const j of judgments) {
|
|
666
|
+
const pattern = j.decision_type;
|
|
667
|
+
patternMap.set(pattern, (patternMap.get(pattern) || 0) + 1);
|
|
668
|
+
}
|
|
669
|
+
for (const [pattern, count] of patternMap) {
|
|
670
|
+
profile.decision_patterns.push({
|
|
671
|
+
pattern,
|
|
672
|
+
description: `Tendency to ${pattern}`,
|
|
673
|
+
frequency: count,
|
|
674
|
+
success_rate: judgments.filter(j => j.decision_type === pattern && j.outcome?.approved).length / count
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
// 提取优先级规则
|
|
678
|
+
profile.priority_rules = judgments
|
|
679
|
+
.filter(j => j.metadata.confidence > 0.8)
|
|
680
|
+
.map(j => ({
|
|
681
|
+
when: j.context.domain,
|
|
682
|
+
prefer: j.decision,
|
|
683
|
+
reason: j.reasons[0] || '',
|
|
684
|
+
weight: j.metadata.confidence
|
|
685
|
+
}));
|
|
686
|
+
return profile;
|
|
687
|
+
}
|
|
688
|
+
async function updateValueProfile(judgment) {
|
|
689
|
+
// 简单更新:标记缓存需要刷新
|
|
690
|
+
valueProfileCache.clear();
|
|
691
|
+
}
|
|
692
|
+
function extractValuesFromTrajectory(trajectory) {
|
|
693
|
+
const values = [];
|
|
694
|
+
const action = trajectory.chosen_action.toLowerCase();
|
|
695
|
+
const outcome = trajectory.outcome.toLowerCase();
|
|
696
|
+
// 从行动推断价值观
|
|
697
|
+
if (action.includes('review') || action.includes('检查') || action.includes('验证')) {
|
|
698
|
+
values.push({ category: 'quality', value: 'code-review', weight: 0.8 });
|
|
699
|
+
}
|
|
700
|
+
if (action.includes('test') || action.includes('测试')) {
|
|
701
|
+
values.push({ category: 'quality', value: 'testing', weight: 0.8 });
|
|
702
|
+
}
|
|
703
|
+
if (action.includes('security') || action.includes('安全')) {
|
|
704
|
+
values.push({ category: 'safety', value: 'security-first', weight: 0.9 });
|
|
705
|
+
}
|
|
706
|
+
if (action.includes('refactor') || action.includes('重构')) {
|
|
707
|
+
values.push({ category: 'quality', value: 'maintainability', weight: 0.7 });
|
|
708
|
+
}
|
|
709
|
+
if (action.includes('simple') || action.includes('简单')) {
|
|
710
|
+
values.push({ category: 'efficiency', value: 'simplicity', weight: 0.8 });
|
|
711
|
+
}
|
|
712
|
+
// 从结果推断价值观
|
|
713
|
+
if (outcome.includes('success') || outcome.includes('成功')) {
|
|
714
|
+
values.push({ category: 'learning', value: 'success-validation', weight: 0.6 });
|
|
715
|
+
}
|
|
716
|
+
if (outcome.includes('fail') || outcome.includes('失败')) {
|
|
717
|
+
values.push({ category: 'learning', value: 'failure-learning', weight: 0.7 });
|
|
718
|
+
}
|
|
719
|
+
return values.length > 0 ? values : [{ category: 'quality', value: 'general', weight: 0.5 }];
|
|
720
|
+
}
|
|
721
|
+
function inferContext(action) {
|
|
722
|
+
const actionLower = action.toLowerCase();
|
|
723
|
+
let domain = 'general';
|
|
724
|
+
if (actionLower.includes('code') || actionLower.includes('代码'))
|
|
725
|
+
domain = 'code';
|
|
726
|
+
else if (actionLower.includes('arch') || actionLower.includes('架构'))
|
|
727
|
+
domain = 'architecture';
|
|
728
|
+
else if (actionLower.includes('security') || actionLower.includes('安全'))
|
|
729
|
+
domain = 'security';
|
|
730
|
+
else if (actionLower.includes('test') || actionLower.includes('测试'))
|
|
731
|
+
domain = 'testing';
|
|
732
|
+
let complexity = 'moderate';
|
|
733
|
+
if (actionLower.includes('simple') || action.length < 50)
|
|
734
|
+
complexity = 'simple';
|
|
735
|
+
if (actionLower.includes('complex') || action.length > 200)
|
|
736
|
+
complexity = 'complex';
|
|
737
|
+
return {
|
|
738
|
+
domain,
|
|
739
|
+
complexity,
|
|
740
|
+
stakes: 'medium',
|
|
741
|
+
time_pressure: 'low'
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
function inferPositiveValues(action) {
|
|
745
|
+
return extractValuesFromTrajectory({
|
|
746
|
+
situation: action,
|
|
747
|
+
chosen_action: action,
|
|
748
|
+
outcome: 'approved',
|
|
749
|
+
approved: true
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
function inferNegativeValues(action) {
|
|
753
|
+
return extractValuesFromTrajectory({
|
|
754
|
+
situation: action,
|
|
755
|
+
chosen_action: action,
|
|
756
|
+
outcome: 'rejected',
|
|
757
|
+
approved: false
|
|
758
|
+
}).map(v => ({ ...v, weight: v.weight * 0.5 }));
|
|
759
|
+
}
|
|
760
|
+
function extractValuesFromCorrection(original, corrected) {
|
|
761
|
+
const values = [];
|
|
762
|
+
// 检测修正类型
|
|
763
|
+
if (corrected.includes('security') || corrected.includes('安全')) {
|
|
764
|
+
values.push({ category: 'safety', value: 'security-fix', weight: 0.9 });
|
|
765
|
+
}
|
|
766
|
+
if (corrected.includes('test') && !original.includes('test')) {
|
|
767
|
+
values.push({ category: 'quality', value: 'add-testing', weight: 0.8 });
|
|
768
|
+
}
|
|
769
|
+
if (corrected.length < original.length) {
|
|
770
|
+
values.push({ category: 'efficiency', value: 'simplification', weight: 0.7 });
|
|
771
|
+
}
|
|
772
|
+
return values.length > 0 ? values : [{ category: 'quality', value: 'general-fix', weight: 0.6 }];
|
|
773
|
+
}
|
|
774
|
+
// ============================================================
|
|
775
|
+
// 统计
|
|
776
|
+
// ============================================================
|
|
777
|
+
async function getValueStats() {
|
|
778
|
+
const judgments = await loadAllJudgments();
|
|
779
|
+
const byType = {};
|
|
780
|
+
const bySource = {};
|
|
781
|
+
const valueCounts = new Map();
|
|
782
|
+
for (const j of judgments) {
|
|
783
|
+
byType[j.decision_type] = (byType[j.decision_type] || 0) + 1;
|
|
784
|
+
bySource[j.metadata.source] = (bySource[j.metadata.source] || 0) + 1;
|
|
785
|
+
for (const v of j.values_derived) {
|
|
786
|
+
const key = `${v.category}:${v.value}`;
|
|
787
|
+
valueCounts.set(key, (valueCounts.get(key) || 0) + 1);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const topValues = Array.from(valueCounts.entries())
|
|
791
|
+
.map(([key, count]) => {
|
|
792
|
+
const [category, value] = key.split(':');
|
|
793
|
+
return { category: category, value, weight: count };
|
|
794
|
+
})
|
|
795
|
+
.sort((a, b) => b.weight - a.weight)
|
|
796
|
+
.slice(0, 10);
|
|
797
|
+
return {
|
|
798
|
+
total_judgments: judgments.length,
|
|
799
|
+
by_type: byType,
|
|
800
|
+
by_source: bySource,
|
|
801
|
+
top_values: topValues
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
function clearCache() {
|
|
805
|
+
judgmentCache = [];
|
|
806
|
+
valueProfileCache.clear();
|
|
807
|
+
}
|
|
808
|
+
//# sourceMappingURL=human-value-store.js.map
|