@hasna/coders 0.1.4 → 0.1.6
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.mjs +87 -15
- package/dist/cli.mjs.map +3 -3
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -61852,12 +61852,15 @@ async function runAgentLoop(initialMessages, options2) {
|
|
|
61852
61852
|
options2.onThinkingDelta?.(event.delta.thinking);
|
|
61853
61853
|
}
|
|
61854
61854
|
}
|
|
61855
|
-
if (event.type === "
|
|
61855
|
+
if (event.type === "message_delta") {
|
|
61856
|
+
stopReason = accumulated.stopReason ?? stopReason;
|
|
61857
|
+
}
|
|
61858
|
+
if (event.type === "message_stop") {
|
|
61856
61859
|
if (accumulated.content) {
|
|
61857
61860
|
contentBlocks.length = 0;
|
|
61858
61861
|
contentBlocks.push(...accumulated.content);
|
|
61859
61862
|
}
|
|
61860
|
-
stopReason = accumulated.stopReason ??
|
|
61863
|
+
stopReason = accumulated.stopReason ?? stopReason;
|
|
61861
61864
|
if (accumulated.usage) {
|
|
61862
61865
|
totalInputTokens += accumulated.usage.inputTokens;
|
|
61863
61866
|
totalOutputTokens += accumulated.usage.outputTokens;
|
|
@@ -62353,8 +62356,9 @@ var init_bash = __esm({
|
|
|
62353
62356
|
{ pattern: /\b:(){ :\|:& };:/, reason: "Fork bomb" },
|
|
62354
62357
|
{ pattern: /\bchmod\s+-R\s+777\s+\//, reason: "Recursive chmod 777 on root" },
|
|
62355
62358
|
{ pattern: /\bchown\s+-R\s+.*\s+\//, reason: "Recursive chown on root" },
|
|
62356
|
-
{ pattern: /\
|
|
62357
|
-
{ pattern: /\
|
|
62359
|
+
{ pattern: /\b(curl|wget)\s.*\|\s*(sh|bash|zsh|ksh)\b/, reason: "Pipe remote script to shell" },
|
|
62360
|
+
{ pattern: /\bdd\s+if=/, reason: "Direct disk copy" },
|
|
62361
|
+
{ pattern: /\bsudo\s+rm\s+-rf\b/, reason: "Recursive delete as root" },
|
|
62358
62362
|
{ pattern: /\b\/etc\/passwd\b/, reason: "Access to passwd file" },
|
|
62359
62363
|
{ pattern: /\b\/etc\/shadow\b/, reason: "Access to shadow file" }
|
|
62360
62364
|
];
|
|
@@ -62645,8 +62649,7 @@ var init_bash = __esm({
|
|
|
62645
62649
|
shell: getShell(),
|
|
62646
62650
|
cwd: process.cwd(),
|
|
62647
62651
|
env: { ...process.env },
|
|
62648
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
62649
|
-
timeout: timeoutMs
|
|
62652
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
62650
62653
|
});
|
|
62651
62654
|
child.stdout?.on("data", (data) => {
|
|
62652
62655
|
stdout += data.toString();
|
|
@@ -62654,6 +62657,11 @@ var init_bash = __esm({
|
|
|
62654
62657
|
child.stderr?.on("data", (data) => {
|
|
62655
62658
|
stderr += data.toString();
|
|
62656
62659
|
});
|
|
62660
|
+
const timeoutTimer = setTimeout(() => {
|
|
62661
|
+
interrupted = true;
|
|
62662
|
+
child.kill("SIGTERM");
|
|
62663
|
+
setTimeout(() => child.kill("SIGKILL"), 3e3);
|
|
62664
|
+
}, timeoutMs);
|
|
62657
62665
|
const onAbort = () => {
|
|
62658
62666
|
interrupted = true;
|
|
62659
62667
|
child.kill("SIGTERM");
|
|
@@ -62661,6 +62669,7 @@ var init_bash = __esm({
|
|
|
62661
62669
|
};
|
|
62662
62670
|
context.abortController?.signal.addEventListener("abort", onAbort, { once: true });
|
|
62663
62671
|
child.on("close", (code, signal) => {
|
|
62672
|
+
clearTimeout(timeoutTimer);
|
|
62664
62673
|
context.abortController?.signal.removeEventListener("abort", onAbort);
|
|
62665
62674
|
const durationMs = performance.now() - startTime;
|
|
62666
62675
|
if (signal === "SIGTERM" || signal === "SIGKILL") {
|
|
@@ -62974,7 +62983,7 @@ Usage:
|
|
|
62974
62983
|
});
|
|
62975
62984
|
|
|
62976
62985
|
// src/tools/builtin/edit.ts
|
|
62977
|
-
import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, existsSync as existsSync7 } from "fs";
|
|
62986
|
+
import { readFileSync as readFileSync6, writeFileSync as writeFileSync4, existsSync as existsSync7, statSync as statSync2 } from "fs";
|
|
62978
62987
|
import { resolve as resolve3, isAbsolute as isAbsolute2 } from "path";
|
|
62979
62988
|
import { randomUUID } from "crypto";
|
|
62980
62989
|
function resolvePath2(filePath) {
|
|
@@ -63153,6 +63162,23 @@ var init_edit = __esm({
|
|
|
63153
63162
|
return { data: { filePath: input.file_path, oldString: "", newString: "", replacements: 0, originalFile: "" } };
|
|
63154
63163
|
}
|
|
63155
63164
|
const resolved = resolvePath2(input.file_path);
|
|
63165
|
+
const MAX_FILE_SIZE = 50 * 1024 * 1024;
|
|
63166
|
+
try {
|
|
63167
|
+
const fileSize = statSync2(resolved).size;
|
|
63168
|
+
if (fileSize > MAX_FILE_SIZE) {
|
|
63169
|
+
return {
|
|
63170
|
+
data: {
|
|
63171
|
+
filePath: resolved,
|
|
63172
|
+
oldString: input.old_string,
|
|
63173
|
+
newString: input.new_string,
|
|
63174
|
+
replacements: 0,
|
|
63175
|
+
originalFile: "",
|
|
63176
|
+
gitDiff: void 0
|
|
63177
|
+
}
|
|
63178
|
+
};
|
|
63179
|
+
}
|
|
63180
|
+
} catch {
|
|
63181
|
+
}
|
|
63156
63182
|
const originalContent = readFileSync6(resolved, "utf-8");
|
|
63157
63183
|
let newContent;
|
|
63158
63184
|
let replacements;
|
|
@@ -66965,11 +66991,11 @@ var require_out = __commonJS({
|
|
|
66965
66991
|
async.read(path, getSettings2(optionsOrSettingsOrCallback), callback);
|
|
66966
66992
|
}
|
|
66967
66993
|
exports.stat = stat;
|
|
66968
|
-
function
|
|
66994
|
+
function statSync4(path, optionsOrSettings) {
|
|
66969
66995
|
const settings = getSettings2(optionsOrSettings);
|
|
66970
66996
|
return sync.read(path, settings);
|
|
66971
66997
|
}
|
|
66972
|
-
exports.statSync =
|
|
66998
|
+
exports.statSync = statSync4;
|
|
66973
66999
|
function getSettings2(settingsOrOptions = {}) {
|
|
66974
67000
|
if (settingsOrOptions instanceof settings_1.default) {
|
|
66975
67001
|
return settingsOrOptions;
|
|
@@ -68854,7 +68880,7 @@ var require_out4 = __commonJS({
|
|
|
68854
68880
|
});
|
|
68855
68881
|
|
|
68856
68882
|
// src/tools/builtin/glob.ts
|
|
68857
|
-
import { statSync as
|
|
68883
|
+
import { statSync as statSync3, existsSync as existsSync9 } from "fs";
|
|
68858
68884
|
import { resolve as resolve5, isAbsolute as isAbsolute4 } from "path";
|
|
68859
68885
|
function resolvePath4(p) {
|
|
68860
68886
|
if (isAbsolute4(p)) return p;
|
|
@@ -68920,6 +68946,15 @@ var init_glob = __esm({
|
|
|
68920
68946
|
},
|
|
68921
68947
|
async call(input, context) {
|
|
68922
68948
|
const cwd2 = input.path ? resolvePath4(input.path) : process.cwd();
|
|
68949
|
+
if (input.path && !existsSync9(cwd2)) {
|
|
68950
|
+
return {
|
|
68951
|
+
data: {
|
|
68952
|
+
files: [],
|
|
68953
|
+
totalMatches: 0,
|
|
68954
|
+
truncated: false
|
|
68955
|
+
}
|
|
68956
|
+
};
|
|
68957
|
+
}
|
|
68923
68958
|
try {
|
|
68924
68959
|
const allFiles = await (0, import_fast_glob.default)(input.pattern, {
|
|
68925
68960
|
cwd: cwd2,
|
|
@@ -68942,7 +68977,7 @@ var init_glob = __esm({
|
|
|
68942
68977
|
});
|
|
68943
68978
|
const withStats = allFiles.map((f) => {
|
|
68944
68979
|
try {
|
|
68945
|
-
const stat =
|
|
68980
|
+
const stat = statSync3(f);
|
|
68946
68981
|
return { path: f, mtime: stat.mtimeMs };
|
|
68947
68982
|
} catch {
|
|
68948
68983
|
return { path: f, mtime: 0 };
|
|
@@ -69191,7 +69226,7 @@ var init_grep = __esm({
|
|
|
69191
69226
|
return processOutput(result, input);
|
|
69192
69227
|
} catch (error) {
|
|
69193
69228
|
const err = error;
|
|
69194
|
-
if (err.status === 1) {
|
|
69229
|
+
if (err.status === 1 && (!err.stderr || err.stderr.trim() === "")) {
|
|
69195
69230
|
return {
|
|
69196
69231
|
data: { content: "No matches found.", matchCount: 0, fileCount: 0, truncated: false }
|
|
69197
69232
|
};
|
|
@@ -70361,6 +70396,7 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70361
70396
|
const [tokens, setTokens] = (0, import_react22.useState)(0);
|
|
70362
70397
|
const [history, setHistory] = (0, import_react22.useState)([]);
|
|
70363
70398
|
const [activeTools, setActiveTools] = (0, import_react22.useState)([]);
|
|
70399
|
+
const [queuedMessages, setQueuedMessages] = (0, import_react22.useState)([]);
|
|
70364
70400
|
const activeToolsRef = import_react22.default.useRef([]);
|
|
70365
70401
|
activeToolsRef.current = activeTools;
|
|
70366
70402
|
const rows = stdout?.rows ?? 24;
|
|
@@ -70433,6 +70469,10 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70433
70469
|
const toolHandlers = createToolHandlers();
|
|
70434
70470
|
const permCtx = createDefaultPermissionContext();
|
|
70435
70471
|
const toolStartTimes = /* @__PURE__ */ new Map();
|
|
70472
|
+
const builtinTools = [bashTool, readTool, editTool, writeTool, globTool, grepTool];
|
|
70473
|
+
const toolPrompts = await Promise.all(
|
|
70474
|
+
builtinTools.map(async (t) => ({ name: t.name, prompt: await t.prompt() }))
|
|
70475
|
+
);
|
|
70436
70476
|
const result = await runAgentLoop(
|
|
70437
70477
|
newHistory,
|
|
70438
70478
|
{
|
|
@@ -70441,7 +70481,7 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70441
70481
|
projectDir: process.cwd(),
|
|
70442
70482
|
model,
|
|
70443
70483
|
permissionMode: mode,
|
|
70444
|
-
tools:
|
|
70484
|
+
tools: toolPrompts
|
|
70445
70485
|
}),
|
|
70446
70486
|
tools: toolHandlers,
|
|
70447
70487
|
model,
|
|
@@ -70515,6 +70555,13 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70515
70555
|
setBusy(false);
|
|
70516
70556
|
}
|
|
70517
70557
|
}, [busy, history, model, exit, onToolStart, onToolEnd, streaming, activeTools]);
|
|
70558
|
+
(0, import_react22.useEffect)(() => {
|
|
70559
|
+
if (!busy && queuedMessages.length > 0) {
|
|
70560
|
+
const next = queuedMessages[0];
|
|
70561
|
+
setQueuedMessages((q) => q.slice(1));
|
|
70562
|
+
setTimeout(() => submit(next), 100);
|
|
70563
|
+
}
|
|
70564
|
+
}, [busy, queuedMessages]);
|
|
70518
70565
|
(0, import_react22.useEffect)(() => {
|
|
70519
70566
|
if (initialPrompt) submit(initialPrompt);
|
|
70520
70567
|
}, []);
|
|
@@ -70524,6 +70571,24 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70524
70571
|
if (key.ctrl && ch === "c") {
|
|
70525
70572
|
setBusy(false);
|
|
70526
70573
|
setStreaming("");
|
|
70574
|
+
return;
|
|
70575
|
+
}
|
|
70576
|
+
if (key.return && input.trim()) {
|
|
70577
|
+
setQueuedMessages((q) => [...q, input.trim()]);
|
|
70578
|
+
setInput("");
|
|
70579
|
+
return;
|
|
70580
|
+
}
|
|
70581
|
+
if (key.backspace || key.delete) {
|
|
70582
|
+
setInput((p) => p.slice(0, -1));
|
|
70583
|
+
return;
|
|
70584
|
+
}
|
|
70585
|
+
if (key.escape) {
|
|
70586
|
+
setInput("");
|
|
70587
|
+
return;
|
|
70588
|
+
}
|
|
70589
|
+
if (!key.ctrl && !key.meta && ch) {
|
|
70590
|
+
setInput((p) => p + ch);
|
|
70591
|
+
return;
|
|
70527
70592
|
}
|
|
70528
70593
|
return;
|
|
70529
70594
|
}
|
|
@@ -70594,8 +70659,15 @@ function App2({ model, mode, initialPrompt }) {
|
|
|
70594
70659
|
" "
|
|
70595
70660
|
] }),
|
|
70596
70661
|
input.startsWith("/") ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: "magenta", children: input }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { children: input }),
|
|
70597
|
-
|
|
70662
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: "gray", children: "\u258E" })
|
|
70598
70663
|
] }),
|
|
70664
|
+
queuedMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { dimColor: true, children: [
|
|
70665
|
+
" ",
|
|
70666
|
+
queuedMessages.length,
|
|
70667
|
+
" queued message",
|
|
70668
|
+
queuedMessages.length > 1 ? "s" : "",
|
|
70669
|
+
" \u2014 will send after current response"
|
|
70670
|
+
] }) }),
|
|
70599
70671
|
showSlashMenu && filteredCommands.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Box_default, { flexDirection: "column", paddingLeft: 2, children: filteredCommands.map((cmd, i) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Box_default, { children: [
|
|
70600
70672
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Text, { color: i === slashSelected ? "cyan" : void 0, bold: i === slashSelected, children: i === slashSelected ? "\u25B8 " : " " }),
|
|
70601
70673
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Text, { color: i === slashSelected ? "cyan" : "blue", children: [
|
|
@@ -70983,7 +71055,7 @@ var VERSION, BUILD_TIME, PACKAGE_NAME2, ISSUES_URL2, startupTimestamps, original
|
|
|
70983
71055
|
var init_index = __esm({
|
|
70984
71056
|
"src/cli/index.ts"() {
|
|
70985
71057
|
VERSION = "0.1.2";
|
|
70986
|
-
BUILD_TIME = "2026-03-
|
|
71058
|
+
BUILD_TIME = "2026-03-20T17:39:26.799Z";
|
|
70987
71059
|
PACKAGE_NAME2 = "@hasna/coders";
|
|
70988
71060
|
ISSUES_URL2 = "https://github.com/hasnaxyz/open-coders/issues";
|
|
70989
71061
|
startupTimestamps = {};
|