@dev-anywhere/proxy 0.4.5 → 0.4.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/dist/serve.js CHANGED
@@ -263,7 +263,8 @@ var SessionManager = class {
263
263
  pid,
264
264
  ...resolvedName !== void 0 ? { name: resolvedName } : {},
265
265
  ...resolvedNameLocked !== void 0 ? { nameLocked: resolvedNameLocked } : {},
266
- ...pendingPtyMetadata?.claudeSessionId !== void 0 ? { claudeSessionId: pendingPtyMetadata.claudeSessionId } : {}
266
+ ...pendingPtyMetadata?.claudeSessionId !== void 0 ? { claudeSessionId: pendingPtyMetadata.claudeSessionId } : {},
267
+ ...pendingPtyMetadata?.historySessionId !== void 0 ? { historySessionId: pendingPtyMetadata.historySessionId } : {}
267
268
  };
268
269
  this.sessions.set(info.id, info);
269
270
  this.pendingPtyReconnectMetadata.delete(info.id);
@@ -353,6 +354,15 @@ var SessionManager = class {
353
354
  this.save();
354
355
  this.recordRestoreMetadata(session, claudeSessionId);
355
356
  }
357
+ setHistorySessionId(id, historySessionId) {
358
+ const session = this.sessions.get(id);
359
+ if (!session) {
360
+ throw new Error(`Session not found: ${id}`);
361
+ }
362
+ session.historySessionId = historySessionId;
363
+ this.save();
364
+ this.recordRestoreMetadata(session, historySessionId);
365
+ }
356
366
  setPid(id, pid) {
357
367
  const session = this.sessions.get(id);
358
368
  if (!session) {
@@ -444,7 +454,8 @@ var SessionManager = class {
444
454
  pid: s.pid,
445
455
  ...s.name !== void 0 ? { name: s.name } : {},
446
456
  ...s.nameLocked !== void 0 ? { nameLocked: s.nameLocked } : {},
447
- ...s.claudeSessionId !== void 0 ? { claudeSessionId: s.claudeSessionId } : {}
457
+ ...s.claudeSessionId !== void 0 ? { claudeSessionId: s.claudeSessionId } : {},
458
+ ...s.historySessionId !== void 0 ? { historySessionId: s.historySessionId } : {}
448
459
  };
449
460
  }
450
461
  load() {
@@ -469,6 +480,7 @@ var SessionManager = class {
469
480
  );
470
481
  return;
471
482
  }
483
+ const historyMetadata = readSessionHistoryMetadata(this.historyMetadataPath);
472
484
  for (const item of parsed) {
473
485
  if (item && typeof item === "object" && "state" in item) {
474
486
  const sessionId = String(item.id);
@@ -489,9 +501,13 @@ var SessionManager = class {
489
501
  );
490
502
  continue;
491
503
  }
504
+ const inferredHistorySessionId = info.mode === "json" && info.historySessionId === void 0 && info.claudeSessionId ? historyMetadata.find(
505
+ (record) => record.devAnywhereSessionId === info.id && record.provider === info.provider && record.mode === "json" && record.nativeSessionId !== info.claudeSessionId
506
+ )?.nativeSessionId : void 0;
507
+ const hydratedInfo = inferredHistorySessionId !== void 0 ? { ...info, historySessionId: inferredHistorySessionId } : info;
492
508
  if (info.mode === "pty") {
493
509
  if (info.pid && this.isProcessAlive(info.pid)) {
494
- this.pendingPtyReconnectMetadata.set(info.id, this.toPersistedRecord(info));
510
+ this.pendingPtyReconnectMetadata.set(info.id, this.toPersistedRecord(hydratedInfo));
495
511
  serviceLogger.info(
496
512
  { sessionId: info.id, pid: info.pid },
497
513
  "PTY session skipped on load, terminal alive"
@@ -506,7 +522,7 @@ var SessionManager = class {
506
522
  continue;
507
523
  }
508
524
  if (info.pid && this.isProcessAlive(info.pid)) {
509
- this.sessions.set(info.id, { ...info, state: SessionState.IDLE });
525
+ this.sessions.set(info.id, { ...hydratedInfo, state: SessionState.IDLE });
510
526
  } else {
511
527
  this.onSessionRemoved?.(info.id);
512
528
  serviceLogger.info(
@@ -2630,8 +2646,8 @@ var RelayHistoryHandlers = class {
2630
2646
  const { sessionId: sid, requestId, before, limit } = msg;
2631
2647
  if (!sid) return;
2632
2648
  const session = this.deps.sessionManager.getSession(sid);
2633
- if (session?.claudeSessionId) {
2634
- readSessionMessagesPage(session.claudeSessionId, { before, limit }).then((page) => {
2649
+ if (session?.claudeSessionId || session?.historySessionId) {
2650
+ readSessionHistoryPageForSession(session, { before, limit }).then((page) => {
2635
2651
  this.deps.relaySend(
2636
2652
  serializeControl({
2637
2653
  type: "session_history_messages",
@@ -2692,6 +2708,60 @@ var RelayHistoryHandlers = class {
2692
2708
  serviceLogger.info({ sessionId: sid, count: approvals.length }, "Pending approvals pushed");
2693
2709
  }
2694
2710
  };
2711
+ var RESUME_CURSOR_PREFIX = "resume:";
2712
+ var ACTIVE_CURSOR_PREFIX = "active:";
2713
+ function addCursorPrefix(prefix, messages) {
2714
+ return messages.map(
2715
+ (message) => message.cursor ? { ...message, cursor: `${prefix}${message.cursor}` } : message
2716
+ );
2717
+ }
2718
+ function stripCursorPrefix(prefix, cursor) {
2719
+ return cursor.startsWith(prefix) ? cursor.slice(prefix.length) : cursor;
2720
+ }
2721
+ async function readSessionHistoryPageForSession(session, options) {
2722
+ const historySessionId = session.historySessionId;
2723
+ const activeSessionId = session.claudeSessionId;
2724
+ const hasSeparateHistory = historySessionId !== void 0 && activeSessionId !== void 0 && historySessionId !== activeSessionId;
2725
+ if (!hasSeparateHistory) {
2726
+ const sourceId = activeSessionId ?? historySessionId;
2727
+ if (!sourceId) return { messages: [], hasMore: false };
2728
+ return readSessionMessagesPage(sourceId, options);
2729
+ }
2730
+ if (options.before?.startsWith(ACTIVE_CURSOR_PREFIX)) {
2731
+ const page = await readSessionMessagesPage(activeSessionId, {
2732
+ ...options,
2733
+ before: stripCursorPrefix(ACTIVE_CURSOR_PREFIX, options.before)
2734
+ });
2735
+ return {
2736
+ ...page,
2737
+ messages: addCursorPrefix(ACTIVE_CURSOR_PREFIX, page.messages),
2738
+ ...page.nextBefore !== void 0 ? { nextBefore: `${ACTIVE_CURSOR_PREFIX}${page.nextBefore}` } : {}
2739
+ };
2740
+ }
2741
+ if (options.before?.startsWith(RESUME_CURSOR_PREFIX)) {
2742
+ const page = await readSessionMessagesPage(historySessionId, {
2743
+ ...options,
2744
+ before: stripCursorPrefix(RESUME_CURSOR_PREFIX, options.before)
2745
+ });
2746
+ return {
2747
+ ...page,
2748
+ messages: addCursorPrefix(RESUME_CURSOR_PREFIX, page.messages),
2749
+ ...page.nextBefore !== void 0 ? { nextBefore: `${RESUME_CURSOR_PREFIX}${page.nextBefore}` } : {}
2750
+ };
2751
+ }
2752
+ const [historyPage, activePage] = await Promise.all([
2753
+ readSessionMessagesPage(historySessionId, options),
2754
+ readSessionMessagesPage(activeSessionId, options)
2755
+ ]);
2756
+ return {
2757
+ messages: [
2758
+ ...addCursorPrefix(RESUME_CURSOR_PREFIX, historyPage.messages),
2759
+ ...addCursorPrefix(ACTIVE_CURSOR_PREFIX, activePage.messages)
2760
+ ],
2761
+ hasMore: historyPage.hasMore,
2762
+ ...historyPage.nextBefore !== void 0 ? { nextBefore: `${RESUME_CURSOR_PREFIX}${historyPage.nextBefore}` } : {}
2763
+ };
2764
+ }
2695
2765
 
2696
2766
  // src/serve/relay-permission-handlers.ts
2697
2767
  var RelayPermissionHandlers = class {
@@ -3310,7 +3380,7 @@ var RelaySessionCreateHandler = class {
3310
3380
  nameLocked
3311
3381
  );
3312
3382
  if (resumeSessionId) {
3313
- this.deps.sessionManager.setClaudeSessionId(session.id, resumeSessionId);
3383
+ this.deps.sessionManager.setHistorySessionId(session.id, resumeSessionId);
3314
3384
  }
3315
3385
  this.deps.relaySend(
3316
3386
  serializeControl({