@jakkrichm/create-nexus-devflow 2.16.4 → 2.17.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 (97) hide show
  1. package/dist/bin/create-nexus-devflow.d.ts +1 -1
  2. package/dist/bin/create-nexus-devflow.js +77 -4
  3. package/dist/bin/create-nexus-devflow.js.map +1 -1
  4. package/dist/lib/doctor.js +2 -1
  5. package/dist/lib/doctor.js.map +1 -1
  6. package/dist/lib/project-config.js +2 -1
  7. package/dist/lib/project-config.js.map +1 -1
  8. package/dist/lib/project-status-engine.d.ts +11 -3
  9. package/dist/lib/project-status-engine.js +99 -17
  10. package/dist/lib/project-status-engine.js.map +1 -1
  11. package/dist/lib/review.d.ts +1 -0
  12. package/dist/lib/review.js +58 -3
  13. package/dist/lib/review.js.map +1 -1
  14. package/dist/lib/skill-registry-engine.js +1 -1
  15. package/dist/lib/skill-registry-engine.js.map +1 -1
  16. package/dist/lib/status.d.ts +3 -3
  17. package/dist/lib/status.js +2 -2
  18. package/dist/lib/status.js.map +1 -1
  19. package/dist/lib/tooling/commands/migrate-structure.d.ts +8 -0
  20. package/dist/lib/tooling/commands/migrate-structure.js +200 -0
  21. package/dist/lib/tooling/commands/migrate-structure.js.map +1 -0
  22. package/dist/lib/tooling/commands/summarize-run-status.js +3 -1
  23. package/dist/lib/tooling/commands/summarize-run-status.js.map +1 -1
  24. package/dist/lib/tooling/registry.js +2 -0
  25. package/dist/lib/tooling/registry.js.map +1 -1
  26. package/dist/lib/update.d.ts +34 -3
  27. package/dist/lib/update.js +142 -1
  28. package/dist/lib/update.js.map +1 -1
  29. package/dist/lib/workspace-paths.d.ts +16 -0
  30. package/dist/lib/workspace-paths.js +85 -0
  31. package/dist/lib/workspace-paths.js.map +1 -0
  32. package/dist/scripts/prepare-template.js +75 -15
  33. package/dist/scripts/prepare-template.js.map +1 -1
  34. package/package.json +1 -1
  35. package/template/.agents/skills/analyze/SKILL.md +21 -21
  36. package/template/.agents/skills/audit/SKILL.md +36 -18
  37. package/template/.agents/skills/audit/reference/independent-review.md +58 -2
  38. package/template/.agents/skills/brainstorm/SKILL.md +1 -1
  39. package/template/.agents/skills/complete/SKILL.md +23 -1
  40. package/template/.agents/skills/complete/reference/completion-recovery.md +248 -0
  41. package/template/.agents/skills/continuous/SKILL.md +156 -82
  42. package/template/.agents/skills/feature/SKILL.md +6 -0
  43. package/template/.agents/skills/feature/reference/build-history.md +79 -0
  44. package/template/.agents/skills/idea/SKILL.md +14 -14
  45. package/template/.agents/skills/rollback/SKILL.md +23 -10
  46. package/template/.claude/skills/analyze/SKILL.md +21 -21
  47. package/template/.claude/skills/audit/SKILL.md +33 -16
  48. package/template/.claude/skills/audit/reference/independent-review.md +58 -2
  49. package/template/.claude/skills/brainstorm/SKILL.md +1 -1
  50. package/template/.claude/skills/complete/SKILL.md +23 -1
  51. package/template/.claude/skills/complete/reference/completion-recovery.md +248 -0
  52. package/template/.claude/skills/continuous/SKILL.md +156 -82
  53. package/template/.claude/skills/feature/SKILL.md +6 -0
  54. package/template/.claude/skills/feature/reference/build-history.md +79 -0
  55. package/template/.claude/skills/idea/SKILL.md +14 -14
  56. package/template/.claude/skills/rollback/SKILL.md +23 -10
  57. package/template/AGENTS.md +11 -10
  58. package/template/devflow/{context → 00-context}/ai-interaction.md +1 -1
  59. package/template/devflow/{build-plan.md → 30-planning/build-plan.md} +24 -0
  60. package/template/devflow/40-tasks/.gitkeep +0 -0
  61. package/template/devflow/40-tasks/README.md +11 -0
  62. package/template/devflow/60-docs/migration-guide-decade-numbered.md +93 -0
  63. package/template/devflow/config.json +1 -0
  64. /package/template/devflow/{context → 00-context}/coding-standards.md +0 -0
  65. /package/template/devflow/{context → 00-context}/glossary.md +0 -0
  66. /package/template/devflow/{context → 00-context}/project-overview.md +0 -0
  67. /package/template/devflow/{ideas.md → 10-ideation/ideas.md} +0 -0
  68. /package/template/devflow/{reference → 10-ideation/reference}/build-plan-template.md +0 -0
  69. /package/template/devflow/{reference → 10-ideation/reference}/feature-spec-template.md +0 -0
  70. /package/template/devflow/{reference → 10-ideation/reference}/mockup.html +0 -0
  71. /package/template/devflow/{reference → 10-ideation/reference}/project-overview-template.md +0 -0
  72. /package/template/devflow/{reference → 10-ideation/reference}/project-plan-template.md +0 -0
  73. /package/template/devflow/{reference → 10-ideation/reference}/running-id-contract.md +0 -0
  74. /package/template/devflow/{decisions → 20-discovery/decisions}/.gitkeep +0 -0
  75. /package/template/devflow/{decisions → 20-discovery/decisions}/README.md +0 -0
  76. /package/template/devflow/{discoveries → 20-discovery/discoveries}/.gitkeep +0 -0
  77. /package/template/devflow/{project-plan.md → 30-planning/project-plan.md} +0 -0
  78. /package/template/devflow/{history → 50-history}/HISTORY.md +0 -0
  79. /package/template/devflow/{history → 50-history}/features/README.md +0 -0
  80. /package/template/devflow/{history → 50-history}/fixes/README.md +0 -0
  81. /package/template/devflow/{history → 50-history}/rollbacks/README.md +0 -0
  82. /package/template/devflow/{docs → 60-docs}/USAGE.md +0 -0
  83. /package/template/devflow/{docs → 60-docs}/diagrams/nexus-devflow-architecture.html +0 -0
  84. /package/template/devflow/{docs → 60-docs}/diagrams/nexus-devflow-architecture.json +0 -0
  85. /package/template/devflow/{docs → 60-docs}/diagrams/nexus-devflow-lifecycle.html +0 -0
  86. /package/template/devflow/{docs → 60-docs}/diagrams/nexus-devflow-lifecycle.json +0 -0
  87. /package/template/devflow/{docs → 60-docs}/examples/living-spec/adr.example.md +0 -0
  88. /package/template/devflow/{docs → 60-docs}/examples/living-spec/current-feature.example.md +0 -0
  89. /package/template/devflow/{docs → 60-docs}/examples/living-spec/discovery.example.md +0 -0
  90. /package/template/devflow/{docs → 60-docs}/examples/living-spec/ideas.example.md +0 -0
  91. /package/template/devflow/{docs → 60-docs}/governance-rules.md +0 -0
  92. /package/template/devflow/{docs → 60-docs}/manual-review-workflow-spec.md +0 -0
  93. /package/template/devflow/{docs → 60-docs}/markdown-metadata-contract.md +0 -0
  94. /package/template/devflow/{docs → 60-docs}/quickstart.md +0 -0
  95. /package/template/devflow/{docs → 60-docs}/release-process.md +0 -0
  96. /package/template/devflow/{docs → 60-docs}/skill-selection-policy.md +0 -0
  97. /package/template/devflow/{docs → 60-docs}/workflow-surface-map.md +0 -0
