@s_s/harmonia 1.3.0 → 1.4.0

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 (172) hide show
  1. package/README.md +140 -392
  2. package/build/cli/setup.d.ts +4 -2
  3. package/build/cli/setup.js +44 -18
  4. package/build/cli/setup.js.map +1 -1
  5. package/build/core/action-registry.d.ts +36 -0
  6. package/build/core/action-registry.js +53 -0
  7. package/build/core/action-registry.js.map +1 -0
  8. package/build/core/artifacts.d.ts +66 -0
  9. package/build/core/artifacts.js +178 -0
  10. package/build/core/artifacts.js.map +1 -0
  11. package/build/core/dispatch.d.ts +6 -2
  12. package/build/core/dispatch.js +12 -7
  13. package/build/core/dispatch.js.map +1 -1
  14. package/build/core/overrides.d.ts +19 -26
  15. package/build/core/overrides.js +32 -98
  16. package/build/core/overrides.js.map +1 -1
  17. package/build/core/plugin.d.ts +86 -0
  18. package/build/core/plugin.js +332 -0
  19. package/build/core/plugin.js.map +1 -0
  20. package/build/core/registry.d.ts +4 -5
  21. package/build/core/registry.js +8 -9
  22. package/build/core/registry.js.map +1 -1
  23. package/build/core/reviews.d.ts +11 -12
  24. package/build/core/reviews.js +18 -21
  25. package/build/core/reviews.js.map +1 -1
  26. package/build/core/schema.d.ts +43 -15
  27. package/build/core/schema.js +124 -20
  28. package/build/core/schema.js.map +1 -1
  29. package/build/core/state.d.ts +26 -27
  30. package/build/core/state.js +36 -90
  31. package/build/core/state.js.map +1 -1
  32. package/build/core/steps.d.ts +13 -14
  33. package/build/core/steps.js +26 -29
  34. package/build/core/steps.js.map +1 -1
  35. package/build/core/tree-utils.d.ts +52 -0
  36. package/build/core/tree-utils.js +226 -0
  37. package/build/core/tree-utils.js.map +1 -0
  38. package/build/core/types.d.ts +389 -118
  39. package/build/core/types.js +15 -1
  40. package/build/core/types.js.map +1 -1
  41. package/build/core/workflow-engine.d.ts +68 -0
  42. package/build/core/workflow-engine.js +821 -0
  43. package/build/core/workflow-engine.js.map +1 -0
  44. package/build/core/workflow-validator.d.ts +22 -0
  45. package/build/core/workflow-validator.js +489 -0
  46. package/build/core/workflow-validator.js.map +1 -0
  47. package/build/index.js +25 -26
  48. package/build/index.js.map +1 -1
  49. package/build/setup/inject.d.ts +4 -4
  50. package/build/setup/inject.js +6 -6
  51. package/build/setup/inject.js.map +1 -1
  52. package/build/setup/templates.d.ts +9 -7
  53. package/build/setup/templates.js +68 -172
  54. package/build/setup/templates.js.map +1 -1
  55. package/build/tools/artifact-approve.d.ts +8 -0
  56. package/build/tools/{approve-doc.js → artifact-approve.js} +24 -16
  57. package/build/tools/artifact-approve.js.map +1 -0
  58. package/build/tools/artifact-schema.d.ts +12 -0
  59. package/build/tools/artifact-schema.js +148 -0
  60. package/build/tools/artifact-schema.js.map +1 -0
  61. package/build/tools/artifact-tools.d.ts +18 -0
  62. package/build/tools/artifact-tools.js +465 -0
  63. package/build/tools/artifact-tools.js.map +1 -0
  64. package/build/tools/{report-dispatch.d.ts → dispatch-report.d.ts} +7 -3
  65. package/build/tools/{report-dispatch.js → dispatch-report.js} +106 -28
  66. package/build/tools/dispatch-report.js.map +1 -0
  67. package/build/tools/engine-helpers.d.ts +41 -0
  68. package/build/tools/engine-helpers.js +182 -0
  69. package/build/tools/engine-helpers.js.map +1 -0
  70. package/build/tools/get-project-status.d.ts +6 -4
  71. package/build/tools/get-project-status.js +265 -248
  72. package/build/tools/get-project-status.js.map +1 -1
  73. package/build/tools/get-role-prompt.d.ts +1 -1
  74. package/build/tools/get-role-prompt.js +7 -41
  75. package/build/tools/get-role-prompt.js.map +1 -1
  76. package/build/tools/iteration-start.d.ts +7 -4
  77. package/build/tools/iteration-start.js +45 -19
  78. package/build/tools/iteration-start.js.map +1 -1
  79. package/build/tools/loop-done.d.ts +11 -0
  80. package/build/tools/loop-done.js +109 -0
  81. package/build/tools/loop-done.js.map +1 -0
  82. package/build/tools/patch-start.d.ts +4 -2
  83. package/build/tools/patch-start.js +36 -11
  84. package/build/tools/patch-start.js.map +1 -1
  85. package/build/tools/project-init.d.ts +5 -5
  86. package/build/tools/project-init.js +41 -10
  87. package/build/tools/project-init.js.map +1 -1
  88. package/build/tools/role-dispatch.d.ts +55 -0
  89. package/build/tools/role-dispatch.js +508 -0
  90. package/build/tools/role-dispatch.js.map +1 -0
  91. package/build/tools/utils.d.ts +6 -0
  92. package/build/tools/utils.js +36 -0
  93. package/build/tools/utils.js.map +1 -1
  94. package/package.json +1 -1
  95. package/{build/hooks/claude-code.js → workflows/dev/hooks/claude.js} +34 -23
  96. package/{build → workflows/dev}/hooks/content.js +27 -18
  97. package/workflows/dev/hooks/index.js +52 -0
  98. package/{build → workflows/dev}/hooks/openclaw.js +31 -20
  99. package/{build → workflows/dev}/hooks/opencode.js +31 -20
  100. package/workflows/dev/roles/architect.md +68 -28
  101. package/workflows/dev/roles/coordinator.md +103 -0
  102. package/workflows/dev/roles/developer.md +5 -5
  103. package/workflows/dev/roles/tester.md +19 -19
  104. package/workflows/dev/schemas/api-contract.json +42 -0
  105. package/workflows/dev/schemas/api-design.json +30 -13
  106. package/workflows/dev/schemas/data-model.json +20 -7
  107. package/workflows/dev/schemas/prd.completeness-check.json +6 -5
  108. package/workflows/dev/schemas/prd.draft.json +13 -5
  109. package/workflows/dev/schemas/prd.final.json +34 -11
  110. package/workflows/dev/schemas/prd.json +29 -11
  111. package/workflows/dev/schemas/prd.requirements.json +6 -5
  112. package/workflows/dev/schemas/prototype.json +6 -2
  113. package/workflows/dev/schemas/task-breakdown.coarse.json +4 -3
  114. package/workflows/dev/schemas/task-breakdown.dependencies.json +5 -4
  115. package/workflows/dev/schemas/task-breakdown.detailed.json +8 -3
  116. package/workflows/dev/schemas/task-breakdown.final.json +8 -3
  117. package/workflows/dev/schemas/task-breakdown.json +8 -3
  118. package/workflows/dev/schemas/tech-design.analysis.json +6 -5
  119. package/workflows/dev/schemas/tech-design.draft.json +14 -5
  120. package/workflows/dev/schemas/tech-design.final.json +39 -13
  121. package/workflows/dev/schemas/tech-design.json +34 -13
  122. package/workflows/dev/schemas/tech-design.research.json +21 -0
  123. package/workflows/dev/schemas/test-plan.json +17 -7
  124. package/workflows/dev/schemas/test-report.json +26 -9
  125. package/workflows/dev/schemas/user-stories.json +7 -3
  126. package/workflows/dev/tools/index.js +23 -0
  127. package/workflows/dev/workflow.json +234 -101
  128. package/build/core/docs.d.ts +0 -36
  129. package/build/core/docs.js +0 -96
  130. package/build/core/docs.js.map +0 -1
  131. package/build/core/workflow.d.ts +0 -33
  132. package/build/core/workflow.js +0 -140
  133. package/build/core/workflow.js.map +0 -1
  134. package/build/hooks/claude-code.d.ts +0 -20
  135. package/build/hooks/claude-code.js.map +0 -1
  136. package/build/hooks/content.d.ts +0 -43
  137. package/build/hooks/content.js.map +0 -1
  138. package/build/hooks/install.d.ts +0 -40
  139. package/build/hooks/install.js +0 -63
  140. package/build/hooks/install.js.map +0 -1
  141. package/build/hooks/openclaw.d.ts +0 -24
  142. package/build/hooks/openclaw.js.map +0 -1
  143. package/build/hooks/opencode.d.ts +0 -29
  144. package/build/hooks/opencode.js.map +0 -1
  145. package/build/tools/approve-doc.d.ts +0 -6
  146. package/build/tools/approve-doc.js.map +0 -1
  147. package/build/tools/dispatch-role.d.ts +0 -16
  148. package/build/tools/dispatch-role.js +0 -266
  149. package/build/tools/dispatch-role.js.map +0 -1
  150. package/build/tools/doc-tools.d.ts +0 -16
  151. package/build/tools/doc-tools.js +0 -425
  152. package/build/tools/doc-tools.js.map +0 -1
  153. package/build/tools/override-tools.d.ts +0 -6
  154. package/build/tools/override-tools.js +0 -129
  155. package/build/tools/override-tools.js.map +0 -1
  156. package/build/tools/report-dispatch.js.map +0 -1
  157. package/build/tools/set-scale.d.ts +0 -6
  158. package/build/tools/set-scale.js +0 -95
  159. package/build/tools/set-scale.js.map +0 -1
  160. package/build/tools/setup-project.d.ts +0 -8
  161. package/build/tools/setup-project.js +0 -116
  162. package/build/tools/setup-project.js.map +0 -1
  163. package/build/tools/update-phase.d.ts +0 -12
  164. package/build/tools/update-phase.js +0 -148
  165. package/build/tools/update-phase.js.map +0 -1
  166. package/workflows/dev/roles/pm.md +0 -99
  167. package/workflows/dev/schemas/deploy.json +0 -20
  168. package/workflows/dev/schemas/fsd.json +0 -25
  169. package/workflows/dev/schemas/project-plan.json +0 -20
  170. package/workflows/dev/schemas/retrospective.json +0 -20
  171. package/workflows/dev/schemas/risk-assessment.json +0 -15
  172. package/workflows/dev/schemas/tech-design.api-contract.json +0 -20
