@hasna/coders 0.1.4 → 0.1.5

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 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 === "message_stop" || event.type === "message_delta") {
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 ?? null;
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: /\bcurl\s.*\|\s*sh\b/, reason: "Pipe remote script to shell" },
62357
- { pattern: /\bwget\s.*\|\s*sh\b/, reason: "Pipe remote script to shell" },
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 statSync3(path, optionsOrSettings) {
66994
+ function statSync4(path, optionsOrSettings) {
66969
66995
  const settings = getSettings2(optionsOrSettings);
66970
66996
  return sync.read(path, settings);
66971
66997
  }
66972
- exports.statSync = statSync3;
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 statSync2 } from "fs";
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 = statSync2(f);
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
  };
@@ -70433,6 +70468,10 @@ function App2({ model, mode, initialPrompt }) {
70433
70468
  const toolHandlers = createToolHandlers();
70434
70469
  const permCtx = createDefaultPermissionContext();
70435
70470
  const toolStartTimes = /* @__PURE__ */ new Map();
70471
+ const builtinTools = [bashTool, readTool, editTool, writeTool, globTool, grepTool];
70472
+ const toolPrompts = await Promise.all(
70473
+ builtinTools.map(async (t) => ({ name: t.name, prompt: await t.prompt() }))
70474
+ );
70436
70475
  const result = await runAgentLoop(
70437
70476
  newHistory,
70438
70477
  {
@@ -70441,7 +70480,7 @@ function App2({ model, mode, initialPrompt }) {
70441
70480
  projectDir: process.cwd(),
70442
70481
  model,
70443
70482
  permissionMode: mode,
70444
- tools: toolHandlers.map((t) => ({ name: t.name, prompt: "" }))
70483
+ tools: toolPrompts
70445
70484
  }),
70446
70485
  tools: toolHandlers,
70447
70486
  model,
@@ -70983,7 +71022,7 @@ var VERSION, BUILD_TIME, PACKAGE_NAME2, ISSUES_URL2, startupTimestamps, original
70983
71022
  var init_index = __esm({
70984
71023
  "src/cli/index.ts"() {
70985
71024
  VERSION = "0.1.2";
70986
- BUILD_TIME = "2026-03-20T14:03:23.252Z";
71025
+ BUILD_TIME = "2026-03-20T17:30:01.515Z";
70987
71026
  PACKAGE_NAME2 = "@hasna/coders";
70988
71027
  ISSUES_URL2 = "https://github.com/hasnaxyz/open-coders/issues";
70989
71028
  startupTimestamps = {};