agent-contracts-runtime 0.36.6 → 0.36.8

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 (39) hide show
  1. package/cli-contract.yaml +76 -0
  2. package/dist/adapters/adk-sdk.d.ts +2 -2
  3. package/dist/adapters/adk-sdk.js +1 -1
  4. package/dist/adapters/claude-agent-sdk.d.ts +2 -2
  5. package/dist/adapters/mock.d.ts +1 -1
  6. package/dist/adapters/openai-agents-sdk.d.ts +2 -2
  7. package/dist/agent-runtime.bundle.mjs +584 -403
  8. package/dist/agent-runtime.bundle.mjs.map +4 -4
  9. package/dist/bound-resolver-K4UHLXN6.js +17 -0
  10. package/dist/bound-resolver-K4UHLXN6.js.map +1 -0
  11. package/dist/{chunk-FFCXUPYA.js → chunk-5UGCLWDM.js} +68 -281
  12. package/dist/chunk-5UGCLWDM.js.map +1 -0
  13. package/dist/chunk-D2QTXQB2.js +266 -0
  14. package/dist/chunk-D2QTXQB2.js.map +1 -0
  15. package/dist/chunk-LTZA6QWC.js +296 -0
  16. package/dist/chunk-LTZA6QWC.js.map +1 -0
  17. package/dist/{chunk-JDXRLHY3.js → chunk-MGRZBGQL.js} +20 -1
  18. package/dist/chunk-MGRZBGQL.js.map +1 -0
  19. package/dist/chunk-MWZXU25C.js +171 -0
  20. package/dist/chunk-MWZXU25C.js.map +1 -0
  21. package/dist/chunk-VOBS62OH.js +323 -0
  22. package/dist/chunk-VOBS62OH.js.map +1 -0
  23. package/dist/cli/index.js +95 -16
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/context-B_bekYiE.d.ts +106 -0
  26. package/dist/dsl-context-LACANPO4.js +13 -0
  27. package/dist/dsl-context-LACANPO4.js.map +1 -0
  28. package/dist/generator/index.d.ts +17 -106
  29. package/dist/generator/index.js +5 -3
  30. package/dist/{guardrail-hooks-B1_vgkE5.d.ts → guardrail-hooks-C8G5NGsj.d.ts} +8 -1
  31. package/dist/index.d.ts +80 -5
  32. package/dist/index.js +26 -9
  33. package/dist/{task-runner-C1bAy5k9.d.ts → task-runner-Bo37lS9q.d.ts} +5 -0
  34. package/docs/cli-reference.md +160 -0
  35. package/package.json +7 -2
  36. package/dist/chunk-FFCXUPYA.js.map +0 -1
  37. package/dist/chunk-JDXRLHY3.js.map +0 -1
  38. package/dist/chunk-KQOZCJK6.js +0 -593
  39. package/dist/chunk-KQOZCJK6.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ import {
2
+ BoundResolver,
3
+ buildPerAgentGuardrails,
4
+ getEffectiveGuardrailIds,
5
+ getGuardrailRulesForAgent,
6
+ guardrailContextToRuleData
7
+ } from "./chunk-MWZXU25C.js";
8
+ import "./chunk-LTZA6QWC.js";
9
+ import "./chunk-D2QTXQB2.js";
10
+ export {
11
+ BoundResolver,
12
+ buildPerAgentGuardrails,
13
+ getEffectiveGuardrailIds,
14
+ getGuardrailRulesForAgent,
15
+ guardrailContextToRuleData
16
+ };
17
+ //# sourceMappingURL=bound-resolver-K4UHLXN6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,7 +1,15 @@
1
+ import {
2
+ BoundResolver,
3
+ getGuardrailRulesForAgent
4
+ } from "./chunk-MWZXU25C.js";
1
5
  import {
2
6
  createGuardrailHooksFromRules,
3
7
  pluginRegistry
4
- } from "./chunk-JDXRLHY3.js";
8
+ } from "./chunk-MGRZBGQL.js";
9
+ import {
10
+ buildGuardrailRulesFromDsl,
11
+ loadDslContext
12
+ } from "./chunk-D2QTXQB2.js";
5
13
 
6
14
  // src/lib/task-runner.ts
7
15
  import { z } from "zod";
