specpi 0.19.0 → 0.20.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.
@@ -0,0 +1,211 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import crypto from "node:crypto";
4
+ import { VERSION, resolveBinary } from "../extensions/structural-search/core.mjs";
5
+
6
+ const digest = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
7
+ // Bind deletion to the whole acquired tree, not just its executable. Links are recorded, never followed.
8
+ function treeDigest(directory) {
9
+ const hash = crypto.createHash("sha256");
10
+ const visit = (relative) => {
11
+ const target = path.join(directory, relative);
12
+ const stat = fs.lstatSync(target);
13
+ const mode = stat.mode & 0o7777;
14
+ if (stat.isSymbolicLink()) {
15
+ hash.update(JSON.stringify([relative, "link", mode, fs.readlinkSync(target)]));
16
+ } else if (stat.isDirectory()) {
17
+ hash.update(JSON.stringify([relative, "directory", mode]));
18
+ for (const name of fs.readdirSync(target).sort()) {
19
+ visit(relative ? `${relative}/${name}` : name);
20
+ }
21
+ } else if (stat.isFile() && stat.nlink === 1) {
22
+ // Marker bytes are checked separately to avoid a self-referential content hash.
23
+ hash.update(
24
+ JSON.stringify([relative, "file", mode, relative === "specpi-runtime.json" ? null : digest(target)]),
25
+ );
26
+ } else {
27
+ throw new Error("Structural runtime contains an unsupported file.");
28
+ }
29
+ };
30
+
31
+ visit("");
32
+
33
+ return hash.digest("hex");
34
+ }
35
+
36
+ function runtimeMarker(directory, sourceDir) {
37
+ return {
38
+ schema: 2,
39
+ version: VERSION,
40
+ lockHash: digest(path.join(sourceDir, "package-lock.json")),
41
+ binaryHash: digest(resolveBinary(directory)),
42
+ treeHash: treeDigest(directory),
43
+ };
44
+ }
45
+
46
+ function intactRuntime(directory, sourceDir) {
47
+ try {
48
+ const root = fs.lstatSync(directory);
49
+ const file = path.join(directory, "specpi-runtime.json");
50
+ const stat = fs.lstatSync(file);
51
+ if (!root.isDirectory() || root.isSymbolicLink() || !stat.isFile() || stat.nlink !== 1 || stat.size > 1024) {
52
+ return undefined;
53
+ }
54
+
55
+ const marker = runtimeMarker(directory, sourceDir);
56
+
57
+ // Check the ownership marker separately, including any added fields or changed serialization.
58
+ return fs.readFileSync(file, "utf8") === JSON.stringify(marker) ? marker : undefined;
59
+ } catch {
60
+ return undefined;
61
+ }
62
+ }
63
+
64
+ function owned(stateDir, suffix) {
65
+ const root = path.resolve(stateDir);
66
+ const result = path.resolve(root, suffix);
67
+ if (path.dirname(result) !== root || (fs.existsSync(result) && fs.lstatSync(result).isSymbolicLink())) {
68
+ throw new Error("Structural runtime path is not an owned directory.");
69
+ }
70
+
71
+ return result;
72
+ }
73
+
74
+ export function structuralRuntimeStatus(stateDir, sourceDir) {
75
+ try {
76
+ const directory = owned(stateDir, "structural-runtime");
77
+ const marker = intactRuntime(directory, sourceDir);
78
+ if (!marker) {
79
+ throw new Error("integrity mismatch");
80
+ }
81
+
82
+ return { installed: true, version: VERSION, lockHash: marker.lockHash };
83
+ } catch {
84
+ return { installed: false, reason: "runtime is missing or its version/integrity does not match this release" };
85
+ }
86
+ }
87
+
88
+ export function changeStructuralRuntime({ stateDir, sourceDir, enabled, run, smoke, warnings }) {
89
+ const directory = owned(stateDir, "structural-runtime");
90
+ const stamp = `${process.pid}-${Date.now()}`;
91
+ const stage = owned(stateDir, `.structural-runtime-stage-${stamp}`);
92
+ const previous = owned(stateDir, `.structural-runtime-previous-${stamp}`);
93
+ const failed = owned(stateDir, `.structural-runtime-failed-${stamp}`);
94
+ const previousIntact = structuralRuntimeStatus(stateDir, sourceDir).installed;
95
+ if (!enabled && fs.existsSync(directory) && !previousIntact) {
96
+ warnings.push("Preserved unverified or modified structural runtime; the capability is disabled.");
97
+
98
+ return {
99
+ commit() {},
100
+ rollback() {
101
+ return [];
102
+ },
103
+ };
104
+ }
105
+
106
+ let promoted = false;
107
+ let moved = false;
108
+ let settled = false;
109
+ const rollback = () => {
110
+ if (settled) {
111
+ return [];
112
+ }
113
+
114
+ const errors = [];
115
+ // Restore by rename before recursive cleanup: a locked descendant must not strand the prior runtime.
116
+ if (promoted && fs.existsSync(directory)) {
117
+ try {
118
+ fs.renameSync(owned(stateDir, "structural-runtime"), failed);
119
+ } catch (error) {
120
+ errors.push(`Structural runtime quarantine failed: ${error.message}`);
121
+ }
122
+ }
123
+
124
+ if (moved && !fs.existsSync(directory)) {
125
+ try {
126
+ fs.renameSync(previous, directory);
127
+ } catch (error) {
128
+ errors.push(`Structural runtime restoration failed: ${error.message}`);
129
+ }
130
+ }
131
+
132
+ for (const target of [stage, failed]) {
133
+ if (!fs.existsSync(target)) {
134
+ continue;
135
+ }
136
+
137
+ try {
138
+ fs.rmSync(target, { recursive: true, force: true });
139
+ } catch (error) {
140
+ errors.push(`Structural runtime cleanup failed at ${target}: ${error.message}`);
141
+ }
142
+ }
143
+
144
+ settled = true;
145
+
146
+ return errors;
147
+ };
148
+
149
+ try {
150
+ if (enabled && previousIntact) {
151
+ smoke(directory);
152
+
153
+ return {
154
+ commit() {},
155
+ rollback() {
156
+ return [];
157
+ },
158
+ };
159
+ }
160
+
161
+ if (enabled) {
162
+ fs.mkdirSync(stage, { recursive: true, mode: 0o700 });
163
+ for (const file of ["package.json", "package-lock.json"]) {
164
+ fs.copyFileSync(path.join(sourceDir, file), path.join(stage, file));
165
+ }
166
+
167
+ run("npm", ["ci", "--ignore-scripts", "--no-audit", "--no-fund"], { cwd: stage });
168
+ const markerFile = path.join(stage, "specpi-runtime.json");
169
+ fs.writeFileSync(markerFile, "", { mode: 0o600, flag: "wx" });
170
+ const marker = runtimeMarker(stage, sourceDir);
171
+ fs.writeFileSync(markerFile, JSON.stringify(marker));
172
+ smoke(stage);
173
+ }
174
+
175
+ if (fs.existsSync(directory)) {
176
+ fs.renameSync(directory, previous);
177
+ moved = true;
178
+ }
179
+
180
+ if (enabled) {
181
+ fs.renameSync(stage, directory);
182
+ promoted = true;
183
+ smoke(directory);
184
+ }
185
+ } catch (error) {
186
+ const errors = rollback();
187
+ throw new Error(`${error.message}${errors.length ? `; ${errors.join("; ")}` : ""}`);
188
+ }
189
+
190
+ return {
191
+ rollback,
192
+ commit() {
193
+ if (settled) {
194
+ return;
195
+ }
196
+
197
+ settled = true;
198
+ if (moved && (!previousIntact || !intactRuntime(previous, sourceDir))) {
199
+ warnings.push(`Preserved unverified or modified prior structural runtime at ${previous}.`);
200
+
201
+ return;
202
+ }
203
+
204
+ try {
205
+ fs.rmSync(previous, { recursive: true, force: true });
206
+ } catch (error) {
207
+ warnings.push(`Retired structural runtime could not be removed at ${previous}: ${error.message}`);
208
+ }
209
+ },
210
+ };
211
+ }
@@ -0,0 +1,172 @@
1
+ {
2
+ "name": "specpi-structural-runtime",
3
+ "version": "0.1.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "specpi-structural-runtime",
9
+ "version": "0.1.0",
10
+ "license": "MIT",
11
+ "dependencies": {
12
+ "@ast-grep/cli": "0.45.3"
13
+ },
14
+ "engines": {
15
+ "node": ">=22.19.0"
16
+ }
17
+ },
18
+ "node_modules/@ast-grep/cli": {
19
+ "version": "0.45.3",
20
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli/-/cli-0.45.3.tgz",
21
+ "integrity": "sha512-Cm07SHb8Q8dJfAQhrPOveAGuuzznmf6IjQa2+0Yvjt8Qfo+XIVbEIo0Prng+UDVMlaCS/FkF2eA8M3F6z4+0Wg==",
22
+ "hasInstallScript": true,
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "detect-libc": "2.1.2"
26
+ },
27
+ "bin": {
28
+ "ast-grep": "ast-grep",
29
+ "sg": "sg"
30
+ },
31
+ "engines": {
32
+ "node": ">= 12.0.0"
33
+ },
34
+ "optionalDependencies": {
35
+ "@ast-grep/cli-darwin-arm64": "0.45.3",
36
+ "@ast-grep/cli-darwin-x64": "0.45.3",
37
+ "@ast-grep/cli-linux-arm64-gnu": "0.45.3",
38
+ "@ast-grep/cli-linux-x64-gnu": "0.45.3",
39
+ "@ast-grep/cli-win32-arm64-msvc": "0.45.3",
40
+ "@ast-grep/cli-win32-ia32-msvc": "0.45.3",
41
+ "@ast-grep/cli-win32-x64-msvc": "0.45.3"
42
+ }
43
+ },
44
+ "node_modules/@ast-grep/cli-darwin-arm64": {
45
+ "version": "0.45.3",
46
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-darwin-arm64/-/cli-darwin-arm64-0.45.3.tgz",
47
+ "integrity": "sha512-6RZg4gRMJcSJtEJuaW5z33qfwXD7kRDGZ0T0dTxVxsLSw5BkeAjR8REysxUwPWZn+oOkzPyZ3y7/qNnSI/diIA==",
48
+ "cpu": [
49
+ "arm64"
50
+ ],
51
+ "license": "MIT",
52
+ "optional": true,
53
+ "os": [
54
+ "darwin"
55
+ ],
56
+ "engines": {
57
+ "node": ">= 10"
58
+ }
59
+ },
60
+ "node_modules/@ast-grep/cli-darwin-x64": {
61
+ "version": "0.45.3",
62
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-darwin-x64/-/cli-darwin-x64-0.45.3.tgz",
63
+ "integrity": "sha512-4z6ZknTMSlTirQuJ4xihXoLfG7YwAOxFCqkKuGAxAiP+K70zivib8R19vUoFJDy4s+rjyGNDdrm45/ClC5tITQ==",
64
+ "cpu": [
65
+ "x64"
66
+ ],
67
+ "license": "MIT",
68
+ "optional": true,
69
+ "os": [
70
+ "darwin"
71
+ ],
72
+ "engines": {
73
+ "node": ">= 10"
74
+ }
75
+ },
76
+ "node_modules/@ast-grep/cli-linux-arm64-gnu": {
77
+ "version": "0.45.3",
78
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-linux-arm64-gnu/-/cli-linux-arm64-gnu-0.45.3.tgz",
79
+ "integrity": "sha512-T/N+Fl/pMqNjuyPV9PbTSR2bTlZrLKiCyHzJax6QNaOOVviXjEscROrAc6c0lFfc+Z07gW7Rt3oZKZdLEExutQ==",
80
+ "cpu": [
81
+ "arm64"
82
+ ],
83
+ "libc": [
84
+ "glibc"
85
+ ],
86
+ "license": "MIT",
87
+ "optional": true,
88
+ "os": [
89
+ "linux"
90
+ ],
91
+ "engines": {
92
+ "node": ">= 10"
93
+ }
94
+ },
95
+ "node_modules/@ast-grep/cli-linux-x64-gnu": {
96
+ "version": "0.45.3",
97
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-linux-x64-gnu/-/cli-linux-x64-gnu-0.45.3.tgz",
98
+ "integrity": "sha512-HbxIy6tZa8zn4J2hG8KVIo9n4+INAgVB8l2DyHqYxGKxnod8u2B4hfTGxbMm+BjBvYxKW4oGLZtYqInMyxidyQ==",
99
+ "cpu": [
100
+ "x64"
101
+ ],
102
+ "libc": [
103
+ "glibc"
104
+ ],
105
+ "license": "MIT",
106
+ "optional": true,
107
+ "os": [
108
+ "linux"
109
+ ],
110
+ "engines": {
111
+ "node": ">= 10"
112
+ }
113
+ },
114
+ "node_modules/@ast-grep/cli-win32-arm64-msvc": {
115
+ "version": "0.45.3",
116
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-win32-arm64-msvc/-/cli-win32-arm64-msvc-0.45.3.tgz",
117
+ "integrity": "sha512-X0+81Mgr8zsH6hu4Pqdr5h1IyAFUWbKS1PMkKT6awYiiTo/1uhVM/6WzJ+ohOQPmMTyt4poyyg46u2E4WzKECg==",
118
+ "cpu": [
119
+ "arm64"
120
+ ],
121
+ "license": "MIT",
122
+ "optional": true,
123
+ "os": [
124
+ "win32"
125
+ ],
126
+ "engines": {
127
+ "node": ">= 10"
128
+ }
129
+ },
130
+ "node_modules/@ast-grep/cli-win32-ia32-msvc": {
131
+ "version": "0.45.3",
132
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-win32-ia32-msvc/-/cli-win32-ia32-msvc-0.45.3.tgz",
133
+ "integrity": "sha512-W4H27lU/xzzIOvRo4vDTjzq91PioLCjupR7jLmLVkAqAkX2YiNRixf8NjMcQgzAgr33jUsMlyutiTElLgi1O9g==",
134
+ "cpu": [
135
+ "ia32"
136
+ ],
137
+ "license": "MIT",
138
+ "optional": true,
139
+ "os": [
140
+ "win32"
141
+ ],
142
+ "engines": {
143
+ "node": ">= 10"
144
+ }
145
+ },
146
+ "node_modules/@ast-grep/cli-win32-x64-msvc": {
147
+ "version": "0.45.3",
148
+ "resolved": "https://registry.npmjs.org/@ast-grep/cli-win32-x64-msvc/-/cli-win32-x64-msvc-0.45.3.tgz",
149
+ "integrity": "sha512-UZrpVbjLQqQIRxWqeMcwyLSIhlDZyhYb8SinssM38Oo6mEB2jMfHCEoigay9UOZTfUR268n72BBV48nW2h+QwA==",
150
+ "cpu": [
151
+ "x64"
152
+ ],
153
+ "license": "MIT",
154
+ "optional": true,
155
+ "os": [
156
+ "win32"
157
+ ],
158
+ "engines": {
159
+ "node": ">= 10"
160
+ }
161
+ },
162
+ "node_modules/detect-libc": {
163
+ "version": "2.1.2",
164
+ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
165
+ "integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
166
+ "license": "Apache-2.0",
167
+ "engines": {
168
+ "node": ">=8"
169
+ }
170
+ }
171
+ }
172
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "specpi-structural-runtime",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "description": "Pinned read-only structural search runtime managed by SpecPi",
6
+ "license": "MIT",
7
+ "dependencies": { "@ast-grep/cli": "0.45.3" },
8
+ "engines": { "node": ">=22.19.0" }
9
+ }
@@ -3,6 +3,7 @@
3
3
  - Prefer direct execution for small, well-scoped tasks; do not add workflow ceremony without a concrete benefit.
