brito-cli 0.13.1 → 0.13.3

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.
@@ -1,3 +1,5 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
1
3
  import path from "node:path";
2
4
  import { spawn, spawnSync } from "node:child_process";
3
5
  import { randomUUID } from "node:crypto";
@@ -16,6 +18,33 @@ import { fmtBytes, findImages, splitOversize } from "../util/images.js";
16
18
  import { classifyClaudeCliFailure, collectClaudeFailure, shortError } from "../provider/fallback.js";
17
19
  // Backend alternativo: delega ao `claude` oficial, que autentica com o /login do usuário.
18
20
  // O brito nunca lê nem envia o token da assinatura. Grafo, memória e skills chegam ao claude via MCP.
21
+ /** Limite seguro para a linha de comando: o Windows corta em ~32.767 caracteres (spawn ENAMETOOLONG). */
22
+ const ARGV_BUDGET = 24_000;
23
+ /**
24
+ * Um CLAUDE.md/AGENTS.md grande estoura a linha de comando no Windows. Quando o total passa do limite, o system prompt, o
25
+ * --mcp-config e o --agents vão para arquivos temporários (o claude aceita caminho nos três); `cleanup` apaga a pasta.
26
+ */
27
+ export function spillLongArgs(args) {
28
+ if (args.reduce((n, a) => n + a.length + 1, 0) <= ARGV_BUDGET)
29
+ return { args, cleanup: () => { } };
30
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "brito-claude-"));
31
+ const out = [...args];
32
+ const spill = (flag, newFlag, file) => {
33
+ const i = out.indexOf(flag);
34
+ if (i < 0 || i + 1 >= out.length)
35
+ return;
36
+ const f = path.join(dir, file);
37
+ fs.writeFileSync(f, out[i + 1], { mode: 0o600 });
38
+ out.splice(i, 2, newFlag, f);
39
+ };
40
+ spill("--append-system-prompt", "--append-system-prompt-file", "system.md");
41
+ spill("--mcp-config", "--mcp-config", "mcp.json");
42
+ spill("--agents", "--agents", "agents.json");
43
+ return { args: out, cleanup: () => { try {
44
+ fs.rmSync(dir, { recursive: true, force: true });
45
+ }
46
+ catch { /* temp */ } } };
47
+ }
19
48
  export function hasClaudeCli() {
20
49
  const c = claudeCommand(["--version"]);
21
50
  return spawnSync(c.command, c.args, { stdio: "ignore" }).status === 0;
@@ -257,7 +286,8 @@ export class ClaudeSession {
257
286
  ui.info(`📎 ${imgs.map((i) => `${i.name} (${fmtBytes(i.bytes)})`).join(", ")} anexado${imgs.length > 1 ? "s" : ""}`);
258
287
  // O claude vê a imagem pela tool Read: o prompt diz quais arquivos são imagens anexadas pelo usuário.
259
288
  const prompt = this.pendingHandoff + (imgs.length ? `${text}\n\n[O usuário anexou ${imgs.length > 1 ? "estes arquivos" : "este arquivo"}; abra com a tool Read para vê-${imgs.length > 1 ? "las" : "la"}:\n${imgs.map((i) => `- ${i.path}`).join("\n")}]` : text);
260
- const cmd = (this.o.command ?? claudeCommand)(this.args(prompt, [...new Set(imgs.map((i) => path.dirname(i.path)))]));
289
+ const spilled = spillLongArgs(this.args(prompt, [...new Set(imgs.map((i) => path.dirname(i.path)))]));
290
+ const cmd = (this.o.command ?? claudeCommand)(spilled.args);
261
291
  const child = (this.child = spawn(cmd.command, cmd.args, {
262
292
  cwd: this.o.root, stdio: ["ignore", "pipe", "pipe"],
263
293
  // `/reasoning none`: o claude desliga o raciocínio com MAX_THINKING_TOKENS=0 (não há `--effort none`)
@@ -335,8 +365,9 @@ export class ClaudeSession {
335
365
  }
336
366
  });
337
367
  child.stderr.on("data", (d) => { stderr += d.toString(); });
338
- child.on("error", (e) => { ok = false; failure.spawnError = e.message; ui.error(`não consegui executar o claude: ${e.message}`); });
368
+ child.on("error", (e) => { spilled.cleanup(); ok = false; failure.spawnError = e.message; ui.error(`não consegui executar o claude: ${e.message}`); });
339
369
  child.on("close", (code, signal) => {
370
+ spilled.cleanup();
340
371
  this.child = null;
341
372
  interrupted = signal === "SIGINT" || code === 130 || this.aborted;
342
373
  this.aborted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brito-cli",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "description": "Coding-agent CLI with a code knowledge graph, memory and reviewable skills / CLI de agente de código com grafo de conhecimento, memória e skills revisáveis",
5
5
  "type": "module",
6
6
  "bin": {