agent-contracts-runtime 0.36.6 → 0.36.7

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.
@@ -1,7 +1,10 @@
1
1
  import {
2
2
  createGuardrailHooksFromRules,
3
3
  pluginRegistry
4
- } from "./chunk-JDXRLHY3.js";
4
+ } from "./chunk-MGRZBGQL.js";
5
+ import {
6
+ buildGuardrailContext
7
+ } from "./chunk-LTZA6QWC.js";
5
8
 
6
9
  // src/lib/task-runner.ts
7
10
  import { z } from "zod";
@@ -53,10 +56,12 @@ function buildCandidateAgents(agentRegistry, opts) {
53
56
  for (const [id, agent] of Object.entries(agentRegistry)) {
54
57
  if (id === entryId) continue;
55
58
  if (allowSet && !allowSet.has(id)) continue;
59
+ const tools = agent.can_execute_tools;
56
60
  candidates.push({
57
61
  name: id,
58
62
  description: deriveDescription(agent.purpose),
59
- prompt: renderAgentSystemPrompt(agent)
63
+ prompt: renderAgentSystemPrompt(agent),
64
+ ...tools && tools.length > 0 ? { tools: [...tools] } : {}
60
65
  });
61
66
  }
62
67
  return candidates;
@@ -968,152 +973,9 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
968
973
  });
969
974
  }
970
975
 
