@ureck/alexandria 1.5.0 → 1.6.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.
@@ -129,7 +129,7 @@ Solo se extrajeron ${chars} caracteres en ${pdf.numPages} p\xE1gina(s): el conte
129
129
  async function htmlToMarkdown(html) {
130
130
  const TurndownService = (await import("turndown")).default;
131
131
  const td = new TurndownService({ headingStyle: "atx", codeBlockStyle: "fenced", bulletListMarker: "-" });
132
- td.remove(["script", "style", "nav", "footer", "aside", "noscript", "iframe", "svg"]);
132
+ td.remove(["script", "style", "nav", "footer", "aside", "noscript", "iframe", "svg", "title", "head"]);
133
133
  td.addRule("table", {
134
134
  filter: "table",
135
135
  replacement: (_content, node) => {
@@ -258,5 +258,6 @@ function parseCsv(text, delim = ",") {
258
258
  export {
259
259
  PDF_TOKENS_PER_PAGE,
260
260
  formatOf,
261
- convertFile
261
+ convertFile,
262
+ htmlToMarkdown
262
263
  };
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ modelCacheDir
4
+ } from "./chunk-EDYBSJSS.js";
5
+
6
+ // src/run/fold.ts
7
+ var FOLD_THRESHOLD = 2048;
8
+ var MAX_ERROR_LINES = 30;
9
+ var TAIL_LINES = 15;
10
+ var MAX_LINE = 300;
11
+ var ANSI = /\x1b\[[0-9;?]*[A-Za-z]|\x1b\][^\x07]*\x07/g;
12
+ var ERROR_RE = /\b(error|errors|fail|failed|failure|failing|fatal|panic|exception|traceback|ERR!|cannot find|not found|undefined is not|segmentation fault)\b|✗|✘|×\s|FAIL\b|E\d{3,}/i;
13
+ var SUMMARY_RE = /^\s*(tests?:|test files|test suites?:|suites?:|ran \d+ tests?|\d+ (passed|failed|passing|failing)|=+ .*(passed|failed).* =+|ok\s+\S+\s+[\d.]+s|build (succeeded|failed|success)|compiled (successfully|with)|found \d+ (vulnerabilit|error))/i;
14
+ function stripAnsi(s) {
15
+ return s.replace(ANSI, "").replace(/\r(?!\n)/g, "\n");
16
+ }
17
+ var clip = (l) => l.length > MAX_LINE ? l.slice(0, MAX_LINE) + "\u2026" : l;
18
+ function collapse(lines) {
19
+ const out = [];
20
+ for (const l of lines) {
21
+ if (!l.trim()) {
22
+ if (out.length && out[out.length - 1] !== "") out.push("");
23
+ continue;
24
+ }
25
+ const prev = out[out.length - 1];
26
+ const m = prev?.match(/^(.*) \(×(\d+)\)$/);
27
+ if (prev === l) out[out.length - 1] = `${l} (\xD72)`;
28
+ else if (m && m[1] === l) out[out.length - 1] = `${l} (\xD7${Number(m[2]) + 1})`;
29
+ else out.push(l);
30
+ }
31
+ return out;
32
+ }
33
+ function foldOutput({ output, exitCode, ms, id, command }) {
34
+ const clean = stripAnsi(output);
35
+ if (clean.length <= FOLD_THRESHOLD) return { text: clean, folded: false, originalChars: clean.length };
36
+ const lines = clean.split("\n");
37
+ const keep = /* @__PURE__ */ new Set();
38
+ let errors = 0;
39
+ const PASS = /^\s*(✓|✔|√|ok\b|PASS\b|passed\b)/i;
40
+ lines.forEach((l, i) => {
41
+ if (errors >= MAX_ERROR_LINES || PASS.test(l) || !ERROR_RE.test(l)) return;
42
+ for (let j = i - 1; j <= i + 3; j++) if (j >= 0 && j < lines.length && lines[j].trim()) keep.add(j);
43
+ errors++;
44
+ });
45
+ while (lines.length && !lines[lines.length - 1].trim()) lines.pop();
46
+ const tailStart = Math.max(0, lines.length - TAIL_LINES);
47
+ const summary = lines.filter((l, i) => i < tailStart && SUMMARY_RE.test(l)).slice(-8);
48
+ const errBlock = [];
49
+ let last = -2;
50
+ for (const i of [...keep].sort((a, b) => a - b)) {
51
+ if (i >= tailStart) continue;
52
+ if (i > last + 1 && errBlock.length) errBlock.push(" \u22EF");
53
+ errBlock.push(clip(lines[i]));
54
+ last = i;
55
+ }
56
+ const secs = (ms / 1e3).toFixed(1);
57
+ const parts = [
58
+ `\u29C9 ${command.length > 80 ? command.slice(0, 80) + "\u2026" : command} \xB7 exit ${exitCode} \xB7 ${secs}s \xB7 ${lines.length} l\xEDneas (${Math.ceil(clean.length / 4).toLocaleString("en")} tokens) \u2192 plegado por Alexandria`
59
+ ];
60
+ if (errBlock.length) parts.push(`\u2014 errores/fallos \u2014
61
+ ${collapse(errBlock).join("\n")}`);
62
+ const shown = new Set(errBlock);
63
+ const freshSummary = summary.map(clip).filter((l) => !shown.has(l));
64
+ if (freshSummary.length) parts.push(`\u2014 resumen \u2014
65
+ ${collapse(freshSummary).join("\n")}`);
66
+ parts.push(`\u2014 final \u2014
67
+ ${collapse(lines.slice(tailStart).map(clip)).join("\n").trim()}`);
68
+ parts.push(`salida completa: ale run show ${id} [--grep <regex>] [--lines a-b] (o tool MCP run_output)`);
69
+ return { text: parts.join("\n"), folded: true, originalChars: clean.length };
70
+ }
71
+ var NOISY = /^(\s*(npx\s+|bunx\s+)?)(npm|pnpm|yarn|bun)\s+(run\s+)?(test|build|lint|typecheck|check|install|i|ci|add|audit)\b|^\s*npx\s+(vitest|jest|tsc|eslint|next\s+build|playwright\s+test|prisma\s+(migrate|generate))\b|^\s*(pytest|python3?\s+-m\s+pytest|cargo\s+(build|test|check|clippy)|go\s+(test|build|vet)|mvn\b|\.?\/?gradlew?\b|docker\s+(build|compose\s+(up|build))|dotnet\s+(build|test)|composer\s+install|pip3?\s+install|make)\b/;
72
+ var VIEWER = /^\s*(cat|head|tail|sed|awk|less|more|bat|jq|yq|diff|grep|rg|find|ls|tree|curl|wget|wc|git\s+(show|diff|log|blame|status)|node\s+-[ep]|python3?\s+-c)\b/;
73
+ var GENERIC_FOLD = 4e4;
74
+ function shouldFoldOutput(command, chars) {
75
+ if (chars <= FOLD_THRESHOLD) return false;
76
+ if (/\bale\s+run\b|\balexandria\s+run\b|cli\.js"?\s+run\b/.test(command)) return false;
77
+ const last = (command.split("&&").pop() ?? "").trim();
78
+ if (NOISY.test(last)) return true;
79
+ return chars > GENERIC_FOLD && !VIEWER.test(last);
80
+ }
81
+
82
+ // src/run/run.ts
83
+ import fs from "fs";
84
+ import path from "path";
85
+ import crypto from "crypto";
86
+ import { spawn } from "child_process";
87
+ var KEEP_RUNS = 50;
88
+ var MAX_CAPTURE = 50 * 1024 * 1024;
89
+ function runsDir() {
90
+ return path.join(path.dirname(modelCacheDir()), "runs");
91
+ }
92
+ function newId() {
93
+ return Date.now().toString(36) + crypto.randomBytes(2).toString("hex");
94
+ }
95
+ function rotate() {
96
+ try {
97
+ const metas = fs.readdirSync(runsDir()).filter((f) => f.endsWith(".json")).sort();
98
+ for (const f of metas.slice(0, Math.max(0, metas.length - KEEP_RUNS))) {
99
+ const id = f.slice(0, -5);
100
+ fs.rmSync(path.join(runsDir(), `${id}.json`), { force: true });
101
+ fs.rmSync(path.join(runsDir(), `${id}.log`), { force: true });
102
+ }
103
+ } catch {
104
+ }
105
+ }
106
+ function runCommand(command, cwd = process.cwd()) {
107
+ return new Promise((resolve) => {
108
+ const started = Date.now();
109
+ const chunks = [];
110
+ let size = 0;
111
+ const take = (b) => {
112
+ if (size < MAX_CAPTURE) chunks.push(b);
113
+ size += b.length;
114
+ };
115
+ const child = spawn(command, { cwd, shell: true, env: process.env, windowsHide: true });
116
+ child.stdout.on("data", take);
117
+ child.stderr.on("data", take);
118
+ const finish = (code) => {
119
+ let output = Buffer.concat(chunks).toString("utf8");
120
+ if (size > MAX_CAPTURE) output += `
121
+ \u2026(salida truncada a ${MAX_CAPTURE / 1024 / 1024} MB de ${(size / 1024 / 1024).toFixed(1)} MB)`;
122
+ resolve(saveRun({ command, cwd, output, exitCode: code, ms: Date.now() - started }));
123
+ };
124
+ child.on("error", (e) => {
125
+ take(Buffer.from(String(e.message)));
126
+ finish(127);
127
+ });
128
+ child.on("close", (code, signal) => finish(code ?? (signal ? 128 : 1)));
129
+ });
130
+ }
131
+ function saveRun(r) {
132
+ const id = newId();
133
+ const meta = { id, command: r.command, cwd: r.cwd, exitCode: r.exitCode, ms: r.ms, chars: r.output.length, t: (/* @__PURE__ */ new Date()).toISOString() };
134
+ const fold = foldOutput({ output: r.output, exitCode: r.exitCode, ms: r.ms, id, command: r.command });
135
+ if (fold.folded) {
136
+ try {
137
+ fs.mkdirSync(runsDir(), { recursive: true });
138
+ fs.writeFileSync(path.join(runsDir(), `${id}.log`), stripAnsi(r.output));
139
+ fs.writeFileSync(path.join(runsDir(), `${id}.json`), JSON.stringify(meta));
140
+ rotate();
141
+ } catch {
142
+ }
143
+ }
144
+ return { meta, fold };
145
+ }
146
+ function showRun(id, opts = {}) {
147
+ const ref = id === "last" ? lastRunId() : id;
148
+ const file = ref ? path.join(runsDir(), `${ref}.log`) : "";
149
+ if (!ref || !fs.existsSync(file)) return `No encontr\xE9 la corrida \xAB${id}\xBB. Las \xFAltimas: ${listRuns(5).map((m) => m.id).join(", ") || "(ninguna)"}`;
150
+ const all = fs.readFileSync(file, "utf8").split("\n");
151
+ let picked = all.map((l, i) => ({ n: i + 1, l }));
152
+ if (opts.lines) {
153
+ const [a, b] = opts.lines.split("-").map((x) => parseInt(x, 10));
154
+ picked = picked.filter((x) => x.n >= (a || 1) && x.n <= (b || a || all.length));
155
+ }
156
+ if (opts.grep) {
157
+ let re;
158
+ try {
159
+ re = new RegExp(opts.grep, "i");
160
+ } catch {
161
+ re = new RegExp(opts.grep.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
162
+ }
163
+ picked = picked.filter((x) => re.test(x.l));
164
+ }
165
+ const budget = (opts.maxTokens ?? 2e3) * 4;
166
+ const out = [];
167
+ let used = 0;
168
+ for (const x of picked) {
169
+ const line = `${x.n}: ${x.l}`;
170
+ if (used + line.length > budget) {
171
+ out.push(`\u2026(+${picked.length - out.length} l\xEDneas; acota con --lines o --grep, o sube max_tokens)`);
172
+ break;
173
+ }
174
+ out.push(line);
175
+ used += line.length + 1;
176
+ }
177
+ return `corrida ${ref} \xB7 ${picked.length} de ${all.length} l\xEDneas
178
+ ${out.join("\n")}`;
179
+ }
180
+ function listRuns(n = 10) {
181
+ try {
182
+ return fs.readdirSync(runsDir()).filter((f) => f.endsWith(".json")).sort().slice(-n).reverse().map((f) => JSON.parse(fs.readFileSync(path.join(runsDir(), f), "utf8")));
183
+ } catch {
184
+ return [];
185
+ }
186
+ }
187
+ function lastRunId() {
188
+ return listRuns(1)[0]?.id;
189
+ }
190
+
191
+ export {
192
+ shouldFoldOutput,
193
+ runCommand,
194
+ saveRun,
195
+ showRun,
196
+ listRuns
197
+ };
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  VaultIndex
4
- } from "./chunk-BV2KJV5W.js";
4
+ } from "./chunk-44QPE5IM.js";
5
5
 
6
6
  // src/graph/viewer.ts
7
7
  import fs from "fs";
@@ -1,15 +1,17 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ isoDate,
4
+ supersedeNote
5
+ } from "./chunk-44QPE5IM.js";
2
6
  import {
3
7
  charsToTokens
4
- } from "./chunk-POA77JSS.js";
8
+ } from "./chunk-X4V6SYYA.js";
5
9
  import {
6
10
  isHarnessInjected
7
- } from "./chunk-CEHNXDUE.js";
8
- import {
9
- isoDate
10
- } from "./chunk-BV2KJV5W.js";
11
+ } from "./chunk-YICWI3U3.js";
11
12
  import {
12
13
  MODEL_ID,
14
+ dot,
13
15
  modelCacheDir
14
16
  } from "./chunk-EDYBSJSS.js";
15
17
 
@@ -19,6 +21,8 @@ import path from "path";
19
21
  import matter from "gray-matter";
20
22
  var ARCHIVE_DIR = "archive";
21
23
  var STATS_KEEP_DAYS = 90;
24
+ var DUPLICATE_COSINE = 0.96;
25
+ var DEDUPE_TYPES = ["lesson", "note", "solution"];
22
26
  function archiveRoot(vault) {
23
27
  return path.join(vault.managed, ARCHIVE_DIR);
24
28
  }
@@ -100,7 +104,30 @@ function planClean(vault, notes, opts) {
100
104
  }
101
105
  } catch {
102
106
  }
