@haposoft/cafekit 0.8.12 → 0.8.14

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.
@@ -0,0 +1,407 @@
1
+ # Reconstruct Workflow
2
+
3
+ Use this reference for `/hapo:docs reconstruct <scope>`.
4
+
5
+ ## Goal
6
+
7
+ Rebuild current-state, as-is system documentation from source code.
8
+
9
+ This is useful for:
10
+
11
+ - existing systems with weak or missing documentation
12
+ - legacy system modernization discovery
13
+ - sales demos showing source-code-to-docs capability
14
+ - preparing a reviewed baseline before `/hapo:specs` creates modernization/change specs
15
+
16
+ ## Non-Goal
17
+
18
+ This workflow does not produce future design, implementation tasks, rewrite plans, or product code.
19
+
20
+ It answers:
21
+
22
+ ```text
23
+ What does the current system appear to do, based on evidence?
24
+ ```
25
+
26
+ It does not answer:
27
+
28
+ ```text
29
+ What should the future system do?
30
+ ```
31
+
32
+ ## Output Contract
33
+
34
+ Write output under:
35
+
36
+ ```text
37
+ docs/as-is/<scope-slug>/
38
+ ```
39
+
40
+ Files:
41
+
42
+ ```text
43
+ overview.html
44
+ reconstruction.json
45
+ system-overview.md
46
+ requirements-as-is.md
47
+ roles-and-permissions.md
48
+ entities-and-statuses.md
49
+ business-rules.md
50
+ integrations.md
51
+ architecture-c4.md
52
+ constraints-risks-and-decisions.md
53
+ glossary.md
54
+ evidence-map.md
55
+ unknowns-and-assumptions.md
56
+ ```
57
+
58
+ If the user provides a different docs root through `.claude/runtime.json`, use that root.
59
+
60
+ Use the bundled templates as output starters:
61
+
62
+ - `templates/reconstruction.json`
63
+ - `templates/requirements-as-is.md`
64
+ - `templates/evidence-map.md`
65
+ - `templates/unknowns-and-assumptions.md`
66
+ - `templates/reconstruct-overview.html`
67
+
68
+ `overview.html` is a self-contained visual review surface. Markdown and JSON remain the source of truth.
69
+
70
+ ## Required Classification
71
+
72
+ Every major finding must include:
73
+
74
+ ```text
75
+ Type: Observed | Inferred | Unknown
76
+ Confidence: High | Medium | Low
77
+ Evidence:
78
+ - path/to/file.ext
79
+ - path/to/file.ext:functionOrClass
80
+ - path/to/test.spec.ts
81
+ ```
82
+
83
+ Use line numbers when available from reads. If exact line numbers are not available, cite file paths and symbols.
84
+
85
+ ## Reconstruction Reader Model
86
+
87
+ Reconstruction is written for two readers:
88
+
89
+ 1. a domain reviewer who can confirm or reject recovered behavior
90
+ 2. a future `hapo:specs` run that needs an approved as-is baseline before change design
91
+
92
+ Write each document so those readers can separate:
93
+
94
+ - current behavior visible from source
95
+ - behavior inferred from multiple code signals
96
+ - missing business context only humans or runtime evidence can supply
97
+
98
+ ## Evidence Quality
99
+
100
+ High confidence:
101
+ - directly found in route/controller/component/schema/test/config
102
+ - supported by at least one source file and one behavior signal
103
+
104
+ Medium confidence:
105
+ - supported by multiple related source signals, but no explicit test or end-to-end path
106
+
107
+ Low confidence:
108
+ - suggested by naming, partial code, comments, or incomplete references
109
+
110
+ Unknown:
111
+ - not enough evidence
112
+ - code path is dead or unreachable
113
+ - behavior depends on runtime data, external service, manual operation, or undocumented configuration
114
+
115
+ ## Evidence Ledger
116
+
117
+ Build an evidence ledger before writing conclusions. An evidence row should capture:
118
+
119
+ | Field | Meaning |
120
+ |---|---|
121
+ | ID | Stable evidence ID such as `E-API-003` |
122
+ | Surface | UI, API, data, auth, job, integration, test, config |
123
+ | Source | File path and symbol/route/schema/test |
124
+ | Observation | What the source directly proves |
125
+ | Related behavior | Requirement/business rule/entity it may support |
126
+ | Confidence | High, Medium, Low |
127
+ | Gap | Missing trigger, runtime data, customer rule, or external system |
128
+
129
+ Write the human-readable ledger into `evidence-map.md`. Reference evidence IDs from reconstructed requirements and supporting docs when a requirement needs multiple sources.
130
+
131
+ ## Workflow
132
+
133
+ ### 1. Scope Gate
134
+
135
+ If `<scope>` is missing, ask for a module or bounded context.
136
+
137
+ If `<scope>` is broad (`.`, `/`, `whole repo`, `entire system`):
138
+
139
+ 1. Run a structure scout first.
140
+ 2. Identify 2-6 candidate modules.
141
+ 3. Ask the user to choose, unless one module is clearly requested by the prompt.
142
+
143
+ Never silently reconstruct a large system as one flat document.
144
+
145
+ ### 2. Structure And Source Scout
146
+
147
+ Use `hapo:inspect` patterns or targeted reads to identify:
148
+
149
+ - project type and language/framework
150
+ - relevant screens/pages/routes
151
+ - API endpoints/controllers
152
+ - database schemas, migrations, models, entities
153
+ - state machines/status fields/enums
154
+ - validation logic
155
+ - permission/auth checks
156
+ - tests and fixtures
157
+ - integrations, workers, jobs, cron, queues, webhooks
158
+ - existing docs that may be stale or useful
159
+
160
+ Use existing docs only as leads until source evidence confirms them.
161
+
162
+ Save detailed scout findings and evidence IDs in:
163
+
164
+ ```text
165
+ docs/as-is/<scope-slug>/evidence-map.md
166
+ ```
167
+
168
+ ### 3. Trace Behavior Surfaces
169
+
170
+ Recover behavior by tracing reachable source surfaces:
171
+
172
+ | Surface | Questions to answer |
173
+ |---|---|
174
+ | UI/screens | What actor sees, starts, filters, updates, downloads |
175
+ | API/routes | What operations exist, inputs accepted, outputs/errors returned |
176
+ | Data/schema | What entities, fields, statuses, relations, constraints exist |
177
+ | Auth/permissions | Who can access which route/action/record |
178
+ | Business rules | What validation, calculations, branching, lifecycle rules exist |
179
+ | Background work | What jobs, events, queues, schedulers, hooks run |
180
+ | Integrations | What external services, files, webhooks, mailers, payments exist |
181
+ | Tests | What intended behavior is asserted and what gaps remain |
182
+
183
+ Prefer end-to-end traces that connect entry point, rule, state change, and output. When a trace is incomplete, keep the gap in the evidence ledger and unknowns list.
184
+
185
+ ### 4. Reconstruct As-Is Requirements
186
+
187
+ Write `requirements-as-is.md` using current behavior only.
188
+
189
+ Recommended shape:
190
+
191
+ ```markdown
192
+ ## R-ASIS-001: <current behavior>
193
+ - Type: Observed
194
+ - Confidence: High
195
+ - Evidence:
196
+ - E-API-003 — src/...
197
+ - E-TEST-004 — tests/...
198
+ - Actors:
199
+ - ...
200
+ - Trigger:
201
+ - ...
202
+ - Current outcome:
203
+ - ...
204
+ - Exceptions or gaps:
205
+ - ...
206
+ - Notes:
207
+ - ...
208
+ ```
209
+
210
+ Requirements should be singular, testable, and tied to code evidence.
211
+
212
+ Do not use future-tense language such as "will", "should", or "must be improved" unless quoting existing source docs.
213
+
214
+ Recommended extraction checklist:
215
+
216
+ 1. Identify actor or caller.
217
+ 2. Identify trigger and source entry point.
218
+ 3. Identify input, validation, state read/write, output, and error behavior.
219
+ 4. Link entity/status/permission/integration evidence.
220
+ 5. Mark requirement `Observed` only when its current behavior is directly supported.
221
+ 6. Move uncertain policy intent to `unknowns-and-assumptions.md`.
222
+
223
+ ### 5. Reconstruct Supporting Docs
224
+
225
+ `system-overview.md`:
226
+ - scope summary
227
+ - actor summary
228
+ - module boundaries
229
+ - primary runtime entry points
230
+
231
+ `roles-and-permissions.md`:
232
+ - roles
233
+ - allowed/blocked actions
234
+ - permission checks and evidence
235
+ - unauthenticated/authenticated boundaries when visible
236
+
237
+ `entities-and-statuses.md`:
238
+ - entities/models
239
+ - important fields
240
+ - statuses/enums
241
+ - state transitions
242
+
243
+ `business-rules.md`:
244
+ - validations
245
+ - calculations
246
+ - branching conditions
247
+ - lifecycle rules
248
+ - non-obvious defaults and side effects
249
+
250
+ `integrations.md`:
251
+ - external APIs
252
+ - email/SMS/payment/file import/export
253
+ - batch/cron/queue/webhook behavior
254
+
255
+ `architecture-c4.md`:
256
+ - C4-style textual diagrams or Mermaid diagrams if useful
257
+ - system context
258
+ - container/component view for the selected scope
259
+ - runtime/deployment notes only when source evidence exists
260
+
261
+ `constraints-risks-and-decisions.md`:
262
+ - technical and business constraints observed in source/config
263
+ - recovered quality risks or technical debt that affect modernization review
264
+ - architecture decisions with rationale only when evidence exists
265
+ - explicitly unknown rationale when code shows the decision but not the reason
266
+
267
+ `glossary.md`:
268
+ - domain terms found in screens, schemas, routes, jobs, and tests
269
+ - source vocabulary aliases or unclear terms needing reviewer correction
270
+ - status/role labels that a reviewer should normalize before specs
271
+
272
+ `unknowns-and-assumptions.md`:
273
+ - uncertain areas
274
+ - inferred behavior needing human confirmation
275
+ - missing environment/runtime/data dependencies
276
+ - interview questions for customer/domain expert
277
+
278
+ ### 6. Cross-Document Consistency Review
279
+
280
+ Before declaring the bundle ready for review:
281
+
282
+ 1. Check that each as-is requirement has evidence or is explicitly unknown.
283
+ 2. Check that actors in requirements appear in roles/permissions or unknowns.
284
+ 3. Check that statuses and transitions match schemas/enums/rules found.
285
+ 4. Check that integrations listed in requirements appear in `integrations.md`.
286
+ 5. Check that architecture claims do not exceed evidence scope.
287
+ 6. Move future ideas and requested changes out of as-is docs.
288
+
289
+ ### 7. Build `overview.html`
290
+
291
+ Generate `overview.html` from the reconstruct overview template after the markdown bundle has enough evidence to summarize:
292
+
293
+ - scope, source revision, generated time, review status
294
+ - observed/inferred/unknown counts
295
+ - actor/module/external-system overview
296
+ - recovered requirement cards with evidence IDs
297
+ - entity/status summary
298
+ - business rule/integration summary
299
+ - human review queue and evidence trace
300
+
301
+ Do not put unique facts only in HTML. Every overview claim must be traceable to markdown/JSON evidence.
302
+
303
+ ### 8. Build `reconstruction.json`
304
+
305
+ Use this machine-readable summary:
306
+
307
+ ```json
308
+ {
309
+ "scope": "<scope>",
310
+ "generated_at": "<ISO timestamp>",
311
+ "status": "draft",
312
+ "docs_root": "docs/as-is/<scope-slug>",
313
+ "source_revision": "<git commit or unavailable reason>",
314
+ "source_branch": "<branch or unavailable reason>",
315
+ "evidence_policy": "observed-inferred-unknown",
316
+ "review_gate": "human_review_required",
317
+ "review_status": "pending",
318
+ "reviewed_by": null,
319
+ "reviewed_at": null,
320
+ "approved_for_specs": false,
321
+ "source_scope": [
322
+ "<scope>"
323
+ ],
324
+ "documents": [
325
+ "overview.html",
326
+ "system-overview.md",
327
+ "requirements-as-is.md",
328
+ "roles-and-permissions.md",
329
+ "entities-and-statuses.md",
330
+ "business-rules.md",
331
+ "integrations.md",
332
+ "architecture-c4.md",
333
+ "constraints-risks-and-decisions.md",
334
+ "glossary.md",
335
+ "evidence-map.md",
336
+ "unknowns-and-assumptions.md"
337
+ ],
338
+ "counts": {
339
+ "requirements": 0,
340
+ "evidence_items": 0,
341
+ "observed": 0,
342
+ "inferred": 0,
343
+ "unknown": 0,
344
+ "open_unknowns": 0
345
+ },
346
+ "next_recommended_step": "human_review"
347
+ }
348
+ ```
349
+
350
+ If Git revision data is unavailable, record an explicit reason in `source_revision` instead of leaving the source snapshot blank.
351
+
352
+ ### 9. Validate Bundle
353
+
354
+ Run the deterministic gate before human review:
355
+
356
+ ```text
357
+ node .claude/scripts/validate-docs-reconstruct.cjs docs/as-is/<scope-slug>
358
+ ```
359
+
360
+ Validator failure blocks the handoff. Fix:
361
+
362
+ - missing bundle files
363
+ - incomplete `reconstruction.json` registry/review metadata
364
+ - requirements missing type/confidence/evidence IDs
365
+ - evidence IDs missing from `evidence-map.md`
366
+ - overview output missing its review-surface marker
367
+
368
+ ### 10. Human Review Gate
369
+
370
+ End with a clear review prompt:
371
+
372
+ - confirm observed requirements
373
+ - correct inferred behavior
374
+ - answer unknowns
375
+ - add business rules that are not present in code
376
+
377
+ Do not recommend `/hapo:develop`.
378
+
379
+ Do not call the output approved until human review has resolved high-impact inferred and unknown behavior.
380
+
381
+ Recommended handoff after review:
382
+
383
+ ```text
384
+ /hapo:specs <modernization/change request based on approved docs/as-is/<scope-slug>>
385
+ ```
386
+
387
+ ## Guardrails
388
+
389
+ - Do not invent missing behavior.
390
+ - Do not collapse `Inferred` into `Observed`.
391
+ - Do not omit unknowns to make the report look complete.
392
+ - Do not describe future improvements inside as-is docs.
393
+ - Do not create tasks or implementation plans.
394
+ - Do not read ignored/generated/sensitive paths such as `.git`, `node_modules`, `dist`, `build`, `.next`, `coverage`, `.env`, secrets, or private dumps.
395
+ - Do not trust stale docs without source verification.
396
+ - Do not use route names, enum names, or comments alone to claim business intent when rule execution is not traced.
397
+ - Do not treat HTML as source of truth; it is a visual layer over evidence-backed docs.
398
+
399
+ ## Best-Practice Basis
400
+
401
+ Apply:
402
+
403
+ - Docs as Code: commit docs with source.
404
+ - C4: capture architecture at the right abstraction level.
405
+ - arc42: preserve context, building blocks, runtime behavior, risks, and decisions.
406
+ - Diataxis: separate explanation/reference/how-to content.
407
+ - ADR discipline: record recovered decisions as evidence-backed notes, not guesses.
@@ -0,0 +1,124 @@
1
+ # Standard Docs Workflow
2
+
3
+ Use this shared contract for `/hapo:docs init`, `/hapo:docs update`, and `/hapo:docs summarize`.
4
+
5
+ Then load the mode-specific reference:
6
+
7
+ - `init-workflow.md`
8
+ - `update-workflow.md`
9
+ - `summarize-workflow.md`
10
+
11
+ ## Purpose
12
+
13
+ Create or refresh living project documentation from the current repository.
14
+
15
+ This workflow is for normal project docs. If the user asks to reconstruct current behavior from a legacy/existing system, use `reconstruct-workflow.md` instead.
16
+
17
+ ## Inputs
18
+
19
+ - `README.md`
20
+ - existing `docs/` files
21
+ - package manifests and workspace config
22
+ - source directories such as `src/`, `app/`, `apps/`, `packages/`, `lib/`
23
+ - tests, build scripts, CI config, deployment config
24
+
25
+ ## Output Files
26
+
27
+ Use the docs root from `.claude/runtime.json` (`paths.docs`, default `docs`).
28
+
29
+ Recommended files:
30
+
31
+ ```text
32
+ docs/
33
+ ├── project-overview-pdr.md
34
+ ├── codebase-summary.md
35
+ ├── system-architecture.md
36
+ ├── code-standards.md
37
+ ├── design-guidelines.md
38
+ ├── deployment-guide.md
39
+ └── project-roadmap.md
40
+ ```
41
+
42
+ Create only files that are useful. Minimum viable documentation is preferred over a large stale docs set.
43
+
44
+ ## Shared Workflow Decisions
45
+
46
+ ### 1. Decide Operation
47
+
48
+ `init`:
49
+ - docs missing or clearly incomplete
50
+ - create baseline docs
51
+
52
+ `update`:
53
+ - docs exist
54
+ - compare recent code changes and update only affected docs
55
+
56
+ `summarize`:
57
+ - update only `codebase-summary.md`
58
+
59
+ ### 2. Scout And Verify
60
+
61
+ Normal docs are current-state living docs. Ground them in:
62
+
63
+ - repo instructions
64
+ - existing docs and README
65
+ - package/workspace/build/runtime config
66
+ - source code that implements the documented behavior
67
+ - tests, CI, deploy config, schemas, migrations, routes when relevant
68
+
69
+ Use `hapo:inspect` or targeted `rg`/file reads when the project is large. Keep broad scanning scoped by real project areas.
70
+
71
+ ### 3. Author Concisely
72
+
73
+ Follow these rules:
74
+
75
+ - prefer short sections over huge narrative
76
+ - document real code, not aspirations
77
+ - keep generated docs easy to review
78
+ - include unresolved questions at the end
79
+ - remove or rewrite stale claims when evidence contradicts existing docs
80
+ - verify paths, commands, config keys, endpoints, and symbols before naming them
81
+
82
+ ### 4. Keep The Core Docs Legible
83
+
84
+ The Research docs workflow uses a size check after generation and update. CafeKit keeps that rule:
85
+
86
+ - read `docs.maxLoc` from session/runtime context when available
87
+ - default to 800 lines per markdown document
88
+ - split large topics by semantic boundary instead of expanding one omnibus file
89
+
90
+ ### 5. Sync Tracking
91
+
92
+ If the project uses `docs/.sync_hash`, update it only after docs accurately reflect the current source state.
93
+
94
+ Use the same docs root as runtime config:
95
+
96
+ ```text
97
+ <docs-root>/.sync_hash
98
+ ```
99
+
100
+ ### 6. Validate
101
+
102
+ When available, run:
103
+
104
+ ```text
105
+ node .claude/scripts/validate-docs.cjs <docs-root>
106
+ ```
107
+
108
+ Use validation output to catch broken internal doc links before reporting.
109
+
110
+ ### 7. Final Report
111
+
112
+ Report:
113
+
114
+ - files created/updated
115
+ - code areas reviewed
116
+ - stale docs corrected
117
+ - unresolved questions
118
+
119
+ ## Guardrails
120
+
121
+ - Do not run broad full-repo reads when targeted scout is enough.
122
+ - Do not invent architecture from folder names alone.
123
+ - Do not modify product code.
124
+ - Do not overwrite user-written docs without reading them first.
@@ -0,0 +1,89 @@
1
+ # Summarize Workflow
2
+
3
+ Use with `/hapo:docs summarize`.
4
+
5
+ ## Goal
6
+
7
+ Create or refresh the fastest reliable project orientation artifact:
8
+
9
+ ```text
10
+ <docs-root>/codebase-summary.md
11
+ ```
12
+
13
+ This mode is intentionally smaller than `init` and `update`.
14
+
15
+ ## Inputs
16
+
17
+ - docs root from `.claude/runtime.json` (`paths.docs`, default `docs`)
18
+ - existing `codebase-summary.md`, if present
19
+ - user focus topics, if provided
20
+ - narrowly selected source evidence
21
+
22
+ ## Argument Semantics
23
+
24
+ Treat the prompt after `summarize` as focus:
25
+
26
+ | User request | Behavior |
27
+ |---|---|
28
+ | no focus | summarize current high-level project map |
29
+ | module/path focus | summarize only that area plus its dependencies |
30
+ | explicit "scan codebase" | scout the source layout before summarizing |
31
+
32
+ Do not scan the entire codebase just because summary mode was selected.
33
+
34
+ ## Workflow
35
+
36
+ ### Phase 1: Read Current Summary
37
+
38
+ 1. Read repo instructions.
39
+ 2. Read existing `codebase-summary.md` if present.
40
+ 3. Identify stale claims or missing focus areas relevant to the request.
41
+
42
+ ### Phase 2: Focused Scout
43
+
44
+ Read the smallest evidence set needed:
45
+
46
+ - top-level manifests and README for project identity
47
+ - the focused module/path if user supplied one
48
+ - runtime entry points and dependency boundaries needed to orient readers
49
+ - tests/config only when they clarify behavior or commands
50
+
51
+ Use `hapo:inspect` only if the relevant path is unclear. For a broad explicit scan, apply inspect scope gating first.
52
+
53
+ ### Phase 3: Write Summary
54
+
55
+ Update only `codebase-summary.md`.
56
+
57
+ Recommended sections:
58
+
59
+ 1. project identity and current purpose
60
+ 2. tech stack and commands verified from manifests/config
61
+ 3. source layout and major boundaries
62
+ 4. runtime entry points and key flows
63
+ 5. data/integration notes when directly relevant
64
+ 6. links to deeper docs that already exist
65
+ 7. unresolved questions
66
+
67
+ Keep the result usable as an orientation document, not as a requirements spec.
68
+
69
+ ### Phase 4: Validate
70
+
71
+ 1. Validate docs links with `.claude/scripts/validate-docs.cjs <docs-root>` when available.
72
+ 2. Respect docs size discipline; split only if summary has become a long handbook and the user asked for that work.
73
+
74
+ ## Guardrails
75
+
76
+ - Do not update every docs file.
77
+ - Do not reconstruct legacy requirements in summary mode.
78
+ - Do not implement code.
79
+ - Do not convert weak source hints into verified behavior.
80
+
81
+ ## Required Final Report
82
+
83
+ Report:
84
+
85
+ - summary path
86
+ - focus used
87
+ - evidence read
88
+ - validation result
89
+ - unresolved questions