agent-contracts-runtime 0.2.0 → 0.3.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 +42 -2
- package/cli-contract.yaml +82 -0
- package/dist/adapters/claude-agent-sdk.d.ts +1 -1
- package/dist/adapters/cursor-sdk.d.ts +1 -1
- package/dist/adapters/mock.d.ts +1 -1
- package/dist/chunk-24SRKCWQ.js +595 -0
- package/dist/chunk-24SRKCWQ.js.map +1 -0
- package/dist/cli/index.js +82 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +14 -451
- package/dist/index.js.map +1 -1
- package/dist/{task-runner-CuYWldNc.d.ts → task-runner-MQO5VR1Y.d.ts} +14 -3
- package/package.json +1 -1
- package/templates/contracts-index.ts.hbs +7 -4
- package/templates/hooks-index.ts.hbs +2 -2
- package/templates/tasks.ts.hbs +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,9 @@ agent-contracts.yaml (DSL) bindings/runtime.yaml (guardrail impl)
|
|
|
40
40
|
│
|
|
41
41
|
├── Plugin: beforeWorkflow
|
|
42
42
|
├── For each step:
|
|
43
|
-
│ ├── Plugin: beforeTask
|
|
43
|
+
│ ├── Plugin: beforeTask
|
|
44
|
+
│ ├── Plugin: promptBuilder (full override) or default buildTaskPrompt
|
|
45
|
+
│ ├── Plugin: promptEnhancer (post-process)
|
|
44
46
|
│ ├── SDK Adapter: send prompt to LLM
|
|
45
47
|
│ ├── Extract structured result (YAML/JSON)
|
|
46
48
|
│ ├── Validate against Zod handoff schema
|
|
@@ -94,6 +96,7 @@ agent-runtime doctor
|
|
|
94
96
|
| `agent-runtime generate` | Generate contracts and hooks from DSL |
|
|
95
97
|
| `agent-runtime run <workflow> <request>` | Execute a workflow |
|
|
96
98
|
| `agent-runtime list <resource>` | List workflows, tasks, or agents |
|
|
99
|
+
| `agent-runtime show-prompt <task>` | Display the generated prompt for a task |
|
|
97
100
|
| `agent-runtime doctor` | Verify configuration and connectivity |
|
|
98
101
|
| `agent-runtime replay <run-dir>` | Replay a past execution |
|
|
99
102
|
|
|
@@ -105,6 +108,10 @@ agent-runtime generate --clean # Delete and regenerate
|
|
|
105
108
|
agent-runtime generate -t ./my-tpl # Use custom Handlebars templates
|
|
106
109
|
agent-runtime run ... --dry-run # Simulate without calling SDK
|
|
107
110
|
agent-runtime run ... --adapter mock # Use mock adapter for testing
|
|
111
|
+
agent-runtime show-prompt plan-and-implement # Preview prompt
|
|
112
|
+
agent-runtime show-prompt audit-tests -u "Check test quality" # With custom request
|
|
113
|
+
agent-runtime show-prompt plan-and-implement --format json # JSON output
|
|
114
|
+
agent-runtime show-prompt plan-and-implement --with-plugins # Apply plugin enhancers
|
|
108
115
|
```
|
|
109
116
|
|
|
110
117
|
For full CLI reference with exit codes and output schemas, see [docs/cli-reference.md](docs/cli-reference.md).
|
|
@@ -188,6 +195,8 @@ const adapter = await CursorSdkAdapter.create({
|
|
|
188
195
|
|
|
189
196
|
const result = await runWorkflow(adapter, "feature-implement", {
|
|
190
197
|
user_request: "Add login endpoint with JWT",
|
|
198
|
+
maxFollowUps: 3, // override lightweight recovery attempts (default: 2)
|
|
199
|
+
maxRetries: 1, // override heavyweight retry attempts (default: from DSL step.max_retries)
|
|
191
200
|
|
|
192
201
|
onStepComplete: (event) => {
|
|
193
202
|
console.log(`Step ${event.step_index + 1}: ${event.task_id} -> ${event.outcome_status}`);
|
|
@@ -227,8 +236,12 @@ if (result.outcome.status === "success") {
|
|
|
227
236
|
| **Cost** | Lightweight | Heavy |
|
|
228
237
|
| **Use case** | Output format correction | Full task re-execution |
|
|
229
238
|
| **Default limit** | `maxFollowUps: 2` | `maxRetries: 0` (opt-in) |
|
|
239
|
+
| **DSL mapping** | Independent (always available) | `step.max_retries` in workflow DSL |
|
|
230
240
|
| **Trigger** | Zod schema validation error | Empty output, or `decideRetryStrategy` |
|
|
231
241
|
| **Session** | Same session continues | New session |
|
|
242
|
+
| **Override** | `WorkflowRunOptions.maxFollowUps` | `WorkflowRunOptions.maxRetries` |
|
|
243
|
+
|
|
244
|
+
The prompt includes the full handoff schema field table and a YAML example, so the agent can produce valid output on the first attempt without guessing the format.
|
|
232
245
|
|
|
233
246
|
Inject custom recovery logic via `decideRetryStrategy`:
|
|
234
247
|
|
|
@@ -274,12 +287,39 @@ interface AgentPlugin {
|
|
|
274
287
|
beforeTask?(taskId: string, context: TaskContext): Promise<TaskContext | null>;
|
|
275
288
|
afterTask?(taskId: string, outcome: TaskOutcome): Promise<TaskOutcome>;
|
|
276
289
|
promptEnhancer?(taskId: string, prompt: string, context: TaskContext): string;
|
|
290
|
+
promptBuilder?(args: PromptBuilderArgs): string | null;
|
|
277
291
|
customGuardrails?: { /* evaluateCommand, evaluateFilePath, evaluateFileContent */ };
|
|
278
292
|
beforeWorkflow?(workflowId: string, userRequest: string): Promise<void>;
|
|
279
293
|
afterWorkflow?(workflowId: string, result: WorkflowResult): Promise<void>;
|
|
280
294
|
}
|
|
281
295
|
```
|
|
282
296
|
|
|
297
|
+
### Prompt customization hooks
|
|
298
|
+
|
|
299
|
+
Two hooks control what prompt is sent to the SDK agent:
|
|
300
|
+
|
|
301
|
+
| Hook | Purpose | Execution order |
|
|
302
|
+
|------|---------|-----------------|
|
|
303
|
+
| `promptBuilder` | Full prompt override. Return a string to replace the default prompt, or `null` to use the default. | 1st (before `promptEnhancer`) |
|
|
304
|
+
| `promptEnhancer` | Lightweight post-processor. Receives the built prompt and returns a modified version. | 2nd (after `promptBuilder`) |
|
|
305
|
+
|
|
306
|
+
Example: custom prompt builder that injects project-specific context:
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
const customPromptPlugin: AgentPlugin = {
|
|
310
|
+
id: "custom-prompt",
|
|
311
|
+
promptBuilder({ agent, task, context, options }) {
|
|
312
|
+
if (task.id === "plan-and-implement") {
|
|
313
|
+
return buildTaskPrompt(agent, task, {
|
|
314
|
+
...context,
|
|
315
|
+
prior_context: `${context.prior_context ?? ""}\n\nProject uses NestJS with TypeORM.`,
|
|
316
|
+
}, options);
|
|
317
|
+
}
|
|
318
|
+
return null; // use default for other tasks
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
```
|
|
322
|
+
|
|
283
323
|
## SDK adapters
|
|
284
324
|
|
|
285
325
|
| Adapter | SDK | Status |
|
|
@@ -342,7 +382,7 @@ templates_dir: ./custom-templates # optional, overrides built-in templa
|
|
|
342
382
|
|
|
343
383
|
| Import path | Description |
|
|
344
384
|
|-------------|-------------|
|
|
345
|
-
| `agent-contracts-runtime` | Core runtime API (`runWorkflow`, `runTask`, `pluginRegistry`) |
|
|
385
|
+
| `agent-contracts-runtime` | Core runtime API (`runWorkflow`, `runTask`, `buildTaskPrompt`, `pluginRegistry`, `zodSchemaToPromptDescription`) |
|
|
346
386
|
| `agent-contracts-runtime/generator` | Generator API (`generate`, `checkFreshness`, `buildContractContext`) |
|
|
347
387
|
| `agent-contracts-runtime/adapters/cursor-sdk` | Cursor SDK adapter |
|
|
348
388
|
| `agent-contracts-runtime/adapters/claude-agent-sdk` | Claude Agent SDK adapter |
|
package/cli-contract.yaml
CHANGED
|
@@ -294,6 +294,65 @@ commandSets:
|
|
|
294
294
|
idempotent: true
|
|
295
295
|
sideEffects: []
|
|
296
296
|
|
|
297
|
+
# -----------------------------------------------------------------------
|
|
298
|
+
# show-prompt
|
|
299
|
+
# -----------------------------------------------------------------------
|
|
300
|
+
show-prompt:
|
|
301
|
+
summary: Display the generated prompt for a task.
|
|
302
|
+
description: |
|
|
303
|
+
Builds and displays the full prompt that would be sent to an SDK agent
|
|
304
|
+
for a given task. Useful for inspecting, debugging, and validating
|
|
305
|
+
prompt content before execution.
|
|
306
|
+
|
|
307
|
+
Shows the agent role, responsibilities, constraints, task details,
|
|
308
|
+
completion criteria, handoff schema fields, and output format example.
|
|
309
|
+
arguments:
|
|
310
|
+
- name: task-id
|
|
311
|
+
required: true
|
|
312
|
+
description: ID of the task to show the prompt for (e.g. plan-and-implement, audit-tests).
|
|
313
|
+
schema:
|
|
314
|
+
type: string
|
|
315
|
+
|
|
316
|
+
options:
|
|
317
|
+
- name: user-request
|
|
318
|
+
aliases: [u]
|
|
319
|
+
description: User request text to include in the prompt preview.
|
|
320
|
+
schema:
|
|
321
|
+
type: string
|
|
322
|
+
default: "(preview)"
|
|
323
|
+
|
|
324
|
+
- name: format
|
|
325
|
+
description: Output format.
|
|
326
|
+
schema:
|
|
327
|
+
type: string
|
|
328
|
+
enum: [markdown, raw, json]
|
|
329
|
+
default: markdown
|
|
330
|
+
|
|
331
|
+
- name: with-plugins
|
|
332
|
+
description: Apply registered plugin prompt enhancers to the output.
|
|
333
|
+
schema:
|
|
334
|
+
type: boolean
|
|
335
|
+
default: false
|
|
336
|
+
|
|
337
|
+
exits:
|
|
338
|
+
"0":
|
|
339
|
+
description: Prompt displayed successfully.
|
|
340
|
+
stdout:
|
|
341
|
+
format: json
|
|
342
|
+
schema:
|
|
343
|
+
$ref: "#/components/schemas/ShowPromptResult"
|
|
344
|
+
|
|
345
|
+
"1":
|
|
346
|
+
description: Failed to build prompt (unknown task, missing contracts, etc.).
|
|
347
|
+
stderr:
|
|
348
|
+
format: text
|
|
349
|
+
|
|
350
|
+
x-agent:
|
|
351
|
+
riskLevel: none
|
|
352
|
+
requiresConfirmation: false
|
|
353
|
+
idempotent: true
|
|
354
|
+
sideEffects: []
|
|
355
|
+
|
|
297
356
|
# -----------------------------------------------------------------------
|
|
298
357
|
# doctor
|
|
299
358
|
# -----------------------------------------------------------------------
|
|
@@ -509,6 +568,29 @@ components:
|
|
|
509
568
|
description:
|
|
510
569
|
type: string
|
|
511
570
|
|
|
571
|
+
# -------------------------------------------------------------------------
|
|
572
|
+
# show-prompt
|
|
573
|
+
# -------------------------------------------------------------------------
|
|
574
|
+
ShowPromptResult:
|
|
575
|
+
type: object
|
|
576
|
+
required: [task_id, agent_id, prompt]
|
|
577
|
+
properties:
|
|
578
|
+
task_id:
|
|
579
|
+
type: string
|
|
580
|
+
description: The task ID used to build the prompt.
|
|
581
|
+
agent_id:
|
|
582
|
+
type: string
|
|
583
|
+
description: The target agent ID for this task.
|
|
584
|
+
prompt:
|
|
585
|
+
type: string
|
|
586
|
+
description: The full generated prompt text.
|
|
587
|
+
handoff_schema:
|
|
588
|
+
type: string
|
|
589
|
+
description: The handoff schema ID for the task result.
|
|
590
|
+
plugins_applied:
|
|
591
|
+
type: boolean
|
|
592
|
+
description: Whether plugin prompt enhancers were applied.
|
|
593
|
+
|
|
512
594
|
# -------------------------------------------------------------------------
|
|
513
595
|
# doctor
|
|
514
596
|
# -------------------------------------------------------------------------
|
package/dist/adapters/mock.d.ts
CHANGED