@theokit/sdk 5.5.0 → 5.7.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 (160) hide show
  1. package/CHANGELOG.md +667 -0
  2. package/dist/{agent-CjMVbhhY.d.ts → agent-Bqzdhkqr.d.ts} +12 -3
  3. package/dist/{agent-DyB_lzrx.d.cts → agent-Dya5SmhY.d.cts} +12 -3
  4. package/dist/{agent-G3T7Q3SQ.js → agent-EQ5HKTWV.js} +15 -14
  5. package/dist/{agent-G3T7Q3SQ.js.map → agent-EQ5HKTWV.js.map} +1 -1
  6. package/dist/{agent-YWSIHHFM.cjs → agent-KA63WDQH.cjs} +16 -15
  7. package/dist/{agent-YWSIHHFM.cjs.map → agent-KA63WDQH.cjs.map} +1 -1
  8. package/dist/agent.d.ts +11 -0
  9. package/dist/{chunk-Z2JFX372.cjs → chunk-33A27NFX.cjs} +15 -15
  10. package/dist/{chunk-Z2JFX372.cjs.map → chunk-33A27NFX.cjs.map} +1 -1
  11. package/dist/{chunk-N6OOOYFZ.js → chunk-3VXQEQE4.js} +13 -4
  12. package/dist/chunk-3VXQEQE4.js.map +1 -0
  13. package/dist/{chunk-DZG77WU7.cjs → chunk-3XSWF5AP.cjs} +3 -3
  14. package/dist/{chunk-DZG77WU7.cjs.map → chunk-3XSWF5AP.cjs.map} +1 -1
  15. package/dist/{chunk-M3ZGRGOG.js → chunk-6JG2RFGK.js} +3 -3
  16. package/dist/{chunk-M3ZGRGOG.js.map → chunk-6JG2RFGK.js.map} +1 -1
  17. package/dist/{chunk-S6B5XYC3.js → chunk-7C3HWGCW.js} +33 -22
  18. package/dist/chunk-7C3HWGCW.js.map +1 -0
  19. package/dist/{chunk-LOHMT36V.cjs → chunk-7KBNBPFK.cjs} +75 -2
  20. package/dist/chunk-7KBNBPFK.cjs.map +1 -0
  21. package/dist/{chunk-UKJJRU7C.cjs → chunk-A575WPBL.cjs} +330 -129
  22. package/dist/chunk-A575WPBL.cjs.map +1 -0
  23. package/dist/{chunk-2XRAWOZZ.js → chunk-A6PDYH55.js} +74 -3
  24. package/dist/chunk-A6PDYH55.js.map +1 -0
  25. package/dist/{chunk-LX7SEXOQ.js → chunk-CA5VUAP3.js} +25 -7
  26. package/dist/chunk-CA5VUAP3.js.map +1 -0
  27. package/dist/{chunk-2QKV4CGK.js → chunk-CZWN4C6A.js} +3 -3
  28. package/dist/{chunk-2QKV4CGK.js.map → chunk-CZWN4C6A.js.map} +1 -1
  29. package/dist/chunk-DQNI52VV.js +20 -0
  30. package/dist/chunk-DQNI52VV.js.map +1 -0
  31. package/dist/{chunk-VPK6PHIE.cjs → chunk-E6QXZZKE.cjs} +8 -8
  32. package/dist/{chunk-VPK6PHIE.cjs.map → chunk-E6QXZZKE.cjs.map} +1 -1
  33. package/dist/{chunk-IU5N5224.cjs → chunk-EFETPSJZ.cjs} +17 -8
  34. package/dist/chunk-EFETPSJZ.cjs.map +1 -0
  35. package/dist/{chunk-2ZLQZHZC.cjs → chunk-ER5BOIYD.cjs} +4 -4
  36. package/dist/{chunk-2ZLQZHZC.cjs.map → chunk-ER5BOIYD.cjs.map} +1 -1
  37. package/dist/{chunk-ODBID5TG.js → chunk-FUUSIT2T.js} +234 -35
  38. package/dist/chunk-FUUSIT2T.js.map +1 -0
  39. package/dist/{chunk-VY6NKMOA.cjs → chunk-GK3UG7YQ.cjs} +34 -25
  40. package/dist/chunk-GK3UG7YQ.cjs.map +1 -0
  41. package/dist/{chunk-NQTNSHSB.cjs → chunk-HNAYCTX4.cjs} +5 -5
  42. package/dist/chunk-HNAYCTX4.cjs.map +1 -0
  43. package/dist/{chunk-QATRS7JD.cjs → chunk-MYJGWS2J.cjs} +26 -8
  44. package/dist/chunk-MYJGWS2J.cjs.map +1 -0
  45. package/dist/{chunk-KZSKIUXZ.js → chunk-N7VAE6DZ.js} +31 -3
  46. package/dist/chunk-N7VAE6DZ.js.map +1 -0
  47. package/dist/{chunk-7SZAV6QG.js → chunk-P5S3WCSZ.js} +3 -3
  48. package/dist/{chunk-7SZAV6QG.js.map → chunk-P5S3WCSZ.js.map} +1 -1
  49. package/dist/{chunk-HW7SEELD.cjs → chunk-QRVS2PRE.cjs} +31 -8
  50. package/dist/chunk-QRVS2PRE.cjs.map +1 -0
  51. package/dist/{chunk-SADXXGWU.js → chunk-R3LBRQAN.js} +3 -3
  52. package/dist/{chunk-NQTNSHSB.cjs.map → chunk-R3LBRQAN.js.map} +1 -1
  53. package/dist/{chunk-AYA65JA5.cjs → chunk-RWPLWMCZ.cjs} +25 -9
  54. package/dist/chunk-RWPLWMCZ.cjs.map +1 -0
  55. package/dist/{chunk-O7L7M42F.js → chunk-T3ZDEYTJ.js} +21 -5
  56. package/dist/chunk-T3ZDEYTJ.js.map +1 -0
  57. package/dist/{chunk-43YXGD3P.cjs → chunk-TY56BKSK.cjs} +8 -4
  58. package/dist/chunk-TY56BKSK.cjs.map +1 -0
  59. package/dist/chunk-UOLBAPDM.js +66 -0
  60. package/dist/chunk-UOLBAPDM.js.map +1 -0
  61. package/dist/{chunk-NSLHPAC7.js → chunk-X7EUUHXU.js} +6 -5
  62. package/dist/chunk-X7EUUHXU.js.map +1 -0
  63. package/dist/{chunk-WS5ULCL4.js → chunk-YRLI5DVC.js} +3 -3
  64. package/dist/{chunk-WS5ULCL4.js.map → chunk-YRLI5DVC.js.map} +1 -1
  65. package/dist/chunk-YYN6BB7R.cjs +24 -0
  66. package/dist/chunk-YYN6BB7R.cjs.map +1 -0
  67. package/dist/{chunk-C4ZQPWXJ.cjs → chunk-ZLMU5EU3.cjs} +33 -4
  68. package/dist/chunk-ZLMU5EU3.cjs.map +1 -0
  69. package/dist/{compact-session-7FMYJXQ7.cjs → compact-session-75KD2FCM.cjs} +15 -11
  70. package/dist/{compact-session-7FMYJXQ7.cjs.map → compact-session-75KD2FCM.cjs.map} +1 -1
  71. package/dist/{compact-session-YSEK7NQF.js → compact-session-QT6RJOKO.js} +3 -3
  72. package/dist/{compact-session-YSEK7NQF.js.map → compact-session-QT6RJOKO.js.map} +1 -1
  73. package/dist/context/index.cjs +11 -7
  74. package/dist/context/index.cjs.map +1 -1
  75. package/dist/context/index.js +7 -3
  76. package/dist/context/index.js.map +1 -1
  77. package/dist/context-7RP5JXGM.cjs +24 -0
  78. package/dist/{context-JTGSBJT6.cjs.map → context-7RP5JXGM.cjs.map} +1 -1
  79. package/dist/context-OJIIXJCV.js +7 -0
  80. package/dist/{context-3HPU754C.js.map → context-OJIIXJCV.js.map} +1 -1
  81. package/dist/{cron-Bgivg88c.d.cts → cron-BwxDUscv.d.cts} +1 -1
  82. package/dist/{cron-CNUa7PDo.d.ts → cron-D8uB1Xh5.d.ts} +1 -1
  83. package/dist/cron.cjs +15 -14
  84. package/dist/cron.d.cts +2 -2
  85. package/dist/cron.d.ts +2 -2
  86. package/dist/cron.js +14 -13
  87. package/dist/eval.cjs +14 -13
  88. package/dist/eval.cjs.map +1 -1
  89. package/dist/eval.js +13 -12
  90. package/dist/eval.js.map +1 -1
  91. package/dist/{index-manager-3UNPYH34.cjs → index-manager-W7RHSL6G.cjs} +6 -6
  92. package/dist/{index-manager-3UNPYH34.cjs.map → index-manager-W7RHSL6G.cjs.map} +1 -1
  93. package/dist/{index-manager-W7FDMGEG.js → index-manager-Z4XMRVWQ.js} +5 -5
  94. package/dist/{index-manager-W7FDMGEG.js.map → index-manager-Z4XMRVWQ.js.map} +1 -1
  95. package/dist/index.cjs +284 -49
  96. package/dist/index.cjs.map +1 -1
  97. package/dist/index.d.cts +197 -5
  98. package/dist/index.d.ts +197 -5
  99. package/dist/index.js +249 -25
  100. package/dist/index.js.map +1 -1
  101. package/dist/{inject-session-PC73TMP2.cjs → inject-session-L6MIIELT.cjs} +4 -4
  102. package/dist/{inject-session-PC73TMP2.cjs.map → inject-session-L6MIIELT.cjs.map} +1 -1
  103. package/dist/{inject-session-J4LBWAPH.js → inject-session-XWWN4DAA.js} +3 -3
  104. package/dist/{inject-session-J4LBWAPH.js.map → inject-session-XWWN4DAA.js.map} +1 -1
  105. package/dist/internal/memory/storage/index.cjs +32 -32
  106. package/dist/internal/memory/storage/index.js +3 -3
  107. package/dist/internal/memory/storage/memory-root.d.cts +27 -0
  108. package/dist/internal/memory/storage/memory-root.d.ts +27 -0
  109. package/dist/internal/persistence/index.cjs +4 -4
  110. package/dist/internal/persistence/index.js +1 -1
  111. package/dist/internal/runtime/compat/foreign-config-sources.d.ts +17 -4
  112. package/dist/internal/runtime/compat/managed-settings.d.ts +80 -0
  113. package/dist/internal/runtime/context/context-discovery-runner.d.ts +14 -0
  114. package/dist/internal/runtime/context/context-discovery.d.ts +64 -0
  115. package/dist/internal/runtime/context/context-manager.d.ts +21 -1
  116. package/dist/internal/runtime/context/yaml-frontmatter.d.ts +6 -3
  117. package/dist/internal/runtime/hooks/hooks-executor.d.ts +13 -1
  118. package/dist/internal/runtime/hooks/hooks-source.d.ts +36 -1
  119. package/dist/internal/runtime/skills/discover-skills.d.ts +4 -0
  120. package/dist/internal/session/compact-session.d.ts +36 -0
  121. package/dist/project.cjs +3 -3
  122. package/dist/project.js +1 -1
  123. package/dist/skills.cjs +5 -5
  124. package/dist/skills.js +2 -2
  125. package/dist/subagents-loader-CJFYQQU2.js +7 -0
  126. package/dist/{subagents-loader-AIVDQ2D5.js.map → subagents-loader-CJFYQQU2.js.map} +1 -1
  127. package/dist/subagents-loader-MOO7DC4E.cjs +16 -0
  128. package/dist/{subagents-loader-DN4LETGL.cjs.map → subagents-loader-MOO7DC4E.cjs.map} +1 -1
  129. package/dist/subagents-loader.cjs +4 -4
  130. package/dist/subagents-loader.d.cts +1 -1
  131. package/dist/subagents-loader.d.ts +1 -1
  132. package/dist/subagents-loader.js +3 -3
  133. package/dist/types/agent.d.ts +7 -2
  134. package/docs/error-codes.md +20 -18
  135. package/docs/harness-capability-map.md +9 -1
  136. package/package.json +1 -1
  137. package/dist/chunk-2XRAWOZZ.js.map +0 -1
  138. package/dist/chunk-43YXGD3P.cjs.map +0 -1
  139. package/dist/chunk-AYA65JA5.cjs.map +0 -1
  140. package/dist/chunk-C4ZQPWXJ.cjs.map +0 -1
  141. package/dist/chunk-HW7SEELD.cjs.map +0 -1
  142. package/dist/chunk-IU5N5224.cjs.map +0 -1
  143. package/dist/chunk-JNAA4G4H.js +0 -43
  144. package/dist/chunk-JNAA4G4H.js.map +0 -1
  145. package/dist/chunk-KZSKIUXZ.js.map +0 -1
  146. package/dist/chunk-LOHMT36V.cjs.map +0 -1
  147. package/dist/chunk-LX7SEXOQ.js.map +0 -1
  148. package/dist/chunk-N6OOOYFZ.js.map +0 -1
  149. package/dist/chunk-NSLHPAC7.js.map +0 -1
  150. package/dist/chunk-O7L7M42F.js.map +0 -1
  151. package/dist/chunk-ODBID5TG.js.map +0 -1
  152. package/dist/chunk-QATRS7JD.cjs.map +0 -1
  153. package/dist/chunk-S6B5XYC3.js.map +0 -1
  154. package/dist/chunk-SADXXGWU.js.map +0 -1
  155. package/dist/chunk-UKJJRU7C.cjs.map +0 -1
  156. package/dist/chunk-VY6NKMOA.cjs.map +0 -1
  157. package/dist/context-3HPU754C.js +0 -6
  158. package/dist/context-JTGSBJT6.cjs +0 -23
  159. package/dist/subagents-loader-AIVDQ2D5.js +0 -7
  160. package/dist/subagents-loader-DN4LETGL.cjs +0 -16
