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/cli-contract.yaml CHANGED
@@ -86,12 +86,12 @@ command_sets:
86
86
  format: text
87
87
 
88
88
  x-agent:
89
- risk_level: low
90
- requires_confirmation: false
89
+ riskLevel: low
90
+ requiresConfirmation: false
91
91
  idempotent: false
92
- side_effects:
92
+ sideEffects:
93
93
  - filesystem_write
94
- safe_dry_run_option: ""
94
+ safeDryRunOption: ""
95
95
 
96
96
  # -----------------------------------------------------------------------
97
97
  # generate
@@ -151,12 +151,12 @@ command_sets:
151
151
  $ref: "#/components/schemas/ValidationError"
152
152
 
153
153
  x-agent:
154
- risk_level: low
155
- requires_confirmation: false
154
+ riskLevel: low
155
+ requiresConfirmation: false
156
156
  idempotent: true
157
- side_effects:
157
+ sideEffects:
158
158
  - filesystem_write
159
- safe_dry_run_option: check
159
+ safeDryRunOption: check
160
160
 
161
161
  # -----------------------------------------------------------------------
162
162
  # run
@@ -247,25 +247,28 @@ command_sets:
247
247
  stderr:
248
248
  format: text
249
249
 
250
- "2":
251
- description: Invalid arguments or unknown workflow/adapter.
250
+ "3":
251
+ description: >-
252
+ Input validation failed (invalid arguments, unknown workflow/adapter,
253
+ or generated files outdated).
252
254
  stderr:
253
255
  format: text
254
256
 
255
- "3":
256
- description: Generated files outdated. Run `agent-runtime generate` first.
257
+ "12":
258
+ description: Adapter initialization error (missing API key, etc.).
257
259
  stderr:
258
260
  format: text
259
261
 
260
262
  x-agent:
261
- risk_level: high
262
- requires_confirmation: true
263
+ riskLevel: high
264
+ requiresConfirmation: true
263
265
  idempotent: false
264
- side_effects:
266
+ sideEffects:
265
267
  - sdk_call
266
268
  - filesystem_write
267
- safe_dry_run_option: dry-run
268
- recommended_before_use:
269
+ safeDryRunOption: dry-run
270
+ expectedDurationMs: 300000
271
+ recommendedBeforeUse:
269
272
  - Run `agent-runtime generate --check` to ensure contracts are up to date.
270
273
  - Run `agent-runtime doctor` to verify SDK configuration.
271
274
 
@@ -308,10 +311,10 @@ command_sets:
308
311
  format: text
309
312
 
310
313
  x-agent:
311
- risk_level: low
312
- requires_confirmation: false
314
+ riskLevel: low
315
+ requiresConfirmation: false
313
316
  idempotent: true
314
- side_effects: []
317
+ sideEffects: []
315
318
 
316
319
  # -----------------------------------------------------------------------
317
320
  # show-prompt
@@ -367,10 +370,235 @@ command_sets:
367
370
  format: text
368
371
 
369
372
  x-agent:
370
- risk_level: low
371
- requires_confirmation: false
373
+ riskLevel: low
374
+ requiresConfirmation: false
372
375
  idempotent: true
