@cjhyy/code-shell-server 0.8.0 → 0.8.1

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.
@@ -67,9 +67,9 @@ export interface WorkerBridgeCoreOptions {
67
67
  fallbackCwd?: () => string;
68
68
  log?: WorkerBridgeLog;
69
69
  /**
70
- * Rewrite/side-effect hook for injectWorkerMessage lines (e.g. agent/run
71
- * trust metadata + on-demand spawn). Returns the line to write; `method`
72
- * is only used for log context.
70
+ * Rewrite/side-effect hook for every host-originated worker frame, whether
71
+ * injected or correlated (e.g. agent/run trust metadata + on-demand spawn).
72
+ * Returns the line to write; `method` is only used for log context.
73
73
  */
74
74
  prepareInbound?: (line: string) => {
75
75
  line: string;
@@ -10,7 +10,7 @@
10
10
  // - stdout line framing (readline split) + listener dispatch
11
11
  // - request/response correlation (id → resolver, with timeout / consume /
12
12
  // settle-on-exit semantics)
13
- // - inbound line injection (`injectWorkerMessage`) with a pluggable
13
+ // - inbound line injection and correlated requests with a pluggable
14
14
  // `prepareInbound` hook for host-specific rewriting (e.g. agent/run trust)
15
15
  // - worker generation counter (bumped on every successful spawn)
16
16
  // - pending outbox flushed once the worker's stdin exists
@@ -283,21 +283,30 @@ export class WorkerBridgeCore {
283
283
  settleOnExit: options.settleOnExit === true,
284
284
  settle,
285
285
  });
286
- const frame = JSON.stringify({
286
+ const rawFrame = JSON.stringify({
287
287
  jsonrpc: "2.0",
288
288
  id,
289
289
  method,
290
290
  ...(params === undefined ? {} : { params }),
291
291
  });
292
- // Wake a lazily-unspawned worker before writing, so a spawn-triggering
293
- // request (pet/IM-gateway agent/run) isn't dropped by sendLine and left
294
- // to hang until timeout. Idempotent when a child is already alive.
295
- if (options.ensureWorker)
296
- this.ensureWorker(options.ensureWorkerCwd);
297
292
  let sent = false;
298
293
  let sendError;
299
294
  try {
300
- sent = this.sendLine(frame);
295
+ // Correlated host requests must cross the same metadata boundary as
296
+ // injected renderer/mobile frames. In particular, Panel App
297
+ // agent.submitPrompt uses request() and carries the session bucket;
298
+ // bypassing this hook left the main process unable to route the first
299
+ // Panel tool call for a restored session.
300
+ const prepared = this.opts.prepareInbound
301
+ ? this.opts.prepareInbound(rawFrame)
302
+ : { line: rawFrame, method: undefined };
303
+ // Wake a lazily-unspawned worker before writing, so a spawn-triggering
304
+ // request (pet/IM-gateway agent/run) isn't dropped by sendLine and left
305
+ // to hang until timeout. Idempotent when prepareInbound already spawned
306
+ // the worker as an agent/run side effect.
307
+ if (options.ensureWorker)
308
+ this.ensureWorker(options.ensureWorkerCwd);
309
+ sent = this.sendLine(prepared.line);
301
310
  }
302
311
  catch (e) {
303
312
  sendError = e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cjhyy/code-shell-server",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "CodeShell server transport layer — mobile remote HTTP/WS host, pairing, passcode gate, tunnel, rooms, uploads, and session/attachment services. Electron-free; precursor of the auth gateway.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -38,9 +38,9 @@
38
38
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
39
39
  },
40
40
  "dependencies": {
41
- "@cjhyy/code-shell-capability-coding": "0.8.0",
42
- "@cjhyy/code-shell-core": "0.8.0",
43
- "@cjhyy/code-shell-web": "0.8.0",
41
+ "@cjhyy/code-shell-capability-coding": "0.8.1",
42
+ "@cjhyy/code-shell-core": "0.8.1",
43
+ "@cjhyy/code-shell-web": "0.8.1",
44
44
  "@types/ws": "^8.18.1",
45
45
  "ws": "^8.21.0"
46
46
  },