@duypham93/openkit 0.2.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.
- package/.opencode/README.md +47 -0
- package/.opencode/install-manifest.json +41 -0
- package/.opencode/lib/artifact-scaffolder.js +111 -0
- package/.opencode/lib/contract-consistency.js +218 -0
- package/.opencode/lib/parallel-execution-rules.js +261 -0
- package/.opencode/lib/runtime-paths.js +95 -0
- package/.opencode/lib/runtime-summary.js +82 -0
- package/.opencode/lib/state-guard.js +99 -0
- package/.opencode/lib/task-board-rules.js +375 -0
- package/.opencode/lib/work-item-store.js +280 -0
- package/.opencode/lib/workflow-state-controller.js +1739 -0
- package/.opencode/lib/workflow-state-rules.js +331 -0
- package/.opencode/opencode.json +93 -0
- package/.opencode/package.json +3 -0
- package/.opencode/tests/artifact-scaffolder.test.js +733 -0
- package/.opencode/tests/multi-work-item-runtime.test.js +369 -0
- package/.opencode/tests/parallel-execution-runtime.test.js +259 -0
- package/.opencode/tests/session-start-hook.test.js +357 -0
- package/.opencode/tests/state-guard.test.js +124 -0
- package/.opencode/tests/task-board-rules.test.js +204 -0
- package/.opencode/tests/work-item-store.test.js +380 -0
- package/.opencode/tests/workflow-behavior.test.js +149 -0
- package/.opencode/tests/workflow-contract-consistency.test.js +387 -0
- package/.opencode/tests/workflow-state-cli.test.js +1275 -0
- package/.opencode/tests/workflow-state-controller.test.js +1038 -0
- package/.opencode/work-items/feature-001/state.json +70 -0
- package/.opencode/work-items/index.json +13 -0
- package/.opencode/workflow-state.js +489 -0
- package/.opencode/workflow-state.json +70 -0
- package/AGENTS.md +265 -0
- package/README.md +401 -0
- package/agents/architect-agent.md +63 -0
- package/agents/ba-agent.md +56 -0
- package/agents/code-reviewer.md +77 -0
- package/agents/fullstack-agent.md +115 -0
- package/agents/master-orchestrator.md +60 -0
- package/agents/pm-agent.md +56 -0
- package/agents/qa-agent.md +124 -0
- package/agents/tech-lead-agent.md +60 -0
- package/assets/install-bundle/README.md +7 -0
- package/assets/install-bundle/opencode/README.md +11 -0
- package/assets/install-bundle/opencode/agents/ArchitectAgent.md +63 -0
- package/assets/install-bundle/opencode/agents/BAAgent.md +56 -0
- package/assets/install-bundle/opencode/agents/CodeReviewer.md +77 -0
- package/assets/install-bundle/opencode/agents/FullstackAgent.md +115 -0
- package/assets/install-bundle/opencode/agents/MasterOrchestrator.md +60 -0
- package/assets/install-bundle/opencode/agents/PMAgent.md +56 -0
- package/assets/install-bundle/opencode/agents/QAAgent.md +124 -0
- package/assets/install-bundle/opencode/agents/TechLeadAgent.md +60 -0
- package/assets/install-bundle/opencode/commands/brainstorm.md +44 -0
- package/assets/install-bundle/opencode/commands/delivery.md +45 -0
- package/assets/install-bundle/opencode/commands/execute-plan.md +44 -0
- package/assets/install-bundle/opencode/commands/migrate.md +61 -0
- package/assets/install-bundle/opencode/commands/quick-task.md +45 -0
- package/assets/install-bundle/opencode/commands/task.md +46 -0
- package/assets/install-bundle/opencode/commands/write-plan.md +50 -0
- package/assets/install-bundle/opencode/context/core/lane-selection.md +54 -0
- package/assets/install-bundle/opencode/skills/brainstorming/SKILL.md +51 -0
- package/assets/install-bundle/opencode/skills/code-review/SKILL.md +48 -0
- package/assets/install-bundle/opencode/skills/subagent-driven-development/SKILL.md +79 -0
- package/assets/install-bundle/opencode/skills/systematic-debugging/SKILL.md +61 -0
- package/assets/install-bundle/opencode/skills/test-driven-development/SKILL.md +48 -0
- package/assets/install-bundle/opencode/skills/using-skills/SKILL.md +39 -0
- package/assets/install-bundle/opencode/skills/verification-before-completion/SKILL.md +137 -0
- package/assets/install-bundle/opencode/skills/writing-plans/SKILL.md +68 -0
- package/assets/install-bundle/opencode/skills/writing-specs/SKILL.md +47 -0
- package/assets/opencode.json.template +11 -0
- package/assets/openkit-install.json.template +19 -0
- package/bin/openkit.js +9 -0
- package/commands/brainstorm.md +44 -0
- package/commands/delivery.md +45 -0
- package/commands/execute-plan.md +44 -0
- package/commands/migrate.md +61 -0
- package/commands/quick-task.md +45 -0
- package/commands/task.md +46 -0
- package/commands/write-plan.md +50 -0
- package/context/core/approval-gates.md +146 -0
- package/context/core/code-quality.md +42 -0
- package/context/core/issue-routing.md +85 -0
- package/context/core/lane-selection.md +54 -0
- package/context/core/project-config.md +143 -0
- package/context/core/session-resume.md +85 -0
- package/context/core/workflow-state-schema.md +224 -0
- package/context/core/workflow.md +442 -0
- package/context/navigation.md +94 -0
- package/docs/adr/README.md +6 -0
- package/docs/architecture/2026-03-20-task-intake-dashboard.md +54 -0
- package/docs/architecture/README.md +7 -0
- package/docs/briefs/2026-03-20-task-intake-dashboard.md +48 -0
- package/docs/briefs/README.md +7 -0
- package/docs/governance/README.md +25 -0
- package/docs/governance/adr-policy.md +27 -0
- package/docs/governance/definition-of-done.md +17 -0
- package/docs/governance/naming-conventions.md +21 -0
- package/docs/governance/severity-levels.md +12 -0
- package/docs/maintainer/README.md +51 -0
- package/docs/operations/README.md +79 -0
- package/docs/operations/internal-records/2026-03-24-release-checklist.md +79 -0
- package/docs/operations/internal-records/2026-03-24-simplified-install-ux.md +36 -0
- package/docs/operations/internal-records/README.md +18 -0
- package/docs/operations/runbooks/README.md +23 -0
- package/docs/operations/runbooks/openkit-daily-usage.md +288 -0
- package/docs/operations/runbooks/workflow-state-smoke-tests.md +302 -0
- package/docs/operator/README.md +50 -0
- package/docs/plans/2026-03-20-task-intake-dashboard.md +49 -0
- package/docs/plans/2026-03-21-openkit-full-delivery-multi-task-runtime.md +521 -0
- package/docs/plans/2026-03-23-openkit-global-install-runtime.md +157 -0
- package/docs/plans/README.md +7 -0
- package/docs/qa/2026-03-20-task-intake-dashboard.md +41 -0
- package/docs/qa/README.md +7 -0
- package/docs/specs/2026-03-20-task-intake-dashboard.md +50 -0
- package/docs/specs/2026-03-21-openkit-full-delivery-multi-task-runtime.md +462 -0
- package/docs/specs/README.md +7 -0
- package/docs/templates/README.md +36 -0
- package/docs/templates/adr-template.md +18 -0
- package/docs/templates/architecture-template.md +31 -0
- package/docs/templates/implementation-plan-template.md +32 -0
- package/docs/templates/migration-baseline-checklist.md +48 -0
- package/docs/templates/migration-plan-template.md +52 -0
- package/docs/templates/migration-report-template.md +74 -0
- package/docs/templates/migration-verify-checklist.md +39 -0
- package/docs/templates/product-brief-template.md +32 -0
- package/docs/templates/qa-report-template.md +37 -0
- package/docs/templates/quick-task-template.md +36 -0
- package/docs/templates/spec-template.md +31 -0
- package/hooks/hooks.json +16 -0
- package/hooks/session-start +162 -0
- package/package.json +24 -0
- package/registry.json +328 -0
- package/skills/brainstorming/SKILL.md +51 -0
- package/skills/code-review/SKILL.md +48 -0
- package/skills/subagent-driven-development/SKILL.md +79 -0
- package/skills/systematic-debugging/SKILL.md +61 -0
- package/skills/test-driven-development/SKILL.md +48 -0
- package/skills/using-skills/SKILL.md +39 -0
- package/skills/verification-before-completion/SKILL.md +137 -0
- package/skills/writing-plans/SKILL.md +68 -0
- package/skills/writing-specs/SKILL.md +47 -0
- package/src/audit/vietnamese-detection.js +259 -0
- package/src/cli/commands/detect-vietnamese.js +24 -0
- package/src/cli/commands/doctor.js +33 -0
- package/src/cli/commands/help.js +33 -0
- package/src/cli/commands/init.js +25 -0
- package/src/cli/commands/install-global.js +26 -0
- package/src/cli/commands/install.js +25 -0
- package/src/cli/commands/run.js +63 -0
- package/src/cli/commands/uninstall.js +32 -0
- package/src/cli/commands/upgrade.js +25 -0
- package/src/cli/conflict-output.js +19 -0
- package/src/cli/index.js +56 -0
- package/src/global/doctor.js +101 -0
- package/src/global/ensure-install.js +32 -0
- package/src/global/install-state.js +73 -0
- package/src/global/launcher.js +51 -0
- package/src/global/materialize.js +123 -0
- package/src/global/paths.js +85 -0
- package/src/global/uninstall.js +25 -0
- package/src/global/workspace-state.js +63 -0
- package/src/install/asset-manifest.js +284 -0
- package/src/install/conflicts.js +43 -0
- package/src/install/discovery.js +138 -0
- package/src/install/install-state.js +136 -0
- package/src/install/materialize.js +158 -0
- package/src/install/merge-policy.js +145 -0
- package/src/runtime/doctor.js +281 -0
- package/src/runtime/launcher.js +49 -0
- package/src/runtime/opencode-layering.js +135 -0
- package/src/runtime/openkit-managed-summary.js +27 -0
- package/tests/cli/openkit-cli.test.js +417 -0
- package/tests/global/doctor.test.js +130 -0
- package/tests/global/ensure-install.test.js +105 -0
- package/tests/install/discovery.test.js +124 -0
- package/tests/install/install-state.test.js +346 -0
- package/tests/install/materialize.test.js +244 -0
- package/tests/install/merge-policy.test.js +177 -0
- package/tests/runtime/doctor.test.js +430 -0
- package/tests/runtime/launcher.test.js +230 -0
- package/tests/runtime/module-boundary.test.js +16 -0
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
const test = require("node:test")
|
|
2
|
+
const assert = require("node:assert/strict")
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const os = require("os")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
bootstrapLegacyWorkflowState,
|
|
9
|
+
deriveWorkItemId,
|
|
10
|
+
readWorkItemIndex,
|
|
11
|
+
readWorkItemState,
|
|
12
|
+
refreshCompatibilityMirror,
|
|
13
|
+
resolveWorkItemPaths,
|
|
14
|
+
setActiveWorkItem,
|
|
15
|
+
validateActiveMirror,
|
|
16
|
+
writeWorkItemIndex,
|
|
17
|
+
writeWorkItemState,
|
|
18
|
+
} = require("../lib/work-item-store")
|
|
19
|
+
|
|
20
|
+
function makeTempProject() {
|
|
21
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), "openkit-work-item-store-"))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createFixtureState(overrides = {}) {
|
|
25
|
+
return {
|
|
26
|
+
feature_id: "FEATURE-001",
|
|
27
|
+
feature_slug: "task-intake-dashboard",
|
|
28
|
+
mode: "full",
|
|
29
|
+
mode_reason: "Feature-sized workflow example with full artifact chain and approvals",
|
|
30
|
+
routing_profile: {
|
|
31
|
+
work_intent: "feature",
|
|
32
|
+
behavior_delta: "extend",
|
|
33
|
+
dominant_uncertainty: "product",
|
|
34
|
+
scope_shape: "cross_boundary",
|
|
35
|
+
selection_reason: "Feature-sized workflow example with full artifact chain and approvals",
|
|
36
|
+
},
|
|
37
|
+
current_stage: "full_done",
|
|
38
|
+
status: "done",
|
|
39
|
+
current_owner: "MasterOrchestrator",
|
|
40
|
+
artifacts: {
|
|
41
|
+
task_card: null,
|
|
42
|
+
brief: "docs/briefs/2026-03-20-task-intake-dashboard.md",
|
|
43
|
+
spec: "docs/specs/2026-03-20-task-intake-dashboard.md",
|
|
44
|
+
architecture: "docs/architecture/2026-03-20-task-intake-dashboard.md",
|
|
45
|
+
plan: "docs/plans/2026-03-20-task-intake-dashboard.md",
|
|
46
|
+
migration_report: null,
|
|
47
|
+
qa_report: "docs/qa/2026-03-20-task-intake-dashboard.md",
|
|
48
|
+
adr: [],
|
|
49
|
+
},
|
|
50
|
+
approvals: {
|
|
51
|
+
pm_to_ba: { status: "approved", approved_by: "user", approved_at: "2026-03-20", notes: null },
|
|
52
|
+
ba_to_architect: { status: "approved", approved_by: "user", approved_at: "2026-03-20", notes: null },
|
|
53
|
+
architect_to_tech_lead: { status: "approved", approved_by: "user", approved_at: "2026-03-20", notes: null },
|
|
54
|
+
tech_lead_to_fullstack: { status: "approved", approved_by: "user", approved_at: "2026-03-20", notes: null },
|
|
55
|
+
fullstack_to_qa: { status: "approved", approved_by: "system", approved_at: "2026-03-20", notes: null },
|
|
56
|
+
qa_to_done: { status: "approved", approved_by: "user", approved_at: "2026-03-20", notes: null },
|
|
57
|
+
},
|
|
58
|
+
issues: [],
|
|
59
|
+
retry_count: 0,
|
|
60
|
+
escalated_from: null,
|
|
61
|
+
escalation_reason: null,
|
|
62
|
+
updated_at: "2026-03-20",
|
|
63
|
+
...overrides,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function setupLegacyState(projectRoot, overrides = {}) {
|
|
68
|
+
const opencodeDir = path.join(projectRoot, ".opencode")
|
|
69
|
+
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
70
|
+
|
|
71
|
+
const state = createFixtureState(overrides)
|
|
72
|
+
const statePath = path.join(opencodeDir, "workflow-state.json")
|
|
73
|
+
fs.writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`, "utf8")
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
state,
|
|
77
|
+
statePath,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test("deriveWorkItemId uses a persisted id when present and otherwise derives a stable slug from feature_id", () => {
|
|
82
|
+
assert.equal(deriveWorkItemId({ work_item_id: "existing-item", feature_id: "FEATURE-001" }), "existing-item")
|
|
83
|
+
assert.equal(deriveWorkItemId({ feature_id: "FEATURE-001" }), "feature-001")
|
|
84
|
+
assert.equal(deriveWorkItemId({ feature_id: "Feature 001 / Alpha" }), "feature-001-alpha")
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test("bootstrapLegacyWorkflowState creates index and per-item state from the compatibility file without duplicates", () => {
|
|
88
|
+
const projectRoot = makeTempProject()
|
|
89
|
+
const { state } = setupLegacyState(projectRoot)
|
|
90
|
+
|
|
91
|
+
const firstResult = bootstrapLegacyWorkflowState(projectRoot)
|
|
92
|
+
const secondResult = bootstrapLegacyWorkflowState(projectRoot)
|
|
93
|
+
|
|
94
|
+
assert.equal(firstResult.workItemId, "feature-001")
|
|
95
|
+
assert.equal(secondResult.workItemId, "feature-001")
|
|
96
|
+
|
|
97
|
+
const index = readWorkItemIndex(projectRoot)
|
|
98
|
+
assert.equal(index.active_work_item_id, "feature-001")
|
|
99
|
+
assert.equal(index.work_items.length, 1)
|
|
100
|
+
assert.deepEqual(index.work_items[0], {
|
|
101
|
+
work_item_id: "feature-001",
|
|
102
|
+
feature_id: state.feature_id,
|
|
103
|
+
feature_slug: state.feature_slug,
|
|
104
|
+
mode: state.mode,
|
|
105
|
+
status: state.status,
|
|
106
|
+
state_path: ".opencode/work-items/feature-001/state.json",
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const perItemState = readWorkItemState(projectRoot, "feature-001")
|
|
110
|
+
assert.equal(perItemState.work_item_id, "feature-001")
|
|
111
|
+
assert.equal(perItemState.feature_id, state.feature_id)
|
|
112
|
+
|
|
113
|
+
const mirrorState = JSON.parse(
|
|
114
|
+
fs.readFileSync(path.join(projectRoot, ".opencode", "workflow-state.json"), "utf8"),
|
|
115
|
+
)
|
|
116
|
+
assert.equal(mirrorState.work_item_id, "feature-001")
|
|
117
|
+
assert.deepEqual(mirrorState, perItemState)
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
test("readWorkItemIndex and writeWorkItemIndex round-trip the minimal index shape", () => {
|
|
121
|
+
const projectRoot = makeTempProject()
|
|
122
|
+
|
|
123
|
+
writeWorkItemIndex(projectRoot, {
|
|
124
|
+
active_work_item_id: "feature-900",
|
|
125
|
+
work_items: [
|
|
126
|
+
{
|
|
127
|
+
work_item_id: "feature-900",
|
|
128
|
+
feature_id: "FEATURE-900",
|
|
129
|
+
feature_slug: "runtime-updates",
|
|
130
|
+
mode: "full",
|
|
131
|
+
status: "in_progress",
|
|
132
|
+
state_path: ".opencode/work-items/feature-900/state.json",
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
assert.deepEqual(readWorkItemIndex(projectRoot), {
|
|
138
|
+
active_work_item_id: "feature-900",
|
|
139
|
+
work_items: [
|
|
140
|
+
{
|
|
141
|
+
work_item_id: "feature-900",
|
|
142
|
+
feature_id: "FEATURE-900",
|
|
143
|
+
feature_slug: "runtime-updates",
|
|
144
|
+
mode: "full",
|
|
145
|
+
status: "in_progress",
|
|
146
|
+
state_path: ".opencode/work-items/feature-900/state.json",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
})
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test("readWorkItemState and writeWorkItemState round-trip one work item state file", () => {
|
|
153
|
+
const projectRoot = makeTempProject()
|
|
154
|
+
const state = createFixtureState({
|
|
155
|
+
work_item_id: "feature-777",
|
|
156
|
+
feature_id: "FEATURE-777",
|
|
157
|
+
feature_slug: "isolated-store-helper",
|
|
158
|
+
status: "in_progress",
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
writeWorkItemState(projectRoot, "feature-777", state)
|
|
162
|
+
|
|
163
|
+
const persistedState = readWorkItemState(projectRoot, "feature-777")
|
|
164
|
+
assert.deepEqual(persistedState, state)
|
|
165
|
+
|
|
166
|
+
const paths = resolveWorkItemPaths(projectRoot, "feature-777")
|
|
167
|
+
assert.equal(fs.existsSync(paths.statePath), true)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test("writeWorkItemState persists the stable work_item_id for general state writes", () => {
|
|
171
|
+
const projectRoot = makeTempProject()
|
|
172
|
+
|
|
173
|
+
writeWorkItemState(projectRoot, "feature-888", createFixtureState({
|
|
174
|
+
feature_id: "FEATURE-888",
|
|
175
|
+
feature_slug: "stable-id-write",
|
|
176
|
+
status: "in_progress",
|
|
177
|
+
}))
|
|
178
|
+
|
|
179
|
+
const persistedState = readWorkItemState(projectRoot, "feature-888")
|
|
180
|
+
assert.equal(persistedState.work_item_id, "feature-888")
|
|
181
|
+
assert.equal(persistedState.feature_id, "FEATURE-888")
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
test("setActiveWorkItem updates the active pointer independently of mirror refresh", () => {
|
|
185
|
+
const projectRoot = makeTempProject()
|
|
186
|
+
setupLegacyState(projectRoot)
|
|
187
|
+
bootstrapLegacyWorkflowState(projectRoot)
|
|
188
|
+
|
|
189
|
+
writeWorkItemState(projectRoot, "feature-002", createFixtureState({
|
|
190
|
+
work_item_id: "feature-002",
|
|
191
|
+
feature_id: "FEATURE-002",
|
|
192
|
+
feature_slug: "parallel-runtime",
|
|
193
|
+
status: "in_progress",
|
|
194
|
+
}))
|
|
195
|
+
writeWorkItemIndex(projectRoot, {
|
|
196
|
+
active_work_item_id: "feature-001",
|
|
197
|
+
work_items: [
|
|
198
|
+
{
|
|
199
|
+
work_item_id: "feature-001",
|
|
200
|
+
feature_id: "FEATURE-001",
|
|
201
|
+
feature_slug: "task-intake-dashboard",
|
|
202
|
+
mode: "full",
|
|
203
|
+
status: "done",
|
|
204
|
+
state_path: ".opencode/work-items/feature-001/state.json",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
work_item_id: "feature-002",
|
|
208
|
+
feature_id: "FEATURE-002",
|
|
209
|
+
feature_slug: "parallel-runtime",
|
|
210
|
+
mode: "full",
|
|
211
|
+
status: "in_progress",
|
|
212
|
+
state_path: ".opencode/work-items/feature-002/state.json",
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
setActiveWorkItem(projectRoot, "feature-002")
|
|
218
|
+
|
|
219
|
+
const index = readWorkItemIndex(projectRoot)
|
|
220
|
+
const mirrorState = JSON.parse(
|
|
221
|
+
fs.readFileSync(path.join(projectRoot, ".opencode", "workflow-state.json"), "utf8"),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
assert.equal(index.active_work_item_id, "feature-002")
|
|
225
|
+
assert.equal(mirrorState.work_item_id, "feature-001")
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
test("setActiveWorkItem rejects an index entry whose state file is missing", () => {
|
|
229
|
+
const projectRoot = makeTempProject()
|
|
230
|
+
setupLegacyState(projectRoot)
|
|
231
|
+
bootstrapLegacyWorkflowState(projectRoot)
|
|
232
|
+
|
|
233
|
+
writeWorkItemIndex(projectRoot, {
|
|
234
|
+
active_work_item_id: "feature-001",
|
|
235
|
+
work_items: [
|
|
236
|
+
{
|
|
237
|
+
work_item_id: "feature-001",
|
|
238
|
+
feature_id: "FEATURE-001",
|
|
239
|
+
feature_slug: "task-intake-dashboard",
|
|
240
|
+
mode: "full",
|
|
241
|
+
status: "done",
|
|
242
|
+
state_path: ".opencode/work-items/feature-001/state.json",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
work_item_id: "feature-404",
|
|
246
|
+
feature_id: "FEATURE-404",
|
|
247
|
+
feature_slug: "missing-state",
|
|
248
|
+
mode: "full",
|
|
249
|
+
status: "in_progress",
|
|
250
|
+
state_path: ".opencode/work-items/feature-404/state.json",
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
assert.throws(() => setActiveWorkItem(projectRoot, "feature-404"), /Work-item state missing/)
|
|
256
|
+
assert.equal(readWorkItemIndex(projectRoot).active_work_item_id, "feature-001")
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test("refreshCompatibilityMirror writes from the active per-item state and validateActiveMirror reports stale or missing mirrors", () => {
|
|
260
|
+
const projectRoot = makeTempProject()
|
|
261
|
+
setupLegacyState(projectRoot)
|
|
262
|
+
bootstrapLegacyWorkflowState(projectRoot)
|
|
263
|
+
|
|
264
|
+
writeWorkItemState(projectRoot, "feature-001", createFixtureState({
|
|
265
|
+
work_item_id: "feature-001",
|
|
266
|
+
feature_id: "FEATURE-001",
|
|
267
|
+
feature_slug: "task-intake-dashboard",
|
|
268
|
+
status: "in_progress",
|
|
269
|
+
updated_at: "2026-03-21",
|
|
270
|
+
}))
|
|
271
|
+
|
|
272
|
+
assert.throws(() => validateActiveMirror(projectRoot), /Compatibility mirror diverged/)
|
|
273
|
+
|
|
274
|
+
refreshCompatibilityMirror(projectRoot)
|
|
275
|
+
assert.doesNotThrow(() => validateActiveMirror(projectRoot))
|
|
276
|
+
|
|
277
|
+
fs.rmSync(path.join(projectRoot, ".opencode", "workflow-state.json"))
|
|
278
|
+
assert.throws(() => validateActiveMirror(projectRoot), /Compatibility mirror missing/)
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
test("validateActiveMirror accepts reordered but semantically equivalent JSON content", () => {
|
|
282
|
+
const projectRoot = makeTempProject()
|
|
283
|
+
setupLegacyState(projectRoot)
|
|
284
|
+
bootstrapLegacyWorkflowState(projectRoot)
|
|
285
|
+
|
|
286
|
+
const activeState = readWorkItemState(projectRoot, "feature-001")
|
|
287
|
+
const reorderedMirrorState = {
|
|
288
|
+
updated_at: activeState.updated_at,
|
|
289
|
+
escalation_reason: activeState.escalation_reason,
|
|
290
|
+
escalated_from: activeState.escalated_from,
|
|
291
|
+
retry_count: activeState.retry_count,
|
|
292
|
+
issues: activeState.issues,
|
|
293
|
+
approvals: {
|
|
294
|
+
qa_to_done: activeState.approvals.qa_to_done,
|
|
295
|
+
fullstack_to_qa: activeState.approvals.fullstack_to_qa,
|
|
296
|
+
tech_lead_to_fullstack: activeState.approvals.tech_lead_to_fullstack,
|
|
297
|
+
architect_to_tech_lead: activeState.approvals.architect_to_tech_lead,
|
|
298
|
+
ba_to_architect: activeState.approvals.ba_to_architect,
|
|
299
|
+
pm_to_ba: activeState.approvals.pm_to_ba,
|
|
300
|
+
},
|
|
301
|
+
artifacts: {
|
|
302
|
+
adr: activeState.artifacts.adr,
|
|
303
|
+
qa_report: activeState.artifacts.qa_report,
|
|
304
|
+
migration_report: activeState.artifacts.migration_report,
|
|
305
|
+
plan: activeState.artifacts.plan,
|
|
306
|
+
architecture: activeState.artifacts.architecture,
|
|
307
|
+
spec: activeState.artifacts.spec,
|
|
308
|
+
brief: activeState.artifacts.brief,
|
|
309
|
+
task_card: activeState.artifacts.task_card,
|
|
310
|
+
},
|
|
311
|
+
current_owner: activeState.current_owner,
|
|
312
|
+
status: activeState.status,
|
|
313
|
+
current_stage: activeState.current_stage,
|
|
314
|
+
routing_profile: {
|
|
315
|
+
selection_reason: activeState.routing_profile.selection_reason,
|
|
316
|
+
scope_shape: activeState.routing_profile.scope_shape,
|
|
317
|
+
dominant_uncertainty: activeState.routing_profile.dominant_uncertainty,
|
|
318
|
+
behavior_delta: activeState.routing_profile.behavior_delta,
|
|
319
|
+
work_intent: activeState.routing_profile.work_intent,
|
|
320
|
+
},
|
|
321
|
+
mode_reason: activeState.mode_reason,
|
|
322
|
+
mode: activeState.mode,
|
|
323
|
+
feature_slug: activeState.feature_slug,
|
|
324
|
+
feature_id: activeState.feature_id,
|
|
325
|
+
work_item_id: activeState.work_item_id,
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
fs.writeFileSync(
|
|
329
|
+
path.join(projectRoot, ".opencode", "workflow-state.json"),
|
|
330
|
+
`${JSON.stringify(reorderedMirrorState, null, 2)}\n`,
|
|
331
|
+
"utf8",
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
assert.doesNotThrow(() => validateActiveMirror(projectRoot))
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
test("activating a different work item and refreshing the mirror rewrites compatibility state from the new active item", () => {
|
|
338
|
+
const projectRoot = makeTempProject()
|
|
339
|
+
setupLegacyState(projectRoot)
|
|
340
|
+
bootstrapLegacyWorkflowState(projectRoot)
|
|
341
|
+
|
|
342
|
+
writeWorkItemState(projectRoot, "feature-002", createFixtureState({
|
|
343
|
+
feature_id: "FEATURE-002",
|
|
344
|
+
feature_slug: "parallel-runtime",
|
|
345
|
+
status: "in_progress",
|
|
346
|
+
updated_at: "2026-03-21",
|
|
347
|
+
}))
|
|
348
|
+
writeWorkItemIndex(projectRoot, {
|
|
349
|
+
active_work_item_id: "feature-001",
|
|
350
|
+
work_items: [
|
|
351
|
+
{
|
|
352
|
+
work_item_id: "feature-001",
|
|
353
|
+
feature_id: "FEATURE-001",
|
|
354
|
+
feature_slug: "task-intake-dashboard",
|
|
355
|
+
mode: "full",
|
|
356
|
+
status: "done",
|
|
357
|
+
state_path: ".opencode/work-items/feature-001/state.json",
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
work_item_id: "feature-002",
|
|
361
|
+
feature_id: "FEATURE-002",
|
|
362
|
+
feature_slug: "parallel-runtime",
|
|
363
|
+
mode: "full",
|
|
364
|
+
status: "in_progress",
|
|
365
|
+
state_path: ".opencode/work-items/feature-002/state.json",
|
|
366
|
+
},
|
|
367
|
+
],
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
setActiveWorkItem(projectRoot, "feature-002")
|
|
371
|
+
refreshCompatibilityMirror(projectRoot)
|
|
372
|
+
|
|
373
|
+
const mirrorState = JSON.parse(
|
|
374
|
+
fs.readFileSync(path.join(projectRoot, ".opencode", "workflow-state.json"), "utf8"),
|
|
375
|
+
)
|
|
376
|
+
assert.equal(mirrorState.work_item_id, "feature-002")
|
|
377
|
+
assert.equal(mirrorState.feature_id, "FEATURE-002")
|
|
378
|
+
assert.equal(mirrorState.feature_slug, "parallel-runtime")
|
|
379
|
+
assert.equal(mirrorState.updated_at, "2026-03-21")
|
|
380
|
+
})
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const test = require("node:test")
|
|
2
|
+
const assert = require("node:assert/strict")
|
|
3
|
+
const fs = require("fs")
|
|
4
|
+
const os = require("os")
|
|
5
|
+
const path = require("path")
|
|
6
|
+
const { spawnSync } = require("child_process")
|
|
7
|
+
|
|
8
|
+
const {
|
|
9
|
+
advanceStage,
|
|
10
|
+
routeRework,
|
|
11
|
+
startTask,
|
|
12
|
+
validateState,
|
|
13
|
+
} = require("../lib/workflow-state-controller")
|
|
14
|
+
|
|
15
|
+
function makeTempDir() {
|
|
16
|
+
return fs.mkdtempSync(path.join(os.tmpdir(), "openkit-workflow-behavior-"))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function loadFixtureState() {
|
|
20
|
+
const fixturePath = path.resolve(__dirname, "../workflow-state.json")
|
|
21
|
+
return JSON.parse(fs.readFileSync(fixturePath, "utf8"))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createTempStateFile() {
|
|
25
|
+
const dir = makeTempDir()
|
|
26
|
+
const opencodeDir = path.join(dir, ".opencode")
|
|
27
|
+
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
28
|
+
const statePath = path.join(opencodeDir, "workflow-state.json")
|
|
29
|
+
fs.writeFileSync(statePath, `${JSON.stringify(loadFixtureState(), null, 2)}\n`, "utf8")
|
|
30
|
+
return statePath
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function writeManifest(projectRoot) {
|
|
34
|
+
const opencodeDir = path.join(projectRoot, ".opencode")
|
|
35
|
+
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
36
|
+
fs.writeFileSync(
|
|
37
|
+
path.join(opencodeDir, "opencode.json"),
|
|
38
|
+
`${JSON.stringify({
|
|
39
|
+
kit: {
|
|
40
|
+
name: "OpenKit AI Software Factory",
|
|
41
|
+
version: "0.1.0",
|
|
42
|
+
entryAgent: "MasterOrchestrator",
|
|
43
|
+
},
|
|
44
|
+
}, null, 2)}\n`,
|
|
45
|
+
"utf8",
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
test("quick requirement gaps escalate to full_intake with full-mode approvals", () => {
|
|
50
|
+
const statePath = createTempStateFile()
|
|
51
|
+
|
|
52
|
+
startTask("quick", "TASK-300", "needs-clarification", "Started as a bounded quick task", statePath)
|
|
53
|
+
const result = routeRework("requirement_gap", false, statePath)
|
|
54
|
+
|
|
55
|
+
assert.equal(result.state.mode, "full")
|
|
56
|
+
assert.equal(result.state.current_stage, "full_intake")
|
|
57
|
+
assert.equal(result.state.current_owner, "MasterOrchestrator")
|
|
58
|
+
assert.equal(result.state.escalated_from, "quick")
|
|
59
|
+
assert.match(result.state.escalation_reason, /requirement_gap/)
|
|
60
|
+
assert.equal(Object.hasOwn(result.state.approvals, "quick_verified"), false)
|
|
61
|
+
assert.equal(result.state.approvals.pm_to_ba.status, "pending")
|
|
62
|
+
assert.equal(result.state.approvals.qa_to_done.status, "pending")
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("quick stage advancement preserves the canonical owner chain", () => {
|
|
66
|
+
const statePath = createTempStateFile()
|
|
67
|
+
|
|
68
|
+
startTask("quick", "TASK-301", "owner-chain", "Follow quick-stage ownership", statePath)
|
|
69
|
+
let result = validateState(statePath)
|
|
70
|
+
assert.equal(result.state.current_stage, "quick_intake")
|
|
71
|
+
assert.equal(result.state.current_owner, "MasterOrchestrator")
|
|
72
|
+
|
|
73
|
+
result = advanceStage("quick_plan", statePath)
|
|
74
|
+
assert.equal(result.state.current_stage, "quick_plan")
|
|
75
|
+
assert.equal(result.state.current_owner, "MasterOrchestrator")
|
|
76
|
+
|
|
77
|
+
result = advanceStage("quick_build", statePath)
|
|
78
|
+
assert.equal(result.state.current_stage, "quick_build")
|
|
79
|
+
assert.equal(result.state.current_owner, "FullstackAgent")
|
|
80
|
+
|
|
81
|
+
result = advanceStage("quick_verify", statePath)
|
|
82
|
+
assert.equal(result.state.current_stage, "quick_verify")
|
|
83
|
+
assert.equal(result.state.current_owner, "QAAgent")
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test("full workflows start in full_intake with full-mode state", () => {
|
|
87
|
+
const statePath = createTempStateFile()
|
|
88
|
+
|
|
89
|
+
startTask("full", "FEATURE-301", "full-workflow", "Feature-sized workflow", statePath)
|
|
90
|
+
const result = validateState(statePath)
|
|
91
|
+
|
|
92
|
+
assert.equal(result.state.mode, "full")
|
|
93
|
+
assert.equal(result.state.current_stage, "full_intake")
|
|
94
|
+
assert.notEqual(result.state.current_stage, "quick_intake")
|
|
95
|
+
assert.equal(result.state.escalated_from, null)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test("migration workflows start in migration_intake with migration-mode state", () => {
|
|
99
|
+
const statePath = createTempStateFile()
|
|
100
|
+
|
|
101
|
+
startTask("migration", "MIGRATE-301", "react-refresh", "Framework upgrade workflow", statePath)
|
|
102
|
+
const result = validateState(statePath)
|
|
103
|
+
|
|
104
|
+
assert.equal(result.state.mode, "migration")
|
|
105
|
+
assert.equal(result.state.current_stage, "migration_intake")
|
|
106
|
+
assert.notEqual(result.state.current_stage, "quick_intake")
|
|
107
|
+
assert.notEqual(result.state.current_stage, "full_intake")
|
|
108
|
+
assert.equal(result.state.escalated_from, null)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
test("session-start resume hints stay aligned with full stage names", () => {
|
|
112
|
+
const projectRoot = makeTempDir()
|
|
113
|
+
const opencodeDir = path.join(projectRoot, ".opencode")
|
|
114
|
+
fs.mkdirSync(opencodeDir, { recursive: true })
|
|
115
|
+
writeManifest(projectRoot)
|
|
116
|
+
|
|
117
|
+
const state = loadFixtureState()
|
|
118
|
+
state.feature_id = "FEATURE-302"
|
|
119
|
+
state.feature_slug = "full-qa-resume"
|
|
120
|
+
state.mode = "full"
|
|
121
|
+
state.routing_profile = {
|
|
122
|
+
work_intent: "feature",
|
|
123
|
+
behavior_delta: "extend",
|
|
124
|
+
dominant_uncertainty: "product",
|
|
125
|
+
scope_shape: "cross_boundary",
|
|
126
|
+
selection_reason: "full qa resume",
|
|
127
|
+
}
|
|
128
|
+
state.current_stage = "full_qa"
|
|
129
|
+
state.current_owner = "QAAgent"
|
|
130
|
+
state.status = "in_progress"
|
|
131
|
+
fs.writeFileSync(path.join(opencodeDir, "workflow-state.json"), `${JSON.stringify(state, null, 2)}\n`, "utf8")
|
|
132
|
+
|
|
133
|
+
const result = spawnSync(path.resolve(__dirname, "../../hooks/session-start"), {
|
|
134
|
+
cwd: projectRoot,
|
|
135
|
+
encoding: "utf8",
|
|
136
|
+
env: {
|
|
137
|
+
...process.env,
|
|
138
|
+
OPENKIT_PROJECT_ROOT: projectRoot,
|
|
139
|
+
OPENKIT_SESSION_START_NO_SKILL: "1",
|
|
140
|
+
OPENKIT_WORKFLOW_STATE: path.join(projectRoot, ".opencode", "workflow-state.json"),
|
|
141
|
+
},
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
assert.equal(result.status, 0)
|
|
145
|
+
assert.match(result.stdout, /mode: full/)
|
|
146
|
+
assert.match(result.stdout, /stage: full_qa/)
|
|
147
|
+
assert.match(result.stdout, /owner: QAAgent/)
|
|
148
|
+
assert.match(result.stdout, /work item: FEATURE-302 \(full-qa-resume\)/)
|
|
149
|
+
})
|