@theokit/sdk 4.29.0 → 4.31.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 +43 -0
- package/dist/{agent-LBCEK6VH.cjs → agent-6GQBOHHA.cjs} +8 -8
- package/dist/{agent-LBCEK6VH.cjs.map → agent-6GQBOHHA.cjs.map} +1 -1
- package/dist/{agent-CdjSCbYz.d.cts → agent-Bzg2_uGr.d.cts} +55 -1
- package/dist/{agent-FBTLZI6V.js → agent-DY5LGZ5E.js} +7 -7
- package/dist/{agent-FBTLZI6V.js.map → agent-DY5LGZ5E.js.map} +1 -1
- package/dist/{agent-BZz4X8ZM.d.ts → agent-Ekv8y7_c.d.ts} +55 -1
- package/dist/agent.d.ts +15 -2
- package/dist/{chunk-EULKRTB5.js → chunk-4JWZRASX.js} +3 -3
- package/dist/{chunk-EULKRTB5.js.map → chunk-4JWZRASX.js.map} +1 -1
- package/dist/{chunk-YQAPEYUV.cjs → chunk-CYTAM3E6.cjs} +81 -43
- package/dist/chunk-CYTAM3E6.cjs.map +1 -0
- package/dist/{chunk-54YLX4Q6.cjs → chunk-FDGRQQWX.cjs} +5 -5
- package/dist/{chunk-54YLX4Q6.cjs.map → chunk-FDGRQQWX.cjs.map} +1 -1
- package/dist/{chunk-VUJ3NVDC.js → chunk-FZ75EZR5.js} +52 -14
- package/dist/chunk-FZ75EZR5.js.map +1 -0
- package/dist/chunk-ICSCKB3N.js +140 -0
- package/dist/chunk-ICSCKB3N.js.map +1 -0
- package/dist/{chunk-U6QGZHPN.js → chunk-PORDVVJS.js} +5 -6
- package/dist/chunk-PORDVVJS.js.map +1 -0
- package/dist/{chunk-NRSH7RJY.js → chunk-TLG444A6.js} +61 -13
- package/dist/chunk-TLG444A6.js.map +1 -0
- package/dist/{chunk-2HRYBRD7.cjs → chunk-U447MTG4.cjs} +5 -6
- package/dist/chunk-U447MTG4.cjs.map +1 -0
- package/dist/{chunk-2MF3IE2D.cjs → chunk-UKNMWCPZ.cjs} +63 -15
- package/dist/chunk-UKNMWCPZ.cjs.map +1 -0
- package/dist/{chunk-SQLZ7ONU.js → chunk-VUXLNVX7.js} +3 -3
- package/dist/{chunk-SQLZ7ONU.js.map → chunk-VUXLNVX7.js.map} +1 -1
- package/dist/{chunk-HK7ZHSAX.cjs → chunk-WQEQCJTZ.cjs} +64 -3
- package/dist/chunk-WQEQCJTZ.cjs.map +1 -0
- package/dist/{chunk-YU6KON2I.cjs → chunk-XJT5VACT.cjs} +3 -3
- package/dist/{chunk-YU6KON2I.cjs.map → chunk-XJT5VACT.cjs.map} +1 -1
- package/dist/{compact-session-OO7NVWPB.cjs → compact-session-2BFNMENR.cjs} +11 -11
- package/dist/{compact-session-OO7NVWPB.cjs.map → compact-session-2BFNMENR.cjs.map} +1 -1
- package/dist/{compact-session-OO2GD76G.js → compact-session-2JONXHLR.js} +3 -3
- package/dist/{compact-session-OO2GD76G.js.map → compact-session-2JONXHLR.js.map} +1 -1
- package/dist/{cron-CIIshMs3.d.cts → cron-CjzvXGT2.d.cts} +1 -1
- package/dist/{cron-dElBjDaL.d.ts → cron-D0Z29gI-.d.ts} +1 -1
- package/dist/cron.cjs +7 -7
- package/dist/cron.d.cts +2 -2
- package/dist/cron.d.ts +2 -2
- package/dist/cron.js +6 -6
- package/dist/eval.cjs +10 -11
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +6 -7
- package/dist/eval.js.map +1 -1
- package/dist/fs-session-store-26WVVMC4.cjs +17 -0
- package/dist/{fs-session-store-KAUQYSGI.cjs.map → fs-session-store-26WVVMC4.cjs.map} +1 -1
- package/dist/fs-session-store-7AEI4STY.js +8 -0
- package/dist/{fs-session-store-ZKB5NN37.js.map → fs-session-store-7AEI4STY.js.map} +1 -1
- package/dist/index.cjs +28 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -6
- package/dist/index.d.ts +19 -6
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-6MJUSGZP.cjs → inject-session-MIFEKATN.cjs} +4 -4
- package/dist/{inject-session-6MJUSGZP.cjs.map → inject-session-MIFEKATN.cjs.map} +1 -1
- package/dist/{inject-session-KOFHS5K3.js → inject-session-NNSCCIVP.js} +3 -3
- package/dist/{inject-session-KOFHS5K3.js.map → inject-session-NNSCCIVP.js.map} +1 -1
- package/dist/internal/llm/retrying-client.d.ts +29 -0
- package/dist/internal/persistence/index.cjs +18 -19
- package/dist/internal/persistence/index.cjs.map +1 -1
- package/dist/internal/persistence/index.js +1 -2
- package/dist/internal/persistence/index.js.map +1 -1
- package/dist/internal/plugins/types.d.cts +1 -1
- package/dist/internal/plugins/types.d.ts +1 -1
- package/dist/persistence.cjs +10 -11
- package/dist/persistence.cjs.map +1 -1
- package/dist/persistence.js +1 -2
- 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/plugin.d.ts +32 -0
- package/package.json +1 -1
- package/dist/chunk-2HRYBRD7.cjs.map +0 -1
- package/dist/chunk-2MF3IE2D.cjs.map +0 -1
- package/dist/chunk-C7PICHRF.cjs +0 -68
- package/dist/chunk-C7PICHRF.cjs.map +0 -1
- package/dist/chunk-HK7ZHSAX.cjs.map +0 -1
- package/dist/chunk-HZQEDNF6.js +0 -66
- package/dist/chunk-HZQEDNF6.js.map +0 -1
- package/dist/chunk-NRSH7RJY.js.map +0 -1
- package/dist/chunk-R6ZP6KNB.js +0 -80
- package/dist/chunk-R6ZP6KNB.js.map +0 -1
- package/dist/chunk-U6QGZHPN.js.map +0 -1
- package/dist/chunk-VUJ3NVDC.js.map +0 -1
- package/dist/chunk-YQAPEYUV.cjs.map +0 -1
- package/dist/fs-session-store-KAUQYSGI.cjs +0 -17
- package/dist/fs-session-store-ZKB5NN37.js +0 -8
package/dist/chunk-C7PICHRF.cjs
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkYLQQX5W2_cjs = require('./chunk-YLQQX5W2.cjs');
|
|
4
|
-
|
|
5
|
-
// src/internal/persistence/file-lock.ts
|
|
6
|
-
var cached;
|
|
7
|
-
var warnedMissing = false;
|
|
8
|
-
var warnedStructural = false;
|
|
9
|
-
async function getProperLockfile() {
|
|
10
|
-
if (cached !== void 0) return cached;
|
|
11
|
-
try {
|
|
12
|
-
const mod = await import('proper-lockfile');
|
|
13
|
-
if (!validateLockModule(mod)) {
|
|
14
|
-
if (!warnedStructural) {
|
|
15
|
-
warnedStructural = true;
|
|
16
|
-
process.stderr.write(
|
|
17
|
-
"[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"
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
cached = null;
|
|
21
|
-
return cached;
|
|
22
|
-
}
|
|
23
|
-
cached = mod;
|
|
24
|
-
} catch {
|
|
25
|
-
cached = null;
|
|
26
|
-
}
|
|
27
|
-
return cached;
|
|
28
|
-
}
|
|
29
|
-
function validateLockModule(mod) {
|
|
30
|
-
if (mod === null || mod === void 0 || typeof mod !== "object") return false;
|
|
31
|
-
const m = mod;
|
|
32
|
-
return typeof m.lock === "function" && typeof m.unlock === "function";
|
|
33
|
-
}
|
|
34
|
-
async function withFileLock(path, fn, options) {
|
|
35
|
-
const lib = await getProperLockfile();
|
|
36
|
-
if (lib === null) {
|
|
37
|
-
if (!warnedMissing) {
|
|
38
|
-
warnedMissing = true;
|
|
39
|
-
process.stderr.write(
|
|
40
|
-
"[theokit-sdk] proper-lockfile not installed; cross-process file lock unavailable. Install with: pnpm add proper-lockfile\n"
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
return chunkYLQQX5W2_cjs.withCwdMutex(`file-lock:${path}`, fn);
|
|
44
|
-
}
|
|
45
|
-
return chunkYLQQX5W2_cjs.withCwdMutex(`file-lock:${path}`, async () => {
|
|
46
|
-
const release = await lib.lock(path, {
|
|
47
|
-
// EC-1: companion lockfile, target path may not exist yet.
|
|
48
|
-
lockfilePath: `${path}.lock`,
|
|
49
|
-
realpath: false,
|
|
50
|
-
stale: options?.stale ?? 3e4,
|
|
51
|
-
retries: {
|
|
52
|
-
retries: options?.retries ?? 5,
|
|
53
|
-
factor: options?.retryFactor ?? 1.5,
|
|
54
|
-
minTimeout: 100,
|
|
55
|
-
maxTimeout: 5e3
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
try {
|
|
59
|
-
return await fn();
|
|
60
|
-
} finally {
|
|
61
|
-
await release();
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
exports.withFileLock = withFileLock;
|
|
67
|
-
//# sourceMappingURL=chunk-C7PICHRF.cjs.map
|
|
68
|
-
//# sourceMappingURL=chunk-C7PICHRF.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/persistence/file-lock.ts"],"names":["withCwdMutex"],"mappings":";;;;;AAgCA,IAAI,MAAA;AACJ,IAAI,aAAA,GAAgB,KAAA;AACpB,IAAI,gBAAA,GAAmB,KAAA;AAEvB,eAAe,iBAAA,GAA0D;AACvE,EAAA,IAAI,MAAA,KAAW,QAAW,OAAO,MAAA;AACjC,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,MAAM,OAAO,iBAAiB,CAAA;AAM1C,IAAA,IAAI,CAAC,kBAAA,CAAmB,GAAG,CAAA,EAAG;AAC5B,MAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,QAAA,gBAAA,GAAmB,IAAA;AACnB,QAAA,OAAA,CAAQ,MAAA,CAAO,KAAA;AAAA,UACb;AAAA,SAKF;AAAA,MACF;AACA,MAAA,MAAA,GAAS,IAAA;AACT,MAAA,OAAO,MAAA;AAAA,IACT;AACA,IAAA,MAAA,GAAS,GAAA;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CAAA;AAED,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,EAAA,EAAG;AAAA,IAClB,CAAA,SAAE;AACA,MAAA,MAAM,OAAA,EAAQ;AAAA,IAChB;AAAA,EACF,CAAC,CAAA;AACH","file":"chunk-C7PICHRF.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 { 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\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 process.stderr.write(\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 {\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}\n\n/**\n * Options for `withFileLock`.\n *\n * @internal\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 * @internal\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 if (!warnedMissing) {\n warnedMissing = true;\n process.stderr.write(\n \"[theokit-sdk] proper-lockfile not installed; \" +\n \"cross-process file lock unavailable. \" +\n \"Install with: pnpm add proper-lockfile\\n\",\n );\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/persistence/jsonl.ts"],"names":["readFileSync","path","mkdirSync","dirname","appendFileSync"],"mappings":";;;;;;AAoBO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EACzC,WAAA,CACE,SACS,IAAA,EACT;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAFJ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAGT,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AAAA,EACd;AAAA,EAJW,IAAA;AAKb;AAEA,SAAS,cAAc,KAAA,EAAkD;AACvE,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AAGA,SAAS,mBAAmB,IAAA,EAAmD;AAC7E,EAAA,IAAI,IAAA,CAAK,MAAA,KAAW,CAAA,EAAG,OAAO,MAAA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onl` — generic dataset reader (split/trim/skip-blank/parse) with a\n * line-numbered {@link JsonlParseError}. The dataset SCHEMA is the caller's\n * concern via `map` (M6 ADR D3) — this module owns only the parse.\n * - `appendJsonl` / `readJsonlIds` — crash-durable, resumable batch persistence\n * (M6 ADR D1): each record is appended as one whole `\\n`-terminated line the\n * instant it is produced, and a re-run resumes by skipping already-keyed rows.\n *\n * referencia: knowledge-base/references/theocode-eval/lib/swebench-dataset.ts:82\n * (parseJsonl + line-N error) and swebench-batch.ts:113,205 (resume + per-line\n * flush).\n *\n * @internal\n */\nimport { appendFileSync, mkdirSync, readFileSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\n\n/** Raised when a JSONL line is not valid JSON or is not a JSON object. Carries the 1-based line number. */\nexport class JsonlParseError extends Error {\n constructor(\n message: string,\n readonly line: number,\n ) {\n super(message);\n this.name = \"JsonlParseError\";\n }\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Parse a single trimmed line to a plain object, or `undefined` if blank / invalid / non-object. */\nfunction tryParseObjectLine(line: string): Record<string, unknown> | undefined {\n if (line.length === 0) return undefined;\n let parsed: unknown;\n try {\n parsed = JSON.parse(line);\n } catch {\n return undefined;\n }\n return isPlainObject(parsed) ? parsed : undefined;\n}\n\n/**\n * Parse a JSONL file into rows. Blank lines are skipped. A malformed or\n * non-object line throws {@link JsonlParseError} naming the 1-based line. When\n * `map` is provided, each raw object is mapped to the typed row (the SWE-bench\n * schema lives in the caller's `map`, per M6 ADR D3).\n */\nexport function loadJsonl<T = Record<string, unknown>>(\n path: string,\n opts: {\n map?: (raw: Record<string, unknown>, lineNumber: number) => T;\n /**\n * M81 — tolerate a truncated LAST line (a crash artifact: the process died mid-write).\n *\n * Opt-in on purpose. As a default it would also swallow corruption in the MIDDLE of the file,\n * turning loud data loss into silent data loss — the wrong trade for a session store.\n */\n tolerateTrailingPartialLine?: boolean;\n } = {},\n): T[] {\n const linhas = readFileSync(path, \"utf8\").split(\"\\n\");\n const out: T[] = [];\n for (let i = 0; i < linhas.length; i += 1) {\n const lineNumber = i + 1;\n const line = (linhas[i] ?? \"\").trim();\n if (line.length === 0) continue;\n // M81 — `undefined` = linha inválida tolerada (última, truncada por crash). Qualquer outra\n // linha inválida já lançou dentro de `parsearLinha`.\n const parsed = parsearLinha(\n line,\n lineNumber,\n opts.tolerateTrailingPartialLine === true && lineNumber === linhas.length,\n );\n if (parsed === undefined) break;\n out.push(opts.map ? opts.map(parsed, lineNumber) : (parsed as unknown as T));\n }\n return out;\n}\n\n/**\n * Parse de UMA linha, devolvendo `undefined` quando ela é uma última-linha-truncada tolerada.\n *\n * Extraído porque `loadJsonl` passou do teto de complexidade cognitiva quando ganhou a tolerância —\n * e porque parse-de-linha e iteração-do-arquivo são duas responsabilidades que só estavam juntas\n * por hábito.\n */\nfunction parsearLinha(\n line: string,\n lineNumber: number,\n tolerar: boolean,\n): Record<string, unknown> | undefined {\n let parsed: unknown;\n try {\n parsed = JSON.parse(line);\n } catch {\n if (tolerar) return undefined;\n throw new JsonlParseError(`line ${lineNumber}: invalid JSON`, lineNumber);\n }\n if (!isPlainObject(parsed)) {\n throw new JsonlParseError(`line ${lineNumber}: not a JSON object`, lineNumber);\n }\n return parsed;\n}\n\n/**\n * Append one record as a whole `\\n`-terminated JSON line. Creates the parent dir\n * if missing. `appendFileSync` is synchronous, so within a single Node process\n * the event loop serializes writes and each call writes its line atomically —\n * interleave-safe for the bounded-concurrency batch runner.\n *\n * referencia: swebench-batch.ts:192 (mkdir-before-append), :205 (per-line flush).\n */\nexport function appendJsonl(path: string, record: unknown): void {\n mkdirSync(dirname(path), { recursive: true });\n appendFileSync(path, `${JSON.stringify(record)}\\n`);\n}\n\n/**\n * Read the set of keys from an existing JSONL file for which `keyFn(parsed)`\n * returns a non-empty string. Used to resume a crashed batch by skipping rows\n * already persisted with a successful result. A trailing partial line from an\n * interrupted append is tolerated (skipped, not thrown), and a missing file\n * yields an empty set.\n *\n * referencia: swebench-batch.ts:113 (readDoneIds), :129 (success-only),\n * :131 (tolerate partial line).\n */\nexport function readJsonlIds(\n path: string,\n keyFn: (parsed: Record<string, unknown>) => string | undefined,\n): Set<string> {\n const done = new Set<string>();\n let text: string;\n try {\n text = readFileSync(path, \"utf8\");\n } catch {\n return done; // no file yet → nothing done\n }\n for (const rawLine of text.split(\"\\n\")) {\n // A trailing partial line from an interrupted run parses to undefined → skipped.\n const parsed = tryParseObjectLine(rawLine.trim());\n if (parsed === undefined) continue;\n const key = keyFn(parsed);\n if (typeof key === \"string\" && key.length > 0) done.add(key);\n }\n return done;\n}\n"]}
|
package/dist/chunk-HZQEDNF6.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { withCwdMutex } from './chunk-2XLKLVVR.js';
|
|
2
|
-
|
|
3
|
-
// src/internal/persistence/file-lock.ts
|
|
4
|
-
var cached;
|
|
5
|
-
var warnedMissing = false;
|
|
6
|
-
var warnedStructural = false;
|
|
7
|
-
async function getProperLockfile() {
|
|
8
|
-
if (cached !== void 0) return cached;
|
|
9
|
-
try {
|
|
10
|
-
const mod = await import('proper-lockfile');
|
|
11
|
-
if (!validateLockModule(mod)) {
|
|
12
|
-
if (!warnedStructural) {
|
|
13
|
-
warnedStructural = true;
|
|
14
|
-
process.stderr.write(
|
|
15
|
-
"[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"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
cached = null;
|
|
19
|
-
return cached;
|
|
20
|
-
}
|
|
21
|
-
cached = mod;
|
|
22
|
-
} catch {
|
|
23
|
-
cached = null;
|
|
24
|
-
}
|
|
25
|
-
return cached;
|
|
26
|
-
}
|
|
27
|
-
function validateLockModule(mod) {
|
|
28
|
-
if (mod === null || mod === void 0 || typeof mod !== "object") return false;
|
|
29
|
-
const m = mod;
|
|
30
|
-
return typeof m.lock === "function" && typeof m.unlock === "function";
|
|
31
|
-
}
|
|
32
|
-
async function withFileLock(path, fn, options) {
|
|
33
|
-
const lib = await getProperLockfile();
|
|
34
|
-
if (lib === null) {
|
|
35
|
-
if (!warnedMissing) {
|
|
36
|
-
warnedMissing = true;
|
|
37
|
-
process.stderr.write(
|
|
38
|
-
"[theokit-sdk] proper-lockfile not installed; cross-process file lock unavailable. Install with: pnpm add proper-lockfile\n"
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
return withCwdMutex(`file-lock:${path}`, fn);
|
|
42
|
-
}
|
|
43
|
-
return withCwdMutex(`file-lock:${path}`, async () => {
|
|
44
|
-
const release = await lib.lock(path, {
|
|
45
|
-
// EC-1: companion lockfile, target path may not exist yet.
|
|
46
|
-
lockfilePath: `${path}.lock`,
|
|
47
|
-
realpath: false,
|
|
48
|
-
stale: options?.stale ?? 3e4,
|
|
49
|
-
retries: {
|
|
50
|
-
retries: options?.retries ?? 5,
|
|
51
|
-
factor: options?.retryFactor ?? 1.5,
|
|
52
|
-
minTimeout: 100,
|
|
53
|
-
maxTimeout: 5e3
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
try {
|
|
57
|
-
return await fn();
|
|
58
|
-
} finally {
|
|
59
|
-
await release();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export { withFileLock };
|
|
65
|
-
//# sourceMappingURL=chunk-HZQEDNF6.js.map
|
|
66
|
-
//# sourceMappingURL=chunk-HZQEDNF6.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/persistence/file-lock.ts"],"names":[],"mappings":";;;AAgCA,IAAI,MAAA;AACJ,IAAI,aAAA,GAAgB,KAAA;AACpB,IAAI,gBAAA,GAAmB,KAAA;AAEvB,eAAe,iBAAA,GAA0D;AACvE,EAAA,IAAI,MAAA,KAAW,QAA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AA,GAAU,MAAM,GAAA,CAAI,IAAA,CAAK,IAAA,EAAM;AAAA;AAAA,MAEnC,YAAA,EAAc,GAAG,IAAI,CAAA,KAAA,CAAA;AAAA,MACrB,QAAA,EAAU,KAAA;AAAA,MACV,KAAA,EAAO,SAAS,KAAA,IAAS,GAAA;AAAA,MACzB,OAAA,EAAS;AAAA,QACP,OAAA,EAAS,SAAS,OAAA,IAAW,CAAA;AAAA,QAC7B,MAAA,EAAQ,SAAS,WAAA,IAAe,GAAA;AAAA,QAChC,UAAA,EAAY,GAAA;AAAA,QACZ,UAAA,EAAY;AAAA;AACd,KACD,CAAA;AAED,IAAA,IAAI;AACF,MAAA,OAAO,MAAM,EAAA,EAAG;AAAA,IAClB,CAAA,SAAE;AACA,MAAA,MAAM,OAAA,EAAQ;AAAA,IAChB;AAAA,EACF,CAAC,CAAA;AACH","file":"chunk-HZQEDNF6.js","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 { 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\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 process.stderr.write(\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 {\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}\n\n/**\n * Options for `withFileLock`.\n *\n * @internal\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 * @internal\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 if (!warnedMissing) {\n warnedMissing = true;\n process.stderr.write(\n \"[theokit-sdk] proper-lockfile not installed; \" +\n \"cross-process file lock unavailable. \" +\n \"Install with: pnpm add proper-lockfile\\n\",\n );\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"]}
|