@stigmer/plugin-package 0.1.0-dev.20261017020314.g644422724c27
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/LICENSE +194 -0
- package/README.md +72 -0
- package/client/archive.d.ts +27 -0
- package/client/archive.d.ts.map +1 -0
- package/client/archive.js +38 -0
- package/client/archive.js.map +1 -0
- package/client/builtin.d.ts +37 -0
- package/client/builtin.d.ts.map +1 -0
- package/client/builtin.js +49 -0
- package/client/builtin.js.map +1 -0
- package/client/ignore/defaults.d.ts +2 -0
- package/client/ignore/defaults.d.ts.map +1 -0
- package/client/ignore/defaults.js +140 -0
- package/client/ignore/defaults.js.map +1 -0
- package/client/ignore/match.d.ts +3 -0
- package/client/ignore/match.d.ts.map +1 -0
- package/client/ignore/match.js +166 -0
- package/client/ignore/match.js.map +1 -0
- package/client/ignore/matcher.d.ts +50 -0
- package/client/ignore/matcher.d.ts.map +1 -0
- package/client/ignore/matcher.js +116 -0
- package/client/ignore/matcher.js.map +1 -0
- package/client/ignore/pattern.d.ts +13 -0
- package/client/ignore/pattern.d.ts.map +1 -0
- package/client/ignore/pattern.js +119 -0
- package/client/ignore/pattern.js.map +1 -0
- package/client/prepare-eval.d.ts +62 -0
- package/client/prepare-eval.d.ts.map +1 -0
- package/client/prepare-eval.js +60 -0
- package/client/prepare-eval.js.map +1 -0
- package/client/prepare.d.ts +99 -0
- package/client/prepare.d.ts.map +1 -0
- package/client/prepare.js +89 -0
- package/client/prepare.js.map +1 -0
- package/client/presentation.d.ts +19 -0
- package/client/presentation.d.ts.map +1 -0
- package/client/presentation.js +44 -0
- package/client/presentation.js.map +1 -0
- package/client/refs.d.ts +76 -0
- package/client/refs.d.ts.map +1 -0
- package/client/refs.js +123 -0
- package/client/refs.js.map +1 -0
- package/client/release.d.ts +20 -0
- package/client/release.d.ts.map +1 -0
- package/client/release.js +28 -0
- package/client/release.js.map +1 -0
- package/client/reroot.d.ts +21 -0
- package/client/reroot.d.ts.map +1 -0
- package/client/reroot.js +37 -0
- package/client/reroot.js.map +1 -0
- package/client/select.d.ts +74 -0
- package/client/select.d.ts.map +1 -0
- package/client/select.js +121 -0
- package/client/select.js.map +1 -0
- package/client/vocabulary.d.ts +13 -0
- package/client/vocabulary.d.ts.map +1 -0
- package/client/vocabulary.js +17 -0
- package/client/vocabulary.js.map +1 -0
- package/client.d.ts +51 -0
- package/client.d.ts.map +1 -0
- package/client.js +51 -0
- package/client.js.map +1 -0
- package/detect.d.ts +83 -0
- package/detect.d.ts.map +1 -0
- package/detect.js +210 -0
- package/detect.js.map +1 -0
- package/dialects/claude.d.ts +34 -0
- package/dialects/claude.d.ts.map +1 -0
- package/dialects/claude.js +84 -0
- package/dialects/claude.js.map +1 -0
- package/dialects/codex.d.ts +20 -0
- package/dialects/codex.d.ts.map +1 -0
- package/dialects/codex.js +21 -0
- package/dialects/codex.js.map +1 -0
- package/dialects/cursor.d.ts +25 -0
- package/dialects/cursor.d.ts.map +1 -0
- package/dialects/cursor.js +66 -0
- package/dialects/cursor.js.map +1 -0
- package/dialects/manifest.d.ts +164 -0
- package/dialects/manifest.d.ts.map +1 -0
- package/dialects/manifest.js +256 -0
- package/dialects/manifest.js.map +1 -0
- package/dialects/open.d.ts +19 -0
- package/dialects/open.d.ts.map +1 -0
- package/dialects/open.js +49 -0
- package/dialects/open.js.map +1 -0
- package/documents.d.ts +58 -0
- package/documents.d.ts.map +1 -0
- package/documents.js +121 -0
- package/documents.js.map +1 -0
- package/evals/eval-dir.d.ts +59 -0
- package/evals/eval-dir.d.ts.map +1 -0
- package/evals/eval-dir.js +84 -0
- package/evals/eval-dir.js.map +1 -0
- package/evals/fields.d.ts +78 -0
- package/evals/fields.d.ts.map +1 -0
- package/evals/fields.js +156 -0
- package/evals/fields.js.map +1 -0
- package/evals/glob.d.ts +40 -0
- package/evals/glob.d.ts.map +1 -0
- package/evals/glob.js +146 -0
- package/evals/glob.js.map +1 -0
- package/evals/graders.d.ts +52 -0
- package/evals/graders.d.ts.map +1 -0
- package/evals/graders.js +279 -0
- package/evals/graders.js.map +1 -0
- package/evals/markdown.d.ts +24 -0
- package/evals/markdown.d.ts.map +1 -0
- package/evals/markdown.js +48 -0
- package/evals/markdown.js.map +1 -0
- package/evals/mocks.d.ts +50 -0
- package/evals/mocks.d.ts.map +1 -0
- package/evals/mocks.js +182 -0
- package/evals/mocks.js.map +1 -0
- package/evals/read-eval-suite.d.ts +110 -0
- package/evals/read-eval-suite.d.ts.map +1 -0
- package/evals/read-eval-suite.js +603 -0
- package/evals/read-eval-suite.js.map +1 -0
- package/evals/summary.d.ts +61 -0
- package/evals/summary.d.ts.map +1 -0
- package/evals/summary.js +69 -0
- package/evals/summary.js.map +1 -0
- package/evals/types.d.ts +203 -0
- package/evals/types.d.ts.map +1 -0
- package/evals/types.js +21 -0
- package/evals/types.js.map +1 -0
- package/files.d.ts +135 -0
- package/files.d.ts.map +1 -0
- package/files.js +209 -0
- package/files.js.map +1 -0
- package/frontmatter.d.ts +51 -0
- package/frontmatter.d.ts.map +1 -0
- package/frontmatter.js +61 -0
- package/frontmatter.js.map +1 -0
- package/index.d.ts +37 -0
- package/index.d.ts.map +1 -0
- package/index.js +33 -0
- package/index.js.map +1 -0
- package/marketplace/messages.d.ts +20 -0
- package/marketplace/messages.d.ts.map +1 -0
- package/marketplace/messages.js +49 -0
- package/marketplace/messages.js.map +1 -0
- package/marketplace/outcome.d.ts +70 -0
- package/marketplace/outcome.d.ts.map +1 -0
- package/marketplace/outcome.js +29 -0
- package/marketplace/outcome.js.map +1 -0
- package/marketplace/read-marketplace.d.ts +52 -0
- package/marketplace/read-marketplace.d.ts.map +1 -0
- package/marketplace/read-marketplace.js +351 -0
- package/marketplace/read-marketplace.js.map +1 -0
- package/messages.d.ts +55 -0
- package/messages.d.ts.map +1 -0
- package/messages.js +167 -0
- package/messages.js.map +1 -0
- package/normalise/hooks.d.ts +91 -0
- package/normalise/hooks.d.ts.map +1 -0
- package/normalise/hooks.js +437 -0
- package/normalise/hooks.js.map +1 -0
- package/normalise/ignored.d.ts +34 -0
- package/normalise/ignored.d.ts.map +1 -0
- package/normalise/ignored.js +78 -0
- package/normalise/ignored.js.map +1 -0
- package/normalise/mcp-servers.d.ts +50 -0
- package/normalise/mcp-servers.d.ts.map +1 -0
- package/normalise/mcp-servers.js +398 -0
- package/normalise/mcp-servers.js.map +1 -0
- package/normalise/settings.d.ts +32 -0
- package/normalise/settings.d.ts.map +1 -0
- package/normalise/settings.js +72 -0
- package/normalise/settings.js.map +1 -0
- package/normalise/skills.d.ts +39 -0
- package/normalise/skills.d.ts.map +1 -0
- package/normalise/skills.js +135 -0
- package/normalise/skills.js.map +1 -0
- package/normalise/stigmer-folder.d.ts +17 -0
- package/normalise/stigmer-folder.d.ts.map +1 -0
- package/normalise/stigmer-folder.js +19 -0
- package/normalise/stigmer-folder.js.map +1 -0
- package/normalise/sub-agents.d.ts +54 -0
- package/normalise/sub-agents.d.ts.map +1 -0
- package/normalise/sub-agents.js +219 -0
- package/normalise/sub-agents.js.map +1 -0
- package/normalise/variables.d.ts +31 -0
- package/normalise/variables.d.ts.map +1 -0
- package/normalise/variables.js +170 -0
- package/normalise/variables.js.map +1 -0
- package/outcome.d.ts +59 -0
- package/outcome.d.ts.map +1 -0
- package/outcome.js +32 -0
- package/outcome.js.map +1 -0
- package/package.json +47 -0
- package/placeholders.d.ts +65 -0
- package/placeholders.d.ts.map +1 -0
- package/placeholders.js +99 -0
- package/placeholders.js.map +1 -0
- package/presentation.d.ts +53 -0
- package/presentation.d.ts.map +1 -0
- package/presentation.js +156 -0
- package/presentation.js.map +1 -0
- package/read-plugin-package.d.ts +20 -0
- package/read-plugin-package.d.ts.map +1 -0
- package/read-plugin-package.js +73 -0
- package/read-plugin-package.js.map +1 -0
- package/src/client/archive.ts +44 -0
- package/src/client/builtin.ts +60 -0
- package/src/client/ignore/defaults.ts +155 -0
- package/src/client/ignore/match.ts +158 -0
- package/src/client/ignore/matcher.ts +156 -0
- package/src/client/ignore/pattern.ts +132 -0
- package/src/client/prepare-eval.ts +92 -0
- package/src/client/prepare.ts +160 -0
- package/src/client/presentation.ts +47 -0
- package/src/client/refs.ts +170 -0
- package/src/client/release.ts +29 -0
- package/src/client/reroot.ts +35 -0
- package/src/client/select.ts +161 -0
- package/src/client/vocabulary.ts +19 -0
- package/src/client.ts +102 -0
- package/src/detect.ts +245 -0
- package/src/dialects/claude.ts +102 -0
- package/src/dialects/codex.ts +26 -0
- package/src/dialects/cursor.ts +77 -0
- package/src/dialects/manifest.ts +316 -0
- package/src/dialects/open.ts +50 -0
- package/src/documents.ts +158 -0
- package/src/evals/eval-dir.ts +101 -0
- package/src/evals/fields.ts +184 -0
- package/src/evals/glob.ts +141 -0
- package/src/evals/graders.ts +293 -0
- package/src/evals/markdown.ts +56 -0
- package/src/evals/mocks.ts +202 -0
- package/src/evals/read-eval-suite.ts +713 -0
- package/src/evals/summary.ts +100 -0
- package/src/evals/types.ts +217 -0
- package/src/files.ts +235 -0
- package/src/frontmatter.ts +70 -0
- package/src/index.ts +129 -0
- package/src/marketplace/messages.ts +61 -0
- package/src/marketplace/outcome.ts +91 -0
- package/src/marketplace/read-marketplace.ts +388 -0
- package/src/messages.ts +248 -0
- package/src/normalise/hooks.ts +469 -0
- package/src/normalise/ignored.ts +79 -0
- package/src/normalise/mcp-servers.ts +423 -0
- package/src/normalise/settings.ts +81 -0
- package/src/normalise/skills.ts +145 -0
- package/src/normalise/stigmer-folder.ts +23 -0
- package/src/normalise/sub-agents.ts +231 -0
- package/src/normalise/variables.ts +181 -0
- package/src/outcome.ts +158 -0
- package/src/placeholders.ts +110 -0
- package/src/presentation.ts +170 -0
- package/src/read-plugin-package.ts +80 -0
- package/src/testing.ts +347 -0
- package/src/tool-names.ts +30 -0
- package/src/trim.ts +10 -0
- package/src/types.ts +214 -0
- package/testing.d.ts +127 -0
- package/testing.d.ts.map +1 -0
- package/testing.js +266 -0
- package/testing.js.map +1 -0
- package/tool-names.d.ts +21 -0
- package/tool-names.d.ts.map +1 -0
- package/tool-names.js +28 -0
- package/tool-names.js.map +1 -0
- package/trim.d.ts +7 -0
- package/trim.d.ts.map +1 -0
- package/trim.js +12 -0
- package/trim.js.map +1 -0
- package/types.d.ts +179 -0
- package/types.d.ts.map +1 -0
- package/types.js +19 -0
- package/types.js.map +1 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// Faithful port of Go's path/filepath Match, used by the gitignore pattern
|
|
2
|
+
// engine to match a single glob against a single path component.
|
|
3
|
+
//
|
|
4
|
+
// The separator is fixed to "/" (paths are normalized to forward slashes and
|
|
5
|
+
// individual components never contain a separator). Matching operates on UTF-16
|
|
6
|
+
// code units rather than runes — correct for the ASCII glob syntax gitignore
|
|
7
|
+
// patterns use; exotic multi-byte classes are out of scope.
|
|
8
|
+
//
|
|
9
|
+
// Go returns ErrBadPattern for malformed patterns; every go-git caller treats
|
|
10
|
+
// that as "no match", so `matchName` swallows the error and returns false.
|
|
11
|
+
|
|
12
|
+
const SEPARATOR = "/";
|
|
13
|
+
|
|
14
|
+
class BadPatternError extends Error {}
|
|
15
|
+
|
|
16
|
+
/** Match `name` against the glob `pattern` (Go filepath.Match semantics). */
|
|
17
|
+
export function matchName(pattern: string, name: string): boolean {
|
|
18
|
+
try {
|
|
19
|
+
return matchImpl(pattern, name);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
if (err instanceof BadPatternError) return false;
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function matchImpl(pattern: string, name: string): boolean {
|
|
27
|
+
outer: while (pattern.length > 0) {
|
|
28
|
+
const [star, chunk, rest] = scanChunk(pattern);
|
|
29
|
+
pattern = rest;
|
|
30
|
+
|
|
31
|
+
if (star && chunk === "") {
|
|
32
|
+
// Trailing `*` matches the rest of the component (which has no separator).
|
|
33
|
+
return !name.includes(SEPARATOR);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [t, ok] = matchChunk(chunk, name);
|
|
37
|
+
if (ok && (t.length === 0 || pattern.length > 0)) {
|
|
38
|
+
name = t;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (star) {
|
|
43
|
+
for (let i = 0; i < name.length && name[i] !== SEPARATOR; i++) {
|
|
44
|
+
const [t2, ok2] = matchChunk(chunk, name.slice(i + 1));
|
|
45
|
+
if (ok2) {
|
|
46
|
+
if (pattern.length === 0 && t2.length > 0) continue;
|
|
47
|
+
name = t2;
|
|
48
|
+
continue outer;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
return name.length === 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function scanChunk(pattern: string): [boolean, string, string] {
|
|
58
|
+
let star = false;
|
|
59
|
+
while (pattern.length > 0 && pattern[0] === "*") {
|
|
60
|
+
pattern = pattern.slice(1);
|
|
61
|
+
star = true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let inrange = false;
|
|
65
|
+
let i = 0;
|
|
66
|
+
scan: for (i = 0; i < pattern.length; i++) {
|
|
67
|
+
switch (pattern[i]) {
|
|
68
|
+
case "\\":
|
|
69
|
+
if (i + 1 < pattern.length) i++;
|
|
70
|
+
break;
|
|
71
|
+
case "[":
|
|
72
|
+
inrange = true;
|
|
73
|
+
break;
|
|
74
|
+
case "]":
|
|
75
|
+
inrange = false;
|
|
76
|
+
break;
|
|
77
|
+
case "*":
|
|
78
|
+
if (!inrange) break scan;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return [star, pattern.slice(0, i), pattern.slice(i)];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function matchChunk(chunk: string, s: string): [string, boolean] {
|
|
86
|
+
let failed = false;
|
|
87
|
+
while (chunk.length > 0) {
|
|
88
|
+
if (!failed && s.length === 0) failed = true;
|
|
89
|
+
|
|
90
|
+
const c = chunk[0];
|
|
91
|
+
if (c === "[") {
|
|
92
|
+
let r = "";
|
|
93
|
+
if (!failed) {
|
|
94
|
+
r = s[0] ?? "";
|
|
95
|
+
s = s.slice(1);
|
|
96
|
+
}
|
|
97
|
+
chunk = chunk.slice(1);
|
|
98
|
+
let negated = false;
|
|
99
|
+
if (chunk.length > 0 && chunk[0] === "^") {
|
|
100
|
+
negated = true;
|
|
101
|
+
chunk = chunk.slice(1);
|
|
102
|
+
}
|
|
103
|
+
let match = false;
|
|
104
|
+
let nrange = 0;
|
|
105
|
+
for (;;) {
|
|
106
|
+
if (chunk.length > 0 && chunk[0] === "]" && nrange > 0) {
|
|
107
|
+
chunk = chunk.slice(1);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
let lo: string;
|
|
111
|
+
[lo, chunk] = getEsc(chunk);
|
|
112
|
+
let hi = lo;
|
|
113
|
+
if (chunk[0] === "-") {
|
|
114
|
+
[hi, chunk] = getEsc(chunk.slice(1));
|
|
115
|
+
}
|
|
116
|
+
if (lo <= r && r <= hi) match = true;
|
|
117
|
+
nrange++;
|
|
118
|
+
}
|
|
119
|
+
if (match === negated) failed = true;
|
|
120
|
+
} else if (c === "?") {
|
|
121
|
+
if (!failed) {
|
|
122
|
+
if (s[0] === SEPARATOR) failed = true;
|
|
123
|
+
s = s.slice(1);
|
|
124
|
+
}
|
|
125
|
+
chunk = chunk.slice(1);
|
|
126
|
+
} else if (c === "\\") {
|
|
127
|
+
chunk = chunk.slice(1);
|
|
128
|
+
if (chunk.length === 0) throw new BadPatternError("bad pattern");
|
|
129
|
+
if (!failed) {
|
|
130
|
+
if (chunk[0] !== s[0]) failed = true;
|
|
131
|
+
s = s.slice(1);
|
|
132
|
+
}
|
|
133
|
+
chunk = chunk.slice(1);
|
|
134
|
+
} else {
|
|
135
|
+
if (!failed) {
|
|
136
|
+
if (chunk[0] !== s[0]) failed = true;
|
|
137
|
+
s = s.slice(1);
|
|
138
|
+
}
|
|
139
|
+
chunk = chunk.slice(1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (failed) return ["", false];
|
|
143
|
+
return [s, true];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function getEsc(chunk: string): [string, string] {
|
|
147
|
+
if (chunk.length === 0 || chunk[0] === "-" || chunk[0] === "]") {
|
|
148
|
+
throw new BadPatternError("bad pattern");
|
|
149
|
+
}
|
|
150
|
+
if (chunk[0] === "\\") {
|
|
151
|
+
chunk = chunk.slice(1);
|
|
152
|
+
if (chunk.length === 0) throw new BadPatternError("bad pattern");
|
|
153
|
+
}
|
|
154
|
+
const r = chunk[0] ?? "";
|
|
155
|
+
const nchunk = chunk.slice(1);
|
|
156
|
+
if (nchunk.length === 0) throw new BadPatternError("bad pattern");
|
|
157
|
+
return [r, nchunk];
|
|
158
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Ignore matcher: composes pattern sources with gitignore precedence (defaults
|
|
2
|
+
// → .gitignore → .stigmerignore → caller flags), evaluating "last match wins".
|
|
3
|
+
// A faithful port of the Go CLI's pkg/ignore Matcher.
|
|
4
|
+
//
|
|
5
|
+
// The matcher is pure over the TEXT of the ignore files. Where that text
|
|
6
|
+
// comes from is the caller's edge: the CLI reads `.gitignore` and
|
|
7
|
+
// `.stigmerignore` from the directory it is about to package, the console
|
|
8
|
+
// finds them among the files a marketplace tree lists. Both build the same
|
|
9
|
+
// matcher from the same sources, which is what makes a plugin selected in
|
|
10
|
+
// the browser the same set of files the CLI would have selected.
|
|
11
|
+
|
|
12
|
+
import { DEFAULT_PATTERNS } from "./defaults.js";
|
|
13
|
+
import { MatchResult, type Pattern, parsePattern } from "./pattern.js";
|
|
14
|
+
|
|
15
|
+
export const SOURCE_DEFAULTS = "defaults";
|
|
16
|
+
export const SOURCE_GITIGNORE = ".gitignore";
|
|
17
|
+
export const SOURCE_STIGMERIGNORE = ".stigmerignore";
|
|
18
|
+
export const SOURCE_CLI = "cli";
|
|
19
|
+
|
|
20
|
+
export enum Reason {
|
|
21
|
+
NoMatch = 0,
|
|
22
|
+
Excluded = 1,
|
|
23
|
+
Included = 2,
|
|
24
|
+
DefaultDeny = 3,
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const REASON_TEXT: Readonly<Record<Reason, string>> = {
|
|
28
|
+
[Reason.NoMatch]: "no pattern matched",
|
|
29
|
+
[Reason.Excluded]: "excluded by pattern",
|
|
30
|
+
[Reason.Included]: "included by negation pattern",
|
|
31
|
+
[Reason.DefaultDeny]: "excluded by security default",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export interface MatchReason {
|
|
35
|
+
readonly ignored: boolean;
|
|
36
|
+
readonly reason: Reason;
|
|
37
|
+
readonly source: string;
|
|
38
|
+
readonly pattern: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface PatternEntry {
|
|
42
|
+
readonly pattern: Pattern;
|
|
43
|
+
readonly source: string;
|
|
44
|
+
readonly raw: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The pattern sources a matcher is built from, in precedence order (later wins). */
|
|
48
|
+
export interface IgnoreSources {
|
|
49
|
+
/** Whether the built-in security defaults apply (every push says yes). */
|
|
50
|
+
readonly includeDefaults: boolean;
|
|
51
|
+
/** The text of the root `.gitignore`, or `undefined` when absent or not respected. */
|
|
52
|
+
readonly gitignore?: string;
|
|
53
|
+
/** The text of the root `.stigmerignore`, or `undefined` when absent. */
|
|
54
|
+
readonly stigmerignore?: string;
|
|
55
|
+
/** Extra exclusion patterns from the caller (`--ignore`). */
|
|
56
|
+
readonly extraIgnore?: readonly string[];
|
|
57
|
+
/** Extra inclusion patterns from the caller (`--include`), negated if not already. */
|
|
58
|
+
readonly extraInclude?: readonly string[];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class Matcher {
|
|
62
|
+
private readonly entries: readonly PatternEntry[];
|
|
63
|
+
|
|
64
|
+
constructor(entries: readonly PatternEntry[]) {
|
|
65
|
+
this.entries = entries;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Decide whether a path (relative, forward-slash) is ignored, with reason. */
|
|
69
|
+
matchWithReason(path: string, isDir: boolean): MatchReason {
|
|
70
|
+
const components = pathToComponents(path);
|
|
71
|
+
if (components.length === 0) {
|
|
72
|
+
return { ignored: false, reason: Reason.NoMatch, source: "", pattern: "" };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let lastMatch: PatternEntry | undefined;
|
|
76
|
+
let lastResult = MatchResult.NoMatch;
|
|
77
|
+
for (const entry of this.entries) {
|
|
78
|
+
const result = entry.pattern.match(components, isDir);
|
|
79
|
+
if (result !== MatchResult.NoMatch) {
|
|
80
|
+
lastMatch = entry;
|
|
81
|
+
lastResult = result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (lastMatch === undefined) {
|
|
86
|
+
return { ignored: false, reason: Reason.NoMatch, source: "", pattern: "" };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (lastResult === MatchResult.Exclude) {
|
|
90
|
+
const reason = lastMatch.source === SOURCE_DEFAULTS ? Reason.DefaultDeny : Reason.Excluded;
|
|
91
|
+
return { ignored: true, reason, source: lastMatch.source, pattern: lastMatch.raw };
|
|
92
|
+
}
|
|
93
|
+
// Include (negation): explicitly un-ignored.
|
|
94
|
+
return { ignored: false, reason: Reason.Included, source: lastMatch.source, pattern: lastMatch.raw };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Whether the path should be excluded from the artifact. */
|
|
98
|
+
match(path: string, isDir: boolean): boolean {
|
|
99
|
+
return this.matchWithReason(path, isDir).ignored;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** All loaded patterns as "[source] pattern" (for dry-run diagnostics). */
|
|
103
|
+
patterns(): string[] {
|
|
104
|
+
return this.entries.map((entry) => `[${entry.source}] ${entry.raw}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Build a matcher from its sources; the pure core every reader shares. */
|
|
109
|
+
export function buildMatcher(sources: IgnoreSources): Matcher {
|
|
110
|
+
const entries: PatternEntry[] = [];
|
|
111
|
+
if (sources.includeDefaults) {
|
|
112
|
+
entries.push(...parseEntries(DEFAULT_PATTERNS, SOURCE_DEFAULTS));
|
|
113
|
+
}
|
|
114
|
+
if (sources.gitignore !== undefined) {
|
|
115
|
+
entries.push(...parseEntries(sources.gitignore.split(/\r?\n/), SOURCE_GITIGNORE));
|
|
116
|
+
}
|
|
117
|
+
if (sources.stigmerignore !== undefined) {
|
|
118
|
+
entries.push(...parseEntries(sources.stigmerignore.split(/\r?\n/), SOURCE_STIGMERIGNORE));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const extraIgnore = sources.extraIgnore ?? [];
|
|
122
|
+
const extraInclude = sources.extraInclude ?? [];
|
|
123
|
+
if (extraIgnore.length > 0 || extraInclude.length > 0) {
|
|
124
|
+
entries.push(...loadCliPatterns(extraIgnore, extraInclude));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return new Matcher(entries);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseEntries(patterns: readonly string[], source: string): PatternEntry[] {
|
|
131
|
+
const entries: PatternEntry[] = [];
|
|
132
|
+
for (const raw of patterns) {
|
|
133
|
+
const trimmed = raw.trim();
|
|
134
|
+
if (trimmed === "" || trimmed.startsWith("#")) continue;
|
|
135
|
+
entries.push({ pattern: parsePattern(trimmed, []), source, raw: trimmed });
|
|
136
|
+
}
|
|
137
|
+
return entries;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function loadCliPatterns(ignore: readonly string[], include: readonly string[]): PatternEntry[] {
|
|
141
|
+
const entries = parseEntries(ignore, SOURCE_CLI);
|
|
142
|
+
const negations: string[] = [];
|
|
143
|
+
for (const pattern of include) {
|
|
144
|
+
const trimmed = pattern.trim();
|
|
145
|
+
if (trimmed === "") continue;
|
|
146
|
+
negations.push(trimmed.startsWith("!") ? trimmed : `!${trimmed}`);
|
|
147
|
+
}
|
|
148
|
+
entries.push(...parseEntries(negations, SOURCE_CLI));
|
|
149
|
+
return entries;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function pathToComponents(path: string): string[] {
|
|
153
|
+
const normalized = path.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
154
|
+
if (normalized === "" || normalized === ".") return [];
|
|
155
|
+
return normalized.split("/");
|
|
156
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Faithful port of go-git's plumbing/format/gitignore Pattern (ParsePattern +
|
|
2
|
+
// Match). This is what gives `push` its exact gitignore semantics: domain
|
|
3
|
+
// scoping, directory-only patterns, single-name vs glob matching, and the
|
|
4
|
+
// `**` zero-to-many-directories wildcard.
|
|
5
|
+
|
|
6
|
+
import { matchName } from "./match.js";
|
|
7
|
+
import { trimTrailing } from "../../trim.js";
|
|
8
|
+
|
|
9
|
+
export enum MatchResult {
|
|
10
|
+
NoMatch = 0,
|
|
11
|
+
Exclude = 1,
|
|
12
|
+
Include = 2,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const INCLUSION_PREFIX = "!";
|
|
16
|
+
const ZERO_TO_MANY = "**";
|
|
17
|
+
const DIR_SEP = "/";
|
|
18
|
+
|
|
19
|
+
export interface Pattern {
|
|
20
|
+
/** Whether this is a negation (`!`) pattern — needed for source ordering. */
|
|
21
|
+
readonly inclusion: boolean;
|
|
22
|
+
match(path: readonly string[], isDir: boolean): MatchResult;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class GitignorePattern implements Pattern {
|
|
26
|
+
readonly inclusion: boolean;
|
|
27
|
+
private readonly domain: readonly string[];
|
|
28
|
+
private readonly parts: readonly string[];
|
|
29
|
+
private readonly dirOnly: boolean;
|
|
30
|
+
private readonly isGlob: boolean;
|
|
31
|
+
|
|
32
|
+
constructor(domain: readonly string[], parts: readonly string[], inclusion: boolean, dirOnly: boolean, isGlob: boolean) {
|
|
33
|
+
this.domain = domain;
|
|
34
|
+
this.parts = parts;
|
|
35
|
+
this.inclusion = inclusion;
|
|
36
|
+
this.dirOnly = dirOnly;
|
|
37
|
+
this.isGlob = isGlob;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
match(path: readonly string[], isDir: boolean): MatchResult {
|
|
41
|
+
const matchResult = this.inclusion ? MatchResult.Include : MatchResult.Exclude;
|
|
42
|
+
|
|
43
|
+
if (path.length <= this.domain.length) return MatchResult.NoMatch;
|
|
44
|
+
for (let i = 0; i < this.domain.length; i++) {
|
|
45
|
+
if (path[i] !== this.domain[i]) return MatchResult.NoMatch;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const scoped = path.slice(this.domain.length);
|
|
49
|
+
const matched = this.isGlob ? this.globMatch(scoped, isDir) : this.simpleNameMatch(scoped, isDir);
|
|
50
|
+
return matched ? matchResult : MatchResult.NoMatch;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private simpleNameMatch(path: readonly string[], isDir: boolean): boolean {
|
|
54
|
+
for (let i = 0; i < path.length; i++) {
|
|
55
|
+
if (!matchName(this.parts[0] ?? "", path[i] ?? "")) continue;
|
|
56
|
+
if (this.dirOnly && !isDir && i === path.length - 1) return false;
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private globMatch(path: readonly string[], isDir: boolean): boolean {
|
|
63
|
+
let matched = false;
|
|
64
|
+
let canTraverse = false;
|
|
65
|
+
let remaining = path;
|
|
66
|
+
|
|
67
|
+
for (let i = 0; i < this.parts.length; i++) {
|
|
68
|
+
const part = this.parts[i] ?? "";
|
|
69
|
+
if (part === "") {
|
|
70
|
+
canTraverse = false;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (part === ZERO_TO_MANY) {
|
|
74
|
+
if (i === this.parts.length - 1) break;
|
|
75
|
+
canTraverse = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (part.includes(ZERO_TO_MANY)) return false;
|
|
79
|
+
if (remaining.length === 0) return false;
|
|
80
|
+
|
|
81
|
+
if (canTraverse) {
|
|
82
|
+
canTraverse = false;
|
|
83
|
+
for (;;) {
|
|
84
|
+
if (remaining.length === 0) {
|
|
85
|
+
matched = false;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
const e = remaining[0] ?? "";
|
|
89
|
+
remaining = remaining.slice(1);
|
|
90
|
+
if (matchName(part, e)) {
|
|
91
|
+
matched = true;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
if (!matchName(part, remaining[0] ?? "")) return false;
|
|
97
|
+
matched = true;
|
|
98
|
+
remaining = remaining.slice(1);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (matched && this.dirOnly && !isDir && remaining.length === 0) {
|
|
103
|
+
matched = false;
|
|
104
|
+
}
|
|
105
|
+
return matched;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Parse a gitignore pattern string into a matchable Pattern (go-git parity). */
|
|
110
|
+
export function parsePattern(raw: string, domain: readonly string[]): Pattern {
|
|
111
|
+
let p = raw;
|
|
112
|
+
let inclusion = false;
|
|
113
|
+
|
|
114
|
+
if (p.startsWith(INCLUSION_PREFIX)) {
|
|
115
|
+
inclusion = true;
|
|
116
|
+
p = p.slice(1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!p.endsWith("\\ ")) {
|
|
120
|
+
p = trimTrailing(p, " ");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let dirOnly = false;
|
|
124
|
+
if (p.endsWith(DIR_SEP)) {
|
|
125
|
+
dirOnly = true;
|
|
126
|
+
p = p.slice(0, -1);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const isGlob = p.includes(DIR_SEP);
|
|
130
|
+
const parts = p.split(DIR_SEP);
|
|
131
|
+
return new GitignorePattern(domain, parts, inclusion, dirOnly, isGlob);
|
|
132
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preparation every client runs for an eval push: from an
|
|
3
|
+
* already-selected evals/ folder, leave out the run output, refuse what
|
|
4
|
+
* the server refuses, archive, digest, and say what the server will read.
|
|
5
|
+
*
|
|
6
|
+
* An eval is Claude Code's `evals/` folder pushed whole: its case
|
|
7
|
+
* directories, `mocks/` and any shared files at the archive's root.
|
|
8
|
+
* `results/` at the root is what `claude plugin eval` writes when it runs
|
|
9
|
+
* the cases, never part of the suite, so it is left out before the archive
|
|
10
|
+
* is built and two pushes of one suite have one digest whatever was run in
|
|
11
|
+
* between. A folder holding a plugin manifest is a plugin, not its evals,
|
|
12
|
+
* and is refused naming the folder to push instead; a folder where no case
|
|
13
|
+
* loads is refused with the reader's findings, as the server refuses it.
|
|
14
|
+
*
|
|
15
|
+
* The archive is `archivePlugin`'s, the selection's order and the one
|
|
16
|
+
* mtime, so the digest a client computes is the server's `status.digest`.
|
|
17
|
+
* Refusals are returned, not thrown: each client renders them in its own
|
|
18
|
+
* voice. Pinned by `__tests__/client-prepare-eval.test.ts`.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { hasPluginManifest } from "../detect.js";
|
|
22
|
+
import type { PluginFiles } from "../files.js";
|
|
23
|
+
import { readEvalFolder } from "../evals/read-eval-suite.js";
|
|
24
|
+
import type { EvalSuite, EvalSuiteFinding } from "../evals/types.js";
|
|
25
|
+
import { archivePlugin, digestArchive } from "./archive.js";
|
|
26
|
+
import type { SelectionStats } from "./select.js";
|
|
27
|
+
|
|
28
|
+
/** The run output `claude plugin eval` writes beside the cases; never pushed. */
|
|
29
|
+
export const EVAL_RESULTS_DIR = "results";
|
|
30
|
+
|
|
31
|
+
/** What a client holds after preparing an eval: the reading, the bytes a push sends, and their identity. */
|
|
32
|
+
export interface PreparedEval {
|
|
33
|
+
/** The folder as the server will read it: its cases, findings and mocked servers. */
|
|
34
|
+
readonly suite: EvalSuite;
|
|
35
|
+
/** The files the archive carries, `results/` left out. */
|
|
36
|
+
readonly files: PluginFiles;
|
|
37
|
+
readonly stats: SelectionStats;
|
|
38
|
+
/** The exact bytes a push sends. */
|
|
39
|
+
readonly archive: Uint8Array;
|
|
40
|
+
/** SHA-256 of `archive`, lowercase hex: the server's `status.digest` for these bytes. */
|
|
41
|
+
readonly digest: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** What a selected folder can come to. */
|
|
45
|
+
export type PrepareEvalOutcome =
|
|
46
|
+
| { readonly ok: true; readonly prepared: PreparedEval }
|
|
47
|
+
/** The folder holds a plugin manifest: push its evals/ folder instead. */
|
|
48
|
+
| { readonly ok: false; readonly kind: "plugin-folder" }
|
|
49
|
+
/** No case in the folder loads; `findings` say why, as the server would. */
|
|
50
|
+
| { readonly ok: false; readonly kind: "no-cases"; readonly findings: readonly EvalSuiteFinding[] };
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Prepare an already-selected evals/ folder. `selection` is what
|
|
54
|
+
* `selectPluginFiles` returns or what the CLI's walk builds in its shape;
|
|
55
|
+
* its `files.read` must answer synchronously for every listed entry.
|
|
56
|
+
*/
|
|
57
|
+
export async function prepareEvalArchive(selection: {
|
|
58
|
+
readonly files: PluginFiles;
|
|
59
|
+
readonly stats: SelectionStats;
|
|
60
|
+
}): Promise<PrepareEvalOutcome> {
|
|
61
|
+
const { files, stats } = withoutResults(selection);
|
|
62
|
+
if (hasPluginManifest(files.entries.map((entry) => entry.path))) {
|
|
63
|
+
return { ok: false, kind: "plugin-folder" };
|
|
64
|
+
}
|
|
65
|
+
const suite = readEvalFolder(files);
|
|
66
|
+
if (suite.cases.length === 0) {
|
|
67
|
+
return { ok: false, kind: "no-cases", findings: suite.findings };
|
|
68
|
+
}
|
|
69
|
+
const archive = archivePlugin(files);
|
|
70
|
+
return { ok: true, prepared: { suite, files, stats, archive, digest: await digestArchive(archive) } };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The selection with the root `results/` directory left out, its files counted as ignored. */
|
|
74
|
+
function withoutResults(selection: { readonly files: PluginFiles; readonly stats: SelectionStats }): {
|
|
75
|
+
readonly files: PluginFiles;
|
|
76
|
+
readonly stats: SelectionStats;
|
|
77
|
+
} {
|
|
78
|
+
const prefix = `${EVAL_RESULTS_DIR}/`;
|
|
79
|
+
const dropped = selection.files.entries.filter((entry) => entry.path.startsWith(prefix));
|
|
80
|
+
if (dropped.length === 0) return selection;
|
|
81
|
+
const entries = selection.files.entries.filter((entry) => !entry.path.startsWith(prefix));
|
|
82
|
+
const droppedSize = dropped.reduce((total, entry) => total + entry.size, 0);
|
|
83
|
+
return {
|
|
84
|
+
files: { entries, read: (path) => selection.files.read(path) },
|
|
85
|
+
stats: {
|
|
86
|
+
filesIncluded: selection.stats.filesIncluded - dropped.length,
|
|
87
|
+
filesIgnored: selection.stats.filesIgnored + dropped.length,
|
|
88
|
+
dirsSkipped: selection.stats.dirsSkipped + 1,
|
|
89
|
+
totalSize: selection.stats.totalSize - droppedSize,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The preparation every client runs once it holds a tree: select the files
|
|
3
|
+
* a push carries, read the package and refuse what the reader refuses,
|
|
4
|
+
* archive, digest.
|
|
5
|
+
*
|
|
6
|
+
* Three clients arrive here with three kinds of tree: the CLI with a
|
|
7
|
+
* directory on disk, the console with a marketplace host's file listing,
|
|
8
|
+
* and the console again with a folder or a zip the user picked. What they
|
|
9
|
+
* do after selection is identical, and it is where the plugin's identity
|
|
10
|
+
* is made (the archive's bytes are `status.digest`), so it is written once.
|
|
11
|
+
* A parity test proves that one function reached three ways yields one
|
|
12
|
+
* digest for one tree; before this module each client carried its own copy
|
|
13
|
+
* of the chain and the test proved a coincidence.
|
|
14
|
+
*
|
|
15
|
+
* `preparePluginFromTree` is the lazy form for a tree whose bytes cost
|
|
16
|
+
* something to obtain (a fetch per file, a `File.arrayBuffer()`): it reads
|
|
17
|
+
* the two root ignore files, selects, refuses an over-cap selection before
|
|
18
|
+
* another byte moves, then reads only the files the archive will carry. A
|
|
19
|
+
* plugin folder holding a `node_modules/` costs its ignore file and its
|
|
20
|
+
* manifest, wherever the tree lives. The CLI keeps its own walk (a
|
|
21
|
+
* filesystem lets it skip a directory before listing it, which a flat tree
|
|
22
|
+
* cannot) and joins at `preparePluginArchive`.
|
|
23
|
+
*
|
|
24
|
+
* Refusals are returned, not thrown: each client renders the reader's
|
|
25
|
+
* findings in its own voice (the CLI's `pluginRefusal`, the console's
|
|
26
|
+
* `PluginReadRefusal`) and adds its own provenance around the result.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { PluginFiles } from "../files.js";
|
|
30
|
+
import type { PluginFinding } from "../outcome.js";
|
|
31
|
+
import { readPluginPackage } from "../read-plugin-package.js";
|
|
32
|
+
import type { PluginPackage } from "../types.js";
|
|
33
|
+
import { archivePlugin, digestArchive } from "./archive.js";
|
|
34
|
+
import {
|
|
35
|
+
type CandidateFile,
|
|
36
|
+
type SelectPluginFilesOptions,
|
|
37
|
+
type SelectionStats,
|
|
38
|
+
IGNORE_FILE_NAMES,
|
|
39
|
+
selectPluginFiles,
|
|
40
|
+
} from "./select.js";
|
|
41
|
+
|
|
42
|
+
/** What a client holds after preparation: the package as read, the bytes a push sends, and their identity. */
|
|
43
|
+
export interface PreparedPlugin {
|
|
44
|
+
readonly plugin: PluginPackage;
|
|
45
|
+
readonly warnings: readonly PluginFinding[];
|
|
46
|
+
/** The selected files, for the client that lists them (`push --dry-run`). */
|
|
47
|
+
readonly files: PluginFiles;
|
|
48
|
+
readonly stats: SelectionStats;
|
|
49
|
+
/** The exact bytes a push sends. */
|
|
50
|
+
readonly archive: Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* SHA-256 of `archive`, lowercase hex: the identity the server records as
|
|
53
|
+
* `status.digest` (its digest is over the bytes it receives, and these are
|
|
54
|
+
* those bytes), so a client knows "already installed" without pushing.
|
|
55
|
+
*/
|
|
56
|
+
readonly digest: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What an already-selected tree can come to: a prepared plugin, or the reader's refusal. */
|
|
60
|
+
export type PrepareArchiveOutcome =
|
|
61
|
+
| { readonly ok: true; readonly prepared: PreparedPlugin }
|
|
62
|
+
/** The reader refused the package; `errors` are its sentences, as `stigmer validate -f` prints them. */
|
|
63
|
+
| {
|
|
64
|
+
readonly ok: false;
|
|
65
|
+
readonly kind: "refused";
|
|
66
|
+
readonly errors: readonly PluginFinding[];
|
|
67
|
+
readonly warnings: readonly PluginFinding[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** What a lazily-read tree can come to: the above, or a refusal on size before its bytes were read. */
|
|
71
|
+
export type PreparePluginOutcome =
|
|
72
|
+
| PrepareArchiveOutcome
|
|
73
|
+
/** The selected files exceed the caller's `maxBytes`; nothing beyond the ignore files was read. */
|
|
74
|
+
| { readonly ok: false; readonly kind: "too-large"; readonly selectedBytes: number; readonly maxBytes: number };
|
|
75
|
+
|
|
76
|
+
/** A tree the client can list now and read later: a candidate with the promise of its bytes. */
|
|
77
|
+
export interface LazyCandidate extends CandidateFile {
|
|
78
|
+
read(): Promise<Uint8Array>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface PrepareFromTreeOptions extends SelectPluginFilesOptions {
|
|
82
|
+
/**
|
|
83
|
+
* The most bytes the SELECTED files may total, refused before they are
|
|
84
|
+
* read. A client states its own budget (the console's is the archive cap
|
|
85
|
+
* a browser will hold in memory); omitted, nothing is refused here and
|
|
86
|
+
* the server's zip gate is the only limit.
|
|
87
|
+
*/
|
|
88
|
+
readonly maxBytes?: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Read, refuse, archive and digest an already-selected tree. `selection`
|
|
93
|
+
* is what `selectPluginFiles` returns or what the CLI's walk builds in the
|
|
94
|
+
* same shape; its `files.read` must answer synchronously for every listed
|
|
95
|
+
* entry by now.
|
|
96
|
+
*/
|
|
97
|
+
export async function preparePluginArchive(selection: {
|
|
98
|
+
readonly files: PluginFiles;
|
|
99
|
+
readonly stats: SelectionStats;
|
|
100
|
+
}): Promise<PrepareArchiveOutcome> {
|
|
101
|
+
const outcome = readPluginPackage(selection.files);
|
|
102
|
+
if (!outcome.ok) {
|
|
103
|
+
return { ok: false, kind: "refused", errors: outcome.errors, warnings: outcome.warnings };
|
|
104
|
+
}
|
|
105
|
+
const archive = archivePlugin(selection.files);
|
|
106
|
+
return {
|
|
107
|
+
ok: true,
|
|
108
|
+
prepared: {
|
|
109
|
+
plugin: outcome.plugin,
|
|
110
|
+
warnings: outcome.warnings,
|
|
111
|
+
files: selection.files,
|
|
112
|
+
stats: selection.stats,
|
|
113
|
+
archive,
|
|
114
|
+
digest: await digestArchive(archive),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Prepare a tree whose bytes are obtained on demand. A byte is read only
|
|
121
|
+
* for a file that will be in the archive (plus the two root ignore files
|
|
122
|
+
* that decide which those are), and an over-cap selection is refused
|
|
123
|
+
* before any of them.
|
|
124
|
+
*/
|
|
125
|
+
export async function preparePluginFromTree(
|
|
126
|
+
candidates: readonly LazyCandidate[],
|
|
127
|
+
options: PrepareFromTreeOptions,
|
|
128
|
+
): Promise<PreparePluginOutcome> {
|
|
129
|
+
const byPath = new Map(candidates.map((candidate) => [candidate.path, candidate]));
|
|
130
|
+
const contents = new Map<string, Uint8Array>();
|
|
131
|
+
const fetchInto = async (path: string): Promise<void> => {
|
|
132
|
+
const candidate = byPath.get(path);
|
|
133
|
+
if (candidate === undefined) throw new Error(`plugin file '${path}' is not listed`);
|
|
134
|
+
contents.set(path, await candidate.read());
|
|
135
|
+
};
|
|
136
|
+
const read = (path: string): Uint8Array => {
|
|
137
|
+
const bytes = contents.get(path);
|
|
138
|
+
if (bytes === undefined) throw new Error(`plugin file '${path}' was not read before selection asked for it`);
|
|
139
|
+
return bytes;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Phase 1: only the two files that shape the selection.
|
|
143
|
+
await Promise.all(
|
|
144
|
+
[IGNORE_FILE_NAMES.gitignore, IGNORE_FILE_NAMES.stigmerignore]
|
|
145
|
+
.filter((name) => byPath.has(name))
|
|
146
|
+
.map((name) => fetchInto(name)),
|
|
147
|
+
);
|
|
148
|
+
const { maxBytes, ...selectOptions } = options;
|
|
149
|
+
const selection = selectPluginFiles(candidates, read, selectOptions);
|
|
150
|
+
|
|
151
|
+
if (maxBytes !== undefined && selection.stats.totalSize > maxBytes) {
|
|
152
|
+
return { ok: false, kind: "too-large", selectedBytes: selection.stats.totalSize, maxBytes };
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Phase 2: exactly the files the archive carries.
|
|
156
|
+
await Promise.all(
|
|
157
|
+
selection.files.entries.filter((entry) => !contents.has(entry.path)).map((entry) => fetchInto(entry.path)),
|
|
158
|
+
);
|
|
159
|
+
return preparePluginArchive(selection);
|
|
160
|
+
}
|