103
- return { bundles, noise, tmpFiles, staleModels, statsLinesToRotate: oldStatsLines(vault).length };
107
+ return { bundles, noise, tmpFiles, staleModels, statsLinesToRotate: oldStatsLines(vault).length, duplicates: findDuplicates(opts) };
108
+ }
109
+ function findDuplicates(opts) {
110
+ if (opts.dedupe === false || !opts.idx) return [];
111
+ const vecs = opts.idx.noteVectors(DEDUPE_TYPES);
112
+ const rels = [...vecs.keys()];
113
+ const used = /* @__PURE__ */ new Set();
114
+ const out = [];
115
+ for (let i = 0; i < rels.length; i++) {
116
+ for (let j = i + 1; j < rels.length; j++) {
117
+ const a = rels[i];
118
+ const b = rels[j];
119
+ if (used.has(a) || used.has(b)) continue;
120
+ const na = opts.idx.meta.notes[a];
121
+ const nb = opts.idx.meta.notes[b];
122
+ if (!na || !nb || na.type !== nb.type) continue;
123
+ const cos = dot(vecs.get(a), vecs.get(b));
124
+ if (cos < DUPLICATE_COSINE) continue;
125
+ const [older, newer] = (na.created ?? "") <= (nb.created ?? "") ? [na, nb] : [nb, na];
126
+ out.push({ older, newer, cos: Math.round(cos * 1e3) / 1e3 });
127
+ used.add(older.rel);
128
+ }
129
+ }
130
+ return out;
104
131
  }
