@ctxr/skill-llm-wiki 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +21 -0
  3. package/README.md +484 -0
  4. package/SKILL.md +252 -0
  5. package/guide/basics/concepts.md +74 -0
  6. package/guide/basics/index.md +45 -0
  7. package/guide/basics/schema.md +140 -0
  8. package/guide/cli.md +256 -0
  9. package/guide/correctness/index.md +45 -0
  10. package/guide/correctness/invariants.md +89 -0
  11. package/guide/correctness/safety.md +96 -0
  12. package/guide/history/diff.md +110 -0
  13. package/guide/history/hidden-git.md +130 -0
  14. package/guide/history/index.md +52 -0
  15. package/guide/history/remote-sync.md +113 -0
  16. package/guide/index.md +134 -0
  17. package/guide/isolation/coexistence.md +134 -0
  18. package/guide/isolation/index.md +44 -0
  19. package/guide/isolation/scale.md +251 -0
  20. package/guide/layout/in-place-mode.md +97 -0
  21. package/guide/layout/index.md +53 -0
  22. package/guide/layout/layout-contract.md +131 -0
  23. package/guide/layout/layout-modes.md +115 -0
  24. package/guide/operations/index.md +76 -0
  25. package/guide/operations/ingest/build.md +75 -0
  26. package/guide/operations/ingest/extend.md +61 -0
  27. package/guide/operations/ingest/index.md +54 -0
  28. package/guide/operations/ingest/join.md +65 -0
  29. package/guide/operations/maintain/fix.md +66 -0
  30. package/guide/operations/maintain/index.md +47 -0
  31. package/guide/operations/maintain/rebuild.md +86 -0
  32. package/guide/operations/validate.md +48 -0
  33. package/guide/substrate/index.md +47 -0
  34. package/guide/substrate/operators.md +96 -0
  35. package/guide/substrate/tiered-ai.md +363 -0
  36. package/guide/ux/index.md +44 -0
  37. package/guide/ux/preflight.md +150 -0
  38. package/guide/ux/user-intent.md +135 -0
  39. package/package.json +55 -0
  40. package/scripts/cli.mjs +893 -0
  41. package/scripts/commands/remote.mjs +93 -0
  42. package/scripts/commands/review.mjs +253 -0
  43. package/scripts/commands/sync.mjs +84 -0
  44. package/scripts/lib/chunk.mjs +421 -0
  45. package/scripts/lib/cluster-detect.mjs +516 -0
  46. package/scripts/lib/decision-log.mjs +343 -0
  47. package/scripts/lib/draft.mjs +158 -0
  48. package/scripts/lib/embeddings.mjs +366 -0
  49. package/scripts/lib/frontmatter.mjs +497 -0
  50. package/scripts/lib/git-commands.mjs +155 -0
  51. package/scripts/lib/git.mjs +486 -0
  52. package/scripts/lib/gitignore.mjs +62 -0
  53. package/scripts/lib/history.mjs +331 -0
  54. package/scripts/lib/indices.mjs +510 -0
  55. package/scripts/lib/ingest.mjs +258 -0
  56. package/scripts/lib/intent.mjs +713 -0
  57. package/scripts/lib/interactive.mjs +99 -0
  58. package/scripts/lib/migrate.mjs +126 -0
  59. package/scripts/lib/nest-applier.mjs +260 -0
  60. package/scripts/lib/operators.mjs +1365 -0
  61. package/scripts/lib/orchestrator.mjs +718 -0
  62. package/scripts/lib/paths.mjs +197 -0
  63. package/scripts/lib/preflight.mjs +213 -0
  64. package/scripts/lib/provenance.mjs +672 -0
  65. package/scripts/lib/quality-metric.mjs +269 -0
  66. package/scripts/lib/query-fixture.mjs +71 -0
  67. package/scripts/lib/rollback.mjs +95 -0
  68. package/scripts/lib/shape-check.mjs +172 -0
  69. package/scripts/lib/similarity-cache.mjs +126 -0
  70. package/scripts/lib/similarity.mjs +230 -0
  71. package/scripts/lib/snapshot.mjs +54 -0
  72. package/scripts/lib/source-frontmatter.mjs +85 -0
  73. package/scripts/lib/tier2-protocol.mjs +470 -0
  74. package/scripts/lib/tiered.mjs +453 -0
  75. package/scripts/lib/validate.mjs +362 -0
