pi-dent-terms 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,60 +1,63 @@
1
1
  # pi-dent-terms
2
2
 
3
- A pi extension that manages a workspace's terms file — what each domain term means — and checks
4
- the workspace's Markdown against it. pi-dent bundles it through its `pi.extensions`.
3
+ A pi extension that keeps a workspace's terminology: a terms file giving each domain concept one
4
+ preferred label, its meaning, and the phrases to reject, and a check of the workspace's Markdown
5
+ against it. An agent in pi drives it through the `Terms` tool; pi-dent bundles it.
5
6
 
6
- ## What a session gets
7
+ ## Why
7
8
 
8
- - **`Terms` tool.** `find` looks an entry up by id, label, form, reject phrase, or meaning, with
9
- filters on status, key, group, and owner. `check` reports the workspace's findings. `add`,
10
- `update`, `rename`, `merge`, `split`, `deprecate`, `reown`, and `import` change the terms file.
11
- An operation writes the terms file and returns the document occurrences to edit; it never edits
12
- a document itself.
13
- - **After-edit check.** When the host's `edit` or `write` tool changes a Markdown document, the
14
- extension appends that document's prose findings to the tool result, so a session sees its own
15
- rejected wording at once.
9
+ A written vocabulary alone is advice: an agent writing prose drifts off it, and nothing reports
10
+ the drift. pi-dent-terms makes the vocabulary machine-checkable. The check is
11
+ deterministic and offline — it matches phrases, it does not judge what a word means. Findings name
12
+ the occurrences to rewrite; the agent rewrites them with its own `edit` tool, so a wrong entry
13
+ costs a finding to disagree with, never changed prose. Cost tracks change, not corpus — a check
14
+ with a change set reports only what the change introduces.
16
15
 
17
- ## Install
16
+ ## How it works
18
17
 
19
- ```sh
20
- pi install npm:pi-dent-terms # add it to pi's packages
21
- pi -e npm:pi-dent-terms # or try it for one run
22
- ```
18
+ The terms file is `.pi/pi-dent/terms.yaml` under the workspace root, the top level of the Git
19
+ working tree. Each entry gives an `id`, `label`, `meaning`, `owner` (the document that defines the
20
+ term), `reject` phrases, `forms`, a `group`, a `key`, a `status`, and a `history`. The checked
21
+ documents are the `.md` files `git ls-files` lists, tracked or untracked but not ignored.
23
22
 
24
- Requires Node 26 or later, and a pi that provides the extension API
25
- (`@earendil-works/pi-coding-agent`).
23
+ The `Terms` tool:
26
24
 
27
- ## The terms file
25
+ - `find` looks an entry up by id, label, form, reject phrase, or meaning.
26
+ - `check` reports the workspace's findings.
27
+ - `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown`, and `import` change the terms
28
+ file. An operation writes it and returns the document occurrences to rewrite; applying them is
29
+ the agent's edit. The first operation creates it; `import` fills an empty one from a Markdown
30
+ table.
28
31
 
29
- `.pi/pi-dent/terms.yaml` under the workspace root, the top level of the Git working tree. It holds
30
- one entry per concept: its `id`, `label`, `meaning`, the `owner` document that defines it, its
31
- `group`, its `key`, its `status`, and its `history`. Change it through the `Terms` tool: an
32
- operation records the history item and keeps ids and references consistent. A hand edit loses
33
- both.
32
+ When the host's `edit` or `write` changes a Markdown document, the extension appends that
33
+ document's findings to the tool result, so the session sees its rejected wording at once.
34
34
 
35
- ## Findings
35
+ Findings read `<path>:<line>:<column> <code> <message>`, all one weight:
36
36
 
37
- | Code | What it reports |
38
- | --------- | ----------------------------------------------------------------------------------------------------------------------------------- |
39
- | T001–T006 | Terms-file problems: syntax, duplicate labels, dangling ids, deprecation reasons, key use, and an owner that does not use its entry |
40
- | P001–P002 | A rejected or deprecated phrase in prose |
41
- | S001 | A `terms-ignore` comment that is not valid |
37
+ - `T001–T006` — terms-file problems: syntax, duplicate labels, dangling ids, deprecation rules,
38
+ key use, an entry its owner does not use.
39
+ - `P001–P002` — a rejected or deprecated phrase in prose.
40
+ - `S001` — a `terms-ignore` comment that is not valid.
42
41
 
43
42
  Silence one finding on one line with `<!-- terms-ignore P001: reason -->`.
44
43
 
