@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
package/dist/index.cjs CHANGED
@@ -3,24 +3,24 @@
3
3
  var chunkTFG5IBZS_cjs = require('./chunk-TFG5IBZS.cjs');
4
4
  var chunkOBA6YK2R_cjs = require('./chunk-OBA6YK2R.cjs');
5
5
  var chunkQDM3OHUT_cjs = require('./chunk-QDM3OHUT.cjs');
6
- var chunkVPK6PHIE_cjs = require('./chunk-VPK6PHIE.cjs');
6
+ var chunk52FDUJSV_cjs = require('./chunk-52FDUJSV.cjs');
7
7
  var chunkQWD4RDZ3_cjs = require('./chunk-QWD4RDZ3.cjs');
8
8
  require('./chunk-7JJ3A6AT.cjs');
9
9
  var chunk4HS6FFGL_cjs = require('./chunk-4HS6FFGL.cjs');
10
10
  require('./chunk-4A3SKJ53.cjs');
11
11
  require('./chunk-VTYY7XL5.cjs');
12
- var chunkJ6KZE2ZQ_cjs = require('./chunk-J6KZE2ZQ.cjs');
13
- var chunkUALC6Q3J_cjs = require('./chunk-UALC6Q3J.cjs');
12
+ var chunkHG4UN4MN_cjs = require('./chunk-HG4UN4MN.cjs');
13
+ var chunkGCHZMH42_cjs = require('./chunk-GCHZMH42.cjs');
14
14
  var chunkKVSAY6NZ_cjs = require('./chunk-KVSAY6NZ.cjs');
15
15
  require('./chunk-DZG77WU7.cjs');
16
16
  require('./chunk-BUUUWQMB.cjs');
17
- require('./chunk-Z2JFX372.cjs');
18
- require('./chunk-3FDU5JFE.cjs');
17
+ require('./chunk-VUHXC74Q.cjs');
18
+ require('./chunk-7IZKTQ5G.cjs');
19
19
  require('./chunk-BV2MWEMV.cjs');
20
20
  require('./chunk-D6POWE7E.cjs');
21
21
  require('./chunk-GHX4P3V2.cjs');
22
22
  require('./chunk-TMKTSYDS.cjs');
23
- var chunkNQTNSHSB_cjs = require('./chunk-NQTNSHSB.cjs');
23
+ var chunkGFFBXSQT_cjs = require('./chunk-GFFBXSQT.cjs');
24
24
  var chunk7FDKWDA2_cjs = require('./chunk-7FDKWDA2.cjs');
25
25
  var chunkC4ZQPWXJ_cjs = require('./chunk-C4ZQPWXJ.cjs');
26
26
  require('./chunk-FUSDYC2B.cjs');
@@ -29,7 +29,7 @@ require('./chunk-24SYBZPL.cjs');
29
29
  require('./chunk-QOGNZMHD.cjs');
30
30
  var chunkYIFFF23U_cjs = require('./chunk-YIFFF23U.cjs');
31
31
  require('./chunk-2ZPEDVLM.cjs');
32
- require('./chunk-IU5N5224.cjs');
32
+ require('./chunk-EIOMN5VA.cjs');
33
33
  require('./chunk-KRD3GQAA.cjs');
34
34
  require('./chunk-RQMCOFAI.cjs');
35
35
  require('./chunk-MUUQ2WFJ.cjs');
@@ -38,8 +38,8 @@ require('./chunk-YSTXFWQE.cjs');
38
38
  require('./chunk-FRITRLZQ.cjs');
39
39
  require('./chunk-NQTD6QOW.cjs');
40
40
  require('./chunk-NINIJCHU.cjs');
41
- require('./chunk-QATRS7JD.cjs');
42
- require('./chunk-LOHMT36V.cjs');
41
+ var chunkMYJGWS2J_cjs = require('./chunk-MYJGWS2J.cjs');
42
+ require('./chunk-LD6HASA5.cjs');
43
43
  require('./chunk-IJ7M6GOG.cjs');
44
44
  require('./chunk-7A6535RA.cjs');
