tmux-ide 2.9.25 → 2.9.27

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 (67) hide show
  1. package/README.md +1 -1
  2. package/bin/cli.js +1577 -559
  3. package/package.json +3 -2
  4. package/packages/contracts/src/pane-stream.ts +28 -0
  5. package/packages/contracts/src/terminal-delivery.ts +122 -5
  6. package/packages/contracts/src/terminal-runtime-inventory.ts +61 -1
  7. package/packages/contracts/src/tmux-server-scope.ts +18 -0
  8. package/packages/core/src/index.ts +1 -0
  9. package/packages/core/src/terminal-delivery-binary.ts +8 -7
  10. package/packages/core/src/terminal-delivery.ts +174 -3
  11. package/packages/core/src/terminal-partial-history.ts +152 -0
  12. package/packages/core/src/terminal-replica.ts +70 -1
  13. package/packages/daemon/dist/command-center/owner-keep-alive.js +30 -0
  14. package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +42 -2
  15. package/packages/daemon/dist/command-center/server.js +3 -0
  16. package/packages/daemon/dist/command-center/tmux-server-attach.js +51 -0
  17. package/packages/daemon/dist/command-center/tmux-servers.js +95 -7
  18. package/packages/daemon/dist/doctor.js +4 -4
  19. package/packages/daemon/dist/lib/app-config.js +7 -0
  20. package/packages/daemon/dist/lib/node-requirement.js +20 -0
  21. package/packages/daemon/dist/lib/require-supported-node.js +8 -0
  22. package/packages/daemon/dist/lib/tmux-server-owner.js +4 -2
  23. package/packages/daemon/dist/lib/tmux-server-session-open.js +38 -12
  24. package/packages/daemon/dist/lib/workspace-promotion.js +4 -4
  25. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +2 -2
  26. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
  27. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
  28. package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +2 -2
  29. package/packages/daemon/dist/server/pane-stream-upgrade.js +39 -1
  30. package/packages/daemon/dist/terminal/mirror/session-channel.js +6 -1
  31. package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +1 -0
  32. package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +112 -22
  33. package/packages/daemon/dist/terminal/protocol/browser-icon.js +1 -1
  34. package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +26 -3
  35. package/packages/daemon/dist/terminal/session-runtime/registry.js +2 -0
  36. package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +571 -33
  37. package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +2 -0
  38. package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +51 -4
  39. package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +76 -2
  40. package/packages/daemon/dist/tui/mirror/theme.js +8 -1
  41. package/packages/daemon/src/command-center/attach-window-rule.cases.json +84 -0
  42. package/packages/daemon/src/command-center/owner-keep-alive.ts +38 -0
  43. package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +48 -1
  44. package/packages/daemon/src/command-center/server.ts +3 -0
  45. package/packages/daemon/src/command-center/tmux-server-attach.ts +75 -0
  46. package/packages/daemon/src/command-center/tmux-servers.ts +103 -6
  47. package/packages/daemon/src/doctor.ts +4 -4
  48. package/packages/daemon/src/lib/app-config.ts +15 -0
  49. package/packages/daemon/src/lib/node-requirement.ts +22 -0
  50. package/packages/daemon/src/lib/require-supported-node.ts +9 -0
  51. package/packages/daemon/src/lib/tmux-server-owner.ts +6 -3
  52. package/packages/daemon/src/lib/tmux-server-session-open.ts +53 -15
  53. package/packages/daemon/src/lib/workspace-promotion.ts +4 -4
  54. package/packages/daemon/src/server/pane-stream-upgrade.ts +41 -1
  55. package/packages/daemon/src/terminal/mirror/events.ts +2 -0
  56. package/packages/daemon/src/terminal/mirror/session-channel.ts +8 -1
  57. package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +3 -0
  58. package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +136 -20
  59. package/packages/daemon/src/terminal/protocol/browser-icon.ts +1 -1
  60. package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +32 -2
  61. package/packages/daemon/src/terminal/session-runtime/registry.ts +2 -0
  62. package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +696 -30
  63. package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +6 -0
  64. package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +2 -0
  65. package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +67 -3
  66. package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +82 -2
  67. package/packages/daemon/src/tui/mirror/theme.ts +13 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmux-ide",
