@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.js CHANGED
@@ -2787,6 +2787,18 @@ function detectShellPrompt(lines) {
2787
2787
  return null;
2788
2788
  }
2789
2789
 
2790
+ // src/services/questions/permissionAnswerKeys.ts
2791
+ var ENTER2 = "\r";
2792
+ function permissionAnswerKeys(index) {
2793
+ if (!Number.isInteger(index) || index < 0) {
2794
+ throw new Error(`Invalid permission option index: ${index}`);
2795
+ }
2796
+ return `${index}${ENTER2}`;
2797
+ }
2798
+ function isPermissionAnswer(gate, keys) {
2799
+ return gate.options.some((o) => keys === (o.answerKeys ?? permissionAnswerKeys(o.index)));
2800
+ }
2801
+
2790
2802
  // src/utils/deriveSessionName.ts
2791
2803
  function deriveSessionName(firstMessageText) {
2792
2804
  const firstLine = firstMessageText.split("\n", 1)[0]?.trim() ?? "";
@@ -2829,10 +2841,12 @@ var PTYManager = class {
2829
2841
  onLiveQuestion;
2830
2842
  onLiveQuestionGone;
2831
2843
  onUserMessage;
2832
- // Per-session permission-gate state. True between an OSC 777 (gate open) and
2833
- // the next prompt-ready without a fresh 777 (gate closed). Prevents
2834
- // re-broadcasting open/close on every chunk.
2835
- permissionOpen = /* @__PURE__ */ new Set();
2844
+ // Per-session permission-gate state: the gate currently open on a session's
2845
+ // screen. Set between an OSC 777 / paint-time claim (gate open) and the next
2846
+ // prompt-ready without a fresh 777 (gate closed). Prevents re-broadcasting
2847
+ // open/close on every chunk. Holds the gate itself rather than just the id so
2848
+ // sendKeys can tell whether the bytes it is writing are that gate's answer.
2849
+ permissionOpen = /* @__PURE__ */ new Map();
2836
2850
  // Last chunk's raw tail per session — prepended to the next chunk before
2837
2851
  // the OSC regex test so a split escape still matches. Consumed on match.
2838
2852
  oscTail = /* @__PURE__ */ new Map();
@@ -3067,6 +3081,11 @@ var PTYManager = class {
3067
3081
  );
3068
3082
  session.process.write(keys);
3069
3083
  session.lastActivityAt = /* @__PURE__ */ new Date();
3084
+ const openGate = this.permissionOpen.get(sessionId);
3085
+ if (openGate && isPermissionAnswer(openGate, keys)) {
3086
+ this.permissionOpen.delete(sessionId);
3087
+ this.onPermissionChange?.(sessionId, null);
3088
+ }
3070
3089
  }
3071
3090
  sendInput(sessionId, input) {
3072
3091
  const session = this.sessions.get(sessionId);
@@ -3413,7 +3432,7 @@ var PTYManager = class {
3413
3432
  }
3414
3433
  if (oscPermission && !askFooterOnScreen) {
3415
3434
  const gate = scrapePermissionGate(lines);
3416
- this.permissionOpen.add(sessionId);
3435
+ this.permissionOpen.set(sessionId, gate ?? { options: [] });
3417
3436
  this.onPermissionChange?.(sessionId, gate ?? { options: [] });
3418
3437
  } else if (this.permissionOpen.has(sessionId) && !askFooterOnScreen) {
3419
3438
  const gate = detectGateScreen(lines);
@@ -3427,6 +3446,7 @@ var PTYManager = class {
3427
3446
  this.closedGateKey.delete(sessionId);
3428
3447
  }
3429
3448
  } else if (gate) {
3449
+ this.permissionOpen.set(sessionId, gate);
3430
3450
  this.onPermissionChange?.(sessionId, gate);
3431
3451
  }
3432
3452
  } else if (!askFooterOnScreen && !oscWaitingForInput) {
@@ -3434,7 +3454,7 @@ var PTYManager = class {
3434
3454
  if (gate) {
3435
3455
  const key = permissionContentKey({ ...gate, cursor: void 0 });
3436
3456
  if (this.closedGateKey.get(sessionId) !== key) {
3437
- this.permissionOpen.add(sessionId);
3457
+ this.permissionOpen.set(sessionId, gate);
3438
3458
  this.onPermissionChange?.(sessionId, gate);
3439
3459
  }
3440
3460
  } else {
@@ -9553,7 +9573,7 @@ function parseStatusLine(lines) {
9553
9573
 
9554
9574
  // src/services/questions/answersToKeystrokes.ts
9555
9575
  var DOWN = "\x1B[B";
9556
- var ENTER2 = "\r";
9576
+ var ENTER3 = "\r";
9557
9577
  var UnknownOptionError = class extends Error {
9558
9578
  constructor(question, value) {
9559
9579
  super(`No option labelled "${value}" for question "${question}"`);
@@ -9574,7 +9594,7 @@ function answersToKeystrokes(questions, answers) {
9574
9594
  const label = Array.isArray(raw) ? raw[0] : raw;
9575
9595
  const target = q.options.findIndex((o) => o.label === label);
9576
9596
  if (target < 0) throw new UnknownOptionError(q.question, label);
9577
- out += DOWN.repeat(target) + ENTER2;
9597
+ out += DOWN.repeat(target) + ENTER3;
9578
9598
  }
9579
9599
  return out;
9580
9600
  }