pi-dent-terms 0.1.3 → 0.2.0

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/changes.ts CHANGED
@@ -53,8 +53,8 @@ const LINE_ENDING = /\r\n|\r|\n/;
53
53
  // Validation (specs/terms-tool.md#validation)
54
54
 
55
55
  /** True when `path` is a workspace path (specs/terms.md#workspace-root). */
56
- function isWorkspacePath(path: string): boolean {
57
- if (path === "") {
56
+ export function isWorkspacePath(path: string): boolean {
57
+ if (path === "" || path.includes("\u0000")) {
58
58
  return false;
59
59
  }
60
60
  return path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
package/lib/checks.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  type Occurrence,
15
15
  type Variant,
16
16
  } from "./match.ts";
17
- import { parseProse, type ProseDocument } from "./prose.ts";
17
+ import { enclosingHeading, parseProse, type ProseDocument } from "./prose.ts";
18
18
  import {
19
19
  TERMS_PATH,
20
20
  parseTermsFile,
@@ -67,11 +67,37 @@ export interface Workspace {
67
67
  readonly externals: ReadonlyMap<string, ReadonlySet<string>>;
68
68
  }
69
69
 
70
+ /** A repeated unregistered code span of a workspace (specs/terms.md#uses). */
71
+ export interface RepeatedCodeSpan {
72
+ readonly text: string;
73
+ readonly paths: readonly string[];
74
+ }
75
+
76
+ /** A use of an entry in a document, prose or code span (specs/terms-tool.md#find). */
77
+ export interface EntryUse {
78
+ readonly id: string;
79
+ readonly path: string;
80
+ readonly line: number;
81
+ readonly column: number;
82
+ readonly kind: "prose" | "code";
83
+ readonly text: string;
84
+ readonly heading: string | null;
85
+ }
86
+
70
87
  /** The check of a workspace (specs/terms.md#findings), with the counts the `check` action reports. */
71
88
  export interface WorkspaceCheck {
72
89
  readonly findings: readonly CheckFinding[];
73
90
  readonly documentCount: number;
74
91
  readonly termsCount: number;
92
+ readonly candidates?: readonly RepeatedCodeSpan[];
93
+ }
94
+
95
+ /** The prose check of a list of documents (specs/terms.md#findings). */
96
+ export interface DocumentsCheck {
97
+ readonly findings: readonly ProseFinding[];
98
+ readonly documentCount: number;
99
+ readonly termsCount: number;
100
+ readonly t001Count: number;
75
101
  }
76
102
 
77
103
  /** An owner path with leading `../` is external (specs/terms.md#documents); every other owner is internal. */
@@ -116,7 +142,7 @@ function analyseText(
116
142
  const occurrences = findOccurrences(text, prose.runs, variants);
117
143
  const usedIds = new Set(usedEntryIds(occurrences));
118
144
  for (const span of prose.codeSpans) {
119
- for (const id of index.get(normalise(span)) ?? []) {
145
+ for (const id of index.get(normalise(span.text)) ?? []) {
120
146
  usedIds.add(id);
121
147
  }
122
148
  }
@@ -244,15 +270,133 @@ export function checkWorkspace(
244
270
  const ws = analyseWorkspace(parseTermsFile(termsBytes), documents, externalOwners);
245
271
  const findings: CheckFinding[] = [...fileFindings(ws)];
246
272
  for (const doc of ws.documents.values()) {
247
- findings.push(...proseFindings(ws, doc));
273
+ for (const finding of proseFindings(ws, doc)) {
274
+ findings.push(finding);
275
+ }
276
+ }
277
+ return {
278
+ findings: findings.toSorted(compareFindings),
279
+ documentCount: documents.size,
280
+ termsCount: ws.terms.termsCount,
281
+ candidates: repeatedUnregisteredCodeSpans(ws),
282
+ };
283
+ }
284
+
285
+ /**
286
+ * The prose check of a list of documents (specs/terms.md#findings), without file checks.
287
+ */
288
+ export function checkDocuments(
289
+ termsBytes: Uint8Array,
290
+ documents: ReadonlyMap<string, string>,
291
+ ): DocumentsCheck {
292
+ const ws = analyseWorkspace(parseTermsFile(termsBytes), documents);
293
+ const findings: ProseFinding[] = [];
294
+ for (const doc of ws.documents.values()) {
295
+ for (const finding of proseFindings(ws, doc)) {
296
+ findings.push(finding);
297
+ }
248
298
  }
249
299
  return {
250
300
  findings: findings.toSorted(compareFindings),
251
301
  documentCount: documents.size,
252
302
  termsCount: ws.terms.termsCount,
303
+ t001Count: ws.terms.t001.length,
253
304
  };
254
305
  }
255
306
 
307
+ const HAS_WORD_CHAR = /[\p{L}\p{M}\p{N}]/u;
308
+
309
+ /**
310
+ * Unregistered code spans appearing in two or more distinct documents of the workspace
311
+ * (specs/terms.md#uses), ordered by descending document count, then ascending text.
312
+ */
313
+ export function repeatedUnregisteredCodeSpans(ws: Workspace): RepeatedCodeSpan[] {
314
+ const registered = new Set(ws.variants.map((variant) => variant.text));
315
+ const bySpan = new Map<string, Set<string>>();
316
+ for (const [path, doc] of ws.documents) {
317
+ for (const span of doc.prose.codeSpans) {
318
+ const text = normalise(span.text);
319
+ if (text === "" || !HAS_WORD_CHAR.test(text) || registered.has(text)) {
320
+ continue;
321
+ }
322
+ let paths = bySpan.get(text);
323
+ if (paths === undefined) {
324
+ paths = new Set<string>();
325
+ bySpan.set(text, paths);
326
+ }
327
+ paths.add(path);
328
+ }
329
+ }
330
+ const out: RepeatedCodeSpan[] = [];
331
+ for (const [text, paths] of bySpan) {
332
+ if (paths.size >= 2) {
333
+ out.push({ text, paths: [...paths].toSorted(compareUtf16) });
334
+ }
335
+ }
336
+ return out.toSorted((a, b) => b.paths.length - a.paths.length || compareUtf16(a.text, b.text));
337
+ }
338
+
339
+ /**
340
+ * The uses of each entry in `ids` (or all entries if omitted) across `documents`
341
+ * (specs/terms-tool.md#find), ordered per entry by path, line, and column ascending.
342
+ */
343
+ export function entryUses(
344
+ terms: TermsFile,
345
+ documents: ReadonlyMap<string, string>,
346
+ ids?: ReadonlySet<string>,
347
+ ): Map<string, EntryUse[]> {
348
+ const ws = analyseWorkspace(terms, documents);
349
+ const index = codeSpanIndex(ws.variants);
350
+ const out = new Map<string, EntryUse[]>();
351
+ const push = (use: EntryUse): void => {
352
+ let list = out.get(use.id);
353
+ if (list === undefined) {
354
+ list = [];
355
+ out.set(use.id, list);
356
+ }
357
+ list.push(use);
358
+ };
359
+ for (const [path, doc] of ws.documents) {
360
+ for (const occurrence of doc.occurrences) {
361
+ const { entry, kind } = occurrence.variant;
362
+ if (ids !== undefined && !ids.has(entry.id)) continue;
363
+ if (
364
+ (entry.status === "active" && (kind === "label" || kind === "form")) ||
365
+ (entry.status === "deprecated" && kind === "deprecated")
366
+ ) {
367
+ push({
368
+ id: entry.id,
369
+ path,
370
+ line: occurrence.line,
371
+ column: occurrence.column,
372
+ kind: "prose",
373
+ text: occurrence.spelled,
374
+ heading: enclosingHeading(doc.prose.headings, occurrence.line),
375
+ });
376
+ }
377
+ }
378
+ for (const span of doc.prose.codeSpans) {
379
+ const text = normalise(span.text);
380
+ for (const id of index.get(text) ?? []) {
381
+ if (ids !== undefined && !ids.has(id)) continue;
382
+ push({
383
+ id,
384
+ path,
385
+ line: span.line,
386
+ column: span.column,
387
+ kind: "code",
388
+ text,
389
+ heading: enclosingHeading(doc.prose.headings, span.line),
390
+ });
391
+ }
392
+ }
393
+ }
394
+ for (const list of out.values()) {
395
+ list.sort((a, b) => compareUtf16(a.path, b.path) || a.line - b.line || a.column - b.column);
396
+ }
397
+ return out;
398
+ }
399
+
256
400
  // ---------------------------------------------------------------------------------------------
257
401
  // Helpers
258
402
 
package/lib/prose.ts CHANGED
@@ -75,6 +75,14 @@ export interface ProseHeading {
75
75
  readonly text: string;
76
76
  }
77
77
 
78
+ export interface ProseCodeSpan {
79
+ /** The raw value of the code span. */
80
+ readonly text: string;
81
+ /** Line and column (UTF-16) of the opening delimiter (specs/terms.md#uses). */
82
+ readonly line: number;
83
+ readonly column: number;
84
+ }
85
+
78
86
  export interface ProseSuppression {
79
87
  readonly line: number;
80
88
  readonly column: number;
@@ -89,8 +97,29 @@ export interface ProseDocument {
89
97
  readonly headings: readonly ProseHeading[];
90
98
  readonly tables: readonly ProseTable[];
91
99
  readonly suppressions: readonly ProseSuppression[];
92
- /** The raw values of the code spans of the document, in document order (specs/terms.md#uses). */
93
- readonly codeSpans: readonly string[];
100
+ /** The code spans of the document, in document order (specs/terms.md#uses). */
101
+ readonly codeSpans: readonly ProseCodeSpan[];
102
+ }
103
+
104
+ /**
105
+ * The text of the last heading in `headings` whose line is at or before `line`, or `null` when
106
+ * none precedes it (specs/terms.md#prose-runs).
107
+ */
108
+ export function enclosingHeading(headings: readonly ProseHeading[], line: number): string | null {
109
+ let lo = 0;
110
+ let hi = headings.length - 1;
111
+ let found: string | null = null;
112
+ while (lo <= hi) {
113
+ const mid = (lo + hi) >> 1;
114
+ const heading = headings[mid];
115
+ if (heading !== undefined && heading.line <= line) {
116
+ found = heading.text;
117
+ lo = mid + 1;
118
+ } else {
119
+ hi = mid - 1;
120
+ }
121
+ }
122
+ return found;
94
123
  }
95
124
 
96
125
  /** The prose runs of a document, in document order. */
@@ -119,7 +148,7 @@ export function parseProse(text: string): ProseDocument {
119
148
  };
120
149
  const doc: Document = { runs: [], headings: [], tables: [], suppressions: [], codeSpans: [] };
121
150
  visitBlock(ctx, tree, doc);
122
- codeSpansOf(tree, doc.codeSpans);
151
+ codeSpansOf(ctx, tree, doc.codeSpans);
123
152
  return doc;
124
153
  }
125
154
 
@@ -152,7 +181,7 @@ interface Document {
152
181
  headings: ProseHeading[];
153
182
  tables: ProseTable[];
154
183
  suppressions: ProseSuppression[];
155
- codeSpans: string[];
184
+ codeSpans: ProseCodeSpan[];
156
185
  }
157
186
 
158
187
  type Mode = "prose" | "text";
@@ -214,15 +243,16 @@ function lineLocator(text: string): (offset: number) => { line: number; column:
214
243
  };
215
244
  }
216
245
 
217
- /** The values of the code spans under a node, in document order; code blocks hold none. */
218
- function codeSpansOf(node: Nodes, out: string[]): void {
246
+ /** The code spans under a node, in document order; code blocks hold none (specs/terms.md#uses). */
247
+ function codeSpansOf(ctx: Ctx, node: Nodes, out: ProseCodeSpan[]): void {
219
248
  if (node.type === "inlineCode") {
220
- out.push(node.value);
249
+ const { line, column } = ctx.locate(offsetOf(node.position?.start));
250
+ out.push({ text: node.value, line, column });
221
251
  return;
222
252
  }
223
253
  if ("children" in node) {
224
254
  for (const child of node.children) {
225
- codeSpansOf(child, out);
255
+ codeSpansOf(ctx, child, out);
226
256
  }
227
257
  }
228
258
  }
package/lib/tool.ts CHANGED
@@ -12,8 +12,21 @@
12
12
  import type { AgentToolResult, ToolDefinition } from "@earendil-works/pi-coding-agent";
13
13
  import { Type, type Static } from "typebox";
14
14
 
15
- import { checkWorkspace, isExternalOwner } from "./checks.ts";
16
- import { checkChanges, validateChanges, type Change, type LabelOccurrence } from "./changes.ts";
15
+ import {
16
+ checkDocuments,
17
+ checkWorkspace,
18
+ entryUses,
19
+ isExternalOwner,
20
+ type EntryUse,
21
+ type RepeatedCodeSpan,
22
+ } from "./checks.ts";
23
+ import {
24
+ checkChanges,
25
+ isWorkspacePath,
26
+ validateChanges,
27
+ type Change,
28
+ type LabelOccurrence,
29
+ } from "./changes.ts";
17
30
  import {
18
31
  runOperation,
19
32
  type Edit,
@@ -38,7 +51,7 @@ import { TermsError, type WorkspaceAccess } from "./workspace.ts";
38
51
  // ---------------------------------------------------------------------------
39
52
 
40
53
  /** The model-facing `description` of the tool (specs/terms-tool.md#model-facing-texts). */
41
- export const TERMS_DESCRIPTION = `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.`;
54
+ export const TERMS_DESCRIPTION = `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; with uses: true, it also lists each match's prose occurrences and code-span uses with line, column, and enclosing heading. check reports findings for the terms file and for every Markdown document not ignored by git, plus repeated unregistered code spans as advisory candidates; with paths, it runs prose checks on those documents only; 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.`;
42
55
 
43
56
  /** The model-facing `promptSnippet` of the tool (specs/terms-tool.md#model-facing-texts). */
44
57
  export const TERMS_PROMPT_SNIPPET = "Look up, check, and change the workspace's thesaurus of terms";
@@ -49,6 +62,7 @@ const ACTION_DESCRIPTION =
49
62
  const FIELD_DESCRIPTIONS = {
50
63
  query:
51
64
  "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.",
65
+ uses: "For find: when true, list each match's prose occurrences and code-span uses with line, column, and enclosing heading.",
52
66
  id: 'The entry\'s id, a lowercase slug such as "rendered-view"; for add, the new id.',
53
67
  label: "For add and rename: the one preferred term, in base form, lowercase unless a name.",
54
68
  meaning: "For add (required) or update (optional): one sentence saying what the concept is.",
@@ -74,6 +88,8 @@ const FIELD_DESCRIPTIONS = {
74
88
  path: "For import: the workspace-relative path of the Markdown thesaurus.",
75
89
  changes:
76
90
  "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.",
91
+ paths:
92
+ "For check: workspace paths of Markdown documents to prose-check alone; mutually exclusive with changes.",
77
93
  } as const;
78
94
 
79
95
  const optionalString = (description: string) =>
@@ -101,6 +117,9 @@ export const TermsSchema = Type.Object(
101
117
  { description: ACTION_DESCRIPTION },
102
118
  ),
103
119
  query: optionalString(FIELD_DESCRIPTIONS.query),
120
+ uses: Type.Optional(
121
+ Type.Union([Type.Boolean(), Type.Null()], { description: FIELD_DESCRIPTIONS.uses }),
122
+ ),
104
123
  id: optionalString(FIELD_DESCRIPTIONS.id),
105
124
  label: optionalString(FIELD_DESCRIPTIONS.label),
106
125
  meaning: optionalString(FIELD_DESCRIPTIONS.meaning),
@@ -152,6 +171,7 @@ export const TermsSchema = Type.Object(
152
171
  { description: FIELD_DESCRIPTIONS.changes },
153
172
  ),
154
173
  ),
174
+ paths: optionalStrings(FIELD_DESCRIPTIONS.paths),
155
175
  },
156
176
  { additionalProperties: false },
157
177
  );
@@ -167,6 +187,7 @@ export type OperationAction = Exclude<Action, "find" | "check">;
167
187
  /** The parameter fields, in the table order of specs/terms-tool.md#parameter-schema. */
168
188
  type Field =
169
189
  | "query"
190
+ | "uses"
170
191
  | "id"
171
192
  | "label"
172
193
  | "meaning"
@@ -185,10 +206,12 @@ type Field =
185
206
  | "reason"
186
207
  | "replacedBy"
187
208
  | "path"
188
- | "changes";
209
+ | "changes"
210
+ | "paths";
189
211
 
190
212
  const FIELDS: readonly Field[] = [
191
213
  "query",
214
+ "uses",
192
215
  "id",
193
216
  "label",
194
217
  "meaning",
@@ -208,6 +231,7 @@ const FIELDS: readonly Field[] = [
208
231
  "replacedBy",
209
232
  "path",
210
233
  "changes",
234
+ "paths",
211
235
  ];
212
236
 
213
237
  const STRING_FIELDS: readonly Field[] = [
@@ -230,12 +254,13 @@ const LIST_FIELDS = [
230
254
  "forms",
231
255
  "into",
232
256
  "replacedBy",
257
+ "paths",
233
258
  ] as const;
234
259
 
235
260
  /** The fields each action accepts (specs/terms-tool.md#parameter-schema). */
236
261
  const ACCEPTS: Record<Action, readonly Field[]> = {
237
- find: ["query", "status", "key", "group", "owner"],
238
- check: ["changes"],
262
+ find: ["query", "uses", "status", "key", "group", "owner"],
263
+ check: ["changes", "paths"],
239
264
  add: ["id", "label", "meaning", "owner", "group", "key", "reject", "distinguish", "forms"],
240
265
  update: [
241
266
  "id",
@@ -277,6 +302,7 @@ const REQUIRED: Record<Action, readonly Field[]> = {
277
302
  interface Args {
278
303
  readonly action: Action;
279
304
  readonly query?: string | undefined;
305
+ readonly uses?: boolean | undefined;
280
306
  readonly id?: string | undefined;
281
307
  readonly label?: string | undefined;
282
308
  readonly meaning?: string | undefined;
@@ -296,6 +322,7 @@ interface Args {
296
322
  readonly replacedBy?: readonly string[] | undefined;
297
323
  readonly path?: string | undefined;
298
324
  readonly changes?: readonly Change[] | undefined;
325
+ readonly paths?: readonly string[] | undefined;
299
326
  }
300
327
 
301
328
  /** Removes leading and trailing white space (specs/terms.md#phrases). */
@@ -326,6 +353,7 @@ export function cleanArgs(params: TermsParams): Args {
326
353
  return {
327
354
  action: params.action,
328
355
  query: trimmedText(params.query),
356
+ uses: given(params.uses),
329
357
  id: trimmedText(params.id),
330
358
  label: trimmedText(params.label),
331
359
  meaning: trimmedText(params.meaning),
@@ -349,6 +377,7 @@ export function cleanArgs(params: TermsParams): Args {
349
377
  before: change.before,
350
378
  ...(change.from == null ? {} : { from: trimmed(change.from) }),
351
379
  })),
380
+ paths: list(params.paths),
352
381
  };
353
382
  }
354
383
 
@@ -390,7 +419,27 @@ export function validate(args: Args): string | undefined {
390
419
  if (action === "update" && args.status === "deprecated") {
391
420
  return "update takes status active only; use deprecate";
392
421
  }
393
- return args.changes === undefined ? undefined : validateChanges(args.changes);
422
+ if (action === "check" && args.paths !== undefined && args.changes !== undefined) {
423
+ return "check takes paths or changes, not both";
424
+ }
425
+ if (args.changes !== undefined) {
426
+ const problem = validateChanges(args.changes);
427
+ if (problem !== undefined) return problem;
428
+ }
429
+ if (args.paths !== undefined) {
430
+ if (args.paths.length === 0) return "paths must hold at least one path";
431
+ const seen = new Set<string>();
432
+ for (const [i, p] of args.paths.entries()) {
433
+ if (!p.endsWith(".md") || !isWorkspacePath(p)) {
434
+ return `paths[${i}] must be a workspace path ending with .md`;
435
+ }
436
+ if (seen.has(p)) {
437
+ return `paths[${i}] repeats ${quote(p)}`;
438
+ }
439
+ seen.add(p);
440
+ }
441
+ }
442
+ return undefined;
394
443
  }
395
444
 
396
445
  /** A value that validation has shown to be present. */
@@ -423,7 +472,11 @@ export interface EditDetail {
423
472
 
424
473
  /** The details of a result (specs/terms-tool.md#actions). */
425
474
  export type TermsDetails =
426
- | { readonly action: "find"; readonly ids: readonly string[] }
475
+ | {
476
+ readonly action: "find";
477
+ readonly ids: readonly string[];
478
+ readonly uses?: readonly EntryUse[];
479
+ }
427
480
  | {
428
481
  readonly action: "check";
429
482
  readonly findings: readonly FindingDetail[];
@@ -431,6 +484,7 @@ export type TermsDetails =
431
484
  LabelOccurrence,
432
485
  "id" | "path" | "line" | "column" | "text"
433
486
  >[];
487
+ readonly candidates?: readonly RepeatedCodeSpan[];
434
488
  }
435
489
  | {
436
490
  readonly action: OperationAction;
@@ -499,24 +553,42 @@ export async function runTerms(
499
553
  async function perform(args: Args, dependencies: TermsDependencies): Promise<TermsOutcome> {
500
554
  const { cwd, io, signal } = dependencies;
501
555
  const root = await io.root(cwd, signal);
502
- const documents: ReadonlyMap<string, string> =
503
- args.action === "find" ? new Map() : await io.documents(root, signal);
504
- const bytes = await io.readTerms(root);
505
-
506
556
  if (args.action === "find") {
557
+ const docs = args.uses === true ? await io.documents(root, signal) : undefined;
558
+ const bytes = await io.readTerms(root);
507
559
  if (bytes === undefined) return failure(NO_TERMS_FILE);
508
- return find(args, parseTermsFile(bytes));
560
+ return find(args, parseTermsFile(bytes), docs);
509
561
  }
510
562
  if (args.action === "check") {
563
+ if (args.paths !== undefined) {
564
+ const targeted = new Map<string, string>();
565
+ let missingPath: string | undefined;
566
+ for (const path of args.paths) {
567
+ const text = await io.document(root, path, signal);
568
+ if (text === undefined) {
569
+ missingPath ??= path;
570
+ } else {
571
+ targeted.set(path, text);
572
+ }
573
+ }
574
+ const bytes = await io.readTerms(root);
575
+ if (bytes === undefined) return failure(NO_TERMS_FILE);
576
+ if (missingPath !== undefined) return failure(`${missingPath} is not a document`);
577
+ return checkPaths(bytes, targeted);
578
+ }
579
+ const documents = await io.documents(root, signal);
580
+ const bytes = await io.readTerms(root);
511
581
  if (bytes === undefined) return failure(NO_TERMS_FILE);
512
582
  return check(bytes, documents, await gatherExternalOwners(bytes, root, io), args.changes);
513
583
  }
584
+ const documents = await io.documents(root, signal);
585
+ const bytes = await io.readTerms(root);
514
586
  return operate(args, args.action, root, bytes, documents, dependencies);
515
587
  }
516
588
 
517
589
  // --- find (specs/terms-tool.md#find) ----------------------------------------------------
518
590
 
519
- function find(args: Args, terms: TermsFile): TermsOutcome {
591
+ function find(args: Args, terms: TermsFile, documents?: ReadonlyMap<string, string>): TermsOutcome {
520
592
  const query = args.query === undefined ? undefined : normalise(args.query);
521
593
  const group = args.group === undefined ? undefined : normalise(args.group);
522
594
  const byId = new Map<string, Entry>(
@@ -527,18 +599,38 @@ function find(args: Args, terms: TermsFile): TermsOutcome {
527
599
  .filter((entry) => matches(entry, args, query, group));
528
600
  const ordered = query === undefined ? matching.toSorted(byIdOrder) : labelFirst(matching, query);
529
601
  const search = searchText(args, query, group);
602
+ const includeUses = args.uses === true && documents !== undefined;
603
+ const usesById =
604
+ includeUses && ordered.length > 0
605
+ ? entryUses(terms, documents, new Set(ordered.map((entry) => entry.id)))
606
+ : new Map<string, EntryUse[]>();
530
607
 
531
608
  const lines: string[] = [];
532
609
  if (ordered.length === 0) {
533
610
  lines.push(`No entry matches ${search}`);
534
611
  } else {
535
612
  lines.push(`${ordered.length} entries match ${search}:`);
536
- for (const entry of ordered) lines.push(...entryLines(entry, terms, byId));
613
+ for (const entry of ordered) {
614
+ for (const line of entryLines(
615
+ entry,
616
+ terms,
617
+ byId,
618
+ includeUses ? (usesById.get(entry.id) ?? []) : undefined,
619
+ )) {
620
+ lines.push(line);
621
+ }
622
+ }
537
623
  }
538
624
  if (terms.t001.length > 0) {
539
625
  lines.push(`${TERMS_PATH} has ${terms.t001.length} T001 findings; run check`);
540
626
  }
541
- return success(lines, { action: "find", ids: ordered.map((entry) => entry.id) });
627
+ const ids = ordered.map((entry) => entry.id);
628
+ return success(
629
+ lines,
630
+ includeUses
631
+ ? { action: "find", ids, uses: ordered.flatMap((entry) => usesById.get(entry.id) ?? []) }
632
+ : { action: "find", ids },
633
+ );
542
634
  }
543
635
 
544
636
  /** True when every condition of specs/terms-tool.md#find that is present holds for an entry. */
@@ -594,7 +686,12 @@ function searchTexts(entry: Entry): string[] {
594
686
  }
595
687
 
596
688
  /** The lines of one matching entry: its header, then its indented details (specs/terms-tool.md#find). */
597
- function entryLines(entry: Entry, terms: TermsFile, byId: ReadonlyMap<string, Entry>): string[] {
689
+ function entryLines(
690
+ entry: Entry,
691
+ terms: TermsFile,
692
+ byId: ReadonlyMap<string, Entry>,
693
+ uses?: readonly EntryUse[],
694
+ ): string[] {
598
695
  const reference = (id: string): string => {
599
696
  const target = byId.get(id);
600
697
  return target === undefined ? `${id} (not an entry)` : `${id} ${quote(target.label)}`;
@@ -617,6 +714,17 @@ function entryLines(entry: Entry, terms: TermsFile, byId: ReadonlyMap<string, En
617
714
  lines.push(` replacedBy: ${entry.replacedBy.map((id) => reference(id)).join(", ")}`);
618
715
  }
619
716
  if (entry.reason !== undefined) lines.push(` reason: ${entry.reason}`);
717
+ if (uses !== undefined) {
718
+ if (uses.length === 0) {
719
+ lines.push(" uses: none");
720
+ } else {
721
+ lines.push(` uses: ${uses.length}`);
722
+ for (const u of uses) {
723
+ const suffix = u.heading === null ? "" : ` · ${quote(u.heading)}`;
724
+ lines.push(` ${u.path}:${u.line}:${u.column} ${u.kind} ${quote(u.text)}${suffix}`);
725
+ }
726
+ }
727
+ }
620
728
  return lines;
621
729
  }
622
730
 
@@ -631,6 +739,23 @@ function distinguishIds(entry: Entry, records: readonly EntryRecord[]): string[]
631
739
 
632
740
  // --- check (specs/terms-tool.md#check) ---------------------------------------------------
633
741
 
742
+ function checkPaths(bytes: Uint8Array, documents: ReadonlyMap<string, string>): TermsOutcome {
743
+ const result = checkDocuments(bytes, documents);
744
+ const header = `${result.findings.length} findings · ${documents.size} documents · ${result.termsCount} entries`;
745
+ const findings: FindingDetail[] = result.findings.map((finding) => ({
746
+ path: finding.path,
747
+ line: finding.line,
748
+ column: finding.column,
749
+ code: finding.code,
750
+ message: finding.message,
751
+ }));
752
+ const lines = [header, ...result.findings.map((finding) => findingText(finding))];
753
+ if (result.t001Count > 0) {
754
+ lines.push(`${TERMS_PATH} has ${result.t001Count} T001 findings; run check`);
755
+ }
756
+ return success(lines, { action: "check", findings });
757
+ }
758
+
634
759
  function check(
635
760
  bytes: Uint8Array,
636
761
  documents: ReadonlyMap<string, string>,
@@ -640,7 +765,7 @@ function check(
640
765
  const result =
641
766
  changes === undefined
642
767
  ? { ...checkWorkspace(bytes, documents, externalOwners), occurrences: undefined }
643
- : checkChanges(bytes, documents, externalOwners, changes);
768
+ : { ...checkChanges(bytes, documents, externalOwners, changes), candidates: undefined };
644
769
  const header =
645
770
  changes === undefined
646
771
  ? `${result.findings.length} findings · ${documents.size} documents · ${result.termsCount} entries`
@@ -653,7 +778,22 @@ function check(
653
778
  message: finding.message,
654
779
  }));
655
780
  const lines = [header, ...result.findings.map((finding) => findingText(finding))];
656
- if (result.occurrences === undefined) return success(lines, { action: "check", findings });
781
+ if (result.occurrences === undefined) {
782
+ const candidates = result.candidates;
783
+ if (candidates !== undefined && candidates.length > 0) {
784
+ lines.push(
785
+ "",
786
+ `${candidates.length} unregistered code spans in 2 or more documents (advisory):`,
787
+ );
788
+ for (const candidate of candidates) {
789
+ lines.push(
790
+ ` ${quote(candidate.text)} (${candidate.paths.length} documents: ${candidate.paths.join(", ")})`,
791
+ );
792
+ }
793
+ return success(lines, { action: "check", findings, candidates });
794
+ }
795
+ return success(lines, { action: "check", findings });
796
+ }
657
797
  if (result.occurrences.length > 0) {
658
798
  lines.push(
659
799
  "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dent-terms",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
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",
@@ -45,6 +45,7 @@ fields below. A field whose value is `null` counts as absent.
45
45
  | ------------------- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
46
46
  | `action` | `"find" \| "check" \| "add" \| "update" \| "rename" \| "merge" \| "split" \| "deprecate" \| "reown" \| "import"` | all | The action ([actions](#actions)). |
47
47
  | `query` | string? \| null | `find` | The text looked up ([`find`](#find)). |
48
+ | `uses` | boolean? \| null | `find` | Whether to list each match's occurrences and code-span uses ([`find`](#find)). |
48
49
  | `id` | string? \| null | `add`, `update`, `rename`, `merge`, `split`, `deprecate`, `reown` | Required. The entry the operation acts on. |
49
50
  | `label` | string? \| null | `add`, `rename` | Required. The label. |
50
51
  | `meaning` | string? \| null | `add`, `update` | Required for `add`, optional for `update`. The meaning. |
@@ -64,6 +65,7 @@ fields below. A field whose value is `null` counts as absent.
64
65
  | `replacedBy` | string[]? \| null | `deprecate` | The replacements. |
65
66
  | `path` | string? \| null | `import` | Required. The workspace path of the document holding the table. |
66
67
  | `changes` | object[]? \| null | `check` | The change set ([terms.md, change checks](terms.md#change-checks)). |
68
+ | `paths` | string[]? \| null | `check` | The workspace paths of the documents to prose-check ([`check`](#check)). |
67
69
 
68
70
  Each item of `changes` is an object schema with `additionalProperties: false`, the required fields
69
71
  `path` (string) and `before` (string or `null`), and the optional field `from` (string or `null`,
@@ -86,12 +88,14 @@ in this order, before any file is read:
86
88
  | 5 | `merge`: `into` does not hold exactly one item | `merge takes exactly one id in into` |
87
89
  | 6 | `find`: none of `query`, `status`, `key`, `group`, and `owner` is present | `action find requires query or a filter` |
88
90
  | 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 |
91
+ | 8 | `check`: both `paths` and `changes` are present | `check takes paths or changes, not both` |
92
+ | 9 | `changes`: the change set is not valid ([terms.md, change checks](terms.md#change-checks)) | see below |
93
+ | 10 | `paths`: `paths` is empty, holds a non-`.md` or non-workspace path, or repeats a path | see below |
90
94
 
91
95
  Trimming removes leading and trailing white space ([terms.md, phrases](terms.md#phrases)). Every
92
96
  string, and every item of a list, is used trimmed, except `before`, which is used as given.
93
97
 
94
- For check 8, the items of `changes` are examined in order; for each item, its `path`, then its
98
+ For check 9, the items of `changes` are examined in order; for each item, its `path`, then its
95
99
  `from` when set, then the item as a whole, each against the conditions of [terms.md, change
96
100
  checks](terms.md#change-checks), in their order. The first failure gives its text, `<i>` being the
97
101
  item's position from 0:
@@ -109,6 +113,11 @@ Condition 1 applies to each field examined, condition 2 to `from`; conditions 3
109
113
  as a whole,
110
114
  condition 6 naming `from` when it is set, else `path`, `<p>` being the base path.
111
115
 
116
+ For check 10, if `paths` is empty the error is `paths must hold at least one path`. Otherwise the
117
+ items of `paths` are examined in order: if `paths[<i>]` is not a workspace path ending with `.md`
118
+ (including any path holding U+0000), the error is `paths[<i>] must be a workspace path ending with
119
+ .md`; if `paths[<i>]` equals an earlier item `<p>`, the error is `paths[<i>] repeats "<p>"`.
120
+
112
121
  ### 1.3 Model-facing texts {#model-facing-texts}
113
122
 
114
123
  The texts of this section are what a model reads to choose and fill a call; each MUST be
@@ -117,7 +126,7 @@ registered verbatim, and none cites a specification.
117
126
  The `description` is
118
127
 
119
128
  ```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.
129
+ 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; with uses: true, it also lists each match's prose occurrences and code-span uses with line, column, and enclosing heading. check reports findings for the terms file and for every Markdown document not ignored by git, plus repeated unregistered code spans as advisory candidates; with paths, it runs prose checks on those documents only; 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
130
  ```
122
131
 
123
132
  The `promptSnippet` is
@@ -132,6 +141,7 @@ Each property of the parameter schema carries this `description`:
132
141
  | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
133
142
  | `action` | `find: look entries up. check: report findings. add, update, rename, merge, split, deprecate, reown, import: change the terms file.` |
134
143
  | `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.` |
144
+ | `uses` | `For find: when true, list each match's prose occurrences and code-span uses with line, column, and enclosing heading.` |
135
145
  | `id` | `The entry's id, a lowercase slug such as "rendered-view"; for add, the new id.` |
136
146
  | `label` | `For add and rename: the one preferred term, in base form, lowercase unless a name.` |
137
147
  | `meaning` | `For add (required) or update (optional): one sentence saying what the concept is.` |
@@ -151,12 +161,14 @@ Each property of the parameter schema carries this `description`:
151
161
  | `replacedBy` | `For deprecate: the id of the entry that replaces it.` |
152
162
  | `path` | `For import: the workspace-relative path of the Markdown thesaurus.` |
153
163
  | `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.` |
164
+ | `paths` | `For check: workspace paths of Markdown documents to prose-check alone; mutually exclusive with changes.` |
154
165
 
155
166
  ## 2. Workspace access {#workspace-access}
156
167
 
157
168
  The workspace of a call or an event is that of the workspace root ([terms.md, workspace
158
169
  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
170
+ terms file anew and, unless its action is `find` with `uses` not `true` or `check` with `paths`,
171
+ lists and reads the documents anew; `check` with `paths` reads only the listed documents. A call MUST be
160
172
  rejected, the first failure reported, with:
161
173
 
162
174
  | Failure | Error text |
@@ -172,8 +184,8 @@ output, else the system's error message; `<code>` is the error code the file sys
172
184
  failure status is the first row; a Git that cannot be started is the second. A terms file whose
173
185
  path gives `ENOENT` or `ENOTDIR` is absent.
174
186
 
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,
187
+ For `check` without `paths`, the extension MUST separately supply the external owner texts of
188
+ [terms.md, documents](terms.md#documents), for every active entry not left out under [terms.md,
177
189
  entries](terms.md#entries). Paths are resolved against the workspace root. File type is tested on
178
190
  the final path component without following a symbolic link there; symbolic links in parent
179
191
  directories are followed. The extension MUST skip missing, unreadable, non-regular, non-UTF-8, or
@@ -197,9 +209,8 @@ Git process; the call is then rejected as a Git failure (`git failed: <message>`
197
209
 
198
210
  A result's content is one text block holding its result text. In a result text, `"<x>"` is the
199
211
  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.
212
+ and the words `entries`, `findings`, `documents`, `occurrences`, `candidates`, `spans`, and `changes`
213
+ stay plural whatever the number. `isError` is unset on every result of this section.
203
214
 
204
215
  ### 3.1 `find` {#find}
205
216
 
@@ -235,16 +246,45 @@ present only when its list is not empty or its field is set, indented by two spa
235
246
  6. `reason: <reason>`.
236
247
 
237
248
  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.
249
+ run check` ends the text, with or without a match.
250
+
251
+ When `uses` is `true`, the documents of the workspace are read and each matching entry also lists
252
+ its uses: for an active entry, every occurrence of kind `label` or `form` ([terms.md,
253
+ occurrences](terms.md#occurrences)) and every code span that uses it ([terms.md, uses](terms.md#uses));
254
+ for a deprecated entry, every occurrence of kind `deprecated`. Each use has `kind` (`"prose"` for
255
+ an occurrence, `"code"` for a code span), `path`, `line`, `column`, `text` (normalised spelled
256
+ text or normalised code span content), and `heading` (the enclosing heading's normalised plain
257
+ text per [terms.md, prose runs](terms.md#prose-runs), or `null` when none), ordered by `path`,
258
+ then `line`, then `column`, each ascending. After the entry's other indented lines, ` uses: none`
259
+ is added when it has none; otherwise ` uses: <u>` (`<u>` being their count) followed by one line
260
+ per use indented by four spaces: ` <path>:<line>:<column> <kind> "<text>"` when `heading` is
261
+ `null`, else ` <path>:<line>:<column> <kind> "<text>" · "<heading>"`.
262
+
263
+ `details` is `{ action: "find", ids: [<id>…] }`, the matching ids in listed order; when `uses` is
264
+ `true`, it also holds `uses: [{ id, path, line, column, kind, text, heading }…]` in entry order and
265
+ then use order.
240
266
 
241
267
  ### 3.2 `check` {#check}
242
268
 
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.
269
+ Without `changes` and without `paths`, the text is the line `<n> findings · <d> documents · <e>
270
+ entries`, then the text of each finding of the check of the workspace ([terms.md,
271
+ findings](terms.md#findings)), in order, one per line. `<d>` is the number of documents and `<e>`
272
+ the number of items of `terms`, `0` when `terms` is not a sequence. When the workspace has at
273
+ least one repeated unregistered code span ([terms.md, uses](terms.md#uses)), the finding lines
274
+ (or the header when there are none) are followed by an empty line, the line `<k> unregistered code
275
+ spans in 2 or more documents (advisory):`, and one line per item in order: ` "<text>" (<d>
276
+ documents: <paths>)`, `<paths>` being its paths joined by `, `. `details` is `{ action: "check",
277
+ findings: [{ path, line, column, code, message }…] }` in finding order, and also holds
278
+ `candidates: [{ text, paths }…]` in the same order when there is at least one item.
279
+
280
+ With `paths`, each listed path is read as a document of the workspace; if any path is not a
281
+ document of the workspace, the call MUST be rejected with `<path> is not a document` for the first
282
+ such path in `paths` order. The prose check of the listed documents ([terms.md,
283
+ findings](terms.md#findings)) is run without file checks. The text is `<n> findings · <d>
284
+ documents · <e> entries`, `<d>` being the number of paths in `paths` and `<e>` the number of
285
+ items of `terms` (`0` when `terms` is not a sequence), then the finding lines in order, followed by
286
+ `.pi/pi-dent/terms.yaml has <k> T001 findings; run check` when the terms file gives T001 findings.
287
+ `details` is `{ action: "check", findings: [{ path, line, column, code, message }…] }`.
248
288
 
249
289
  With `changes`, the findings are the introduced findings of the change set ([terms.md, change
250
290
  checks](terms.md#change-checks)), and the first line is `<n> findings introduced · <c> changes · <d>
package/specs/terms.md CHANGED
@@ -195,7 +195,11 @@ inline content contributes, in order:
195
195
 
196
196
  The space of a line break has no position: no occurrence starts or ends with a space, so no
197
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.
198
+ Prose is the characters of the prose runs of the documents. Each heading in a document has a
199
+ start line and a normalised plain text (the characters its inline content contributes, code span
200
+ content and image descriptions included, normalised per [phrases](#phrases)). The enclosing
201
+ heading of a line in a document is the last heading in the document whose start line is less than
202
+ or equal to that line, or absent when no heading precedes it.
199
203
 
200
204
  ### 3.3 Suppression comments {#suppression-comments}
201
205
 
@@ -289,10 +293,18 @@ from prose runs, but not in front matter, HTML blocks, code blocks, or image des
289
293
  matches do not count: a code span `Terms` uses the label `Terms`, but a code span `run Terms now`
290
294
  does not use the label `Terms`. Suppression comments do not change uses.
291
295
 
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
+ Within checks, code-span uses count only for T005 and T006 (including the `local` rules) in
297
+ [file checks](#file-checks). A code span has the line and column of its opening delimiter. It
298
+ remains a barrier under [prose runs](#prose-runs): it gives no occurrence, so no prose finding
299
+ and no edit list item. For T006 an available external owner text is parsed and tested for use by
300
+ these same rules without becoming a document.
301
+
302
+ An unregistered code span of a workspace is a code span in a document whose normalised content
303
+ holds at least one word character ([phrases](#phrases)) and equals no variant's text
304
+ ([phrases](#phrases)) of any entry left in under [entries](#entries). A repeated unregistered
305
+ code span is one that appears in two or more distinct documents of the workspace; each holds its
306
+ normalised text and those documents' paths in ascending order. Repeated unregistered code spans
307
+ are ordered by descending document count, then ascending text in UTF-16 code units.
296
308
 
297
309
  ## 5. Checks {#checks}
298
310
 
@@ -305,9 +317,11 @@ then column, then code, then message, each ascending by UTF-16 code units or num
305
317
  finding has the same weight: there is no severity level.
306
318
 
307
319
  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.
320
+ are those that [prose checks](#prose-checks) lists, for that document. The check of a workspace
321
+ gives the findings of the file checks and of the prose checks of every document, ordered, with
322
+ every finding a valid suppression comment suppresses left out. The prose check of a list of
323
+ documents gives the findings of the prose checks of each listed document, ordered, with every
324
+ finding a valid suppression comment suppresses left out.
311
325
 
312
326
  ### 5.2 File checks {#file-checks}
313
327