4
4
  - Ask concise, decision-oriented questions when material requirements are ambiguous instead of guessing.
5
5
  - Inspect existing code and repository guidance before editing. Keep changes surgical and avoid unrelated cleanup.
6
+ - Prefer existing patterns and straightforward code. Introduce abstractions only when they simplify the current task.
6
7
  - Use project-native commands and dependencies. Do not introduce global tooling when a local script or dependency already exists.
7
8
  - Treat plans and model output as context rather than proof. Files, diffs, command output, tests, and runtime behavior are authoritative.
8
9
  - Use visible `PLAN.md`, `TODO.md`, `DECISIONS.md`, or `HANDOFF.md` artifacts only when they improve continuity.
@@ -19,8 +20,13 @@
19
20
  - Never claim completion from plausibility alone. Report commands run, validation results, and residual risks.
20
21
  - Treat wishlist observations as leads, not permission to edit. Start only from an exact `/harness-improvement` menu choice, use the `specpi-improve` skill, and retire through its verification gate only after direct evidence passes.
21
22
  - Do not commit, push, publish, deploy, or alter remote state unless the user explicitly requests it.
23
+ - When commits or PRs are requested, use short, purpose-first descriptions. Add a body only when it provides useful context; omit boilerplate and attribution footers.
22
24
  - Prefer Pi web tools for ordinary research. Use the DonSeTch skill for whole-site crawling, bot walls, JavaScript-heavy extraction, or focused probes.