@@ -53,10 +61,12 @@ function buildCandidateAgents(agentRegistry, opts) {
53
61
  for (const [id, agent] of Object.entries(agentRegistry)) {
54
62
  if (id === entryId) continue;
55
63
  if (allowSet && !allowSet.has(id)) continue;
64
+ const tools = agent.can_execute_tools;
56
65
  candidates.push({
57
66
  name: id,
58
67
  description: deriveDescription(agent.purpose),
59
- prompt: renderAgentSystemPrompt(agent)
68
+ prompt: renderAgentSystemPrompt(agent),
69
+ ...tools && tools.length > 0 ? { tools: [...tools] } : {}
60
70
  });
61
71
  }
62
72
  return candidates;
@@ -1115,262 +1125,6 @@ async function loadPlugins(options) {
1115
1125
  return loadPluginsFromDirectory(conventionDir);
1116
1126
  }
1117
1127
 
1118
- // src/lib/dsl-context.ts
1119
- import { readFile } from "fs/promises";
1120
- import YAML from "yaml";
1121
-
1122
- // src/lib/schema-converter.ts
1123
- import { z as z2 } from "zod";
1124
- function applyStringValidations(schema, def) {
1125
- let s = schema;
1126
- if (typeof def.minLength === "number") s = s.min(def.minLength);
1127
- if (typeof def.maxLength === "number") s = s.max(def.maxLength);
1128
- if (typeof def.pattern === "string") s = s.regex(new RegExp(def.pattern));
1129
- return s;
1130
- }
1131
- function applyNumberValidations(schema, def, isInteger) {
1132
- let n = schema;
1133
- if (isInteger) n = n.int();
1134
- if (typeof def.minimum === "number") n = n.min(def.minimum);
1135
- if (typeof def.maximum === "number") n = n.max(def.maximum);
1136
- return n;
1137
- }
1138
- function applyArrayValidations(schema, def) {
1139
- let a = schema;
1140
- if (typeof def.minItems === "number") a = a.min(def.minItems);
1141
- if (typeof def.maxItems === "number") a = a.max(def.maxItems);
1142
- return a;
1143
- }
1144
- function jsonSchemaToZod(schema) {
1145
- if (!schema || typeof schema !== "object") return z2.unknown();
1146
- if (schema.enum) {
1147
- const vals = schema.enum;
1148
- if (vals.length === 0) return z2.unknown();
1149
- return z2.enum(vals);
1150
- }
1151
- if (schema.const !== void 0) {
1152
- const val = schema.const;
1153
- if (typeof val === "string" || typeof val === "number" || typeof val === "boolean") {
1154
- return z2.literal(val);
1155
- }
1156
- return z2.unknown();
1157
- }
1158
- const type = schema.type;
1159
- if (type === "string") return applyStringValidations(z2.string(), schema);
1160
- if (type === "integer") return applyNumberValidations(z2.number(), schema, true);
1161
- if (type === "number") return applyNumberValidations(z2.number(), schema, false);
1162
- if (type === "boolean") return z2.boolean();
1163
- if (type === "array") {
1164
- const items = schema.items;
1165
- const inner = items ? jsonSchemaToZod(items) : z2.unknown();
1166
- return applyArrayValidations(z2.array(inner), schema);
1167
- }
1168
- if (type === "object") {
1169
- const props = schema.properties;
1170
- if (!props) return z2.record(z2.string(), z2.unknown());
1171
- const required = new Set(schema.required ?? []);
1172
- const shape = {};
1173
- for (const [key, val] of Object.entries(props)) {
1174
- const fieldSchema = jsonSchemaToZod(val);
1175
- shape[key] = required.has(key) ? fieldSchema : fieldSchema.optional();
1176
- }
1177
- return z2.object(shape).passthrough();
1178
- }
1179
- if (schema.allOf) {
1180
- const parts = schema.allOf.map(jsonSchemaToZod);
1181
- if (parts.length === 0) return z2.unknown();
1182
- if (parts.length === 1) return parts[0];
1183
- let merged = parts[0];
1184
- for (let i = 1; i < parts.length; i++) {
1185
- const part = parts[i];
1186
- if (merged instanceof z2.ZodObject && part instanceof z2.ZodObject) {
1187
- merged = merged.merge(part);
1188
- }
1189
- }
1190
- return merged;
1191
- }
1192
- return z2.unknown();
1193
- }
1194
-
1195
- // src/lib/dsl-context.ts
1196
- var DslValidationError = class extends Error {
1197
- missing;
1198
- constructor(missing) {
1199
- super(
1200
- "Required entities missing after DSL merge:\n" + missing.map((m) => ` - ${m}`).join("\n")
1201
- );
1202
- this.name = "DslValidationError";
1203
- this.missing = missing;
1204
- }
1205
- };
1206
- function buildAgentRegistry(agents) {
1207
- const registry = {};
1208
- for (const [id, agent] of Object.entries(agents)) {
1209
- const rawMode = agent.mode ?? "read-only";
1210
- const mode = rawMode === "read-write" ? "read-write" : "read-only";
1211
- registry[id] = {
1212
- id,
1213
- role_name: agent.role_name ?? id,
1214
- purpose: agent.purpose ?? "",
1215
- mode,
1216
- responsibilities: agent.responsibilities ?? [],
1217
- constraints: agent.constraints ?? [],
1218
- rules: agent.rules ?? []
1219
- };
1220
- }
1221
- return registry;
1222
- }
1223
- function buildTaskRegistry(tasks) {
1224
- const registry = {};
1225
- for (const [id, task] of Object.entries(tasks)) {
1226
- registry[id] = {
1227
- id,
1228
- description: task.description ?? "",
1229
- target_agent: task.target_agent ?? "",
1230
- result_handoff: task.result_handoff ?? "",
1231
- completion_criteria: task.completion_criteria ?? [],
1232
- model_class: task.model_class
1233
- };
1234
- }
1235
- return registry;
1236
- }
1237
- function buildWorkflowStep(step) {
1238
- if (step.type === "gate") {
1239
- return {
1240
- type: "gate",
1241
- gate_kind: step.gate_kind ?? "",
1242
- description: step.description ?? "",
1243
- depends_on: step.depends_on
1244
- };
1245
- }
1246
- return {
1247
- type: "delegate",
1248
- task: step.task ?? "",
1249
- from_agent: step.from_agent ?? "",
1250
- description: step.description ?? "",
1251
- optional: step.optional ?? false,
1252
- max_retries: step.max_retries ?? 0,
1253
- max_follow_ups: step.max_follow_ups,
1254
- depends_on: step.depends_on,
1255
- retry: step.retry
1256
- };
1257
- }
1258
- function buildWorkflowRegistry(workflows) {
1259
- const registry = {};
1260
- for (const [id, wf] of Object.entries(workflows)) {
1261
- const steps = (wf.steps ?? []).map(buildWorkflowStep);
1262
- registry[id] = { id, description: wf.description ?? "", steps };
1263
- }
1264
- return registry;
1265
- }
1266
- function buildHandoffSchemas(handoffTypes) {
1267
- const schemas = {};
1268
- for (const [id, ht] of Object.entries(handoffTypes)) {
1269
- const schema = ht.schema;
1270
- if (schema) {
1271
- schemas[id] = jsonSchemaToZod(schema);
1272
- }
1273
- }
1274
- return schemas;
1275
- }
1276
- function buildGuardrailRulesFromDsl(dsl) {
1277
- const raw = dsl._guardrailRules;
1278
- if (!raw) return void 0;
1279
- return {
1280
- commandRules: raw.commandRules ?? [],
1281
- fileRules: raw.fileRules ?? [],
1282
- contentRules: raw.contentRules ?? []
1283
- };
1284
- }
1285
- function buildRegistriesFromDsl(dsl) {
1286
- const agents = dsl.agents ?? {};
1287
- const tasks = dsl.tasks ?? {};
1288
- const workflows = dsl.workflow ?? {};
1289
- const handoffTypes = dsl.handoff_types ?? {};
1290
- return {
1291
- agentRegistry: buildAgentRegistry(agents),
1292
- taskRegistry: buildTaskRegistry(tasks),
1293
- workflowRegistry: buildWorkflowRegistry(workflows),
1294
- handoffSchemas: buildHandoffSchemas(handoffTypes)
1295
- };
1296
- }
1297
- function validateRequiredEntities(dsl, required) {
1298
- const missing = [];
1299
- const workflows = dsl.workflow ?? {};
1300
- const tasks = dsl.tasks ?? {};
1301
- const handoffTypes = dsl.handoff_types ?? {};
1302
- if (required.workflows) {
1303
- for (const wfId of required.workflows) {
1304
- if (!(wfId in workflows)) {
1305
- missing.push(`workflow "${wfId}" is required by the CLI but not found in the resolved DSL`);
1306
- }
1307
- }
1308
- }
1309
- if (required.tasks) {
1310
- for (const taskId of required.tasks) {
1311
- if (!(taskId in tasks)) {
1312
- missing.push(`task "${taskId}" is required by the CLI but not found in the resolved DSL`);
1313
- continue;
1314
- }
1315
- const task = tasks[taskId];
1316
- const invHandoff = task.invocation_handoff;
1317
- const resHandoff = task.result_handoff;
1318
- if (invHandoff && !(invHandoff in handoffTypes)) {
1319
- missing.push(`handoff_type "${invHandoff}" (invocation_handoff of task "${taskId}") not found`);
1320
- }
1321
- if (resHandoff && !(resHandoff in handoffTypes)) {
1322
- missing.push(`handoff_type "${resHandoff}" (result_handoff of task "${taskId}") not found`);
1323
- }
1324
- }
1325
- }
1326
- if (required.workflows) {
1327
- for (const wfId of required.workflows) {
1328
- if (!(wfId in workflows)) continue;
1329
- const wf = workflows[wfId];
1330
- const steps = wf.steps ?? [];
1331
- for (const step of steps) {
1332
- if (step.type !== "delegate") continue;
1333
- const taskId = step.task;
1334
- if (taskId && taskId in tasks) {
1335
- const task = tasks[taskId];
1336
- const resHandoff = task.result_handoff;
1337
- if (resHandoff && !(resHandoff in handoffTypes)) {
1338
- missing.push(`handoff_type "${resHandoff}" (result of task "${taskId}" in workflow "${wfId}") not found`);
1339
- }
1340
- }
1341
- }
1342
- }
1343
- }
1344
- if (missing.length > 0) {
1345
- throw new DslValidationError(missing);
1346
- }
1347
- }
1348
- async function loadDslContext(options) {
1349
- let dsl;
1350
- if (options.projectDslPath) {
1351
- const { resolve: resolveDsl, mergeDsl, expandDefaults } = await import("agent-contracts");
1352
- const raw = await readFile(options.projectDslPath, "utf8");
1353
- const projectData = YAML.parse(raw);
1354
- if (projectData.extends === "/$embedded/") {
1355
- const { extends: _extends, ...projectOverrides } = projectData;
1356
- const merged = mergeDsl(options.embeddedDsl, projectOverrides);
1357
- dsl = expandDefaults(merged);
1358
- } else {
1359
- const projectResult = await resolveDsl(options.projectDslPath);
1360
- const merged = mergeDsl(options.embeddedDsl, projectResult.data);
1361
- dsl = expandDefaults(merged);
1362
- }
1363
- } else {
1364
- dsl = options.embeddedDsl;
1365
- }
1366
- if (options.requiredEntities) {
1367
- validateRequiredEntities(dsl, options.requiredEntities);
1368
- }
1369
- const registries = buildRegistriesFromDsl(dsl);
1370
- const guardrailRules = buildGuardrailRulesFromDsl(dsl);
1371
- return { registries, dsl, guardrailRules };
1372
- }
1373
-
1374
1128
  // src/lib/progress-sink.ts
1375
1129
  import { openSync, writeSync, closeSync, mkdirSync } from "fs";
1376
1130
  import { dirname, join as join2, basename, extname } from "path";
@@ -1504,16 +1258,60 @@ Install it with: npm install ${pkg}`
1504
1258
 
1505
1259
  // src/lib/execute.ts
1506
1260
  import { resolve as resolve2 } from "path";
1507
- async function executeTask(taskId, options) {
1261
+ async function resolveExecutionContext(options, requiredEntities) {
1262
+ const useBoundResolver = options.resolvedComponent || options.bindingPaths && options.bindingPaths.length > 0 || options.artifactBinding;
1263
+ if (useBoundResolver) {
1264
+ const component = options.resolvedComponent ?? await new BoundResolver().resolve({
1265
+ id: options.componentId ?? "default",
1266
+ embeddedDsl: options.dsl,
1267
+ bindingPaths: options.bindingPaths,
1268
+ activeGuardrailPolicy: options.activeGuardrailPolicy,
1269
+ artifactBinding: options.artifactBinding,
1270
+ paths: options.paths
1271
+ });
1272
+ if (requiredEntities) {
1273
+ const ctx2 = await loadDslContext({
1274
+ embeddedDsl: component.dsl,
1275
+ requiredEntities
1276
+ });
1277
+ return { registries: ctx2.registries, dsl: component.dsl, resolvedComponent: component };
1278
+ }
1279
+ return {
1280
+ registries: component.registries,
1281
+ dsl: component.dsl,
1282
+ resolvedComponent: component
1283
+ };
1284
+ }
1508
1285
  const ctx = await loadDslContext({
1509
1286
  embeddedDsl: options.dsl,
1510
1287
  projectDslPath: options.projectDslPath,
1511
- requiredEntities: { tasks: [taskId] }
1288
+ requiredEntities
1512
1289
  });
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);
1290
+ return { registries: ctx.registries, dsl: ctx.dsl };
1291
+ }
1292
+ function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
1293
+ if (adapterOptions.guardrailHooks) return;
1294
+ if (execCtx.resolvedComponent && targetAgentId) {
1295
+ const rules2 = getGuardrailRulesForAgent(
1296
+ execCtx.resolvedComponent,
1297
+ targetAgentId,
1298
+ execCtx.dsl
1299
+ );
1300
+ if (rules2 && (rules2.commandRules.length > 0 || rules2.fileRules.length > 0 || rules2.contentRules.length > 0)) {
1301
+ adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules2);
1302
+ }
1303
+ return;
1516
1304
  }
1305
+ const rules = buildGuardrailRulesFromDsl(execCtx.dsl);
1306
+ if (rules && (rules.commandRules.length > 0 || rules.fileRules.length > 0 || rules.contentRules.length > 0)) {
1307
+ adapterOptions.guardrailHooks = createGuardrailHooksFromRules(rules);
1308
+ }
1309
+ }
1310
+ async function executeTask(taskId, options) {
1311
+ const execCtx = await resolveExecutionContext(options, { tasks: [taskId] });
1312
+ const targetAgentId = execCtx.registries.taskRegistry?.[taskId]?.target_agent;
1313
+ const adapterOptions = { ...options.adapterOptions };
1314
+ injectGuardrailHooks(adapterOptions, execCtx, targetAgentId);
1517
1315
  const adapter = await createAdapter(options.adapter, {
1518
1316
  model: options.model,
1519
1317
  ...adapterOptions
@@ -1523,13 +1321,13 @@ async function executeTask(taskId, options) {
1523
1321
  );
1524
1322
  try {
1525
1323
  if (options.hooks?.beforeTask) {
1526
- await options.hooks.beforeTask({ adapter, registries: ctx.registries, taskId });
1324
+ await options.hooks.beforeTask({ adapter, registries: execCtx.registries, taskId });
1527
1325
  }
1528
1326
  const result = await runTask(adapter, taskId, { user_request: options.request }, {
1529
1327
  maxFollowUps: options.maxFollowUps ?? 2,
1530
1328
  maxRetries: options.maxRetries ?? 0,
1531
1329
  progressOutput: progressSink,
1532
- ...ctx.registries
1330
+ ...execCtx.registries
1533
1331
  });
1534
1332
  if (options.hooks?.afterTask) {
1535
1333
  await options.hooks.afterTask(result);
@@ -1540,15 +1338,9 @@ async function executeTask(taskId, options) {
1540
1338
  }
1541
1339
  }
1542
1340
  async function executeWorkflow(workflowId, options) {
1543
- const ctx = await loadDslContext({
1544
- embeddedDsl: options.dsl,
1545
- projectDslPath: options.projectDslPath,
1546
- requiredEntities: { workflows: [workflowId] }
1547
- });
1341
+ const execCtx = await resolveExecutionContext(options, { workflows: [workflowId] });
1548
1342
  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
- }
1343
+ injectGuardrailHooks(adapterOptions, execCtx);
1552
1344
  const adapter = await createAdapter(options.adapter, {
1553
1345
  model: options.model,
1554
1346
  ...adapterOptions
@@ -1558,7 +1350,7 @@ async function executeWorkflow(workflowId, options) {
1558
1350
  );
1559
1351
  try {
1560
1352
  if (options.hooks?.beforeWorkflow) {
1561
- await options.hooks.beforeWorkflow({ adapter, registries: ctx.registries, workflowId });
1353
+ await options.hooks.beforeWorkflow({ adapter, registries: execCtx.registries, workflowId });
1562
1354
  }
1563
1355
  const invocation = {
1564
1356
  workflow: workflowId,
@@ -1576,7 +1368,7 @@ async function executeWorkflow(workflowId, options) {
1576
1368
  },
1577
1369
  context: options.context
1578
1370
  };
1579
- const result = await runWorkflow(adapter, invocation, ctx.registries);
1371
+ const result = await runWorkflow(adapter, invocation, execCtx.registries);
1580
1372
  if (options.hooks?.afterWorkflow) {
1581
1373
  await options.hooks.afterWorkflow(result);
1582
1374
  }
@@ -1604,15 +1396,10 @@ export {
1604
1396
  loadPluginsFromPaths,
1605
1397
  loadPluginsFromDirectory,
1606
1398
  loadPlugins,
1607
- jsonSchemaToZod,
1608
- DslValidationError,
1609
- buildGuardrailRulesFromDsl,
1610
- buildRegistriesFromDsl,
1611
- loadDslContext,
1612
1399
  createProgressSink,
1613
1400
  InMemoryStore,
1614
1401
  createAdapter,
1615
1402
  executeTask,
1616
1403
  executeWorkflow
1617
1404
  };
1618
- //# sourceMappingURL=chunk-FFCXUPYA.js.map
1405
+ //# sourceMappingURL=chunk-5UGCLWDM.js.map