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,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deciding what to do about a conflict.
|
|
3
|
+
*
|
|
4
|
+
* `buildPlan` reports collisions; this turns each one into a decision and
|
|
5
|
+
* rewrites the plan accordingly, before anything is written. Decisions are made
|
|
6
|
+
* per *resource*, not per file, because one skill is a dozen writes and the user
|
|
7
|
+
* means one thing by all of them.
|
|
8
|
+
*
|
|
9
|
+
* Four outcomes:
|
|
10
|
+
* skip leave what is on disk; drop our writes for that resource
|
|
11
|
+
* overwrite write ours over theirs (this is what --force does to everything)
|
|
12
|
+
* rename install under a different name -- MCP servers only, because they
|
|
13
|
+
* are addressed by name and the bundle's own instructions can be
|
|
14
|
+
* rewritten to match (see rename.ts)
|
|
15
|
+
* abort stop the whole run having written nothing
|
|
16
|
+
*
|
|
17
|
+
* Every choice is remembered for the run, so a bundle installed into three
|
|
18
|
+
* harnesses asks once rather than three times.
|
|
19
|
+
*/
|
|
20
|
+
import { AbortedError, ConflictError } from './errors.js';
|
|
21
|
+
import { color, log } from './logger.js';
|
|
22
|
+
import { applicableParameters, applyParameters } from './parameters.js';
|
|
23
|
+
import { detectConflicts, resourceActions } from './planner.js';
|
|
24
|
+
import { isInteractive, select, text } from './prompt.js';
|
|
25
|
+
import { remapReferences } from './refmap.js';
|
|
26
|
+
import { NAME_PATTERN, rewriteReferences } from './rename.js';
|
|
27
|
+
import { getTarget } from '../targets/index.js';
|
|
28
|
+
import { resourceKey, } from './types.js';
|
|
29
|
+
/** Guards against a rename that keeps landing on another taken name. */
|
|
30
|
+
const MAX_ROUNDS = 10;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve every conflict in `plan` and return the plan that should actually be
|
|
33
|
+
* applied. Throws `AbortedError` if the user aborts, or `ConflictError` when
|
|
34
|
+
* the policy is `abort` (the default when there is no terminal to ask at).
|
|
35
|
+
*/
|
|
36
|
+
export async function resolvePlanConflicts(plan, options) {
|
|
37
|
+
const target = getTarget(plan.target);
|
|
38
|
+
const bundleName = plan.bundle.manifest.name;
|
|
39
|
+
const decisions = options.decisions ?? new Map();
|
|
40
|
+
// A rename regenerates one resource's writes from the bundle, so they arrive
|
|
41
|
+
// holding raw `<%PLACEHOLDERS%>` again and have to be rendered like the rest.
|
|
42
|
+
const parameterValues = plan.templating?.values ?? {};
|
|
43
|
+
const parameters = applicableParameters(plan.bundle.parameters, {
|
|
44
|
+
target: plan.target,
|
|
45
|
+
flavors: plan.flavors,
|
|
46
|
+
});
|
|
47
|
+
let actions = plan.actions;
|
|
48
|
+
let conflicts = plan.conflicts;
|
|
49
|
+
const outcomes = [];
|
|
50
|
+
const skipped = [...plan.skipped];
|
|
51
|
+
/** Resources the user chose to overwrite: their collisions stop being news. */
|
|
52
|
+
const accepted = new Set();
|
|
53
|
+
/** Resources already answered in *this* plan; a repeat means the answer failed. */
|
|
54
|
+
const answered = new Set();
|
|
55
|
+
const rename = (key, newName) => {
|
|
56
|
+
const current = actions.find((action) => action.resource && resourceKey(action.resource) === key)?.resource;
|
|
57
|
+
if (!current)
|
|
58
|
+
return undefined;
|
|
59
|
+
const fresh = resourceActions(target, { ...current, name: newName }, bundleName, plan.scope, plan.targetOptions);
|
|
60
|
+
const { kept, insertAt } = extract(actions, key);
|
|
61
|
+
// Only the *other* resources get their references rewritten: the renamed
|
|
62
|
+
// one was regenerated, and rewriting it would also rename its command.
|
|
63
|
+
const rewrite = rewriteReferences(kept, current.name, newName);
|
|
64
|
+
const combined = [
|
|
65
|
+
...rewrite.actions.slice(0, insertAt),
|
|
66
|
+
...fresh,
|
|
67
|
+
...rewrite.actions.slice(insertAt),
|
|
68
|
+
];
|
|
69
|
+
// The regenerated writes have not been past the file-reference remapper or
|
|
70
|
+
// the parameter renderer -- both run once, in buildPlan -- so give just
|
|
71
|
+
// those the same treatment, in the same order. They sit where `fresh` was
|
|
72
|
+
// spliced in, which remapping preserves.
|
|
73
|
+
const remapped = remapReferences(plan.bundle, combined, fresh).actions;
|
|
74
|
+
actions = applyParameters(remapped, parameterValues, parameters, remapped.slice(insertAt, insertAt + fresh.length)).actions;
|
|
75
|
+
answered.add(key);
|
|
76
|
+
return {
|
|
77
|
+
label: `${current.kind} "${current.name}"`,
|
|
78
|
+
choice: 'rename',
|
|
79
|
+
detail: `installed as "${newName}"` +
|
|
80
|
+
(rewrite.total > 0
|
|
81
|
+
? `; rewrote ${rewrite.total} reference(s) in ${rewrite.touched.length} file(s)`
|
|
82
|
+
: '; no references found in the bundle'),
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
// Answers are remembered per bundle, so two bundles that happen to ship a
|
|
86
|
+
// resource of the same name still get asked separately.
|
|
87
|
+
const remembered = (key) => decisions.get(`${bundleName}/${key}`);
|
|
88
|
+
const remember = (key, resolution) => {
|
|
89
|
+
decisions.set(`${bundleName}/${key}`, resolution);
|
|
90
|
+
};
|
|
91
|
+
// A rename decided for an earlier target applies here too, collision or not:
|
|
92
|
+
// the same server under two names across harnesses would be a trap.
|
|
93
|
+
let carried = false;
|
|
94
|
+
for (const [stored, decision] of decisions) {
|
|
95
|
+
if (decision.choice !== 'rename' || !decision.newName)
|
|
96
|
+
continue;
|
|
97
|
+
if (!stored.startsWith(`${bundleName}/`))
|
|
98
|
+
continue;
|
|
99
|
+
const outcome = rename(stored.slice(bundleName.length + 1), decision.newName);
|
|
100
|
+
if (!outcome)
|
|
101
|
+
continue;
|
|
102
|
+
outcomes.push({ ...outcome, detail: `${outcome.detail} (as decided earlier)` });
|
|
103
|
+
carried = true;
|
|
104
|
+
}
|
|
105
|
+
if (carried) {
|
|
106
|
+
conflicts = await detectConflicts(actions, plan.scopeRoot, bundleName, options.cwd);
|
|
107
|
+
}
|
|
108
|
+
if (conflicts.length === 0) {
|
|
109
|
+
return { plan: { ...plan, actions, conflicts, skipped }, outcomes };
|
|
110
|
+
}
|
|
111
|
+
const resolver = pickResolver(options, () => conflicts, bundleName);
|
|
112
|
+
for (let round = 0; round < MAX_ROUNDS; round += 1) {
|
|
113
|
+
const pending = conflicts.filter((conflict) => !accepted.has(groupKey(conflict)));
|
|
114
|
+
if (pending.length === 0)
|
|
115
|
+
break;
|
|
116
|
+
for (const group of groupConflicts(pending, bundleName)) {
|
|
117
|
+
const earlier = answered.has(group.key) ? undefined : remembered(group.key);
|
|
118
|
+
if (earlier)
|
|
119
|
+
log.debug(`reusing your earlier answer for ${group.label}: ${earlier.choice}`);
|
|
120
|
+
const resolution = earlier ?? (await resolver(group));
|
|
121
|
+
remember(group.key, resolution);
|
|
122
|
+
answered.add(group.key);
|
|
123
|
+
if (resolution.choice === 'abort') {
|
|
124
|
+
throw new AbortedError(`Aborted at ${group.label}`);
|
|
125
|
+
}
|
|
126
|
+
if (resolution.choice === 'overwrite') {
|
|
127
|
+
accepted.add(group.key);
|
|
128
|
+
outcomes.push({
|
|
129
|
+
label: group.label,
|
|
130
|
+
choice: 'overwrite',
|
|
131
|
+
detail: group.conflicts.map((conflict) => conflict.path).join(', '),
|
|
132
|
+
});
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (resolution.choice === 'skip') {
|
|
136
|
+
const before = actions.length;
|
|
137
|
+
actions = dropSkipped(actions, group);
|
|
138
|
+
skipped.push(...(group.resource
|
|
139
|
+
? [{ resource: group.resource, reason: 'skipped: kept what was already there' }]
|
|
140
|
+
: []));
|
|
141
|
+
outcomes.push({
|
|
142
|
+
label: group.label,
|
|
143
|
+
choice: 'skip',
|
|
144
|
+
detail: `${before - actions.length} write(s) dropped`,
|
|
145
|
+
});
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
// Rename. Regenerate this resource's writes under the new name, then
|
|
149
|
+
// point the rest of the bundle's instructions at it.
|
|
150
|
+
const outcome = resolution.newName ? rename(group.key, resolution.newName) : undefined;
|
|
151
|
+
if (!outcome)
|
|
152
|
+
throw new AbortedError(`Cannot rename ${group.label}`);
|
|
153
|
+
outcomes.push(outcome);
|
|
154
|
+
}
|
|
155
|
+
conflicts = await detectConflicts(actions, plan.scopeRoot, bundleName, options.cwd);
|
|
156
|
+
}
|
|
157
|
+
const unresolved = conflicts.filter((conflict) => !accepted.has(groupKey(conflict)));
|
|
158
|
+
if (unresolved.length > 0) {
|
|
159
|
+
throw new ConflictError(`Could not resolve ${unresolved.length} conflict(s) installing "${bundleName}"`, unresolved);
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
plan: { ...plan, actions, conflicts, skipped },
|
|
163
|
+
outcomes,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
// ---------------------------------------------------------------------------
|
|
167
|
+
// Grouping
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
function groupKey(conflict) {
|
|
170
|
+
return conflict.resource ? resourceKey(conflict.resource) : `path:${conflict.path}`;
|
|
171
|
+
}
|
|
172
|
+
function describeResource(resource, path) {
|
|
173
|
+
return resource ? `${resource.kind} "${resource.name}"` : path;
|
|
174
|
+
}
|
|
175
|
+
function groupConflicts(conflicts, bundleName) {
|
|
176
|
+
const groups = new Map();
|
|
177
|
+
for (const conflict of conflicts) {
|
|
178
|
+
const key = groupKey(conflict);
|
|
179
|
+
const existing = groups.get(key);
|
|
180
|
+
if (existing) {
|
|
181
|
+
existing.conflicts.push(conflict);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
const resource = conflict.resource;
|
|
185
|
+
const canRename = resource?.kind === 'mcp';
|
|
186
|
+
groups.set(key, {
|
|
187
|
+
key,
|
|
188
|
+
label: describeResource(resource, conflict.path),
|
|
189
|
+
resource,
|
|
190
|
+
conflicts: [conflict],
|
|
191
|
+
canRename,
|
|
192
|
+
...(canRename && resource ? { suggestedName: `${bundleName}-${resource.name}` } : {}),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return [...groups.values()];
|
|
196
|
+
}
|
|
197
|
+
// ---------------------------------------------------------------------------
|
|
198
|
+
// Applying a skip
|
|
199
|
+
// ---------------------------------------------------------------------------
|
|
200
|
+
/**
|
|
201
|
+
* Drop the writes a skip cancels.
|
|
202
|
+
*
|
|
203
|
+
* For most kinds that is the whole resource -- half a skill on disk is worse
|
|
204
|
+
* than none. A settings fragment is different: its keys are independent, so
|
|
205
|
+
* only the colliding ones are dropped and the rest still land.
|
|
206
|
+
*/
|
|
207
|
+
function dropSkipped(actions, group) {
|
|
208
|
+
if (group.resource?.kind === 'settings') {
|
|
209
|
+
const collided = new Set(group.conflicts.map((conflict) => `${conflict.path}::${(conflict.pointer ?? []).join('.')}`));
|
|
210
|
+
return actions.filter((action) => {
|
|
211
|
+
if (!action.resource || resourceKey(action.resource) !== group.key)
|
|
212
|
+
return true;
|
|
213
|
+
const pointer = action.payload.kind === 'json-value' || action.payload.kind === 'json-array-item'
|
|
214
|
+
? action.payload.pointer
|
|
215
|
+
: [];
|
|
216
|
+
return !collided.has(`${action.path}::${pointer.join('.')}`);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
if (!group.resource) {
|
|
220
|
+
const paths = new Set(group.conflicts.map((conflict) => conflict.path));
|
|
221
|
+
return actions.filter((action) => !paths.has(action.path));
|
|
222
|
+
}
|
|
223
|
+
return actions.filter((action) => !action.resource || resourceKey(action.resource) !== group.key);
|
|
224
|
+
}
|
|
225
|
+
/** Remove one resource's actions, remembering where they were. */
|
|
226
|
+
function extract(actions, key) {
|
|
227
|
+
const kept = [];
|
|
228
|
+
let insertAt = actions.length;
|
|
229
|
+
for (const action of actions) {
|
|
230
|
+
if (action.resource && resourceKey(action.resource) === key) {
|
|
231
|
+
if (insertAt === actions.length)
|
|
232
|
+
insertAt = kept.length;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
kept.push(action);
|
|
236
|
+
}
|
|
237
|
+
return { kept, insertAt };
|
|
238
|
+
}
|
|
239
|
+
// ---------------------------------------------------------------------------
|
|
240
|
+
// Resolvers
|
|
241
|
+
// ---------------------------------------------------------------------------
|
|
242
|
+
/**
|
|
243
|
+
* The resolver implied by `--on-conflict`.
|
|
244
|
+
*
|
|
245
|
+
* `abort` -- and `prompt` with no terminal to prompt at -- never returns one:
|
|
246
|
+
* it raises straight away, listing the conflicts as they stand now, which is
|
|
247
|
+
* what `hcm` has always done for scripts and CI.
|
|
248
|
+
*/
|
|
249
|
+
function pickResolver(options, current, bundleName) {
|
|
250
|
+
if (options.resolver)
|
|
251
|
+
return options.resolver;
|
|
252
|
+
if (options.policy === 'prompt' && isInteractive())
|
|
253
|
+
return promptResolver;
|
|
254
|
+
if (options.policy === 'prompt' || options.policy === 'abort') {
|
|
255
|
+
const conflicts = current();
|
|
256
|
+
throw new ConflictError(`${conflicts.length} conflict(s) installing "${bundleName}"`, conflicts);
|
|
257
|
+
}
|
|
258
|
+
const choice = options.policy;
|
|
259
|
+
return async () => ({ choice });
|
|
260
|
+
}
|
|
261
|
+
/** Ask, once per resource. */
|
|
262
|
+
export const promptResolver = async (group) => {
|
|
263
|
+
log.plain('');
|
|
264
|
+
log.warn(`${group.label} conflicts with what is already installed:`);
|
|
265
|
+
for (const conflict of group.conflicts) {
|
|
266
|
+
log.plain(` ${color.dim(conflict.path)} ${conflict.detail}`);
|
|
267
|
+
}
|
|
268
|
+
const choice = await select(` How should hcm handle ${group.label}?`, group.canRename
|
|
269
|
+
? [
|
|
270
|
+
{ value: 'skip', label: 'skip', detail: 'keep the existing one, install nothing' },
|
|
271
|
+
{ value: 'overwrite', label: 'replace', detail: 'overwrite it with the bundle version' },
|
|
272
|
+
{
|
|
273
|
+
value: 'rename',
|
|
274
|
+
label: 'rename',
|
|
275
|
+
detail: 'install under another name and update this bundle’s instructions',
|
|
276
|
+
},
|
|
277
|
+
{ value: 'abort', label: 'abort', detail: 'stop; write nothing at all' },
|
|
278
|
+
]
|
|
279
|
+
: [
|
|
280
|
+
{ value: 'skip', label: 'skip', detail: 'keep the existing one, install nothing' },
|
|
281
|
+
{ value: 'overwrite', label: 'overwrite', detail: 'replace it with the bundle version' },
|
|
282
|
+
{ value: 'abort', label: 'abort', detail: 'stop; write nothing at all' },
|
|
283
|
+
], 'skip');
|
|
284
|
+
if (choice !== 'rename')
|
|
285
|
+
return { choice };
|
|
286
|
+
const oldName = group.resource?.name ?? '';
|
|
287
|
+
const newName = await text(` new name for ${group.label}${group.suggestedName ? color.dim(` [${group.suggestedName}]`) : ''}`, (value) => {
|
|
288
|
+
const candidate = value === '' ? group.suggestedName ?? '' : value;
|
|
289
|
+
if (!candidate)
|
|
290
|
+
return 'enter a name';
|
|
291
|
+
if (candidate === oldName)
|
|
292
|
+
return 'that is the name that already clashed';
|
|
293
|
+
if (!NAME_PATTERN.test(candidate)) {
|
|
294
|
+
return 'use letters, digits, dots, dashes and underscores';
|
|
295
|
+
}
|
|
296
|
+
return undefined;
|
|
297
|
+
});
|
|
298
|
+
return { choice, newName: newName === '' ? group.suggestedName : newName };
|
|
299
|
+
};
|
|
300
|
+
//# sourceMappingURL=conflicts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conflicts.js","sourceRoot":"","sources":["../../src/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* The context cache.
|
|
3
|
+
*
|
|
4
|
+
* `context/` resources are the one kind that lands in a file the harness's own
|
|
5
|
+
* agent edits: `CLAUDE.md`, `AGENTS.md`, `REASONIX.md`. When an agent rewrites
|
|
6
|
+
* one of those to record what it has learned about the project, the marker
|
|
7
|
+
* blocks -- and the instructions inside them -- can go with it.
|
|
8
|
+
*
|
|
9
|
+
* Rollback receipts cannot help: a block receipt says *where* a section was,
|
|
10
|
+
* not what it said. Re-reading the bundle can, but that needs the registry, the
|
|
11
|
+
* store, and possibly the network, none of which are around when you just want
|
|
12
|
+
* your instructions back.
|
|
13
|
+
*
|
|
14
|
+
* So every install also drops a copy of each context section under `.hcm`,
|
|
15
|
+
* together with a ledger of which file each one belongs in. `hcm context
|
|
16
|
+
* append|override|remove` then works entirely from that copy.
|
|
17
|
+
*
|
|
18
|
+
* .hcm/context.json the ledger
|
|
19
|
+
* .hcm/context/<bundle>/<name>.md one section, body only
|
|
20
|
+
*/
|
|
21
|
+
import { type ContextLedger, type ContextPlacement, type ContextSection, type LoadedBundle, type PlanAction, type Scope, type TargetId } from './types.js';
|
|
22
|
+
export declare function readContextLedger(scope: Scope, cwd: string): Promise<ContextLedger>;
|
|
23
|
+
export declare function writeContextLedger(scope: Scope, cwd: string, ledger: ContextLedger): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Remember the context sections a plan just wrote. Called after the install so
|
|
26
|
+
* the cache only ever holds sections that really landed somewhere.
|
|
27
|
+
*
|
|
28
|
+
* Re-installing overwrites the cached copy, which is what makes `hcm update`
|
|
29
|
+
* refresh the sections rather than pin them to whatever shipped first.
|
|
30
|
+
*/
|
|
31
|
+
export declare function captureContext(bundle: LoadedBundle, targetId: TargetId, scope: Scope, cwd: string, actions: PlanAction[]): Promise<number>;
|
|
32
|
+
/**
|
|
33
|
+
* Forget what a bundle contributed to one target, after an uninstall has taken
|
|
34
|
+
* the blocks away. A section left with no placements at all is dropped, and its
|
|
35
|
+
* cached copy with it -- nothing would ever put it back.
|
|
36
|
+
*/
|
|
37
|
+
export declare function forgetContext(bundleName: string, targetId: TargetId, scope: Scope, cwd: string): Promise<void>;
|
|
38
|
+
export interface ContextItem {
|
|
39
|
+
section: ContextSection;
|
|
40
|
+
placement: ContextPlacement;
|
|
41
|
+
/**
|
|
42
|
+
* Every target this one block belongs to. Usually one, but OpenCode and Pi
|
|
43
|
+
* share `AGENTS.md`, and the block written there answers to both -- so both
|
|
44
|
+
* installations' receipts have to move together when it comes or goes.
|
|
45
|
+
*/
|
|
46
|
+
targets: TargetId[];
|
|
47
|
+
/** The cached body, or undefined when the copy has gone missing. */
|
|
48
|
+
body?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Every section that belongs in one instruction file, in the order it belongs. */
|
|
51
|
+
export interface ContextFile {
|
|
52
|
+
/** The target whose mapping named this file; see `targets` for all of them. */
|
|
53
|
+
target: TargetId;
|
|
54
|
+
targets: TargetId[];
|
|
55
|
+
scope: Scope;
|
|
56
|
+
/** Scope-root-relative POSIX path. */
|
|
57
|
+
path: string;
|
|
58
|
+
/** The root that `path` is relative to; nothing above it is ever pruned. */
|
|
59
|
+
scopeRoot: string;
|
|
60
|
+
absolutePath: string;
|
|
61
|
+
items: ContextItem[];
|
|
62
|
+
}
|
|
63
|
+
export interface ContextSelection {
|
|
64
|
+
/** Bundle names; empty or absent means every tracked bundle. */
|
|
65
|
+
bundles?: string[];
|
|
66
|
+
targets?: TargetId[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Group the cached sections by the file they live in. Two targets writing the
|
|
70
|
+
* same `AGENTS.md` share one group, so a section is never written twice.
|
|
71
|
+
*/
|
|
72
|
+
export declare function contextFiles(scope: Scope, cwd: string, selection?: ContextSelection): Promise<ContextFile[]>;
|
|
73
|
+
/** The bundles that have cached context in a scope. */
|
|
74
|
+
export declare function trackedBundles(scope: Scope, cwd: string): Promise<string[]>;
|
|
75
|
+
export type ContextOutcome =
|
|
76
|
+
/** Was not there, and now is. */
|
|
77
|
+
'appended'
|
|
78
|
+
/** Was there, and was written again from the cache. */
|
|
79
|
+
| 'rewritten'
|
|
80
|
+
/** Its marker block is already in the file; left alone. */
|
|
81
|
+
| 'present'
|
|
82
|
+
/** No marker, but the text is there verbatim; left alone rather than doubled. */
|
|
83
|
+
| 'unmarked' | 'removed'
|
|
84
|
+
/** Nothing to remove, or nothing cached to write. */
|
|
85
|
+
| 'missing';
|
|
86
|
+
export interface ContextItemResult {
|
|
87
|
+
item: ContextItem;
|
|
88
|
+
outcome: ContextOutcome;
|
|
89
|
+
}
|
|
90
|
+
export interface ContextFileResult {
|
|
91
|
+
file: ContextFile;
|
|
92
|
+
results: ContextItemResult[];
|
|
93
|
+
changed: boolean;
|
|
94
|
+
/** Non-blank lines of foreign content `override` dropped. */
|
|
95
|
+
discardedLines?: number;
|
|
96
|
+
/** The file held nothing else and was deleted. */
|
|
97
|
+
deleted?: boolean;
|
|
98
|
+
}
|
|
99
|
+
export interface ContextApplyOptions {
|
|
100
|
+
dryRun?: boolean;
|
|
101
|
+
/** Write every section, without first checking whether it is already there. */
|
|
102
|
+
force?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Put back whatever is missing.
|
|
106
|
+
*
|
|
107
|
+
* A section already inside its marker block is left exactly as it is, edits and
|
|
108
|
+
* all -- hcm does not overwrite what somebody has since improved. `--force`
|
|
109
|
+
* says to write them all from the cache regardless, which is also how you undo
|
|
110
|
+
* an agent's edit to the text inside the markers.
|
|
111
|
+
*/
|
|
112
|
+
export declare function appendContext(file: ContextFile, options?: ContextApplyOptions): Promise<ContextFileResult>;
|
|
113
|
+
/**
|
|
114
|
+
* Clear the file and lay the sections down in order.
|
|
115
|
+
*
|
|
116
|
+
* Everything hcm did not write is discarded -- that is the point: an agent's
|
|
117
|
+
* rewrite is exactly what you are throwing away. Blocks belonging to other
|
|
118
|
+
* bundles, or to rules rather than context, are kept and moved below the
|
|
119
|
+
* sections, because they have receipts of their own and losing them would only
|
|
120
|
+
* make `hcm status` report damage.
|
|
121
|
+
*/
|
|
122
|
+
export declare function overrideContext(file: ContextFile, options?: ContextApplyOptions): Promise<ContextFileResult>;
|
|
123
|
+
/**
|
|
124
|
+
* Take the sections out again, leaving everything else -- including a file the
|
|
125
|
+
* user wrote and we only appended to. A file left holding nothing goes too,
|
|
126
|
+
* which is what `hcm uninstall` does with the same blocks.
|
|
127
|
+
*/
|
|
128
|
+
export declare function removeContext(file: ContextFile, options?: ContextApplyOptions): Promise<ContextFileResult>;
|
|
129
|
+
export declare function syncBlockReceipts(scope: Scope, cwd: string, results: ContextFileResult[]): Promise<void>;
|
|
130
|
+
/** Record that a section has just been written where the ledger says it goes. */
|
|
131
|
+
export declare function touchPlacements(scope: Scope, cwd: string, results: ContextFileResult[]): Promise<void>;
|
|
132
|
+
export type ContextPresence = 'present' | 'unmarked' | 'absent';
|
|
133
|
+
/** What the file says about a section right now, ignoring the ledger. */
|
|
134
|
+
export declare function inspectContext(file: ContextFile): Promise<{
|
|
135
|
+
item: ContextItem;
|
|
136
|
+
presence: ContextPresence;
|
|
137
|
+
}[]>;
|
|
138
|
+
/** Where the cached copy of a section lives on disk. */
|
|
139
|
+
export declare function cachedSectionPath(scope: Scope, cwd: string, section: ContextSection): string;
|