373
- side_effects: []
376
+ sideEffects: []
377
+
378
+ # -----------------------------------------------------------------------
379
+ # implement
380
+ # -----------------------------------------------------------------------
381
+ implement:
382
+ summary: Implement LLM-powered commands in a CLI tool.
383
+ description: |
384
+ Uses an agentic LLM adapter (Claude, Cursor, etc.) to analyze the
385
+ target project and implement LLM-powered commands following the
386
+ agent-contracts + agent-contracts-runtime + cli-contracts stack.
387
+
388
+ The agent reads the project structure, cli-contract.yaml, and existing
389
+ code, then generates DSL definitions, TypeScript modules (orchestrator,
390
+ context-builder, formatter), CLI command handlers, and updates the
391
+ CLI contract with x-agent metadata.
392
+
393
+ Requires an agentic adapter that supports tool use (file read/write).
394
+ arguments:
395
+ - name: description
396
+ required: true
397
+ description: >-
398
+ Natural language description of the LLM feature(s) to implement.
399
+ Examples: "Add an audit command for migration safety",
400
+ "Add propose and explain commands for SQL optimization".
401
+ schema:
402
+ type: string
403
+
404
+ options:
405
+ - name: adapter
406
+ aliases: [a]
407
+ description: SDK adapter to use. Must be an agentic adapter (claude, cursor).
408
+ schema:
409
+ type: string
410
+ enum: [claude, cursor, mock]
411
+ default: claude
412
+
413
+ - name: project-dir
414
+ aliases: [p]
415
+ description: Path to the target project directory.
416
+ schema:
417
+ type: string
418
+ default: "."
419
+
420
+ - name: dry-run
421
+ aliases: [n]
422
+ description: Output the prompt context without calling the LLM.
423
+ schema:
424
+ type: boolean
425
+ default: false
426
+
427
+ - name: model
428
+ description: Model name override for the selected adapter.
429
+ schema:
430
+ type: string
431
+
432
+ - name: output
433
+ aliases: [o]
434
+ description: Write the result to a file instead of stdout.
435
+ schema:
436
+ type: string
437
+ file:
438
+ mode: write
439
+
440
+ - name: report-format
441
+ description: Output format for the result.
442
+ schema:
443
+ type: string
444
+ enum: [json, text, yaml]
445
+ default: text
446
+
447
+ exits:
448
+ "0":
449
+ description: Implementation completed successfully.
450
+ stdout:
451
+ format: json
452
+ schema:
453
+ $ref: "#/components/schemas/ImplementResult"
454
+
455
+ "1":
456
+ description: Implementation failed.
457
+ stderr:
458
+ format: text
459
+
460
+ "3":
461
+ description: Input validation failed (e.g. project directory not found).
462
+ stderr:
463
+ format: text
464
+
465
+ "12":
466
+ description: Adapter initialization error.
467
+ stderr:
468
+ format: text
469
+
470
+ x-agent:
471
+ riskLevel: high
472
+ requiresConfirmation: true
473
+ idempotent: false
474
+ sideEffects:
475
+ - sdk_call
476
+ - filesystem_write
477
+ safeDryRunOption: dry-run
478
+ expectedDurationMs: 300000
479
+ retryableExitCodes: [1, 12]
480
+ recommendedBeforeUse:
481
+ - Ensure the target project has a cli-contract.yaml or plan to create one.
482
+ - Run in a clean git working tree so changes can be reviewed.
483
+
484
+ # -----------------------------------------------------------------------
485
+ # audit-implementation
486
+ # -----------------------------------------------------------------------
487
+ audit-implementation:
488
+ summary: Audit an LLM command integration for pattern conformance.
489
+ description: |
490
+ Analyzes a target project's LLM command integration to verify it
491
+ correctly follows the agent-contracts + agent-contracts-runtime +
492
+ cli-contracts stack conventions.
493
+
494
+ Checks all three layers:
495
+ 1. DSL definitions (agents, tasks, workflows, handoff schemas)
496
+ 2. Runtime integration (adapter usage, runTask/runWorkflow, registries)
497
+ 3. CLI contract (standard options, x-agent metadata, exit codes)
498
+
499
+ Produces structured findings with severity, category, and
500
+ concrete remediation steps. Read-only — does not modify files.
501
+ arguments:
502
+ - name: project-dir
503
+ required: false
504
+ description: >-
505
+ Path to the project directory to audit. Defaults to current directory.
506
+ schema:
507
+ type: string
508
+
509
+ options:
510
+ - name: adapter
511
+ aliases: [a]
512
+ description: SDK adapter to use for the audit agent.
513
+ schema:
514
+ type: string
515
+ enum: [claude, cursor, mock]
516
+ default: claude
517
+
518
+ - name: focus
519
+ description: >-
520
+ Limit audit to a specific layer. Defaults to all layers.
521
+ schema:
522
+ type: string
523
+ enum: [all, dsl, runtime, cli-contract, architecture]
524
+ default: all
525
+
526
+ - name: dry-run
527
+ aliases: [n]
528
+ description: Output the prompt context without calling the LLM.
529
+ schema:
530
+ type: boolean
531
+ default: false
532
+
533
+ - name: fail-on
534
+ description: Minimum finding severity that causes a non-zero exit.
535
+ schema:
536
+ type: string
537
+ enum: [warning, error, critical]
538
+ default: error
539
+
540
+ - name: model
541
+ description: Model name override for the selected adapter.
542
+ schema:
543
+ type: string
544
+
545
+ - name: output
546
+ aliases: [o]
547
+ description: Write the result to a file instead of stdout.
548
+ schema:
549
+ type: string
550
+ file:
551
+ mode: write
552
+
553
+ - name: report-format
554
+ description: Output format for the audit report.
555
+ schema:
556
+ type: string
557
+ enum: [json, text, yaml]
558
+ default: text
559
+
560
+ exits:
561
+ "0":
562
+ description: Audit completed with no findings above threshold.
563
+ stdout:
564
+ format: json
565
+ schema:
566
+ $ref: "#/components/schemas/AuditImplementationResult"
567
+
568
+ "1":
569
+ description: Audit failed (agent error, unexpected failure).
570
+ stderr:
571
+ format: text
572
+
573
+ "3":
574
+ description: Input validation failed (e.g. project directory not found).
575
+ stderr:
576
+ format: text
577
+
578
+ "10":
579
+ description: Audit completed with findings above --fail-on threshold.
580
+ stdout:
581
+ format: json
582
+ schema:
583
+ $ref: "#/components/schemas/AuditImplementationResult"
584
+
585
+ "12":
586
+ description: Adapter initialization error.
587
+ stderr:
588
+ format: text
589
+
590
+ x-agent:
591
+ riskLevel: low
592
+ requiresConfirmation: false
593
+ idempotent: true
594
+ sideEffects:
595
+ - network
596
+ sideEffectNote: >-
597
+ Network calls to LLM provider when adapter is not mock.
598
+ Filesystem write only when --output is specified.
599
+ safeDryRunOption: dry-run
600
+ expectedDurationMs: 180000
601
+ retryableExitCodes: [1, 12]
374
602
 
