@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
package/dist/index.js CHANGED
@@ -2,14 +2,11 @@ import {
2
2
  buildSdkFunctionTools
3
3
  } from "./chunk-DBM5XN67.js";
4
4
  import {
5
- buildGuardrailContext,
6
- loadProjectConfig
7
- } from "./chunk-YZQRSVDZ.js";
8
- import {
5
+ BoundResolver,
9
6
  DslValidationError,
10
7
  buildCandidateAgents,
11
- buildGuardrailRulesFromDsl,
12
8
  buildNavigationContext,
9
+ buildPerAgentGuardrails,
13
10
  buildRegistriesFromDsl,
14
11
  buildRetryFollowUp,
15
12
  buildSplitTaskPrompt,
@@ -17,12 +14,16 @@ import {
17
14
  collectAnalyzerToolIds,
18
15
  computeCostUsd,
19
16
  createAnalyzerBridge,
17
+ deriveToolchainsForAgents,
20
18
  emitProcessEdit,
21
19
  emitProcessTaskClose,
22
20
  emitProcessTaskOpen,
23
21
  emitProcessWorkflowClose,
24
22
  emitProcessWorkflowOpen,
25
23
  extractStructuredResult,
24
+ getEffectiveGuardrailIds,
25
+ getGuardrailRulesForAgent,
26
+ guardrailContextToRuleData,
26
27
  isContextPack,
27
28
  isFileEditTool,
28
29
  isNavigationIndex,
@@ -31,11 +32,13 @@ import {
31
32
  renderAnalyzerExplorationMandatePrompt,
32
33
  renderContextPackPrompt,
33
34
  renderNavigationIndexPrompt,
35
+ resolveArtifacts,
36
+ resolveGuardrailContext,
34
37
  runTask,
35
38
  shouldInjectAnalyzerExplorationMandate,
36
39
  zodSchemaToPromptDescription,
37
40
  zodSchemaToYamlExample
38
- } from "./chunk-M3GJAHLX.js";
41
+ } from "./chunk-N4KNGDYY.js";
39
42
  import {
40
43
  jsonSchemaToZod
41
44
  } from "./chunk-ET6TGQRT.js";
@@ -58,6 +61,14 @@ import {
58
61
  emitToolchainOpen,
59
62
  serializeObserverEmit
60
63
  } from "./chunk-KXGUWBGK.js";
64
+ import {
65
+ PROJECT_CONFIG_FILENAME,
66
+ loadProjectConfig,
67
+ loadWorkspaceMembers
68
+ } from "./chunk-3H3PVPPF.js";
69
+ import {
70
+ guardrailCacheKey
71
+ } from "./chunk-LDCQZPDG.js";
61
72
  import {
62
73
  PluginRegistry,
63
74
  createGuardrailHooks,
@@ -67,7 +78,7 @@ import {
67
78
  getWarnings,
68
79
  hasBlockingViolation,
69
80
  pluginRegistry
70
- } from "./chunk-EH5VFZYJ.js";
81
+ } from "./chunk-NMX4C6LC.js";
71
82
  import {
72
83
  __commonJS,
73
84
  __require,
@@ -6180,7 +6191,8 @@ function resolveInvocation(invocation) {
6180
6191
  observer: invocation.observer,
6181
6192
  toolchain: invocation.toolchain,
6182
6193
  libraryTools: invocation.libraryTools,
6183
- resolveModelMeta: invocation.resolveModelMeta
6194
+ resolveModelMeta: invocation.resolveModelMeta,
6195
+ perAgentAdapters: invocation.perAgentAdapters
6184
6196
  }
6185
6197
  };
6186
6198
  }
@@ -6464,13 +6476,12 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
6464
6476
  }
