@linzumi/cli 1.0.300 → 1.0.302

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.
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "version": 1,
3
- "sourceSha256": "0fe0761fe94c9791cdffb1ed2e271b4aee1ec777cdb984219da0ea1d3c2cc399",
4
- "buildScriptSha256": "42e501268392badf5caa9ca0b64e28f0c3d7e437542c95512e362969cd1471cf",
5
- "binarySha256": "90f178d65067a4313c00fa82697825d38886e6a89dee2063c13146b4891a20eb",
3
+ "sourceSha256": "192542c039720061daa0b31359564c06cef9e00fed6729c59bd5c3e8edfcca49",
4
+ "buildScriptSha256": "2c295e06280bb843579edb0e42b6a25e68d18790cbdb3ec5520504dae3715379",
5
+ "binarySha256": "4ed8952bc81b03e4028539c7c08b669d427ad661d1e5d624f7c8856d410d30fa",
6
6
  "architectures": [
7
7
  "arm64",
8
8
  "x86_64"
@@ -20,5 +20,6 @@
20
20
  "-mmacosx-version-min=11.0"
21
21
  ],
22
22
  "compiler": "Apple clang version 21.0.0 (clang-2100.3.34.2)",
23
- "sdkVersion": "27.0"
23
+ "sdkVersion": "27.0",
24
+ "inputReceipts": 1
24
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linzumi/cli",
3
- "version": "1.0.300",
3
+ "version": "1.0.302",
4
4
  "description": "Linzumi CLI \u2014 point a Codex agent at the real code on your laptop, with your team watching and steering from shared threads.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -267,9 +267,13 @@ function scanTargets() {
267
267
  // the CLI was at version X legitimately carries that version string
268
268
  // in its recorded wire payloads forever, and the bump must neither
269
269
  // rewrite it nor refuse because of it
270
- // (spec/codex-wire-capture-replay.spec.md).
270
+ // (spec/codex-wire-capture-replay.spec.md). Captured production-failure
271
+ // fixtures are the same frozen evidence (CLAUDE.md "every real bug =>
272
+ // a captured prod fixture"; lint-staged keeps them byte-exact): an
273
+ // incident recorded on version X names X forever.
271
274
  if (
272
- relativePath.startsWith(join('test', 'fixtures', 'agent-raw-replay'))
275
+ relativePath.startsWith(join('test', 'fixtures', 'agent-raw-replay')) ||
276
+ relativePath.startsWith(join('test', 'fixtures', 'prod-failures'))
273
277
  ) {
274
278
  continue;
275
279
  }
@@ -8,6 +8,12 @@
8
8
  * 'i' input bytes, written to the PTY master exactly once
9
9
  * 'r' resize: cols u16 BE, rows u16 BE (clamped 20..400 x 5..200)
10
10
  * 's' stop: SIGHUP+SIGTERM the shell group, SIGKILL after 2s
11
+ * 'w' write receipt: id u32 BE. Answered once, in order, on stderr
12
+ * when every input byte accepted before it has been written
13
+ * to the PTY master (WRITTEN), or when Stop or a closed PTY
14
+ * means some of them never will be (DROPPED). A receipt
15
+ * confirms the PTY write only - never that a program read or
16
+ * acted on the bytes (plans/2026-10-19-terminal-enter-delivery.md).
11
17
  * EOF on stdin is treated as 's' (Commander died or detached us).
12
18
  * SIGTERM/SIGHUP/SIGINT delivered to the helper itself are also 's',
13
19
  * so a stop is never queued behind unconsumed input.
@@ -30,6 +36,11 @@
30
36
  * (discarded: post-Stop output bytes Commander was not draining;
31
37
  * explicit, never silent)
32
38
  * LINZUMI_PTY_ERROR <code>
39
+ * LINZUMI_PTY_INPUT_WRITTEN id=<n> | LINZUMI_PTY_INPUT_DROPPED id=<n>
40
+ * LINZUMI_PTY_INPUT_FAILED errno=<n> (a PTY write failed for good:
41
+ * the pending input is discarded and its receipts DROPPED)
42
+ * LINZUMI_PTY_INPUT_INVALID_RECEIPT length=<n> (a 'w' frame without
43
+ * a 4-byte id; there is no id to answer, so it is named instead)
33
44
  *
