refactor(setup): check env vars per-step instead of upfront all-or-nothing
Remove the grouped detectExistingEnv() block that asked "reuse all or start fresh" at the top of setup. Each channel step now reads credentials directly from .env on disk via readEnvKey() and offers to reuse them individually at the point of use. - Add readEnvKey() helper in setup/environment.ts - Remove ENV_KEY_GROUPS, ExistingEnvGroup, detectExistingEnv from auto.ts - Move detectRegisteredGroups skip to right before cli-agent step - Switch all channel files (telegram, discord, slack, teams, imessage) from process.env to readEnvKey() Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -122,39 +122,6 @@ async function main(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
// Detect existing .env and offer to reuse it so the user doesn't have to
|
||||
// paste credentials again on a re-run.
|
||||
const existingEnv = detectExistingEnv();
|
||||
if (existingEnv) {
|
||||
const lines = Object.values(existingEnv.groups).map(
|
||||
(g) => ` ${k.green('✓')} ${g.label}`,
|
||||
);
|
||||
note(lines.join('\n'), 'Found existing configuration');
|
||||
|
||||
const reuseChoice = ensureAnswer(
|
||||
await brightSelect({
|
||||
message: 'Use this existing environment?',
|
||||
options: [
|
||||
{ value: 'reuse', label: 'Yes, use what I already have', hint: 'recommended' },
|
||||
{ value: 'fresh', label: 'No, start fresh' },
|
||||
],
|
||||
initialValue: 'reuse',
|
||||
}),
|
||||
) as 'reuse' | 'fresh';
|
||||
setupLog.userInput('existing_env_choice', reuseChoice);
|
||||
|
||||
if (reuseChoice === 'reuse') {
|
||||
for (const [key, value] of Object.entries(existingEnv.raw)) {
|
||||
if (!process.env[key]) process.env[key] = value;
|
||||
}
|
||||
if (existingEnv.groups.onecli) skip.add('onecli');
|
||||
if (detectRegisteredGroups(process.cwd())) {
|
||||
skip.add('cli-agent');
|
||||
skip.add('first-chat');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!skip.has('container')) {
|
||||
p.log.message(brandBody(dimWrap('Your assistant lives in its own sandbox. It can only see what you explicitly share.', 4)));
|
||||
p.log.message(
|
||||
@@ -344,6 +311,11 @@ async function main(): Promise<void> {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
if (!skip.has('cli-agent') && detectRegisteredGroups(process.cwd())) {
|
||||
skip.add('cli-agent');
|
||||
skip.add('first-chat');
|
||||
}
|
||||
|
||||
if (!skip.has('cli-agent')) {
|
||||
await resolveDisplayName();
|
||||
const res = await runQuietStep(
|
||||
@@ -1063,56 +1035,6 @@ async function askChannelChoice(): Promise<ChannelChoice> {
|
||||
|
||||
// ─── interactive / env helpers ─────────────────────────────────────────
|
||||
|
||||
interface ExistingEnvGroup {
|
||||
label: string;
|
||||
keys: string[];
|
||||
}
|
||||
|
||||
const ENV_KEY_GROUPS: Record<string, { label: string; keys: string[] }> = {
|
||||
onecli: { label: 'OneCLI', keys: ['ONECLI_URL'] },
|
||||
telegram: { label: 'Telegram', keys: ['TELEGRAM_BOT_TOKEN'] },
|
||||
discord: { label: 'Discord', keys: ['DISCORD_BOT_TOKEN', 'DISCORD_APPLICATION_ID', 'DISCORD_PUBLIC_KEY'] },
|
||||
slack: { label: 'Slack', keys: ['SLACK_BOT_TOKEN', 'SLACK_SIGNING_SECRET'] },
|
||||
signal: { label: 'Signal', keys: ['SIGNAL_ACCOUNT'] },
|
||||
teams: { label: 'Teams', keys: ['TEAMS_APP_ID', 'TEAMS_APP_PASSWORD', 'TEAMS_APP_TENANT_ID', 'TEAMS_APP_TYPE'] },
|
||||
whatsapp: { label: 'WhatsApp', keys: ['ASSISTANT_HAS_OWN_NUMBER'] },
|
||||
imessage: { label: 'iMessage', keys: ['IMESSAGE_LOCAL', 'IMESSAGE_ENABLED', 'IMESSAGE_SERVER_URL', 'IMESSAGE_API_KEY'] },
|
||||
};
|
||||
|
||||
function detectExistingEnv(): { groups: Record<string, ExistingEnvGroup>; raw: Record<string, string> } | null {
|
||||
const envPath = path.join(process.cwd(), '.env');
|
||||
if (!fs.existsSync(envPath)) return null;
|
||||
|
||||
let content: string;
|
||||
try {
|
||||
content = fs.readFileSync(envPath, 'utf-8');
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
const raw: Record<string, string> = {};
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed || trimmed.startsWith('#')) continue;
|
||||
const eq = trimmed.indexOf('=');
|
||||
if (eq < 1) continue;
|
||||
raw[trimmed.slice(0, eq)] = trimmed.slice(eq + 1);
|
||||
}
|
||||
|
||||
if (Object.keys(raw).length === 0) return null;
|
||||
|
||||
const groups: Record<string, ExistingEnvGroup> = {};
|
||||
for (const [id, def] of Object.entries(ENV_KEY_GROUPS)) {
|
||||
const found = def.keys.filter((key) => raw[key] !== undefined);
|
||||
if (found.length > 0) {
|
||||
groups[id] = { label: def.label, keys: found };
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(groups).length === 0) return null;
|
||||
return { groups, raw };
|
||||
}
|
||||
|
||||
function anthropicSecretExists(): boolean {
|
||||
try {
|
||||
const res = spawnSync('onecli', ['secrets', 'list'], {
|
||||
|
||||
Reference in New Issue
Block a user