105
132
  function oldStatsLines(vault) {
106
133
  const cutoff = Date.now() - STATS_KEEP_DAYS * 864e5;
@@ -108,7 +135,7 @@ function oldStatsLines(vault) {
108
135
  return fs.readFileSync(path.join(vault.cache, "stats.jsonl"), "utf8").split("\n").filter((l) => {
109
136
  try {
110
137
  const o = JSON.parse(l);
111
- return o.t !== "summary" && o.kind !== "doc" && Date.parse(o.t ?? "") < cutoff;
138
+ return o.t !== "summary" && ["inject", "session-start", "solution-cache"].includes(o.kind ?? "inject") && Date.parse(o.t ?? "") < cutoff;
112
139
  } catch {
113
140
  return false;
114
141
  }
@@ -128,8 +155,8 @@ function section(n, text) {
128
155
  ${text}
129
156
  `;
130
157
  }
131
- function applyClean(vault, plan) {
132
- const res = { compacted: 0, dropped: 0, bundlesWritten: 0, removedDerived: 0, bytesFreed: 0 };
158
+ function applyClean(vault, plan, opts = {}) {
159
+ const res = { compacted: 0, dropped: 0, bundlesWritten: 0, removedDerived: 0, bytesFreed: 0, superseded: 0 };
133
160
  for (const [key, list] of plan.bundles) {
134
161
  const [proj, month] = key.split("/");
135
162
  const file = path.join(archiveRoot(vault), proj, `${month}.md`);
@@ -171,6 +198,13 @@ Proyecto: [[Mapa - ${proj}]]
171
198
  fs.rmSync(p, { recursive: true, force: true });
172
199
  res.removedDerived++;
173
200
  }
201
+ for (const d of opts.applyDuplicates ? plan.duplicates : []) {
202
+ try {
203
+ supersedeNote(path.join(vault.root, d.older.rel), d.newer.title);
204
+ res.superseded++;
205
+ } catch {
206
+ }
207
+ }
174
208
  rotateStats(vault);
175
209
  return res;
176
210
  }
@@ -4,7 +4,7 @@ import {
4
4
  defaultOutput,
5
5
  formatContext,
6
6
  normalizeInput
7
- } from "./chunk-CEHNXDUE.js";
7
+ } from "./chunk-YICWI3U3.js";
8
8
 
9
9
  // src/hooks/util.ts
10
10
  import fs from "fs";
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/core/stats.ts
4
+ import fs from "fs";
5
+ import path from "path";
6
+ var charsToTokens = (chars) => Math.round(chars / 4);
7
+ function logInjection(vault, line) {
8
+ try {
9
+ fs.mkdirSync(vault.cache, { recursive: true });
10
+ fs.appendFileSync(
11
+ path.join(vault.cache, "stats.jsonl"),
12
+ JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), ...line }) + "\n"
13
+ );
14
+ } catch {
15
+ }
16
+ }
17
+ function logDocUse(vault, line) {
18
+ try {
19
+ fs.mkdirSync(vault.cache, { recursive: true });
20
+ fs.appendFileSync(path.join(vault.cache, "stats.jsonl"), JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), kind: "doc", ...line }) + "\n");
21
+ } catch {
22
+ }
23
+ }
24
+ function logFold(vault, line) {
25
+ try {
26
+ fs.mkdirSync(vault.cache, { recursive: true });
27
+ fs.appendFileSync(path.join(vault.cache, "stats.jsonl"), JSON.stringify({ t: (/* @__PURE__ */ new Date()).toISOString(), kind: "fold", ...line }) + "\n");
28
+ } catch {
29
+ }
30
+ }
31
+ var EST_LOW = 3;
32
+ var EST_HIGH = 8;
33
+ function readStats(vault) {
34
+ const file = path.join(vault.cache, "stats.jsonl");
35
+ const summary = {
36
+ injections: 0,
37
+ solutionCacheHits: 0,
38
+ injectedTokens: 0,
39
+ cacheHitTokens: 0,
40
+ estSavedLow: 0,
41
+ estSavedHigh: 0,
42
+ docIngests: 0,
43
+ docReads: 0,
44
+ docTokensOriginal: 0,
45
+ docTokensServed: 0,
46
+ folds: 0,
47
+ foldTokensOriginal: 0,
48
+ foldTokensServed: 0,
49
+ dedupSavedTokens: 0
50
+ };
51
+ try {
52
+ for (const raw of fs.readFileSync(file, "utf8").split("\n")) {
53
+ if (!raw.trim()) continue;
54
+ try {
55
+ const line = JSON.parse(raw);
56
+ if (line.kind === "fold") {
57
+ const f = line;
58
+ summary.folds++;
59
+ summary.foldTokensOriginal += charsToTokens(f.originalChars ?? 0);
60
+ summary.foldTokensServed += charsToTokens(f.servedChars ?? 0);
61
+ continue;
62
+ }
63
+ if (line.kind === "doc") {
64
+ const d = line;
65
+ if (d.op === "ingest") summary.docIngests++;
66
+ else summary.docReads++;
67
+ summary.docTokensOriginal += d.tokensOriginal ?? 0;
68
+ summary.docTokensServed += d.tokensServed ?? 0;
69
+ continue;
70
+ }
71
+ const n = line.count ?? 1;
72
+ if (line.dedupSkippedChars) summary.dedupSavedTokens += charsToTokens(line.dedupSkippedChars);
73
+ summary.injections += n;
74
+ const tk = line.tokens ?? charsToTokens(line.injectedChars);
75
+ summary.injectedTokens += tk;
76
+ if (line.kind === "solution-cache") {
77
+ summary.solutionCacheHits += n;
78
+ summary.cacheHitTokens += tk;
79
+ }
80
+ } catch {
81
+ }
82
+ }
83
+ } catch {
84
+ }
85
+ summary.estSavedLow = summary.injectedTokens * EST_LOW;
86
+ summary.estSavedHigh = summary.injectedTokens * EST_HIGH;
87
+ return summary;
88
+ }
89
+ function readSessionUsage(vault) {
90
+ const by = /* @__PURE__ */ new Map();
91
+ let raw = "";
92
+ try {
93
+ raw = fs.readFileSync(path.join(vault.cache, "stats.jsonl"), "utf8");
94
+ } catch {
95
+ return [];
96
+ }
97
+ for (const l of raw.split("\n")) {
98
+ if (!l.trim()) continue;
99
+ let o;
100
+ try {
101
+ o = JSON.parse(l);
102
+ } catch {
103
+ continue;
104
+ }
105
+ if (!o.session || o.t === "summary") continue;
106
+ const u = by.get(o.session) ?? { session: o.session, first: o.t ?? "", last: o.t ?? "", injections: 0, injectedTokens: 0, dedupSavedTokens: 0, folds: 0, foldTokensOriginal: 0, foldTokensServed: 0, topNotes: [], notes: /* @__PURE__ */ new Map() };
107
+ if (o.t && o.t < u.first) u.first = o.t;
108
+ if (o.t && o.t > u.last) u.last = o.t;
109
+ if (o.kind === "fold") {
110
+ u.folds++;
111
+ u.foldTokensOriginal += charsToTokens(o.originalChars ?? 0);
112
+ u.foldTokensServed += charsToTokens(o.servedChars ?? 0);
113
+ } else if (o.kind !== "doc") {
114
+ u.injections++;
115
+ u.injectedTokens += charsToTokens(o.injectedChars ?? 0);
116
+ u.dedupSavedTokens += charsToTokens(o.dedupSkippedChars ?? 0);
117
+ for (const r of o.rels ?? []) u.notes.set(r, (u.notes.get(r) ?? 0) + 1);
118
+ }
119
+ by.set(o.session, u);
120
+ }
121
+ return [...by.values()].map(({ notes, ...u }) => ({ ...u, topNotes: [...notes].sort((a, b) => b[1] - a[1]).slice(0, 5) })).sort((a, b) => b.last.localeCompare(a.last));
122
+ }
123
+
124
+ export {
125
+ charsToTokens,
126
+ logInjection,
127
+ logDocUse,
128
+ logFold,
129
+ readStats,
130
+ readSessionUsage
131
+ };
@@ -154,6 +154,18 @@ var TOKEN_TOGGLES = [
154
154
  desc: "En Claude Code, la primera lectura directa de un PDF/DOCX/XLSX/CSV grande se redirige a doc_ingest/doc_read (el segundo intento pasa)",
155
155
  impact: "ahorra ~2,000 tokens por p\xE1gina de PDF; desact\xEDvalo si sueles necesitar ver im\xE1genes/gr\xE1ficas"
156
156
  },
157
+ {
158
+ key: "run.fold",
159
+ label: "Plegar salida grande de comandos",
160
+ desc: "Builds/tests/installs/logs largos: el agente recibe errores + resumen + final; la salida completa queda en disco (ale run show)",
161
+ impact: "ahorra la mayor parte de un build o test suite (miles de tokens por corrida); desact\xEDvalo si quieres ver siempre todo"
162
+ },
163
+ {
164
+ key: "context.dedupe",
165
+ label: "No reinyectar lo ya inyectado",
166
+ desc: "Si una nota ya se inyect\xF3 en esta sesi\xF3n, se manda una referencia de 1 l\xEDnea en vez del extracto completo",
167
+ impact: "ahorra hasta ~1500 tokens por prompt en conversaciones largas sobre el mismo tema"
168
+ },
157
169
  {
158
170
  key: "clean.auto",
159
171
  label: "Limpieza autom\xE1tica semanal",
@@ -185,7 +197,11 @@ function normalizeInput(raw) {
185
197
  answer: raw.last_assistant_message ?? raw.prompt_response ?? raw.text,
186
198
  compact: /^(PreCompact|PreCompress|preCompact)$/.test(event) || Boolean(raw.trigger),
187
199
  toolName: raw.tool_name,
188
- filePath: raw.tool_input?.file_path
200
+ filePath: raw.tool_input?.file_path,
201
+ command: typeof raw.tool_input?.command === "string" ? raw.tool_input.command : void 0,
202
+ toolResponse: raw.tool_response,
203
+ durationMs: raw.duration_ms,
204
+ source: raw.source
189
205
  };
190
206
  }
191
207
  function formatContext(harness, kind, text) {
@@ -234,7 +250,9 @@ function lastExchange(lines) {
234
250
  return { user, assistant };
235
251
  }
236
252
  function isHarnessInjected(prompt) {
237
- return /^<(task-notification|system-reminder|command-|local-command|user-prompt-submit-hook|ide_)/i.test(prompt.trim());
253
+ const p = prompt.trim();
254
+ return /^<(task-notification|system-reminder|command-|local-command|user-prompt-submit-hook|ide_)/i.test(p) || // mensajes que el arnés escribe como si fueran del usuario
255
+ /^(Tool loaded\.|Your response above was cut off|This session is being continued from a previous conversation|\[Request interrupted|Caveat: The messages below were generated)/i.test(p);
238
256
  }
239
257
 
240
258
  export {