971
- // src/lib/builder.ts
972
- function createRuntime(config) {
973
- return {
974
- workflow(workflowId) {
975
- return new WorkflowBuilder(config.adapter, workflowId, config.registries);
976
- }
977
- };
978
- }
979
- var WorkflowBuilder = class {
980
- adapter;
981
- invocation;
982
- registries;
983
- constructor(adapter, workflowId, registries) {
984
- this.adapter = adapter;
985
- this.invocation = { workflow: workflowId };
986
- this.registries = registries;
987
- }
988
- /** Set a typed handoff envelope as input. */
989
- handoff(input) {
990
- this.invocation = { ...this.invocation, handoff: input };
991
- return this;
992
- }
993
- /** Set a simple string request (convenience shorthand). */
994
- request(userRequest) {
995
- this.invocation = { ...this.invocation, user_request: userRequest };
996
- return this;
997
- }
998
- maxFollowUps(n) {
999
- this.invocation = {
1000
- ...this.invocation,
1001
- runtime: { ...this.invocation.runtime, maxFollowUps: n }
1002
- };
1003
- return this;
1004
- }
1005
- maxRetries(n) {
1006
- this.invocation = {
1007
- ...this.invocation,
1008
- runtime: { ...this.invocation.runtime, maxRetries: n }
1009
- };
1010
- return this;
1011
- }
1012
- onStepComplete(cb) {
1013
- this.invocation = {
1014
- ...this.invocation,
1015
- hooks: { ...this.invocation.hooks, onStepComplete: cb }
1016
- };
1017
- return this;
1018
- }
1019
- onGate(cb) {
1020
- this.invocation = {
1021
- ...this.invocation,
1022
- hooks: { ...this.invocation.hooks, onGate: cb }
1023
- };
1024
- return this;
1025
- }
1026
- onOptionalStep(cb) {
1027
- this.invocation = {
1028
- ...this.invocation,
1029
- hooks: { ...this.invocation.hooks, onOptionalStep: cb }
1030
- };
1031
- return this;
1032
- }
1033
- /** Set progress output sink for real-time execution visibility. */
1034
- progressOutput(sink) {
1035
- this.invocation = { ...this.invocation, progressOutput: sink };
1036
- return this;
1037
- }
1038
- async run() {
1039
- return runWorkflow(this.adapter, this.invocation, this.registries);
1040
- }
1041
- };
1042
-
1043
- // src/lib/plugin-loader.ts
1044
- import { existsSync } from "fs";
1045
- import { readdir } from "fs/promises";
1046
- import { resolve, join } from "path";
1047
- var PLUGIN_EXTENSIONS = [".ts", ".js", ".mts", ".mjs"];
1048
- function isPluginLike(obj) {
1049
- return typeof obj === "object" && obj !== null && typeof obj.id === "string";
1050
- }
1051
- async function scanDirectory(dir) {
1052
- if (!existsSync(dir)) return [];
1053
- const entries = await readdir(dir, { withFileTypes: true });
1054
- return entries.filter(
1055
- (e) => e.isFile() && PLUGIN_EXTENSIONS.some((ext) => e.name.endsWith(ext)) && !e.name.startsWith("_") && !e.name.endsWith(".d.ts") && !e.name.endsWith(".test.ts") && !e.name.endsWith(".spec.ts")
1056
- ).map((e) => resolve(dir, e.name));
1057
- }
1058
- async function loadPluginModule(modulePath) {
1059
- const mod = await import(new URL(`file://${modulePath}`).href);
1060
- let count = 0;
1061
- for (const exportValue of Object.values(mod)) {
1062
- if (isPluginLike(exportValue)) {
1063
- try {
1064
- pluginRegistry.register(exportValue);
1065
- count++;
1066
- } catch {
1067
- }
1068
- }
1069
- }
1070
- return count;
1071
- }
1072
- async function loadPluginsFromPaths(paths, baseDir) {
1073
- const result = { loaded: 0, files: [], errors: [] };
1074
- for (const p of paths) {
1075
- const absPath = resolve(baseDir, p);
1076
- if (!existsSync(absPath)) {
1077
- result.errors.push({ file: p, error: `File not found: ${absPath}` });
1078
- continue;
1079
- }
1080
- try {
1081
- const count = await loadPluginModule(absPath);
1082
- result.loaded += count;
1083
- result.files.push(absPath);
1084
- } catch (err) {
1085
- result.errors.push({
1086
- file: p,
1087
- error: err.message
1088
- });
1089
- }
1090
- }
1091
- return result;
1092
- }
1093
- async function loadPluginsFromDirectory(dir) {
1094
- const result = { loaded: 0, files: [], errors: [] };
1095
- const candidates = await scanDirectory(dir);
1096
- for (const filePath of candidates) {
1097
- try {
1098
- const count = await loadPluginModule(filePath);
1099
- result.loaded += count;
1100
- result.files.push(filePath);
1101
- } catch (err) {
1102
- result.errors.push({
1103
- file: filePath,
1104
- error: err.message
1105
- });
1106
- }
1107
- }
1108
- return result;
1109
- }
1110
- async function loadPlugins(options) {
1111
- if (options.pluginPaths && options.pluginPaths.length > 0) {
1112
- return loadPluginsFromPaths(options.pluginPaths, options.projectDir);
1113
- }
1114
- const conventionDir = join(options.projectDir, "src", "plugins");
1115
- return loadPluginsFromDirectory(conventionDir);
1116
- }
976
+ // src/lib/bound-resolver.ts
977
+ import { readFile as readFile2 } from "fs/promises";
978
+ import YAML2 from "yaml";
1117
979
 
1118
980
  // src/lib/dsl-context.ts
1119
981
  import { readFile } from "fs/promises";
@@ -1215,7 +1077,9 @@ function buildAgentRegistry(agents) {
1215
1077
  mode,
1216
1078
  responsibilities: agent.responsibilities ?? [],
1217
1079
  constraints: agent.constraints ?? [],
1218
- rules: agent.rules ?? []
1080
+ rules: agent.rules ?? [],
1081
+ can_invoke_agents: agent.can_invoke_agents ?? void 0,
1082
+ can_execute_tools: agent.can_execute_tools ?? void 0
1219
1083
  };
1220
1084
  }
1221
1085
  return registry;
@@ -1371,6 +1235,307 @@ async function loadDslContext(options) {
1371
1235
  return { registries, dsl, guardrailRules };
1372
1236
  }
1373
1237
 
