@theokit/sdk 5.9.1 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +119 -0
- package/dist/{agent-enXXu447.d.ts → agent-CmKwSyyD.d.ts} +27 -0
- package/dist/{agent-5M7WLUWH.cjs → agent-TLRURB7W.cjs} +18 -16
- package/dist/{agent-5M7WLUWH.cjs.map → agent-TLRURB7W.cjs.map} +1 -1
- package/dist/{agent-Dh2YHSLj.d.cts → agent-XMkGzff_.d.cts} +27 -0
- package/dist/{agent-R5RERYFU.js → agent-XTLAVVYC.js} +17 -15
- package/dist/{agent-R5RERYFU.js.map → agent-XTLAVVYC.js.map} +1 -1
- package/dist/agent-session-store-ODD3IZCW.js +6 -0
- package/dist/{agent-session-store-AFML3AXC.js.map → agent-session-store-ODD3IZCW.js.map} +1 -1
- package/dist/agent-session-store-SVEJHSUA.cjs +23 -0
- package/dist/{agent-session-store-MTSIY3MH.cjs.map → agent-session-store-SVEJHSUA.cjs.map} +1 -1
- package/dist/auth/index.cjs +8 -7
- package/dist/auth/index.cjs.map +1 -1
- package/dist/auth/index.js +3 -2
- package/dist/auth/index.js.map +1 -1
- package/dist/{chunk-QCIARBLS.js → chunk-523O5UYB.js} +3 -3
- package/dist/{chunk-QCIARBLS.js.map → chunk-523O5UYB.js.map} +1 -1
- package/dist/chunk-7KIN3L2S.js +103 -0
- package/dist/chunk-7KIN3L2S.js.map +1 -0
- package/dist/chunk-ASK2OQM5.cjs +84 -0
- package/dist/chunk-ASK2OQM5.cjs.map +1 -0
- package/dist/{chunk-56BCEM26.cjs → chunk-CVEQ5366.cjs} +105 -91
- package/dist/chunk-CVEQ5366.cjs.map +1 -0
- package/dist/{chunk-R2C3HXR3.js → chunk-DPY2M74T.js} +3 -3
- package/dist/{chunk-R2C3HXR3.js.map → chunk-DPY2M74T.js.map} +1 -1
- package/dist/chunk-EHD25JBZ.cjs +10 -0
- package/dist/chunk-EHD25JBZ.cjs.map +1 -0
- package/dist/{chunk-NOO6GZTZ.js → chunk-EVH3OUMY.js} +13 -12
- package/dist/chunk-EVH3OUMY.js.map +1 -0
- package/dist/{chunk-5522X223.js → chunk-EXI7EHDN.js} +4 -4
- package/dist/{chunk-5522X223.js.map → chunk-EXI7EHDN.js.map} +1 -1
- package/dist/{chunk-PSLCVSCS.cjs → chunk-FR6COQXZ.cjs} +6 -6
- package/dist/{chunk-PSLCVSCS.cjs.map → chunk-FR6COQXZ.cjs.map} +1 -1
- package/dist/{chunk-JOFVLOFY.js → chunk-FTZTZBCU.js} +12 -4
- package/dist/chunk-FTZTZBCU.js.map +1 -0
- package/dist/{chunk-T5KOSR5Y.cjs → chunk-FYEHYQ7T.cjs} +8 -8
- package/dist/{chunk-T5KOSR5Y.cjs.map → chunk-FYEHYQ7T.cjs.map} +1 -1
- package/dist/{chunk-HOHR75KF.js → chunk-HI3W37FY.js} +4 -3
- package/dist/chunk-HI3W37FY.js.map +1 -0
- package/dist/chunk-HU666T3Q.cjs +1891 -0
- package/dist/chunk-HU666T3Q.cjs.map +1 -0
- package/dist/{chunk-53RDNK3H.js → chunk-I2ORT6QD.js} +3 -3
- package/dist/{chunk-53RDNK3H.js.map → chunk-I2ORT6QD.js.map} +1 -1
- package/dist/{chunk-UNZOJVVC.js → chunk-IZDDSLL2.js} +5 -4
- package/dist/chunk-IZDDSLL2.js.map +1 -0
- package/dist/{chunk-TTBIQTO5.cjs → chunk-L3C6CCBG.cjs} +15 -15
- package/dist/{chunk-TTBIQTO5.cjs.map → chunk-L3C6CCBG.cjs.map} +1 -1
- package/dist/{chunk-B3XXQX6L.cjs → chunk-NQVWSSX2.cjs} +10 -9
- package/dist/chunk-NQVWSSX2.cjs.map +1 -0
- package/dist/{chunk-LL4QA3DI.cjs → chunk-PCLRIQPX.cjs} +4 -4
- package/dist/{chunk-LL4QA3DI.cjs.map → chunk-PCLRIQPX.cjs.map} +1 -1
- package/dist/chunk-Q7GYMXVC.js +8 -0
- package/dist/chunk-Q7GYMXVC.js.map +1 -0
- package/dist/{chunk-ARMFXTY6.cjs → chunk-QY3CIMUV.cjs} +34 -33
- package/dist/chunk-QY3CIMUV.cjs.map +1 -0
- package/dist/chunk-R5YPDAKD.cjs +108 -0
- package/dist/chunk-R5YPDAKD.cjs.map +1 -0
- package/dist/chunk-RGQICWFU.js +82 -0
- package/dist/chunk-RGQICWFU.js.map +1 -0
- package/dist/{chunk-OOM236Z4.js → chunk-RTE2DD4S.js} +32 -18
- package/dist/chunk-RTE2DD4S.js.map +1 -0
- package/dist/chunk-SGC7LSHF.cjs +18 -0
- package/dist/{chunk-R3ZQBPA5.cjs.map → chunk-SGC7LSHF.cjs.map} +1 -1
- package/dist/{chunk-RA7IE4NK.cjs → chunk-SKDNCTXG.cjs} +4 -3
- package/dist/chunk-SKDNCTXG.cjs.map +1 -0
- package/dist/chunk-SVCPJRUB.js +1874 -0
- package/dist/chunk-SVCPJRUB.js.map +1 -0
- package/dist/{chunk-EJROML3Q.js → chunk-TX56N7FR.js} +4 -3
- package/dist/chunk-TX56N7FR.js.map +1 -0
- package/dist/{chunk-QDQQYRJI.js → chunk-W2ZVTEOD.js} +3 -3
- package/dist/{chunk-QDQQYRJI.js.map → chunk-W2ZVTEOD.js.map} +1 -1
- package/dist/{chunk-TC4RWP3Y.js → chunk-X3LOJJMO.js} +89 -29
- package/dist/chunk-X3LOJJMO.js.map +1 -0
- package/dist/{chunk-2WXHA33T.js → chunk-XERM7PDQ.js} +3 -3
- package/dist/{chunk-2WXHA33T.js.map → chunk-XERM7PDQ.js.map} +1 -1
- package/dist/{chunk-MEUBLCM4.cjs → chunk-YEHQ3SIC.cjs} +4 -3
- package/dist/chunk-YEHQ3SIC.cjs.map +1 -0
- package/dist/{chunk-YIFFF23U.cjs → chunk-ZAM7BJXJ.cjs} +5 -5
- package/dist/{chunk-YIFFF23U.cjs.map → chunk-ZAM7BJXJ.cjs.map} +1 -1
- package/dist/{chunk-76PIKR4P.cjs → chunk-ZD66GFH5.cjs} +91 -29
- package/dist/chunk-ZD66GFH5.cjs.map +1 -0
- package/dist/{chunk-GZV6AVRL.cjs → chunk-ZWACQM5U.cjs} +11 -3
- package/dist/chunk-ZWACQM5U.cjs.map +1 -0
- package/dist/{compact-session-RBPLUPCK.cjs → compact-session-4QHBBGEY.cjs} +16 -15
- package/dist/{compact-session-RBPLUPCK.cjs.map → compact-session-4QHBBGEY.cjs.map} +1 -1
- package/dist/{compact-session-2N3ZYJTW.js → compact-session-PVAWTKKL.js} +7 -6
- package/dist/{compact-session-2N3ZYJTW.js.map → compact-session-PVAWTKKL.js.map} +1 -1
- package/dist/{cron-DTuaPMVI.d.ts → cron-BPccQCO8.d.ts} +1 -1
- package/dist/{cron-QTgcwcZt.d.cts → cron-Blj6wMYg.d.cts} +1 -1
- package/dist/cron.cjs +17 -15
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +16 -14
- package/dist/eval.cjs +20 -18
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +16 -14
- package/dist/eval.js.map +1 -1
- package/dist/fs-session-store-3VI4CPTX.js +11 -0
- package/dist/{fs-session-store-STZZFXH2.js.map → fs-session-store-3VI4CPTX.js.map} +1 -1
- package/dist/fs-session-store-IQ6PEHYF.cjs +20 -0
- package/dist/{fs-session-store-JHBJFKVV.cjs.map → fs-session-store-IQ6PEHYF.cjs.map} +1 -1
- package/dist/{index-manager-ONQJSWX5.js → index-manager-JVYIVTZG.js} +6 -5
- package/dist/{index-manager-ONQJSWX5.js.map → index-manager-JVYIVTZG.js.map} +1 -1
- package/dist/{index-manager-ZGJN25FD.cjs → index-manager-YGXRFJMZ.cjs} +7 -6
- package/dist/{index-manager-ZGJN25FD.cjs.map → index-manager-YGXRFJMZ.cjs.map} +1 -1
- package/dist/index.cjs +68 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +42 -6
- package/dist/index.d.ts +42 -6
- package/dist/index.js +31 -23
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-YNNOE3O6.js → inject-session-O24XGRR6.js} +5 -5
- package/dist/{inject-session-YNNOE3O6.js.map → inject-session-O24XGRR6.js.map} +1 -1
- package/dist/{inject-session-3FPXJDJP.cjs → inject-session-OMLFL2V3.cjs} +7 -7
- package/dist/{inject-session-3FPXJDJP.cjs.map → inject-session-OMLFL2V3.cjs.map} +1 -1
- package/dist/internal/memory/adapters/index.cjs +3 -2
- package/dist/internal/memory/adapters/index.js +2 -1
- package/dist/internal/memory/dreaming/phases.d.ts +2 -0
- package/dist/internal/memory/dreaming/run.d.ts +5 -0
- package/dist/internal/memory/sdk-memory-peer-loader.d.ts +2 -0
- package/dist/internal/memory/storage/fact-ceiling.d.cts +19 -0
- package/dist/internal/memory/storage/fact-ceiling.d.ts +19 -0
- package/dist/internal/memory/storage/index.cjs +41 -32
- package/dist/internal/memory/storage/index.d.cts +1 -0
- package/dist/internal/memory/storage/index.d.ts +1 -0
- package/dist/internal/memory/storage/index.js +4 -3
- package/dist/internal/memory/storage/markdown-store.d.cts +3 -1
- package/dist/internal/memory/storage/markdown-store.d.ts +3 -1
- package/dist/internal/memory/types.d.ts +6 -0
- package/dist/internal/persistence/index.cjs +7 -6
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.js +2 -1
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/persistence/persistence-schema.d.cts +1 -1
- package/dist/internal/persistence/persistence-schema.d.ts +1 -1
- package/dist/internal/providers/catalog-loader.d.ts +30 -3
- package/dist/internal/runtime/registry/agent-registry-store.d.ts +2 -0
- package/dist/internal/runtime-fetch.d.ts +1 -0
- package/dist/models.cjs +12 -11
- package/dist/models.cjs.map +1 -1
- package/dist/models.js +4 -3
- package/dist/models.js.map +1 -1
- package/dist/persistence.cjs +14 -13
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +4 -3
- package/dist/persistence.js.map +1 -1
- package/dist/providers.cjs +6 -5
- package/dist/providers.js +4 -3
- package/dist/{session-transcript-VTBTCGQX.js → session-transcript-AR7IBICT.js} +3 -3
- package/dist/{session-transcript-VTBTCGQX.js.map → session-transcript-AR7IBICT.js.map} +1 -1
- package/dist/{session-transcript-LGHSNVY5.cjs → session-transcript-RACG7BK2.cjs} +16 -16
- package/dist/{session-transcript-LGHSNVY5.cjs.map → session-transcript-RACG7BK2.cjs.map} +1 -1
- package/dist/subagents-loader.d.cts +1 -1
- package/dist/subagents-loader.d.ts +1 -1
- package/dist/subscription/index.cjs +2 -1
- package/dist/subscription/index.cjs.map +1 -1
- package/dist/subscription/index.js +2 -1
- package/dist/subscription/index.js.map +1 -1
- package/dist/types/agent.d.ts +27 -0
- package/docs/error-codes.md +40 -38
- package/docs/harness-capability-map.md +6 -1
- package/package.json +2 -2
- package/dist/agent-session-store-AFML3AXC.js +0 -6
- package/dist/agent-session-store-MTSIY3MH.cjs +0 -23
- package/dist/chunk-56BCEM26.cjs.map +0 -1
- package/dist/chunk-76PIKR4P.cjs.map +0 -1
- package/dist/chunk-ARMFXTY6.cjs.map +0 -1
- package/dist/chunk-B3XXQX6L.cjs.map +0 -1
- package/dist/chunk-BKMDRBJ7.js +0 -180
- package/dist/chunk-BKMDRBJ7.js.map +0 -1
- package/dist/chunk-EJROML3Q.js.map +0 -1
- package/dist/chunk-GZV6AVRL.cjs.map +0 -1
- package/dist/chunk-HOHR75KF.js.map +0 -1
- package/dist/chunk-JOFVLOFY.js.map +0 -1
- package/dist/chunk-MEUBLCM4.cjs.map +0 -1
- package/dist/chunk-MFZODA5Y.js +0 -583
- package/dist/chunk-MFZODA5Y.js.map +0 -1
- package/dist/chunk-NOO6GZTZ.js.map +0 -1
- package/dist/chunk-OF2CLCTH.cjs +0 -186
- package/dist/chunk-OF2CLCTH.cjs.map +0 -1
- package/dist/chunk-OOM236Z4.js.map +0 -1
- package/dist/chunk-R3ZQBPA5.cjs +0 -18
- package/dist/chunk-RA7IE4NK.cjs.map +0 -1
- package/dist/chunk-TC4RWP3Y.js.map +0 -1
- package/dist/chunk-UNZOJVVC.js.map +0 -1
- package/dist/chunk-YRJA2POB.cjs +0 -601
- package/dist/chunk-YRJA2POB.cjs.map +0 -1
- package/dist/fs-session-store-JHBJFKVV.cjs +0 -19
- package/dist/fs-session-store-STZZFXH2.js +0 -10
- package/dist/provider-catalog.json +0 -1295
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { enqueueSessionWrite } from './chunk-
|
|
1
|
+
import { enqueueSessionWrite } from './chunk-EXI7EHDN.js';
|
|
2
2
|
import { invalidateSessionCache } from './chunk-2XC6KDJM.js';
|
|
3
|
-
import './chunk-
|
|
4
|
-
import { SessionTranscript } from './chunk-
|
|
3
|
+
import './chunk-XERM7PDQ.js';
|
|
4
|
+
import { SessionTranscript } from './chunk-FTZTZBCU.js';
|
|
5
5
|
import './chunk-3JHIFQ4I.js';
|
|
6
6
|
import './chunk-AGACYRJ2.js';
|
|
7
7
|
import './chunk-CZJ6Q7CW.js';
|
|
@@ -23,5 +23,5 @@ async function injectSessionTurn(opts) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export { injectSessionTurn };
|
|
26
|
-
//# sourceMappingURL=inject-session-
|
|
27
|
-
//# sourceMappingURL=inject-session-
|
|
26
|
+
//# sourceMappingURL=inject-session-O24XGRR6.js.map
|
|
27
|
+
//# sourceMappingURL=inject-session-O24XGRR6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":[],"mappings":";;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAM,oBAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAa,iBAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAA,sBAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-
|
|
1
|
+
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":[],"mappings":";;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAM,oBAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAa,iBAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAA,sBAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-O24XGRR6.js","sourcesContent":["/**\n * M51 (agent-builder) — inject a SYNTHETIC user+assistant pair into a session's persisted transcript\n * WITHOUT running an LLM turn. This is the Codex review-exit mechanism (`exit_success.xml` appended to\n * the parent thread history so follow-ups like \"fix finding 2\" work): the pair chains onto the DAG\n * leaf (M50 pattern) and the in-memory cache is invalidated so the NEXT send re-hydrates with it.\n */\nimport type { SessionStore } from \"../../types/session-store.js\";\nimport { SessionTranscript } from \"../persistence/session-transcript.js\";\nimport { enqueueSessionWrite, invalidateSessionCache } from \"./agent-session.js\";\nimport type { CompactLocation } from \"./compact-session.js\";\n\nexport async function injectSessionTurn(opts: {\n store: SessionStore;\n loc: CompactLocation;\n sessionId: string;\n userText: string;\n assistantText: string;\n}): Promise<void> {\n await enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {\n const prior = await opts.store.readRecords(opts.loc.agentId);\n const transcript = SessionTranscript.fromRecords(prior, {\n cwd: opts.loc.cwd,\n sessionId: opts.sessionId,\n model: opts.loc.model ?? \"unknown\",\n });\n transcript.appendUserTurn(opts.userText);\n transcript.appendAssistantTurn({ text: opts.assistantText });\n await opts.store.appendRecords(opts.loc.agentId, transcript.records().slice(prior.length));\n invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);\n });\n}\n"]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFR6COQXZ_cjs = require('./chunk-FR6COQXZ.cjs');
|
|
4
4
|
var chunkYJNYDJ2T_cjs = require('./chunk-YJNYDJ2T.cjs');
|
|
5
|
-
require('./chunk-
|
|
6
|
-
var
|
|
5
|
+
require('./chunk-ZAM7BJXJ.cjs');
|
|
6
|
+
var chunkZWACQM5U_cjs = require('./chunk-ZWACQM5U.cjs');
|
|
7
7
|
require('./chunk-JLRLCBJ4.cjs');
|
|
8
8
|
require('./chunk-NVXXWAU7.cjs');
|
|
9
9
|
require('./chunk-6LHQPOMI.cjs');
|
|
10
10
|
|
|
11
11
|
// src/internal/session/inject-session.ts
|
|
12
12
|
async function injectSessionTurn(opts) {
|
|
13
|
-
await
|
|
13
|
+
await chunkFR6COQXZ_cjs.enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {
|
|
14
14
|
const prior = await opts.store.readRecords(opts.loc.agentId);
|
|
15
|
-
const transcript =
|
|
15
|
+
const transcript = chunkZWACQM5U_cjs.SessionTranscript.fromRecords(prior, {
|
|
16
16
|
cwd: opts.loc.cwd,
|
|
17
17
|
sessionId: opts.sessionId,
|
|
18
18
|
model: opts.loc.model ?? "unknown"
|
|
@@ -25,5 +25,5 @@ async function injectSessionTurn(opts) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
exports.injectSessionTurn = injectSessionTurn;
|
|
28
|
-
//# sourceMappingURL=inject-session-
|
|
29
|
-
//# sourceMappingURL=inject-session-
|
|
28
|
+
//# sourceMappingURL=inject-session-OMLFL2V3.cjs.map
|
|
29
|
+
//# sourceMappingURL=inject-session-OMLFL2V3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":["enqueueSessionWrite","SessionTranscript","invalidateSessionCache"],"mappings":";;;;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAMA,sCAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAaC,mCAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAAC,wCAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-
|
|
1
|
+
{"version":3,"sources":["../src/internal/session/inject-session.ts"],"names":["enqueueSessionWrite","SessionTranscript","invalidateSessionCache"],"mappings":";;;;;;;;;;;AAWA,eAAsB,kBAAkB,IAAA,EAMtB;AAChB,EAAA,MAAMA,sCAAoB,IAAA,CAAK,GAAA,CAAI,KAAK,IAAA,CAAK,GAAA,CAAI,SAAS,YAAY;AACpE,IAAA,MAAM,QAAQ,MAAM,IAAA,CAAK,MAAM,WAAA,CAAY,IAAA,CAAK,IAAI,OAAO,CAAA;AAC3D,IAAA,MAAM,UAAA,GAAaC,mCAAA,CAAkB,WAAA,CAAY,KAAA,EAAO;AAAA,MACtD,GAAA,EAAK,KAAK,GAAA,CAAI,GAAA;AAAA,MACd,WAAW,IAAA,CAAK,SAAA;AAAA,MAChB,KAAA,EAAO,IAAA,CAAK,GAAA,CAAI,KAAA,IAAS;AAAA,KAC1B,CAAA;AACD,IAAA,UAAA,CAAW,cAAA,CAAe,KAAK,QAAQ,CAAA;AACvC,IAAA,UAAA,CAAW,mBAAA,CAAoB,EAAE,IAAA,EAAM,IAAA,CAAK,eAAe,CAAA;AAC3D,IAAA,MAAM,IAAA,CAAK,KAAA,CAAM,aAAA,CAAc,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,UAAA,CAAW,OAAA,EAAQ,CAAE,KAAA,CAAM,KAAA,CAAM,MAAM,CAAC,CAAA;AACzF,IAAAC,wCAAA,CAAuB,IAAA,CAAK,GAAA,CAAI,GAAA,EAAK,IAAA,CAAK,IAAI,OAAO,CAAA;AAAA,EACvD,CAAC,CAAA;AACH","file":"inject-session-OMLFL2V3.cjs","sourcesContent":["/**\n * M51 (agent-builder) — inject a SYNTHETIC user+assistant pair into a session's persisted transcript\n * WITHOUT running an LLM turn. This is the Codex review-exit mechanism (`exit_success.xml` appended to\n * the parent thread history so follow-ups like \"fix finding 2\" work): the pair chains onto the DAG\n * leaf (M50 pattern) and the in-memory cache is invalidated so the NEXT send re-hydrates with it.\n */\nimport type { SessionStore } from \"../../types/session-store.js\";\nimport { SessionTranscript } from \"../persistence/session-transcript.js\";\nimport { enqueueSessionWrite, invalidateSessionCache } from \"./agent-session.js\";\nimport type { CompactLocation } from \"./compact-session.js\";\n\nexport async function injectSessionTurn(opts: {\n store: SessionStore;\n loc: CompactLocation;\n sessionId: string;\n userText: string;\n assistantText: string;\n}): Promise<void> {\n await enqueueSessionWrite(opts.loc.cwd, opts.loc.agentId, async () => {\n const prior = await opts.store.readRecords(opts.loc.agentId);\n const transcript = SessionTranscript.fromRecords(prior, {\n cwd: opts.loc.cwd,\n sessionId: opts.sessionId,\n model: opts.loc.model ?? \"unknown\",\n });\n transcript.appendUserTurn(opts.userText);\n transcript.appendAssistantTurn({ text: opts.assistantText });\n await opts.store.appendRecords(opts.loc.agentId, transcript.records().slice(prior.length));\n invalidateSessionCache(opts.loc.cwd, opts.loc.agentId);\n });\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkYEHQ3SIC_cjs = require('../../../chunk-YEHQ3SIC.cjs');
|
|
4
4
|
var chunkGHX4P3V2_cjs = require('../../../chunk-GHX4P3V2.cjs');
|
|
5
5
|
require('../../../chunk-WPO3VCY4.cjs');
|
|
6
6
|
require('../../../chunk-QOGNZMHD.cjs');
|
|
@@ -9,6 +9,7 @@ require('../../../chunk-GM54F4FE.cjs');
|
|
|
9
9
|
require('../../../chunk-SA6K24NB.cjs');
|
|
10
10
|
require('../../../chunk-IIYJMXYW.cjs');
|
|
11
11
|
require('../../../chunk-NJSIAJEK.cjs');
|
|
12
|
+
require('../../../chunk-EHD25JBZ.cjs');
|
|
12
13
|
require('../../../chunk-UNFBHV46.cjs');
|
|
13
14
|
require('../../../chunk-6LHQPOMI.cjs');
|
|
14
15
|
|
|
@@ -16,7 +17,7 @@ require('../../../chunk-6LHQPOMI.cjs');
|
|
|
16
17
|
|
|
17
18
|
Object.defineProperty(exports, "createOpenAiCompatibleRuntime", {
|
|
18
19
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
20
|
+
get: function () { return chunkYEHQ3SIC_cjs.createOpenAiCompatibleRuntime; }
|
|
20
21
|
});
|
|
21
22
|
Object.defineProperty(exports, "LruEmbeddingCache", {
|
|
22
23
|
enumerable: true,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createOpenAiCompatibleRuntime } from '../../../chunk-
|
|
1
|
+
export { createOpenAiCompatibleRuntime } from '../../../chunk-HI3W37FY.js';
|
|
2
2
|
export { LruEmbeddingCache, globalEmbeddingCache } from '../../../chunk-H73MEMQB.js';
|
|
3
3
|
import '../../../chunk-TE6XVTOA.js';
|
|
4
4
|
import '../../../chunk-24MGQDK3.js';
|
|
@@ -7,6 +7,7 @@ import '../../../chunk-5DD4NJN3.js';
|
|
|
7
7
|
import '../../../chunk-UKMBRMGT.js';
|
|
8
8
|
import '../../../chunk-7JAKO3NM.js';
|
|
9
9
|
import '../../../chunk-ZWFTECOE.js';
|
|
10
|
+
import '../../../chunk-Q7GYMXVC.js';
|
|
10
11
|
import '../../../chunk-B5MHRQJZ.js';
|
|
11
12
|
import '../../../chunk-CZJ6Q7CW.js';
|
|
12
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,6 +6,8 @@ export interface Cluster {
|
|
|
6
6
|
}
|
|
7
7
|
export interface ClusterResult {
|
|
8
8
|
clusters: Cluster[];
|
|
9
|
+
/** How many input facts past the per-sweep cap were not clustered; 0 when none were. */
|
|
10
|
+
factsLeftOut: number;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Light phase — drop facts whose embedding is too similar to one already kept.
|
|
@@ -6,5 +6,10 @@ export interface DreamingResult {
|
|
|
6
6
|
clustersCreated: number;
|
|
7
7
|
notesWritten: number;
|
|
8
8
|
diaryEntryHash: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Deduplicated facts past the per-sweep cap that were not clustered. Set on `"ok"`, 0 on
|
|
11
|
+
* `"skipped"`, and absent on `"error"`, where the sweep cannot say how many it left out.
|
|
12
|
+
*/
|
|
13
|
+
factsLeftOut?: number;
|
|
9
14
|
}
|
|
10
15
|
export declare function runDreamingSweep(options: DreamingOptions): Promise<DreamingResult>;
|
|
@@ -44,6 +44,8 @@ export interface SdkMemoryModule {
|
|
|
44
44
|
duplicatesRemoved: number;
|
|
45
45
|
clustersCreated: number;
|
|
46
46
|
notesWritten: number;
|
|
47
|
+
/** Optional: a peer older than the one that reports the count leaves it out. */
|
|
48
|
+
factsLeftOut?: number;
|
|
47
49
|
}>;
|
|
48
50
|
/** Mirrors @theokit/sdk-memory's IndexManager class (static open). */
|
|
49
51
|
readonly IndexManager: {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConfigurationError } from "../../../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ceiling a caller declared, or `undefined` when none was declared.
|
|
4
|
+
*
|
|
5
|
+
* Validated before anything touches disk, because a ceiling that cannot be met (0, a negative or
|
|
6
|
+
* fractional number, a string, `null`) would otherwise surface later as a refusal of every write
|
|
7
|
+
* that names the wrong cause.
|
|
8
|
+
*
|
|
9
|
+
* @throws ConfigurationError with code `invalid_memory_ceiling` when the value is declared and is
|
|
10
|
+
* not a positive safe integer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveMaxFacts(value: unknown): number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The refusal of a new fact at a store's declared ceiling: where the store is, how many facts it
|
|
15
|
+
* holds, the ceiling, and what to consolidate. `remedy` is the store-specific way to make room.
|
|
16
|
+
*
|
|
17
|
+
* Returned, not thrown, so each writer throws it at the point where it has written nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ceilingReachedError(where: string, count: number, maxFacts: number, remedy: string): ConfigurationError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ConfigurationError } from "../../../errors.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ceiling a caller declared, or `undefined` when none was declared.
|
|
4
|
+
*
|
|
5
|
+
* Validated before anything touches disk, because a ceiling that cannot be met (0, a negative or
|
|
6
|
+
* fractional number, a string, `null`) would otherwise surface later as a refusal of every write
|
|
7
|
+
* that names the wrong cause.
|
|
8
|
+
*
|
|
9
|
+
* @throws ConfigurationError with code `invalid_memory_ceiling` when the value is declared and is
|
|
10
|
+
* not a positive safe integer.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveMaxFacts(value: unknown): number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The refusal of a new fact at a store's declared ceiling: where the store is, how many facts it
|
|
15
|
+
* holds, the ceiling, and what to consolidate. `remedy` is the store-specific way to make room.
|
|
16
|
+
*
|
|
17
|
+
* Returned, not thrown, so each writer throws it at the point where it has written nothing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function ceilingReachedError(where: string, count: number, maxFacts: number, remedy: string): ConfigurationError;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkFYEHYQ7T_cjs = require('../../../chunk-FYEHYQ7T.cjs');
|
|
4
4
|
var chunkTMKTSYDS_cjs = require('../../../chunk-TMKTSYDS.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkZD66GFH5_cjs = require('../../../chunk-ZD66GFH5.cjs');
|
|
6
6
|
require('../../../chunk-KRD3GQAA.cjs');
|
|
7
7
|
require('../../../chunk-MUUQ2WFJ.cjs');
|
|
8
8
|
require('../../../chunk-SWALPLFQ.cjs');
|
|
9
9
|
require('../../../chunk-GM54F4FE.cjs');
|
|
10
10
|
require('../../../chunk-SA6K24NB.cjs');
|
|
11
|
-
require('../../../chunk-
|
|
11
|
+
require('../../../chunk-ZWACQM5U.cjs');
|
|
12
12
|
require('../../../chunk-P22BZE7G.cjs');
|
|
13
|
+
require('../../../chunk-ASK2OQM5.cjs');
|
|
13
14
|
require('../../../chunk-ZF2LDKQQ.cjs');
|
|
14
15
|
require('../../../chunk-JLRLCBJ4.cjs');
|
|
15
16
|
require('../../../chunk-UNFBHV46.cjs');
|
|
@@ -19,23 +20,23 @@ require('../../../chunk-6LHQPOMI.cjs');
|
|
|
19
20
|
|
|
20
21
|
Object.defineProperty(exports, "appendDiaryEntry", {
|
|
21
22
|
enumerable: true,
|
|
22
|
-
get: function () { return
|
|
23
|
+
get: function () { return chunkFYEHYQ7T_cjs.appendDiaryEntry; }
|
|
23
24
|
});
|
|
24
25
|
Object.defineProperty(exports, "diaryPath", {
|
|
25
26
|
enumerable: true,
|
|
26
|
-
get: function () { return
|
|
27
|
+
get: function () { return chunkFYEHYQ7T_cjs.diaryPath; }
|
|
27
28
|
});
|
|
28
29
|
Object.defineProperty(exports, "entryHash", {
|
|
29
30
|
enumerable: true,
|
|
30
|
-
get: function () { return
|
|
31
|
+
get: function () { return chunkFYEHYQ7T_cjs.entryHash; }
|
|
31
32
|
});
|
|
32
33
|
Object.defineProperty(exports, "readAllSqliteFacts", {
|
|
33
34
|
enumerable: true,
|
|
34
|
-
get: function () { return
|
|
35
|
+
get: function () { return chunkFYEHYQ7T_cjs.readAllSqliteFacts; }
|
|
35
36
|
});
|
|
36
37
|
Object.defineProperty(exports, "renderDiaryEntry", {
|
|
37
38
|
enumerable: true,
|
|
38
|
-
get: function () { return
|
|
39
|
+
get: function () { return chunkFYEHYQ7T_cjs.renderDiaryEntry; }
|
|
39
40
|
});
|
|
40
41
|
Object.defineProperty(exports, "persistActiveMemoryTranscript", {
|
|
41
42
|
enumerable: true,
|
|
@@ -43,99 +44,107 @@ Object.defineProperty(exports, "persistActiveMemoryTranscript", {
|
|
|
43
44
|
});
|
|
44
45
|
Object.defineProperty(exports, "MEMORY_INDEX_MAX_BYTES", {
|
|
45
46
|
enumerable: true,
|
|
46
|
-
get: function () { return
|
|
47
|
+
get: function () { return chunkZD66GFH5_cjs.MEMORY_INDEX_MAX_BYTES; }
|
|
47
48
|
});
|
|
48
49
|
Object.defineProperty(exports, "MEMORY_INDEX_MAX_LINES", {
|
|
49
50
|
enumerable: true,
|
|
50
|
-
get: function () { return
|
|
51
|
+
get: function () { return chunkZD66GFH5_cjs.MEMORY_INDEX_MAX_LINES; }
|
|
51
52
|
});
|
|
52
53
|
Object.defineProperty(exports, "appendFact", {
|
|
53
54
|
enumerable: true,
|
|
54
|
-
get: function () { return
|
|
55
|
+
get: function () { return chunkZD66GFH5_cjs.appendFact; }
|
|
55
56
|
});
|
|
56
57
|
Object.defineProperty(exports, "appendFactToMarkdown", {
|
|
57
58
|
enumerable: true,
|
|
58
|
-
get: function () { return
|
|
59
|
+
get: function () { return chunkZD66GFH5_cjs.appendFactToMarkdown; }
|
|
59
60
|
});
|
|
60
61
|
Object.defineProperty(exports, "asMemoryRoot", {
|
|
61
62
|
enumerable: true,
|
|
62
|
-
get: function () { return
|
|
63
|
+
get: function () { return chunkZD66GFH5_cjs.asMemoryRoot; }
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, "ceilingReachedError", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () { return chunkZD66GFH5_cjs.ceilingReachedError; }
|
|
63
68
|
});
|
|
64
69
|
Object.defineProperty(exports, "claudeProjectMemoryDir", {
|
|
65
70
|
enumerable: true,
|
|
66
|
-
get: function () { return
|
|
71
|
+
get: function () { return chunkZD66GFH5_cjs.claudeProjectMemoryDir; }
|
|
67
72
|
});
|
|
68
73
|
Object.defineProperty(exports, "collectMarkdownFiles", {
|
|
69
74
|
enumerable: true,
|
|
70
|
-
get: function () { return
|
|
75
|
+
get: function () { return chunkZD66GFH5_cjs.collectMarkdownFiles; }
|
|
71
76
|
});
|
|
72
77
|
Object.defineProperty(exports, "defaultIndexPath", {
|
|
73
78
|
enumerable: true,
|
|
74
|
-
get: function () { return
|
|
79
|
+
get: function () { return chunkZD66GFH5_cjs.defaultIndexPath; }
|
|
75
80
|
});
|
|
76
81
|
Object.defineProperty(exports, "discoverSessionFiles", {
|
|
77
82
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
83
|
+
get: function () { return chunkZD66GFH5_cjs.discoverSessionFiles; }
|
|
79
84
|
});
|
|
80
85
|
Object.defineProperty(exports, "discoverWikiFiles", {
|
|
81
86
|
enumerable: true,
|
|
82
|
-
get: function () { return
|
|
87
|
+
get: function () { return chunkZD66GFH5_cjs.discoverWikiFiles; }
|
|
83
88
|
});
|
|
84
89
|
Object.defineProperty(exports, "indexBudgetWarning", {
|
|
85
90
|
enumerable: true,
|
|
86
|
-
get: function () { return
|
|
91
|
+
get: function () { return chunkZD66GFH5_cjs.indexBudgetWarning; }
|
|
87
92
|
});
|
|
88
93
|
Object.defineProperty(exports, "lanceStoragePath", {
|
|
89
94
|
enumerable: true,
|
|
90
|
-
get: function () { return
|
|
95
|
+
get: function () { return chunkZD66GFH5_cjs.lanceStoragePath; }
|
|
91
96
|
});
|
|
92
97
|
Object.defineProperty(exports, "memoryIndexRoot", {
|
|
93
98
|
enumerable: true,
|
|
94
|
-
get: function () { return
|
|
99
|
+
get: function () { return chunkZD66GFH5_cjs.memoryIndexRoot; }
|
|
95
100
|
});
|
|
96
101
|
Object.defineProperty(exports, "memoryMdPath", {
|
|
97
102
|
enumerable: true,
|
|
98
|
-
get: function () { return
|
|
103
|
+
get: function () { return chunkZD66GFH5_cjs.memoryMdPath; }
|
|
99
104
|
});
|
|
100
105
|
Object.defineProperty(exports, "memoryReadRoots", {
|
|
101
106
|
enumerable: true,
|
|
102
|
-
get: function () { return
|
|
107
|
+
get: function () { return chunkZD66GFH5_cjs.memoryReadRoots; }
|
|
103
108
|
});
|
|
104
109
|
Object.defineProperty(exports, "notesDir", {
|
|
105
110
|
enumerable: true,
|
|
106
|
-
get: function () { return
|
|
111
|
+
get: function () { return chunkZD66GFH5_cjs.notesDir; }
|
|
107
112
|
});
|
|
108
113
|
Object.defineProperty(exports, "projectMemoryDir", {
|
|
109
114
|
enumerable: true,
|
|
110
|
-
get: function () { return
|
|
115
|
+
get: function () { return chunkZD66GFH5_cjs.projectMemoryDir; }
|
|
111
116
|
});
|
|
112
117
|
Object.defineProperty(exports, "readFacts", {
|
|
113
118
|
enumerable: true,
|
|
114
|
-
get: function () { return
|
|
119
|
+
get: function () { return chunkZD66GFH5_cjs.readFacts; }
|
|
115
120
|
});
|
|
116
121
|
Object.defineProperty(exports, "readFactsFromMarkdown", {
|
|
117
122
|
enumerable: true,
|
|
118
|
-
get: function () { return
|
|
123
|
+
get: function () { return chunkZD66GFH5_cjs.readFactsFromMarkdown; }
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "resolveMaxFacts", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function () { return chunkZD66GFH5_cjs.resolveMaxFacts; }
|
|
119
128
|
});
|
|
120
129
|
Object.defineProperty(exports, "resolveMemoryRoot", {
|
|
121
130
|
enumerable: true,
|
|
122
|
-
get: function () { return
|
|
131
|
+
get: function () { return chunkZD66GFH5_cjs.resolveMemoryRoot; }
|
|
123
132
|
});
|
|
124
133
|
Object.defineProperty(exports, "sessionSummaryPath", {
|
|
125
134
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
135
|
+
get: function () { return chunkZD66GFH5_cjs.sessionSummaryPath; }
|
|
127
136
|
});
|
|
128
137
|
Object.defineProperty(exports, "sessionsDir", {
|
|
129
138
|
enumerable: true,
|
|
130
|
-
get: function () { return
|
|
139
|
+
get: function () { return chunkZD66GFH5_cjs.sessionsDir; }
|
|
131
140
|
});
|
|
132
141
|
Object.defineProperty(exports, "wikiDir", {
|
|
133
142
|
enumerable: true,
|
|
134
|
-
get: function () { return
|
|
143
|
+
get: function () { return chunkZD66GFH5_cjs.wikiDir; }
|
|
135
144
|
});
|
|
136
145
|
Object.defineProperty(exports, "writeSessionSummary", {
|
|
137
146
|
enumerable: true,
|
|
138
|
-
get: function () { return
|
|
147
|
+
get: function () { return chunkZD66GFH5_cjs.writeSessionSummary; }
|
|
139
148
|
});
|
|
140
149
|
//# sourceMappingURL=index.cjs.map
|
|
141
150
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -20,6 +20,7 @@ export { defaultIndexPath } from "../index-db.js";
|
|
|
20
20
|
export { collectMarkdownFiles, type DiscoveredFile } from "../index-manager-helpers.js";
|
|
21
21
|
export { lanceStoragePath } from "../lance-index.js";
|
|
22
22
|
export { readAllSqliteFacts, type SqliteFactRow } from "../migrate-sqlite-to-lance.js";
|
|
23
|
+
export { ceilingReachedError, resolveMaxFacts } from "./fact-ceiling.js";
|
|
23
24
|
export { appendFact, appendFactToMarkdown, memoryMdPath, notesDir, readFacts, readFactsFromMarkdown, } from "./markdown-store.js";
|
|
24
25
|
export { asMemoryRoot, claudeProjectMemoryDir, indexBudgetWarning, MEMORY_INDEX_MAX_BYTES, MEMORY_INDEX_MAX_LINES, type MemoryLocationConfig, type MemoryRoot, memoryIndexRoot, memoryReadRoots, projectMemoryDir, resolveMemoryRoot, } from "./memory-root.js";
|
|
25
26
|
export { discoverSessionFiles, type SessionFile } from "./session-loader.js";
|
|
@@ -20,6 +20,7 @@ export { defaultIndexPath } from "../index-db.js";
|
|
|
20
20
|
export { collectMarkdownFiles, type DiscoveredFile } from "../index-manager-helpers.js";
|
|
21
21
|
export { lanceStoragePath } from "../lance-index.js";
|
|
22
22
|
export { readAllSqliteFacts, type SqliteFactRow } from "../migrate-sqlite-to-lance.js";
|
|
23
|
+
export { ceilingReachedError, resolveMaxFacts } from "./fact-ceiling.js";
|
|
23
24
|
export { appendFact, appendFactToMarkdown, memoryMdPath, notesDir, readFacts, readFactsFromMarkdown, } from "./markdown-store.js";
|
|
24
25
|
export { asMemoryRoot, claudeProjectMemoryDir, indexBudgetWarning, MEMORY_INDEX_MAX_BYTES, MEMORY_INDEX_MAX_LINES, type MemoryLocationConfig, type MemoryRoot, memoryIndexRoot, memoryReadRoots, projectMemoryDir, resolveMemoryRoot, } from "./memory-root.js";
|
|
25
26
|
export { discoverSessionFiles, type SessionFile } from "./session-loader.js";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
export { appendDiaryEntry, diaryPath, entryHash, readAllSqliteFacts, renderDiaryEntry } from '../../../chunk-
|
|
1
|
+
export { appendDiaryEntry, diaryPath, entryHash, readAllSqliteFacts, renderDiaryEntry } from '../../../chunk-W2ZVTEOD.js';
|
|
2
2
|
export { persistActiveMemoryTranscript } from '../../../chunk-OR6XIWLB.js';
|
|
3
|
-
export { MEMORY_INDEX_MAX_BYTES, MEMORY_INDEX_MAX_LINES, appendFact, appendFactToMarkdown, asMemoryRoot, claudeProjectMemoryDir, collectMarkdownFiles, defaultIndexPath, discoverSessionFiles, discoverWikiFiles, indexBudgetWarning, lanceStoragePath, memoryIndexRoot, memoryMdPath, memoryReadRoots, notesDir, projectMemoryDir, readFacts, readFactsFromMarkdown, resolveMemoryRoot, sessionSummaryPath, sessionsDir, wikiDir, writeSessionSummary } from '../../../chunk-
|
|
3
|
+
export { MEMORY_INDEX_MAX_BYTES, MEMORY_INDEX_MAX_LINES, appendFact, appendFactToMarkdown, asMemoryRoot, ceilingReachedError, claudeProjectMemoryDir, collectMarkdownFiles, defaultIndexPath, discoverSessionFiles, discoverWikiFiles, indexBudgetWarning, lanceStoragePath, memoryIndexRoot, memoryMdPath, memoryReadRoots, notesDir, projectMemoryDir, readFacts, readFactsFromMarkdown, resolveMaxFacts, resolveMemoryRoot, sessionSummaryPath, sessionsDir, wikiDir, writeSessionSummary } from '../../../chunk-X3LOJJMO.js';
|
|
4
4
|
import '../../../chunk-KVNWIAO4.js';
|
|
5
5
|
import '../../../chunk-FD2UT76F.js';
|
|
6
6
|
import '../../../chunk-4QCJAJAG.js';
|
|
7
7
|
import '../../../chunk-5DD4NJN3.js';
|
|
8
8
|
import '../../../chunk-UKMBRMGT.js';
|
|
9
|
-
import '../../../chunk-
|
|
9
|
+
import '../../../chunk-FTZTZBCU.js';
|
|
10
10
|
import '../../../chunk-XZHJYSPB.js';
|
|
11
|
+
import '../../../chunk-RGQICWFU.js';
|
|
11
12
|
import '../../../chunk-Q5EWJPRY.js';
|
|
12
13
|
import '../../../chunk-3JHIFQ4I.js';
|
|
13
14
|
import '../../../chunk-B5MHRQJZ.js';
|
|
@@ -29,7 +29,9 @@ export declare function readFactsFromMarkdown(cwd: string, config?: MemoryLocati
|
|
|
29
29
|
* `modified` is stamped HERE and never read from `fact`: a timestamp a caller can set is a
|
|
30
30
|
* timestamp that can lie about when something was learned, and weighing recency is the point.
|
|
31
31
|
*/
|
|
32
|
-
export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact, targetDir?: string
|
|
32
|
+
export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact, targetDir?: string, options?: {
|
|
33
|
+
maxFacts?: number;
|
|
34
|
+
}): Promise<void>;
|
|
33
35
|
/**
|
|
34
36
|
* Every memory in the store, honouring the `enabled` gate on {@link MemoryConfig}: when memory is
|
|
35
37
|
* disabled the call resolves to `[]` without touching disk. Configuration-aware entry point;
|
|
@@ -29,7 +29,9 @@ export declare function readFactsFromMarkdown(cwd: string, config?: MemoryLocati
|
|
|
29
29
|
* `modified` is stamped HERE and never read from `fact`: a timestamp a caller can set is a
|
|
30
30
|
* timestamp that can lie about when something was learned, and weighing recency is the point.
|
|
31
31
|
*/
|
|
32
|
-
export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact, targetDir?: string
|
|
32
|
+
export declare function appendFactToMarkdown(cwd: string, fact: MemoryFact, targetDir?: string, options?: {
|
|
33
|
+
maxFacts?: number;
|
|
34
|
+
}): Promise<void>;
|
|
33
35
|
/**
|
|
34
36
|
* Every memory in the store, honouring the `enabled` gate on {@link MemoryConfig}: when memory is
|
|
35
37
|
* disabled the call resolves to `[]` without touching disk. Configuration-aware entry point;
|
|
@@ -9,6 +9,12 @@ export interface MemoryConfig {
|
|
|
9
9
|
* See `storage/memory-root.ts` for why a relative value is refused rather than resolved.
|
|
10
10
|
*/
|
|
11
11
|
directory?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The most facts the write directory may hold. A new fact at the ceiling is refused with
|
|
14
|
+
* `memory_ceiling_reached`; a second observation of a stored fact is still admitted. Absent means
|
|
15
|
+
* no ceiling. The public contract is `MemorySettings.maxFacts` in `types/agent.ts`.
|
|
16
|
+
*/
|
|
17
|
+
maxFacts?: number;
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* What a fact IS, which is what decides whether it ages (#389).
|
|
@@ -4,7 +4,8 @@ var chunkVTYY7XL5_cjs = require('../../chunk-VTYY7XL5.cjs');
|
|
|
4
4
|
var chunkRQMCOFAI_cjs = require('../../chunk-RQMCOFAI.cjs');
|
|
5
5
|
var chunkA4RAL2ER_cjs = require('../../chunk-A4RAL2ER.cjs');
|
|
6
6
|
var chunkP22BZE7G_cjs = require('../../chunk-P22BZE7G.cjs');
|
|
7
|
-
var
|
|
7
|
+
var chunkR5YPDAKD_cjs = require('../../chunk-R5YPDAKD.cjs');
|
|
8
|
+
var chunkASK2OQM5_cjs = require('../../chunk-ASK2OQM5.cjs');
|
|
8
9
|
var chunkZF2LDKQQ_cjs = require('../../chunk-ZF2LDKQQ.cjs');
|
|
9
10
|
var chunkJLRLCBJ4_cjs = require('../../chunk-JLRLCBJ4.cjs');
|
|
10
11
|
var chunkTY56BKSK_cjs = require('../../chunk-TY56BKSK.cjs');
|
|
@@ -75,23 +76,23 @@ Object.defineProperty(exports, "openSqliteResilient", {
|
|
|
75
76
|
});
|
|
76
77
|
Object.defineProperty(exports, "JsonlParseError", {
|
|
77
78
|
enumerable: true,
|
|
78
|
-
get: function () { return
|
|
79
|
+
get: function () { return chunkR5YPDAKD_cjs.JsonlParseError; }
|
|
79
80
|
});
|
|
80
81
|
Object.defineProperty(exports, "appendJsonl", {
|
|
81
82
|
enumerable: true,
|
|
82
|
-
get: function () { return
|
|
83
|
+
get: function () { return chunkR5YPDAKD_cjs.appendJsonl; }
|
|
83
84
|
});
|
|
84
85
|
Object.defineProperty(exports, "loadJsonl", {
|
|
85
86
|
enumerable: true,
|
|
86
|
-
get: function () { return
|
|
87
|
+
get: function () { return chunkR5YPDAKD_cjs.loadJsonl; }
|
|
87
88
|
});
|
|
88
89
|
Object.defineProperty(exports, "readJsonlIds", {
|
|
89
90
|
enumerable: true,
|
|
90
|
-
get: function () { return
|
|
91
|
+
get: function () { return chunkR5YPDAKD_cjs.readJsonlIds; }
|
|
91
92
|
});
|
|
92
93
|
Object.defineProperty(exports, "withFileLock", {
|
|
93
94
|
enumerable: true,
|
|
94
|
-
get: function () { return
|
|
95
|
+
get: function () { return chunkASK2OQM5_cjs.withFileLock; }
|
|
95
96
|
});
|
|
96
97
|
Object.defineProperty(exports, "withCwdMutex", {
|
|
97
98
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/persistence/exclusive-create.ts","../../../src/internal/persistence/sqlite-cas.ts"],"names":["open"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/persistence/exclusive-create.ts","../../../src/internal/persistence/sqlite-cas.ts"],"names":["open"],"mappings":";;;;;;;;;;;;;;;AAwDA,eAAsB,eAAA,CACpB,IAAA,EACA,IAAA,EACA,OAAA,EACkB;AAClB,EAAA,MAAM,IAAA,GAAO,SAAS,IAAA,IAAQ,GAAA;AAC9B,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAMA,aAAA,CAAK,IAAA,EAAM,MAAM,IAAI,CAAA;AAC1C,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,CAAO,UAAU,IAAI,CAAA;AAC3B,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,SAAE;AACA,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB;AAAA,EACF,SAAS,GAAA,EAAK;AACZ,IAAA,IAAK,GAAA,CAA8B,SAAS,QAAA,EAAU;AACpD,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACF;;;ACdO,SAAS,SAAA,CACd,EAAA,EACA,GAAA,EACA,MAAA,EACA,kBAA0B,CAAA,EACjB;AACT,EAAA,MAAM,IAAA,GAAO,EAAA,CAAG,OAAA,CAAQ,GAAG,CAAA;AAC3B,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,GAAI,MAAoB,CAAA;AAChD,EAAA,OAAO,OAAO,OAAA,KAAY,eAAA;AAC5B","file":"index.cjs","sourcesContent":["/**\n * O_EXCL exclusive file creation (ADR D82).\n *\n * `createExclusive(path, data, { mode })` creates a file in a single\n * syscall (`open(path, \"wx\", mode)`). Returns `true` if created, `false`\n * if it already existed (EEXIST swallowed — caller decides). All other\n * errors propagate.\n *\n * Default mode is 0o600 (owner-only) — EC-2 fix from edge-case review:\n * token files, lockfiles, and PID files MUST NOT default to world-\n * readable 0o644 under typical umask 022. Callers writing non-sensitive\n * files can pass `mode: 0o644` explicitly.\n *\n * NFS not honoring O_EXCL is documented (D61 — same stance as\n * `withFileLock`); the SDK target is ext4/APFS/NTFS.\n *\n * @internal\n */\n\nimport { open } from \"node:fs/promises\";\n\nexport interface CreateExclusiveOptions {\n /** Unix mode for the new file (default 0o600 — owner-only). */\n mode?: number;\n}\n\n/**\n * Create `path` holding `data`, but only if it does not exist yet. Returns `true` when this call\n * created it, `false` when it was already there.\n *\n * The check and the create are one `open(path, \"wx\")` syscall, so of N processes racing to create\n * the same path exactly one gets `true` — no window between testing and writing. The content is\n * written after the create, so the `false` branch tells you the file exists, not that another\n * writer has finished filling it.\n *\n * Only `EEXIST` becomes `false`. Every other error propagates: a missing parent directory is\n * `ENOENT`, an unwritable one `EACCES`. This never creates directories.\n *\n * The file is created with mode 0600 unless `options.mode` says otherwise, and the mode is\n * subject to the process umask. That default is deliberate — the callers are token files,\n * lockfiles and PID files, and 0644 under a typical umask would make them world-readable.\n *\n * **Choosing between this and the locks.** `createExclusive` claims a NAME once and is the right\n * tool for first-writer-wins: seeding a config, electing a single owner, writing a credential\n * exactly once. It cannot guard repeated updates, because a file that already exists always loses.\n * For read-modify-write on a path several writers touch, take a lock instead —\n * {@link withFileLock} across processes, `withCwdMutex` when the writers are all in this one. For\n * an in-place update guarded by a version column in SQLite, `casUpdate` is the equivalent\n * primitive.\n *\n * Atomicity is the filesystem's `O_EXCL`, which NFS does not reliably honor; the SDK targets\n * ext4, APFS and NTFS.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport async function createExclusive(\n path: string,\n data: string | Uint8Array,\n options?: CreateExclusiveOptions,\n): Promise<boolean> {\n const mode = options?.mode ?? 0o600;\n try {\n const handle = await open(path, \"wx\", mode);\n try {\n await handle.writeFile(data);\n return true;\n } finally {\n await handle.close();\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EEXIST\") {\n return false;\n }\n throw err;\n }\n}\n","/**\n * SQLite optimistic compare-and-swap (ADR D83).\n *\n * `casUpdate(db, sql, params, expectedChanges)` executes a prepared\n * UPDATE and returns true if `result.changes === expectedChanges`.\n * Caller provides the full SQL (including `WHERE version = ?` predicate);\n * helper does NOT generate SQL — DRY at the level of \"wrap the\n * convention\", not \"build queries\".\n *\n * Use case canonical (Hermes `kanban_db.py:1922-1934`):\n *\n * const won = casUpdate(\n * db,\n * \"UPDATE registry SET status = ?, version = version + 1 WHERE id = ? AND version = ?\",\n * [\"running\", \"agent-foo\", 3],\n * );\n * if (!won) { ... re-read and retry ... }\n *\n * Helper does NOT retry — caller responsible for backoff (avoids hidden\n * loops). Helper does NOT cache prepared statements — `better-sqlite3`\n * caches internally; SDK use is one-shot per mutation, not hot loops.\n *\n * NOTE — no internal-visibility tag in this block. `tsconfig.base.json` sets `stripInternal: true`,\n * and TypeScript scans EVERY leading comment range of the declaration that follows, including the\n * import right below this one. The tag that used to sit here deleted that import from the emitted\n * `.d.ts`, leaving the types it binds unresolvable for any consumer running type-aware lint\n * (usetheodev/theokit-sdk#283 records the same trap on a declaration).\n */\n\nimport type Database from \"better-sqlite3\";\n\ntype DatabaseInstance = InstanceType<typeof Database>;\n\n/**\n * Run an UPDATE and report whether it changed exactly the number of rows you expected — the\n * optimistic-concurrency equivalent of taking a lock.\n *\n * `sql` is yours, in full, including the guard that makes it a compare-and-swap: the\n * `WHERE ... AND version = ?` predicate and the `SET version = version + 1` that closes it. This\n * function generates nothing. It prepares the statement, runs it with `params`, and compares\n * `changes` against `expectedChanges` (default 1).\n *\n * `false` means the guard did not match — someone else moved the row first, or the id does not\n * exist. Those two are indistinguishable here; if you need to tell them apart, re-read the row.\n * A `false` return means NOTHING was written, so the caller owns the re-read-and-retry, with\n * whatever backoff it wants. There is no retry loop hidden in here, by design.\n *\n * SQL errors propagate — bad syntax, a closed database, a constraint violation, a busy writer.\n * Only the row-count mismatch is reported as `false`.\n *\n * Runs as a single implicit transaction, so no explicit BEGIN is needed for one statement. Wrap\n * the call yourself when the swap has to commit together with other writes.\n *\n * **Choosing between this and the locks.** `casUpdate` never blocks and never waits: the loser\n * finds out immediately and decides what to do. Prefer it when the contended state is already a\n * row with a version column. When the contended state is a FILE, there is no version column to\n * swap on — use `withFileLock` across processes, or `withCwdMutex` within one. When the goal is\n * to create something exactly once rather than update it, `createExclusive` is the primitive.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function casUpdate(\n db: DatabaseInstance,\n sql: string,\n params: ReadonlyArray<unknown>,\n expectedChanges: number = 1,\n): boolean {\n const stmt = db.prepare(sql);\n const result = stmt.run(...(params as unknown[]));\n return result.changes === expectedChanges;\n}\n"]}
|
|
@@ -2,7 +2,8 @@ export { PersistenceSchema } from '../../chunk-HY66GLM6.js';
|
|
|
2
2
|
export { migrateSchema, readVersionedJson, writeVersionedJson } from '../../chunk-SVQIW5RJ.js';
|
|
3
3
|
export { containsCjk, sanitizeFts5Query } from '../../chunk-WE22OXQA.js';
|
|
4
4
|
export { applyWalWithFallback, isCorruptionError, openSqliteResilient } from '../../chunk-XZHJYSPB.js';
|
|
5
|
-
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds
|
|
5
|
+
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds } from '../../chunk-7KIN3L2S.js';
|
|
6
|
+
export { withFileLock } from '../../chunk-RGQICWFU.js';
|
|
6
7
|
export { withCwdMutex } from '../../chunk-Q5EWJPRY.js';
|
|
7
8
|
export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from '../../chunk-3JHIFQ4I.js';
|
|
8
9
|
export { displayTheokitHome, getProfilesRoot, getTheokitHome } from '../../chunk-X7EUUHXU.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internal/persistence/exclusive-create.ts","../../../src/internal/persistence/sqlite-cas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/internal/persistence/exclusive-create.ts","../../../src/internal/persistence/sqlite-cas.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAwDA,eAAsB,eAAA,CACpB,IAAA,EACA,IAAA,EACA,OAAA,EACkB;AAClB,EAAA,MAAM,IAAA,GAAO,SAAS,IAAA,IAAQ,GAAA;AAC9B,EAAA,IAAI;AACF,IAAA,MAAM,MAAA,GAAS,MAAM,IAAA,CAAK,IAAA,EAAM,MAAM,IAAI,CAAA;AAC1C,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,CAAO,UAAU,IAAI,CAAA;AAC3B,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,SAAE;AACA,MAAA,MAAM,OAAO,KAAA,EAAM;AAAA,IACrB;AAAA,EACF,SAAS,GAAA,EAAK;AACZ,IAAA,IAAK,GAAA,CAA8B,SAAS,QAAA,EAAU;AACpD,MAAA,OAAO,KAAA;AAAA,IACT;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACF;;;ACdO,SAAS,SAAA,CACd,EAAA,EACA,GAAA,EACA,MAAA,EACA,kBAA0B,CAAA,EACjB;AACT,EAAA,MAAM,IAAA,GAAO,EAAA,CAAG,OAAA,CAAQ,GAAG,CAAA;AAC3B,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,GAAI,MAAoB,CAAA;AAChD,EAAA,OAAO,OAAO,OAAA,KAAY,eAAA;AAC5B","file":"index.js","sourcesContent":["/**\n * O_EXCL exclusive file creation (ADR D82).\n *\n * `createExclusive(path, data, { mode })` creates a file in a single\n * syscall (`open(path, \"wx\", mode)`). Returns `true` if created, `false`\n * if it already existed (EEXIST swallowed — caller decides). All other\n * errors propagate.\n *\n * Default mode is 0o600 (owner-only) — EC-2 fix from edge-case review:\n * token files, lockfiles, and PID files MUST NOT default to world-\n * readable 0o644 under typical umask 022. Callers writing non-sensitive\n * files can pass `mode: 0o644` explicitly.\n *\n * NFS not honoring O_EXCL is documented (D61 — same stance as\n * `withFileLock`); the SDK target is ext4/APFS/NTFS.\n *\n * @internal\n */\n\nimport { open } from \"node:fs/promises\";\n\nexport interface CreateExclusiveOptions {\n /** Unix mode for the new file (default 0o600 — owner-only). */\n mode?: number;\n}\n\n/**\n * Create `path` holding `data`, but only if it does not exist yet. Returns `true` when this call\n * created it, `false` when it was already there.\n *\n * The check and the create are one `open(path, \"wx\")` syscall, so of N processes racing to create\n * the same path exactly one gets `true` — no window between testing and writing. The content is\n * written after the create, so the `false` branch tells you the file exists, not that another\n * writer has finished filling it.\n *\n * Only `EEXIST` becomes `false`. Every other error propagates: a missing parent directory is\n * `ENOENT`, an unwritable one `EACCES`. This never creates directories.\n *\n * The file is created with mode 0600 unless `options.mode` says otherwise, and the mode is\n * subject to the process umask. That default is deliberate — the callers are token files,\n * lockfiles and PID files, and 0644 under a typical umask would make them world-readable.\n *\n * **Choosing between this and the locks.** `createExclusive` claims a NAME once and is the right\n * tool for first-writer-wins: seeding a config, electing a single owner, writing a credential\n * exactly once. It cannot guard repeated updates, because a file that already exists always loses.\n * For read-modify-write on a path several writers touch, take a lock instead —\n * {@link withFileLock} across processes, `withCwdMutex` when the writers are all in this one. For\n * an in-place update guarded by a version column in SQLite, `casUpdate` is the equivalent\n * primitive.\n *\n * Atomicity is the filesystem's `O_EXCL`, which NFS does not reliably honor; the SDK targets\n * ext4, APFS and NTFS.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport async function createExclusive(\n path: string,\n data: string | Uint8Array,\n options?: CreateExclusiveOptions,\n): Promise<boolean> {\n const mode = options?.mode ?? 0o600;\n try {\n const handle = await open(path, \"wx\", mode);\n try {\n await handle.writeFile(data);\n return true;\n } finally {\n await handle.close();\n }\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"EEXIST\") {\n return false;\n }\n throw err;\n }\n}\n","/**\n * SQLite optimistic compare-and-swap (ADR D83).\n *\n * `casUpdate(db, sql, params, expectedChanges)` executes a prepared\n * UPDATE and returns true if `result.changes === expectedChanges`.\n * Caller provides the full SQL (including `WHERE version = ?` predicate);\n * helper does NOT generate SQL — DRY at the level of \"wrap the\n * convention\", not \"build queries\".\n *\n * Use case canonical (Hermes `kanban_db.py:1922-1934`):\n *\n * const won = casUpdate(\n * db,\n * \"UPDATE registry SET status = ?, version = version + 1 WHERE id = ? AND version = ?\",\n * [\"running\", \"agent-foo\", 3],\n * );\n * if (!won) { ... re-read and retry ... }\n *\n * Helper does NOT retry — caller responsible for backoff (avoids hidden\n * loops). Helper does NOT cache prepared statements — `better-sqlite3`\n * caches internally; SDK use is one-shot per mutation, not hot loops.\n *\n * NOTE — no internal-visibility tag in this block. `tsconfig.base.json` sets `stripInternal: true`,\n * and TypeScript scans EVERY leading comment range of the declaration that follows, including the\n * import right below this one. The tag that used to sit here deleted that import from the emitted\n * `.d.ts`, leaving the types it binds unresolvable for any consumer running type-aware lint\n * (usetheodev/theokit-sdk#283 records the same trap on a declaration).\n */\n\nimport type Database from \"better-sqlite3\";\n\ntype DatabaseInstance = InstanceType<typeof Database>;\n\n/**\n * Run an UPDATE and report whether it changed exactly the number of rows you expected — the\n * optimistic-concurrency equivalent of taking a lock.\n *\n * `sql` is yours, in full, including the guard that makes it a compare-and-swap: the\n * `WHERE ... AND version = ?` predicate and the `SET version = version + 1` that closes it. This\n * function generates nothing. It prepares the statement, runs it with `params`, and compares\n * `changes` against `expectedChanges` (default 1).\n *\n * `false` means the guard did not match — someone else moved the row first, or the id does not\n * exist. Those two are indistinguishable here; if you need to tell them apart, re-read the row.\n * A `false` return means NOTHING was written, so the caller owns the re-read-and-retry, with\n * whatever backoff it wants. There is no retry loop hidden in here, by design.\n *\n * SQL errors propagate — bad syntax, a closed database, a constraint violation, a busy writer.\n * Only the row-count mismatch is reported as `false`.\n *\n * Runs as a single implicit transaction, so no explicit BEGIN is needed for one statement. Wrap\n * the call yourself when the swap has to commit together with other writes.\n *\n * **Choosing between this and the locks.** `casUpdate` never blocks and never waits: the loser\n * finds out immediately and decides what to do. Prefer it when the contended state is already a\n * row with a version column. When the contended state is a FILE, there is no version column to\n * swap on — use `withFileLock` across processes, or `withCwdMutex` within one. When the goal is\n * to create something exactly once rather than update it, `createExclusive` is the primitive.\n *\n * Semver-exempt: reachable via the `@theokit/sdk/internal/persistence` sub-path, which the package\n * declares in `exports` but does NOT cover with its semver contract.\n */\nexport function casUpdate(\n db: DatabaseInstance,\n sql: string,\n params: ReadonlyArray<unknown>,\n expectedChanges: number = 1,\n): boolean {\n const stmt = db.prepare(sql);\n const result = stmt.run(...(params as unknown[]));\n return result.changes === expectedChanges;\n}\n"]}
|