@@ -1,109 +1,225 @@
1
1
  /**
2
2
  * Core type definitions for Harmonia.
3
- * These types are workflow-agnostic — no hardcoded role names or phase names.
3
+ *
4
+ * Architecture: Core provides composable collaboration primitives.
5
+ * Workflow plugins use these primitives to define specific processes.
6
+ *
7
+ * This file defines:
8
+ * - Workflow node types (task, sequence, parallel, gate, loop)
9
+ * - Workflow state (node-based, not phase-based)
10
+ * - Engine types (nextAction, events, gate evaluation)
11
+ * - Artifact system
12
+ * - Plugin interface
13
+ * - Session & Dispatch tracking
14
+ * - Override configuration (simplified to 2-layer)
15
+ * - Sequential step tracking
16
+ * - Issue tracking
17
+ * - Review state
4
18
  */
5
- export interface PhaseDefinition {
19
+ /** Agent type for spawning team member agents (re-exported from @s_s/agent-kit) */
20
+ import type { AgentType } from '@s_s/agent-kit';
21
+ export type { AgentType };
22
+ export type NodeType = 'task' | 'sequence' | 'parallel' | 'gate' | 'loop';
23
+ /** Hook configuration for beforeDispatch / afterComplete */
24
+ export interface NodeHook {
25
+ /** Extra prompt text to inject */
26
+ inject?: string[];
27
+ /** Registered action names to execute synchronously */
28
+ actions?: string[];
29
+ }
30
+ /** Failure handler for task and parallel nodes */
31
+ export interface FailureHandler {
32
+ /** Target node ID to jump back to (must satisfy ancestor-chain constraint) */
33
+ goto: string;
34
+ /** Max retry count; omit for unlimited */
35
+ maxRetries?: number;
36
+ /** Floating node ID to jump to when retries exhausted */
37
+ onExhausted?: string;
38
+ }
39
+ /** Goto target for gate fail paths */
40
+ export interface GotoTarget {
41
+ /** Target node ID to jump back to */
42
+ goto: string;
43
+ /** Max retry count; omit for unlimited */
44
+ maxRetries?: number;
45
+ /** Floating node ID to jump to when retries exhausted */
46
+ onExhausted?: string;
47
+ }
48
+ /** Task node — work unit assigned to a role */
49
+ export interface TaskNode {
50
+ type: 'task';
51
+ id: string;
52
+ /** Role ID that executes this task */
53
+ role: string;
54
+ /** Artifact IDs this task needs as input (resolved to name + path references at dispatch time) */
55
+ inputArtifacts?: string[];
56
+ /** Optional timeout in seconds */
57
+ timeout?: number;
58
+ /** Optional failure handler */
59
+ onFailed?: FailureHandler;
60
+ /** Hook before dispatching to role */
61
+ beforeDispatch?: NodeHook;
62
+ /** Hook after task completion */
63
+ afterComplete?: NodeHook;
64
+ }
65
+ /** Sequence node — children execute in order */
66
+ export interface SequenceNode {
67
+ type: 'sequence';
68
+ id: string;
69
+ children: WorkflowNode[];
70
+ }
71
+ /** Parallel node — children execute simultaneously */
72
+ export interface ParallelNode {
73
+ type: 'parallel';
74
+ id: string;
75
+ /** Required: how to handle child failures */
76
+ failStrategy: 'fail-fast' | 'wait-all';
77
+ children: WorkflowNode[];
78
+ /** Optional failure handler */
79
+ onFailed?: FailureHandler;
80
+ }
81
+ /** Gate condition types */
82
+ export interface ArtifactExistsCondition {
83
+ type: 'artifact_exists';
84
+ /** Artifact ID to check */
85
+ artifact: string;
86
+ }
87
+ export interface ArtifactApprovedCondition {
88
+ type: 'artifact_approved';
89
+ /** Artifact ID to check */
90
+ artifact: string;
91
+ }
92
+ export type ArtifactFieldOperator = 'eq' | 'neq' | 'gt' | 'lt' | 'gte' | 'lte' | 'contains' | 'in';
93
+ export interface ArtifactFieldCondition {
94
+ type: 'artifact_field';
95
+ /** Artifact ID to check */
96
+ artifact: string;
97
+ /** Field path within the artifact */
98
+ field: string;
99
+ /** Comparison operator */
100
+ operator: ArtifactFieldOperator;
101
+ /** Expected value */
102
+ value: unknown;
103
+ }
104
+ export type GateCondition = ArtifactExistsCondition | ArtifactApprovedCondition | ArtifactFieldCondition;
105
+ /** Gate node — condition check with pass/fail paths */
106
+ export interface GateNode {
107
+ type: 'gate';
6
108
  id: string;
109
+ /** All conditions must be met for pass */
110
+ conditions: GateCondition[];
111
+ /** Path when all conditions pass (inline node) */
112
+ pass: WorkflowNode;
113
+ /** Path when conditions fail — inline node or goto */
114
+ fail: WorkflowNode | GotoTarget;
115
+ }
116
+ /** Loop node — repeated execution of a sub-workflow with iteration state */
117
+ export interface LoopNode {
118
+ type: 'loop';
119
+ id: string;
120
+ /** Maximum iterations (safety cap) */
121
+ maxIterations: number;
122
+ /** The sub-workflow to repeat each iteration */
123
+ body: WorkflowNode;
124
+ /** Optional failure handler */
125
+ onFailed?: FailureHandler;
126
+ }
127
+ /** Union of all workflow node types */
128
+ export type WorkflowNode = TaskNode | SequenceNode | ParallelNode | GateNode | LoopNode;
129
+ /** Complete workflow definition loaded from workflow.json */
130
+ export interface WorkflowDefinition {
7
131
  name: string;
8
- roles: string[];
9
- inputs?: string[];
10
- outputs: string[];
11
132
  description: string;
133
+ version?: string;
134
+ /** Author of this workflow */
135
+ author?: string;
136
+ /** Coordinator role ID — every workflow must have one */
137
+ coordinator: string;
138
+ /** Root node of the workflow tree */
139
+ root: WorkflowNode;
140
+ /** Standalone nodes referenced by onExhausted/onFailed */
141
+ floatingNodes?: TaskNode[];
12
142
  }
13
- export type DocScale = 'full' | 'lite' | 'skip' | 'optional';
14
- /** Step definition within a doc (for sequential mode) */
15
- export interface DocStepDefinition {
143
+ /** Step definition within an artifact (for sequential mode) */
144
+ export interface ArtifactStepDefinition {
16
145
  /** Step ID, e.g. "requirements", "draft", "final" */
17
146
  id: string;
18
147
  /** Human-readable name */
19
148
  name: string;
20
- /** Output format for this step's artifact */
149
+ /** Output format for this step */
21
150
  format: 'json' | 'md';
22
151
  /** Description shown to agent */
23
152
  description: string;
24
153
  }
25
- export interface DocDefinition {
154
+ /** Artifact definition — metadata for an artifact type */
155
+ export interface ArtifactDefinition {
156
+ /** Human-readable name */
26
157
  name: string;
27
- scale: Record<ProjectScale, DocScale>;
28
- /** File format: "md" (default) or "html" */
29
- format?: 'md' | 'html';
30
- /** Whether this doc requires user review/approval after creation */
158
+ /** File format: "md" (default), "html", or "json" */
159
+ format?: 'md' | 'html' | 'json';
160
+ /** Whether this artifact requires user review/approval */
31
161
  review?: boolean;
32
- /** External output — not managed by write_doc (e.g. code written directly to project dir) */
33
- external?: boolean;
34
- /** Sequential steps — when defined and scale >= medium, write_doc requires step parameter */
35
- steps?: DocStepDefinition[];
36
- }
37
- export interface ScaleDimension {
38
- small: string | number | boolean;
39
- medium: string | number | boolean;
40
- large: string | number | boolean;
41
- }
42
- export interface WorkflowDefinition {
43
- name: string;
44
- description: string;
45
- version?: string;
46
- author?: string;
47
- phases: PhaseDefinition[];
48
- docs: Record<string, DocDefinition>;
49
- scale_criteria: {
50
- description: string;
51
- dimensions: Record<string, ScaleDimension>;
52
- };
162
+ /** Unmanaged output — not managed by artifact_write (e.g. code written directly by agent) */
163
+ unmanaged?: boolean;
164
+ /**
165
+ * Output directory template using placeholders:
166
+ * - `{global}` → `<data_dir>/<project>/iter-N/artifacts/`
167
+ * - `{project}` → `<projectDir>/`
168
+ * - `{context}` `iter-N` or `patch-N` (must follow `{global}` or `{project}`)
169
+ *
170
+ * When undefined, defaults to `{global}` behavior.
171
+ * File name is always `<artifactId>.<ext>` — output only controls the directory.
172
+ */
173
+ output?: string;
174
+ /** Sequential steps — when defined, artifact_write requires step parameter */
175
+ steps?: ArtifactStepDefinition[];
53
176
  }
54
- /**
55
- * A required section (heading) in a markdown document.
56
- * Validation checks that the document contains a heading matching the primary
57
- * pattern or one of the aliases.
58
- */
59
- export interface DocSchemaSection {
177
+ /** A required section (heading) in a markdown artifact */
178
+ export interface ArtifactSchemaSection {
60
179
  /** Primary heading text, e.g. "## 项目概述" */
61
180
  heading: string;
62
- /** Per-scale requirement: true = required, false = optional */
63
- required: Record<ProjectScale, boolean>;
181
+ /** Whether this section is required */
182
+ required: boolean;
64
183
  /** Alternative heading texts that satisfy this requirement */
65
184
  aliases?: string[];
66
185
  }
67
- /**
68
- * Schema definition for a document type.
69
- * Used by write_doc to validate content structure before writing.
70
- */
71
- export interface DocSchema {
72
- /** Required sections for markdown documents */
73
- sections?: DocSchemaSection[];
74
- /** Required HTML tags for html-format documents (e.g. ["html", "body", "nav"]) */
75
- htmlTags?: string[];
76
- /** Required top-level JSON fields (for JSON step artifacts) */
77
- jsonFields?: DocSchemaJsonField[];
78
- /** Minimum content length in characters (optional) */
79
- minLength?: number;
80
- }
81
- /**
82
- * A required top-level field in a JSON document.
83
- * Used for validating structured step artifacts.
84
- */
85
- export interface DocSchemaJsonField {
186
+ /** A required top-level field in a JSON artifact */
187
+ export interface ArtifactSchemaJsonField {
86
188
  /** Field name (top-level key in JSON) */
87
189
  field: string;
88
- /** Per-scale requirement: true = required, false = optional */
89
- required: Record<ProjectScale, boolean>;
190
+ /** Whether this field is required */
191
+ required: boolean;
90
192
  /** Expected type: "string", "array", "object", "number", "boolean" */
91
193
  type?: string;
92
194
  /** If type is "array", minimum number of items */
93
195
  minItems?: number;
94
196
  }
197
+ /** Schema definition for an artifact type */
198
+ export interface ArtifactSchema {
199
+ /** Required sections for markdown artifacts */
200
+ sections?: ArtifactSchemaSection[];
201
+ /** Required HTML tags for html-format artifacts */
202
+ htmlTags?: string[];
203
+ /** Required top-level JSON fields */
204
+ jsonFields?: ArtifactSchemaJsonField[];
205
+ /** Minimum content length in characters */
206
+ minLength?: number;
207
+ /** Human-readable guidance for agents */
208
+ guidance?: string;
209
+ }
95
210
  export interface RoleCapability {
96
211
  /** Unique ID for this capability */
97
212
  id: string;
98
- /** Human-readable description of what this capability does */
213
+ /** Human-readable description */
99
214
  description: string;
100
- /** Associated doc ID — if set, this capability produces this document */
101
- doc?: string;
215
+ /** Associated artifact ID — if set, this capability produces this artifact */
216
+ artifact?: string;
102
217
  }
103
218
  export interface RoleFrontmatter {
104
- model: string;
219
+ model?: string;
105
220
  session: 'none' | 'persistent' | 'optional';
106
221
  parallel: boolean;
222
+ agent?: string;
107
223
  /** Capabilities this role provides (used by override system) */
108
224
  capabilities?: RoleCapability[];
109
225
  }
@@ -112,45 +228,200 @@ export interface RoleDefinition {
112
228
  frontmatter: RoleFrontmatter;
113
229
  prompt: string;
114
230
  }
115
- export interface LoadedWorkflow {
116
- definition: WorkflowDefinition;
117
- roles: Record<string, RoleDefinition>;
118
- }
119
- export type PhaseStatus = 'pending' | 'in_progress' | 'completed' | 'blocked' | 'review' | 'skipped';
120
- export type ProjectScale = 'small' | 'medium' | 'large';
231
+ export type NodeStatus = 'pending' | 'active' | 'completed' | 'failed' | 'cancelled' | 'skipped';
121
232
  export type ContextType = 'iteration' | 'patch';
122
- export interface PhaseState {
233
+ /** Runtime state of a single node */
234
+ export interface NodeState {
235
+ /** Node ID (matches definition) */
123
236
  id: string;
124
- status: PhaseStatus;
237
+ /** Current status */
238
+ status: NodeStatus;
239
+ /** Number of times this node has been retried (0 = first execution) */
240
+ retryCount: number;
241
+ /** When this node became active */
125
242
  startedAt?: string;
243
+ /** When this node completed (or failed) */
126
244
  completedAt?: string;
127
- blockedReason?: string;
245
+ /** Error message if failed */
246
+ error?: string;
247
+ }
248
+ /** Runtime state for loop nodes (extends NodeState) */
249
+ export interface LoopNodeState extends NodeState {
250
+ /** Current iteration index (0-based) */
251
+ currentIteration: number;
252
+ /** Whether loop_done has been called — loop will terminate after current iteration completes */
253
+ done: boolean;
128
254
  }
129
- export interface ProjectState {
255
+ /** Complete workflow state (persisted in state.json) */
256
+ export interface WorkflowState {
130
257
  /** Project name (unique identifier) */
131
258
  projectName: string;
132
259
  /** Absolute path to the project source directory */
133
260
  projectDir: string;
134
- /** Workflow name, e.g. "dev" */
261
+ /** Workflow plugin name, e.g. "dev" */
135
262
  workflow: string;
136
- /** Context type: "iteration" for full iterations, "patch" for lightweight patches */
263
+ /** Context type: iteration or patch */
137
264
  type: ContextType;
138
- /** Iteration or patch number this state belongs to */
265
+ /** Iteration or patch number */
139
266
  iteration: number;
140
- /** Project scale determined by PM (null until set via project_set_scale) */
141
- scale: ProjectScale | null;
142
- /** Current phase id */
143
- currentPhase: string;
144
- /** State of each phase */
145
- phases: PhaseState[];
146
- /** Timestamp of project initialization */
267
+ /** Currently active node ID (null when workflow is completed or not started) */
268
+ activeNodeId: string | null;
269
+ /** State of every node, keyed by node ID */
270
+ nodes: Record<string, NodeState>;
271
+ /** Timestamp of state initialization */
147
272
  createdAt: string;
148
273
  /** Last updated timestamp */
149
274
  updatedAt: string;
275
+ /** Optional metadata (e.g. patch description, linked issue) */
276
+ meta?: Record<string, unknown>;
277
+ }
278
+ /** Per-condition evaluation detail */
279
+ export interface GateConditionResult {
280
+ /** The condition that was evaluated */
281
+ condition: GateCondition;
282
+ /** Whether the condition was met */
283
+ met: boolean;
284
+ /** Actual value found (for artifact_field conditions) */
285
+ actualValue?: unknown;
286
+ }
287
+ /** Gate evaluation result */
288
+ export interface GateEvaluationResult {
289
+ /** Whether all conditions passed */
290
+ passed: boolean;
291
+ /** Per-condition evaluation details */
292
+ conditions: GateConditionResult[];
293
+ }
294
+ /** nextAction type — tells the coordinator what to do next */
295
+ export type NextActionType = 'dispatch' | 'write_artifact' | 'approve_artifact' | 'wait' | 'completed' | 'failed' | 'evaluate_gate' | 'none';
296
+ /** Unified nextAction return structure */
297
+ export interface NextAction {
298
+ /** What the coordinator should do */
299
+ type: NextActionType;
300
+ /** Target node ID (if applicable) */
301
+ nodeId?: string;
302
+ /** Role to dispatch (if type is 'dispatch') */
303
+ role?: string;
304
+ /** Human-readable instructions for the coordinator */
305
+ instructions: string;
306
+ /** Fully assembled prompt for the team member (if dispatching) */
307
+ rolePrompt?: string;
308
+ /** Gate evaluation results (if coming from a gate fail/goto) */
309
+ gateResults?: GateEvaluationResult;
310
+ /** Parallel dispatch targets (when dispatching multiple tasks simultaneously) */
311
+ parallelDispatch?: Array<{
312
+ nodeId: string;
313
+ role: string;
314
+ }>;
315
+ }
316
+ /** Events that trigger engine state transitions */
317
+ export type WorkflowEvent = {
318
+ type: 'node_completed';
319
+ nodeId: string;
320
+ result?: unknown;
321
+ } | {
322
+ type: 'node_failed';
323
+ nodeId: string;
324
+ error: string;
325
+ } | {
326
+ type: 'artifact_written';
327
+ artifactId: string;
328
+ } | {
329
+ type: 'artifact_approved';
330
+ artifactId: string;
331
+ } | {
332
+ type: 'dispatch_requested';
333
+ nodeId: string;
334
+ } | {
335
+ type: 'query_status';
336
+ } | {
337
+ type: 'loop_done';
338
+ nodeId: string;
339
+ };
340
+ /** Context passed to action handlers */
341
+ export interface ActionContext {
342
+ /** Current node ID */
343
+ nodeId: string;
344
+ /** Current node's role */
345
+ role: string;
346
+ /** Current retry count (0 = first execution) */
347
+ retryCount: number;
348
+ /** Project name */
349
+ projectName: string;
350
+ /** Plugin-specific configuration (opaque to Core) */
351
+ pluginConfig: unknown;
352
+ /** Gate evaluation results (if arriving via goto from gate fail) */
353
+ gateResults?: GateEvaluationResult;
354
+ /** Current workflow state snapshot */
355
+ workflowState: WorkflowState;
356
+ /** Artifact access API */
357
+ artifacts: {
358
+ read: (artifactId: string) => Promise<string>;
359
+ list: () => Promise<string[]>;
360
+ };
361
+ /** Task completion result (only in afterComplete) */
362
+ taskResult?: unknown;
363
+ /** Current loop iteration index (0-based), only set when task is inside a loop */
364
+ loopIteration?: number;
365
+ }
366
+ /** Return value from action handlers */
367
+ export interface ActionResult {
368
+ /** Dynamic prompt text to inject */
369
+ inject?: string[];
370
+ /** Additional data to pass downstream */
371
+ data?: unknown;
372
+ }
373
+ /** Action handler function signature */
374
+ export type ActionHandler = (context: ActionContext) => Promise<ActionResult>;
375
+ /** Hook creator function signature */
376
+ export type HookCreator = (agentType: AgentType, context: HookCreatorContext) => unknown;
377
+ /** Context passed to plugin's createHooks function */
378
+ export interface HookCreatorContext {
379
+ /** defineHooks function from agent-kit */
380
+ defineHooks: unknown;
381
+ /** Harmonia data directory */
382
+ dataDir: string;
383
+ /** Project name */
384
+ projectName: string;
385
+ }
386
+ /** Complete loaded workflow plugin */
387
+ export interface WorkflowPlugin {
388
+ /** Plugin name (matches workflow name) */
389
+ name: string;
390
+ /** Workflow tree definition */
391
+ definition: WorkflowDefinition;
392
+ /** Role definitions keyed by role ID */
393
+ roles: Record<string, RoleDefinition>;
394
+ /** Artifact schemas keyed by artifact ID */
395
+ artifactSchemas: Record<string, ArtifactSchema>;
396
+ /** Artifact definitions keyed by artifact ID */
397
+ artifactDefinitions: Record<string, ArtifactDefinition>;
398
+ /** Registered actions (from tools/index.js) */
399
+ actions?: Record<string, ActionHandler>;
400
+ /** Hook creator (from hooks/index.js) */
401
+ hooks?: HookCreator;
402
+ /** Plugin-specific configuration (from config.json) */
403
+ config?: unknown;
404
+ /** Filesystem path to the plugin directory */
405
+ pluginDir: string;
406
+ }
407
+ /** Plugin entry in config.json */
408
+ export interface PluginEntry {
409
+ /** Workflow name */
410
+ name?: string;
411
+ /** Filesystem path to the plugin directory */
412
+ path: string;
413
+ /** Plugin-specific configuration */
414
+ config?: unknown;
415
+ }
416
+ /** Global config.json structure */
417
+ export interface GlobalConfig {
418
+ /** Registered workflow plugins */
419
+ workflows: Record<string, PluginEntry>;
150
420
  }
151
421
  export type ReviewStatus = 'pending' | 'approved' | 'rejected';
152
- export interface DocReviewState {
153
- docId: string;
422
+ export interface ReviewState {
423
+ /** Artifact ID */
424
+ artifactId: string;
154
425
  status: ReviewStatus;
155
426
  submittedAt: string;
156
427
  reviewedAt?: string;
@@ -162,13 +433,13 @@ export interface SessionRecord {
162
433
  id: string;
163
434
  /** Role this session belongs to */
164
435
  role: string;
165
- /** Actual session ID from the host agent (e.g. OpenCode session ID) */
436
+ /** Actual session ID from the host agent */
166
437
  agentSessionId?: string;
167
438
  /** Agent type used for this session */
168
439
  agentType?: AgentType;
169
440
  /** Current session status */
170
441
  status: SessionStatus;
171
- /** PM-defined label, e.g. "dev-auth-module" */
442
+ /** Coordinator-defined label */
172
443
  label?: string;
173
444
  /** When this session was created */
174
445
  createdAt: string;
@@ -187,7 +458,9 @@ export interface DispatchRecord {
187
458
  taskBrief: string;
188
459
  /** Current dispatch status */
189
460
  status: DispatchStatus;
190
- /** Expected output doc IDs from this dispatch */
461
+ /** Node ID this dispatch is for */
462
+ nodeId?: string;
463
+ /** Expected output artifact IDs from this dispatch */
191
464
  expectedOutputs: string[];
192
465
  /** When this dispatch was created */
193
466
  createdAt: string;
@@ -206,43 +479,32 @@ export interface CapabilityOverride {
206
479
  tool: string;
207
480
  /** MCP server name (required when type is "mcp") */
208
481
  server?: string;
209
- /** Static parameters to always pass when calling the tool */
482
+ /** Static parameters to always pass */
210
483
  params?: Record<string, unknown>;
211
- /** Additional notes for prompt generation (rarely needed) */
484
+ /** Additional notes for prompt generation */
212
485
  notes?: string;
213
486
  }
214
- /** Agent type for spawning team member agents (re-exported from @s_s/agent-kit) */
215
- import type { AgentType } from '@s_s/agent-kit';
216
- export type { AgentType };
217
487
  /** Per-role override configuration */
218
488
  export interface RoleOverride {
219
489
  /** Agent type to use for this role */
220
490
  agent?: AgentType;
221
- /** Model to use for this role (overrides the role's default model level) */
491
+ /** Model to use (overrides role's default) */
222
492
  model?: string;
223
- /** Capability overrides for this role */
493
+ /** Capability overrides */
224
494
  capabilities?: Record<string, CapabilityOverride>;
225
495
  }
226
496
  /**
227
- * Override configuration file structure (<data_dir>/overrides.json or project-level).
228
- *
229
- * review: boolean | Record<docId, boolean>
230
- * - boolean: global toggle for all docs
231
- * - Record: per-doc toggle
232
- *
233
- * roles: Record<roleId, RoleOverride>
234
- * - agent: agent type for spawning
235
- * - model: model override
236
- * - capabilities: Record<capabilityId, CapabilityOverride>
497
+ * Override configuration (project-level only, no global layer).
498
+ * Merges: project-level > workflow defaults.
237
499
  */
238
500
  export interface OverrideConfig {
239
- /** Review overrides — global toggle or per-doc */
501
+ /** Review overrides — global toggle or per-artifact */
240
502
  review?: boolean | Record<string, boolean>;
241
503
  /** Role overrides (agent, model, capabilities) */
242
504
  roles?: Record<string, RoleOverride>;
243
505
  }
244
506
  /** Step completion record */
245
- export interface DocStepRecord {
507
+ export interface ArtifactStepRecord {
246
508
  /** Step ID */
247
509
  stepId: string;
248
510
  /** When this step was completed */
@@ -250,13 +512,13 @@ export interface DocStepRecord {
250
512
  /** File path of the step artifact (relative to project data dir) */
251
513
  artifactPath: string;
252
514
  }
253
- /** Per-doc step tracking state */
254
- export interface DocStepState {
255
- /** Doc ID */
256
- docId: string;
515
+ /** Per-artifact step tracking state */
516
+ export interface ArtifactStepState {
517
+ /** Artifact ID */
518
+ artifactId: string;
257
519
  /** Completed steps (in order) */
258
- completedSteps: DocStepRecord[];
259
- /** Whether the final doc has been written (last step completed + merged) */
520
+ completedSteps: ArtifactStepRecord[];
521
+ /** Whether the final artifact has been written */
260
522
  finalized: boolean;
261
523
  /** Finalized at timestamp */
262
524
  finalizedAt?: string;
@@ -287,3 +549,12 @@ export interface Issue {
287
549
  /** When this issue was closed */
288
550
  closedAt?: string;
289
551
  }
552
+ /** Validation error from workflow validator */
553
+ export interface ValidationError {
554
+ /** Error type */
555
+ type: 'duplicate_id' | 'invalid_goto' | 'cycle' | 'missing_fail_strategy' | 'invalid_floating_ref' | 'invalid_role_ref' | 'invalid_coordinator' | 'invalid_artifact_output' | 'invalid_input_artifact' | 'other';
556
+ /** Human-readable error message */
557
+ message: string;
558
+ /** Node ID where the error was found (if applicable) */
559
+ nodeId?: string;
560
+ }
@@ -1,6 +1,20 @@
1
1
  /**
2
2
  * Core type definitions for Harmonia.
3
- * These types are workflow-agnostic — no hardcoded role names or phase names.
3
+ *
4
+ * Architecture: Core provides composable collaboration primitives.
5
+ * Workflow plugins use these primitives to define specific processes.
6
+ *
7
+ * This file defines:
8
+ * - Workflow node types (task, sequence, parallel, gate, loop)
9
+ * - Workflow state (node-based, not phase-based)
10
+ * - Engine types (nextAction, events, gate evaluation)
11
+ * - Artifact system
12
+ * - Plugin interface
13
+ * - Session & Dispatch tracking
14
+ * - Override configuration (simplified to 2-layer)
15
+ * - Sequential step tracking
16
+ * - Issue tracking
17
+ * - Review state
4
18
  */
5
19
  export {};
6
20
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}