1238
+ // src/lib/bound-resolver.ts
1239
+ function getEffectiveGuardrailIds(dsl, agentId) {
1240
+ const ids = /* @__PURE__ */ new Set();
1241
+ const agents = dsl.agents ?? {};
1242
+ const agent = agents[agentId];
1243
+ if (agent) {
1244
+ for (const ref of agent.guardrails ?? []) {
1245
+ ids.add(ref);
1246
+ }
1247
+ }
1248
+ const guardrails = dsl.guardrails ?? {};
1249
+ for (const [guardrailId, guardrail] of Object.entries(guardrails)) {
1250
+ if (guardrail.scope?.agents?.includes(agentId)) {
1251
+ ids.add(guardrailId);
1252
+ }
1253
+ }
1254
+ return ids;
1255
+ }
1256
+ function guardrailCheckToCommandRule(c) {
1257
+ return {
1258
+ guardrail_id: c.guardrail_id,
1259
+ pattern: c.pattern,
1260
+ action: c.action,
1261
+ message: c.message
1262
+ };
1263
+ }
1264
+ function guardrailCheckToFileRule(c) {
1265
+ return {
1266
+ guardrail_id: c.guardrail_id,
1267
+ pattern: c.pattern,
1268
+ action: c.action,
1269
+ message: c.message,
1270
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
1271
+ };
1272
+ }
1273
+ function guardrailCheckToContentRule(c) {
1274
+ return {
1275
+ guardrail_id: c.guardrail_id,
1276
+ pattern: c.pattern,
1277
+ action: c.action,
1278
+ message: c.message,
1279
+ ...c.file_glob ? { file_glob: c.file_glob } : {},
1280
+ ...c.exclude_glob ? { exclude_glob: c.exclude_glob } : {}
1281
+ };
1282
+ }
1283
+ function guardrailContextToRuleData(ctx, effectiveIds) {
1284
+ const filter = (checks) => effectiveIds ? checks.filter((c) => effectiveIds.has(c.guardrail_id)) : checks;
1285
+ return {
1286
+ commandRules: filter(ctx.commandChecks).map(guardrailCheckToCommandRule),
1287
+ fileRules: filter(ctx.fileChecks).map(guardrailCheckToFileRule),
1288
+ contentRules: filter(ctx.contentChecks).map(guardrailCheckToContentRule)
1289
+ };
1290
+ }
1291
+ function buildPerAgentGuardrails(dsl, guardrailCtx) {
1292
+ const perAgent = /* @__PURE__ */ new Map();
1293
+ const agents = dsl.agents ?? {};
1294
+ for (const agentId of Object.keys(agents)) {
1295
+ const effectiveIds = getEffectiveGuardrailIds(dsl, agentId);
1296
+ const rules = guardrailContextToRuleData(guardrailCtx, effectiveIds);
1297
+ if (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0) {
1298
+ perAgent.set(agentId, rules);
1299
+ }
1300
+ }
1301
+ return perAgent;
1302
+ }
1303
+ function hasGuardrailRules(rules) {
1304
+ return rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0;
1305
+ }
1306
+ var BoundResolver = class {
1307
+ cache = /* @__PURE__ */ new Map();
1308
+ /**
1309
+ * Resolve binding + policy in one pass. Results are cached by component id.
1310
+ */
1311
+ async resolve(opts) {
1312
+ const cached = this.cache.get(opts.id);
1313
+ if (cached) return cached;
1314
+ const diagnostics = [];
1315
+ let dsl;
1316
+ if (opts.embeddedDsl) {
1317
+ dsl = opts.embeddedDsl;
1318
+ } else if (opts.dslPath) {
1319
+ const { resolve: resolveDsl } = await import("agent-contracts");
1320
+ const result = await resolveDsl(opts.dslPath);
1321
+ dsl = result.data;
1322
+ } else {
1323
+ throw new Error("BoundResolver.resolve requires embeddedDsl or dslPath");
1324
+ }
1325
+ if (opts.artifactBinding) {
1326
+ const { resolveBound } = await import("agent-contracts");
1327
+ const boundResult = await resolveBound(dsl, {
1328
+ artifactBinding: opts.artifactBinding,
1329
+ paths: opts.paths
1330
+ });
1331
+ dsl = boundResult.data;
1332
+ for (const d of boundResult.diagnostics) {
1333
+ diagnostics.push({
1334
+ path: d.rule,
1335
+ message: d.message,
1336
+ severity: d.severity
1337
+ });
1338
+ }
1339
+ }
1340
+ let guardrailCtx = {
1341
+ commandChecks: [],
1342
+ fileChecks: [],
1343
+ contentChecks: [],
1344
+ allChecks: [],
1345
+ hasGuardrails: false
1346
+ };
1347
+ if (opts.bindingPaths && opts.bindingPaths.length > 0) {
1348
+ for (const bindingPath of opts.bindingPaths) {
1349
+ const raw = await readFile2(bindingPath, "utf8");
1350
+ const binding = YAML2.parse(raw);
1351
+ guardrailCtx = buildGuardrailContext(
1352
+ dsl,
1353
+ binding,
1354
+ opts.activeGuardrailPolicy
1355
+ );
1356
+ }
1357
+ }
1358
+ const perAgent = guardrailCtx.hasGuardrails ? buildPerAgentGuardrails(dsl, guardrailCtx) : /* @__PURE__ */ new Map();
1359
+ const component = {
1360
+ id: opts.id,
1361
+ dsl,
1362
+ registries: buildRegistriesFromDsl(dsl),
1363
+ guardrails: { perAgent },
1364
+ diagnostics
1365
+ };
1366
+ this.cache.set(opts.id, component);
1367
+ return component;
1368
+ }
1369
+ /** Clear cached components (e.g. for testing). */
1370
+ clearCache() {
1371
+ this.cache.clear();
1372
+ }
1373
+ };
1374
+ function getGuardrailRulesForAgent(component, agentId, fallbackDsl) {
1375
+ const perAgent = component.guardrails.perAgent.get(agentId);
1376
+ if (perAgent && hasGuardrailRules(perAgent)) {
1377
+ return perAgent;
1378
+ }
1379
+ if (fallbackDsl) {
1380
+ const raw = fallbackDsl._guardrailRules;
1381
+ if (raw) {
1382
+ return {
1383
+ commandRules: raw.commandRules ?? [],
1384
+ fileRules: raw.fileRules ?? [],
1385
+ contentRules: raw.contentRules ?? []
1386
+ };
1387
+ }
1388
+ }
1389
+ return void 0;
1390
+ }
1391
+
1392
+ // src/lib/builder.ts
1393
+ function createRuntime(config) {
1394
+ return {
1395
+ workflow(workflowId) {
1396
+ return new WorkflowBuilder(config.adapter, workflowId, config.registries);
1397
+ }
1398
+ };
1399
+ }
1400
+ var WorkflowBuilder = class {
1401
+ adapter;
1402
+ invocation;
1403
+ registries;
1404
+ constructor(adapter, workflowId, registries) {
1405
+ this.adapter = adapter;
1406
+ this.invocation = { workflow: workflowId };
1407
+ this.registries = registries;
1408
+ }
1409
+ /** Set a typed handoff envelope as input. */
1410
+ handoff(input) {
1411
+ this.invocation = { ...this.invocation, handoff: input };
1412
+ return this;
1413
+ }
1414
+ /** Set a simple string request (convenience shorthand). */
1415
+ request(userRequest) {
1416
+ this.invocation = { ...this.invocation, user_request: userRequest };
1417
+ return this;
1418
+ }
1419
+ maxFollowUps(n) {
1420
+ this.invocation = {
1421
+ ...this.invocation,
1422
+ runtime: { ...this.invocation.runtime, maxFollowUps: n }
1423
+ };
1424
+ return this;
1425
+ }
1426
+ maxRetries(n) {
1427
+ this.invocation = {
1428
+ ...this.invocation,
1429
+ runtime: { ...this.invocation.runtime, maxRetries: n }
1430
+ };
1431
+ return this;
1432
+ }
1433
+ onStepComplete(cb) {
1434
+ this.invocation = {
1435
+ ...this.invocation,
1436
+ hooks: { ...this.invocation.hooks, onStepComplete: cb }
1437
+ };
1438
+ return this;
1439
+ }
1440
+ onGate(cb) {
1441
+ this.invocation = {
1442
+ ...this.invocation,
1443
+ hooks: { ...this.invocation.hooks, onGate: cb }
1444
+ };
1445
+ return this;
1446
+ }
1447
+ onOptionalStep(cb) {
1448
+ this.invocation = {
1449
+ ...this.invocation,
1450
+ hooks: { ...this.invocation.hooks, onOptionalStep: cb }
1451
+ };
1452
+ return this;
1453
+ }
1454
+ /** Set progress output sink for real-time execution visibility. */
1455
+ progressOutput(sink) {
1456
+ this.invocation = { ...this.invocation, progressOutput: sink };
1457
+ return this;
1458
+ }
1459
+ async run() {
1460
+ return runWorkflow(this.adapter, this.invocation, this.registries);
1461
+ }
1462
+ };
1463
+
1464
+ // src/lib/plugin-loader.ts
1465
+ import { existsSync } from "fs";
1466
+ import { readdir } from "fs/promises";
1467
+ import { resolve, join } from "path";
1468
+ var PLUGIN_EXTENSIONS = [".ts", ".js", ".mts", ".mjs"];
1469
+ function isPluginLike(obj) {
1470
+ return typeof obj === "object" && obj !== null && typeof obj.id === "string";
1471
+ }
1472
+ async function scanDirectory(dir) {
1473
+ if (!existsSync(dir)) return [];
1474
+ const entries = await readdir(dir, { withFileTypes: true });
1475
+ return entries.filter(
1476
+ (e) => e.isFile() && PLUGIN_EXTENSIONS.some((ext) => e.name.endsWith(ext)) && !e.name.startsWith("_") && !e.name.endsWith(".d.ts") && !e.name.endsWith(".test.ts") && !e.name.endsWith(".spec.ts")
1477
+ ).map((e) => resolve(dir, e.name));
1478
+ }
1479
+ async function loadPluginModule(modulePath) {
1480
+ const mod = await import(new URL(`file://${modulePath}`).href);
1481
+ let count = 0;
1482
+ for (const exportValue of Object.values(mod)) {
1483
+ if (isPluginLike(exportValue)) {
1484
+ try {
1485
+ pluginRegistry.register(exportValue);
1486
+ count++;
1487
+ } catch {
1488
+ }
1489
+ }
1490
+ }
1491
+ return count;
1492
+ }
1493
+ async function loadPluginsFromPaths(paths, baseDir) {
1494
+ const result = { loaded: 0, files: [], errors: [] };
1495
+ for (const p of paths) {
1496
+ const absPath = resolve(baseDir, p);
1497
+ if (!existsSync(absPath)) {
1498
+ result.errors.push({ file: p, error: `File not found: ${absPath}` });
1499
+ continue;
1500
+ }
1501
+ try {
1502
+ const count = await loadPluginModule(absPath);
1503
+ result.loaded += count;
1504
+ result.files.push(absPath);
1505
+ } catch (err) {
1506
+ result.errors.push({
1507
+ file: p,
1508
+ error: err.message
1509
+ });
1510
+ }
1511
+ }
1512
+ return result;
1513
+ }
1514
+ async function loadPluginsFromDirectory(dir) {
1515
+ const result = { loaded: 0, files: [], errors: [] };
1516
+ const candidates = await scanDirectory(dir);
1517
+ for (const filePath of candidates) {
1518
+ try {
1519
+ const count = await loadPluginModule(filePath);
1520
+ result.loaded += count;
1521
+ result.files.push(filePath);
1522
+ } catch (err) {
1523
+ result.errors.push({
1524
+ file: filePath,
1525
+ error: err.message
1526
+ });
1527
+ }
1528
+ }
1529
+ return result;
1530
+ }
1531
+ async function loadPlugins(options) {
1532
+ if (options.pluginPaths && options.pluginPaths.length > 0) {
1533
+ return loadPluginsFromPaths(options.pluginPaths, options.projectDir);
1534
+ }
1535
+ const conventionDir = join(options.projectDir, "src", "plugins");
1536
+ return loadPluginsFromDirectory(conventionDir);
1537
+ }
1538
+
1374
1539
  // src/lib/progress-sink.ts