@@ -0,0 +1,76 @@
1
+ ---
2
+ id: operations
3
+ type: index
4
+ depth_role: subcategory
5
+ depth: 1
6
+ focus: per-operation phase pipelines for Build, Extend, Validate, Rebuild, Fix, and Join
7
+ parents:
8
+ - "../index.md"
9
+ shared_covers:
10
+ - every operation runs a named phase pipeline with one git commit per phase in the private repo
11
+ - "every operation starts with a preflight and ends with an atomic commit-finalize that tags op/<id>"
12
+ - "every operation honours the safety envelope from guide/safety.md"
13
+ activation_defaults:
14
+ tag_matches:
15
+ - operation
16
+ orientation: |
17
+ One leaf per top-level operation. Exactly one activates per user ask,
18
+ selected by its keyword_matches on the profile's operation keyword.
19
+ Activation here requires the profile to carry the "operation" tag — the
20
+ whole subcategory is short-circuited for informational queries so they
21
+ never descend into operation leaves.
22
+
23
+ generator: "skill-llm-wiki/v1"
24
+ entries:
25
+ - id: validate
26
+ file: validate.md
27
+ type: primary
28
+ focus: Validate operation — read-only correctness check against a wiki
29
+ tags:
30
+ - operations
31
+ - validate
32
+ - read-only
33
+ - id: ingest
34
+ file: "ingest/index.md"
35
+ type: index
36
+ focus: "Operations that bring external source material into a wiki (create, extend, merge)."
37
+ tags:
38
+ - operations
39
+ - id: maintain
40
+ file: "maintain/index.md"
41
+ type: index
42
+ focus: Mutating maintenance operations on an existing wiki — repair divergences and optimise structure.
43
+ tags:
44
+ - operations
45
+ children:
46
+ - "ingest/index.md"
47
+ - "maintain/index.md"
48
+ ---
49
+ <!-- BEGIN AUTO-GENERATED NAVIGATION -->
50
+
51
+ # Operations
52
+
53
+ **Focus:** per-operation phase pipelines for Build, Extend, Validate, Rebuild, Fix, and Join
54
+
55
+ **Shared across all children:**
56
+
57
+ - every operation runs a named phase pipeline with one git commit per phase in the private repo
58
+ - every operation starts with a preflight and ends with an atomic commit-finalize that tags op/<id>
59
+ - every operation honours the safety envelope from guide/safety.md
60
+
61
+ ## Children
62
+
63
+ | File | Type | Focus |
64
+ |------|------|-------|
65
+ | [validate.md](validate.md) | 📄 primary | Validate operation — read-only correctness check against a wiki |
66
+ | [ingest/index.md](ingest/index.md) | 📁 index | Operations that bring external source material into a wiki (create, extend, merge). |
67
+ | [maintain/index.md](maintain/index.md) | 📁 index | Mutating maintenance operations on an existing wiki — repair divergences and optimise structure. |
68
+
69
+ <!-- END AUTO-GENERATED NAVIGATION -->
70
+
71
+ <!-- BEGIN AUTHORED ORIENTATION -->
72
+ One leaf per top-level operation. Claude loads exactly one of these per
73
+ invocation, named by SKILL.md's routing table. Each leaf documents the
74
+ operation's phases, adaptations for hosted mode where applicable, and
75
+ any mode-specific notes. Leaves here never chain into each other.
76
+ <!-- END AUTHORED ORIENTATION -->
@@ -0,0 +1,75 @@
1
+ ---
2
+ id: build
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: "Build operation — create a new wiki from source(s) via the full phase pipeline"
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "phase pipeline: preflight, intent-check, pre-op snapshot, ingest, draft-frontmatter, operator-convergence, (optional) review, index-generation, validation, commit-finalize"
10
+ - "sibling mode produces `<source>.wiki/` with its full history in the private git; in-place mode transforms the source itself; hosted mode writes under a user-chosen target with a .llmwiki.layout.yaml contract"
11
+ - "classify is currently a pre-draft categoriser (draft-category) plus per-entry placement; Claude handles unplaceable candidates"
12
+ - draft-frontmatter uses script-first heuristic + Claude fallback for prose-heavy sources
13
+ - operator-convergence is contract-gated in hosted mode
14
+ - "determinism: LLM_WIKI_FIXED_TIMESTAMP pins commit SHAs for reproducible builds"
15
+ tags:
16
+ - operations
17
+ - build
18
+ activation:
19
+ keyword_matches:
20
+ - build
21
+ - create wiki
22
+ - new wiki
23
+ - from source
24
+ - build wiki
25
+ tag_matches:
26
+ - operation
27
+ - building
28
+ source:
29
+ origin: file
30
+ path: "operations/build.md"
31
+ hash: "sha256:37b89f4bc9b693720465dc7cc57b32d18f627f9e5ce520d0ed0cfb4f950c90c7"
32
+ ---
33
+
34
+ # Build
35
+
36
+ **Purpose:** create a new wiki from source(s).
37
+
38
+ ## Invocation
39
+
40
+ ```bash
41
+ node scripts/cli.mjs build <source> [--layout-mode sibling|in-place|hosted] [--target <path>]
42
+ ```
43
+
44
+ The default mode is `sibling`, which writes to `<source>.wiki/`. Pass `--layout-mode in-place` to transform `<source>/` itself, or `--layout-mode hosted --target <path>` for a user-chosen target that carries a `.llmwiki.layout.yaml` contract. Ambiguous invocations refuse with an `INT-NN` structured error — see `guide/user-intent.md`.
45
+
46
+ ## Phases (executed by the CLI, not by hand)
47
+
48
+ The `build` subcommand runs the full phase pipeline end-to-end under the orchestrator. Claude does not materialise entries by hand; the CLI is the source of truth. The sequence is:
49
+
50
+ 0. **preflight** — Node.js ≥18, git ≥2.25, and (if the target already exists) `git fsck` on the private repo. Preflight failures exit with codes 4 (Node), 5 (git), or 6 (wiki-corrupt).
51
+ 1. **intent-check** — `intent.mjs` resolves the layout mode and target; any ambiguity short-circuits with `INT-NN` and exit 2.
52
+ 2. **pre-op snapshot** — `git add -A && git commit -m "pre-op <op-id>"`, tag `pre-op/<op-id>`. Rollback anchor for the entire operation. Also writes/merges `<wiki>/.gitignore` with the wiki-local ignore entries.
53
+ 3. **ingest** — walks the source, computes content hashes and byte sizes, records per-target provenance to `<wiki>/.llmwiki/provenance.yaml` so `LOSS-01` can verify nothing was silently dropped.
54
+ 4. **draft-frontmatter** — per-entry heuristic draft; Claude-in-Tier-2 fallback for prose-heavy sources (via the tiered ladder — see `guide/tiered-ai.md`). Commits as `phase draft-frontmatter: wrote N leaves`.
55
+ 5. **operator-convergence** — applies DESCEND > LIFT > MERGE > NEST > DECOMPOSE in priority order until no operator reports a change. One git commit per iteration so `git log pre-op/<id>..HEAD` shows per-iteration progress. Operator decisions at Tier 2 go through the decision log at `<wiki>/.llmwiki/decisions.yaml`.
56
+ 6. **review (optional)** — only if invoked with `rebuild --review`. Not part of the default `build` flow.
57
+ 7. **index-generation** — regenerates every `index.md`. Commit: `phase index-generation: rebuilt N index.md files`.
58
+ 8. **validation** — runs all hard invariants from `guide/invariants.md`, including `GIT-01` and `LOSS-01`. Failure triggers `git reset --hard pre-op/<id>` + `git clean -fd`; the operation exits 2 and nothing is persisted under `op/<op-id>`.
59
+ 9. **commit-finalize** — tags `op/<op-id>`, appends to `<wiki>/.llmwiki/op-log.yaml`, deletes the live `.work/` scratch.
60
+
61
+ ## What Claude does at session time
62
+
63
+ Claude does not run the phase pipeline by hand. Claude's job during a build is:
64
+
65
+ 1. **Understand the user's ask.** Which source, which layout mode, any constraints. Prompt on ambiguity — see `guide/user-intent.md`.
66
+ 2. **Invoke `build` with the right flags.** Relay the CLI's output to the user.
67
+ 3. **If the CLI exits with `INT-NN`**, read the structured error and ask the user the disambiguating question. Do not invent a flag the user didn't confirm.
68
+ 4. **If the CLI fails at validation**, read the structured findings and either (a) propose a Fix invocation to repair them, or (b) tell the user what went wrong. Never hand-edit frontmatter in a wiki that failed validation — the working tree is already back at `pre-op/<op-id>`.
69
+ 5. **If a Tier 2 AI call was needed during draft-frontmatter**, the orchestrator will prompt Claude-at-session-time via a structured request. Read the source, draft the `focus` and `covers[]`, return them.
70
+
71
+ ## Notes
72
+
73
+ - **Determinism.** Setting `LLM_WIKI_FIXED_TIMESTAMP=<epoch>` pins commit/tag timestamps so same-input builds produce byte-identical commit SHAs across runs and machines.
74
+ - **Hosted mode.** The contract file must already exist at the target root before the build runs — if it doesn't, the build refuses with `INT-09b` or (if the target is foreign) `INT-01b`.
75
+ - **In-place mode.** The `pre-op/<op-id>` snapshot captures the source content byte-for-byte before the build starts, so rollback restores the original directory exactly.
@@ -0,0 +1,61 @@
1
+ ---
2
+ id: extend
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: Extend operation — add new sources to an existing wiki without reprocessing existing entries
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "phase pipeline: preflight, intent-check, pre-op snapshot, ingest-new, draft-frontmatter-new, place-new, index-rebuild, validation, commit-finalize"
10
+ - "extend operates on the same stable `<source>.wiki/` sibling (or in-place / hosted target), producing new per-phase commits under a new `op/<id>` tag"
11
+ - new entries are classified against existing categories; hosted mode cannot invent new top-level directories
12
+ - extend never applies rewrite operators; shape warnings accumulate for the next Rebuild
13
+ tags:
14
+ - operations
15
+ - extend
16
+ activation:
17
+ keyword_matches:
18
+ - extend
19
+ - add source
20
+ - add to wiki
21
+ - new source
22
+ - append
23
+ tag_matches:
24
+ - operation
25
+ - building
26
+ source:
27
+ origin: file
28
+ path: "operations/extend.md"
29
+ hash: "sha256:2a8465183bc32543b35e1b0c61ecadf1070ad3f569c321ae5ca6c335a4961b15"
30
+ ---
31
+
32
+ # Extend
33
+
34
+ **Purpose:** add new sources to an existing wiki without reprocessing existing entries.
35
+
36
+ ## Invocation
37
+
38
+ ```bash
39
+ node scripts/cli.mjs extend <wiki> <source>
40
+ ```
41
+
42
+ The wiki keeps its original layout mode; extend appends commits to the same stable sibling directory (or in-place target, or hosted target) and tags a new `op/<id>` on completion. Rollback to `pre-op/<id>` restores the pre-extend state exactly.
43
+
44
+ ## Phases
45
+
46
+ 0. **preflight** — Node.js, git, and wiki-fsck checks (see SKILL.md and `guide/preflight.md`). Exit codes 4 / 5 / 6 on failure.
47
+ 1. **intent-check** — `intent.mjs` resolves the target; legacy `.llmwiki.v<N>/` targets trigger the `INT-04` migration prompt; a dirty enclosing user git repo raises `INT-08` unless `--accept-dirty` is passed.
48
+ 2. **pre-op snapshot** — `git add -A && git commit -m "pre-op <op-id>"`, tag `pre-op/<op-id>`.
49
+ 3. **ingest-new** — walks only the new source(s), computes hashes. *(Provenance is currently build-only; extend does not append to `provenance.yaml`.)*
50
+ 4. **draft-frontmatter-new** — per-entry heuristic draft with Tier-2 fallback for prose-heavy sources.
51
+ 5. **place-new** — classify each new entry against existing categories. Hosted mode: against the contract's `layout[]`. If nothing fits: sibling mode creates a new top-level category; hosted mode escalates to HUMAN (you may not invent new contract directories).
52
+ 6. **index-rebuild** — regenerates affected `index.md` files.
53
+ 7. **validation** — full hard-invariant check.
54
+ 8. **commit-finalize** — tags `op/<op-id>`, appends to the op-log.
55
+
56
+ ## Notes
57
+
58
+ - Extend does **not** apply rewrite operators. Accumulated shape warnings are surfaced via `shape-check` and addressed by an explicit next Rebuild.
59
+ - Extend never touches entries that already exist — it only writes new ones into affected branches.
60
+ - In hosted mode, Extend cannot invent new top-level directories. If a new entry doesn't fit anywhere, escalate to HUMAN and stop.
61
+ - Extend is currently a **minimal forward-port** of the build pipeline scoped to new sources; a richer incremental-update path (per-entry diff, selective re-classification) is scoped as future work.
@@ -0,0 +1,54 @@
1
+ ---
2
+ id: ingest
3
+ type: index
4
+ depth_role: subcategory
5
+ depth: 2
6
+ focus: "Operations that bring external source material into a wiki (create, extend, merge)."
7
+ parents:
8
+ - "../index.md"
9
+ shared_covers: []
10
+ tags:
11
+ - operations
12
+ entries:
13
+ - id: build
14
+ file: build.md
15
+ type: primary
16
+ focus: "Build operation — create a new wiki from source(s) via the full phase pipeline"
17
+ tags:
18
+ - operations
19
+ - build
20
+ - id: extend
21
+ file: extend.md
22
+ type: primary
23
+ focus: Extend operation — add new sources to an existing wiki without reprocessing existing entries
24
+ tags:
25
+ - operations
26
+ - extend
27
+ - id: join
28
+ file: join.md
29
+ type: primary
30
+ focus: Join operation — merge N ≥ 2 existing wikis into a single unified wiki
31
+ tags:
32
+ - operations
33
+ - join
34
+ - merge
35
+ children: []
36
+ ---
37
+ <!-- BEGIN AUTO-GENERATED NAVIGATION -->
38
+
39
+ # Ingest
40
+
41
+ **Focus:** Operations that bring external source material into a wiki (create, extend, merge).
42
+
43
+ ## Children
44
+
45
+ | File | Type | Focus |
46
+ |------|------|-------|
47
+ | [build.md](build.md) | 📄 primary | Build operation — create a new wiki from source(s) via the full phase pipeline |
48
+ | [extend.md](extend.md) | 📄 primary | Extend operation — add new sources to an existing wiki without reprocessing existing entries |
49
+ | [join.md](join.md) | 📄 primary | Join operation — merge N ≥ 2 existing wikis into a single unified wiki |
50
+
51
+ <!-- END AUTO-GENERATED NAVIGATION -->
52
+
53
+ <!-- BEGIN AUTHORED ORIENTATION -->
54
+ <!-- END AUTHORED ORIENTATION -->
@@ -0,0 +1,65 @@
1
+ ---
2
+ id: join
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: Join operation — merge N ≥ 2 existing wikis into a single unified wiki
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "11-phase pipeline: preflight, ingest-all, source-validate, plan-union, resolve-id-collisions, merge-categories, rewire-references, apply-operators, generate-indices, validation, golden-path-union, commit"
10
+ - "id collision policies: merge, namespace (default), ask"
11
+ - category merging via category-level MERGE when focus matches
12
+ - reference rewiring across sources via id → alias → rename map
13
+ - "source immutability: inputs are read-only and byte-identical after Join"
14
+ - hosted wikis require compatible contracts or a merged contract at the join target
15
+ tags:
16
+ - operations
17
+ - join
18
+ - merge
19
+ activation:
20
+ keyword_matches:
21
+ - join
22
+ - merge wikis
23
+ - combine wikis
24
+ - unify
25
+ tag_matches:
26
+ - operation
27
+ - building
28
+ - mutation
29
+ source:
30
+ origin: file
31
+ path: "operations/join.md"
32
+ hash: "sha256:5b44d3f5f6bd218de6e60dba2286f43ce3cee5c84c171ca978e3f6cb5f005e4e"
33
+ ---
34
+
35
+ # Join
36
+
37
+ **Purpose:** merge N ≥ 2 existing wikis into one.
38
+
39
+ ## Phases
40
+
41
+ 0. **preflight** — Node.js preflight (see SKILL.md). Stop and relay if it fails.
42
+ 1. **ingest-all** — read every source wiki's tree into memory.
43
+ 2. **source-validate** — `node scripts/cli.mjs validate` on each source. Any hard failure halts with "fix this source first."
44
+ 3. **plan-union** — build an in-memory union of categories, entries, overlays, relationships.
45
+ 4. **resolve-id-collisions** — policy:
46
+ - `--id-collision=merge`: if frontmatter compatible, apply MERGE (see `guide/operators.md`); merged entry inherits both ids in `aliases[]` and both source wikis in `source_wikis[]`.
47
+ - `--id-collision=namespace` (default): rename each colliding entry `<source-prefix>.<original-id>`. Record the rename.
48
+ - `--id-collision=ask`: halt, write to HUMAN decisions file.
49
+ 5. **merge-categories** — for top-level categories with matching focus, category-level MERGE.
50
+ 6. **rewire-references** — walk every `links[].id`, `overlay_targets`, `parents[]`; resolve via id → alias → rename map.
51
+ 7. **apply-operators** — full operator-convergence on the unified tree.
52
+ 8. **generate-indices** — `node scripts/cli.mjs index-rebuild` on the joined tree.
53
+ 9. **validation** — hard invariants on the joined tree.
54
+ 10. **golden-path-union** — each source's fixtures must still pass. Regressions halt for user decision.
55
+ 11. **commit** — atomic move into target versioned directory. In hosted mode, both contracts must be compatible (same top-level paths and compatible rules) or a merged contract must be supplied at the join target.
56
+
57
+ ## Source immutability
58
+
59
+ Every source wiki is read-only during the operation and byte-identical afterward. Join never mutates the inputs; it only produces a new unified output.
60
+
61
+ ## Notes
62
+
63
+ - If the user is joining hosted wikis with different contracts, ask them to provide or confirm a merged contract at the target before starting.
64
+ - Always run Validate against each source before Join. Joining a broken source produces a broken joined wiki.
65
+ - The default id-collision policy (`namespace`) is the safest — it never loses any entry, just renames conflicts. `merge` should only be used when the user explicitly confirms the entries are semantically identical.
@@ -0,0 +1,66 @@
1
+ ---
2
+ id: fix
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: Fix operation — repair methodology divergences in an existing wiki
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "three repair classes: AUTO (deterministic), AI-ASSIST (script detects, Claude generates content), HUMAN (user must decide via structured prompt)"
10
+ - "phase pipeline: preflight, intent-check, pre-op snapshot, validate-input, scan, apply-auto, apply-ai-assist, prompt-human, index-rebuild, validation, commit-finalize"
11
+ - Fix enforces contract invariants on top of methodology invariants in hosted mode
12
+ - always report repairs back to the user; never run silently
13
+ tags:
14
+ - operations
15
+ - fix
16
+ - repair
17
+ activation:
18
+ keyword_matches:
19
+ - fix
20
+ - repair
21
+ - divergence
22
+ - reconcile
23
+ tag_matches:
24
+ - operation
25
+ - fixing
26
+ - mutation
27
+ source:
28
+ origin: file
29
+ path: "operations/fix.md"
30
+ hash: "sha256:187ceb962a8fb6f29ab23d3010189bfadf0827e7bc951098a1a4d907bc6fd1e4"
31
+ ---
32
+
33
+ # Fix
34
+
35
+ **Purpose:** repair methodology divergences. Uses the same safety envelope as Build: pre-op snapshot, phase commits, per-op `op/<id>` tag, and the standard validation gate.
36
+
37
+ > **Scope note.** The Fix pipeline in the current orchestrator is a **minimal forward-port**: it runs the phase sequence below and writes AUTO-class repairs, but the rich mode surface described in earlier methodology drafts (`--dry-run`, `--batch`, `--interactive`, `--hard-only`, `--with-soft`, a planned `fix-plan.yaml` artefact) is scoped as **future work** and is not wired through the CLI today. Fix currently accepts only the layout-mode and UX flags documented in `guide/cli.md`; any other flag trips `INT-11`. HUMAN-class divergences currently surface as plain validation errors — a dedicated structured-prompt `INT` code is scoped for the full fix pipeline.
38
+
39
+ ## Repair classes
40
+
41
+ Every invariant from `guide/invariants.md` is tagged with one of:
42
+
43
+ - **AUTO** — script-deterministic repairs: missing `id` that matches filename, stale indices, derivable `parents[]`, broken `links[].id` with alias resolution, parent-file contract violations (extract leaked content to a new leaf), out-of-sync counts, `depth_role` mismatches, missing `aliases[]` after rename cascades.
44
+ - **AI-ASSIST** — script detects, Claude generates the repair content at session time: missing `focus`, missing `covers[]`, `focus` failing the narrowing chain, DECOMPOSE needing semantic partition, source-hash drift needing fresh frontmatter from updated content.
45
+ - **HUMAN** — user must decide: cycles in `parents[]`, colliding ids that are not semantically identical, canonical-parent inconsistencies, orphaned overlay targets, contract violations with no clear repair. These currently surface as plain validation errors; a dedicated structured-prompt `INT` code is scoped for the full fix pipeline.
46
+
47
+ ## Phases
48
+
49
+ 0. **preflight** — Node, git, and wiki-fsck checks.
50
+ 1. **intent-check** — `intent.mjs` resolves the target and surfaces any ambiguity as `INT-NN`.
51
+ 2. **pre-op snapshot** — `git add -A && git commit -m "pre-op <op-id>"`, tag `pre-op/<op-id>`.
52
+ 3. **validate-input** — run the validator and collect all divergences.
53
+ 4. **scan** — categorise each finding into AUTO / AI-ASSIST / HUMAN.
54
+ 5. **apply-auto** — execute deterministic repairs via direct file writes under `mutate()`.
55
+ 6. **apply-ai-assist** — for each AI-ASSIST item, emit a structured request that Claude-at-session-time fulfils with the repair content.
56
+ 7. **prompt-human** — for HUMAN items, surface the finding as a plain validation error (a dedicated structured-prompt `INT` code is future work). The user resolves the upstream cause and re-invokes `fix`, or opts to `rollback` to `pre-op/<op-id>`.
57
+ 8. **index-rebuild** — regenerate affected `index.md` files.
58
+ 9. **validation** — re-run the validator to confirm repairs took effect. Failure triggers rollback to `pre-op/<id>`.
59
+ 10. **commit-finalize** — tag the final commit `op/<op-id>`, append to the op-log.
60
+
61
+ ## Notes
62
+
63
+ - Fix is the primary repair path. Always prefer Fix over direct hand-editing of frontmatter.
64
+ - In hosted mode, Fix enforces both methodology invariants and the contract's `global_invariants` + per-directory `content_rules`.
65
+ - Never run Fix silently — always report every repair you made (and every HUMAN item you couldn't auto-resolve) back to the user.
66
+ - A "golden-path" regression check and a `.shape/history/<op-id>/` audit archive are scoped as future work; they are not part of the current phase pipeline.
@@ -0,0 +1,47 @@
1
+ ---
2
+ id: maintain
3
+ type: index
4
+ depth_role: subcategory
5
+ depth: 2
6
+ focus: Mutating maintenance operations on an existing wiki — repair divergences and optimise structure.
7
+ parents:
8
+ - "../index.md"
9
+ shared_covers: []
10
+ tags:
11
+ - operations
12
+ entries:
13
+ - id: fix
14
+ file: fix.md
15
+ type: primary
16
+ focus: Fix operation — repair methodology divergences in an existing wiki
17
+ tags:
18
+ - operations
19
+ - fix
20
+ - repair
21
+ - id: rebuild
22
+ file: rebuild.md
23
+ type: primary
24
+ focus: Rebuild operation — optimise structure via rewrite operators, produce a rewrite plan then apply
25
+ tags:
26
+ - operations
27
+ - rebuild
28
+ - operators
29
+ children: []
30
+ ---
31
+ <!-- BEGIN AUTO-GENERATED NAVIGATION -->
32
+
33
+ # Maintain
34
+
35
+ **Focus:** Mutating maintenance operations on an existing wiki — repair divergences and optimise structure.
36
+
37
+ ## Children
38
+
39
+ | File | Type | Focus |
40
+ |------|------|-------|
41
+ | [fix.md](fix.md) | 📄 primary | Fix operation — repair methodology divergences in an existing wiki |
42
+ | [rebuild.md](rebuild.md) | 📄 primary | Rebuild operation — optimise structure via rewrite operators, produce a rewrite plan then apply |
43
+
44
+ <!-- END AUTO-GENERATED NAVIGATION -->
45
+
46
+ <!-- BEGIN AUTHORED ORIENTATION -->
47
+ <!-- END AUTHORED ORIENTATION -->
@@ -0,0 +1,86 @@
1
+ ---
2
+ id: rebuild
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: Rebuild operation — optimise structure via rewrite operators, produce a rewrite plan then apply
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "10-phase pipeline including validate-input, check-mode, collect-candidates, dry-run-apply, iterate, golden-path-check, emit-plan, backup (hosted), apply, commit"
10
+ - "always emit the plan first; require user review before `--apply`"
11
+ - operator-convergence is contract-gated in hosted mode
12
+ - "failed apply leaves the previous state intact (pointer unchanged or backup restored)"
13
+ tags:
14
+ - operations
15
+ - rebuild
16
+ - operators
17
+ activation:
18
+ keyword_matches:
19
+ - rebuild
20
+ - optimize
21
+ - optimise
22
+ - restructure
23
+ - rewrite plan
24
+ tag_matches:
25
+ - operation
26
+ - structural-change
27
+ - mutation
28
+ source:
29
+ origin: file
30
+ path: "operations/rebuild.md"
31
+ hash: "sha256:73f42655b30dc02b8f4ef4ab7fde9df11f26db72ae2654072f825f566ed68f50"
32
+ ---
33
+
34
+ # Rebuild
35
+
36
+ **Purpose:** optimise structure via rewrite operators, produce a new version (or in-place updated tree in hosted mode).
37
+
38
+ ## Phases
39
+
40
+ 0. **preflight** — Node.js preflight (see SKILL.md). Stop and relay if it fails.
41
+ 1. **validate-input** — the input wiki must pass hard invariants. If not, tell the user to run Fix first.
42
+ 2. **check-mode** — free vs hosted; load the contract from `guide/layout-contract.md` if present.
43
+ 3. **collect-candidates** — run `node scripts/cli.mjs shape-check <wiki>` and read `<wiki>/.shape/suggestions.md`. Score each candidate against fitness (density + weighted-content).
44
+ 4. **dry-run-apply** — apply operators (see `guide/operators.md`) in priority order on an in-memory projected tree state. In hosted mode, contract-gate every proposed move. After each application, recompute fitness. Accept only if fitness strictly improves or a hard invariant is newly satisfied.
45
+ 5. **iterate** — until no accepted moves.
46
+ 6. **golden-path-check** — if fixtures exist, route each through the projected tree. Roll back any move that causes a regression.
47
+ 7. **emit-plan** — write `<wiki>/.shape/rewrite-plan-<timestamp>.yaml`. Stop here if the user invoked `--plan` (or didn't authorise an apply yet).
48
+ 8. **backup** (hosted + in-place only) — snapshot target to `<backup_dir>/<timestamp>/`.
49
+ 9. **apply** — execute the plan: copy current version to a new version directory (free mode) or apply changes in place (hosted + in-place), rewrite file locations, rebuild indices, re-validate.
50
+ 10. **commit** — flip current-pointer (free) or finalize in-place (hosted). Archive work.
51
+
52
+ ## Notes
53
+
54
+ - Always write the plan first and let the user review before applying. Rebuild is the most structurally-invasive operation — the user should see what's about to move before it moves.
55
+ - Rebuild never silently skips contract rules in hosted mode. If a proposed move violates the contract, it's rejected and the remaining operators still run until convergence within the contract's boundaries.
56
+ - A failed apply leaves the previous state intact (free: previous version still pointed to by current-pointer; hosted: backup restored).
57
+
58
+ ## `--review` — interactive per-iteration review (Phase 7)
59
+
60
+ Pass `--review` on any `rebuild` invocation to pause after operator-
61
+ convergence and walk through the pending operator commits one by
62
+ one. After the convergence phase produces its per-iteration commits
63
+ (and before validation + commit-finalize run), the review flow:
64
+
65
+ 1. Prints `git diff --stat pre-op/<id>..HEAD` so you see the file-
66
+ level summary of what moved.
67
+ 2. Lists every pending iteration commit with its subject line.
68
+ 3. Prompts you to pick one of: **approve**, **abort**, or **drop
69
+ &lt;iteration&gt;**.
70
+
71
+ - **approve** — proceed to validation + commit-finalize as normal.
72
+ - **abort** — `git reset --hard pre-op/<id>` + `git clean -fd`,
73
+ roll the working tree back to its pre-op state, and exit with
74
+ code 2. Nothing lands in the wiki.
75
+ - **drop &lt;N&gt;** — revert the commit for iteration N via
76
+ `git revert --no-edit`, producing an inverse commit. Iteration
77
+ N's move is undone but the other iterations survive. Re-prompts
78
+ so you can drop more iterations one at a time.
79
+
80
+ In non-interactive mode (CI, hooks, `--no-prompt`, or stdin not a
81
+ TTY), `--review` is a silent pass-through — the orchestrator
82
+ proceeds as if the flag hadn't been passed.
83
+
84
+ `--review` only pauses when convergence actually produced at
85
+ least one commit. An op that triggered zero operators auto-
86
+ approves without prompting.
@@ -0,0 +1,48 @@
1
+ ---
2
+ id: validate
3
+ type: primary
4
+ depth_role: leaf
5
+ focus: Validate operation — read-only correctness check against a wiki
6
+ parents:
7
+ - index.md
8
+ covers:
9
+ - "invokes `node scripts/cli.mjs validate <wiki>` and reports every finding verbatim"
10
+ - "exit codes: 0 clean, 2 errors; warnings do not change exit code"
11
+ - does not auto-fix; if repairs are wanted the user must explicitly invoke Fix
12
+ - lowest-risk operation, always run before structural changes
13
+ tags:
14
+ - operations
15
+ - validate
16
+ - read-only
17
+ activation:
18
+ keyword_matches:
19
+ - validate
20
+ - check wiki
21
+ - verify wiki
22
+ - correctness
23
+ tag_matches:
24
+ - operation
25
+ - validating
26
+ source:
27
+ origin: file
28
+ path: "operations/validate.md"
29
+ hash: "sha256:8b710cbe390c57c46a4bcc5fea6d3df886b9d9ba6352f365fd05dacdb1e094b1"
30
+ ---
31
+
32
+
33
+ # Validate
34
+
35
+ **Purpose:** read-only correctness check against a wiki.
36
+
37
+ ## Phases
38
+
39
+ 0. **preflight** — Node.js preflight (see SKILL.md). Stop and relay if it fails.
40
+ 1. **run validator** — `node scripts/cli.mjs validate <wiki>`.
41
+ 2. **interpret findings** — parse the stdout report; each finding has a code (e.g. `PARENTS-REQUIRED`, `ID-MISMATCH-FILE`, `DUP-ID`), a severity tag, and the affected path.
42
+ 3. **report to user** — surface every finding verbatim with its code and path. In hosted mode, note contract invariants separately so the user sees which layer is failing.
43
+
44
+ ## Notes
45
+
46
+ - Do not auto-fix anything. If the user wants repairs, they explicitly invoke Fix — see `guide/operations/fix.md`.
47
+ - The validator exits 0 on clean, 2 on errors. Warnings are printed but don't affect exit code.
48
+ - Validate is the lowest-risk operation you can run against any existing wiki — always run it before structural changes.
@@ -0,0 +1,47 @@
1
+ ---
2
+ id: substrate
3
+ type: index
4
+ depth_role: subcategory
5
+ depth: 1
6
+ focus: Decision machinery — rewrite operators and the tiered AI ladder driving them.
7
+ parents:
8
+ - "../index.md"
9
+ shared_covers: []
10
+ tags:
11
+ - operators
12
+ entries:
13
+ - id: operators
14
+ file: operators.md
15
+ type: primary
16
+ focus: the four rewrite operators that shape wiki trees toward a token-minimal normal form
17
+ tags:
18
+ - operators
19
+ - rebuild
20
+ - normal-form
21
+ - id: tiered-ai
22
+ file: tiered-ai.md
23
+ type: primary
24
+ focus: tiered AI ladder — TF-IDF → local embeddings → Claude — with quality modes
25
+ tags:
26
+ - ai-strategy
27
+ - operators
28
+ - similarity
29
+ children: []
30
+ ---
31
+ <!-- BEGIN AUTO-GENERATED NAVIGATION -->
32
+
33
+ # Substrate
34
+
35
+ **Focus:** Decision machinery — rewrite operators and the tiered AI ladder driving them.
36
+
37
+ ## Children
38
+
39
+ | File | Type | Focus |
40
+ |------|------|-------|
41
+ | [operators.md](operators.md) | 📄 primary | the four rewrite operators that shape wiki trees toward a token-minimal normal form |
42
+ | [tiered-ai.md](tiered-ai.md) | 📄 primary | tiered AI ladder — TF-IDF → local embeddings → Claude — with quality modes |
43
+
44
+ <!-- END AUTO-GENERATED NAVIGATION -->
45
+
46
+ <!-- BEGIN AUTHORED ORIENTATION -->
47
+ <!-- END AUTHORED ORIENTATION -->