3
- "version": "2.9.25",
3
+ "version": "2.9.27",
4
4
  "description": "The open-source workspace for coding agents: run Claude Code, Codex and other agents in tmux with live status",
5
5
  "type": "module",
6
6
  "bin": {
@@ -39,6 +39,7 @@
39
39
  "test:tmux-boundary": "node scripts/test-tmux-boundary.mjs",
40
40
  "build": "pnpm build:cli",
41
41
  "build:cli": "node scripts/build-cli.mjs",
42
+ "check:cli-bundle": "node scripts/check-cli-bundle.mjs",
42
43
  "build:macos-notifier": "node scripts/build-macos-notifier.mjs",
43
44
  "build:tui": "bun scripts/build-tui.mjs",
44
45
  "prepack": "pnpm build:cli",
@@ -123,7 +124,7 @@
123
124
  "developer-tools"
124
125
  ],
125
126
  "engines": {
126
- "node": ">=20"
127
+ "node": ">=24"
127
128
  },
128
129
  "repository": {
129
130
  "type": "git",
@@ -46,6 +46,7 @@ import {
46
46
  TerminalDeliveryEnvelopeSchemaZ,
47
47
  TerminalDeliveryFaultSchemaZ,
48
48
  TerminalDeliveryNackSchemaZ,
49
+ TerminalDeliveryHistoryRequestSchemaZ,
49
50
  TerminalDeliveryNegotiationResultSchemaZ,
50
51
  TerminalDeliveryOfferSchemaZ,
51
52
  TerminalDeliveryVisibilitySchemaZ,
@@ -136,6 +137,14 @@ export const PaneStreamLeaseRequestSchemaZ = z
136
137
  viewerMode: PaneStreamViewerModeSchemaZ,
137
138
  /** Explicit semantic-v2 content/authority mode. Omission retains raw v1. */
138
139
  terminalDelivery: TerminalDeliveryOfferSchemaZ.optional(),
140
+ /**
141
+ * #806: a stream for one window. `panes` must be exactly that window's
142
+ * panes (at most PANE_STREAM_MAX_PANES), so a session with more panes in
143
+ * all can be viewed window by window. Under capability 119/120 the stream
144
+ * follows that window's pane set in place; other windows never enter.
145
+ * Released daemons refuse the field: send it only to a daemon that has it.
146
+ */
147
+ semanticWindowId: TerminalAttachmentSemanticWindowIdSchemaZ.optional(),
139
148
  })
140
149
  .strict();
141
150
  export type PaneStreamLeaseRequest = z.infer<typeof PaneStreamLeaseRequestSchemaZ>;
@@ -257,6 +266,12 @@ export const PANE_STREAM_BROWSER_ICON_CAPABILITY_VERSION = 117;
257
266
  * Offered in place of 117 because the offer array has nine slots.
258
267
  */
259
268
  export const PANE_STREAM_READER_CAPABILITY_VERSION = 118;
269
+ /**
270
+ * #718: layout panes carry `browserKind` ("native" | "plain" | null), so a
271
+ * client can say why a plain terminal browser has no tmux-ide controls.
272
+ * Sent only to a client offering 123; older clients refuse the field.
273
+ */
274
+ export const PANE_STREAM_BROWSER_KIND_CAPABILITY_VERSION = 123;
260
275
  /**
261
276
  * The client keeps its stream when the session gains or loses a pane (#723):
262
277
  * the daemon sends a `topology` frame where it would otherwise close the
@@ -332,6 +347,13 @@ export const PaneStreamTerminalProjectionMaterializeFrameSchemaZ = z
332
347
  request: TerminalProjectionMaterializeSchemaZ,
333
348
  })
334
349
  .strict();
350
+ /** Capability 122: ask for older history rows of one pane. */
351
+ export const PaneStreamTerminalDeliveryHistoryRequestFrameSchemaZ = z
352
+ .object({
353
+ type: z.literal("terminal-delivery-history-request"),
354
+ request: TerminalDeliveryHistoryRequestSchemaZ,
355
+ })
356
+ .strict();
335
357
  export const PaneStreamTerminalDeliveryNackFrameSchemaZ = z
