@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.js CHANGED
@@ -1,36 +1,37 @@
1
1
  export { StreamObjectError } from './chunk-5WKQDIGO.js';
2
2
  export { GOAL_CONTINUATION_MARKER } from './chunk-PY2RQOA7.js';
3
3
  export { JudgeCredentialError } from './chunk-IUMAQURF.js';
4
- import { migrateSqliteToLance, appendDiaryEntry } from './chunk-WS5ULCL4.js';
4
+ import { migrateSqliteToLance, appendDiaryEntry } from './chunk-YRLI5DVC.js';
5
5
  export { GenerateObjectError } from './chunk-44I6UYVH.js';
6
6
  import './chunk-47TF32NQ.js';
7
7
  import { Workflow, agentStep } from './chunk-HFEJE7AC.js';
8
8
  export { Workflow, agentStep, fn } from './chunk-HFEJE7AC.js';
9
9
  import './chunk-GBCVPKHE.js';
10
10
  import './chunk-HY66GLM6.js';
11
- export { Cron } from './chunk-M3ZGRGOG.js';
12
- import { MEMORY_EMBEDDING_ADAPTERS, resolveSessionDir, DEFAULT_AGENTIC_MODEL_ID, Agent } from './chunk-ODBID5TG.js';
13
- export { Agent, AgentBuilder, Tool, ToolError, UsageAccumulator, computeCost, getPricingEntry } from './chunk-ODBID5TG.js';
11
+ export { Cron } from './chunk-6JG2RFGK.js';
12
+ import { MEMORY_EMBEDDING_ADAPTERS, resolveSessionDir, DEFAULT_AGENTIC_MODEL_ID, Agent } from './chunk-FUUSIT2T.js';
13
+ export { Agent, AgentBuilder, Tool, ToolError, UsageAccumulator, computeCost, getPricingEntry, managedSettingsPathFor, readManagedSettings } from './chunk-FUUSIT2T.js';
14
14
  import { configure, submit, list, get, cancel, subscribe } from './chunk-K2VMFZQ5.js';
15
15
  export { emitRunEvent } from './chunk-K2VMFZQ5.js';
16
- import './chunk-2QKV4CGK.js';
16
+ import './chunk-CZWN4C6A.js';
17
17
  import './chunk-K2BQQ445.js';
18
- import './chunk-7SZAV6QG.js';
19
- import './chunk-S6B5XYC3.js';
18
+ import './chunk-P5S3WCSZ.js';
19
+ import './chunk-DQNI52VV.js';
20
20
  import './chunk-2SFBB54R.js';
21
21
  import './chunk-55GB6JYQ.js';
22
22
  import './chunk-H73MEMQB.js';
23
23
  import './chunk-OR6XIWLB.js';
24
- import { resolveMemoryRoot, readFactsFromMarkdown } from './chunk-SADXXGWU.js';
24
+ import { resolveMemoryRoot, readFactsFromMarkdown } from './chunk-R3LBRQAN.js';
25
25
  import { FsSessionStore } from './chunk-AAEZSPTC.js';
26
- import { discoverProviderPlugins, shouldUseFixtureMode, isFixtureApiKey, httpRequest, mapOllamaTransportError, readErrorResponseBody, mapOllamaHttpError } from './chunk-KZSKIUXZ.js';
26
+ import { discoverProviderPlugins, shouldUseFixtureMode, isFixtureApiKey, httpRequest, mapOllamaTransportError, readErrorResponseBody, mapOllamaHttpError } from './chunk-N7VAE6DZ.js';
27
27
  import './chunk-UBR5PWD7.js';
28
28
  import './chunk-2XC6KDJM.js';
29
29
  import './chunk-XB4GI5RZ.js';
30
30
  import './chunk-24MGQDK3.js';
31
31
  import { readSessionMessages } from './chunk-2WXHA33T.js';
32
32
  import './chunk-HKCKOAIO.js';
33
- import './chunk-N6OOOYFZ.js';
33
+ import './chunk-3VXQEQE4.js';
34
+ import './chunk-7C3HWGCW.js';
34
35
  import './chunk-KVNWIAO4.js';
