agent-contracts-runtime 0.31.4 → 0.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -96
- package/cli-contract.yaml +406 -26
- package/dist/{chunk-NLVQ3OOT.js → chunk-MINIXDVQ.js} +9 -2
- package/dist/chunk-MINIXDVQ.js.map +1 -0
- package/dist/{chunk-IAIG5VCJ.js → chunk-W5YWUFAH.js} +7 -3
- package/dist/chunk-W5YWUFAH.js.map +1 -0
- package/dist/cli/index.js +1130 -23
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/docs/cli-reference.md +1261 -111
- package/dsl/agent-runtime.config.yaml +2 -0
- package/dsl/agents/implementation-auditor.yaml +276 -0
- package/dsl/agents/llm-feature-implementer.yaml +294 -0
- package/dsl/handoff-types.yaml +187 -0
- package/dsl/implement-dsl.yaml +119 -0
- package/dsl/tasks.yaml +777 -0
- package/package.json +4 -1
- package/templates/implement-reference-templates.md +823 -0
- package/templates/implement-reference.md +220 -0
- package/templates/workflows.ts.hbs +2 -2
- package/dist/chunk-IAIG5VCJ.js.map +0 -1
- package/dist/chunk-NLVQ3OOT.js.map +0 -1
package/dsl/tasks.yaml
ADDED
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
implement-llm-feature:
|
|
2
|
+
description: |
|
|
3
|
+
Implement LLM-powered commands in a target CLI tool using the
|
|
4
|
+
agent-contracts + agent-contracts-runtime + cli-contracts stack.
|
|
5
|
+
|
|
6
|
+
## Implementation Procedure
|
|
7
|
+
|
|
8
|
+
### Step 1: Project Analysis
|
|
9
|
+
|
|
10
|
+
Read these files from the target project:
|
|
11
|
+
- cli-contract.yaml — existing commands, components/schemas, x-agent usage
|
|
12
|
+
- package.json — dependencies, scripts, bin entries, type:"module" check
|
|
13
|
+
- tsconfig.json — module resolution, paths, outDir
|
|
14
|
+
- src/ directory structure — understand existing command handler pattern
|
|
15
|
+
|
|
16
|
+
Determine:
|
|
17
|
+
- Which LLM commands to add (audit / propose / explain)
|
|
18
|
+
- What domain-specific context each command needs
|
|
19
|
+
- What structured output schema each command returns
|
|
20
|
+
- Whether the project already has agent-contracts integration
|
|
21
|
+
|
|
22
|
+
### Step 2: Install Dependencies
|
|
23
|
+
|
|
24
|
+
Add to package.json devDependencies:
|
|
25
|
+
- agent-contracts: ^0.32.0
|
|
26
|
+
- agent-contracts-runtime: ^0.31.0
|
|
27
|
+
- zod: ^4.0.0
|
|
28
|
+
|
|
29
|
+
Add optional peerDependencies for SDK packages:
|
|
30
|
+
- @anthropic-ai/claude-agent-sdk: >=0.2.0
|
|
31
|
+
- @openai/agents: >=0.10.0
|
|
32
|
+
- @google/genai: >=2.0.0
|
|
33
|
+
- @cursor/sdk (no version constraint)
|
|
34
|
+
|
|
35
|
+
### Step 3: Create DSL Definitions
|
|
36
|
+
|
|
37
|
+
Create directory structure:
|
|
38
|
+
|
|
39
|
+
dsl/
|
|
40
|
+
├── {project}-dsl.yaml
|
|
41
|
+
├── agent-runtime.config.yaml
|
|
42
|
+
├── agents/
|
|
43
|
+
│ └── {agent-name}.yaml
|
|
44
|
+
├── tasks.yaml
|
|
45
|
+
└── handoff-types.yaml
|
|
46
|
+
|
|
47
|
+
**Main DSL entry** (`dsl/{project}-dsl.yaml`):
|
|
48
|
+
|
|
49
|
+
version: 1
|
|
50
|
+
system:
|
|
51
|
+
id: {project}
|
|
52
|
+
name: "{Project} Agent System"
|
|
53
|
+
default_workflow_order:
|
|
54
|
+
- {workflow-ids}
|
|
55
|
+
agents: { $ref: "./agents/" }
|
|
56
|
+
tasks: { $ref: "./tasks.yaml" }
|
|
57
|
+
handoff_types: { $ref: "./handoff-types.yaml" }
|
|
58
|
+
guardrails:
|
|
59
|
+
output-schema-conformance:
|
|
60
|
+
description: ...
|
|
61
|
+
scope: { agents: [...], tasks: [...] }
|
|
62
|
+
rationale: ...
|
|
63
|
+
guardrail_policies:
|
|
64
|
+
{domain}-safety-policy:
|
|
65
|
+
rules:
|
|
66
|
+
- guardrail: output-schema-conformance
|
|
67
|
+
severity: critical
|
|
68
|
+
action: block
|
|
69
|
+
workflow:
|
|
70
|
+
{workflow-id}:
|
|
71
|
+
description: ...
|
|
72
|
+
trigger: cli-command
|
|
73
|
+
entry_conditions: [...]
|
|
74
|
+
steps:
|
|
75
|
+
- type: delegate
|
|
76
|
+
task: {task-id}
|
|
77
|
+
from_agent: {agent-id}
|
|
78
|
+
|
|
79
|
+
**Agent definition** (`dsl/agents/{agent-name}.yaml`):
|
|
80
|
+
|
|
81
|
+
{agent-name}:
|
|
82
|
+
role_name: "{Role Name}"
|
|
83
|
+
purpose: >-
|
|
84
|
+
Domain-specific purpose describing what the agent knows
|
|
85
|
+
and what it can do that static rules cannot.
|
|
86
|
+
mode: read-only
|
|
87
|
+
can_read_artifacts: []
|
|
88
|
+
can_write_artifacts: []
|
|
89
|
+
can_invoke_agents: []
|
|
90
|
+
can_execute_tools: []
|
|
91
|
+
can_return_handoffs: [{result-handoff-ids}]
|
|
92
|
+
responsibilities: [...]
|
|
93
|
+
constraints: [...]
|
|
94
|
+
rules:
|
|
95
|
+
- id: "R-{PREFIX}-001"
|
|
96
|
+
description: ...
|
|
97
|
+
severity: mandatory
|
|
98
|
+
escalation_criteria:
|
|
99
|
+
- condition: ...
|
|
100
|
+
action: stop_and_report
|
|
101
|
+
|
|
102
|
+
**Tasks** (`dsl/tasks.yaml`):
|
|
103
|
+
|
|
104
|
+
{task-id}:
|
|
105
|
+
description: ...
|
|
106
|
+
target_agent: {agent-name}
|
|
107
|
+
allowed_from_agents: [{agent-name}]
|
|
108
|
+
workflow: {workflow-id}
|
|
109
|
+
input_artifacts: []
|
|
110
|
+
invocation_handoff: {request-handoff}
|
|
111
|
+
result_handoff: {result-handoff}
|
|
112
|
+
responsibilities: [...]
|
|
113
|
+
completion_criteria: [...]
|
|
114
|
+
|
|
115
|
+
**Handoff types** (`dsl/handoff-types.yaml`):
|
|
116
|
+
Use AgentAuditResult shape as the base for result types:
|
|
117
|
+
|
|
118
|
+
{result-handoff}:
|
|
119
|
+
version: 1
|
|
120
|
+
description: ...
|
|
121
|
+
schema:
|
|
122
|
+
type: object
|
|
123
|
+
required: [summary, riskLevel, findings]
|
|
124
|
+
properties:
|
|
125
|
+
summary: { type: string }
|
|
126
|
+
riskLevel:
|
|
127
|
+
type: string
|
|
128
|
+
enum: [low, medium, high, critical]
|
|
129
|
+
findings:
|
|
130
|
+
type: array
|
|
131
|
+
items:
|
|
132
|
+
type: object
|
|
133
|
+
required: [severity, category, message]
|
|
134
|
+
properties:
|
|
135
|
+
id: { type: string }
|
|
136
|
+
severity:
|
|
137
|
+
type: string
|
|
138
|
+
enum: [info, warning, error, critical]
|
|
139
|
+
category: { type: string }
|
|
140
|
+
target: { type: string }
|
|
141
|
+
location: { type: string }
|
|
142
|
+
message: { type: string }
|
|
143
|
+
recommendation: { type: string }
|
|
144
|
+
confidence: { type: number, minimum: 0, maximum: 1 }
|
|
145
|
+
recommendedActions:
|
|
146
|
+
type: array
|
|
147
|
+
items:
|
|
148
|
+
type: object
|
|
149
|
+
required: [kind, title]
|
|
150
|
+
properties:
|
|
151
|
+
kind:
|
|
152
|
+
type: string
|
|
153
|
+
enum: [run_command, edit_file, review, confirm, block, ignore]
|
|
154
|
+
title: { type: string }
|
|
155
|
+
command: { type: string }
|
|
156
|
+
target: { type: string }
|
|
157
|
+
rationale: { type: string }
|
|
158
|
+
metadata:
|
|
159
|
+
type: object
|
|
160
|
+
properties:
|
|
161
|
+
tool: { type: string }
|
|
162
|
+
command: { type: string }
|
|
163
|
+
version: { type: string }
|
|
164
|
+
generatedAt: { type: string }
|
|
165
|
+
adapter: { type: string }
|
|
166
|
+
model: { type: string }
|
|
167
|
+
|
|
168
|
+
Domain-specific result types add properties alongside the base fields.
|
|
169
|
+
|
|
170
|
+
**Runtime config** (`dsl/agent-runtime.config.yaml`):
|
|
171
|
+
|
|
172
|
+
dsl: ./{project}-dsl.yaml
|
|
173
|
+
generated_dir: ../src/generated/dsl
|
|
174
|
+
|
|
175
|
+
### Step 4: Generate TypeScript Contracts
|
|
176
|
+
|
|
177
|
+
Add to package.json scripts:
|
|
178
|
+
|
|
179
|
+
"dsl:generate": "agent-runtime generate --config dsl/agent-runtime.config.yaml"
|
|
180
|
+
|
|
181
|
+
Run: npm run dsl:generate
|
|
182
|
+
|
|
183
|
+
This produces src/generated/dsl/ containing:
|
|
184
|
+
- agents.ts (AgentContract interface + agentRegistry)
|
|
185
|
+
- tasks.ts (TaskContract interface + taskRegistry)
|
|
186
|
+
- workflows.ts (WorkflowContract + workflowRegistry)
|
|
187
|
+
- handoffs.ts (Zod schemas + handoffSchemas + factory functions)
|
|
188
|
+
- index.ts (barrel re-exports)
|
|
189
|
+
|
|
190
|
+
### Step 5: Implement src/agents/ Module
|
|
191
|
+
|
|
192
|
+
**src/agents/types.ts**:
|
|
193
|
+
|
|
194
|
+
import type { {ResultType} } from "../generated/dsl/handoffs.js";
|
|
195
|
+
|
|
196
|
+
export type TaskId = "{task-1}" | "{task-2}" | ...;
|
|
197
|
+
|
|
198
|
+
export interface AgentConfig {
|
|
199
|
+
adapter?: string;
|
|
200
|
+
model?: string;
|
|
201
|
+
temperature?: number;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface AgentOptions {
|
|
205
|
+
dryRun?: boolean;
|
|
206
|
+
failOn?: "warning" | "error" | "critical";
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export interface AgentRunResult {
|
|
210
|
+
taskId: TaskId;
|
|
211
|
+
data: {ResultType} | null;
|
|
212
|
+
raw: string;
|
|
213
|
+
prompt: string;
|
|
214
|
+
dryRun: boolean;
|
|
215
|
+
status: "success" | "error" | "escalation" | "validation_error";
|
|
216
|
+
errorMessage?: string;
|
|
217
|
+
followUpsUsed: number;
|
|
218
|
+
retriesUsed: number;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
**src/agents/orchestrator.ts**:
|
|
222
|
+
|
|
223
|
+
export const EXIT_RUNTIME_MISSING = 11;
|
|
224
|
+
export const EXIT_ADAPTER_ERROR = 12;
|
|
225
|
+
|
|
226
|
+
async function createAdapter(pkg: string, name: string, config: AgentConfig) {
|
|
227
|
+
switch (name) {
|
|
228
|
+
case "mock": {
|
|
229
|
+
const m = await import(`${pkg}/adapters/mock`);
|
|
230
|
+
return new m.MockAdapter();
|
|
231
|
+
}
|
|
232
|
+
case "cursor": {
|
|
233
|
+
const m = await import(`${pkg}/adapters/cursor-sdk`);
|
|
234
|
+
return m.CursorSdkAdapter.create({ apiKey: process.env.CURSOR_API_KEY, model: config.model });
|
|
235
|
+
}
|
|
236
|
+
case "claude": {
|
|
237
|
+
const m = await import(`${pkg}/adapters/claude-agent-sdk`);
|
|
238
|
+
return new m.ClaudeAgentSdkAdapter({ model: config.model });
|
|
239
|
+
}
|
|
240
|
+
case "openai": {
|
|
241
|
+
const m = await import(`${pkg}/adapters/openai-agents-sdk`);
|
|
242
|
+
return new m.OpenAIAgentsSdkAdapter({ model: config.model });
|
|
243
|
+
}
|
|
244
|
+
case "gemini": {
|
|
245
|
+
const m = await import(`${pkg}/adapters/gemini-sdk`);
|
|
246
|
+
return new m.GeminiSdkAdapter({ apiKey: process.env.GEMINI_API_KEY, model: config.model });
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export async function runAgentWorkflow(
|
|
252
|
+
userRequest: string, workflowId: WorkflowId, config: AgentConfig, options: AgentOptions,
|
|
253
|
+
): Promise<AgentRunResult> {
|
|
254
|
+
if (options.dryRun) return { workflowId, data:null, raw:"", prompt:userRequest, dryRun:true, status:"success" };
|
|
255
|
+
|
|
256
|
+
const PKG = "agent-contracts-runtime";
|
|
257
|
+
let runWorkflow;
|
|
258
|
+
try { ({ runWorkflow } = await import(PKG)); }
|
|
259
|
+
catch { throw Object.assign(new Error("agent-contracts-runtime not installed"), { exitCode: EXIT_RUNTIME_MISSING }); }
|
|
260
|
+
|
|
261
|
+
let registries;
|
|
262
|
+
try {
|
|
263
|
+
const dsl = await import("../generated/dsl/index.js");
|
|
264
|
+
registries = { agentRegistry: dsl.agentRegistry, taskRegistry: dsl.taskRegistry, handoffSchemas: dsl.handoffSchemas, workflowRegistry: dsl.workflowRegistry };
|
|
265
|
+
} catch { registries = {}; }
|
|
266
|
+
|
|
267
|
+
const adapter = await createAdapter(PKG, config.adapter ?? "mock", config);
|
|
268
|
+
const result = await runWorkflow(adapter, { workflow: workflowId, user_request: userRequest, runtime: { maxFollowUps:3, maxRetries:1 } }, registries);
|
|
269
|
+
// map result to AgentRunResult
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
**src/agents/context-builder.ts**:
|
|
273
|
+
|
|
274
|
+
CRITICAL: context-builder builds the USER-SIDE prompt only.
|
|
275
|
+
Agent instructions (purpose, responsibilities, constraints, rules,
|
|
276
|
+
evaluation criteria, anti-patterns, output format) are defined in
|
|
277
|
+
the DSL (dsl/agents/*.yaml) and injected by the runtime via
|
|
278
|
+
buildTaskPrompt / runWorkflow. NEVER hardcode these in context-builder.
|
|
279
|
+
|
|
280
|
+
Context-builder SHOULD contain:
|
|
281
|
+
- Domain-specific DATA: file contents, configuration, scan results
|
|
282
|
+
- Project metadata: target paths, dialect, directory structure
|
|
283
|
+
- Deterministic pre-analysis: lint results, schema excerpts
|
|
284
|
+
- Operational context: cwd, timestamps
|
|
285
|
+
- Brief task framing: "# Migration Safety Audit Request"
|
|
286
|
+
|
|
287
|
+
Context-builder MUST NOT contain:
|
|
288
|
+
- "## Instructions" / "## Required Patterns" sections
|
|
289
|
+
- Output format specifications (handled by handoff schema)
|
|
290
|
+
- Evaluation criteria or checklists
|
|
291
|
+
- Anti-pattern definitions or rule sets
|
|
292
|
+
- API reference material
|
|
293
|
+
- Anything that duplicates DSL agent purpose/responsibilities/rules
|
|
294
|
+
|
|
295
|
+
export function build{Command}Context(target, config): string {
|
|
296
|
+
const sections = [];
|
|
297
|
+
sections.push("# {Command} Request");
|
|
298
|
+
sections.push(`## Target\n\n${target}`);
|
|
299
|
+
// Domain data only — no instructions here.
|
|
300
|
+
// Agent instructions come from DSL via buildTaskPrompt.
|
|
301
|
+
// Cap total context at 16KB
|
|
302
|
+
return sections.join("\n\n");
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
**src/agents/formatter.ts**:
|
|
306
|
+
|
|
307
|
+
export function computeExitCode(result, options): number {
|
|
308
|
+
if (result.dryRun) return 0;
|
|
309
|
+
if (result.status !== "success") return 1;
|
|
310
|
+
const order = ["info","warning","error","critical"];
|
|
311
|
+
const threshold = order.indexOf(options.failOn ?? "error");
|
|
312
|
+
return result.data.findings.some(f => order.indexOf(f.severity) >= threshold) ? 10 : 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export function formatResultText(result): string { /* severity icons, structured output */ }
|
|
316
|
+
export function formatResultJson(result): string { return JSON.stringify(result.data, null, 2); }
|
|
317
|
+
|
|
318
|
+
### Step 6: Create CLI Command Handlers
|
|
319
|
+
|
|
320
|
+
For each LLM command, create src/commands/{command}.ts:
|
|
321
|
+
|
|
322
|
+
export async function command{Name}(target, opts) {
|
|
323
|
+
const cwd = process.cwd();
|
|
324
|
+
const context = build{Name}Context(target, config);
|
|
325
|
+
const agentConfig = { adapter: opts.adapter, model: opts.model, cwd };
|
|
326
|
+
const result = await runAgentWorkflow(context, "{workflow-id}", agentConfig, agentOpts);
|
|
327
|
+
if (opts.reportFormat === "json") console.log(formatResultJson(result));
|
|
328
|
+
else console.log(formatResultText(result));
|
|
329
|
+
process.exit(computeExitCode(result, opts));
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
Wire handlers through cli-contracts' generated program:
|
|
333
|
+
|
|
334
|
+
import { createProgram, type CommandHandlers } from './generated/program.js';
|
|
335
|
+
|
|
336
|
+
const handlers: CommandHandlers = {
|
|
337
|
+
{commandName}: async (target, opts) => {
|
|
338
|
+
await command{Name}(target, opts);
|
|
339
|
+
},
|
|
340
|
+
// ... other handlers
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
createProgram(handlers, version).parse();
|
|
344
|
+
|
|
345
|
+
### Step 7: Update cli-contract.yaml
|
|
346
|
+
|
|
347
|
+
Add each LLM command with standard options and x-agent metadata:
|
|
348
|
+
|
|
349
|
+
{command-name}:
|
|
350
|
+
summary: "{Command summary}"
|
|
351
|
+
arguments: [...]
|
|
352
|
+
options:
|
|
353
|
+
- name: adapter
|
|
354
|
+
schema: { type: string, enum: [mock, cursor, claude, openai, gemini] }
|
|
355
|
+
- name: model
|
|
356
|
+
schema: { type: string }
|
|
357
|
+
- name: dry-run
|
|
358
|
+
schema: { type: boolean, default: false }
|
|
359
|
+
- name: fail-on
|
|
360
|
+
schema: { type: string, enum: [warning, error, critical], default: error }
|
|
361
|
+
- name: output
|
|
362
|
+
aliases: [o]
|
|
363
|
+
schema: { type: string }
|
|
364
|
+
file: { mode: write }
|
|
365
|
+
- name: report-format
|
|
366
|
+
schema: { type: string, enum: [json, text, yaml], default: json }
|
|
367
|
+
x-agent:
|
|
368
|
+
riskLevel: low
|
|
369
|
+
requiresConfirmation: false
|
|
370
|
+
idempotent: true
|
|
371
|
+
sideEffects: [network]
|
|
372
|
+
sideEffectNote: >-
|
|
373
|
+
Network calls to LLM provider when adapter is not mock.
|
|
374
|
+
Filesystem write only when --output is specified.
|
|
375
|
+
safeDryRunOption: dry-run
|
|
376
|
+
expectedDurationMs: 120000
|
|
377
|
+
retryableExitCodes: [1, 12]
|
|
378
|
+
exits:
|
|
379
|
+
'0': { description: "No blocking findings.", stdout: { format: json, schema: { $ref: '...' } } }
|
|
380
|
+
'1': { description: "General error.", stderr: { format: text } }
|
|
381
|
+
'3': { description: "Input validation failed.", stderr: { format: json } }
|
|
382
|
+
'10': { description: "Blocking findings detected.", stdout: { format: json, schema: { $ref: '...' } } }
|
|
383
|
+
'11': { description: "Runtime not installed.", stderr: { format: json } }
|
|
384
|
+
'12': { description: "Adapter error.", stderr: { format: json } }
|
|
385
|
+
|
|
386
|
+
Add AgentAuditResult, AgentFinding, AgentRecommendedAction, AgentEvidence
|
|
387
|
+
to components/schemas if not already present.
|
|
388
|
+
|
|
389
|
+
### Step 8: Update README
|
|
390
|
+
|
|
391
|
+
Add "Agent-Native Toolchain" section after mechanical features:
|
|
392
|
+
- Intro: tool encapsulates domain-specific semantic reasoning
|
|
393
|
+
- Deterministic checks first, then semantic audit
|
|
394
|
+
- Structured findings (AgentAuditResult/AgentFinding)
|
|
395
|
+
- LLM Adapter Configuration table
|
|
396
|
+
- Add agent-contracts-runtime, agent-contracts, cli-contracts to Technology Stack
|
|
397
|
+
|
|
398
|
+
target_agent: llm-feature-implementer
|
|
399
|
+
allowed_from_agents:
|
|
400
|
+
- llm-feature-implementer
|
|
401
|
+
workflow: implement-llm-feature
|
|
402
|
+
input_artifacts: []
|
|
403
|
+
invocation_handoff: implement-request
|
|
404
|
+
result_handoff: implementation-result
|
|
405
|
+
|
|
406
|
+
responsibilities:
|
|
407
|
+
- Analyze the target project and determine the right LLM commands to add
|
|
408
|
+
- Create all DSL definition files with correct cross-references
|
|
409
|
+
- Generate TypeScript contracts via agent-runtime generate
|
|
410
|
+
- Implement the complete src/agents/ module following the exact patterns
|
|
411
|
+
- Create CLI command handlers integrating with the project's existing CLI structure
|
|
412
|
+
- Update cli-contract.yaml with proper x-agent metadata and component schemas
|
|
413
|
+
- Ensure the implementation compiles and --dry-run mode works
|
|
414
|
+
|
|
415
|
+
completion_criteria:
|
|
416
|
+
- dsl/ directory contains valid DSL definitions that pass agent-runtime generate
|
|
417
|
+
- agent-runtime.config.yaml points to the DSL with correct generated_dir
|
|
418
|
+
- src/generated/dsl/ contains generated contracts (agentRegistry, taskRegistry, handoffSchemas, workflowRegistry)
|
|
419
|
+
- src/agents/orchestrator.ts uses runWorkflow from agent-contracts-runtime (never runTask directly, no direct adapter.send calls)
|
|
420
|
+
- src/agents/orchestrator.ts dynamic-imports the runtime and adapters with correct exit codes (11, 12)
|
|
421
|
+
- src/agents/context-builder.ts contains only domain data (file contents, config, scan results) — no hardcoded agent instructions, evaluation criteria, or output format specs
|
|
422
|
+
- src/agents/context-builder.ts caps input at 16KB
|
|
423
|
+
- src/agents/formatter.ts implements computeExitCode with the standard exit code mapping
|
|
424
|
+
- src/commands/ has a handler for each new LLM command, passing cwd to AgentConfig
|
|
425
|
+
- CLI entry point uses cli-contracts' createProgram(handlers, version) with CommandHandlers interface
|
|
426
|
+
- cli-contract.yaml has all new commands with --adapter, --model, --dry-run, --fail-on, --output, --report-format options
|
|
427
|
+
- cli-contract.yaml has x-agent metadata on each new command (riskLevel, safeDryRunOption, expectedDurationMs)
|
|
428
|
+
- components/schemas includes AgentAuditResult and related schemas
|
|
429
|
+
- All generated TypeScript compiles without type errors
|
|
430
|
+
- --dry-run returns the constructed prompt without calling the LLM
|
|
431
|
+
|
|
432
|
+
# =============================================================================
|
|
433
|
+
# Audit tasks — parallelized by layer
|
|
434
|
+
# =============================================================================
|
|
435
|
+
|
|
436
|
+
audit-dsl:
|
|
437
|
+
description: |
|
|
438
|
+
Audit the DSL layer of an LLM command integration.
|
|
439
|
+
|
|
440
|
+
Verify these files exist and are well-formed:
|
|
441
|
+
- dsl/{project}-dsl.yaml — must have version:1, system:{id,name},
|
|
442
|
+
agents/tasks/handoff_types via $ref
|
|
443
|
+
- dsl/agents/*.yaml — each agent has role_name, purpose, mode,
|
|
444
|
+
can_read_artifacts:[], can_write_artifacts:[], responsibilities,
|
|
445
|
+
constraints, rules with R-PREFIX-NNN
|
|
446
|
+
- dsl/tasks.yaml — target_agent, workflow, result_handoff all
|
|
447
|
+
cross-reference valid IDs
|
|
448
|
+
- dsl/handoff-types.yaml — version:1, schema with JSON Schema,
|
|
449
|
+
result types follow AgentAuditResult shape
|
|
450
|
+
- dsl/agent-runtime.config.yaml — dsl and generated_dir fields
|
|
451
|
+
|
|
452
|
+
Severity classification:
|
|
453
|
+
- critical: missing version:1 or system block (generator will fail)
|
|
454
|
+
- critical: task references non-existent agent or workflow
|
|
455
|
+
- critical: agent mode contradicts its purpose (see below)
|
|
456
|
+
- error: agent missing constraints or rules
|
|
457
|
+
- error: handoff schema not following AgentAuditResult shape
|
|
458
|
+
- warning: missing guardrails or guardrail_policies
|
|
459
|
+
- warning: agent has no escalation_criteria
|
|
460
|
+
|
|
461
|
+
CRITICAL: agent mode-purpose coherence (category: dsl-agent):
|
|
462
|
+
- Agent with mode: read-only has purpose or responsibilities
|
|
463
|
+
that describe file writing, editing, creation, or code
|
|
464
|
+
generation — the agent's adapter tools won't include Write/Edit
|
|
465
|
+
so the stated purpose is impossible to fulfil
|
|
466
|
+
- Agent with mode: read-write has purpose that is purely
|
|
467
|
+
analytical (audit, review, explain) with no file output —
|
|
468
|
+
unnecessarily broad permissions
|
|
469
|
+
|
|
470
|
+
Category vocabulary: dsl-structure, dsl-agent, dsl-task,
|
|
471
|
+
dsl-handoff, dsl-workflow, dsl-guardrail.
|
|
472
|
+
|
|
473
|
+
Output a partial audit-result with findings only from the DSL layer.
|
|
474
|
+
|
|
475
|
+
target_agent: implementation-auditor
|
|
476
|
+
allowed_from_agents:
|
|
477
|
+
- implementation-auditor
|
|
478
|
+
workflow: audit-implementation
|
|
479
|
+
input_artifacts: []
|
|
480
|
+
invocation_handoff: audit-request
|
|
481
|
+
result_handoff: audit-result
|
|
482
|
+
|
|
483
|
+
responsibilities:
|
|
484
|
+
- Check all DSL files for structural correctness
|
|
485
|
+
- Validate cross-references (agent↔task↔workflow↔handoff)
|
|
486
|
+
- Verify guardrails and guardrail_policies
|
|
487
|
+
- Check agent mode-purpose coherence (read-only agents must not
|
|
488
|
+
have write-oriented purposes; read-write agents must justify
|
|
489
|
+
their write permissions in their purpose)
|
|
490
|
+
|
|
491
|
+
completion_criteria:
|
|
492
|
+
- Every dsl/* file checked for required fields
|
|
493
|
+
- Cross-references validated
|
|
494
|
+
- Agent mode is consistent with stated purpose and responsibilities
|
|
495
|
+
- Findings use dsl-* category vocabulary
|
|
496
|
+
|
|
497
|
+
audit-runtime:
|
|
498
|
+
description: |
|
|
499
|
+
Audit the runtime integration layer of an LLM command integration.
|
|
500
|
+
|
|
501
|
+
Scan src/agents/orchestrator.ts (or equivalent runtime module):
|
|
502
|
+
|
|
503
|
+
CRITICAL violations (category: runtime-orchestrator):
|
|
504
|
+
- adapter.send() or adapter.sendExecution() called directly
|
|
505
|
+
- adapter.followUp() called directly
|
|
506
|
+
- Custom adapter class defined (not imported from runtime)
|
|
507
|
+
- runWorkflow not imported from agent-contracts-runtime
|
|
508
|
+
- runTask used instead of runWorkflow — consumer projects must
|
|
509
|
+
use runWorkflow() which orchestrates through the DSL workflow
|
|
510
|
+
DAG, activates workflow-level plugin hooks (beforeWorkflow/
|
|
511
|
+
afterWorkflow), handles gate steps and step dependencies.
|
|
512
|
+
runTask() is a low-level internal API; calling it directly
|
|
513
|
+
bypasses workflow orchestration entirely
|
|
514
|
+
|
|
515
|
+
ERROR violations (category: runtime-registry):
|
|
516
|
+
- Generated registries not imported from src/generated/dsl/
|
|
517
|
+
- Registries not passed to runWorkflow options
|
|
518
|
+
- Hard-coded agent/task definitions instead of registry lookup
|
|
519
|
+
|
|
520
|
+
ERROR violations (category: runtime-adapter):
|
|
521
|
+
- Adapter packages imported statically (not dynamic import)
|
|
522
|
+
- Missing exit code 11 when runtime import fails
|
|
523
|
+
- Missing exit code 12 when adapter creation fails
|
|
524
|
+
- CursorSdkAdapter created with constructor (must use static .create())
|
|
525
|
+
|
|
526
|
+
ERROR violations (category: runtime-handler):
|
|
527
|
+
- Project has cli-contracts generated code (src/generated/program.ts
|
|
528
|
+
or src/generated/cli/program.ts exporting CommandHandlers and
|
|
529
|
+
createProgram) but CLI entry point manually creates Commander
|
|
530
|
+
commands instead of using createProgram(handlers, version)
|
|
531
|
+
- LLM command handlers are not wired through the generated
|
|
532
|
+
CommandHandlers interface — handler signatures drift from the
|
|
533
|
+
cli-contract.yaml definition without type errors
|
|
534
|
+
- CLI entry point calls runTask directly instead of going through
|
|
535
|
+
the command handler → context-builder → orchestrator chain
|
|
536
|
+
|
|
537
|
+
WARNING violations (category: runtime-plugin):
|
|
538
|
+
- Plugin hooks explicitly bypassed or ignored
|
|
539
|
+
|
|
540
|
+
Category vocabulary: runtime-orchestrator, runtime-registry,
|
|
541
|
+
runtime-adapter, runtime-handler, runtime-plugin.
|
|
542
|
+
|
|
543
|
+
Output a partial audit-result with findings only from the runtime layer.
|
|
544
|
+
|
|
545
|
+
target_agent: implementation-auditor
|
|
546
|
+
allowed_from_agents:
|
|
547
|
+
- implementation-auditor
|
|
548
|
+
workflow: audit-implementation
|
|
549
|
+
input_artifacts: []
|
|
550
|
+
invocation_handoff: audit-request
|
|
551
|
+
result_handoff: audit-result
|
|
552
|
+
|
|
553
|
+
responsibilities:
|
|
554
|
+
- Scan orchestrator code for direct adapter usage
|
|
555
|
+
- Verify runWorkflow is used (not runTask) for LLM command execution
|
|
556
|
+
- Verify registry imports and passing
|
|
557
|
+
- Check adapter creation patterns and exit codes
|
|
558
|
+
- Verify cli-contracts handler wiring (CommandHandlers +
|
|
559
|
+
createProgram used in CLI entry point)
|
|
560
|
+
|
|
561
|
+
completion_criteria:
|
|
562
|
+
- All orchestrator files scanned for adapter.send / adapter.followUp
|
|
563
|
+
- No runTask usage found (runWorkflow must be used instead)
|
|
564
|
+
- Registry usage verified
|
|
565
|
+
- Exit code 11/12 patterns checked
|
|
566
|
+
- cli-contracts handler integration verified (CommandHandlers
|
|
567
|
+
interface used, createProgram called)
|
|
568
|
+
|
|
569
|
+
audit-cli-contract:
|
|
570
|
+
description: |
|
|
571
|
+
Audit the CLI contract layer of an LLM command integration.
|
|
572
|
+
|
|
573
|
+
Parse cli-contract.yaml and check each LLM command:
|
|
574
|
+
|
|
575
|
+
ERROR: missing standard options (category: cli-contract-options):
|
|
576
|
+
- --adapter, --model, --dry-run, --fail-on, --output, --report-format
|
|
577
|
+
- Using --format instead of --report-format for LLM commands
|
|
578
|
+
|
|
579
|
+
ERROR: missing x-agent metadata (category: cli-contract-xagent):
|
|
580
|
+
- No x-agent block on LLM command
|
|
581
|
+
- Missing riskLevel, safeDryRunOption, or expectedDurationMs
|
|
582
|
+
- Using snake_case instead of camelCase for x-agent fields
|
|
583
|
+
|
|
584
|
+
ERROR: wrong exit codes (category: cli-contract-exits):
|
|
585
|
+
- Missing exit 0/1/3/10/11/12 definitions
|
|
586
|
+
- Exit 10 not defined for finding-based commands
|
|
587
|
+
|
|
588
|
+
WARNING: missing schemas (category: cli-contract-schema):
|
|
589
|
+
- AgentAuditResult not in components/schemas
|
|
590
|
+
- AgentFinding, AgentRecommendedAction, AgentEvidence not defined
|
|
591
|
+
|
|
592
|
+
Category vocabulary: cli-contract-options, cli-contract-xagent,
|
|
593
|
+
cli-contract-exits, cli-contract-schema.
|
|
594
|
+
|
|
595
|
+
Output a partial audit-result with findings only from the CLI contract layer.
|
|
596
|
+
|
|
597
|
+
target_agent: implementation-auditor
|
|
598
|
+
allowed_from_agents:
|
|
599
|
+
- implementation-auditor
|
|
600
|
+
workflow: audit-implementation
|
|
601
|
+
input_artifacts: []
|
|
602
|
+
invocation_handoff: audit-request
|
|
603
|
+
result_handoff: audit-result
|
|
604
|
+
|
|
605
|
+
responsibilities:
|
|
606
|
+
- Check each LLM command for standard options
|
|
607
|
+
- Verify x-agent metadata fields and casing
|
|
608
|
+
- Validate exit code definitions
|
|
609
|
+
- Check components/schemas for canonical types
|
|
610
|
+
|
|
611
|
+
completion_criteria:
|
|
612
|
+
- Every LLM command checked for all 6 standard options
|
|
613
|
+
- x-agent metadata validated on every LLM command
|
|
614
|
+
- Exit codes verified against convention
|
|
615
|
+
- Schema completeness checked
|
|
616
|
+
|
|
617
|
+
audit-architecture:
|
|
618
|
+
description: |
|
|
619
|
+
Audit the architecture and module structure of an LLM command integration.
|
|
620
|
+
|
|
621
|
+
Verify module structure (category: architecture-modules):
|
|
622
|
+
- src/agents/types.ts exists with TaskId, AgentConfig, AgentOptions, AgentRunResult
|
|
623
|
+
- src/agents/orchestrator.ts exists
|
|
624
|
+
- src/agents/context-builder.ts exists
|
|
625
|
+
- src/agents/formatter.ts exists with computeExitCode
|
|
626
|
+
|
|
627
|
+
Verify behavior (category: architecture-dry-run):
|
|
628
|
+
- --dry-run path returns the constructed prompt without calling the adapter
|
|
629
|
+
- buildTaskPrompt is used (not a placeholder string)
|
|
630
|
+
|
|
631
|
+
CRITICAL: context-builder SSoT violations (category: architecture-context-builder):
|
|
632
|
+
|
|
633
|
+
The context-builder's role is to assemble domain-specific DATA (file
|
|
634
|
+
contents, configuration, scan results, schema context) into the user
|
|
635
|
+
prompt. Agent INSTRUCTIONS (how to evaluate, what rules to apply,
|
|
636
|
+
what patterns to look for, output format) belong in the DSL agent
|
|
637
|
+
definition and are injected by buildTaskPrompt / runWorkflow.
|
|
638
|
+
|
|
639
|
+
Detect any of the following in context-builder source code:
|
|
640
|
+
- Sections titled "## Instructions", "## Required Patterns",
|
|
641
|
+
"## Audit Instructions", "## Output Format", or similar
|
|
642
|
+
behavioral directive headings — these are agent instructions
|
|
643
|
+
that belong in DSL (agent purpose, responsibilities, constraints,
|
|
644
|
+
rules) and must not be hardcoded in context-builder
|
|
645
|
+
- Output format specifications (field lists, JSON/YAML schema
|
|
646
|
+
descriptions, example output structures) — buildTaskPrompt
|
|
647
|
+
already generates "Required Output Format" from the handoff
|
|
648
|
+
Zod schema; duplicating this in context-builder causes conflicts
|
|
649
|
+
- Domain-specific evaluation criteria, checklists, anti-pattern
|
|
650
|
+
definitions, rule sets, or API reference material — these
|
|
651
|
+
belong in the DSL agent definition's purpose field
|
|
652
|
+
- Any string that duplicates or paraphrases content already
|
|
653
|
+
present in the DSL agent's purpose, responsibilities,
|
|
654
|
+
constraints, or rules fields
|
|
655
|
+
|
|
656
|
+
What IS allowed in context-builder:
|
|
657
|
+
- File contents read from disk (migration SQL, schema, config)
|
|
658
|
+
- Project metadata (dialect, directories, file lists)
|
|
659
|
+
- Deterministic pre-analysis results (lint violations, scan output)
|
|
660
|
+
- Operational context (target path, cwd, timestamp)
|
|
661
|
+
- Brief task framing ("# Migration Safety Audit Request")
|
|
662
|
+
|
|
663
|
+
ERROR: mode-purpose coherence (category: architecture-agent-coherence):
|
|
664
|
+
- DSL agent with mode: read-only has purpose or responsibilities
|
|
665
|
+
that describe file writing, editing, creation, or modification
|
|
666
|
+
- DSL agent with mode: read-write but no cwd propagated to adapter
|
|
667
|
+
— the agent's file tools won't operate in the project directory
|
|
668
|
+
- Command handler doesn't pass cwd to AgentConfig when using an
|
|
669
|
+
agentic adapter (claude, cursor)
|
|
670
|
+
|
|
671
|
+
ERROR: adapter cwd propagation (category: architecture-adapter-cwd):
|
|
672
|
+
- AgentConfig type has no cwd field
|
|
673
|
+
- Command handlers don't set config.cwd = process.cwd() or
|
|
674
|
+
resolve(projectDir)
|
|
675
|
+
- createAdapter doesn't pass cwd to adapter constructor/factory
|
|
676
|
+
- Agentic adapters (claude, cursor) instantiated without cwd —
|
|
677
|
+
their file tools will operate in an undefined directory
|
|
678
|
+
|
|
679
|
+
CRITICAL: runTask usage (category: architecture-handler):
|
|
680
|
+
- runTask() imported or called anywhere in the consumer project —
|
|
681
|
+
consumer projects must use runWorkflow() exclusively; runTask()
|
|
682
|
+
is a low-level internal API that bypasses workflow DAG
|
|
683
|
+
orchestration, workflow-level plugin hooks, and gate steps
|
|
684
|
+
|
|
685
|
+
ERROR: cli-contracts handler wiring (category: architecture-handler):
|
|
686
|
+
- Project has cli-contracts generated code (src/generated/program.ts
|
|
687
|
+
or src/generated/cli/program.ts with CommandHandlers) but CLI
|
|
688
|
+
entry point manually creates Commander commands instead of
|
|
689
|
+
calling createProgram(handlers, version)
|
|
690
|
+
- Command handlers bypass the generated CommandHandlers interface
|
|
691
|
+
|
|
692
|
+
Scan for direct SDK imports (category: architecture-modules):
|
|
693
|
+
- @anthropic-ai/sdk or @anthropic-ai/claude-agent-sdk imported
|
|
694
|
+
outside src/agents/orchestrator.ts or adapter files
|
|
695
|
+
- openai or @openai/agents imported outside adapters
|
|
696
|
+
- @google/genai imported outside adapters
|
|
697
|
+
- @cursor/sdk imported outside adapters
|
|
698
|
+
|
|
699
|
+
Category vocabulary: architecture-modules, architecture-dry-run,
|
|
700
|
+
architecture-context-builder, architecture-agent-coherence,
|
|
701
|
+
architecture-adapter-cwd, architecture-handler,
|
|
702
|
+
architecture-formatter.
|
|
703
|
+
|
|
704
|
+
Output a partial audit-result with findings only from the architecture layer.
|
|
705
|
+
|
|
706
|
+
target_agent: implementation-auditor
|
|
707
|
+
allowed_from_agents:
|
|
708
|
+
- implementation-auditor
|
|
709
|
+
workflow: audit-implementation
|
|
710
|
+
input_artifacts: []
|
|
711
|
+
invocation_handoff: audit-request
|
|
712
|
+
result_handoff: audit-result
|
|
713
|
+
|
|
714
|
+
responsibilities:
|
|
715
|
+
- Verify module structure
|
|
716
|
+
- Check dry-run behavior
|
|
717
|
+
- Audit context-builder for SSoT violations (hardcoded instructions,
|
|
718
|
+
output format specs, domain rules that belong in DSL)
|
|
719
|
+
- Check mode-purpose coherence across DSL definitions and runtime code
|
|
720
|
+
- Verify cwd propagation from command handler through adapter config
|
|
721
|
+
- Verify cli-contracts handler wiring (CommandHandlers + createProgram)
|
|
722
|
+
- Scan for direct SDK imports
|
|
723
|
+
|
|
724
|
+
completion_criteria:
|
|
725
|
+
- Module structure verified
|
|
726
|
+
- Dry-run behavior confirmed
|
|
727
|
+
- Context-builder contains only domain data, not agent instructions
|
|
728
|
+
- Agent mode is consistent with purpose and tool usage
|
|
729
|
+
- cwd is propagated to agentic adapters
|
|
730
|
+
- cli-contracts handler integration verified
|
|
731
|
+
- No direct SDK imports outside adapter files
|
|
732
|
+
|
|
733
|
+
# =============================================================================
|
|
734
|
+
# Audit merge — aggregates parallel audit results
|
|
735
|
+
# =============================================================================
|
|
736
|
+
|
|
737
|
+
audit-merge:
|
|
738
|
+
description: |
|
|
739
|
+
Merge the partial audit results from the four parallel layer audits
|
|
740
|
+
(DSL, runtime, CLI contract, architecture) into a single unified
|
|
741
|
+
audit-result.
|
|
742
|
+
|
|
743
|
+
The prior_context contains the JSON output from each completed
|
|
744
|
+
audit step. Parse each one, combine all findings into a single
|
|
745
|
+
array, deduplicate by (target + message), assign sequential IDs
|
|
746
|
+
(F-001, F-002, ...), derive the overall riskLevel from the worst
|
|
747
|
+
finding severity, and produce prioritized recommendedActions.
|
|
748
|
+
|
|
749
|
+
Merging rules:
|
|
750
|
+
- Collect all findings from all layer results
|
|
751
|
+
- Sort: critical first, then error, warning, info
|
|
752
|
+
- Assign sequential IDs: F-001, F-002, ...
|
|
753
|
+
- Deduplicate: if two findings have the same target and message, keep one
|
|
754
|
+
- Derive riskLevel: any critical → critical, any error → high,
|
|
755
|
+
any warning → medium, info only → low
|
|
756
|
+
- Merge recommendedActions from all layers, deduplicate by title
|
|
757
|
+
- Set metadata: { tool: "agent-runtime", command: "audit-implementation" }
|
|
758
|
+
|
|
759
|
+
target_agent: implementation-auditor
|
|
760
|
+
allowed_from_agents:
|
|
761
|
+
- implementation-auditor
|
|
762
|
+
workflow: audit-implementation
|
|
763
|
+
input_artifacts: []
|
|
764
|
+
invocation_handoff: audit-request
|
|
765
|
+
result_handoff: audit-result
|
|
766
|
+
|
|
767
|
+
responsibilities:
|
|
768
|
+
- Parse prior_context JSON from each layer audit step
|
|
769
|
+
- Merge and deduplicate findings
|
|
770
|
+
- Derive overall riskLevel
|
|
771
|
+
- Produce a single coherent summary paragraph
|
|
772
|
+
|
|
773
|
+
completion_criteria:
|
|
774
|
+
- All findings from all layers included
|
|
775
|
+
- No duplicate findings
|
|
776
|
+
- riskLevel correctly derived from worst finding
|
|
777
|
+
- Summary paragraph covers all audited layers
|