@aaac/runtime 0.1.53 → 0.1.55

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 (36) hide show
  1. package/dist/adapters/adk-sdk.d.ts +1 -1
  2. package/dist/adapters/adk-sdk.js +1 -1
  3. package/dist/adapters/claude-agent-sdk.d.ts +1 -1
  4. package/dist/adapters/mock.d.ts +1 -1
  5. package/dist/adapters/openai-agents-sdk.d.ts +1 -1
  6. package/dist/{chunk-YZQRSVDZ.js → chunk-3H3PVPPF.js} +198 -4
  7. package/dist/chunk-3H3PVPPF.js.map +1 -0
  8. package/dist/chunk-LDCQZPDG.js +11 -0
  9. package/dist/chunk-LDCQZPDG.js.map +1 -0
  10. package/dist/{chunk-M3GJAHLX.js → chunk-N4KNGDYY.js} +343 -28
  11. package/dist/chunk-N4KNGDYY.js.map +1 -0
  12. package/dist/{chunk-EH5VFZYJ.js → chunk-NMX4C6LC.js} +6 -2
  13. package/dist/chunk-NMX4C6LC.js.map +1 -0
  14. package/dist/{chunk-KNYJV2Q6.js → chunk-QVH5KKBR.js} +5 -9
  15. package/dist/chunk-QVH5KKBR.js.map +1 -0
  16. package/dist/claude-bundles/full.js +223 -217
  17. package/dist/claude-bundles/lean.js +5 -5
  18. package/dist/generator/index.d.ts +2 -286
  19. package/dist/generator/index.js +1 -1
  20. package/dist/index-LqEvaRk-.d.ts +299 -0
  21. package/dist/index.d.ts +29 -17
  22. package/dist/index.js +118 -436
  23. package/dist/index.js.map +1 -1
  24. package/dist/lib/claude-native/hooks-lite.d.ts +18 -325
  25. package/dist/lib/claude-native/hooks-lite.js +8 -2
  26. package/dist/lib/claude-native/index.d.ts +153 -20
  27. package/dist/lib/claude-native/index.js +162 -37
  28. package/dist/lib/claude-native/index.js.map +1 -1
  29. package/dist/{navigation-context-xrReMkTn.d.ts → navigation-context-D_E1NIUf.d.ts} +11 -3
  30. package/dist/{task-runner-Sez_CXcD.d.ts → task-runner-DfIEorkU.d.ts} +21 -9
  31. package/dist/workspace-pre-tool-use-C6nidc0q.d.ts +333 -0
  32. package/package.json +1 -1
  33. package/dist/chunk-EH5VFZYJ.js.map +0 -1
  34. package/dist/chunk-KNYJV2Q6.js.map +0 -1
  35. package/dist/chunk-M3GJAHLX.js.map +0 -1
  36. package/dist/chunk-YZQRSVDZ.js.map +0 -1
@@ -6,9 +6,12 @@ import {
6
6
  emitSubagentClose,
7
7
  emitSubagentOpen
8
8
  } from "./chunk-KXGUWBGK.js";
9
+ import {
10
+ buildGuardrailContext
11
+ } from "./chunk-3H3PVPPF.js";
9
12
  import {
10
13
  pluginRegistry
11
- } from "./chunk-EH5VFZYJ.js";
14
+ } from "./chunk-NMX4C6LC.js";
12
15
 
13
16
  // src/lib/candidate-agents.ts
