@drafthq/draft 3.2.1 → 3.3.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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +28 -0
- package/README.md +20 -2
- package/cli/src/hosts/cursor.js +35 -5
- package/cli/src/installer.js +12 -0
- package/cli/src/lib/cursor-registry.js +122 -0
- package/cli/src/lib/plugin-manifest.js +20 -0
- package/core/methodology.md +1 -1
- package/core/templates/okf/ai-context-index.md +48 -0
- package/core/templates/okf/concept.md +54 -0
- package/core/templates/okf/index.md +40 -0
- package/core/templates/okf/section-index.md +25 -0
- package/integrations/agents/AGENTS.md +452 -2
- package/integrations/copilot/.github/copilot-instructions.md +452 -2
- package/package.json +3 -2
- package/scripts/lib.sh +9 -0
- package/scripts/tools/graph-preflight.sh +259 -0
- package/scripts/tools/okf-render-views.sh +373 -0
- package/scripts/tools/okf-validate.sh +204 -0
- package/skills/init/SKILL.md +24 -1
- package/skills/init/references/okf-emitter.md +223 -0
- package/integrations/copilot/.github/copilot-instructions.md.7iDz8X +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.DoBdtd +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.McGoBW +0 -122
- package/integrations/copilot/.github/copilot-instructions.md.VsPyLB +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.XAVr7D +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.YoFVFa +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.a9DeW0 +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.oxQs3B +0 -91
- package/integrations/copilot/.github/copilot-instructions.md.ww33Ly +0 -91
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# okf-validate.sh — validate an OKF (Open Knowledge Format) taxonomy bundle.
|
|
3
|
+
#
|
|
4
|
+
# This is the deterministic ground-truth verifier for the `/draft:init` OKF
|
|
5
|
+
# emitter (DRAFT_INIT_MODE=okf). It fails the build on dangling cross-links,
|
|
6
|
+
# missing/invalid frontmatter, and an incomplete path→concept index, so a
|
|
7
|
+
# page-by-page generation pass cannot ship a structurally broken bundle.
|
|
8
|
+
#
|
|
9
|
+
# Checks:
|
|
10
|
+
# 1. BUNDLE_DIR exists and contains a root index.md.
|
|
11
|
+
# 2. Every concept page (any *.md whose frontmatter declares `type:`) carries
|
|
12
|
+
# all required OKF frontmatter keys: type, title, description, resource.
|
|
13
|
+
# 3. Every declared `type` is in the frozen code-repo vocabulary (§4 of HLD).
|
|
14
|
+
# 4. Every relative markdown cross-link ( ](path.md) ) resolves to a file that
|
|
15
|
+
# exists inside the bundle. External (http/https/mailto) and pure-anchor
|
|
16
|
+
# (#frag) links are ignored.
|
|
17
|
+
# 5. (optional) --path-index FILE: every concept page referenced by the
|
|
18
|
+
# path→concept index exists in the bundle (no dangle, no stale rename).
|
|
19
|
+
#
|
|
20
|
+
# Usage:
|
|
21
|
+
# scripts/tools/okf-validate.sh <BUNDLE_DIR> [--path-index FILE] [--json]
|
|
22
|
+
#
|
|
23
|
+
# Exit codes: 0 valid, 1 invalid (diagnostics to stderr), 2 bundle not found.
|
|
24
|
+
set -euo pipefail
|
|
25
|
+
|
|
26
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
27
|
+
# shellcheck source=scripts/tools/_lib.sh
|
|
28
|
+
source "$SCRIPT_DIR/_lib.sh"
|
|
29
|
+
|
|
30
|
+
# Frozen concept `type` vocabulary for code repos. Changing this churns every
|
|
31
|
+
# generated file, so it is versioned in the bundle (index.md: okf_types_version).
|
|
32
|
+
OKF_TYPES="Subsystem Module Feature Entrypoint API DataModel Dependency ADR Runbook"
|
|
33
|
+
|
|
34
|
+
BUNDLE=""
|
|
35
|
+
PATH_INDEX=""
|
|
36
|
+
JSON=0
|
|
37
|
+
|
|
38
|
+
usage() {
|
|
39
|
+
cat <<'EOF'
|
|
40
|
+
okf-validate.sh — validate an OKF taxonomy bundle (the /draft:init OKF emitter output).
|
|
41
|
+
|
|
42
|
+
Usage:
|
|
43
|
+
scripts/tools/okf-validate.sh <BUNDLE_DIR> [--path-index FILE] [--json]
|
|
44
|
+
|
|
45
|
+
Flags:
|
|
46
|
+
--path-index FILE Validate a path→concept index (JSON): every concept page it
|
|
47
|
+
names must exist in the bundle.
|
|
48
|
+
--json Emit a JSON summary instead of human diagnostics.
|
|
49
|
+
--help Show this help.
|
|
50
|
+
|
|
51
|
+
Exit 0 valid, 1 invalid, 2 bundle directory not found.
|
|
52
|
+
EOF
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
while [[ $# -gt 0 ]]; do
|
|
56
|
+
case "$1" in
|
|
57
|
+
--path-index) PATH_INDEX="$2"; shift 2;;
|
|
58
|
+
--json) JSON=1; shift;;
|
|
59
|
+
--help|-h) usage; exit 0;;
|
|
60
|
+
-*) echo "Unknown flag: $1" >&2; usage >&2; exit 1;;
|
|
61
|
+
*)
|
|
62
|
+
if [[ -z "$BUNDLE" ]]; then BUNDLE="$1"
|
|
63
|
+
else echo "Unexpected arg: $1" >&2; exit 1
|
|
64
|
+
fi
|
|
65
|
+
shift
|
|
66
|
+
;;
|
|
67
|
+
esac
|
|
68
|
+
done
|
|
69
|
+
|
|
70
|
+
if [[ -z "$BUNDLE" ]]; then
|
|
71
|
+
usage >&2
|
|
72
|
+
exit 1
|
|
73
|
+
fi
|
|
74
|
+
|
|
75
|
+
if [[ ! -d "$BUNDLE" ]]; then
|
|
76
|
+
echo "ERROR: bundle directory not found: $BUNDLE" >&2
|
|
77
|
+
exit 2
|
|
78
|
+
fi
|
|
79
|
+
|
|
80
|
+
BUNDLE="${BUNDLE%/}"
|
|
81
|
+
|
|
82
|
+
ERRORS=()
|
|
83
|
+
PAGE_COUNT=0
|
|
84
|
+
CONCEPT_COUNT=0
|
|
85
|
+
|
|
86
|
+
add_error() { ERRORS+=("$1"); }
|
|
87
|
+
|
|
88
|
+
# Does the frozen vocabulary contain $1?
|
|
89
|
+
is_known_type() {
|
|
90
|
+
local t="$1"
|
|
91
|
+
[[ " $OKF_TYPES " == *" $t "* ]]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# --- 1. Root index ---
|
|
95
|
+
if [[ ! -f "$BUNDLE/index.md" ]]; then
|
|
96
|
+
add_error "missing bundle root: $BUNDLE/index.md"
|
|
97
|
+
fi
|
|
98
|
+
|
|
99
|
+
# --- 2/3. Per-page frontmatter + type vocabulary ---
|
|
100
|
+
while IFS= read -r -d '' page; do
|
|
101
|
+
PAGE_COUNT=$((PAGE_COUNT + 1))
|
|
102
|
+
rel="${page#"$BUNDLE/"}"
|
|
103
|
+
|
|
104
|
+
# A page is a "concept" only if its frontmatter declares a type.
|
|
105
|
+
type_val="$(get_yaml_field "$page" "type")"
|
|
106
|
+
[[ -z "$type_val" ]] && continue
|
|
107
|
+
CONCEPT_COUNT=$((CONCEPT_COUNT + 1))
|
|
108
|
+
|
|
109
|
+
for key in title description resource; do
|
|
110
|
+
if [[ -z "$(get_yaml_field "$page" "$key")" ]]; then
|
|
111
|
+
add_error "$rel: concept missing required frontmatter field '$key'"
|
|
112
|
+
fi
|
|
113
|
+
done
|
|
114
|
+
|
|
115
|
+
if ! is_known_type "$type_val"; then
|
|
116
|
+
add_error "$rel: unknown concept type '$type_val' (frozen vocab: $OKF_TYPES)"
|
|
117
|
+
fi
|
|
118
|
+
done < <(find "$BUNDLE" -type f -name '*.md' -print0 | sort -z)
|
|
119
|
+
|
|
120
|
+
# --- 4. Cross-link resolution ---
|
|
121
|
+
# Scan every markdown page for relative links of the form ](target.md[#frag]).
|
|
122
|
+
# Resolve targets relative to the linking file's directory; flag dangles.
|
|
123
|
+
# Use a temp file (outside the bundle) because the scan runs in a pipeline
|
|
124
|
+
# subshell where add_error would not persist.
|
|
125
|
+
DANGLE_FILE="$(mktemp)"
|
|
126
|
+
trap 'rm -f "$DANGLE_FILE"' EXIT
|
|
127
|
+
while IFS= read -r -d '' page; do
|
|
128
|
+
pdir="$(dirname "$page")"
|
|
129
|
+
prel="${page#"$BUNDLE/"}"
|
|
130
|
+
# Extract link targets: text inside ]( ... ) up to a space or closing paren.
|
|
131
|
+
grep -oE '\]\([^) ]+\)' "$page" 2>/dev/null | sed -E 's/^\]\(//; s/\)$//' | while IFS= read -r target; do
|
|
132
|
+
[[ -z "$target" ]] && continue
|
|
133
|
+
# Skip external schemes and pure anchors.
|
|
134
|
+
case "$target" in
|
|
135
|
+
http://*|https://*|mailto:*|\#*) continue;;
|
|
136
|
+
esac
|
|
137
|
+
# Strip any #anchor and ?query.
|
|
138
|
+
target="${target%%#*}"
|
|
139
|
+
target="${target%%\?*}"
|
|
140
|
+
[[ -z "$target" ]] && continue
|
|
141
|
+
# Only resolve intra-bundle markdown/asset links (relative paths).
|
|
142
|
+
case "$target" in
|
|
143
|
+
/*) continue;; # absolute path — out of scope for bundle integrity
|
|
144
|
+
esac
|
|
145
|
+
resolved="$pdir/$target"
|
|
146
|
+
if [[ ! -e "$resolved" ]]; then
|
|
147
|
+
printf '%s\t%s\n' "$prel" "$target"
|
|
148
|
+
fi
|
|
149
|
+
done || true # inner pipeline returns non-zero at EOF; don't trip set -e
|
|
150
|
+
done < <(find "$BUNDLE" -type f -name '*.md' -print0 | sort -z) >>"$DANGLE_FILE"
|
|
151
|
+
|
|
152
|
+
if [[ -s "$DANGLE_FILE" ]]; then
|
|
153
|
+
while IFS=$'\t' read -r prel target; do
|
|
154
|
+
add_error "$prel: dangling cross-link → '$target'"
|
|
155
|
+
done < "$DANGLE_FILE"
|
|
156
|
+
fi
|
|
157
|
+
|
|
158
|
+
# --- 5. path→concept index completeness (optional) ---
|
|
159
|
+
if [[ -n "$PATH_INDEX" ]]; then
|
|
160
|
+
if [[ ! -f "$PATH_INDEX" ]]; then
|
|
161
|
+
add_error "path-index not found: $PATH_INDEX"
|
|
162
|
+
else
|
|
163
|
+
# The index maps source path → array of concept page(s), bundle-relative:
|
|
164
|
+
# { "src/auth/login.go": ["systems/auth.md"], ... }
|
|
165
|
+
# Validate the array VALUES (the pages) only. Keys are source paths and may
|
|
166
|
+
# themselves end in .md (e.g. grounding to docs/INVARIANTS.md) — those are
|
|
167
|
+
# not bundle pages, so we extract strings *inside* the [ ... ] value arrays
|
|
168
|
+
# and ignore keys entirely. Each page must exist in the bundle.
|
|
169
|
+
while IFS= read -r ref; do
|
|
170
|
+
[[ -z "$ref" ]] && continue
|
|
171
|
+
if [[ ! -f "$BUNDLE/$ref" ]]; then
|
|
172
|
+
add_error "path-index references missing concept page: $ref"
|
|
173
|
+
fi
|
|
174
|
+
done < <(grep -oE '\[[^]]*\]' "$PATH_INDEX" 2>/dev/null \
|
|
175
|
+
| grep -oE '"[^"]+\.md"' | tr -d '"' | sort -u)
|
|
176
|
+
fi
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
# --- Report ---
|
|
180
|
+
if [[ $JSON -eq 1 ]]; then
|
|
181
|
+
valid=true
|
|
182
|
+
[[ ${#ERRORS[@]} -eq 0 ]] || valid=false
|
|
183
|
+
printf '{"valid":%s,"bundle":"%s","pages":%d,"concepts":%d,"errors":[' \
|
|
184
|
+
"$valid" "$(json_escape "$BUNDLE")" "$PAGE_COUNT" "$CONCEPT_COUNT"
|
|
185
|
+
if [[ ${#ERRORS[@]} -gt 0 ]]; then
|
|
186
|
+
for i in "${!ERRORS[@]}"; do
|
|
187
|
+
[[ $i -gt 0 ]] && printf ','
|
|
188
|
+
printf '"%s"' "$(json_escape "${ERRORS[$i]}")"
|
|
189
|
+
done
|
|
190
|
+
fi
|
|
191
|
+
printf ']}\n'
|
|
192
|
+
else
|
|
193
|
+
if [[ ${#ERRORS[@]} -gt 0 ]]; then
|
|
194
|
+
echo "OKF bundle INVALID: $BUNDLE ($PAGE_COUNT pages, $CONCEPT_COUNT concepts)" >&2
|
|
195
|
+
for e in "${ERRORS[@]}"; do
|
|
196
|
+
echo " - $e" >&2
|
|
197
|
+
done
|
|
198
|
+
else
|
|
199
|
+
echo "OKF bundle valid: $BUNDLE ($PAGE_COUNT pages, $CONCEPT_COUNT concepts)"
|
|
200
|
+
fi
|
|
201
|
+
fi
|
|
202
|
+
|
|
203
|
+
[[ ${#ERRORS[@]} -eq 0 ]] || exit 1
|
|
204
|
+
exit 0
|
package/skills/init/SKILL.md
CHANGED
|
@@ -199,6 +199,23 @@ Check for arguments:
|
|
|
199
199
|
|
|
200
200
|
> `/draft:init` is the **single entry point** for building context — there is no separate `index` command. Init is scope-aware (root vs sub-module); see **Scope Detection** below.
|
|
201
201
|
|
|
202
|
+
### Output Mode (`DRAFT_INIT_MODE`)
|
|
203
|
+
|
|
204
|
+
Init has two output modes. The default is **tier-gated (`auto`)** — resolved from the codebase tier computed in Step 1.4.5 — and the `DRAFT_INIT_MODE` environment variable overrides it:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
DRAFT_INIT_MODE="${DRAFT_INIT_MODE:-auto}"
|
|
208
|
+
# auto → resolved AFTER tier is known (Step 1.4.5):
|
|
209
|
+
# tier 1–2 (micro/small) → monolith
|
|
210
|
+
# tier 3–5 (medium/large/XL) → okf
|
|
211
|
+
# monolith / okf → explicit override; honored as-is.
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
- **`monolith`** — the standard path documented in this skill: a single `architecture.md` (10-section graph-primary) + derived `.ai-context.md` / `.ai-profile.md`. The default for **small repos (tier 1–2)**, where one linear document beats a taxonomy with little to navigate. Also the A/B baseline and the over-fetch fallback.
|
|
215
|
+
- **`okf`** — emit an OKF-conformant concept taxonomy bundle (`draft/wiki/`) with `.ai-context.md` as the index root and `architecture.md` demoted to a generated rendered view. The default for **tier 3+ repos**, where navigation + maintainability pay off. When active, follow `references/okf-emitter.md` for the decomposition + serialization + validation stage; all shared phases (5-phase analysis, graph snapshot, `.state/` hashing, scope detection, atomic staging) are reused unchanged.
|
|
216
|
+
|
|
217
|
+
The tier-gated default rests on **maintainability/readability** (one navigable concept per file, cleaner PRs, a generated `architecture.md` preserved for linear onboarding) — not on the A/B benchmark, which was accuracy-parity (`docs/audit/okf-benchmark.md`). `monolith` is **retained, not retired**: it is the tier-1/2 default, the A/B baseline, and the fallback. If `DRAFT_INIT_MODE` is unset, do not commit to a mode until **Step 1.4.5** has computed the tier.
|
|
218
|
+
|
|
202
219
|
### Route Explicit Modes Before Initialization
|
|
203
220
|
|
|
204
221
|
If the user explicitly invoked a specialist mode, route directly:
|
|
@@ -318,7 +335,11 @@ If the user runs `/draft:init refresh`:
|
|
|
318
335
|
|
|
319
336
|
1. **Tech Stack Refresh**: Re-scan `package.json`, `go.mod`, etc. Compare with `draft/tech-stack.md`. Propose updates.
|
|
320
337
|
|
|
321
|
-
2. **Architecture Refresh**:
|
|
338
|
+
2. **Architecture Refresh**:
|
|
339
|
+
|
|
340
|
+
**Mode detection (do this first).** If `draft/wiki/` exists, the bundle was generated in **`okf` mode** and `architecture.md` is a *generated rendered view*, not the source of truth. In that case **follow `references/okf-emitter.md` §"Incremental refresh at concept granularity (M5)"** instead of the monolith steps below: diff `hashes.json` → map changed source paths to affected concepts → regenerate only those concepts (carry the rest forward from cache) → always re-render `.ai-context.md`, `architecture.md`, and `log.md` via `okf-render-views.sh` → re-run `okf-validate.sh` so cross-links still resolve. Do **not** hand-edit `architecture.md` in this mode — it is overwritten by the renderer. Then skip to step 3.
|
|
341
|
+
|
|
342
|
+
Otherwise (**`monolith` mode** — `draft/architecture.md` is the source of truth and no `draft/wiki/` exists), use metadata-based incremental analysis. If freshness state is available from step 0b, use file-level deltas to scope the refresh more precisely than git-diff alone:
|
|
322
343
|
|
|
323
344
|
**a. Read synced commit from metadata:**
|
|
324
345
|
```bash
|
|
@@ -562,6 +583,8 @@ Apply tier table:
|
|
|
562
583
|
|
|
563
584
|
Hold tier in memory. This governs: architecture.md length minimum, .ai-context.md budget, and module deep-dive depth.
|
|
564
585
|
|
|
586
|
+
**Resolve the output mode now (if `auto`).** If `DRAFT_INIT_MODE` is unset/`auto`, finalize it from the tier just computed: **tier 1–2 → `monolith`**, **tier 3–5 → `okf`** (see **Output Mode** in Pre-Check). An explicit `DRAFT_INIT_MODE=monolith|okf` always wins and skips this resolution. Announce the resolved mode, e.g. `Tier 4 (large) → okf mode (wiki taxonomy bundle).` If `okf`, switch to `references/okf-emitter.md` for the decomposition + serialization + render-views + validate stage from here on; all the shared analysis above is reused unchanged.
|
|
587
|
+
|
|
565
588
|
**Step 1.4.6 — Build Module Priority List:**
|
|
566
589
|
From `"$DRAFT_TOOLS/hotspot-rank.sh" --repo .`: count hotspot symbols per module.
|
|
567
590
|
From `$ARCH | jq '.packages[]'`: read `fan_in` per module.
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
## Init — OKF Taxonomy Emitter (DRAFT_INIT_MODE=okf)
|
|
2
|
+
|
|
3
|
+
> Progressive-disclosure reference for `/draft:init`. Covers the OKF emitter:
|
|
4
|
+
> type vocabulary, frontmatter contract, generation pipeline, render views,
|
|
5
|
+
> incremental refresh, and the `okf-validate.sh` gate. Authoritative HLD:
|
|
6
|
+
> `hld-draft-init-okf-taxonomy.md` at the repo root.
|
|
7
|
+
|
|
8
|
+
This is the `/draft:init` output mode for **tier 3+ repos**, where it is the
|
|
9
|
+
**tier-gated default** (`DRAFT_INIT_MODE` unset → tier 1–2 `monolith`, tier 3–5
|
|
10
|
+
`okf`; an explicit `DRAFT_INIT_MODE=monolith|okf` overrides). `monolith` is
|
|
11
|
+
retained — the tier-1/2 default, the A/B baseline, and the over-fetch fallback.
|
|
12
|
+
The default rests on maintainability/readability, not the benchmark (parity).
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
# Mode gate — default is tier-gated 'auto', finalized after Step 1.4.5 (tier):
|
|
16
|
+
DRAFT_INIT_MODE="${DRAFT_INIT_MODE:-auto}"
|
|
17
|
+
case "$DRAFT_INIT_MODE" in
|
|
18
|
+
monolith|okf) : ;; # explicit override — honored as-is
|
|
19
|
+
auto) : ;; # resolve from tier: 1–2 → monolith, 3–5 → okf
|
|
20
|
+
*) echo "Unknown DRAFT_INIT_MODE='$DRAFT_INIT_MODE' (monolith|okf|auto); using auto" >&2
|
|
21
|
+
DRAFT_INIT_MODE=auto ;;
|
|
22
|
+
esac
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Everything else in `/draft:init` (5-phase analysis, graph snapshot, `.state/`
|
|
26
|
+
hashing, scope detection, atomic staging) is **reused unchanged**. This mode adds
|
|
27
|
+
a decomposition + serialization stage. It introduces **no new LLM analysis
|
|
28
|
+
engine** and exactly **one** new deterministic helper, `okf-validate.sh`.
|
|
29
|
+
|
|
30
|
+
## Target layout
|
|
31
|
+
|
|
32
|
+
`okf` mode changes **only** the `architecture.md` / `.ai-context.md` packaging
|
|
33
|
+
and adds `wiki/`. **Every other standard `/draft:init` file is still produced**
|
|
34
|
+
— `product.md`, `tech-stack.md`, `workflow.md`, `guardrails.md`, `index.md`,
|
|
35
|
+
`.ai-profile.md`, `tracks/` + `tracks.md`, `.state/`, `graph/` — exactly as in
|
|
36
|
+
`monolith` mode. Do **not** skip them: emitting only the bundle is a regression.
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
draft/
|
|
40
|
+
├── .ai-context.md # INDEX ROOT: synopsis (150–250 lines) + Concept Map
|
|
41
|
+
├── architecture.md # RENDERED VIEW (generated from bundle; not source of truth)
|
|
42
|
+
├── .ai-profile.md # always-injected profile (derived from .ai-context.md) [SAME AS MONOLITH]
|
|
43
|
+
├── product.md # [SAME AS MONOLITH]
|
|
44
|
+
├── tech-stack.md # [SAME AS MONOLITH]
|
|
45
|
+
├── workflow.md # [SAME AS MONOLITH]
|
|
46
|
+
├── guardrails.md # [SAME AS MONOLITH]
|
|
47
|
+
├── index.md # docs index — lists prose files + wiki/ [SAME AS MONOLITH, +wiki link]
|
|
48
|
+
├── tracks.md + tracks/ # [SAME AS MONOLITH]
|
|
49
|
+
├── wiki/ # OKF bundle (source of truth) — okf-mode ONLY
|
|
50
|
+
│ ├── index.md # bundle root + Concept Map
|
|
51
|
+
│ ├── overview/{index,architecture,getting-started,glossary}.md
|
|
52
|
+
│ ├── systems/{index,<subsystem>}.md
|
|
53
|
+
│ ├── features/{index,<feature>}.md
|
|
54
|
+
│ ├── reference/{index,<ref>}.md # config, deps, data models, ADRs, runbooks
|
|
55
|
+
│ ├── entrypoints/<app>.md
|
|
56
|
+
│ ├── web/index.html # optional offline viewer (okf-render-views.sh --web)
|
|
57
|
+
│ └── log.md # chronological change history (from .state run memory)
|
|
58
|
+
├── graph/schema.yaml # [SAME AS MONOLITH] engine gate marker
|
|
59
|
+
└── .state/
|
|
60
|
+
├── hashes.json # file → content hash [SAME AS MONOLITH]
|
|
61
|
+
├── path-to-concept.json # NEW: source path → concept page(s) it grounds
|
|
62
|
+
└── signals.json # [SAME AS MONOLITH]
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The standard project files come from the same generators as `monolith` mode
|
|
66
|
+
(intake questions → `product.md`; tech detection → `tech-stack.md`; `/draft:learn`
|
|
67
|
+
→ `guardrails.md`; templates → `workflow.md`, `index.md`, `tracks.md`,
|
|
68
|
+
`.ai-profile.md`). The OKF emitter only *replaces the architecture packaging*; it
|
|
69
|
+
never owns or removes the rest of the context directory.
|
|
70
|
+
|
|
71
|
+
Templates for each bundle page live in `core/templates/okf/` (`index.md`,
|
|
72
|
+
`concept.md`, `section-index.md`, `ai-context-index.md`).
|
|
73
|
+
|
|
74
|
+
## Frozen `type` vocabulary
|
|
75
|
+
|
|
76
|
+
Every concept carries a `type` from this frozen set (changing it churns every
|
|
77
|
+
file; versioned via `index.md` frontmatter `okf_types_version`):
|
|
78
|
+
|
|
79
|
+
| type | Maps to | Home |
|
|
80
|
+
|------|---------|------|
|
|
81
|
+
| `Subsystem` | major graph cluster / package boundary | `systems/` |
|
|
82
|
+
| `Module` | single package/dir, cohesive responsibility | `systems/` |
|
|
83
|
+
| `Feature` | user-facing capability spanning modules | `features/` |
|
|
84
|
+
| `Entrypoint` | binary / main / CLI / handler root | `entrypoints/` |
|
|
85
|
+
| `API` | public interface, route group, RPC surface | `reference/` |
|
|
86
|
+
| `DataModel` | schema, table, core struct/type | `reference/` |
|
|
87
|
+
| `Dependency` | notable external dep + how it's used | `reference/` |
|
|
88
|
+
| `ADR` | architecture decision record | `reference/` |
|
|
89
|
+
| `Runbook` | operational procedure | `reference/` |
|
|
90
|
+
|
|
91
|
+
`okf-validate.sh` enforces this set as ground truth — an out-of-vocab `type`
|
|
92
|
+
fails the build.
|
|
93
|
+
|
|
94
|
+
## Frontmatter contract
|
|
95
|
+
|
|
96
|
+
Per concept page (see `core/templates/okf/concept.md`). Required OKF keys:
|
|
97
|
+
`type`, `title`, `description`, `resource`. **`description` is the load-bearing
|
|
98
|
+
routing key** — write it as a routing decision ("should the agent open this for
|
|
99
|
+
the task at hand?"), never a summary. Draft extensions are namespaced `x-` and
|
|
100
|
+
ignored by generic OKF consumers: `x-grounded-paths`, `x-hotspot-score`,
|
|
101
|
+
`x-callers`.
|
|
102
|
+
|
|
103
|
+
## Concept granularity (resolves open decision 1)
|
|
104
|
+
|
|
105
|
+
Derive concepts from the graph, not by hand:
|
|
106
|
+
|
|
107
|
+
- A **Subsystem** = a graph cluster (package/dir boundary) with `fan_in ≥ 2` from
|
|
108
|
+
other clusters, OR a top-ranked module from `hotspot-rank.sh`.
|
|
109
|
+
- A **Module** = a cohesive package/dir below a subsystem that is *not* itself a
|
|
110
|
+
cluster boundary but has its own hotspot or public surface.
|
|
111
|
+
- A **Feature** = a capability the graph shows spanning ≥2 modules (shared
|
|
112
|
+
callers / a route group touching multiple packages).
|
|
113
|
+
- Default cap: one page per package boundary; do not split a package into
|
|
114
|
+
multiple concept pages unless it has >1 distinct public surface. This keeps
|
|
115
|
+
page count ≈ module count and navigation depth shallow.
|
|
116
|
+
|
|
117
|
+
## Generation pipeline (M3)
|
|
118
|
+
|
|
119
|
+
```
|
|
120
|
+
1. Survey → existing /draft:init 5-phase + graph snapshot (graph-snapshot.sh)
|
|
121
|
+
2. Plan → derive the concept list (above) from graph clusters +
|
|
122
|
+
entrypoints + features. Topo-sort by dependency so pages that
|
|
123
|
+
others link to (overview, core subsystems) generate FIRST —
|
|
124
|
+
forward cross-links resolve.
|
|
125
|
+
3. Generate → per concept, pull grounding from the graph and write the page:
|
|
126
|
+
x-callers ← graph-callers.sh --symbol <c>
|
|
127
|
+
x-grounded-paths ← graph-impact.sh --symbol <c> (blast radius)
|
|
128
|
+
x-hotspot-score ← hotspot-rank.sh
|
|
129
|
+
overview diagrams ← mermaid-from-graph.sh
|
|
130
|
+
Record each source path → page in .state/path-to-concept.json.
|
|
131
|
+
4. Render views → ai-context.md (synopsis + Concept Map), architecture.md
|
|
132
|
+
(concatenated view), wiki/log.md (see M4).
|
|
133
|
+
5. Validate → okf-validate.sh draft/wiki \
|
|
134
|
+
--path-index draft/.state/path-to-concept.json
|
|
135
|
+
FAIL the build (do not atomic-rename) on any dangle, missing
|
|
136
|
+
field, bad type, or path-index gap.
|
|
137
|
+
6. Emit → mv draft.tmp/ draft/ ; update .state/.
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Page bodies are LLM-narrated for readability **but** the graph-derived
|
|
141
|
+
frontmatter and the `Blast radius`/`Used by` sections are deterministic. To keep
|
|
142
|
+
incremental carry-forward byte-identical (open decision 2), cache the narrated
|
|
143
|
+
prose keyed by the source hash of `x-grounded-paths` — unchanged sources reuse
|
|
144
|
+
the cached narration verbatim.
|
|
145
|
+
|
|
146
|
+
## Render views (M4)
|
|
147
|
+
|
|
148
|
+
Both are produced by the deterministic helper `okf-render-views.sh` (no LLM) —
|
|
149
|
+
regenerated on every init/refresh so they never drift from the bundle:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
okf-render-views.sh draft/wiki \
|
|
153
|
+
--arch-out draft/architecture.md \
|
|
154
|
+
--concept-map-into draft/wiki/index.md \
|
|
155
|
+
--concept-map-into draft/.ai-context.md \
|
|
156
|
+
--web draft/wiki/web/index.html
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
- `--arch-out` renders the linear `architecture.md` (banner + TOC + every concept
|
|
160
|
+
page in canonical section order, frontmatter stripped, Mermaid preserved).
|
|
161
|
+
- `--concept-map-into` rebuilds the routing table between the
|
|
162
|
+
`<!-- CONCEPT-MAP:START -->` / `:END` markers from each concept's `title` +
|
|
163
|
+
`type` + `description` (section `index.md` pages excluded).
|
|
164
|
+
- `--web` writes a **self-contained offline HTML viewer** (single file: all pages
|
|
165
|
+
inlined as JSON + a built-in markdown renderer + sidebar nav + search). Works by
|
|
166
|
+
double-click — no server, no internet, no CDN. Optional, human-facing; regenerate
|
|
167
|
+
on refresh like the other views. (Mermaid blocks render as labeled source since a
|
|
168
|
+
graphical engine can't be inlined offline.)
|
|
169
|
+
|
|
170
|
+
All views write into `draft/` (the OKF emitter never creates a separate output
|
|
171
|
+
dir): `draft/wiki/` is the bundle, `draft/architecture.md` + `draft/.ai-context.md`
|
|
172
|
+
are the rendered views, `draft/wiki/web/index.html` is the optional viewer.
|
|
173
|
+
|
|
174
|
+
The two views:
|
|
175
|
+
|
|
176
|
+
- **`ai-context.md`** (index root) — from `core/templates/okf/ai-context-index.md`:
|
|
177
|
+
the Synopsis preserves the prior `.ai-context.md` content shape (so existing
|
|
178
|
+
downstream consumers keep working); the Concept Map is built from each
|
|
179
|
+
concept's `description`. Broad tasks terminate here.
|
|
180
|
+
- **`architecture.md`** (rendered view) — TOC + per-concept section concat +
|
|
181
|
+
Mermaid, in topo order. Demoted, not deleted: the brownfield Context Quality
|
|
182
|
+
Audit and any command grepping `architecture.md` keep working (§9 of the HLD).
|
|
183
|
+
- **`wiki/log.md`** — appended from `.state/` run memory.
|
|
184
|
+
|
|
185
|
+
The `<!-- CONCEPT-MAP:START -->` / `:END` markers in `wiki/index.md` and the
|
|
186
|
+
section `index.md` tables are the injection slots for the routing tables.
|
|
187
|
+
|
|
188
|
+
## Incremental refresh at concept granularity (M5)
|
|
189
|
+
|
|
190
|
+
`/draft:init refresh` under `okf` mode:
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
1. Diff hashes.json vs working tree → changed source paths
|
|
194
|
+
2. path-to-concept.json → affected concept pages
|
|
195
|
+
3. Regenerate ONLY affected concepts; carry the rest verbatim (cached narration)
|
|
196
|
+
4. Re-render ai-context.md / architecture.md / log.md (cheap; always regenerated)
|
|
197
|
+
5. Re-validate: okf-validate.sh on the bundle + path-index (cross-links touching
|
|
198
|
+
changed concepts must still resolve)
|
|
199
|
+
6. Append log.md; update hashes.json + path-to-concept.json
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
A 1-file change regenerates only the concept(s) that file grounds. Unchanged
|
|
203
|
+
concepts are byte-identical across runs.
|
|
204
|
+
|
|
205
|
+
## Backward compatibility (§9)
|
|
206
|
+
|
|
207
|
+
- `architecture.md` is retained as a rendered view (brownfield audit + grep keep
|
|
208
|
+
working).
|
|
209
|
+
- `ai-context.md`'s Synopsis preserves the prior content shape; the Concept Map
|
|
210
|
+
is additive.
|
|
211
|
+
- `/draft:review` and downstream command contracts are unchanged — they consume
|
|
212
|
+
`architecture.md` / `ai-context.md`, both of which still exist.
|
|
213
|
+
|
|
214
|
+
## Default policy & retirement of `monolith`
|
|
215
|
+
|
|
216
|
+
`okf` is the **tier-gated default** (tier 3+); `monolith` is the tier-1/2 default
|
|
217
|
+
and remains in place as the A/B baseline + over-fetch fallback. Full retirement of
|
|
218
|
+
`monolith` is deferred until **both**: (1) the large-monolith A/B run shows `okf` ≥
|
|
219
|
+
baseline on tokens at parity accuracy (the regime the §12 benchmark flagged), and
|
|
220
|
+
(2) a human-onboarding eval confirms the wiki + generated `architecture.md` covers
|
|
221
|
+
linear onboarding. Note: retiring `monolith` would not remove `architecture.md` —
|
|
222
|
+
it is generated from the bundle regardless — so there is no readability gain from
|
|
223
|
+
deletion, only lost optionality.
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# Draft - Context-Driven Development
|
|
2
|
-
|
|
3
|
-
You are operating with the Draft methodology for Context-Driven Development.
|
|
4
|
-
|
|
5
|
-
**Measure twice, code once.**
|
|
6
|
-
|
|
7
|
-
## Core Workflow
|
|
8
|
-
|
|
9
|
-
**Context -> Spec & Plan -> Implement**
|
|
10
|
-
|
|
11
|
-
Every feature follows this lifecycle:
|
|
12
|
-
1. **Setup** - Initialize project context (once per project)
|
|
13
|
-
2. **New Track** - Create specification and plan
|
|
14
|
-
3. **Implement** - Execute tasks with TDD workflow
|
|
15
|
-
4. **Verify** - Confirm acceptance criteria met
|
|
16
|
-
|
|
17
|
-
## Project Context Files
|
|
18
|
-
|
|
19
|
-
When `draft/` exists in the project, always consider:
|
|
20
|
-
- `draft/.ai-context.md` - Source of truth for AI agents (dense codebase understanding)
|
|
21
|
-
- `draft/architecture.md` - Human-readable engineering guide (derived from .ai-context.md)
|
|
22
|
-
- `draft/product.md` - Product vision and goals
|
|
23
|
-
- `draft/tech-stack.md` - Technical constraints
|
|
24
|
-
- `draft/workflow.md` - TDD and commit preferences
|
|
25
|
-
- `draft/tracks.md` - Active work items
|
|
26
|
-
|
|
27
|
-
## Available Commands
|
|
28
|
-
|
|
29
|
-
| Command | Purpose |
|
|
30
|
-
|---------|---------|
|
|
31
|
-
| `draft` | Show overview and available commands |
|
|
32
|
-
| `draft init` | Initialize project (run once) |
|
|
33
|
-
| `draft index [--init-missing]` | Aggregate monorepo service contexts |
|
|
34
|
-
| `draft new-track <description>` | Create feature/bug track |
|
|
35
|
-
| `draft decompose` | Module decomposition with dependency mapping |
|
|
36
|
-
| `draft implement` | Execute tasks from plan |
|
|
37
|
-
| `draft coverage` | Code coverage report (target 95%+) |
|
|
38
|
-
| `draft bughunt [--track <id>]` | Systematic bug discovery |
|
|
39
|
-
| `draft review [--track <id>]` | Three-stage code review |
|
|
40
|
-
| `draft deep-review [module]` | Exhaustive production-grade module audit |
|
|
41
|
-
| `draft learn [promote\|migrate]` | Discover coding patterns, update guardrails |
|
|
42
|
-
| `draft adr [title]` | Architecture Decision Records |
|
|
43
|
-
| `draft status` | Show progress overview |
|
|
44
|
-
| `draft revert` | Git-aware rollback |
|
|
45
|
-
| `draft change <description>` | Handle mid-track requirement changes |
|
|
46
|
-
| `draft jira-preview [track-id]` | Generate jira-export.md for review |
|
|
47
|
-
| `draft jira-create [track-id]` | Create Jira issues from export via MCP |
|
|
48
|
-
|
|
49
|
-
## Intent Mapping
|
|
50
|
-
|
|
51
|
-
Recognize these natural language patterns:
|
|
52
|
-
|
|
53
|
-
| User Says | Action |
|
|
54
|
-
|-----------|--------|
|
|
55
|
-
| "set up the project" | Run init |
|
|
56
|
-
| "index services", "aggregate context" | Run index |
|
|
57
|
-
| "new feature", "add X" | Create new track |
|
|
58
|
-
| "break into modules", "decompose" | Run decompose |
|
|
59
|
-
| "start implementing" | Execute implement |
|
|
60
|
-
| "check coverage", "test coverage" | Run coverage |
|
|
61
|
-
| "hunt bugs", "find bugs" | Run bug hunt |
|
|
62
|
-
| "review code", "review track", "check quality" | Run review |
|
|
63
|
-
| "deep review", "production audit", "module audit" | Run deep-review |
|
|
64
|
-
| "learn patterns", "update guardrails", "discover conventions" | Run learn |
|
|
65
|
-
| "what's the status" | Show status |
|
|
66
|
-
| "undo", "revert" | Run revert |
|
|
67
|
-
| "requirements changed", "scope changed", "update the spec" | Run change |
|
|
68
|
-
| "preview jira", "export to jira" | Run jira-preview |
|
|
69
|
-
| "create jira", "push to jira" | Run jira-create |
|
|
70
|
-
| "document decision", "create ADR" | Create architecture decision record |
|
|
71
|
-
| "help", "what commands" | Show draft overview |
|
|
72
|
-
| "the plan" | Read active track's plan.md |
|
|
73
|
-
| "the spec" | Read active track's spec.md |
|
|
74
|
-
|
|
75
|
-
## Tracks
|
|
76
|
-
|
|
77
|
-
A **track** is a high-level unit of work (feature, bug fix, refactor). Each track contains:
|
|
78
|
-
- `spec.md` - Requirements and acceptance criteria
|
|
79
|
-
- `plan.md` - Phased task breakdown
|
|
80
|
-
- `metadata.json` - Status and timestamps
|
|
81
|
-
|
|
82
|
-
Located at: `draft/tracks/<track-id>/`
|
|
83
|
-
|
|
84
|
-
## Status Markers
|
|
85
|
-
|
|
86
|
-
Recognize and use these throughout plan.md:
|
|
87
|
-
- `[ ]` - Pending
|
|
88
|
-
- `[~]` - In Progress
|
|
89
|
-
- `[x]` - Completed
|
|
90
|
-
- `[!]` - Blocked
|
|
91
|
-
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# Draft - Context-Driven Development
|
|
2
|
-
|
|
3
|
-
You are operating with the Draft methodology for Context-Driven Development.
|
|
4
|
-
|
|
5
|
-
**Measure twice, code once.**
|
|
6
|
-
|
|
7
|
-
## Core Workflow
|
|
8
|
-
|
|
9
|
-
**Context -> Spec & Plan -> Implement**
|
|
10
|
-
|
|
11
|
-
Every feature follows this lifecycle:
|
|
12
|
-
1. **Setup** - Initialize project context (once per project)
|
|
13
|
-
2. **New Track** - Create specification and plan
|
|
14
|
-
3. **Implement** - Execute tasks with TDD workflow
|
|
15
|
-
4. **Verify** - Confirm acceptance criteria met
|
|
16
|
-
|
|
17
|
-
## Project Context Files
|
|
18
|
-
|
|
19
|
-
When `draft/` exists in the project, always consider:
|
|
20
|
-
- `draft/.ai-context.md` - Source of truth for AI agents (dense codebase understanding)
|
|
21
|
-
- `draft/architecture.md` - Human-readable engineering guide (derived from .ai-context.md)
|
|
22
|
-
- `draft/product.md` - Product vision and goals
|
|
23
|
-
- `draft/tech-stack.md` - Technical constraints
|
|
24
|
-
- `draft/workflow.md` - TDD and commit preferences
|
|
25
|
-
- `draft/tracks.md` - Active work items
|
|
26
|
-
|
|
27
|
-
## Available Commands
|
|
28
|
-
|
|
29
|
-
| Command | Purpose |
|
|
30
|
-
|---------|---------|
|
|
31
|
-
| `draft` | Show overview and available commands |
|
|
32
|
-
| `draft init` | Initialize project (run once) |
|
|
33
|
-
| `draft index [--init-missing]` | Aggregate monorepo service contexts |
|
|
34
|
-
| `draft new-track <description>` | Create feature/bug track |
|
|
35
|
-
| `draft decompose` | Module decomposition with dependency mapping |
|
|
36
|
-
| `draft implement` | Execute tasks from plan |
|
|
37
|
-
| `draft coverage` | Code coverage report (target 95%+) |
|
|
38
|
-
| `draft bughunt [--track <id>]` | Systematic bug discovery |
|
|
39
|
-
| `draft review [--track <id>]` | Three-stage code review |
|
|
40
|
-
| `draft deep-review [module]` | Exhaustive production-grade module audit |
|
|
41
|
-
| `draft learn [promote\|migrate]` | Discover coding patterns, update guardrails |
|
|
42
|
-
| `draft adr [title]` | Architecture Decision Records |
|
|
43
|
-
| `draft status` | Show progress overview |
|
|
44
|
-
| `draft revert` | Git-aware rollback |
|
|
45
|
-
| `draft change <description>` | Handle mid-track requirement changes |
|
|
46
|
-
| `draft jira-preview [track-id]` | Generate jira-export.md for review |
|
|
47
|
-
| `draft jira-create [track-id]` | Create Jira issues from export via MCP |
|
|
48
|
-
|
|
49
|
-
## Intent Mapping
|
|
50
|
-
|
|
51
|
-
Recognize these natural language patterns:
|
|
52
|
-
|
|
53
|
-
| User Says | Action |
|
|
54
|
-
|-----------|--------|
|
|
55
|
-
| "set up the project" | Run init |
|
|
56
|
-
| "index services", "aggregate context" | Run index |
|
|
57
|
-
| "new feature", "add X" | Create new track |
|
|
58
|
-
| "break into modules", "decompose" | Run decompose |
|
|
59
|
-
| "start implementing" | Execute implement |
|
|
60
|
-
| "check coverage", "test coverage" | Run coverage |
|
|
61
|
-
| "hunt bugs", "find bugs" | Run bug hunt |
|
|
62
|
-
| "review code", "review track", "check quality" | Run review |
|
|
63
|
-
| "deep review", "production audit", "module audit" | Run deep-review |
|
|
64
|
-
| "learn patterns", "update guardrails", "discover conventions" | Run learn |
|
|
65
|
-
| "what's the status" | Show status |
|
|
66
|
-
| "undo", "revert" | Run revert |
|
|
67
|
-
| "requirements changed", "scope changed", "update the spec" | Run change |
|
|
68
|
-
| "preview jira", "export to jira" | Run jira-preview |
|
|
69
|
-
| "create jira", "push to jira" | Run jira-create |
|
|
70
|
-
| "document decision", "create ADR" | Create architecture decision record |
|
|
71
|
-
| "help", "what commands" | Show draft overview |
|
|
72
|
-
| "the plan" | Read active track's plan.md |
|
|
73
|
-
| "the spec" | Read active track's spec.md |
|
|
74
|
-
|
|
75
|
-
## Tracks
|
|
76
|
-
|
|
77
|
-
A **track** is a high-level unit of work (feature, bug fix, refactor). Each track contains:
|
|
78
|
-
- `spec.md` - Requirements and acceptance criteria
|
|
79
|
-
- `plan.md` - Phased task breakdown
|
|
80
|
-
- `metadata.json` - Status and timestamps
|
|
81
|
-
|
|
82
|
-
Located at: `draft/tracks/<track-id>/`
|
|
83
|
-
|
|
84
|
-
## Status Markers
|
|
85
|
-
|
|
86
|
-
Recognize and use these throughout plan.md:
|
|
87
|
-
- `[ ]` - Pending
|
|
88
|
-
- `[~]` - In Progress
|
|
89
|
-
- `[x]` - Completed
|
|
90
|
-
- `[!]` - Blocked
|
|
91
|
-
|