@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,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plugin's presentation from a tree whose bytes cost something to obtain:
|
|
3
|
+
* the lazy twin of `readPluginPresentation`, as `preparePluginFromTree` is
|
|
4
|
+
* the lazy twin of the full read.
|
|
5
|
+
*
|
|
6
|
+
* A storefront lists a catalogue from one file and then shows a card per
|
|
7
|
+
* entry; the face on each card is in that entry's manifest, one small file
|
|
8
|
+
* in a directory the client has listed but not read. This reads exactly the
|
|
9
|
+
* manifest paths the listing shows (one, rarely two) and nothing else, then
|
|
10
|
+
* hands a `PluginFiles` whose `read` answers for those paths alone to the
|
|
11
|
+
* pure reader. A manifest that cannot be fetched contributes nothing, the
|
|
12
|
+
* pure reader's own rule for a manifest that cannot be parsed: a card is
|
|
13
|
+
* never refused, it is drawn with what arrived.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { comparePaths, type PluginFiles } from "../files.js";
|
|
17
|
+
import { MANIFEST_LOCATIONS } from "../messages.js";
|
|
18
|
+
import { type PluginPresentation, readPluginPresentation } from "../presentation.js";
|
|
19
|
+
import type { LazyCandidate } from "./prepare.js";
|
|
20
|
+
|
|
21
|
+
const MANIFEST_PATHS: ReadonlySet<string> = new Set(Object.values(MANIFEST_LOCATIONS));
|
|
22
|
+
|
|
23
|
+
/** The presentation of the plugin whose files `candidates` list, reading only its manifests. */
|
|
24
|
+
export async function readPluginPresentationFromTree(candidates: readonly LazyCandidate[]): Promise<PluginPresentation> {
|
|
25
|
+
const contents = new Map<string, Uint8Array>();
|
|
26
|
+
await Promise.all(
|
|
27
|
+
candidates
|
|
28
|
+
.filter((candidate) => MANIFEST_PATHS.has(candidate.path))
|
|
29
|
+
.map(async (candidate) => {
|
|
30
|
+
try {
|
|
31
|
+
contents.set(candidate.path, await candidate.read());
|
|
32
|
+
} catch {
|
|
33
|
+
// Unfetchable is unreadable: the pure reader skips a manifest it cannot open.
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
const files: PluginFiles = {
|
|
38
|
+
// `PluginFiles` promises a sorted listing; a host's tree order is its own.
|
|
39
|
+
entries: candidates.map(({ path, size }) => ({ path, size })).sort((a, b) => comparePaths(a.path, b.path)),
|
|
40
|
+
read: (path) => {
|
|
41
|
+
const bytes = contents.get(path);
|
|
42
|
+
if (bytes === undefined) throw new Error(`plugin file '${path}' was not fetched for presentation`);
|
|
43
|
+
return bytes;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
return readPluginPresentation(files);
|
|
47
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two grammars a user types at any marketplace surface, and the words
|
|
3
|
+
* every client uses for what they name.
|
|
4
|
+
*
|
|
5
|
+
* `install [marketplace/]name[@version]`: the plugin's name in its
|
|
6
|
+
* marketplace, optionally qualified by the marketplace's name and pinned to
|
|
7
|
+
* the version the entry's manifest must carry. Both names obey the plugin
|
|
8
|
+
* name rule (`isValidPluginName`: lowercase letters, digits, `.` and `-`,
|
|
9
|
+
* never `/` or `@`), which is what makes the grammar unambiguous: the first
|
|
10
|
+
* `/` splits the marketplace off, the first `@` splits the version off, and
|
|
11
|
+
* anything else is not a ref. A path (`./thermos`, `/tmp/x`, `..`) is the
|
|
12
|
+
* one likely mistake and gets its own sentence, so a client can point at
|
|
13
|
+
* the command that installs a folder.
|
|
14
|
+
*
|
|
15
|
+
* A GitHub marketplace source: `owner/repo[@ref]`, or the URL a browser
|
|
16
|
+
* shows for that repository (`https://github.com/owner/repo[/tree/<ref>]`),
|
|
17
|
+
* normalised to one record. Every vendor keeps its marketplace file at the
|
|
18
|
+
* repository root, so a subdirectory grammar is not offered.
|
|
19
|
+
*
|
|
20
|
+
* Refusals are returned, not thrown: the CLI wraps one in its `UsageError`
|
|
21
|
+
* and the console renders it, and the sentence is the same in both. A
|
|
22
|
+
* client adds the second paragraph naming its own command.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { isValidPluginName } from "../detect.js";
|
|
26
|
+
|
|
27
|
+
/** The built-in marketplace's name: the prefix in `install stigmer/<plugin>`; reserved in every client. */
|
|
28
|
+
export const OFFICIAL_MARKETPLACE_NAME = "stigmer";
|
|
29
|
+
|
|
30
|
+
export interface InstallRef {
|
|
31
|
+
/** The marketplace named before the `/`, or `undefined` when the name stands alone. */
|
|
32
|
+
readonly marketplace?: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
/** The version named after the `@`, asserted against the entry's manifest. */
|
|
35
|
+
readonly version?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type InstallRefOutcome =
|
|
39
|
+
| { readonly ok: true; readonly ref: InstallRef }
|
|
40
|
+
| {
|
|
41
|
+
readonly ok: false;
|
|
42
|
+
/** `path` when the text names a folder rather than a plugin; `shape` for every other refusal. */
|
|
43
|
+
readonly kind: "path" | "shape";
|
|
44
|
+
readonly message: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The characters a `@version` may carry: the plugin's tag pattern, so what a ref pins is a tag the server can hold. */
|
|
48
|
+
const VERSION_PATTERN = /^[a-zA-Z0-9._-]+$/;
|
|
49
|
+
|
|
50
|
+
/** The grammar in the user's terms, quoted by every refusal. */
|
|
51
|
+
export const INSTALL_REF_SHAPE =
|
|
52
|
+
"[marketplace/]name[@version], for example 'thermos', 'cursor-plugins/thermos' or 'thermos@1.0.0'";
|
|
53
|
+
|
|
54
|
+
export function parseInstallRef(text: string): InstallRefOutcome {
|
|
55
|
+
if (looksLikePath(text)) {
|
|
56
|
+
return {
|
|
57
|
+
ok: false,
|
|
58
|
+
kind: "path",
|
|
59
|
+
message: `'${text}' is a path, and 'install' takes a plugin's name in a marketplace`,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
let rest = text;
|
|
63
|
+
let marketplace: string | undefined;
|
|
64
|
+
const slash = rest.indexOf("/");
|
|
65
|
+
if (slash !== -1) {
|
|
66
|
+
marketplace = rest.slice(0, slash);
|
|
67
|
+
rest = rest.slice(slash + 1);
|
|
68
|
+
if (!isValidPluginName(marketplace)) {
|
|
69
|
+
return { ok: false, kind: "shape", message: `'${marketplace}' is not a marketplace name` };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let version: string | undefined;
|
|
73
|
+
const at = rest.indexOf("@");
|
|
74
|
+
if (at !== -1) {
|
|
75
|
+
version = rest.slice(at + 1);
|
|
76
|
+
rest = rest.slice(0, at);
|
|
77
|
+
if (version === "" || !VERSION_PATTERN.test(version)) {
|
|
78
|
+
return { ok: false, kind: "shape", message: `'${version}' is not a version` };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!isValidPluginName(rest)) {
|
|
82
|
+
return { ok: false, kind: "shape", message: `'${rest}' is not a plugin name` };
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
ref: {
|
|
87
|
+
...(marketplace !== undefined && { marketplace }),
|
|
88
|
+
name: rest,
|
|
89
|
+
...(version !== undefined && { version }),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The grammar's own text for a ref, the inverse of `parseInstallRef`. */
|
|
95
|
+
export function formatInstallRef(ref: InstallRef): string {
|
|
96
|
+
const prefix = ref.marketplace === undefined ? "" : `${ref.marketplace}/`;
|
|
97
|
+
const suffix = ref.version === undefined ? "" : `@${ref.version}`;
|
|
98
|
+
return `${prefix}${ref.name}${suffix}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Whether `text` reads as a filesystem path on any platform (relative, home, absolute, Windows). */
|
|
102
|
+
export function looksLikePath(text: string): boolean {
|
|
103
|
+
return (
|
|
104
|
+
text === "." ||
|
|
105
|
+
text === ".." ||
|
|
106
|
+
text.startsWith("./") ||
|
|
107
|
+
text.startsWith("../") ||
|
|
108
|
+
text.startsWith("~") ||
|
|
109
|
+
text.startsWith("/") ||
|
|
110
|
+
text.includes("\\") ||
|
|
111
|
+
/^[A-Za-z]:/.test(text)
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** A public GitHub repository at a ref; the default branch when `ref` is absent. */
|
|
116
|
+
export interface GitHubMarketplaceSource {
|
|
117
|
+
readonly type: "github";
|
|
118
|
+
/** `owner/repo`. */
|
|
119
|
+
readonly repo: string;
|
|
120
|
+
/** Branch, tag or commit. */
|
|
121
|
+
readonly ref?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type GitHubSourceOutcome =
|
|
125
|
+
| { readonly ok: true; readonly source: GitHubMarketplaceSource }
|
|
126
|
+
| { readonly ok: false; readonly message: string };
|
|
127
|
+
|
|
128
|
+
/** What a GitHub source may be typed as, quoted by every refusal. */
|
|
129
|
+
export const GITHUB_SOURCE_SHAPE =
|
|
130
|
+
"a GitHub repository as 'owner/repo' or 'owner/repo@ref', or that repository's URL (https://github.com/owner/repo)";
|
|
131
|
+
|
|
132
|
+
const GITHUB_URL = /^https?:\/\/(?:www\.)?github\.com\/([^/\s]+)\/([^/\s#?]+?)(?:\.git)?(?:\/tree\/([^\s#?]+))?\/?$/;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* `owner/repo[@ref]` or a github.com URL as one source. The URL form is
|
|
136
|
+
* tried first because it contains a `/` too; a text that is neither is
|
|
137
|
+
* refused with the shape.
|
|
138
|
+
*/
|
|
139
|
+
export function parseGitHubSource(text: string): GitHubSourceOutcome {
|
|
140
|
+
const url = GITHUB_URL.exec(text);
|
|
141
|
+
if (url !== null) {
|
|
142
|
+
const repo = `${url[1] ?? ""}/${url[2] ?? ""}`;
|
|
143
|
+
if (!isOwnerRepo(repo)) {
|
|
144
|
+
return { ok: false, message: `'${text}' does not name a GitHub repository` };
|
|
145
|
+
}
|
|
146
|
+
const ref = url[3];
|
|
147
|
+
return { ok: true, source: { type: "github", repo, ...(ref !== undefined && ref !== "" && { ref }) } };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const at = text.indexOf("@");
|
|
151
|
+
const repo = at === -1 ? text : text.slice(0, at);
|
|
152
|
+
const ref = at === -1 ? undefined : text.slice(at + 1);
|
|
153
|
+
if (isOwnerRepo(repo) && (ref === undefined || ref !== "")) {
|
|
154
|
+
return { ok: true, source: { type: "github", repo, ...(ref !== undefined && { ref }) } };
|
|
155
|
+
}
|
|
156
|
+
return { ok: false, message: `'${text}' is not a GitHub 'owner/repo'` };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** One phrase naming a GitHub source, for lists and sentences. */
|
|
160
|
+
export function describeGitHubSource(source: GitHubMarketplaceSource): string {
|
|
161
|
+
return source.ref === undefined ? `github.com/${source.repo}` : `github.com/${source.repo}@${source.ref}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const OWNER_REPO_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
165
|
+
|
|
166
|
+
/** `owner/repo` as GitHub spells it: two segments, no `.git` suffix required or refused. */
|
|
167
|
+
export function isOwnerRepo(value: string): boolean {
|
|
168
|
+
const parts = value.split("/");
|
|
169
|
+
return parts.length === 2 && parts.every((part) => OWNER_REPO_SEGMENT.test(part) && part !== "." && part !== "..");
|
|
170
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a version string names a release the lockstep publish covers.
|
|
3
|
+
*
|
|
4
|
+
* The official catalogue (`@stigmer/plugins`) and the runtime packages are
|
|
5
|
+
* published at every release version and at every pre-release the release
|
|
6
|
+
* lane cuts (`X.Y.Z-rc.1` under the `next` tag), never for a source build
|
|
7
|
+
* (`dev`, `0.0.0-dev`), a dev-channel stamp (`X.Y.Z-dev.<stamp>`) or a
|
|
8
|
+
* local build (`0.0.0-local.<stamp>`, scripts/stage-server-library.mjs). Two
|
|
9
|
+
* clients used to answer this with two different tests: the console
|
|
10
|
+
* accepted only `X.Y.Z` and called an `rc` server a development build; the
|
|
11
|
+
* CLI accepted anything without `-dev` and would have tried to acquire
|
|
12
|
+
* packages for the bare `dev` an unbundled server reports. One predicate,
|
|
13
|
+
* its cases pinned, no third opinion. The server reads it too: a release
|
|
14
|
+
* server's sandbox drivers hold the runner layer to that release, so a
|
|
15
|
+
* local build read as one refused every layer that named a real release
|
|
16
|
+
* (stigmer/stigmer#1867).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A semver core, optionally followed by a pre-release whose first
|
|
21
|
+
* identifier is neither `dev` nor `local`. Build metadata (`+…`) is not
|
|
22
|
+
* accepted: nothing publishes with it.
|
|
23
|
+
*/
|
|
24
|
+
const RELEASE_PATTERN = /^\d+\.\d+\.\d+(?:-(?!(?:dev|local)(?:[.-]|$))[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
|
|
25
|
+
|
|
26
|
+
/** True for `3.17.0` and `3.17.0-rc.1`; false for `dev`, `0.0.0-dev`, `3.17.0-dev.20260918120000` and `0.0.0-local.20261004150608`. */
|
|
27
|
+
export function isReleaseVersion(version: string): boolean {
|
|
28
|
+
return RELEASE_PATTERN.test(version);
|
|
29
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one directory a zipped folder wraps itself in, so the archive reads
|
|
3
|
+
* as the folder.
|
|
4
|
+
*
|
|
5
|
+
* `zip -r plugin.zip my-plugin/`, a Finder "Compress", and a browser's
|
|
6
|
+
* download of a repository all produce an archive whose every path begins
|
|
7
|
+
* with the folder's own name; the manifest a reader looks for at the root
|
|
8
|
+
* is then one level down. This decides, from the paths alone, whether that
|
|
9
|
+
* is the case: it is when every path shares exactly one leading directory
|
|
10
|
+
* and nothing sits beside it. A tree with a root file, or two top-level
|
|
11
|
+
* directories, is taken as it is; a reader that then finds no manifest says
|
|
12
|
+
* so in its own words.
|
|
13
|
+
*
|
|
14
|
+
* Pure over paths; the caller strips the prefix. Kept out of `select.ts`,
|
|
15
|
+
* which reasons about a tree that already has its root.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** The shared leading directory of `paths`, or `null` when the tree is already rooted. */
|
|
19
|
+
export function rerootSingleDirectory(paths: readonly string[]): string | null {
|
|
20
|
+
let prefix: string | null = null;
|
|
21
|
+
for (const path of paths) {
|
|
22
|
+
const slash = path.indexOf("/");
|
|
23
|
+
if (slash <= 0) return null;
|
|
24
|
+
const head = path.slice(0, slash);
|
|
25
|
+
if (prefix === null) prefix = head;
|
|
26
|
+
else if (prefix !== head) return null;
|
|
27
|
+
}
|
|
28
|
+
return prefix;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** `paths` with `prefix/` removed from each; the caller has established every path carries it. */
|
|
32
|
+
export function stripDirectoryPrefix(paths: readonly string[], prefix: string): string[] {
|
|
33
|
+
const cut = prefix.length + 1;
|
|
34
|
+
return paths.map((path) => path.slice(cut));
|
|
35
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which files of a tree a plugin push carries, and in what order.
|
|
3
|
+
*
|
|
4
|
+
* A client that installs a plugin holds a tree: the CLI a directory on disk,
|
|
5
|
+
* the console the file list a marketplace host returned. Both must choose
|
|
6
|
+
* the same files in the same order, because the archive's bytes are the
|
|
7
|
+
* plugin's identity on the server (`status.digest` is the SHA-256 of what
|
|
8
|
+
* it received) and the order of the archive's entries is part of those
|
|
9
|
+
* bytes. This module is that choice, made once.
|
|
10
|
+
*
|
|
11
|
+
* The rule is the CLI's original walk (`stigmer push plugin <dir>`): at each
|
|
12
|
+
* directory the names are sorted by code point, files and directories
|
|
13
|
+
* interleaved by name, and a directory the matcher ignores is skipped whole,
|
|
14
|
+
* so no negation inside it can pull a file back. Symlinks never appear (the
|
|
15
|
+
* CLI walker skips them; a hosted tree has none the client asks for).
|
|
16
|
+
* `compareWalkOrder` states that order for a flat list of paths so a client
|
|
17
|
+
* with no directory to walk arrives at the same sequence; it is NOT the plain
|
|
18
|
+
* code-point order of full paths (`b/x.txt` sorts before `b.txt` here,
|
|
19
|
+
* because the directory `b` sorts before the file `b.txt` at their level).
|
|
20
|
+
* The reader in `read-plugin-package.ts` indexes entries by path and is
|
|
21
|
+
* indifferent to their order; only the archive cares.
|
|
22
|
+
*
|
|
23
|
+
* `.gitignore` and `.stigmerignore` are read from the root of the tree being
|
|
24
|
+
* selected, as the CLI does, never from an ancestor: a marketplace entry is
|
|
25
|
+
* its own plugin root.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import type { PluginFileEntry, PluginFiles } from "../files.js";
|
|
29
|
+
import { type IgnoreSources, type Matcher, SOURCE_GITIGNORE, SOURCE_STIGMERIGNORE, buildMatcher } from "./ignore/matcher.js";
|
|
30
|
+
|
|
31
|
+
/** The tree a client holds before selection: every file it could offer, with its size. */
|
|
32
|
+
export interface CandidateFile {
|
|
33
|
+
/** Root-relative POSIX path, no leading `./`. */
|
|
34
|
+
readonly path: string;
|
|
35
|
+
readonly size: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** What the selection included and left out, for the summary line every client prints. */
|
|
39
|
+
export interface SelectionStats {
|
|
40
|
+
filesIncluded: number;
|
|
41
|
+
filesIgnored: number;
|
|
42
|
+
/** Ignored directories that held at least one candidate; a tree lists no empty directories. */
|
|
43
|
+
dirsSkipped: number;
|
|
44
|
+
totalSize: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SelectPluginFilesOptions {
|
|
48
|
+
/** Whether the tree's own root `.gitignore` applies (every push says yes unless asked otherwise). */
|
|
49
|
+
readonly respectGitignore: boolean;
|
|
50
|
+
readonly extraIgnore?: readonly string[];
|
|
51
|
+
readonly extraInclude?: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface PluginSelection {
|
|
55
|
+
readonly files: PluginFiles;
|
|
56
|
+
readonly stats: SelectionStats;
|
|
57
|
+
/** The matcher the selection ran, for diagnostics (`push --dry-run` lists its patterns). */
|
|
58
|
+
readonly matcher: Matcher;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The two files at a tree's root that shape its own selection. */
|
|
62
|
+
export const IGNORE_FILE_NAMES = {
|
|
63
|
+
gitignore: SOURCE_GITIGNORE,
|
|
64
|
+
stigmerignore: SOURCE_STIGMERIGNORE,
|
|
65
|
+
} as const;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Select the files a push of `candidates` carries. `read` yields a listed
|
|
69
|
+
* candidate's bytes and is called here only for the two ignore files at the
|
|
70
|
+
* root, so a client may hand over a lazy reader and pay for the rest only
|
|
71
|
+
* when the archive is built.
|
|
72
|
+
*/
|
|
73
|
+
export function selectPluginFiles(
|
|
74
|
+
candidates: readonly CandidateFile[],
|
|
75
|
+
read: (path: string) => Uint8Array,
|
|
76
|
+
options: SelectPluginFilesOptions,
|
|
77
|
+
): PluginSelection {
|
|
78
|
+
const byPath = new Map(candidates.map((candidate) => [candidate.path, candidate]));
|
|
79
|
+
const sources: IgnoreSources = {
|
|
80
|
+
includeDefaults: true,
|
|
81
|
+
...(options.respectGitignore &&
|
|
82
|
+
byPath.has(IGNORE_FILE_NAMES.gitignore) && { gitignore: decode(read(IGNORE_FILE_NAMES.gitignore)) }),
|
|
83
|
+
...(byPath.has(IGNORE_FILE_NAMES.stigmerignore) && {
|
|
84
|
+
stigmerignore: decode(read(IGNORE_FILE_NAMES.stigmerignore)),
|
|
85
|
+
}),
|
|
86
|
+
...(options.extraIgnore !== undefined && { extraIgnore: options.extraIgnore }),
|
|
87
|
+
...(options.extraInclude !== undefined && { extraInclude: options.extraInclude }),
|
|
88
|
+
};
|
|
89
|
+
const matcher = buildMatcher(sources);
|
|
90
|
+
|
|
91
|
+
const stats: SelectionStats = { filesIncluded: 0, filesIgnored: 0, dirsSkipped: 0, totalSize: 0 };
|
|
92
|
+
const skippedDirs = new Set<string>();
|
|
93
|
+
const entries: PluginFileEntry[] = [];
|
|
94
|
+
|
|
95
|
+
for (const candidate of [...candidates].sort((a, b) => compareWalkOrder(a.path, b.path))) {
|
|
96
|
+
if (underSkippedDir(candidate.path, matcher, skippedDirs, stats)) continue;
|
|
97
|
+
if (matcher.matchWithReason(candidate.path, false).ignored) {
|
|
98
|
+
stats.filesIgnored++;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
entries.push({ path: candidate.path, size: candidate.size });
|
|
102
|
+
stats.filesIncluded++;
|
|
103
|
+
stats.totalSize += candidate.size;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
files: {
|
|
108
|
+
entries,
|
|
109
|
+
read(path) {
|
|
110
|
+
if (!byPath.has(path)) throw new Error(`plugin file '${path}' is not listed`);
|
|
111
|
+
return read(path);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
stats,
|
|
115
|
+
matcher,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* The order a sorted directory walk visits files: component by component,
|
|
121
|
+
* each compared by code point. Two paths never share a prefix that is a
|
|
122
|
+
* file in one and a directory in the other, so a shorter path is never a
|
|
123
|
+
* prefix of a longer one at the point they differ.
|
|
124
|
+
*/
|
|
125
|
+
export function compareWalkOrder(a: string, b: string): number {
|
|
126
|
+
const as = a.split("/");
|
|
127
|
+
const bs = b.split("/");
|
|
128
|
+
const depth = Math.min(as.length, bs.length);
|
|
129
|
+
for (let i = 0; i < depth; i++) {
|
|
130
|
+
const x = as[i] ?? "";
|
|
131
|
+
const y = bs[i] ?? "";
|
|
132
|
+
if (x !== y) return x < y ? -1 : 1;
|
|
133
|
+
}
|
|
134
|
+
return as.length - bs.length;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* True when an ancestor directory of `path` is ignored as a directory. The
|
|
139
|
+
* walk checks a directory once and skips its subtree, so each ignored
|
|
140
|
+
* directory counts once whatever it holds.
|
|
141
|
+
*/
|
|
142
|
+
function underSkippedDir(path: string, matcher: Matcher, skipped: Set<string>, stats: SelectionStats): boolean {
|
|
143
|
+
const parts = path.split("/");
|
|
144
|
+
let dir = "";
|
|
145
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
146
|
+
dir = dir === "" ? (parts[i] ?? "") : `${dir}/${parts[i] ?? ""}`;
|
|
147
|
+
if (skipped.has(dir)) return true;
|
|
148
|
+
if (matcher.matchWithReason(dir, true).ignored) {
|
|
149
|
+
skipped.add(dir);
|
|
150
|
+
stats.dirsSkipped++;
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const decoder = new TextDecoder();
|
|
158
|
+
|
|
159
|
+
function decode(bytes: Uint8Array): string {
|
|
160
|
+
return decoder.decode(bytes);
|
|
161
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words every client prints for the same thing.
|
|
3
|
+
*
|
|
4
|
+
* The CLI's `validate -f`, `push plugin --dry-run` and `install`, and the
|
|
5
|
+
* console's install preview, all describe a package to the user; a
|
|
6
|
+
* platform where the same fact is named differently on two surfaces has
|
|
7
|
+
* two vocabularies. The labels here are the docs' words
|
|
8
|
+
* (`docs/vocabulary.md`), kept once.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { PluginDialect } from "../types.js";
|
|
12
|
+
|
|
13
|
+
/** Human labels for the four dialects, in the vocabulary the docs use. */
|
|
14
|
+
export const DIALECT_LABELS: Readonly<Record<PluginDialect, string>> = {
|
|
15
|
+
"agent-plugins": "Agent Plugins 1.0",
|
|
16
|
+
claude: "Claude Code plugin",
|
|
17
|
+
cursor: "Cursor plugin",
|
|
18
|
+
codex: "Codex plugin",
|
|
19
|
+
};
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@stigmer/plugin-package/client`: what every client that installs a
|
|
3
|
+
* plugin does identically.
|
|
4
|
+
*
|
|
5
|
+
* The main entry reads a package; this entry is for the client that holds
|
|
6
|
+
* a tree and must turn it into the push the server expects. Two clients do
|
|
7
|
+
* that today, the CLI from a directory and the console from a marketplace
|
|
8
|
+
* host's file list, and a plugin installed from either must have one
|
|
9
|
+
* digest for one tree, be refused with one sentence for one mistake, and be
|
|
10
|
+
* described in one vocabulary. So the pieces live here, once:
|
|
11
|
+
*
|
|
12
|
+
* - the gitignore-compatible ignore engine and the security defaults
|
|
13
|
+
* (`ignore/`), pure over the text of the ignore files;
|
|
14
|
+
* - the selection rule (`select.ts`): which files a push carries, in the
|
|
15
|
+
* order the CLI's original walk produced them;
|
|
16
|
+
* - the archive and its digest (`archive.ts`): the deterministic zip and
|
|
17
|
+
* the SHA-256 the server records;
|
|
18
|
+
* - the preparation (`prepare.ts`): select, read, refuse, archive, digest,
|
|
19
|
+
* once, for a tree on disk, on a host, or in a browser's memory;
|
|
20
|
+
* - the eval preparation (`prepare-eval.ts`): an evals/ folder's push,
|
|
21
|
+
* its run output left out, read as the server reads it, archived;
|
|
22
|
+
* - the presentation (`presentation.ts`): a card's face from a listed
|
|
23
|
+
* tree, reading the entry's manifest and nothing else;
|
|
24
|
+
* - the grammars (`refs.ts`): an install ref and a GitHub marketplace
|
|
25
|
+
* source, with their refusal sentences;
|
|
26
|
+
* - the built-in sources (`builtin.ts`): the official catalogue and the
|
|
27
|
+
* three vendors', listed by every client without configuration;
|
|
28
|
+
* - the release predicate (`release.ts`): which server versions the
|
|
29
|
+
* catalogue is published for;
|
|
30
|
+
* - the re-rooting rule (`reroot.ts`): a zipped folder reads as the folder;
|
|
31
|
+
* - the vocabulary (`vocabulary.ts`): the labels both surfaces print.
|
|
32
|
+
*
|
|
33
|
+
* Nothing here touches the filesystem, the network or any `node:*` module.
|
|
34
|
+
* A client's edge (a directory walk, a fetch, a file pick) produces the
|
|
35
|
+
* candidates and the bytes; this entry decides what becomes of them.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
export { DEFAULT_PATTERNS } from "./client/ignore/defaults.js";
|
|
39
|
+
export { matchName } from "./client/ignore/match.js";
|
|
40
|
+
export {
|
|
41
|
+
type IgnoreSources,
|
|
42
|
+
type MatchReason,
|
|
43
|
+
Matcher,
|
|
44
|
+
Reason,
|
|
45
|
+
REASON_TEXT,
|
|
46
|
+
SOURCE_CLI,
|
|
47
|
+
SOURCE_DEFAULTS,
|
|
48
|
+
SOURCE_GITIGNORE,
|
|
49
|
+
SOURCE_STIGMERIGNORE,
|
|
50
|
+
buildMatcher,
|
|
51
|
+
} from "./client/ignore/matcher.js";
|
|
52
|
+
export { MatchResult, type Pattern, parsePattern } from "./client/ignore/pattern.js";
|
|
53
|
+
export {
|
|
54
|
+
type CandidateFile,
|
|
55
|
+
type PluginSelection,
|
|
56
|
+
type SelectPluginFilesOptions,
|
|
57
|
+
type SelectionStats,
|
|
58
|
+
IGNORE_FILE_NAMES,
|
|
59
|
+
compareWalkOrder,
|
|
60
|
+
selectPluginFiles,
|
|
61
|
+
} from "./client/select.js";
|
|
62
|
+
export { DETERMINISTIC_ZIP_MTIME, archivePlugin, digestArchive } from "./client/archive.js";
|
|
63
|
+
export {
|
|
64
|
+
type LazyCandidate,
|
|
65
|
+
type PrepareArchiveOutcome,
|
|
66
|
+
type PrepareFromTreeOptions,
|
|
67
|
+
type PreparePluginOutcome,
|
|
68
|
+
type PreparedPlugin,
|
|
69
|
+
preparePluginArchive,
|
|
70
|
+
preparePluginFromTree,
|
|
71
|
+
} from "./client/prepare.js";
|
|
72
|
+
export {
|
|
73
|
+
EVAL_RESULTS_DIR,
|
|
74
|
+
type PrepareEvalOutcome,
|
|
75
|
+
type PreparedEval,
|
|
76
|
+
prepareEvalArchive,
|
|
77
|
+
} from "./client/prepare-eval.js";
|
|
78
|
+
export { readPluginPresentationFromTree } from "./client/presentation.js";
|
|
79
|
+
export {
|
|
80
|
+
type BuiltInMarketplace,
|
|
81
|
+
BUILT_IN_MARKETPLACES,
|
|
82
|
+
builtInSourceRefusal,
|
|
83
|
+
isBuiltInMarketplaceName,
|
|
84
|
+
} from "./client/builtin.js";
|
|
85
|
+
export { isReleaseVersion } from "./client/release.js";
|
|
86
|
+
export { rerootSingleDirectory, stripDirectoryPrefix } from "./client/reroot.js";
|
|
87
|
+
export {
|
|
88
|
+
type GitHubMarketplaceSource,
|
|
89
|
+
type GitHubSourceOutcome,
|
|
90
|
+
type InstallRef,
|
|
91
|
+
type InstallRefOutcome,
|
|
92
|
+
GITHUB_SOURCE_SHAPE,
|
|
93
|
+
INSTALL_REF_SHAPE,
|
|
94
|
+
OFFICIAL_MARKETPLACE_NAME,
|
|
95
|
+
describeGitHubSource,
|
|
96
|
+
formatInstallRef,
|
|
97
|
+
isOwnerRepo,
|
|
98
|
+
looksLikePath,
|
|
99
|
+
parseGitHubSource,
|
|
100
|
+
parseInstallRef,
|
|
101
|
+
} from "./client/refs.js";
|
|
102
|
+
export { DIALECT_LABELS } from "./client/vocabulary.js";
|