45
45
  require('./chunk-SA6K24NB.cjs');
@@ -53,9 +53,9 @@ require('./chunk-BJUJT5ED.cjs');
53
53
  var chunkZF2LDKQQ_cjs = require('./chunk-ZF2LDKQQ.cjs');
54
54
  var chunkHCT4HPCL_cjs = require('./chunk-HCT4HPCL.cjs');
55
55
  var chunkJLRLCBJ4_cjs = require('./chunk-JLRLCBJ4.cjs');
56
- require('./chunk-AYA65JA5.cjs');
57
- require('./chunk-43YXGD3P.cjs');
58
- require('./chunk-HW7SEELD.cjs');
56
+ require('./chunk-RWPLWMCZ.cjs');
57
+ var chunkTY56BKSK_cjs = require('./chunk-TY56BKSK.cjs');
58
+ require('./chunk-QRVS2PRE.cjs');
59
59
  var chunkATT276RD_cjs = require('./chunk-ATT276RD.cjs');
60
60
  var chunk3EE6LVWT_cjs = require('./chunk-3EE6LVWT.cjs');
61
61
  require('./chunk-ANMJJD6D.cjs');
@@ -67,15 +67,16 @@ require('./chunk-HUFSABUZ.cjs');
67
67
  var chunkJ7J7J2GN_cjs = require('./chunk-J7J7J2GN.cjs');
68
68
  var chunk6LHQPOMI_cjs = require('./chunk-6LHQPOMI.cjs');
69
69
  var crypto = require('crypto');
70
- var zod = require('zod');
71
70
  var promises = require('fs/promises');
72
71
  var path = require('path');
72
+ var zod = require('zod');
73
+ var os = require('os');
73
74
 
74
75
  // src/agent-factory.ts
75
76
  function createAgentFactory(common) {
76
77
  return {
77
- forSession: (agentId, overrides) => chunkUALC6Q3J_cjs.Agent.create(mergeAgentOptions(common, overrides, agentId)),
78
- getOrCreate: (agentId, overrides) => chunkUALC6Q3J_cjs.Agent.getOrCreate(agentId, mergeAgentOptions(common, overrides, agentId))
78
+ forSession: (agentId, overrides) => chunkGCHZMH42_cjs.Agent.create(mergeAgentOptions(common, overrides, agentId)),
79
+ getOrCreate: (agentId, overrides) => chunkGCHZMH42_cjs.Agent.getOrCreate(agentId, mergeAgentOptions(common, overrides, agentId))
79
80
  };
80
81
  }
81
82
  function mergeAgentOptions(common, overrides, agentId) {
@@ -686,12 +687,43 @@ var Provider = class _Provider {
686
687
  return _Provider.builtins().find((p) => p.name === provider);
687
688
  }
688
689
  };
690
+ async function resolveBody(skill) {
691
+ if (typeof skill.instructions === "string") {
692
+ const inline = skill;
693
+ return inline.references === void 0 ? { instructions: inline.instructions } : { instructions: inline.instructions, references: inline.references };
694
+ }
695
+ const source = skill.source;
696
+ const skillDir = path.dirname(source);
697
+ const body = chunkMYJGWS2J_cjs.stripSkillFrontmatter(await promises.readFile(source, "utf8"));
698
+ const instructions = body.replaceAll(SKILL_DIR_PLACEHOLDER, skillDir);
699
+ const references = await readReferences(skillDir);
700
+ return references === void 0 ? { instructions } : { instructions, references };
701
+ }
702
+ var SKILL_DIR_PLACEHOLDER = "${CLAUDE_SKILL_DIR}";
703
+ async function readReferences(skillDir) {
704
+ const dir = path.join(skillDir, "references");
705
+ let names;
706
+ try {
707
+ names = await promises.readdir(dir);
708
+ } catch {
709
+ return void 0;
710
+ }
711
+ const refs = {};
712
+ for (const name of names) {
713
+ try {
714
+ refs[name] = await promises.readFile(path.join(dir, name), "utf8");
715
+ } catch {
716
+ }
717
+ }
718
+ return Object.keys(refs).length > 0 ? refs : void 0;
719
+ }
689
720
  var SkillReadInputSchema = zod.z.object({
690
721
  name: zod.z.string().min(1, "skill_read: `name` is required.")
691
722
  });
