@theokit/sdk 3.1.1 → 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 +10 -0
  2. package/dist/a2a/index.cjs +152 -35
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +152 -35
  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 +3 -3
package/dist/a2a/index.js CHANGED
@@ -959,10 +959,10 @@ function buildToolPrompt(prompt) {
959
959
  Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
960
960
  }
961
961
  function setupStructuredOutput(schema, maxRetries) {
962
- const z7 = requireZod();
962
+ const z8 = requireZod();
963
963
  const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
964
964
  return {
965
- z: z7,
965
+ z: z8,
966
966
  jsonSchema,
967
967
  maxRetries: maxRetries ?? 1,
968
968
  initialUsage: { inputTokens: 0, outputTokens: 0 }
@@ -6038,7 +6038,7 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
6038
6038
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
6039
6039
  };
6040
6040
  }
6041
- async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6041
+ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6042
6042
  const resolved = await resolveSendSkills(inputs, userText, memoryFacts);
6043
6043
  const baseCtx = await buildSystemPromptContext(inputs, userText, memoryFacts, resolved.manager);
6044
6044
  const assemblyCtx = {
@@ -6051,19 +6051,21 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
6051
6051
  assemblyCtx.activeMemorySummary = activeMemorySummary;
6052
6052
  }
6053
6053
  if (inputs.context !== void 0) {
6054
+ await inputs.context.applyScope(contextPaths);
6054
6055
  const internal = inputs.context.internalAssemblySnapshot();
6055
6056
  assemblyCtx.contextSnapshot = { sources: internal.sources };
6056
6057
  if (internal.maxTokens !== void 0) assemblyCtx.contextMaxTokens = internal.maxTokens;
6057
6058
  }
6058
6059
  return assemblyCtx;
6059
6060
  }
6060
- async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6061
+ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6061
6062
  const ctx = await buildAssemblyContext(
6062
6063
  inputs,
6063
6064
  userText,
6064
6065
  baseSystemPrompt,
6065
6066
  memoryFacts,
6066
- activeMemorySummary
6067
+ activeMemorySummary,
6068
+ contextPaths
6067
6069
  );
6068
6070
  return inputs.systemPromptPipeline.assemble(ctx);
6069
6071
  }
