@yasaswy.nagavolu/agents 0.9.0 → 0.9.2

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
@@ -79,16 +79,21 @@ agents-cli install
79
79
 
80
80
  In a color-capable terminal, `agents-cli install` looks roughly like this
81
81
  (`✓`/colors omitted from this plain-text README, but selected rows get a
82
- green check, the cursor row is highlighted, `(needs: ...)` is yellow,
83
- `(asks: ...)` is cyan, and `[passthrough]` is magenta in the real thing):
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):
84
87
 
85
88
  ```
86
- @yasaswy.nagavolu/agents v0.9.0
89
+ @yasaswy.nagavolu/agents v0.9.1
87
90
  Select bundles to install
88
91
 
89
92
  [ ] Session Tools — Resume past Claude Code sessions by name and archive session transcripts to markdown
90
- [ ] Shipping — Ship code changes end-to-end: sync, test, commit, push, and file the GitLab issue update in one skill (asks: GITLAB_TOKEN)
91
- ❯ [✓] Reddit Reader — Read Reddit posts/threads into Claude Code from a URL, with a deterministic prompt-intent nudge (asks: REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USER_AGENT)
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
92
97
  [ ] Skill Authoring — code-is-law: turn skill/agent-file prose rules into an enforced PostToolUse lint
93
98
 
94
99
  ────────────────────────────────────────────────────────────────
package/bin/cli.js CHANGED
@@ -17,14 +17,16 @@ 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,
23
24
  deriveBundleDetails,
24
25
  } = require('../lib/menu');
25
- const { pickBundles } = require('../lib/tty-menu');
26
+ const { pickBundles, buildHintLine, HINT_INDENT } = require('../lib/tty-menu');
26
27
  const { supportsColor, createStyler, renderBar, formatBytes } = require('../lib/ansi');
27
- const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMissingSecrets } = require('../lib/secretsPrompt');
28
+ const { collectBundleSecrets, collectComponentSecrets, isResolved, promptForMissingSecrets, maskValue, askChoice } = require('../lib/secretsPrompt');
29
+ const { envPath, readSecrets, removeSecret } = require('../lib/secretsStore');
28
30
  const { runSelfProfilePostInstall } = require('../lib/selfProfile');
29
31
 
30
32
  const PACKAGE_ROOT = path.join(__dirname, '..');
@@ -170,6 +172,8 @@ function listBundles(profile = 'public') {
170
172
  console.log('Available bundles:');
171
173
  for (const bundle of bundles) {
172
174
  console.log(` ${bundle.key} — ${bundle.summary}`);
175
+ const hintLine = buildHintLine(describeBundleHints(bundle, manifest), ansi);
176
+ if (hintLine) console.log(`${HINT_INDENT}${hintLine}`);
173
177
  }
174
178
  console.log('\nRun: agents-cli install --bundle <key> --yes');
175
179
  return 0;
@@ -346,7 +350,7 @@ async function runInteractiveMenu({ advanced, targetDir, targetConfig, noSecrets
346
350
  return 0;
347
351
  }
348
352
 
349
- const rows = candidateBundles.map(describeBundleRow);
353
+ const rows = candidateBundles.map((b) => describeBundleRow(b, manifest));
350
354
  const details = new Map(candidateBundles.map((b) => [b.key, deriveBundleDetails(b, manifest, { repoRoot })]));
351
355
  const header = `${pkg.name} v${pkg.version}`;
352
356
  const selectedKeys = await pickBundles(rows, { details, header });
@@ -515,6 +519,8 @@ async function runUninstall(argv) {
515
519
  }
516
520
 
517
521
  try {
522
+ const { manifest } = loadManifest(PACKAGE_ROOT);
523
+ const uninstalledBundle = findBundle(manifest, args.bundle);
518
524
  const result = uninstallBundle({
519
525
  packageRoot: PACKAGE_ROOT,
520
526
  bundleKey: args.bundle,
@@ -554,6 +560,35 @@ async function runUninstall(argv) {
554
560
  );
555
561
  }
556
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
+
557
592
  return 0;
558
593
  } catch (err) {
559
594
  if (err instanceof UninstallError || err instanceof ManifestError || err instanceof LedgerError || err instanceof WiringError) {
@@ -565,7 +600,7 @@ async function runUninstall(argv) {
565
600
  }
566
601
 
567
602
  function parseSecretsArgs(argv) {
568
- const args = { bundle: null, list: false, targetDir: null };
603
+ const args = { bundle: null, list: false, targetDir: null, remove: null, purgeUnused: false, yes: false };
569
604
  for (let i = 0; i < argv.length; i += 1) {
570
605
  const arg = argv[i];
571
606
  if (arg === '--bundle') {
@@ -576,6 +611,13 @@ function parseSecretsArgs(argv) {
576
611
  } else if (arg === '--target-dir') {
577
612
  args.targetDir = argv[i + 1];
578
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;
579
621
  } else {
580
622
  throw new InstallError(`Unknown secrets flag: ${arg}`);
581
623
  }
@@ -583,6 +625,22 @@ function parseSecretsArgs(argv) {
583
625
  return args;
584
626
  }
585
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
+
586
644
  /** Every bundle key with at least one file/wiring entry in the ledger at targetBase. */
587
645
  function installedBundleKeys(targetBase, cliVersion) {
588
646
  return bundleKeysInLedger(loadLedger(targetBase, cliVersion));
@@ -600,6 +658,57 @@ async function runSecrets(argv) {
600
658
  const targetBase = args.targetDir || defaultTargetBase();
601
659
  const { manifest } = loadManifest(PACKAGE_ROOT);
602
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
+
603
712
  let bundles;
604
713
  if (args.bundle) {
605
714
  const bundle = findBundle(manifest, args.bundle);
package/lib/menu.js CHANGED
@@ -77,11 +77,42 @@ function advancedMenuBundles(manifest, profile = 'public') {
77
77
  return manifest.bundles.filter((b) => profileVisible(b, profile));
78
78
  }
79
79
 
80
+ /**
81
+ * Pure derivation of the hint data a renderer shows below a bundle's title:
82
+ * which components it needs, which secrets it will prompt for (its own,
83
+ * plus any *required* secret owned by a dep's component — tagged
84
+ * `component: true` so a renderer can label it "(component)"; a
85
+ * component's own *optional* provider keys are that component's concern,
86
+ * not every dependent bundle's, so those are left off), and whether
87
+ * selecting it is a passthrough (prints a command instead of installing).
88
+ * `manifest` is optional; without it (e.g. an --advanced per-item row,
89
+ * which has no bundle-shaped manifest context) component secrets are
90
+ * simply skipped rather than looked up.
91
+ */
92
+ function describeBundleHints(bundle, manifest) {
93
+ const needs = bundle.deps || [];
94
+ const asks = (bundle.secrets || []).map((s) => ({ name: s.name, component: false }));
95
+ if (manifest && manifest.components) {
96
+ for (const depKey of needs) {
97
+ const component = manifest.components[depKey];
98
+ for (const secret of (component && component.secrets) || []) {
99
+ if (!isSecretOptional(secret)) {
100
+ asks.push({ name: secret.name, component: true });
101
+ }
102
+ }
103
+ }
104
+ }
105
+ return { needs, asks, passthrough: classifyBundle(bundle) === 'passthrough' };
106
+ }
107
+
80
108
  /**
81
109
  * Build the row data a renderer (TTY or fallback numbered list) needs for
82
110
  * one bundle, without any presentation/formatting decisions baked in.
111
+ * `manifest` is optional and only needed to enrich `hints` with
112
+ * component-owned secrets (see describeBundleHints) — omit it for
113
+ * contexts with no real manifest (e.g. some tests).
83
114
  */
84
- function describeBundleRow(bundle) {
115
+ function describeBundleRow(bundle, manifest) {
85
116
  const status = classifyBundle(bundle);
86
117
  return {
87
118
  key: bundle.key,
@@ -90,6 +121,7 @@ function describeBundleRow(bundle) {
90
121
  status,
91
122
  secretsHint: secretsHint(bundle),
92
123
  depsHint: depsHint(bundle),
124
+ hints: describeBundleHints(bundle, manifest),
93
125
  itemCount: bundle.items.length,
94
126
  passthroughCommand: bundle.passthrough ? bundle.passthrough.command : null,
95
127
  };
@@ -228,6 +260,29 @@ function deriveBundleDetails(bundle, manifest, { repoRoot } = {}) {
228
260
  };
229
261
  }
230
262
 
263
+ /**
264
+ * Toggle-all/none for a picker's "a" key. `selectableKeys` is the scoped set
265
+ * "a" acts over (today: every row the picker offers — passthrough bundles
266
+ * and advancedOnly items included, same as the old select-all behavior).
267
+ * If every selectable key is already selected, deselects all of them;
268
+ * otherwise selects every selectable key. Any selection outside
269
+ * `selectableKeys` (there isn't one today, but a future scoped picker could
270
+ * have one) is left untouched either way.
271
+ *
272
+ * Pure — returns a new Set, does not mutate `selected`. Kept here (not in
273
+ * tty-menu.js) so it's testable without a TTY.
274
+ */
275
+ function toggleAll(selected, selectableKeys) {
276
+ const allSelected = selectableKeys.every((k) => selected.has(k));
277
+ const next = new Set(selected);
278
+ if (allSelected) {
279
+ for (const k of selectableKeys) next.delete(k);
280
+ } else {
281
+ for (const k of selectableKeys) next.add(k);
282
+ }
283
+ return next;
284
+ }
285
+
231
286
  module.exports = {
232
287
  classifyBundle,
233
288
  secretsHint,
@@ -235,8 +290,10 @@ module.exports = {
235
290
  profileVisible,
236
291
  basicMenuBundles,
237
292
  advancedMenuBundles,
293
+ describeBundleHints,
238
294
  describeBundleRow,
239
295
  planSelection,
240
296
  describeBundleItems,
241
297
  deriveBundleDetails,
298
+ toggleAll,
242
299
  };
@@ -3,7 +3,7 @@
3
3
  const readline = require('node:readline');
4
4
  const https = require('node:https');
5
5
  const { readEnvFile } = require('./agentsEnv');
6
- const { writeSecrets } = require('./secretsStore');
6
+ const { writeSecrets, envPath } = require('./secretsStore');
7
7
 
8
8
  /**
9
9
  * Dedupe a set of selected bundles' declared secrets by name (first bundle
@@ -48,20 +48,62 @@ function collectComponentSecrets(bundles, manifest) {
48
48
  }
49
49
 
50
50
  /**
51
- * Is `name` already resolvable via the shared loader's resolution order
52
- * (real env var, or non-empty value in targetBase/agents.env)? Prompting
53
- * only asks for secrets that would NOT already resolve at hook runtime —
54
- * asking again for a value already exported in the shell would be noise.
51
+ * Where (if anywhere) `name` currently resolves from, via the shared
52
+ * loader's resolution order: a real env var first, then a non-empty value
53
+ * in targetBase/agents.env. Returns the resolved value too (never logged by
54
+ * this module — callers that display it must go through maskValue()).
55
55
  */
56
- function isResolved(name, targetBase) {
57
- if (process.env[name]) return true;
56
+ function resolveSecretSource(name, targetBase) {
57
+ if (process.env[name]) {
58
+ return { resolved: true, source: 'env var', value: process.env[name] };
59
+ }
58
60
  const values = readEnvFile(targetBase);
59
- return !!(values[name] && values[name].length > 0);
61
+ if (values[name] && values[name].length > 0) {
62
+ return { resolved: true, source: 'agents.env', value: values[name] };
63
+ }
64
+ return { resolved: false, source: null, value: null };
65
+ }
66
+
67
+ /**
68
+ * Is `name` already resolvable via the shared loader's resolution order?
69
+ * Thin boolean wrapper over resolveSecretSource for callers (e.g. the
70
+ * `secrets --list` CLI path) that only need the yes/no.
71
+ */
72
+ function isResolved(name, targetBase) {
73
+ return resolveSecretSource(name, targetBase).resolved;
74
+ }
75
+
76
+ /**
77
+ * Mask a secret value for display: reveals at most the last 4 characters,
78
+ * never more. Values under 8 characters are masked entirely (revealing 4 of
79
+ * fewer than 8 chars discloses too much of the secret to be worth it).
80
+ */
81
+ function maskValue(value) {
82
+ const str = String(value == null ? '' : value);
83
+ if (str.length < 8) return '*'.repeat(str.length);
84
+ return '*'.repeat(str.length - 4) + str.slice(-4);
85
+ }
86
+
87
+ /**
88
+ * Ensure `input` is actively flowing before reading from it. A stream left
89
+ * paused by a prior consumer (notably lib/tty-menu.js's raw-mode bundle
90
+ * picker, whose cleanup() calls stdin.pause() to restore an idle default)
91
+ * stays paused forever once pause() has been called explicitly — attaching
92
+ * new 'data'/'keypress' listeners afterward does NOT auto-resume it (that
93
+ * only happens the first time, before any explicit pause()/resume() call).
94
+ * Without this, the menu-then-secrets sequence in bin/cli.js would silently
95
+ * never deliver a single keystroke to this module's readers, and Node would
96
+ * exit once the event loop drains — printing the prompt, then dropping
97
+ * straight back to the shell with nothing ever read.
98
+ */
99
+ function ensureFlowing(input) {
100
+ if (input && typeof input.resume === 'function') input.resume();
60
101
  }
61
102
 
62
103
  /** Read one line from `input`, terminated by '\n'. No echo/masking. */
63
104
  function readPlainLine({ input }) {
64
105
  return new Promise((resolve) => {
106
+ ensureFlowing(input);
65
107
  let buf = '';
66
108
  function onData(chunk) {
67
109
  buf += chunk.toString();
@@ -93,19 +135,44 @@ function readMaskedSecret({ input, output, promptText }) {
93
135
  }
94
136
 
95
137
  input.setRawMode(true);
138
+ // See ensureFlowing()'s doc comment — must happen before/alongside
139
+ // emitKeypressEvents, since a stream already explicitly paused by an
140
+ // earlier consumer won't auto-resume just because a new listener is
141
+ // attached.
142
+ ensureFlowing(input);
96
143
  if (typeof readline.emitKeypressEvents === 'function') {
97
144
  readline.emitKeypressEvents(input);
98
145
  }
99
146
  let value = '';
147
+ let settled = false;
148
+
149
+ const onEnd = () => {
150
+ if (settled) return;
151
+ settled = true;
152
+ cleanup();
153
+ // A real TTY input stream ending before any keypress was read is not
154
+ // a normal "user pressed Enter on empty" skip — it means something
155
+ // upstream (a prior raw-mode consumer, a broken pipe, etc.) left this
156
+ // stream in a state it should never be in for an interactive session.
157
+ // Surface it loudly instead of silently treating it as "skipped",
158
+ // which would look identical to a deliberate skip in every log.
159
+ output.write(
160
+ '\n(unexpected end of input while reading from a terminal — this looks like a bug; treating as skipped)\n'
161
+ );
162
+ resolve('');
163
+ };
164
+
100
165
  const onKeypress = (str, key) => {
101
166
  const k = key || {};
102
167
  if (k.ctrl && k.name === 'c') {
168
+ settled = true;
103
169
  cleanup();
104
170
  output.write('\n');
105
171
  process.exit(130);
106
172
  return;
107
173
  }
108
174
  if (k.name === 'return' || k.name === 'enter') {
175
+ settled = true;
109
176
  cleanup();
110
177
  output.write('\n');
111
178
  resolve(value);
@@ -130,8 +197,12 @@ function readMaskedSecret({ input, output, promptText }) {
130
197
  // best-effort — nothing more to do if the platform refuses
131
198
  }
132
199
  input.removeListener('keypress', onKeypress);
200
+ input.removeListener('end', onEnd);
201
+ input.removeListener('close', onEnd);
133
202
  }
134
203
  input.on('keypress', onKeypress);
204
+ input.on('end', onEnd);
205
+ input.on('close', onEnd);
135
206
  });
136
207
  }
137
208
 
@@ -181,17 +252,24 @@ const DEFAULT_VALIDATORS = { GITLAB_TOKEN: validateGitlabToken };
181
252
  * Prompt for, validate (where a validator is registered), and return the
182
253
  * outcome for one secret. Loops on a failed live validation until the user
183
254
  * picks retry / skip / keep.
255
+ *
256
+ * `alreadySet` (bool): when true, this secret already resolves (env var or
257
+ * agents.env) — Enter-on-empty means "keep the current value" (status
258
+ * `'kept'`) rather than "skip" (status `'skipped'`), and the prompt text is
259
+ * worded to match.
184
260
  */
185
- async function promptOneSecret({ secret, io, validator }) {
261
+ async function promptOneSecret({ secret, io, validator, alreadySet = false }) {
186
262
  for (;;) {
187
263
  // eslint-disable-next-line no-await-in-loop
188
264
  const value = await readMaskedSecret({
189
265
  input: io.input,
190
266
  output: io.output,
191
- promptText: `Enter ${secret.name} (Enter to skip): `,
267
+ promptText: alreadySet
268
+ ? `Enter ${secret.name} (Enter to keep current value): `
269
+ : `Enter ${secret.name} (Enter to skip): `,
192
270
  });
193
271
  if (!value) {
194
- return { status: 'skipped' };
272
+ return { status: alreadySet ? 'kept' : 'skipped' };
195
273
  }
196
274
  if (!validator) {
197
275
  return { status: 'accepted', value };
@@ -214,17 +292,24 @@ async function promptOneSecret({ secret, io, validator }) {
214
292
  choices: ['retry', 'skip', 'keep'],
215
293
  defaultChoice: 'retry',
216
294
  });
217
- if (choice === 'skip') return { status: 'skipped' };
295
+ if (choice === 'skip') return { status: alreadySet ? 'kept' : 'skipped' };
218
296
  if (choice === 'keep') return { status: 'accepted', value };
219
297
  // 'retry' falls through to loop again
220
298
  }
221
299
  }
222
300
 
223
301
  /**
224
- * Prompt for every secret declared by `bundles` that is currently missing
225
- * (per isResolved), skip entirely in a non-TTY environment (pointing the
226
- * user at `agents-cli secrets`), and write every accepted value to
227
- * targetBase/agents.env in a single batched write.
302
+ * Prompt for every secret `bundles` declares (via manifest/components too —
303
+ * see collectComponentSecrets), skip entirely in a non-TTY environment
304
+ * (pointing the user at `agents-cli secrets`), and write every accepted
305
+ * value to targetBase/agents.env in a single batched write.
306
+ *
307
+ * Already-resolved secrets (real env var, or a non-empty value already in
308
+ * agents.env) are still prompted for interactively — Enter keeps the
309
+ * current value (`result.alreadySet`), typing a new one replaces it
310
+ * (`result.written`) — so this is also how a user updates a value they
311
+ * already set. In a non-TTY run, already-resolved secrets are left alone
312
+ * entirely (no way to prompt), matching the pre-existing behavior there.
228
313
  *
229
314
  * `io` (test seam): { input, output } — defaults to process.stdin/stdout.
230
315
  * `validators` (test seam): name -> async (value) => {status}; defaults to
@@ -257,19 +342,11 @@ async function promptForMissingSecrets({ bundles, targetBase, io, validators, no
257
342
  const isTTY = !!(resolvedIo.input && resolvedIo.input.isTTY && resolvedIo.output && resolvedIo.output.isTTY);
258
343
  const activeValidators = validators || DEFAULT_VALIDATORS;
259
344
 
260
- const missing = [];
261
- for (const secret of declared) {
262
- if (isResolved(secret.name, targetBase)) {
263
- result.alreadySet.push(secret.name);
264
- } else {
265
- missing.push(secret);
266
- }
267
- }
268
- if (missing.length === 0) {
269
- return result;
270
- }
271
-
272
345
  if (!isTTY) {
346
+ const missing = declared.filter((secret) => !isResolved(secret.name, targetBase));
347
+ if (missing.length === 0) {
348
+ return result;
349
+ }
273
350
  log(
274
351
  `\n${missing.length} secret(s) not yet configured (${missing.map((s) => s.name).join(', ')}). ` +
275
352
  'Not running in a terminal — run "agents-cli secrets" to set them.'
@@ -278,20 +355,41 @@ async function promptForMissingSecrets({ bundles, targetBase, io, validators, no
278
355
  return result;
279
356
  }
280
357
 
358
+ // A prior raw-mode consumer of this same stdin (e.g. tty-menu's bundle
359
+ // picker, just before this runs in the install flow) may have left it
360
+ // paused — see readMaskedSecret's ensureFlowing() call for the mechanics.
361
+ // Resuming here too means even the very first log()/write() below can't
362
+ // race a still-paused stream in some future refactor.
363
+ ensureFlowing(resolvedIo.input);
364
+
365
+ log(`\nSecrets are stored locally in ${envPath(targetBase)} — they never leave this machine.`);
366
+
281
367
  const updates = {};
282
- for (const secret of missing) {
368
+ for (const secret of declared) {
369
+ const resolution = resolveSecretSource(secret.name, targetBase);
283
370
  log(`\n${secret.name} — ${secret.prompt}`);
284
371
  if (secret.validationHint) {
285
372
  log(` (${secret.validationHint})`);
286
373
  }
287
- // eslint-disable-next-line no-await-in-loop
288
- const outcome = await promptOneSecret({ secret, io: resolvedIo, validator: activeValidators[secret.name] });
289
- if (outcome.status === 'skipped') {
290
- log(` Skipped ${secret.name}.`);
374
+ if (resolution.resolved) {
375
+ log(` already set (${maskValue(resolution.value)}, from ${resolution.source}) — Enter keeps, type to replace`);
376
+ }
377
+ const outcome = await promptOneSecret({ // eslint-disable-line no-await-in-loop
378
+ secret,
379
+ io: resolvedIo,
380
+ validator: activeValidators[secret.name],
381
+ alreadySet: resolution.resolved,
382
+ });
383
+ if (outcome.status === 'kept') {
384
+ log(` Kept existing ${secret.name}.`);
385
+ result.alreadySet.push(secret.name);
386
+ } else if (outcome.status === 'skipped') {
387
+ log(' – skipped, set later with: agents-cli secrets');
291
388
  result.skipped.push(secret.name);
292
389
  } else {
293
390
  updates[secret.name] = outcome.value;
294
391
  result.written.push(secret.name);
392
+ log(` ✓ ${secret.name} = ${maskValue(outcome.value)} → saved to ${envPath(targetBase)}`);
295
393
  }
296
394
  }
297
395
 
@@ -308,7 +406,9 @@ async function promptForMissingSecrets({ bundles, targetBase, io, validators, no
308
406
  module.exports = {
309
407
  collectBundleSecrets,
310
408
  collectComponentSecrets,
409
+ resolveSecretSource,
311
410
  isResolved,
411
+ maskValue,
312
412
  readMaskedSecret,
313
413
  readPlainLine,
314
414
  askChoice,
@@ -112,4 +112,37 @@ function writeSecrets(targetBase, updates, { spawnRunner, chmod } = {}) {
112
112
  return { ok: perm.ok, wrote: true, warning: perm.warning, permissionsApplied: perm.ran || null };
113
113
  }
114
114
 
115
- module.exports = { envPath, readSecrets, writeSecrets, applyOwnerOnlyPermissions };
115
+ /**
116
+ * Delete `name` from targetBase/agents.env if present, preserving every
117
+ * other line (comments/blanks/other keys) verbatim. Returns `existed: false`
118
+ * (no file rewrite, no permissions re-apply) when the key wasn't there —
119
+ * the caller (agents-cli secrets --remove) treats that as an error. The
120
+ * removed value is returned (never logged by this function) so a caller can
121
+ * show a masked confirmation of what was deleted.
122
+ */
123
+ function removeSecret(targetBase, name, { spawnRunner, chmod } = {}) {
124
+ const { values, lines } = readSecrets(targetBase);
125
+ if (!Object.prototype.hasOwnProperty.call(values, name)) {
126
+ return { ok: true, existed: false, value: null };
127
+ }
128
+ const removedValue = values[name];
129
+
130
+ const file = envPath(targetBase);
131
+ const outLines = [];
132
+ for (const line of lines) {
133
+ const trimmed = line.trim();
134
+ let key = null;
135
+ if (trimmed && !trimmed.startsWith('#')) {
136
+ const eq = trimmed.indexOf('=');
137
+ if (eq !== -1) key = trimmed.slice(0, eq).trim();
138
+ }
139
+ if (key === name) continue;
140
+ outLines.push(line);
141
+ }
142
+
143
+ writeFileAtomic(file, outLines.length ? `${outLines.join('\n')}\n` : '');
144
+ const perm = applyOwnerOnlyPermissions(file, { spawnRunner, chmod });
145
+ return { ok: perm.ok, existed: true, value: removedValue, warning: perm.warning, permissionsApplied: perm.ran || null };
146
+ }
147
+
148
+ module.exports = { envPath, readSecrets, writeSecrets, removeSecret, applyOwnerOnlyPermissions };
package/lib/tty-menu.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const readline = require('node:readline');
4
4
  const { supportsColor, createStyler, formatBytes } = require('./ansi');
5
+ const { toggleAll } = require('./menu');
5
6
 
6
7
  // Fixed line count for the detail pane so the layout never jumps as the
7
8
  // cursor moves between bundles with different amounts of detail to show.
@@ -37,27 +38,102 @@ function pickBundles(rows, { stdin = process.stdin, stdout = process.stdout, det
37
38
  return pickWithNumberedPrompt(rows, stdin, stdout);
38
39
  }
39
40
 
40
- function statusLabel(row) {
41
- if (row.status === 'passthrough') return '[passthrough]';
42
- return '';
43
- }
44
-
45
41
  function detailFor(details, row) {
46
42
  if (!details || !row) return null;
47
43
  if (typeof details.get === 'function') return details.get(row.key) || null;
48
44
  return details[row.key] || null;
49
45
  }
50
46
 
51
- function renderRowColored(row, ansi, { isSelected, isCursor }) {
47
+ // Width of the row prefix a hint line indents under: pointer (1 col) + ' '
48
+ // + box '[ ]'/'[✓]' (3 cols) + ' ', so "↳" lands under the title's first
49
+ // character regardless of cursor/selection state (those only recolor the
50
+ // prefix, they never change its width).
51
+ const HINT_INDENT = ' '.repeat(6);
52
+
53
+ /**
54
+ * menu.describeBundleRow() attaches a `hints` field (see
55
+ * menu.describeBundleHints); older/lighter row shapes — e.g. the
56
+ * --advanced per-item picker's rows, built by hand in bin/cli.js with no
57
+ * bundle/manifest context — don't have one. Fall back to whatever legacy
58
+ * fields the row does carry so those rows still render (with no hint line,
59
+ * same as before this feature existed) instead of throwing.
60
+ */
61
+ function hintsFromRow(row) {
62
+ if (row.hints) return row.hints;
63
+ return {
64
+ needs: row.depsHint ? row.depsHint.split(', ').filter(Boolean) : [],
65
+ asks: row.secretsHint ? row.secretsHint.split(', ').filter(Boolean).map((name) => ({ name, component: false })) : [],
66
+ passthrough: row.status === 'passthrough',
67
+ };
68
+ }
69
+
70
+ /** Colored "needs: …" / "asks: …" / "[passthrough]" segments for one hint line, skipping any that don't apply. */
71
+ function formatHintSegments(hints, ansi) {
72
+ const segments = [];
73
+ if (hints.needs && hints.needs.length) {
74
+ segments.push(ansi.yellow(`needs: ${hints.needs.join(', ')}`));
75
+ }
76
+ if (hints.asks && hints.asks.length) {
77
+ const names = hints.asks.map((a) => (a.component ? `${a.name} (component)` : a.name)).join(', ');
78
+ segments.push(ansi.cyan(`asks: ${names}`));
79
+ }
80
+ if (hints.passthrough) {
81
+ segments.push(ansi.magenta(ansi.italic('[passthrough]')));
82
+ }
83
+ return segments;
84
+ }
85
+
86
+ /**
87
+ * The full "↳ needs: … · asks: …" hint line (undecorated with indent —
88
+ * callers place it), or null when the bundle has no hints to show at all
89
+ * (so a renderer can skip the second line entirely). The whole line is
90
+ * wrapped in `dim` — including the colored segments — so it always reads
91
+ * as secondary to the row above it; ansi.js's nesting-safe wrapping keeps
92
+ * each segment's own color visible under that dim.
93
+ */
94
+ function buildHintLine(hints, ansi) {
95
+ const segments = formatHintSegments(hints, ansi);
96
+ if (segments.length === 0) return null;
97
+ return ansi.dim(`↳ ${segments.join(' · ')}`);
98
+ }
99
+
100
+ /**
101
+ * One row's display lines: always the main "[ ] Title — summary" line
102
+ * (inverse-highlighted when it's under the cursor), plus a second, always-
103
+ * dim hint line directly below it when the bundle has deps/secrets/is a
104
+ * passthrough — never inverse, even under the cursor (cursor highlighting
105
+ * is a main-row-only signal). Rows with no hints stay one line, same as
106
+ * before this feature existed.
107
+ */
108
+ function buildRowLines(row, ansi, { isSelected, isCursor }) {
52
109
  const box = isSelected ? ansi.green('[✓]') : '[ ]';
53
110
  const pointer = isCursor ? ansi.cyan('❯') : ' ';
54
111
  const title = ansi.bold(ansi.white(row.title));
55
112
  const summary = ansi.dim(row.summary);
56
- const depsPart = row.depsHint ? ` ${ansi.yellow(`(needs: ${row.depsHint})`)}` : '';
57
- const secretsPart = row.secretsHint ? ` ${ansi.cyan(`(asks: ${row.secretsHint})`)}` : '';
58
- const label = row.status === 'passthrough' ? ` ${ansi.magenta(ansi.italic('[passthrough]'))}` : '';
59
- const line = `${pointer} ${box} ${title} — ${summary}${depsPart}${secretsPart}${label}`;
60
- return isCursor ? ansi.inverse(line) : line;
113
+ const mainLine = `${pointer} ${box} ${title} — ${summary}`;
114
+ const lines = [isCursor ? ansi.inverse(mainLine) : mainLine];
115
+ const hintLine = buildHintLine(hintsFromRow(row), ansi);
116
+ if (hintLine) lines.push(`${HINT_INDENT}${hintLine}`);
117
+ return lines;
118
+ }
119
+
120
+ /**
121
+ * Flattens every row into its display lines (1 or 2 each — see
122
+ * buildRowLines) and records, per row, the line index its block starts at.
123
+ * Pure/testable without a TTY: this is the "row height accounting" a
124
+ * viewport/scroll window would need if one's ever added (today's draw()
125
+ * always redraws the full list, no windowing), and it's what keeps
126
+ * mixed 1-line/2-line lists laying out correctly regardless of how many
127
+ * rows above a given one have hints.
128
+ */
129
+ function layoutRows(rows, ansi, { selected, cursor }) {
130
+ const lines = [];
131
+ const rowLineOffsets = [];
132
+ rows.forEach((row, i) => {
133
+ rowLineOffsets.push(lines.length);
134
+ lines.push(...buildRowLines(row, ansi, { isSelected: selected.has(i), isCursor: cursor === i }));
135
+ });
136
+ return { lines, rowLineOffsets };
61
137
  }
62
138
 
63
139
  /** Builds exactly DETAIL_HEIGHT lines (padded/truncated) describing the
@@ -108,21 +184,19 @@ function pickWithRawMode(rows, stdin, stdout, { details, header } = {}) {
108
184
  stdin.resume();
109
185
 
110
186
  let cursor = 0;
111
- const selected = new Set();
187
+ let selected = new Set();
112
188
 
113
189
  function draw() {
114
190
  const out = [ansi.clearScreen()];
115
191
  if (header) out.push(ansi.bold(header));
116
192
  out.push(ansi.dim('Select bundles to install'));
117
193
  out.push('');
118
- rows.forEach((row, i) => {
119
- out.push(renderRowColored(row, ansi, { isSelected: selected.has(i), isCursor: cursor === i }));
120
- });
194
+ out.push(...layoutRows(rows, ansi, { selected, cursor }).lines);
121
195
  out.push('');
122
196
  out.push(ansi.dim('─'.repeat(RULE_WIDTH)));
123
197
  out.push(...buildDetailLines(rows[cursor], detailFor(details, rows[cursor]), ansi, { isSelected: selected.has(cursor) }));
124
198
  out.push(ansi.dim('─'.repeat(RULE_WIDTH)));
125
- out.push(ansi.dim('↑/↓/j/k move PgUp/PgDn jump space toggle a all enter confirm q quit'));
199
+ out.push(ansi.dim('↑/↓/j/k move PgUp/PgDn jump space toggle a all/none enter confirm q quit'));
126
200
  stdout.write(`${out.join('\n')}\n`);
127
201
  }
128
202
 
@@ -164,7 +238,10 @@ function pickWithRawMode(rows, stdin, stdout, { details, header } = {}) {
164
238
  } else if (key && key.name === 'space') {
165
239
  toggle(cursor);
166
240
  } else if (str === 'a') {
167
- rows.forEach((_, i) => toggle(i));
241
+ selected = toggleAll(
242
+ selected,
243
+ rows.map((_, i) => i)
244
+ );
168
245
  } else if (key && key.name === 'return') {
169
246
  cleanup();
170
247
  resolve(rows.filter((_, i) => selected.has(i)).map((r) => r.key));
@@ -181,12 +258,12 @@ function pickWithRawMode(rows, stdin, stdout, { details, header } = {}) {
181
258
 
182
259
  function pickWithNumberedPrompt(rows, stdin, stdout) {
183
260
  return new Promise((resolve) => {
261
+ const plainAnsi = createStyler(false);
184
262
  stdout.write('Available bundles:\n');
185
263
  rows.forEach((row, i) => {
186
- const label = statusLabel(row);
187
- const depsPart = row.depsHint ? ` (needs: ${row.depsHint})` : '';
188
- const secretsPart = row.secretsHint ? ` (asks: ${row.secretsHint})` : '';
189
- stdout.write(` ${i + 1}) ${row.title} — ${row.summary}${depsPart}${secretsPart} ${label}\n`.trimEnd() + '\n');
264
+ stdout.write(` ${i + 1}) ${row.title} — ${row.summary}\n`);
265
+ const hintLine = buildHintLine(hintsFromRow(row), plainAnsi);
266
+ if (hintLine) stdout.write(`${HINT_INDENT}${hintLine}\n`);
190
267
  });
191
268
  const rl = readline.createInterface({ input: stdin, output: stdout });
192
269
  rl.question(
@@ -214,4 +291,13 @@ function pickWithNumberedPrompt(rows, stdin, stdout) {
214
291
  });
215
292
  }
216
293
 
217
- module.exports = { pickBundles, buildDetailLines, DETAIL_HEIGHT };
294
+ module.exports = {
295
+ pickBundles,
296
+ buildDetailLines,
297
+ DETAIL_HEIGHT,
298
+ buildRowLines,
299
+ buildHintLine,
300
+ hintsFromRow,
301
+ layoutRows,
302
+ HINT_INDENT,
303
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yasaswy.nagavolu/agents",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "CLI for installing the yasaswy.nagavolu agent/skill/hook bundle. `install` opens an interactive bundle menu in a TTY (or `--bundle <key> --yes` for non-interactive installs), with hash-tracked idempotent deploys, automatic hook wiring into settings.json, and masked secret prompting. `update` reconciles installed bundles against the current source (hash-tracked: silent overwrite, conflict diff+prompt, or --theirs/--keep-mine). `uninstall` removes a bundle's files and wiring. `secrets` re-runs secret prompting for already-installed bundles.",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",