@threadbase-sh/streamer 1.67.3 → 1.67.4

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/index.cjs CHANGED
@@ -2840,6 +2840,18 @@ function detectShellPrompt(lines) {
2840
2840
  return null;
2841
2841
  }
2842
2842
 
2843
+ // src/services/questions/permissionAnswerKeys.ts
2844
+ var ENTER2 = "\r";
2845
+ function permissionAnswerKeys(index) {
2846
+ if (!Number.isInteger(index) || index < 0) {
2847
+ throw new Error(`Invalid permission option index: ${index}`);
2848
+ }
2849
+ return `${index}${ENTER2}`;
2850
+ }
2851
+ function isPermissionAnswer(gate, keys) {
2852
+ return gate.options.some((o) => keys === (o.answerKeys ?? permissionAnswerKeys(o.index)));
2853
+ }
2854
+
2843
2855
  // src/utils/deriveSessionName.ts
2844
2856
  function deriveSessionName(firstMessageText) {
2845
2857
  const firstLine = firstMessageText.split("\n", 1)[0]?.trim() ?? "";
@@ -2882,10 +2894,12 @@ var PTYManager = class {
2882
2894
  onLiveQuestion;
2883
2895
  onLiveQuestionGone;
2884
2896
  onUserMessage;
2885
- // Per-session permission-gate state. True between an OSC 777 (gate open) and
2886
- // the next prompt-ready without a fresh 777 (gate closed). Prevents
2887
- // re-broadcasting open/close on every chunk.
2888
- permissionOpen = /* @__PURE__ */ new Set();
2897
+ // Per-session permission-gate state: the gate currently open on a session's
2898
+ // screen. Set between an OSC 777 / paint-time claim (gate open) and the next
2899
+ // prompt-ready without a fresh 777 (gate closed). Prevents re-broadcasting
2900
+ // open/close on every chunk. Holds the gate itself rather than just the id so
2901
+ // sendKeys can tell whether the bytes it is writing are that gate's answer.
2902
+ permissionOpen = /* @__PURE__ */ new Map();
2889
2903
  // Last chunk's raw tail per session — prepended to the next chunk before
2890
2904
  // the OSC regex test so a split escape still matches. Consumed on match.
2891
2905
  oscTail = /* @__PURE__ */ new Map();
@@ -3120,6 +3134,11 @@ var PTYManager = class {
3120
3134
  );
3121
3135
  session.process.write(keys);
3122
3136
  session.lastActivityAt = /* @__PURE__ */ new Date();
3137
+ const openGate = this.permissionOpen.get(sessionId);
3138
+ if (openGate && isPermissionAnswer(openGate, keys)) {
3139
+ this.permissionOpen.delete(sessionId);
3140
+ this.onPermissionChange?.(sessionId, null);
3141
+ }
3123
3142
  }
3124
3143
  sendInput(sessionId, input) {
3125
3144
  const session = this.sessions.get(sessionId);
@@ -3466,7 +3485,7 @@ var PTYManager = class {
3466
3485
  }
3467
3486
  if (oscPermission && !askFooterOnScreen) {
3468
3487
  const gate = scrapePermissionGate(lines);
3469
- this.permissionOpen.add(sessionId);
3488
+ this.permissionOpen.set(sessionId, gate ?? { options: [] });
3470
3489
  this.onPermissionChange?.(sessionId, gate ?? { options: [] });
3471
3490
  } else if (this.permissionOpen.has(sessionId) && !askFooterOnScreen) {
3472
3491
  const gate = detectGateScreen(lines);
@@ -3480,6 +3499,7 @@ var PTYManager = class {
3480
3499
  this.closedGateKey.delete(sessionId);
3481
3500
  }
3482
3501
  } else if (gate) {
3502
+ this.permissionOpen.set(sessionId, gate);
3483
3503
  this.onPermissionChange?.(sessionId, gate);
3484
3504
  }
3485
3505
  } else if (!askFooterOnScreen && !oscWaitingForInput) {
@@ -3487,7 +3507,7 @@ var PTYManager = class {
3487
3507
  if (gate) {
3488
3508
  const key = permissionContentKey({ ...gate, cursor: void 0 });
3489
3509
  if (this.closedGateKey.get(sessionId) !== key) {
3490
- this.permissionOpen.add(sessionId);
3510
+ this.permissionOpen.set(sessionId, gate);
3491
3511
  this.onPermissionChange?.(sessionId, gate);
3492
3512
  }
3493
3513
  } else {
@@ -9593,7 +9613,7 @@ function parseStatusLine(lines) {
9593
9613
 
9594
9614
  // src/services/questions/answersToKeystrokes.ts
9595
9615
  var DOWN = "\x1B[B";
9596
- var ENTER2 = "\r";
9616
+ var ENTER3 = "\r";
9597
9617
  var UnknownOptionError = class extends Error {
9598
9618
  constructor(question, value) {
9599
9619
  super(`No option labelled "${value}" for question "${question}"`);
@@ -9614,7 +9634,7 @@ function answersToKeystrokes(questions, answers) {
9614
9634
  const label = Array.isArray(raw) ? raw[0] : raw;
9615
9635
  const target = q.options.findIndex((o) => o.label === label);
9616
9636
  if (target < 0) throw new UnknownOptionError(q.question, label);
9617
- out += DOWN.repeat(target) + ENTER2;
9637
+ out += DOWN.repeat(target) + ENTER3;
9618
9638
  }
9619
9639
  return out;
9620
9640
  }