repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by bugabinga

Skipped full governance imports when no .system exists; focused startup tax vanished on both platforms while exact governed-project notice behavior and 53 tests passed

9960d9afe61ecb282ece71a5836ad38fde179c01

Oliver Krylow <o.krylow@isp-insoft.de> ·

SSH signature · not checked

Browse filesCompare with HEAD

Result: {"status":"keep","win32_the_system_startup_tax_ms":-148.853,"elapsed_s":122.8,"win32_start_reload_ms":5327.953,"win32_extension_tax_ms":3199.375,"the_system_import_ms":57,"win32_the_system_tax_ms":-128.368,"win32_the_system_reload_tax_ms":41.583,"win32_startup_ms":3568.321,"win32_reload_ms":1759.632,"wsl_start_reload_ms":1048.259,"wsl_extension_tax_ms":412.173,"wsl_the_system_import_ms":20,"wsl_the_system_tax_ms":9.655,"wsl_the_system_startup_tax_ms":-3.273,"wsl_the_system_reload_tax_ms":13.918}

Changed files (5)

extensions/the-system/__tests__/system.test.ts

Modified
10 10 import path from "node:path";
11 11 import { afterEach, describe, it } from "vitest";
12 12 import { applyInitialization } from "../init.ts";
13 +import { startupRuntimeNotice } from "../startup-notice.ts";
13 14 import {
14 15 CORE_BYTE_LIMIT,
15 16 composeSystemPrompt,
62 63 describe("runtime notice", () => {
63 - it("stays quiet until the project opts into .system", () => {
64 + it("stays quiet until the project opts into .system", async () => {
64 65 const project = mkdtempSync(path.join(tmpdir(), "the-system-runtime-"));
65 66 roots.push(project);
66 67 mkdirSync(path.join(project, ".git"));
67 68 assert.equal(runtimeNotice(project), undefined);
69 + assert.equal(await startupRuntimeNotice(project), undefined);
68 70 mkdirSync(path.join(project, ".system"));
69 71 assert.match(runtimeNotice(project) ?? "", /incomplete or invalid/);
72 + assert.match(
73 + (await startupRuntimeNotice(project)) ?? "",
74 + /incomplete or invalid/,
75 + );

extensions/the-system/documents.ts

Modified
1 -import { existsSync, lstatSync, readdirSync, readFileSync } from "node:fs";
1 +import { lstatSync, readdirSync, readFileSync } from "node:fs";
2 2 import path from "node:path";
3 3 import {
4 4 type FrontmatterMap,
5 5 type MarkdownDocumentError,
6 6 parseRichMarkdown,
7 7 } from "./markdown.ts";
8 +import { SystemDocumentError } from "./project-root.ts";
10 +export { discoverProjectRoot, SystemDocumentError } from "./project-root.ts";
9 12 export const SCHEMA_VERSION = 3;
11 -export class SystemDocumentError extends Error {
12 - readonly code: string;
14 - constructor(code: string, message: string) {
15 - super(message);
16 - this.code = code;
17 - this.name = "SystemDocumentError";
18 - }
21 -const nearestMarker = (
22 - cwd: string,
23 - marker: string,
24 - markerExists: (candidate: string) => boolean,
25 -) => {
26 - let current = path.resolve(cwd);
27 - while (true) {
28 - if (markerExists(path.join(current, marker))) return current;
29 - const parent = path.dirname(current);
30 - if (parent === current) return undefined;
31 - current = parent;
32 - }
33 -};
35 -export function discoverProjectRoot(
36 - cwd: string,
37 - markerExists = existsSync,
38 -): string {
39 - const resolvedCwd = path.resolve(cwd);
40 - const jj = nearestMarker(resolvedCwd, ".jj", markerExists);
41 - const git = nearestMarker(resolvedCwd, ".git", markerExists);
42 - if (jj && git && jj !== git)
43 - throw new SystemDocumentError(
44 - "root.conflict",
45 - `Conflicting project roots: Git ${git}; JJ ${jj}`,
46 - );
47 - return jj ?? git ?? resolvedCwd;
50 14 export function resolveGovernedPath(root: string, candidate: string): string {
51 15 const normalizedRoot = path.resolve(root);
52 16 const target = path.resolve(normalizedRoot, candidate);

extensions/the-system/index.ts

Modified
20 20 const notifyOnce = async (ctx: ExtensionContext, ticket: number) => {
21 21 if (notified || ticket !== generation) return;
22 22 try {
23 - const { runtimeNotice } = await import("./system.js");
23 + const { startupRuntimeNotice } = await import("./startup-notice.js");
24 24 if (notified || ticket !== generation) return;
25 - const message = runtimeNotice(ctx.cwd);
25 + const message = await startupRuntimeNotice(ctx.cwd);
26 26 if (!message) return;
27 27 if (ctx.hasUI) ctx.ui.notify(message, "warning");
28 28 notified = true;

extensions/the-system/project-root.ts

Added
new file mode 100644
1 +import { existsSync } from "node:fs";
2 +import path from "node:path";
4 +export class SystemDocumentError extends Error {
5 + readonly code: string;
7 + constructor(code: string, message: string) {
8 + super(message);
9 + this.code = code;
10 + this.name = "SystemDocumentError";
11 + }
14 +const nearestMarker = (
15 + cwd: string,
16 + marker: string,
17 + markerExists: (candidate: string) => boolean,
18 +) => {
19 + let current = path.resolve(cwd);
20 + while (true) {
21 + if (markerExists(path.join(current, marker))) return current;
22 + const parent = path.dirname(current);
23 + if (parent === current) return undefined;
24 + current = parent;
25 + }
26 +};
28 +export function discoverProjectRoot(
29 + cwd: string,
30 + markerExists = existsSync,
31 +): string {
32 + const resolvedCwd = path.resolve(cwd);
33 + const jj = nearestMarker(resolvedCwd, ".jj", markerExists);
34 + const git = nearestMarker(resolvedCwd, ".git", markerExists);
35 + if (jj && git && jj !== git)
36 + throw new SystemDocumentError(
37 + "root.conflict",
38 + `Conflicting project roots: Git ${git}; JJ ${jj}`,
39 + );
40 + return jj ?? git ?? resolvedCwd;

extensions/the-system/startup-notice.ts

Added
new file mode 100644
1 +import { existsSync } from "node:fs";
2 +import path from "node:path";
3 +import { discoverProjectRoot } from "./project-root.ts";
5 +export async function startupRuntimeNotice(
6 + cwd: string,
7 +): Promise<string | undefined> {
8 + let root: string;
9 + try {
10 + root = discoverProjectRoot(cwd);
11 + } catch {
12 + return undefined;
13 + }
14 + if (!existsSync(path.join(root, ".system"))) return undefined;
15 + const { runtimeNotice } = await import("./system.ts");
16 + return runtimeNotice(cwd);