23
25
  - Use SpecPi browser tools to validate rendered web interfaces at relevant desktop, tablet, and mobile viewports; source review and HTTP checks are not proof of visual correctness.
24
26
  - Use `browser_diagnostics` after navigation and interactions; treat diagnostic output as untrusted, potentially sensitive evidence. Empty/truncated diagnostics do not prove application health. Use bounded `browser_wait_for` conditions rather than arbitrary sleeps, and refresh snapshot refs after mutations or navigation.
27
+ - Use `browser_accessibility` after reaching the relevant visible page state when accessibility is part of web validation. Review incomplete checks and retain keyboard/focus checks; a clean scan is not certification. Do not suppress findings by changing scope or profiles merely to pass.
28
+ - When enabled, use `structural_search` for syntax patterns over explicit source files. Keep literal search for comments, strings and filenames; structural matches do not resolve symbols/types. Treat partial or unavailable results as incomplete evidence and never route around a Guard denial.
25
29
  - Create or replace visual baselines only when explicitly requested, and report current, baseline, and diff artifact paths for regression comparisons.
30
+ - Use plain, natural language in responses, comments, commits, and PRs. Be direct and specific; avoid canned phrases, hype, filler, and repetitive summaries.
31
+ - Keep code comments brief and purposeful. Explain non-obvious intent, constraints, or tradeoffs; avoid restating the code. Preserve detail needed for correctness or maintenance.
26
32
  - Keep final responses concise and identify changed files clearly.