@pbuilder/sdk 0.4.0 → 0.5.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/README.md +42 -2
- package/dist/commons/index.js +5 -2
- package/dist/conformance/index.d.ts +2 -2
- package/dist/conformance/index.js +38 -19
- package/dist/core/define-dialect.js +15 -8
- package/dist/core/dialect-handle.js +1 -1
- package/dist/core/json-value.d.ts +14 -0
- package/dist/core/json-value.js +43 -0
- package/dist/dialects/json/ast.d.ts +24 -0
- package/dist/dialects/json/ast.js +21 -0
- package/dist/dialects/json/index.d.ts +55 -0
- package/dist/dialects/json/index.js +54 -0
- package/dist/dialects/json/ops.d.ts +46 -0
- package/dist/dialects/json/ops.js +561 -0
- package/dist/dialects/yaml/ast.d.ts +15 -0
- package/dist/dialects/yaml/ast.js +154 -0
- package/dist/dialects/yaml/documents.d.ts +8 -0
- package/dist/dialects/yaml/documents.js +24 -0
- package/dist/dialects/yaml/index.d.ts +69 -0
- package/dist/dialects/yaml/index.js +70 -0
- package/dist/dialects/yaml/paths.d.ts +55 -0
- package/dist/dialects/yaml/paths.js +208 -0
- package/dist/dialects/yaml/presentation.d.ts +24 -0
- package/dist/dialects/yaml/presentation.js +264 -0
- package/dist/dialects/yaml/structural.d.ts +39 -0
- package/dist/dialects/yaml/structural.js +307 -0
- package/dist/runner-manifest.json +3 -3
- package/dist/transport/error-text.d.ts +6 -1
- package/dist/transport/error-text.js +94 -31
- package/package.json +16 -3
- package/schemas/project-builder.schema.json +112 -0
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
// module source excerpts, no raw peer frame bytes), and every path is expressed
|
|
5
5
|
// project-relative, NEVER absolute (falling back to the `<outside-project>` placeholder
|
|
6
6
|
// when no relative form is meaningful, e.g. a different filesystem root).
|
|
7
|
-
import {
|
|
7
|
+
import { realpathSync } from "node:fs";
|
|
8
|
+
import { dirname, isAbsolute, relative } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
8
10
|
// SDK-chosen placeholders pending engine-side confirmation — same provenance posture as
|
|
9
11
|
// SEC-05's timeout bound and WPS-06's BATCH_CAP_BYTES.
|
|
10
12
|
export const MESSAGE_CEILING_CHARS = 2000;
|
|
@@ -42,36 +44,97 @@ export function toProjectRelativePath(subjectPath, projectRoot = process.cwd())
|
|
|
42
44
|
export function composeWithToken(prefix, token, suffix = "") {
|
|
43
45
|
return boundMessage(`${prefix}${truncateToken(token)}${suffix}`);
|
|
44
46
|
}
|
|
45
|
-
//
|
|
46
|
-
//
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
//
|
|
50
|
-
//
|
|
47
|
+
// This module sits at <sdk>/src/transport/ in source and <sdk>/dist/transport/ in the build.
|
|
48
|
+
// dirname rather than a "../.." URL: that form keeps a trailing slash, which never matches
|
|
49
|
+
// as a whole segment.
|
|
50
|
+
const SDK_ROOT = dirname(dirname(dirname(fileURLToPath(import.meta.url))));
|
|
51
|
+
// REQ-WPS-07.7: the prefixes whose disclosure says something about THIS machine, each also
|
|
52
|
+
// under its realpath (a symlinked checkout reports either). Home and temp directories are not
|
|
53
|
+
// anchored: reading them needs node:os or process.env, neither admitted in the runner closure
|
|
54
|
+
// (scripts/capability-admission.ts).
|
|
55
|
+
export function hostAnchors(projectRoot = process.cwd()) {
|
|
56
|
+
const anchors = [];
|
|
57
|
+
const known = [
|
|
58
|
+
["<project-root>", projectRoot],
|
|
59
|
+
["<sdk>", SDK_ROOT],
|
|
60
|
+
];
|
|
61
|
+
for (const [token, path] of known) {
|
|
62
|
+
anchors.push({ token, path });
|
|
63
|
+
try {
|
|
64
|
+
const real = realpathSync(path);
|
|
65
|
+
if (real !== path)
|
|
66
|
+
anchors.push({ token, path: real });
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
// A prefix that does not exist on disk has no realpath form to add.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return anchors;
|
|
73
|
+
}
|
|
74
|
+
// REQ-WPS-07.7: exact substring replacement — no left boundary, so a path glued to the word
|
|
75
|
+
// before it ("loaderror/home/...") is still caught. The right side must end the segment, so
|
|
76
|
+
// "/repo" never claims "/repo-old". Longest prefix first: the SDK root usually sits under the
|
|
77
|
+
// project root. "/" is skipped: it would claim every slash in the message. A plain scan rather
|
|
78
|
+
// than a built RegExp: the runner closure admits regex literals only.
|
|
79
|
+
const CONTINUES_SEGMENT = /[^\s'"<>\\/]/;
|
|
80
|
+
function anchorKnownPrefixes(message, anchors) {
|
|
81
|
+
const ordered = anchors.filter(({ path }) => path.length > 1).sort((a, b) => b.path.length - a.path.length);
|
|
82
|
+
let scrubbed = "";
|
|
83
|
+
let index = 0;
|
|
84
|
+
while (index < message.length) {
|
|
85
|
+
const anchor = ordered.find(({ path }) => message.startsWith(path, index) && !CONTINUES_SEGMENT.test(message.charAt(index + path.length)));
|
|
86
|
+
if (anchor === undefined) {
|
|
87
|
+
scrubbed += message.charAt(index);
|
|
88
|
+
index += 1;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
scrubbed += anchor.token;
|
|
92
|
+
index += anchor.path.length;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return scrubbed;
|
|
96
|
+
}
|
|
97
|
+
// One alternation, so every position is claimed by exactly one shape and a URL's path or a
|
|
98
|
+
// token's tail is never re-scanned by the groups after it:
|
|
51
99
|
//
|
|
52
|
-
//
|
|
53
|
-
//
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
// "/" to require) count as absolute without also matching prose fractions.
|
|
100
|
+
// 1. What the prefix pass left behind: a token plus its tail, already safe.
|
|
101
|
+
// 2. REQ-WPS-07.8: a URL, recognised whole so its "scheme:" never reads as a path boundary
|
|
102
|
+
// before "//authority/...". The two-character scheme minimum leaves "C://x" to group 3.
|
|
103
|
+
// 3. REQ-WPS-07.4/.6, ADR-02: a Windows-drive-letter or UNC/WSL-interop path — replaced
|
|
104
|
+
// unconditionally, since node:path's POSIX-default isAbsolute/relative cannot classify
|
|
105
|
+
// either on this SDK's POSIX hosts. The drive-letter lookbehind keeps a letter-colon-slash
|
|
106
|
+
// after a word character from reading as a drive. A UNC path needs a server name and its
|
|
107
|
+
// closing backslash (REQ-WPS-07.9), so a bare "\\" in prose survives.
|
|
108
|
+
// 4. REQ-WPS-07.4: a POSIX path. The lookbehind on "/" keeps prose ("and/or", "24/7") from
|
|
109
|
+
// reading as a root while a real boundary (start, space, quote, paren, "=", ":") does not,
|
|
110
|
+
// which is what lets a single segment ("/root", "/etc") count as absolute.
|
|
64
111
|
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
//
|
|
71
|
-
// (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
112
|
+
// In groups 3 and 4 a literal space does not end the match: it's consumed ONLY when a
|
|
113
|
+
// lookahead proves the path keeps going — more non-terminator characters followed by a
|
|
114
|
+
// separator ("Program Files\x", "Application Support/x"). A space with no further separator
|
|
115
|
+
// ahead is NOT consumed, so prose is never swallowed past the actual path boundary.
|
|
116
|
+
const SHAPES = /(<(?:project-root|sdk)>[^\s'"<>]*)|([A-Za-z][A-Za-z0-9+.-]+:\/\/[^\s'"<>]*)|((?:(?<![A-Za-z0-9_])[A-Za-z]:[\\/]|\\\\[A-Za-z0-9._$-]+\\)(?:[^\s'"<>]|[ ](?=[^\s'"<>]*[\\/]))*)|(?<![A-Za-z0-9_])\/(?:[^\s'"<>]|[ ](?=[^\s'"<>]*\/))+/g;
|
|
117
|
+
// A scheme ending in "file" also covers a word glued before it ("loadfile:///..."). A drive
|
|
118
|
+
// letter after the authority slash ("file:///C:/...") is handed to the Windows group.
|
|
119
|
+
const FILE_URL = /^([A-Za-z0-9+.-]*file:\/\/)(?:\/(?=[A-Za-z]:[\\/]))?/i;
|
|
120
|
+
function scrubShapes(text, projectRoot) {
|
|
121
|
+
return text.replace(SHAPES, (match, anchored, url, windows) => {
|
|
122
|
+
if (anchored !== undefined)
|
|
123
|
+
return match;
|
|
124
|
+
if (url !== undefined) {
|
|
125
|
+
const fileUrl = FILE_URL.exec(match);
|
|
126
|
+
return fileUrl === null ? match : `${fileUrl[1]}${scrubShapes(match.slice(fileUrl[0].length), projectRoot)}`;
|
|
127
|
+
}
|
|
128
|
+
if (windows !== undefined)
|
|
129
|
+
return OUTSIDE_PROJECT_TOKEN;
|
|
130
|
+
return toProjectRelativePath(match, projectRoot);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
// REQ-WPS-07.4/.6/.7: scrubs absolute paths embedded anywhere in a plain Error's free-text
|
|
134
|
+
// message. Known host prefixes are replaced first, by exact substring; whatever is left is
|
|
135
|
+
// matched by shape — Windows/UNC/WSL to the outside-project placeholder (ADR-02), POSIX via
|
|
136
|
+
// toProjectRelativePath (ADR-01). Best-effort, not a security boundary: non-path-shaped secret
|
|
137
|
+
// content is untouched (REQ-WPS-07.5).
|
|
138
|
+
export function scrubAbsolutePaths(message, projectRoot, anchors = hostAnchors(projectRoot)) {
|
|
139
|
+
return scrubShapes(anchorKnownPrefixes(message, anchors), projectRoot);
|
|
77
140
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pbuilder/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "The public TypeScript/Bun authoring layer for Project Builder schematics. Authors file mutations (create, replaceContent, remove, rename, move, copy, copyIn), lowers them to IR, and talks to the Project Builder engine over framed stdio (see docs/engine-sdk-wire-spec.md).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
|
-
"dist"
|
|
33
|
+
"dist",
|
|
34
|
+
"schemas"
|
|
34
35
|
],
|
|
35
36
|
"bin": {
|
|
36
37
|
"pbuilder-codegen": "dist/bin/pbuilder-codegen.js"
|
|
@@ -66,6 +67,16 @@
|
|
|
66
67
|
"types": "./dist/dialects/react/index.d.ts",
|
|
67
68
|
"import": "./dist/dialects/react/index.js",
|
|
68
69
|
"default": "./dist/dialects/react/index.js"
|
|
70
|
+
},
|
|
71
|
+
"./json": {
|
|
72
|
+
"types": "./dist/dialects/json/index.d.ts",
|
|
73
|
+
"import": "./dist/dialects/json/index.js",
|
|
74
|
+
"default": "./dist/dialects/json/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./yaml": {
|
|
77
|
+
"types": "./dist/dialects/yaml/index.d.ts",
|
|
78
|
+
"import": "./dist/dialects/yaml/index.js",
|
|
79
|
+
"default": "./dist/dialects/yaml/index.js"
|
|
69
80
|
}
|
|
70
81
|
},
|
|
71
82
|
"scripts": {
|
|
@@ -90,6 +101,8 @@
|
|
|
90
101
|
"verdaccio": "6.10.3"
|
|
91
102
|
},
|
|
92
103
|
"dependencies": {
|
|
93
|
-
"
|
|
104
|
+
"jsonc-parser": "3.3.1",
|
|
105
|
+
"ts-morph": "28.0.0",
|
|
106
|
+
"yaml": "2.9.1"
|
|
94
107
|
}
|
|
95
108
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/Project-Builder-Schematics/project-builder-sdk/schemas/project-builder.schema.json",
|
|
4
|
+
"title": "project-builder.json",
|
|
5
|
+
"description": "Workspace configuration read and written by the project-builder CLI.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "Path or URL of this schema."
|
|
11
|
+
},
|
|
12
|
+
"version": {
|
|
13
|
+
"type": "string",
|
|
14
|
+
"description": "Config format version.",
|
|
15
|
+
"examples": ["1"]
|
|
16
|
+
},
|
|
17
|
+
"collections": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"description": "Collections by name. An entry either points at a collection.json or holds schematics by name.",
|
|
20
|
+
"additionalProperties": {
|
|
21
|
+
"oneOf": [
|
|
22
|
+
{ "$ref": "#/$defs/collectionPointer" },
|
|
23
|
+
{ "$ref": "#/$defs/schematicContainer" }
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"description": "Package names mapped to semver ranges.",
|
|
30
|
+
"additionalProperties": { "type": "string" }
|
|
31
|
+
},
|
|
32
|
+
"settings": {
|
|
33
|
+
"type": "object",
|
|
34
|
+
"properties": {
|
|
35
|
+
"autoInstall": { "type": "boolean", "default": true },
|
|
36
|
+
"conflictPolicy": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"default": "child-wins",
|
|
39
|
+
"description": "Documented values: child-wins, strict."
|
|
40
|
+
},
|
|
41
|
+
"depValidation": {
|
|
42
|
+
"type": "string",
|
|
43
|
+
"default": "dev",
|
|
44
|
+
"description": "Documented values: dev, strict."
|
|
45
|
+
},
|
|
46
|
+
"schematicCollections": {
|
|
47
|
+
"type": "array",
|
|
48
|
+
"items": { "type": "string" },
|
|
49
|
+
"default": ["default"],
|
|
50
|
+
"description": "Ordered collections searched for a bare schematic name."
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"skill": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"properties": {
|
|
57
|
+
"enabled": { "type": "boolean" },
|
|
58
|
+
"path": { "type": "string" }
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"sdk": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"properties": {
|
|
64
|
+
"version": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "Minimum @pbuilder/sdk version, used when package.json declares none.",
|
|
67
|
+
"examples": ["0.2.4"]
|
|
68
|
+
},
|
|
69
|
+
"root": {
|
|
70
|
+
"type": "string",
|
|
71
|
+
"description": "Absolute or config-relative path to an external @pbuilder/sdk package directory."
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"$defs": {
|
|
77
|
+
"collectionPointer": {
|
|
78
|
+
"type": "object",
|
|
79
|
+
"required": ["path"],
|
|
80
|
+
"properties": {
|
|
81
|
+
"path": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"description": "Workspace-relative path to a collection.json."
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"schematicContainer": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"not": { "required": ["path"] },
|
|
90
|
+
"properties": {
|
|
91
|
+
"schematics": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"description": "Inline schematic registrations.",
|
|
94
|
+
"additionalProperties": {
|
|
95
|
+
"type": "object",
|
|
96
|
+
"properties": { "factory": { "type": "string" } }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"additionalProperties": {
|
|
101
|
+
"type": "object",
|
|
102
|
+
"required": ["path"],
|
|
103
|
+
"properties": {
|
|
104
|
+
"path": {
|
|
105
|
+
"type": "string",
|
|
106
|
+
"description": "Workspace-relative path to a schematic directory."
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|