@meiti/healer 0.2.0 → 0.2.2

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.
Files changed (2) hide show
  1. package/mcp/servidor.mjs +41 -12
  2. package/package.json +2 -2
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.3.3';
17
+ const VERSION = '0.3.6';
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');
@@ -145,7 +145,8 @@ async function resultado({ job_id, esperar_segundos }) {
145
145
  if (!['queued', 'running'].includes(r.status) || Date.now() >= limite) break;
146
146
  await new Promise((ok) => setTimeout(ok, 5000));
147
147
  }
148
- if (r.status === 'queued' || r.status === 'running') return `Still ${r.status === 'queued' ? 'queued' : 'running'}. Call healer_resultado again in a moment.`;
148
+ // El servidor manda en qué va (proyecto, minutos, etapa, lo hecho): se muestra eso en vez de solo "running".
149
+ if (r.status === 'queued' || r.status === 'running') return `${r.progress?.message || `Still ${r.status}.`}\nCall healer_resultado again in a moment.\nJob id: ${job_id}`;
149
150
  if (r.status === 'error') return `Healer could not finish: ${r.error || 'unknown error'}.`;
150
151
 
151
152
  const meta = fs.existsSync(archivoDeTrabajo(job_id)) ? JSON.parse(fs.readFileSync(archivoDeTrabajo(job_id), 'utf8')) : null;
@@ -164,8 +165,13 @@ async function resultado({ job_id, esperar_segundos }) {
164
165
  lineas.push('No file changes to apply.');
165
166
  return lineas.join('\n');
166
167
  }
