@theokit/agents 16.5.2 → 16.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 (60) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +88 -5
  3. package/dist/{agent-compiler-C-4X_vKz.d.ts → agent-compiler-aubY9WIa.d.ts} +13 -1
  4. package/dist/{agent-handle-rEWdERuv.d.ts → agent-handle-C343-xUh.d.ts} +16 -1
  5. package/dist/{agent-orchestrator-BHF1bS6k.d.ts → agent-orchestrator-DQtfrPaq.d.ts} +2 -2
  6. package/dist/{agent-runner-BoMoOnHV.d.ts → agent-runner-BuuqK_Dp.d.ts} +3 -3
  7. package/dist/{agent-sse-handler-BRp9vHrb.d.ts → agent-sse-handler-BtIpJZxO.d.ts} +3 -1
  8. package/dist/auth.d.ts +21 -1
  9. package/dist/auth.js +23 -13
  10. package/dist/auth.js.map +1 -1
  11. package/dist/{bridge-entry-DO1LjHkc.d.ts → bridge-entry-nkeH6pAk.d.ts} +50 -7
  12. package/dist/bridge.d.ts +6 -6
  13. package/dist/bridge.js +9 -5
  14. package/dist/{chunk-KXE52FP2.js → chunk-4DOKIDGC.js} +59 -1
  15. package/dist/chunk-4DOKIDGC.js.map +1 -0
  16. package/dist/{chunk-NIQJ4GZX.js → chunk-JJ6Y6EBP.js} +4 -1
  17. package/dist/chunk-JJ6Y6EBP.js.map +1 -0
  18. package/dist/{chunk-ZLKZOSWR.js → chunk-RXD6S6RV.js} +2 -2
  19. package/dist/{chunk-K4MY4CV7.js → chunk-UARNAQ6O.js} +3 -3
  20. package/dist/{chunk-AZ2FOUSN.js → chunk-W533YIGA.js} +32 -5
  21. package/dist/chunk-W533YIGA.js.map +1 -0
  22. package/dist/{chunk-RZWD73QG.js → chunk-XGW7IZP6.js} +70 -5
  23. package/dist/chunk-XGW7IZP6.js.map +1 -0
  24. package/dist/client-react.d.ts +1 -1
  25. package/dist/client-react.js +1 -1
  26. package/dist/client.d.ts +14 -4
  27. package/dist/client.js +49 -2
  28. package/dist/client.js.map +1 -1
  29. package/dist/commands.d.ts +64 -12
  30. package/dist/commands.js +104 -12
  31. package/dist/commands.js.map +1 -1
  32. package/dist/config.d.ts +105 -1
  33. package/dist/config.js +460 -62
  34. package/dist/config.js.map +1 -1
  35. package/dist/{delegation-scoring-BBPJ9eug.d.ts → delegation-scoring-DPckVefy.d.ts} +1 -1
  36. package/dist/evals.d.ts +3 -3
  37. package/dist/evals.js +2 -2
  38. package/dist/handoff.d.ts +4 -4
  39. package/dist/handoff.js +3 -3
  40. package/dist/hooks.d.ts +24 -1
  41. package/dist/hooks.js +78 -3
  42. package/dist/hooks.js.map +1 -1
  43. package/dist/index.d.ts +22 -12
  44. package/dist/index.js +17 -5
  45. package/dist/index.js.map +1 -1
  46. package/dist/{sdk-adapter-C57SpmLH.d.ts → sdk-adapter-B0i8J7N0.d.ts} +2 -2
  47. package/dist/session.d.ts +17 -1
  48. package/dist/session.js +15 -0
  49. package/dist/session.js.map +1 -1
  50. package/dist/testing.d.ts +1 -1
  51. package/dist/testing.js +1 -1
  52. package/dist/tools.d.ts +4 -4
  53. package/dist/tools.js +4 -4
  54. package/package.json +3 -3
  55. package/dist/chunk-AZ2FOUSN.js.map +0 -1
  56. package/dist/chunk-KXE52FP2.js.map +0 -1
  57. package/dist/chunk-NIQJ4GZX.js.map +0 -1
  58. package/dist/chunk-RZWD73QG.js.map +0 -1
  59. /package/dist/{chunk-ZLKZOSWR.js.map → chunk-RXD6S6RV.js.map} +0 -0
  60. /package/dist/{chunk-K4MY4CV7.js.map → chunk-UARNAQ6O.js.map} +0 -0
package/dist/config.js CHANGED
@@ -87,13 +87,105 @@ function buildReport(layers) {
87
87
  }
88
88
  __name(buildReport, "buildReport");
89
89
 
