@tina_summer/codepocket 2.2.6 → 2.2.7
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 +47 -21
- package/package.json +1 -1
package/bin/codepocket.js
CHANGED
|
@@ -98,11 +98,13 @@ function findHubBin() {
|
|
|
98
98
|
return null
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
function isHubRunning(hubUrl) {
|
|
101
|
+
async function isHubRunning(hubUrl) {
|
|
102
102
|
try {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const controller = new AbortController()
|
|
104
|
+
const timer = setTimeout(() => controller.abort(), 2000)
|
|
105
|
+
const res = await fetch(`${hubUrl}/api/sessions`, { signal: controller.signal })
|
|
106
|
+
clearTimeout(timer)
|
|
107
|
+
return res.status > 0 // Any HTTP response means hub is up
|
|
106
108
|
} catch { return false }
|
|
107
109
|
}
|
|
108
110
|
|
|
@@ -266,27 +268,25 @@ function log(msg) {
|
|
|
266
268
|
|
|
267
269
|
function waitForHub() {
|
|
268
270
|
return new Promise((resolve) => {
|
|
269
|
-
if (noHub
|
|
271
|
+
if (noHub) { resolve(); return }
|
|
272
|
+
isHubRunning(hubUrl).then(up => { if (up) { resolve(); return } })
|
|
270
273
|
let attempts = 0
|
|
271
274
|
const check = setInterval(() => {
|
|
272
275
|
attempts++
|
|
273
|
-
|
|
274
|
-
clearInterval(check)
|
|
275
|
-
resolve()
|
|
276
|
-
}
|
|
277
|
-
clearInterval(check)
|
|
278
|
-
resolve()
|
|
279
|
-
}
|
|
276
|
+
isHubRunning(hubUrl).then(up => {
|
|
277
|
+
if (up) { clearInterval(check); resolve() }
|
|
278
|
+
else if (attempts > 30) { clearInterval(check); resolve() }
|
|
279
|
+
})
|
|
280
280
|
}, 1000)
|
|
281
281
|
})
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
function startHub(hubBin) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (!hubBin) { resolve(); return }
|
|
284
|
+
async function startHub(hubBin) {
|
|
285
|
+
if (noHub) return
|
|
286
|
+
if (await isHubRunning(hubUrl)) return
|
|
287
|
+
if (!hubBin) return
|
|
289
288
|
|
|
289
|
+
return new Promise((resolve) => {
|
|
290
290
|
const hub = spawn(hubBin, ['hub', 'start'], {
|
|
291
291
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
292
292
|
detached: false,
|
|
@@ -303,8 +303,8 @@ function startHub(hubBin) {
|
|
|
303
303
|
}
|
|
304
304
|
})
|
|
305
305
|
|
|
306
|
-
setTimeout(() => {
|
|
307
|
-
if (!started && isHubRunning(hubUrl)) { started = true }
|
|
306
|
+
setTimeout(async () => {
|
|
307
|
+
if (!started && await isHubRunning(hubUrl)) { started = true }
|
|
308
308
|
resolve()
|
|
309
309
|
}, 8000)
|
|
310
310
|
|
|
@@ -537,17 +537,30 @@ async function handleSpawnSession(requestId, directory) {
|
|
|
537
537
|
log(`[DEBUG:spawn] Spawning: ${hubBin} ${spawnArgs.join(' ')}`)
|
|
538
538
|
|
|
539
539
|
const child = spawn(hubBin, spawnArgs, {
|
|
540
|
-
stdio: 'ignore',
|
|
540
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
541
541
|
detached: true,
|
|
542
542
|
env: { ...process.env, ...HOME_ENV },
|
|
543
543
|
})
|
|
544
544
|
log(`[DEBUG:spawn] Process spawned, PID=${child.pid}`)
|
|
545
|
+
let spawnStderr = ''
|
|
546
|
+
child.stderr.on('data', (d) => {
|
|
547
|
+
const text = d.toString().trim()
|
|
548
|
+
if (text) {
|
|
549
|
+
spawnStderr += text + '\n'
|
|
550
|
+
log(`[DEBUG:spawn] stderr: ${text.slice(0, 500)}`)
|
|
551
|
+
}
|
|
552
|
+
})
|
|
553
|
+
child.stdout.on('data', (d) => {
|
|
554
|
+
const text = d.toString().trim()
|
|
555
|
+
if (text) log(`[DEBUG:spawn] stdout: ${text.slice(0, 500)}`)
|
|
556
|
+
})
|
|
545
557
|
child.unref()
|
|
546
558
|
child.on('error', (err) => {
|
|
547
559
|
log(`[DEBUG:spawn] Process error: ${err.message}`)
|
|
548
560
|
})
|
|
549
561
|
child.on('exit', (code, signal) => {
|
|
550
562
|
log(`[DEBUG:spawn] Process exited: code=${code}, signal=${signal}, PID=${child.pid}`)
|
|
563
|
+
if (spawnStderr) log(`[DEBUG:spawn] Full stderr:\n${spawnStderr.slice(0, 2000)}`)
|
|
551
564
|
})
|
|
552
565
|
|
|
553
566
|
// Refresh JWT before polling
|
|
@@ -682,17 +695,30 @@ async function handleResumeSession(requestId, sessionId) {
|
|
|
682
695
|
const spawnArgs = ['--path', directory, '--resume', claudeSessionId]
|
|
683
696
|
log(`[DEBUG:resume] Spawning: ${hubBin} ${spawnArgs.join(' ')}`)
|
|
684
697
|
const child = spawn(hubBin, spawnArgs, {
|
|
685
|
-
stdio: 'ignore',
|
|
698
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
686
699
|
detached: true,
|
|
687
700
|
env: { ...process.env, ...HOME_ENV },
|
|
688
701
|
})
|
|
689
702
|
log(`[DEBUG:resume] Process spawned, PID=${child.pid}`)
|
|
703
|
+
let resumeStderr = ''
|
|
704
|
+
child.stderr.on('data', (d) => {
|
|
705
|
+
const text = d.toString().trim()
|
|
706
|
+
if (text) {
|
|
707
|
+
resumeStderr += text + '\n'
|
|
708
|
+
log(`[DEBUG:resume] stderr: ${text.slice(0, 500)}`)
|
|
709
|
+
}
|
|
710
|
+
})
|
|
711
|
+
child.stdout.on('data', (d) => {
|
|
712
|
+
const text = d.toString().trim()
|
|
713
|
+
if (text) log(`[DEBUG:resume] stdout: ${text.slice(0, 500)}`)
|
|
714
|
+
})
|
|
690
715
|
child.unref()
|
|
691
716
|
child.on('error', (err) => {
|
|
692
717
|
log(`[DEBUG:resume] Process error: ${err.message}`)
|
|
693
718
|
})
|
|
694
719
|
child.on('exit', (code, signal) => {
|
|
695
720
|
log(`[DEBUG:resume] Process exited: code=${code}, signal=${signal}, PID=${child.pid}`)
|
|
721
|
+
if (resumeStderr) log(`[DEBUG:resume] Full stderr:\n${resumeStderr.slice(0, 2000)}`)
|
|
696
722
|
})
|
|
697
723
|
|
|
698
724
|
// 3. Poll for session to become active
|