@theokit/sdk 5.4.0 → 5.6.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 (132) hide show
  1. package/CHANGELOG.md +642 -0
  2. package/dist/{agent-AUVD4TI4.cjs → agent-47NS6ZVL.cjs} +13 -13
  3. package/dist/{agent-AUVD4TI4.cjs.map → agent-47NS6ZVL.cjs.map} +1 -1
  4. package/dist/{agent-C1Efo7PI.d.cts → agent-82d_DrCL.d.cts} +33 -2
  5. package/dist/{agent-Bmy2G_ml.d.ts → agent-G6g-uwcB.d.ts} +33 -2
  6. package/dist/{agent-MNINE73R.js → agent-JJZM2VIK.js} +12 -12
  7. package/dist/{agent-MNINE73R.js.map → agent-JJZM2VIK.js.map} +1 -1
  8. package/dist/{chunk-IKBLU7ZS.js → chunk-2UXQASTX.js} +232 -32
  9. package/dist/chunk-2UXQASTX.js.map +1 -0
  10. package/dist/{chunk-VPK6PHIE.cjs → chunk-52FDUJSV.cjs} +8 -8
  11. package/dist/{chunk-VPK6PHIE.cjs.map → chunk-52FDUJSV.cjs.map} +1 -1
  12. package/dist/{chunk-2XRAWOZZ.js → chunk-5NELQ6LB.js} +65 -3
  13. package/dist/chunk-5NELQ6LB.js.map +1 -0
  14. package/dist/{chunk-3FDU5JFE.cjs → chunk-7IZKTQ5G.cjs} +35 -7
  15. package/dist/chunk-7IZKTQ5G.cjs.map +1 -0
  16. package/dist/{chunk-7SZAV6QG.js → chunk-7MMTZBTT.js} +3 -3
  17. package/dist/{chunk-7SZAV6QG.js.map → chunk-7MMTZBTT.js.map} +1 -1
  18. package/dist/{chunk-SADXXGWU.js → chunk-BZ3YMAMP.js} +3 -3
  19. package/dist/{chunk-NQTNSHSB.cjs.map → chunk-BZ3YMAMP.js.map} +1 -1
  20. package/dist/{chunk-LX7SEXOQ.js → chunk-CA5VUAP3.js} +25 -7
  21. package/dist/chunk-CA5VUAP3.js.map +1 -0
  22. package/dist/{chunk-IU5N5224.cjs → chunk-EIOMN5VA.cjs} +8 -8
  23. package/dist/chunk-EIOMN5VA.cjs.map +1 -0
  24. package/dist/{chunk-KWGSBZ2Q.js → chunk-FPIY5CLV.js} +3 -3
  25. package/dist/{chunk-KWGSBZ2Q.js.map → chunk-FPIY5CLV.js.map} +1 -1
  26. package/dist/{chunk-UALC6Q3J.cjs → chunk-GCHZMH42.cjs} +290 -88
  27. package/dist/chunk-GCHZMH42.cjs.map +1 -0
  28. package/dist/{chunk-NQTNSHSB.cjs → chunk-GFFBXSQT.cjs} +5 -5
  29. package/dist/chunk-GFFBXSQT.cjs.map +1 -0
  30. package/dist/{chunk-J6KZE2ZQ.cjs → chunk-HG4UN4MN.cjs} +4 -4
  31. package/dist/{chunk-J6KZE2ZQ.cjs.map → chunk-HG4UN4MN.cjs.map} +1 -1
  32. package/dist/{chunk-N6OOOYFZ.js → chunk-HUDNLFY4.js} +4 -4
  33. package/dist/chunk-HUDNLFY4.js.map +1 -0
  34. package/dist/{chunk-LOHMT36V.cjs → chunk-LD6HASA5.cjs} +65 -2
  35. package/dist/chunk-LD6HASA5.cjs.map +1 -0
  36. package/dist/{chunk-QATRS7JD.cjs → chunk-MYJGWS2J.cjs} +26 -8
  37. package/dist/chunk-MYJGWS2J.cjs.map +1 -0
  38. package/dist/{chunk-XD3FS5OI.js → chunk-N2KAIZ5D.js} +34 -7
  39. package/dist/chunk-N2KAIZ5D.js.map +1 -0
  40. package/dist/{chunk-HW7SEELD.cjs → chunk-QRVS2PRE.cjs} +31 -8
  41. package/dist/chunk-QRVS2PRE.cjs.map +1 -0
  42. package/dist/{chunk-AYA65JA5.cjs → chunk-RWPLWMCZ.cjs} +25 -9
  43. package/dist/chunk-RWPLWMCZ.cjs.map +1 -0
  44. package/dist/{chunk-WS5ULCL4.js → chunk-STGSMJMJ.js} +3 -3
  45. package/dist/{chunk-WS5ULCL4.js.map → chunk-STGSMJMJ.js.map} +1 -1
  46. package/dist/{chunk-O7L7M42F.js → chunk-T3ZDEYTJ.js} +21 -5
  47. package/dist/chunk-T3ZDEYTJ.js.map +1 -0
  48. package/dist/{chunk-43YXGD3P.cjs → chunk-TY56BKSK.cjs} +8 -4
  49. package/dist/chunk-TY56BKSK.cjs.map +1 -0
  50. package/dist/chunk-UOLBAPDM.js +66 -0
  51. package/dist/chunk-UOLBAPDM.js.map +1 -0
  52. package/dist/{chunk-Z2JFX372.cjs → chunk-VUHXC74Q.cjs} +15 -15
  53. package/dist/{chunk-Z2JFX372.cjs.map → chunk-VUHXC74Q.cjs.map} +1 -1
  54. package/dist/{chunk-NSLHPAC7.js → chunk-X7EUUHXU.js} +6 -5
  55. package/dist/chunk-X7EUUHXU.js.map +1 -0
  56. package/dist/context/index.cjs +7 -7
  57. package/dist/context/index.js +3 -3
  58. package/dist/{context-4AIK26QB.cjs → context-HR4KMXMA.cjs} +7 -7
  59. package/dist/{context-4AIK26QB.cjs.map → context-HR4KMXMA.cjs.map} +1 -1
  60. package/dist/context-J5BJ3LBS.js +6 -0
  61. package/dist/{context-EGM6CHXD.js.map → context-J5BJ3LBS.js.map} +1 -1
  62. package/dist/{cron-DSMdlhyF.d.cts → cron-DWv69ZSD.d.cts} +1 -1
  63. package/dist/{cron-Dcdrdv_T.d.ts → cron-GynWtAax.d.ts} +1 -1
  64. package/dist/cron.cjs +12 -12
  65. package/dist/cron.d.cts +2 -2
  66. package/dist/cron.d.ts +2 -2
  67. package/dist/cron.js +11 -11
  68. package/dist/eval.cjs +11 -11
  69. package/dist/eval.js +10 -10
  70. package/dist/{index-manager-W7FDMGEG.js → index-manager-27WLNQEE.js} +5 -5
  71. package/dist/{index-manager-W7FDMGEG.js.map → index-manager-27WLNQEE.js.map} +1 -1
  72. package/dist/{index-manager-3UNPYH34.cjs → index-manager-BBHDKMQS.cjs} +6 -6
  73. package/dist/{index-manager-3UNPYH34.cjs.map → index-manager-BBHDKMQS.cjs.map} +1 -1
  74. package/dist/index.cjs +274 -40
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.d.cts +168 -5
  77. package/dist/index.d.ts +168 -5
  78. package/dist/index.js +246 -23
  79. package/dist/index.js.map +1 -1
  80. package/dist/internal/memory/storage/index.cjs +32 -32
  81. package/dist/internal/memory/storage/index.js +3 -3
  82. package/dist/internal/memory/storage/memory-root.d.cts +27 -0
  83. package/dist/internal/memory/storage/memory-root.d.ts +27 -0
  84. package/dist/internal/persistence/index.cjs +4 -4
  85. package/dist/internal/persistence/index.js +1 -1
  86. package/dist/internal/runtime/compat/foreign-config-sources.d.ts +17 -4
  87. package/dist/internal/runtime/compat/managed-settings.d.ts +80 -0
  88. package/dist/internal/runtime/context/context-discovery-runner.d.ts +14 -0
  89. package/dist/internal/runtime/context/context-discovery.d.ts +37 -0
  90. package/dist/internal/runtime/context/context-manager.d.ts +21 -1
  91. package/dist/internal/runtime/context/yaml-frontmatter.d.ts +6 -3
  92. package/dist/internal/runtime/hooks/hooks-executor.d.ts +23 -1
  93. package/dist/internal/runtime/hooks/hooks-source.d.ts +46 -1
  94. package/dist/internal/runtime/skills/discover-skills.d.ts +4 -0
  95. package/dist/project.cjs +3 -3
  96. package/dist/project.js +1 -1
  97. package/dist/skills.cjs +5 -5
  98. package/dist/skills.js +2 -2
  99. package/dist/subagents-loader-CJFYQQU2.js +7 -0
  100. package/dist/{subagents-loader-AIVDQ2D5.js.map → subagents-loader-CJFYQQU2.js.map} +1 -1
  101. package/dist/subagents-loader-MOO7DC4E.cjs +16 -0
  102. package/dist/{subagents-loader-DN4LETGL.cjs.map → subagents-loader-MOO7DC4E.cjs.map} +1 -1
  103. package/dist/subagents-loader.cjs +4 -4
  104. package/dist/subagents-loader.d.cts +1 -1
  105. package/dist/subagents-loader.d.ts +1 -1
  106. package/dist/subagents-loader.js +3 -3
  107. package/dist/types/agent.d.ts +6 -1
  108. package/dist/types/hooks.d.ts +22 -0
  109. package/docs/error-codes.md +20 -18
  110. package/docs/harness-capability-map.md +9 -1
  111. package/package.json +1 -1
  112. package/dist/chunk-2XRAWOZZ.js.map +0 -1
  113. package/dist/chunk-3FDU5JFE.cjs.map +0 -1
  114. package/dist/chunk-43YXGD3P.cjs.map +0 -1
  115. package/dist/chunk-AYA65JA5.cjs.map +0 -1
  116. package/dist/chunk-HW7SEELD.cjs.map +0 -1
  117. package/dist/chunk-IKBLU7ZS.js.map +0 -1
  118. package/dist/chunk-IU5N5224.cjs.map +0 -1
  119. package/dist/chunk-JNAA4G4H.js +0 -43
  120. package/dist/chunk-JNAA4G4H.js.map +0 -1
  121. package/dist/chunk-LOHMT36V.cjs.map +0 -1
  122. package/dist/chunk-LX7SEXOQ.js.map +0 -1
  123. package/dist/chunk-N6OOOYFZ.js.map +0 -1
  124. package/dist/chunk-NSLHPAC7.js.map +0 -1
  125. package/dist/chunk-O7L7M42F.js.map +0 -1
  126. package/dist/chunk-QATRS7JD.cjs.map +0 -1
  127. package/dist/chunk-SADXXGWU.js.map +0 -1
  128. package/dist/chunk-UALC6Q3J.cjs.map +0 -1
  129. package/dist/chunk-XD3FS5OI.js.map +0 -1
  130. package/dist/context-EGM6CHXD.js +0 -6
  131. package/dist/subagents-loader-AIVDQ2D5.js +0 -7
  132. package/dist/subagents-loader-DN4LETGL.cjs +0 -16
