@theokit/sdk 5.9.2 → 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 +45 -0
- package/dist/{agent-enXXu447.d.ts → agent-CmKwSyyD.d.ts} +27 -0
- package/dist/{agent-WQ4LLTSY.cjs → agent-TLRURB7W.cjs} +9 -8
- package/dist/{agent-WQ4LLTSY.cjs.map → agent-TLRURB7W.cjs.map} +1 -1
- package/dist/{agent-Dh2YHSLj.d.cts → agent-XMkGzff_.d.cts} +27 -0
- package/dist/{agent-GZVZXKME.js → agent-XTLAVVYC.js} +8 -7
- package/dist/{agent-GZVZXKME.js.map → agent-XTLAVVYC.js.map} +1 -1
- package/dist/{chunk-M2CCHC66.js → chunk-523O5UYB.js} +3 -3
- package/dist/{chunk-M2CCHC66.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-JU76WCW7.cjs → chunk-CVEQ5366.cjs} +37 -24
- package/dist/chunk-CVEQ5366.cjs.map +1 -0
- package/dist/{chunk-ZDF2IJKC.js → chunk-DPY2M74T.js} +3 -3
- package/dist/{chunk-ZDF2IJKC.js.map → chunk-DPY2M74T.js.map} +1 -1
- package/dist/{chunk-X7Z2FEI7.cjs → chunk-FYEHYQ7T.cjs} +8 -8
- package/dist/{chunk-X7Z2FEI7.cjs.map → chunk-FYEHYQ7T.cjs.map} +1 -1
- package/dist/{chunk-OZLQ6ZFM.js → chunk-IZDDSLL2.js} +4 -3
- package/dist/chunk-IZDDSLL2.js.map +1 -0
- package/dist/{chunk-DLUCTZ56.cjs → chunk-L3C6CCBG.cjs} +15 -15
- package/dist/{chunk-DLUCTZ56.cjs.map → chunk-L3C6CCBG.cjs.map} +1 -1
- package/dist/{chunk-RX3CFWQ2.cjs → chunk-NQVWSSX2.cjs} +6 -5
- package/dist/chunk-NQVWSSX2.cjs.map +1 -0
- package/dist/{chunk-KXKT3HSD.cjs → chunk-PCLRIQPX.cjs} +4 -4
- package/dist/{chunk-KXKT3HSD.cjs.map → chunk-PCLRIQPX.cjs.map} +1 -1
- 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-PEIV7LOU.js → chunk-RTE2DD4S.js} +20 -7
- package/dist/chunk-RTE2DD4S.js.map +1 -0
- package/dist/{chunk-N7KYUNFO.js → chunk-W2ZVTEOD.js} +3 -3
- package/dist/{chunk-N7KYUNFO.js.map → chunk-W2ZVTEOD.js.map} +1 -1
- package/dist/{chunk-47Z6LP3I.js → chunk-X3LOJJMO.js} +88 -28
- package/dist/chunk-X3LOJJMO.js.map +1 -0
- package/dist/{chunk-VZ2JZ2EH.cjs → chunk-ZD66GFH5.cjs} +89 -27
- package/dist/chunk-ZD66GFH5.cjs.map +1 -0
- 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 +8 -7
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +7 -6
- package/dist/eval.cjs +11 -10
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +7 -6
- package/dist/eval.js.map +1 -1
- package/dist/fs-session-store-3VI4CPTX.js +11 -0
- package/dist/{fs-session-store-LCZBM3LT.js.map → fs-session-store-3VI4CPTX.js.map} +1 -1
- package/dist/fs-session-store-IQ6PEHYF.cjs +20 -0
- package/dist/{fs-session-store-SVEMRE4K.cjs.map → fs-session-store-IQ6PEHYF.cjs.map} +1 -1
- package/dist/{index-manager-6B2UF5S3.js → index-manager-JVYIVTZG.js} +5 -4
- package/dist/{index-manager-6B2UF5S3.js.map → index-manager-JVYIVTZG.js.map} +1 -1
- package/dist/{index-manager-M3FHJCHQ.cjs → index-manager-YGXRFJMZ.cjs} +6 -5
- package/dist/{index-manager-M3FHJCHQ.cjs.map → index-manager-YGXRFJMZ.cjs.map} +1 -1
- package/dist/index.cjs +44 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +22 -15
- package/dist/index.js.map +1 -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 +40 -31
- 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 +3 -2
- 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/runtime/registry/agent-registry-store.d.ts +2 -0
- package/dist/persistence.cjs +7 -6
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +2 -1
- package/dist/persistence.js.map +1 -1
- package/dist/subagents-loader.d.cts +1 -1
- package/dist/subagents-loader.d.ts +1 -1
- package/dist/types/agent.d.ts +27 -0
- package/docs/error-codes.md +27 -25
- package/docs/harness-capability-map.md +6 -1
- package/package.json +1 -1
- package/dist/chunk-47Z6LP3I.js.map +0 -1
- package/dist/chunk-BKMDRBJ7.js +0 -180
- package/dist/chunk-BKMDRBJ7.js.map +0 -1
- package/dist/chunk-JU76WCW7.cjs.map +0 -1
- package/dist/chunk-OF2CLCTH.cjs +0 -186
- package/dist/chunk-OF2CLCTH.cjs.map +0 -1
- package/dist/chunk-OZLQ6ZFM.js.map +0 -1
- package/dist/chunk-PEIV7LOU.js.map +0 -1
- package/dist/chunk-RX3CFWQ2.cjs.map +0 -1
- package/dist/chunk-VZ2JZ2EH.cjs.map +0 -1
- package/dist/fs-session-store-LCZBM3LT.js +0 -10
- package/dist/fs-session-store-SVEMRE4K.cjs +0 -19
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkZF2LDKQQ_cjs = require('./chunk-ZF2LDKQQ.cjs');
|
|
4
|
+
var chunk6LHQPOMI_cjs = require('./chunk-6LHQPOMI.cjs');
|
|
5
|
+
|
|
6
|
+
// src/internal/persistence/file-lock.ts
|
|
7
|
+
var cached;
|
|
8
|
+
var warnedMissing = false;
|
|
9
|
+
var warnedStructural = false;
|
|
10
|
+
var loadFailure;
|
|
11
|
+
function isModuleAbsent(err) {
|
|
12
|
+
const code = err?.code;
|
|
13
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND";
|
|
14
|
+
}
|
|
15
|
+
function describeLockLoadFailure(err) {
|
|
16
|
+
const consequence = "cross-process file lock unavailable \u2014 concurrent processes over the same file are NOT serialized.";
|
|
17
|
+
if (isModuleAbsent(err)) {
|
|
18
|
+
return `[theokit-sdk] proper-lockfile not installed; ${consequence} Install with: pnpm add proper-lockfile
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
const code = err?.code;
|
|
22
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
23
|
+
return `[theokit-sdk] proper-lockfile could not be loaded${code !== void 0 ? ` (${String(code)})` : ""}: ${detail}. ${consequence} The package resolves for the SDK but failed to load \u2014 check bundling and module-format interop before re-checking the install.
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
async function getProperLockfile() {
|
|
27
|
+
if (cached !== void 0) return cached;
|
|
28
|
+
try {
|
|
29
|
+
const mod = await import('proper-lockfile');
|
|
30
|
+
if (!validateLockModule(mod)) {
|
|
31
|
+
if (!warnedStructural) {
|
|
32
|
+
warnedStructural = true;
|
|
33
|
+
chunk6LHQPOMI_cjs.diag(
|
|
34
|
+
"[theokit-sdk] proper-lockfile: imported module does NOT expose the expected `lock`/`unlock` API surface. This may indicate a supply-chain compromise or an incompatible major version. Falling back to in-process mutex (no cross-process safety). Reinstall with: pnpm add proper-lockfile@^11\n"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
cached = null;
|
|
38
|
+
return cached;
|
|
39
|
+
}
|
|
40
|
+
cached = mod;
|
|
41
|
+
} catch (err) {
|
|
42
|
+
loadFailure = err;
|
|
43
|
+
cached = null;
|
|
44
|
+
}
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
function validateLockModule(mod) {
|
|
48
|
+
if (mod === null || mod === void 0 || typeof mod !== "object") return false;
|
|
49
|
+
const m = mod;
|
|
50
|
+
return typeof m.lock === "function" && typeof m.unlock === "function";
|
|
51
|
+
}
|
|
52
|
+
async function withFileLock(path, fn, options) {
|
|
53
|
+
const lib = await getProperLockfile();
|
|
54
|
+
if (lib === null) {
|
|
55
|
+
if (!warnedMissing && !warnedStructural) {
|
|
56
|
+
warnedMissing = true;
|
|
57
|
+
chunk6LHQPOMI_cjs.diag(describeLockLoadFailure(loadFailure));
|
|
58
|
+
}
|
|
59
|
+
return chunkZF2LDKQQ_cjs.withCwdMutex(`file-lock:${path}`, fn);
|
|
60
|
+
}
|
|
61
|
+
return chunkZF2LDKQQ_cjs.withCwdMutex(`file-lock:${path}`, async () => {
|
|
62
|
+
const release = await lib.lock(path, {
|
|
63
|
+
// EC-1: companion lockfile, target path may not exist yet.
|
|
64
|
+
lockfilePath: `${path}.lock`,
|
|
65
|
+
realpath: false,
|
|
66
|
+
stale: options?.stale ?? 3e4,
|
|
67
|
+
retries: {
|
|
68
|
+
retries: options?.retries ?? 5,
|
|
69
|
+
factor: options?.retryFactor ?? 1.5,
|
|
70
|
+
minTimeout: 100,
|
|
71
|
+
maxTimeout: 5e3
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
try {
|
|
75
|
+
return await fn();
|
|
76
|
+
} finally {
|
|
77
|
+
await release();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.withFileLock = withFileLock;
|
|
83
|
+
//# sourceMappingURL=chunk-ASK2OQM5.cjs.map
|
|
84
|
+
//# sourceMappingURL=chunk-ASK2OQM5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/persistence/file-lock.ts"],"names":["diag","withCwdMutex"],"mappings":"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","file":"chunk-ASK2OQM5.cjs","sourcesContent":["/**\n * Cross-process file lock helper (ADR D61).\n *\n * Uses `proper-lockfile` (optional peer dep) for cross-process locks. When\n * the peer dep is absent, falls back to `withCwdMutex` (in-process only)\n * with a one-shot stderr warning.\n *\n * EC-1 fix: uses a companion `<path>.lock` file with `realpath: false` so\n * `withFileLock` works even when the target `path` does not exist yet.\n * Without this, fresh installs that lock-then-create would crash with ENOENT.\n *\n * @internal\n */\n\nimport { diag } from \"../diagnostics.js\";\nimport { withCwdMutex } from \"./cwd-mutex.js\";\n\ninterface ProperLockfileModule {\n lock: (file: string, options: ProperLockfileOptions) => Promise<() => Promise<void>>;\n}\n\ninterface ProperLockfileOptions {\n lockfilePath?: string;\n realpath?: boolean;\n stale?: number;\n retries?: {\n retries: number;\n factor?: number;\n minTimeout?: number;\n maxTimeout?: number;\n };\n}\n\nlet cached: ProperLockfileModule | null | undefined;\nlet warnedMissing = false;\nlet warnedStructural = false;\n/** Why the import failed, kept so the warning can report the observation instead of a guess (#174). */\nlet loadFailure: unknown;\n\n/** Node reports a missing module as `ERR_MODULE_NOT_FOUND` (ESM loader) or `MODULE_NOT_FOUND` (CJS). */\nfunction isModuleAbsent(err: unknown): boolean {\n const code = (err as { code?: unknown } | null | undefined)?.code;\n return code === \"ERR_MODULE_NOT_FOUND\" || code === \"MODULE_NOT_FOUND\";\n}\n\n/**\n * #174 — build the fallback warning from what actually happened.\n *\n * This used to always read \"proper-lockfile not installed\", because the import was wrapped in a\n * bare `catch` that discarded the error (Unbreakable Rule 8: a swallowed error is the dangerous\n * kind). A consumer whose package WAS installed, declared and resolvable spent a debugging session\n * re-verifying the install, because the message named a cause the code had never checked.\n *\n * Absence is now the only case that claims absence. Every other failure — a broken install, an\n * interop problem, a bundler that rewrote the specifier — reports its own code and message, which\n * is what points at the real cause.\n *\n * @internal\n */\nfunction describeLockLoadFailure(err: unknown): string {\n const consequence =\n \"cross-process file lock unavailable — concurrent processes over the same file are NOT serialized.\";\n if (isModuleAbsent(err)) {\n return `[theokit-sdk] proper-lockfile not installed; ${consequence} Install with: pnpm add proper-lockfile\\n`;\n }\n const code = (err as { code?: unknown } | null | undefined)?.code;\n const detail = err instanceof Error ? err.message : String(err);\n return (\n `[theokit-sdk] proper-lockfile could not be loaded${code !== undefined ? ` (${String(code)})` : \"\"}: ` +\n `${detail}. ${consequence} The package resolves for the SDK but failed to load — check bundling ` +\n \"and module-format interop before re-checking the install.\\n\"\n );\n}\n\n/** Test seam for the message builder — NOT in the public barrel. @internal */\nexport function __TESTING__describeLockLoadFailure(err: unknown): string {\n return describeLockLoadFailure(err);\n}\n\nasync function getProperLockfile(): Promise<ProperLockfileModule | null> {\n if (cached !== undefined) return cached;\n try {\n const mod = await import(\"proper-lockfile\");\n // T5.9 — supply-chain hardening: validate the imported module\n // exposes the API surface we depend on BEFORE caching it. A\n // tampered or incompatible version that lacks `lock`/`unlock`\n // functions gets treated as \"not installed\" with an advisory\n // warning — never silently used.\n if (!validateLockModule(mod)) {\n if (!warnedStructural) {\n warnedStructural = true;\n diag(\n \"[theokit-sdk] proper-lockfile: imported module does NOT expose \" +\n \"the expected `lock`/`unlock` API surface. This may indicate a \" +\n \"supply-chain compromise or an incompatible major version. \" +\n \"Falling back to in-process mutex (no cross-process safety). \" +\n \"Reinstall with: pnpm add proper-lockfile@^11\\n\",\n );\n }\n cached = null;\n return cached;\n }\n cached = mod as ProperLockfileModule;\n } catch (err) {\n // #174 — keep WHY. Discarding it here is what made the fallback warning assert a cause it had\n // never observed, and sent a consumer to re-check an install that was already correct.\n loadFailure = err;\n cached = null;\n }\n return cached;\n}\n\n/**\n * T5.9 — Structural validation of the dynamically-imported\n * `proper-lockfile` module. Verifies the API surface we depend on\n * (`lock` and `unlock` as functions) is present. Pure function —\n * never throws, never mutates, never performs I/O.\n *\n * Exported via `__TESTING__validateLockModule` seam so unit tests\n * can drive the check without spinning up the dynamic import.\n *\n * @internal\n */\nfunction validateLockModule(mod: unknown): boolean {\n if (mod === null || mod === undefined || typeof mod !== \"object\") return false;\n const m = mod as Record<string, unknown>;\n return typeof m.lock === \"function\" && typeof m.unlock === \"function\";\n}\n\n/**\n * T5.9 — Test seam: expose the structural validator for unit tests.\n * NOT included in the public barrel.\n *\n * @internal\n */\nexport function __TESTING__validateLockModule(mod: unknown): boolean {\n return validateLockModule(mod);\n}\n\n/**\n * T5.9 — Test seam: reset the module cache + warning flags between\n * tests so each test starts fresh. NOT included in the public barrel.\n *\n * @internal\n */\nexport function __TESTING__resetFileLockCache(): void {\n cached = undefined;\n warnedMissing = false;\n warnedStructural = false;\n loadFailure = undefined;\n}\n\n/**\n * Retry and staleness tuning for `withFileLock`.\n *\n * Every field is optional and the defaults are applied per call, so `undefined` means the default\n * rather than \"no limit\". They are handed to `proper-lockfile` and have NO effect on the fallback\n * path: when that package is absent, `withFileLock` degrades to the in-process mutex, which\n * queues indefinitely and never goes stale.\n *\n * `stale` (default 30000 ms) is how old a lock file must be before it is treated as abandoned by a\n * dead process and broken. Setting it below the longest a legitimate holder can run is what turns\n * a slow operation into two concurrent ones.\n *\n * `retries` (default 5) is the number of acquisition attempts AFTER the first, and `retryFactor`\n * (default 1.5) the backoff multiplier between them. The per-attempt wait is clamped to\n * 100–5000 ms, which the caller cannot change. Exhausting the retries rejects — it does not fall\n * through to running `fn` unlocked.\n *\n * @public — re-exported from the semver-protected `@theokit/sdk/persistence` barrel, and (for\n * back-compat) from the semver-exempt `@theokit/sdk/internal/persistence` alias.\n */\nexport interface FileLockOptions {\n /** Stale lock timeout in ms. Default 30_000 (30s). */\n stale?: number;\n /** Max retries on busy lock. Default 5. */\n retries?: number;\n /** Backoff factor between retries. Default 1.5. */\n retryFactor?: number;\n}\n\n/**\n * Run `fn` while holding an OS-level cross-process lock on `path`.\n *\n * If `proper-lockfile` is installed, uses it with a companion `<path>.lock`\n * file (`realpath: false`, so target file does NOT need to exist yet).\n * Otherwise falls back to in-process `withCwdMutex` and prints a one-shot\n * stderr warning telling the user to install `proper-lockfile` for\n * cross-process safety.\n *\n * The lock is released even when `fn` throws.\n *\n */\nexport async function withFileLock<T>(\n path: string,\n fn: () => Promise<T>,\n options?: FileLockOptions,\n): Promise<T> {\n const lib = await getProperLockfile();\n\n if (lib === null) {\n // #174 — stay silent when the structural check already explained itself. Emitting \"not\n // installed\" on top of \"does not expose lock/unlock\" would be two contradictory diagnoses of\n // one failure, and the reader has no way to tell which is true.\n if (!warnedMissing && !warnedStructural) {\n warnedMissing = true;\n diag(describeLockLoadFailure(loadFailure));\n }\n return withCwdMutex(`file-lock:${path}`, fn);\n }\n\n // proper-lockfile errors immediately on same-process concurrent acquire\n // (\"Lock file is already being held\"). Wrap with cwd-mutex first so\n // in-process callers queue and only ONE thread at a time enters the\n // cross-process acquire path. Combined: full in-process + cross-process\n // serialization.\n return withCwdMutex(`file-lock:${path}`, async () => {\n const release = await lib.lock(path, {\n // EC-1: companion lockfile, target path may not exist yet.\n lockfilePath: `${path}.lock`,\n realpath: false,\n stale: options?.stale ?? 30_000,\n retries: {\n retries: options?.retries ?? 5,\n factor: options?.retryFactor ?? 1.5,\n minTimeout: 100,\n maxTimeout: 5_000,\n },\n });\n\n try {\n return await fn();\n } finally {\n await release();\n }\n });\n}\n\n/**\n * Test helper — resets the cached proper-lockfile module + warning flag.\n * Allows tests to simulate \"module absent\" by clearing cache then\n * monkey-patching the dynamic import resolution.\n *\n * @internal\n */\nexport function _resetFileLockCacheForTesting(): void {\n cached = undefined;\n warnedMissing = false;\n}\n"]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var chunkJ6GXS5A2_cjs = require('./chunk-J6GXS5A2.cjs');
|
|
4
4
|
var chunkFR6COQXZ_cjs = require('./chunk-FR6COQXZ.cjs');
|
|
5
|
-
var
|
|
5
|
+
var chunkL3C6CCBG_cjs = require('./chunk-L3C6CCBG.cjs');
|
|
6
6
|
var chunkKIKKTW5O_cjs = require('./chunk-KIKKTW5O.cjs');
|
|
7
7
|
var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
|
|
8
8
|
var chunkYEHQ3SIC_cjs = require('./chunk-YEHQ3SIC.cjs');
|
|
9
9
|
var chunkTMKTSYDS_cjs = require('./chunk-TMKTSYDS.cjs');
|
|
10
|
-
var
|
|
11
|
-
var
|
|
10
|
+
var chunkZD66GFH5_cjs = require('./chunk-ZD66GFH5.cjs');
|
|
11
|
+
var chunkNQVWSSX2_cjs = require('./chunk-NQVWSSX2.cjs');
|
|
12
12
|
var chunkQY3CIMUV_cjs = require('./chunk-QY3CIMUV.cjs');
|
|
13
13
|
var chunk2ZPEDVLM_cjs = require('./chunk-2ZPEDVLM.cjs');
|
|
14
14
|
var chunkXKZFIP7Z_cjs = require('./chunk-XKZFIP7Z.cjs');
|
|
@@ -24,7 +24,7 @@ var chunkGM54F4FE_cjs = require('./chunk-GM54F4FE.cjs');
|
|
|
24
24
|
var chunkSA6K24NB_cjs = require('./chunk-SA6K24NB.cjs');
|
|
25
25
|
var chunkIIYJMXYW_cjs = require('./chunk-IIYJMXYW.cjs');
|
|
26
26
|
var chunkZWACQM5U_cjs = require('./chunk-ZWACQM5U.cjs');
|
|
27
|
-
var
|
|
27
|
+
var chunkASK2OQM5_cjs = require('./chunk-ASK2OQM5.cjs');
|
|
28
28
|
var chunkZF2LDKQQ_cjs = require('./chunk-ZF2LDKQQ.cjs');
|
|
29
29
|
var chunkJLRLCBJ4_cjs = require('./chunk-JLRLCBJ4.cjs');
|
|
30
30
|
var chunkC7GKRGKN_cjs = require('./chunk-C7GKRGKN.cjs');
|
|
@@ -338,6 +338,8 @@ function serializeMemory(memory) {
|
|
|
338
338
|
if (memory.scope !== void 0) out.scope = memory.scope;
|
|
339
339
|
if (memory.activeRecall !== void 0) out.activeRecall = { ...memory.activeRecall };
|
|
340
340
|
if (memory.index !== void 0) out.index = serializeMemoryIndex(memory.index);
|
|
341
|
+
if (memory.maxFacts !== void 0) out.maxFacts = memory.maxFacts;
|
|
342
|
+
if (memory.directory !== void 0) out.directory = memory.directory;
|
|
341
343
|
return out;
|
|
342
344
|
}
|
|
343
345
|
function serializeMemoryIndex(index) {
|
|
@@ -821,7 +823,7 @@ async function readLegacyFacts(jsonPath) {
|
|
|
821
823
|
}
|
|
822
824
|
async function writeMigratedFacts(cwd, jsonPath, facts) {
|
|
823
825
|
try {
|
|
824
|
-
for (const fact of facts) await
|
|
826
|
+
for (const fact of facts) await chunkZD66GFH5_cjs.appendFactToMarkdown(cwd, fact);
|
|
825
827
|
await promises.unlink(jsonPath).catch(() => void 0);
|
|
826
828
|
chunk6LHQPOMI_cjs.diag(`[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
|
|
827
829
|
`);
|
|
@@ -838,11 +840,11 @@ async function migrateLegacyJson(cwd, config) {
|
|
|
838
840
|
const key = `${cwd}::${config.namespace ?? "default"}::${config.scope ?? "agent"}::${config.userId ?? "default"}`;
|
|
839
841
|
if (migrationRun.has(key)) return { migrated: false, factCount: 0, reason: "already-migrated" };
|
|
840
842
|
migrationRun.add(key);
|
|
841
|
-
const jsonPath =
|
|
843
|
+
const jsonPath = chunkZD66GFH5_cjs.legacyMemoryJsonPath(cwd, config);
|
|
842
844
|
if (!await fileExists(jsonPath)) {
|
|
843
845
|
return { migrated: false, factCount: 0, reason: "no-legacy-json" };
|
|
844
846
|
}
|
|
845
|
-
if (await fileExists(
|
|
847
|
+
if (await fileExists(chunkZD66GFH5_cjs.memoryMdPath(chunkZD66GFH5_cjs.resolveMemoryRoot(cwd, config)))) {
|
|
846
848
|
chunk6LHQPOMI_cjs.diag(
|
|
847
849
|
`[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
|
|
848
850
|
`
|
|
@@ -871,28 +873,29 @@ function unstoredRememberWarning(message) {
|
|
|
871
873
|
if (isMemoryWritePrompt(message) && extractMemoryFact(message).length > 0) return void 0;
|
|
872
874
|
const trimmed = message.trim();
|
|
873
875
|
const quoted = trimmed.length > QUOTED_MESSAGE_MAX ? `${trimmed.slice(0, QUOTED_MESSAGE_MAX)}\u2026` : trimmed;
|
|
874
|
-
return `[theokit-sdk] NOTHING WAS STORED \u2014 this message does not match the memory capture pattern: ${JSON.stringify(quoted)}. Supported: "Remember: <fact>" or "Remember (${
|
|
876
|
+
return `[theokit-sdk] NOTHING WAS STORED \u2014 this message does not match the memory capture pattern: ${JSON.stringify(quoted)}. Supported: "Remember: <fact>" or "Remember (${chunkZD66GFH5_cjs.MEMORY_KINDS.join("|")}): <fact>". It still reaches the session transcript, so a follow-up may answer from it \u2014 that is search over transcripts, not a durable memory.`;
|
|
875
877
|
}
|
|
876
878
|
function extractMemoryKind(message) {
|
|
877
879
|
const match = REMEMBER_PATTERN.exec(message);
|
|
878
880
|
const declared = match?.[1];
|
|
879
881
|
if (declared === void 0) return void 0;
|
|
880
882
|
const lowered = declared.toLowerCase();
|
|
881
|
-
return
|
|
883
|
+
return chunkZD66GFH5_cjs.MEMORY_KINDS.includes(lowered) ? lowered : void 0;
|
|
882
884
|
}
|
|
883
885
|
async function readMemoryFacts(cwd, config) {
|
|
884
886
|
if (!config.enabled) return [];
|
|
885
887
|
await migrateLegacyJson(cwd, config);
|
|
886
|
-
return
|
|
888
|
+
return chunkZD66GFH5_cjs.readFacts(cwd, config);
|
|
887
889
|
}
|
|
888
890
|
async function appendMemoryFact(cwd, config, fact) {
|
|
889
891
|
if (!config.enabled) return;
|
|
892
|
+
chunkZD66GFH5_cjs.resolveMaxFacts(config.maxFacts);
|
|
890
893
|
await migrateLegacyJson(cwd, config);
|
|
891
894
|
const sanitized = {
|
|
892
895
|
text: chunk6LHQPOMI_cjs.redactSecrets(fact.text),
|
|
893
896
|
...fact.kind === void 0 ? {} : { kind: fact.kind }
|
|
894
897
|
};
|
|
895
|
-
await
|
|
898
|
+
await chunkZD66GFH5_cjs.appendFact(cwd, config, sanitized);
|
|
896
899
|
}
|
|
897
900
|
|
|
898
901
|
// src/internal/runtime/fixtures/fixture-scripts.ts
|
|
@@ -2199,7 +2202,7 @@ var PersonalityStore = class {
|
|
|
2199
2202
|
async #persist(agentId, slug) {
|
|
2200
2203
|
const filePath = this.#filePath();
|
|
2201
2204
|
await promises.mkdir(path.dirname(filePath), { recursive: true });
|
|
2202
|
-
await
|
|
2205
|
+
await chunkASK2OQM5_cjs.withFileLock(filePath, async () => {
|
|
2203
2206
|
const current = await readState(filePath);
|
|
2204
2207
|
const nextAgents = { ...current.agents };
|
|
2205
2208
|
if (slug === void 0) delete nextAgents[agentId];
|
|
@@ -2980,7 +2983,7 @@ async function runPostRunLifecycle(inputs) {
|
|
|
2980
2983
|
cwd: workspaceCwd,
|
|
2981
2984
|
// Resolved once, here, and handed to both writers. Recomputing it inside either one is how
|
|
2982
2985
|
// the summary ended up in a directory the indexer never scanned (#463).
|
|
2983
|
-
memoryRoot:
|
|
2986
|
+
memoryRoot: chunkZD66GFH5_cjs.resolveMemoryRoot(workspaceCwd, inputs.memory),
|
|
2984
2987
|
runId: result.id,
|
|
2985
2988
|
agentId,
|
|
2986
2989
|
userText,
|
|
@@ -2992,7 +2995,7 @@ async function runPostRunLifecycle(inputs) {
|
|
|
2992
2995
|
if (memoryProvider?.recordSessionSummary !== void 0) {
|
|
2993
2996
|
await memoryProvider.recordSessionSummary(summaryArgs);
|
|
2994
2997
|
} else {
|
|
2995
|
-
await
|
|
2998
|
+
await chunkZD66GFH5_cjs.writeSessionSummary(summaryArgs);
|
|
2996
2999
|
}
|
|
2997
3000
|
} catch (cause) {
|
|
2998
3001
|
const message = cause instanceof Error ? cause.message : String(cause);
|
|
@@ -3614,6 +3617,7 @@ function validateToolSchema(tool) {
|
|
|
3614
3617
|
}
|
|
3615
3618
|
function validateMemory(options) {
|
|
3616
3619
|
const memory = options.memory;
|
|
3620
|
+
chunkZD66GFH5_cjs.resolveMaxFacts(memory?.maxFacts);
|
|
3617
3621
|
if (memory?.storePath === void 0) return;
|
|
3618
3622
|
const storePath = memory.storePath;
|
|
3619
3623
|
if (storePath.includes("..") || storePath.startsWith("/") || /^[A-Z]:/i.test(storePath)) {
|
|
@@ -3639,7 +3643,7 @@ var HISTOGRAM_NAMES = {
|
|
|
3639
3643
|
};
|
|
3640
3644
|
function safeRequire(moduleName) {
|
|
3641
3645
|
try {
|
|
3642
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3646
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CVEQ5366.cjs', document.baseURI).href)));
|
|
3643
3647
|
return r(moduleName);
|
|
3644
3648
|
} catch {
|
|
3645
3649
|
return void 0;
|
|
@@ -3882,7 +3886,7 @@ var cachedOtel;
|
|
|
3882
3886
|
function loadOtel() {
|
|
3883
3887
|
if (cachedOtel === void 0) {
|
|
3884
3888
|
try {
|
|
3885
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3889
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-CVEQ5366.cjs', document.baseURI).href)));
|
|
3886
3890
|
const mod = r("@opentelemetry/api");
|
|
3887
3891
|
cachedOtel = mod;
|
|
3888
3892
|
} catch {
|
|
@@ -8385,7 +8389,7 @@ async function finalize(args, queryMode, result) {
|
|
|
8385
8389
|
};
|
|
8386
8390
|
args.cache?.set(args.userText, queryMode, result, tenantCtx);
|
|
8387
8391
|
if (args.persistTranscripts === true && args.cwd !== void 0) {
|
|
8388
|
-
await chunkTMKTSYDS_cjs.persistActiveMemoryTranscript(args.memoryRoot ??
|
|
8392
|
+
await chunkTMKTSYDS_cjs.persistActiveMemoryTranscript(args.memoryRoot ?? chunkZD66GFH5_cjs.resolveMemoryRoot(args.cwd), {
|
|
8389
8393
|
runId: args.runId ?? `run-${Date.now()}`,
|
|
8390
8394
|
startedAtMs: Date.now() - result.durationMs,
|
|
8391
8395
|
userText: args.userText,
|
|
@@ -8976,7 +8980,7 @@ var LocalAgentMemory = class {
|
|
|
8976
8980
|
const openOpts = { cwd: this.workspaceCwd, memoryRoot };
|
|
8977
8981
|
if (embedding !== void 0) openOpts.embedding = embedding;
|
|
8978
8982
|
if (cfg?.backend !== void 0) openOpts.backend = cfg.backend;
|
|
8979
|
-
this.index = await
|
|
8983
|
+
this.index = await chunkL3C6CCBG_cjs.IndexManager.open(openOpts);
|
|
8980
8984
|
await this.index.sync();
|
|
8981
8985
|
this.toolsCache = [
|
|
8982
8986
|
createMemorySearchTool({ index: this.index }),
|
|
@@ -9020,7 +9024,7 @@ var LocalAgentMemory = class {
|
|
|
9020
9024
|
* and the active-memory transcript writer. Three separate resolutions is how they drifted (#463).
|
|
9021
9025
|
*/
|
|
9022
9026
|
memoryRoot() {
|
|
9023
|
-
this.memoryRootCache ??=
|
|
9027
|
+
this.memoryRootCache ??= chunkZD66GFH5_cjs.resolveMemoryRoot(this.workspaceCwd, this.options.memory);
|
|
9024
9028
|
return this.memoryRootCache;
|
|
9025
9029
|
}
|
|
9026
9030
|
buildActiveMemoryOptions(cfg) {
|
|
@@ -9135,7 +9139,7 @@ function createLocalAgentMemoryProvider(opts) {
|
|
|
9135
9139
|
return { facts: [], systemPromptAdditions: summary };
|
|
9136
9140
|
},
|
|
9137
9141
|
async recordSessionSummary(args) {
|
|
9138
|
-
await
|
|
9142
|
+
await chunkZD66GFH5_cjs.writeSessionSummary(args);
|
|
9139
9143
|
},
|
|
9140
9144
|
async sync(handle) {
|
|
9141
9145
|
const state = handle[INTERNAL_LAM_KEY];
|
|
@@ -10133,7 +10137,7 @@ var LocalAgent = class {
|
|
|
10133
10137
|
this.options = options;
|
|
10134
10138
|
this.workspaceCwd = resolveCwd(options.local?.cwd);
|
|
10135
10139
|
this.transcriptBaseDir = resolveSessionDir(options.local);
|
|
10136
|
-
this.sessionStore = options.local?.sessionStore ?? new
|
|
10140
|
+
this.sessionStore = options.local?.sessionStore ?? new chunkNQVWSSX2_cjs.FsSessionStore({ baseDir: this.transcriptBaseDir, cwd: this.workspaceCwd });
|
|
10137
10141
|
this.settingSourcesIncludeProject = includesSetting(options, "project");
|
|
10138
10142
|
this.settingSourcesIncludePlugins = includesSetting(options, "plugins");
|
|
10139
10143
|
const sub = bootstrapSubmanagers({
|
|
@@ -10610,10 +10614,12 @@ async function rehydrateExistingAgent(agentId, existing, options) {
|
|
|
10610
10614
|
await chunkQY3CIMUV_cjs.discoverProviderPlugins();
|
|
10611
10615
|
await validateRehydratedAgent(agentId, existing);
|
|
10612
10616
|
const mergedLocal = options.local !== void 0 && existing.options.local !== void 0 ? { ...existing.options.local, ...options.local } : options.local ?? existing.options.local;
|
|
10617
|
+
const mergedMemory = mergeResumedMemory(existing.options.memory, options.memory);
|
|
10613
10618
|
const mergedOptions = {
|
|
10614
10619
|
...existing.options,
|
|
10615
10620
|
...options,
|
|
10616
10621
|
...mergedLocal !== void 0 ? { local: mergedLocal } : {},
|
|
10622
|
+
...mergedMemory !== void 0 ? { memory: mergedMemory } : {},
|
|
10617
10623
|
// SE8 — normalize a caller-supplied bare-string model override at this resume
|
|
10618
10624
|
// boundary (Agent.resume never flows through runCreateUnderSpan). Cloud resume
|
|
10619
10625
|
// honors it; local resume forces the persisted model below.
|
|
@@ -10621,6 +10627,7 @@ async function rehydrateExistingAgent(agentId, existing, options) {
|
|
|
10621
10627
|
mcpServers: void 0,
|
|
10622
10628
|
agentId
|
|
10623
10629
|
};
|
|
10630
|
+
chunkZD66GFH5_cjs.resolveMaxFacts(mergedOptions.memory?.maxFacts);
|
|
10624
10631
|
if (existing.runtime === "cloud") {
|
|
10625
10632
|
return new CloudAgent(mergedOptions, agentId);
|
|
10626
10633
|
}
|
|
@@ -10628,6 +10635,12 @@ async function rehydrateExistingAgent(agentId, existing, options) {
|
|
|
10628
10635
|
await agent.initialize();
|
|
10629
10636
|
return agent;
|
|
10630
10637
|
}
|
|
10638
|
+
function mergeResumedMemory(persisted, override) {
|
|
10639
|
+
if (override === void 0) return persisted;
|
|
10640
|
+
if (persisted === void 0) return override;
|
|
10641
|
+
const named = Object.entries(override).filter(([, value]) => value !== void 0);
|
|
10642
|
+
return { ...persisted, ...Object.fromEntries(named) };
|
|
10643
|
+
}
|
|
10631
10644
|
async function validateRehydratedAgent(agentId, entry) {
|
|
10632
10645
|
if (entry.runtime !== "local") return;
|
|
10633
10646
|
const candidate = entry.options.local?.cwd ?? entry.cwd;
|
|
@@ -11236,7 +11249,7 @@ async function openLocalStore(reg) {
|
|
|
11236
11249
|
const cwd = reg.cwd ?? process.cwd();
|
|
11237
11250
|
const optModel = reg.options.model;
|
|
11238
11251
|
const model = reg.model?.id ?? (typeof optModel === "string" ? optModel : optModel?.id) ?? "unknown";
|
|
11239
|
-
const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-
|
|
11252
|
+
const { FsSessionStore: FsSessionStore2 } = await import('./fs-session-store-IQ6PEHYF.cjs');
|
|
11240
11253
|
const { defaultBaseDir: defaultBaseDir2, expandTilde: expandTilde2 } = await import('./session-transcript-RACG7BK2.cjs');
|
|
11241
11254
|
const configuredSessionDir = reg.options.local?.sessionDir ?? reg.options.local?.baseDir;
|
|
11242
11255
|
const baseDir = configuredSessionDir !== void 0 ? expandTilde2(configuredSessionDir) : defaultBaseDir2();
|
|
@@ -11257,5 +11270,5 @@ exports.managedSettingsPathFor = managedSettingsPathFor;
|
|
|
11257
11270
|
exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
|
|
11258
11271
|
exports.readManagedSettings = readManagedSettings;
|
|
11259
11272
|
exports.resolveSessionDir = resolveSessionDir;
|
|
11260
|
-
//# sourceMappingURL=chunk-
|
|
11261
|
-
//# sourceMappingURL=chunk-
|
|
11273
|
+
//# sourceMappingURL=chunk-CVEQ5366.cjs.map
|
|
11274
|
+
//# sourceMappingURL=chunk-CVEQ5366.cjs.map
|