@@ -21,10 +21,10 @@ contract in `AGENTS.md`.
21
21
  ```text
22
22
  # 1. Ingest specific file from any path (PDF, DOCX, XLSX, Image, CSV, Text)
23
23
  /analyze C:\Users\...\Downloads\customer-spec.pdf
24
- /analyze ./mockup.png ./schema.xlsx "ระบบสะสมแต้มสมาชิก"
24
+ /analyze ./mockup.png ./schema.xlsx "Loyalty point system"
25
25
 
26
26
  # 2. Ingest raw text or requirement from chat
27
- /analyze "ลูกค้าต้องการระบบผ่อนชำระ 0% เชื่อมกับ KBank Payment Gateway..."
27
+ /analyze "Customer requested 0% installment plan connected to KBank Payment Gateway..."
28
28
 
29
29
  # 3. Scan pending unassigned files in devflow/inbox/
30
30
  /analyze
@@ -46,50 +46,50 @@ contract in `AGENTS.md`.
46
46
 
47
47
  ---
48
48
 
49
- ### Step 1: Auto-Allocate Workspace & Ingestion (Frictionless Ingest)
49
+ ## Step 1: Auto-Allocate Workspace & Ingestion (Frictionless Ingest)
50
50
  1. **Allocate REQ-ID**: Generate sequential ID format `REQ-YYYYMMDD-NNN` (e.g. `REQ-20260903-001-point-system`).
51
51
  2. **Create Request Workspace**:
52
52
  ```text
53
53
  devflow/inbox/{REQ-ID}/
