handmux 0.34.0 → 0.36.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.
Files changed (79) hide show
  1. package/dist/build-meta.json +3 -3
  2. package/dist/package.json +13 -13
  3. package/dist/public/assets/{abnfDiagram-O67JEVCF-CfEOyxDH.js → abnfDiagram-O67JEVCF-77h2IIrd.js} +1 -1
  4. package/dist/public/assets/{arc-CWOmUQMu.js → arc-B1uiT5Hv.js} +1 -1
  5. package/dist/public/assets/{architectureDiagram-NJMV4G6O-BkLlCd5w.js → architectureDiagram-NJMV4G6O-CIzN4Www.js} +1 -1
  6. package/dist/public/assets/{blockDiagram-BEXU5L5S-Ciuoprd6.js → blockDiagram-BEXU5L5S-CFLMQR49.js} +1 -1
  7. package/dist/public/assets/{c4Diagram-YGBWAQC7-DM9-eJxf.js → c4Diagram-YGBWAQC7-De2rKPDq.js} +1 -1
  8. package/dist/public/assets/channel-DaUmhuF_.js +1 -0
  9. package/dist/public/assets/{chunk-2Q5K7J3B-D1c3AmPs.js → chunk-2Q5K7J3B-CLFF4J1f.js} +1 -1
  10. package/dist/public/assets/{chunk-3FUC2YCW-Bl68bUES.js → chunk-3FUC2YCW-QQVae1fu.js} +2 -2
  11. package/dist/public/assets/{chunk-5VM5RSS4-X_LQ24Gn.js → chunk-5VM5RSS4-B5UjIFDk.js} +1 -1
  12. package/dist/public/assets/{chunk-GTNCS2PH-CNEFfAzS.js → chunk-GTNCS2PH-DcdDMr9j.js} +1 -1
  13. package/dist/public/assets/{chunk-GWA4HPMP-C7DkZlNq.js → chunk-GWA4HPMP-CssmLYDR.js} +1 -1
  14. package/dist/public/assets/{chunk-JWPE2WC7-CMFCw_nU.js → chunk-JWPE2WC7-BizFpeWo.js} +1 -1
  15. package/dist/public/assets/{chunk-NETBCI7D-C5uY9Nj5.js → chunk-NETBCI7D-DWSxWS3y.js} +1 -1
  16. package/dist/public/assets/{chunk-WEXAMYUT-CyJYuumg.js → chunk-WEXAMYUT-BKN16NsC.js} +1 -1
  17. package/dist/public/assets/{chunk-XXDRQBXY-Hhi1Qat7.js → chunk-XXDRQBXY-By-Uw-Aj.js} +1 -1
  18. package/dist/public/assets/{classDiagram-v2-NBCMYWYE-CUVpgYkQ.js → classDiagram-v2-NBCMYWYE-DqoFIYb9.js} +1 -1
  19. package/dist/public/assets/{cose-bilkent-JH36ORCC-CvKLCNyf.js → cose-bilkent-JH36ORCC-HmH4VsKR.js} +1 -1
  20. package/dist/public/assets/{cynefin-OW5HDTMX-BWav6_j0.js → cynefin-OW5HDTMX-DYD9YRjp.js} +1 -1
  21. package/dist/public/assets/{cynefinDiagram-VND7K2PF-N-o2dJ6N.js → cynefinDiagram-VND7K2PF-C9RjJJ0d.js} +1 -1
  22. package/dist/public/assets/{dagre-6A5THRUB-MD8RkRhV.js → dagre-6A5THRUB-COdxco8b.js} +1 -1
  23. package/dist/public/assets/{diagram-22UHCM2B-GMOFN-eG.js → diagram-22UHCM2B-BV5ehlp3.js} +1 -1
  24. package/dist/public/assets/{diagram-3UASUU5V-Dpldk42J.js → diagram-3UASUU5V-CEc6OJqR.js} +1 -1
  25. package/dist/public/assets/{diagram-ATOU4E4O-C8iQ5gco.js → diagram-ATOU4E4O-DOhyTrVD.js} +1 -1
  26. package/dist/public/assets/{diagram-CDSNMT55-B9uLzKhV.js → diagram-CDSNMT55-C8NBEqvd.js} +1 -1
  27. package/dist/public/assets/{diagram-MLGK6HIB-DErxpCbQ.js → diagram-MLGK6HIB-CWaQF3Ld.js} +1 -1
  28. package/dist/public/assets/{diagram-MPIPVDR6-D2DFt4wW.js → diagram-MPIPVDR6-D6hkQ7gd.js} +1 -1
  29. package/dist/public/assets/{ebnfDiagram-ZINNZB2B-CXdiw8VF.js → ebnfDiagram-ZINNZB2B-sLsnAmFD.js} +1 -1
  30. package/dist/public/assets/{elk-276RUBZZ-B8THaPhk.js → elk-276RUBZZ-DVtwkYol.js} +1 -1
  31. package/dist/public/assets/{erDiagram-OPXOYQCR-CB66OCnA.js → erDiagram-OPXOYQCR-xdeqkZd4.js} +1 -1
  32. package/dist/public/assets/{flowDiagram-KWPJA3E3-C9ZJri7o.js → flowDiagram-KWPJA3E3-CZl1CKuP.js} +1 -1
  33. package/dist/public/assets/{ganttDiagram-FUAMR5RP-CbCpJoQp.js → ganttDiagram-FUAMR5RP-DnkdTY3-.js} +1 -1
  34. package/dist/public/assets/{gitGraphDiagram-X574FWY7-B54Zfqy2.js → gitGraphDiagram-X574FWY7-DQNG42Tn.js} +1 -1
  35. package/dist/public/assets/index-BOQmZzyT.js +363 -0
  36. package/dist/public/assets/index-DPZqWW1u.css +32 -0
  37. package/dist/public/assets/{infoDiagram-VRGFBTTK-Cm8cRNo1.js → infoDiagram-VRGFBTTK-BeYpU1R5.js} +1 -1
  38. package/dist/public/assets/{ishikawaDiagram-OU5B5YK6-DDlIGelT.js → ishikawaDiagram-OU5B5YK6-mEgC8PlA.js} +1 -1
  39. package/dist/public/assets/{journeyDiagram-ZHPQQLJL-Bi3Itxu4.js → journeyDiagram-ZHPQQLJL-C5mSuQmo.js} +1 -1
  40. package/dist/public/assets/{kanban-definition-PNTS6WVX-DAMbX7MM.js → kanban-definition-PNTS6WVX-A1k2Vl-J.js} +1 -1
  41. package/dist/public/assets/{linear-MAhVrjlB.js → linear-DSYqxhOx.js} +1 -1
  42. package/dist/public/assets/{mermaid.core-DuEETMGj.js → mermaid.core-Bl8C4fSx.js} +4 -4
  43. package/dist/public/assets/{mindmap-definition-NLK3R4M7-BYstGJ4o.js → mindmap-definition-NLK3R4M7-F2PHGXa5.js} +1 -1
  44. package/dist/public/assets/{pegDiagram-GJSIUBJH-DaHHVjAd.js → pegDiagram-GJSIUBJH-lS3dgdwe.js} +1 -1
  45. package/dist/public/assets/{pieDiagram-5QR66LMP-B1VuPvcW.js → pieDiagram-5QR66LMP-DjyOARJR.js} +1 -1
  46. package/dist/public/assets/{quadrantDiagram-O4NWA36T-Cv0WKpnS.js → quadrantDiagram-O4NWA36T-Drm_KOLr.js} +1 -1
  47. package/dist/public/assets/{railroadDiagram-XR7U4H2S-B1bku2zK.js → railroadDiagram-XR7U4H2S-D7snifLU.js} +1 -1
  48. package/dist/public/assets/{requirementDiagram-PLB6GJNP-C73LGTz4.js → requirementDiagram-PLB6GJNP-C-7BjXZm.js} +1 -1
  49. package/dist/public/assets/{sankeyDiagram-IPEJSGJF-DsGIjgz6.js → sankeyDiagram-IPEJSGJF-DUE0QpYN.js} +1 -1
  50. package/dist/public/assets/{sequenceDiagram-PO4LG4MO-CUYiZBzY.js → sequenceDiagram-PO4LG4MO--fgXhSUK.js} +1 -1
  51. package/dist/public/assets/{sizeCapture-INFHLROL-BZ66sANG.js → sizeCapture-INFHLROL-J042wM-E.js} +1 -1
  52. package/dist/public/assets/{stateDiagram-v2-GCMORJYK-1ETj6tOy.js → stateDiagram-v2-GCMORJYK-DBEgADBU.js} +1 -1
  53. package/dist/public/assets/{swimlanes-2SLR337P-Ct6oNBoE.js → swimlanes-2SLR337P-n1MMMryz.js} +1 -1
  54. package/dist/public/assets/swimlanesDiagram-TC7HE7FX-BxouFZW9.js +8 -0
  55. package/dist/public/assets/{timeline-definition-EJHVYXUP-D0vSfYcC.js → timeline-definition-EJHVYXUP-Ch4oAOvy.js} +1 -1
  56. package/dist/public/assets/{usecaseDiagram-POWQR4AR-Dy0YO-j7.js → usecaseDiagram-POWQR4AR-DFs_6tJM.js} +1 -1
  57. package/dist/public/assets/{vennDiagram-UO4OBE2U-DkrJdx67.js → vennDiagram-UO4OBE2U-cJ5Rpp6V.js} +1 -1
  58. package/dist/public/assets/{wardleyDiagram-VNRHLVJA-CPuHAJIV.js → wardleyDiagram-VNRHLVJA-CFe6IjhY.js} +1 -1
  59. package/dist/public/assets/{xychartDiagram-PMCCYNJV-BwwGXvBZ.js → xychartDiagram-PMCCYNJV-DVqkUPUP.js} +1 -1
  60. package/dist/public/index.html +2 -2
  61. package/dist/src/agent-runtime/conversation.js +20 -1
  62. package/dist/src/agent-runtime/conversationValidation.js +8 -1
  63. package/dist/src/agent-runtime/runtime.js +105 -0
  64. package/dist/src/agent-runtime/scheduledMessages.js +549 -0
  65. package/dist/src/agents/codexConversation.js +70 -58
  66. package/dist/src/agents/codexUsageLimitRecovery.js +97 -0
  67. package/dist/src/cli/authCmd.js +1 -1
  68. package/dist/src/cli/i18n/en.js +1 -0
  69. package/dist/src/cli/i18n/zh.js +1 -0
  70. package/dist/src/codexTranscriptParse.js +3 -0
  71. package/dist/src/deviceAuth/service.js +2 -2
  72. package/dist/src/routes/agents.js +46 -0
  73. package/dist/src/tmux/format.js +19 -3
  74. package/dist/src/workspace/tmuxAdapter.js +30 -0
  75. package/package.json +4 -4
  76. package/dist/public/assets/channel-Cci2XuJS.js +0 -1
  77. package/dist/public/assets/index-Dp0a9bVz.css +0 -32
  78. package/dist/public/assets/index-bFpfaPZi.js +0 -363
  79. package/dist/public/assets/swimlanesDiagram-TC7HE7FX-7GrZvyr4.js +0 -8
