@cr8rcho/alkahest 0.1.89 → 0.1.91

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 (37) hide show
  1. package/README.md +1 -0
  2. package/dist/cli.js +10 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/presets.d.ts +13 -0
  5. package/dist/commands/presets.js +68 -1
  6. package/dist/commands/presets.js.map +1 -1
  7. package/dist/commands/update.js +16 -0
  8. package/dist/commands/update.js.map +1 -1
  9. package/dist/core/presetUpdate.d.ts +65 -0
  10. package/dist/core/presetUpdate.js +289 -0
  11. package/dist/core/presetUpdate.js.map +1 -0
  12. package/dist/core/presets.d.ts +33 -0
  13. package/dist/core/presets.js +3 -3
  14. package/dist/core/presets.js.map +1 -1
  15. package/dist/mcp/server.js +7 -1
  16. package/dist/mcp/server.js.map +1 -1
  17. package/package.json +4 -2
  18. package/presets/as-built/CHANGES.md +28 -0
  19. package/presets/as-built/CLAUDE-snippet.md +2 -1
  20. package/presets/as-built/history/0fe9dc4fc94d413f +71 -0
  21. package/presets/as-built/history/32be1c85c4b2757d +124 -0
  22. package/presets/as-built/history/5a9ef521edb13aa1 +71 -0
  23. package/presets/as-built/history/6e0b36b4d353b6b6 +72 -0
  24. package/presets/as-built/history/87497464ab8cfa7d +72 -0
  25. package/presets/as-built/history/8a9e3845f322e51c +56 -0
  26. package/presets/as-built/history/8e8f6eebcb4b2a58 +24 -0
  27. package/presets/as-built/history/96497831c905de56 +25 -0
  28. package/presets/as-built/history/bd84de1dd9759c12 +65 -0
  29. package/presets/as-built/history/ed625ebd1209c061 +24 -0
  30. package/presets/as-built/history/f431a6fcf54a4906 +123 -0
  31. package/presets/as-built/history.json +56 -0
  32. package/presets/as-built/sync-docs-maps.mjs +4 -3
  33. package/presets/llm-wiki/CHANGES.md +8 -0
  34. package/presets/llm-wiki/history/44e1874c74476cd7 +57 -0
  35. package/presets/llm-wiki/history/59cf7b5051fce7e3 +93 -0
  36. package/presets/llm-wiki/history/b5f313af919c6236 +69 -0
  37. package/presets/llm-wiki/history.json +22 -0