45
- ## Configuration
44
+ Limits: only Markdown documents are checked, and the after-edit check sees only the host's `edit`
45
+ and `write` — a change through `Bash` gets none. Phrase matching cannot tell a term from the
46
+ everyday word; judging that is the agent's job, on the occurrences a change check hands it.
46
47
 
47
- `terms.checkAfterEdit` in pi-dent's configuration file sets the after-edit check for the user; a
48
- workspace's `settings.checkAfterEdit` in its terms file overrides it. Without a terms file the
49
- check is off. A bad value or an unknown key is reported as a `pi-dent-terms: <message>` warning
50
- when the session starts.
48
+ ## Using it
49
+
50
+ pi-dent loads it; standalone, `pi install npm:pi-dent-terms` adds it to pi's packages. Requires Node
51
+ 26 or later. Without a terms file, `find` and `check` refuse and the after-edit check is off. Turn
52
+ the check on with `terms.checkAfterEdit: true` in pi-dent's configuration file; a workspace's terms
53
+ file overrides it with `settings.checkAfterEdit`. [terms-tool.md, after-edit
54
+ check](specs/terms-tool.md#after-edit-check) owns these settings and their diagnostics.
51
55
 
52
56
  ## Documentation
53
57
 
54
- - `specs/terms.md` — the terms file, matching, checks, and operations.
58
+ - `specs/terms.md` — the terms file, prose, matching, checks, and operations; the exact rules.
55
59
  - `specs/terms-tool.md` — the `Terms` tool and the after-edit check.
56
- - `docs/research/README.md` — the experiments behind the design.
57
- - `AGENTS.md` — how to work on the repository.
60
+ - `docs/research/README.md` — the experiments behind the design, non-normative.
58
61
 
59
62
  ## License
60
63
 
package/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * pi-dent-terms - see specs/.
3
3
  *
4
- * Wiring only: every building block lives in lib/ (specs/terms-tool.md, Sections 1 and 4).
4
+ * Wiring only: every building block lives in lib/ (specs/terms-tool.md#package-and-registration and
5
+ * specs/terms-tool.md#after-edit-check).
5
6
  */
6
7
 
7
8
  import { homedir } from "node:os";
@@ -14,7 +15,7 @@ import { createTermsTool } from "./lib/tool.ts";
14
15
  import { realWorkspace } from "./lib/workspace.ts";
15
16
 
16
17
  export default function piDentTerms(pi: ExtensionAPI): void {
17
- // Read once per extension instance, at its first session_start (specs/terms-tool.md, 4.2).
18
+ // Read once per extension instance, at its first session_start (specs/terms-tool.md#configuration).
18
19
  // The project layer is `<cwd>` of the process (pi-dent's config-file.md, Section 1), not the session's.
19
20
  let config: TermsConfig | undefined;
20
21
 
package/lib/after-edit.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The after-edit check (specs/terms-tool.md, Section 4): the effective setting (4.1) and the
2
+ * The after-edit check (specs/terms-tool.md#after-edit-check): the effective setting (4.1) and the
3
3
  * handler that checks a document the host's `edit` or `write` tool changed (4.3).
4
4
  */
5
5
 
@@ -13,7 +13,7 @@ import { parseTermsFile } from "./terms-file.ts";
13
13
  import { findingText } from "./text.ts";
14
14
  import { workspacePathOf, type WorkspaceAccess } from "./workspace.ts";
15
15
 
16
- /** The content of a tool result (specs/terms-tool.md, Section 4.3). */
16
+ /** The content of a tool result (specs/terms-tool.md#checking-a-written-document). */
17
17
  export type ResultContent = ToolResultEvent["content"];
18
18
 
19
19
  /** The fields of a `tool_result` event the check reads. */
@@ -24,7 +24,7 @@ export interface ToolResultFields {
24
24
  readonly isError: boolean;
25
25
  }
26
26
 
27
- /** The inputs of the handler (specs/terms-tool.md, Section 4.3). */
27
+ /** The inputs of the handler (specs/terms-tool.md#checking-a-written-document). */
28
28
  export interface AfterEditDependencies {
29
29
  readonly io: WorkspaceAccess;
30
30
  /** The user's home directory, for a leading `~`. */
@@ -34,7 +34,7 @@ export interface AfterEditDependencies {
34
34
  }
35
35
 
36
36
  /**
37
- * The effective after-edit setting of a workspace whose terms file exists (Section 4.1): the
37
+ * The effective after-edit setting of a workspace whose terms file exists (specs/terms-tool.md#effective-setting): the
38
38
  * file's `settings.checkAfterEdit` when present, else the configuration's, else off.
39
39
  */
40
40
  export function effectiveCheckAfterEdit(
@@ -45,7 +45,7 @@ export function effectiveCheckAfterEdit(
45
45
  }
46
46
 
47
47
  /**
48
- * The absolute target of an event's `path` (Section 4.3): one leading `@` removed, `~` or a
48
+ * The absolute target of an event's `path` (specs/terms-tool.md#checking-a-written-document): one leading `@` removed, `~` or a
49
49
  * leading `~/` read as `homeDir`, resolved against `cwd` when relative.
50
50
  */
51
51
  export function targetPath(raw: string, cwd: string, homeDir: string): string {
@@ -58,7 +58,7 @@ export function targetPath(raw: string, cwd: string, homeDir: string): string {
58
58
  return resolve(cwd, path);
59
59
  }
60
60
 
61
- /** The appended text of a check (Section 4.3): its header, then one line per finding. */
61
+ /** The appended text of a check (specs/terms-tool.md#checking-a-written-document): its header, then one line per finding. */
62
62
  export function checkBlockText(path: string, findings: readonly ProseFinding[]): string {
63
63
  return [
64
64
  `Terms check of ${path}: ${findings.length} findings`,
@@ -67,7 +67,7 @@ export function checkBlockText(path: string, findings: readonly ProseFinding[]):
67
67
  }
68
68
 
69
69
  /**
70
- * The `tool_result` handler for `edit` and `write` (Section 4.3). It returns the event's content
70
+ * The `tool_result` handler for `edit` and `write` (specs/terms-tool.md#checking-a-written-document). It returns the event's content
71
71
  * with the check block appended when findings remain, and `undefined` (the result unchanged) in
72
72
  * every other case, a failure to run Git or read a file included.
73
73
  */
@@ -79,7 +79,7 @@ export function createAfterEdit(
79
79
  if (event.toolName !== "edit" && event.toolName !== "write") return;
80
80
  const raw = event.input.path;
81
81
  if (typeof raw !== "string") return;
82
- // Only a `.md` target can be a document, so nothing else is looked at (terms.md, Section 1.2).
82
+ // Only a `.md` target can be a document, so nothing else is looked at (specs/terms.md#documents).
83
83
  const target = targetPath(raw, cwd, dependencies.homeDir);
84
84
  if (!basename(target).endsWith(".md")) return;
85
85
  try {
package/lib/changes.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Change checks (specs/terms.md, Section 5.4): the validation of a change set, the base workspace,
2
+ * Change checks (specs/terms.md#change-checks): the validation of a change set, the base workspace,
3
3
  * the line pairing, the introduced findings, and the label occurrences in changed lines.
4
4
  *
5
5
  * The functions are pure: the change set is supplied by the caller, and the library reads no
@@ -16,7 +16,7 @@ import {
16
16
  import { TERMS_PATH, parseTermsFile } from "./terms-file.ts";
17
17
  import { compareUtf16, normalise, quote } from "./text.ts";
18
18
 
19
- /** A change of a change set (specs/terms.md, Section 5.4). */
19
+ /** A change of a change set (specs/terms.md#change-checks). */
20
20
  export interface Change {
21
21
  /** The changed file's path in the workspace. */
22
22
  readonly path: string;
@@ -26,7 +26,7 @@ export interface Change {
26
26
  readonly from?: string | undefined;
27
27
  }
28
28
 
29
- /** A label occurrence in a changed line (specs/terms.md, Section 5.4). */
29
+ /** A label occurrence in a changed line (specs/terms.md#change-checks). */
30
30
  export interface LabelOccurrence {
31
31
  readonly id: string;
32
32
  readonly label: string;
@@ -34,7 +34,7 @@ export interface LabelOccurrence {
34
34
  readonly path: string;
35
35
  readonly line: number;
36
36
  readonly column: number;
37
- /** The occurrence's source text, normalised (Section 4.1). */
37
+ /** The occurrence's source text, normalised (specs/terms.md#phrases). */
38
38
  readonly text: string;
39
39
  }
40
40
 
@@ -50,9 +50,9 @@ const UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
50
50
  const LINE_ENDING = /\r\n|\r|\n/;
51
51
 
52
52
  // ---------------------------------------------------------------------------------------------
53
- // Validation (specs/terms-tool.md, Section 1.2)
53
+ // Validation (specs/terms-tool.md#validation)
54
54
 
55
- /** True when `path` is a workspace path (Section 1.1). */
55
+ /** True when `path` is a workspace path (specs/terms.md#workspace-root). */
56
56
  function isWorkspacePath(path: string): boolean {
57
57
  if (path === "") {
58
58
  return false;
@@ -60,7 +60,7 @@ function isWorkspacePath(path: string): boolean {
60
60
  return path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
61
61
  }
62
62
 
63
- /** True when a `path` or `from` meets condition 1 of Section 5.4. */
63
+ /** True when a `path` or `from` meets condition 1 of specs/terms.md#change-checks. */
64
64
  function isChangePath(path: string): boolean {
65
65
  return path === TERMS_PATH || (path.endsWith(".md") && isWorkspacePath(path));
66
66
  }
@@ -82,14 +82,14 @@ function hasLoneSurrogate(text: string): boolean {
82
82
  return false;
83
83
  }
84
84
 
85
- /** A change's base path: its `from`, else its `path` (Section 5.4). */
85
+ /** A change's base path: its `from`, else its `path` (specs/terms.md#change-checks). */
86
86
  function basePathOf(change: Change): string {
87
87
  return change.from ?? change.path;
88
88
  }
89
89
 
90
90
  /**
91
- * The error text of the first failing check of specs/terms-tool.md, Section 1.2, for a change set,
92
- * or `undefined` when the change set is valid (Section 5.4). Items are examined in order; for each,
91
+ * The error text of the first failing check of specs/terms-tool.md#validation, for a change set,
92
+ * or `undefined` when the change set is valid (specs/terms.md#change-checks). Items are examined in order; for each,
93
93
  * its `path`, then its `from` when set, then the item as a whole.
94
94
  */
95
95
  export function validateChanges(changes: readonly Change[]): string | undefined {
@@ -126,7 +126,7 @@ export function validateChanges(changes: readonly Change[]): string | undefined
126
126
  }
127
127
 
128
128
  // ---------------------------------------------------------------------------------------------
129
- // Change check (specs/terms.md, Section 5.4)
129
+ // Change check (specs/terms.md#change-checks)
130
130
 
131
131
  /** One line number of a base text paired with one of a current text; both counted from 1. */
132
132
  interface Pair {
@@ -154,7 +154,7 @@ interface ChangeAnalysis {
154
154
  readonly changed: ReadonlySet<number>;
155
155
  }
156
156
 
157
- /** The base workspace of a change set (Section 5.4). */
157
+ /** The base workspace of a change set (specs/terms.md#change-checks). */
158
158
  interface BaseWorkspace {
159
159
  readonly termsBytes: Uint8Array | undefined;
160
160
  readonly documents: ReadonlyMap<string, string>;
@@ -177,7 +177,7 @@ function decodeText(bytes: Uint8Array | undefined): string {
177
177
  }
178
178
  }
179
179
 
180
- /** The lines of a text (Section 5.4): its parts between line endings, without a trailing empty one. */
180
+ /** The lines of a text (specs/terms.md#change-checks): its parts between line endings, without a trailing empty one. */
181
181
  function linesOf(text: string): string[] {
182
182
  const parts = text.split(LINE_ENDING);
183
183
  if (parts.at(-1) === "") {
@@ -187,7 +187,7 @@ function linesOf(text: string): string[] {
187
187
  }
188
188
 
189
189
  /**
190
- * The line pairing of a change (Section 5.4): a longest list of equal-line pairs, ascending in both
190
+ * The line pairing of a change (specs/terms.md#change-checks): a longest list of equal-line pairs, ascending in both
191
191
  * numbers, the smallest sequence `i1, j1, i2, j2, …` among the longest.
192
192
  */
193
193
  function linePairing(base: readonly string[], current: readonly string[]): Pair[] {
@@ -234,7 +234,7 @@ function linePairing(base: readonly string[], current: readonly string[]): Pair[
234
234
  return pairs;
235
235
  }
236
236
 
237
- /** The base workspace of a change set (Section 5.4): each change undone. */
237
+ /** The base workspace of a change set (specs/terms.md#change-checks): each change undone. */
238
238
  function baseWorkspace(
239
239
  termsBytes: Uint8Array,
240
240
  documents: ReadonlyMap<string, string>,
@@ -289,7 +289,7 @@ function analyseChange(
289
289
  }
290
290
 
291
291
  /**
292
- * The base lines of a finding of a change's file (Section 5.4): the base line of its pair, else the
292
+ * The base lines of a finding of a change's file (specs/terms.md#change-checks): the base line of its pair, else the
293
293
  * lines of the base region that corresponds to the region holding its line. The last region of the
294
294
  * base text also holds every line number past its last line.
295
295
  */
@@ -344,7 +344,7 @@ function countBase(
344
344
  return count;
345
345
  }
346
346
 
347
- /** Orders label occurrences by id, then path, line, and column (Section 5.4). */
347
+ /** Orders label occurrences by id, then path, line, and column (specs/terms.md#change-checks). */
348
348
  function compareOccurrences(a: LabelOccurrence, b: LabelOccurrence): number {
349
349
  return (
350
350
  compareUtf16(a.id, b.id) ||
@@ -354,7 +354,7 @@ function compareOccurrences(a: LabelOccurrence, b: LabelOccurrence): number {
354
354
  );
355
355
  }
356
356
 
357
- /** The label occurrences in changed lines (Section 5.4). */
357
+ /** The label occurrences in changed lines (specs/terms.md#change-checks). */
358
358
  function labelOccurrences(
359
359
  analyses: readonly ChangeAnalysis[],
360
360
  termsBytes: Uint8Array,
@@ -399,7 +399,7 @@ function labelOccurrences(
399
399
  }
400
400
 
401
401
  /**
402
- * The check of a workspace with a change set (specs/terms.md, Section 5.4): the introduced findings
402
+ * The check of a workspace with a change set (specs/terms.md#change-checks): the introduced findings
403
403
  * and the label occurrences in changed lines. The change set MUST be valid (see `validateChanges`).
404
404
  */
405
405
  export function checkChanges(
package/lib/checks.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Checks of the workspace (specs/terms.md, Section 5): the ordering and suppression of findings
2
+ * Checks of the workspace (specs/terms.md#checks): the ordering and suppression of findings
3
3
  * (5.1), the file checks T002–T006 (5.2), and the prose checks P001, P002, and S001 (5.3).
4
4
  *
5
5
  * Each document is parsed and matched once, into a DocumentAnalysis that the file checks T005 and
@@ -28,7 +28,7 @@ export type FileCode = "T001" | "T002" | "T003" | "T004" | "T005" | "T006";
28
28
  export type ProseCode = "P001" | "P002" | "S001";
29
29
 
30
30
  /**
31
- * A file check finding (Section 5.2). `concerns` holds the ids of the entries it concerns, in
31
+ * A file check finding (specs/terms.md#file-checks). `concerns` holds the ids of the entries it concerns, in
32
32
  * ascending order: the entry its value path is or lies under, left in or not (T001), or the entry
33
33
  * `<id>` and the entries its message names (the other codes). A T001 finding concerns no entry when
34
34
  * its item has no string `id`.
@@ -38,50 +38,50 @@ export interface FileFinding extends Finding {
38
38
  readonly concerns: readonly string[];
39
39
  }
40
40
 
41
- /** A prose check finding (Section 5.3). */
41
+ /** A prose check finding (specs/terms.md#prose-checks). */
42
42
  export interface ProseFinding extends Finding {
43
43
  readonly code: ProseCode;
44
44
  }
45
45
 
46
46
  export type CheckFinding = FileFinding | ProseFinding;
47
47
 
48
- /** A document parsed and matched once (Sections 3 and 4). */
48
+ /** A document parsed and matched once (specs/terms.md#prose and specs/terms.md#matching). */
49
49
  export interface DocumentAnalysis {
50
50
  readonly path: string;
51
51
  readonly prose: ProseDocument;
52
52
  readonly occurrences: readonly Occurrence[];
53
- /** The ids of the active entries the document uses (Section 4.3), code-span uses included. */
53
+ /** The ids of the active entries the document uses (specs/terms.md#uses), code-span uses included. */
54
54
  readonly usedIds: ReadonlySet<string>;
55
55
  }
56
56
 
57
57
  /** The terms file and the analysed documents of a workspace. */
58
58
  export interface Workspace {
59
59
  readonly terms: TermsFile;
60
- /** The variants of the entries that are not left out (Section 4.1). */
60
+ /** The variants of the entries that are not left out (specs/terms.md#phrases). */
61
61
  readonly variants: readonly Variant[];
62
62
  /** The entries that are not left out, by id. */
63
63
  readonly entries: ReadonlyMap<string, EntryRecord>;
64
64
  /** The analysed documents, by workspace path. */
65
65
  readonly documents: ReadonlyMap<string, DocumentAnalysis>;
66
- /** The ids used by each supplied external owner text, by owner path (Section 4.3). */
66
+ /** The ids used by each supplied external owner text, by owner path (specs/terms.md#uses). */
67
67
  readonly externals: ReadonlyMap<string, ReadonlySet<string>>;
68
68
  }
69
69
 
70
- /** The check of a workspace (Section 5.1), with the counts the `check` action reports. */
70
+ /** The check of a workspace (specs/terms.md#findings), with the counts the `check` action reports. */
71
71
  export interface WorkspaceCheck {
72
72
  readonly findings: readonly CheckFinding[];
73
73
  readonly documentCount: number;
74
74
  readonly termsCount: number;
75
75
  }
76
76
 
77
- /** An owner path with leading `../` is external (Section 1.2); every other owner is internal. */
77
+ /** An owner path with leading `../` is external (specs/terms.md#documents); every other owner is internal. */
78
78
  export function isExternalOwner(owner: string): boolean {
79
79
  return owner.startsWith("../");
80
80
  }
81
81
 
82
82
  /**
83
83
  * The ids of the active entries whose normalised label or form, or its capitalised variant, is
84
- * the normalised whole content of a code span (Section 4.3), by that text.
84
+ * the normalised whole content of a code span (specs/terms.md#uses), by that text.
85
85
  */
86
86
  function codeSpanIndex(variants: readonly Variant[]): Map<string, Set<string>> {
87
87
  const index = new Map<string, Set<string>>();
@@ -148,7 +148,7 @@ export function analyseWorkspace(
148
148
  return { terms, variants, entries, documents: analysed, externals };
149
149
  }
150
150
 
151
- /** The file checks of the workspace (Section 5.2), in finding order. */
151
+ /** The file checks of the workspace (specs/terms.md#file-checks), in finding order. */
152
152
  export function fileFindings(ws: Workspace): FileFinding[] {
153
153
  return [
154
154
  ...t001Findings(ws),
@@ -159,7 +159,7 @@ export function fileFindings(ws: Workspace): FileFinding[] {
159
159
  ].toSorted(compareFindings);
160
160
  }
161
161
 
162
- /** The file checks of a terms file and its documents (Section 5.2), in finding order. */
162
+ /** The file checks of a terms file and its documents (specs/terms.md#file-checks), in finding order. */
163
163
  export function fileChecks(
164
164
  terms: TermsFile,
165
165
  documents: ReadonlyMap<string, string>,
@@ -169,7 +169,7 @@ export function fileChecks(
169
169
  }
170
170
 
171
171
  /**
172
- * Whether a valid suppression comment suppresses the occurrence (Section 3.3): its code is the
172
+ * Whether a valid suppression comment suppresses the occurrence (specs/terms.md#suppression-comments): its code is the
173
173
  * code of the occurrence's kind, its target line is the line the occurrence starts on.
174
174
  */
175
175
  export function isSuppressed(doc: DocumentAnalysis, occurrence: Occurrence): boolean {
@@ -185,7 +185,7 @@ export function isSuppressed(doc: DocumentAnalysis, occurrence: Occurrence): boo
185
185
  );
186
186
  }
187
187
 
188
- /** The prose checks of one analysed document (Section 5.3), suppressions applied, in order. */
188
+ /** The prose checks of one analysed document (specs/terms.md#prose-checks), suppressions applied, in order. */
189
189
  export function proseFindings(ws: Workspace, doc: DocumentAnalysis): ProseFinding[] {
190
190
  const out: ProseFinding[] = [];
191
191
  for (const occurrence of doc.occurrences) {
@@ -226,14 +226,14 @@ export function proseFindings(ws: Workspace, doc: DocumentAnalysis): ProseFindin
226
226
  return out.toSorted(compareFindings);
227
227
  }
228
228
 
229
- /** The prose checks of one document (Section 5.3), with valid suppressions applied. */
229
+ /** The prose checks of one document (specs/terms.md#prose-checks), with valid suppressions applied. */
230
230
  export function proseChecks(path: string, text: string, terms: TermsFile): ProseFinding[] {
231
231
  const ws = analyseWorkspace(terms, new Map([[path, text]]));
232
232
  return [...ws.documents.values()].flatMap((doc) => proseFindings(ws, doc));
233
233
  }
234
234
 
235
235
  /**
236
- * The check of a workspace (Section 5.1): the file checks and the prose checks of every document,
236
+ * The check of a workspace (specs/terms.md#findings): the file checks and the prose checks of every document,
237
237
  * ordered, with the findings that valid suppressions suppress left out.
238
238
  */
239
239
  export function checkWorkspace(
@@ -294,7 +294,7 @@ function fileFinding(
294
294
  };
295
295
  }
296
296
 
297
- /** The ids that name an entry left in (Section 2.3); other ids are left out. */
297
+ /** The ids that name an entry left in (specs/terms.md#entries); other ids are left out. */
298
298
  function existingOnly(ws: Workspace, ids: readonly string[]): string[] {
299
299
  return ids.filter((id) => ws.entries.has(id));
300
300
  }
@@ -316,7 +316,7 @@ interface Phrase {
316
316
  readonly path: string;
317
317
  }
318
318
 
319
- /** The label and the forms phrases of a record, normalised (Section 4.1). */
319
+ /** The label and the forms phrases of a record, normalised (specs/terms.md#phrases). */
320
320
  function phrasesOf(record: EntryRecord): Phrase[] {
321
321
  const { entry } = record;
322
322
  return [
@@ -329,7 +329,7 @@ function phrasesOf(record: EntryRecord): Phrase[] {
329
329
  }
330
330
 
331
331
  /**
332
- * The T001 findings of the terms file, each with the entry it concerns (Section 5.2): the entry
332
+ * The T001 findings of the terms file, each with the entry it concerns (specs/terms.md#file-checks): the entry
333
333
  * of the `terms[<i>]` prefix of its value path, by the id that item has.
334
334
  */
335
335
  function t001Findings(ws: Workspace): FileFinding[] {
@@ -348,7 +348,7 @@ function t001Findings(ws: Workspace): FileFinding[] {
348
348
  }
349
349
 
350
350
  // ---------------------------------------------------------------------------------------------
351
- // File checks (Section 5.2)
351
+ // File checks (specs/terms.md#file-checks)
352
352
 
353
353
  /** T002: a label or form equal to a label, form, or reject phrase of another entry. */
354
354
  function checkT002(ws: Workspace): FileFinding[] {
@@ -420,7 +420,7 @@ function reachableFrom(ws: Workspace, start: string, memo: Map<string, Set<strin
420
420
  return seen;
421
421
  }
422
422
 
423
- /** The cycle set of an entry (Section 5.2): the entries it reaches that reach it back. */
423
+ /** The cycle set of an entry (specs/terms.md#file-checks): the entries it reaches that reach it back. */
424
424
  function cycleSetOf(ws: Workspace, id: string, memo: Map<string, Set<string>>): string[] {
425
425
  const reach = reachableFrom(ws, id, memo);
426
426
  return [...reach]
@@ -554,7 +554,7 @@ function checkT004(ws: Workspace): FileFinding[] {
554
554
  }
555
555
 
556
556
  /**
557
- * The uses of an entry's owner text (Section 5.2): its document, or its supplied external owner
557
+ * The uses of an entry's owner text (specs/terms.md#file-checks): its document, or its supplied external owner
558
558
  * text; undefined when that text is unavailable.
559
559
  */
560
560
  function ownerUsedIds(ws: Workspace, owner: string): ReadonlySet<string> | undefined {
package/lib/config.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The configuration of pi-dent-terms (specs/terms-tool.md, Section 4.2): the root key `terms` of
2
+ * The configuration of pi-dent-terms (specs/terms-tool.md#configuration): the root key `terms` of
3
3
  * pi-dent's layered configuration file, read as specs/config-file.md, Sections 1, 2, 3, and 7
4
4
  * specify, and the diagnostics of its `terms` value.
5
5
  *
6
6
  * `resolveConfig` is pure: the parsed layers in, the configuration and its diagnostics out.
7
7
  * `loadTermsConfig` adds the reads. A layer whose read or parse fails is dropped silently, as
8
- * Section 4.2 requires of this extension.
8
+ * specs/terms-tool.md#configuration requires of this extension.
9
9
  */
10
10
 
11
11
  import { readFileSync } from "node:fs";
@@ -13,10 +13,10 @@ import { homedir } from "node:os";
13
13
  import { join } from "node:path";
14
14
  import { parseTree, type Node, type ParseError } from "jsonc-parser";
15
15
 
16
- /** The root key this extension contributes (specs/terms-tool.md, Section 4.2). */
16
+ /** The root key this extension contributes (specs/terms-tool.md#configuration). */
17
17
  export const CONFIG_ROOT_KEY = "terms";
18
18
 
19
- /** The keys of the `terms` object (specs/terms-tool.md, Section 4.2). */
19
+ /** The keys of the `terms` object (specs/terms-tool.md#configuration). */
20
20
  const TERMS_KEYS: readonly string[] = ["checkAfterEdit"];
21
21
 
22
22
  /** The environment variables a `${env.NAME}` reference reads. */
@@ -83,7 +83,10 @@ function expansion(token: string, cwd: string, env: Environment): string | undef
83
83
  return env[name];
84
84
  }
85
85
 
86
- /** A string with its placeholders expanded, or `ABSENT` when one is invalid (Section 7). */
86
+ /**
87
+ * A string with its placeholders expanded, or `ABSENT` when one is invalid (config-file.md,
88
+ * Section 7).
89
+ */
87
90
  function substituteString(value: string, cwd: string, env: Environment): string | typeof ABSENT {
88
91
  let out = "";
89
92
  let index = 0;
@@ -176,7 +179,7 @@ function declares(root: Readonly<Record<string, unknown>>, path: readonly string
176
179
  return true;
177
180
  }
178
181
 
179
- /** Deep merge: objects merge key by key, any other value of `override` replaces (Section 3). */
182
+ /** Deep merge: objects merge key by key, any other value of `override` replaces (specs/terms-tool.md#actions). */
180
183
  function mergeValues(base: unknown, override: unknown): unknown {
181
184
  if (!isRecord(base) || !isRecord(override)) return override;
182
185
  const out: Record<string, unknown> = {};
@@ -237,7 +240,7 @@ export function resolveConfig(layers: {
237
240
 
238
241
  /**
239
242
  * The extension's configuration: both layers read, parsed, and resolved. Call it once per
240
- * extension instance (specs/terms-tool.md, Section 4.2).
243
+ * extension instance (specs/terms-tool.md#configuration).
241
244
  */
242
245
  export function loadTermsConfig(dependencies: ConfigDependencies): TermsConfig {
243
246
  const homeDir = dependencies.homeDir ?? homedir();
package/lib/import.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Import of thesaurus tables into entries (specs/terms.md, Section 6.8): row problems, ids,
2
+ * Import of thesaurus tables into entries (specs/terms.md#import): row problems, ids,
3
3
  * owners, groups, distinguish ids, and reject candidates.
4
4
  */
5
5
 
@@ -32,7 +32,7 @@ interface Row {
32
32
 
33
33
  /**
34
34
  * Reads the thesaurus tables of one document (`text`, the document at `path`) into active entries
35
- * dated `date` (Section 6.8, refusals 3 and 4 of the table rows). The caller has checked the
35
+ * dated `date` (specs/terms.md#import, refusals 3 and 4 of the table rows). The caller has checked the
36
36
  * terms file and that `path` is a document.
37
37
  */
38
38
  export function readThesaurus(
@@ -108,7 +108,7 @@ export function readThesaurus(
108
108
  return { entries: deriveKeys(entries, documents), candidates };
109
109
  }
110
110
 
111
- /** Derives keys from uses in the complete proposed matching (Section 6.8). */
111
+ /** Derives keys from uses in the complete proposed matching (specs/terms.md#import). */
112
112
  function deriveKeys(entries: readonly Entry[], documents: ReadonlyMap<string, string>): Entry[] {
113
113
  const variants = variantsOf(entries);
114
114
  const users = new Map<string, Set<string>>();
@@ -130,7 +130,7 @@ function deriveKeys(entries: readonly Entry[], documents: ReadonlyMap<string, st
130
130
  });
131
131
  }
132
132
 
133
- /** The cell text of a column, normalised; a missing cell is empty (Section 6.8). */
133
+ /** The cell text of a column, normalised; a missing cell is empty (specs/terms.md#import). */
134
134
  function cellText(row: ProseRow, column: number): string {
135
135
  return normalise(row.cells[column]?.text ?? "");
136
136
  }
@@ -168,7 +168,7 @@ function labelOfOther(row: Row, rows: readonly Row[], item: string): boolean {
168
168
  return rows.some((other) => other !== row && other.term === item);
169
169
  }
170
170
 
171
- /** The ids of the other rows whose label equals an item of the row, without repeats (Section 6.8). */
171
+ /** The ids of the other rows whose label equals an item of the row, without repeats (specs/terms.md#import). */
172
172
  function distinguishOf(row: Row, rows: readonly Row[]): string[] {
173
173
  const out: string[] = [];
174
174
  for (const item of row.items) {
@@ -188,7 +188,7 @@ function directoryOf(path: string): string {
188
188
  }
189
189
 
190
190
  /**
191
- * The owner path of a row (Section 6.8), or undefined when the Owner cell gives no owner path.
191
+ * The owner path of a row (specs/terms.md#import), or undefined when the Owner cell gives no owner path.
192
192
  */
193
193
  function ownerOf(path: string, cell: ProseCell | undefined): string | undefined {
194
194
  const link = cell?.links[0];