#!/usr/bin/env node

// src/common/pty-approval-state.ts
function shouldReleaseApprovalWait(options) {
  if (options.currentState !== "approval_wait") return false;
  if (options.signalState === void 0) return false;
  if (options.signalState === null && options.allowTitleOnlyRelease === false) return false;
  return options.signalState !== "approval_wait";
}
function stateAfterApprovalRelease(signalState) {
  if (signalState === null) return "turn_complete";
  return signalState !== "approval_wait" ? signalState : "working";
}
function shouldReleaseTextApprovalOnInput(data) {
  if (data.includes("\r") || data.includes("\n")) return true;
  return data === "1" || data === "2" || data === "y" || data === "Y" || data === "n" || data === "N" || data === "\x1B" || data === "";
}

// src/common/pty-semantic-machine.ts
function withMeta(signal) {
  return {
    ...signal?.title !== void 0 ? { title: signal.title } : {},
    ...signal?.tool !== void 0 ? { tool: signal.tool } : {}
  };
}
function decidePtySemanticTransition(input) {
  const {
    currentState,
    signal,
    sessionStateIsWaitingApproval,
    allowTitleOnlyApprovalRelease = true,
    hasTextActivity = false
  } = input;
  if (signal?.state === "approval_wait") {
    return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
  }
  if (shouldReleaseApprovalWait({
    currentState,
    signalState: signal === null ? void 0 : signal.state,
    allowTitleOnlyRelease: allowTitleOnlyApprovalRelease
  })) {
    return {
      nextState: stateAfterApprovalRelease(signal.state),
      emit: true,
      meta: withMeta(signal)
    };
  }
  const inApprovalContext = currentState === "approval_wait" || sessionStateIsWaitingApproval === true;
  if (inApprovalContext && signal?.state !== "turn_complete") {
    return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
  }
  if (signal !== null && signal.state === null && (currentState === "working" || !hasTextActivity)) {
    return { nextState: currentState, emit: false };
  }
  if (signal && signal.state !== null && signal.state !== "working") {
    return { nextState: signal.state, emit: true, meta: withMeta(signal) };
  }
  if (currentState !== "working") {
    return { nextState: "working", emit: true };
  }
  return { nextState: currentState, emit: false };
}

export {
  shouldReleaseTextApprovalOnInput,
  decidePtySemanticTransition
};
//# sourceMappingURL=chunk-RYUEUDBR.js.map