instar 0.28.22 → 0.28.23

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.
@@ -142,25 +142,37 @@ If they type something else → interpret conversationally and route.
142
142
 
143
143
  #### If gh_status="auth-needed"
144
144
 
145
- Walk the user through auth FIRST:
145
+ **MANDATORY DO THIS BEFORE ASKING FOR AN AGENT NAME.** The discovery scan ran without GitHub access. The user may already have agents backed up to GitHub from another machine. You MUST offer to sign them in BEFORE proceeding to fresh-install prompts. Skipping this step has caused users to create duplicate agents instead of restoring existing ones.
146
146
 
147
- > Let me check if you have agents backed up on GitHub.
148
- > I need to sign you into GitHub this opens your browser.
147
+ Say:
148
+ > Before we set up a new agent, let me check GitHub for any agents you've backed up from another machine. I need to sign you init takes about 30 seconds.
149
149
 
150
- ```bash
151
- gh auth login --web --git-protocol https
152
- ```
153
-
154
- After auth, re-scan and present results.
150
+ Then follow the **GitHub Device-Code Auth Flow** below. After auth completes, re-run discovery (call `runDiscovery` via the setup CLI or re-invoke the wizard) and present the updated agent list. Only proceed to fresh-install if discovery still shows zero agents.
155
151
 
156
152
  #### If gh_status="unavailable"
157
153
 
158
- Ask:
159
- > Have you used Instar before on another machine?
154
+ GitHub CLI isn't installed. With instar 0.28.18+ this should be rare — the prerequisite check auto-installs gh. If you somehow get here, ask:
155
+ > Have you used Instar before on another machine? If so, I should install GitHub CLI so I can find your existing agents before we create a new one.
160
156
 
161
- If yes: Show install guidance for the platform. After install auth scan.
157
+ If yes: Install gh (brew/apt), then follow the **GitHub Device-Code Auth Flow** below, then re-run discovery.
162
158
  If no: Continue to fresh install.
163
159
 
160
+ #### GitHub Device-Code Auth Flow (use this everywhere `gh auth login` is needed)
161
+
162
+ **DO NOT run `gh auth login` synchronously in Bash** — it blocks waiting for the user to visit a URL and the Bash tool buffer hides the prompt. The user will see a frozen command and have no idea what to do.
163
+
164
+ Instead:
165
+
166
+ 1. Start `gh auth login --web --git-protocol https` with `run_in_background: true`.
167
+ 2. Poll the background output every 2 seconds (BashOutput tool) until you see a line matching `! First copy your one-time code: XXXX-XXXX` and a line containing `https://github.com/login/device`.
168
+ 3. Extract the code and URL, then present them to the user conversationally — NOT as raw Bash output:
169
+ > To sign in, visit **https://github.com/login/device** and enter this code: **XXXX-XXXX**
170
+ > I'll wait here until you're done.
171
+ 4. Poll `gh auth status` every 5 seconds (foreground, fast). When it exits 0, the user has finished. Stop polling the background process and let it complete on its own.
172
+ 5. Confirm: "You're signed in as <username>. Let me check for your agents now."
173
+
174
+ If 5 minutes pass with no auth completion, ask the user if they want to keep waiting or skip GitHub for now.
175
+
164
176
  #### Normal fresh install options
165
177
 
166
178
  **If inside a git repo:**
@@ -1909,15 +1921,7 @@ Wait for user to install, then re-check.
1909
1921
  gh auth status 2>&1
