harness-config-manager 0.1.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/LICENSE +21 -0
- package/README.md +1547 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +584 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/config.d.ts +7 -0
- package/dist/commands/config.js +49 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/context.d.ts +24 -0
- package/dist/commands/context.js +329 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/export.d.ts +19 -0
- package/dist/commands/export.js +116 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/import.d.ts +33 -0
- package/dist/commands/import.js +81 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/info.d.ts +19 -0
- package/dist/commands/info.js +235 -0
- package/dist/commands/info.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.js +116 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/install.d.ts +119 -0
- package/dist/commands/install.js +533 -0
- package/dist/commands/install.js.map +1 -0
- package/dist/commands/list.d.ts +9 -0
- package/dist/commands/list.js +102 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/params.d.ts +58 -0
- package/dist/commands/params.js +366 -0
- package/dist/commands/params.js.map +1 -0
- package/dist/commands/refs.d.ts +60 -0
- package/dist/commands/refs.js +329 -0
- package/dist/commands/refs.js.map +1 -0
- package/dist/commands/registry.d.ts +18 -0
- package/dist/commands/registry.js +173 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/status.d.ts +10 -0
- package/dist/commands/status.js +83 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/targets.d.ts +8 -0
- package/dist/commands/targets.js +61 -0
- package/dist/commands/targets.js.map +1 -0
- package/dist/commands/uninstall.d.ts +71 -0
- package/dist/commands/uninstall.js +322 -0
- package/dist/commands/uninstall.js.map +1 -0
- package/dist/commands/update.d.ts +66 -0
- package/dist/commands/update.js +384 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/validate.d.ts +3 -0
- package/dist/commands/validate.js +38 -0
- package/dist/commands/validate.js.map +1 -0
- package/dist/core/bundle.d.ts +49 -0
- package/dist/core/bundle.js +326 -0
- package/dist/core/bundle.js.map +1 -0
- package/dist/core/config.d.ts +65 -0
- package/dist/core/config.js +112 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/conflicts.d.ts +67 -0
- package/dist/core/conflicts.js +300 -0
- package/dist/core/conflicts.js.map +1 -0
- package/dist/core/context.d.ts +139 -0
- package/dist/core/context.js +432 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/deps.d.ts +62 -0
- package/dist/core/deps.js +339 -0
- package/dist/core/deps.js.map +1 -0
- package/dist/core/errors.d.ts +21 -0
- package/dist/core/errors.js +26 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/executor.d.ts +9 -0
- package/dist/core/executor.js +139 -0
- package/dist/core/executor.js.map +1 -0
- package/dist/core/flavors.d.ts +128 -0
- package/dist/core/flavors.js +386 -0
- package/dist/core/flavors.js.map +1 -0
- package/dist/core/frontmatter.d.ts +6 -0
- package/dist/core/frontmatter.js +20 -0
- package/dist/core/frontmatter.js.map +1 -0
- package/dist/core/fsx.d.ts +40 -0
- package/dist/core/fsx.js +180 -0
- package/dist/core/fsx.js.map +1 -0
- package/dist/core/github.d.ts +37 -0
- package/dist/core/github.js +157 -0
- package/dist/core/github.js.map +1 -0
- package/dist/core/harnesses.d.ts +142 -0
- package/dist/core/harnesses.js +215 -0
- package/dist/core/harnesses.js.map +1 -0
- package/dist/core/hash.d.ts +12 -0
- package/dist/core/hash.js +34 -0
- package/dist/core/hash.js.map +1 -0
- package/dist/core/logger.d.ts +16 -0
- package/dist/core/logger.js +36 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/overlap.d.ts +79 -0
- package/dist/core/overlap.js +155 -0
- package/dist/core/overlap.js.map +1 -0
- package/dist/core/parameters.d.ts +249 -0
- package/dist/core/parameters.js +944 -0
- package/dist/core/parameters.js.map +1 -0
- package/dist/core/paths.d.ts +20 -0
- package/dist/core/paths.js +35 -0
- package/dist/core/paths.js.map +1 -0
- package/dist/core/planner.d.ts +36 -0
- package/dist/core/planner.js +364 -0
- package/dist/core/planner.js.map +1 -0
- package/dist/core/prompt.d.ts +52 -0
- package/dist/core/prompt.js +197 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/refmap.d.ts +91 -0
- package/dist/core/refmap.js +331 -0
- package/dist/core/refmap.js.map +1 -0
- package/dist/core/refs.d.ts +297 -0
- package/dist/core/refs.js +801 -0
- package/dist/core/refs.js.map +1 -0
- package/dist/core/registry.d.ts +119 -0
- package/dist/core/registry.js +363 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/rename.d.ts +36 -0
- package/dist/core/rename.js +74 -0
- package/dist/core/rename.js.map +1 -0
- package/dist/core/rollback.d.ts +38 -0
- package/dist/core/rollback.js +226 -0
- package/dist/core/rollback.js.map +1 -0
- package/dist/core/semver.d.ts +56 -0
- package/dist/core/semver.js +214 -0
- package/dist/core/semver.js.map +1 -0
- package/dist/core/state.d.ts +99 -0
- package/dist/core/state.js +196 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/store.d.ts +30 -0
- package/dist/core/store.js +54 -0
- package/dist/core/store.js.map +1 -0
- package/dist/core/types.d.ts +515 -0
- package/dist/core/types.js +49 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/merge/blocks.d.ts +48 -0
- package/dist/merge/blocks.js +0 -0
- package/dist/merge/blocks.js.map +1 -0
- package/dist/merge/json-merge.d.ts +66 -0
- package/dist/merge/json-merge.js +176 -0
- package/dist/merge/json-merge.js.map +1 -0
- package/dist/merge/toml.d.ts +48 -0
- package/dist/merge/toml.js +118 -0
- package/dist/merge/toml.js.map +1 -0
- package/dist/targets/claude-code.d.ts +11 -0
- package/dist/targets/claude-code.js +94 -0
- package/dist/targets/claude-code.js.map +1 -0
- package/dist/targets/copilot.d.ts +13 -0
- package/dist/targets/copilot.js +126 -0
- package/dist/targets/copilot.js.map +1 -0
- package/dist/targets/index.d.ts +20 -0
- package/dist/targets/index.js +60 -0
- package/dist/targets/index.js.map +1 -0
- package/dist/targets/opencode.d.ts +32 -0
- package/dist/targets/opencode.js +172 -0
- package/dist/targets/opencode.js.map +1 -0
- package/dist/targets/pi.d.ts +42 -0
- package/dist/targets/pi.js +134 -0
- package/dist/targets/pi.js.map +1 -0
- package/dist/targets/reasonix.d.ts +27 -0
- package/dist/targets/reasonix.js +192 -0
- package/dist/targets/reasonix.js.map +1 -0
- package/dist/targets/shared.d.ts +33 -0
- package/dist/targets/shared.js +109 -0
- package/dist/targets/shared.js.map +1 -0
- package/dist/targets/types.d.ts +40 -0
- package/dist/targets/types.js +17 -0
- package/dist/targets/types.js.map +1 -0
- package/docs/authoring-bundles.md +828 -0
- package/package.json +74 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hcm refs check` and `hcm refs fix`.
|
|
3
|
+
*
|
|
4
|
+
* Checking is a report. Fixing is a round trip through a file the user edits:
|
|
5
|
+
*
|
|
6
|
+
* 1. scan, and for every broken reference work out what it probably meant
|
|
7
|
+
* 2. write that out as JSON -- one entry per broken reference, each with the
|
|
8
|
+
* candidates ranked best first
|
|
9
|
+
* 3. the user deletes the wrong ones, leaving exactly one per entry
|
|
10
|
+
* 4. on save and close, every entry with one candidate left is applied
|
|
11
|
+
*
|
|
12
|
+
* The list-of-candidates shape is the point. A rename that broke twenty
|
|
13
|
+
* references usually broke them in two or three distinct ways, and picking from
|
|
14
|
+
* a ranked list is a keystroke where typing the path is a fresh chance to get
|
|
15
|
+
* it wrong. Entries left with more than one candidate are not guessed at; they
|
|
16
|
+
* are reported and left alone, so an unfinished pass through the file cannot
|
|
17
|
+
* quietly write something nobody chose.
|
|
18
|
+
*/
|
|
19
|
+
import { spawn } from 'node:child_process';
|
|
20
|
+
import os from 'node:os';
|
|
21
|
+
import path from 'node:path';
|
|
22
|
+
import { HcmError } from '../core/errors.js';
|
|
23
|
+
import { fs, pathExists, toPosix } from '../core/fsx.js';
|
|
24
|
+
import { color, log } from '../core/logger.js';
|
|
25
|
+
import { applyRefEdits, scanReferences, } from '../core/refs.js';
|
|
26
|
+
const DEFAULT_FIX_FILE = 'hcm-refs.json';
|
|
27
|
+
/**
|
|
28
|
+
* The scan scope, read off the flags.
|
|
29
|
+
*
|
|
30
|
+
* `check` and `fix` share it because `fix` re-scans before applying: a fix file
|
|
31
|
+
* produced under one scope and applied under another would not find the
|
|
32
|
+
* references it was written for.
|
|
33
|
+
*/
|
|
34
|
+
function scopeOf(options) {
|
|
35
|
+
return {
|
|
36
|
+
links: options.links ?? false,
|
|
37
|
+
allPaths: options.allPaths ?? false,
|
|
38
|
+
strict: options.strict ?? false,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The scope as flags again, so a command we print can be pasted and reproduce
|
|
43
|
+
* the same scan. `fix` re-scans, so a hint that dropped them would repair a
|
|
44
|
+
* different set of references than the one just reported.
|
|
45
|
+
*/
|
|
46
|
+
function scopeFlags(scope) {
|
|
47
|
+
const flags = [
|
|
48
|
+
scope.links === true ? '--links' : '',
|
|
49
|
+
scope.strict === true ? '--strict' : scope.allPaths === true ? '--all-paths' : '',
|
|
50
|
+
].filter(Boolean);
|
|
51
|
+
return flags.length > 0 ? ` ${flags.join(' ')}` : '';
|
|
52
|
+
}
|
|
53
|
+
/** The scope in a few words, so the report says what it did and did not read. */
|
|
54
|
+
function describeScope(scope) {
|
|
55
|
+
if (scope.links === true)
|
|
56
|
+
return 'links and wikilinks only';
|
|
57
|
+
if (scope.strict === true)
|
|
58
|
+
return 'every path, including bare filenames with no match';
|
|
59
|
+
if (scope.allPaths === true)
|
|
60
|
+
return 'every path, including implicit ones';
|
|
61
|
+
return 'links, wikilinks and explicitly relative paths';
|
|
62
|
+
}
|
|
63
|
+
// ---------------------------------------------------------------------------
|
|
64
|
+
// check
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
export async function refsCheckCommand(options) {
|
|
67
|
+
const root = await resolveRoot(options.path, options.cwd);
|
|
68
|
+
const result = await scanReferences(root, scopeOf(options));
|
|
69
|
+
if (options.json) {
|
|
70
|
+
log.plain(JSON.stringify(toReport(result), null, 2));
|
|
71
|
+
return result.broken.length === 0;
|
|
72
|
+
}
|
|
73
|
+
log.plain(`${color.bold(toPosix(path.relative(options.cwd, root)) || root)} ` +
|
|
74
|
+
color.dim(`· ${result.scanned.length} file(s) · ${result.refs.length} reference(s) · ` +
|
|
75
|
+
`${result.bundles.length} bundle(s)`));
|
|
76
|
+
log.plain(color.dim(` scope: ${describeScope(result.scope)}`));
|
|
77
|
+
if (result.broken.length === 0) {
|
|
78
|
+
log.success(' No broken references.');
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
for (const [file, refs] of groupByFile(result.broken)) {
|
|
82
|
+
log.plain(`\n${color.bold(file)}`);
|
|
83
|
+
for (const ref of refs) {
|
|
84
|
+
log.plain(` ${color.red('✖')} ${color.dim(`line ${ref.line}`)} ${ref.ref} ` +
|
|
85
|
+
color.dim(`(${ref.syntax}${ref.confidence === 'weak' ? ', unsure' : ''})`));
|
|
86
|
+
for (const suggestion of ref.suggestions) {
|
|
87
|
+
const note = suggestion.crossBundle ? color.yellow(' [another bundle]') : '';
|
|
88
|
+
log.plain(` ${color.dim('→')} ${suggestion.ref}${note}`);
|
|
89
|
+
}
|
|
90
|
+
if (ref.suggestions.length === 0)
|
|
91
|
+
log.plain(color.dim(' (nothing similar found)'));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
log.plain('');
|
|
95
|
+
log.warn(`${result.broken.length} broken reference(s) in ${groupByFile(result.broken).size} file(s)`);
|
|
96
|
+
log.info(color.dim(`Run "hcm refs fix --path ${quote(options.path ?? '.')}${scopeFlags(result.scope)}" ` +
|
|
97
|
+
'to repair them.'));
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
function toReport(result) {
|
|
101
|
+
return {
|
|
102
|
+
root: result.root,
|
|
103
|
+
scope: result.scope,
|
|
104
|
+
scanned: result.scanned.length,
|
|
105
|
+
references: result.refs.length,
|
|
106
|
+
broken: result.broken.map((ref) => ({
|
|
107
|
+
file: ref.fileRelative,
|
|
108
|
+
line: ref.line,
|
|
109
|
+
ref: ref.ref,
|
|
110
|
+
syntax: ref.syntax,
|
|
111
|
+
confidence: ref.confidence,
|
|
112
|
+
suggestions: ref.suggestions.map((suggestion) => ({
|
|
113
|
+
ref: suggestion.ref,
|
|
114
|
+
crossBundle: suggestion.crossBundle,
|
|
115
|
+
})),
|
|
116
|
+
})),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// fix
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
export async function refsFixCommand(options) {
|
|
123
|
+
// --file skips the scan entirely: the decisions have already been made, and
|
|
124
|
+
// re-deriving them would only risk disagreeing with the file being applied.
|
|
125
|
+
if (options.file)
|
|
126
|
+
return applyFixFile(options.file, options);
|
|
127
|
+
const root = await resolveRoot(options.path, options.cwd);
|
|
128
|
+
const result = await scanReferences(root, scopeOf(options));
|
|
129
|
+
if (result.broken.length === 0) {
|
|
130
|
+
log.success('No broken references — nothing to fix.');
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
const fixFile = buildFixFile(result);
|
|
134
|
+
const destination = options.write
|
|
135
|
+
? path.resolve(options.cwd, typeof options.write === 'string' ? options.write : DEFAULT_FIX_FILE)
|
|
136
|
+
: path.join(await fs.mkdtemp(path.join(os.tmpdir(), 'hcm-refs-')), DEFAULT_FIX_FILE);
|
|
137
|
+
await fs.writeFile(destination, `${JSON.stringify(fixFile, null, 2)}\n`, 'utf8');
|
|
138
|
+
log.info(`${color.bold(String(result.broken.length))} broken reference(s) written to ` +
|
|
139
|
+
color.bold(toPosix(path.relative(options.cwd, destination)) || destination));
|
|
140
|
+
// --write is the non-interactive half of the round trip: hand the file over
|
|
141
|
+
// and stop, so it can be edited by whatever, whenever, and applied later.
|
|
142
|
+
if (options.write) {
|
|
143
|
+
log.info(color.dim('Leave exactly one entry in each "new" list, then apply it with:\n' +
|
|
144
|
+
` hcm refs fix --path ${quote(options.path ?? '.')}${scopeFlags(result.scope)} ` +
|
|
145
|
+
`--file ${quote(toPosix(path.relative(options.cwd, destination)) || destination)}`));
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
log.info(color.dim('Leave exactly one entry in each "new" list, then save and close.'));
|
|
149
|
+
await (options.edit ?? openInEditor)(destination);
|
|
150
|
+
return applyFixFile(destination, options);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* One entry per broken reference.
|
|
154
|
+
*
|
|
155
|
+
* The key is the file the reference is in, which is what makes the file
|
|
156
|
+
* readable -- but a file may well have broken several references at once, and
|
|
157
|
+
* JSON objects do not keep duplicate keys. Later entries for the same file get
|
|
158
|
+
* a `#2`, `#3` suffix; `original_ref` is what actually identifies the
|
|
159
|
+
* reference, so nothing depends on the suffix.
|
|
160
|
+
*/
|
|
161
|
+
export function buildFixFile(result) {
|
|
162
|
+
const out = {};
|
|
163
|
+
const seen = new Map();
|
|
164
|
+
for (const ref of result.broken) {
|
|
165
|
+
const count = (seen.get(ref.fileRelative) ?? 0) + 1;
|
|
166
|
+
seen.set(ref.fileRelative, count);
|
|
167
|
+
const key = count === 1 ? ref.fileRelative : `${ref.fileRelative}#${count}`;
|
|
168
|
+
out[key] = {
|
|
169
|
+
original_ref: ref.ref,
|
|
170
|
+
new: ref.suggestions.map((suggestion) => suggestion.ref),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return out;
|
|
174
|
+
}
|
|
175
|
+
/** `path/to/file.md#3` -> `path/to/file.md`. */
|
|
176
|
+
function keyToFile(key) {
|
|
177
|
+
return key.replace(/#\d+$/, '');
|
|
178
|
+
}
|
|
179
|
+
async function applyFixFile(file, options) {
|
|
180
|
+
const absolute = path.resolve(options.cwd, file);
|
|
181
|
+
const text = await fs.readFile(absolute, 'utf8').catch(() => undefined);
|
|
182
|
+
if (text === undefined)
|
|
183
|
+
throw new HcmError(`No such fix file: ${absolute}`);
|
|
184
|
+
let parsed;
|
|
185
|
+
try {
|
|
186
|
+
parsed = JSON.parse(text);
|
|
187
|
+
}
|
|
188
|
+
catch (error) {
|
|
189
|
+
throw new HcmError(`${absolute} is not valid JSON: ${error.message}`, 'Re-run without --file to generate a fresh one.');
|
|
190
|
+
}
|
|
191
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
192
|
+
throw new HcmError(`${absolute} should be an object keyed by file path`);
|
|
193
|
+
}
|
|
194
|
+
// Paths in the fix file are relative to the folder that was scanned, which is
|
|
195
|
+
// not necessarily where the file ended up or where hcm is being run from.
|
|
196
|
+
const root = await resolveRoot(options.path, options.cwd);
|
|
197
|
+
// Re-scan so the offsets are current: whatever the user did to the JSON, the
|
|
198
|
+
// bundle itself may have been edited in the same sitting.
|
|
199
|
+
const result = await scanReferences(root, scopeOf(options));
|
|
200
|
+
const located = new Map();
|
|
201
|
+
for (const ref of result.broken) {
|
|
202
|
+
const list = located.get(ref.fileRelative) ?? [];
|
|
203
|
+
list.push(ref);
|
|
204
|
+
located.set(ref.fileRelative, list);
|
|
205
|
+
}
|
|
206
|
+
const edits = [];
|
|
207
|
+
const undecided = [];
|
|
208
|
+
const unknown = [];
|
|
209
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
210
|
+
const entry = value;
|
|
211
|
+
if (!entry || typeof entry.original_ref !== 'string' || !Array.isArray(entry.new)) {
|
|
212
|
+
throw new HcmError(`Entry "${key}" is malformed`, 'Each entry needs "original_ref" (a string) and "new" (a list of paths).');
|
|
213
|
+
}
|
|
214
|
+
const choices = entry.new.filter((choice) => typeof choice === 'string' && choice.trim() !== '');
|
|
215
|
+
if (choices.length !== 1) {
|
|
216
|
+
undecided.push(`${key}: ${choices.length === 0 ? 'no replacement chosen' : `${choices.length} left in "new"`}`);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const fileRelative = keyToFile(key);
|
|
220
|
+
const match = (located.get(fileRelative) ?? []).find((candidate) => candidate.ref === entry.original_ref);
|
|
221
|
+
const target = path.resolve(root, ...fileRelative.split('/'));
|
|
222
|
+
if (!(await pathExists(target))) {
|
|
223
|
+
unknown.push(`${key}: no such file under ${root}`);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
edits.push({
|
|
227
|
+
file: target,
|
|
228
|
+
original: entry.original_ref,
|
|
229
|
+
replacement: choices[0].trim(),
|
|
230
|
+
...(match ? { start: match.start, end: match.end } : {}),
|
|
231
|
+
});
|
|
232
|
+
// Consume it, so two entries for the same file do not both aim at the same
|
|
233
|
+
// occurrence when several references share a spelling.
|
|
234
|
+
if (match) {
|
|
235
|
+
const list = located.get(fileRelative);
|
|
236
|
+
list.splice(list.indexOf(match), 1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
for (const problem of undecided)
|
|
240
|
+
log.warn(` skipped ${problem}`);
|
|
241
|
+
for (const problem of unknown)
|
|
242
|
+
log.warn(` skipped ${problem}`);
|
|
243
|
+
if (edits.length === 0) {
|
|
244
|
+
log.warn('Nothing to apply — every entry still needs exactly one choice in "new".');
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const outcomes = await applyRefEdits(edits, { dryRun: options.dryRun ?? false });
|
|
248
|
+
for (const outcome of outcomes) {
|
|
249
|
+
const where = toPosix(path.relative(root, outcome.file));
|
|
250
|
+
if (outcome.applied) {
|
|
251
|
+
log.info(` ${color.green('✔')} ${where}: ${color.dim(outcome.original)} → ${outcome.replacement}`);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
log.warn(` ${where}: ${outcome.reason}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const applied = outcomes.filter((outcome) => outcome.applied).length;
|
|
258
|
+
const failed = outcomes.length - applied;
|
|
259
|
+
if (options.dryRun) {
|
|
260
|
+
log.info(color.dim(`(dry run — nothing written; ${applied} reference(s) would change)`));
|
|
261
|
+
return failed === 0;
|
|
262
|
+
}
|
|
263
|
+
log.success(`Fixed ${applied} reference(s)${failed > 0 ? `, ${failed} left alone` : ''}`);
|
|
264
|
+
return failed === 0 && undecided.length === 0 && unknown.length === 0;
|
|
265
|
+
}
|
|
266
|
+
// ---------------------------------------------------------------------------
|
|
267
|
+
// Odds and ends
|
|
268
|
+
// ---------------------------------------------------------------------------
|
|
269
|
+
/** A folder, normally -- but a single file is a reasonable thing to check too. */
|
|
270
|
+
async function resolveRoot(target, cwd) {
|
|
271
|
+
const root = path.resolve(cwd, target ?? '.');
|
|
272
|
+
if (!(await pathExists(root))) {
|
|
273
|
+
throw new HcmError(`No such path: ${root}`, 'Point --path at a bundle, or at a folder holding several.');
|
|
274
|
+
}
|
|
275
|
+
return root;
|
|
276
|
+
}
|
|
277
|
+
function groupByFile(refs) {
|
|
278
|
+
const groups = new Map();
|
|
279
|
+
for (const ref of refs) {
|
|
280
|
+
const list = groups.get(ref.fileRelative) ?? [];
|
|
281
|
+
list.push(ref);
|
|
282
|
+
groups.set(ref.fileRelative, list);
|
|
283
|
+
}
|
|
284
|
+
return groups;
|
|
285
|
+
}
|
|
286
|
+
function quote(value) {
|
|
287
|
+
return /\s/.test(value) ? `"${value}"` : value;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Open the fix file and wait for the editor to close.
|
|
291
|
+
*
|
|
292
|
+
* `$VISUAL` then `$EDITOR`, as every other tool that does this uses; failing
|
|
293
|
+
* that, whatever the platform will open a `.json` with. The wait is the whole
|
|
294
|
+
* mechanism -- an editor that forks (`code` without `--wait`) would have us
|
|
295
|
+
* read the file back before it had been touched -- so the ones known to fork
|
|
296
|
+
* are given the flag that makes them stay.
|
|
297
|
+
*/
|
|
298
|
+
async function openInEditor(file) {
|
|
299
|
+
const configured = process.env.VISUAL || process.env.EDITOR;
|
|
300
|
+
const { command, args } = editorCommand(configured, file);
|
|
301
|
+
log.info(color.dim(` opening ${command} …`));
|
|
302
|
+
await new Promise((resolve, reject) => {
|
|
303
|
+
const child = spawn(command, args, { stdio: 'inherit', shell: !configured });
|
|
304
|
+
child.on('error', (error) => reject(new HcmError(`Could not open an editor (${command}): ${error.message}`, 'Set $EDITOR, or use --write to save the file and edit it yourself.')));
|
|
305
|
+
child.on('exit', () => resolve());
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
export function editorCommand(configured, file) {
|
|
309
|
+
if (!configured) {
|
|
310
|
+
// No editor named: hand it to the platform. On Windows `start` needs a
|
|
311
|
+
// title argument first, or it takes the path as one.
|
|
312
|
+
if (process.platform === 'win32')
|
|
313
|
+
return { command: 'notepad', args: [file] };
|
|
314
|
+
if (process.platform === 'darwin')
|
|
315
|
+
return { command: 'open', args: ['-W', '-t', file] };
|
|
316
|
+
return { command: 'nano', args: [file] };
|
|
317
|
+
}
|
|
318
|
+
const parts = configured.split(/\s+/).filter(Boolean);
|
|
319
|
+
const command = parts[0];
|
|
320
|
+
const args = parts.slice(1);
|
|
321
|
+
// GUI editors return immediately unless told to wait, which would apply the
|
|
322
|
+
// file before it had been edited.
|
|
323
|
+
const forks = ['code', 'code-insiders', 'codium', 'subl', 'atom', 'gedit', 'cursor', 'windsurf'];
|
|
324
|
+
if (forks.includes(path.basename(command, path.extname(command))) && !args.includes('--wait')) {
|
|
325
|
+
args.push('--wait');
|
|
326
|
+
}
|
|
327
|
+
return { command, args: [...args, file] };
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=refs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refs.js","sourceRoot":"","sources":["../../src/commands/refs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;G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,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACxF,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;IAC3C,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAW,CAAC;IACnC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE5B,4EAA4E;IAC5E,kCAAkC;IAClC,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACjG,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC9F,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtB,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare function registryAddCommand(sources: string | string[], options: {
|
|
2
|
+
name?: string;
|
|
3
|
+
dev?: boolean;
|
|
4
|
+
cwd: string;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
export declare function registryRemoveCommand(references: string[], options: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
}): Promise<void>;
|
|
9
|
+
export declare function registryListCommand(options: {
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}): Promise<void>;
|
|
12
|
+
/**
|
|
13
|
+
* Show -- and open -- the store: the one directory holding every registered
|
|
14
|
+
* bundle's files. With a reference, opens that bundle's folder instead.
|
|
15
|
+
*/
|
|
16
|
+
export declare function registryOpenCommand(reference: string | undefined, options: {
|
|
17
|
+
open?: boolean;
|
|
18
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { HcmError } from '../core/errors.js';
|
|
3
|
+
import { flavorNames } from '../core/flavors.js';
|
|
4
|
+
import { parameterNames } from '../core/parameters.js';
|
|
5
|
+
import { ensureDir } from '../core/fsx.js';
|
|
6
|
+
import { describeSource } from '../core/github.js';
|
|
7
|
+
import { color, log } from '../core/logger.js';
|
|
8
|
+
import { storeDir } from '../core/paths.js';
|
|
9
|
+
import { addToRegistry, asList, liveEntries, readRegistry, removeFromRegistry, requireEntry, } from '../core/registry.js';
|
|
10
|
+
import { storeEntryDir } from '../core/store.js';
|
|
11
|
+
import { readState } from '../core/state.js';
|
|
12
|
+
export async function registryAddCommand(sources, options) {
|
|
13
|
+
const wanted = asList(sources);
|
|
14
|
+
// `--name` renames the entry, so it can only mean one of them.
|
|
15
|
+
if (options.name && wanted.length > 1) {
|
|
16
|
+
throw new HcmError('--name takes one bundle, but several sources were given', 'Register them one at a time to name each, or drop --name to keep their own names.');
|
|
17
|
+
}
|
|
18
|
+
const entries = [];
|
|
19
|
+
for (const source of wanted) {
|
|
20
|
+
entries.push(...(await addToRegistry(source, options.cwd, { name: options.name, dev: options.dev })));
|
|
21
|
+
}
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
const mode = entry.dev ? color.yellow(' [dev]') : '';
|
|
24
|
+
log.success(`Registered ${color.dim(`[${entry.id}]`)} ${color.bold(entry.name)} v${entry.version}${mode} ` +
|
|
25
|
+
`${color.dim(describeSource(entry.source))}`);
|
|
26
|
+
}
|
|
27
|
+
if (entries.some((entry) => entry.dev)) {
|
|
28
|
+
log.info(color.dim('Dev bundles are read from that directory every time, so edit and re-run "hcm install" freely.'));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
log.info(color.dim('Copied into the store; run "hcm update" to pick up later changes at the source.'));
|
|
32
|
+
}
|
|
33
|
+
// One command, however many were registered: `hcm install` takes a list.
|
|
34
|
+
const ids = entries.map((entry) => entry.id);
|
|
35
|
+
log.info(color.dim(ids.length === 1
|
|
36
|
+
? `Install it with: hcm install ${ids[0]}`
|
|
37
|
+
: `Install them with: hcm install ${ids.join(' ')}`));
|
|
38
|
+
// A bundle that can be installed in parts is worth saying so about once,
|
|
39
|
+
// here, rather than leaving it to be discovered in `hcm info`.
|
|
40
|
+
for (const entry of entries) {
|
|
41
|
+
if (!entry.flavors?.length)
|
|
42
|
+
continue;
|
|
43
|
+
log.info(color.dim(`${color.bold(entry.name)} installs in parts: ${flavorNames(entry.flavors)} — ` +
|
|
44
|
+
`e.g. hcm install ${entry.id} --flavor ${entry.flavors[0]?.name}`));
|
|
45
|
+
}
|
|
46
|
+
// The same for a bundle that will stop and ask: knowing the names in advance
|
|
47
|
+
// is what makes a scripted install possible at all.
|
|
48
|
+
for (const entry of entries) {
|
|
49
|
+
if (!entry.parameters?.length)
|
|
50
|
+
continue;
|
|
51
|
+
log.info(color.dim(`${color.bold(entry.name)} is customised at install time: ` +
|
|
52
|
+
`${parameterNames(entry.parameters)} — ` +
|
|
53
|
+
`e.g. hcm install ${entry.id} --param ${entry.parameters[0]?.name}=<value>`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export async function registryRemoveCommand(references, options) {
|
|
57
|
+
for (const reference of references) {
|
|
58
|
+
const removed = await removeFromRegistry(reference);
|
|
59
|
+
if (!removed)
|
|
60
|
+
throw new HcmError(`"${reference}" is not registered`);
|
|
61
|
+
const { entry, storeRemoved } = removed;
|
|
62
|
+
log.success(`Removed ${color.dim(`[${entry.id}]`)} ${color.bold(entry.name)}`);
|
|
63
|
+
if (storeRemoved)
|
|
64
|
+
log.info(color.dim(` deleted the stored copy (${entry.store})`));
|
|
65
|
+
else if (entry.dev) {
|
|
66
|
+
log.info(color.dim(` left your working copy alone (${describeSource(entry.source)})`));
|
|
67
|
+
}
|
|
68
|
+
const installed = await installationsOf(entry.name, options.cwd);
|
|
69
|
+
if (installed.length > 0) {
|
|
70
|
+
log.warn(` still installed in ${installed.join(', ')} — ` +
|
|
71
|
+
`run "hcm uninstall ${entry.name}" to remove those items.`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Where a bundle is currently installed, as "target (scope)" labels. */
|
|
76
|
+
async function installationsOf(bundle, cwd) {
|
|
77
|
+
const labels = [];
|
|
78
|
+
for (const scope of ['project', 'user']) {
|
|
79
|
+
const state = await readState(scope, cwd);
|
|
80
|
+
for (const record of state.installations) {
|
|
81
|
+
if (record.bundle === bundle)
|
|
82
|
+
labels.push(`${record.target} (${scope})`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return labels;
|
|
86
|
+
}
|
|
87
|
+
export async function registryListCommand(options) {
|
|
88
|
+
const registry = await readRegistry();
|
|
89
|
+
// Read from the working copy for dev entries -- see liveEntry in core/registry.
|
|
90
|
+
const entries = await liveEntries(registry.entries);
|
|
91
|
+
if (options.json) {
|
|
92
|
+
log.plain(JSON.stringify(entries, null, 2));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (entries.length === 0) {
|
|
96
|
+
log.info('No bundles registered.');
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const width = Math.max(...entries.map((entry) => entry.id.length));
|
|
100
|
+
for (const entry of entries) {
|
|
101
|
+
const mode = entry.dev ? color.yellow(' [dev]') : '';
|
|
102
|
+
log.plain(`${color.dim(entry.id.padStart(width))} ${color.bold(entry.name)} ` +
|
|
103
|
+
`${color.dim(`v${entry.version ?? '?'}`)}${mode}`);
|
|
104
|
+
log.plain(` ${' '.repeat(width)}${color.dim(describeSource(entry.source))}`);
|
|
105
|
+
// What this one can be installed as a part of, which is not something the
|
|
106
|
+
// name or the source can tell you.
|
|
107
|
+
if (entry.flavors?.length) {
|
|
108
|
+
log.plain(` ${' '.repeat(width)}${color.dim(`flavors: ${flavorNames(entry.flavors)}`)}`);
|
|
109
|
+
}
|
|
110
|
+
// And what it will ask for on the way in, which is worth knowing before
|
|
111
|
+
// running the install rather than when it stops to ask.
|
|
112
|
+
if (entry.parameters?.length) {
|
|
113
|
+
log.plain(` ${' '.repeat(width)}${color.dim(`parameters: ${parameterNames(entry.parameters)}`)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Show -- and open -- the store: the one directory holding every registered
|
|
119
|
+
* bundle's files. With a reference, opens that bundle's folder instead.
|
|
120
|
+
*/
|
|
121
|
+
export async function registryOpenCommand(reference, options) {
|
|
122
|
+
const target = reference ? await bundleDir(reference) : await storeDir();
|
|
123
|
+
// Opening a directory that does not exist yet fails on every platform, and a
|
|
124
|
+
// fresh install has never written the store.
|
|
125
|
+
await ensureDir(target);
|
|
126
|
+
log.plain(target);
|
|
127
|
+
if (options.open === false)
|
|
128
|
+
return;
|
|
129
|
+
const opened = await openInFileManager(target);
|
|
130
|
+
if (!opened) {
|
|
131
|
+
log.info(color.dim('Could not open a file manager here; the path is printed above.'));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** The directory a registered bundle's files live in, dev or stored. */
|
|
135
|
+
async function bundleDir(reference) {
|
|
136
|
+
const entry = await requireEntry(reference);
|
|
137
|
+
if (entry.dev)
|
|
138
|
+
return devPath(entry);
|
|
139
|
+
if (entry.store)
|
|
140
|
+
return storeEntryDir(entry.store);
|
|
141
|
+
throw new HcmError(`"${entry.name}" has no directory in the store`, 'Run "hcm update ' + entry.id + '" to populate it.');
|
|
142
|
+
}
|
|
143
|
+
function devPath(entry) {
|
|
144
|
+
if (entry.source.type !== 'local') {
|
|
145
|
+
throw new HcmError(`"${entry.name}" is marked dev but has no local path`);
|
|
146
|
+
}
|
|
147
|
+
return entry.source.path;
|
|
148
|
+
}
|
|
149
|
+
/** Hand a directory to the platform's file manager. Never throws. */
|
|
150
|
+
function openInFileManager(target) {
|
|
151
|
+
const [command, args] = process.platform === 'win32'
|
|
152
|
+
? ['explorer.exe', [target]]
|
|
153
|
+
: process.platform === 'darwin'
|
|
154
|
+
? ['open', [target]]
|
|
155
|
+
: ['xdg-open', [target]];
|
|
156
|
+
return new Promise((resolve) => {
|
|
157
|
+
try {
|
|
158
|
+
const child = spawn(command, args, {
|
|
159
|
+
detached: true,
|
|
160
|
+
stdio: 'ignore',
|
|
161
|
+
});
|
|
162
|
+
child.on('error', () => resolve(false));
|
|
163
|
+
child.unref();
|
|
164
|
+
// Explorer returns a non-zero exit code even when it worked, so a
|
|
165
|
+
// successful spawn is as much confirmation as we are going to get.
|
|
166
|
+
resolve(true);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
resolve(false);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/commands/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL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CAAC,MAAM,CAAC,IAAI,CAAC;AAC3B,CAAC;AAED,qEAAqE;AACrE,SAAS,iBAAiB,CAAC,MAAc;IACvC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,GACnB,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC1B,CAAC,CAAC,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ;YAC7B,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAE/B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,KAAK,CAAC,OAAiB,EAAE,IAAgB,EAAE;gBACvD,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,QAAQ;aAChB,CAAC,CAAC;YACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YACxC,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,kEAAkE;YAClE,mEAAmE;YACnE,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Scope } from '../core/types.js';
|
|
2
|
+
export interface StatusOptions {
|
|
3
|
+
scope?: Scope | 'all';
|
|
4
|
+
cwd: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Verify that what the ledger claims is still true on disk: useful after a
|
|
8
|
+
* teammate edits a shared file, or before an uninstall you want to be clean.
|
|
9
|
+
*/
|
|
10
|
+
export declare function statusCommand(options: StatusOptions): Promise<void>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { detectHarnesses, describeEvidence } from '../core/harnesses.js';
|
|
2
|
+
import { color, log } from '../core/logger.js';
|
|
3
|
+
import { allSharedFiles } from '../core/overlap.js';
|
|
4
|
+
import { auditInstallation } from '../core/rollback.js';
|
|
5
|
+
import { readState } from '../core/state.js';
|
|
6
|
+
import { describeReceipt } from '../core/types.js';
|
|
7
|
+
import { getTarget } from '../targets/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Verify that what the ledger claims is still true on disk: useful after a
|
|
10
|
+
* teammate edits a shared file, or before an uninstall you want to be clean.
|
|
11
|
+
*/
|
|
12
|
+
export async function statusCommand(options) {
|
|
13
|
+
const scopes = options.scope === 'all' || options.scope === undefined ? ['project', 'user'] : [options.scope];
|
|
14
|
+
await reportHarnesses(scopes, options.cwd);
|
|
15
|
+
let total = 0;
|
|
16
|
+
let drifted = 0;
|
|
17
|
+
for (const scope of scopes) {
|
|
18
|
+
const state = await readState(scope, options.cwd);
|
|
19
|
+
if (state.installations.length === 0)
|
|
20
|
+
continue;
|
|
21
|
+
log.plain(color.bold(`\n${scope} scope`));
|
|
22
|
+
for (const record of state.installations) {
|
|
23
|
+
const target = getTarget(record.target);
|
|
24
|
+
const scopeRoot = target.scopeRoot(record.scope, options.cwd);
|
|
25
|
+
const results = await auditInstallation(record, scopeRoot);
|
|
26
|
+
const missing = results.filter((result) => result.status === 'missing');
|
|
27
|
+
const modified = results.filter((result) => result.status === 'modified');
|
|
28
|
+
const adopted = results.filter((result) => result.status === 'kept');
|
|
29
|
+
total += results.length;
|
|
30
|
+
drifted += missing.length + modified.length;
|
|
31
|
+
const summary = missing.length === 0 && modified.length === 0
|
|
32
|
+
? color.green('ok')
|
|
33
|
+
: color.yellow(`${modified.length} modified, ${missing.length} missing`);
|
|
34
|
+
const adoptedNote = adopted.length > 0 ? color.dim(` (${adopted.length} adopted)`) : '';
|
|
35
|
+
log.plain(` ${color.bold(record.bundle)} → ${record.target} ${summary}${adoptedNote}`);
|
|
36
|
+
for (const result of [...modified, ...missing]) {
|
|
37
|
+
log.plain(` ${color.dim(result.status)} ${describeReceipt(result.receipt)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (total === 0) {
|
|
42
|
+
log.info('Nothing installed.');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
log.plain('');
|
|
46
|
+
if (drifted === 0)
|
|
47
|
+
log.success(`${total} item(s) tracked, all intact.`);
|
|
48
|
+
else
|
|
49
|
+
log.warn(`${total} item(s) tracked, ${drifted} drifted from the recorded state.`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Which harnesses this folder is used by, before anything about bundles.
|
|
53
|
+
*
|
|
54
|
+
* `hcm status` is the "is my setup sane?" command, and in a folder shared
|
|
55
|
+
* between harnesses the first thing to know is that it *is* shared -- and which
|
|
56
|
+
* files that makes ambiguous, since an item in one of those is never removed
|
|
57
|
+
* from just one harness.
|
|
58
|
+
*/
|
|
59
|
+
async function reportHarnesses(scopes, cwd) {
|
|
60
|
+
for (const scope of scopes) {
|
|
61
|
+
const found = await detectHarnesses(scope, cwd);
|
|
62
|
+
if (found.length === 0)
|
|
63
|
+
continue;
|
|
64
|
+
log.plain(color.bold(`\n${scope} harnesses`));
|
|
65
|
+
for (const harness of found) {
|
|
66
|
+
log.plain(` ${color.green('●')} ${color.bold(getTarget(harness.target).title)} ` +
|
|
67
|
+
color.dim(`(${describeEvidence(harness)})`));
|
|
68
|
+
}
|
|
69
|
+
if (found.length < 2)
|
|
70
|
+
continue;
|
|
71
|
+
const here = new Set(found.map((harness) => harness.target));
|
|
72
|
+
const shared = allSharedFiles(scope, cwd).filter((file) => file.readers.filter((reader) => here.has(reader.target)).length > 1);
|
|
73
|
+
for (const file of shared) {
|
|
74
|
+
const readers = [
|
|
75
|
+
...new Set(file.readers.filter((reader) => here.has(reader.target)).map((reader) => reader.target)),
|
|
76
|
+
];
|
|
77
|
+
log.plain(color.dim(` ${file.readers[0]?.path}: shared by ` +
|
|
78
|
+
`${readers.map((id) => getTarget(id).title).join(', ')} -- ` +
|
|
79
|
+
'anything installed there is visible to all of them'));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=status.js.map
|