54
- ├── raw/ # เก็บไฟล์ต้นฉบับ (PDF, Word, Excel, Images, Email)
55
- ├── parsed.md # ข้อความ/ตารางที่สกัดออกมาแล้ว (Clean Markdown)
56
- └── clarifications.md # รายการคำถามที่ต้องไปถาม Stakeholder เพิ่ม
54
+ ├── raw/ # Original source files (PDF, Word, Excel, Images, Email)
55
+ ├── parsed.md # Extracted structured text/tables (Clean Markdown)
56
+ └── clarifications.md # Questions and clarifications checklist for stakeholders
57
57
  ```
58
58
  3. Copy or save incoming files into `devflow/inbox/{REQ-ID}/raw/`.
59
59
 
60
60
  ---
61
61
 
62
- ### Step 2: Parse & Normalize Requirement (`parsed.md`)
62
+ ## Step 2: Parse & Normalize Requirement (`parsed.md`)
63
63
  1. Extract text and tables from all raw files:
64
64
  - For Office/PDF docs: Invoke `convert-any-to-md` or document extractor.
65
65
  - For Web URLs / Confluence / Notion: Invoke `defuddle`.
66
66
  - For Images / Wireframes / Screenshots: Conduct Multimodal Vision OCR and describe layout and fields.
67
67
  2. Structure into `devflow/inbox/{REQ-ID}/parsed.md`:
68
- - **Executive Summary**: วัตถุประสงค์หลักของ Requirement
69
- - **Target Persona & User Stories**: ใครทำอะไร เพื่ออะไร
70
- - **Functional Requirements (FR)**: รายการฟังก์ชันและ Business Rules
71
- - **Non-Functional Requirements (NFR)**: Performance, Security, PDPA, Retention
72
- - **Data Entities & Fields**: ฟิลด์ข้อมูลและชนิดข้อมูลเบื้องต้น
68
+ - **Executive Summary**: Core purpose and business objective of the requirement
69
+ - **Target Persona & User Stories**: Who performs what action and why
70
+ - **Functional Requirements (FR)**: List of functions and business rules
71
+ - **Non-Functional Requirements (NFR)**: Performance, Security, PDPA/Privacy, Data Retention
72
+ - **Data Entities & Fields**: Data fields, schemas, and initial types
73
73
 
74
74
  ---
75
75
 
76
- ### Step 3: Codebase Impact & Blast Radius Analysis (`codebase-impact.md`)
77
- *(ดำเนินการเมื่อเป็นระบบเดิม / Brownfield Codebase)*
76
+ ## Step 3: Codebase Impact & Blast Radius Analysis (`codebase-impact.md`)
77
+ *(Execute when operating on an existing system / brownfield codebase)*
78
78
 
79
79
  1. Search codebase patterns using `grep_search`, `rg`, and AST analysis for affected models, controllers, APIs, and routes.
80
80
  2. Calculate **Blast Radius & Complexity Score**:
81
- - **Affected Files & Modules**: รายการไฟล์ที่ต้องแก้ไขหรือสร้างใหม่
82
- - **API & Contract Breaking Risk**: ตรวจสอบว่ากระทบกับ API เดิมหรือ Third-Party หรือไม่
83
- - **Complexity Rating**: `Low` | `Medium` | `High` | `Extreme` พร้อมเหตุผล
81
+ - **Affected Files & Modules**: List of files to be modified or newly created
82
+ - **API & Contract Breaking Risk**: Check if existing APIs or third-party contracts are impacted
83
+ - **Complexity Rating**: `Low` | `Medium` | `High` | `Extreme` with rationale
84
84
  3. Save analysis report to `devflow/analysis/{REQ-ID}/codebase-impact.md`.
85
85
 
86
86
  ---
87
87
 
88
- ### Step 4: Socratic Gap Detection & Clarification Checklist (`clarifications.md`)
88
+ ## Step 4: Socratic Gap Detection & Clarification Checklist (`clarifications.md`)
89
89
  1. Apply `grilling` and `domain-modeling` lenses to detect gaps:
90
- - **Missing Edge Cases**: เงื่อนไขขอบ, กรณีข้อมูลผิดพลาด, เน็ตหลุด, Concurrent Requests
91
- - **Ambiguous Business Rules**: กฎที่ยังคลุมเครือ ไม่ระบุ SLA หรือขั้นตอนที่ชัดเจน
92
- - **Security & Authorization**: การกำหนด Role, สิทธิ์การเข้าถึงข้อมูล, ข้อมูลส่วนบุคคล (PII)
90
+ - **Missing Edge Cases**: Boundary conditions, error states, network drops, concurrent requests
91
+ - **Ambiguous Business Rules**: Unclear policies, unspecified SLAs, or undefined workflows
92
+ - **Security & Authorization**: Role definitions, access permissions, personal identifiable data (PII)
93
93
  2. Generate an actionable checklist in `devflow/inbox/{REQ-ID}/clarifications.md` for the SA to take directly into stakeholder meetings.
94
94
 
95
95
  ---
@@ -110,14 +110,22 @@ the fresh-session handoff; Phase B must omit `Actual execution` so the legacy
110
110
  request and receipt keep both execution fields absent.
111
111
 
112
112
  1. Require an active spec with every build step checked and status `verified`, a
113
- non-default work branch, a reliable merge base, and a clean working tree.
113
+ non-default work branch, a reliable merge base, and a working tree matching
114
+ the target except existing `devflow/context/{xxx-slug}/review.md` and
115
+ `devflow/context/{xxx-slug}/findings.md` evidence.
114
116
  Independent mode accepts only a locally recorded remote default branch,
115
117
  local `main`, or local `master` as its enforceable base ref. Stop when none
116
118
  reliably covers the active work.
117
- The current full `HEAD` must be the approved review checkpoint, including the
118
- verified spec. Never create that commit inside Audit. If work is dirty, stop
119
- and ask the user to approve a review checkpoint through `/implement`, even
120
- when normal checkpoint commits are disabled.
119
+ The current full `HEAD` must be the approved application-code checkpoint.
120
+ Include the verified spec when tracked; for a new ignored-spec request, prepare
121
+ the exact local `Spec snapshot` under the reference contract. Never force-add
122
+ it or change ignore visibility. Never create a commit inside Audit. If any
123
+ tracked, staged, unstaged, or untracked path other than those two evidence
124
+ paths differs from the target, stop and ask the user to approve a review
125
+ checkpoint through `/implement`, even when normal checkpoint commits are
126
+ disabled. Do not create a checkpoint solely for review/findings changes.
127
+ This normal Phase A exception never allows snapshot Git differences or
128
+ overwriting conflicting completion-recovery evidence.
121
129
  2. Read installed adapters from `.nexus/nexus-devflow.json` or manifest when valid.
122
130
  Detect `.agents/skills` as `antigravity`/`codex`/`copilot` and `.claude/skills`
123
131
  as `claude`.
@@ -133,32 +141,37 @@ request and receipt keep both execution fields absent.
133
141
  isolated child through the current runtime. Do not discover, select, or
134
142
  depend on a globally installed role, skill, prompt, or another workflow
135
143
  such as TraversyFlow. If the runtime cannot start that generic child from
136
- project-local instructions, or capability, isolation, identity, model, or
137
- completion cannot be confirmed, use the manual path.
144
+ project-local instructions, or capability, isolation, identity, model,
145
+ completion, or access to the same ignored spec/snapshot inputs cannot be
146
+ confirmed, use the manual path in the original checkout.
138
147
  4. Record the full target SHA, full merge-base SHA, the exact local base ref
139
148
  used to calculate it, exact spec SHA-256, current adapter and model,
140
149
  requested reviewer adapter and model, requested execution from
141
150
  `review.independentExecution`, workflow, and
142
- whether the configured Check gate is required. Write the pending template
143
- into `devflow/context/{xxx-slug}/review.md`.
151
+ whether the configured Check gate is required. For a new ignored-spec request,
152
+ create or reuse the exact snapshot first and record `Spec snapshot` as defined
153
+ in the reference. Never add that field to an existing pending or completed
154
+ record. Write the pending template into `devflow/context/{xxx-slug}/review.md`.
144
155
  5. Execute the configured path:
145
156
  - For `manual`, set dashboard activity to `ready` and give the exact handoff
146
157
  command for the selected adapter. Claude Code uses
147
158
  `/audit independent current`; Google Antigravity uses
148
159
  `/audit independent current`; Codex uses `$audit independent current`;
149
160
  Copilot and OpenCode receive the equivalent plain-language instruction.
150
- Tell the user to open a fresh session with only the handoff, not the builder
151
- chat.
161
+ Tell the user to open a fresh session in the original checkout with only the
162
+ handoff, not the builder chat. Include target/base SHAs and, when present,
163
+ the exact snapshot path and spec hash.
152
164
  - For `automatic`, freeze all parent product, test, spec, and config changes.
153
165
  Start one generic isolated child without the builder transcript. Instruct
154
166
  it to read the project-local Audit skill and
155
167
  `reference/independent-review.md` from the current adapter tree, then
156
- execute Phase B against the prepared request. All review instructions come
157
- from that installed DevFlow project. The reviewer may write only
158
- `devflow/context/{xxx-slug}/findings.md` and `devflow/context/{xxx-slug}/review.md`; it must
159
- not repair code, change the spec, commit, or perform external actions. Wait
160
- for completion, then reread and validate the normal receipt before
161
- continuing. Record `fresh subagent` as its reviewer context.
168
+ execute Phase B using the same local spec/snapshot inputs against the
169
+ prepared request. All review instructions come from that installed DevFlow
170
+ project. The reviewer may write only `devflow/context/{xxx-slug}/findings.md`
171
+ and `devflow/context/{xxx-slug}/review.md`; it must not repair code, change
172
+ the spec, commit, or perform external actions. Wait for completion, then
173
+ reread and validate the normal receipt before continuing. Record `fresh subagent`
174
+ as its reviewer context.
162
175
 
163
176
  If automatic execution fails or any required property becomes uncertain, keep
164
177
  the pending request intact, set activity to `ready`, and stop with the existing
@@ -177,7 +190,9 @@ Use this phase when a current pending request exists in `devflow/context/{xxx-sl
177
190
  `HEAD` matches `Target commit`, the recorded base ref still produces the
178
191
  recorded merge base, the exact spec hash matches, and no path differs from
179
192
  the target except `devflow/context/{xxx-slug}/review.md` and
180
- `devflow/context/{xxx-slug}/findings.md`. Stop on any mismatch or stale state.
193
+ `devflow/context/{xxx-slug}/findings.md`. When `Spec snapshot` is present, verify
194
+ both raw spec/snapshot hashes and every path, visibility, and Git condition in
195
+ the reference. Stop on any mismatch or stale state.
181
196
  2. Proceed only from the fresh reviewer handoff. Record `fresh session` for a
182
197
  manual reviewer or `fresh subagent` for an automatic isolated reviewer. This
183
198
  is a declaration, never cryptographic proof. If the reviewer has the builder
@@ -206,6 +221,9 @@ Use this phase when a current pending request exists in `devflow/context/{xxx-sl
206
221
  After changes are requested, the builder repairs through `/implement`, obtains
207
222
  approval for a new checkpoint, and prepares a new request. The next reviewer
208
223
  pass reviews the complete new delta, not only the old findings.
224
+ A local-spec-only revision may reuse the same approved product HEAD after normal
225
+ spec and verification gates, with a new snapshot/request and full fresh review;
226
+ it never requires an empty commit.
209
227
 
210
228
  ## Step 1 - gather context
211
229
 
@@ -68,6 +68,56 @@ work branch, and `Base commit` cannot equal `Target commit`. If none of those
68
68
  base refs reliably covers the active work, stop instead of creating a receipt
69
69
  whose review range cannot be re-derived.
70
70
 
71
+ ## Local spec snapshot
72
+
73
+ For a new request whose verified spec is intentionally ignored, keep application
74
+ code in the approved checkpoint and freeze the spec outside Git. Add exactly one
75
+ field after `Spec hash`, using a plain path with no backticks:
76
+
77
+ ```markdown
78
+ **Spec snapshot:** devflow/.state/review-specs/<Target commit>-<Spec hash>.md
79
+ ```
80
+
81
+ Substitute the request's full lowercase target SHA and lowercase spec hash. This
82
+ is the only permitted snapshot path; duplicate fields or another path are
83
+ malformed. Tracked-spec requests do not need this field. Existing requests and
84
+ receipts without it retain their previous hash, freshness, and execution rules.
85
+ Never retroactively add `Spec snapshot` to a pending or completed record.
86
+
87
+ Phase A prepares the copy before publishing a new pending request:
88
+
89
+ 1. Read the verified active spec as raw bytes and calculate its SHA-256 without
90
+ decoding, trimming, or normalizing line endings. Use that digest as `Spec hash`.
91
+ 2. Use `lstat` on the selected project root and every directory below it leading
92
+ to the spec and snapshot. Require ordinary directories, a regular spec file,
93
+ and a regular file for any existing snapshot. Reject symbolic links, including
94
+ dangling links. Ancestor aliases above the selected root are not inspected.
95
+ Create missing snapshot directories only beneath verified ordinary parents;
96
+ a missing snapshot leaf is allowed only for exclusive creation below them.
97
+ 3. Require both paths to be ignored and untracked, absent from the index and
98
+ `Target commit`. Check ignore status separately for each path, require no
99
+ entries from `git ls-files --stage -- <spec-path> <snapshot-path>` or
100
+ `git ls-tree -r --name-only <target> -- <spec-path> <snapshot-path>`, and
101
+ distinguish expected absence from Git failure. Never force-add files or
102
+ change ignore visibility to make these checks pass.
103
+ 4. Create the snapshot exclusively, for example with Node's `fs.open` using
104
+ `wx`, then write the raw byte buffer and close the handle. If it already
105
+ exists, reuse only an ordinary file whose bytes exactly match the spec.
106
+ Conflicting bytes, unsafe paths, or a failed write stop preparation; never
107
+ overwrite or repair the existing snapshot in place.
108
+ 5. Read both files back and require identical raw bytes and the recorded hash.
109
+ Recheck their path and Git conditions before writing the request. Keep the
110
+ snapshot unchanged through review and completion; do not automatically delete
111
+ or regenerate it to make an existing receipt pass.
112
+
113
+ The target/base fields bind application code; `Spec hash` binds both local files.
114
+ The snapshot is an input, never another allowed dirty Git path. Manual handoff
115
+ names the original checkout, target/base SHAs, snapshot path, and hash. An
116
+ automatic child must be able to read those same ignored inputs and installed
117
+ project-local skills. If that access cannot be confirmed, retain the request and
118
+ use the manual fresh-session handoff in the original checkout. Do not copy local
119
+ inputs externally or substitute a clone/worktree that lacks them.
120
+
71
121
  ## Completed receipt
72
122
 
73
123
  Keep the request fields unchanged and replace `pending` with `passed` or
@@ -131,6 +181,9 @@ A receipt is current only when all of these hold:
131
181
  equals `Base commit`, and it remains a locally recorded remote default branch,
132
182
  local `main`, or local `master`.
133
183
  - The exact task spec bytes still match `Spec hash`.
184
+ - When `Spec snapshot` is present, both raw files match that hash and every
185
+ snapshot path, visibility, and Git condition above still holds. Missing or
186
+ changed snapshot inputs make the record stale; Git failure never passes.
134
187
  - No tracked, staged, unstaged, or untracked path differs from the target except
135
188
  `devflow/context/{xxx-slug}/review.md` and `devflow/context/{xxx-slug}/findings.md`.
136
189
  - The completed reviewer adapter matches `Requested reviewer`.
@@ -149,8 +202,11 @@ A receipt is current only when all of these hold:
149
202
  record the actual value.
150
203
 
151
204
  Any other code, test, configuration, spec, or acceptance-criteria change makes
152
- the receipt stale. A stale receipt never proves the new state. Prepare a new
153
- request against a new approved checkpoint and review the whole delta again.
205
+ the receipt stale. A stale receipt never proves the new state. Product changes
206
+ need a new approved checkpoint. A local-spec-only revision may reuse the same
207
+ approved product HEAD after normal spec and verification gates, with a new
208
+ snapshot, a new request, and a full fresh review. Never create an empty commit
209
+ just to capture ignored spec changes or edit a passed receipt into a new review.
154
210
 
155
211
  The adapter, model, and context fields are declared metadata. DevFlow proves
156
212
  the target and staleness, but it cannot cryptographically prove that a separate
@@ -37,7 +37,7 @@ Provide at least 2-3 materially distinct approaches:
37
37
  ### 3. Trade-off Comparison Matrix
38
38
  Construct a structured evaluation table:
39
39
 
40
- | Option | Pros (ข้อดี) | Cons (ข้อเสีย) | Effort & Complexity | Verdict / Status |
40
+ | Option | Pros | Cons | Effort & Complexity | Verdict / Status |
41
41
  | :--- | :--- | :--- | :--- | :--- |
42
42
  | **Option A** | ... | ... | Low / Med / High | ... |
43
43
  | **Option B** | ... | ... | Low / Med / High | **Recommended** |
@@ -33,6 +33,15 @@ passes.
33
33
  Read `devflow/config.json`. A missing file means the built-in defaults apply.
34
34
  If the file exists but is invalid, stop and point the user to `/doctor`.
35
35
 
36
+ Before requiring a real active spec, check for pending completion using
37
+ `reference/completion-recovery.md`. A matching archive may mean archival was
38
+ interrupted, the work commit awaits merge, or the merge already finished. Follow
39
+ that phase instead of restarting logging. Missing or ambiguous evidence stops
40
+ with concrete recovery steps; an archive or clean context never authorizes selecting new work.
41
+ Recovery uses archive and Git proof, never dashboard activity as authority.
42
+
43
+ For a normal completion with no recovery in progress, continue below.
44
+
36
45
  Confirm the target work is actually finished: `devflow/context/{xxx-slug}/spec.md`
37
46
  holds a real spec, its steps are built on a branch, and `Verify`, or the fallback
38
47
  build and tests, passes. If any of the
@@ -45,6 +54,7 @@ Read `devflow/context/{xxx-slug}/review.md` (or `devflow/context/review.md`) whe
45
54
  changes-requested, malformed, or stale record is always a blocker because the
46
55
  user already initiated that gate, even when its configured policy is `manual`.
47
56
 
57
+
48
58
  ## Configured regular quality gates
49
59
 
50
60
  Use `qualityGates.regular` for this work item:
@@ -103,6 +113,15 @@ evidence is missing.
103
113
 
104
114
  ## Step 1 - log the work
105
115
 
116
+ Follow `reference/completion-recovery.md` to capture the source tree and compact
117
+ archive annotation before any logging edits. Preserve the exact verified spec
118
+ prefix, its UTF-8 byte length and SHA-256, branch, original HEAD, and local base.
119
+ Record the reference's narrow `absentOptional` proof before creating any optional
120
+ findings/review stub on an older installation; tree absence alone is insufficient.
121
+ Prepare the entire archive, including the sections below and any generated try
122
+ guide, before placing it at its destination in `devflow/history/features/`, `fixes/`, or `rollbacks/`. An existing matching archive
123
+ enters recovery; never overwrite it or append duplicate sections.
124
+
106
125
  Check whether the spec is a feature, fix, or rollback. A fix is marked
107
126
  `Type: Fix` and has no build-plan number. A rollback is marked `Type: Rollback`
108
127
  and records the exact target feature, archive, commit, and parent.
@@ -122,11 +141,14 @@ delete the `prototypes/` folder now.
122
141
 
123
142
  ## Step 2 - make the work commit on feature branch
124
143
 
125
- Stage everything on the branch (any uncommitted step work plus the Step 1 logging
144
+ Show the complete product and logging diff with the proposed commit message,
145
+ then obtain explicit commit approval. Only then stage the reviewed branch work
146
+ (any uncommitted step work plus the Step 1 logging
126
147
  changes) and make one conventional work commit on the active branch (for example `feat: <feature>`,
127
148
  `fix: <name>`, or `revert: roll back <feature>`). `Verify`, or the fallback build
128
149
  and tests, must pass first.
129
150
 
151
+
130
152
  ## Step 3 - Mandatory Delivery Gate (Ask User First)
131
153
 
132
154
  > [!IMPORTANT]
@@ -0,0 +1,248 @@
1
+ # Completion recovery
2
+
3
+ Use this contract before Complete requires a live spec, and before Status or
4
+ Continuous selects new work. Archive and Git evidence determine the phase.
5
+ `run.json`, modification times, archive titles, and commit subjects prove none of
6
+ these transitions. Recovery grants no commit, merge, push, or cleanup approval.
7
+
8
+ ## Prepare one recoverable archive
9
+
10
+ After Complete's final gates pass, but before any logging edits, record the full
11
+ work branch ref, `HEAD`, local default branch ref and its current commit. Require
12
+ that default commit to be an ancestor of the work branch. Resolve refs locally;
13
+ do not fetch. Capture the verified working tree in a temporary Git index:
14
+
15
+ ```bash
16
+ node --input-type=module -e '
17
+ import fs from "node:fs";
18
+ import os from "node:os";
19
+ import path from "node:path";
20
+ import { execFileSync } from "node:child_process";
21
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "devflow-completion-"));
22
+ const env = { ...process.env, GIT_INDEX_FILE: path.join(dir, "index") };
23
+ try {
24
+ execFileSync("git", ["read-tree", "HEAD"], { env });
25
+ execFileSync("git", ["add", "-A", "--", "."], { env });
26
+ process.stdout.write(execFileSync("git", ["write-tree"], { env }));
27
+ } finally {
28
+ fs.rmSync(dir, { recursive: true, force: true });
29
+ }'
30
+ ```
31
+
32
+ Run from the project root only after excluding unrelated work and Git conflicts.
33
+ This writes local Git objects, not a commit or ref, and leaves the normal index
34
+ untouched. Never force-add ignored files. Dirty submodules or required ignored
35
+ inputs without separately recoverable exact bytes cannot support this proof.
36
+ The source tree is evidence, not approval or a substitute for any quality gate.
37
+
38
+ Before logging, record `absentOptional` as an array containing only
39
+ `devflow/context/{xxx-slug}/findings.md` and/or `devflow/context/{xxx-slug}/review.md` when each
40
+ exact path returns `ENOENT` from `lstat`, its parents are ordinary directories,
41
+ and neither HEAD nor sourceTree contains it. Otherwise omit that path. This
42
+ records original filesystem absence, never permission to discard evidence.
43
+ Ignored existing files and symlinks are not absent. Reject other paths, duplicates,
44
+ or contradictions; a missing field in an older annotation proves no absence.
45
+
46
+ Start the archive with the original verified spec bytes, unchanged. Measure
47
+ UTF-8 **bytes**, not characters or lines. Append two LF bytes and this single-line
48
+ JSON comment before any Findings, Independent review, or Manual try guide section:
49
+
50
+ ```text
51
+ <!-- devflow:completion {"schemaVersion":1,"specBytes":123,"specSha256":"<64 hex>","branch":"refs/heads/feature/name","head":"<full SHA>","baseRef":"refs/heads/main","baseCommit":"<full SHA>","sourceTree":"<full tree SHA>","absentOptional":[]} -->
52
+ ```
53
+
54
+ Use `Buffer.length` and SHA-256 over the exact file bytes. To recover, locate the
55
+ unique annotation boundary and remove only the two inserted line breaks before
56
+ it (LF or CRLF). Test that prefix as raw bytes and uniform LF/CRLF candidates
57
+ against both `specBytes` and `specSha256`; deduplicate identical candidates and
58
+ accept only one exact match. This reconstructs hash-proven original bytes across
59
+ ordinary Git EOL conversion. Mixed endings or custom filters without an exact
60
+ match stop recovery. Never trim content, split on a Markdown heading, or accept a
61
+ normalized digest instead of the original. Reject malformed/duplicate annotations.
62
+
63
+ Build the complete archive in a temporary file first, including all resolved
64
+ findings, the exact passing receipt when present, and any generated try guide.
65
+ Validate it against its inputs, then place it at the intended absent archive path
66
+ in `devflow/history/features/`, `fixes/`, or `rollbacks/`.
67
+ Never overwrite an existing archive: a matching one enters recovery; a conflicting
68
+ one stops for an exact path decision. Finish plan/overview bookkeeping, update
69
+ `devflow/history/HISTORY.md`, then clean up the run workspace `devflow/context/{xxx-slug}/`.
70
+ Do not append sections incrementally to an existing archive during recovery.
71
+
72
+ ## Screen candidates read-only
73
+
74
+ Before matching a reused feature branch, apply the historical-build exclusion
75
+ below. Do not treat a proved prior reversed build as pending completion of its
76
+ replacement. If that exclusion cannot be proved, retain the candidate and stop
77
+ for full proof rather than guessing from a different spec or archive name.
78
+
79
+ Inspect current branch, `git status --porcelain=v1`, live spec/review and plan
80
+ consistency, and relevant annotated archives. Check recorded local work refs with
81
+ `git show-ref --verify --quiet <branch>`. A matching work branch/archive, a retained
82
+ matching work ref after merge, or uncommitted completion changes/live evidence tied
83
+ to that item is a recovery candidate. An explicit request to resume completion
84
+ also requires full proof. Status reports candidates and routes them to Complete;
85
+ it does not create a temporary index or claim the phase has passed full proof.
86
+
87
+ For ordinary Status or a new Continuous invocation, a clean local default branch
88
+ with consistent live state, no matching local work ref, and no pending completion
89
+ evidence is settled history. An archive at its tip alone does not trigger recovery.
90
+ Do not require historical `head`/`sourceTree` objects for that orientation; clean
91
+ clones and Git pruning legitimately lose them. This is not a new claim about past
92
+ verification. A reset stub alone proves nothing: check the refs, cleanliness, and
93
+ live state too. Missing objects still block actual recovery and explicit resume.
94
+
95
+ ## Prove an actual recovery candidate
96
+
97
+ For feature archives on a reused branch, exclude a prior build only when all of
98
+ these read-only Git checks pass:
99
+
100
+ - `../../feature/reference/build-history.md` proves its unique unchanged archive
101
+ addition on the local default, and the introducing commit's sole parent equals
102
+ that archive annotation's `baseCommit` on the same `baseRef`.
103
+ - An exact completed, unchanged, reachable rollback record names that archive and
104
+ introducing commit; its commit is after the feature addition.
105
+ - The current work branch descends from a post-rollback local default: that
106
+ rollback commit is an ancestor of the merge base of the current work branch
107
+ and local default. Its old archive remains byte/mode-identical in both trees
108
+ and the working tree, with no pending archive edits or retained review explicitly
109
+ targeting that old build.
110
+
111
+ Different spec bytes, title, attempt, filename, or ancestry alone never exclude
112
+ an archive. Missing, changed, or contradictory proof stops; this exception does
113
+ not recover old missing inputs or waive current gates. It permits legacy branch
114
+ reuse only after the old lifecycle is demonstrably finished and reversed.
115
+
116
+ Require one annotated archive matching the recorded work branch, or the exact
117
+ archive/commit proof in the merged phase below. A real live spec must match its
118
+ recovered bytes; a cleaned-up workspace is also expected after merge. A different spec conflicts.
119
+ For features, use the recovered spec's frozen `**Build attempt:**` and that exact
120
+ archive path; never allocate a new attempt on resume. For a legacy feature spec
121
+ without the field, the path plus existing annotation fixes the destination only
122
+ after the prior-build proof in `../../feature/reference/build-history.md` at its
123
+ recorded `baseCommit` uniquely establishes its attempt. Exclude the current archive from those prior
124
+ builds. Do not edit the recovered bytes to insert metadata.
125
+
126
+ Require all recorded commits and `sourceTree` to exist (`git cat-file -e`).
127
+ Unreferenced source trees can be pruned by Git: missing objects stop recovery;
128
+ request the original objects or an identified backup, never recreate a guessed
129
+ baseline. An old archive without this annotation may be read as history, but
130
+ cannot automatically recover a missing live spec through this contract.
131
+
132
+ Use the temporary-index command above to inspect the present work tree without
133
+ altering the real index. Compare trees with `git diff --raw -z <source> <current>`
134
+ and inspect source blobs with `git show <sourceTree>:<path>`. Git trees use clean-
135
+ filtered bytes; compare evidence through `git hash-object --path=<path> --stdin`
136
+ when ordinary EOL conversion applies, while recovering the exact spec only by
137
+ its archive digest above. Unsupported custom filters stop recovery. Inspect staged
138
+ changes too; conflicting staged/working versions must be reconciled explicitly.
139
+ Do not infer identity from ancestry alone, a matching filename, or a latest date.
140
+
141
+ ## Validate only the expected completion changes
142
+
143
+ Reconstruct the original spec and evidence from the source tree and archive.
144
+ Every changed path, file mode, addition, and deletion must be accounted for.
145
+ Only these exact transformations can follow the captured source tree:
146
+
147
+ - Add this one archive, with the exact spec prefix and annotation, resolved
148
+ findings copied with only the documented ID prefix, the original passing
149
+ receipt bytes, and a try guide for this spec when required or already generated.
150
+ - Apply this work item's exact build-plan checkbox/parent changes, or its exact
151
+ rollback note. Update `devflow/history/HISTORY.md` with the release digest.
152
+ Change only the overview's existing source-hash value, using the documented hash contract.
153
+ A fix has no build-plan change.
154
+ - Remove only resolved ledger entries present in that archive. Preserve every
155
+ `open`, `fixed`, and `unverified` entry byte-for-byte, including its ID.
156
+ - Clean up the completed task run directory `devflow/context/{xxx-slug}/`.
157
+ - Delete only the exact consumed prototype files already authorized for this
158
+ work item and identified by its design reference. No general cleanup is allowed.
159
+
160
+ No other history, context, configuration, product, test, or ignore-rule changes
161
+ are completion bookkeeping. Read the full diffs, not just a filename allowlist.
162
+ Partial plan bookkeeping is recoverable only when each changed byte is one of
163
+ these transformations and all unfinished operations can be identified exactly.
164
+ Conflicting or partial archive/evidence content stops before any live reset.
165
+
166
+ For independent review, validate the archived receipt against its original
167
+ `Target commit`, original base/merge-base, exact recovered spec digest, reviewer
168
+ identity, execution/context pairing, required Check result, and receipt sections.
169
+ The annotation's `head` must equal that target, and its source tree may differ
170
+ from the target only in the original review/findings evidence permitted by Audit.
171
+ Never relabel the receipt as current at the later work commit or merge commit.
172
+ When the original receipt has `Spec snapshot`, preserve that field unchanged.
173
+ After live reset, the hash-proven original archive prefix may establish the same
174
+ spec identity: require its exact digest to equal the receipt's `Spec hash` and the
175
+ annotation's `specSha256`, and require the snapshot field's canonical path to
176
+ contain that original target and hash. This is archived-receipt validation, not
177
+ a current live receipt. Do not create a new snapshot or relabel the target.
178
+ Conflicting retained snapshot bytes or unsafe paths still stop recovery; an
179
+ absent local snapshot may use this exact archive proof after reset. This does
180
+ not replace source-tree/product proof or recover other ignored evidence.
181
+ The narrow completion changes above preserve the reviewed product; any other
182
+ change requires restored exact active inputs and renewed gates/checkpoint/review.
183
+ Never overwrite conflicting live evidence to obtain that restoration.
184
+
185
+ Ignored local-only files are absent from this tree proof. Validate them using
186
+ separately provable exact original bytes plus the archive and retained inputs,
187
+ or stop and name the missing evidence. A local archive can match a still-existing
188
+ work branch; its presence alone cannot bind an already-deleted branch to a squash
189
+ commit. Do not force-add ignored workflow files to make recovery pass.
190
+
191
+ ## Interrupted archival, before the work commit
192
+
193
+ Require the recorded work branch at the recorded `head`, the local default still
194
+ at `baseCommit`, a complete matching archive, and only the validated partial or
195
+ finished bookkeeping changes above. Reconcile archived and retained findings and
196
+ review before changing anything. Do not duplicate sections or erase unresolved
197
+ entries. If the archive is absent and live inputs are intact, use normal Complete;
198
+ if both the archive and needed live input are missing, stop for recovery evidence.
199
+
200
+ Read the recovered spec from a temporary file, preserving its exact bytes; do
201
+ not overwrite the live stub merely to orient a fresh session. Repeat current-
202
+ session Verify and required gates against that spec and the current product.
203
+ Reuse a passing archived review only through the original-target checks above.
204
+ If a gate needs active files restored, restore only proven matching originals
205
+ with no conflicting live data, run the gate, and re-enter normal Complete. If
206
+ verification or review changes evidence, stop and reconcile a new reviewed archive
207
+ candidate explicitly; never silently append to the existing archive.
208
+
209
+ Finish only the missing bookkeeping, with live workspace cleanup last. Show the concrete
210
+ remaining diff and proposed conventional work commit, obtain normal commit
211
+ approval, and continue at Complete Step 2. This archive does not authorize Git.
212
+
213
+ ## Work committed, awaiting merge
214
+
215
+ Require a clean recorded work branch at one unambiguous final work commit whose
216
+ sole parent is recorded `head`, with the default still at `baseCommit`. Compare the complete work
217
+ commit tree to `sourceTree` and require exactly the finished transformations above.
218
+ The tracked archive and final bookkeeping must be in that commit, not added later.
219
+ For ignored evidence require the separate proof described above. Extra commits or
220
+ post-commit drift stop for review, not another completion commit.
221
+
222
+ Rerun current-session Verify and validate all required gates using the recovered
223
+ spec and original receipt. Resume at Complete Step 3's merge approval. Never make
224
+ a second work commit, reset evidence again, or treat earlier approval as covering
225
+ new changes. Preserve the exact work commit SHA for merge verification.
226
+
227
+ ## Merge already completed
228
+
229
+ Require a clean local default branch tip whose sole parent is the recorded
230
+ `baseCommit`, and the complete finished tree and archive. If the work branch still
231
+ exists, require its exact final work commit and tree equality with that default
232
+ tip (`git diff --exit-code <workCommit>^{tree} <defaultTip>^{tree}`), including the
233
+ archive blob. A squash merge normally does not contain the work commit as an
234
+ ancestor. Tree equality alone without the matching base, archive, and completed
235
+ bookkeeping is insufficient.
236
+
237
+ If the work branch was deleted, require the tracked archive at the default tip,
238
+ its exact source-tree/spec/branch annotation, and exactly the finished changes
239
+ from sourceTree to that tip. An ignored archive without a provable commit binding
240
+ must stop for user identification and supporting evidence. If the default has
241
+ advanced or several commits/archives fit, stop and name the ambiguity instead of
242
+ weakening this proof or searching by title.
243
+
244
+ Do only pending cleanup already authorized for this work item; ask if cleanup
245
+ approval is missing. Never repeat archival, the work commit, or the squash merge,
246
+ and never create a cleanup commit on the default branch. If nothing remains,
247
+ report the verified local merge once and leave Git unchanged. Push still needs
248
+ its separate approval. A repeated resume follows this same no-op path.