@theokit/sdk 3.1.1 → 3.2.2

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 (44) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/a2a/index.cjs +188 -49
  3. package/dist/a2a/index.cjs.map +1 -1
  4. package/dist/a2a/index.js +188 -49
  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 +188 -49
  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 +188 -49
  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 +188 -64
  18. package/dist/eval.cjs.map +1 -1
  19. package/dist/eval.js +188 -64
  20. package/dist/eval.js.map +1 -1
  21. package/dist/index.cjs +197 -50
  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 +197 -50
  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/sandbox/index.cjs +8 -9
  38. package/dist/sandbox/index.cjs.map +1 -1
  39. package/dist/sandbox/index.js +8 -9
  40. package/dist/sandbox/index.js.map +1 -1
  41. package/dist/sandbox/types.d.cts +0 -1
  42. package/dist/sandbox/types.d.ts +0 -1
  43. package/dist/types/run.d.ts +9 -0
  44. package/package.json +3 -3
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 }
@@ -4757,7 +4757,14 @@ var init_env_policy = __esm({
4757
4757
  /[_-]PWD/i,
4758
4758
  /CREDENTIAL/i,
4759
4759
  /PRIVATE/i,
4760
- /_AUTH/i
4760
+ /_AUTH/i,
4761
+ // #54-a — value-embedded-secret conventions (no generic `*_URL` — see keep-list test).
4762
+ /DSN/i,
4763
+ /WEBHOOK/i,
4764
+ /COOKIE/i,
4765
+ /CONNECTION[_-]?STRING/i,
4766
+ // Known DB / message-broker connection-string vars (carry `user:pass@`).
4767
+ /(?:^|[_-])(?:DATABASE|DB|REDIS|MONGO(?:DB)?|POSTGRES(?:QL)?|MYSQL|MARIADB|AMQP|RABBITMQ|CLICKHOUSE|ELASTIC(?:SEARCH)?|CASSANDRA|COUCHDB|MEMCACHED|NATS|KAFKA)[_-]?(?:URL|URI|DSN|CONNECTION)/i
4761
4768
  ];
4762
4769
  CORE_VARS = [
4763
4770
  "PATH",
@@ -6055,7 +6062,7 @@ async function buildSystemPromptContext(inputs, userText, memoryFacts, manager =
6055
6062
  memory: memoryFacts.map((fact) => ({ text: fact.text }))
6056
6063
  };
6057
6064
  }
6058
- async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6065
+ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6059
6066
  const resolved = await resolveSendSkills(inputs, userText, memoryFacts);
6060
6067
  const baseCtx = await buildSystemPromptContext(inputs, userText, memoryFacts, resolved.manager);
6061
6068
  const assemblyCtx = {
@@ -6068,19 +6075,21 @@ async function buildAssemblyContext(inputs, userText, baseSystemPrompt, memoryFa
6068
6075
  assemblyCtx.activeMemorySummary = activeMemorySummary;
6069
6076
  }
6070
6077
  if (inputs.context !== void 0) {
6078
+ await inputs.context.applyScope(contextPaths);
6071
6079
  const internal = inputs.context.internalAssemblySnapshot();
6072
6080
  assemblyCtx.contextSnapshot = { sources: internal.sources };
6073
6081
  if (internal.maxTokens !== void 0) assemblyCtx.contextMaxTokens = internal.maxTokens;
6074
6082
  }
6075
6083
  return assemblyCtx;
6076
6084
  }
6077
- async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary) {
6085
+ async function assembleSystemPromptForSend(inputs, userText, baseSystemPrompt, memoryFacts, activeMemorySummary, contextPaths) {
6078
6086
  const ctx = await buildAssemblyContext(
6079
6087
  inputs,
6080
6088
  userText,
6081
6089
  baseSystemPrompt,
6082
6090
  memoryFacts,
6083
- activeMemorySummary
6091
+ activeMemorySummary,
6092
+ contextPaths
6084
6093
  );
6085
6094
  return inputs.systemPromptPipeline.assemble(ctx);
6086
6095
  }
@@ -6787,6 +6796,14 @@ var init_context_discovery = __esm({
6787
6796
  followImports: false,
6788
6797
  priority: 40
6789
6798
  },
6799
+ {
6800
+ id: "theokit-rules",
6801
+ pattern: ".theokit/rules/*.md",
6802
+ scope: "globbed",
6803
+ parser: "rules-frontmatter",
6804
+ followImports: false,
6805
+ priority: 45
6806
+ },
6790
6807
  {
6791
6808
  id: "theokit-context",
6792
6809
  pattern: ".theokit/context/*.md",
@@ -6870,32 +6887,27 @@ var init_context_import_resolver = __esm({
6870
6887
  MAX_HOPS = 5;
6871
6888
  }
6872
6889
  });
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
- }
6890
+
6891
+ // src/internal/runtime/context/context-glob.ts
6892
+ function globToRegex(glob) {
6893
+ const compiled = glob.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "::GLOBSTAR_SLASH::").replace(/\*\*/g, "::GLOBSTAR::").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/::GLOBSTAR_SLASH::/g, "(?:.*/)?").replace(/::GLOBSTAR::/g, ".*");
6894
+ return new RegExp(`^${compiled}$`);
6888
6895
  }
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)));
6896
+ function anyGlobMatches(patterns, paths) {
6897
+ if (patterns.length === 0 || paths.length === 0) return false;
6898
+ const res = patterns.map(globToRegex);
6899
+ return paths.some((p) => res.some((re) => re.test(p)));
6895
6900
  }
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}$`);
6901
+ var init_context_glob = __esm({
6902
+ "src/internal/runtime/context/context-glob.ts"() {
6903
+ }
6904
+ });
6905
+
6906
+ // src/internal/runtime/context/context-yaml-lite.ts
6907
+ function splitFrontmatter3(content) {
6908
+ const m = FRONTMATTER_RE.exec(content);
6909
+ if (m === null) return { yaml: void 0, body: content };
6910
+ return { yaml: m[1] ?? "", body: m[2] ?? "" };
6899
6911
  }
6900
6912
  function parseSimpleYaml2(yaml) {
6901
6913
  const out = {};
@@ -6942,15 +6954,76 @@ function parseScalar(s) {
6942
6954
  if (/^-?\d+$/.test(s)) return parseInt(s, 10);
6943
6955
  return s.replace(/^["']|["']$/g, "");
6944
6956
  }
6945
- var McdFrontmatterSchema, FRONTMATTER_RE;
6957
+ var FRONTMATTER_RE;
6958
+ var init_context_yaml_lite = __esm({
6959
+ "src/internal/runtime/context/context-yaml-lite.ts"() {
6960
+ FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6961
+ }
6962
+ });
6963
+ function parseMdc(content) {
6964
+ const { yaml, body } = splitFrontmatter3(content);
6965
+ if (yaml === void 0) {
6966
+ return { frontmatter: { alwaysApply: true }, body: content };
6967
+ }
6968
+ try {
6969
+ const parsed = parseSimpleYaml2(yaml);
6970
+ const validated = McdFrontmatterSchema.safeParse(parsed);
6971
+ if (!validated.success) return void 0;
6972
+ return { frontmatter: validated.data, body };
6973
+ } catch {
6974
+ return void 0;
6975
+ }
6976
+ }
6977
+ function shouldActivate(fm, touchedFiles) {
6978
+ if (fm.alwaysApply === true) return true;
6979
+ if (fm.globs === void 0 || fm.globs.length === 0) return false;
6980
+ return anyGlobMatches(fm.globs, touchedFiles);
6981
+ }
6982
+ var McdFrontmatterSchema;
6946
6983
  var init_context_mdc_parser = __esm({
6947
6984
  "src/internal/runtime/context/context-mdc-parser.ts"() {
6985
+ init_context_glob();
6986
+ init_context_yaml_lite();
6948
6987
  McdFrontmatterSchema = zod.z.object({
6949
6988
  description: zod.z.string().optional(),
6950
6989
  globs: zod.z.array(zod.z.string()).optional(),
6951
6990
  alwaysApply: zod.z.boolean().optional()
6952
6991
  });
6953
- FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/;
6992
+ }
6993
+ });
6994
+ function parseRules(content) {
6995
+ const { yaml, body } = splitFrontmatter3(content);
6996
+ if (yaml === void 0) {
6997
+ return { frontmatter: { alwaysApply: true }, body: content };
6998
+ }
6999
+ try {
7000
+ const parsed = parseSimpleYaml2(yaml);
7001
+ const validated = RulesFrontmatterSchema.safeParse(parsed);
7002
+ if (!validated.success) return void 0;
7003
+ return { frontmatter: validated.data, body };
7004
+ } catch {
7005
+ return void 0;
7006
+ }
7007
+ }
7008
+ function shouldActivateRule(fm, inScopePaths) {
7009
+ if (fm.enabled === false) return false;
7010
+ if (fm.alwaysApply === true) return true;
7011
+ const patterns = [...fm.paths ?? [], ...fm.globs ?? []];
7012
+ if (patterns.length === 0) return false;
7013
+ return anyGlobMatches(patterns, inScopePaths);
7014
+ }
7015
+ var RulesFrontmatterSchema;
7016
+ var init_context_rules_frontmatter = __esm({
7017
+ "src/internal/runtime/context/context-rules-frontmatter.ts"() {
7018
+ init_context_glob();
7019
+ init_context_yaml_lite();
7020
+ RulesFrontmatterSchema = zod.z.object({
7021
+ description: zod.z.string().optional(),
7022
+ paths: zod.z.array(zod.z.string()).optional(),
7023
+ globs: zod.z.array(zod.z.string()).optional(),
7024
+ alwaysApply: zod.z.boolean().optional(),
7025
+ enabled: zod.z.boolean().optional()
7026
+ });
6954
7027
  }
6955
7028
  });
6956
7029
  async function runDiscovery(opts) {
@@ -6986,6 +7059,9 @@ async function loadOneSource(spec, path$1, opts, gitRoot) {
6986
7059
  if (spec.parser === "mdc") {
6987
7060
  return loadMdcSource(spec, path$1, id, opts);
6988
7061
  }
7062
+ if (spec.parser === "rules-frontmatter") {
7063
+ return loadRulesSource(spec, path$1, id, opts);
7064
+ }
6989
7065
  if (spec.parser === "frontmatter-zod") {
6990
7066
  return void 0;
6991
7067
  }
@@ -7009,6 +7085,24 @@ async function loadMdcSource(spec, path, id, opts) {
7009
7085
  truncated: false
7010
7086
  };
7011
7087
  }
7088
+ async function loadRulesSource(spec, path, id, opts) {
7089
+ let raw;
7090
+ try {
7091
+ raw = await promises.readFile(path, "utf8");
7092
+ } catch {
7093
+ return void 0;
7094
+ }
7095
+ const parsed = parseRules(raw);
7096
+ if (parsed === void 0) return void 0;
7097
+ if (!shouldActivateRule(parsed.frontmatter, opts.touchedFiles ?? [])) return void 0;
7098
+ return {
7099
+ id,
7100
+ source: path,
7101
+ content: parsed.body,
7102
+ priority: spec.priority,
7103
+ truncated: false
7104
+ };
7105
+ }
7012
7106
  async function loadPlainMarkdownSource(spec, path, id, opts) {
7013
7107
  const loaded = await loadPlainMarkdown(path, { maxBytesPerFile: opts.maxBytesPerFile });
7014
7108
  if (loaded === void 0) return void 0;
@@ -7034,6 +7128,7 @@ var init_context_discovery_runner = __esm({
7034
7128
  init_context_import_resolver();
7035
7129
  init_context_loaders();
7036
7130
  init_context_mdc_parser();
7131
+ init_context_rules_frontmatter();
7037
7132
  }
7038
7133
  });
7039
7134
  var ContextSourceFrontmatterSchema;
@@ -7169,6 +7264,10 @@ function matchesGlob(pattern, path) {
7169
7264
  function tokenizeContent(content) {
7170
7265
  return content.split(/\s+/).filter((token) => token.length > 0);
7171
7266
  }
7267
+ function sameScope(a, b) {
7268
+ if (a.length !== b.length) return false;
7269
+ return a.every((v, i) => v === b[i]);
7270
+ }
7172
7271
  var FileContextManager;
7173
7272
  var init_context_manager = __esm({
7174
7273
  "src/internal/runtime/context/context-manager.ts"() {
@@ -7189,6 +7288,13 @@ var init_context_manager = __esm({
7189
7288
  settings;
7190
7289
  settingSourcesIncludeProject;
7191
7290
  state;
7291
+ /**
7292
+ * The in-scope file set used by the most recent `refresh`. Tracked so
7293
+ * `applyScope` only touches state when the scope actually changes — a
7294
+ * caller that never scopes (the common case) keeps the create-time
7295
+ * snapshot untouched, at zero per-send cost.
7296
+ */
7297
+ lastScope = [];
7192
7298
  async initialize() {
7193
7299
  if (!this.settingSourcesIncludeProject && this.settings.manager !== "file") {
7194
7300
  this.state = { config: { sources: [] }, loadedSources: [] };
@@ -7196,14 +7302,31 @@ var init_context_manager = __esm({
7196
7302
  }
7197
7303
  await this.refresh();
7198
7304
  }
7199
- async refresh() {
7305
+ /**
7306
+ * Re-run discovery for a specific per-send in-scope file set (T3). Path-scoped
7307
+ * rules (`.theokit/rules/*.md`, `.cursor/rules/*.mdc` globs) activate iff a
7308
+ * pattern matches one of `contextPaths`. Idempotent: unchanged scope is a
7309
+ * no-op, and `undefined` scope while never previously scoped never touches
7310
+ * state (preserves the create-time snapshot for non-users).
7311
+ */
7312
+ async applyScope(contextPaths) {
7313
+ const scope = contextPaths ?? [];
7314
+ if (scope.length === 0 && this.lastScope.length === 0) return;
7315
+ if (sameScope(scope, this.lastScope)) return;
7316
+ await this.refresh({ touchedFiles: scope });
7317
+ }
7318
+ async refresh(opts) {
7319
+ const touchedFiles = opts?.touchedFiles ?? [];
7320
+ this.lastScope = [...touchedFiles];
7200
7321
  const config = await loadContextConfig(this.cwd);
7201
7322
  const legacy = await loadSources(config, this.cwd);
7202
7323
  const maxBytesPerFile = this.settings.maxBytesPerFile ?? DEFAULT_MAX_BYTES_PER_FILE;
7203
7324
  const maxBytesTotal = this.settings.maxBytesTotal ?? DEFAULT_MAX_BYTES_TOTAL;
7204
7325
  const discovered = await runDiscovery({
7205
7326
  cwd: this.cwd,
7206
- maxBytesPerFile});
7327
+ maxBytesPerFile,
7328
+ touchedFiles
7329
+ });
7207
7330
  const legacyAsAggregator = legacy.map((src) => ({
7208
7331
  id: src.name,
7209
7332
  source: src.path,
@@ -7638,15 +7761,19 @@ async function collectChildToolResults(run) {
7638
7761
  ${lines.join("\n")}
7639
7762
  </subagent-tool-results>`;
7640
7763
  }
7641
- async function runChildAgent(spec, input, signal, maxSteps, inherited) {
7642
- const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
7764
+ function buildChildCreateOptions(spec, inherited) {
7643
7765
  const model = spec.model ? { id: spec.model } : inherited?.model;
7644
- const agent = await Agent2.create({
7766
+ return {
7645
7767
  ...inherited?.apiKey !== void 0 ? { apiKey: inherited.apiKey } : {},
7646
7768
  ...model !== void 0 ? { model } : {},
7769
+ ...inherited?.plugins !== void 0 ? { plugins: inherited.plugins } : {},
7647
7770
  systemPrompt: spec.instructions,
7648
7771
  tools: spec.tools ?? []
7649
- });
7772
+ };
7773
+ }
7774
+ async function runChildAgent(spec, input, signal, maxSteps, inherited) {
7775
+ const { Agent: Agent2 } = await Promise.resolve().then(() => (init_agent(), agent_exports));
7776
+ const agent = await Agent2.create(buildChildCreateOptions(spec, inherited));
7650
7777
  try {
7651
7778
  const sendOptions = {
7652
7779
  ...signal !== void 0 ? { signal } : {},
@@ -9549,7 +9676,10 @@ async function runAgentLoop(inputs) {
9549
9676
  }
9550
9677
  budget.consume();
9551
9678
  inputs.budgetTracker?.nextIteration?.();
9552
- if (inputs.signal?.aborted === true) break;
9679
+ if (inputs.signal?.aborted === true) {
9680
+ ctx.finalStatus = "cancelled";
9681
+ break;
9682
+ }
9553
9683
  }
9554
9684
  if (lastTurnDecision === "continue" && budget.shouldContinue() === false) {
9555
9685
  ctx.stoppedAtIterationLimit = true;
@@ -9734,15 +9864,15 @@ async function guardAndTransformToolResults(inputs, raw, ctx) {
9734
9864
  }
9735
9865
  async function continueOrTerminate(inputs, ctx, llmOutput) {
9736
9866
  if (llmOutput.errored) return "error";
9737
- if (llmOutput.text.length > 0) {
9738
- await emitAssistantTextStep(inputs, ctx, llmOutput.text);
9867
+ const tCtx = { agentId: inputs.agentId, runId: inputs.runId };
9868
+ const text = llmOutput.text.length > 0 ? await transformLlmOutputText(inputs, llmOutput.text, tCtx) : llmOutput.text;
9869
+ if (text.length > 0) {
9870
+ await emitAssistantTextStep(inputs, ctx, text);
9739
9871
  }
9740
9872
  if (llmOutput.stopReason !== "tool_use" || llmOutput.toolCalls.length === 0) {
9741
9873
  return finishOrReflect(inputs, ctx, llmOutput);
9742
9874
  }
9743
- const tCtx = { agentId: inputs.agentId, runId: inputs.runId };
9744
- const outText = await transformLlmOutputText(inputs, llmOutput.text, tCtx);
9745
- ctx.messages.push(buildAssistantTurn(outText, llmOutput.toolCalls));
9875
+ ctx.messages.push(buildAssistantTurn(text, llmOutput.toolCalls));
9746
9876
  const rawResults = await dispatchTools(
9747
9877
  // SE12 — forward a read-only text projection of the transcript-so-far to tool
9748
9878
  // handlers via `ctx.messages` (consumed by defineSubAgent's messageFilter).
@@ -13080,7 +13210,12 @@ var init_client = __esm({
13080
13210
  code: "mcp_http_error"
13081
13211
  });
13082
13212
  }
13083
- return await response.json();
13213
+ try {
13214
+ return await response.json();
13215
+ } catch (cause) {
13216
+ if (isAbortLike(cause)) throw mcpTimeoutError(this.name, timeoutMs);
13217
+ throw cause;
13218
+ }
13084
13219
  }
13085
13220
  };
13086
13221
  }
@@ -13320,9 +13455,11 @@ function declarativeSubagentTools(agentOptions, parentTools) {
13320
13455
  return subAgentToolsFromDefinitions(agents2, parentTools);
13321
13456
  }
13322
13457
  function bindParentCredentials(tools, agentOptions) {
13458
+ const parentPlugins = Array.isArray(agentOptions.plugins) ? agentOptions.plugins : void 0;
13323
13459
  const credentials = {
13324
13460
  ...agentOptions.apiKey !== void 0 ? { apiKey: agentOptions.apiKey } : {},
13325
- ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {}
13461
+ ...typeof agentOptions.model === "object" ? { model: agentOptions.model } : {},
13462
+ ...parentPlugins !== void 0 ? { plugins: parentPlugins } : {}
13326
13463
  };
13327
13464
  for (const tool of tools) inheritSubAgentCredentials(tool, credentials);
13328
13465
  }
@@ -15856,10 +15993,11 @@ var init_local_agent_memory = __esm({
15856
15993
  }
15857
15994
  buildTelemetryRecallArgs(telemetry) {
15858
15995
  const userId = typeof this.options.memoryContext?.userId === "string" ? this.options.memoryContext.userId : void 0;
15996
+ const tenantId = typeof this.options.memoryContext?.tenantId === "string" ? this.options.memoryContext.tenantId : void 0;
15859
15997
  return {
15860
15998
  ...telemetry !== void 0 ? { telemetry } : {},
15861
15999
  ...userId !== void 0 ? { userId } : {},
15862
- namespace: "default",
16000
+ namespace: tenantId ?? "default",
15863
16001
  scope: "session"
15864
16002
  };
15865
16003
  }
@@ -17156,7 +17294,8 @@ async function executeSendLocked(inputs, message, options) {
17156
17294
  userText,
17157
17295
  baseSystemPrompt,
17158
17296
  memoryFacts,
17159
- activeMemorySummary
17297
+ activeMemorySummary,
17298
+ options.contextPaths
17160
17299
  );
17161
17300
  const projectedSystemPrompt = await projectCurrentObjective(
17162
17301
  inputs.storageHandle,
@@ -18229,7 +18368,7 @@ var init_local_agent = __esm({
18229
18368
  runPreHook: (ut) => this.runPreHook(ut),
18230
18369
  // biome-ignore format: G8 budget — callbacks wire to private methods.
18231
18370
  resolveSystemPromptForSend: (ut, o, mf) => this.resolveSystemPrompt(ut, o, mf),
18232
- assembleSystemPromptForSend: (ut, bp, mf, ams) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams),
18371
+ assembleSystemPromptForSend: (ut, bp, mf, ams, cp) => assembleSystemPromptForSend(this.assemblyInputs(), ut, bp, mf, ams, cp),
18233
18372
  dispatchRun: (msg, o, sp, mf, pm, mt, mp) => this.dispatchRun(msg, o, sp, mf, pm, mt, mp)
18234
18373
  },
18235
18374
  message,
@@ -22128,8 +22267,10 @@ var JobQueue = class {
22128
22267
  const job = this.jobs.get(id);
22129
22268
  if (!job) return false;
22130
22269
  if (job.status === "pending" || job.status === "running") {
22270
+ const wasRunning = job.status === "running";
22131
22271
  job.status = "cancelled";
22132
22272
  this.controllers.get(id)?.abort();
22273
+ if (wasRunning) this.#release(id);
22133
22274
  return true;
22134
22275
  }
22135
22276
  return false;
@@ -22147,8 +22288,14 @@ var JobQueue = class {
22147
22288
  });
22148
22289
  });
22149
22290
  }
22150
- /** Release a slot + clean up the controller; start the next waiting job. */
22291
+ /**
22292
+ * Release a slot + clean up the controller; start the next waiting job.
22293
+ * Idempotent — keyed on the controller's presence, so a running job that was
22294
+ * cancelled (released early) does not double-decrement when its `.finally`
22295
+ * eventually fires.
22296
+ */
22151
22297
  #release(id) {
22298
+ if (!this.controllers.has(id)) return;
22152
22299
  this.controllers.delete(id);
22153
22300
  this.running -= 1;
22154
22301
  const next = this.waiting.shift();