newtype-profile 1.0.18 → 1.0.19
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/index.js +1 -1
- package/dist/index.js +188 -223
- package/dist/shared/spawn.d.ts +29 -0
- package/dist/tools/lsp/client.d.ts +1 -0
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -2253,7 +2253,7 @@ var require_picocolors = __commonJS((exports, module) => {
|
|
|
2253
2253
|
var require_package = __commonJS((exports, module) => {
|
|
2254
2254
|
module.exports = {
|
|
2255
2255
|
name: "newtype-profile",
|
|
2256
|
-
version: "1.0.
|
|
2256
|
+
version: "1.0.19",
|
|
2257
2257
|
description: "AI Agent Collaboration System for Content Creation - Based on oh-my-opencode",
|
|
2258
2258
|
main: "dist/index.js",
|
|
2259
2259
|
types: "dist/index.d.ts",
|
package/dist/index.js
CHANGED
|
@@ -8502,7 +8502,7 @@ var require_cross_spawn = __commonJS((exports, module) => {
|
|
|
8502
8502
|
var cp = __require("child_process");
|
|
8503
8503
|
var parse7 = require_parse2();
|
|
8504
8504
|
var enoent = require_enoent();
|
|
8505
|
-
function
|
|
8505
|
+
function spawn5(command, args, options) {
|
|
8506
8506
|
const parsed = parse7(command, args, options);
|
|
8507
8507
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
8508
8508
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -8514,8 +8514,8 @@ var require_cross_spawn = __commonJS((exports, module) => {
|
|
|
8514
8514
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
8515
8515
|
return result;
|
|
8516
8516
|
}
|
|
8517
|
-
module.exports =
|
|
8518
|
-
module.exports.spawn =
|
|
8517
|
+
module.exports = spawn5;
|
|
8518
|
+
module.exports.spawn = spawn5;
|
|
8519
8519
|
module.exports.sync = spawnSync2;
|
|
8520
8520
|
module.exports._parse = parse7;
|
|
8521
8521
|
module.exports._enoent = enoent;
|
|
@@ -9050,8 +9050,57 @@ ${CONTEXT_REMINDER}
|
|
|
9050
9050
|
// src/hooks/session-notification.ts
|
|
9051
9051
|
import { platform } from "os";
|
|
9052
9052
|
|
|
9053
|
+
// src/shared/spawn.ts
|
|
9054
|
+
import { spawn as nodeSpawn } from "child_process";
|
|
9055
|
+
import { writeFile } from "fs/promises";
|
|
9056
|
+
function spawnAsync(command, options = {}) {
|
|
9057
|
+
return new Promise((resolve, reject) => {
|
|
9058
|
+
const [cmd, ...args] = command;
|
|
9059
|
+
const proc = nodeSpawn(cmd, args, {
|
|
9060
|
+
cwd: options.cwd,
|
|
9061
|
+
stdio: [options.stdin ? "pipe" : "ignore", "pipe", "pipe"]
|
|
9062
|
+
});
|
|
9063
|
+
let stdout = "";
|
|
9064
|
+
let stderr = "";
|
|
9065
|
+
let killed = false;
|
|
9066
|
+
const timeoutId = options.timeout ? setTimeout(() => {
|
|
9067
|
+
killed = true;
|
|
9068
|
+
proc.kill();
|
|
9069
|
+
reject(new Error(`Timeout after ${options.timeout}ms`));
|
|
9070
|
+
}, options.timeout) : null;
|
|
9071
|
+
if (options.stdin && proc.stdin) {
|
|
9072
|
+
proc.stdin.write(options.stdin);
|
|
9073
|
+
proc.stdin.end();
|
|
9074
|
+
}
|
|
9075
|
+
proc.stdout?.on("data", (data) => {
|
|
9076
|
+
stdout += data.toString();
|
|
9077
|
+
});
|
|
9078
|
+
proc.stderr?.on("data", (data) => {
|
|
9079
|
+
stderr += data.toString();
|
|
9080
|
+
});
|
|
9081
|
+
proc.on("close", (code) => {
|
|
9082
|
+
if (timeoutId)
|
|
9083
|
+
clearTimeout(timeoutId);
|
|
9084
|
+
if (!killed) {
|
|
9085
|
+
resolve({ stdout, stderr, exitCode: code ?? 1 });
|
|
9086
|
+
}
|
|
9087
|
+
});
|
|
9088
|
+
proc.on("error", (err) => {
|
|
9089
|
+
if (timeoutId)
|
|
9090
|
+
clearTimeout(timeoutId);
|
|
9091
|
+
reject(err);
|
|
9092
|
+
});
|
|
9093
|
+
});
|
|
9094
|
+
}
|
|
9095
|
+
async function writeFileSafe(path3, data) {
|
|
9096
|
+
if (data instanceof ArrayBuffer) {
|
|
9097
|
+
await writeFile(path3, Buffer.from(data));
|
|
9098
|
+
} else {
|
|
9099
|
+
await writeFile(path3, data);
|
|
9100
|
+
}
|
|
9101
|
+
}
|
|
9102
|
+
|
|
9053
9103
|
// src/hooks/session-notification-utils.ts
|
|
9054
|
-
var {spawn } = globalThis.Bun;
|
|
9055
9104
|
var notifySendPath = null;
|
|
9056
9105
|
var notifySendPromise = null;
|
|
9057
9106
|
var osascriptPath = null;
|
|
@@ -9068,16 +9117,11 @@ async function findCommand(commandName) {
|
|
|
9068
9117
|
const isWindows = process.platform === "win32";
|
|
9069
9118
|
const cmd = isWindows ? "where" : "which";
|
|
9070
9119
|
try {
|
|
9071
|
-
const
|
|
9072
|
-
|
|
9073
|
-
stderr: "pipe"
|
|
9074
|
-
});
|
|
9075
|
-
const exitCode = await proc.exited;
|
|
9076
|
-
if (exitCode !== 0) {
|
|
9120
|
+
const result = await spawnAsync([cmd, commandName]);
|
|
9121
|
+
if (result.exitCode !== 0) {
|
|
9077
9122
|
return null;
|
|
9078
9123
|
}
|
|
9079
|
-
const
|
|
9080
|
-
const path3 = stdout.trim().split(`
|
|
9124
|
+
const path3 = result.stdout.trim().split(`
|
|
9081
9125
|
`)[0];
|
|
9082
9126
|
if (!path3) {
|
|
9083
9127
|
return null;
|
|
@@ -9965,7 +10009,6 @@ function createSessionRecoveryHook(ctx, options) {
|
|
|
9965
10009
|
};
|
|
9966
10010
|
}
|
|
9967
10011
|
// src/hooks/comment-checker/cli.ts
|
|
9968
|
-
var {spawn: spawn3 } = globalThis.Bun;
|
|
9969
10012
|
import { createRequire as createRequire2 } from "module";
|
|
9970
10013
|
import { dirname, join as join9 } from "path";
|
|
9971
10014
|
import { existsSync as existsSync5 } from "fs";
|
|
@@ -9973,7 +10016,6 @@ import * as fs2 from "fs";
|
|
|
9973
10016
|
import { tmpdir as tmpdir3 } from "os";
|
|
9974
10017
|
|
|
9975
10018
|
// src/hooks/comment-checker/downloader.ts
|
|
9976
|
-
var {spawn: spawn2 } = globalThis.Bun;
|
|
9977
10019
|
import { existsSync as existsSync4, mkdirSync as mkdirSync3, chmodSync, unlinkSync as unlinkSync2, appendFileSync as appendFileSync2 } from "fs";
|
|
9978
10020
|
import { join as join8 } from "path";
|
|
9979
10021
|
import { homedir as homedir2, tmpdir as tmpdir2 } from "os";
|
|
@@ -10023,29 +10065,17 @@ function getPackageVersion() {
|
|
|
10023
10065
|
}
|
|
10024
10066
|
async function extractTarGz(archivePath, destDir) {
|
|
10025
10067
|
debugLog("Extracting tar.gz:", archivePath, "to", destDir);
|
|
10026
|
-
const
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
});
|
|
10030
|
-
const exitCode = await proc.exited;
|
|
10031
|
-
if (exitCode !== 0) {
|
|
10032
|
-
const stderr = await new Response(proc.stderr).text();
|
|
10033
|
-
throw new Error(`tar extraction failed (exit ${exitCode}): ${stderr}`);
|
|
10068
|
+
const result = await spawnAsync(["tar", "-xzf", archivePath, "-C", destDir]);
|
|
10069
|
+
if (result.exitCode !== 0) {
|
|
10070
|
+
throw new Error(`tar extraction failed (exit ${result.exitCode}): ${result.stderr}`);
|
|
10034
10071
|
}
|
|
10035
10072
|
}
|
|
10036
10073
|
async function extractZip(archivePath, destDir) {
|
|
10037
10074
|
debugLog("Extracting zip:", archivePath, "to", destDir);
|
|
10038
|
-
const
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
stdout: "pipe",
|
|
10043
|
-
stderr: "pipe"
|
|
10044
|
-
});
|
|
10045
|
-
const exitCode = await proc.exited;
|
|
10046
|
-
if (exitCode !== 0) {
|
|
10047
|
-
const stderr = await new Response(proc.stderr).text();
|
|
10048
|
-
throw new Error(`zip extraction failed (exit ${exitCode}): ${stderr}`);
|
|
10075
|
+
const command = process.platform === "win32" ? ["powershell", "-command", `Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force`] : ["unzip", "-o", archivePath, "-d", destDir];
|
|
10076
|
+
const result = await spawnAsync(command);
|
|
10077
|
+
if (result.exitCode !== 0) {
|
|
10078
|
+
throw new Error(`zip extraction failed (exit ${result.exitCode}): ${result.stderr}`);
|
|
10049
10079
|
}
|
|
10050
10080
|
}
|
|
10051
10081
|
async function downloadCommentChecker() {
|
|
@@ -10078,7 +10108,7 @@ async function downloadCommentChecker() {
|
|
|
10078
10108
|
}
|
|
10079
10109
|
const archivePath = join8(cacheDir, assetName);
|
|
10080
10110
|
const arrayBuffer = await response.arrayBuffer();
|
|
10081
|
-
await
|
|
10111
|
+
await writeFileSafe(archivePath, arrayBuffer);
|
|
10082
10112
|
debugLog(`Downloaded archive to: ${archivePath}`);
|
|
10083
10113
|
if (ext === "tar.gz") {
|
|
10084
10114
|
await extractTarGz(archivePath, cacheDir);
|
|
@@ -10205,24 +10235,15 @@ async function runCommentChecker(input, cliPath, customPrompt) {
|
|
|
10205
10235
|
if (customPrompt) {
|
|
10206
10236
|
args.push("--prompt", customPrompt);
|
|
10207
10237
|
}
|
|
10208
|
-
const
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
stderr: "pipe"
|
|
10212
|
-
});
|
|
10213
|
-
proc.stdin.write(jsonInput);
|
|
10214
|
-
proc.stdin.end();
|
|
10215
|
-
const stdout = await new Response(proc.stdout).text();
|
|
10216
|
-
const stderr = await new Response(proc.stderr).text();
|
|
10217
|
-
const exitCode = await proc.exited;
|
|
10218
|
-
debugLog2("exit code:", exitCode, "stdout length:", stdout.length, "stderr length:", stderr.length);
|
|
10219
|
-
if (exitCode === 0) {
|
|
10238
|
+
const result = await spawnAsync(args, { stdin: jsonInput });
|
|
10239
|
+
debugLog2("exit code:", result.exitCode, "stdout length:", result.stdout.length, "stderr length:", result.stderr.length);
|
|
10240
|
+
if (result.exitCode === 0) {
|
|
10220
10241
|
return { hasComments: false, message: "" };
|
|
10221
10242
|
}
|
|
10222
|
-
if (exitCode === 2) {
|
|
10223
|
-
return { hasComments: true, message: stderr };
|
|
10243
|
+
if (result.exitCode === 2) {
|
|
10244
|
+
return { hasComments: true, message: result.stderr };
|
|
10224
10245
|
}
|
|
10225
|
-
debugLog2("unexpected exit code:", exitCode, "stderr:", stderr);
|
|
10246
|
+
debugLog2("unexpected exit code:", result.exitCode, "stderr:", result.stderr);
|
|
10226
10247
|
return { hasComments: false, message: "" };
|
|
10227
10248
|
} catch (err) {
|
|
10228
10249
|
debugLog2("failed to run comment-checker:", err);
|
|
@@ -15374,7 +15395,7 @@ function parseFrontmatter(content) {
|
|
|
15374
15395
|
}
|
|
15375
15396
|
}
|
|
15376
15397
|
// src/shared/command-executor.ts
|
|
15377
|
-
import { spawn
|
|
15398
|
+
import { spawn } from "child_process";
|
|
15378
15399
|
import { exec } from "child_process";
|
|
15379
15400
|
import { promisify } from "util";
|
|
15380
15401
|
import { existsSync as existsSync17 } from "fs";
|
|
@@ -15419,7 +15440,7 @@ async function executeHookCommand(command, stdin, cwd, options) {
|
|
|
15419
15440
|
}
|
|
15420
15441
|
}
|
|
15421
15442
|
return new Promise((resolve3) => {
|
|
15422
|
-
const proc =
|
|
15443
|
+
const proc = spawn(finalCommand, {
|
|
15423
15444
|
cwd,
|
|
15424
15445
|
shell: true,
|
|
15425
15446
|
env: { ...process.env, HOME: home, CLAUDE_PROJECT_DIR: cwd }
|
|
@@ -19703,6 +19724,9 @@ function createNonInteractiveEnvHook(_ctx) {
|
|
|
19703
19724
|
}
|
|
19704
19725
|
};
|
|
19705
19726
|
}
|
|
19727
|
+
// src/hooks/interactive-bash-session/index.ts
|
|
19728
|
+
import { spawn as spawn2 } from "child_process";
|
|
19729
|
+
|
|
19706
19730
|
// src/hooks/interactive-bash-session/storage.ts
|
|
19707
19731
|
import {
|
|
19708
19732
|
existsSync as existsSync32,
|
|
@@ -19867,11 +19891,13 @@ function createInteractiveBashSessionHook(_ctx) {
|
|
|
19867
19891
|
async function killAllTrackedSessions(state2) {
|
|
19868
19892
|
for (const sessionName of state2.tmuxSessions) {
|
|
19869
19893
|
try {
|
|
19870
|
-
|
|
19871
|
-
|
|
19872
|
-
|
|
19894
|
+
await new Promise((resolve5) => {
|
|
19895
|
+
const proc = spawn2("tmux", ["kill-session", "-t", sessionName], {
|
|
19896
|
+
stdio: "ignore"
|
|
19897
|
+
});
|
|
19898
|
+
proc.on("close", () => resolve5());
|
|
19899
|
+
proc.on("error", () => resolve5());
|
|
19873
19900
|
});
|
|
19874
|
-
await proc.exited;
|
|
19875
19901
|
} catch {}
|
|
19876
19902
|
}
|
|
19877
19903
|
}
|
|
@@ -28379,7 +28405,7 @@ function getAllServers() {
|
|
|
28379
28405
|
return result;
|
|
28380
28406
|
}
|
|
28381
28407
|
// src/tools/lsp/client.ts
|
|
28382
|
-
|
|
28408
|
+
import { spawn as spawn3 } from "child_process";
|
|
28383
28409
|
import { readFileSync as readFileSync28 } from "fs";
|
|
28384
28410
|
import { extname, resolve as resolve6 } from "path";
|
|
28385
28411
|
class LSPServerManager {
|
|
@@ -28534,6 +28560,7 @@ class LSPClient {
|
|
|
28534
28560
|
root;
|
|
28535
28561
|
server;
|
|
28536
28562
|
proc = null;
|
|
28563
|
+
procExitCode = null;
|
|
28537
28564
|
buffer = new Uint8Array(0);
|
|
28538
28565
|
pending = new Map;
|
|
28539
28566
|
requestIdCounter = 0;
|
|
@@ -28546,10 +28573,9 @@ class LSPClient {
|
|
|
28546
28573
|
this.server = server;
|
|
28547
28574
|
}
|
|
28548
28575
|
async start() {
|
|
28549
|
-
|
|
28550
|
-
|
|
28551
|
-
|
|
28552
|
-
stderr: "pipe",
|
|
28576
|
+
const [cmd, ...args] = this.server.command;
|
|
28577
|
+
this.proc = spawn3(cmd, args, {
|
|
28578
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
28553
28579
|
cwd: this.root,
|
|
28554
28580
|
env: {
|
|
28555
28581
|
...process.env,
|
|
@@ -28559,62 +28585,54 @@ class LSPClient {
|
|
|
28559
28585
|
if (!this.proc) {
|
|
28560
28586
|
throw new Error(`Failed to spawn LSP server: ${this.server.command.join(" ")}`);
|
|
28561
28587
|
}
|
|
28588
|
+
this.proc.on("exit", (code) => {
|
|
28589
|
+
this.procExitCode = code;
|
|
28590
|
+
this.processExited = true;
|
|
28591
|
+
});
|
|
28592
|
+
this.proc.on("error", (err) => {
|
|
28593
|
+
this.processExited = true;
|
|
28594
|
+
this.rejectAllPending(`LSP spawn error: ${err.message}`);
|
|
28595
|
+
});
|
|
28562
28596
|
this.startReading();
|
|
28563
28597
|
this.startStderrReading();
|
|
28564
28598
|
await new Promise((resolve7) => setTimeout(resolve7, 100));
|
|
28565
|
-
if (this.
|
|
28599
|
+
if (this.procExitCode !== null) {
|
|
28566
28600
|
const stderr = this.stderrBuffer.join(`
|
|
28567
28601
|
`);
|
|
28568
|
-
throw new Error(`LSP server exited immediately with code ${this.
|
|
28602
|
+
throw new Error(`LSP server exited immediately with code ${this.procExitCode}` + (stderr ? `
|
|
28569
28603
|
stderr: ${stderr}` : ""));
|
|
28570
28604
|
}
|
|
28571
28605
|
}
|
|
28572
28606
|
startReading() {
|
|
28573
|
-
if (!this.proc)
|
|
28607
|
+
if (!this.proc?.stdout)
|
|
28574
28608
|
return;
|
|
28575
|
-
|
|
28576
|
-
|
|
28577
|
-
|
|
28578
|
-
|
|
28579
|
-
|
|
28580
|
-
|
|
28581
|
-
|
|
28582
|
-
|
|
28583
|
-
|
|
28584
|
-
|
|
28585
|
-
|
|
28586
|
-
|
|
28587
|
-
|
|
28588
|
-
|
|
28589
|
-
|
|
28590
|
-
|
|
28591
|
-
} catch (err) {
|
|
28592
|
-
this.processExited = true;
|
|
28593
|
-
this.rejectAllPending(`LSP stdout read error: ${err}`);
|
|
28594
|
-
}
|
|
28595
|
-
};
|
|
28596
|
-
read();
|
|
28609
|
+
this.proc.stdout.on("data", (chunk) => {
|
|
28610
|
+
const value = new Uint8Array(chunk);
|
|
28611
|
+
const newBuf = new Uint8Array(this.buffer.length + value.length);
|
|
28612
|
+
newBuf.set(this.buffer);
|
|
28613
|
+
newBuf.set(value, this.buffer.length);
|
|
28614
|
+
this.buffer = newBuf;
|
|
28615
|
+
this.processBuffer();
|
|
28616
|
+
});
|
|
28617
|
+
this.proc.stdout.on("close", () => {
|
|
28618
|
+
this.processExited = true;
|
|
28619
|
+
this.rejectAllPending("LSP server stdout closed");
|
|
28620
|
+
});
|
|
28621
|
+
this.proc.stdout.on("error", (err) => {
|
|
28622
|
+
this.processExited = true;
|
|
28623
|
+
this.rejectAllPending(`LSP stdout read error: ${err}`);
|
|
28624
|
+
});
|
|
28597
28625
|
}
|
|
28598
28626
|
startStderrReading() {
|
|
28599
|
-
if (!this.proc)
|
|
28627
|
+
if (!this.proc?.stderr)
|
|
28600
28628
|
return;
|
|
28601
|
-
|
|
28602
|
-
|
|
28603
|
-
|
|
28604
|
-
|
|
28605
|
-
|
|
28606
|
-
|
|
28607
|
-
|
|
28608
|
-
break;
|
|
28609
|
-
const text = decoder.decode(value);
|
|
28610
|
-
this.stderrBuffer.push(text);
|
|
28611
|
-
if (this.stderrBuffer.length > 100) {
|
|
28612
|
-
this.stderrBuffer.shift();
|
|
28613
|
-
}
|
|
28614
|
-
}
|
|
28615
|
-
} catch {}
|
|
28616
|
-
};
|
|
28617
|
-
read();
|
|
28629
|
+
this.proc.stderr.on("data", (chunk) => {
|
|
28630
|
+
const text = chunk.toString();
|
|
28631
|
+
this.stderrBuffer.push(text);
|
|
28632
|
+
if (this.stderrBuffer.length > 100) {
|
|
28633
|
+
this.stderrBuffer.shift();
|
|
28634
|
+
}
|
|
28635
|
+
});
|
|
28618
28636
|
}
|
|
28619
28637
|
rejectAllPending(reason) {
|
|
28620
28638
|
for (const [id, handler] of this.pending) {
|
|
@@ -28686,10 +28704,10 @@ stderr: ${stderr}` : ""));
|
|
|
28686
28704
|
send(method, params) {
|
|
28687
28705
|
if (!this.proc)
|
|
28688
28706
|
throw new Error("LSP client not started");
|
|
28689
|
-
if (this.processExited || this.
|
|
28707
|
+
if (this.processExited || this.procExitCode !== null) {
|
|
28690
28708
|
const stderr = this.stderrBuffer.slice(-10).join(`
|
|
28691
28709
|
`);
|
|
28692
|
-
throw new Error(`LSP server already exited (code: ${this.
|
|
28710
|
+
throw new Error(`LSP server already exited (code: ${this.procExitCode})` + (stderr ? `
|
|
28693
28711
|
stderr: ${stderr}` : ""));
|
|
28694
28712
|
}
|
|
28695
28713
|
const id = ++this.requestIdCounter;
|
|
@@ -28697,7 +28715,7 @@ stderr: ${stderr}` : ""));
|
|
|
28697
28715
|
const header = `Content-Length: ${Buffer.byteLength(msg)}\r
|
|
28698
28716
|
\r
|
|
28699
28717
|
`;
|
|
28700
|
-
this.proc.stdin
|
|
28718
|
+
this.proc.stdin?.write(header + msg);
|
|
28701
28719
|
return new Promise((resolve7, reject) => {
|
|
28702
28720
|
this.pending.set(id, { resolve: resolve7, reject });
|
|
28703
28721
|
setTimeout(() => {
|
|
@@ -28712,9 +28730,9 @@ recent stderr: ${stderr}` : "")));
|
|
|
28712
28730
|
});
|
|
28713
28731
|
}
|
|
28714
28732
|
notify(method, params) {
|
|
28715
|
-
if (!this.proc)
|
|
28733
|
+
if (!this.proc?.stdin)
|
|
28716
28734
|
return;
|
|
28717
|
-
if (this.processExited || this.
|
|
28735
|
+
if (this.processExited || this.procExitCode !== null)
|
|
28718
28736
|
return;
|
|
28719
28737
|
const msg = JSON.stringify({ jsonrpc: "2.0", method, params });
|
|
28720
28738
|
this.proc.stdin.write(`Content-Length: ${Buffer.byteLength(msg)}\r
|
|
@@ -28722,9 +28740,9 @@ recent stderr: ${stderr}` : "")));
|
|
|
28722
28740
|
${msg}`);
|
|
28723
28741
|
}
|
|
28724
28742
|
respond(id, result) {
|
|
28725
|
-
if (!this.proc)
|
|
28743
|
+
if (!this.proc?.stdin)
|
|
28726
28744
|
return;
|
|
28727
|
-
if (this.processExited || this.
|
|
28745
|
+
if (this.processExited || this.procExitCode !== null)
|
|
28728
28746
|
return;
|
|
28729
28747
|
const msg = JSON.stringify({ jsonrpc: "2.0", id, result });
|
|
28730
28748
|
this.proc.stdin.write(`Content-Length: ${Buffer.byteLength(msg)}\r
|
|
@@ -28910,7 +28928,7 @@ ${msg}`);
|
|
|
28910
28928
|
return this.send("codeAction/resolve", codeAction);
|
|
28911
28929
|
}
|
|
28912
28930
|
isAlive() {
|
|
28913
|
-
return this.proc !== null && !this.processExited && this.
|
|
28931
|
+
return this.proc !== null && !this.processExited && this.procExitCode === null;
|
|
28914
28932
|
}
|
|
28915
28933
|
async stop() {
|
|
28916
28934
|
try {
|
|
@@ -41902,7 +41920,6 @@ import { dirname as dirname11, join as join52 } from "path";
|
|
|
41902
41920
|
import { existsSync as existsSync44, statSync as statSync4 } from "fs";
|
|
41903
41921
|
|
|
41904
41922
|
// src/tools/ast-grep/downloader.ts
|
|
41905
|
-
var {spawn: spawn6 } = globalThis.Bun;
|
|
41906
41923
|
import { existsSync as existsSync43, mkdirSync as mkdirSync12, chmodSync as chmodSync2, unlinkSync as unlinkSync10 } from "fs";
|
|
41907
41924
|
import { join as join51 } from "path";
|
|
41908
41925
|
import { homedir as homedir16 } from "os";
|
|
@@ -41945,16 +41962,15 @@ function getCachedBinaryPath2() {
|
|
|
41945
41962
|
return existsSync43(binaryPath) ? binaryPath : null;
|
|
41946
41963
|
}
|
|
41947
41964
|
async function extractZip2(archivePath, destDir) {
|
|
41948
|
-
const
|
|
41965
|
+
const command = process.platform === "win32" ? [
|
|
41949
41966
|
"powershell",
|
|
41950
41967
|
"-command",
|
|
41951
41968
|
`Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force`
|
|
41952
|
-
]
|
|
41953
|
-
const
|
|
41954
|
-
if (exitCode !== 0) {
|
|
41955
|
-
const stderr = await new Response(proc.stderr).text();
|
|
41969
|
+
] : ["unzip", "-o", archivePath, "-d", destDir];
|
|
41970
|
+
const result = await spawnAsync(command);
|
|
41971
|
+
if (result.exitCode !== 0) {
|
|
41956
41972
|
const toolHint = process.platform === "win32" ? "Ensure PowerShell is available on your system." : "Please install 'unzip' (e.g., apt install unzip, brew install unzip).";
|
|
41957
|
-
throw new Error(`zip extraction failed (exit ${exitCode}): ${stderr}
|
|
41973
|
+
throw new Error(`zip extraction failed (exit ${result.exitCode}): ${result.stderr}
|
|
41958
41974
|
|
|
41959
41975
|
${toolHint}`);
|
|
41960
41976
|
}
|
|
@@ -41986,7 +42002,7 @@ async function downloadAstGrep(version2 = DEFAULT_VERSION) {
|
|
|
41986
42002
|
}
|
|
41987
42003
|
const archivePath = join51(cacheDir, assetName);
|
|
41988
42004
|
const arrayBuffer = await response2.arrayBuffer();
|
|
41989
|
-
await
|
|
42005
|
+
await writeFileSafe(archivePath, arrayBuffer);
|
|
41990
42006
|
await extractZip2(archivePath, cacheDir);
|
|
41991
42007
|
if (existsSync43(archivePath)) {
|
|
41992
42008
|
unlinkSync10(archivePath);
|
|
@@ -42117,7 +42133,6 @@ var DEFAULT_MAX_OUTPUT_BYTES = 1 * 1024 * 1024;
|
|
|
42117
42133
|
var DEFAULT_MAX_MATCHES = 500;
|
|
42118
42134
|
|
|
42119
42135
|
// src/tools/ast-grep/cli.ts
|
|
42120
|
-
var {spawn: spawn7 } = globalThis.Bun;
|
|
42121
42136
|
import { existsSync as existsSync45 } from "fs";
|
|
42122
42137
|
var resolvedCliPath3 = null;
|
|
42123
42138
|
var initPromise2 = null;
|
|
@@ -42171,27 +42186,17 @@ async function runSg(options) {
|
|
|
42171
42186
|
}
|
|
42172
42187
|
}
|
|
42173
42188
|
const timeout = DEFAULT_TIMEOUT_MS;
|
|
42174
|
-
const proc = spawn7([cliPath, ...args], {
|
|
42175
|
-
stdout: "pipe",
|
|
42176
|
-
stderr: "pipe"
|
|
42177
|
-
});
|
|
42178
|
-
const timeoutPromise = new Promise((_3, reject) => {
|
|
42179
|
-
const id = setTimeout(() => {
|
|
42180
|
-
proc.kill();
|
|
42181
|
-
reject(new Error(`Search timeout after ${timeout}ms`));
|
|
42182
|
-
}, timeout);
|
|
42183
|
-
proc.exited.then(() => clearTimeout(id));
|
|
42184
|
-
});
|
|
42185
42189
|
let stdout;
|
|
42186
42190
|
let stderr;
|
|
42187
42191
|
let exitCode;
|
|
42188
42192
|
try {
|
|
42189
|
-
|
|
42190
|
-
|
|
42191
|
-
|
|
42193
|
+
const result = await spawnAsync([cliPath, ...args], { timeout });
|
|
42194
|
+
stdout = result.stdout;
|
|
42195
|
+
stderr = result.stderr;
|
|
42196
|
+
exitCode = result.exitCode;
|
|
42192
42197
|
} catch (e2) {
|
|
42193
42198
|
const error45 = e2;
|
|
42194
|
-
if (error45.message?.includes("
|
|
42199
|
+
if (error45.message?.includes("Timeout")) {
|
|
42195
42200
|
return {
|
|
42196
42201
|
matches: [],
|
|
42197
42202
|
totalMatches: 0,
|
|
@@ -42424,9 +42429,6 @@ var ast_grep_replace = tool({
|
|
|
42424
42429
|
}
|
|
42425
42430
|
}
|
|
42426
42431
|
});
|
|
42427
|
-
// src/tools/grep/cli.ts
|
|
42428
|
-
var {spawn: spawn9 } = globalThis.Bun;
|
|
42429
|
-
|
|
42430
42432
|
// src/tools/grep/constants.ts
|
|
42431
42433
|
import { existsSync as existsSync47 } from "fs";
|
|
42432
42434
|
import { join as join54, dirname as dirname12 } from "path";
|
|
@@ -42435,7 +42437,6 @@ import { spawnSync } from "child_process";
|
|
|
42435
42437
|
// src/tools/grep/downloader.ts
|
|
42436
42438
|
import { existsSync as existsSync46, mkdirSync as mkdirSync13, chmodSync as chmodSync3, unlinkSync as unlinkSync11, readdirSync as readdirSync15 } from "fs";
|
|
42437
42439
|
import { join as join53 } from "path";
|
|
42438
|
-
var {spawn: spawn8 } = globalThis.Bun;
|
|
42439
42440
|
function findFileRecursive(dir, filename) {
|
|
42440
42441
|
try {
|
|
42441
42442
|
const entries = readdirSync15(dir, { withFileTypes: true, recursive: true });
|
|
@@ -42474,7 +42475,7 @@ async function downloadFile(url2, destPath) {
|
|
|
42474
42475
|
throw new Error(`Failed to download: ${response2.status} ${response2.statusText}`);
|
|
42475
42476
|
}
|
|
42476
42477
|
const buffer = await response2.arrayBuffer();
|
|
42477
|
-
await
|
|
42478
|
+
await writeFileSafe(destPath, buffer);
|
|
42478
42479
|
}
|
|
42479
42480
|
async function extractTarGz2(archivePath, destDir) {
|
|
42480
42481
|
const platformKey = getPlatformKey();
|
|
@@ -42484,21 +42485,14 @@ async function extractTarGz2(archivePath, destDir) {
|
|
|
42484
42485
|
} else if (platformKey.endsWith("-linux")) {
|
|
42485
42486
|
args.push("--wildcards", "*/rg");
|
|
42486
42487
|
}
|
|
42487
|
-
const
|
|
42488
|
-
|
|
42489
|
-
|
|
42490
|
-
stderr: "pipe"
|
|
42491
|
-
});
|
|
42492
|
-
const exitCode = await proc.exited;
|
|
42493
|
-
if (exitCode !== 0) {
|
|
42494
|
-
const stderr = await new Response(proc.stderr).text();
|
|
42495
|
-
throw new Error(`Failed to extract tar.gz: ${stderr}`);
|
|
42488
|
+
const result = await spawnAsync(args, { cwd: destDir });
|
|
42489
|
+
if (result.exitCode !== 0) {
|
|
42490
|
+
throw new Error(`Failed to extract tar.gz: ${result.stderr}`);
|
|
42496
42491
|
}
|
|
42497
42492
|
}
|
|
42498
42493
|
async function extractZipWindows(archivePath, destDir) {
|
|
42499
|
-
const
|
|
42500
|
-
|
|
42501
|
-
if (exitCode !== 0) {
|
|
42494
|
+
const result = await spawnAsync(["powershell", "-Command", `Expand-Archive -Path '${archivePath}' -DestinationPath '${destDir}' -Force`]);
|
|
42495
|
+
if (result.exitCode !== 0) {
|
|
42502
42496
|
throw new Error("Failed to extract zip with PowerShell");
|
|
42503
42497
|
}
|
|
42504
42498
|
const foundPath = findFileRecursive(destDir, "rg.exe");
|
|
@@ -42511,12 +42505,8 @@ async function extractZipWindows(archivePath, destDir) {
|
|
|
42511
42505
|
}
|
|
42512
42506
|
}
|
|
42513
42507
|
async function extractZipUnix(archivePath, destDir) {
|
|
42514
|
-
const
|
|
42515
|
-
|
|
42516
|
-
stderr: "pipe"
|
|
42517
|
-
});
|
|
42518
|
-
const exitCode = await proc.exited;
|
|
42519
|
-
if (exitCode !== 0) {
|
|
42508
|
+
const result = await spawnAsync(["unzip", "-o", archivePath, "-d", destDir]);
|
|
42509
|
+
if (result.exitCode !== 0) {
|
|
42520
42510
|
throw new Error("Failed to extract zip");
|
|
42521
42511
|
}
|
|
42522
42512
|
const foundPath = findFileRecursive(destDir, "rg");
|
|
@@ -42768,21 +42758,9 @@ async function runRg(options) {
|
|
|
42768
42758
|
}
|
|
42769
42759
|
const paths = options.paths?.length ? options.paths : ["."];
|
|
42770
42760
|
args.push(...paths);
|
|
42771
|
-
const proc = spawn9([cli.path, ...args], {
|
|
42772
|
-
stdout: "pipe",
|
|
42773
|
-
stderr: "pipe"
|
|
42774
|
-
});
|
|
42775
|
-
const timeoutPromise = new Promise((_3, reject) => {
|
|
42776
|
-
const id = setTimeout(() => {
|
|
42777
|
-
proc.kill();
|
|
42778
|
-
reject(new Error(`Search timeout after ${timeout}ms`));
|
|
42779
|
-
}, timeout);
|
|
42780
|
-
proc.exited.then(() => clearTimeout(id));
|
|
42781
|
-
});
|
|
42782
42761
|
try {
|
|
42783
|
-
const
|
|
42784
|
-
const stderr
|
|
42785
|
-
const exitCode = await proc.exited;
|
|
42762
|
+
const result = await spawnAsync([cli.path, ...args], { timeout });
|
|
42763
|
+
const { stdout, stderr, exitCode } = result;
|
|
42786
42764
|
const truncated = stdout.length >= DEFAULT_MAX_OUTPUT_BYTES2;
|
|
42787
42765
|
const outputToProcess = truncated ? stdout.substring(0, DEFAULT_MAX_OUTPUT_BYTES2) : stdout;
|
|
42788
42766
|
if (exitCode > 1 && stderr.trim()) {
|
|
@@ -42869,9 +42847,6 @@ var grep = tool({
|
|
|
42869
42847
|
}
|
|
42870
42848
|
});
|
|
42871
42849
|
|
|
42872
|
-
// src/tools/glob/cli.ts
|
|
42873
|
-
var {spawn: spawn10 } = globalThis.Bun;
|
|
42874
|
-
|
|
42875
42850
|
// src/tools/glob/constants.ts
|
|
42876
42851
|
var DEFAULT_TIMEOUT_MS3 = 60000;
|
|
42877
42852
|
var DEFAULT_LIMIT = 100;
|
|
@@ -42952,22 +42927,9 @@ async function runRgFiles(options, resolvedCli) {
|
|
|
42952
42927
|
cwd = paths[0] || ".";
|
|
42953
42928
|
command = [cli.path, ...args];
|
|
42954
42929
|
}
|
|
42955
|
-
const proc = spawn10(command, {
|
|
42956
|
-
stdout: "pipe",
|
|
42957
|
-
stderr: "pipe",
|
|
42958
|
-
cwd
|
|
42959
|
-
});
|
|
42960
|
-
const timeoutPromise = new Promise((_3, reject) => {
|
|
42961
|
-
const id = setTimeout(() => {
|
|
42962
|
-
proc.kill();
|
|
42963
|
-
reject(new Error(`Glob search timeout after ${timeout}ms`));
|
|
42964
|
-
}, timeout);
|
|
42965
|
-
proc.exited.then(() => clearTimeout(id));
|
|
42966
|
-
});
|
|
42967
42930
|
try {
|
|
42968
|
-
const
|
|
42969
|
-
const stderr
|
|
42970
|
-
const exitCode = await proc.exited;
|
|
42931
|
+
const result = await spawnAsync(command, { cwd, timeout });
|
|
42932
|
+
const { stdout, stderr, exitCode } = result;
|
|
42971
42933
|
if (exitCode > 1 && stderr.trim()) {
|
|
42972
42934
|
return {
|
|
42973
42935
|
files: [],
|
|
@@ -43822,6 +43784,9 @@ var session_info = tool({
|
|
|
43822
43784
|
}
|
|
43823
43785
|
}
|
|
43824
43786
|
});
|
|
43787
|
+
// src/tools/interactive-bash/tools.ts
|
|
43788
|
+
import { spawn as spawn4 } from "child_process";
|
|
43789
|
+
|
|
43825
43790
|
// src/tools/interactive-bash/constants.ts
|
|
43826
43791
|
var DEFAULT_TIMEOUT_MS4 = 60000;
|
|
43827
43792
|
var BLOCKED_TMUX_SUBCOMMANDS = [
|
|
@@ -43841,33 +43806,23 @@ For: server processes, long-running tasks, background jobs, interactive CLI tool
|
|
|
43841
43806
|
Blocked (use bash instead): capture-pane, save-buffer, show-buffer, pipe-pane.`;
|
|
43842
43807
|
|
|
43843
43808
|
// src/tools/interactive-bash/utils.ts
|
|
43844
|
-
var {spawn: spawn11 } = globalThis.Bun;
|
|
43845
43809
|
var tmuxPath = null;
|
|
43846
43810
|
var initPromise3 = null;
|
|
43847
43811
|
async function findTmuxPath() {
|
|
43848
43812
|
const isWindows2 = process.platform === "win32";
|
|
43849
43813
|
const cmd = isWindows2 ? "where" : "which";
|
|
43850
43814
|
try {
|
|
43851
|
-
const
|
|
43852
|
-
|
|
43853
|
-
stderr: "pipe"
|
|
43854
|
-
});
|
|
43855
|
-
const exitCode = await proc.exited;
|
|
43856
|
-
if (exitCode !== 0) {
|
|
43815
|
+
const result = await spawnAsync([cmd, "tmux"]);
|
|
43816
|
+
if (result.exitCode !== 0) {
|
|
43857
43817
|
return null;
|
|
43858
43818
|
}
|
|
43859
|
-
const
|
|
43860
|
-
const path9 = stdout.trim().split(`
|
|
43819
|
+
const path9 = result.stdout.trim().split(`
|
|
43861
43820
|
`)[0];
|
|
43862
43821
|
if (!path9) {
|
|
43863
43822
|
return null;
|
|
43864
43823
|
}
|
|
43865
|
-
const
|
|
43866
|
-
|
|
43867
|
-
stderr: "pipe"
|
|
43868
|
-
});
|
|
43869
|
-
const verifyExitCode = await verifyProc.exited;
|
|
43870
|
-
if (verifyExitCode !== 0) {
|
|
43824
|
+
const verifyResult = await spawnAsync([path9, "-V"]);
|
|
43825
|
+
if (verifyResult.exitCode !== 0) {
|
|
43871
43826
|
return null;
|
|
43872
43827
|
}
|
|
43873
43828
|
return path9;
|
|
@@ -43952,30 +43907,40 @@ var interactive_bash = tool({
|
|
|
43952
43907
|
if (BLOCKED_TMUX_SUBCOMMANDS.includes(subcommand)) {
|
|
43953
43908
|
return `Error: '${parts[0]}' is blocked. Use bash tool instead for capturing/printing terminal output.`;
|
|
43954
43909
|
}
|
|
43955
|
-
const
|
|
43956
|
-
|
|
43957
|
-
|
|
43958
|
-
|
|
43959
|
-
|
|
43960
|
-
|
|
43910
|
+
const result = await new Promise((resolve8, reject) => {
|
|
43911
|
+
const proc = spawn4(tmuxPath2, parts, {
|
|
43912
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
43913
|
+
});
|
|
43914
|
+
let stdout = "";
|
|
43915
|
+
let stderr = "";
|
|
43916
|
+
let killed = false;
|
|
43917
|
+
const timeout = setTimeout(() => {
|
|
43918
|
+
killed = true;
|
|
43961
43919
|
proc.kill();
|
|
43962
43920
|
reject(new Error(`Timeout after ${DEFAULT_TIMEOUT_MS4}ms`));
|
|
43963
43921
|
}, DEFAULT_TIMEOUT_MS4);
|
|
43964
|
-
proc.
|
|
43922
|
+
proc.stdout?.on("data", (data) => {
|
|
43923
|
+
stdout += data.toString();
|
|
43924
|
+
});
|
|
43925
|
+
proc.stderr?.on("data", (data) => {
|
|
43926
|
+
stderr += data.toString();
|
|
43927
|
+
});
|
|
43928
|
+
proc.on("close", (code) => {
|
|
43929
|
+
clearTimeout(timeout);
|
|
43930
|
+
if (!killed) {
|
|
43931
|
+
resolve8({ stdout, stderr, exitCode: code ?? 1 });
|
|
43932
|
+
}
|
|
43933
|
+
});
|
|
43934
|
+
proc.on("error", (err) => {
|
|
43935
|
+
clearTimeout(timeout);
|
|
43936
|
+
reject(err);
|
|
43937
|
+
});
|
|
43965
43938
|
});
|
|
43966
|
-
|
|
43967
|
-
|
|
43968
|
-
new Response(proc.stdout).text(),
|
|
43969
|
-
new Response(proc.stderr).text(),
|
|
43970
|
-
proc.exited
|
|
43971
|
-
]),
|
|
43972
|
-
timeoutPromise
|
|
43973
|
-
]);
|
|
43974
|
-
if (exitCode !== 0) {
|
|
43975
|
-
const errorMsg = stderr.trim() || `Command failed with exit code ${exitCode}`;
|
|
43939
|
+
if (result.exitCode !== 0) {
|
|
43940
|
+
const errorMsg = result.stderr.trim() || `Command failed with exit code ${result.exitCode}`;
|
|
43976
43941
|
return `Error: ${errorMsg}`;
|
|
43977
43942
|
}
|
|
43978
|
-
return stdout || "(no output)";
|
|
43943
|
+
return result.stdout || "(no output)";
|
|
43979
43944
|
} catch (e2) {
|
|
43980
43945
|
return `Error: ${e2 instanceof Error ? e2.message : String(e2)}`;
|
|
43981
43946
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js-compatible spawn utilities
|
|
3
|
+
* Replaces Bun.spawn for Node.js runtime compatibility
|
|
4
|
+
*/
|
|
5
|
+
export interface SpawnResult {
|
|
6
|
+
stdout: string;
|
|
7
|
+
stderr: string;
|
|
8
|
+
exitCode: number;
|
|
9
|
+
}
|
|
10
|
+
export interface SpawnWithPipeOptions {
|
|
11
|
+
cwd?: string;
|
|
12
|
+
stdin?: string;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Spawn a process and collect stdout/stderr
|
|
17
|
+
*/
|
|
18
|
+
export declare function spawnAsync(command: string[], options?: SpawnWithPipeOptions): Promise<SpawnResult>;
|
|
19
|
+
/**
|
|
20
|
+
* Simple spawn that returns exit code only (for fire-and-forget)
|
|
21
|
+
*/
|
|
22
|
+
export declare function spawnSimple(command: string[], options?: {
|
|
23
|
+
cwd?: string;
|
|
24
|
+
stdio?: "ignore" | "pipe";
|
|
25
|
+
}): Promise<number>;
|
|
26
|
+
/**
|
|
27
|
+
* Write file to disk (replacement for Bun.write)
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeFileSafe(path: string, data: ArrayBuffer | Buffer | string): Promise<void>;
|