34
45
  * The helper never logs input/output content. The post-fork child does only
35
46
  * async-signal-safe work (chdir, execve, _exit); argv/envp are built pre-fork.
@@ -76,6 +87,8 @@
76
87
  #define KILL_CONFIRM_MS 1000
77
88
  /* Final cleanup re-enumerates and kills at most this many times. */
78
89
  #define CLEANUP_ROUNDS 4
90
+ /* Outstanding write receipts; a further 'w' frame waits (backpressure). */
91
+ #define MAX_RECEIPTS 64
79
92
 
80
93
  extern char **environ;
81
94
 
@@ -92,6 +105,17 @@ static void status_line(const char *line) {
92
105
  }
93
106
  }
94
107
 
108
+ typedef struct {
109
+ uint32_t id;
110
+ unsigned long long target; /* accepted-input total the receipt waits for */
111
+ } receipt;
112
+
113
+ static void receipt_line(const char *outcome, uint32_t id) {
114
+ char line[64];
115
+ snprintf(line, sizeof(line), "LINZUMI_PTY_INPUT_%s id=%u\n", outcome, (unsigned)id);
116
+ status_line(line);
117
+ }
118
+
95
119
  static int fail(const char *code, int status) {
96
120
  char line[128];
97
121
  snprintf(line, sizeof(line), "LINZUMI_PTY_ERROR %s\n", code);
@@ -170,10 +194,12 @@ static int test_fault(const char *name) {
170
194
  #define fault_pid_lookup() test_fault("pid_lookup")
171
195
  #define fault_pause_before_reap() test_fault("pause_before_reap")
172
196
  #define fault_pause_after_fork() test_fault("pause_after_fork")
197
+ #define fault_input_write() test_fault("input_write")
173
198
  #else
174
199
  #define fault_pid_lookup() 0
175
200
  #define fault_pause_before_reap() 0
176
201
  #define fault_pause_after_fork() 0
202
+ #define fault_input_write() 0
177
203
  #endif
178
204
 
179
205
  static void add_member(pid_t pid, struct timeval started) {
@@ -408,6 +434,16 @@ int main(int argc, char **argv) {
408
434
  size_t pending_used = 0;
409
435
  size_t out_used = 0;
410
436
  unsigned long long discarded = 0; /* post-stop bytes Commander could not take */
437
+ static receipt receipts[MAX_RECEIPTS];
438
+ size_t receipts_used = 0;
439
+ unsigned long long accepted_total = 0; /* input bytes ever queued for the PTY */
440
+ unsigned long long written_total = 0; /* input bytes ever written to the PTY */
441
+ /* Each receipt covers the input accepted after the previous receipt, up to
442
+ * its own target. Bytes up to discarded_through never reached the PTY, so a
443
+ * receipt covering any of them is DROPPED, even one parsed after the
444
+ * failure (the 'i' and 'w' frames may arrive in separate reads). */
445
+ unsigned long long last_receipt_target = 0;
446
+ unsigned long long discarded_through = 0;
411
447
  int stdin_open = 1;
412
448
  int stdout_open = 1;
413
449
  int master_open = 1;
@@ -419,11 +455,29 @@ int main(int argc, char **argv) {
419
455
  /* The shell exited but is deliberately NOT reaped until cleanup ends. */
420
456
  int child_exited = 0;
421
457
 
458
+ /* Answers every receipt whose bytes are all written, in order. */
459
+ #define SETTLE_RECEIPTS() \
460
+ do { \
461
+ size_t settled = 0; \
462
+ while (settled < receipts_used && receipts[settled].target <= written_total) \
463
+ receipt_line("WRITTEN", receipts[settled++].id); \
464
+ memmove(receipts, receipts + settled, (receipts_used - settled) * sizeof(receipt)); \
465
+ receipts_used -= settled; \
466
+ } while (0)
467
+ /* The pending bytes will never be written: every open receipt is dropped. */
468
+ #define DROP_RECEIPTS() \
469
+ do { \
470
+ for (size_t r = 0; r < receipts_used; r++) \
471
+ receipt_line("DROPPED", receipts[r].id); \
472
+ receipts_used = 0; \
473
+ } while (0)
474
+
422
475
  #define BEGIN_STOP() \
423
476
  do { \
424
477
  if (!stopping) { \
425
478
  stopping = 1; \
426
479
  pending_used = 0; /* fenced: never reaches PTY */ \
480
+ DROP_RECEIPTS(); \
427
481
  kill_deadline = monotonic_ms() + STOP_GRACE_MS; \
428
482
  collect_session_members(child); \
429
483
  signal_terminal(child, master, SIGHUP); \
@@ -516,11 +570,26 @@ int main(int argc, char **argv) {
516
570
  } else if (revents & (POLLHUP | POLLERR)) {
517
571
  master_open = 0;
518
572
  }
573
+ if (!master_open) DROP_RECEIPTS(); /* nothing more reaches the PTY */
519
574
  if (master_open && !stopping && (revents & POLLOUT) && pending_used > 0) {
520
- ssize_t wrote = write(master, pending, pending_used);
575
+ ssize_t wrote = fault_input_write() ? (errno = EIO, -1) : write(master, pending, pending_used);
521
576
  if (wrote > 0) {
522
577
  memmove(pending, pending + wrote, pending_used - (size_t)wrote);
523
578
  pending_used -= (size_t)wrote;
579
+ written_total += (unsigned long long)wrote;
580
+ SETTLE_RECEIPTS();
581
+ } else if (wrote < 0 && errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
582
+ /* Never silent: the bytes cannot reach the PTY, so they are
583
+ * discarded (never retried) and every waiting receipt is dropped. */
584
+ char line[64];
585
+ snprintf(line, sizeof(line), "LINZUMI_PTY_INPUT_FAILED errno=%d\n", errno);
586
+ status_line(line);
587
+ /* Counted as settled so a later receipt waits only for later bytes;
588
+ * every receipt covering the discarded bytes is dropped. */
589
+ written_total += (unsigned long long)pending_used;
590
+ discarded_through = accepted_total;
591
+ pending_used = 0;
592
+ DROP_RECEIPTS();
524
593
  }
525
594
  }
526
595
  }
@@ -579,6 +648,25 @@ int main(int argc, char **argv) {
579
648
  if (!stopping && master_open) {
580
649
  memcpy(pending + pending_used, payload, length);
581
650
  pending_used += length;
651
+ accepted_total += length;
652
+ }
653
+ } else if (type == 'w' && length != 4) {
654
+ char line[64];
655
+ snprintf(line, sizeof(line), "LINZUMI_PTY_INPUT_INVALID_RECEIPT length=%u\n", (unsigned)length);
656
+ status_line(line);
657
+ } else if (type == 'w') {
658
+ if (receipts_used == MAX_RECEIPTS) break; /* wait; never drop */
659
+ uint32_t id = ((uint32_t)payload[0] << 24) | ((uint32_t)payload[1] << 16) |
660
+ ((uint32_t)payload[2] << 8) | (uint32_t)payload[3];
661
+ int covers_discarded = discarded_through > last_receipt_target;
662
+ last_receipt_target = accepted_total;
663
+ if (stopping || !master_open || covers_discarded) {
664
+ receipt_line("DROPPED", id);
665
+ } else {
666
+ receipts[receipts_used].id = id;
667
+ receipts[receipts_used].target = accepted_total;
668
+ receipts_used++;
669
+ SETTLE_RECEIPTS();
582
670
  }
583
671
  } else if (type == 'r' && length == 4 && master_open) {
584
672
  struct winsize next;
@@ -595,6 +683,8 @@ int main(int argc, char **argv) {
595
683
  }
596
684
  }
597
685
 
686
+ /* The loop ended with input unwritten: those receipts never complete. */
687
+ DROP_RECEIPTS();
598
688
  if (!child_exited) {
599
689
  kill(-child, SIGKILL);
600
690
  kill(child, SIGKILL);