claude-yes 1.21.0 → 1.22.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/README.md +26 -0
- package/dist/claude-yes.js +23 -19
- package/dist/cli.js +23 -19
- package/dist/cli.js.map +3 -3
- package/dist/codex-yes.js +23 -19
- package/dist/copilot-yes.js +23 -19
- package/dist/cursor-yes.js +23 -19
- package/dist/gemini-yes.js +23 -19
- package/dist/grok-yes.js +342 -0
- package/dist/index.js +23 -19
- package/dist/index.js.map +3 -3
- package/index.ts +39 -36
- package/package.json +14 -13
- package/postbuild.ts +10 -1
package/dist/cursor-yes.js
CHANGED
|
@@ -25,7 +25,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
25
25
|
|
|
26
26
|
// dist/index.js
|
|
27
27
|
import { fromReadable, fromWritable } from "from-node-stream";
|
|
28
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
28
|
+
import { appendFile, mkdir, writeFile } from "fs/promises";
|
|
29
29
|
import path from "path";
|
|
30
30
|
import DIE from "phpdie";
|
|
31
31
|
import sflow from "sflow";
|
|
@@ -70,7 +70,8 @@ function removeControlCharacters(str) {
|
|
|
70
70
|
var CLI_CONFIGURES = {
|
|
71
71
|
grok: {
|
|
72
72
|
install: "npm install -g @vibe-kit/grok-cli",
|
|
73
|
-
ready: [/^
|
|
73
|
+
ready: [/^ │ ❯ /],
|
|
74
|
+
enter: [/^ 1. Yes/]
|
|
74
75
|
},
|
|
75
76
|
claude: {
|
|
76
77
|
install: "npm install -g @anthropic-ai/claude-code",
|
|
@@ -78,7 +79,7 @@ var CLI_CONFIGURES = {
|
|
|
78
79
|
enter: [/❯ 1. Yes/, /❯ 1. Dark mode✔/, /Press Enter to continue…/],
|
|
79
80
|
fatal: [
|
|
80
81
|
/No conversation found to continue/,
|
|
81
|
-
/⎿
|
|
82
|
+
/⎿ Claude usage limit reached\./
|
|
82
83
|
]
|
|
83
84
|
},
|
|
84
85
|
gemini: {
|
|
@@ -90,7 +91,10 @@ var CLI_CONFIGURES = {
|
|
|
90
91
|
codex: {
|
|
91
92
|
install: "npm install -g @openai/codex-cli",
|
|
92
93
|
ready: [/⏎ send/],
|
|
93
|
-
enter: [
|
|
94
|
+
enter: [
|
|
95
|
+
/\b▌ \> 1\. Approve and run now/,
|
|
96
|
+
/\b\> 1\. Yes, allow Codex to work in this folder/
|
|
97
|
+
],
|
|
94
98
|
fatal: [/Error: The cursor position could not be read within/],
|
|
95
99
|
ensureArgs: (args) => {
|
|
96
100
|
if (!args.includes("--search"))
|
|
@@ -109,7 +113,7 @@ var CLI_CONFIGURES = {
|
|
|
109
113
|
binary: "cursor-agent",
|
|
110
114
|
ready: [/\/ commands/],
|
|
111
115
|
enter: [/→ Run \(once\) \(y\) \(enter\)/, /▶ \[a\] Trust this workspace/],
|
|
112
|
-
fatal: []
|
|
116
|
+
fatal: [/^ Error: You've hit your usage limit/]
|
|
113
117
|
}
|
|
114
118
|
};
|
|
115
119
|
async function claudeYes({
|
|
@@ -165,7 +169,6 @@ async function claudeYes({
|
|
|
165
169
|
return console.warn(`continueOnCrash is only supported for ${Object.keys(continueArgs).join(", ")} currently, not ${cli}`);
|
|
166
170
|
}
|
|
167
171
|
if (isFatal) {
|
|
168
|
-
console.log(`${cli} crashed with "No conversation found to continue", exiting...`);
|
|
169
172
|
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
170
173
|
}
|
|
171
174
|
console.log(`${cli} crashed, restarting...`);
|
|
@@ -192,6 +195,8 @@ async function claudeYes({
|
|
|
192
195
|
console.log("[${cli}-yes] ${cli} is idle, exiting...");
|
|
193
196
|
await exitAgent();
|
|
194
197
|
});
|
|
198
|
+
console.log(`[${cli}-yes] Started ${cli} with args: ${[cliCommand, ...cliArgs].join(" ")}`);
|
|
199
|
+
shell.write("\x1B[1;1R");
|
|
195
200
|
sflow(fromReadable(process.stdin)).map((buffer) => buffer.toString()).by({
|
|
196
201
|
writable: new WritableStream({
|
|
197
202
|
write: async (data) => {
|
|
@@ -206,13 +211,11 @@ async function claudeYes({
|
|
|
206
211
|
return;
|
|
207
212
|
if (text.includes("\x1B[6n"))
|
|
208
213
|
return;
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
`).length + 1;
|
|
212
|
-
const col = (rendered.split(`
|
|
213
|
-
`).slice(-1)[0]?.length || 0) + 1;
|
|
214
|
+
const { col, row } = terminalRender.getCursorPosition();
|
|
215
|
+
console.log(`[${cli}-yes] Responding cursor position: row=${row}, col=${col}`);
|
|
214
216
|
shell.write(`\x1B[${row};${col}R`);
|
|
215
|
-
}).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).
|
|
217
|
+
}).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach((e2) => appendFile("io.log", "output|" + JSON.stringify(e2) + `
|
|
218
|
+
`)).forEach(async (e2, i) => {
|
|
216
219
|
const conf = CLI_CONFIGURES[cli] || null;
|
|
217
220
|
if (!conf)
|
|
218
221
|
return;
|
|
@@ -221,15 +224,16 @@ async function claudeYes({
|
|
|
221
224
|
return;
|
|
222
225
|
stdinReady.ready();
|
|
223
226
|
}
|
|
224
|
-
if (conf.enter?.some((rx) => e2.match(rx)))
|
|
227
|
+
if (conf.enter?.some((rx) => e2.match(rx))) {
|
|
225
228
|
await sendEnter(300);
|
|
226
|
-
|
|
229
|
+
}
|
|
230
|
+
if (conf.fatal?.some((rx) => e2.match(rx))) {
|
|
227
231
|
isFatal = true;
|
|
232
|
+
await exitAgent();
|
|
233
|
+
}
|
|
228
234
|
}).run()).map((e) => removeControlCharactersFromStdout ? removeControlCharacters(e) : e).to(fromWritable(process.stdout)).then(() => null);
|
|
229
235
|
if (prompt)
|
|
230
|
-
|
|
231
|
-
await sendMessage(prompt);
|
|
232
|
-
})();
|
|
236
|
+
await sendMessage(prompt);
|
|
233
237
|
const exitCode = await pendingExitCode.promise;
|
|
234
238
|
console.log(`[${cli}-yes] ${cli} exited with code ${exitCode}`);
|
|
235
239
|
if (logFile) {
|
|
@@ -268,7 +272,7 @@ async function claudeYes({
|
|
|
268
272
|
}
|
|
269
273
|
function getTerminalDimensions() {
|
|
270
274
|
return {
|
|
271
|
-
cols:
|
|
275
|
+
cols: process.stdout.columns,
|
|
272
276
|
rows: process.stdout.rows
|
|
273
277
|
};
|
|
274
278
|
}
|
|
@@ -334,5 +338,5 @@ var { exitCode, logs } = await claudeYes({
|
|
|
334
338
|
});
|
|
335
339
|
process.exit(exitCode ?? 1);
|
|
336
340
|
|
|
337
|
-
//# debugId=
|
|
341
|
+
//# debugId=F98366DB626CC88164756E2164756E21
|
|
338
342
|
//# sourceMappingURL=cli.js.map
|
package/dist/gemini-yes.js
CHANGED
|
@@ -25,7 +25,7 @@ import { hideBin } from "yargs/helpers";
|
|
|
25
25
|
|
|
26
26
|
// dist/index.js
|
|
27
27
|
import { fromReadable, fromWritable } from "from-node-stream";
|
|
28
|
-
import { mkdir, writeFile } from "fs/promises";
|
|
28
|
+
import { appendFile, mkdir, writeFile } from "fs/promises";
|
|
29
29
|
import path from "path";
|
|
30
30
|
import DIE from "phpdie";
|
|
31
31
|
import sflow from "sflow";
|
|
@@ -70,7 +70,8 @@ function removeControlCharacters(str) {
|
|
|
70
70
|
var CLI_CONFIGURES = {
|
|
71
71
|
grok: {
|
|
72
72
|
install: "npm install -g @vibe-kit/grok-cli",
|
|
73
|
-
ready: [/^
|
|
73
|
+
ready: [/^ │ ❯ /],
|
|
74
|
+
enter: [/^ 1. Yes/]
|
|
74
75
|
},
|
|
75
76
|
claude: {
|
|
76
77
|
install: "npm install -g @anthropic-ai/claude-code",
|
|
@@ -78,7 +79,7 @@ var CLI_CONFIGURES = {
|
|
|
78
79
|
enter: [/❯ 1. Yes/, /❯ 1. Dark mode✔/, /Press Enter to continue…/],
|
|
79
80
|
fatal: [
|
|
80
81
|
/No conversation found to continue/,
|
|
81
|
-
/⎿
|
|
82
|
+
/⎿ Claude usage limit reached\./
|
|
82
83
|
]
|
|
83
84
|
},
|
|
84
85
|
gemini: {
|
|
@@ -90,7 +91,10 @@ var CLI_CONFIGURES = {
|
|
|
90
91
|
codex: {
|
|
91
92
|
install: "npm install -g @openai/codex-cli",
|
|
92
93
|
ready: [/⏎ send/],
|
|
93
|
-
enter: [
|
|
94
|
+
enter: [
|
|
95
|
+
/\b▌ \> 1\. Approve and run now/,
|
|
96
|
+
/\b\> 1\. Yes, allow Codex to work in this folder/
|
|
97
|
+
],
|
|
94
98
|
fatal: [/Error: The cursor position could not be read within/],
|
|
95
99
|
ensureArgs: (args) => {
|
|
96
100
|
if (!args.includes("--search"))
|
|
@@ -109,7 +113,7 @@ var CLI_CONFIGURES = {
|
|
|
109
113
|
binary: "cursor-agent",
|
|
110
114
|
ready: [/\/ commands/],
|
|
111
115
|
enter: [/→ Run \(once\) \(y\) \(enter\)/, /▶ \[a\] Trust this workspace/],
|
|
112
|
-
fatal: []
|
|
116
|
+
fatal: [/^ Error: You've hit your usage limit/]
|
|
113
117
|
}
|
|
114
118
|
};
|
|
115
119
|
async function claudeYes({
|
|
@@ -165,7 +169,6 @@ async function claudeYes({
|
|
|
165
169
|
return console.warn(`continueOnCrash is only supported for ${Object.keys(continueArgs).join(", ")} currently, not ${cli}`);
|
|
166
170
|
}
|
|
167
171
|
if (isFatal) {
|
|
168
|
-
console.log(`${cli} crashed with "No conversation found to continue", exiting...`);
|
|
169
172
|
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
170
173
|
}
|
|
171
174
|
console.log(`${cli} crashed, restarting...`);
|
|
@@ -192,6 +195,8 @@ async function claudeYes({
|
|
|
192
195
|
console.log("[${cli}-yes] ${cli} is idle, exiting...");
|
|
193
196
|
await exitAgent();
|
|
194
197
|
});
|
|
198
|
+
console.log(`[${cli}-yes] Started ${cli} with args: ${[cliCommand, ...cliArgs].join(" ")}`);
|
|
199
|
+
shell.write("\x1B[1;1R");
|
|
195
200
|
sflow(fromReadable(process.stdin)).map((buffer) => buffer.toString()).by({
|
|
196
201
|
writable: new WritableStream({
|
|
197
202
|
write: async (data) => {
|
|
@@ -206,13 +211,11 @@ async function claudeYes({
|
|
|
206
211
|
return;
|
|
207
212
|
if (text.includes("\x1B[6n"))
|
|
208
213
|
return;
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
`).length + 1;
|
|
212
|
-
const col = (rendered.split(`
|
|
213
|
-
`).slice(-1)[0]?.length || 0) + 1;
|
|
214
|
+
const { col, row } = terminalRender.getCursorPosition();
|
|
215
|
+
console.log(`[${cli}-yes] Responding cursor position: row=${row}, col=${col}`);
|
|
214
216
|
shell.write(`\x1B[${row};${col}R`);
|
|
215
|
-
}).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).
|
|
217
|
+
}).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach((e2) => appendFile("io.log", "output|" + JSON.stringify(e2) + `
|
|
218
|
+
`)).forEach(async (e2, i) => {
|
|
216
219
|
const conf = CLI_CONFIGURES[cli] || null;
|
|
217
220
|
if (!conf)
|
|
218
221
|
return;
|
|
@@ -221,15 +224,16 @@ async function claudeYes({
|
|
|
221
224
|
return;
|
|
222
225
|
stdinReady.ready();
|
|
223
226
|
}
|
|
224
|
-
if (conf.enter?.some((rx) => e2.match(rx)))
|
|
227
|
+
if (conf.enter?.some((rx) => e2.match(rx))) {
|
|
225
228
|
await sendEnter(300);
|
|
226
|
-
|
|
229
|
+
}
|
|
230
|
+
if (conf.fatal?.some((rx) => e2.match(rx))) {
|
|
227
231
|
isFatal = true;
|
|
232
|
+
await exitAgent();
|
|
233
|
+
}
|
|
228
234
|
}).run()).map((e) => removeControlCharactersFromStdout ? removeControlCharacters(e) : e).to(fromWritable(process.stdout)).then(() => null);
|
|
229
235
|
if (prompt)
|
|
230
|
-
|
|
231
|
-
await sendMessage(prompt);
|
|
232
|
-
})();
|
|
236
|
+
await sendMessage(prompt);
|
|
233
237
|
const exitCode = await pendingExitCode.promise;
|
|
234
238
|
console.log(`[${cli}-yes] ${cli} exited with code ${exitCode}`);
|
|
235
239
|
if (logFile) {
|
|
@@ -268,7 +272,7 @@ async function claudeYes({
|
|
|
268
272
|
}
|
|
269
273
|
function getTerminalDimensions() {
|
|
270
274
|
return {
|
|
271
|
-
cols:
|
|
275
|
+
cols: process.stdout.columns,
|
|
272
276
|
rows: process.stdout.rows
|
|
273
277
|
};
|
|
274
278
|
}
|
|
@@ -334,5 +338,5 @@ var { exitCode, logs } = await claudeYes({
|
|
|
334
338
|
});
|
|
335
339
|
process.exit(exitCode ?? 1);
|
|
336
340
|
|
|
337
|
-
//# debugId=
|
|
341
|
+
//# debugId=F98366DB626CC88164756E2164756E21
|
|
338
342
|
//# sourceMappingURL=cli.js.map
|
package/dist/grok-yes.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
9
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
10
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
11
|
+
for (let key of __getOwnPropNames(mod))
|
|
12
|
+
if (!__hasOwnProp.call(to, key))
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: () => mod[key],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
20
|
+
|
|
21
|
+
// cli.ts
|
|
22
|
+
import enhancedMs from "enhanced-ms";
|
|
23
|
+
import yargs from "yargs";
|
|
24
|
+
import { hideBin } from "yargs/helpers";
|
|
25
|
+
|
|
26
|
+
// dist/index.js
|
|
27
|
+
import { fromReadable, fromWritable } from "from-node-stream";
|
|
28
|
+
import { appendFile, mkdir, writeFile } from "fs/promises";
|
|
29
|
+
import path from "path";
|
|
30
|
+
import DIE from "phpdie";
|
|
31
|
+
import sflow from "sflow";
|
|
32
|
+
import { TerminalTextRender } from "terminal-render";
|
|
33
|
+
class IdleWaiter {
|
|
34
|
+
lastActivityTime = Date.now();
|
|
35
|
+
checkInterval = 100;
|
|
36
|
+
constructor() {
|
|
37
|
+
this.ping();
|
|
38
|
+
}
|
|
39
|
+
ping() {
|
|
40
|
+
this.lastActivityTime = Date.now();
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
async wait(ms) {
|
|
44
|
+
while (this.lastActivityTime >= Date.now() - ms)
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, this.checkInterval));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class ReadyManager {
|
|
50
|
+
isReady = false;
|
|
51
|
+
readyQueue = [];
|
|
52
|
+
wait() {
|
|
53
|
+
if (this.isReady)
|
|
54
|
+
return;
|
|
55
|
+
return new Promise((resolve) => this.readyQueue.push(resolve));
|
|
56
|
+
}
|
|
57
|
+
unready() {
|
|
58
|
+
this.isReady = false;
|
|
59
|
+
}
|
|
60
|
+
ready() {
|
|
61
|
+
this.isReady = true;
|
|
62
|
+
if (!this.readyQueue.length)
|
|
63
|
+
return;
|
|
64
|
+
this.readyQueue.splice(0).map((resolve) => resolve());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function removeControlCharacters(str) {
|
|
68
|
+
return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
|
69
|
+
}
|
|
70
|
+
var CLI_CONFIGURES = {
|
|
71
|
+
grok: {
|
|
72
|
+
install: "npm install -g @vibe-kit/grok-cli",
|
|
73
|
+
ready: [/^ │ ❯ /],
|
|
74
|
+
enter: [/^ 1. Yes/]
|
|
75
|
+
},
|
|
76
|
+
claude: {
|
|
77
|
+
install: "npm install -g @anthropic-ai/claude-code",
|
|
78
|
+
ready: [/^> /],
|
|
79
|
+
enter: [/❯ 1. Yes/, /❯ 1. Dark mode✔/, /Press Enter to continue…/],
|
|
80
|
+
fatal: [
|
|
81
|
+
/No conversation found to continue/,
|
|
82
|
+
/⎿ Claude usage limit reached\./
|
|
83
|
+
]
|
|
84
|
+
},
|
|
85
|
+
gemini: {
|
|
86
|
+
install: "npm install -g @google/gemini-cli",
|
|
87
|
+
ready: [/Type your message/],
|
|
88
|
+
enter: [/│ ● 1. Yes, allow once/],
|
|
89
|
+
fatal: []
|
|
90
|
+
},
|
|
91
|
+
codex: {
|
|
92
|
+
install: "npm install -g @openai/codex-cli",
|
|
93
|
+
ready: [/⏎ send/],
|
|
94
|
+
enter: [
|
|
95
|
+
/\b▌ \> 1\. Approve and run now/,
|
|
96
|
+
/\b\> 1\. Yes, allow Codex to work in this folder/
|
|
97
|
+
],
|
|
98
|
+
fatal: [/Error: The cursor position could not be read within/],
|
|
99
|
+
ensureArgs: (args) => {
|
|
100
|
+
if (!args.includes("--search"))
|
|
101
|
+
return ["--search", ...args];
|
|
102
|
+
return args;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
copilot: {
|
|
106
|
+
install: "npm install -g @github/copilot",
|
|
107
|
+
ready: [/^ > /],
|
|
108
|
+
enter: [/ │ ❯ 1. Yes, proceed/, /❯ 1. Yes/],
|
|
109
|
+
fatal: []
|
|
110
|
+
},
|
|
111
|
+
cursor: {
|
|
112
|
+
install: "open https://cursor.com/ja/docs/cli/installation",
|
|
113
|
+
binary: "cursor-agent",
|
|
114
|
+
ready: [/\/ commands/],
|
|
115
|
+
enter: [/→ Run \(once\) \(y\) \(enter\)/, /▶ \[a\] Trust this workspace/],
|
|
116
|
+
fatal: [/^ Error: You've hit your usage limit/]
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
async function claudeYes({
|
|
120
|
+
cli = "claude",
|
|
121
|
+
cliArgs = [],
|
|
122
|
+
prompt,
|
|
123
|
+
continueOnCrash,
|
|
124
|
+
cwd,
|
|
125
|
+
env,
|
|
126
|
+
exitOnIdle,
|
|
127
|
+
logFile,
|
|
128
|
+
removeControlCharactersFromStdout = false,
|
|
129
|
+
verbose = false
|
|
130
|
+
} = {}) {
|
|
131
|
+
const continueArgs = {
|
|
132
|
+
codex: "resume --last".split(" "),
|
|
133
|
+
claude: "--continue".split(" "),
|
|
134
|
+
gemini: []
|
|
135
|
+
};
|
|
136
|
+
process.stdin.setRawMode?.(true);
|
|
137
|
+
let isFatal = false;
|
|
138
|
+
const stdinReady = new ReadyManager;
|
|
139
|
+
const shellOutputStream = new TransformStream;
|
|
140
|
+
const outputWriter = shellOutputStream.writable.getWriter();
|
|
141
|
+
const pty = await import("node-pty").catch(async () => await import("bun-pty")).catch(async () => DIE("Please install node-pty or bun-pty, run this: bun install bun-pty"));
|
|
142
|
+
const getPtyOptions = () => ({
|
|
143
|
+
name: "xterm-color",
|
|
144
|
+
...getTerminalDimensions(),
|
|
145
|
+
cwd: cwd ?? process.cwd(),
|
|
146
|
+
env: env ?? process.env
|
|
147
|
+
});
|
|
148
|
+
const cliConf = CLI_CONFIGURES[cli] || {};
|
|
149
|
+
cliArgs = cliConf.ensureArgs?.(cliArgs) ?? cliArgs;
|
|
150
|
+
const cliCommand = cliConf?.binary || cli;
|
|
151
|
+
let shell = tryCatch(() => pty.spawn(cliCommand, cliArgs, getPtyOptions()), (error) => {
|
|
152
|
+
console.error(`Fatal: Failed to start ${cliCommand}.`);
|
|
153
|
+
if (cliConf?.install)
|
|
154
|
+
console.error(`If you did not installed it yet, Please install it first: ${cliConf.install}`);
|
|
155
|
+
throw error;
|
|
156
|
+
});
|
|
157
|
+
const pendingExitCode = Promise.withResolvers();
|
|
158
|
+
let pendingExitCodeValue = null;
|
|
159
|
+
async function onData(data) {
|
|
160
|
+
await outputWriter.write(data);
|
|
161
|
+
}
|
|
162
|
+
shell.onData(onData);
|
|
163
|
+
shell.onExit(function onExit({ exitCode: exitCode2 }) {
|
|
164
|
+
stdinReady.unready();
|
|
165
|
+
const agentCrashed = exitCode2 !== 0;
|
|
166
|
+
const continueArg = continueArgs[cli];
|
|
167
|
+
if (agentCrashed && continueOnCrash && continueArg) {
|
|
168
|
+
if (!continueArg) {
|
|
169
|
+
return console.warn(`continueOnCrash is only supported for ${Object.keys(continueArgs).join(", ")} currently, not ${cli}`);
|
|
170
|
+
}
|
|
171
|
+
if (isFatal) {
|
|
172
|
+
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
173
|
+
}
|
|
174
|
+
console.log(`${cli} crashed, restarting...`);
|
|
175
|
+
shell = pty.spawn(cli, continueArg, getPtyOptions());
|
|
176
|
+
shell.onData(onData);
|
|
177
|
+
shell.onExit(onExit);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
return pendingExitCode.resolve(pendingExitCodeValue = exitCode2);
|
|
181
|
+
});
|
|
182
|
+
process.stdout.on("resize", () => {
|
|
183
|
+
const { cols, rows } = getTerminalDimensions();
|
|
184
|
+
shell.resize(cols, rows);
|
|
185
|
+
});
|
|
186
|
+
const terminalRender = new TerminalTextRender;
|
|
187
|
+
const isStillWorkingQ = () => terminalRender.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/);
|
|
188
|
+
const idleWaiter = new IdleWaiter;
|
|
189
|
+
if (exitOnIdle)
|
|
190
|
+
idleWaiter.wait(exitOnIdle).then(async () => {
|
|
191
|
+
if (isStillWorkingQ()) {
|
|
192
|
+
console.log("[${cli}-yes] ${cli} is idle, but seems still working, not exiting yet");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
console.log("[${cli}-yes] ${cli} is idle, exiting...");
|
|
196
|
+
await exitAgent();
|
|
197
|
+
});
|
|
198
|
+
console.log(`[${cli}-yes] Started ${cli} with args: ${[cliCommand, ...cliArgs].join(" ")}`);
|
|
199
|
+
shell.write("\x1B[1;1R");
|
|
200
|
+
sflow(fromReadable(process.stdin)).map((buffer) => buffer.toString()).by({
|
|
201
|
+
writable: new WritableStream({
|
|
202
|
+
write: async (data) => {
|
|
203
|
+
await stdinReady.wait();
|
|
204
|
+
shell.write(data);
|
|
205
|
+
}
|
|
206
|
+
}),
|
|
207
|
+
readable: shellOutputStream.readable
|
|
208
|
+
}).forEach(() => idleWaiter.ping()).forEach((text) => {
|
|
209
|
+
terminalRender.write(text);
|
|
210
|
+
if (process.stdin.isTTY)
|
|
211
|
+
return;
|
|
212
|
+
if (text.includes("\x1B[6n"))
|
|
213
|
+
return;
|
|
214
|
+
const { col, row } = terminalRender.getCursorPosition();
|
|
215
|
+
console.log(`[${cli}-yes] Responding cursor position: row=${row}, col=${col}`);
|
|
216
|
+
shell.write(`\x1B[${row};${col}R`);
|
|
217
|
+
}).forkTo((e) => e.map((e2) => removeControlCharacters(e2)).map((e2) => e2.replaceAll("\r", "")).forEach((e2) => appendFile("io.log", "output|" + JSON.stringify(e2) + `
|
|
218
|
+
`)).forEach(async (e2, i) => {
|
|
219
|
+
const conf = CLI_CONFIGURES[cli] || null;
|
|
220
|
+
if (!conf)
|
|
221
|
+
return;
|
|
222
|
+
if (conf.ready?.some((rx) => e2.match(rx))) {
|
|
223
|
+
if (cli === "gemini" && i <= 80)
|
|
224
|
+
return;
|
|
225
|
+
stdinReady.ready();
|
|
226
|
+
}
|
|
227
|
+
if (conf.enter?.some((rx) => e2.match(rx))) {
|
|
228
|
+
await sendEnter(300);
|
|
229
|
+
}
|
|
230
|
+
if (conf.fatal?.some((rx) => e2.match(rx))) {
|
|
231
|
+
isFatal = true;
|
|
232
|
+
await exitAgent();
|
|
233
|
+
}
|
|
234
|
+
}).run()).map((e) => removeControlCharactersFromStdout ? removeControlCharacters(e) : e).to(fromWritable(process.stdout)).then(() => null);
|
|
235
|
+
if (prompt)
|
|
236
|
+
await sendMessage(prompt);
|
|
237
|
+
const exitCode = await pendingExitCode.promise;
|
|
238
|
+
console.log(`[${cli}-yes] ${cli} exited with code ${exitCode}`);
|
|
239
|
+
if (logFile) {
|
|
240
|
+
verbose && console.log(`[${cli}-yes] Writing rendered logs to ${logFile}`);
|
|
241
|
+
const logFilePath = path.resolve(logFile);
|
|
242
|
+
await mkdir(path.dirname(logFilePath), { recursive: true }).catch(() => null);
|
|
243
|
+
await writeFile(logFilePath, terminalRender.render());
|
|
244
|
+
}
|
|
245
|
+
return { exitCode, logs: terminalRender.render() };
|
|
246
|
+
async function sendEnter(waitms = 1000) {
|
|
247
|
+
const st = Date.now();
|
|
248
|
+
await idleWaiter.wait(waitms);
|
|
249
|
+
const et = Date.now();
|
|
250
|
+
process.stdout.write(`\ridleWaiter.wait(${waitms}) took ${et - st}ms\r`);
|
|
251
|
+
shell.write("\r");
|
|
252
|
+
}
|
|
253
|
+
async function sendMessage(message) {
|
|
254
|
+
await stdinReady.wait();
|
|
255
|
+
shell.write(message);
|
|
256
|
+
idleWaiter.ping();
|
|
257
|
+
await sendEnter();
|
|
258
|
+
}
|
|
259
|
+
async function exitAgent() {
|
|
260
|
+
continueOnCrash = false;
|
|
261
|
+
await sendMessage("/exit");
|
|
262
|
+
let exited = false;
|
|
263
|
+
await Promise.race([
|
|
264
|
+
pendingExitCode.promise.then(() => exited = true),
|
|
265
|
+
new Promise((resolve) => setTimeout(() => {
|
|
266
|
+
if (exited)
|
|
267
|
+
return;
|
|
268
|
+
shell.kill();
|
|
269
|
+
resolve();
|
|
270
|
+
}, 5000))
|
|
271
|
+
]);
|
|
272
|
+
}
|
|
273
|
+
function getTerminalDimensions() {
|
|
274
|
+
return {
|
|
275
|
+
cols: process.stdout.columns,
|
|
276
|
+
rows: process.stdout.rows
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
function tryCatch(fn, catchFn) {
|
|
281
|
+
try {
|
|
282
|
+
return fn();
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return catchFn(error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// cli.ts
|
|
289
|
+
var argv = yargs(hideBin(process.argv)).usage("Usage: $0 [options] [claude args] [--] [prompts...]").example('$0 --exit-on-idle=30s --continue-on-crash "help me solve all todos in my codebase"', "Run Claude with a 30 seconds idle timeout and continue on crash").option("continue-on-crash", {
|
|
290
|
+
type: "boolean",
|
|
291
|
+
default: true,
|
|
292
|
+
description: "spawn Claude with --continue if it crashes, only works for claude"
|
|
293
|
+
}).option("log-file", {
|
|
294
|
+
type: "string",
|
|
295
|
+
description: "Log file to write to"
|
|
296
|
+
}).option("cli", {
|
|
297
|
+
type: "string",
|
|
298
|
+
description: 'Claude CLI command, e.g. "claude,gemini,codex,cursor,copilot", default is "claude"'
|
|
299
|
+
}).option("prompt", {
|
|
300
|
+
type: "string",
|
|
301
|
+
description: "Prompt to send to Claude",
|
|
302
|
+
alias: "p"
|
|
303
|
+
}).option("verbose", {
|
|
304
|
+
type: "boolean",
|
|
305
|
+
description: "Enable verbose logging",
|
|
306
|
+
default: false
|
|
307
|
+
}).option("exit-on-idle", {
|
|
308
|
+
type: "string",
|
|
309
|
+
description: 'Exit after a period of inactivity, e.g., "5s" or "1m"'
|
|
310
|
+
}).parserConfiguration({
|
|
311
|
+
"unknown-options-as-args": true,
|
|
312
|
+
"halt-at-non-option": true
|
|
313
|
+
}).parseSync();
|
|
314
|
+
if (!argv.cli) {
|
|
315
|
+
const cliName = process.argv[1]?.split("/").pop()?.split("-")[0];
|
|
316
|
+
argv.cli = cliName || "claude";
|
|
317
|
+
}
|
|
318
|
+
var rawArgs = process.argv.slice(2);
|
|
319
|
+
var dashIndex = rawArgs.indexOf("--");
|
|
320
|
+
var promptFromDash = undefined;
|
|
321
|
+
var cliArgsForSpawn = [];
|
|
322
|
+
if (dashIndex !== -1) {
|
|
323
|
+
const after = rawArgs.slice(dashIndex + 1);
|
|
324
|
+
promptFromDash = after.join(" ");
|
|
325
|
+
cliArgsForSpawn = rawArgs.slice(0, dashIndex).map(String);
|
|
326
|
+
} else {
|
|
327
|
+
cliArgsForSpawn = argv._.map((e) => String(e));
|
|
328
|
+
}
|
|
329
|
+
console.clear();
|
|
330
|
+
var { exitCode, logs } = await claudeYes({
|
|
331
|
+
cli: argv.cli,
|
|
332
|
+
prompt: argv.prompt || promptFromDash,
|
|
333
|
+
exitOnIdle: argv.exitOnIdle ? enhancedMs(argv.exitOnIdle) : undefined,
|
|
334
|
+
cliArgs: cliArgsForSpawn,
|
|
335
|
+
continueOnCrash: argv.continueOnCrash,
|
|
336
|
+
logFile: argv.logFile,
|
|
337
|
+
verbose: argv.verbose
|
|
338
|
+
});
|
|
339
|
+
process.exit(exitCode ?? 1);
|
|
340
|
+
|
|
341
|
+
//# debugId=F98366DB626CC88164756E2164756E21
|
|
342
|
+
//# sourceMappingURL=cli.js.map
|