claude-yes 1.14.0 → 1.14.2
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/cli.js +3 -3
- package/dist/index.js +3 -3
- package/index.ts +36 -29
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5390,10 +5390,10 @@ async function claudeYes({
|
|
|
5390
5390
|
const ttr = new TerminalTextRender;
|
|
5391
5391
|
const idleWatcher = createIdleWatcher(async () => {
|
|
5392
5392
|
if (exitOnIdle) {
|
|
5393
|
-
if (ttr.render().
|
|
5394
|
-
console.
|
|
5393
|
+
if (ttr.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/)) {
|
|
5394
|
+
console.warn("[CLAUDE-YES] Claude is idle, but seems still working, not exiting yet");
|
|
5395
5395
|
} else {
|
|
5396
|
-
console.
|
|
5396
|
+
console.warn("[CLAUDE-YES] Claude is idle, exiting...");
|
|
5397
5397
|
await exitClaudeCode();
|
|
5398
5398
|
}
|
|
5399
5399
|
}
|
package/dist/index.js
CHANGED
|
@@ -5170,10 +5170,10 @@ async function claudeYes({
|
|
|
5170
5170
|
const ttr = new TerminalTextRender;
|
|
5171
5171
|
const idleWatcher = createIdleWatcher(async () => {
|
|
5172
5172
|
if (exitOnIdle) {
|
|
5173
|
-
if (ttr.render().
|
|
5174
|
-
console.
|
|
5173
|
+
if (ttr.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/)) {
|
|
5174
|
+
console.warn("[CLAUDE-YES] Claude is idle, but seems still working, not exiting yet");
|
|
5175
5175
|
} else {
|
|
5176
|
-
console.
|
|
5176
|
+
console.warn("[CLAUDE-YES] Claude is idle, exiting...");
|
|
5177
5177
|
await exitClaudeCode();
|
|
5178
5178
|
}
|
|
5179
5179
|
}
|
package/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { fromReadable, fromWritable } from
|
|
2
|
-
import sflow from
|
|
3
|
-
import { createIdleWatcher } from
|
|
4
|
-
import { removeControlCharacters } from
|
|
5
|
-
import { sleepms } from
|
|
6
|
-
import { TerminalTextRender } from
|
|
1
|
+
import { fromReadable, fromWritable } from 'from-node-stream';
|
|
2
|
+
import sflow from 'sflow';
|
|
3
|
+
import { createIdleWatcher } from './createIdleWatcher';
|
|
4
|
+
import { removeControlCharacters } from './removeControlCharacters';
|
|
5
|
+
import { sleepms } from './utils';
|
|
6
|
+
import { TerminalTextRender } from 'terminal-render';
|
|
7
7
|
// for debug only
|
|
8
8
|
// if (import.meta.main) await main();
|
|
9
9
|
// async function main() {
|
|
@@ -42,27 +42,27 @@ export default async function claudeYes({
|
|
|
42
42
|
} = {}) {
|
|
43
43
|
const defaultTimeout = 5e3; // 5 seconds idle timeout
|
|
44
44
|
const idleTimeout =
|
|
45
|
-
typeof exitOnIdle ===
|
|
45
|
+
typeof exitOnIdle === 'number' ? exitOnIdle : defaultTimeout;
|
|
46
46
|
|
|
47
47
|
console.log(
|
|
48
|
-
|
|
48
|
+
'⭐ Starting claude, automatically responding to yes/no prompts...'
|
|
49
49
|
);
|
|
50
50
|
console.log(
|
|
51
|
-
|
|
51
|
+
'⚠️ Important Security Warning: Only run this on trusted repositories. This tool automatically responds to prompts and can execute commands without user confirmation. Be aware of potential prompt injection attacks where malicious code or instructions could be embedded in files or user inputs to manipulate the automated responses.'
|
|
52
52
|
);
|
|
53
53
|
|
|
54
54
|
process.stdin.setRawMode?.(true); //must be called any stdout/stdin usage
|
|
55
|
-
const prefix =
|
|
55
|
+
const prefix = ''; // "YESC|"
|
|
56
56
|
const PREFIXLENGTH = prefix.length;
|
|
57
57
|
let errorNoConversation = false; // match 'No conversation found to continue'
|
|
58
58
|
|
|
59
59
|
const shellOutputStream = new TransformStream<string, string>();
|
|
60
60
|
const outputWriter = shellOutputStream.writable.getWriter();
|
|
61
61
|
const pty = globalThis.Bun
|
|
62
|
-
? await import(
|
|
63
|
-
: await import(
|
|
64
|
-
let shell = pty.spawn(
|
|
65
|
-
name:
|
|
62
|
+
? await import('bun-pty')
|
|
63
|
+
: await import('node-pty');
|
|
64
|
+
let shell = pty.spawn('claude', claudeArgs, {
|
|
65
|
+
name: 'xterm-color',
|
|
66
66
|
cols: process.stdout.columns - PREFIXLENGTH,
|
|
67
67
|
rows: process.stdout.rows,
|
|
68
68
|
cwd,
|
|
@@ -81,13 +81,13 @@ export default async function claudeYes({
|
|
|
81
81
|
if (continueOnCrash && exitCode !== 0) {
|
|
82
82
|
if (errorNoConversation) {
|
|
83
83
|
console.log(
|
|
84
|
-
'Claude crashed with "No conversation found to continue", exiting...'
|
|
84
|
+
'Claude crashed with "No conversation found to continue", exiting...'
|
|
85
85
|
);
|
|
86
86
|
void process.exit(exitCode);
|
|
87
87
|
}
|
|
88
|
-
console.log(
|
|
89
|
-
shell = pty.spawn(
|
|
90
|
-
name:
|
|
88
|
+
console.log('Claude crashed, restarting...');
|
|
89
|
+
shell = pty.spawn('claude', ['continue', '--continue'], {
|
|
90
|
+
name: 'xterm-color',
|
|
91
91
|
cols: process.stdout.columns - PREFIXLENGTH,
|
|
92
92
|
rows: process.stdout.rows,
|
|
93
93
|
cwd,
|
|
@@ -102,7 +102,7 @@ export default async function claudeYes({
|
|
|
102
102
|
|
|
103
103
|
const exitClaudeCode = async () => {
|
|
104
104
|
// send exit command to the shell, must sleep a bit to avoid claude treat it as pasted input
|
|
105
|
-
await sflow([
|
|
105
|
+
await sflow(['\r', '/exit', '\r'])
|
|
106
106
|
.forEach(async (e) => {
|
|
107
107
|
await sleepms(200);
|
|
108
108
|
shell.write(e);
|
|
@@ -116,7 +116,7 @@ export default async function claudeYes({
|
|
|
116
116
|
shell.onExit(() => {
|
|
117
117
|
resolve();
|
|
118
118
|
exited = true;
|
|
119
|
-
})
|
|
119
|
+
})
|
|
120
120
|
), // resolve when shell exits
|
|
121
121
|
// if shell doesn't exit in 5 seconds, kill it
|
|
122
122
|
new Promise<void>((resolve) =>
|
|
@@ -124,13 +124,13 @@ export default async function claudeYes({
|
|
|
124
124
|
if (exited) return; // if shell already exited, do nothing
|
|
125
125
|
shell.kill(); // kill the shell process if it doesn't exit in time
|
|
126
126
|
resolve();
|
|
127
|
-
}, 5000)
|
|
127
|
+
}, 5000)
|
|
128
128
|
), // 5 seconds timeout
|
|
129
129
|
]);
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
// when current tty resized, resize the pty
|
|
133
|
-
process.stdout.on(
|
|
133
|
+
process.stdout.on('resize', () => {
|
|
134
134
|
const { columns, rows } = process.stdout;
|
|
135
135
|
shell.resize(columns - PREFIXLENGTH, rows);
|
|
136
136
|
});
|
|
@@ -146,17 +146,24 @@ export default async function claudeYes({
|
|
|
146
146
|
const ttr = new TerminalTextRender();
|
|
147
147
|
const idleWatcher = createIdleWatcher(async () => {
|
|
148
148
|
if (exitOnIdle) {
|
|
149
|
-
if (
|
|
150
|
-
|
|
149
|
+
if (
|
|
150
|
+
ttr
|
|
151
|
+
.render()
|
|
152
|
+
.replace(/\s+/g, ' ')
|
|
153
|
+
.match(/esc to interrupt|to run in background/)
|
|
154
|
+
) {
|
|
155
|
+
console.warn(
|
|
156
|
+
'[CLAUDE-YES] Claude is idle, but seems still working, not exiting yet'
|
|
157
|
+
);
|
|
151
158
|
} else {
|
|
152
|
-
console.
|
|
159
|
+
console.warn('[CLAUDE-YES] Claude is idle, exiting...');
|
|
153
160
|
await exitClaudeCode();
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
}, idleTimeout);
|
|
157
164
|
const confirm = async () => {
|
|
158
165
|
await sleepms(200);
|
|
159
|
-
shell.write(
|
|
166
|
+
shell.write('\r');
|
|
160
167
|
};
|
|
161
168
|
await sflow(fromReadable<Buffer>(process.stdin))
|
|
162
169
|
.forEach(() => idleWatcher.ping()) // ping the idle watcher on output for last active time to keep track of claude status
|
|
@@ -167,7 +174,7 @@ export default async function claudeYes({
|
|
|
167
174
|
.forkTo((e) =>
|
|
168
175
|
e
|
|
169
176
|
.map((e) => removeControlCharacters(e as string))
|
|
170
|
-
.map((e) => e.replaceAll(
|
|
177
|
+
.map((e) => e.replaceAll('\r', '')) // remove carriage return
|
|
171
178
|
.forEach(async (e) => {
|
|
172
179
|
if (e.match(/❯ 1. Yes/)) return await confirm();
|
|
173
180
|
if (e.match(/❯ 1. Dark mode✔|Press Enter to continue…/))
|
|
@@ -179,11 +186,11 @@ export default async function claudeYes({
|
|
|
179
186
|
})
|
|
180
187
|
|
|
181
188
|
// .forEach(e => appendFile('.cache/io.log', "output|" + JSON.stringify(e) + '\n')) // for debugging
|
|
182
|
-
.run()
|
|
189
|
+
.run()
|
|
183
190
|
)
|
|
184
191
|
.replaceAll(/.*(?:\r\n?|\r?\n)/g, (line) => prefix + line) // add prefix
|
|
185
192
|
.map((e) =>
|
|
186
|
-
removeControlCharactersFromStdout ? removeControlCharacters(e) : e
|
|
193
|
+
removeControlCharactersFromStdout ? removeControlCharacters(e) : e
|
|
187
194
|
)
|
|
188
195
|
.to(fromWritable(process.stdout));
|
|
189
196
|
|