@theokit/sdk 3.1.0 → 3.2.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 (38) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/a2a/index.cjs +166 -44
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +166 -44
  5. package/dist/a2a/index.js.map +1 -1
  6. package/dist/{cron-C2jWAvlQ.d.cts → cron-4u1UdmgC.d.cts} +1 -1
  7. package/dist/{cron-BLRe166v.d.ts → cron-DuhVPer6.d.ts} +1 -1
  8. package/dist/cron.cjs +152 -35
  9. package/dist/cron.cjs.map +1 -1
  10. package/dist/cron.d.cts +2 -2
  11. package/dist/cron.d.ts +2 -2
  12. package/dist/cron.js +152 -35
  13. package/dist/cron.js.map +1 -1
  14. package/dist/{errors-D_Bfo30u.d.ts → errors-_fPS0X80.d.ts} +1 -1
  15. package/dist/{errors-DZpCGlYv.d.cts → errors-jxK4yfp5.d.cts} +1 -1
  16. package/dist/errors.d.cts +2 -2
  17. package/dist/eval.cjs +152 -35
  18. package/dist/eval.cjs.map +1 -1
  19. package/dist/eval.js +152 -35
  20. package/dist/eval.js.map +1 -1
  21. package/dist/index.cjs +152 -35
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +6 -6
  24. package/dist/index.d.ts +6 -6
  25. package/dist/index.js +152 -35
  26. package/dist/index.js.map +1 -1
  27. package/dist/internal/runtime/context/context-discovery.d.ts +1 -1
  28. package/dist/internal/runtime/context/context-glob.d.ts +1 -0
  29. package/dist/internal/runtime/context/context-manager.d.ts +18 -1
  30. package/dist/internal/runtime/context/context-mdc-parser.d.ts +7 -6
  31. package/dist/internal/runtime/context/context-rules-frontmatter.d.ts +30 -0
  32. package/dist/internal/runtime/context/context-yaml-lite.d.ts +26 -0
  33. package/dist/project.cjs.map +1 -1
  34. package/dist/project.js.map +1 -1
  35. package/dist/{run-CLXKMRgq.d.cts → run-CrHz9BAP.d.cts} +9 -0
  36. package/dist/{run-CLXKMRgq.d.ts → run-CrHz9BAP.d.ts} +9 -0
  37. package/dist/types/run.d.ts +9 -0
  38. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -976,10 +976,10 @@ function buildToolPrompt(prompt) {
976
976
  Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
977
977
  }
978
978
  function setupStructuredOutput(schema, maxRetries) {
979
- const z10 = requireZod();
979
+ const z11 = requireZod();
980
980
  const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
981
981
  return {
982
- z: z10,
982
+ z: z11,
983
983
  jsonSchema,
984
984
  maxRetries: maxRetries ?? 1,
985
985
  initialUsage: { inputTokens: 0, outputTokens: 0 }
@@ -6055,7 +6055,7 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
6055
6055
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
6056
6056
  };
6057
6057
  }
6058
- async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6058
+ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6059
6059
  const resolved = await resolveSendSkills(inputs, userText, memoryFacts);
6060
6060
  const baseCtx = await buildSystemPromptContext(inputs, userText, memoryFacts, resolved.manager);
6061
6061
  const assemblyCtx = {
@@ -6068,19 +6068,21 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
6068
6068
  assemblyCtx.activeMemorySummary = activeMemorySummary;
6069
6069
  }
6070
6070
  if (inputs.context !== void 0) {
6071
+ await inputs.context.applyScope(contextPaths);
6071
6072
  const internal = inputs.context.internalAssemblySnapshot();
6072
6073
  assemblyCtx.contextSnapshot = { sources: internal.sources };
6073
6074
  if (internal.maxTokens !== void 0) assemblyCtx.contextMaxTokens = internal.maxTokens;
6074
6075
  }
6075
6076
  return assemblyCtx;
6076
6077
  }
6077
- async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6078
+ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6078
6079
  const ctx = await buildAssemblyContext(
6079
6080
  inputs,
6080
6081
  userText,
6081
6082
  baseSystemPrompt,
6082
6083
  memoryFacts,
6083
- activeMemorySummary
6084
+ activeMemorySummary,
6085
+ contextPaths
6084
6086
  );
6085
6087
  return inputs.systemPromptPipeline.assemble(ctx);
6086
6088
  }
