agent-contracts-runtime 0.0.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/LICENSE +21 -0
- package/README.md +266 -0
- package/cli-contract.yaml +532 -0
- package/dist/adapters/claude-agent-sdk.d.ts +20 -0
- package/dist/adapters/claude-agent-sdk.js +31 -0
- package/dist/adapters/claude-agent-sdk.js.map +1 -0
- package/dist/adapters/cursor-sdk.d.ts +21 -0
- package/dist/adapters/cursor-sdk.js +35 -0
- package/dist/adapters/cursor-sdk.js.map +1 -0
- package/dist/adapters/mock.d.ts +20 -0
- package/dist/adapters/mock.js +27 -0
- package/dist/adapters/mock.js.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +32 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.js +378 -0
- package/dist/index.js.map +1 -0
- package/dist/task-runner-B5SV4eCS.d.ts +66 -0
- package/package.json +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 foo-ogawa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# agent-contracts-runtime
|
|
2
|
+
|
|
3
|
+
Runtime bridge for executing [`agent-contracts`](https://github.com/foo-ogawa/agent-contracts) workflows on Agent SDKs.
|
|
4
|
+
|
|
5
|
+
`agent-contracts` defines your multi-agent system as contracts.
|
|
6
|
+
`agent-contracts-runtime` turns those contracts into an executable SDK runtime.
|
|
7
|
+
|
|
8
|
+
It generates typed contracts, handoff validators, and guardrail hooks from your DSL, then runs workflows through pluggable SDK adapters such as Cursor, Claude, or OpenAI Agents SDK.
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
- **Generate** typed TypeScript contracts, Zod handoff schemas, and guardrail hooks from `agent-contracts.yaml`
|
|
13
|
+
- **Run** multi-step agent workflows with mechanical orchestration (retry, gate, escalation)
|
|
14
|
+
- **Validate** every LLM output against handoff schemas before proceeding to the next step
|
|
15
|
+
- **Enforce** guardrails (command, file path, file content) before SDK execution
|
|
16
|
+
- **Extend** with project-specific plugins (lifecycle hooks, prompt enhancement, custom guardrails)
|
|
17
|
+
- **Adapt** to any SDK through a pluggable adapter interface
|
|
18
|
+
|
|
19
|
+
## Architecture
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
agent-contracts.yaml (SSoT)
|
|
23
|
+
│
|
|
24
|
+
▼
|
|
25
|
+
agent-runtime generate
|
|
26
|
+
│
|
|
27
|
+
├── agent/generated/contracts/ (agents, tasks, workflows, handoffs)
|
|
28
|
+
├── agent/generated/hooks/ (guardrails, SDK hook adapters)
|
|
29
|
+
└── agent/generated/manifest.ts (DSL hash, generation metadata)
|
|
30
|
+
|
|
31
|
+
agent/src/ (user plugins, project guardrails)
|
|
32
|
+
│
|
|
33
|
+
▼
|
|
34
|
+
agent-runtime run <workflow> <request>
|
|
35
|
+
│
|
|
36
|
+
├── Plugin: beforeWorkflow
|
|
37
|
+
├── For each step:
|
|
38
|
+
│ ├── Plugin: beforeTask / promptEnhancer
|
|
39
|
+
│ ├── SDK Adapter: send prompt to LLM
|
|
40
|
+
│ ├── Extract structured result (YAML/JSON)
|
|
41
|
+
│ ├── Validate against Zod handoff schema
|
|
42
|
+
│ ├── Plugin: afterTask
|
|
43
|
+
│ └── Retry on validation failure
|
|
44
|
+
└── Plugin: afterWorkflow
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Layer separation
|
|
48
|
+
|
|
49
|
+
| Layer | Path | Owner | Description |
|
|
50
|
+
|-------|------|-------|-------------|
|
|
51
|
+
| **Generated** | `agent/generated/` | Auto-generated | DSL-derived contracts and hooks. Never edit manually. |
|
|
52
|
+
| **User code** | `agent/src/` | You | Plugins, project guardrails, interceptors. |
|
|
53
|
+
| **Runtime** | `node_modules/agent-contracts-runtime/` | npm package | Workflow runner, task runner, SDK adapters. |
|
|
54
|
+
|
|
55
|
+
## Install
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install -D agent-contracts agent-contracts-runtime
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick start
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# 1. Initialize project scaffolding
|
|
65
|
+
agent-runtime init
|
|
66
|
+
|
|
67
|
+
# 2. Validate and lint your DSL
|
|
68
|
+
agent-contracts validate
|
|
69
|
+
agent-contracts lint --strict
|
|
70
|
+
|
|
71
|
+
# 3. Generate contracts and hooks
|
|
72
|
+
agent-runtime generate
|
|
73
|
+
|
|
74
|
+
# 4. Run a workflow
|
|
75
|
+
agent-runtime run feature-implement "Add login endpoint with JWT"
|
|
76
|
+
|
|
77
|
+
# 5. Verify project setup
|
|
78
|
+
agent-runtime doctor
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## CLI
|
|
82
|
+
|
|
83
|
+
| Command | Description |
|
|
84
|
+
|---------|-------------|
|
|
85
|
+
| `agent-runtime init` | Initialize runtime scaffolding |
|
|
86
|
+
| `agent-runtime generate` | Generate contracts and hooks from DSL |
|
|
87
|
+
| `agent-runtime run <workflow> <request>` | Execute a workflow |
|
|
88
|
+
| `agent-runtime list <resource>` | List workflows, tasks, or agents |
|
|
89
|
+
| `agent-runtime doctor` | Verify configuration and connectivity |
|
|
90
|
+
| `agent-runtime replay <run-dir>` | Replay a past execution |
|
|
91
|
+
|
|
92
|
+
Key options:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
agent-runtime generate --check # CI: verify generated files are up to date
|
|
96
|
+
agent-runtime generate --clean # Delete and regenerate
|
|
97
|
+
agent-runtime run ... --dry-run # Simulate without calling SDK
|
|
98
|
+
agent-runtime run ... --adapter mock # Use mock adapter for testing
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
For full CLI reference with exit codes and output schemas, see [docs/cli-reference.md](docs/cli-reference.md).
|
|
102
|
+
|
|
103
|
+
The CLI specification is managed contract-first via [`cli-contracts`](https://www.npmjs.com/package/cli-contracts) in [`cli-contract.yaml`](cli-contract.yaml).
|
|
104
|
+
|
|
105
|
+
## Programmatic API
|
|
106
|
+
|
|
107
|
+
### Run a workflow
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { runWorkflow } from "agent-contracts-runtime";
|
|
111
|
+
import { CursorSdkAdapter } from "agent-contracts-runtime/adapters/cursor-sdk";
|
|
112
|
+
|
|
113
|
+
const adapter = await CursorSdkAdapter.create({
|
|
114
|
+
apiKey: process.env.CURSOR_API_KEY!,
|
|
115
|
+
model: "composer-2",
|
|
116
|
+
cwd: process.cwd(),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result = await runWorkflow(adapter, "feature-implement", {
|
|
120
|
+
user_request: "Add login endpoint with JWT",
|
|
121
|
+
|
|
122
|
+
onStepComplete: (event) => {
|
|
123
|
+
console.log(`Step ${event.step_index + 1}: ${event.task_id} -> ${event.outcome_status}`);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
onGate: async (gateKind, description) => {
|
|
127
|
+
return true; // approve
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
console.log(`${result.workflow_id}: ${result.status} (${result.total_elapsed_ms}ms)`);
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Run a single task
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
import { runTask } from "agent-contracts-runtime";
|
|
138
|
+
|
|
139
|
+
const outcome = await runTask(adapter, "run-tests", {
|
|
140
|
+
user_request: "Run all tests and report results",
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
if (outcome.status === "success") {
|
|
144
|
+
console.log("Completed:", outcome.data);
|
|
145
|
+
} else if (outcome.status === "validation_error") {
|
|
146
|
+
console.error("Schema mismatch:", outcome.errors.message);
|
|
147
|
+
} else if (outcome.status === "escalation") {
|
|
148
|
+
console.warn("Escalation:", outcome.reason);
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Register a plugin
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
import { pluginRegistry, type AgentPlugin } from "agent-contracts-runtime";
|
|
156
|
+
|
|
157
|
+
const myPlugin: AgentPlugin = {
|
|
158
|
+
id: "my-plugin",
|
|
159
|
+
async beforeTask(taskId, context) {
|
|
160
|
+
return context; // return null to skip
|
|
161
|
+
},
|
|
162
|
+
async afterTask(taskId, outcome) {
|
|
163
|
+
return outcome;
|
|
164
|
+
},
|
|
165
|
+
promptEnhancer(taskId, prompt) {
|
|
166
|
+
return prompt + "\n\nAlways write tests first.";
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
pluginRegistry.register(myPlugin);
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Plugin system
|
|
174
|
+
|
|
175
|
+
Plugins inject mechanical logic into DSL-defined workflows without modifying the DSL or the runtime engine.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
interface AgentPlugin {
|
|
179
|
+
readonly id: string;
|
|
180
|
+
beforeTask?(taskId: string, context: TaskContext): Promise<TaskContext | null>;
|
|
181
|
+
afterTask?(taskId: string, outcome: TaskOutcome): Promise<TaskOutcome>;
|
|
182
|
+
promptEnhancer?(taskId: string, prompt: string, context: TaskContext): string;
|
|
183
|
+
customGuardrails?: { /* evaluateCommand, evaluateFilePath, evaluateFileContent */ };
|
|
184
|
+
beforeWorkflow?(workflowId: string, userRequest: string): Promise<void>;
|
|
185
|
+
afterWorkflow?(workflowId: string, result: WorkflowResult): Promise<void>;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Built-in sample plugins:
|
|
190
|
+
|
|
191
|
+
| Plugin | Purpose |
|
|
192
|
+
|--------|---------|
|
|
193
|
+
| `observability` | Emit structured events for workflow/task lifecycle |
|
|
194
|
+
| `project-guardrails` | Block dangerous packages, protect migration files |
|
|
195
|
+
| `test-enforcer` | Require test files in implementation task results |
|
|
196
|
+
|
|
197
|
+
## SDK adapters
|
|
198
|
+
|
|
199
|
+
| Adapter | SDK | Status |
|
|
200
|
+
|---------|-----|--------|
|
|
201
|
+
| `cursor` | Cursor Cloud Agents (`@cursor/sdk`) | Implemented |
|
|
202
|
+
| `claude` | Claude Agent SDK (`@anthropic-ai/claude-agent-sdk`) | Stub |
|
|
203
|
+
| `openai` | OpenAI Agents SDK | Planned |
|
|
204
|
+
| `mock` | Simulated responses for testing/demo | Implemented |
|
|
205
|
+
|
|
206
|
+
The adapter interface is minimal:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
interface SdkAdapter {
|
|
210
|
+
send(prompt: string, options: { readonly: boolean }): Promise<string>;
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Guardrails
|
|
215
|
+
|
|
216
|
+
Guardrails evaluate commands, file paths, and file content before execution.
|
|
217
|
+
|
|
218
|
+
DSL-generated guardrails and plugin custom guardrails are merged and evaluated together, producing one of four actions:
|
|
219
|
+
|
|
220
|
+
| Action | Effect |
|
|
221
|
+
|--------|--------|
|
|
222
|
+
| `block` | Deny the operation |
|
|
223
|
+
| `warn` | Allow with warning (can fail with `fail_on_guardrail_warning`) |
|
|
224
|
+
| `info` | Allow with informational context |
|
|
225
|
+
| `shadow` | Log only, no effect on execution |
|
|
226
|
+
|
|
227
|
+
## Configuration
|
|
228
|
+
|
|
229
|
+
`agent-runtime.config.yaml`:
|
|
230
|
+
|
|
231
|
+
```yaml
|
|
232
|
+
contracts:
|
|
233
|
+
dsl: ./agent-contracts.yaml
|
|
234
|
+
generated_dir: ./agent/generated
|
|
235
|
+
|
|
236
|
+
runtime:
|
|
237
|
+
adapter: cursor
|
|
238
|
+
plugins: ./agent/src/plugins/index.ts
|
|
239
|
+
|
|
240
|
+
execution:
|
|
241
|
+
default_max_retries: 2
|
|
242
|
+
require_structured_output: true
|
|
243
|
+
|
|
244
|
+
observability:
|
|
245
|
+
provider: local
|
|
246
|
+
output_dir: ./.agent-runs
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## CI integration
|
|
250
|
+
|
|
251
|
+
```yaml
|
|
252
|
+
- run: agent-contracts validate
|
|
253
|
+
- run: agent-contracts lint --strict
|
|
254
|
+
- run: agent-runtime generate --check
|
|
255
|
+
- run: agent-runtime doctor
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Requirements
|
|
259
|
+
|
|
260
|
+
- Node.js 20+
|
|
261
|
+
- TypeScript 5.x (ESM, strict mode)
|
|
262
|
+
- `agent-contracts` (peer dependency)
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
MIT
|