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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1547 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +584 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/config.d.ts +7 -0
  7. package/dist/commands/config.js +49 -0
  8. package/dist/commands/config.js.map +1 -0
  9. package/dist/commands/context.d.ts +24 -0
  10. package/dist/commands/context.js +329 -0
  11. package/dist/commands/context.js.map +1 -0
  12. package/dist/commands/export.d.ts +19 -0
  13. package/dist/commands/export.js +116 -0
  14. package/dist/commands/export.js.map +1 -0
  15. package/dist/commands/import.d.ts +33 -0
  16. package/dist/commands/import.js +81 -0
  17. package/dist/commands/import.js.map +1 -0
  18. package/dist/commands/info.d.ts +19 -0
  19. package/dist/commands/info.js +235 -0
  20. package/dist/commands/info.js.map +1 -0
  21. package/dist/commands/init.d.ts +5 -0
  22. package/dist/commands/init.js +116 -0
  23. package/dist/commands/init.js.map +1 -0
  24. package/dist/commands/install.d.ts +119 -0
  25. package/dist/commands/install.js +533 -0
  26. package/dist/commands/install.js.map +1 -0
  27. package/dist/commands/list.d.ts +9 -0
  28. package/dist/commands/list.js +102 -0
  29. package/dist/commands/list.js.map +1 -0
  30. package/dist/commands/params.d.ts +58 -0
  31. package/dist/commands/params.js +366 -0
  32. package/dist/commands/params.js.map +1 -0
  33. package/dist/commands/refs.d.ts +60 -0
  34. package/dist/commands/refs.js +329 -0
  35. package/dist/commands/refs.js.map +1 -0
  36. package/dist/commands/registry.d.ts +18 -0
  37. package/dist/commands/registry.js +173 -0
  38. package/dist/commands/registry.js.map +1 -0
  39. package/dist/commands/status.d.ts +10 -0
  40. package/dist/commands/status.js +83 -0
  41. package/dist/commands/status.js.map +1 -0
  42. package/dist/commands/targets.d.ts +8 -0
  43. package/dist/commands/targets.js +61 -0
  44. package/dist/commands/targets.js.map +1 -0
  45. package/dist/commands/uninstall.d.ts +71 -0
  46. package/dist/commands/uninstall.js +322 -0
  47. package/dist/commands/uninstall.js.map +1 -0
  48. package/dist/commands/update.d.ts +66 -0
  49. package/dist/commands/update.js +384 -0
  50. package/dist/commands/update.js.map +1 -0
  51. package/dist/commands/validate.d.ts +3 -0
  52. package/dist/commands/validate.js +38 -0
  53. package/dist/commands/validate.js.map +1 -0
  54. package/dist/core/bundle.d.ts +49 -0
  55. package/dist/core/bundle.js +326 -0
  56. package/dist/core/bundle.js.map +1 -0
  57. package/dist/core/config.d.ts +65 -0
  58. package/dist/core/config.js +112 -0
  59. package/dist/core/config.js.map +1 -0
  60. package/dist/core/conflicts.d.ts +67 -0
  61. package/dist/core/conflicts.js +300 -0
  62. package/dist/core/conflicts.js.map +1 -0
  63. package/dist/core/context.d.ts +139 -0
  64. package/dist/core/context.js +432 -0
  65. package/dist/core/context.js.map +1 -0
  66. package/dist/core/deps.d.ts +62 -0
  67. package/dist/core/deps.js +339 -0
  68. package/dist/core/deps.js.map +1 -0
  69. package/dist/core/errors.d.ts +21 -0
  70. package/dist/core/errors.js +26 -0
  71. package/dist/core/errors.js.map +1 -0
  72. package/dist/core/executor.d.ts +9 -0
  73. package/dist/core/executor.js +139 -0
  74. package/dist/core/executor.js.map +1 -0
  75. package/dist/core/flavors.d.ts +128 -0
  76. package/dist/core/flavors.js +386 -0
  77. package/dist/core/flavors.js.map +1 -0
  78. package/dist/core/frontmatter.d.ts +6 -0
  79. package/dist/core/frontmatter.js +20 -0
  80. package/dist/core/frontmatter.js.map +1 -0
  81. package/dist/core/fsx.d.ts +40 -0
  82. package/dist/core/fsx.js +180 -0
  83. package/dist/core/fsx.js.map +1 -0
  84. package/dist/core/github.d.ts +37 -0
  85. package/dist/core/github.js +157 -0
  86. package/dist/core/github.js.map +1 -0
  87. package/dist/core/harnesses.d.ts +142 -0
  88. package/dist/core/harnesses.js +215 -0
  89. package/dist/core/harnesses.js.map +1 -0
  90. package/dist/core/hash.d.ts +12 -0
  91. package/dist/core/hash.js +34 -0
  92. package/dist/core/hash.js.map +1 -0
  93. package/dist/core/logger.d.ts +16 -0
  94. package/dist/core/logger.js +36 -0
  95. package/dist/core/logger.js.map +1 -0
  96. package/dist/core/overlap.d.ts +79 -0
  97. package/dist/core/overlap.js +155 -0
  98. package/dist/core/overlap.js.map +1 -0
  99. package/dist/core/parameters.d.ts +249 -0
  100. package/dist/core/parameters.js +944 -0
  101. package/dist/core/parameters.js.map +1 -0
  102. package/dist/core/paths.d.ts +20 -0
  103. package/dist/core/paths.js +35 -0
  104. package/dist/core/paths.js.map +1 -0
  105. package/dist/core/planner.d.ts +36 -0
  106. package/dist/core/planner.js +364 -0
  107. package/dist/core/planner.js.map +1 -0
  108. package/dist/core/prompt.d.ts +52 -0
  109. package/dist/core/prompt.js +197 -0
  110. package/dist/core/prompt.js.map +1 -0
  111. package/dist/core/refmap.d.ts +91 -0
  112. package/dist/core/refmap.js +331 -0
  113. package/dist/core/refmap.js.map +1 -0
  114. package/dist/core/refs.d.ts +297 -0
  115. package/dist/core/refs.js +801 -0
  116. package/dist/core/refs.js.map +1 -0
  117. package/dist/core/registry.d.ts +119 -0
  118. package/dist/core/registry.js +363 -0
  119. package/dist/core/registry.js.map +1 -0
  120. package/dist/core/rename.d.ts +36 -0
  121. package/dist/core/rename.js +74 -0
  122. package/dist/core/rename.js.map +1 -0
  123. package/dist/core/rollback.d.ts +38 -0
  124. package/dist/core/rollback.js +226 -0
  125. package/dist/core/rollback.js.map +1 -0
  126. package/dist/core/semver.d.ts +56 -0
  127. package/dist/core/semver.js +214 -0
  128. package/dist/core/semver.js.map +1 -0
  129. package/dist/core/state.d.ts +99 -0
  130. package/dist/core/state.js +196 -0
  131. package/dist/core/state.js.map +1 -0
  132. package/dist/core/store.d.ts +30 -0
  133. package/dist/core/store.js +54 -0
  134. package/dist/core/store.js.map +1 -0
  135. package/dist/core/types.d.ts +515 -0
  136. package/dist/core/types.js +49 -0
  137. package/dist/core/types.js.map +1 -0
  138. package/dist/index.d.ts +16 -0
  139. package/dist/index.js +16 -0
  140. package/dist/index.js.map +1 -0
  141. package/dist/merge/blocks.d.ts +48 -0
  142. package/dist/merge/blocks.js +0 -0
  143. package/dist/merge/blocks.js.map +1 -0
  144. package/dist/merge/json-merge.d.ts +66 -0
  145. package/dist/merge/json-merge.js +176 -0
  146. package/dist/merge/json-merge.js.map +1 -0
  147. package/dist/merge/toml.d.ts +48 -0
  148. package/dist/merge/toml.js +118 -0
  149. package/dist/merge/toml.js.map +1 -0
  150. package/dist/targets/claude-code.d.ts +11 -0
  151. package/dist/targets/claude-code.js +94 -0
  152. package/dist/targets/claude-code.js.map +1 -0
  153. package/dist/targets/copilot.d.ts +13 -0
  154. package/dist/targets/copilot.js +126 -0
  155. package/dist/targets/copilot.js.map +1 -0
  156. package/dist/targets/index.d.ts +20 -0
  157. package/dist/targets/index.js +60 -0
  158. package/dist/targets/index.js.map +1 -0
  159. package/dist/targets/opencode.d.ts +32 -0
  160. package/dist/targets/opencode.js +172 -0
  161. package/dist/targets/opencode.js.map +1 -0
  162. package/dist/targets/pi.d.ts +42 -0
  163. package/dist/targets/pi.js +134 -0
  164. package/dist/targets/pi.js.map +1 -0
  165. package/dist/targets/reasonix.d.ts +27 -0
  166. package/dist/targets/reasonix.js +192 -0
  167. package/dist/targets/reasonix.js.map +1 -0
  168. package/dist/targets/shared.d.ts +33 -0
  169. package/dist/targets/shared.js +109 -0
  170. package/dist/targets/shared.js.map +1 -0
  171. package/dist/targets/types.d.ts +40 -0
  172. package/dist/targets/types.js +17 -0
  173. package/dist/targets/types.js.map +1 -0
  174. package/docs/authoring-bundles.md +828 -0
  175. package/package.json +74 -0
