@meiti/healer 0.3.0 → 0.5.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.
- package/mcp/servidor.mjs +22 -7
- package/package.json +1 -1
package/mcp/servidor.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import path from 'node:path';
|
|
|
14
14
|
import crypto from 'node:crypto';
|
|
15
15
|
import readline from 'node:readline';
|
|
16
16
|
|
|
17
|
-
const VERSION = '0.
|
|
17
|
+
const VERSION = '0.6.0';
|
|
18
18
|
const API = (process.env.HEALER_API_URL || 'https://healer-api.meiti.dev').replace(/\/$/, '');
|
|
19
19
|
const leerClave = () => String(process.env.CLAUDE_PLUGIN_OPTION_API_KEY || '').trim();
|
|
20
20
|
const ESTADO = path.join(os.tmpdir(), 'healer-claude-code');
|
|
@@ -120,7 +120,7 @@ const archivoDeTrabajo = (jobId) => path.join(ESTADO, `${String(jobId).replace(/
|
|
|
120
120
|
|
|
121
121
|
// ───────────────────────────── Herramientas ─────────────────────────────
|
|
122
122
|
|
|
123
|
-
async function revisar({ ruta, nivel, tests, confirmar_free, solo_revisar }) {
|
|
123
|
+
async function revisar({ ruta, nivel, tests, confirmar_free, solo_revisar, bug }) {
|
|
124
124
|
const raiz = path.resolve(ruta || process.cwd());
|
|
125
125
|
if (!fs.existsSync(raiz) || !fs.statSync(raiz).isDirectory()) throw new Error(`Folder not found: ${raiz}.`);
|
|
126
126
|
const { files, total, omitidos } = archivosDelProyecto(raiz);
|
|
@@ -131,7 +131,7 @@ async function revisar({ ruta, nivel, tests, confirmar_free, solo_revisar }) {
|
|
|
131
131
|
// Si tocaría free y la organización pide preguntar, Healer responde 409 y no se encola nada.
|
|
132
132
|
let envio;
|
|
133
133
|
try {
|
|
134
|
-
envio = await api('POST', '/v1/repair', { files, app_id: appId, ...(nivel === 'free' || nivel === 'pro' ? { ai_level: nivel } : {}), ...(confirmar_free === true ? { confirm_free: true } : {}), ...(solo_revisar === true ? { review_only: true } : {}) });
|
|
134
|
+
envio = await api('POST', '/v1/repair', { files, app_id: appId, ...(nivel === 'free' || nivel === 'pro' ? { ai_level: nivel } : {}), ...(confirmar_free === true ? { confirm_free: true } : {}), ...(solo_revisar === true ? { review_only: true } : {}), ...(typeof bug === 'string' && bug.trim() ? { bug_report: bug.trim().slice(0, 4000) } : {}) });
|
|
135
135
|
} catch (e) {
|
|
136
136
|
if (e.status === 409) return `Needs the user's confirmation, nothing was queued: ${e.datos?.message}\nIn this tool, "confirm_free" is confirmar_free: true${e.datos?.reason === 'cupo_agotado' ? ', and "review_only" is solo_revisar: true' : ''}.`;
|
|
137
137
|
throw e;
|
|
@@ -199,18 +199,27 @@ async function resultado({ job_id, esperar_segundos }) {
|
|
|
199
199
|
const meta = fs.existsSync(archivoDeTrabajo(job_id)) ? JSON.parse(fs.readFileSync(archivoDeTrabajo(job_id), 'utf8')) : null;
|
|
200
200
|
const cambiados = r.changed_files || [];
|
|
201
201
|
// La propuesta queda guardada para healer_aplicar (y para mirarla con calma).
|
|
202
|
-
if (meta) fs.writeFileSync(archivoDeTrabajo(job_id), JSON.stringify({ ...meta, terminado: new Date().toISOString(), status: r.status, changed_files: cambiados, base_hashes: r.base_hashes || {}, files: Object.fromEntries(cambiados.map((c) => [c, r.files?.[c]])) }));
|
|
202
|
+
if (meta) fs.writeFileSync(archivoDeTrabajo(job_id), JSON.stringify({ ...meta, terminado: new Date().toISOString(), status: r.status, changed_files: cambiados, base_hashes: r.base_hashes || {}, ...(r.requires_acceptance ? { requires_acceptance: r.requires_acceptance } : {}), files: Object.fromEntries(cambiados.map((c) => [c, r.files?.[c]])) }));
|
|
203
203
|
|
|
204
204
|
const lineas = [];
|
|
205
|
-
const titulo = { production_ready: 'Production ready: every check passes.', unresolved: r.partial_fix ? 'Partial delivery: some failures fixed, some remain.' : 'Unresolved: Healer could not leave every check passing.', unsupported_stack: 'Unsupported stack: no supported language was found to verify.' }[r.status] || r.status;
|
|
205
|
+
const titulo = r.not_accepted ? `Not accepted: ${r.not_accepted.reason} Healer only reviewed it; nothing was repaired and it does not count as a repair success or failure.` : { production_ready: 'Production ready: every check passes.', unresolved: r.partial_fix ? 'Partial delivery: some failures fixed, some remain.' : 'Unresolved: Healer could not leave every check passing.', unsupported_stack: 'Unsupported stack: no supported language was found to verify.' }[r.status] || r.status;
|
|
206
206
|
lineas.push(`Result: ${titulo}`);
|
|
207
207
|
// 🔐 [2026-11-16] Siempre se dice con qué nivel corrió y por qué.
|
|
208
208
|
if (r.ai_level) lineas.push(`AI level: ${r.ai_level === 'none' ? 'none (review only)' : r.ai_level}${r.ai_level_reason ? ` (${({ pedido: 'requested', organizacion: 'organization default', cupo: 'single repairs', confirmado: 'confirmed by the user', auto: 'organization allows free automatically', solo_revisar: 'review only', benchmark: 'benchmark' })[r.ai_level_reason] || r.ai_level_reason})` : ''}.`);
|
|
209
209
|
// 📋 [2026-11-14, pedido del usuario: "el usuario no ve lo que vemos, no lo demos por hecho"] El informe de Healer (report):
|
|
210
210
|
// qué se reparó, tests antes y después, y cada pendiente con qué es, por qué quedó y qué hace falta. Sin informe (Healer
|
|
211
211
|
// de antes), la línea de fallas de siempre.
|
|
212
|
+
// 🔬 [2026-11-16] Reproducir antes de reparar: si vino con bug_report, el test que lo reprodujo y si pasa después.
|
|
213
|
+
if (r.reproduction) {
|
|
214
|
+
const rp = r.reproduction;
|
|
215
|
+
lineas.push(rp.status === 'reproduced'
|
|
216
|
+
? `Bug reproduced with a test (${rp.test_file}): it failed with the original code${rp.passes_after === true ? ' and passes after the repair' : rp.passes_after === false ? ', and it STILL FAILS after the repair' : ''}. Offer the user to add this test to the project so the bug cannot come back:\n${String(rp.test_content || '').split('\n').map((l) => ' ' + l).join('\n')}`
|
|
217
|
+
: `Bug NOT reproduced (${rp.status}): ${rp.message}`);
|
|
218
|
+
}
|
|
212
219
|
if (r.report) {
|
|
213
220
|
lineas.push(`Summary: ${r.report.headline}`);
|
|
221
|
+
// ⚖️ [2026-11-16] Una dependencia que baja el puntaje: lo primero que tiene que saber la persona.
|
|
222
|
+
if (r.requires_acceptance) lineas.push(`NEEDS THE USER'S ACCEPTANCE (tell them before anything else): ${r.requires_acceptance.reason} Quality score ${r.requires_acceptance.pentagono_before} → ${r.requires_acceptance.pentagono_after}. Apply it only if they accept (healer_aplicar with acepto_puntaje_menor: true), or leave out ${r.requires_acceptance.files.join(', ')}.`);
|
|
214
223
|
for (const x of r.report.fixed || []) lineas.push(`Fixed: ${x}`);
|
|
215
224
|
if ((r.report.pending || []).length) {
|
|
216
225
|
lineas.push('Pending (tell the user every item and what it needs; they decide whether to send it again or handle it themselves):');
|
|
@@ -286,7 +295,7 @@ function diffDe(antes, despues) {
|
|
|
286
295
|
return salida.join('\n').slice(0, 12000);
|
|
287
296
|
}
|
|
288
297
|
|
|
289
|
-
async function aplicar({ job_id, archivos }) {
|
|
298
|
+
async function aplicar({ job_id, archivos, acepto_puntaje_menor }) {
|
|
290
299
|
const archivo = archivoDeTrabajo(job_id);
|
|
291
300
|
if (!fs.existsSync(archivo)) throw new Error('No proposal stored for that job: call healer_resultado first.');
|
|
292
301
|
const t = JSON.parse(fs.readFileSync(archivo, 'utf8'));
|
|
@@ -298,6 +307,11 @@ async function aplicar({ job_id, archivos }) {
|
|
|
298
307
|
if (ajenos.length) throw new Error(`These are not among the files Healer changed: ${ajenos.join(', ')}. Changed files: ${t.changed_files.join(', ')}.`);
|
|
299
308
|
}
|
|
300
309
|
const elegidos = pedidos ?? t.changed_files;
|
|
310
|
+
// ⚖️ [2026-11-16] La misma regla que Healer (orquestador/aceptacion.ts): sin el sí del usuario, la dependencia que baja el
|
|
311
|
+
// puntaje no se escribe. Dejarla afuera y aplicar el resto sí se puede.
|
|
312
|
+
const ra = t.requires_acceptance;
|
|
313
|
+
const tocados = ra && acepto_puntaje_menor !== true ? ra.files.filter((x) => elegidos.includes(x)) : [];
|
|
314
|
+
if (tocados.length) return `Needs the user's acceptance before applying: ${ra.reason} Quality score ${ra.pentagono_before} → ${ra.pentagono_after}. Ask the user; if they accept the lower score, call healer_aplicar again with acepto_puntaje_menor: true. Or leave out ${tocados.join(', ')} and apply the rest.`;
|
|
301
315
|
// La base tiene que coincidir: si el usuario tocó un archivo después de mandarlo, ese no se pisa.
|
|
302
316
|
const distintos = elegidos.filter((ruta) => {
|
|
303
317
|
const local = path.join(t.raiz, ruta);
|
|
@@ -364,6 +378,7 @@ const HERRAMIENTAS = [
|
|
|
364
378
|
nivel: { type: 'string', enum: ['free', 'pro'], description: 'Optional. Leave it out unless the user asked for a level: the organization default applies (pro unless the owner changed it). Free means free AI providers, which may keep what they receive, and the code may be used for training.' },
|
|
365
379
|
confirmar_free: { type: 'boolean', description: 'Only after the user said yes to the free level for THIS job (Healer asks when a job would run on free). Never set it on your own.' },
|
|
366
380
|
solo_revisar: { type: 'boolean', description: 'Run the checks without repairing and without AI (offered when the pro repairs are used up and the user does not want free).' },
|
|
381
|
+
bug: { type: 'string', description: 'Optional: the bug as the user tells it (what they did, what they expected, what happened). Healer first writes a test that reproduces it and checks that it fails with the current code; only then repairs, and the test must pass after. If it does not reproduce, nothing is repaired blindly.' },
|
|
367
382
|
tests: { type: 'array', items: { type: 'string' }, description: 'Optional: the tests that define "fixed" (e.g. tests/test_api.py::test_login). Without this Healer runs the full suite.' }
|
|
368
383
|
}
|
|
369
384
|
},
|
|
@@ -378,7 +393,7 @@ const HERRAMIENTAS = [
|
|
|
378
393
|
{
|
|
379
394
|
name: 'healer_aplicar',
|
|
380
395
|
description: 'Write Healer\'s proposed changes into the project. Only call it after the user agreed. Pass "archivos" to write only the files the user approved (the rest are left out). It refuses any file that changed since it was sent.',
|
|
381
|
-
inputSchema: { type: 'object', properties: { job_id: { type: 'string' }, archivos: { type: 'array', items: { type: 'string' }, description: 'Optional: paths (as listed by healer_resultado) of the only files to write.' } }, required: ['job_id'] },
|
|
396
|
+
inputSchema: { type: 'object', properties: { job_id: { type: 'string' }, archivos: { type: 'array', items: { type: 'string' }, description: 'Optional: paths (as listed by healer_resultado) of the only files to write.' }, acepto_puntaje_menor: { type: 'boolean', description: 'Only when the result says "Needs the user acceptance" and the user explicitly accepted the lower quality score.' } }, required: ['job_id'] },
|
|
382
397
|
run: aplicar
|
|
383
398
|
},
|
|
384
399
|
{
|