1910
1922
  ```
1911
1923
 
1912
- If not authenticated, walk them through it:
1913
-
1914
- > I need to connect to your GitHub account. This opens your browser for a secure sign-in.
1915
-
1916
- ```bash
1917
- gh auth login --web --git-protocol https
1918
- ```
1919
-
1920
- This is an interactive command that opens the browser — run it with `stdio: 'inherit'` so the user sees the auth flow. Wait for it to complete.
1924
+ If not authenticated, use the **GitHub Device-Code Auth Flow** described in Entry Point B (above). DO NOT run `gh auth login` synchronously — it blocks the Bash tool and the user will see a frozen command. Run in background, parse the device code and URL from output, present them conversationally, and poll `gh auth status` until success.
1921
1925
 
1922
1926
  **Step 3: Create private repo**
1923
1927
 
package/dist/cli.js CHANGED
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2PH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA6zCD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAipItE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/commands/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2PH,UAAU,YAAY;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;2DACuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AA81CD,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAkpItE;AAED,wBAAsB,UAAU,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAsDzE;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAuD5E"}
@@ -7,7 +7,7 @@
7
7
  * When Telegram is configured, wires up message routing:
8
8
  * topic message → find/spawn session → inject message → session replies via [telegram:N]
9
9
  */
10
- import { execFileSync, execSync } from 'node:child_process';
10
+ import { execFileSync } from 'node:child_process';
11
11
  import fs from 'node:fs';
12
12
  import os from 'node:os';
13
13
  import path from 'node:path';
@@ -1221,6 +1221,34 @@ async function ensureAgentUpdatesTopic(telegram, state) {
1221
1221
  console.error(` Failed to create Agent Updates topic: ${err}`);
1222
1222
  }
1223
1223
  }
1224
+ /**
1225
+ * Find npm's CLI entry point (npm-cli.js) so we can run npm via
1226
+ * `execFileSync(process.execPath, [npmCli, ...args])` — no shell required.
1227
+ * This avoids "/bin/sh ENOENT" failures in minimal/containerized environments.
1228
+ */
1229
+ function findNpmCli() {
1230
+ // npm ships alongside node — look for it relative to process.execPath
1231
+ const nodeDir = path.dirname(process.execPath);
1232
+ // Standard layout: node is in bin/, npm-cli.js is in lib/node_modules/npm/bin/npm-cli.js
1233
+ const libNpmCli = path.resolve(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js');
1234
+ if (fs.existsSync(libNpmCli))
1235
+ return libNpmCli;
1236
+ // Homebrew on macOS: node in /opt/homebrew/bin, npm-cli in /opt/homebrew/lib/node_modules/npm/bin/npm-cli.js
1237
+ // (same layout, but verify explicitly for clarity)
1238
+ for (const candidate of [
1239
+ '/opt/homebrew/lib/node_modules/npm/bin/npm-cli.js',
1240
+ '/usr/local/lib/node_modules/npm/bin/npm-cli.js',
1241
+ '/usr/lib/node_modules/npm/bin/npm-cli.js',
1242
+ ]) {
1243
+ if (fs.existsSync(candidate))
1244
+ return candidate;
1245
+ }
1246
+ // Last resort: use the npm shell wrapper (requires shell, but at least we tried)
1247
+ const npmBin = path.join(nodeDir, 'npm');
1248
+ if (fs.existsSync(npmBin))
1249
+ return npmBin;
1250
+ throw new Error('Cannot find npm CLI — native module rebuild unavailable');
1251
+ }
1224
1252
  /**
1225
1253
  * Pre-flight check: ensure better-sqlite3 native bindings are compiled for the current Node.js version.
1226
1254
  *
@@ -1271,10 +1299,13 @@ async function ensureSqliteBindings() {
1271
1299
  else {
1272
1300
  // Fallback: npm rebuild in the directory containing better-sqlite3.
1273
1301
  // Shadow installs have their own node_modules — try that first, then global.
1302
+ // IMPORTANT: Use execFileSync (no shell) instead of execSync to avoid
1303
+ // "/bin/sh ENOENT" failures in minimal/containerized environments.
1304
+ const npmCli = findNpmCli();
1274
1305
  const instarDir = new URL('../../..', import.meta.url).pathname;
1275
1306
  const shadowBs3 = path.join(instarDir, 'node_modules', 'better-sqlite3');
1276
1307
  if (fs.existsSync(shadowBs3)) {
1277
- execSync('npm rebuild better-sqlite3', {
1308
+ execFileSync(process.execPath, [npmCli, 'rebuild', 'better-sqlite3'], {
1278
1309
  cwd: instarDir,
1279
1310
  encoding: 'utf-8',
1280
1311
  timeout: 60000,
@@ -1282,8 +1313,8 @@ async function ensureSqliteBindings() {
1282
1313
  });
1283
1314
  }
1284
1315
  else {
1285
- const globalInstarDir = execSync('npm root -g', { encoding: 'utf-8', timeout: 10000 }).trim() + '/instar';
1286
- execSync('npm rebuild better-sqlite3', {
1316
+ const globalInstarDir = execFileSync(process.execPath, [npmCli, 'root', '-g'], { encoding: 'utf-8', timeout: 10000 }).toString().trim() + '/instar';
1317
+ execFileSync(process.execPath, [npmCli, 'rebuild', 'better-sqlite3'], {
1287
1318
  cwd: globalInstarDir,
1288
1319
  encoding: 'utf-8',
1289
1320
  timeout: 60000,
@@ -2295,8 +2326,9 @@ export async function startServer(options) {
2295
2326
  execFileSync(process.execPath, [fixScript], { encoding: 'utf-8', timeout: 60000, stdio: 'pipe' });
2296
2327
  }
2297
2328
  else {
2298
- const globalInstarDir = execSync('npm root -g', { encoding: 'utf-8', timeout: 10000 }).trim() + '/instar';
2299
- execSync('npm rebuild better-sqlite3', {
2329
+ const npmCli = findNpmCli();
2330
+ const globalInstarDir = execFileSync(process.execPath, [npmCli, 'root', '-g'], { encoding: 'utf-8', timeout: 10000 }).toString().trim() + '/instar';
2331
+ execFileSync(process.execPath, [npmCli, 'rebuild', 'better-sqlite3'], {
2300
2332
  cwd: globalInstarDir,
2301
2333
  encoding: 'utf-8',
2302
2334
  timeout: 60000,