@studio-foundation/engine 0.3.0-beta.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.
Files changed (90) hide show
  1. package/ARCHITECTURE.md +57 -0
  2. package/LICENSE +663 -0
  3. package/README.md +118 -0
  4. package/package.json +47 -0
  5. package/src/__tests__/__fixtures__/script-stage/contracts/book-context.contract.yaml +4 -0
  6. package/src/__tests__/engine.conditions-group.test.ts +244 -0
  7. package/src/__tests__/engine.conditions.test.ts +186 -0
  8. package/src/__tests__/engine.resume.test.ts +108 -0
  9. package/src/__tests__/engine.script-stage.test.ts +125 -0
  10. package/src/db/client.ts +5 -0
  11. package/src/engine.context-event.test.ts +175 -0
  12. package/src/engine.ts +491 -0
  13. package/src/events.ts +167 -0
  14. package/src/index.ts +64 -0
  15. package/src/pipeline/agent-loader.test.ts +151 -0
  16. package/src/pipeline/agent-loader.ts +39 -0
  17. package/src/pipeline/condition-evaluator.test.ts +129 -0
  18. package/src/pipeline/condition-evaluator.ts +121 -0
  19. package/src/pipeline/context-pack-loader.ts +63 -0
  20. package/src/pipeline/context-propagation.test.ts +237 -0
  21. package/src/pipeline/context-propagation.ts +235 -0
  22. package/src/pipeline/contract-loader.ts +41 -0
  23. package/src/pipeline/group-orchestrator.ts +483 -0
  24. package/src/pipeline/hook-executor.test.ts +121 -0
  25. package/src/pipeline/hook-executor.ts +87 -0
  26. package/src/pipeline/invariants-loader.test.ts +51 -0
  27. package/src/pipeline/invariants-loader.ts +14 -0
  28. package/src/pipeline/loader.test.ts +128 -0
  29. package/src/pipeline/loader.ts +149 -0
  30. package/src/pipeline/output-validator.test.ts +100 -0
  31. package/src/pipeline/output-validator.ts +40 -0
  32. package/src/pipeline/post-validator.ts +124 -0
  33. package/src/pipeline/skill-loader.test.ts +44 -0
  34. package/src/pipeline/skill-loader.ts +32 -0
  35. package/src/pipeline/stage-executor.ts +654 -0
  36. package/src/pipeline/stage-resolver.ts +8 -0
  37. package/src/pipeline/startup-executor.test.ts +37 -0
  38. package/src/pipeline/startup-executor.ts +32 -0
  39. package/src/pipeline/types.ts +42 -0
  40. package/src/repo-resolver.ts +61 -0
  41. package/src/spawners/direct-engine-spawner.ts +26 -0
  42. package/src/state/run-store.test.ts +157 -0
  43. package/src/state/run-store.ts +362 -0
  44. package/src/state/state-machine.ts +35 -0
  45. package/src/state/status-derivation.ts +36 -0
  46. package/tests/context-pack-loader.test.ts +113 -0
  47. package/tests/context-propagation.test.ts +267 -0
  48. package/tests/direct-engine-spawner.test.ts +102 -0
  49. package/tests/e2e/feature-v5.test.ts +57 -0
  50. package/tests/events.test.ts +56 -0
  51. package/tests/fixtures/agents/test-agent.agent.yaml +5 -0
  52. package/tests/fixtures/contracts/code-gen.contract.yaml +6 -0
  53. package/tests/fixtures/contracts/qa-gate.contract.yaml +15 -0
  54. package/tests/fixtures/contracts/test-contract.contract.yaml +6 -0
  55. package/tests/fixtures/pipelines/group-test.pipeline.yaml +40 -0
  56. package/tests/fixtures/pipelines/simple.pipeline.yaml +15 -0
  57. package/tests/fixtures/pipelines/two-stage.pipeline.yaml +24 -0
  58. package/tests/fixtures/software/pipelines/feature-builder.pipeline.yaml +75 -0
  59. package/tests/fixtures/test-project/agents/test-agent.agent.yaml +5 -0
  60. package/tests/fixtures/test-project/contracts/basic-result.contract.yaml +6 -0
  61. package/tests/fixtures/test-project/contracts/code-gen.contract.yaml +6 -0
  62. package/tests/fixtures/test-project/contracts/maximum-only.contract.yaml +8 -0
  63. package/tests/fixtures/test-project/contracts/qa-gate.contract.yaml +15 -0
  64. package/tests/fixtures/test-project/contracts/strict-result.contract.yaml +7 -0
  65. package/tests/fixtures/test-project/contracts/test-contract.contract.yaml +6 -0
  66. package/tests/fixtures/test-project/pipelines/group-simple.pipeline.yaml +26 -0
  67. package/tests/fixtures/test-project/pipelines/group-test.pipeline.yaml +40 -0
  68. package/tests/fixtures/test-project/pipelines/hook-output-template.pipeline.yaml +19 -0
  69. package/tests/fixtures/test-project/pipelines/hook-reject-on-failure.pipeline.yaml +19 -0
  70. package/tests/fixtures/test-project/pipelines/maximum-only.pipeline.yaml +15 -0
  71. package/tests/fixtures/test-project/pipelines/parallel-collect-all-test.pipeline.yaml +39 -0
  72. package/tests/fixtures/test-project/pipelines/parallel-context-isolation-test.pipeline.yaml +38 -0
  73. package/tests/fixtures/test-project/pipelines/parallel-fail-test.pipeline.yaml +39 -0
  74. package/tests/fixtures/test-project/pipelines/parallel-test.pipeline.yaml +39 -0
  75. package/tests/fixtures/test-project/pipelines/parallel-then-sequential-test.pipeline.yaml +38 -0
  76. package/tests/fixtures/test-project/pipelines/simple.pipeline.yaml +15 -0
  77. package/tests/fixtures/test-project/pipelines/two-stage.pipeline.yaml +24 -0
  78. package/tests/fixtures/test-project/pipelines/with-startup.pipeline.yaml +19 -0
  79. package/tests/loader.test.ts +385 -0
  80. package/tests/post-validator.test.ts +297 -0
  81. package/tests/repo-resolver.test.ts +102 -0
  82. package/tests/run-store.test.ts +143 -0
  83. package/tests/state-machine.test.ts +110 -0
  84. package/tests/unit/context-propagation.test.ts +45 -0
  85. package/tests/unit/engine.test.ts +770 -0
  86. package/tests/unit/group-loop.test.ts +389 -0
  87. package/tests/unit/group-parallel.test.ts +423 -0
  88. package/tests/unit/state/status-derivation.test.ts +88 -0
  89. package/tsconfig.json +24 -0
  90. package/vitest.config.ts +14 -0
