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
package/dist/core/fsx.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
/** Convert any path to POSIX separators, which is what receipts and manifests store. */
|
|
4
|
+
export function toPosix(p) {
|
|
5
|
+
return p.split(path.sep).join('/');
|
|
6
|
+
}
|
|
7
|
+
/** Resolve a scope-relative POSIX path against an absolute root. */
|
|
8
|
+
export function fromPosix(root, relative) {
|
|
9
|
+
return path.resolve(root, ...relative.split('/'));
|
|
10
|
+
}
|
|
11
|
+
export async function pathExists(target) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.access(target);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export async function isDirectory(target) {
|
|
21
|
+
try {
|
|
22
|
+
return (await fs.stat(target)).isDirectory();
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function readTextIfExists(target) {
|
|
29
|
+
try {
|
|
30
|
+
return await fs.readFile(target, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error.code === 'ENOENT')
|
|
34
|
+
return undefined;
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Raw bytes, for content that would not survive a round trip through UTF-8. */
|
|
39
|
+
export async function readBytesIfExists(target) {
|
|
40
|
+
try {
|
|
41
|
+
return await fs.readFile(target);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code === 'ENOENT')
|
|
45
|
+
return undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export async function readJsonIfExists(target) {
|
|
50
|
+
const text = await readTextIfExists(target);
|
|
51
|
+
if (text === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (text.trim() === '')
|
|
54
|
+
return undefined;
|
|
55
|
+
return JSON.parse(text);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create a directory tree, returning the directories that did not previously
|
|
59
|
+
* exist (deepest last). Uninstall uses this to prune only what it created.
|
|
60
|
+
*/
|
|
61
|
+
export async function ensureDir(target) {
|
|
62
|
+
const created = [];
|
|
63
|
+
const segments = [];
|
|
64
|
+
let current = path.resolve(target);
|
|
65
|
+
while (!(await pathExists(current))) {
|
|
66
|
+
segments.push(current);
|
|
67
|
+
const parent = path.dirname(current);
|
|
68
|
+
if (parent === current)
|
|
69
|
+
break;
|
|
70
|
+
current = parent;
|
|
71
|
+
}
|
|
72
|
+
for (const dir of segments.reverse()) {
|
|
73
|
+
await fs.mkdir(dir, { recursive: true });
|
|
74
|
+
created.push(dir);
|
|
75
|
+
}
|
|
76
|
+
return created;
|
|
77
|
+
}
|
|
78
|
+
export async function writeText(target, contents) {
|
|
79
|
+
const created = await ensureDir(path.dirname(target));
|
|
80
|
+
await fs.writeFile(target, contents, 'utf8');
|
|
81
|
+
return created;
|
|
82
|
+
}
|
|
83
|
+
export async function writeBytes(target, contents) {
|
|
84
|
+
const created = await ensureDir(path.dirname(target));
|
|
85
|
+
await fs.writeFile(target, contents);
|
|
86
|
+
return created;
|
|
87
|
+
}
|
|
88
|
+
export async function writeJson(target, value) {
|
|
89
|
+
return writeText(target, `${JSON.stringify(value, null, 2)}\n`);
|
|
90
|
+
}
|
|
91
|
+
export async function removeFile(target) {
|
|
92
|
+
try {
|
|
93
|
+
await fs.unlink(target);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (error.code !== 'ENOENT')
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Remove a directory only when it is empty. Returns true when removed. */
|
|
101
|
+
export async function removeDirIfEmpty(target) {
|
|
102
|
+
try {
|
|
103
|
+
const entries = await fs.readdir(target);
|
|
104
|
+
if (entries.length > 0)
|
|
105
|
+
return false;
|
|
106
|
+
await fs.rmdir(target);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Walk upward from `target`, removing empty directories, stopping at `stopAt`
|
|
115
|
+
* (exclusive) or at the first non-empty directory.
|
|
116
|
+
*/
|
|
117
|
+
export async function pruneEmptyDirs(target, stopAt) {
|
|
118
|
+
let current = path.resolve(target);
|
|
119
|
+
const boundary = path.resolve(stopAt);
|
|
120
|
+
while (current.startsWith(boundary) && current !== boundary) {
|
|
121
|
+
if (!(await removeDirIfEmpty(current)))
|
|
122
|
+
return;
|
|
123
|
+
current = path.dirname(current);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Recursively list files under a directory, returning absolute paths. */
|
|
127
|
+
export async function listFiles(root) {
|
|
128
|
+
const out = [];
|
|
129
|
+
async function walk(dir) {
|
|
130
|
+
let entries;
|
|
131
|
+
try {
|
|
132
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
for (const entry of entries) {
|
|
138
|
+
const full = path.join(dir, entry.name);
|
|
139
|
+
if (entry.isDirectory())
|
|
140
|
+
await walk(full);
|
|
141
|
+
else if (entry.isFile())
|
|
142
|
+
out.push(full);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
await walk(root);
|
|
146
|
+
return out.sort();
|
|
147
|
+
}
|
|
148
|
+
/** Copy a file, creating parent directories as needed. */
|
|
149
|
+
export async function copyFile(from, to) {
|
|
150
|
+
const created = await ensureDir(path.dirname(to));
|
|
151
|
+
await fs.copyFile(from, to);
|
|
152
|
+
return created;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Recursively copy a directory. `skip` names directories to leave behind --
|
|
156
|
+
* a bundle's own `.git` or `node_modules` are not part of the bundle.
|
|
157
|
+
* Symlinks are copied as links rather than followed, so a cycle cannot hang us.
|
|
158
|
+
*/
|
|
159
|
+
export async function copyDir(from, to, skip = []) {
|
|
160
|
+
const skipped = new Set(skip);
|
|
161
|
+
await fs.mkdir(to, { recursive: true });
|
|
162
|
+
for (const entry of await fs.readdir(from, { withFileTypes: true })) {
|
|
163
|
+
if (skipped.has(entry.name))
|
|
164
|
+
continue;
|
|
165
|
+
const source = path.join(from, entry.name);
|
|
166
|
+
const destination = path.join(to, entry.name);
|
|
167
|
+
if (entry.isDirectory())
|
|
168
|
+
await copyDir(source, destination, skip);
|
|
169
|
+
else if (entry.isSymbolicLink())
|
|
170
|
+
await fs.symlink(await fs.readlink(source), destination);
|
|
171
|
+
else if (entry.isFile())
|
|
172
|
+
await fs.copyFile(source, destination);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** Remove a directory and everything under it. Missing is not an error. */
|
|
176
|
+
export async function removeDir(target) {
|
|
177
|
+
await fs.rm(target, { recursive: true, force: true });
|
|
178
|
+
}
|
|
179
|
+
export { fs };
|
|
180
|
+
//# sourceMappingURL=fsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsx.js","sourceRoot":"","sources":["../../src/core/fsx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,wFAAwF;AACxF,MAAM,UAAU,OAAO,CAAC,CAAS;IAC/B,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,oEAAoE;AACpE,MAAM,UAAU,SAAS,CAAC,IAAY,EAAE,QAAgB;IACtD,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAc;IAC7C,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAc;IAC9C,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAc;IACnD,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CA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C;QAE9C,IAAI,KAAK,CAAC,WAAW,EAAE;YAAE,MAAM,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;aAC7D,IAAI,KAAK,CAAC,cAAc,EAAE;YAAE,MAAM,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC;aACrF,IAAI,KAAK,CAAC,MAAM,EAAE;YAAE,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAClE,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc;IAC5C,MAAM,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetching bundles from GitHub.
|
|
3
|
+
*
|
|
4
|
+
* We download the ref tarball rather than shelling out to git: no git
|
|
5
|
+
* dependency, no credential prompts, and it works for a subdirectory of a
|
|
6
|
+
* monorepo of bundles.
|
|
7
|
+
*/
|
|
8
|
+
import type { BundleSource } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Parse every form of GitHub reference someone might reasonably paste:
|
|
11
|
+
*
|
|
12
|
+
* owner/repo shorthand
|
|
13
|
+
* owner/repo#branch shorthand with ref
|
|
14
|
+
* owner/repo/sub/dir#branch shorthand with subdirectory
|
|
15
|
+
* https://github.com/owner/repo browser address bar
|
|
16
|
+
* https://github.com/owner/repo?tab=readme-ov-file ...with GitHub's query string
|
|
17
|
+
* https://github.com/owner/repo/tree/main/sub/dir browser, viewing a directory
|
|
18
|
+
* https://github.com/owner/repo/blob/main/sub/hcm.yaml browser, viewing a file
|
|
19
|
+
* https://github.com/owner/repo.git HTTPS clone URL
|
|
20
|
+
* git@github.com:owner/repo.git SSH clone URL
|
|
21
|
+
* ssh://git@github.com/owner/repo.git SSH clone URL, protocol form
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseGithubSource(input: string): BundleSource | undefined;
|
|
24
|
+
export declare function describeSource(source: BundleSource): string;
|
|
25
|
+
/**
|
|
26
|
+
* Download and extract a GitHub ref into the cache, returning the directory
|
|
27
|
+
* that holds the bundle (honouring `subdir`).
|
|
28
|
+
*/
|
|
29
|
+
export declare function fetchGithubBundle(source: Extract<BundleSource, {
|
|
30
|
+
type: 'github';
|
|
31
|
+
}>, options?: {
|
|
32
|
+
refresh?: boolean;
|
|
33
|
+
}): Promise<string>;
|
|
34
|
+
/** Resolve any source to a local directory, downloading when needed. */
|
|
35
|
+
export declare function resolveSource(source: BundleSource, options?: {
|
|
36
|
+
refresh?: boolean;
|
|
37
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetching bundles from GitHub.
|
|
3
|
+
*
|
|
4
|
+
* We download the ref tarball rather than shelling out to git: no git
|
|
5
|
+
* dependency, no credential prompts, and it works for a subdirectory of a
|
|
6
|
+
* monorepo of bundles.
|
|
7
|
+
*/
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { x as extractTar } from 'tar';
|
|
10
|
+
import { HcmError } from './errors.js';
|
|
11
|
+
import { ensureDir, fs, isDirectory, pathExists } from './fsx.js';
|
|
12
|
+
import { cacheDir } from './paths.js';
|
|
13
|
+
/**
|
|
14
|
+
* Parse every form of GitHub reference someone might reasonably paste:
|
|
15
|
+
*
|
|
16
|
+
* owner/repo shorthand
|
|
17
|
+
* owner/repo#branch shorthand with ref
|
|
18
|
+
* owner/repo/sub/dir#branch shorthand with subdirectory
|
|
19
|
+
* https://github.com/owner/repo browser address bar
|
|
20
|
+
* https://github.com/owner/repo?tab=readme-ov-file ...with GitHub's query string
|
|
21
|
+
* https://github.com/owner/repo/tree/main/sub/dir browser, viewing a directory
|
|
22
|
+
* https://github.com/owner/repo/blob/main/sub/hcm.yaml browser, viewing a file
|
|
23
|
+
* https://github.com/owner/repo.git HTTPS clone URL
|
|
24
|
+
* git@github.com:owner/repo.git SSH clone URL
|
|
25
|
+
* ssh://git@github.com/owner/repo.git SSH clone URL, protocol form
|
|
26
|
+
*/
|
|
27
|
+
export function parseGithubSource(input) {
|
|
28
|
+
const trimmed = input.trim();
|
|
29
|
+
if (!trimmed)
|
|
30
|
+
return undefined;
|
|
31
|
+
// SSH clone URLs, in both the scp-like and protocol forms.
|
|
32
|
+
const ssh = /^(?:ssh:\/\/)?git@github\.com[:/]([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/.exec(trimmed);
|
|
33
|
+
if (ssh) {
|
|
34
|
+
return { type: 'github', owner: ssh[1], repo: ssh[2], ref: 'HEAD' };
|
|
35
|
+
}
|
|
36
|
+
// Web and HTTPS clone URLs, with or without www.
|
|
37
|
+
const url = /^(?:https?|git):\/\/(?:www\.)?github\.com\/(.+)$/i.exec(trimmed);
|
|
38
|
+
if (url)
|
|
39
|
+
return parseGithubUrlPath(url[1]);
|
|
40
|
+
// Bare shorthand. Excluded when it looks like a filesystem path.
|
|
41
|
+
const shorthand = /^([\w.-]+)\/([\w.-]+)(?:\/([^#]+))?(?:#(.+))?$/.exec(trimmed);
|
|
42
|
+
if (shorthand && !trimmed.startsWith('.') && !path.isAbsolute(trimmed)) {
|
|
43
|
+
const [, owner, repo, subdir, ref] = shorthand;
|
|
44
|
+
return {
|
|
45
|
+
type: 'github',
|
|
46
|
+
owner: owner,
|
|
47
|
+
repo: repo,
|
|
48
|
+
ref: ref ?? 'HEAD',
|
|
49
|
+
...(subdir ? { subdir: trimSlashes(subdir) } : {}),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Fragments GitHub's own UI appends. Treating these as a git ref would send us
|
|
56
|
+
* looking for a branch called "readme", so they are ignored -- but any other
|
|
57
|
+
* fragment is honoured as a ref, so `.../repo#v1.2.0` works as you'd expect.
|
|
58
|
+
*/
|
|
59
|
+
const UI_FRAGMENTS = new Set(['readme', 'readme-ov-file']);
|
|
60
|
+
/** Parse the path portion of a github.com URL (everything after the host). */
|
|
61
|
+
function parseGithubUrlPath(rest) {
|
|
62
|
+
// Strip the query string, then split off the fragment.
|
|
63
|
+
const hashIndex = rest.indexOf('#');
|
|
64
|
+
const fragment = hashIndex >= 0 ? rest.slice(hashIndex + 1) : '';
|
|
65
|
+
const withoutFragment = hashIndex >= 0 ? rest.slice(0, hashIndex) : rest;
|
|
66
|
+
const pathname = (withoutFragment.split('?')[0] ?? '').replace(/\/+$/, '');
|
|
67
|
+
const segments = pathname.split('/').filter(Boolean);
|
|
68
|
+
const owner = segments[0];
|
|
69
|
+
const repo = segments[1]?.replace(/\.git$/, '');
|
|
70
|
+
if (!owner || !repo)
|
|
71
|
+
return undefined;
|
|
72
|
+
// A fragment is a ref only when the URL did not already name one, and only
|
|
73
|
+
// when it is not one of GitHub's own UI anchors (#readme, #L42).
|
|
74
|
+
const fragmentRef = fragment && !UI_FRAGMENTS.has(fragment.toLowerCase()) && !/^L\d+(?:-L\d+)?$/.test(fragment)
|
|
75
|
+
? fragment
|
|
76
|
+
: undefined;
|
|
77
|
+
const kind = segments[2];
|
|
78
|
+
if (kind === 'tree' || kind === 'blob') {
|
|
79
|
+
const ref = segments[3];
|
|
80
|
+
if (!ref)
|
|
81
|
+
return { type: 'github', owner, repo, ref: fragmentRef ?? 'HEAD' };
|
|
82
|
+
// GitHub uses /blob/ only for files and /tree/ for directories, so a blob
|
|
83
|
+
// URL's last segment is always a filename -- drop it to get the bundle
|
|
84
|
+
// directory. This holds for extensionless files such as README or LICENSE.
|
|
85
|
+
const parts = kind === 'blob' ? segments.slice(4, -1) : segments.slice(4);
|
|
86
|
+
return {
|
|
87
|
+
type: 'github',
|
|
88
|
+
owner,
|
|
89
|
+
repo,
|
|
90
|
+
ref,
|
|
91
|
+
...(parts.length ? { subdir: parts.join('/') } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Any other trailing path (/issues, /pulls, /releases) refers to the repo as
|
|
95
|
+
// a whole as far as we are concerned.
|
|
96
|
+
return { type: 'github', owner, repo, ref: fragmentRef ?? 'HEAD' };
|
|
97
|
+
}
|
|
98
|
+
function trimSlashes(value) {
|
|
99
|
+
return value.replace(/^\/+|\/+$/g, '');
|
|
100
|
+
}
|
|
101
|
+
export function describeSource(source) {
|
|
102
|
+
if (source.type === 'local')
|
|
103
|
+
return source.path;
|
|
104
|
+
const subdir = source.subdir ? `/${source.subdir}` : '';
|
|
105
|
+
return `github:${source.owner}/${source.repo}${subdir}#${source.ref}`;
|
|
106
|
+
}
|
|
107
|
+
function cacheKey(source) {
|
|
108
|
+
return `${source.owner}-${source.repo}-${source.ref}`.replace(/[^\w.-]/g, '_');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Download and extract a GitHub ref into the cache, returning the directory
|
|
112
|
+
* that holds the bundle (honouring `subdir`).
|
|
113
|
+
*/
|
|
114
|
+
export async function fetchGithubBundle(source, options = {}) {
|
|
115
|
+
const root = path.join(await cacheDir(), cacheKey(source));
|
|
116
|
+
const bundleDir = source.subdir ? path.join(root, ...source.subdir.split('/')) : root;
|
|
117
|
+
if (!options.refresh && (await isDirectory(bundleDir)))
|
|
118
|
+
return bundleDir;
|
|
119
|
+
if (await pathExists(root))
|
|
120
|
+
await fs.rm(root, { recursive: true, force: true });
|
|
121
|
+
await ensureDir(root);
|
|
122
|
+
const ref = source.ref === 'HEAD' ? await defaultBranch(source) : source.ref;
|
|
123
|
+
const url = `https://codeload.github.com/${source.owner}/${source.repo}/tar.gz/${encodeURIComponent(ref)}`;
|
|
124
|
+
const response = await fetch(url);
|
|
125
|
+
if (!response.ok) {
|
|
126
|
+
throw new HcmError(`Failed to download ${describeSource(source)} (HTTP ${response.status})`, 'Check the repository name and ref, and that the repository is public.');
|
|
127
|
+
}
|
|
128
|
+
const archive = path.join(root, 'bundle.tar.gz');
|
|
129
|
+
await fs.writeFile(archive, Buffer.from(await response.arrayBuffer()));
|
|
130
|
+
// GitHub tarballs nest everything under `<repo>-<ref>/`; strip that level.
|
|
131
|
+
await extractTar({ file: archive, cwd: root, strip: 1 });
|
|
132
|
+
await fs.rm(archive, { force: true });
|
|
133
|
+
if (!(await isDirectory(bundleDir))) {
|
|
134
|
+
throw new HcmError(`Path "${source.subdir}" not found in ${source.owner}/${source.repo}@${ref}`);
|
|
135
|
+
}
|
|
136
|
+
return bundleDir;
|
|
137
|
+
}
|
|
138
|
+
async function defaultBranch(source) {
|
|
139
|
+
const response = await fetch(`https://api.github.com/repos/${source.owner}/${source.repo}`, {
|
|
140
|
+
headers: { Accept: 'application/vnd.github+json' },
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok)
|
|
143
|
+
return 'main';
|
|
144
|
+
const data = (await response.json());
|
|
145
|
+
return data.default_branch ?? 'main';
|
|
146
|
+
}
|
|
147
|
+
/** Resolve any source to a local directory, downloading when needed. */
|
|
148
|
+
export async function resolveSource(source, options = {}) {
|
|
149
|
+
if (source.type === 'local') {
|
|
150
|
+
if (!(await isDirectory(source.path))) {
|
|
151
|
+
throw new HcmError(`Bundle directory no longer exists: ${source.path}`);
|
|
152
|
+
}
|
|
153
|
+
return source.path;
|
|
154
|
+
}
|
|
155
|
+
return fetchGithubBundle(source, options);
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/core/github.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,IAAI,UAAU,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,O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AAO,EAAE,EAAE,MAAM,EAAE,6BAA6B,EAAE;KACnD,CAAC,CAAC;IACH,IAAI,CAAC,QAAQ,CAAC,EAAE;QAAE,OAAO,MAAM,CAAC;IAChC,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAgC,CAAC;IACpE,OAAO,IAAI,CAAC,cAAc,IAAI,MAAM,CAAC;AACvC,CAAC;AAED,wEAAwE;AACxE,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAoB,EACpB,UAAiC,EAAE;IAEnC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,QAAQ,CAAC,sCAAsC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IACD,OAAO,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which harnesses is this folder actually used by, and does a command have to
|
|
3
|
+
* say which one it means?
|
|
4
|
+
*
|
|
5
|
+
* A project folder is not one harness's. The same directory can hold
|
|
6
|
+
* `.claude/`, `.reasonix/` and `.pi/` side by side, because the person working
|
|
7
|
+
* in it uses all three. Everything hcm records is already per-target -- an
|
|
8
|
+
* installation is keyed `bundle@target@scope` -- but the *commands* used to
|
|
9
|
+
* assume otherwise: `hcm install my-kit` with no `-t` meant all five harnesses,
|
|
10
|
+
* and `hcm uninstall my-kit` meant every one it could find.
|
|
11
|
+
*
|
|
12
|
+
* That default is fine in a folder set up for one harness and wrong in a folder
|
|
13
|
+
* set up for three, where it silently touches harnesses the user was not
|
|
14
|
+
* thinking about. So: work out which harnesses are here, and when an operation
|
|
15
|
+
* would span more than one of them, make the user say which.
|
|
16
|
+
*
|
|
17
|
+
* Presence is read from two places, because either alone is incomplete:
|
|
18
|
+
*
|
|
19
|
+
* markers directories and files only that harness uses (`core/targets`
|
|
20
|
+
* declares them). This is what finds a harness hcm never installed
|
|
21
|
+
* into -- the usual case, since people set their harnesses up first.
|
|
22
|
+
* ledger what hcm has installed here. This is what finds a harness whose
|
|
23
|
+
* own files have not been created yet.
|
|
24
|
+
*/
|
|
25
|
+
import type { Scope, TargetId } from './types.js';
|
|
26
|
+
/** The word `-t` accepts for "every harness", the explicit form of the old default. */
|
|
27
|
+
export declare const ALL_TARGETS = "all";
|
|
28
|
+
export interface HarnessPresence {
|
|
29
|
+
target: TargetId;
|
|
30
|
+
/** The harness's root for the scope this was detected at. */
|
|
31
|
+
root: string;
|
|
32
|
+
/** Scope-root-relative paths found on disk. Empty when only the ledger knew. */
|
|
33
|
+
markers: string[];
|
|
34
|
+
/** hcm has an installation recorded for this harness in this scope. */
|
|
35
|
+
installed: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The harnesses in use at `scope`, in the order `hcm targets` lists them.
|
|
39
|
+
*
|
|
40
|
+
* Only a harness with real evidence is included -- an empty project has none,
|
|
41
|
+
* which is what keeps the ambiguity gate below quiet in a fresh checkout.
|
|
42
|
+
*/
|
|
43
|
+
export declare function detectHarnesses(scope: Scope, cwd: string): Promise<HarnessPresence[]>;
|
|
44
|
+
/** "Claude Code, Pi and Reasonix" -- for messages about what was found. */
|
|
45
|
+
export declare function describeHarnesses(found: HarnessPresence[]): string;
|
|
46
|
+
/** Why hcm thinks a harness is here, for `hcm targets` and `hcm status`. */
|
|
47
|
+
export declare function describeEvidence(harness: HarnessPresence): string;
|
|
48
|
+
/**
|
|
49
|
+
* Turn the raw `-t` values into target ids: several harnesses at once, each
|
|
50
|
+
* named by id, alias or unambiguous prefix, with `all` meaning every one.
|
|
51
|
+
*
|
|
52
|
+
* -t pi -> [pi]
|
|
53
|
+
* -t claude pi -> [claude-code, pi]
|
|
54
|
+
* -t all -> every harness
|
|
55
|
+
*
|
|
56
|
+
* `all` is how you ask for the blanket behaviour once the gate below starts
|
|
57
|
+
* asking: it means the same thing as naming every harness, and it is recorded
|
|
58
|
+
* as an answer rather than an absence of one.
|
|
59
|
+
*
|
|
60
|
+
* Duplicates are dropped rather than refused -- `-t pi -t pi` and `-t claude
|
|
61
|
+
* claude-code` are the same request said twice, and installing twice into one
|
|
62
|
+
* harness is not a thing anybody means.
|
|
63
|
+
*/
|
|
64
|
+
export declare function expandTargets(values: readonly string[] | undefined): TargetId[] | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* What a command needs answered when it was not told which harness to act on.
|
|
67
|
+
*
|
|
68
|
+
* `available` is what is worth offering -- the harnesses the bundles in this
|
|
69
|
+
* run actually support, not all five. `preselected` is what the menu opens
|
|
70
|
+
* with ticked and what an empty answer takes. `here` is the subset of those
|
|
71
|
+
* this folder is already set up for, which is only there so the menu can say
|
|
72
|
+
* why a line came ticked.
|
|
73
|
+
*/
|
|
74
|
+
export interface TargetQuestion {
|
|
75
|
+
available: TargetId[];
|
|
76
|
+
preselected: TargetId[];
|
|
77
|
+
here: TargetId[];
|
|
78
|
+
}
|
|
79
|
+
/** Answers a `TargetQuestion`. The terminal does it; tests supply their own. */
|
|
80
|
+
export type TargetChooser = (question: TargetQuestion) => Promise<TargetId[]>;
|
|
81
|
+
/**
|
|
82
|
+
* The harnesses this folder is already committed to, in `available` order.
|
|
83
|
+
*
|
|
84
|
+
* The ledger first: a harness hcm has installed into here is one the user has
|
|
85
|
+
* decided about, and re-running `hcm install` almost always means "the same
|
|
86
|
+
* places as last time". Only when nothing has been installed yet does harness
|
|
87
|
+
* *presence* stand in for it -- a folder with a `.claude/` directory and an
|
|
88
|
+
* empty ledger is a Claude Code folder, whoever created that directory.
|
|
89
|
+
*/
|
|
90
|
+
export declare function initializedTargets(scope: Scope, cwd: string, available: readonly TargetId[]): Promise<TargetId[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Settle which harnesses to install into when `-t` did not say.
|
|
93
|
+
*
|
|
94
|
+
* The old answer was "every one of them", which is right in a folder that uses
|
|
95
|
+
* one harness and wrong in a folder that uses three -- and `requireTargetChoice`
|
|
96
|
+
* could only refuse the command, which is a poor thing to do to someone who is
|
|
97
|
+
* sitting at a terminal and can simply be asked. So ask, with what the folder
|
|
98
|
+
* is already set up for ticked.
|
|
99
|
+
*
|
|
100
|
+
* Returns undefined when there was no question to ask -- one harness on offer,
|
|
101
|
+
* no terminal, `--no-prompt` -- and the caller carries on with the behaviour it
|
|
102
|
+
* had before, `requireTargetChoice` gate included.
|
|
103
|
+
*/
|
|
104
|
+
export declare function chooseTargets(options: {
|
|
105
|
+
available: readonly TargetId[];
|
|
106
|
+
scope: Scope;
|
|
107
|
+
cwd: string;
|
|
108
|
+
chooser?: TargetChooser;
|
|
109
|
+
/** False never asks, however interactive the terminal is. */
|
|
110
|
+
prompt?: boolean;
|
|
111
|
+
}): Promise<TargetId[] | undefined>;
|
|
112
|
+
/** The terminal's answer: a ticked menu of the harnesses on offer. */
|
|
113
|
+
export declare const promptForTargets: TargetChooser;
|
|
114
|
+
export interface TargetChoice {
|
|
115
|
+
/** What `-t` said, expanded. Undefined means the user did not say. */
|
|
116
|
+
chosen?: TargetId[];
|
|
117
|
+
/** Every harness the command would touch if nothing narrowed it. */
|
|
118
|
+
affected: TargetId[];
|
|
119
|
+
/** The command line to put in the error, without the `-t` part. */
|
|
120
|
+
command: string;
|
|
121
|
+
scope: Scope;
|
|
122
|
+
cwd: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Refuse an operation that would silently span harnesses the user did not name.
|
|
126
|
+
*
|
|
127
|
+
* Deliberately narrow, so it never gets in the way of an unambiguous command:
|
|
128
|
+
* it fires only when the folder is set up for more than one harness *and* this
|
|
129
|
+
* particular operation would affect more than one. Uninstalling a bundle that
|
|
130
|
+
* only ever went into Claude Code needs no `-t` however many harnesses are
|
|
131
|
+
* configured alongside it.
|
|
132
|
+
*
|
|
133
|
+
* Returns the harnesses found, so callers can go on to report the file overlaps
|
|
134
|
+
* between them without detecting twice.
|
|
135
|
+
*/
|
|
136
|
+
export declare function requireTargetChoice(choice: TargetChoice): Promise<HarnessPresence[]>;
|
|
137
|
+
/**
|
|
138
|
+
* Installing into every harness in a folder that only uses one is not ambiguous
|
|
139
|
+
* -- there is nothing to ask -- but it is almost certainly not what was meant,
|
|
140
|
+
* so say what is about to happen rather than refusing it.
|
|
141
|
+
*/
|
|
142
|
+
export declare function warnIfWiderThanTheFolder(found: HarnessPresence[], chosen: TargetId[] | undefined, affected: TargetId[], command: string, warn: (message: string) => void): void;
|