claude-yes 1.37.0 → 1.37.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 +683 -756
- package/dist/index.js +603 -484
- package/package.json +4 -21
- package/ts/index.ts +77 -325
- package/ts/parseCliArgs.ts +1 -1
- package/ts/pidStore.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -10354,19 +10354,6 @@ class TerminalTextRender {
|
|
|
10354
10354
|
}
|
|
10355
10355
|
var init_dist5 = () => {};
|
|
10356
10356
|
|
|
10357
|
-
// ts/catcher.ts
|
|
10358
|
-
function catcher(catchFn, fn) {
|
|
10359
|
-
if (!fn)
|
|
10360
|
-
return (fn2) => catcher(catchFn, fn2);
|
|
10361
|
-
return (...args) => {
|
|
10362
|
-
try {
|
|
10363
|
-
return fn(...args);
|
|
10364
|
-
} catch (error) {
|
|
10365
|
-
return catchFn(error, fn, ...args);
|
|
10366
|
-
}
|
|
10367
|
-
};
|
|
10368
|
-
}
|
|
10369
|
-
|
|
10370
10357
|
// ts/resume/codexSessionManager.ts
|
|
10371
10358
|
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
|
|
10372
10359
|
import { homedir } from "os";
|
|
@@ -10479,23 +10466,6 @@ function extractSessionId(output) {
|
|
|
10479
10466
|
var getSessionsFile = () => process.env.CLI_YES_TEST_HOME ? path7.join(process.env.CLI_YES_TEST_HOME, ".config", "agent-yes", "codex-sessions.json") : path7.join(homedir(), ".config", "agent-yes", "codex-sessions.json"), getCodexSessionsDir = () => process.env.CLI_YES_TEST_HOME ? path7.join(process.env.CLI_YES_TEST_HOME, ".codex", "sessions") : path7.join(homedir(), ".codex", "sessions");
|
|
10480
10467
|
var init_codexSessionManager = () => {};
|
|
10481
10468
|
|
|
10482
|
-
// ts/idleWaiter.ts
|
|
10483
|
-
class IdleWaiter {
|
|
10484
|
-
lastActivityTime = Date.now();
|
|
10485
|
-
checkInterval = 100;
|
|
10486
|
-
constructor() {
|
|
10487
|
-
this.ping();
|
|
10488
|
-
}
|
|
10489
|
-
ping() {
|
|
10490
|
-
this.lastActivityTime = Date.now();
|
|
10491
|
-
return this;
|
|
10492
|
-
}
|
|
10493
|
-
async wait(ms) {
|
|
10494
|
-
while (this.lastActivityTime >= Date.now() - ms)
|
|
10495
|
-
await new Promise((resolve) => setTimeout(resolve, this.checkInterval));
|
|
10496
|
-
}
|
|
10497
|
-
}
|
|
10498
|
-
|
|
10499
10469
|
// node_modules/logform/format.js
|
|
10500
10470
|
var require_format = __commonJS((exports, module) => {
|
|
10501
10471
|
class InvalidFormatError extends Error {
|
|
@@ -20391,26 +20361,6 @@ var init_pty = __esm(async () => {
|
|
|
20391
20361
|
pty_default = pty;
|
|
20392
20362
|
});
|
|
20393
20363
|
|
|
20394
|
-
// ts/ReadyManager.ts
|
|
20395
|
-
class ReadyManager {
|
|
20396
|
-
isReady = false;
|
|
20397
|
-
readyQueue = [];
|
|
20398
|
-
wait() {
|
|
20399
|
-
if (this.isReady)
|
|
20400
|
-
return;
|
|
20401
|
-
return new Promise((resolve) => this.readyQueue.push(resolve));
|
|
20402
|
-
}
|
|
20403
|
-
unready() {
|
|
20404
|
-
this.isReady = false;
|
|
20405
|
-
}
|
|
20406
|
-
ready() {
|
|
20407
|
-
this.isReady = true;
|
|
20408
|
-
if (!this.readyQueue.length)
|
|
20409
|
-
return;
|
|
20410
|
-
this.readyQueue.splice(0).map((resolve) => resolve());
|
|
20411
|
-
}
|
|
20412
|
-
}
|
|
20413
|
-
|
|
20414
20364
|
// ts/removeControlCharacters.ts
|
|
20415
20365
|
function removeControlCharacters(str) {
|
|
20416
20366
|
return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, "");
|
|
@@ -20992,6 +20942,10 @@ fifo/
|
|
|
20992
20942
|
*.raw.log
|
|
20993
20943
|
*.lines.log
|
|
20994
20944
|
*.debug.log
|
|
20945
|
+
|
|
20946
|
+
# Ignore .gitignore itself
|
|
20947
|
+
.gitignore
|
|
20948
|
+
|
|
20995
20949
|
`;
|
|
20996
20950
|
try {
|
|
20997
20951
|
await writeFile3(gitignorePath, gitignoreContent, { flag: "wx" });
|
|
@@ -21014,166 +20968,108 @@ var init_pidStore = __esm(() => {
|
|
|
21014
20968
|
init_logger();
|
|
21015
20969
|
});
|
|
21016
20970
|
|
|
21017
|
-
// ts/
|
|
21018
|
-
async function
|
|
21019
|
-
|
|
21020
|
-
|
|
21021
|
-
|
|
20971
|
+
// ts/core/messaging.ts
|
|
20972
|
+
async function sendEnter(context, waitms = 1000) {
|
|
20973
|
+
const st = Date.now();
|
|
20974
|
+
await context.idleWaiter.wait(waitms);
|
|
20975
|
+
const et = Date.now();
|
|
20976
|
+
logger.debug(`sendEn| idleWaiter.wait(${String(waitms)}) took ${String(et - st)}ms`);
|
|
20977
|
+
context.nextStdout.unready();
|
|
20978
|
+
context.shell.write("\r");
|
|
20979
|
+
await Promise.race([
|
|
20980
|
+
context.nextStdout.wait(),
|
|
20981
|
+
new Promise((resolve) => setTimeout(() => {
|
|
20982
|
+
if (!context.nextStdout.ready) {
|
|
20983
|
+
context.shell.write("\r");
|
|
20984
|
+
}
|
|
20985
|
+
resolve();
|
|
20986
|
+
}, 1000))
|
|
20987
|
+
]);
|
|
20988
|
+
await Promise.race([
|
|
20989
|
+
context.nextStdout.wait(),
|
|
20990
|
+
new Promise((resolve) => setTimeout(() => {
|
|
20991
|
+
if (!context.nextStdout.ready) {
|
|
20992
|
+
context.shell.write("\r");
|
|
20993
|
+
}
|
|
20994
|
+
resolve();
|
|
20995
|
+
}, 3000))
|
|
20996
|
+
]);
|
|
20997
|
+
}
|
|
20998
|
+
async function sendMessage3(context, message, { waitForReady = true } = {}) {
|
|
20999
|
+
if (waitForReady)
|
|
21000
|
+
await context.stdinReady.wait();
|
|
21001
|
+
logger.debug(`send |${message}`);
|
|
21002
|
+
context.nextStdout.unready();
|
|
21003
|
+
context.shell.write(message);
|
|
21004
|
+
context.idleWaiter.ping();
|
|
21005
|
+
logger.debug(`waiting next stdout|${message}`);
|
|
21006
|
+
await context.nextStdout.wait();
|
|
21007
|
+
logger.debug(`sending enter`);
|
|
21008
|
+
await sendEnter(context, 1000);
|
|
21009
|
+
logger.debug(`sent enter`);
|
|
21022
21010
|
}
|
|
21011
|
+
var init_messaging = __esm(() => {
|
|
21012
|
+
init_logger();
|
|
21013
|
+
});
|
|
21023
21014
|
|
|
21024
|
-
// ts/
|
|
21025
|
-
|
|
21026
|
-
|
|
21027
|
-
|
|
21028
|
-
|
|
21029
|
-
|
|
21030
|
-
|
|
21031
|
-
|
|
21032
|
-
|
|
21033
|
-
|
|
21034
|
-
|
|
21035
|
-
|
|
21036
|
-
|
|
21037
|
-
|
|
21015
|
+
// ts/core/logging.ts
|
|
21016
|
+
import path10 from "path";
|
|
21017
|
+
import { mkdir as mkdir4, writeFile as writeFile4 } from "fs/promises";
|
|
21018
|
+
function initializeLogPaths(pidStore, pid) {
|
|
21019
|
+
const logPath = pidStore.getLogPath(pid);
|
|
21020
|
+
const rawLogPath = path10.resolve(path10.dirname(logPath), `${pid}.raw.log`);
|
|
21021
|
+
const rawLinesLogPath = path10.resolve(path10.dirname(logPath), `${pid}.lines.log`);
|
|
21022
|
+
const debuggingLogsPath = path10.resolve(path10.dirname(logPath), `${pid}.debug.log`);
|
|
21023
|
+
return {
|
|
21024
|
+
logPath,
|
|
21025
|
+
rawLogPath,
|
|
21026
|
+
rawLinesLogPath,
|
|
21027
|
+
debuggingLogsPath
|
|
21028
|
+
};
|
|
21029
|
+
}
|
|
21030
|
+
function setupDebugLogging(debuggingLogsPath) {
|
|
21031
|
+
if (debuggingLogsPath) {
|
|
21032
|
+
logger.add(new import_winston2.default.transports.File({
|
|
21033
|
+
filename: debuggingLogsPath,
|
|
21034
|
+
level: "debug"
|
|
21035
|
+
}));
|
|
21038
21036
|
}
|
|
21039
|
-
return target;
|
|
21040
21037
|
}
|
|
21041
|
-
|
|
21042
|
-
|
|
21043
|
-
|
|
21044
|
-
|
|
21045
|
-
|
|
21046
|
-
});
|
|
21047
|
-
import { mkdir as mkdir4 } from "node:fs/promises";
|
|
21048
|
-
import os from "node:os";
|
|
21049
|
-
import path10 from "node:path";
|
|
21050
|
-
function getDefaultConfig() {
|
|
21051
|
-
return defineCliYesConfig({
|
|
21052
|
-
configDir,
|
|
21053
|
-
logsDir: configDir && path10.resolve(configDir, "logs"),
|
|
21054
|
-
clis: {
|
|
21055
|
-
qwen: {
|
|
21056
|
-
install: "npm install -g @qwen-code/qwen-code@latest",
|
|
21057
|
-
version: "qwen --version"
|
|
21058
|
-
},
|
|
21059
|
-
grok: {
|
|
21060
|
-
install: "npm install -g @vibe-kit/grok-cli@latest",
|
|
21061
|
-
ready: [/^ │ ❯ +/],
|
|
21062
|
-
enter: [/^ 1. Yes/]
|
|
21063
|
-
},
|
|
21064
|
-
claude: {
|
|
21065
|
-
promptArg: "last-arg",
|
|
21066
|
-
install: {
|
|
21067
|
-
powershell: "irm https://claude.ai/install.ps1 | iex",
|
|
21068
|
-
bash: "curl -fsSL https://claude.ai/install.sh | bash",
|
|
21069
|
-
npm: "npm i -g @anthropic-ai/claude-code@latest"
|
|
21070
|
-
},
|
|
21071
|
-
ready: [/^\? for shortcuts/, /^> /],
|
|
21072
|
-
typingRespond: {
|
|
21073
|
-
"1\n": [/│ Do you want to use this API key\?/]
|
|
21074
|
-
},
|
|
21075
|
-
enter: [
|
|
21076
|
-
/^.{0,4} 1\. Yes/m,
|
|
21077
|
-
/^.{0,4} 1\. Yes, continue/m,
|
|
21078
|
-
/^.{0,4} 1\. Dark mode ?✔/m,
|
|
21079
|
-
/❯ 1\. Yes/m,
|
|
21080
|
-
/❯ 1\. Yes, continue/m,
|
|
21081
|
-
/❯ 1\. Dark mode ?✔/m,
|
|
21082
|
-
/Press Enter to continue…/m
|
|
21083
|
-
],
|
|
21084
|
-
fatal: [/⎿ Claude usage limit reached\./, /^error: unknown option/],
|
|
21085
|
-
restoreArgs: ["--continue"],
|
|
21086
|
-
restartWithoutContinueArg: [/No conversation found to continue/],
|
|
21087
|
-
exitCommand: ["/exit"],
|
|
21088
|
-
bunx: true,
|
|
21089
|
-
defaultArgs: ["--model=sonnet"]
|
|
21090
|
-
},
|
|
21091
|
-
gemini: {
|
|
21092
|
-
install: "npm install -g @google/gemini-cli@latest",
|
|
21093
|
-
ready: [/Type your message/],
|
|
21094
|
-
enter: [/│ ● 1. Yes, allow once/, /│ ● 1. Allow once/],
|
|
21095
|
-
fatal: [/Error resuming session/, /No previous sessions found for this project./],
|
|
21096
|
-
restoreArgs: ["--resume"],
|
|
21097
|
-
restartWithoutContinueArg: [
|
|
21098
|
-
/No previous sessions found for this project\./,
|
|
21099
|
-
/Error resuming session/
|
|
21100
|
-
],
|
|
21101
|
-
exitCommand: ["/chat save ${PWD}", "/quit"]
|
|
21102
|
-
},
|
|
21103
|
-
codex: {
|
|
21104
|
-
promptArg: "first-arg",
|
|
21105
|
-
install: "npm install -g @openai/codex@latest",
|
|
21106
|
-
updateAvailable: [/^✨⬆️ Update available!/],
|
|
21107
|
-
ready: [
|
|
21108
|
-
/⏎ send/,
|
|
21109
|
-
/\? for shortcuts/
|
|
21110
|
-
],
|
|
21111
|
-
enter: [
|
|
21112
|
-
/> 1. Yes,/,
|
|
21113
|
-
/> 1. Yes, allow Codex to work in this folder/,
|
|
21114
|
-
/> 1. Approve and run now/
|
|
21115
|
-
],
|
|
21116
|
-
fatal: [/Error: The cursor position could not be read within/],
|
|
21117
|
-
defaultArgs: ["--search"],
|
|
21118
|
-
noEOL: true
|
|
21119
|
-
},
|
|
21120
|
-
copilot: {
|
|
21121
|
-
install: "npm install -g @github/copilot",
|
|
21122
|
-
ready: [/^ +> /, /Ctrl\+c Exit/],
|
|
21123
|
-
enter: [/ │ ❯ +1. Yes, proceed/, /❯ +1. Yes/],
|
|
21124
|
-
fatal: []
|
|
21125
|
-
},
|
|
21126
|
-
cursor: {
|
|
21127
|
-
install: "open https://cursor.com/ja/docs/cli/installation",
|
|
21128
|
-
binary: "cursor-agent",
|
|
21129
|
-
bunx: true,
|
|
21130
|
-
ready: [/\/ commands/],
|
|
21131
|
-
enter: [/→ Run \(once\) \(y\) \(enter\)/, /▶ \[a\] Trust this workspace/],
|
|
21132
|
-
fatal: [/^ Error: You've hit your usage limit/]
|
|
21133
|
-
},
|
|
21134
|
-
auggie: {
|
|
21135
|
-
help: "https://docs.augmentcode.com/cli/overview",
|
|
21136
|
-
install: "npm install -g @augmentcode/auggie",
|
|
21137
|
-
promptArg: "first-arg",
|
|
21138
|
-
ready: [/ > /, /\? to show shortcuts/],
|
|
21139
|
-
enter: [],
|
|
21140
|
-
fatal: []
|
|
21141
|
-
},
|
|
21142
|
-
amp: {
|
|
21143
|
-
help: "https://ampcode.com/",
|
|
21144
|
-
install: {
|
|
21145
|
-
bash: "curl -fsSL https://ampcode.com/install.sh | bash",
|
|
21146
|
-
npm: "npm i -g @sourcegraph/amp"
|
|
21147
|
-
},
|
|
21148
|
-
enter: [
|
|
21149
|
-
/^.{0,4} Approve /
|
|
21150
|
-
]
|
|
21151
|
-
}
|
|
21152
|
-
}
|
|
21153
|
-
});
|
|
21038
|
+
async function saveLogFile(logPath, content) {
|
|
21039
|
+
if (!logPath)
|
|
21040
|
+
return;
|
|
21041
|
+
await mkdir4(path10.dirname(logPath), { recursive: true }).catch(() => null);
|
|
21042
|
+
await writeFile4(logPath, content).catch(() => null);
|
|
21043
|
+
logger.info(`Full logs saved to ${logPath}`);
|
|
21154
21044
|
}
|
|
21155
|
-
|
|
21156
|
-
|
|
21157
|
-
init_logger();
|
|
21158
|
-
logger.debug("loading cli-yes.config.ts from " + import.meta.url);
|
|
21159
|
-
configDir = await (async () => {
|
|
21160
|
-
const homeConfigDir = path10.resolve(os.homedir(), ".agent-yes");
|
|
21161
|
-
const isHomeWritable = await mkdir4(homeConfigDir, { recursive: true }).then(() => true).catch(() => false);
|
|
21162
|
-
if (isHomeWritable) {
|
|
21163
|
-
logger.debug("[config] Using home directory:", homeConfigDir);
|
|
21164
|
-
return homeConfigDir;
|
|
21165
|
-
}
|
|
21166
|
-
const tmpConfigDir = path10.resolve("/tmp/.agent-yes");
|
|
21167
|
-
const isWritable = await mkdir4(tmpConfigDir, { recursive: true });
|
|
21168
|
-
if (isWritable) {
|
|
21169
|
-
logger.debug("[config] Using workspace directory:", tmpConfigDir);
|
|
21170
|
-
return tmpConfigDir;
|
|
21171
|
-
}
|
|
21045
|
+
async function saveDeprecatedLogFile(logFile, content, verbose) {
|
|
21046
|
+
if (!logFile)
|
|
21172
21047
|
return;
|
|
21173
|
-
|
|
21174
|
-
|
|
21048
|
+
if (verbose)
|
|
21049
|
+
logger.info(`Writing rendered logs to ${logFile}`);
|
|
21050
|
+
const logFilePath = path10.resolve(logFile);
|
|
21051
|
+
await mkdir4(path10.dirname(logFilePath), { recursive: true }).catch(() => null);
|
|
21052
|
+
await writeFile4(logFilePath, content);
|
|
21053
|
+
}
|
|
21054
|
+
var import_winston2;
|
|
21055
|
+
var init_logging = __esm(() => {
|
|
21056
|
+
init_logger();
|
|
21057
|
+
import_winston2 = __toESM(require_winston(), 1);
|
|
21175
21058
|
});
|
|
21176
21059
|
|
|
21060
|
+
// ts/catcher.ts
|
|
21061
|
+
function catcher(catchFn, fn) {
|
|
21062
|
+
if (!fn)
|
|
21063
|
+
return (fn2) => catcher(catchFn, fn2);
|
|
21064
|
+
return (...args) => {
|
|
21065
|
+
try {
|
|
21066
|
+
return fn(...args);
|
|
21067
|
+
} catch (error) {
|
|
21068
|
+
return catchFn(error, fn, ...args);
|
|
21069
|
+
}
|
|
21070
|
+
};
|
|
21071
|
+
}
|
|
21072
|
+
|
|
21177
21073
|
// ts/pty-fix.ts
|
|
21178
21074
|
var exports_pty_fix = {};
|
|
21179
21075
|
import { execSync as execSync2 } from "child_process";
|
|
@@ -21301,42 +21197,451 @@ var init_pty_fix = __esm(() => {
|
|
|
21301
21197
|
}
|
|
21302
21198
|
});
|
|
21303
21199
|
|
|
21304
|
-
// ts/
|
|
21305
|
-
|
|
21306
|
-
|
|
21307
|
-
|
|
21308
|
-
|
|
21309
|
-
|
|
21310
|
-
|
|
21311
|
-
|
|
21312
|
-
|
|
21313
|
-
|
|
21314
|
-
|
|
21315
|
-
|
|
21316
|
-
|
|
21317
|
-
|
|
21318
|
-
|
|
21319
|
-
|
|
21320
|
-
|
|
21321
|
-
|
|
21322
|
-
|
|
21323
|
-
|
|
21324
|
-
|
|
21325
|
-
|
|
21326
|
-
|
|
21327
|
-
|
|
21328
|
-
|
|
21329
|
-
|
|
21330
|
-
|
|
21331
|
-
|
|
21332
|
-
|
|
21333
|
-
|
|
21334
|
-
|
|
21335
|
-
|
|
21336
|
-
|
|
21337
|
-
}
|
|
21338
|
-
|
|
21339
|
-
|
|
21200
|
+
// ts/core/spawner.ts
|
|
21201
|
+
function getInstallCommand(installConfig) {
|
|
21202
|
+
if (typeof installConfig === "string") {
|
|
21203
|
+
return installConfig;
|
|
21204
|
+
}
|
|
21205
|
+
const isWindows = process.platform === "win32";
|
|
21206
|
+
const platform3 = isWindows ? "windows" : "unix";
|
|
21207
|
+
if (installConfig[platform3]) {
|
|
21208
|
+
return installConfig[platform3];
|
|
21209
|
+
}
|
|
21210
|
+
if (isWindows && installConfig.powershell) {
|
|
21211
|
+
return installConfig.powershell;
|
|
21212
|
+
}
|
|
21213
|
+
if (!isWindows && installConfig.bash) {
|
|
21214
|
+
return installConfig.bash;
|
|
21215
|
+
}
|
|
21216
|
+
if (installConfig.npm) {
|
|
21217
|
+
return installConfig.npm;
|
|
21218
|
+
}
|
|
21219
|
+
return null;
|
|
21220
|
+
}
|
|
21221
|
+
function isCommandNotFoundError(e) {
|
|
21222
|
+
if (e instanceof Error) {
|
|
21223
|
+
return e.message.includes("command not found") || e.message.includes("ENOENT") || e.message.includes("spawn");
|
|
21224
|
+
}
|
|
21225
|
+
return false;
|
|
21226
|
+
}
|
|
21227
|
+
function spawnAgent(options) {
|
|
21228
|
+
const { cli, cliConf, cliArgs, verbose, install, ptyOptions } = options;
|
|
21229
|
+
const spawn2 = () => {
|
|
21230
|
+
const cliCommand = cliConf?.binary || cli;
|
|
21231
|
+
let [bin, ...args] = [...parseCommandString(cliCommand), ...cliArgs];
|
|
21232
|
+
if (verbose)
|
|
21233
|
+
logger.info(`Spawning ${bin} with args: ${JSON.stringify(args)}`);
|
|
21234
|
+
logger.info(`Spawning ${bin} with args: ${JSON.stringify(args)}`);
|
|
21235
|
+
const spawned = pty_default.spawn(bin, args, ptyOptions);
|
|
21236
|
+
logger.info(`[${cli}-yes] Spawned ${bin} with PID ${spawned.pid}`);
|
|
21237
|
+
return spawned;
|
|
21238
|
+
};
|
|
21239
|
+
return catcher((error, _fn, ..._args) => {
|
|
21240
|
+
logger.error(`Fatal: Failed to start ${cli}.`);
|
|
21241
|
+
const isNotFound = isCommandNotFoundError(error);
|
|
21242
|
+
if (cliConf?.install && isNotFound) {
|
|
21243
|
+
const installCmd = getInstallCommand(cliConf.install);
|
|
21244
|
+
if (!installCmd) {
|
|
21245
|
+
logger.error(`No suitable install command found for ${cli} on this platform`);
|
|
21246
|
+
throw error;
|
|
21247
|
+
}
|
|
21248
|
+
logger.info(`Please install the cli by run ${installCmd}`);
|
|
21249
|
+
if (install) {
|
|
21250
|
+
logger.info(`Attempting to install ${cli}...`);
|
|
21251
|
+
execaCommandSync(installCmd, { stdio: "inherit" });
|
|
21252
|
+
logger.info(`${cli} installed successfully. Please rerun the command.`);
|
|
21253
|
+
return spawn2();
|
|
21254
|
+
} else {
|
|
21255
|
+
logger.error(`If you did not installed it yet, Please install it first: ${installCmd}`);
|
|
21256
|
+
throw error;
|
|
21257
|
+
}
|
|
21258
|
+
}
|
|
21259
|
+
if (globalThis.Bun && error instanceof Error && error.stack?.includes("bun-pty")) {
|
|
21260
|
+
logger.error(`Detected bun-pty issue, attempted to fix it. Please try again.`);
|
|
21261
|
+
init_pty_fix();
|
|
21262
|
+
}
|
|
21263
|
+
throw error;
|
|
21264
|
+
}, spawn2)();
|
|
21265
|
+
}
|
|
21266
|
+
function getTerminalDimensions() {
|
|
21267
|
+
if (!process.stdout.isTTY)
|
|
21268
|
+
return { cols: 80, rows: 30 };
|
|
21269
|
+
return {
|
|
21270
|
+
cols: Math.min(Math.max(20, process.stdout.columns), 80),
|
|
21271
|
+
rows: process.stdout.rows
|
|
21272
|
+
};
|
|
21273
|
+
}
|
|
21274
|
+
var init_spawner = __esm(async () => {
|
|
21275
|
+
init_execa();
|
|
21276
|
+
init_logger();
|
|
21277
|
+
await init_pty();
|
|
21278
|
+
});
|
|
21279
|
+
|
|
21280
|
+
// ts/ReadyManager.ts
|
|
21281
|
+
class ReadyManager {
|
|
21282
|
+
isReady = false;
|
|
21283
|
+
readyQueue = [];
|
|
21284
|
+
wait() {
|
|
21285
|
+
if (this.isReady)
|
|
21286
|
+
return;
|
|
21287
|
+
return new Promise((resolve) => this.readyQueue.push(resolve));
|
|
21288
|
+
}
|
|
21289
|
+
unready() {
|
|
21290
|
+
this.isReady = false;
|
|
21291
|
+
}
|
|
21292
|
+
ready() {
|
|
21293
|
+
this.isReady = true;
|
|
21294
|
+
if (!this.readyQueue.length)
|
|
21295
|
+
return;
|
|
21296
|
+
this.readyQueue.splice(0).map((resolve) => resolve());
|
|
21297
|
+
}
|
|
21298
|
+
}
|
|
21299
|
+
|
|
21300
|
+
// ts/idleWaiter.ts
|
|
21301
|
+
class IdleWaiter {
|
|
21302
|
+
lastActivityTime = Date.now();
|
|
21303
|
+
checkInterval = 100;
|
|
21304
|
+
constructor() {
|
|
21305
|
+
this.ping();
|
|
21306
|
+
}
|
|
21307
|
+
ping() {
|
|
21308
|
+
this.lastActivityTime = Date.now();
|
|
21309
|
+
return this;
|
|
21310
|
+
}
|
|
21311
|
+
async wait(ms) {
|
|
21312
|
+
while (this.lastActivityTime >= Date.now() - ms)
|
|
21313
|
+
await new Promise((resolve) => setTimeout(resolve, this.checkInterval));
|
|
21314
|
+
}
|
|
21315
|
+
}
|
|
21316
|
+
|
|
21317
|
+
// ts/core/context.ts
|
|
21318
|
+
class AgentContext {
|
|
21319
|
+
shell;
|
|
21320
|
+
pidStore;
|
|
21321
|
+
logPaths;
|
|
21322
|
+
cli;
|
|
21323
|
+
cliConf;
|
|
21324
|
+
verbose;
|
|
21325
|
+
robust;
|
|
21326
|
+
stdinReady = new ReadyManager;
|
|
21327
|
+
stdinFirstReady = new ReadyManager;
|
|
21328
|
+
nextStdout = new ReadyManager;
|
|
21329
|
+
idleWaiter = new IdleWaiter;
|
|
21330
|
+
isFatal = false;
|
|
21331
|
+
shouldRestartWithoutContinue = false;
|
|
21332
|
+
constructor(params) {
|
|
21333
|
+
this.shell = params.shell;
|
|
21334
|
+
this.pidStore = params.pidStore;
|
|
21335
|
+
this.logPaths = params.logPaths;
|
|
21336
|
+
this.cli = params.cli;
|
|
21337
|
+
this.cliConf = params.cliConf;
|
|
21338
|
+
this.verbose = params.verbose;
|
|
21339
|
+
this.robust = params.robust;
|
|
21340
|
+
}
|
|
21341
|
+
get messageContext() {
|
|
21342
|
+
return {
|
|
21343
|
+
shell: this.shell,
|
|
21344
|
+
idleWaiter: this.idleWaiter,
|
|
21345
|
+
stdinReady: this.stdinReady,
|
|
21346
|
+
nextStdout: this.nextStdout
|
|
21347
|
+
};
|
|
21348
|
+
}
|
|
21349
|
+
}
|
|
21350
|
+
var init_context = () => {};
|
|
21351
|
+
|
|
21352
|
+
// ts/core/responders.ts
|
|
21353
|
+
async function createAutoResponseHandler(line, lineIndex, options) {
|
|
21354
|
+
const { ctx, conf, cli, workingDir, exitAgent } = options;
|
|
21355
|
+
logger.debug(`stdout|${line}`);
|
|
21356
|
+
if (conf.ready?.some((rx) => line.match(rx))) {
|
|
21357
|
+
logger.debug(`ready |${line}`);
|
|
21358
|
+
if (cli === "gemini" && lineIndex <= 80)
|
|
21359
|
+
return;
|
|
21360
|
+
ctx.stdinReady.ready();
|
|
21361
|
+
ctx.stdinFirstReady.ready();
|
|
21362
|
+
}
|
|
21363
|
+
if (conf.enter?.some((rx) => line.match(rx))) {
|
|
21364
|
+
logger.debug(`enter |${line}`);
|
|
21365
|
+
return await sendEnter(ctx.messageContext, 400);
|
|
21366
|
+
}
|
|
21367
|
+
const typingResponded = await src_default(Object.entries(conf.typingRespond ?? {})).filter(([_sendString, onThePatterns]) => onThePatterns.some((rx) => line.match(rx))).map(async ([sendString]) => await sendMessage3(ctx.messageContext, sendString, { waitForReady: false })).toCount();
|
|
21368
|
+
if (typingResponded)
|
|
21369
|
+
return;
|
|
21370
|
+
if (conf.fatal?.some((rx) => line.match(rx))) {
|
|
21371
|
+
logger.debug(`fatal |${line}`);
|
|
21372
|
+
ctx.isFatal = true;
|
|
21373
|
+
await exitAgent();
|
|
21374
|
+
}
|
|
21375
|
+
if (conf.restartWithoutContinueArg?.some((rx) => line.match(rx))) {
|
|
21376
|
+
logger.debug(`restart-without-continue|${line}`);
|
|
21377
|
+
ctx.shouldRestartWithoutContinue = true;
|
|
21378
|
+
ctx.isFatal = true;
|
|
21379
|
+
await exitAgent();
|
|
21380
|
+
}
|
|
21381
|
+
if (cli === "codex") {
|
|
21382
|
+
const sessionId = extractSessionId(line);
|
|
21383
|
+
if (sessionId) {
|
|
21384
|
+
logger.debug(`session|captured session ID: ${sessionId}`);
|
|
21385
|
+
await storeSessionForCwd(workingDir, sessionId);
|
|
21386
|
+
}
|
|
21387
|
+
}
|
|
21388
|
+
}
|
|
21389
|
+
var init_responders = __esm(() => {
|
|
21390
|
+
init_dist4();
|
|
21391
|
+
init_logger();
|
|
21392
|
+
init_messaging();
|
|
21393
|
+
init_codexSessionManager();
|
|
21394
|
+
});
|
|
21395
|
+
|
|
21396
|
+
// ts/core/streamHelpers.ts
|
|
21397
|
+
function handleConsoleControlCodes(text, shell, terminalRender, cli, verbose) {
|
|
21398
|
+
terminalRender.write(text);
|
|
21399
|
+
if (text.includes("\x1B[c") || text.includes("\x1B[0c")) {
|
|
21400
|
+
shell.write("\x1B[?1;2c");
|
|
21401
|
+
if (verbose) {
|
|
21402
|
+
logger.debug("device|respond DA: VT100 with Advanced Video Option");
|
|
21403
|
+
}
|
|
21404
|
+
return;
|
|
21405
|
+
}
|
|
21406
|
+
if (process.stdin.isTTY)
|
|
21407
|
+
return;
|
|
21408
|
+
if (!text.includes("\x1B[6n"))
|
|
21409
|
+
return;
|
|
21410
|
+
const { col, row } = terminalRender.getCursorPosition();
|
|
21411
|
+
shell.write(`\x1B[${row};${col}R`);
|
|
21412
|
+
logger.debug(`cursor|respond position: row=${String(row)}, col=${String(col)}`);
|
|
21413
|
+
}
|
|
21414
|
+
function createTerminateSignalHandler(stdinReady, onAbort) {
|
|
21415
|
+
let aborted2 = false;
|
|
21416
|
+
return (chunk) => {
|
|
21417
|
+
if (!aborted2 && chunk === "\x1A") {
|
|
21418
|
+
return "";
|
|
21419
|
+
}
|
|
21420
|
+
if (!aborted2 && !stdinReady.isReady && chunk === "\x03") {
|
|
21421
|
+
logger.error("User aborted: SIGINT");
|
|
21422
|
+
onAbort(130);
|
|
21423
|
+
aborted2 = true;
|
|
21424
|
+
return chunk;
|
|
21425
|
+
}
|
|
21426
|
+
return chunk;
|
|
21427
|
+
};
|
|
21428
|
+
}
|
|
21429
|
+
function createTerminatorStream(exitPromise) {
|
|
21430
|
+
return new TransformStream({
|
|
21431
|
+
start: function terminator(ctrl) {
|
|
21432
|
+
exitPromise.then(() => ctrl.terminate());
|
|
21433
|
+
},
|
|
21434
|
+
transform: (e, ctrl) => ctrl.enqueue(e),
|
|
21435
|
+
flush: (ctrl) => ctrl.terminate()
|
|
21436
|
+
});
|
|
21437
|
+
}
|
|
21438
|
+
var init_streamHelpers = __esm(() => {
|
|
21439
|
+
init_logger();
|
|
21440
|
+
});
|
|
21441
|
+
|
|
21442
|
+
// ts/defineConfig.ts
|
|
21443
|
+
async function defineCliYesConfig(cfg) {
|
|
21444
|
+
if (typeof cfg === "function")
|
|
21445
|
+
cfg = await cfg({ clis: {} });
|
|
21446
|
+
return cfg;
|
|
21447
|
+
}
|
|
21448
|
+
|
|
21449
|
+
// ts/utils.ts
|
|
21450
|
+
function deepMixin(target, source, ...more) {
|
|
21451
|
+
for (const key in source) {
|
|
21452
|
+
if (source[key] && typeof source[key] === "object" && !Array.isArray(source[key])) {
|
|
21453
|
+
if (!target[key] || typeof target[key] !== "object") {
|
|
21454
|
+
target[key] = {};
|
|
21455
|
+
}
|
|
21456
|
+
deepMixin(target[key], source[key]);
|
|
21457
|
+
} else if (source[key] !== undefined) {
|
|
21458
|
+
target[key] = source[key];
|
|
21459
|
+
}
|
|
21460
|
+
}
|
|
21461
|
+
for (const moreSource of more) {
|
|
21462
|
+
deepMixin(target, moreSource);
|
|
21463
|
+
}
|
|
21464
|
+
return target;
|
|
21465
|
+
}
|
|
21466
|
+
|
|
21467
|
+
// agent-yes.config.ts
|
|
21468
|
+
var exports_agent_yes_config = {};
|
|
21469
|
+
__export(exports_agent_yes_config, {
|
|
21470
|
+
default: () => agent_yes_config_default
|
|
21471
|
+
});
|
|
21472
|
+
import { mkdir as mkdir5 } from "node:fs/promises";
|
|
21473
|
+
import os from "node:os";
|
|
21474
|
+
import path11 from "node:path";
|
|
21475
|
+
function getDefaultConfig() {
|
|
21476
|
+
return defineCliYesConfig({
|
|
21477
|
+
configDir,
|
|
21478
|
+
logsDir: configDir && path11.resolve(configDir, "logs"),
|
|
21479
|
+
clis: {
|
|
21480
|
+
qwen: {
|
|
21481
|
+
install: "npm install -g @qwen-code/qwen-code@latest",
|
|
21482
|
+
version: "qwen --version"
|
|
21483
|
+
},
|
|
21484
|
+
grok: {
|
|
21485
|
+
install: "npm install -g @vibe-kit/grok-cli@latest",
|
|
21486
|
+
ready: [/^ │ ❯ +/],
|
|
21487
|
+
enter: [/^ 1. Yes/]
|
|
21488
|
+
},
|
|
21489
|
+
claude: {
|
|
21490
|
+
promptArg: "last-arg",
|
|
21491
|
+
install: {
|
|
21492
|
+
powershell: "irm https://claude.ai/install.ps1 | iex",
|
|
21493
|
+
bash: "curl -fsSL https://claude.ai/install.sh | bash",
|
|
21494
|
+
npm: "npm i -g @anthropic-ai/claude-code@latest"
|
|
21495
|
+
},
|
|
21496
|
+
ready: [/^\? for shortcuts/, /^> /],
|
|
21497
|
+
typingRespond: {
|
|
21498
|
+
"1\n": [/│ Do you want to use this API key\?/]
|
|
21499
|
+
},
|
|
21500
|
+
enter: [
|
|
21501
|
+
/^.{0,4} 1\. Yes/m,
|
|
21502
|
+
/^.{0,4} 1\. Yes, continue/m,
|
|
21503
|
+
/^.{0,4} 1\. Dark mode ?✔/m,
|
|
21504
|
+
/❯ 1\. Yes/m,
|
|
21505
|
+
/❯ 1\. Yes, continue/m,
|
|
21506
|
+
/❯ 1\. Dark mode ?✔/m,
|
|
21507
|
+
/Press Enter to continue…/m
|
|
21508
|
+
],
|
|
21509
|
+
fatal: [/⎿ Claude usage limit reached\./, /^error: unknown option/],
|
|
21510
|
+
restoreArgs: ["--continue"],
|
|
21511
|
+
restartWithoutContinueArg: [/No conversation found to continue/],
|
|
21512
|
+
exitCommand: ["/exit"],
|
|
21513
|
+
bunx: true,
|
|
21514
|
+
defaultArgs: ["--model=sonnet"]
|
|
21515
|
+
},
|
|
21516
|
+
gemini: {
|
|
21517
|
+
install: "npm install -g @google/gemini-cli@latest",
|
|
21518
|
+
ready: [/Type your message/],
|
|
21519
|
+
enter: [/│ ● 1. Yes, allow once/, /│ ● 1. Allow once/],
|
|
21520
|
+
fatal: [/Error resuming session/, /No previous sessions found for this project./],
|
|
21521
|
+
restoreArgs: ["--resume"],
|
|
21522
|
+
restartWithoutContinueArg: [
|
|
21523
|
+
/No previous sessions found for this project\./,
|
|
21524
|
+
/Error resuming session/
|
|
21525
|
+
],
|
|
21526
|
+
exitCommand: ["/chat save ${PWD}", "/quit"]
|
|
21527
|
+
},
|
|
21528
|
+
codex: {
|
|
21529
|
+
promptArg: "first-arg",
|
|
21530
|
+
install: "npm install -g @openai/codex@latest",
|
|
21531
|
+
updateAvailable: [/^✨⬆️ Update available!/],
|
|
21532
|
+
ready: [
|
|
21533
|
+
/⏎ send/,
|
|
21534
|
+
/\? for shortcuts/
|
|
21535
|
+
],
|
|
21536
|
+
enter: [
|
|
21537
|
+
/> 1. Yes,/,
|
|
21538
|
+
/> 1. Yes, allow Codex to work in this folder/,
|
|
21539
|
+
/> 1. Approve and run now/
|
|
21540
|
+
],
|
|
21541
|
+
fatal: [/Error: The cursor position could not be read within/],
|
|
21542
|
+
defaultArgs: ["--search"],
|
|
21543
|
+
noEOL: true
|
|
21544
|
+
},
|
|
21545
|
+
copilot: {
|
|
21546
|
+
install: "npm install -g @github/copilot",
|
|
21547
|
+
ready: [/^ +> /, /Ctrl\+c Exit/],
|
|
21548
|
+
enter: [/ │ ❯ +1. Yes, proceed/, /❯ +1. Yes/],
|
|
21549
|
+
fatal: []
|
|
21550
|
+
},
|
|
21551
|
+
cursor: {
|
|
21552
|
+
install: "open https://cursor.com/ja/docs/cli/installation",
|
|
21553
|
+
binary: "cursor-agent",
|
|
21554
|
+
bunx: true,
|
|
21555
|
+
ready: [/\/ commands/],
|
|
21556
|
+
enter: [/→ Run \(once\) \(y\) \(enter\)/, /▶ \[a\] Trust this workspace/],
|
|
21557
|
+
fatal: [/^ Error: You've hit your usage limit/]
|
|
21558
|
+
},
|
|
21559
|
+
auggie: {
|
|
21560
|
+
help: "https://docs.augmentcode.com/cli/overview",
|
|
21561
|
+
install: "npm install -g @augmentcode/auggie",
|
|
21562
|
+
promptArg: "first-arg",
|
|
21563
|
+
ready: [/ > /, /\? to show shortcuts/],
|
|
21564
|
+
enter: [],
|
|
21565
|
+
fatal: []
|
|
21566
|
+
},
|
|
21567
|
+
amp: {
|
|
21568
|
+
help: "https://ampcode.com/",
|
|
21569
|
+
install: {
|
|
21570
|
+
bash: "curl -fsSL https://ampcode.com/install.sh | bash",
|
|
21571
|
+
npm: "npm i -g @sourcegraph/amp"
|
|
21572
|
+
},
|
|
21573
|
+
enter: [
|
|
21574
|
+
/^.{0,4} Approve /
|
|
21575
|
+
]
|
|
21576
|
+
}
|
|
21577
|
+
}
|
|
21578
|
+
});
|
|
21579
|
+
}
|
|
21580
|
+
var configDir, agent_yes_config_default;
|
|
21581
|
+
var init_agent_yes_config = __esm(async () => {
|
|
21582
|
+
init_logger();
|
|
21583
|
+
logger.debug("loading cli-yes.config.ts from " + import.meta.url);
|
|
21584
|
+
configDir = await (async () => {
|
|
21585
|
+
const homeConfigDir = path11.resolve(os.homedir(), ".agent-yes");
|
|
21586
|
+
const isHomeWritable = await mkdir5(homeConfigDir, { recursive: true }).then(() => true).catch(() => false);
|
|
21587
|
+
if (isHomeWritable) {
|
|
21588
|
+
logger.debug("[config] Using home directory:", homeConfigDir);
|
|
21589
|
+
return homeConfigDir;
|
|
21590
|
+
}
|
|
21591
|
+
const tmpConfigDir = path11.resolve("/tmp/.agent-yes");
|
|
21592
|
+
const isWritable = await mkdir5(tmpConfigDir, { recursive: true });
|
|
21593
|
+
if (isWritable) {
|
|
21594
|
+
logger.debug("[config] Using workspace directory:", tmpConfigDir);
|
|
21595
|
+
return tmpConfigDir;
|
|
21596
|
+
}
|
|
21597
|
+
return;
|
|
21598
|
+
})();
|
|
21599
|
+
agent_yes_config_default = deepMixin(await getDefaultConfig(), await import(path11.resolve(os.homedir(), ".agent-yes/config.ts")).catch(() => ({ default: {} })).then((mod) => mod.default), await import(path11.resolve(process.cwd(), "node_modules/.agent-yes/config.ts")).catch(() => ({ default: {} })).then((mod) => mod.default), await import(path11.resolve(process.cwd(), ".agent-yes/config.ts")).catch(() => ({ default: {} })).then((mod) => mod.default));
|
|
21600
|
+
});
|
|
21601
|
+
|
|
21602
|
+
// ts/index.ts
|
|
21603
|
+
init_execa();
|
|
21604
|
+
init_dist();
|
|
21605
|
+
init_dist4();
|
|
21606
|
+
init_dist5();
|
|
21607
|
+
init_codexSessionManager();
|
|
21608
|
+
init_runningLock();
|
|
21609
|
+
init_logger();
|
|
21610
|
+
init_fifo();
|
|
21611
|
+
init_pidStore();
|
|
21612
|
+
init_messaging();
|
|
21613
|
+
init_logging();
|
|
21614
|
+
init_context();
|
|
21615
|
+
init_responders();
|
|
21616
|
+
init_streamHelpers();
|
|
21617
|
+
await __promiseAll([
|
|
21618
|
+
init_pty(),
|
|
21619
|
+
init_spawner()
|
|
21620
|
+
]);
|
|
21621
|
+
import { fromReadable as fromReadable2, fromWritable } from "from-node-stream";
|
|
21622
|
+
import { mkdir as mkdir6, readFile as readFile3, writeFile as writeFile5 } from "fs/promises";
|
|
21623
|
+
import path12 from "path";
|
|
21624
|
+
var config = await init_agent_yes_config().then(() => exports_agent_yes_config).then((mod) => mod.default || mod);
|
|
21625
|
+
var CLIS_CONFIG = config.clis;
|
|
21626
|
+
async function agentYes({
|
|
21627
|
+
cli,
|
|
21628
|
+
cliArgs = [],
|
|
21629
|
+
prompt,
|
|
21630
|
+
robust = true,
|
|
21631
|
+
cwd,
|
|
21632
|
+
env,
|
|
21633
|
+
exitOnIdle,
|
|
21634
|
+
logFile,
|
|
21635
|
+
removeControlCharactersFromStdout = false,
|
|
21636
|
+
verbose = false,
|
|
21637
|
+
queue = false,
|
|
21638
|
+
install = false,
|
|
21639
|
+
resume = false,
|
|
21640
|
+
useSkills = false,
|
|
21641
|
+
useFifo = false
|
|
21642
|
+
}) {
|
|
21643
|
+
if (!cli)
|
|
21644
|
+
throw new Error(`cli is required`);
|
|
21340
21645
|
const conf = CLIS_CONFIG[cli] || phpdie_default(`Unsupported cli tool: ${cli}, current process.argv: ${process.argv.join(" ")}`);
|
|
21341
21646
|
const workingDir = cwd ?? process.cwd();
|
|
21342
21647
|
if (queue) {
|
|
@@ -21364,36 +21669,12 @@ async function agentYes({
|
|
|
21364
21669
|
const pidStore = new PidStore(workingDir);
|
|
21365
21670
|
await pidStore.init();
|
|
21366
21671
|
process.stdin.setRawMode?.(true);
|
|
21367
|
-
let isFatal = false;
|
|
21368
|
-
let shouldRestartWithoutContinue = false;
|
|
21369
|
-
const stdinReady = new ReadyManager;
|
|
21370
|
-
const stdinFirstReady = new ReadyManager;
|
|
21371
|
-
sleep2(1e4).then(() => {
|
|
21372
|
-
if (!stdinReady.isReady)
|
|
21373
|
-
stdinReady.ready();
|
|
21374
|
-
if (!stdinFirstReady.isReady)
|
|
21375
|
-
stdinFirstReady.ready();
|
|
21376
|
-
});
|
|
21377
|
-
const nextStdout = new ReadyManager;
|
|
21378
21672
|
const shellOutputStream = new TransformStream;
|
|
21379
21673
|
const outputWriter = shellOutputStream.writable.getWriter();
|
|
21380
21674
|
logger.debug(`Using ${ptyPackage} for pseudo terminal management.`);
|
|
21381
|
-
let logPath = false;
|
|
21382
|
-
let rawLogPath = false;
|
|
21383
|
-
let rawLinesLogPath = false;
|
|
21384
|
-
let debuggingLogsPath = false;
|
|
21385
21675
|
const isSubAgent = !!process.env.CLAUDE_PPID;
|
|
21386
21676
|
if (isSubAgent)
|
|
21387
21677
|
logger.info(`[${cli}-yes] Running as sub-agent (CLAUDE_PPID=${process.env.CLAUDE_PPID})`);
|
|
21388
|
-
const getPtyOptions = () => {
|
|
21389
|
-
const ptyEnv = { ...env ?? process.env };
|
|
21390
|
-
return {
|
|
21391
|
-
name: "xterm-color",
|
|
21392
|
-
...getTerminalDimensions(),
|
|
21393
|
-
cwd: cwd ?? process.cwd(),
|
|
21394
|
-
env: ptyEnv
|
|
21395
|
-
};
|
|
21396
|
-
};
|
|
21397
21678
|
const cliConf = CLIS_CONFIG[cli] || {};
|
|
21398
21679
|
cliArgs = cliConf.defaultArgs ? [...cliConf.defaultArgs, ...cliArgs] : cliArgs;
|
|
21399
21680
|
try {
|
|
@@ -21411,9 +21692,9 @@ async function agentYes({
|
|
|
21411
21692
|
} catch {}
|
|
21412
21693
|
const skillHeaders = [];
|
|
21413
21694
|
let currentDir = workingDir2;
|
|
21414
|
-
const searchLimit = gitRoot ||
|
|
21695
|
+
const searchLimit = gitRoot || path12.parse(currentDir).root;
|
|
21415
21696
|
while (true) {
|
|
21416
|
-
const skillPath =
|
|
21697
|
+
const skillPath = path12.resolve(currentDir, "SKILL.md");
|
|
21417
21698
|
const md = await readFile3(skillPath, "utf8").catch(() => null);
|
|
21418
21699
|
if (md) {
|
|
21419
21700
|
const headerMatch = md.match(/^[\s\S]*?(?=\n##\s)/);
|
|
@@ -21426,7 +21707,7 @@ async function agentYes({
|
|
|
21426
21707
|
}
|
|
21427
21708
|
if (currentDir === searchLimit)
|
|
21428
21709
|
break;
|
|
21429
|
-
const parentDir =
|
|
21710
|
+
const parentDir = path12.dirname(currentDir);
|
|
21430
21711
|
if (parentDir === currentDir)
|
|
21431
21712
|
break;
|
|
21432
21713
|
currentDir = parentDir;
|
|
@@ -21489,93 +21770,54 @@ ${prompt}` : prefix;
|
|
|
21489
21770
|
logger.warn(`Unknown promptArg format: ${cliConf.promptArg}`);
|
|
21490
21771
|
}
|
|
21491
21772
|
}
|
|
21492
|
-
const
|
|
21493
|
-
|
|
21494
|
-
|
|
21495
|
-
|
|
21496
|
-
|
|
21497
|
-
|
|
21498
|
-
if (installConfig[platform3]) {
|
|
21499
|
-
return installConfig[platform3];
|
|
21500
|
-
}
|
|
21501
|
-
if (isWindows && installConfig.powershell) {
|
|
21502
|
-
return installConfig.powershell;
|
|
21503
|
-
}
|
|
21504
|
-
if (!isWindows && installConfig.bash) {
|
|
21505
|
-
return installConfig.bash;
|
|
21506
|
-
}
|
|
21507
|
-
if (installConfig.npm) {
|
|
21508
|
-
return installConfig.npm;
|
|
21509
|
-
}
|
|
21510
|
-
return null;
|
|
21773
|
+
const ptyEnv = { ...env ?? process.env };
|
|
21774
|
+
const ptyOptions = {
|
|
21775
|
+
name: "xterm-color",
|
|
21776
|
+
...getTerminalDimensions(),
|
|
21777
|
+
cwd: cwd ?? process.cwd(),
|
|
21778
|
+
env: ptyEnv
|
|
21511
21779
|
};
|
|
21512
|
-
|
|
21513
|
-
|
|
21514
|
-
|
|
21515
|
-
|
|
21516
|
-
|
|
21517
|
-
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
return spawned;
|
|
21521
|
-
};
|
|
21522
|
-
let shell = catcher((error, _fn, ..._args) => {
|
|
21523
|
-
logger.error(`Fatal: Failed to start ${cli}.`);
|
|
21524
|
-
const isNotFound = isCommandNotFoundError(error);
|
|
21525
|
-
if (cliConf?.install && isNotFound) {
|
|
21526
|
-
const installCmd = getInstallCommand(cliConf.install);
|
|
21527
|
-
if (!installCmd) {
|
|
21528
|
-
logger.error(`No suitable install command found for ${cli} on this platform`);
|
|
21529
|
-
throw error;
|
|
21530
|
-
}
|
|
21531
|
-
logger.info(`Please install the cli by run ${installCmd}`);
|
|
21532
|
-
if (install) {
|
|
21533
|
-
logger.info(`Attempting to install ${cli}...`);
|
|
21534
|
-
execaCommandSync(installCmd, { stdio: "inherit" });
|
|
21535
|
-
logger.info(`${cli} installed successfully. Please rerun the command.`);
|
|
21536
|
-
return spawn2();
|
|
21537
|
-
} else {
|
|
21538
|
-
logger.error(`If you did not installed it yet, Please install it first: ${installCmd}`);
|
|
21539
|
-
throw error;
|
|
21540
|
-
}
|
|
21541
|
-
}
|
|
21542
|
-
if (globalThis.Bun && error instanceof Error && error.stack?.includes("bun-pty")) {
|
|
21543
|
-
logger.error(`Detected bun-pty issue, attempted to fix it. Please try again.`);
|
|
21544
|
-
init_pty_fix();
|
|
21545
|
-
}
|
|
21546
|
-
throw error;
|
|
21547
|
-
function isCommandNotFoundError(e) {
|
|
21548
|
-
if (e instanceof Error) {
|
|
21549
|
-
return e.message.includes("command not found") || e.message.includes("ENOENT") || e.message.includes("spawn");
|
|
21550
|
-
}
|
|
21551
|
-
return false;
|
|
21552
|
-
}
|
|
21553
|
-
}, spawn2)();
|
|
21780
|
+
let shell = spawnAgent({
|
|
21781
|
+
cli,
|
|
21782
|
+
cliConf,
|
|
21783
|
+
cliArgs,
|
|
21784
|
+
verbose,
|
|
21785
|
+
install,
|
|
21786
|
+
ptyOptions
|
|
21787
|
+
});
|
|
21554
21788
|
await pidStore.registerProcess({ pid: shell.pid, cli, args: cliArgs, prompt });
|
|
21555
|
-
|
|
21556
|
-
|
|
21557
|
-
|
|
21558
|
-
|
|
21559
|
-
|
|
21560
|
-
|
|
21561
|
-
|
|
21562
|
-
|
|
21563
|
-
|
|
21789
|
+
const logPaths = initializeLogPaths(pidStore, shell.pid);
|
|
21790
|
+
setupDebugLogging(logPaths.debuggingLogsPath);
|
|
21791
|
+
const ctx = new AgentContext({
|
|
21792
|
+
shell,
|
|
21793
|
+
pidStore,
|
|
21794
|
+
logPaths,
|
|
21795
|
+
cli,
|
|
21796
|
+
cliConf,
|
|
21797
|
+
verbose,
|
|
21798
|
+
robust
|
|
21799
|
+
});
|
|
21800
|
+
sleep2(1e4).then(() => {
|
|
21801
|
+
if (!ctx.stdinReady.isReady)
|
|
21802
|
+
ctx.stdinReady.ready();
|
|
21803
|
+
if (!ctx.stdinFirstReady.isReady)
|
|
21804
|
+
ctx.stdinFirstReady.ready();
|
|
21805
|
+
});
|
|
21564
21806
|
const pendingExitCode = Promise.withResolvers();
|
|
21565
21807
|
async function onData(data) {
|
|
21566
21808
|
await outputWriter.write(data);
|
|
21567
21809
|
}
|
|
21568
21810
|
shell.onData(onData);
|
|
21569
21811
|
shell.onExit(async function onExit({ exitCode: exitCode2 }) {
|
|
21570
|
-
stdinReady.unready();
|
|
21812
|
+
ctx.stdinReady.unready();
|
|
21571
21813
|
const agentCrashed = exitCode2 !== 0;
|
|
21572
|
-
if (shouldRestartWithoutContinue) {
|
|
21814
|
+
if (ctx.shouldRestartWithoutContinue) {
|
|
21573
21815
|
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21574
21816
|
exitReason: "restarted",
|
|
21575
21817
|
exitCode: exitCode2 ?? undefined
|
|
21576
21818
|
});
|
|
21577
|
-
shouldRestartWithoutContinue = false;
|
|
21578
|
-
isFatal = false;
|
|
21819
|
+
ctx.shouldRestartWithoutContinue = false;
|
|
21820
|
+
ctx.isFatal = false;
|
|
21579
21821
|
const cliCommand = cliConf?.binary || cli;
|
|
21580
21822
|
let [bin, ...args] = [
|
|
21581
21823
|
...parseCommandString(cliCommand),
|
|
@@ -21593,7 +21835,7 @@ ${prompt}` : prefix;
|
|
|
21593
21835
|
logger.warn(`robust is only supported for ${Object.entries(CLIS_CONFIG).filter(([_, v]) => v.restoreArgs).map(([k]) => k).join(", ")} currently, not ${cli}`);
|
|
21594
21836
|
return;
|
|
21595
21837
|
}
|
|
21596
|
-
if (isFatal) {
|
|
21838
|
+
if (ctx.isFatal) {
|
|
21597
21839
|
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21598
21840
|
exitReason: "fatal",
|
|
21599
21841
|
exitCode: exitCode2 ?? undefined
|
|
@@ -21634,9 +21876,8 @@ ${prompt}` : prefix;
|
|
|
21634
21876
|
});
|
|
21635
21877
|
const terminalRender = new TerminalTextRender;
|
|
21636
21878
|
const isStillWorkingQ = () => terminalRender.render().replace(/\s+/g, " ").match(/esc to interrupt|to run in background/);
|
|
21637
|
-
const idleWaiter = new IdleWaiter;
|
|
21638
21879
|
if (exitOnIdle)
|
|
21639
|
-
idleWaiter.wait(exitOnIdle).then(async () => {
|
|
21880
|
+
ctx.idleWaiter.wait(exitOnIdle).then(async () => {
|
|
21640
21881
|
await pidStore.updateStatus(shell.pid, "idle").catch(() => null);
|
|
21641
21882
|
if (isStillWorkingQ()) {
|
|
21642
21883
|
logger.warn("[${cli}-yes] ${cli} is idle, but seems still working, not exiting yet");
|
|
@@ -21646,20 +21887,11 @@ ${prompt}` : prefix;
|
|
|
21646
21887
|
await exitAgent();
|
|
21647
21888
|
});
|
|
21648
21889
|
await src_default(fromReadable2(process.stdin)).map((buffer2) => buffer2.toString()).by(function handleTerminateSignals(s) {
|
|
21649
|
-
|
|
21650
|
-
|
|
21651
|
-
|
|
21652
|
-
return "";
|
|
21653
|
-
}
|
|
21654
|
-
if (!aborted2 && !stdinReady.isReady && chunk === "\x03") {
|
|
21655
|
-
logger.error("User aborted: SIGINT");
|
|
21656
|
-
shell.kill("SIGINT");
|
|
21657
|
-
pendingExitCode.resolve(130);
|
|
21658
|
-
aborted2 = true;
|
|
21659
|
-
return chunk;
|
|
21660
|
-
}
|
|
21661
|
-
return chunk;
|
|
21890
|
+
const handler = createTerminateSignalHandler(ctx.stdinReady, (exitCode2) => {
|
|
21891
|
+
shell.kill("SIGINT");
|
|
21892
|
+
pendingExitCode.resolve(exitCode2);
|
|
21662
21893
|
});
|
|
21894
|
+
return s.map(handler);
|
|
21663
21895
|
}).by((s) => {
|
|
21664
21896
|
if (!useFifo)
|
|
21665
21897
|
return s;
|
|
@@ -21675,154 +21907,49 @@ ${prompt}` : prefix;
|
|
|
21675
21907
|
}).onStart(async function promptOnStart() {
|
|
21676
21908
|
logger.debug("Sending prompt message: " + JSON.stringify(prompt));
|
|
21677
21909
|
if (prompt)
|
|
21678
|
-
await sendMessage3(prompt);
|
|
21910
|
+
await sendMessage3(ctx.messageContext, prompt);
|
|
21679
21911
|
}).by({
|
|
21680
21912
|
writable: new WritableStream({
|
|
21681
21913
|
write: async (data) => {
|
|
21682
|
-
await stdinReady.wait();
|
|
21914
|
+
await ctx.stdinReady.wait();
|
|
21683
21915
|
shell.write(data);
|
|
21684
21916
|
}
|
|
21685
21917
|
}),
|
|
21686
21918
|
readable: shellOutputStream.readable
|
|
21687
21919
|
}).forEach(() => {
|
|
21688
|
-
idleWaiter.ping();
|
|
21920
|
+
ctx.idleWaiter.ping();
|
|
21689
21921
|
pidStore.updateStatus(shell.pid, "active").catch(() => null);
|
|
21690
|
-
}).forEach(() => nextStdout.ready()).forkTo(async function rawLogger(f) {
|
|
21691
|
-
if (!rawLogPath)
|
|
21922
|
+
}).forEach(() => ctx.nextStdout.ready()).forkTo(async function rawLogger(f) {
|
|
21923
|
+
if (!ctx.logPaths.rawLogPath)
|
|
21692
21924
|
return f.run();
|
|
21693
|
-
return await
|
|
21694
|
-
logger.debug(`[${cli}-yes] raw logs streaming to ${rawLogPath}`);
|
|
21925
|
+
return await mkdir6(path12.dirname(ctx.logPaths.rawLogPath), { recursive: true }).then(() => {
|
|
21926
|
+
logger.debug(`[${cli}-yes] raw logs streaming to ${ctx.logPaths.rawLogPath}`);
|
|
21695
21927
|
return f.forEach(async (chars) => {
|
|
21696
|
-
await
|
|
21928
|
+
await writeFile5(ctx.logPaths.rawLogPath, chars, { flag: "a" }).catch(() => null);
|
|
21697
21929
|
}).run();
|
|
21698
21930
|
}).catch(() => f.run());
|
|
21699
21931
|
}).by(function consoleResponder(e) {
|
|
21700
21932
|
if (cli === "codex")
|
|
21701
21933
|
shell.write(`\x1B[1;1R`);
|
|
21702
|
-
return e.forEach((text) =>
|
|
21703
|
-
terminalRender.write(text);
|
|
21704
|
-
if (text.includes("\x1B[c") || text.includes("\x1B[0c")) {
|
|
21705
|
-
shell.write("\x1B[?1;2c");
|
|
21706
|
-
if (verbose) {
|
|
21707
|
-
logger.debug("device|respond DA: VT100 with Advanced Video Option");
|
|
21708
|
-
}
|
|
21709
|
-
return;
|
|
21710
|
-
}
|
|
21711
|
-
if (process.stdin.isTTY)
|
|
21712
|
-
return;
|
|
21713
|
-
if (!text.includes("\x1B[6n"))
|
|
21714
|
-
return;
|
|
21715
|
-
const { col, row } = terminalRender.getCursorPosition();
|
|
21716
|
-
shell.write(`\x1B[${row};${col}R`);
|
|
21717
|
-
logger.debug(`cursor|respond position: row=${String(row)}, col=${String(col)}`);
|
|
21718
|
-
});
|
|
21934
|
+
return e.forEach((text) => handleConsoleControlCodes(text, shell, terminalRender, cli, verbose));
|
|
21719
21935
|
}).forkTo(function autoResponse(e) {
|
|
21720
21936
|
return e.map((e2) => removeControlCharacters(e2)).by((s) => {
|
|
21721
21937
|
if (conf.noEOL)
|
|
21722
21938
|
return s;
|
|
21723
21939
|
return s.lines({ EOL: "NONE" });
|
|
21724
|
-
}).forEach(async
|
|
21725
|
-
|
|
21726
|
-
|
|
21727
|
-
logger.debug(`ready |${e2}`);
|
|
21728
|
-
if (cli === "gemini" && i2 <= 80)
|
|
21729
|
-
return;
|
|
21730
|
-
stdinReady.ready();
|
|
21731
|
-
stdinFirstReady.ready();
|
|
21732
|
-
}
|
|
21733
|
-
if (conf.enter?.some((rx) => e2.match(rx))) {
|
|
21734
|
-
logger.debug(`enter |${e2}`);
|
|
21735
|
-
return await sendEnter(400);
|
|
21736
|
-
}
|
|
21737
|
-
const typingResponded = await src_default(Object.entries(conf.typingRespond ?? {})).filter(([_sendString, onThePatterns]) => onThePatterns.some((rx) => e2.match(rx))).map(async ([sendString]) => await sendMessage3(sendString, { waitForReady: false })).toCount();
|
|
21738
|
-
if (typingResponded)
|
|
21739
|
-
return;
|
|
21740
|
-
if (conf.fatal?.some((rx) => e2.match(rx))) {
|
|
21741
|
-
logger.debug(`fatal |${e2}`);
|
|
21742
|
-
isFatal = true;
|
|
21743
|
-
await exitAgent();
|
|
21744
|
-
}
|
|
21745
|
-
if (conf.restartWithoutContinueArg?.some((rx) => e2.match(rx))) {
|
|
21746
|
-
await logger.debug(`restart-without-continue|${e2}`);
|
|
21747
|
-
shouldRestartWithoutContinue = true;
|
|
21748
|
-
isFatal = true;
|
|
21749
|
-
await exitAgent();
|
|
21750
|
-
}
|
|
21751
|
-
if (cli === "codex") {
|
|
21752
|
-
const sessionId = extractSessionId(e2);
|
|
21753
|
-
if (sessionId) {
|
|
21754
|
-
await logger.debug(`session|captured session ID: ${sessionId}`);
|
|
21755
|
-
await storeSessionForCwd(workingDir, sessionId);
|
|
21756
|
-
}
|
|
21757
|
-
}
|
|
21758
|
-
}).run();
|
|
21759
|
-
}).by((s) => removeControlCharactersFromStdout ? s.map((e) => removeControlCharacters(e)) : s).by(new TransformStream({
|
|
21760
|
-
start: function terminator(ctrl) {
|
|
21761
|
-
pendingExitCode.promise.then(() => ctrl.terminate());
|
|
21762
|
-
},
|
|
21763
|
-
transform: (e, ctrl) => ctrl.enqueue(e),
|
|
21764
|
-
flush: (ctrl) => ctrl.terminate()
|
|
21765
|
-
})).to(fromWritable(process.stdout));
|
|
21766
|
-
if (logPath) {
|
|
21767
|
-
await mkdir5(path11.dirname(logPath), { recursive: true }).catch(() => null);
|
|
21768
|
-
await writeFile4(logPath, terminalRender.render()).catch(() => null);
|
|
21769
|
-
logger.info(`[${cli}-yes] Full logs saved to ${logPath}`);
|
|
21770
|
-
}
|
|
21940
|
+
}).forEach(async (line, lineIndex) => createAutoResponseHandler(line, lineIndex, { ctx, conf, cli, workingDir, exitAgent })).run();
|
|
21941
|
+
}).by((s) => removeControlCharactersFromStdout ? s.map((e) => removeControlCharacters(e)) : s).by(createTerminatorStream(pendingExitCode.promise)).to(fromWritable(process.stdout));
|
|
21942
|
+
await saveLogFile(ctx.logPaths.logPath, terminalRender.render());
|
|
21771
21943
|
const exitCode = await pendingExitCode.promise;
|
|
21772
21944
|
logger.info(`[${cli}-yes] ${cli} exited with code ${exitCode}`);
|
|
21773
21945
|
await pidStore.close();
|
|
21774
21946
|
await outputWriter.close();
|
|
21775
|
-
|
|
21776
|
-
if (verbose)
|
|
21777
|
-
logger.info(`[${cli}-yes] Writing rendered logs to ${logFile}`);
|
|
21778
|
-
const logFilePath = path11.resolve(logFile);
|
|
21779
|
-
await mkdir5(path11.dirname(logFilePath), { recursive: true }).catch(() => null);
|
|
21780
|
-
await writeFile4(logFilePath, terminalRender.render());
|
|
21781
|
-
}
|
|
21947
|
+
await saveDeprecatedLogFile(logFile, terminalRender.render(), verbose);
|
|
21782
21948
|
return { exitCode, logs: terminalRender.render() };
|
|
21783
|
-
async function sendEnter(waitms = 1000) {
|
|
21784
|
-
const st = Date.now();
|
|
21785
|
-
await idleWaiter.wait(waitms);
|
|
21786
|
-
const et = Date.now();
|
|
21787
|
-
logger.debug(`sendEn| idleWaiter.wait(${String(waitms)}) took ${String(et - st)}ms`);
|
|
21788
|
-
nextStdout.unready();
|
|
21789
|
-
shell.write("\r");
|
|
21790
|
-
await Promise.race([
|
|
21791
|
-
nextStdout.wait(),
|
|
21792
|
-
new Promise((resolve) => setTimeout(() => {
|
|
21793
|
-
if (!nextStdout.ready) {
|
|
21794
|
-
shell.write("\r");
|
|
21795
|
-
}
|
|
21796
|
-
resolve();
|
|
21797
|
-
}, 1000))
|
|
21798
|
-
]);
|
|
21799
|
-
await Promise.race([
|
|
21800
|
-
nextStdout.wait(),
|
|
21801
|
-
new Promise((resolve) => setTimeout(() => {
|
|
21802
|
-
if (!nextStdout.ready) {
|
|
21803
|
-
shell.write("\r");
|
|
21804
|
-
}
|
|
21805
|
-
resolve();
|
|
21806
|
-
}, 3000))
|
|
21807
|
-
]);
|
|
21808
|
-
}
|
|
21809
|
-
async function sendMessage3(message, { waitForReady = true } = {}) {
|
|
21810
|
-
if (waitForReady)
|
|
21811
|
-
await stdinReady.wait();
|
|
21812
|
-
logger.debug(`send |${message}`);
|
|
21813
|
-
nextStdout.unready();
|
|
21814
|
-
shell.write(message);
|
|
21815
|
-
idleWaiter.ping();
|
|
21816
|
-
logger.debug(`waiting next stdout|${message}`);
|
|
21817
|
-
await nextStdout.wait();
|
|
21818
|
-
logger.debug(`sending enter`);
|
|
21819
|
-
await sendEnter(1000);
|
|
21820
|
-
logger.debug(`sent enter`);
|
|
21821
|
-
}
|
|
21822
21949
|
async function exitAgent() {
|
|
21823
|
-
robust = false;
|
|
21950
|
+
ctx.robust = false;
|
|
21824
21951
|
for (const cmd of cliConf.exitCommands ?? ["/exit"])
|
|
21825
|
-
await sendMessage3(cmd);
|
|
21952
|
+
await sendMessage3(ctx.messageContext, cmd);
|
|
21826
21953
|
let exited = false;
|
|
21827
21954
|
await Promise.race([
|
|
21828
21955
|
pendingExitCode.promise.then(() => exited = true),
|
|
@@ -21834,14 +21961,6 @@ ${prompt}` : prefix;
|
|
|
21834
21961
|
}, 5000))
|
|
21835
21962
|
]);
|
|
21836
21963
|
}
|
|
21837
|
-
function getTerminalDimensions() {
|
|
21838
|
-
if (!process.stdout.isTTY)
|
|
21839
|
-
return { cols: 80, rows: 30 };
|
|
21840
|
-
return {
|
|
21841
|
-
cols: Math.min(Math.max(20, process.stdout.columns), 80),
|
|
21842
|
-
rows: process.stdout.rows
|
|
21843
|
-
};
|
|
21844
|
-
}
|
|
21845
21964
|
}
|
|
21846
21965
|
function sleep2(ms) {
|
|
21847
21966
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -21853,5 +21972,5 @@ export {
|
|
|
21853
21972
|
CLIS_CONFIG
|
|
21854
21973
|
};
|
|
21855
21974
|
|
|
21856
|
-
//# debugId=
|
|
21975
|
+
//# debugId=245641C79D1EE9C764756E2164756E21
|
|
21857
21976
|
//# sourceMappingURL=index.js.map
|