@@ -2,22 +2,22 @@
2
2
 
3
3
  var chunkKVSAY6NZ_cjs = require('./chunk-KVSAY6NZ.cjs');
4
4
  var chunkDZG77WU7_cjs = require('./chunk-DZG77WU7.cjs');
5
- var chunkZ2JFX372_cjs = require('./chunk-Z2JFX372.cjs');
6
- var chunk3FDU5JFE_cjs = require('./chunk-3FDU5JFE.cjs');
5
+ var chunkVUHXC74Q_cjs = require('./chunk-VUHXC74Q.cjs');
6
+ var chunk7IZKTQ5G_cjs = require('./chunk-7IZKTQ5G.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');
10
- var chunkNQTNSHSB_cjs = require('./chunk-NQTNSHSB.cjs');
10
+ var chunkGFFBXSQT_cjs = require('./chunk-GFFBXSQT.cjs');
11
11
  var chunk7FDKWDA2_cjs = require('./chunk-7FDKWDA2.cjs');
12
12
  var chunkC4ZQPWXJ_cjs = require('./chunk-C4ZQPWXJ.cjs');
13
13
  var chunk2ZPEDVLM_cjs = require('./chunk-2ZPEDVLM.cjs');
14
- var chunkIU5N5224_cjs = require('./chunk-IU5N5224.cjs');
14
+ var chunkEIOMN5VA_cjs = require('./chunk-EIOMN5VA.cjs');
15
15
  var chunkRQMCOFAI_cjs = require('./chunk-RQMCOFAI.cjs');
16
16
  var chunkAA27GEYS_cjs = require('./chunk-AA27GEYS.cjs');
17
17
  var chunkYSTXFWQE_cjs = require('./chunk-YSTXFWQE.cjs');
18
18
  var chunkNQTD6QOW_cjs = require('./chunk-NQTD6QOW.cjs');
19
19
  var chunkNINIJCHU_cjs = require('./chunk-NINIJCHU.cjs');
20
- var chunkQATRS7JD_cjs = require('./chunk-QATRS7JD.cjs');
20
+ var chunkMYJGWS2J_cjs = require('./chunk-MYJGWS2J.cjs');
21
21
  var chunkIJ7M6GOG_cjs = require('./chunk-IJ7M6GOG.cjs');
22
22
  var chunk7A6535RA_cjs = require('./chunk-7A6535RA.cjs');
23
23
  var chunkSA6K24NB_cjs = require('./chunk-SA6K24NB.cjs');
@@ -26,9 +26,9 @@ 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 chunkAYA65JA5_cjs = require('./chunk-AYA65JA5.cjs');
30
- var chunk43YXGD3P_cjs = require('./chunk-43YXGD3P.cjs');
31
- var chunkHW7SEELD_cjs = require('./chunk-HW7SEELD.cjs');
29
+ var chunkRWPLWMCZ_cjs = require('./chunk-RWPLWMCZ.cjs');
30
+ var chunkTY56BKSK_cjs = require('./chunk-TY56BKSK.cjs');
31
+ var chunkQRVS2PRE_cjs = require('./chunk-QRVS2PRE.cjs');
32
32
  var chunkATT276RD_cjs = require('./chunk-ATT276RD.cjs');
33
33
  var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
34
34
  var chunkANMJJD6D_cjs = require('./chunk-ANMJJD6D.cjs');
@@ -40,6 +40,7 @@ var promises = require('fs/promises');
40
40
  var crypto = require('crypto');
41
41
  var path = require('path');
42
42
  var fs = require('fs');
43
+ var process$1 = require('process');
43
44
  var child_process = require('child_process');
44
45
  var zod = require('zod');
45
46
  var module$1 = require('module');
@@ -383,7 +384,7 @@ function serializeAgents(agents2) {
383
384
  return out;
384
385
  }
385
386
  function registryPath(cwd) {
386
- return path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), REGISTRY_RELATIVE_SUFFIX);
387
+ return path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), REGISTRY_RELATIVE_SUFFIX);
387
388
  }
