instar 0.9.47 → 0.9.49

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.
@@ -0,0 +1,182 @@
1
+ ---
2
+ name: secret-setup
3
+ description: Focused micro-skill for secret management setup. Explains options, guides through Bitwarden installation/login/unlock, configures backend. Exits when done.
4
+ ---
5
+
6
+ # Secret Management Setup
7
+
8
+ You are guiding a user through choosing and configuring how their Instar agent stores secrets (API tokens, bot credentials, etc). This is a **focused conversation** — your ONLY job is to get secret management configured, then exit.
9
+
10
+ ## CRITICAL RULES
11
+
12
+ ### 1. No Interactive CLI Commands — WILL HANG FOREVER
13
+
14
+ **Claude Code's Bash tool CANNOT handle stdin prompts.** Any command that asks for a password, confirmation, or any input will hang until timeout. There is NO workaround — you cannot type into a running command.
15
+
16
+ **UNDERSTAND THIS ABOUT `--raw`:** The `--raw` flag ONLY changes the output format. It does NOT prevent interactive prompts. `bw unlock --raw` STILL prompts for a password and WILL HANG. The password must ALWAYS be passed as a POSITIONAL ARGUMENT before any flags.
17
+
18
+ **Commands that WILL HANG (never run these):**
19
+ ```
20
+ bw unlock --raw # HANGS — no password argument
21
+ bw unlock # HANGS — prompts for password
22
+ bw login --raw # HANGS — no email/password
23
+ bw login # HANGS — prompts for credentials
24
+ echo "text" && bw unlock --raw # HANGS — bw still prompts
25
+ read -s VARIABLE # HANGS — waits for hidden input
26
+ ```
27
+
28
+ **Commands that WORK (use ONLY these patterns):**
29
+ ```
30
+ bw unlock "ACTUAL_PASSWORD_HERE" --raw # Returns session key immediately
31
+ bw login "EMAIL" "PASSWORD" --raw # Returns session key immediately
32
+ bw status --raw # Returns JSON, never prompts
33
+ which bw 2>/dev/null # Checks if installed, never prompts
34
+ bw --version # Returns version, never prompts
35
+ ```
36
+
37
+ **THE RULE:** You MUST have the user's password as text BEFORE running any unlock/login command. Ask the user, get their answer, THEN construct the command with their password as a positional argument.
38
+
39
+ ### 2. No Multi-Choice for Text Input
40
+
41
+ AskUserQuestion multi-choice is for DECISIONS (pick A or B or C).
42
+ NEVER use it to collect free-text input (passwords, emails, tokens).
43
+ When you need text, ask a plain question and wait for the user's response.
44
+
45
+ ### 3. No Assumptions About What's Stored
46
+
47
+ Do NOT assume the user has any specific credentials in Bitwarden. They might have Bitwarden but have never stored anything in it for Instar. Only check what's actually there — never tell the user "I need to restore your Telegram token" unless you've confirmed it exists.
48
+
49
+ ### 4. Terminal Display Rules
50
+ Keep text short. 2-3 sentences max per paragraph. No sentences over ~100 characters.
51
+
52
+ ### 5. No Commands in User-Facing Text
53
+ Never show CLI commands to the user. You run everything. The user's only job is answering your questions.
54
+
55
+ ## The Conversation Flow
56
+
57
+ ### Step 1: Introduce Secret Management
58
+
59
+ Start with a brief, friendly explanation:
60
+
61
+ > Your agent will need to store sensitive things — like API tokens and bot credentials.
62
+ >
63
+ > I'd recommend setting up a password manager so these are backed up securely. That way if you ever reinstall or move to a new machine, everything restores automatically.
64
+
65
+ Then present the choice via AskUserQuestion (this IS a decision — multi-choice is correct here):
66
+
67
+ 1. **"Bitwarden (Recommended)"** — Description: "Free, open-source password manager. Secrets sync across machines and survive reinstalls."
68
+ 2. **"Local encrypted store"** — Description: "AES-256 encrypted on this machine. Good if you only use one computer."
69
+ 3. **"I'll manage secrets manually"** — Description: "You'll paste tokens each time. Not recommended."
70
+
71
+ ### Step 2: Handle the Choice
72
+
73
+ #### If Bitwarden:
74
+
75
+ **Step 2a: Check if `bw` CLI is installed:**
76
+ ```bash
77
+ which bw 2>/dev/null && bw --version 2>/dev/null
78
+ ```
79
+
80
+ **If NOT installed — install it yourself:**
81
+ Tell the user: "Let me install the Bitwarden CLI for you."
82
+ ```bash
83
+ npm install -g @bitwarden/cli
84
+ ```
85
+ If that fails, try `brew install bitwarden-cli` on macOS.
86
+ If installation fails entirely, fall back to local encrypted store and exit.
87
+
88
+ **Step 2b: Check vault status:**
89
+ ```bash
90
+ bw status --raw 2>/dev/null
91
+ ```
92
+ Parse the JSON response. Three possible `status` values:
93
+
94
+ - **`"unlocked"`** — Already good! Skip to Step 2d.
95
+ - **`"locked"`** — Need master password. Go to Step 2c.
96
+ - **`"unauthenticated"`** — Need email + password login. Go to Step 2c.
97
+
98
+ **Step 2c: Get credentials from user and unlock:**
99
+
100
+ If unauthenticated, ask TWO separate questions:
101
+ 1. "What email address do you use for Bitwarden?" (wait for response)
102
+ 2. "What's your Bitwarden master password?" (wait for response)
103
+
104
+ Then run (substituting THEIR ACTUAL ANSWERS):
105
+ ```bash
106
+ BW_SESSION=$(bw login "user@example.com" "their_actual_password" --raw 2>&1)
107
+ echo "RESULT:$BW_SESSION"
108
+ ```
109
+
110
+ If locked (already logged in), ask ONE question:
111
+ 1. "What's your Bitwarden master password?" (wait for response)
112
+
113
+ Then run (substituting THEIR ACTUAL ANSWER):
114
+ ```bash
115
+ BW_SESSION=$(bw unlock "their_actual_password" --raw 2>&1)
116
+ echo "RESULT:$BW_SESSION"
117
+ ```
118
+
119
+ **CHECK THE RESULT:** If `BW_SESSION` is empty or contains "Invalid" or "error":
120
+ > "That didn't work — the password might be wrong. Want to try again?"
121
+
122
+ Allow up to 3 retries. After 3 failures, offer to fall back to local store.
123
+
124
+ **Step 2d: Verify and save session:**
125
+ ```bash
126
+ export BW_SESSION="the_session_key_from_above"
127
+ bw sync --session "$BW_SESSION" 2>/dev/null
128
+ ```
129
+
130
+ Save the session for the main wizard to pick up:
131
+ ```bash
132
+ mkdir -p "$HOME/.instar/secrets"
133
+ echo "$BW_SESSION" > "$HOME/.instar/secrets/.bw-session"
134
+ chmod 600 "$HOME/.instar/secrets/.bw-session"
135
+ ```
136
+
137
+ Tell the user:
138
+ > "Bitwarden is unlocked and ready. Your agent's secrets will be stored securely."
139
+
140
+ **Step 2e: Check for existing Instar secrets (optional, don't assume):**
141
+ ```bash
142
+ bw list items --search "instar" --session "$BW_SESSION" --raw 2>/dev/null
143
+ ```
144
+
145
+ If results are found, tell the user what's available. If nothing is found, that's fine — just move on. Do NOT say "I couldn't find your Telegram credentials" — they might not have any.
146
+
147
+ #### If Local Encrypted Store:
148
+
149
+ No user interaction needed. Tell the user:
150
+ > "Local encrypted store is ready. Your secrets are AES-256 encrypted on this machine."
151
+
152
+ #### If Manual:
153
+
154
+ Tell the user:
155
+ > "Got it. You'll paste tokens when prompted during setup."
156
+
157
+ ### Step 3: Save Backend and Exit
158
+
159
+ Write the backend preference:
160
+ ```bash
161
+ mkdir -p "$HOME/.instar/secrets"
162
+ cat > "$HOME/.instar/secrets/backend.json" << 'JSONEOF'
163
+ {"backend":"CHOSEN_BACKEND","configuredAt":"CURRENT_ISO_DATE"}
164
+ JSONEOF
165
+ ```
166
+
167
+ Verify it was saved:
168
+ ```bash
169
+ cat "$HOME/.instar/secrets/backend.json"
170
+ ```
171
+
172
+ Tell the user this step is done and the main setup will continue automatically.
173
+
174
+ **Then exit.** Do not continue into other setup phases. Your job is done.
175
+
176
+ ## Edge Cases
177
+
178
+ - **"What is Bitwarden?"** — Free, open-source password manager. End-to-end encrypted. Widely trusted. Bitwarden can't read your secrets.
179
+ - **"I use 1Password/LastPass"** — Instar specifically integrates with the Bitwarden CLI. Offer local encrypted store as alternative.
180
+ - **"Skip everything"** — Allow it, but note they'll paste tokens manually each reinstall.
181
+ - **`bw` command times out** — Retry once. If still failing, offer local fallback.
182
+ - **Two-factor auth** — If login returns a 2FA error, ask the user for their authenticator code, then: `bw login "EMAIL" "PASSWORD" --method 0 --code "CODE" --raw`
@@ -602,83 +602,21 @@ Or for short messages:
602
602
  Strip the `[telegram:N]` prefix before interpreting the message. Respond naturally, then relay. Only relay your conversational text — not tool output or internal reasoning.
603
603
  ```
604
604
 
605
- ## Phase 2.5: Secret Management — Protecting Credentials
605
+ ## Phase 2.5: Secret Management — HANDLED BY SETUP.TS
606
606
 
607
- **Before Telegram setup**, configure how the agent stores sensitive data. This determines whether Telegram tokens (and other secrets) survive agent deletion and reinstall.
607
+ **DO NOT handle secret management here.** The setup launcher runs a dedicated `/secret-setup` micro-session BEFORE this wizard starts. By the time you're reading this, `~/.instar/secrets/backend.json` already exists.
608
608
 
609
- ### Why This Comes Before Telegram
609
+ Check the prompt context for `SECRET_BACKEND_CONFIGURED`. If present:
610
+ - Secret management is DONE — do not re-configure it
611
+ - Do not attempt to unlock Bitwarden — the micro-session already handled that
612
+ - Do not prompt the user about secret storage options
613
+ - If `BW_SESSION is available` appears in context, Bitwarden is already unlocked and the env var is set
610
614
 
611
- When a user reinstalls an agent, the Telegram bot token and chat ID are the hardest things to recover. If we set up secret management FIRST, we can:
612
- 1. Auto-restore Telegram credentials on reinstall (no re-setup needed)
613
- 2. Back up tokens before nuke (transparent to user)
614
- 3. Share credentials across machines (via Bitwarden)
615
+ **If `SECRET_BACKEND_CONFIGURED` is NOT in context** (edge case — user ran the wizard directly), check `~/.instar/secrets/backend.json`. If it exists, skip this phase. If it truly doesn't exist, tell the user to run `npx instar` which will handle secret setup properly.
615
616
 
616
- ### Step 2.5a: Check for Existing Secret Backend
617
+ **Credential restoration**: If the backend is Bitwarden and BW_SESSION is available, you MAY check for existing credentials. But do NOT assume any specific credentials exist — check first, then only mention what you actually find. Never say "I need to restore your Telegram token" unless you've confirmed it's there.
617
618
 
618
- First, check if this agent already has a secret backend configured:
619
-
620
- ```bash
621
- # Check if backend preference exists
622
- cat "$HOME/.instar/secrets/backend.json" 2>/dev/null
623
- ```
624
-
625
- If a preference exists and it's not `manual`, tell the user and move on:
626
- > "Your secrets are backed up using [Bitwarden / local encrypted store]. Any saved credentials will be auto-restored."
627
-
628
- Then try to restore Telegram credentials:
629
- ```javascript
630
- import { SecretManager } from 'instar';
631
- const mgr = new SecretManager({ agentName: '<name>' });
632
- mgr.initialize();
633
- const telegram = mgr.restoreTelegramConfig();
634
- // If telegram is not null, we have token + chatId
635
- ```
636
-
637
- If Telegram credentials are restored and valid (verify with `getMe` API call), **skip Phase 3 entirely** and tell the user:
638
- > "Telegram credentials restored and validated! Bot @[username] is ready."
639
-
640
- ### Step 2.5b: Configure Secret Backend (Fresh Install)
641
-
642
- If no preference exists, present the choice conversationally:
643
-
644
- > **How should your agent store sensitive data?**
645
- >
646
- > Things like Telegram tokens and auth keys need to be stored securely. This choice persists across reinstalls.
647
-
648
- Present these options via AskUserQuestion:
649
-
650
- 1. **"Bitwarden (Recommended)"** — Description: "Cross-machine. Cloud-backed. Install any agent on any machine with just your master password."
651
- 2. **"Local encrypted store"** — Description: "AES-256 encrypted on this machine. macOS Keychain for password-free access. Survives reinstalls."
652
- 3. **"I'll manage secrets manually"** — Description: "You'll paste tokens each time you install."
653
-
654
- **If Bitwarden selected:**
655
- ```bash
656
- # Check if bw CLI is available
657
- which bw 2>/dev/null
658
- ```
659
- If not available, tell them how to install it and fall back to local:
660
- > "Bitwarden CLI isn't installed yet. You can set it up later. For now, I'll use the local encrypted store."
661
-
662
- **If Local selected (or Bitwarden fallback):**
663
- The local store auto-initializes using macOS Keychain (no password needed) or a machine-derived key. No user interaction required — just initialize it silently:
664
- ```javascript
665
- const mgr = new SecretManager({ agentName: '<name>', backend: 'local' });
666
- mgr.initialize();
667
- ```
668
- Tell the user:
669
- > "Local encrypted store initialized. Your secrets are AES-256 encrypted and will survive reinstalls."
670
-
671
- **If Manual selected:**
672
- > "Got it. You'll need to provide tokens manually during setup and after reinstalls."
673
-
674
- ### Step 2.5c: Save Backend Preference
675
-
676
- Write the backend preference so it persists:
677
- ```javascript
678
- mgr.configureBackend(chosenBackend);
679
- ```
680
-
681
- This saves to `~/.instar/secrets/backend.json` — it survives agent deletion since it's outside the agent directory.
619
+ **CRITICAL No Interactive CLI Commands**: If you ever need to run `bw` commands, the password MUST be a positional argument: `bw unlock "PASSWORD" --raw`. The `--raw` flag does NOT prevent interactive prompts — it only changes output format. `bw unlock --raw` WILL HANG FOREVER.
682
620
 
683
621
  ---
684
622
 
@@ -537,7 +537,7 @@ I run with \`--dangerously-skip-permissions\` — meaning I have full access to
537
537
 
538
538
  **"Present Options"** — If I know the next steps, they're not suggestions — they're my job.
539
539
 
540
- **"Interactive CLI Commands"** — Claude Code's Bash tool CANNOT handle commands that wait for stdin. Commands like \`bw unlock\` (no args), \`read -s\`, \`npm init\` (interactive), or any tool with password/confirmation prompts will HANG FOREVER. Always use non-interactive equivalents: pass arguments directly, use \`--raw\`, \`--yes\`, \`-y\`, \`--non-interactive\` flags. Collect user input via conversation FIRST, then pass it as command arguments.
540
+ **"Interactive CLI Commands"** — Claude Code's Bash tool CANNOT handle stdin prompts. Any command that waits for input HANGS FOREVER. IMPORTANT: the \`--raw\` flag does NOT prevent prompts — it only changes output format. \`bw unlock --raw\` STILL HANGS because it still prompts for a password. The password must be a POSITIONAL ARGUMENT: \`bw unlock "PASSWORD" --raw\`. Same for all CLI tools: collect input from the user via conversation FIRST, then pass it as arguments to the command. Never run a command hoping it will prompt the user.
541
541
 
542
542
  **"Multi-Choice for Text Input"** — AskUserQuestion multi-choice is for DECISIONS (pick A or B). Never use it to collect free-text input (passwords, emails, tokens). It makes "Skip" look like the default and buries the actual input. Ask a plain question and wait instead.
543
543
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instar",
3
- "version": "0.9.47",
3
+ "version": "0.9.49",
4
4
  "description": "Persistent autonomy infrastructure for AI agents",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,7 +51,8 @@
51
51
  "dashboard",
52
52
  "upgrades",
53
53
  "src/templates",
54
- ".claude/skills/setup-wizard"
54
+ ".claude/skills/setup-wizard",
55
+ ".claude/skills/secret-setup"
55
56
  ],
56
57
  "license": "MIT",
57
58
  "engines": {