@@ -6787,6 +6789,14 @@ var init_context_discovery = __esm({
6787
6789
  followImports: false,
6788
6790
  priority: 40
6789
6791
  },
6792
+ {
6793
+ id: "theokit-rules",
6794
+ pattern: ".theokit/rules/*.md",
6795
+ scope: "globbed",
6796
+ parser: "rules-frontmatter",
6797
+ followImports: false,
6798
+ priority: 45
6799
+ },
6790
6800
  {
6791
6801
  id: "theokit-context",
6792
6802
  pattern: ".theokit/context/*.md",
@@ -6870,32 +6880,27 @@ var init_context_import_resolver = __esm({
6870
6880
  MAX_HOPS = 5;
6871
6881
  }
6872
6882
  });
6873
- function parseMdc(content) {
6874
- const m = FRONTMATTER_RE.exec(content);
6875
- if (m === null) {
6876
- return { frontmatter: { alwaysApply: true }, body: content };
6877
- }
6878
- const yamlBody = m[1] ?? "";
6879
- const body = m[2] ?? "";
6880
- try {
6881
- const parsed = parseSimpleYaml2(yamlBody);
6882
- const validated = McdFrontmatterSchema.safeParse(parsed);
6883
- if (!validated.success) return void 0;
6884
- return { frontmatter: validated.data, body };
6885
- } catch {
6886
- return void 0;
6887
- }
6883
+
6884
+ // src/internal/runtime/context/context-glob.ts
6885
+ function globToRegex(glob) {
6886
+ const compiled = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "::GLOBSTAR_SLASH::").replace(/\*\*/g, "::GLOBSTAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::GLOBSTAR_SLASH::/g, "(?:.*/)?").replace(/::GLOBSTAR::/g, ".*");
6887
+ return new RegExp(`^${compiled}$`);
6888
6888
  }
6889
- function shouldActivate(fm, touchedFiles) {
6890
- if (fm.alwaysApply === true) return true;
6891
- if (fm.globs === void 0 || fm.globs.length === 0) return false;
6892
- if (touchedFiles.length === 0) return false;
6893
- const globRes = fm.globs.map(globToRegex);
6894
- return touchedFiles.some((file) => globRes.some((re) => re.test(file)));
6889
+ function anyGlobMatches(patterns, paths) {
6890
+ if (patterns.length === 0 || paths.length === 0) return false;
6891
+ const res = patterns.map(globToRegex);
6892
+ return paths.some((p) => res.some((re) => re.test(p)));
6895
6893
  }
6896
- function globToRegex(glob) {
6897
- const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "::DOUBLESTAR::").replace(/\*/g, "[^/]*").replace(/::DOUBLESTAR::/g, ".*").replace(/\?/g, ".");
6898
- return new RegExp(`^${escaped}$`);
6894
+ var init_context_glob = __esm({
6895
+ "src/internal/runtime/context/context-glob.ts"() {
6896
+ }
6897
+ });
6898
+
6899
+ // src/internal/runtime/context/context-yaml-lite.ts
6900
+ function splitFrontmatter3(content) {
6901
+ const m = FRONTMATTER_RE.exec(content);
6902
+ if (m === null) return { yaml: void 0, body: content };
6903
+ return { yaml: m[1] ?? "", body: m[2] ?? "" };
6899
6904
  }
6900
6905
  function parseSimpleYaml2(yaml) {
6901
6906
  const out = {};
@@ -6942,15 +6947,76 @@ function parseScalar(s) {
6942
6947
  if (/^-?\d+$/.test(s)) return parseInt(s, 10);
6943
6948
  return s.replace(/^["']|["']$/g, "");
6944
6949
  }
6945
- var McdFrontmatterSchema, FRONTMATTER_RE;
6950
+ var FRONTMATTER_RE;
6951
+ var init_context_yaml_lite = __esm({
6952
+ "src/internal/runtime/context/context-yaml-lite.ts"() {
6953
+ FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6954
+ }
6955
+ });
6956
+ function parseMdc(content) {
6957
+ const { yaml, body } = splitFrontmatter3(content);
6958
+ if (yaml === void 0) {
6959
+ return { frontmatter: { alwaysApply: true }, body: content };
6960
+ }
6961
+ try {
6962
+ const parsed = parseSimpleYaml2(yaml);
6963
+ const validated = McdFrontmatterSchema.safeParse(parsed);
6964
+ if (!validated.success) return void 0;
6965
+ return { frontmatter: validated.data, body };
6966
+ } catch {
6967
+ return void 0;
6968
+ }
6969
+ }
6970
+ function shouldActivate(fm, touchedFiles) {
6971
+ if (fm.alwaysApply === true) return true;
6972
+ if (fm.globs === void 0 || fm.globs.length === 0) return false;
6973
+ return anyGlobMatches(fm.globs, touchedFiles);
6974
+ }
6975
+ var McdFrontmatterSchema;
6946
6976
  var init_context_mdc_parser = __esm({
6947
6977
  "src/internal/runtime/context/context-mdc-parser.ts"() {
6978
+ init_context_glob();
6979
+ init_context_yaml_lite();
6948
6980
  McdFrontmatterSchema = zod.z.object({
6949
6981
  description: zod.z.string().optional(),
6950
6982
  globs: zod.z.array(zod.z.string()).optional(),
6951
6983
  alwaysApply: zod.z.boolean().optional()
6952
6984
  });
6953
- FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6985
+ }
6986
+ });
6987
+ function parseRules(content) {
6988
+ const { yaml, body } = splitFrontmatter3(content);
6989
+ if (yaml === void 0) {
6990
+ return { frontmatter: { alwaysApply: true }, body: content };
6991
+ }
6992
+ try {
6993
+ const parsed = parseSimpleYaml2(yaml);
6994
+ const validated = RulesFrontmatterSchema.safeParse(parsed);
6995
+ if (!validated.success) return void 0;
6996
+ return { frontmatter: validated.data, body };
6997
+ } catch {
6998
+ return void 0;
6999
+ }
7000
+ }
7001
+ function shouldActivateRule(fm, inScopePaths) {
7002
+ if (fm.enabled === false) return false;
7003
+ if (fm.alwaysApply === true) return true;
7004
+ const patterns = [...fm.paths ?? [], ...fm.globs ?? []];
7005
+ if (patterns.length === 0) return false;
7006
+ return anyGlobMatches(patterns, inScopePaths);
7007
+ }
7008
+ var RulesFrontmatterSchema;
7009
+ var init_context_rules_frontmatter = __esm({
7010
+ "src/internal/runtime/context/context-rules-frontmatter.ts"() {
7011
+ init_context_glob();
7012
+ init_context_yaml_lite();
7013
+ RulesFrontmatterSchema = zod.z.object({
7014
+ description: zod.z.string().optional(),
7015
+ paths: zod.z.array(zod.z.string()).optional(),
7016
+ globs: zod.z.array(zod.z.string()).optional(),
7017
+ alwaysApply: zod.z.boolean().optional(),
7018
+ enabled: zod.z.boolean().optional()
7019
+ });
6954
7020
  }
6955
7021
  });
6956
7022
  async function runDiscovery(opts) {
@@ -6986,6 +7052,9 @@ async function loadOneSource(spec, path$1, opts, gitRoot) {
6986
7052
  if (spec.parser === "mdc") {
6987
7053
  return loadMdcSource(spec, path$1, id, opts);
6988
7054
  }
7055
+ if (spec.parser === "rules-frontmatter") {
7056
+ return loadRulesSource(spec, path$1, id, opts);
7057
+ }
6989
7058
  if (spec.parser === "frontmatter-zod") {
6990
7059
  return void 0;
6991
7060
  }
@@ -7009,6 +7078,24 @@ async function loadMdcSource(spec, path, id, opts) {
7009
7078
  truncated: false
7010
7079
  };
7011
7080
  }
7081
+ async function loadRulesSource(spec, path, id, opts) {
7082
+ let raw;
7083
+ try {
7084
+ raw = await promises.readFile(path, "utf8");
7085
+ } catch {
7086
+ return void 0;
7087
+ }
7088
+ const parsed = parseRules(raw);
7089
+ if (parsed === void 0) return void 0;
7090
+ if (!shouldActivateRule(parsed.frontmatter, opts.touchedFiles ?? [])) return void 0;
7091
+ return {
7092
+ id,
7093
+ source: path,
7094
+ content: parsed.body,
7095
+ priority: spec.priority,
7096
+ truncated: false
7097
+ };
7098
+ }
7012
7099
  async function loadPlainMarkdownSource(spec, path, id, opts) {
7013
7100
  const loaded = await loadPlainMarkdown(path, { maxBytesPerFile: opts.maxBytesPerFile });
7014
7101
  if (loaded === void 0) return void 0;
@@ -7034,6 +7121,7 @@ var init_context_discovery_runner = __esm({
7034
7121
  init_context_import_resolver();
7035
7122
  init_context_loaders();
7036
7123
  init_context_mdc_parser();
7124
+ init_context_rules_frontmatter();
7037
7125
  }
7038
7126
  });
7039
7127
  var ContextSourceFrontmatterSchema;
@@ -7169,6 +7257,10 @@ function matchesGlob(pattern, path) {
7169
7257
  function tokenizeContent(content) {
7170
7258
  return content.split(/\s+/).filter((token) => token.length > 0);
7171
7259
  }
7260
+ function sameScope(a, b) {
7261
+ if (a.length !== b.length) return false;
7262
+ return a.every((v, i) => v === b[i]);
7263
+ }
7172
7264
  var FileContextManager;
7173
7265
  var init_context_manager = __esm({
7174
7266
  "src/internal/runtime/context/context-manager.ts"() {
@@ -7189,6 +7281,13 @@ var init_context_manager = __esm({
7189
7281
  settings;
7190
7282
  settingSourcesIncludeProject;
7191
7283
  state;
7284
+ /**
7285
+ * The in-scope file set used by the most recent `refresh`. Tracked so
7286
+ * `applyScope` only touches state when the scope actually changes — a
7287
+ * caller that never scopes (the common case) keeps the create-time
7288
+ * snapshot untouched, at zero per-send cost.
7289
+ */
7290
+ lastScope = [];
7192
7291
  async initialize() {
7193
7292
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
7194
7293
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -7196,14 +7295,31 @@ var init_context_manager = __esm({
7196
7295
  }
7197
7296
  await this.refresh();
7198
7297
  }
7199
- async refresh() {
7298
+ /**
7299
+ * Re-run discovery for a specific per-send in-scope file set (T3). Path-scoped
7300
+ * rules (`.theokit/rules/*.md`, `.cursor/rules/*.mdc` globs) activate iff a
7301
+ * pattern matches one of `contextPaths`. Idempotent: unchanged scope is a
7302
+ * no-op, and `undefined` scope while never previously scoped never touches
7303
+ * state (preserves the create-time snapshot for non-users).
7304
+ */
7305
+ async applyScope(contextPaths) {
7306
+ const scope = contextPaths ?? [];
7307
+ if (scope.length === 0 && this.lastScope.length === 0) return;
7308
+ if (sameScope(scope, this.lastScope)) return;
7309
+ await this.refresh({ touchedFiles: scope });
7310
+ }
7311
+ async refresh(opts) {
7312
+ const touchedFiles = opts?.touchedFiles ?? [];
7313
+ this.lastScope = [...touchedFiles];
7200
7314
  const config = await loadContextConfig(this.cwd);
7201
7315
  const legacy = await loadSources(config, this.cwd);
7202
7316
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
7203
7317
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
7204
7318
  const discovered = await runDiscovery({
7205
7319
  cwd: this.cwd,
7206
- maxBytesPerFile});
7320
+ maxBytesPerFile,
7321
+ touchedFiles
7322
+ });
7207
7323
  const legacyAsAggregator = legacy.map((src) => ({
7208
7324
  id: src.name,
7209
7325
  source: src.path,
@@ -17156,7 +17272,8 @@ async function executeSendLocked(inputs, message, options) {
17156
17272
  userText,
17157
17273
  baseSystemPrompt,
17158
17274
  memoryFacts,
17159
- activeMemorySummary
17275
+ activeMemorySummary,
17276
+ options.contextPaths
17160
17277
  );
17161
17278
  const projectedSystemPrompt = await projectCurrentObjective(
17162
17279
  inputs.storageHandle,
@@ -18229,7 +18346,7 @@ var init_local_agent = __esm({
18229
18346
  runPreHook: (ut) => this.runPreHook(ut),
18230
18347
  // biome-ignore format: G8 budget — callbacks wire to private methods.
18231
18348
  resolveSystemPromptForSend: (ut, o, mf) => this.resolveSystemPrompt(ut, o, mf),
18232
- assembleSystemPromptForSend: (ut, bp, mf, ams) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams),
18349
+ assembleSystemPromptForSend: (ut, bp, mf, ams, cp) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams, cp),
18233
18350
  dispatchRun: (msg, o, sp, mf, pm, mt, mp) => this.dispatchRun(msg, o, sp, mf, pm, mt, mp)
18234
18351
  },
18235
18352
  message,