@@ -1,3 +1,4 @@
1
+ import { codexUsageLimitRecovery } from './codexUsageLimitRecovery.js';
1
2
  import { createHash } from 'node:crypto';
2
3
  import { homedir } from 'node:os';
3
4
  import { resolve } from 'node:path';
@@ -361,7 +362,7 @@ function projectDurableMessage(message, sessionId, suppressedCompactorItems) {
361
362
  }
362
363
  if (message.type === 'notice' && typeof message.text === 'string') {
363
364
  return [{ ...itemBase(message, sessionId), kind: 'notice', level: message.noticeLevel || 'info',
364
- code: 'provider_error', message: clipConversationText(message.text).text }];
365
+ code: 'provider_error', message: clipConversationText(message.text).text, ...(message.recovery ? { recovery: message.recovery } : {}) }];
365
366
  }
366
367
  if (message.type === 'thinking' && typeof message.text === 'string') {
367
368
  // Codex rollout stores the provider's public reasoning summary, not hidden reasoning content.
@@ -588,11 +589,24 @@ export function createCodexConversationAdapter({ app, sessionsRoot = sessionsDir
588
589
  durableCheckpoints.delete(oldest);
589
590
  }
590
591
  }
592
+ async function guardDurableRead(sessionId, read) {
593
+ try {
594
+ return await read();
595
+ }
596
+ catch (error) {
597
+ // The reader may already have consumed a change hint. Keep the last-good snapshot/floor,
598
+ // but do not incrementally reuse it on retry, even if another append supplies a later hint.
599
+ const known = durableCheckpoints.get(sessionId);
600
+ if (known)
601
+ known.deltaHintInvalid = true;
602
+ throw error;
603
+ }
604
+ }
591
605
  function snapshotFromMessages(session, parsed, file, version, readerGeneration, changedFrom, checkpoint, suppressedCompactorItems) {
592
606
  const suppressionKey = suppressionKeyOf(suppressedCompactorItems);
593
607
  const sameReader = readerGeneration === undefined || checkpoint?.readerGeneration === undefined
594
608
  || checkpoint.readerGeneration === readerGeneration;
595
- const reusable = checkpoint?.file === file && sameReader && changedFrom !== null
609
+ const reusable = checkpoint?.file === file && !checkpoint.deltaHintInvalid && sameReader && changedFrom !== null
596
610
  && checkpoint.suppressionKey === suppressionKey
597
611
  && changedFrom >= 0 && changedFrom <= checkpoint.messageCount
598
612
  && changedFrom <= parsed.length;
@@ -645,38 +659,33 @@ export function createCodexConversationAdapter({ app, sessionsRoot = sessionsDir
645
659
  };
646
660
  }
647
661
  async function readDurableSnapshot(session, suppressionProvider) {
648
- const file = await findRollout(sessionsRoot, session.sessionId);
649
- const read = file && reader.readSnapshot
650
- ? await reader.readSnapshot(file, createCodexTranscriptParser)
651
- : {
652
- messages: file ? await reader.read(file, createCodexTranscriptParser) : [],
653
- version: undefined,
654
- changedFrom: 0,
655
- generation: undefined,
656
- };
657
- const suppressedCompactorItems = suppressionProvider
658
- ? await suppressionProvider()
659
- : suppressedCompactorItemsBySession.get(session.sessionId) ?? new Set();
660
- const suppressionKey = suppressionKeyOf(suppressedCompactorItems);
661
- const known = durableCheckpoints.get(session.sessionId);
662
- if (known && known.file === file && known.suppressionKey === suppressionKey
663
- && read.version !== undefined && known.version === read.version) {
664
- rememberCheckpoint(session.sessionId, known);
665
- return known.snapshot;
666
- }
667
- const sameReader = read.generation === undefined || known?.readerGeneration === undefined
668
- || known.readerGeneration === read.generation;
669
- if (known && known.file === file && sameReader && read.changedFrom === null) {
670
- if (read.version === undefined)
671
- delete known.version;
672
- else
673
- known.version = read.version;
674
- rememberCheckpoint(session.sessionId, known);
675
- return known.snapshot;
676
- }
677
- const checkpoint = snapshotFromMessages(session, read.messages, file, read.version, read.generation, read.changedFrom, known, suppressedCompactorItems);
678
- rememberCheckpoint(session.sessionId, checkpoint);
679
- return checkpoint.snapshot;
662
+ return guardDurableRead(session.sessionId, async () => {
663
+ const file = await findRollout(sessionsRoot, session.sessionId);
664
+ const read = file && reader.readSnapshot
665
+ ? await reader.readSnapshot(file, createCodexTranscriptParser)
666
+ : {
667
+ messages: file ? await reader.read(file, createCodexTranscriptParser) : [],
668
+ version: undefined,
669
+ changedFrom: 0,
670
+ generation: undefined,
671
+ };
672
+ const suppressedCompactorItems = suppressionProvider
673
+ ? await suppressionProvider()
674
+ : suppressedCompactorItemsBySession.get(session.sessionId) ?? new Set();
675
+ const suppressionKey = suppressionKeyOf(suppressedCompactorItems);
676
+ const known = durableCheckpoints.get(session.sessionId);
677
+ if (known && !known.deltaHintInvalid && known.file === file && known.suppressionKey === suppressionKey
678
+ && read.version !== undefined && known.version === read.version) {
679
+ rememberCheckpoint(session.sessionId, known);
680
+ return known.snapshot;
681
+ }
682
+ // changedFrom is a destructive parser hint, not proof that this projection is current.
683
+ // A read can consume it before a later provider query fails. Only an identical committed
684
+ // version (above) permits reuse; a changed/unknown version with no hint must rebuild.
685
+ const checkpoint = snapshotFromMessages(session, read.messages, file, read.version, read.generation, read.changedFrom, known, suppressedCompactorItems);
686
+ rememberCheckpoint(session.sessionId, checkpoint);
687
+ return checkpoint.snapshot;
688
+ });
680
689
  }
681
690
  async function captureDurableCutoff(sessionId) {
682
691
  const file = await findRollout(sessionsRoot, sessionId);
@@ -688,30 +697,32 @@ export function createCodexConversationAdapter({ app, sessionsRoot = sessionsDir
688
697
  : { file: null, endExclusive: 0 };
689
698
  }
690
699
  async function readDurablePrefix(session, cutoff, suppressionProvider) {
691
- const known = durableCheckpoints.get(session.sessionId);
692
- const working = known ? cloneCheckpoint(known) : undefined;
693
- const read = cutoff.file && reader.readPrefixSnapshot
694
- ? await reader.readPrefixSnapshot(cutoff.file, cutoff.endExclusive, createCodexTranscriptParser)
695
- : {
696
- messages: cutoff.file
697
- ? await readPrefix(cutoff.file, cutoff.endExclusive, createCodexTranscriptParser) : [],
698
- version: undefined,
699
- changedFrom: 0,
700
- generation: undefined,
700
+ return guardDurableRead(session.sessionId, async () => {
701
+ const known = durableCheckpoints.get(session.sessionId);
702
+ const working = known ? cloneCheckpoint(known) : undefined;
703
+ const read = cutoff.file && reader.readPrefixSnapshot
704
+ ? await reader.readPrefixSnapshot(cutoff.file, cutoff.endExclusive, createCodexTranscriptParser)
705
+ : {
706
+ messages: cutoff.file
707
+ ? await readPrefix(cutoff.file, cutoff.endExclusive, createCodexTranscriptParser) : [],
708
+ version: undefined,
709
+ changedFrom: 0,
710
+ generation: undefined,
711
+ };
712
+ const suppressedCompactorItems = suppressionProvider
713
+ ? await suppressionProvider()
714
+ : suppressedCompactorItemsBySession.get(session.sessionId) ?? new Set();
715
+ const suppressionKey = suppressionKeyOf(suppressedCompactorItems);
716
+ const checkpoint = working && !working.deltaHintInvalid && working.file === cutoff.file
717
+ && working.suppressionKey === suppressionKey
718
+ && read.version !== undefined && working.version === read.version
719
+ ? working
720
+ : snapshotFromMessages(session, read.messages, cutoff.file, read.version, read.generation, read.changedFrom, working, suppressedCompactorItems);
721
+ return {
722
+ checkpoint,
723
+ snapshot: { ...checkpoint.snapshot, items: [...checkpoint.snapshot.items] },
701
724
  };
702
- const suppressedCompactorItems = suppressionProvider
703
- ? await suppressionProvider()
704
- : suppressedCompactorItemsBySession.get(session.sessionId) ?? new Set();
705
- const suppressionKey = suppressionKeyOf(suppressedCompactorItems);
706
- const checkpoint = working && working.file === cutoff.file
707
- && working.suppressionKey === suppressionKey
708
- && read.version !== undefined && working.version === read.version
709
- ? working
710
- : snapshotFromMessages(session, read.messages, cutoff.file, read.version, read.generation, read.changedFrom, working, suppressedCompactorItems);
711
- return {
712
- checkpoint,
713
- snapshot: { ...checkpoint.snapshot, items: [...checkpoint.snapshot.items] },
714
- };
725
+ });
715
726
  }
716
727
  async function readPage(session, request) {
717
728
  const opening = request.beforeSourceCursor === undefined
@@ -965,8 +976,9 @@ export function createCodexConversationAdapter({ app, sessionsRoot = sessionsDir
965
976
  if (event.type === 'cursorReset' || event.type === 'disconnected' || event.type === 'error') {
966
977
  if (event.type === 'error' && event.message.trim()) {
967
978
  const provisionalId = `codex-stream-error:${sessionId}:${live.sourceSequence + 1}`;
979
+ const recovery = codexUsageLimitRecovery(event, typeof event.timestamp === 'string' ? Date.parse(event.timestamp) : undefined);
968
980
  const draft = {
969
- kind: 'notice', level: 'warning', code: 'provider_error', message: event.message.trim(),
981
+ kind: 'notice', level: 'warning', code: 'provider_error', message: event.message.trim(), ...(recovery ? { recovery } : {}),
970
982
  };
971
983
  await emit({ type: 'item.opened', provisionalId, draft });
972
984
  await emit({ type: 'item.settled', provisionalId,
@@ -0,0 +1,97 @@
1
+ const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
2
+ const validTime = (value) => Number.isSafeInteger(value) && value > 0 && value <= 8_640_000_000_000_000;
3
+ function absoluteTime(value) {
4
+ if (typeof value === 'number') {
5
+ const at = value < 1e12 ? value * 1000 : value;
6
+ return validTime(at) ? at : undefined;
7
+ }
8
+ if (typeof value !== 'string')
9
+ return undefined;
10
+ const iso = value.trim().match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})$/i);
11
+ if (!iso)
12
+ return undefined;
13
+ const year = Number(iso[1]);
14
+ const month = Number(iso[2]);
15
+ const day = Number(iso[3]);
16
+ if (month < 1 || month > 12 || day < 1 || day > new Date(Date.UTC(year, month, 0)).getUTCDate()
17
+ || Number(iso[4]) > 23 || Number(iso[5]) > 59 || Number(iso[6] ?? 0) > 59)
18
+ return undefined;
19
+ const at = Date.parse(value);
20
+ return validTime(at) ? at : undefined;
21
+ }
22
+ /** Codex local text follows the server timezone by the user's explicit scheduling policy. */
23
+ function textResetTime(message, occurredAt) {
24
+ const source = message.replace(/\s+/g, ' ').trim();
25
+ // Official format_retry_timestamp: full date outside today, clock only on the event's local day.
26
+ // https://github.com/openai/codex/blob/c419fd01a70dd1d05356da443ac44328bda2e6f4/codex-rs/protocol/src/error.rs
27
+ const full = source.match(/\b(Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(\d{4})\s+(\d{1,2}):(\d{2})(?:\s*(AM|PM))?([^\r\n]*)/i);
28
+ const short = full ? null : source.match(/\btry\s+again\s+at\s+(\d{1,2}):(\d{2})(?:\s*(AM|PM))?([^\r\n]*)/i);
29
+ if (!full && (!short || occurredAt === undefined || !validTime(occurredAt)))
30
+ return undefined;
31
+ const clock = full ? full.slice(4) : short.slice(1);
32
+ const hour = Number(clock[0]);
33
+ const minute = Number(clock[1]);
34
+ const meridiem = clock[2]?.toUpperCase();
35
+ if (minute > 59 || (meridiem ? hour < 1 || hour > 12 : hour > 23))
36
+ return undefined;
37
+ const hours = meridiem ? hour % 12 + (meridiem === 'PM' ? 12 : 0) : hour;
38
+ // Inspect the entire suffix before sentence punctuation. Unknown/malformed explicit zones or
39
+ // AM/PM must fail closed, rather than being reinterpreted by a second bare-clock matcher.
40
+ const zone = (clock[3] ?? '').split(/[.!?;]/, 1)[0].trim();
41
+ if (zone && !/^(?:(?:UTC|GMT)?[+-]\d{2}:?\d{2}|Z|UTC|GMT)$/i.test(zone))
42
+ return undefined;
43
+ if (!full && zone)
44
+ return undefined; // A dated, explicit-offset format is required for this path.
45
+ const event = new Date(occurredAt ?? 0);
46
+ const year = full ? Number(full[3]) : event.getFullYear();
47
+ const month = full ? ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'].indexOf(full[1].slice(0, 3).toLowerCase()) + 1 : event.getMonth() + 1;
48
+ const day = full ? Number(full[2]) : event.getDate();
49
+ if (zone) {
50
+ const offset = /^(?:Z|UTC|GMT)$/i.test(zone) ? 'Z' : zone.replace(/^(?:UTC|GMT)/i, '');
51
+ return absoluteTime(`${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}T${String(hours).padStart(2, '0')}:${String(minute).padStart(2, '0')}:00${offset}`);
52
+ }
53
+ const local = new Date(year, month - 1, day, hours, minute, 0, 0);
54
+ // Date normalizes invalid dates and spring-forward gaps; reject changed components.
55
+ if (local.getFullYear() !== year || local.getMonth() !== month - 1 || local.getDate() !== day
56
+ || local.getHours() !== hours || local.getMinutes() !== minute)
57
+ return undefined;
58
+ const at = local.getTime();
59
+ // Date chooses the earlier instant in a fold. Check the actual offset change, including
60
+ // half-hour transitions, and reject if the later instant has the same local components.
61
+ const tomorrow = new Date(year, month - 1, day + 1, hours, minute, 0, 0);
62
+ const offsetChange = tomorrow.getTimezoneOffset() - local.getTimezoneOffset();
63
+ if (offsetChange > 0) {
64
+ const later = new Date(at + offsetChange * 60000);
65
+ if (later.getFullYear() === year && later.getMonth() === month - 1 && later.getDate() === day
66
+ && later.getHours() === hours && later.getMinutes() === minute)
67
+ return undefined;
68
+ }
69
+ return validTime(at) ? at : undefined;
70
+ }
71
+ /** Only called for native provider errors, never user/assistant content. */
72
+ export function codexUsageLimitRecovery(value, occurredAt) {
73
+ const error = record(value);
74
+ const message = typeof error.message === 'string' ? error.message : '';
75
+ const info = error.codex_error_info ?? error.code ?? error.type;
76
+ const code = typeof info === 'string' ? info : Object.keys(record(info)).join(' ');
77
+ if (!/usage[_\s-]*limit[_\s-]*exceeded|rate[_\s-]*limit[_\s-]*exceeded/i.test(code)
78
+ && !/\b(?:usage[\s_-]+limit|rate[\s_-]+limit|too many requests)\b/i.test(message))
79
+ return undefined;
80
+ let retryAt = absoluteTime(error.resets_at);
81
+ if (retryAt === undefined) {
82
+ const iso = message.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})/i)?.[0];
83
+ retryAt = absoluteTime(iso);
84
+ }
85
+ if (retryAt === undefined)
86
+ retryAt = textResetTime(message, occurredAt);
87
+ if (retryAt === undefined && occurredAt !== undefined && validTime(occurredAt)) {
88
+ const relative = message.match(/\btry again in\s+(\d+(?:\.\d+)?)\s*(seconds?|minutes?|hours?)\b/i);
89
+ if (relative) {
90
+ const delay = Number(relative[1]) * (/^hour/i.test(relative[2]) ? 3600000 : /^minute/i.test(relative[2]) ? 60000 : 1000);
91
+ const at = occurredAt + delay;
92
+ if (validTime(at))
93
+ retryAt = at;
94
+ }
95
+ }
96
+ return { kind: 'usage_limit', ...(retryAt === undefined ? {} : { retryAt }) };
97
+ }
@@ -78,7 +78,7 @@ const controlErrorCopy = {
78
78
  CODE_INVALID: 'auth.error.codeInvalid', CLAIM_RATE_LIMIT: 'auth.error.rateLimit',
79
79
  PAIRING_NOT_FOUND: 'auth.error.pairingGone', PAIRING_INACTIVE: 'auth.error.pairingGone',
80
80
  DEVICE_NOT_FOUND: 'auth.error.deviceNotFound', DEVICE_INACTIVE: 'auth.error.deviceInactive',
81
- DEVICE_CONFLICT: 'auth.error.conflict', INVALID_EDIT: 'auth.error.invalidEdit',
81
+ DEVICE_NAME_TAKEN: 'auth.error.nameTaken', DEVICE_CONFLICT: 'auth.error.conflict', INVALID_EDIT: 'auth.error.invalidEdit',
82
82
  INVALID_VERSION: 'auth.error.invalidVersion', PAIRING_CAPACITY: 'auth.error.pairingCapacity',
83
83
  TOKEN_REQUIRED: 'auth.error.tokenRequired', DEVICE_REQUIRED: 'auth.error.deviceRequired',
84
84
  DEVICE_EXPIRY_CLI_ONLY: 'auth.error.expiryCliOnly',
@@ -32,6 +32,7 @@ export default {
32
32
  'auth.error.pairingGone': 'This authorization request no longer exists or has expired. Request a new code in the browser.',
33
33
  'auth.error.deviceNotFound': 'Device not found. Run handmux auth device list to check the device ID.',
34
34
  'auth.error.deviceInactive': 'This device has expired or been unbound. Authorize it again.',
35
+ 'auth.error.nameTaken': 'An active device already uses this name. Choose another name.',
35
36
  'auth.error.conflict': 'The device was changed by another operation. List devices again, then retry.',
36
37
  'auth.error.invalidEdit': 'Provide at least --name or --expire.',
37
38
  'auth.error.invalidVersion': 'The device was updated. List devices again, then retry.',
@@ -31,6 +31,7 @@ export default {
31
31
  'auth.error.pairingGone': '这次授权申请已不存在或已过期,请在浏览器重新申请验证码。',
32
32
  'auth.error.deviceNotFound': '找不到这个设备,请先运行 handmux auth device list 查看设备 ID。',
33
33
  'auth.error.deviceInactive': '设备已过期或解除绑定,请重新授权。',
34
+ 'auth.error.nameTaken': '已有有效设备使用此名称,请换一个名称。',
34
35
  'auth.error.conflict': '设备信息已被其他操作修改,请重新查看设备后再试。',
35
36
  'auth.error.invalidEdit': '请至少提供 --name 或 --expire。',
36
37
  'auth.error.invalidVersion': '设备信息已更新,请重新查看设备后再试。',
@@ -1,3 +1,4 @@
1
+ import { codexUsageLimitRecovery } from './agents/codexUsageLimitRecovery.js';
1
2
  import { codexPlanSnapshot } from './codexPlan.js';
2
3
  import { codexGoalMessageId, codexItemMessageId } from './codexMessageIdentity.js';
3
4
  const isRecord = (value) => (value !== null && typeof value === 'object' && !Array.isArray(value));
@@ -629,8 +630,10 @@ export function createCodexTranscriptParser() {
629
630
  const payloadError = asRecord(payload.error);
630
631
  if (payload.type === 'task_complete' && typeof payloadError.message === 'string'
631
632
  && payloadError.message.trim()) {
633
+ const recovery = codexUsageLimitRecovery(payloadError, ts ? Date.parse(ts) : undefined);
632
634
  messages.push({
633
635
  i, type: 'notice', noticeLevel: 'warning', text: payloadError.message.trim(), ts,
636
+ ...(recovery ? { recovery } : {}),
634
637
  ...(typeof payload.turn_id === 'string' && payload.turn_id ? { turnId: payload.turn_id } : {}),
635
638
  });
636
639
  }
@@ -369,7 +369,7 @@ export class DeviceAuthService {
369
369
  if (values.name === undefined && values.expire === undefined)
370
370
  throw new DeviceAuthError('INVALID_EDIT', 'Provide --name or --expire');
371
371
  const name = values.name === undefined ? undefined : validateName(values.name);
372
- if (name !== undefined && this.db.prepare('SELECT id FROM auth_devices WHERE name=? AND id<>? AND revoked_at IS NULL').get(name, id))
372
+ if (name !== undefined && this.db.prepare('SELECT id FROM auth_devices WHERE name=? AND id<>? AND revoked_at IS NULL AND (expires_at IS NULL OR expires_at>?)').get(name, id, this.now()))
373
373
  throw new DeviceAuthError('DEVICE_NAME_TAKEN', 'Device name is already in use', 409);
374
374
  const duration = values.expire === undefined ? undefined : parseExpire(values.expire);
375
375
  return this.transaction(() => {
@@ -554,7 +554,7 @@ export class DeviceAuthService {
554
554
  this.requireMode();
555
555
  const name = validateName(values.name);
556
556
  const duration = parseExpire(values.expire);
557
- if (this.db.prepare('SELECT id FROM auth_devices WHERE name=? AND revoked_at IS NULL').get(name))
557
+ if (this.db.prepare('SELECT id FROM auth_devices WHERE name=? AND revoked_at IS NULL AND (expires_at IS NULL OR expires_at>?)').get(name, this.now()))
558
558
  throw new DeviceAuthError('DEVICE_NAME_TAKEN', 'Device name is already in use', 409);
559
559
  const p = [...this.pending.values()].find(p => p.id === id && p.owner === owner);
560
560
  if (!p)
@@ -1,3 +1,4 @@
1
+ import { ScheduledError } from '../agent-runtime/scheduledMessages.js';
1
2
  import express from 'express';
2
3
  import { ConversationContractError } from '../agent-runtime/conversation.js';
3
4
  import { ConversationActivationError } from '../agent-runtime/conversationActivation.js';
@@ -429,6 +430,51 @@ export function agentRoutes({ runtime }) {
429
430
  return next(error);
430
431
  }
431
432
  });
433
+ router.post('/agents/scheduled-messages', async (req, res, next) => {
434
+ try {
435
+ if (!runtime.scheduledMessages || !runtime.scheduledTarget)
436
+ return res.status(409).json({ error: 'Scheduled messages are unavailable', code: 'unsupported' });
437
+ const ref = run(req.body?.run);
438
+ const service = runtime.scheduledMessages;
439
+ const body = record(req.body) ?? {};
440
+ if (body.action === 'preview')
441
+ return res.json(service.preview(body.request, typeof body.timeZone === 'string' ? body.timeZone : undefined));
442
+ if (!text(body.tmuxSession, 256) || !text(body.paneId, 256))
443
+ throw new ScheduledError('Choose a tmux session and pane');
444
+ const scope = { tmuxSession: body.tmuxSession, paneId: body.paneId };
445
+ if (body.action === 'snapshot')
446
+ return res.json(service.snapshot(scope));
447
+ const target = body.action === 'create' && ref ? await runtime.scheduledTarget(ref) : null;
448
+ if (body.action === 'create' && (!target || target.tmuxSession !== scope.tmuxSession || target.paneId !== scope.paneId))
449
+ throw new ScheduledError('Choose the current pane and Agent session', 'conflict');
450
+ switch (body.action) {
451
+ case 'create': return res.json(service.create(target, body.request));
452
+ case 'trigger':
453
+ case 'terminate':
454
+ case 'update':
455
+ case 'delete':
456
+ case 'exception': {
457
+ if (!text(body.id, 256) || !Number.isSafeInteger(body.revision))
458
+ throw new ScheduledError('Invalid scheduled message revision');
459
+ if (body.action === 'terminate')
460
+ return res.json(service.terminate(scope, body.id, body.revision));
461
+ if (body.action === 'trigger')
462
+ return res.json(await service.trigger(scope, body.id, body.revision));
463
+ if (body.action === 'update')
464
+ return res.json(service.update(scope, body.id, body.revision, body.request));
465
+ if (body.action === 'delete')
466
+ return res.json(service.remove(scope, body.id, body.revision));
467
+ return res.json(service.resolveException(scope, body.id, body.revision, body.request));
468
+ }
469
+ default: throw new ScheduledError('Invalid scheduled message action');
470
+ }
471
+ }
472
+ catch (error) {
473
+ if (error instanceof ScheduledError)
474
+ return res.status(error.code === 'invalid_request' ? 400 : error.code === 'not_found' ? 404 : 409).json({ error: error.message, code: error.code });
475
+ return next(error);
476
+ }
477
+ });
432
478
  router.post('/agents/conversation/discover', async (req, res, next) => {
433
479
  try {
434
480
  if (!runtime.conversation)
@@ -1,5 +1,5 @@
1
1
  const Q_ESCAPED = new Set([
2
- '|', '&', ';', '<', '>', '(', ')', '$', '`', '\\', '"', "'", '*', '?', '[', '#', ' ', '=', '%',
2
+ '|', '&', ';', '<', '>', '(', ')', '{', '}', '$', '`', '\\', '"', "'", '*', '?', '[', '#', ' ', '=', '%', '\n', '\t',
3
3
  ]);
4
4
  export function tmuxFormat(fields) {
5
5
  if (!Array.isArray(fields) || fields.length === 0)
@@ -42,6 +42,22 @@ export function parseTmuxRows(output, columns, label = 'tmux') {
42
42
  const value = String(output ?? '');
43
43
  if (value === '' || value === '\n' || value === '\r\n')
44
44
  return [];
45
- return value.replace(/\r?\n$/, '').split(/\r?\n/)
46
- .map((line) => parseTmuxFields(line, columns, label));
45
+ const rows = [];
46
+ let start = 0;
47
+ for (let i = 0; i < value.length; i++) {
48
+ // tmux 3.8 q-escapes literal LF. Skip complete escape pairs so that
49
+ // an escaped backslash before LF still leaves a record boundary.
50
+ if (value.charAt(i) === '\\') {
51
+ i++;
52
+ continue;
53
+ }
54
+ if (value.charAt(i) !== '\n')
55
+ continue;
56
+ const end = value.charAt(i - 1) === '\r' ? i - 1 : i;
57
+ rows.push(parseTmuxFields(value.slice(start, end), columns, label));
58
+ start = i + 1;
59
+ }
60
+ if (start < value.length)
61
+ rows.push(parseTmuxFields(value.slice(start), columns, label));
62
+ return rows;
47
63
  }
@@ -89,9 +89,39 @@ function ephemeralLogicalId(option, runtimeId) {
89
89
  function requireCreatedRuntime(value, prefix, label) {
90
90
  return runtime(value, prefix, label);
91
91
  }
92
+ function isLayoutInteger(value, minimum = 0) {
93
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= minimum;
94
+ }
95
+ function isJsonLayoutCell(value) {
96
+ const cell = recordOf(value);
97
+ if (!cell || !isLayoutInteger(cell.w, 1) || !isLayoutInteger(cell.h, 1)
98
+ || !isLayoutInteger(cell.x, -Number.MAX_SAFE_INTEGER)
99
+ || !isLayoutInteger(cell.y, -Number.MAX_SAFE_INTEGER))
100
+ return false;
101
+ if (cell.t === 'p') {
102
+ return cell.c === undefined && isLayoutInteger(cell.i)
103
+ && (cell.a === undefined || typeof cell.a === 'boolean')
104
+ && (cell.l === undefined || isLayoutInteger(cell.l))
105
+ && (cell.z === undefined || isLayoutInteger(cell.z))
106
+ && (cell.I === undefined || (typeof cell.I === 'string' && /^%\d+$/.test(cell.I)));
107
+ }
108
+ return (cell.t === 'h' || cell.t === 'v')
109
+ && Array.isArray(cell.c) && cell.c.length >= 2 && cell.c.every(isJsonLayoutCell);
110
+ }
92
111
  function isTmuxLayout(value) {
93
112
  if (typeof value !== 'string' || value.length === 0 || value.length > 8192)
94
113
  return false;
114
+ if (value.startsWith('{')) {
115
+ // tmux 3.8 emits V2 JSON, including floating pane metadata. Keep it intact;
116
+ // tmux owns full layout semantics and still accepts the legacy V1 format.
117
+ try {
118
+ const layout = recordOf(JSON.parse(value));
119
+ return layout?.V === 2 && isJsonLayoutCell(layout.L);
120
+ }
121
+ catch {
122
+ return false;
123
+ }
124
+ }
95
125
  if (!/^[0-9a-f]{4},\d+x\d+,\d+,\d+(?:,\d+|[\[{])/i.test(value))
96
126
  return false;
97
127
  if (!/^[0-9a-fx,{}\[\]]+$/i.test(value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "handmux",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "A mobile vibe-coding cockpit — built on tmux: drive your live session, Claude Code / Codex — anything a terminal can run — from your phone.",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -75,13 +75,13 @@
75
75
  "vitest": "^2.0.0"
76
76
  },
77
77
  "whatsNew": [
78
+ {"version":"0.36.0","date":"2026-10-22","zh":"对话定时消息 · 限额后定时继续","en":"Scheduled messages · plan a retry after usage limits"},
79
+ {"version":"0.35.0","date":"2026-10-20","zh":"会话快捷操作 · 终端工具收放与位置记忆","en":"Session actions · collapsible terminal tools with saved positions"},
78
80
  {"version":"0.34.0","date":"2026-10-12","zh":"Codex 会话重启 · 分屏尺寸与代码复制","en":"Codex session restart, pane sizing, and code copying"},
79
81
  {"version":"0.33.4","date":"2026-10-10","zh":"修复终端实时连接、电脑键盘与 Codex 排队","en":"Fixes live terminal, desktop keys, and Codex queues"},
80
82
  {"version":"0.33.3","date":"2026-10-06","zh":"Claude 余额不足提示更明确","en":"Clearer Claude insufficient-balance errors"},
81
83
  {"version":"0.33.2","date":"2026-10-03","zh":"修复 v0.33.1 发布包的构建兼容问题","en":"Fixes build compatibility in the v0.33.1 package"},
82
84
  {"version":"0.33.1","date":"2026-10-02","zh":"对话复制和工作区操作更顺手","en":"Smoother conversation copying and workspace actions"},
83
- {"version":"0.33.0","date":"2026-09-30","zh":"终端路径高亮不再闪烁 · 服务更新提示更可靠","en":"Steady terminal paths · reliable service update prompts"},
84
- {"version":"0.32.1","date":"2026-09-28","zh":"抽屉与工作区切换更顺滑","en":"Smoother drawer and workspace switching"},
85
- {"version":"0.32.0","date":"2026-09-24","zh":"项目与会话导航全面升级 · 抽屉切换更顺滑","en":"Project and session navigation, rebuilt"}
85
+ {"version":"0.33.0","date":"2026-09-30","zh":"终端路径高亮不再闪烁 · 服务更新提示更可靠","en":"Steady terminal paths · reliable service update prompts"}
86
86
  ]
87
87
  }
@@ -1 +0,0 @@
1
- import{U as o,a as n}from"./mermaid.core-DuEETMGj.js";const t=(r,a)=>o.lang.round(n.parse(r)[a]);export{t as c};