@meiti/healer-sdk 0.3.0 → 0.4.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/README.md CHANGED
@@ -79,6 +79,18 @@ console.log(r.report?.headline);
79
79
  for (const p of r.report?.pending ?? []) console.log(`- ${p.what} Needs: ${p.needs}`);
80
80
  ```
81
81
 
82
+ ### AI level
83
+
84
+ Without `aiLevel`, your organization rule applies (pro unless the owner changed it in the panel). Free never runs hidden: if a job would run on free (you asked for it, or the pro repairs of the plan are used up) and the organization asks for confirmation, `repair()` and `submitRepair()` throw `HealerNeedsConfirmationError` and nothing is queued. Ask the user; if they agree, send it again with `confirmFree: true` (this job only). With the pro repairs used up, `reviewOnly: true` runs the checks without repairing and without AI.
85
+
86
+ ```ts
87
+ try {
88
+ await healer.repair({ files });
89
+ } catch (e) {
90
+ if (e instanceof HealerNeedsConfirmationError) console.log(e.reason, e.message); // ask the user first
91
+ }
92
+ ```
93
+
82
94
  ### Screen review
83
95
 
84
96
  To only check what the pages of an app show (no repair, no AI), Healer starts the app in its sandbox and reads each page:
@@ -95,6 +107,15 @@ for (const p of r.pages) console.log(p.path, p.state, p.expectations.map((e) =>
95
107
 
96
108
  Each page comes back LOADED, DID NOT LOAD (with the reason) or NOT THE EXPECTED PAGE. On a page that did not load, a `not_exists` answers CANNOT PROVE, never a false yes.
97
109
 
110
+ `startCommand`, `port` and `pages` are optional. Without them Healer finds how to start the app (`.healer.json` `"screen"`, the command that worked last time for this `appId`, or `package.json` / the Python entry file) and checks `/`. `r.start` says which command ran, where it came from (`declared`, `repo_config`, `remembered`, `detected`) and whether the app answered:
111
+
112
+ ```ts
113
+ const r = await healer.reviewScreen({ files });
114
+ console.log(r.start); // { command: 'npx vite --host 0.0.0.0 --port 5173 --strictPort', port: 5173, source: 'detected', detail: 'package.json: the "dev" script runs Vite', verified: true }
115
+ ```
116
+
117
+ To fix the command for every agent, declare it once in `.healer.json`: `{ "screen": { "start_command": "npm start", "port": 3000, "pages": [{ "path": "/" }] } }`.
118
+
98
119
  ### Partial delivery
99
120
 
100
121
  When some failures were fixed and others remain, `status` stays `"unresolved"` but the result carries
package/dist/client.d.ts CHANGED
@@ -1,9 +1,19 @@
1
- import type { EnvioAceptado, EstadoJob, ProgresoJob, ResultadoReparacion, SolicitudReparacion, ScreenReviewRequest, ScreenReviewResult } from './types.js';
1
+ import type { EnvioAceptado, EstadoJob, ProgresoJob, ResultadoReparacion, SolicitudReparacion, ScreenReviewRequest, ScreenReviewResult, HealerInfo } from './types.js';
2
2
  export declare class HealerApiError extends Error {
3
3
  readonly status: number;
4
4
  readonly body: unknown;
5
5
  constructor(status: number, body: unknown);
6
6
  }
7
+ /**
8
+ * The job would run on the free level (it asked for free, or the pro repairs of the plan are used up) and the organization asks
9
+ * for confirmation. Nothing was queued. Ask the user; if they agree, send it again with confirmFree: true (this job only), or
10
+ * with reviewOnly: true to run the checks without repairing and without AI. The owner sets the rule in the Healer panel.
11
+ */
12
+ export declare class HealerNeedsConfirmationError extends Error {
13
+ readonly reason: 'free_pedido' | 'cupo_agotado';
14
+ readonly options: string[];
15
+ constructor(body: any);
16
+ }
7
17
  export declare class HealerTimeoutError extends Error {
8
18
  constructor(jobId: string, timeoutMs: number);
9
19
  }
@@ -23,6 +33,9 @@ export declare class HealerClient {
23
33
  private readonly timeoutMs;
24
34
  constructor(options: HealerClientOptions);
25
35
  private pedir;
36
+ /** The organization rule for the AI level and the pro repairs left this month (no AI, no cost). Check it before sending a job
37
+ * to know whether it would need the user's yes for free. */
38
+ getInfo(): Promise<HealerInfo>;
26
39
  /** Envía el código y devuelve de inmediato { job_id, app_id, status: "queued" } — sin esperar
27
40
  * a que termine. Usar junto a getRepair() para armar tu propio loop de consulta, o preferir
28
41
  * repair() si alcanza con esperar el resultado final. */
package/dist/client.js CHANGED
@@ -9,6 +9,21 @@ export class HealerApiError extends Error {
9
9
  this.body = body;
10
10
  }
11
11
  }
12
+ /**
13
+ * The job would run on the free level (it asked for free, or the pro repairs of the plan are used up) and the organization asks
14
+ * for confirmation. Nothing was queued. Ask the user; if they agree, send it again with confirmFree: true (this job only), or
15
+ * with reviewOnly: true to run the checks without repairing and without AI. The owner sets the rule in the Healer panel.
16
+ */
17
+ export class HealerNeedsConfirmationError extends Error {
18
+ reason;
19
+ options;
20
+ constructor(body) {
21
+ super(body?.message || 'This job needs the user to confirm the free level.');
22
+ this.name = 'HealerNeedsConfirmationError';
23
+ this.reason = body?.reason;
24
+ this.options = Array.isArray(body?.options) ? body.options : ['confirm_free'];
25
+ }
26
+ }
12
27
  // Se agota esperando un job que nunca termina (proveedor de IA caído en serio, servidor caído a
13
28
  // mitad de camino, etc.) — nunca cuelga la llamada de "repair()" para siempre.
14
29
  export class HealerTimeoutError extends Error {
@@ -28,7 +43,9 @@ function cuerpoHttp(request) {
28
43
  app_intent: request.appIntent,
29
44
  start_command: request.startCommand,
30
45
  port: request.port,
31
- ai_level: request.aiLevel
46
+ ai_level: request.aiLevel,
47
+ confirm_free: request.confirmFree,
48
+ review_only: request.reviewOnly
32
49
  };
33
50
  }
34
51
  // 🎓 [SDK OFICIAL, 2026-09-16, pedido explícito: "vender el pipeline vía API... entre menos
@@ -59,11 +76,18 @@ export class HealerClient {
59
76
  });
60
77
  const texto = await respuesta.text();
61
78
  const datos = texto ? JSON.parse(texto) : null;
79
+ if (respuesta.status === 409 && datos?.status === 'needs_confirmation')
80
+ throw new HealerNeedsConfirmationError(datos);
62
81
  if (!respuesta.ok) {
63
82
  throw new HealerApiError(respuesta.status, datos);
64
83
  }
65
84
  return datos;
66
85
  }
86
+ /** The organization rule for the AI level and the pro repairs left this month (no AI, no cost). Check it before sending a job
87
+ * to know whether it would need the user's yes for free. */
88
+ async getInfo() {
89
+ return this.pedir('GET', '/v1/info');
90
+ }
67
91
  /** Envía el código y devuelve de inmediato { job_id, app_id, status: "queued" } — sin esperar
68
92
  * a que termine. Usar junto a getRepair() para armar tu propio loop de consulta, o preferir
69
93
  * repair() si alcanza con esperar el resultado final. */
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { HealerClient, HealerApiError, HealerTimeoutError } from './client.js';
1
+ export { HealerClient, HealerApiError, HealerTimeoutError, HealerNeedsConfirmationError } from './client.js';
2
2
  export type { HealerClientOptions } from './client.js';
3
3
  export { verificarBase, aplicarReparacion, ErrorBaseModificada } from './aplicar.js';
4
4
  export type { VerificacionBase } from './aplicar.js';
5
- export type { SolicitudReparacion, ResultadoReparacion, EnvioAceptado, EstadoJob, ProgresoJob, EventoReparacion, ReporteAuditoriaSeguridad, HallazgoSeguridad, HallazgoPendiente, ReporteUsoReal, ProblemaUsoReal, ItemNoProbado, ReportePentagono, HallazgoPentagono, Cobertura, Stack, HealerReport, PendingKind, ScreenPage, ScreenReviewRequest, ScreenReviewResult } from './types.js';
5
+ export type { SolicitudReparacion, ResultadoReparacion, EnvioAceptado, EstadoJob, ProgresoJob, EventoReparacion, ReporteAuditoriaSeguridad, HallazgoSeguridad, HallazgoPendiente, ReporteUsoReal, ProblemaUsoReal, ItemNoProbado, ReportePentagono, HallazgoPentagono, Cobertura, Stack, HealerReport, PendingKind, ScreenPage, ScreenReviewRequest, ScreenReviewResult, HealerInfo } from './types.js';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { HealerClient, HealerApiError, HealerTimeoutError } from './client.js';
1
+ export { HealerClient, HealerApiError, HealerTimeoutError, HealerNeedsConfirmationError } from './client.js';
2
2
  export { verificarBase, aplicarReparacion, ErrorBaseModificada } from './aplicar.js';
package/dist/types.d.ts CHANGED
@@ -65,8 +65,10 @@ export interface ResultadoReparacion {
65
65
  pending_improvements: HallazgoPendiente[];
66
66
  uso_real_report?: ReporteUsoReal | null;
67
67
  pentagono_report: ReportePentagono | null;
68
- /** Con qué nivel de IA corrió el job. */
69
- ai_level?: 'free' | 'pro';
68
+ /** Con qué nivel de IA corrió el job ("none": revisar sin reparar, sin IA). */
69
+ ai_level?: 'free' | 'pro' | 'none';
70
+ /** Por qué ese nivel: pedido, la política de la organización, reparaciones sueltas, confirmado por la persona, free automático de la organización o solo revisar. */
71
+ ai_level_reason?: 'pedido' | 'organizacion' | 'cupo' | 'confirmado' | 'auto' | 'solo_revisar' | 'benchmark';
70
72
  /** SHA-256 de cada archivo tal como lo mandaste (solo con "files"). Ver verificarBase(). */
71
73
  base_hashes?: Record<string, string>;
72
74
  /** Archivos que Healer cambió de verdad. Todos los demás salen idénticos. */
@@ -173,16 +175,22 @@ export interface SolicitudReparacion {
173
175
  appIntent?: string;
174
176
  startCommand?: string;
175
177
  port?: number;
176
- /** Con qué IA se repara. "free": proveedores gratis (Groq, NVIDIA y Gemini), sin costo de IA.
177
- * "pro": las APIs pagas (Claude / Gemini Pro). Default: "pro".
178
- * En "free" el código puede reusarse para reentrenar los modelos de MEITI y de esos proveedores;
179
- * en "pro" nada se usa para entrenar. */
178
+ /** Con qué IA se repara. "free": proveedores gratis (Groq, NVIDIA y Gemini), que pueden guardar lo que reciben, y el código
179
+ * puede usarse para entrenar. "pro": las APIs pagas, nada se usa para entrenar. Sin mandarlo vale la política de la
180
+ * organización (pro, salvo que el dueño la cambie en el panel). Si tocaría free y la organización pide confirmar, submitRepair
181
+ * y repair tiran HealerNeedsConfirmationError y no se encola nada. */
180
182
  aiLevel?: 'free' | 'pro';
183
+ /** Solo después de que la persona dijo que sí al nivel free para ESTE trabajo. */
184
+ confirmFree?: boolean;
185
+ /** Revisar sin reparar y sin IA (compilación, tests y seguridad). */
186
+ reviewOnly?: boolean;
181
187
  }
182
188
  export interface EnvioAceptado {
183
189
  job_id: string;
184
190
  app_id: string;
185
191
  status: 'queued';
192
+ ai_level?: 'free' | 'pro' | 'none';
193
+ ai_level_reason?: string;
186
194
  }
187
195
  /** preexisting_lint: already in your code, in files Healer did not touch · did_not_run: the tests could not run · dependency: something is not installed · not_delivered: fixed but not delivered · not_fixed: Healer could not fix it. */
188
196
  export type PendingKind = 'preexisting_lint' | 'did_not_run' | 'dependency' | 'not_delivered' | 'not_fixed';
@@ -211,6 +219,19 @@ export interface HealerReport {
211
219
  unverified_suggestions: number;
212
220
  code_changed: boolean;
213
221
  }
222
+ /** GET /v1/info: the organization rule for the AI level and the pro repairs left this month. No AI, no cost. */
223
+ export interface HealerInfo {
224
+ server: 'healer';
225
+ remote_connector_version: string;
226
+ ai_level_default: 'pro' | 'free';
227
+ /** "ask": free never runs without the user's yes (HealerNeedsConfirmationError). */
228
+ when_free: 'ask' | 'auto';
229
+ repairs: {
230
+ used: number;
231
+ limit: number | null;
232
+ extra: number;
233
+ } | null;
234
+ }
214
235
  /** One page to check in a screen review (POST /v1/screen). */
215
236
  export interface ScreenPage {
216
237
  path: string;
@@ -233,10 +254,15 @@ export interface ScreenReviewRequest {
233
254
  files?: Record<string, string>;
234
255
  repositoryUrl?: string;
235
256
  commitSha?: string;
236
- /** The command that starts the app (it must listen on 0.0.0.0). */
237
- startCommand: string;
238
- port: number;
239
- pages: ScreenPage[];
257
+ /**
258
+ * The command that starts the app (it must listen on 0.0.0.0). Optional: without it Healer finds it (.healer.json "screen",
259
+ * the command that worked last time for this appId, or package.json / the Python entry file). See ScreenReviewResult.start.
260
+ */
261
+ startCommand?: string;
262
+ /** Optional, like startCommand. */
263
+ port?: number;
264
+ /** Optional: default [{ path: "/" }] (or the pages in .healer.json "screen"). */
265
+ pages?: ScreenPage[];
240
266
  appId?: string;
241
267
  }
242
268
  /** The result of a screen review: Healer started the app in its sandbox and checked each page. Nothing was repaired. */
@@ -244,13 +270,38 @@ export interface ScreenReviewResult {
244
270
  tipo: 'pantalla';
245
271
  status: 'checked' | 'did_not_start' | 'unsupported_stack';
246
272
  message: string;
273
+ /**
274
+ * How the app was started. source: declared (you sent it), repo_config (.healer.json), remembered (worked last time for
275
+ * this appId), detected (read from package.json or the Python files). verified: the app answered on that port. null when
276
+ * Healer could not find how to start it (message says what is needed).
277
+ */
278
+ /** The last lines the app's server printed, when it did not start or a page did not load. */
279
+ server_log?: string;
280
+ /** Services the pages called that were not running in the sandbox: the review is incomplete, not necessarily the app. */
281
+ missing_services?: {
282
+ address: string;
283
+ requests: number;
284
+ pages: string[];
285
+ found_in?: string;
286
+ hint: string;
287
+ }[];
288
+ start: {
289
+ command: string;
290
+ port: number;
291
+ source: 'declared' | 'repo_config' | 'remembered' | 'detected';
292
+ detail: string;
293
+ verified: boolean;
294
+ } | null;
247
295
  pages: {
248
296
  path: string;
249
297
  state: 'LOADED' | 'DID NOT LOAD' | 'STILL LOADING' | 'NOT THE EXPECTED PAGE';
250
298
  reasons: string[];
251
299
  http: number | null;
252
300
  title: string;
301
+ /** HTTP 4xx/5xx answers, and "NO RESPONSE ..." for requests that got no answer at all (backend down, wrong address, CORS). */
253
302
  failed_requests: string[];
303
+ /** Console errors and uncaught exceptions while the page loaded: usually why a page stays blank. */
304
+ page_errors: string[];
254
305
  visual_issues: {
255
306
  type: string;
256
307
  element: string | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meiti/healer-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Official SDK for Healer: send code, get it back repaired or unchanged, never worse. Thin layer over the REST API with polling, safe apply and partial delivery.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",