@harnesspm/cli 0.0.0-stage → 0.17.0
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/CHANGELOG.md +269 -0
- package/LICENSE +21 -0
- package/README.md +69 -2
- package/dist/added.d.ts +51 -0
- package/dist/added.js +192 -0
- package/dist/check.d.ts +14 -0
- package/dist/check.js +263 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +218 -0
- package/dist/commands.d.ts +58 -0
- package/dist/commands.js +1299 -0
- package/dist/config.d.ts +15 -0
- package/dist/config.js +45 -0
- package/dist/deliver.d.ts +1 -0
- package/dist/deliver.js +31 -0
- package/dist/doctor.d.ts +18 -0
- package/dist/doctor.js +99 -0
- package/dist/exec-outputs.d.ts +75 -0
- package/dist/exec-outputs.js +425 -0
- package/dist/exec-units.d.ts +68 -0
- package/dist/exec-units.js +151 -0
- package/dist/fetch.d.ts +16 -0
- package/dist/fetch.js +145 -0
- package/dist/frontmatter.d.ts +16 -0
- package/dist/frontmatter.js +49 -0
- package/dist/homes.d.ts +7 -0
- package/dist/homes.js +21 -0
- package/dist/lock.d.ts +47 -0
- package/dist/lock.js +245 -0
- package/dist/manifest.d.ts +78 -0
- package/dist/manifest.js +169 -0
- package/dist/new.d.ts +33 -0
- package/dist/new.js +228 -0
- package/dist/outputs.d.ts +124 -0
- package/dist/outputs.js +875 -0
- package/dist/parent.d.ts +41 -0
- package/dist/parent.js +182 -0
- package/dist/render.d.ts +91 -0
- package/dist/render.js +221 -0
- package/dist/resolve.d.ts +132 -0
- package/dist/resolve.js +522 -0
- package/dist/reviewed.d.ts +15 -0
- package/dist/reviewed.js +41 -0
- package/dist/run.d.ts +18 -0
- package/dist/run.js +133 -0
- package/dist/sections.d.ts +32 -0
- package/dist/sections.js +121 -0
- package/dist/telemetry-api.d.ts +26 -0
- package/dist/telemetry-api.js +60 -0
- package/dist/telemetry.d.ts +119 -0
- package/dist/telemetry.js +401 -0
- package/dist/user-outputs.d.ts +30 -0
- package/dist/user-outputs.js +239 -0
- package/dist/util.d.ts +137 -0
- package/dist/util.js +370 -0
- package/dist/workspaces.d.ts +2 -0
- package/dist/workspaces.js +62 -0
- package/docs/spec/01-overview.md +149 -0
- package/docs/spec/02-package-format.md +252 -0
- package/docs/spec/03-resolution.md +108 -0
- package/docs/spec/04-outputs.md +194 -0
- package/docs/spec/05-executables.md +170 -0
- package/docs/spec/06-trust.md +88 -0
- package/docs/spec/07-added.md +109 -0
- package/docs/spec/08-improving.md +79 -0
- package/docs/spec/09-cloud.md +68 -0
- package/docs/spec/10-cli.md +187 -0
- package/docs/spec/11-standards.md +52 -0
- package/docs/spec/12-dogfooding.md +51 -0
- package/docs/spec/13-open-questions.md +97 -0
- package/docs/spec/14-telemetry.md +199 -0
- package/docs/spec/README.md +33 -0
- package/harness/dev.harnesspm/rules/generated-files.md +9 -0
- package/harness/dev.harnesspm/rules/harnesspm-config.md +12 -0
- package/harness/plugin.json +13 -0
- package/harness/skills/harnesspm-export/SKILL.md +43 -0
- package/harness/skills/harnesspm-import/SKILL.md +40 -0
- package/harness/skills/harnesspm-improve/SKILL.md +38 -0
- package/package.json +71 -4
- package/schema/harnesspm.schema.json +58 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { HarnessError, isDir, readJson } from './util.js';
|
|
4
|
+
async function main() {
|
|
5
|
+
const commands = await import('./commands.js');
|
|
6
|
+
const { Refused } = await import('./run.js');
|
|
7
|
+
try {
|
|
8
|
+
process.exitCode = await dispatch(process.argv.slice(2), commands);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof HarnessError) {
|
|
12
|
+
console.error(`harnesspm: ${error.message}`);
|
|
13
|
+
process.exitCode = error instanceof Refused ? 2 : 1;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
throw error;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const HELP = `harnesspm — the harness package manager
|
|
21
|
+
|
|
22
|
+
Usage: harnesspm [-C <dir>] <command>
|
|
23
|
+
-C <dir> act on the project in <dir>, such as a repository you cloned. \`run\` keeps
|
|
24
|
+
the current folder for the script, so file arguments stay valid
|
|
25
|
+
harnesspm help these commands, and the project's packages, one line each
|
|
26
|
+
harnesspm help <package | rule ID | tool>
|
|
27
|
+
a package's rules, docs, tools, MCP servers, skills and hooks in full,
|
|
28
|
+
one rule, or a tool's usage and run command. Needs no install
|
|
29
|
+
|
|
30
|
+
Projects
|
|
31
|
+
harnesspm init set up harnesspm in this project
|
|
32
|
+
harnesspm sync [--check | --write]
|
|
33
|
+
write the agent files (--check: compare only, for CI;
|
|
34
|
+
--write: committed files too when CI=true)
|
|
35
|
+
harnesspm status layers, packages and always-on size
|
|
36
|
+
harnesspm doctor check that local files stay out of git and the outputs are in place
|
|
37
|
+
harnesspm why <ID> where a unit comes from and how to change it
|
|
38
|
+
harnesspm run <plugin>:<script> [-- args]
|
|
39
|
+
run a script of a trusted package
|
|
40
|
+
harnesspm approve [<package>] approve a "pin" package's new version, and write what an agent could not
|
|
41
|
+
harnesspm fetch download the harness packages in the lock, for jobs without an install
|
|
42
|
+
|
|
43
|
+
Harnesses on top of the repository's (your team's, your own)
|
|
44
|
+
harnesspm add <source> [--local] [--no-hook]
|
|
45
|
+
add a harness: github:<owner>/<repo>, git:<url>, npm:<name> or a folder
|
|
46
|
+
harnesspm remove <source> [--local]
|
|
47
|
+
harnesspm update fetch new versions of added harnesses
|
|
48
|
+
|
|
49
|
+
Authors
|
|
50
|
+
harnesspm check [<folder>] validate a harness before publishing
|
|
51
|
+
harnesspm new <kind> <name> [--to <plugin>] [--entry]
|
|
52
|
+
a rule, skill, agent, script, hook or mcp from a template
|
|
53
|
+
harnesspm new patch <rule ID> [--to <plugin>] [--entry]
|
|
54
|
+
a patch that changes some sections of a rule
|
|
55
|
+
`;
|
|
56
|
+
/** Details for a command whose usage line is not enough. */
|
|
57
|
+
const DETAILS = {
|
|
58
|
+
new: `Kinds: rule, skill, agent, script, hook, mcp. \`new patch\` takes a rule ID, such as acme-ui:rules/usage.
|
|
59
|
+
--to <plugin> write into a harness you added (\`harnesspm status\` lists them), not the project's own harness/
|
|
60
|
+
--entry with --to: write into that harness's entry for this repository`,
|
|
61
|
+
};
|
|
62
|
+
/** Help for one command: its lines in HELP and its details. Undefined for a word that is not a command. */
|
|
63
|
+
function commandHelp(command) {
|
|
64
|
+
const picked = [];
|
|
65
|
+
let inside = false;
|
|
66
|
+
for (const line of HELP.split('\n')) {
|
|
67
|
+
if (line === ` harnesspm ${command}` || line.startsWith(` harnesspm ${command} `)) {
|
|
68
|
+
inside = true;
|
|
69
|
+
picked.push(line);
|
|
70
|
+
}
|
|
71
|
+
else if (inside && /^ {3,}\S/.test(line))
|
|
72
|
+
picked.push(line);
|
|
73
|
+
else
|
|
74
|
+
inside = false;
|
|
75
|
+
}
|
|
76
|
+
if (picked.length === 0)
|
|
77
|
+
return undefined;
|
|
78
|
+
const details = DETAILS[command];
|
|
79
|
+
return [...picked, ...(details !== undefined ? ['', details] : []), '', 'Every command: harnesspm help. Every option: https://harnesspm.tenphi.me/reference/cli/'].join('\n');
|
|
80
|
+
}
|
|
81
|
+
const out = {
|
|
82
|
+
log: (line) => console.log(line),
|
|
83
|
+
warn: (line) => console.error(line),
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* `-C <dir>` before the command: harnesspm acts as if it started in <dir>, as `git -C` does (spec 10.1). Returns the
|
|
87
|
+
* folder and the arguments after it.
|
|
88
|
+
*/
|
|
89
|
+
function projectFolder(argv) {
|
|
90
|
+
if (argv[0] !== '-C')
|
|
91
|
+
return { cwd: process.cwd(), named: false, argv };
|
|
92
|
+
const dir = argv[1];
|
|
93
|
+
if (dir === undefined || dir === '')
|
|
94
|
+
throw new HarnessError('Usage: harnesspm -C <dir> <command>');
|
|
95
|
+
const cwd = path.resolve(dir);
|
|
96
|
+
if (!isDir(cwd))
|
|
97
|
+
throw new HarnessError(`-C ${dir}: no such folder`);
|
|
98
|
+
return { cwd, named: true, argv: argv.slice(2) };
|
|
99
|
+
}
|
|
100
|
+
function dispatch(argvIn, { add, approve, check, doctor, fetch, init, mcp, newUnit, projectHelp, remove, run, status, sync, targetHelp, update, why }) {
|
|
101
|
+
const { cwd, named, argv } = projectFolder(argvIn);
|
|
102
|
+
const [command, ...rest] = argv;
|
|
103
|
+
const isHelp = (arg) => arg === '--help' || arg === '-h';
|
|
104
|
+
// After `run <plugin>:<script>`, every argument goes to the script, `--help` too. Only a first `--help` is harnesspm's.
|
|
105
|
+
if (command !== undefined && (command === 'run' || command === 'mcp' ? isHelp(rest[0]) : rest.some(isHelp))) {
|
|
106
|
+
console.log(commandHelp(command) ?? HELP);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
if (command === 'run' || command === 'mcp') {
|
|
110
|
+
// Everything after the script name goes to the script, untouched.
|
|
111
|
+
let agent;
|
|
112
|
+
let i = 0;
|
|
113
|
+
if (rest[0] === '--agent') {
|
|
114
|
+
agent = rest[1];
|
|
115
|
+
i = 2;
|
|
116
|
+
}
|
|
117
|
+
const ref = rest[i];
|
|
118
|
+
if (ref === undefined)
|
|
119
|
+
throw new HarnessError(`Usage: harnesspm ${command} [--agent <claude|codex>] <plugin>:<name>${command === 'run' ? ' [-- args]' : ''}`);
|
|
120
|
+
const args = rest.slice(i + 1);
|
|
121
|
+
if (args[0] === '--')
|
|
122
|
+
args.shift();
|
|
123
|
+
return command === 'run' ? run(cwd, ref, args, agent) : mcp(cwd, ref, agent);
|
|
124
|
+
}
|
|
125
|
+
const flags = new Set(rest.filter((a) => a.startsWith('--')));
|
|
126
|
+
const args = rest.filter((a) => !a.startsWith('--'));
|
|
127
|
+
const unknown = (allowed) => {
|
|
128
|
+
for (const flag of flags)
|
|
129
|
+
if (!allowed.includes(flag))
|
|
130
|
+
throw new HarnessError(`Unknown option ${flag} for ${command}`);
|
|
131
|
+
};
|
|
132
|
+
switch (command) {
|
|
133
|
+
case 'init':
|
|
134
|
+
unknown([]);
|
|
135
|
+
return init(cwd, out);
|
|
136
|
+
case 'sync':
|
|
137
|
+
unknown(['--check', '--write']);
|
|
138
|
+
return sync(cwd, out, { check: flags.has('--check'), write: flags.has('--write') });
|
|
139
|
+
case 'status':
|
|
140
|
+
unknown([]);
|
|
141
|
+
return status(cwd, out);
|
|
142
|
+
case 'doctor':
|
|
143
|
+
unknown([]);
|
|
144
|
+
return doctor(cwd, out);
|
|
145
|
+
case 'why':
|
|
146
|
+
unknown([]);
|
|
147
|
+
if (args[0] === undefined)
|
|
148
|
+
throw new HarnessError('Usage: harnesspm why <ID>');
|
|
149
|
+
return why(cwd, args[0], out);
|
|
150
|
+
case 'add':
|
|
151
|
+
case 'remove': {
|
|
152
|
+
unknown(command === 'add' ? ['--local', '--no-hook'] : ['--local']);
|
|
153
|
+
if (args[0] === undefined)
|
|
154
|
+
throw new HarnessError(`Usage: harnesspm ${command} <source>${command === 'add' ? ' [--local] [--no-hook]' : ' [--local]'}`);
|
|
155
|
+
if (command === 'add')
|
|
156
|
+
return add(cwd, args[0], out, { local: flags.has('--local'), hook: !flags.has('--no-hook') });
|
|
157
|
+
return remove(cwd, args[0], out, { local: flags.has('--local') });
|
|
158
|
+
}
|
|
159
|
+
case 'update':
|
|
160
|
+
unknown([]);
|
|
161
|
+
return update(cwd, out);
|
|
162
|
+
case 'new': {
|
|
163
|
+
const flagArgs = rest.filter((a, i) => a === '--to' || rest[i - 1] === '--to' || a === '--entry');
|
|
164
|
+
const positional = rest.filter((a) => !flagArgs.includes(a) && !a.startsWith('--'));
|
|
165
|
+
const toIndex = rest.indexOf('--to');
|
|
166
|
+
const to = toIndex >= 0 ? rest[toIndex + 1] : undefined;
|
|
167
|
+
for (const a of rest)
|
|
168
|
+
if (a.startsWith('--') && a !== '--to' && a !== '--entry')
|
|
169
|
+
throw new HarnessError(`Unknown option ${a} for new`);
|
|
170
|
+
if (positional.length !== 2)
|
|
171
|
+
throw new HarnessError('Usage: harnesspm new <kind> <name> [--to <plugin>] [--entry], or harnesspm new patch <rule ID>');
|
|
172
|
+
return newUnit(cwd, positional[0], positional[1], { ...(to !== undefined ? { to } : {}), entry: rest.includes('--entry') }, out);
|
|
173
|
+
}
|
|
174
|
+
case 'fetch':
|
|
175
|
+
unknown([]);
|
|
176
|
+
return fetch(cwd, out);
|
|
177
|
+
case 'approve':
|
|
178
|
+
unknown([]);
|
|
179
|
+
return approve(cwd, args[0], out);
|
|
180
|
+
case 'check':
|
|
181
|
+
unknown([]);
|
|
182
|
+
return check(args[0] ?? cwd, out);
|
|
183
|
+
case '--version':
|
|
184
|
+
case '-v': {
|
|
185
|
+
const pkg = readJson(new URL('../package.json', import.meta.url).pathname);
|
|
186
|
+
console.log(pkg.version);
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
case 'help':
|
|
190
|
+
case undefined:
|
|
191
|
+
case '--help':
|
|
192
|
+
case '-h':
|
|
193
|
+
if (command === 'help' && args[0] !== undefined) {
|
|
194
|
+
// A command first, then a package, rule or tool of the project (spec 10.1).
|
|
195
|
+
const text = commandHelp(args[0]);
|
|
196
|
+
if (text !== undefined) {
|
|
197
|
+
console.log(text);
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
200
|
+
return targetHelp(cwd, args[0], out);
|
|
201
|
+
}
|
|
202
|
+
console.log(HELP.trimEnd());
|
|
203
|
+
// Inside a project, or with -C, the project's own harness follows.
|
|
204
|
+
return projectHelp(cwd, out, named);
|
|
205
|
+
default:
|
|
206
|
+
throw new HarnessError(`Unknown command "${command}". Run \`harnesspm help\`.`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Agent hooks call `harnesspm track` on every matching tool call, so it loads only what it needs (spec 14.4). A hook in a
|
|
210
|
+
// folder above the project names the project with `-C <dir>` (spec 4.10).
|
|
211
|
+
const tracked = process.argv[2] === 'track' ? 3 : process.argv[2] === '-C' && process.argv[4] === 'track' ? 5 : 0;
|
|
212
|
+
if (tracked > 0) {
|
|
213
|
+
const { track } = await import('./telemetry.js');
|
|
214
|
+
process.exitCode = track(process.argv.slice(tracked), tracked === 5 ? path.resolve(process.argv[3]) : undefined);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
await main();
|
|
218
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export interface Output {
|
|
2
|
+
log(line: string): void;
|
|
3
|
+
warn(line: string): void;
|
|
4
|
+
}
|
|
5
|
+
/** The repository to work on: the nearest folder with harnesspm.json, else the git root, else `cwd`. */
|
|
6
|
+
export declare function findProjectDir(cwd: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* `check` compares and writes nothing. With `CI=true`, the committed outputs stay as they are unless `write` is set,
|
|
9
|
+
* so that an install's sync cannot hide a missed sync from a later `sync --check` (spec 6.4, 10.1).
|
|
10
|
+
*/
|
|
11
|
+
export declare function sync(cwd: string, out: Output, options?: {
|
|
12
|
+
check?: boolean;
|
|
13
|
+
write?: boolean;
|
|
14
|
+
quiet?: boolean;
|
|
15
|
+
}): number;
|
|
16
|
+
export declare function init(projectDir: string, out: Output): number;
|
|
17
|
+
export declare function add(cwd: string, spec: string, out: Output, options?: {
|
|
18
|
+
local?: boolean;
|
|
19
|
+
hook?: boolean;
|
|
20
|
+
}): number;
|
|
21
|
+
export declare function remove(cwd: string, spec: string, out: Output, options?: {
|
|
22
|
+
local?: boolean;
|
|
23
|
+
}): number;
|
|
24
|
+
/**
|
|
25
|
+
* Fetches the added harnesses, then syncs. The `SessionStart` hook runs it (spec 7.5), so a source that cannot be
|
|
26
|
+
* fetched never fails it: harnesspm warns and syncs what is on this machine. Without a person at a terminal, git never
|
|
27
|
+
* prompts and a slow fetch is stopped.
|
|
28
|
+
*/
|
|
29
|
+
export declare function update(cwd: string, out: Output): number;
|
|
30
|
+
export declare function status(cwd: string, out: Output): number;
|
|
31
|
+
/**
|
|
32
|
+
* `harnesspm doctor`: whether this repository is ready for harnesses, its own and a person's (spec 10.1).
|
|
33
|
+
* It changes nothing. Exits 1 when a check fails; warnings do not fail.
|
|
34
|
+
*/
|
|
35
|
+
export declare function doctor(cwd: string, out: Output): number;
|
|
36
|
+
export declare function why(cwd: string, id: string, out: Output): number;
|
|
37
|
+
/** The command that runs the project's tools from where harnesspm started: with `-C` from outside it (spec 10.1). */
|
|
38
|
+
export declare function toolCommand(projectDir: string): string;
|
|
39
|
+
export declare function run(cwd: string, ref: string, args: string[], agent: string | undefined): Promise<number>;
|
|
40
|
+
export declare function mcp(cwd: string, ref: string, agent: string | undefined): number;
|
|
41
|
+
/**
|
|
42
|
+
* The project's part of `help` (spec 10.1): one line per package, across workspaces, with what it covers and the
|
|
43
|
+
* `help <package>` command that prints the rest.
|
|
44
|
+
*/
|
|
45
|
+
export declare function projectHelp(cwd: string, out: Output, named: boolean): number;
|
|
46
|
+
/**
|
|
47
|
+
* `help <target>`: a package or plugin, a rule ID, or a tool by `<plugin>:<script>` or its ID (spec 10.1). It works
|
|
48
|
+
* without an install, like `help`, and sends a `help` event (spec 14.2).
|
|
49
|
+
*/
|
|
50
|
+
export declare function targetHelp(cwd: string, target: string, out: Output): number;
|
|
51
|
+
/** Approves new versions of "pin" packages and writes what a model run left pending (spec 6.2). */
|
|
52
|
+
export declare function approve(cwd: string, name: string | undefined, out: Output): number;
|
|
53
|
+
export declare function newUnit(cwd: string, kind: string, name: string, options: {
|
|
54
|
+
to?: string;
|
|
55
|
+
entry?: boolean;
|
|
56
|
+
}, out: Output): number;
|
|
57
|
+
export declare function fetch(cwd: string, out: Output): number;
|
|
58
|
+
export declare function check(target: string, out: Output): number;
|