90
+ // src/config/app-bootstrap.ts
91
+ import { existsSync, readFileSync } from "fs";
92
+ import { join } from "path";
93
+ import { parseEnv } from "util";
94
+ import { loadProjectEnv } from "@theokit/sdk";
95
+ import { TheokitAgentError as TheokitAgentError2 } from "@theokit/sdk/errors";
96
+ var BootstrapStepError = class extends TheokitAgentError2 {
97
+ static {
98
+ __name(this, "BootstrapStepError");
99
+ }
100
+ name = "BootstrapStepError";
101
+ step;
102
+ constructor(step, cause) {
103
+ const detail = cause instanceof Error ? cause.message : String(cause);
104
+ super(`[@theokit/agents] bootstrap step "${step}" failed: ${detail}`, {
105
+ code: "bootstrap_step_failed",
106
+ isRetryable: false,
107
+ cause
108
+ });
109
+ this.step = step;
110
+ }
111
+ };
112
+ var BootstrapNotRunError = class extends TheokitAgentError2 {
113
+ static {
114
+ __name(this, "BootstrapNotRunError");
115
+ }
116
+ name = "BootstrapNotRunError";
117
+ constructor(caller) {
118
+ super(`[@theokit/agents] ${caller} was called before the app bootstrap completed`, {
119
+ code: "bootstrap_not_run",
120
+ isRetryable: false
121
+ });
122
+ }
123
+ };
124
+ function defineAppBootstrap(steps) {
125
+ const seen = /* @__PURE__ */ new Set();
126
+ for (const step of steps) {
127
+ if (seen.has(step.name)) {
128
+ throw new Error(`[@theokit/agents] defineAppBootstrap: duplicate step name "${step.name}"`);
129
+ }
130
+ seen.add(step.name);
131
+ }
132
+ const list = [
133
+ ...steps
134
+ ];
135
+ let pending;
136
+ let done = false;
137
+ const execute = /* @__PURE__ */ __name(async (ctx) => {
138
+ await Promise.resolve();
139
+ const ran = [];
140
+ for (const step of list) {
141
+ try {
142
+ await step.run(ctx);
143
+ } catch (cause) {
144
+ throw new BootstrapStepError(step.name, cause);
145
+ }
146
+ ran.push(step.name);
147
+ }
148
+ done = true;
149
+ return {
150
+ ran
151
+ };
152
+ }, "execute");
153
+ return {
154
+ run(ctx) {
155
+ pending ??= execute(ctx);
156
+ return pending;
157
+ },
158
+ steps: list.map((s) => s.name),
159
+ get done() {
160
+ return done;
161
+ }
162
+ };
163
+ }
164
+ __name(defineAppBootstrap, "defineAppBootstrap");
165
+ function assertBootstrapped(bootstrap, caller) {
166
+ if (!bootstrap.done) throw new BootstrapNotRunError(caller);
167
+ }
168
+ __name(assertBootstrapped, "assertBootstrapped");
169
+ var projectEnvStep = {
170
+ name: "project-env",
171
+ run(ctx) {
172
+ loadProjectEnv(ctx.env, () => {
173
+ const file = join(ctx.cwd, ".env");
174
+ if (!existsSync(file)) return;
175
+ for (const [key, value] of Object.entries(parseEnv(readFileSync(file, "utf8")))) {
176
+ ctx.env[key] ??= value;
177
+ }
178
+ });
179
+ }
180
+ };
181
+
90
182
  // src/config/trust-store.ts
91
- import { chmodSync, existsSync, readFileSync, realpathSync, statSync } from "fs";
183
+ import { chmodSync, existsSync as existsSync2, readFileSync as readFileSync2, realpathSync, statSync } from "fs";
92
184
  import { resolve } from "path";
93
185
  import { resolveTrustPosture } from "@theokit/sdk";
94
- import { TheokitAgentError as TheokitAgentError2 } from "@theokit/sdk/errors";
186
+ import { TheokitAgentError as TheokitAgentError3 } from "@theokit/sdk/errors";
95
187
  import { atomicWriteJson, withFileLock } from "@theokit/sdk/persistence";
