blun-king-cli 9.1.587 → 9.1.588
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/CHANGELOG.md +11 -185
- package/LIESMICH.txt +51 -13
- package/README.md +44 -47
- package/agent-spine-plugin/.codex-plugin/plugin.json +16 -4
- package/agent-spine-plugin/CHANGELOG.md +37 -5
- package/agent-spine-plugin/README.md +3 -3
- package/agent-spine-plugin/blun.plugin.json +45 -10
- package/agent-spine-plugin/docs/artifact-evaluation.md +93 -0
- package/agent-spine-plugin/docs/host-integration.md +42 -27
- package/agent-spine-plugin/docs/preflight-recall.md +4 -2
- package/agent-spine-plugin/docs/session-timeline.md +97 -236
- package/agent-spine-plugin/docs/world-model.md +25 -0
- package/agent-spine-plugin/hooks/codex.json +1 -1
- package/agent-spine-plugin/hooks/hooks.json +1 -1
- package/agent-spine-plugin/package.json +1 -3
- package/agent-spine-plugin/scripts/check-hosts.js +3 -3
- package/agent-spine-plugin/scripts/release-check.js +10 -5
- package/agent-spine-plugin/scripts/run-checks.js +4 -1
- package/agent-spine-plugin/scripts/run-tests-hermetic.js +32 -6
- package/agent-spine-plugin/src/cli-learning.js +15 -0
- package/agent-spine-plugin/src/cli.js +2 -0
- package/agent-spine-plugin/src/hook.js +32 -32
- package/agent-spine-plugin/src/lib/action-lesson-recall.js +73 -8
- package/agent-spine-plugin/src/lib/briefing.js +146 -36
- package/agent-spine-plugin/src/lib/channel-continuity.js +19 -0
- package/agent-spine-plugin/src/lib/delivery-agent-usage.js +14 -7
- package/agent-spine-plugin/src/lib/gateway-group-response.js +128 -0
- package/agent-spine-plugin/src/lib/gateway-runs.js +24 -15
- package/agent-spine-plugin/src/lib/hook-briefing-use.js +13 -3
- package/agent-spine-plugin/src/lib/hook-context.js +16 -3
- package/agent-spine-plugin/src/lib/hook-output.js +129 -5
- package/agent-spine-plugin/src/lib/hook-timeline.js +5 -3
- package/agent-spine-plugin/src/lib/indexed-memory.js +2 -2
- package/agent-spine-plugin/src/lib/learning-artifact-evaluator.js +114 -0
- package/agent-spine-plugin/src/lib/learning-context.js +11 -4
- package/agent-spine-plugin/src/lib/learning-measurements.js +2 -2
- package/agent-spine-plugin/src/lib/mcp-runtime.js +89 -3
- package/agent-spine-plugin/src/lib/mcp-source-context.js +12 -2
- package/agent-spine-plugin/src/lib/mcp-timeline-tools.js +91 -8
- package/agent-spine-plugin/src/lib/mcp-world-tools.js +2 -2
- package/agent-spine-plugin/src/lib/owned-file-lock.js +20 -1
- package/agent-spine-plugin/src/lib/persona-runtime.js +2 -2
- package/agent-spine-plugin/src/lib/preflight-delivery-id.js +27 -0
- package/agent-spine-plugin/src/lib/preflight.js +4 -4
- package/agent-spine-plugin/src/lib/session-timeline-codex.js +15 -0
- package/agent-spine-plugin/src/lib/session-timeline-contract.js +12 -4
- package/agent-spine-plugin/src/lib/session-timeline-event-extract.js +36 -7
- package/agent-spine-plugin/src/lib/session-timeline-host-origin.js +13 -10
- package/agent-spine-plugin/src/lib/session-timeline-invocation.js +1 -1
- package/agent-spine-plugin/src/lib/session-timeline-king.js +14 -0
- package/agent-spine-plugin/src/lib/session-timeline-prior.js +18 -12
- package/agent-spine-plugin/src/lib/session-timeline-provider.js +5 -0
- package/agent-spine-plugin/src/lib/session-timeline-query.js +2 -0
- package/agent-spine-plugin/src/lib/session-timeline-results.js +35 -10
- package/agent-spine-plugin/src/lib/session-timeline-source-open.js +30 -0
- package/agent-spine-plugin/src/lib/session-timeline.js +122 -75
- package/agent-spine-plugin/src/lib/source-roots.js +3 -2
- package/agent-spine-plugin/src/lib/task-knowledge-context.js +22 -1
- package/agent-spine-plugin/src/lib/timeline-continuation-update.js +100 -0
- package/agent-spine-plugin/src/lib/timeline-tool-guard.js +30 -7
- package/agent-spine-plugin/src/lib/timeline-user-feedback.js +217 -0
- package/agent-spine-plugin/src/lib/timeline-world-capture.js +233 -0
- package/agent-spine-plugin/src/lib/world-knowledge.js +59 -2
- package/agent-spine-plugin/src/lib/world-model.js +64 -9
- package/agent-spine-plugin/src/worker.js +13 -1
- package/bin/blun.js +43 -28
- package/bin/core-bootstrap.js +5 -4
- package/bin/king.js +43 -28
- package/bin/launcher-mode.js +1 -10
- package/bin/launcher-runtime.js +128 -295
- package/bin/managed-node.js +0 -0
- package/bin/managed-plugin-selection.cjs +0 -1
- package/bin/native-module-repair.js +0 -0
- package/bin/node-runtime.js +0 -0
- package/bin/node-version.js +0 -0
- package/bin/plugin-bootstrap.js +56 -120
- package/bin/private-paths.js +11 -34
- package/bin/standard-tools-bootstrap.js +34 -114
- package/bin/turn-thinking-policy.cjs +3 -11
- package/bin/update-copy.js +200 -0
- package/bin/update-lease.js +0 -0
- package/bin/update-notice.js +136 -289
- package/bin/verify-agent-behavior.cjs +122 -0
- package/bin/verify-agent-components.cjs +104 -0
- package/bin/verify-bundled-agent-sources.cjs +57 -0
- package/blun.mjs +143076 -135288
- package/bundled-agent-sources.json +701 -0
- package/package.json +12 -15
- package/standard-skills/translate-native/README.md +1293 -0
- package/standard-skills/translate-native/SKILL.md +172 -22
- package/standard-skills/translate-native/VERSION +1 -1
- package/standard-skills/translate-native/agents/openai.yaml +18 -0
- package/standard-skills/translate-native/assets/icon.svg +8 -0
- package/standard-skills/translate-native/docs/BLUN_CODE_INTEGRATION.md +76 -0
- package/standard-skills/translate-native/docs/PREMORTEM.md +489 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION.md +2035 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION_API.md +1302 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION_EVIDENCE_HTTP.md +136 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION_HEALTH_HTTP.md +130 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION_HTTP_PROVIDER.md +175 -0
- package/standard-skills/translate-native/docs/WEBSITE_LOCALIZATION_RECEIPT_VERIFIER_HTTP.md +86 -0
- package/standard-skills/translate-native/integrations/AGENT_RULES.md +32 -0
- package/standard-skills/translate-native/integrations/adapters/blun-code-language-guard.js +514 -0
- package/standard-skills/translate-native/integrations/adapters/node-language-guard.js +230 -0
- package/standard-skills/translate-native/integrations/audit_log.py +327 -0
- package/standard-skills/translate-native/integrations/claude_language_hook.js +1536 -0
- package/standard-skills/translate-native/integrations/commercial_localization_profile.py +42 -0
- package/standard-skills/translate-native/integrations/delivery-policy.example.json +28 -0
- package/standard-skills/translate-native/integrations/enforced_delivery.py +543 -0
- package/standard-skills/translate-native/integrations/guard_service.py +435 -0
- package/standard-skills/translate-native/integrations/language_gateway.py +67 -0
- package/standard-skills/translate-native/integrations/mcp_auth_headers.py +198 -0
- package/standard-skills/translate-native/integrations/mcp_http_gateway.py +429 -0
- package/standard-skills/translate-native/integrations/non_language_html_entities.js +1485 -0
- package/standard-skills/translate-native/integrations/pre_output_guard.py +65 -0
- package/standard-skills/translate-native/integrations/task_router.py +101 -0
- package/standard-skills/translate-native/integrations/website_localization.py +401 -0
- package/standard-skills/translate-native/integrations/website_localization_api.py +581 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark.py +1885 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_campaign.py +1772 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_candidate.py +506 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_http.py +400 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_review_store.py +781 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_reviewer_http.py +500 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_runtime.py +1107 -0
- package/standard-skills/translate-native/integrations/website_localization_benchmark_suite.py +463 -0
- package/standard-skills/translate-native/integrations/website_localization_cms.py +2835 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_client.py +875 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_dispatch.py +805 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_http.py +588 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_lifecycle_monitor.py +991 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_receiver.py +1441 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_receiver_runtime.py +414 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_receiver_store.py +1073 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_removal_dispatch.py +865 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_client.py +583 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_delivery.py +964 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_delivery_runtime.py +665 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_http.py +1153 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_runtime.py +675 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_source_service.py +1125 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_notification.py +674 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_notification_http.py +444 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_notification_receiver.py +1469 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_notification_receiver_runtime.py +1142 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_processing_monitor.py +634 -0
- package/standard-skills/translate-native/integrations/website_localization_cms_terminal_receiver_client.py +804 -0
- package/standard-skills/translate-native/integrations/website_localization_deepl_baseline.py +922 -0
- package/standard-skills/translate-native/integrations/website_localization_evidence_http.py +482 -0
- package/standard-skills/translate-native/integrations/website_localization_health.py +1541 -0
- package/standard-skills/translate-native/integrations/website_localization_health_http.py +372 -0
- package/standard-skills/translate-native/integrations/website_localization_http_provider.py +297 -0
- package/standard-skills/translate-native/integrations/website_localization_native_reference_http.py +479 -0
- package/standard-skills/translate-native/integrations/website_localization_native_reference_intake.py +363 -0
- package/standard-skills/translate-native/integrations/website_localization_native_reference_queue.py +1449 -0
- package/standard-skills/translate-native/integrations/website_localization_native_reference_store.py +420 -0
- package/standard-skills/translate-native/integrations/website_localization_quality_profiles.py +235 -0
- package/standard-skills/translate-native/integrations/website_localization_queue.py +671 -0
- package/standard-skills/translate-native/integrations/website_localization_receipt_verifier_http.py +516 -0
- package/standard-skills/translate-native/integrations/website_localization_release.py +928 -0
- package/standard-skills/translate-native/integrations/website_localization_release_coordinator.py +1008 -0
- package/standard-skills/translate-native/integrations/website_localization_runner.py +276 -0
- package/standard-skills/translate-native/integrations/website_localization_runtime.py +862 -0
- package/standard-skills/translate-native/integrations/website_localization_service.py +350 -0
- package/standard-skills/translate-native/integrations/website_localization_supervisor.py +511 -0
- package/standard-skills/translate-native/integrations/website_localization_worker.py +663 -0
- package/standard-skills/translate-native/provenance.json +3 -4
- package/standard-skills/translate-native/references/commercial-localization.md +177 -0
- package/standard-skills/translate-native/scripts/blun_language_guard.py +7 -1
- package/standard-skills/translate-native/scripts/check_commercial_review.py +80 -0
- package/standard-skills/translate-native/scripts/commercial_localization_profile.py +333 -0
- package/standard-tools/language-guard/LICENSE +21 -0
- package/standard-tools/language-guard/VERSION +1 -0
- package/standard-tools/language-guard/blun_language_guard.py +7 -1
- package/standard-tools/language-guard/check_commercial_review.py +80 -0
- package/standard-tools/language-guard/commercial_localization_profile.py +333 -0
- package/standard-tools/language-guard/language_gateway.py +62 -0
- package/standard-tools/language-guard/pre_output_guard.py +64 -0
- package/standard-tools/language-guard/provenance.json +4 -11
- package/standard-tools/manifest.json +34 -11
- package/telegram-plugin/commands/access.md +2 -10
- package/telegram-plugin/dist/bridge.mjs +64041 -687
- package/telegram-plugin/dist/mcp-server.mjs +72810 -9027
- package/telegram-plugin/dist/noise.mjs +28 -63511
- package/agent-spine-plugin/CONTRIBUTING.md +0 -52
- package/agent-spine-plugin/SECURITY.md +0 -47
- package/agent-spine-plugin/docs/assignment-continuation.md +0 -48
- package/agent-spine-plugin/docs/releasing.md +0 -85
- package/agent-spine-plugin/docs/structured-completion.md +0 -67
- package/bin/abort-listener-policy.cjs +0 -43
- package/bin/active-steer-priority-policy.cjs +0 -24
- package/bin/agent-api-http-adapter.mjs +0 -446
- package/bin/agent-api-private-http-server.mjs +0 -288
- package/bin/agent-api-runtime.mjs +0 -252
- package/bin/agent-api-service-environment.mjs +0 -236
- package/bin/agent-api-service-host.mjs +0 -209
- package/bin/agent-api-service-process.mjs +0 -171
- package/bin/agent-api-session-registry.mjs +0 -428
- package/bin/agent-api-tool-broker.cjs +0 -248
- package/bin/agent-api-turn-controller.mjs +0 -461
- package/bin/agent-api-usage-journal.cjs +0 -259
- package/bin/agent-resume-snapshot.cjs +0 -241
- package/bin/agentspine-king-goal-inbox.mjs +0 -111
- package/bin/agentspine-king-goal-intake.mjs +0 -106
- package/bin/approval-rejection-stop.cjs +0 -15
- package/bin/assistant-message-offload-policy.cjs +0 -284
- package/bin/baseline-skill-performance-policy.cjs +0 -39
- package/bin/bash-search-scope-policy.cjs +0 -49
- package/bin/codebase-search-runtime.cjs +0 -23
- package/bin/cognitive-action-checkpoint.cjs +0 -1104
- package/bin/cognitive-attention-delivery.cjs +0 -76
- package/bin/cognitive-attention-policy.cjs +0 -143
- package/bin/cognitive-attention-runtime.cjs +0 -91
- package/bin/cognitive-context-projection.cjs +0 -73
- package/bin/cognitive-cross-portal-acceptance.cjs +0 -443
- package/bin/cognitive-effective-view.cjs +0 -77
- package/bin/cognitive-focus-projection.cjs +0 -206
- package/bin/cognitive-focus-scope.cjs +0 -37
- package/bin/cognitive-goal-autostart-policy.cjs +0 -72
- package/bin/cognitive-goal-time-trigger-controller.cjs +0 -146
- package/bin/cognitive-memory-adapter.cjs +0 -282
- package/bin/cognitive-memory-command.cjs +0 -293
- package/bin/cognitive-memory-provider.cjs +0 -92
- package/bin/cognitive-salience-policy.cjs +0 -159
- package/bin/cognitive-state-store.cjs +0 -508
- package/bin/cognitive-turn-lifecycle.cjs +0 -624
- package/bin/cognitive-work-focus.cjs +0 -180
- package/bin/compaction-history-archive.cjs +0 -166
- package/bin/compaction-history-startup.cjs +0 -50
- package/bin/compaction-model-policy.cjs +0 -31
- package/bin/compaction-stage-policy.cjs +0 -21
- package/bin/compaction-transaction-policy.cjs +0 -122
- package/bin/config-write-dedup-policy.cjs +0 -27
- package/bin/context-budget-ledger.cjs +0 -31
- package/bin/context-doctor-policy.cjs +0 -70
- package/bin/context-insight-policy.cjs +0 -36
- package/bin/context-performance-policy.cjs +0 -19
- package/bin/context-pressure-policy.cjs +0 -20
- package/bin/cron-run-output.cjs +0 -45
- package/bin/cron-run-store.cjs +0 -145
- package/bin/curiosity-scout-policy.cjs +0 -49
- package/bin/default-model-output-budget-policy.cjs +0 -28
- package/bin/durable-task-resume-policy.cjs +0 -130
- package/bin/durable-task-resume-runtime.cjs +0 -117
- package/bin/durable-task-resume-store.cjs +0 -88
- package/bin/editable-tool-approval-policy.cjs +0 -540
- package/bin/editable-tool-approval-runtime.cjs +0 -99
- package/bin/effective-system-prompt-cache-policy.cjs +0 -33
- package/bin/error-memory-performance-policy.cjs +0 -113
- package/bin/file-observation-policy.cjs +0 -133
- package/bin/foreground-output-capture-policy.cjs +0 -41
- package/bin/generated-source-health.cjs +0 -142
- package/bin/glob-pattern-policy.cjs +0 -13
- package/bin/goal-completion-evidence-policy.cjs +0 -120
- package/bin/grep-output-limit-policy.cjs +0 -39
- package/bin/historical-media-projection-policy.cjs +0 -48
- package/bin/history-offload-pressure-policy.cjs +0 -33
- package/bin/html-to-research-markdown.cjs +0 -147
- package/bin/identity-context-policy.cjs +0 -764
- package/bin/identity-journal-policy.cjs +0 -107
- package/bin/input-draft-persistence.cjs +0 -77
- package/bin/king-tui-function-contract.json +0 -33
- package/bin/launcher-restart-policy.cjs +0 -150
- package/bin/live-response-repetition-guard.cjs +0 -196
- package/bin/llm-config-log-dedup-policy.cjs +0 -76
- package/bin/loop-event-record-policy.cjs +0 -174
- package/bin/managed-context-startup-policy.cjs +0 -27
- package/bin/media-activity-layout-policy.cjs +0 -34
- package/bin/media-auto-retrieval-policy.cjs +0 -90
- package/bin/media-result-policy.cjs +0 -59
- package/bin/micro-compaction-policy.cjs +0 -145
- package/bin/mistake-relevance-policy.cjs +0 -319
- package/bin/model-retry-progress-policy.cjs +0 -46
- package/bin/native-large-file-io.cjs +0 -42
- package/bin/native-runtime-cache.cjs +0 -76
- package/bin/natural-presence-policy.cjs +0 -28
- package/bin/noninteractive-shell-env-policy.cjs +0 -19
- package/bin/observer-hooks.cjs +0 -14
- package/bin/outbound-claim-provenance.cjs +0 -150
- package/bin/oversized-context-offload-policy.cjs +0 -86
- package/bin/pending-media-policy.cjs +0 -182
- package/bin/pending-token-estimate-policy.cjs +0 -41
- package/bin/personal-memory-consent-policy.cjs +0 -72
- package/bin/personal-memory-performance-policy.cjs +0 -12
- package/bin/personality-choice-policy.cjs +0 -101
- package/bin/personality-memory-adapter.cjs +0 -379
- package/bin/personality-mode.cjs +0 -46
- package/bin/personality-setup-policy.cjs +0 -197
- package/bin/proactive-compaction-policy.cjs +0 -25
- package/bin/profile-identity-resolution.cjs +0 -136
- package/bin/profile-runtime.cjs +0 -318
- package/bin/profile-tool-exclusion-policy.cjs +0 -37
- package/bin/programmatic-context-isolation.cjs +0 -25
- package/bin/programmatic-tool-runtime.mjs +0 -627
- package/bin/provider-idle-timeout-policy.cjs +0 -14
- package/bin/provider-model-refresh-deadline.cjs +0 -53
- package/bin/provider-model-refresh-policy.cjs +0 -107
- package/bin/rate-limit-recovery-policy.cjs +0 -47
- package/bin/read-batch-policy.cjs +0 -32
- package/bin/read-continuation-policy.cjs +0 -59
- package/bin/recurring-cron-history-policy.cjs +0 -124
- package/bin/relationship-continuity-policy.cjs +0 -143
- package/bin/relationship-curiosity-policy.cjs +0 -107
- package/bin/relationship-learning-policy.cjs +0 -168
- package/bin/release-artifact-freeze-policy.cjs +0 -30
- package/bin/reload-plugin-bootstrap.cjs +0 -18
- package/bin/reload-queue-policy.cjs +0 -38
- package/bin/repeated-assistant-response-policy.cjs +0 -232
- package/bin/repeated-injection-projection.cjs +0 -107
- package/bin/repeated-user-message-projection.cjs +0 -8
- package/bin/research-page-result.cjs +0 -74
- package/bin/retry-checkpoint-policy.cjs +0 -13
- package/bin/runtime-exit-ledger.cjs +0 -144
- package/bin/scoped-cron-run-policy.cjs +0 -358
- package/bin/session-checkpoint-policy.cjs +0 -25
- package/bin/session-compaction-policy.cjs +0 -84
- package/bin/session-replay-policy.cjs +0 -20
- package/bin/session-replay-window-policy.cjs +0 -40
- package/bin/session-resume-checkpoint.cjs +0 -254
- package/bin/session-scrollback-archive.cjs +0 -229
- package/bin/skill-activation-performance-policy.cjs +0 -69
- package/bin/skill-listing-performance-policy.cjs +0 -92
- package/bin/soul-organization-policy.cjs +0 -78
- package/bin/soul-preservation-policy.cjs +0 -20
- package/bin/startup-preferences.cjs +0 -131
- package/bin/streaming-flush-performance-policy.cjs +0 -28
- package/bin/structured-agent-swarm-output.cjs +0 -325
- package/bin/structured-subagent-output.cjs +0 -252
- package/bin/subagent-context-fork-policy.cjs +0 -155
- package/bin/subagent-max-tokens-handoff-policy.cjs +0 -69
- package/bin/subagent-parent-responsiveness.cjs +0 -19
- package/bin/subagent-skill-policy.cjs +0 -206
- package/bin/subagent-timeout-policy.cjs +0 -182
- package/bin/subagent-tool-policy.cjs +0 -60
- package/bin/subagent-usage-rollup-policy.cjs +0 -29
- package/bin/system-prompt-context-policy.cjs +0 -124
- package/bin/system-prompt-token-cache-policy.cjs +0 -60
- package/bin/telegram-addressed-focus.cjs +0 -55
- package/bin/telegram-addressed-priority.cjs +0 -12
- package/bin/telegram-approval-relay.cjs +0 -290
- package/bin/telegram-bot-priority.cjs +0 -17
- package/bin/telegram-console-status-policy.cjs +0 -174
- package/bin/telegram-context-projection-policy.cjs +0 -141
- package/bin/telegram-delivery-lifecycle.cjs +0 -125
- package/bin/telegram-direct-focus-policy.cjs +0 -273
- package/bin/telegram-mcp-compatibility.cjs +0 -49
- package/bin/telegram-media-delivery-policy.cjs +0 -42
- package/bin/telegram-private-conversation-policy.cjs +0 -185
- package/bin/telegram-queue-handoff-policy.cjs +0 -73
- package/bin/telegram-remote-status-policy.cjs +0 -120
- package/bin/telegram-session-queue-runtime.mjs +0 -306
- package/bin/telegram-text-chunk-policy.cjs +0 -63
- package/bin/telegram-truncated-reply-policy.cjs +0 -37
- package/bin/telegram-urgent-policy.cjs +0 -45
- package/bin/telemetry-spool-policy.cjs +0 -57
- package/bin/thinking-activity-status-policy.cjs +0 -132
- package/bin/thinking-only-guard.cjs +0 -80
- package/bin/todo-list-turn-policy.cjs +0 -131
- package/bin/tool-call-loop-policy.cjs +0 -51
- package/bin/tool-file-persistence.cjs +0 -141
- package/bin/tool-result-offload-policy.cjs +0 -359
- package/bin/tool-result-offload-telemetry.cjs +0 -12
- package/bin/tool-schema-token-cache-policy.cjs +0 -41
- package/bin/tool-stream-preview-policy.cjs +0 -9
- package/bin/tui-functional-contract.cjs +0 -55
- package/bin/turn-tool-performance-policy.cjs +0 -486
- package/bin/usage-cache-efficiency-policy.cjs +0 -26
- package/bin/user-home-path-policy.cjs +0 -13
- package/bin/user-message-offload-policy.cjs +0 -103
- package/bin/user-prompt-hook-origin-policy.cjs +0 -34
- package/bin/user-tool-record-policy.cjs +0 -7
- package/bin/validated-learning-insight-policy.cjs +0 -58
- package/bin/validated-learning-outcome-trace.cjs +0 -107
- package/bin/validated-learning-performance-policy.cjs +0 -53
- package/bin/validated-learning-signal.cjs +0 -463
- package/bin/windows-bash-dialect-policy.cjs +0 -25
- package/bin/windows-node-crash-dump.cjs +0 -110
- package/bin/write-continuation-policy.cjs +0 -69
- package/codebase-index/README.md +0 -82
- package/codebase-index/codebase_index.py +0 -470
- package/standard-skills/agent-browser/SKILL.md +0 -19
- package/standard-skills/agent-browser/references/runtime.md +0 -8
- package/standard-skills/blun-session-inspector/SKILL.md +0 -41
- package/standard-skills/blun-session-inspector/scripts/inspect-session.cjs +0 -437
- package/standard-skills/design-taste-frontend/SKILL.md +0 -1206
- package/standard-skills/full-output-enforcement/SKILL.md +0 -49
- package/standard-skills/high-end-visual-design/SKILL.md +0 -98
- package/standard-skills/image-to-code/SKILL.md +0 -1228
- package/standard-skills/industrial-brutalist-ui/SKILL.md +0 -92
- package/standard-skills/minimalist-ui/SKILL.md +0 -85
- package/standard-skills/motion-design-taste/SKILL.md +0 -74
- package/standard-skills/playwright-testing/SKILL.md +0 -19
- package/standard-skills/playwright-testing/references/runtime.md +0 -7
- package/standard-skills/premortem/SKILL.md +0 -148
- package/standard-skills/redesign-existing-projects/SKILL.md +0 -178
- package/standard-skills/research-evidence/SKILL.md +0 -39
- package/standard-skills/research-evidence/references/evidence-format.md +0 -104
- package/standard-skills/research-evidence/scripts/evidence-collection.cjs +0 -260
- package/standard-skills/research-evidence/scripts/score-report.cjs +0 -130
- package/standard-skills/screenshot-lesen/SKILL.md +0 -52
- package/standard-skills/stitch-design-taste/DESIGN.md +0 -121
- package/standard-skills/stitch-design-taste/SKILL.md +0 -184
- package/standard-skills/telegram-channel/SKILL.md +0 -18
- package/standard-skills/telegram-channel/references/runtime.md +0 -7
- package/standard-skills/venture-flywheel/SKILL.md +0 -32
- package/standard-skills/venture-flywheel/identity/project-identity.cjs +0 -146
- package/standard-skills/venture-flywheel/policy/capability-engine.cjs +0 -114
- package/standard-skills/venture-flywheel/policy/repository-trust.cjs +0 -229
- package/standard-skills/venture-flywheel/references/BEISPIELE-phase0.md +0 -146
- package/standard-skills/venture-flywheel/references/CAPABILITY-MAP.md +0 -34
- package/standard-skills/venture-flywheel/references/SPEC-phase0-identity-trust.md +0 -77
- package/standard-skills/venture-flywheel/references/SPEC-phase0-state-events.md +0 -93
- package/standard-skills/venture-flywheel/schemas/capability-decision.schema.json +0 -13
- package/standard-skills/venture-flywheel/schemas/execution-event.schema.json +0 -44
- package/standard-skills/venture-flywheel/schemas/project-identity.schema.json +0 -32
- package/standard-skills/venture-flywheel/schemas/repository-trust.schema.json +0 -57
- package/standard-skills/venture-flywheel/schemas/run-transition.schema.json +0 -59
- package/standard-skills/venture-flywheel/state/execution-event.cjs +0 -191
- package/standard-skills/venture-flywheel/state/task-state-machine.cjs +0 -190
- package/standard-skills/web-lesen/SKILL.md +0 -73
- package/standard-skills/web-lesen/scripts/crawl_public.py +0 -379
- package/standard-skills/windows-mcp/SKILL.md +0 -19
- package/standard-skills/windows-mcp/references/runtime.md +0 -9
- package/telegram-plugin/DELIVERY.md +0 -36
- package/telegram-plugin/bin/telegram-approval-relay.cjs +0 -290
- package/telegram-plugin/bin/telegram-console-status-policy.cjs +0 -175
- package/telegram-plugin/bin/telegram-delivery-lifecycle.cjs +0 -125
- package/telegram-plugin/bin/telegram-direct-reply-policy.cjs +0 -48
- package/telegram-plugin/bin/telegram-launcher-status-queue.cjs +0 -122
- package/telegram-plugin/bin/telegram-private-conversation-policy.cjs +0 -186
- package/telegram-plugin/bin/telegram-remote-status-policy.cjs +0 -121
- package/telegram-plugin/bin/telegram-reply-parts.cjs +0 -149
- package/telegram-plugin/bin/telegram-text-chunk-policy.cjs +0 -63
- package/telegram-plugin/bin/telegram-typing-keepalive.cjs +0 -89
- package/telegram-plugin/compat/mcp-server-fa511cd1.mjs +0 -73825
- /package/{bin → scripts}/fix-node-pty-perms.js +0 -0
|
@@ -1,624 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const crypto = require('node:crypto');
|
|
4
|
-
const fs = require('node:fs');
|
|
5
|
-
const path = require('node:path');
|
|
6
|
-
const { openCognitiveMemoryAdapter } = require('./cognitive-memory-adapter.cjs');
|
|
7
|
-
const { loadConfiguredCognitiveMemoryAdapter } = require('./cognitive-memory-provider.cjs');
|
|
8
|
-
const { buildCognitiveContextProjection } = require('./cognitive-context-projection.cjs');
|
|
9
|
-
const {
|
|
10
|
-
buildCognitiveFocusSelection,
|
|
11
|
-
evaluateCognitiveDecisionBasis,
|
|
12
|
-
} = require('./cognitive-focus-projection.cjs');
|
|
13
|
-
const { cognitiveEntityKey, focusAccessObservation } = require('./cognitive-salience-policy.cjs');
|
|
14
|
-
const { authorizeAttentionCandidate } = require('./cognitive-attention-runtime.cjs');
|
|
15
|
-
|
|
16
|
-
const SAFE_ID_RE = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/u;
|
|
17
|
-
const RIGHTS_AUTHORITIES = new Set(['runtime_user_prompt_hook', 'runtime_tool_policy']);
|
|
18
|
-
const RIGHTS_DECISIONS = new Set(['passed', 'blocked', 'not_applicable']);
|
|
19
|
-
const TOOL_POLICY_DECISIONS = new Set(['passed', 'blocked', 'error']);
|
|
20
|
-
const TOOL_OUTCOMES = new Set(['success', 'error', 'cancelled']);
|
|
21
|
-
const TURN_REASONS = new Set(['completed', 'cancelled', 'filtered', 'failed']);
|
|
22
|
-
const FOCUS_DOMAINS = new Set([
|
|
23
|
-
'self', 'world', 'team', 'goal', 'open_thread', 'assumption', 'knowledge_gap',
|
|
24
|
-
'next_trigger', 'expected_evidence',
|
|
25
|
-
]);
|
|
26
|
-
const FOCUS_EPISTEMIC_STATES = new Set([
|
|
27
|
-
'verified', 'credible_unverified', 'hypothesis', 'uncertain_memory', 'stale', 'unknown', 'legacy_unknown',
|
|
28
|
-
]);
|
|
29
|
-
const AUTHORITY_KEY_RE = /(?:^|:|_)(?:acl|api[_-]?key|capability|password|permission|secret|token)(?::|_|$)/iu;
|
|
30
|
-
|
|
31
|
-
function fail(code) {
|
|
32
|
-
const error = new Error(code);
|
|
33
|
-
error.code = code;
|
|
34
|
-
throw error;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function exactKeys(value, keys) {
|
|
38
|
-
return value && typeof value === 'object' && !Array.isArray(value)
|
|
39
|
-
&& Object.keys(value).every((key) => keys.has(key));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function safeId(value) {
|
|
43
|
-
const text = String(value ?? '').trim();
|
|
44
|
-
return SAFE_ID_RE.test(text) ? text : '';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function safeTurnId(value) {
|
|
48
|
-
return Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function cleanLabel(value, max = 128) {
|
|
52
|
-
const text = String(value ?? '').replace(/[\u0000-\u001f\u007f]+/gu, ' ').replace(/\s+/gu, ' ').trim();
|
|
53
|
-
return text && text.length <= max ? text : '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function digestId(prefix, values) {
|
|
57
|
-
const digest = crypto.createHash('sha256').update(values.join('\0')).digest('hex').slice(0, 40);
|
|
58
|
-
return `${prefix}-${digest}`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function identityFromManifest(home) {
|
|
62
|
-
const root = fs.realpathSync(path.resolve(String(home ?? '')));
|
|
63
|
-
const identityRoot = path.join(root, 'identity');
|
|
64
|
-
const manifestPath = path.join(identityRoot, 'manifest.json');
|
|
65
|
-
try {
|
|
66
|
-
const identityStat = fs.lstatSync(identityRoot);
|
|
67
|
-
const manifestStat = fs.lstatSync(manifestPath);
|
|
68
|
-
if (!identityStat.isDirectory() || identityStat.isSymbolicLink()
|
|
69
|
-
|| !manifestStat.isFile() || manifestStat.isSymbolicLink() || manifestStat.size > 64 * 1024) return null;
|
|
70
|
-
if (fs.realpathSync(identityRoot) !== identityRoot || fs.realpathSync(manifestPath) !== manifestPath) return null;
|
|
71
|
-
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
72
|
-
const tenantId = safeId(manifest?.tenant_id);
|
|
73
|
-
const agentId = safeId(manifest?.active_agent_id);
|
|
74
|
-
return manifest?.version === 1 && tenantId && agentId ? { tenantId, agentId } : null;
|
|
75
|
-
} catch {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function createCognitiveTurnLifecycle({
|
|
81
|
-
home,
|
|
82
|
-
tenantId,
|
|
83
|
-
agentId,
|
|
84
|
-
runtimeId,
|
|
85
|
-
memoryAdapter,
|
|
86
|
-
memoryMode = memoryAdapter === undefined ? 'profile-local-fallback' : 'injected-adapter',
|
|
87
|
-
identityMode = 'shared-identity',
|
|
88
|
-
now = () => new Date().toISOString(),
|
|
89
|
-
} = {}) {
|
|
90
|
-
const tenant = safeId(tenantId);
|
|
91
|
-
const agent = safeId(agentId);
|
|
92
|
-
const runtime = safeId(runtimeId ?? `runtime-${process.pid}-${Date.now()}`);
|
|
93
|
-
const memoryModes = new Set(['profile-local-fallback', 'configured-provider', 'injected-adapter']);
|
|
94
|
-
const identityModes = new Set(['shared-identity', 'profile-derived']);
|
|
95
|
-
if (!tenant || !agent || !runtime || typeof now !== 'function'
|
|
96
|
-
|| !memoryModes.has(memoryMode) || !identityModes.has(identityMode)) {
|
|
97
|
-
fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
98
|
-
}
|
|
99
|
-
const store = openCognitiveMemoryAdapter({ home, adapter: memoryAdapter });
|
|
100
|
-
const internalMemoryAccess = Object.freeze({
|
|
101
|
-
tenantId: tenant,
|
|
102
|
-
userId: agent,
|
|
103
|
-
actorId: agent,
|
|
104
|
-
agentId: agent,
|
|
105
|
-
portalId: 'cli',
|
|
106
|
-
channelId: 'runtime',
|
|
107
|
-
conversationId: runtime,
|
|
108
|
-
requestedScope: 'agent:memory',
|
|
109
|
-
permissionContext: Object.freeze({
|
|
110
|
-
authority: 'runtime_internal',
|
|
111
|
-
decision: 'passed',
|
|
112
|
-
receiptId: runtime,
|
|
113
|
-
}),
|
|
114
|
-
});
|
|
115
|
-
const stageTimes = new Map();
|
|
116
|
-
const stageResults = new Map();
|
|
117
|
-
|
|
118
|
-
function stageTime(stageKey) {
|
|
119
|
-
if (!stageTimes.has(stageKey)) {
|
|
120
|
-
const occurredAt = String(now());
|
|
121
|
-
if (Number.isNaN(Date.parse(occurredAt))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
122
|
-
stageTimes.set(stageKey, occurredAt);
|
|
123
|
-
}
|
|
124
|
-
return stageTimes.get(stageKey);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function commitStage(stageKey, observations) {
|
|
128
|
-
if (stageResults.has(stageKey)) return { ...stageResults.get(stageKey), idempotent: true };
|
|
129
|
-
const occurredAt = stageTime(stageKey);
|
|
130
|
-
const eventId = digestId('cycle', [tenant, agent, runtime, stageKey]);
|
|
131
|
-
const normalized = observations.map((item, index) => ({
|
|
132
|
-
observation_id: digestId('cycleobs', [eventId, String(index)]),
|
|
133
|
-
epistemic_state: 'verified',
|
|
134
|
-
...item,
|
|
135
|
-
}));
|
|
136
|
-
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
137
|
-
const expectedVersion = store.read({ tenantId: tenant, agentId: agent }, internalMemoryAccess).version;
|
|
138
|
-
try {
|
|
139
|
-
const result = store.commit({
|
|
140
|
-
tenantId: tenant,
|
|
141
|
-
agentId: agent,
|
|
142
|
-
eventId,
|
|
143
|
-
expectedVersion,
|
|
144
|
-
occurredAt,
|
|
145
|
-
receivedAt: occurredAt,
|
|
146
|
-
retentionClass: 'operational',
|
|
147
|
-
source: {
|
|
148
|
-
provider: 'runtime',
|
|
149
|
-
channel_id: 'runtime',
|
|
150
|
-
actor_id: agent,
|
|
151
|
-
context_id: runtime,
|
|
152
|
-
message_id: stageKey,
|
|
153
|
-
},
|
|
154
|
-
observations: normalized,
|
|
155
|
-
}, internalMemoryAccess);
|
|
156
|
-
stageResults.set(stageKey, result);
|
|
157
|
-
return result;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
if (error?.code !== 'COGNITIVE_VERSION_CONFLICT' || attempt === 3) throw error;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
fail('COGNITIVE_VERSION_CONFLICT');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function commitDurableStage(stageKey, observations) {
|
|
166
|
-
if (stageResults.has(stageKey)) return { ...stageResults.get(stageKey), idempotent: true };
|
|
167
|
-
const eventId = digestId('durable', [tenant, agent, stageKey]);
|
|
168
|
-
if (store.hasEvent({
|
|
169
|
-
eventId, tenantId: tenant, agentId: agent, visibilityScope: 'agent:memory',
|
|
170
|
-
}, internalMemoryAccess)) {
|
|
171
|
-
const result = { idempotent: true };
|
|
172
|
-
stageResults.set(stageKey, result);
|
|
173
|
-
return result;
|
|
174
|
-
}
|
|
175
|
-
const occurredAt = stageTime(`durable:${stageKey}`);
|
|
176
|
-
const normalized = observations.map((item, index) => ({
|
|
177
|
-
observation_id: digestId('durableobs', [eventId, String(index)]),
|
|
178
|
-
...item,
|
|
179
|
-
}));
|
|
180
|
-
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
181
|
-
if (store.hasEvent({
|
|
182
|
-
eventId, tenantId: tenant, agentId: agent, visibilityScope: 'agent:memory',
|
|
183
|
-
}, internalMemoryAccess)) {
|
|
184
|
-
const result = { idempotent: true };
|
|
185
|
-
stageResults.set(stageKey, result);
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
const expectedVersion = store.read({ tenantId: tenant, agentId: agent }, internalMemoryAccess).version;
|
|
189
|
-
try {
|
|
190
|
-
const result = store.commit({
|
|
191
|
-
tenantId: tenant,
|
|
192
|
-
agentId: agent,
|
|
193
|
-
eventId,
|
|
194
|
-
expectedVersion,
|
|
195
|
-
occurredAt,
|
|
196
|
-
receivedAt: occurredAt,
|
|
197
|
-
retentionClass: 'durable',
|
|
198
|
-
source: {
|
|
199
|
-
provider: 'runtime',
|
|
200
|
-
channel_id: 'runtime',
|
|
201
|
-
actor_id: agent,
|
|
202
|
-
context_id: 'durable-focus',
|
|
203
|
-
message_id: stageKey,
|
|
204
|
-
},
|
|
205
|
-
observations: normalized,
|
|
206
|
-
}, internalMemoryAccess);
|
|
207
|
-
stageResults.set(stageKey, result);
|
|
208
|
-
return result;
|
|
209
|
-
} catch (error) {
|
|
210
|
-
if (error?.code !== 'COGNITIVE_VERSION_CONFLICT' || attempt === 3) throw error;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
fail('COGNITIVE_VERSION_CONFLICT');
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function startTurn(input) {
|
|
217
|
-
if (!exactKeys(input, new Set(['turnId', 'originKind']))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
218
|
-
const turnId = safeTurnId(input.turnId);
|
|
219
|
-
const originKind = safeId(input.originKind);
|
|
220
|
-
if (turnId === null || !originKind) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
221
|
-
const key = `turn:${turnId}`;
|
|
222
|
-
return commitStage(`turn-${turnId}-start`, [
|
|
223
|
-
{ domain: 'open_thread', key: `${key}:phase`, value: 'perceived', confidence: 1, scope: 'runtime' },
|
|
224
|
-
{ domain: 'assumption', key: `${key}:classification`, value: `origin:${originKind}`, confidence: 1, scope: 'runtime' },
|
|
225
|
-
{ domain: 'goal', key: `${key}:plan`, value: 'run-bounded-model-turn', confidence: 1, scope: 'runtime' },
|
|
226
|
-
{ domain: 'next_trigger', key: `${key}:next`, value: 'runtime-policy-check', confidence: 1, scope: 'runtime' },
|
|
227
|
-
{ domain: 'expected_evidence', key: `${key}:evidence`, value: 'turn.ended-event', confidence: 1, scope: 'runtime' },
|
|
228
|
-
]);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function recordRightsCheck(input) {
|
|
232
|
-
if (!exactKeys(input, new Set(['turnId', 'decision', 'authority']))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
233
|
-
const turnId = safeTurnId(input.turnId);
|
|
234
|
-
const decision = String(input.decision ?? '');
|
|
235
|
-
const authority = String(input.authority ?? '');
|
|
236
|
-
if (turnId === null || !RIGHTS_DECISIONS.has(decision)) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
237
|
-
if (!RIGHTS_AUTHORITIES.has(authority)) fail('COGNITIVE_RIGHTS_AUTHORITY_REQUIRED');
|
|
238
|
-
return commitStage(`turn-${turnId}-rights-${authority}`, [{
|
|
239
|
-
domain: 'world',
|
|
240
|
-
key: `turn:${turnId}:rights-check`,
|
|
241
|
-
value: `${decision}:${authority}`,
|
|
242
|
-
confidence: 1,
|
|
243
|
-
scope: 'runtime',
|
|
244
|
-
}]);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function endTurn(input) {
|
|
248
|
-
if (!exactKeys(input, new Set(['turnId', 'reason', 'durationMs']))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
249
|
-
const turnId = safeTurnId(input.turnId);
|
|
250
|
-
const reason = String(input.reason ?? '');
|
|
251
|
-
const durationMs = Number(input.durationMs);
|
|
252
|
-
if (turnId === null || !TURN_REASONS.has(reason) || !Number.isSafeInteger(durationMs) || durationMs < 0) {
|
|
253
|
-
fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
254
|
-
}
|
|
255
|
-
const key = `turn:${turnId}`;
|
|
256
|
-
return commitStage(`turn-${turnId}-end`, [
|
|
257
|
-
{ domain: 'open_thread', key: `${key}:phase`, value: reason, confidence: 1, scope: 'runtime' },
|
|
258
|
-
{ domain: 'expected_evidence', key: `${key}:result`, value: `turn.ended:${reason}:${durationMs}ms`, confidence: 1, scope: 'runtime' },
|
|
259
|
-
{ domain: 'next_trigger', key: `${key}:next`, value: reason === 'completed' ? 'await-next-input' : 'inspect-turn-outcome', confidence: 1, scope: 'runtime' },
|
|
260
|
-
]);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function recordFocusSnapshot(input) {
|
|
264
|
-
if (!exactKeys(input, new Set(['snapshotId', 'observations']))
|
|
265
|
-
|| !safeId(input.snapshotId) || !Array.isArray(input.observations)
|
|
266
|
-
|| input.observations.length < 1 || input.observations.length > 16) {
|
|
267
|
-
fail('COGNITIVE_FOCUS_INVALID');
|
|
268
|
-
}
|
|
269
|
-
const observations = input.observations.map((item) => {
|
|
270
|
-
if (!exactKeys(item, new Set(['domain', 'key', 'value', 'confidence', 'epistemicState', 'scope']))) fail('COGNITIVE_FOCUS_INVALID');
|
|
271
|
-
const domain = String(item.domain ?? '');
|
|
272
|
-
const key = cleanLabel(item.key, 128);
|
|
273
|
-
const value = cleanLabel(item.value, 512);
|
|
274
|
-
const confidence = Number(item.confidence);
|
|
275
|
-
const epistemicState = item.epistemicState === undefined
|
|
276
|
-
? 'legacy_unknown' : String(item.epistemicState);
|
|
277
|
-
const scope = cleanLabel(item.scope, 128);
|
|
278
|
-
if (!FOCUS_DOMAINS.has(domain) || !key || AUTHORITY_KEY_RE.test(key) || !value
|
|
279
|
-
|| !Number.isFinite(confidence) || confidence < 0.5 || confidence > 1
|
|
280
|
-
|| !FOCUS_EPISTEMIC_STATES.has(epistemicState)
|
|
281
|
-
|| !scope || scope === 'runtime') fail('COGNITIVE_FOCUS_INVALID');
|
|
282
|
-
return { domain, key, value, confidence, epistemic_state: epistemicState, scope };
|
|
283
|
-
});
|
|
284
|
-
return commitDurableStage(`focus-${input.snapshotId}`, observations);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function commitExplicitFocusRevision(kind, input) {
|
|
288
|
-
const correction = kind === 'correction';
|
|
289
|
-
const allowed = correction
|
|
290
|
-
? new Set(['requestId', 'targetObservationId', 'domain', 'key', 'value', 'scope', 'authority', 'confirmation', 'occurredAt', 'source'])
|
|
291
|
-
: new Set(['requestId', 'targetObservationId', 'domain', 'key', 'scope', 'authority', 'confirmation', 'occurredAt', 'source']);
|
|
292
|
-
if (!exactKeys(input, allowed)) fail('COGNITIVE_REVISION_INVALID');
|
|
293
|
-
const requestId = safeId(input.requestId);
|
|
294
|
-
const targetObservationId = safeId(input.targetObservationId);
|
|
295
|
-
const domain = String(input.domain ?? '');
|
|
296
|
-
const key = cleanLabel(input.key, 128);
|
|
297
|
-
const scope = cleanLabel(input.scope, 128);
|
|
298
|
-
const occurredAt = String(input.occurredAt ?? '').trim();
|
|
299
|
-
const source = input.source;
|
|
300
|
-
if (input.authority !== 'runtime_user_prompt_hook' || input.confirmation !== 'explicit_user_request') {
|
|
301
|
-
fail('COGNITIVE_REVISION_EXPLICIT_USER_REQUIRED');
|
|
302
|
-
}
|
|
303
|
-
if (!requestId || !targetObservationId || !FOCUS_DOMAINS.has(domain) || !key
|
|
304
|
-
|| AUTHORITY_KEY_RE.test(key) || !scope || scope === 'runtime'
|
|
305
|
-
|| Number.isNaN(Date.parse(occurredAt))
|
|
306
|
-
|| !exactKeys(source, new Set(['provider', 'channelId', 'actorId', 'contextId', 'messageId']))) {
|
|
307
|
-
fail('COGNITIVE_REVISION_INVALID');
|
|
308
|
-
}
|
|
309
|
-
const normalizedSource = {
|
|
310
|
-
provider: safeId(source.provider),
|
|
311
|
-
channel_id: safeId(source.channelId),
|
|
312
|
-
actor_id: safeId(source.actorId),
|
|
313
|
-
context_id: safeId(source.contextId),
|
|
314
|
-
message_id: safeId(source.messageId),
|
|
315
|
-
};
|
|
316
|
-
if (Object.values(normalizedSource).some((value) => !value)) fail('COGNITIVE_REVISION_INVALID');
|
|
317
|
-
const value = correction ? cleanLabel(input.value, 512) : 'withdrawn';
|
|
318
|
-
if (!value) fail('COGNITIVE_REVISION_INVALID');
|
|
319
|
-
const eventId = digestId('revision', [tenant, agent, kind, requestId]);
|
|
320
|
-
const observationId = digestId('revisionobs', [eventId]);
|
|
321
|
-
const observation = {
|
|
322
|
-
observation_id: observationId,
|
|
323
|
-
domain,
|
|
324
|
-
key,
|
|
325
|
-
value,
|
|
326
|
-
confidence: 1,
|
|
327
|
-
epistemic_state: 'verified',
|
|
328
|
-
scope,
|
|
329
|
-
...(correction ? { supersedes: targetObservationId } : { withdraws: targetObservationId }),
|
|
330
|
-
};
|
|
331
|
-
const normalizedOccurredAt = new Date(occurredAt).toISOString();
|
|
332
|
-
const receivedAt = stageTime(`revision:${kind}:${requestId}`);
|
|
333
|
-
const revisionMemoryAccess = {
|
|
334
|
-
tenantId: tenant,
|
|
335
|
-
userId: normalizedSource.actor_id,
|
|
336
|
-
actorId: normalizedSource.actor_id,
|
|
337
|
-
agentId: agent,
|
|
338
|
-
portalId: normalizedSource.provider,
|
|
339
|
-
channelId: normalizedSource.channel_id,
|
|
340
|
-
conversationId: normalizedSource.context_id,
|
|
341
|
-
requestedScope: scope,
|
|
342
|
-
permissionContext: {
|
|
343
|
-
authority: input.authority,
|
|
344
|
-
decision: 'passed',
|
|
345
|
-
receiptId: requestId,
|
|
346
|
-
},
|
|
347
|
-
};
|
|
348
|
-
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
349
|
-
const current = store.read({ tenantId: tenant, agentId: agent }, revisionMemoryAccess);
|
|
350
|
-
const existing = current.observations.find((item) => item.observation_id === observationId);
|
|
351
|
-
if (existing) {
|
|
352
|
-
const matches = existing.domain === observation.domain && existing.key === observation.key
|
|
353
|
-
&& existing.value === observation.value && existing.confidence === 1
|
|
354
|
-
&& existing.scope === observation.scope && existing.occurred_at === normalizedOccurredAt
|
|
355
|
-
&& existing.supersedes === (observation.supersedes ?? null)
|
|
356
|
-
&& existing.withdraws === (observation.withdraws ?? null)
|
|
357
|
-
&& existing.source.provider === normalizedSource.provider
|
|
358
|
-
&& existing.source.channel_id === normalizedSource.channel_id
|
|
359
|
-
&& existing.source.actor_id === normalizedSource.actor_id
|
|
360
|
-
&& existing.source.context_id === normalizedSource.context_id
|
|
361
|
-
&& existing.source.message_id === normalizedSource.message_id;
|
|
362
|
-
if (!matches) fail('COGNITIVE_REVISION_REQUEST_REUSE');
|
|
363
|
-
return { version: current.version, idempotent: true };
|
|
364
|
-
}
|
|
365
|
-
const target = current.observations.find((item) => item.observation_id === targetObservationId);
|
|
366
|
-
if (target && Date.parse(normalizedOccurredAt) < Date.parse(target.occurred_at)) {
|
|
367
|
-
fail('COGNITIVE_REVISION_TIME_ORDER');
|
|
368
|
-
}
|
|
369
|
-
try {
|
|
370
|
-
return store.commit({
|
|
371
|
-
tenantId: tenant,
|
|
372
|
-
agentId: agent,
|
|
373
|
-
eventId,
|
|
374
|
-
expectedVersion: current.version,
|
|
375
|
-
occurredAt: normalizedOccurredAt,
|
|
376
|
-
receivedAt,
|
|
377
|
-
retentionClass: 'durable',
|
|
378
|
-
source: normalizedSource,
|
|
379
|
-
observations: [observation],
|
|
380
|
-
}, revisionMemoryAccess);
|
|
381
|
-
} catch (error) {
|
|
382
|
-
if (error?.code !== 'COGNITIVE_VERSION_CONFLICT' || attempt === 3) throw error;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
fail('COGNITIVE_VERSION_CONFLICT');
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function correctFocusObservation(input) {
|
|
389
|
-
return commitExplicitFocusRevision('correction', input);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
function withdrawFocusObservation(input) {
|
|
393
|
-
return commitExplicitFocusRevision('withdrawal', input);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function toolFields(input, allowedKeys) {
|
|
397
|
-
if (!exactKeys(input, allowedKeys)) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
398
|
-
const turnId = safeTurnId(input.turnId);
|
|
399
|
-
const toolCallId = cleanLabel(input.toolCallId, 256);
|
|
400
|
-
const toolName = cleanLabel(input.toolName, 128);
|
|
401
|
-
if (turnId === null || !toolCallId || !toolName) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
402
|
-
return { turnId, toolCallId, toolName, callKey: digestId('call', [toolCallId]).slice(0, 21) };
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
function recordToolPolicy(input) {
|
|
406
|
-
const { turnId, toolCallId, toolName, callKey } = toolFields(input, new Set(['turnId', 'toolCallId', 'toolName', 'decision']));
|
|
407
|
-
const decision = String(input.decision ?? '');
|
|
408
|
-
if (!TOOL_POLICY_DECISIONS.has(decision)) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
409
|
-
return commitStage(`turn-${turnId}-${callKey}-policy`, [{
|
|
410
|
-
domain: 'world',
|
|
411
|
-
key: `turn:${turnId}:${callKey}:tool-policy`,
|
|
412
|
-
value: `${decision}:runtime_tool_policy:${toolName}`,
|
|
413
|
-
confidence: 1,
|
|
414
|
-
scope: 'runtime',
|
|
415
|
-
}]);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function recordToolResult(input) {
|
|
419
|
-
const { turnId, toolCallId, toolName, callKey } = toolFields(input, new Set(['turnId', 'toolCallId', 'toolName', 'outcome', 'durationMs']));
|
|
420
|
-
const outcome = String(input.outcome ?? '');
|
|
421
|
-
const durationMs = Number(input.durationMs);
|
|
422
|
-
if (!TOOL_OUTCOMES.has(outcome) || !Number.isSafeInteger(durationMs) || durationMs < 0) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
423
|
-
return commitStage(`turn-${turnId}-${callKey}-result`, [
|
|
424
|
-
{ domain: 'expected_evidence', key: `turn:${turnId}:${callKey}:tool-result`, value: `${outcome}:${durationMs}ms:${toolName}`, confidence: 1, scope: 'runtime' },
|
|
425
|
-
{ domain: 'next_trigger', key: `turn:${turnId}:${callKey}:tool-next`, value: outcome === 'success' ? 'continue-after-tool' : 'inspect-tool-failure', confidence: 1, scope: 'runtime' },
|
|
426
|
-
]);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function recordToolBatch(input) {
|
|
430
|
-
if (!exactKeys(input, new Set(['turnId', 'entries']))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
431
|
-
const turnId = safeTurnId(input.turnId);
|
|
432
|
-
if (turnId === null || !Array.isArray(input.entries) || input.entries.length < 1 || input.entries.length > 10) {
|
|
433
|
-
fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
434
|
-
}
|
|
435
|
-
const observations = [];
|
|
436
|
-
const stageParts = [];
|
|
437
|
-
for (const entry of input.entries) {
|
|
438
|
-
const { toolCallId, toolName, callKey } = toolFields(
|
|
439
|
-
{ turnId, ...entry },
|
|
440
|
-
new Set(['turnId', 'toolCallId', 'toolName', 'decision', 'outcome', 'durationMs']),
|
|
441
|
-
);
|
|
442
|
-
const decision = String(entry.decision ?? '');
|
|
443
|
-
const outcome = String(entry.outcome ?? '');
|
|
444
|
-
const durationMs = Number(entry.durationMs);
|
|
445
|
-
if (!TOOL_POLICY_DECISIONS.has(decision) || !TOOL_OUTCOMES.has(outcome)
|
|
446
|
-
|| !Number.isSafeInteger(durationMs) || durationMs < 0) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
447
|
-
stageParts.push(`${toolCallId}:${decision}:${outcome}:${durationMs}`);
|
|
448
|
-
observations.push({
|
|
449
|
-
domain: 'world',
|
|
450
|
-
key: `turn:${turnId}:${callKey}:tool-policy`,
|
|
451
|
-
value: `${decision}:runtime_tool_policy:${toolName}`,
|
|
452
|
-
confidence: 1,
|
|
453
|
-
scope: 'runtime',
|
|
454
|
-
}, {
|
|
455
|
-
domain: 'expected_evidence',
|
|
456
|
-
key: `turn:${turnId}:${callKey}:tool-result`,
|
|
457
|
-
value: `${outcome}:${durationMs}ms:${toolName}`,
|
|
458
|
-
confidence: 1,
|
|
459
|
-
scope: 'runtime',
|
|
460
|
-
}, {
|
|
461
|
-
domain: 'next_trigger',
|
|
462
|
-
key: `turn:${turnId}:${callKey}:tool-next`,
|
|
463
|
-
value: outcome === 'success' ? 'continue-after-tool' : 'inspect-tool-failure',
|
|
464
|
-
confidence: 1,
|
|
465
|
-
scope: 'runtime',
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
const batchKey = digestId('toolbatch', stageParts);
|
|
469
|
-
const result = commitStage(`turn-${turnId}-${batchKey}`, observations);
|
|
470
|
-
return { ...result, events: 1, entries: input.entries.length };
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function projectForTurn(input) {
|
|
474
|
-
if (!exactKeys(input, new Set(['turnId', 'focusScopes']))) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
475
|
-
const turnId = safeTurnId(input.turnId);
|
|
476
|
-
if (turnId === null) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
477
|
-
const state = store.read({ tenantId: tenant, agentId: agent }, internalMemoryAccess);
|
|
478
|
-
const continuity = buildCognitiveContextProjection(state, {
|
|
479
|
-
currentTurnId: turnId,
|
|
480
|
-
currentRuntimeId: runtime,
|
|
481
|
-
});
|
|
482
|
-
const focus = buildCognitiveFocusSelection(state, {
|
|
483
|
-
focusScopes: input.focusScopes,
|
|
484
|
-
currentSessionId: runtime,
|
|
485
|
-
});
|
|
486
|
-
if (focus?.selected.length > 0) {
|
|
487
|
-
const selected = [...focus.selected].sort((left, right) => (
|
|
488
|
-
cognitiveEntityKey(left).localeCompare(cognitiveEntityKey(right))
|
|
489
|
-
));
|
|
490
|
-
const accessKey = digestId('focusaccess', selected.map(cognitiveEntityKey));
|
|
491
|
-
commitStage(`focus-access-${accessKey}`, selected.map(focusAccessObservation));
|
|
492
|
-
}
|
|
493
|
-
return [focus?.text, continuity].filter(Boolean).join('\n\n') || null;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
function evaluateDecisionBasis(refs) {
|
|
497
|
-
const state = store.read({ tenantId: tenant, agentId: agent }, internalMemoryAccess);
|
|
498
|
-
return evaluateCognitiveDecisionBasis(state, refs);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
function authorizeAttention(input) {
|
|
502
|
-
const candidate = input?.candidate;
|
|
503
|
-
const authorization = input?.authorization;
|
|
504
|
-
const memoryAccess = {
|
|
505
|
-
tenantId: tenant,
|
|
506
|
-
userId: agent,
|
|
507
|
-
actorId: agent,
|
|
508
|
-
agentId: agent,
|
|
509
|
-
portalId: 'cli',
|
|
510
|
-
channelId: String(input?.channel ?? ''),
|
|
511
|
-
conversationId: runtime,
|
|
512
|
-
requestedScope: String(candidate?.evidence_scope ?? ''),
|
|
513
|
-
permissionContext: {
|
|
514
|
-
authority: String(authorization?.authority ?? ''),
|
|
515
|
-
decision: authorization?.decision === 'passed' ? 'passed' : 'blocked',
|
|
516
|
-
receiptId: String(authorization?.receiptId ?? ''),
|
|
517
|
-
},
|
|
518
|
-
};
|
|
519
|
-
return authorizeAttentionCandidate({
|
|
520
|
-
store,
|
|
521
|
-
tenantId: tenant,
|
|
522
|
-
currentAgent: agent,
|
|
523
|
-
now,
|
|
524
|
-
input,
|
|
525
|
-
memoryAccess,
|
|
526
|
-
});
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
function memoryStatus() {
|
|
530
|
-
const verification = store.verify({ tenantId: tenant, agentId: agent }, internalMemoryAccess);
|
|
531
|
-
const valid = verification?.valid === true;
|
|
532
|
-
let crossPortalStatus = 'provider-configured-unverified';
|
|
533
|
-
if (memoryMode === 'profile-local-fallback') crossPortalStatus = 'blocked-profile-local';
|
|
534
|
-
else if (identityMode === 'profile-derived') crossPortalStatus = 'blocked-profile-derived-identity';
|
|
535
|
-
return {
|
|
536
|
-
version: 1,
|
|
537
|
-
authority: 'diagnostic-only',
|
|
538
|
-
adapter: {
|
|
539
|
-
mode: memoryMode,
|
|
540
|
-
kind: store.kind,
|
|
541
|
-
contractVersion: store.contractVersion,
|
|
542
|
-
},
|
|
543
|
-
identity: { mode: identityMode },
|
|
544
|
-
integrity: { valid },
|
|
545
|
-
crossPortal: {
|
|
546
|
-
status: crossPortalStatus,
|
|
547
|
-
evidence: 'not-run',
|
|
548
|
-
},
|
|
549
|
-
};
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return {
|
|
553
|
-
startTurn,
|
|
554
|
-
recordRightsCheck,
|
|
555
|
-
recordToolPolicy,
|
|
556
|
-
recordToolResult,
|
|
557
|
-
recordToolBatch,
|
|
558
|
-
recordFocusSnapshot,
|
|
559
|
-
correctFocusObservation,
|
|
560
|
-
withdrawFocusObservation,
|
|
561
|
-
authorizeAttention,
|
|
562
|
-
memoryStatus,
|
|
563
|
-
evaluateDecisionBasis,
|
|
564
|
-
projectForTurn,
|
|
565
|
-
endTurn,
|
|
566
|
-
read: () => store.read({ tenantId: tenant, agentId: agent }, internalMemoryAccess),
|
|
567
|
-
verify: () => store.verify({ tenantId: tenant, agentId: agent }, internalMemoryAccess),
|
|
568
|
-
close: () => store.close(),
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
function createRuntimeCognitiveTurnLifecycle({
|
|
573
|
-
home,
|
|
574
|
-
agentName,
|
|
575
|
-
tenantId,
|
|
576
|
-
agentId,
|
|
577
|
-
runtimeId,
|
|
578
|
-
memoryAdapter,
|
|
579
|
-
memoryAdapterModule,
|
|
580
|
-
now,
|
|
581
|
-
} = {}) {
|
|
582
|
-
const resolvedHome = String(home ?? '').trim();
|
|
583
|
-
const resolvedAgent = String(agentName ?? '').trim();
|
|
584
|
-
if (!resolvedHome || !resolvedAgent) fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
585
|
-
const explicitTenant = tenantId === undefined ? '' : safeId(tenantId);
|
|
586
|
-
const explicitAgent = agentId === undefined ? '' : safeId(agentId);
|
|
587
|
-
if ((tenantId !== undefined && !explicitTenant) || (agentId !== undefined && !explicitAgent)) {
|
|
588
|
-
fail('COGNITIVE_LIFECYCLE_INVALID');
|
|
589
|
-
}
|
|
590
|
-
const manifestIdentity = identityFromManifest(resolvedHome);
|
|
591
|
-
const identity = {
|
|
592
|
-
tenantId: explicitTenant || manifestIdentity?.tenantId || '',
|
|
593
|
-
agentId: explicitAgent || manifestIdentity?.agentId || '',
|
|
594
|
-
};
|
|
595
|
-
const hasSharedIdentity = Boolean(identity.tenantId && identity.agentId);
|
|
596
|
-
const resolvedTenantId = hasSharedIdentity
|
|
597
|
-
? identity.tenantId : digestId('home', [resolvedHome.toLowerCase()]);
|
|
598
|
-
const resolvedAgentId = hasSharedIdentity
|
|
599
|
-
? identity.agentId : digestId('agent', [resolvedAgent.toLowerCase()]);
|
|
600
|
-
const resolvedMemoryAdapter = memoryAdapter === undefined
|
|
601
|
-
? loadConfiguredCognitiveMemoryAdapter({
|
|
602
|
-
modulePath: memoryAdapterModule,
|
|
603
|
-
home: resolvedHome,
|
|
604
|
-
tenantId: resolvedTenantId,
|
|
605
|
-
agentId: resolvedAgentId,
|
|
606
|
-
agentName: resolvedAgent,
|
|
607
|
-
})
|
|
608
|
-
: memoryAdapter;
|
|
609
|
-
const memoryMode = memoryAdapter !== undefined
|
|
610
|
-
? 'injected-adapter'
|
|
611
|
-
: resolvedMemoryAdapter === undefined ? 'profile-local-fallback' : 'configured-provider';
|
|
612
|
-
return createCognitiveTurnLifecycle({
|
|
613
|
-
home: resolvedHome,
|
|
614
|
-
tenantId: resolvedTenantId,
|
|
615
|
-
agentId: resolvedAgentId,
|
|
616
|
-
runtimeId,
|
|
617
|
-
memoryAdapter: resolvedMemoryAdapter,
|
|
618
|
-
memoryMode,
|
|
619
|
-
identityMode: hasSharedIdentity ? 'shared-identity' : 'profile-derived',
|
|
620
|
-
now,
|
|
621
|
-
});
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
module.exports = { createCognitiveTurnLifecycle, createRuntimeCognitiveTurnLifecycle };
|