@harnesspm/cli 0.0.0-snapshot.412a718 → 0.0.0-stage

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.
Files changed (80) hide show
  1. package/README.md +2 -69
  2. package/package.json +4 -71
  3. package/CHANGELOG.md +0 -259
  4. package/LICENSE +0 -21
  5. package/dist/added.d.ts +0 -51
  6. package/dist/added.js +0 -192
  7. package/dist/check.d.ts +0 -14
  8. package/dist/check.js +0 -263
  9. package/dist/cli.d.ts +0 -2
  10. package/dist/cli.js +0 -218
  11. package/dist/commands.d.ts +0 -58
  12. package/dist/commands.js +0 -1299
  13. package/dist/config.d.ts +0 -15
  14. package/dist/config.js +0 -45
  15. package/dist/deliver.d.ts +0 -1
  16. package/dist/deliver.js +0 -31
  17. package/dist/doctor.d.ts +0 -18
  18. package/dist/doctor.js +0 -99
  19. package/dist/exec-outputs.d.ts +0 -75
  20. package/dist/exec-outputs.js +0 -425
  21. package/dist/exec-units.d.ts +0 -68
  22. package/dist/exec-units.js +0 -151
  23. package/dist/fetch.d.ts +0 -16
  24. package/dist/fetch.js +0 -145
  25. package/dist/frontmatter.d.ts +0 -16
  26. package/dist/frontmatter.js +0 -49
  27. package/dist/homes.d.ts +0 -7
  28. package/dist/homes.js +0 -21
  29. package/dist/lock.d.ts +0 -47
  30. package/dist/lock.js +0 -245
  31. package/dist/manifest.d.ts +0 -78
  32. package/dist/manifest.js +0 -169
  33. package/dist/new.d.ts +0 -33
  34. package/dist/new.js +0 -228
  35. package/dist/outputs.d.ts +0 -124
  36. package/dist/outputs.js +0 -875
  37. package/dist/parent.d.ts +0 -41
  38. package/dist/parent.js +0 -182
  39. package/dist/render.d.ts +0 -91
  40. package/dist/render.js +0 -221
  41. package/dist/resolve.d.ts +0 -132
  42. package/dist/resolve.js +0 -522
  43. package/dist/reviewed.d.ts +0 -15
  44. package/dist/reviewed.js +0 -41
  45. package/dist/run.d.ts +0 -18
  46. package/dist/run.js +0 -133
  47. package/dist/sections.d.ts +0 -32
  48. package/dist/sections.js +0 -121
  49. package/dist/telemetry-api.d.ts +0 -26
  50. package/dist/telemetry-api.js +0 -60
  51. package/dist/telemetry.d.ts +0 -119
  52. package/dist/telemetry.js +0 -401
  53. package/dist/user-outputs.d.ts +0 -30
  54. package/dist/user-outputs.js +0 -239
  55. package/dist/util.d.ts +0 -137
  56. package/dist/util.js +0 -370
  57. package/dist/workspaces.d.ts +0 -2
  58. package/dist/workspaces.js +0 -62
  59. package/docs/spec/01-overview.md +0 -149
  60. package/docs/spec/02-package-format.md +0 -252
  61. package/docs/spec/03-resolution.md +0 -108
  62. package/docs/spec/04-outputs.md +0 -194
  63. package/docs/spec/05-executables.md +0 -170
  64. package/docs/spec/06-trust.md +0 -88
  65. package/docs/spec/07-added.md +0 -109
  66. package/docs/spec/08-improving.md +0 -79
  67. package/docs/spec/09-cloud.md +0 -68
  68. package/docs/spec/10-cli.md +0 -181
  69. package/docs/spec/11-standards.md +0 -52
  70. package/docs/spec/12-dogfooding.md +0 -51
  71. package/docs/spec/13-open-questions.md +0 -97
  72. package/docs/spec/14-telemetry.md +0 -199
  73. package/docs/spec/README.md +0 -33
  74. package/harness/dev.harnesspm/rules/generated-files.md +0 -9
  75. package/harness/dev.harnesspm/rules/harnesspm-config.md +0 -12
  76. package/harness/plugin.json +0 -13
  77. package/harness/skills/harnesspm-export/SKILL.md +0 -43
  78. package/harness/skills/harnesspm-import/SKILL.md +0 -40
  79. package/harness/skills/harnesspm-improve/SKILL.md +0 -38
  80. package/schema/harnesspm.schema.json +0 -58
