@harnesspm/cli 0.0.1 → 0.18.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 +275 -0
- package/LICENSE +1 -1
- package/README.md +71 -3
- 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 +230 -0
- package/dist/commands.d.ts +68 -0
- package/dist/commands.js +1441 -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 +77 -0
- package/dist/exec-outputs.js +426 -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/start.d.ts +18 -0
- package/dist/start.js +136 -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 +156 -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 +215 -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 +32 -0
- package/harness/skills/harnesspm-improve/SKILL.md +38 -0
- package/package.json +66 -11
- package/schema/harnesspm.schema.json +58 -0
- package/index.js +0 -4
package/dist/parent.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ExecEntries } from './exec-outputs.ts';
|
|
2
|
+
/** The first harnesspm whose CLI runs every hook of a parent folder: `-C <dir> track` is new in it. */
|
|
3
|
+
export declare const PARENT_HOOKS_SINCE = "0.11.0";
|
|
4
|
+
/** The projects right below `dir`: its subfolders with a harnesspm.json, as real paths. */
|
|
5
|
+
export declare function childProjects(dir: string): string[];
|
|
6
|
+
/**
|
|
7
|
+
* The git repositories right below a folder that may be a parent folder, as real paths, for the per-machine outputs of
|
|
8
|
+
* added harnesses (spec 4.10). A repository needs no harnesspm.json: an added harness's entry may target any.
|
|
9
|
+
*/
|
|
10
|
+
export declare function childRepos(dir: string): string[];
|
|
11
|
+
/** A parent folder: a candidate with projects right below it. */
|
|
12
|
+
export declare function isParentFolder(dir: string): boolean;
|
|
13
|
+
/** Whether a sync ran in `dir` as a parent folder, so a project's own sync keeps its entries there current. */
|
|
14
|
+
export declare function hasParentOutputs(dir: string): boolean;
|
|
15
|
+
/** Whether `dir` holds parent outputs to write or to clean up: projects below it now, or outputs of earlier ones. */
|
|
16
|
+
export declare function parentToSync(dir: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* The project's hooks as the parent folder runs them: the same events and matchers, with `-C <project>` after the runner.
|
|
19
|
+
* `runner` is the prefix that the project's own hook commands start with. Permissions, MCP servers and sub-agents stay in
|
|
20
|
+
* the project: they name commands and files that only work from there.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parentEntries(team: ExecEntries, projectDir: string, runner: string): ExecEntries;
|
|
23
|
+
export interface ParentResult {
|
|
24
|
+
changed: string[];
|
|
25
|
+
held: string[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Writes one project's hooks into the parent folder's agent settings. `widen` is false for a run by the agent's model:
|
|
29
|
+
* it keeps and removes hooks but adds none, also those the project's default branch records, because the parent folder
|
|
30
|
+
* is the person's and the project may be one the agent just cloned (spec 4.10, rule 4).
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeParent(parentDir: string, projectDir: string, team: ExecEntries, runner: string, widen: boolean): ParentResult;
|
|
33
|
+
/** Removes the entries of projects that are no longer below the parent folder. Removing grants nothing, so any run may. */
|
|
34
|
+
export declare function removeGone(parentDir: string, projects: string[]): string[];
|
|
35
|
+
/** The block that names each project below `parentDir` and how to reach its harness. Paths are absolute: the file is per machine. */
|
|
36
|
+
export declare function parentBlock(parentDir: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Writes the block in the parent folder's `AGENTS.md`, with the `@AGENTS.md` import that makes Claude Code read it, or
|
|
39
|
+
* removes both when no project is left below the folder.
|
|
40
|
+
*/
|
|
41
|
+
export declare function writePointer(parentDir: string): string[];
|
package/dist/parent.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Outputs for sessions that start in a parent folder (spec 4.10): a Claude Code cloud session with several
|
|
2
|
+
// repositories, a person's folder of clones, or a job runner's work folder. Agents read settings and instructions only
|
|
3
|
+
// from the folder a session starts in, so the projects' hooks and a pointer to their harness go there.
|
|
4
|
+
import { createHash } from 'node:crypto';
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import * as os from 'node:os';
|
|
7
|
+
import * as path from 'node:path';
|
|
8
|
+
import { applyEntries, emptyEntries } from './exec-outputs.js';
|
|
9
|
+
import { claudeJsonFile, harnesspmHome } from './homes.js';
|
|
10
|
+
import { claudeImport } from './outputs.js';
|
|
11
|
+
import { blockRange, CLAUDE_IMPORT, removeBlock, upsertBlock, wrapBlock } from './render.js';
|
|
12
|
+
import { NPX_ANY, compareVersions, gitExcludeFile, installedCli, isFile, isRecord, listDir, readJsonIfExists, readTextIfExists, realpath, shellWord, writeIfChanged } from './util.js';
|
|
13
|
+
const CONFIG_FILE = 'harnesspm.json';
|
|
14
|
+
/** The first harnesspm whose CLI runs every hook of a parent folder: `-C <dir> track` is new in it. */
|
|
15
|
+
export const PARENT_HOOKS_SINCE = '0.11.0';
|
|
16
|
+
const realOrSame = (p) => {
|
|
17
|
+
try {
|
|
18
|
+
return realpath(p);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return path.resolve(p);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** A path as one word of a hook command. Windows commands hold no shell-quoted path (spec 5.2). */
|
|
25
|
+
const commandWord = (p) => (process.platform === 'win32' ? (/[\s"]/.test(p) ? `"${p}"` : p) : shellWord(p));
|
|
26
|
+
/** The projects right below `dir`: its subfolders with a harnesspm.json, as real paths. */
|
|
27
|
+
export function childProjects(dir) {
|
|
28
|
+
return listDir(dir)
|
|
29
|
+
.filter((name) => !name.startsWith('.') && name !== 'node_modules' && isFile(path.join(dir, name, CONFIG_FILE)))
|
|
30
|
+
.map((name) => realOrSame(path.join(dir, name)));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A folder that may be a parent folder: not a project, not inside a git repository, and not the home folder, whose
|
|
34
|
+
* `.claude/` and `.codex/` hold the user-level settings of every session on the machine.
|
|
35
|
+
*/
|
|
36
|
+
function parentCandidate(dir) {
|
|
37
|
+
return realOrSame(dir) !== realOrSame(os.homedir()) && !isFile(path.join(dir, CONFIG_FILE)) && gitExcludeFile(dir) === undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The git repositories right below a folder that may be a parent folder, as real paths, for the per-machine outputs of
|
|
41
|
+
* added harnesses (spec 4.10). A repository needs no harnesspm.json: an added harness's entry may target any.
|
|
42
|
+
*/
|
|
43
|
+
export function childRepos(dir) {
|
|
44
|
+
if (!parentCandidate(dir))
|
|
45
|
+
return [];
|
|
46
|
+
return listDir(dir)
|
|
47
|
+
.filter((name) => !name.startsWith('.') && name !== 'node_modules' && fs.existsSync(path.join(dir, name, '.git')))
|
|
48
|
+
.map((name) => realOrSame(path.join(dir, name)));
|
|
49
|
+
}
|
|
50
|
+
/** A parent folder: a candidate with projects right below it. */
|
|
51
|
+
export function isParentFolder(dir) {
|
|
52
|
+
return parentCandidate(dir) && childProjects(dir).length > 0;
|
|
53
|
+
}
|
|
54
|
+
const slug = (dir) => `${path.basename(dir)}-${createHash('sha256').update(dir).digest('hex').slice(0, 8)}`;
|
|
55
|
+
/** The per-machine records of the parent folder's entries: one file per project, so projects never take each other's. */
|
|
56
|
+
const stateDir = (parentDir) => path.join(harnesspmHome(), 'state', 'parents', slug(realOrSame(parentDir)));
|
|
57
|
+
const hasBlock = (dir) => blockRange(readTextIfExists(path.join(dir, 'AGENTS.md'))) !== undefined;
|
|
58
|
+
/** Whether a sync ran in `dir` as a parent folder, so a project's own sync keeps its entries there current. */
|
|
59
|
+
export function hasParentOutputs(dir) {
|
|
60
|
+
return hasBlock(dir) && isParentFolder(dir);
|
|
61
|
+
}
|
|
62
|
+
/** Whether `dir` holds parent outputs to write or to clean up: projects below it now, or outputs of earlier ones. */
|
|
63
|
+
export function parentToSync(dir) {
|
|
64
|
+
return parentCandidate(dir) && (childProjects(dir).length > 0 || hasBlock(dir) || listDir(stateDir(dir)).length > 0);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* How a hook in the parent folder starts harnesspm for `projectDir`, with `-C`: the project's installed CLI file when it
|
|
68
|
+
* runs parent hooks, else npx. A newer harnesspm may sync the parent folder than the one the project installed.
|
|
69
|
+
*/
|
|
70
|
+
function parentRunner(projectDir) {
|
|
71
|
+
const cli = process.platform === 'win32' ? undefined : installedCli(projectDir);
|
|
72
|
+
const pkg = cli !== undefined ? readJsonIfExists(path.join(path.dirname(cli), '..', 'package.json')) : undefined;
|
|
73
|
+
const version = isRecord(pkg) && typeof pkg['version'] === 'string' ? pkg['version'] : undefined;
|
|
74
|
+
const local = version !== undefined && !version.includes('-') && compareVersions(version, PARENT_HOOKS_SINCE) >= 0;
|
|
75
|
+
return `${local ? `node ${shellWord(cli)}` : NPX_ANY} -C ${commandWord(projectDir)}`;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The project's hooks as the parent folder runs them: the same events and matchers, with `-C <project>` after the runner.
|
|
79
|
+
* `runner` is the prefix that the project's own hook commands start with. Permissions, MCP servers and sub-agents stay in
|
|
80
|
+
* the project: they name commands and files that only work from there.
|
|
81
|
+
*/
|
|
82
|
+
export function parentEntries(team, projectDir, runner) {
|
|
83
|
+
const entries = emptyEntries();
|
|
84
|
+
const prefix = parentRunner(projectDir);
|
|
85
|
+
const move = (hooks) => hooks.filter((h) => h.command.startsWith(`${runner} `)).map((h) => ({ ...h, command: `${prefix} ${h.command.slice(runner.length + 1)}` }));
|
|
86
|
+
entries.claude.hooks = move(team.claude.hooks);
|
|
87
|
+
entries.codex.hooks = move(team.codex.hooks);
|
|
88
|
+
return entries;
|
|
89
|
+
}
|
|
90
|
+
function parentTargets(parentDir, stateFile) {
|
|
91
|
+
return {
|
|
92
|
+
claudeSettings: path.join(parentDir, '.claude', 'settings.local.json'),
|
|
93
|
+
claudeJson: claudeJsonFile(),
|
|
94
|
+
codexHooks: path.join(parentDir, '.codex', 'hooks.json'),
|
|
95
|
+
codexRules: path.join(parentDir, '.codex', 'rules', 'harnesspm.rules'),
|
|
96
|
+
stateFile,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function pruneDirs(parentDir) {
|
|
100
|
+
for (const dir of [path.join(parentDir, '.codex', 'rules'), path.join(parentDir, '.codex'), path.join(parentDir, '.claude')]) {
|
|
101
|
+
try {
|
|
102
|
+
fs.rmdirSync(dir);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Not empty, or not there.
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Writes one project's hooks into the parent folder's agent settings. `widen` is false for a run by the agent's model:
|
|
111
|
+
* it keeps and removes hooks but adds none, also those the project's default branch records, because the parent folder
|
|
112
|
+
* is the person's and the project may be one the agent just cloned (spec 4.10, rule 4).
|
|
113
|
+
*/
|
|
114
|
+
export function writeParent(parentDir, projectDir, team, runner, widen) {
|
|
115
|
+
const stateFile = path.join(stateDir(parentDir), `${slug(projectDir)}.json`);
|
|
116
|
+
const applied = applyEntries('team', parentEntries(team, projectDir, runner), parentTargets(parentDir, stateFile), widen);
|
|
117
|
+
pruneDirs(parentDir);
|
|
118
|
+
return { changed: applied.changed, held: applied.held };
|
|
119
|
+
}
|
|
120
|
+
/** Removes the entries of projects that are no longer below the parent folder. Removing grants nothing, so any run may. */
|
|
121
|
+
export function removeGone(parentDir, projects) {
|
|
122
|
+
const dir = stateDir(parentDir);
|
|
123
|
+
const keep = new Set(projects.map((p) => `${slug(p)}.json`));
|
|
124
|
+
const changed = [];
|
|
125
|
+
for (const name of listDir(dir)) {
|
|
126
|
+
if (!name.endsWith('.json') || keep.has(name))
|
|
127
|
+
continue;
|
|
128
|
+
const file = path.join(dir, name);
|
|
129
|
+
changed.push(...applyEntries('team', emptyEntries(), parentTargets(parentDir, file), false).changed);
|
|
130
|
+
fs.rmSync(file, { force: true });
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
fs.rmdirSync(dir);
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Projects remain, or it was never there.
|
|
137
|
+
}
|
|
138
|
+
pruneDirs(parentDir);
|
|
139
|
+
return changed;
|
|
140
|
+
}
|
|
141
|
+
/** The block that names each project below `parentDir` and how to reach its harness. Paths are absolute: the file is per machine. */
|
|
142
|
+
export function parentBlock(parentDir) {
|
|
143
|
+
const lines = childProjects(parentDir).map((dir) => `- \`${path.basename(dir)}\`: \`${dir}\`. Rules: \`${path.join(dir, 'AGENTS.md')}\`. Its harness: \`${NPX_ANY} -C ${commandWord(dir)} help\`.`);
|
|
144
|
+
return wrapBlock([
|
|
145
|
+
'## Repositories with a harness',
|
|
146
|
+
'',
|
|
147
|
+
'A session that starts in this folder does not load the agent rules of the repositories below it. Before you change files in one, read its `AGENTS.md`, and the `AGENTS.md` of the folder you change. `help` lists its rules, docs, skills and tools; run a tool with `-C <path> run <tool> [args]`.',
|
|
148
|
+
'',
|
|
149
|
+
...lines,
|
|
150
|
+
].join('\n'));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Writes the block in the parent folder's `AGENTS.md`, with the `@AGENTS.md` import that makes Claude Code read it, or
|
|
154
|
+
* removes both when no project is left below the folder.
|
|
155
|
+
*/
|
|
156
|
+
export function writePointer(parentDir) {
|
|
157
|
+
const changed = [];
|
|
158
|
+
const agentsFile = path.join(parentDir, 'AGENTS.md');
|
|
159
|
+
const claudeFile = path.join(parentDir, 'CLAUDE.md');
|
|
160
|
+
if (childProjects(parentDir).length > 0) {
|
|
161
|
+
if (writeIfChanged(agentsFile, upsertBlock(readTextIfExists(agentsFile), parentBlock(parentDir))))
|
|
162
|
+
changed.push(agentsFile);
|
|
163
|
+
const claude = claudeImport(parentDir);
|
|
164
|
+
if (writeIfChanged(claude.file, claude.text))
|
|
165
|
+
changed.push(claude.file);
|
|
166
|
+
return changed;
|
|
167
|
+
}
|
|
168
|
+
if (!hasBlock(parentDir))
|
|
169
|
+
return changed;
|
|
170
|
+
const rest = removeBlock(readTextIfExists(agentsFile));
|
|
171
|
+
if (rest === undefined)
|
|
172
|
+
fs.rmSync(agentsFile, { force: true });
|
|
173
|
+
else
|
|
174
|
+
writeIfChanged(agentsFile, rest);
|
|
175
|
+
changed.push(agentsFile);
|
|
176
|
+
// The import that sync added, when the file holds nothing else.
|
|
177
|
+
if ((readTextIfExists(claudeFile) ?? '').trim() === CLAUDE_IMPORT && rest === undefined) {
|
|
178
|
+
fs.rmSync(claudeFile, { force: true });
|
|
179
|
+
changed.push(claudeFile);
|
|
180
|
+
}
|
|
181
|
+
return changed;
|
|
182
|
+
}
|
package/dist/render.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { FinalRule, Resolution, ResolvedPackage } from './resolve.ts';
|
|
2
|
+
export declare const BLOCK_BEGIN = "<!-- BEGIN:harnesspm \u2014 generated by `harnesspm sync`. Do not edit. To change a rule, run `npx -y @harnesspm/cli why <ID>`. -->";
|
|
3
|
+
export declare const BLOCK_END = "<!-- END:harnesspm -->";
|
|
4
|
+
/** Paths that outputs use for a rule file and a docs index. */
|
|
5
|
+
export interface PathFor {
|
|
6
|
+
rule(rule: FinalRule): string;
|
|
7
|
+
docsIndex(pkg: ResolvedPackage): string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface Section {
|
|
10
|
+
heading: string;
|
|
11
|
+
/** What `help <package>` takes for this package: its npm name, or the plugin name of an added harness (spec 10.1). */
|
|
12
|
+
target: string;
|
|
13
|
+
rules: FinalRule[];
|
|
14
|
+
docsIndex?: {
|
|
15
|
+
path: string;
|
|
16
|
+
id: string;
|
|
17
|
+
};
|
|
18
|
+
/** Lines before the rules, such as a note on what the section changes. */
|
|
19
|
+
intro?: string[];
|
|
20
|
+
/** Script lines: scripts the agent may run, with their command. */
|
|
21
|
+
scripts?: string[];
|
|
22
|
+
/** Lines about hooks that change how the agent should work, such as hooks that check file edits. */
|
|
23
|
+
hooks?: string[];
|
|
24
|
+
/** More pointer lines, such as the MCP servers and skills that `help` lists. */
|
|
25
|
+
extra?: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function packageHeading(pkg: ResolvedPackage): string;
|
|
28
|
+
/** A rule's text without its frontmatter and its `#` title. */
|
|
29
|
+
export declare const ruleBodyWithoutTitle: (rule: FinalRule) => string;
|
|
30
|
+
export declare function alwaysOnText(rule: FinalRule, label?: string): string;
|
|
31
|
+
export declare function pointerLine(rule: FinalRule, file: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* The summary of a rule in a compact block (spec 4.6): its `description`, else its `##` and `###` section headings.
|
|
34
|
+
* The title is on the line already.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ruleSummary(rule: FinalRule): string;
|
|
37
|
+
/** An always-on rule in a compact block: one line, and `help <package>` prints its text (spec 4.6). */
|
|
38
|
+
export declare function alwaysOnLine(rule: FinalRule, target: string): string;
|
|
39
|
+
/**
|
|
40
|
+
* The text of sections. `compact` gives each always-on rule one line, as committed blocks do: `help <package>` prints
|
|
41
|
+
* the text (spec 4.6). Without it, the text is inlined, as in `CLAUDE.local.md` and user-level blocks.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renderSections(sections: Section[], paths: PathFor, options?: {
|
|
44
|
+
compact?: boolean;
|
|
45
|
+
}): string;
|
|
46
|
+
/** What `help` takes to name a package: the npm name, or the plugin name of an added harness. */
|
|
47
|
+
export declare const helpTarget: (pkg: ResolvedPackage) => string;
|
|
48
|
+
/**
|
|
49
|
+
* `runPrefix` returns the command prefix for a trusted package's scripts, or undefined to list none. `compact` lists a
|
|
50
|
+
* script as a tool by its name, without the command: the commands at the top of the block say how to run it (spec 4.6).
|
|
51
|
+
*/
|
|
52
|
+
export declare function sectionsFor(res: Resolution, packages: ResolvedPackage[], paths: PathFor, runPrefix?: (pkg: ResolvedPackage) => string | undefined, options?: {
|
|
53
|
+
compact?: boolean;
|
|
54
|
+
rules?: FinalRule[];
|
|
55
|
+
includeOtherUnits?: (pkg: ResolvedPackage) => boolean;
|
|
56
|
+
}): Section[];
|
|
57
|
+
/**
|
|
58
|
+
* The root block's pointer to workspace blocks (spec 4.5). Claude Code loads a workspace's block only when the agent
|
|
59
|
+
* opens a file there with its file tools, and Codex only when it starts in that folder, so the always-on root names them.
|
|
60
|
+
*/
|
|
61
|
+
export declare function workspacesSection(keys: string[]): string | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The commands at the top of a committed block with units (spec 4.6). The lines below name rules and tools only, so
|
|
64
|
+
* the agent learns here how to get a rule's text, a tool's options, and how to run a tool, also from another folder
|
|
65
|
+
* such as a repository that cloned this one (spec 10.1, `-C`).
|
|
66
|
+
*/
|
|
67
|
+
export declare const COMMAND_LINES: string;
|
|
68
|
+
/**
|
|
69
|
+
* A blank line after BEGIN and before END keeps Markdown formatters such as Prettier from changing the block (spec 4.6).
|
|
70
|
+
* `commands` puts the command lines first.
|
|
71
|
+
*/
|
|
72
|
+
export declare function wrapBlock(content: string, commands?: boolean): string;
|
|
73
|
+
/** The committed block: the dependency and project layers, compact. */
|
|
74
|
+
export declare function renderBlock(res: Resolution, paths: PathFor, runPrefix?: (pkg: ResolvedPackage) => string | undefined): string;
|
|
75
|
+
/** Puts the block into a Markdown file. Text outside the block never changes. */
|
|
76
|
+
export declare function upsertBlock(existing: string | undefined, block: string): string;
|
|
77
|
+
/** Removes the block. Returns undefined when nothing else is left in the file. */
|
|
78
|
+
export declare function removeBlock(existing: string | undefined, leftover?: RegExp): string | undefined;
|
|
79
|
+
/** Where the block is in `text`: the index of its BEGIN marker and the index just after its END marker. */
|
|
80
|
+
export declare function blockRange(text: string | undefined): [number, number] | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* The block in `text`, for comparison. Blank lines next to the markers are dropped, so a block that harnesspm 0.3
|
|
83
|
+
* wrote without them, or one that a formatter changed, compares equal to the current form.
|
|
84
|
+
*/
|
|
85
|
+
export declare function extractBlock(text: string | undefined): string | undefined;
|
|
86
|
+
export declare const CLAUDE_IMPORT = "@AGENTS.md";
|
|
87
|
+
/** Whether `text` has `line`, such as `@AGENTS.md` or `@../AGENTS.md`, on a line of its own. */
|
|
88
|
+
export declare function hasClaudeImport(text: string | undefined, line?: string): boolean;
|
|
89
|
+
export declare function withClaudeImport(existing: string | undefined): string;
|
|
90
|
+
/** TOML basic multi-line string. */
|
|
91
|
+
export declare function tomlString(text: string): string;
|
package/dist/render.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Managed blocks (spec 4.6): AGENTS.md for the team, CLAUDE.local.md and user-level files for added harnesses.
|
|
2
|
+
import { demoteHeadings, headings } from './sections.js';
|
|
3
|
+
import { NPX_ANY } from './util.js';
|
|
4
|
+
export const BLOCK_BEGIN = `<!-- BEGIN:harnesspm — generated by \`harnesspm sync\`. Do not edit. To change a rule, run \`${NPX_ANY} why <ID>\`. -->`;
|
|
5
|
+
export const BLOCK_END = '<!-- END:harnesspm -->';
|
|
6
|
+
const BEGIN_PREFIX = '<!-- BEGIN:harnesspm';
|
|
7
|
+
function withoutTitle(body) {
|
|
8
|
+
const lines = body.split('\n');
|
|
9
|
+
const first = headings(lines)[0];
|
|
10
|
+
if (first && first.level === 1)
|
|
11
|
+
lines.splice(first.line, 1);
|
|
12
|
+
return lines.join('\n').trim();
|
|
13
|
+
}
|
|
14
|
+
export function packageHeading(pkg) {
|
|
15
|
+
if (pkg.layer === 'project')
|
|
16
|
+
return `## ${pkg.name} (this project)`;
|
|
17
|
+
if (pkg.layer === 'added') {
|
|
18
|
+
const spec = pkg.added?.source.spec ?? pkg.name;
|
|
19
|
+
if (pkg.entry)
|
|
20
|
+
return `## ${pkg.plugin}: entry for this repository (${spec})`;
|
|
21
|
+
return `## ${pkg.plugin} (${spec}, ${pkg.scope} scope)`;
|
|
22
|
+
}
|
|
23
|
+
// No version: a bump that keeps the harness the same changes no committed Markdown. The lock records it (spec 4.6).
|
|
24
|
+
return `## ${pkg.name}${pkg.via !== undefined ? ` (via ${pkg.via})` : ''}`;
|
|
25
|
+
}
|
|
26
|
+
/** A rule's text without its frontmatter and its `#` title. */
|
|
27
|
+
export const ruleBodyWithoutTitle = (rule) => withoutTitle(rule.body);
|
|
28
|
+
export function alwaysOnText(rule, label = rule.id) {
|
|
29
|
+
const body = demoteHeadings(withoutTitle(rule.body), 2);
|
|
30
|
+
return `### ${rule.title} (${label})${body !== '' ? `\n\n${body}` : ''}`;
|
|
31
|
+
}
|
|
32
|
+
export function pointerLine(rule, file) {
|
|
33
|
+
if (rule.activation === 'file') {
|
|
34
|
+
// A leading `/` anchors a pattern at the project root (spec 2.5). Readers of a pointer line take paths from the root anyway.
|
|
35
|
+
const globs = (rule.paths ?? []).map((p) => `\`${p.replace(/^\/(?!\/)/, '')}\``).join(', ');
|
|
36
|
+
const description = rule.description !== undefined ? ` — ${rule.description}` : '';
|
|
37
|
+
return `- When editing ${globs}, read ${file}${description} (${rule.id})`;
|
|
38
|
+
}
|
|
39
|
+
return `- ${rule.description}: read ${file} (${rule.id})`;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The summary of a rule in a compact block (spec 4.6): its `description`, else its `##` and `###` section headings.
|
|
43
|
+
* The title is on the line already.
|
|
44
|
+
*/
|
|
45
|
+
export function ruleSummary(rule) {
|
|
46
|
+
if (rule.description !== undefined && rule.description.trim() !== '')
|
|
47
|
+
return rule.description.trim();
|
|
48
|
+
return headings(withoutTitle(rule.body).split('\n'))
|
|
49
|
+
.filter((h) => h.level === 2 || h.level === 3)
|
|
50
|
+
.map((h) => h.text)
|
|
51
|
+
.join(', ');
|
|
52
|
+
}
|
|
53
|
+
/** An always-on rule in a compact block: one line, and `help <package>` prints its text (spec 4.6). */
|
|
54
|
+
export function alwaysOnLine(rule, target) {
|
|
55
|
+
const summary = ruleSummary(rule);
|
|
56
|
+
return `- Always-on rule: ${rule.title}${summary !== '' ? ` — ${summary}` : ''}. Read it with \`help ${target}\` (${rule.id})`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The text of sections. `compact` gives each always-on rule one line, as committed blocks do: `help <package>` prints
|
|
60
|
+
* the text (spec 4.6). Without it, the text is inlined, as in `CLAUDE.local.md` and user-level blocks.
|
|
61
|
+
*/
|
|
62
|
+
export function renderSections(sections, paths, options = {}) {
|
|
63
|
+
const out = [];
|
|
64
|
+
for (const section of sections) {
|
|
65
|
+
const parts = [section.heading, ...(section.intro ?? [])];
|
|
66
|
+
const always = section.rules.filter((r) => r.activation === 'always');
|
|
67
|
+
if (!options.compact)
|
|
68
|
+
for (const rule of always)
|
|
69
|
+
parts.push(alwaysOnText(rule));
|
|
70
|
+
const pointers = options.compact ? always.map((r) => alwaysOnLine(r, section.target)) : [];
|
|
71
|
+
pointers.push(...section.rules.filter((r) => r.activation !== 'always').map((r) => pointerLine(r, paths.rule(r))));
|
|
72
|
+
if (section.docsIndex)
|
|
73
|
+
pointers.push(`- Docs: ${section.docsIndex.path} (${section.docsIndex.id})`);
|
|
74
|
+
pointers.push(...(section.scripts ?? []), ...(section.hooks ?? []), ...(section.extra ?? []));
|
|
75
|
+
if (pointers.length > 0)
|
|
76
|
+
parts.push(pointers.join('\n'));
|
|
77
|
+
if (parts.length > 1)
|
|
78
|
+
out.push(parts.join('\n\n'));
|
|
79
|
+
}
|
|
80
|
+
return out.join('\n\n');
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether a hook matcher matches a tool name, as each agent reads it (research/agent-capabilities.md). Claude Code:
|
|
84
|
+
* letters, digits, `_`, `-`, spaces, `,` and `|` make a list of exact names; anything else is a regular expression.
|
|
85
|
+
* Codex: always a regular expression. Both match anywhere in the name.
|
|
86
|
+
*/
|
|
87
|
+
function matcherHits(agent, matcher, tool) {
|
|
88
|
+
if (agent === 'claude' && /^[\w\s,|-]*$/.test(matcher))
|
|
89
|
+
return matcher.split(/[|,]/).some((name) => name.trim() === tool);
|
|
90
|
+
try {
|
|
91
|
+
return new RegExp(matcher).test(tool);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** File-edit tools: Claude Code's, and the names that Codex matches for its `apply_patch` edits. */
|
|
98
|
+
const EDIT_TOOLS = { claude: ['Edit', 'Write', 'MultiEdit'], codex: ['apply_patch', 'Edit', 'Write'] };
|
|
99
|
+
/** A hook that runs on the agent's file edits. An edit through a shell command, such as `sed`, skips it. */
|
|
100
|
+
function checksEdits(hook) {
|
|
101
|
+
if (hook.event !== 'PreToolUse' && hook.event !== 'PostToolUse')
|
|
102
|
+
return false;
|
|
103
|
+
return ['claude', 'codex'].some((agent) => {
|
|
104
|
+
const matcher = hook.matchers[agent];
|
|
105
|
+
return matcher !== undefined && matcher !== '' && matcher !== '*' && EDIT_TOOLS[agent].some((tool) => matcherHits(agent, matcher, tool));
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/** What `help` takes to name a package: the npm name, or the plugin name of an added harness. */
|
|
109
|
+
export const helpTarget = (pkg) => (pkg.layer === 'added' ? pkg.plugin : pkg.name);
|
|
110
|
+
/**
|
|
111
|
+
* `runPrefix` returns the command prefix for a trusted package's scripts, or undefined to list none. `compact` lists a
|
|
112
|
+
* script as a tool by its name, without the command: the commands at the top of the block say how to run it (spec 4.6).
|
|
113
|
+
*/
|
|
114
|
+
export function sectionsFor(res, packages, paths, runPrefix = () => undefined, options = {}) {
|
|
115
|
+
return packages.map((pkg) => {
|
|
116
|
+
const other = options.includeOtherUnits?.(pkg) ?? true;
|
|
117
|
+
const index = other ? paths.docsIndex(pkg) : undefined;
|
|
118
|
+
const prefix = other ? runPrefix(pkg) : undefined;
|
|
119
|
+
const line = (s) => options.compact ? `- Tool: \`${pkg.plugin}:${s.name}\` — ${s.description} (${s.id})` : `- Script: \`${prefix} run ${pkg.plugin}:${s.name}\` — ${s.description} (${s.id})`;
|
|
120
|
+
const scripts = prefix === undefined ? [] : res.scripts.filter((s) => s.pkg === pkg && s.description !== undefined).map(line);
|
|
121
|
+
// Only a trusted package's hooks run, so only they get a line, like scripts.
|
|
122
|
+
const editHooks = prefix === undefined ? [] : res.hooks.filter((h) => h.pkg === pkg && checksEdits(h)).map((h) => h.id);
|
|
123
|
+
const hooks = editHooks.length > 0 ? [`- Edit files with your file tools, not shell commands such as \`sed\`, so the hook that checks each edit runs (${editHooks.join(', ')})`] : [];
|
|
124
|
+
return {
|
|
125
|
+
heading: packageHeading(pkg),
|
|
126
|
+
target: helpTarget(pkg),
|
|
127
|
+
rules: (options.rules ?? res.rules).filter((r) => r.pkg === pkg),
|
|
128
|
+
...(index !== undefined ? { docsIndex: { path: index, id: `${pkg.plugin}:docs` } } : {}),
|
|
129
|
+
...(scripts.length > 0 ? { scripts } : {}),
|
|
130
|
+
...(hooks.length > 0 ? { hooks } : {}),
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The root block's pointer to workspace blocks (spec 4.5). Claude Code loads a workspace's block only when the agent
|
|
136
|
+
* opens a file there with its file tools, and Codex only when it starts in that folder, so the always-on root names them.
|
|
137
|
+
*/
|
|
138
|
+
export function workspacesSection(keys) {
|
|
139
|
+
if (keys.length === 0)
|
|
140
|
+
return undefined;
|
|
141
|
+
const list = keys.map((k) => `\`${k}\``).join(', ');
|
|
142
|
+
return `## Workspaces\n\nThese folders have harness rules of their own in their \`AGENTS.md\`: ${list}. Read a folder's \`AGENTS.md\` before you change files in it.`;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* The commands at the top of a committed block with units (spec 4.6). The lines below name rules and tools only, so
|
|
146
|
+
* the agent learns here how to get a rule's text, a tool's options, and how to run a tool, also from another folder
|
|
147
|
+
* such as a repository that cloned this one (spec 10.1, `-C`).
|
|
148
|
+
*/
|
|
149
|
+
export const COMMAND_LINES = [
|
|
150
|
+
`- Every package of this harness: \`${NPX_ANY} help\`. A package's rules and tools in full: \`${NPX_ANY} help <package>\`.`,
|
|
151
|
+
`- Run a tool: \`${NPX_ANY} run <tool> [args]\`. Its options: \`${NPX_ANY} help <tool>\`.`,
|
|
152
|
+
`- From outside this folder, add \`-C <path to this folder>\` before \`help\` or \`run\`.`,
|
|
153
|
+
].join('\n');
|
|
154
|
+
/**
|
|
155
|
+
* A blank line after BEGIN and before END keeps Markdown formatters such as Prettier from changing the block (spec 4.6).
|
|
156
|
+
* `commands` puts the command lines first.
|
|
157
|
+
*/
|
|
158
|
+
export function wrapBlock(content, commands = false) {
|
|
159
|
+
return `${BLOCK_BEGIN}\n\n${commands ? `${COMMAND_LINES}\n\n` : ''}${content}\n\n${BLOCK_END}`;
|
|
160
|
+
}
|
|
161
|
+
/** The committed block: the dependency and project layers, compact. */
|
|
162
|
+
export function renderBlock(res, paths, runPrefix) {
|
|
163
|
+
const content = renderSections(sectionsFor(res, res.packages, paths, runPrefix, { compact: true }), paths, { compact: true });
|
|
164
|
+
return content !== '' ? wrapBlock(content, true) : wrapBlock('No harness units yet.');
|
|
165
|
+
}
|
|
166
|
+
/** Puts the block into a Markdown file. Text outside the block never changes. */
|
|
167
|
+
export function upsertBlock(existing, block) {
|
|
168
|
+
if (existing === undefined || existing.trim() === '')
|
|
169
|
+
return `${block}\n`;
|
|
170
|
+
const range = blockRange(existing);
|
|
171
|
+
if (range)
|
|
172
|
+
return existing.slice(0, range[0]) + block + existing.slice(range[1]);
|
|
173
|
+
return `${existing.replace(/\s+$/, '')}\n\n${block}\n`;
|
|
174
|
+
}
|
|
175
|
+
/** Removes the block. Returns undefined when nothing else is left in the file. */
|
|
176
|
+
export function removeBlock(existing, leftover = /^\s*$/) {
|
|
177
|
+
if (existing === undefined)
|
|
178
|
+
return undefined;
|
|
179
|
+
const range = blockRange(existing);
|
|
180
|
+
const rest = range ? existing.slice(0, range[0]).replace(/\s+$/, '') + existing.slice(range[1]) : existing;
|
|
181
|
+
if (leftover.test(rest))
|
|
182
|
+
return undefined;
|
|
183
|
+
return `${rest.replace(/\s+$/, '')}\n`;
|
|
184
|
+
}
|
|
185
|
+
/** Where the block is in `text`: the index of its BEGIN marker and the index just after its END marker. */
|
|
186
|
+
export function blockRange(text) {
|
|
187
|
+
if (text === undefined)
|
|
188
|
+
return undefined;
|
|
189
|
+
const start = text.indexOf(BEGIN_PREFIX);
|
|
190
|
+
const end = text.indexOf(BLOCK_END, start);
|
|
191
|
+
return start >= 0 && end > start ? [start, end + BLOCK_END.length] : undefined;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The block in `text`, for comparison. Blank lines next to the markers are dropped, so a block that harnesspm 0.3
|
|
195
|
+
* wrote without them, or one that a formatter changed, compares equal to the current form.
|
|
196
|
+
*/
|
|
197
|
+
export function extractBlock(text) {
|
|
198
|
+
const range = blockRange(text);
|
|
199
|
+
if (!range)
|
|
200
|
+
return undefined;
|
|
201
|
+
return text
|
|
202
|
+
.slice(range[0], range[1])
|
|
203
|
+
.replace(/^([^\n]*-->)\n(?:[ \t]*\n)+/, '$1\n')
|
|
204
|
+
.replace(/\n(?:[ \t]*\n)+(<!-- END:harnesspm -->)$/, '\n$1');
|
|
205
|
+
}
|
|
206
|
+
export const CLAUDE_IMPORT = '@AGENTS.md';
|
|
207
|
+
/** Whether `text` has `line`, such as `@AGENTS.md` or `@../AGENTS.md`, on a line of its own. */
|
|
208
|
+
export function hasClaudeImport(text, line = CLAUDE_IMPORT) {
|
|
209
|
+
return text !== undefined && text.split('\n').some((l) => l.trimEnd() === line);
|
|
210
|
+
}
|
|
211
|
+
export function withClaudeImport(existing) {
|
|
212
|
+
if (existing === undefined || existing.trim() === '')
|
|
213
|
+
return `${CLAUDE_IMPORT}\n`;
|
|
214
|
+
if (hasClaudeImport(existing))
|
|
215
|
+
return existing;
|
|
216
|
+
return `${CLAUDE_IMPORT}\n\n${existing}`;
|
|
217
|
+
}
|
|
218
|
+
/** TOML basic multi-line string. */
|
|
219
|
+
export function tomlString(text) {
|
|
220
|
+
return `"""\n${text.replace(/\\/g, '\\\\').replace(/"""/g, '""\\"')}\n"""`;
|
|
221
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AddedHarness, Scope } from './added.ts';
|
|
2
|
+
import { type ProjectConfig } from './config.ts';
|
|
3
|
+
import { type DocsSource, type HarnessPackage, type RuleMeta, type SkillSource } from './manifest.ts';
|
|
4
|
+
import { type AgentUnit, type HookUnit, type McpUnit, type PermissionsUnit, type ScriptUnit } from './exec-units.ts';
|
|
5
|
+
import { type TouchedSection } from './sections.ts';
|
|
6
|
+
export interface ResolvedPackage extends HarnessPackage {
|
|
7
|
+
/** The package whose `extends` brought this one in, when it is not a direct dependency. */
|
|
8
|
+
via?: string;
|
|
9
|
+
direct: boolean;
|
|
10
|
+
/** Names of the packages this one passes on through `extends`, transitively. */
|
|
11
|
+
closure: Set<string>;
|
|
12
|
+
/** For an added harness: its scope and source. */
|
|
13
|
+
scope?: Scope;
|
|
14
|
+
added?: AddedHarness;
|
|
15
|
+
/** True for an added harness's entry for this repository. */
|
|
16
|
+
entry?: boolean;
|
|
17
|
+
/** Workspaces whose dependencies reach this package: "" for the repository root, else the workspace's path. */
|
|
18
|
+
members: Set<string>;
|
|
19
|
+
}
|
|
20
|
+
export interface ResolveOptions {
|
|
21
|
+
/** Added harnesses to put on top, in order. */
|
|
22
|
+
added?: AddedHarness[];
|
|
23
|
+
/** Resolve the dependency and project layers. False when they are not installed or not used. */
|
|
24
|
+
team?: boolean;
|
|
25
|
+
/** Where to find a package that is not installed, such as one `harnesspm fetch` downloaded. */
|
|
26
|
+
locate?: (name: string) => string | undefined;
|
|
27
|
+
}
|
|
28
|
+
export interface Workspace {
|
|
29
|
+
/** Path from the repository root, with forward slashes. */
|
|
30
|
+
key: string;
|
|
31
|
+
dir: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Override {
|
|
34
|
+
kind: 'exclude' | 'replace' | 'patch';
|
|
35
|
+
target: string;
|
|
36
|
+
/** Absolute path of the replacement or patch file. */
|
|
37
|
+
file?: string;
|
|
38
|
+
/** Who declared it: a package name or `harnesspm.json`. */
|
|
39
|
+
by: string;
|
|
40
|
+
/** The package that declared it. Undefined for `harnesspm.json`. */
|
|
41
|
+
from?: ResolvedPackage;
|
|
42
|
+
/** Lower numbers come from lower layers, or from packages further upstream. */
|
|
43
|
+
order: number;
|
|
44
|
+
scope: Set<string> | 'all';
|
|
45
|
+
}
|
|
46
|
+
export interface AppliedPatch {
|
|
47
|
+
/** Patch file, relative to the project. */
|
|
48
|
+
patch: string;
|
|
49
|
+
by: string;
|
|
50
|
+
sections: TouchedSection[];
|
|
51
|
+
}
|
|
52
|
+
export interface FinalRule extends RuleMeta {
|
|
53
|
+
id: string;
|
|
54
|
+
name: string;
|
|
55
|
+
pkg: ResolvedPackage;
|
|
56
|
+
/** The rule's own file. */
|
|
57
|
+
original: string;
|
|
58
|
+
/** The file the text comes from: the original or a replacement. */
|
|
59
|
+
source: string;
|
|
60
|
+
/** Final text, with frontmatter, after replace and patches. */
|
|
61
|
+
text: string;
|
|
62
|
+
replacedBy?: Override;
|
|
63
|
+
patches: AppliedPatch[];
|
|
64
|
+
/** Where this version of the rule applies. The empty key is the repository root. */
|
|
65
|
+
members: Set<string>;
|
|
66
|
+
/** More than one override sequence applies to this rule. */
|
|
67
|
+
variant: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface FinalSkill extends SkillSource {
|
|
70
|
+
pkg: ResolvedPackage;
|
|
71
|
+
/** The skill's own folder. `dir` is the folder in use: this one, or a replacement. */
|
|
72
|
+
original: string;
|
|
73
|
+
replacedBy?: Override;
|
|
74
|
+
replacementConflict?: string;
|
|
75
|
+
}
|
|
76
|
+
export declare function rulesById(rules: FinalRule[]): Map<string, FinalRule[]>;
|
|
77
|
+
/** Inside a workspace, select its rules. At the root, include workspace-only rules in the repository overview. */
|
|
78
|
+
export declare function rulesForDirectory(res: Resolution, dir: string): FinalRule[];
|
|
79
|
+
export declare const describeMembers: (members: Set<string>) => string;
|
|
80
|
+
/** Changes to the team's rule text on this machine, with the affected members of each version. */
|
|
81
|
+
export declare function localRuleChanges(team: Resolution, full: Resolution): {
|
|
82
|
+
id: string;
|
|
83
|
+
changed?: FinalRule;
|
|
84
|
+
members: Set<string>;
|
|
85
|
+
}[];
|
|
86
|
+
/**
|
|
87
|
+
* The package whose files a skill uses: the one whose `replace` put them in the skill's place, else its own. Trust
|
|
88
|
+
* follows these files (spec 6.1). Undefined when `harnesspm.json` replaced the skill with a file of the project.
|
|
89
|
+
*/
|
|
90
|
+
export declare const skillAuthor: (skill: FinalSkill) => ResolvedPackage | undefined;
|
|
91
|
+
export interface FinalDocs extends DocsSource {
|
|
92
|
+
pkg: ResolvedPackage;
|
|
93
|
+
}
|
|
94
|
+
type WithPkg<T> = Omit<T, 'pkg'> & {
|
|
95
|
+
pkg: ResolvedPackage;
|
|
96
|
+
};
|
|
97
|
+
export type FinalScript = WithPkg<ScriptUnit>;
|
|
98
|
+
export type FinalHook = WithPkg<HookUnit>;
|
|
99
|
+
export type FinalMcp = WithPkg<McpUnit>;
|
|
100
|
+
export type FinalPermissions = WithPkg<PermissionsUnit>;
|
|
101
|
+
export type FinalAgent = WithPkg<AgentUnit>;
|
|
102
|
+
export interface Resolution {
|
|
103
|
+
projectDir: string;
|
|
104
|
+
projectName: string;
|
|
105
|
+
/** The workspaces of a monorepo, without the root. Empty for a single package. */
|
|
106
|
+
workspaces: Workspace[];
|
|
107
|
+
config: ProjectConfig;
|
|
108
|
+
/** Dependency layer upstream first, then the project's own harness. */
|
|
109
|
+
packages: ResolvedPackage[];
|
|
110
|
+
rules: FinalRule[];
|
|
111
|
+
skills: FinalSkill[];
|
|
112
|
+
docs: FinalDocs[];
|
|
113
|
+
scripts: FinalScript[];
|
|
114
|
+
hooks: FinalHook[];
|
|
115
|
+
mcp: FinalMcp[];
|
|
116
|
+
permissions: FinalPermissions[];
|
|
117
|
+
agents: FinalAgent[];
|
|
118
|
+
overrides: Override[];
|
|
119
|
+
excludedUnits: {
|
|
120
|
+
id: string;
|
|
121
|
+
by: string;
|
|
122
|
+
}[];
|
|
123
|
+
excludedPackages: {
|
|
124
|
+
name: string;
|
|
125
|
+
by: string;
|
|
126
|
+
}[];
|
|
127
|
+
warnings: string[];
|
|
128
|
+
}
|
|
129
|
+
/** Finds `<name>` in node_modules from `fromDir` upward, the way Node.js does. */
|
|
130
|
+
export declare function resolvePackageDir(name: string, fromDir: string): string | undefined;
|
|
131
|
+
export declare function resolve(projectDirInput: string, options?: ResolveOptions): Resolution;
|
|
132
|
+
export {};
|