agent-contracts-runtime 0.36.16 → 0.36.18
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/adapters/claude-agent-sdk.d.ts +2 -0
- package/dist/adapters/claude-agent-sdk.js +21 -7
- package/dist/adapters/claude-agent-sdk.js.map +1 -1
- package/dist/adapters/mock.js +3 -37
- package/dist/adapters/mock.js.map +1 -1
- package/dist/agent-runtime.bundle.mjs +523 -725
- package/dist/agent-runtime.bundle.mjs.map +4 -4
- package/dist/{bound-resolver-I7WLYGC6.js → bound-resolver-RPJYAOCW.js} +4 -4
- package/dist/{chunk-S7MTKPBF.js → chunk-CFOEW6XJ.js} +4 -25
- package/dist/chunk-CFOEW6XJ.js.map +1 -0
- package/dist/chunk-KB4VDAAQ.js +740 -0
- package/dist/chunk-KB4VDAAQ.js.map +1 -0
- package/dist/chunk-L5OAGF7D.js +42 -0
- package/dist/chunk-L5OAGF7D.js.map +1 -0
- package/dist/{chunk-6JVGBBP3.js → chunk-UHHKLLA3.js} +375 -58
- package/dist/chunk-UHHKLLA3.js.map +1 -0
- package/dist/cli/index.js +40 -57
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.js +2 -2
- package/dist/{guardrail-hooks-CFd3a8tQ.d.ts → guardrail-hooks-BiLI9u9-.d.ts} +12 -6
- package/dist/index.d.ts +13 -6
- package/dist/index.js +17 -21
- package/dist/{task-runner-CD8nnKpn.d.ts → task-runner-Ba4kLv7O.d.ts} +5 -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-2E2LWE6C.js +0 -171
- package/dist/chunk-2E2LWE6C.js.map +0 -1
- package/dist/chunk-6JVGBBP3.js.map +0 -1
- package/dist/chunk-D2QTXQB2.js +0 -266
- package/dist/chunk-D2QTXQB2.js.map +0 -1
- package/dist/chunk-KKJW4TE5.js +0 -302
- package/dist/chunk-KKJW4TE5.js.map +0 -1
- package/dist/chunk-M57HVYUU.js +0 -325
- package/dist/chunk-M57HVYUU.js.map +0 -1
- package/dist/chunk-S7MTKPBF.js.map +0 -1
- package/dist/dsl-context-LACANPO4.js +0 -13
- package/dist/dsl-context-LACANPO4.js.map +0 -1
- /package/dist/{bound-resolver-I7WLYGC6.js.map → bound-resolver-RPJYAOCW.js.map} +0 -0
|
@@ -1,20 +1,113 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-2E2LWE6C.js";
|
|
5
|
-
import {
|
|
6
|
-
createGuardrailHooksFromRules,
|
|
7
|
-
pluginRegistry
|
|
8
|
-
} from "./chunk-M57HVYUU.js";
|
|
2
|
+
MockAdapter
|
|
3
|
+
} from "./chunk-L5OAGF7D.js";
|
|
9
4
|
import {
|
|
5
|
+
BoundResolver,
|
|
10
6
|
buildGuardrailRulesFromDsl,
|
|
7
|
+
getGuardrailRulesForAgent,
|
|
8
|
+
getGuardrailRulesForComponent,
|
|
11
9
|
loadDslContext
|
|
12
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-KB4VDAAQ.js";
|
|
13
11
|
|
|
14
12
|
// src/lib/task-runner.ts
|
|
15
13
|
import { z } from "zod";
|
|
16
14
|
import * as yaml from "yaml";
|
|
17
15
|
|
|
16
|
+
// src/lib/plugin.ts
|
|
17
|
+
var PluginRegistry = class {
|
|
18
|
+
plugins = [];
|
|
19
|
+
register(plugin) {
|
|
20
|
+
if (this.plugins.some((p) => p.id === plugin.id)) {
|
|
21
|
+
throw new Error(`Plugin "${plugin.id}" is already registered`);
|
|
22
|
+
}
|
|
23
|
+
this.plugins.push(plugin);
|
|
24
|
+
}
|
|
25
|
+
getAll() {
|
|
26
|
+
return this.plugins;
|
|
27
|
+
}
|
|
28
|
+
async runBeforeTask(taskId, context) {
|
|
29
|
+
let ctx = context;
|
|
30
|
+
for (const plugin of this.plugins) {
|
|
31
|
+
if (!plugin.beforeTask || ctx === null) continue;
|
|
32
|
+
ctx = await plugin.beforeTask(taskId, ctx);
|
|
33
|
+
}
|
|
34
|
+
return ctx;
|
|
35
|
+
}
|
|
36
|
+
async runAfterTask(taskId, outcome) {
|
|
37
|
+
let result = outcome;
|
|
38
|
+
for (const plugin of this.plugins) {
|
|
39
|
+
if (!plugin.afterTask) continue;
|
|
40
|
+
result = await plugin.afterTask(taskId, result);
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
applyContextEnhancers(taskId, context) {
|
|
45
|
+
let ctx = context;
|
|
46
|
+
for (const plugin of this.plugins) {
|
|
47
|
+
if (!plugin.contextEnhancer) continue;
|
|
48
|
+
ctx = plugin.contextEnhancer(taskId, ctx);
|
|
49
|
+
}
|
|
50
|
+
return ctx;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Try plugin promptBuilder hooks. Returns custom prompt if any plugin provides one,
|
|
54
|
+
* or null to use the default buildTaskPrompt.
|
|
55
|
+
*/
|
|
56
|
+
applyPromptBuilder(args) {
|
|
57
|
+
for (const plugin of this.plugins) {
|
|
58
|
+
if (!plugin.promptBuilder) continue;
|
|
59
|
+
const result = plugin.promptBuilder(args);
|
|
60
|
+
if (result !== null) return result;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
applyPromptEnhancers(taskId, prompt, context) {
|
|
65
|
+
let enhanced = prompt;
|
|
66
|
+
for (const plugin of this.plugins) {
|
|
67
|
+
if (!plugin.promptEnhancer) continue;
|
|
68
|
+
enhanced = plugin.promptEnhancer(taskId, enhanced, context);
|
|
69
|
+
}
|
|
70
|
+
return enhanced;
|
|
71
|
+
}
|
|
72
|
+
evaluateCommandGuardrails(command) {
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const plugin of this.plugins) {
|
|
75
|
+
if (!plugin.customGuardrails?.evaluateCommand) continue;
|
|
76
|
+
results.push(...plugin.customGuardrails.evaluateCommand(command));
|
|
77
|
+
}
|
|
78
|
+
return results;
|
|
79
|
+
}
|
|
80
|
+
evaluateFilePathGuardrails(filePath) {
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const plugin of this.plugins) {
|
|
83
|
+
if (!plugin.customGuardrails?.evaluateFilePath) continue;
|
|
84
|
+
results.push(...plugin.customGuardrails.evaluateFilePath(filePath));
|
|
85
|
+
}
|
|
86
|
+
return results;
|
|
87
|
+
}
|
|
88
|
+
evaluateFileContentGuardrails(filePath, content) {
|
|
89
|
+
const results = [];
|
|
90
|
+
for (const plugin of this.plugins) {
|
|
91
|
+
if (!plugin.customGuardrails?.evaluateFileContent) continue;
|
|
92
|
+
results.push(...plugin.customGuardrails.evaluateFileContent(filePath, content));
|
|
93
|
+
}
|
|
94
|
+
return results;
|
|
95
|
+
}
|
|
96
|
+
async runBeforeWorkflow(workflowId, userRequest) {
|
|
97
|
+
for (const plugin of this.plugins) {
|
|
98
|
+
if (!plugin.beforeWorkflow) continue;
|
|
99
|
+
await plugin.beforeWorkflow(workflowId, userRequest);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async runAfterWorkflow(workflowId, result) {
|
|
103
|
+
for (const plugin of this.plugins) {
|
|
104
|
+
if (!plugin.afterWorkflow) continue;
|
|
105
|
+
await plugin.afterWorkflow(workflowId, result);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var pluginRegistry = new PluginRegistry();
|
|
110
|
+
|
|
18
111
|
// src/lib/candidate-agents.ts
|
|
19
112
|
function renderAgentSystemPrompt(agent) {
|
|
20
113
|
const sections = [];
|
|
@@ -179,11 +272,11 @@ function collectFieldTables(schema, pathPrefix, tables) {
|
|
|
179
272
|
|
|
180
273
|
` : "";
|
|
181
274
|
const header = "| Field | Type | Required | Constraints | Description |";
|
|
182
|
-
const
|
|
275
|
+
const sep2 = "|-------|------|----------|-------------|-------------|";
|
|
183
276
|
const rows = fields.map(
|
|
184
277
|
(f) => `| ${f.name} | ${f.type} | ${f.required ? "Yes" : "No"} | ${f.constraints ?? ""} | ${f.description ?? ""} |`
|
|
185
278
|
);
|
|
186
|
-
tables.push(`${title}${[header,
|
|
279
|
+
tables.push(`${title}${[header, sep2, ...rows].join("\n")}`);
|
|
187
280
|
const shape = schema instanceof z.ZodObject ? schema.shape : null;
|
|
188
281
|
if (!shape) return;
|
|
189
282
|
for (const f of fields) {
|
|
@@ -533,7 +626,7 @@ async function runTask(adapter, taskId, context, options) {
|
|
|
533
626
|
splitPrompt = void 0;
|
|
534
627
|
prompt = enhancedPrompt;
|
|
535
628
|
}
|
|
536
|
-
const isReadonly = agentContract.mode === "read-only";
|
|
629
|
+
const isReadonly = agentContract.mode === "read-only" || options?.readonly === true;
|
|
537
630
|
const allowDynamicWorkflow = task.allow_dynamic_workflow ?? false;
|
|
538
631
|
const candidateAgents = Object.keys(agentReg).length > 0 ? buildCandidateAgents(agentReg, {
|
|
539
632
|
entryAgentId: agentContract.id,
|
|
@@ -673,6 +766,8 @@ function resolveInvocation(invocation) {
|
|
|
673
766
|
user_request: userRequest,
|
|
674
767
|
maxFollowUps: invocation.runtime?.maxFollowUps,
|
|
675
768
|
maxRetries: invocation.runtime?.maxRetries,
|
|
769
|
+
readonly: invocation.runtime?.readonly,
|
|
770
|
+
dryRun: invocation.runtime?.dryRun,
|
|
676
771
|
variables: Object.keys(variables).length > 0 ? variables : void 0,
|
|
677
772
|
onGate: invocation.hooks?.onGate,
|
|
678
773
|
onStepComplete: invocation.hooks?.onStepComplete,
|
|
@@ -682,7 +777,6 @@ function resolveInvocation(invocation) {
|
|
|
682
777
|
};
|
|
683
778
|
}
|
|
684
779
|
async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRegistries, maybeRegistries) {
|
|
685
|
-
const { adapter: primaryAdapter, factory: adapterFactory } = resolveAdapter(adapterOrFactory);
|
|
686
780
|
let workflowId;
|
|
687
781
|
let options;
|
|
688
782
|
let registries;
|
|
@@ -698,6 +792,9 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
698
792
|
registries = optionsOrRegistries;
|
|
699
793
|
invocationHandoff = workflowIdOrInvocation.handoff;
|
|
700
794
|
}
|
|
795
|
+
const { adapter: primaryAdapter, factory: adapterFactory } = resolveAdapter(
|
|
796
|
+
options.dryRun ? new MockAdapter() : adapterOrFactory
|
|
797
|
+
);
|
|
701
798
|
if (invocationHandoff && registries?.handoffSchemas) {
|
|
702
799
|
const inputSchema = registries.handoffSchemas[invocationHandoff.type];
|
|
703
800
|
if (inputSchema) {
|
|
@@ -784,7 +881,8 @@ async function runWorkflow(adapterOrFactory, workflowIdOrInvocation, optionsOrRe
|
|
|
784
881
|
agentRegistry: registries?.agentRegistry,
|
|
785
882
|
handoffSchemas: registries?.handoffSchemas,
|
|
786
883
|
retry: step.retry,
|
|
787
|
-
progressOutput: options.progressOutput
|
|
884
|
+
progressOutput: options.progressOutput,
|
|
885
|
+
readonly: options.readonly
|
|
788
886
|
});
|
|
789
887
|
return {
|
|
790
888
|
step_index: i,
|
|
@@ -906,7 +1004,7 @@ async function handleGateStep(step, priorResults, options, stepIndex, adapter) {
|
|
|
906
1004
|
return {
|
|
907
1005
|
step_index: stepIndex,
|
|
908
1006
|
gate_kind: step.gate_kind,
|
|
909
|
-
outcome: { status: "
|
|
1007
|
+
outcome: { status: "gate_rejected" },
|
|
910
1008
|
follow_ups_used: 0,
|
|
911
1009
|
retries_used: 0,
|
|
912
1010
|
elapsed_ms: Date.now() - start
|
|
@@ -978,6 +1076,240 @@ function emitStepEvent(options, workflowId, stepIndex, step, result) {
|
|
|
978
1076
|
});
|
|
979
1077
|
}
|
|
980
1078
|
|
|
1079
|
+
// src/lib/guardrail-hooks.ts
|
|
1080
|
+
import { realpathSync } from "fs";
|
|
1081
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
1082
|
+
function globFragmentToRegex(fragment) {
|
|
1083
|
+
let out = "";
|
|
1084
|
+
for (const ch of fragment) {
|
|
1085
|
+
if (ch === "*") out += "[^/]*";
|
|
1086
|
+
else if (ch === "?") out += "[^/]";
|
|
1087
|
+
else if (".+^$|()[]\\".includes(ch)) out += "\\" + ch;
|
|
1088
|
+
else out += ch;
|
|
1089
|
+
}
|
|
1090
|
+
return out;
|
|
1091
|
+
}
|
|
1092
|
+
function matchGlob(pattern, path) {
|
|
1093
|
+
let regex = "";
|
|
1094
|
+
let i = 0;
|
|
1095
|
+
while (i < pattern.length) {
|
|
1096
|
+
if (pattern[i] === "*" && pattern[i + 1] === "*" && pattern[i + 2] === "/") {
|
|
1097
|
+
regex += "(?:.+/)?";
|
|
1098
|
+
i += 3;
|
|
1099
|
+
} else if (pattern[i] === "*" && pattern[i + 1] === "*") {
|
|
1100
|
+
regex += ".*";
|
|
1101
|
+
i += 2;
|
|
1102
|
+
} else if (pattern[i] === "*") {
|
|
1103
|
+
regex += "[^/]*";
|
|
1104
|
+
i += 1;
|
|
1105
|
+
} else if (pattern[i] === "?") {
|
|
1106
|
+
regex += "[^/]";
|
|
1107
|
+
i += 1;
|
|
1108
|
+
} else if (pattern[i] === "{") {
|
|
1109
|
+
const end = pattern.indexOf("}", i);
|
|
1110
|
+
if (end !== -1) {
|
|
1111
|
+
const alts = pattern.slice(i + 1, end).split(",").map(globFragmentToRegex);
|
|
1112
|
+
regex += "(?:" + alts.join("|") + ")";
|
|
1113
|
+
i = end + 1;
|
|
1114
|
+
} else {
|
|
1115
|
+
regex += "\\{";
|
|
1116
|
+
i += 1;
|
|
1117
|
+
}
|
|
1118
|
+
} else if (".+^$|()[]\\".includes(pattern[i])) {
|
|
1119
|
+
regex += "\\" + pattern[i];
|
|
1120
|
+
i += 1;
|
|
1121
|
+
} else {
|
|
1122
|
+
regex += pattern[i];
|
|
1123
|
+
i += 1;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
return new RegExp("^" + regex + "$").test(path);
|
|
1127
|
+
}
|
|
1128
|
+
function realPathAsFarAsItExists(path) {
|
|
1129
|
+
const missing = [];
|
|
1130
|
+
let head = path;
|
|
1131
|
+
for (; ; ) {
|
|
1132
|
+
try {
|
|
1133
|
+
return join(realpathSync(head), ...missing);
|
|
1134
|
+
} catch {
|
|
1135
|
+
const parent = dirname(head);
|
|
1136
|
+
if (parent === head) return path;
|
|
1137
|
+
missing.unshift(basename(head));
|
|
1138
|
+
head = parent;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
function rootRelativeTarget(path, root) {
|
|
1143
|
+
const absolute = resolve(root, path);
|
|
1144
|
+
const rel = relative(realPathAsFarAsItExists(root), realPathAsFarAsItExists(absolute));
|
|
1145
|
+
const outside = rel === "" || isAbsolute(rel) || rel.split(sep)[0] === "..";
|
|
1146
|
+
return outside ? absolute : rel.split(sep).join("/");
|
|
1147
|
+
}
|
|
1148
|
+
function getBlockingViolations(results) {
|
|
1149
|
+
return results.filter((r) => !r.passed && r.action === "block");
|
|
1150
|
+
}
|
|
1151
|
+
function getWarnings(results) {
|
|
1152
|
+
return results.filter((r) => !r.passed && r.action === "warn");
|
|
1153
|
+
}
|
|
1154
|
+
function hasBlockingViolation(results) {
|
|
1155
|
+
return results.some((r) => !r.passed && r.action === "block");
|
|
1156
|
+
}
|
|
1157
|
+
function pluginResultToCheckResult(r) {
|
|
1158
|
+
return {
|
|
1159
|
+
guardrail_id: r.guardrail_id,
|
|
1160
|
+
passed: !r.matched,
|
|
1161
|
+
action: r.action,
|
|
1162
|
+
message: r.matched ? r.message : ""
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
function createGuardrailHooks(checks) {
|
|
1166
|
+
function runChecks(ctx) {
|
|
1167
|
+
const results = [];
|
|
1168
|
+
if (ctx.command) {
|
|
1169
|
+
results.push(...checks.checkCommand(ctx.command));
|
|
1170
|
+
results.push(
|
|
1171
|
+
...pluginRegistry.evaluateCommandGuardrails(ctx.command).map(pluginResultToCheckResult)
|
|
1172
|
+
);
|
|
1173
|
+
}
|
|
1174
|
+
if (ctx.filePath) {
|
|
1175
|
+
results.push(...checks.checkFilePath(ctx.filePath));
|
|
1176
|
+
results.push(
|
|
1177
|
+
...pluginRegistry.evaluateFilePathGuardrails(ctx.filePath).map(pluginResultToCheckResult)
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
if (ctx.filePath && ctx.content) {
|
|
1181
|
+
results.push(...checks.checkContent(ctx.filePath, ctx.content));
|
|
1182
|
+
results.push(
|
|
1183
|
+
...pluginRegistry.evaluateFileContentGuardrails(ctx.filePath, ctx.content).map(pluginResultToCheckResult)
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
return results;
|
|
1187
|
+
}
|
|
1188
|
+
function beforeShellExecution(input) {
|
|
1189
|
+
const command = input.command ?? "";
|
|
1190
|
+
if (!command) return {};
|
|
1191
|
+
const results = runChecks({ command });
|
|
1192
|
+
const blocks = getBlockingViolations(results);
|
|
1193
|
+
const warns = getWarnings(results);
|
|
1194
|
+
if (blocks.length > 0) {
|
|
1195
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1196
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1197
|
+
}
|
|
1198
|
+
if (warns.length > 0) {
|
|
1199
|
+
return {
|
|
1200
|
+
additionalContext: warns.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n")
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
return {};
|
|
1204
|
+
}
|
|
1205
|
+
function preToolUse(input, root) {
|
|
1206
|
+
const target = input.tool_input?.file_path ?? input.tool_input?.path ?? "";
|
|
1207
|
+
if (!target) return {};
|
|
1208
|
+
const filePath = rootRelativeTarget(target, root ?? process.cwd());
|
|
1209
|
+
const results = runChecks({ filePath, content: input.tool_input?.content });
|
|
1210
|
+
const blocks = getBlockingViolations(results);
|
|
1211
|
+
if (blocks.length > 0) {
|
|
1212
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1213
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1214
|
+
}
|
|
1215
|
+
return {};
|
|
1216
|
+
}
|
|
1217
|
+
function afterFileEdit(input) {
|
|
1218
|
+
const filePath = input.file_path ?? "";
|
|
1219
|
+
const content = input.content ?? "";
|
|
1220
|
+
if (!filePath) return {};
|
|
1221
|
+
const results = runChecks({ filePath, content });
|
|
1222
|
+
const blocks = getBlockingViolations(results);
|
|
1223
|
+
if (blocks.length > 0) {
|
|
1224
|
+
const msg = blocks.map((r) => `[${r.guardrail_id}] ${r.message}`).join("\n");
|
|
1225
|
+
return { permission: "deny", user_message: msg, agent_message: msg };
|
|
1226
|
+
}
|
|
1227
|
+
return {};
|
|
1228
|
+
}
|
|
1229
|
+
return { beforeShellExecution, preToolUse, afterFileEdit, runChecks };
|
|
1230
|
+
}
|
|
1231
|
+
function createGuardrailHooksForAgent(agentId, perAgent) {
|
|
1232
|
+
const hooks = createGuardrailHooksFromRules(perAgent.get(agentId));
|
|
1233
|
+
const baseRunChecks = hooks.runChecks;
|
|
1234
|
+
return {
|
|
1235
|
+
...hooks,
|
|
1236
|
+
runChecks(ctx) {
|
|
1237
|
+
return baseRunChecks({ ...ctx, agentId });
|
|
1238
|
+
}
|
|
1239
|
+
};
|
|
1240
|
+
}
|
|
1241
|
+
function compileRulePattern(pattern) {
|
|
1242
|
+
const inline = /^\(\?([ims]+)\)/.exec(pattern);
|
|
1243
|
+
return inline ? new RegExp(pattern.slice(inline[0].length), inline[1]) : new RegExp(pattern);
|
|
1244
|
+
}
|
|
1245
|
+
function createGuardrailHooksFromRules(rules) {
|
|
1246
|
+
const commandChecks = (rules?.commandRules ?? []).map((rule) => ({
|
|
1247
|
+
guardrail_id: rule.guardrail_id,
|
|
1248
|
+
pattern: compileRulePattern(rule.pattern),
|
|
1249
|
+
action: rule.action,
|
|
1250
|
+
message: rule.message
|
|
1251
|
+
}));
|
|
1252
|
+
const fileChecks = rules?.fileRules ?? [];
|
|
1253
|
+
const contentChecks = (rules?.contentRules ?? []).map((rule) => ({
|
|
1254
|
+
guardrail_id: rule.guardrail_id,
|
|
1255
|
+
pattern: compileRulePattern(rule.pattern),
|
|
1256
|
+
action: rule.action,
|
|
1257
|
+
message: rule.message,
|
|
1258
|
+
file_glob: rule.file_glob,
|
|
1259
|
+
exclude_glob: rule.exclude_glob
|
|
1260
|
+
}));
|
|
1261
|
+
return createGuardrailHooks({
|
|
1262
|
+
checkCommand(command) {
|
|
1263
|
+
const results = [];
|
|
1264
|
+
for (const check of commandChecks) {
|
|
1265
|
+
const passed = !check.pattern.test(command);
|
|
1266
|
+
results.push({
|
|
1267
|
+
guardrail_id: check.guardrail_id,
|
|
1268
|
+
passed,
|
|
1269
|
+
action: check.action,
|
|
1270
|
+
message: passed ? "" : check.message
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
return results;
|
|
1274
|
+
},
|
|
1275
|
+
checkFilePath(filePath) {
|
|
1276
|
+
const results = [];
|
|
1277
|
+
for (const check of fileChecks) {
|
|
1278
|
+
if (check.exclude_glob && matchGlob(check.exclude_glob, filePath)) {
|
|
1279
|
+
continue;
|
|
1280
|
+
}
|
|
1281
|
+
const matched = matchGlob(check.pattern, filePath);
|
|
1282
|
+
results.push({
|
|
1283
|
+
guardrail_id: check.guardrail_id,
|
|
1284
|
+
passed: !matched,
|
|
1285
|
+
action: check.action,
|
|
1286
|
+
message: matched ? check.message : ""
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
return results;
|
|
1290
|
+
},
|
|
1291
|
+
checkContent(filePath, content) {
|
|
1292
|
+
const results = [];
|
|
1293
|
+
for (const check of contentChecks) {
|
|
1294
|
+
if (check.file_glob && !matchGlob(check.file_glob, filePath)) {
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
if (check.exclude_glob && matchGlob(check.exclude_glob, filePath)) {
|
|
1298
|
+
continue;
|
|
1299
|
+
}
|
|
1300
|
+
const matched = check.pattern.test(content);
|
|
1301
|
+
results.push({
|
|
1302
|
+
guardrail_id: check.guardrail_id,
|
|
1303
|
+
passed: !matched,
|
|
1304
|
+
action: check.action,
|
|
1305
|
+
message: matched ? check.message : ""
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
return results;
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
|
|
981
1313
|
// src/lib/builder.ts
|
|
982
1314
|
function createRuntime(config) {
|
|
983
1315
|
return {
|
|
@@ -1053,7 +1385,7 @@ var WorkflowBuilder = class {
|
|
|
1053
1385
|
// src/lib/plugin-loader.ts
|
|
1054
1386
|
import { existsSync } from "fs";
|
|
1055
1387
|
import { readdir } from "fs/promises";
|
|
1056
|
-
import { resolve, join } from "path";
|
|
1388
|
+
import { resolve as resolve2, join as join2 } from "path";
|
|
1057
1389
|
var PLUGIN_EXTENSIONS = [".ts", ".js", ".mts", ".mjs"];
|
|
1058
1390
|
function isPluginLike(obj) {
|
|
1059
1391
|
return typeof obj === "object" && obj !== null && typeof obj.id === "string";
|
|
@@ -1063,7 +1395,7 @@ async function scanDirectory(dir) {
|
|
|
1063
1395
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
1064
1396
|
return entries.filter(
|
|
1065
1397
|
(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")
|
|
1066
|
-
).map((e) =>
|
|
1398
|
+
).map((e) => resolve2(dir, e.name));
|
|
1067
1399
|
}
|
|
1068
1400
|
async function loadPluginModule(modulePath) {
|
|
1069
1401
|
const mod = await import(new URL(`file://${modulePath}`).href);
|
|
@@ -1082,7 +1414,7 @@ async function loadPluginModule(modulePath) {
|
|
|
1082
1414
|
async function loadPluginsFromPaths(paths, baseDir) {
|
|
1083
1415
|
const result = { loaded: 0, files: [], errors: [] };
|
|
1084
1416
|
for (const p of paths) {
|
|
1085
|
-
const absPath =
|
|
1417
|
+
const absPath = resolve2(baseDir, p);
|
|
1086
1418
|
if (!existsSync(absPath)) {
|
|
1087
1419
|
result.errors.push({ file: p, error: `File not found: ${absPath}` });
|
|
1088
1420
|
continue;
|
|
@@ -1121,27 +1453,27 @@ async function loadPlugins(options) {
|
|
|
1121
1453
|
if (options.pluginPaths && options.pluginPaths.length > 0) {
|
|
1122
1454
|
return loadPluginsFromPaths(options.pluginPaths, options.projectDir);
|
|
1123
1455
|
}
|
|
1124
|
-
const conventionDir =
|
|
1456
|
+
const conventionDir = join2(options.projectDir, "src", "plugins");
|
|
1125
1457
|
return loadPluginsFromDirectory(conventionDir);
|
|
1126
1458
|
}
|
|
1127
1459
|
|
|
1128
1460
|
// src/lib/progress-sink.ts
|
|
1129
1461
|
import { openSync, writeSync, closeSync, mkdirSync } from "fs";
|
|
1130
|
-
import { dirname, join as
|
|
1462
|
+
import { dirname as dirname2, join as join3, basename as basename2, extname } from "path";
|
|
1131
1463
|
function resolveFilePath(base, naming, label) {
|
|
1132
1464
|
if (naming === "single") return base;
|
|
1133
|
-
const dir =
|
|
1465
|
+
const dir = dirname2(base);
|
|
1134
1466
|
const ext = extname(base);
|
|
1135
|
-
const stem =
|
|
1467
|
+
const stem = basename2(base, ext);
|
|
1136
1468
|
const now = /* @__PURE__ */ new Date();
|
|
1137
1469
|
if (naming === "daily") {
|
|
1138
1470
|
const date = now.toISOString().slice(0, 10);
|
|
1139
|
-
return
|
|
1471
|
+
return join3(dir, `${stem}-${date}${ext}`);
|
|
1140
1472
|
}
|
|
1141
1473
|
const pad = (n) => String(n).padStart(2, "0");
|
|
1142
1474
|
const ts = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}T${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
|
|
1143
1475
|
const suffix = label ? `-${label}` : "";
|
|
1144
|
-
return
|
|
1476
|
+
return join3(dir, `${stem}-${ts}${suffix}${ext}`);
|
|
1145
1477
|
}
|
|
1146
1478
|
function createProgressSink(options) {
|
|
1147
1479
|
const useStderr = options.stderr ?? false;
|
|
@@ -1150,7 +1482,7 @@ function createProgressSink(options) {
|
|
|
1150
1482
|
if (options.file) {
|
|
1151
1483
|
const naming = options.naming ?? "single";
|
|
1152
1484
|
resolvedPath = resolveFilePath(options.file, naming, options.label);
|
|
1153
|
-
mkdirSync(
|
|
1485
|
+
mkdirSync(dirname2(resolvedPath), { recursive: true });
|
|
1154
1486
|
fd = openSync(resolvedPath, "a");
|
|
1155
1487
|
}
|
|
1156
1488
|
if (!useStderr && fd === null) {
|
|
@@ -1192,15 +1524,14 @@ var InMemoryStore = class {
|
|
|
1192
1524
|
// src/lib/adapter-factory.ts
|
|
1193
1525
|
var ADAPTER_PACKAGES = {
|
|
1194
1526
|
claude: "@anthropic-ai/claude-agent-sdk",
|
|
1195
|
-
gemini: "@google/adk",
|
|
1196
1527
|
openai: "@openai/agents"
|
|
1197
1528
|
};
|
|
1198
1529
|
async function createAdapter(name, options) {
|
|
1199
1530
|
const { model, cwd, tools, permissionMode, guardrailHooks } = options ?? {};
|
|
1200
1531
|
switch (name) {
|
|
1201
1532
|
case "mock": {
|
|
1202
|
-
const { MockAdapter } = await import("./adapters/mock.js");
|
|
1203
|
-
return new
|
|
1533
|
+
const { MockAdapter: MockAdapter2 } = await import("./adapters/mock.js");
|
|
1534
|
+
return new MockAdapter2();
|
|
1204
1535
|
}
|
|
1205
1536
|
case "claude": {
|
|
1206
1537
|
try {
|
|
@@ -1216,17 +1547,6 @@ async function createAdapter(name, options) {
|
|
|
1216
1547
|
throwMissingPackageError("claude", err);
|
|
1217
1548
|
}
|
|
1218
1549
|
}
|
|
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
1550
|
case "openai": {
|
|
1231
1551
|
try {
|
|
1232
1552
|
const { OpenAIAgentsSdkAdapter } = await import("./adapters/openai-agents-sdk.js");
|
|
@@ -1240,7 +1560,7 @@ async function createAdapter(name, options) {
|
|
|
1240
1560
|
}
|
|
1241
1561
|
default:
|
|
1242
1562
|
throw new Error(
|
|
1243
|
-
`Unknown adapter: "${name}". Available: mock, claude, openai
|
|
1563
|
+
`Unknown adapter: "${name}". Available: mock, claude, openai`
|
|
1244
1564
|
);
|
|
1245
1565
|
}
|
|
1246
1566
|
}
|
|
@@ -1257,7 +1577,7 @@ Install it with: npm install ${pkg}`
|
|
|
1257
1577
|
}
|
|
1258
1578
|
|
|
1259
1579
|
// src/lib/execute.ts
|
|
1260
|
-
import { resolve as
|
|
1580
|
+
import { resolve as resolve3 } from "path";
|
|
1261
1581
|
async function resolveExecutionContext(options, requiredEntities) {
|
|
1262
1582
|
const useBoundResolver = options.resolvedComponent || options.bindingPaths && options.bindingPaths.length > 0 || options.artifactBinding;
|
|
1263
1583
|
if (useBoundResolver) {
|
|
@@ -1291,21 +1611,10 @@ async function resolveExecutionContext(options, requiredEntities) {
|
|
|
1291
1611
|
}
|
|
1292
1612
|
function injectGuardrailHooks(adapterOptions, execCtx, targetAgentId) {
|
|
1293
1613
|
if (adapterOptions.guardrailHooks) return;
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
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;
|
|
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
|
-
}
|
|
1614
|
+
const component = execCtx.resolvedComponent;
|
|
1615
|
+
adapterOptions.guardrailHooks = createGuardrailHooksFromRules(
|
|
1616
|
+
!component ? buildGuardrailRulesFromDsl(execCtx.dsl) : targetAgentId ? getGuardrailRulesForAgent(component, targetAgentId, execCtx.dsl) : getGuardrailRulesForComponent(component, execCtx.dsl)
|
|
1617
|
+
);
|
|
1309
1618
|
}
|
|
1310
1619
|
async function executeTask(taskId, options) {
|
|
1311
1620
|
const execCtx = await resolveExecutionContext(options, { tasks: [taskId] });
|
|
@@ -1317,7 +1626,7 @@ async function executeTask(taskId, options) {
|
|
|
1317
1626
|
...adapterOptions
|
|
1318
1627
|
});
|
|
1319
1628
|
const progressSink = createProgressSink(
|
|
1320
|
-
options.logFile ? { stderr: true, file:
|
|
1629
|
+
options.logFile ? { stderr: true, file: resolve3(options.logFile), naming: "single" } : { stderr: true }
|
|
1321
1630
|
);
|
|
1322
1631
|
try {
|
|
1323
1632
|
if (options.hooks?.beforeTask) {
|
|
@@ -1346,7 +1655,7 @@ async function executeWorkflow(workflowId, options) {
|
|
|
1346
1655
|
...adapterOptions
|
|
1347
1656
|
});
|
|
1348
1657
|
const progressSink = createProgressSink(
|
|
1349
|
-
options.logFile ? { stderr: true, file:
|
|
1658
|
+
options.logFile ? { stderr: true, file: resolve3(options.logFile), naming: "single" } : { stderr: true }
|
|
1350
1659
|
);
|
|
1351
1660
|
try {
|
|
1352
1661
|
if (options.hooks?.beforeWorkflow) {
|
|
@@ -1379,6 +1688,8 @@ async function executeWorkflow(workflowId, options) {
|
|
|
1379
1688
|
}
|
|
1380
1689
|
|
|
1381
1690
|
export {
|
|
1691
|
+
PluginRegistry,
|
|
1692
|
+
pluginRegistry,
|
|
1382
1693
|
renderAgentSystemPrompt,
|
|
1383
1694
|
buildCandidateAgents,
|
|
1384
1695
|
zodSchemaToPromptDescription,
|
|
@@ -1391,6 +1702,12 @@ export {
|
|
|
1391
1702
|
runWorkflow,
|
|
1392
1703
|
buildGateEvaluationPrompt,
|
|
1393
1704
|
parseGateEvaluationResponse,
|
|
1705
|
+
getBlockingViolations,
|
|
1706
|
+
getWarnings,
|
|
1707
|
+
hasBlockingViolation,
|
|
1708
|
+
createGuardrailHooks,
|
|
1709
|
+
createGuardrailHooksForAgent,
|
|
1710
|
+
createGuardrailHooksFromRules,
|
|
1394
1711
|
createRuntime,
|
|
1395
1712
|
WorkflowBuilder,
|
|
1396
1713
|
loadPluginsFromPaths,
|
|
@@ -1402,4 +1719,4 @@ export {
|
|
|
1402
1719
|
executeTask,
|
|
1403
1720
|
executeWorkflow
|
|
1404
1721
|
};
|
|
1405
|
-
//# sourceMappingURL=chunk-
|
|
1722
|
+
//# sourceMappingURL=chunk-UHHKLLA3.js.map
|