@harnesspm/cli 0.0.0-snapshot.412a718 → 0.0.0-snapshot.ce9f12c
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 +16 -0
- package/README.md +12 -9
- package/dist/cli.js +26 -14
- package/dist/commands.d.ts +16 -6
- package/dist/commands.js +305 -161
- package/dist/exec-outputs.d.ts +2 -0
- package/dist/exec-outputs.js +5 -4
- package/dist/run.js +1 -1
- package/dist/start.d.ts +18 -0
- package/dist/start.js +136 -0
- package/docs/spec/01-overview.md +13 -6
- package/docs/spec/04-outputs.md +5 -5
- package/docs/spec/06-trust.md +1 -1
- package/docs/spec/07-added.md +2 -2
- package/docs/spec/09-cloud.md +1 -1
- package/docs/spec/10-cli.md +65 -31
- package/harness/dev.harnesspm/rules/harnesspm-config.md +1 -1
- package/harness/skills/harnesspm-export/SKILL.md +1 -1
- package/harness/skills/harnesspm-import/SKILL.md +10 -18
- package/package.json +1 -1
package/dist/commands.js
CHANGED
|
@@ -14,14 +14,15 @@ import { fetchLocked, locateLocked } from './fetch.js';
|
|
|
14
14
|
import { createPatch, createUnit, KINDS, resolveTarget } from './new.js';
|
|
15
15
|
import { reviewedState } from './reviewed.js';
|
|
16
16
|
import { runMcp, runScript } from './run.js';
|
|
17
|
-
import { pathTools } from './outputs.js';
|
|
17
|
+
import { DOCS_EXCLUDE, DOCS_PROBE, pathTools } from './outputs.js';
|
|
18
|
+
import { afterInit, EVERY_COMMAND, nextAfterNew, startText, version } from './start.js';
|
|
18
19
|
import { alwaysOnText, blockRange, helpTarget, ruleBodyWithoutTitle } from './render.js';
|
|
19
20
|
import { describeMembers, localRuleChanges, resolve, resolvePackageDir, rulesForDirectory } from './resolve.js';
|
|
20
21
|
import { demoteHeadings } from './sections.js';
|
|
21
22
|
import { tryFrontmatter } from './frontmatter.js';
|
|
22
23
|
import { commandCaller, describeSend, outsideField, readIndex, readTelemetryState, sendEvent } from './telemetry.js';
|
|
23
24
|
import { migrateSessionHook, userHeld, writeUserOutputs, writeUserSettings } from './user-outputs.js';
|
|
24
|
-
import { HarnessError, NPX_ANY, OLD_PACKAGE_NAMES, PACKAGE_NAME, PACKAGE_NAMES, addExclude, codexRun, gitExcludeFile, inCloudSession, insideDir, isDir, isFile, isRecord, readJson, readJsonIfExists, readTextIfExists, relPosix, runner, shellWord, writeIfChanged } from './util.js';
|
|
25
|
+
import { HarnessError, NPX_ANY, OLD_PACKAGE_NAMES, PACKAGE_NAME, PACKAGE_NAMES, addExclude, codexRun, gitExclude, gitExcludeFile, gitIgnoreSource, inCloudSession, insideDir, isDir, isFile, isRecord, readJson, readJsonIfExists, readTextIfExists, relPosix, runner, shellWord, writeIfChanged } from './util.js';
|
|
25
26
|
import { spawnSync } from 'node:child_process';
|
|
26
27
|
const printWarnings = (out, warnings) => {
|
|
27
28
|
for (const w of [...new Set(warnings)])
|
|
@@ -32,25 +33,34 @@ const plural = (count, word, many = `${word}s`) => `${count} ${count === 1 ? wor
|
|
|
32
33
|
* Where a person grants what an agent could not. A Claude Code cloud session has no terminal of the person's, and its
|
|
33
34
|
* container goes away, so there the setup script runs the command, before each new session starts (spec 9).
|
|
34
35
|
*/
|
|
35
|
-
const cloudStep = (what
|
|
36
|
-
|
|
36
|
+
const cloudStep = (what) => `A Claude Code cloud session gives the person no terminal, so the environment's setup script grants this before each new session: ask them to add ${what} to it.`;
|
|
37
|
+
/** `withAdd` also names a person's own `add`, which grants entries of added harnesses; trusting a package needs only the install. */
|
|
38
|
+
function grantStep(projectDir, inTerminal, withAdd = true) {
|
|
37
39
|
if (!inCloudSession())
|
|
38
40
|
return inTerminal;
|
|
39
41
|
const line = setupLine(projectDir);
|
|
40
|
-
|
|
42
|
+
const install = line !== undefined ? `\`${line}\`` : "the project's install";
|
|
43
|
+
return cloudStep(withAdd ? `${install}, or their own \`${NPX_ANY} add <source>\`,` : install);
|
|
41
44
|
}
|
|
42
45
|
const firstThree = (items) => `${items.slice(0, 3).join('; ')}${items.length > 3 ? '; …' : ''}`;
|
|
43
46
|
const heldList = (report) => `${plural(report.held.length, 'entry', 'entries')} that an agent cannot grant (${firstThree(report.held)})${report.why !== undefined ? `, because ${report.why}` : ''}`;
|
|
44
47
|
const unwrittenList = ({ entries, branch }) => `${plural(entries.length, 'entry', 'entries')} that ${branch} records (${firstThree(entries)})`;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
48
|
+
/** The person's step for everything an agent cannot grant itself (spec 6.2, rule 4). */
|
|
49
|
+
const APPROVE = `A person runs \`${NPX_ANY} approve\` in their own terminal.`;
|
|
50
|
+
const WAITING = '⏳ Waiting for a person';
|
|
51
|
+
/**
|
|
52
|
+
* Everything that waits for a person, one line each with the step that ends the wait: packages to trust or versions to
|
|
53
|
+
* approve, and entries an agent's run held back (spec 6.2). What any sync writes is not a person's step.
|
|
54
|
+
*/
|
|
55
|
+
function waitingLines(report, projectDir) {
|
|
56
|
+
return [...new Set(report.pending), ...(report.held.length > 0 ? [`${heldList(report)}. ${grantStep(projectDir, APPROVE)}`] : [])];
|
|
57
|
+
}
|
|
58
|
+
function printWaiting(out, lines) {
|
|
59
|
+
if (lines.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
out.log(WAITING);
|
|
62
|
+
for (const line of lines)
|
|
63
|
+
out.log(` - ${line}`);
|
|
54
64
|
}
|
|
55
65
|
/** The repository to work on: the nearest folder with harnesspm.json, else the git root, else `cwd`. */
|
|
56
66
|
export function findProjectDir(cwd) {
|
|
@@ -102,23 +112,36 @@ function resolveAll(projectDir, options) {
|
|
|
102
112
|
* so that an install's sync cannot hide a missed sync from a later `sync --check` (spec 6.4, 10.1).
|
|
103
113
|
*/
|
|
104
114
|
export function sync(cwd, out, options = {}) {
|
|
105
|
-
const projectDir = findProjectDir(cwd);
|
|
106
115
|
if (options.check && options.write)
|
|
107
116
|
throw new HarnessError('Use either --check or --write, not both.');
|
|
108
|
-
if (options.check)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
for (const p of problems)
|
|
114
|
-
out.log(`❌ ${p}`);
|
|
115
|
-
if (problems.length > 0) {
|
|
116
|
-
out.log(`Run \`${NPX_ANY} sync\` and commit the result.`);
|
|
117
|
-
return 1;
|
|
118
|
-
}
|
|
119
|
-
out.log('✅ harnesspm outputs are up to date');
|
|
117
|
+
if (options.check)
|
|
118
|
+
return syncCheck(findProjectDir(cwd), out);
|
|
119
|
+
const done = syncProject(cwd, out, options);
|
|
120
|
+
printWaiting(out, waitingLines(done.report, done.projectDir));
|
|
121
|
+
if (options.quiet)
|
|
120
122
|
return 0;
|
|
123
|
+
if (done.keptCommitted)
|
|
124
|
+
out.log(`CI: committed outputs left as they are; \`${NPX_ANY} sync --check\` compares them, \`sync --write\` writes them.`);
|
|
125
|
+
out.log(done.changed > 0 ? `harnesspm: ${done.what}. Updated ${plural(done.changed, 'file')}.` : `harnesspm: ${done.what}. Nothing changed.`);
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
function syncCheck(projectDir, out) {
|
|
129
|
+
const { team, full, warnings } = resolveAll(projectDir, { withAdded: false });
|
|
130
|
+
const plan = computePlan(team, full);
|
|
131
|
+
printWarnings(out, [...warnings, ...plan.warnings]);
|
|
132
|
+
const problems = checkPlan(projectDir, plan);
|
|
133
|
+
for (const p of problems)
|
|
134
|
+
out.log(`❌ ${p}`);
|
|
135
|
+
if (problems.length > 0) {
|
|
136
|
+
out.log(`Run \`${NPX_ANY} sync\` and commit the result.`);
|
|
137
|
+
return 1;
|
|
121
138
|
}
|
|
139
|
+
out.log('✅ harnesspm outputs are up to date');
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
/** Writes every output, as `sync` does, and prints only the warnings. */
|
|
143
|
+
function syncProject(cwd, out, options) {
|
|
144
|
+
const projectDir = findProjectDir(cwd);
|
|
122
145
|
const resolved = resolveAll(projectDir, { withAdded: true });
|
|
123
146
|
const { full, mode } = resolved;
|
|
124
147
|
const warnings = [...resolved.warnings];
|
|
@@ -170,19 +193,13 @@ export function sync(cwd, out, options = {}) {
|
|
|
170
193
|
if (process.env['CI'] !== 'true' && !model)
|
|
171
194
|
changed.push(...migrateSessionHook());
|
|
172
195
|
printWarnings(out, warnings);
|
|
173
|
-
printPending(out, report, projectDir);
|
|
174
|
-
if (options.quiet)
|
|
175
|
-
return 0;
|
|
176
|
-
if (keptCommitted)
|
|
177
|
-
out.log(`CI: committed outputs left as they are; \`${NPX_ANY} sync --check\` compares them, \`sync --write\` writes them.`);
|
|
178
196
|
const counts = `${plural(new Set(full.rules.map((r) => r.id)).size, 'rule')}, ${plural(full.skills.length, 'skill')}, ${plural(full.docs.length, 'doc')} from ${plural(full.packages.length, 'package')}`;
|
|
179
197
|
const above = `Sessions that start here get the hooks of ${plural(children.length, 'project')} below: ${children.map((c) => path.basename(c)).join(', ')}`;
|
|
180
198
|
const gone = 'No projects below this folder any more: removed what an earlier sync wrote for them';
|
|
181
199
|
const below = `Added harnesses in ${plural(applied.length, 'repository', 'repositories')} below: ${applied.join(', ')}`;
|
|
182
200
|
const parts = [...(children.length > 0 ? [above] : parentSync ? [gone] : []), ...(applied.length > 0 ? [below] : [])];
|
|
183
201
|
const what = mode === 'none' ? (parts.length > 0 ? parts.join('. ') : 'Nothing to do in this folder') : mode === 'added-only' ? `Added harnesses only: ${counts}` : counts;
|
|
184
|
-
|
|
185
|
-
return 0;
|
|
202
|
+
return { projectDir, report, what, mode, changed: changed.length, keptCommitted };
|
|
186
203
|
}
|
|
187
204
|
/**
|
|
188
205
|
* Writes one project's outputs, as `sync` in it does. `keepCommitted` leaves the committed outputs as they are and
|
|
@@ -273,17 +290,75 @@ function harnesspmDependency(pkg) {
|
|
|
273
290
|
}));
|
|
274
291
|
}
|
|
275
292
|
const dependsOnHarnesspm = (pkg) => harnesspmDependency(pkg) !== undefined;
|
|
276
|
-
/** Lockfiles that an install changes, with the
|
|
277
|
-
const
|
|
278
|
-
'package-lock.json': 'npm
|
|
279
|
-
'npm-shrinkwrap.json': 'npm
|
|
280
|
-
'pnpm-lock.yaml': 'pnpm
|
|
281
|
-
'yarn.lock': 'yarn
|
|
282
|
-
'bun.lock': 'bun
|
|
283
|
-
'bun.lockb': 'bun
|
|
293
|
+
/** Lockfiles that an install changes, with the package manager that writes each one. */
|
|
294
|
+
const LOCKS = {
|
|
295
|
+
'package-lock.json': 'npm',
|
|
296
|
+
'npm-shrinkwrap.json': 'npm',
|
|
297
|
+
'pnpm-lock.yaml': 'pnpm',
|
|
298
|
+
'yarn.lock': 'yarn',
|
|
299
|
+
'bun.lock': 'bun',
|
|
300
|
+
'bun.lockb': 'bun',
|
|
301
|
+
};
|
|
302
|
+
/** The install that each package manager's lockfile asks for, and its command that adds a dev dependency. */
|
|
303
|
+
const MANAGERS = {
|
|
304
|
+
npm: { install: 'npm ci', add: 'npm i -D' },
|
|
305
|
+
pnpm: { install: 'pnpm install', add: 'pnpm add -D' },
|
|
306
|
+
yarn: { install: 'yarn install', add: 'yarn add -D' },
|
|
307
|
+
bun: { install: 'bun install', add: 'bun add -d' },
|
|
284
308
|
};
|
|
285
309
|
/** `init` names the lockfile the project has with the files to commit. */
|
|
286
|
-
const LOCKFILES = Object.keys(
|
|
310
|
+
const LOCKFILES = Object.keys(LOCKS);
|
|
311
|
+
const lockfileOf = (projectDir) => LOCKFILES.find((file) => isFile(path.join(projectDir, file)));
|
|
312
|
+
/** The project's package manager: by its lockfile, else by its `packageManager` field, else npm. */
|
|
313
|
+
function managerOf(projectDir, pkg) {
|
|
314
|
+
const lock = lockfileOf(projectDir);
|
|
315
|
+
if (lock !== undefined)
|
|
316
|
+
return LOCKS[lock];
|
|
317
|
+
const field = typeof pkg['packageManager'] === 'string' ? /^(npm|pnpm|yarn|bun)@/.exec(pkg['packageManager'])?.[1] : undefined;
|
|
318
|
+
return field ?? 'npm';
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Yarn 2 and later install with Plug'n'Play unless `.yarnrc.yml` sets another `nodeLinker`. Plug'n'Play writes no
|
|
322
|
+
* `node_modules`, where harnesspm finds each package's harness, so harnesspm supports Yarn with `nodeLinker: node-modules`.
|
|
323
|
+
*/
|
|
324
|
+
function yarnPnp(projectDir) {
|
|
325
|
+
if (isFile(path.join(projectDir, '.pnp.cjs')))
|
|
326
|
+
return true;
|
|
327
|
+
const rc = readTextIfExists(path.join(projectDir, '.yarnrc.yml'));
|
|
328
|
+
return rc !== undefined && !/^nodeLinker:\s*["']?node-modules\b/m.test(rc);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Adds harnesspm as a dev dependency with the project's package manager, at this version or a later compatible one
|
|
332
|
+
* (spec 10.1), and returns the command. A workspace root needs pnpm's `-w` and Yarn 1's `-W`. The package manager's
|
|
333
|
+
* own output goes to stderr, so the report on stdout stays as `init` prints it.
|
|
334
|
+
*/
|
|
335
|
+
function installHarnesspm(projectDir, manager, pkg) {
|
|
336
|
+
const root = manager === 'pnpm' ? isFile(path.join(projectDir, 'pnpm-workspace.yaml')) : manager === 'yarn' && 'workspaces' in pkg && !isFile(path.join(projectDir, '.yarnrc.yml'));
|
|
337
|
+
const add = `${MANAGERS[manager].add}${root ? (manager === 'pnpm' ? ' -w' : ' -W') : ''}`;
|
|
338
|
+
const own = version();
|
|
339
|
+
const spec = `${PACKAGE_NAME}@${own.includes('-') ? own : `^${own}`}`;
|
|
340
|
+
const windows = process.platform === 'win32';
|
|
341
|
+
const [command, ...args] = add.split(' ');
|
|
342
|
+
const result = spawnSync(windows ? `${add} ${spec}` : command, windows ? [] : [...args, spec], { cwd: projectDir, stdio: ['ignore', 2, 2], shell: windows });
|
|
343
|
+
if (result.status !== 0) {
|
|
344
|
+
throw new HarnessError(`\`${add} ${spec}\` failed${result.error ? ` (${result.error.message})` : ''}, so init stopped before it changed anything. Add ${PACKAGE_NAME} as a dev dependency yourself, then run \`${NPX_ANY} init\` again.`);
|
|
345
|
+
}
|
|
346
|
+
return add;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Adds `/.harnesspm/` to the project folder's `.gitignore`, so formatters skip the docs copies (spec 4.3, note 8), unless
|
|
350
|
+
* a `.gitignore` already ignores the folder. Only `init` edits `.gitignore`, and only this line. False outside git.
|
|
351
|
+
*/
|
|
352
|
+
function ignoreDocsCopies(projectDir) {
|
|
353
|
+
if (gitExclude(projectDir) === undefined)
|
|
354
|
+
return false;
|
|
355
|
+
const source = gitIgnoreSource(projectDir, DOCS_PROBE);
|
|
356
|
+
if (typeof source === 'string' && !path.isAbsolute(source) && path.basename(source) === '.gitignore')
|
|
357
|
+
return false;
|
|
358
|
+
const file = path.join(projectDir, '.gitignore');
|
|
359
|
+
const text = readTextIfExists(file) ?? '';
|
|
360
|
+
return writeIfChanged(file, `${text}${text === '' || text.endsWith('\n') ? '' : '\n'}${DOCS_EXCLUDE}\n`);
|
|
361
|
+
}
|
|
287
362
|
/**
|
|
288
363
|
* The project's install for a Claude Code cloud environment's setup script (spec 9.1), or undefined when it is not
|
|
289
364
|
* known. It names the project by its absolute path, because the setup script does not start in the clone. A pinned
|
|
@@ -294,20 +369,20 @@ function setupLine(projectDir) {
|
|
|
294
369
|
// A folder above projects: its sync, after the projects' installs (spec 4.10).
|
|
295
370
|
if (isParentFolder(projectDir))
|
|
296
371
|
return `cd ${/^[\w./-]+$/.test(projectDir) ? projectDir : `'${projectDir.replaceAll("'", "'\\''")}'`} && ${NPX_ANY} sync`;
|
|
297
|
-
const lock =
|
|
372
|
+
const lock = lockfileOf(projectDir);
|
|
298
373
|
if (lock === undefined || !isFile(path.join(projectDir, CONFIG_FILE)))
|
|
299
374
|
return undefined;
|
|
300
375
|
const pkg = readJsonIfExists(path.join(projectDir, 'package.json'));
|
|
301
376
|
const corepack = isRecord(pkg) && typeof pkg['packageManager'] === 'string' ? 'corepack enable && COREPACK_NPM_REGISTRY=https://registry.npmjs.org ' : '';
|
|
302
377
|
const dir = /^[\w./-]+$/.test(projectDir) ? projectDir : `'${projectDir.replaceAll("'", "'\\''")}'`;
|
|
303
|
-
return `cd ${dir} && ${corepack}${
|
|
378
|
+
return `cd ${dir} && ${corepack}${MANAGERS[LOCKS[lock]].install}`;
|
|
304
379
|
}
|
|
305
380
|
/** The committed files (spec 1.7) that git sees as new or changed, in a fixed order. Empty outside git. */
|
|
306
381
|
function filesToCommit(projectDir) {
|
|
307
382
|
const { team, full } = resolveAll(projectDir, { withAdded: false });
|
|
308
383
|
const committed = team ? computePlan(team, full).committed : undefined;
|
|
309
384
|
const nested = committed ? [...committed.workspaces.filter((ws) => ws.agentsMd !== undefined).map((ws) => path.join(ws.dir, 'AGENTS.md')), ...committed.claudeMds.map((c) => c.file)] : [];
|
|
310
|
-
const candidates = [...new Set(['AGENTS.md', 'CLAUDE.md', ...nested.map((file) => relPosix(projectDir, file)), CONFIG_FILE, LOCK_FILE, 'package.json', ...LOCKFILES])];
|
|
385
|
+
const candidates = [...new Set(['.gitignore', 'AGENTS.md', 'CLAUDE.md', ...nested.map((file) => relPosix(projectDir, file)), CONFIG_FILE, LOCK_FILE, 'package.json', ...LOCKFILES])];
|
|
311
386
|
// The short format shows paths relative to the current folder, also in a subfolder of the repository.
|
|
312
387
|
const result = spawnSync('git', ['status', '--short', '--untracked-files=all', '--', ...candidates], { cwd: projectDir, encoding: 'utf8' });
|
|
313
388
|
if (result.status !== 0)
|
|
@@ -315,24 +390,75 @@ function filesToCommit(projectDir) {
|
|
|
315
390
|
const changed = new Set(result.stdout.split('\n').filter((line) => line.length > 3).map((line) => line.slice(3).replace(/^.* -> /, '')));
|
|
316
391
|
return candidates.filter((file) => changed.has(file));
|
|
317
392
|
}
|
|
393
|
+
/** More tool lines than this, and `init` lists one line per package instead. */
|
|
394
|
+
const TOOL_LINES = 8;
|
|
395
|
+
/**
|
|
396
|
+
* The executable units of the packages that the project does not trust yet, as `init` lists them: each tool with what
|
|
397
|
+
* it does and whether it runs without a prompt, the hooks and MCP servers, or one line per package when there are many.
|
|
398
|
+
*/
|
|
399
|
+
function untrustedTools(team) {
|
|
400
|
+
const rows = [];
|
|
401
|
+
const perPackage = [];
|
|
402
|
+
const packages = [];
|
|
403
|
+
for (const pkg of team.packages) {
|
|
404
|
+
if (pkg.layer !== 'dependencies' || team.config.trust[pkg.name] !== undefined)
|
|
405
|
+
continue;
|
|
406
|
+
const scripts = team.scripts.filter((s) => s.pkg === pkg);
|
|
407
|
+
const hooks = team.hooks.filter((h) => h.pkg === pkg);
|
|
408
|
+
const servers = team.mcp.filter((m) => m.pkg === pkg);
|
|
409
|
+
if (scripts.length + hooks.length + servers.length === 0)
|
|
410
|
+
continue;
|
|
411
|
+
packages.push(pkg.name);
|
|
412
|
+
const tools = scripts.filter((s) => s.description !== undefined);
|
|
413
|
+
for (const s of tools) {
|
|
414
|
+
const events = [...new Set(hooks.filter((h) => h.run === s.name).map((h) => h.event))];
|
|
415
|
+
rows.push([pkg.name, `${pkg.plugin}:${s.name} — ${s.description}${s.allow ? ' · no prompt' : ''}${events.length > 0 ? ` · a ${events.join(' and ')} hook runs it` : ''}`]);
|
|
416
|
+
}
|
|
417
|
+
for (const h of hooks)
|
|
418
|
+
if (!tools.some((s) => s.name === h.run))
|
|
419
|
+
rows.push([pkg.name, `a ${h.event} hook runs ${pkg.plugin}:${h.run}`]);
|
|
420
|
+
for (const m of servers)
|
|
421
|
+
rows.push([pkg.name, `MCP server ${pkg.plugin}:${m.name}`]);
|
|
422
|
+
const what = [plural(scripts.length, 'script'), plural(hooks.length, 'hook'), plural(servers.length, 'MCP server')].filter((w) => !w.startsWith('0 '));
|
|
423
|
+
perPackage.push([pkg.name, `${what.join(', ')}: \`${NPX_ANY} help ${helpTarget(pkg)}\``]);
|
|
424
|
+
}
|
|
425
|
+
const chosen = rows.length > TOOL_LINES ? perPackage : rows;
|
|
426
|
+
const width = Math.max(0, ...chosen.map(([name]) => name.length)) + 2;
|
|
427
|
+
return { lines: chosen.map(([name, text]) => ` ${name.padEnd(width)}${text}`), packages };
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* `harnesspm init` (spec 10.1): installs harnesspm when the project does not list it, writes the configuration, the
|
|
431
|
+
* install hook, the import in CLAUDE.md and the `.gitignore` line, syncs, and reports what waits for a person and what
|
|
432
|
+
* to commit.
|
|
433
|
+
*/
|
|
318
434
|
export function init(projectDir, out) {
|
|
319
435
|
const pkgFile = path.join(projectDir, 'package.json');
|
|
320
436
|
if (!isFile(pkgFile))
|
|
321
|
-
throw new HarnessError(
|
|
322
|
-
|
|
323
|
-
const pkg = readJson(pkgFile);
|
|
437
|
+
throw new HarnessError(`No package.json here, so there is no project to set up. \`${NPX_ANY}\` names the tasks for this folder.`);
|
|
438
|
+
let pkg = readJson(pkgFile);
|
|
324
439
|
if (!isRecord(pkg))
|
|
325
440
|
throw new HarnessError('package.json must be a JSON object');
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
441
|
+
const manager = managerOf(projectDir, pkg);
|
|
442
|
+
if (manager === 'yarn' && yarnPnp(projectDir)) {
|
|
443
|
+
throw new HarnessError(`This project uses Yarn Plug'n'Play, which writes no node_modules, where harnesspm finds each package's harness. Set \`nodeLinker: node-modules\` in .yarnrc.yml, run \`yarn install\`, then run \`${NPX_ANY} init\` again.`);
|
|
444
|
+
}
|
|
445
|
+
// The script that `init` adds calls the `harnesspm` command, so the project must list harnesspm: without it, the next
|
|
446
|
+
// install fails with "harnesspm: not found" (research/package-managers.md). Install it first, before anything changes.
|
|
447
|
+
let dependency = harnesspmDependency(pkg);
|
|
329
448
|
if (dependency === undefined) {
|
|
330
|
-
|
|
449
|
+
const add = installHarnesspm(projectDir, manager, pkg);
|
|
450
|
+
pkg = readJson(pkgFile);
|
|
451
|
+
dependency = harnesspmDependency(pkg);
|
|
452
|
+
if (!isRecord(pkg) || dependency === undefined)
|
|
453
|
+
throw new HarnessError(`\`${add}\` did not list ${PACKAGE_NAME} in package.json. Add it as a dev dependency yourself, then run \`${NPX_ANY} init\` again.`);
|
|
454
|
+
out.log(`Installed ${PACKAGE_NAME} as a dev dependency (${add})`);
|
|
331
455
|
}
|
|
456
|
+
const raw = readTextIfExists(pkgFile);
|
|
457
|
+
const wrote = [];
|
|
332
458
|
const configFile = path.join(projectDir, CONFIG_FILE);
|
|
333
459
|
if (!isFile(configFile)) {
|
|
334
460
|
writeIfChanged(configFile, `${JSON.stringify({ $schema: CONFIG_SCHEMA }, null, 2)}\n`);
|
|
335
|
-
|
|
461
|
+
wrote.push(CONFIG_FILE);
|
|
336
462
|
}
|
|
337
463
|
// A private package is never installed by others, so `postinstall` is safe there, and Yarn 2+ runs only
|
|
338
464
|
// `postinstall`. A published package uses `prepare`, which does not run when others install it.
|
|
@@ -344,7 +470,7 @@ export function init(projectDir, out) {
|
|
|
344
470
|
const current = typeof scripts[hookName] === 'string' ? scripts[hookName] : undefined;
|
|
345
471
|
scripts[hookName] = current === undefined ? installHook(dependency) : `${current} && (${installHook(dependency)})`;
|
|
346
472
|
changed = true;
|
|
347
|
-
|
|
473
|
+
wrote.push(`the "${hookName}" script (syncs on every install)`);
|
|
348
474
|
}
|
|
349
475
|
else {
|
|
350
476
|
for (const name of HOOK_SCRIPTS) {
|
|
@@ -364,15 +490,40 @@ export function init(projectDir, out) {
|
|
|
364
490
|
}
|
|
365
491
|
const claude = claudeImport(projectDir);
|
|
366
492
|
if (writeIfChanged(claude.file, claude.text))
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
493
|
+
wrote.push(`${relPosix(projectDir, claude.file)} (imports AGENTS.md)`);
|
|
494
|
+
if (ignoreDocsCopies(projectDir))
|
|
495
|
+
wrote.push(`.gitignore (${DOCS_EXCLUDE})`);
|
|
496
|
+
if (wrote.length > 0)
|
|
497
|
+
out.log(`Wrote ${wrote.join(', ')}`);
|
|
498
|
+
const done = syncProject(projectDir, out, { write: true });
|
|
499
|
+
out.log(`harnesspm: ${done.what}.${done.mode === 'full' ? ' Agents find them through the block in AGENTS.md.' : ''}`);
|
|
500
|
+
// What waits for a person, with the tools of each package that is not trusted, so the person can decide on trust.
|
|
501
|
+
const { team } = resolveAll(projectDir, { withAdded: false });
|
|
502
|
+
const tools = team ? untrustedTools(team) : { lines: [], packages: [] };
|
|
503
|
+
const others = waitingLines(done.report, projectDir).filter((line) => !tools.packages.some((name) => line.startsWith(`${name}: `)));
|
|
504
|
+
const waiting = tools.lines.length + others.length > 0;
|
|
505
|
+
// Without an installed dependency, the sync wrote no units, and its warning says why.
|
|
506
|
+
const full = done.mode === 'full';
|
|
507
|
+
out.log('');
|
|
508
|
+
if (!waiting)
|
|
509
|
+
out.log(full ? 'Rules, docs, skills and tools work now. Nothing waits for a person.' : 'Nothing waits for a person.');
|
|
510
|
+
else {
|
|
511
|
+
if (full)
|
|
512
|
+
out.log('Rules, docs and skills work now.');
|
|
513
|
+
out.log(`${WAITING}${tools.lines.length > 0 ? ': these tools stay off until a person trusts their package.' : ''}`);
|
|
514
|
+
for (const line of tools.lines)
|
|
515
|
+
out.log(line);
|
|
516
|
+
if (tools.lines.length > 0) {
|
|
517
|
+
const step = inCloudSession() ? ` and commits it. ${grantStep(projectDir, APPROVE, false)}` : `, then runs \`${NPX_ANY} approve\` in their own terminal.`;
|
|
518
|
+
out.log(` To turn one on, a person adds its package to "trust" in ${CONFIG_FILE}${step} An agent never changes "trust" itself.`);
|
|
519
|
+
}
|
|
520
|
+
for (const line of others)
|
|
521
|
+
out.log(` - ${line}`);
|
|
522
|
+
}
|
|
523
|
+
out.log('');
|
|
524
|
+
for (const line of afterInit(filesToCommit(projectDir), waiting))
|
|
525
|
+
out.log(line);
|
|
526
|
+
return 0;
|
|
376
527
|
}
|
|
377
528
|
/** Directories of editable added harnesses, which agents may write to (spec 8.5). */
|
|
378
529
|
function writableDirs() {
|
|
@@ -388,7 +539,7 @@ function writableDirs() {
|
|
|
388
539
|
function settingsAfterChange(out, hook) {
|
|
389
540
|
if (caller() === 'model') {
|
|
390
541
|
out.log('⏳ The SessionStart hook and write access to the harness folder are pending: an agent cannot grant them.');
|
|
391
|
-
out.log(` ${inCloudSession() ? cloudStep('the same command'
|
|
542
|
+
out.log(` ${inCloudSession() ? cloudStep('the same command') : 'Ask the person to run the same command in their own terminal.'}`);
|
|
392
543
|
return;
|
|
393
544
|
}
|
|
394
545
|
const anyUser = readList(configFileFor('user', '')).length > 0;
|
|
@@ -591,9 +742,35 @@ function preview(projectDir, resolved) {
|
|
|
591
742
|
function describeAdded(h) {
|
|
592
743
|
return `${h.pkg.plugin} (${h.source.spec}, ${h.scope})${h.entry ? ', with an entry for this repository' : ''}`;
|
|
593
744
|
}
|
|
745
|
+
/** `harnesspm status`: the project's report (spec 10.5). It always exits 0. */
|
|
594
746
|
export function status(cwd, out) {
|
|
595
|
-
|
|
596
|
-
|
|
747
|
+
report(cwd, out);
|
|
748
|
+
return 0;
|
|
749
|
+
}
|
|
750
|
+
/** `harnesspm doctor`: the same report, which exits 1 when a check fails; what waits for a person does not fail. */
|
|
751
|
+
export function doctor(cwd, out) {
|
|
752
|
+
return report(cwd, out) > 0 ? 1 : 0;
|
|
753
|
+
}
|
|
754
|
+
/** The command that runs harnesspm here: the installed one in a project that uses it (spec 10). */
|
|
755
|
+
const syncCommand = (_projectDir) => `${NPX_ANY} sync`;
|
|
756
|
+
/** A telemetry file inside the project, which harnesspm keeps out of git (spec 14.1). */
|
|
757
|
+
function telemetryFiles(projectDir) {
|
|
758
|
+
const send = readTelemetryState(projectDir).config?.send;
|
|
759
|
+
if (send === undefined || typeof send === 'string')
|
|
760
|
+
return [];
|
|
761
|
+
const rel = relPosix(projectDir, path.resolve(projectDir, send.file));
|
|
762
|
+
return rel.startsWith('../') || path.isAbsolute(rel) ? [] : [rel];
|
|
763
|
+
}
|
|
764
|
+
const linkPointsTo = (link, target) => {
|
|
765
|
+
try {
|
|
766
|
+
return fs.lstatSync(link).isSymbolicLink() && path.resolve(path.dirname(link), fs.readlinkSync(link)) === path.resolve(target);
|
|
767
|
+
}
|
|
768
|
+
catch {
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
/** The layers and the always-on size: the report's first lines. */
|
|
773
|
+
function summary(projectDir, resolved, plan, out) {
|
|
597
774
|
const res = resolved.team ?? resolved.full;
|
|
598
775
|
const deps = res.packages.filter((p) => p.layer === 'dependencies');
|
|
599
776
|
const describe = (name, version) => `${name} ${version}`;
|
|
@@ -615,60 +792,31 @@ export function status(cwd, out) {
|
|
|
615
792
|
if (own)
|
|
616
793
|
projectParts.push(`harness/ (plugin ${own.plugin})`);
|
|
617
794
|
out.log(`🏢 project ${projectParts.join(' · ')}`);
|
|
618
|
-
|
|
619
|
-
const { plan, report } = preview(projectDir, resolved);
|
|
620
|
-
printPending(out, report, projectDir);
|
|
621
|
-
if (resolved.team) {
|
|
795
|
+
if (resolved.team && plan?.committed) {
|
|
622
796
|
const changes = [...new Set(localRuleChanges(resolved.team, resolved.full).map(({ id }) => id))];
|
|
623
797
|
if (changes.length > 0)
|
|
624
798
|
out.log(`✏️ changed here ${changes.join(', ')} (by added harnesses; see CLAUDE.local.md)`);
|
|
625
799
|
const agents = plan.committed.agentsMd;
|
|
626
|
-
const bytes = Buffer.byteLength(agents);
|
|
627
800
|
const claudeLines = agents.split('\n').length + (plan.localMd ?? '').split('\n').length;
|
|
628
|
-
out.log(`📏 always-on Codex ${(
|
|
629
|
-
if (bytes > CODEX_LIMIT)
|
|
630
|
-
out.warn(`⚠️ AGENTS.md is over ${CODEX_OVER}. Move details into on-demand rules or docs.`);
|
|
631
|
-
else if (bytes > 28 * 1024)
|
|
632
|
-
out.warn("⚠️ AGENTS.md is close to Codex's 32 KiB limit. Move details into on-demand rules or docs.");
|
|
633
|
-
for (const miss of [...lateBlocks(projectDir, plan), ...codexMisses(projectDir, plan)])
|
|
634
|
-
out.warn(`⚠️ ${miss}`);
|
|
801
|
+
out.log(`📏 always-on Codex ${kib(Buffer.byteLength(agents))} of 32 KiB · Claude Code ${claudeLines} lines`);
|
|
635
802
|
}
|
|
636
803
|
const telemetry = readTelemetryState(projectDir);
|
|
637
804
|
if (telemetry.config) {
|
|
638
805
|
out.log(`📡 telemetry ${telemetry.send !== undefined ? `${[...telemetry.events].join(', ')} → ${describeSend(telemetry.send)}` : telemetry.off}`);
|
|
639
806
|
}
|
|
640
|
-
const local = checkLocalFiles(projectDir, telemetryFiles(projectDir));
|
|
641
|
-
if (local && local.problems.length > 0)
|
|
642
|
-
out.log(`🩺 local files ${plural(local.problems.length, 'problem')}. Run \`${syncCommand(projectDir).replace(/ sync$/, ' doctor')}\`.`);
|
|
643
|
-
printWarnings(out, resolved.warnings);
|
|
644
|
-
return 0;
|
|
645
|
-
}
|
|
646
|
-
/** The command that runs harnesspm here: the installed one in a project that uses it (spec 10). */
|
|
647
|
-
const syncCommand = (_projectDir) => `${NPX_ANY} sync`;
|
|
648
|
-
/** A telemetry file inside the project, which harnesspm keeps out of git (spec 14.1). */
|
|
649
|
-
function telemetryFiles(projectDir) {
|
|
650
|
-
const send = readTelemetryState(projectDir).config?.send;
|
|
651
|
-
if (send === undefined || typeof send === 'string')
|
|
652
|
-
return [];
|
|
653
|
-
const rel = relPosix(projectDir, path.resolve(projectDir, send.file));
|
|
654
|
-
return rel.startsWith('../') || path.isAbsolute(rel) ? [] : [rel];
|
|
655
807
|
}
|
|
656
|
-
const linkPointsTo = (link, target) => {
|
|
657
|
-
try {
|
|
658
|
-
return fs.lstatSync(link).isSymbolicLink() && path.resolve(path.dirname(link), fs.readlinkSync(link)) === path.resolve(target);
|
|
659
|
-
}
|
|
660
|
-
catch {
|
|
661
|
-
return false;
|
|
662
|
-
}
|
|
663
|
-
};
|
|
664
808
|
/**
|
|
665
|
-
*
|
|
666
|
-
*
|
|
809
|
+
* The project's report, which `status`, `doctor` and the bare command in a project print (spec 10.5): the layers and
|
|
810
|
+
* sizes, then whether the repository is ready for harnesses, its own and a person's, then what waits for a person. It
|
|
811
|
+
* changes nothing, and each problem names the command that fixes it. Returns the number of failed checks.
|
|
667
812
|
*/
|
|
668
|
-
|
|
813
|
+
function report(cwd, out) {
|
|
669
814
|
const projectDir = findProjectDir(cwd);
|
|
670
815
|
const usesHarnesspm = isFile(path.join(projectDir, CONFIG_FILE));
|
|
671
816
|
const sync = syncCommand(projectDir);
|
|
817
|
+
const resolved = resolveAll(projectDir, { withAdded: true });
|
|
818
|
+
const { plan, report: waiting } = preview(projectDir, resolved);
|
|
819
|
+
summary(projectDir, resolved, plan, out);
|
|
672
820
|
const groups = [];
|
|
673
821
|
// Per-machine files never reach a commit.
|
|
674
822
|
const local = checkLocalFiles(projectDir, telemetryFiles(projectDir), sync);
|
|
@@ -698,13 +846,9 @@ export function doctor(cwd, out) {
|
|
|
698
846
|
groups.push(['➕ Harnesses of your own', own]);
|
|
699
847
|
// Outputs are in place.
|
|
700
848
|
const outputs = [];
|
|
701
|
-
|
|
702
|
-
const { plan, report } = preview(projectDir, resolved);
|
|
703
|
-
if (!usesHarnesspm)
|
|
704
|
-
outputs.push({ level: 'info', text: `This repository does not use harnesspm (no ${CONFIG_FILE}), so only added harnesses apply.` });
|
|
705
|
-
else if (!resolved.team)
|
|
849
|
+
if (usesHarnesspm && !resolved.team)
|
|
706
850
|
outputs.push({ level: 'warn', text: `The dependencies are not installed. Install them, then run \`${sync}\`.` });
|
|
707
|
-
else {
|
|
851
|
+
else if (usesHarnesspm) {
|
|
708
852
|
const forCheck = resolveAll(projectDir, { withAdded: false });
|
|
709
853
|
const problems = checkPlan(projectDir, computePlan(forCheck.team, forCheck.full));
|
|
710
854
|
for (const p of problems)
|
|
@@ -725,6 +869,9 @@ export function doctor(cwd, out) {
|
|
|
725
869
|
outputs.push({ level: 'warn', text: `${plural(stale, 'per-machine output')} missing or out of date. Run \`${sync}\`.` });
|
|
726
870
|
else if (total > 0)
|
|
727
871
|
outputs.push({ level: 'ok', text: `${plural(total, 'per-machine output')} in place` });
|
|
872
|
+
// The repository's entries that any sync writes: not a person's step.
|
|
873
|
+
if (waiting.unwritten)
|
|
874
|
+
outputs.push({ level: 'warn', text: `${unwrittenList(waiting.unwritten)} are not written yet. Run \`${sync}\`.` });
|
|
728
875
|
if (!plan.codexOurs)
|
|
729
876
|
outputs.push({ level: 'warn', text: '.codex/ belongs to the repository, so harnesspm writes nothing there and Codex misses some units.' });
|
|
730
877
|
const pkgJson = readJsonIfExists(path.join(projectDir, 'package.json'));
|
|
@@ -743,38 +890,36 @@ export function doctor(cwd, out) {
|
|
|
743
890
|
const bytes = plan.committed !== undefined ? Buffer.byteLength(plan.committed.agentsMd) : 0;
|
|
744
891
|
if (bytes > CODEX_LIMIT)
|
|
745
892
|
outputs.push({ level: 'warn', text: `AGENTS.md is ${kib(bytes)}, over ${CODEX_OVER}. Move details into on-demand rules or docs.` });
|
|
893
|
+
else if (bytes > 28 * 1024)
|
|
894
|
+
outputs.push({ level: 'warn', text: "AGENTS.md is close to Codex's 32 KiB limit. Move details into on-demand rules or docs." });
|
|
746
895
|
for (const miss of [...lateBlocks(projectDir, plan), ...codexMisses(projectDir, plan)])
|
|
747
896
|
outputs.push({ level: 'warn', text: miss });
|
|
748
897
|
}
|
|
749
898
|
if (outputs.length > 0)
|
|
750
|
-
groups.push(['
|
|
751
|
-
// Trust: pending entries are not errors (spec 10.4).
|
|
752
|
-
const trust = [];
|
|
753
|
-
// Each pending entry already says how to turn it on: trust the package, or approve a pinned version.
|
|
754
|
-
for (const p of new Set(report.pending))
|
|
755
|
-
trust.push({ level: 'warn', text: `Off: ${p}` });
|
|
756
|
-
if (report.unwritten)
|
|
757
|
-
trust.push({ level: 'warn', text: `${unwrittenList(report.unwritten)} are not written yet. Run \`${sync}\`.` });
|
|
758
|
-
if (report.held.length > 0)
|
|
759
|
-
trust.push({ level: 'warn', text: `${heldList(report)}. ${grantStep(projectDir, `Run \`${NPX_ANY} sync\` in your own terminal.`)}` });
|
|
760
|
-
const telemetry = readTelemetryState(projectDir);
|
|
761
|
-
// A held handler is in the list above, as `sync` lists it.
|
|
762
|
-
const heldHandler = plan?.telemetryHeld !== undefined;
|
|
763
|
-
if (telemetry.config && telemetry.send === undefined && !heldHandler)
|
|
764
|
-
trust.push({ level: telemetry.off?.startsWith('held') ? 'warn' : 'info', text: `Telemetry ${telemetry.off}` });
|
|
765
|
-
if (trust.length === 0 && plan)
|
|
766
|
-
trust.push({ level: 'ok', text: 'Nothing waits for trust' });
|
|
767
|
-
if (trust.length > 0)
|
|
768
|
-
groups.push(['🛡️ Trust', trust]);
|
|
899
|
+
groups.push(['📝 Outputs', outputs]);
|
|
769
900
|
for (const [title, findings] of groups) {
|
|
770
901
|
out.log(title);
|
|
771
902
|
for (const finding of findings)
|
|
772
903
|
out.log(formatFinding(finding));
|
|
773
904
|
}
|
|
905
|
+
// Each entry says how to turn it on: trust the package, approve a pinned version, or approve what an agent held back.
|
|
906
|
+
printWaiting(out, waitingLines(waiting, projectDir));
|
|
907
|
+
printWarnings(out, resolved.warnings);
|
|
774
908
|
const failed = groups.flatMap(([, findings]) => findings).filter((f) => f.level === 'fail').length;
|
|
775
909
|
out.log('');
|
|
776
910
|
out.log(failed > 0 ? `❌ ${plural(failed, 'problem')}. Each line above says how to fix it.` : '✅ Ready. Nothing to fix.');
|
|
777
|
-
return failed
|
|
911
|
+
return failed;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* The bare command (spec 10.1): in a project that uses harnesspm, its report; elsewhere, what the folder is and the
|
|
915
|
+
* tasks for it, each with the one command that starts it.
|
|
916
|
+
*/
|
|
917
|
+
export function start(cwd, out) {
|
|
918
|
+
if (isFile(path.join(findProjectDir(cwd), CONFIG_FILE)))
|
|
919
|
+
return status(cwd, out);
|
|
920
|
+
for (const line of startText(cwd))
|
|
921
|
+
out.log(line);
|
|
922
|
+
return 0;
|
|
778
923
|
}
|
|
779
924
|
/** The unit `id` of a resolution, with the rules that apply in `cwd`. */
|
|
780
925
|
function findUnit(res, cwd, id) {
|
|
@@ -914,8 +1059,8 @@ export function toolCommand(projectDir) {
|
|
|
914
1059
|
}
|
|
915
1060
|
/** The project's install, from the caller's folder. */
|
|
916
1061
|
function installCommand(projectDir) {
|
|
917
|
-
const lock =
|
|
918
|
-
const install = lock !== undefined ?
|
|
1062
|
+
const lock = lockfileOf(projectDir);
|
|
1063
|
+
const install = lock !== undefined ? MANAGERS[LOCKS[lock]].install : 'npm install';
|
|
919
1064
|
return callerInside(projectDir) ? install : `cd ${fromCaller(projectDir)} && ${install}`;
|
|
920
1065
|
}
|
|
921
1066
|
/**
|
|
@@ -1031,6 +1176,7 @@ function helpView(cwd, out) {
|
|
|
1031
1176
|
command: toolCommand(projectDir),
|
|
1032
1177
|
...(base !== undefined ? { base } : {}),
|
|
1033
1178
|
trusted: (pkg) => trustOf(pkg, res, lock).trusted,
|
|
1179
|
+
trust: (pkg) => trustOf(pkg, res, lock),
|
|
1034
1180
|
paths: {
|
|
1035
1181
|
rule: (rule) => shown(existing(projectPaths.rule(rule), rule.source)),
|
|
1036
1182
|
docsIndex: (pkg) => {
|
|
@@ -1057,18 +1203,14 @@ function helpIntro(view, out) {
|
|
|
1057
1203
|
}
|
|
1058
1204
|
const count = (n, word) => (n === 1 ? `1 ${word}` : `${n} ${word}s`);
|
|
1059
1205
|
/**
|
|
1060
|
-
*
|
|
1061
|
-
* `help <package>` command that prints the rest.
|
|
1206
|
+
* `help` in a project (spec 10.1): one line per package, across workspaces, with what it covers and the
|
|
1207
|
+
* `help <package>` command that prints the rest. Undefined outside a project that uses harnesspm.
|
|
1062
1208
|
*/
|
|
1063
|
-
export function projectHelp(cwd, out
|
|
1209
|
+
export function projectHelp(cwd, out) {
|
|
1064
1210
|
const view = helpView(cwd, out);
|
|
1065
|
-
if (view === undefined)
|
|
1066
|
-
|
|
1067
|
-
out.log(`\n${fromCaller(findProjectDir(cwd))} does not use harnesspm: it has no ${CONFIG_FILE}.`);
|
|
1068
|
-
return 0;
|
|
1069
|
-
}
|
|
1211
|
+
if (view === undefined)
|
|
1212
|
+
return undefined;
|
|
1070
1213
|
const { res, command } = view;
|
|
1071
|
-
out.log('');
|
|
1072
1214
|
helpIntro(view, out);
|
|
1073
1215
|
out.log('');
|
|
1074
1216
|
const lines = res.packages
|
|
@@ -1089,10 +1231,16 @@ export function projectHelp(cwd, out, named) {
|
|
|
1089
1231
|
return `- ${name}${covers !== '' ? ` — ${covers}` : ''}. ${parts.length > 0 ? `${parts.join(', ')}: ` : ''}\`${command} help ${helpTarget(pkg)}\``;
|
|
1090
1232
|
});
|
|
1091
1233
|
out.log(lines.length > 0 ? lines.join('\n') : 'No harness units yet.');
|
|
1234
|
+
out.log('');
|
|
1092
1235
|
if (lines.length > 0)
|
|
1093
|
-
out.log(
|
|
1236
|
+
out.log(`A tool's options: \`${command} help <tool>\`. Run a tool: \`${command} run <tool> [args]\`.`);
|
|
1237
|
+
out.log(`${EVERY_COMMAND}.`);
|
|
1094
1238
|
return 0;
|
|
1095
1239
|
}
|
|
1240
|
+
/** Where `help` says that a folder named with `-C` does not use harnesspm. */
|
|
1241
|
+
export function notAProject(cwd) {
|
|
1242
|
+
return `${fromCaller(findProjectDir(cwd))} does not use harnesspm: it has no ${CONFIG_FILE}.`;
|
|
1243
|
+
}
|
|
1096
1244
|
/** How a rule becomes active, in words (spec 2.5). */
|
|
1097
1245
|
function activationLine(rule, file) {
|
|
1098
1246
|
if (rule.activation === 'always')
|
|
@@ -1113,12 +1261,14 @@ function ruleHelp(view, rule, level) {
|
|
|
1113
1261
|
const body = demoteHeadings(ruleBodyWithoutTitle(rule), level - 1);
|
|
1114
1262
|
return [head, about, ...(body !== '' ? [body] : [])].join('\n\n');
|
|
1115
1263
|
}
|
|
1116
|
-
|
|
1117
|
-
|
|
1264
|
+
/** Why a package's tools are off, and the person's step that turns them on (spec 6.2). */
|
|
1265
|
+
function trustNote(view, pkg) {
|
|
1266
|
+
const { reason = 'not trusted', action = '' } = view.trust(pkg);
|
|
1267
|
+
return `${reason.charAt(0).toUpperCase()}${reason.slice(1)}, so they stay off in this project and \`run\` refuses them. ${action}`;
|
|
1118
1268
|
}
|
|
1119
1269
|
function toolLines(view, script) {
|
|
1120
1270
|
const ref = `${script.pkg.plugin}:${script.name}`;
|
|
1121
|
-
const lines = [`- \`${view.command} run ${ref}${script.usage !== undefined && !script.usage.includes('\n') ? ` ${script.usage}` : ' [args]'}\`${script.description !== undefined ? ` — ${script.description}` : ''} (${script.id})`];
|
|
1271
|
+
const lines = [`- \`${view.command} run ${ref}${script.usage !== undefined && !script.usage.includes('\n') ? ` ${script.usage}` : ' [args]'}\`${script.description !== undefined ? ` — ${script.description}` : ''}${script.allow ? ' · no prompt' : ''} (${script.id})`];
|
|
1122
1272
|
if (script.usage !== undefined && script.usage.includes('\n'))
|
|
1123
1273
|
lines.push(...script.usage.split('\n').map((l) => ` ${l}`));
|
|
1124
1274
|
return lines;
|
|
@@ -1145,10 +1295,10 @@ function packageHelp(view, pkg) {
|
|
|
1145
1295
|
parts.push('## Docs', `- ${index} (${pkg.plugin}:docs)`);
|
|
1146
1296
|
const scripts = res.scripts.filter((s) => s.pkg === pkg && s.description !== undefined);
|
|
1147
1297
|
if (scripts.length > 0)
|
|
1148
|
-
parts.push('## Tools', [...(trusted ? [] : [`⚠️ ${trustNote(pkg)}`]), ...scripts.flatMap((s) => toolLines(view, s))].join('\n'));
|
|
1298
|
+
parts.push('## Tools', [...(trusted ? [] : [`⚠️ ${trustNote(view, pkg)}`]), ...scripts.flatMap((s) => toolLines(view, s))].join('\n'));
|
|
1149
1299
|
const servers = res.mcp.filter((m) => m.pkg === pkg);
|
|
1150
1300
|
if (servers.length > 0)
|
|
1151
|
-
parts.push('## MCP servers', [...(trusted ? [] : [`⚠️ ${trustNote(pkg)}`]), ...servers.map((m) => mcpLine(view, m))].join('\n'));
|
|
1301
|
+
parts.push('## MCP servers', [...(trusted ? [] : [`⚠️ ${trustNote(view, pkg)}`]), ...servers.map((m) => mcpLine(view, m))].join('\n'));
|
|
1152
1302
|
const skills = res.skills.filter((k) => k.pkg === pkg);
|
|
1153
1303
|
if (skills.length > 0) {
|
|
1154
1304
|
const line = (skill) => {
|
|
@@ -1160,7 +1310,7 @@ function packageHelp(view, pkg) {
|
|
|
1160
1310
|
}
|
|
1161
1311
|
const hooks = res.hooks.filter((h) => h.pkg === pkg);
|
|
1162
1312
|
if (hooks.length > 0)
|
|
1163
|
-
parts.push('## Hooks', [...(trusted ? [] : [`⚠️ ${trustNote(pkg)}`]), ...hooks.map(hookLine)].join('\n'));
|
|
1313
|
+
parts.push('## Hooks', [...(trusted ? [] : [`⚠️ ${trustNote(view, pkg)}`]), ...hooks.map(hookLine)].join('\n'));
|
|
1164
1314
|
if (parts.length === 1)
|
|
1165
1315
|
parts.push('No harness units.');
|
|
1166
1316
|
return parts.join('\n\n');
|
|
@@ -1180,9 +1330,11 @@ function scriptHelp(view, script) {
|
|
|
1180
1330
|
lines.push(`Usage: none declared. Its package can add "usage" next to "description" in its manifest. harnesspm does not run the script to ask.`);
|
|
1181
1331
|
if (script.answers !== undefined)
|
|
1182
1332
|
lines.push(`Exit: 0 is ok. ${script.answers.join(', ')} ${script.answers.length > 1 ? 'are answers' : 'is an answer'}, such as "found problems", not a broken tool. Any other code is a failure.`);
|
|
1333
|
+
if (script.allow)
|
|
1334
|
+
lines.push('Allow: runs without a prompt in a project that trusts its package.');
|
|
1183
1335
|
lines.push(`Run: ${view.command} run ${ref} [args]`);
|
|
1184
1336
|
if (!view.trusted(script.pkg))
|
|
1185
|
-
lines.push('', `⚠️ ${trustNote(script.pkg)}`);
|
|
1337
|
+
lines.push('', `⚠️ ${trustNote(view, script.pkg)}`);
|
|
1186
1338
|
return lines.join('\n');
|
|
1187
1339
|
}
|
|
1188
1340
|
/**
|
|
@@ -1192,7 +1344,7 @@ function scriptHelp(view, script) {
|
|
|
1192
1344
|
export function targetHelp(cwd, target, out) {
|
|
1193
1345
|
const view = helpView(cwd, out);
|
|
1194
1346
|
if (view === undefined)
|
|
1195
|
-
throw new HarnessError(`No command "${target}", and ${fromCaller(findProjectDir(cwd))} does not use harnesspm, so it has no packages, rules or tools.
|
|
1347
|
+
throw new HarnessError(`No command "${target}", and ${fromCaller(findProjectDir(cwd))} does not use harnesspm, so it has no packages, rules or tools. ${EVERY_COMMAND}.`);
|
|
1196
1348
|
const { res } = view;
|
|
1197
1349
|
const pkg = res.packages.find((p) => p.name === target || p.plugin === target);
|
|
1198
1350
|
const rules = pkg === undefined ? view.rules.filter((r) => r.id === target) : [];
|
|
@@ -1245,15 +1397,6 @@ export function approve(cwd, name, out) {
|
|
|
1245
1397
|
}
|
|
1246
1398
|
return sync(projectDir, out, { write: true });
|
|
1247
1399
|
}
|
|
1248
|
-
/** What to do after `new`. `why` and `sync` reach the project's own harness only where the project uses harnesspm. */
|
|
1249
|
-
function nextAfterNew(projectDir, added) {
|
|
1250
|
-
const npx = NPX_ANY;
|
|
1251
|
-
if (added)
|
|
1252
|
-
return `Next: edit it, run \`${npx} sync\`, then save the change the way that harness's own AGENTS.md or CONTRIBUTING.md says.`;
|
|
1253
|
-
if (isFile(path.join(projectDir, CONFIG_FILE)))
|
|
1254
|
-
return `Next: edit it, then run \`${npx} sync\` and \`${npx} check\`.`;
|
|
1255
|
-
return `Next: edit it, then run \`${npx} check\`. To see the harness in this repository's AGENTS.md too, run \`${npx} init\`.`;
|
|
1256
|
-
}
|
|
1257
1400
|
export function newUnit(cwd, kind, name, options, out) {
|
|
1258
1401
|
const projectDir = findProjectDir(cwd);
|
|
1259
1402
|
const show = (file) => (file.startsWith(projectDir + path.sep) ? relPosix(projectDir, file) : file);
|
|
@@ -1271,7 +1414,8 @@ export function newUnit(cwd, kind, name, options, out) {
|
|
|
1271
1414
|
out.log(`Wrote in ${target.label}:`);
|
|
1272
1415
|
for (const file of files)
|
|
1273
1416
|
out.log(` ${show(file)}`);
|
|
1274
|
-
|
|
1417
|
+
for (const line of nextAfterNew(projectDir, options.to !== undefined))
|
|
1418
|
+
out.log(line);
|
|
1275
1419
|
}
|
|
1276
1420
|
sync(projectDir, out, { quiet: true, write: true });
|
|
1277
1421
|
return 0;
|