@theokit/sdk 5.3.3 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/{agent-CTbU0O1R.d.ts → agent-CjMVbhhY.d.ts} +95 -2
  3. package/dist/{agent-QLwxhXY3.d.cts → agent-DyB_lzrx.d.cts} +95 -2
  4. package/dist/{agent-PNYJ5S2Y.js → agent-G3T7Q3SQ.js} +8 -8
  5. package/dist/{agent-PNYJ5S2Y.js.map → agent-G3T7Q3SQ.js.map} +1 -1
  6. package/dist/{agent-KJLAWKZB.cjs → agent-YWSIHHFM.cjs} +9 -9
  7. package/dist/{agent-KJLAWKZB.cjs.map → agent-YWSIHHFM.cjs.map} +1 -1
  8. package/dist/{chunk-AWINL3ZC.js → chunk-2QKV4CGK.js} +3 -3
  9. package/dist/{chunk-AWINL3ZC.js.map → chunk-2QKV4CGK.js.map} +1 -1
  10. package/dist/{chunk-L4XENLQO.cjs → chunk-2ZLQZHZC.cjs} +4 -4
  11. package/dist/{chunk-L4XENLQO.cjs.map → chunk-2ZLQZHZC.cjs.map} +1 -1
  12. package/dist/{chunk-DWB3CN46.cjs → chunk-43YXGD3P.cjs} +14 -4
  13. package/dist/chunk-43YXGD3P.cjs.map +1 -0
  14. package/dist/{chunk-IQBDR5YZ.cjs → chunk-AYA65JA5.cjs} +5 -5
  15. package/dist/{chunk-IQBDR5YZ.cjs.map → chunk-AYA65JA5.cjs.map} +1 -1
  16. package/dist/{chunk-2HPNT6HH.cjs → chunk-C4ZQPWXJ.cjs} +9 -9
  17. package/dist/chunk-C4ZQPWXJ.cjs.map +1 -0
  18. package/dist/{chunk-Y2KYR2ED.cjs → chunk-DZG77WU7.cjs} +3 -3
  19. package/dist/{chunk-Y2KYR2ED.cjs.map → chunk-DZG77WU7.cjs.map} +1 -1
  20. package/dist/{chunk-K3NH62DG.js → chunk-KZSKIUXZ.js} +7 -7
  21. package/dist/chunk-KZSKIUXZ.js.map +1 -0
  22. package/dist/{chunk-ZITYGJOD.js → chunk-M3ZGRGOG.js} +3 -3
  23. package/dist/{chunk-ZITYGJOD.js.map → chunk-M3ZGRGOG.js.map} +1 -1
  24. package/dist/{chunk-RP3VXJMA.js → chunk-NSLHPAC7.js} +14 -4
  25. package/dist/chunk-NSLHPAC7.js.map +1 -0
  26. package/dist/{chunk-DLFWMJE3.js → chunk-O7L7M42F.js} +3 -3
  27. package/dist/{chunk-DLFWMJE3.js.map → chunk-O7L7M42F.js.map} +1 -1
  28. package/dist/{chunk-363RBGIR.js → chunk-ODBID5TG.js} +63 -27
  29. package/dist/chunk-ODBID5TG.js.map +1 -0
  30. package/dist/{chunk-7L3MIW2F.js → chunk-S6B5XYC3.js} +4 -4
  31. package/dist/chunk-S6B5XYC3.js.map +1 -0
  32. package/dist/{chunk-Y46VI73J.cjs → chunk-UKJJRU7C.cjs} +132 -96
  33. package/dist/chunk-UKJJRU7C.cjs.map +1 -0
  34. package/dist/{chunk-65UMH5V3.cjs → chunk-VY6NKMOA.cjs} +6 -6
  35. package/dist/chunk-VY6NKMOA.cjs.map +1 -0
  36. package/dist/{compact-session-BHTPCIHA.cjs → compact-session-7FMYJXQ7.cjs} +11 -11
  37. package/dist/{compact-session-BHTPCIHA.cjs.map → compact-session-7FMYJXQ7.cjs.map} +1 -1
  38. package/dist/{compact-session-W4WLJTHA.js → compact-session-YSEK7NQF.js} +3 -3
  39. package/dist/{compact-session-W4WLJTHA.js.map → compact-session-YSEK7NQF.js.map} +1 -1
  40. package/dist/context-3HPU754C.js +6 -0
  41. package/dist/{context-BUIE52VH.js.map → context-3HPU754C.js.map} +1 -1
  42. package/dist/{context-FCCJQ3FN.cjs → context-JTGSBJT6.cjs} +7 -7
  43. package/dist/{context-FCCJQ3FN.cjs.map → context-JTGSBJT6.cjs.map} +1 -1
  44. package/dist/{cron-Dz8AOpy3.d.cts → cron-Bgivg88c.d.cts} +1 -1
  45. package/dist/{cron-Cl8FrK3D.d.ts → cron-CNUa7PDo.d.ts} +1 -1
  46. package/dist/cron.cjs +8 -8
  47. package/dist/cron.d.cts +2 -2
  48. package/dist/cron.d.ts +2 -2
  49. package/dist/cron.js +7 -7
  50. package/dist/eval.cjs +7 -7
  51. package/dist/eval.js +6 -6
  52. package/dist/index.cjs +30 -30
  53. package/dist/index.d.cts +3 -3
  54. package/dist/index.d.ts +3 -3
  55. package/dist/index.js +9 -9
  56. package/dist/{inject-session-SUM6TDJF.js → inject-session-J4LBWAPH.js} +3 -3
  57. package/dist/{inject-session-SUM6TDJF.js.map → inject-session-J4LBWAPH.js.map} +1 -1
  58. package/dist/{inject-session-W6A46J3E.cjs → inject-session-PC73TMP2.cjs} +4 -4
  59. package/dist/{inject-session-W6A46J3E.cjs.map → inject-session-PC73TMP2.cjs.map} +1 -1
  60. package/dist/internal/llm/tool-result-content.d.ts +1 -1
  61. package/dist/internal/persistence/index.cjs +4 -4
  62. package/dist/internal/persistence/index.js +1 -1
  63. package/dist/internal/runtime/hooks/hooks-executor.d.ts +35 -1
  64. package/dist/internal/runtime/hooks/hooks-source.d.ts +10 -0
  65. package/dist/subagents-loader-AIVDQ2D5.js +7 -0
  66. package/dist/{subagents-loader-PAZVOZHI.js.map → subagents-loader-AIVDQ2D5.js.map} +1 -1
  67. package/dist/subagents-loader-DN4LETGL.cjs +16 -0
  68. package/dist/{subagents-loader-7G76XOZU.cjs.map → subagents-loader-DN4LETGL.cjs.map} +1 -1
  69. package/dist/subagents-loader.cjs +3 -3
  70. package/dist/subagents-loader.d.cts +1 -1
  71. package/dist/subagents-loader.d.ts +1 -1
  72. package/dist/subagents-loader.js +2 -2
  73. package/dist/types/agent.d.ts +25 -2
  74. package/dist/types/hooks.d.ts +70 -0
  75. package/docs/error-codes.md +4 -4
  76. package/package.json +1 -1
  77. package/dist/chunk-2HPNT6HH.cjs.map +0 -1
  78. package/dist/chunk-363RBGIR.js.map +0 -1
  79. package/dist/chunk-65UMH5V3.cjs.map +0 -1
  80. package/dist/chunk-7L3MIW2F.js.map +0 -1
  81. package/dist/chunk-DWB3CN46.cjs.map +0 -1
  82. package/dist/chunk-K3NH62DG.js.map +0 -1
  83. package/dist/chunk-RP3VXJMA.js.map +0 -1
  84. package/dist/chunk-Y46VI73J.cjs.map +0 -1
  85. package/dist/context-BUIE52VH.js +0 -6
  86. package/dist/subagents-loader-7G76XOZU.cjs +0 -16
  87. package/dist/subagents-loader-PAZVOZHI.js +0 -7
