@tina_summer/codepocket 2.0.1 → 2.1.0

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.
Files changed (2) hide show
  1. package/bin/codepocket.js +40 -15
  2. package/package.json +1 -1
package/bin/codepocket.js CHANGED
@@ -67,20 +67,7 @@ if (args[0] === 'test') {
67
67
 
68
68
  if (!CONNECT_ARGS.includes(args[0])) {
69
69
  // Default or any other subcommand → pass through to hub binary (runs Claude)
70
- const hubBin = findHubBin()
71
- if (hubBin) {
72
- const child = spawn(hubBin, args, {
73
- stdio: 'inherit',
74
- env: {
75
- ...process.env,
76
- CODEPOCKET_HOME: path.join(os.homedir(), '.codepocket'),
77
- },
78
- })
79
- child.on('exit', (code) => process.exit(code || 0))
80
- } else {
81
- console.error('[!] 找不到 Hub 二进制')
82
- process.exit(1)
83
- }
70
+ runDefault(args)
84
71
  return
85
72
  }
86
73
 
@@ -376,7 +363,45 @@ async function handleAuthRequest(requestId, accessToken) {
376
363
  }
377
364
  }
378
365
 
379
- // ── Main ──
366
+ // ── Default mode: auto-connect then launch Claude ──
367
+
368
+ async function runDefault(passThroughArgs) {
369
+ const hubBin = findHubBin()
370
+ if (!hubBin) {
371
+ console.error('[!] 找不到 Hub 二进制')
372
+ process.exit(1)
373
+ }
374
+
375
+ // Check if hub + relay are already running
376
+ let hubRunning = false
377
+ try {
378
+ const result = execSync(`curl -s -o /dev/null -w "%{http_code}" ${hubUrl}/ 2>/dev/null`).toString().trim()
379
+ hubRunning = result === '200'
380
+ } catch {}
381
+
382
+ // If hub not running, fork a background process to run connect flow
383
+ if (!hubRunning) {
384
+ const savedCfg = loadConfig()
385
+ if (savedCfg.relayKey) {
386
+ // Spawn `codepocket connect` as a detached background process
387
+ const bg = spawn(process.execPath, [process.argv[1], 'connect'], {
388
+ stdio: 'ignore',
389
+ detached: true,
390
+ env: { ...process.env, CODEPOCKET_HOME: path.join(os.homedir(), '.codepocket') },
391
+ })
392
+ bg.unref()
393
+ }
394
+ }
395
+
396
+ // Launch Claude
397
+ const child = spawn(hubBin, passThroughArgs, {
398
+ stdio: 'inherit',
399
+ env: { ...process.env, CODEPOCKET_HOME: path.join(os.homedir(), '.codepocket') },
400
+ })
401
+ child.on('exit', (code) => process.exit(code || 0))
402
+ }
403
+
404
+ // ── Main (connect mode) ──
380
405
 
381
406
  async function main() {
382
407
  console.log()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tina_summer/codepocket",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "CodePocket — 你的全能 AI 随身控制台",
5
5
  "bin": {
6
6
  "codepocket": "bin/codepocket.js",