375
603
  # -----------------------------------------------------------------------
376
604
  # doctor
@@ -399,10 +627,10 @@ command_sets:
399
627
  $ref: "#/components/schemas/DoctorResult"
400
628
 
401
629
  x-agent:
402
- risk_level: low
403
- requires_confirmation: false
630
+ riskLevel: low
631
+ requiresConfirmation: false
404
632
  idempotent: true
405
- side_effects: []
633
+ sideEffects: []
406
634
 
407
635
 
408
636
  # =============================================================================
@@ -577,6 +805,83 @@ components:
577
805
  all_passed:
578
806
  type: boolean
579
807
 
808
+ # -------------------------------------------------------------------------
809
+ # implement
810
+ # -------------------------------------------------------------------------
811
+ ImplementResult:
812
+ type: object
813
+ required: [files_created, files_modified, summary]
814
+ properties:
815
+ files_created:
816
+ type: array
817
+ items:
818
+ type: string
819
+ description: List of new files created.
820
+ files_modified:
821
+ type: array
822
+ items:
823
+ type: string
824
+ description: List of existing files modified.
825
+ summary:
826
+ type: string
827
+ description: Human-readable summary of what was implemented.
828
+ commands_added:
829
+ type: array
830
+ items:
831
+ type: object
832
+ required: [name, type]
833
+ properties:
834
+ name:
835
+ type: string
836
+ type:
837
+ type: string
838
+ enum: [audit, propose, explain]
839
+ description:
840
+ type: string
841
+ next_steps:
842
+ type: array
843
+ items:
844
+ type: string
845
+ description: Recommended next steps for the developer.
846
+
847
+ # -------------------------------------------------------------------------
848
+ # audit-implementation
849
+ # -------------------------------------------------------------------------
850
+ AuditImplementationResult:
851
+ type: object
852
+ required: [summary, riskLevel, findings]
853
+ properties:
854
+ summary:
855
+ type: string
856
+ description: One-paragraph overall assessment.
857
+ riskLevel:
858
+ type: string
859
+ enum: [low, medium, high, critical]
860
+ description: Derived from worst finding severity.
861
+ findings:
862
+ type: array
863
+ items:
864
+ $ref: "#/components/schemas/AgentFinding"
865
+ recommendedActions:
866
+ type: array
867
+ items:
868
+ $ref: "#/components/schemas/AgentRecommendedAction"
869
+ metadata:
870
+ type: object
871
+ properties:
872
+ tool:
873
+ type: string
874
+ command:
875
+ type: string
876
+ version:
877
+ type: string
878
+ generatedAt:
879
+ type: string
880
+ adapter:
881
+ type: string
882
+ model:
883
+ type: string
884
+
580
885
  DoctorCheck:
581
886
  type: object
582
887
  required: [name, status]
@@ -590,3 +895,78 @@ components:
590
895
  message:
591
896
  type: string
592
897
  description: Human-readable detail.
