claude-yes 1.16.1 → 1.17.1
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/README.md +5 -1
- package/ReadyManager.ts +18 -0
- package/cli.ts +2 -1
- package/dist/cli.js +65 -41
- package/dist/cli.js.map +6 -5
- package/dist/index.js +64 -40
- package/dist/index.js.map +5 -4
- package/index.ts +48 -45
- package/package.json +12 -11
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
|
|
5097
|
-
env
|
|
5098
|
-
exitOnIdle,
|
|
5120
|
+
cwd,
|
|
5121
|
+
env,
|
|
5122
|
+
exitOnIdle = 60000,
|
|
5099
5123
|
logFile,
|
|
5100
5124
|
removeControlCharactersFromStdout = false,
|
|
5101
5125
|
verbose = false
|
|
@@ -5117,52 +5141,51 @@ 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
|
-
const pty = process.versions.bun ? await import("bun-pty")
|
|
5123
|
-
|
|
5147
|
+
const pty = process.versions.bun ? await import("bun-pty").catch(() => {
|
|
5148
|
+
throw new Error("Please install bun-pty");
|
|
5149
|
+
}) : await import("node-pty").catch(() => {
|
|
5150
|
+
throw new Error("Please install node-pty");
|
|
5151
|
+
});
|
|
5152
|
+
const getPtyOptions = () => ({
|
|
5124
5153
|
name: "xterm-color",
|
|
5125
5154
|
cols: process.stdout.columns - PREFIXLENGTH,
|
|
5126
5155
|
rows: process.stdout.rows,
|
|
5127
|
-
cwd,
|
|
5128
|
-
env
|
|
5156
|
+
cwd: cwd ?? process.cwd(),
|
|
5157
|
+
env: env ?? process.env
|
|
5129
5158
|
});
|
|
5159
|
+
let shell = pty.spawn("claude", claudeArgs, getPtyOptions());
|
|
5130
5160
|
let pendingExitCode = Promise.withResolvers();
|
|
5161
|
+
let pendingExitCodeValue = null;
|
|
5131
5162
|
async function onData(data) {
|
|
5132
5163
|
await outputWriter.write(data);
|
|
5164
|
+
shellReady.ready();
|
|
5133
5165
|
}
|
|
5134
5166
|
shell.onData(onData);
|
|
5135
5167
|
shell.onExit(function onExit({ exitCode: exitCode2 }) {
|
|
5136
|
-
|
|
5168
|
+
shellReady.unready();
|
|
5169
|
+
const claudeCrashed = exitCode2 !== 0;
|
|
5170
|
+
if (claudeCrashed && continueOnCrash) {
|
|
5137
5171
|
if (errorNoConversation) {
|
|
5138
5172
|
console.log('Claude crashed with "No conversation found to continue", exiting...');
|
|
5139
|
-
return pendingExitCode.resolve(exitCode2);
|
|
5173
|
+
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
5140
5174
|
}
|
|
5141
5175
|
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
|
-
});
|
|
5176
|
+
shell = pty.spawn("claude", ["--continue", "continue"], getPtyOptions());
|
|
5149
5177
|
shell.onData(onData);
|
|
5150
5178
|
shell.onExit(onExit);
|
|
5151
5179
|
return;
|
|
5152
5180
|
}
|
|
5153
|
-
return pendingExitCode.resolve(exitCode2);
|
|
5181
|
+
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
5154
5182
|
});
|
|
5155
5183
|
const exitClaudeCode = async () => {
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
shell.write(e);
|
|
5159
|
-
}).run();
|
|
5184
|
+
continueOnCrash = false;
|
|
5185
|
+
await src_default(["\r", "/exit", "\r"]).forEach(async () => await sleepms(200)).forEach(async (e) => shell.write(e)).run();
|
|
5160
5186
|
let exited = false;
|
|
5161
5187
|
await Promise.race([
|
|
5162
|
-
|
|
5163
|
-
resolve();
|
|
5164
|
-
exited = true;
|
|
5165
|
-
})),
|
|
5188
|
+
pendingExitCode.promise.then(() => exited = true),
|
|
5166
5189
|
new Promise((resolve) => setTimeout(() => {
|
|
5167
5190
|
if (exited)
|
|
5168
5191
|
return;
|
|
@@ -5175,16 +5198,9 @@ async function claudeYes({
|
|
|
5175
5198
|
const { columns, rows } = process.stdout;
|
|
5176
5199
|
shell.resize(columns - PREFIXLENGTH, rows);
|
|
5177
5200
|
});
|
|
5178
|
-
const
|
|
5179
|
-
writable: new WritableStream({
|
|
5180
|
-
write: (data) => shell.write(data),
|
|
5181
|
-
close: () => {}
|
|
5182
|
-
}),
|
|
5183
|
-
readable: shellOutputStream.readable
|
|
5184
|
-
};
|
|
5185
|
-
const ttr = new TerminalTextRender;
|
|
5201
|
+
const render = new TerminalTextRender;
|
|
5186
5202
|
const idleWatcher = !exitOnIdle ? null : createIdleWatcher(async () => {
|
|
5187
|
-
if (
|
|
5203
|
+
if (render.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/)) {
|
|
5188
5204
|
console.log("[claude-yes] Claude is idle, but seems still working, not exiting yet");
|
|
5189
5205
|
} else {
|
|
5190
5206
|
console.log("[claude-yes] Claude is idle, exiting...");
|
|
@@ -5195,7 +5211,15 @@ async function claudeYes({
|
|
|
5195
5211
|
await sleepms(200);
|
|
5196
5212
|
shell.write("\r");
|
|
5197
5213
|
};
|
|
5198
|
-
src_default(fromReadable(process.stdin)).map((buffer2) => buffer2.toString()).by(
|
|
5214
|
+
src_default(fromReadable(process.stdin)).map((buffer2) => buffer2.toString()).by({
|
|
5215
|
+
writable: new WritableStream({
|
|
5216
|
+
write: async (data) => {
|
|
5217
|
+
await shellReady.wait();
|
|
5218
|
+
shell.write(data);
|
|
5219
|
+
}
|
|
5220
|
+
}),
|
|
5221
|
+
readable: shellOutputStream.readable
|
|
5222
|
+
}).forEach((text) => render.write(text)).forEach(() => idleWatcher?.ping()).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach(async (e2) => {
|
|
5199
5223
|
if (e2.match(/❯ 1. Yes/))
|
|
5200
5224
|
return await confirm();
|
|
5201
5225
|
if (e2.match(/❯ 1. Dark mode✔|Press Enter to continue…/))
|
|
@@ -5206,19 +5230,19 @@ async function claudeYes({
|
|
|
5206
5230
|
}
|
|
5207
5231
|
}).run()).replaceAll(/.*(?:\r\n?|\r?\n)/g, (line) => prefix + line).map((e) => removeControlCharactersFromStdout ? removeControlCharacters(e) : e).to(fromWritable(process.stdout));
|
|
5208
5232
|
const exitCode = await pendingExitCode.promise;
|
|
5209
|
-
|
|
5233
|
+
console.log(`[claude-yes] claude exited with code ${exitCode}`);
|
|
5210
5234
|
if (logFile) {
|
|
5211
5235
|
verbose && console.log(`[claude-yes] Writing rendered logs to ${logFile}`);
|
|
5212
5236
|
const logFilePath = path2.resolve(logFile);
|
|
5213
5237
|
await mkdir(path2.dirname(logFilePath), { recursive: true }).catch(() => null);
|
|
5214
|
-
await writeFile(logFilePath,
|
|
5238
|
+
await writeFile(logFilePath, render.render());
|
|
5215
5239
|
}
|
|
5216
|
-
return { exitCode, logs:
|
|
5240
|
+
return { exitCode, logs: render.render() };
|
|
5217
5241
|
}
|
|
5218
5242
|
export {
|
|
5219
5243
|
removeControlCharacters,
|
|
5220
5244
|
claudeYes as default
|
|
5221
5245
|
};
|
|
5222
5246
|
|
|
5223
|
-
//# debugId=
|
|
5247
|
+
//# debugId=D57ADA4381F993DD64756E2164756E21
|
|
5224
5248
|
//# sourceMappingURL=index.js.map
|