@yasaswy.nagavolu/agents 0.9.0 → 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 +10 -5
- package/bin/cli.js +113 -4
- package/lib/menu.js +34 -1
- package/lib/secretsPrompt.js +133 -33
- package/lib/secretsStore.js +34 -1
- package/lib/tty-menu.js +101 -19
- package/package.json +1 -1
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,
|
|
83
|
-
|
|
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.
|
|
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
|
|
91
|
-
|
|
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
|
};
|
|
@@ -235,6 +267,7 @@ module.exports = {
|
|
|
235
267
|
profileVisible,
|
|
236
268
|
basicMenuBundles,
|
|
237
269
|
advancedMenuBundles,
|
|
270
|
+
describeBundleHints,
|
|
238
271
|
describeBundleRow,
|
|
239
272
|
planSelection,
|
|
240
273
|
describeBundleItems,
|
package/lib/secretsPrompt.js
CHANGED
|
@@ -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
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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
|
|
57
|
-
if (process.env[name])
|
|
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
|
-
|
|
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:
|
|
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
|
|
225
|
-
*
|
|
226
|
-
* user at `agents-cli secrets`), and write every accepted
|
|
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
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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,
|
package/lib/secretsStore.js
CHANGED
|
@@ -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
|
-
|
|
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
|
@@ -37,27 +37,102 @@ function pickBundles(rows, { stdin = process.stdin, stdout = process.stdout, det
|
|
|
37
37
|
return pickWithNumberedPrompt(rows, stdin, stdout);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
function statusLabel(row) {
|
|
41
|
-
if (row.status === 'passthrough') return '[passthrough]';
|
|
42
|
-
return '';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
40
|
function detailFor(details, row) {
|
|
46
41
|
if (!details || !row) return null;
|
|
47
42
|
if (typeof details.get === 'function') return details.get(row.key) || null;
|
|
48
43
|
return details[row.key] || null;
|
|
49
44
|
}
|
|
50
45
|
|
|
51
|
-
|
|
46
|
+
// Width of the row prefix a hint line indents under: pointer (1 col) + ' '
|
|
47
|
+
// + box '[ ]'/'[✓]' (3 cols) + ' ', so "↳" lands under the title's first
|
|
48
|
+
// character regardless of cursor/selection state (those only recolor the
|
|
49
|
+
// prefix, they never change its width).
|
|
50
|
+
const HINT_INDENT = ' '.repeat(6);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* menu.describeBundleRow() attaches a `hints` field (see
|
|
54
|
+
* menu.describeBundleHints); older/lighter row shapes — e.g. the
|
|
55
|
+
* --advanced per-item picker's rows, built by hand in bin/cli.js with no
|
|
56
|
+
* bundle/manifest context — don't have one. Fall back to whatever legacy
|
|
57
|
+
* fields the row does carry so those rows still render (with no hint line,
|
|
58
|
+
* same as before this feature existed) instead of throwing.
|
|
59
|
+
*/
|
|
60
|
+
function hintsFromRow(row) {
|
|
61
|
+
if (row.hints) return row.hints;
|
|
62
|
+
return {
|
|
63
|
+
needs: row.depsHint ? row.depsHint.split(', ').filter(Boolean) : [],
|
|
64
|
+
asks: row.secretsHint ? row.secretsHint.split(', ').filter(Boolean).map((name) => ({ name, component: false })) : [],
|
|
65
|
+
passthrough: row.status === 'passthrough',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Colored "needs: …" / "asks: …" / "[passthrough]" segments for one hint line, skipping any that don't apply. */
|
|
70
|
+
function formatHintSegments(hints, ansi) {
|
|
71
|
+
const segments = [];
|
|
72
|
+
if (hints.needs && hints.needs.length) {
|
|
73
|
+
segments.push(ansi.yellow(`needs: ${hints.needs.join(', ')}`));
|
|
74
|
+
}
|
|
75
|
+
if (hints.asks && hints.asks.length) {
|
|
76
|
+
const names = hints.asks.map((a) => (a.component ? `${a.name} (component)` : a.name)).join(', ');
|
|
77
|
+
segments.push(ansi.cyan(`asks: ${names}`));
|
|
78
|
+
}
|
|
79
|
+
if (hints.passthrough) {
|
|
80
|
+
segments.push(ansi.magenta(ansi.italic('[passthrough]')));
|
|
81
|
+
}
|
|
82
|
+
return segments;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The full "↳ needs: … · asks: …" hint line (undecorated with indent —
|
|
87
|
+
* callers place it), or null when the bundle has no hints to show at all
|
|
88
|
+
* (so a renderer can skip the second line entirely). The whole line is
|
|
89
|
+
* wrapped in `dim` — including the colored segments — so it always reads
|
|
90
|
+
* as secondary to the row above it; ansi.js's nesting-safe wrapping keeps
|
|
91
|
+
* each segment's own color visible under that dim.
|
|
92
|
+
*/
|
|
93
|
+
function buildHintLine(hints, ansi) {
|
|
94
|
+
const segments = formatHintSegments(hints, ansi);
|
|
95
|
+
if (segments.length === 0) return null;
|
|
96
|
+
return ansi.dim(`↳ ${segments.join(' · ')}`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* One row's display lines: always the main "[ ] Title — summary" line
|
|
101
|
+
* (inverse-highlighted when it's under the cursor), plus a second, always-
|
|
102
|
+
* dim hint line directly below it when the bundle has deps/secrets/is a
|
|
103
|
+
* passthrough — never inverse, even under the cursor (cursor highlighting
|
|
104
|
+
* is a main-row-only signal). Rows with no hints stay one line, same as
|
|
105
|
+
* before this feature existed.
|
|
106
|
+
*/
|
|
107
|
+
function buildRowLines(row, ansi, { isSelected, isCursor }) {
|
|
52
108
|
const box = isSelected ? ansi.green('[✓]') : '[ ]';
|
|
53
109
|
const pointer = isCursor ? ansi.cyan('❯') : ' ';
|
|
54
110
|
const title = ansi.bold(ansi.white(row.title));
|
|
55
111
|
const summary = ansi.dim(row.summary);
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
return
|
|
112
|
+
const mainLine = `${pointer} ${box} ${title} — ${summary}`;
|
|
113
|
+
const lines = [isCursor ? ansi.inverse(mainLine) : mainLine];
|
|
114
|
+
const hintLine = buildHintLine(hintsFromRow(row), ansi);
|
|
115
|
+
if (hintLine) lines.push(`${HINT_INDENT}${hintLine}`);
|
|
116
|
+
return lines;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Flattens every row into its display lines (1 or 2 each — see
|
|
121
|
+
* buildRowLines) and records, per row, the line index its block starts at.
|
|
122
|
+
* Pure/testable without a TTY: this is the "row height accounting" a
|
|
123
|
+
* viewport/scroll window would need if one's ever added (today's draw()
|
|
124
|
+
* always redraws the full list, no windowing), and it's what keeps
|
|
125
|
+
* mixed 1-line/2-line lists laying out correctly regardless of how many
|
|
126
|
+
* rows above a given one have hints.
|
|
127
|
+
*/
|
|
128
|
+
function layoutRows(rows, ansi, { selected, cursor }) {
|
|
129
|
+
const lines = [];
|
|
130
|
+
const rowLineOffsets = [];
|
|
131
|
+
rows.forEach((row, i) => {
|
|
132
|
+
rowLineOffsets.push(lines.length);
|
|
133
|
+
lines.push(...buildRowLines(row, ansi, { isSelected: selected.has(i), isCursor: cursor === i }));
|
|
134
|
+
});
|
|
135
|
+
return { lines, rowLineOffsets };
|
|
61
136
|
}
|
|
62
137
|
|
|
63
138
|
/** Builds exactly DETAIL_HEIGHT lines (padded/truncated) describing the
|
|
@@ -115,9 +190,7 @@ function pickWithRawMode(rows, stdin, stdout, { details, header } = {}) {
|
|
|
115
190
|
if (header) out.push(ansi.bold(header));
|
|
116
191
|
out.push(ansi.dim('Select bundles to install'));
|
|
117
192
|
out.push('');
|
|
118
|
-
|
|
119
|
-
out.push(renderRowColored(row, ansi, { isSelected: selected.has(i), isCursor: cursor === i }));
|
|
120
|
-
});
|
|
193
|
+
out.push(...layoutRows(rows, ansi, { selected, cursor }).lines);
|
|
121
194
|
out.push('');
|
|
122
195
|
out.push(ansi.dim('─'.repeat(RULE_WIDTH)));
|
|
123
196
|
out.push(...buildDetailLines(rows[cursor], detailFor(details, rows[cursor]), ansi, { isSelected: selected.has(cursor) }));
|
|
@@ -181,12 +254,12 @@ function pickWithRawMode(rows, stdin, stdout, { details, header } = {}) {
|
|
|
181
254
|
|
|
182
255
|
function pickWithNumberedPrompt(rows, stdin, stdout) {
|
|
183
256
|
return new Promise((resolve) => {
|
|
257
|
+
const plainAnsi = createStyler(false);
|
|
184
258
|
stdout.write('Available bundles:\n');
|
|
185
259
|
rows.forEach((row, i) => {
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
stdout.write(` ${i + 1}) ${row.title} — ${row.summary}${depsPart}${secretsPart} ${label}\n`.trimEnd() + '\n');
|
|
260
|
+
stdout.write(` ${i + 1}) ${row.title} — ${row.summary}\n`);
|
|
261
|
+
const hintLine = buildHintLine(hintsFromRow(row), plainAnsi);
|
|
262
|
+
if (hintLine) stdout.write(`${HINT_INDENT}${hintLine}\n`);
|
|
190
263
|
});
|
|
191
264
|
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
192
265
|
rl.question(
|
|
@@ -214,4 +287,13 @@ function pickWithNumberedPrompt(rows, stdin, stdout) {
|
|
|
214
287
|
});
|
|
215
288
|
}
|
|
216
289
|
|
|
217
|
-
module.exports = {
|
|
290
|
+
module.exports = {
|
|
291
|
+
pickBundles,
|
|
292
|
+
buildDetailLines,
|
|
293
|
+
DETAIL_HEIGHT,
|
|
294
|
+
buildRowLines,
|
|
295
|
+
buildHintLine,
|
|
296
|
+
hintsFromRow,
|
|
297
|
+
layoutRows,
|
|
298
|
+
HINT_INDENT,
|
|
299
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yasaswy.nagavolu/agents",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
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",
|