claude-yes 1.14.0 → 1.14.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/dist/cli.js +3 -3
- package/dist/index.js +3 -3
- package/index.ts +31 -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().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().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,19 @@ export default async function claudeYes({
|
|
|
146
146
|
const ttr = new TerminalTextRender();
|
|
147
147
|
const idleWatcher = createIdleWatcher(async () => {
|
|
148
148
|
if (exitOnIdle) {
|
|
149
|
-
if (ttr.render().
|
|
150
|
-
console.
|
|
149
|
+
if (ttr.render().match(/esc to interrupt|to run in background/)) {
|
|
150
|
+
console.warn(
|
|
151
|
+
'[CLAUDE-YES] Claude is idle, but seems still working, not exiting yet'
|
|
152
|
+
);
|
|
151
153
|
} else {
|
|
152
|
-
console.
|
|
154
|
+
console.warn('[CLAUDE-YES] Claude is idle, exiting...');
|
|
153
155
|
await exitClaudeCode();
|
|
154
156
|
}
|
|
155
157
|
}
|
|
156
158
|
}, idleTimeout);
|
|
157
159
|
const confirm = async () => {
|
|
158
160
|
await sleepms(200);
|
|
159
|
-
shell.write(
|
|
161
|
+
shell.write('\r');
|
|
160
162
|
};
|
|
161
163
|
await sflow(fromReadable<Buffer>(process.stdin))
|
|
162
164
|
.forEach(() => idleWatcher.ping()) // ping the idle watcher on output for last active time to keep track of claude status
|
|
@@ -167,7 +169,7 @@ export default async function claudeYes({
|
|
|
167
169
|
.forkTo((e) =>
|
|
168
170
|
e
|
|
169
171
|
.map((e) => removeControlCharacters(e as string))
|
|
170
|
-
.map((e) => e.replaceAll(
|
|
172
|
+
.map((e) => e.replaceAll('\r', '')) // remove carriage return
|
|
171
173
|
.forEach(async (e) => {
|
|
172
174
|
if (e.match(/❯ 1. Yes/)) return await confirm();
|
|
173
175
|
if (e.match(/❯ 1. Dark mode✔|Press Enter to continue…/))
|
|
@@ -179,11 +181,11 @@ export default async function claudeYes({
|
|
|
179
181
|
})
|
|
180
182
|
|
|
181
183
|
// .forEach(e => appendFile('.cache/io.log', "output|" + JSON.stringify(e) + '\n')) // for debugging
|
|
182
|
-
.run()
|
|
184
|
+
.run()
|
|
183
185
|
)
|
|
184
186
|
.replaceAll(/.*(?:\r\n?|\r?\n)/g, (line) => prefix + line) // add prefix
|
|
185
187
|
.map((e) =>
|
|
186
|
-
removeControlCharactersFromStdout ? removeControlCharacters(e) : e
|
|
188
|
+
removeControlCharactersFromStdout ? removeControlCharacters(e) : e
|
|
187
189
|
)
|
|
188
190
|
.to(fromWritable(process.stdout));
|
|
189
191
|
|