388
389
  async function loadRegistry(cwd) {
389
390
  void chunkJLRLCBJ4_cjs.sweepStaleAtomicTemps(registryPath(cwd)).catch(() => void 0);
@@ -818,7 +819,7 @@ async function readLegacyFacts(jsonPath) {
818
819
  }
819
820
  async function writeMigratedFacts(cwd, jsonPath, facts) {
820
821
  try {
821
- for (const fact of facts) await chunkNQTNSHSB_cjs.appendFactToMarkdown(cwd, fact);
822
+ for (const fact of facts) await chunkGFFBXSQT_cjs.appendFactToMarkdown(cwd, fact);
822
823
  await promises.unlink(jsonPath).catch(() => void 0);
823
824
  chunk6LHQPOMI_cjs.diag(`[theokit-sdk] migrated ${facts.length} fact(s) from ${jsonPath} to MEMORY.md
824
825
  `);
@@ -835,11 +836,11 @@ async function migrateLegacyJson(cwd, config) {
835
836
  const key = `${cwd}::${config.namespace ?? "default"}::${config.scope ?? "agent"}::${config.userId ?? "default"}`;
836
837
  if (migrationRun.has(key)) return { migrated: false, factCount: 0, reason: "already-migrated" };
837
838
  migrationRun.add(key);
838
- const jsonPath = chunkNQTNSHSB_cjs.legacyMemoryJsonPath(cwd, config);
839
+ const jsonPath = chunkGFFBXSQT_cjs.legacyMemoryJsonPath(cwd, config);
839
840
  if (!await fileExists(jsonPath)) {
840
841
  return { migrated: false, factCount: 0, reason: "no-legacy-json" };
841
842
  }
842
- if (await fileExists(chunkNQTNSHSB_cjs.memoryMdPath(chunkNQTNSHSB_cjs.resolveMemoryRoot(cwd, config)))) {
843
+ if (await fileExists(chunkGFFBXSQT_cjs.memoryMdPath(chunkGFFBXSQT_cjs.resolveMemoryRoot(cwd, config)))) {
843
844
  chunk6LHQPOMI_cjs.diag(
844
845
  `[theokit-sdk] memory migration skipped: both MEMORY.md and legacy JSON exist at ${jsonPath}; leaving both intact
845
846
  `
@@ -868,19 +869,19 @@ function unstoredRememberWarning(message) {
868
869
  if (isMemoryWritePrompt(message) && extractMemoryFact(message).length > 0) return void 0;
869
870
  const trimmed = message.trim();
870
871
  const quoted = trimmed.length > QUOTED_MESSAGE_MAX ? `${trimmed.slice(0, QUOTED_MESSAGE_MAX)}\u2026` : trimmed;
871
- return `[theokit-sdk] NOTHING WAS STORED \u2014 this message does not match the memory capture pattern: ${JSON.stringify(quoted)}. Supported: "Remember: <fact>" or "Remember (${chunkNQTNSHSB_cjs.MEMORY_KINDS.join("|")}): <fact>". It still reaches the session transcript, so a follow-up may answer from it \u2014 that is search over transcripts, not a durable memory.`;
872
+ return `[theokit-sdk] NOTHING WAS STORED \u2014 this message does not match the memory capture pattern: ${JSON.stringify(quoted)}. Supported: "Remember: <fact>" or "Remember (${chunkGFFBXSQT_cjs.MEMORY_KINDS.join("|")}): <fact>". It still reaches the session transcript, so a follow-up may answer from it \u2014 that is search over transcripts, not a durable memory.`;
872
873
  }
873
874
  function extractMemoryKind(message) {
874
875
  const match = REMEMBER_PATTERN.exec(message);
875
876
  const declared = match?.[1];
876
877
  if (declared === void 0) return void 0;
877
878
  const lowered = declared.toLowerCase();
878
- return chunkNQTNSHSB_cjs.MEMORY_KINDS.includes(lowered) ? lowered : void 0;
879
+ return chunkGFFBXSQT_cjs.MEMORY_KINDS.includes(lowered) ? lowered : void 0;
879
880
  }
880
881
  async function readMemoryFacts(cwd, config) {
881
882
  if (!config.enabled) return [];
882
883
  await migrateLegacyJson(cwd, config);
883
- return chunkNQTNSHSB_cjs.readFacts(cwd, config);
884
+ return chunkGFFBXSQT_cjs.readFacts(cwd, config);
884
885
  }
885
886
  async function appendMemoryFact(cwd, config, fact) {
886
887
  if (!config.enabled) return;
@@ -889,7 +890,7 @@ async function appendMemoryFact(cwd, config, fact) {
889
890
  text: chunk6LHQPOMI_cjs.redactSecrets(fact.text),
890
891
  ...fact.kind === void 0 ? {} : { kind: fact.kind }
891
892
  };
892
- await chunkNQTNSHSB_cjs.appendFact(cwd, config, sanitized);
893
+ await chunkGFFBXSQT_cjs.appendFact(cwd, config, sanitized);
893
894
  }
894
895
 
895
896
  // src/internal/runtime/fixtures/fixture-scripts.ts
@@ -2122,14 +2123,14 @@ async function readState(filePath) {
2122
2123
  try {
2123
2124
  parsed = JSON.parse(raw);
2124
2125
  } catch {
2125
- chunk3FDU5JFE_cjs.warnOnce(
2126
+ chunk7IZKTQ5G_cjs.warnOnce(
2126
2127
  "personality-store-json-parse",
2127
2128
  "[theokit-sdk] personality.json is malformed; treating as empty"
2128
2129
  );
2129
2130
  return emptyState();
2130
2131
  }
2131
2132
  if (!isStateV1(parsed)) {
2132
- chunk3FDU5JFE_cjs.warnOnce(
2133
+ chunk7IZKTQ5G_cjs.warnOnce(
2133
2134
  "personality-store-bad-version",
2134
2135
  `[theokit-sdk] personality.json has unknown version; treating as empty (file kept untouched)`
2135
2136
  );
@@ -2160,7 +2161,7 @@ var PersonalityStore = class {
2160
2161
  try {
2161
2162
  await this.#persist(agentId, slug);
2162
2163
  } catch (err) {
2163
- chunk3FDU5JFE_cjs.warnOnce(
2164
+ chunk7IZKTQ5G_cjs.warnOnce(
2164
2165
  `personality-store-persist-failure-${agentId}`,
2165
2166
  `[theokit-sdk] personality persist failed for ${chunk6LHQPOMI_cjs.redactSecrets(agentId)}: ${chunk6LHQPOMI_cjs.redactSecrets(
2166
2167
  err.message
@@ -2177,7 +2178,7 @@ var PersonalityStore = class {
2177
2178
  try {
2178
2179
  state = await readState(filePath);
2179
2180
  } catch (err) {
2180
- chunk3FDU5JFE_cjs.warnOnce(
2181
+ chunk7IZKTQ5G_cjs.warnOnce(
2181
2182
  `personality-store-hydrate-failure-${agentId}`,
2182
2183
  `[theokit-sdk] personality hydrate failed for ${chunk6LHQPOMI_cjs.redactSecrets(agentId)}: ${chunk6LHQPOMI_cjs.redactSecrets(
2183
2184
  err.message
@@ -2206,7 +2207,7 @@ var PersonalityStore = class {
2206
2207
  });
2207
2208
  }
2208
2209
  #filePath() {
2209
- return path.join(chunk43YXGD3P_cjs.getTheokitHome(this.#cwd), FILE_NAME);
2210
+ return path.join(chunkTY56BKSK_cjs.getTheokitHome(this.#cwd), FILE_NAME);
2210
2211
  }
2211
2212
  };
2212
2213
 
@@ -2523,7 +2524,7 @@ function removeAll(arr, toRemove) {
2523
2524
  }
2524
2525
  }
2525
2526
  function readCompatConfigFile(cwd) {
2526
- const path$1 = path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), "config.json");
2527
+ const path$1 = path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), "config.json");
2527
2528
  if (!fs.existsSync(path$1)) return [];
2528
2529
  let raw;
2529
2530
  try {
@@ -2553,6 +2554,116 @@ function readCompatConfigFile(cwd) {
2553
2554
  function resolveCompatSources(options, cwd) {
2554
2555
  return options.local?.compatSources ?? readCompatConfigFile(cwd);
2555
2556
  }
2557
+ var KNOWN_KEYS = /* @__PURE__ */ new Set([
2558
+ "disableAllHooks",
2559
+ "disableSkillShellExecution",
2560
+ "permissions",
2561
+ "permissionMode"
2562
+ ]);
2563
+ function managedSettingsPathFor(root) {
2564
+ if (root !== void 0) return path.join(root, "claude-code", "managed-settings.json");
2565
+ if (process$1.platform === "darwin") {
2566
+ return "/Library/Application Support/ClaudeCode/managed-settings.json";
2567
+ }
2568
+ if (process$1.platform === "win32") {
2569
+ const programData = process.env.PROGRAMDATA ?? "C:\\ProgramData";
2570
+ return path.join(programData, "ClaudeCode", "managed-settings.json");
2571
+ }
2572
+ return "/etc/claude-code/managed-settings.json";
2573
+ }
2574
+ function readManagedSettings(root) {
2575
+ const path = managedSettingsPathFor(root);
2576
+ const parsed = readPolicyDocument(path);
2577
+ if (parsed === void 0) return {};
2578
+ const out = {};
2579
+ for (const [key, value] of Object.entries(parsed)) {
2580
+ applyPolicyKey(out, key, value, path);
2581
+ }
2582
+ return out;
2583
+ }
2584
+ function readPolicyDocument(path) {
2585
+ if (!fs.existsSync(path)) return void 0;
2586
+ let raw;
2587
+ try {
2588
+ raw = fs.readFileSync(path, "utf8");
2589
+ } catch (cause) {
2590
+ chunk6LHQPOMI_cjs.diagFailure(
2591
+ `[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.
2592
+ `
2593
+ );
2594
+ return void 0;
2595
+ }
2596
+ let parsed;
2597
+ try {
2598
+ parsed = JSON.parse(raw);
2599
+ } catch (cause) {
2600
+ chunk6LHQPOMI_cjs.diagFailure(
2601
+ `[theokit-sdk] ${path} is not valid JSON (${cause.message}) \u2014 NO operator policy is being applied.
2602
+ `
2603
+ );
2604
+ return void 0;
2605
+ }
2606
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
2607
+ chunk6LHQPOMI_cjs.diagFailure(
2608
+ `[theokit-sdk] ${path} is not a JSON object \u2014 NO operator policy is being applied.
2609
+ `
2610
+ );
2611
+ return void 0;
2612
+ }
2613
+ return parsed;
2614
+ }
2615
+ var PERMISSION_MODES = ["default", "plan", "acceptEdits", "bypass"];
2616
+ function applyPolicyKey(out, key, value, path) {
2617
+ if (!KNOWN_KEYS.has(key)) {
2618
+ decline(path, key, "this runtime does not enforce it");
2619
+ return;
2620
+ }
2621
+ if (key === "permissionMode") {
2622
+ const mode = readMode(value, path);
2623
+ if (mode !== void 0) out.permissionMode = mode;
2624
+ return;
2625
+ }
2626
+ if (key === "permissions") {
2627
+ const rules = readRuleLists(value, path);
2628
+ if (rules !== void 0) out.permissions = rules;
2629
+ return;
2630
+ }
2631
+ const flag = readBoolean(value, key, path);
2632
+ if (flag === void 0) return;
2633
+ if (key === "disableAllHooks") out.disableAllHooks = flag;
2634
+ if (key === "disableSkillShellExecution") out.disableSkillShellExecution = flag;
2635
+ }
2636
+ function decline(path, key, reason) {
2637
+ chunk6LHQPOMI_cjs.diagFailure(`[theokit-sdk] ${path} declares "${key}" \u2014 ${reason}. It is NOT being applied.
2638
+ `);
2639
+ }
2640
+ function readMode(value, path) {
2641
+ if (typeof value === "string" && PERMISSION_MODES.includes(value)) {
2642
+ return value;
2643
+ }
2644
+ decline(
2645
+ path,
2646
+ "permissionMode",
2647
+ `${JSON.stringify(value)} is not one of ${PERMISSION_MODES.join(", ")}`
2648
+ );
2649
+ return void 0;
2650
+ }
2651
+ function readRuleLists(value, path) {
2652
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
2653
+ return value;
2654
+ }
2655
+ decline(
2656
+ path,
2657
+ "permissions",
2658
+ `it is ${Array.isArray(value) ? "an array" : typeof value}, not an object of rule lists`
2659
+ );
2660
+ return void 0;
2661
+ }
2662
+ function readBoolean(value, key, path) {
2663
+ if (typeof value === "boolean") return value;
2664
+ decline(path, key, `it is ${typeof value}, not a boolean`);
2665
+ return void 0;
2666
+ }
2556
2667
  function spawnAndCollect(options) {
2557
2668
  return new Promise((resolve) => {
2558
2669
  const timeoutMs = options.timeoutMs ?? 3e4;
@@ -2603,21 +2714,31 @@ function spawnAndCollect(options) {
2603
2714
 
2604
2715
  // src/internal/runtime/hooks/hooks-executor.ts
2605
2716
  var HooksExecutor = class {
2606
- constructor(cwd, compatSources = [], gate = void 0) {
2717
+ constructor(cwd, compatSources = [], gate = void 0, policy = {}) {
2607
2718
  this.cwd = cwd;
2608
2719
  this.compatSources = compatSources;
2609
2720
  this.gate = gate;
2721
+ this.policy = policy;
2610
2722
  }
2611
2723
  cwd;
2612
2724
  compatSources;
2613
2725
  gate;
2726
+ policy;
2614
2727
  config = {};
2615
2728
  async initialize(settingSourcesIncludeProject) {
2729
+ if (readManagedSettings(this.policy.managedSettingsRoot).disableAllHooks === true) {
2730
+ chunk7IZKTQ5G_cjs.warnFailureOnce(
2731
+ "hooks-disabled-by-policy",
2732
+ "[theokit-sdk] hooks: an operator policy (managed-settings.json) declares disableAllHooks \u2014 NO hook will run, including any this project declared."
2733
+ );
2734
+ this.config = {};
2735
+ return;
2736
+ }
2616
2737
  if (!settingSourcesIncludeProject) {
2617
2738
  this.config = {};
2618
2739
  return;
2619
2740
  }
2620
- this.config = await chunk3FDU5JFE_cjs.loadHookConfig(this.cwd, this.compatSources);
2741
+ this.config = await chunk7IZKTQ5G_cjs.loadHookConfig(this.cwd, this.compatSources);
2621
2742
  }
2622
2743
  /** Fire every hook registered for `event` and aggregate the decisions. */
2623
2744
  async run(payload) {
@@ -2659,19 +2780,24 @@ var HooksExecutor = class {
2659
2780
  *
2660
2781
  * No gate means no refusal, which is what every consumer gets today.
2661
2782
  */
2662
- async refusedByConsumer(command, payload) {
2783
+ async refusedByConsumer(command, payload, timeoutMs) {
2663
2784
  if (this.gate?.approve === void 0) return false;
2664
2785
  const request = {
2665
2786
  command: command.command,
2666
2787
  event: payload.event,
2788
+ // #637 — the EFFECTIVE timeout, passed in rather than recomputed here, so the number the
2789
+ // consumer is shown and the number `spawnAndCollect` enforces are the same expression.
2790
+ // Recomputing would be one line and would be the place they later diverge.
2791
+ timeoutMs,
2792
+ sourceEvent: command.sourceEvent,
2667
2793
  ...command.sourcePath === void 0 ? {} : { sourcePath: command.sourcePath },
2668
2794
  ...command.matcher === void 0 ? {} : { matcher: command.matcher }
2669
2795
  };
2670
2796
  return !await this.gate.approve(request);
2671
2797
  }
2672
2798
  async executeOne(command, payload) {
2673
- if (await this.refusedByConsumer(command, payload)) return { decision: "allow" };
2674
2799
  const timeoutMs = command.timeoutMs ?? 3e4;
2800
+ if (await this.refusedByConsumer(command, payload, timeoutMs)) return { decision: "allow" };
2675
2801
  const env = runtimeEnvFor(command.sourcePath, this.cwd);
2676
2802
  const result = await spawnAndCollect({
2677
2803
  command: "sh",
@@ -2679,7 +2805,7 @@ var HooksExecutor = class {
2679
2805
  cwd: this.cwd,
2680
2806
  ...Object.keys(env).length > 0 ? { env } : {},
2681
2807
  timeoutMs,
2682
- stdin: JSON.stringify(payload)
2808
+ stdin: JSON.stringify(stdinPayloadFor(payload, command, this.cwd))
2683
2809
  });
2684
2810
  const failure = this.decisionFromFailure(result, command, env, timeoutMs);
2685
2811
  return failure ?? parseDecisionFromStdout(result.stdout);
@@ -2693,14 +2819,21 @@ var HooksExecutor = class {
2693
2819
  * spawned.
2694
2820
  */
2695
2821
  decisionFromFailure(result, command, env, timeoutMs) {
2696
- if (result.timedOut) return { decision: "deny", reason: `Hook timed out after ${timeoutMs}ms` };
2822
+ if (result.timedOut)
2823
+ return {
2824
+ decision: "deny",
2825
+ reason: `Hook timed out after ${timeoutMs}ms`
2826
+ };
2697
2827
  if (result.spawnError !== void 0) {
2698
- return { decision: "deny", reason: `Hook spawn failed: ${result.spawnError.message}` };
2828
+ return {
2829
+ decision: "deny",
2830
+ reason: `Hook spawn failed: ${result.spawnError.message}`
2831
+ };
2699
2832
  }
2700
2833
  if (result.exitCode === 0) return void 0;
2701
2834
  const stderr = result.stderr.trim();
2702
2835
  const base = stderr.length > 0 ? stderr : `Hook exited with code ${result.exitCode}`;
2703
- const missing = chunk43YXGD3P_cjs.undefinedVariablesIn(command.command, env);
2836
+ const missing = chunkTY56BKSK_cjs.undefinedVariablesIn(command.command, env);
2704
2837
  if (missing.length === 0) return { decision: "deny", reason: base };
2705
2838
  return {
2706
2839
  decision: "deny",
@@ -2708,26 +2841,52 @@ var HooksExecutor = class {
2708
2841
  };
2709
2842
  }
2710
2843
  };
2844
+ function stdinPayloadFor(payload, command, cwd) {
2845
+ return {
2846
+ ...payload,
2847
+ cwd,
2848
+ ...command.sourceEvent === void 0 ? {} : { hook_event_name: command.sourceEvent },
2849
+ ...payload.tool === void 0 ? {} : { tool_name: payload.tool },
2850
+ ...payload.input === void 0 ? {} : { tool_input: payload.input },
2851
+ ...payload.output === void 0 ? {} : { tool_response: payload.output }
2852
+ };
2853
+ }
2711
2854
  function runtimeEnvFor(sourcePath, cwd) {
2712
2855
  if (sourcePath === void 0) return {};
2713
- return chunk43YXGD3P_cjs.adapterForConfigPath(sourcePath)?.runtimeEnv(cwd) ?? {};
2856
+ return chunkTY56BKSK_cjs.adapterForConfigPath(sourcePath)?.runtimeEnv(cwd) ?? {};
2714
2857
  }
2715
2858
  function parseDecisionFromStdout(stdout) {
2716
2859
  const trimmed = stdout.trim();
2717
2860
  if (trimmed.length === 0) return { decision: "allow" };
2861
+ let parsed;
2718
2862
  try {
2719
- const parsed = JSON.parse(trimmed);
2720
- if (parsed.decision === "deny" || parsed.decision === "feedback") {
2721
- const result = { decision: parsed.decision };
2722
- if (parsed.reason !== void 0) result.reason = parsed.reason;
2723
- if (parsed.feedback !== void 0) result.feedback = parsed.feedback;
2724
- return result;
2725
- }
2726
- if (parsed.decision === "allow") return { decision: "allow" };
2863
+ parsed = JSON.parse(trimmed);
2727
2864
  } catch {
2728
2865
  return { decision: "feedback", feedback: trimmed };
2729
2866
  }
2730
- return { decision: "allow" };
2867
+ return nestedDecision(parsed) ?? flatDecision(parsed) ?? { decision: "allow" };
2868
+ }
2869
+ function nestedDecision(parsed) {
2870
+ const nested = parsed.hookSpecificOutput;
2871
+ if (nested?.permissionDecision === "allow") return { decision: "allow" };
2872
+ if (nested?.permissionDecision !== "deny" && nested?.permissionDecision !== "ask") {
2873
+ return void 0;
2874
+ }
2875
+ const result = { decision: "deny" };
2876
+ if (nested.permissionDecisionReason !== void 0) {
2877
+ result.reason = nested.permissionDecisionReason;
2878
+ }
2879
+ return result;
2880
+ }
2881
+ function flatDecision(parsed) {
2882
+ if (parsed.decision === "allow") return { decision: "allow" };
2883
+ if (parsed.decision !== "deny" && parsed.decision !== "block" && parsed.decision !== "feedback") {
2884
+ return void 0;
2885
+ }
2886
+ const result = parsed.decision === "feedback" ? { decision: "feedback" } : { decision: "deny" };
2887
+ if (parsed.reason !== void 0) result.reason = parsed.reason;
2888
+ if (parsed.feedback !== void 0) result.feedback = parsed.feedback;
2889
+ return result;
2731
2890
  }
2732
2891
 
2733
2892
  // src/internal/runtime/lifecycle/context-budget-event.ts
@@ -2819,7 +2978,7 @@ async function runPostRunLifecycle(inputs) {
2819
2978
  cwd: workspaceCwd,
2820
2979
  // Resolved once, here, and handed to both writers. Recomputing it inside either one is how
2821
2980
  // the summary ended up in a directory the indexer never scanned (#463).
2822
- memoryRoot: chunkNQTNSHSB_cjs.resolveMemoryRoot(workspaceCwd, inputs.memory),
2981
+ memoryRoot: chunkGFFBXSQT_cjs.resolveMemoryRoot(workspaceCwd, inputs.memory),
2823
2982
  runId: result.id,
2824
2983
  agentId,
2825
2984
  userText,
@@ -2831,7 +2990,7 @@ async function runPostRunLifecycle(inputs) {
2831
2990
  if (memoryProvider?.recordSessionSummary !== void 0) {
2832
2991
  await memoryProvider.recordSessionSummary(summaryArgs);
2833
2992
  } else {
2834
- await chunkNQTNSHSB_cjs.writeSessionSummary(summaryArgs);
2993
+ await chunkGFFBXSQT_cjs.writeSessionSummary(summaryArgs);
2835
2994
  }
2836
2995
  } catch (cause) {
2837
2996
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -2883,15 +3042,15 @@ var SkillsManager = class {
2883
3042
  }
2884
3043
  async refresh() {
2885
3044
  const roots = this.skillsDir === void 0 ? [
2886
- ...chunk43YXGD3P_cjs.projectConfigRoots(this.cwd, this.compatSources, "skills").map(
3045
+ ...chunkTY56BKSK_cjs.projectConfigRoots(this.cwd, this.compatSources, "skills").map(
2887
3046
  (root) => path.join(root, "skills")
2888
3047
  ),
2889
- ...(await chunkAYA65JA5_cjs.pluginBundleDirs(this.cwd, this.compatSources)).map((b) => path.join(b, "skills"))
3048
+ ...(await chunkRWPLWMCZ_cjs.pluginBundleDirs(this.cwd, this.compatSources)).map((b) => path.join(b, "skills"))
2890
3049
  ] : [this.skillsDir];
2891
3050
  const discovered = [];
2892
3051
  const seen = /* @__PURE__ */ new Set();
2893
3052
  for (const root of roots) {
2894
- for (const skill of await chunkQATRS7JD_cjs.discoverSkills(root, {
3053
+ for (const skill of await chunkMYJGWS2J_cjs.discoverSkills(root, {
2895
3054
  onInvalidSkill: (info) => {
2896
3055
  chunk6LHQPOMI_cjs.diag(`[theokit-sdk] skill ${info.name} skipped (${info.code}): ${info.message}
2897
3056
  `);
@@ -2922,7 +3081,7 @@ var SkillsManager = class {
2922
3081
  async get(name) {
2923
3082
  const skill = this.skills.find((s) => s.name === name);
2924
3083
  if (skill === void 0) return void 0;
2925
- const instructions = typeof skill.instructions === "string" ? skill.instructions : chunkQATRS7JD_cjs.stripSkillFrontmatter(await promises.readFile(skill.source, "utf8"));
3084
+ const instructions = typeof skill.instructions === "string" ? skill.instructions : chunkMYJGWS2J_cjs.stripSkillFrontmatter(await promises.readFile(skill.source, "utf8"));
2926
3085
  const references = skill.references;
2927
3086
  return {
2928
3087
  name: skill.name,
@@ -3041,7 +3200,15 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
3041
3200
  agentId: inputs.agentId,
3042
3201
  cwd: inputs.workspaceCwd,
3043
3202
  model: inputs.model,
3044
- skills: skills.map((skill) => ({ name: skill.name, description: skill.description })),
3203
+ // This is the ONLY place the model learns which skills exist, which is what makes
3204
+ // `disable-model-invocation` enforceable rather than decorative. The scaffold had been writing
3205
+ // authorization frontmatter that the parser discarded, so the default was disclose-all.
3206
+ //
3207
+ // A disclosure rule, not an execution rule: `skills.get(name)` still resolves a hidden skill,
3208
+ // because a caller naming one has already made the decision this field keeps away from the
3209
+ // model. Widening it to execution would break the case the field is FOR — a side-effecting
3210
+ // skill a human may run and the model may not propose.
3211
+ skills: skills.filter((skill) => skill.disableModelInvocation !== true).map((skill) => ({ name: skill.name, description: skill.description })),
3045
3212
  userMessage: userText,
3046
3213
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
3047
3214
  };
@@ -3101,7 +3268,7 @@ var ActiveMemoryPromptProvider = class {
3101
3268
  if (ctx.activeMemorySummary === void 0 || ctx.activeMemorySummary.length === 0) {
3102
3269
  return Promise.resolve(void 0);
3103
3270
  }
3104
- const body = chunkQATRS7JD_cjs.escapeBlockBody(ctx.activeMemorySummary);
3271
+ const body = chunkMYJGWS2J_cjs.escapeBlockBody(ctx.activeMemorySummary);
3105
3272
  return Promise.resolve(`<active-memory>
3106
3273
  ${body}
3107
3274
  </active-memory>`);
@@ -3154,7 +3321,7 @@ function formatSource(name, tokens) {
3154
3321
  if (tokens.length === 0) {
3155
3322
  return ` <source name="${escapeAttribute(name)}" />`;
3156
3323
  }
3157
- const body = chunkQATRS7JD_cjs.escapeBlockBody(tokens.join(" "));
3324
+ const body = chunkMYJGWS2J_cjs.escapeBlockBody(tokens.join(" "));
3158
3325
  return ` <source name="${escapeAttribute(name)}">
3159
3326
  ${body}
3160
3327
  </source>`;
@@ -3178,7 +3345,7 @@ var MemoryPromptProvider = class {
3178
3345
  if (ctx.memory.length === 0) return Promise.resolve(void 0);
3179
3346
  const lines = ctx.memory.map((fact) => {
3180
3347
  const tag = fact.observations === 1 ? "[unconfirmed] " : "";
3181
- return ` - ${tag}${chunkQATRS7JD_cjs.escapeBlockBody(fact.text)}`;
3348
+ return ` - ${tag}${chunkMYJGWS2J_cjs.escapeBlockBody(fact.text)}`;
3182
3349
  });
3183
3350
  return Promise.resolve(`${MEMORY_GUIDANCE}
3184
3351
  <memory>
@@ -3202,7 +3369,7 @@ var SkillsPromptProvider = class {
3202
3369
  priority = 20;
3203
3370
  contribute(ctx) {
3204
3371
  if (ctx.skillsAutoInject === false) return Promise.resolve(void 0);
3205
- return Promise.resolve(chunkQATRS7JD_cjs.buildSkillsBlock(ctx.skills));
3372
+ return Promise.resolve(chunkMYJGWS2J_cjs.buildSkillsBlock(ctx.skills));
3206
3373
  }
3207
3374
  };
3208
3375
 
@@ -3470,7 +3637,7 @@ var HISTOGRAM_NAMES = {
3470
3637
  };
3471
3638
  function safeRequire(moduleName) {
3472
3639
  try {
3473
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UALC6Q3J.cjs', document.baseURI).href)));
3640
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GCHZMH42.cjs', document.baseURI).href)));
3474
3641
  return r(moduleName);
3475
3642
  } catch {
3476
3643
  return void 0;
@@ -3713,7 +3880,7 @@ var cachedOtel;
3713
3880
  function loadOtel() {
3714
3881
  if (cachedOtel === void 0) {
3715
3882
  try {
3716
- const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-UALC6Q3J.cjs', document.baseURI).href)));
3883
+ const r = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-GCHZMH42.cjs', document.baseURI).href)));
3717
3884
  const mod = r("@opentelemetry/api");
3718
3885
  cachedOtel = mod;
3719
3886
  } catch {
@@ -3950,7 +4117,7 @@ async function loadMarkdownEntities(opts) {
3950
4117
  const raw = await promises.readFile(resolved.source, "utf8").catch(() => null);
3951
4118
  if (raw === null) continue;
3952
4119
  const split = splitFrontmatter(raw, resolved.source, errorCodePrefix);
3953
- const fields = chunkHW7SEELD_cjs.parseSimpleYaml(split.frontmatter);
4120
+ const fields = chunkQRVS2PRE_cjs.parseSimpleYaml(split.frontmatter);
3954
4121
  const parsed = schema.safeParse(fields);
3955
4122
  if (!parsed.success) {
3956
4123
  throw new chunkJ7J7J2GN_cjs.ConfigurationError(
@@ -4032,7 +4199,7 @@ function applyAggregateCap(sources, maxTotal) {
4032
4199
  }
4033
4200
  const remaining = maxTotal - totalBytes;
4034
4201
  if (remaining > 0) {
4035
- const { finalContent } = chunkIU5N5224_cjs.truncateWithMarker(s.content, remaining);
4202
+ const { finalContent } = chunkEIOMN5VA_cjs.truncateWithMarker(s.content, remaining);
4036
4203
  kept.push({ ...s, content: finalContent, truncated: true });
4037
4204
  totalBytes = maxTotal;
4038
4205
  } else {
@@ -4065,14 +4232,24 @@ var ContextSourceFrontmatterSchema = zod.z.object({
4065
4232
 
4066
4233
  // src/internal/runtime/context/context-manager.ts
4067
4234
  var FileContextManager = class {
4068
- constructor(cwd, settings, settingSourcesIncludeProject) {
4235
+ /**
4236
+ * @param compatSources - What the consumer declared in `local.compatSources` (or
4237
+ * `.theokit/config.json`), as `resolveCompatSources` resolved it. `undefined` means the caller
4238
+ * did not thread the declaration through at all and every dialect runs — the pre-#652 behaviour,
4239
+ * kept so an internal caller constructing this directly does not silently lose content. An empty
4240
+ * ARRAY is different and is the fix: it means the consumer declared no foreign dialect, so
4241
+ * `.claude/rules/*.md` does not reach the prompt.
4242
+ */
4243
+ constructor(cwd, settings, settingSourcesIncludeProject, compatSources) {
4069
4244
  this.cwd = cwd;
4070
4245
  this.settings = settings;
4071
4246
  this.settingSourcesIncludeProject = settingSourcesIncludeProject;
4247
+ this.compatSources = compatSources;
4072
4248
  }
4073
4249
  cwd;
4074
4250
  settings;
4075
4251
  settingSourcesIncludeProject;
4252
+ compatSources;
4076
4253
  state;
4077
4254
  /**
4078
4255
  * The in-scope file set used by the most recent `refresh`. Tracked so
@@ -4081,6 +4258,19 @@ var FileContextManager = class {
4081
4258
  * snapshot untouched, at zero per-send cost.
4082
4259
  */
4083
4260
  lastScope = [];
4261
+ /**
4262
+ * The dialect kinds granted the `context` surface, or `undefined` when nothing was declared to
4263
+ * this instance.
4264
+ *
4265
+ * Routed through `adaptersForSurface` rather than reading `.kind` off the declarations, so the
4266
+ * three fail-closed rules #524 established govern this surface identically to the other four: a
4267
+ * bare string admits everything, an object with no `import` admits nothing, and an unrecognised
4268
+ * surface name narrows rather than widens.
4269
+ */
4270
+ grantedContextDialects() {
4271
+ if (this.compatSources === void 0) return void 0;
4272
+ return chunkTY56BKSK_cjs.adaptersForSurface(this.compatSources, "context").map((a) => a.kind);
4273
+ }
4084
4274
  async initialize() {
4085
4275
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
4086
4276
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -4106,13 +4296,18 @@ var FileContextManager = class {
4106
4296
  this.lastScope = [...touchedFiles];
4107
4297
  const config = await loadContextConfig(this.cwd);
4108
4298
  const legacy = await loadSources(config, this.cwd);
4109
- const maxBytesPerFile = this.settings.maxBytesPerFile ?? chunkIU5N5224_cjs.DEFAULT_MAX_BYTES_PER_FILE;
4299
+ const maxBytesPerFile = this.settings.maxBytesPerFile ?? chunkEIOMN5VA_cjs.DEFAULT_MAX_BYTES_PER_FILE;
4110
4300
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
4111
- const discovered = await chunkIU5N5224_cjs.runDiscovery({
4301
+ const granted = this.grantedContextDialects();
4302
+ const discovered = await chunkEIOMN5VA_cjs.runDiscovery({
4112
4303
  cwd: this.cwd,
4113
4304
  maxBytesPerFile,
4114
4305
  skipLegacyTheokitContext: true,
4115
- touchedFiles
4306
+ touchedFiles,
4307
+ // #652 — the grant this path never consulted. Without it, a consumer who enabled project
4308
+ // scope for its OWN `.theokit/` also received a cloned repository's `.claude/rules/*.md`,
4309
+ // through a door the hooks/skills/subagents/plugins gate does not cover.
4310
+ ...granted === void 0 ? {} : { declaredCompatKinds: granted }
4116
4311
  });
4117
4312
  const legacyAsAggregator = legacy.filter((src) => src.status !== "excluded").map((src) => ({
4118
4313
  id: src.name,
@@ -4167,8 +4362,8 @@ var FileContextManager = class {
4167
4362
  }
4168
4363
  };
4169
4364
  async function loadContextConfig(cwd) {
4170
- const mdDir = path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), "context");
4171
- const jsonPath = path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), "context.json");
4365
+ const mdDir = path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), "context");
4366
+ const jsonPath = path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), "context.json");
4172
4367
  const mdEntities = await loadMarkdownEntities({
4173
4368
  dir: mdDir,
4174
4369
  schema: ContextSourceFrontmatterSchema,
@@ -4177,7 +4372,7 @@ async function loadContextConfig(cwd) {
4177
4372
  });
4178
4373
  if (mdEntities.length > 0) {
4179
4374
  if (fs.existsSync(jsonPath)) {
4180
- chunk3FDU5JFE_cjs.warnOnce(
4375
+ chunk7IZKTQ5G_cjs.warnOnce(
4181
4376
  "context-both-present",
4182
4377
  "[theokit-sdk] both .theokit/context/ and .theokit/context.json detected \u2014 using markdown; remove context.json"
4183
4378
  );
@@ -4187,7 +4382,7 @@ async function loadContextConfig(cwd) {
4187
4382
  };
4188
4383
  }
4189
4384
  if (!fs.existsSync(jsonPath)) return { sources: [] };
4190
- chunk3FDU5JFE_cjs.warnOnce(
4385
+ chunk7IZKTQ5G_cjs.warnOnce(
4191
4386
  "context-json-deprecated",
4192
4387
  // Names no command: `theokit-migrate-config` was unpublished with the `bin` entry, and a warning
4193
4388
  // that tells you to run something the package does not ship is worse than one that tells you
@@ -4328,13 +4523,13 @@ var PluginsManager = class {
4328
4523
  }
4329
4524
  async refresh() {
4330
4525
  this.plugins = [];
4331
- for (const pluginsRoot of chunk43YXGD3P_cjs.pluginBundleRoots(this.cwd, this.compatSources)) {
4526
+ for (const pluginsRoot of chunkTY56BKSK_cjs.pluginBundleRoots(this.cwd, this.compatSources)) {
4332
4527
  await this.refreshRoot(pluginsRoot);
4333
4528
  }
4334
4529
  }
4335
4530
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: MD-first + JSON fallback + CLI location + both-present detection per plugin folder — branch table is clearer inlined.
4336
4531
  async refreshRoot(pluginsRoot) {
4337
- const entries = await chunkHW7SEELD_cjs.readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
4532
+ const entries = await chunkQRVS2PRE_cjs.readWorkspaceDir(pluginsRoot, "plugins_read_error", "plugins directory");
4338
4533
  for (const entry of entries) {
4339
4534
  if (!entry.isDirectory()) continue;
4340
4535
  const folderName = entry.name;
@@ -4350,13 +4545,13 @@ var PluginsManager = class {
4350
4545
  const jsonPath = path.join(pluginsRoot, folderName, "plugin.json");
4351
4546
  const metadata = fs.existsSync(mdPath) ? await loadPluginManifestFromMarkdown(this.cwd, pluginsRoot, folderName) : await loadPluginManifestFromJson(this.cwd, jsonPath, folderName);
4352
4547
  if (fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
4353
- chunk3FDU5JFE_cjs.warnOnce(
4548
+ chunk7IZKTQ5G_cjs.warnOnce(
4354
4549
  `plugin-${folderName}-both`,
4355
4550
  `[theokit-sdk] both ${folderName}/PLUGIN.md and ${folderName}/plugin.json detected \u2014 using markdown; remove plugin.json`
4356
4551
  );
4357
4552
  }
4358
4553
  if (!fs.existsSync(mdPath) && fs.existsSync(jsonPath)) {
4359
- chunk3FDU5JFE_cjs.warnOnce(
4554
+ chunk7IZKTQ5G_cjs.warnOnce(
4360
4555
  "plugin-json-deprecated",
4361
4556
  // Same reason as the context.json warning: the CLI it used to name is no longer published.
4362
4557
  "[theokit-sdk] plugin.json manifests are deprecated; replace each with a PLUGIN.md"
@@ -4507,7 +4702,12 @@ function buildContext(args, out) {
4507
4702
  out.context = new FileContextManager(
4508
4703
  args.workspaceCwd,
4509
4704
  args.options.context,
4510
- args.settingSourcesIncludeProject
4705
+ args.settingSourcesIncludeProject,
4706
+ // #652 — the same declaration `buildSkills` and `buildPlugins` already pass. Omitting it here
4707
+ // is what let a foreign root's instructions into the system prompt while its skills, subagents,
4708
+ // hooks and plugins were correctly withheld: four surfaces failing closed and a fifth nobody
4709
+ // had wired to the gate.
4710
+ resolveCompatSources(args.options, args.workspaceCwd)
4511
4711
  );
4512
4712
  }
4513
4713
  function buildProviders(args, out) {
@@ -5602,7 +5802,7 @@ function stripThinkBlocks(content) {
5602
5802
  function resolveSystemPromptWithMemoryAdditions(systemPrompt, additions) {
5603
5803
  if (additions === void 0 || additions.length === 0) return systemPrompt;
5604
5804
  const block = `<active-memory>
5605
- ${chunkQATRS7JD_cjs.escapeBlockBody(additions)}
5805
+ ${chunkMYJGWS2J_cjs.escapeBlockBody(additions)}
5606
5806
  </active-memory>`;
5607
5807
  if (systemPrompt === void 0 || systemPrompt.length === 0) return block;
5608
5808
  return `${block}
@@ -7246,7 +7446,7 @@ function applyPersonalityFilter(exposedTools, whitelist, opts) {
7246
7446
  if (exposedSet.has(name)) continue;
7247
7447
  const hint = suggestClosest(name, exposedSet);
7248
7448
  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)`;
7249
- chunk3FDU5JFE_cjs.warnOnce(
7449
+ chunk7IZKTQ5G_cjs.warnOnce(
7250
7450
  `personality-tool-missing|${opts?.agentId ?? "?"}|${opts?.personalityName ?? "?"}|${name}`,
7251
7451
  message
7252
7452
  );
@@ -7695,7 +7895,7 @@ async function dispatchLocalRun(args) {
7695
7895
  });
7696
7896
  }
7697
7897
  async function readProjectMcpServers(cwd) {
7698
- const path$1 = path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), "mcp.json");
7898
+ const path$1 = path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), "mcp.json");
7699
7899
  try {
7700
7900
  const raw = await promises.readFile(path$1, "utf8");
7701
7901
  const parsed = JSON.parse(raw);
@@ -7937,7 +8137,7 @@ async function reloadLocalAgent(agent) {
7937
8137
  if (agent.context !== void 0) await agent.context.refresh();
7938
8138
  if (agent.skillsManager !== void 0) await agent.skillsManager.refresh();
7939
8139
  if (agent.pluginsManager !== void 0) await agent.pluginsManager.refresh();
7940
- return await chunkAYA65JA5_cjs.loadSubagents(
8140
+ return await chunkRWPLWMCZ_cjs.loadSubagents(
7941
8141
  agent.workspaceCwd,
7942
8142
  agent.settingSourcesIncludeProject,
7943
8143
  agent.options.agents
@@ -8183,7 +8383,7 @@ async function finalize(args, queryMode, result) {
8183
8383
  };
8184
8384
  args.cache?.set(args.userText, queryMode, result, tenantCtx);
8185
8385
  if (args.persistTranscripts === true && args.cwd !== void 0) {
8186
- await chunkTMKTSYDS_cjs.persistActiveMemoryTranscript(args.memoryRoot ?? chunkNQTNSHSB_cjs.resolveMemoryRoot(args.cwd), {
8386
+ await chunkTMKTSYDS_cjs.persistActiveMemoryTranscript(args.memoryRoot ?? chunkGFFBXSQT_cjs.resolveMemoryRoot(args.cwd), {
8187
8387
  runId: args.runId ?? `run-${Date.now()}`,
8188
8388
  startedAtMs: Date.now() - result.durationMs,
8189
8389
  userText: args.userText,
@@ -8774,7 +8974,7 @@ var LocalAgentMemory = class {
8774
8974
  const openOpts = { cwd: this.workspaceCwd, memoryRoot };
8775
8975
  if (embedding !== void 0) openOpts.embedding = embedding;
8776
8976
  if (cfg?.backend !== void 0) openOpts.backend = cfg.backend;
8777
- this.index = await chunkZ2JFX372_cjs.IndexManager.open(openOpts);
8977
+ this.index = await chunkVUHXC74Q_cjs.IndexManager.open(openOpts);
8778
8978
  await this.index.sync();
8779
8979
  this.toolsCache = [
8780
8980
  createMemorySearchTool({ index: this.index }),
@@ -8818,7 +9018,7 @@ var LocalAgentMemory = class {
8818
9018
  * and the active-memory transcript writer. Three separate resolutions is how they drifted (#463).
8819
9019
  */
8820
9020
  memoryRoot() {
8821
- this.memoryRootCache ??= chunkNQTNSHSB_cjs.resolveMemoryRoot(this.workspaceCwd, this.options.memory);
9021
+ this.memoryRootCache ??= chunkGFFBXSQT_cjs.resolveMemoryRoot(this.workspaceCwd, this.options.memory);
8822
9022
  return this.memoryRootCache;
8823
9023
  }
8824
9024
  buildActiveMemoryOptions(cfg) {
@@ -8933,7 +9133,7 @@ function createLocalAgentMemoryProvider(opts) {
8933
9133
  return { facts: [], systemPromptAdditions: summary };
8934
9134
  },
8935
9135
  async recordSessionSummary(args) {
8936
- await chunkNQTNSHSB_cjs.writeSessionSummary(args);
9136
+ await chunkGFFBXSQT_cjs.writeSessionSummary(args);
8937
9137
  },
8938
9138
  async sync(handle) {
8939
9139
  const state = handle[INTERNAL_LAM_KEY];
@@ -8971,7 +9171,7 @@ var PersonalityRegistry = class _PersonalityRegistry {
8971
9171
  * @internal
8972
9172
  */
8973
9173
  static async load(cwd) {
8974
- const projectDir = path.join(chunk43YXGD3P_cjs.theokitConfigRoot(cwd), PERSONALITIES_SUFFIX);
9174
+ const projectDir = path.join(chunkTY56BKSK_cjs.theokitConfigRoot(cwd), PERSONALITIES_SUFFIX);
8975
9175
  const userDir = path.join(os.homedir(), USER_SUBDIR);
8976
9176
  const [userEntities, projectEntities] = await Promise.all([
8977
9177
  loadMarkdownEntities({
@@ -9023,7 +9223,7 @@ function addEntity(byName, entity, origin, collisionMap) {
9023
9223
  );
9024
9224
  }
9025
9225
  if (origin === "project" && collisionMap?.has(fm.name)) {
9026
- chunk3FDU5JFE_cjs.warnOnce(
9226
+ chunk7IZKTQ5G_cjs.warnOnce(
9027
9227
  `personality-collision-${fm.name}`,
9028
9228
  `[theokit-sdk] personality "${fm.name}" overridden by project preset`
9029
9229
  );
@@ -9073,14 +9273,14 @@ async function performPersonalitySwitch(args) {
9073
9273
 
9074
9274
  // src/internal/local-agent/local-agent-personality-extensions.ts
9075
9275
  function resolveActivePersonalityPreset(args) {
9076
- const forkCtx = chunk3FDU5JFE_cjs.currentPersonalityContext();
9276
+ const forkCtx = chunk7IZKTQ5G_cjs.currentPersonalityContext();
9077
9277
  const slug = forkCtx !== void 0 ? forkCtx.slug : args.personalityStore.active(args.agentId);
9078
9278
  if (slug === void 0) return void 0;
9079
9279
  return args.personalityRegistry?.get(slug);
9080
9280
  }
9081
9281
  async function ensurePersonalityRegistryIfNeeded(args) {
9082
9282
  if (args.personalityRegistry !== void 0) return args.personalityRegistry;
9083
- const forkSlug = chunk3FDU5JFE_cjs.currentPersonalityContext()?.slug;
9283
+ const forkSlug = chunk7IZKTQ5G_cjs.currentPersonalityContext()?.slug;
9084
9284
  const ownSlug = args.personalityStore.active(args.agentId);
9085
9285
  if (forkSlug === void 0 && ownSlug === void 0) return void 0;
9086
9286
  return await PersonalityRegistry.load(args.workspaceCwd);
@@ -9093,8 +9293,8 @@ function applyPersonalityOverlay(preset, base) {
9093
9293
  ${preset.systemPrompt}`;
9094
9294
  }
9095
9295
  async function localAgentUsePersonality(agent, name, opts) {
9096
- if (chunk3FDU5JFE_cjs.currentPersonalityContext() !== void 0) {
9097
- chunk3FDU5JFE_cjs.warnPersonalitySwitchInsideFork(agent.agentId);
9296
+ if (chunk7IZKTQ5G_cjs.currentPersonalityContext() !== void 0) {
9297
+ chunk7IZKTQ5G_cjs.warnPersonalitySwitchInsideFork(agent.agentId);
9098
9298
  return null;
9099
9299
  }
9100
9300
  if (agent.personalityRegistry === void 0) {
@@ -9155,7 +9355,7 @@ async function* localAgentStreamToCompletion(agent, message, options) {
9155
9355
  async function localAgentFork(parent, options) {
9156
9356
  const { forkAgentImpl } = await import('./fork-agent-WAEQI2DL.cjs');
9157
9357
  const { getAgentFacade } = await import('./agent-factory-registry-UU46BUMU.cjs');
9158
- const { withPersonalityContext } = await import('./context-4AIK26QB.cjs');
9358
+ const { withPersonalityContext } = await import('./context-HR4KMXMA.cjs');
9159
9359
  const create = getAgentFacade().create;
9160
9360
  return withPersonalityContext(
9161
9361
  { slug: parent.personalitySlugSnapshot, isFork: true },
@@ -9948,7 +10148,7 @@ var LocalAgent = class {
9948
10148
  if (sub.plugins !== void 0) this.plugins = sub.plugins;
9949
10149
  reportUnknownLocalOptions(options.local);
9950
10150
  const compatSources = resolveCompatSources(options, this.workspaceCwd);
9951
- chunk43YXGD3P_cjs.reportUndeclaredSources(this.workspaceCwd, compatSources);
10151
+ chunkTY56BKSK_cjs.reportUndeclaredSources(this.workspaceCwd, compatSources);
9952
10152
  this.hooksExecutor = new HooksExecutor(this.workspaceCwd, compatSources, options.local?.hooks);
9953
10153
  this.defaultMemoryProviderForLoop = createLocalAgentMemoryProvider({
9954
10154
  agentOptions: options,
@@ -9976,7 +10176,7 @@ var LocalAgent = class {
9976
10176
  if (this.pluginsManager !== void 0) await this.pluginsManager.initialize();
9977
10177
  const codePlugins = chunkBV2MWEMV_cjs.extractCodePlugins(this.options.plugins);
9978
10178
  await this.pluginManagerCode.initialize(codePlugins);
9979
- this.resolvedSubagents = await chunkAYA65JA5_cjs.loadSubagents(
10179
+ this.resolvedSubagents = await chunkRWPLWMCZ_cjs.loadSubagents(
9980
10180
  this.workspaceCwd,
9981
10181
  this.settingSourcesIncludeProject,
9982
10182
  this.options.agents,
@@ -10932,7 +11132,7 @@ var Agent = class _Agent {
10932
11132
  */
10933
11133
  static async describe(agentId) {
10934
11134
  const agent = await getRegisteredAgentOrThrow(agentId);
10935
- const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-DN4LETGL.cjs');
11135
+ const { loadSubagents: loadSubagents2 } = await import('./subagents-loader-MOO7DC4E.cjs');
10936
11136
  const settingSources = agent.options.local?.settingSources;
10937
11137
  const subagents = await loadSubagents2(
10938
11138
  agent.cwd ?? process.cwd(),
@@ -11048,7 +11248,9 @@ exports.UsageAccumulator = UsageAccumulator;
11048
11248
  exports.computeCost = computeCost;
11049
11249
  exports.generateCronId = generateCronId;
11050
11250
  exports.getPricingEntry = getPricingEntry;
11251
+ exports.managedSettingsPathFor = managedSettingsPathFor;
11051
11252
  exports.openRouterMemoryEmbeddingProviderAdapter = openRouterMemoryEmbeddingProviderAdapter;
11253
+ exports.readManagedSettings = readManagedSettings;
11052
11254
  exports.resolveSessionDir = resolveSessionDir;
11053
- //# sourceMappingURL=chunk-UALC6Q3J.cjs.map
11054
- //# sourceMappingURL=chunk-UALC6Q3J.cjs.map
11255
+ //# sourceMappingURL=chunk-GCHZMH42.cjs.map
11256
+ //# sourceMappingURL=chunk-GCHZMH42.cjs.map