@@ -0,0 +1,6 @@
1
+
2
+ name: code-gen
3
+ version: 1
4
+ schema:
5
+ required_fields:
6
+ - files_changed
@@ -0,0 +1,8 @@
1
+
2
+ name: maximum-only
3
+ version: 1
4
+ schema:
5
+ required_fields:
6
+ - summary
7
+ tool_calls:
8
+ maximum: 2
@@ -0,0 +1,15 @@
1
+
2
+ name: qa-gate
3
+ version: 1
4
+ schema:
5
+ required_fields:
6
+ - status
7
+ - issues
8
+ post_validation:
9
+ rejection_detection:
10
+ field: status
11
+ approved_values:
12
+ - approved
13
+ - pass
14
+ details_field: issues
15
+ summary_field: summary
@@ -0,0 +1,7 @@
1
+
2
+ name: strict-result
3
+ version: 1
4
+ schema:
5
+ required_fields:
6
+ - result
7
+ - must_exist
@@ -0,0 +1,6 @@
1
+
2
+ name: test-contract
3
+ version: 1
4
+ schema:
5
+ required_fields:
6
+ - summary
@@ -0,0 +1,26 @@
1
+
2
+ name: group-simple
3
+ description: Pipeline with a simple group for cancellation testing
4
+ version: 1
5
+ stages:
6
+ - group: review-loop
7
+ max_iterations: 2
8
+ stages:
9
+ - name: review-stage-1
10
+ kind: analysis
11
+ agent: test-agent
12
+ ralph:
13
+ max_attempts: 1
14
+ retry_strategy: none
15
+ context:
16
+ include:
17
+ - input
18
+ - name: review-stage-2
19
+ kind: analysis
20
+ agent: test-agent
21
+ ralph:
22
+ max_attempts: 1
23
+ retry_strategy: none
24
+ context:
25
+ include:
26
+ - input
@@ -0,0 +1,40 @@
1
+
2
+ name: group-test
3
+ description: Test pipeline with a feedback loop group
4
+ version: 2
5
+ stages:
6
+ - name: analysis
7
+ kind: analysis
8
+ agent: test-agent
9
+ ralph:
10
+ max_attempts: 1
11
+ retry_strategy: none
12
+ context:
13
+ include:
14
+ - input
15
+ - group: impl-review
16
+ max_iterations: 3
17
+ stages:
18
+ - name: code-gen
19
+ kind: code_generation
20
+ agent: test-agent
21
+ contract: code-gen
22
+ ralph:
23
+ max_attempts: 1
24
+ retry_strategy: none
25
+ context:
26
+ include:
27
+ - input
28
+ - all_stage_outputs
29
+ - group_feedback
30
+ - name: qa-review
31
+ kind: qa
32
+ agent: test-agent
33
+ contract: qa-gate
34
+ ralph:
35
+ max_attempts: 1
36
+ retry_strategy: none
37
+ context:
38
+ include:
39
+ - input
40
+ - all_stage_outputs
@@ -0,0 +1,19 @@
1
+
2
+ name: hook-output-template
3
+ description: Pipeline that verifies on_stage_complete hook receives stage output as template context
4
+ version: 1
5
+ stages:
6
+ - name: analysis
7
+ kind: analysis
8
+ agent: test-agent
9
+ contract: test-contract
10
+ hooks:
11
+ on_stage_complete:
12
+ - command: "sh -c 'echo {{output.files_changed}} | grep -qx file.ts'"
13
+ on_failure: reject
14
+ ralph:
15
+ max_attempts: 1
16
+ retry_strategy: none
17
+ context:
18
+ include:
19
+ - input
@@ -0,0 +1,19 @@
1
+
2
+ name: hook-reject-on-failure
3
+ description: Pipeline where on_stage_complete hook fails and rejects the stage
4
+ version: 1
5
+ stages:
6
+ - name: analysis
7
+ kind: analysis
8
+ agent: test-agent
9
+ contract: test-contract
10
+ hooks:
11
+ on_stage_complete:
12
+ - command: "sh -c 'echo hook-error-output >&2; exit 1'"
13
+ on_failure: reject
14
+ ralph:
15
+ max_attempts: 1
16
+ retry_strategy: none
17
+ context:
18
+ include:
19
+ - input
@@ -0,0 +1,15 @@
1
+
2
+ name: maximum-only
3
+ description: Pipeline with a contract that only sets maximum tool_calls
4
+ version: 1
5
+ stages:
6
+ - name: analysis
7
+ kind: analysis
8
+ agent: test-agent
9
+ contract: maximum-only
10
+ ralph:
11
+ max_attempts: 1
12
+ retry_strategy: none
13
+ context:
14
+ include:
15
+ - input
@@ -0,0 +1,39 @@
1
+
2
+ name: parallel-collect-all-test
3
+ description: Test pipeline with collect-all parallel group
4
+ version: 1
5
+ stages:
6
+ - group: parallel-work
7
+ mode: parallel
8
+ on_failure: collect-all
9
+ stages:
10
+ - name: stage-a
11
+ kind: analysis
12
+ agent: test-agent
13
+ contract: basic-result
14
+ ralph:
15
+ max_attempts: 1
16
+ retry_strategy: none
17
+ context:
18
+ include:
19
+ - input
20
+ - name: stage-b
21
+ kind: analysis
22
+ agent: test-agent
23
+ contract: strict-result
24
+ ralph:
25
+ max_attempts: 1
26
+ retry_strategy: none
27
+ context:
28
+ include:
29
+ - input
30
+ - name: stage-c
31
+ kind: analysis
32
+ agent: test-agent
33
+ contract: basic-result
34
+ ralph:
35
+ max_attempts: 1
36
+ retry_strategy: none
37
+ context:
38
+ include:
39
+ - input
@@ -0,0 +1,38 @@
1
+
2
+ name: parallel-context-isolation-test
3
+ description: context isolation test
4
+ version: 1
5
+ stages:
6
+ - name: pre-stage
7
+ kind: analysis
8
+ agent: test-agent
9
+ contract: basic-result
10
+ ralph:
11
+ max_attempts: 1
12
+ retry_strategy: none
13
+ context:
14
+ include:
15
+ - input
16
+ - group: parallel-work
17
+ mode: parallel
18
+ stages:
19
+ - name: stage-a
20
+ kind: analysis
21
+ agent: test-agent
22
+ contract: basic-result
23
+ ralph:
24
+ max_attempts: 1
25
+ retry_strategy: none
26
+ context:
27
+ include:
28
+ - all_stage_outputs
29
+ - name: stage-b
30
+ kind: analysis
31
+ agent: test-agent
32
+ contract: basic-result
33
+ ralph:
34
+ max_attempts: 1
35
+ retry_strategy: none
36
+ context:
37
+ include:
38
+ - all_stage_outputs
@@ -0,0 +1,39 @@
1
+
2
+ name: parallel-fail-test
3
+ description: Test pipeline with a failing stage in parallel group
4
+ version: 1
5
+ stages:
6
+ - group: parallel-work
7
+ mode: parallel
8
+ on_failure: fail-fast
9
+ stages:
10
+ - name: stage-a
11
+ kind: analysis
12
+ agent: test-agent
13
+ contract: basic-result
14
+ ralph:
15
+ max_attempts: 1
16
+ retry_strategy: none
17
+ context:
18
+ include:
19
+ - input
20
+ - name: stage-b
21
+ kind: analysis
22
+ agent: test-agent
23
+ contract: strict-result
24
+ ralph:
25
+ max_attempts: 1
26
+ retry_strategy: none
27
+ context:
28
+ include:
29
+ - input
30
+ - name: stage-c
31
+ kind: analysis
32
+ agent: test-agent
33
+ contract: basic-result
34
+ ralph:
35
+ max_attempts: 1
36
+ retry_strategy: none
37
+ context:
38
+ include:
39
+ - input
@@ -0,0 +1,39 @@
1
+
2
+ name: parallel-test
3
+ description: Test pipeline with parallel group
4
+ version: 1
5
+ stages:
6
+ - group: parallel-work
7
+ mode: parallel
8
+ max_iterations: 1
9
+ stages:
10
+ - name: stage-a
11
+ kind: analysis
12
+ agent: test-agent
13
+ contract: basic-result
14
+ ralph:
15
+ max_attempts: 1
16
+ retry_strategy: none
17
+ context:
18
+ include:
19
+ - input
20
+ - name: stage-b
21
+ kind: analysis
22
+ agent: test-agent
23
+ contract: basic-result
24
+ ralph:
25
+ max_attempts: 1
26
+ retry_strategy: none
27
+ context:
28
+ include:
29
+ - input
30
+ - name: stage-c
31
+ kind: analysis
32
+ agent: test-agent
33
+ contract: basic-result
34
+ ralph:
35
+ max_attempts: 1
36
+ retry_strategy: none
37
+ context:
38
+ include:
39
+ - input
@@ -0,0 +1,38 @@
1
+
2
+ name: parallel-then-sequential-test
3
+ description: Test pipeline with parallel group followed by sequential stage
4
+ version: 1
5
+ stages:
6
+ - group: parallel-work
7
+ mode: parallel
8
+ stages:
9
+ - name: stage-a
10
+ kind: analysis
11
+ agent: test-agent
12
+ contract: basic-result
13
+ ralph:
14
+ max_attempts: 1
15
+ retry_strategy: none
16
+ context:
17
+ include:
18
+ - input
19
+ - name: stage-b
20
+ kind: analysis
21
+ agent: test-agent
22
+ contract: basic-result
23
+ ralph:
24
+ max_attempts: 1
25
+ retry_strategy: none
26
+ context:
27
+ include:
28
+ - input
29
+ - name: merge-results
30
+ kind: merge
31
+ agent: test-agent
32
+ contract: basic-result
33
+ ralph:
34
+ max_attempts: 1
35
+ retry_strategy: none
36
+ context:
37
+ include:
38
+ - all_stage_outputs
@@ -0,0 +1,15 @@
1
+
2
+ name: simple
3
+ description: Simple test pipeline
4
+ version: 1
5
+ stages:
6
+ - name: analysis
7
+ kind: analysis
8
+ agent: test-agent
9
+ contract: test-contract
10
+ ralph:
11
+ max_attempts: 2
12
+ retry_strategy: none
13
+ context:
14
+ include:
15
+ - input
@@ -0,0 +1,24 @@
1
+
2
+ name: two-stage
3
+ description: Two stage pipeline
4
+ version: 1
5
+ stages:
6
+ - name: stage-1
7
+ kind: analysis
8
+ agent: test-agent
9
+ ralph:
10
+ max_attempts: 1
11
+ retry_strategy: none
12
+ context:
13
+ include:
14
+ - input
15
+ - name: stage-2
16
+ kind: planning
17
+ agent: test-agent
18
+ ralph:
19
+ max_attempts: 1
20
+ retry_strategy: none
21
+ context:
22
+ include:
23
+ - input
24
+ - previous_stage_output
@@ -0,0 +1,19 @@
1
+
2
+ name: with-startup
3
+ description: Pipeline that exercises on_pipeline_start context injection
4
+ version: 1
5
+ on_pipeline_start:
6
+ - command: "echo git-status-output"
7
+ inject_as: git_status
8
+ stages:
9
+ - name: analysis
10
+ kind: analysis
11
+ agent: test-agent
12
+ contract: test-contract
13
+ ralph:
14
+ max_attempts: 1
15
+ retry_strategy: none
16
+ context:
17
+ include:
18
+ - input
19
+ - pipeline_start_context