@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
package/dist/context/delivery.js
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { withImmediateTransaction } from '../db/transaction.js';
|
|
2
2
|
import { KiokukoError } from '../errors.js';
|
|
3
|
-
import { CONTEXT_RANKING_COMPONENTS, CONTEXT_RANKING_COMPONENTS_V2, CONTEXT_SELECTION_REASON_ORDER, } from './ranking.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { CONTEXT_RANKING_VERSION, CONTEXT_RANKING_COMPONENTS, CONTEXT_RANKING_COMPONENTS_V2, CONTEXT_SELECTION_REASON_ORDER, } from './ranking.js';
|
|
4
|
+
import { canonicalContentHash, canonicalJson } from '../serialization/validate.js';
|
|
5
|
+
import { effectiveRetrievalScope, hasExplicitApplicability, } from '../memory/structured-memory.js';
|
|
6
|
+
import { readEntry } from '../memory/entries.js';
|
|
7
|
+
import { isRetrievableEntry } from '../memory/hybrid-retrieval.js';
|
|
8
|
+
import { entryOriginMatchesWorkspace, isContextEntryOrigin } from './origin.js';
|
|
9
|
+
import { RUN_STATUSES } from '../ledger/types.js';
|
|
10
|
+
import { RECOMMENDATION_POLICY_VERSION } from './recommendations.js';
|
|
11
|
+
import { readContextRunProfileBinding } from './run-state.js';
|
|
6
12
|
const MAX_IDENTIFIER_BYTES = 256;
|
|
7
13
|
const MAX_ITEMS = 100;
|
|
8
14
|
const MAX_SCORE_COMPONENT = 1_000_000;
|
|
9
15
|
const MAX_CHAR_BUDGET = 100_000;
|
|
10
|
-
const MAX_EXTERNAL_SUMMARY_BYTES = 16 * 1024;
|
|
11
|
-
const MAX_EXTERNAL_ERROR_BYTES = 1024;
|
|
12
|
-
const MAX_SOURCES = 16;
|
|
13
16
|
const MAX_LIMIT = 100;
|
|
14
17
|
const DEFAULT_LIMIT = 100;
|
|
15
18
|
const DELIVERY_CURSOR_VERSION = 1;
|
|
19
|
+
// The persisted score schema is the mode discriminant: v1 is the generic
|
|
20
|
+
// broker contract and v2 is the scoped broker contract.
|
|
21
|
+
const GENERIC_DELIVERY_POLICY_VERSION = `${CONTEXT_RANKING_VERSION}+${RECOMMENDATION_POLICY_VERSION}`;
|
|
22
|
+
const SCOPED_DELIVERY_POLICY_VERSION = 'context-ranking-v4';
|
|
16
23
|
const VALIDATION_MESSAGE = 'Context delivery input is invalid';
|
|
17
24
|
const NOT_FOUND_MESSAGE = 'Context delivery target was not found';
|
|
18
25
|
const CONFLICT_MESSAGE = 'Context delivery conflicts with existing record';
|
|
@@ -36,15 +43,47 @@ function databaseFailure() {
|
|
|
36
43
|
function integrity() {
|
|
37
44
|
return fail('INTEGRITY_ERROR', INTEGRITY_MESSAGE);
|
|
38
45
|
}
|
|
46
|
+
function scopedIdentityIntegrity() {
|
|
47
|
+
return fail('INTEGRITY_ERROR', 'Stored scoped context character accounting is invalid');
|
|
48
|
+
}
|
|
39
49
|
function isKiokukoError(error) {
|
|
40
50
|
return error instanceof KiokukoError;
|
|
41
51
|
}
|
|
42
|
-
|
|
52
|
+
const SQLITE_CONSTRAINT_PRIMARY_KEY = 1_555;
|
|
53
|
+
const SQLITE_CONSTRAINT_UNIQUE = 2_067;
|
|
54
|
+
const NO_UNIQUENESS_FAILURES = new Set();
|
|
55
|
+
const SQLITE_OPERATIONAL_PRIMARY_CODES = new Set([5, 6, 7, 8, 9, 10, 13, 14, 15, 22, 23]);
|
|
56
|
+
const SQLITE_INTEGRITY_PRIMARY_CODES = new Set([11, 24, 26]);
|
|
57
|
+
const DELIVERY_UNIQUENESS_FAILURES = new Set([
|
|
58
|
+
'UNIQUE constraint failed: context_deliveries.delivery_id',
|
|
59
|
+
'UNIQUE constraint failed: context_delivery_entries.delivery_id, context_delivery_entries.entry_id',
|
|
60
|
+
]);
|
|
61
|
+
function nodeSqliteFailure(error) {
|
|
62
|
+
if (!(error instanceof Error))
|
|
63
|
+
return null;
|
|
64
|
+
const failure = error;
|
|
65
|
+
if (failure.code !== 'ERR_SQLITE_ERROR'
|
|
66
|
+
|| typeof failure.errcode !== 'number'
|
|
67
|
+
|| !Number.isSafeInteger(failure.errcode)
|
|
68
|
+
|| failure.errcode < 0)
|
|
69
|
+
return null;
|
|
70
|
+
return failure;
|
|
71
|
+
}
|
|
72
|
+
function normalizeDatabaseError(error, uniquenessFailures = NO_UNIQUENESS_FAILURES) {
|
|
43
73
|
if (isKiokukoError(error))
|
|
44
74
|
throw error;
|
|
45
|
-
|
|
75
|
+
const failure = nodeSqliteFailure(error);
|
|
76
|
+
if (failure === null)
|
|
77
|
+
throw error;
|
|
78
|
+
if ((failure.errcode === SQLITE_CONSTRAINT_PRIMARY_KEY || failure.errcode === SQLITE_CONSTRAINT_UNIQUE)
|
|
79
|
+
&& uniquenessFailures.has(failure.message))
|
|
46
80
|
conflict();
|
|
47
|
-
|
|
81
|
+
const primaryResultCode = failure.errcode & 0xff;
|
|
82
|
+
if (SQLITE_INTEGRITY_PRIMARY_CODES.has(primaryResultCode))
|
|
83
|
+
integrity();
|
|
84
|
+
if (SQLITE_OPERATIONAL_PRIMARY_CODES.has(primaryResultCode))
|
|
85
|
+
databaseFailure();
|
|
86
|
+
throw error;
|
|
48
87
|
}
|
|
49
88
|
function isPlainObject(value) {
|
|
50
89
|
try {
|
|
@@ -156,6 +195,14 @@ function positiveSafeInteger(value) {
|
|
|
156
195
|
validation();
|
|
157
196
|
return value;
|
|
158
197
|
}
|
|
198
|
+
function validatedScoreSchemaVersion(value, onInvalid) {
|
|
199
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value) || (value !== 1 && value !== 2))
|
|
200
|
+
onInvalid();
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
function deliveryPolicyVersion(version) {
|
|
204
|
+
return version === 1 ? GENERIC_DELIVERY_POLICY_VERSION : SCOPED_DELIVERY_POLICY_VERSION;
|
|
205
|
+
}
|
|
159
206
|
function storedNonNegativeSafeInteger(value) {
|
|
160
207
|
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < 0)
|
|
161
208
|
integrity();
|
|
@@ -265,7 +312,7 @@ function validateDeliveryItems(value, scoreSchemaVersion) {
|
|
|
265
312
|
const rank = positiveSafeInteger(readField(object, 'rank'));
|
|
266
313
|
if (rank !== index + 1)
|
|
267
314
|
validation();
|
|
268
|
-
const origin = object.origin === undefined ? undefined : object.origin
|
|
315
|
+
const origin = object.origin === undefined ? undefined : isContextEntryOrigin(object.origin) ? object.origin : validation();
|
|
269
316
|
return {
|
|
270
317
|
entryId,
|
|
271
318
|
entryRevision,
|
|
@@ -276,74 +323,14 @@ function validateDeliveryItems(value, scoreSchemaVersion) {
|
|
|
276
323
|
};
|
|
277
324
|
});
|
|
278
325
|
}
|
|
279
|
-
function sanitizeExternalError(value, workspace) {
|
|
280
|
-
if (typeof value !== 'string' || value.length === 0)
|
|
281
|
-
validation();
|
|
282
|
-
let sanitized;
|
|
283
|
-
try {
|
|
284
|
-
sanitized = sanitizeJson({ error: value }, { workspace }).value;
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
validation();
|
|
288
|
-
}
|
|
289
|
-
if (!isPlainObject(sanitized))
|
|
290
|
-
validation();
|
|
291
|
-
const error = readField(sanitized, 'error');
|
|
292
|
-
if (typeof error !== 'string' || error.length === 0 || Buffer.byteLength(error, 'utf8') > MAX_EXTERNAL_ERROR_BYTES)
|
|
293
|
-
validation();
|
|
294
|
-
return error;
|
|
295
|
-
}
|
|
296
|
-
function validateExternalSummary(value, workspace) {
|
|
297
|
-
const object = objectInput(value, ['attempted', 'imported', 'sources'], true);
|
|
298
|
-
const attempted = booleanValue(readField(object, 'attempted'));
|
|
299
|
-
const imported = nonNegativeSafeInteger(readField(object, 'imported'));
|
|
300
|
-
const sourceArray = arrayInput(readField(object, 'sources'));
|
|
301
|
-
if (sourceArray.length > MAX_SOURCES)
|
|
302
|
-
validation();
|
|
303
|
-
const sourceIds = new Set();
|
|
304
|
-
const sources = sourceArray.map((source) => {
|
|
305
|
-
const sourceObject = objectInput(source, ['sourceId', 'commit', 'documents', 'imported', 'error'], false);
|
|
306
|
-
for (const field of ['sourceId', 'commit', 'documents', 'imported']) {
|
|
307
|
-
if (!hasOwn(sourceObject, field))
|
|
308
|
-
validation();
|
|
309
|
-
}
|
|
310
|
-
const sourceId = boundedIdentifier(readField(sourceObject, 'sourceId'));
|
|
311
|
-
if (sourceIds.has(sourceId))
|
|
312
|
-
validation();
|
|
313
|
-
sourceIds.add(sourceId);
|
|
314
|
-
const rawCommit = readField(sourceObject, 'commit');
|
|
315
|
-
const commit = rawCommit === null
|
|
316
|
-
? null
|
|
317
|
-
: typeof rawCommit === 'string' && rawCommit.length > 0 && /^[0-9a-f]+$/u.test(rawCommit) && Buffer.byteLength(rawCommit, 'utf8') <= MAX_IDENTIFIER_BYTES
|
|
318
|
-
? rawCommit
|
|
319
|
-
: validation();
|
|
320
|
-
const documents = nonNegativeSafeInteger(readField(sourceObject, 'documents'));
|
|
321
|
-
const sourceImported = nonNegativeSafeInteger(readField(sourceObject, 'imported'));
|
|
322
|
-
if (sourceImported > documents)
|
|
323
|
-
validation();
|
|
324
|
-
const result = { sourceId, commit, documents, imported: sourceImported };
|
|
325
|
-
if (hasOwn(sourceObject, 'error'))
|
|
326
|
-
result.error = sanitizeExternalError(readField(sourceObject, 'error'), workspace);
|
|
327
|
-
return result;
|
|
328
|
-
});
|
|
329
|
-
if (!attempted && (imported !== 0 || sources.length !== 0))
|
|
330
|
-
validation();
|
|
331
|
-
const sourceTotal = sources.reduce((total, source) => total + source.imported, 0);
|
|
332
|
-
if (imported !== sourceTotal)
|
|
333
|
-
validation();
|
|
334
|
-
const summary = { attempted, imported, sources };
|
|
335
|
-
if (Buffer.byteLength(canonicalJson(summary), 'utf8') > MAX_EXTERNAL_SUMMARY_BYTES)
|
|
336
|
-
validation();
|
|
337
|
-
return summary;
|
|
338
|
-
}
|
|
339
326
|
function validateContextDeliveryInput(value) {
|
|
340
327
|
try {
|
|
341
328
|
const object = objectInput(value, [
|
|
342
329
|
'workspace', 'deliveryId', 'runId', 'throughSequence', 'intakeSessionId', 'taskProfileHash',
|
|
343
|
-
'queryHash', 'policyVersion', '
|
|
330
|
+
'queryHash', 'policyVersion', 'charBudget', 'charCount', 'truncated',
|
|
344
331
|
'createdAt', 'items', 'scoreSchemaVersion',
|
|
345
332
|
], false);
|
|
346
|
-
for (const field of ['workspace', 'deliveryId', 'runId', 'throughSequence', 'intakeSessionId', 'taskProfileHash', 'queryHash', 'policyVersion', '
|
|
333
|
+
for (const field of ['workspace', 'deliveryId', 'runId', 'throughSequence', 'intakeSessionId', 'taskProfileHash', 'queryHash', 'policyVersion', 'charBudget', 'charCount', 'truncated', 'createdAt', 'items']) {
|
|
347
334
|
if (!hasOwn(object, field))
|
|
348
335
|
validation();
|
|
349
336
|
}
|
|
@@ -356,7 +343,6 @@ function validateContextDeliveryInput(value) {
|
|
|
356
343
|
const taskProfileHash = hash(readField(object, 'taskProfileHash'));
|
|
357
344
|
const queryHash = hash(readField(object, 'queryHash'));
|
|
358
345
|
const policyVersion = boundedIdentifier(readField(object, 'policyVersion'));
|
|
359
|
-
const externalSyncSummary = validateExternalSummary(readField(object, 'externalSyncSummary'), workspace);
|
|
360
346
|
const charBudget = readField(object, 'charBudget');
|
|
361
347
|
if (typeof charBudget !== 'number' || !Number.isSafeInteger(charBudget) || charBudget < 1 || charBudget > MAX_CHAR_BUDGET)
|
|
362
348
|
validation();
|
|
@@ -365,8 +351,10 @@ function validateContextDeliveryInput(value) {
|
|
|
365
351
|
validation();
|
|
366
352
|
const truncated = booleanValue(readField(object, 'truncated'));
|
|
367
353
|
const createdAt = timestamp(readField(object, 'createdAt'));
|
|
368
|
-
const
|
|
369
|
-
|
|
354
|
+
const parsedScoreSchemaVersion = validatedScoreSchemaVersion(object.scoreSchemaVersion === undefined ? 1 : object.scoreSchemaVersion, validation);
|
|
355
|
+
if (policyVersion !== deliveryPolicyVersion(parsedScoreSchemaVersion))
|
|
356
|
+
validation();
|
|
357
|
+
const items = validateDeliveryItems(readField(object, 'items'), parsedScoreSchemaVersion);
|
|
370
358
|
return {
|
|
371
359
|
workspace,
|
|
372
360
|
deliveryId,
|
|
@@ -376,13 +364,12 @@ function validateContextDeliveryInput(value) {
|
|
|
376
364
|
taskProfileHash,
|
|
377
365
|
queryHash,
|
|
378
366
|
policyVersion,
|
|
379
|
-
externalSyncSummary,
|
|
380
367
|
charBudget,
|
|
381
368
|
charCount,
|
|
382
369
|
truncated,
|
|
383
370
|
createdAt,
|
|
384
371
|
items,
|
|
385
|
-
...(scoreSchemaVersion === undefined ? {} : { scoreSchemaVersion }),
|
|
372
|
+
...(object.scoreSchemaVersion === undefined ? {} : { scoreSchemaVersion: parsedScoreSchemaVersion }),
|
|
386
373
|
};
|
|
387
374
|
}
|
|
388
375
|
catch {
|
|
@@ -460,7 +447,6 @@ function canonicalDeliveryBody(input) {
|
|
|
460
447
|
taskProfileHash: input.taskProfileHash,
|
|
461
448
|
queryHash: input.queryHash,
|
|
462
449
|
policyVersion: input.policyVersion,
|
|
463
|
-
externalSyncSummary: input.externalSyncSummary,
|
|
464
450
|
charBudget: input.charBudget,
|
|
465
451
|
charCount: input.charCount,
|
|
466
452
|
truncated: input.truncated,
|
|
@@ -476,52 +462,111 @@ function canonicalDeliveryBody(input) {
|
|
|
476
462
|
scoreSchemaVersion: input.scoreSchemaVersion ?? 1,
|
|
477
463
|
});
|
|
478
464
|
}
|
|
465
|
+
function scopedDeliveryId(input) {
|
|
466
|
+
return `context-${canonicalContentHash({
|
|
467
|
+
kind: 'scoped-context-delivery-v1',
|
|
468
|
+
workspace: input.workspace,
|
|
469
|
+
runId: input.runId,
|
|
470
|
+
throughSequence: input.throughSequence,
|
|
471
|
+
intakeSessionId: input.intakeSessionId,
|
|
472
|
+
taskProfileHash: input.taskProfileHash,
|
|
473
|
+
queryHash: input.queryHash,
|
|
474
|
+
policyVersion: input.policyVersion,
|
|
475
|
+
charBudget: input.charBudget,
|
|
476
|
+
charCount: input.charCount,
|
|
477
|
+
truncated: input.truncated,
|
|
478
|
+
createdAt: input.createdAt,
|
|
479
|
+
scoreSchemaVersion: input.scoreSchemaVersion ?? 1,
|
|
480
|
+
items: input.items.map((item) => ({
|
|
481
|
+
entryId: item.entryId,
|
|
482
|
+
entryRevision: item.entryRevision,
|
|
483
|
+
rank: item.rank,
|
|
484
|
+
scoreComponents: item.scoreComponents,
|
|
485
|
+
selectionReasons: item.selectionReasons,
|
|
486
|
+
...(item.origin === undefined ? {} : { origin: item.origin }),
|
|
487
|
+
})),
|
|
488
|
+
})}`;
|
|
489
|
+
}
|
|
479
490
|
function selectHeaderByDeliveryId(database, deliveryId) {
|
|
480
491
|
return database.prepare(`
|
|
481
492
|
SELECT cd.delivery_id, cd.run_id, cd.through_sequence, cd.intake_session_id,
|
|
482
493
|
cd.task_profile_hash, cd.query_hash, cd.policy_version,
|
|
483
|
-
cd.
|
|
484
|
-
cd.truncated, cd.created_at, cd.score_schema_version,
|
|
494
|
+
cd.char_budget, cd.char_count, cd.truncated, cd.created_at, cd.score_schema_version,
|
|
485
495
|
lr.workspace AS run_workspace, lr.last_sequence AS run_last_sequence
|
|
486
496
|
FROM context_deliveries AS cd
|
|
487
497
|
LEFT JOIN ledger_runs AS lr ON lr.run_id = cd.run_id
|
|
488
498
|
WHERE cd.delivery_id = ?
|
|
489
499
|
`).get(deliveryId);
|
|
490
500
|
}
|
|
501
|
+
function strictCurrentEntry(database, workspace, entryId, requireStructuredScope) {
|
|
502
|
+
try {
|
|
503
|
+
return readEntry(database, { workspace, entryId }, { requireStructuredScope });
|
|
504
|
+
}
|
|
505
|
+
catch (error) {
|
|
506
|
+
if (isKiokukoError(error) && error.code === 'INTEGRITY_ERROR')
|
|
507
|
+
integrity();
|
|
508
|
+
throw error;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
491
511
|
function assertRunForWrite(database, input) {
|
|
492
|
-
const run = database.prepare('SELECT run_id, last_sequence FROM ledger_runs WHERE run_id = ? AND workspace = ?')
|
|
512
|
+
const run = database.prepare('SELECT run_id, status, last_sequence FROM ledger_runs WHERE run_id = ? AND workspace = ?')
|
|
513
|
+
.get(input.runId, input.workspace);
|
|
493
514
|
if (!run)
|
|
494
515
|
notFound();
|
|
495
516
|
if (typeof run.run_id !== 'string')
|
|
496
517
|
integrity();
|
|
518
|
+
if (typeof run.status !== 'string' || !RUN_STATUSES.includes(run.status))
|
|
519
|
+
integrity();
|
|
497
520
|
const lastSequence = storedNonNegativeSafeInteger(run.last_sequence);
|
|
498
|
-
if (input.throughSequence
|
|
521
|
+
if (run.status !== 'active' || input.throughSequence !== lastSequence)
|
|
499
522
|
conflict();
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
notFound();
|
|
523
|
+
let binding;
|
|
524
|
+
try {
|
|
525
|
+
binding = readContextRunProfileBinding(database, input.runId, input.throughSequence);
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
if (isKiokukoError(error) && (error.code === 'NOT_FOUND' || error.code === 'INTEGRITY_ERROR'))
|
|
529
|
+
integrity();
|
|
530
|
+
throw error;
|
|
509
531
|
}
|
|
532
|
+
if (binding.workspace !== input.workspace)
|
|
533
|
+
integrity();
|
|
534
|
+
if (input.intakeSessionId !== binding.intakeSessionId)
|
|
535
|
+
notFound();
|
|
536
|
+
if (input.taskProfileHash !== binding.profileHash)
|
|
537
|
+
conflict();
|
|
510
538
|
for (const item of input.items) {
|
|
511
|
-
const
|
|
512
|
-
SELECT e.id, e.workspace, r.
|
|
539
|
+
const candidate = database.prepare(`
|
|
540
|
+
SELECT e.id, e.workspace, r.workspace AS revision_workspace
|
|
513
541
|
FROM entry_revisions AS r
|
|
514
542
|
JOIN entries AS e ON e.id = r.entry_id
|
|
515
543
|
WHERE r.entry_id = ? AND r.revision = ?
|
|
516
544
|
`).get(item.entryId, item.entryRevision);
|
|
517
|
-
if (!
|
|
545
|
+
if (!candidate || candidate.id !== item.entryId)
|
|
518
546
|
notFound();
|
|
519
|
-
if (
|
|
520
|
-
|
|
547
|
+
if (typeof candidate.workspace !== 'string' || candidate.workspace.length === 0)
|
|
548
|
+
integrity();
|
|
549
|
+
const entryWorkspace = candidate.workspace;
|
|
550
|
+
const origin = item.origin ?? 'project';
|
|
551
|
+
if (candidate.revision_workspace !== entryWorkspace)
|
|
552
|
+
integrity();
|
|
553
|
+
const entry = strictCurrentEntry(database, entryWorkspace, item.entryId, origin !== 'project');
|
|
554
|
+
if (entry.revision !== item.entryRevision)
|
|
555
|
+
conflict();
|
|
556
|
+
if (!isRetrievableEntry(database, entry) || entry.status === 'superseded')
|
|
557
|
+
conflict();
|
|
558
|
+
if (!entryOriginMatchesWorkspace({ origin, runWorkspace: input.workspace, entryWorkspace: entry.workspace }))
|
|
559
|
+
notFound();
|
|
560
|
+
if (origin === 'global') {
|
|
561
|
+
if (entry.workspace !== 'global' || entry.scope.visibility !== 'global' || effectiveRetrievalScope(entry.scope) !== 'global')
|
|
562
|
+
notFound();
|
|
563
|
+
}
|
|
564
|
+
else if (origin === 'ecosystem') {
|
|
565
|
+
if (!hasOwn(entry.scope, 'retrievalScope')
|
|
566
|
+
|| effectiveRetrievalScope(entry.scope) !== 'ecosystem'
|
|
567
|
+
|| !hasExplicitApplicability(entry.scope))
|
|
521
568
|
notFound();
|
|
522
569
|
}
|
|
523
|
-
else if (entry.workspace !== input.workspace)
|
|
524
|
-
notFound();
|
|
525
570
|
}
|
|
526
571
|
}
|
|
527
572
|
function validateStoredJson(value) {
|
|
@@ -531,31 +576,24 @@ function validateStoredJson(value) {
|
|
|
531
576
|
try {
|
|
532
577
|
parsed = JSON.parse(value);
|
|
533
578
|
}
|
|
534
|
-
catch {
|
|
535
|
-
|
|
536
|
-
}
|
|
537
|
-
try {
|
|
538
|
-
if (canonicalJson(parsed) !== value)
|
|
579
|
+
catch (error) {
|
|
580
|
+
if (error instanceof SyntaxError || error instanceof RangeError)
|
|
539
581
|
integrity();
|
|
582
|
+
throw error;
|
|
540
583
|
}
|
|
541
|
-
|
|
542
|
-
integrity();
|
|
543
|
-
}
|
|
544
|
-
return parsed;
|
|
545
|
-
}
|
|
546
|
-
function validateStoredExternalSummary(value, workspace) {
|
|
584
|
+
let canonical;
|
|
547
585
|
try {
|
|
548
|
-
|
|
549
|
-
const normalized = validateExternalSummary(parsed, workspace);
|
|
550
|
-
if (canonicalJson(normalized) !== value)
|
|
551
|
-
integrity();
|
|
552
|
-
return normalized;
|
|
586
|
+
canonical = canonicalJson(parsed);
|
|
553
587
|
}
|
|
554
588
|
catch (error) {
|
|
555
|
-
if (
|
|
556
|
-
|
|
557
|
-
|
|
589
|
+
if (error instanceof RangeError
|
|
590
|
+
|| (error instanceof KiokukoError && error.code === 'VALIDATION_ERROR'))
|
|
591
|
+
integrity();
|
|
592
|
+
throw error;
|
|
558
593
|
}
|
|
594
|
+
if (canonical !== value)
|
|
595
|
+
integrity();
|
|
596
|
+
return parsed;
|
|
559
597
|
}
|
|
560
598
|
function validateStoredHeader(row, workspace) {
|
|
561
599
|
const deliveryId = boundedStoredIdentifier(row.delivery_id);
|
|
@@ -572,8 +610,9 @@ function validateStoredHeader(row, workspace) {
|
|
|
572
610
|
const taskProfileHash = storedHash(row.task_profile_hash);
|
|
573
611
|
const queryHash = storedHash(row.query_hash);
|
|
574
612
|
const policyVersion = boundedStoredIdentifier(row.policy_version);
|
|
575
|
-
const scoreSchemaVersion =
|
|
576
|
-
|
|
613
|
+
const scoreSchemaVersion = validatedScoreSchemaVersion(row.score_schema_version, integrity);
|
|
614
|
+
if (policyVersion !== deliveryPolicyVersion(scoreSchemaVersion))
|
|
615
|
+
integrity();
|
|
577
616
|
const charBudget = storedPositiveSafeInteger(row.char_budget);
|
|
578
617
|
if (charBudget > MAX_CHAR_BUDGET)
|
|
579
618
|
integrity();
|
|
@@ -591,7 +630,6 @@ function validateStoredHeader(row, workspace) {
|
|
|
591
630
|
taskProfileHash,
|
|
592
631
|
queryHash,
|
|
593
632
|
policyVersion,
|
|
594
|
-
externalSyncSummary,
|
|
595
633
|
charBudget,
|
|
596
634
|
charCount,
|
|
597
635
|
truncated,
|
|
@@ -626,10 +664,8 @@ function validateStoredEntries(database, header) {
|
|
|
626
664
|
integrity();
|
|
627
665
|
entryIds.add(entryId);
|
|
628
666
|
const entryWorkspace = boundedStoredIdentifier(row.entry_workspace);
|
|
629
|
-
const origin = row.origin_scope
|
|
630
|
-
if (origin
|
|
631
|
-
integrity();
|
|
632
|
-
if (origin === 'global' && entryWorkspace !== 'global')
|
|
667
|
+
const origin = isContextEntryOrigin(row.origin_scope) ? row.origin_scope : integrity();
|
|
668
|
+
if (!entryOriginMatchesWorkspace({ origin, runWorkspace: header.workspace, entryWorkspace }))
|
|
633
669
|
integrity();
|
|
634
670
|
const entryRevision = storedPositiveSafeInteger(row.entry_revision);
|
|
635
671
|
const revisionWorkspace = boundedStoredIdentifier(row.revision_workspace);
|
|
@@ -645,19 +681,22 @@ function validateStoredEntries(database, header) {
|
|
|
645
681
|
const reasons = storedSelectionReasons(reasonValue);
|
|
646
682
|
if (canonicalJson(score) !== row.score_components_json || canonicalJson(reasons) !== row.selection_reason_json)
|
|
647
683
|
integrity();
|
|
648
|
-
return { entryId, entryRevision, rank, scoreComponents: score, selectionReasons: reasons, ...(origin === '
|
|
684
|
+
return { entryId, entryRevision, rank, scoreComponents: score, selectionReasons: reasons, ...(origin === 'project' ? {} : { origin }) };
|
|
649
685
|
});
|
|
650
686
|
}
|
|
651
|
-
function
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
687
|
+
function assertStoredProfileBinding(database, header) {
|
|
688
|
+
let binding;
|
|
689
|
+
try {
|
|
690
|
+
binding = readContextRunProfileBinding(database, header.runId, header.throughSequence);
|
|
691
|
+
}
|
|
692
|
+
catch (error) {
|
|
693
|
+
if (isKiokukoError(error) && (error.code === 'NOT_FOUND' || error.code === 'INTEGRITY_ERROR'))
|
|
694
|
+
integrity();
|
|
695
|
+
throw error;
|
|
696
|
+
}
|
|
697
|
+
if (binding.workspace !== header.workspace
|
|
698
|
+
|| header.intakeSessionId !== binding.intakeSessionId
|
|
699
|
+
|| header.taskProfileHash !== binding.profileHash)
|
|
661
700
|
integrity();
|
|
662
701
|
}
|
|
663
702
|
function readStoredDelivery(database, workspace, deliveryId) {
|
|
@@ -669,33 +708,40 @@ function readStoredDelivery(database, workspace, deliveryId) {
|
|
|
669
708
|
if (row.run_workspace !== workspace)
|
|
670
709
|
notFound();
|
|
671
710
|
const header = validateStoredHeader(row, workspace);
|
|
672
|
-
|
|
711
|
+
assertStoredProfileBinding(database, header);
|
|
673
712
|
const items = validateStoredEntries(database, header);
|
|
713
|
+
const complete = { ...header, items };
|
|
714
|
+
if ((header.scoreSchemaVersion ?? 1) === 2 && header.deliveryId !== scopedDeliveryId(complete))
|
|
715
|
+
scopedIdentityIntegrity();
|
|
674
716
|
const view = {
|
|
675
|
-
...
|
|
717
|
+
...complete,
|
|
676
718
|
items: items.map((item) => ({ ...item, scoreComponents: { ...item.scoreComponents }, selectionReasons: [...item.selectionReasons], untrusted: true })),
|
|
677
719
|
untrusted: true,
|
|
678
720
|
};
|
|
679
721
|
return view;
|
|
680
722
|
}
|
|
681
|
-
function writeContextDelivery(database, input) {
|
|
723
|
+
function writeContextDelivery(database, input, options = {}) {
|
|
724
|
+
if ((input.scoreSchemaVersion ?? 1) === 2 && input.deliveryId !== scopedDeliveryId(input))
|
|
725
|
+
validation();
|
|
726
|
+
assertRunForWrite(database, input);
|
|
682
727
|
const existing = selectHeaderByDeliveryId(database, input.deliveryId);
|
|
683
728
|
if (existing) {
|
|
684
729
|
if (existing.run_workspace !== input.workspace)
|
|
685
730
|
conflict();
|
|
686
731
|
const stored = readStoredDelivery(database, input.workspace, input.deliveryId);
|
|
687
|
-
if (canonicalDeliveryBody(stored) === canonicalDeliveryBody(input))
|
|
732
|
+
if (canonicalDeliveryBody(stored) === canonicalDeliveryBody(input)) {
|
|
733
|
+
options.assertBeforePersist?.();
|
|
688
734
|
return stored;
|
|
735
|
+
}
|
|
689
736
|
conflict();
|
|
690
737
|
}
|
|
691
|
-
|
|
692
|
-
const summaryJson = canonicalJson(input.externalSyncSummary);
|
|
738
|
+
options.assertBeforePersist?.();
|
|
693
739
|
database.prepare(`
|
|
694
740
|
INSERT INTO context_deliveries (
|
|
695
741
|
delivery_id, run_id, through_sequence, intake_session_id, task_profile_hash, query_hash,
|
|
696
742
|
policy_version, external_sync_summary_json, char_budget, char_count, truncated, created_at, score_schema_version
|
|
697
743
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
698
|
-
`).run(input.deliveryId, input.runId, input.throughSequence, input.intakeSessionId, input.taskProfileHash, input.queryHash, input.policyVersion,
|
|
744
|
+
`).run(input.deliveryId, input.runId, input.throughSequence, input.intakeSessionId, input.taskProfileHash, input.queryHash, input.policyVersion, '{}', input.charBudget, input.charCount, input.truncated ? 1 : 0, input.createdAt, input.scoreSchemaVersion ?? 1);
|
|
699
745
|
for (const item of input.items) {
|
|
700
746
|
database.prepare(`
|
|
701
747
|
INSERT INTO context_delivery_entries (
|
|
@@ -705,22 +751,26 @@ function writeContextDelivery(database, input) {
|
|
|
705
751
|
}
|
|
706
752
|
return readStoredDelivery(database, input.workspace, input.deliveryId);
|
|
707
753
|
}
|
|
708
|
-
export function recordContextDeliveryInTransaction(database, input) {
|
|
754
|
+
export function recordContextDeliveryInTransaction(database, input, options = {}) {
|
|
709
755
|
const validated = validateContextDeliveryInput(input);
|
|
756
|
+
if (options.assertBeforePersist !== undefined && typeof options.assertBeforePersist !== 'function')
|
|
757
|
+
validation();
|
|
710
758
|
try {
|
|
711
|
-
return writeContextDelivery(database, validated);
|
|
759
|
+
return writeContextDelivery(database, validated, options);
|
|
712
760
|
}
|
|
713
761
|
catch (error) {
|
|
714
|
-
normalizeDatabaseError(error);
|
|
762
|
+
normalizeDatabaseError(error, DELIVERY_UNIQUENESS_FAILURES);
|
|
715
763
|
}
|
|
716
764
|
}
|
|
717
|
-
export function recordContextDelivery(database, input) {
|
|
765
|
+
export function recordContextDelivery(database, input, options = {}) {
|
|
718
766
|
const validated = validateContextDeliveryInput(input);
|
|
767
|
+
if (options.assertBeforePersist !== undefined && typeof options.assertBeforePersist !== 'function')
|
|
768
|
+
validation();
|
|
719
769
|
try {
|
|
720
|
-
return withImmediateTransaction(database, () => writeContextDelivery(database, validated));
|
|
770
|
+
return withImmediateTransaction(database, () => writeContextDelivery(database, validated, options));
|
|
721
771
|
}
|
|
722
772
|
catch (error) {
|
|
723
|
-
normalizeDatabaseError(error);
|
|
773
|
+
normalizeDatabaseError(error, DELIVERY_UNIQUENESS_FAILURES);
|
|
724
774
|
}
|
|
725
775
|
}
|
|
726
776
|
export function readContextDelivery(database, input) {
|
|
@@ -751,8 +801,7 @@ export function listContextDeliveries(database, input) {
|
|
|
751
801
|
const rows = database.prepare(`
|
|
752
802
|
SELECT cd.delivery_id, cd.run_id, cd.through_sequence, cd.intake_session_id,
|
|
753
803
|
cd.task_profile_hash, cd.query_hash, cd.policy_version,
|
|
754
|
-
cd.
|
|
755
|
-
cd.truncated, cd.created_at, cd.score_schema_version,
|
|
804
|
+
cd.char_budget, cd.char_count, cd.truncated, cd.created_at, cd.score_schema_version,
|
|
756
805
|
lr.workspace AS run_workspace, lr.last_sequence AS run_last_sequence
|
|
757
806
|
FROM context_deliveries AS cd
|
|
758
807
|
LEFT JOIN ledger_runs AS lr ON lr.run_id = cd.run_id
|
|
@@ -763,10 +812,13 @@ export function listContextDeliveries(database, input) {
|
|
|
763
812
|
const pageRows = rows.slice(0, validated.limit);
|
|
764
813
|
const items = pageRows.map((row) => {
|
|
765
814
|
const header = validateStoredHeader(row, validated.workspace);
|
|
766
|
-
|
|
815
|
+
assertStoredProfileBinding(database, header);
|
|
767
816
|
const storedItems = validateStoredEntries(database, header);
|
|
817
|
+
const complete = { ...header, items: storedItems };
|
|
818
|
+
if ((header.scoreSchemaVersion ?? 1) === 2 && header.deliveryId !== scopedDeliveryId(complete))
|
|
819
|
+
scopedIdentityIntegrity();
|
|
768
820
|
return {
|
|
769
|
-
...
|
|
821
|
+
...complete,
|
|
770
822
|
items: storedItems.map((item) => ({ ...item, scoreComponents: { ...item.scoreComponents }, selectionReasons: [...item.selectionReasons], untrusted: true })),
|
|
771
823
|
untrusted: true,
|
|
772
824
|
};
|