pi-dent-terms 0.1.0 → 0.1.2
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 +41 -38
- package/index.ts +3 -2
- package/lib/after-edit.ts +8 -8
- package/lib/changes.ts +19 -19
- package/lib/checks.ts +22 -22
- package/lib/config.ts +10 -7
- package/lib/import.ts +8 -7
- package/lib/match.ts +10 -10
- package/lib/operations.ts +30 -30
- package/lib/prose.ts +11 -11
- package/lib/terms-file.ts +22 -20
- package/lib/text.ts +5 -5
- package/lib/tool.ts +48 -40
- package/lib/workspace.ts +10 -9
- package/package.json +3 -2
- package/specs/AGENTS.md +28 -0
- package/specs/terms-tool.md +369 -0
- package/specs/terms.md +756 -0
|
@@ -0,0 +1,369 @@
|
|
|
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 extension MUST register the tool through the host `registerTool` API when it loads, in every
|
|
15
|
+
run mode:
|
|
16
|
+
|
|
17
|
+
| Field | Value |
|
|
18
|
+
| --------------- | ----------------------------------------------------- |
|
|
19
|
+
| `name` | `"Terms"` |
|
|
20
|
+
| `label` | `"Terms"` |
|
|
21
|
+
| `description` | The text of [model-facing texts](#model-facing-texts) |
|
|
22
|
+
| `promptSnippet` | The text of [model-facing texts](#model-facing-texts) |
|
|
23
|
+
| `parameters` | The [parameter schema](#parameter-schema) |
|
|
24
|
+
| `executionMode` | `"sequential"` |
|
|
25
|
+
| `renderShell` | not set: the host's default tool shell |
|
|
26
|
+
|
|
27
|
+
`executionMode` `"sequential"` makes the host run a `Terms` call alone, never concurrently with
|
|
28
|
+
another tool call. `renderCall` and `renderResult` are not set. Every rejection this
|
|
29
|
+
specification gives is a tool error (`isError: true`) whose content is its error text alone,
|
|
30
|
+
with no `details`.
|
|
31
|
+
|
|
32
|
+
### 1.1 Parameter schema {#parameter-schema}
|
|
33
|
+
|
|
34
|
+
The parameter schema is a JSON object schema with `type: "object"` and
|
|
35
|
+
`additionalProperties: false`, with one required field, `action`; every other field is optional
|
|
36
|
+
in the schema and admits `null` beside the type in the table, and each action accepts only its
|
|
37
|
+
fields below. A field whose value is `null` counts as absent.
|
|
38
|
+
|
|
39
|
+
| Field | Type | Actions | Contract |
|
|
40
|
+
| ------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
41
|
+
| `action` | `"find" \| "check" \| "add" \| "update" \| "rename" \| "merge" \| "split" \| "deprecate" \| "reown" \| "import"` | all | The action ([actions](#actions)). |
|
|
42
|
+
| `query` | string? \| null | `find` | The text looked up ([`find`](#find)). |
|
|
43
|
+
| `id` | string? \| null | `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown` | Required. The entry the operation acts on. |
|
|
44
|
+
| `label` | string? \| null | `add`, `rename` | Required. The label. |
|
|
45
|
+
| `meaning` | string? \| null | `add`, `update` | Required for `add`, optional for `update`. The meaning. |
|
|
46
|
+
| `owner` | string? \| null | `find`, `add`, `reown` | Required for `add` and `reown`. The owner path ([terms.md, documents](terms.md#documents)). |
|
|
47
|
+
| `group` | string? \| null | `find`, `add` | Required for `add`. The group. |
|
|
48
|
+
| `key` | `"shared" \| "confusable" \| "local"`? \| null | `find`, `add`, `update` | Required for `add`. The key. |
|
|
49
|
+
| `status` | `"active" \| "deprecated"`? \| null | `find`, `update` | The status; for `update`, `active` only. |
|
|
50
|
+
| `reject` | string[]? \| null | `add` | The reject phrases. |
|
|
51
|
+
| `distinguish` | string[]? \| null | `add` | The ids to distinguish. |
|
|
52
|
+
| `addReject` | string[]? \| null | `update` | Reject phrases to add. |
|
|
53
|
+
| `removeReject` | string[]? \| null | `update` | Reject phrases to remove. |
|
|
54
|
+
| `addDistinguish` | string[]? \| null | `update` | Distinguish ids to add symmetrically. |
|
|
55
|
+
| `removeDistinguish` | string[]? \| null | `update` | Distinguish ids to remove symmetrically. |
|
|
56
|
+
| `forms` | string[]? \| null | `add`, `rename` | The irregular forms of the label. |
|
|
57
|
+
| `into` | string[]? \| null | `merge`, `split` | Required. The ids merged or split into. |
|
|
58
|
+
| `reason` | `"renamed" \| "out-of-scope"`? \| null | `deprecate` | Required. The reason. |
|
|
59
|
+
| `replacedBy` | string[]? \| null | `deprecate` | The replacements. |
|
|
60
|
+
| `path` | string? \| null | `import` | Required. The workspace path of the document holding the table. |
|
|
61
|
+
| `changes` | object[]? \| null | `check` | The change set ([terms.md, change checks](terms.md#change-checks)). |
|
|
62
|
+
|
|
63
|
+
Each item of `changes` is an object schema with `additionalProperties: false`, the required fields
|
|
64
|
+
`path` (string) and `before` (string or `null`), and the optional field `from` (string or `null`,
|
|
65
|
+
`null` counting as absent). The schema constrains the types of the table and of these items, the
|
|
66
|
+
values of `action`, `key`, and `reason`, and the set of admitted properties, and nothing else. Each
|
|
67
|
+
field other than `changes` maps to the operation parameter of the same name ([terms.md,
|
|
68
|
+
operations](terms.md#operations)); `merge` passes the one id of `into` as its `into`.
|
|
69
|
+
|
|
70
|
+
### 1.2 Validation {#validation}
|
|
71
|
+
|
|
72
|
+
Execution-time validation MUST reject the call with the error text of the first failing check,
|
|
73
|
+
in this order, before any file is read:
|
|
74
|
+
|
|
75
|
+
| # | Check | Error text |
|
|
76
|
+
| --- | -------------------------------------------------------------------------------------------------------- | ------------------------------------------------ |
|
|
77
|
+
| 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>` |
|
|
78
|
+
| 2 | A required field of the action is absent (first such field in table order) | `action <action> requires <field>` |
|
|
79
|
+
| 3 | A string field is empty after trimming (first such field in table order) | `<field> must be a non-empty string` |
|
|
80
|
+
| 4 | A list field holds an item that is empty after trimming (first such field in table order) | `<field> must hold non-empty strings` |
|
|
81
|
+
| 5 | `merge`: `into` does not hold exactly one item | `merge takes exactly one id in into` |
|
|
82
|
+
| 6 | `find`: none of `query`, `status`, `key`, `group`, and `owner` is present | `action find requires query or a filter` |
|
|
83
|
+
| 7 | `update`: `status` is `deprecated` | `update takes status active only; use deprecate` |
|
|
84
|
+
| 8 | `changes`: the change set is not valid ([terms.md, change checks](terms.md#change-checks)) | see below |
|
|
85
|
+
|
|
86
|
+
Trimming removes leading and trailing white space ([terms.md, phrases](terms.md#phrases)). Every
|
|
87
|
+
string, and every item of a list, is used trimmed, except `before`, which is used as given.
|
|
88
|
+
|
|
89
|
+
For check 8, the items of `changes` are examined in order; for each item, its `path`, then its
|
|
90
|
+
`from` when set, then the item as a whole, each against the conditions of [terms.md, change
|
|
91
|
+
checks](terms.md#change-checks), in their order. The first failure gives its text, `<i>` being the
|
|
92
|
+
item's position from 0:
|
|
93
|
+
|
|
94
|
+
| Condition | Error text |
|
|
95
|
+
| --------- | ----------------------------------------------------------------------------------------- |
|
|
96
|
+
| 1 | `changes[<i>].<field> must be .pi/pi-dent/terms.yaml or a workspace path ending with .md` |
|
|
97
|
+
| 2 | `changes[<i>].from must be .pi/pi-dent/terms.yaml exactly when path is` |
|
|
98
|
+
| 3 | `changes[<i>].from needs a before text` |
|
|
99
|
+
| 4 | `changes[<i>].before holds a lone surrogate` |
|
|
100
|
+
| 5 | `changes[<i>].path repeats "<path>"` |
|
|
101
|
+
| 6 | `changes[<i>].<field> repeats the base path "<p>"` |
|
|
102
|
+
|
|
103
|
+
Condition 1 applies to each field examined, condition 2 to `from`; conditions 3 to 6 to the item
|
|
104
|
+
as a whole,
|
|
105
|
+
condition 6 naming `from` when it is set, else `path`, `<p>` being the base path.
|
|
106
|
+
|
|
107
|
+
### 1.3 Model-facing texts {#model-facing-texts}
|
|
108
|
+
|
|
109
|
+
The texts of this section are what a model reads to choose and fill a call; each MUST be
|
|
110
|
+
registered verbatim, and none cites a specification.
|
|
111
|
+
|
|
112
|
+
The `description` is
|
|
113
|
+
|
|
114
|
+
```text
|
|
115
|
+
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.
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The `promptSnippet` is
|
|
119
|
+
|
|
120
|
+
```text
|
|
121
|
+
Look up, check, and change the workspace's thesaurus of terms
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Each property of the parameter schema carries this `description`:
|
|
125
|
+
|
|
126
|
+
| Field | `description` |
|
|
127
|
+
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
128
|
+
| `action` | `find: look entries up. check: report findings. add, update, rename, merge, split, deprecate, reown, import: change the terms file.` |
|
|
129
|
+
| `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.` |
|
|
130
|
+
| `id` | `The entry's id, a lowercase slug such as "rendered-view"; for add, the new id.` |
|
|
131
|
+
| `label` | `For add and rename: the one preferred term, in base form, lowercase unless a name.` |
|
|
132
|
+
| `meaning` | `For add (required) or update (optional): one sentence saying what the concept is.` |
|
|
133
|
+
| `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.` |
|
|
134
|
+
| `group` | `For add: the group the entry is listed under. For find: list only entries in this group.` |
|
|
135
|
+
| `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.` |
|
|
136
|
+
| `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.` |
|
|
137
|
+
| `reject` | `For add: specific phrases that must not be used for this concept; never ordinary words.` |
|
|
138
|
+
| `distinguish` | `For add: ids of neighbouring concepts a reader could confuse with this one.` |
|
|
139
|
+
| `addReject` | `For update: specific reject phrases to add; already-present phrases are refused.` |
|
|
140
|
+
| `removeReject` | `For update: reject phrases to remove; missing phrases are refused.` |
|
|
141
|
+
| `addDistinguish` | `For update: existing ids to distinguish from, on both entries; self and existing relations are refused.` |
|
|
142
|
+
| `removeDistinguish` | `For update: ids to stop distinguishing from, on both entries; missing relations are refused.` |
|
|
143
|
+
| `forms` | `For add and rename: irregular inflections of the label only; regular plurals are derived.` |
|
|
144
|
+
| `into` | `For merge: the one id that absorbs the entry. For split: the two or more ids that replace it; add them first.` |
|
|
145
|
+
| `reason` | `For deprecate: renamed (with one replacedBy) or out-of-scope (with none).` |
|
|
146
|
+
| `replacedBy` | `For deprecate: the id of the entry that replaces it.` |
|
|
147
|
+
| `path` | `For import: the workspace-relative path of the Markdown thesaurus.` |
|
|
148
|
+
| `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.` |
|
|
149
|
+
|
|
150
|
+
## 2. Workspace access {#workspace-access}
|
|
151
|
+
|
|
152
|
+
The workspace of a call or an event is that of the workspace root ([terms.md, workspace
|
|
153
|
+
root](terms.md#workspace-root)) of the invoking session's working directory. Each call reads the
|
|
154
|
+
terms file anew and, unless its action is `find`, lists and reads the documents anew. A call MUST be
|
|
155
|
+
rejected, the first failure reported, with:
|
|
156
|
+
|
|
157
|
+
| Failure | Error text |
|
|
158
|
+
| ------------------------------------------------------------------------------------------------- | -------------------------------------------- |
|
|
159
|
+
| The working directory has no workspace root | `<cwd> is not inside a Git working tree` |
|
|
160
|
+
| Git cannot be run, or a Git command of [terms.md, workspace](terms.md#workspace), fails otherwise | `git failed: <message>` |
|
|
161
|
+
| The terms file exists and cannot be read | `cannot read .pi/pi-dent/terms.yaml: <code>` |
|
|
162
|
+
| `find` or `check`, and there is no terms file | `no terms file at .pi/pi-dent/terms.yaml` |
|
|
163
|
+
|
|
164
|
+
`<cwd>` is the working directory; `<message>` is the first line of what Git wrote to its error
|
|
165
|
+
output, else the system's error message; `<code>` is the error code the file system reports
|
|
166
|
+
(such as `EISDIR`), else its message. A `git rev-parse --show-toplevel` run that exits with a
|
|
167
|
+
failure status is the first row; a Git that cannot be started is the second. A terms file whose
|
|
168
|
+
path gives `ENOENT` or `ENOTDIR` is absent.
|
|
169
|
+
|
|
170
|
+
For `check`, the extension MUST separately supply the external owner texts of [terms.md,
|
|
171
|
+
documents](terms.md#documents), for every active entry not left out under [terms.md,
|
|
172
|
+
entries](terms.md#entries). Paths are resolved against the workspace root. File type is tested on
|
|
173
|
+
the final path component without following a symbolic link there; symbolic links in parent
|
|
174
|
+
directories are followed. The extension MUST skip missing, unreadable, non-regular, non-UTF-8, or
|
|
175
|
+
U+0000-containing external owner files without an error.
|
|
176
|
+
|
|
177
|
+
The extension MUST NOT read a file or run Git to derive a change set: `changes` is used as given. An
|
|
178
|
+
operation's date is the current calendar date in the local time zone of the process. A refusal of an
|
|
179
|
+
operation ([terms.md, common rules](terms.md#common-rules)) is a tool error with the refusal text.
|
|
180
|
+
Otherwise the extension MUST write the new terms file text to `.pi/pi-dent/terms.yaml`, creating
|
|
181
|
+
`.pi/` and `.pi/pi-dent/` when they are absent. It MUST write the text to a new file in the
|
|
182
|
+
directory of the terms file's target and rename that file over the target, so that a failed write
|
|
183
|
+
leaves the previous terms file unchanged and removes the new file. It MUST NOT write any other file,
|
|
184
|
+
including a `.gitignore` in `.pi/pi-dent/`; a failed write is a tool error `cannot write
|
|
185
|
+
.pi/pi-dent/terms.yaml: <code>`. The target is the file a symbolic link at `.pi/pi-dent/terms.yaml`
|
|
186
|
+
resolves to, else `.pi/pi-dent/terms.yaml`.
|
|
187
|
+
|
|
188
|
+
When a call's abort signal fires while a Git command of the call runs, the extension MUST end that
|
|
189
|
+
Git process; the call is then rejected as a Git failure (`git failed: <message>`).
|
|
190
|
+
|
|
191
|
+
## 3. Actions {#actions}
|
|
192
|
+
|
|
193
|
+
A result's content is one text block holding its result text. In a result text, `"<x>"` is the
|
|
194
|
+
value as ECMAScript `JSON.stringify` writes it ([ECMA-262]), lines are joined by one line feed,
|
|
195
|
+
and the words `entries`, `findings`, `documents`, `occurrences`, `candidates`, and `changes` stay
|
|
196
|
+
plural
|
|
197
|
+
whatever the number. `isError` is unset on every result of this section.
|
|
198
|
+
|
|
199
|
+
### 3.1 `find` {#find}
|
|
200
|
+
|
|
201
|
+
`<query>` is `query` normalised ([terms.md, phrases](terms.md#phrases)). The filters are `status`,
|
|
202
|
+
`key`, `group`, and `owner`, each when present. An entry matches when each of these that is
|
|
203
|
+
present holds:
|
|
204
|
+
|
|
205
|
+
- `<query>`, in ECMAScript lower case ([ECMA-262]), is a substring of its `id`, its `label`, one
|
|
206
|
+
of its `reject` or `forms` phrases, or its `meaning`, each normalised and in ECMAScript lower
|
|
207
|
+
case;
|
|
208
|
+
- its `status` equals `status`, and its `key` equals `key`;
|
|
209
|
+
- its `group`, normalised, equals `group` normalised;
|
|
210
|
+
- its `owner` equals `owner`.
|
|
211
|
+
|
|
212
|
+
Entries left out under [terms.md, entries](terms.md#entries), are not searched. Matching entries are
|
|
213
|
+
listed in ascending `id` order; with `query`, those whose normalised lower-case label equals the
|
|
214
|
+
lower-case `<query>` come first, then the others, each part in ascending `id` order.
|
|
215
|
+
|
|
216
|
+
`<search>` is, joined by `, `, each of these whose parameter is present, in this order:
|
|
217
|
+
`"<query>"`, `status <status>`, `key <key>`, `group "<group>"`, and `owner <owner>`, the group
|
|
218
|
+
normalised. With no match the text is `No entry matches <search>`. Otherwise it is the line
|
|
219
|
+
`<n> entries match <search>:`, then for each matching entry the line
|
|
220
|
+
`<id> "<label>" · <status> · <key> · <group> · owner <owner>`, followed by these lines, each
|
|
221
|
+
present only when its list is not empty or its field is set, indented by two spaces:
|
|
222
|
+
|
|
223
|
+
1. `meaning: <meaning>`;
|
|
224
|
+
2. `reject: ` and the `reject` phrases as `"<p>"`, joined by `, `;
|
|
225
|
+
3. `forms: ` and the `forms` phrases, written the same way;
|
|
226
|
+
4. `distinguish: ` and each entry in the distinguish relation with it, in ascending `id`
|
|
227
|
+
order, as `<id> "<label>"`, or `<id> (not an entry)` for a listed id that names no entry left
|
|
228
|
+
in under [terms.md, entries](terms.md#entries), joined by `, `;
|
|
229
|
+
5. `replacedBy: ` and each replacement as on line 4, joined by `, `;
|
|
230
|
+
6. `reason: <reason>`.
|
|
231
|
+
|
|
232
|
+
When the terms file gives T001 findings, the line `.pi/pi-dent/terms.yaml has <k> T001 findings;
|
|
233
|
+
run check` ends the text, with or without a match. `details` is `{ action: "find", ids: [<id>…] }`,
|
|
234
|
+
the matching ids in listed order.
|
|
235
|
+
|
|
236
|
+
### 3.2 `check` {#check}
|
|
237
|
+
|
|
238
|
+
The text is the line `<n> findings · <d> documents · <e> entries`, then the text of each finding of
|
|
239
|
+
the check of the workspace ([terms.md, findings](terms.md#findings)), in order, one per line. `<d>`
|
|
240
|
+
is the number of documents and `<e>` the number of items of `terms`, `0` when `terms` is not a
|
|
241
|
+
sequence. `details` is `{ action: "check", findings: [{ path, line, column, code, message }…] }` in
|
|
242
|
+
the same order.
|
|
243
|
+
|
|
244
|
+
With `changes`, the findings are the introduced findings of the change set ([terms.md, change
|
|
245
|
+
checks](terms.md#change-checks)), and the first line is `<n> findings introduced · <c> changes · <d>
|
|
246
|
+
documents · <e> entries`, `<c>` being the number of items of `changes`. When there is at least one
|
|
247
|
+
label occurrence in changed lines, the finding lines are followed by an empty line, the line `<u>
|
|
248
|
+
label occurrences in changed lines; confirm each means its entry:`, `<u>` being their number, and
|
|
249
|
+
for each entry with one, in ascending `id` order, the line `<id> "<label>": <meaning>`, label and
|
|
250
|
+
meaning as the terms file holds them, then one line per label occurrence of it, in order, `
|
|
251
|
+
<path>:<line>:<column> "<text>"`, indented by two spaces, `<text>` being its normalised source text.
|
|
252
|
+
`details` also holds `occurrences: [{ id, path, line, column, text }…]`, in the same order.
|
|
253
|
+
|
|
254
|
+
### 3.3 Operations {#operations}
|
|
255
|
+
|
|
256
|
+
The actions `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown`, and `import` run the
|
|
257
|
+
operation of the same name ([terms.md, operations](terms.md#operations), including `update` in
|
|
258
|
+
[terms.md, `update`](terms.md#update)). The text is the summary line, then ` ·
|
|
259
|
+
.pi/pi-dent/terms.yaml written` appended to it, then the edit list block, then, for `import`, the
|
|
260
|
+
candidate block.
|
|
261
|
+
|
|
262
|
+
| Action | Summary line |
|
|
263
|
+
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
264
|
+
| `add` | `Added <id> "<label>"` |
|
|
265
|
+
| `update` | `Updated <id>` |
|
|
266
|
+
| `rename` | `Renamed <id> "<old label>" → "<label>"` |
|
|
267
|
+
| `merge` | `Merged <id> into <into>` |
|
|
268
|
+
| `split` | `Split <id> into <ids>` |
|
|
269
|
+
| `deprecate` | `Deprecated <id> (<reason>)`, followed by ` → <ids>` when `replacedBy` holds one or more ids |
|
|
270
|
+
| `reown` | `Moved the owner of <id> from <old owner> to <owner>` |
|
|
271
|
+
| `import` | `Imported <n> entries from <path>`, followed by `; key local: <ids>` when any ids were assigned `local` per [terms.md, `import`](terms.md#import) |
|
|
272
|
+
|
|
273
|
+
`<ids>` is the list joined by `, `; for `import` it is the local ids in ascending order. The edit
|
|
274
|
+
list block is the line `No occurrences to edit.` when the edit list is empty; otherwise the line
|
|
275
|
+
`<k> occurrences to edit with your edit tool; no document was changed:`, then one line per
|
|
276
|
+
occurrence in edit list order: `<path>:<line>:<column> "<old>" → "<new>"`, or
|
|
277
|
+
`<path>:<line>:<column> "<old>" → no suggestion, rewrite by hand` when the item has no suggested
|
|
278
|
+
text. The candidate block is absent when there is no reject candidate; otherwise the line `<k>
|
|
279
|
+
reject candidates; use update with addReject for specific phrases and drop ordinary words:`, then
|
|
280
|
+
one line `<id>: "<item>"` per candidate in order.
|
|
281
|
+
|
|
282
|
+
For example, an `update` of `rendered-view` with an empty edit list returns:
|
|
283
|
+
|
|
284
|
+
```text
|
|
285
|
+
Updated rendered-view · .pi/pi-dent/terms.yaml written
|
|
286
|
+
No occurrences to edit.
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
`details` is `{ action, edits: [{ path, line, column, old, new }…] }`, `new` being `null` for an
|
|
290
|
+
item without a suggested text; for `import` it also holds `candidates: [{ id, text }…]` and
|
|
291
|
+
`localIds: [<id>…]`, the local ids in ascending order, empty when none qualify.
|
|
292
|
+
|
|
293
|
+
## 4. After-edit check {#after-edit-check}
|
|
294
|
+
|
|
295
|
+
### 4.1 Effective setting {#effective-setting}
|
|
296
|
+
|
|
297
|
+
The after-edit check is off for a workspace without a terms file. Otherwise it is on when the
|
|
298
|
+
terms file's `settings.checkAfterEdit` is `true` and off when it is `false`; when that value is
|
|
299
|
+
absent or counts as absent ([terms.md, root](terms.md#root)), the configuration value of
|
|
300
|
+
[configuration](#configuration) decides, and without one the check is off.
|
|
301
|
+
|
|
302
|
+
### 4.2 Configuration {#configuration}
|
|
303
|
+
|
|
304
|
+
This specification contributes the root key `terms` to pi-dent's configuration file
|
|
305
|
+
(pi-dent-agent `specs/config-file.md`, Section 2):
|
|
306
|
+
|
|
307
|
+
| Key | Type | Contract |
|
|
308
|
+
| ---------------------- | ----------------- | ---------------------------------------------------------------------------------------------- |
|
|
309
|
+
| `terms` | object, optional | The settings of this extension. |
|
|
310
|
+
| `terms.checkAfterEdit` | boolean, optional | The user's default for the after-edit check, used per [effective setting](#effective-setting). |
|
|
311
|
+
|
|
312
|
+
The extension MUST read the configuration as pi-dent-agent `specs/config-file.md`, Sections 1, 2, 3,
|
|
313
|
+
and 7, specify it, once per extension instance (one call of the extension factory), at the
|
|
314
|
+
instance's first `session_start`; a layer that those sections drop is dropped without a diagnostic
|
|
315
|
+
from this extension. A `terms` value that is not an object, or a `checkAfterEdit` value that is not
|
|
316
|
+
a boolean, MUST produce one diagnostic and be ignored; unknown keys of `terms` follow the
|
|
317
|
+
unknown-key rule (pi-dent-agent `specs/config-file.md`, Section 2). The diagnostics are `<file>:
|
|
318
|
+
terms must be an object`, `<file>: terms.checkAfterEdit must be true or false`, and `<file>: terms
|
|
319
|
+
has unknown keys <keys>`, `<keys>` being the unknown keys in ascending order joined by `, `, and
|
|
320
|
+
`<file>` the owning layer's file (pi-dent-agent `specs/config-file.md`, Section 4). Each MUST be
|
|
321
|
+
reported once per extension instance, at that `session_start`, through the host `notify` API at
|
|
322
|
+
level `warning` as `pi-dent-terms: <message>`. Other diagnostics of config-file.md, Sections 1, 2,
|
|
323
|
+
and 7 (layer read, parse, root, substitution) are not reported by this extension.
|
|
324
|
+
|
|
325
|
+
### 4.3 Checking a written document {#checking-a-written-document}
|
|
326
|
+
|
|
327
|
+
The extension MUST handle every `tool_result` event whose tool name is `edit` or `write` and whose
|
|
328
|
+
`isError` is false. Its target is the event input's `path` when it is a string, with one leading `@`
|
|
329
|
+
removed and `~` or a leading `~/` standing for the user's home directory, resolved against the
|
|
330
|
+
invoking session's working directory when relative. The target's directory is resolved through
|
|
331
|
+
symbolic links (realpath) before its workspace path is taken. When the after-edit check is on, read
|
|
332
|
+
at the event, and the target is a document of the workspace, the extension MUST run the prose checks
|
|
333
|
+
of that document ([terms.md, prose checks](terms.md#prose-checks)) on its current text, with the
|
|
334
|
+
findings that valid suppression comments suppress left out. When at least one finding remains, the
|
|
335
|
+
handler MUST return the event's content with one text block appended: `Terms check of <path>: <n>
|
|
336
|
+
findings`, then the text of each finding, one per line, `<path>` being the target's workspace path.
|
|
337
|
+
In every other case, a failure to run Git or read a file included, the handler MUST leave the result
|
|
338
|
+
unchanged.
|
|
339
|
+
|
|
340
|
+
## 5. Normative references {#normative-references}
|
|
341
|
+
|
|
342
|
+
- [ECMA-262] ECMAScript Language Specification, 14th edition (June 2023), Ecma International:
|
|
343
|
+
`String.prototype.toLowerCase` and `JSON.stringify`.
|
|
344
|
+
|
|
345
|
+
## 6. Specification gaps {#specification-gaps}
|
|
346
|
+
|
|
347
|
+
- Whether a child session binds `Terms`, and whether the host fires `tool_result` for a child
|
|
348
|
+
session's `edit` and `write`, is the host's and pi-dent's.
|
|
349
|
+
- A document changed through any tool other than the host's `edit` and `write`, such as pi-dent's
|
|
350
|
+
`Markdown` `edit`, `Bash`, or `Script`, gets no after-edit check.
|
|
351
|
+
- The terms file is written outside the host's file mutation queue; a process that changes it
|
|
352
|
+
between a call's read and its write is overwritten.
|
|
353
|
+
- No bound is set on the number of items of `changes` or the length of a `before` text; the line
|
|
354
|
+
pairing of a change takes time proportional to the product of its two line counts.
|
|
355
|
+
- No bound is set on the length of a result text; how the host shows or cuts a long one is the
|
|
356
|
+
host's.
|
|
357
|
+
- The configuration is read once per extension instance, not once per boot window: a session
|
|
358
|
+
that replaces its predecessor through the host's `new`, `resume`, or `fork` reads it again.
|
|
359
|
+
- File checks are not part of the after-edit check, so a use that an edit adds or removes changes
|
|
360
|
+
the T005 and T006 findings only on the next `check`.
|
|
361
|
+
- The `old` text of an edit list item is often not unique in its document; the line and column
|
|
362
|
+
locate it, but the host's `edit` needs enough surrounding text to be unique.
|
|
363
|
+
- A `git rev-parse --show-toplevel` failure for another reason, such as dubious ownership or a
|
|
364
|
+
corrupt repository, is reported as `<cwd> is not inside a Git working tree`.
|
|
365
|
+
- A symbolic link at `.pi/pi-dent/terms.yaml`, at `.pi/`, or at `.pi/pi-dent/` is followed when the
|
|
366
|
+
terms file is written, so the write can land outside the workspace.
|
|
367
|
+
- `.pi/pi-dent/` may hold a `.gitignore` written by the pi-dent desktop app (pi-dent-app), meant to
|
|
368
|
+
ignore only that app's index files; whether the terms file is committable depends on it. A
|
|
369
|
+
workspace whose own `.gitignore` ignores `.pi/` leaves the terms file untracked.
|