@drafthq/draft 3.3.1 → 3.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.cursor-plugin/plugin.json +1 -1
- package/core/shared/draft-context-loading.md +9 -0
- package/core/shared/okf-retrieval.md +94 -0
- package/core/templates/okf/concept.md +9 -0
- package/integrations/agents/AGENTS.md +198 -20
- package/integrations/copilot/.github/copilot-instructions.md +198 -20
- package/package.json +1 -1
- package/scripts/lib.sh +6 -0
- package/scripts/tools/okf-coverage-check.sh +192 -0
- package/scripts/tools/okf-plan-concepts.sh +296 -0
- package/scripts/tools/okf-render-views.sh +30 -0
- package/scripts/tools/okf-validate-all.sh +117 -0
- package/scripts/tools/okf-validate-quality.sh +272 -0
- package/scripts/tools/okf-validate.sh +35 -1
- package/skills/init/SKILL.md +10 -0
- package/skills/init/references/okf-emitter.md +67 -20
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"name": "draft",
|
|
13
13
|
"source": "./",
|
|
14
14
|
"description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
|
|
15
|
-
"version": "3.
|
|
15
|
+
"version": "3.5.0",
|
|
16
16
|
"author": {
|
|
17
17
|
"name": "mayurpise"
|
|
18
18
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "draft",
|
|
3
3
|
"displayName": "Draft",
|
|
4
4
|
"description": "Context-Driven Development: draft specs and plans before implementation. Structured workflows for features and fixes.",
|
|
5
|
-
"version": "3.
|
|
5
|
+
"version": "3.5.0",
|
|
6
6
|
"skills": "./skills/",
|
|
7
7
|
"agents": "./core/agents/",
|
|
8
8
|
"author": {
|
|
@@ -117,6 +117,15 @@ Apply relevance scoring when ALL of these conditions are true:
|
|
|
117
117
|
|
|
118
118
|
Do NOT apply relevance scoring for commands that need full context (`/draft:init`, `/draft:deep-review`, `/draft:decompose`).
|
|
119
119
|
|
|
120
|
+
### Retrieval Path Selection (okf vs monolith)
|
|
121
|
+
|
|
122
|
+
Relevance scoring has two implementations; pick by output mode:
|
|
123
|
+
|
|
124
|
+
- **okf mode** — if `draft/wiki/` exists, use **tree-search retrieval** (`core/shared/okf-retrieval.md`): navigate the OKF Concept Map by reasoning over each concept's routing `description`, descending only the matching subtrees. This is the vectorless, reasoning-based path (PageIndex-style) and supersedes the static section table below for okf bundles.
|
|
125
|
+
- **monolith mode** — if `draft/wiki/` does not exist, use the static **Scoring Procedure** below against `.ai-context.md` sections.
|
|
126
|
+
|
|
127
|
+
The minimum context floor (`META`, `INVARIANTS`, `TEST`, `FILES`) applies to both paths.
|
|
128
|
+
|
|
120
129
|
### Scoring Procedure
|
|
121
130
|
|
|
122
131
|
1. **Extract key concepts** from the active task:
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# OKF Tree-Search Retrieval
|
|
2
|
+
|
|
3
|
+
Reasoning-based retrieval over the OKF knowledge bundle. When a project was emitted in `okf` mode (`draft/wiki/` exists), agents locate relevant context by **navigating the concept tree** — reading routing descriptions and descending only the matching subtrees — instead of loading sections by a static heuristic. No embeddings, no chunking, no similarity search: relevance is decided by reasoning over the tree, the same way a human expert scans a table of contents.
|
|
4
|
+
|
|
5
|
+
Referenced by: `core/shared/draft-context-loading.md` (Relevance-Scored Context Loading). Applies to every command that loads focused project context (`/draft:implement`, `/draft:bughunt`, `/draft:review`, `/draft:debug`, `/draft:change`).
|
|
6
|
+
|
|
7
|
+
> **Prior art.** This adapts the navigation model of [PageIndex](https://github.com/VectifyAI/PageIndex) (vectorless, reasoning-based RAG) to Draft's self-authored artifacts. Draft already builds the tree — the OKF bundle (`index.md` → section indexes → concept pages) is a table-of-contents whose `description` frontmatter is the per-node routing key. What this procedure adds is the **retrieval loop**: a reasoning descent over that tree. Draft does not need PageIndex's tree-*generation* engine (it authors the tree itself) and stays vectorless by design.
|
|
8
|
+
|
|
9
|
+
## When this applies
|
|
10
|
+
|
|
11
|
+
Apply tree-search retrieval when ALL of these hold:
|
|
12
|
+
|
|
13
|
+
1. `draft/wiki/` exists (project emitted in `okf` mode) **and** `draft/wiki/index.md` carries a populated `<!-- CONCEPT-MAP:START -->…:END -->` block.
|
|
14
|
+
2. A specific track or task is active (focused retrieval — broad tasks terminate at the Synopsis, see below).
|
|
15
|
+
3. The command benefits from focused context (the relevance-scoring conditions in `draft-context-loading.md`).
|
|
16
|
+
|
|
17
|
+
If `draft/wiki/` does **not** exist (monolith mode), skip this procedure entirely and use the static section-scoring table in `draft-context-loading.md`. The two are mutually exclusive: tree-search is the okf-mode retrieval path; section-scoring is the monolith path.
|
|
18
|
+
|
|
19
|
+
## The retrieval loop
|
|
20
|
+
|
|
21
|
+
The bundle is a tree: `.ai-context.md` (index root: Synopsis + Concept Map) → section indexes (`systems/`, `features/`, `reference/`, `entrypoints/`, `overview/`) → concept pages. Each node advertises a `description` routing key. Navigate it, do not flatten it.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
1. Frame the query
|
|
25
|
+
Extract routing terms from the active task: domain nouns from spec.md
|
|
26
|
+
acceptance criteria, file paths / module names / tech terms from plan.md,
|
|
27
|
+
and the primary concern (data flow, API, security, perf, config, …).
|
|
28
|
+
|
|
29
|
+
2. Enter at the root
|
|
30
|
+
Read draft/.ai-context.md. The Synopsis is the cheap broad-context path —
|
|
31
|
+
for a BROAD task (onboarding, architecture overview, "how does X work
|
|
32
|
+
end-to-end") it is sufficient: TERMINATE here, do not descend.
|
|
33
|
+
For a FOCUSED task, read the Concept Map (the root routing table).
|
|
34
|
+
|
|
35
|
+
3. Select subtrees (reason, don't match strings)
|
|
36
|
+
For each Concept Map row, judge the `description` as a ROUTING DECISION:
|
|
37
|
+
"does opening this concept help THIS task?" Score each candidate:
|
|
38
|
+
- strong — description names the task's responsibility or its own terms
|
|
39
|
+
- possible — adjacent/depends-on the task area
|
|
40
|
+
- skip — unrelated
|
|
41
|
+
Descend `strong` first; hold `possible` as a frontier for step 5.
|
|
42
|
+
|
|
43
|
+
4. Descend to leaves
|
|
44
|
+
For a selected section, open its index.md and repeat step 3 against the
|
|
45
|
+
section's concept rows (one routing description per concept). Open the
|
|
46
|
+
matching concept page(s). A concept page is a LEAF — its `x-grounded-paths`
|
|
47
|
+
are the exact source files the task should open; `Used by` / `x-callers`
|
|
48
|
+
give the next hop if the task spans callers.
|
|
49
|
+
|
|
50
|
+
5. Expand only if under-covered
|
|
51
|
+
If the opened leaves do not cover the task's routing terms, expand the
|
|
52
|
+
highest-scored `possible` frontier node (step 3) and recurse. Otherwise stop.
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Routing decision criteria
|
|
56
|
+
|
|
57
|
+
The `description` frontmatter is load-bearing — it is written as a routing decision, not a summary (`core/templates/okf/concept.md`). Judge each node by:
|
|
58
|
+
|
|
59
|
+
| Signal | Descend when… |
|
|
60
|
+
|--------|---------------|
|
|
61
|
+
| Responsibility match | The description names the capability/module the task changes |
|
|
62
|
+
| Term overlap | Task's domain nouns / file paths appear in the description or `x-grounded-paths` |
|
|
63
|
+
| Caller/blast-radius reach | Task modifies a symbol whose `x-callers` / `Used by` point at this node |
|
|
64
|
+
| Concern alignment | Task's primary concern (security, perf, data flow) is this node's stated focus |
|
|
65
|
+
|
|
66
|
+
Reason about relevance — do not keyword-match. A concept whose description does not justify opening it for the task at hand is skipped even if a term coincidentally overlaps (similarity ≠ relevance).
|
|
67
|
+
|
|
68
|
+
## Termination & budget
|
|
69
|
+
|
|
70
|
+
- **Broad task** → terminate at the Synopsis (step 2). Do not open concept pages.
|
|
71
|
+
- **Focused task** → terminate when opened leaves cover the task's routing terms, or when **≤ 5 concept pages** have been opened (default budget; raise only if the task explicitly spans many subsystems, e.g. a cross-cutting refactor).
|
|
72
|
+
- **Depth** → the tree is shallow by construction (root → section → concept ≈ 2 hops). If a descent has not reached a leaf in 3 hops, stop and open the best leaf seen so far.
|
|
73
|
+
- **No match** → if no Concept Map row scores above `skip`, fall back to the Synopsis plus `## INVARIANTS` / `## FILES` / `## TEST` floor from `draft-context-loading.md`.
|
|
74
|
+
|
|
75
|
+
The minimum context floor from `draft-context-loading.md` (`META`, `INVARIANTS`, `TEST`, `FILES`) still applies and is always loaded regardless of the descent.
|
|
76
|
+
|
|
77
|
+
## Output contract (traceability)
|
|
78
|
+
|
|
79
|
+
Tree-search retrieval is explainable by construction — record the path taken, mirroring PageIndex's node-ID grounding:
|
|
80
|
+
|
|
81
|
+
- **Opened concepts** — the leaf pages selected, each with the one-line reason it was opened.
|
|
82
|
+
- **Grounded paths** — the union of `x-grounded-paths` across opened leaves: the precise source files the task will read or modify.
|
|
83
|
+
- **Skipped frontier** — `possible` nodes held but not expanded (so a follow-up task can resume from them).
|
|
84
|
+
|
|
85
|
+
Surface this trace when the command reports which context it loaded (e.g. `/draft:implement` plan preamble, `/draft:review` scope note). It replaces "loaded sections A, B, C" with "navigated to concepts X, Y because …".
|
|
86
|
+
|
|
87
|
+
## Degradation
|
|
88
|
+
|
|
89
|
+
| Scenario | Behavior |
|
|
90
|
+
|----------|----------|
|
|
91
|
+
| `draft/wiki/` missing | Skip; use monolith section-scoring in `draft-context-loading.md` |
|
|
92
|
+
| Concept Map markers empty/absent | Fall back to reading `wiki/*/index.md` section tables directly; if those are missing, use the Synopsis + floor |
|
|
93
|
+
| Routing descriptions thin/uninformative | Open the section `index.md` and skim concept titles; flag for `/draft:init refresh` to regenerate descriptions |
|
|
94
|
+
| Task is broad | Terminate at Synopsis — descending is over-fetch (a Red Flag per `red-flags.md`) |
|
|
@@ -52,3 +52,12 @@ so a focused task knows exactly which source files to open.
|
|
|
52
52
|
## See also
|
|
53
53
|
|
|
54
54
|
- [Related concept](../systems/other.md)
|
|
55
|
+
|
|
56
|
+
<!-- okf:concept-template v1
|
|
57
|
+
A stub or redirect-only page (e.g. "see architecture.md", an unreplaced
|
|
58
|
+
{PLACEHOLDER} token, or a body below the per-type minimum) FAILS
|
|
59
|
+
okf-validate-quality.sh and therefore does NOT satisfy okf-coverage-check.sh —
|
|
60
|
+
the bundle will not be promoted. Diagram types (Subsystem/Module/Feature/
|
|
61
|
+
Entrypoint) require ≥1 valid Mermaid block and ≥2 x-grounded-paths.
|
|
62
|
+
-->
|
|
63
|
+
|
|
@@ -336,6 +336,16 @@ DRAFT_INIT_MODE="${DRAFT_INIT_MODE:-auto}"
|
|
|
336
336
|
|
|
337
337
|
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.
|
|
338
338
|
|
|
339
|
+
**OKF Completeness Verification (blocking — tier 3+ `okf` mode).** Completeness is enforced by tooling, not honor system, so the wiki is generated completely for every module/sub-module/component on every run. Before promoting `draft.tmp/` → `draft/`, ALL must hold (see `references/okf-emitter.md` for the pipeline):
|
|
340
|
+
|
|
341
|
+
1. `okf-plan-concepts.sh` ran and the expected/required/deferred counts were logged **before** any page was written (the concept boundary is a tool output, not an in-context guess).
|
|
342
|
+
2. Every `required` entry in `concept-plan.json` has a non-stub page.
|
|
343
|
+
3. `okf-validate-all.sh … --plan … --strict` exits 0 (structure + per-type quality + coverage all pass).
|
|
344
|
+
4. `systems/coverage.md` was generated by tooling (verify the `<!-- okf:coverage-generated -->` marker) — no required package with `fan_in ≥ floor` is **MISSING**.
|
|
345
|
+
5. On any failure: **do not** atomic-rename; surface `.state/validation-report.json`.
|
|
346
|
+
|
|
347
|
+
> **Red flag:** writing concept pages without first running `okf-plan-concepts.sh`, or finishing generation while any `required` plan entry is unwritten, is a **completeness failure** — not a stylistic one.
|
|
348
|
+
|
|
339
349
|
### Route Explicit Modes Before Initialization
|
|
340
350
|
|
|
341
351
|
If the user explicitly invoked a specialist mode, route directly:
|
|
@@ -3291,7 +3301,10 @@ esac
|
|
|
3291
3301
|
Everything else in `draft init` (5-phase analysis, graph snapshot, `.state/`
|
|
3292
3302
|
hashing, scope detection, atomic staging) is **reused unchanged**. This mode adds
|
|
3293
3303
|
a decomposition + serialization stage. It introduces **no new LLM analysis
|
|
3294
|
-
engine
|
|
3304
|
+
engine**; its deterministic helpers are `okf-plan-concepts.sh` (expected-concept
|
|
3305
|
+
set), `okf-validate.sh` (structure), `okf-validate-quality.sh` (per-type
|
|
3306
|
+
anti-stub), `okf-coverage-check.sh` (completeness), and `okf-validate-all.sh`
|
|
3307
|
+
(the single promotion gate that runs all three), plus `okf-render-views.sh`.
|
|
3295
3308
|
|
|
3296
3309
|
## Target layout
|
|
3297
3310
|
|
|
@@ -3384,25 +3397,64 @@ Derive concepts from the graph, not by hand:
|
|
|
3384
3397
|
|
|
3385
3398
|
```
|
|
3386
3399
|
1. Survey → existing draft init 5-phase + graph snapshot (graph-snapshot.sh)
|
|
3387
|
-
2. Plan →
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3400
|
+
2. Plan → DETERMINISTIC. okf-plan-concepts.sh derives the expected-concept
|
|
3401
|
+
set from the graph (every package with fan_in ≥ floor → required
|
|
3402
|
+
Subsystem/Module; entrypoints → required; below-floor / allow-defer
|
|
3403
|
+
→ deferred with a reason) and writes draft.tmp/.state/concept-plan.json.
|
|
3404
|
+
okf-plan-concepts.sh --repo . [--scope PATH] \
|
|
3405
|
+
[--manifest FILE] [--min-fan-in 2] [--allow-defer GLOB]... \
|
|
3406
|
+
--out draft.tmp/.state/concept-plan.json
|
|
3407
|
+
This replaces the old in-context concept enumeration — the boundary
|
|
3408
|
+
of the work is now a tool output, not an LLM judgment, so modules
|
|
3409
|
+
cannot be silently dropped. LOG the counts (expected/required/
|
|
3410
|
+
deferred) BEFORE writing any page. `generated_order` is topo-ish
|
|
3411
|
+
(required + high-fan-in first) so forward cross-links resolve.
|
|
3412
|
+
3. Generate → iterate concept-plan.generated_order; write ONE page per REQUIRED
|
|
3413
|
+
entry, grounding each from the graph:
|
|
3392
3414
|
x-callers ← graph-callers.sh --symbol <c>
|
|
3393
3415
|
x-grounded-paths ← graph-impact.sh --symbol <c> (blast radius)
|
|
3394
3416
|
x-hotspot-score ← hotspot-rank.sh
|
|
3395
3417
|
overview diagrams ← mermaid-from-graph.sh
|
|
3396
3418
|
Record each source path → page in .state/path-to-concept.json.
|
|
3419
|
+
Loop post-condition: every required concept_id has an output file.
|
|
3420
|
+
⚠ Writing pages via shell heredoc without reading x-grounded-paths
|
|
3421
|
+
sources, or finishing while any required entry is unwritten, is a
|
|
3422
|
+
completeness failure — not a stylistic one.
|
|
3397
3423
|
4. Render views → ai-context.md (synopsis + Concept Map), architecture.md
|
|
3398
|
-
(concatenated view), wiki/log.md (see M4).
|
|
3399
|
-
5. Validate →
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
3424
|
+
(concatenated view + coverage banner), wiki/log.md (see M4).
|
|
3425
|
+
5. Validate → the promotion gate. Run all layers via the orchestrator:
|
|
3426
|
+
5a. okf-validate-all.sh draft.tmp/wiki \
|
|
3427
|
+
--repo . \
|
|
3428
|
+
--plan draft.tmp/.state/concept-plan.json \
|
|
3429
|
+
--path-index draft.tmp/.state/path-to-concept.json \
|
|
3430
|
+
--strict --report draft.tmp/.state/validation-report.json
|
|
3431
|
+
It runs, in order: okf-validate.sh (structure + reverse index),
|
|
3432
|
+
okf-validate-quality.sh (per-type anti-stub / depth / mermaid lint),
|
|
3433
|
+
okf-coverage-check.sh (every required plan entry → real page).
|
|
3434
|
+
ANY layer failing ⇒ exit non-zero ⇒ DO NOT atomic-rename.
|
|
3435
|
+
coverage.md (systems/coverage.md) is regenerated by the coverage
|
|
3436
|
+
layer; it is tool-owned (marker <!-- okf:coverage-generated -->) —
|
|
3437
|
+
never hand-author it except deferral reasons in the manifest.
|
|
3438
|
+
6. Emit → mv draft.tmp/ draft/ ONLY IF step 5 exit 0 ; update .state/.
|
|
3439
|
+
On failure keep draft.tmp/ and surface validation-report.json.
|
|
3440
|
+
```
|
|
3441
|
+
|
|
3442
|
+
### Validation report schema (`.state/validation-report.json`)
|
|
3443
|
+
|
|
3444
|
+
```json
|
|
3445
|
+
{ "valid": false, "bundle": "draft.tmp/wiki",
|
|
3446
|
+
"layers": { "structure": "pass", "quality": "pass", "coverage": "fail" } }
|
|
3404
3447
|
```
|
|
3405
3448
|
|
|
3449
|
+
### Component manifest (optional — `--manifest FILE`)
|
|
3450
|
+
|
|
3451
|
+
When the graph engine is unavailable (or a repo wants an authoritative list), pass
|
|
3452
|
+
a plain-text manifest: one component name per line, `#` comments and blanks ignored.
|
|
3453
|
+
Every listed component becomes a REQUIRED concept; `--allow-defer GLOB` still moves
|
|
3454
|
+
matches to deferred. Without a manifest the plan comes from the graph, and only if
|
|
3455
|
+
both are unavailable does it fall back to a heuristic top-level-dir scan (which it
|
|
3456
|
+
marks `degraded: true`).
|
|
3457
|
+
|
|
3406
3458
|
Page bodies are LLM-narrated for readability **but** the graph-derived
|
|
3407
3459
|
frontmatter and the `Blast radius`/`Used by` sections are deterministic. To keep
|
|
3408
3460
|
incremental carry-forward byte-identical (open decision 2), cache the narrated
|
|
@@ -3456,17 +3508,22 @@ section `index.md` tables are the injection slots for the routing tables.
|
|
|
3456
3508
|
`draft init refresh` under `okf` mode:
|
|
3457
3509
|
|
|
3458
3510
|
```
|
|
3459
|
-
1.
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
6.
|
|
3511
|
+
1. Re-derive the plan: okf-plan-concepts.sh (modules added since last run become
|
|
3512
|
+
REQUIRED — a new package can't slip through a refresh either)
|
|
3513
|
+
2. Diff hashes.json vs working tree → changed source paths
|
|
3514
|
+
3. path-to-concept.json → affected concept pages
|
|
3515
|
+
4. Regenerate ONLY affected concepts; carry the rest verbatim (cached narration)
|
|
3516
|
+
5. Re-render ai-context.md / architecture.md / log.md (cheap; always regenerated)
|
|
3517
|
+
6. Re-validate (full gate): okf-validate-all.sh on the bundle with --plan and
|
|
3518
|
+
--path-index. Refresh re-runs structure + quality + coverage — a changed
|
|
3519
|
+
concept must still clear the quality bar, and a newly-required module must
|
|
3520
|
+
still be present.
|
|
3521
|
+
7. Append log.md; update hashes.json + path-to-concept.json
|
|
3466
3522
|
```
|
|
3467
3523
|
|
|
3468
3524
|
A 1-file change regenerates only the concept(s) that file grounds. Unchanged
|
|
3469
|
-
concepts are byte-identical across runs.
|
|
3525
|
+
concepts are byte-identical across runs. The full gate still runs, so refresh
|
|
3526
|
+
cannot promote a bundle that a newly-added module left incomplete.
|
|
3470
3527
|
|
|
3471
3528
|
## Backward compatibility (§9)
|
|
3472
3529
|
|
|
@@ -16274,6 +16331,15 @@ Apply relevance scoring when ALL of these conditions are true:
|
|
|
16274
16331
|
|
|
16275
16332
|
Do NOT apply relevance scoring for commands that need full context (`draft init`, `draft deep-review`, `draft decompose`).
|
|
16276
16333
|
|
|
16334
|
+
### Retrieval Path Selection (okf vs monolith)
|
|
16335
|
+
|
|
16336
|
+
Relevance scoring has two implementations; pick by output mode:
|
|
16337
|
+
|
|
16338
|
+
- **okf mode** — if `draft/wiki/` exists, use **tree-search retrieval** (`core/shared/okf-retrieval.md`): navigate the OKF Concept Map by reasoning over each concept's routing `description`, descending only the matching subtrees. This is the vectorless, reasoning-based path (PageIndex-style) and supersedes the static section table below for okf bundles.
|
|
16339
|
+
- **monolith mode** — if `draft/wiki/` does not exist, use the static **Scoring Procedure** below against `.ai-context.md` sections.
|
|
16340
|
+
|
|
16341
|
+
The minimum context floor (`META`, `INVARIANTS`, `TEST`, `FILES`) applies to both paths.
|
|
16342
|
+
|
|
16277
16343
|
### Scoring Procedure
|
|
16278
16344
|
|
|
16279
16345
|
1. **Extract key concepts** from the active task:
|
|
@@ -17647,6 +17713,109 @@ The engine indexes C/C++, Go, Python, TypeScript/JS, and more (tree-sitter, 159
|
|
|
17647
17713
|
|
|
17648
17714
|
---
|
|
17649
17715
|
|
|
17716
|
+
## core/shared/okf-retrieval.md
|
|
17717
|
+
|
|
17718
|
+
<core-file path="core/shared/okf-retrieval.md">
|
|
17719
|
+
|
|
17720
|
+
# OKF Tree-Search Retrieval
|
|
17721
|
+
|
|
17722
|
+
Reasoning-based retrieval over the OKF knowledge bundle. When a project was emitted in `okf` mode (`draft/wiki/` exists), agents locate relevant context by **navigating the concept tree** — reading routing descriptions and descending only the matching subtrees — instead of loading sections by a static heuristic. No embeddings, no chunking, no similarity search: relevance is decided by reasoning over the tree, the same way a human expert scans a table of contents.
|
|
17723
|
+
|
|
17724
|
+
Referenced by: `core/shared/draft-context-loading.md` (Relevance-Scored Context Loading). Applies to every command that loads focused project context (`draft implement`, `draft bughunt`, `draft review`, `draft debug`, `draft change`).
|
|
17725
|
+
|
|
17726
|
+
> **Prior art.** This adapts the navigation model of [PageIndex](https://github.com/VectifyAI/PageIndex) (vectorless, reasoning-based RAG) to Draft's self-authored artifacts. Draft already builds the tree — the OKF bundle (`index.md` → section indexes → concept pages) is a table-of-contents whose `description` frontmatter is the per-node routing key. What this procedure adds is the **retrieval loop**: a reasoning descent over that tree. Draft does not need PageIndex's tree-*generation* engine (it authors the tree itself) and stays vectorless by design.
|
|
17727
|
+
|
|
17728
|
+
## When this applies
|
|
17729
|
+
|
|
17730
|
+
Apply tree-search retrieval when ALL of these hold:
|
|
17731
|
+
|
|
17732
|
+
1. `draft/wiki/` exists (project emitted in `okf` mode) **and** `draft/wiki/index.md` carries a populated `<!-- CONCEPT-MAP:START -->…:END -->` block.
|
|
17733
|
+
2. A specific track or task is active (focused retrieval — broad tasks terminate at the Synopsis, see below).
|
|
17734
|
+
3. The command benefits from focused context (the relevance-scoring conditions in `draft-context-loading.md`).
|
|
17735
|
+
|
|
17736
|
+
If `draft/wiki/` does **not** exist (monolith mode), skip this procedure entirely and use the static section-scoring table in `draft-context-loading.md`. The two are mutually exclusive: tree-search is the okf-mode retrieval path; section-scoring is the monolith path.
|
|
17737
|
+
|
|
17738
|
+
## The retrieval loop
|
|
17739
|
+
|
|
17740
|
+
The bundle is a tree: `.ai-context.md` (index root: Synopsis + Concept Map) → section indexes (`systems/`, `features/`, `reference/`, `entrypoints/`, `overview/`) → concept pages. Each node advertises a `description` routing key. Navigate it, do not flatten it.
|
|
17741
|
+
|
|
17742
|
+
```
|
|
17743
|
+
1. Frame the query
|
|
17744
|
+
Extract routing terms from the active task: domain nouns from spec.md
|
|
17745
|
+
acceptance criteria, file paths / module names / tech terms from plan.md,
|
|
17746
|
+
and the primary concern (data flow, API, security, perf, config, …).
|
|
17747
|
+
|
|
17748
|
+
2. Enter at the root
|
|
17749
|
+
Read draft/.ai-context.md. The Synopsis is the cheap broad-context path —
|
|
17750
|
+
for a BROAD task (onboarding, architecture overview, "how does X work
|
|
17751
|
+
end-to-end") it is sufficient: TERMINATE here, do not descend.
|
|
17752
|
+
For a FOCUSED task, read the Concept Map (the root routing table).
|
|
17753
|
+
|
|
17754
|
+
3. Select subtrees (reason, don't match strings)
|
|
17755
|
+
For each Concept Map row, judge the `description` as a ROUTING DECISION:
|
|
17756
|
+
"does opening this concept help THIS task?" Score each candidate:
|
|
17757
|
+
- strong — description names the task's responsibility or its own terms
|
|
17758
|
+
- possible — adjacent/depends-on the task area
|
|
17759
|
+
- skip — unrelated
|
|
17760
|
+
Descend `strong` first; hold `possible` as a frontier for step 5.
|
|
17761
|
+
|
|
17762
|
+
4. Descend to leaves
|
|
17763
|
+
For a selected section, open its index.md and repeat step 3 against the
|
|
17764
|
+
section's concept rows (one routing description per concept). Open the
|
|
17765
|
+
matching concept page(s). A concept page is a LEAF — its `x-grounded-paths`
|
|
17766
|
+
are the exact source files the task should open; `Used by` / `x-callers`
|
|
17767
|
+
give the next hop if the task spans callers.
|
|
17768
|
+
|
|
17769
|
+
5. Expand only if under-covered
|
|
17770
|
+
If the opened leaves do not cover the task's routing terms, expand the
|
|
17771
|
+
highest-scored `possible` frontier node (step 3) and recurse. Otherwise stop.
|
|
17772
|
+
```
|
|
17773
|
+
|
|
17774
|
+
## Routing decision criteria
|
|
17775
|
+
|
|
17776
|
+
The `description` frontmatter is load-bearing — it is written as a routing decision, not a summary (`core/templates/okf/concept.md`). Judge each node by:
|
|
17777
|
+
|
|
17778
|
+
| Signal | Descend when… |
|
|
17779
|
+
|--------|---------------|
|
|
17780
|
+
| Responsibility match | The description names the capability/module the task changes |
|
|
17781
|
+
| Term overlap | Task's domain nouns / file paths appear in the description or `x-grounded-paths` |
|
|
17782
|
+
| Caller/blast-radius reach | Task modifies a symbol whose `x-callers` / `Used by` point at this node |
|
|
17783
|
+
| Concern alignment | Task's primary concern (security, perf, data flow) is this node's stated focus |
|
|
17784
|
+
|
|
17785
|
+
Reason about relevance — do not keyword-match. A concept whose description does not justify opening it for the task at hand is skipped even if a term coincidentally overlaps (similarity ≠ relevance).
|
|
17786
|
+
|
|
17787
|
+
## Termination & budget
|
|
17788
|
+
|
|
17789
|
+
- **Broad task** → terminate at the Synopsis (step 2). Do not open concept pages.
|
|
17790
|
+
- **Focused task** → terminate when opened leaves cover the task's routing terms, or when **≤ 5 concept pages** have been opened (default budget; raise only if the task explicitly spans many subsystems, e.g. a cross-cutting refactor).
|
|
17791
|
+
- **Depth** → the tree is shallow by construction (root → section → concept ≈ 2 hops). If a descent has not reached a leaf in 3 hops, stop and open the best leaf seen so far.
|
|
17792
|
+
- **No match** → if no Concept Map row scores above `skip`, fall back to the Synopsis plus `## INVARIANTS` / `## FILES` / `## TEST` floor from `draft-context-loading.md`.
|
|
17793
|
+
|
|
17794
|
+
The minimum context floor from `draft-context-loading.md` (`META`, `INVARIANTS`, `TEST`, `FILES`) still applies and is always loaded regardless of the descent.
|
|
17795
|
+
|
|
17796
|
+
## Output contract (traceability)
|
|
17797
|
+
|
|
17798
|
+
Tree-search retrieval is explainable by construction — record the path taken, mirroring PageIndex's node-ID grounding:
|
|
17799
|
+
|
|
17800
|
+
- **Opened concepts** — the leaf pages selected, each with the one-line reason it was opened.
|
|
17801
|
+
- **Grounded paths** — the union of `x-grounded-paths` across opened leaves: the precise source files the task will read or modify.
|
|
17802
|
+
- **Skipped frontier** — `possible` nodes held but not expanded (so a follow-up task can resume from them).
|
|
17803
|
+
|
|
17804
|
+
Surface this trace when the command reports which context it loaded (e.g. `draft implement` plan preamble, `draft review` scope note). It replaces "loaded sections A, B, C" with "navigated to concepts X, Y because …".
|
|
17805
|
+
|
|
17806
|
+
## Degradation
|
|
17807
|
+
|
|
17808
|
+
| Scenario | Behavior |
|
|
17809
|
+
|----------|----------|
|
|
17810
|
+
| `draft/wiki/` missing | Skip; use monolith section-scoring in `draft-context-loading.md` |
|
|
17811
|
+
| Concept Map markers empty/absent | Fall back to reading `wiki/*/index.md` section tables directly; if those are missing, use the Synopsis + floor |
|
|
17812
|
+
| Routing descriptions thin/uninformative | Open the section `index.md` and skim concept titles; flag for `draft init refresh` to regenerate descriptions |
|
|
17813
|
+
| Task is broad | Terminate at Synopsis — descending is over-fetch (a Red Flag per `red-flags.md`) |
|
|
17814
|
+
|
|
17815
|
+
</core-file>
|
|
17816
|
+
|
|
17817
|
+
---
|
|
17818
|
+
|
|
17650
17819
|
## core/shared/parallel-analysis.md
|
|
17651
17820
|
|
|
17652
17821
|
<core-file path="core/shared/parallel-analysis.md">
|
|
@@ -22575,6 +22744,15 @@ so a focused task knows exactly which source files to open.
|
|
|
22575
22744
|
|
|
22576
22745
|
- [Related concept](../systems/other.md)
|
|
22577
22746
|
|
|
22747
|
+
<!-- okf:concept-template v1
|
|
22748
|
+
A stub or redirect-only page (e.g. "see architecture.md", an unreplaced
|
|
22749
|
+
{PLACEHOLDER} token, or a body below the per-type minimum) FAILS
|
|
22750
|
+
okf-validate-quality.sh and therefore does NOT satisfy okf-coverage-check.sh —
|
|
22751
|
+
the bundle will not be promoted. Diagram types (Subsystem/Module/Feature/
|
|
22752
|
+
Entrypoint) require ≥1 valid Mermaid block and ≥2 x-grounded-paths.
|
|
22753
|
+
-->
|
|
22754
|
+
|
|
22755
|
+
|
|
22578
22756
|
</core-file>
|
|
22579
22757
|
|
|
22580
22758
|
---
|