@tina_summer/codepocket 2.1.1 → 2.1.2
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 +40 -0
- package/package.json +1 -1
package/bin/codepocket.js
CHANGED
|
@@ -256,6 +256,14 @@ function connectRelay() {
|
|
|
256
256
|
handleSpawnSession(msg.requestId, msg.directory)
|
|
257
257
|
break
|
|
258
258
|
}
|
|
259
|
+
case 'list-dir': {
|
|
260
|
+
handleListDir(msg.requestId, msg.path)
|
|
261
|
+
break
|
|
262
|
+
}
|
|
263
|
+
case 'list-dir': {
|
|
264
|
+
handleListDir(msg.requestId, msg.path)
|
|
265
|
+
break
|
|
266
|
+
}
|
|
259
267
|
}
|
|
260
268
|
})
|
|
261
269
|
|
|
@@ -366,9 +374,27 @@ async function handleSpawnSession(requestId, directory) {
|
|
|
366
374
|
}
|
|
367
375
|
}
|
|
368
376
|
|
|
377
|
+
function handleListDir(requestId, dirPath) {
|
|
378
|
+
try {
|
|
379
|
+
const resolved = (dirPath || '~').replace(/^~/, os.homedir())
|
|
380
|
+
const abs = path.resolve(resolved)
|
|
381
|
+
const entries = fs.readdirSync(abs, { withFileTypes: true })
|
|
382
|
+
.filter(d => d.isDirectory())
|
|
383
|
+
.map(d => ({ name: d.name, path: path.join(abs, d.name) }))
|
|
384
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
385
|
+
sendToRelay({ type: 'list-dir-result', requestId, path: abs, entries })
|
|
386
|
+
} catch (err) {
|
|
387
|
+
sendToRelay({ type: 'list-dir-result', requestId, error: err.message })
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
369
391
|
// ── Background connect: auth + MCP + SSE + relay ──
|
|
370
392
|
|
|
371
393
|
async function connectInBackground() {
|
|
394
|
+
if (!relayUrl) {
|
|
395
|
+
console.log('[codepocket] 未配置 Relay 地址,手机连接功能不可用')
|
|
396
|
+
return
|
|
397
|
+
}
|
|
372
398
|
try {
|
|
373
399
|
const token = await findHubToken()
|
|
374
400
|
jwt = await authenticateHub(token)
|
|
@@ -403,6 +429,20 @@ async function run() {
|
|
|
403
429
|
console.error('[codepocket] ✗ Key 不能为空')
|
|
404
430
|
process.exit(1)
|
|
405
431
|
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// 1.5 Relay URL (prompt if missing)
|
|
435
|
+
if (!relayUrl) {
|
|
436
|
+
relayUrl = await new Promise((resolve) => {
|
|
437
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout })
|
|
438
|
+
rl.question(' Relay URL (如 wss://example.com/ws): ', (answer) => {
|
|
439
|
+
rl.close()
|
|
440
|
+
resolve(answer.trim())
|
|
441
|
+
})
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (relayKey) {
|
|
406
446
|
saveConfig({ ...loadConfig(), relayKey, relayUrl })
|
|
407
447
|
console.log('[codepocket] ✓ 配置已保存')
|
|
408
448
|
}
|