agent-contracts-runtime 0.3.2 → 0.5.0
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/cli-contract.yaml +8 -0
- package/dist/adapters/claude-agent-sdk.d.ts +9 -1
- package/dist/adapters/claude-agent-sdk.js +23 -15
- package/dist/adapters/claude-agent-sdk.js.map +1 -1
- package/dist/adapters/cursor-sdk.d.ts +21 -2
- package/dist/adapters/cursor-sdk.js +9 -3
- package/dist/adapters/cursor-sdk.js.map +1 -1
- package/dist/adapters/mock.d.ts +1 -1
- package/dist/{chunk-DNTCPVJN.js → chunk-OEGPQAWA.js} +17 -3
- package/dist/chunk-OEGPQAWA.js.map +1 -0
- package/dist/{chunk-24SRKCWQ.js → chunk-W4BDBZYV.js} +106 -5
- package/dist/chunk-W4BDBZYV.js.map +1 -0
- package/dist/cli/index.js +170 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.d.ts +24 -0
- package/dist/generator/index.js +1 -1
- package/dist/index.d.ts +67 -3
- package/dist/index.js +9 -1
- package/dist/{task-runner-MQO5VR1Y.d.ts → task-runner-DuZwv4zJ.d.ts} +10 -0
- package/package.json +2 -2
- package/templates/hooks-index.ts.hbs +19 -31
- package/dist/chunk-24SRKCWQ.js.map +0 -1
- package/dist/chunk-DNTCPVJN.js.map +0 -1
package/dist/cli/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
buildTaskPrompt,
|
|
4
|
-
pluginRegistry
|
|
5
|
-
|
|
4
|
+
pluginRegistry,
|
|
5
|
+
runWorkflow
|
|
6
|
+
} from "../chunk-W4BDBZYV.js";
|
|
6
7
|
import {
|
|
8
|
+
checkFreshness,
|
|
7
9
|
generate,
|
|
8
10
|
loadConfig
|
|
9
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-OEGPQAWA.js";
|
|
10
12
|
|
|
11
13
|
// src/cli/index.ts
|
|
12
14
|
import { existsSync } from "fs";
|
|
@@ -25,7 +27,7 @@ function createProgram(handlers2, version) {
|
|
|
25
27
|
program2.command("generate").description("Generate runtime contracts and hooks from DSL.").option("--clean", "Delete generated_dir before regenerating.\nRemoves stale files that may remain from previous generations.\n", false).option("--check", "Dry-run mode for CI. Does not write files.\nCompares current generated output with what would be regenerated.\nExits with code 1 if any differences are found.\n", false).option("-t, --templates <value>", "Custom templates directory. Overrides built-in templates.").action(async (opts, cmd) => {
|
|
26
28
|
await handlers2.generate(opts, cmd.optsWithGlobals());
|
|
27
29
|
});
|
|
28
|
-
program2.command("run").description("Execute a workflow.").argument("<workflow-id>", "ID of the workflow to execute (e.g. feature-implement, issue-fix).").argument("<user-request>", "Natural language description of what to do.").option("-a, --adapter <value>", "SDK adapter to use. Overrides config.").option("-r, --max-retries <value>", "Override default max retries per step.").option("-n, --dry-run", "Simulate execution without calling the SDK adapter.", false).option("--auto-approve-gates", "Automatically approve all gate steps.", false).action(async (workflowId, userRequest, opts, cmd) => {
|
|
30
|
+
program2.command("run").description("Execute a workflow.").argument("<workflow-id>", "ID of the workflow to execute (e.g. feature-implement, issue-fix).").argument("<user-request>", "Natural language description of what to do.").option("-a, --adapter <value>", "SDK adapter to use. Overrides config.").option("-r, --max-retries <value>", "Override default max retries per step.").option("-f, --max-follow-ups <value>", "Override default max follow-ups per step.").option("-n, --dry-run", "Simulate execution without calling the SDK adapter.", false).option("--auto-approve-gates", "Automatically approve all gate steps.", false).action(async (workflowId, userRequest, opts, cmd) => {
|
|
29
31
|
await handlers2.run(workflowId, userRequest, opts, cmd.optsWithGlobals());
|
|
30
32
|
});
|
|
31
33
|
program2.command("list").description("List available workflows, tasks, or agents.").argument("<resource>", "Type of resource to list.").option("--format <value>", "Output format.", "table").action(async (resource, opts, cmd) => {
|
|
@@ -44,7 +46,7 @@ function createProgram(handlers2, version) {
|
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
// src/cli/index.ts
|
|
47
|
-
var VERSION = "0.
|
|
49
|
+
var VERSION = "0.5.0";
|
|
48
50
|
async function loadGeneratedContracts(configPath) {
|
|
49
51
|
const config = await loadConfig(configPath);
|
|
50
52
|
const basePath = `${config.generatedDir}/index`;
|
|
@@ -62,9 +64,44 @@ async function loadGeneratedContracts(configPath) {
|
|
|
62
64
|
return {
|
|
63
65
|
agentRegistry: mod.agentRegistry ?? mod.agents?.agentRegistry ?? {},
|
|
64
66
|
taskRegistry: mod.taskRegistry ?? mod.tasks?.taskRegistry ?? {},
|
|
65
|
-
handoffSchemas: mod.handoffSchemas ?? mod.handoffs?.handoffSchemas ?? {}
|
|
67
|
+
handoffSchemas: mod.handoffSchemas ?? mod.handoffs?.handoffSchemas ?? {},
|
|
68
|
+
workflowRegistry: mod.workflowRegistry ?? mod.workflows?.workflowRegistry ?? {}
|
|
66
69
|
};
|
|
67
70
|
}
|
|
71
|
+
async function createAdapter(adapterName) {
|
|
72
|
+
switch (adapterName) {
|
|
73
|
+
case "mock": {
|
|
74
|
+
const { MockAdapter } = await import("../adapters/mock.js");
|
|
75
|
+
return new MockAdapter();
|
|
76
|
+
}
|
|
77
|
+
case "claude": {
|
|
78
|
+
const { ClaudeAgentSdkAdapter } = await import("../adapters/claude-agent-sdk.js");
|
|
79
|
+
return new ClaudeAgentSdkAdapter({});
|
|
80
|
+
}
|
|
81
|
+
case "cursor": {
|
|
82
|
+
const { CursorSdkAdapter } = await import("../adapters/cursor-sdk.js");
|
|
83
|
+
const apiKey = process.env.CURSOR_API_KEY;
|
|
84
|
+
if (!apiKey) {
|
|
85
|
+
throw new Error("CURSOR_API_KEY environment variable is required for the cursor adapter");
|
|
86
|
+
}
|
|
87
|
+
return CursorSdkAdapter.create({ apiKey });
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
throw new Error(`Unknown adapter: ${adapterName}. Available: mock, claude, cursor`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function formatTable(headers, rows) {
|
|
94
|
+
const widths = headers.map(
|
|
95
|
+
(h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? "").length))
|
|
96
|
+
);
|
|
97
|
+
const sep = widths.map((w) => "-".repeat(w)).join(" ");
|
|
98
|
+
const pad = (s, w) => s.padEnd(w);
|
|
99
|
+
const headerLine = headers.map((h, i) => pad(h, widths[i])).join(" ");
|
|
100
|
+
const dataLines = rows.map(
|
|
101
|
+
(r) => r.map((c, i) => pad(c ?? "", widths[i])).join(" ")
|
|
102
|
+
);
|
|
103
|
+
return [headerLine, sep, ...dataLines].join("\n");
|
|
104
|
+
}
|
|
68
105
|
var handlers = {
|
|
69
106
|
async init(options, _globalOpts) {
|
|
70
107
|
console.log("agent-runtime init \u2014 not yet implemented");
|
|
@@ -93,15 +130,134 @@ var handlers = {
|
|
|
93
130
|
process.exit(1);
|
|
94
131
|
}
|
|
95
132
|
},
|
|
96
|
-
async run(workflowId, userRequest, options,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
133
|
+
async run(workflowId, userRequest, options, globalOpts) {
|
|
134
|
+
if (!workflowId) {
|
|
135
|
+
console.error("Error: workflow-id is required");
|
|
136
|
+
process.exit(1);
|
|
137
|
+
}
|
|
138
|
+
if (!userRequest) {
|
|
139
|
+
console.error("Error: user-request is required");
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
const configPath = globalOpts.config ?? "./agent-runtime.config.yaml";
|
|
143
|
+
const fresh = await checkFreshness(configPath);
|
|
144
|
+
if (!fresh) {
|
|
145
|
+
console.error("Generated files are stale or missing. Run `agent-runtime generate` first.");
|
|
146
|
+
process.exit(3);
|
|
147
|
+
}
|
|
148
|
+
let contracts;
|
|
149
|
+
try {
|
|
150
|
+
contracts = await loadGeneratedContracts(configPath);
|
|
151
|
+
} catch (err) {
|
|
152
|
+
console.error(`Failed to load generated contracts: ${err.message}`);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!contracts.workflowRegistry[workflowId]) {
|
|
157
|
+
console.error(`Unknown workflow: ${workflowId}`);
|
|
158
|
+
console.error(`Available workflows: ${Object.keys(contracts.workflowRegistry).join(", ")}`);
|
|
159
|
+
process.exit(1);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const adapterName = options.adapter ?? "mock";
|
|
163
|
+
let adapter;
|
|
164
|
+
try {
|
|
165
|
+
adapter = await createAdapter(adapterName);
|
|
166
|
+
} catch (err) {
|
|
167
|
+
console.error(err.message);
|
|
168
|
+
process.exit(1);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const config = await loadConfig(configPath);
|
|
172
|
+
const recovery = config.recovery;
|
|
173
|
+
const maxRetries = options.maxRetries ? parseInt(options.maxRetries, 10) : void 0;
|
|
174
|
+
const maxFollowUps = options.maxFollowUps ? parseInt(options.maxFollowUps, 10) : void 0;
|
|
175
|
+
const result = await runWorkflow(adapter, workflowId, {
|
|
176
|
+
user_request: userRequest,
|
|
177
|
+
maxRetries: maxRetries ?? recovery.max_retries,
|
|
178
|
+
maxFollowUps: maxFollowUps ?? recovery.max_follow_ups,
|
|
179
|
+
onGate: options.autoApproveGates ? async () => true : async (gateKind, description) => {
|
|
180
|
+
console.error(`Gate "${gateKind}": ${description}`);
|
|
181
|
+
console.error("Use --auto-approve-gates to auto-approve. Rejecting by default.");
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}, {
|
|
185
|
+
workflowRegistry: contracts.workflowRegistry,
|
|
186
|
+
taskRegistry: contracts.taskRegistry,
|
|
187
|
+
agentRegistry: contracts.agentRegistry,
|
|
188
|
+
handoffSchemas: contracts.handoffSchemas
|
|
189
|
+
});
|
|
190
|
+
console.log(JSON.stringify(result, null, 2));
|
|
191
|
+
if (result.status !== "completed") {
|
|
192
|
+
process.exit(1);
|
|
193
|
+
}
|
|
100
194
|
},
|
|
101
|
-
async list(resource, options,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
195
|
+
async list(resource, options, globalOpts) {
|
|
196
|
+
if (!resource) {
|
|
197
|
+
console.error("Error: resource is required (workflows, tasks, agents)");
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
const validResources = ["workflows", "tasks", "agents"];
|
|
201
|
+
if (!validResources.includes(resource)) {
|
|
202
|
+
console.error(`Unknown resource: ${resource}`);
|
|
203
|
+
console.error(`Available resources: ${validResources.join(", ")}`);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const configPath = globalOpts.config ?? "./agent-runtime.config.yaml";
|
|
208
|
+
let contracts;
|
|
209
|
+
try {
|
|
210
|
+
contracts = await loadGeneratedContracts(configPath);
|
|
211
|
+
} catch (err) {
|
|
212
|
+
console.error(`Failed to load generated contracts: ${err.message}`);
|
|
213
|
+
console.error("Run `agent-runtime generate` first.");
|
|
214
|
+
process.exit(1);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const format = options.format ?? "table";
|
|
218
|
+
if (resource === "agents") {
|
|
219
|
+
const agents = Object.values(contracts.agentRegistry);
|
|
220
|
+
if (format === "json") {
|
|
221
|
+
console.log(JSON.stringify(agents, null, 2));
|
|
222
|
+
} else {
|
|
223
|
+
if (agents.length === 0) {
|
|
224
|
+
console.log("No agents defined.");
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
console.log(formatTable(
|
|
228
|
+
["ID", "Role", "Mode", "Purpose"],
|
|
229
|
+
agents.map((a) => [a.id, a.role_name, a.mode, a.purpose])
|
|
230
|
+
));
|
|
231
|
+
}
|
|
232
|
+
} else if (resource === "tasks") {
|
|
233
|
+
const tasks = Object.values(contracts.taskRegistry);
|
|
234
|
+
if (format === "json") {
|
|
235
|
+
console.log(JSON.stringify(tasks, null, 2));
|
|
236
|
+
} else {
|
|
237
|
+
if (tasks.length === 0) {
|
|
238
|
+
console.log("No tasks defined.");
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
console.log(formatTable(
|
|
242
|
+
["ID", "Agent", "Description"],
|
|
243
|
+
tasks.map((t) => [t.id, t.target_agent, t.description])
|
|
244
|
+
));
|
|
245
|
+
}
|
|
246
|
+
} else {
|
|
247
|
+
const workflows = Object.values(contracts.workflowRegistry);
|
|
248
|
+
if (format === "json") {
|
|
249
|
+
console.log(JSON.stringify(workflows, null, 2));
|
|
250
|
+
} else {
|
|
251
|
+
if (workflows.length === 0) {
|
|
252
|
+
console.log("No workflows defined.");
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
console.log(formatTable(
|
|
256
|
+
["ID", "Steps", "Description"],
|
|
257
|
+
workflows.map((w) => [w.id, String(w.steps.length), w.description])
|
|
258
|
+
));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
105
261
|
},
|
|
106
262
|
async showPrompt(taskId, options, globalOpts) {
|
|
107
263
|
if (!taskId) {
|
package/dist/cli/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/index.ts","../../src/generated/cli/program.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * agent-runtime CLI entry point\n *\n * Uses auto-generated program from cli-contract.yaml.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { createProgram, type CommandHandlers } from \"../generated/cli/program.js\";\nimport { generate, loadConfig } from \"../generator/index.js\";\nimport { buildTaskPrompt, pluginRegistry, type AgentContractLike, type TaskContractLike } from \"../index.js\";\nimport type { z } from \"zod\";\n\nconst VERSION = \"0.3.2\";\n\n/**\n * Dynamically import the generated contracts from the configured generated_dir.\n * Handles both .ts (via tsx/ts-node) and .js (compiled) files,\n * and both flat exports and namespace exports.\n */\nasync function loadGeneratedContracts(configPath: string): Promise<{\n agentRegistry: Record<string, AgentContractLike>;\n taskRegistry: Record<string, TaskContractLike>;\n handoffSchemas: Record<string, z.ZodTypeAny>;\n}> {\n const config = await loadConfig(configPath);\n const basePath = `${config.generatedDir}/index`;\n\n let indexPath: string;\n if (existsSync(`${basePath}.js`)) {\n indexPath = `${basePath}.js`;\n } else if (existsSync(`${basePath}.ts`)) {\n indexPath = `${basePath}.ts`;\n } else {\n throw new Error(\n `Generated index file not found at ${basePath}.{js,ts}. Run \\`agent-runtime generate\\` first.`,\n );\n }\n\n const mod = await import(new URL(`file://${indexPath}`).href);\n\n return {\n agentRegistry: mod.agentRegistry ?? mod.agents?.agentRegistry ?? {},\n taskRegistry: mod.taskRegistry ?? mod.tasks?.taskRegistry ?? {},\n handoffSchemas: mod.handoffSchemas ?? mod.handoffs?.handoffSchemas ?? {},\n };\n}\n\nconst handlers: CommandHandlers = {\n async init(options, _globalOpts) {\n console.log(\"agent-runtime init — not yet implemented\");\n console.log(\"Options:\", JSON.stringify(options));\n },\n\n async generate(options, globalOpts) {\n try {\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n const result = await generate({\n clean: options.clean,\n check: options.check,\n templates: options.templates,\n configPath,\n });\n\n if (result.checkMode) {\n if (result.hasDifferences) {\n console.error(\"Generated files are out of date. Run `agent-runtime generate` to update.\");\n process.exit(1);\n }\n console.log(JSON.stringify({ ...result, status: \"up-to-date\" }, null, 2));\n } else {\n console.log(JSON.stringify(result, null, 2));\n }\n } catch (err) {\n console.error(\"Generate failed:\", (err as Error).message);\n process.exit(1);\n }\n },\n\n async run(workflowId, userRequest, options, _globalOpts) {\n console.log(\"agent-runtime run — not yet implemented\");\n console.log(`Workflow: ${workflowId}, Request: ${userRequest}`);\n console.log(\"Options:\", JSON.stringify(options));\n },\n\n async list(resource, options, _globalOpts) {\n console.log(\"agent-runtime list — not yet implemented\");\n console.log(`Resource: ${resource}`);\n console.log(\"Options:\", JSON.stringify(options));\n },\n\n async showPrompt(taskId, options, globalOpts) {\n if (!taskId) {\n console.error(\"Error: task-id is required\");\n process.exit(1);\n }\n\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n\n let contracts: Awaited<ReturnType<typeof loadGeneratedContracts>>;\n try {\n contracts = await loadGeneratedContracts(configPath);\n } catch (err) {\n console.error(`Failed to load generated contracts: ${(err as Error).message}`);\n console.error(\"Run `agent-runtime generate` first.\");\n process.exit(1);\n return;\n }\n\n const task = contracts.taskRegistry[taskId];\n if (!task) {\n console.error(`Unknown task: ${taskId}`);\n console.error(`Available tasks: ${Object.keys(contracts.taskRegistry).join(\", \")}`);\n process.exit(1);\n return;\n }\n\n const agent = contracts.agentRegistry[task.target_agent];\n if (!agent) {\n console.error(`Unknown agent: ${task.target_agent} (referenced by task ${taskId})`);\n process.exit(1);\n return;\n }\n\n const userRequest = options.userRequest ?? \"(preview)\";\n let prompt = buildTaskPrompt(agent, task, { user_request: userRequest }, {\n handoffSchemas: contracts.handoffSchemas,\n });\n\n const pluginsApplied = options.withPlugins ?? false;\n if (pluginsApplied) {\n prompt = pluginRegistry.applyPromptEnhancers(taskId, prompt, { user_request: userRequest });\n }\n\n const format = options.format ?? \"markdown\";\n if (format === \"json\") {\n console.log(JSON.stringify({\n task_id: taskId,\n agent_id: task.target_agent,\n prompt,\n handoff_schema: task.result_handoff,\n plugins_applied: pluginsApplied,\n }, null, 2));\n } else {\n console.log(prompt);\n }\n },\n\n async doctor(_globalOpts) {\n console.log(\"agent-runtime doctor — not yet implemented\");\n },\n\n async replay(runDir, options, _globalOpts) {\n console.log(\"agent-runtime replay — not yet implemented\");\n console.log(`Run dir: ${runDir}`);\n console.log(\"Options:\", JSON.stringify(options));\n },\n};\n\nconst program = createProgram(handlers, VERSION);\nprogram.parse();\n","// Auto-generated by cli-contracts. Do not edit.\nimport { Command } from \"commander\";\n\nexport interface CommandHandlers {\n init: (options: { adapter?: string; output?: string; force?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n generate: (options: { clean?: boolean; check?: boolean; templates?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n run: (workflowId: string | undefined, userRequest: string | undefined, options: { adapter?: string; maxRetries?: string; dryRun?: boolean; autoApproveGates?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n list: (resource: string | undefined, options: { format?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n showPrompt: (taskId: string | undefined, options: { userRequest?: string; format?: string; withPlugins?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n doctor: (parentOpts: Record<string, unknown>) => Promise<void>;\n replay: (runDir: string | undefined, options: { validateOnly?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n}\n\nexport function createProgram(\n handlers: CommandHandlers,\n version: string,\n): Command {\n const program = new Command();\n program\n .name(\"agent-runtime\")\n .version(version, \"-V, --version\")\n .description(\"CLI for agent-contracts-runtime — generate, run, and manage agent workflows.\");\n\n program.option(\"-c, --config <value>\", \"Path to agent-runtime.config.yaml.\", \"./agent-runtime.config.yaml\");\n program.option(\"-v, --verbose\", \"Enable verbose output.\", false);\n program.option(\"-q, --quiet\", \"Suppress non-error output.\", false);\n\n program\n .command(\"init\")\n .description(\"Initialize runtime scaffolding for a project.\")\n .option(\"-a, --adapter <value>\", \"Default SDK adapter to configure.\", \"mock\")\n .option(\"-o, --output <value>\", \"Output directory for generated scaffolding.\", \".\")\n .option(\"-f, --force\", \"Overwrite existing files without prompting.\", false)\n .action(async (opts, cmd) => {\n await handlers.init(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"generate\")\n .description(\"Generate runtime contracts and hooks from DSL.\")\n .option(\"--clean\", \"Delete generated_dir before regenerating.\\nRemoves stale files that may remain from previous generations.\\n\", false)\n .option(\"--check\", \"Dry-run mode for CI. Does not write files.\\nCompares current generated output with what would be regenerated.\\nExits with code 1 if any differences are found.\\n\", false)\n .option(\"-t, --templates <value>\", \"Custom templates directory. Overrides built-in templates.\")\n .action(async (opts, cmd) => {\n await handlers.generate(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"run\")\n .description(\"Execute a workflow.\")\n .argument(\"<workflow-id>\", \"ID of the workflow to execute (e.g. feature-implement, issue-fix).\")\n .argument(\"<user-request>\", \"Natural language description of what to do.\")\n .option(\"-a, --adapter <value>\", \"SDK adapter to use. Overrides config.\")\n .option(\"-r, --max-retries <value>\", \"Override default max retries per step.\")\n .option(\"-n, --dry-run\", \"Simulate execution without calling the SDK adapter.\", false)\n .option(\"--auto-approve-gates\", \"Automatically approve all gate steps.\", false)\n .action(async (workflowId, userRequest, opts, cmd) => {\n await handlers.run(workflowId, userRequest, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"list\")\n .description(\"List available workflows, tasks, or agents.\")\n .argument(\"<resource>\", \"Type of resource to list.\")\n .option(\"--format <value>\", \"Output format.\", \"table\")\n .action(async (resource, opts, cmd) => {\n await handlers.list(resource, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"show-prompt\")\n .description(\"Display the generated prompt for a task.\")\n .argument(\"<task-id>\", \"ID of the task to show the prompt for (e.g. plan-and-implement, audit-tests).\")\n .option(\"-u, --user-request <value>\", \"User request text to include in the prompt preview.\", \"(preview)\")\n .option(\"--format <value>\", \"Output format.\", \"markdown\")\n .option(\"--with-plugins\", \"Apply registered plugin prompt enhancers to the output.\", false)\n .action(async (taskId, opts, cmd) => {\n await handlers.showPrompt(taskId, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"doctor\")\n .description(\"Verify configuration, generated files, and SDK connectivity.\")\n .action(async (opts, cmd) => {\n await handlers.doctor({}, cmd.optsWithGlobals());\n });\n\n program\n .command(\"replay\")\n .description(\"Replay a past workflow execution from logs.\")\n .argument(\"<run-dir>\", \"Path to the .agent-runs/<run-id> directory.\")\n .option(\"--validate-only\", \"Only validate the run log without re-execution.\", false)\n .action(async (runDir, opts, cmd) => {\n await handlers.replay(runDir, opts, cmd.optsWithGlobals());\n });\n\n return program;\n}\n"],"mappings":";;;;;;;;;;;AAQA,SAAS,kBAAkB;;;ACP3B,SAAS,eAAe;AAYjB,SAAS,cACdA,WACA,SACS;AACT,QAAMC,WAAU,IAAI,QAAQ;AAC5B,EAAAA,SACG,KAAK,eAAe,EACpB,QAAQ,SAAS,eAAe,EAChC,YAAY,mFAA8E;AAE7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iB;AAAA,MACnB,GAAG,MAAM,CAAC,CAAC;AAAA,IACb,OAAO;AACL,cAAQ,IAAI,MAAM;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,aAAa;AACxB,YAAQ,IAAI,iDAA4C;AAAA,EAC1D;AAAA,EAEA,MAAM,OAAO,QAAQ,SAAS,aAAa;AACzC,YAAQ,IAAI,iDAA4C;AACxD,YAAQ,IAAI,YAAY,MAAM,EAAE;AAChC,YAAQ,IAAI,YAAY,KAAK,UAAU,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,IAAM,UAAU,cAAc,UAAU,OAAO;AAC/C,QAAQ,MAAM;","names":["handlers","program"]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/index.ts","../../src/generated/cli/program.ts"],"sourcesContent":["#!/usr/bin/env node\n\n/**\n * agent-runtime CLI entry point\n *\n * Uses auto-generated program from cli-contract.yaml.\n */\n\nimport { existsSync } from \"node:fs\";\nimport { createProgram, type CommandHandlers } from \"../generated/cli/program.js\";\nimport { generate, loadConfig, checkFreshness } from \"../generator/index.js\";\nimport {\n buildTaskPrompt,\n pluginRegistry,\n runWorkflow,\n type AgentContractLike,\n type TaskContractLike,\n type SdkAdapter,\n type WorkflowContractLike,\n} from \"../index.js\";\nimport type { z } from \"zod\";\n\nconst VERSION = \"0.5.0\";\n\n/**\n * Dynamically import the generated contracts from the configured generated_dir.\n * Handles both .ts (via tsx/ts-node) and .js (compiled) files,\n * and both flat exports and namespace exports.\n */\nasync function loadGeneratedContracts(configPath: string): Promise<{\n agentRegistry: Record<string, AgentContractLike>;\n taskRegistry: Record<string, TaskContractLike>;\n handoffSchemas: Record<string, z.ZodTypeAny>;\n workflowRegistry: Record<string, WorkflowContractLike>;\n}> {\n const config = await loadConfig(configPath);\n const basePath = `${config.generatedDir}/index`;\n\n let indexPath: string;\n if (existsSync(`${basePath}.js`)) {\n indexPath = `${basePath}.js`;\n } else if (existsSync(`${basePath}.ts`)) {\n indexPath = `${basePath}.ts`;\n } else {\n throw new Error(\n `Generated index file not found at ${basePath}.{js,ts}. Run \\`agent-runtime generate\\` first.`,\n );\n }\n\n const mod = await import(new URL(`file://${indexPath}`).href);\n\n return {\n agentRegistry: mod.agentRegistry ?? mod.agents?.agentRegistry ?? {},\n taskRegistry: mod.taskRegistry ?? mod.tasks?.taskRegistry ?? {},\n handoffSchemas: mod.handoffSchemas ?? mod.handoffs?.handoffSchemas ?? {},\n workflowRegistry: mod.workflowRegistry ?? mod.workflows?.workflowRegistry ?? {},\n };\n}\n\nasync function createAdapter(adapterName: string): Promise<SdkAdapter> {\n switch (adapterName) {\n case \"mock\": {\n const { MockAdapter } = await import(\"../adapters/mock.js\");\n return new MockAdapter();\n }\n case \"claude\": {\n const { ClaudeAgentSdkAdapter } = await import(\"../adapters/claude-agent-sdk.js\");\n return new ClaudeAgentSdkAdapter({});\n }\n case \"cursor\": {\n const { CursorSdkAdapter } = await import(\"../adapters/cursor-sdk.js\");\n const apiKey = process.env.CURSOR_API_KEY;\n if (!apiKey) {\n throw new Error(\"CURSOR_API_KEY environment variable is required for the cursor adapter\");\n }\n return CursorSdkAdapter.create({ apiKey });\n }\n default:\n throw new Error(`Unknown adapter: ${adapterName}. Available: mock, claude, cursor`);\n }\n}\n\nfunction formatTable(headers: string[], rows: string[][]): string {\n const widths = headers.map((h, i) =>\n Math.max(h.length, ...rows.map((r) => (r[i] ?? \"\").length)),\n );\n const sep = widths.map((w) => \"-\".repeat(w)).join(\" \");\n const pad = (s: string, w: number) => s.padEnd(w);\n const headerLine = headers.map((h, i) => pad(h, widths[i])).join(\" \");\n const dataLines = rows.map((r) =>\n r.map((c, i) => pad(c ?? \"\", widths[i])).join(\" \"),\n );\n return [headerLine, sep, ...dataLines].join(\"\\n\");\n}\n\nconst handlers: CommandHandlers = {\n async init(options, _globalOpts) {\n console.log(\"agent-runtime init — not yet implemented\");\n console.log(\"Options:\", JSON.stringify(options));\n },\n\n async generate(options, globalOpts) {\n try {\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n const result = await generate({\n clean: options.clean,\n check: options.check,\n templates: options.templates,\n configPath,\n });\n\n if (result.checkMode) {\n if (result.hasDifferences) {\n console.error(\"Generated files are out of date. Run `agent-runtime generate` to update.\");\n process.exit(1);\n }\n console.log(JSON.stringify({ ...result, status: \"up-to-date\" }, null, 2));\n } else {\n console.log(JSON.stringify(result, null, 2));\n }\n } catch (err) {\n console.error(\"Generate failed:\", (err as Error).message);\n process.exit(1);\n }\n },\n\n async run(workflowId, userRequest, options, globalOpts) {\n if (!workflowId) {\n console.error(\"Error: workflow-id is required\");\n process.exit(1);\n }\n if (!userRequest) {\n console.error(\"Error: user-request is required\");\n process.exit(1);\n }\n\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n\n const fresh = await checkFreshness(configPath);\n if (!fresh) {\n console.error(\"Generated files are stale or missing. Run `agent-runtime generate` first.\");\n process.exit(3);\n }\n\n let contracts: Awaited<ReturnType<typeof loadGeneratedContracts>>;\n try {\n contracts = await loadGeneratedContracts(configPath);\n } catch (err) {\n console.error(`Failed to load generated contracts: ${(err as Error).message}`);\n process.exit(1);\n return;\n }\n\n if (!contracts.workflowRegistry[workflowId]) {\n console.error(`Unknown workflow: ${workflowId}`);\n console.error(`Available workflows: ${Object.keys(contracts.workflowRegistry).join(\", \")}`);\n process.exit(1);\n return;\n }\n\n const adapterName = (options.adapter as string) ?? \"mock\";\n let adapter: SdkAdapter;\n try {\n adapter = await createAdapter(adapterName);\n } catch (err) {\n console.error((err as Error).message);\n process.exit(1);\n return;\n }\n\n const config = await loadConfig(configPath);\n const recovery = config.recovery;\n const maxRetries = options.maxRetries\n ? parseInt(options.maxRetries, 10)\n : undefined;\n const maxFollowUps = options.maxFollowUps\n ? parseInt(options.maxFollowUps, 10)\n : undefined;\n\n const result = await runWorkflow(adapter, workflowId, {\n user_request: userRequest,\n maxRetries: maxRetries ?? recovery.max_retries,\n maxFollowUps: maxFollowUps ?? recovery.max_follow_ups,\n onGate: options.autoApproveGates\n ? async () => true\n : async (gateKind, description) => {\n console.error(`Gate \"${gateKind}\": ${description}`);\n console.error(\"Use --auto-approve-gates to auto-approve. Rejecting by default.\");\n return false;\n },\n }, {\n workflowRegistry: contracts.workflowRegistry,\n taskRegistry: contracts.taskRegistry,\n agentRegistry: contracts.agentRegistry,\n handoffSchemas: contracts.handoffSchemas,\n });\n\n console.log(JSON.stringify(result, null, 2));\n\n if (result.status !== \"completed\") {\n process.exit(1);\n }\n },\n\n async list(resource, options, globalOpts) {\n if (!resource) {\n console.error(\"Error: resource is required (workflows, tasks, agents)\");\n process.exit(1);\n }\n\n const validResources = [\"workflows\", \"tasks\", \"agents\"];\n if (!validResources.includes(resource)) {\n console.error(`Unknown resource: ${resource}`);\n console.error(`Available resources: ${validResources.join(\", \")}`);\n process.exit(1);\n return;\n }\n\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n\n let contracts: Awaited<ReturnType<typeof loadGeneratedContracts>>;\n try {\n contracts = await loadGeneratedContracts(configPath);\n } catch (err) {\n console.error(`Failed to load generated contracts: ${(err as Error).message}`);\n console.error(\"Run `agent-runtime generate` first.\");\n process.exit(1);\n return;\n }\n\n const format = options.format ?? \"table\";\n\n if (resource === \"agents\") {\n const agents = Object.values(contracts.agentRegistry);\n if (format === \"json\") {\n console.log(JSON.stringify(agents, null, 2));\n } else {\n if (agents.length === 0) {\n console.log(\"No agents defined.\");\n return;\n }\n console.log(formatTable(\n [\"ID\", \"Role\", \"Mode\", \"Purpose\"],\n agents.map((a) => [a.id, a.role_name, a.mode, a.purpose]),\n ));\n }\n } else if (resource === \"tasks\") {\n const tasks = Object.values(contracts.taskRegistry);\n if (format === \"json\") {\n console.log(JSON.stringify(tasks, null, 2));\n } else {\n if (tasks.length === 0) {\n console.log(\"No tasks defined.\");\n return;\n }\n console.log(formatTable(\n [\"ID\", \"Agent\", \"Description\"],\n tasks.map((t) => [t.id, t.target_agent, t.description]),\n ));\n }\n } else {\n const workflows = Object.values(contracts.workflowRegistry);\n if (format === \"json\") {\n console.log(JSON.stringify(workflows, null, 2));\n } else {\n if (workflows.length === 0) {\n console.log(\"No workflows defined.\");\n return;\n }\n console.log(formatTable(\n [\"ID\", \"Steps\", \"Description\"],\n workflows.map((w) => [w.id, String(w.steps.length), w.description]),\n ));\n }\n }\n },\n\n async showPrompt(taskId, options, globalOpts) {\n if (!taskId) {\n console.error(\"Error: task-id is required\");\n process.exit(1);\n }\n\n const configPath = (globalOpts.config as string) ?? \"./agent-runtime.config.yaml\";\n\n let contracts: Awaited<ReturnType<typeof loadGeneratedContracts>>;\n try {\n contracts = await loadGeneratedContracts(configPath);\n } catch (err) {\n console.error(`Failed to load generated contracts: ${(err as Error).message}`);\n console.error(\"Run `agent-runtime generate` first.\");\n process.exit(1);\n return;\n }\n\n const task = contracts.taskRegistry[taskId];\n if (!task) {\n console.error(`Unknown task: ${taskId}`);\n console.error(`Available tasks: ${Object.keys(contracts.taskRegistry).join(\", \")}`);\n process.exit(1);\n return;\n }\n\n const agent = contracts.agentRegistry[task.target_agent];\n if (!agent) {\n console.error(`Unknown agent: ${task.target_agent} (referenced by task ${taskId})`);\n process.exit(1);\n return;\n }\n\n const userRequest = options.userRequest ?? \"(preview)\";\n let prompt = buildTaskPrompt(agent, task, { user_request: userRequest }, {\n handoffSchemas: contracts.handoffSchemas,\n });\n\n const pluginsApplied = options.withPlugins ?? false;\n if (pluginsApplied) {\n prompt = pluginRegistry.applyPromptEnhancers(taskId, prompt, { user_request: userRequest });\n }\n\n const format = options.format ?? \"markdown\";\n if (format === \"json\") {\n console.log(JSON.stringify({\n task_id: taskId,\n agent_id: task.target_agent,\n prompt,\n handoff_schema: task.result_handoff,\n plugins_applied: pluginsApplied,\n }, null, 2));\n } else {\n console.log(prompt);\n }\n },\n\n async doctor(_globalOpts) {\n console.log(\"agent-runtime doctor — not yet implemented\");\n },\n\n async replay(runDir, options, _globalOpts) {\n console.log(\"agent-runtime replay — not yet implemented\");\n console.log(`Run dir: ${runDir}`);\n console.log(\"Options:\", JSON.stringify(options));\n },\n};\n\nconst program = createProgram(handlers, VERSION);\nprogram.parse();\n","// Auto-generated by cli-contracts. Do not edit.\nimport { Command } from \"commander\";\n\nexport interface CommandHandlers {\n init: (options: { adapter?: string; output?: string; force?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n generate: (options: { clean?: boolean; check?: boolean; templates?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n run: (workflowId: string | undefined, userRequest: string | undefined, options: { adapter?: string; maxRetries?: string; maxFollowUps?: string; dryRun?: boolean; autoApproveGates?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n list: (resource: string | undefined, options: { format?: string }, parentOpts: Record<string, unknown>) => Promise<void>;\n showPrompt: (taskId: string | undefined, options: { userRequest?: string; format?: string; withPlugins?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n doctor: (parentOpts: Record<string, unknown>) => Promise<void>;\n replay: (runDir: string | undefined, options: { validateOnly?: boolean }, parentOpts: Record<string, unknown>) => Promise<void>;\n}\n\nexport function createProgram(\n handlers: CommandHandlers,\n version: string,\n): Command {\n const program = new Command();\n program\n .name(\"agent-runtime\")\n .version(version, \"-V, --version\")\n .description(\"CLI for agent-contracts-runtime — generate, run, and manage agent workflows.\");\n\n program.option(\"-c, --config <value>\", \"Path to agent-runtime.config.yaml.\", \"./agent-runtime.config.yaml\");\n program.option(\"-v, --verbose\", \"Enable verbose output.\", false);\n program.option(\"-q, --quiet\", \"Suppress non-error output.\", false);\n\n program\n .command(\"init\")\n .description(\"Initialize runtime scaffolding for a project.\")\n .option(\"-a, --adapter <value>\", \"Default SDK adapter to configure.\", \"mock\")\n .option(\"-o, --output <value>\", \"Output directory for generated scaffolding.\", \".\")\n .option(\"-f, --force\", \"Overwrite existing files without prompting.\", false)\n .action(async (opts, cmd) => {\n await handlers.init(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"generate\")\n .description(\"Generate runtime contracts and hooks from DSL.\")\n .option(\"--clean\", \"Delete generated_dir before regenerating.\\nRemoves stale files that may remain from previous generations.\\n\", false)\n .option(\"--check\", \"Dry-run mode for CI. Does not write files.\\nCompares current generated output with what would be regenerated.\\nExits with code 1 if any differences are found.\\n\", false)\n .option(\"-t, --templates <value>\", \"Custom templates directory. Overrides built-in templates.\")\n .action(async (opts, cmd) => {\n await handlers.generate(opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"run\")\n .description(\"Execute a workflow.\")\n .argument(\"<workflow-id>\", \"ID of the workflow to execute (e.g. feature-implement, issue-fix).\")\n .argument(\"<user-request>\", \"Natural language description of what to do.\")\n .option(\"-a, --adapter <value>\", \"SDK adapter to use. Overrides config.\")\n .option(\"-r, --max-retries <value>\", \"Override default max retries per step.\")\n .option(\"-f, --max-follow-ups <value>\", \"Override default max follow-ups per step.\")\n .option(\"-n, --dry-run\", \"Simulate execution without calling the SDK adapter.\", false)\n .option(\"--auto-approve-gates\", \"Automatically approve all gate steps.\", false)\n .action(async (workflowId, userRequest, opts, cmd) => {\n await handlers.run(workflowId, userRequest, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"list\")\n .description(\"List available workflows, tasks, or agents.\")\n .argument(\"<resource>\", \"Type of resource to list.\")\n .option(\"--format <value>\", \"Output format.\", \"table\")\n .action(async (resource, opts, cmd) => {\n await handlers.list(resource, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"show-prompt\")\n .description(\"Display the generated prompt for a task.\")\n .argument(\"<task-id>\", \"ID of the task to show the prompt for (e.g. plan-and-implement, audit-tests).\")\n .option(\"-u, --user-request <value>\", \"User request text to include in the prompt preview.\", \"(preview)\")\n .option(\"--format <value>\", \"Output format.\", \"markdown\")\n .option(\"--with-plugins\", \"Apply registered plugin prompt enhancers to the output.\", false)\n .action(async (taskId, opts, cmd) => {\n await handlers.showPrompt(taskId, opts, cmd.optsWithGlobals());\n });\n\n program\n .command(\"doctor\")\n .description(\"Verify configuration, generated files, and SDK connectivity.\")\n .action(async (opts, cmd) => {\n await handlers.doctor({}, cmd.optsWithGlobals());\n });\n\n program\n .command(\"replay\")\n .description(\"Replay a past workflow execution from logs.\")\n .argument(\"<run-dir>\", \"Path to the .agent-runs/<run-id> directory.\")\n .option(\"--validate-only\", \"Only validate the run log without re-execution.\", false)\n .action(async (runDir, opts, cmd) => {\n await handlers.replay(runDir, opts, cmd.optsWithGlobals());\n });\n\n return program;\n}\n"],"mappings":";;;;;;;;;;;;;AAQA,SAAS,kBAAkB;;;ACP3B,SAAS,eAAe;AAYjB,SAAS,cACdA,WACA,SACS;AACT,QAAMC,WAAU,IAAI,QAAQ;AAC5B,EAAAA,SACG,KAAK,eAAe,EACpB,QAAQ,SAAS,eAAe,EAChC,YAAY,mFAA8E;AAE7F,EAAAA,SAAQ,OAAO,wBAAwB,sCAAsC,6BAA6B;AAC1G,EAAAA,SAAQ,OAAO,iBAAiB,0BAA0B,KAAK;AAC/D,EAAAA,SAAQ,OAAO,eAAe,8BAA8B,KAAK;AAEjE,EAAAA,SACG,QAAQ,MAAM,EACd,YAAY,+CAA+C,EAC3D,OAAO,yBAAyB,qCAAqC,MAAM,EAC3E,OAAO,wBAAwB,+CAA+C,GAAG,EACjF,OAAO,eAAe,+CAA+C,KAAK,EAC1E,OAAO,OAAO,MAAM,QAAQ;AAC3B,UAAMD,UAAS,KAAK,MAAM,IAAI,gBAAgB,CAAC;AAAA,EACjD,CAAC;AAEH,EAAAC,SACG,QAAQ,UAAU,EAClB,YAAY,gDAAgD,EAC5D,OAAO,WAAW,+GAA+G,KAAK,EACtI,OAAO,WAAW,oKAAoK,KAAK,EAC3L,OAAO,2BAA2B,2DAA2D,EAC7F,OAAO,OAAO,MAAM,QAAQ;AAC3B,UAAMD,UAAS,SAAS,MAAM,IAAI,gBAAgB,CAAC;AAAA,EACrD,CAAC;AAEH,EAAAC,SACG,QAAQ,KAAK,EACb,YAAY,qBAAqB,EACjC,SAAS,iBAAiB,oEAAoE,EAC9F,SAAS,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jC,QAAI,WAAW,QAAQ;AACrB,cAAQ,IAAI,KAAK,UAAU;AAAA,QACzB,SAAS;AAAA,QACT,UAAU,KAAK;AAAA,QACf;AAAA,QACA,gBAAgB,KAAK;AAAA,QACrB,iBAAiB;AAAA,MACnB,GAAG,MAAM,CAAC,CAAC;AAAA,IACb,OAAO;AACL,cAAQ,IAAI,MAAM;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,aAAa;AACxB,YAAQ,IAAI,iDAA4C;AAAA,EAC1D;AAAA,EAEA,MAAM,OAAO,QAAQ,SAAS,aAAa;AACzC,YAAQ,IAAI,iDAA4C;AACxD,YAAQ,IAAI,YAAY,MAAM,EAAE;AAChC,YAAQ,IAAI,YAAY,KAAK,UAAU,OAAO,CAAC;AAAA,EACjD;AACF;AAEA,IAAM,UAAU,cAAc,UAAU,OAAO;AAC/C,QAAQ,MAAM;","names":["handlers","program"]}
|
|
@@ -10,10 +10,24 @@ declare const RuntimeConfigSchema: z.ZodObject<{
|
|
|
10
10
|
bindings: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
11
11
|
active_guardrail_policy: z.ZodOptional<z.ZodString>;
|
|
12
12
|
templates_dir: z.ZodOptional<z.ZodString>;
|
|
13
|
+
recovery: z.ZodDefault<z.ZodObject<{
|
|
14
|
+
max_follow_ups: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
max_retries: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
max_follow_ups: number;
|
|
18
|
+
max_retries: number;
|
|
19
|
+
}, {
|
|
20
|
+
max_follow_ups?: number | undefined;
|
|
21
|
+
max_retries?: number | undefined;
|
|
22
|
+
}>>;
|
|
13
23
|
}, "strip", z.ZodTypeAny, {
|
|
14
24
|
dsl: string;
|
|
15
25
|
generated_dir: string;
|
|
16
26
|
bindings: string[];
|
|
27
|
+
recovery: {
|
|
28
|
+
max_follow_ups: number;
|
|
29
|
+
max_retries: number;
|
|
30
|
+
};
|
|
17
31
|
active_guardrail_policy?: string | undefined;
|
|
18
32
|
templates_dir?: string | undefined;
|
|
19
33
|
}, {
|
|
@@ -22,6 +36,10 @@ declare const RuntimeConfigSchema: z.ZodObject<{
|
|
|
22
36
|
bindings?: string[] | undefined;
|
|
23
37
|
active_guardrail_policy?: string | undefined;
|
|
24
38
|
templates_dir?: string | undefined;
|
|
39
|
+
recovery?: {
|
|
40
|
+
max_follow_ups?: number | undefined;
|
|
41
|
+
max_retries?: number | undefined;
|
|
42
|
+
} | undefined;
|
|
25
43
|
}>;
|
|
26
44
|
type RuntimeConfig = z.infer<typeof RuntimeConfigSchema>;
|
|
27
45
|
interface ResolvedConfig extends RuntimeConfig {
|
|
@@ -81,7 +99,13 @@ interface WorkflowStepEntry {
|
|
|
81
99
|
description?: string;
|
|
82
100
|
optional?: boolean;
|
|
83
101
|
max_retries?: number;
|
|
102
|
+
max_follow_ups?: number;
|
|
84
103
|
gate_kind?: string;
|
|
104
|
+
retry?: {
|
|
105
|
+
condition: string;
|
|
106
|
+
fix_task: string;
|
|
107
|
+
revalidate_task?: string;
|
|
108
|
+
};
|
|
85
109
|
}
|
|
86
110
|
interface WorkflowEntry {
|
|
87
111
|
id: string;
|
package/dist/generator/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TaskOutcome, a as TaskContext, S as SdkAdapter, b as TaskContractLike, A as AgentContractLike, P as PromptBuilderOptions } from './task-runner-
|
|
2
|
-
export { R as RetryDecision, c as TaskRunOptions, d as TaskRunResult, e as buildRetryFollowUp, f as buildTaskPrompt, g as extractStructuredResult, r as runTask, z as zodSchemaToPromptDescription, h as zodSchemaToYamlExample } from './task-runner-
|
|
1
|
+
import { T as TaskOutcome, a as TaskContext, S as SdkAdapter, b as TaskContractLike, A as AgentContractLike, P as PromptBuilderOptions } from './task-runner-DuZwv4zJ.js';
|
|
2
|
+
export { R as RetryDecision, c as TaskRunOptions, d as TaskRunResult, e as buildRetryFollowUp, f as buildTaskPrompt, g as extractStructuredResult, r as runTask, z as zodSchemaToPromptDescription, h as zodSchemaToYamlExample } from './task-runner-DuZwv4zJ.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -24,6 +24,12 @@ interface DelegateStep {
|
|
|
24
24
|
readonly description: string;
|
|
25
25
|
readonly optional: boolean;
|
|
26
26
|
readonly max_retries: number;
|
|
27
|
+
readonly max_follow_ups?: number;
|
|
28
|
+
readonly retry?: {
|
|
29
|
+
readonly condition: string;
|
|
30
|
+
readonly fix_task: string;
|
|
31
|
+
readonly revalidate_task?: string;
|
|
32
|
+
};
|
|
27
33
|
}
|
|
28
34
|
interface GateStep {
|
|
29
35
|
readonly type: "gate";
|
|
@@ -148,4 +154,62 @@ declare class PluginRegistry {
|
|
|
148
154
|
}
|
|
149
155
|
declare const pluginRegistry: PluginRegistry;
|
|
150
156
|
|
|
151
|
-
|
|
157
|
+
/**
|
|
158
|
+
* SDK Guardrail Hook Bridge — generic adapter from guardrail check functions
|
|
159
|
+
* + plugin guardrails to SDK-compatible hook responses.
|
|
160
|
+
*
|
|
161
|
+
* The generated hooks/index.ts calls createGuardrailHooks() with the
|
|
162
|
+
* DSL-generated check functions. All logic lives here in the lib.
|
|
163
|
+
*/
|
|
164
|
+
interface GuardrailCheckResult {
|
|
165
|
+
guardrail_id: string;
|
|
166
|
+
passed: boolean;
|
|
167
|
+
action: "block" | "warn" | "shadow" | "info";
|
|
168
|
+
message: string;
|
|
169
|
+
}
|
|
170
|
+
interface HookResponse {
|
|
171
|
+
permission?: "deny";
|
|
172
|
+
user_message?: string;
|
|
173
|
+
agent_message?: string;
|
|
174
|
+
additionalContext?: string;
|
|
175
|
+
}
|
|
176
|
+
interface GuardrailCheckFunctions {
|
|
177
|
+
checkCommand: (command: string) => GuardrailCheckResult[];
|
|
178
|
+
checkFilePath: (filePath: string) => GuardrailCheckResult[];
|
|
179
|
+
checkContent: (filePath: string, content: string) => GuardrailCheckResult[];
|
|
180
|
+
}
|
|
181
|
+
interface HookContext {
|
|
182
|
+
command?: string;
|
|
183
|
+
filePath?: string;
|
|
184
|
+
content?: string;
|
|
185
|
+
}
|
|
186
|
+
interface GuardrailHooks {
|
|
187
|
+
beforeShellExecution: (input: {
|
|
188
|
+
command?: string;
|
|
189
|
+
}) => HookResponse;
|
|
190
|
+
preToolUse: (input: {
|
|
191
|
+
tool_name?: string;
|
|
192
|
+
tool_input?: {
|
|
193
|
+
file_path?: string;
|
|
194
|
+
path?: string;
|
|
195
|
+
};
|
|
196
|
+
}) => HookResponse;
|
|
197
|
+
afterFileEdit: (input: {
|
|
198
|
+
file_path?: string;
|
|
199
|
+
content?: string;
|
|
200
|
+
}) => HookResponse;
|
|
201
|
+
runChecks: (ctx: HookContext) => GuardrailCheckResult[];
|
|
202
|
+
}
|
|
203
|
+
declare function getBlockingViolations(results: GuardrailCheckResult[]): GuardrailCheckResult[];
|
|
204
|
+
declare function getWarnings(results: GuardrailCheckResult[]): GuardrailCheckResult[];
|
|
205
|
+
declare function hasBlockingViolation(results: GuardrailCheckResult[]): boolean;
|
|
206
|
+
/**
|
|
207
|
+
* Create SDK hook functions from generated guardrail check functions.
|
|
208
|
+
*
|
|
209
|
+
* Merges DSL-generated checks with plugin-registered guardrails and
|
|
210
|
+
* returns hook functions in the format expected by Cursor / Claude SDKs,
|
|
211
|
+
* plus a generic runChecks() for programmatic use.
|
|
212
|
+
*/
|
|
213
|
+
declare function createGuardrailHooks(checks: GuardrailCheckFunctions): GuardrailHooks;
|
|
214
|
+
|
|
215
|
+
export { AgentContractLike, type AgentPlugin, type DelegateStep, type GateStep, type GuardrailCheckFunctions, type GuardrailCheckResult, type GuardrailHooks, type GuardrailResult, type HookContext, type HookResponse, PluginRegistry, type PromptBuilderArgs, PromptBuilderOptions, SdkAdapter, type StepCompleteEvent, type StepResult, TaskContext, TaskContractLike, TaskOutcome, type WorkflowContractLike, type WorkflowResult, type WorkflowRunOptions, type WorkflowStep, createGuardrailHooks, getBlockingViolations, getWarnings, hasBlockingViolation, pluginRegistry, runWorkflow };
|
package/dist/index.js
CHANGED
|
@@ -2,18 +2,26 @@ import {
|
|
|
2
2
|
PluginRegistry,
|
|
3
3
|
buildRetryFollowUp,
|
|
4
4
|
buildTaskPrompt,
|
|
5
|
+
createGuardrailHooks,
|
|
5
6
|
extractStructuredResult,
|
|
7
|
+
getBlockingViolations,
|
|
8
|
+
getWarnings,
|
|
9
|
+
hasBlockingViolation,
|
|
6
10
|
pluginRegistry,
|
|
7
11
|
runTask,
|
|
8
12
|
runWorkflow,
|
|
9
13
|
zodSchemaToPromptDescription,
|
|
10
14
|
zodSchemaToYamlExample
|
|
11
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-W4BDBZYV.js";
|
|
12
16
|
export {
|
|
13
17
|
PluginRegistry,
|
|
14
18
|
buildRetryFollowUp,
|
|
15
19
|
buildTaskPrompt,
|
|
20
|
+
createGuardrailHooks,
|
|
16
21
|
extractStructuredResult,
|
|
22
|
+
getBlockingViolations,
|
|
23
|
+
getWarnings,
|
|
24
|
+
hasBlockingViolation,
|
|
17
25
|
pluginRegistry,
|
|
18
26
|
runTask,
|
|
19
27
|
runWorkflow,
|
|
@@ -103,6 +103,11 @@ declare function zodSchemaToPromptDescription(schema: z.ZodTypeAny): string;
|
|
|
103
103
|
declare function zodSchemaToYamlExample(schema: z.ZodTypeAny): string;
|
|
104
104
|
interface PromptBuilderOptions {
|
|
105
105
|
handoffSchemas?: Record<string, z.ZodTypeAny>;
|
|
106
|
+
retry?: {
|
|
107
|
+
condition: string;
|
|
108
|
+
fix_task: string;
|
|
109
|
+
revalidate_task?: string;
|
|
110
|
+
};
|
|
106
111
|
}
|
|
107
112
|
declare function buildTaskPrompt(agent: AgentContractLike, task: TaskContractLike, context: TaskContext, options?: PromptBuilderOptions): string;
|
|
108
113
|
declare function extractStructuredResult(raw: string): unknown | null;
|
|
@@ -111,6 +116,11 @@ declare function runTask(adapter: SdkAdapter, taskId: string, context: TaskConte
|
|
|
111
116
|
agentRegistry?: Record<string, AgentContractLike>;
|
|
112
117
|
taskRegistry?: Record<string, TaskContractLike>;
|
|
113
118
|
handoffSchemas?: Record<string, z.ZodTypeAny>;
|
|
119
|
+
retry?: {
|
|
120
|
+
condition: string;
|
|
121
|
+
fix_task: string;
|
|
122
|
+
revalidate_task?: string;
|
|
123
|
+
};
|
|
114
124
|
}): Promise<TaskRunResult>;
|
|
115
125
|
|
|
116
126
|
export { type AgentContractLike as A, type PromptBuilderOptions as P, type RetryDecision as R, type SdkAdapter as S, type TaskOutcome as T, type TaskContext as a, type TaskContractLike as b, type TaskRunOptions as c, type TaskRunResult as d, buildRetryFollowUp as e, buildTaskPrompt as f, extractStructuredResult as g, zodSchemaToYamlExample as h, runTask as r, zodSchemaToPromptDescription as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-contracts-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Runtime bridge for executing agent-contracts workflows on Agent SDKs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@anthropic-ai/claude-agent-sdk": ">=0.2.0",
|
|
101
101
|
"@cursor/sdk": ">=1.0.0",
|
|
102
|
-
"agent-contracts": "
|
|
102
|
+
"agent-contracts": "^0.17.0"
|
|
103
103
|
},
|
|
104
104
|
"peerDependenciesMeta": {
|
|
105
105
|
"agent-contracts": {
|
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (ctx.filePath && ctx.content) {
|
|
23
|
-
results.push(...checkContent(ctx.filePath, ctx.content));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return results;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function hasBlockingViolation(results: GuardrailCheckResult[]): boolean {
|
|
30
|
-
return results.some((r) => !r.passed && r.action === "block");
|
|
31
|
-
}
|
|
1
|
+
import { createGuardrailHooks } from "agent-contracts-runtime";
|
|
2
|
+
import { checkCommand, checkFilePath, checkContent } from "./guardrails";
|
|
3
|
+
|
|
4
|
+
export const guardrailHooks = createGuardrailHooks({
|
|
5
|
+
checkCommand,
|
|
6
|
+
checkFilePath,
|
|
7
|
+
checkContent,
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export const { beforeShellExecution, preToolUse, afterFileEdit, runChecks } = guardrailHooks;
|
|
11
|
+
|
|
12
|
+
export { checkCommand, checkFilePath, checkContent, type GuardrailCheckResult } from "./guardrails";
|
|
13
|
+
export {
|
|
14
|
+
type HookResponse,
|
|
15
|
+
type HookContext,
|
|
16
|
+
hasBlockingViolation,
|
|
17
|
+
getBlockingViolations,
|
|
18
|
+
getWarnings,
|
|
19
|
+
} from "agent-contracts-runtime";
|