1375
1540
  import { openSync, writeSync, closeSync, mkdirSync } from "fs";
1376
1541
  import { dirname, join as join2, basename, extname } from "path";
@@ -1504,16 +1669,60 @@ Install it with: npm install ${pkg}`
1504
1669
 
1505
1670
  // src/lib/execute.ts
1506
1671
  import { resolve as resolve2 } from "path";
1507
- async function executeTask(taskId, options) {
1672
+ async function resolveExecutionContext(options, requiredEntities) {
1673
+ const useBoundResolver = options.resolvedComponent || options.bindingPaths && options.bindingPaths.length > 0 || options.artifactBinding;
1674
+ if (useBoundResolver) {
1675
+ const component = options.resolvedComponent ?? await new BoundResolver().resolve({
1676
+ id: options.componentId ?? "default",
1677
+ embeddedDsl: options.dsl,
1678
+ bindingPaths: options.bindingPaths,
1679
+ activeGuardrailPolicy: options.activeGuardrailPolicy,
1680
+ artifactBinding: options.artifactBinding,
1681
+ paths: options.paths
1682
+ });
1683
+ if (requiredEntities) {
1684
+ const ctx2 = await loadDslContext({
1685
+ embeddedDsl: component.dsl,
1686
+ requiredEntities
1687
+ });
1688
+ return { registries: ctx2.registries, dsl: component.dsl, resolvedComponent: component };
1689
+ }
1690
+ return {
1691
+ registries: component.registries,
1692
+ dsl: component.dsl,
1693
+ resolvedComponent: component
1694
+ };
1695
+ }
1508
1696
  const ctx = await loadDslContext({
1509
1697
  embeddedDsl: options.dsl,
1510
1698
  projectDslPath: options.projectDslPath,
1511
- requiredEntities: { tasks: [taskId] }
1699
+ requiredEntities
1512
1700
  });
1513
- const adapterOptions = { ...options.adapterOptions };
1514
- if (!adapterOptions.guardrailHooks && ctx.guardrailRules && (ctx.guardrailRules.commandRules.length > 0 || ctx.guardrailRules.fileRules.length > 0 || ctx.guardrailRules.contentRules.length > 0)) {
1515
- adapterOptions.guardrailHooks = createGuardrailHooksFromRules(ctx.guardrailRules);
1701
+ return { registries: ctx.registries, dsl: ctx.dsl };
1702
+ }
1703
+ function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
1704
+ if (adapterOptions.guardrailHooks) return;
1705
+ if (execCtx.resolvedComponent && targetAgentId) {
1706
+ const rules2 = getGuardrailRulesForAgent(
1707
+ execCtx.resolvedComponent,
1708
+ targetAgentId,
1709
+ execCtx.dsl
1710
+ );
1711
+ if (rules2 && (rules2.commandRules.length > 0 || rules2.fileRules.length > 0 || rules2.contentRules.length > 0)) {
1712
+ adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules2);
1713
+ }
1714
+ return;
1516
1715
  }
1716
+ const rules = buildGuardrailRulesFromDsl(execCtx.dsl);
1717
+ if (rules && (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0)) {
1718
+ adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules);
1719
+ }
1720
+ }
1721
+ async function executeTask(taskId, options) {
1722
+ const execCtx = await resolveExecutionContext(options, { tasks: [taskId] });
1723
+ const targetAgentId = execCtx.registries.taskRegistry?.[taskId]?.target_agent;
1724
+ const adapterOptions = { ...options.adapterOptions };
1725
+ injectGuardrailHooks(adapterOptions, execCtx, targetAgentId);
1517
1726
  const adapter = await createAdapter(options.adapter, {
1518
1727
  model: options.model,
1519
1728
  ...adapterOptions
@@ -1523,13 +1732,13 @@ async function executeTask(taskId, options) {
1523
1732
  );
1524
1733
  try {
1525
1734
  if (options.hooks?.beforeTask) {
1526
- await options.hooks.beforeTask({ adapter, registries: ctx.registries, taskId });
1735
+ await options.hooks.beforeTask({ adapter, registries: execCtx.registries, taskId });
1527
1736
  }
1528
1737
  const result = await runTask(adapter, taskId, { user_request: options.request }, {
1529
1738
  maxFollowUps: options.maxFollowUps ?? 2,
1530
1739
  maxRetries: options.maxRetries ?? 0,
1531
1740
  progressOutput: progressSink,
1532
- ...ctx.registries
1741
+ ...execCtx.registries
1533
1742
  });
1534
1743
  if (options.hooks?.afterTask) {
1535
1744
  await options.hooks.afterTask(result);
@@ -1540,15 +1749,9 @@ async function executeTask(taskId, options) {
1540
1749
  }
1541
1750
  }
1542
1751
  async function executeWorkflow(workflowId, options) {
1543
- const ctx = await loadDslContext({
1544
- embeddedDsl: options.dsl,
1545
- projectDslPath: options.projectDslPath,
1546
- requiredEntities: { workflows: [workflowId] }
1547
- });
1752
+ const execCtx = await resolveExecutionContext(options, { workflows: [workflowId] });
1548
1753
  const adapterOptions = { ...options.adapterOptions };
1549
- if (!adapterOptions.guardrailHooks && ctx.guardrailRules && (ctx.guardrailRules.commandRules.length > 0 || ctx.guardrailRules.fileRules.length > 0 || ctx.guardrailRules.contentRules.length > 0)) {
1550
- adapterOptions.guardrailHooks = createGuardrailHooksFromRules(ctx.guardrailRules);
1551
- }
1754
+ injectGuardrailHooks(adapterOptions, execCtx);
1552
1755
  const adapter = await createAdapter(options.adapter, {
1553
1756
  model: options.model,
1554
1757
  ...adapterOptions
@@ -1558,7 +1761,7 @@ async function executeWorkflow(workflowId, options) {
1558
1761
  );
1559
1762
  try {
1560
1763
  if (options.hooks?.beforeWorkflow) {
1561
- await options.hooks.beforeWorkflow({ adapter, registries: ctx.registries, workflowId });
1764
+ await options.hooks.beforeWorkflow({ adapter, registries: execCtx.registries, workflowId });
1562
1765
  }
1563
1766
  const invocation = {
1564
1767
  workflow: workflowId,
@@ -1576,7 +1779,7 @@ async function executeWorkflow(workflowId, options) {
1576
1779
  },
1577
1780
  context: options.context
1578
1781
  };
1579
- const result = await runWorkflow(adapter, invocation, ctx.registries);
1782
+ const result = await runWorkflow(adapter, invocation, execCtx.registries);
1580
1783
  if (options.hooks?.afterWorkflow) {
1581
1784
  await options.hooks.afterWorkflow(result);
1582
1785
  }
@@ -1599,20 +1802,25 @@ export {
1599
1802
  runWorkflow,
1600
1803
  buildGateEvaluationPrompt,
1601
1804
  parseGateEvaluationResponse,
1602
- createRuntime,
1603
- WorkflowBuilder,
1604
- loadPluginsFromPaths,
1605
- loadPluginsFromDirectory,
1606
- loadPlugins,
1607
1805
  jsonSchemaToZod,
1608
1806
  DslValidationError,
1609
1807
  buildGuardrailRulesFromDsl,
1610
1808
  buildRegistriesFromDsl,
1611
1809
  loadDslContext,
1810
+ getEffectiveGuardrailIds,
1811
+ guardrailContextToRuleData,
1812
+ buildPerAgentGuardrails,
1813
+ BoundResolver,
1814
+ getGuardrailRulesForAgent,
1815
+ createRuntime,
1816
+ WorkflowBuilder,
1817
+ loadPluginsFromPaths,
1818
+ loadPluginsFromDirectory,
1819
+ loadPlugins,
1612
1820
  createProgressSink,
1613
1821
  InMemoryStore,
1614
1822
  createAdapter,
1615
1823
  executeTask,
1616
1824
  executeWorkflow
1617
1825
  };
1618
- //# sourceMappingURL=chunk-FFCXUPYA.js.map
1826
+ //# sourceMappingURL=chunk-DPJFPYJO.js.map