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 CHANGED
@@ -2,120 +2,102 @@
2
2
 
3
3
  Runtime bridge for executing [`agent-contracts`](https://github.com/foo-log-inc/agent-contracts) agent teams from TypeScript programs.
4
4
 
5
- `agent-contracts` defines business-level agent behavior in DSL: agent roles, task boundaries, workflows, handoff schemas, validations, and guardrails.
5
+ ## Built-in Agents: Implement and Audit
6
6
 
7
- `agent-contracts-runtime` makes those DSL-defined workflows callable from ordinary TypeScript code.
7
+ `agent-contracts-runtime` ships with two built-in agents that add LLM-powered commands to any CLI tool using the three-layer stack (`agent-contracts` + `agent-contracts-runtime` + `cli-contracts`).
8
8
 
9
- It sits between your program and Agent SDKs:
9
+ ### `agent-runtime implement` — Let the agent build it
10
10
 
11
- ```
12
- TypeScript program
13
- ↓
14
- WorkflowInvocation
15
- ↓
16
- agent-contracts-runtime
17
- ↓
18
- DSL-derived contracts
19
- ↓
20
- Agent SDK adapter
21
- ↓
22
- Cursor / Claude / OpenAI Agents SDK / custom runner
11
+ Instead of hand-writing the integration code yourself, describe what you want and let the implementation agent do it:
12
+
13
+ ```bash
14
+ agent-runtime implement \
15
+ --adapter claude \
16
+ --project-dir ./my-tool \
17
+ "Add an audit command for migration safety and a propose command for SQL optimization"
23
18
  ```
24
19
 
25
- Agent SDKs execute LLM agents.
20
+ The agent reads your project, then generates:
26
21
 
27
- `agent-contracts-runtime` lets application code invoke reusable, DSL-defined agent workflows without hand-writing SDK-specific orchestration for each workflow.
22
+ - DSL definitions (`dsl/agents/`, `dsl/tasks.yaml`, `dsl/handoff-types.yaml`, workflows, guardrails)
23
+ - TypeScript contracts via `agent-runtime generate`
24
+ - Runtime integration (`src/agents/orchestrator.ts`, `context-builder.ts`, `formatter.ts`)
25
+ - CLI command handlers
26
+ - Updated `cli-contract.yaml` with `x-agent` metadata and `components/schemas`
28
27
 
29
- ## Why this exists
28
+ The agent is a domain expert in the three-layer stack. It knows the correct patterns, exit code conventions, adapter usage, and registry wiring. It will not call LLM APIs directly — all invocations go through `runTask`/`runWorkflow`.
30
29
 
31
- Agent SDKs are good at executing agents.
30
+ ```bash
31
+ agent-runtime implement --dry-run "Add an audit command" # Preview the prompt
32
+ agent-runtime implement --report-format json "..." # JSON output
33
+ agent-runtime implement --model claude-sonnet-4 "..." # Specify model
34
+ ```
32
35
 
33
- But business-level agent behavior often involves more than one prompt or one SDK call.
36
+ ### `agent-runtime audit-implementation` — Verify the integration
34
37
 
35
- A real agent team may define:
38
+ After implementation (by the agent or by hand), audit the result:
36
39
 
37
- - which agents exist
38
- - which tasks they can perform
39
- - who can delegate to whom
40
- - what handoff shape is expected
41
- - which workflow steps are allowed
42
- - what validation must happen before the next step
43
- - which guardrails apply
40
+ ```bash
41
+ agent-runtime audit-implementation --adapter claude ./my-tool
42
+ ```
44
43
 
45
- That behavior belongs in `agent-contracts` DSL.
44
+ The auditor checks all three layers in parallel:
46
45
 
47
- `agent-contracts-runtime` exists so TypeScript programs can execute those DSL-defined workflows without rewriting the same SDK-specific orchestration code each time.
46
+ | Layer | What it checks |
47
+ |-------|----------------|
48
+ | **DSL** | version:1, system block, agent/task/workflow cross-references, guardrails |
49
+ | **Runtime** | `runTask`/`runWorkflow` usage (no `adapter.send()`), dynamic imports, exit codes 11/12, registry passing |
50
+ | **CLI contract** | Standard options (--adapter, --model, --dry-run, --fail-on, --output, --report-format), x-agent metadata, exit codes |
51
+ | **Architecture** | Module structure, dry-run behavior, context size cap, no direct SDK imports |
48
52
 
49
- ## What it does
53
+ The four layer checks run concurrently via the DAG workflow scheduler, then merge into a single structured report:
50
54
 
51
- `agent-contracts-runtime`:
55
+ ```bash
56
+ agent-runtime audit-implementation --focus dsl ./my-tool # Check one layer
57
+ agent-runtime audit-implementation --fail-on warning ./my-tool # Strict mode
58
+ agent-runtime audit-implementation --report-format json ./my-tool # JSON output
59
+ agent-runtime audit-implementation --output report.json ./my-tool # Write to file
60
+ ```
52
61
 
53
- - loads generated contracts from `agent-contracts`
54
- - accepts workflow invocations from TypeScript or CLI
55
- - resolves the DSL-defined workflow, task, agent, and handoff contracts
56
- - builds an SDK execution request
57
- - calls an Agent SDK through an adapter
58
- - validates the returned handoff
59
- - returns a structured workflow result
62
+ Exit codes: `0` = no findings above threshold, `10` = findings detected, `12` = adapter error.
60
63
 
61
- It is the execution bridge for DSL-defined agent teams.
64
+ ### Why use the built-in agents?
62
65
 
63
- ## Why not call the SDK directly?
66
+ Hand-writing the integration code for `agent-contracts` + `agent-contracts-runtime` + `cli-contracts` is error-prone. Common mistakes include:
64
67
 
65
- You can.
68
+ - Calling `adapter.send()` directly instead of `runTask()`/`runWorkflow()`
69
+ - Missing standard CLI options or exit codes
70
+ - Forgetting `x-agent` metadata
71
+ - Incorrect adapter construction (e.g., `new CursorSdkAdapter()` instead of `CursorSdkAdapter.create()`)
72
+ - Static imports instead of dynamic imports for graceful degradation
66
73
 
67
- For simple one-off agents, direct SDK code is enough.
74
+ The implementation agent has all of these patterns embedded in its DSL definition. The audit agent detects violations. Together they form a closed loop: implement correctly, then verify.
68
75
 
69
- `agent-contracts-runtime` is useful when the agent behavior is defined as reusable contracts:
76
+ ---
70
77
 
71
- - multiple workflows use the same agent team
72
- - handoff schemas should be generated and validated
73
- - workflow steps should come from DSL, not scattered program code
74
- - different SDK adapters should run the same contract
75
- - application code should call business-level workflows, not low-level agent prompts
78
+ ## Overview
76
79
 
77
- Instead of writing this repeatedly:
80
+ `agent-contracts` defines business-level agent behavior in DSL: agent roles, task boundaries, workflows, handoff schemas, validations, and guardrails.
78
81
 
79
- ```typescript
80
- // resolve prompt
81
- // choose agent
82
- // build context
83
- // call SDK
84
- // parse output
85
- // validate schema
86
- // retry on malformed output
87
- // route to next task
88
- ```
82
+ `agent-contracts-runtime` makes those DSL-defined workflows callable from ordinary TypeScript code.
89
83
 
90
- you call:
84
+ It sits between your program and Agent SDKs:
91
85
 
92
- ```typescript
93
- const result = await runtime
94
- .workflow("feature-implement")
95
- .handoff(handoffs.featureImplementationRequest({
96
- objective: "Add login endpoint with JWT",
97
- inputs: { repository: "." },
98
- expectedOutputs: ["implementation-diff"],
99
- completionCriteria: ["tests_passed"],
100
- }))
101
- .run();
86
+ ```
87
+ TypeScript program
88
+ ↓
89
+ WorkflowInvocation
90
+ ↓
91
+ agent-contracts-runtime
92
+ ↓
93
+ DSL-derived contracts
94
+ ↓
95
+ Agent SDK adapter
96
+ ↓
97
+ Cursor / Claude / OpenAI Agents SDK / custom runner
102
98
  ```
103
99
 
104
- ## Business behavior lives in the DSL
105
-
106
- Prompts and SDK calls are execution details.
107
-
108
- The reusable behavior of an agent team belongs in the DSL:
109
-
110
- - agent roles and responsibilities
111
- - task boundaries
112
- - delegation rules
113
- - workflow steps
114
- - handoff schemas
115
- - validations
116
- - guardrails
117
-
118
- `agent-contracts-runtime` executes those generated contracts instead of duplicating the workflow logic in application code.
100
+ Agent SDKs execute LLM agents. `agent-contracts-runtime` lets application code invoke reusable, DSL-defined agent workflows without hand-writing SDK-specific orchestration for each workflow.
119
101
 
120
102
  ## Install
121
103
 
@@ -127,20 +109,17 @@ npm install -D agent-contracts
127
109
  ## Quick start
128
110
 
129
111
  ```bash
130
- # 1. Initialize project scaffolding
131
- agent-runtime init
112
+ # 1. Add LLM commands to your CLI tool (the agent does the work)
113
+ agent-runtime implement --adapter claude --project-dir ./my-tool \
114
+ "Add an audit command for code quality"
132
115
 
133
- # 2. Validate and lint your DSL
134
- agent-contracts validate
135
- agent-contracts lint --strict
116
+ # 2. Audit the generated integration
117
+ agent-runtime audit-implementation --adapter claude ./my-tool
136
118
 
137
- # 3. Generate contracts and hooks
119
+ # 3. Or set up manually: initialize, generate, run
120
+ agent-runtime init
138
121
  agent-runtime generate
139
-
140
- # 4. Run a workflow
141
122
  agent-runtime run feature-implement "Add login endpoint with JWT"
142
-
143
- # 5. Verify project setup
144
123
  agent-runtime doctor
145
124
  ```
146
125
 
@@ -478,6 +457,8 @@ Each step result includes task ID, outcome status, validation errors, follow-up
478
457
 
479
458
  | Command | Description |
480
459
  |---------|-------------|
460
+ | `agent-runtime implement <description>` | Add LLM-powered commands to a CLI tool (agentic) |
461
+ | `agent-runtime audit-implementation [dir]` | Audit an LLM integration for pattern conformance (agentic) |
481
462
  | `agent-runtime init` | Initialize runtime scaffolding |
482
463
  | `agent-runtime generate` | Generate contracts and hooks from DSL |
483
464
  | `agent-runtime run <workflow> <request>` | Execute a workflow |