@pigcloud/skills 1.0.3 → 1.0.4
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/CHANGELOG.md +4 -4
- package/README.en.md +74 -83
- package/README.md +74 -85
- package/bin/cli.js +34 -35
- package/bin/postinstall.js +1 -1
- package/package.json +1 -1
- package/rules/skill-profile-map.json +5 -5
- package/rules/skill-profile-map.md +2 -2
- package/scripts/validate-skill-shapes.js +2 -1
- package/skills/api-docs/SKILL.md +2 -2
- package/skills/domain-modeling/SKILL.md +4 -4
- package/skills/extract-business-facts/SKILL.md +336 -0
- package/skills/extract-business-facts/scripts/write-knowledge-base.js +227 -0
- package/skills/knowledge-capture/SKILL.md +16 -7
- package/skills/project-bootstrap/SKILL.md +2 -2
- package/skills/references/business-fact-extraction.md +414 -0
- package/skills/references/golden-prompt-suite.js +64 -14
- package/skills/references/rule-loading-map.md +18 -18
- package/skills/references/skill-authoring-standard.md +2 -2
- package/skills/references/skill-boundary-template.md +56 -23
- package/skills/references/skill-enhanced-template.md +80 -30
- package/skills/references/skill-reference-matrix.md +21 -20
- package/skills/{spec-refinement → spec}/SKILL.md +19 -14
- package/skills/technical-design/SKILL.md +4 -4
- package/pig-cloud-skills-commands/.codex-plugin/plugin.json +0 -35
- package/pig-cloud-skills-commands/README.md +0 -24
- package/pig-cloud-skills-commands/commands/analyze.md +0 -21
- package/pig-cloud-skills-commands/commands/build.md +0 -21
- package/pig-cloud-skills-commands/commands/design.md +0 -21
- package/pig-cloud-skills-commands/commands/distill.md +0 -21
- package/pig-cloud-skills-commands/commands/doc.md +0 -21
- package/pig-cloud-skills-commands/commands/infra.md +0 -21
- package/pig-cloud-skills-commands/commands/init.md +0 -20
- package/pig-cloud-skills-commands/commands/kb.md +0 -20
- package/pig-cloud-skills-commands/commands/perf.md +0 -20
- package/pig-cloud-skills-commands/commands/prd.md +0 -21
- package/pig-cloud-skills-commands/commands/review.md +0 -21
- package/pig-cloud-skills-commands/commands/security.md +0 -21
- package/pig-cloud-skills-commands/commands/test.md +0 -21
- package/pig-cloud-skills-commands/commands/workflow.md +0 -20
- package/skills/product-intake/SKILL.md +0 -98
- package/skills/references/agent-personas.md +0 -34
- package/skills/references/flow-test-cases.md +0 -62
- package/skills/references/full-chain-replay-scenarios.md +0 -79
- package/skills/references/hooks.md +0 -67
- package/skills/references/negative-replay-scenarios.md +0 -49
- package/skills/references/prompt-replay-checklist.md +0 -128
- package/skills/references/requirements-separation-map.md +0 -71
- package/skills/references/slash-commands.md +0 -34
- package/skills/spec-refinement/references/ears-syntax.md +0 -127
- package/skills/spec-refinement/references/requirement-checklist.md +0 -139
- package/skills/spec-refinement/references/spec-workbook.md +0 -75
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: extract-business-facts
|
|
3
|
+
description: Extract business facts, current behaviors, invariants, and terminology from code, tests, logs, and docs when Codex needs to reverse-engineer what the system actually does or prepare evidence-backed input for domain modeling, spec refinement, or knowledge capture.
|
|
4
|
+
lifecycle_stage: analysis
|
|
5
|
+
rule_profile: modeling
|
|
6
|
+
dependencies: []
|
|
7
|
+
triggers:
|
|
8
|
+
- reverse engineer behavior
|
|
9
|
+
- business facts
|
|
10
|
+
- current behavior
|
|
11
|
+
- code facts
|
|
12
|
+
- extract facts from code
|
|
13
|
+
- behavior map
|
|
14
|
+
inputs:
|
|
15
|
+
- code paths
|
|
16
|
+
- tests
|
|
17
|
+
- logs
|
|
18
|
+
- docs
|
|
19
|
+
- schemas
|
|
20
|
+
- runtime evidence
|
|
21
|
+
outputs:
|
|
22
|
+
- code fact map
|
|
23
|
+
- business fact map
|
|
24
|
+
- codewiki delta
|
|
25
|
+
- handoff notes
|
|
26
|
+
- knowledge-base file targets
|
|
27
|
+
workflow:
|
|
28
|
+
- collect code, test, doc, and runtime evidence for the requested area
|
|
29
|
+
- extract code facts first, then derive business meaning, then propose CodeWiki updates
|
|
30
|
+
- mark each fact as evidence-backed, inferred, or unknown
|
|
31
|
+
- summarize gaps, contradictions, and open questions
|
|
32
|
+
- choose the destination knowledge-base files before writing the final note
|
|
33
|
+
- hand off to domain-modeling, spec, or knowledge-capture
|
|
34
|
+
gates:
|
|
35
|
+
- stop at fact extraction
|
|
36
|
+
- do not design a new solution
|
|
37
|
+
- do not rewrite the PRD
|
|
38
|
+
- do not generate code
|
|
39
|
+
refs:
|
|
40
|
+
- skills/references/business-fact-extraction.md
|
|
41
|
+
- skills/references/skill-reference-matrix.md
|
|
42
|
+
- skills/references/rule-loading-map.md
|
|
43
|
+
- docs/codewiki-knowledge-base.md
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
# Extract Business Facts
|
|
47
|
+
|
|
48
|
+
## Purpose
|
|
49
|
+
|
|
50
|
+
Turn code-backed evidence into reusable business facts.
|
|
51
|
+
|
|
52
|
+
## Suitable / Unsuitable
|
|
53
|
+
|
|
54
|
+
- Suitable: reverse engineering, current behavior mapping, business rule extraction, terminology normalization, evidence-backed summaries
|
|
55
|
+
- Unsuitable: PRD drafting, solution design, implementation, review, final knowledge capture
|
|
56
|
+
|
|
57
|
+
## Quick Start
|
|
58
|
+
|
|
59
|
+
- Start from code paths, tests, docs, runtime traces, and schemas.
|
|
60
|
+
- Produce the output in three stages: code facts, business facts, and CodeWiki updates.
|
|
61
|
+
- Keep evidence, inference, and unknowns distinct.
|
|
62
|
+
- Hand off the result when the facts are stable enough for `domain-modeling`, `spec`, or `knowledge-capture`.
|
|
63
|
+
|
|
64
|
+
## Write Back
|
|
65
|
+
|
|
66
|
+
- When the user wants persistence, render the staged output into a JSON fact pack.
|
|
67
|
+
- Use `skills/extract-business-facts/scripts/write-knowledge-base.js` to write the pack into the knowledge-base files.
|
|
68
|
+
- Keep the pack keyed by target file path under `knowledge-base/`.
|
|
69
|
+
- Write only the smallest matching file for each fact.
|
|
70
|
+
- Treat the script as a writer, not as a second analysis pass.
|
|
71
|
+
|
|
72
|
+
## Inputs / Outputs
|
|
73
|
+
|
|
74
|
+
- Inputs:
|
|
75
|
+
- code paths
|
|
76
|
+
- tests
|
|
77
|
+
- logs
|
|
78
|
+
- docs
|
|
79
|
+
- schemas
|
|
80
|
+
- runtime evidence
|
|
81
|
+
- Outputs:
|
|
82
|
+
- code fact map
|
|
83
|
+
- business fact map
|
|
84
|
+
- codewiki delta
|
|
85
|
+
- handoff notes
|
|
86
|
+
- knowledge-base file targets
|
|
87
|
+
|
|
88
|
+
## Output Template
|
|
89
|
+
|
|
90
|
+
### 1. Code Facts
|
|
91
|
+
|
|
92
|
+
#### `knowledge-base/realtime-code/modules.md`
|
|
93
|
+
|
|
94
|
+
- module:
|
|
95
|
+
- current responsibility:
|
|
96
|
+
- key entry points:
|
|
97
|
+
- important constraints:
|
|
98
|
+
- last verified:
|
|
99
|
+
|
|
100
|
+
#### `knowledge-base/realtime-code/flows.md`
|
|
101
|
+
|
|
102
|
+
- flow name:
|
|
103
|
+
- trigger:
|
|
104
|
+
- path:
|
|
105
|
+
- output:
|
|
106
|
+
- failure points:
|
|
107
|
+
- notes:
|
|
108
|
+
|
|
109
|
+
#### `knowledge-base/realtime-code/runtime-notes.md`
|
|
110
|
+
|
|
111
|
+
- fact:
|
|
112
|
+
- evidence:
|
|
113
|
+
- affected area:
|
|
114
|
+
- date:
|
|
115
|
+
- notes:
|
|
116
|
+
|
|
117
|
+
### 2. Business Facts
|
|
118
|
+
|
|
119
|
+
#### `knowledge-base/requirements/decisions.md`
|
|
120
|
+
|
|
121
|
+
- decision:
|
|
122
|
+
- reason:
|
|
123
|
+
- date or context:
|
|
124
|
+
- affected artifact:
|
|
125
|
+
- notes:
|
|
126
|
+
|
|
127
|
+
#### `knowledge-base/requirements/acceptance.md`
|
|
128
|
+
|
|
129
|
+
- requirement:
|
|
130
|
+
- acceptance criteria:
|
|
131
|
+
- out of scope:
|
|
132
|
+
- open questions:
|
|
133
|
+
- confirmed by:
|
|
134
|
+
|
|
135
|
+
#### `knowledge-base/requirements/conflicts.md`
|
|
136
|
+
|
|
137
|
+
- conflict:
|
|
138
|
+
- source:
|
|
139
|
+
- impact:
|
|
140
|
+
- resolution:
|
|
141
|
+
- status:
|
|
142
|
+
|
|
143
|
+
### 3. CodeWiki Update
|
|
144
|
+
|
|
145
|
+
#### `knowledge-base/codewiki/overview.md`
|
|
146
|
+
|
|
147
|
+
- one-line summary:
|
|
148
|
+
- what the system does:
|
|
149
|
+
- what changed:
|
|
150
|
+
- why it matters:
|
|
151
|
+
|
|
152
|
+
#### `knowledge-base/codewiki/architecture.md`
|
|
153
|
+
|
|
154
|
+
- layers:
|
|
155
|
+
- boundaries:
|
|
156
|
+
- dependencies:
|
|
157
|
+
- major integration points:
|
|
158
|
+
|
|
159
|
+
#### `knowledge-base/codewiki/modules.md`
|
|
160
|
+
|
|
161
|
+
- module name:
|
|
162
|
+
- responsibility:
|
|
163
|
+
- main interfaces:
|
|
164
|
+
- related runtime facts:
|
|
165
|
+
|
|
166
|
+
#### `knowledge-base/codewiki/flows.md`
|
|
167
|
+
|
|
168
|
+
- request flow:
|
|
169
|
+
- data flow:
|
|
170
|
+
- error flow:
|
|
171
|
+
- handoff flow:
|
|
172
|
+
|
|
173
|
+
#### `knowledge-base/codewiki/api.md`
|
|
174
|
+
|
|
175
|
+
- endpoint or contract:
|
|
176
|
+
- request shape:
|
|
177
|
+
- response shape:
|
|
178
|
+
- constraints:
|
|
179
|
+
|
|
180
|
+
#### `knowledge-base/codewiki/runbook.md`
|
|
181
|
+
|
|
182
|
+
- startup:
|
|
183
|
+
- verify:
|
|
184
|
+
- troubleshoot:
|
|
185
|
+
- recover:
|
|
186
|
+
|
|
187
|
+
#### `knowledge-base/codewiki/conventions.md`
|
|
188
|
+
|
|
189
|
+
- naming:
|
|
190
|
+
- layering:
|
|
191
|
+
- error handling:
|
|
192
|
+
- logging:
|
|
193
|
+
- data handling:
|
|
194
|
+
|
|
195
|
+
### 4. Enterprise Note
|
|
196
|
+
|
|
197
|
+
#### `knowledge-base/enterprise/decisions.md`
|
|
198
|
+
|
|
199
|
+
- decision:
|
|
200
|
+
- reason:
|
|
201
|
+
- scope:
|
|
202
|
+
- date:
|
|
203
|
+
- reusable lesson:
|
|
204
|
+
|
|
205
|
+
#### `knowledge-base/enterprise/pitfalls.md`
|
|
206
|
+
|
|
207
|
+
- pitfall:
|
|
208
|
+
- context:
|
|
209
|
+
- why it failed:
|
|
210
|
+
- how to avoid it:
|
|
211
|
+
|
|
212
|
+
#### `knowledge-base/enterprise/examples.md`
|
|
213
|
+
|
|
214
|
+
- example:
|
|
215
|
+
- context:
|
|
216
|
+
- lesson:
|
|
217
|
+
- reusable pattern:
|
|
218
|
+
|
|
219
|
+
#### `knowledge-base/enterprise/ai-coding-rules.md`
|
|
220
|
+
|
|
221
|
+
- rule:
|
|
222
|
+
- when it applies:
|
|
223
|
+
- why it matters:
|
|
224
|
+
- examples:
|
|
225
|
+
|
|
226
|
+
## Sample Output
|
|
227
|
+
|
|
228
|
+
### Code Facts
|
|
229
|
+
|
|
230
|
+
#### `knowledge-base/realtime-code/modules.md`
|
|
231
|
+
|
|
232
|
+
- module: `order-service`
|
|
233
|
+
- current responsibility: creates orders and reserves inventory
|
|
234
|
+
- key entry points: `createOrder()`, `reserveInventory()`
|
|
235
|
+
- important constraints: stock must be checked before commit
|
|
236
|
+
- last verified: 2026-06-22
|
|
237
|
+
|
|
238
|
+
#### `knowledge-base/realtime-code/flows.md`
|
|
239
|
+
|
|
240
|
+
- flow name: checkout order placement
|
|
241
|
+
- trigger: user confirms checkout
|
|
242
|
+
- path: validate stock -> reserve inventory -> create order
|
|
243
|
+
- output: confirmed order or shortage error
|
|
244
|
+
- failure points: stock shortage, reservation failure
|
|
245
|
+
- notes: reservation must happen before the order commit
|
|
246
|
+
|
|
247
|
+
### Business Facts
|
|
248
|
+
|
|
249
|
+
#### `knowledge-base/requirements/decisions.md`
|
|
250
|
+
|
|
251
|
+
- decision: inventory must be reserved before order confirmation
|
|
252
|
+
- reason: avoid overselling
|
|
253
|
+
- date or context: 2026-06-22, order flow review
|
|
254
|
+
- affected artifact: checkout spec
|
|
255
|
+
- notes: failure should return a clear stock shortage message
|
|
256
|
+
|
|
257
|
+
#### `knowledge-base/requirements/acceptance.md`
|
|
258
|
+
|
|
259
|
+
- requirement: checkout must not confirm an order when stock is unavailable
|
|
260
|
+
- acceptance criteria: shortage blocks confirmation and returns a clear message
|
|
261
|
+
- out of scope: backorder design
|
|
262
|
+
- open questions: whether to retry reservation automatically
|
|
263
|
+
- confirmed by: order flow review
|
|
264
|
+
|
|
265
|
+
### CodeWiki Update
|
|
266
|
+
|
|
267
|
+
#### `knowledge-base/codewiki/flows.md`
|
|
268
|
+
|
|
269
|
+
- request flow: checkout -> validate stock -> reserve inventory -> create order
|
|
270
|
+
- data flow: cart snapshot -> reservation record -> order record
|
|
271
|
+
- error flow: stock shortage -> stop checkout -> return shortage reason
|
|
272
|
+
- handoff flow: checkout service hands off to inventory service and order repository
|
|
273
|
+
|
|
274
|
+
#### `knowledge-base/codewiki/modules.md`
|
|
275
|
+
|
|
276
|
+
- module name: `order-service`
|
|
277
|
+
- responsibility: coordinates checkout and order creation
|
|
278
|
+
- main interfaces: `createOrder()`, `reserveInventory()`
|
|
279
|
+
- related runtime facts: inventory must be reserved before commit
|
|
280
|
+
|
|
281
|
+
### Enterprise Note
|
|
282
|
+
|
|
283
|
+
#### `knowledge-base/enterprise/pitfalls.md`
|
|
284
|
+
|
|
285
|
+
- pitfall: reservation happens after order creation
|
|
286
|
+
- context: checkout path
|
|
287
|
+
- why it failed: allowed overselling under concurrent requests
|
|
288
|
+
- how to avoid it: reserve before committing the order
|
|
289
|
+
|
|
290
|
+
#### `knowledge-base/enterprise/ai-coding-rules.md`
|
|
291
|
+
|
|
292
|
+
- rule: reserve inventory before committing the order
|
|
293
|
+
- when it applies: any checkout flow that can oversell
|
|
294
|
+
- why it matters: keeps business state consistent under concurrency
|
|
295
|
+
- examples: validate stock, reserve, then create the order
|
|
296
|
+
|
|
297
|
+
## Workflow
|
|
298
|
+
|
|
299
|
+
1. Collect code, test, doc, and runtime evidence for the requested area.
|
|
300
|
+
2. Write the code fact map with observed behavior, state changes, contracts, and evidence.
|
|
301
|
+
3. Derive the business fact map from the code facts and separate inference from proof.
|
|
302
|
+
4. Draft the CodeWiki delta with reusable architecture, flow, and convention updates.
|
|
303
|
+
5. Map each section to the exact knowledge-base files it should update.
|
|
304
|
+
6. Mark each fact as evidence-backed, inferred, or unknown.
|
|
305
|
+
7. Summarize gaps, contradictions, and open questions.
|
|
306
|
+
8. Hand off to `domain-modeling`, `spec`, or `knowledge-capture`.
|
|
307
|
+
|
|
308
|
+
## Replay Signals
|
|
309
|
+
|
|
310
|
+
- Input signal: codebase walkthrough, behavior reconstruction, business rule extraction, or current-state analysis.
|
|
311
|
+
- Output to verify: code fact map, business fact map, codewiki delta, file targets, gap list.
|
|
312
|
+
- Stop signal: solution design, PRD rewriting, or code generation.
|
|
313
|
+
- Handoff signal: the extracted facts are stable enough for downstream modeling or capture.
|
|
314
|
+
|
|
315
|
+
## Gotchas
|
|
316
|
+
|
|
317
|
+
- Do not infer business intent from comments alone.
|
|
318
|
+
- Do not merge evidence-backed facts and assumptions into one claim.
|
|
319
|
+
- Do not skip contradictory evidence.
|
|
320
|
+
- Do not turn extraction into design.
|
|
321
|
+
- Do not write the CodeWiki delta before the code facts are stable.
|
|
322
|
+
- Do not leave file targets implicit.
|
|
323
|
+
|
|
324
|
+
## Stop Rules
|
|
325
|
+
|
|
326
|
+
- Stop at fact extraction.
|
|
327
|
+
- Do not design a new solution.
|
|
328
|
+
- Do not rewrite the PRD.
|
|
329
|
+
- Do not generate code.
|
|
330
|
+
|
|
331
|
+
## References
|
|
332
|
+
|
|
333
|
+
- `skills/references/business-fact-extraction.md`
|
|
334
|
+
- `skills/references/skill-reference-matrix.md`
|
|
335
|
+
- `skills/references/rule-loading-map.md`
|
|
336
|
+
- `docs/codewiki-knowledge-base.md`
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
const REPO_ROOT = path.join(__dirname, '..', '..', '..');
|
|
7
|
+
const START_MARKER = '<!-- extract-business-facts:start -->';
|
|
8
|
+
const END_MARKER = '<!-- extract-business-facts:end -->';
|
|
9
|
+
|
|
10
|
+
const FILE_FIELD_ORDER = {
|
|
11
|
+
'knowledge-base/realtime-code/modules.md': ['module', 'current responsibility', 'key entry points', 'important constraints', 'last verified'],
|
|
12
|
+
'knowledge-base/realtime-code/flows.md': ['flow name', 'trigger', 'path', 'output', 'failure points', 'notes'],
|
|
13
|
+
'knowledge-base/realtime-code/runtime-notes.md': ['fact', 'evidence', 'affected area', 'date', 'notes'],
|
|
14
|
+
'knowledge-base/requirements/decisions.md': ['decision', 'reason', 'date or context', 'affected artifact', 'notes'],
|
|
15
|
+
'knowledge-base/requirements/acceptance.md': ['requirement', 'acceptance criteria', 'out of scope', 'open questions', 'confirmed by'],
|
|
16
|
+
'knowledge-base/requirements/conflicts.md': ['conflict', 'source', 'impact', 'resolution', 'status'],
|
|
17
|
+
'knowledge-base/codewiki/overview.md': ['one-line summary', 'what the system does', 'what changed', 'why it matters'],
|
|
18
|
+
'knowledge-base/codewiki/architecture.md': ['layers', 'boundaries', 'dependencies', 'major integration points'],
|
|
19
|
+
'knowledge-base/codewiki/modules.md': ['module name', 'responsibility', 'main interfaces', 'related runtime facts'],
|
|
20
|
+
'knowledge-base/codewiki/flows.md': ['request flow', 'data flow', 'error flow', 'handoff flow'],
|
|
21
|
+
'knowledge-base/codewiki/api.md': ['endpoint or contract', 'request shape', 'response shape', 'constraints'],
|
|
22
|
+
'knowledge-base/codewiki/runbook.md': ['startup', 'verify', 'troubleshoot', 'recover'],
|
|
23
|
+
'knowledge-base/codewiki/conventions.md': ['naming', 'layering', 'error handling', 'logging', 'data handling'],
|
|
24
|
+
'knowledge-base/enterprise/decisions.md': ['decision', 'reason', 'scope', 'date', 'reusable lesson'],
|
|
25
|
+
'knowledge-base/enterprise/pitfalls.md': ['pitfall', 'context', 'why it failed', 'how to avoid it'],
|
|
26
|
+
'knowledge-base/enterprise/examples.md': ['example', 'context', 'lesson', 'reusable pattern'],
|
|
27
|
+
'knowledge-base/enterprise/ai-coding-rules.md': ['rule', 'when it applies', 'why it matters', 'examples']
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const SAMPLE_PACK = {
|
|
31
|
+
files: {
|
|
32
|
+
'knowledge-base/realtime-code/modules.md': [
|
|
33
|
+
{
|
|
34
|
+
module: 'order-service',
|
|
35
|
+
'current responsibility': 'creates orders and reserves inventory',
|
|
36
|
+
'key entry points': 'createOrder(), reserveInventory()',
|
|
37
|
+
'important constraints': 'stock must be checked before commit',
|
|
38
|
+
'last verified': '2026-06-22'
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
'knowledge-base/requirements/decisions.md': [
|
|
42
|
+
{
|
|
43
|
+
decision: 'inventory must be reserved before order confirmation',
|
|
44
|
+
reason: 'avoid overselling',
|
|
45
|
+
'date or context': '2026-06-22, order flow review',
|
|
46
|
+
'affected artifact': 'checkout spec',
|
|
47
|
+
notes: 'failure should return a clear stock shortage message'
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
'knowledge-base/codewiki/flows.md': [
|
|
51
|
+
{
|
|
52
|
+
'request flow': 'checkout -> validate stock -> reserve inventory -> create order',
|
|
53
|
+
'data flow': 'cart snapshot -> reservation record -> order record',
|
|
54
|
+
'error flow': 'stock shortage -> stop checkout -> return shortage reason',
|
|
55
|
+
'handoff flow': 'checkout service hands off to inventory service and order repository'
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
'knowledge-base/enterprise/pitfalls.md': [
|
|
59
|
+
{
|
|
60
|
+
pitfall: 'reservation happens after order creation',
|
|
61
|
+
context: 'checkout path',
|
|
62
|
+
'why it failed': 'allowed overselling under concurrent requests',
|
|
63
|
+
'how to avoid it': 'reserve before committing the order'
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
function parseArgs(argv) {
|
|
70
|
+
const args = {
|
|
71
|
+
input: null,
|
|
72
|
+
root: REPO_ROOT,
|
|
73
|
+
dryRun: false,
|
|
74
|
+
sample: false
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
78
|
+
const token = argv[index];
|
|
79
|
+
if (token === '--input' || token === '-i') {
|
|
80
|
+
args.input = argv[++index];
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (token.startsWith('--input=')) {
|
|
84
|
+
args.input = token.slice('--input='.length);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (token === '--root' || token === '-r') {
|
|
88
|
+
args.root = path.resolve(argv[++index]);
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (token.startsWith('--root=')) {
|
|
92
|
+
args.root = path.resolve(token.slice('--root='.length));
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (token === '--dry-run') {
|
|
96
|
+
args.dryRun = true;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (token === '--sample') {
|
|
100
|
+
args.sample = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return args;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function readInput(inputPath) {
|
|
109
|
+
if (!inputPath || inputPath === '-') {
|
|
110
|
+
return fs.readFileSync(0, 'utf8');
|
|
111
|
+
}
|
|
112
|
+
return fs.readFileSync(inputPath, 'utf8');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function loadPack(inputText) {
|
|
116
|
+
const parsed = JSON.parse(String(inputText).replace(/^\uFEFF/, ''));
|
|
117
|
+
if (parsed && typeof parsed === 'object' && parsed.files && typeof parsed.files === 'object') {
|
|
118
|
+
return parsed.files;
|
|
119
|
+
}
|
|
120
|
+
if (parsed && typeof parsed === 'object') {
|
|
121
|
+
return parsed;
|
|
122
|
+
}
|
|
123
|
+
throw new Error('Input must be a JSON object.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function normalizeValue(value) {
|
|
127
|
+
if (value === null || value === undefined || value === '') return 'unknown';
|
|
128
|
+
if (Array.isArray(value)) return value.map(item => normalizeValue(item)).join(', ');
|
|
129
|
+
if (typeof value === 'object') return JSON.stringify(value);
|
|
130
|
+
return String(value).trim() || 'unknown';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderEntry(fields, entry) {
|
|
134
|
+
return fields.map(field => `- ${field}: ${normalizeValue(entry[field])}`).join('\n');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function renderFileSection(relativePath, entries) {
|
|
138
|
+
const fieldOrder = FILE_FIELD_ORDER[relativePath];
|
|
139
|
+
if (!fieldOrder) {
|
|
140
|
+
throw new Error(`Unsupported target file: ${relativePath}`);
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(entries) || entries.length === 0) {
|
|
143
|
+
throw new Error(`No entries provided for ${relativePath}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const blocks = entries.map(entry => renderEntry(fieldOrder, entry));
|
|
147
|
+
return [
|
|
148
|
+
'## Generated Entries',
|
|
149
|
+
START_MARKER,
|
|
150
|
+
blocks.join('\n\n'),
|
|
151
|
+
END_MARKER
|
|
152
|
+
].join('\n');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function upsertGeneratedSection(existingContent, generatedSection) {
|
|
156
|
+
const startIndex = existingContent.indexOf(START_MARKER);
|
|
157
|
+
const endIndex = existingContent.indexOf(END_MARKER);
|
|
158
|
+
|
|
159
|
+
if (startIndex >= 0 && endIndex >= 0 && endIndex > startIndex) {
|
|
160
|
+
const before = existingContent.slice(0, startIndex).trimEnd();
|
|
161
|
+
const after = existingContent.slice(endIndex + END_MARKER.length).trimStart();
|
|
162
|
+
const middle = generatedSection;
|
|
163
|
+
const parts = [before, middle];
|
|
164
|
+
if (after) {
|
|
165
|
+
parts.push(after);
|
|
166
|
+
}
|
|
167
|
+
return `${parts.filter(Boolean).join('\n\n').trimEnd()}\n`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const base = existingContent.trimEnd();
|
|
171
|
+
if (!base) {
|
|
172
|
+
return `${generatedSection}\n`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return `${base}\n\n${generatedSection}\n`;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function collectTargets(filePack) {
|
|
179
|
+
const targets = [];
|
|
180
|
+
for (const [relativePath, entries] of Object.entries(filePack)) {
|
|
181
|
+
if (!relativePath.startsWith('knowledge-base/')) {
|
|
182
|
+
throw new Error(`Refusing to write outside knowledge-base: ${relativePath}`);
|
|
183
|
+
}
|
|
184
|
+
targets.push({ relativePath, entries });
|
|
185
|
+
}
|
|
186
|
+
return targets;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function ensureParentDir(filePath) {
|
|
190
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function main() {
|
|
194
|
+
const args = parseArgs(process.argv.slice(2));
|
|
195
|
+
|
|
196
|
+
if (args.sample) {
|
|
197
|
+
process.stdout.write(`${JSON.stringify(SAMPLE_PACK, null, 2)}\n`);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const inputText = readInput(args.input);
|
|
202
|
+
const filePack = loadPack(inputText);
|
|
203
|
+
const targets = collectTargets(filePack);
|
|
204
|
+
|
|
205
|
+
for (const { relativePath, entries } of targets) {
|
|
206
|
+
const absolutePath = path.join(args.root, relativePath);
|
|
207
|
+
const generatedSection = renderFileSection(relativePath, entries);
|
|
208
|
+
const existingContent = fs.existsSync(absolutePath) ? fs.readFileSync(absolutePath, 'utf8') : '';
|
|
209
|
+
const nextContent = upsertGeneratedSection(existingContent, generatedSection);
|
|
210
|
+
|
|
211
|
+
if (args.dryRun) {
|
|
212
|
+
process.stdout.write(`=== ${relativePath} ===\n${nextContent}\n`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
ensureParentDir(absolutePath);
|
|
217
|
+
fs.writeFileSync(absolutePath, nextContent, 'utf8');
|
|
218
|
+
process.stdout.write(`Wrote ${relativePath}\n`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
main();
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error(error.message);
|
|
226
|
+
process.exitCode = 1;
|
|
227
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: knowledge-capture
|
|
3
|
-
description:
|
|
3
|
+
description: Capture reusable decisions, requirement knowledge, realtime code facts, CodeWiki facts, and handoff notes; use when an upstream task already produced evidence and you need to normalize it, persist it, or hand it off without redoing analysis.
|
|
4
4
|
lifecycle_stage: capture
|
|
5
5
|
rule_profile: capture
|
|
6
6
|
dependencies: []
|
|
@@ -15,21 +15,26 @@ inputs:
|
|
|
15
15
|
- approved artifacts
|
|
16
16
|
- findings
|
|
17
17
|
- decisions
|
|
18
|
+
- staged fact packs
|
|
18
19
|
outputs:
|
|
19
20
|
- reusable note
|
|
20
21
|
- knowledge page
|
|
21
22
|
- handoff summary
|
|
23
|
+
- knowledge-base write pack
|
|
22
24
|
workflow:
|
|
23
25
|
- collect the produced artifact
|
|
24
26
|
- normalize it into a reusable note
|
|
25
27
|
- separate requirement knowledge, realtime code facts, CodeWiki facts, and decision-log content
|
|
26
28
|
- link it to the originating skill
|
|
29
|
+
- when persistence is needed, convert the note into a knowledge-base fact pack and write it with the capture writer
|
|
27
30
|
- publish the handoff summary for downstream reuse
|
|
28
31
|
gates:
|
|
29
32
|
- stop at capture and organization
|
|
30
33
|
- do not redo upstream analysis
|
|
31
34
|
- do not generate new requirements or code
|
|
35
|
+
- do not rewrite the fact pack into a new analysis
|
|
32
36
|
refs:
|
|
37
|
+
- skills/references/business-fact-extraction.md
|
|
33
38
|
- skills/references/skill-reference-matrix.md
|
|
34
39
|
- skills/references/rule-loading-map.md
|
|
35
40
|
- skills/references/flow-test-cases.md
|
|
@@ -46,7 +51,7 @@ Store decisions, artifacts, and handoff notes so other skills can reuse them lat
|
|
|
46
51
|
|
|
47
52
|
## Suitable / Unsuitable
|
|
48
53
|
|
|
49
|
-
- Suitable: summaries, decision logs, reusable knowledge, artifact handoff, CodeWiki facts, requirements knowledge, realtime code facts
|
|
54
|
+
- Suitable: summaries, decision logs, reusable knowledge, artifact handoff, CodeWiki facts, requirements knowledge, realtime code facts, staged fact packs
|
|
50
55
|
- Unsuitable: requirement discovery, design, implementation, review, test authoring
|
|
51
56
|
|
|
52
57
|
## Workflow
|
|
@@ -55,12 +60,13 @@ Store decisions, artifacts, and handoff notes so other skills can reuse them lat
|
|
|
55
60
|
2. Normalize it into a reusable note.
|
|
56
61
|
3. Separate requirement knowledge, realtime code facts, CodeWiki facts, decision log entries, and pitfall notes.
|
|
57
62
|
4. Link it back to the originating skill.
|
|
58
|
-
5.
|
|
63
|
+
5. If the note should persist, map it to the knowledge-base file targets and write the fact pack.
|
|
64
|
+
6. Publish the handoff summary for downstream reuse.
|
|
59
65
|
|
|
60
66
|
## Replay Signals
|
|
61
67
|
|
|
62
|
-
- Input signal: approved artifacts, findings, or
|
|
63
|
-
- Output to verify: reusable note, knowledge page, handoff summary, decision log entry, codewiki update, enterprise knowledge note.
|
|
68
|
+
- Input signal: approved artifacts, findings, decisions, or staged fact packs.
|
|
69
|
+
- Output to verify: reusable note, knowledge page, handoff summary, decision log entry, codewiki update, enterprise knowledge note, knowledge-base write pack.
|
|
64
70
|
- Stop signal: redoing upstream analysis or generating new requirements/code.
|
|
65
71
|
- Handoff signal: the reusable note is ready for later reuse by other skills.
|
|
66
72
|
|
|
@@ -70,15 +76,18 @@ Store decisions, artifacts, and handoff notes so other skills can reuse them lat
|
|
|
70
76
|
- Do not redo upstream analysis.
|
|
71
77
|
- Do not generate new requirements or code.
|
|
72
78
|
- Do not merge requirement knowledge, code facts, and decisions into one blob.
|
|
79
|
+
- Do not treat persistence as a new analysis pass.
|
|
80
|
+
- Do not rewrite the fact pack into a new analysis.
|
|
73
81
|
|
|
74
82
|
## Examples
|
|
75
83
|
|
|
76
84
|
- Input: "Capture the decisions and pitfalls from this task."
|
|
77
|
-
- Output: reusable note, knowledge page, handoff summary
|
|
85
|
+
- Output: reusable note, knowledge page, handoff summary, optional knowledge-base write pack
|
|
78
86
|
- Stop: do not re-open the design or implementation debate
|
|
79
87
|
|
|
80
88
|
## References
|
|
81
89
|
|
|
90
|
+
- `skills/references/business-fact-extraction.md`
|
|
82
91
|
- `skills/references/skill-reference-matrix.md`
|
|
83
92
|
- `skills/references/rule-loading-map.md`
|
|
84
|
-
- `
|
|
93
|
+
- `docs/codewiki-knowledge-base.md`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: project-bootstrap
|
|
3
|
-
description: 当项目需要初始化时,为新工作区装载合适的技能和规则包
|
|
3
|
+
description: 当项目需要初始化时,为新工作区装载合适的技能和规则包
|
|
4
4
|
lifecycle_stage: scaffold
|
|
5
5
|
rule_profile: scaffold
|
|
6
6
|
dependencies: []
|
|
@@ -58,7 +58,7 @@ Create a new workspace with the right skills and rules layout.
|
|
|
58
58
|
- Input signal: client type, workspace markers, desired rules bundle.
|
|
59
59
|
- Output to verify: starter structure, installed bundle, setup notes.
|
|
60
60
|
- Stop signal: product scope design or application code generation.
|
|
61
|
-
- Handoff signal: the workspace is ready for `workflow-router` or `
|
|
61
|
+
- Handoff signal: the workspace is ready for `workflow-router` or `spec`.
|
|
62
62
|
|
|
63
63
|
## Examples
|
|
64
64
|
|