@theokit/sdk 5.1.0 → 5.2.1
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 +122 -0
- package/dist/{agent-ARLOD4JX.cjs → agent-GACKKINM.cjs} +7 -7
- package/dist/{agent-ARLOD4JX.cjs.map → agent-GACKKINM.cjs.map} +1 -1
- package/dist/{agent-N6WJ54ML.js → agent-VUNM33WJ.js} +6 -6
- package/dist/{agent-N6WJ54ML.js.map → agent-VUNM33WJ.js.map} +1 -1
- package/dist/{chunk-OYD3U3LY.js → chunk-43H4EBS2.js} +7 -7
- package/dist/{chunk-OYD3U3LY.js.map → chunk-43H4EBS2.js.map} +1 -1
- package/dist/{chunk-AW6F6HZR.js → chunk-AI4MXACC.js} +3 -3
- package/dist/{chunk-AW6F6HZR.js.map → chunk-AI4MXACC.js.map} +1 -1
- package/dist/{chunk-D3CCY3A2.cjs → chunk-DEJCKB65.cjs} +39 -39
- package/dist/{chunk-D3CCY3A2.cjs.map → chunk-DEJCKB65.cjs.map} +1 -1
- package/dist/{chunk-OQRGVTQF.js → chunk-DLFWMJE3.js} +3 -3
- package/dist/{chunk-OQRGVTQF.js.map → chunk-DLFWMJE3.js.map} +1 -1
- package/dist/{chunk-NYQ3IS7K.cjs → chunk-DWB3CN46.cjs} +8 -3
- package/dist/chunk-DWB3CN46.cjs.map +1 -0
- package/dist/{chunk-QYLZQ43D.cjs → chunk-IQBDR5YZ.cjs} +5 -5
- package/dist/{chunk-QYLZQ43D.cjs.map → chunk-IQBDR5YZ.cjs.map} +1 -1
- package/dist/{chunk-67SBTGMA.cjs → chunk-PEAOQMWE.cjs} +4 -4
- package/dist/{chunk-67SBTGMA.cjs.map → chunk-PEAOQMWE.cjs.map} +1 -1
- package/dist/{chunk-WMWEI3NS.js → chunk-RP3VXJMA.js} +8 -3
- package/dist/chunk-RP3VXJMA.js.map +1 -0
- package/dist/{chunk-KGANQYP7.cjs → chunk-SSIRPWWD.cjs} +5 -5
- package/dist/{chunk-KGANQYP7.cjs.map → chunk-SSIRPWWD.cjs.map} +1 -1
- package/dist/{chunk-XU6MLSC6.js → chunk-WHTMFN4Q.js} +3 -3
- package/dist/{chunk-XU6MLSC6.js.map → chunk-WHTMFN4Q.js.map} +1 -1
- package/dist/{context-4QOEWRDF.cjs → context-3YMZDEX5.cjs} +7 -7
- package/dist/{context-4QOEWRDF.cjs.map → context-3YMZDEX5.cjs.map} +1 -1
- package/dist/context-XNREEC7M.js +6 -0
- package/dist/{context-Z3CFTT3H.js.map → context-XNREEC7M.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 +64 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -1
- package/dist/index.d.ts +66 -1
- package/dist/index.js +51 -9
- package/dist/index.js.map +1 -1
- 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 +16 -6
- package/dist/subagents-loader-7G76XOZU.cjs +16 -0
- package/dist/{subagents-loader-GEHYCMEX.cjs.map → subagents-loader-7G76XOZU.cjs.map} +1 -1
- package/dist/subagents-loader-PAZVOZHI.js +7 -0
- package/dist/{subagents-loader-DOBTTICM.js.map → subagents-loader-PAZVOZHI.js.map} +1 -1
- package/dist/subagents-loader.cjs +3 -3
- package/dist/subagents-loader.js +2 -2
- package/docs/error-codes.md +2 -1
- package/docs/harness-capability-map.md +4 -1
- package/package.json +1 -1
- package/dist/chunk-NYQ3IS7K.cjs.map +0 -1
- package/dist/chunk-WMWEI3NS.js.map +0 -1
- package/dist/context-Z3CFTT3H.js +0 -6
- package/dist/subagents-loader-DOBTTICM.js +0 -7
- package/dist/subagents-loader-GEHYCMEX.cjs +0 -16
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { theokitConfigRoot, projectConfigRoots } from './chunk-
|
|
1
|
+
import { theokitConfigRoot, projectConfigRoots } from './chunk-RP3VXJMA.js';
|
|
2
2
|
import { ConfigurationError } from './chunk-ALUN2B4W.js';
|
|
3
3
|
import { diag } from './chunk-CZJ6Q7CW.js';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
@@ -162,5 +162,5 @@ function warnPersonalitySwitchInsideFork(agentId) {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
export { currentPersonalityContext, loadHookConfig, warnOnce, warnPersonalitySwitchInsideFork, withPersonalityContext };
|
|
165
|
-
//# sourceMappingURL=chunk-
|
|
166
|
-
//# sourceMappingURL=chunk-
|
|
165
|
+
//# sourceMappingURL=chunk-AI4MXACC.js.map
|
|
166
|
+
//# sourceMappingURL=chunk-AI4MXACC.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internal/runtime/hooks/hooks-source.ts","../src/internal/personality/context.ts"],"names":[],"mappings":";;;;;;;;AAkCA,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,cAAA,CACpB,GAAA,EACA,aAAA,GAAoD,EAAC,EAChC;AACrB,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,IAAI,MAAA,GAAS,KAAA;AACb,EAAA,KAAA,MAAW,IAAA,IAAQ,oBAAA,CAAqB,GAAA,EAAK,aAAa,CAAA,EAAG;AAC3D,IAA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uDAAuD,IAAA,CAAK,SAAA,CAAU,IAAI,IAAI,CAAC,QAAQ,IAAI,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,IAAI,kBAAA,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;;;ACxPA,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-AW6F6HZR.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, theokitConfigRoot } from \"../../persistence/paths.js\";\nimport type { CompatSourceDeclaration } from \"../compat/foreign-config-sources.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(\n cwd: string,\n compatSources: readonly CompatSourceDeclaration[] = [],\n): Promise<HookConfig> {\n const merged: HookConfig = {};\n let sawAny = false;\n for (const path of hookConfigCandidates(cwd, compatSources)) {\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(theokitConfigRoot(cwd), \"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(\n cwd: string,\n compatSources: readonly CompatSourceDeclaration[],\n): string[] {\n const roots = projectConfigRoots(cwd, compatSources, \"hooks\");\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
|
+
{"version":3,"sources":["../src/internal/runtime/hooks/hooks-source.ts","../src/internal/personality/context.ts"],"names":[],"mappings":";;;;;;;;AAkCA,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,cAAA,CACpB,GAAA,EACA,aAAA,GAAoD,EAAC,EAChC;AACrB,EAAA,MAAM,SAAqB,EAAC;AAC5B,EAAA,IAAI,MAAA,GAAS,KAA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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, theokitConfigRoot } from \"../../persistence/paths.js\";\nimport type { CompatSourceDeclaration } from \"../compat/foreign-config-sources.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(\n cwd: string,\n compatSources: readonly CompatSourceDeclaration[] = [],\n): Promise<HookConfig> {\n const merged: HookConfig = {};\n let sawAny = false;\n for (const path of hookConfigCandidates(cwd, compatSources)) {\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(theokitConfigRoot(cwd), \"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(\n cwd: string,\n compatSources: readonly CompatSourceDeclaration[],\n): string[] {\n const roots = projectConfigRoots(cwd, compatSources, \"hooks\");\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"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var chunkKVSAY6NZ_cjs = require('./chunk-KVSAY6NZ.cjs');
|
|
4
4
|
var chunkY2KYR2ED_cjs = require('./chunk-Y2KYR2ED.cjs');
|
|
5
5
|
var chunkZ2JFX372_cjs = require('./chunk-Z2JFX372.cjs');
|
|
6
|
-
var
|
|
6
|
+
var chunkSSIRPWWD_cjs = require('./chunk-SSIRPWWD.cjs');
|
|
7
7
|
var chunkBV2MWEMV_cjs = require('./chunk-BV2MWEMV.cjs');
|
|
8
8
|
var chunkD6POWE7E_cjs = require('./chunk-D6POWE7E.cjs');
|
|
9
9
|
var chunkTMKTSYDS_cjs = require('./chunk-TMKTSYDS.cjs');
|
|
@@ -26,8 +26,8 @@ var chunkGZV6AVRL_cjs = require('./chunk-GZV6AVRL.cjs');
|
|
|
26
26
|
var chunkBJUJT5ED_cjs = require('./chunk-BJUJT5ED.cjs');
|
|
27
27
|
var chunkZF2LDKQQ_cjs = require('./chunk-ZF2LDKQQ.cjs');
|
|
28
28
|
var chunkJLRLCBJ4_cjs = require('./chunk-JLRLCBJ4.cjs');
|
|
29
|
-
var
|
|
30
|
-
var
|
|
29
|
+
var chunkIQBDR5YZ_cjs = require('./chunk-IQBDR5YZ.cjs');
|
|
30
|
+
var chunkDWB3CN46_cjs = require('./chunk-DWB3CN46.cjs');
|
|
31
31
|
var chunkHW7SEELD_cjs = require('./chunk-HW7SEELD.cjs');
|
|
32
32
|
var chunkATT276RD_cjs = require('./chunk-ATT276RD.cjs');
|
|
33
33
|
var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
|
|
@@ -383,7 +383,7 @@ function serializeAgents(agents2) {
|
|
|
383
383
|
return out;
|
|
384
384
|
}
|
|
385
385
|
function registryPath(cwd) {
|
|
386
|
-
return path.join(
|
|
386
|
+
return path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), REGISTRY_RELATIVE_SUFFIX);
|
|
387
387
|
}
|
|
388
388
|
async function loadRegistry(cwd) {
|
|
389
389
|
void chunkJLRLCBJ4_cjs.sweepStaleAtomicTemps(registryPath(cwd)).catch(() => void 0);
|
|
@@ -2122,14 +2122,14 @@ async function readState(filePath) {
|
|
|
2122
2122
|
try {
|
|
2123
2123
|
parsed = JSON.parse(raw);
|
|
2124
2124
|
} catch {
|
|
2125
|
-
|
|
2125
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
2126
2126
|
"personality-store-json-parse",
|
|
2127
2127
|
"[theokit-sdk] personality.json is malformed; treating as empty"
|
|
2128
2128
|
);
|
|
2129
2129
|
return emptyState();
|
|
2130
2130
|
}
|
|
2131
2131
|
if (!isStateV1(parsed)) {
|
|
2132
|
-
|
|
2132
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
2133
2133
|
"personality-store-bad-version",
|
|
2134
2134
|
`[theokit-sdk] personality.json has unknown version; treating as empty (file kept untouched)`
|
|
2135
2135
|
);
|
|
@@ -2160,7 +2160,7 @@ var PersonalityStore = class {
|
|
|
2160
2160
|
try {
|
|
2161
2161
|
await this.#persist(agentId, slug);
|
|
2162
2162
|
} catch (err) {
|
|
2163
|
-
|
|
2163
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
2164
2164
|
`personality-store-persist-failure-${agentId}`,
|
|
2165
2165
|
`[theokit-sdk] personality persist failed for ${chunk6LHQPOMI_cjs.redactSecrets(agentId)}: ${chunk6LHQPOMI_cjs.redactSecrets(
|
|
2166
2166
|
err.message
|
|
@@ -2177,7 +2177,7 @@ var PersonalityStore = class {
|
|
|
2177
2177
|
try {
|
|
2178
2178
|
state = await readState(filePath);
|
|
2179
2179
|
} catch (err) {
|
|
2180
|
-
|
|
2180
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
2181
2181
|
`personality-store-hydrate-failure-${agentId}`,
|
|
2182
2182
|
`[theokit-sdk] personality hydrate failed for ${chunk6LHQPOMI_cjs.redactSecrets(agentId)}: ${chunk6LHQPOMI_cjs.redactSecrets(
|
|
2183
2183
|
err.message
|
|
@@ -2206,7 +2206,7 @@ var PersonalityStore = class {
|
|
|
2206
2206
|
});
|
|
2207
2207
|
}
|
|
2208
2208
|
#filePath() {
|
|
2209
|
-
return path.join(
|
|
2209
|
+
return path.join(chunkDWB3CN46_cjs.getTheokitHome(this.#cwd), FILE_NAME);
|
|
2210
2210
|
}
|
|
2211
2211
|
};
|
|
2212
2212
|
|
|
@@ -2523,7 +2523,7 @@ function removeAll(arr, toRemove) {
|
|
|
2523
2523
|
}
|
|
2524
2524
|
}
|
|
2525
2525
|
function readCompatConfigFile(cwd) {
|
|
2526
|
-
const path$1 = path.join(
|
|
2526
|
+
const path$1 = path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), "config.json");
|
|
2527
2527
|
if (!fs.existsSync(path$1)) return [];
|
|
2528
2528
|
let raw;
|
|
2529
2529
|
try {
|
|
@@ -2615,7 +2615,7 @@ var HooksExecutor = class {
|
|
|
2615
2615
|
this.config = {};
|
|
2616
2616
|
return;
|
|
2617
2617
|
}
|
|
2618
|
-
this.config = await
|
|
2618
|
+
this.config = await chunkSSIRPWWD_cjs.loadHookConfig(this.cwd, this.compatSources);
|
|
2619
2619
|
}
|
|
2620
2620
|
/** Fire every hook registered for `event` and aggregate the decisions. */
|
|
2621
2621
|
async run(payload) {
|
|
@@ -2668,7 +2668,7 @@ var HooksExecutor = class {
|
|
|
2668
2668
|
if (result.exitCode !== 0) {
|
|
2669
2669
|
const stderr = result.stderr.trim();
|
|
2670
2670
|
const base = stderr.length > 0 ? stderr : `Hook exited with code ${result.exitCode}`;
|
|
2671
|
-
const missing =
|
|
2671
|
+
const missing = chunkDWB3CN46_cjs.undefinedVariablesIn(command.command, env);
|
|
2672
2672
|
if (missing.length === 0) return { decision: "deny", reason: base };
|
|
2673
2673
|
return {
|
|
2674
2674
|
decision: "deny",
|
|
@@ -2680,7 +2680,7 @@ var HooksExecutor = class {
|
|
|
2680
2680
|
};
|
|
2681
2681
|
function runtimeEnvFor(sourcePath, cwd) {
|
|
2682
2682
|
if (sourcePath === void 0) return {};
|
|
2683
|
-
return
|
|
2683
|
+
return chunkDWB3CN46_cjs.adapterForConfigPath(sourcePath)?.runtimeEnv(cwd) ?? {};
|
|
2684
2684
|
}
|
|
2685
2685
|
function parseDecisionFromStdout(stdout) {
|
|
2686
2686
|
const trimmed = stdout.trim();
|
|
@@ -2853,10 +2853,10 @@ var SkillsManager = class {
|
|
|
2853
2853
|
}
|
|
2854
2854
|
async refresh() {
|
|
2855
2855
|
const roots = this.skillsDir === void 0 ? [
|
|
2856
|
-
...
|
|
2856
|
+
...chunkDWB3CN46_cjs.projectConfigRoots(this.cwd, this.compatSources, "skills").map(
|
|
2857
2857
|
(root) => path.join(root, "skills")
|
|
2858
2858
|
),
|
|
2859
|
-
...(await
|
|
2859
|
+
...(await chunkIQBDR5YZ_cjs.pluginBundleDirs(this.cwd, this.compatSources)).map((b) => path.join(b, "skills"))
|
|
2860
2860
|
] : [this.skillsDir];
|
|
2861
2861
|
const discovered = [];
|
|
2862
2862
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3440,7 +3440,7 @@ var HISTOGRAM_NAMES = {
|
|
|
3440
3440
|
};
|
|
3441
3441
|
function safeRequire(moduleName) {
|
|
3442
3442
|
try {
|
|
3443
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3443
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-DEJCKB65.cjs', document.baseURI).href)));
|
|
3444
3444
|
return r(moduleName);
|
|
3445
3445
|
} catch {
|
|
3446
3446
|
return void 0;
|
|
@@ -3683,7 +3683,7 @@ var cachedOtel;
|
|
|
3683
3683
|
function loadOtel() {
|
|
3684
3684
|
if (cachedOtel === void 0) {
|
|
3685
3685
|
try {
|
|
3686
|
-
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-
|
|
3686
|
+
const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-DEJCKB65.cjs', document.baseURI).href)));
|
|
3687
3687
|
const mod = r("@opentelemetry/api");
|
|
3688
3688
|
cachedOtel = mod;
|
|
3689
3689
|
} catch {
|
|
@@ -4137,8 +4137,8 @@ var FileContextManager = class {
|
|
|
4137
4137
|
}
|
|
4138
4138
|
};
|
|
4139
4139
|
async function loadContextConfig(cwd) {
|
|
4140
|
-
const mdDir = path.join(
|
|
4141
|
-
const jsonPath = path.join(
|
|
4140
|
+
const mdDir = path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), "context");
|
|
4141
|
+
const jsonPath = path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), "context.json");
|
|
4142
4142
|
const mdEntities = await loadMarkdownEntities({
|
|
4143
4143
|
dir: mdDir,
|
|
4144
4144
|
schema: ContextSourceFrontmatterSchema,
|
|
@@ -4147,7 +4147,7 @@ async function loadContextConfig(cwd) {
|
|
|
4147
4147
|
});
|
|
4148
4148
|
if (mdEntities.length > 0) {
|
|
4149
4149
|
if (fs.existsSync(jsonPath)) {
|
|
4150
|
-
|
|
4150
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
4151
4151
|
"context-both-present",
|
|
4152
4152
|
"[theokit-sdk] both .theokit/context/ and .theokit/context.json detected \u2014 using markdown; remove context.json"
|
|
4153
4153
|
);
|
|
@@ -4157,7 +4157,7 @@ async function loadContextConfig(cwd) {
|
|
|
4157
4157
|
};
|
|
4158
4158
|
}
|
|
4159
4159
|
if (!fs.existsSync(jsonPath)) return { sources: [] };
|
|
4160
|
-
|
|
4160
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
4161
4161
|
"context-json-deprecated",
|
|
4162
4162
|
// Names no command: `theokit-migrate-config` was unpublished with the `bin` entry, and a warning
|
|
4163
4163
|
// that tells you to run something the package does not ship is worse than one that tells you
|
|
@@ -4298,7 +4298,7 @@ var PluginsManager = class {
|
|
|
4298
4298
|
}
|
|
4299
4299
|
async refresh() {
|
|
4300
4300
|
this.plugins = [];
|
|
4301
|
-
for (const pluginsRoot of
|
|
4301
|
+
for (const pluginsRoot of chunkDWB3CN46_cjs.pluginBundleRoots(this.cwd, this.compatSources)) {
|
|
4302
4302
|
await this.refreshRoot(pluginsRoot);
|
|
4303
4303
|
}
|
|
4304
4304
|
}
|
|
@@ -4320,13 +4320,13 @@ var PluginsManager = class {
|
|
|
4320
4320
|
const jsonPath = path.join(pluginsRoot, folderName, "plugin.json");
|
|
4321
4321
|
const metadata = fs.existsSync(mdPath) ? await loadPluginManifestFromMarkdown(this.cwd, pluginsRoot, folderName) : await loadPluginManifestFromJson(this.cwd, jsonPath, folderName);
|
|
4322
4322
|
if (fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
|
|
4323
|
-
|
|
4323
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
4324
4324
|
`plugin-${folderName}-both`,
|
|
4325
4325
|
`[theokit-sdk] both ${folderName}/PLUGIN.md and ${folderName}/plugin.json detected \u2014 using markdown; remove plugin.json`
|
|
4326
4326
|
);
|
|
4327
4327
|
}
|
|
4328
4328
|
if (!fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
|
|
4329
|
-
|
|
4329
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
4330
4330
|
"plugin-json-deprecated",
|
|
4331
4331
|
// Same reason as the context.json warning: the CLI it used to name is no longer published.
|
|
4332
4332
|
"[theokit-sdk] plugin.json manifests are deprecated; replace each with a PLUGIN.md"
|
|
@@ -7210,7 +7210,7 @@ function applyPersonalityFilter(exposedTools, whitelist, opts) {
|
|
|
7210
7210
|
if (exposedSet.has(name)) continue;
|
|
7211
7211
|
const hint = suggestClosest(name, exposedSet);
|
|
7212
7212
|
const message = hint !== void 0 ? `[theokit-sdk] personality "${opts?.personalityName ?? "?"}" references unknown tool "${name}"; did you mean "${hint}"?` : `[theokit-sdk] personality "${opts?.personalityName ?? "?"}" references unknown tool "${name}" (not exposed)`;
|
|
7213
|
-
|
|
7213
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
7214
7214
|
`personality-tool-missing|${opts?.agentId ?? "?"}|${opts?.personalityName ?? "?"}|${name}`,
|
|
7215
7215
|
message
|
|
7216
7216
|
);
|
|
@@ -7659,7 +7659,7 @@ async function dispatchLocalRun(args) {
|
|
|
7659
7659
|
});
|
|
7660
7660
|
}
|
|
7661
7661
|
async function readProjectMcpServers(cwd) {
|
|
7662
|
-
const path$1 = path.join(
|
|
7662
|
+
const path$1 = path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), "mcp.json");
|
|
7663
7663
|
try {
|
|
7664
7664
|
const raw = await promises.readFile(path$1, "utf8");
|
|
7665
7665
|
const parsed = JSON.parse(raw);
|
|
@@ -7901,7 +7901,7 @@ async function reloadLocalAgent(agent) {
|
|
|
7901
7901
|
if (agent.context !== void 0) await agent.context.refresh();
|
|
7902
7902
|
if (agent.skillsManager !== void 0) await agent.skillsManager.refresh();
|
|
7903
7903
|
if (agent.pluginsManager !== void 0) await agent.pluginsManager.refresh();
|
|
7904
|
-
return await
|
|
7904
|
+
return await chunkIQBDR5YZ_cjs.loadSubagents(
|
|
7905
7905
|
agent.workspaceCwd,
|
|
7906
7906
|
agent.settingSourcesIncludeProject,
|
|
7907
7907
|
agent.options.agents
|
|
@@ -8935,7 +8935,7 @@ var PersonalityRegistry = class _PersonalityRegistry {
|
|
|
8935
8935
|
* @internal
|
|
8936
8936
|
*/
|
|
8937
8937
|
static async load(cwd) {
|
|
8938
|
-
const projectDir = path.join(
|
|
8938
|
+
const projectDir = path.join(chunkDWB3CN46_cjs.theokitConfigRoot(cwd), PERSONALITIES_SUFFIX);
|
|
8939
8939
|
const userDir = path.join(os.homedir(), USER_SUBDIR);
|
|
8940
8940
|
const [userEntities, projectEntities] = await Promise.all([
|
|
8941
8941
|
loadMarkdownEntities({
|
|
@@ -8987,7 +8987,7 @@ function addEntity(byName, entity, origin, collisionMap) {
|
|
|
8987
8987
|
);
|
|
8988
8988
|
}
|
|
8989
8989
|
if (origin === "project" && collisionMap?.has(fm.name)) {
|
|
8990
|
-
|
|
8990
|
+
chunkSSIRPWWD_cjs.warnOnce(
|
|
8991
8991
|
`personality-collision-${fm.name}`,
|
|
8992
8992
|
`[theokit-sdk] personality "${fm.name}" overridden by project preset`
|
|
8993
8993
|
);
|
|
@@ -9037,14 +9037,14 @@ async function performPersonalitySwitch(args) {
|
|
|
9037
9037
|
|
|
9038
9038
|
// src/internal/local-agent/local-agent-personality-extensions.ts
|
|
9039
9039
|
function resolveActivePersonalityPreset(args) {
|
|
9040
|
-
const forkCtx =
|
|
9040
|
+
const forkCtx = chunkSSIRPWWD_cjs.currentPersonalityContext();
|
|
9041
9041
|
const slug = forkCtx !== void 0 ? forkCtx.slug : args.personalityStore.active(args.agentId);
|
|
9042
9042
|
if (slug === void 0) return void 0;
|
|
9043
9043
|
return args.personalityRegistry?.get(slug);
|
|
9044
9044
|
}
|
|
9045
9045
|
async function ensurePersonalityRegistryIfNeeded(args) {
|
|
9046
9046
|
if (args.personalityRegistry !== void 0) return args.personalityRegistry;
|
|
9047
|
-
const forkSlug =
|
|
9047
|
+
const forkSlug = chunkSSIRPWWD_cjs.currentPersonalityContext()?.slug;
|
|
9048
9048
|
const ownSlug = args.personalityStore.active(args.agentId);
|
|
9049
9049
|
if (forkSlug === void 0 && ownSlug === void 0) return void 0;
|
|
9050
9050
|
return await PersonalityRegistry.load(args.workspaceCwd);
|
|
@@ -9057,8 +9057,8 @@ function applyPersonalityOverlay(preset, base) {
|
|
|
9057
9057
|
${preset.systemPrompt}`;
|
|
9058
9058
|
}
|
|
9059
9059
|
async function localAgentUsePersonality(agent, name, opts) {
|
|
9060
|
-
if (
|
|
9061
|
-
|
|
9060
|
+
if (chunkSSIRPWWD_cjs.currentPersonalityContext() !== void 0) {
|
|
9061
|
+
chunkSSIRPWWD_cjs.warnPersonalitySwitchInsideFork(agent.agentId);
|
|
9062
9062
|
return null;
|
|
9063
9063
|
}
|
|
9064
9064
|
if (agent.personalityRegistry === void 0) {
|
|
@@ -9119,7 +9119,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
|
|
|
9119
9119
|
async function localAgentFork(parent, options) {
|
|
9120
9120
|
const { forkAgentImpl } = await import('./fork-agent-WAEQI2DL.cjs');
|
|
9121
9121
|
const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
|
|
9122
|
-
const { withPersonalityContext } = await import('./context-
|
|
9122
|
+
const { withPersonalityContext } = await import('./context-3YMZDEX5.cjs');
|
|
9123
9123
|
const create = getAgentFacade().create;
|
|
9124
9124
|
return withPersonalityContext(
|
|
9125
9125
|
{ slug: parent.personalitySlugSnapshot, isFork: true },
|
|
@@ -9911,7 +9911,7 @@ var LocalAgent = class {
|
|
|
9911
9911
|
if (sub.plugins !== void 0) this.plugins = sub.plugins;
|
|
9912
9912
|
reportUnknownLocalOptions(options.local);
|
|
9913
9913
|
const compatSources = resolveCompatSources(options, this.workspaceCwd);
|
|
9914
|
-
|
|
9914
|
+
chunkDWB3CN46_cjs.reportUndeclaredSources(this.workspaceCwd, compatSources);
|
|
9915
9915
|
this.hooksExecutor = new HooksExecutor(this.workspaceCwd, compatSources);
|
|
9916
9916
|
this.defaultMemoryProviderForLoop = createLocalAgentMemoryProvider({
|
|
9917
9917
|
agentOptions: options,
|
|
@@ -9939,7 +9939,7 @@ var LocalAgent = class {
|
|
|
9939
9939
|
if (this.pluginsManager !== void 0) await this.pluginsManager.initialize();
|
|
9940
9940
|
const codePlugins = chunkBV2MWEMV_cjs.extractCodePlugins(this.options.plugins);
|
|
9941
9941
|
await this.pluginManagerCode.initialize(codePlugins);
|
|
9942
|
-
this.resolvedSubagents = await
|
|
9942
|
+
this.resolvedSubagents = await chunkIQBDR5YZ_cjs.loadSubagents(
|
|
9943
9943
|
this.workspaceCwd,
|
|
9944
9944
|
this.settingSourcesIncludeProject,
|
|
9945
9945
|
this.options.agents,
|
|
@@ -10892,7 +10892,7 @@ var Agent = class _Agent {
|
|
|
10892
10892
|
*/
|
|
10893
10893
|
static async describe(agentId) {
|
|
10894
10894
|
const agent = await getRegisteredAgentOrThrow(agentId);
|
|
10895
|
-
const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-
|
|
10895
|
+
const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-7G76XOZU.cjs');
|
|
10896
10896
|
const settingSources = agent.options.local?.settingSources;
|
|
10897
10897
|
const subagents = await loadSubagents2(
|
|
10898
10898
|
agent.cwd ?? process.cwd(),
|
|
@@ -10991,5 +10991,5 @@ exports.generateCronId = generateCronId;
|
|
|
10991
10991
|
exports.getPricingEntry = getPricingEntry;
|
|
10992
10992
|
exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
|
|
10993
10993
|
exports.resolveSessionDir = resolveSessionDir;
|
|
10994
|
-
//# sourceMappingURL=chunk-
|
|
10995
|
-
//# sourceMappingURL=chunk-
|
|
10994
|
+
//# sourceMappingURL=chunk-DEJCKB65.cjs.map
|
|
10995
|
+
//# sourceMappingURL=chunk-DEJCKB65.cjs.map
|