claude-yes 1.16.1 → 1.17.0

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
@@ -112,7 +112,7 @@ class PolyfillTextEncoderStream {
112
112
  });
113
113
  }
114
114
 
115
- // node_modules/rambda/dist/rambda.js
115
+ // node_modules/sflow/node_modules/rambda/dist/rambda.js
116
116
  var cloneList = (list) => Array.prototype.slice.call(list);
117
117
  function curry(fn, args = []) {
118
118
  return (..._args) => ((rest) => rest.length >= fn.length ? fn(...rest) : curry(fn, rest))([...args, ..._args]);
@@ -5090,12 +5090,36 @@ class TerminalTextRender {
5090
5090
  import { writeFile } from "fs/promises";
5091
5091
  import path2 from "path";
5092
5092
  import { mkdir } from "fs/promises";
5093
+
5094
+ // ReadyManager.ts
5095
+ class ReadyManager {
5096
+ isReady = false;
5097
+ readyQueue = [];
5098
+ wait() {
5099
+ return new Promise((resolve) => {
5100
+ if (this.isReady)
5101
+ return resolve();
5102
+ this.readyQueue.push(resolve);
5103
+ });
5104
+ }
5105
+ unready() {
5106
+ this.isReady = false;
5107
+ }
5108
+ ready() {
5109
+ this.isReady = true;
5110
+ if (!this.readyQueue.length)
5111
+ return;
5112
+ this.readyQueue.splice(0).map((resolve) => resolve());
5113
+ }
5114
+ }
5115
+
5116
+ // index.ts
5093
5117
  async function claudeYes({
5094
5118
  claudeArgs = [],
5095
5119
  continueOnCrash,
5096
- cwd = process.cwd(),
5097
- env = process.env,
5098
- exitOnIdle,
5120
+ cwd,
5121
+ env,
5122
+ exitOnIdle = 60000,
5099
5123
  logFile,
5100
5124
  removeControlCharactersFromStdout = false,
5101
5125
  verbose = false
@@ -5117,52 +5141,47 @@ async function claudeYes({
5117
5141
  const prefix = "";
5118
5142
  const PREFIXLENGTH = prefix.length;
5119
5143
  let errorNoConversation = false;
5144
+ const shellReady = new ReadyManager;
5120
5145
  const shellOutputStream = new TransformStream;
5121
5146
  const outputWriter = shellOutputStream.writable.getWriter();
5122
5147
  const pty = process.versions.bun ? await import("bun-pty") : await import("node-pty");
5123
- let shell = pty.spawn("claude", claudeArgs, {
5148
+ const getPtyOptions = () => ({
5124
5149
  name: "xterm-color",
5125
5150
  cols: process.stdout.columns - PREFIXLENGTH,
5126
5151
  rows: process.stdout.rows,
5127
- cwd,
5128
- env
5152
+ cwd: cwd ?? process.cwd(),
5153
+ env: env ?? process.env
5129
5154
  });
5155
+ let shell = pty.spawn("claude", claudeArgs, getPtyOptions());
5130
5156
  let pendingExitCode = Promise.withResolvers();
5157
+ let pendingExitCodeValue = null;
5131
5158
  async function onData(data) {
5132
5159
  await outputWriter.write(data);
5160
+ shellReady.ready();
5133
5161
  }
5134
5162
  shell.onData(onData);
5135
5163
  shell.onExit(function onExit({ exitCode: exitCode2 }) {
5136
- if (continueOnCrash && exitCode2 !== 0) {
5164
+ shellReady.unready();
5165
+ const claudeCrashed = exitCode2 !== 0;
5166
+ if (claudeCrashed && continueOnCrash) {
5137
5167
  if (errorNoConversation) {
5138
5168
  console.log('Claude crashed with "No conversation found to continue", exiting...');
5139
- return pendingExitCode.resolve(exitCode2);
5169
+ return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
5140
5170
  }
5141
5171
  console.log("Claude crashed, restarting...");
5142
- shell = pty.spawn("claude", ["--continue", "continue"], {
5143
- name: "xterm-color",
5144
- cols: process.stdout.columns - PREFIXLENGTH,
5145
- rows: process.stdout.rows,
5146
- cwd,
5147
- env
5148
- });
5172
+ shell = pty.spawn("claude", ["--continue", "continue"], getPtyOptions());
5149
5173
  shell.onData(onData);
5150
5174
  shell.onExit(onExit);
5151
5175
  return;
5152
5176
  }
5153
- return pendingExitCode.resolve(exitCode2);
5177
+ return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
5154
5178
  });
5155
5179
  const exitClaudeCode = async () => {
5156
- await src_default(["\r", "/exit", "\r"]).forEach(async (e) => {
5157
- await sleepms(200);
5158
- shell.write(e);
5159
- }).run();
5180
+ continueOnCrash = false;
5181
+ await src_default(["\r", "/exit", "\r"]).forEach(async () => await sleepms(200)).forEach(async (e) => shell.write(e)).run();
5160
5182
  let exited = false;
5161
5183
  await Promise.race([
5162
- new Promise((resolve) => shell.onExit(() => {
5163
- resolve();
5164
- exited = true;
5165
- })),
5184
+ pendingExitCode.promise.then(() => exited = true),
5166
5185
  new Promise((resolve) => setTimeout(() => {
5167
5186
  if (exited)
5168
5187
  return;
@@ -5175,16 +5194,9 @@ async function claudeYes({
5175
5194
  const { columns, rows } = process.stdout;
5176
5195
  shell.resize(columns - PREFIXLENGTH, rows);
5177
5196
  });
5178
- const shellStdio = {
5179
- writable: new WritableStream({
5180
- write: (data) => shell.write(data),
5181
- close: () => {}
5182
- }),
5183
- readable: shellOutputStream.readable
5184
- };
5185
- const ttr = new TerminalTextRender;
5197
+ const render = new TerminalTextRender;
5186
5198
  const idleWatcher = !exitOnIdle ? null : createIdleWatcher(async () => {
5187
- if (ttr.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/)) {
5199
+ if (render.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/)) {
5188
5200
  console.log("[claude-yes] Claude is idle, but seems still working, not exiting yet");
5189
5201
  } else {
5190
5202
  console.log("[claude-yes] Claude is idle, exiting...");
@@ -5195,7 +5207,15 @@ async function claudeYes({
5195
5207
  await sleepms(200);
5196
5208
  shell.write("\r");
5197
5209
  };
5198
- src_default(fromReadable(process.stdin)).map((buffer2) => buffer2.toString()).by(shellStdio).forEach((text) => ttr.write(text)).forEach(() => idleWatcher?.ping()).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach(async (e2) => {
5210
+ src_default(fromReadable(process.stdin)).map((buffer2) => buffer2.toString()).by({
5211
+ writable: new WritableStream({
5212
+ write: async (data) => {
5213
+ await shellReady.wait();
5214
+ shell.write(data);
5215
+ }
5216
+ }),
5217
+ readable: shellOutputStream.readable
5218
+ }).forEach((text) => render.write(text)).forEach(() => idleWatcher?.ping()).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach(async (e2) => {
5199
5219
  if (e2.match(/❯ 1. Yes/))
5200
5220
  return await confirm();
5201
5221
  if (e2.match(/❯ 1. Dark mode✔|Press Enter to continue…/))
@@ -5206,19 +5226,19 @@ async function claudeYes({
5206
5226
  }
5207
5227
  }).run()).replaceAll(/.*(?:\r\n?|\r?\n)/g, (line) => prefix + line).map((e) => removeControlCharactersFromStdout ? removeControlCharacters(e) : e).to(fromWritable(process.stdout));
5208
5228
  const exitCode = await pendingExitCode.promise;
5209
- verbose && console.log(`[claude-yes] claude exited with code ${exitCode}`);
5229
+ console.log(`[claude-yes] claude exited with code ${exitCode}`);
5210
5230
  if (logFile) {
5211
5231
  verbose && console.log(`[claude-yes] Writing rendered logs to ${logFile}`);
5212
5232
  const logFilePath = path2.resolve(logFile);
5213
5233
  await mkdir(path2.dirname(logFilePath), { recursive: true }).catch(() => null);
5214
- await writeFile(logFilePath, ttr.render());
5234
+ await writeFile(logFilePath, render.render());
5215
5235
  }
5216
- return { exitCode, logs: ttr.render() };
5236
+ return { exitCode, logs: render.render() };
5217
5237
  }
5218
5238
  export {
5219
5239
  removeControlCharacters,
5220
5240
  claudeYes as default
5221
5241
  };
5222
5242
 
5223
- //# debugId=3F612601EADFF57764756E2164756E21
5243
+ //# debugId=9DCC732BF3D33A1E64756E2164756E21
5224
5244
  //# sourceMappingURL=index.js.map