@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
package/src/index.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@stigmer/plugin-package`: the public surface.
|
|
3
|
+
*
|
|
4
|
+
* `readPluginPackage` reads one plugin; `readMarketplace` reads a catalogue
|
|
5
|
+
* of them; `readPluginPresentation` reads what a card shows for one entry
|
|
6
|
+
* without opening the rest of it; `readEvalSuite` reads the plugin's own
|
|
7
|
+
* eval suite, which the install summarises and the eval workflow runs. Everything else here is what a consumer needs to supply its
|
|
8
|
+
* input (`PluginFiles`, the caps), route a directory (`MANIFEST_LOCATIONS`,
|
|
9
|
+
* `hasPluginManifest`, `MARKETPLACE_LOCATIONS`, `hasMarketplaceFile`), or
|
|
10
|
+
* render an outcome (the finding kinds and `isErrorKind`). The dialect
|
|
11
|
+
* readers and normalisers are internal: a consumer never composes a partial
|
|
12
|
+
* read.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { hasPluginManifest, isValidPluginName } from "./detect.js";
|
|
16
|
+
export {
|
|
17
|
+
comparePaths,
|
|
18
|
+
inMemoryPluginFiles,
|
|
19
|
+
isContainedPath,
|
|
20
|
+
PLUGIN_DOCUMENT_LIMITS,
|
|
21
|
+
resolveDeclaredPath,
|
|
22
|
+
type DeclaredPathOutcome,
|
|
23
|
+
type PluginDocumentClass,
|
|
24
|
+
type PluginFileEntry,
|
|
25
|
+
type PluginFiles,
|
|
26
|
+
} from "./files.js";
|
|
27
|
+
export { SKILL_NAME_PATTERN } from "./frontmatter.js";
|
|
28
|
+
export {
|
|
29
|
+
AGENT_PLUGINS_MANIFEST_SCHEMA,
|
|
30
|
+
AGENT_PLUGINS_MCP_SCHEMA,
|
|
31
|
+
errorMessage,
|
|
32
|
+
isErrorKind,
|
|
33
|
+
MANIFEST_LOCATIONS,
|
|
34
|
+
warningMessage,
|
|
35
|
+
} from "./messages.js";
|
|
36
|
+
export { HOOK_CONDITION_PATTERN, RUN_EVENTS, hookVariableReferences, isValidMatcher } from "./normalise/hooks.js";
|
|
37
|
+
export { isAcceptableServerUrl } from "./normalise/mcp-servers.js";
|
|
38
|
+
export { SUB_AGENT_INSTRUCTIONS_MIN, classifyModel } from "./normalise/sub-agents.js";
|
|
39
|
+
export {
|
|
40
|
+
PLACEHOLDER_PATTERN,
|
|
41
|
+
PLATFORM_VARIABLES,
|
|
42
|
+
RUNNER_FILLED_VARIABLES,
|
|
43
|
+
VARIABLE_NAME_PATTERN,
|
|
44
|
+
findPluginRootPlaceholder,
|
|
45
|
+
} from "./placeholders.js";
|
|
46
|
+
export { HOOK_WARNING_KINDS } from "./outcome.js";
|
|
47
|
+
export type {
|
|
48
|
+
Finding,
|
|
49
|
+
FindingContext,
|
|
50
|
+
PluginErrorKind,
|
|
51
|
+
PluginFinding,
|
|
52
|
+
PluginFindingKind,
|
|
53
|
+
PluginReadOutcome,
|
|
54
|
+
PluginWarningKind,
|
|
55
|
+
} from "./outcome.js";
|
|
56
|
+
export { MARKETPLACE_LOCATIONS } from "./marketplace/messages.js";
|
|
57
|
+
export type {
|
|
58
|
+
Marketplace,
|
|
59
|
+
MarketplaceDialect,
|
|
60
|
+
MarketplaceEntry,
|
|
61
|
+
MarketplaceErrorKind,
|
|
62
|
+
MarketplaceFinding,
|
|
63
|
+
MarketplaceFindingKind,
|
|
64
|
+
MarketplaceOwner,
|
|
65
|
+
MarketplaceReadOutcome,
|
|
66
|
+
MarketplaceWarningKind,
|
|
67
|
+
} from "./marketplace/outcome.js";
|
|
68
|
+
export { hasMarketplaceFile, readMarketplace, readMarketplaceFile } from "./marketplace/read-marketplace.js";
|
|
69
|
+
export { readPluginPackage } from "./read-plugin-package.js";
|
|
70
|
+
export { isToolNameSegment, toolServerSegment } from "./tool-names.js";
|
|
71
|
+
export {
|
|
72
|
+
DEFAULT_EVAL_DIR,
|
|
73
|
+
EVAL_CURSOR_UNSUPPORTED_FEATURES,
|
|
74
|
+
EVAL_MAX_APPEND_SYSTEM_PROMPT,
|
|
75
|
+
EVAL_MAX_GRADERS,
|
|
76
|
+
EVAL_UNSUPPORTED_FEATURES,
|
|
77
|
+
type EvalCursorUnsupportedFeature,
|
|
78
|
+
type EvalUnsupportedFeature,
|
|
79
|
+
evalCaseUnsupportedOnCursor,
|
|
80
|
+
readEvalFolder,
|
|
81
|
+
readEvalSuite,
|
|
82
|
+
} from "./evals/read-eval-suite.js";
|
|
83
|
+
export { MOCKS_DIR } from "./evals/mocks.js";
|
|
84
|
+
export { EVAL_ENV_KEY_PATTERN, EVAL_SCHEMA_VERSION } from "./evals/fields.js";
|
|
85
|
+
export {
|
|
86
|
+
EVAL_SUMMARY_MAX_CASE_TAGS,
|
|
87
|
+
EVAL_SUMMARY_MAX_CASES,
|
|
88
|
+
EVAL_SUMMARY_MAX_FINDINGS,
|
|
89
|
+
EVAL_SUMMARY_MAX_MESSAGE,
|
|
90
|
+
EVAL_SUMMARY_MAX_PATH,
|
|
91
|
+
EVAL_SUMMARY_MAX_SUITE_TAGS,
|
|
92
|
+
EVAL_SUMMARY_MAX_TEXT,
|
|
93
|
+
type EvalSuiteSummary,
|
|
94
|
+
type EvalSuiteSummaryCase,
|
|
95
|
+
summariseEvalSuite,
|
|
96
|
+
} from "./evals/summary.js";
|
|
97
|
+
export { GLOB_MAX_ALTERNATIVES, GLOB_MAX_BRACE_DEPTH, GLOB_MAX_CLASS_ITEMS, GLOB_MAX_LENGTH, GLOB_MAX_TOKENS, globError } from "./evals/glob.js";
|
|
98
|
+
export type {
|
|
99
|
+
EvalCase,
|
|
100
|
+
EvalCaseContext,
|
|
101
|
+
EvalFocus,
|
|
102
|
+
EvalGrader,
|
|
103
|
+
EvalGraderArm,
|
|
104
|
+
EvalGraderCheck,
|
|
105
|
+
EvalGraderType,
|
|
106
|
+
EvalMockServer,
|
|
107
|
+
EvalMockTool,
|
|
108
|
+
EvalSuite,
|
|
109
|
+
EvalSuiteFinding,
|
|
110
|
+
EvalToolRef,
|
|
111
|
+
} from "./evals/types.js";
|
|
112
|
+
export { type PluginPresentation, readPluginPresentation } from "./presentation.js";
|
|
113
|
+
export type {
|
|
114
|
+
HookFormat,
|
|
115
|
+
IgnoredComponent,
|
|
116
|
+
IgnoredComponentKind,
|
|
117
|
+
ModelAlias,
|
|
118
|
+
ModelHint,
|
|
119
|
+
PluginAuthor,
|
|
120
|
+
PluginDialect,
|
|
121
|
+
PluginHookGroup,
|
|
122
|
+
PluginHookHandler,
|
|
123
|
+
PluginHooks,
|
|
124
|
+
PluginMcpServer,
|
|
125
|
+
PluginPackage,
|
|
126
|
+
PluginSkill,
|
|
127
|
+
PluginSubAgent,
|
|
128
|
+
PluginVariable,
|
|
129
|
+
} from "./types.js";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one sentence for every marketplace finding kind, and the collector
|
|
3
|
+
* bound to them.
|
|
4
|
+
*
|
|
5
|
+
* The same rule as the plugin vocabulary: copy lives here and nowhere else,
|
|
6
|
+
* the CLI prints these sentences verbatim, and the `Record` types are
|
|
7
|
+
* exhaustive so a kind without a sentence does not compile. The four
|
|
8
|
+
* locations are named in the not-found sentence because that is the one an
|
|
9
|
+
* author meets first when a file sits in the wrong place (Claude Code's own
|
|
10
|
+
* issue tracker shows how often).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { at, FindingCollector, q, type Sentence } from "../messages.js";
|
|
14
|
+
import type { MarketplaceDialect, MarketplaceErrorKind, MarketplaceWarningKind } from "./outcome.js";
|
|
15
|
+
|
|
16
|
+
/** The four marketplace file locations, in the precedence the reader applies. */
|
|
17
|
+
export const MARKETPLACE_LOCATIONS: Readonly<Record<MarketplaceDialect, string>> = {
|
|
18
|
+
stigmer: "marketplace.json",
|
|
19
|
+
claude: ".claude-plugin/marketplace.json",
|
|
20
|
+
cursor: ".cursor-plugin/marketplace.json",
|
|
21
|
+
codex: ".agents/plugins/marketplace.json",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const locationList = Object.values(MARKETPLACE_LOCATIONS)
|
|
25
|
+
.map((location) => q(location))
|
|
26
|
+
.join(", ");
|
|
27
|
+
|
|
28
|
+
const ERROR_MESSAGES: Readonly<Record<MarketplaceErrorKind, Sentence>> = {
|
|
29
|
+
"marketplace-not-found": () => `no marketplace file found: expected one of ${locationList}`,
|
|
30
|
+
"marketplace-too-large": (c) => `${q(c.path)} is ${c.subject ?? ""} bytes, above the ${c.detail ?? ""} byte cap for a marketplace file`,
|
|
31
|
+
"marketplace-unreadable": (c) => `${q(c.path)} is not a readable marketplace file: ${c.detail ?? "parse error"}`,
|
|
32
|
+
"marketplace-field-type": (c) => `${q(c.path)} field ${q(c.subject)} must be ${c.detail ?? "of another type"}`,
|
|
33
|
+
"marketplace-name-missing": (c) => `${q(c.path)} has no 'name'; a marketplace needs one so its plugins can be addressed as '<marketplace>/<plugin>'`,
|
|
34
|
+
"marketplace-name-invalid": (c) =>
|
|
35
|
+
`${q(c.path)} name ${q(c.subject)} is invalid: 1 to 64 characters of a-z, 0-9, '-' and '.', starting and ending alphanumeric, no '--' or '..'`,
|
|
36
|
+
"marketplace-plugins-missing": (c) => `${q(c.path)} has no 'plugins' list`,
|
|
37
|
+
"entry-shape": (c) => `${q(c.path)} plugins[${c.subject ?? ""}] must be an object with 'name' and 'source'`,
|
|
38
|
+
"entry-name-missing": (c) => `${q(c.path)} plugins[${c.subject ?? ""}] has no 'name'`,
|
|
39
|
+
"entry-name-invalid": (c) =>
|
|
40
|
+
`${q(c.path)} plugin ${q(c.subject)} has an invalid name: 1 to 64 characters of a-z, 0-9, '-' and '.', starting and ending alphanumeric, no '--' or '..'`,
|
|
41
|
+
"entry-name-duplicate": (c) => `${q(c.path)} lists plugin ${q(c.subject)} more than once; 'install ${c.subject ?? ""}' would be ambiguous`,
|
|
42
|
+
"entry-source-missing": (c) => `${q(c.path)} plugin ${q(c.subject)} has no 'source'`,
|
|
43
|
+
"entry-source-escapes-root": (c) =>
|
|
44
|
+
`${q(c.path)} plugin ${q(c.subject)} has source ${q(c.detail)} outside the marketplace root; a source is a directory inside the marketplace`,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const WARNING_MESSAGES: Readonly<Record<MarketplaceWarningKind, Sentence>> = {
|
|
48
|
+
"entry-source-unsupported": (c) =>
|
|
49
|
+
`plugin ${q(c.subject)}${at(c.path)} has source ${q(c.detail)}, a form Stigmer does not fetch (only a directory inside the marketplace); not offered`,
|
|
50
|
+
"entry-directory-missing": (c) =>
|
|
51
|
+
`plugin ${q(c.subject)}${at(c.path)} names directory ${q(c.detail)}, which the marketplace does not contain; not offered`,
|
|
52
|
+
"entry-not-a-plugin": (c) =>
|
|
53
|
+
`plugin ${q(c.subject)}${at(c.path)} names directory ${q(c.detail)}, which holds no plugin manifest; not offered`,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** The marketplace reader's collector, bound to the marketplace vocabulary. */
|
|
57
|
+
export class MarketplaceFindings extends FindingCollector<MarketplaceErrorKind, MarketplaceWarningKind> {
|
|
58
|
+
constructor() {
|
|
59
|
+
super(ERROR_MESSAGES, WARNING_MESSAGES);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a marketplace is once read, and the closed vocabulary of findings a
|
|
3
|
+
* marketplace read can produce.
|
|
4
|
+
*
|
|
5
|
+
* A marketplace is a directory tree with a marketplace file that lists the
|
|
6
|
+
* plugins it offers, each as a name and a directory inside the tree. That is
|
|
7
|
+
* the convention Cursor (`.cursor-plugin/marketplace.json`), Claude Code
|
|
8
|
+
* (`.claude-plugin/marketplace.json`) and Codex (`.agents/plugins/
|
|
9
|
+
* marketplace.json`) already publish, and the agent-plugins.org
|
|
10
|
+
* specification leaves marketplaces client-owned, so there is no open
|
|
11
|
+
* format to defer to; Stigmer's own file sits at the tree root as
|
|
12
|
+
* `marketplace.json`, the position the open plugin manifest takes. The four
|
|
13
|
+
* dialects reduce to one shape here: a client that can read this shape can
|
|
14
|
+
* install from any of the four catalogues.
|
|
15
|
+
*
|
|
16
|
+
* Two error postures, stated as the plugin reader states them. A marketplace
|
|
17
|
+
* FILE that is broken (unreadable, unnamed, no plugin list, a source that
|
|
18
|
+
* escapes the tree, two entries with one name) refuses the marketplace: a
|
|
19
|
+
* catalogue that cannot be trusted as a whole is not offered at all. An
|
|
20
|
+
* ENTRY that cannot be installed (a source form this reader does not fetch,
|
|
21
|
+
* a directory the tree does not hold, a directory with no plugin manifest)
|
|
22
|
+
* is dropped with a warning: a user adding a public catalogue of eighty
|
|
23
|
+
* plugins should still see the seventy-nine that work, and a catalogue's
|
|
24
|
+
* own static suite asserts zero warnings so the publisher hears about the
|
|
25
|
+
* one. Every kind has exactly one sentence in `messages.ts` and exactly one
|
|
26
|
+
* adversarial fixture.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { Finding } from "../outcome.js";
|
|
30
|
+
|
|
31
|
+
/** The marketplace file dialects, in the precedence the reader applies. */
|
|
32
|
+
export type MarketplaceDialect = "stigmer" | "claude" | "cursor" | "codex";
|
|
33
|
+
|
|
34
|
+
export type MarketplaceErrorKind =
|
|
35
|
+
// The file
|
|
36
|
+
| "marketplace-not-found"
|
|
37
|
+
| "marketplace-too-large"
|
|
38
|
+
| "marketplace-unreadable"
|
|
39
|
+
| "marketplace-field-type"
|
|
40
|
+
| "marketplace-name-missing"
|
|
41
|
+
| "marketplace-name-invalid"
|
|
42
|
+
| "marketplace-plugins-missing"
|
|
43
|
+
// Entries
|
|
44
|
+
| "entry-shape"
|
|
45
|
+
| "entry-name-missing"
|
|
46
|
+
| "entry-name-invalid"
|
|
47
|
+
| "entry-name-duplicate"
|
|
48
|
+
| "entry-source-missing"
|
|
49
|
+
| "entry-source-escapes-root";
|
|
50
|
+
|
|
51
|
+
export type MarketplaceWarningKind =
|
|
52
|
+
| "entry-source-unsupported"
|
|
53
|
+
| "entry-directory-missing"
|
|
54
|
+
| "entry-not-a-plugin";
|
|
55
|
+
|
|
56
|
+
export type MarketplaceFindingKind = MarketplaceErrorKind | MarketplaceWarningKind;
|
|
57
|
+
|
|
58
|
+
export type MarketplaceFinding = Finding<MarketplaceFindingKind>;
|
|
59
|
+
|
|
60
|
+
export interface MarketplaceOwner {
|
|
61
|
+
readonly name?: string;
|
|
62
|
+
readonly email?: string;
|
|
63
|
+
readonly url?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One installable plugin the marketplace offers. */
|
|
67
|
+
export interface MarketplaceEntry {
|
|
68
|
+
/** The name a user installs it by; unique within the marketplace. */
|
|
69
|
+
readonly name: string;
|
|
70
|
+
/** The plugin's directory, marketplace-relative with no leading `./`; the empty string is the tree root. */
|
|
71
|
+
readonly dir: string;
|
|
72
|
+
/** The catalogue's own one-line description, when the file carries one. */
|
|
73
|
+
readonly description?: string;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface Marketplace {
|
|
77
|
+
/** The marketplace's identifier, the prefix in `install <marketplace>/<plugin>`. */
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly description?: string;
|
|
80
|
+
readonly owner?: MarketplaceOwner;
|
|
81
|
+
/** The dialect whose file named the marketplace. */
|
|
82
|
+
readonly dialect: MarketplaceDialect;
|
|
83
|
+
/** The marketplace file that was read, tree-relative. */
|
|
84
|
+
readonly path: string;
|
|
85
|
+
/** Installable entries, in the file's order; entries the reader dropped are in the warnings. */
|
|
86
|
+
readonly plugins: readonly MarketplaceEntry[];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type MarketplaceReadOutcome =
|
|
90
|
+
| { readonly ok: true; readonly marketplace: Marketplace; readonly warnings: readonly MarketplaceFinding[] }
|
|
91
|
+
| { readonly ok: false; readonly errors: readonly MarketplaceFinding[]; readonly warnings: readonly MarketplaceFinding[] };
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The marketplace entry: a `PluginFiles` over a marketplace tree in, a
|
|
3
|
+
* `MarketplaceReadOutcome` out.
|
|
4
|
+
*
|
|
5
|
+
* The read is a fixed sequence, like the plugin read: locate the marketplace
|
|
6
|
+
* file (first present in the dialect precedence, and only that one is read;
|
|
7
|
+
* a tree that carries two dialects' files describes one catalogue twice);
|
|
8
|
+
* parse it under the marketplace cap; read the dialect's shape into the one
|
|
9
|
+
* normalised shape; validate names and sources; drop the entries the tree
|
|
10
|
+
* cannot install, each with its own warning. Findings are collected and the
|
|
11
|
+
* read continues, so the outcome names every problem at once, and the
|
|
12
|
+
* marketplace is returned only when nothing refused.
|
|
13
|
+
*
|
|
14
|
+
* A catalogue installs nothing by itself: a field a dialect uses to name
|
|
15
|
+
* entries a client installs unasked (Codex's `INSTALLED_BY_DEFAULT` policy,
|
|
16
|
+
* or a `defaults` list) is not read, so a file that still carries one reads
|
|
17
|
+
* the same as a file without it.
|
|
18
|
+
*
|
|
19
|
+
* Sources. Every dialect names a plugin's directory relative to the
|
|
20
|
+
* marketplace root (Claude and Codex with a `./` prefix, Cursor without,
|
|
21
|
+
* Claude optionally under `metadata.pluginRoot`); the reader accepts both
|
|
22
|
+
* spellings and refuses a path that escapes the root. A source that is not
|
|
23
|
+
* such a directory (Claude's `github`, `url`, `npm` and `git-subdir` objects,
|
|
24
|
+
* Codex's non-`local` sources, Cursor's remote URLs) is a form this reader
|
|
25
|
+
* does not fetch: the entry is dropped with `entry-source-unsupported`, and
|
|
26
|
+
* nothing is invented in its place.
|
|
27
|
+
*
|
|
28
|
+
* This reader does not open the plugins it lists. A consumer that wants an
|
|
29
|
+
* entry's own description or version reads that directory with
|
|
30
|
+
* `readPluginPackage`; a consumer that wants to install it hands the same
|
|
31
|
+
* directory to the walker it already uses. Keeping the two reads apart is
|
|
32
|
+
* what lets a catalogue of eighty entries be listed without eighty reads.
|
|
33
|
+
*
|
|
34
|
+
* `readMarketplaceFile` is the same read without the tree: what the file
|
|
35
|
+
* declares, for a client that holds the file alone and asks only "does this
|
|
36
|
+
* source offer a plugin called X" before it pays for the tree (the CLI's
|
|
37
|
+
* bare-name search across GitHub sources fetches one small file per source
|
|
38
|
+
* instead of a zipball each). Whether the tree holds an entry is still
|
|
39
|
+
* `readMarketplace`'s to say, on the tree, before anything is installed.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
import { hasPluginManifest, isValidPluginName } from "../detect.js";
|
|
43
|
+
import { describeValue, isJsonObject, type JsonObject } from "../documents.js";
|
|
44
|
+
import { decodeUtf8, isContainedPath, PLUGIN_DOCUMENT_LIMITS, PluginFileIndex, type PluginFiles } from "../files.js";
|
|
45
|
+
import { MARKETPLACE_LOCATIONS, MarketplaceFindings } from "./messages.js";
|
|
46
|
+
import type { Marketplace, MarketplaceDialect, MarketplaceEntry, MarketplaceOwner, MarketplaceReadOutcome } from "./outcome.js";
|
|
47
|
+
|
|
48
|
+
/** The precedence the reader applies when a tree carries more than one marketplace file. */
|
|
49
|
+
const DIALECT_PRECEDENCE: readonly MarketplaceDialect[] = ["stigmer", "claude", "cursor", "codex"];
|
|
50
|
+
|
|
51
|
+
/** True when the tree holds any of the four marketplace files; the CLI's routing test. */
|
|
52
|
+
export function hasMarketplaceFile(paths: Iterable<string>): boolean {
|
|
53
|
+
const locations = new Set<string>(Object.values(MARKETPLACE_LOCATIONS));
|
|
54
|
+
for (const path of paths) if (locations.has(path)) return true;
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function readMarketplace(files: PluginFiles): MarketplaceReadOutcome {
|
|
59
|
+
return read(files, "tree");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The marketplace file as declared, the tree unverified: every entry with a
|
|
64
|
+
* readable source is offered, whether or not `files` holds its directory.
|
|
65
|
+
* For a client that has fetched the file alone; never for an install.
|
|
66
|
+
*/
|
|
67
|
+
export function readMarketplaceFile(files: PluginFiles): MarketplaceReadOutcome {
|
|
68
|
+
return read(files, "file");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* `tree`: entries whose directory the tree lacks, or holds without a plugin
|
|
73
|
+
* manifest, are dropped with their warning. `file`: entries are taken as the
|
|
74
|
+
* file declares them, and the tree is not consulted.
|
|
75
|
+
*/
|
|
76
|
+
function read(files: PluginFiles, verify: "tree" | "file"): MarketplaceReadOutcome {
|
|
77
|
+
const findings = new MarketplaceFindings();
|
|
78
|
+
const index = new PluginFileIndex(files);
|
|
79
|
+
|
|
80
|
+
const located = locate(index);
|
|
81
|
+
if (located === undefined) {
|
|
82
|
+
findings.error("marketplace-not-found");
|
|
83
|
+
return refused(findings);
|
|
84
|
+
}
|
|
85
|
+
const { dialect, path } = located;
|
|
86
|
+
|
|
87
|
+
const object = readObject(index, path, findings);
|
|
88
|
+
if (object === undefined) return refused(findings);
|
|
89
|
+
|
|
90
|
+
const name = readName(object, path, findings);
|
|
91
|
+
const raw = readEntries(object, dialect, path, findings);
|
|
92
|
+
const entries = verify === "tree" ? offeredEntries(raw, index, path, findings) : declaredEntries(raw);
|
|
93
|
+
|
|
94
|
+
if (findings.errors.length > 0 || name === undefined) return refused(findings);
|
|
95
|
+
|
|
96
|
+
const description = readDescription(object, dialect);
|
|
97
|
+
const owner = readOwner(object);
|
|
98
|
+
const marketplace: Marketplace = {
|
|
99
|
+
name,
|
|
100
|
+
...(description !== undefined && { description }),
|
|
101
|
+
...(owner !== undefined && { owner }),
|
|
102
|
+
dialect,
|
|
103
|
+
path,
|
|
104
|
+
plugins: entries,
|
|
105
|
+
};
|
|
106
|
+
return { ok: true, marketplace, warnings: findings.warnings };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function refused(findings: MarketplaceFindings): MarketplaceReadOutcome {
|
|
110
|
+
return { ok: false, errors: findings.errors, warnings: findings.warnings };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function locate(index: PluginFileIndex): { dialect: MarketplaceDialect; path: string } | undefined {
|
|
114
|
+
for (const dialect of DIALECT_PRECEDENCE) {
|
|
115
|
+
const path = MARKETPLACE_LOCATIONS[dialect];
|
|
116
|
+
if (index.has(path)) return { dialect, path };
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function readObject(index: PluginFileIndex, path: string, findings: MarketplaceFindings): JsonObject | undefined {
|
|
122
|
+
const limit = PLUGIN_DOCUMENT_LIMITS.marketplace;
|
|
123
|
+
const entry = index.entry(path);
|
|
124
|
+
if (entry === undefined) {
|
|
125
|
+
throw new Error(`marketplace file '${path}' is not listed`);
|
|
126
|
+
}
|
|
127
|
+
if (entry.size > limit) {
|
|
128
|
+
findings.error("marketplace-too-large", { path, subject: String(entry.size), detail: String(limit) });
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
const bytes = index.files.read(path);
|
|
132
|
+
if (bytes.length > limit) {
|
|
133
|
+
findings.error("marketplace-too-large", { path, subject: String(bytes.length), detail: String(limit) });
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
let value: unknown;
|
|
137
|
+
try {
|
|
138
|
+
value = JSON.parse(decodeUtf8(bytes));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
findings.error("marketplace-unreadable", { path, detail: error instanceof Error ? error.message : String(error) });
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
if (!isJsonObject(value)) {
|
|
144
|
+
findings.error("marketplace-unreadable", { path, detail: "the document is not a JSON object" });
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** The marketplace's own name, validated under the plugin name rule (the same characters an install ref can carry). */
|
|
151
|
+
function readName(object: JsonObject, path: string, findings: MarketplaceFindings): string | undefined {
|
|
152
|
+
const value = object["name"];
|
|
153
|
+
if (value === undefined) {
|
|
154
|
+
findings.error("marketplace-name-missing", { path });
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
if (typeof value !== "string") {
|
|
158
|
+
findings.error("marketplace-field-type", { path, subject: "name", detail: "a string" });
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
if (!isValidPluginName(value)) {
|
|
162
|
+
findings.error("marketplace-name-invalid", { path, subject: value });
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function readDescription(object: JsonObject, dialect: MarketplaceDialect): string | undefined {
|
|
169
|
+
switch (dialect) {
|
|
170
|
+
case "stigmer":
|
|
171
|
+
return optionalStringOf(object, "description");
|
|
172
|
+
case "claude":
|
|
173
|
+
case "cursor": {
|
|
174
|
+
const metadata = object["metadata"];
|
|
175
|
+
return isJsonObject(metadata) ? optionalStringOf(metadata, "description") : undefined;
|
|
176
|
+
}
|
|
177
|
+
case "codex":
|
|
178
|
+
// Codex's `interface.displayName` is a label for a picker, not a description.
|
|
179
|
+
return undefined;
|
|
180
|
+
default: {
|
|
181
|
+
const exhaustive: never = dialect;
|
|
182
|
+
return exhaustive;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function readOwner(object: JsonObject): MarketplaceOwner | undefined {
|
|
188
|
+
const value = object["owner"];
|
|
189
|
+
if (!isJsonObject(value)) return undefined;
|
|
190
|
+
const name = optionalStringOf(value, "name");
|
|
191
|
+
const email = optionalStringOf(value, "email");
|
|
192
|
+
const url = optionalStringOf(value, "url");
|
|
193
|
+
if (name === undefined && email === undefined && url === undefined) return undefined;
|
|
194
|
+
return {
|
|
195
|
+
...(name !== undefined && { name }),
|
|
196
|
+
...(email !== undefined && { email }),
|
|
197
|
+
...(url !== undefined && { url }),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A string field or `undefined`; a field of another type is treated as absent (metadata never refuses a catalogue). */
|
|
202
|
+
function optionalStringOf(object: JsonObject, field: string): string | undefined {
|
|
203
|
+
const value = object[field];
|
|
204
|
+
return typeof value === "string" ? value : undefined;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* One entry as the file states it, before the tree is consulted. `dir` is
|
|
209
|
+
* the resolved marketplace-relative directory, or `undefined` when the
|
|
210
|
+
* source is a form this reader does not fetch (the warning is recorded here
|
|
211
|
+
* so the entry's order in the file is kept for the sentence).
|
|
212
|
+
*/
|
|
213
|
+
interface RawEntry {
|
|
214
|
+
readonly name: string;
|
|
215
|
+
readonly dir: string | undefined;
|
|
216
|
+
readonly description?: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function readEntries(object: JsonObject, dialect: MarketplaceDialect, path: string, findings: MarketplaceFindings): readonly RawEntry[] {
|
|
220
|
+
const list = object["plugins"];
|
|
221
|
+
if (list === undefined) {
|
|
222
|
+
findings.error("marketplace-plugins-missing", { path });
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
if (!Array.isArray(list)) {
|
|
226
|
+
findings.error("marketplace-field-type", { path, subject: "plugins", detail: "an array" });
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
const pluginRoot = dialect === "claude" ? claudePluginRoot(object) : "";
|
|
230
|
+
|
|
231
|
+
const entries: RawEntry[] = [];
|
|
232
|
+
const seen = new Set<string>();
|
|
233
|
+
list.forEach((item: unknown, position: number) => {
|
|
234
|
+
if (!isJsonObject(item)) {
|
|
235
|
+
findings.error("entry-shape", { path, subject: String(position) });
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const name = item["name"];
|
|
239
|
+
if (name === undefined) {
|
|
240
|
+
findings.error("entry-name-missing", { path, subject: String(position) });
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (typeof name !== "string" || !isValidPluginName(name)) {
|
|
244
|
+
findings.error("entry-name-invalid", { path, subject: describeValue(name) });
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (seen.has(name)) {
|
|
248
|
+
findings.error("entry-name-duplicate", { path, subject: name });
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
seen.add(name);
|
|
252
|
+
|
|
253
|
+
const description = optionalStringOf(item, "description");
|
|
254
|
+
entries.push({
|
|
255
|
+
name,
|
|
256
|
+
dir: resolveSource(item["source"], name, pluginRoot, path, findings),
|
|
257
|
+
...(description !== undefined && { description }),
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
return entries;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Claude's `metadata.pluginRoot`, prepended to every relative source; the empty string when absent or unusable. */
|
|
264
|
+
function claudePluginRoot(object: JsonObject): string {
|
|
265
|
+
const metadata = object["metadata"];
|
|
266
|
+
if (!isJsonObject(metadata)) return "";
|
|
267
|
+
const root = optionalStringOf(metadata, "pluginRoot");
|
|
268
|
+
if (root === undefined) return "";
|
|
269
|
+
const resolved = relativeDirectory(root);
|
|
270
|
+
return resolved.ok ? resolved.dir : "";
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* A source becomes a marketplace-relative directory or nothing. A string is
|
|
275
|
+
* a relative directory (with or without `./`) unless it is a URL; Codex's
|
|
276
|
+
* `{source: "local", path}` object is the same directory; every other
|
|
277
|
+
* object form is a remote this reader does not fetch.
|
|
278
|
+
*/
|
|
279
|
+
function resolveSource(
|
|
280
|
+
source: unknown,
|
|
281
|
+
entryName: string,
|
|
282
|
+
pluginRoot: string,
|
|
283
|
+
path: string,
|
|
284
|
+
findings: MarketplaceFindings,
|
|
285
|
+
): string | undefined {
|
|
286
|
+
if (source === undefined) {
|
|
287
|
+
findings.error("entry-source-missing", { path, subject: entryName });
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
let candidate: string | undefined;
|
|
291
|
+
if (typeof source === "string") {
|
|
292
|
+
if (isUrl(source)) {
|
|
293
|
+
findings.warn("entry-source-unsupported", { path, subject: entryName, detail: source });
|
|
294
|
+
return undefined;
|
|
295
|
+
}
|
|
296
|
+
candidate = source;
|
|
297
|
+
} else if (isJsonObject(source) && source["source"] === "local" && typeof source["path"] === "string") {
|
|
298
|
+
candidate = source["path"];
|
|
299
|
+
} else {
|
|
300
|
+
findings.warn("entry-source-unsupported", { path, subject: entryName, detail: describeSource(source) });
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const resolved = relativeDirectory(candidate);
|
|
305
|
+
if (!resolved.ok) {
|
|
306
|
+
findings.error("entry-source-escapes-root", { path, subject: entryName, detail: candidate });
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
return joinDirectories(pluginRoot, resolved.dir);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** The `source` discriminator of a remote object, or the whole value, for the sentence. */
|
|
313
|
+
function describeSource(source: unknown): string {
|
|
314
|
+
if (isJsonObject(source) && typeof source["source"] === "string") return source["source"];
|
|
315
|
+
return describeValue(source);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function isUrl(value: string): boolean {
|
|
319
|
+
return /^[a-z][a-z0-9+.-]*:\/\//i.test(value);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
type RelativeDirectory = { readonly ok: true; readonly dir: string } | { readonly ok: false };
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* `./thermos`, `thermos`, `third_party/github/`, `.` and `./` all name a
|
|
326
|
+
* directory inside the root (the root itself is the empty string); an
|
|
327
|
+
* absolute path, a backslash, or a `..` segment does not.
|
|
328
|
+
*/
|
|
329
|
+
function relativeDirectory(value: string): RelativeDirectory {
|
|
330
|
+
let trimmed = value;
|
|
331
|
+
if (trimmed === "." || trimmed === "./") return { ok: true, dir: "" };
|
|
332
|
+
if (trimmed.startsWith("./")) trimmed = trimmed.slice(2);
|
|
333
|
+
trimmed = trimmed.replace(/\/+$/, "");
|
|
334
|
+
if (trimmed === "") return { ok: true, dir: "" };
|
|
335
|
+
return isContainedPath(trimmed) ? { ok: true, dir: trimmed } : { ok: false };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
function joinDirectories(root: string, dir: string): string {
|
|
339
|
+
if (root === "") return dir;
|
|
340
|
+
return dir === "" ? root : `${root}/${dir}`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The entries the tree can install: a directory that exists and holds a plugin manifest at its root. */
|
|
344
|
+
function offeredEntries(
|
|
345
|
+
raw: readonly RawEntry[],
|
|
346
|
+
index: PluginFileIndex,
|
|
347
|
+
path: string,
|
|
348
|
+
findings: MarketplaceFindings,
|
|
349
|
+
): readonly MarketplaceEntry[] {
|
|
350
|
+
const offered: MarketplaceEntry[] = [];
|
|
351
|
+
for (const entry of raw) {
|
|
352
|
+
if (entry.dir === undefined) continue;
|
|
353
|
+
if (!index.isDirectory(entry.dir)) {
|
|
354
|
+
findings.warn("entry-directory-missing", { path, subject: entry.name, detail: entry.dir === "" ? "." : entry.dir });
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
if (!hasPluginManifest(childFilesOf(index, entry.dir))) {
|
|
358
|
+
findings.warn("entry-not-a-plugin", { path, subject: entry.name, detail: entry.dir === "" ? "." : entry.dir });
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
offered.push({
|
|
362
|
+
name: entry.name,
|
|
363
|
+
dir: entry.dir,
|
|
364
|
+
...(entry.description !== undefined && { description: entry.description }),
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
return offered;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Every entry with a readable source, as the file declares it; the tree is not asked. */
|
|
371
|
+
function declaredEntries(raw: readonly RawEntry[]): readonly MarketplaceEntry[] {
|
|
372
|
+
const declared: MarketplaceEntry[] = [];
|
|
373
|
+
for (const entry of raw) {
|
|
374
|
+
if (entry.dir === undefined) continue;
|
|
375
|
+
declared.push({
|
|
376
|
+
name: entry.name,
|
|
377
|
+
dir: entry.dir,
|
|
378
|
+
...(entry.description !== undefined && { description: entry.description }),
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
return declared;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/** The files under `dir` as plugin-relative paths, so `hasPluginManifest` reads them as it reads a plugin's own listing. */
|
|
385
|
+
function childFilesOf(index: PluginFileIndex, dir: string): readonly string[] {
|
|
386
|
+
const prefix = dir === "" ? "" : `${dir}/`;
|
|
387
|
+
return index.filesUnder(dir).map((file) => file.slice(prefix.length));
|
|
388
|
+
}
|