@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
@@ -1,6 +1,6 @@
1
1
  import * as zod from 'zod';
2
2
  import { ZodType } from 'zod';
3
- import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, k as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor, r as MessageOrigin } from './run-CLXKMRgq.cjs';
3
+ import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, k as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor, r as MessageOrigin } from './run-CrHz9BAP.cjs';
4
4
 
5
5
  /**
6
6
  * Fork primitive public type contracts (T1.2, ADRs D110-D114).
@@ -1,6 +1,6 @@
1
1
  import * as zod from 'zod';
2
2
  import { ZodType } from 'zod';
3
- import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, k as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor, r as MessageOrigin } from './run-CLXKMRgq.js';
3
+ import { C as CustomTool, M as ModelSelection, a7 as SDKUserMessage, a9 as SendOptions, b as Run, G as GenerateOptions, k as GenerateRunResult, V as RunToCompletionOptions, W as RunToCompletionResult, S as SDKMessage, ag as StreamToCompletionResult, a as McpServerConfig, P as Processor, r as MessageOrigin } from './run-CrHz9BAP.js';
4
4
 
5
5
  /**
6
6
  * Fork primitive public type contracts (T1.2, ADRs D110-D114).
package/dist/cron.cjs CHANGED
@@ -966,10 +966,10 @@ function buildToolPrompt(prompt) {
966
966
  Respond by calling the \`output\` tool with the structured answer that matches the schema.`;
967
967
  }
968
968
  function setupStructuredOutput(schema, maxRetries) {
969
- const z7 = requireZod();
969
+ const z8 = requireZod();
970
970
  const jsonSchema = toJsonSchema(schema, { unrepresentable: "any" });
971
971
  return {
972
- z: z7,
972
+ z: z8,
973
973
  jsonSchema,
974
974
  maxRetries: maxRetries ?? 1,
975
975
  initialUsage: { inputTokens: 0, outputTokens: 0 }
@@ -6045,7 +6045,7 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
6045
6045
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
6046
6046
  };
6047
6047
  }
6048
- async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6048
+ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6049
6049
  const resolved = await resolveSendSkills(inputs, userText, memoryFacts);
6050
6050
  const baseCtx = await buildSystemPromptContext(inputs, userText, memoryFacts, resolved.manager);
6051
6051
  const assemblyCtx = {
@@ -6058,19 +6058,21 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
6058
6058
  assemblyCtx.activeMemorySummary = activeMemorySummary;
6059
6059
  }
6060
6060
  if (inputs.context !== void 0) {
6061
+ await inputs.context.applyScope(contextPaths);
6061
6062
  const internal = inputs.context.internalAssemblySnapshot();
6062
6063
  assemblyCtx.contextSnapshot = { sources: internal.sources };
6063
6064
  if (internal.maxTokens !== void 0) assemblyCtx.contextMaxTokens = internal.maxTokens;
6064
6065
  }
6065
6066
  return assemblyCtx;
6066
6067
  }
6067
- async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6068
+ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6068
6069
  const ctx = await buildAssemblyContext(
6069
6070
  inputs,
6070
6071
  userText,
6071
6072
  baseSystemPrompt,
6072
6073
  memoryFacts,
6073
- activeMemorySummary
6074
+ activeMemorySummary,
6075
+ contextPaths
6074
6076
  );
6075
6077
  return inputs.systemPromptPipeline.assemble(ctx);
6076
6078
  }
@@ -6777,6 +6779,14 @@ var init_context_discovery = __esm({
6777
6779
  followImports: false,
6778
6780
  priority: 40
6779
6781
  },
6782
+ {
6783
+ id: "theokit-rules",
6784
+ pattern: ".theokit/rules/*.md",
6785
+ scope: "globbed",
6786
+ parser: "rules-frontmatter",
6787
+ followImports: false,
6788
+ priority: 45
6789
+ },
6780
6790
  {
6781
6791
  id: "theokit-context",
6782
6792
  pattern: ".theokit/context/*.md",
@@ -6860,32 +6870,27 @@ var init_context_import_resolver = __esm({
6860
6870
  MAX_HOPS = 5;
6861
6871
  }
6862
6872
  });
6863
- function parseMdc(content) {
6864
- const m = FRONTMATTER_RE.exec(content);
6865
- if (m === null) {
6866
- return { frontmatter: { alwaysApply: true }, body: content };
6867
- }
6868
- const yamlBody = m[1] ?? "";
6869
- const body = m[2] ?? "";
6870
- try {
6871
- const parsed = parseSimpleYaml2(yamlBody);
6872
- const validated = McdFrontmatterSchema.safeParse(parsed);
6873
- if (!validated.success) return void 0;
6874
- return { frontmatter: validated.data, body };
6875
- } catch {
6876
- return void 0;
6877
- }
6873
+
6874
+ // src/internal/runtime/context/context-glob.ts
6875
+ function globToRegex(glob) {
6876
+ const compiled = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "::GLOBSTAR_SLASH::").replace(/\*\*/g, "::GLOBSTAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::GLOBSTAR_SLASH::/g, "(?:.*/)?").replace(/::GLOBSTAR::/g, ".*");
6877
+ return new RegExp(`^${compiled}$`);
6878
6878
  }