@@ -6770,6 +6772,14 @@ var init_context_discovery = __esm({
6770
6772
  followImports: false,
6771
6773
  priority: 40
6772
6774
  },
6775
+ {
6776
+ id: "theokit-rules",
6777
+ pattern: ".theokit/rules/*.md",
6778
+ scope: "globbed",
6779
+ parser: "rules-frontmatter",
6780
+ followImports: false,
6781
+ priority: 45
6782
+ },
6773
6783
  {
6774
6784
  id: "theokit-context",
6775
6785
  pattern: ".theokit/context/*.md",
@@ -6853,32 +6863,27 @@ var init_context_import_resolver = __esm({
6853
6863
  MAX_HOPS = 5;
6854
6864
  }
6855
6865
  });
6856
- function parseMdc(content) {
6857
- const m = FRONTMATTER_RE.exec(content);
6858
- if (m === null) {
6859
- return { frontmatter: { alwaysApply: true }, body: content };
6860
- }
6861
- const yamlBody = m[1] ?? "";
6862
- const body = m[2] ?? "";
6863
- try {
6864
- const parsed = parseSimpleYaml2(yamlBody);
6865
- const validated = McdFrontmatterSchema.safeParse(parsed);
6866
- if (!validated.success) return void 0;
6867
- return { frontmatter: validated.data, body };
6868
- } catch {
6869
- return void 0;
6870
- }
6866
+
6867
+ // src/internal/runtime/context/context-glob.ts
6868
+ function globToRegex(glob) {
6869
+ const compiled = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "::GLOBSTAR_SLASH::").replace(/\*\*/g, "::GLOBSTAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::GLOBSTAR_SLASH::/g, "(?:.*/)?").replace(/::GLOBSTAR::/g, ".*");
6870
+ return new RegExp(`^${compiled}$`);
6871
6871
  }
6872
- function shouldActivate(fm, touchedFiles) {
6873
- if (fm.alwaysApply === true) return true;
6874
- if (fm.globs === void 0 || fm.globs.length === 0) return false;
6875
- if (touchedFiles.length === 0) return false;
6876
- const globRes = fm.globs.map(globToRegex);
6877
- return touchedFiles.some((file) => globRes.some((re) => re.test(file)));
6872
+ function anyGlobMatches(patterns, paths) {
6873
+ if (patterns.length === 0 || paths.length === 0) return false;
6874
+ const res = patterns.map(globToRegex);
6875
+ return paths.some((p) => res.some((re) => re.test(p)));
6878
6876
  }
6879
- function globToRegex(glob) {
6880
- const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "::DOUBLESTAR::").replace(/\*/g, "[^/]*").replace(/::DOUBLESTAR::/g, ".*").replace(/\?/g, ".");
6881
- return new RegExp(`^${escaped}$`);
6877
+ var init_context_glob = __esm({
6878
+ "src/internal/runtime/context/context-glob.ts"() {
6879
+ }
6880
+ });
6881
+
6882
+ // src/internal/runtime/context/context-yaml-lite.ts
6883
+ function splitFrontmatter3(content) {
6884
+ const m = FRONTMATTER_RE.exec(content);
6885
+ if (m === null) return { yaml: void 0, body: content };
6886
+ return { yaml: m[1] ?? "", body: m[2] ?? "" };
6882
6887
  }
6883
6888
  function parseSimpleYaml2(yaml) {
6884
6889
  const out = {};
@@ -6925,15 +6930,76 @@ function parseScalar(s) {
6925
6930
  if (/^-?\d+$/.test(s)) return parseInt(s, 10);
6926
6931
  return s.replace(/^["']|["']$/g, "");
6927
6932
  }
6928
- var McdFrontmatterSchema, FRONTMATTER_RE;
6933
+ var FRONTMATTER_RE;
6934
+ var init_context_yaml_lite = __esm({
6935
+ "src/internal/runtime/context/context-yaml-lite.ts"() {
6936
+ FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6937
+ }
6938
+ });
6939
+ function parseMdc(content) {
6940
+ const { yaml, body } = splitFrontmatter3(content);
6941
+ if (yaml === void 0) {
6942
+ return { frontmatter: { alwaysApply: true }, body: content };
6943
+ }
6944
+ try {
6945
+ const parsed = parseSimpleYaml2(yaml);
6946
+ const validated = McdFrontmatterSchema.safeParse(parsed);
6947
+ if (!validated.success) return void 0;
6948
+ return { frontmatter: validated.data, body };
6949
+ } catch {
6950
+ return void 0;
6951
+ }
6952
+ }
6953
+ function shouldActivate(fm, touchedFiles) {
6954
+ if (fm.alwaysApply === true) return true;
6955
+ if (fm.globs === void 0 || fm.globs.length === 0) return false;
6956
+ return anyGlobMatches(fm.globs, touchedFiles);
6957
+ }
6958
+ var McdFrontmatterSchema;
6929
6959
  var init_context_mdc_parser = __esm({
6930
6960
  "src/internal/runtime/context/context-mdc-parser.ts"() {
6961
+ init_context_glob();
6962
+ init_context_yaml_lite();
6931
6963
  McdFrontmatterSchema = z.object({
6932
6964
  description: z.string().optional(),
6933
6965
  globs: z.array(z.string()).optional(),
6934
6966
  alwaysApply: z.boolean().optional()
6935
6967
  });
6936
- FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6968
+ }
6969
+ });
6970
+ function parseRules(content) {
6971
+ const { yaml, body } = splitFrontmatter3(content);
6972
+ if (yaml === void 0) {
6973
+ return { frontmatter: { alwaysApply: true }, body: content };
6974
+ }
6975
+ try {
6976
+ const parsed = parseSimpleYaml2(yaml);
6977
+ const validated = RulesFrontmatterSchema.safeParse(parsed);
6978
+ if (!validated.success) return void 0;
6979
+ return { frontmatter: validated.data, body };
6980
+ } catch {
6981
+ return void 0;
6982
+ }
6983
+ }
6984
+ function shouldActivateRule(fm, inScopePaths) {
6985
+ if (fm.enabled === false) return false;
6986
+ if (fm.alwaysApply === true) return true;
6987
+ const patterns = [...fm.paths ?? [], ...fm.globs ?? []];
6988
+ if (patterns.length === 0) return false;
6989
+ return anyGlobMatches(patterns, inScopePaths);
6990
+ }
6991
+ var RulesFrontmatterSchema;
6992
+ var init_context_rules_frontmatter = __esm({
6993
+ "src/internal/runtime/context/context-rules-frontmatter.ts"() {
6994
+ init_context_glob();
6995
+ init_context_yaml_lite();
6996
+ RulesFrontmatterSchema = z.object({
6997
+ description: z.string().optional(),
6998
+ paths: z.array(z.string()).optional(),
6999
+ globs: z.array(z.string()).optional(),
7000
+ alwaysApply: z.boolean().optional(),
7001
+ enabled: z.boolean().optional()
7002
+ });
6937
7003
  }
6938
7004
  });
6939
7005
  async function runDiscovery(opts) {
@@ -6969,6 +7035,9 @@ async function loadOneSource(spec, path, opts, gitRoot) {
6969
7035
  if (spec.parser === "mdc") {
6970
7036
  return loadMdcSource(spec, path, id, opts);
6971
7037
  }
7038
+ if (spec.parser === "rules-frontmatter") {
7039
+ return loadRulesSource(spec, path, id, opts);
7040
+ }
6972
7041
  if (spec.parser === "frontmatter-zod") {
6973
7042
  return void 0;
6974
7043
  }
@@ -6992,6 +7061,24 @@ async function loadMdcSource(spec, path, id, opts) {
6992
7061
  truncated: false
6993
7062
  };
6994
7063
  }
7064
+ async function loadRulesSource(spec, path, id, opts) {
7065
+ let raw;
7066
+ try {
7067
+ raw = await readFile(path, "utf8");
7068
+ } catch {
7069
+ return void 0;
7070
+ }
7071
+ const parsed = parseRules(raw);
7072
+ if (parsed === void 0) return void 0;
7073
+ if (!shouldActivateRule(parsed.frontmatter, opts.touchedFiles ?? [])) return void 0;
7074
+ return {
7075
+ id,
7076
+ source: path,
7077
+ content: parsed.body,
7078
+ priority: spec.priority,
7079
+ truncated: false
7080
+ };
7081
+ }
6995
7082
  async function loadPlainMarkdownSource(spec, path, id, opts) {
6996
7083
  const loaded = await loadPlainMarkdown(path, { maxBytesPerFile: opts.maxBytesPerFile });
6997
7084
  if (loaded === void 0) return void 0;
@@ -7017,6 +7104,7 @@ var init_context_discovery_runner = __esm({
7017
7104
  init_context_import_resolver();
7018
7105
  init_context_loaders();
7019
7106
  init_context_mdc_parser();
7107
+ init_context_rules_frontmatter();
7020
7108
  }
7021
7109
  });
7022
7110
  var ContextSourceFrontmatterSchema;
@@ -7152,6 +7240,10 @@ function matchesGlob(pattern, path) {
7152
7240
  function tokenizeContent(content) {
7153
7241
  return content.split(/\s+/).filter((token) => token.length > 0);
7154
7242
  }
7243
+ function sameScope(a, b) {
7244
+ if (a.length !== b.length) return false;
7245
+ return a.every((v, i) => v === b[i]);
7246
+ }
7155
7247
  var FileContextManager;
7156
7248
  var init_context_manager = __esm({
7157
7249
  "src/internal/runtime/context/context-manager.ts"() {
@@ -7172,6 +7264,13 @@ var init_context_manager = __esm({
7172
7264
  settings;
7173
7265
  settingSourcesIncludeProject;
7174
7266
  state;
7267
+ /**
7268
+ * The in-scope file set used by the most recent `refresh`. Tracked so
7269
+ * `applyScope` only touches state when the scope actually changes — a
7270
+ * caller that never scopes (the common case) keeps the create-time
7271
+ * snapshot untouched, at zero per-send cost.
7272
+ */
7273
+ lastScope = [];
7175
7274
  async initialize() {
7176
7275
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
7177
7276
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -7179,14 +7278,31 @@ var init_context_manager = __esm({
7179
7278
  }
7180
7279
  await this.refresh();
7181
7280
  }
7182
- async refresh() {
7281
+ /**
7282
+ * Re-run discovery for a specific per-send in-scope file set (T3). Path-scoped
7283
+ * rules (`.theokit/rules/*.md`, `.cursor/rules/*.mdc` globs) activate iff a
7284
+ * pattern matches one of `contextPaths`. Idempotent: unchanged scope is a
7285
+ * no-op, and `undefined` scope while never previously scoped never touches
7286
+ * state (preserves the create-time snapshot for non-users).
7287
+ */
7288
+ async applyScope(contextPaths) {
7289
+ const scope = contextPaths ?? [];
7290
+ if (scope.length === 0 && this.lastScope.length === 0) return;
7291
+ if (sameScope(scope, this.lastScope)) return;
7292
+ await this.refresh({ touchedFiles: scope });
7293
+ }
7294
+ async refresh(opts) {
7295
+ const touchedFiles = opts?.touchedFiles ?? [];
7296
+ this.lastScope = [...touchedFiles];
7183
7297
  const config = await loadContextConfig(this.cwd);
7184
7298
  const legacy = await loadSources(config, this.cwd);
7185
7299
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
7186
7300
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
7187
7301
  const discovered = await runDiscovery({
7188
7302
  cwd: this.cwd,
7189
- maxBytesPerFile});
7303
+ maxBytesPerFile,
7304
+ touchedFiles
7305
+ });
7190
7306
  const legacyAsAggregator = legacy.map((src) => ({
7191
7307
  id: src.name,
7192
7308
  source: src.path,
@@ -16963,7 +17079,8 @@ async function executeSendLocked(inputs, message, options) {
16963
17079
  userText,
16964
17080
  baseSystemPrompt,
16965
17081
  memoryFacts,
16966
- activeMemorySummary
17082
+ activeMemorySummary,
17083
+ options.contextPaths
16967
17084
  );
16968
17085
  const projectedSystemPrompt = await projectCurrentObjective(
16969
17086
  inputs.storageHandle,
@@ -17851,7 +17968,7 @@ var init_local_agent = __esm({
17851
17968
  runPreHook: (ut) => this.runPreHook(ut),
17852
17969
  // biome-ignore format: G8 budget — callbacks wire to private methods.
17853
17970
  resolveSystemPromptForSend: (ut, o, mf) => this.resolveSystemPrompt(ut, o, mf),
17854
- assembleSystemPromptForSend: (ut, bp, mf, ams) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams),
17971
+ assembleSystemPromptForSend: (ut, bp, mf, ams, cp) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams, cp),
17855
17972
  dispatchRun: (msg, o, sp, mf, pm, mt, mp) => this.dispatchRun(msg, o, sp, mf, pm, mt, mp)
17856
17973
  },
17857
17974
  message,