14
17
  function renderAgentSystemPrompt(agent) {
@@ -1363,9 +1366,68 @@ Please re-execute the entire task.`
1363
1366
  }
1364
1367
  }
1365
1368
 
1366
- // src/lib/dsl-context.ts
1369
+ // src/lib/artifact-resolver.ts
1367
1370
  import { readFile } from "fs/promises";
1368
1371
  import YAML from "yaml";
1372
+ async function loadArtifactRegistry(source) {
1373
+ let content;
1374
+ try {
1375
+ content = await readFile(source, "utf8");
1376
+ } catch {
1377
+ throw new Error(
1378
+ `Failed to read artifact registry: ${source} (declared by the project manifest's \`artifacts:\`).`
1379
+ );
1380
+ }
1381
+ let parsed;
1382
+ try {
1383
+ parsed = YAML.parse(content);
1384
+ } catch (err) {
1385
+ throw new Error(
1386
+ `Invalid YAML in artifact registry ${source}: ${err.message}`
1387
+ );
1388
+ }
1389
+ const artifacts = parsed?.artifacts;
1390
+ if (artifacts && typeof artifacts === "object" && !Array.isArray(artifacts)) {
1391
+ return artifacts;
1392
+ }
1393
+ return {};
1394
+ }
1395
+ async function resolveArtifacts(options) {
1396
+ if (!options.artifactBinding) {
1397
+ return { dsl: options.dsl, diagnostics: [] };
1398
+ }
1399
+ const { resolveArtifactBinding } = await import("agent-contracts");
1400
+ const registry = await loadArtifactRegistry(options.artifactBinding.source);
1401
+ const dslArtifacts = options.dsl.artifacts ?? {};
1402
+ const mappings = options.artifactBinding.mappings;
1403
+ const claimed = new Set(
1404
+ Object.keys(dslArtifacts).map((id) => mappings?.[id] ?? id)
1405
+ );
1406
+ const composed = Object.keys(registry).filter(
1407
+ (id) => !claimed.has(id) && !(id in dslArtifacts)
1408
+ );
1409
+ const bound = resolveArtifactBinding(
1410
+ {
1411
+ ...Object.fromEntries(composed.map((id) => [id, {}])),
1412
+ ...dslArtifacts
1413
+ },
1414
+ { artifacts: registry },
1415
+ mappings,
1416
+ options.paths
1417
+ );
1418
+ return {
1419
+ dsl: { ...options.dsl, artifacts: bound.artifacts },
1420
+ diagnostics: bound.diagnostics.map((d) => ({
1421
+ path: d.rule,
1422
+ message: d.message,
1423
+ severity: d.severity
1424
+ }))
1425
+ };
1426
+ }
1427
+
1428
+ // src/lib/dsl-context.ts
1429
+ import { readFile as readFile2 } from "fs/promises";
1430
+ import YAML2 from "yaml";
1369
1431
  var DslValidationError = class extends Error {
1370
1432
  missing;
1371
1433
  constructor(missing) {
@@ -1464,15 +1526,6 @@ function buildHandoffSchemas(handoffTypes) {
1464
1526
  }
1465
1527
  return schemas;
1466
1528
  }
1467
- function buildGuardrailRulesFromDsl(dsl) {
1468
- const raw = dsl._guardrailRules;
1469
- if (!raw) return void 0;
1470
- return {
1471
- commandRules: raw.commandRules ?? [],
1472
- fileRules: raw.fileRules ?? [],
1473
- contentRules: raw.contentRules ?? []
1474
- };
1475
- }
1476
1529
  function buildRegistriesFromDsl(dsl) {
1477
1530
  const agents = dsl.agents ?? {};
1478
1531
  const tasks = dsl.tasks ?? {};
@@ -1540,8 +1593,8 @@ async function loadDslContext(options) {
1540
1593
  let dsl;
1541
1594
  if (options.projectDslPath) {
1542
1595
  const { resolve: resolveDsl, mergeDsl, expandDefaults } = await import("agent-contracts");
1543
- const raw = await readFile(options.projectDslPath, "utf8");
1544
- const projectData = YAML.parse(raw);
1596
+ const raw = await readFile2(options.projectDslPath, "utf8");
1597
+ const projectData = YAML2.parse(raw);
1545
1598
  if (projectData.extends === "/$embedded/") {
1546
1599
  const { extends: _extends, ...projectOverrides } = projectData;
1547
1600
  const merged = mergeDsl(options.embeddedDsl, projectOverrides);
@@ -1558,8 +1611,264 @@ async function loadDslContext(options) {
1558
1611
  validateRequiredEntities(dsl, options.requiredEntities);
1559
1612
  }
1560
1613
  const registries = buildRegistriesFromDsl(dsl);
1561
- const guardrailRules = buildGuardrailRulesFromDsl(dsl);
1562
- return { registries, dsl, guardrailRules };
1614
+ return { registries, dsl };
1615
+ }
1616
+
1617
+ // src/lib/bound-resolver.ts
1618
+ import { readFile as readFile3 } from "fs/promises";
1619
+ import YAML3 from "yaml";
1620
+ function getEffectiveGuardrailIds(dsl, agentId) {
1621
+ const ids = /* @__PURE__ */ new Set();
1622
+ const agents = dsl.agents ?? {};
1623
+ const agent = agents[agentId];
1624
+ if (agent) {
1625
+ for (const ref of agent.guardrails ?? []) {
1626
+ ids.add(ref);
1627
+ }
1628
+ }
1629
+ const guardrails = dsl.guardrails ?? {};
1630
+ for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
1631
+ if (guardrail.scope?.agents?.includes(agentId)) {
1632
+ ids.add(guardrailId);
1633
+ }
1634
+ }
1635
+ return ids;
1636
+ }
1637
+ function guardrailCheckToCommandRule(c) {
1638
+ return {
1639
+ guardrail_id: c.guardrail_id,
1640
+ pattern: c.pattern,
1641
+ action: c.action,
1642
+ message: c.message
1643
+ };
1644
+ }
1645
+ function guardrailCheckToFileRule(c) {
1646
+ return {
1647
+ guardrail_id: c.guardrail_id,
1648
+ pattern: c.pattern,
1649
+ action: c.action,
1650
+ message: c.message,
1651
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
1652
+ };
1653
+ }
1654
+ function guardrailCheckToContentRule(c) {
1655
+ return {
1656
+ guardrail_id: c.guardrail_id,
1657
+ pattern: c.pattern,
1658
+ action: c.action,
1659
+ message: c.message,
1660
+ ...c.file_glob ? { file_glob: c.file_glob } : {},
1661
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
1662
+ };
1663
+ }
1664
+ function guardrailContextToRuleData(ctx, effectiveIds) {
1665
+ const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
1666
+ return {
1667
+ commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
1668
+ fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
1669
+ contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
1670
+ };
1671
+ }
1672
+ function buildPerAgentGuardrails(dsl, guardrailCtx) {
1673
+ const perAgent = /* @__PURE__ */ new Map();
1674
+ const agents = dsl.agents ?? {};
1675
+ for (const agentId of Object.keys(agents)) {
1676
+ const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
1677
+ const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
1678
+ if (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) {
1679
+ perAgent.set(agentId, rules);
1680
+ }
1681
+ }
1682
+ return perAgent;
1683
+ }
1684
+ var EMPTY_GUARDRAIL_CONTEXT = {
1685
+ commandChecks: [],
1686
+ fileChecks: [],
1687
+ contentChecks: [],
1688
+ allChecks: [],
1689
+ hasGuardrails: false
1690
+ };
1691
+ async function resolveGuardrailContext(dsl, bindingPaths, activeGuardrailPolicy, options) {
1692
+ if (!bindingPaths || bindingPaths.length === 0) {
1693
+ return EMPTY_GUARDRAIL_CONTEXT;
1694
+ }
1695
+ const merged = {
1696
+ commandChecks: [],
1697
+ fileChecks: [],
1698
+ contentChecks: [],
1699
+ allChecks: [],
1700
+ hasGuardrails: false
1701
+ };
1702
+ for (const bindingPath of bindingPaths) {
1703
+ let raw;
1704
+ try {
1705
+ raw = await readFile3(bindingPath, "utf8");
1706
+ } catch (err) {
1707
+ if (options?.skipMissing && err.code === "ENOENT") continue;
1708
+ throw err;
1709
+ }
1710
+ const binding = YAML3.parse(raw);
1711
+ const ctx = buildGuardrailContext(dsl, binding, activeGuardrailPolicy);
1712
+ merged.commandChecks.push(...ctx.commandChecks);
1713
+ merged.fileChecks.push(...ctx.fileChecks);
1714
+ merged.contentChecks.push(...ctx.contentChecks);
1715
+ merged.allChecks.push(...ctx.allChecks);
1716
+ merged.hasGuardrails = merged.hasGuardrails || ctx.hasGuardrails;
1717
+ }
1718
+ return merged;
1719
+ }
1720
+ function hasGuardrailRules(rules) {
1721
+ return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
1722
+ }
1723
+ function mergeDerivedWithAgentTools(derivedTools, agentToolIds, allToolchains) {
1724
+ const merged = /* @__PURE__ */ new Map();
1725
+ for (const tc of derivedTools) {
1726
+ merged.set(tc.id, tc);
1727
+ }
1728
+ for (const toolId of agentToolIds) {
1729
+ if (!merged.has(toolId)) {
1730
+ if (allToolchains[toolId]) {
1731
+ merged.set(toolId, { ...allToolchains[toolId], source: "merged" });
1732
+ }
1733
+ } else {
1734
+ const existing = merged.get(toolId);
1735
+ merged.set(toolId, { ...existing, source: "merged" });
1736
+ }
1737
+ }
1738
+ return Array.from(merged.values());
1739
+ }
1740
+ function deriveToolchainsForAgents(dsl, toolchains) {
1741
+ const result = /* @__PURE__ */ new Map();
1742
+ const agents = dsl.agents ?? {};
1743
+ for (const [agentId, agent] of Object.entries(agents)) {
1744
+ const derivedTools = [];
1745
+ const canReadArtifacts = agent.can_read_artifacts ?? [];
1746
+ const canWriteArtifacts = agent.can_write_artifacts ?? [];
1747
+ const agentArtifacts = agent.artifacts;
1748
+ const readArtifacts = /* @__PURE__ */ new Set([
1749
+ ...canReadArtifacts,
1750
+ ...agentArtifacts?.consumes ?? []
1751
+ ]);
1752
+ const writeArtifacts = /* @__PURE__ */ new Set([
1753
+ ...canWriteArtifacts,
1754
+ ...agentArtifacts?.produces ?? []
1755
+ ]);
1756
+ for (const tc of Object.values(toolchains)) {
1757
+ let matched = false;
1758
+ for (const artifactId of tc.artifacts.consumes) {
1759
+ if (readArtifacts.has(artifactId) || writeArtifacts.has(artifactId)) {
1760
+ matched = true;
1761
+ break;
1762
+ }
1763
+ }
1764
+ if (!matched) {
1765
+ for (const artifactId of tc.artifacts.produces) {
1766
+ if (writeArtifacts.has(artifactId)) {
1767
+ matched = true;
1768
+ break;
1769
+ }
1770
+ }
1771
+ }
1772
+ if (matched) {
1773
+ derivedTools.push(tc);
1774
+ }
1775
+ }
1776
+ if (derivedTools.length > 0) {
1777
+ const agentTools = agent.can_execute_tools ?? [];
1778
+ const mergedTools = mergeDerivedWithAgentTools(
1779
+ derivedTools,
1780
+ agentTools,
1781
+ toolchains
1782
+ );
1783
+ result.set(agentId, mergedTools);
1784
+ }
1785
+ }
1786
+ return result;
1787
+ }
1788
+ var BoundResolver = class {
1789
+ cache = /* @__PURE__ */ new Map();
1790
+ /**
1791
+ * Resolve binding + policy in one pass. Results are cached by component id.
1792
+ */
1793
+ async resolve(opts) {
1794
+ const cached = this.cache.get(opts.id);
1795
+ if (cached) return cached;
1796
+ const diagnostics = [];
1797
+ let dsl;
1798
+ if (opts.embeddedDsl) {
1799
+ dsl = opts.embeddedDsl;
1800
+ } else if (opts.dslPath) {
1801
+ const { resolve: resolveDsl } = await import("agent-contracts");
1802
+ const result = await resolveDsl(opts.dslPath);
1803
+ dsl = result.data;
1804
+ } else {
1805
+ throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
1806
+ }
1807
+ if (opts.artifactBinding) {
1808
+ const bound = await resolveArtifacts({
1809
+ dsl,
1810
+ artifactBinding: opts.artifactBinding,
1811
+ paths: opts.paths
1812
+ });
1813
+ dsl = bound.dsl;
1814
+ diagnostics.push(...bound.diagnostics);
1815
+ }
1816
+ let guardrailCtx;
1817
+ guardrailCtx = await resolveGuardrailContext(
1818
+ dsl,
1819
+ opts.bindingPaths,
1820
+ opts.activeGuardrailPolicy
1821
+ );
1822
+ const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
1823
+ let toolchains;
1824
+ let toolchainsByAgent;
1825
+ if (opts.toolchainContractsPath) {
1826
+ const toolchainPkg = "@aaac/toolchain";
1827
+ const mod = await import(
1828
+ /* webpackIgnore: true */
1829
+ toolchainPkg
1830
+ );
1831
+ const tcDoc = await mod.loadToolchainContracts(opts.toolchainContractsPath);
1832
+ toolchains = {};
1833
+ for (const [id, tc] of Object.entries(tcDoc.toolchains)) {
1834
+ toolchains[id] = {
1835
+ id,
1836
+ kind: tc.kind,
1837
+ description: tc.description,
1838
+ module: tc.module,
1839
+ command: tc.command,
1840
+ cli_contract: tc.cli_contract,
1841
+ component_contract: tc.component_contract,
1842
+ artifacts: {
1843
+ consumes: [...tc.artifacts.consumes],
1844
+ produces: [...tc.artifacts.produces]
1845
+ },
1846
+ operations: tc.operations ? [...tc.operations] : void 0,
1847
+ source: "toolchain-contracts"
1848
+ };
1849
+ }
1850
+ toolchainsByAgent = deriveToolchainsForAgents(dsl, toolchains);
1851
+ }
1852
+ const component = {
1853
+ id: opts.id,
1854
+ dsl,
1855
+ registries: buildRegistriesFromDsl(dsl),
1856
+ guardrails: { perAgent },
1857
+ diagnostics,
1858
+ ...toolchains ? { toolchains } : {},
1859
+ ...toolchainsByAgent ? { toolchainsByAgent } : {}
1860
+ };
1861
+ this.cache.set(opts.id, component);
1862
+ return component;
1863
+ }
1864
+ /** Clear cached components (e.g. for testing). */
1865
+ clearCache() {
1866
+ this.cache.clear();
1867
+ }
1868
+ };
1869
+ function getGuardrailRulesForAgent(component, agentId) {
1870
+ const perAgent = component.guardrails.perAgent.get(agentId);
1871
+ return perAgent && hasGuardrailRules(perAgent) ? perAgent : void 0;
1563
1872
  }
1564
1873
 
1565
1874
  // src/lib/navigation-context.ts
@@ -1584,19 +1893,13 @@ async function buildNavigationContext(options) {
1584
1893
  throw new Error("buildNavigationContext requires embeddedDsl or projectDslPath");
1585
1894
  }
1586
1895
  if (options.artifactBinding) {
1587
- const { resolveBound } = await import("agent-contracts");
1588
- const boundResult = await resolveBound(dsl, {
1896
+ const bound = await resolveArtifacts({
1897
+ dsl,
1589
1898
  artifactBinding: options.artifactBinding,
1590
1899
  paths: options.paths
1591
1900
  });
1592
- dsl = boundResult.data;
1593
- for (const d of boundResult.diagnostics) {
1594
- diagnostics.push({
1595
- path: d.rule,
1596
- message: d.message,
1597
- severity: d.severity
1598
- });
1599
- }
1901
+ dsl = bound.dsl;
1902
+ diagnostics.push(...bound.diagnostics);
1600
1903
  }
1601
1904
  const { validateSchema, buildNavigationIndex } = await import("agent-contracts");
1602
1905
  const validation = validateSchema(dsl);
@@ -1610,7 +1913,12 @@ async function buildNavigationContext(options) {
1610
1913
  const navigationIndex = buildNavigationIndex(
1611
1914
  validation.data ?? dsl
1612
1915
  );
1613
- const guardrailRules = buildGuardrailRulesFromDsl(dsl);
1916
+ const guardrailCtx = await resolveGuardrailContext(
1917
+ dsl,
1918
+ options.bindingPaths,
1919
+ options.activeGuardrailPolicy
1920
+ );
1921
+ const guardrailRules = guardrailCtx.hasGuardrails ? guardrailContextToRuleData(guardrailCtx) : void 0;
1614
1922
  return { dsl, navigationIndex, guardrailRules, diagnostics };
1615
1923
  }
1616
1924
 
@@ -1639,10 +1947,17 @@ export {
1639
1947
  extractStructuredResult,
1640
1948
  buildRetryFollowUp,
1641
1949
  runTask,
1950
+ resolveArtifacts,
1642
1951
  DslValidationError,
1643
- buildGuardrailRulesFromDsl,
1644
1952
  buildRegistriesFromDsl,
1645
1953
  loadDslContext,
1954
+ getEffectiveGuardrailIds,
1955
+ guardrailContextToRuleData,
1956
+ buildPerAgentGuardrails,
1957
+ resolveGuardrailContext,
1958
+ deriveToolchainsForAgents,
1959
+ BoundResolver,
1960
+ getGuardrailRulesForAgent,
1646
1961
  buildNavigationContext
1647
1962
  };
1648
- //# sourceMappingURL=chunk-M3GJAHLX.js.map
1963
+ //# sourceMappingURL=chunk-N4KNGDYY.js.map