898
+
899
+ # -------------------------------------------------------------------------
900
+ # Canonical agent result schemas (AgentAuditResult sub-types)
901
+ # -------------------------------------------------------------------------
902
+ AgentFinding:
903
+ type: object
904
+ required: [severity, category, message]
905
+ properties:
906
+ id:
907
+ type: string
908
+ description: Unique finding identifier (e.g. F-001).
909
+ severity:
910
+ type: string
911
+ enum: [info, warning, error, critical]
912
+ category:
913
+ type: string
914
+ description: Domain vocabulary category (e.g. cli-contract-options, runtime-adapter).
915
+ target:
916
+ type: string
917
+ description: File path or resource the finding applies to.
918
+ location:
919
+ type: string
920
+ description: Line range or specific location within the target.
921
+ message:
922
+ type: string
923
+ description: Human-readable description of the finding.
924
+ recommendation:
925
+ type: string
926
+ description: Concrete remediation step.
927
+ confidence:
928
+ type: number
929
+ minimum: 0
930
+ maximum: 1
931
+ description: Confidence score (0–1) for the finding.
932
+ evidence:
933
+ type: array
934
+ items:
935
+ $ref: "#/components/schemas/AgentEvidence"
936
+ details:
937
+ type: object
938
+ description: Additional structured details specific to the finding category.
939
+
940
+ AgentRecommendedAction:
941
+ type: object
942
+ required: [kind, title]
943
+ properties:
944
+ kind:
945
+ type: string
946
+ enum: [run_command, edit_file, review, confirm, block, ignore]
947
+ title:
948
+ type: string
949
+ description: Short human-readable title for the action.
950
+ command:
951
+ type: string
952
+ description: Shell command to run (when kind is run_command).
953
+ target:
954
+ type: string
955
+ description: File path to edit (when kind is edit_file).
956
+ rationale:
957
+ type: string
958
+ description: Explanation of why this action is recommended.
959
+
960
+ AgentEvidence:
961
+ type: object
962
+ required: [type, content]
963
+ properties:
964
+ type:
965
+ type: string
966
+ description: Evidence type (e.g. code_snippet, file_excerpt, lint_output).
967
+ content:
968
+ type: string
969
+ description: The evidence content.
970
+ source:
971
+ type: string
972
+ description: Source file path or URL for the evidence.
@@ -561,12 +561,18 @@ function resolveInvocation(invocation) {
561
561
  } else {
562
562
  userRequest = invocation.user_request ?? "";
563
563
  }
564
+ const ctx = invocation.context;
565
+ const variables = { ...ctx?.variables };
566
+ if (ctx?.cwd) variables.cwd = ctx.cwd;
567
+ if (ctx?.environment) variables.environment = ctx.environment;
568
+ if (ctx?.artifacts) variables.artifacts = ctx.artifacts;
564
569
  return {
565
570
  workflowId: invocation.workflow,
566
571
  options: {
567
572
  user_request: userRequest,
568
573
  maxFollowUps: invocation.runtime?.maxFollowUps,
569
574
  maxRetries: invocation.runtime?.maxRetries,
575
+ variables: Object.keys(variables).length > 0 ? variables : void 0,
570
576
  onGate: invocation.hooks?.onGate,
571
577
  onStepComplete: invocation.hooks?.onStepComplete,
572
578
  onOptionalStep: invocation.hooks?.onOptionalStep
@@ -649,7 +655,7 @@ async function runWorkflow(adapter, workflowIdOrInvocation, optionsOrRegistries,
649
655
  return handleGateStep(step, Object.values(stepResults).filter(Boolean), options, i, adapter);
650
656
  }
651
657
  if (step.optional) {
652
- const ctx = { user_request: options.user_request, prior_context: contextFor(i) };
658
+ const ctx = { user_request: options.user_request, prior_context: contextFor(i), variables: options.variables };
653
659
  const shouldRun = options.onOptionalStep ? await options.onOptionalStep(step, ctx) : false;
654
660
  if (!shouldRun) {
655
661
  return {
@@ -665,6 +671,7 @@ async function runWorkflow(adapter, workflowIdOrInvocation, optionsOrRegistries,
665
671
  const context = {
666
672
  user_request: options.user_request,
667
673
  prior_context: contextFor(i),
674
+ variables: options.variables,
668
675
  ...invocationHandoff ? { handoff_input: invocationHandoff } : {}
669
676
  };
670
677
  const taskResult = await runTask(adapter, step.task, context, {
@@ -1101,4 +1108,4 @@ export {
1101
1108
  loadPluginsFromDirectory,
1102
1109
  loadPlugins
1103
1110
  };
1104
- //# sourceMappingURL=chunk-NLVQ3OOT.js.map
1111
+ //# sourceMappingURL=chunk-MINIXDVQ.js.map