@theokit/sdk 4.63.3 → 4.63.4
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 +67 -0
- package/dist/{agent-3JK7VXNN.js → agent-A5XMIVNP.js} +6 -6
- package/dist/{agent-3JK7VXNN.js.map → agent-A5XMIVNP.js.map} +1 -1
- package/dist/{agent-PVINJTUR.cjs → agent-UX7WFI6B.cjs} +7 -7
- package/dist/{agent-PVINJTUR.cjs.map → agent-UX7WFI6B.cjs.map} +1 -1
- package/dist/chunk-247ZTLNU.js +73 -0
- package/dist/chunk-247ZTLNU.js.map +1 -0
- package/dist/{chunk-GPKAF7SG.js → chunk-32WTYBUH.js} +3 -3
- package/dist/{chunk-GPKAF7SG.js.map → chunk-32WTYBUH.js.map} +1 -1
- package/dist/{chunk-CQBXOJ6U.cjs → chunk-43ZQRWAP.cjs} +5 -5
- package/dist/{chunk-CQBXOJ6U.cjs.map → chunk-43ZQRWAP.cjs.map} +1 -1
- package/dist/{chunk-JJ3OVRUM.cjs → chunk-7VT4P3Z4.cjs} +136 -35
- package/dist/chunk-7VT4P3Z4.cjs.map +1 -0
- package/dist/chunk-AKJP2STZ.cjs +81 -0
- package/dist/chunk-AKJP2STZ.cjs.map +1 -0
- package/dist/{chunk-ZWRG4NWT.cjs → chunk-GMLBYDW4.cjs} +4 -4
- package/dist/{chunk-ZWRG4NWT.cjs.map → chunk-GMLBYDW4.cjs.map} +1 -1
- package/dist/{chunk-LXI4XZEC.js → chunk-LKBEROHN.js} +3 -3
- package/dist/{chunk-LXI4XZEC.js.map → chunk-LKBEROHN.js.map} +1 -1
- package/dist/{chunk-25BD2R5G.js → chunk-LYTOXSRH.js} +113 -12
- package/dist/chunk-LYTOXSRH.js.map +1 -0
- package/dist/{chunk-K5OJUYSZ.js → chunk-NDGGJQTZ.js} +13 -4
- package/dist/chunk-NDGGJQTZ.js.map +1 -0
- package/dist/{chunk-ZCIRZE37.cjs → chunk-VCLBZAZU.cjs} +14 -5
- package/dist/chunk-VCLBZAZU.cjs.map +1 -0
- package/dist/{context-AGQ3DIZU.cjs → context-WFLTTMK3.cjs} +7 -7
- package/dist/{context-AGQ3DIZU.cjs.map → context-WFLTTMK3.cjs.map} +1 -1
- package/dist/context-WI2DFG7V.js +7 -0
- package/dist/{context-GQRFBCLP.js.map → context-WI2DFG7V.js.map} +1 -1
- package/dist/cron.cjs +6 -6
- package/dist/cron.js +5 -5
- package/dist/eval.cjs +5 -5
- package/dist/eval.js +4 -4
- package/dist/index.cjs +20 -20
- package/dist/index.js +7 -7
- package/dist/internal/agent-loop/replay-messages.d.ts +41 -0
- package/dist/internal/local-agent/local-option-keys.d.ts +2 -0
- package/dist/internal/persistence/index.cjs +4 -4
- package/dist/internal/persistence/index.js +1 -1
- package/dist/internal/runtime/compat/foreign-config-sources.d.ts +92 -0
- package/dist/internal/runtime/hooks/hooks-executor.d.ts +9 -0
- package/dist/internal/runtime/hooks/hooks-source.d.ts +9 -0
- package/dist/subagents-loader-UCNO7FUH.cjs +17 -0
- package/dist/{subagents-loader-YEUFFPAL.cjs.map → subagents-loader-UCNO7FUH.cjs.map} +1 -1
- package/dist/subagents-loader-XP5ERVDZ.js +8 -0
- package/dist/{subagents-loader-CRT5LLL3.js.map → subagents-loader-XP5ERVDZ.js.map} +1 -1
- package/dist/subagents-loader.cjs +3 -3
- package/dist/subagents-loader.js +2 -2
- package/docs/error-codes.md +5 -5
- package/package.json +1 -1
- package/dist/chunk-25BD2R5G.js.map +0 -1
- package/dist/chunk-AQO3NSRG.cjs +0 -41
- package/dist/chunk-AQO3NSRG.cjs.map +0 -1
- package/dist/chunk-JJ3OVRUM.cjs.map +0 -1
- package/dist/chunk-K5OJUYSZ.js.map +0 -1
- package/dist/chunk-UFLD2HEV.js +0 -35
- package/dist/chunk-UFLD2HEV.js.map +0 -1
- package/dist/chunk-ZCIRZE37.cjs.map +0 -1
- package/dist/context-GQRFBCLP.js +0 -7
- package/dist/subagents-loader-CRT5LLL3.js +0 -8
- package/dist/subagents-loader-YEUFFPAL.cjs +0 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { projectConfigRoots } from './chunk-
|
|
1
|
+
import { projectConfigRoots } from './chunk-247ZTLNU.js';
|
|
2
2
|
import { ConfigurationError } from './chunk-ZZMZWBR6.js';
|
|
3
3
|
import { diag } from './chunk-XEQ3TM66.js';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
@@ -25,7 +25,7 @@ async function loadHookConfig(cwd) {
|
|
|
25
25
|
for (const path of hookConfigCandidates(cwd)) {
|
|
26
26
|
if (!existsSync(path)) continue;
|
|
27
27
|
sawAny = true;
|
|
28
|
-
mergeInto(merged, await readHookFile(path));
|
|
28
|
+
mergeInto(merged, stampSource(await readHookFile(path), path));
|
|
29
29
|
}
|
|
30
30
|
if (!sawAny && existsSync(join(cwd, ".theokit", "hooks"))) {
|
|
31
31
|
warnOnce(
|
|
@@ -43,6 +43,15 @@ function hookConfigCandidates(cwd) {
|
|
|
43
43
|
...roots.map((root) => join(root, "settings.local.json"))
|
|
44
44
|
];
|
|
45
45
|
}
|
|
46
|
+
function stampSource(config, sourcePath) {
|
|
47
|
+
if (config.hooks === void 0) return config;
|
|
48
|
+
const hooks = {};
|
|
49
|
+
for (const [event, commands] of Object.entries(config.hooks)) {
|
|
50
|
+
if (commands === void 0) continue;
|
|
51
|
+
hooks[event] = commands.map((c) => ({ sourcePath, ...c }));
|
|
52
|
+
}
|
|
53
|
+
return { hooks };
|
|
54
|
+
}
|
|
46
55
|
function mergeInto(target, source) {
|
|
47
56
|
for (const [event, commands] of Object.entries(source.hooks ?? {})) {
|
|
48
57
|
if (commands === void 0 || commands.length === 0) continue;
|
|
@@ -153,5 +162,5 @@ function warnPersonalitySwitchInsideFork(agentId) {
|
|
|
153
162
|
}
|
|
154
163
|
|
|
155
164
|
export { currentPersonalityContext, loadHookConfig, warnOnce, warnPersonalitySwitchInsideFork, withPersonalityContext };
|
|
156
|
-
//# sourceMappingURL=chunk-
|
|
157
|
-
//# sourceMappingURL=chunk-
|
|
165
|
+
//# sourceMappingURL=chunk-NDGGJQTZ.js.map
|
|
166
|
+
//# sourceMappingURL=chunk-NDGGJQTZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/runtime/hooks/hooks-source.ts","../src/internal/personality/context.ts"],"names":[],"mappings":";;;;;;;;AAiCA,IAAM,qBAAA,GAA6D;AAAA,EACjE,UAAA,EAAY,YAAA;AAAA,EACZ,WAAA,EAAa,aAAA;AAAA,EACb,gBAAA,EAAkB,QAAA;AAAA,EAClB,IAAA,EAAM;AACR,CAAA;AAqBA,IAAM,MAAA,uBAAa,GAAA,EAAY;AAYxB,SAAS,QAAA,CAAS,KAAa,OAAA,EAAuB;AAC3D,EAAA,IAAI,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA,EAAG;AACrB,EAAA,MAAA,CAAO,IAAI,GAAG,CAAA;AACd,EAAA,IAAA,CAAK,GAAG,OAAO;AAAA,CAAI,CAAA;AACrB;AAcA,eAAsB,eAAe,GAAA,EAAkC;AACrE,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,IAAA,IAAQ,oBAAA,CAAqB,GAAG,CAAA,EAAG;AAC5C,IAAA,IAAI,CAAC,UAAA,CAAW,IAAI,CAAA,EAAG;AACvB,IAAA,MAAA,GAAS,IAAA;AAIT,IAAA,SAAA,CAAU,QAAQ,WAAA,CAAY,MAAM,aAAa,IAAI,CAAA,EAAG,IAAI,CAAC,CAAA;AAAA,EAC/D;AACA,EAAA,IAAI,CAAC,UAAU,UAAA,CAAW,IAAA,CAAK,KAAK,UAAA,EAAY,OAAO,CAAC,CAAA,EAAG;AACzD,IAAA,QAAA;AAAA,MACE,sBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAaA,S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I,OAAA,EAAQ;AAC/C,EAAA,IAAI,OAAA,KAAY,MAAA,EAAW,EAAA,CAAG,OAAA,GAAU,OAAA;AACxC,EAAA,IAAI,OAAO,GAAA,CAAI,OAAA,KAAY,QAAA,IAAY,GAAA,CAAI,UAAU,CAAA,EAAG;AACtD,IAAA,EAAA,CAAG,SAAA,GAAY,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,UAAU,GAAI,CAAA;AAAA,EAC9C;AACA,EAAA,OAAO,EAAA;AACT;;;ACjPA,IAAM,OAAA,GAAU,IAAI,iBAAA,EAA0C;AAQvD,SAAS,sBAAA,CACd,KACA,EAAA,EACY;AACZ,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,EAAE,CAAA;AAC5B;AAQO,SAAS,yBAAA,GAAgE;AAC9E,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;AASO,SAAS,gCAAgC,OAAA,EAAuB;AACrE,EAAA,QAAA;AAAA,IACE,8BAA8B,OAAO,CAAA,CAAA;AAAA,IACrC,CAAA,0IAAA;AAAA,GACF;AACF","file":"chunk-NDGGJQTZ.js","sourcesContent":["/**\n * Single source of truth for loading the hooks config (ADR 0016 — reverses\n * D74/D77 for hooks: JSON is canonical again, in the Claude Code shape).\n *\n * `.theokit/hooks.json` (Claude-Code-shaped JSON) is the only supported form.\n * A stray legacy `.theokit/hooks/*.md` dir (no hooks.json) is NOT loaded — it\n * warns to migrate and yields no hooks. Absent both → empty config.\n *\n * Consumed by `hooks-executor.ts` (runtime dispatch).\n *\n * Config shape (identical to Claude Code's `settings.json` hooks):\n * { \"hooks\": { \"PreToolUse\": [ { \"matcher\": \"shell\",\n * \"hooks\": [ { \"type\": \"command\", \"command\": \"…\", \"timeout\": 30 } ] } ] } }\n *\n * @internal\n */\n\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { ConfigurationError } from \"../../../errors.js\";\nimport { diag } from \"../../diagnostics.js\";\nimport { projectConfigRoots } from \"../../persistence/paths.js\";\n\n/** The five lifecycle events the SDK runtime actually fires. */\nexport type HookEvent = \"preRun\" | \"postRun\" | \"preToolUse\" | \"postToolUse\" | \"stop\";\n\n/**\n * Claude Code event name → the SDK firing event. Only events the runtime\n * genuinely emits are mapped; a Claude Code event with no SDK firing point\n * (SessionStart / SubagentStop / PreCompact / Notification / SessionEnd) is\n * skipped with a warn rather than silently accepted (it would never run).\n */\nconst CLAUDE_CODE_EVENT_MAP: Readonly<Record<string, HookEvent>> = {\n PreToolUse: \"preToolUse\",\n PostToolUse: \"postToolUse\",\n UserPromptSubmit: \"preRun\",\n Stop: \"stop\",\n};\n\nexport interface HookCommand {\n command: string;\n matcher?: string;\n timeoutMs?: number;\n /**\n * The config file this command was declared in.\n *\n * Carried so the executor can supply the runtime contract the declaring DIALECT presumes — a\n * command from `.claude/settings.json` is written against Claude Code's runtime and expects\n * `$CLAUDE_PROJECT_DIR` to exist (#522). Absent for a command built in memory, which is native by\n * construction.\n */\n sourcePath?: string;\n}\n\nexport interface HookConfig {\n hooks?: Partial<Record<HookEvent, HookCommand[]>>;\n}\n\nconst warned = new Set<string>();\n\n/**\n * Emit a stderr warn once per process per unique key. Helps surface the\n * deprecation path without spamming when the loader is called many times\n * during a session (cron + send + skills all hit this).\n *\n * Note: spawned workers (cron, subagent) start fresh processes — warn\n * re-emits there, by design (1 per process boot, not per call).\n *\n * @internal\n */\nexport function warnOnce(key: string, message: string): void {\n if (warned.has(key)) return;\n warned.add(key);\n diag(`${message}\\n`);\n}\n\n/** Reset for tests; not exported via barrel. @internal */\nexport function _resetWarnOnceForTests(): void {\n warned.clear();\n}\n\n/**\n * Load hooks from `.theokit/hooks.json` (Claude-Code-shaped — the only supported\n * form). A stray legacy `.theokit/hooks/*.md` markdown dir (no `hooks.json`) is\n * NOT loaded — it emits a one-time migration warn and yields no hooks.\n *\n * @internal\n */\nexport async function loadHookConfig(cwd: string): Promise<HookConfig> {\n const merged: HookConfig = {};\n let sawAny = false;\n for (const path of hookConfigCandidates(cwd)) {\n if (!existsSync(path)) continue;\n sawAny = true;\n // Stamped at merge, where the file is still known. One line later the commands are pooled per\n // event and every trace of which dialect declared them is gone — which is how a Claude Code\n // command came to be run without Claude Code's runtime (#522).\n mergeInto(merged, stampSource(await readHookFile(path), path));\n }\n if (!sawAny && existsSync(join(cwd, \".theokit\", \"hooks\"))) {\n warnOnce(\n \"hooks-md-unsupported\",\n \"[theokit-sdk] .theokit/hooks/*.md hooks are no longer supported (ADR 0016) — migrate to a Claude-Code-shaped .theokit/hooks.json\",\n );\n }\n return merged;\n}\n\n/**\n * Every file that may declare hooks, in precedence order.\n *\n * `hooks.json` under each project config root, then the Claude Code CLI's own settings files — which\n * is where the CLI actually keeps hooks, so a repository set up for it presents its hooks here\n * without being converted. `settings.local.json` is the CLI's personal-override file and sits beside\n * the shared one rather than replacing it.\n *\n * The shape never needed translating: `parseClaudeCodeConfig` reads the `hooks` key off whatever\n * object it is given, and a settings file is that same object with other keys alongside.\n */\nfunction hookConfigCandidates(cwd: string): string[] {\n const roots = projectConfigRoots(cwd);\n return [\n ...roots.map((root) => join(root, \"hooks.json\")),\n ...roots.map((root) => join(root, \"settings.json\")),\n ...roots.map((root) => join(root, \"settings.local.json\")),\n ];\n}\n\n/**\n * Record which file each command came from.\n *\n * A command already carrying a `sourcePath` keeps it: nothing produces that today, and a nested\n * config that declared its own origin would be describing something this function cannot see.\n */\nfunction stampSource(config: HookConfig, sourcePath: string): HookConfig {\n if (config.hooks === undefined) return config;\n const hooks: NonNullable<HookConfig[\"hooks\"]> = {};\n for (const [event, commands] of Object.entries(config.hooks) as [\n HookEvent,\n HookCommand[] | undefined,\n ][]) {\n if (commands === undefined) continue;\n hooks[event] = commands.map((c) => ({ sourcePath, ...c }));\n }\n return { hooks };\n}\n\n/**\n * Append one source's commands onto the accumulator, per event.\n *\n * MERGED, not first-wins, and the distinction is deliberate. An agent or a skill is a NAMED\n * declaration: two files claiming one name collide, and the explicit namespace should win. Hooks are\n * unnamed lists — two files declaring `PreToolUse` are two sets of commands an operator wrote, and\n * keeping only one drops the other in silence, which is the failure class this package guards\n * against everywhere else.\n */\nfunction mergeInto(target: HookConfig, source: HookConfig): void {\n for (const [event, commands] of Object.entries(source.hooks ?? {}) as [\n HookEvent,\n HookCommand[] | undefined,\n ][]) {\n if (commands === undefined || commands.length === 0) continue;\n target.hooks ??= {};\n target.hooks[event] = [...(target.hooks[event] ?? []), ...commands];\n }\n}\n\nasync function readHookFile(jsonPath: string): Promise<HookConfig> {\n let raw: string;\n try {\n raw = await readFile(jsonPath, \"utf8\");\n } catch (cause) {\n throw new ConfigurationError(`Failed to read hooks config: ${jsonPath}`, {\n code: \"hooks_read_error\",\n cause,\n });\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new ConfigurationError(`Invalid JSON in hooks config: ${jsonPath}`, {\n code: \"hooks_json_invalid\",\n cause,\n });\n }\n return parseClaudeCodeConfig(parsed, jsonPath);\n}\n\n/** Narrow an unknown to a record, or throw a typed config error. */\nfunction asRecord(value: unknown, path: string, where: string): Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new ConfigurationError(`hooks: expected an object at ${where} in ${path}`, {\n code: \"hooks_json_invalid\",\n });\n }\n return value as Record<string, unknown>;\n}\n\n/** Narrow an unknown to an array, or throw a typed config error. */\nfunction asArray(value: unknown, path: string, where: string): unknown[] {\n if (!Array.isArray(value)) {\n throw new ConfigurationError(`hooks: expected an array at ${where} in ${path}`, {\n code: \"hooks_json_invalid\",\n });\n }\n return value;\n}\n\n/**\n * Parse Claude Code's nested hooks config into the SDK's flat internal shape:\n * `{ hooks: { PreToolUse: [{ matcher?, hooks: [{ type:\"command\", command, timeout? }] }] } }`\n * → `{ hooks: { preToolUse: [{ command, matcher?, timeoutMs? }] } }`. Each group's\n * `matcher` applies to every command it wraps; `timeout` (seconds) → `timeoutMs`.\n */\nfunction parseClaudeCodeConfig(raw: unknown, path: string): HookConfig {\n const root = asRecord(raw, path, \"the root\");\n if (root.hooks === undefined) return {};\n const hooksRec = asRecord(root.hooks, path, `\"hooks\"`);\n const grouped: Partial<Record<HookEvent, HookCommand[]>> = {};\n\n for (const [ccEvent, groups] of Object.entries(hooksRec)) {\n const event = CLAUDE_CODE_EVENT_MAP[ccEvent];\n if (event === undefined) {\n warnOnce(\n `hooks-event-${ccEvent}`,\n `[theokit-sdk] hooks: event \"${ccEvent}\" is not fired by the SDK runtime (supported: ${Object.keys(CLAUDE_CODE_EVENT_MAP).join(\", \")}) — skipping`,\n );\n continue;\n }\n grouped[event] = [...(grouped[event] ?? []), ...flattenEventGroups(groups, path, ccEvent)];\n }\n return { hooks: grouped };\n}\n\n/** Flatten one Claude Code event's matcher-groups into internal HookCommands. */\nfunction flattenEventGroups(groups: unknown, path: string, ccEvent: string): HookCommand[] {\n const commands: HookCommand[] = [];\n for (const rawGroup of asArray(groups, path, `hooks.${ccEvent}`)) {\n const group = asRecord(rawGroup, path, `hooks.${ccEvent}[]`);\n const matcher = group.matcher === undefined ? undefined : String(group.matcher);\n for (const rawCmd of asArray(group.hooks, path, `hooks.${ccEvent}[].hooks`)) {\n commands.push(parseClaudeCodeCommand(rawCmd, matcher, path, ccEvent));\n }\n }\n return commands;\n}\n\n/** One `{ type:\"command\", command, timeout? }` entry → an internal HookCommand. */\nfunction parseClaudeCodeCommand(\n raw: unknown,\n matcher: string | undefined,\n path: string,\n ccEvent: string,\n): HookCommand {\n const cmd = asRecord(raw, path, `hooks.${ccEvent}[].hooks[]`);\n if (cmd.type !== \"command\") {\n throw new ConfigurationError(\n `hooks: only { \"type\": \"command\" } is supported (got ${JSON.stringify(cmd.type)}) in ${path}`,\n { code: \"hooks_unsupported_type\" },\n );\n }\n if (typeof cmd.command !== \"string\" || cmd.command.length === 0) {\n throw new ConfigurationError(`hooks: \"command\" must be a non-empty string in ${path}`, {\n code: \"hooks_invalid_command\",\n });\n }\n const hc: HookCommand = { command: cmd.command };\n if (matcher !== undefined) hc.matcher = matcher;\n if (typeof cmd.timeout === \"number\" && cmd.timeout > 0) {\n hc.timeoutMs = Math.round(cmd.timeout * 1000);\n }\n return hc;\n}\n","/**\n * Personality fork-context (ADR D168 + EC-A snapshot semantic).\n *\n * Uses Node's `AsyncLocalStorage` so a fork's execution chain can know\n * that it is running inside a fork AND can see the slug that was active\n * on the parent **at fork-construction time**.\n *\n * **EC-A:** The slug stored here is captured ONCE at the wrap site\n * (`localAgentFork`) — passing `parentStore.active(parentAgentId)`\n * returns a primitive `string | undefined`, which is then frozen\n * inside the ALS context object. Subsequent `usePersonality` calls on\n * the parent do NOT mutate the fork's view, because the fork reads from\n * its own ALS frame, not from the parent's store.\n *\n * @internal\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { warnOnce } from \"../runtime/hooks/hooks-source.js\";\n\n/**\n * Snapshot data carried into a fork's async context.\n *\n * @internal\n */\nexport interface PersonalityForkContext {\n /** Parent's active personality slug at fork-construction time. */\n readonly slug: string | undefined;\n /** Always `true` inside this scope (used by guards). */\n readonly isFork: true;\n}\n\nconst storage = new AsyncLocalStorage<PersonalityForkContext>();\n\n/**\n * Run `fn` with `ctx` bound as the active fork context. Nested calls\n * shadow the outer context (EC-22).\n *\n * @internal\n */\nexport function withPersonalityContext<T>(\n ctx: PersonalityForkContext,\n fn: () => Promise<T>,\n): Promise<T> {\n return storage.run(ctx, fn);\n}\n\n/**\n * Return the active fork context, or `undefined` when called outside a\n * fork scope.\n *\n * @internal\n */\nexport function currentPersonalityContext(): PersonalityForkContext | undefined {\n return storage.getStore();\n}\n\n/**\n * Emit one warning per agentId stating that personality switches inside\n * a fork are no-ops. The fork inherits the parent snapshot — runtime\n * mutation is intentionally rejected to keep fork voice deterministic.\n *\n * @internal\n */\nexport function warnPersonalitySwitchInsideFork(agentId: string): void {\n warnOnce(\n `personality-switch-in-fork-${agentId}`,\n `[theokit-sdk] usePersonality is a no-op inside a fork (D168). Subagents inherit the parent's active personality at fork-construction time.`,\n );\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkAKJP2STZ_cjs = require('./chunk-AKJP2STZ.cjs');
|
|
4
4
|
var chunk4ZHTIJNE_cjs = require('./chunk-4ZHTIJNE.cjs');
|
|
5
5
|
var chunkEG4QM7ZJ_cjs = require('./chunk-EG4QM7ZJ.cjs');
|
|
6
6
|
var async_hooks = require('async_hooks');
|
|
@@ -27,7 +27,7 @@ async function loadHookConfig(cwd) {
|
|
|
27
27
|
for (const path of hookConfigCandidates(cwd)) {
|
|
28
28
|
if (!fs.existsSync(path)) continue;
|
|
29
29
|
sawAny = true;
|
|
30
|
-
mergeInto(merged, await readHookFile(path));
|
|
30
|
+
mergeInto(merged, stampSource(await readHookFile(path), path));
|
|
31
31
|
}
|
|
32
32
|
if (!sawAny && fs.existsSync(path.join(cwd, ".theokit", "hooks"))) {
|
|
33
33
|
warnOnce(
|
|
@@ -38,13 +38,22 @@ async function loadHookConfig(cwd) {
|
|
|
38
38
|
return merged;
|
|
39
39
|
}
|
|
40
40
|
function hookConfigCandidates(cwd) {
|
|
41
|
-
const roots =
|
|
41
|
+
const roots = chunkAKJP2STZ_cjs.projectConfigRoots(cwd);
|
|
42
42
|
return [
|
|
43
43
|
...roots.map((root) => path.join(root, "hooks.json")),
|
|
44
44
|
...roots.map((root) => path.join(root, "settings.json")),
|
|
45
45
|
...roots.map((root) => path.join(root, "settings.local.json"))
|
|
46
46
|
];
|
|
47
47
|
}
|
|
48
|
+
function stampSource(config, sourcePath) {
|
|
49
|
+
if (config.hooks === void 0) return config;
|
|
50
|
+
const hooks = {};
|
|
51
|
+
for (const [event, commands] of Object.entries(config.hooks)) {
|
|
52
|
+
if (commands === void 0) continue;
|
|
53
|
+
hooks[event] = commands.map((c) => ({ sourcePath, ...c }));
|
|
54
|
+
}
|
|
55
|
+
return { hooks };
|
|
56
|
+
}
|
|
48
57
|
function mergeInto(target, source) {
|
|
49
58
|
for (const [event, commands] of Object.entries(source.hooks ?? {})) {
|
|
50
59
|
if (commands === void 0 || commands.length === 0) continue;
|
|
@@ -159,5 +168,5 @@ exports.loadHookConfig = loadHookConfig;
|
|
|
159
168
|
exports.warnOnce = warnOnce;
|
|
160
169
|
exports.warnPersonalitySwitchInsideFork = warnPersonalitySwitchInsideFork;
|
|
161
170
|
exports.withPersonalityContext = withPersonalityContext;
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
163
|
-
//# sourceMappingURL=chunk-
|
|
171
|
+
//# sourceMappingURL=chunk-VCLBZAZU.cjs.map
|
|
172
|
+
//# sourceMappingURL=chunk-VCLBZAZU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/runtime/hooks/hooks-source.ts","../src/internal/personality/context.ts"],"names":["diag","existsSync","join","projectConfigRoots","readFile","ConfigurationError","AsyncLocalStorage"],"mappings":";;;;;;;;;;AAiCA,IAAM,qBAAA,GAA6D;AAAA,EACjE,UAAA,EAAY,YAAA;AAAA,EACZ,WAAA,EAAa,aAAA;AAAA,EACb,gBAAA,EAAkB,QAAA;AAAA,EAClB,IAAA,EAAM;AACR,CAAA;AAqBA,IAAM,MAAA,uBAAa,GAAA,EAAY;AAYxB,SAAS,QAAA,CAAS,KAAa,OAAA,EAAuB;AAC3D,EAAA,IAAI,MAAA,CAAO,GAAA,CAAI,GAAG,CAAA,EAAG;AACrB,EAAA,MAAA,CAAO,IAAI,GAAG,CAAA;AACd,EAAAA,sBAAA,CAAK,GAAG,OAAO;AAAA,CAAI,CAAA;AACrB;AAcA,eAAsB,eAAe,GAAA,EAAkC;AACrE,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,IAAA,IAAQ,oBAAA,CAAqB,GAAG,CAAA,EAAG;AAC5C,IAAA,IAAI,CAACC,aAAA,CAAW,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I,CAAA,CAAA;AAAA,MAC3F,EAAE,MAAM,wBAAA;AAAyB,KACnC;AAAA,EACF;AACA,EAAA,IAAI,OAAO,GAAA,CAAI,OAAA,KAAY,YAAY,GAAA,CAAI,OAAA,CAAQ,WAAW,CAAA,EAAG;AAC/D,IAAA,MAAM,IAAIA,oCAAA,CAAmB,CAAA,+CAAA,EAAkD,IAAI,CAAA,CAAA,EAAI;AAAA,MACrF,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA,EAAA,MAAM,EAAA,GAAkB,EAAE,OAAA,EAAS,GAAA,CAAI,OAAA,EAAQ;AAC/C,EAAA,IAAI,OAAA,KAAY,MAAA,EAAW,EAAA,CAAG,OAAA,GAAU,OAAA;AACxC,EAAA,IAAI,OAAO,GAAA,CAAI,OAAA,KAAY,QAAA,IAAY,GAAA,CAAI,UAAU,CAAA,EAAG;AACtD,IAAA,EAAA,CAAG,SAAA,GAAY,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,UAAU,GAAI,CAAA;AAAA,EAC9C;AACA,EAAA,OAAO,EAAA;AACT;;;ACjPA,IAAM,OAAA,GAAU,IAAIC,6BAAA,EAA0C;AAQvD,SAAS,sBAAA,CACd,KACA,EAAA,EACY;AACZ,EAAA,OAAO,OAAA,CAAQ,GAAA,CAAI,GAAA,EAAK,EAAE,CAAA;AAC5B;AAQO,SAAS,yBAAA,GAAgE;AAC9E,EAAA,OAAO,QAAQ,QAAA,EAAS;AAC1B;AASO,SAAS,gCAAgC,OAAA,EAAuB;AACrE,EAAA,QAAA;AAAA,IACE,8BAA8B,OAAO,CAAA,CAAA;AAAA,IACrC,CAAA,0IAAA;AAAA,GACF;AACF","file":"chunk-VCLBZAZU.cjs","sourcesContent":["/**\n * Single source of truth for loading the hooks config (ADR 0016 — reverses\n * D74/D77 for hooks: JSON is canonical again, in the Claude Code shape).\n *\n * `.theokit/hooks.json` (Claude-Code-shaped JSON) is the only supported form.\n * A stray legacy `.theokit/hooks/*.md` dir (no hooks.json) is NOT loaded — it\n * warns to migrate and yields no hooks. Absent both → empty config.\n *\n * Consumed by `hooks-executor.ts` (runtime dispatch).\n *\n * Config shape (identical to Claude Code's `settings.json` hooks):\n * { \"hooks\": { \"PreToolUse\": [ { \"matcher\": \"shell\",\n * \"hooks\": [ { \"type\": \"command\", \"command\": \"…\", \"timeout\": 30 } ] } ] } }\n *\n * @internal\n */\n\nimport { existsSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { ConfigurationError } from \"../../../errors.js\";\nimport { diag } from \"../../diagnostics.js\";\nimport { projectConfigRoots } from \"../../persistence/paths.js\";\n\n/** The five lifecycle events the SDK runtime actually fires. */\nexport type HookEvent = \"preRun\" | \"postRun\" | \"preToolUse\" | \"postToolUse\" | \"stop\";\n\n/**\n * Claude Code event name → the SDK firing event. Only events the runtime\n * genuinely emits are mapped; a Claude Code event with no SDK firing point\n * (SessionStart / SubagentStop / PreCompact / Notification / SessionEnd) is\n * skipped with a warn rather than silently accepted (it would never run).\n */\nconst CLAUDE_CODE_EVENT_MAP: Readonly<Record<string, HookEvent>> = {\n PreToolUse: \"preToolUse\",\n PostToolUse: \"postToolUse\",\n UserPromptSubmit: \"preRun\",\n Stop: \"stop\",\n};\n\nexport interface HookCommand {\n command: string;\n matcher?: string;\n timeoutMs?: number;\n /**\n * The config file this command was declared in.\n *\n * Carried so the executor can supply the runtime contract the declaring DIALECT presumes — a\n * command from `.claude/settings.json` is written against Claude Code's runtime and expects\n * `$CLAUDE_PROJECT_DIR` to exist (#522). Absent for a command built in memory, which is native by\n * construction.\n */\n sourcePath?: string;\n}\n\nexport interface HookConfig {\n hooks?: Partial<Record<HookEvent, HookCommand[]>>;\n}\n\nconst warned = new Set<string>();\n\n/**\n * Emit a stderr warn once per process per unique key. Helps surface the\n * deprecation path without spamming when the loader is called many times\n * during a session (cron + send + skills all hit this).\n *\n * Note: spawned workers (cron, subagent) start fresh processes — warn\n * re-emits there, by design (1 per process boot, not per call).\n *\n * @internal\n */\nexport function warnOnce(key: string, message: string): void {\n if (warned.has(key)) return;\n warned.add(key);\n diag(`${message}\\n`);\n}\n\n/** Reset for tests; not exported via barrel. @internal */\nexport function _resetWarnOnceForTests(): void {\n warned.clear();\n}\n\n/**\n * Load hooks from `.theokit/hooks.json` (Claude-Code-shaped — the only supported\n * form). A stray legacy `.theokit/hooks/*.md` markdown dir (no `hooks.json`) is\n * NOT loaded — it emits a one-time migration warn and yields no hooks.\n *\n * @internal\n */\nexport async function loadHookConfig(cwd: string): Promise<HookConfig> {\n const merged: HookConfig = {};\n let sawAny = false;\n for (const path of hookConfigCandidates(cwd)) {\n if (!existsSync(path)) continue;\n sawAny = true;\n // Stamped at merge, where the file is still known. One line later the commands are pooled per\n // event and every trace of which dialect declared them is gone — which is how a Claude Code\n // command came to be run without Claude Code's runtime (#522).\n mergeInto(merged, stampSource(await readHookFile(path), path));\n }\n if (!sawAny && existsSync(join(cwd, \".theokit\", \"hooks\"))) {\n warnOnce(\n \"hooks-md-unsupported\",\n \"[theokit-sdk] .theokit/hooks/*.md hooks are no longer supported (ADR 0016) — migrate to a Claude-Code-shaped .theokit/hooks.json\",\n );\n }\n return merged;\n}\n\n/**\n * Every file that may declare hooks, in precedence order.\n *\n * `hooks.json` under each project config root, then the Claude Code CLI's own settings files — which\n * is where the CLI actually keeps hooks, so a repository set up for it presents its hooks here\n * without being converted. `settings.local.json` is the CLI's personal-override file and sits beside\n * the shared one rather than replacing it.\n *\n * The shape never needed translating: `parseClaudeCodeConfig` reads the `hooks` key off whatever\n * object it is given, and a settings file is that same object with other keys alongside.\n */\nfunction hookConfigCandidates(cwd: string): string[] {\n const roots = projectConfigRoots(cwd);\n return [\n ...roots.map((root) => join(root, \"hooks.json\")),\n ...roots.map((root) => join(root, \"settings.json\")),\n ...roots.map((root) => join(root, \"settings.local.json\")),\n ];\n}\n\n/**\n * Record which file each command came from.\n *\n * A command already carrying a `sourcePath` keeps it: nothing produces that today, and a nested\n * config that declared its own origin would be describing something this function cannot see.\n */\nfunction stampSource(config: HookConfig, sourcePath: string): HookConfig {\n if (config.hooks === undefined) return config;\n const hooks: NonNullable<HookConfig[\"hooks\"]> = {};\n for (const [event, commands] of Object.entries(config.hooks) as [\n HookEvent,\n HookCommand[] | undefined,\n ][]) {\n if (commands === undefined) continue;\n hooks[event] = commands.map((c) => ({ sourcePath, ...c }));\n }\n return { hooks };\n}\n\n/**\n * Append one source's commands onto the accumulator, per event.\n *\n * MERGED, not first-wins, and the distinction is deliberate. An agent or a skill is a NAMED\n * declaration: two files claiming one name collide, and the explicit namespace should win. Hooks are\n * unnamed lists — two files declaring `PreToolUse` are two sets of commands an operator wrote, and\n * keeping only one drops the other in silence, which is the failure class this package guards\n * against everywhere else.\n */\nfunction mergeInto(target: HookConfig, source: HookConfig): void {\n for (const [event, commands] of Object.entries(source.hooks ?? {}) as [\n HookEvent,\n HookCommand[] | undefined,\n ][]) {\n if (commands === undefined || commands.length === 0) continue;\n target.hooks ??= {};\n target.hooks[event] = [...(target.hooks[event] ?? []), ...commands];\n }\n}\n\nasync function readHookFile(jsonPath: string): Promise<HookConfig> {\n let raw: string;\n try {\n raw = await readFile(jsonPath, \"utf8\");\n } catch (cause) {\n throw new ConfigurationError(`Failed to read hooks config: ${jsonPath}`, {\n code: \"hooks_read_error\",\n cause,\n });\n }\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (cause) {\n throw new ConfigurationError(`Invalid JSON in hooks config: ${jsonPath}`, {\n code: \"hooks_json_invalid\",\n cause,\n });\n }\n return parseClaudeCodeConfig(parsed, jsonPath);\n}\n\n/** Narrow an unknown to a record, or throw a typed config error. */\nfunction asRecord(value: unknown, path: string, where: string): Record<string, unknown> {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new ConfigurationError(`hooks: expected an object at ${where} in ${path}`, {\n code: \"hooks_json_invalid\",\n });\n }\n return value as Record<string, unknown>;\n}\n\n/** Narrow an unknown to an array, or throw a typed config error. */\nfunction asArray(value: unknown, path: string, where: string): unknown[] {\n if (!Array.isArray(value)) {\n throw new ConfigurationError(`hooks: expected an array at ${where} in ${path}`, {\n code: \"hooks_json_invalid\",\n });\n }\n return value;\n}\n\n/**\n * Parse Claude Code's nested hooks config into the SDK's flat internal shape:\n * `{ hooks: { PreToolUse: [{ matcher?, hooks: [{ type:\"command\", command, timeout? }] }] } }`\n * → `{ hooks: { preToolUse: [{ command, matcher?, timeoutMs? }] } }`. Each group's\n * `matcher` applies to every command it wraps; `timeout` (seconds) → `timeoutMs`.\n */\nfunction parseClaudeCodeConfig(raw: unknown, path: string): HookConfig {\n const root = asRecord(raw, path, \"the root\");\n if (root.hooks === undefined) return {};\n const hooksRec = asRecord(root.hooks, path, `\"hooks\"`);\n const grouped: Partial<Record<HookEvent, HookCommand[]>> = {};\n\n for (const [ccEvent, groups] of Object.entries(hooksRec)) {\n const event = CLAUDE_CODE_EVENT_MAP[ccEvent];\n if (event === undefined) {\n warnOnce(\n `hooks-event-${ccEvent}`,\n `[theokit-sdk] hooks: event \"${ccEvent}\" is not fired by the SDK runtime (supported: ${Object.keys(CLAUDE_CODE_EVENT_MAP).join(\", \")}) — skipping`,\n );\n continue;\n }\n grouped[event] = [...(grouped[event] ?? []), ...flattenEventGroups(groups, path, ccEvent)];\n }\n return { hooks: grouped };\n}\n\n/** Flatten one Claude Code event's matcher-groups into internal HookCommands. */\nfunction flattenEventGroups(groups: unknown, path: string, ccEvent: string): HookCommand[] {\n const commands: HookCommand[] = [];\n for (const rawGroup of asArray(groups, path, `hooks.${ccEvent}`)) {\n const group = asRecord(rawGroup, path, `hooks.${ccEvent}[]`);\n const matcher = group.matcher === undefined ? undefined : String(group.matcher);\n for (const rawCmd of asArray(group.hooks, path, `hooks.${ccEvent}[].hooks`)) {\n commands.push(parseClaudeCodeCommand(rawCmd, matcher, path, ccEvent));\n }\n }\n return commands;\n}\n\n/** One `{ type:\"command\", command, timeout? }` entry → an internal HookCommand. */\nfunction parseClaudeCodeCommand(\n raw: unknown,\n matcher: string | undefined,\n path: string,\n ccEvent: string,\n): HookCommand {\n const cmd = asRecord(raw, path, `hooks.${ccEvent}[].hooks[]`);\n if (cmd.type !== \"command\") {\n throw new ConfigurationError(\n `hooks: only { \"type\": \"command\" } is supported (got ${JSON.stringify(cmd.type)}) in ${path}`,\n { code: \"hooks_unsupported_type\" },\n );\n }\n if (typeof cmd.command !== \"string\" || cmd.command.length === 0) {\n throw new ConfigurationError(`hooks: \"command\" must be a non-empty string in ${path}`, {\n code: \"hooks_invalid_command\",\n });\n }\n const hc: HookCommand = { command: cmd.command };\n if (matcher !== undefined) hc.matcher = matcher;\n if (typeof cmd.timeout === \"number\" && cmd.timeout > 0) {\n hc.timeoutMs = Math.round(cmd.timeout * 1000);\n }\n return hc;\n}\n","/**\n * Personality fork-context (ADR D168 + EC-A snapshot semantic).\n *\n * Uses Node's `AsyncLocalStorage` so a fork's execution chain can know\n * that it is running inside a fork AND can see the slug that was active\n * on the parent **at fork-construction time**.\n *\n * **EC-A:** The slug stored here is captured ONCE at the wrap site\n * (`localAgentFork`) — passing `parentStore.active(parentAgentId)`\n * returns a primitive `string | undefined`, which is then frozen\n * inside the ALS context object. Subsequent `usePersonality` calls on\n * the parent do NOT mutate the fork's view, because the fork reads from\n * its own ALS frame, not from the parent's store.\n *\n * @internal\n */\n\nimport { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { warnOnce } from \"../runtime/hooks/hooks-source.js\";\n\n/**\n * Snapshot data carried into a fork's async context.\n *\n * @internal\n */\nexport interface PersonalityForkContext {\n /** Parent's active personality slug at fork-construction time. */\n readonly slug: string | undefined;\n /** Always `true` inside this scope (used by guards). */\n readonly isFork: true;\n}\n\nconst storage = new AsyncLocalStorage<PersonalityForkContext>();\n\n/**\n * Run `fn` with `ctx` bound as the active fork context. Nested calls\n * shadow the outer context (EC-22).\n *\n * @internal\n */\nexport function withPersonalityContext<T>(\n ctx: PersonalityForkContext,\n fn: () => Promise<T>,\n): Promise<T> {\n return storage.run(ctx, fn);\n}\n\n/**\n * Return the active fork context, or `undefined` when called outside a\n * fork scope.\n *\n * @internal\n */\nexport function currentPersonalityContext(): PersonalityForkContext | undefined {\n return storage.getStore();\n}\n\n/**\n * Emit one warning per agentId stating that personality switches inside\n * a fork are no-ops. The fork inherits the parent snapshot — runtime\n * mutation is intentionally rejected to keep fork voice deterministic.\n *\n * @internal\n */\nexport function warnPersonalitySwitchInsideFork(agentId: string): void {\n warnOnce(\n `personality-switch-in-fork-${agentId}`,\n `[theokit-sdk] usePersonality is a no-op inside a fork (D168). Subagents inherit the parent's active personality at fork-construction time.`,\n );\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkVCLBZAZU_cjs = require('./chunk-VCLBZAZU.cjs');
|
|
4
|
+
require('./chunk-AKJP2STZ.cjs');
|
|
5
5
|
require('./chunk-4ZHTIJNE.cjs');
|
|
6
6
|
require('./chunk-XL7Q7HB2.cjs');
|
|
7
7
|
require('./chunk-EG4QM7ZJ.cjs');
|
|
@@ -10,15 +10,15 @@ require('./chunk-EG4QM7ZJ.cjs');
|
|
|
10
10
|
|
|
11
11
|
Object.defineProperty(exports, "currentPersonalityContext", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkVCLBZAZU_cjs.currentPersonalityContext; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "warnPersonalitySwitchInsideFork", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkVCLBZAZU_cjs.warnPersonalitySwitchInsideFork; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "withPersonalityContext", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkVCLBZAZU_cjs.withPersonalityContext; }
|
|
22
22
|
});
|
|
23
|
-
//# sourceMappingURL=context-
|
|
24
|
-
//# sourceMappingURL=context-
|
|
23
|
+
//# sourceMappingURL=context-WFLTTMK3.cjs.map
|
|
24
|
+
//# sourceMappingURL=context-WFLTTMK3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"context-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"context-WFLTTMK3.cjs"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { currentPersonalityContext, warnPersonalitySwitchInsideFork, withPersonalityContext } from './chunk-NDGGJQTZ.js';
|
|
2
|
+
import './chunk-247ZTLNU.js';
|
|
3
|
+
import './chunk-ZZMZWBR6.js';
|
|
4
|
+
import './chunk-D4CUGAKZ.js';
|
|
5
|
+
import './chunk-XEQ3TM66.js';
|
|
6
|
+
//# sourceMappingURL=context-WI2DFG7V.js.map
|
|
7
|
+
//# sourceMappingURL=context-WI2DFG7V.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"context-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"context-WI2DFG7V.js"}
|
package/dist/cron.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
3
|
+
var chunkGMLBYDW4_cjs = require('./chunk-GMLBYDW4.cjs');
|
|
4
|
+
require('./chunk-7VT4P3Z4.cjs');
|
|
5
5
|
require('./chunk-3FFAEAUJ.cjs');
|
|
6
6
|
require('./chunk-RMWTPV3M.cjs');
|
|
7
7
|
require('./chunk-BUUUWQMB.cjs');
|
|
8
8
|
require('./chunk-VLVVJLDH.cjs');
|
|
9
|
-
require('./chunk-
|
|
9
|
+
require('./chunk-VCLBZAZU.cjs');
|
|
10
10
|
require('./chunk-BV2MWEMV.cjs');
|
|
11
11
|
require('./chunk-KQ7TS7WW.cjs');
|
|
12
12
|
require('./chunk-GHX4P3V2.cjs');
|
|
@@ -43,8 +43,8 @@ require('./chunk-UU36SHFY.cjs');
|
|
|
43
43
|
require('./chunk-ZF2LDKQQ.cjs');
|
|
44
44
|
require('./chunk-RFMBZPOW.cjs');
|
|
45
45
|
require('./chunk-UALX2J2Q.cjs');
|
|
46
|
-
require('./chunk-
|
|
47
|
-
require('./chunk-
|
|
46
|
+
require('./chunk-43ZQRWAP.cjs');
|
|
47
|
+
require('./chunk-AKJP2STZ.cjs');
|
|
48
48
|
require('./chunk-4CLOXP6H.cjs');
|
|
49
49
|
require('./chunk-DXGZ2NUG.cjs');
|
|
50
50
|
require('./chunk-3EE6LVWT.cjs');
|
|
@@ -61,7 +61,7 @@ require('./chunk-EG4QM7ZJ.cjs');
|
|
|
61
61
|
|
|
62
62
|
Object.defineProperty(exports, "Cron", {
|
|
63
63
|
enumerable: true,
|
|
64
|
-
get: function () { return
|
|
64
|
+
get: function () { return chunkGMLBYDW4_cjs.Cron; }
|
|
65
65
|
});
|
|
66
66
|
//# sourceMappingURL=cron.cjs.map
|
|
67
67
|
//# sourceMappingURL=cron.cjs.map
|
package/dist/cron.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { Cron } from './chunk-
|
|
2
|
-
import './chunk-
|
|
1
|
+
export { Cron } from './chunk-32WTYBUH.js';
|
|
2
|
+
import './chunk-LYTOXSRH.js';
|
|
3
3
|
import './chunk-A46SWMIF.js';
|
|
4
4
|
import './chunk-4FFBAUFS.js';
|
|
5
5
|
import './chunk-K2BQQ445.js';
|
|
6
6
|
import './chunk-L3MTL4NA.js';
|
|
7
|
-
import './chunk-
|
|
7
|
+
import './chunk-NDGGJQTZ.js';
|
|
8
8
|
import './chunk-2SFBB54R.js';
|
|
9
9
|
import './chunk-UBDMVMBZ.js';
|
|
10
10
|
import './chunk-H73MEMQB.js';
|
|
@@ -41,8 +41,8 @@ import './chunk-3O42QOMJ.js';
|
|
|
41
41
|
import './chunk-Q5EWJPRY.js';
|
|
42
42
|
import './chunk-KQRW2GPZ.js';
|
|
43
43
|
import './chunk-2GUYQR5P.js';
|
|
44
|
-
import './chunk-
|
|
45
|
-
import './chunk-
|
|
44
|
+
import './chunk-LKBEROHN.js';
|
|
45
|
+
import './chunk-247ZTLNU.js';
|
|
46
46
|
import './chunk-LXQ6HKPS.js';
|
|
47
47
|
import './chunk-A4JVILQU.js';
|
|
48
48
|
import './chunk-R7WIIPUR.js';
|
package/dist/eval.cjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkJ24VJOH3_cjs = require('./chunk-J24VJOH3.cjs');
|
|
4
|
-
var
|
|
4
|
+
var chunk7VT4P3Z4_cjs = require('./chunk-7VT4P3Z4.cjs');
|
|
5
5
|
require('./chunk-3FFAEAUJ.cjs');
|
|
6
6
|
require('./chunk-RMWTPV3M.cjs');
|
|
7
7
|
var chunkBUUUWQMB_cjs = require('./chunk-BUUUWQMB.cjs');
|
|
8
8
|
require('./chunk-VLVVJLDH.cjs');
|
|
9
|
-
require('./chunk-
|
|
9
|
+
require('./chunk-VCLBZAZU.cjs');
|
|
10
10
|
require('./chunk-BV2MWEMV.cjs');
|
|
11
11
|
require('./chunk-KQ7TS7WW.cjs');
|
|
12
12
|
require('./chunk-GHX4P3V2.cjs');
|
|
@@ -43,8 +43,8 @@ var chunkUU36SHFY_cjs = require('./chunk-UU36SHFY.cjs');
|
|
|
43
43
|
require('./chunk-ZF2LDKQQ.cjs');
|
|
44
44
|
require('./chunk-RFMBZPOW.cjs');
|
|
45
45
|
require('./chunk-UALX2J2Q.cjs');
|
|
46
|
-
require('./chunk-
|
|
47
|
-
require('./chunk-
|
|
46
|
+
require('./chunk-43ZQRWAP.cjs');
|
|
47
|
+
require('./chunk-AKJP2STZ.cjs');
|
|
48
48
|
require('./chunk-4CLOXP6H.cjs');
|
|
49
49
|
require('./chunk-DXGZ2NUG.cjs');
|
|
50
50
|
require('./chunk-3EE6LVWT.cjs');
|
|
@@ -784,7 +784,7 @@ function makeDefaultEmbedder(opts) {
|
|
|
784
784
|
let runtime;
|
|
785
785
|
return (texts) => {
|
|
786
786
|
if (runtime === void 0) {
|
|
787
|
-
runtime =
|
|
787
|
+
runtime = chunk7VT4P3Z4_cjs.openRouterMemoryEmbeddingProviderAdapter.create(embedderCreateOptions(opts));
|
|
788
788
|
}
|
|
789
789
|
return runtime.then((rt) => rt.embed(texts));
|
|
790
790
|
};
|
package/dist/eval.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { shellEscapePosix, LocalSandbox } from './chunk-2D34UTDC.js';
|
|
2
|
-
import { openRouterMemoryEmbeddingProviderAdapter } from './chunk-
|
|
2
|
+
import { openRouterMemoryEmbeddingProviderAdapter } from './chunk-LYTOXSRH.js';
|
|
3
3
|
import './chunk-A46SWMIF.js';
|
|
4
4
|
import './chunk-4FFBAUFS.js';
|
|
5
5
|
import { getTracer } from './chunk-K2BQQ445.js';
|
|
6
6
|
import './chunk-L3MTL4NA.js';
|
|
7
|
-
import './chunk-
|
|
7
|
+
import './chunk-NDGGJQTZ.js';
|
|
8
8
|
import './chunk-2SFBB54R.js';
|
|
9
9
|
import './chunk-UBDMVMBZ.js';
|
|
10
10
|
import './chunk-H73MEMQB.js';
|
|
@@ -42,8 +42,8 @@ export { JsonlParseError, loadJsonl } from './chunk-3O42QOMJ.js';
|
|
|
42
42
|
import './chunk-Q5EWJPRY.js';
|
|
43
43
|
import './chunk-KQRW2GPZ.js';
|
|
44
44
|
import './chunk-2GUYQR5P.js';
|
|
45
|
-
import './chunk-
|
|
46
|
-
import './chunk-
|
|
45
|
+
import './chunk-LKBEROHN.js';
|
|
46
|
+
import './chunk-247ZTLNU.js';
|
|
47
47
|
import './chunk-LXQ6HKPS.js';
|
|
48
48
|
import './chunk-A4JVILQU.js';
|
|
49
49
|
import './chunk-R7WIIPUR.js';
|
package/dist/index.cjs
CHANGED
|
@@ -9,13 +9,13 @@ require('./chunk-B4EOJWOY.cjs');
|
|
|
9
9
|
var chunkYML4ME27_cjs = require('./chunk-YML4ME27.cjs');
|
|
10
10
|
require('./chunk-WNO3C3N2.cjs');
|
|
11
11
|
require('./chunk-VTYY7XL5.cjs');
|
|
12
|
-
var
|
|
13
|
-
var
|
|
12
|
+
var chunkGMLBYDW4_cjs = require('./chunk-GMLBYDW4.cjs');
|
|
13
|
+
var chunk7VT4P3Z4_cjs = require('./chunk-7VT4P3Z4.cjs');
|
|
14
14
|
var chunk3FFAEAUJ_cjs = require('./chunk-3FFAEAUJ.cjs');
|
|
15
15
|
require('./chunk-RMWTPV3M.cjs');
|
|
16
16
|
require('./chunk-BUUUWQMB.cjs');
|
|
17
17
|
require('./chunk-VLVVJLDH.cjs');
|
|
18
|
-
require('./chunk-
|
|
18
|
+
require('./chunk-VCLBZAZU.cjs');
|
|
19
19
|
require('./chunk-BV2MWEMV.cjs');
|
|
20
20
|
require('./chunk-KQ7TS7WW.cjs');
|
|
21
21
|
require('./chunk-GHX4P3V2.cjs');
|
|
@@ -52,8 +52,8 @@ require('./chunk-UU36SHFY.cjs');
|
|
|
52
52
|
var chunkZF2LDKQQ_cjs = require('./chunk-ZF2LDKQQ.cjs');
|
|
53
53
|
var chunkRFMBZPOW_cjs = require('./chunk-RFMBZPOW.cjs');
|
|
54
54
|
var chunkUALX2J2Q_cjs = require('./chunk-UALX2J2Q.cjs');
|
|
55
|
-
require('./chunk-
|
|
56
|
-
require('./chunk-
|
|
55
|
+
require('./chunk-43ZQRWAP.cjs');
|
|
56
|
+
require('./chunk-AKJP2STZ.cjs');
|
|
57
57
|
require('./chunk-4CLOXP6H.cjs');
|
|
58
58
|
require('./chunk-DXGZ2NUG.cjs');
|
|
59
59
|
var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
|
|
@@ -73,8 +73,8 @@ var path = require('path');
|
|
|
73
73
|
// src/agent-factory.ts
|
|
74
74
|
function createAgentFactory(common) {
|
|
75
75
|
return {
|
|
76
|
-
forSession: (agentId, overrides) =>
|
|
77
|
-
getOrCreate: (agentId, overrides) =>
|
|
76
|
+
forSession: (agentId, overrides) => chunk7VT4P3Z4_cjs.Agent.create(mergeAgentOptions(common, overrides, agentId)),
|
|
77
|
+
getOrCreate: (agentId, overrides) => chunk7VT4P3Z4_cjs.Agent.getOrCreate(agentId, mergeAgentOptions(common, overrides, agentId))
|
|
78
78
|
};
|
|
79
79
|
}
|
|
80
80
|
function mergeAgentOptions(common, overrides, agentId) {
|
|
@@ -1266,7 +1266,7 @@ var Memory = {
|
|
|
1266
1266
|
return await peer.IndexManager.open(openArgs);
|
|
1267
1267
|
}
|
|
1268
1268
|
const { IndexManager } = await import('./index-manager-2SRX45WJ.cjs');
|
|
1269
|
-
openArgs.embedding = await resolveEmbedding(opts.embedding,
|
|
1269
|
+
openArgs.embedding = await resolveEmbedding(opts.embedding, chunk7VT4P3Z4_cjs.MEMORY_EMBEDDING_ADAPTERS);
|
|
1270
1270
|
return await IndexManager.open(openArgs);
|
|
1271
1271
|
},
|
|
1272
1272
|
/**
|
|
@@ -1277,7 +1277,7 @@ var Memory = {
|
|
|
1277
1277
|
*/
|
|
1278
1278
|
async runDreamingSweep(opts) {
|
|
1279
1279
|
const peer = await tryLoadSdkMemoryPeer();
|
|
1280
|
-
const catalog = peer !== null ? peer.MEMORY_EMBEDDING_ADAPTERS :
|
|
1280
|
+
const catalog = peer !== null ? peer.MEMORY_EMBEDDING_ADAPTERS : chunk7VT4P3Z4_cjs.MEMORY_EMBEDDING_ADAPTERS;
|
|
1281
1281
|
const sweepArgs = await buildDreamingSweepArgs(opts, catalog);
|
|
1282
1282
|
const result = peer !== null ? (
|
|
1283
1283
|
// biome-ignore lint/suspicious/noExplicitAny: peer is dynamically loaded — structural compat ensured by sdk-memory
|
|
@@ -1701,7 +1701,7 @@ function isBuiltAgent(m) {
|
|
|
1701
1701
|
return typeof m.send === "function";
|
|
1702
1702
|
}
|
|
1703
1703
|
async function materialize(def, index) {
|
|
1704
|
-
const { Agent: Agent2 } = await import('./agent-
|
|
1704
|
+
const { Agent: Agent2 } = await import('./agent-UX7WFI6B.cjs');
|
|
1705
1705
|
return Agent2.create({
|
|
1706
1706
|
// `AgentDefinition.model` admits the sentinel `'inherit'`, which is not a model id. Inheriting
|
|
1707
1707
|
// here means "declare nothing and let the default apply" — forwarding the literal would create
|
|
@@ -1843,7 +1843,7 @@ var FIXTURE_USER = {
|
|
|
1843
1843
|
};
|
|
1844
1844
|
var FIXTURE_MODELS = [
|
|
1845
1845
|
{
|
|
1846
|
-
id:
|
|
1846
|
+
id: chunk7VT4P3Z4_cjs.DEFAULT_AGENTIC_MODEL_ID,
|
|
1847
1847
|
name: "Gemini 2.0 Flash",
|
|
1848
1848
|
displayName: "Gemini 2.0 Flash",
|
|
1849
1849
|
parameters: [
|
|
@@ -2046,7 +2046,7 @@ var Theokit = class {
|
|
|
2046
2046
|
envVars: p.envVars
|
|
2047
2047
|
}));
|
|
2048
2048
|
},
|
|
2049
|
-
embeddingAdapters: () => Object.entries(
|
|
2049
|
+
embeddingAdapters: () => Object.entries(chunk7VT4P3Z4_cjs.MEMORY_EMBEDDING_ADAPTERS).map(([id, adapter]) => ({
|
|
2050
2050
|
id,
|
|
2051
2051
|
transport: adapter.transport,
|
|
2052
2052
|
defaultModel: adapter.defaultModel
|
|
@@ -2265,35 +2265,35 @@ Object.defineProperty(exports, "fn", {
|
|
|
2265
2265
|
});
|
|
2266
2266
|
Object.defineProperty(exports, "Cron", {
|
|
2267
2267
|
enumerable: true,
|
|
2268
|
-
get: function () { return
|
|
2268
|
+
get: function () { return chunkGMLBYDW4_cjs.Cron; }
|
|
2269
2269
|
});
|
|
2270
2270
|
Object.defineProperty(exports, "Agent", {
|
|
2271
2271
|
enumerable: true,
|
|
2272
|
-
get: function () { return
|
|
2272
|
+
get: function () { return chunk7VT4P3Z4_cjs.Agent; }
|
|
2273
2273
|
});
|
|
2274
2274
|
Object.defineProperty(exports, "AgentBuilder", {
|
|
2275
2275
|
enumerable: true,
|
|
2276
|
-
get: function () { return
|
|
2276
|
+
get: function () { return chunk7VT4P3Z4_cjs.AgentBuilder; }
|
|
2277
2277
|
});
|
|
2278
2278
|
Object.defineProperty(exports, "Tool", {
|
|
2279
2279
|
enumerable: true,
|
|
2280
|
-
get: function () { return
|
|
2280
|
+
get: function () { return chunk7VT4P3Z4_cjs.Tool; }
|
|
2281
2281
|
});
|
|
2282
2282
|
Object.defineProperty(exports, "ToolError", {
|
|
2283
2283
|
enumerable: true,
|
|
2284
|
-
get: function () { return
|
|
2284
|
+
get: function () { return chunk7VT4P3Z4_cjs.ToolError; }
|
|
2285
2285
|
});
|
|
2286
2286
|
Object.defineProperty(exports, "UsageAccumulator", {
|
|
2287
2287
|
enumerable: true,
|
|
2288
|
-
get: function () { return
|
|
2288
|
+
get: function () { return chunk7VT4P3Z4_cjs.UsageAccumulator; }
|
|
2289
2289
|
});
|
|
2290
2290
|
Object.defineProperty(exports, "computeCost", {
|
|
2291
2291
|
enumerable: true,
|
|
2292
|
-
get: function () { return
|
|
2292
|
+
get: function () { return chunk7VT4P3Z4_cjs.computeCost; }
|
|
2293
2293
|
});
|
|
2294
2294
|
Object.defineProperty(exports, "getPricingEntry", {
|
|
2295
2295
|
enumerable: true,
|
|
2296
|
-
get: function () { return
|
|
2296
|
+
get: function () { return chunk7VT4P3Z4_cjs.getPricingEntry; }
|
|
2297
2297
|
});
|
|
2298
2298
|
Object.defineProperty(exports, "emitRunEvent", {
|
|
2299
2299
|
enumerable: true,
|
package/dist/index.js
CHANGED
|
@@ -8,15 +8,15 @@ import { Workflow, agentStep } from './chunk-OSEG74VJ.js';
|
|
|
8
8
|
export { Workflow, agentStep, fn } from './chunk-OSEG74VJ.js';
|
|
9
9
|
import './chunk-BZRFXJHA.js';
|
|
10
10
|
import './chunk-HY66GLM6.js';
|
|
11
|
-
export { Cron } from './chunk-
|
|
12
|
-
import { MEMORY_EMBEDDING_ADAPTERS, DEFAULT_AGENTIC_MODEL_ID, Agent } from './chunk-
|
|
13
|
-
export { Agent, AgentBuilder, Tool, ToolError, UsageAccumulator, computeCost, getPricingEntry } from './chunk-
|
|
11
|
+
export { Cron } from './chunk-32WTYBUH.js';
|
|
12
|
+
import { MEMORY_EMBEDDING_ADAPTERS, DEFAULT_AGENTIC_MODEL_ID, Agent } from './chunk-LYTOXSRH.js';
|
|
13
|
+
export { Agent, AgentBuilder, Tool, ToolError, UsageAccumulator, computeCost, getPricingEntry } from './chunk-LYTOXSRH.js';
|
|
14
14
|
import { configure, submit, list, get, cancel, subscribe } from './chunk-A46SWMIF.js';
|
|
15
15
|
export { emitRunEvent } from './chunk-A46SWMIF.js';
|
|
16
16
|
import './chunk-4FFBAUFS.js';
|
|
17
17
|
import './chunk-K2BQQ445.js';
|
|
18
18
|
import './chunk-L3MTL4NA.js';
|
|
19
|
-
import './chunk-
|
|
19
|
+
import './chunk-NDGGJQTZ.js';
|
|
20
20
|
import './chunk-2SFBB54R.js';
|
|
21
21
|
import './chunk-UBDMVMBZ.js';
|
|
22
22
|
import './chunk-H73MEMQB.js';
|
|
@@ -54,8 +54,8 @@ import { withCwdMutex } from './chunk-Q5EWJPRY.js';
|
|
|
54
54
|
export { withCwdMutex } from './chunk-Q5EWJPRY.js';
|
|
55
55
|
export { TASK_RESERVED_PREFIXES, isValidTaskId } from './chunk-KQRW2GPZ.js';
|
|
56
56
|
import { replaceFileAtomic } from './chunk-2GUYQR5P.js';
|
|
57
|
-
import './chunk-
|
|
58
|
-
import './chunk-
|
|
57
|
+
import './chunk-LKBEROHN.js';
|
|
58
|
+
import './chunk-247ZTLNU.js';
|
|
59
59
|
import './chunk-LXQ6HKPS.js';
|
|
60
60
|
import './chunk-A4JVILQU.js';
|
|
61
61
|
import { parseModelId } from './chunk-R7WIIPUR.js';
|
|
@@ -1705,7 +1705,7 @@ function isBuiltAgent(m) {
|
|
|
1705
1705
|
return typeof m.send === "function";
|
|
1706
1706
|
}
|
|
1707
1707
|
async function materialize(def, index) {
|
|
1708
|
-
const { Agent: Agent2 } = await import('./agent-
|
|
1708
|
+
const { Agent: Agent2 } = await import('./agent-A5XMIVNP.js');
|
|
1709
1709
|
return Agent2.create({
|
|
1710
1710
|
// `AgentDefinition.model` admits the sentinel `'inherit'`, which is not a model id. Inheriting
|
|
1711
1711
|
// here means "declare nothing and let the default apply" — forwarding the literal would create
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { SessionMessage } from "../../types/session-message.js";
|
|
2
|
+
import type { LlmMessage } from "../llm/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rebuild the model's history from a session's stored turns.
|
|
5
|
+
*
|
|
6
|
+
* ## Why this exists
|
|
7
|
+
*
|
|
8
|
+
* The replay used to be one line — `content: [{ type: "text", text: msg.text }]` — and `text` is the
|
|
9
|
+
* FLAT projection, in which a tool call folds to `[tool call] NAME` and a result to
|
|
10
|
+
* `[tool result] <body>`. So a resumed session showed the model its own prior turn as prose
|
|
11
|
+
* containing a marker, and the model did the reasonable thing with a pattern it is shown: it wrote
|
|
12
|
+
* the marker instead of calling the tool (usetheokit/theokit#631). A consumer saw
|
|
13
|
+
* `"…report its output.[tool call] run_shell"` in the assistant's reply, with no tool call behind it.
|
|
14
|
+
*
|
|
15
|
+
* The structured projection was already there. `narrowToSessionMessage` returns BOTH `text` and
|
|
16
|
+
* `parts`, and `parts` carries the call id, the tool name and the arguments — everything the flat
|
|
17
|
+
* form destroys. Nothing read it: `msg.parts` appeared nowhere in the shipped bundle.
|
|
18
|
+
*
|
|
19
|
+
* ## The shape it produces
|
|
20
|
+
*
|
|
21
|
+
* `SessionMessagePart` and `LlmContentPart` agree field for field on all three cases, which is what
|
|
22
|
+
* makes this a mapping rather than a translation. What does NOT carry over is the grouping: a
|
|
23
|
+
* `tool_result` may not travel in an assistant message. The live loop already settles that —
|
|
24
|
+
* `loop.ts` pushes results as `{ role: "user", content: toolResults }` — so a replayed turn is split
|
|
25
|
+
* the same way rather than inventing a second convention for the same provider wire.
|
|
26
|
+
*
|
|
27
|
+
* ## When it falls back
|
|
28
|
+
*
|
|
29
|
+
* `parts` is optional and its absence means "this projection carries no structure", never "this turn
|
|
30
|
+
* had none" — a `SessionMessage` built in memory during a live turn has only `text`. So a message
|
|
31
|
+
* without parts replays exactly as before. That is also what keeps this safe for a session stored by
|
|
32
|
+
* an older SDK: those rows have no `parts`, and they keep the behaviour they were written under.
|
|
33
|
+
*
|
|
34
|
+
* ## An empty text part is dropped
|
|
35
|
+
*
|
|
36
|
+
* A `{ type: "text", text: "" }` survives the projection — a turn that was only a tool call has one,
|
|
37
|
+
* because `partToText` folds the call and leaves the text empty. Several provider wires reject an
|
|
38
|
+
* empty text block outright, and none of them need it, so it does not travel. Dropping it is also
|
|
39
|
+
* what makes the `own.length > 0` guard below meaningful rather than incidental.
|
|
40
|
+
*/
|
|
41
|
+
export declare function replayMessages(prior: readonly SessionMessage[]): LlmMessage[];
|
|
@@ -7,7 +7,7 @@ var chunk5VB22SYX_cjs = require('../../chunk-5VB22SYX.cjs');
|
|
|
7
7
|
var chunkUU36SHFY_cjs = require('../../chunk-UU36SHFY.cjs');
|
|
8
8
|
var chunkZF2LDKQQ_cjs = require('../../chunk-ZF2LDKQQ.cjs');
|
|
9
9
|
var chunkUALX2J2Q_cjs = require('../../chunk-UALX2J2Q.cjs');
|
|
10
|
-
var
|
|
10
|
+
var chunkAKJP2STZ_cjs = require('../../chunk-AKJP2STZ.cjs');
|
|
11
11
|
require('../../chunk-4ZHTIJNE.cjs');
|
|
12
12
|
require('../../chunk-XL7Q7HB2.cjs');
|
|
13
13
|
require('../../chunk-EG4QM7ZJ.cjs');
|
|
@@ -112,15 +112,15 @@ Object.defineProperty(exports, "replaceFileAtomic", {
|
|
|
112
112
|
});
|
|
113
113
|
Object.defineProperty(exports, "displayTheokitHome", {
|
|
114
114
|
enumerable: true,
|
|
115
|
-
get: function () { return
|
|
115
|
+
get: function () { return chunkAKJP2STZ_cjs.displayTheokitHome; }
|
|
116
116
|
});
|
|
117
117
|
Object.defineProperty(exports, "getProfilesRoot", {
|
|
118
118
|
enumerable: true,
|
|
119
|
-
get: function () { return
|
|
119
|
+
get: function () { return chunkAKJP2STZ_cjs.getProfilesRoot; }
|
|
120
120
|
});
|
|
121
121
|
Object.defineProperty(exports, "getTheokitHome", {
|
|
122
122
|
enumerable: true,
|
|
123
|
-
get: function () { return
|
|
123
|
+
get: function () { return chunkAKJP2STZ_cjs.getTheokitHome; }
|
|
124
124
|
});
|
|
125
125
|
exports.casUpdate = casUpdate;
|
|
126
126
|
exports.createExclusive = createExclusive;
|
|
@@ -5,7 +5,7 @@ export { applyWalWithFallback, isCorruptionError, openSqliteResilient } from '..
|
|
|
5
5
|
export { JsonlParseError, appendJsonl, loadJsonl, readJsonlIds, withFileLock } from '../../chunk-3O42QOMJ.js';
|
|
6
6
|
export { withCwdMutex } from '../../chunk-Q5EWJPRY.js';
|
|
7
7
|
export { atomicWriteJson, atomicWriteText, replaceFileAtomic } from '../../chunk-2GUYQR5P.js';
|
|
8
|
-
export { displayTheokitHome, getProfilesRoot, getTheokitHome } from '../../chunk-
|
|
8
|
+
export { displayTheokitHome, getProfilesRoot, getTheokitHome } from '../../chunk-247ZTLNU.js';
|
|
9
9
|
import '../../chunk-ZZMZWBR6.js';
|
|
10
10
|
import '../../chunk-D4CUGAKZ.js';
|
|
11
11
|
import '../../chunk-XEQ3TM66.js';
|