@askdkc/kiokuko 0.1.16 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +91 -112
- package/README.ko.md +90 -102
- package/README.md +103 -260
- package/README.zh-CN.md +88 -102
- package/dist/agent-file/atomic-write.d.ts +90 -3
- package/dist/agent-file/atomic-write.d.ts.map +1 -1
- package/dist/agent-file/atomic-write.js +990 -14
- package/dist/agent-file/atomic-write.js.map +1 -1
- package/dist/agent-file/managed-block.d.ts +12 -1
- package/dist/agent-file/managed-block.d.ts.map +1 -1
- package/dist/agent-file/managed-block.js +49 -4
- package/dist/agent-file/managed-block.js.map +1 -1
- package/dist/agent-file/render.d.ts +1 -1
- package/dist/agent-file/render.d.ts.map +1 -1
- package/dist/agent-file/render.js +10 -7
- package/dist/agent-file/render.js.map +1 -1
- package/dist/akinator/agent-task.d.ts +14 -24
- package/dist/akinator/agent-task.d.ts.map +1 -1
- package/dist/akinator/agent-task.js +460 -103
- package/dist/akinator/agent-task.js.map +1 -1
- package/dist/akinator/capabilities.d.ts +52 -7
- package/dist/akinator/capabilities.d.ts.map +1 -1
- package/dist/akinator/capabilities.js +226 -28
- package/dist/akinator/capabilities.js.map +1 -1
- package/dist/akinator/capability-binding.d.ts +11 -0
- package/dist/akinator/capability-binding.d.ts.map +1 -0
- package/dist/akinator/capability-binding.js +56 -0
- package/dist/akinator/capability-binding.js.map +1 -0
- package/dist/akinator/domain.js +2 -2
- package/dist/akinator/domain.js.map +1 -1
- package/dist/akinator/knowledge-path.d.ts.map +1 -1
- package/dist/akinator/knowledge-path.js +409 -39
- package/dist/akinator/knowledge-path.js.map +1 -1
- package/dist/akinator/orchestrator.d.ts +3 -4
- package/dist/akinator/orchestrator.d.ts.map +1 -1
- package/dist/akinator/orchestrator.js +1 -4
- package/dist/akinator/orchestrator.js.map +1 -1
- package/dist/akinator/service.d.ts +0 -4
- package/dist/akinator/service.d.ts.map +1 -1
- package/dist/akinator/service.js +19 -35
- package/dist/akinator/service.js.map +1 -1
- package/dist/akinator/skill-discovery-attempt.d.ts +20 -0
- package/dist/akinator/skill-discovery-attempt.d.ts.map +1 -0
- package/dist/akinator/skill-discovery-attempt.js +390 -0
- package/dist/akinator/skill-discovery-attempt.js.map +1 -0
- package/dist/akinator/store.d.ts.map +1 -1
- package/dist/akinator/store.js +107 -52
- package/dist/akinator/store.js.map +1 -1
- package/dist/akinator/types.d.ts +0 -12
- package/dist/akinator/types.d.ts.map +1 -1
- package/dist/bin/kiokuko.js +0 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +561 -144
- package/dist/cli.js.map +1 -1
- package/dist/client/server-client.d.ts +5 -3
- package/dist/client/server-client.d.ts.map +1 -1
- package/dist/client/server-client.js +486 -181
- package/dist/client/server-client.js.map +1 -1
- package/dist/commands/agent.d.ts +2 -0
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +861 -86
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/backup.d.ts +2 -1
- package/dist/commands/backup.d.ts.map +1 -1
- package/dist/commands/backup.js +64 -8
- package/dist/commands/backup.js.map +1 -1
- package/dist/commands/doctor.d.ts +5 -1
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +70 -26
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/export.d.ts +0 -4
- package/dist/commands/export.d.ts.map +1 -1
- package/dist/commands/export.js +191 -32
- package/dist/commands/export.js.map +1 -1
- package/dist/commands/import.d.ts +10 -1
- package/dist/commands/import.d.ts.map +1 -1
- package/dist/commands/import.js +592 -113
- package/dist/commands/import.js.map +1 -1
- package/dist/commands/init.d.ts +19 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +569 -22
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/purge.d.ts.map +1 -1
- package/dist/commands/purge.js +3 -0
- package/dist/commands/purge.js.map +1 -1
- package/dist/commands/setup.d.ts +34 -8
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +418 -86
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/skills.d.ts +9 -0
- package/dist/commands/skills.d.ts.map +1 -0
- package/dist/commands/skills.js +317 -0
- package/dist/commands/skills.js.map +1 -0
- package/dist/commands/use.d.ts +10 -2
- package/dist/commands/use.d.ts.map +1 -1
- package/dist/commands/use.js +851 -73
- package/dist/commands/use.js.map +1 -1
- package/dist/config/paths.d.ts +11 -1
- package/dist/config/paths.d.ts.map +1 -1
- package/dist/config/paths.js +64 -29
- package/dist/config/paths.js.map +1 -1
- package/dist/config/project-config.d.ts +1 -0
- package/dist/config/project-config.d.ts.map +1 -1
- package/dist/config/project-config.js +70 -32
- package/dist/config/project-config.js.map +1 -1
- package/dist/context/broker.d.ts +30 -14
- package/dist/context/broker.d.ts.map +1 -1
- package/dist/context/broker.js +628 -150
- package/dist/context/broker.js.map +1 -1
- package/dist/context/delivery.d.ts +8 -22
- package/dist/context/delivery.d.ts.map +1 -1
- package/dist/context/delivery.js +204 -152
- package/dist/context/delivery.js.map +1 -1
- package/dist/context/feedback.d.ts +11 -12
- package/dist/context/feedback.d.ts.map +1 -1
- package/dist/context/feedback.js +250 -268
- package/dist/context/feedback.js.map +1 -1
- package/dist/context/origin.d.ts +9 -0
- package/dist/context/origin.d.ts.map +1 -0
- package/dist/context/origin.js +15 -0
- package/dist/context/origin.js.map +1 -0
- package/dist/context/ranking.d.ts +4 -13
- package/dist/context/ranking.d.ts.map +1 -1
- package/dist/context/ranking.js +21 -5
- package/dist/context/ranking.js.map +1 -1
- package/dist/context/recommendations.d.ts +0 -5
- package/dist/context/recommendations.d.ts.map +1 -1
- package/dist/context/recommendations.js +0 -1
- package/dist/context/recommendations.js.map +1 -1
- package/dist/context/run-state.d.ts +26 -0
- package/dist/context/run-state.d.ts.map +1 -0
- package/dist/context/run-state.js +399 -0
- package/dist/context/run-state.js.map +1 -0
- package/dist/context/scoped-broker.d.ts +19 -6
- package/dist/context/scoped-broker.d.ts.map +1 -1
- package/dist/context/scoped-broker.js +530 -131
- package/dist/context/scoped-broker.js.map +1 -1
- package/dist/context/selection-state.d.ts +19 -0
- package/dist/context/selection-state.d.ts.map +1 -0
- package/dist/context/selection-state.js +250 -0
- package/dist/context/selection-state.js.map +1 -0
- package/dist/db/adapter.d.ts +5 -3
- package/dist/db/adapter.d.ts.map +1 -1
- package/dist/db/adapter.js +6 -3
- package/dist/db/adapter.js.map +1 -1
- package/dist/db/capabilities.d.ts.map +1 -1
- package/dist/db/capabilities.js +34 -16
- package/dist/db/capabilities.js.map +1 -1
- package/dist/db/connection.d.ts +8 -0
- package/dist/db/connection.d.ts.map +1 -1
- package/dist/db/connection.js +55 -26
- package/dist/db/connection.js.map +1 -1
- package/dist/db/migrate.d.ts +28 -7
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +106 -78
- package/dist/db/migrate.js.map +1 -1
- package/dist/db/sqlite-retry.d.ts +11 -0
- package/dist/db/sqlite-retry.d.ts.map +1 -0
- package/dist/db/sqlite-retry.js +66 -0
- package/dist/db/sqlite-retry.js.map +1 -0
- package/dist/db/transaction.d.ts +13 -0
- package/dist/db/transaction.d.ts.map +1 -1
- package/dist/db/transaction.js +53 -24
- package/dist/db/transaction.js.map +1 -1
- package/dist/db/upgrade-backup.d.ts +58 -2
- package/dist/db/upgrade-backup.d.ts.map +1 -1
- package/dist/db/upgrade-backup.js +757 -28
- package/dist/db/upgrade-backup.js.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/gateway/agent-service.d.ts +4 -1
- package/dist/gateway/agent-service.d.ts.map +1 -1
- package/dist/gateway/agent-service.js +71 -58
- package/dist/gateway/agent-service.js.map +1 -1
- package/dist/gateway/checkpoint-service.d.ts +1 -0
- package/dist/gateway/checkpoint-service.d.ts.map +1 -1
- package/dist/gateway/checkpoint-service.js +47 -24
- package/dist/gateway/checkpoint-service.js.map +1 -1
- package/dist/ledger/archive.d.ts +1 -4
- package/dist/ledger/archive.d.ts.map +1 -1
- package/dist/ledger/archive.js +134 -54
- package/dist/ledger/archive.js.map +1 -1
- package/dist/ledger/maintenance.d.ts +0 -11
- package/dist/ledger/maintenance.d.ts.map +1 -1
- package/dist/ledger/maintenance.js +41 -44
- package/dist/ledger/maintenance.js.map +1 -1
- package/dist/ledger/projection.d.ts +0 -1
- package/dist/ledger/projection.d.ts.map +1 -1
- package/dist/ledger/projection.js.map +1 -1
- package/dist/ledger/promotion.d.ts +0 -9
- package/dist/ledger/promotion.d.ts.map +1 -1
- package/dist/ledger/promotion.js.map +1 -1
- package/dist/ledger/query.d.ts +1 -15
- package/dist/ledger/query.d.ts.map +1 -1
- package/dist/ledger/query.js.map +1 -1
- package/dist/ledger/store.d.ts +0 -1
- package/dist/ledger/store.d.ts.map +1 -1
- package/dist/ledger/store.js +11 -8
- package/dist/ledger/store.js.map +1 -1
- package/dist/ledger/types.d.ts +0 -4
- package/dist/ledger/types.d.ts.map +1 -1
- package/dist/ledger/types.js.map +1 -1
- package/dist/ledger/validate.d.ts.map +1 -1
- package/dist/ledger/validate.js +0 -5
- package/dist/ledger/validate.js.map +1 -1
- package/dist/mcp/bounded-stdio-transport.d.ts +23 -0
- package/dist/mcp/bounded-stdio-transport.d.ts.map +1 -0
- package/dist/mcp/bounded-stdio-transport.js +109 -0
- package/dist/mcp/bounded-stdio-transport.js.map +1 -0
- package/dist/mcp/server.d.ts +4 -0
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +111 -75
- package/dist/mcp/server.js.map +1 -1
- package/dist/memory/audit.d.ts +0 -1
- package/dist/memory/audit.d.ts.map +1 -1
- package/dist/memory/audit.js +0 -1
- package/dist/memory/audit.js.map +1 -1
- package/dist/memory/curator.d.ts +45 -1
- package/dist/memory/curator.d.ts.map +1 -1
- package/dist/memory/curator.js +290 -68
- package/dist/memory/curator.js.map +1 -1
- package/dist/memory/entries.d.ts +12 -2
- package/dist/memory/entries.d.ts.map +1 -1
- package/dist/memory/entries.js +198 -114
- package/dist/memory/entries.js.map +1 -1
- package/dist/memory/federated-retrieval.d.ts +78 -0
- package/dist/memory/federated-retrieval.d.ts.map +1 -0
- package/dist/memory/federated-retrieval.js +441 -0
- package/dist/memory/federated-retrieval.js.map +1 -0
- package/dist/memory/hybrid-retrieval.d.ts +5 -11
- package/dist/memory/hybrid-retrieval.d.ts.map +1 -1
- package/dist/memory/hybrid-retrieval.js +78 -58
- package/dist/memory/hybrid-retrieval.js.map +1 -1
- package/dist/memory/lifecycle.d.ts.map +1 -1
- package/dist/memory/lifecycle.js +17 -13
- package/dist/memory/lifecycle.js.map +1 -1
- package/dist/memory/portability.d.ts +10 -0
- package/dist/memory/portability.d.ts.map +1 -0
- package/dist/memory/portability.js +44 -0
- package/dist/memory/portability.js.map +1 -0
- package/dist/memory/rebuild-search.d.ts +5 -0
- package/dist/memory/rebuild-search.d.ts.map +1 -1
- package/dist/memory/rebuild-search.js +101 -76
- package/dist/memory/rebuild-search.js.map +1 -1
- package/dist/memory/retrieval-query.d.ts +0 -5
- package/dist/memory/retrieval-query.d.ts.map +1 -1
- package/dist/memory/retrieval-query.js +0 -5
- package/dist/memory/retrieval-query.js.map +1 -1
- package/dist/memory/retrieval.d.ts +11 -0
- package/dist/memory/retrieval.d.ts.map +1 -1
- package/dist/memory/retrieval.js +34 -120
- package/dist/memory/retrieval.js.map +1 -1
- package/dist/memory/revisions.d.ts +76 -1
- package/dist/memory/revisions.d.ts.map +1 -1
- package/dist/memory/revisions.js +539 -35
- package/dist/memory/revisions.js.map +1 -1
- package/dist/memory/scoped-memory.d.ts +22 -13
- package/dist/memory/scoped-memory.d.ts.map +1 -1
- package/dist/memory/scoped-memory.js +248 -139
- package/dist/memory/scoped-memory.js.map +1 -1
- package/dist/memory/secrets.d.ts +2 -0
- package/dist/memory/secrets.d.ts.map +1 -1
- package/dist/memory/secrets.js +36 -0
- package/dist/memory/secrets.js.map +1 -1
- package/dist/memory/structured-memory.d.ts +8 -1
- package/dist/memory/structured-memory.d.ts.map +1 -1
- package/dist/memory/structured-memory.js +74 -20
- package/dist/memory/structured-memory.js.map +1 -1
- package/dist/memory/workspaces.d.ts +9 -0
- package/dist/memory/workspaces.d.ts.map +1 -1
- package/dist/memory/workspaces.js +67 -0
- package/dist/memory/workspaces.js.map +1 -1
- package/dist/package-version.d.ts +2 -0
- package/dist/package-version.d.ts.map +1 -0
- package/dist/package-version.js +7 -0
- package/dist/package-version.js.map +1 -0
- package/dist/repository/binding.d.ts +5 -0
- package/dist/repository/binding.d.ts.map +1 -1
- package/dist/repository/binding.js +117 -17
- package/dist/repository/binding.js.map +1 -1
- package/dist/repository/framework-version.d.ts +8 -0
- package/dist/repository/framework-version.d.ts.map +1 -0
- package/dist/repository/framework-version.js +29 -0
- package/dist/repository/framework-version.js.map +1 -0
- package/dist/repository/identity-value.d.ts +4 -0
- package/dist/repository/identity-value.d.ts.map +1 -0
- package/dist/repository/identity-value.js +24 -0
- package/dist/repository/identity-value.js.map +1 -0
- package/dist/repository/identity.d.ts.map +1 -1
- package/dist/repository/identity.js +2 -0
- package/dist/repository/identity.js.map +1 -1
- package/dist/repository/project-fingerprint.d.ts +33 -0
- package/dist/repository/project-fingerprint.d.ts.map +1 -0
- package/dist/repository/project-fingerprint.js +429 -0
- package/dist/repository/project-fingerprint.js.map +1 -0
- package/dist/repository/remote-url.d.ts +0 -1
- package/dist/repository/remote-url.d.ts.map +1 -1
- package/dist/repository/remote-url.js +0 -1
- package/dist/repository/remote-url.js.map +1 -1
- package/dist/runtime-version.d.ts +2 -1
- package/dist/runtime-version.d.ts.map +1 -1
- package/dist/runtime-version.js +21 -4
- package/dist/runtime-version.js.map +1 -1
- package/dist/serialization/boundary-json.d.ts +20 -0
- package/dist/serialization/boundary-json.d.ts.map +1 -0
- package/dist/serialization/boundary-json.js +129 -0
- package/dist/serialization/boundary-json.js.map +1 -0
- package/dist/serialization/envelope.js +1 -1
- package/dist/serialization/envelope.js.map +1 -1
- package/dist/serialization/validate.d.ts +7 -0
- package/dist/serialization/validate.d.ts.map +1 -1
- package/dist/serialization/validate.js +53 -13
- package/dist/serialization/validate.js.map +1 -1
- package/dist/server/app.js +1 -1
- package/dist/server/app.js.map +1 -1
- package/dist/server/http.d.ts +4 -3
- package/dist/server/http.d.ts.map +1 -1
- package/dist/server/http.js +90 -50
- package/dist/server/http.js.map +1 -1
- package/dist/server/idempotency.d.ts +0 -6
- package/dist/server/idempotency.d.ts.map +1 -1
- package/dist/server/idempotency.js.map +1 -1
- package/dist/server/router.d.ts.map +1 -1
- package/dist/server/router.js +21 -4
- package/dist/server/router.js.map +1 -1
- package/dist/server/routes/agent-capability-gate.d.ts +40 -0
- package/dist/server/routes/agent-capability-gate.d.ts.map +1 -0
- package/dist/server/routes/agent-capability-gate.js +182 -0
- package/dist/server/routes/agent-capability-gate.js.map +1 -0
- package/dist/server/routes/agent-events.d.ts.map +1 -1
- package/dist/server/routes/agent-events.js +8 -1
- package/dist/server/routes/agent-events.js.map +1 -1
- package/dist/server/routes/agent-intake.d.ts.map +1 -1
- package/dist/server/routes/agent-intake.js +10 -2
- package/dist/server/routes/agent-intake.js.map +1 -1
- package/dist/server/routes/agent-promotions.d.ts.map +1 -1
- package/dist/server/routes/agent-promotions.js +5 -2
- package/dist/server/routes/agent-promotions.js.map +1 -1
- package/dist/server/routes/agent-runs.d.ts.map +1 -1
- package/dist/server/routes/agent-runs.js +18 -4
- package/dist/server/routes/agent-runs.js.map +1 -1
- package/dist/server/routes/request-binding.d.ts +5 -0
- package/dist/server/routes/request-binding.d.ts.map +1 -0
- package/dist/server/routes/request-binding.js +49 -0
- package/dist/server/routes/request-binding.js.map +1 -0
- package/dist/server/routes/task5-support.d.ts +1 -8
- package/dist/server/routes/task5-support.d.ts.map +1 -1
- package/dist/server/routes/task5-support.js +1 -17
- package/dist/server/routes/task5-support.js.map +1 -1
- package/dist/server/routes/task5.d.ts.map +1 -1
- package/dist/server/routes/task5.js +106 -36
- package/dist/server/routes/task5.js.map +1 -1
- package/dist/server/write-queue.js +2 -2
- package/dist/server/write-queue.js.map +1 -1
- package/dist/setup/claude-config.d.ts +2 -1
- package/dist/setup/claude-config.d.ts.map +1 -1
- package/dist/setup/claude-config.js +54 -4
- package/dist/setup/claude-config.js.map +1 -1
- package/dist/setup/client-detection.d.ts +7 -2
- package/dist/setup/client-detection.d.ts.map +1 -1
- package/dist/setup/client-detection.js +27 -9
- package/dist/setup/client-detection.js.map +1 -1
- package/dist/setup/hermes-config.d.ts +2 -1
- package/dist/setup/hermes-config.d.ts.map +1 -1
- package/dist/setup/hermes-config.js +53 -12
- package/dist/setup/hermes-config.js.map +1 -1
- package/dist/setup/legacy-client-cleanup.d.ts +6 -0
- package/dist/setup/legacy-client-cleanup.d.ts.map +1 -0
- package/dist/setup/legacy-client-cleanup.js +152 -0
- package/dist/setup/legacy-client-cleanup.js.map +1 -0
- package/dist/setup/managed-text.d.ts.map +1 -1
- package/dist/setup/managed-text.js +11 -1
- package/dist/setup/managed-text.js.map +1 -1
- package/dist/setup/opencode-config.d.ts +2 -1
- package/dist/setup/opencode-config.d.ts.map +1 -1
- package/dist/setup/opencode-config.js +57 -5
- package/dist/setup/opencode-config.js.map +1 -1
- package/dist/setup/render.d.ts +2 -1
- package/dist/setup/render.d.ts.map +1 -1
- package/dist/setup/render.js +91 -17
- package/dist/setup/render.js.map +1 -1
- package/dist/setup/standard-skills.d.ts +16 -2
- package/dist/setup/standard-skills.d.ts.map +1 -1
- package/dist/setup/standard-skills.js +37 -13
- package/dist/setup/standard-skills.js.map +1 -1
- package/dist/setup/strict-json.d.ts +7 -0
- package/dist/setup/strict-json.d.ts.map +1 -0
- package/dist/setup/strict-json.js +98 -0
- package/dist/setup/strict-json.js.map +1 -0
- package/dist/setup/strict-toml.d.ts +7 -0
- package/dist/setup/strict-toml.d.ts.map +1 -0
- package/dist/setup/strict-toml.js +470 -0
- package/dist/setup/strict-toml.js.map +1 -0
- package/dist/skills/cache.d.ts +15 -0
- package/dist/skills/cache.d.ts.map +1 -0
- package/dist/skills/cache.js +19 -0
- package/dist/skills/cache.js.map +1 -0
- package/dist/skills/candidate-ranking.d.ts +15 -0
- package/dist/skills/candidate-ranking.d.ts.map +1 -0
- package/dist/skills/candidate-ranking.js +52 -0
- package/dist/skills/candidate-ranking.js.map +1 -0
- package/dist/skills/chunking.d.ts +11 -0
- package/dist/skills/chunking.d.ts.map +1 -0
- package/dist/skills/chunking.js +291 -0
- package/dist/skills/chunking.js.map +1 -0
- package/dist/skills/config.d.ts +19 -0
- package/dist/skills/config.d.ts.map +1 -0
- package/dist/skills/config.js +103 -0
- package/dist/skills/config.js.map +1 -0
- package/dist/skills/discovery-service.d.ts +26 -0
- package/dist/skills/discovery-service.d.ts.map +1 -0
- package/dist/skills/discovery-service.js +921 -0
- package/dist/skills/discovery-service.js.map +1 -0
- package/dist/skills/external-transport.d.ts +2 -0
- package/dist/skills/external-transport.d.ts.map +1 -0
- package/dist/skills/external-transport.js +30 -0
- package/dist/skills/external-transport.js.map +1 -0
- package/dist/skills/find.d.ts +16 -0
- package/dist/skills/find.d.ts.map +1 -0
- package/dist/skills/find.js +58 -0
- package/dist/skills/find.js.map +1 -0
- package/dist/skills/gap-detection.d.ts +23 -0
- package/dist/skills/gap-detection.d.ts.map +1 -0
- package/dist/skills/gap-detection.js +62 -0
- package/dist/skills/gap-detection.js.map +1 -0
- package/dist/skills/import-preparation.d.ts +4 -0
- package/dist/skills/import-preparation.d.ts.map +1 -0
- package/dist/skills/import-preparation.js +20 -0
- package/dist/skills/import-preparation.js.map +1 -0
- package/dist/skills/materialization-authority.d.ts +11 -0
- package/dist/skills/materialization-authority.d.ts.map +1 -0
- package/dist/skills/materialization-authority.js +92 -0
- package/dist/skills/materialization-authority.js.map +1 -0
- package/dist/skills/materialization-service.d.ts +22 -0
- package/dist/skills/materialization-service.d.ts.map +1 -0
- package/dist/skills/materialization-service.js +101 -0
- package/dist/skills/materialization-service.js.map +1 -0
- package/dist/skills/official-catalog.d.ts +31 -0
- package/dist/skills/official-catalog.d.ts.map +1 -0
- package/dist/skills/official-catalog.js +110 -0
- package/dist/skills/official-catalog.js.map +1 -0
- package/dist/skills/providers/schema.d.ts +30 -0
- package/dist/skills/providers/schema.d.ts.map +1 -0
- package/dist/skills/providers/schema.js +354 -0
- package/dist/skills/providers/schema.js.map +1 -0
- package/dist/skills/providers/skills-sh-compat.d.ts +17 -0
- package/dist/skills/providers/skills-sh-compat.d.ts.map +1 -0
- package/dist/skills/providers/skills-sh-compat.js +71 -0
- package/dist/skills/providers/skills-sh-compat.js.map +1 -0
- package/dist/skills/providers/skills-sh-v1.d.ts +23 -0
- package/dist/skills/providers/skills-sh-v1.d.ts.map +1 -0
- package/dist/skills/providers/skills-sh-v1.js +134 -0
- package/dist/skills/providers/skills-sh-v1.js.map +1 -0
- package/dist/skills/query-builder.d.ts +18 -0
- package/dist/skills/query-builder.d.ts.map +1 -0
- package/dist/skills/query-builder.js +93 -0
- package/dist/skills/query-builder.js.map +1 -0
- package/dist/skills/source/errors.d.ts +9 -0
- package/dist/skills/source/errors.d.ts.map +1 -0
- package/dist/skills/source/errors.js +15 -0
- package/dist/skills/source/errors.js.map +1 -0
- package/dist/skills/source/frontmatter.d.ts +9 -0
- package/dist/skills/source/frontmatter.d.ts.map +1 -0
- package/dist/skills/source/frontmatter.js +77 -0
- package/dist/skills/source/frontmatter.js.map +1 -0
- package/dist/skills/source/github-fetcher.d.ts +20 -0
- package/dist/skills/source/github-fetcher.d.ts.map +1 -0
- package/dist/skills/source/github-fetcher.js +292 -0
- package/dist/skills/source/github-fetcher.js.map +1 -0
- package/dist/skills/source/snapshot-validator.d.ts +28 -0
- package/dist/skills/source/snapshot-validator.d.ts.map +1 -0
- package/dist/skills/source/snapshot-validator.js +186 -0
- package/dist/skills/source/snapshot-validator.js.map +1 -0
- package/dist/skills/store.d.ts +181 -0
- package/dist/skills/store.d.ts.map +1 -0
- package/dist/skills/store.js +1710 -0
- package/dist/skills/store.js.map +1 -0
- package/dist/skills/types.d.ts +169 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +2 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/web/i18n.d.ts +56 -8
- package/dist/web/i18n.d.ts.map +1 -1
- package/dist/web/i18n.js +224 -32
- package/dist/web/i18n.js.map +1 -1
- package/dist/web/server.d.ts.map +1 -1
- package/dist/web/server.js +458 -42
- package/dist/web/server.js.map +1 -1
- package/dist/web/ui.d.ts +4 -0
- package/dist/web/ui.d.ts.map +1 -1
- package/dist/web/ui.js +697 -61
- package/dist/web/ui.js.map +1 -1
- package/migrations/008_federated_memory.sql +46 -0
- package/migrations/009_external_skill_discovery.sql +126 -0
- package/package.json +6 -3
- package/skills/kiokuko-single-purpose-functions/SKILL.md +288 -0
- package/skills/kiokuko-single-purpose-functions/references/kiokuko-patterns.md +344 -0
- package/skills/kiokuko-single-purpose-functions/references/review-checklist.md +97 -0
- package/skills/kiokuko-ui-design-soul/SKILL.md +1186 -28
- package/templates/AGENTS.md +8 -7
- package/dist/client/runtime-discovery.d.ts +0 -15
- package/dist/client/runtime-discovery.d.ts.map +0 -1
- package/dist/client/runtime-discovery.js +0 -45
- package/dist/client/runtime-discovery.js.map +0 -1
- package/dist/commands/call.d.ts +0 -7
- package/dist/commands/call.d.ts.map +0 -1
- package/dist/commands/call.js +0 -10
- package/dist/commands/call.js.map +0 -1
- package/dist/commands/link.d.ts +0 -6
- package/dist/commands/link.d.ts.map +0 -1
- package/dist/commands/link.js +0 -6
- package/dist/commands/link.js.map +0 -1
- package/dist/commands/promote.d.ts +0 -6
- package/dist/commands/promote.d.ts.map +0 -1
- package/dist/commands/promote.js +0 -6
- package/dist/commands/promote.js.map +0 -1
- package/dist/commands/read.d.ts +0 -6
- package/dist/commands/read.d.ts.map +0 -1
- package/dist/commands/read.js +0 -4
- package/dist/commands/read.js.map +0 -1
- package/dist/commands/recall.d.ts +0 -6
- package/dist/commands/recall.d.ts.map +0 -1
- package/dist/commands/recall.js +0 -4
- package/dist/commands/recall.js.map +0 -1
- package/dist/commands/record.d.ts +0 -6
- package/dist/commands/record.d.ts.map +0 -1
- package/dist/commands/record.js +0 -4
- package/dist/commands/record.js.map +0 -1
- package/dist/commands/search.d.ts +0 -6
- package/dist/commands/search.d.ts.map +0 -1
- package/dist/commands/search.js +0 -4
- package/dist/commands/search.js.map +0 -1
- package/dist/commands/supersede.d.ts +0 -6
- package/dist/commands/supersede.d.ts.map +0 -1
- package/dist/commands/supersede.js +0 -6
- package/dist/commands/supersede.js.map +0 -1
- package/dist/knowledge/sources.d.ts +0 -72
- package/dist/knowledge/sources.d.ts.map +0 -1
- package/dist/knowledge/sources.js +0 -388
- package/dist/knowledge/sources.js.map +0 -1
- package/dist/setup/opencode-evidence.d.ts +0 -37
- package/dist/setup/opencode-evidence.d.ts.map +0 -1
- package/dist/setup/opencode-evidence.js +0 -58
- package/dist/setup/opencode-evidence.js.map +0 -1
- package/dist/setup/opencode-loop-guard.d.ts +0 -9
- package/dist/setup/opencode-loop-guard.d.ts.map +0 -1
- package/dist/setup/opencode-loop-guard.js +0 -248
- package/dist/setup/opencode-loop-guard.js.map +0 -1
|
@@ -1,16 +1,66 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { KiokukoError } from '../errors.js';
|
|
2
|
+
import { canonicalContentHash, compareCanonicalStrings } from '../serialization/validate.js';
|
|
3
3
|
import { readEntry } from '../memory/entries.js';
|
|
4
|
+
import { decodeStoredStructuredScope, readEntryRevision } from '../memory/revisions.js';
|
|
4
5
|
import { ensureGlobalWorkspace, GLOBAL_WORKSPACE, resolveProjectWorkspace } from '../memory/workspaces.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { federatedEntries } from '../memory/federated-retrieval.js';
|
|
7
|
+
import { isRetrievableEntry } from '../memory/hybrid-retrieval.js';
|
|
8
|
+
import { effectiveRetrievalScope, hasExplicitApplicability } from '../memory/structured-memory.js';
|
|
9
|
+
import { readContextDelivery, recordContextDeliveryInTransaction } from './delivery.js';
|
|
7
10
|
import { CONTEXT_SELECTION_REASON_ORDER } from './ranking.js';
|
|
8
|
-
|
|
11
|
+
import { withImmediateTransaction } from '../db/transaction.js';
|
|
12
|
+
import { contextFeedbackSignals } from './feedback.js';
|
|
13
|
+
import { captureProjectManifestSnapshot, resolveProjectFingerprint, } from '../repository/project-fingerprint.js';
|
|
14
|
+
import { entryOriginMatchesWorkspace } from './origin.js';
|
|
15
|
+
import { isExternalSkillReference } from '../skills/store.js';
|
|
16
|
+
import { contextRetrievalStateHash, ordinaryContextSelectionStateHash } from './selection-state.js';
|
|
17
|
+
import { readContextRunRetrievalState } from './run-state.js';
|
|
18
|
+
export const SCOPED_CONTEXT_POLICY_VERSION = 'context-ranking-v4';
|
|
19
|
+
export const SCOPED_CONTEXT_DEFAULT_CHARACTER_BUDGET = 8_000;
|
|
20
|
+
export const SCOPED_CONTEXT_MAX_CHARACTER_BUDGET = 100_000;
|
|
21
|
+
function normalizedScopedGateDecision(value) {
|
|
22
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
23
|
+
throw new TypeError('Scoped context gate returned an invalid decision');
|
|
24
|
+
}
|
|
25
|
+
const prototype = Object.getPrototypeOf(value);
|
|
26
|
+
const keys = Reflect.ownKeys(value);
|
|
27
|
+
if ((prototype !== Object.prototype && prototype !== null)
|
|
28
|
+
|| keys.some((key) => typeof key !== 'string'
|
|
29
|
+
|| key !== 'persist' && key !== 'value' && key !== 'assertBeforePersist')
|
|
30
|
+
|| !keys.includes('persist')
|
|
31
|
+
|| !keys.includes('value')) {
|
|
32
|
+
throw new TypeError('Scoped context gate returned an invalid decision');
|
|
33
|
+
}
|
|
34
|
+
const persistDescriptor = Object.getOwnPropertyDescriptor(value, 'persist');
|
|
35
|
+
const resultDescriptor = Object.getOwnPropertyDescriptor(value, 'value');
|
|
36
|
+
const assertionDescriptor = Object.getOwnPropertyDescriptor(value, 'assertBeforePersist');
|
|
37
|
+
if (persistDescriptor === undefined
|
|
38
|
+
|| !Object.hasOwn(persistDescriptor, 'value')
|
|
39
|
+
|| typeof persistDescriptor.value !== 'boolean'
|
|
40
|
+
|| resultDescriptor === undefined
|
|
41
|
+
|| !Object.hasOwn(resultDescriptor, 'value')
|
|
42
|
+
|| assertionDescriptor !== undefined
|
|
43
|
+
&& (!Object.hasOwn(assertionDescriptor, 'value') || typeof assertionDescriptor.value !== 'function')) {
|
|
44
|
+
throw new TypeError('Scoped context gate returned an invalid decision');
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
persist: persistDescriptor.value,
|
|
48
|
+
value: resultDescriptor.value,
|
|
49
|
+
...(assertionDescriptor === undefined
|
|
50
|
+
? {}
|
|
51
|
+
: { assertBeforePersist: assertionDescriptor.value }),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
9
54
|
const MAX_LIMIT = 100;
|
|
10
|
-
const MAX_BUDGET = 100_000;
|
|
11
55
|
function normalize(value) {
|
|
12
56
|
return value.normalize('NFKC').toLowerCase();
|
|
13
57
|
}
|
|
58
|
+
function characterCount(value) {
|
|
59
|
+
return Array.from(value).length;
|
|
60
|
+
}
|
|
61
|
+
function takeCharacters(value, limit) {
|
|
62
|
+
return Array.from(value).slice(0, Math.max(0, limit)).join('');
|
|
63
|
+
}
|
|
14
64
|
function textFor(query) {
|
|
15
65
|
return [
|
|
16
66
|
query.task,
|
|
@@ -29,15 +79,15 @@ function scopeObject(entry) {
|
|
|
29
79
|
function stringList(value) {
|
|
30
80
|
return Array.isArray(value) ? value.filter((item) => typeof item === 'string').map(normalize) : [];
|
|
31
81
|
}
|
|
32
|
-
function applicabilityScore(entry, queryText) {
|
|
33
|
-
if (
|
|
82
|
+
function applicabilityScore(entry, queryText, origin) {
|
|
83
|
+
if (origin === 'project')
|
|
34
84
|
return { score: 0, reasons: [], conflict: false };
|
|
35
85
|
const scope = scopeObject(entry);
|
|
36
86
|
const applicability = typeof scope.applicability === 'object' && scope.applicability !== null && !Array.isArray(scope.applicability)
|
|
37
87
|
? scope.applicability
|
|
38
88
|
: undefined;
|
|
39
89
|
if (applicability === undefined)
|
|
40
|
-
return { score: -4, reasons: ['unscoped_global_prior'], conflict: false };
|
|
90
|
+
return origin === 'global' ? { score: -4, reasons: ['unscoped_global_prior'], conflict: false } : { score: -8, reasons: ['applicability_unknown'], conflict: false };
|
|
41
91
|
const haystack = normalize(queryText);
|
|
42
92
|
const values = [
|
|
43
93
|
...stringList(applicability.languages),
|
|
@@ -48,7 +98,7 @@ function applicabilityScore(entry, queryText) {
|
|
|
48
98
|
...(Array.isArray(applicability.frameworks) ? applicability.frameworks.flatMap((item) => typeof item === 'object' && item !== null && typeof item.name === 'string' ? [normalize(item.name)] : []) : []),
|
|
49
99
|
];
|
|
50
100
|
if (values.length === 0)
|
|
51
|
-
return { score: -2, reasons: ['unscoped_global_prior'], conflict: false };
|
|
101
|
+
return origin === 'global' ? { score: -2, reasons: ['unscoped_global_prior'], conflict: false } : { score: -8, reasons: ['applicability_unknown'], conflict: false };
|
|
52
102
|
const matches = values.filter((value) => haystack.includes(value)).length;
|
|
53
103
|
const likelyUnrelated = /\b(?:swiftui|ios|android|kotlin|rust|django|rails|laravel|postgres(?:ql)?|mysql|react|vue)\b/giu;
|
|
54
104
|
const queryEcosystems = [...haystack.matchAll(likelyUnrelated)].map((match) => match[0].toLowerCase());
|
|
@@ -61,23 +111,23 @@ function applicabilityScore(entry, queryText) {
|
|
|
61
111
|
conflict: false,
|
|
62
112
|
};
|
|
63
113
|
}
|
|
64
|
-
function entryScore(entry, retrieval, exact,
|
|
65
|
-
const scope =
|
|
114
|
+
function entryScore(entry, origin, retrieval, exact, queryText) {
|
|
115
|
+
const scope = origin;
|
|
66
116
|
const status = entry.status === 'verified' ? 100 : entry.status === 'candidate' ? 40 : 0;
|
|
67
117
|
const trust = entry.trustLevel === 'system_verified' ? 30 : entry.trustLevel === 'source_verified' ? 25 : entry.trustLevel === 'user_asserted' ? 15 : 0;
|
|
68
118
|
const confidence = Math.round(entry.confidence * 20);
|
|
69
|
-
const scopeAffinity = scope === 'project' ? 9 : 4;
|
|
70
|
-
const applicability = applicabilityScore(entry, queryText);
|
|
119
|
+
const scopeAffinity = scope === 'project' ? 9 : scope === 'ecosystem' ? 6 : 4;
|
|
120
|
+
const applicability = applicabilityScore(entry, queryText, origin);
|
|
71
121
|
const exactSignal = exact ? 24 : 0;
|
|
72
122
|
const score = status + trust + confidence + retrieval + scopeAffinity + applicability.score + exactSignal;
|
|
73
|
-
const reasons = [scope === 'project' ? 'project_origin' : 'global_origin', ...(entry.status === 'verified' ? ['verified'] : ['candidate']), ...applicability.reasons, ...(exact ? ['exact_signal_match'] : [])];
|
|
123
|
+
const reasons = [scope === 'project' ? 'project_origin' : scope === 'ecosystem' ? 'ecosystem_origin' : 'global_origin', ...(entry.status === 'verified' ? ['verified'] : ['candidate']), ...applicability.reasons, ...(exact ? ['exact_signal_match'] : [])];
|
|
74
124
|
return {
|
|
75
125
|
entryId: entry.id,
|
|
76
126
|
revision: entry.revision,
|
|
77
127
|
origin: scope,
|
|
78
128
|
title: entry.title,
|
|
79
129
|
summary: entry.summary,
|
|
80
|
-
bodyPreview: entry.
|
|
130
|
+
bodyPreview: entry.body,
|
|
81
131
|
score,
|
|
82
132
|
scoreComponents: {
|
|
83
133
|
status,
|
|
@@ -100,149 +150,498 @@ function entryScore(entry, retrieval, exact, query, queryText) {
|
|
|
100
150
|
};
|
|
101
151
|
}
|
|
102
152
|
function feedbackScore(database, entryId) {
|
|
103
|
-
const rows = database.prepare(`
|
|
104
|
-
SELECT verdict, COUNT(DISTINCT run_id) AS runs
|
|
105
|
-
FROM context_feedback
|
|
106
|
-
WHERE entry_id = ?
|
|
107
|
-
GROUP BY verdict
|
|
108
|
-
`).all(entryId);
|
|
109
153
|
let score = 0;
|
|
110
154
|
const reasons = [];
|
|
111
|
-
for (const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
score += 3 * influence;
|
|
155
|
+
for (const signal of contextFeedbackSignals(database, entryId)) {
|
|
156
|
+
if (signal.verdict === 'helpful') {
|
|
157
|
+
score += 3 * signal.boundedInfluence;
|
|
115
158
|
reasons.push('helpful_feedback');
|
|
116
159
|
}
|
|
117
|
-
if (
|
|
118
|
-
score -= 2 *
|
|
160
|
+
if (signal.verdict === 'irrelevant') {
|
|
161
|
+
score -= 2 * signal.boundedInfluence;
|
|
119
162
|
reasons.push('irrelevant_feedback');
|
|
120
163
|
}
|
|
121
|
-
if (
|
|
122
|
-
score -= 3 *
|
|
164
|
+
if (signal.verdict === 'stale') {
|
|
165
|
+
score -= 3 * signal.boundedInfluence;
|
|
123
166
|
reasons.push('stale_feedback');
|
|
124
167
|
}
|
|
125
|
-
if (
|
|
126
|
-
score -= 3 *
|
|
168
|
+
if (signal.verdict === 'conflicting') {
|
|
169
|
+
score -= 3 * signal.boundedInfluence;
|
|
127
170
|
reasons.push('conflicting_feedback');
|
|
128
171
|
}
|
|
129
172
|
}
|
|
130
173
|
return { score: Math.max(-6, Math.min(6, score)), reasons };
|
|
131
174
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const limit = raw.limit ?? 20;
|
|
136
|
-
const characterBudget = raw.characterBudget ?? 8_000;
|
|
137
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_LIMIT || !Number.isSafeInteger(characterBudget) || characterBudget < 1 || characterBudget > MAX_BUDGET) {
|
|
138
|
-
throw new Error('Scoped context bounds are invalid');
|
|
175
|
+
function assertScopedSelectionState(database, workspaces, expectedHash) {
|
|
176
|
+
if (contextRetrievalStateHash(database, workspaces, { includeEcosystem: workspaces.length > 0 }) !== expectedHash) {
|
|
177
|
+
throw new KiokukoError('CONFLICT', 'Scoped context catalog changed after ranking');
|
|
139
178
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const queryHash = canonicalContentHash({ task: raw.task, taskProfile: raw.taskProfile, recommendedTags: raw.recommendedTags ?? [], changedPaths: raw.changedPaths ?? [], errorSignatures: raw.errorSignatures ?? [] });
|
|
143
|
-
const candidates = new Map();
|
|
144
|
-
const targets = project === undefined ? [GLOBAL_WORKSPACE] : [project.workspace, GLOBAL_WORKSPACE];
|
|
145
|
-
for (const workspace of targets) {
|
|
146
|
-
const retrieval = hybridSearch(database, {
|
|
147
|
-
workspace,
|
|
148
|
-
query: queryText,
|
|
149
|
-
limit: 200,
|
|
150
|
-
includeSuperseded: false,
|
|
151
|
-
});
|
|
152
|
-
for (const hit of retrieval) {
|
|
153
|
-
const entry = readEntry(database, { workspace, entryId: hit.entryId });
|
|
154
|
-
const item = entryScore(entry, hit.fusedScore * 100, hit.laneRanks['exact-signal'] !== undefined, raw, queryText);
|
|
155
|
-
const feedback = feedbackScore(database, entry.id);
|
|
156
|
-
item.score += feedback.score;
|
|
157
|
-
item.scoreComponents.feedback = feedback.score;
|
|
158
|
-
item.selectionReasons.push(...feedback.reasons);
|
|
159
|
-
if (item.score <= -50)
|
|
160
|
-
continue;
|
|
161
|
-
const previous = candidates.get(item.entryId);
|
|
162
|
-
if (previous === undefined || item.score > previous.score)
|
|
163
|
-
candidates.set(item.entryId, item);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const ordered = [...candidates.values()].sort((left, right) => right.score - left.score || left.entryId.localeCompare(right.entryId));
|
|
179
|
+
}
|
|
180
|
+
function fitScopedItems(ordered, limit, characterBudget) {
|
|
167
181
|
const items = [];
|
|
168
182
|
let remaining = characterBudget;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
183
|
+
let truncated = false;
|
|
184
|
+
for (const item of ordered) {
|
|
185
|
+
if (items.length >= limit) {
|
|
186
|
+
truncated = true;
|
|
173
187
|
break;
|
|
174
|
-
|
|
188
|
+
}
|
|
189
|
+
const metadataCost = characterCount(item.title) + characterCount(item.summary ?? '');
|
|
190
|
+
if (metadataCost > remaining) {
|
|
191
|
+
if (items.length === 0) {
|
|
192
|
+
throw new KiokukoError('VALIDATION_ERROR', 'Scoped context character budget cannot fit candidate metadata');
|
|
193
|
+
}
|
|
194
|
+
truncated = true;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
const bodyPreview = takeCharacters(item.bodyPreview, remaining - metadataCost);
|
|
198
|
+
if (characterCount(bodyPreview) < characterCount(item.bodyPreview))
|
|
199
|
+
truncated = true;
|
|
200
|
+
const cost = metadataCost + characterCount(bodyPreview);
|
|
201
|
+
items.push({
|
|
202
|
+
...item,
|
|
203
|
+
bodyPreview,
|
|
204
|
+
scoreComponents: { ...item.scoreComponents },
|
|
205
|
+
selectionReasons: [...item.selectionReasons],
|
|
206
|
+
});
|
|
175
207
|
remaining -= cost;
|
|
176
208
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
209
|
+
return { items, charCount: characterBudget - remaining, truncated };
|
|
210
|
+
}
|
|
211
|
+
function scopedRunContext(database, runId) {
|
|
212
|
+
if (runId === undefined)
|
|
213
|
+
return null;
|
|
214
|
+
let state;
|
|
215
|
+
try {
|
|
216
|
+
state = readContextRunRetrievalState(database, runId);
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
if (error instanceof KiokukoError && error.code === 'NOT_FOUND') {
|
|
220
|
+
throw new KiokukoError('VALIDATION_ERROR', 'Scoped context run is invalid');
|
|
221
|
+
}
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
return {
|
|
225
|
+
runId,
|
|
226
|
+
workspace: state.run.workspace,
|
|
227
|
+
status: state.run.status,
|
|
228
|
+
throughSequence: state.run.lastSequence,
|
|
229
|
+
createdAt: state.run.createdAt,
|
|
230
|
+
intakeSessionId: state.intakeSessionId,
|
|
231
|
+
profileHash: state.profileHash,
|
|
232
|
+
stateHash: state.stateHash,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function scopedDeliveryId(delivery) {
|
|
236
|
+
return `context-${canonicalContentHash({
|
|
237
|
+
kind: 'scoped-context-delivery-v1',
|
|
238
|
+
workspace: delivery.workspace,
|
|
239
|
+
runId: delivery.runId,
|
|
240
|
+
throughSequence: delivery.throughSequence,
|
|
241
|
+
intakeSessionId: delivery.intakeSessionId,
|
|
242
|
+
taskProfileHash: delivery.taskProfileHash,
|
|
243
|
+
queryHash: delivery.queryHash,
|
|
244
|
+
policyVersion: delivery.policyVersion,
|
|
245
|
+
charBudget: delivery.charBudget,
|
|
246
|
+
charCount: delivery.charCount,
|
|
247
|
+
truncated: delivery.truncated,
|
|
248
|
+
createdAt: delivery.createdAt,
|
|
249
|
+
scoreSchemaVersion: delivery.scoreSchemaVersion ?? 1,
|
|
250
|
+
items: delivery.items.map((item) => ({
|
|
190
251
|
entryId: item.entryId,
|
|
191
|
-
entryRevision: item.
|
|
192
|
-
rank:
|
|
193
|
-
scoreComponents:
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
252
|
+
entryRevision: item.entryRevision,
|
|
253
|
+
rank: item.rank,
|
|
254
|
+
scoreComponents: item.scoreComponents,
|
|
255
|
+
selectionReasons: item.selectionReasons,
|
|
256
|
+
...(item.origin === undefined ? {} : { origin: item.origin }),
|
|
257
|
+
})),
|
|
258
|
+
})}`;
|
|
259
|
+
}
|
|
260
|
+
function assertScopedDeliveryIdentity(delivery) {
|
|
261
|
+
if (delivery.deliveryId !== scopedDeliveryId(delivery)) {
|
|
262
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context character accounting is invalid');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function assertScopedReplayDeliveryUnchanged(database, expected) {
|
|
266
|
+
let current;
|
|
267
|
+
try {
|
|
268
|
+
current = readContextDelivery(database, {
|
|
269
|
+
workspace: expected.workspace,
|
|
270
|
+
deliveryId: expected.deliveryId,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
if (error instanceof KiokukoError && error.code === 'NOT_FOUND') {
|
|
275
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context delivery disappeared during replay');
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
assertScopedDeliveryIdentity(current);
|
|
280
|
+
if (scopedDeliveryId(current) !== scopedDeliveryId(expected)) {
|
|
281
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context delivery changed during replay');
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
function currentRetrievableDeliveryEntry(database, runWorkspace, item) {
|
|
285
|
+
const candidate = database.prepare('SELECT workspace FROM entries WHERE id = ?')
|
|
286
|
+
.get(item.entryId);
|
|
287
|
+
if (candidate === undefined) {
|
|
288
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry is missing');
|
|
289
|
+
}
|
|
290
|
+
if (typeof candidate.workspace !== 'string' || candidate.workspace.length === 0) {
|
|
291
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry is invalid');
|
|
292
|
+
}
|
|
293
|
+
const origin = item.origin ?? 'project';
|
|
294
|
+
let deliveredRevision;
|
|
295
|
+
try {
|
|
296
|
+
deliveredRevision = readEntryRevision(database, {
|
|
297
|
+
workspace: candidate.workspace,
|
|
298
|
+
entryId: item.entryId,
|
|
299
|
+
revision: item.entryRevision,
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
if (error instanceof KiokukoError && error.code === 'NOT_FOUND') {
|
|
304
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry revision is missing');
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
}
|
|
308
|
+
const deliveredScope = decodeStoredStructuredScope(deliveredRevision.scope, origin !== 'project').canonicalScope;
|
|
309
|
+
if (!entryOriginMatchesWorkspace({ origin, runWorkspace, entryWorkspace: deliveredRevision.workspace })) {
|
|
310
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry origin is invalid');
|
|
311
|
+
}
|
|
312
|
+
if (origin === 'global'
|
|
313
|
+
&& (deliveredScope.visibility !== 'global' || effectiveRetrievalScope(deliveredScope) !== 'global')) {
|
|
314
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry scope is invalid');
|
|
315
|
+
}
|
|
316
|
+
if (origin === 'ecosystem'
|
|
317
|
+
&& (!Object.hasOwn(deliveredScope, 'retrievalScope')
|
|
318
|
+
|| effectiveRetrievalScope(deliveredScope) !== 'ecosystem'
|
|
319
|
+
|| !hasExplicitApplicability(deliveredScope))) {
|
|
320
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry scope is invalid');
|
|
321
|
+
}
|
|
322
|
+
if (isExternalSkillReference(deliveredRevision)) {
|
|
323
|
+
const mappings = database.prepare('SELECT COUNT(*) AS count FROM external_skill_entries WHERE entry_id = ?')
|
|
324
|
+
.get(item.entryId)?.count;
|
|
325
|
+
if (typeof mappings !== 'number' || !Number.isSafeInteger(mappings) || mappings < 1) {
|
|
326
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context external entry mapping is missing');
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
const entry = readEntry(database, { workspace: candidate.workspace, entryId: item.entryId }, { requireStructuredScope: origin !== 'project' });
|
|
330
|
+
const retrievable = isRetrievableEntry(database, entry);
|
|
331
|
+
if (entry.revision !== item.entryRevision)
|
|
332
|
+
return null;
|
|
333
|
+
if (!retrievable)
|
|
334
|
+
return null;
|
|
335
|
+
if (entry.status === 'superseded')
|
|
336
|
+
return null;
|
|
337
|
+
return entry;
|
|
338
|
+
}
|
|
339
|
+
function storedDeliveryIsRetrievable(database, delivery, throughSequence, taskProfileHash, limit, characterBudget) {
|
|
340
|
+
assertScopedDeliveryIdentity(delivery);
|
|
341
|
+
if (delivery.throughSequence !== throughSequence)
|
|
342
|
+
return false;
|
|
343
|
+
if (!delivery.items.every((item) => currentRetrievableDeliveryEntry(database, delivery.workspace, item) !== null))
|
|
344
|
+
return false;
|
|
345
|
+
return !(delivery.taskProfileHash !== taskProfileHash
|
|
346
|
+
|| delivery.policyVersion !== SCOPED_CONTEXT_POLICY_VERSION
|
|
347
|
+
|| delivery.scoreSchemaVersion !== 2
|
|
348
|
+
|| delivery.charBudget !== characterBudget
|
|
349
|
+
|| delivery.items.length > limit);
|
|
350
|
+
}
|
|
351
|
+
function replayableDelivery(database, run, queryHash, taskProfileHash, limit, characterBudget) {
|
|
352
|
+
if (run === null)
|
|
353
|
+
return null;
|
|
354
|
+
const rows = database.prepare(`
|
|
355
|
+
SELECT delivery_id AS deliveryId
|
|
356
|
+
FROM context_deliveries
|
|
357
|
+
WHERE run_id = ? AND query_hash = ?
|
|
358
|
+
ORDER BY delivery_id ASC
|
|
359
|
+
`).all(run.runId, queryHash);
|
|
360
|
+
for (const row of rows) {
|
|
361
|
+
const delivery = readContextDelivery(database, { workspace: run.workspace, deliveryId: row.deliveryId });
|
|
362
|
+
if (storedDeliveryIsRetrievable(database, delivery, run.throughSequence, taskProfileHash, limit, characterBudget))
|
|
363
|
+
return delivery;
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
function storedScopedItems(database, delivery) {
|
|
368
|
+
assertScopedDeliveryIdentity(delivery);
|
|
369
|
+
const fullItems = delivery.items.map((item) => {
|
|
370
|
+
const current = currentRetrievableDeliveryEntry(database, delivery.workspace, item);
|
|
371
|
+
if (current === null)
|
|
372
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context entry is no longer retrievable');
|
|
373
|
+
const revision = readEntryRevision(database, {
|
|
374
|
+
entryId: item.entryId,
|
|
375
|
+
workspace: current.workspace,
|
|
376
|
+
revision: item.entryRevision,
|
|
229
377
|
});
|
|
378
|
+
const scoreComponents = item.scoreComponents;
|
|
379
|
+
return {
|
|
380
|
+
entryId: item.entryId,
|
|
381
|
+
revision: item.entryRevision,
|
|
382
|
+
origin: item.origin ?? 'project',
|
|
383
|
+
title: revision.title,
|
|
384
|
+
summary: revision.summary,
|
|
385
|
+
bodyPreview: revision.body,
|
|
386
|
+
score: Object.values(scoreComponents).reduce((total, component) => total + component, 0),
|
|
387
|
+
scoreComponents: { ...scoreComponents },
|
|
388
|
+
selectionReasons: [...item.selectionReasons],
|
|
389
|
+
metadata: { storedData: true, untrusted: true, instructions: false },
|
|
390
|
+
};
|
|
391
|
+
});
|
|
392
|
+
const fitted = fitScopedItems(fullItems, fullItems.length || 1, delivery.charBudget);
|
|
393
|
+
if (fitted.charCount !== delivery.charCount
|
|
394
|
+
|| fitted.items.length !== delivery.items.length
|
|
395
|
+
|| (fitted.truncated && !delivery.truncated)) {
|
|
396
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context character accounting is invalid');
|
|
230
397
|
}
|
|
398
|
+
return fitted.items;
|
|
399
|
+
}
|
|
400
|
+
function deliveryItems(items) {
|
|
401
|
+
const allowedReasons = new Set(CONTEXT_SELECTION_REASON_ORDER);
|
|
402
|
+
return items.map((item, index) => ({
|
|
403
|
+
entryId: item.entryId,
|
|
404
|
+
entryRevision: item.revision,
|
|
405
|
+
rank: index + 1,
|
|
406
|
+
scoreComponents: { ...item.scoreComponents },
|
|
407
|
+
selectionReasons: [...new Set([
|
|
408
|
+
...item.selectionReasons.filter((reason) => allowedReasons.has(reason)),
|
|
409
|
+
item.scoreComponents.status >= 100 ? 'verified' : 'candidate',
|
|
410
|
+
])].sort((left, right) => CONTEXT_SELECTION_REASON_ORDER.findIndex((reason) => reason === left)
|
|
411
|
+
- CONTEXT_SELECTION_REASON_ORDER.findIndex((reason) => reason === right)),
|
|
412
|
+
...(item.origin === 'project' ? {} : { origin: item.origin }),
|
|
413
|
+
}));
|
|
414
|
+
}
|
|
415
|
+
function deliveryRequest(run, taskProfileHash, queryHash, characterBudget, fitted) {
|
|
231
416
|
return {
|
|
232
|
-
|
|
417
|
+
workspace: run.workspace,
|
|
418
|
+
runId: run.runId,
|
|
419
|
+
throughSequence: run.throughSequence,
|
|
420
|
+
intakeSessionId: run.intakeSessionId,
|
|
233
421
|
taskProfileHash,
|
|
234
422
|
queryHash,
|
|
235
423
|
policyVersion: SCOPED_CONTEXT_POLICY_VERSION,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
truncated:
|
|
239
|
-
|
|
424
|
+
charBudget: characterBudget,
|
|
425
|
+
charCount: fitted.charCount,
|
|
426
|
+
truncated: fitted.truncated,
|
|
427
|
+
createdAt: run.createdAt,
|
|
428
|
+
scoreSchemaVersion: 2,
|
|
429
|
+
items: deliveryItems(fitted.items),
|
|
240
430
|
};
|
|
241
431
|
}
|
|
242
|
-
|
|
243
|
-
|
|
432
|
+
async function prepareScopedContext(database, raw) {
|
|
433
|
+
const taskProfileHash = canonicalContentHash(raw.taskProfile);
|
|
434
|
+
const run = scopedRunContext(database, raw.runId);
|
|
435
|
+
if (run !== null && run.profileHash !== taskProfileHash) {
|
|
436
|
+
throw new KiokukoError('CONFLICT', 'Scoped context task profile does not match its run');
|
|
437
|
+
}
|
|
438
|
+
const resolvedProject = raw.project ?? await resolveProjectWorkspace(database, raw.cwd);
|
|
439
|
+
const project = resolvedProject === undefined ? undefined : { ...resolvedProject };
|
|
440
|
+
if (run !== null && (project === undefined || run.workspace !== project.workspace)) {
|
|
441
|
+
throw new KiokukoError('VALIDATION_ERROR', 'Scoped context run is invalid');
|
|
442
|
+
}
|
|
443
|
+
if (raw.fingerprint !== undefined && project === undefined) {
|
|
444
|
+
throw new KiokukoError('VALIDATION_ERROR', 'Scoped context fingerprint requires a project');
|
|
445
|
+
}
|
|
446
|
+
const manifestSnapshot = project === undefined ? undefined : captureProjectManifestSnapshot(project);
|
|
447
|
+
if (raw.fingerprint !== undefined
|
|
448
|
+
&& manifestSnapshot !== undefined
|
|
449
|
+
&& raw.fingerprint.manifestDigest !== manifestSnapshot.manifestDigest) {
|
|
450
|
+
throw new KiokukoError('CONFLICT', 'Project manifest changed while task context was being prepared');
|
|
451
|
+
}
|
|
452
|
+
const fingerprint = project === undefined || manifestSnapshot === undefined
|
|
453
|
+
? undefined
|
|
454
|
+
: resolveProjectFingerprint(database, project, manifestSnapshot);
|
|
455
|
+
if (raw.fingerprint !== undefined
|
|
456
|
+
&& fingerprint !== undefined
|
|
457
|
+
&& canonicalContentHash(raw.fingerprint) !== canonicalContentHash(fingerprint)) {
|
|
458
|
+
throw new KiokukoError('CONFLICT', 'Project manifest changed while task context was being prepared');
|
|
459
|
+
}
|
|
460
|
+
const projectState = project === undefined || fingerprint === undefined ? null : { project, fingerprint };
|
|
461
|
+
ensureGlobalWorkspace(database);
|
|
462
|
+
const limit = raw.limit ?? 20;
|
|
463
|
+
const characterBudget = raw.characterBudget ?? SCOPED_CONTEXT_DEFAULT_CHARACTER_BUDGET;
|
|
464
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_LIMIT || !Number.isSafeInteger(characterBudget) || characterBudget < 1 || characterBudget > SCOPED_CONTEXT_MAX_CHARACTER_BUDGET) {
|
|
465
|
+
throw new KiokukoError('VALIDATION_ERROR', 'Scoped context bounds are invalid');
|
|
466
|
+
}
|
|
467
|
+
const queryText = textFor(raw);
|
|
468
|
+
const selectionWorkspaces = project === undefined ? [] : [project.workspace, GLOBAL_WORKSPACE];
|
|
469
|
+
const selectionStateHash = ordinaryContextSelectionStateHash(database, selectionWorkspaces, {
|
|
470
|
+
includeEcosystem: project !== undefined,
|
|
471
|
+
});
|
|
472
|
+
const retrievalStateHash = contextRetrievalStateHash(database, selectionWorkspaces, {
|
|
473
|
+
includeEcosystem: project !== undefined,
|
|
474
|
+
});
|
|
475
|
+
const queryHash = canonicalContentHash({
|
|
476
|
+
task: raw.task,
|
|
477
|
+
taskProfile: raw.taskProfile,
|
|
478
|
+
recommendedTags: raw.recommendedTags ?? [],
|
|
479
|
+
changedPaths: raw.changedPaths ?? [],
|
|
480
|
+
errorSignatures: raw.errorSignatures ?? [],
|
|
481
|
+
project: project === undefined ? null : {
|
|
482
|
+
workspace: project.workspace,
|
|
483
|
+
repositoryId: project.repositoryId,
|
|
484
|
+
repositoryRoot: project.repositoryRoot,
|
|
485
|
+
fingerprint,
|
|
486
|
+
},
|
|
487
|
+
limit,
|
|
488
|
+
characterBudget,
|
|
489
|
+
policyVersion: SCOPED_CONTEXT_POLICY_VERSION,
|
|
490
|
+
retrievalStateHash,
|
|
491
|
+
runStateHash: run?.stateHash ?? null,
|
|
492
|
+
});
|
|
493
|
+
const replay = replayableDelivery(database, run, queryHash, taskProfileHash, limit, characterBudget);
|
|
494
|
+
if (replay !== null) {
|
|
495
|
+
return {
|
|
496
|
+
result: {
|
|
497
|
+
project: project ?? null,
|
|
498
|
+
taskProfileHash,
|
|
499
|
+
queryHash,
|
|
500
|
+
policyVersion: SCOPED_CONTEXT_POLICY_VERSION,
|
|
501
|
+
items: storedScopedItems(database, replay),
|
|
502
|
+
deliveryId: replay.deliveryId,
|
|
503
|
+
truncated: replay.truncated,
|
|
504
|
+
untrusted: true,
|
|
505
|
+
},
|
|
506
|
+
replayDelivery: replay,
|
|
507
|
+
selectionStateHash,
|
|
508
|
+
retrievalStateHash,
|
|
509
|
+
selectionWorkspaces,
|
|
510
|
+
pendingDelivery: null,
|
|
511
|
+
run,
|
|
512
|
+
projectState,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
const candidates = new Map();
|
|
516
|
+
const federated = project === undefined ? [] : await federatedEntries(database, {
|
|
517
|
+
project,
|
|
518
|
+
...(fingerprint === undefined ? {} : { fingerprint }),
|
|
519
|
+
query: queryText,
|
|
520
|
+
limit: 200,
|
|
521
|
+
});
|
|
522
|
+
for (const hit of federated) {
|
|
523
|
+
const entry = hit.entry;
|
|
524
|
+
const item = entryScore(entry, hit.origin, hit.score, hit.selectionReasons.includes('exact_signal_match'), queryText);
|
|
525
|
+
item.selectionReasons.push(...hit.selectionReasons);
|
|
526
|
+
item.selectionReasons = [...new Set(item.selectionReasons)];
|
|
527
|
+
const feedback = feedbackScore(database, entry.id);
|
|
528
|
+
item.score += feedback.score;
|
|
529
|
+
item.scoreComponents.feedback = feedback.score;
|
|
530
|
+
item.selectionReasons.push(...feedback.reasons);
|
|
531
|
+
if (item.score <= -50)
|
|
532
|
+
continue;
|
|
533
|
+
const previous = candidates.get(item.entryId);
|
|
534
|
+
if (previous === undefined || item.score > previous.score)
|
|
535
|
+
candidates.set(item.entryId, item);
|
|
536
|
+
}
|
|
537
|
+
const ordered = [...candidates.values()].sort((left, right) => right.score - left.score || compareCanonicalStrings(left.entryId, right.entryId));
|
|
538
|
+
const fitted = fitScopedItems(ordered, limit, characterBudget);
|
|
539
|
+
return {
|
|
540
|
+
result: {
|
|
541
|
+
project: project ?? null,
|
|
542
|
+
taskProfileHash,
|
|
543
|
+
queryHash,
|
|
544
|
+
policyVersion: SCOPED_CONTEXT_POLICY_VERSION,
|
|
545
|
+
items: fitted.items,
|
|
546
|
+
deliveryId: null,
|
|
547
|
+
truncated: fitted.truncated,
|
|
548
|
+
untrusted: true,
|
|
549
|
+
},
|
|
550
|
+
replayDelivery: null,
|
|
551
|
+
selectionStateHash,
|
|
552
|
+
retrievalStateHash,
|
|
553
|
+
selectionWorkspaces,
|
|
554
|
+
pendingDelivery: run === null ? null : deliveryRequest(run, taskProfileHash, queryHash, characterBudget, fitted),
|
|
555
|
+
run,
|
|
556
|
+
projectState,
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
function assertPreparedScopedRun(database, run) {
|
|
560
|
+
const current = readContextRunRetrievalState(database, run.runId);
|
|
561
|
+
if (run.status !== 'active'
|
|
562
|
+
|| current.run.workspace !== run.workspace
|
|
563
|
+
|| current.run.status !== run.status
|
|
564
|
+
|| current.run.lastSequence !== run.throughSequence
|
|
565
|
+
|| current.intakeSessionId !== run.intakeSessionId
|
|
566
|
+
|| current.profileHash !== run.profileHash
|
|
567
|
+
|| current.stateHash !== run.stateHash) {
|
|
568
|
+
throw new KiokukoError('CONFLICT', 'Scoped context run changed before persistence');
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
function assertPreparedScopedState(database, prepared) {
|
|
572
|
+
if (prepared.projectState !== null) {
|
|
573
|
+
const manifestSnapshot = captureProjectManifestSnapshot(prepared.projectState.project);
|
|
574
|
+
if (manifestSnapshot.manifestDigest !== prepared.projectState.fingerprint.manifestDigest) {
|
|
575
|
+
throw new KiokukoError('CONFLICT', 'Scoped context project state changed after ranking');
|
|
576
|
+
}
|
|
577
|
+
const currentFingerprint = resolveProjectFingerprint(database, prepared.projectState.project, manifestSnapshot, { readOnly: true });
|
|
578
|
+
if (canonicalContentHash(currentFingerprint) !== canonicalContentHash(prepared.projectState.fingerprint)) {
|
|
579
|
+
throw new KiokukoError('CONFLICT', 'Scoped context project state changed after ranking');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (prepared.run !== null)
|
|
583
|
+
assertPreparedScopedRun(database, prepared.run);
|
|
584
|
+
const workspace = prepared.run?.workspace ?? prepared.result.project?.workspace;
|
|
585
|
+
if (workspace !== undefined && prepared.result.items.some((item) => currentRetrievableDeliveryEntry(database, workspace, {
|
|
586
|
+
entryId: item.entryId,
|
|
587
|
+
entryRevision: item.revision,
|
|
588
|
+
origin: item.origin,
|
|
589
|
+
}) === null)) {
|
|
590
|
+
throw new KiokukoError('CONFLICT', 'Scoped context selection changed before return');
|
|
591
|
+
}
|
|
592
|
+
assertScopedSelectionState(database, prepared.selectionWorkspaces, prepared.retrievalStateHash);
|
|
593
|
+
if (prepared.replayDelivery !== null) {
|
|
594
|
+
assertScopedReplayDeliveryUnchanged(database, prepared.replayDelivery);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function persistPreparedScopedContext(database, prepared, assertBeforePersist) {
|
|
598
|
+
if (prepared.pendingDelivery === null) {
|
|
599
|
+
return withImmediateTransaction(database, () => {
|
|
600
|
+
assertPreparedScopedState(database, prepared);
|
|
601
|
+
if (assertBeforePersist !== undefined) {
|
|
602
|
+
assertBeforePersist();
|
|
603
|
+
assertPreparedScopedState(database, prepared);
|
|
604
|
+
}
|
|
605
|
+
return prepared.result;
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
const request = prepared.pendingDelivery;
|
|
609
|
+
return withImmediateTransaction(database, () => {
|
|
610
|
+
if (prepared.run === null)
|
|
611
|
+
throw new KiokukoError('INTEGRITY_ERROR', 'Stored scoped context run is invalid');
|
|
612
|
+
assertPreparedScopedState(database, prepared);
|
|
613
|
+
if (assertBeforePersist !== undefined) {
|
|
614
|
+
assertBeforePersist();
|
|
615
|
+
assertPreparedScopedState(database, prepared);
|
|
616
|
+
}
|
|
617
|
+
const delivery = recordContextDeliveryInTransaction(database, { ...request, deliveryId: scopedDeliveryId(request) });
|
|
618
|
+
return {
|
|
619
|
+
...prepared.result,
|
|
620
|
+
items: storedScopedItems(database, delivery),
|
|
621
|
+
deliveryId: delivery.deliveryId,
|
|
622
|
+
truncated: delivery.truncated,
|
|
623
|
+
};
|
|
624
|
+
});
|
|
244
625
|
}
|
|
245
|
-
export function
|
|
246
|
-
return
|
|
626
|
+
export async function queryScopedContext(database, raw) {
|
|
627
|
+
return persistPreparedScopedContext(database, await prepareScopedContext(database, raw));
|
|
628
|
+
}
|
|
629
|
+
export async function queryScopedContextGated(database, raw, decide) {
|
|
630
|
+
const prepared = await prepareScopedContext(database, raw);
|
|
631
|
+
const decision = normalizedScopedGateDecision(decide(prepared.result));
|
|
632
|
+
if (!decision.persist) {
|
|
633
|
+
withImmediateTransaction(database, () => {
|
|
634
|
+
assertPreparedScopedState(database, prepared);
|
|
635
|
+
if (decision.assertBeforePersist !== undefined) {
|
|
636
|
+
decision.assertBeforePersist();
|
|
637
|
+
assertPreparedScopedState(database, prepared);
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
return {
|
|
642
|
+
context: decision.persist ? persistPreparedScopedContext(database, prepared, decision.assertBeforePersist) : null,
|
|
643
|
+
value: decision.value,
|
|
644
|
+
selectionStateHash: prepared.selectionStateHash,
|
|
645
|
+
};
|
|
247
646
|
}
|
|
248
647
|
//# sourceMappingURL=scoped-broker.js.map
|