agent-contracts 0.23.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +176 -154
- package/dist/cli.js.map +1 -1
- package/dist/index.js +99 -77
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50032,7 +50032,12 @@ function deepMergeEntities(base, project, path, hasExtends) {
|
|
|
50032
50032
|
} else if (isRecord2(baseVal)) {
|
|
50033
50033
|
result[key] = applyMapMergeOperator(baseVal, projVal, `${path}.${key}`);
|
|
50034
50034
|
} else {
|
|
50035
|
-
|
|
50035
|
+
const op = hasOperator(projVal, `${path}.${key}`);
|
|
50036
|
+
if (op === "$replace") {
|
|
50037
|
+
result[key] = projVal["$replace"];
|
|
50038
|
+
} else {
|
|
50039
|
+
result[key] = applyArrayMergeOperator([], projVal, `${path}.${key}`);
|
|
50040
|
+
}
|
|
50036
50041
|
}
|
|
50037
50042
|
} else if (isRecord2(projVal) && isRecord2(baseVal) && !Array.isArray(projVal) && !Array.isArray(baseVal)) {
|
|
50038
50043
|
result[key] = deepMergeEntities(
|
|
@@ -50048,6 +50053,40 @@ function deepMergeEntities(base, project, path, hasExtends) {
|
|
|
50048
50053
|
return result;
|
|
50049
50054
|
}
|
|
50050
50055
|
var OPERATOR_KEYS = /* @__PURE__ */ new Set(["$append", "$prepend", "$insert_after", "$replace", "$remove"]);
|
|
50056
|
+
function mergeSection(base, project, path, hasExtends, mode) {
|
|
50057
|
+
switch (mode) {
|
|
50058
|
+
case "map": {
|
|
50059
|
+
const baseMap = isRecord2(base) ? base : {};
|
|
50060
|
+
return mergeEntityMaps(baseMap, project, path, hasExtends);
|
|
50061
|
+
}
|
|
50062
|
+
case "array": {
|
|
50063
|
+
const baseArr = Array.isArray(base) ? base : [];
|
|
50064
|
+
if (isRecord2(project) && hasOperator(project, path)) {
|
|
50065
|
+
if (!hasExtends) {
|
|
50066
|
+
throw new MergeError(
|
|
50067
|
+
`Merge operator used without extends at ${path}`
|
|
50068
|
+
);
|
|
50069
|
+
}
|
|
50070
|
+
return applyArrayMergeOperator(baseArr, project, path);
|
|
50071
|
+
}
|
|
50072
|
+
const projArr = Array.isArray(project) ? project : [];
|
|
50073
|
+
return [...baseArr, ...projArr];
|
|
50074
|
+
}
|
|
50075
|
+
case "object": {
|
|
50076
|
+
const baseObj = isRecord2(base) ? base : {};
|
|
50077
|
+
const projObj = isRecord2(project) ? project : {};
|
|
50078
|
+
if (hasOperator(projObj, path)) {
|
|
50079
|
+
if (!hasExtends) {
|
|
50080
|
+
throw new MergeError(
|
|
50081
|
+
`Merge operator used without extends at ${path}`
|
|
50082
|
+
);
|
|
50083
|
+
}
|
|
50084
|
+
return applyMapMergeOperator(baseObj, projObj, path);
|
|
50085
|
+
}
|
|
50086
|
+
return deepMergeEntities(baseObj, projObj, path, hasExtends);
|
|
50087
|
+
}
|
|
50088
|
+
}
|
|
50089
|
+
}
|
|
50051
50090
|
function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
|
|
50052
50091
|
let result;
|
|
50053
50092
|
if (isRecord2(projectMap) && !Array.isArray(projectMap)) {
|
|
@@ -50068,9 +50107,10 @@ function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
|
|
|
50068
50107
|
for (const [key, projVal] of Object.entries(projectMap)) {
|
|
50069
50108
|
if (OPERATOR_KEYS.has(key)) continue;
|
|
50070
50109
|
const baseVal = result[key];
|
|
50071
|
-
if (
|
|
50110
|
+
if (isRecord2(projVal) && !Array.isArray(projVal)) {
|
|
50111
|
+
const baseObj = isRecord2(baseVal) ? baseVal : {};
|
|
50072
50112
|
result[key] = deepMergeEntities(
|
|
50073
|
-
|
|
50113
|
+
baseObj,
|
|
50074
50114
|
projVal,
|
|
50075
50115
|
`${path}.${key}`,
|
|
50076
50116
|
hasExtends
|
|
@@ -50081,44 +50121,33 @@ function mergeEntityMaps(baseMap, projectMap, path, hasExtends) {
|
|
|
50081
50121
|
}
|
|
50082
50122
|
return result;
|
|
50083
50123
|
}
|
|
50084
|
-
var
|
|
50085
|
-
|
|
50086
|
-
|
|
50087
|
-
|
|
50088
|
-
|
|
50089
|
-
|
|
50090
|
-
|
|
50091
|
-
|
|
50092
|
-
|
|
50093
|
-
|
|
50094
|
-
|
|
50095
|
-
|
|
50096
|
-
|
|
50097
|
-
|
|
50098
|
-
|
|
50124
|
+
var DSL_SECTIONS = {
|
|
50125
|
+
agents: "map",
|
|
50126
|
+
tasks: "map",
|
|
50127
|
+
artifacts: "map",
|
|
50128
|
+
tools: "map",
|
|
50129
|
+
validations: "map",
|
|
50130
|
+
handoff_types: "map",
|
|
50131
|
+
imports: "map",
|
|
50132
|
+
workflow: "map",
|
|
50133
|
+
policies: "map",
|
|
50134
|
+
guardrails: "map",
|
|
50135
|
+
guardrail_policies: "map",
|
|
50136
|
+
components: "map",
|
|
50137
|
+
extensions: "map",
|
|
50138
|
+
system: "object"
|
|
50139
|
+
};
|
|
50099
50140
|
function mergeDsl(base, project) {
|
|
50100
50141
|
const hasExtends = typeof project["extends"] === "string";
|
|
50101
50142
|
const result = { ...base, ...project };
|
|
50102
|
-
|
|
50103
|
-
|
|
50104
|
-
|
|
50105
|
-
|
|
50106
|
-
|
|
50107
|
-
hasExtends
|
|
50108
|
-
);
|
|
50109
|
-
}
|
|
50110
|
-
for (const section of MERGE_SECTIONS) {
|
|
50111
|
-
const baseVal = base[section];
|
|
50112
|
-
const projVal = project[section];
|
|
50113
|
-
if (projVal === void 0) {
|
|
50114
|
-
continue;
|
|
50115
|
-
}
|
|
50116
|
-
const baseMap = isRecord2(baseVal) ? baseVal : {};
|
|
50117
|
-
result[section] = mergeEntityMaps(
|
|
50118
|
-
baseMap,
|
|
50119
|
-
projVal,
|
|
50143
|
+
for (const [section, mode] of Object.entries(DSL_SECTIONS)) {
|
|
50144
|
+
if (project[section] === void 0) continue;
|
|
50145
|
+
result[section] = mergeSection(
|
|
50146
|
+
base[section],
|
|
50147
|
+
project[section],
|
|
50120
50148
|
section,
|
|
50121
|
-
hasExtends
|
|
50149
|
+
hasExtends,
|
|
50150
|
+
mode
|
|
50122
50151
|
);
|
|
50123
50152
|
}
|
|
50124
50153
|
delete result["extends"];
|
|
@@ -54141,8 +54170,16 @@ function filterIds(allIds, include, exclude) {
|
|
|
54141
54170
|
if (exclude) return allIds.filter((id) => !exclude.includes(id));
|
|
54142
54171
|
return allIds;
|
|
54143
54172
|
}
|
|
54144
|
-
function expandOutputPath(pattern, context, entityId) {
|
|
54145
|
-
return pattern.replace(
|
|
54173
|
+
function expandOutputPath(pattern, context, entityId, entity) {
|
|
54174
|
+
return pattern.replace(
|
|
54175
|
+
new RegExp(`\\{${context}\\.([^}]+)\\}`, "g"),
|
|
54176
|
+
(_match, field) => {
|
|
54177
|
+
if (field === "id") return entityId;
|
|
54178
|
+
if (entity === void 0) return _match;
|
|
54179
|
+
const value = entity[field];
|
|
54180
|
+
return typeof value === "string" ? value : _match;
|
|
54181
|
+
}
|
|
54182
|
+
);
|
|
54146
54183
|
}
|
|
54147
54184
|
function buildEntityContext(dsl, context, entityId) {
|
|
54148
54185
|
switch (context) {
|
|
@@ -54207,7 +54244,8 @@ async function renderFromConfig(dsl, renderTargets, options) {
|
|
|
54207
54244
|
for (const entityId of ids) {
|
|
54208
54245
|
const ctx = buildEntityContext(dsl, target.context, entityId);
|
|
54209
54246
|
const output = compiled(ctx);
|
|
54210
|
-
const
|
|
54247
|
+
const entity = section[entityId];
|
|
54248
|
+
const outputPath = expandOutputPath(target.output, target.context, entityId, entity);
|
|
54211
54249
|
if (target.skip_empty && isEffectivelyEmpty(output)) {
|
|
54212
54250
|
await removeIfExists(outputPath);
|
|
54213
54251
|
continue;
|
|
@@ -54256,7 +54294,8 @@ async function checkDriftFromConfig(dsl, renderTargets, options) {
|
|
|
54256
54294
|
for (const entityId of ids) {
|
|
54257
54295
|
const ctx = buildEntityContext(dsl, target.context, entityId);
|
|
54258
54296
|
const expected = compiled(ctx);
|
|
54259
|
-
const
|
|
54297
|
+
const entity = section[entityId];
|
|
54298
|
+
const outputPath = expandOutputPath(target.output, target.context, entityId, entity);
|
|
54260
54299
|
await checkExpectedVsExisting(expected, outputPath, target.skip_empty, diffs);
|
|
54261
54300
|
}
|
|
54262
54301
|
}
|
|
@@ -54471,42 +54510,23 @@ function resolveDslPath(dirArg, dirArgDefault, config) {
|
|
|
54471
54510
|
}
|
|
54472
54511
|
|
|
54473
54512
|
// src/config/binding-merger.ts
|
|
54474
|
-
|
|
54475
|
-
|
|
54476
|
-
|
|
54477
|
-
|
|
54478
|
-
|
|
54513
|
+
var BINDING_SECTIONS = {
|
|
54514
|
+
guardrail_impl: "map",
|
|
54515
|
+
outputs: "map",
|
|
54516
|
+
renders: "array",
|
|
54517
|
+
reporting: "object"
|
|
54518
|
+
};
|
|
54479
54519
|
function mergeBinding(base, project) {
|
|
54480
54520
|
const hasExtends = typeof project["extends"] === "string";
|
|
54481
54521
|
const result = { ...base, ...project };
|
|
54482
|
-
for (const section of
|
|
54483
|
-
|
|
54484
|
-
|
|
54485
|
-
|
|
54486
|
-
|
|
54487
|
-
}
|
|
54488
|
-
const baseMap = isRecord5(baseVal) ? baseVal : {};
|
|
54489
|
-
result[section] = mergeEntityMaps(
|
|
54490
|
-
baseMap,
|
|
54491
|
-
projVal,
|
|
54522
|
+
for (const [section, mode] of Object.entries(BINDING_SECTIONS)) {
|
|
54523
|
+
if (project[section] === void 0) continue;
|
|
54524
|
+
result[section] = mergeSection(
|
|
54525
|
+
base[section],
|
|
54526
|
+
project[section],
|
|
54492
54527
|
section,
|
|
54493
|
-
hasExtends
|
|
54494
|
-
|
|
54495
|
-
}
|
|
54496
|
-
for (const section of BINDING_ARRAY_MERGE_SECTIONS) {
|
|
54497
|
-
const baseVal = base[section];
|
|
54498
|
-
const projVal = project[section];
|
|
54499
|
-
if (projVal === void 0) continue;
|
|
54500
|
-
const baseArr = Array.isArray(baseVal) ? baseVal : [];
|
|
54501
|
-
const projArr = Array.isArray(projVal) ? projVal : [];
|
|
54502
|
-
result[section] = [...baseArr, ...projArr];
|
|
54503
|
-
}
|
|
54504
|
-
if (project["reporting"] !== void 0 && isRecord5(base["reporting"]) && isRecord5(project["reporting"])) {
|
|
54505
|
-
result["reporting"] = deepMergeEntities(
|
|
54506
|
-
base["reporting"],
|
|
54507
|
-
project["reporting"],
|
|
54508
|
-
"reporting",
|
|
54509
|
-
hasExtends
|
|
54528
|
+
hasExtends,
|
|
54529
|
+
mode
|
|
54510
54530
|
);
|
|
54511
54531
|
}
|
|
54512
54532
|
delete result["extends"];
|
|
@@ -54945,7 +54965,8 @@ async function loadRenderedFiles(dsl, renderTargets) {
|
|
|
54945
54965
|
const section = getDslSection(dsl, target.context);
|
|
54946
54966
|
const ids = filterIds(Object.keys(section), target.include, target.exclude);
|
|
54947
54967
|
for (const entityId of ids) {
|
|
54948
|
-
const
|
|
54968
|
+
const entity = section[entityId];
|
|
54969
|
+
const outputPath = expandOutputPath(target.output, target.context, entityId, entity);
|
|
54949
54970
|
try {
|
|
54950
54971
|
const content = await readFile5(outputPath, "utf8");
|
|
54951
54972
|
entries.push({ agent_id: entityId, path: outputPath, content });
|
|
@@ -54997,7 +55018,7 @@ function formatDslOverview(dsl) {
|
|
|
54997
55018
|
`- Validations: ${Object.keys(dsl.validations).join(", ")}`
|
|
54998
55019
|
].join("\n");
|
|
54999
55020
|
}
|
|
55000
|
-
function
|
|
55021
|
+
function isRecord5(v2) {
|
|
55001
55022
|
return typeof v2 === "object" && v2 !== null && !Array.isArray(v2);
|
|
55002
55023
|
}
|
|
55003
55024
|
function collectAllXUsages(dsl) {
|
|
@@ -55010,7 +55031,7 @@ function collectAllXUsages(dsl) {
|
|
|
55010
55031
|
}
|
|
55011
55032
|
}
|
|
55012
55033
|
walk(dsl, "", "root");
|
|
55013
|
-
if (
|
|
55034
|
+
if (isRecord5(dsl.system)) walk(dsl.system, "system", "system");
|
|
55014
55035
|
for (const [id, a3] of Object.entries(dsl.agents))
|
|
55015
55036
|
walk(a3, `agents.${id}`, "agent");
|
|
55016
55037
|
for (const [id, t3] of Object.entries(dsl.tasks))
|
|
@@ -56272,8 +56293,9 @@ async function generateGuardrails(options) {
|
|
|
56272
56293
|
const entityCtx = buildEntityContext(dsl, context, entityId);
|
|
56273
56294
|
const mergedCtx = { ...entityCtx, vars, paths, binding, resolved_checks: checkResult.resolved };
|
|
56274
56295
|
const rendered = compiled(mergedCtx);
|
|
56296
|
+
const entity = section[entityId];
|
|
56275
56297
|
const resolvedOutput = resolveBindingRenderOutputPath(
|
|
56276
|
-
expandOutputPath(renderTarget.output, context, entityId),
|
|
56298
|
+
expandOutputPath(renderTarget.output, context, entityId, entity),
|
|
56277
56299
|
paths
|
|
56278
56300
|
);
|
|
56279
56301
|
const outputPath = resolve6(config.configDir, resolvedOutput);
|