agent-contracts-runtime 0.31.4 → 0.32.1
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 +411 -22
- package/dist/{chunk-IAIG5VCJ.js → chunk-W5YWUFAH.js} +7 -3
- package/dist/chunk-W5YWUFAH.js.map +1 -0
- package/dist/cli/index.js +1011 -12
- package/dist/cli/index.js.map +1 -1
- package/dist/generator/index.js +1 -1
- package/docs/cli-reference.md +1370 -216
- package/dsl/agent-runtime.config.yaml +2 -0
- package/dsl/agents/implementation-auditor.yaml +195 -0
- package/dsl/agents/llm-feature-implementer.yaml +298 -0
- package/dsl/handoff-types.yaml +184 -0
- package/dsl/implement-dsl.yaml +119 -0
- package/dsl/tasks.yaml +635 -0
- package/package.json +3 -1
- package/templates/implement-reference-templates.md +823 -0
- package/templates/implement-reference.md +240 -0
- package/templates/workflows.ts.hbs +2 -2
- package/dist/chunk-IAIG5VCJ.js.map +0 -1
|
@@ -0,0 +1,823 @@
|
|
|
1
|
+
# Reference Templates
|
|
2
|
+
|
|
3
|
+
Complete file templates for LLM command integration. Replace `{project}`,
|
|
4
|
+
`{agent-name}`, `{domain}` with project-specific values.
|
|
5
|
+
|
|
6
|
+
## DSL: Main entry (`dsl/{project}-dsl.yaml`)
|
|
7
|
+
|
|
8
|
+
```yaml
|
|
9
|
+
version: 1
|
|
10
|
+
system:
|
|
11
|
+
id: {project}
|
|
12
|
+
name: "{Project} Agent System"
|
|
13
|
+
default_workflow_order:
|
|
14
|
+
- {workflow-1}
|
|
15
|
+
- {workflow-2}
|
|
16
|
+
- {workflow-3}
|
|
17
|
+
|
|
18
|
+
agents: { $ref: "./agents/" }
|
|
19
|
+
tasks: { $ref: "./tasks.yaml" }
|
|
20
|
+
handoff_types: { $ref: "./handoff-types.yaml" }
|
|
21
|
+
|
|
22
|
+
guardrails:
|
|
23
|
+
output-schema-conformance:
|
|
24
|
+
description: >-
|
|
25
|
+
Ensure all agent outputs conform to the result handoff schema.
|
|
26
|
+
Validation is performed at runtime via Zod.
|
|
27
|
+
scope:
|
|
28
|
+
agents:
|
|
29
|
+
- {agent-name}
|
|
30
|
+
tasks:
|
|
31
|
+
- {task-1}
|
|
32
|
+
- {task-2}
|
|
33
|
+
- {task-3}
|
|
34
|
+
rationale: >-
|
|
35
|
+
Structured output conformance is critical for CLI parsing
|
|
36
|
+
and downstream tooling integration.
|
|
37
|
+
|
|
38
|
+
no-{dangerous-action}:
|
|
39
|
+
description: >-
|
|
40
|
+
Agent must never {perform dangerous action}.
|
|
41
|
+
scope:
|
|
42
|
+
agents:
|
|
43
|
+
- {agent-name}
|
|
44
|
+
rationale: >-
|
|
45
|
+
The agent operates in read-only analysis mode.
|
|
46
|
+
|
|
47
|
+
confidence-threshold:
|
|
48
|
+
description: >-
|
|
49
|
+
Findings with confidence below 0.5 must include an explicit
|
|
50
|
+
uncertainty disclaimer in their recommendation.
|
|
51
|
+
scope:
|
|
52
|
+
tasks:
|
|
53
|
+
- {task-1}
|
|
54
|
+
- {task-2}
|
|
55
|
+
rationale: >-
|
|
56
|
+
Low-confidence findings without disclaimers may mislead users.
|
|
57
|
+
|
|
58
|
+
guardrail_policies:
|
|
59
|
+
{domain}-safety-policy:
|
|
60
|
+
description: >-
|
|
61
|
+
Groups all guardrails for the {agent-name} agent.
|
|
62
|
+
rules:
|
|
63
|
+
- guardrail: output-schema-conformance
|
|
64
|
+
severity: critical
|
|
65
|
+
action: block
|
|
66
|
+
- guardrail: no-{dangerous-action}
|
|
67
|
+
severity: critical
|
|
68
|
+
action: block
|
|
69
|
+
- guardrail: confidence-threshold
|
|
70
|
+
severity: warning
|
|
71
|
+
action: warn
|
|
72
|
+
|
|
73
|
+
workflow:
|
|
74
|
+
{workflow-1}:
|
|
75
|
+
description: "{Workflow 1 description}"
|
|
76
|
+
trigger: cli-command
|
|
77
|
+
entry_conditions:
|
|
78
|
+
- "{Entry condition}"
|
|
79
|
+
steps:
|
|
80
|
+
- type: delegate
|
|
81
|
+
task: {task-1}
|
|
82
|
+
from_agent: {agent-name}
|
|
83
|
+
|
|
84
|
+
{workflow-2}:
|
|
85
|
+
description: "{Workflow 2 description}"
|
|
86
|
+
trigger: cli-command
|
|
87
|
+
entry_conditions:
|
|
88
|
+
- "{Entry condition}"
|
|
89
|
+
steps:
|
|
90
|
+
- type: delegate
|
|
91
|
+
task: {task-2}
|
|
92
|
+
from_agent: {agent-name}
|
|
93
|
+
|
|
94
|
+
{workflow-3}:
|
|
95
|
+
description: "{Workflow 3 description}"
|
|
96
|
+
trigger: cli-command
|
|
97
|
+
entry_conditions:
|
|
98
|
+
- "{Entry condition}"
|
|
99
|
+
steps:
|
|
100
|
+
- type: delegate
|
|
101
|
+
task: {task-3}
|
|
102
|
+
from_agent: {agent-name}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## DSL: Agent (`dsl/agents/{agent-name}.yaml`)
|
|
106
|
+
|
|
107
|
+
```yaml
|
|
108
|
+
{agent-name}:
|
|
109
|
+
role_name: "{Agent Role Name}"
|
|
110
|
+
purpose: >-
|
|
111
|
+
{Describe the agent's purpose. What domain knowledge does it have?
|
|
112
|
+
What can it do that static rules cannot?}
|
|
113
|
+
mode: read-only
|
|
114
|
+
can_read_artifacts: []
|
|
115
|
+
can_write_artifacts: []
|
|
116
|
+
can_invoke_agents: []
|
|
117
|
+
can_execute_tools: []
|
|
118
|
+
can_return_handoffs:
|
|
119
|
+
- {result-handoff-1}
|
|
120
|
+
- {result-handoff-2}
|
|
121
|
+
- {result-handoff-3}
|
|
122
|
+
responsibilities:
|
|
123
|
+
- "{Responsibility 1}"
|
|
124
|
+
- "{Responsibility 2}"
|
|
125
|
+
- "{Responsibility 3}"
|
|
126
|
+
constraints:
|
|
127
|
+
- "Do not claim safety without citing specific assumptions"
|
|
128
|
+
- "Output must conform to AgentAuditResult schema (summary, riskLevel, findings, recommendedActions, metadata)"
|
|
129
|
+
- "Findings must use {project} category vocabulary ({cat-1}, {cat-2}, ...)"
|
|
130
|
+
- "Each finding must include a recommendation when severity is warning or above"
|
|
131
|
+
rules:
|
|
132
|
+
- id: "R-{PREFIX}-001"
|
|
133
|
+
description: "{Rule 1}"
|
|
134
|
+
severity: mandatory
|
|
135
|
+
- id: "R-{PREFIX}-002"
|
|
136
|
+
description: "{Rule 2}"
|
|
137
|
+
severity: mandatory
|
|
138
|
+
escalation_criteria:
|
|
139
|
+
- condition: "Input cannot be parsed or is structurally invalid"
|
|
140
|
+
action: stop_and_report
|
|
141
|
+
- condition: "Input contains dynamic content that cannot be statically analyzed"
|
|
142
|
+
action: stop_and_report
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## DSL: Tasks (`dsl/tasks.yaml`)
|
|
146
|
+
|
|
147
|
+
```yaml
|
|
148
|
+
{task-1}:
|
|
149
|
+
description: "{Task 1: audit-style}"
|
|
150
|
+
target_agent: {agent-name}
|
|
151
|
+
allowed_from_agents:
|
|
152
|
+
- {agent-name}
|
|
153
|
+
workflow: {workflow-1}
|
|
154
|
+
input_artifacts: []
|
|
155
|
+
invocation_handoff: {request-handoff}
|
|
156
|
+
result_handoff: {result-handoff-1}
|
|
157
|
+
responsibilities:
|
|
158
|
+
- "Evaluate all items for risks"
|
|
159
|
+
- "Classify findings by severity and category"
|
|
160
|
+
completion_criteria:
|
|
161
|
+
- "All items evaluated"
|
|
162
|
+
- "Findings classified by severity and category"
|
|
163
|
+
- "Output conforms to AgentAuditResult schema"
|
|
164
|
+
|
|
165
|
+
{task-2}:
|
|
166
|
+
description: "{Task 2: proposal-style}"
|
|
167
|
+
target_agent: {agent-name}
|
|
168
|
+
allowed_from_agents:
|
|
169
|
+
- {agent-name}
|
|
170
|
+
workflow: {workflow-2}
|
|
171
|
+
input_artifacts: []
|
|
172
|
+
invocation_handoff: {request-handoff}
|
|
173
|
+
result_handoff: {result-handoff-2}
|
|
174
|
+
responsibilities:
|
|
175
|
+
- "Identify problems requiring structured proposals"
|
|
176
|
+
- "Generate valid, actionable proposals"
|
|
177
|
+
completion_criteria:
|
|
178
|
+
- "Proposal is complete and actionable"
|
|
179
|
+
- "Each step has valid output"
|
|
180
|
+
- "recommendedActions include concrete edit_file actions"
|
|
181
|
+
|
|
182
|
+
{task-3}:
|
|
183
|
+
description: "{Task 3: explain-style}"
|
|
184
|
+
target_agent: {agent-name}
|
|
185
|
+
allowed_from_agents:
|
|
186
|
+
- {agent-name}
|
|
187
|
+
workflow: {workflow-3}
|
|
188
|
+
input_artifacts: []
|
|
189
|
+
invocation_handoff: {request-handoff}
|
|
190
|
+
result_handoff: {result-handoff-3}
|
|
191
|
+
responsibilities:
|
|
192
|
+
- "Summarize output for non-expert readers"
|
|
193
|
+
- "Provide concrete next steps as recommendedActions"
|
|
194
|
+
completion_criteria:
|
|
195
|
+
- "Explanation accurately summarizes the command output"
|
|
196
|
+
- "Action items are concrete and actionable"
|
|
197
|
+
- "Technical terms explained for non-expert readers"
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## DSL: Handoff types (`dsl/handoff-types.yaml`)
|
|
201
|
+
|
|
202
|
+
**Preferred**: Use `$ref` to `cli-contract.yaml` AgentAuditResult as SSoT
|
|
203
|
+
(this is how cli-contracts itself does it):
|
|
204
|
+
|
|
205
|
+
```yaml
|
|
206
|
+
{request-handoff}:
|
|
207
|
+
version: 1
|
|
208
|
+
description: Request to execute a {project} audit task
|
|
209
|
+
schema:
|
|
210
|
+
type: object
|
|
211
|
+
properties:
|
|
212
|
+
task_id:
|
|
213
|
+
type: string
|
|
214
|
+
description: Identifier of the task to execute
|
|
215
|
+
context:
|
|
216
|
+
type: string
|
|
217
|
+
description: Built context string
|
|
218
|
+
required:
|
|
219
|
+
- task_id
|
|
220
|
+
|
|
221
|
+
{result-handoff-1}:
|
|
222
|
+
version: 1
|
|
223
|
+
description: >-
|
|
224
|
+
Result of a {project} audit task.
|
|
225
|
+
Schema references cli-contract.yaml AgentAuditResult as SSoT.
|
|
226
|
+
schema:
|
|
227
|
+
$ref: '../cli-contract.yaml#/components/schemas/AgentAuditResult'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
**Fallback** (when agent-contracts cannot resolve cross-file `$ref` at
|
|
231
|
+
generate time): Inline the schema with a comment noting the SSoT.
|
|
232
|
+
|
|
233
|
+
The inlined schema must follow the **cli-contracts reference specification**:
|
|
234
|
+
|
|
235
|
+
```yaml
|
|
236
|
+
{result-handoff-1}:
|
|
237
|
+
version: 1
|
|
238
|
+
description: >-
|
|
239
|
+
Result of a {project} audit task.
|
|
240
|
+
Inlined from cli-contract.yaml AgentAuditResult (SSoT).
|
|
241
|
+
schema:
|
|
242
|
+
type: object
|
|
243
|
+
required: [summary, riskLevel, findings]
|
|
244
|
+
properties:
|
|
245
|
+
summary:
|
|
246
|
+
type: string
|
|
247
|
+
riskLevel:
|
|
248
|
+
type: string
|
|
249
|
+
enum: [low, medium, high, critical]
|
|
250
|
+
findings:
|
|
251
|
+
type: array
|
|
252
|
+
items:
|
|
253
|
+
# AgentFinding — cli-contracts reference schema
|
|
254
|
+
type: object
|
|
255
|
+
required: [severity, category, message]
|
|
256
|
+
properties:
|
|
257
|
+
id:
|
|
258
|
+
type: string
|
|
259
|
+
description: Unique finding identifier
|
|
260
|
+
severity:
|
|
261
|
+
type: string
|
|
262
|
+
enum: [info, warning, error, critical]
|
|
263
|
+
category:
|
|
264
|
+
type: string
|
|
265
|
+
description: Finding category (domain-specific vocabulary)
|
|
266
|
+
target:
|
|
267
|
+
type: string
|
|
268
|
+
description: Target of the finding (file path, command ID, etc.)
|
|
269
|
+
location:
|
|
270
|
+
type: string
|
|
271
|
+
description: Location within the target
|
|
272
|
+
message:
|
|
273
|
+
type: string
|
|
274
|
+
recommendation:
|
|
275
|
+
type: string
|
|
276
|
+
confidence:
|
|
277
|
+
type: number
|
|
278
|
+
minimum: 0
|
|
279
|
+
maximum: 1
|
|
280
|
+
description: Confidence score (0-1) for LLM-generated findings
|
|
281
|
+
evidence:
|
|
282
|
+
type: array
|
|
283
|
+
items:
|
|
284
|
+
type: object
|
|
285
|
+
properties:
|
|
286
|
+
type: { type: string }
|
|
287
|
+
content: { type: string }
|
|
288
|
+
source: { type: string }
|
|
289
|
+
details:
|
|
290
|
+
type: object
|
|
291
|
+
additionalProperties: true
|
|
292
|
+
recommendedActions:
|
|
293
|
+
type: array
|
|
294
|
+
items:
|
|
295
|
+
# AgentRecommendedAction — cli-contracts reference schema
|
|
296
|
+
type: object
|
|
297
|
+
required: [kind, title]
|
|
298
|
+
properties:
|
|
299
|
+
kind:
|
|
300
|
+
type: string
|
|
301
|
+
enum: [run_command, edit_file, review, confirm, block, ignore]
|
|
302
|
+
title:
|
|
303
|
+
type: string
|
|
304
|
+
command:
|
|
305
|
+
type: string
|
|
306
|
+
description: CLI command to run (for run_command kind)
|
|
307
|
+
target:
|
|
308
|
+
type: string
|
|
309
|
+
description: Target file or resource
|
|
310
|
+
rationale:
|
|
311
|
+
type: string
|
|
312
|
+
metadata:
|
|
313
|
+
type: object
|
|
314
|
+
properties:
|
|
315
|
+
tool: { type: string }
|
|
316
|
+
command: { type: string }
|
|
317
|
+
version: { type: string }
|
|
318
|
+
generatedAt: { type: string }
|
|
319
|
+
adapter: { type: string }
|
|
320
|
+
model: { type: string }
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
**Domain-specific result types** extend the base shape with additional
|
|
324
|
+
fields while keeping all AgentAuditResult fields intact:
|
|
325
|
+
|
|
326
|
+
```yaml
|
|
327
|
+
{result-handoff-2}:
|
|
328
|
+
version: 1
|
|
329
|
+
description: >-
|
|
330
|
+
Domain-specific result extending AgentAuditResult.
|
|
331
|
+
Adds {domain-specific fields} alongside base fields.
|
|
332
|
+
schema:
|
|
333
|
+
type: object
|
|
334
|
+
required: [summary, riskLevel, findings]
|
|
335
|
+
properties:
|
|
336
|
+
# All AgentAuditResult base fields (same as above)
|
|
337
|
+
summary: { type: string }
|
|
338
|
+
riskLevel: { type: string, enum: [low, medium, high, critical] }
|
|
339
|
+
findings:
|
|
340
|
+
type: array
|
|
341
|
+
items: { ... } # Same AgentFinding shape
|
|
342
|
+
recommendedActions:
|
|
343
|
+
type: array
|
|
344
|
+
items: { ... } # Same AgentRecommendedAction shape
|
|
345
|
+
metadata: { ... }
|
|
346
|
+
|
|
347
|
+
# Domain-specific extensions:
|
|
348
|
+
phases:
|
|
349
|
+
type: array
|
|
350
|
+
items:
|
|
351
|
+
type: object
|
|
352
|
+
required: [name, sql]
|
|
353
|
+
properties:
|
|
354
|
+
name: { type: string }
|
|
355
|
+
sql: { type: string }
|
|
356
|
+
description: { type: string }
|
|
357
|
+
|
|
358
|
+
{result-handoff-3}:
|
|
359
|
+
version: 1
|
|
360
|
+
description: >-
|
|
361
|
+
Explain-style result extending AgentAuditResult.
|
|
362
|
+
schema:
|
|
363
|
+
type: object
|
|
364
|
+
required: [summary, riskLevel, findings]
|
|
365
|
+
properties:
|
|
366
|
+
# All AgentAuditResult base fields
|
|
367
|
+
summary: { type: string }
|
|
368
|
+
riskLevel: { type: string, enum: [low, medium, high, critical] }
|
|
369
|
+
findings: { ... }
|
|
370
|
+
recommendedActions: { ... }
|
|
371
|
+
metadata: { ... }
|
|
372
|
+
|
|
373
|
+
# Domain-specific extension:
|
|
374
|
+
explanation:
|
|
375
|
+
type: string
|
|
376
|
+
description: Human-readable explanation of the command output
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## DSL: Runtime config (`dsl/agent-runtime.config.yaml`)
|
|
380
|
+
|
|
381
|
+
```yaml
|
|
382
|
+
dsl: ./{project}-dsl.yaml
|
|
383
|
+
generated_dir: ../src/generated/dsl
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
## TypeScript: `src/agents/types.ts`
|
|
387
|
+
|
|
388
|
+
```typescript
|
|
389
|
+
import type { {ResultType} } from "../generated/dsl/handoffs.js";
|
|
390
|
+
|
|
391
|
+
export type TaskId =
|
|
392
|
+
| "{task-1}"
|
|
393
|
+
| "{task-2}"
|
|
394
|
+
| "{task-3}";
|
|
395
|
+
|
|
396
|
+
export interface AgentConfig {
|
|
397
|
+
adapter?: string;
|
|
398
|
+
model?: string;
|
|
399
|
+
temperature?: number;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export interface AgentOptions {
|
|
403
|
+
dryRun?: boolean;
|
|
404
|
+
failOn?: "warning" | "error" | "critical";
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export interface AgentRunResult {
|
|
408
|
+
taskId: TaskId;
|
|
409
|
+
data: {ResultType} | null;
|
|
410
|
+
raw: string;
|
|
411
|
+
prompt: string;
|
|
412
|
+
dryRun: boolean;
|
|
413
|
+
status: "success" | "error" | "escalation" | "validation_error";
|
|
414
|
+
errorMessage?: string;
|
|
415
|
+
followUpsUsed: number;
|
|
416
|
+
retriesUsed: number;
|
|
417
|
+
}
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
## TypeScript: `src/agents/orchestrator.ts`
|
|
421
|
+
|
|
422
|
+
```typescript
|
|
423
|
+
import type { AgentConfig, AgentOptions, AgentRunResult, TaskId } from "./types.js";
|
|
424
|
+
|
|
425
|
+
export const EXIT_RUNTIME_MISSING = 11;
|
|
426
|
+
export const EXIT_ADAPTER_ERROR = 12;
|
|
427
|
+
|
|
428
|
+
async function createAdapter(runtimePkg: string, name: string, config: AgentConfig) {
|
|
429
|
+
switch (name) {
|
|
430
|
+
case "mock": {
|
|
431
|
+
const mod = await import(`${runtimePkg}/adapters/mock`);
|
|
432
|
+
return new mod.MockAdapter();
|
|
433
|
+
}
|
|
434
|
+
case "cursor": {
|
|
435
|
+
const mod = await import(`${runtimePkg}/adapters/cursor-sdk`);
|
|
436
|
+
const apiKey = process.env.CURSOR_API_KEY;
|
|
437
|
+
if (!apiKey) throw new Error("CURSOR_API_KEY environment variable is required");
|
|
438
|
+
return mod.CursorSdkAdapter.create({ apiKey, model: config.model });
|
|
439
|
+
}
|
|
440
|
+
case "openai": {
|
|
441
|
+
const mod = await import(`${runtimePkg}/adapters/openai-agents-sdk`);
|
|
442
|
+
return new mod.OpenAIAgentsSdkAdapter({ model: config.model, maxTurns: 1 });
|
|
443
|
+
}
|
|
444
|
+
case "gemini": {
|
|
445
|
+
const mod = await import(`${runtimePkg}/adapters/gemini-sdk`);
|
|
446
|
+
return new mod.GeminiSdkAdapter({
|
|
447
|
+
apiKey: process.env.GEMINI_API_KEY,
|
|
448
|
+
model: config.model,
|
|
449
|
+
temperature: config.temperature,
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
case "claude": {
|
|
453
|
+
const mod = await import(`${runtimePkg}/adapters/claude-agent-sdk`);
|
|
454
|
+
return new mod.ClaudeAgentSdkAdapter({
|
|
455
|
+
model: config.model,
|
|
456
|
+
tools: ["Read", "Glob", "Grep"],
|
|
457
|
+
permissionMode: "bypassPermissions",
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
default:
|
|
461
|
+
throw new Error(`Unsupported adapter: "${name}". Available: mock, cursor, openai, gemini, claude.`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
export async function runAgentTask(
|
|
466
|
+
userRequest: string,
|
|
467
|
+
taskId: TaskId,
|
|
468
|
+
config: AgentConfig,
|
|
469
|
+
options: AgentOptions,
|
|
470
|
+
): Promise<AgentRunResult> {
|
|
471
|
+
if (options.dryRun) {
|
|
472
|
+
return { taskId, data: null, raw: "", prompt: userRequest, dryRun: true,
|
|
473
|
+
status: "success", followUpsUsed: 0, retriesUsed: 0 };
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
const RUNTIME_PKG = ["agent-contracts", "runtime"].join("-");
|
|
477
|
+
|
|
478
|
+
let runTask;
|
|
479
|
+
try {
|
|
480
|
+
const runtime = await import(RUNTIME_PKG);
|
|
481
|
+
runTask = runtime.runTask;
|
|
482
|
+
} catch {
|
|
483
|
+
throw Object.assign(
|
|
484
|
+
new Error("agent-contracts-runtime is not installed.\n npm install agent-contracts-runtime"),
|
|
485
|
+
{ exitCode: EXIT_RUNTIME_MISSING },
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let agentRegistry, taskRegistry, handoffSchemas;
|
|
490
|
+
try {
|
|
491
|
+
const dsl = await import("../generated/dsl/index.js");
|
|
492
|
+
agentRegistry = dsl.agentRegistry;
|
|
493
|
+
taskRegistry = dsl.taskRegistry;
|
|
494
|
+
handoffSchemas = dsl.handoffSchemas;
|
|
495
|
+
} catch {
|
|
496
|
+
agentRegistry = {}; taskRegistry = {}; handoffSchemas = {};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
let adapter;
|
|
500
|
+
try {
|
|
501
|
+
adapter = await createAdapter(RUNTIME_PKG, config.adapter ?? "mock", config);
|
|
502
|
+
} catch (err) {
|
|
503
|
+
throw Object.assign(err as Error, { exitCode: EXIT_ADAPTER_ERROR });
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
const result = await runTask(adapter, taskId, { user_request: userRequest }, {
|
|
507
|
+
maxFollowUps: 3, maxRetries: 1, agentRegistry, taskRegistry, handoffSchemas,
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const outcome = result.outcome;
|
|
511
|
+
return {
|
|
512
|
+
taskId,
|
|
513
|
+
data: outcome.status === "success" ? outcome.data : null,
|
|
514
|
+
raw: (outcome.raw as string) ?? "",
|
|
515
|
+
prompt: userRequest,
|
|
516
|
+
dryRun: false,
|
|
517
|
+
status: outcome.status,
|
|
518
|
+
errorMessage:
|
|
519
|
+
outcome.status === "error" ? outcome.message :
|
|
520
|
+
outcome.status === "escalation" ? outcome.reason :
|
|
521
|
+
outcome.status === "validation_error" ? outcome.errors?.message :
|
|
522
|
+
undefined,
|
|
523
|
+
followUpsUsed: result.follow_ups_used,
|
|
524
|
+
retriesUsed: result.retries_used,
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## TypeScript: `src/agents/formatter.ts`
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
import type { AgentRunResult, AgentOptions } from "./types.js";
|
|
533
|
+
|
|
534
|
+
export function computeExitCode(result: AgentRunResult, options: AgentOptions): number {
|
|
535
|
+
if (result.dryRun) return 0;
|
|
536
|
+
if (result.status !== "success" || !result.data) return 1;
|
|
537
|
+
|
|
538
|
+
const failOn = options.failOn ?? "error";
|
|
539
|
+
const order = ["info", "warning", "error", "critical"] as const;
|
|
540
|
+
const threshold = order.indexOf(failOn);
|
|
541
|
+
const hasBlocking = result.data.findings.some(
|
|
542
|
+
(f) => order.indexOf(f.severity) >= threshold,
|
|
543
|
+
);
|
|
544
|
+
return hasBlocking ? 10 : 0;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
export function formatResultText(result: AgentRunResult): string {
|
|
548
|
+
if (result.dryRun) return result.prompt;
|
|
549
|
+
if (result.status !== "success" || !result.data) {
|
|
550
|
+
return result.errorMessage ?? `Task failed: ${result.status}`;
|
|
551
|
+
}
|
|
552
|
+
const d = result.data;
|
|
553
|
+
const lines = [`Risk Level: ${d.riskLevel.toUpperCase()}`, `Summary: ${d.summary}`, ""];
|
|
554
|
+
if (d.findings.length > 0) {
|
|
555
|
+
lines.push(`Findings (${d.findings.length}):`, "");
|
|
556
|
+
for (const f of d.findings) {
|
|
557
|
+
const icon = f.severity === "critical" || f.severity === "error" ? "✖"
|
|
558
|
+
: f.severity === "warning" ? "⚠" : "ℹ";
|
|
559
|
+
lines.push(` ${icon} [${f.category}] ${f.message}`);
|
|
560
|
+
if (f.target) lines.push(` Target: ${f.target}`);
|
|
561
|
+
if (f.location) lines.push(` Location: ${f.location}`);
|
|
562
|
+
if (f.recommendation) lines.push(` Recommendation: ${f.recommendation}`);
|
|
563
|
+
if (f.confidence != null) lines.push(` Confidence: ${f.confidence}`);
|
|
564
|
+
lines.push("");
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
if (d.recommendedActions?.length) {
|
|
568
|
+
lines.push("Recommended Actions:");
|
|
569
|
+
for (const a of d.recommendedActions) {
|
|
570
|
+
lines.push(` - [${a.kind}] ${a.title}`);
|
|
571
|
+
if (a.command) lines.push(` $ ${a.command}`);
|
|
572
|
+
if (a.target) lines.push(` Target: ${a.target}`);
|
|
573
|
+
if (a.rationale) lines.push(` Rationale: ${a.rationale}`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
return lines.join("\n");
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export function formatResultJson(result: AgentRunResult): string {
|
|
580
|
+
if (result.dryRun) return JSON.stringify({ dryRun: true, prompt: result.prompt }, null, 2);
|
|
581
|
+
if (!result.data) return JSON.stringify({ error: result.errorMessage, status: result.status }, null, 2);
|
|
582
|
+
return JSON.stringify(result.data, null, 2);
|
|
583
|
+
}
|
|
584
|
+
```
|
|
585
|
+
|
|
586
|
+
## CLI registration pattern
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
import { Command } from "commander";
|
|
590
|
+
|
|
591
|
+
const audit = new Command("audit")
|
|
592
|
+
.description("Semantic safety audit via LLM")
|
|
593
|
+
.argument("[target]", "file or directory to audit")
|
|
594
|
+
.option("--adapter <name>", "LLM adapter (cursor, openai, gemini, claude, mock)", "mock")
|
|
595
|
+
.option("--model <name>", "Model name to pass to the adapter")
|
|
596
|
+
.option("--dry-run", "Output prompt without making an LLM call")
|
|
597
|
+
.option("--fail-on <level>", "Minimum severity for non-zero exit", "error")
|
|
598
|
+
.option("-o, --output <file>", "Write result to file instead of stdout")
|
|
599
|
+
.option("--report-format <fmt>", "Output format (json, text, yaml)", "json")
|
|
600
|
+
.action(async (target, opts) => {
|
|
601
|
+
// load config, call command handler
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
program.addCommand(audit);
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
## cli-contract.yaml: LLM command options + x-agent
|
|
608
|
+
|
|
609
|
+
```yaml
|
|
610
|
+
commands:
|
|
611
|
+
audit:
|
|
612
|
+
description: "Semantic safety audit via LLM"
|
|
613
|
+
arguments:
|
|
614
|
+
- name: target
|
|
615
|
+
index: 0
|
|
616
|
+
required: false
|
|
617
|
+
description: "File or directory to audit"
|
|
618
|
+
schema:
|
|
619
|
+
type: string
|
|
620
|
+
|
|
621
|
+
options:
|
|
622
|
+
- name: adapter
|
|
623
|
+
description: LLM adapter to use.
|
|
624
|
+
valueName: name
|
|
625
|
+
schema:
|
|
626
|
+
type: string
|
|
627
|
+
enum: [mock, cursor, claude, openai, gemini]
|
|
628
|
+
|
|
629
|
+
- name: model
|
|
630
|
+
description: Model name to pass to the adapter.
|
|
631
|
+
valueName: name
|
|
632
|
+
schema:
|
|
633
|
+
type: string
|
|
634
|
+
|
|
635
|
+
- name: dry-run
|
|
636
|
+
description: Output the prompt context without making an LLM call.
|
|
637
|
+
schema:
|
|
638
|
+
type: boolean
|
|
639
|
+
default: false
|
|
640
|
+
|
|
641
|
+
- name: fail-on
|
|
642
|
+
description: Minimum severity that causes a non-zero exit.
|
|
643
|
+
valueName: level
|
|
644
|
+
schema:
|
|
645
|
+
type: string
|
|
646
|
+
enum: [warning, error, critical]
|
|
647
|
+
default: error
|
|
648
|
+
|
|
649
|
+
- name: output
|
|
650
|
+
aliases: [o]
|
|
651
|
+
description: Write result to a file instead of stdout.
|
|
652
|
+
valueName: file
|
|
653
|
+
schema:
|
|
654
|
+
type: string
|
|
655
|
+
file:
|
|
656
|
+
mode: write
|
|
657
|
+
mediaType: application/json
|
|
658
|
+
encoding: utf-8
|
|
659
|
+
|
|
660
|
+
- name: report-format
|
|
661
|
+
description: Output format for the audit report.
|
|
662
|
+
valueName: fmt
|
|
663
|
+
schema:
|
|
664
|
+
type: string
|
|
665
|
+
enum: [json, text, yaml]
|
|
666
|
+
default: json
|
|
667
|
+
|
|
668
|
+
x-agent:
|
|
669
|
+
riskLevel: low
|
|
670
|
+
requiresConfirmation: false
|
|
671
|
+
idempotent: true
|
|
672
|
+
sideEffects: [network]
|
|
673
|
+
sideEffectNote: >-
|
|
674
|
+
Network calls to LLM provider when adapter is not mock.
|
|
675
|
+
Filesystem write only when --output is specified.
|
|
676
|
+
safeDryRunOption: dry-run
|
|
677
|
+
expectedDurationMs: 120000
|
|
678
|
+
retryableExitCodes: [1, 12]
|
|
679
|
+
|
|
680
|
+
exits:
|
|
681
|
+
'0':
|
|
682
|
+
description: Completed without blocking findings.
|
|
683
|
+
stdout:
|
|
684
|
+
format: '{options.report-format}'
|
|
685
|
+
schema:
|
|
686
|
+
$ref: '#/components/schemas/AgentAuditResult'
|
|
687
|
+
'1':
|
|
688
|
+
description: Unexpected error.
|
|
689
|
+
stderr:
|
|
690
|
+
format: json
|
|
691
|
+
schema:
|
|
692
|
+
$ref: '#/components/schemas/Error'
|
|
693
|
+
'3':
|
|
694
|
+
description: Input validation/parse failed.
|
|
695
|
+
stderr:
|
|
696
|
+
format: json
|
|
697
|
+
schema:
|
|
698
|
+
$ref: '#/components/schemas/Error'
|
|
699
|
+
'10':
|
|
700
|
+
description: Completed with blocking findings.
|
|
701
|
+
stdout:
|
|
702
|
+
format: '{options.report-format}'
|
|
703
|
+
schema:
|
|
704
|
+
$ref: '#/components/schemas/AgentAuditResult'
|
|
705
|
+
'11':
|
|
706
|
+
description: Runtime dependency missing (agent-contracts-runtime).
|
|
707
|
+
stderr:
|
|
708
|
+
format: json
|
|
709
|
+
schema:
|
|
710
|
+
$ref: '#/components/schemas/Error'
|
|
711
|
+
'12':
|
|
712
|
+
description: Adapter initialization error.
|
|
713
|
+
stderr:
|
|
714
|
+
format: json
|
|
715
|
+
schema:
|
|
716
|
+
$ref: '#/components/schemas/Error'
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
## cli-contract.yaml: AgentAuditResult schema (in components/schemas)
|
|
720
|
+
|
|
721
|
+
This is the reference specification from cli-contracts. Include it in
|
|
722
|
+
your project's `cli-contract.yaml` `components/schemas` section:
|
|
723
|
+
|
|
724
|
+
```yaml
|
|
725
|
+
components:
|
|
726
|
+
schemas:
|
|
727
|
+
AgentFinding:
|
|
728
|
+
type: object
|
|
729
|
+
description: >-
|
|
730
|
+
A single finding from an agent audit.
|
|
731
|
+
Reference schema for AI agent interoperability.
|
|
732
|
+
required: [severity, category, message]
|
|
733
|
+
properties:
|
|
734
|
+
id:
|
|
735
|
+
type: string
|
|
736
|
+
description: Unique finding identifier.
|
|
737
|
+
severity:
|
|
738
|
+
type: string
|
|
739
|
+
enum: [info, warning, error, critical]
|
|
740
|
+
category:
|
|
741
|
+
type: string
|
|
742
|
+
description: Finding category (domain-specific vocabulary).
|
|
743
|
+
target:
|
|
744
|
+
type: string
|
|
745
|
+
description: Target of the finding (file path, command ID, etc.).
|
|
746
|
+
location:
|
|
747
|
+
type: string
|
|
748
|
+
description: Location within the target.
|
|
749
|
+
message:
|
|
750
|
+
type: string
|
|
751
|
+
recommendation:
|
|
752
|
+
type: string
|
|
753
|
+
confidence:
|
|
754
|
+
type: number
|
|
755
|
+
minimum: 0
|
|
756
|
+
maximum: 1
|
|
757
|
+
description: Confidence score (0-1) for LLM-generated findings.
|
|
758
|
+
evidence:
|
|
759
|
+
type: array
|
|
760
|
+
items:
|
|
761
|
+
$ref: '#/components/schemas/AgentEvidence'
|
|
762
|
+
details:
|
|
763
|
+
type: object
|
|
764
|
+
additionalProperties: true
|
|
765
|
+
|
|
766
|
+
AgentEvidence:
|
|
767
|
+
type: object
|
|
768
|
+
properties:
|
|
769
|
+
type: { type: string }
|
|
770
|
+
content: { type: string }
|
|
771
|
+
source: { type: string }
|
|
772
|
+
|
|
773
|
+
AgentRecommendedAction:
|
|
774
|
+
type: object
|
|
775
|
+
description: >-
|
|
776
|
+
A recommended action from an agent audit.
|
|
777
|
+
Reference schema for AI agent interoperability.
|
|
778
|
+
required: [kind, title]
|
|
779
|
+
properties:
|
|
780
|
+
kind:
|
|
781
|
+
type: string
|
|
782
|
+
enum: [run_command, edit_file, review, confirm, block, ignore]
|
|
783
|
+
title:
|
|
784
|
+
type: string
|
|
785
|
+
command:
|
|
786
|
+
type: string
|
|
787
|
+
description: CLI command to run (for run_command kind).
|
|
788
|
+
target:
|
|
789
|
+
type: string
|
|
790
|
+
description: Target file or resource.
|
|
791
|
+
rationale:
|
|
792
|
+
type: string
|
|
793
|
+
|
|
794
|
+
AgentAuditResult:
|
|
795
|
+
type: object
|
|
796
|
+
description: >-
|
|
797
|
+
Top-level result from an agent audit.
|
|
798
|
+
Reference schema for AI agent interoperability.
|
|
799
|
+
required: [summary, riskLevel, findings]
|
|
800
|
+
properties:
|
|
801
|
+
summary:
|
|
802
|
+
type: string
|
|
803
|
+
riskLevel:
|
|
804
|
+
type: string
|
|
805
|
+
enum: [low, medium, high, critical]
|
|
806
|
+
findings:
|
|
807
|
+
type: array
|
|
808
|
+
items:
|
|
809
|
+
$ref: '#/components/schemas/AgentFinding'
|
|
810
|
+
recommendedActions:
|
|
811
|
+
type: array
|
|
812
|
+
items:
|
|
813
|
+
$ref: '#/components/schemas/AgentRecommendedAction'
|
|
814
|
+
metadata:
|
|
815
|
+
type: object
|
|
816
|
+
properties:
|
|
817
|
+
tool: { type: string }
|
|
818
|
+
command: { type: string }
|
|
819
|
+
version: { type: string }
|
|
820
|
+
generatedAt: { type: string }
|
|
821
|
+
adapter: { type: string }
|
|
822
|
+
model: { type: string }
|
|
823
|
+
```
|