6465
6477
  const batchResults = await Promise.all(ready.map(async (i) => {
6466
6478
  const step = workflow.steps[i];
6467
- const modelClass = step.type === "delegate" || step.type === "evaluate" ? registries?.taskRegistry?.[step.task]?.model_class : void 0;
6479
+ const stepTask = step.type === "delegate" || step.type === "evaluate" ? registries?.taskRegistry?.[step.task] : void 0;
6480
+ const modelClass = stepTask?.model_class;
6481
+ const stepAgentId = options.perAgentAdapters ? stepTask?.target_agent : void 0;
6468
6482
  let stepAdapter;
6469
- if (ready.length > 1 && adapterFactory) {
6470
- const result = adapterFactory(modelClass);
6471
- stepAdapter = result && typeof result.then === "function" ? await result : result;
6472
- } else if (modelClass && adapterFactory) {
6473
- const result = adapterFactory(modelClass);
6483
+ if (adapterFactory && (ready.length > 1 || modelClass || stepAgentId)) {
6484
+ const result = adapterFactory(modelClass, stepAgentId);
6474
6485
  stepAdapter = result && typeof result.then === "function" ? await result : result;
6475
6486
  } else {
6476
6487
  stepAdapter = primaryAdapter;
@@ -6803,258 +6814,6 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
6803
6814
  });
6804
6815
  }
6805
6816
 
6806
- // src/lib/bound-resolver.ts
6807
- import { readFile as readFile2 } from "fs/promises";
6808
- import YAML from "yaml";
6809
- function getEffectiveGuardrailIds(dsl, agentId) {
6810
- const ids = /* @__PURE__ */ new Set();
6811
- const agents = dsl.agents ?? {};
6812
- const agent = agents[agentId];
6813
- if (agent) {
6814
- for (const ref of agent.guardrails ?? []) {
6815
- ids.add(ref);
6816
- }
6817
- }
6818
- const guardrails = dsl.guardrails ?? {};
6819
- for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
6820
- if (guardrail.scope?.agents?.includes(agentId)) {
6821
- ids.add(guardrailId);
6822
- }
6823
- }
6824
- return ids;
6825
- }
6826
- function guardrailCheckToCommandRule(c) {
6827
- return {
6828
- guardrail_id: c.guardrail_id,
6829
- pattern: c.pattern,
6830
- action: c.action,
6831
- message: c.message
6832
- };
6833
- }
6834
- function guardrailCheckToFileRule(c) {
6835
- return {
6836
- guardrail_id: c.guardrail_id,
6837
- pattern: c.pattern,
6838
- action: c.action,
6839
- message: c.message,
6840
- ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
6841
- };
6842
- }
6843
- function guardrailCheckToContentRule(c) {
6844
- return {
6845
- guardrail_id: c.guardrail_id,
6846
- pattern: c.pattern,
6847
- action: c.action,
6848
- message: c.message,
6849
- ...c.file_glob ? { file_glob: c.file_glob } : {},
6850
- ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
6851
- };
6852
- }
6853
- function guardrailContextToRuleData(ctx, effectiveIds) {
6854
- const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
6855
- return {
6856
- commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
6857
- fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
6858
- contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
6859
- };
6860
- }
6861
- function buildPerAgentGuardrails(dsl, guardrailCtx) {
6862
- const perAgent = /* @__PURE__ */ new Map();
6863
- const agents = dsl.agents ?? {};
6864
- for (const agentId of Object.keys(agents)) {
6865
- const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
6866
- const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
6867
- if (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) {
6868
- perAgent.set(agentId, rules);
6869
- }
6870
- }
6871
- return perAgent;
6872
- }
6873
- function hasGuardrailRules(rules) {
6874
- return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
6875
- }
6876
- function mergeDerivedWithAgentTools(derivedTools, agentToolIds, allToolchains) {
6877
- const merged = /* @__PURE__ */ new Map();
6878
- for (const tc of derivedTools) {
6879
- merged.set(tc.id, tc);
6880
- }
6881
- for (const toolId of agentToolIds) {
6882
- if (!merged.has(toolId)) {
6883
- if (allToolchains[toolId]) {
6884
- merged.set(toolId, { ...allToolchains[toolId], source: "merged" });
6885
- }
6886
- } else {
6887
- const existing = merged.get(toolId);
6888
- merged.set(toolId, { ...existing, source: "merged" });
6889
- }
6890
- }
6891
- return Array.from(merged.values());
6892
- }
6893
- function deriveToolchainsForAgents(dsl, toolchains) {
6894
- const result = /* @__PURE__ */ new Map();
6895
- const agents = dsl.agents ?? {};
6896
- for (const [agentId, agent] of Object.entries(agents)) {
6897
- const derivedTools = [];
6898
- const canReadArtifacts = agent.can_read_artifacts ?? [];
6899
- const canWriteArtifacts = agent.can_write_artifacts ?? [];
6900
- const agentArtifacts = agent.artifacts;
6901
- const readArtifacts = /* @__PURE__ */ new Set([
6902
- ...canReadArtifacts,
6903
- ...agentArtifacts?.consumes ?? []
6904
- ]);
6905
- const writeArtifacts = /* @__PURE__ */ new Set([
6906
- ...canWriteArtifacts,
6907
- ...agentArtifacts?.produces ?? []
6908
- ]);
6909
- for (const tc of Object.values(toolchains)) {
6910
- let matched = false;
6911
- for (const artifactId of tc.artifacts.consumes) {
6912
- if (readArtifacts.has(artifactId) || writeArtifacts.has(artifactId)) {
6913
- matched = true;
6914
- break;
6915
- }
6916
- }
6917
- if (!matched) {
6918
- for (const artifactId of tc.artifacts.produces) {
6919
- if (writeArtifacts.has(artifactId)) {
6920
- matched = true;
6921
- break;
6922
- }
6923
- }
6924
- }
6925
- if (matched) {
6926
- derivedTools.push(tc);
6927
- }
6928
- }
6929
- if (derivedTools.length > 0) {
6930
- const agentTools = agent.can_execute_tools ?? [];
6931
- const mergedTools = mergeDerivedWithAgentTools(
6932
- derivedTools,
6933
- agentTools,
6934
- toolchains
6935
- );
6936
- result.set(agentId, mergedTools);
6937
- }
6938
- }
6939
- return result;
6940
- }
6941
- var BoundResolver = class {
6942
- cache = /* @__PURE__ */ new Map();
6943
- /**
6944
- * Resolve binding + policy in one pass. Results are cached by component id.
6945
- */
6946
- async resolve(opts) {
6947
- const cached = this.cache.get(opts.id);
6948
- if (cached) return cached;
6949
- const diagnostics = [];
6950
- let dsl;
6951
- if (opts.embeddedDsl) {
6952
- dsl = opts.embeddedDsl;
6953
- } else if (opts.dslPath) {
6954
- const { resolve: resolveDsl } = await import("agent-contracts");
6955
- const result = await resolveDsl(opts.dslPath);
6956
- dsl = result.data;
6957
- } else {
6958
- throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
6959
- }
6960
- if (opts.artifactBinding) {
6961
- const { resolveBound } = await import("agent-contracts");
6962
- const boundResult = await resolveBound(dsl, {
6963
- artifactBinding: opts.artifactBinding,
6964
- paths: opts.paths
6965
- });
6966
- dsl = boundResult.data;
6967
- for (const d of boundResult.diagnostics) {
6968
- diagnostics.push({
6969
- path: d.rule,
6970
- message: d.message,
6971
- severity: d.severity
6972
- });
6973
- }
6974
- }
6975
- let guardrailCtx = {
6976
- commandChecks: [],
6977
- fileChecks: [],
6978
- contentChecks: [],
6979
- allChecks: [],
6980
- hasGuardrails: false
6981
- };
6982
- if (opts.bindingPaths && opts.bindingPaths.length > 0) {
6983
- for (const bindingPath of opts.bindingPaths) {
6984
- const raw = await readFile2(bindingPath, "utf8");
6985
- const binding = YAML.parse(raw);
6986
- guardrailCtx = buildGuardrailContext(
6987
- dsl,
6988
- binding,
6989
- opts.activeGuardrailPolicy
6990
- );
6991
- }
6992
- }
6993
- const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
6994
- let toolchains;
6995
- let toolchainsByAgent;
6996
- if (opts.toolchainContractsPath) {
6997
- const toolchainPkg = "@aaac/toolchain";
6998
- const mod = await import(
6999
- /* webpackIgnore: true */
7000
- toolchainPkg
7001
- );
7002
- const tcDoc = await mod.loadToolchainContracts(opts.toolchainContractsPath);
7003
- toolchains = {};
7004
- for (const [id, tc] of Object.entries(tcDoc.toolchains)) {
7005
- toolchains[id] = {
7006
- id,
7007
- kind: tc.kind,
7008
- description: tc.description,
7009
- module: tc.module,
7010
- command: tc.command,
7011
- cli_contract: tc.cli_contract,
7012
- component_contract: tc.component_contract,
7013
- artifacts: {
7014
- consumes: [...tc.artifacts.consumes],
7015
- produces: [...tc.artifacts.produces]
7016
- },
7017
- operations: tc.operations ? [...tc.operations] : void 0,
7018
- source: "toolchain-contracts"
7019
- };
7020
- }
7021
- toolchainsByAgent = deriveToolchainsForAgents(dsl, toolchains);
7022
- }
7023
- const component = {
7024
- id: opts.id,
7025
- dsl,
7026
- registries: buildRegistriesFromDsl(dsl),
7027
- guardrails: { perAgent },
7028
- diagnostics,
7029
- ...toolchains ? { toolchains } : {},
7030
- ...toolchainsByAgent ? { toolchainsByAgent } : {}
7031
- };
7032
- this.cache.set(opts.id, component);
7033
- return component;
7034
- }
7035
- /** Clear cached components (e.g. for testing). */
7036
- clearCache() {
7037
- this.cache.clear();
7038
- }
7039
- };
7040
- function getGuardrailRulesForAgent(component, agentId, fallbackDsl) {
7041
- const perAgent = component.guardrails.perAgent.get(agentId);
7042
- if (perAgent && hasGuardrailRules(perAgent)) {
7043
- return perAgent;
7044
- }
7045
- if (fallbackDsl) {
7046
- const raw = fallbackDsl._guardrailRules;
7047
- if (raw) {
7048
- return {
7049
- commandRules: raw.commandRules ?? [],
7050
- fileRules: raw.fileRules ?? [],
7051
- contentRules: raw.contentRules ?? []
7052
- };
7053
- }
7054
- }
7055
- return void 0;
7056
- }
7057
-
7058
6817
  // src/lib/builder.ts
7059
6818
  function createRuntime(config) {
7060
6819
  return {
@@ -7314,7 +7073,7 @@ var InMemoryStore = class {
7314
7073
  };
7315
7074
 
7316
7075
  // src/lib/file-memory-store.ts
7317
- import { mkdir, readFile as readFile3, unlink, writeFile } from "fs/promises";
7076
+ import { mkdir, readFile as readFile2, unlink, writeFile } from "fs/promises";
7318
7077
  import { join as join3 } from "path";
7319
7078
  function resolveFilePath2(baseDir, ref) {
7320
7079
  const runId = ref.parent_run_id ?? "unknown";
@@ -7333,7 +7092,7 @@ var FileMemoryStore = class {
7333
7092
  async load(ref) {
7334
7093
  const filePath = resolveFilePath2(this.baseDir, ref);
7335
7094
  try {
7336
- const raw = await readFile3(filePath, "utf-8");
7095
+ const raw = await readFile2(filePath, "utf-8");
7337
7096
  return JSON.parse(raw);
7338
7097
  } catch (error) {
7339
7098
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -7356,7 +7115,7 @@ var FileMemoryStore = class {
7356
7115
  };
7357
7116
 
7358
7117
  // src/lib/agent-log-writer.ts
7359
- import { mkdir as mkdir2, readFile as readFile4, readdir as readdir2, stat, unlink as unlink2, writeFile as writeFile2, appendFile } from "fs/promises";
7118
+ import { mkdir as mkdir2, readFile as readFile3, readdir as readdir2, stat, unlink as unlink2, writeFile as writeFile2, appendFile } from "fs/promises";
7360
7119
  import { join as join4 } from "path";
7361
7120
  var AgentLogWriter = class {
7362
7121
  baseDir;
@@ -7380,7 +7139,7 @@ var AgentLogWriter = class {
7380
7139
  async readRunLog(runId) {
7381
7140
  const filePath = join4(this.baseDir, "runs", `${runId}.jsonl`);
7382
7141
  try {
7383
- const raw = await readFile4(filePath, "utf-8");
7142
+ const raw = await readFile3(filePath, "utf-8");
7384
7143
  return raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
7385
7144
  } catch (error) {
7386
7145
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -7398,7 +7157,7 @@ var AgentLogWriter = class {
7398
7157
  async readHandoff(runId, step) {
7399
7158
  const filePath = join4(this.baseDir, "handoffs", `${runId}_${step}.json`);
7400
7159
  try {
7401
- const raw = await readFile4(filePath, "utf-8");
7160
+ const raw = await readFile3(filePath, "utf-8");
7402
7161
  return JSON.parse(raw);
7403
7162
  } catch (error) {
7404
7163
  if (error instanceof Error && "code" in error && error.code === "ENOENT") {
@@ -7600,8 +7359,9 @@ Install it with: npm install ${pkg2}`
7600
7359
  import { resolve as resolve3 } from "path";
7601
7360
 
7602
7361
  // src/lib/model-aware-adapter.ts
7603
- function cacheKey(resolved) {
7604
- return `${resolved.adapter}:${resolved.model ?? ""}`;
7362
+ function cacheKey(resolved, agentId) {
7363
+ const base = `${resolved.adapter}:${resolved.model ?? ""}`;
7364
+ return agentId ? `${base}:${agentId}` : base;
7605
7365
  }
7606
7366
  async function createModelAwareAdapterSetup(options) {
7607
7367
  const modelResolver = createModelResolver({
@@ -7612,16 +7372,23 @@ async function createModelAwareAdapterSetup(options) {
7612
7372
  });
7613
7373
  const cache = /* @__PURE__ */ new Map();
7614
7374
  const inflight = /* @__PURE__ */ new Map();
7615
- async function ensureAdapter(modelClass) {
7375
+ const scopeHooks = options.adapterOptions?.guardrailHooks ? void 0 : options.guardrailHooksForAgent;
7376
+ function scopeKey(agentId) {
7377
+ return scopeHooks && agentId ? agentId : void 0;
7378
+ }
7379
+ async function ensureAdapter(modelClass, agentId) {
7616
7380
  const resolved = modelResolver.resolve(modelClass);
7617
- const key = cacheKey(resolved);
7381
+ const scope = scopeKey(agentId);
7382
+ const key = cacheKey(resolved, scope);
7618
7383
  const hit = cache.get(key);
7619
7384
  if (hit) return hit;
7620
7385
  let pending = inflight.get(key);
7621
7386
  if (!pending) {
7387
+ const agentHooks = scope ? scopeHooks(scope) : void 0;
7622
7388
  pending = createAdapter(resolved.adapter, {
7623
7389
  model: resolved.model,
7624
- ...options.adapterOptions
7390
+ ...options.adapterOptions,
7391
+ ...agentHooks ? { guardrailHooks: agentHooks } : {}
7625
7392
  });
7626
7393
  inflight.set(key, pending);
7627
7394
  }
@@ -7634,16 +7401,16 @@ async function createModelAwareAdapterSetup(options) {
7634
7401
  }
7635
7402
  }
7636
7403
  const defaultAdapter = await ensureAdapter("standard");
7637
- const factory = (modelClass) => {
7404
+ const factory = (modelClass, agentId) => {
7638
7405
  const effectiveClass = modelClass ?? "standard";
7639
7406
  const resolved = modelResolver.resolve(effectiveClass);
7640
- const key = cacheKey(resolved);
7641
- const hit = cache.get(key);
7407
+ const scope = scopeKey(agentId);
7408
+ const hit = cache.get(cacheKey(resolved, scope));
7642
7409
  if (hit) return hit;
7643
- if (effectiveClass === "standard") {
7410
+ if (effectiveClass === "standard" && !scope) {
7644
7411
  return defaultAdapter;
7645
7412
  }
7646
- return ensureAdapter(effectiveClass);
7413
+ return ensureAdapter(effectiveClass, agentId);
7647
7414
  };
7648
7415
  return {
7649
7416
  factory,
@@ -7693,22 +7460,23 @@ async function resolveExecutionContext(options, requiredEntities) {
7693
7460
  });
7694
7461
  return { registries: ctx.registries, dsl: ctx.dsl };
7695
7462
  }
7463
+ function createAgentGuardrailHooks(execCtx) {
7464
+ const component = execCtx.resolvedComponent;
7465
+ if (!component || component.guardrails.perAgent.size === 0) return void 0;
7466
+ const cache = /* @__PURE__ */ new Map();
7467
+ return (agentId) => {
7468
+ if (cache.has(agentId)) return cache.get(agentId);
7469
+ const rules = getGuardrailRulesForAgent(component, agentId);
7470
+ const hooks = rules && (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) ? createGuardrailHooksFromRules(rules) : void 0;
7471
+ cache.set(agentId, hooks);
7472
+ return hooks;
7473
+ };
7474
+ }
7696
7475
  function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
7697
- if (adapterOptions.guardrailHooks) return;
7698
- if (execCtx.resolvedComponent && targetAgentId) {
7699
- const rules2 = getGuardrailRulesForAgent(
7700
- execCtx.resolvedComponent,
7701
- targetAgentId,
7702
- execCtx.dsl
7703
- );
7704
- if (rules2 && (rules2.commandRules.length > 0 || rules2.fileRules.length > 0 || rules2.contentRules.length > 0)) {
7705
- adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules2);
7706
- }
7707
- return;
7708
- }
7709
- const rules = buildGuardrailRulesFromDsl(execCtx.dsl);
7710
- if (rules && (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0)) {
7711
- adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules);
7476
+ if (adapterOptions.guardrailHooks || !targetAgentId) return;
7477
+ const hooks = createAgentGuardrailHooks(execCtx)?.(targetAgentId);
7478
+ if (hooks) {
7479
+ adapterOptions.guardrailHooks = hooks;
7712
7480
  }
7713
7481
  }
7714
7482
  function buildAnalyzerToolRegistry(options = {}) {
@@ -7793,13 +7561,14 @@ async function executeTask(taskId, options) {
7793
7561
  async function executeWorkflow(workflowId, options) {
7794
7562
  const execCtx = await resolveExecutionContext(options, { workflows: [workflowId] });
7795
7563
  const adapterOptions = { ...options.adapterOptions };
7796
- injectGuardrailHooks(adapterOptions, execCtx);
7564
+ const guardrailHooksForAgent = adapterOptions.guardrailHooks ? void 0 : createAgentGuardrailHooks(execCtx);
7797
7565
  const { factory: adapterOrFactory, defaultAdapter: adapter, modelResolver } = await createModelAwareAdapterSetup({
7798
7566
  fallbackAdapter: options.adapter,
7799
7567
  fallbackModel: options.model,
7800
7568
  modelMapping: options.modelMapping,
7801
7569
  adapterOptions,
7802
- pinAdapter: options.pinAdapter
7570
+ pinAdapter: options.pinAdapter,
7571
+ guardrailHooksForAgent
7803
7572
  });
7804
7573
  const progressSink = createProgressSink(
7805
7574
  options.logFile ? { stderr: true, file: resolve3(options.logFile), naming: "single" } : { stderr: true }
@@ -7829,6 +7598,7 @@ async function executeWorkflow(workflowId, options) {
7829
7598
  toolchain: options.toolchain,
7830
7599
  libraryTools: analyzerTools,
7831
7600
  resolveModelMeta: (modelClass) => modelResolver.resolve(modelClass),
7601
+ perAgentAdapters: Boolean(guardrailHooksForAgent),
7832
7602
  runtime: {
7833
7603
  maxFollowUps: options.maxFollowUps ?? 2,
7834
7604
  maxRetries: options.maxRetries ?? 0
@@ -7976,11 +7746,8 @@ async function dispatchOperation(operationName, op, options, input, ctx, handler
7976
7746
 
7977
7747
  // src/lib/project-runtime.ts
7978
7748
  import { existsSync as existsSync3 } from "fs";
7979
- import { readFile as readFile5 } from "fs/promises";
7980
7749
  import { resolve as resolve4, dirname as dirname2 } from "path";
7981
- import YAML2 from "yaml";
7982
7750
  import { createPipeline } from "@aaac/observability";
7983
- var PROJECT_CONFIG_FILENAME = "project.yaml";
7984
7751
  var DEFAULT_ADAPTER = "claude";
7985
7752
  function findProjectConfig(startDir, filename = PROJECT_CONFIG_FILENAME) {
7986
7753
  let dir = resolve4(startDir);
@@ -8007,14 +7774,12 @@ async function createProjectRuntime(options) {
8007
7774
  }
8008
7775
  const config = await loadProjectConfig(configPath);
8009
7776
  const env = options.env ?? process.env;
8010
- const rawManifest = YAML2.parse(await readFile5(configPath, "utf8"));
8011
- const overlayExplicit = typeof rawManifest?.agents === "string" || typeof rawManifest?.dsl === "string";
8012
- if (overlayExplicit && !existsSync3(config.dslPath)) {
7777
+ if (config.dslDeclared && !existsSync3(config.dslPath)) {
8013
7778
  throw new Error(
8014
7779
  `Project agents DSL not found: ${config.dslPath} (referenced by ${configPath}).`
8015
7780
  );
8016
7781
  }
8017
- const projectDslPath = overlayExplicit ? config.dslPath : void 0;
7782
+ const projectDslPath = config.dslDeclared ? config.dslPath : void 0;
8018
7783
  let observer;
8019
7784
  let observerSink;
8020
7785
  let observerClosed = false;
@@ -8193,29 +7958,9 @@ function createComponentScope(componentIR, binding, options) {
8193
7958
  };
8194
7959
  }
8195
7960
 
8196
- // src/lib/artifact-resolver.ts
8197
- async function resolveArtifacts(options) {
8198
- if (!options.artifactBinding) {
8199
- return { dsl: options.dsl, diagnostics: [] };
8200
- }
8201
- const { resolveBound } = await import("agent-contracts");
8202
- const result = await resolveBound(options.dsl, {
8203
- artifactBinding: options.artifactBinding,
8204
- paths: options.paths
8205
- });
8206
- return {
8207
- dsl: result.data,
8208
- diagnostics: result.diagnostics.map((d) => ({
8209
- path: d.rule,
8210
- message: d.message,
8211
- severity: d.severity
8212
- }))
8213
- };
8214
- }
8215
-
8216
7961
  // src/lib/guard-commands.ts
8217
- import { readFile as readFile6, readdir as readdir3 } from "fs/promises";
8218
- import YAML3 from "yaml";
7962
+ import { readFile as readFile4, readdir as readdir3 } from "fs/promises";
7963
+ import "yaml";
8219
7964
  async function evaluateGuardrail(opts) {
8220
7965
  let hookInput;
8221
7966
  try {
@@ -8225,29 +7970,12 @@ async function evaluateGuardrail(opts) {
8225
7970
  `Invalid hook JSON: input must be valid JSON. ${cause.message}`
8226
7971
  );
8227
7972
  }
8228
- let guardrailCtx = {
8229
- commandChecks: [],
8230
- fileChecks: [],
8231
- contentChecks: [],
8232
- allChecks: [],
8233
- hasGuardrails: false
8234
- };
8235
- for (const bindingPath of opts.bindingPaths) {
8236
- let raw;
8237
- try {
8238
- raw = await readFile6(bindingPath, "utf8");
8239
- } catch (err) {
8240
- const code = err.code;
8241
- if (code === "ENOENT") continue;
8242
- throw err;
8243
- }
8244
- const binding = YAML3.parse(raw);
8245
- guardrailCtx = buildGuardrailContext(
8246
- opts.dsl,
8247
- binding,
8248
- opts.activeGuardrailPolicy
8249
- );
8250
- }
7973
+ const guardrailCtx = await resolveGuardrailContext(
7974
+ opts.dsl,
7975
+ opts.bindingPaths,
7976
+ opts.activeGuardrailPolicy,
7977
+ { skipMissing: true }
7978
+ );
8251
7979
  const ruleData = guardrailContextToRuleData(guardrailCtx);
8252
7980
  const hooks = createGuardrailHooksFromRules(ruleData);
8253
7981
  const command = hookInput.command;
@@ -8257,9 +7985,10 @@ async function evaluateGuardrail(opts) {
8257
7985
  const content = hookInput.content;
8258
7986
  let response = {};
8259
7987
  let checks = [];
8260
- if (command !== void 0) {
8261
- response = hooks.beforeShellExecution({ command });
8262
- checks = hooks.runChecks({ command });
7988
+ const shellCommand = command ?? toolInput?.command;
7989
+ if (shellCommand !== void 0) {
7990
+ response = hooks.beforeShellExecution({ command: shellCommand });
7991
+ checks = hooks.runChecks({ command: shellCommand });
8263
7992
  } else if (toolName !== void 0 || toolInput !== void 0) {
8264
7993
  response = hooks.preToolUse({ tool_name: toolName, tool_input: toolInput });
8265
7994
  const checkFilePath = toolInput?.file_path ?? toolInput?.path ?? "";
@@ -8274,29 +8003,12 @@ async function evaluateGuardrail(opts) {
8274
8003
  return { response, exitCode, checks };
8275
8004
  }
8276
8005
  async function listGuardrails(opts) {
8277
- let guardrailCtx = {
8278
- commandChecks: [],
8279
- fileChecks: [],
8280
- contentChecks: [],
8281
- allChecks: [],
8282
- hasGuardrails: false
8283
- };
8284
- for (const bindingPath of opts.bindingPaths) {
8285
- let raw;
8286
- try {
8287
- raw = await readFile6(bindingPath, "utf8");
8288
- } catch (err) {
8289
- const code = err.code;
8290
- if (code === "ENOENT") continue;
8291
- throw err;
8292
- }
8293
- const binding = YAML3.parse(raw);
8294
- guardrailCtx = buildGuardrailContext(
8295
- opts.dsl,
8296
- binding,
8297
- opts.activeGuardrailPolicy
8298
- );
8299
- }
8006
+ const guardrailCtx = await resolveGuardrailContext(
8007
+ opts.dsl,
8008
+ opts.bindingPaths,
8009
+ opts.activeGuardrailPolicy,
8010
+ { skipMissing: true }
8011
+ );
8300
8012
  const entries = guardrailCtx.allChecks.map(
8301
8013
  (c) => ({
8302
8014
  guardrail_id: c.guardrail_id,
@@ -8343,7 +8055,7 @@ async function guardStatus(opts = {}) {
8343
8055
  const filePath = `${runsDir}/${file}`;
8344
8056
  let raw;
8345
8057
  try {
8346
- raw = await readFile6(filePath, "utf8");
8058
+ raw = await readFile4(filePath, "utf8");
8347
8059
  } catch {
8348
8060
  continue;
8349
8061
  }
@@ -8366,32 +8078,7 @@ async function guardStatus(opts = {}) {
8366
8078
  }
8367
8079
 
8368
8080
  // src/lib/claude-materialize/config.ts
8369
- import { basename as basename2 } from "path";
8370
8081
  import { z as z2 } from "zod";
8371
- var WorkspaceMemberBindingSchema = z2.object({
8372
- /**
8373
- * Workspace-relative path to the member directory
8374
- * (e.g. `"./aaac"`). The member's agent-contracts.yaml is resolved
8375
- * relative to this directory using `config_path`.
8376
- */
8377
- path: z2.string(),
8378
- /**
8379
- * Path to the member's agent-contracts DSL, relative to the member
8380
- * root. Defaults to `"./agent-contracts.yaml"`.
8381
- */
8382
- config_path: z2.string().optional()
8383
- });
8384
- var WorkspaceBindingConfigSchema = z2.object({
8385
- members: z2.array(WorkspaceMemberBindingSchema),
8386
- /**
8387
- * @deprecated Since #241 the generated hook bins are bundled into
8388
- * self-contained ESM (`@aaac/runtime` inlined) at `claude sync` time, so no
8389
- * `node_modules` resolution — and thus no `NODE_PATH` export — is needed at
8390
- * runtime. This field is still accepted for config backward-compatibility but
8391
- * is ignored (no-op). Remove it from your binding config at your convenience.
8392
- */
8393
- resolve_from: z2.string().optional()
8394
- });
8395
8082
  var ClaudeCommandsEmitSchema = z2.object({
8396
8083
  /**
8397
8084
  * Project-root-relative output path with a required `{name}` placeholder.
@@ -8419,7 +8106,13 @@ var ClaudeEmitSchema = z2.object({
8419
8106
  var ClaudeConfigSchema = z2.object({
8420
8107
  /** Root directory for Claude artifacts (relative to the project root). */
8421
8108
  output_dir: z2.string().default(".claude"),
8422
- /** Path to agent-contracts.yaml (relative to the project root). */
8109
+ /**
8110
+ * Agents DSL path (relative to the project root) baked into the generated
8111
+ * nav hook bins as the FALLBACK for a project root with no `project.yaml`
8112
+ * (a bare component checkout). When a manifest exists it is authoritative:
8113
+ * the hooks resolve `agents:` and `artifacts:` from it at hook runtime
8114
+ * (#260), so this value is not consulted.
8115
+ */
8423
8116
  config_path: z2.string().default("./agent-contracts.yaml"),
8424
8117
  /**
8425
8118
  * Additive-artifact emission toggles. Defaults keep the historical
@@ -8432,27 +8125,8 @@ var ClaudeConfigSchema = z2.object({
8432
8125
  */
8433
8126
  guard_command: z2.string().optional(),
8434
8127
  /** Override component id; defaults to `dsl.system.id`. */
8435
- component_id: z2.string().optional(),
8436
- /**
8437
- * Workspace binding configuration. When present the generator emits
8438
- * workspace-router bins instead of single-component bins (AC3).
8439
- */
8440
- workspace: WorkspaceBindingConfigSchema.optional()
8128
+ component_id: z2.string().optional()
8441
8129
  }).strip();
8442
- function resolveWorkspaceMembers(ws) {
8443
- return ws.members.map((m) => {
8444
- const name = basename2(m.path.replace(/\/+$/, "")) || m.path;
8445
- const configPath = m.config_path ?? "./agent-contracts.yaml";
8446
- const cacheKey2 = `navigation-index.${name}`;
8447
- return {
8448
- name,
8449
- path: m.path,
8450
- configPath,
8451
- cacheKey: cacheKey2,
8452
- guardrailCacheKey: `${cacheKey2}.guardrails`
8453
- };
8454
- });
8455
- }
8456
8130
  function parseClaudeConfig(raw) {
8457
8131
  return ClaudeConfigSchema.parse(raw ?? {});
8458
8132
  }
@@ -8995,7 +8669,7 @@ function renderCommandFiles(dsl, outputTemplate, templateSource) {
8995
8669
 
8996
8670
  // src/lib/claude-materialize/materialize.ts
8997
8671
  import { existsSync as existsSync4 } from "fs";
8998
- import { mkdir as mkdir3, readFile as readFile7, writeFile as writeFile3 } from "fs/promises";
8672
+ import { mkdir as mkdir3, readFile as readFile5, writeFile as writeFile3 } from "fs/promises";
8999
8673
  import { dirname as dirname5, join as join7, resolve as resolve5 } from "path";
9000
8674
  import {
9001
8675
  claudeGenerator
@@ -9253,14 +8927,23 @@ function absPath(root, file) {
9253
8927
  }
9254
8928
  async function readIfExists(path) {
9255
8929
  if (!existsSync4(path)) return void 0;
9256
- return readFile7(path, "utf8");
8930
+ return readFile5(path, "utf8");
8931
+ }
8932
+ async function workspaceMembersForProject(root) {
8933
+ const manifestPath = join7(root, PROJECT_CONFIG_FILENAME);
8934
+ if (!existsSync4(manifestPath)) return [];
8935
+ const members = await loadWorkspaceMembers(manifestPath);
8936
+ return members.map((m) => ({
8937
+ name: m.name,
8938
+ path: m.path,
8939
+ cacheKey: m.cacheKey,
8940
+ guardrailCacheKey: guardrailCacheKey(m.cacheKey)
8941
+ }));
9257
8942
  }
9258
- function renderFiles(dsl, config) {
8943
+ async function renderFiles(root, dsl, config) {
9259
8944
  const ir = buildComponentIR(dsl, config);
9260
- const workspaceOptions = config.workspace ? {
9261
- members: resolveWorkspaceMembers(config.workspace),
9262
- resolve_from: config.workspace.resolve_from
9263
- } : void 0;
8945
+ const members = await workspaceMembersForProject(root);
8946
+ const workspaceOptions = members.length > 0 ? { members } : void 0;
9264
8947
  return claudeGenerator.generate(ir, {
9265
8948
  outputDir: "",
9266
8949
  componentPath: "",
@@ -9353,7 +9036,7 @@ async function commandFiles(dsl, config, root) {
9353
9036
  let templateSource = DEFAULT_COMMAND_TEMPLATE;
9354
9037
  if (commands.template) {
9355
9038
  const templatePath = resolve5(root, commands.template);
9356
- templateSource = await readFile7(templatePath, "utf8");
9039
+ templateSource = await readFile5(templatePath, "utf8");
9357
9040
  }
9358
9041
  return renderCommandFiles(dsl, outputTemplate, templateSource);
9359
9042
  }
@@ -9365,7 +9048,7 @@ async function syncClaude(opts) {
9365
9048
  const config = parseClaudeConfig(opts.config);
9366
9049
  const root = resolve5(opts.projectRoot);
9367
9050
  const result = { files: [] };
9368
- for (const file of renderFiles(opts.dsl, config)) {
9051
+ for (const file of await renderFiles(root, opts.dsl, config)) {
9369
9052
  const rel = relPath(file);
9370
9053
  const abs = absPath(root, file);
9371
9054
  const existing = await readIfExists(abs);
@@ -9407,7 +9090,7 @@ async function checkClaude(opts) {
9407
9090
  const config = parseClaudeConfig(opts.config);
9408
9091
  const root = resolve5(opts.projectRoot);
9409
9092
  const drift = [];
9410
- for (const file of renderFiles(opts.dsl, config)) {
9093
+ for (const file of await renderFiles(root, opts.dsl, config)) {
9411
9094
  const rel = relPath(file);
9412
9095
  const existing = await readIfExists(absPath(root, file));
9413
9096
  if (isHookBin(file.targetDir, file.path)) {
@@ -9441,7 +9124,7 @@ async function checkClaude(opts) {
9441
9124
  }
9442
9125
 
9443
9126
  // src/lib/prompt-executor.ts
9444
- import * as YAML4 from "yaml";
9127
+ import * as YAML2 from "yaml";
9445
9128
  function unwrapInputSchema(input) {
9446
9129
  if (!input) {
9447
9130
  return { type: "object", properties: {} };
@@ -9500,7 +9183,7 @@ function parseRouterResponse(response, validNames) {
9500
9183
  const content = yamlMatch ? yamlMatch[1].trim() : response.trim();
9501
9184
  let parsed;
9502
9185
  try {
9503
- parsed = YAML4.parse(content);
9186
+ parsed = YAML2.parse(content);
9504
9187
  } catch {
9505
9188
  const jsonMatch = response.match(/\{[\s\S]*"operation"[\s\S]*\}/);
9506
9189
  if (jsonMatch) {
@@ -9571,7 +9254,6 @@ export {
9571
9254
  WorkflowBuilder,
9572
9255
  buildCandidateAgents,
9573
9256
  buildGateEvaluationPrompt,
9574
- buildGuardrailRulesFromDsl,
9575
9257
  buildNavigationContext,
9576
9258
  buildObservabilityEnv,
9577
9259
  buildPerAgentGuardrails,