pi-dent-terms 0.1.1 → 0.1.3

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/lib/import.ts CHANGED
@@ -126,7 +126,8 @@ function deriveKeys(entries: readonly Entry[], documents: ReadonlyMap<string, st
126
126
  documents.has(entry.owner) &&
127
127
  paths?.size === 1 &&
128
128
  paths.has(entry.owner);
129
- return { ...entry, key: local ? "local" : "shared" };
129
+ if (local) return { ...entry, key: "local" };
130
+ return { ...entry, key: paths?.size === 1 ? "confusable" : "shared" };
130
131
  });
131
132
  }
132
133
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dent-terms",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "A pi extension that manages a workspace's terms file and checks its Markdown against it",
5
5
  "keywords": [
6
6
  "glossary",
@@ -19,7 +19,8 @@
19
19
  },
20
20
  "files": [
21
21
  "index.ts",
22
- "lib/"
22
+ "lib/",
23
+ "specs/"
23
24
  ],
24
25
  "type": "module",
25
26
  "dependencies": {
@@ -0,0 +1,28 @@
1
+ # pi-dent-terms specifications
2
+
3
+ Write and review specs per the `dev:writing-specs` skill, which defines the requirement keywords and
4
+ the conformance rule. This file holds only this repository's differences from it.
5
+
6
+ ## Specs
7
+
8
+ | Spec | Subject |
9
+ | --------------- | ---------------------------------------------------------------------- |
10
+ | `terms.md` | The terms file, prose, matching, checks, and operations (the resource) |
11
+ | `terms-tool.md` | The `Terms` tool and the after-edit check (the extension surface) |
12
+
13
+ ## Differences
14
+
15
+ - A resource spec is `<subject>.md`; the tool spec over it is `<subject>-tool.md`, which links the
16
+ resource spec as its owning contract.
17
+ - pi-dent's specifications (pi-dent-agent `specs/`) may be cited, never linked, as owning contracts
18
+ for what pi-dent provides. They are cited by `Section N` with the document named on the line,
19
+ never by `#id`: spec-map resolves ids only in this repository's specs, and
20
+ `.config/spec-map.json` lists `config-file.md` under `externalSpecs`. When pi-dent-agent
21
+ renumbers a cited section, update the number here.
22
+ - Configuration is a root key contributed to pi-dent's `config-file.md`, Section 2, whose
23
+ unknown-key rule is the one policy; the terms file is workspace data, not configuration.
24
+ - `.config/spec-map.json` skips `docs/research/jev-term-sense/items.json`: its text fields quote the
25
+ specs as they stood, section numbers included, and stay verbatim.
26
+ - A length or a column counted in characters counts UTF-16 code units; a duration shown in whole
27
+ seconds is rounded down.
28
+ - The term registry is the `Terms` tool, storing `.pi/pi-dent/terms.yaml`.
@@ -0,0 +1,374 @@
1
+ # Terms tool specification
2
+
3
+ This document specifies the `pi-dent-terms` extension: the `Terms` tool, through which a session
4
+ looks entries up, checks its workspace, and runs the operations on its terms file, and the
5
+ after-edit check, which checks a document that the host's `edit` or `write` tool changed. The
6
+ terms file, matching, checks, and operations are owned by [terms.md](terms.md).
7
+
8
+ ## 1. Package and registration {#package-and-registration}
9
+
10
+ The package name is `pi-dent-terms`. The `pi` key of its `package.json` holds the package manifest,
11
+ whose `extensions` array MUST be exactly `["./index.ts"]`; that module's default export is the
12
+ extension factory.
13
+
14
+ The host installs the package with `devDependencies` omitted and supplies the peer packages through
15
+ its own module resolution. Every bare module specifier the entry imports, directly or transitively,
16
+ MUST name a package in `dependencies` or `peerDependencies`, and the entry MUST load with only the
17
+ `dependencies` installed.
18
+
19
+ The extension MUST register the tool through the host `registerTool` API when it loads, in every
20
+ run mode:
21
+
22
+ | Field | Value |
23
+ | --------------- | ----------------------------------------------------- |
24
+ | `name` | `"Terms"` |
25
+ | `label` | `"Terms"` |
26
+ | `description` | The text of [model-facing texts](#model-facing-texts) |
27
+ | `promptSnippet` | The text of [model-facing texts](#model-facing-texts) |
28
+ | `parameters` | The [parameter schema](#parameter-schema) |
29
+ | `executionMode` | `"sequential"` |
30
+ | `renderShell` | not set: the host's default tool shell |
31
+
32
+ `executionMode` `"sequential"` makes the host run a `Terms` call alone, never concurrently with
33
+ another tool call. `renderCall` and `renderResult` are not set. Every rejection this
34
+ specification gives is a tool error (`isError: true`) whose content is its error text alone,
35
+ with no `details`.
36
+
37
+ ### 1.1 Parameter schema {#parameter-schema}
38
+
39
+ The parameter schema is a JSON object schema with `type: "object"` and
40
+ `additionalProperties: false`, with one required field, `action`; every other field is optional
41
+ in the schema and admits `null` beside the type in the table, and each action accepts only its
42
+ fields below. A field whose value is `null` counts as absent.
43
+
44
+ | Field | Type | Actions | Contract |
45
+ | ------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
46
+ | `action` | `"find" \| "check" \| "add" \| "update" \| "rename" \| "merge" \| "split" \| "deprecate" \| "reown" \| "import"` | all | The action ([actions](#actions)). |
47
+ | `query` | string? \| null | `find` | The text looked up ([`find`](#find)). |
48
+ | `id` | string? \| null | `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown` | Required. The entry the operation acts on. |
49
+ | `label` | string? \| null | `add`, `rename` | Required. The label. |
50
+ | `meaning` | string? \| null | `add`, `update` | Required for `add`, optional for `update`. The meaning. |
51
+ | `owner` | string? \| null | `find`, `add`, `reown` | Required for `add` and `reown`. The owner path ([terms.md, documents](terms.md#documents)). |
52
+ | `group` | string? \| null | `find`, `add` | Required for `add`. The group. |
53
+ | `key` | `"shared" \| "confusable" \| "local"`? \| null | `find`, `add`, `update` | Required for `add`. The key. |
54
+ | `status` | `"active" \| "deprecated"`? \| null | `find`, `update` | The status; for `update`, `active` only. |
55
+ | `reject` | string[]? \| null | `add` | The reject phrases. |
56
+ | `distinguish` | string[]? \| null | `add` | The ids to distinguish. |
57
+ | `addReject` | string[]? \| null | `update` | Reject phrases to add. |
58
+ | `removeReject` | string[]? \| null | `update` | Reject phrases to remove. |
59
+ | `addDistinguish` | string[]? \| null | `update` | Distinguish ids to add symmetrically. |
60
+ | `removeDistinguish` | string[]? \| null | `update` | Distinguish ids to remove symmetrically. |
61
+ | `forms` | string[]? \| null | `add`, `rename` | The irregular forms of the label. |
62
+ | `into` | string[]? \| null | `merge`, `split` | Required. The ids merged or split into. |
63
+ | `reason` | `"renamed" \| "out-of-scope"`? \| null | `deprecate` | Required. The reason. |
64
+ | `replacedBy` | string[]? \| null | `deprecate` | The replacements. |
65
+ | `path` | string? \| null | `import` | Required. The workspace path of the document holding the table. |
66
+ | `changes` | object[]? \| null | `check` | The change set ([terms.md, change checks](terms.md#change-checks)). |
67
+
68
+ Each item of `changes` is an object schema with `additionalProperties: false`, the required fields
69
+ `path` (string) and `before` (string or `null`), and the optional field `from` (string or `null`,
70
+ `null` counting as absent). The schema constrains the types of the table and of these items, the
71
+ values of `action`, `key`, and `reason`, and the set of admitted properties, and nothing else. Each
72
+ field other than `changes` maps to the operation parameter of the same name ([terms.md,
73
+ operations](terms.md#operations)); `merge` passes the one id of `into` as its `into`.
74
+
75
+ ### 1.2 Validation {#validation}
76
+
77
+ Execution-time validation MUST reject the call with the error text of the first failing check,
78
+ in this order, before any file is read:
79
+
80
+ | # | Check | Error text |
81
+ | --- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
82
+ | 1 | A field other than `action` that the action does not accept is present (first such field in table order) | `<field> is not valid for action <action>` |
83
+ | 2 | A required field of the action is absent (first such field in table order) | `action <action> requires <field>` |
84
+ | 3 | A string field is empty after trimming (first such field in table order) | `<field> must be a non-empty string` |
85
+ | 4 | A list field holds an item that is empty after trimming (first such field in table order) | `<field> must hold non-empty strings` |
86
+ | 5 | `merge`: `into` does not hold exactly one item | `merge takes exactly one id in into` |
87
+ | 6 | `find`: none of `query`, `status`, `key`, `group`, and `owner` is present | `action find requires query or a filter` |
88
+ | 7 | `update`: `status` is `deprecated` | `update takes status active only; use deprecate` |
89
+ | 8 | `changes`: the change set is not valid ([terms.md, change checks](terms.md#change-checks)) | see below |
90
+
91
+ Trimming removes leading and trailing white space ([terms.md, phrases](terms.md#phrases)). Every
92
+ string, and every item of a list, is used trimmed, except `before`, which is used as given.
93
+
94
+ For check 8, the items of `changes` are examined in order; for each item, its `path`, then its
95
+ `from` when set, then the item as a whole, each against the conditions of [terms.md, change
96
+ checks](terms.md#change-checks), in their order. The first failure gives its text, `<i>` being the
97
+ item's position from 0:
98
+
99
+ | Condition | Error text |
100
+ | --------- | ----------------------------------------------------------------------------------------- |
101
+ | 1 | `changes[<i>].<field> must be .pi/pi-dent/terms.yaml or a workspace path ending with .md` |
102
+ | 2 | `changes[<i>].from must be .pi/pi-dent/terms.yaml exactly when path is` |
103
+ | 3 | `changes[<i>].from needs a before text` |
104
+ | 4 | `changes[<i>].before holds a lone surrogate` |
105
+ | 5 | `changes[<i>].path repeats "<path>"` |
106
+ | 6 | `changes[<i>].<field> repeats the base path "<p>"` |
107
+
108
+ Condition 1 applies to each field examined, condition 2 to `from`; conditions 3 to 6 to the item
109
+ as a whole,
110
+ condition 6 naming `from` when it is set, else `path`, `<p>` being the base path.
111
+
112
+ ### 1.3 Model-facing texts {#model-facing-texts}
113
+
114
+ The texts of this section are what a model reads to choose and fill a call; each MUST be
115
+ registered verbatim, and none cites a specification.
116
+
117
+ The `description` is
118
+
119
+ ```text
120
+ Manage this workspace's thesaurus in .pi/pi-dent/terms.yaml, one preferred label per concept and no synonyms, and check the workspace's Markdown documents against it. find looks entries up by id, label, reject phrase, form, or meaning, optionally filtered by status, key, group, or owner (a filter alone lists every entry it admits), and lists each match with its meaning, status, owner, and related entries; use it to learn what a term means and before writing a domain term you are unsure of. check reports findings for the terms file and for every Markdown document not ignored by git; with changes, each the changed file's path, its text before the change (null when new), and from when moved, it reports only the findings the changes introduced and lists label occurrences on changed lines, to confirm each means its entry; list every file you changed, .pi/pi-dent/terms.yaml included after an operation, and keep each before text the same across checks. add, update, rename, merge, split, deprecate, and reown change the terms file and record the change in each changed entry's history; ids are never removed. update changes an active entry's key, meaning, reject phrases, or symmetric distinguish relations, recording a replaced meaning in history, and with status active returns a deprecated entry to active; give at least one effective change. local entries are used only by their owner. An entire normalised code span matching an active label or form, or its capitalised variant, counts as a use, never an occurrence to rewrite. Owners can be workspace-relative paths with leading ../ for external files. import fills an empty terms file from a Markdown table with the columns Term, Meaning, Owner, and Avoid or distinguish. No action edits a document: the result lists the occurrences to rewrite, with a suggested text where there is one; apply them with your edit tool. To keep one occurrence on purpose, put <!-- terms-ignore P001: reason --> (or P002) on its line or as a standalone comment before it; a standalone comment targets the first nonblank line after its block.
121
+ ```
122
+
123
+ The `promptSnippet` is
124
+
125
+ ```text
126
+ Look up, check, and change the workspace's thesaurus of terms
127
+ ```
128
+
129
+ Each property of the parameter schema carries this `description`:
130
+
131
+ | Field | `description` |
132
+ | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | `action` | `find: look entries up. check: report findings. add, update, rename, merge, split, deprecate, reown, import: change the terms file.` |
134
+ | `query` | `For find: text to look for in ids, labels, reject phrases, forms, and meanings, ignoring case; optional when a filter (status, key, group, owner) is given.` |
135
+ | `id` | `The entry's id, a lowercase slug such as "rendered-view"; for add, the new id.` |
136
+ | `label` | `For add and rename: the one preferred term, in base form, lowercase unless a name.` |
137
+ | `meaning` | `For add (required) or update (optional): one sentence saying what the concept is.` |
138
+ | `owner` | `For add and reown: the owner path of the Markdown file that defines the term, relative to the workspace root; leading ../ is allowed. For find: list only entries with this owner.` |
139
+ | `group` | `For add: the group the entry is listed under. For find: list only entries in this group.` |
140
+ | `key` | `For add (required) or update (optional): shared for use by two or more documents, confusable for one or more, local for use only by the owner. For find: list only entries with this key.` |
141
+ | `status` | `For find: list only active or only deprecated entries. For update: active returns a deprecated entry to active; the other update fields apply as well.` |
142
+ | `reject` | `For add: specific phrases that must not be used for this concept; never ordinary words.` |
143
+ | `distinguish` | `For add: ids of neighbouring concepts a reader could confuse with this one.` |
144
+ | `addReject` | `For update: specific reject phrases to add; already-present phrases are refused.` |
145
+ | `removeReject` | `For update: reject phrases to remove; missing phrases are refused.` |
146
+ | `addDistinguish` | `For update: existing ids to distinguish from, on both entries; self and existing relations are refused.` |
147
+ | `removeDistinguish` | `For update: ids to stop distinguishing from, on both entries; missing relations are refused.` |
148
+ | `forms` | `For add and rename: irregular inflections of the label only; regular plurals are derived.` |
149
+ | `into` | `For merge: the one id that absorbs the entry. For split: the two or more ids that replace it; add them first.` |
150
+ | `reason` | `For deprecate: renamed (with one replacedBy) or out-of-scope (with none).` |
151
+ | `replacedBy` | `For deprecate: the id of the entry that replaces it.` |
152
+ | `path` | `For import: the workspace-relative path of the Markdown thesaurus.` |
153
+ | `changes` | `For check: the changed files, each { path, before, from }: before is the text before the change, null for a new file; from is the old path of a moved file.` |
154
+
155
+ ## 2. Workspace access {#workspace-access}
156
+
157
+ The workspace of a call or an event is that of the workspace root ([terms.md, workspace
158
+ root](terms.md#workspace-root)) of the invoking session's working directory. Each call reads the
159
+ terms file anew and, unless its action is `find`, lists and reads the documents anew. A call MUST be
160
+ rejected, the first failure reported, with:
161
+
162
+ | Failure | Error text |
163
+ | ------------------------------------------------------------------------------------------------- | -------------------------------------------- |
164
+ | The working directory has no workspace root | `<cwd> is not inside a Git working tree` |
165
+ | Git cannot be run, or a Git command of [terms.md, workspace](terms.md#workspace), fails otherwise | `git failed: <message>` |
166
+ | The terms file exists and cannot be read | `cannot read .pi/pi-dent/terms.yaml: <code>` |
167
+ | `find` or `check`, and there is no terms file | `no terms file at .pi/pi-dent/terms.yaml` |
168
+
169
+ `<cwd>` is the working directory; `<message>` is the first line of what Git wrote to its error
170
+ output, else the system's error message; `<code>` is the error code the file system reports
171
+ (such as `EISDIR`), else its message. A `git rev-parse --show-toplevel` run that exits with a
172
+ failure status is the first row; a Git that cannot be started is the second. A terms file whose
173
+ path gives `ENOENT` or `ENOTDIR` is absent.
174
+
175
+ For `check`, the extension MUST separately supply the external owner texts of [terms.md,
176
+ documents](terms.md#documents), for every active entry not left out under [terms.md,
177
+ entries](terms.md#entries). Paths are resolved against the workspace root. File type is tested on
178
+ the final path component without following a symbolic link there; symbolic links in parent
179
+ directories are followed. The extension MUST skip missing, unreadable, non-regular, non-UTF-8, or
180
+ U+0000-containing external owner files without an error.
181
+
182
+ The extension MUST NOT read a file or run Git to derive a change set: `changes` is used as given. An
183
+ operation's date is the current calendar date in the local time zone of the process. A refusal of an
184
+ operation ([terms.md, common rules](terms.md#common-rules)) is a tool error with the refusal text.
185
+ Otherwise the extension MUST write the new terms file text to `.pi/pi-dent/terms.yaml`, creating
186
+ `.pi/` and `.pi/pi-dent/` when they are absent. It MUST write the text to a new file in the
187
+ directory of the terms file's target and rename that file over the target, so that a failed write
188
+ leaves the previous terms file unchanged and removes the new file. It MUST NOT write any other file,
189
+ including a `.gitignore` in `.pi/pi-dent/`; a failed write is a tool error `cannot write
190
+ .pi/pi-dent/terms.yaml: <code>`. The target is the file a symbolic link at `.pi/pi-dent/terms.yaml`
191
+ resolves to, else `.pi/pi-dent/terms.yaml`.
192
+
193
+ When a call's abort signal fires while a Git command of the call runs, the extension MUST end that
194
+ Git process; the call is then rejected as a Git failure (`git failed: <message>`).
195
+
196
+ ## 3. Actions {#actions}
197
+
198
+ A result's content is one text block holding its result text. In a result text, `"<x>"` is the
199
+ value as ECMAScript `JSON.stringify` writes it ([ECMA-262]), lines are joined by one line feed,
200
+ and the words `entries`, `findings`, `documents`, `occurrences`, `candidates`, and `changes` stay
201
+ plural
202
+ whatever the number. `isError` is unset on every result of this section.
203
+
204
+ ### 3.1 `find` {#find}
205
+
206
+ `<query>` is `query` normalised ([terms.md, phrases](terms.md#phrases)). The filters are `status`,
207
+ `key`, `group`, and `owner`, each when present. An entry matches when each of these that is
208
+ present holds:
209
+
210
+ - `<query>`, in ECMAScript lower case ([ECMA-262]), is a substring of its `id`, its `label`, one
211
+ of its `reject` or `forms` phrases, or its `meaning`, each normalised and in ECMAScript lower
212
+ case;
213
+ - its `status` equals `status`, and its `key` equals `key`;
214
+ - its `group`, normalised, equals `group` normalised;
215
+ - its `owner` equals `owner`.
216
+
217
+ Entries left out under [terms.md, entries](terms.md#entries), are not searched. Matching entries are
218
+ listed in ascending `id` order; with `query`, those whose normalised lower-case label equals the
219
+ lower-case `<query>` come first, then the others, each part in ascending `id` order.
220
+
221
+ `<search>` is, joined by `, `, each of these whose parameter is present, in this order:
222
+ `"<query>"`, `status <status>`, `key <key>`, `group "<group>"`, and `owner <owner>`, the group
223
+ normalised. With no match the text is `No entry matches <search>`. Otherwise it is the line
224
+ `<n> entries match <search>:`, then for each matching entry the line
225
+ `<id> "<label>" · <status> · <key> · <group> · owner <owner>`, followed by these lines, each
226
+ present only when its list is not empty or its field is set, indented by two spaces:
227
+
228
+ 1. `meaning: <meaning>`;
229
+ 2. `reject: ` and the `reject` phrases as `"<p>"`, joined by `, `;
230
+ 3. `forms: ` and the `forms` phrases, written the same way;
231
+ 4. `distinguish: ` and each entry in the distinguish relation with it, in ascending `id`
232
+ order, as `<id> "<label>"`, or `<id> (not an entry)` for a listed id that names no entry left
233
+ in under [terms.md, entries](terms.md#entries), joined by `, `;
234
+ 5. `replacedBy: ` and each replacement as on line 4, joined by `, `;
235
+ 6. `reason: <reason>`.
236
+
237
+ When the terms file gives T001 findings, the line `.pi/pi-dent/terms.yaml has <k> T001 findings;
238
+ run check` ends the text, with or without a match. `details` is `{ action: "find", ids: [<id>…] }`,
239
+ the matching ids in listed order.
240
+
241
+ ### 3.2 `check` {#check}
242
+
243
+ The text is the line `<n> findings · <d> documents · <e> entries`, then the text of each finding of
244
+ the check of the workspace ([terms.md, findings](terms.md#findings)), in order, one per line. `<d>`
245
+ is the number of documents and `<e>` the number of items of `terms`, `0` when `terms` is not a
246
+ sequence. `details` is `{ action: "check", findings: [{ path, line, column, code, message }…] }` in
247
+ the same order.
248
+
249
+ With `changes`, the findings are the introduced findings of the change set ([terms.md, change
250
+ checks](terms.md#change-checks)), and the first line is `<n> findings introduced · <c> changes · <d>
251
+ documents · <e> entries`, `<c>` being the number of items of `changes`. When there is at least one
252
+ label occurrence in changed lines, the finding lines are followed by an empty line, the line `<u>
253
+ label occurrences in changed lines; confirm each means its entry:`, `<u>` being their number, and
254
+ for each entry with one, in ascending `id` order, the line `<id> "<label>": <meaning>`, label and
255
+ meaning as the terms file holds them, then one line per label occurrence of it, in order, `
256
+ <path>:<line>:<column> "<text>"`, indented by two spaces, `<text>` being its normalised source text.
257
+ `details` also holds `occurrences: [{ id, path, line, column, text }…]`, in the same order.
258
+
259
+ ### 3.3 Operations {#operations}
260
+
261
+ The actions `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown`, and `import` run the
262
+ operation of the same name ([terms.md, operations](terms.md#operations), including `update` in
263
+ [terms.md, `update`](terms.md#update)). The text is the summary line, then ` ·
264
+ .pi/pi-dent/terms.yaml written` appended to it, then the edit list block, then, for `import`, the
265
+ candidate block.
266
+
267
+ | Action | Summary line |
268
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
269
+ | `add` | `Added <id> "<label>"` |
270
+ | `update` | `Updated <id>` |
271
+ | `rename` | `Renamed <id> "<old label>" → "<label>"` |
272
+ | `merge` | `Merged <id> into <into>` |
273
+ | `split` | `Split <id> into <ids>` |
274
+ | `deprecate` | `Deprecated <id> (<reason>)`, followed by ` → <ids>` when `replacedBy` holds one or more ids |
275
+ | `reown` | `Moved the owner of <id> from <old owner> to <owner>` |
276
+ | `import` | `Imported <n> entries from <path>`, followed by `; key local: <ids>` when any ids were assigned `local` per [terms.md, `import`](terms.md#import) |
277
+
278
+ `<ids>` is the list joined by `, `; for `import` it is the local ids in ascending order. The edit
279
+ list block is the line `No occurrences to edit.` when the edit list is empty; otherwise the line
280
+ `<k> occurrences to edit with your edit tool; no document was changed:`, then one line per
281
+ occurrence in edit list order: `<path>:<line>:<column> "<old>" → "<new>"`, or
282
+ `<path>:<line>:<column> "<old>" → no suggestion, rewrite by hand` when the item has no suggested
283
+ text. The candidate block is absent when there is no reject candidate; otherwise the line `<k>
284
+ reject candidates; use update with addReject for specific phrases and drop ordinary words:`, then
285
+ one line `<id>: "<item>"` per candidate in order.
286
+
287
+ For example, an `update` of `rendered-view` with an empty edit list returns:
288
+
289
+ ```text
290
+ Updated rendered-view · .pi/pi-dent/terms.yaml written
291
+ No occurrences to edit.
292
+ ```
293
+
294
+ `details` is `{ action, edits: [{ path, line, column, old, new }…] }`, `new` being `null` for an
295
+ item without a suggested text; for `import` it also holds `candidates: [{ id, text }…]` and
296
+ `localIds: [<id>…]`, the local ids in ascending order, empty when none qualify.
297
+
298
+ ## 4. After-edit check {#after-edit-check}
299
+
300
+ ### 4.1 Effective setting {#effective-setting}
301
+
302
+ The after-edit check is off for a workspace without a terms file. Otherwise it is on when the
303
+ terms file's `settings.checkAfterEdit` is `true` and off when it is `false`; when that value is
304
+ absent or counts as absent ([terms.md, root](terms.md#root)), the configuration value of
305
+ [configuration](#configuration) decides, and without one the check is off.
306
+
307
+ ### 4.2 Configuration {#configuration}
308
+
309
+ This specification contributes the root key `terms` to pi-dent's configuration file
310
+ (pi-dent-agent `specs/config-file.md`, Section 2):
311
+
312
+ | Key | Type | Contract |
313
+ | ---------------------- | ----------------- | ---------------------------------------------------------------------------------------------- |
314
+ | `terms` | object, optional | The settings of this extension. |
315
+ | `terms.checkAfterEdit` | boolean, optional | The user's default for the after-edit check, used per [effective setting](#effective-setting). |
316
+
317
+ The extension MUST read the configuration as pi-dent-agent `specs/config-file.md`, Sections 1, 2, 3,
318
+ and 7, specify it, once per extension instance (one call of the extension factory), at the
319
+ instance's first `session_start`; a layer that those sections drop is dropped without a diagnostic
320
+ from this extension. A `terms` value that is not an object, or a `checkAfterEdit` value that is not
321
+ a boolean, MUST produce one diagnostic and be ignored; unknown keys of `terms` follow the
322
+ unknown-key rule (pi-dent-agent `specs/config-file.md`, Section 2). The diagnostics are `<file>:
323
+ terms must be an object`, `<file>: terms.checkAfterEdit must be true or false`, and `<file>: terms
324
+ has unknown keys <keys>`, `<keys>` being the unknown keys in ascending order joined by `, `, and
325
+ `<file>` the owning layer's file (pi-dent-agent `specs/config-file.md`, Section 4). Each MUST be
326
+ reported once per extension instance, at that `session_start`, through the host `notify` API at
327
+ level `warning` as `pi-dent-terms: <message>`. Other diagnostics of config-file.md, Sections 1, 2,
328
+ and 7 (layer read, parse, root, substitution) are not reported by this extension.
329
+
330
+ ### 4.3 Checking a written document {#checking-a-written-document}
331
+
332
+ The extension MUST handle every `tool_result` event whose tool name is `edit` or `write` and whose
333
+ `isError` is false. Its target is the event input's `path` when it is a string, with one leading `@`
334
+ removed and `~` or a leading `~/` standing for the user's home directory, resolved against the
335
+ invoking session's working directory when relative. The target's directory is resolved through
336
+ symbolic links (realpath) before its workspace path is taken. When the after-edit check is on, read
337
+ at the event, and the target is a document of the workspace, the extension MUST run the prose checks
338
+ of that document ([terms.md, prose checks](terms.md#prose-checks)) on its current text, with the
339
+ findings that valid suppression comments suppress left out. When at least one finding remains, the
340
+ handler MUST return the event's content with one text block appended: `Terms check of <path>: <n>
341
+ findings`, then the text of each finding, one per line, `<path>` being the target's workspace path.
342
+ In every other case, a failure to run Git or read a file included, the handler MUST leave the result
343
+ unchanged.
344
+
345
+ ## 5. Normative references {#normative-references}
346
+
347
+ - [ECMA-262] ECMAScript Language Specification, 14th edition (June 2023), Ecma International:
348
+ `String.prototype.toLowerCase` and `JSON.stringify`.
349
+
350
+ ## 6. Specification gaps {#specification-gaps}
351
+
352
+ - Whether a child session binds `Terms`, and whether the host fires `tool_result` for a child
353
+ session's `edit` and `write`, is the host's and pi-dent's.
354
+ - A document changed through any tool other than the host's `edit` and `write`, such as pi-dent's
355
+ `Markdown` `edit`, `Bash`, or `Script`, gets no after-edit check.
356
+ - The terms file is written outside the host's file mutation queue; a process that changes it
357
+ between a call's read and its write is overwritten.
358
+ - No bound is set on the number of items of `changes` or the length of a `before` text; the line
359
+ pairing of a change takes time proportional to the product of its two line counts.
360
+ - No bound is set on the length of a result text; how the host shows or cuts a long one is the
361
+ host's.
362
+ - The configuration is read once per extension instance, not once per boot window: a session
363
+ that replaces its predecessor through the host's `new`, `resume`, or `fork` reads it again.
364
+ - File checks are not part of the after-edit check, so a use that an edit adds or removes changes
365
+ the T005 and T006 findings only on the next `check`.
366
+ - The `old` text of an edit list item is often not unique in its document; the line and column
367
+ locate it, but the host's `edit` needs enough surrounding text to be unique.
368
+ - A `git rev-parse --show-toplevel` failure for another reason, such as dubious ownership or a
369
+ corrupt repository, is reported as `<cwd> is not inside a Git working tree`.
370
+ - A symbolic link at `.pi/pi-dent/terms.yaml`, at `.pi/`, or at `.pi/pi-dent/` is followed when the
371
+ terms file is written, so the write can land outside the workspace.
372
+ - `.pi/pi-dent/` may hold a `.gitignore` written by the pi-dent desktop app (pi-dent-app), meant to
373
+ ignore only that app's index files; whether the terms file is committable depends on it. A
374
+ workspace whose own `.gitignore` ignores `.pi/` leaves the terms file untracked.
package/specs/terms.md ADDED
@@ -0,0 +1,756 @@
1
+ # Terms specification
2
+
3
+ This document specifies the terms file of a workspace, the matching of its entries in the prose
4
+ of the workspace's documents, the checks that report findings, and the operations that change
5
+ the terms file. The `pi-dent-terms` package provides them as a library and as a pi extension; the
6
+ `Terms` tool and the after-edit check are owned by [terms-tool.md](terms-tool.md).
7
+
8
+ The library computes every check and every operation as a function of its inputs alone: the terms
9
+ file's bytes, the set of documents with their texts, for checks the separately supplied external
10
+ owner texts ([documents](#documents)), for a change check its change set ([change
11
+ checks](#change-checks)), and for an operation its parameters and the date. The same inputs MUST
12
+ give the same output, byte for byte. The library MUST NOT read or write files, read the clock, or
13
+ run processes; the extension supplies the inputs and writes the output ([terms-tool.md, workspace
14
+ access](terms-tool.md#workspace-access)).
15
+
16
+ ## 1. Workspace {#workspace}
17
+
18
+ ### 1.1 Workspace root {#workspace-root}
19
+
20
+ The workspace root of a directory is the top level of the Git working tree that contains it,
21
+ the directory `git rev-parse --show-toplevel` prints when run in it. A directory outside every
22
+ Git working tree has no workspace root. The workspace of a workspace root is the Git working
23
+ tree below it, with its documents and its terms file. A workspace path is a path relative to
24
+ the workspace root, its segments joined by `/`, with no empty, `.`, or `..` segment.
25
+
26
+ ### 1.2 Documents {#documents}
27
+
28
+ The documents of a workspace are the files that `git ls-files -z --cached --others
29
+ --exclude-standard`, run in the workspace root, lists and that meet all of these:
30
+
31
+ - the path ends with `.md`, compared exactly;
32
+ - the path names a regular file, a symbolic link not being one whatever it points to;
33
+ - its bytes are valid UTF-8 and contain no U+0000.
34
+
35
+ A path listed more than once is one document. A document's text is its bytes decoded as UTF-8,
36
+ without a leading U+FEFF; a character is a Unicode scalar value. A line ending is a line feed,
37
+ a carriage return not followed by a line feed, or a carriage return followed by a line feed
38
+ ([CommonMark], Section 2.1); lines are numbered from 1. The column of a character is 1 plus the
39
+ number of UTF-16 code units before it on its line. Paths are compared and ordered by UTF-16
40
+ code units.
41
+
42
+ An owner path is either a workspace path ending with `.md`, or one or more leading `../` segments
43
+ followed by a workspace path ending with `.md`. It is resolved against the workspace root, not the
44
+ session's working directory. Owner identity is its path string, without resolving physical file
45
+ aliases. An owner path with leading `../` is external; every other owner path is internal. An
46
+ external owner is not a workspace document, and its text never contributes a document use or an
47
+ occurrence. The library accepts external owner texts separately, keyed by owner path, decoded as
48
+ document texts above. An absent external owner text is unavailable, not an empty text. [file
49
+ checks](#file-checks) defines the check that uses these texts; the extension supplies them per
50
+ [terms-tool.md, workspace access](terms-tool.md#workspace-access).
51
+
52
+ ## 2. Terms file {#terms-file}
53
+
54
+ ### 2.1 Location and syntax {#location-and-syntax}
55
+
56
+ The terms file of a workspace is `.pi/pi-dent/terms.yaml` under its workspace root; no other path is
57
+ the terms file. Its text is its bytes decoded as UTF-8, without a leading U+FEFF, parsed as one YAML
58
+ document ([YAML 1.2.2]) with the core schema (Section 10.3 of [YAML 1.2.2]), so that a date is a
59
+ string. A text that is not valid UTF-8, that does not parse, that holds other than exactly one
60
+ document, or that has a duplicate key in a mapping gives one T001 finding ([file
61
+ checks](#file-checks)) and no settings and no entries.
62
+
63
+ ### 2.2 Root {#root}
64
+
65
+ The root MUST be a mapping; a root that is not gives one T001 finding and no settings and no
66
+ entries. A `terms` value that is absent or not a sequence gives one T001 finding and no entries.
67
+ A `settings` value that is not a mapping, or a `settings` key whose value does not have its
68
+ type, gives one T001 finding and counts as absent.
69
+
70
+ | Key | Type | Contract |
71
+ | ---------- | ------------------ | ---------------------------------- |
72
+ | `settings` | mapping, optional | The file-level settings. |
73
+ | `terms` | sequence, required | The entries ([entries](#entries)). |
74
+
75
+ | `settings` key | Type | Contract |
76
+ | ---------------- | ----------------- | -------------------------------------------------------------------------------------------------------------------------- |
77
+ | `checkAfterEdit` | boolean, optional | Whether the after-edit check runs in this workspace ([terms-tool.md, effective setting](terms-tool.md#effective-setting)). |
78
+
79
+ An unknown key of the root, of `settings`, of an entry, or of a history item follows the
80
+ unknown-key rule (pi-dent-agent `specs/config-file.md`, Section 2), the one
81
+ diagnostic being one T001 finding that names the object and all its unknown keys.
82
+
83
+ ### 2.3 Entries {#entries}
84
+
85
+ An entry is the record of one concept. A string is one line when it holds neither a line feed nor a
86
+ carriage return; a non-empty line is a one-line string holding a character other than white space; a
87
+ phrase is a one-line string with no leading or trailing white space that holds at least one word
88
+ character (Section 4.1). An id is a string matching `^[a-z0-9]+(-[a-z0-9]+)*$`. Two phrases or ids
89
+ of one list are the same when they are equal after normalisation ([phrases](#phrases)).
90
+
91
+ | Field | Type | Contract |
92
+ | ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- |
93
+ | `id` | id, required | The concept's identity. Unique in the file. |
94
+ | `label` | phrase, required | The one preferred term for the concept, in base form. |
95
+ | `meaning` | string, required | What the concept is, one non-empty line. |
96
+ | `owner` | string, required | The owner path ([documents](#documents)) of the file that defines the concept. |
97
+ | `group` | string, required | The heading the entry is listed under, one non-empty line. |
98
+ | `key` | enum, required | `shared`: used by two or more documents. `confusable`: by one or more. `local`: used only by its owner ([file checks](#file-checks)). |
99
+ | `status` | enum, required | `active` or `deprecated`. |
100
+ | `reject` | phrase[], optional | Phrases no document uses for the concept. No phrase twice. |
101
+ | `distinguish` | id[], optional | Ids of neighbouring concepts a reader confuses with this one. No id twice. |
102
+ | `forms` | phrase[], optional | Inflected forms of `label` that [phrases](#phrases) does not derive. No phrase twice. |
103
+ | `replacedBy` | id[], optional | Ids of the entries that replace a deprecated entry, its replacements. No id twice. |
104
+ | `reason` | enum, optional | Why the entry is deprecated: `merged`, `split`, `renamed`, or `out-of-scope`. |
105
+ | `history` | history item[], required | The operations that changed the entry, in the order they did ([history items](#history-items)); at least one item. |
106
+
107
+ An absent list is an empty list. The distinguish relation holds between two entries when either
108
+ lists the other. The `terms` sequence MUST hold its entries in strictly ascending order of `id`; an
109
+ entry whose `id` is not greater than the last string `id` before it gives one T001 finding. Each
110
+ violation of this section or of [history items](#history-items) gives one T001 finding. An entry
111
+ with a T001 finding whose `<value path>` ([file checks](#file-checks)) is the entry or lies under
112
+ it, other than one for unknown keys, is left out of every other check, of matching, and of the
113
+ operations' changes; its `id`, when it is a string, still counts as an existing id.
114
+
115
+ ### 2.4 History items {#history-items}
116
+
117
+ A history item is a mapping with the keys `date`, a valid calendar date in the complete extended
118
+ form `YYYY-MM-DD` of [ISO 8601], `op`, and the operands of one operand set of its `op`, each
119
+ required except `replacedBy`:
120
+
121
+ | `op` | Operand sets |
122
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
123
+ | `add` | none |
124
+ | `update` | none; `meaning`: the entry's meaning before the operation, a string; `status`: the entry's status before the operation, `deprecated`; or both |
125
+ | `import` | `from`: the workspace path of the imported document |
126
+ | `rename` | `from`, `to`: the label before and after, phrases |
127
+ | `merge` | on the merged entry, `into`: the id it was merged into; on that entry, `from`: the merged id |
128
+ | `split` | on the split entry, `into`: the list of ids it was split into; on each of those, `from`: the split id |
129
+ | `deprecate` | on the deprecated entry, `reason` and, when it has replacements, `replacedBy`: the list of their ids; on a replacement, `from`: the deprecated id |
130
+ | `reown` | `from`, `to`: the owner before and after, owner paths ([documents](#documents)) |
131
+
132
+ A `merge` or `split` item takes its first set when it holds `into`, a `deprecate` item when it holds
133
+ `reason`, an `update` item the set of those of `meaning` and `status` it holds, and otherwise its
134
+ second set. An id operand
135
+ is a string, a list operand a sequence of strings, and `reason` takes the values of the entry field
136
+ `reason`. A key other than `date`, `op`, and the operands of the taken set is unknown. When `op` is
137
+ absent or not one of these values, no operand set is taken and the item's keys other than `date` and
138
+ `op` are not checked.
139
+
140
+ ### 2.5 Canonical form {#canonical-form}
141
+
142
+ Every terms file an operation writes is in canonical form:
143
+
144
+ 1. UTF-8 without a byte-order mark; every line ends with a line feed; no line has trailing
145
+ white space.
146
+ 2. When the input had a non-empty `settings`, the line `settings:` and each of its keys as
147
+ `<key>: <value>` on its own line indented by 2 spaces, in the order of the table of
148
+ [root](#root); then `terms:`, or `terms: []` when there is no entry.
149
+ 3. Each entry as a block sequence item, ` - id: <id>`, then its other present fields, each on its
150
+ own line indented by 4 spaces, in the order of the table of [entries](#entries), a list field as
151
+ `<field>:` alone. An empty list and an absent optional field are not written.
152
+ 4. Each item of a list of strings as `- <item>` on its own line indented by 6 spaces.
153
+ 5. Each history item as a block mapping: ` - date: <date>`, then `op: <op>`, then each operand as
154
+ `<key>: <value>` in the order of the table of [history items](#history-items), each on its own
155
+ line indented by 8 spaces; a list operand as `<key>:` alone, then each of its ids as `- <id>` on
156
+ its own line indented by 10 spaces.
157
+ 6. A string matching `^[A-Za-z0-9]([A-Za-z0-9 ._/-]*[A-Za-z0-9._/])?$` that the core schema
158
+ does not resolve to a null, boolean, integer, or float is written plain; every other string
159
+ is written as ECMAScript `JSON.stringify` writes it ([ECMA-262]), then with each character
160
+ outside the printable set of [YAML 1.2.2], Section 5.1, written `\u` and four lowercase
161
+ hexadecimal digits. When that text holds `\"` and no other `\`, the string is instead
162
+ written single-quoted: `'`, the string with each `'` doubled, then `'`.
163
+ 7. No other line is written: the input's comments, blank lines, and layout are not kept.
164
+
165
+ > Note (non-normative): with no flow collection and single quotes where they save escapes, oxfmt
166
+ > leaves a written terms file unchanged.
167
+
168
+ ## 3. Prose {#prose}
169
+
170
+ ### 3.1 Parsing {#parsing}
171
+
172
+ When line 1 of a document is exactly `---` and a later line is exactly `---`, lines 1 through
173
+ the first such later line are front matter: they hold no prose, and the document is parsed as if
174
+ they were blank, so that line numbers stay. The document is parsed per [CommonMark] with the
175
+ tables extension of [GFM] (Section 4.10) and no other extension; a link destination is taken
176
+ as CommonMark gives it, without percent-decoding.
177
+
178
+ ### 3.2 Prose runs {#prose-runs}
179
+
180
+ A prose block is a heading, a paragraph, or a table cell, wherever it is nested: list items and
181
+ block quotes hold paragraphs. Code blocks, HTML blocks, link reference definitions, front
182
+ matter, and the cells of the `Term` and `Avoid or distinguish` columns of a thesaurus table
183
+ ([`import`](#import)) hold no prose block. Each prose block gives one prose run: a sequence of
184
+ characters, each with the position (line and column) of its source text, and barriers. Its
185
+ inline content contributes, in order:
186
+
187
+ | Inline content | Contributes |
188
+ | -------------------------------------------------- | ---------------------------------------------------------------------------- |
189
+ | Text | its characters |
190
+ | A backslash escape | the escaped character, at the backslash's position |
191
+ | An entity or numeric character reference | the characters it decodes to, at the reference's position |
192
+ | Emphasis, strong emphasis, the link text of a link | what its content contributes; its delimiters and brackets contribute nothing |
193
+ | A soft or hard line break | one space |
194
+ | A code span, raw HTML, an autolink, an image | one barrier |
195
+
196
+ The space of a line break has no position: no occurrence starts or ends with a space, so no
197
+ output reports one. A link destination, a link title, and a link label contribute nothing.
198
+ Prose is the characters of the prose runs of the documents.
199
+
200
+ ### 3.3 Suppression comments {#suppression-comments}
201
+
202
+ A suppression comment is an HTML comment whose text between `<!--` and `-->`, with leading and
203
+ trailing white space removed, is `terms-ignore` or starts with `terms-ignore` followed by white
204
+ space, and that is either raw HTML inside a prose block or the whole of an HTML block, leading
205
+ and trailing white space aside. Its target line is the line on which it starts when it is raw
206
+ HTML. Otherwise its target is the first nonblank line after the last line of its HTML block,
207
+ where a blank line holds only white space ([phrases](#phrases)) after removing the markers of the
208
+ comment's enclosing block quotes; it has no target when no such line exists. A valid comment
209
+ with no target suppresses nothing and gives no S001 finding.
210
+
211
+ A suppression comment is valid when that text matches the ECMAScript regular expression
212
+ ([ECMA-262]) `^terms-ignore[ \t]+(P001|P002):[ \t]+\S` and is one line. A valid suppression
213
+ comment suppresses the findings of its code whose occurrence starts on its target line; one
214
+ comment suppresses one code on one line. An invalid one suppresses nothing and gives an S001
215
+ finding ([prose checks](#prose-checks)).
216
+
217
+ For example, a standalone `<!-- terms-ignore P001: quoted legacy wording -->` on line 1,
218
+ blank lines 2 and 3, and prose on line 4 targets line 4. If only blank lines follow the
219
+ comment, it has no target. Another nonblank comment or a code-block line is not skipped.
220
+
221
+ ## 4. Matching {#matching}
222
+
223
+ ### 4.1 Phrases {#phrases}
224
+
225
+ A word character is a character of Unicode general category L, M, or N ([Unicode], Section
226
+ 4.5); white space is a character with the Unicode property White_Space ([Unicode], Section 4.6).
227
+ A string is normalised by replacing each maximal run of white space with one space and removing
228
+ leading and trailing white space. The last word of a phrase is its last maximal run of word
229
+ characters.
230
+
231
+ The plural of a phrase whose last character is a letter (category L) is the phrase with its last
232
+ word changed by the first rule that applies, letters compared exactly:
233
+
234
+ 1. The word ends with `s`, `x`, `z`, `ch`, or `sh`: `es` is appended.
235
+ 2. The word ends with `y` after a letter other than `a`, `e`, `i`, `o`, and `u`: the `y` is
236
+ replaced by `ies`.
237
+ 3. Otherwise `s` is appended.
238
+
239
+ A phrase whose last character is not a letter has no plural. The capitalised variant of a string
240
+ whose first character is of category Ll is the string with that character replaced by the result
241
+ of ECMAScript `String.prototype.toUpperCase` on it ([ECMA-262]); any other string has none. A
242
+ possessive needs no variant: an apostrophe is not a word character, so the phrase or its plural
243
+ ends before it.
244
+
245
+ The variants of an entry that passes [terms file](#terms-file) are these normalised strings, each
246
+ recording the entry, its kind, and whether it is plural and whether it is capitalised:
247
+
248
+ | Source | Kind | Variants |
249
+ | ----------------------------------------- | ------------ | ----------------------------------------------------------- |
250
+ | `label` of an active entry | `label` | the label, its plural, and the capitalised variant of each |
251
+ | each `forms` phrase of an active entry | `form` | the phrase and its capitalised variant |
252
+ | `label` of a deprecated entry | `deprecated` | the label, its plural, and the capitalised variant of each |
253
+ | each `forms` phrase of a deprecated entry | `deprecated` | the phrase and its capitalised variant |
254
+ | each `reject` phrase of an active entry | `reject` | the phrase, its plural, and the capitalised variant of each |
255
+
256
+ The reject phrases of a deprecated entry give no variant.
257
+
258
+ ### 4.2 Occurrences {#occurrences}
259
+
260
+ An occurrence is a place in a prose run where a variant is found. Each prose run is scanned from
261
+ its first character. At a position `i`, a variant `v` is found when, from `i`:
262
+
263
+ - the run's characters spell `v`, a maximal run of white space in the prose run matching one
264
+ space of `v`, with no barrier in between;
265
+ - when the first character of `v` is a word character, the character before `i` is not a word
266
+ character, a barrier and the start of the run counting as not one;
267
+ - when the last character of `v` is a word character, the character after the spelled text is
268
+ not a word character, a barrier and the end of the run counting as not one.
269
+
270
+ When at least one variant is found at `i`, the one that comes first in this order gives an
271
+ occurrence and the scan continues after the spelled text: the longer spelled text first, in
272
+ UTF-16 code units; then kind `label` or `form` before kind `deprecated`; then not capitalised
273
+ before capitalised; then not plural before plural; then
274
+ kind `label`, `form`, `deprecated`, `reject`; then ascending entry `id`. Otherwise the scan
275
+ continues at `i` + 1. An occurrence starts at the position of its first character; its source
276
+ text is the document text from the start of its first character's source to the end of its last
277
+ character's source.
278
+
279
+ ### 4.3 Uses {#uses}
280
+
281
+ A document uses an active entry when it has an occurrence of kind `label` or `form` of that entry,
282
+ or a code span whose entire content, as CommonMark decodes it and then normalised per
283
+ [phrases](#phrases), equals its normalised label or a normalised `forms` phrase, or the capitalised
284
+ variant of either ([phrases](#phrases)). A derived plural alone does not count unless listed in
285
+ `forms`. Every matching active entry counts as used; the occurrence tie-break of
286
+ [occurrences](#occurrences) does not select between code-span matches. Code spans are considered
287
+ wherever inline content is parsed under [parsing](#parsing), including the thesaurus cells excluded
288
+ from prose runs, but not in front matter, HTML blocks, code blocks, or image descriptions. Substring
289
+ matches do not count: a code span `Terms` uses the label `Terms`, but a code span `run Terms now`
290
+ does not use the label `Terms`. Suppression comments do not change uses.
291
+
292
+ Code-span uses count only for T005 and T006 (including the `local` rules) in [file
293
+ checks](#file-checks). A code span remains a barrier under [prose runs](#prose-runs): it gives no
294
+ occurrence, so no prose finding and no edit list item. For T006 an available external owner text is
295
+ parsed and tested for use by these same rules without becoming a document.
296
+
297
+ ## 5. Checks {#checks}
298
+
299
+ ### 5.1 Findings {#findings}
300
+
301
+ A finding is one reported problem: a workspace path, a line, a column, a code, and a message.
302
+ Its text is `<path>:<line>:<column> <code> <message>`. In a message, `"<x>"` is the value as
303
+ ECMAScript `JSON.stringify` writes it ([ECMA-262]). Findings are ordered by path, then line,
304
+ then column, then code, then message, each ascending by UTF-16 code units or numerically. Every
305
+ finding has the same weight: there is no severity level.
306
+
307
+ The file checks are those that [file checks](#file-checks) lists; the prose checks of a document
308
+ are those that [prose checks](#prose-checks) lists, for that document. The check of a workspace gives the findings of
309
+ the file checks and of the prose checks of every document, ordered, with every finding a valid
310
+ suppression comment suppresses left out.
311
+
312
+ ### 5.2 File checks {#file-checks}
313
+
314
+ A file check finding has the path `.pi/pi-dent/terms.yaml`. `<id>` is the concerned entry's `id`. A
315
+ T001 finding concerns the entry its `<value path>` is or lies under, left in or not. Any other
316
+ finding concerns the entry `<id>` and every entry its message names. A finding is placed at the
317
+ start of a YAML node: for T001, the node its `<value path>` names, or line 1, column 1 for `(file)`
318
+ except that a syntax error is placed where the parser reports it; for T002, the label or `forms`
319
+ item `<p>`; for T003, the item `<x>`, the item naming the entry itself, the `owner` value, or the
320
+ `replacedBy` value of a cycle; for T004, the value of the `reason` or `<field>` its message names,
321
+ else the entry; for T005, the `label` value; for T006, the `owner` value.
322
+
323
+ | Code | Condition | Message |
324
+ | ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
325
+ | T001 | A violation of [terms file](#terms-file) | `<value path>: <reason>` |
326
+ | T002 | The normalised label or a normalised `forms` phrase `<p>` of an active entry equals the normalised label or a normalised `forms` phrase of another entry `<other>` that is deprecated, or active with a smaller `id` | `<id>: "<p>" is also a label or form of <other>` |
327
+ | T002 | The normalised label or a normalised `forms` phrase `<p>` of an active entry equals a normalised `reject` phrase of an active entry `<other>`, itself included | `<id>: "<p>" is a reject phrase of <other>` |
328
+ | T003 | An id `<x>` in the entry's `<field>`, `distinguish` or `replacedBy`, is not an existing id | `<id>: <field> names <x>, which is not an entry` |
329
+ | T003 | The entry's `distinguish` or `replacedBy` holds its own `id` | `<id>: <field> names the entry itself` |
330
+ | T003 | The `owner` of an active entry is internal and is not a document | `<id>: owner <owner> is not a document` |
331
+ | T003 | The entry has the smallest `id` of its cycle set, when that set holds two or more entries | `<id>: replacedBy cycle through <ids>` |
332
+ | T004 | A deprecated entry has no `reason` | `<id>: deprecated without a reason` |
333
+ | T004 | A deprecated entry with `reason` `merged` or `renamed` has other than exactly one replacement | `<id>: reason <reason> needs exactly one replacement, has <n>` |
334
+ | T004 | A deprecated entry with `reason` `split` has fewer than two replacements | `<id>: reason split needs at least two replacements, has <n>` |
335
+ | T004 | A deprecated entry with `reason` `out-of-scope` has a replacement | `<id>: reason out-of-scope takes no replacement, has <n>` |
336
+ | T004 | An active entry has `reason` or a replacement | `<id>: <field> is set on an active entry` |
337
+ | T005 | An active entry with `key` `shared` or `confusable` is used by no document | `<id>: "<label>" is used by no document` |
338
+ | T005 | An active entry with `key` `shared` is used by exactly one document | `<id>: "<label>" is shared but used only by <path>` |
339
+ | T005 | An active entry with `key` `local` is used by a document `<path>` other than its owner (one finding per such document) | `<id>: "<label>" is local but used by <path>` |
340
+ | T006 | An active entry's owner text is available from its document or its supplied external owner text, and that text does not use the entry | `<id>: owner <owner> does not use "<label>"` |
341
+
342
+ `<value path>` names the concerned value from the root, mapping keys joined by `.` and sequence
343
+ positions written `[<i>]` from 0, such as `terms[3].label`; it is `(root)` for the root value
344
+ itself, and `(file)` for a failure of [location and syntax](#location-and-syntax). `<reason>` is:
345
+
346
+ | Violation | `<value path>` | `<reason>` |
347
+ | ---------------------------------------------------------------------------------------------------------- | ------------------- | ----------------------------- |
348
+ | The bytes are not valid UTF-8 | `(file)` | `not valid UTF-8` |
349
+ | The text does not parse | `(file)` | the parser's message |
350
+ | The text holds `<n>` YAML documents, `<n>` other than 1 | `(file)` | `holds <n> YAML documents` |
351
+ | A mapping has a duplicate key | `(file)` | `duplicate key` |
352
+ | A required key `<key>` is absent | the object | `missing <key>` |
353
+ | An object has unknown keys | the object | `unknown keys <keys>` |
354
+ | A value does not have its type | the value | `must be <type>` |
355
+ | A list holds a phrase or id `<x>` that an earlier item holds (`<x>` is the later item's string as written) | the later item | `repeats "<x>"` |
356
+ | `history` holds no item | the `history` value | `must hold at least one item` |
357
+ | An `id` is not greater than the last string `id` `<p>` before it | the `id` value | `must come after <p>` |
358
+
359
+ `<keys>` are the unknown keys as `"<x>"`, in source order, joined by `, `. `<type>` is, for the type
360
+ that [root](#root), [entries](#entries), or [history items](#history-items) gives the value: `a
361
+ mapping`, `a sequence`, `true or false`, `a string`, `an id matching ^[a-z0-9]+(-[a-z0-9]+)*$`, `a
362
+ phrase (one trimmed line holding a letter, mark, or digit)`, `one non-empty line`, `a workspace path
363
+ ending with .md`, `an owner path ending with .md`, `a date YYYY-MM-DD`, or, for an enumeration, `one
364
+ of ` and its values in table order joined by `, `.
365
+
366
+ An external owner gives no T003 owner finding, whether or not its text is available. T006
367
+ skips an unavailable external owner. External owner use does not count toward T005's document
368
+ counts. A `local` entry used by no document gives no zero-use T005: only T006 applies when its
369
+ owner text is available and does not use it (or T003 when its internal owner is not a document).
370
+ The `local` constraints give no P findings; use outside the owner is reported only by T005.
371
+ For example, a `local` entry with an available owner that does not use it and two nonowner
372
+ documents that do use it gives two local T005 findings and one T006. With no uses anywhere it
373
+ gives only T006; with only an unavailable external owner and no document uses it gives neither.
374
+
375
+ > Note (non-normative): a left-out entry's id is an existing id, so a reference to it gives no
376
+ > T003 finding.
377
+
378
+ The cycle set of an entry is the set of entries it reaches by following `replacedBy` ids one or
379
+ more times and that reach it back the same way; `<ids>` are their ids in ascending order, joined
380
+ by `, `. An entry left out under [entries](#entries) gives no finding other than T001.
381
+
382
+ ### 5.3 Prose checks {#prose-checks}
383
+
384
+ A prose check finding has the document's path and the start position of its occurrence or
385
+ suppression comment. `<text>` is the spelled prose text of the occurrence, normalised.
386
+
387
+ | Code | Condition | Message |
388
+ | ---- | --------------------------------------- | ------------------------------------------------------------------------------- |
389
+ | P001 | An occurrence of kind `reject` | `"<text>" is rejected: use "<label>" (<id>)` |
390
+ | P002 | An occurrence of kind `deprecated` | `"<text>" is deprecated (<reason>)<replacement>` |
391
+ | S001 | A suppression comment that is not valid | `terms-ignore needs one code, P001 or P002, a colon, and a reason, on one line` |
392
+
393
+ In P001, `<label>` and `<id>` are those of the entry whose reject phrase gave the variant. In
394
+ P002, `<reason>` is the entry's `reason`, or `none` when it has none, and `<replacement>` is
395
+ empty when it has no replacement, else `: use ` followed by `"<label>" (<id>)` for each
396
+ replacement in `replacedBy` order, or `<id>` alone for an id that names no entry left in under
397
+ [entries](#entries), joined by a space, `or`, and a space.
398
+
399
+ ### 5.4 Change checks {#change-checks}
400
+
401
+ A change set describes how the workspace differs from an earlier state of it, its base
402
+ workspace, as a list of changes; a change is one item of a change set. The caller supplies it:
403
+ the library takes no revision and runs no Git command. Each change has these fields:
404
+
405
+ | Field | Type | Contract |
406
+ | -------- | ------------------------ | --------------------------------------------------------------------------------- |
407
+ | `path` | workspace path | The changed file's path in the workspace. |
408
+ | `before` | string or null | The file's text in the base workspace; null when it has no file at the base path. |
409
+ | `from` | workspace path, optional | The file's path in the base workspace when it was moved; absent means `path`. |
410
+
411
+ A change's base path is its `from`, else its `path`. A change set is valid when each of these
412
+ conditions holds:
413
+
414
+ 1. Every `path` and `from` is `.pi/pi-dent/terms.yaml` or a workspace path ending with `.md`.
415
+ 2. A `from` is `.pi/pi-dent/terms.yaml` exactly when its change's `path` is.
416
+ 3. A change with a `from` has a `before` that is not null.
417
+ 4. No `before` holds a lone surrogate.
418
+ 5. No two changes have the same `path`.
419
+ 6. No two changes have the same base path.
420
+
421
+ An empty change set is valid. [terms-tool.md, validation](terms-tool.md#validation), rejects an
422
+ invalid one. A file that no change lists is the same in the base workspace as in the workspace, so
423
+ its changes introduce nothing.
424
+
425
+ The base workspace is the workspace with each change undone:
426
+
427
+ 1. Its documents are the workspace's documents without those at a change's `path` or base path,
428
+ plus, for each change whose base path ends with `.md` and whose `before` is not null and holds
429
+ no U+0000, a document at the base path whose text is `before` without a leading U+FEFF.
430
+ 2. Its terms file is, when a change has the `path` `.pi/pi-dent/terms.yaml`, that change's `before`
431
+ encoded as UTF-8, or none when it is null; otherwise the workspace's terms file.
432
+ 3. Its external owner texts are the workspace's.
433
+
434
+ The lines of a text are its parts between line endings ([documents](#documents)); an empty part
435
+ after the last line ending is not a line, and the empty text has none. The base text of a change is
436
+ its `before` without a leading U+FEFF, the empty text when `before` is null; its current text is the
437
+ text of the document or the terms file at its `path`, decoded as UTF-8 without a leading U+FEFF, the
438
+ empty text when there is none or the bytes are not valid UTF-8.
439
+
440
+ The line pairing of a change is the longest list of pairs `(i, j)` of a line number of its base text
441
+ and a line number of its current text, both ascending, whose lines are equal as UTF-16 code unit
442
+ sequences; among several such lists, the one whose sequence `i1, j1, i2, j2, …` is smallest,
443
+ compared item by item. For example, base lines `x`, `y` and current lines `y`, `x` give the one pair
444
+ `(1, 2)`, so current line 1 is a changed line. A changed line is a line of a current text that is in
445
+ no pair. The pairs split the line numbers of each text into regions: those before the first pair,
446
+ those between two consecutive pairs, and those after the last pair, the last region of each text
447
+ also holding every line number past its last line. With no pair, each text has one region holding
448
+ all its line numbers. A region of the current text and the region of the base text between the same
449
+ pairs correspond.
450
+
451
+ The base lines of a finding of the workspace in the file at a change's `path` are, when its line is
452
+ in a pair, the base line of that pair, else the lines of the base region that corresponds to the
453
+ region holding its line; its base path is the change's base path. For a finding in any other file,
454
+ its base path is its path and its base lines are its line. Findings with the same base path, base
455
+ lines, code, and message form a group. The base count of a group is the number of findings of the
456
+ check of the base workspace ([findings](#findings)) at its base path, on one of its base lines, with
457
+ its code and message; a base workspace without a terms file gives no findings. The introduced
458
+ findings of a change set are, of each group, the findings of the check of the workspace after the
459
+ first `<base count>` in finding order, in the order of [findings](#findings).
460
+
461
+ > Note (non-normative): a finding on an edited line is compared with the base findings of the
462
+ > lines that edit replaced. A line moved across an unchanged line leaves its region, so its
463
+ > findings are introduced, as is a finding whose message names a moved document's path.
464
+
465
+ The label occurrences in changed lines of a change set are the occurrences of kind `label` or
466
+ `form` (a form counting as its entry's label) in a document at a change's `path` that start on a
467
+ changed line. Each is the entry's
468
+ `id`, `label`, and `meaning`, the document's path, the occurrence's line and column, and its
469
+ source text normalised ([phrases](#phrases)). They are ordered by `id`, then path, line, and column;
470
+ suppression comments do not change them.
471
+
472
+ ## 6. Operations {#operations}
473
+
474
+ ### 6.1 Common rules {#common-rules}
475
+
476
+ An operation is one of `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown`, and
477
+ `import`. It takes the terms file's bytes, absent when there is no terms file, the documents, the
478
+ date as a calendar date of [ISO 8601], and its parameters, and gives either a refusal text or the
479
+ new terms file text, in canonical form ([canonical form](#canonical-form)), together with an edit
480
+ list. An operation MUST NOT remove an entry, change an `id`, or change any entry other than those
481
+ its section names. It MUST append, to each entry it changes, one history item with the given date,
482
+ the operation's name as `op`, and the operands of [history items](#history-items). Every string
483
+ parameter other than `owner` and `path`, and every string of a list parameter, is normalised
484
+ ([phrases](#phrases)) before use; `owner` and `path` are used with leading and trailing white space
485
+ removed.
486
+
487
+ An operation MUST refuse, with the text of the first that applies, when:
488
+
489
+ 1. the terms file is absent and the operation is neither `add` nor `import`:
490
+ `no terms file at .pi/pi-dent/terms.yaml`;
491
+ 2. the terms file gives a T001 finding:
492
+ `.pi/pi-dent/terms.yaml has T001 findings; fix them first: <finding text>`, with the first
493
+ such finding;
494
+ 3. an id `<x>` of a parameter that the operation's section says names an active entry, taken in
495
+ parameter order and then list order, is no entry's `id`: `no entry <x>`, or names a
496
+ deprecated entry: `<x> is deprecated`; then a refusal of the operation's own section, in the
497
+ order listed there;
498
+ 4. the new terms file gives a T001, T002, T003, or T004 finding that concerns ([file
499
+ checks](#file-checks)) an entry the operation changed: `<operation> refused: <finding text>`,
500
+ with the first such finding.
501
+
502
+ The edit list holds the occurrences that the operation's section names, in the new terms
503
+ file's matching, ordered by path, line, and column, without an occurrence of kind `reject` that
504
+ a valid P001 suppression comment suppresses or one of kind `deprecated` that a valid P002
505
+ suppression comment suppresses. Each item is the occurrence's path, line, column, source text as
506
+ `old`, and a suggested text as `new`, or none:
507
+
508
+ - for an occurrence of kind `reject` of entry `E`, the label of `E`;
509
+ - for an occurrence of kind `deprecated` whose entry has exactly one replacement, that
510
+ replacement is an entry, and whose variant did not come from a `forms` phrase, its label;
511
+ - for any other occurrence, and for one whose variant came from a `forms` phrase, none.
512
+
513
+ A suggested label is turned into its plural when the occurrence's variant is plural, none being
514
+ suggested when it has no plural, and then into its capitalised variant when the occurrence's
515
+ variant is capitalised and the label has one. An operation MUST NOT change a document.
516
+
517
+ ### 6.2 `add` {#add}
518
+
519
+ Parameters: `id`, `label`, `meaning`, `owner`, `group`, `key`, and optionally `reject`,
520
+ `distinguish`, and `forms`. Refusal: `<id> is already an entry` when an entry has the `id`.
521
+ When the terms file is absent, the input is a terms file without settings and entries. The
522
+ operation inserts an active entry with these fields at its place in `id` order. The edit list
523
+ holds the occurrences of kind `reject` of the new entry.
524
+
525
+ ### 6.3 `rename` {#rename}
526
+
527
+ Parameters: `id`, naming an active entry, `label`, and optionally `forms`. Refusal: `<id> is already
528
+ labelled "<label>"` when `label` equals the entry's label after normalisation. The operation appends
529
+ the old label, then each old `forms` phrase, to the entry's `reject`, leaving out a phrase already
530
+ there, the new label, and each phrase of the new `forms`; removes the new label and each phrase of
531
+ the new `forms` from `reject`; sets `label`; and sets `forms` to the parameter, or removes it when
532
+ the parameter is absent; phrases are compared normalised. The edit list holds the occurrences of
533
+ kind `reject` of the entry whose variant came from a phrase this operation appended; one whose
534
+ phrase was an old `forms` phrase has no suggested text. The old label is the entry's `label` as
535
+ written, not normalised: the phrase it appends to `reject`, the `from` operand of its history item,
536
+ and the old label of the summary are that text.
537
+
538
+ ### 6.4 `merge` {#merge}
539
+
540
+ Parameters: `id` and `into`, each naming an active entry. Refusal:
541
+ `cannot merge <id> into itself` when they are equal. The operation sets the entry `id` to
542
+ `status` `deprecated`, `reason` `merged`, and `replacedBy` `[into]`; appends its `reject`
543
+ phrases to the `reject` of `into`, leaving out a phrase already there; and removes `reject` from
544
+ `id`. The
545
+ history item on `id` has the operand `into`, the one on `into` the operand `from`. The edit list
546
+ holds the occurrences of kind `deprecated` of `id` and of kind `reject` of `into` whose variant
547
+ came from a phrase this operation moved.
548
+
549
+ ### 6.5 `split` {#split}
550
+
551
+ Parameters: `id`, naming an active entry, and `into`, a list of ids, each naming an active entry.
552
+ The operation sets the entry `id` to `status` `deprecated`, `reason` `split`, and `replacedBy` the
553
+ list. The history item on `id` has the operand `into`, the one on each listed entry the operand
554
+ `from`; a list of fewer than two ids, or one naming `id`, gives the finding of refusal 4 of [common
555
+ rules](#common-rules). The edit list holds the occurrences of kind `deprecated` of `id`; none has a
556
+ suggested text.
557
+
558
+ ### 6.6 `deprecate` {#deprecate}
559
+
560
+ Parameters: `id`, naming an active entry, `reason`, either `renamed` or `out-of-scope`, and
561
+ optionally `replacedBy`, a list of ids, each naming an active entry. The operation sets the entry to
562
+ `status` `deprecated` with the `reason` and, when given, the `replacedBy`. With exactly one
563
+ replacement, it also moves the entry's `reject` phrases to the replacement as `merge` does, and
564
+ appends a history item with the operand `from` to the replacement. A replacement count the reason
565
+ does not admit gives the finding of refusal 4 of [common rules](#common-rules). The edit list holds
566
+ the occurrences of kind `deprecated` of `id` and of kind `reject` of the replacement whose variant
567
+ came from a phrase this operation moved.
568
+
569
+ ### 6.7 `reown` {#reown}
570
+
571
+ Parameters: `id`, naming an active entry, and `owner`. Refusal:
572
+ `<id> is already owned by <owner>` when `owner` equals the entry's `owner`. The operation sets
573
+ `owner`. The edit list is empty.
574
+
575
+ ### 6.8 `import` {#import}
576
+
577
+ `import` builds the entries of an empty terms file from a thesaurus table of one document.
578
+ Parameter: `path`. Refusals, in order:
579
+
580
+ 1. `import needs a terms file without entries; .pi/pi-dent/terms.yaml has <n>` when the terms
581
+ file has at least one entry;
582
+ 2. `<path> is not a document` when `path` is not a document;
583
+ 3. `<path> has no thesaurus table` when the document has no thesaurus table;
584
+ 4. `<path>:<line>: <problem>` for the first row, in document order, that has a problem of this
585
+ list, with the row's line and the first of its problems in list order: `the Term cell is
586
+ empty`, `the label gives no id`, `no heading precedes the table`, `the Owner cell gives no
587
+ owner path`.
588
+
589
+ A thesaurus table is a table of the document whose header cells, as cell texts, are exactly `Term`,
590
+ `Meaning`, `Owner`, and `Avoid or distinguish`, in this order. The cell text of a cell is its inline
591
+ content as plain text, normalised: the characters a prose run gets ([prose runs](#prose-runs)), with
592
+ the content of a code span and the description of an image in place of their barriers and raw HTML
593
+ and autolinks contributing nothing. Each body row of every thesaurus table, in document order, gives
594
+ one active entry, the entries placed in ascending `id` order:
595
+
596
+ | Field | Value |
597
+ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
598
+ | `label` | The Term cell text. |
599
+ | `id` | The label in ECMAScript lower case, each maximal run of characters other than `a`–`z` and `0`–`9` replaced by `-`, leading and trailing `-` removed; when an earlier row gave the same id, `-<n>` appended with the smallest `n` from 2 that gives a new id. |
600
+ | `meaning` | The Meaning cell text. |
601
+ | `owner` | The row's owner path. |
602
+ | `group` | The heading text, as plain text like a cell text, of the last heading before the table. |
603
+ | `key` | Derived by the rule below. |
604
+ | `distinguish` | The id of each other row whose label equals an item of the row, without repeats, in item order. |
605
+ | `history` | One item with `op` `import` and the operand `from` set to `path`. |
606
+
607
+ The operation MUST set an imported entry's `key` to `local` when its owner is a workspace
608
+ document and the set of workspace documents that use the entry ([uses](#uses)), computed in the
609
+ proposed file's matching, is exactly that owner; else to `confusable` when that set holds exactly
610
+ one document; otherwise to `shared`. An external owner never gives `local`, and is not a use. The
611
+ operation also gives the ids assigned `local`,
612
+ in ascending `id` order, an empty list when none qualify.
613
+
614
+ The owner path of a row is the destination of the first link other than an autolink in its Owner
615
+ cell, else the Owner cell text, without the part from its first `#`, joined with `/` to the
616
+ directory of `path`, or alone when that directory is the workspace root, then with each `.` segment
617
+ removed and each `..` segment removed together with the segment before it when that preceding
618
+ segment is not `..`; leading `..` segments are retained. The Owner cell gives no owner path when
619
+ that destination or text, before the join, is empty, starts with `/`, or holds a `:` before its
620
+ first `/` (or has no `/`); or when the resulting path is not an owner path
621
+ ([documents](#documents)). For example, from `docs/research/README.md`,
622
+ `../../specs/terms.md#entries` gives the owner `specs/terms.md`; from `specs/terms.md`,
623
+ `../../elsewhere/notes.md#finding` gives the external owner `../elsewhere/notes.md`, retaining its
624
+ leading `../`.
625
+
626
+ The items of a row are the parts of its Avoid or distinguish cell text split at `;`, each
627
+ normalised, empty parts left out. Every item that does not give a `distinguish` id is a reject
628
+ candidate of the row's entry. The operation keeps the input's `settings`. Its edit list is empty;
629
+ it also gives its reject candidates as pairs of entry id and item, in row order and then item
630
+ order.
631
+
632
+ > Note (non-normative): whether an item names a specific phrase or an ordinary word is a
633
+ > judgement; the candidates are returned for the agent to add with `update`'s `addReject` or drop.
634
+
635
+ ### 6.9 `update` {#update}
636
+
637
+ Parameters: `id`, naming an active entry, or any entry when `status` is given, and optionally
638
+ `status`, `key`, `meaning`, `addReject`, `removeReject`, `addDistinguish`, and `removeDistinguish`.
639
+ `status` takes the one value `active`; `key` takes the values of [entries](#entries); `meaning` is a
640
+ string, normalised ([common rules](#common-rules)) and compared with the stored meaning as written;
641
+ the other parameters are string arrays, empty when absent. Reject operands are phrases and
642
+ distinguish operands are ids; they are compared after [phrases](#phrases) normalisation, including
643
+ against stored strings. An unchanged `status`, `key`, or `meaning` is allowed alongside another
644
+ effective change. Empty arrays do nothing.
645
+
646
+ After refusals 1 to 3 of [common rules](#common-rules), the operation MUST refuse in this order
647
+ (lists are scanned in their input order). In these texts `<field>` is the parameter name, `<other>`
648
+ is the distinguish operand, and `"<value>"` and `"<phrase>"` are the normalised operand as
649
+ ECMAScript `JSON.stringify` writes it:
650
+
651
+ 1. For each list in parameter order `addReject`, `removeReject`, `addDistinguish`,
652
+ `removeDistinguish`, a repeated normalised value: `<field> repeats "<value>"`.
653
+ 2. A value in both reject lists, in `addReject` order:
654
+ `update cannot add and remove reject "<phrase>"`; then a value in both distinguish lists,
655
+ in `addDistinguish` order: `update cannot add and remove distinguish <other>`.
656
+ 3. A `removeReject` phrase absent from the entry's `reject`:
657
+ `<id> does not reject "<phrase>"`; then an `addReject` phrase already present:
658
+ `<id> already rejects "<phrase>"`.
659
+ 4. For each id in `addDistinguish`, then `removeDistinguish`, an unknown id:
660
+ `no entry <other>`; or the entry's own id:
661
+ `cannot distinguish <id> from itself`. A distinguish target can be active or deprecated.
662
+ 5. A `removeDistinguish` id not in the distinguish relation with `id`:
663
+ `<id> is not distinguished from <other>`; then an `addDistinguish` id already in that
664
+ relation: `<id> is already distinguished from <other>`. Presence on either side counts.
665
+ 6. No effective change (all list parameters are empty, and `status`, `key`, and `meaning` are
666
+ each absent or unchanged):
667
+ `update makes no changes to <id>`.
668
+
669
+ When `status` is given and the entry is deprecated, the operation sets its `status` to `active` and
670
+ removes its `reason` and `replacedBy`; phrases an earlier operation moved from its `reject` are not
671
+ moved back. The operation sets `key` and `meaning` when given, removes the `removeReject` phrases,
672
+ and appends `addReject` phrases in input order. It removes each `removeDistinguish` relation from
673
+ both entries' lists and adds each `addDistinguish` relation to both entries' lists, appending in
674
+ input order. It preserves the order and spelling of all retained list items. It changes only the
675
+ entry named by `id` and entries named by distinguish operands. An entry is changed when its stored
676
+ `status`, `key`, `meaning`, `reject`, or `distinguish` changes, before adding history. Each such
677
+ entry gets exactly one `update` history item: with the operand `meaning`, the stored meaning before
678
+ the operation as written, when its meaning changed, and the operand `status`, `deprecated`, when its
679
+ status changed; otherwise with no operands, including an entry changed only by a reciprocal
680
+ distinguish edit. Removing a relation stored only on the other entry changes only that other entry;
681
+ it does not append history to an unchanged entry named by `id`.
682
+
683
+ The proposed file is subject to refusal 4 of [common rules](#common-rules), after the refusals above;
684
+ failure writes nothing and gives no edit list. The edit list holds the occurrences of kind `reject`
685
+ of `id` whose variant came from a phrase in `addReject`, using the new file's matching.
686
+
687
+ For example, `update` with `id: rendered-view`, `key: local`, and
688
+ `addReject: [rendering-view]` changes the key and appends that reject phrase, records one
689
+ history item with `op: update`, and lists matching prose occurrences of
690
+ `rendering-view`, not code spans. An update containing only the already-current key is refused.
691
+ An `update` of `rendered-view` with a new `meaning` sets it and records one `update` history
692
+ item whose `meaning` is the old text.
693
+
694
+ > Note (non-normative): a changed meaning keeps the label, for a concept that widens or is
695
+ > described better. A concept that becomes a different one is a `split` or a `deprecate`.
696
+
697
+ ## 7. Normative references {#normative-references}
698
+
699
+ - [CommonMark] CommonMark Spec, version 0.31.2 (2024-01-28), J. MacFarlane: Section 2.1
700
+ (characters and lines), Section 4 (leaf blocks), Section 5 (container blocks), and Section 6
701
+ (inlines).
702
+ - [GFM] GitHub Flavored Markdown Spec, version 0.29-gfm (2019-04-06): Section 4.10 (tables
703
+ extension).
704
+ - [YAML 1.2.2] YAML Ain't Markup Language, version 1.2.2 (2021-10-01): the syntax of the terms
705
+ file, Section 5.1 (character set), and Section 10.3 (core schema).
706
+ - [Unicode] The Unicode Standard, Version 15.1.0: Section 4.5 (General Category) and Section 4.6
707
+ with Unicode Standard Annex #44 (the White_Space property).
708
+ - [ECMA-262] ECMAScript Language Specification, 14th edition (June 2023), Ecma International:
709
+ regular expressions, `String.prototype.toLowerCase`, `String.prototype.toUpperCase`, and
710
+ `JSON.stringify`.
711
+ - [ISO 8601] ISO 8601-1:2019, Date and time — Representations for information interchange —
712
+ Part 1: Basic rules: the calendar date, complete representation, extended format.
713
+
714
+ ## 8. Specification gaps {#specification-gaps}
715
+
716
+ - Whether a `reject` phrase is a specific phrase or an ordinary word, whether a `label` is in
717
+ base form, and whether a `meaning` is one sentence are not checked.
718
+ - An `id` removed from the terms file by hand cannot be told from one never used, so its reuse
719
+ is not detected.
720
+ - No operation removes or rewrites a history item, and a hand edit of the terms file is outside
721
+ this specification, so a value a history item records, such as a stale fixture id or a personal
722
+ path, stays in the file. Whether a redact operation, or a rule admitting hand redaction of a
723
+ history item, should cover this is open.
724
+ - Text in another Unicode normalisation form than the phrase it spells does not match it.
725
+ - A hyphen is not a word character: `workspace` is found in `workspace-relative`.
726
+ - A label written in upper case throughout, as in a heading set in capitals, is not found; nor is
727
+ a sentence-initial capitalised word attributed to a lowercase label when an active entry's
728
+ label, or a reject phrase, is that capitalised word.
729
+ - The plural rules derive wrong plurals for some words; only `forms` adds the right ones.
730
+ - A suggested text replaces the whole source text of an occurrence, emphasis delimiters and
731
+ line breaks inside it included.
732
+ - A `terms-ignore` comment inside an HTML block holding more than the comment is neither a
733
+ suppression comment nor a finding.
734
+ - Which line and column a YAML parser reports for a syntax error, and its message, are not
735
+ specified.
736
+ - A change to an external owner file cannot be expressed in a change set: the base workspace
737
+ has the workspace's external owner texts.
738
+ - A file copied with `from` while its source stays shares its source's base findings: of each
739
+ group only the findings past the base count are introduced, chosen in finding order, so one of
740
+ the two copies of an old finding is reported; a copy written as a change without `from` gives
741
+ each its own.
742
+ - A file moved to a new path while a new file takes its old path cannot be written as a move: the
743
+ base paths repeat. Writing both as changes without `from` expresses it.
744
+ - The `reject` phrases of an entry deprecated by `split` or with `reason` `out-of-scope` give no
745
+ variant, so they are no longer reported.
746
+ - A plural or capitalised variant of one entry that spells a variant of another entry is not
747
+ reported.
748
+ - A file `git ls-files` lists but that cannot be read, or is not UTF-8, is not a document and is
749
+ not reported.
750
+ - The version of Git whose `ls-files` and `rev-parse` behaviour [workspace](#workspace) relies on
751
+ is not specified.
752
+ - The names the library exports are not specified.
753
+ - An external owner whose file is missing or unreadable gives no finding, so a wrong external
754
+ owner path is not reported.
755
+ - An external owner path pointing back into the workspace is not recognised as an alias of
756
+ its workspace document path; a `local` entry's use there gives T005.