pi-dent-agent 0.2.1 → 0.2.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/index.ts CHANGED
@@ -69,6 +69,9 @@ import { GUIDANCE_CUSTOM_TYPE, modelCatalog, parsedModelGuidance } from "./lib/m
69
69
  import { GuidanceController } from "./lib/guidance-controller.ts";
70
70
  import { renderGuidanceMessage } from "./lib/guidance-render.ts";
71
71
  import { readLocalZone } from "./lib/billing-text.ts";
72
+ import { localLinkDiagnostics } from "./lib/local-links.ts";
73
+ import { dirname } from "node:path";
74
+ import { fileURLToPath } from "node:url";
72
75
 
73
76
  /**
74
77
  * The boot snapshot is cached per process so one boot window (process start
@@ -205,6 +208,10 @@ export default function (pi: ExtensionAPI) {
205
208
  }
206
209
  heldDiagnostics.push(diagnostic);
207
210
  };
211
+ // package.md Section 5.3: a declared local link that is missing, or in use, is told at load.
212
+ for (const diagnostic of localLinkDiagnostics(dirname(fileURLToPath(import.meta.url)))) {
213
+ reportDiagnostic(diagnostic);
214
+ }
208
215
  // footer.md Section 1.1: the configuration is read once per boot window, and its diagnostics
209
216
  // hold until the session's UI shows them.
210
217
  const footerSettings = parseFooter(boot.config);
@@ -0,0 +1,115 @@
1
+ // Local links (specs/package.md, Section 5): symlinks in node_modules to sibling checkouts,
2
+ // declared in the gitignored .local-links file of the package root.
3
+ import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync, symlinkSync } from "node:fs";
4
+ import { dirname, isAbsolute, join } from "node:path";
5
+ import { type Diagnostic, errorMessage, isPlainObject } from "./util.ts";
6
+
7
+ export const LOCAL_LINKS_FILE = ".local-links";
8
+ const LINK_COMMAND = "node scripts/link-local.ts";
9
+ const PACKAGE_NAME = /^(@[a-z0-9~-][a-z0-9._~-]*\/)?[a-z0-9~-][a-z0-9._~-]*$/;
10
+
11
+ export interface LocalLink {
12
+ name: string;
13
+ path: string;
14
+ }
15
+
16
+ function namesPackage(path: string, name: string): boolean {
17
+ let manifest: unknown;
18
+ try {
19
+ manifest = JSON.parse(readFileSync(join(path, "package.json"), "utf8"));
20
+ } catch {
21
+ // Missing, unreadable or not JSON: the caller reports the line as invalid.
22
+ return false;
23
+ }
24
+ return isPlainObject(manifest) && manifest.name === name;
25
+ }
26
+
27
+ /** The links `text` declares; throws the Section 5.1 error message of the first invalid line. */
28
+ export function parseLocalLinks(text: string): LocalLink[] {
29
+ const links: LocalLink[] = [];
30
+ for (const [index, raw] of text.split("\n").entries()) {
31
+ const line = raw.trim();
32
+ if (line === "" || line.startsWith("#")) continue;
33
+ const where = `${LOCAL_LINKS_FILE} line ${index + 1}`;
34
+ const cut = line.indexOf("=");
35
+ const name = cut === -1 ? "" : line.slice(0, cut).trim();
36
+ const path = cut === -1 ? "" : line.slice(cut + 1).trim();
37
+ if (path === "" || !PACKAGE_NAME.test(name)) {
38
+ throw new Error(`${where}: expected <package name>=<absolute path>`);
39
+ }
40
+ if (links.some((link) => link.name === name)) {
41
+ throw new Error(`${where}: duplicate package ${name}`);
42
+ }
43
+ if (!isAbsolute(path)) throw new Error(`${where}: path is not absolute: ${path}`);
44
+ if (!namesPackage(path, name)) {
45
+ throw new Error(`${where}: ${path} is not a directory whose package.json names ${name}`);
46
+ }
47
+ links.push({ name, path });
48
+ }
49
+ return links;
50
+ }
51
+
52
+ /** The links declared in `root`, undefined without a .local-links file; throws when it is invalid. */
53
+ export function readLocalLinks(root: string): LocalLink[] | undefined {
54
+ const file = join(root, LOCAL_LINKS_FILE);
55
+ if (!existsSync(file)) return undefined;
56
+ let text: string;
57
+ try {
58
+ text = readFileSync(file, "utf8");
59
+ } catch (error) {
60
+ throw new Error(`${LOCAL_LINKS_FILE}: ${errorMessage(error)}`, { cause: error });
61
+ }
62
+ return parseLocalLinks(text);
63
+ }
64
+
65
+ function resolved(path: string): string | undefined {
66
+ try {
67
+ return realpathSync(path);
68
+ } catch {
69
+ // Absent or dangling: resolves to nothing, so the link is not in place.
70
+ return undefined;
71
+ }
72
+ }
73
+
74
+ export function linkInPlace(root: string, link: LocalLink): boolean {
75
+ const target = resolved(link.path);
76
+ return target !== undefined && resolved(join(root, "node_modules", link.name)) === target;
77
+ }
78
+
79
+ /** Puts every declared link of `root` in place; returns the lines to print. Throws on an invalid file. */
80
+ export function applyLocalLinks(root: string): string[] {
81
+ const lines: string[] = [];
82
+ for (const link of readLocalLinks(root) ?? []) {
83
+ if (linkInPlace(root, link)) {
84
+ lines.push(`already linked ${link.name} -> ${link.path}`);
85
+ continue;
86
+ }
87
+ const at = join(root, "node_modules", link.name);
88
+ rmSync(at, { recursive: true, force: true });
89
+ mkdirSync(dirname(at), { recursive: true });
90
+ symlinkSync(link.path, at, "dir");
91
+ lines.push(`linked ${link.name} -> ${link.path}`);
92
+ }
93
+ return lines;
94
+ }
95
+
96
+ /** The load-time check of Section 5.3. */
97
+ export function localLinkDiagnostics(root: string): Diagnostic[] {
98
+ let links: LocalLink[];
99
+ try {
100
+ links = readLocalLinks(root) ?? [];
101
+ } catch (error) {
102
+ const message = `local links: ${errorMessage(error)}; correct ${LOCAL_LINKS_FILE}, then run ${LINK_COMMAND}`;
103
+ return [{ level: "warning", message }];
104
+ }
105
+ if (links.length === 0) return [];
106
+ const missing = links.filter((link) => !linkInPlace(root, link));
107
+ if (missing.length === 0) {
108
+ const names = links.map((link) => link.name).join(", ");
109
+ return [{ level: "info", message: `local links in use: ${names}` }];
110
+ }
111
+ return missing.map(({ name, path }) => ({
112
+ level: "warning",
113
+ message: `local link ${name} is not in place: node_modules/${name} does not resolve to ${path}; run ${LINK_COMMAND}`,
114
+ }));
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dent-agent",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A generic coding agent as a pi extension: Bash, Task, Agent, Fleet, Script, Search, Markdown and more tools, with billing and terms extensions bundled",
5
5
  "keywords": [
6
6
  "coding-agent",