@vibe-agent-toolkit/agent-skills 0.1.38 → 0.1.39-rc.10
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/dist/files-config.d.ts +83 -7
- package/dist/files-config.d.ts.map +1 -1
- package/dist/files-config.js +72 -12
- package/dist/files-config.js.map +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/inventory/detectors/declared-but-missing.d.ts +1 -1
- package/dist/inventory/detectors/declared-but-missing.d.ts.map +1 -1
- package/dist/inventory/detectors/declared-but-missing.js.map +1 -1
- package/dist/inventory/detectors/marketplace-source-missing.d.ts +1 -1
- package/dist/inventory/detectors/marketplace-source-missing.d.ts.map +1 -1
- package/dist/inventory/detectors/marketplace-source-missing.js.map +1 -1
- package/dist/inventory/detectors/present-but-undeclared.d.ts +1 -1
- package/dist/inventory/detectors/present-but-undeclared.d.ts.map +1 -1
- package/dist/inventory/detectors/present-but-undeclared.js.map +1 -1
- package/dist/inventory/detectors/reference-target-missing.d.ts +1 -1
- package/dist/inventory/detectors/reference-target-missing.d.ts.map +1 -1
- package/dist/inventory/detectors/reference-target-missing.js.map +1 -1
- package/dist/post-build-checks.d.ts +6 -6
- package/dist/post-build-checks.d.ts.map +1 -1
- package/dist/post-build-checks.js +119 -61
- package/dist/post-build-checks.js.map +1 -1
- package/dist/schemas/installed-plugins-registry.d.ts +6 -6
- package/dist/skill-packager.d.ts +2 -3
- package/dist/skill-packager.d.ts.map +1 -1
- package/dist/skill-packager.js +110 -32
- package/dist/skill-packager.js.map +1 -1
- package/dist/skill-source/content-hash.d.ts +13 -0
- package/dist/skill-source/content-hash.d.ts.map +1 -0
- package/dist/skill-source/content-hash.js +49 -0
- package/dist/skill-source/content-hash.js.map +1 -0
- package/dist/skill-source/fetch-cache.d.ts +26 -0
- package/dist/skill-source/fetch-cache.d.ts.map +1 -0
- package/dist/skill-source/fetch-cache.js +62 -0
- package/dist/skill-source/fetch-cache.js.map +1 -0
- package/dist/skill-source/git-clone.d.ts +21 -0
- package/dist/skill-source/git-clone.d.ts.map +1 -0
- package/dist/skill-source/git-clone.js +66 -0
- package/dist/skill-source/git-clone.js.map +1 -0
- package/dist/skill-source/resolve-skill-source.d.ts +12 -0
- package/dist/skill-source/resolve-skill-source.d.ts.map +1 -0
- package/dist/skill-source/resolve-skill-source.js +37 -0
- package/dist/skill-source/resolve-skill-source.js.map +1 -0
- package/dist/skill-source/sources/npm-source.d.ts +22 -0
- package/dist/skill-source/sources/npm-source.d.ts.map +1 -0
- package/dist/skill-source/sources/npm-source.js +48 -0
- package/dist/skill-source/sources/npm-source.js.map +1 -0
- package/dist/skill-source/sources/path-source.d.ts +10 -0
- package/dist/skill-source/sources/path-source.d.ts.map +1 -0
- package/dist/skill-source/sources/path-source.js +17 -0
- package/dist/skill-source/sources/path-source.js.map +1 -0
- package/dist/skill-source/sources/url-source.d.ts +14 -0
- package/dist/skill-source/sources/url-source.d.ts.map +1 -0
- package/dist/skill-source/sources/url-source.js +113 -0
- package/dist/skill-source/sources/url-source.js.map +1 -0
- package/dist/skill-source/sources/vendored-source.d.ts +8 -0
- package/dist/skill-source/sources/vendored-source.d.ts.map +1 -0
- package/dist/skill-source/sources/vendored-source.js +16 -0
- package/dist/skill-source/sources/vendored-source.js.map +1 -0
- package/dist/skill-source/sources/workspace-source.d.ts +17 -0
- package/dist/skill-source/sources/workspace-source.d.ts.map +1 -0
- package/dist/skill-source/sources/workspace-source.js +27 -0
- package/dist/skill-source/sources/workspace-source.js.map +1 -0
- package/dist/skill-source/stage.d.ts +21 -0
- package/dist/skill-source/stage.d.ts.map +1 -0
- package/dist/skill-source/stage.js +73 -0
- package/dist/skill-source/stage.js.map +1 -0
- package/dist/skill-source/types.d.ts +65 -0
- package/dist/skill-source/types.d.ts.map +1 -0
- package/dist/skill-source/types.js +11 -0
- package/dist/skill-source/types.js.map +1 -0
- package/dist/skill-test/build-hook.d.ts +58 -0
- package/dist/skill-test/build-hook.d.ts.map +1 -0
- package/dist/skill-test/build-hook.js +63 -0
- package/dist/skill-test/build-hook.js.map +1 -0
- package/dist/skill-test/configure-writer.d.ts +31 -0
- package/dist/skill-test/configure-writer.d.ts.map +1 -0
- package/dist/skill-test/configure-writer.js +39 -0
- package/dist/skill-test/configure-writer.js.map +1 -0
- package/dist/skill-test/declared-env.d.ts +72 -0
- package/dist/skill-test/declared-env.d.ts.map +1 -0
- package/dist/skill-test/declared-env.js +85 -0
- package/dist/skill-test/declared-env.js.map +1 -0
- package/dist/skill-test/evals-template.d.ts +22 -0
- package/dist/skill-test/evals-template.d.ts.map +1 -0
- package/dist/skill-test/evals-template.js +56 -0
- package/dist/skill-test/evals-template.js.map +1 -0
- package/dist/skill-test/exit-codes.d.ts +34 -0
- package/dist/skill-test/exit-codes.d.ts.map +1 -0
- package/dist/skill-test/exit-codes.js +59 -0
- package/dist/skill-test/exit-codes.js.map +1 -0
- package/dist/skill-test/experimenter-prompt.d.ts +20 -0
- package/dist/skill-test/experimenter-prompt.d.ts.map +1 -0
- package/dist/skill-test/experimenter-prompt.js +68 -0
- package/dist/skill-test/experimenter-prompt.js.map +1 -0
- package/dist/skill-test/friction-schema.d.ts +74 -0
- package/dist/skill-test/friction-schema.d.ts.map +1 -0
- package/dist/skill-test/friction-schema.js +28 -0
- package/dist/skill-test/friction-schema.js.map +1 -0
- package/dist/skill-test/grading-adapter.d.ts +22 -0
- package/dist/skill-test/grading-adapter.d.ts.map +1 -0
- package/dist/skill-test/grading-adapter.js +49 -0
- package/dist/skill-test/grading-adapter.js.map +1 -0
- package/dist/skill-test/grading-schema.d.ts +171 -0
- package/dist/skill-test/grading-schema.d.ts.map +1 -0
- package/dist/skill-test/grading-schema.js +65 -0
- package/dist/skill-test/grading-schema.js.map +1 -0
- package/dist/skill-test/harness-location.d.ts +40 -0
- package/dist/skill-test/harness-location.d.ts.map +1 -0
- package/dist/skill-test/harness-location.js +111 -0
- package/dist/skill-test/harness-location.js.map +1 -0
- package/dist/skill-test/index.d.ts +16 -0
- package/dist/skill-test/index.d.ts.map +1 -0
- package/dist/skill-test/index.js +16 -0
- package/dist/skill-test/index.js.map +1 -0
- package/dist/skill-test/lock.d.ts +16 -0
- package/dist/skill-test/lock.d.ts.map +1 -0
- package/dist/skill-test/lock.js +42 -0
- package/dist/skill-test/lock.js.map +1 -0
- package/dist/skill-test/manifest.d.ts +59 -0
- package/dist/skill-test/manifest.d.ts.map +1 -0
- package/dist/skill-test/manifest.js +34 -0
- package/dist/skill-test/manifest.js.map +1 -0
- package/dist/skill-test/plugin-env.d.ts +20 -0
- package/dist/skill-test/plugin-env.d.ts.map +1 -0
- package/dist/skill-test/plugin-env.js +24 -0
- package/dist/skill-test/plugin-env.js.map +1 -0
- package/dist/skill-test/plugin-layout.d.ts +41 -0
- package/dist/skill-test/plugin-layout.d.ts.map +1 -0
- package/dist/skill-test/plugin-layout.js +49 -0
- package/dist/skill-test/plugin-layout.js.map +1 -0
- package/dist/skill-test/preflight.d.ts +31 -0
- package/dist/skill-test/preflight.d.ts.map +1 -0
- package/dist/skill-test/preflight.js +67 -0
- package/dist/skill-test/preflight.js.map +1 -0
- package/dist/skill-test/run-harness.d.ts +102 -0
- package/dist/skill-test/run-harness.d.ts.map +1 -0
- package/dist/skill-test/run-harness.js +446 -0
- package/dist/skill-test/run-harness.js.map +1 -0
- package/dist/skill-test/staging.d.ts +76 -0
- package/dist/skill-test/staging.d.ts.map +1 -0
- package/dist/skill-test/staging.js +145 -0
- package/dist/skill-test/staging.js.map +1 -0
- package/dist/skill-test/vendor-manifest.d.ts +39 -0
- package/dist/skill-test/vendor-manifest.d.ts.map +1 -0
- package/dist/skill-test/vendor-manifest.js +121 -0
- package/dist/skill-test/vendor-manifest.js.map +1 -0
- package/dist/validators/bundled-resource-link-detection.d.ts +1 -1
- package/dist/validators/bundled-resource-link-detection.d.ts.map +1 -1
- package/dist/validators/bundled-resource-link-detection.js +1 -1
- package/dist/validators/bundled-resource-link-detection.js.map +1 -1
- package/dist/validators/compat-detectors.d.ts +1 -1
- package/dist/validators/compat-detectors.d.ts.map +1 -1
- package/dist/validators/compat-detectors.js +1 -1
- package/dist/validators/compat-detectors.js.map +1 -1
- package/dist/validators/cross-skill-dependency-detection.d.ts +1 -1
- package/dist/validators/cross-skill-dependency-detection.d.ts.map +1 -1
- package/dist/validators/cross-skill-dependency-detection.js +1 -1
- package/dist/validators/cross-skill-dependency-detection.js.map +1 -1
- package/dist/validators/description-style-detection.d.ts +1 -1
- package/dist/validators/description-style-detection.d.ts.map +1 -1
- package/dist/validators/description-style-detection.js +1 -1
- package/dist/validators/description-style-detection.js.map +1 -1
- package/dist/validators/frontmatter-validation.d.ts +1 -1
- package/dist/validators/frontmatter-validation.d.ts.map +1 -1
- package/dist/validators/frontmatter-validation.js +1 -1
- package/dist/validators/frontmatter-validation.js.map +1 -1
- package/dist/validators/imperative-body-detection.d.ts +1 -1
- package/dist/validators/imperative-body-detection.d.ts.map +1 -1
- package/dist/validators/imperative-body-detection.js +1 -1
- package/dist/validators/imperative-body-detection.js.map +1 -1
- package/dist/validators/index.d.ts +2 -1
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/kebab-case-detection.d.ts +1 -1
- package/dist/validators/kebab-case-detection.d.ts.map +1 -1
- package/dist/validators/kebab-case-detection.js +1 -1
- package/dist/validators/kebab-case-detection.js.map +1 -1
- package/dist/validators/marketplace-validator.d.ts.map +1 -1
- package/dist/validators/marketplace-validator.js.map +1 -1
- package/dist/validators/packaging-validator.d.ts +8 -3
- package/dist/validators/packaging-validator.d.ts.map +1 -1
- package/dist/validators/packaging-validator.js +45 -23
- package/dist/validators/packaging-validator.js.map +1 -1
- package/dist/validators/plugin-recommended-fields.d.ts +1 -1
- package/dist/validators/plugin-recommended-fields.d.ts.map +1 -1
- package/dist/validators/plugin-recommended-fields.js +1 -1
- package/dist/validators/plugin-recommended-fields.js.map +1 -1
- package/dist/validators/registry-validator.d.ts.map +1 -1
- package/dist/validators/registry-validator.js.map +1 -1
- package/dist/validators/rule-engine/index.d.ts +10 -0
- package/dist/validators/rule-engine/index.d.ts.map +1 -0
- package/dist/validators/rule-engine/index.js +3 -0
- package/dist/validators/rule-engine/index.js.map +1 -0
- package/dist/validators/rule-engine/rule-context.d.ts +107 -0
- package/dist/validators/rule-engine/rule-context.d.ts.map +1 -0
- package/dist/validators/rule-engine/rule-context.js +44 -0
- package/dist/validators/rule-engine/rule-context.js.map +1 -0
- package/dist/validators/rule-engine/rule-engine.d.ts +50 -0
- package/dist/validators/rule-engine/rule-engine.d.ts.map +1 -0
- package/dist/validators/rule-engine/rule-engine.js +117 -0
- package/dist/validators/rule-engine/rule-engine.js.map +1 -0
- package/dist/validators/skill-validator.d.ts.map +1 -1
- package/dist/validators/skill-validator.js +4 -3
- package/dist/validators/skill-validator.js.map +1 -1
- package/dist/validators/types.d.ts +1 -20
- package/dist/validators/types.d.ts.map +1 -1
- package/dist/validators/validation-rules.d.ts +1 -1
- package/dist/validators/validation-rules.d.ts.map +1 -1
- package/dist/validators/validation-rules.js +2 -2
- package/dist/validators/validation-rules.js.map +1 -1
- package/dist/validators/validation-utils.d.ts +1 -1
- package/dist/validators/validation-utils.d.ts.map +1 -1
- package/dist/validators/validation-utils.js.map +1 -1
- package/dist/validators/walker-to-issues.d.ts +13 -1
- package/dist/validators/walker-to-issues.d.ts.map +1 -1
- package/dist/validators/walker-to-issues.js +59 -22
- package/dist/validators/walker-to-issues.js.map +1 -1
- package/dist/walk-link-graph.d.ts +10 -2
- package/dist/walk-link-graph.d.ts.map +1 -1
- package/dist/walk-link-graph.js +38 -14
- package/dist/walk-link-graph.js.map +1 -1
- package/package.json +7 -5
- package/schemas/friction-report.json +59 -0
- package/vendor/skill-creator/ATTRIBUTION.md +12 -0
- package/vendor/skill-creator/LICENSE.txt +202 -0
- package/vendor/skill-creator/SKILL.md +485 -0
- package/vendor/skill-creator/agents/grader.md +223 -0
- package/vendor/skill-creator/plugin.json +8 -0
- package/vendor/skill-creator/references/schemas.md +430 -0
- package/vendor/skill-creator/vendored.manifest.json +10 -0
- package/dist/validators/allow-filter.d.ts +0 -37
- package/dist/validators/allow-filter.d.ts.map +0 -1
- package/dist/validators/allow-filter.js +0 -86
- package/dist/validators/allow-filter.js.map +0 -1
- package/dist/validators/code-registry.d.ts +0 -23
- package/dist/validators/code-registry.d.ts.map +0 -1
- package/dist/validators/code-registry.js +0 -58
- package/dist/validators/code-registry.js.map +0 -1
- package/dist/validators/severity-resolver.d.ts +0 -6
- package/dist/validators/severity-resolver.d.ts.map +0 -1
- package/dist/validators/severity-resolver.js +0 -9
- package/dist/validators/severity-resolver.js.map +0 -1
- package/dist/validators/validation-framework.d.ts +0 -21
- package/dist/validators/validation-framework.d.ts.map +0 -1
- package/dist/validators/validation-framework.js +0 -67
- package/dist/validators/validation-framework.js.map +0 -1
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
* Run after packageSkill() completes — all files are copied, all links rewritten.
|
|
5
5
|
* Detects unreferenced files and broken links in the packaged output.
|
|
6
6
|
*/
|
|
7
|
-
import { existsSync, readdirSync } from 'node:fs';
|
|
7
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
8
8
|
import { readFile } from 'node:fs/promises';
|
|
9
9
|
import { dirname } from 'node:path';
|
|
10
|
+
import { parseHtml } from '@vibe-agent-toolkit/resources';
|
|
10
11
|
import { safePath, toForwardSlash } from '@vibe-agent-toolkit/utils';
|
|
11
|
-
import {
|
|
12
|
+
import { evaluate, makeRuleContext, materializeIssue } from './validators/rule-engine/index.js';
|
|
12
13
|
/**
|
|
13
14
|
* Regex matching markdown inline links: [text](href).
|
|
14
15
|
* Negated character classes [^\]\\] and [^)] are non-backtracking by design.
|
|
@@ -76,38 +77,105 @@ function extractLocalLinks(content) {
|
|
|
76
77
|
return links;
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
79
|
-
*
|
|
80
|
+
* Extract local file hrefs from a content file — markdown or HTML.
|
|
81
|
+
*
|
|
82
|
+
* For markdown: regex-matches `[text](href)` links, skipping code blocks.
|
|
83
|
+
* For HTML/HTM: uses `parseHtml` (parse5-based) and returns `local_file` hrefs only.
|
|
84
|
+
* Fragments are stripped from all returned hrefs.
|
|
85
|
+
*/
|
|
86
|
+
async function extractLocalHrefs(filePath) {
|
|
87
|
+
if (filePath.endsWith('.html') || filePath.endsWith('.htm')) {
|
|
88
|
+
const result = await parseHtml(filePath);
|
|
89
|
+
return result.links
|
|
90
|
+
.filter(link => link.type === 'local_file')
|
|
91
|
+
.map(link => {
|
|
92
|
+
const [withoutFragment] = link.href.split('#');
|
|
93
|
+
return withoutFragment ?? '';
|
|
94
|
+
})
|
|
95
|
+
.filter(href => href.length > 0);
|
|
96
|
+
}
|
|
97
|
+
// Markdown: read content and regex-match
|
|
98
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath from walkDir
|
|
99
|
+
const content = await readFile(filePath, 'utf-8');
|
|
100
|
+
return extractLocalLinks(content);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Check hrefs from a content file against allFileSet and return PACKAGED_BROKEN_LINK
|
|
104
|
+
* issues for any that don't resolve to a file in the packaged output.
|
|
105
|
+
*
|
|
106
|
+
* Shared by markdown and HTML broken-link checks to eliminate duplicate resolve/emit logic.
|
|
107
|
+
*/
|
|
108
|
+
function collectBrokenLinkIssues(sourceFile, hrefs, allFileSet, outputDir) {
|
|
109
|
+
const issues = [];
|
|
110
|
+
const relativeSourcePath = toForwardSlash(safePath.relative(outputDir, sourceFile));
|
|
111
|
+
for (const href of hrefs) {
|
|
112
|
+
const resolved = toForwardSlash(safePath.resolve(dirname(sourceFile), href));
|
|
113
|
+
if (!allFileSet.has(resolved)) {
|
|
114
|
+
// A navigational directory link (href ending in `/`, classified `local_directory`)
|
|
115
|
+
// is a valid target if the directory itself exists on disk — walkDir populates
|
|
116
|
+
// allFileSet with FILES only, so directory paths are never in the set.
|
|
117
|
+
// Note: a NO-SLASH link (`[Concepts](concepts)`, classified `local_file`) that
|
|
118
|
+
// happens to resolve to a directory is a different case — it matches the
|
|
119
|
+
// link-rewrite bundled-link rule (skill-packager.ts buildRewriteRules) and
|
|
120
|
+
// renders with an undefined `link.resource.*`. Fixing that is the
|
|
121
|
+
// link-rewrite engine's job, tracked under #129 (slice 3, built-path
|
|
122
|
+
// unification). The slash form (`concepts/`, `local_directory`) survives
|
|
123
|
+
// rewrite verbatim and is the realistic navigational case this guard covers.
|
|
124
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- resolved is a normalized path from a validated output directory
|
|
125
|
+
const isExistingDirectory = statSync(resolved, { throwIfNoEntry: false })?.isDirectory() === true;
|
|
126
|
+
if (isExistingDirectory) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
// Built-path edge extraction: a link whose target is absent from the
|
|
130
|
+
// packaged output. The engine resolves this to PACKAGED_BROKEN_LINK
|
|
131
|
+
// (a link-rewriter bug) rather than LINK_MISSING_TARGET via phase: 'built'.
|
|
132
|
+
const code = evaluate(makeRuleContext({ subject: 'edge', phase: 'built', existsAtSource: false }));
|
|
133
|
+
if (code !== null) {
|
|
134
|
+
issues.push(materializeIssue(code, {
|
|
135
|
+
location: relativeSourcePath,
|
|
136
|
+
detail: `link: ${href} from ${relativeSourcePath}`,
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return issues;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Walk the markdown and HTML link graph starting at SKILL.md and return the set of
|
|
80
145
|
* referenced file paths (normalized to forward slashes).
|
|
81
146
|
*
|
|
82
|
-
* SKILL.md itself is always included as the root.
|
|
147
|
+
* SKILL.md itself is always included as the root. Traversal follows `.md`, `.html`,
|
|
148
|
+
* and `.htm` links transitively so an HTML file referenced only by another HTML file
|
|
149
|
+
* is not reported as unreferenced.
|
|
83
150
|
*/
|
|
84
151
|
async function collectReferencedPaths(outputDir, allFileSet) {
|
|
85
152
|
const referenced = new Set();
|
|
86
153
|
const skillMdPath = safePath.join(outputDir, 'SKILL.md');
|
|
87
|
-
const
|
|
154
|
+
const fileQueue = [skillMdPath];
|
|
88
155
|
const visited = new Set();
|
|
89
156
|
// SKILL.md itself is the root — always referenced
|
|
90
157
|
referenced.add(toForwardSlash(skillMdPath));
|
|
91
|
-
while (
|
|
92
|
-
const
|
|
93
|
-
if (!
|
|
158
|
+
while (fileQueue.length > 0) {
|
|
159
|
+
const filePath = fileQueue.shift();
|
|
160
|
+
if (!filePath)
|
|
94
161
|
break;
|
|
95
|
-
const normalized = toForwardSlash(
|
|
162
|
+
const normalized = toForwardSlash(filePath);
|
|
96
163
|
if (visited.has(normalized))
|
|
97
164
|
continue;
|
|
98
165
|
visited.add(normalized);
|
|
99
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename --
|
|
100
|
-
if (!existsSync(
|
|
166
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- filePath from walkDir output
|
|
167
|
+
if (!existsSync(filePath))
|
|
101
168
|
continue;
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
for (const href of links) {
|
|
106
|
-
const resolved = toForwardSlash(safePath.resolve(dirname(mdFile), href));
|
|
169
|
+
const hrefs = await extractLocalHrefs(filePath);
|
|
170
|
+
for (const href of hrefs) {
|
|
171
|
+
const resolved = toForwardSlash(safePath.resolve(dirname(filePath), href));
|
|
107
172
|
referenced.add(resolved);
|
|
108
|
-
//
|
|
109
|
-
|
|
110
|
-
|
|
173
|
+
// Traverse .md, .html, and .htm files transitively
|
|
174
|
+
const isTraversable = (resolved.endsWith('.md') || resolved.endsWith('.html') || resolved.endsWith('.htm')) &&
|
|
175
|
+
allFileSet.has(resolved) &&
|
|
176
|
+
!visited.has(resolved);
|
|
177
|
+
if (isTraversable) {
|
|
178
|
+
fileQueue.push(resolved);
|
|
111
179
|
}
|
|
112
180
|
}
|
|
113
181
|
}
|
|
@@ -115,22 +183,22 @@ async function collectReferencedPaths(outputDir, allFileSet) {
|
|
|
115
183
|
}
|
|
116
184
|
/**
|
|
117
185
|
* Record packaged files whose output-relative path appears anywhere in any
|
|
118
|
-
* packaged markdown — inside code blocks
|
|
119
|
-
*
|
|
186
|
+
* packaged content file (markdown or HTML) — inside code blocks, inline code
|
|
187
|
+
* spans, or prose — as "documented" references.
|
|
120
188
|
*
|
|
121
189
|
* A file that a skill author chose to bundle but never documents is the real
|
|
122
190
|
* problem this check exists to catch; documentation by code-block invocation
|
|
123
191
|
* is still documentation. By contrast, `collectReferencedPaths` is intentionally
|
|
124
|
-
* strict (only
|
|
192
|
+
* strict (only formal link syntax) because it also walks the transitive link
|
|
125
193
|
* graph, which would be unbounded if we followed substring hits.
|
|
126
194
|
*/
|
|
127
|
-
async function addMentionReferences(outputDir, referenced, candidates,
|
|
128
|
-
if (candidates.length === 0 ||
|
|
195
|
+
async function addMentionReferences(outputDir, referenced, candidates, contentFiles) {
|
|
196
|
+
if (candidates.length === 0 || contentFiles.length === 0) {
|
|
129
197
|
return;
|
|
130
198
|
}
|
|
131
199
|
const contents = await Promise.all(
|
|
132
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename --
|
|
133
|
-
|
|
200
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- contentFile from walkDir
|
|
201
|
+
contentFiles.map(f => readFile(f, 'utf-8')));
|
|
134
202
|
const haystack = contents.join('\n');
|
|
135
203
|
for (const candidate of candidates) {
|
|
136
204
|
const relativePath = toForwardSlash(safePath.relative(outputDir, candidate));
|
|
@@ -140,68 +208,58 @@ async function addMentionReferences(outputDir, referenced, candidates, mdFiles)
|
|
|
140
208
|
}
|
|
141
209
|
}
|
|
142
210
|
/**
|
|
143
|
-
* Check that every file in the packaged output is referenced from some markdown file.
|
|
211
|
+
* Check that every file in the packaged output is referenced from some markdown or HTML file.
|
|
144
212
|
*
|
|
145
213
|
* Two-pass detection:
|
|
146
|
-
* 1. Walk
|
|
214
|
+
* 1. Walk formal link graph from SKILL.md (strict, transitive, covers .md and .html/.htm).
|
|
147
215
|
* 2. For files not covered by pass 1, check whether their output-relative path
|
|
148
|
-
* is mentioned anywhere in packaged
|
|
216
|
+
* is mentioned anywhere in packaged content files (markdown or HTML).
|
|
149
217
|
* Authors often document CLI scripts via invocation examples rather than
|
|
150
|
-
*
|
|
218
|
+
* formal links, and that counts as documented.
|
|
151
219
|
*/
|
|
152
220
|
export async function checkUnreferencedFiles(outputDir) {
|
|
153
221
|
const allFiles = walkDir(outputDir);
|
|
154
222
|
const allFileSet = new Set(allFiles.map(f => toForwardSlash(f)));
|
|
155
223
|
const referenced = await collectReferencedPaths(outputDir, allFileSet);
|
|
156
|
-
// Second pass: treat any path mention in packaged
|
|
224
|
+
// Second pass: treat any path mention in packaged content files as documentation.
|
|
157
225
|
const candidates = allFiles.filter(f => !referenced.has(toForwardSlash(f)));
|
|
158
|
-
const
|
|
159
|
-
await addMentionReferences(outputDir, referenced, candidates,
|
|
226
|
+
const contentFiles = allFiles.filter(f => f.endsWith('.md') || f.endsWith('.html') || f.endsWith('.htm'));
|
|
227
|
+
await addMentionReferences(outputDir, referenced, candidates, contentFiles);
|
|
160
228
|
// Find unreferenced files
|
|
161
229
|
const issues = [];
|
|
162
230
|
for (const file of allFiles) {
|
|
163
231
|
const normalized = toForwardSlash(file);
|
|
164
232
|
if (!referenced.has(normalized)) {
|
|
165
233
|
const relativePath = toForwardSlash(safePath.relative(outputDir, file));
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
234
|
+
// Built-path file extraction: a packaged file reachable by neither link
|
|
235
|
+
// nor mention nor files: declaration. The engine resolves this to
|
|
236
|
+
// PACKAGED_UNREFERENCED_FILE for a skill-bundled copy at the built phase.
|
|
237
|
+
const code = evaluate(makeRuleContext({
|
|
238
|
+
subject: 'file',
|
|
239
|
+
phase: 'built',
|
|
240
|
+
copyRole: 'skill-bundled',
|
|
241
|
+
reachableFromSkillMd: false,
|
|
242
|
+
referencedHow: 'none',
|
|
243
|
+
}));
|
|
244
|
+
if (code !== null) {
|
|
245
|
+
issues.push(materializeIssue(code, { location: relativePath, detail: relativePath }));
|
|
246
|
+
}
|
|
174
247
|
}
|
|
175
248
|
}
|
|
176
249
|
return issues;
|
|
177
250
|
}
|
|
178
251
|
/**
|
|
179
|
-
* Check that every local file link in packaged markdown files resolves to a file
|
|
252
|
+
* Check that every local file link in packaged markdown and HTML files resolves to a file
|
|
180
253
|
* that exists in the packaged output.
|
|
181
254
|
*/
|
|
182
255
|
export async function checkBrokenPackagedLinks(outputDir) {
|
|
183
256
|
const allFiles = walkDir(outputDir);
|
|
184
|
-
const
|
|
257
|
+
const linkableFiles = allFiles.filter(f => f.endsWith('.md') || f.endsWith('.html') || f.endsWith('.htm'));
|
|
185
258
|
const allFileSet = new Set(allFiles.map(f => toForwardSlash(f)));
|
|
186
259
|
const issues = [];
|
|
187
|
-
for (const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const links = extractLocalLinks(content);
|
|
191
|
-
const relativeMdPath = toForwardSlash(safePath.relative(outputDir, mdFile));
|
|
192
|
-
for (const href of links) {
|
|
193
|
-
const resolved = toForwardSlash(safePath.resolve(dirname(mdFile), href));
|
|
194
|
-
if (!allFileSet.has(resolved)) {
|
|
195
|
-
issues.push({
|
|
196
|
-
severity: CODE_REGISTRY.PACKAGED_BROKEN_LINK.defaultSeverity,
|
|
197
|
-
code: 'PACKAGED_BROKEN_LINK',
|
|
198
|
-
message: `Broken link in packaged output: ${href} (from ${relativeMdPath})`,
|
|
199
|
-
location: relativeMdPath,
|
|
200
|
-
fix: CODE_REGISTRY.PACKAGED_BROKEN_LINK.fix,
|
|
201
|
-
reference: CODE_REGISTRY.PACKAGED_BROKEN_LINK.reference,
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
260
|
+
for (const sourceFile of linkableFiles) {
|
|
261
|
+
const hrefs = await extractLocalHrefs(sourceFile);
|
|
262
|
+
issues.push(...collectBrokenLinkIssues(sourceFile, hrefs, allFileSet, outputDir));
|
|
205
263
|
}
|
|
206
264
|
return issues;
|
|
207
265
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-build-checks.js","sourceRoot":"","sources":["../src/post-build-checks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"post-build-checks.js","sourceRoot":"","sources":["../src/post-build-checks.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAEhG;;;GAGG;AACH,gGAAgG;AAChG,MAAM,iBAAiB,GAAG,kCAAkC,CAAC;AAE7D;;;GAGG;AACH,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAEvC;;;;GAIG;AACH,SAAS,eAAe,CAAC,OAAe;IACtC,OAAO,OAAO,CAAC,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACrF,CAAC;AAED;;GAEG;AACH,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B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,OAAO,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAC/D,CAAC;IACF,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,KAAK,MAAM,UAAU,IAAI,aAAa,EAAE,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,GAAG,uBAAuB,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;IACpF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -11,16 +11,16 @@ declare const PluginInstallationSchema: z.ZodObject<{
|
|
|
11
11
|
gitCommitSha: z.ZodOptional<z.ZodString>;
|
|
12
12
|
isLocal: z.ZodBoolean;
|
|
13
13
|
}, "strict", z.ZodTypeAny, {
|
|
14
|
-
version: string;
|
|
15
14
|
scope: "user" | "system";
|
|
15
|
+
version: string;
|
|
16
16
|
installPath: string;
|
|
17
17
|
installedAt: string;
|
|
18
18
|
lastUpdated: string;
|
|
19
19
|
isLocal: boolean;
|
|
20
20
|
gitCommitSha?: string | undefined;
|
|
21
21
|
}, {
|
|
22
|
-
version: string;
|
|
23
22
|
scope: "user" | "system";
|
|
23
|
+
version: string;
|
|
24
24
|
installPath: string;
|
|
25
25
|
installedAt: string;
|
|
26
26
|
lastUpdated: string;
|
|
@@ -46,16 +46,16 @@ export declare const InstalledPluginsRegistrySchema: z.ZodObject<{
|
|
|
46
46
|
gitCommitSha: z.ZodOptional<z.ZodString>;
|
|
47
47
|
isLocal: z.ZodBoolean;
|
|
48
48
|
}, "strict", z.ZodTypeAny, {
|
|
49
|
-
version: string;
|
|
50
49
|
scope: "user" | "system";
|
|
50
|
+
version: string;
|
|
51
51
|
installPath: string;
|
|
52
52
|
installedAt: string;
|
|
53
53
|
lastUpdated: string;
|
|
54
54
|
isLocal: boolean;
|
|
55
55
|
gitCommitSha?: string | undefined;
|
|
56
56
|
}, {
|
|
57
|
-
version: string;
|
|
58
57
|
scope: "user" | "system";
|
|
58
|
+
version: string;
|
|
59
59
|
installPath: string;
|
|
60
60
|
installedAt: string;
|
|
61
61
|
lastUpdated: string;
|
|
@@ -65,8 +65,8 @@ export declare const InstalledPluginsRegistrySchema: z.ZodObject<{
|
|
|
65
65
|
}, "strict", z.ZodTypeAny, {
|
|
66
66
|
version: 2;
|
|
67
67
|
plugins: Record<string, {
|
|
68
|
-
version: string;
|
|
69
68
|
scope: "user" | "system";
|
|
69
|
+
version: string;
|
|
70
70
|
installPath: string;
|
|
71
71
|
installedAt: string;
|
|
72
72
|
lastUpdated: string;
|
|
@@ -76,8 +76,8 @@ export declare const InstalledPluginsRegistrySchema: z.ZodObject<{
|
|
|
76
76
|
}, {
|
|
77
77
|
version: 2;
|
|
78
78
|
plugins: Record<string, {
|
|
79
|
-
version: string;
|
|
80
79
|
scope: "user" | "system";
|
|
80
|
+
version: string;
|
|
81
81
|
installPath: string;
|
|
82
82
|
installedAt: string;
|
|
83
83
|
lastUpdated: string;
|
package/dist/skill-packager.d.ts
CHANGED
|
@@ -14,12 +14,11 @@
|
|
|
14
14
|
* Uses ResourceRegistry + transformContent() from @vibe-agent-toolkit/resources
|
|
15
15
|
* for link resolution and rewriting (replacing the previous inline regex approach).
|
|
16
16
|
*/
|
|
17
|
+
import { type ValidationConfig, type ValidationIssue } from '@vibe-agent-toolkit/agent-schema';
|
|
17
18
|
import { ResourceRegistry } from '@vibe-agent-toolkit/resources';
|
|
18
19
|
import { type GitTracker } from '@vibe-agent-toolkit/utils';
|
|
19
|
-
import type
|
|
20
|
+
import { type SkillFileEntry } from './files-config.js';
|
|
20
21
|
import { type PackagingValidationResult } from './validators/packaging-validator.js';
|
|
21
|
-
import type { ValidationIssue } from './validators/types.js';
|
|
22
|
-
import { type ValidationConfig } from './validators/validation-framework.js';
|
|
23
22
|
/**
|
|
24
23
|
* Resource naming strategy type
|
|
25
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skill-packager.d.ts","sourceRoot":"","sources":["../src/skill-packager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EACL,gBAAgB,
|
|
1
|
+
{"version":3,"file":"skill-packager.d.ts","sourceRoot":"","sources":["../src/skill-packager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,gBAAgB,EAYjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAA0C,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEhG,OAAO,EAA6B,KAAK,yBAAyB,EAAE,MAAM,qCAAqC,CAAC;AAShH;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,UAAU,GAAG,aAAa,GAAG,eAAe,CAAC;AAElF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG,YAAY,CAAC;AAK3D,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,OAAO,CAAC,EAAE,CAAC,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,aAAa,CAAC,EAAE,CAAC;IAE1D;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;;;;;;;;OAcG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;IAExC;;;;;;;;;;;;OAYG;IACH,WAAW,CAA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
import { copyFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
19
19
|
import { basename, dirname } from 'node:path';
|
|
20
|
-
import {
|
|
20
|
+
import { runValidationFramework, } from '@vibe-agent-toolkit/agent-schema';
|
|
21
|
+
import { ResourceRegistry, loadConfig, openFrontmatter, resolveLocalHref, rewriteFrontmatterUriReferencesFromSchema, rewriteHtmlLinks, transformContent, parseMarkdown, } from '@vibe-agent-toolkit/resources';
|
|
21
22
|
import { findProjectRoot, resolveAssetReference, toForwardSlash, safePath, } from '@vibe-agent-toolkit/utils';
|
|
22
23
|
import { getTargetSubdir } from './content-type-routing.js';
|
|
24
|
+
import { applyFilesConfig, computeDeferredPaths } from './files-config.js';
|
|
23
25
|
import { checkBrokenPackagedLinks, checkUnreferencedFiles } from './post-build-checks.js';
|
|
24
26
|
import { validateSkillForPackaging } from './validators/packaging-validator.js';
|
|
25
|
-
import {
|
|
26
|
-
import { walkerExclusionsToIssues } from './validators/walker-to-issues.js';
|
|
27
|
+
import { deferredAssetsToIssues, walkerExclusionsToIssues } from './validators/walker-to-issues.js';
|
|
27
28
|
import { walkLinkGraph } from './walk-link-graph.js';
|
|
28
29
|
const PACKAGE_JSON_FILENAME = 'package.json';
|
|
29
30
|
/** Default template for excluded links when no explicit template is configured — renders just the link text */
|
|
@@ -108,17 +109,20 @@ export async function packageSkill(skillPath, options = {}) {
|
|
|
108
109
|
// Find the skill resource in the registry
|
|
109
110
|
const skillResource = registry.getResource(safePath.resolve(skillPath));
|
|
110
111
|
const skillResourceId = skillResource?.id ?? '';
|
|
112
|
+
const filesConfig = options.files ?? [];
|
|
113
|
+
const deferredPaths = computeDeferredPaths(filesConfig, { skillDir: skillRoot, projectRoot });
|
|
111
114
|
const packagerWalkOptions = {
|
|
112
115
|
maxDepth,
|
|
113
116
|
excludeRules: excludeConfig?.rules ?? [],
|
|
114
117
|
projectRoot,
|
|
115
118
|
skillRootPath: safePath.resolve(skillPath),
|
|
116
119
|
excludeNavigationFiles,
|
|
120
|
+
deferredPaths,
|
|
117
121
|
};
|
|
118
122
|
if (options.gitTracker !== undefined) {
|
|
119
123
|
packagerWalkOptions.gitTracker = options.gitTracker;
|
|
120
124
|
}
|
|
121
|
-
const { bundledResources, bundledAssets, excludedReferences } = walkLinkGraph(skillResourceId, registry, packagerWalkOptions);
|
|
125
|
+
const { bundledResources, bundledAssets, excludedReferences, deferredAssets } = walkLinkGraph(skillResourceId, registry, packagerWalkOptions);
|
|
122
126
|
// Register non-markdown bundled assets in the source registry so link rewriting
|
|
123
127
|
// can resolve them (resolvedId must be set on links pointing to YAML, JSON, etc.).
|
|
124
128
|
// For any asset whose ID collides with a paired markdown file (e.g. config.yaml +
|
|
@@ -148,7 +152,6 @@ export async function packageSkill(skillPath, options = {}) {
|
|
|
148
152
|
const namingBasePath = projectRoot;
|
|
149
153
|
const pathMap = buildPathMap(skillPath, bundledFiles, outputPath, resourceNaming, namingBasePath, stripPrefix, target);
|
|
150
154
|
// 8b. Apply files config: copy declared files and adjust path map
|
|
151
|
-
const filesConfig = options.files ?? [];
|
|
152
155
|
for (const fileEntry of filesConfig) {
|
|
153
156
|
const absoluteSource = safePath.resolve(safePath.join(projectRoot, fileEntry.source));
|
|
154
157
|
const absoluteDest = safePath.join(outputPath, fileEntry.dest);
|
|
@@ -175,6 +178,10 @@ export async function packageSkill(skillPath, options = {}) {
|
|
|
175
178
|
}
|
|
176
179
|
// Add non-markdown bundled files (assets) to output registry so link rewriting resolves them
|
|
177
180
|
addBundledAssetsToOutputRegistry(outputResources, bundledAssets, pathMap, registry, collidedAssets);
|
|
181
|
+
// Register files: deferred-dest links so the build preserves/rewrites them (mirrors
|
|
182
|
+
// the collided-asset handling). Stamps resolvedId on dest links and adds a synthetic
|
|
183
|
+
// output resource so the rewriter renders [text](dest) instead of stripping to ().
|
|
184
|
+
outputResources.push(...registerDeferredDestLinks(filesConfig, collectResourcesWithLinks(bundledResources, skillResource), skillPath, outputPath, outputResources));
|
|
178
185
|
// Include excluded resources (with source paths) for pattern-based rule matching
|
|
179
186
|
for (const excl of excludedReferences) {
|
|
180
187
|
if (excl.excludeReason === 'directory-target' || excl.excludeReason === 'outside-project') {
|
|
@@ -213,9 +220,10 @@ export async function packageSkill(skillPath, options = {}) {
|
|
|
213
220
|
templateContext: { skill: { name: skillMetadata.name } },
|
|
214
221
|
collectionSchemas,
|
|
215
222
|
projectRoot,
|
|
223
|
+
warn: (message) => process.stderr.write(`warning: ${message}\n`),
|
|
216
224
|
});
|
|
217
225
|
// 12b. Copy files config entries that were not auto-discovered via link traversal.
|
|
218
|
-
await
|
|
226
|
+
await applyFilesConfig({ filesConfig, projectRoot, skillOutputDir: outputPath, bundledFiles });
|
|
219
227
|
// 13. Post-build integrity check: no SKILL.md in subdirectories
|
|
220
228
|
// A SKILL.md is a skill definition marker — it must only exist at the root.
|
|
221
229
|
// If another skill's SKILL.md was bundled as a resource, it creates duplicate
|
|
@@ -232,7 +240,10 @@ export async function packageSkill(skillPath, options = {}) {
|
|
|
232
240
|
...await checkUnreferencedFiles(outputPath),
|
|
233
241
|
...await checkBrokenPackagedLinks(outputPath),
|
|
234
242
|
];
|
|
235
|
-
const rawLinkIssues =
|
|
243
|
+
const rawLinkIssues = [
|
|
244
|
+
...walkerExclusionsToIssues(excludedReferences, projectRoot),
|
|
245
|
+
...deferredAssetsToIssues(deferredAssets, projectRoot),
|
|
246
|
+
];
|
|
236
247
|
const framework = runValidationFramework([...rawLinkIssues, ...rawPostBuildIssues], options.validation ?? {});
|
|
237
248
|
// 13c. Run full validation suite on built output
|
|
238
249
|
const postBuildValidation = await runPostBuildValidation(outputPath, options.validation);
|
|
@@ -471,6 +482,73 @@ function buildSyntheticAssetResource(assetPath, outputFilePath) {
|
|
|
471
482
|
checksum: '0'.repeat(64),
|
|
472
483
|
};
|
|
473
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Register `files:` deferred-dest links so the build preserves and rewrites them.
|
|
487
|
+
*
|
|
488
|
+
* A deferred dest (e.g. `dist/bin/cli.mjs → scripts/cli.mjs`) does not exist at
|
|
489
|
+
* source-walk time, so it is neither a bundled resource nor a bundled asset: its
|
|
490
|
+
* link gets no `resolvedId` and the dest is absent from the output registry. The
|
|
491
|
+
* bundled-link template then renders an empty `relativePath` and strips the href
|
|
492
|
+
* to `()` — leaving the shipped artifact unreferenced (`PACKAGED_UNREFERENCED_FILE`).
|
|
493
|
+
*
|
|
494
|
+
* This mirrors the collided-asset handling: for each `files:` entry we synthesize
|
|
495
|
+
* a stable id (`synthesizeAssetId(absDestTarget)`), stamp it as `resolvedId` on
|
|
496
|
+
* any local_file link that resolves to the dest, and return a synthetic output
|
|
497
|
+
* resource (`buildSyntheticAssetResource`) whose `filePath` is the dest's output
|
|
498
|
+
* path so the output registry computes `relativePath = entry.dest`.
|
|
499
|
+
*
|
|
500
|
+
* Scope: dest links only. A SKILL.md link to a deferred *source* path that is
|
|
501
|
+
* copied to a different dest is an exotic case with ambiguous output mapping and
|
|
502
|
+
* is intentionally left to its existing behavior.
|
|
503
|
+
*
|
|
504
|
+
* @returns Synthetic output resources to push into `outputResources` (deduped by
|
|
505
|
+
* filePath against the existing set) BEFORE the output registry is built.
|
|
506
|
+
*/
|
|
507
|
+
function registerDeferredDestLinks(filesConfig, resources, skillPath, outputPath, existingOutputResources) {
|
|
508
|
+
const syntheticResources = [];
|
|
509
|
+
const skillDir = dirname(skillPath);
|
|
510
|
+
for (const entry of filesConfig) {
|
|
511
|
+
// Where a SKILL.md link `entry.dest` resolves at source time (SKILL.md lives at skillPath).
|
|
512
|
+
const absDestTarget = safePath.resolve(skillDir, entry.dest);
|
|
513
|
+
const absDestOutput = safePath.join(outputPath, entry.dest);
|
|
514
|
+
const id = synthesizeAssetId(absDestTarget);
|
|
515
|
+
if (!stampDeferredDestResolvedId(resources, absDestTarget, id))
|
|
516
|
+
continue;
|
|
517
|
+
// Dedup: skip if an output resource already targets this dest output path.
|
|
518
|
+
const alreadyPresent = existingOutputResources.some(r => toForwardSlash(r.filePath) === toForwardSlash(absDestOutput)) ||
|
|
519
|
+
syntheticResources.some(r => toForwardSlash(r.filePath) === toForwardSlash(absDestOutput));
|
|
520
|
+
if (alreadyPresent)
|
|
521
|
+
continue;
|
|
522
|
+
// buildSyntheticAssetResource derives the id via synthesizeAssetId(absDestTarget),
|
|
523
|
+
// matching the resolvedId stamped above.
|
|
524
|
+
syntheticResources.push(buildSyntheticAssetResource(absDestTarget, absDestOutput));
|
|
525
|
+
}
|
|
526
|
+
return syntheticResources;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Stamp `resolvedId` on every unresolved local_file link that resolves to the
|
|
530
|
+
* deferred dest target. Mirrors the link-walk in `resolveCollidedAssetLinks`.
|
|
531
|
+
*
|
|
532
|
+
* @returns true if at least one link was stamped (the dest is referenced).
|
|
533
|
+
*/
|
|
534
|
+
function stampDeferredDestResolvedId(resources, absDestTarget, id) {
|
|
535
|
+
let linked = false;
|
|
536
|
+
for (const resource of resources) {
|
|
537
|
+
for (const link of resource.links) {
|
|
538
|
+
if (link.type !== 'local_file' || link.resolvedId !== undefined) {
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
const [hrefPath] = link.href.split('#');
|
|
542
|
+
if (hrefPath === undefined)
|
|
543
|
+
continue;
|
|
544
|
+
if (safePath.resolve(dirname(resource.filePath), hrefPath) === absDestTarget) {
|
|
545
|
+
link.resolvedId = id;
|
|
546
|
+
linked = true;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return linked;
|
|
551
|
+
}
|
|
474
552
|
// ============================================================================
|
|
475
553
|
// Path Map Building
|
|
476
554
|
// ============================================================================
|
|
@@ -560,25 +638,6 @@ function buildRewriteRules(excludedIds, excludeRules, defaultExcludeTemplate) {
|
|
|
560
638
|
}
|
|
561
639
|
return rules;
|
|
562
640
|
}
|
|
563
|
-
/**
|
|
564
|
-
* Copy files config entries that were not auto-discovered via link traversal.
|
|
565
|
-
*
|
|
566
|
-
* Build artifacts declared in `files` (e.g. `dist/bin/cli.mjs → scripts/cli.mjs`)
|
|
567
|
-
* are not in the link graph (the linked path points to `dest`, which doesn't exist
|
|
568
|
-
* at source time). This step copies them explicitly to the output directory.
|
|
569
|
-
*/
|
|
570
|
-
async function copyFilesConfigEntries(filesConfig, bundledFiles, projectRoot, outputPath) {
|
|
571
|
-
const bundledFileSet = new Set(bundledFiles.map(f => toForwardSlash(f)));
|
|
572
|
-
for (const fileEntry of filesConfig) {
|
|
573
|
-
const absoluteSource = safePath.resolve(safePath.join(projectRoot, fileEntry.source));
|
|
574
|
-
const absoluteDest = safePath.join(outputPath, fileEntry.dest);
|
|
575
|
-
if (!bundledFileSet.has(toForwardSlash(absoluteSource))) {
|
|
576
|
-
// eslint-disable-next-line security/detect-non-literal-fs-filename -- source path from validated config
|
|
577
|
-
await mkdir(dirname(absoluteDest), { recursive: true });
|
|
578
|
-
await copyFile(absoluteSource, absoluteDest);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
641
|
/**
|
|
583
642
|
* Copy SKILL.md and all linked files to the output directory,
|
|
584
643
|
* rewriting links using transformContent().
|
|
@@ -616,8 +675,11 @@ async function copyAndRewriteFile(sourcePath, targetPath, ctx) {
|
|
|
616
675
|
// Ensure target directory exists
|
|
617
676
|
// eslint-disable-next-line security/detect-non-literal-fs-filename -- targetPath is constructed from validated paths
|
|
618
677
|
await mkdir(dirname(targetPath), { recursive: true });
|
|
619
|
-
|
|
620
|
-
|
|
678
|
+
const lower = sourcePath.toLowerCase();
|
|
679
|
+
const isMarkdown = lower.endsWith('.md');
|
|
680
|
+
const isHtml = lower.endsWith('.html') || lower.endsWith('.htm');
|
|
681
|
+
// Non-rewritable files or rewriting disabled: plain binary copy
|
|
682
|
+
if ((!isMarkdown && !isHtml) || !ctx.rewriteLinks) {
|
|
621
683
|
await copyFile(sourcePath, targetPath);
|
|
622
684
|
return;
|
|
623
685
|
}
|
|
@@ -627,11 +689,27 @@ async function copyAndRewriteFile(sourcePath, targetPath, ctx) {
|
|
|
627
689
|
// Look up the resource in the "from" registry
|
|
628
690
|
const resource = ctx.fromRegistry.getResource(safePath.resolve(sourcePath));
|
|
629
691
|
if (!resource) {
|
|
630
|
-
// Resource not in registry — write content as-is
|
|
692
|
+
// Resource not in registry — write content as-is. For HTML this is only
|
|
693
|
+
// reachable on an ID collision (e.g. page.html + page.md), where the asset
|
|
694
|
+
// is copied verbatim and its links are NOT rewritten (v1 limitation,
|
|
695
|
+
// mirrors the pre-existing asset-collision behavior).
|
|
696
|
+
ctx.warn(`Copied '${sourcePath}' verbatim without link rewriting: it is not in the resource registry ` +
|
|
697
|
+
`(typically an ID collision with a same-named markdown file). Source-relative links inside it are not rewritten.`);
|
|
631
698
|
// eslint-disable-next-line security/detect-non-literal-fs-filename -- targetPath is constructed from validated paths
|
|
632
699
|
await writeFile(targetPath, content, 'utf-8');
|
|
633
700
|
return;
|
|
634
701
|
}
|
|
702
|
+
// HTML: offset-splice link rewrite (no frontmatter, no template body rewrite).
|
|
703
|
+
if (isHtml) {
|
|
704
|
+
const rewriteHref = buildHrefRewriter(ctx.fromRegistry, ctx.toRegistry, sourcePath, targetPath, ctx.projectRoot);
|
|
705
|
+
const rewritten = rewriteHtmlLinks(content, rewriteHref, (info) => {
|
|
706
|
+
ctx.warn(`Could not rewrite <${info.tagName} ${info.attr}="${info.from}"> in '${sourcePath}' (${info.reason}); ` +
|
|
707
|
+
`the original value was kept.`);
|
|
708
|
+
});
|
|
709
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- targetPath is constructed from validated paths
|
|
710
|
+
await writeFile(targetPath, rewritten, 'utf-8');
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
635
713
|
// Parse once via FrontmatterEditor so comments survive any frontmatter
|
|
636
714
|
// rewrites. The body is held verbatim; we run it through transformContent
|
|
637
715
|
// for the existing rule/template body-link rewrite contract (unchanged).
|
|
@@ -649,7 +727,7 @@ async function copyAndRewriteFile(sourcePath, targetPath, ctx) {
|
|
|
649
727
|
// and body agree on target paths.
|
|
650
728
|
const matchingCollections = (resource.collections ?? []).filter((id) => ctx.collectionSchemas.has(id));
|
|
651
729
|
if (matchingCollections.length > 0) {
|
|
652
|
-
const rewriteHref =
|
|
730
|
+
const rewriteHref = buildHrefRewriter(ctx.fromRegistry, ctx.toRegistry, sourcePath, targetPath, ctx.projectRoot);
|
|
653
731
|
for (const collectionId of matchingCollections) {
|
|
654
732
|
const schema = ctx.collectionSchemas.get(collectionId);
|
|
655
733
|
if (schema) {
|
|
@@ -661,7 +739,7 @@ async function copyAndRewriteFile(sourcePath, targetPath, ctx) {
|
|
|
661
739
|
await writeFile(targetPath, editor.toString(), 'utf-8');
|
|
662
740
|
}
|
|
663
741
|
/**
|
|
664
|
-
* Build the per-href rewrite callback used for frontmatter URI-refs.
|
|
742
|
+
* Build the per-href rewrite callback used for frontmatter URI-refs and HTML attributes.
|
|
665
743
|
*
|
|
666
744
|
* Mirrors the body-rewrite path so frontmatter and body link rewriting agree
|
|
667
745
|
* on target paths:
|
|
@@ -676,7 +754,7 @@ async function copyAndRewriteFile(sourcePath, targetPath, ctx) {
|
|
|
676
754
|
*
|
|
677
755
|
* Returns the original href when no rewrite applies.
|
|
678
756
|
*/
|
|
679
|
-
function
|
|
757
|
+
function buildHrefRewriter(fromRegistry, toRegistry, sourcePath, targetPath, projectRoot) {
|
|
680
758
|
const targetDir = dirname(targetPath);
|
|
681
759
|
return (href) => {
|
|
682
760
|
const resolution = resolveLocalHref(href, sourcePath, projectRoot);
|