6879
- function shouldActivate(fm, touchedFiles) {
6880
- if (fm.alwaysApply === true) return true;
6881
- if (fm.globs === void 0 || fm.globs.length === 0) return false;
6882
- if (touchedFiles.length === 0) return false;
6883
- const globRes = fm.globs.map(globToRegex);
6884
- return touchedFiles.some((file) => globRes.some((re) => re.test(file)));
6879
+ function anyGlobMatches(patterns, paths) {
6880
+ if (patterns.length === 0 || paths.length === 0) return false;
6881
+ const res = patterns.map(globToRegex);
6882
+ return paths.some((p) => res.some((re) => re.test(p)));
6885
6883
  }
6886
- function globToRegex(glob) {
6887
- const escaped = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "::DOUBLESTAR::").replace(/\*/g, "[^/]*").replace(/::DOUBLESTAR::/g, ".*").replace(/\?/g, ".");
6888
- return new RegExp(`^${escaped}$`);
6884
+ var init_context_glob = __esm({
6885
+ "src/internal/runtime/context/context-glob.ts"() {
6886
+ }
6887
+ });
6888
+
6889
+ // src/internal/runtime/context/context-yaml-lite.ts
6890
+ function splitFrontmatter3(content) {
6891
+ const m = FRONTMATTER_RE.exec(content);
6892
+ if (m === null) return { yaml: void 0, body: content };
6893
+ return { yaml: m[1] ?? "", body: m[2] ?? "" };
6889
6894
  }
6890
6895
  function parseSimpleYaml2(yaml) {
6891
6896
  const out = {};
@@ -6932,15 +6937,76 @@ function parseScalar(s) {
6932
6937
  if (/^-?\d+$/.test(s)) return parseInt(s, 10);
6933
6938
  return s.replace(/^["']|["']$/g, "");
6934
6939
  }
6935
- var McdFrontmatterSchema, FRONTMATTER_RE;
6940
+ var FRONTMATTER_RE;
6941
+ var init_context_yaml_lite = __esm({
6942
+ "src/internal/runtime/context/context-yaml-lite.ts"() {
6943
+ FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6944
+ }
6945
+ });
6946
+ function parseMdc(content) {
6947
+ const { yaml, body } = splitFrontmatter3(content);
6948
+ if (yaml === void 0) {
6949
+ return { frontmatter: { alwaysApply: true }, body: content };
6950
+ }
6951
+ try {
6952
+ const parsed = parseSimpleYaml2(yaml);
6953
+ const validated = McdFrontmatterSchema.safeParse(parsed);
6954
+ if (!validated.success) return void 0;
6955
+ return { frontmatter: validated.data, body };
6956
+ } catch {
6957
+ return void 0;
6958
+ }
6959
+ }
6960
+ function shouldActivate(fm, touchedFiles) {
6961
+ if (fm.alwaysApply === true) return true;
6962
+ if (fm.globs === void 0 || fm.globs.length === 0) return false;
6963
+ return anyGlobMatches(fm.globs, touchedFiles);
6964
+ }
6965
+ var McdFrontmatterSchema;
6936
6966
  var init_context_mdc_parser = __esm({
6937
6967
  "src/internal/runtime/context/context-mdc-parser.ts"() {
6968
+ init_context_glob();
6969
+ init_context_yaml_lite();
6938
6970
  McdFrontmatterSchema = zod.z.object({
6939
6971
  description: zod.z.string().optional(),
6940
6972
  globs: zod.z.array(zod.z.string()).optional(),
6941
6973
  alwaysApply: zod.z.boolean().optional()
6942
6974
  });
6943
- FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6975
+ }
6976
+ });
6977
+ function parseRules(content) {
6978
+ const { yaml, body } = splitFrontmatter3(content);
6979
+ if (yaml === void 0) {
6980
+ return { frontmatter: { alwaysApply: true }, body: content };
6981
+ }
6982
+ try {
6983
+ const parsed = parseSimpleYaml2(yaml);
6984
+ const validated = RulesFrontmatterSchema.safeParse(parsed);
6985
+ if (!validated.success) return void 0;
6986
+ return { frontmatter: validated.data, body };
6987
+ } catch {
6988
+ return void 0;
6989
+ }
6990
+ }
6991
+ function shouldActivateRule(fm, inScopePaths) {
6992
+ if (fm.enabled === false) return false;
6993
+ if (fm.alwaysApply === true) return true;
6994
+ const patterns = [...fm.paths ?? [], ...fm.globs ?? []];
6995
+ if (patterns.length === 0) return false;
6996
+ return anyGlobMatches(patterns, inScopePaths);
6997
+ }
6998
+ var RulesFrontmatterSchema;
6999
+ var init_context_rules_frontmatter = __esm({
7000
+ "src/internal/runtime/context/context-rules-frontmatter.ts"() {
7001
+ init_context_glob();
7002
+ init_context_yaml_lite();
7003
+ RulesFrontmatterSchema = zod.z.object({
7004
+ description: zod.z.string().optional(),
7005
+ paths: zod.z.array(zod.z.string()).optional(),
7006
+ globs: zod.z.array(zod.z.string()).optional(),
7007
+ alwaysApply: zod.z.boolean().optional(),
7008
+ enabled: zod.z.boolean().optional()
7009
+ });
6944
7010
  }
6945
7011
  });
6946
7012
  async function runDiscovery(opts) {
@@ -6976,6 +7042,9 @@ async function loadOneSource(spec, path$1, opts, gitRoot) {
6976
7042
  if (spec.parser === "mdc") {
6977
7043
  return loadMdcSource(spec, path$1, id, opts);
6978
7044
  }
7045
+ if (spec.parser === "rules-frontmatter") {
7046
+ return loadRulesSource(spec, path$1, id, opts);
7047
+ }
6979
7048
  if (spec.parser === "frontmatter-zod") {
6980
7049
  return void 0;
6981
7050
  }
@@ -6999,6 +7068,24 @@ async function loadMdcSource(spec, path, id, opts) {
6999
7068
  truncated: false
7000
7069
  };
7001
7070
  }
7071
+ async function loadRulesSource(spec, path, id, opts) {
7072
+ let raw;
7073
+ try {
7074
+ raw = await promises.readFile(path, "utf8");
7075
+ } catch {
7076
+ return void 0;
7077
+ }
7078
+ const parsed = parseRules(raw);
7079
+ if (parsed === void 0) return void 0;
7080
+ if (!shouldActivateRule(parsed.frontmatter, opts.touchedFiles ?? [])) return void 0;
7081
+ return {
7082
+ id,
7083
+ source: path,
7084
+ content: parsed.body,
7085
+ priority: spec.priority,
7086
+ truncated: false
7087
+ };
7088
+ }
7002
7089
  async function loadPlainMarkdownSource(spec, path, id, opts) {
7003
7090
  const loaded = await loadPlainMarkdown(path, { maxBytesPerFile: opts.maxBytesPerFile });
7004
7091
  if (loaded === void 0) return void 0;
@@ -7024,6 +7111,7 @@ var init_context_discovery_runner = __esm({
7024
7111
  init_context_import_resolver();
7025
7112
  init_context_loaders();
7026
7113
  init_context_mdc_parser();
7114
+ init_context_rules_frontmatter();
7027
7115
  }
7028
7116
  });
7029
7117
  var ContextSourceFrontmatterSchema;
@@ -7159,6 +7247,10 @@ function matchesGlob(pattern, path) {
7159
7247
  function tokenizeContent(content) {
7160
7248
  return content.split(/\s+/).filter((token) => token.length > 0);
7161
7249
  }
7250
+ function sameScope(a, b) {
7251
+ if (a.length !== b.length) return false;
7252
+ return a.every((v, i) => v === b[i]);
7253
+ }
7162
7254
  var FileContextManager;
7163
7255
  var init_context_manager = __esm({
7164
7256
  "src/internal/runtime/context/context-manager.ts"() {
@@ -7179,6 +7271,13 @@ var init_context_manager = __esm({
7179
7271
  settings;
7180
7272
  settingSourcesIncludeProject;
7181
7273
  state;
7274
+ /**
7275
+ * The in-scope file set used by the most recent `refresh`. Tracked so
7276
+ * `applyScope` only touches state when the scope actually changes — a
7277
+ * caller that never scopes (the common case) keeps the create-time
7278
+ * snapshot untouched, at zero per-send cost.
7279
+ */
7280
+ lastScope = [];
7182
7281
  async initialize() {
7183
7282
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
7184
7283
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -7186,14 +7285,31 @@ var init_context_manager = __esm({
7186
7285
  }
7187
7286
  await this.refresh();
7188
7287
  }
7189
- async refresh() {
7288
+ /**
7289
+ * Re-run discovery for a specific per-send in-scope file set (T3). Path-scoped
7290
+ * rules (`.theokit/rules/*.md`, `.cursor/rules/*.mdc` globs) activate iff a
7291
+ * pattern matches one of `contextPaths`. Idempotent: unchanged scope is a
7292
+ * no-op, and `undefined` scope while never previously scoped never touches
7293
+ * state (preserves the create-time snapshot for non-users).
7294
+ */
7295
+ async applyScope(contextPaths) {
7296
+ const scope = contextPaths ?? [];
7297
+ if (scope.length === 0 && this.lastScope.length === 0) return;
7298
+ if (sameScope(scope, this.lastScope)) return;
7299
+ await this.refresh({ touchedFiles: scope });
7300
+ }
7301
+ async refresh(opts) {
7302
+ const touchedFiles = opts?.touchedFiles ?? [];
7303
+ this.lastScope = [...touchedFiles];
7190
7304
  const config = await loadContextConfig(this.cwd);
7191
7305
  const legacy = await loadSources(config, this.cwd);
7192
7306
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
7193
7307
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
7194
7308
  const discovered = await runDiscovery({
7195
7309
  cwd: this.cwd,
7196
- maxBytesPerFile});
7310
+ maxBytesPerFile,
7311
+ touchedFiles
7312
+ });
7197
7313
  const legacyAsAggregator = legacy.map((src) => ({
7198
7314
  id: src.name,
7199
7315
  source: src.path,
@@ -17123,7 +17239,8 @@ async function executeSendLocked(inputs, message, options) {
17123
17239
  userText,
17124
17240
  baseSystemPrompt,
17125
17241
  memoryFacts,
17126
- activeMemorySummary
17242
+ activeMemorySummary,
17243
+ options.contextPaths
17127
17244
  );
17128
17245
  const projectedSystemPrompt = await projectCurrentObjective(
17129
17246
  inputs.storageHandle,
@@ -18011,7 +18128,7 @@ var init_local_agent = __esm({
18011
18128
  runPreHook: (ut) => this.runPreHook(ut),
18012
18129
  // biome-ignore format: G8 budget — callbacks wire to private methods.
18013
18130
  resolveSystemPromptForSend: (ut, o, mf) => this.resolveSystemPrompt(ut, o, mf),
18014
- assembleSystemPromptForSend: (ut, bp, mf, ams) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams),
18131
+ assembleSystemPromptForSend: (ut, bp, mf, ams, cp) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams, cp),
18015
18132
  dispatchRun: (msg, o, sp, mf, pm, mt, mp) => this.dispatchRun(msg, o, sp, mf, pm, mt, mp)
18016
18133
  },
18017
18134
  message,