35
36
  import './chunk-SVQIW5RJ.js';
36
37
  import './chunk-FD2UT76F.js';
@@ -39,8 +40,8 @@ import './chunk-FJWQP6EE.js';
39
40
  import './chunk-NAF4L3T6.js';
40
41
  import './chunk-CFE6QF2Q.js';
41
42
  import './chunk-6X6ID4MO.js';
42
- import './chunk-LX7SEXOQ.js';
43
- import './chunk-2XRAWOZZ.js';
43
+ import { stripSkillFrontmatter } from './chunk-CA5VUAP3.js';
44
+ import './chunk-A6PDYH55.js';
44
45
  import './chunk-SAGRF4IB.js';
45
46
  import './chunk-EH6XD3FY.js';
46
47
  import './chunk-UKMBRMGT.js';
@@ -55,9 +56,9 @@ import { withCwdMutex } from './chunk-Q5EWJPRY.js';
55
56
  export { withCwdMutex } from './chunk-Q5EWJPRY.js';
56
57
  export { TASK_RESERVED_PREFIXES, isValidTaskId } from './chunk-EIQFAOFD.js';
57
58
  import { replaceFileAtomic } from './chunk-3JHIFQ4I.js';
58
- import './chunk-O7L7M42F.js';
59
- import './chunk-NSLHPAC7.js';
60
- import './chunk-JNAA4G4H.js';
59
+ import './chunk-T3ZDEYTJ.js';
60
+ import { CLAUDE_DIR_NAME, THEOKIT_DIR_LITERAL } from './chunk-X7EUUHXU.js';
61
+ import './chunk-UOLBAPDM.js';
61
62
  import { estimateTokens, CHARS_PER_TOKEN } from './chunk-6M2OIS4Y.js';
62
63
  export { estimateTokens } from './chunk-6M2OIS4Y.js';
63
64
  import { parseModelId } from './chunk-R7WIIPUR.js';
