claude-yes 1.33.0 → 1.35.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/dist/cli.js +335 -120
- package/dist/index.js +160 -51
- package/package.json +8 -7
- package/ts/index.ts +63 -11
- package/ts/logger.ts +0 -1
- package/ts/pidStore.ts +152 -47
package/dist/cli.js
CHANGED
|
@@ -20732,24 +20732,81 @@ var init_fifo = __esm(() => {
|
|
|
20732
20732
|
});
|
|
20733
20733
|
|
|
20734
20734
|
// ts/pidStore.ts
|
|
20735
|
-
import Datastore from "@seald-io/nedb";
|
|
20736
20735
|
import { mkdir as mkdir3 } from "fs/promises";
|
|
20737
20736
|
import path9 from "path";
|
|
20738
20737
|
|
|
20738
|
+
class SqliteAdapter {
|
|
20739
|
+
db;
|
|
20740
|
+
async init(dbPath) {
|
|
20741
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
20742
|
+
try {
|
|
20743
|
+
const { Database } = await import("bun:sqlite");
|
|
20744
|
+
this.db = new Database(dbPath);
|
|
20745
|
+
} catch (error) {
|
|
20746
|
+
logger.warn("[pidStore] bun:sqlite not available, falling back to better-sqlite3");
|
|
20747
|
+
const Database = (await import("better-sqlite3")).default;
|
|
20748
|
+
this.db = new Database(dbPath);
|
|
20749
|
+
}
|
|
20750
|
+
} else {
|
|
20751
|
+
const Database = (await import("better-sqlite3")).default;
|
|
20752
|
+
this.db = new Database(dbPath);
|
|
20753
|
+
}
|
|
20754
|
+
}
|
|
20755
|
+
query(sql, params = []) {
|
|
20756
|
+
if (typeof this.db.prepare === "function") {
|
|
20757
|
+
return this.db.prepare(sql).all(params);
|
|
20758
|
+
} else {
|
|
20759
|
+
return this.db.query(sql).all(params);
|
|
20760
|
+
}
|
|
20761
|
+
}
|
|
20762
|
+
run(sql, params = []) {
|
|
20763
|
+
if (typeof this.db.prepare === "function") {
|
|
20764
|
+
return this.db.prepare(sql).run(params);
|
|
20765
|
+
} else {
|
|
20766
|
+
this.db.run(sql, params);
|
|
20767
|
+
return {};
|
|
20768
|
+
}
|
|
20769
|
+
}
|
|
20770
|
+
close() {
|
|
20771
|
+
if (this.db.close) {
|
|
20772
|
+
this.db.close();
|
|
20773
|
+
}
|
|
20774
|
+
}
|
|
20775
|
+
}
|
|
20776
|
+
|
|
20739
20777
|
class PidStore {
|
|
20740
20778
|
db;
|
|
20741
20779
|
baseDir;
|
|
20780
|
+
dbPath;
|
|
20742
20781
|
constructor(workingDir) {
|
|
20743
20782
|
this.baseDir = path9.resolve(workingDir, ".agent-yes");
|
|
20783
|
+
this.dbPath = path9.join(this.baseDir, "pid.sqlite");
|
|
20744
20784
|
}
|
|
20745
20785
|
async init() {
|
|
20746
20786
|
await mkdir3(path9.join(this.baseDir, "logs"), { recursive: true });
|
|
20747
20787
|
await mkdir3(path9.join(this.baseDir, "fifo"), { recursive: true });
|
|
20748
|
-
this.db = new
|
|
20749
|
-
|
|
20750
|
-
|
|
20751
|
-
|
|
20752
|
-
|
|
20788
|
+
this.db = new SqliteAdapter;
|
|
20789
|
+
await this.db.init(this.dbPath);
|
|
20790
|
+
this.db.run("PRAGMA journal_mode=WAL");
|
|
20791
|
+
this.db.run("PRAGMA synchronous=NORMAL");
|
|
20792
|
+
this.db.run("PRAGMA cache_size=1000");
|
|
20793
|
+
this.db.run("PRAGMA temp_store=memory");
|
|
20794
|
+
this.db.run(`
|
|
20795
|
+
CREATE TABLE IF NOT EXISTS pid_records (
|
|
20796
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
20797
|
+
pid INTEGER NOT NULL UNIQUE,
|
|
20798
|
+
cli TEXT NOT NULL,
|
|
20799
|
+
args TEXT NOT NULL,
|
|
20800
|
+
prompt TEXT,
|
|
20801
|
+
logFile TEXT NOT NULL,
|
|
20802
|
+
fifoFile TEXT NOT NULL,
|
|
20803
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
20804
|
+
exitReason TEXT NOT NULL DEFAULT '',
|
|
20805
|
+
exitCode INTEGER,
|
|
20806
|
+
startedAt INTEGER NOT NULL,
|
|
20807
|
+
updatedAt INTEGER NOT NULL
|
|
20808
|
+
)
|
|
20809
|
+
`);
|
|
20753
20810
|
await this.cleanStaleRecords();
|
|
20754
20811
|
}
|
|
20755
20812
|
async registerProcess({
|
|
@@ -20759,29 +20816,43 @@ class PidStore {
|
|
|
20759
20816
|
prompt
|
|
20760
20817
|
}) {
|
|
20761
20818
|
const now = Date.now();
|
|
20762
|
-
const
|
|
20763
|
-
|
|
20764
|
-
|
|
20765
|
-
|
|
20766
|
-
|
|
20767
|
-
|
|
20768
|
-
|
|
20769
|
-
|
|
20770
|
-
|
|
20771
|
-
|
|
20772
|
-
|
|
20773
|
-
|
|
20774
|
-
|
|
20819
|
+
const argsJson = JSON.stringify(args);
|
|
20820
|
+
const logFile = this.getLogPath(pid);
|
|
20821
|
+
const fifoFile = this.getFifoPath(pid);
|
|
20822
|
+
try {
|
|
20823
|
+
this.db.run(`
|
|
20824
|
+
INSERT INTO pid_records (pid, cli, args, prompt, logFile, fifoFile, status, exitReason, startedAt, updatedAt)
|
|
20825
|
+
VALUES (?, ?, ?, ?, ?, ?, 'active', '', ?, ?)
|
|
20826
|
+
`, [pid, cli, argsJson, prompt, logFile, fifoFile, now, now]);
|
|
20827
|
+
} catch (error) {
|
|
20828
|
+
if (error.code === "SQLITE_CONSTRAINT_UNIQUE") {
|
|
20829
|
+
this.db.run(`
|
|
20830
|
+
UPDATE pid_records
|
|
20831
|
+
SET cli = ?, args = ?, prompt = ?, logFile = ?, fifoFile = ?, status = 'active', exitReason = '', startedAt = ?, updatedAt = ?
|
|
20832
|
+
WHERE pid = ?
|
|
20833
|
+
`, [cli, argsJson, prompt, logFile, fifoFile, now, now, pid]);
|
|
20834
|
+
} else {
|
|
20835
|
+
throw error;
|
|
20836
|
+
}
|
|
20837
|
+
}
|
|
20838
|
+
const result = this.db.query("SELECT * FROM pid_records WHERE pid = ?", [pid])[0];
|
|
20839
|
+
if (!result) {
|
|
20840
|
+
const allRecords = this.db.query("SELECT * FROM pid_records");
|
|
20841
|
+
logger.error(`[pidStore] Failed to find record for PID ${pid}. All records:`, allRecords);
|
|
20842
|
+
throw new Error(`Failed to register process ${pid}`);
|
|
20843
|
+
}
|
|
20775
20844
|
logger.debug(`[pidStore] Registered process ${pid}`);
|
|
20776
|
-
return
|
|
20845
|
+
return result;
|
|
20777
20846
|
}
|
|
20778
20847
|
async updateStatus(pid, status, extra) {
|
|
20779
|
-
const
|
|
20780
|
-
|
|
20781
|
-
|
|
20782
|
-
|
|
20783
|
-
|
|
20784
|
-
|
|
20848
|
+
const updatedAt = Date.now();
|
|
20849
|
+
const exitReason = extra?.exitReason || "";
|
|
20850
|
+
const exitCode = extra?.exitCode;
|
|
20851
|
+
if (exitCode !== undefined) {
|
|
20852
|
+
this.db.run("UPDATE pid_records SET status = ?, exitReason = ?, exitCode = ?, updatedAt = ? WHERE pid = ?", [status, exitReason, exitCode, updatedAt, pid]);
|
|
20853
|
+
} else {
|
|
20854
|
+
this.db.run("UPDATE pid_records SET status = ?, exitReason = ?, updatedAt = ? WHERE pid = ?", [status, exitReason, updatedAt, pid]);
|
|
20855
|
+
}
|
|
20785
20856
|
logger.debug(`[pidStore] Updated process ${pid} status=${status}`);
|
|
20786
20857
|
}
|
|
20787
20858
|
getLogPath(pid) {
|
|
@@ -20791,25 +20862,23 @@ class PidStore {
|
|
|
20791
20862
|
return path9.resolve(this.baseDir, "fifo", `${pid}.stdin`);
|
|
20792
20863
|
}
|
|
20793
20864
|
async cleanStaleRecords() {
|
|
20794
|
-
const activeRecords =
|
|
20795
|
-
status: { $ne: "exited" }
|
|
20796
|
-
});
|
|
20865
|
+
const activeRecords = this.db.query("SELECT * FROM pid_records WHERE status != 'exited'");
|
|
20797
20866
|
for (const record of activeRecords) {
|
|
20798
20867
|
if (!this.isProcessAlive(record.pid)) {
|
|
20799
|
-
|
|
20800
|
-
$set: {
|
|
20801
|
-
status: "exited",
|
|
20802
|
-
exitReason: "stale-cleanup",
|
|
20803
|
-
updatedAt: Date.now()
|
|
20804
|
-
}
|
|
20805
|
-
}, {});
|
|
20868
|
+
this.db.run("UPDATE pid_records SET status = 'exited', exitReason = 'stale-cleanup', updatedAt = ? WHERE pid = ?", [Date.now(), record.pid]);
|
|
20806
20869
|
logger.debug(`[pidStore] Cleaned stale record for PID ${record.pid}`);
|
|
20807
20870
|
}
|
|
20808
20871
|
}
|
|
20809
20872
|
}
|
|
20810
20873
|
async close() {
|
|
20811
|
-
|
|
20812
|
-
|
|
20874
|
+
try {
|
|
20875
|
+
this.db.run("PRAGMA optimize");
|
|
20876
|
+
this.db.run("VACUUM");
|
|
20877
|
+
} catch (error) {
|
|
20878
|
+
logger.warn("[pidStore] Failed to optimize database:", error);
|
|
20879
|
+
}
|
|
20880
|
+
this.db.close();
|
|
20881
|
+
logger.debug("[pidStore] Database optimized and closed");
|
|
20813
20882
|
}
|
|
20814
20883
|
isProcessAlive(pid) {
|
|
20815
20884
|
try {
|
|
@@ -20822,10 +20891,9 @@ class PidStore {
|
|
|
20822
20891
|
static async findActiveFifo(workingDir) {
|
|
20823
20892
|
const store = new PidStore(workingDir);
|
|
20824
20893
|
await store.init();
|
|
20825
|
-
const records =
|
|
20894
|
+
const records = store.db.query("SELECT * FROM pid_records WHERE status != 'exited' ORDER BY startedAt DESC LIMIT 1");
|
|
20826
20895
|
await store.close();
|
|
20827
|
-
|
|
20828
|
-
return sorted[0]?.fifoFile ?? null;
|
|
20896
|
+
return records[0]?.fifoFile ?? null;
|
|
20829
20897
|
}
|
|
20830
20898
|
}
|
|
20831
20899
|
var init_pidStore = __esm(() => {
|
|
@@ -20881,8 +20949,12 @@ function getDefaultConfig() {
|
|
|
20881
20949
|
},
|
|
20882
20950
|
claude: {
|
|
20883
20951
|
promptArg: "last-arg",
|
|
20884
|
-
install:
|
|
20885
|
-
|
|
20952
|
+
install: {
|
|
20953
|
+
powershell: "irm https://claude.ai/install.ps1 | iex",
|
|
20954
|
+
bash: "curl -fsSL https://claude.ai/install.sh | bash",
|
|
20955
|
+
npm: "npm i -g @anthropic-ai/claude-code@latest"
|
|
20956
|
+
},
|
|
20957
|
+
ready: [/^\? for shortcuts/, /^> /],
|
|
20886
20958
|
typingRespond: {
|
|
20887
20959
|
"1\n": [/│ Do you want to use this API key\?/]
|
|
20888
20960
|
},
|
|
@@ -21319,6 +21391,26 @@ ${prompt}` : prefix;
|
|
|
21319
21391
|
logger.warn(`Unknown promptArg format: ${cliConf.promptArg}`);
|
|
21320
21392
|
}
|
|
21321
21393
|
}
|
|
21394
|
+
const getInstallCommand = (installConfig) => {
|
|
21395
|
+
if (typeof installConfig === "string") {
|
|
21396
|
+
return installConfig;
|
|
21397
|
+
}
|
|
21398
|
+
const isWindows = process.platform === "win32";
|
|
21399
|
+
const platform3 = isWindows ? "windows" : "unix";
|
|
21400
|
+
if (installConfig[platform3]) {
|
|
21401
|
+
return installConfig[platform3];
|
|
21402
|
+
}
|
|
21403
|
+
if (isWindows && installConfig.powershell) {
|
|
21404
|
+
return installConfig.powershell;
|
|
21405
|
+
}
|
|
21406
|
+
if (!isWindows && installConfig.bash) {
|
|
21407
|
+
return installConfig.bash;
|
|
21408
|
+
}
|
|
21409
|
+
if (installConfig.npm) {
|
|
21410
|
+
return installConfig.npm;
|
|
21411
|
+
}
|
|
21412
|
+
return null;
|
|
21413
|
+
};
|
|
21322
21414
|
const spawn2 = () => {
|
|
21323
21415
|
const cliCommand = cliConf?.binary || cli;
|
|
21324
21416
|
let [bin, ...args] = [...parseCommandString(cliCommand), ...cliArgs];
|
|
@@ -21333,14 +21425,19 @@ ${prompt}` : prefix;
|
|
|
21333
21425
|
logger.error(`Fatal: Failed to start ${cli}.`);
|
|
21334
21426
|
const isNotFound = isCommandNotFoundError(error);
|
|
21335
21427
|
if (cliConf?.install && isNotFound) {
|
|
21336
|
-
|
|
21428
|
+
const installCmd = getInstallCommand(cliConf.install);
|
|
21429
|
+
if (!installCmd) {
|
|
21430
|
+
logger.error(`No suitable install command found for ${cli} on this platform`);
|
|
21431
|
+
throw error;
|
|
21432
|
+
}
|
|
21433
|
+
logger.info(`Please install the cli by run ${installCmd}`);
|
|
21337
21434
|
if (install) {
|
|
21338
21435
|
logger.info(`Attempting to install ${cli}...`);
|
|
21339
|
-
execaCommandSync(
|
|
21436
|
+
execaCommandSync(installCmd, { stdio: "inherit" });
|
|
21340
21437
|
logger.info(`${cli} installed successfully. Please rerun the command.`);
|
|
21341
21438
|
return spawn2();
|
|
21342
21439
|
} else {
|
|
21343
|
-
logger.error(`If you did not installed it yet, Please install it first: ${
|
|
21440
|
+
logger.error(`If you did not installed it yet, Please install it first: ${installCmd}`);
|
|
21344
21441
|
throw error;
|
|
21345
21442
|
}
|
|
21346
21443
|
}
|
|
@@ -21375,7 +21472,10 @@ ${prompt}` : prefix;
|
|
|
21375
21472
|
stdinReady.unready();
|
|
21376
21473
|
const agentCrashed = exitCode2 !== 0;
|
|
21377
21474
|
if (shouldRestartWithoutContinue) {
|
|
21378
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21475
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21476
|
+
exitReason: "restarted",
|
|
21477
|
+
exitCode: exitCode2 ?? undefined
|
|
21478
|
+
});
|
|
21379
21479
|
shouldRestartWithoutContinue = false;
|
|
21380
21480
|
isFatal = false;
|
|
21381
21481
|
const cliCommand = cliConf?.binary || cli;
|
|
@@ -21396,10 +21496,16 @@ ${prompt}` : prefix;
|
|
|
21396
21496
|
return;
|
|
21397
21497
|
}
|
|
21398
21498
|
if (isFatal) {
|
|
21399
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21499
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21500
|
+
exitReason: "fatal",
|
|
21501
|
+
exitCode: exitCode2 ?? undefined
|
|
21502
|
+
});
|
|
21400
21503
|
return pendingExitCode.resolve(exitCode2);
|
|
21401
21504
|
}
|
|
21402
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21505
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21506
|
+
exitReason: "restarted",
|
|
21507
|
+
exitCode: exitCode2 ?? undefined
|
|
21508
|
+
});
|
|
21403
21509
|
logger.info(`${cli} crashed, restarting...`);
|
|
21404
21510
|
let restoreArgs = conf.restoreArgs;
|
|
21405
21511
|
if (cli === "codex") {
|
|
@@ -21418,7 +21524,10 @@ ${prompt}` : prefix;
|
|
|
21418
21524
|
return;
|
|
21419
21525
|
}
|
|
21420
21526
|
const exitReason = agentCrashed ? "crash" : "normal";
|
|
21421
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21527
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
21528
|
+
exitReason,
|
|
21529
|
+
exitCode: exitCode2 ?? undefined
|
|
21530
|
+
});
|
|
21422
21531
|
return pendingExitCode.resolve(exitCode2);
|
|
21423
21532
|
});
|
|
21424
21533
|
process.stdout.on("resize", () => {
|
|
@@ -21835,6 +21944,26 @@ ${prompt}` : prefix;
|
|
|
21835
21944
|
logger.warn(`Unknown promptArg format: ${cliConf.promptArg}`);
|
|
21836
21945
|
}
|
|
21837
21946
|
}
|
|
21947
|
+
const getInstallCommand = (installConfig) => {
|
|
21948
|
+
if (typeof installConfig === "string") {
|
|
21949
|
+
return installConfig;
|
|
21950
|
+
}
|
|
21951
|
+
const isWindows = process.platform === "win32";
|
|
21952
|
+
const platform3 = isWindows ? "windows" : "unix";
|
|
21953
|
+
if (installConfig[platform3]) {
|
|
21954
|
+
return installConfig[platform3];
|
|
21955
|
+
}
|
|
21956
|
+
if (isWindows && installConfig.powershell) {
|
|
21957
|
+
return installConfig.powershell;
|
|
21958
|
+
}
|
|
21959
|
+
if (!isWindows && installConfig.bash) {
|
|
21960
|
+
return installConfig.bash;
|
|
21961
|
+
}
|
|
21962
|
+
if (installConfig.npm) {
|
|
21963
|
+
return installConfig.npm;
|
|
21964
|
+
}
|
|
21965
|
+
return null;
|
|
21966
|
+
};
|
|
21838
21967
|
const spawn2 = () => {
|
|
21839
21968
|
const cliCommand = cliConf?.binary || cli;
|
|
21840
21969
|
let [bin, ...args] = [...parseCommandString(cliCommand), ...cliArgs];
|
|
@@ -21849,14 +21978,19 @@ ${prompt}` : prefix;
|
|
|
21849
21978
|
logger.error(`Fatal: Failed to start ${cli}.`);
|
|
21850
21979
|
const isNotFound = isCommandNotFoundError(error);
|
|
21851
21980
|
if (cliConf?.install && isNotFound) {
|
|
21852
|
-
|
|
21981
|
+
const installCmd = getInstallCommand(cliConf.install);
|
|
21982
|
+
if (!installCmd) {
|
|
21983
|
+
logger.error(`No suitable install command found for ${cli} on this platform`);
|
|
21984
|
+
throw error;
|
|
21985
|
+
}
|
|
21986
|
+
logger.info(`Please install the cli by run ${installCmd}`);
|
|
21853
21987
|
if (install) {
|
|
21854
21988
|
logger.info(`Attempting to install ${cli}...`);
|
|
21855
|
-
execaCommandSync(
|
|
21989
|
+
execaCommandSync(installCmd, { stdio: "inherit" });
|
|
21856
21990
|
logger.info(`${cli} installed successfully. Please rerun the command.`);
|
|
21857
21991
|
return spawn2();
|
|
21858
21992
|
} else {
|
|
21859
|
-
logger.error(`If you did not installed it yet, Please install it first: ${
|
|
21993
|
+
logger.error(`If you did not installed it yet, Please install it first: ${installCmd}`);
|
|
21860
21994
|
throw error;
|
|
21861
21995
|
}
|
|
21862
21996
|
}
|
|
@@ -21891,7 +22025,10 @@ ${prompt}` : prefix;
|
|
|
21891
22025
|
stdinReady.unready();
|
|
21892
22026
|
const agentCrashed = exitCode2 !== 0;
|
|
21893
22027
|
if (shouldRestartWithoutContinue) {
|
|
21894
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22028
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22029
|
+
exitReason: "restarted",
|
|
22030
|
+
exitCode: exitCode2 ?? undefined
|
|
22031
|
+
});
|
|
21895
22032
|
shouldRestartWithoutContinue = false;
|
|
21896
22033
|
isFatal = false;
|
|
21897
22034
|
const cliCommand = cliConf?.binary || cli;
|
|
@@ -21912,10 +22049,16 @@ ${prompt}` : prefix;
|
|
|
21912
22049
|
return;
|
|
21913
22050
|
}
|
|
21914
22051
|
if (isFatal) {
|
|
21915
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22052
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22053
|
+
exitReason: "fatal",
|
|
22054
|
+
exitCode: exitCode2 ?? undefined
|
|
22055
|
+
});
|
|
21916
22056
|
return pendingExitCode.resolve(exitCode2);
|
|
21917
22057
|
}
|
|
21918
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22058
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22059
|
+
exitReason: "restarted",
|
|
22060
|
+
exitCode: exitCode2 ?? undefined
|
|
22061
|
+
});
|
|
21919
22062
|
logger.info(`${cli} crashed, restarting...`);
|
|
21920
22063
|
let restoreArgs = conf.restoreArgs;
|
|
21921
22064
|
if (cli === "codex") {
|
|
@@ -21934,7 +22077,10 @@ ${prompt}` : prefix;
|
|
|
21934
22077
|
return;
|
|
21935
22078
|
}
|
|
21936
22079
|
const exitReason = agentCrashed ? "crash" : "normal";
|
|
21937
|
-
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22080
|
+
await pidStore.updateStatus(shell.pid, "exited", {
|
|
22081
|
+
exitReason,
|
|
22082
|
+
exitCode: exitCode2 ?? undefined
|
|
22083
|
+
});
|
|
21938
22084
|
return pendingExitCode.resolve(exitCode2);
|
|
21939
22085
|
});
|
|
21940
22086
|
process.stdout.on("resize", () => {
|
|
@@ -27577,10 +27723,10 @@ var package_default = {
|
|
|
27577
27723
|
url: "git+https://github.com/snomiao/agent-yes.git"
|
|
27578
27724
|
},
|
|
27579
27725
|
bin: {
|
|
27580
|
-
ay: "./dist/agent-yes.js",
|
|
27581
27726
|
"agent-yes": "./dist/agent-yes.js",
|
|
27582
27727
|
"amp-yes": "./dist/amp-yes.js",
|
|
27583
27728
|
"auggie-yes": "./dist/auggie-yes.js",
|
|
27729
|
+
ay: "./dist/agent-yes.js",
|
|
27584
27730
|
"claude-yes": "./dist/claude-yes.js",
|
|
27585
27731
|
"codex-yes": "./dist/codex-yes.js",
|
|
27586
27732
|
"copilot-yes": "./dist/copilot-yes.js",
|
|
@@ -27593,10 +27739,10 @@ var package_default = {
|
|
|
27593
27739
|
doc: "docs"
|
|
27594
27740
|
},
|
|
27595
27741
|
files: [
|
|
27596
|
-
"dist/**/*.js",
|
|
27597
|
-
"!dist/**/*.map",
|
|
27598
27742
|
"scripts",
|
|
27599
|
-
"ts/*.ts"
|
|
27743
|
+
"ts/*.ts",
|
|
27744
|
+
"!dist/**/*.map",
|
|
27745
|
+
"dist/**/*.js"
|
|
27600
27746
|
],
|
|
27601
27747
|
type: "module",
|
|
27602
27748
|
module: "ts/index.ts",
|
|
@@ -27610,7 +27756,7 @@ var package_default = {
|
|
|
27610
27756
|
registry: "https://registry.npmjs.org/"
|
|
27611
27757
|
},
|
|
27612
27758
|
scripts: {
|
|
27613
|
-
build: "bun build ./ts/cli.ts ./ts/index.ts --outdir=dist --target=node --sourcemap --external
|
|
27759
|
+
build: "bun build ./ts/cli.ts ./ts/index.ts --outdir=dist --target=node --sourcemap --external=better-sqlite3 --external=@snomiao/bun-pty --external=bun-pty --external=node-pty --external=from-node-stream --external=bun",
|
|
27614
27760
|
postbuild: "bun ./ts/postbuild.ts",
|
|
27615
27761
|
demo: "bun run build && bun link && claude-yes -- demo",
|
|
27616
27762
|
dev: "bun ts/index.ts",
|
|
@@ -27622,27 +27768,13 @@ var package_default = {
|
|
|
27622
27768
|
test: "bun test --coverage"
|
|
27623
27769
|
},
|
|
27624
27770
|
dependencies: {
|
|
27625
|
-
"@seald-io/nedb": "^4.0.4",
|
|
27626
27771
|
"@snomiao/bun-pty": "^0.3.4",
|
|
27627
27772
|
"bun-pty": "^0.4.8",
|
|
27773
|
+
"better-sqlite3": "^12.1.0",
|
|
27628
27774
|
"from-node-stream": "^0.1.2"
|
|
27629
27775
|
},
|
|
27630
27776
|
devDependencies: {
|
|
27631
27777
|
"@anthropic-ai/sdk": "^0.71.2",
|
|
27632
|
-
"cpu-wait": "^0.0.10",
|
|
27633
|
-
execa: "^9.6.1",
|
|
27634
|
-
ink: "^6.6.0",
|
|
27635
|
-
ms: "^2.1.3",
|
|
27636
|
-
openai: "^6.16.0",
|
|
27637
|
-
"p-map": "^7.0.4",
|
|
27638
|
-
phpdie: "^1.7.0",
|
|
27639
|
-
rambda: "^11.0.1",
|
|
27640
|
-
sflow: "^1.27.0",
|
|
27641
|
-
"strip-ansi-control-characters": "^2.0.0",
|
|
27642
|
-
"terminal-render": "^1.2.2",
|
|
27643
|
-
"tsa-composer": "^3.0.3",
|
|
27644
|
-
winston: "^3.19.0",
|
|
27645
|
-
yargs: "^18.0.0",
|
|
27646
27778
|
"@semantic-release/changelog": "^6.0.3",
|
|
27647
27779
|
"@semantic-release/exec": "^7.1.0",
|
|
27648
27780
|
"@semantic-release/git": "^10.0.1",
|
|
@@ -27650,16 +27782,31 @@ var package_default = {
|
|
|
27650
27782
|
"@types/bun": "^1.3.6",
|
|
27651
27783
|
"@types/jest": "^30.0.0",
|
|
27652
27784
|
"@types/ms": "^2.1.0",
|
|
27785
|
+
"@types/better-sqlite3": "^7.6.12",
|
|
27653
27786
|
"@types/node": "^25.0.10",
|
|
27654
27787
|
"@types/yargs": "^17.0.35",
|
|
27788
|
+
"cpu-wait": "^0.0.10",
|
|
27789
|
+
execa: "^9.6.1",
|
|
27655
27790
|
husky: "^9.1.7",
|
|
27791
|
+
ink: "^6.6.0",
|
|
27656
27792
|
"lint-staged": "^16.2.7",
|
|
27793
|
+
ms: "^2.1.3",
|
|
27657
27794
|
"node-pty": "^1.1.0",
|
|
27795
|
+
openai: "^6.16.0",
|
|
27658
27796
|
oxfmt: "^0.26.0",
|
|
27659
27797
|
oxlint: "^1.41.0",
|
|
27798
|
+
"p-map": "^7.0.4",
|
|
27799
|
+
phpdie: "^1.7.0",
|
|
27800
|
+
rambda: "^11.0.1",
|
|
27660
27801
|
"semantic-release": "^25.0.2",
|
|
27802
|
+
sflow: "^1.27.0",
|
|
27661
27803
|
"standard-version": "^9.5.0",
|
|
27662
|
-
|
|
27804
|
+
"strip-ansi-control-characters": "^2.0.0",
|
|
27805
|
+
"terminal-render": "^1.2.2",
|
|
27806
|
+
"tsa-composer": "^3.0.3",
|
|
27807
|
+
vitest: "^4.0.17",
|
|
27808
|
+
winston: "^3.19.0",
|
|
27809
|
+
yargs: "^18.0.0"
|
|
27663
27810
|
},
|
|
27664
27811
|
peerDependencies: {
|
|
27665
27812
|
"node-pty": "latest",
|
|
@@ -27846,24 +27993,81 @@ var logger2 = import_winston3.default.createLogger({
|
|
|
27846
27993
|
|
|
27847
27994
|
// ts/pidStore.ts
|
|
27848
27995
|
init_logger();
|
|
27849
|
-
import Datastore2 from "@seald-io/nedb";
|
|
27850
27996
|
import { mkdir as mkdir6 } from "fs/promises";
|
|
27851
27997
|
import path12 from "path";
|
|
27852
27998
|
|
|
27999
|
+
class SqliteAdapter2 {
|
|
28000
|
+
db;
|
|
28001
|
+
async init(dbPath) {
|
|
28002
|
+
if (typeof globalThis.Bun !== "undefined") {
|
|
28003
|
+
try {
|
|
28004
|
+
const { Database } = await import("bun:sqlite");
|
|
28005
|
+
this.db = new Database(dbPath);
|
|
28006
|
+
} catch (error) {
|
|
28007
|
+
logger.warn("[pidStore] bun:sqlite not available, falling back to better-sqlite3");
|
|
28008
|
+
const Database = (await import("better-sqlite3")).default;
|
|
28009
|
+
this.db = new Database(dbPath);
|
|
28010
|
+
}
|
|
28011
|
+
} else {
|
|
28012
|
+
const Database = (await import("better-sqlite3")).default;
|
|
28013
|
+
this.db = new Database(dbPath);
|
|
28014
|
+
}
|
|
28015
|
+
}
|
|
28016
|
+
query(sql, params = []) {
|
|
28017
|
+
if (typeof this.db.prepare === "function") {
|
|
28018
|
+
return this.db.prepare(sql).all(params);
|
|
28019
|
+
} else {
|
|
28020
|
+
return this.db.query(sql).all(params);
|
|
28021
|
+
}
|
|
28022
|
+
}
|
|
28023
|
+
run(sql, params = []) {
|
|
28024
|
+
if (typeof this.db.prepare === "function") {
|
|
28025
|
+
return this.db.prepare(sql).run(params);
|
|
28026
|
+
} else {
|
|
28027
|
+
this.db.run(sql, params);
|
|
28028
|
+
return {};
|
|
28029
|
+
}
|
|
28030
|
+
}
|
|
28031
|
+
close() {
|
|
28032
|
+
if (this.db.close) {
|
|
28033
|
+
this.db.close();
|
|
28034
|
+
}
|
|
28035
|
+
}
|
|
28036
|
+
}
|
|
28037
|
+
|
|
27853
28038
|
class PidStore2 {
|
|
27854
28039
|
db;
|
|
27855
28040
|
baseDir;
|
|
28041
|
+
dbPath;
|
|
27856
28042
|
constructor(workingDir) {
|
|
27857
28043
|
this.baseDir = path12.resolve(workingDir, ".agent-yes");
|
|
28044
|
+
this.dbPath = path12.join(this.baseDir, "pid.sqlite");
|
|
27858
28045
|
}
|
|
27859
28046
|
async init() {
|
|
27860
28047
|
await mkdir6(path12.join(this.baseDir, "logs"), { recursive: true });
|
|
27861
28048
|
await mkdir6(path12.join(this.baseDir, "fifo"), { recursive: true });
|
|
27862
|
-
this.db = new
|
|
27863
|
-
|
|
27864
|
-
|
|
27865
|
-
|
|
27866
|
-
|
|
28049
|
+
this.db = new SqliteAdapter2;
|
|
28050
|
+
await this.db.init(this.dbPath);
|
|
28051
|
+
this.db.run("PRAGMA journal_mode=WAL");
|
|
28052
|
+
this.db.run("PRAGMA synchronous=NORMAL");
|
|
28053
|
+
this.db.run("PRAGMA cache_size=1000");
|
|
28054
|
+
this.db.run("PRAGMA temp_store=memory");
|
|
28055
|
+
this.db.run(`
|
|
28056
|
+
CREATE TABLE IF NOT EXISTS pid_records (
|
|
28057
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
28058
|
+
pid INTEGER NOT NULL UNIQUE,
|
|
28059
|
+
cli TEXT NOT NULL,
|
|
28060
|
+
args TEXT NOT NULL,
|
|
28061
|
+
prompt TEXT,
|
|
28062
|
+
logFile TEXT NOT NULL,
|
|
28063
|
+
fifoFile TEXT NOT NULL,
|
|
28064
|
+
status TEXT NOT NULL DEFAULT 'active',
|
|
28065
|
+
exitReason TEXT NOT NULL DEFAULT '',
|
|
28066
|
+
exitCode INTEGER,
|
|
28067
|
+
startedAt INTEGER NOT NULL,
|
|
28068
|
+
updatedAt INTEGER NOT NULL
|
|
28069
|
+
)
|
|
28070
|
+
`);
|
|
27867
28071
|
await this.cleanStaleRecords();
|
|
27868
28072
|
}
|
|
27869
28073
|
async registerProcess({
|
|
@@ -27873,29 +28077,43 @@ class PidStore2 {
|
|
|
27873
28077
|
prompt
|
|
27874
28078
|
}) {
|
|
27875
28079
|
const now = Date.now();
|
|
27876
|
-
const
|
|
27877
|
-
|
|
27878
|
-
|
|
27879
|
-
|
|
27880
|
-
|
|
27881
|
-
|
|
27882
|
-
|
|
27883
|
-
|
|
27884
|
-
|
|
27885
|
-
|
|
27886
|
-
|
|
27887
|
-
|
|
27888
|
-
|
|
28080
|
+
const argsJson = JSON.stringify(args);
|
|
28081
|
+
const logFile = this.getLogPath(pid);
|
|
28082
|
+
const fifoFile = this.getFifoPath(pid);
|
|
28083
|
+
try {
|
|
28084
|
+
this.db.run(`
|
|
28085
|
+
INSERT INTO pid_records (pid, cli, args, prompt, logFile, fifoFile, status, exitReason, startedAt, updatedAt)
|
|
28086
|
+
VALUES (?, ?, ?, ?, ?, ?, 'active', '', ?, ?)
|
|
28087
|
+
`, [pid, cli, argsJson, prompt, logFile, fifoFile, now, now]);
|
|
28088
|
+
} catch (error) {
|
|
28089
|
+
if (error.code === "SQLITE_CONSTRAINT_UNIQUE") {
|
|
28090
|
+
this.db.run(`
|
|
28091
|
+
UPDATE pid_records
|
|
28092
|
+
SET cli = ?, args = ?, prompt = ?, logFile = ?, fifoFile = ?, status = 'active', exitReason = '', startedAt = ?, updatedAt = ?
|
|
28093
|
+
WHERE pid = ?
|
|
28094
|
+
`, [cli, argsJson, prompt, logFile, fifoFile, now, now, pid]);
|
|
28095
|
+
} else {
|
|
28096
|
+
throw error;
|
|
28097
|
+
}
|
|
28098
|
+
}
|
|
28099
|
+
const result = this.db.query("SELECT * FROM pid_records WHERE pid = ?", [pid])[0];
|
|
28100
|
+
if (!result) {
|
|
28101
|
+
const allRecords = this.db.query("SELECT * FROM pid_records");
|
|
28102
|
+
logger.error(`[pidStore] Failed to find record for PID ${pid}. All records:`, allRecords);
|
|
28103
|
+
throw new Error(`Failed to register process ${pid}`);
|
|
28104
|
+
}
|
|
27889
28105
|
logger.debug(`[pidStore] Registered process ${pid}`);
|
|
27890
|
-
return
|
|
28106
|
+
return result;
|
|
27891
28107
|
}
|
|
27892
28108
|
async updateStatus(pid, status, extra) {
|
|
27893
|
-
const
|
|
27894
|
-
|
|
27895
|
-
|
|
27896
|
-
|
|
27897
|
-
|
|
27898
|
-
|
|
28109
|
+
const updatedAt = Date.now();
|
|
28110
|
+
const exitReason = extra?.exitReason || "";
|
|
28111
|
+
const exitCode = extra?.exitCode;
|
|
28112
|
+
if (exitCode !== undefined) {
|
|
28113
|
+
this.db.run("UPDATE pid_records SET status = ?, exitReason = ?, exitCode = ?, updatedAt = ? WHERE pid = ?", [status, exitReason, exitCode, updatedAt, pid]);
|
|
28114
|
+
} else {
|
|
28115
|
+
this.db.run("UPDATE pid_records SET status = ?, exitReason = ?, updatedAt = ? WHERE pid = ?", [status, exitReason, updatedAt, pid]);
|
|
28116
|
+
}
|
|
27899
28117
|
logger.debug(`[pidStore] Updated process ${pid} status=${status}`);
|
|
27900
28118
|
}
|
|
27901
28119
|
getLogPath(pid) {
|
|
@@ -27905,25 +28123,23 @@ class PidStore2 {
|
|
|
27905
28123
|
return path12.resolve(this.baseDir, "fifo", `${pid}.stdin`);
|
|
27906
28124
|
}
|
|
27907
28125
|
async cleanStaleRecords() {
|
|
27908
|
-
const activeRecords =
|
|
27909
|
-
status: { $ne: "exited" }
|
|
27910
|
-
});
|
|
28126
|
+
const activeRecords = this.db.query("SELECT * FROM pid_records WHERE status != 'exited'");
|
|
27911
28127
|
for (const record of activeRecords) {
|
|
27912
28128
|
if (!this.isProcessAlive(record.pid)) {
|
|
27913
|
-
|
|
27914
|
-
$set: {
|
|
27915
|
-
status: "exited",
|
|
27916
|
-
exitReason: "stale-cleanup",
|
|
27917
|
-
updatedAt: Date.now()
|
|
27918
|
-
}
|
|
27919
|
-
}, {});
|
|
28129
|
+
this.db.run("UPDATE pid_records SET status = 'exited', exitReason = 'stale-cleanup', updatedAt = ? WHERE pid = ?", [Date.now(), record.pid]);
|
|
27920
28130
|
logger.debug(`[pidStore] Cleaned stale record for PID ${record.pid}`);
|
|
27921
28131
|
}
|
|
27922
28132
|
}
|
|
27923
28133
|
}
|
|
27924
28134
|
async close() {
|
|
27925
|
-
|
|
27926
|
-
|
|
28135
|
+
try {
|
|
28136
|
+
this.db.run("PRAGMA optimize");
|
|
28137
|
+
this.db.run("VACUUM");
|
|
28138
|
+
} catch (error) {
|
|
28139
|
+
logger.warn("[pidStore] Failed to optimize database:", error);
|
|
28140
|
+
}
|
|
28141
|
+
this.db.close();
|
|
28142
|
+
logger.debug("[pidStore] Database optimized and closed");
|
|
27927
28143
|
}
|
|
27928
28144
|
isProcessAlive(pid) {
|
|
27929
28145
|
try {
|
|
@@ -27936,10 +28152,9 @@ class PidStore2 {
|
|
|
27936
28152
|
static async findActiveFifo(workingDir) {
|
|
27937
28153
|
const store = new PidStore2(workingDir);
|
|
27938
28154
|
await store.init();
|
|
27939
|
-
const records =
|
|
28155
|
+
const records = store.db.query("SELECT * FROM pid_records WHERE status != 'exited' ORDER BY startedAt DESC LIMIT 1");
|
|
27940
28156
|
await store.close();
|
|
27941
|
-
|
|
27942
|
-
return sorted[0]?.fifoFile ?? null;
|
|
28157
|
+
return records[0]?.fifoFile ?? null;
|
|
27943
28158
|
}
|
|
27944
28159
|
}
|
|
27945
28160
|
|
|
@@ -27972,5 +28187,5 @@ var { exitCode } = await cliYes(config3);
|
|
|
27972
28187
|
console.log("exiting process");
|
|
27973
28188
|
process.exit(exitCode ?? 1);
|
|
27974
28189
|
|
|
27975
|
-
//# debugId=
|
|
28190
|
+
//# debugId=C4007A87ED18C3B264756E2164756E21
|
|
27976
28191
|
//# sourceMappingURL=cli.js.map
|