|
| 1 | +# Architecture |
| 2 | + |
| 3 | +Harness Studio uses one workspace entry point and two execution flows: |
| 4 | + |
| 5 | +- **Build**: generate and evolve the harness graph |
| 6 | +- **Run**: execute a single task against a built harness |
| 7 | + |
| 8 | +The system is intentionally split so build and run do not share the same phase logic or success criteria. |
| 9 | + |
| 10 | +## 1. Single Workspace Model |
| 11 | + |
| 12 | +The main workspace is `/harness/[id]`. |
| 13 | + |
| 14 | +It owns: |
| 15 | + |
| 16 | +- Harness Goal intake |
| 17 | +- Capability policy intake |
| 18 | +- Build / Rebuild actions |
| 19 | +- Run New Task entry |
| 20 | +- Graph, inspector, and build/runtime drawers |
| 21 | + |
| 22 | +`/harness/new` only creates a new harness and redirects back to the workspace. |
| 23 | + |
| 24 | +## 2. Build / Run Separation |
| 25 | + |
| 26 | +### Build |
| 27 | + |
| 28 | +The build path creates or updates the harness graph. |
| 29 | + |
| 30 | +Relevant code: |
| 31 | + |
| 32 | +- `src/lib/build-orchestrator.ts` |
| 33 | +- `src/lib/planner/*` |
| 34 | +- `src/lib/specx/*` |
| 35 | +- `src/lib/scriptx/*` |
| 36 | +- `src/lib/capabilities/*` |
| 37 | + |
| 38 | +Build is responsible for: |
| 39 | + |
| 40 | +- planning |
| 41 | +- composing the blueprint |
| 42 | +- resolving capabilities |
| 43 | +- compiling specs and scripts |
| 44 | +- assembling the graph |
| 45 | + |
| 46 | +Build does not execute runtime tasks. |
| 47 | + |
| 48 | +### Run |
| 49 | + |
| 50 | +The run path consumes a persisted task instance and produces task artifacts. |
| 51 | + |
| 52 | +Relevant code: |
| 53 | + |
| 54 | +- `src/lib/run-orchestrator.ts` |
| 55 | +- `src/lib/runtime/*` |
| 56 | +- `src/lib/run-output/*` |
| 57 | +- `src/lib/task/*` |
| 58 | + |
| 59 | +Run is responsible for: |
| 60 | + |
| 61 | +- task instance planning |
| 62 | +- agent runtime decisions |
| 63 | +- capability selection |
| 64 | +- tool / skill / script execution |
| 65 | +- node output artifacts |
| 66 | +- final deliverable aggregation |
| 67 | +- final report generation as an auxiliary output |
| 68 | + |
| 69 | +## 3. State Machines |
| 70 | + |
| 71 | +The project uses explicit state transitions: |
| 72 | + |
| 73 | +- `src/lib/harness-machine.ts` |
| 74 | +- `src/lib/run-machine.ts` |
| 75 | + |
| 76 | +States are not mutated directly from components or routes. |
| 77 | + |
| 78 | +## 4. Task Instance Layer |
| 79 | + |
| 80 | +The task instance is the authoritative run plan. |
| 81 | + |
| 82 | +Persisted fields include: |
| 83 | + |
| 84 | +- `id` |
| 85 | +- `runId` |
| 86 | +- `harnessId` |
| 87 | +- `instruction` |
| 88 | +- `goal` |
| 89 | +- `constraints` |
| 90 | +- `successCriteria` |
| 91 | +- `perAgentAssignments` |
| 92 | +- `finalDeliverable` |
| 93 | +- `planningSummary` |
| 94 | + |
| 95 | +Agents read the task instance, not just the raw task instruction string. |
| 96 | + |
| 97 | +## 5. Artifact Layer |
| 98 | + |
| 99 | +Artifacts are the main runtime output unit. |
| 100 | + |
| 101 | +Supported artifact types include: |
| 102 | + |
| 103 | +- `task.instance` |
| 104 | +- `agent.plan` |
| 105 | +- `agent.output` |
| 106 | +- `tool.result` |
| 107 | +- `spec.validation` |
| 108 | +- `final.deliverable` |
| 109 | +- `final.report` |
| 110 | +- `error.report` |
| 111 | + |
| 112 | +The run detail view is artifacts-first. |
| 113 | + |
| 114 | +## 6. Final Deliverable |
| 115 | + |
| 116 | +`src/lib/run-output/final-deliverable-aggregator.ts` collects the key node artifacts and requires a real `final.deliverable` artifact. |
| 117 | + |
| 118 | +The final report is a secondary summary, not the primary task result. |
| 119 | + |
| 120 | +## 7. Adapters |
| 121 | + |
| 122 | +The codebase uses adapter boundaries so runtime can be swapped or demoed without replacing the orchestrator. |
| 123 | + |
| 124 | +- **LLM**: `src/lib/llm/*` |
| 125 | +- **SpecX**: `src/lib/specx/*` |
| 126 | +- **Capability resolution**: `src/lib/capabilities/*` |
| 127 | +- **Runtime execution**: `src/lib/runtime/*` |
| 128 | +- **Script authoring and compilation**: `src/lib/scriptx/*` |
| 129 | + |
| 130 | +`DEMO_MODE=true` swaps only adapter implementations. |
| 131 | + |
| 132 | +## 8. SQLite and SSE |
| 133 | + |
| 134 | +- SQLite database bootstrap lives in `src/lib/sqlite.ts` |
| 135 | +- Event streaming lives in `src/lib/useEventStream.ts` |
| 136 | +- Harness and run events are persisted and pushed through SSE |
| 137 | + |
| 138 | +## 9. Code Map |
| 139 | + |
| 140 | +```text |
| 141 | +src/ |
| 142 | + app/ |
| 143 | + api/ |
| 144 | + harness/ |
| 145 | + runs/ |
| 146 | + components/ |
| 147 | + lib/ |
| 148 | + capabilities/ |
| 149 | + llm/ |
| 150 | + planner/ |
| 151 | + run-output/ |
| 152 | + runtime/ |
| 153 | + scriptx/ |
| 154 | + specx/ |
| 155 | + task/ |
| 156 | +shared/ |
| 157 | + prompts/ |
| 158 | + registries/ |
| 159 | + schemas/ |
| 160 | + specs/ |
| 161 | + types/ |
| 162 | +``` |
0 commit comments