@@ -1,21 +1,22 @@
1
1
  import { submit, emitRunEvent } from './chunk-K2VMFZQ5.js';
2
- import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-2QKV4CGK.js';
3
- import { IndexManager } from './chunk-7SZAV6QG.js';
4
- import { loadHookConfig, warnOnce, currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-S6B5XYC3.js';
2
+ import { enqueueSessionWrite, hydrateSession, persistTurnToTranscript, flushSessionWrites, appendSessionMessage, getSessionMessages, discardSession, clearSession } from './chunk-CZWN4C6A.js';
3
+ import { IndexManager } from './chunk-P5S3WCSZ.js';
4
+ import { currentPersonalityContext, warnPersonalitySwitchInsideFork } from './chunk-DQNI52VV.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
- import { writeSessionSummary, resolveMemoryRoot, MEMORY_KINDS, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-SADXXGWU.js';
8
+ import { writeSessionSummary, resolveMemoryRoot, MEMORY_KINDS, appendFact, readFacts, legacyMemoryJsonPath, memoryMdPath, appendFactToMarkdown } from './chunk-R3LBRQAN.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-KZSKIUXZ.js';
10
+ import { discoverProviderPlugins, validateApiKeyShape, getConfiguredBaseUrl, httpRequest, isFixtureApiKey, presentProviderCredentialEnvVars, buildDefaultSummarizer, shouldUseRealLocalRuntime, parseSseStream, CircuitBreaker, resolveRunProvider, mergeExplicitApiKey, resolveProviderChain, abortError, tryFirstEvent, relayStream, renderToolResultContentText } from './chunk-N7VAE6DZ.js';
11
11
  import { resolveChildEnv } from './chunk-HKCKOAIO.js';
12
- import { DEFAULT_MAX_BYTES_PER_FILE, runDiscovery, truncateWithMarker } from './chunk-N6OOOYFZ.js';
12
+ import { DEFAULT_MAX_BYTES_PER_FILE, runDiscovery, truncateWithMarker } from './chunk-3VXQEQE4.js';
13
+ import { warnFailureOnce, loadHookConfig, warnOnce } from './chunk-7C3HWGCW.js';
13
14
  import { readVersionedJson, writeVersionedJson } from './chunk-SVQIW5RJ.js';
14
15
  import { toJsonSchema } from './chunk-7I5Z3UBJ.js';
15
16
  import { sanitizeToolInput } from './chunk-FJWQP6EE.js';
16
17
  import { withInheritedSubAgentCredentials, subAgentToolsFromDefinitions } from './chunk-CFE6QF2Q.js';
17
18
  import { setAgentFacade } from './chunk-6X6ID4MO.js';
18
- import { escapeBlockBody, buildSkillsBlock, discoverSkills, stripSkillFrontmatter } from './chunk-LX7SEXOQ.js';
19
+ import { escapeBlockBody, buildSkillsBlock, discoverSkills, stripSkillFrontmatter } from './chunk-CA5VUAP3.js';
19
20
  import { withToolWhitelist, checkToolWhitelist } from './chunk-SAGRF4IB.js';
20
21
  import { validateArtifactPath, PathTraversalError, safePathJoin } from './chunk-EH6XD3FY.js';
21
22
  import { insideRoot, atOrInsideRoot } from './chunk-UKMBRMGT.js';
@@ -24,9 +25,9 @@ import { expandTilde, defaultBaseDir } from './chunk-JOFVLOFY.js';
24
25
  import { withFileLock } from './chunk-TA3K7SBK.js';
25
26
  import { withCwdMutex } from './chunk-Q5EWJPRY.js';
26
27
  import { sweepStaleAtomicTemps, atomicWriteJson } from './chunk-3JHIFQ4I.js';
27
- import { loadSubagents, pluginBundleDirs } from './chunk-O7L7M42F.js';
28
- import { reportUndeclaredSources, theokitConfigRoot, undefinedVariablesIn, getTheokitHome, adapterForConfigPath, projectConfigRoots, pluginBundleRoots } from './chunk-NSLHPAC7.js';
29
- import { readWorkspaceDir, parseSimpleYaml } from './chunk-JNAA4G4H.js';
28
+ import { loadSubagents, pluginBundleDirs } from './chunk-T3ZDEYTJ.js';
29
+ import { reportUndeclaredSources, theokitConfigRoot, undefinedVariablesIn, getTheokitHome, adapterForConfigPath, adaptersForSurface, projectConfigRoots, pluginBundleRoots } from './chunk-X7EUUHXU.js';
30
+ import { readWorkspaceDir, parseSimpleYaml } from './chunk-UOLBAPDM.js';
30
31
  import { resolveEffectiveContextWindow, CONTEXT_WINDOW_FLOOR, CONTEXT_WINDOW_MARGIN } from './chunk-6M2OIS4Y.js';
31
32
  import { parseModelId } from './chunk-R7WIIPUR.js';
32
33
  import { getProviderProfile } from './chunk-XYFGKVZ7.js';
@@ -38,6 +39,7 @@ import { stat, mkdir, readFile, readdir, access, unlink } from 'fs/promises';
38
39
  import { randomUUID, createHash } from 'crypto';
39
40
  import { join, dirname, resolve, relative, isAbsolute } from 'path';
40
41
  import { existsSync, readFileSync } from 'fs';
42
+ import { platform } from 'process';
41
43
  import { spawn } from 'child_process';
42
44
  import { z } from 'zod';
43
45
  import { createRequire } from 'module';
@@ -2550,6 +2552,116 @@ function readCompatConfigFile(cwd) {
2550
2552
  function resolveCompatSources(options, cwd) {
2551
2553
  return options.local?.compatSources ?? readCompatConfigFile(cwd);
2552
2554
  }
2555
+ var KNOWN_KEYS = /* @__PURE__ */ new Set([
2556
+ "disableAllHooks",
2557
+ "disableSkillShellExecution",
2558
+ "permissions",
2559
+ "permissionMode"
2560
+ ]);
2561
+ function managedSettingsPathFor(root) {
2562
+ if (root !== void 0) return join(root, "claude-code", "managed-settings.json");
2563
+ if (platform === "darwin") {
2564
+ return "/Library/Application Support/ClaudeCode/managed-settings.json";
2565
+ }
2566
+ if (platform === "win32") {
2567
+ const programData = process.env.PROGRAMDATA ?? "C:\\ProgramData";
2568
+ return join(programData, "ClaudeCode", "managed-settings.json");
2569
+ }
2570
+ return "/etc/claude-code/managed-settings.json";
2571
+ }
2572
+ function readManagedSettings(root) {
2573
+ const path = managedSettingsPathFor(root);
2574
+ const parsed = readPolicyDocument(path);
2575
+ if (parsed === void 0) return {};
2576
+ const out = {};
2577
+ for (const [key, value] of Object.entries(parsed)) {
2578
+ applyPolicyKey(out, key, value, path);
2579
+ }
2580
+ return out;
2581
+ }
2582
+ function readPolicyDocument(path) {
2583
+ if (!existsSync(path)) return void 0;
2584
+ let raw;
2585
+ try {
2586
+ raw = readFileSync(path, "utf8");
2587
+ } catch (cause) {
2588
+ diagFailure(
2589
+ `[theokit-sdk] ${path} exists and could not be read (${cause.message}) \u2014 NO operator policy is being applied. Fix the permissions or remove the file.
2590
+ `
2591
+ );
2592
+ return void 0;
2593
+ }
2594
+ let parsed;
2595
+ try {
2596
+ parsed = JSON.parse(raw);
2597
+ } catch (cause) {
2598
+ diagFailure(
2599
+ `[theokit-sdk] ${path} is not valid JSON (${cause.message}) \u2014 NO operator policy is being applied.
2600
+ `
2601
+ );
2602
+ return void 0;
2603
+ }
2604
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
2605
+ diagFailure(
2606
+ `[theokit-sdk] ${path} is not a JSON object \u2014 NO operator policy is being applied.
2607
+ `
2608
+ );
2609
+ return void 0;
2610
+ }
2611
+ return parsed;
2612
+ }
2613
+ var PERMISSION_MODES = ["default", "plan", "acceptEdits", "bypass"];
2614
+ function applyPolicyKey(out, key, value, path) {
2615
+ if (!KNOWN_KEYS.has(key)) {
2616
+ decline(path, key, "this runtime does not enforce it");
2617
+ return;
2618
+ }
2619
+ if (key === "permissionMode") {
2620
+ const mode = readMode(value, path);
2621
+ if (mode !== void 0) out.permissionMode = mode;
2622
+ return;
2623
+ }
2624
+ if (key === "permissions") {
2625
+ const rules = readRuleLists(value, path);
2626
+ if (rules !== void 0) out.permissions = rules;
2627
+ return;
2628
+ }
2629
+ const flag = readBoolean(value, key, path);
2630
+ if (flag === void 0) return;
2631
+ if (key === "disableAllHooks") out.disableAllHooks = flag;
2632
+ if (key === "disableSkillShellExecution") out.disableSkillShellExecution = flag;
2633
+ }
2634
+ function decline(path, key, reason) {
2635
+ diagFailure(`[theokit-sdk] ${path} declares "${key}" \u2014 ${reason}. It is NOT being applied.
2636
+ `);
2637
+ }
2638
+ function readMode(value, path) {
2639
+ if (typeof value === "string" && PERMISSION_MODES.includes(value)) {
2640
+ return value;
2641
+ }
2642
+ decline(
2643
+ path,
2644
+ "permissionMode",
2645
+ `${JSON.stringify(value)} is not one of ${PERMISSION_MODES.join(", ")}`
2646
+ );
2647
+ return void 0;
2648
+ }
2649
+ function readRuleLists(value, path) {
2650
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
2651
+ return value;
2652
+ }
2653
+ decline(
2654
+ path,
2655
+ "permissions",
2656
+ `it is ${Array.isArray(value) ? "an array" : typeof value}, not an object of rule lists`
2657
+ );
2658
+ return void 0;
2659
+ }
2660
+ function readBoolean(value, key, path) {
2661
+ if (typeof value === "boolean") return value;
2662
+ decline(path, key, `it is ${typeof value}, not a boolean`);
2663
+ return void 0;
2664
+ }
2553
2665
  function spawnAndCollect(options) {
2554
2666
  return new Promise((resolve) => {
2555
2667
  const timeoutMs = options.timeoutMs ?? 3e4;
@@ -2600,16 +2712,26 @@ function spawnAndCollect(options) {
2600
2712
 
2601
2713
  // src/internal/runtime/hooks/hooks-executor.ts
2602
2714
  var HooksExecutor = class {
2603
- constructor(cwd, compatSources = [], gate = void 0) {
2715
+ constructor(cwd, compatSources = [], gate = void 0, policy = {}) {
2604
2716
  this.cwd = cwd;
2605
2717
  this.compatSources = compatSources;
2606
2718
  this.gate = gate;
2719
+ this.policy = policy;
2607
2720
  }
2608
2721
  cwd;
2609
2722
  compatSources;
2610
2723
  gate;
2724
+ policy;
2611
2725
  config = {};
2612
2726
  async initialize(settingSourcesIncludeProject) {
2727
+ if (readManagedSettings(this.policy.managedSettingsRoot).disableAllHooks === true) {
2728
+ warnFailureOnce(
2729
+ "hooks-disabled-by-policy",
2730
+ "[theokit-sdk] hooks: an operator policy (managed-settings.json) declares disableAllHooks \u2014 NO hook will run, including any this project declared."
2731
+ );
2732
+ this.config = {};
2733
+ return;
2734
+ }
2613
2735
  if (!settingSourcesIncludeProject) {
2614
2736
  this.config = {};
2615
2737
  return;
@@ -2681,7 +2803,7 @@ var HooksExecutor = class {
2681
2803
  cwd: this.cwd,
2682
2804
  ...Object.keys(env).length > 0 ? { env } : {},
2683
2805
  timeoutMs,
2684
- stdin: JSON.stringify(payload)
2806
+ stdin: JSON.stringify(stdinPayloadFor(payload, command, this.cwd))
2685
2807
  });
2686
2808
  const failure = this.decisionFromFailure(result, command, env, timeoutMs);
2687
2809
  return failure ?? parseDecisionFromStdout(result.stdout);
@@ -2695,9 +2817,16 @@ var HooksExecutor = class {
2695
2817
  * spawned.
2696
2818
  */
2697
2819
  decisionFromFailure(result, command, env, timeoutMs) {
2698
- if (result.timedOut) return { decision: "deny", reason: `Hook timed out after ${timeoutMs}ms` };
2820
+ if (result.timedOut)
2821
+ return {
2822
+ decision: "deny",
2823
+ reason: `Hook timed out after ${timeoutMs}ms`
2824
+ };
2699
2825
  if (result.spawnError !== void 0) {
2700
- return { decision: "deny", reason: `Hook spawn failed: ${result.spawnError.message}` };
2826
+ return {
2827
+ decision: "deny",
2828
+ reason: `Hook spawn failed: ${result.spawnError.message}`
2829
+ };
2701
2830
  }
2702
2831
  if (result.exitCode === 0) return void 0;
2703
2832
  const stderr = result.stderr.trim();
@@ -2710,6 +2839,16 @@ var HooksExecutor = class {
2710
2839
  };
2711
2840
  }
2712
2841
  };
2842
+ function stdinPayloadFor(payload, command, cwd) {
2843
+ return {
2844
+ ...payload,
2845
+ cwd,
2846
+ ...command.sourceEvent === void 0 ? {} : { hook_event_name: command.sourceEvent },
2847
+ ...payload.tool === void 0 ? {} : { tool_name: payload.tool },
2848
+ ...payload.input === void 0 ? {} : { tool_input: payload.input },
2849
+ ...payload.output === void 0 ? {} : { tool_response: payload.output }
2850
+ };
2851
+ }
2713
2852
  function runtimeEnvFor(sourcePath, cwd) {
2714
2853
  if (sourcePath === void 0) return {};
2715
2854
  return adapterForConfigPath(sourcePath)?.runtimeEnv(cwd) ?? {};
@@ -2717,19 +2856,35 @@ function runtimeEnvFor(sourcePath, cwd) {
2717
2856
  function parseDecisionFromStdout(stdout) {
2718
2857
  const trimmed = stdout.trim();
2719
2858
  if (trimmed.length === 0) return { decision: "allow" };
2859
+ let parsed;
2720
2860
  try {
2721
- const parsed = JSON.parse(trimmed);
2722
- if (parsed.decision === "deny" || parsed.decision === "feedback") {
2723
- const result = { decision: parsed.decision };
2724
- if (parsed.reason !== void 0) result.reason = parsed.reason;
2725
- if (parsed.feedback !== void 0) result.feedback = parsed.feedback;
2726
- return result;
2727
- }
2728
- if (parsed.decision === "allow") return { decision: "allow" };
2861
+ parsed = JSON.parse(trimmed);
2729
2862
  } catch {
2730
2863
  return { decision: "feedback", feedback: trimmed };
2731
2864
  }
2732
- return { decision: "allow" };
2865
+ return nestedDecision(parsed) ?? flatDecision(parsed) ?? { decision: "allow" };
2866
+ }
2867
+ function nestedDecision(parsed) {
2868
+ const nested = parsed.hookSpecificOutput;
2869
+ if (nested?.permissionDecision === "allow") return { decision: "allow" };
2870
+ if (nested?.permissionDecision !== "deny" && nested?.permissionDecision !== "ask") {
2871
+ return void 0;
2872
+ }
2873
+ const result = { decision: "deny" };
2874
+ if (nested.permissionDecisionReason !== void 0) {
2875
+ result.reason = nested.permissionDecisionReason;
2876
+ }
2877
+ return result;
2878
+ }
2879
+ function flatDecision(parsed) {
2880
+ if (parsed.decision === "allow") return { decision: "allow" };
2881
+ if (parsed.decision !== "deny" && parsed.decision !== "block" && parsed.decision !== "feedback") {
2882
+ return void 0;
2883
+ }
2884
+ const result = parsed.decision === "feedback" ? { decision: "feedback" } : { decision: "deny" };
2885
+ if (parsed.reason !== void 0) result.reason = parsed.reason;
2886
+ if (parsed.feedback !== void 0) result.feedback = parsed.feedback;
2887
+ return result;
2733
2888
  }
2734
2889
 
2735
2890
  // src/internal/runtime/lifecycle/context-budget-event.ts
@@ -3043,7 +3198,15 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
3043
3198
  agentId: inputs.agentId,
3044
3199
  cwd: inputs.workspaceCwd,
3045
3200
  model: inputs.model,
3046
- skills: skills.map((skill) => ({ name: skill.name, description: skill.description })),
3201
+ // This is the ONLY place the model learns which skills exist, which is what makes
3202
+ // `disable-model-invocation` enforceable rather than decorative. The scaffold had been writing
3203
+ // authorization frontmatter that the parser discarded, so the default was disclose-all.
3204
+ //
3205
+ // A disclosure rule, not an execution rule: `skills.get(name)` still resolves a hidden skill,
3206
+ // because a caller naming one has already made the decision this field keeps away from the
3207
+ // model. Widening it to execution would break the case the field is FOR — a side-effecting
3208
+ // skill a human may run and the model may not propose.
3209
+ skills: skills.filter((skill) => skill.disableModelInvocation !== true).map((skill) => ({ name: skill.name, description: skill.description })),
3047
3210
  userMessage: userText,
3048
3211
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
3049
3212
  };
@@ -4067,14 +4230,24 @@ var ContextSourceFrontmatterSchema = z.object({
4067
4230
 
4068
4231
  // src/internal/runtime/context/context-manager.ts
4069
4232
  var FileContextManager = class {
4070
- constructor(cwd, settings, settingSourcesIncludeProject) {
4233
+ /**
4234
+ * @param compatSources - What the consumer declared in `local.compatSources` (or
4235
+ * `.theokit/config.json`), as `resolveCompatSources` resolved it. `undefined` means the caller
4236
+ * did not thread the declaration through at all and every dialect runs — the pre-#652 behaviour,
4237
+ * kept so an internal caller constructing this directly does not silently lose content. An empty
4238
+ * ARRAY is different and is the fix: it means the consumer declared no foreign dialect, so
4239
+ * `.claude/rules/*.md` does not reach the prompt.
4240
+ */
4241
+ constructor(cwd, settings, settingSourcesIncludeProject, compatSources) {
4071
4242
  this.cwd = cwd;
4072
4243
  this.settings = settings;
4073
4244
  this.settingSourcesIncludeProject = settingSourcesIncludeProject;
4245
+ this.compatSources = compatSources;
4074
4246
  }
4075
4247
  cwd;
4076
4248
  settings;
4077
4249
  settingSourcesIncludeProject;
4250
+ compatSources;
4078
4251
  state;
4079
4252
  /**
4080
4253
  * The in-scope file set used by the most recent `refresh`. Tracked so
@@ -4083,6 +4256,19 @@ var FileContextManager = class {
4083
4256
  * snapshot untouched, at zero per-send cost.
4084
4257
  */
4085
4258
  lastScope = [];
4259
+ /**
4260
+ * The dialect kinds granted the `context` surface, or `undefined` when nothing was declared to
4261
+ * this instance.
4262
+ *
4263
+ * Routed through `adaptersForSurface` rather than reading `.kind` off the declarations, so the
4264
+ * three fail-closed rules #524 established govern this surface identically to the other four: a
4265
+ * bare string admits everything, an object with no `import` admits nothing, and an unrecognised
4266
+ * surface name narrows rather than widens.
4267
+ */
4268
+ grantedContextDialects() {
4269
+ if (this.compatSources === void 0) return void 0;
4270
+ return adaptersForSurface(this.compatSources, "context").map((a) => a.kind);
4271
+ }
4086
4272
  async initialize() {
4087
4273
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
4088
4274
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -4110,11 +4296,16 @@ var FileContextManager = class {
4110
4296
  const legacy = await loadSources(config, this.cwd);
4111
4297
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
4112
4298
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
4299
+ const granted = this.grantedContextDialects();
4113
4300
  const discovered = await runDiscovery({
4114
4301
  cwd: this.cwd,
4115
4302
  maxBytesPerFile,
4116
4303
  skipLegacyTheokitContext: true,
4117
- touchedFiles
4304
+ touchedFiles,
4305
+ // #652 — the grant this path never consulted. Without it, a consumer who enabled project
4306
+ // scope for its OWN `.theokit/` also received a cloned repository's `.claude/rules/*.md`,
4307
+ // through a door the hooks/skills/subagents/plugins gate does not cover.
4308
+ ...granted === void 0 ? {} : { declaredCompatKinds: granted }
4118
4309
  });
4119
4310
  const legacyAsAggregator = legacy.filter((src) => src.status !== "excluded").map((src) => ({
4120
4311
  id: src.name,
@@ -4509,7 +4700,12 @@ function buildContext(args, out) {
4509
4700
  out.context = new FileContextManager(
4510
4701
  args.workspaceCwd,
4511
4702
  args.options.context,
4512
- args.settingSourcesIncludeProject
4703
+ args.settingSourcesIncludeProject,
4704
+ // #652 — the same declaration `buildSkills` and `buildPlugins` already pass. Omitting it here
4705
+ // is what let a foreign root's instructions into the system prompt while its skills, subagents,
4706
+ // hooks and plugins were correctly withheld: four surfaces failing closed and a fifth nobody
4707
+ // had wired to the gate.
4708
+ resolveCompatSources(args.options, args.workspaceCwd)
4513
4709
  );
4514
4710
  }
4515
4711
  function buildProviders(args, out) {
@@ -9157,7 +9353,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
9157
9353
  async function localAgentFork(parent, options) {
9158
9354
  const { forkAgentImpl } = await import('./fork-agent-S2EPIML7.js');
9159
9355
  const { getAgentFacade } = await import('./agent-factory-registry-ZVTABLEY.js');
9160
- const { withPersonalityContext } = await import('./context-3HPU754C.js');
9356
+ const { withPersonalityContext } = await import('./context-OJIIXJCV.js');
9161
9357
  const create = getAgentFacade().create;
9162
9358
  return withPersonalityContext(
9163
9359
  { slug: parent.personalitySlugSnapshot, isFork: true },
@@ -10856,7 +11052,7 @@ var Agent = class _Agent {
10856
11052
  */
10857
11053
  static async compact(agentId, options = {}) {
10858
11054
  const reg = await requireLocalAgent(agentId, "compact");
10859
- const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-YSEK7NQF.js');
11055
+ const { compactSessionTranscript, buildDefaultSummarizer: buildDefaultSummarizer2 } = await import('./compact-session-QT6RJOKO.js');
10860
11056
  const { cwd, model, store } = await openLocalStore(reg);
10861
11057
  return enqueueSessionWrite(
10862
11058
  cwd,
@@ -10869,7 +11065,10 @@ var Agent = class _Agent {
10869
11065
  summarize: options.summarize ?? buildDefaultSummarizer2({
10870
11066
  agentModel: model,
10871
11067
  ...reg.options.apiKey !== void 0 ? { apiKey: reg.options.apiKey } : {}
10872
- })
11068
+ }),
11069
+ ...options.onPreCompact !== void 0 ? { onPreCompact: options.onPreCompact } : {},
11070
+ ...options.onPreCompactError !== void 0 ? { onPreCompactError: options.onPreCompactError } : {},
11071
+ ...options.preCompactTimeoutMs !== void 0 ? { preCompactTimeoutMs: options.preCompactTimeoutMs } : {}
10873
11072
  })
10874
11073
  );
10875
11074
  }
@@ -10883,7 +11082,7 @@ var Agent = class _Agent {
10883
11082
  */
10884
11083
  static async injectSessionTurn(agentId, turn) {
10885
11084
  const reg = await requireLocalAgent(agentId, "injectSessionTurn");
10886
- const { injectSessionTurn } = await import('./inject-session-J4LBWAPH.js');
11085
+ const { injectSessionTurn } = await import('./inject-session-XWWN4DAA.js');
10887
11086
  const { cwd, model, store } = await openLocalStore(reg);
10888
11087
  await injectSessionTurn({
10889
11088
  store,
@@ -10934,7 +11133,7 @@ var Agent = class _Agent {
10934
11133
  */
10935
11134
  static async describe(agentId) {
10936
11135
  const agent = await getRegisteredAgentOrThrow(agentId);
10937
- const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-AIVDQ2D5.js');
11136
+ const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-CJFYQQU2.js');
10938
11137
  const settingSources = agent.options.local?.settingSources;
10939
11138
  const subagents = await loadSubagents2(
10940
11139
  agent.cwd ?? process.cwd(),
@@ -11040,6 +11239,6 @@ async function openLocalStore(reg) {
11040
11239
  return { cwd, model, store: new FsSessionStore2({ baseDir, cwd }) };
11041
11240
  }
11042
11241
 
11043
- export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, openRouterMemoryEmbeddingProviderAdapter, resolveSessionDir };
11044
- //# sourceMappingURL=chunk-ODBID5TG.js.map
11045
- //# sourceMappingURL=chunk-ODBID5TG.js.map
11242
+ export { Agent, AgentBuilder, DEFAULT_AGENTIC_MODEL_ID, MEMORY_EMBEDDING_ADAPTERS, Tool, ToolError, UsageAccumulator, computeCost, generateCronId, getPricingEntry, managedSettingsPathFor, openRouterMemoryEmbeddingProviderAdapter, readManagedSettings, resolveSessionDir };
11243
+ //# sourceMappingURL=chunk-FUUSIT2T.js.map
11244
+ //# sourceMappingURL=chunk-FUUSIT2T.js.map