@@ -0,0 +1,249 @@
1
+ /**
2
+ * Parameters: the values a bundle is customised with as it is installed.
3
+ *
4
+ * A bundle is written once and installed into many projects, and some of what
5
+ * it says is different in each of them -- the agent's name, the team's ticket
6
+ * prefix, the model to prefer. Writing those into the bundle means one bundle
7
+ * per project; leaving them out means the instructions are vague. A *parameter*
8
+ * is the third option: the bundle names the hole, and the install fills it.
9
+ *
10
+ * # hcm.yaml
11
+ * parameters:
12
+ * AGENT_NAME:
13
+ * description: What the agent should call itself
14
+ * default: Claude
15
+ *
16
+ * # context/10-identity.md
17
+ * You are a coding agent called <%AGENT_NAME%>.
18
+ *
19
+ * Three rules, and the rest follows from them:
20
+ *
21
+ * 1. A placeholder is `<%NAME%>`, and it is replaced wherever the text of an
22
+ * installed item can hold one -- markdown bodies and their frontmatter,
23
+ * context blocks, the string values inside MCP and settings fragments, and
24
+ * any skill or asset file that is text. Never in a *path*: where a file
25
+ * lands is a fact about the bundle's layout, not about this install.
26
+ * 2. Substitution happens on the *plan*, after the file references have been
27
+ * remapped and before anything is compared against disk. So the hashes,
28
+ * the receipts, `--dry-run`, `hcm info` and the cached context sections
29
+ * all describe the text that will really be there.
30
+ * 3. The values are recorded with the installation. `hcm update` renders the
31
+ * new version with the same ones without being told again -- an update
32
+ * that silently renamed the agent would be worse than no update at all.
33
+ *
34
+ * A parameter can also say *where* it applies, which is what makes one bundle
35
+ * able to hold questions that are not all worth asking every time:
36
+ *
37
+ * parameters:
38
+ * AGENT_NAME: # global: asked for every install
39
+ * default: Claude
40
+ * PYTEST_ARGS: # only when the python flavor is installed
41
+ * flavors: [python]
42
+ * default: -q
43
+ * COPILOT_ORG: # only when installing into Copilot
44
+ * targets: [copilot]
45
+ *
46
+ * Nothing here removes anything, and nothing here is a template *language*.
47
+ * There are no conditionals, no loops and no expressions: a bundle stays
48
+ * readable as the thing it installs, and the diff between what you wrote and
49
+ * what landed is a handful of names.
50
+ */
51
+ import type { BundleManifest, LoadedBundle, ParameterDefinition, ParameterSummary, ParameterValues, PlanAction, PlanTemplating, TargetId } from './types.js';
52
+ /**
53
+ * Accept every way of writing `parameters:` and return the one shape the rest
54
+ * of hcm works with:
55
+ *
56
+ * parameters: [AGENT_NAME, TEAM] # names alone, each one required
57
+ *
58
+ * parameters:
59
+ * AGENT_NAME: What the agent calls itself # name with a description
60
+ *
61
+ * parameters:
62
+ * AGENT_NAME: # name with the full shape
63
+ * description: What the agent calls itself
64
+ * default: Claude
65
+ * choices: [Claude, Codey]
66
+ * flavors: [python]
67
+ * targets: [claude-code]
68
+ */
69
+ export declare function normalizeParameters(manifest: BundleManifest, where?: string): ParameterDefinition[];
70
+ export interface RenderResult {
71
+ text: string;
72
+ /** Name -> how many times it was filled in. */
73
+ substituted: Map<string, number>;
74
+ /** Name -> how many times it was left standing, nothing having a value for it. */
75
+ unresolved: Map<string, number>;
76
+ }
77
+ /** Fill in every placeholder that has a value; leave the rest exactly as they are. */
78
+ export declare function renderTemplate(input: string, values: ParameterValues): RenderResult;
79
+ /** Every parameter name a piece of text refers to, escaped ones excluded. */
80
+ export declare function placeholderNames(input: string): string[];
81
+ /** True when text anywhere in here refers to a parameter. */
82
+ export declare function hasPlaceholder(input: string): boolean;
83
+ /**
84
+ * A buffer read back as text, or undefined when it is not text at all.
85
+ *
86
+ * Skills and assets are copied byte-for-byte, and most of them are markdown or
87
+ * a shell script that should be templated like anything else. An image must not
88
+ * be: decoding it, substituting nothing and re-encoding would still be a
89
+ * needless round trip, and a NUL byte is the cheapest reliable evidence.
90
+ */
91
+ export declare function decodeText(buffer: Buffer): string | undefined;
92
+ export interface TemplatingReport {
93
+ actions: PlanAction[];
94
+ substituted: PlanTemplating['substituted'];
95
+ unresolved: PlanTemplating['unresolved'];
96
+ }
97
+ /**
98
+ * Render every action's payload with `values`.
99
+ *
100
+ * `only` limits what is rendered without limiting what is reported -- which is
101
+ * what a resolved conflict needs, having regenerated one resource's actions
102
+ * under a new name after the rest were already done.
103
+ *
104
+ * `declared` is used only to explain a placeholder that was left standing: one
105
+ * naming a parameter the bundle never declared is a typo, one naming a
106
+ * parameter that does not apply here is a bundle installed more narrowly than
107
+ * it was written. Both leave the text alone, because a placeholder the user is
108
+ * told about beats a plausible value that is wrong.
109
+ */
110
+ export declare function applyParameters(actions: PlanAction[], values: ParameterValues, declared?: ParameterDefinition[], only?: PlanAction[]): TemplatingReport;
111
+ export interface ParameterScope {
112
+ target: TargetId;
113
+ /** The flavors being installed. Empty is the whole bundle, so everything applies. */
114
+ flavors: string[];
115
+ }
116
+ /**
117
+ * Does this parameter belong to the install being planned?
118
+ *
119
+ * A parameter that names no flavors and no targets is *global*: it applies
120
+ * always, which is what makes the simplest declaration also the most useful
121
+ * one. Naming either narrows it, and the flavor rule is the same one resources
122
+ * follow -- asking for no flavor asks for all of them.
123
+ *
124
+ * Applicability decides what is *asked for*, not what is substituted. A
125
+ * parameter narrowed to Copilot still has a default, and a file installed into
126
+ * Claude Code that mentions it gets that default rather than a placeholder --
127
+ * see `withDefaults`. Only a narrowed parameter with no default at all leaves a
128
+ * hole elsewhere, and `hcm validate` reports exactly that case.
129
+ */
130
+ export declare function appliesTo(parameter: ParameterDefinition, scope: ParameterScope): boolean;
131
+ /** The parameters an install into one harness, narrowed to some flavors, has to answer. */
132
+ export declare function applicableParameters(parameters: ParameterDefinition[], scope: ParameterScope): ParameterDefinition[];
133
+ /**
134
+ * The resolved values, plus a default for every parameter that was not asked
135
+ * about because it does not apply here.
136
+ *
137
+ * This is what stops a narrowing from putting a hole in a file. A bundle whose
138
+ * `MODEL` is asked for on Claude Code and defaulted everywhere else is an
139
+ * ordinary thing to want; without this, "everywhere else" would read
140
+ * `<%MODEL%>` in the installed text. Nothing here is recorded -- a default is
141
+ * always re-derivable from the manifest, and writing it down would freeze it
142
+ * against the next version.
143
+ */
144
+ export declare function withDefaults(values: ParameterValues, parameters: ParameterDefinition[]): ParameterValues;
145
+ /**
146
+ * Values supplied from outside the terminal: `--param`, `--params-file`.
147
+ *
148
+ * Scoped three ways, because one command can install several bundles into
149
+ * several harnesses and `AGENT_NAME` may well mean something different in each.
150
+ * The narrowest scope that mentions a name wins.
151
+ */
152
+ export interface ParameterOverrides {
153
+ /** Applies to any bundle that declares the name. */
154
+ global: ParameterValues;
155
+ /** Bundle name -> values. */
156
+ byBundle: Record<string, ParameterValues>;
157
+ /** `${bundle}@${target}` -> values. */
158
+ byBundleTarget: Record<string, ParameterValues>;
159
+ }
160
+ export declare function emptyOverrides(): ParameterOverrides;
161
+ export declare function mergeOverrides(...list: (ParameterOverrides | undefined)[]): ParameterOverrides;
162
+ /** The values that apply to one bundle in one harness, narrowest last. */
163
+ export declare function overridesFor(overrides: ParameterOverrides, bundle: string, target: TargetId): ParameterValues;
164
+ /**
165
+ * Read `--param` assignments.
166
+ *
167
+ * --param AGENT_NAME=Ada every bundle that asks for one
168
+ * --param review-kit:AGENT_NAME=Ada that bundle only
169
+ * --param review-kit@copilot:AGENT_NAME=Ada that bundle, in that harness only
170
+ */
171
+ export declare function parseAssignments(entries: readonly string[] | undefined): ParameterOverrides;
172
+ /**
173
+ * Read a parameters file -- YAML or JSON, the same two the manifest may be.
174
+ *
175
+ * AGENT_NAME: Ada # every bundle that asks for one
176
+ *
177
+ * bundles:
178
+ * review-kit:
179
+ * REVIEWER: Ada # that bundle
180
+ * targets:
181
+ * copilot:
182
+ * AGENT_NAME: Codey # that bundle, in Copilot
183
+ *
184
+ * This is the answer to "how do I install the same thing on twenty machines":
185
+ * commit the file, pass `--params-file`, and no question is ever asked.
186
+ */
187
+ export declare function readParametersFile(file: string, cwd: string): Promise<ParameterOverrides>;
188
+ /** The environment variable one parameter answers to, for a run with no terminal. */
189
+ export declare function parameterEnvName(name: string): string;
190
+ export type ParameterSource = 'flag' | 'environment' | 'session' | 'recorded' | 'prompt' | 'default' | 'empty';
191
+ export interface ResolveParametersInput {
192
+ bundle: string;
193
+ target: TargetId;
194
+ /** Already narrowed with `applicableParameters`. */
195
+ parameters: ParameterDefinition[];
196
+ /** From `--param` and `--params-file`, already narrowed to this bundle and harness. */
197
+ overrides?: ParameterValues;
198
+ /** What the installation already here was rendered with. */
199
+ recorded?: ParameterValues;
200
+ /**
201
+ * Answers given earlier in this run, so installing into three harnesses asks
202
+ * each question once. Written back as answers are given.
203
+ */
204
+ session?: Map<string, string>;
205
+ /** Ask when a value is missing and there is a terminal to ask at. */
206
+ prompt?: boolean;
207
+ /** Ignore `recorded` and ask again -- `hcm update --reconfigure`. */
208
+ reconfigure?: boolean;
209
+ /** Test seam: answers the questions instead of the terminal. */
210
+ ask?: (parameter: ParameterDefinition) => Promise<string>;
211
+ }
212
+ export interface ResolvedParameters {
213
+ values: ParameterValues;
214
+ /** Where each value came from, for `--verbose`. */
215
+ sources: Record<string, ParameterSource>;
216
+ }
217
+ /**
218
+ * Work out the value of every parameter this install needs.
219
+ *
220
+ * The order is the point. What the command line says beats the environment,
221
+ * which beats what has already been answered in this run, which beats what the
222
+ * last install recorded -- and only when all of those are silent is anybody
223
+ * asked. So a scripted run never blocks, an interactive one never repeats
224
+ * itself, and `hcm update` never changes an answer behind your back.
225
+ */
226
+ export declare function resolveParameters(input: ResolveParametersInput): Promise<ResolvedParameters>;
227
+ /** What is wrong with a value, if anything -- phrased to follow "the value ...". */
228
+ export declare function valueProblem(parameter: ParameterDefinition, value: string): string | undefined;
229
+ /**
230
+ * The values worth writing into the ledger. Secrets are not: the project-scope
231
+ * ledger sits in `.hcm/state.json` next to the code, and a token in there is a
232
+ * token in the repository.
233
+ */
234
+ export declare function storableValues(values: ParameterValues, parameters: ParameterDefinition[]): ParameterValues;
235
+ /** What to store in the registry: what will be asked, not how it is validated. */
236
+ export declare function summarizeParameters(parameters: ParameterDefinition[]): ParameterSummary[];
237
+ /** `AGENT_NAME, TEAM` -- for the listings. */
238
+ export declare function parameterNames(parameters: ParameterSummary[] | undefined): string;
239
+ /** Where a parameter applies, in prose. Empty for a global one. */
240
+ export declare function describeScope(parameter: ParameterDefinition | ParameterSummary): string;
241
+ /**
242
+ * Parameter mistakes worth reporting, surfaced by `hcm validate` and `hcm info`.
243
+ *
244
+ * The first two are the ones that bite: a placeholder nothing declares installs
245
+ * verbatim, and a parameter narrower than the file that uses it installs
246
+ * verbatim for everyone outside the narrowing. Both look, in the installed
247
+ * file, exactly like a bundle that forgot to finish a sentence.
248
+ */
249
+ export declare function parameterProblems(bundle: LoadedBundle): string[];