@indigoai-us/hq-cli 5.31.0 → 5.32.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/dist/commands/group-grants.d.ts +76 -0
- package/dist/commands/group-grants.js +296 -0
- package/dist/commands/pack-install.d.ts +46 -1
- package/dist/commands/pack-install.js +96 -17
- package/dist/commands/packs.d.ts +22 -0
- package/dist/commands/packs.js +406 -0
- package/dist/commands/pkg-list.js +31 -5
- package/dist/index.js +12 -2
- package/dist/utils/pack-contributions.d.ts +87 -0
- package/dist/utils/pack-contributions.js +239 -0
- package/package.json +1 -1
- package/src/commands/group-grants.test.ts +291 -0
- package/src/commands/group-grants.ts +452 -0
- package/src/commands/pack-install.ts +129 -21
- package/src/commands/packs.ts +524 -0
- package/src/commands/pkg-list.ts +34 -3
- package/src/index.ts +12 -0
- package/src/utils/pack-contributions.test.ts +208 -0
- package/src/utils/pack-contributions.ts +303 -0
|
@@ -0,0 +1,524 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hq packs` -- lifecycle for CONTENT packs (the ones installed via
|
|
3
|
+
* `hq install <source>` that live in `core/packages/hq-pack-<name>/`).
|
|
4
|
+
*
|
|
5
|
+
* hq packs list Installed packs + curated catalog, with link health.
|
|
6
|
+
* hq packs update Re-install the latest of an installed pack.
|
|
7
|
+
* hq packs uninstall Un-wire + archive a pack (clean, no dangling symlinks).
|
|
8
|
+
*
|
|
9
|
+
* Distinct from `hq packages ...` (the entitlement-gated REGISTRY system tracked
|
|
10
|
+
* in packages/registry.yaml). Content packs have no registry file -- the
|
|
11
|
+
* filesystem under core/packages/ is the source of truth. Today `hq install`
|
|
12
|
+
* is the only clean content-pack op; this adds the rest.
|
|
13
|
+
*
|
|
14
|
+
* Every subcommand supports `--json` for machine consumers (the HQ Sync
|
|
15
|
+
* menubar app). JSON is also the default when stdout is not a TTY, matching
|
|
16
|
+
* the `hq signals` / `hq sources` convention.
|
|
17
|
+
*
|
|
18
|
+
* Spec: knowledge/public/hq-core/package-yaml-spec.md.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as fs from 'fs';
|
|
22
|
+
import * as path from 'path';
|
|
23
|
+
import * as readline from 'readline';
|
|
24
|
+
import { spawnSync } from 'child_process';
|
|
25
|
+
import { Command } from 'commander';
|
|
26
|
+
import chalk from 'chalk';
|
|
27
|
+
import semverSatisfies from 'semver/functions/satisfies.js';
|
|
28
|
+
import { findHqRoot } from '../utils/manifest.js';
|
|
29
|
+
import {
|
|
30
|
+
classify,
|
|
31
|
+
resolveLatest,
|
|
32
|
+
runScanPackages,
|
|
33
|
+
installPack,
|
|
34
|
+
type LatestResult,
|
|
35
|
+
} from './pack-install.js';
|
|
36
|
+
import {
|
|
37
|
+
contributionLinks,
|
|
38
|
+
linkStatus,
|
|
39
|
+
listInstalledPacks,
|
|
40
|
+
readPackManifest,
|
|
41
|
+
unwirePack,
|
|
42
|
+
readHqVersion,
|
|
43
|
+
readRecommendedPackages,
|
|
44
|
+
packagesDir,
|
|
45
|
+
type InstalledPack,
|
|
46
|
+
type LinkStatus,
|
|
47
|
+
} from '../utils/pack-contributions.js';
|
|
48
|
+
import type { PackContributeKey } from '../types.js';
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// Shared helpers
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
interface CommonOpts {
|
|
55
|
+
json?: boolean;
|
|
56
|
+
hqRoot?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function resolveRoot(opts: CommonOpts): string {
|
|
60
|
+
return opts.hqRoot ? path.resolve(opts.hqRoot) : findHqRoot();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** JSON when --json or when piped (non-TTY); human-readable on a terminal. */
|
|
64
|
+
function wantsJson(opts: CommonOpts): boolean {
|
|
65
|
+
return opts.json === true || !process.stdout.isTTY;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function emitJson(value: unknown): void {
|
|
69
|
+
process.stdout.write(JSON.stringify(value, null, 2) + '\n');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function safeClassify(source?: string): string | null {
|
|
73
|
+
if (!source) return null;
|
|
74
|
+
try {
|
|
75
|
+
return classify(source);
|
|
76
|
+
} catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function evalConditional(expr: string): boolean {
|
|
82
|
+
return spawnSync('bash', ['-c', expr], { stdio: 'ignore' }).status === 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function confirm(question: string): Promise<boolean> {
|
|
86
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
87
|
+
const answer: string = await new Promise((resolve) => {
|
|
88
|
+
rl.question(`${question} [y/N] `, (a) => {
|
|
89
|
+
rl.close();
|
|
90
|
+
resolve(a);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return /^(y|yes)$/i.test(answer.trim());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ---------------------------------------------------------------------------
|
|
97
|
+
// list
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
interface InstalledPackView {
|
|
101
|
+
name: string;
|
|
102
|
+
version?: string;
|
|
103
|
+
publisher?: string;
|
|
104
|
+
source?: string;
|
|
105
|
+
transport: string | null;
|
|
106
|
+
requiresHqCore?: string;
|
|
107
|
+
hqCoreSatisfied: boolean | null;
|
|
108
|
+
contributes: Partial<Record<PackContributeKey, number>>;
|
|
109
|
+
links: Record<LinkStatus, number>;
|
|
110
|
+
brokenLinks: Array<{ key: PackContributeKey; item: string; dst: string }>;
|
|
111
|
+
inCatalog: boolean;
|
|
112
|
+
updateAvailable: boolean | null;
|
|
113
|
+
error?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
interface AvailablePackView {
|
|
117
|
+
source: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
installed: false;
|
|
120
|
+
conditional?: string;
|
|
121
|
+
conditionalStatus: 'pass' | 'fail' | 'unevaluated' | 'none';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
interface PacksListView {
|
|
125
|
+
hqRoot: string;
|
|
126
|
+
hqVersion: string | null;
|
|
127
|
+
installed: InstalledPackView[];
|
|
128
|
+
available: AvailablePackView[];
|
|
129
|
+
warnings: string[];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function buildInstalledView(
|
|
133
|
+
hqRoot: string,
|
|
134
|
+
hqVersion: string | null,
|
|
135
|
+
pack: InstalledPack,
|
|
136
|
+
installedSources: Set<string>,
|
|
137
|
+
checkUpdates: boolean,
|
|
138
|
+
): InstalledPackView {
|
|
139
|
+
if (!pack.manifest) {
|
|
140
|
+
return {
|
|
141
|
+
name: pack.name,
|
|
142
|
+
transport: null,
|
|
143
|
+
hqCoreSatisfied: null,
|
|
144
|
+
contributes: {},
|
|
145
|
+
links: { live: 0, broken: 0, missing: 0, foreign: 0 },
|
|
146
|
+
brokenLinks: [],
|
|
147
|
+
inCatalog: false,
|
|
148
|
+
updateAvailable: null,
|
|
149
|
+
error: pack.error ?? 'unreadable manifest',
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const m = pack.manifest;
|
|
153
|
+
const contributes = m.contributes ?? {};
|
|
154
|
+
const links = contributionLinks(hqRoot, pack.dir, contributes);
|
|
155
|
+
const counts: Record<LinkStatus, number> = { live: 0, broken: 0, missing: 0, foreign: 0 };
|
|
156
|
+
const brokenLinks: InstalledPackView['brokenLinks'] = [];
|
|
157
|
+
for (const link of links) {
|
|
158
|
+
const st = linkStatus(link);
|
|
159
|
+
counts[st]++;
|
|
160
|
+
if (st === 'broken') brokenLinks.push({ key: link.key, item: link.item, dst: link.dst });
|
|
161
|
+
}
|
|
162
|
+
const contributeCounts: Partial<Record<PackContributeKey, number>> = {};
|
|
163
|
+
for (const [key, items] of Object.entries(contributes) as [PackContributeKey, unknown][]) {
|
|
164
|
+
if (Array.isArray(items) && items.length > 0) contributeCounts[key] = items.length;
|
|
165
|
+
}
|
|
166
|
+
const requiresHqCore = m.requires?.hqCore;
|
|
167
|
+
const hqCoreSatisfied =
|
|
168
|
+
hqVersion && requiresHqCore ? semverSatisfies(hqVersion, requiresHqCore) : null;
|
|
169
|
+
|
|
170
|
+
let updateAvailable: boolean | null = null;
|
|
171
|
+
if (checkUpdates && m.source) {
|
|
172
|
+
updateAvailable = resolveLatest(m.source, m.version).updateAvailable;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
name: m.name ?? pack.name,
|
|
177
|
+
version: m.version,
|
|
178
|
+
publisher: m.publisher,
|
|
179
|
+
source: m.source,
|
|
180
|
+
transport: safeClassify(m.source),
|
|
181
|
+
requiresHqCore,
|
|
182
|
+
hqCoreSatisfied,
|
|
183
|
+
contributes: contributeCounts,
|
|
184
|
+
links: counts,
|
|
185
|
+
brokenLinks,
|
|
186
|
+
inCatalog: m.source ? installedSources.has(m.source) : false,
|
|
187
|
+
updateAvailable,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function buildListView(hqRoot: string, checkUpdates: boolean, evalConditionals: boolean): PacksListView {
|
|
192
|
+
const hqVersion = readHqVersion(hqRoot);
|
|
193
|
+
const packs = listInstalledPacks(hqRoot);
|
|
194
|
+
const catalog = readRecommendedPackages(hqRoot);
|
|
195
|
+
const catalogSources = new Set(catalog.map((c) => c.source));
|
|
196
|
+
const warnings: string[] = [];
|
|
197
|
+
|
|
198
|
+
const installed = packs.map((p) =>
|
|
199
|
+
buildInstalledView(hqRoot, hqVersion, p, catalogSources, checkUpdates),
|
|
200
|
+
);
|
|
201
|
+
for (const p of installed) {
|
|
202
|
+
if (p.error) warnings.push(`${p.name}: ${p.error}`);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const installedSources = new Set(
|
|
206
|
+
packs.map((p) => p.manifest?.source).filter((s): s is string => !!s),
|
|
207
|
+
);
|
|
208
|
+
const available: AvailablePackView[] = catalog
|
|
209
|
+
.filter((c) => !installedSources.has(c.source))
|
|
210
|
+
.map((c) => {
|
|
211
|
+
let conditionalStatus: AvailablePackView['conditionalStatus'] = c.conditional
|
|
212
|
+
? 'unevaluated'
|
|
213
|
+
: 'none';
|
|
214
|
+
if (c.conditional && evalConditionals) {
|
|
215
|
+
conditionalStatus = evalConditional(c.conditional) ? 'pass' : 'fail';
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
source: c.source,
|
|
219
|
+
description: c.description,
|
|
220
|
+
installed: false,
|
|
221
|
+
conditional: c.conditional,
|
|
222
|
+
conditionalStatus,
|
|
223
|
+
};
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return { hqRoot, hqVersion, installed, available, warnings };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function printListHuman(view: PacksListView): void {
|
|
230
|
+
console.log(chalk.bold(`\nHQ packs (${view.hqRoot}, hqCore ${view.hqVersion ?? '?'})\n`));
|
|
231
|
+
if (view.installed.length === 0) {
|
|
232
|
+
console.log(chalk.dim(' No content packs installed.\n'));
|
|
233
|
+
} else {
|
|
234
|
+
console.log(chalk.bold('Installed:'));
|
|
235
|
+
for (const p of view.installed) {
|
|
236
|
+
if (p.error) {
|
|
237
|
+
console.log(` ${chalk.red(p.name)} ${chalk.dim('(' + p.error + ')')}`);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const broken = p.links.broken > 0 ? chalk.red(` ! ${p.links.broken} broken link(s)`) : '';
|
|
241
|
+
const upd = p.updateAvailable ? chalk.yellow(' ^ update available') : '';
|
|
242
|
+
const hq = p.hqCoreSatisfied === false ? chalk.red(' x hqCore mismatch') : '';
|
|
243
|
+
console.log(` ${chalk.green(p.name)}@${p.version ?? '?'} ${chalk.dim(p.transport ?? '')}${upd}${hq}${broken}`);
|
|
244
|
+
}
|
|
245
|
+
console.log();
|
|
246
|
+
}
|
|
247
|
+
if (view.available.length > 0) {
|
|
248
|
+
console.log(chalk.bold('Available (curated):'));
|
|
249
|
+
for (const a of view.available) {
|
|
250
|
+
const gate =
|
|
251
|
+
a.conditionalStatus === 'fail'
|
|
252
|
+
? chalk.dim(' (gated off)')
|
|
253
|
+
: a.conditionalStatus === 'unevaluated' && a.conditional
|
|
254
|
+
? chalk.dim(' (conditional)')
|
|
255
|
+
: '';
|
|
256
|
+
console.log(` ${chalk.cyan(a.source)}${gate}`);
|
|
257
|
+
if (a.description) console.log(chalk.dim(` ${a.description}`));
|
|
258
|
+
}
|
|
259
|
+
console.log(chalk.dim('\n Install with: hq install <source>\n'));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// update
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
|
|
267
|
+
interface UpdateCheck {
|
|
268
|
+
name: string;
|
|
269
|
+
transport: string;
|
|
270
|
+
current?: string;
|
|
271
|
+
latest?: string;
|
|
272
|
+
updateAvailable: boolean | null;
|
|
273
|
+
applied: boolean;
|
|
274
|
+
reason?: string;
|
|
275
|
+
error?: string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
interface UpdateOpts extends CommonOpts {
|
|
279
|
+
checkOnly?: boolean;
|
|
280
|
+
yes?: boolean;
|
|
281
|
+
allowHooks?: boolean;
|
|
282
|
+
branch?: boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function runUpdate(name: string | undefined, opts: UpdateOpts): Promise<UpdateCheck[]> {
|
|
286
|
+
const hqRoot = resolveRoot(opts);
|
|
287
|
+
let packs = listInstalledPacks(hqRoot).filter((p) => p.manifest);
|
|
288
|
+
if (name) {
|
|
289
|
+
packs = packs.filter((p) => (p.manifest?.name ?? p.name) === name);
|
|
290
|
+
if (packs.length === 0) {
|
|
291
|
+
return [{ name, transport: 'unknown', updateAvailable: null, applied: false, error: 'not installed' }];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const results: UpdateCheck[] = [];
|
|
296
|
+
for (const pack of packs) {
|
|
297
|
+
const m = pack.manifest!;
|
|
298
|
+
const source = m.source;
|
|
299
|
+
const pname = m.name ?? pack.name;
|
|
300
|
+
if (!source) {
|
|
301
|
+
results.push({ name: pname, transport: 'unknown', updateAvailable: null, applied: false, error: 'no stamped source -- cannot update' });
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
const probe: LatestResult = resolveLatest(source, m.version);
|
|
305
|
+
const base: UpdateCheck = {
|
|
306
|
+
name: pname,
|
|
307
|
+
transport: probe.transport,
|
|
308
|
+
current: probe.current,
|
|
309
|
+
latest: probe.latest,
|
|
310
|
+
updateAvailable: probe.updateAvailable,
|
|
311
|
+
applied: false,
|
|
312
|
+
error: probe.error,
|
|
313
|
+
};
|
|
314
|
+
if (opts.checkOnly) {
|
|
315
|
+
results.push(base);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
// Apply only when there's a known update, or when explicitly named (force re-sync).
|
|
319
|
+
if (probe.updateAvailable === false && !name) {
|
|
320
|
+
results.push({ ...base, reason: 'already current' });
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
// Un-wire old contributions first so a contribution dropped by the new
|
|
325
|
+
// version doesn't leave a dangling host symlink. installPack re-wires.
|
|
326
|
+
unwirePack(hqRoot, pack.dir, m.contributes ?? {});
|
|
327
|
+
const prevCwd = process.cwd();
|
|
328
|
+
if (opts.hqRoot) process.chdir(hqRoot); // installPack resolves via findHqRoot()
|
|
329
|
+
try {
|
|
330
|
+
await installPack(source, {
|
|
331
|
+
allowHooks: opts.yes || opts.allowHooks,
|
|
332
|
+
followBranch: opts.branch,
|
|
333
|
+
quiet: wantsJson(opts),
|
|
334
|
+
});
|
|
335
|
+
} finally {
|
|
336
|
+
if (opts.hqRoot) process.chdir(prevCwd);
|
|
337
|
+
}
|
|
338
|
+
results.push({ ...base, applied: true });
|
|
339
|
+
} catch (e) {
|
|
340
|
+
results.push({ ...base, applied: false, error: (e as Error).message });
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return results;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ---------------------------------------------------------------------------
|
|
347
|
+
// uninstall
|
|
348
|
+
// ---------------------------------------------------------------------------
|
|
349
|
+
|
|
350
|
+
interface UninstallResult {
|
|
351
|
+
name: string;
|
|
352
|
+
archived: string | null;
|
|
353
|
+
unlinked: Array<{ key: PackContributeKey; item: string; dst: string }>;
|
|
354
|
+
skipped: Array<{ key: PackContributeKey; item: string; dst: string; reason: string }>;
|
|
355
|
+
rescan: 'ok' | 'skipped';
|
|
356
|
+
workersRegistryRegenerated: boolean;
|
|
357
|
+
sideEffectsSuggested: string[];
|
|
358
|
+
warnings: string[];
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
interface UninstallOpts extends CommonOpts {
|
|
362
|
+
yes?: boolean;
|
|
363
|
+
archive?: boolean; // commander sets false for --no-archive
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function archiveTimestamp(): string {
|
|
367
|
+
return new Date().toISOString().replace(/[:.]/g, '-').replace('T', '_').slice(0, 19);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
async function runUninstall(name: string, opts: UninstallOpts): Promise<UninstallResult> {
|
|
371
|
+
const hqRoot = resolveRoot(opts);
|
|
372
|
+
const packDir = path.join(packagesDir(hqRoot), name);
|
|
373
|
+
if (!fs.existsSync(packDir)) {
|
|
374
|
+
throw new Error(`Pack "${name}" is not installed (no core/packages/${name}/).`);
|
|
375
|
+
}
|
|
376
|
+
const warnings: string[] = [];
|
|
377
|
+
const { manifest } = readPackManifest(packDir);
|
|
378
|
+
const contributes = manifest?.contributes ?? {};
|
|
379
|
+
if (!manifest) {
|
|
380
|
+
warnings.push('package.yaml unreadable -- host symlinks could not be computed precisely; ran a re-scan to reconcile.');
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// 1. Un-wire only our symlinks.
|
|
384
|
+
const { unlinked, skipped } = unwirePack(hqRoot, packDir, contributes);
|
|
385
|
+
|
|
386
|
+
// 2. Archive (or delete) the pack dir -- BEFORE re-scan so it isn't re-wired.
|
|
387
|
+
let archived: string | null = null;
|
|
388
|
+
if (opts.archive === false) {
|
|
389
|
+
fs.rmSync(packDir, { recursive: true, force: true });
|
|
390
|
+
} else {
|
|
391
|
+
const dest = path.join(packagesDir(hqRoot), '.archive', `${name}-${archiveTimestamp()}`);
|
|
392
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
393
|
+
fs.renameSync(packDir, dest);
|
|
394
|
+
archived = path.relative(hqRoot, dest);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// 3. Re-assert remaining packs' links (handles two packs sharing a contribution).
|
|
398
|
+
let rescan: 'ok' | 'skipped' = 'skipped';
|
|
399
|
+
try {
|
|
400
|
+
// Quiet: uninstall emits its own summary / JSON; keep scan stdout off ours.
|
|
401
|
+
runScanPackages(hqRoot, { quiet: true });
|
|
402
|
+
rescan = 'ok';
|
|
403
|
+
} catch {
|
|
404
|
+
rescan = 'skipped';
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// 4. Regenerate the workers registry if this pack contributed workers.
|
|
408
|
+
let workersRegistryRegenerated = false;
|
|
409
|
+
const contributedWorkers = Array.isArray(contributes.workers) && contributes.workers.length > 0;
|
|
410
|
+
if (contributedWorkers) {
|
|
411
|
+
const gen = path.join(hqRoot, 'core', 'scripts', 'generate-workers-registry.sh');
|
|
412
|
+
if (fs.existsSync(gen)) {
|
|
413
|
+
const r = spawnSync('bash', [gen], { cwd: hqRoot, env: { ...process.env, HQ_ROOT: hqRoot }, stdio: 'ignore' });
|
|
414
|
+
workersRegistryRegenerated = r.status === 0;
|
|
415
|
+
if (!workersRegistryRegenerated) warnings.push('generate-workers-registry.sh exited non-zero');
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const sideEffectsSuggested = ['master-sync', 'qmd-reindex'];
|
|
420
|
+
if (contributedWorkers && !workersRegistryRegenerated) sideEffectsSuggested.push('workers-registry');
|
|
421
|
+
|
|
422
|
+
return {
|
|
423
|
+
name,
|
|
424
|
+
archived,
|
|
425
|
+
unlinked,
|
|
426
|
+
skipped,
|
|
427
|
+
rescan,
|
|
428
|
+
workersRegistryRegenerated,
|
|
429
|
+
sideEffectsSuggested,
|
|
430
|
+
warnings,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// ---------------------------------------------------------------------------
|
|
435
|
+
// Registration
|
|
436
|
+
// ---------------------------------------------------------------------------
|
|
437
|
+
|
|
438
|
+
export function registerPacksCommand(parent: Command): void {
|
|
439
|
+
const packs = parent.command('packs').description('Content-pack lifecycle (install via `hq install`)');
|
|
440
|
+
|
|
441
|
+
packs
|
|
442
|
+
.command('list')
|
|
443
|
+
.alias('ls')
|
|
444
|
+
.description('List installed content packs and the curated catalog')
|
|
445
|
+
.option('--json', 'Machine-readable JSON output')
|
|
446
|
+
.option('--hq-root <path>', 'HQ root (default: auto-detect)')
|
|
447
|
+
.option('--check-updates', 'Probe each pack for available updates (network I/O)')
|
|
448
|
+
.option('--eval-conditionals', 'Evaluate catalog conditional predicates (runs bash)')
|
|
449
|
+
.action(
|
|
450
|
+
async (opts: CommonOpts & { checkUpdates?: boolean; evalConditionals?: boolean }) => {
|
|
451
|
+
try {
|
|
452
|
+
const view = buildListView(resolveRoot(opts), !!opts.checkUpdates, !!opts.evalConditionals);
|
|
453
|
+
if (wantsJson(opts)) emitJson(view);
|
|
454
|
+
else printListHuman(view);
|
|
455
|
+
} catch (e) {
|
|
456
|
+
console.error(chalk.red('packs list failed:'), (e as Error).message);
|
|
457
|
+
process.exit(1);
|
|
458
|
+
}
|
|
459
|
+
},
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
packs
|
|
463
|
+
.command('update [name]')
|
|
464
|
+
.description('Update an installed content pack (re-install latest)')
|
|
465
|
+
.option('--json', 'Machine-readable JSON output')
|
|
466
|
+
.option('--hq-root <path>', 'HQ root (default: auto-detect)')
|
|
467
|
+
.option('--check-only', 'Report availability without installing')
|
|
468
|
+
.option('-y, --yes', 'Non-interactive (implies --allow-hooks)')
|
|
469
|
+
.option('--allow-hooks', 'Install pack hooks without prompting')
|
|
470
|
+
.option('--branch', 'Follow the source branch instead of SHA-pinning')
|
|
471
|
+
.action(async (name: string | undefined, opts: UpdateOpts) => {
|
|
472
|
+
try {
|
|
473
|
+
const results = await runUpdate(name, opts);
|
|
474
|
+
if (wantsJson(opts)) {
|
|
475
|
+
emitJson({ checked: results, updatedCount: results.filter((r) => r.applied).length });
|
|
476
|
+
} else {
|
|
477
|
+
for (const r of results) {
|
|
478
|
+
if (r.error) console.log(` ${chalk.red(r.name)}: ${r.error}`);
|
|
479
|
+
else if (r.applied) console.log(` ${chalk.green(r.name)}: updated`);
|
|
480
|
+
else if (r.updateAvailable) console.log(` ${chalk.yellow(r.name)}: ${r.current ?? '?'} -> ${r.latest ?? '?'} available`);
|
|
481
|
+
else console.log(` ${chalk.dim(r.name)}: ${r.reason ?? 'current'}`);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
} catch (e) {
|
|
485
|
+
console.error(chalk.red('packs update failed:'), (e as Error).message);
|
|
486
|
+
process.exit(1);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
packs
|
|
491
|
+
.command('uninstall <name>')
|
|
492
|
+
.alias('remove')
|
|
493
|
+
.description('Un-wire and archive an installed content pack')
|
|
494
|
+
.option('--json', 'Machine-readable JSON output')
|
|
495
|
+
.option('--hq-root <path>', 'HQ root (default: auto-detect)')
|
|
496
|
+
.option('-y, --yes', 'Skip confirmation')
|
|
497
|
+
.option('--no-archive', 'Delete instead of archiving')
|
|
498
|
+
.action(async (name: string, opts: UninstallOpts) => {
|
|
499
|
+
try {
|
|
500
|
+
if (!opts.yes) {
|
|
501
|
+
if (!process.stdout.isTTY) {
|
|
502
|
+
throw new Error('Refusing to uninstall without --yes in non-interactive mode.');
|
|
503
|
+
}
|
|
504
|
+
const ok = await confirm(`Uninstall pack "${name}"? This removes its host symlinks.`);
|
|
505
|
+
if (!ok) {
|
|
506
|
+
console.log(chalk.dim('Aborted.'));
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
const result = await runUninstall(name, opts);
|
|
511
|
+
if (wantsJson(opts)) {
|
|
512
|
+
emitJson(result);
|
|
513
|
+
} else {
|
|
514
|
+
console.log(chalk.green(`\nOK Uninstalled ${name}`));
|
|
515
|
+
console.log(chalk.dim(` Unlinked ${result.unlinked.length} symlink(s); archived to ${result.archived ?? '(deleted)'}.`));
|
|
516
|
+
if (result.skipped.length > 0) console.log(chalk.dim(` Left ${result.skipped.length} non-owned path(s) in place.`));
|
|
517
|
+
for (const w of result.warnings) console.log(chalk.yellow(` ! ${w}`));
|
|
518
|
+
}
|
|
519
|
+
} catch (e) {
|
|
520
|
+
console.error(chalk.red('packs uninstall failed:'), (e as Error).message);
|
|
521
|
+
process.exit(1);
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}
|
package/src/commands/pkg-list.ts
CHANGED
|
@@ -20,9 +20,10 @@ export function registerPackageListCommand(parent: Command): void {
|
|
|
20
20
|
.command('list')
|
|
21
21
|
.alias('ls')
|
|
22
22
|
.description('List installed and available packages')
|
|
23
|
-
.
|
|
23
|
+
.option('--json', 'Machine-readable JSON output')
|
|
24
|
+
.action(async (opts: { json?: boolean }) => {
|
|
24
25
|
try {
|
|
25
|
-
await listPackages();
|
|
26
|
+
await listPackages(opts.json === true || !process.stdout.isTTY);
|
|
26
27
|
} catch (error) {
|
|
27
28
|
console.error(
|
|
28
29
|
chalk.red('List failed:'),
|
|
@@ -33,7 +34,37 @@ export function registerPackageListCommand(parent: Command): void {
|
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
async function
|
|
37
|
+
async function gatherRegistryPackages(): Promise<{
|
|
38
|
+
installed: ReturnType<typeof readRegistry>;
|
|
39
|
+
available: EntitlementEntry[];
|
|
40
|
+
offline: boolean;
|
|
41
|
+
}> {
|
|
42
|
+
const hqRoot = resolveDefaultHqRoot({ onMissing: 'throw' });
|
|
43
|
+
const installed = readRegistry(hqRoot);
|
|
44
|
+
let entitlements: EntitlementEntry[] = [];
|
|
45
|
+
let offline = false;
|
|
46
|
+
try {
|
|
47
|
+
const cached = loadCachedTokens();
|
|
48
|
+
if (cached && !isExpiring(cached, 120)) {
|
|
49
|
+
const client = new RegistryClient(getRegistryUrl(), cached.accessToken);
|
|
50
|
+
const result = await client.getMyEntitlements();
|
|
51
|
+
entitlements = result.entitlements;
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
offline = true;
|
|
55
|
+
}
|
|
56
|
+
const installedSlugs = new Set(installed.map((p) => p.slug));
|
|
57
|
+
const available = entitlements.filter((e) => !installedSlugs.has(e.slug));
|
|
58
|
+
return { installed, available, offline };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function listPackages(json: boolean): Promise<void> {
|
|
62
|
+
if (json) {
|
|
63
|
+
const { installed, available, offline } = await gatherRegistryPackages();
|
|
64
|
+
process.stdout.write(JSON.stringify({ installed, available, offline }, null, 2) + '\n');
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
37
68
|
const hqRoot = resolveDefaultHqRoot({ onMissing: 'throw' });
|
|
38
69
|
const installed = readRegistry(hqRoot);
|
|
39
70
|
|
package/src/index.ts
CHANGED
|
@@ -23,11 +23,13 @@ import { registerPackageInstallCommand } from "./commands/pkg-install.js";
|
|
|
23
23
|
import { registerPackageRemoveCommand } from "./commands/pkg-remove.js";
|
|
24
24
|
import { registerPackageUpdateCommand } from "./commands/pkg-update.js";
|
|
25
25
|
import { registerPackageListCommand } from "./commands/pkg-list.js";
|
|
26
|
+
import { registerPacksCommand } from "./commands/packs.js";
|
|
26
27
|
import { registerTeamSyncCommand } from "./commands/team-sync.js";
|
|
27
28
|
import { registerAuthCommands } from "./commands/auth.js";
|
|
28
29
|
import { registerSecretsCommand } from "./commands/secrets.js";
|
|
29
30
|
import { registerRunCommand } from "./commands/run.js";
|
|
30
31
|
import { registerGroupsCommand } from "./commands/groups.js";
|
|
32
|
+
import { registerGroupGrantsCommand } from "./commands/group-grants.js";
|
|
31
33
|
import { registerFilesCommand } from "./commands/files.js";
|
|
32
34
|
import { registerFilesBrowseCommands } from "./commands/files-browse.js";
|
|
33
35
|
import { registerMembersCommand } from "./commands/members.js";
|
|
@@ -87,6 +89,12 @@ registerPackageRemoveCommand(packagesCmd);
|
|
|
87
89
|
registerPackageUpdateCommand(packagesCmd);
|
|
88
90
|
registerPackageListCommand(packagesCmd);
|
|
89
91
|
|
|
92
|
+
// Content-pack lifecycle (core/packages/hq-pack-*). Distinct from the registry
|
|
93
|
+
// `packages` system above. Available as both `hq packages packs …` (grouped)
|
|
94
|
+
// and `hq packs …` (top-level convenience).
|
|
95
|
+
registerPacksCommand(packagesCmd);
|
|
96
|
+
registerPacksCommand(program);
|
|
97
|
+
|
|
90
98
|
// Top-level shortcuts for package commands
|
|
91
99
|
// "hq install <slug>" = "hq packages install <slug>"
|
|
92
100
|
// "hq remove <slug>" = "hq packages remove <slug>"
|
|
@@ -131,6 +139,10 @@ registerRunCommand(program);
|
|
|
131
139
|
// Groups management (subcommand group — hq groups create|delete|add|remove|list|members)
|
|
132
140
|
registerGroupsCommand(program);
|
|
133
141
|
|
|
142
|
+
// Cross-company group grants (subcommand group —
|
|
143
|
+
// hq group-grants grant|revoke|outbound|inbound)
|
|
144
|
+
registerGroupGrantsCommand(program);
|
|
145
|
+
|
|
134
146
|
// Files ACL management (subcommand group — hq files share|unshare|acl)
|
|
135
147
|
// `registerFilesCommand` returns the `files` group so we can attach the
|
|
136
148
|
// browse-vs-sync subcommands (`hq files browse`/`cat`) onto the same group.
|