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
package/lib/tool.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `Terms` tool (specs/terms-tool.md
|
|
3
|
-
*
|
|
4
|
-
* (
|
|
2
|
+
* The `Terms` tool (specs/terms-tool.md): its parameter schema
|
|
3
|
+
* (specs/terms-tool.md#parameter-schema), its model-facing texts
|
|
4
|
+
* (specs/terms-tool.md#model-facing-texts), the validation of a call
|
|
5
|
+
* (specs/terms-tool.md#validation), and its actions over the terms file
|
|
6
|
+
* (specs/terms-tool.md#workspace-access and specs/terms-tool.md#actions).
|
|
5
7
|
*
|
|
6
8
|
* `runTerms` is the core. It takes the workspace access and the date as dependencies, so it needs
|
|
7
9
|
* neither a host nor a clock; `createTermsTool` registers it with the host.
|
|
@@ -32,13 +34,13 @@ import { compareUtf16, findingText, normalise, quote } from "./text.ts";
|
|
|
32
34
|
import { TermsError, type WorkspaceAccess } from "./workspace.ts";
|
|
33
35
|
|
|
34
36
|
// ---------------------------------------------------------------------------
|
|
35
|
-
// Schema (
|
|
37
|
+
// Schema (specs/terms-tool.md#parameter-schema) and model-facing texts (specs/terms-tool.md#model-facing-texts)
|
|
36
38
|
// ---------------------------------------------------------------------------
|
|
37
39
|
|
|
38
|
-
/** The model-facing `description` of the tool (
|
|
40
|
+
/** The model-facing `description` of the tool (specs/terms-tool.md#model-facing-texts). */
|
|
39
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.`;
|
|
40
42
|
|
|
41
|
-
/** The model-facing `promptSnippet` of the tool (
|
|
43
|
+
/** The model-facing `promptSnippet` of the tool (specs/terms-tool.md#model-facing-texts). */
|
|
42
44
|
export const TERMS_PROMPT_SNIPPET = "Look up, check, and change the workspace's thesaurus of terms";
|
|
43
45
|
|
|
44
46
|
const ACTION_DESCRIPTION =
|
|
@@ -80,7 +82,7 @@ const optionalString = (description: string) =>
|
|
|
80
82
|
const optionalStrings = (description: string) =>
|
|
81
83
|
Type.Optional(Type.Union([Type.Array(Type.String()), Type.Null()], { description }));
|
|
82
84
|
|
|
83
|
-
/** The parameter schema of the tool (
|
|
85
|
+
/** The parameter schema of the tool (specs/terms-tool.md#parameter-schema). */
|
|
84
86
|
export const TermsSchema = Type.Object(
|
|
85
87
|
{
|
|
86
88
|
action: Type.Union(
|
|
@@ -159,10 +161,10 @@ export type TermsParams = Static<typeof TermsSchema>;
|
|
|
159
161
|
|
|
160
162
|
export type Action = TermsParams["action"];
|
|
161
163
|
|
|
162
|
-
/** The operations of
|
|
164
|
+
/** The operations of specs/terms-tool.md#operations, the actions that change the terms file. */
|
|
163
165
|
export type OperationAction = Exclude<Action, "find" | "check">;
|
|
164
166
|
|
|
165
|
-
/** The parameter fields, in the table order of
|
|
167
|
+
/** The parameter fields, in the table order of specs/terms-tool.md#parameter-schema. */
|
|
166
168
|
type Field =
|
|
167
169
|
| "query"
|
|
168
170
|
| "id"
|
|
@@ -230,7 +232,7 @@ const LIST_FIELDS = [
|
|
|
230
232
|
"replacedBy",
|
|
231
233
|
] as const;
|
|
232
234
|
|
|
233
|
-
/** The fields each action accepts (
|
|
235
|
+
/** The fields each action accepts (specs/terms-tool.md#parameter-schema). */
|
|
234
236
|
const ACCEPTS: Record<Action, readonly Field[]> = {
|
|
235
237
|
find: ["query", "status", "key", "group", "owner"],
|
|
236
238
|
check: ["changes"],
|
|
@@ -253,7 +255,7 @@ const ACCEPTS: Record<Action, readonly Field[]> = {
|
|
|
253
255
|
import: ["path"],
|
|
254
256
|
};
|
|
255
257
|
|
|
256
|
-
/** The fields each action requires (
|
|
258
|
+
/** The fields each action requires (specs/terms-tool.md#parameter-schema). */
|
|
257
259
|
const REQUIRED: Record<Action, readonly Field[]> = {
|
|
258
260
|
find: [],
|
|
259
261
|
check: [],
|
|
@@ -268,7 +270,7 @@ const REQUIRED: Record<Action, readonly Field[]> = {
|
|
|
268
270
|
};
|
|
269
271
|
|
|
270
272
|
// ---------------------------------------------------------------------------
|
|
271
|
-
// Arguments and validation (
|
|
273
|
+
// Arguments and validation (specs/terms-tool.md#validation)
|
|
272
274
|
// ---------------------------------------------------------------------------
|
|
273
275
|
|
|
274
276
|
/** A call's arguments with null counted as absent and strings other than `before` trimmed. */
|
|
@@ -296,7 +298,7 @@ interface Args {
|
|
|
296
298
|
readonly changes?: readonly Change[] | undefined;
|
|
297
299
|
}
|
|
298
300
|
|
|
299
|
-
/** Removes leading and trailing white space (specs/terms.md
|
|
301
|
+
/** Removes leading and trailing white space (specs/terms.md#phrases). */
|
|
300
302
|
function trimmed(value: string): string {
|
|
301
303
|
return value.replace(/^\p{White_Space}+|\p{White_Space}+$/gu, "");
|
|
302
304
|
}
|
|
@@ -316,7 +318,10 @@ function list(value: readonly string[] | null | undefined): string[] | undefined
|
|
|
316
318
|
return present === undefined ? undefined : present.map((item) => trimmed(item));
|
|
317
319
|
}
|
|
318
320
|
|
|
319
|
-
/**
|
|
321
|
+
/**
|
|
322
|
+
* Nulls made absent and strings other than `before` trimmed (specs/terms-tool.md#parameter-schema
|
|
323
|
+
* and specs/terms-tool.md#validation).
|
|
324
|
+
*/
|
|
320
325
|
export function cleanArgs(params: TermsParams): Args {
|
|
321
326
|
return {
|
|
322
327
|
action: params.action,
|
|
@@ -347,7 +352,7 @@ export function cleanArgs(params: TermsParams): Args {
|
|
|
347
352
|
};
|
|
348
353
|
}
|
|
349
354
|
|
|
350
|
-
/** The error text of the first failing check of
|
|
355
|
+
/** The error text of the first failing check of specs/terms-tool.md#validation, or `undefined` when none fails. */
|
|
351
356
|
export function validate(args: Args): string | undefined {
|
|
352
357
|
const { action } = args;
|
|
353
358
|
for (const field of FIELDS) {
|
|
@@ -395,10 +400,10 @@ function need<T>(value: T | undefined): T {
|
|
|
395
400
|
}
|
|
396
401
|
|
|
397
402
|
// ---------------------------------------------------------------------------
|
|
398
|
-
// Outcomes and details (
|
|
403
|
+
// Outcomes and details (specs/terms-tool.md#actions)
|
|
399
404
|
// ---------------------------------------------------------------------------
|
|
400
405
|
|
|
401
|
-
/** The details of a finding in `check` (
|
|
406
|
+
/** The details of a finding in `check` (specs/terms-tool.md#check). */
|
|
402
407
|
export interface FindingDetail {
|
|
403
408
|
readonly path: string;
|
|
404
409
|
readonly line: number;
|
|
@@ -407,7 +412,7 @@ export interface FindingDetail {
|
|
|
407
412
|
readonly message: string;
|
|
408
413
|
}
|
|
409
414
|
|
|
410
|
-
/** The details of an edit list item (
|
|
415
|
+
/** The details of an edit list item (specs/terms-tool.md#operations). */
|
|
411
416
|
export interface EditDetail {
|
|
412
417
|
readonly path: string;
|
|
413
418
|
readonly line: number;
|
|
@@ -416,7 +421,7 @@ export interface EditDetail {
|
|
|
416
421
|
readonly new: string | null;
|
|
417
422
|
}
|
|
418
423
|
|
|
419
|
-
/** The details of a result (
|
|
424
|
+
/** The details of a result (specs/terms-tool.md#actions). */
|
|
420
425
|
export type TermsDetails =
|
|
421
426
|
| { readonly action: "find"; readonly ids: readonly string[] }
|
|
422
427
|
| {
|
|
@@ -439,14 +444,14 @@ export type TermsOutcome =
|
|
|
439
444
|
| { readonly isError: true; readonly text: string }
|
|
440
445
|
| { readonly isError: false; readonly text: string; readonly details: TermsDetails };
|
|
441
446
|
|
|
442
|
-
/** The inputs of a call beyond its parameters (
|
|
447
|
+
/** The inputs of a call beyond its parameters (specs/terms-tool.md#workspace-access). */
|
|
443
448
|
export interface TermsDependencies {
|
|
444
449
|
/** The invoking session's working directory. */
|
|
445
450
|
readonly cwd: string;
|
|
446
451
|
readonly io: WorkspaceAccess;
|
|
447
452
|
/** The current calendar date in the local time zone, `YYYY-MM-DD`. */
|
|
448
453
|
readonly today: () => string;
|
|
449
|
-
/** The call's abort signal; a Git command it fires while running ends the call (
|
|
454
|
+
/** The call's abort signal; a Git command it fires while running ends the call (specs/terms-tool.md#workspace-access). */
|
|
450
455
|
readonly signal?: AbortSignal | undefined;
|
|
451
456
|
}
|
|
452
457
|
|
|
@@ -460,7 +465,7 @@ function success(lines: readonly string[], details: TermsDetails): TermsOutcome
|
|
|
460
465
|
return { isError: false, text: lines.join("\n"), details };
|
|
461
466
|
}
|
|
462
467
|
|
|
463
|
-
/** A call's outcome as the host's tool result (
|
|
468
|
+
/** A call's outcome as the host's tool result (specs/terms-tool.md#package-and-registration). */
|
|
464
469
|
export function toToolResult(outcome: TermsOutcome): AgentToolResult<TermsDetails | undefined> {
|
|
465
470
|
if (outcome.isError) {
|
|
466
471
|
return { content: [{ type: "text", text: outcome.text }], details: undefined, isError: true };
|
|
@@ -469,10 +474,13 @@ export function toToolResult(outcome: TermsOutcome): AgentToolResult<TermsDetail
|
|
|
469
474
|
}
|
|
470
475
|
|
|
471
476
|
// ---------------------------------------------------------------------------
|
|
472
|
-
// Core (
|
|
477
|
+
// Core (specs/terms-tool.md#workspace-access and specs/terms-tool.md#actions)
|
|
473
478
|
// ---------------------------------------------------------------------------
|
|
474
479
|
|
|
475
|
-
/**
|
|
480
|
+
/**
|
|
481
|
+
* Runs a call (specs/terms-tool.md#validation, specs/terms-tool.md#workspace-access, and
|
|
482
|
+
* specs/terms-tool.md#actions): validation first, then the workspace and the action.
|
|
483
|
+
*/
|
|
476
484
|
export async function runTerms(
|
|
477
485
|
params: TermsParams,
|
|
478
486
|
dependencies: TermsDependencies,
|
|
@@ -506,7 +514,7 @@ async function perform(args: Args, dependencies: TermsDependencies): Promise<Ter
|
|
|
506
514
|
return operate(args, args.action, root, bytes, documents, dependencies);
|
|
507
515
|
}
|
|
508
516
|
|
|
509
|
-
// --- find (
|
|
517
|
+
// --- find (specs/terms-tool.md#find) ----------------------------------------------------
|
|
510
518
|
|
|
511
519
|
function find(args: Args, terms: TermsFile): TermsOutcome {
|
|
512
520
|
const query = args.query === undefined ? undefined : normalise(args.query);
|
|
@@ -533,7 +541,7 @@ function find(args: Args, terms: TermsFile): TermsOutcome {
|
|
|
533
541
|
return success(lines, { action: "find", ids: ordered.map((entry) => entry.id) });
|
|
534
542
|
}
|
|
535
543
|
|
|
536
|
-
/** True when every condition of
|
|
544
|
+
/** True when every condition of specs/terms-tool.md#find that is present holds for an entry. */
|
|
537
545
|
function matches(
|
|
538
546
|
entry: Entry,
|
|
539
547
|
args: Args,
|
|
@@ -548,7 +556,7 @@ function matches(
|
|
|
548
556
|
return true;
|
|
549
557
|
}
|
|
550
558
|
|
|
551
|
-
/** The matches with the label-equal ones first, each part in ascending id order (
|
|
559
|
+
/** The matches with the label-equal ones first, each part in ascending id order (specs/terms-tool.md#find). */
|
|
552
560
|
function labelFirst(entries: readonly Entry[], query: string): Entry[] {
|
|
553
561
|
const needle = query.toLowerCase();
|
|
554
562
|
const isExact = (entry: Entry): boolean => normalise(entry.label).toLowerCase() === needle;
|
|
@@ -558,7 +566,7 @@ function labelFirst(entries: readonly Entry[], query: string): Entry[] {
|
|
|
558
566
|
];
|
|
559
567
|
}
|
|
560
568
|
|
|
561
|
-
/** `<search>`: the present parts joined by `, `, in the order of
|
|
569
|
+
/** `<search>`: the present parts joined by `, `, in the order of specs/terms-tool.md#find. */
|
|
562
570
|
function searchText(args: Args, query: string | undefined, group: string | undefined): string {
|
|
563
571
|
const parts: string[] = [];
|
|
564
572
|
if (query !== undefined) parts.push(quote(query));
|
|
@@ -573,19 +581,19 @@ function byIdOrder(a: Entry, b: Entry): number {
|
|
|
573
581
|
return compareUtf16(a.id, b.id);
|
|
574
582
|
}
|
|
575
583
|
|
|
576
|
-
/** True when `<query>`, lower-cased, is a substring of one of an entry's texts (
|
|
584
|
+
/** True when `<query>`, lower-cased, is a substring of one of an entry's texts (specs/terms-tool.md#find). */
|
|
577
585
|
function searched(entry: Entry, needle: string): boolean {
|
|
578
586
|
return searchTexts(entry).some((text) => text.includes(needle));
|
|
579
587
|
}
|
|
580
588
|
|
|
581
|
-
/** The texts an entry is searched by: id, label, meaning, reject and form phrases (
|
|
589
|
+
/** The texts an entry is searched by: id, label, meaning, reject and form phrases (specs/terms-tool.md#find). */
|
|
582
590
|
function searchTexts(entry: Entry): string[] {
|
|
583
591
|
return [entry.id, entry.label, entry.meaning, ...entry.reject, ...entry.forms].map((item) =>
|
|
584
592
|
normalise(item).toLowerCase(),
|
|
585
593
|
);
|
|
586
594
|
}
|
|
587
595
|
|
|
588
|
-
/** The lines of one matching entry: its header, then its indented details (
|
|
596
|
+
/** The lines of one matching entry: its header, then its indented details (specs/terms-tool.md#find). */
|
|
589
597
|
function entryLines(entry: Entry, terms: TermsFile, byId: ReadonlyMap<string, Entry>): string[] {
|
|
590
598
|
const reference = (id: string): string => {
|
|
591
599
|
const target = byId.get(id);
|
|
@@ -612,7 +620,7 @@ function entryLines(entry: Entry, terms: TermsFile, byId: ReadonlyMap<string, En
|
|
|
612
620
|
return lines;
|
|
613
621
|
}
|
|
614
622
|
|
|
615
|
-
/** The ids in the `distinguish` relation with an entry, in ascending order (
|
|
623
|
+
/** The ids in the `distinguish` relation with an entry, in ascending order (specs/terms.md#entries). */
|
|
616
624
|
function distinguishIds(entry: Entry, records: readonly EntryRecord[]): string[] {
|
|
617
625
|
const ids = new Set<string>(entry.distinguish);
|
|
618
626
|
for (const record of records) {
|
|
@@ -621,7 +629,7 @@ function distinguishIds(entry: Entry, records: readonly EntryRecord[]): string[]
|
|
|
621
629
|
return [...ids].toSorted(compareUtf16);
|
|
622
630
|
}
|
|
623
631
|
|
|
624
|
-
// --- check (
|
|
632
|
+
// --- check (specs/terms-tool.md#check) ---------------------------------------------------
|
|
625
633
|
|
|
626
634
|
function check(
|
|
627
635
|
bytes: Uint8Array,
|
|
@@ -675,9 +683,9 @@ function check(
|
|
|
675
683
|
});
|
|
676
684
|
}
|
|
677
685
|
|
|
678
|
-
// --- operations (
|
|
686
|
+
// --- operations (specs/terms-tool.md#operations) ----------------------------------------------
|
|
679
687
|
|
|
680
|
-
/** The operation parameters of a validated call (
|
|
688
|
+
/** The operation parameters of a validated call (specs/terms.md#operations). */
|
|
681
689
|
function toOperation(args: Args): OperationParams {
|
|
682
690
|
switch (args.action) {
|
|
683
691
|
case "add":
|
|
@@ -788,7 +796,7 @@ function editDetail(edit: Edit): EditDetail {
|
|
|
788
796
|
};
|
|
789
797
|
}
|
|
790
798
|
|
|
791
|
-
/** The summary line of an operation (
|
|
799
|
+
/** The summary line of an operation (specs/terms-tool.md#operations). */
|
|
792
800
|
function summaryLine(args: Args, summary: OperationSummary): string {
|
|
793
801
|
switch (summary.op) {
|
|
794
802
|
case "add":
|
|
@@ -823,7 +831,7 @@ function summaryOld(summary: OperationSummary): string {
|
|
|
823
831
|
throw new Error("the summary carries no old value");
|
|
824
832
|
}
|
|
825
833
|
|
|
826
|
-
/** The edit list block (
|
|
834
|
+
/** The edit list block (specs/terms-tool.md#operations). */
|
|
827
835
|
function editLines(edits: readonly Edit[]): string[] {
|
|
828
836
|
if (edits.length === 0) return ["No occurrences to edit."];
|
|
829
837
|
return [
|
|
@@ -835,7 +843,7 @@ function editLines(edits: readonly Edit[]): string[] {
|
|
|
835
843
|
];
|
|
836
844
|
}
|
|
837
845
|
|
|
838
|
-
/** The reject candidate block of an import, absent when there is none (
|
|
846
|
+
/** The reject candidate block of an import, absent when there is none (specs/terms-tool.md#operations). */
|
|
839
847
|
function candidateLines(candidates: readonly RejectCandidate[]): string[] {
|
|
840
848
|
if (candidates.length === 0) return [];
|
|
841
849
|
return [
|
|
@@ -848,14 +856,14 @@ function candidateLines(candidates: readonly RejectCandidate[]): string[] {
|
|
|
848
856
|
// Registration
|
|
849
857
|
// ---------------------------------------------------------------------------
|
|
850
858
|
|
|
851
|
-
/** The local calendar date of a point in time, `YYYY-MM-DD` (
|
|
859
|
+
/** The local calendar date of a point in time, `YYYY-MM-DD` (specs/terms-tool.md#workspace-access). */
|
|
852
860
|
export function localDate(now: Date): string {
|
|
853
861
|
const month = String(now.getMonth() + 1).padStart(2, "0");
|
|
854
862
|
const day = String(now.getDate()).padStart(2, "0");
|
|
855
863
|
return `${now.getFullYear()}-${month}-${day}`;
|
|
856
864
|
}
|
|
857
865
|
|
|
858
|
-
/** The `Terms` tool definition (
|
|
866
|
+
/** The `Terms` tool definition (specs/terms-tool.md#package-and-registration), over the given workspace access. */
|
|
859
867
|
export function createTermsTool(
|
|
860
868
|
io: WorkspaceAccess,
|
|
861
869
|
today: () => string = () => localDate(new Date()),
|
package/lib/workspace.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The I/O of the workspace (specs/terms.md
|
|
2
|
+
* The I/O of the workspace (specs/terms.md#workspace; specs/terms-tool.md#workspace-access and
|
|
3
|
+
* specs/terms-tool.md#checking-a-written-document):
|
|
3
4
|
* the workspace root, the documents, and the terms file, through Git and the file system.
|
|
4
5
|
*
|
|
5
6
|
* The access is an interface, so the tool and the after-edit check take it as a dependency. A
|
|
6
|
-
* failure is a `TermsError` whose message is the tool error text of specs/terms-tool.md
|
|
7
|
+
* failure is a `TermsError` whose message is the tool error text of specs/terms-tool.md#workspace-access.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { execFile } from "node:child_process";
|
|
@@ -26,11 +27,11 @@ export interface WorkspaceAccess {
|
|
|
26
27
|
documents(root: string, signal?: AbortSignal): Promise<ReadonlyMap<string, string>>;
|
|
27
28
|
/**
|
|
28
29
|
* The text of the document at a workspace path, or `undefined` when the path is not a document
|
|
29
|
-
* of the workspace (terms.md
|
|
30
|
+
* of the workspace (specs/terms.md#documents); Git lists only that path, by a literal pathspec.
|
|
30
31
|
*/
|
|
31
32
|
document(root: string, path: string, signal?: AbortSignal): Promise<string | undefined>;
|
|
32
33
|
/**
|
|
33
|
-
* The text of an external owner path (terms.md
|
|
34
|
+
* The text of an external owner path (specs/terms.md#documents) resolved against `root`, or
|
|
34
35
|
* `undefined` when it is unavailable.
|
|
35
36
|
*/
|
|
36
37
|
externalOwner(root: string, path: string): Promise<string | undefined>;
|
|
@@ -57,7 +58,7 @@ function firstLine(text: string): string | undefined {
|
|
|
57
58
|
|
|
58
59
|
/**
|
|
59
60
|
* Runs Git in `cwd`; `exited` tells a failure status from a Git that did not start. An aborted
|
|
60
|
-
* `signal` ends the Git process, and the run fails with the abort's message (
|
|
61
|
+
* `signal` ends the Git process, and the run fails with the abort's message (specs/terms.md#terms-file).
|
|
61
62
|
*/
|
|
62
63
|
function runGit(args: readonly string[], cwd: string, signal?: AbortSignal): Promise<GitRun> {
|
|
63
64
|
return new Promise((resolve) => {
|
|
@@ -95,7 +96,7 @@ function fileProblem(error: unknown): string {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
|
-
* The file a symbolic link at the terms path resolves to, else the path itself (
|
|
99
|
+
* The file a symbolic link at the terms path resolves to, else the path itself (specs/terms.md#terms-file); a
|
|
99
100
|
* path that gives `ENOENT` has no file to resolve to.
|
|
100
101
|
*/
|
|
101
102
|
async function termsTarget(path: string): Promise<string> {
|
|
@@ -117,7 +118,7 @@ function temporaryName(target: string): string {
|
|
|
117
118
|
|
|
118
119
|
const UTF8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
119
120
|
|
|
120
|
-
/** A document's text, or `undefined` when the file is not one (specs/terms.md
|
|
121
|
+
/** A document's text, or `undefined` when the file is not one (specs/terms.md#documents). */
|
|
121
122
|
async function readDocument(path: string): Promise<string | undefined> {
|
|
122
123
|
let info: Stats;
|
|
123
124
|
try {
|
|
@@ -137,7 +138,7 @@ async function readDocument(path: string): Promise<string | undefined> {
|
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
/**
|
|
140
|
-
* The workspace path of an absolute path below `root` (specs/terms.md
|
|
141
|
+
* The workspace path of an absolute path below `root` (specs/terms.md#workspace-root), or
|
|
141
142
|
* `undefined` when the path is not below `root` or has an empty, `.`, or `..` segment.
|
|
142
143
|
*/
|
|
143
144
|
export function workspacePathOf(root: string, absolute: string): string | undefined {
|
|
@@ -208,7 +209,7 @@ export const realWorkspace: WorkspaceAccess = {
|
|
|
208
209
|
try {
|
|
209
210
|
await mkdir(join(root, dirname(TERMS_PATH)), { recursive: true });
|
|
210
211
|
// The new text goes to a new file, renamed over the target, so a failed write leaves the
|
|
211
|
-
// previous terms file as it was and removes the new file (
|
|
212
|
+
// previous terms file as it was and removes the new file (specs/terms.md#terms-file).
|
|
212
213
|
const target = await termsTarget(join(root, TERMS_PATH));
|
|
213
214
|
temporary = temporaryName(target);
|
|
214
215
|
await writeFile(temporary, text, "utf8");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dent-terms",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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": {
|
package/specs/AGENTS.md
ADDED
|
@@ -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`.
|