@@ -0,0 +1,71 @@
1
+ # as-built-docs — writing instructions
2
+
3
+ You are maintaining this repository's **as-built documentation**: documents that record how
4
+ the system **is actually built**. Never plans, PRDs, or aspirations — present tense, code as
5
+ the source of truth.
6
+
7
+ ## The four layers
8
+
9
+ Documents live under `docs/` in four folders, split by scope and viewpoint:
10
+
11
+ | Layer | Scope | Viewpoint | Answers |
12
+ |---|---|---|---|
13
+ | `system/` | whole app | architecture / data flow | "How is this app put together overall?" |
14
+ | `components/` | one UI area | what the user sees | "What is on this screen area, and what does each control do?" |
15
+ | `features/` | one behavior | time / user action | "When and under what conditions does this behavior run?" |
16
+ | `modules/` | one code layer | developer view | "What does this layer provide, and how is it separated from the rest?" |
17
+
18
+ Placement rule of thumb: what the user *sees* → `components/`; what *happens over time* →
19
+ `features/`; *code structure* → `modules/`; the picture that crosses all three → `system/`.
20
+ When a topic straddles two layers, pick one as the **main** document and leave a short
21
+ summary + link in the other.
22
+
23
+ ## Document shape
24
+
25
+ Title each document with a **classed H1**: `# System — <name>`, `# Component — <name>`,
26
+ `# Feature — <name>`, `# Module — <name>`. The note-map mirror strips the class prefix,
27
+ so the hosted note is titled just `<name>` while the file stays unambiguous in the repo.
28
+ (ADRs have their own H1 shape — see the `adr` skill.)
29
+
30
+ ## Bootstrap — when the repo has no docs yet
31
+
32
+ Do NOT try to document everything in one session. The first pass is deliberately small so
33
+ the user sees a map fast:
34
+
35
+ 1. `docs/system/<app>.md` — one system map: layers, data flow, key dependencies, honest
36
+ Known Limitations.
37
+ 2. Two or three `docs/modules/*.md` for the load-bearing modules only.
38
+ 3. One decision record (see the `adr` skill): **ADR-001, an architecture snapshot** — the
39
+ decisions already embedded in the current code.
40
+ 4. Add each document to the index in `docs/README.md`, then **mirror to the note maps and
41
+ hand the user the map link** (the mirroring rule lives in this repo's CLAUDE.md).
42
+
43
+ In the first pass, **prefer `modules/`** (plus the one `system/` map) when a topic could
44
+ fit several layers — grow `features/` and `components/` in later sessions, and leave their
45
+ index tables empty until they have documents.
46
+
47
+ Grow the rest incrementally: each later work session adds or updates only the documents its
48
+ code changes touch.
49
+
50
+ ## Tone and rules
51
+
52
+ - **As-built, present tense** — "this is how it is built." Cite real file paths, function
53
+ names, and constants so readers can jump straight to code.
54
+ - **Decision history is a separate axis** — why / alternatives / trade-offs belong in ADRs
55
+ (`docs/decisions/`, see the `adr` skill), not in these documents.
56
+ - **Known Limitations, honestly** — the most valuable section of a post-hoc document.
57
+ Remove limitations you fixed; add the ones you introduced.
58
+ - **Overwrite freely** — these documents always describe the present. (ADRs are the
59
+ append-only record; never blend the two.)
60
+ - **Trust the code over connected tools** — an MCP server configured in your session
61
+ (a database MCP, for instance) may be bound to a *different* project than the repo you
62
+ are documenting. Verify the binding before citing anything from it, or read the schema
63
+ from the code instead.
64
+
65
+ ## After every code change (checklist)
66
+
67
+ - [ ] Does the affected document still describe current behavior?
68
+ - [ ] Are its code citations (paths, names, constants) still valid?
69
+ - [ ] Known Limitations updated — fixed ones removed, new ones added?
70
+ - [ ] Cross-references from documents in other layers updated?
71
+ - [ ] `docs/README.md` index still accurate (add a row when adding a document)?
@@ -0,0 +1,72 @@
1
+ # adr — decision records
2
+
3
+ ADRs (`docs/decisions/NNN-kebab-title.md`) record the **why** of decisions: context,
4
+ alternatives, trade-offs. They are a separate axis from as-built docs — as-built documents
5
+ are overwritten to stay current; ADRs are **append-only**, frozen at decision time.
6
+
7
+ ## When to write one
8
+
9
+ One-line test: **if the code diff alone cannot reconstruct the "why", it deserves an ADR.**
10
+
11
+ Typical cases: data-model or structural changes; policy decisions and their reversals;
12
+ adopting an external dependency or license; fixing an ownership boundary ("this module is
13
+ the single owner of that transform"); behavior changes that trade something away; and
14
+ decisions deliberately **not** taken (record the reason and the revisit trigger).
15
+
16
+ Skip when: plain bug fixes, refactors, dependency bumps — anything self-evident from the
17
+ code and the as-built docs.
18
+
19
+ ## Bootstrap — ADR-001
20
+
21
+ On a repo's first documentation pass, write **ADR-001 as an architecture snapshot**: the
22
+ decisions already embedded in the current code (framework, storage, module boundaries),
23
+ each with the alternatives it implicitly rejected. This seeds the habit of communicating
24
+ through decision records.
25
+
26
+ ## Numbering & lifecycle
27
+
28
+ - `NNN` is zero-padded, sequential, never reused or renumbered.
29
+ - Never rewrite an accepted ADR. When a decision changes, write a **new** ADR that names
30
+ the old one in `Supersedes:`, and flip the old one's Status to `Superseded by …`
31
+ (keep the body — "why we did it that way once, then backed out" is the value).
32
+
33
+ ## Tags (frontmatter)
34
+
35
+ Every ADR opens with a `tags:` frontmatter block. Keep the vocabulary small and stable:
36
+ one **surface** tag (the area of the product it touches) plus at most two **arc** tags
37
+ (a storyline several ADRs share). On the hosted `adr` note map each tag renders as a hub
38
+ node — keep every tag attached to roughly 3–12 ADRs so the map stays legible, and prefer
39
+ reusing an existing tag over inventing a new one.
40
+
41
+ **The vocabulary lives in `docs/decisions/README.md`'s tag table, and the repo owns it.**
42
+ On the bootstrap pass, seed it: derive 3–7 surface tags from the codebase's *actual* areas
43
+ (the folders/verticals you just documented), record them in the table, and tag ADR-001 from
44
+ that set. Afterwards, every ADR picks from the table; a genuinely new tag means adding its
45
+ row in the same commit. Arc tags are not invented up front — they emerge when several ADRs
46
+ turn out to share a storyline.
47
+
48
+ ## Template
49
+
50
+ ```markdown
51
+ ---
52
+ tags: [<one surface tag>, <0-2 arc tags>]
53
+ ---
54
+
55
+ # ADR-NNN: <one-line title>
56
+
57
+ * **Status**: Accepted (YYYY-MM-DD)
58
+ * **Date**: YYYY-MM-DD
59
+ * **Supersedes**: none | ADR-NNN (partial/full)
60
+ * **Related**: ADRs, as-built docs
61
+
62
+ ***
63
+
64
+ ## 1. Context
65
+ ## 2. Decision
66
+ ## 3. Trade-offs
67
+ ## 4. Considered alternatives
68
+ ## 5. Known limitations
69
+ ```
70
+
71
+ Keep *Trade-offs*, *Considered alternatives*, and *Known limitations* non-empty — they are
72
+ the point of the record. Cite code richly (files, functions, constants).
@@ -0,0 +1,72 @@
1
+ # alkahest/adr — decision records
2
+
3
+ ADRs (`docs/decisions/NNN-kebab-title.md`) record the **why** of decisions: context,
4
+ alternatives, trade-offs. They are a separate axis from as-built docs — as-built documents
5
+ are overwritten to stay current; ADRs are **append-only**, frozen at decision time.
6
+
7
+ ## When to write one
8
+
9
+ One-line test: **if the code diff alone cannot reconstruct the "why", it deserves an ADR.**
10
+
11
+ Typical cases: data-model or structural changes; policy decisions and their reversals;
12
+ adopting an external dependency or license; fixing an ownership boundary ("this module is
13
+ the single owner of that transform"); behavior changes that trade something away; and
14
+ decisions deliberately **not** taken (record the reason and the revisit trigger).
15
+
16
+ Skip when: plain bug fixes, refactors, dependency bumps — anything self-evident from the
17
+ code and the as-built docs.
18
+
19
+ ## Bootstrap — ADR-001
20
+
21
+ On a repo's first documentation pass, write **ADR-001 as an architecture snapshot**: the
22
+ decisions already embedded in the current code (framework, storage, module boundaries),
23
+ each with the alternatives it implicitly rejected. This seeds the habit of communicating
24
+ through decision records.
25
+
26
+ ## Numbering & lifecycle
27
+
28
+ - `NNN` is zero-padded, sequential, never reused or renumbered.
29
+ - Never rewrite an accepted ADR. When a decision changes, write a **new** ADR that names
30
+ the old one in `Supersedes:`, and flip the old one's Status to `Superseded by …`
31
+ (keep the body — "why we did it that way once, then backed out" is the value).
32
+
33
+ ## Tags (frontmatter)
34
+
35
+ Every ADR opens with a `tags:` frontmatter block. Keep the vocabulary small and stable:
36
+ one **surface** tag (the area of the product it touches) plus at most two **arc** tags
37
+ (a storyline several ADRs share). On the hosted `adr` note map each tag renders as a hub
38
+ node — keep every tag attached to roughly 3–12 ADRs so the map stays legible, and prefer
39
+ reusing an existing tag over inventing a new one.
40
+
41
+ **The vocabulary lives in `docs/decisions/README.md`'s tag table, and the repo owns it.**
42
+ On the bootstrap pass, seed it: derive 3–7 surface tags from the codebase's *actual* areas
43
+ (the folders/verticals you just documented), record them in the table, and tag ADR-001 from
44
+ that set. Afterwards, every ADR picks from the table; a genuinely new tag means adding its
45
+ row in the same commit. Arc tags are not invented up front — they emerge when several ADRs
46
+ turn out to share a storyline.
47
+
48
+ ## Template
49
+
50
+ ```markdown
51
+ ---
52
+ tags: [<one surface tag>, <0-2 arc tags>]
53
+ ---
54
+
55
+ # ADR-NNN: <one-line title>
56
+
57
+ * **Status**: Accepted (YYYY-MM-DD)
58
+ * **Date**: YYYY-MM-DD
59
+ * **Supersedes**: none | ADR-NNN (partial/full)
60
+ * **Related**: ADRs, as-built docs
61
+
62
+ ***
63
+
64
+ ## 1. Context
65
+ ## 2. Decision
66
+ ## 3. Trade-offs
67
+ ## 4. Considered alternatives
68
+ ## 5. Known limitations
69
+ ```
70
+
71
+ Keep *Trade-offs*, *Considered alternatives*, and *Known limitations* non-empty — they are
72
+ the point of the record. Cite code richly (files, functions, constants).
@@ -0,0 +1,56 @@
1
+ # as-built-docs — writing instructions
2
+
3
+ You are maintaining this repository's **as-built documentation**: documents that record how
4
+ the system **is actually built**. Never plans, PRDs, or aspirations — present tense, code as
5
+ the source of truth.
6
+
7
+ ## The four layers
8
+
9
+ Documents live under `docs/` in four folders, split by scope and viewpoint:
10
+
11
+ | Layer | Scope | Viewpoint | Answers |
12
+ |---|---|---|---|
13
+ | `system/` | whole app | architecture / data flow | "How is this app put together overall?" |
14
+ | `components/` | one UI area | what the user sees | "What is on this screen area, and what does each control do?" |
15
+ | `features/` | one behavior | time / user action | "When and under what conditions does this behavior run?" |
16
+ | `modules/` | one code layer | developer view | "What does this layer provide, and how is it separated from the rest?" |
17
+
18
+ Placement rule of thumb: what the user *sees* → `components/`; what *happens over time* →
19
+ `features/`; *code structure* → `modules/`; the picture that crosses all three → `system/`.
20
+ When a topic straddles two layers, pick one as the **main** document and leave a short
21
+ summary + link in the other.
22
+
23
+ ## Bootstrap — when the repo has no docs yet
24
+
25
+ Do NOT try to document everything in one session. The first pass is deliberately small so
26
+ the user sees a map fast:
27
+
28
+ 1. `docs/system/<app>.md` — one system map: layers, data flow, key dependencies, honest
29
+ Known Limitations.
30
+ 2. Two or three `docs/modules/*.md` for the load-bearing modules only.
31
+ 3. One decision record (see the `adr` skill): **ADR-001, an architecture snapshot** — the
32
+ decisions already embedded in the current code.
33
+ 4. Add each document to the index in `docs/README.md`, then **mirror to the note maps and
34
+ hand the user the map link** (the mirroring rule lives in this repo's CLAUDE.md).
35
+
36
+ Grow the rest incrementally: each later work session adds or updates only the documents its
37
+ code changes touch.
38
+
39
+ ## Tone and rules
40
+
41
+ - **As-built, present tense** — "this is how it is built." Cite real file paths, function
42
+ names, and constants so readers can jump straight to code.
43
+ - **Decision history is a separate axis** — why / alternatives / trade-offs belong in ADRs
44
+ (`docs/decisions/`, see the `adr` skill), not in these documents.
45
+ - **Known Limitations, honestly** — the most valuable section of a post-hoc document.
46
+ Remove limitations you fixed; add the ones you introduced.
47
+ - **Overwrite freely** — these documents always describe the present. (ADRs are the
48
+ append-only record; never blend the two.)
49
+
50
+ ## After every code change (checklist)
51
+
52
+ - [ ] Does the affected document still describe current behavior?
53
+ - [ ] Are its code citations (paths, names, constants) still valid?
54
+ - [ ] Known Limitations updated — fixed ones removed, new ones added?
55
+ - [ ] Cross-references from documents in other layers updated?
56
+ - [ ] `docs/README.md` index still accurate (add a row when adding a document)?
@@ -0,0 +1,24 @@
1
+ <!-- alkahest as-built preset — installed by `alkahest docs init`. Owned by this repo: edit freely. -->
2
+ ## Documentation — as-built docs + ADR
3
+
4
+ This repo keeps **as-built documentation** under `docs/` (four layers: system / components /
5
+ features / modules — see docs/README.md) and **ADRs** under `docs/decisions/`. The writing
6
+ instructions live in the account skills `as-built-docs` and `adr` — read them via the
7
+ alkahest MCP `skills` tool before writing docs.
8
+
9
+ 1. **After finishing any code change, update the affected docs in the same session.**
10
+ The layer mapping and the update checklist are in the `as-built-docs` skill. Write an
11
+ ADR only for decisions whose "why" a code diff cannot reconstruct (criteria and the
12
+ template are in the `adr` skill).
13
+ 2. **First documentation pass (repo has no docs yet)?** Follow the bootstrap protocol in
14
+ the `as-built-docs` skill: one system map + 2–3 core modules + ADR-001 (architecture
15
+ snapshot) — small first, then mirror and hand the user the note-map link. Grow the rest
16
+ incrementally with later work.
17
+ 3. **After changing `docs/`, mirror it to the hosted note maps** by running
18
+ `node scripts/sync-docs-maps.mjs` (background recommended — one POST per document).
19
+ The script stages the docs (title from the first H1, H1 line stripped, intra-set
20
+ relative links → `[[wikilinks]]`, the original repo path injected as `source_path:`
21
+ frontmatter) and uploads with `alkahest notes import --map <adr|as-built>`. The import
22
+ is idempotent by source_path first, title second — re-runs and retitles update notes in
23
+ place. The script is a reference implementation and belongs to this repo: adapt it to
24
+ local conventions freely.
@@ -0,0 +1,25 @@
1
+ <!-- alkahest as-built preset — installed by `alkahest preset install as-built`. Owned by this repo: edit freely; `alkahest preset update` merges later preset changes into your edits. -->
2
+ ## Documentation — as-built docs + ADR
3
+
4
+ This repo keeps **as-built documentation** under `docs/` (four layers: system / components /
5
+ features / modules — see docs/README.md) and **ADRs** under `docs/decisions/`. The writing
6
+ instructions live in the account skills `alkahest/as-built-docs` and `alkahest/adr` — read them via the
7
+ alkahest MCP `skills` tool before writing docs.
8
+
9
+ 1. **After finishing any code change, update the affected docs in the same session.**
10
+ The layer mapping and the update checklist are in the `alkahest/as-built-docs` skill. Write an
11
+ ADR only for decisions whose "why" a code diff cannot reconstruct (criteria and the
12
+ template are in the `alkahest/adr` skill).
13
+ 2. **First documentation pass (repo has no docs yet)?** Follow the bootstrap protocol in
14
+ the `alkahest/as-built-docs` skill: one system map + 2–3 core modules + ADR-001 (architecture
15
+ snapshot) — small first, then mirror and hand the user the note-map link. Grow the rest
16
+ incrementally with later work.
17
+ 3. **After changing `docs/`, mirror it to the hosted note maps** by running
18
+ `node scripts/sync-docs-maps.mjs` (background recommended — one POST per document).
19
+ The script stages the docs (title from the first H1, H1 line stripped, intra-set
20
+ relative links → `[[wikilinks]]`, the original repo path injected as `source_path:`
21
+ frontmatter) and uploads with `alkahest notes import --map <adr|as-built>`. The import
22
+ is idempotent by source_path first, title second — re-runs and retitles update notes in
23
+ place. The script is a reference implementation and belongs to this repo: adapt it to
24
+ local conventions freely.
25
+ <!-- /alkahest as-built preset -->
@@ -0,0 +1,65 @@
1
+ # adr — decision records
2
+
3
+ ADRs (`docs/decisions/NNN-kebab-title.md`) record the **why** of decisions: context,
4
+ alternatives, trade-offs. They are a separate axis from as-built docs — as-built documents
5
+ are overwritten to stay current; ADRs are **append-only**, frozen at decision time.
6
+
7
+ ## When to write one
8
+
9
+ One-line test: **if the code diff alone cannot reconstruct the "why", it deserves an ADR.**
10
+
11
+ Typical cases: data-model or structural changes; policy decisions and their reversals;
12
+ adopting an external dependency or license; fixing an ownership boundary ("this module is
13
+ the single owner of that transform"); behavior changes that trade something away; and
14
+ decisions deliberately **not** taken (record the reason and the revisit trigger).
15
+
16
+ Skip when: plain bug fixes, refactors, dependency bumps — anything self-evident from the
17
+ code and the as-built docs.
18
+
19
+ ## Bootstrap — ADR-001
20
+
21
+ On a repo's first documentation pass, write **ADR-001 as an architecture snapshot**: the
22
+ decisions already embedded in the current code (framework, storage, module boundaries),
23
+ each with the alternatives it implicitly rejected. This seeds the habit of communicating
24
+ through decision records.
25
+
26
+ ## Numbering & lifecycle
27
+
28
+ - `NNN` is zero-padded, sequential, never reused or renumbered.
29
+ - Never rewrite an accepted ADR. When a decision changes, write a **new** ADR that names
30
+ the old one in `Supersedes:`, and flip the old one's Status to `Superseded by …`
31
+ (keep the body — "why we did it that way once, then backed out" is the value).
32
+
33
+ ## Tags (frontmatter)
34
+
35
+ Every ADR opens with a `tags:` frontmatter block. Keep the vocabulary small and stable:
36
+ one **surface** tag (the area of the product it touches) plus at most two **arc** tags
37
+ (a storyline several ADRs share). On the hosted `adr` note map each tag renders as a hub
38
+ node — keep every tag attached to roughly 3–12 ADRs so the map stays legible, and prefer
39
+ reusing an existing tag over inventing a new one.
40
+
41
+ ## Template
42
+
43
+ ```markdown
44
+ ---
45
+ tags: [<one surface tag>, <0-2 arc tags>]
46
+ ---
47
+
48
+ # ADR-NNN: <one-line title>
49
+
50
+ * **Status**: Accepted (YYYY-MM-DD)
51
+ * **Date**: YYYY-MM-DD
52
+ * **Supersedes**: none | ADR-NNN (partial/full)
53
+ * **Related**: ADRs, as-built docs
54
+
55
+ ***
56
+
57
+ ## 1. Context
58
+ ## 2. Decision
59
+ ## 3. Trade-offs
60
+ ## 4. Considered alternatives
61
+ ## 5. Known limitations
62
+ ```
63
+
64
+ Keep *Trade-offs*, *Considered alternatives*, and *Known limitations* non-empty — they are
65
+ the point of the record. Cite code richly (files, functions, constants).
@@ -0,0 +1,24 @@
1
+ <!-- alkahest as-built preset — installed by `alkahest docs init`. Owned by this repo: edit freely. -->
2
+ ## Documentation — as-built docs + ADR
3
+
4
+ This repo keeps **as-built documentation** under `docs/` (four layers: system / components /
5
+ features / modules — see docs/README.md) and **ADRs** under `docs/decisions/`. The writing
6
+ instructions live in the account skills `alkahest/as-built-docs` and `alkahest/adr` — read them via the
7
+ alkahest MCP `skills` tool before writing docs.
8
+
9
+ 1. **After finishing any code change, update the affected docs in the same session.**
10
+ The layer mapping and the update checklist are in the `alkahest/as-built-docs` skill. Write an
11
+ ADR only for decisions whose "why" a code diff cannot reconstruct (criteria and the
12
+ template are in the `alkahest/adr` skill).
13
+ 2. **First documentation pass (repo has no docs yet)?** Follow the bootstrap protocol in
14
+ the `alkahest/as-built-docs` skill: one system map + 2–3 core modules + ADR-001 (architecture
15
+ snapshot) — small first, then mirror and hand the user the note-map link. Grow the rest
16
+ incrementally with later work.
17
+ 3. **After changing `docs/`, mirror it to the hosted note maps** by running
18
+ `node scripts/sync-docs-maps.mjs` (background recommended — one POST per document).
19
+ The script stages the docs (title from the first H1, H1 line stripped, intra-set
20
+ relative links → `[[wikilinks]]`, the original repo path injected as `source_path:`
21
+ frontmatter) and uploads with `alkahest notes import --map <adr|as-built>`. The import
22
+ is idempotent by source_path first, title second — re-runs and retitles update notes in
23
+ place. The script is a reference implementation and belongs to this repo: adapt it to
24
+ local conventions freely.
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ // Reference implementation (alkahest as-built preset) — mirror this repo's docs into the
3
+ // project's note maps:
4
+ // docs/decisions/NNN-*.md → note map `adr` (flat)
5
+ // docs/{system,components,features,modules}/*.md → note map `as-built` (folder = category)
6
+ //
7
+ // Staging transforms (the importer's rules: filename = title, frontmatter passes through):
8
+ // - title from the first H1 ("ADR-NNN: rest — tail" → "ADR-NNN rest"; as-built strips a
9
+ // "System|Component|Feature|Module — " class prefix and a " — " tail), sanitized;
10
+ // - the H1 line is dropped from the body (the note title renders it);
11
+ // - relative .md links WITHIN each set become [[wikilinks]] so the graph connects
12
+ // (cross-set links stay plain markdown);
13
+ // - the ORIGINAL repo path rides in as `source_path:` frontmatter — the staged filename
14
+ // is title-derived, so this is what keeps identity through a retitle (the importer
15
+ // matches source_path before title and renames the note in place).
16
+ //
17
+ // Re-running is safe: import is idempotent by source_path, then title.
18
+ // This script belongs to the repo it lives in — adapt titles/sets/maps to local conventions.
19
+ // Usage: node scripts/sync-docs-maps.mjs [--stage-only]
20
+ import { readdirSync, readFileSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
21
+ import { spawnSync } from "node:child_process";
22
+ import { join, dirname, basename } from "node:path";
23
+ import { fileURLToPath } from "node:url";
24
+ import { tmpdir } from "node:os";
25
+
26
+ const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
27
+ const DOCS = join(ROOT, "docs");
28
+ const OUT = join(tmpdir(), "alkahest-docs-staging");
29
+ rmSync(OUT, { recursive: true, force: true });
30
+
31
+ const sanitize = (t) =>
32
+ t.replace(/\(\//g, "(").replace(/[/\\:]/g, "-").replace(/`/g, "").replace(/\s+/g, " ").trim();
33
+ const firstH1 = (src) => (src.match(/^#\s+(.+)$/m) ?? [null, ""])[1].trim();
34
+ // Frontmatter rides through to the staged file — the importer strips it from the stored body
35
+ // and harvests its keys into note props (`tags:` is the reserved one). Split it off first so
36
+ // stripH1 still sees the H1 at the head of what's left.
37
+ const splitFm = (src) => {
38
+ const m = src.match(/^---\r?\n[\s\S]*?\r?\n---\r?\n+/);
39
+ return m ? [m[0], src.slice(m[0].length)] : ["", src];
40
+ };
41
+ const stripH1 = (src) => {
42
+ const [fm, body] = splitFm(src);
43
+ return fm + body.replace(/^#\s+.+\n+/, "");
44
+ };
45
+ // Rename-safe identity: inject the ORIGINAL repo path as source_path: frontmatter (merged
46
+ // into an existing block, or a new block is minted).
47
+ const withSource = (staged, rel) => {
48
+ const [fm, body] = splitFm(staged);
49
+ const line = `source_path: ${rel}\n`;
50
+ return fm ? fm.replace(/---\r?\n*$/, (close) => line + close) + body : `---\n${line}---\n\n${staged}`;
51
+ };
52
+
53
+ // ---- ADRs ------------------------------------------------------------------
54
+ const adrDir = join(DOCS, "decisions");
55
+ const adrFiles = readdirSync(adrDir).filter((f) => /^\d{3}-.*\.md$/.test(f));
56
+ const adrTitle = {};
57
+ for (const f of adrFiles) {
58
+ const h1 = firstH1(readFileSync(join(adrDir, f), "utf8"));
59
+ // Convention "ADR-NNN: title — tail"; the em-dash variant "ADR-NNN — title" also parses.
60
+ const m = h1.match(/^ADR-(\d{3})(?::|\s+—)\s*(.+)$/);
61
+ const num = m ? m[1] : f.slice(0, 3);
62
+ adrTitle[num] = sanitize(`ADR-${num} ${(m ? m[2] : h1).split(" — ")[0].trim()}`);
63
+ }
64
+ const linkAdrs = (body) =>
65
+ body.replace(/\[([^\]]*)\]\((?:\.\/)?(\d{3})-[^)#\s]*\.md(?:#[^)]*)?\)/g, (all, _label, num) =>
66
+ adrTitle[num] ? `[[${adrTitle[num]}]]` : all);
67
+ mkdirSync(join(OUT, "adr"), { recursive: true });
68
+ for (const f of adrFiles) {
69
+ const t = adrTitle[f.slice(0, 3)];
70
+ const staged = linkAdrs(stripH1(readFileSync(join(adrDir, f), "utf8")));
71
+ writeFileSync(join(OUT, "adr", `${t}.md`), withSource(staged, `docs/decisions/${f}`));
72
+ }
73
+
74
+ // ---- as-built --------------------------------------------------------------
75
+ const cats = ["system", "components", "features", "modules"];
76
+ const abTitle = {};
77
+ const abSrc = {};
78
+ for (const cat of cats) {
79
+ for (const f of readdirSync(join(DOCS, cat)).filter((x) => x.endsWith(".md"))) {
80
+ const src = readFileSync(join(DOCS, cat, f), "utf8");
81
+ let t = firstH1(src).replace(/^(System|Component|Feature|Module)\s*—\s*/i, "");
82
+ t = t.split(" — ")[0].trim() || firstH1(src);
83
+ abTitle[basename(f, ".md")] = sanitize(t);
84
+ abSrc[basename(f, ".md")] = { cat, src };
85
+ }
86
+ }
87
+ const linkAb = (body) =>
88
+ body.replace(/\[([^\]]*)\]\((?:\.\.\/(?:system|components|features|modules)\/|\.\/)?([a-z0-9-]+)\.md(?:#[^)]*)?\)/g,
89
+ (all, _label, name) => (abTitle[name] ? `[[${abTitle[name]}]]` : all));
90
+ for (const [name, { cat, src }] of Object.entries(abSrc)) {
91
+ mkdirSync(join(OUT, "as-built", cat), { recursive: true });
92
+ writeFileSync(join(OUT, "as-built", cat, `${abTitle[name]}.md`), withSource(linkAb(stripH1(src)), `docs/${cat}/${name}.md`));
93
+ }
94
+
95
+ console.log(`staged ${adrFiles.length} ADRs + ${Object.keys(abSrc).length} as-built docs → ${OUT}`);
96
+ if (process.argv.includes("--stage-only")) process.exit(0);
97
+
98
+ // A full mirror is many sequential POSTs, so a transient failure is a question of when, not
99
+ // if. The CLI handles it per file (keeps going, prints `✗ <file>: <message>`, exits 1) — act
100
+ // on the exit code and retry the whole set: rows that already landed come back as updates.
101
+ const ATTEMPTS = 3;
102
+ const failed = [];
103
+
104
+ for (const [dir, map] of [["adr", "adr"], ["as-built", "as-built"]]) {
105
+ let ok = false;
106
+ for (let attempt = 1; attempt <= ATTEMPTS && !ok; attempt++) {
107
+ console.log(`\n== notes import ${dir} → map ${map}${attempt > 1 ? ` (retry ${attempt - 1})` : ""} ==`);
108
+ const run = spawnSync("alkahest", ["notes", "import", join(OUT, dir), "--map", map, "--path", ROOT], {
109
+ stdio: "inherit",
110
+ });
111
+ if (run.error) console.error(`[sync] could not run alkahest: ${run.error.message}`);
112
+ ok = !run.error && run.status === 0;
113
+ if (!ok && attempt < ATTEMPTS) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 5000);
114
+ }
115
+ if (!ok) failed.push(`${dir} → ${map}`);
116
+ }
117
+
118
+ if (failed.length) {
119
+ console.error(`\n[sync] FAILED after ${ATTEMPTS} attempts: ${failed.join(", ")}`);
120
+ console.error("[sync] scroll up for the per-file '✗ <file>: <message>' lines from the importer.");
121
+ process.exit(1);
122
+ }
123
+ console.log("\n[sync] both maps up to date.");
@@ -0,0 +1,56 @@
1
+ {
2
+ "files": {
3
+ "skills/as-built-docs.md": [
4
+ {
5
+ "sha": "8a9e3845f322e51c",
6
+ "since": "0.1.72"
7
+ },
8
+ {
9
+ "sha": "5a9ef521edb13aa1",
10
+ "since": "0.1.74"
11
+ },
12
+ {
13
+ "sha": "0fe9dc4fc94d413f",
14
+ "since": "0.1.76"
15
+ }
16
+ ],
17
+ "skills/adr.md": [
18
+ {
19
+ "sha": "bd84de1dd9759c12",
20
+ "since": "0.1.72"
21
+ },
22
+ {
23
+ "sha": "6e0b36b4d353b6b6",
24
+ "since": "0.1.75"
25
+ },
26
+ {
27
+ "sha": "87497464ab8cfa7d",
28
+ "since": "0.1.76"
29
+ }
30
+ ],
31
+ "sync-docs-maps.mjs": [
32
+ {
33
+ "sha": "f431a6fcf54a4906",
34
+ "since": "0.1.72"
35
+ },
36
+ {
37
+ "sha": "32be1c85c4b2757d",
38
+ "since": "0.1.90"
39
+ }
40
+ ],
41
+ "CLAUDE-snippet.md": [
42
+ {
43
+ "sha": "8e8f6eebcb4b2a58",
44
+ "since": "0.1.72"
45
+ },
46
+ {
47
+ "sha": "ed625ebd1209c061",
48
+ "since": "0.1.76"
49
+ },
50
+ {
51
+ "sha": "96497831c905de56",
52
+ "since": "0.1.91"
53
+ }
54
+ ]
55
+ }
56
+ }
@@ -17,7 +17,7 @@
17
17
  // Re-running is safe: import is idempotent by source_path, then title.
18
18
  // This script belongs to the repo it lives in — adapt titles/sets/maps to local conventions.
19
19
  // Usage: node scripts/sync-docs-maps.mjs [--stage-only]
20
- import { readdirSync, readFileSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
20
+ import { readdirSync, readFileSync, mkdirSync, writeFileSync, mkdtempSync } from "node:fs";
21
21
  import { spawnSync } from "node:child_process";
22
22
  import { join, dirname, basename } from "node:path";
23
23
  import { fileURLToPath } from "node:url";
@@ -25,8 +25,9 @@ import { tmpdir } from "node:os";
25
25
 
26
26
  const ROOT = join(dirname(fileURLToPath(import.meta.url)), "..");
27
27
  const DOCS = join(ROOT, "docs");
28
- const OUT = join(tmpdir(), "alkahest-docs-staging");
29
- rmSync(OUT, { recursive: true, force: true });
28
+ // A fresh dir per run: a fixed shared path let another repo's copy of this script, running at the
29
+ // same time, restage its own docs under us, and our import pushed them into this project's maps.
30
+ const OUT = mkdtempSync(join(tmpdir(), "alkahest-docs-staging-"));
30
31
 
31
32
  const sanitize = (t) =>
32
33
  t.replace(/\(\//g, "(").replace(/[/\\:]/g, "-").replace(/`/g, "").replace(/\s+/g, " ").trim();
@@ -0,0 +1,8 @@
1
+ # llm-wiki preset — changes
2
+
3
+ Why each shipped file changed, newest first. `alkahest preset update` prints the entries newer
4
+ than the version an installed copy came from. One `## <version>` per release that touched the
5
+ preset; each bullet names its file.
6
+
7
+ ## 0.1.88
8
+ - First release of the preset.