@yasaswy.nagavolu/agents 0.8.2 → 0.9.1

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/README.md CHANGED
@@ -19,6 +19,13 @@ any repo file is left unclaimed by a bundle or `internal[]`.
19
19
  npx @yasaswy.nagavolu/agents install
20
20
  ```
21
21
 
22
+ In PowerShell, quote the package name (`@` collides with the splatting
23
+ operator — harmless elsewhere, required here):
24
+
25
+ ```powershell
26
+ npx '@yasaswy.nagavolu/agents' install
27
+ ```
28
+
22
29
  or install the CLI globally:
23
30
 
24
31
  ```bash
@@ -30,11 +37,18 @@ agents-cli install
30
37
 
31
38
  - `agents-cli --version` — print the installed CLI version
32
39
  - `agents-cli install` — in a terminal (TTY), opens the interactive bundle
33
- menu: `↑`/`↓` move, `space` toggles, `a` selects all, `enter` confirms,
34
- `q`/`Ctrl-C` cancels. If raw-mode keypress handling isn't available, it
35
- falls back to a numbered prompt (`1,3,5` / `a` / blank to quit) — same
36
- underlying selection logic either way. Piped/non-interactive (CI) input
37
- instead prints the bundle list and instructs `--bundle` usage; exits 0.
40
+ menu: `↑`/`↓`/`j`/`k` move, `PgUp`/`PgDn` jump 5 rows, `space` toggles, `a`
41
+ selects all, `enter` confirms, `q`/`Ctrl-C` cancels. A live detail pane
42
+ below the list always shows what the highlighted bundle installs — item
43
+ counts by kind, real destination paths, MCP servers it registers,
44
+ component deps, secrets it will prompt for, and an approximate file
45
+ count/size. If raw-mode keypress handling isn't available, it falls back
46
+ to a numbered prompt (`1,3,5` / `a` / blank to quit) — same underlying
47
+ selection logic either way. Piped/non-interactive (CI) input instead
48
+ prints the bundle list and instructs `--bundle` usage; exits 0. Colors and
49
+ the fancy layout are on for a real TTY and off (plain text) when
50
+ `NO_COLOR` is set — see [The interactive menu](#the-interactive-menu)
51
+ below for what it looks like.
38
52
  - `agents-cli install --advanced` — interactive menu over **every** bundle
39
53
  (not just the public/non-advanced basic set), and for each bundle you pick,
40
54
  a second checkbox lets you deselect individual items within it (including
@@ -61,6 +75,64 @@ agents-cli install
61
75
  [Updating](#updating) below.
62
76
  - `agents-cli --help` — show usage
63
77
 
78
+ ### The interactive menu
79
+
80
+ In a color-capable terminal, `agents-cli install` looks roughly like this
81
+ (`✓`/colors omitted from this plain-text README, but selected rows get a
82
+ green check, the cursor row is highlighted, and each bundle that needs a
83
+ component or asks for a secret gets a dim `↳` hint line of its own directly
84
+ below the title — `needs: ...` is yellow, `asks: ...` is cyan (a
85
+ component-owned secret like LiteLLM's is tagged `(component)`), and
86
+ `[passthrough]` is magenta; bundles with nothing to show stay one line):
87
+
88
+ ```
89
+ @yasaswy.nagavolu/agents v0.9.1
90
+ Select bundles to install
91
+
92
+ [ ] Session Tools — Resume past Claude Code sessions by name and archive session transcripts to markdown
93
+ [ ] Shipping — Ship code changes end-to-end: sync, test, commit, push, and file the GitLab issue update in one skill
94
+ ↳ asks: GITLAB_TOKEN
95
+ ❯ [✓] Reddit Reader — Read Reddit posts/threads into Claude Code from a URL, with a deterministic prompt-intent nudge
96
+ ↳ asks: REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USER_AGENT
97
+ [ ] Skill Authoring — code-is-law: turn skill/agent-file prose rules into an enforced PostToolUse lint
98
+
99
+ ────────────────────────────────────────────────────────────────
100
+ Reddit Reader — selected
101
+ 1 skill, 2 hooks (8 files, 201.5 KB)
102
+ → ~/.claude/skills/read-reddit-post
103
+ → ~/.claude/proxy/reddit_intent_hook.py
104
+ Asks: REDDIT_CLIENT_ID (optional), REDDIT_CLIENT_SECRET (optional), REDDIT_USER_AGENT (optional)
105
+
106
+
107
+ ────────────────────────────────────────────────────────────────
108
+ ↑/↓/j/k move PgUp/PgDn jump space toggle a all enter confirm q quit
109
+ ```
110
+
111
+ Once you confirm a selection, each bundle installs with a determinate
112
+ progress bar (file counts are known up front from the manifest), then a
113
+ one-line summary:
114
+
115
+ ```
116
+ Installing Visual Review ━━━━━━━━━━━━━━━━╸─────── 42/61 files
117
+ ✓ visual-review — 61 file(s) written, 0 unchanged, 1.2 MB, installed to C:/Users/you/.claude
118
+ ✓ wired 3 hook(s) into C:/Users/you/.claude/settings.json
119
+ ```
120
+
121
+ After every requested bundle finishes, a final summary recaps what landed
122
+ where and what's next:
123
+
124
+ ```
125
+ Summary
126
+ ✓ Reddit Reader — 8 file(s), 201.5 KB, 1 hook(s) wired
127
+
128
+ Installed to C:/Users/you/.claude. Next: agents-cli secrets to fill in any skipped secrets, agents-cli update --yes to refresh later.
129
+ ```
130
+
131
+ `NO_COLOR=1` (or a non-TTY stdout) strips all color from every line above
132
+ but keeps the same layout and information; a terminal that can't do raw-mode
133
+ keypress handling at all falls back further, to the plain numbered prompt
134
+ described above.
135
+
64
136
  ### Bundle dispositions in the menu
65
137
 
66
138
  - **installable** — installs immediately, whether or not the bundle declares
@@ -257,6 +329,13 @@ is:
257
329
  npx @yasaswy.nagavolu/agents@latest update
258
330
  ```
259
331
 
332
+ In PowerShell, quote the package name (`@` collides with the splatting
333
+ operator — harmless elsewhere, required here):
334
+
335
+ ```powershell
336
+ npx '@yasaswy.nagavolu/agents@latest' update
337
+ ```
338
+
260
339
  Every installed file is compared three ways — its hash in the shipped
261
340
  source, its hash in `<target-dir>/agents-ledger.json` (what was last
262
341
  installed), and its actual on-disk hash:
package/bin/cli.js CHANGED
@@ -17,15 +17,32 @@ const { WiringError } = require('../lib/wiring');
17
17
  const {
18
18
  basicMenuBundles,
19
19
  advancedMenuBundles,
20
+ describeBundleHints,
20
21
  describeBundleRow,
21
22
  describeBundleItems,
22
23
  planSelection,
24
+ deriveBundleDetails,
23
25
  } = require('../lib/menu');
24
- const { pickBundles } = require('../lib/tty-menu');
25
- const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMissingSecrets } = require('../lib/secretsPrompt');
26
+ const { pickBundles, buildHintLine, HINT_INDENT } = require('../lib/tty-menu');
27
+ const { supportsColor, createStyler, renderBar, formatBytes } = require('../lib/ansi');
28
+ const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMissingSecrets, maskValue, askChoice } = require('../lib/secretsPrompt');
29
+ const { envPath, readSecrets, removeSecret } = require('../lib/secretsStore');
26
30
  const { runSelfProfilePostInstall } = require('../lib/selfProfile');
27
31
 
28
32
  const PACKAGE_ROOT = path.join(__dirname, '..');
33
+ // One styler for the whole process: colors on only for a real TTY stdout
34
+ // with no NO_COLOR set (see lib/ansi.js). Every console.log below that
35
+ // wants color routes through this — it's a plain passthrough (no codes)
36
+ // otherwise, so nothing needs its own TTY check.
37
+ const ansi = createStyler(supportsColor());
38
+
39
+ /** A short pip-style status marker: colored ✓/… when ansi is enabled, plain-ASCII when not (NO_COLOR/non-TTY). */
40
+ function mark(kind) {
41
+ if (kind === 'ok') return ansi.enabled ? ansi.green('✓') : 'OK:';
42
+ if (kind === 'skip') return ansi.enabled ? ansi.yellow('•') : '-';
43
+ if (kind === 'fail') return ansi.enabled ? ansi.red('✗') : 'FAILED:';
44
+ return ansi.enabled ? ansi.dim('·') : '-';
45
+ }
29
46
 
30
47
  function printHelp() {
31
48
  console.log(`${pkg.name} v${pkg.version}
@@ -155,6 +172,8 @@ function listBundles(profile = 'public') {
155
172
  console.log('Available bundles:');
156
173
  for (const bundle of bundles) {
157
174
  console.log(` ${bundle.key} — ${bundle.summary}`);
175
+ const hintLine = buildHintLine(describeBundleHints(bundle, manifest), ansi);
176
+ if (hintLine) console.log(`${HINT_INDENT}${hintLine}`);
158
177
  }
159
178
  console.log('\nRun: agents-cli install --bundle <key> --yes');
160
179
  return 0;
@@ -212,7 +231,30 @@ function runSelfProfileStepsIfNeeded({ profile, targetDir }) {
212
231
  return result;
213
232
  }
214
233
 
215
- function installOneBundle({ bundleKey, targetDir, targetConfig, itemPaths }) {
234
+ /**
235
+ * Builds an install.js progress callback that renders a live, in-place
236
+ * (\r-redrawn) pip-style bar while files are copied — but only when stdout
237
+ * is a real TTY. On a non-TTY stdout (piped/CI/logged) this is a no-op:
238
+ * install.js's per-file events simply go nowhere, and the plain one-line
239
+ * summary printed after installOneBundle's installBundle() call is the only
240
+ * output, matching pre-progress-bar behavior exactly. Colors within the bar
241
+ * itself further degrade under NO_COLOR (module-level `ansi`), independent
242
+ * of whether the bar renders at all.
243
+ */
244
+ function createProgressRenderer(title) {
245
+ const showProgress = !!process.stdout.isTTY;
246
+ return (event) => {
247
+ if (!showProgress || event.type !== 'file' || event.total === 0) return;
248
+ const bar = renderBar(event.index, event.total, { width: 24 });
249
+ const done = event.index >= event.total;
250
+ const coloredBar = ansi.enabled ? (done ? ansi.green(bar) : ansi.cyan(bar)) : bar;
251
+ const line = `Installing ${ansi.bold(title)} ${coloredBar} ${event.index}/${event.total} files`;
252
+ process.stdout.write(`\r${ansi.clearLine()}${line}`);
253
+ if (done) process.stdout.write('\n');
254
+ };
255
+ }
256
+
257
+ function installOneBundle({ bundleKey, bundleTitle, targetDir, targetConfig, itemPaths }) {
216
258
  const result = installBundle({
217
259
  packageRoot: PACKAGE_ROOT,
218
260
  bundleKey,
@@ -220,53 +262,56 @@ function installOneBundle({ bundleKey, targetDir, targetConfig, itemPaths }) {
220
262
  cliVersion: pkg.version,
221
263
  itemPaths,
222
264
  mcpConfigPath: targetConfig,
265
+ progress: createProgressRenderer(bundleTitle || bundleKey),
223
266
  });
267
+ const sizeSuffix = result.bytesWritten ? `, ${formatBytes(result.bytesWritten)}` : '';
224
268
  if (result.unchanged) {
225
- console.log(`Bundle "${result.bundle}" already up to date at ${result.targetBase} (no changes).`);
269
+ console.log(`${mark('skip')} "${result.bundle}" already up to date at ${result.targetBase} (no changes).`);
226
270
  } else {
227
271
  console.log(
228
- `Bundle "${result.bundle}" installed to ${result.targetBase}: ` +
229
- `${result.filesWritten} file(s) written, ${result.filesUnchanged} unchanged.`
272
+ `${mark('ok')} ${ansi.bold(result.bundle)} — ${result.filesWritten} file(s) written, ` +
273
+ `${result.filesUnchanged} unchanged${sizeSuffix}, installed to ${result.targetBase}`
230
274
  );
231
275
  }
232
276
  if (result.hooksWired.length > 0) {
233
- console.log(` Wired ${result.hooksWired.length} hook(s) into ${result.targetBase}/settings.json.`);
277
+ console.log(` ${mark('ok')} wired ${result.hooksWired.length} hook(s) into ${result.targetBase}/settings.json`);
234
278
  }
235
279
  if (result.settingsBackupFile) {
236
- console.log(` Backed up existing settings.json to ${result.settingsBackupFile} before this CLI's first write.`);
280
+ console.log(` ${mark()} backed up existing settings.json to ${result.settingsBackupFile} before this CLI's first write`);
237
281
  }
238
282
  if (result.hooksSkippedNoPython.length > 0) {
239
283
  const names = result.hooksSkippedNoPython.map((h) => h.path).join(', ');
240
284
  console.log(
241
- ` Skipped wiring ${result.hooksSkippedNoPython.length} Python hook(s) (${names}): no python3/python found on PATH. ` +
285
+ ` ${mark('skip')} skipped wiring ${result.hooksSkippedNoPython.length} Python hook(s) (${names}): no python3/python found on PATH. ` +
242
286
  `Install Python, then re-run: agents-cli install --bundle ${result.bundle} --yes`
243
287
  );
244
288
  }
245
289
  if (result.mcpWired.length > 0) {
246
290
  const names = result.mcpWired.map((m) => m.name).join(', ');
247
- console.log(` Wired ${result.mcpWired.length} MCP server(s) (${names}) into ${result.mcpConfigPath}.`);
291
+ console.log(` ${mark('ok')} wired ${result.mcpWired.length} MCP server(s) (${names}) into ${result.mcpConfigPath}`);
248
292
  }
249
293
  if (result.mcpBackupFile) {
250
- console.log(` Backed up existing MCP config to ${result.mcpBackupFile} before this CLI's first write.`);
294
+ console.log(` ${mark()} backed up existing MCP config to ${result.mcpBackupFile} before this CLI's first write`);
251
295
  }
252
296
  if (result.mcpSkippedNoSecret.length > 0) {
253
297
  const names = result.mcpSkippedNoSecret.map((m) => m.name).join(', ');
254
- console.log(` Skipped wiring ${result.mcpSkippedNoSecret.length} MCP server(s) (${names}): required secret not set.`);
298
+ console.log(` ${mark('skip')} skipped wiring ${result.mcpSkippedNoSecret.length} MCP server(s) (${names}): required secret not set`);
255
299
  }
256
300
  for (const component of result.components || []) {
257
301
  if (component.status === 'present') {
258
- console.log(` Component "${component.key}": already on PATH.`);
302
+ console.log(` ${mark('ok')} component "${component.key}": already on PATH`);
259
303
  } else if (component.status === 'installed') {
260
- console.log(` Component "${component.key}": installed via ${component.tool}.`);
304
+ console.log(` ${mark('ok')} component "${component.key}": installed via ${component.tool}`);
261
305
  } else if (component.status === 'failed') {
262
- console.log(` Component "${component.key}": ${component.message}`);
306
+ console.log(` ${mark('fail')} component "${component.key}": ${component.message}`);
263
307
  } else if (component.status === 'pending') {
264
- console.log(` Component "${component.key}": ${component.message}`);
308
+ console.log(` ${mark('skip')} component "${component.key}": ${component.message}`);
265
309
  }
266
310
  if (component.filesWritten && component.filesWritten.length > 0) {
267
- console.log(` Component "${component.key}": wrote ${component.filesWritten.join(', ')} to ${result.targetBase}.`);
311
+ console.log(` ${mark('ok')} component "${component.key}": wrote ${component.filesWritten.join(', ')} to ${result.targetBase}`);
268
312
  }
269
313
  }
314
+ return result;
270
315
  }
271
316
 
272
317
  /**
@@ -275,16 +320,40 @@ function installOneBundle({ bundleKey, targetDir, targetConfig, itemPaths }) {
275
320
  * the only piece of the menu flow that isn't unit-testable without a TTY —
276
321
  * everything it calls (planSelection, installBundle) is.
277
322
  */
323
+ /** "what landed where, what was skipped, next steps" — printed once after every
324
+ * requested bundle has been installed (or skipped/failed). */
325
+ function printFinalSummary({ installed, skipped, targetBase }) {
326
+ if (installed.length === 0 && skipped.length === 0) return;
327
+ console.log(`\n${ansi.bold('Summary')}`);
328
+ for (const { bundle, result } of installed) {
329
+ const totalFiles = result.filesWritten + result.filesUnchanged;
330
+ const sizeSuffix = result.bytesWritten ? `, ${formatBytes(result.bytesWritten)}` : '';
331
+ const hooksSuffix = result.hooksWired.length > 0 ? `, ${result.hooksWired.length} hook(s) wired` : '';
332
+ const mcpSuffix = result.mcpWired.length > 0 ? `, ${result.mcpWired.length} MCP server(s) wired` : '';
333
+ console.log(` ${mark('ok')} ${ansi.bold(bundle.title)} — ${totalFiles} file(s)${sizeSuffix}${hooksSuffix}${mcpSuffix}`);
334
+ }
335
+ for (const label of skipped) {
336
+ console.log(` ${mark('skip')} ${label}`);
337
+ }
338
+ console.log(
339
+ `\nInstalled to ${ansi.bold(targetBase)}. Next: ${ansi.dim('agents-cli secrets')} to fill in any skipped ` +
340
+ `secrets, ${ansi.dim('agents-cli update --yes')} to refresh later.`
341
+ );
342
+ }
343
+
278
344
  async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets, profile }) {
279
- const { manifest } = loadManifest(PACKAGE_ROOT);
345
+ const { manifest, manifestPath } = loadManifest(PACKAGE_ROOT);
346
+ const repoRoot = path.dirname(manifestPath);
280
347
  const candidateBundles = advanced ? advancedMenuBundles(manifest, profile) : basicMenuBundles(manifest, profile);
281
348
  if (!candidateBundles.length) {
282
349
  console.log('No bundles are defined yet.');
283
350
  return 0;
284
351
  }
285
352
 
286
- const rows = candidateBundles.map(describeBundleRow);
287
- const selectedKeys = await pickBundles(rows);
353
+ const rows = candidateBundles.map((b) => describeBundleRow(b, manifest));
354
+ const details = new Map(candidateBundles.map((b) => [b.key, deriveBundleDetails(b, manifest, { repoRoot })]));
355
+ const header = `${pkg.name} v${pkg.version}`;
356
+ const selectedKeys = await pickBundles(rows, { details, header });
288
357
  if (selectedKeys === null) {
289
358
  console.log('Cancelled — nothing installed.');
290
359
  return 0;
@@ -304,6 +373,8 @@ async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets
304
373
  }
305
374
 
306
375
  const installedBundles = [];
376
+ const installedResults = [];
377
+ const skipped = [];
307
378
  for (const bundle of plan.toInstall) {
308
379
  let itemPaths;
309
380
  if (advanced) {
@@ -318,16 +389,19 @@ async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets
318
389
  const selectedItemPaths = await pickBundles(itemRows);
319
390
  if (selectedItemPaths === null || selectedItemPaths.length === 0) {
320
391
  console.log(`Skipping "${bundle.title}" — no items selected.`);
392
+ skipped.push(`${bundle.title} — no items selected`);
321
393
  continue;
322
394
  }
323
395
  itemPaths = selectedItemPaths;
324
396
  }
325
397
  try {
326
- installOneBundle({ bundleKey: bundle.key, targetDir, targetConfig, itemPaths });
398
+ const result = installOneBundle({ bundleKey: bundle.key, bundleTitle: bundle.title, targetDir, targetConfig, itemPaths });
327
399
  installedBundles.push(bundle);
400
+ installedResults.push({ bundle, result });
328
401
  } catch (err) {
329
402
  if (err instanceof InstallError || err instanceof ManifestError || err instanceof LedgerError || err instanceof WiringError) {
330
403
  console.error(err.message);
404
+ skipped.push(`${bundle.title} — failed: ${err.message}`);
331
405
  } else {
332
406
  throw err;
333
407
  }
@@ -345,6 +419,8 @@ async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets
345
419
  runSelfProfileStepsIfNeeded({ profile, targetDir });
346
420
  }
347
421
 
422
+ printFinalSummary({ installed: installedResults, skipped, targetBase: targetDir || defaultTargetBase() });
423
+
348
424
  return 0;
349
425
  }
350
426
 
@@ -377,9 +453,14 @@ async function runInstall(argv) {
377
453
  }
378
454
 
379
455
  try {
380
- installOneBundle({ bundleKey: args.bundle, targetDir: args.targetDir, targetConfig: args.targetConfig });
381
456
  const { manifest } = loadManifest(PACKAGE_ROOT);
382
457
  const bundle = findBundle(manifest, args.bundle);
458
+ installOneBundle({
459
+ bundleKey: args.bundle,
460
+ bundleTitle: bundle ? bundle.title : args.bundle,
461
+ targetDir: args.targetDir,
462
+ targetConfig: args.targetConfig,
463
+ });
383
464
  await promptForMissingSecrets({
384
465
  bundles: bundle ? [bundle] : [],
385
466
  targetBase: args.targetDir || defaultTargetBase(),
@@ -438,6 +519,8 @@ async function runUninstall(argv) {
438
519
  }
439
520
 
440
521
  try {
522
+ const { manifest } = loadManifest(PACKAGE_ROOT);
523
+ const uninstalledBundle = findBundle(manifest, args.bundle);
441
524
  const result = uninstallBundle({
442
525
  packageRoot: PACKAGE_ROOT,
443
526
  bundleKey: args.bundle,
@@ -477,6 +560,35 @@ async function runUninstall(argv) {
477
560
  );
478
561
  }
479
562
  }
563
+
564
+ // Secrets are shared across bundles (e.g. LITELLM_MASTER_KEY) and kept
565
+ // by default rather than deleted on uninstall — report which of this
566
+ // bundle's (plus any just-removed component's) declared secrets are
567
+ // still sitting in agents.env and no longer needed by anything that
568
+ // remains installed, so the user can clean them up deliberately.
569
+ const declaredByUninstalled = new Map();
570
+ for (const secret of collectBundleSecrets(uninstalledBundle ? [uninstalledBundle] : [])) {
571
+ declaredByUninstalled.set(secret.name, secret);
572
+ }
573
+ for (const component of result.components || []) {
574
+ if (component.kept) continue; // still needed elsewhere — not this uninstall's business
575
+ const declaration = manifest.components && manifest.components[component.key];
576
+ for (const secret of (declaration && declaration.secrets) || []) {
577
+ if (!declaredByUninstalled.has(secret.name)) declaredByUninstalled.set(secret.name, secret);
578
+ }
579
+ }
580
+ if (declaredByUninstalled.size > 0) {
581
+ const stillNeeded = secretsStillNeeded(result.targetBase, manifest);
582
+ const { values } = readSecrets(result.targetBase);
583
+ const kept = [...declaredByUninstalled.keys()].filter((name) => values[name] && !stillNeeded.has(name));
584
+ if (kept.length > 0) {
585
+ console.log(` Secrets kept in ${envPath(result.targetBase)}:`);
586
+ for (const name of kept) {
587
+ console.log(` ${name} — remove with: agents-cli secrets --remove ${name}`);
588
+ }
589
+ }
590
+ }
591
+
480
592
  return 0;
481
593
  } catch (err) {
482
594
  if (err instanceof UninstallError || err instanceof ManifestError || err instanceof LedgerError || err instanceof WiringError) {
@@ -488,7 +600,7 @@ async function runUninstall(argv) {
488
600
  }
489
601
 
490
602
  function parseSecretsArgs(argv) {
491
- const args = { bundle: null, list: false, targetDir: null };
603
+ const args = { bundle: null, list: false, targetDir: null, remove: null, purgeUnused: false, yes: false };
492
604
  for (let i = 0; i < argv.length; i += 1) {
493
605
  const arg = argv[i];
494
606
  if (arg === '--bundle') {
@@ -499,6 +611,13 @@ function parseSecretsArgs(argv) {
499
611
  } else if (arg === '--target-dir') {
500
612
  args.targetDir = argv[i + 1];
501
613
  i += 1;
614
+ } else if (arg === '--remove') {
615
+ args.remove = argv[i + 1];
616
+ i += 1;
617
+ } else if (arg === '--purge-unused') {
618
+ args.purgeUnused = true;
619
+ } else if (arg === '--yes') {
620
+ args.yes = true;
502
621
  } else {
503
622
  throw new InstallError(`Unknown secrets flag: ${arg}`);
504
623
  }
@@ -506,6 +625,22 @@ function parseSecretsArgs(argv) {
506
625
  return args;
507
626
  }
508
627
 
628
+ /**
629
+ * Every secret name declared (bundle-level or, via a dep, component-level)
630
+ * by any bundle currently installed at `targetBase`, per the ledger. Used
631
+ * by `secrets --purge-unused` (what's still needed, so anything else in
632
+ * agents.env is a removal candidate) and by the uninstall report (what a
633
+ * just-removed bundle's secrets are still needed for, so they're excluded
634
+ * from the "kept, remove it" suggestion).
635
+ */
636
+ function secretsStillNeeded(targetBase, manifest) {
637
+ const keys = installedBundleKeys(targetBase, pkg.version);
638
+ const bundles = keys.map((key) => findBundle(manifest, key)).filter(Boolean);
639
+ return new Set(
640
+ [...collectBundleSecrets(bundles), ...collectComponentSecrets(bundles, manifest)].map((s) => s.name)
641
+ );
642
+ }
643
+
509
644
  /** Every bundle key with at least one file/wiring entry in the ledger at targetBase. */
510
645
  function installedBundleKeys(targetBase, cliVersion) {
511
646
  return bundleKeysInLedger(loadLedger(targetBase, cliVersion));
@@ -523,6 +658,57 @@ async function runSecrets(argv) {
523
658
  const targetBase = args.targetDir || defaultTargetBase();
524
659
  const { manifest } = loadManifest(PACKAGE_ROOT);
525
660
 
661
+ if (args.remove) {
662
+ const name = args.remove;
663
+ const removal = removeSecret(targetBase, name);
664
+ if (!removal.existed) {
665
+ console.error(`${name} is not set in ${envPath(targetBase)} — nothing to remove.`);
666
+ return 1;
667
+ }
668
+ console.log(`Removed ${name} (was ${maskValue(removal.value)}) from ${envPath(targetBase)}.`);
669
+ if (removal.warning) {
670
+ console.log(` Warning: ${removal.warning}`);
671
+ }
672
+ return 0;
673
+ }
674
+
675
+ if (args.purgeUnused) {
676
+ const stillNeeded = secretsStillNeeded(targetBase, manifest);
677
+ const { values } = readSecrets(targetBase);
678
+ const unused = Object.keys(values).filter((name) => !stillNeeded.has(name));
679
+ if (unused.length === 0) {
680
+ console.log(`No unused secrets found in ${envPath(targetBase)}.`);
681
+ return 0;
682
+ }
683
+ console.log(`The following secret(s) in ${envPath(targetBase)} are not declared by any installed bundle/component:`);
684
+ for (const name of unused) {
685
+ console.log(` ${name} (${maskValue(values[name])})`);
686
+ }
687
+ if (!args.yes) {
688
+ const isTTY = !!(process.stdin.isTTY && process.stdout.isTTY);
689
+ if (!isTTY) {
690
+ console.error('Not running in a terminal — pass --yes to confirm removal.');
691
+ return 1;
692
+ }
693
+ const choice = await askChoice({
694
+ input: process.stdin,
695
+ output: process.stdout,
696
+ promptText: `Remove ${unused.length} secret(s)? [y/N] `,
697
+ choices: ['yes', 'no'],
698
+ defaultChoice: 'no',
699
+ });
700
+ if (choice !== 'yes') {
701
+ console.log('Cancelled — nothing removed.');
702
+ return 0;
703
+ }
704
+ }
705
+ for (const name of unused) {
706
+ removeSecret(targetBase, name);
707
+ }
708
+ console.log(`Removed ${unused.length} secret(s) from ${envPath(targetBase)}.`);
709
+ return 0;
710
+ }
711
+
526
712
  let bundles;
527
713
  if (args.bundle) {
528
714
  const bundle = findBundle(manifest, args.bundle);
@@ -108,7 +108,7 @@ def check(edited_path: str, target_base: Path) -> str | None:
108
108
 
109
109
  return (
110
110
  f'managed by @yasaswy.nagavolu/agents (bundle "{bundle}") — edit {source_display} '
111
- f"and run: npx @yasaswy.nagavolu/agents update"
111
+ f"and run: npx '@yasaswy.nagavolu/agents' update"
112
112
  )
113
113
 
114
114
 
package/lib/ansi.js ADDED
@@ -0,0 +1,105 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Tiny zero-dependency ANSI helper: color/style wrapping, a determinate
5
+ * progress-bar renderer, and byte formatting. No npm packages — the CLI's
6
+ * zero-runtime-dependency constraint is non-negotiable.
7
+ *
8
+ * Nesting-safe: each style wrapper re-asserts its own open code after any
9
+ * embedded reset it finds in the text, so `bold(dim(x))`-style composition
10
+ * doesn't have the inner reset silently cancel the outer style early.
11
+ */
12
+
13
+ const CODES = {
14
+ reset: '\x1b[0m',
15
+ bold: '\x1b[1m',
16
+ dim: '\x1b[2m',
17
+ italic: '\x1b[3m',
18
+ inverse: '\x1b[7m',
19
+ black: '\x1b[30m',
20
+ red: '\x1b[31m',
21
+ green: '\x1b[32m',
22
+ yellow: '\x1b[33m',
23
+ blue: '\x1b[34m',
24
+ magenta: '\x1b[35m',
25
+ cyan: '\x1b[36m',
26
+ white: '\x1b[37m',
27
+ gray: '\x1b[90m',
28
+ };
29
+
30
+ const STYLE_NAMES = Object.keys(CODES).filter((name) => name !== 'reset');
31
+
32
+ /**
33
+ * Colors are on only when stdout is a real TTY and NO_COLOR isn't set (any
34
+ * value, including empty string, per the NO_COLOR spec at no-color.org).
35
+ */
36
+ function supportsColor({ stream = process.stdout, env = process.env } = {}) {
37
+ if (env && Object.prototype.hasOwnProperty.call(env, 'NO_COLOR')) return false;
38
+ return !!(stream && stream.isTTY);
39
+ }
40
+
41
+ function createStyler(enabled) {
42
+ const styler = { enabled: !!enabled };
43
+ for (const name of STYLE_NAMES) {
44
+ styler[name] = (text) => {
45
+ const str = text === undefined || text === null ? '' : String(text);
46
+ if (!styler.enabled || str === '') return str;
47
+ const open = CODES[name];
48
+ const close = CODES.reset;
49
+ // Re-open after any embedded reset so nested styles don't clip early.
50
+ return open + str.split(close).join(close + open) + close;
51
+ };
52
+ }
53
+ styler.clearScreen = () => (styler.enabled ? '\x1Bc' : '');
54
+ styler.hideCursor = () => (styler.enabled ? '\x1b[?25l' : '');
55
+ styler.showCursor = () => (styler.enabled ? '\x1b[?25h' : '');
56
+ // Clear from cursor to end of line, then return to column 0 — used for
57
+ // in-place progress-bar redraws (\r + this) so a shorter next frame
58
+ // doesn't leave stray characters from a longer previous frame.
59
+ styler.clearLine = () => (styler.enabled ? '\x1b[K' : '');
60
+ return styler;
61
+ }
62
+
63
+ function clamp(n, lo, hi) {
64
+ return Math.max(lo, Math.min(hi, n));
65
+ }
66
+
67
+ /**
68
+ * Render a pip-style determinate bar: full cells '━', one partial cap '╸' at
69
+ * the boundary, remaining cells '─'. current/total can be any non-negative
70
+ * numbers; total<=0 or current>=total renders a full bar (nothing left to
71
+ * show as pending), current<=0 renders empty.
72
+ */
73
+ function renderBar(current, total, { width = 24 } = {}) {
74
+ const safeWidth = Math.max(1, Math.floor(width));
75
+ const safeTotal = Math.max(0, total || 0);
76
+ const safeCurrent = Math.max(0, current || 0);
77
+ const ratio = safeTotal === 0 ? 1 : clamp(safeCurrent / safeTotal, 0, 1);
78
+ const filledCells = Math.round(ratio * safeWidth);
79
+ if (filledCells <= 0) return '─'.repeat(safeWidth);
80
+ if (filledCells >= safeWidth) return '━'.repeat(safeWidth);
81
+ return '━'.repeat(filledCells - 1) + '╸' + '─'.repeat(safeWidth - filledCells);
82
+ }
83
+
84
+ function formatBytes(bytes) {
85
+ const value = Math.max(0, bytes || 0);
86
+ if (value === 0) return '0 B';
87
+ const units = ['B', 'KB', 'MB', 'GB'];
88
+ let n = value;
89
+ let unitIndex = 0;
90
+ while (n >= 1024 && unitIndex < units.length - 1) {
91
+ n /= 1024;
92
+ unitIndex += 1;
93
+ }
94
+ const precision = unitIndex === 0 ? 0 : 1;
95
+ return `${n.toFixed(precision)} ${units[unitIndex]}`;
96
+ }
97
+
98
+ module.exports = {
99
+ CODES,
100
+ supportsColor,
101
+ createStyler,
102
+ renderBar,
103
+ formatBytes,
104
+ clamp,
105
+ };