@mrciphersmith/keryx 0.4.21 → 0.4.24

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.
package/dist/core.js CHANGED
@@ -10647,6 +10647,13 @@ function parseFlowArray(value) {
10647
10647
  }
10648
10648
  return inner.split(",").map((item) => stripQuotes(item.trim())).filter((item) => item.length > 0);
10649
10649
  }
10650
+ function parseNestedScalar(value) {
10651
+ if (value.startsWith("[") && value.endsWith("]"))
10652
+ return parseFlowArray(value);
10653
+ if (/^-?\d+$/.test(value))
10654
+ return Number.parseInt(value, 10);
10655
+ return stripQuotes(value);
10656
+ }
10650
10657
  function parseIndentedBlock(lines, startIndex) {
10651
10658
  const first = lines[startIndex];
10652
10659
  if (first === undefined || !INDENTED_LINE.test(first)) {
@@ -10666,7 +10673,7 @@ function parseIndentedBlock(lines, startIndex) {
10666
10673
  }
10667
10674
  return { value: items, consumed: index - startIndex };
10668
10675
  }
10669
- const mapping = {};
10676
+ const mapping = Object.create(null);
10670
10677
  while (index < lines.length) {
10671
10678
  const line = lines[index] ?? "";
10672
10679
  if (!INDENTED_LINE.test(line))
@@ -10677,7 +10684,7 @@ function parseIndentedBlock(lines, startIndex) {
10677
10684
  const key = match[1] ?? "";
10678
10685
  const value = (match[2] ?? "").trim();
10679
10686
  if (value.length > 0) {
10680
- mapping[key] = stripQuotes(value);
10687
+ mapping[key] = parseNestedScalar(value);
10681
10688
  }
10682
10689
  index += 1;
10683
10690
  }
@@ -10698,7 +10705,7 @@ function parseAgentFrontmatter(content) {
10698
10705
  const body = bodyStart === -1 ? "" : content.slice(bodyStart + 1);
10699
10706
  const lines = content.slice(3, end).split(`
10700
10707
  `);
10701
- const data = {};
10708
+ const data = Object.create(null);
10702
10709
  let i = 0;
10703
10710
  while (i < lines.length) {
10704
10711
  const line = lines[i] ?? "";
@@ -10799,6 +10806,41 @@ function validateOrigin(value, errors) {
10799
10806
  pushError(errors, "origin-invalid-type", "origin.generatedAt", "origin.generatedAt must be a string");
10800
10807
  }
10801
10808
  }
10809
+ function validateDelegation(value, errors) {
10810
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
10811
+ pushError(errors, "delegation-not-an-object", "delegation", "delegation must be a mapping");
10812
+ return;
10813
+ }
10814
+ const delegation = value;
10815
+ for (const field of AGENT_DELEGATION_REQUIRED_FIELDS) {
10816
+ if (delegation[field] === undefined) {
10817
+ pushError(errors, "delegation-missing-required-field", `delegation.${field}`, `delegation.${field} is required`);
10818
+ }
10819
+ }
10820
+ for (const key of Object.keys(delegation)) {
10821
+ if (!AGENT_DELEGATION_FIELDS.includes(key)) {
10822
+ pushError(errors, "delegation-unknown-field", `delegation.${key}`, `delegation.${key} is not recognized`);
10823
+ }
10824
+ }
10825
+ const allowed = delegation.allowed_entities;
10826
+ if (allowed !== undefined) {
10827
+ if (!Array.isArray(allowed) || !allowed.every((item) => typeof item === "string" && AGENT_NAME_PATTERN.test(item))) {
10828
+ pushError(errors, "delegation-invalid-type", "delegation.allowed_entities", "allowed_entities must contain valid agent names");
10829
+ } else if (hasDuplicates(allowed)) {
10830
+ pushError(errors, "duplicate-item", "delegation.allowed_entities", "allowed_entities must not contain duplicates");
10831
+ }
10832
+ }
10833
+ for (const [field, maximum] of [["max_depth", 1], ["max_children", 512]]) {
10834
+ const bound = delegation[field];
10835
+ if (bound !== undefined) {
10836
+ if (typeof bound !== "number" || !Number.isSafeInteger(bound)) {
10837
+ pushError(errors, "delegation-invalid-type", `delegation.${field}`, `${field} must be an integer`);
10838
+ } else if (bound < 0 || bound > maximum) {
10839
+ pushError(errors, "delegation-invalid-bound", `delegation.${field}`, `${field} must be between 0 and ${maximum}`);
10840
+ }
10841
+ }
10842
+ }
10843
+ }
10802
10844
  function validateAgentFrontmatter(raw) {
10803
10845
  if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
10804
10846
  return { ok: false, errors: [{ reason: "not-an-object", field: "$", message: "frontmatter must be a mapping" }] };
@@ -10815,8 +10857,20 @@ function validateAgentFrontmatter(raw) {
10815
10857
  pushError(errors, "unknown-field", key, `${key} is not a recognized agent-definition field`);
10816
10858
  }
10817
10859
  }
10818
- if (data.schema_version !== undefined && data.schema_version !== 1) {
10819
- pushError(errors, "invalid-schema-version", "schema_version", "schema_version must be the literal 1");
10860
+ if (data.schema_version !== undefined && data.schema_version !== 1 && data.schema_version !== 2) {
10861
+ pushError(errors, "invalid-schema-version", "schema_version", "schema_version must be 1 or 2");
10862
+ }
10863
+ if (data.schema_version === 2) {
10864
+ for (const field of ["execution_kind", "tool_scope", "delegation"]) {
10865
+ if (data[field] === undefined)
10866
+ pushError(errors, "missing-required-field", field, `${field} is required in schema v2`);
10867
+ }
10868
+ } else {
10869
+ for (const field of ["execution_kind", "tool_scope", "delegation"]) {
10870
+ if (data[field] !== undefined) {
10871
+ pushError(errors, "v2-field-without-v2-schema", field, `${field} requires schema_version: 2`);
10872
+ }
10873
+ }
10820
10874
  }
10821
10875
  if (data.name !== undefined) {
10822
10876
  if (typeof data.name !== "string") {
@@ -10863,10 +10917,51 @@ function validateAgentFrontmatter(raw) {
10863
10917
  if (data.origin !== undefined) {
10864
10918
  validateOrigin(data.origin, errors);
10865
10919
  }
10920
+ if (data.execution_kind !== undefined && !AGENT_EXECUTION_KIND_VALUES.includes(data.execution_kind)) {
10921
+ pushError(errors, "invalid-enum", "execution_kind", `execution_kind must be one of ${AGENT_EXECUTION_KIND_VALUES.join(", ")}`);
10922
+ }
10923
+ if (data.tool_scope !== undefined && !AGENT_TOOL_SCOPE_VALUES.includes(data.tool_scope)) {
10924
+ pushError(errors, "invalid-enum", "tool_scope", `tool_scope must be one of ${AGENT_TOOL_SCOPE_VALUES.join(", ")}`);
10925
+ }
10926
+ if (data.delegation !== undefined)
10927
+ validateDelegation(data.delegation, errors);
10928
+ const executionKind = data.execution_kind ?? "worker";
10929
+ const toolScope = data.tool_scope ?? "static";
10930
+ const delegation = data.delegation;
10931
+ const allowedEntities = Array.isArray(delegation?.allowed_entities) ? delegation.allowed_entities : [];
10932
+ const maxDepth = typeof delegation?.max_depth === "number" ? delegation.max_depth : 0;
10933
+ const maxChildren = typeof delegation?.max_children === "number" ? delegation.max_children : 0;
10934
+ if (data.schema_version === 2 && executionKind === "worker" && (toolScope !== "static" || allowedEntities.length > 0 || maxDepth !== 0 || maxChildren !== 0)) {
10935
+ pushError(errors, "invalid-delegation-contract", "execution_kind", "workers must use static tools and cannot delegate");
10936
+ }
10937
+ if (data.schema_version === 2 && executionKind === "worker" && Array.isArray(data.tools) && data.tools.includes("spawn_subagent")) {
10938
+ pushError(errors, "invalid-delegation-contract", "tools", "workers cannot declare spawn_subagent");
10939
+ }
10940
+ if (executionKind === "orchestrator") {
10941
+ const delegates = allowedEntities.length > 0 || maxDepth > 0 || maxChildren > 0;
10942
+ if (delegates && (!Array.isArray(data.tools) || !data.tools.includes("spawn_subagent"))) {
10943
+ pushError(errors, "invalid-delegation-contract", "tools", "a delegating orchestrator must declare spawn_subagent");
10944
+ }
10945
+ if (delegates && (allowedEntities.length === 0 || maxDepth === 0 || maxChildren === 0)) {
10946
+ pushError(errors, "invalid-delegation-contract", "delegation", "delegation allowlist, depth, and child count must be enabled together");
10947
+ }
10948
+ }
10949
+ if (typeof data.name === "string" && allowedEntities.includes(data.name)) {
10950
+ pushError(errors, "invalid-delegation-contract", "delegation.allowed_entities", "an agent cannot delegate to itself");
10951
+ }
10866
10952
  return { ok: errors.length === 0, errors };
10867
10953
  }
10868
10954
  function validateAgentDefinition(definition) {
10869
10955
  const { body: _body, ...frontmatter } = definition;
10956
+ if (definition.schema_version !== 2) {
10957
+ const delegation = definition.delegation;
10958
+ const normalizedLegacyDefaults = definition.execution_kind === "worker" && definition.tool_scope === "static" && delegation?.allowed_entities.length === 0 && delegation.max_depth === 0 && delegation.max_children === 0;
10959
+ if (normalizedLegacyDefaults) {
10960
+ delete frontmatter.execution_kind;
10961
+ delete frontmatter.tool_scope;
10962
+ delete frontmatter.delegation;
10963
+ }
10964
+ }
10870
10965
  return validateAgentFrontmatter(frontmatter);
10871
10966
  }
10872
10967
  function buildAgentDefinition(data, body) {
@@ -10876,8 +10971,14 @@ function buildAgentDefinition(data, body) {
10876
10971
  ...typeof originRaw.sourceRef === "string" ? { sourceRef: originRaw.sourceRef } : {},
10877
10972
  ...typeof originRaw.generatedAt === "string" ? { generatedAt: originRaw.generatedAt } : {}
10878
10973
  };
10974
+ const delegationRaw = data.delegation;
10975
+ const delegation = delegationRaw === undefined ? { allowed_entities: [], max_depth: 0, max_children: 0 } : {
10976
+ allowed_entities: Array.isArray(delegationRaw.allowed_entities) ? [...delegationRaw.allowed_entities] : [],
10977
+ max_depth: Number(delegationRaw.max_depth ?? 0),
10978
+ max_children: Number(delegationRaw.max_children ?? 0)
10979
+ };
10879
10980
  return {
10880
- ...data.schema_version === 1 ? { schema_version: 1 } : {},
10981
+ ...data.schema_version === 1 || data.schema_version === 2 ? { schema_version: data.schema_version } : {},
10881
10982
  name: String(data.name),
10882
10983
  description: String(data.description),
10883
10984
  role: String(data.role),
@@ -10888,11 +10989,14 @@ function buildAgentDefinition(data, body) {
10888
10989
  stacks: Array.isArray(data.stacks) ? [...data.stacks] : [],
10889
10990
  output_contract: data.output_contract,
10890
10991
  isolation: data.isolation ?? "none",
10992
+ execution_kind: data.execution_kind ?? "worker",
10993
+ tool_scope: data.tool_scope ?? "static",
10994
+ delegation,
10891
10995
  ...origin !== undefined ? { origin } : {},
10892
10996
  body
10893
10997
  };
10894
10998
  }
10895
- var AGENT_NAME_PATTERN, AGENT_DESCRIPTION_MAX_LENGTH = 1024, AGENT_ROLE_MAX_LENGTH = 2000, AGENT_REQUIRED_FIELDS, AGENT_TOP_LEVEL_FIELDS, AGENT_OUTPUT_CONTRACT_VALUES, AGENT_ISOLATION_VALUES, AGENT_ORIGIN_KIND_VALUES, AGENT_ORIGIN_REQUIRED_FIELDS, AGENT_ORIGIN_FIELDS;
10999
+ var AGENT_NAME_PATTERN, AGENT_DESCRIPTION_MAX_LENGTH = 1024, AGENT_ROLE_MAX_LENGTH = 2000, AGENT_REQUIRED_FIELDS, AGENT_TOP_LEVEL_FIELDS, AGENT_OUTPUT_CONTRACT_VALUES, AGENT_ISOLATION_VALUES, AGENT_ORIGIN_KIND_VALUES, AGENT_ORIGIN_REQUIRED_FIELDS, AGENT_ORIGIN_FIELDS, AGENT_EXECUTION_KIND_VALUES, AGENT_TOOL_SCOPE_VALUES, AGENT_DELEGATION_REQUIRED_FIELDS, AGENT_DELEGATION_FIELDS;
10896
11000
  var init_schema = __esm(() => {
10897
11001
  init_model_tier();
10898
11002
  AGENT_NAME_PATTERN = /^[a-z][a-z0-9-]{1,63}$/;
@@ -10917,13 +11021,20 @@ var init_schema = __esm(() => {
10917
11021
  "stacks",
10918
11022
  "output_contract",
10919
11023
  "isolation",
10920
- "origin"
11024
+ "origin",
11025
+ "execution_kind",
11026
+ "tool_scope",
11027
+ "delegation"
10921
11028
  ];
10922
11029
  AGENT_OUTPUT_CONTRACT_VALUES = ["subagent-result"];
10923
11030
  AGENT_ISOLATION_VALUES = ["none", "worktree"];
10924
11031
  AGENT_ORIGIN_KIND_VALUES = ["authored", "generated", "imported", "learned"];
10925
11032
  AGENT_ORIGIN_REQUIRED_FIELDS = ["kind"];
10926
11033
  AGENT_ORIGIN_FIELDS = ["kind", "sourceRef", "generatedAt"];
11034
+ AGENT_EXECUTION_KIND_VALUES = ["worker", "orchestrator"];
11035
+ AGENT_TOOL_SCOPE_VALUES = ["static", "parent"];
11036
+ AGENT_DELEGATION_REQUIRED_FIELDS = ["allowed_entities", "max_depth", "max_children"];
11037
+ AGENT_DELEGATION_FIELDS = [...AGENT_DELEGATION_REQUIRED_FIELDS];
10927
11038
  });
10928
11039
 
10929
11040
  // src/agents/catalog.ts
@@ -11465,6 +11576,7 @@ function containsBaselineNearCopy(body) {
11465
11576
  return false;
11466
11577
  }
11467
11578
  function canonicalDefinitionSource(definition) {
11579
+ const delegation = definition.delegation ?? { allowed_entities: [], max_depth: 0, max_children: 0 };
11468
11580
  return JSON.stringify({
11469
11581
  schema_version: definition.schema_version ?? null,
11470
11582
  name: definition.name,
@@ -11477,6 +11589,13 @@ function canonicalDefinitionSource(definition) {
11477
11589
  stacks: [...definition.stacks],
11478
11590
  output_contract: definition.output_contract,
11479
11591
  isolation: definition.isolation,
11592
+ execution_kind: definition.execution_kind ?? "worker",
11593
+ tool_scope: definition.tool_scope ?? "static",
11594
+ delegation: {
11595
+ allowed_entities: [...delegation.allowed_entities],
11596
+ max_depth: delegation.max_depth,
11597
+ max_children: delegation.max_children
11598
+ },
11480
11599
  origin: definition.origin ?? null,
11481
11600
  body: definition.body
11482
11601
  });
@@ -11560,6 +11679,9 @@ function compileKeryxShell(definition, header) {
11560
11679
  profile: policyResolution.resolution.profileName,
11561
11680
  toolAllowlist: [...definition.tools],
11562
11681
  isolation: definition.isolation,
11682
+ executionKind: definition.execution_kind ?? "worker",
11683
+ toolScope: definition.tool_scope ?? "static",
11684
+ delegation: definition.delegation ?? { allowed_entities: [], max_depth: 0, max_children: 0 },
11563
11685
  enforcement: KERYX_SHELL_ENFORCEMENT
11564
11686
  }
11565
11687
  }
@@ -11605,7 +11727,8 @@ ${header}
11605
11727
  supportLevel: "native",
11606
11728
  relativePath: `.claude/agents/${definition.name}.md`,
11607
11729
  content: finalizeAgentContentHash("md", draft),
11608
- droppedTools: [...droppedTools, ...strippedForPolicy]
11730
+ droppedTools: [...droppedTools, ...strippedForPolicy],
11731
+ unsupportedConstraints: definition.schema_version === 2 ? ["executionKind", "toolScope", "delegation"] : []
11609
11732
  };
11610
11733
  }
11611
11734
  function tomlString(value) {
@@ -11644,7 +11767,8 @@ function renderCodexExport(definition, header) {
11644
11767
  supportLevel: "adapter",
11645
11768
  relativePath: `.codex/agents/${definition.name}.toml`,
11646
11769
  content: finalizeAgentContentHash("toml", draft),
11647
- droppedTools: []
11770
+ droppedTools: [],
11771
+ unsupportedConstraints: definition.schema_version === 2 ? ["executionKind", "toolScope", "delegation"] : []
11648
11772
  }
11649
11773
  };
11650
11774
  }
@@ -11670,7 +11794,8 @@ ${header}`;
11670
11794
  supportLevel: "adapter",
11671
11795
  relativePath: `.kiro/agents/${definition.name}.json`,
11672
11796
  content: finalizeAgentContentHash("kiro-json", draft),
11673
- droppedTools: [...droppedTools, ...strippedForPolicy]
11797
+ droppedTools: [...droppedTools, ...strippedForPolicy],
11798
+ unsupportedConstraints: definition.schema_version === 2 ? ["executionKind", "toolScope", "delegation"] : []
11674
11799
  }
11675
11800
  };
11676
11801
  }
@@ -11708,7 +11833,8 @@ ${header}
11708
11833
  supportLevel: "adapter",
11709
11834
  relativePath: `.opencode/agents/${definition.name}.md`,
11710
11835
  content: finalizeAgentContentHash("md", draft),
11711
- droppedTools
11836
+ droppedTools,
11837
+ unsupportedConstraints: definition.schema_version === 2 ? ["executionKind", "toolScope", "delegation"] : []
11712
11838
  }
11713
11839
  };
11714
11840
  }
@@ -11777,7 +11903,8 @@ var init_compile = __esm(() => {
11777
11903
  KERYX_SHELL_ENFORCEMENT = {
11778
11904
  enforced: ["mode"],
11779
11905
  advisory: ["toolAllowlist", "isolation"],
11780
- note: "spawn_subagent enforces only `mode` (read_only vs general) as of v1 \u2014 see " + "src/harness/tool/builtin/spawn-subagent-tool.ts's mode-to-tools construction. " + "`general` mode currently grants the SAME tool set as `read_only` (the read-only " + "+ metaproject builtin tools; still no shell_exec, apply_patch, web_fetch or " + 'web_search \u2014 "v1 general: still no shell_exec", parent owns mutations). ' + "toolAllowlist and isolation are carried here for a future dispatcher to read " + "but are NOT enforced by spawn_subagent today; nothing is silently dropped (every " + "field lands in input or here), but only `mode` actually constrains the child."
11906
+ unsupported: ["executionKind", "toolScope", "delegation"],
11907
+ note: "spawn_subagent enforces only `mode` (read_only vs general) as of v1 \u2014 see " + "src/harness/tool/builtin/spawn-subagent-tool.ts's mode-to-tools construction. " + "`general` mode currently grants the SAME tool set as `read_only` (the read-only " + "+ metaproject builtin tools; still no shell_exec, apply_patch, web_fetch or " + 'web_search \u2014 "v1 general: still no shell_exec", parent owns mutations). ' + "toolAllowlist and isolation are carried here for a future dispatcher to read " + "but are NOT enforced by spawn_subagent today; nothing is silently dropped (every " + "field lands in input or here), but only `mode` actually constrains the child. " + "V2 executionKind, toolScope, and delegation are recorded as unsupported until " + "the durable review controller performs admission and tool rebinding."
11781
11908
  };
11782
11909
  BASELINE_WORDS = PROMPT_DEFENSE_BASELINE.split(/\s+/).filter((w) => w.length > 0);
11783
11910
  BASELINE_NGRAMS = ngramsOf(BASELINE_WORDS, BASELINE_NGRAM_WORDS);
@@ -11975,6 +12102,7 @@ ${headerResult.header}
11975
12102
  supportLevel,
11976
12103
  relativePath: hostResult.relativePath,
11977
12104
  droppedTools: hostResult.droppedTools,
12105
+ unsupportedConstraints: hostResult.unsupportedConstraints,
11978
12106
  action: "refuse-unmanaged",
11979
12107
  reason: safetyReason
11980
12108
  };
@@ -11988,6 +12116,7 @@ ${headerResult.header}
11988
12116
  relativePath: hostResult.relativePath,
11989
12117
  content: hostResult.content,
11990
12118
  droppedTools: hostResult.droppedTools,
12119
+ unsupportedConstraints: hostResult.unsupportedConstraints,
11991
12120
  action: decided.action,
11992
12121
  ...decided.reason !== undefined ? { reason: decided.reason } : {}
11993
12122
  };