@@ -1,13 +1,13 @@
1
1
  import { submit, emitRunEvent } from './chunk-K2VMFZQ5.js';
2
- import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-AWINL3ZC.js';
2
+ import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-2QKV4CGK.js';
3
3
  import { IndexManager } from './chunk-7SZAV6QG.js';
4
- import { loadHookConfig, warnOnce, currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-7L3MIW2F.js';
4
+ import { loadHookConfig, warnOnce, currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-S6B5XYC3.js';
5
5
  import { extractCodePlugins } from './chunk-2SFBB54R.js';
6
6
  import { createOpenAiCompatibleRuntime } from './chunk-55GB6JYQ.js';
7
7
  import { persistActiveMemoryTranscript } from './chunk-OR6XIWLB.js';
8
8
  import { writeSessionSummary, resolveMemoryRoot, MEMORY_KINDS, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-SADXXGWU.js';
9
9
  import { FsSessionStore } from './chunk-AAEZSPTC.js';
10
- import { discoverProviderPlugins, validateApiKeyShape, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, presentProviderCredentialEnvVars, buildDefaultSummarizer, shouldUseRealLocalRuntime, parseSseStream, CircuitBreaker, resolveRunProvider, mergeExplicitApiKey, resolveProviderChain, abortError, tryFirstEvent, relayStream, renderToolResultContentText } from './chunk-K3NH62DG.js';
10
+ import { discoverProviderPlugins, validateApiKeyShape, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, presentProviderCredentialEnvVars, buildDefaultSummarizer, shouldUseRealLocalRuntime, parseSseStream, CircuitBreaker, resolveRunProvider, mergeExplicitApiKey, resolveProviderChain, abortError, tryFirstEvent, relayStream, renderToolResultContentText } from './chunk-KZSKIUXZ.js';
11
11
  import { resolveChildEnv } from './chunk-HKCKOAIO.js';
12
12
  import { DEFAULT_MAX_BYTES_PER_FILE, runDiscovery, truncateWithMarker } from './chunk-N6OOOYFZ.js';
13
13
  import { readVersionedJson, writeVersionedJson } from './chunk-SVQIW5RJ.js';
@@ -24,8 +24,8 @@ import { expandTilde, defaultBaseDir } from './chunk-JOFVLOFY.js';
24
24
  import { withFileLock } from './chunk-TA3K7SBK.js';
25
25
  import { withCwdMutex } from './chunk-Q5EWJPRY.js';
26
26
  import { sweepStaleAtomicTemps, atomicWriteJson } from './chunk-3JHIFQ4I.js';
27
- import { loadSubagents, pluginBundleDirs } from './chunk-DLFWMJE3.js';
28
- import { reportUndeclaredSources, theokitConfigRoot, undefinedVariablesIn, getTheokitHome, adapterForConfigPath, projectConfigRoots, pluginBundleRoots } from './chunk-RP3VXJMA.js';
27
+ import { loadSubagents, pluginBundleDirs } from './chunk-O7L7M42F.js';
28
+ import { reportUndeclaredSources, theokitConfigRoot, undefinedVariablesIn, getTheokitHome, adapterForConfigPath, projectConfigRoots, pluginBundleRoots } from './chunk-NSLHPAC7.js';
29
29
  import { readWorkspaceDir, parseSimpleYaml } from './chunk-JNAA4G4H.js';
30
30
  import { resolveEffectiveContextWindow, CONTEXT_WINDOW_FLOOR, CONTEXT_WINDOW_MARGIN } from './chunk-6M2OIS4Y.js';
31
31
  import { parseModelId } from './chunk-R7WIIPUR.js';
@@ -2600,12 +2600,14 @@ function spawnAndCollect(options) {
2600
2600
 
2601
2601
  // src/internal/runtime/hooks/hooks-executor.ts
2602
2602
  var HooksExecutor = class {
2603
- constructor(cwd, compatSources = []) {
2603
+ constructor(cwd, compatSources = [], gate = void 0) {
2604
2604
  this.cwd = cwd;
2605
2605
  this.compatSources = compatSources;
2606
+ this.gate = gate;
2606
2607
  }
2607
2608
  cwd;
2608
2609
  compatSources;
2610
+ gate;
2609
2611
  config = {};
2610
2612
  async initialize(settingSourcesIncludeProject) {
2611
2613
  if (!settingSourcesIncludeProject) {
@@ -2645,8 +2647,33 @@ var HooksExecutor = class {
2645
2647
  }
2646
2648
  });
2647
2649
  }
2650
+ /**
2651
+ * #631 — the consumer's gate, consulted at the ONLY point a hook is spawned.
2652
+ *
2653
+ * Here and not at the caller on purpose: a check anywhere else could be reached around by a
2654
+ * second execution path later, and this one cannot — `spawnAndCollect` is called for a hook from
2655
+ * exactly one place.
2656
+ *
2657
+ * No gate means no refusal, which is what every consumer gets today.
2658
+ */
2659
+ async refusedByConsumer(command, payload, timeoutMs) {
2660
+ if (this.gate?.approve === void 0) return false;
2661
+ const request = {
2662
+ command: command.command,
2663
+ event: payload.event,
2664
+ // #637 — the EFFECTIVE timeout, passed in rather than recomputed here, so the number the
2665
+ // consumer is shown and the number `spawnAndCollect` enforces are the same expression.
2666
+ // Recomputing would be one line and would be the place they later diverge.
2667
+ timeoutMs,
2668
+ sourceEvent: command.sourceEvent,
2669
+ ...command.sourcePath === void 0 ? {} : { sourcePath: command.sourcePath },
2670
+ ...command.matcher === void 0 ? {} : { matcher: command.matcher }
2671
+ };
2672
+ return !await this.gate.approve(request);
2673
+ }
2648
2674
  async executeOne(command, payload) {
2649
2675
  const timeoutMs = command.timeoutMs ?? 3e4;
2676
+ if (await this.refusedByConsumer(command, payload, timeoutMs)) return { decision: "allow" };
2650
2677
  const env = runtimeEnvFor(command.sourcePath, this.cwd);
2651
2678
  const result = await spawnAndCollect({
2652
2679
  command: "sh",
@@ -2656,23 +2683,31 @@ var HooksExecutor = class {
2656
2683
  timeoutMs,
2657
2684
  stdin: JSON.stringify(payload)
2658
2685
  });
2659
- if (result.timedOut) {
2660
- return { decision: "deny", reason: `Hook timed out after ${timeoutMs}ms` };
2661
- }
2686
+ const failure = this.decisionFromFailure(result, command, env, timeoutMs);
2687
+ return failure ?? parseDecisionFromStdout(result.stdout);
2688
+ }
2689
+ /**
2690
+ * A run that did not succeed, turned into a decision. `undefined` when it did.
2691
+ *
2692
+ * Extracted from `executeOne` when the approval gate pushed that function past the complexity
2693
+ * gate. The seam is not arbitrary — every branch here answers one question, "the command did not
2694
+ * run cleanly, so what does this hook decide?", and none of them knows how the command was
2695
+ * spawned.
2696
+ */
2697
+ decisionFromFailure(result, command, env, timeoutMs) {
2698
+ if (result.timedOut) return { decision: "deny", reason: `Hook timed out after ${timeoutMs}ms` };
2662
2699
  if (result.spawnError !== void 0) {
2663
2700
  return { decision: "deny", reason: `Hook spawn failed: ${result.spawnError.message}` };
2664
2701
  }
2665
- if (result.exitCode !== 0) {
2666
- const stderr = result.stderr.trim();
2667
- const base = stderr.length > 0 ? stderr : `Hook exited with code ${result.exitCode}`;
2668
- const missing = undefinedVariablesIn(command.command, env);
2669
- if (missing.length === 0) return { decision: "deny", reason: base };
2670
- return {
2671
- decision: "deny",
2672
- reason: `${base} \u2014 this hook came from ${command.sourcePath ?? "an unrecorded source"} and uses ${missing.map((n) => `$${n}`).join(", ")}, which nothing defines here. A variable this runtime does not supply expands to the empty string, so the error above names a path rather than the cause.`
2673
- };
2674
- }
2675
- return parseDecisionFromStdout(result.stdout);
2702
+ if (result.exitCode === 0) return void 0;
2703
+ const stderr = result.stderr.trim();
2704
+ const base = stderr.length > 0 ? stderr : `Hook exited with code ${result.exitCode}`;
2705
+ const missing = undefinedVariablesIn(command.command, env);
2706
+ if (missing.length === 0) return { decision: "deny", reason: base };
2707
+ return {
2708
+ decision: "deny",
2709
+ reason: `${base} \u2014 this hook came from ${command.sourcePath ?? "an unrecorded source"} and uses ${missing.map((n) => `$${n}`).join(", ")}, which nothing defines here. A variable this runtime does not supply expands to the empty string, so the error above names a path rather than the cause.`
2710
+ };
2676
2711
  }
2677
2712
  };
2678
2713
  function runtimeEnvFor(sourcePath, cwd) {
@@ -9122,7 +9157,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
9122
9157
  async function localAgentFork(parent, options) {
9123
9158
  const { forkAgentImpl } = await import('./fork-agent-S2EPIML7.js');
9124
9159
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
9125
- const { withPersonalityContext } = await import('./context-BUIE52VH.js');
9160
+ const { withPersonalityContext } = await import('./context-3HPU754C.js');
9126
9161
  const create = getAgentFacade().create;
9127
9162
  return withPersonalityContext(
9128
9163
  { slug: parent.personalitySlugSnapshot, isFork: true },
@@ -9764,6 +9799,7 @@ var KNOWN_LOCAL_OPTION_KEYS = /* @__PURE__ */ new Set([
9764
9799
  "cwd",
9765
9800
  "settingSources",
9766
9801
  "compatSources",
9802
+ "hooks",
9767
9803
  "sandboxOptions",
9768
9804
  "sessionDir",
9769
9805
  "baseDir",
@@ -9915,7 +9951,7 @@ var LocalAgent = class {
9915
9951
  reportUnknownLocalOptions(options.local);
9916
9952
  const compatSources = resolveCompatSources(options, this.workspaceCwd);
9917
9953
  reportUndeclaredSources(this.workspaceCwd, compatSources);
9918
- this.hooksExecutor = new HooksExecutor(this.workspaceCwd, compatSources);
9954
+ this.hooksExecutor = new HooksExecutor(this.workspaceCwd, compatSources, options.local?.hooks);
9919
9955
  this.defaultMemoryProviderForLoop = createLocalAgentMemoryProvider({
9920
9956
  agentOptions: options,
9921
9957
  workspaceCwd: this.workspaceCwd,
@@ -10820,7 +10856,7 @@ var Agent = class _Agent {
10820
10856
  */
10821
10857
  static async compact(agentId, options = {}) {
10822
10858
  const reg = await requireLocalAgent(agentId, "compact");
10823
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-W4WLJTHA.js');
10859
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-YSEK7NQF.js');
10824
10860
  const { cwd, model, store } = await openLocalStore(reg);
10825
10861
  return enqueueSessionWrite(
10826
10862
  cwd,
@@ -10847,7 +10883,7 @@ var Agent = class _Agent {
10847
10883
  */
10848
10884
  static async injectSessionTurn(agentId, turn) {
10849
10885
  const reg = await requireLocalAgent(agentId, "injectSessionTurn");
10850
- const { injectSessionTurn } = await import('./inject-session-SUM6TDJF.js');
10886
+ const { injectSessionTurn } = await import('./inject-session-J4LBWAPH.js');
10851
10887
  const { cwd, model, store } = await openLocalStore(reg);
10852
10888
  await injectSessionTurn({
10853
10889
  store,
@@ -10898,7 +10934,7 @@ var Agent = class _Agent {
10898
10934
  */
10899
10935
  static async describe(agentId) {
10900
10936
  const agent = await getRegisteredAgentOrThrow(agentId);
10901
- const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-PAZVOZHI.js');
10937
+ const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-AIVDQ2D5.js');
10902
10938
  const settingSources = agent.options.local?.settingSources;
10903
10939
  const subagents = await loadSubagents2(
10904
10940
  agent.cwd ?? process.cwd(),
@@ -11005,5 +11041,5 @@ async function openLocalStore(reg) {
11005
11041
  }
11006
11042
 
11007
11043
  export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, openRouterMemoryEmbeddingProviderAdapter, resolveSessionDir };
11008
- //# sourceMappingURL=chunk-363RBGIR.js.map
11009
- //# sourceMappingURL=chunk-363RBGIR.js.map
11044
+ //# sourceMappingURL=chunk-ODBID5TG.js.map
11045
+ //# sourceMappingURL=chunk-ODBID5TG.js.map