@@ -72,9 +73,10 @@ export { AgentDisposedError, AgentRunError, AuthenticationError, BudgetExceededE
72
73
  import { diag, redactSecrets, addPattern, resolveApiKey } from './chunk-CZJ6Q7CW.js';
73
74
  export { setDiagnosticsSink } from './chunk-CZJ6Q7CW.js';
74
75
  import { createHash, randomUUID } from 'crypto';
76
+ import { readFile, mkdir, readdir } from 'fs/promises';
77
+ import { resolve, normalize, sep, isAbsolute, parse, relative, dirname, join } from 'path';
75
78
  import { z } from 'zod';
76
- import { mkdir } from 'fs/promises';
77
- import { join } from 'path';
79
+ import { homedir } from 'os';
78
80
 
79
81
  // src/agent-factory.ts
80
82
  function createAgentFactory(common) {
@@ -691,12 +693,43 @@ var Provider = class _Provider {
691
693
  return _Provider.builtins().find((p) => p.name === provider);
692
694
  }
693
695
  };
696
+ async function resolveBody(skill) {
697
+ if (typeof skill.instructions === "string") {
698
+ const inline = skill;
699
+ return inline.references === void 0 ? { instructions: inline.instructions } : { instructions: inline.instructions, references: inline.references };
700
+ }
701
+ const source = skill.source;
702
+ const skillDir = dirname(source);
703
+ const body = stripSkillFrontmatter(await readFile(source, "utf8"));
704
+ const instructions = body.replaceAll(SKILL_DIR_PLACEHOLDER, skillDir);
705
+ const references = await readReferences(skillDir);
706
+ return references === void 0 ? { instructions } : { instructions, references };
707
+ }
708
+ var SKILL_DIR_PLACEHOLDER = "${CLAUDE_SKILL_DIR}";
709
+ async function readReferences(skillDir) {
710
+ const dir = join(skillDir, "references");
711
+ let names;
712
+ try {
713
+ names = await readdir(dir);
714
+ } catch {
715
+ return void 0;
716
+ }
717
+ const refs = {};
718
+ for (const name of names) {
719
+ try {
720
+ refs[name] = await readFile(join(dir, name), "utf8");
721
+ } catch {
722
+ }
723
+ }
724
+ return Object.keys(refs).length > 0 ? refs : void 0;
725
+ }
694
726
  var SkillReadInputSchema = z.object({
695
727
  name: z.string().min(1, "skill_read: `name` is required.")
696
728
  });
697
- function renderSkill(skill) {
698
- const parts = [`# Skill: ${skill.name}`, "", skill.instructions];
699
- const refs = skill.references;
729
+ async function renderSkill(skill) {
730
+ const { instructions, references } = await resolveBody(skill);
731
+ const parts = [`# Skill: ${skill.name}`, "", instructions];
732
+ const refs = references;
700
733
  if (refs !== void 0 && Object.keys(refs).length > 0) {
701
734
  parts.push("", "## References");
702
735
  for (const [file, content] of Object.entries(refs)) {
@@ -719,6 +752,11 @@ function defineSkillReadTool(skills) {
719
752
  name: "skill_read",
720
753
  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.",
721
754
  inputSchema: toJsonSchema(SkillReadInputSchema),
755
+ // NOT `async`. Marking the whole handler async turns the schema's SYNCHRONOUS throw into a
756
+ // rejected promise, and this module's contract is that malformed input "fails at the trust
757
+ // boundary via the schema" — measured, two trust-boundary tests went from throwing to
758
+ // returning `undefined`. Only the body read needs to be asynchronous, so only it returns a
759
+ // promise: parse and the not-found answer stay exactly as synchronous as they were.
722
760
  handler: (input) => {
723
761
  const { name } = SkillReadInputSchema.parse(input);
724
762
  const skill = skills.find((s) => s.name === name);
@@ -1028,10 +1066,10 @@ var JobQueue = class {
1028
1066
  this.running += 1;
1029
1067
  return Promise.resolve();
1030
1068
  }
1031
- return new Promise((resolve) => {
1069
+ return new Promise((resolve2) => {
1032
1070
  this.waiting.push(() => {
1033
1071
  this.running += 1;
1034
- resolve();
1072
+ resolve2();
1035
1073
  });
1036
1074
  });
1037
1075
  }
@@ -1339,7 +1377,7 @@ var Memory = {
1339
1377
  openArgs.embedding = await resolveEmbedding(opts.embedding, peer.MEMORY_EMBEDDING_ADAPTERS);
1340
1378
  return await peer.IndexManager.open(openArgs);
1341
1379
  }
1342
- const { IndexManager } = await import('./index-manager-W7FDMGEG.js');
1380
+ const { IndexManager } = await import('./index-manager-Z4XMRVWQ.js');
1343
1381
  openArgs.embedding = await resolveEmbedding(opts.embedding, MEMORY_EMBEDDING_ADAPTERS);
1344
1382
  return await IndexManager.open(openArgs);
1345
1383
  },
@@ -1484,6 +1522,111 @@ var PermissionEngine = class {
1484
1522
  return true;
1485
1523
  }
1486
1524
  };
1525
+ var PROTECTED_SEGMENTS = [
1526
+ ".git",
1527
+ // The two agent-configuration directories come from the dialect declarations rather than being
1528
+ // spelled again here. A second copy of `.theokit` would drift from the one `paths.ts` resolves
1529
+ // against, and this list would then protect a directory the runtime no longer uses — worse than
1530
+ // not protecting it, because the gap would be invisible.
1531
+ CLAUDE_DIR_NAME,
1532
+ THEOKIT_DIR_LITERAL,
1533
+ ".ssh",
1534
+ ".gnupg"
1535
+ ];
1536
+ var PROTECTED_FILES = [
1537
+ ".envrc",
1538
+ ".npmrc",
1539
+ ".mcp.json",
1540
+ ".pre-commit-config.yaml",
1541
+ ".netrc"
1542
+ ];
1543
+ var WRITING_TOOLS = /^(write|edit|apply_?patch|multi_?edit|notebook_?edit|create)/i;
1544
+ var PATH_ARGS = ["file_path", "path", "notebook_path"];
1545
+ var COMMAND_ARGS = ["command", "cmd"];
1546
+ function permissionFloorReason(toolName, args, context = {}) {
1547
+ const cwd = resolve(context.cwd ?? process.cwd());
1548
+ const home = resolve(context.home ?? homedir());
1549
+ const command = firstString(args, COMMAND_ARGS);
1550
+ if (command !== void 0) {
1551
+ const target = destructiveTargetIn(command, { cwd, home });
1552
+ if (target !== void 0) {
1553
+ 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.`;
1554
+ }
1555
+ }
1556
+ if (!WRITING_TOOLS.test(toolName)) return void 0;
1557
+ const path = firstString(args, PATH_ARGS);
1558
+ if (path === void 0) return void 0;
1559
+ const protectedBy = protectedReasonFor(path);
1560
+ if (protectedBy !== void 0) {
1561
+ return `refused by the protected-path floor: writing "${path}" would change ${protectedBy}, which no allow rule can pre-approve. This tier is above every permission rule; nothing in your settings is misconfigured.`;
1562
+ }
1563
+ return void 0;
1564
+ }
1565
+ function firstString(args, names) {
1566
+ if (args === void 0) return void 0;
1567
+ for (const name of names) {
1568
+ const v = args[name];
1569
+ if (typeof v === "string") return v;
1570
+ }
1571
+ return void 0;
1572
+ }
1573
+ function protectedReasonFor(path) {
1574
+ const segments = normalize(path).split(/[\\/]+/).filter((s) => s.length > 0);
1575
+ for (const segment of segments) {
1576
+ if (PROTECTED_SEGMENTS.includes(segment)) return `the ${segment} directory`;
1577
+ }
1578
+ const last = segments.at(-1);
1579
+ if (last !== void 0 && PROTECTED_FILES.includes(last)) return `the ${last} file`;
1580
+ return void 0;
1581
+ }
1582
+ var DESTRUCTIVE = /(?:^|[;&|])\s*(rm|rmdir|shred|mkfs(?:\.[\w.-]{1,32})?|dd)\s/;
1583
+ function destructiveTargetIn(command, roots) {
1584
+ if (!DESTRUCTIVE.test(command)) return void 0;
1585
+ if (SUBSTITUTES.test(command)) {
1586
+ return "a target this floor cannot resolve (the command substitutes or expands it)";
1587
+ }
1588
+ const critical = criticalRootsFor(roots);
1589
+ for (const token of command.split(/\s+/)) {
1590
+ const target = absoluteTargetOf(token, roots.home);
1591
+ const hit = target === void 0 ? void 0 : critical.get(target);
1592
+ if (hit !== void 0) return hit;
1593
+ }
1594
+ return void 0;
1595
+ }
1596
+ var SUBSTITUTES = /\$\(|`|\$\{?\w/;
1597
+ function criticalRootsFor(roots) {
1598
+ const map = /* @__PURE__ */ new Map([
1599
+ [resolve("/"), "the filesystem root"],
1600
+ [roots.home, "the home directory"]
1601
+ ]);
1602
+ for (const parent of ancestorsOf(roots.cwd)) {
1603
+ map.set(parent, "a parent of the working directory");
1604
+ }
1605
+ map.set(roots.cwd, "the working directory");
1606
+ return map;
1607
+ }
1608
+ function absoluteTargetOf(token, home) {
1609
+ const bare = token.replace(/["']/g, "").replace(/\/\*+$/, "");
1610
+ if (bare.length === 0 || bare.startsWith("-")) return void 0;
1611
+ const expanded = bare === "~" || bare.startsWith(`~${sep}`) ? home : bare;
1612
+ return isAbsolute(expanded) ? resolve(expanded) : void 0;
1613
+ }
1614
+ function ancestorsOf(dir) {
1615
+ const out = [];
1616
+ let current = dir;
1617
+ const { root } = parse(dir);
1618
+ while (current !== root) {
1619
+ const parent = resolve(current, "..");
1620
+ if (parent === current) break;
1621
+ out.push(parent);
1622
+ current = parent;
1623
+ }
1624
+ return out;
1625
+ }
1626
+ function isInside(parent, child) {
1627
+ const rel = relative(resolve(parent), resolve(child));
1628
+ return rel.length > 0 && !rel.startsWith("..") && !isAbsolute(rel);
1629
+ }
1487
1630
 
1488
1631
  // src/permission-plugin.ts
1489
1632
  async function resolveAsk(opts, name, args, mode) {
@@ -1507,6 +1650,8 @@ function createPermissionPlugin(engine, opts = {}) {
1507
1650
  ctx.on("pre_tool_call", async (rawCtx) => {
1508
1651
  const { name, args, permissionMode } = rawCtx;
1509
1652
  const mode = permissionMode ?? opts.mode ?? "default";
1653
+ const floor = permissionFloorReason(name, args, {});
1654
+ if (floor !== void 0) return { block: true, message: floor };
1510
1655
  const action = engine.evaluate(name, args, mode);
1511
1656
  if (action === "deny") {
1512
1657
  return { block: true, message: `denied by permission engine: ${name}` };
@@ -1525,6 +1670,85 @@ var PermissionPlugin = class {
1525
1670
  }
1526
1671
  };
1527
1672
 
1673
+ // src/permission-rules.ts
1674
+ var PRIMARY_ARG_NAMES = ["command", "file_path", "path", "url", "query"];
1675
+ function parsePermissionRules(set) {
1676
+ return [
1677
+ ...(set.deny ?? []).flatMap((r) => parseOne(r, "deny")),
1678
+ ...(set.ask ?? []).flatMap((r) => parseOne(r, "ask")),
1679
+ ...(set.allow ?? []).flatMap((r) => parseOne(r, "allow"))
1680
+ ];
1681
+ }
1682
+ function parseOne(rule, action) {
1683
+ const trimmed = rule.trim();
1684
+ const open = trimmed.indexOf("(");
1685
+ if (open === -1) {
1686
+ if (trimmed.length === 0) {
1687
+ throw new ConfigurationError("permission rule is empty", { code: "permission_rule_invalid" });
1688
+ }
1689
+ return [{ tool: normaliseToolName(trimmed), action }];
1690
+ }
1691
+ if (!trimmed.endsWith(")")) {
1692
+ throw new ConfigurationError(
1693
+ `permission rule "${rule}" opens a specifier and never closes it \u2014 expected Tool(specifier)`,
1694
+ { code: "permission_rule_invalid" }
1695
+ );
1696
+ }
1697
+ const tool = trimmed.slice(0, open).trim();
1698
+ const specifier = trimmed.slice(open + 1, -1);
1699
+ if (tool.length === 0) {
1700
+ throw new ConfigurationError(`permission rule "${rule}" names no tool`, {
1701
+ code: "permission_rule_invalid"
1702
+ });
1703
+ }
1704
+ if (specifier === "*") return [{ tool: normaliseToolName(tool), action }];
1705
+ const test = predicateFor(specifier);
1706
+ const name = normaliseToolName(tool);
1707
+ return PRIMARY_ARG_NAMES.map((arg) => ({ tool: name, action, args: { [arg]: test } }));
1708
+ }
1709
+ function normaliseToolName(tool) {
1710
+ if (!tool.startsWith("mcp__")) return tool;
1711
+ return `mcp_${tool.slice("mcp__".length).replaceAll("__", "_")}`;
1712
+ }
1713
+ function predicateFor(specifier) {
1714
+ if (specifier.startsWith("path:")) {
1715
+ const re = globToRegExp(specifier.slice("path:".length));
1716
+ return (v) => typeof v === "string" && re.test(v);
1717
+ }
1718
+ if (specifier.startsWith("domain:")) {
1719
+ const host = specifier.slice("domain:".length).toLowerCase();
1720
+ return (v) => typeof v === "string" && hostOf(v) === host;
1721
+ }
1722
+ if (specifier.endsWith("*")) {
1723
+ const prefix = specifier.slice(0, -1);
1724
+ return (v) => typeof v === "string" && v.startsWith(prefix);
1725
+ }
1726
+ return (v) => v === specifier;
1727
+ }
1728
+ function hostOf(value) {
1729
+ try {
1730
+ return new URL(value).hostname.toLowerCase();
1731
+ } catch {
1732
+ return void 0;
1733
+ }
1734
+ }
1735
+ function translateGlobChar(glob, i) {
1736
+ const c = glob[i] ?? "";
1737
+ if (c === "?") return { pattern: "[^/]", consumed: 0 };
1738
+ if (c !== "*") return { pattern: c.replace(/[.+^${}()|[\]\\]/g, "\\$&"), consumed: 0 };
1739
+ if (glob[i + 1] !== "*") return { pattern: "[^/]*", consumed: 0 };
1740
+ return { pattern: ".*", consumed: glob[i + 2] === "/" ? 2 : 1 };
1741
+ }
1742
+ function globToRegExp(glob) {
1743
+ let out = "";
1744
+ for (let i = 0; i < glob.length; i += 1) {
1745
+ const piece = translateGlobChar(glob, i);
1746
+ out += piece.pattern;
1747
+ i += piece.consumed;
1748
+ }
1749
+ return new RegExp(`^${out}$`);
1750
+ }
1751
+
1528
1752
  // src/project-env.ts
1529
1753
  var SOVEREIGN_ENV_KEYS = [
1530
1754
  /** Locates the SDK home — sessions, and the credential store beneath it. */
@@ -1792,7 +2016,7 @@ function isBuiltAgent(m) {
1792
2016
  return typeof m.send === "function";
1793
2017
  }
1794
2018
  async function materialize(def, index) {
1795
- const { Agent: Agent2 } = await import('./agent-G3T7Q3SQ.js');
2019
+ const { Agent: Agent2 } = await import('./agent-EQ5HKTWV.js');
1796
2020
  return Agent2.create({
1797
2021
  // `AgentDefinition.model` admits the sentinel `'inherit'`, which is not a model id. Inheriting
1798
2022
  // here means "declare nothing and let the default apply" — forwarding the literal would create
@@ -2326,6 +2550,6 @@ function recordWiring(input) {
2326
2550
  return record;
2327
2551
  }
2328
2552
 
2329
- export { AgentFactory, Budget, EventBus, JobQueue, LayerOrderError, LiveSessionError, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, RetentionPolicyError, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UngatedCapabilityError, UnicodeNormalizer, applyMode, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, createCounterBudgetTracker, decideApproval, describeAction, describeCredential, effectiveToolNames, evaluateBlastRadius, extractRawId, foldLayers, guardSessionDestruction, inferApiMode, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, planReaping, preflightCheck, readSessionMessages2 as readSessionMessages, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, verifyLayerOrdering, withBlastRadius };
2553
+ export { AgentFactory, Budget, EventBus, JobQueue, LayerOrderError, LiveSessionError, Memory, NoopMemoryProvider, PermissionEngine, PermissionPlugin, Plugin, Provider, RetentionPolicyError, SOVEREIGN_ENV_KEYS, Security, Skill, SkillReadTool, Squad, Task, Theokit, TokenLimiter, UngatedCapabilityError, UnicodeNormalizer, applyMode, applySecurityFloor, auditEnvReachability, chargeAndCheckThresholds, createCounterBudgetTracker, decideApproval, describeAction, describeCredential, effectiveToolNames, evaluateBlastRadius, extractRawId, foldLayers, guardSessionDestruction, inferApiMode, isInside, loadProjectEnv, migrateSqliteToLance2 as migrateSqliteToLance, mkMemoryId, normalizeSchema, normalizeUsage, parsePermissionRules, permissionFloorReason, planReaping, preflightCheck, readSessionMessages2 as readSessionMessages, recordWiring, resolveTrustPosture, runGoalLoop, scopedConversationId, sessionScopePrefix, toShareGptTrajectory, verifyLayerOrdering, withBlastRadius };
2330
2554
  //# sourceMappingURL=index.js.map
2331
2555
  //# sourceMappingURL=index.js.map