96
- var TrustStorePermissionsError = class extends TheokitAgentError2 {
188
+ var TrustStorePermissionsError = class extends TheokitAgentError3 {
97
189
  static {
98
190
  __name(this, "TrustStorePermissionsError");
99
191
  }
@@ -145,9 +237,9 @@ var TrustStore = class {
145
237
  * correct starting state and the safe one.
146
238
  */
147
239
  read() {
148
- if (!existsSync(this.file)) return [];
240
+ if (!existsSync2(this.file)) return [];
149
241
  this.assertSafePermissions();
150
- const parsed = JSON.parse(readFileSync(this.file, "utf8"));
242
+ const parsed = JSON.parse(readFileSync2(this.file, "utf8"));
151
243
  return parsed.records;
152
244
  }
153
245
  /**
@@ -166,7 +258,7 @@ var TrustStore = class {
166
258
  async trust(record) {
167
259
  ensureSecureDir(this.file);
168
260
  await withFileLock(this.file, async () => {
169
- const existing = existsSync(this.file) ? this.read() : [];
261
+ const existing = existsSync2(this.file) ? this.read() : [];
170
262
  const key = canonicalDir(record.path);
171
263
  const records = [
172
264
  ...existing.filter((r) => canonicalDir(r.path) !== key),
@@ -204,7 +296,7 @@ var TrustStore = class {
204
296
  };
205
297
 
206
298
  // src/config/instruction-imports.ts
207
- import { existsSync as existsSync2, readFileSync as readFileSync2, realpathSync as realpathSync2 } from "fs";
299
+ import { existsSync as existsSync3, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
208
300
  import { dirname, resolve as resolve2 } from "path";
209
301
  var MAX_IMPORT_DEPTH = 4;
210
302
  var IMPORT_REGEX = /(?<![\w`])@([\w~./-]+\.md)\b/g;
@@ -228,7 +320,7 @@ function importTarget(name, filePath, rootDir, visited, warn) {
228
320
  return void 0;
229
321
  }
230
322
  const target = resolve2(dirname(filePath), name);
231
- if (!existsSync2(target)) {
323
+ if (!existsSync3(target)) {
232
324
  warn(`instruction import @${name} in ${filePath} was not found \u2014 kept literal`);
233
325
  return void 0;
234
326
  }
@@ -277,7 +369,7 @@ function expand(text, filePath, ctx) {
277
369
  ctx.visited.add(target);
278
370
  let content;
279
371
  try {
280
- content = readFileSync2(target, "utf8");
372
+ content = readFileSync3(target, "utf8");
281
373
  } catch {
282
374
  ctx.warn(`instruction import @${name} in ${filePath} could not be read \u2014 kept literal`);
283
375
  out.push(match[0]);
@@ -295,8 +387,8 @@ function expand(text, filePath, ctx) {
295
387
  __name(expand, "expand");
296
388
 
297
389
  // src/config/instruction-tree.ts
298
- import { readFileSync as readFileSync3, readdirSync, statSync as statSync2 } from "fs";
299
- import { join, relative, resolve as resolve3 } from "path";
390
+ import { readFileSync as readFileSync4, readdirSync, statSync as statSync2 } from "fs";
391
+ import { join as join2, relative, resolve as resolve3 } from "path";
300
392
  import { assertNoSymlinkEscape } from "@theokit/sdk/path-safety";
301
393
 
302
394
  // src/config/frontmatter.ts
@@ -340,9 +432,13 @@ function globToRegExp(scope) {
340
432
  const char = scope[i];
341
433
  if (char === "*") {
342
434
  if (scope[i + 1] === "*") {
343
- out += ".*";
344
435
  i += 1;
345
- if (scope[i + 1] === "/") i += 1;
436
+ if (scope[i + 1] === "/") {
437
+ out += "(?:.*/)?";
438
+ i += 1;
439
+ } else {
440
+ out += ".*";
441
+ }
346
442
  continue;
347
443
  }
348
444
  out += "[^/]*";