692
- function renderSkill(skill) {
693
- const parts = [`# Skill: ${skill.name}`, "", skill.instructions];
694
- const refs = skill.references;
723
+ async function renderSkill(skill) {
724
+ const { instructions, references } = await resolveBody(skill);
725
+ const parts = [`# Skill: ${skill.name}`, "", instructions];
726
+ const refs = references;
695
727
  if (refs !== void 0 && Object.keys(refs).length > 0) {
696
728
  parts.push("", "## References");
697
729
  for (const [file, content] of Object.entries(refs)) {
@@ -714,6 +746,11 @@ function defineSkillReadTool(skills) {
714
746
  name: "skill_read",
715
747
  description: "Read a skill's full instructions (and any bundled reference documents) by its name. Use this to load the body of a skill listed in the <skills> block before acting on it.",
716
748
  inputSchema: chunkAA27GEYS_cjs.toJsonSchema(SkillReadInputSchema),
749
+ // NOT `async`. Marking the whole handler async turns the schema's SYNCHRONOUS throw into a
750
+ // rejected promise, and this module's contract is that malformed input "fails at the trust
751
+ // boundary via the schema" — measured, two trust-boundary tests went from throwing to
752
+ // returning `undefined`. Only the body read needs to be asynchronous, so only it returns a
753
+ // promise: parse and the not-found answer stay exactly as synchronous as they were.
717
754
  handler: (input) => {
718
755
  const { name } = SkillReadInputSchema.parse(input);
719
756
  const skill = skills.find((s) => s.name === name);
@@ -1023,10 +1060,10 @@ var JobQueue = class {
1023
1060
  this.running += 1;
1024
1061
  return Promise.resolve();
1025
1062
  }
1026
- return new Promise((resolve) => {
1063
+ return new Promise((resolve2) => {
1027
1064
  this.waiting.push(() => {
1028
1065
  this.running += 1;
1029
- resolve();
1066
+ resolve2();
1030
1067
  });
1031
1068
  });
1032
1069
  }
@@ -1220,8 +1257,8 @@ async function runInner(options) {
1220
1257
  const now = options.now ?? Date.now;
1221
1258
  const timestampMs = now();
1222
1259
  try {
1223
- const root = options.memoryRoot ?? chunkNQTNSHSB_cjs.resolveMemoryRoot(options.cwd);
1224
- const facts = await chunkNQTNSHSB_cjs.readFactsFromMarkdown(
1260
+ const root = options.memoryRoot ?? chunkGFFBXSQT_cjs.resolveMemoryRoot(options.cwd);
1261
+ const facts = await chunkGFFBXSQT_cjs.readFactsFromMarkdown(
1225
1262
  options.cwd,
1226
1263
  options.memoryRoot ? { directory: options.memoryRoot } : void 0
1227
1264
  );
@@ -1240,7 +1277,7 @@ async function runInner(options) {
1240
1277
  notesWritten,
1241
1278
  diaryEntryHash: void 0
1242
1279
  };
1243
- await chunkVPK6PHIE_cjs.appendDiaryEntry(root, {
1280
+ await chunk52FDUJSV_cjs.appendDiaryEntry(root, {
1244
1281
  timestampMs,
1245
1282
  factsBefore: result.factsBefore,
1246
1283
  factsAfter: result.factsAfter,
@@ -1334,8 +1371,8 @@ var Memory = {
1334
1371
  openArgs.embedding = await resolveEmbedding(opts.embedding, peer.MEMORY_EMBEDDING_ADAPTERS);
1335
1372
  return await peer.IndexManager.open(openArgs);
1336
1373
  }
1337
- const { IndexManager } = await import('./index-manager-3UNPYH34.cjs');
1338
- openArgs.embedding = await resolveEmbedding(opts.embedding, chunkUALC6Q3J_cjs.MEMORY_EMBEDDING_ADAPTERS);
1374
+ const { IndexManager } = await import('./index-manager-BBHDKMQS.cjs');
1375
+ openArgs.embedding = await resolveEmbedding(opts.embedding, chunkGCHZMH42_cjs.MEMORY_EMBEDDING_ADAPTERS);
1339
1376
  return await IndexManager.open(openArgs);
1340
1377
  },
1341
1378
  /**
@@ -1346,7 +1383,7 @@ var Memory = {
1346
1383
  */
1347
1384
  async runDreamingSweep(opts) {
1348
1385
  const peer = await tryLoadSdkMemoryPeer();
1349
- const catalog = peer !== null ? peer.MEMORY_EMBEDDING_ADAPTERS : chunkUALC6Q3J_cjs.MEMORY_EMBEDDING_ADAPTERS;
1386
+ const catalog = peer !== null ? peer.MEMORY_EMBEDDING_ADAPTERS : chunkGCHZMH42_cjs.MEMORY_EMBEDDING_ADAPTERS;
1350
1387
  const sweepArgs = await buildDreamingSweepArgs(opts, catalog);
1351
1388
  const result = peer !== null ? (
1352
1389
  // biome-ignore lint/suspicious/noExplicitAny: peer is dynamically loaded — structural compat ensured by sdk-memory
@@ -1380,7 +1417,7 @@ async function buildDreamingSweepArgs(opts, catalog) {
1380
1417
  const runtime = await resolveEmbedding(opts.embedding, catalog);
1381
1418
  return {
1382
1419
  cwd: opts.cwd,
1383
- memoryRoot: chunkNQTNSHSB_cjs.resolveMemoryRoot(opts.cwd, { directory: opts.directory }),
1420
+ memoryRoot: chunkGFFBXSQT_cjs.resolveMemoryRoot(opts.cwd, { directory: opts.directory }),
1384
1421
  embedding: runtime,
1385
1422
  ...opts.dedupThreshold !== void 0 ? { dedupThreshold: opts.dedupThreshold } : {},
1386
1423
  ...opts.clusterThreshold !== void 0 ? { clusterThreshold: opts.clusterThreshold } : {}
@@ -1419,7 +1456,7 @@ async function migrateSqliteToLance2(options) {
1419
1456
  if (peer !== null) {
1420
1457
  return peer.migrateSqliteToLance(options);
1421
1458
  }
1422
- return chunkVPK6PHIE_cjs.migrateSqliteToLance(options);
1459
+ return chunk52FDUJSV_cjs.migrateSqliteToLance(options);
1423
1460
  }
1424
1461
 
1425
1462
  // src/permission-engine.ts
@@ -1479,6 +1516,111 @@ var PermissionEngine = class {
1479
1516
  return true;
1480
1517
  }
1481
1518
  };
1519
+ var PROTECTED_SEGMENTS = [
1520
+ ".git",
1521
+ // The two agent-configuration directories come from the dialect declarations rather than being
1522
+ // spelled again here. A second copy of `.theokit` would drift from the one `paths.ts` resolves
1523
+ // against, and this list would then protect a directory the runtime no longer uses — worse than
1524
+ // not protecting it, because the gap would be invisible.
1525
+ chunkTY56BKSK_cjs.CLAUDE_DIR_NAME,
1526
+ chunkTY56BKSK_cjs.THEOKIT_DIR_LITERAL,
1527
+ ".ssh",
1528
+ ".gnupg"
1529
+ ];
1530
+ var PROTECTED_FILES = [
1531
+ ".envrc",
1532
+ ".npmrc",
1533
+ ".mcp.json",
1534
+ ".pre-commit-config.yaml",
1535
+ ".netrc"
1536
+ ];
1537
+ var WRITING_TOOLS = /^(write|edit|apply_?patch|multi_?edit|notebook_?edit|create)/i;
1538
+ var PATH_ARGS = ["file_path", "path", "notebook_path"];
1539
+ var COMMAND_ARGS = ["command", "cmd"];
1540
+ function permissionFloorReason(toolName, args, context = {}) {
1541
+ const cwd = path.resolve(context.cwd ?? process.cwd());
1542
+ const home = path.resolve(context.home ?? os.homedir());
1543
+ const command = firstString(args, COMMAND_ARGS);
1544
+ if (command !== void 0) {
1545
+ const target = destructiveTargetIn(command, { cwd, home });
1546
+ if (target !== void 0) {
1547
+ return `refused by the critical-path floor: "${command}" is a destructive operation on ${target}. This tier is above every permission rule and every mode \u2014 it is not a rule you can reorder, and nothing in your settings is misconfigured.`;
1548
+ }
1549
+ }
1550
+ if (!WRITING_TOOLS.test(toolName)) return void 0;
1551
+ const path$1 = firstString(args, PATH_ARGS);
1552
+ if (path$1 === void 0) return void 0;
1553
+ const protectedBy = protectedReasonFor(path$1);
1554
+ if (protectedBy !== void 0) {
1555
+ return `refused by the protected-path floor: writing "${path$1}" would change ${protectedBy}, which no allow rule can pre-approve. This tier is above every permission rule; nothing in your settings is misconfigured.`;
1556
+ }
1557
+ return void 0;
1558
+ }
1559
+ function firstString(args, names) {
1560
+ if (args === void 0) return void 0;
1561
+ for (const name of names) {
1562
+ const v = args[name];
1563
+ if (typeof v === "string") return v;
1564
+ }
1565
+ return void 0;
1566
+ }
1567
+ function protectedReasonFor(path$1) {
1568
+ const segments = path.normalize(path$1).split(/[\\/]+/).filter((s) => s.length > 0);
1569
+ for (const segment of segments) {
1570
+ if (PROTECTED_SEGMENTS.includes(segment)) return `the ${segment} directory`;
1571
+ }
1572
+ const last = segments.at(-1);
1573
+ if (last !== void 0 && PROTECTED_FILES.includes(last)) return `the ${last} file`;
1574
+ return void 0;
1575
+ }
1576
+ var DESTRUCTIVE = /(?:^|[;&|])\s*(rm|rmdir|shred|mkfs(?:\.[\w.-]{1,32})?|dd)\s/;
1577
+ function destructiveTargetIn(command, roots) {
1578
+ if (!DESTRUCTIVE.test(command)) return void 0;
1579
+ if (SUBSTITUTES.test(command)) {
1580
+ return "a target this floor cannot resolve (the command substitutes or expands it)";
1581
+ }
1582
+ const critical = criticalRootsFor(roots);
1583
+ for (const token of command.split(/\s+/)) {
1584
+ const target = absoluteTargetOf(token, roots.home);
1585
+ const hit = target === void 0 ? void 0 : critical.get(target);
1586
+ if (hit !== void 0) return hit;
1587
+ }
1588
+ return void 0;
1589
+ }
1590
+ var SUBSTITUTES = /\$\(|`|\$\{?\w/;
1591
+ function criticalRootsFor(roots) {
1592
+ const map = /* @__PURE__ */ new Map([
1593
+ [path.resolve("/"), "the filesystem root"],
1594
+ [roots.home, "the home directory"]
1595
+ ]);
1596
+ for (const parent of ancestorsOf(roots.cwd)) {
1597
+ map.set(parent, "a parent of the working directory");
1598
+ }
1599
+ map.set(roots.cwd, "the working directory");
1600
+ return map;
1601
+ }
1602
+ function absoluteTargetOf(token, home) {
1603
+ const bare = token.replace(/["']/g, "").replace(/\/\*+$/, "");
1604
+ if (bare.length === 0 || bare.startsWith("-")) return void 0;
1605
+ const expanded = bare === "~" || bare.startsWith(`~${path.sep}`) ? home : bare;
1606
+ return path.isAbsolute(expanded) ? path.resolve(expanded) : void 0;
1607
+ }
1608
+ function ancestorsOf(dir) {
1609
+ const out = [];
1610
+ let current = dir;
1611
+ const { root } = path.parse(dir);
1612
+ while (current !== root) {
1613
+ const parent = path.resolve(current, "..");
1614
+ if (parent === current) break;
1615
+ out.push(parent);
1616
+ current = parent;
1617
+ }
1618
+ return out;
1619
+ }
1620
+ function isInside(parent, child) {
1621
+ const rel = path.relative(path.resolve(parent), path.resolve(child));
1622
+ return rel.length > 0 && !rel.startsWith("..") && !path.isAbsolute(rel);
1623
+ }
1482
1624
 
1483
1625
  // src/permission-plugin.ts
1484
1626
  async function resolveAsk(opts, name, args, mode) {
@@ -1502,6 +1644,8 @@ function createPermissionPlugin(engine, opts = {}) {
1502
1644
  ctx.on("pre_tool_call", async (rawCtx) => {
1503
1645
  const { name, args, permissionMode } = rawCtx;
1504
1646
  const mode = permissionMode ?? opts.mode ?? "default";
1647
+ const floor = permissionFloorReason(name, args, {});
1648
+ if (floor !== void 0) return { block: true, message: floor };
1505
1649
  const action = engine.evaluate(name, args, mode);
1506
1650
  if (action === "deny") {
1507
1651
  return { block: true, message: `denied by permission engine: ${name}` };
@@ -1520,6 +1664,85 @@ var PermissionPlugin = class {
1520
1664
  }
1521
1665
  };
1522
1666
 
1667
+ // src/permission-rules.ts
1668
+ var PRIMARY_ARG_NAMES = ["command", "file_path", "path", "url", "query"];
1669
+ function parsePermissionRules(set) {
1670
+ return [
1671
+ ...(set.deny ?? []).flatMap((r) => parseOne(r, "deny")),
1672
+ ...(set.ask ?? []).flatMap((r) => parseOne(r, "ask")),
1673
+ ...(set.allow ?? []).flatMap((r) => parseOne(r, "allow"))
1674
+ ];
1675
+ }
1676
+ function parseOne(rule, action) {
1677
+ const trimmed = rule.trim();
1678
+ const open = trimmed.indexOf("(");
1679
+ if (open === -1) {
1680
+ if (trimmed.length === 0) {
1681
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError("permission rule is empty", { code: "permission_rule_invalid" });
1682
+ }
1683
+ return [{ tool: normaliseToolName(trimmed), action }];
1684
+ }
1685
+ if (!trimmed.endsWith(")")) {
1686
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(
1687
+ `permission rule "${rule}" opens a specifier and never closes it \u2014 expected Tool(specifier)`,
1688
+ { code: "permission_rule_invalid" }
1689
+ );
1690
+ }
1691
+ const tool = trimmed.slice(0, open).trim();
1692
+ const specifier = trimmed.slice(open + 1, -1);
1693
+ if (tool.length === 0) {
1694
+ throw new chunkJ7J7J2GN_cjs.ConfigurationError(`permission rule "${rule}" names no tool`, {
1695
+ code: "permission_rule_invalid"
1696
+ });
1697
+ }
1698
+ if (specifier === "*") return [{ tool: normaliseToolName(tool), action }];
1699
+ const test = predicateFor(specifier);
1700
+ const name = normaliseToolName(tool);
1701
+ return PRIMARY_ARG_NAMES.map((arg) => ({ tool: name, action, args: { [arg]: test } }));
1702
+ }
1703
+ function normaliseToolName(tool) {
1704
+ if (!tool.startsWith("mcp__")) return tool;
1705
+ return `mcp_${tool.slice("mcp__".length).replaceAll("__", "_")}`;
1706
+ }
1707
+ function predicateFor(specifier) {
1708
+ if (specifier.startsWith("path:")) {
1709
+ const re = globToRegExp(specifier.slice("path:".length));
1710
+ return (v) => typeof v === "string" && re.test(v);
1711
+ }
1712
+ if (specifier.startsWith("domain:")) {
1713
+ const host = specifier.slice("domain:".length).toLowerCase();
1714
+ return (v) => typeof v === "string" && hostOf(v) === host;
1715
+ }
1716
+ if (specifier.endsWith("*")) {
1717
+ const prefix = specifier.slice(0, -1);
1718
+ return (v) => typeof v === "string" && v.startsWith(prefix);
1719
+ }
1720
+ return (v) => v === specifier;
1721
+ }
1722
+ function hostOf(value) {
1723
+ try {
1724
+ return new URL(value).hostname.toLowerCase();
1725
+ } catch {
1726
+ return void 0;
1727
+ }
1728
+ }
1729
+ function translateGlobChar(glob, i) {
1730
+ const c = glob[i] ?? "";
1731
+ if (c === "?") return { pattern: "[^/]", consumed: 0 };
1732
+ if (c !== "*") return { pattern: c.replace(/[.+^${}()|[\]\\]/g, "\\$&"), consumed: 0 };
1733
+ if (glob[i + 1] !== "*") return { pattern: "[^/]*", consumed: 0 };
1734
+ return { pattern: ".*", consumed: glob[i + 2] === "/" ? 2 : 1 };
1735
+ }
1736
+ function globToRegExp(glob) {
1737
+ let out = "";
1738
+ for (let i = 0; i < glob.length; i += 1) {
1739
+ const piece = translateGlobChar(glob, i);
1740
+ out += piece.pattern;
1741
+ i += piece.consumed;
1742
+ }
1743
+ return new RegExp(`^${out}$`);
1744
+ }
1745
+
1523
1746
  // src/project-env.ts
1524
1747
  var SOVEREIGN_ENV_KEYS = [
1525
1748
  /** Locates the SDK home — sessions, and the credential store beneath it. */
@@ -1770,7 +1993,7 @@ function guardSessionDestruction(sessionId, live) {
1770
1993
  // src/session-messages.ts
1771
1994
  async function readSessionMessages2(options) {
1772
1995
  const cwd = options.cwd ?? process.cwd();
1773
- const baseDir = chunkUALC6Q3J_cjs.resolveSessionDir({ sessionDir: options.sessionDir });
1996
+ const baseDir = chunkGCHZMH42_cjs.resolveSessionDir({ sessionDir: options.sessionDir });
1774
1997
  return chunkYIFFF23U_cjs.readSessionMessages(new chunk7FDKWDA2_cjs.FsSessionStore({ baseDir, cwd }), options.sessionId);
1775
1998
  }
1776
1999
 
@@ -1787,7 +2010,7 @@ function isBuiltAgent(m) {
1787
2010
  return typeof m.send === "function";
1788
2011
  }
1789
2012
  async function materialize(def, index) {
1790
- const { Agent: Agent2 } = await import('./agent-AUVD4TI4.cjs');
2013
+ const { Agent: Agent2 } = await import('./agent-47NS6ZVL.cjs');
1791
2014
  return Agent2.create({
1792
2015
  // `AgentDefinition.model` admits the sentinel `'inherit'`, which is not a model id. Inheriting
1793
2016
  // here means "declare nothing and let the default apply" — forwarding the literal would create
@@ -1929,7 +2152,7 @@ var FIXTURE_USER = {
1929
2152
  };
1930
2153
  var FIXTURE_MODELS = [
1931
2154
  {
1932
- id: chunkUALC6Q3J_cjs.DEFAULT_AGENTIC_MODEL_ID,
2155
+ id: chunkGCHZMH42_cjs.DEFAULT_AGENTIC_MODEL_ID,
1933
2156
  name: "Gemini 2.0 Flash",
1934
2157
  displayName: "Gemini 2.0 Flash",
1935
2158
  parameters: [
@@ -2132,7 +2355,7 @@ var Theokit = class {
2132
2355
  envVars: p.envVars
2133
2356
  }));
2134
2357
  },
2135
- embeddingAdapters: () => Object.entries(chunkUALC6Q3J_cjs.MEMORY_EMBEDDING_ADAPTERS).map(([id, adapter]) => ({
2358
+ embeddingAdapters: () => Object.entries(chunkGCHZMH42_cjs.MEMORY_EMBEDDING_ADAPTERS).map(([id, adapter]) => ({
2136
2359
  id,
2137
2360
  transport: adapter.transport,
2138
2361
  defaultModel: adapter.defaultModel
@@ -2351,35 +2574,43 @@ Object.defineProperty(exports, "fn", {
2351
2574
  });
2352
2575
  Object.defineProperty(exports, "Cron", {
2353
2576
  enumerable: true,
2354
- get: function () { return chunkJ6KZE2ZQ_cjs.Cron; }
2577
+ get: function () { return chunkHG4UN4MN_cjs.Cron; }
2355
2578
  });
2356
2579
  Object.defineProperty(exports, "Agent", {
2357
2580
  enumerable: true,
2358
- get: function () { return chunkUALC6Q3J_cjs.Agent; }
2581
+ get: function () { return chunkGCHZMH42_cjs.Agent; }
2359
2582
  });
2360
2583
  Object.defineProperty(exports, "AgentBuilder", {
2361
2584
  enumerable: true,
2362
- get: function () { return chunkUALC6Q3J_cjs.AgentBuilder; }
2585
+ get: function () { return chunkGCHZMH42_cjs.AgentBuilder; }
2363
2586
  });
2364
2587
  Object.defineProperty(exports, "Tool", {
2365
2588
  enumerable: true,
2366
- get: function () { return chunkUALC6Q3J_cjs.Tool; }
2589
+ get: function () { return chunkGCHZMH42_cjs.Tool; }
2367
2590
  });
2368
2591
  Object.defineProperty(exports, "ToolError", {
2369
2592
  enumerable: true,
2370
- get: function () { return chunkUALC6Q3J_cjs.ToolError; }
2593
+ get: function () { return chunkGCHZMH42_cjs.ToolError; }
2371
2594
  });
2372
2595
  Object.defineProperty(exports, "UsageAccumulator", {
2373
2596
  enumerable: true,
2374
- get: function () { return chunkUALC6Q3J_cjs.UsageAccumulator; }
2597
+ get: function () { return chunkGCHZMH42_cjs.UsageAccumulator; }
2375
2598
  });
2376
2599
  Object.defineProperty(exports, "computeCost", {
2377
2600
  enumerable: true,
2378
- get: function () { return chunkUALC6Q3J_cjs.computeCost; }
2601
+ get: function () { return chunkGCHZMH42_cjs.computeCost; }
2379
2602
  });
2380
2603
  Object.defineProperty(exports, "getPricingEntry", {
2381
2604
  enumerable: true,
2382
- get: function () { return chunkUALC6Q3J_cjs.getPricingEntry; }
2605
+ get: function () { return chunkGCHZMH42_cjs.getPricingEntry; }
2606
+ });
2607
+ Object.defineProperty(exports, "managedSettingsPathFor", {
2608
+ enumerable: true,
2609
+ get: function () { return chunkGCHZMH42_cjs.managedSettingsPathFor; }
2610
+ });
2611
+ Object.defineProperty(exports, "readManagedSettings", {
2612
+ enumerable: true,
2613
+ get: function () { return chunkGCHZMH42_cjs.readManagedSettings; }
2383
2614
  });
2384
2615
  Object.defineProperty(exports, "emitRunEvent", {
2385
2616
  enumerable: true,
@@ -2510,11 +2741,14 @@ exports.extractRawId = extractRawId;
2510
2741
  exports.foldLayers = foldLayers;
2511
2742
  exports.guardSessionDestruction = guardSessionDestruction;
2512
2743
  exports.inferApiMode = inferApiMode;
2744
+ exports.isInside = isInside;
2513
2745
  exports.loadProjectEnv = loadProjectEnv;
2514
2746
  exports.migrateSqliteToLance = migrateSqliteToLance2;
2515
2747
  exports.mkMemoryId = mkMemoryId;
2516
2748
  exports.normalizeSchema = normalizeSchema;
2517
2749
  exports.normalizeUsage = normalizeUsage;
2750
+ exports.parsePermissionRules = parsePermissionRules;
2751
+ exports.permissionFloorReason = permissionFloorReason;
2518
2752
  exports.planReaping = planReaping;
2519
2753
  exports.preflightCheck = preflightCheck;
2520
2754
  exports.readSessionMessages = readSessionMessages2;