package/dist/added.js DELETED
@@ -1,192 +0,0 @@
1
- // Added harnesses: sources, scopes and project entries (spec chapter 7).
2
- import { spawnSync } from 'node:child_process';
3
- import * as fs from 'node:fs';
4
- import * as os from 'node:os';
5
- import * as path from 'node:path';
6
- import { harnesspmHome } from './homes.js';
7
- import { loadHarnessPackage, NS, parseExtension } from './manifest.js';
8
- import { HarnessError, NPX_ANY, ensureDir, isDir, isFile, isRecord, normalizeRemote, readJson, readJsonIfExists, remoteKey } from './util.js';
9
- export const LOCAL_FILE = 'harnesspm.local.json';
10
- export function userConfigFile() {
11
- return path.join(harnesspmHome(), 'config.json');
12
- }
13
- export function configFileFor(scope, projectDir) {
14
- return scope === 'user' ? userConfigFile() : path.join(projectDir, LOCAL_FILE);
15
- }
16
- export function readList(file) {
17
- const raw = readJsonIfExists(file);
18
- if (raw === undefined)
19
- return [];
20
- if (!isRecord(raw) || (raw['harnesses'] !== undefined && !Array.isArray(raw['harnesses']))) {
21
- throw new HarnessError(`${file}: "harnesses" must be an array of sources`);
22
- }
23
- return (raw['harnesses'] ?? []).filter((s) => typeof s === 'string');
24
- }
25
- export function writeList(file, list) {
26
- const raw = readJsonIfExists(file);
27
- const data = isRecord(raw) ? raw : {};
28
- data['harnesses'] = list;
29
- ensureDir(path.dirname(file));
30
- fs.writeFileSync(file, `${JSON.stringify(data, null, 2)}\n`);
31
- }
32
- function expandHome(p) {
33
- return p === '~' || p.startsWith('~/') ? path.join(os.homedir(), p.slice(1)) : p;
34
- }
35
- function slug(text) {
36
- return text.replace(/^@/, '').replace(/[^A-Za-z0-9._-]+/g, '-');
37
- }
38
- export function parseSource(spec, cwd = process.cwd()) {
39
- if (spec.startsWith('github:')) {
40
- const repo = spec.slice('github:'.length).replace(/\.git$/, '');
41
- if (!/^[\w.-]+\/[\w.-]+$/.test(repo))
42
- throw new HarnessError(`Use github:<owner>/<repo>, not ${spec}`);
43
- return { spec, kind: 'git', location: `https://github.com/${repo}.git`, dir: path.join(harnesspmHome(), 'harnesses', slug(repo)), editable: true };
44
- }
45
- if (spec.startsWith('git:')) {
46
- const url = spec.slice('git:'.length);
47
- const parts = url.replace(/\.git$/, '').split(/[/:]/).filter(Boolean).slice(-2);
48
- return { spec, kind: 'git', location: url, dir: path.join(harnesspmHome(), 'harnesses', slug(parts.join('/'))), editable: true };
49
- }
50
- if (spec.startsWith('npm:')) {
51
- const name = spec.slice('npm:'.length);
52
- return { spec, kind: 'npm', location: name, dir: path.join(harnesspmHome(), 'cache', slug(name.replace(/@[^@/]*$/, '')), 'package'), editable: false };
53
- }
54
- const dir = path.resolve(cwd, expandHome(spec));
55
- return { spec: dir, kind: 'folder', location: dir, dir, editable: true };
56
- }
57
- /** How long a fetch may take when nobody can answer a prompt, as in the `SessionStart` hook (spec 7.5). */
58
- export const QUIET_FETCH_SECONDS = 30;
59
- /**
60
- * `quiet` is for runs where nobody can answer a prompt: git never asks for credentials, and a command that takes longer
61
- * than `QUIET_FETCH_SECONDS` is stopped, so a session never waits on the network.
62
- */
63
- function run(cmd, args, cwd, quiet = false) {
64
- const options = quiet ? { timeout: QUIET_FETCH_SECONDS * 1000, env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GCM_INTERACTIVE: 'never' } } : {};
65
- const result = spawnSync(cmd, args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], ...options });
66
- if (result.error?.code === 'ETIMEDOUT')
67
- return { ok: false, out: `no answer in ${QUIET_FETCH_SECONDS} s` };
68
- return { ok: result.status === 0, out: `${result.stdout ?? ''}${result.stderr ?? ''}`.trim() };
69
- }
70
- /** Puts the source on this machine. Returns a note for the person. */
71
- export function fetchSource(source, quiet = false) {
72
- if (source.kind === 'folder') {
73
- if (!isDir(source.dir))
74
- throw new HarnessError(`Folder not found: ${source.dir}`);
75
- return undefined;
76
- }
77
- if (source.kind === 'git') {
78
- if (isDir(path.join(source.dir, '.git')))
79
- return undefined;
80
- ensureDir(path.dirname(source.dir));
81
- const existed = fs.existsSync(source.dir);
82
- const result = run('git', ['clone', '--quiet', source.location, source.dir], undefined, quiet);
83
- if (!result.ok) {
84
- // A clone stopped half-way leaves a folder that the next update would take for a working copy.
85
- if (!existed)
86
- fs.rmSync(source.dir, { recursive: true, force: true });
87
- throw new HarnessError(`git clone ${source.location} failed: ${result.out}`);
88
- }
89
- return `cloned ${source.location} into ${source.dir}`;
90
- }
91
- return fetchNpm(source, quiet);
92
- }
93
- function fetchNpm(source, quiet = false) {
94
- const cache = path.dirname(source.dir);
95
- const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'harnesspm-npm-'));
96
- const packed = run('npm', ['pack', source.location, '--silent', '--pack-destination', tmp], undefined, quiet);
97
- if (!packed.ok)
98
- throw new HarnessError(`npm pack ${source.location} failed: ${packed.out}`);
99
- const tarball = path.join(tmp, packed.out.split('\n').pop().trim());
100
- fs.rmSync(cache, { recursive: true, force: true });
101
- ensureDir(cache);
102
- const extracted = run('tar', ['-xzf', tarball, '-C', cache]);
103
- fs.rmSync(tmp, { recursive: true, force: true });
104
- if (!extracted.ok)
105
- throw new HarnessError(`Cannot unpack ${source.location}: ${extracted.out}`);
106
- return `fetched ${source.location} into ${cache}`;
107
- }
108
- /**
109
- * Brings a source up to date and says what changed. Never changes a working copy with local work (spec 8.7). A pull
110
- * that fails keeps the working copy as it is. A clone or npm fetch that fails throws.
111
- */
112
- export function updateSource(source, options = {}) {
113
- const quiet = options.quiet === true;
114
- if (source.kind === 'folder')
115
- return `${source.spec}: a folder, used as it is`;
116
- if (source.kind === 'npm')
117
- return fetchNpm(source, quiet);
118
- if (!isDir(path.join(source.dir, '.git'))) {
119
- fetchSource(source, quiet);
120
- return `${source.spec}: cloned`;
121
- }
122
- const dirty = run('git', ['status', '--porcelain'], source.dir);
123
- if (dirty.out !== '')
124
- return `${source.spec}: skipped, the working copy has uncommitted changes`;
125
- const ahead = run('git', ['rev-list', '--count', '@{upstream}..HEAD'], source.dir);
126
- if (ahead.ok && ahead.out !== '0')
127
- return `${source.spec}: skipped, the working copy has ${ahead.out} unpushed commits`;
128
- const head = () => run('git', ['rev-parse', '--short', 'HEAD'], source.dir).out;
129
- const before = head();
130
- const pulled = run('git', ['pull', '--quiet', '--ff-only'], source.dir, quiet);
131
- if (!pulled.ok)
132
- return `${source.spec}: pull failed, kept ${before}: ${pulled.out}`;
133
- const after = head();
134
- return before === after ? `${source.spec}: already up to date at ${after}` : `${source.spec}: updated ${before} → ${after}`;
135
- }
136
- // The remote key lives in util.ts, so telemetry can use it without loading this module.
137
- export { normalizeRemote, remoteKey };
138
- function loadEntry(pkg, key) {
139
- if (key === undefined)
140
- return undefined;
141
- const rel = pkg.ext.projects[key];
142
- return rel === undefined ? undefined : entryPackage(pkg, path.resolve(pkg.harnessDir, rel), key);
143
- }
144
- /** A harness's project entries, one per folder, with the remotes that map to it (spec 7.2). */
145
- export function entryFolders(pkg) {
146
- const folders = new Map();
147
- for (const [remote, rel] of Object.entries(pkg.ext.projects)) {
148
- const dir = path.resolve(pkg.harnessDir, rel);
149
- folders.set(dir, [...(folders.get(dir) ?? []), remote]);
150
- }
151
- return [...folders].map(([dir, remotes]) => ({ dir, remotes }));
152
- }
153
- /** The entry in `dir` as a package with the harness's plugin name, or undefined when the folder does not exist. */
154
- export function entryPackage(pkg, dir, key) {
155
- if (!isDir(dir))
156
- return undefined;
157
- // An entry has the layout of harness/. Its optional plugin.json uses the harness's name and holds overrides.
158
- const manifest = path.join(dir, 'plugin.json');
159
- const raw = isFile(manifest) ? readJson(manifest) : {};
160
- const data = isRecord(raw) ? raw : {};
161
- if (data['name'] !== undefined && data['name'] !== pkg.plugin) {
162
- throw new HarnessError(`${manifest}: "name" must be "${pkg.plugin}", the name of its harness`);
163
- }
164
- const problems = [];
165
- const ext = parseExtension(data, problems);
166
- return { ...pkg, name: `${pkg.name} (entry ${key})`, dir, harnessDir: dir, ext: { ...ext, projects: {} }, problems };
167
- }
168
- /** Added harnesses in order: user scope first, then local scope, each as listed. */
169
- export function loadAdded(projectDir, warnings) {
170
- const result = [];
171
- const key = projectDir !== undefined ? remoteKey(projectDir) : undefined;
172
- const scopes = projectDir !== undefined ? ['user', 'local'] : ['user'];
173
- for (const scope of scopes) {
174
- for (const spec of readList(configFileFor(scope, projectDir ?? ''))) {
175
- const source = parseSource(spec);
176
- if (!isFile(path.join(source.dir, 'harness', 'plugin.json'))) {
177
- warnings.push(`${spec} is not on this machine yet. Run \`${NPX_ANY} update\`.`);
178
- continue;
179
- }
180
- const pkg = loadHarnessPackage(source.dir, 'added');
181
- if (pkg.name === path.basename(source.dir))
182
- pkg.name = spec;
183
- const entry = loadEntry(pkg, key);
184
- result.push({ source, scope, pkg, ...(entry ? { entry } : {}) });
185
- }
186
- }
187
- return result;
188
- }
189
- // Moved to light modules, so `harnesspm track` can load them without the rest (spec 14.4).
190
- export { harnesspmHome } from './homes.js';
191
- export { caller } from './util.js';
192
- export const RULES_DIR = path.join(NS, 'rules');
package/dist/check.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export interface CheckResult {
2
- errors: string[];
3
- warnings: string[];
4
- alwaysOnBytes: number;
5
- plugin: string;
6
- /** Each project entry folder once, with the remotes that map to it and its always-on size (spec 2.10). */
7
- entries: {
8
- dir: string;
9
- remotes: string[];
10
- alwaysOnBytes: number;
11
- }[];
12
- }
13
- /** `target` is a package root, or a harness/ folder, or an added harness folder. */
14
- export declare function checkHarness(target: string): CheckResult;
package/dist/check.js DELETED
@@ -1,263 +0,0 @@
1
- // harnesspm check: validate a harness before it is published (spec 2.10).
2
- import * as fs from 'node:fs';
3
- import * as path from 'node:path';
4
- import { parseFrontmatter, stringList } from './frontmatter.js';
5
- import { entryFolders, entryPackage } from './added.js';
6
- import { discoverExecUnits } from './exec-units.js';
7
- import { discoverUnits, loadHarnessPackage, NS, ruleMeta } from './manifest.js';
8
- import { gitKeeps, HarnessError, isDir, isFile, isInside, isRecord, readJsonIfExists, readText, relativeLinks, relPosix } from './util.js';
9
- const SECRET_PATTERNS = [
10
- // A key has a body: a header alone is an example or a placeholder. Encrypted PEM puts `Name: value` lines first.
11
- [/-----BEGIN [A-Z ]*PRIVATE KEY-----\s*(?:[\w-]+: [^\n]*\n\s*)*[A-Za-z0-9+/=]{40,}/, 'a private key'],
12
- [/\bgh[pousr]_[A-Za-z0-9]{30,}\b/, 'a GitHub token'],
13
- [/\bsk-[A-Za-z0-9_-]{20,}\b/, 'an API key'],
14
- [/\bAKIA[0-9A-Z]{16}\b/, 'an AWS access key'],
15
- [/\bxox[abprs]-[A-Za-z0-9-]{10,}\b/, 'a Slack token'],
16
- ];
17
- function walkFiles(dir) {
18
- const files = [];
19
- const walk = (current) => {
20
- for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
21
- const full = path.join(current, entry.name);
22
- if (entry.isDirectory())
23
- walk(full);
24
- else if (entry.isFile())
25
- files.push(full);
26
- }
27
- };
28
- if (isDir(dir))
29
- walk(dir);
30
- return files.sort();
31
- }
32
- /** A docs folder's files without the ones git ignores, as the lock and the index count them (spec 2.7). */
33
- function docsFiles(dir) {
34
- const keeps = gitKeeps(dir);
35
- return walkFiles(dir).filter((file) => keeps(relPosix(dir, file)));
36
- }
37
- /** A `files` pattern as a test of a path relative to the package root: the path itself, or a folder above it. */
38
- function filesPattern(pattern) {
39
- const clean = pattern.replace(/^\.?\//, '').replace(/\/+$/, '');
40
- if (clean === '' || /[[\]{}()+@]/.test(clean))
41
- return undefined;
42
- const source = clean
43
- .split('**')
44
- .map((part) => part.replace(/[.^$|\\]/g, '\\$&').replace(/\*/g, '[^/]*').replace(/\?/g, '[^/]'))
45
- .join('.*')
46
- .replace(/\.\*\//g, '(?:.*/)?');
47
- const re = new RegExp(`^${source}(?:/.*)?$`);
48
- return (rel) => re.test(rel);
49
- }
50
- /**
51
- * Whether npm packs a path, read from `files` in package.json as npm reads it (spec 2.10): a listed path, a folder
52
- * and what is in it, or a glob, less `!` entries, plus the files npm always packs. npm packs by `files`, not by
53
- * `.gitignore`, so docs built at `prepack` ship. `undefined` without `files`, or with a pattern this doesn't read,
54
- * such as braces: then `check` asks git, as the index does. It never runs npm, whose `pack --dry-run` runs the
55
- * package's `prepare` even with `--ignore-scripts`.
56
- */
57
- function packs(root) {
58
- const pkg = readJsonIfExists(path.join(root, 'package.json'));
59
- if (!isRecord(pkg) || !Array.isArray(pkg['files']))
60
- return undefined;
61
- const include = [];
62
- const exclude = [];
63
- for (const entry of pkg['files']) {
64
- if (typeof entry !== 'string')
65
- return undefined;
66
- const test = filesPattern(entry.replace(/^!/, ''));
67
- if (!test)
68
- return undefined;
69
- (entry.startsWith('!') ? exclude : include).push(test);
70
- }
71
- const named = [pkg['main'], ...(typeof pkg['bin'] === 'string' ? [pkg['bin']] : isRecord(pkg['bin']) ? Object.values(pkg['bin']) : [])]
72
- .filter((file) => typeof file === 'string')
73
- .map((file) => file.replace(/^\.\//, ''));
74
- const always = (rel) => /^(package\.json|(readme|licen[cs]e)(\..*)?)$/i.test(rel) || named.includes(rel);
75
- return (rel) => always(rel) || (include.some((test) => test(rel)) && !exclude.some((test) => test(rel)));
76
- }
77
- /** A skill's `name` is its folder's name. A replacement takes the name of the skill it replaces, as agents see it there. */
78
- function checkSkill(dir, name, why, errors, show) {
79
- const file = path.join(dir, 'SKILL.md');
80
- try {
81
- const { data, hasFrontmatter } = parseFrontmatter(readText(file), file);
82
- if (!hasFrontmatter)
83
- errors.push(`${show(file)}: needs frontmatter with "name" and "description"`);
84
- if (data['name'] !== name)
85
- errors.push(`${show(file)}: "name" must be "${name}", ${why}`);
86
- if (typeof data['description'] !== 'string' || data['description'].trim() === '')
87
- errors.push(`${show(file)}: needs a "description"`);
88
- }
89
- catch (error) {
90
- errors.push(error.message);
91
- }
92
- }
93
- /** Checks the rules and skills of a harness or of one of its project entries. Returns them and the always-on size. */
94
- function checkUnits(pkg, errors, warnings, show) {
95
- const overrideFiles = new Set([...Object.values(pkg.ext.replace), ...Object.values(pkg.ext.patch)].map((f) => path.resolve(pkg.harnessDir, f)));
96
- const units = discoverUnits(pkg, overrideFiles);
97
- let alwaysOnBytes = 0;
98
- for (const rule of units.rules) {
99
- try {
100
- const text = readText(rule.file);
101
- const meta = ruleMeta(text, rule.name, rule.file);
102
- const { data } = parseFrontmatter(text, rule.file);
103
- if (data['paths'] !== undefined && !stringList(data['paths']))
104
- errors.push(`${show(rule.file)}: "paths" must be a string or a list of strings`);
105
- if (data['description'] !== undefined && typeof data['description'] !== 'string')
106
- errors.push(`${show(rule.file)}: "description" must be a string`);
107
- if (meta.activation === 'always')
108
- alwaysOnBytes += Buffer.byteLength(meta.body);
109
- }
110
- catch (error) {
111
- errors.push(error.message);
112
- }
113
- }
114
- for (const skill of units.skills) {
115
- checkSkill(skill.dir, skill.name, 'the folder name', errors, show);
116
- if (!skill.name.startsWith(`${pkg.plugin}-`) && skill.name !== pkg.plugin) {
117
- warnings.push(`skill "${skill.name}" should start with the plugin name, such as "${pkg.plugin}-${skill.name}"`);
118
- }
119
- }
120
- return { units, alwaysOnBytes };
121
- }
122
- /** `target` is a package root, or a harness/ folder, or an added harness folder. */
123
- export function checkHarness(target) {
124
- let root = path.resolve(target);
125
- if (path.basename(root) === 'harness' && isFile(path.join(root, 'plugin.json')))
126
- root = path.dirname(root);
127
- const pkg = loadHarnessPackage(root, 'project');
128
- if (!pkg)
129
- throw new HarnessError(`No harness found: ${relPosix(process.cwd(), path.join(root, 'harness', 'plugin.json'))} does not exist`);
130
- const errors = [...pkg.problems];
131
- const warnings = [];
132
- const show = (file) => relPosix(root, file);
133
- const pkgJson = readJsonIfExists(path.join(root, 'package.json'));
134
- if (isRecord(pkgJson) && Array.isArray(pkgJson['files'])) {
135
- const files = pkgJson['files'].filter((f) => typeof f === 'string').map((f) => f.replace(/^\.\//, '').replace(/\/$/, ''));
136
- if (!files.includes('harness'))
137
- errors.push('package.json: "files" must include "harness"');
138
- if (pkg.ext.docs !== undefined) {
139
- const docsRel = relPosix(root, path.resolve(pkg.harnessDir, pkg.ext.docs));
140
- // The folder itself, a parent of it, or entries inside it, such as `docs/components` or `docs/*.md`.
141
- const covers = (f) => docsRel === f || docsRel.startsWith(`${f}/`) || f.startsWith(`${docsRel}/`);
142
- if (!files.some(covers))
143
- errors.push(`package.json: "files" must include the docs folder "${docsRel}", or entries inside it`);
144
- }
145
- }
146
- const checkPath = (label, rel, mustExist) => {
147
- const full = path.resolve(pkg.harnessDir, rel);
148
- if (!isInside(root, full))
149
- errors.push(`${label}: ${rel} points outside the package`);
150
- else if (mustExist === 'file' ? !isFile(full) : !isDir(full))
151
- errors.push(`${label}: ${rel} does not exist`);
152
- };
153
- // A replacement has the shape of the unit it replaces: a rule's file, or a skill's folder (spec 3.4).
154
- const replacedSkills = [];
155
- for (const [id, file] of Object.entries(pkg.ext.replace)) {
156
- const skill = /:skills\/(.+)$/.exec(id)?.[1];
157
- if (skill !== undefined) {
158
- checkPath(`replace ${id}`, file, 'dir');
159
- const dir = path.resolve(pkg.harnessDir, file);
160
- if (isDir(dir) && isInside(root, dir))
161
- replacedSkills.push({ dir, name: skill });
162
- }
163
- else {
164
- checkPath(`replace ${id}`, file, 'file');
165
- if (!id.includes(':rules/'))
166
- errors.push(`replace ${id}: replace works on rules and skills only. Exclude the unit and add one of your own instead.`);
167
- }
168
- }
169
- for (const [id, file] of Object.entries(pkg.ext.patch)) {
170
- checkPath(`patch ${id}`, file, 'file');
171
- if (!id.includes(':rules/'))
172
- errors.push(`patch ${id}: patches work on rules only`);
173
- }
174
- if (pkg.ext.docs !== undefined)
175
- checkPath('docs', pkg.ext.docs, 'dir');
176
- for (const [name, def] of Object.entries(pkg.ext.scripts)) {
177
- if (!def.file.startsWith('./'))
178
- errors.push(`script ${name}: "file" must start with "./"`);
179
- checkPath(`script ${name}`, def.file, 'file');
180
- }
181
- for (const [remote, dir] of Object.entries(pkg.ext.projects))
182
- checkPath(`project entry ${remote}`, dir, 'dir');
183
- const { units, alwaysOnBytes } = checkUnits(pkg, errors, warnings, show);
184
- for (const skill of replacedSkills) {
185
- if (isFile(path.join(skill.dir, 'SKILL.md')))
186
- checkSkill(skill.dir, skill.name, 'the name of the skill it replaces', errors, show);
187
- else
188
- errors.push(`replace: ${show(skill.dir)} needs a SKILL.md`);
189
- }
190
- // Project entries, each folder once, though several remotes may map to it. `sync` loads an entry as this does.
191
- const entries = [];
192
- for (const { dir, remotes } of entryFolders(pkg)) {
193
- if (!isInside(root, dir) || !isDir(dir))
194
- continue;
195
- try {
196
- const entry = entryPackage(pkg, dir, remotes[0]);
197
- for (const problem of entry.problems)
198
- errors.push(`${show(path.join(dir, 'plugin.json'))}: ${problem}`);
199
- entries.push({ dir: show(dir), remotes, alwaysOnBytes: checkUnits(entry, errors, warnings, show).alwaysOnBytes });
200
- }
201
- catch (error) {
202
- errors.push(error.message);
203
- }
204
- }
205
- // Judge the docs and links by what ships (spec 2.10). Without `files` to read, by the files git keeps.
206
- const packed = packs(root);
207
- const ships = (file) => (packed === undefined ? fs.existsSync(file) : packed(relPosix(root, file)));
208
- // Docs pages in a generated index (spec 2.7): the index takes their title and description from the frontmatter.
209
- const docs = units.docs ? (packed === undefined ? docsFiles(units.docs.dir) : walkFiles(units.docs.dir).filter(ships)) : [];
210
- if (units.docs && !(isFile(path.join(units.docs.dir, 'llms.txt')) && ships(path.join(units.docs.dir, 'llms.txt')))) {
211
- for (const file of docs) {
212
- if (!/\.mdx?$/.test(file))
213
- continue;
214
- try {
215
- parseFrontmatter(readText(file), show(file));
216
- }
217
- catch (error) {
218
- errors.push(error.message);
219
- }
220
- }
221
- }
222
- let jsonOk = true;
223
- for (const json of ['mcp.json', path.join(NS, 'hooks.json'), path.join(NS, 'permissions.json')]) {
224
- const file = path.join(pkg.harnessDir, json);
225
- if (isFile(file)) {
226
- try {
227
- JSON.parse(readText(file));
228
- }
229
- catch (error) {
230
- jsonOk = false;
231
- errors.push(`${show(file)}: ${error.message}`);
232
- }
233
- }
234
- }
235
- if (jsonOk) {
236
- try {
237
- discoverExecUnits(pkg, errors);
238
- }
239
- catch (error) {
240
- errors.push(error.message);
241
- }
242
- }
243
- // Links in Markdown and secrets in any file.
244
- const scanned = [...walkFiles(pkg.harnessDir), ...docs];
245
- for (const file of [...new Set(scanned)]) {
246
- const text = fs.readFileSync(file, 'utf8');
247
- for (const [pattern, what] of SECRET_PATTERNS)
248
- if (pattern.test(text))
249
- warnings.push(`${show(file)} looks like it contains ${what}`);
250
- if (!/\.mdx?$/.test(file))
251
- continue;
252
- for (const { link } of relativeLinks(text)) {
253
- const target = path.resolve(path.dirname(file), decodeURI(link));
254
- if (!isInside(root, target))
255
- errors.push(`${show(file)}: the link ${link} points outside the package`);
256
- else if (!fs.existsSync(target))
257
- errors.push(`${show(file)}: the link ${link} points at a missing file`);
258
- else if (isFile(target) && !ships(target))
259
- errors.push(`${show(file)}: the link ${link} points at a file the package does not ship`);
260
- }
261
- }
262
- return { errors, warnings, alwaysOnBytes, plugin: pkg.plugin, entries };
263
- }
package/dist/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};