@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/config.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import { type TelemetryConfig } from './telemetry.ts';
2
- export declare const CONFIG_FILE = "harnesspm.json";
3
- export declare const CONFIG_SCHEMA = "https://unpkg.com/@harnesspm/cli/schema/harnesspm.schema.json";
4
- export type TrustValue = true | 'pin';
5
- export interface ProjectConfig {
6
- exclude: string[];
7
- replace: Record<string, string>;
8
- patch: Record<string, string>;
9
- trust: Record<string, TrustValue>;
10
- /** Events and their handler (spec chapter 14). Undefined when telemetry is off. */
11
- telemetry?: TelemetryConfig;
12
- warnings: string[];
13
- }
14
- export declare function emptyConfig(): ProjectConfig;
15
- export declare function readConfig(projectDir: string): ProjectConfig;
package/dist/config.js DELETED
@@ -1,45 +0,0 @@
1
- // harnesspm.json (spec 3.7).
2
- import * as path from 'node:path';
3
- import { stringList } from './frontmatter.js';
4
- import { parseTelemetry } from './telemetry.js';
5
- import { HarnessError, PACKAGE_NAME, isRecord, readJsonIfExists } from './util.js';
6
- export const CONFIG_FILE = 'harnesspm.json';
7
- export const CONFIG_SCHEMA = `https://unpkg.com/${PACKAGE_NAME}/schema/harnesspm.schema.json`;
8
- const FIELDS = new Set(['$schema', 'exclude', 'replace', 'patch', 'trust', 'telemetry']);
9
- export function emptyConfig() {
10
- return { exclude: [], replace: {}, patch: {}, trust: {}, warnings: [] };
11
- }
12
- export function readConfig(projectDir) {
13
- const file = path.join(projectDir, CONFIG_FILE);
14
- const raw = readJsonIfExists(file) ?? {};
15
- if (!isRecord(raw))
16
- throw new HarnessError(`${file} must be a JSON object`);
17
- const warnings = [];
18
- for (const key of Object.keys(raw))
19
- if (!FIELDS.has(key))
20
- warnings.push(`${CONFIG_FILE}: unknown field "${key}"`);
21
- const map = (field) => {
22
- const value = raw[field];
23
- if (value === undefined)
24
- return {};
25
- if (isRecord(value) && Object.values(value).every((v) => typeof v === 'string'))
26
- return value;
27
- throw new HarnessError(`${CONFIG_FILE}: "${field}" must map strings to strings`);
28
- };
29
- const exclude = raw['exclude'] === undefined ? [] : stringList(raw['exclude']);
30
- if (!exclude)
31
- throw new HarnessError(`${CONFIG_FILE}: "exclude" must be an array of strings`);
32
- const trust = {};
33
- if (raw['trust'] !== undefined) {
34
- if (!isRecord(raw['trust']))
35
- throw new HarnessError(`${CONFIG_FILE}: "trust" must be an object`);
36
- for (const [name, value] of Object.entries(raw['trust'])) {
37
- if (value === true || value === 'pin')
38
- trust[name] = value;
39
- else
40
- throw new HarnessError(`${CONFIG_FILE}: trust for "${name}" must be true or "pin"`);
41
- }
42
- }
43
- const telemetry = parseTelemetry(raw['telemetry']);
44
- return { exclude, replace: map('replace'), patch: map('patch'), trust, ...(telemetry ? { telemetry } : {}), warnings };
45
- }
package/dist/deliver.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/dist/deliver.js DELETED
@@ -1,31 +0,0 @@
1
- // Runs a telemetry command handler in a detached process, once for each event (spec 14.3).
2
- // harnesspm starts it and does not wait. It passes the events, one per line, and the command in the environment.
3
- import { spawnSync } from 'node:child_process';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- const TIMEOUT = 10_000;
7
- const events = (process.env['HARNESSPM_EVENT'] ?? '').split('\n').filter((line) => line !== '');
8
- const command = process.env['HARNESSPM_HANDLER'] ?? '';
9
- const env = { ...process.env };
10
- delete env['HARNESSPM_EVENT'];
11
- delete env['HARNESSPM_HANDLER'];
12
- function note(message) {
13
- try {
14
- const dir = path.join(process.cwd(), 'node_modules', '.harnesspm');
15
- if (fs.existsSync(dir))
16
- fs.appendFileSync(path.join(dir, 'telemetry.log'), `${new Date().toISOString()} ${message.replace(/\s+/g, ' ').slice(0, 2000)}\n`);
17
- }
18
- catch {
19
- // Nobody is waiting for this process.
20
- }
21
- }
22
- for (const event of command !== '' ? events : []) {
23
- const result = spawnSync(command, { shell: true, input: `${event}\n`, env, stdio: ['pipe', 'ignore', 'pipe'], timeout: TIMEOUT, encoding: 'utf8' });
24
- // A handler that exits without reading the event closes stdin early, so writing it fails with EPIPE.
25
- // Its exit code still says how it went.
26
- const unread = result.error?.code === 'EPIPE' && result.status !== null;
27
- if (result.error && !unread)
28
- note(`handler \`${command}\`: ${result.error.message}`);
29
- else if (result.status !== 0)
30
- note(`handler \`${command}\` exited with ${result.status ?? result.signal}: ${result.stderr}`);
31
- }
package/dist/doctor.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export type Level = 'ok' | 'info' | 'warn' | 'fail';
2
- export interface Finding {
3
- level: Level;
4
- text: string;
5
- }
6
- export declare const formatFinding: (f: Finding) => string;
7
- /**
8
- * Checks that every per-machine file on disk is ignored by git and not tracked, so no commit can include it.
9
- * Git answers, so `.gitignore`, `.git/info/exclude` and a global excludes file all count.
10
- * `extra` adds project-relative files that harnesspm creates, such as a telemetry file. `sync` is the command that fixes them.
11
- * Undefined outside a git repository.
12
- */
13
- export declare function checkLocalFiles(projectDir: string, extra?: string[], sync?: string): {
14
- checked: number;
15
- problems: Finding[];
16
- } | undefined;
17
- /** Whether harnesspm can write the clone's exclude file, creating it if needed. */
18
- export declare function excludeWritable(file: string): boolean;
package/dist/doctor.js DELETED
@@ -1,99 +0,0 @@
1
- // `harnesspm doctor`: checks that a repository is ready for harnesses, its own and a person's (spec 10.1).
2
- // It reports and changes nothing. Each problem says the command that fixes it.
3
- import { spawnSync } from 'node:child_process';
4
- import * as fs from 'node:fs';
5
- import * as path from 'node:path';
6
- import { excludedBySync } from './outputs.js';
7
- import { NPX_ANY, excludeEntry, exists, gitExclude, isDir } from './util.js';
8
- const MARK = { ok: '✅', info: 'ℹ️ ', warn: '⚠️ ', fail: '❌' };
9
- export const formatFinding = (f) => ` ${MARK[f.level]} ${f.text}`;
10
- /** Per-machine files that agents or people create, besides the ones harnesspm lists in .git/info/exclude. */
11
- const PER_MACHINE = ['harnesspm.local.json', 'CLAUDE.local.md', '.claude/settings.local.json'];
12
- /** What a tracked per-machine file stops harnesspm from writing. */
13
- const BLOCKS = {
14
- 'CLAUDE.local.md': 'harnesspm writes no added harnesses into it',
15
- '.claude/settings.local.json': 'harnesspm writes no hooks or permissions there',
16
- };
17
- /** Git's output split on NUL. Exit code 1 means "no match" for both commands used here. `empty` keeps empty fields. */
18
- function git(projectDir, args, input, empty = false) {
19
- const result = spawnSync('git', args, { cwd: projectDir, encoding: 'utf8', ...(input !== undefined ? { input } : {}) });
20
- if (result.status !== 0 && result.status !== 1)
21
- return [];
22
- const fields = result.stdout.split('\0');
23
- return empty ? fields : fields.filter(Boolean);
24
- }
25
- const plain = (entry) => entry.replace(/^\/+/, '').replace(/\/+$/, '');
26
- /**
27
- * The pattern that decides each path, by `git check-ignore -v -n`, with the file it is in. A pattern that starts with `!`
28
- * brings the path back. A path that no pattern matches is not in the result.
29
- */
30
- function deciding(projectDir, paths) {
31
- const fields = paths.length > 0 ? git(projectDir, ['check-ignore', '-z', '-v', '-n', '--stdin'], `${paths.join('\0')}\0`, true) : [];
32
- const result = new Map();
33
- for (let i = 0; i + 3 < fields.length; i += 4) {
34
- const [source = '', , pattern = '', rel = ''] = fields.slice(i, i + 4);
35
- if (pattern !== '')
36
- result.set(rel, { source, pattern });
37
- }
38
- return result;
39
- }
40
- /**
41
- * Checks that every per-machine file on disk is ignored by git and not tracked, so no commit can include it.
42
- * Git answers, so `.gitignore`, `.git/info/exclude` and a global excludes file all count.
43
- * `extra` adds project-relative files that harnesspm creates, such as a telemetry file. `sync` is the command that fixes them.
44
- * Undefined outside a git repository.
45
- */
46
- export function checkLocalFiles(projectDir, extra = [], sync = `${NPX_ANY} sync`) {
47
- const exclude = gitExclude(projectDir);
48
- if (exclude === undefined)
49
- return undefined;
50
- const listed = new Set(excludedBySync(projectDir).map(plain));
51
- // `sync` lists these whenever they exist, so it fixes them too.
52
- const syncFixes = new Set([...listed, 'harnesspm.local.json', ...extra.map(plain)]);
53
- const candidates = [...new Set([...syncFixes, ...PER_MACHINE])].filter((rel) => rel !== '' && exists(path.join(projectDir, rel))).sort();
54
- if (candidates.length === 0)
55
- return { checked: 0, problems: [] };
56
- const tracked = git(projectDir, ['ls-files', '-z', '--', ...candidates]);
57
- const isTracked = (rel) => tracked.some((t) => t === rel || t.startsWith(`${rel}/`));
58
- const untracked = candidates.filter((rel) => !isTracked(rel));
59
- const decided = deciding(projectDir, untracked);
60
- const problems = [];
61
- for (const rel of candidates) {
62
- if (isTracked(rel)) {
63
- const blocks = BLOCKS[rel] !== undefined ? `, and ${BLOCKS[rel]}` : '';
64
- const flag = isDir(path.join(projectDir, rel)) && !fs.lstatSync(path.join(projectDir, rel)).isSymbolicLink() ? '-r ' : '';
65
- problems.push({ level: 'fail', text: `${rel} is tracked by git, so a commit can include this machine's files${blocks}. Run \`git rm ${flag}--cached ${rel}\` and commit.` });
66
- }
67
- else {
68
- const match = decided.get(rel);
69
- if (match !== undefined && !match.pattern.startsWith('!'))
70
- continue;
71
- // A project below the git root writes `/<folder>/<path>` into .git/info/exclude, and `/<path>` into its own .gitignore.
72
- const fix = match !== undefined
73
- ? `The pattern \`${match.pattern}\` in ${match.source} brings it back. Remove that pattern.`
74
- : syncFixes.has(rel)
75
- ? `Run \`${sync}\`, which lists it in .git/info/exclude.`
76
- : exclude.prefix === ''
77
- ? `Add \`/${rel}\` to .gitignore, or to .git/info/exclude for this clone only.`
78
- : `Add \`/${rel}\` to the .gitignore in ${exclude.prefix}, or \`${excludeEntry(exclude.prefix, rel)}\` to .git/info/exclude for this clone only.`;
79
- problems.push({ level: 'fail', text: `${rel} is not ignored by git, so \`git add\` can pick it up. ${fix}` });
80
- }
81
- }
82
- return { checked: candidates.length, problems };
83
- }
84
- /** Whether harnesspm can write the clone's exclude file, creating it if needed. */
85
- export function excludeWritable(file) {
86
- for (let p = file;; p = path.dirname(p)) {
87
- if (exists(p)) {
88
- try {
89
- fs.accessSync(p, fs.constants.W_OK);
90
- return true;
91
- }
92
- catch {
93
- return false;
94
- }
95
- }
96
- if (path.dirname(p) === p)
97
- return false;
98
- }
99
- }
@@ -1,75 +0,0 @@
1
- import type { Lock } from './lock.ts';
2
- import { type Resolution, type ResolvedPackage } from './resolve.ts';
3
- import { type Runner } from './util.ts';
4
- export type Group = 'team' | 'added';
5
- export interface TrustState {
6
- trusted: boolean;
7
- reason?: string;
8
- }
9
- /** Trust of a package's executable units (spec 6.2). The project and added harnesses are trusted. */
10
- export declare function trustOf(pkg: ResolvedPackage, res: Resolution, lock: Lock | undefined): TrustState;
11
- export interface HookEntry {
12
- event: string;
13
- matcher?: string;
14
- command: string;
15
- timeout?: number;
16
- /** Runs in the background: the agent does not wait for it (spec 14.4). */
17
- async?: boolean;
18
- }
19
- export interface ExecEntries {
20
- claude: {
21
- allow: string[];
22
- deny: string[];
23
- ask: string[];
24
- hooks: HookEntry[];
25
- mcp: Record<string, Record<string, unknown>>;
26
- };
27
- codex: {
28
- hooks: HookEntry[];
29
- rules: string[];
30
- mcp: Record<string, Record<string, unknown>>;
31
- };
32
- /** Sub-agent files: absolute path → content. */
33
- agentFiles: Map<string, string>;
34
- /** Executable units that are not written because their package is not trusted. */
35
- pending: string[];
36
- warnings: string[];
37
- }
38
- export declare function emptyEntries(): ExecEntries;
39
- export declare function tomlTables(prefix: string, tables: Record<string, Record<string, unknown>>): string;
40
- /**
41
- * The entries that `packages` ask for. `npx` lists the prefixes that the agent types: `npx -y @harnesspm/cli`, and
42
- * for a project's scripts also the bare `npx harnesspm`, which some packages' text still types. Allow rules use them, so they match the
43
- * command. `runner`
44
- * starts hooks and MCP servers, which nobody types, so it can start the installed CLI file, which is faster (spec 5.2).
45
- */
46
- export declare function desiredEntries(res: Resolution, packages: Set<ResolvedPackage>, trust: (pkg: ResolvedPackage) => TrustState, where: {
47
- claudeAgents: string;
48
- codexAgents: string;
49
- npx: (pkg: ResolvedPackage) => string[];
50
- runner: (pkg: ResolvedPackage) => Runner;
51
- }): ExecEntries;
52
- export interface Targets {
53
- claudeSettings: string;
54
- /** ~/.claude.json and, for local scope, the project key inside it. */
55
- claudeJson: string;
56
- claudeProject?: string;
57
- codexHooks: string;
58
- codexRules: string;
59
- stateFile: string;
60
- /** False when the repository tracks that agent's files, so harnesspm leaves them alone. */
61
- writeClaude?: boolean;
62
- writeCodex?: boolean;
63
- }
64
- export interface Applied {
65
- changed: string[];
66
- /** Entries a model run could not add (spec 6.2, rule 4). */
67
- held: string[];
68
- /** Codex MCP servers owned by every group, for the caller to write into a Codex config. */
69
- codexMcp: Record<string, Record<string, unknown>>;
70
- /** Files the outputs wrote, for .git/info/exclude. */
71
- files: string[];
72
- }
73
- /** The entries that a sync by the agent's model would hold back now, without writing anything. */
74
- export declare function heldEntries(group: Group, entries: ExecEntries, stateFile: string): string[];
75
- export declare function applyEntries(group: Group, entries: ExecEntries, targets: Targets, widen: boolean): Applied;