@@ -431,7 +527,7 @@ function walkOrder(dir, entries, order) {
431
527
  for (const entry of [
432
528
  ...entries
433
529
  ].sort((a, b) => a.localeCompare(b))) {
434
- const path = join(dir, entry);
530
+ const path = join2(dir, entry);
435
531
  try {
436
532
  found.push({
437
533
  entry,
@@ -454,7 +550,7 @@ __name(walkOrder, "walkOrder");
454
550
  function parseInstructionFile(path, cwd, warn) {
455
551
  let raw;
456
552
  try {
457
- raw = readFileSync3(path, "utf8");
553
+ raw = readFileSync4(path, "utf8");
458
554
  } catch {
459
555
  return void 0;
460
556
  }
@@ -569,21 +665,21 @@ function composeInstructions(base, sources, options) {
569
665
  __name(composeInstructions, "composeInstructions");
570
666
 
571
667
  // src/config/custom-commands.ts
572
- import { readFileSync as readFileSync4, readdirSync as readdirSync3, statSync as statSync3 } from "fs";
573
- import { extname, join as join3, relative as relative2 } from "path";
668
+ import { readFileSync as readFileSync5, readdirSync as readdirSync3, statSync as statSync3 } from "fs";
669
+ import { extname, join as join4, relative as relative2 } from "path";
574
670
 
575
671
  // src/bridge/unloaded-surfaces.ts
576
- import { existsSync as existsSync3, readdirSync as readdirSync2 } from "fs";
577
- import { join as join2 } from "path";
578
- var WORKFLOWS_DIR = join2(".claude", "workflows");
672
+ import { existsSync as existsSync4, readdirSync as readdirSync2 } from "fs";
673
+ import { join as join3 } from "path";
674
+ var WORKFLOWS_DIR = join3(".claude", "workflows");
579
675
  var SCRIPT_SUFFIXES = [
580
676
  ".js",
581
677
  ".mjs",
582
678
  ".cjs"
583
679
  ];
584
680
  function reportUnloadedSurfaces(input) {
585
- const dir = join2(input.cwd, WORKFLOWS_DIR);
586
- if (!existsSync3(dir)) return;
681
+ const dir = join3(input.cwd, WORKFLOWS_DIR);
682
+ if (!existsSync4(dir)) return;
587
683
  let scripts;
588
684
  try {
589
685
  scripts = readdirSync2(dir).filter((f) => SCRIPT_SUFFIXES.some((s) => f.endsWith(s)));
@@ -598,8 +694,8 @@ function reportUnloadedSurfaces(input) {
598
694
  __name(reportUnloadedSurfaces, "reportUnloadedSurfaces");
599
695
 
600
696
  // src/config/custom-commands.ts
601
- var COMMANDS_DIR = join3(".theokit", "commands");
602
- var COMPAT_COMMANDS_DIR = join3(".claude", "commands");
697
+ var COMMANDS_DIR = join4(".theokit", "commands");
698
+ var COMPAT_COMMANDS_DIR = join4(".claude", "commands");
603
699
  var CLAUDE_CODE_SOURCE = "claude-code";
604
700
  var IGNORE_WARNING3 = /* @__PURE__ */ __name(() => void 0, "IGNORE_WARNING");
605
701
  function declaresCommands(sources) {
@@ -621,9 +717,9 @@ function projectCommandDirs(input) {
621
717
  if (input.projectDir === void 0) return [];
622
718
  const dirs = [];
623
719
  if (declaresCommands(input.compatSources)) {
624
- dirs.push(join3(input.projectDir, COMPAT_COMMANDS_DIR));
720
+ dirs.push(join4(input.projectDir, COMPAT_COMMANDS_DIR));
625
721
  }
626
- dirs.push(join3(input.projectDir, COMMANDS_DIR));
722
+ dirs.push(join4(input.projectDir, COMMANDS_DIR));
627
723
  return dirs;
628
724
  }
629
725
  __name(projectCommandDirs, "projectCommandDirs");
@@ -656,7 +752,7 @@ function loadCustomCommands(input) {
656
752
  });
657
753
  }
658
754
  if (input.homeDir !== void 0) {
659
- for (const command of readCommandsDir(join3(input.homeDir, COMMANDS_DIR), "user", warn)) {
755
+ for (const command of readCommandsDir(join4(input.homeDir, COMMANDS_DIR), "user", warn)) {
660
756
  loaded.set(command.name, command);
661
757
  }
662
758
  }
@@ -692,7 +788,7 @@ function readCommandsDir(dir, source, warn, root = dir) {
692
788
  entries.sort((a, b) => a.localeCompare(b));
693
789
  const commands = [];
694
790
  for (const entry of entries) {
695
- const path = join3(dir, entry);
791
+ const path = join4(dir, entry);
696
792
  let stats;
697
793
  try {
698
794
  stats = statSync3(path);
@@ -713,7 +809,7 @@ __name(readCommandsDir, "readCommandsDir");
713
809
  function parseCommandFile(path, entry, source, warn) {
714
810
  let raw;
715
811
  try {
716
- raw = readFileSync4(path, "utf8");
812
+ raw = readFileSync5(path, "utf8");
717
813
  } catch {
718
814
  return void 0;
719
815
  }
@@ -874,13 +970,13 @@ function settingsLayerChain(values) {
874
970
  __name(settingsLayerChain, "settingsLayerChain");
875
971
 
876
972
  // src/config/output-styles.ts
877
- import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
878
- import { join as join5 } from "path";
879
- import { TheokitAgentError as TheokitAgentError3 } from "@theokit/sdk/errors";
973
+ import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
974
+ import { join as join6 } from "path";
975
+ import { TheokitAgentError as TheokitAgentError4 } from "@theokit/sdk/errors";
880
976
 
881
977
  // src/config/settings-file.ts
882
- import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
883
- import { join as join4 } from "path";
978
+ import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
979
+ import { join as join5 } from "path";
884
980
  import { z } from "zod";
885
981
  var SETTINGS_SCHEMA = z.looseObject({
886
982
  /** Selects a file under `.claude/output-styles/`. Consumed by `loadOutputStyle`. */
@@ -911,6 +1007,44 @@ var SETTINGS_SCHEMA = z.looseObject({
911
1007
  ask: z.array(z.string()).optional()
912
1008
  }).loose().optional()
913
1009
  });
1010
+ var FOREIGN_KEY_DECISIONS = {
1011
+ permissions: {
1012
+ verdict: "honoured",
1013
+ because: "translated into PermissionRule[] and enforced by a pre_tool_call plugin, with denies ordered ahead of allows"
1014
+ },
1015
+ hooks: {
1016
+ verdict: "honoured",
1017
+ because: "granted per surface, and withheld entirely by a consumer that gates them, because a hook executes shell from a file the repository ships"
1018
+ },
1019
+ outputStyle: {
1020
+ verdict: "honoured",
1021
+ because: "read by loadSettings and resolved against .claude/output-styles/ by loadOutputStyle"
1022
+ },
1023
+ model: {
1024
+ verdict: "honoured",
1025
+ because: "this package has a model of its own for the run to select, so a key written here names something the code can act on"
1026
+ },
1027
+ cleanupPeriodDays: {
1028
+ verdict: "honoured",
1029
+ because: "a consumer here keeps session transcripts and collects them on a window, so the number has somewhere to land"
1030
+ },
1031
+ env: {
1032
+ verdict: "refused",
1033
+ because: "an environment variable is not inert: NODE_OPTIONS --require runs a file before the program does, and the directory usually arrives with the clone, so applying it would let a repository choose what runs inside every subprocess"
1034
+ },
1035
+ statusLine: {
1036
+ verdict: "refused",
1037
+ because: "it is a command spec rather than a value, so honouring it would execute a shell command written in a file the repository ships \u2014 the same trust decision env is refused for, with a nicer name"
1038
+ },
1039
+ autoMemoryEnabled: {
1040
+ verdict: "refused",
1041
+ because: "it toggles a per-project transcript memory this package does not have, and a flag that switches off something absent reads as a control in force while governing nothing"
1042
+ },
1043
+ workflows: {
1044
+ verdict: "refused",
1045
+ because: "a workflow file is code, and executing JavaScript found under a caller-supplied directory is a trust decision that belongs to the host rather than to this library"
1046
+ }
1047
+ };
914
1048
  var IGNORE_WARNING4 = /* @__PURE__ */ __name(() => void 0, "IGNORE_WARNING");
915
1049
  var FILE_LAYERS = [
916
1050
  {
@@ -930,9 +1064,9 @@ var FILE_LAYERS = [
930
1064
  }
931
1065
  ];
932
1066
  function readLayer(path, warn) {
933
- if (!existsSync4(path)) return {};
1067
+ if (!existsSync5(path)) return {};
934
1068
  try {
935
- const parsed = JSON.parse(readFileSync5(path, "utf8"));
1069
+ const parsed = JSON.parse(readFileSync6(path, "utf8"));
936
1070
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
937
1071
  warn(`${path} is not a JSON object \u2014 it is NOT being applied.`);
938
1072
  return {};
@@ -955,7 +1089,7 @@ function loadSettings(input) {
955
1089
  {
956
1090
  layer: entry.layer,
957
1091
  precedence: declared.precedence,
958
- values: readLayer(join4(root, ".claude", entry.file), warn)
1092
+ values: readLayer(join5(root, ".claude", entry.file), warn)
959
1093
  }
960
1094
  ];
961
1095
  });
@@ -975,8 +1109,8 @@ function loadSettings(input) {
975
1109
  __name(loadSettings, "loadSettings");
976
1110
 
977
1111
  // src/config/output-styles.ts
978
- var OUTPUT_STYLES_DIR = join5(".claude", "output-styles");
979
- var OutputStyleError = class extends TheokitAgentError3 {
1112
+ var OUTPUT_STYLES_DIR = join6(".claude", "output-styles");
1113
+ var OutputStyleError = class extends TheokitAgentError4 {
980
1114
  static {
981
1115
  __name(this, "OutputStyleError");
982
1116
  }
@@ -991,15 +1125,15 @@ var OutputStyleError = class extends TheokitAgentError3 {
991
1125
  function loadOutputStyle(input) {
992
1126
  if (input.name === void 0) return void 0;
993
1127
  const searched = [
994
- join5(input.cwd, OUTPUT_STYLES_DIR),
1128
+ join6(input.cwd, OUTPUT_STYLES_DIR),
995
1129
  ...input.homeDir === void 0 ? [] : [
996
- join5(input.homeDir, OUTPUT_STYLES_DIR)
1130
+ join6(input.homeDir, OUTPUT_STYLES_DIR)
997
1131
  ]
998
1132
  ];
999
1133
  for (const dir of searched) {
1000
- const path = join5(dir, `${input.name}.md`);
1001
- if (!existsSync5(path)) continue;
1002
- const raw = readFileSync6(path, "utf8");
1134
+ const path = join6(dir, `${input.name}.md`);
1135
+ if (!existsSync6(path)) continue;
1136
+ const raw = readFileSync7(path, "utf8");
1003
1137
  const parsed = splitFrontmatter(raw);
1004
1138
  const body = parsed === void 0 ? raw : parsed.body;
1005
1139
  const description = parsed === void 0 ? void 0 : frontmatterValue(parsed.frontmatter, "description");
@@ -1025,11 +1159,11 @@ function resolveOutputStyle(input) {
1025
1159
  __name(resolveOutputStyle, "resolveOutputStyle");
1026
1160
 
1027
1161
  // src/config/operator-roots.ts
1028
- import { readdirSync as readdirSync4, readFileSync as readFileSync7, statSync as statSync4 } from "fs";
1162
+ import { readdirSync as readdirSync4, readFileSync as readFileSync8, statSync as statSync4 } from "fs";
1029
1163
  import { homedir } from "os";
1030
- import { join as join6 } from "path";
1031
- import { TheokitAgentError as TheokitAgentError4 } from "@theokit/sdk/errors";
1032
- var OperatorRootUnreadableError = class extends TheokitAgentError4 {
1164
+ import { join as join7 } from "path";
1165
+ import { TheokitAgentError as TheokitAgentError5 } from "@theokit/sdk/errors";
1166
+ var OperatorRootUnreadableError = class extends TheokitAgentError5 {
1033
1167
  static {
1034
1168
  __name(this, "OperatorRootUnreadableError");
1035
1169
  }
@@ -1071,10 +1205,10 @@ function readDefinitions(root, origin, skipped) {
1071
1205
  const out = [];
1072
1206
  for (const entry of entries) {
1073
1207
  if (!entry.endsWith(".md")) continue;
1074
- const path = join6(root, entry);
1208
+ const path = join7(root, entry);
1075
1209
  let body;
1076
1210
  try {
1077
- body = readFileSync7(path, "utf8");
1211
+ body = readFileSync8(path, "utf8");
1078
1212
  } catch (cause) {
1079
1213
  throw new OperatorRootUnreadableError(path, cause);
1080
1214
  }
@@ -1114,7 +1248,7 @@ function resolveOperatorRoots(options) {
1114
1248
  "skills",
1115
1249
  "agents"
1116
1250
  ]) {
1117
- const root = join6(base, dir, kind);
1251
+ const root = join7(base, dir, kind);
1118
1252
  if (!exists(root)) continue;
1119
1253
  if (dialect !== void 0 && !grants.has(dialect)) {
1120
1254
  withheld.push({
@@ -1137,9 +1271,9 @@ function resolveOperatorRoots(options) {
1137
1271
  __name(resolveOperatorRoots, "resolveOperatorRoots");
1138
1272
 
1139
1273
  // src/config/agent-memory.ts
1140
- import { existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
1141
- import { join as join7, resolve as resolve4 } from "path";
1142
- import { TheokitAgentError as TheokitAgentError5 } from "@theokit/sdk/errors";
1274
+ import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
1275
+ import { join as join8, resolve as resolve4 } from "path";
1276
+ import { TheokitAgentError as TheokitAgentError6 } from "@theokit/sdk/errors";
1143
1277
  var MEMORY_LINE_CAP = 200;
1144
1278
  var MEMORY_BYTE_CAP = 25e3;
1145
1279
  var ROOTS2 = {
@@ -1156,7 +1290,7 @@ var ROOTS2 = {
1156
1290
  "agent-memory"
1157
1291
  ]
1158
1292
  };
1159
- var AgentMemoryError = class extends TheokitAgentError5 {
1293
+ var AgentMemoryError = class extends TheokitAgentError6 {
1160
1294
  static {
1161
1295
  __name(this, "AgentMemoryError");
1162
1296
  }
@@ -1203,15 +1337,15 @@ function resolveAgentMemory(input) {
1203
1337
  if (baseDir === void 0) {
1204
1338
  throw new AgentMemoryError(`memory scope "user" needs a home directory and none was given. Falling back to the project would write cross-project notes into one repository, which is the opposite of what the scope asks for.`);
1205
1339
  }
1206
- const memoryRoot = join7(baseDir, ".claude", dir);
1340
+ const memoryRoot = join8(baseDir, ".claude", dir);
1207
1341
  assertContained(memoryRoot, input.agent);
1208
- const root = join7(memoryRoot, input.agent);
1209
- const file = join7(root, "MEMORY.md");
1210
- if (!existsSync6(file)) return {
1342
+ const root = join8(memoryRoot, input.agent);
1343
+ const file = join8(root, "MEMORY.md");
1344
+ if (!existsSync7(file)) return {
1211
1345
  root,
1212
1346
  truncated: false
1213
1347
  };
1214
- const { text, truncated } = capped(readFileSync8(file, "utf8"));
1348
+ const { text, truncated } = capped(readFileSync9(file, "utf8"));
1215
1349
  return {
1216
1350
  root,
1217
1351
  memory: text,
@@ -1388,14 +1522,268 @@ function permissionRulesFromSettings(block, opts = {}) {
1388
1522
  }
1389
1523
  __name(permissionRulesFromSettings, "permissionRulesFromSettings");
1390
1524
 
1525
+ // src/config/settings-roots.ts
1526
+ import { existsSync as existsSync8, readFileSync as readFileSync10 } from "fs";
1527
+ import { join as join9 } from "path";
1528
+ var CLAUDE_SETTINGS_KEYS = /* @__PURE__ */ new Set([
1529
+ "advisorModel",
1530
+ "agent",
1531
+ "agentPushNotifEnabled",
1532
+ "allowAllClaudeAiMcps",
1533
+ "allowedChannelPlugins",
1534
+ "allowedHttpHookUrls",
1535
+ "allowedMcpServers",
1536
+ "allowManagedHooksOnly",
1537
+ "allowManagedMcpServersOnly",
1538
+ "allowManagedPermissionRulesOnly",
1539
+ "alwaysThinkingEnabled",
1540
+ "apiKeyHelper",
1541
+ "askUserQuestionTimeout",
1542
+ "attribution",
1543
+ "autoCompactEnabled",
1544
+ "autoCompactWindow",
1545
+ "autoConnectIde",
1546
+ "autoContinueAtUsageLimit",
1547
+ "autoInstallIdeExtension",
1548
+ "autoMemoryDirectory",
1549
+ "autoMemoryEnabled",
1550
+ "autoMode",
1551
+ "autoScrollEnabled",
1552
+ "autoUpdatesChannel",
1553
+ "availableModels",
1554
+ "awaySummaryEnabled",
1555
+ "awsAuthRefresh",
1556
+ "awsCredentialExport",
1557
+ "axScreenReader",
1558
+ "bashOutputMaxChars",
1559
+ "blockedMarketplaces",
1560
+ "browserExternalPageTools",
1561
+ "channelsEnabled",
1562
+ "claudeMd",
1563
+ "claudeMdExcludes",
1564
+ "cleanupPeriodDays",
1565
+ "companyAnnouncements",
1566
+ "crossSessionInbound",
1567
+ "defaultShell",
1568
+ "deniedMcpServers",
1569
+ "desktopSessionCleanupPeriodDays",
1570
+ "dialogExpiry",
1571
+ "diffTool",
1572
+ "disableAgentView",
1573
+ "disableAllHooks",
1574
+ "disableArtifact",
1575
+ "disableAutoMode",
1576
+ "disableBrowserExternalNavigation",
1577
+ "disableBundledSkills",
1578
+ "disableClaudeAiConnectors",
1579
+ "disableCommandPluginSources",
1580
+ "disableDeepLinkRegistration",
1581
+ "disableDesktopLocalSessions",
1582
+ "disabledMcpjsonServers",
1583
+ "disableMobileSimulatorTools",
1584
+ "disableRemoteControl",
1585
+ "disableSideloadFlags",
1586
+ "disableSkillShellExecution",
1587
+ "disableWorkflows",
1588
+ "editorMode",
1589
+ "effortLevel",
1590
+ "emojiCompletionEnabled",
1591
+ "enableAllProjectMcpServers",
1592
+ "enableArtifact",
1593
+ "enabledMcpjsonServers",
1594
+ "enabledPlugins",
1595
+ "enableWorkflows",
1596
+ "enforceAvailableModels",
1597
+ "env",
1598
+ "externalEditorContext",
1599
+ "extraKnownMarketplaces",
1600
+ "fallbackModel",
1601
+ "fastMode",
1602
+ "fastModePerSessionOptIn",
1603
+ "feedbackDrafts",
1604
+ "feedbackSurveyRate",
1605
+ "fileCheckpointingEnabled",
1606
+ "fileSuggestion",
1607
+ "footerLinksRegexes",
1608
+ "forceLoginGatewayUrl",
1609
+ "forceLoginMethod",
1610
+ "forceLoginOrgUUID",
1611
+ "forceRemoteSettingsRefresh",
1612
+ "gcpAuthRefresh",
1613
+ "httpHookAllowedEnvVars",
1614
+ "includeCoAuthoredBy",
1615
+ "includeGitInstructions",
1616
+ "inputNeededNotifEnabled",
1617
+ "isolatePeerMachines",
1618
+ "keybindingFlavor",
1619
+ "language",
1620
+ "managedSourcesBehavior",
1621
+ "minimumVersion",
1622
+ "modelOverrides",
1623
+ "modelPicker",
1624
+ "modelPricing",
1625
+ "modelSettings",
1626
+ "otelHeadersHelper",
1627
+ "parentSettingsBehavior",
1628
+ "permissionExplainerEnabled",
1629
+ "permissions",
1630
+ "plansDirectory",
1631
+ "pluginConfigs",
1632
+ "pluginSuggestionMarketplaces",
1633
+ "pluginTrustMessage",
1634
+ "policyHelper",
1635
+ "preferredNotifChannel",
1636
+ "prefersReducedMotion",
1637
+ "processWrapper",
1638
+ "promptCacheTtl",
1639
+ "promptSuggestionEnabled",
1640
+ "prUrlTemplate",
1641
+ "remoteControlAtStartup",
1642
+ "requiredMaximumVersion",
1643
+ "requiredMinimumVersion",
1644
+ "respectGitignore",
1645
+ "respondToBashCommands",
1646
+ "sandbox",
1647
+ "showClearContextOnPlanAccept",
1648
+ "showThinkingSummaries",
1649
+ "showTurnDuration",
1650
+ "skillListingBudgetFraction",
1651
+ "skillListingMaxDescChars",
1652
+ "skillOverrides",
1653
+ "skipAutoPermissionPrompt",
1654
+ "skipDangerousModePermissionPrompt",
1655
+ "skipWebFetchPreflight",
1656
+ "spellcheck",
1657
+ "spinnerTipsEnabled",
1658
+ "spinnerTipsOverride",
1659
+ "spinnerVerbs",
1660
+ "sshConfigs",
1661
+ "sshHostAllowlist",
1662
+ "statusLine",
1663
+ "strictKnownMarketplaces",
1664
+ "strictPluginOnlyCustomization",
1665
+ "subagentPromptCacheTtl",
1666
+ "ultracode",
1667
+ "workflowSizeGuideline"
1668
+ ]);
1669
+ function settingsCandidates(input) {
1670
+ const foreign = input.foreignRoot ?? ".claude";
1671
+ const roots = [
1672
+ {
1673
+ root: input.ownRoot,
1674
+ foreignRoot: false
1675
+ },
1676
+ ...foreign === false ? [] : [
1677
+ {
1678
+ root: foreign,
1679
+ foreignRoot: true
1680
+ }
1681
+ ]
1682
+ ];
1683
+ const scope = /* @__PURE__ */ __name((base, file) => roots.map((r) => ({
1684
+ path: join9(base, r.root, file),
1685
+ foreignRoot: r.foreignRoot
1686
+ })), "scope");
1687
+ return {
1688
+ user: scope(input.home, "settings.json"),
1689
+ project: scope(input.cwd, "settings.json"),
1690
+ projectLocal: scope(input.cwd, "settings.local.json")
1691
+ };
1692
+ }
1693
+ __name(settingsCandidates, "settingsCandidates");
1694
+ function isConvention(key) {
1695
+ return key === "$schema" || key.startsWith("_");
1696
+ }
1697
+ __name(isConvention, "isConvention");
1698
+ function isKnownForeign(key) {
1699
+ return CLAUDE_SETTINGS_KEYS.has(key) || Object.hasOwn(FOREIGN_KEY_DECISIONS, key) || isConvention(key);
1700
+ }
1701
+ __name(isKnownForeign, "isKnownForeign");
1702
+ function parseFile(path, warn) {
1703
+ if (!existsSync8(path)) return void 0;
1704
+ try {
1705
+ const parsed = JSON.parse(readFileSync10(path, "utf8"));
1706
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
1707
+ warn(`${path} is not a JSON object \u2014 it is NOT being applied.`);
1708
+ return void 0;
1709
+ }
1710
+ return parsed;
1711
+ } catch (error) {
1712
+ warn(`${path} could not be parsed (${error.message}) \u2014 it is NOT being applied.`);
1713
+ return void 0;
1714
+ }
1715
+ }
1716
+ __name(parseFile, "parseFile");
1717
+ function readSettingsFile(candidate, options) {
1718
+ const raw = parseFile(candidate.path, options.onWarn ?? (() => void 0));
1719
+ if (raw === void 0) return void 0;
1720
+ const own = new Set(options.ownKeys);
1721
+ const values = {};
1722
+ const ignored = [];
1723
+ const unrecognised = [];
1724
+ let permissionRules = [];
1725
+ let unsupportedPermissions = [];
1726
+ let hooks;
1727
+ let hasHooks = false;
1728
+ for (const [rawKey, value] of Object.entries(raw)) {
1729
+ const key = options.renames?.[rawKey] ?? rawKey;
1730
+ if (key === "permissions") {
1731
+ const translated = permissionRulesFromSettings(value, {
1732
+ ...options.specifierArg === void 0 ? {} : {
1733
+ specifierArg: options.specifierArg
1734
+ },
1735
+ ...options.baseDir === void 0 ? {} : {
1736
+ baseDir: options.baseDir
1737
+ }
1738
+ });
1739
+ permissionRules = translated.rules;
1740
+ unsupportedPermissions = translated.unsupported.map((u) => ({
1741
+ entry: u.entry,
1742
+ reason: u.reason
1743
+ }));
1744
+ } else if (key === "hooks") {
1745
+ hooks = value;
1746
+ hasHooks = true;
1747
+ } else if (own.has(key)) {
1748
+ values[key] = value;
1749
+ } else if (isKnownForeign(key)) {
1750
+ ignored.push(key);
1751
+ } else if (candidate.foreignRoot) {
1752
+ unrecognised.push(key);
1753
+ } else {
1754
+ values[key] = value;
1755
+ }
1756
+ }
1757
+ return {
1758
+ path: candidate.path,
1759
+ values,
1760
+ ignored,
1761
+ unrecognised,
1762
+ permissionRules,
1763
+ unsupportedPermissions,
1764
+ ...hasHooks ? {
1765
+ hooks
1766
+ } : {}
1767
+ };
1768
+ }
1769
+ __name(readSettingsFile, "readSettingsFile");
1770
+ function firstSettingsFile(candidates, options) {
1771
+ for (const candidate of candidates) {
1772
+ const read = readSettingsFile(candidate, options);
1773
+ if (read !== void 0) return read;
1774
+ }
1775
+ return void 0;
1776
+ }
1777
+ __name(firstSettingsFile, "firstSettingsFile");
1778
+
1391
1779
  // src/config/context-pressure.ts
1392
1780
  import { resolveEffectiveContextWindow } from "@theokit/sdk/compaction";
1393
- import { TheokitAgentError as TheokitAgentError6 } from "@theokit/sdk/errors";
1781
+ import { TheokitAgentError as TheokitAgentError7 } from "@theokit/sdk/errors";
1394
1782
  var DEFAULT_CONTEXT_PRESSURE_THRESHOLDS = {
1395
1783
  warn: 0.75,
1396
1784
  critical: 0.9
1397
1785
  };
1398
- var ContextPressureThresholdError = class extends TheokitAgentError6 {
1786
+ var ContextPressureThresholdError = class extends TheokitAgentError7 {
1399
1787
  static {
1400
1788
  __name(this, "ContextPressureThresholdError");
1401
1789
  }
@@ -1421,9 +1809,13 @@ function contextPressure(usedTokens, effectiveWindow, thresholds = DEFAULT_CONTE
1421
1809
  __name(contextPressure, "contextPressure");
1422
1810
  export {
1423
1811
  AgentMemoryError,
1812
+ BootstrapNotRunError,
1813
+ BootstrapStepError,
1814
+ CLAUDE_SETTINGS_KEYS,
1424
1815
  ContextPressureThresholdError,
1425
1816
  DEFAULT_CONTEXT_PRESSURE_THRESHOLDS,
1426
1817
  FILE_INLINE_CAP,
1818
+ FOREIGN_KEY_DECISIONS,
1427
1819
  LAYERS_ARE_POSITIONED,
1428
1820
  LayerOutOfOrderError,
1429
1821
  LayeredConfig,
@@ -1435,13 +1827,16 @@ export {
1435
1827
  TrustStore,
1436
1828
  TrustStorePermissionsError,
1437
1829
  applySubagentMemory,
1830
+ assertBootstrapped,
1438
1831
  blockAppliesTo,
1439
1832
  composeInstructions,
1440
1833
  contextPressure,
1441
1834
  currentOperatorPolicy,
1835
+ defineAppBootstrap,
1442
1836
  resolveEffectiveContextWindow as effectiveContextWindow,
1443
1837
  expandCommandTemplate,
1444
1838
  expandInstructionImports,
1839
+ firstSettingsFile,
1445
1840
  frontmatterValue,
1446
1841
  layerPrecedence,
1447
1842
  loadCustomCommands,
@@ -1450,9 +1845,12 @@ export {
1450
1845
  loadSettings,
1451
1846
  mcpServerAdmitted,
1452
1847
  permissionRulesFromSettings,
1848
+ projectEnvStep,
1849
+ readSettingsFile,
1453
1850
  resolveAgentMemory,
1454
1851
  resolveOperatorRoots,
1455
1852
  resolveOutputStyle,
1853
+ settingsCandidates,
1456
1854
  settingsLayerChain,
1457
1855
  splitFrontmatter,
1458
1856
  templateHints