167
- lineas.push(`Proposed changes in ${cambiados.length} file(s): ${cambiados.join(', ')}.`);
168
- lineas.push('Nothing has been written. Show this to the user and apply only if they agree, with healer_aplicar.');
168
+ // Qué arregló en cada archivo, para que el usuario elija: se puede aplicar solo una parte (igual que el conector remoto).
169
+ lineas.push(`Proposed changes in ${cambiados.length} file(s). What each one fixes:`);
170
+ for (const ruta of cambiados) {
171
+ const motivos = (r.history || []).filter((h) => h?.file === ruta).map((h) => String(h.error || '').replace(/\s+/g, ' ').slice(0, 200)).filter(Boolean);
172
+ lineas.push(`- ${ruta}${motivos.length ? `\n ${motivos.map((m) => `· ${m}`).join('\n ')}` : ''}`);
173
+ }
174
+ lineas.push('Nothing has been written. Review each file against the rest of the project, show this to the user and apply only what they agree to, with healer_aplicar (pass "archivos" to apply only some files).');
169
175
  if (meta) {
170
176
  for (const ruta of cambiados) {
171
177
  const local = path.join(meta.raiz, ruta);
@@ -220,27 +226,42 @@ function diffDe(antes, despues) {
220
226
  return salida.join('\n').slice(0, 12000);
221
227
  }
222
228
 
223
- async function aplicar({ job_id }) {
229
+ async function aplicar({ job_id, archivos }) {
224
230
  const archivo = archivoDeTrabajo(job_id);
225
231
  if (!fs.existsSync(archivo)) throw new Error('No proposal stored for that job: call healer_resultado first.');
226
232
  const t = JSON.parse(fs.readFileSync(archivo, 'utf8'));
227
233
  if (!t.changed_files?.length) return 'That job has no changes to apply.';
234
+ // Solo lo que el usuario aprobó (si mandó "archivos"); un nombre que Healer no cambió frena todo.
235
+ const pedidos = Array.isArray(archivos) && archivos.length ? archivos.map(String) : null;
236
+ if (pedidos) {
237
+ const ajenos = pedidos.filter((p) => !t.changed_files.includes(p));
238
+ if (ajenos.length) throw new Error(`These are not among the files Healer changed: ${ajenos.join(', ')}. Changed files: ${t.changed_files.join(', ')}.`);
239
+ }
240
+ const elegidos = pedidos ?? t.changed_files;
228
241
  // La base tiene que coincidir: si el usuario tocó un archivo después de mandarlo, ese no se pisa.
229
- const distintos = t.changed_files.filter((ruta) => {
242
+ const distintos = elegidos.filter((ruta) => {
230
243
  const local = path.join(t.raiz, ruta);
231
244
  const actual = fs.existsSync(local) ? fs.readFileSync(local, 'utf8') : null;
232
245
  return t.base_hashes[ruta] && (actual === null || sha256(actual) !== t.base_hashes[ruta]);
233
246
  });
234
247
  if (distintos.length) return `Not applied: these files changed since they were sent to Healer: ${distintos.join(', ')}. Send the project again with healer_revisar.`;
235
- for (const ruta of t.changed_files) {
248
+ for (const ruta of elegidos) {
236
249
  const destino = path.resolve(t.raiz, ruta);
237
250
  if (!destino.startsWith(t.raiz + path.sep)) throw new Error(`Path outside the project: ${ruta}`);
238
251
  if (typeof t.files[ruta] !== 'string') continue;
239
252
  fs.mkdirSync(path.dirname(destino), { recursive: true });
240
253
  fs.writeFileSync(destino, t.files[ruta]);
241
254
  }
242
- fs.writeFileSync(archivo, JSON.stringify({ ...t, aplicado: new Date().toISOString() }));
243
- return `Applied: ${t.changed_files.length} file(s) written (${t.changed_files.join(', ')}). Review the diff with git before committing.`;
255
+ fs.writeFileSync(archivo, JSON.stringify({ ...t, aplicado: new Date().toISOString(), aplicados: elegidos }));
256
+ const descartados = t.changed_files.filter((c) => !elegidos.includes(c));
257
+ // Le cuenta a Healer qué se aplicó y qué no (solo para medir qué cambios valen la pena; si falla, no importa).
258
+ await api('POST', `/v1/repair/${encodeURIComponent(job_id)}/decision`, { aplicados: elegidos, descartados, via: 'plugin_local' }).catch(() => {});
259
+ return `Applied: ${elegidos.length} file(s) written (${elegidos.join(', ')}).${descartados.length ? ` Left out as requested: ${descartados.join(', ')}.` : ''} Review the diff with git before committing.`;
260
+ }
261
+
262
+ async function informarDecision({ job_id, aplicados = [], descartados = [] }) {
263
+ const r = await api('POST', `/v1/repair/${encodeURIComponent(job_id)}/decision`, { aplicados, descartados, via: 'agente' });
264
+ return `Thanks: recorded ${r.registrados ?? 0} decision(s) (${aplicados.length} applied, ${descartados.length} left out).`;
244
265
  }
245
266
 
246
267
  const HERRAMIENTAS = [
@@ -265,9 +286,15 @@ const HERRAMIENTAS = [
265
286
  },
266
287
  {
267
288
  name: 'healer_aplicar',
268
- description: 'Write Healer\'s proposed changes into the project. Only call it after the user agreed. It refuses any file that changed since it was sent.',
269
- inputSchema: { type: 'object', properties: { job_id: { type: 'string' } }, required: ['job_id'] },
289
+ 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.',
290
+ 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'] },
270
291
  run: aplicar
292
+ },
293
+ {
294
+ name: 'healer_informar_decision',
295
+ description: 'Tell Healer which of its changes the user decided not to apply (or applied by hand). healer_aplicar reports this by itself; use this when the user applies none, or edits by hand. Healer stores only fingerprints of the file paths, never code.',
296
+ inputSchema: { type: 'object', properties: { job_id: { type: 'string' }, aplicados: { type: 'array', items: { type: 'string' } }, descartados: { type: 'array', items: { type: 'string' } } }, required: ['job_id'] },
297
+ run: informarDecision
271
298
  }
272
299
  ];
273
300
 
@@ -282,7 +309,9 @@ readline.createInterface({ input: process.stdin }).on('line', async (linea) => {
282
309
  if (m.id === undefined) return; // notificaciones (initialized, cancelled): nada que responder
283
310
  try {
284
311
  if (m.method === 'initialize') {
285
- return responder(m.id, { protocolVersion: m.params?.protocolVersion || '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: 'healer', version: VERSION } });
312
+ // Mismo ícono y título que el conector remoto, para los clientes que los muestran (MCP 2025-11-25).
313
+ const icono = (lado) => ({ src: `https://healer-api.meiti.dev/icono-${lado}.png?v=1`, mimeType: 'image/png', sizes: [`${lado}x${lado}`] });
314
+ return responder(m.id, { protocolVersion: m.params?.protocolVersion || '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: 'healer', title: 'Healer', version: VERSION, websiteUrl: 'https://meiti.dev/healer', icons: [icono(512), icono(192), icono(64)] } });
286
315
  }
287
316
  if (m.method === 'ping') return responder(m.id, {});
288
317
  if (m.method === 'tools/list') return responder(m.id, { tools: HERRAMIENTAS.map(({ run, ...h }) => h) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meiti/healer",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Connect Healer to Claude Code (and any MCP agent) in a minute: a short code, one click in the browser, done.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,6 +32,6 @@
32
32
  ],
33
33
  "license": "MIT",
34
34
  "scripts": {
35
- "prepack": "node -e \"require('fs').mkdirSync('mcp',{recursive:true});require('fs').copyFileSync('../claude-code/plugins/healer/mcp/servidor.mjs','mcp/servidor.mjs')\""
35
+ "prepack": "node -e \"require('fs').mkdirSync('mcp',{recursive:true});require('fs').copyFileSync('../claude-code/plugins/healer-local/mcp/servidor.mjs','mcp/servidor.mjs')\""
36
36
  }
37
37
  }