agent-contracts-runtime 0.36.16 → 0.36.17
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/README.md +6 -65
- package/cli-contract.yaml +3 -3
- package/dist/agent-runtime.bundle.mjs +521 -725
- package/dist/agent-runtime.bundle.mjs.map +4 -4
- package/dist/{chunk-6JVGBBP3.js → chunk-VKCNOSMQ.js} +324 -18
- package/dist/chunk-VKCNOSMQ.js.map +1 -0
- package/dist/cli/index.js +16 -22
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +12 -14
- package/dist/{task-runner-CD8nnKpn.d.ts → task-runner-DJW49UGZ.d.ts} +3 -4
- package/docs/cli-reference.md +1 -1
- package/docs/sdk-options-bridge-spec.md +4 -3
- package/dsl/agents/llm-feature-implementer.yaml +2 -4
- package/dsl/tasks.yaml +1 -5
- package/package.json +5 -20
- package/templates/implement-reference-templates.md +3 -17
- package/templates/implement-reference.md +3 -3
- package/dist/adapters/adk-sdk.d.ts +0 -129
- package/dist/adapters/adk-sdk.js +0 -185
- package/dist/adapters/adk-sdk.js.map +0 -1
- package/dist/chunk-6JVGBBP3.js.map +0 -1
- package/dist/chunk-M57HVYUU.js +0 -325
- package/dist/chunk-M57HVYUU.js.map +0 -1
|
@@ -2,10 +2,6 @@ import {
|
|
|
2
2
|
BoundResolver,
|
|
3
3
|
getGuardrailRulesForAgent
|
|
4
4
|
} from "./chunk-2E2LWE6C.js";
|
|
5
|
-
import {
|
|
6
|
-
createGuardrailHooksFromRules,
|
|
7
|
-
pluginRegistry
|
|
8
|
-
} from "./chunk-M57HVYUU.js";
|
|
9
5
|
import {
|
|
10
6
|
buildGuardrailRulesFromDsl,
|
|
11
7
|
loadDslContext
|
|
@@ -15,6 +11,101 @@ import {
|
|
|
15
11
|
import { z } from "zod";
|
|
16
12
|
import * as yaml from "yaml";
|
|
17
13
|
|
|
14
|
+
// src/lib/plugin.ts
|
|
15
|
+
var PluginRegistry = class {
|
|
16
|
+
plugins = [];
|
|
17
|
+
register(plugin) {
|
|
18
|
+
if (this.plugins.some((p) => p.id === plugin.id)) {
|
|
19
|
+
throw new Error(`Plugin "${plugin.id}" is already registered`);
|
|
20
|
+
}
|
|
21
|
+
this.plugins.push(plugin);
|
|
22
|
+
}
|
|
23
|
+
getAll() {
|
|
24
|
+
return this.plugins;
|
|
25
|
+
}
|
|
26
|
+
async runBeforeTask(taskId, context) {
|
|
27
|
+
let ctx = context;
|
|
28
|
+
for (const plugin of this.plugins) {
|
|
29
|
+
if (!plugin.beforeTask || ctx === null) continue;
|
|
30
|
+
ctx = await plugin.beforeTask(taskId, ctx);
|
|
31
|
+
}
|
|
32
|
+
return ctx;
|
|
33
|
+
}
|
|
34
|
+
async runAfterTask(taskId, outcome) {
|
|
35
|
+
let result = outcome;
|
|
36
|
+
for (const plugin of this.plugins) {
|
|
37
|
+
if (!plugin.afterTask) continue;
|
|
38
|
+
result = await plugin.afterTask(taskId, result);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
applyContextEnhancers(taskId, context) {
|
|
43
|
+
let ctx = context;
|
|
44
|
+
for (const plugin of this.plugins) {
|
|
45
|
+
if (!plugin.contextEnhancer) continue;
|
|
46
|
+
ctx = plugin.contextEnhancer(taskId, ctx);
|
|
47
|
+
}
|
|
48
|
+
return ctx;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Try plugin promptBuilder hooks. Returns custom prompt if any plugin provides one,
|
|
52
|
+
* or null to use the default buildTaskPrompt.
|
|
53
|
+
*/
|
|
54
|
+
applyPromptBuilder(args) {
|
|
55
|
+
for (const plugin of this.plugins) {
|
|
56
|
+
if (!plugin.promptBuilder) continue;
|
|
57
|
+
const result = plugin.promptBuilder(args);
|
|
58
|
+
if (result !== null) return result;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
applyPromptEnhancers(taskId, prompt, context) {
|
|
63
|
+
let enhanced = prompt;
|
|
64
|
+
for (const plugin of this.plugins) {
|
|
65
|
+
if (!plugin.promptEnhancer) continue;
|
|
66
|
+
enhanced = plugin.promptEnhancer(taskId, enhanced, context);
|
|
67
|
+
}
|
|
68
|
+
return enhanced;
|
|
69
|
+
}
|
|
70
|
+
evaluateCommandGuardrails(command) {
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const plugin of this.plugins) {
|
|
73
|
+
if (!plugin.customGuardrails?.evaluateCommand) continue;
|
|
74
|
+
results.push(...plugin.customGuardrails.evaluateCommand(command));
|
|
75
|
+
}
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
evaluateFilePathGuardrails(filePath) {
|
|
79
|
+
const results = [];
|
|
80
|
+
for (const plugin of this.plugins) {
|
|
81
|
+
if (!plugin.customGuardrails?.evaluateFilePath) continue;
|
|
82
|
+
results.push(...plugin.customGuardrails.evaluateFilePath(filePath));
|
|
83
|
+
}
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
86
|
+
evaluateFileContentGuardrails(filePath, content) {
|
|
87
|
+
const results = [];
|
|
88
|
+
for (const plugin of this.plugins) {
|
|
89
|
+
if (!plugin.customGuardrails?.evaluateFileContent) continue;
|
|
90
|
+
results.push(...plugin.customGuardrails.evaluateFileContent(filePath, content));
|
|
91
|
+
}
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
async runBeforeWorkflow(workflowId, userRequest) {
|
|
95
|
+
for (const plugin of this.plugins) {
|
|
96
|
+
if (!plugin.beforeWorkflow) continue;
|
|
97
|
+
await plugin.beforeWorkflow(workflowId, userRequest);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
async runAfterWorkflow(workflowId, result) {
|
|
101
|
+
for (const plugin of this.plugins) {
|
|
102
|
+
if (!plugin.afterWorkflow) continue;
|
|
103
|
+
await plugin.afterWorkflow(workflowId, result);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var pluginRegistry = new PluginRegistry();
|
|
108
|
+
|
|
18
109
|
// src/lib/candidate-agents.ts
|
|
19
110
|
function renderAgentSystemPrompt(agent) {
|
|
20
111
|
const sections = [];
|
|
@@ -978,6 +1069,225 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
|
|
|
978
1069
|
});
|
|
979
1070
|
}
|
|
980
1071
|
|
|
1072
|
+
// src/lib/guardrail-hooks.ts
|
|
1073
|
+
function globFragmentToRegex(fragment) {
|
|
1074
|
+
let out = "";
|
|
1075
|
+
for (const ch of fragment) {
|
|
1076
|
+
if (ch === "*") out += "[^/]*";
|
|
1077
|
+
else if (ch === "?") out += "[^/]";
|
|
1078
|
+
else if (".+^$|()[]\\".includes(ch)) out += "\\" + ch;
|
|
1079
|
+
else out += ch;
|
|
1080
|
+
}
|
|
1081
|
+
return out;
|
|
1082
|
+
}
|
|
1083
|
+
function matchGlob(pattern, path) {
|
|
1084
|
+
let regex = "";
|
|
1085
|
+
let i = 0;
|
|
1086
|
+
while (i < pattern.length) {
|
|
1087
|
+
if (pattern[i] === "*" && pattern[i + 1] === "*" && pattern[i + 2] === "/") {
|
|
1088
|
+
regex += "(?:.+/)?";
|
|
1089
|
+
i += 3;
|
|
1090
|
+
} else if (pattern[i] === "*" && pattern[i + 1] === "*") {
|
|
1091
|
+
regex += ".*";
|
|
1092
|
+
i += 2;
|
|
1093
|
+
} else if (pattern[i] === "*") {
|
|
1094
|
+
regex += "[^/]*";
|
|
1095
|
+
i += 1;
|
|
1096
|
+
} else if (pattern[i] === "?") {
|
|
1097
|
+
regex += "[^/]";
|
|
1098
|
+
i += 1;
|
|
1099
|
+
} else if (pattern[i] === "{") {
|
|
1100
|
+
const end = pattern.indexOf("}", i);
|
|
1101
|
+
if (end !== -1) {
|
|
1102
|
+
const alts = pattern.slice(i + 1, end).split(",").map(globFragmentToRegex);
|
|
1103
|
+
regex += "(?:" + alts.join("|") + ")";
|
|
1104
|
+
i = end + 1;
|
|
1105
|
+
} else {
|
|
1106
|
+
regex += "\\{";
|
|
1107
|
+
i += 1;
|
|
1108
|
+
}
|
|
1109
|
+
} else if (".+^$|()[]\\".includes(pattern[i])) {
|
|
1110
|
+
regex += "\\" + pattern[i];
|
|
1111
|
+
i += 1;
|
|
1112
|
+
} else {
|
|
1113
|
+
regex += pattern[i];
|
|
1114
|
+
i += 1;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return new RegExp("^" + regex + "$").test(path);
|
|
1118
|
+
}
|
|
1119
|
+
function getBlockingViolations(results) {
|
|
1120
|
+
return results.filter((r) => !r.passed && r.action === "block");
|
|
1121
|
+
}
|
|
1122
|
+
function getWarnings(results) {
|
|
1123
|
+
return results.filter((r) => !r.passed && r.action === "warn");
|
|
1124
|
+
}
|
|
1125
|
+
function hasBlockingViolation(results) {
|
|
1126
|
+
return results.some((r) => !r.passed && r.action === "block");
|
|
1127
|
+
}
|
|
1128
|
+
function pluginResultToCheckResult(r) {
|
|
1129
|
+
return {
|
|
1130
|
+
guardrail_id: r.guardrail_id,
|
|
1131
|
+
passed: !r.matched,
|
|
1132
|
+
action: r.action,
|
|
1133
|
+
message: r.matched ? r.message : ""
|
|
1134
|
+
};
|
|
1135
|
+
}
|
|
1136
|
+
function createGuardrailHooks(checks) {
|
|
1137
|
+
function runChecks(ctx) {
|
|
1138
|
+
const results = [];
|
|
1139
|
+
if (ctx.command) {
|
|
1140
|
+
results.push(...checks.checkCommand(ctx.command));
|
|
1141
|
+
results.push(
|
|
1142
|
+
...pluginRegistry.evaluateCommandGuardrails(ctx.command).map(pluginResultToCheckResult)
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
if (ctx.filePath) {
|
|
1146
|
+
results.push(...checks.checkFilePath(ctx.filePath));
|
|
1147
|
+
results.push(
|
|
1148
|
+
...pluginRegistry.evaluateFilePathGuardrails(ctx.filePath).map(pluginResultToCheckResult)
|
|
1149
|
+
);
|
|
1150
|
+
}
|
|
1151
|
+
if (ctx.filePath && ctx.content) {
|
|
1152
|
+
results.push(...checks.checkContent(ctx.filePath, ctx.content));
|
|
1153
|
+
results.push(
|
|
1154
|
+
...pluginRegistry.evaluateFileContentGuardrails(ctx.filePath, ctx.content).map(pluginResultToCheckResult)
|
|
1155
|
+
);
|
|
1156
|
+
}
|
|
1157
|
+
return results;
|
|
1158
|
+
}
|
|
1159
|
+
function beforeShellExecution(input) {
|
|
1160
|
+
const command = input.command ?? "";
|
|
1161
|
+
if (!command) return {};
|
|
1162
|
+
const results = runChecks({ command });
|
|
1163
|
+
const blocks = getBlockingViolations(results);
|
|
1164
|
+
const warns = getWarnings(results);
|
|
1165
|
+
if (blocks.length > 0) {
|
|
1166
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1167
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1168
|
+
}
|
|
1169
|
+
if (warns.length > 0) {
|
|
1170
|
+
return {
|
|
1171
|
+
additionalContext: warns.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n")
|
|
1172
|
+
};
|
|
1173
|
+
}
|
|
1174
|
+
return {};
|
|
1175
|
+
}
|
|
1176
|
+
function preToolUse(input) {
|
|
1177
|
+
const filePath = input.tool_input?.file_path ?? input.tool_input?.path ?? "";
|
|
1178
|
+
if (!filePath) return {};
|
|
1179
|
+
const results = runChecks({ filePath });
|
|
1180
|
+
const blocks = getBlockingViolations(results);
|
|
1181
|
+
if (blocks.length > 0) {
|
|
1182
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1183
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1184
|
+
}
|
|
1185
|
+
return {};
|
|
1186
|
+
}
|
|
1187
|
+
function afterFileEdit(input) {
|
|
1188
|
+
const filePath = input.file_path ?? "";
|
|
1189
|
+
const content = input.content ?? "";
|
|
1190
|
+
if (!filePath) return {};
|
|
1191
|
+
const results = runChecks({ filePath, content });
|
|
1192
|
+
const blocks = getBlockingViolations(results);
|
|
1193
|
+
if (blocks.length > 0) {
|
|
1194
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1195
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1196
|
+
}
|
|
1197
|
+
return {};
|
|
1198
|
+
}
|
|
1199
|
+
return { beforeShellExecution, preToolUse, afterFileEdit, runChecks };
|
|
1200
|
+
}
|
|
1201
|
+
function createGuardrailHooksForAgent(agentId, perAgent) {
|
|
1202
|
+
const rules = perAgent.get(agentId);
|
|
1203
|
+
if (!rules) {
|
|
1204
|
+
return createGuardrailHooks({
|
|
1205
|
+
checkCommand: () => [],
|
|
1206
|
+
checkFilePath: () => [],
|
|
1207
|
+
checkContent: () => []
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
const hooks = createGuardrailHooksFromRules(rules);
|
|
1211
|
+
const baseRunChecks = hooks.runChecks;
|
|
1212
|
+
return {
|
|
1213
|
+
...hooks,
|
|
1214
|
+
runChecks(ctx) {
|
|
1215
|
+
return baseRunChecks({ ...ctx, agentId });
|
|
1216
|
+
}
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
function compileRulePattern(pattern) {
|
|
1220
|
+
const inline = /^\(\?([ims]+)\)/.exec(pattern);
|
|
1221
|
+
return inline ? new RegExp(pattern.slice(inline[0].length), inline[1]) : new RegExp(pattern);
|
|
1222
|
+
}
|
|
1223
|
+
function createGuardrailHooksFromRules(rules) {
|
|
1224
|
+
const commandChecks = rules.commandRules.map((rule) => ({
|
|
1225
|
+
guardrail_id: rule.guardrail_id,
|
|
1226
|
+
pattern: compileRulePattern(rule.pattern),
|
|
1227
|
+
action: rule.action,
|
|
1228
|
+
message: rule.message
|
|
1229
|
+
}));
|
|
1230
|
+
const fileChecks = rules.fileRules;
|
|
1231
|
+
const contentChecks = rules.contentRules.map((rule) => ({
|
|
1232
|
+
guardrail_id: rule.guardrail_id,
|
|
1233
|
+
pattern: compileRulePattern(rule.pattern),
|
|
1234
|
+
action: rule.action,
|
|
1235
|
+
message: rule.message,
|
|
1236
|
+
file_glob: rule.file_glob,
|
|
1237
|
+
exclude_glob: rule.exclude_glob
|
|
1238
|
+
}));
|
|
1239
|
+
return createGuardrailHooks({
|
|
1240
|
+
checkCommand(command) {
|
|
1241
|
+
const results = [];
|
|
1242
|
+
for (const check of commandChecks) {
|
|
1243
|
+
const passed = !check.pattern.test(command);
|
|
1244
|
+
results.push({
|
|
1245
|
+
guardrail_id: check.guardrail_id,
|
|
1246
|
+
passed,
|
|
1247
|
+
action: check.action,
|
|
1248
|
+
message: passed ? "" : check.message
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
return results;
|
|
1252
|
+
},
|
|
1253
|
+
checkFilePath(filePath) {
|
|
1254
|
+
const results = [];
|
|
1255
|
+
for (const check of fileChecks) {
|
|
1256
|
+
if (check.exclude_glob && matchGlob(check.exclude_glob, filePath)) {
|
|
1257
|
+
continue;
|
|
1258
|
+
}
|
|
1259
|
+
const matched = matchGlob(check.pattern, filePath);
|
|
1260
|
+
results.push({
|
|
1261
|
+
guardrail_id: check.guardrail_id,
|
|
1262
|
+
passed: !matched,
|
|
1263
|
+
action: check.action,
|
|
1264
|
+
message: matched ? check.message : ""
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
return results;
|
|
1268
|
+
},
|
|
1269
|
+
checkContent(filePath, content) {
|
|
1270
|
+
const results = [];
|
|
1271
|
+
for (const check of contentChecks) {
|
|
1272
|
+
if (check.file_glob && !matchGlob(check.file_glob, filePath)) {
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
if (check.exclude_glob && matchGlob(check.exclude_glob, filePath)) {
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
const matched = check.pattern.test(content);
|
|
1279
|
+
results.push({
|
|
1280
|
+
guardrail_id: check.guardrail_id,
|
|
1281
|
+
passed: !matched,
|
|
1282
|
+
action: check.action,
|
|
1283
|
+
message: matched ? check.message : ""
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
return results;
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1290
|
+
|
|
981
1291
|
// src/lib/builder.ts
|
|
982
1292
|
function createRuntime(config) {
|
|
983
1293
|
return {
|
|
@@ -1192,7 +1502,6 @@ var InMemoryStore = class {
|
|
|
1192
1502
|
// src/lib/adapter-factory.ts
|
|
1193
1503
|
var ADAPTER_PACKAGES = {
|
|
1194
1504
|
claude: "@anthropic-ai/claude-agent-sdk",
|
|
1195
|
-
gemini: "@google/adk",
|
|
1196
1505
|
openai: "@openai/agents"
|
|
1197
1506
|
};
|
|
1198
1507
|
async function createAdapter(name, options) {
|
|
@@ -1216,17 +1525,6 @@ async function createAdapter(name, options) {
|
|
|
1216
1525
|
throwMissingPackageError("claude", err);
|
|
1217
1526
|
}
|
|
1218
1527
|
}
|
|
1219
|
-
case "gemini": {
|
|
1220
|
-
try {
|
|
1221
|
-
const { AdkSdkAdapter } = await import("./adapters/adk-sdk.js");
|
|
1222
|
-
return new AdkSdkAdapter({
|
|
1223
|
-
guardrailHooks,
|
|
1224
|
-
...model ? { model } : {}
|
|
1225
|
-
});
|
|
1226
|
-
} catch (err) {
|
|
1227
|
-
throwMissingPackageError("gemini", err);
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
1528
|
case "openai": {
|
|
1231
1529
|
try {
|
|
1232
1530
|
const { OpenAIAgentsSdkAdapter } = await import("./adapters/openai-agents-sdk.js");
|
|
@@ -1240,7 +1538,7 @@ async function createAdapter(name, options) {
|
|
|
1240
1538
|
}
|
|
1241
1539
|
default:
|
|
1242
1540
|
throw new Error(
|
|
1243
|
-
`Unknown adapter: "${name}". Available: mock, claude, openai
|
|
1541
|
+
`Unknown adapter: "${name}". Available: mock, claude, openai`
|
|
1244
1542
|
);
|
|
1245
1543
|
}
|
|
1246
1544
|
}
|
|
@@ -1379,6 +1677,8 @@ async function executeWorkflow(workflowId, options) {
|
|
|
1379
1677
|
}
|
|
1380
1678
|
|
|
1381
1679
|
export {
|
|
1680
|
+
PluginRegistry,
|
|
1681
|
+
pluginRegistry,
|
|
1382
1682
|
renderAgentSystemPrompt,
|
|
1383
1683
|
buildCandidateAgents,
|
|
1384
1684
|
zodSchemaToPromptDescription,
|
|
@@ -1391,6 +1691,12 @@ export {
|
|
|
1391
1691
|
runWorkflow,
|
|
1392
1692
|
buildGateEvaluationPrompt,
|
|
1393
1693
|
parseGateEvaluationResponse,
|
|
1694
|
+
getBlockingViolations,
|
|
1695
|
+
getWarnings,
|
|
1696
|
+
hasBlockingViolation,
|
|
1697
|
+
createGuardrailHooks,
|
|
1698
|
+
createGuardrailHooksForAgent,
|
|
1699
|
+
createGuardrailHooksFromRules,
|
|
1394
1700
|
createRuntime,
|
|
1395
1701
|
WorkflowBuilder,
|
|
1396
1702
|
loadPluginsFromPaths,
|
|
@@ -1402,4 +1708,4 @@ export {
|
|
|
1402
1708
|
executeTask,
|
|
1403
1709
|
executeWorkflow
|
|
1404
1710
|
};
|
|
1405
|
-
//# sourceMappingURL=chunk-
|
|
1711
|
+
//# sourceMappingURL=chunk-VKCNOSMQ.js.map
|