@tina_summer/codepocket 2.0.0 → 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.
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
- HAPI_HOME: path.join(os.homedir(), '.codepocket', 'hub'),
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
 
@@ -137,7 +124,7 @@ function startHub() {
137
124
  detached: false,
138
125
  env: {
139
126
  ...process.env,
140
- HAPI_HOME: path.join(os.homedir(), '.codepocket', 'hub'),
127
+ CODEPOCKET_HOME: path.join(os.homedir(), '.codepocket'),
141
128
  },
142
129
  })
143
130
 
@@ -191,7 +178,7 @@ function findHubBin() {
191
178
  // ── Step 2: Authenticate ──
192
179
 
193
180
  async function findHubToken() {
194
- const hubHome = process.env.HAPI_HOME || path.join(os.homedir(), '.codepocket', 'hub')
181
+ const hubHome = process.env.CODEPOCKET_HOME || path.join(os.homedir(), '.codepocket')
195
182
  const settingsPath = path.join(hubHome, 'settings.json')
196
183
  try {
197
184
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'))
@@ -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/bin/run.js CHANGED
@@ -66,7 +66,7 @@ let sseResponse = null
66
66
  // ── Find CLI token ──
67
67
 
68
68
  async function findHubToken() {
69
- const hubHome = process.env.HAPI_HOME || path.join(os.homedir(), '.codepocket', 'hub')
69
+ const hubHome = process.env.CODEPOCKET_HOME || path.join(os.homedir(), '.codepocket')
70
70
  const settingsPath = path.join(hubHome, 'settings.json')
71
71
  try {
72
72
  const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tina_summer/codepocket",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "CodePocket — 你的全能 AI 随身控制台",
5
5
  "bin": {
6
6
  "codepocket": "bin/codepocket.js",