336
358
  .object({ type: z.literal("terminal-delivery-nack"), nack: TerminalDeliveryNackSchemaZ })
337
359
  .strict();
@@ -457,6 +479,7 @@ export const PaneStreamClientFrameSchemaZ = z.union([
457
479
  PaneStreamTerminalProjectionReceiptFrameSchemaZ,
458
480
  PaneStreamTerminalProjectionMaterializeFrameSchemaZ,
459
481
  PaneStreamTerminalDeliveryNackFrameSchemaZ,
482
+ PaneStreamTerminalDeliveryHistoryRequestFrameSchemaZ,
460
483
  PaneStreamTerminalDeliveryVisibilityFrameSchemaZ,
461
484
  PaneStreamSemanticIntentFrameSchemaZ,
462
485
  PaneStreamViewportFrameSchemaZ,
@@ -588,6 +611,11 @@ export const PaneStreamLayoutFrameSchemaZ = z
588
611
  .regex(/^(?:[0-9a-f]{2048})?$/u)
589
612
  .nullable()
590
613
  .optional(),
614
+ /**
615
+ * Only with capability 123: a terminal browser with tmux-ide's
616
+ * native controls, a plain one without them, or null.
617
+ */
618
+ browserKind: z.enum(["native", "plain"]).nullable().optional(),
591
619
  /** Only with capability 118: the Markdown reader's file name, never its path. */
592
620
  reader: z
593
621
  .object({
@@ -5,6 +5,7 @@ import { TerminalAttachmentSemanticPaneIdSchemaZ } from "./semantic-identity.ts"
5
5
  import { SessionRuntimeGenerationSchemaZ } from "./session-runtime.ts";
6
6
  import { WorkspaceIdSchemaZ } from "./workspace-state.ts";
7
7
  import {
8
+ TerminalReplicaRowSchemaZ,
8
9
  TerminalReplicaPatchPayloadSchemaZ,
9
10
  TerminalReplicaSnapshotSchemaZ,
10
11
  TerminalReplicaTombstonePayloadSchemaZ,
@@ -20,6 +21,34 @@ export const TERMINAL_DELIVERY_BINARY_CAPABILITY_VERSION = 109;
20
21
  export const TERMINAL_DELIVERY_BINARY_LOCAL_CAPABILITY_VERSION = 110;
21
22
 
22
23
  export const TERMINAL_DELIVERY_PROTOCOL_VERSION = 1 as const;
24
+
25
+ /**
26
+ * History on demand (owner's decision 17 Nov, 2.9.26). With capability 122 a
27
+ * seed carries the screen plus the newest TERMINAL_DELIVERY_HISTORY_TAIL_ROWS
28
+ * history rows and a commitment `{rows, digest}` to the older, unloaded rows.
29
+ * The rows digest is a polynomial fold, so the loaded rows and the commitment
30
+ * still verify against the full canonical state hash. The client asks for
31
+ * older rows with a history request; they come newest first in a "history"
32
+ * frame at its current revision. It replaces deferred-history-v1 (111/112).
33
+ */
34
+ export const TERMINAL_DELIVERY_PARTIAL_HISTORY_CAPABILITY_VERSION = 122;
35
+ export const TERMINAL_DELIVERY_HISTORY_TAIL_ROWS = 200;
36
+ /**
37
+ * Capability 124: the client takes patches pipelined behind unacknowledged
38
+ * ones. It applies each in order against its last applied revision, ACKs each
39
+ * in order, and holds a delivery that arrives while an earlier one is still
40
+ * decoding or unsettled. Without it a pane keeps one delivery in flight.
41
+ */
42
+ export const TERMINAL_DELIVERY_PIPELINING_CAPABILITY_VERSION = 124;
43
+ /**
44
+ * Deliveries a pane of a 124 client may have unacknowledged. After a NACK a
45
+ * client NACKs each pipelined patch once; the app fails a stream on its
46
+ * fourth NACK in a row, so this stays at 3 or below.
47
+ */
48
+ export const TERMINAL_DELIVERY_MAX_PIPELINED = 3;
49
+ export const TERMINAL_DELIVERY_HISTORY_CHUNK_MAX_ROWS = 2000;
50
+ /** Capability numbers one offer may carry (nine before 2.9.26). */
51
+ export const TERMINAL_DELIVERY_MAX_OFFERED_VERSIONS = 16;
23
52
  export const TERMINAL_DELIVERY_CHUNK_BYTES = 256 * 1024;
24
53
  export const TERMINAL_DELIVERY_PATCH_TO_SEED_BYTES = 512 * 1024;
25
54
  export const TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES = 16 * 1024 * 1024;
@@ -35,8 +64,12 @@ export type TerminalDeliveryEncoding = z.infer<typeof TerminalDeliveryEncodingSc
35
64
 
36
65
  export const TerminalDeliveryOfferSchemaZ = z
37
66
  .object({
38
- // Interactive binary/graphics offers use eight slots; native surfaces add one.
39
- protocolVersions: z.array(z.number().int().positive()).min(1).max(9),
67
+ // Released daemons before 2.9.26 refuse more than nine numbers, so a client
68
+ // offers a tenth only to a daemon whose productVersion is 2.9.26 or later.
69
+ protocolVersions: z
70
+ .array(z.number().int().positive())
71
+ .min(1)
72
+ .max(TERMINAL_DELIVERY_MAX_OFFERED_VERSIONS),
40
73
  encodings: z.array(TerminalDeliveryEncodingSchemaZ).min(1).max(4),
41
74
  richPlacements: z.boolean(),
42
75
  })
@@ -55,6 +88,8 @@ export const TerminalDeliveryNegotiatedSchemaZ = z
55
88
  encoding: TerminalDeliveryEncodingSchemaZ,
56
89
  fallbackEncoding: z.literal("semantic-v1").nullable().optional(),
57
90
  alternateScreenProjection: z.literal("deferred-history-v1").optional(),
91
+ /** Capability 122: history on demand. */
92
+ partialHistory: z.literal("tail-v1").optional(),
58
93
  richPlacements: z.boolean(),
59
94
  generation: SessionRuntimeGenerationSchemaZ,
60
95
  deliveryNonce: z.uuid(),
@@ -63,6 +98,15 @@ export const TerminalDeliveryNegotiatedSchemaZ = z
63
98
  .superRefine((value, context) => {
64
99
  if (value.alternateScreenProjection && value.encoding !== "semantic-binary-v1")
65
100
  context.addIssue({ code: "custom", message: "projection requires binary semantic delivery" });
101
+ if (
102
+ value.partialHistory &&
103
+ ((value.encoding !== "semantic-compact-v1" && value.encoding !== "semantic-binary-v1") ||
104
+ value.alternateScreenProjection)
105
+ )
106
+ context.addIssue({
107
+ code: "custom",
108
+ message: "partial history requires compact or binary semantic delivery and no projection",
109
+ });
66
110
  if (value.fallbackEncoding && value.encoding !== "semantic-compact-v1")
67
111
  context.addIssue({ code: "custom", message: "fallback encoding requires compact semantic" });
68
112
  if (
@@ -92,6 +136,28 @@ export type TerminalDeliveryNegotiationResult = z.infer<
92
136
  typeof TerminalDeliveryNegotiationResultSchemaZ
93
137
  >;
94
138
 
139
+ /** The rows digest of no rows. */
140
+ export const TERMINAL_HISTORY_EMPTY_DIGEST = "0000000000000000";
141
+
142
+ /**
143
+ * Pinned at `rows: 0` to the digest of no rows: with that anchor, each history
144
+ * chunk's chain check is an induction proof (review of #435). Without it a
145
+ * forged chain of chunks could end in any digest and still match the hash.
146
+ */
147
+ export const TerminalDeliveryHistoryCommitmentSchemaZ = z
148
+ .object({
149
+ rows: z.number().int().nonnegative().max(1_000_000),
150
+ digest: z.string().regex(/^[0-9a-f]{16}$/u),
151
+ })
152
+ .strict()
153
+ .refine(
154
+ (value) => value.rows > 0 || value.digest === TERMINAL_HISTORY_EMPTY_DIGEST,
155
+ "an empty commitment has the empty digest",
156
+ );
157
+ export type TerminalDeliveryHistoryCommitment = z.infer<
158
+ typeof TerminalDeliveryHistoryCommitmentSchemaZ
159
+ >;
160
+
95
161
  const DeliveryAddressSchemaZ = z.object({
96
162
  workspaceName: WorkspaceIdSchemaZ,
97
163
  semanticPaneId: TerminalAttachmentSemanticPaneIdSchemaZ,
@@ -113,7 +179,7 @@ export const TerminalDeliveryEnvelopeSchemaZ = DeliveryAddressSchemaZ.extend({
113
179
  causalCellProof: CausalCellProofV1SchemaZ.optional(),
114
180
  protocolVersion: z.literal(TERMINAL_DELIVERY_PROTOCOL_VERSION),
115
181
  encoding: TerminalDeliveryEncodingSchemaZ,
116
- frame: z.enum(["seed", "patch", "tombstone"]),
182
+ frame: z.enum(["seed", "patch", "tombstone", "history"]),
117
183
  baseRevision: z.number().int().min(-1).nullable(),
118
184
  canonicalRevision: z.number().int().nonnegative(),
119
185
  canonicalStateHash: z.string().regex(/^[0-9a-f]{16}$/u),
@@ -125,7 +191,9 @@ export const TerminalDeliveryEnvelopeSchemaZ = DeliveryAddressSchemaZ.extend({
125
191
  .max(TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES),
126
192
  chunkCount: z.number().int().positive().max(256),
127
193
  canonicalEquivalent: z.boolean(),
128
- history: z.enum(["complete", "truncated", "not-applicable"]),
194
+ history: z.enum(["complete", "partial", "truncated", "not-applicable"]),
195
+ /** Capability 122: the history rows the client does not hold, oldest first. */
196
+ historyUnloaded: TerminalDeliveryHistoryCommitmentSchemaZ.optional(),
129
197
  richPlacements: z.boolean(),
130
198
  })
131
199
  .strict()
@@ -145,17 +213,39 @@ export const TerminalDeliveryEnvelopeSchemaZ = DeliveryAddressSchemaZ.extend({
145
213
  });
146
214
  if (value.frame === "seed" && value.baseRevision !== null)
147
215
  context.addIssue({ code: "custom", message: "seed baseRevision must be null" });
216
+ if (
217
+ value.frame === "history" &&
218
+ (value.baseRevision !== value.canonicalRevision || value.history !== "partial")
219
+ )
220
+ context.addIssue({
221
+ code: "custom",
222
+ message: "a history frame is partial and stays at the client's revision",
223
+ });
148
224
  if (
149
225
  value.frame !== "seed" &&
226
+ value.frame !== "history" &&
150
227
  (value.baseRevision === null || value.canonicalRevision <= value.baseRevision)
151
228
  )
152
229
  context.addIssue({
153
230
  code: "custom",
154
231
  message: "patch/tombstone requires an earlier baseRevision",
155
232
  });
233
+ if ((value.history === "partial") !== (value.historyUnloaded !== undefined))
234
+ context.addIssue({
235
+ code: "custom",
236
+ message: "a partial history carries its unloaded commitment, and only it does",
237
+ });
238
+ if (value.history === "partial" && (!semantic || value.frame === "tombstone"))
239
+ context.addIssue({
240
+ code: "custom",
241
+ message: "partial history is semantic and not a tombstone",
242
+ });
156
243
  if (
157
244
  semantic &&
158
- (!value.canonicalEquivalent || (value.frame !== "tombstone" && value.history !== "complete"))
245
+ (!value.canonicalEquivalent ||
246
+ (value.frame !== "tombstone" &&
247
+ value.history !== "complete" &&
248
+ value.history !== "partial"))
159
249
  )
160
250
  context.addIssue({
161
251
  code: "custom",
@@ -219,6 +309,19 @@ export const TerminalDeliveryNackSchemaZ = DeliveryAddressSchemaZ.extend({
219
309
  }).strict();
220
310
  export type TerminalDeliveryNack = z.infer<typeof TerminalDeliveryNackSchemaZ>;
221
311
 
312
+ /**
313
+ * Capability 122: the client asks for the newest `maxRows` of its unloaded
314
+ * history. It names its committed revision and unloaded row count; a request
315
+ * that no longer matches the daemon's view of that baseline is dropped.
316
+ */
317
+ export const TerminalDeliveryHistoryRequestSchemaZ = DeliveryAddressSchemaZ.extend({
318
+ type: z.literal("terminal.delivery.history-request"),
319
+ canonicalRevision: z.number().int().nonnegative(),
320
+ unloadedRows: z.number().int().nonnegative().max(1_000_000),
321
+ maxRows: z.number().int().min(1).max(TERMINAL_DELIVERY_HISTORY_CHUNK_MAX_ROWS),
322
+ }).strict();
323
+ export type TerminalDeliveryHistoryRequest = z.infer<typeof TerminalDeliveryHistoryRequestSchemaZ>;
324
+
222
325
  export type TerminalDeliveryServerMessage =
223
326
  | TerminalDeliveryEnvelope
224
327
  | TerminalProjectionEnvelope
@@ -263,3 +366,17 @@ export const TerminalSemanticDeliveryPayloadSchemaZ = z.discriminatedUnion("fram
263
366
  export type TerminalSemanticDeliveryPayload = z.infer<
264
367
  typeof TerminalSemanticDeliveryPayloadSchemaZ
265
368
  >;
369
+
370
+ /**
371
+ * Capability 122: a "history" frame's payload, the newest unloaded rows,
372
+ * oldest first, at the client's revision. Kept apart from the seed, patch and
373
+ * tombstone union: it changes no revision and no canonical state.
374
+ */
375
+ export const TerminalSemanticHistoryPayloadSchemaZ = z
376
+ .object({
377
+ frame: z.literal("history"),
378
+ revision: z.number().int().nonnegative(),
379
+ rows: z.array(TerminalReplicaRowSchemaZ).min(1).max(TERMINAL_DELIVERY_HISTORY_CHUNK_MAX_ROWS),
380
+ })
381
+ .strict();
382
+ export type TerminalSemanticHistoryPayload = z.infer<typeof TerminalSemanticHistoryPayloadSchemaZ>;
@@ -2,7 +2,10 @@ import { z } from "zod";
2
2
 
3
3
  import { DaemonInstanceIdentitySchemaZ } from "./daemon-wire.ts";
4
4
  import { DesktopWorkspaceNameSchemaZ } from "./desktop-workspace-name.ts";
5
- import { TerminalAttachmentSemanticPaneIdSchemaZ } from "./terminal-attachments.ts";
5
+ import {
6
+ TerminalAttachmentSemanticPaneIdSchemaZ,
7
+ TerminalAttachmentSemanticWindowIdSchemaZ,
8
+ } from "./terminal-attachments.ts";
6
9
  import { FleetSessionIdSchemaZ } from "./fleet-catalog.ts";
7
10
  import { SemanticProductIdSchemaZ } from "./pane-appearance.ts";
8
11
 
@@ -30,6 +33,63 @@ export type TerminalRuntimeInventoryProjectionV1 = z.infer<
30
33
  typeof TerminalRuntimeInventoryProjectionV1SchemaZ
31
34
  >;
32
35
 
36
+ /**
37
+ * #806: version 2 also names each window with its panes, so a client can issue
38
+ * a pane stream for one window (`semanticWindowId` plus exactly these panes).
39
+ * A window is listed only when every pane in it is available; a client that
40
+ * asks for version 2 of an older daemon gets version 1 and has no windows.
41
+ */
42
+ export const TerminalRuntimeInventoryWindowSchemaZ = z
43
+ .object({
44
+ semanticWindowId: TerminalAttachmentSemanticWindowIdSchemaZ,
45
+ /** tmux's current window of the session. */
46
+ active: z.boolean(),
47
+ semanticPaneIds: z
48
+ .array(TerminalAttachmentSemanticPaneIdSchemaZ)
49
+ .min(1)
50
+ .max(256)
51
+ .refine((values) => new Set(values).size === values.length, "pane ids must be unique"),
52
+ })
53
+ .strict();
54
+ export type TerminalRuntimeInventoryWindow = z.infer<typeof TerminalRuntimeInventoryWindowSchemaZ>;
55
+
56
+ export const TerminalRuntimeInventoryProjectionV2SchemaZ =
57
+ TerminalRuntimeInventoryProjectionV1SchemaZ.extend({
58
+ /** In tmux window order. */
59
+ windows: z.array(TerminalRuntimeInventoryWindowSchemaZ).max(256),
60
+ })
61
+ .strict()
62
+ .superRefine((value, ctx) => {
63
+ const listed = new Set(value.semanticPaneIds);
64
+ const seen = new Set<string>();
65
+ const windows = new Set<string>();
66
+ let active = 0;
67
+ for (const window of value.windows) {
68
+ if (windows.has(window.semanticWindowId))
69
+ ctx.addIssue({ code: "custom", message: "a window is listed twice", path: ["windows"] });
70
+ windows.add(window.semanticWindowId);
71
+ if (window.active) active += 1;
72
+ for (const pane of window.semanticPaneIds) {
73
+ if (!listed.has(pane) || seen.has(pane))
74
+ ctx.addIssue({
75
+ code: "custom",
76
+ message: "a window pane must be listed once and in the inventory",
77
+ path: ["windows"],
78
+ });
79
+ seen.add(pane);
80
+ }
81
+ }
82
+ if (active > 1)
83
+ ctx.addIssue({
84
+ code: "custom",
85
+ message: "at most one window is active",
86
+ path: ["windows"],
87
+ });
88
+ });
89
+ export type TerminalRuntimeInventoryProjectionV2 = z.infer<
90
+ typeof TerminalRuntimeInventoryProjectionV2SchemaZ
91
+ >;
92
+
33
93
  export const TerminalRuntimeInventoryResourceV1SchemaZ = z
34
94
  .object({
35
95
  version: z.literal(TERMINAL_RUNTIME_INVENTORY_RESOURCE_VERSION),
@@ -205,6 +205,24 @@ export const TmuxServerSessionsResourceV2SchemaZ = z
205
205
  .strict();
206
206
  export type TmuxServerSessionsResourceV2 = z.infer<typeof TmuxServerSessionsResourceV2SchemaZ>;
207
207
 
208
+ /**
209
+ * #806: version 3 adds the pane count of the session's largest window, so Home
210
+ * can tell whether a session opens window by window (at most 24 panes per
211
+ * window) before opening it. Versions 1 and 2 stay as they were.
212
+ */
213
+ export const TmuxServerSessionsResourceV3SchemaZ = z
214
+ .object({
215
+ version: z.literal(3),
216
+ server: TmuxServerScopeSchemaZ,
217
+ sessions: z.array(
218
+ TmuxServerSessionsResourceV2SchemaZ.shape.sessions.element
219
+ .extend({ largestWindowPaneCount: z.number().int().min(1) })
220
+ .strict(),
221
+ ),
222
+ })
223
+ .strict();
224
+ export type TmuxServerSessionsResourceV3 = z.infer<typeof TmuxServerSessionsResourceV3SchemaZ>;
225
+
208
226
  /** Selector intent is interpreted only by the daemon on its own host. */
209
227
  export const TmuxServerRegistrationRequestSchemaZ = z
210
228
  .object({
@@ -22,3 +22,4 @@ export * from "./resize-transaction.ts";
22
22
  export * from "./kitty-placeholders.ts";
23
23
 
24
24
  export * from "./terminal-projection.ts";
25
+ export * from "./terminal-partial-history.ts";
@@ -70,15 +70,15 @@ export class BinaryTerminalWriter {
70
70
  throw new TypeError("Invalid binary tuple value");
71
71
  }
72
72
  header(
73
- frame: "seed" | "patch" | "tombstone",
73
+ frame: "seed" | "patch" | "tombstone" | "history",
74
74
  revision: number,
75
75
  base?: number,
76
76
  magic: "TCB1" | "TCP1" = "TCB1",
77
77
  ) {
78
78
  for (const b of magic === "TCP1" ? [84, 67, 80, 49] : [84, 67, 66, 49]) this.byte(b);
79
- this.byte(frame === "seed" ? 0 : frame === "patch" ? 1 : 2);
79
+ this.byte(frame === "seed" ? 0 : frame === "patch" ? 1 : frame === "tombstone" ? 2 : 3);
80
80
  this.uint(revision);
81
- if (frame !== "seed") this.uint(base!);
81
+ if (frame !== "seed" && frame !== "history") this.uint(base!);
82
82
  }
83
83
  get byteLength(): number {
84
84
  return this.length;
@@ -91,7 +91,7 @@ export function decodeBinaryTerminalTuple(
91
91
  bytes: Uint8Array,
92
92
  magic: "TCB1" | "TCP1" = "TCB1",
93
93
  ): {
94
- frame: "seed" | "patch" | "tombstone";
94
+ frame: "seed" | "patch" | "tombstone" | "history";
95
95
  revision: number;
96
96
  baseRevision?: number;
97
97
  value: unknown;
@@ -150,10 +150,11 @@ export function decodeBinaryTerminalTuple(
150
150
  throw new TypeError("Unknown binary value tag");
151
151
  };
152
152
  const kind = byte();
153
- if (kind > 2) throw new TypeError("Unknown binary frame");
154
- const frame = kind === 0 ? "seed" : kind === 1 ? "patch" : "tombstone";
153
+ // Frame 3 is a capability-122 history chunk: a revision and no base.
154
+ if (kind > 3) throw new TypeError("Unknown binary frame");
155
+ const frame = kind === 0 ? "seed" : kind === 1 ? "patch" : kind === 2 ? "tombstone" : "history";
155
156
  const revision = uint();
156
- const baseRevision = kind === 0 ? undefined : uint();
157
+ const baseRevision = kind === 0 || kind === 3 ? undefined : uint();
157
158
  const value = read();
158
159
  if (offset !== bytes.length) throw new TypeError("Trailing binary data");
159
160
  return { frame, revision, ...(baseRevision === undefined ? {} : { baseRevision }), value };