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