@meiti/healer-sdk 0.3.1 → 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/README.md +12 -0
- package/dist/aplicar.d.ts +7 -0
- package/dist/aplicar.js +16 -0
- package/dist/client.d.ts +14 -1
- package/dist/client.js +26 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/types.d.ts +62 -6
- package/package.json +1 -1
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:
|
package/dist/aplicar.d.ts
CHANGED
|
@@ -23,8 +23,15 @@ export declare function verificarBase(archivosActuales: Record<string, string>,
|
|
|
23
23
|
* Con { archivos: [...] } aplica solo esos (de changed_files) y deja los demás como estaban: para cuando
|
|
24
24
|
* la persona aprueba algunos arreglos y otros no. Un archivo que Healer no cambió tira un error.
|
|
25
25
|
*/
|
|
26
|
+
/** The result needs the user's acceptance of a lower quality score (see requires_acceptance). */
|
|
27
|
+
export declare class HealerNeedsAcceptanceError extends Error {
|
|
28
|
+
readonly requiresAcceptance: NonNullable<ResultadoReparacion['requires_acceptance']>;
|
|
29
|
+
readonly files: string[];
|
|
30
|
+
constructor(requiresAcceptance: NonNullable<ResultadoReparacion['requires_acceptance']>, files: string[]);
|
|
31
|
+
}
|
|
26
32
|
export declare function aplicarReparacion(archivosActuales: Record<string, string>, resultado: ResultadoReparacion, opciones?: {
|
|
27
33
|
forzar?: boolean;
|
|
28
34
|
incluirSoporte?: boolean;
|
|
29
35
|
archivos?: string[];
|
|
36
|
+
aceptarPuntajeMenor?: boolean;
|
|
30
37
|
}): Record<string, string>;
|
package/dist/aplicar.js
CHANGED
|
@@ -49,6 +49,17 @@ export function verificarBase(archivosActuales, resultado) {
|
|
|
49
49
|
* Con { archivos: [...] } aplica solo esos (de changed_files) y deja los demás como estaban: para cuando
|
|
50
50
|
* la persona aprueba algunos arreglos y otros no. Un archivo que Healer no cambió tira un error.
|
|
51
51
|
*/
|
|
52
|
+
/** The result needs the user's acceptance of a lower quality score (see requires_acceptance). */
|
|
53
|
+
export class HealerNeedsAcceptanceError extends Error {
|
|
54
|
+
requiresAcceptance;
|
|
55
|
+
files;
|
|
56
|
+
constructor(requiresAcceptance, files) {
|
|
57
|
+
super(`Needs the user's acceptance before applying: ${requiresAcceptance.reason} Quality score ${requiresAcceptance.pentagono_before} → ${requiresAcceptance.pentagono_after}. Pass { aceptarPuntajeMenor: true } if they accept, or leave out ${files.join(', ')}.`);
|
|
58
|
+
this.requiresAcceptance = requiresAcceptance;
|
|
59
|
+
this.files = files;
|
|
60
|
+
this.name = 'HealerNeedsAcceptanceError';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
52
63
|
export function aplicarReparacion(archivosActuales, resultado, opciones = {}) {
|
|
53
64
|
if (opciones.archivos?.length) {
|
|
54
65
|
const ajenos = opciones.archivos.filter((a) => !(resultado.changed_files ?? []).includes(a));
|
|
@@ -70,6 +81,11 @@ export function aplicarReparacion(archivosActuales, resultado, opciones = {}) {
|
|
|
70
81
|
const salida = { ...archivosActuales };
|
|
71
82
|
const soporte = opciones.incluirSoporte === false ? resultado.support_updates ?? [] : [];
|
|
72
83
|
const elegidos = opciones.archivos?.length ? opciones.archivos : resultado.changed_files ?? [];
|
|
84
|
+
// ⚖️ [2026-11-16] Una dependencia que baja el puntaje solo con el sí del usuario (misma regla que Healer).
|
|
85
|
+
const ra = resultado.requires_acceptance;
|
|
86
|
+
const tocados = ra && !opciones.aceptarPuntajeMenor ? ra.files.filter((r) => elegidos.includes(r) && !soporte.includes(r)) : [];
|
|
87
|
+
if (ra && tocados.length)
|
|
88
|
+
throw new HealerNeedsAcceptanceError(ra, tocados);
|
|
73
89
|
for (const ruta of elegidos.filter((r) => !soporte.includes(r))) {
|
|
74
90
|
const reparado = resultado.files[ruta];
|
|
75
91
|
if (reparado !== undefined)
|
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,10 @@ 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,
|
|
49
|
+
bug_report: request.bugReport
|
|
32
50
|
};
|
|
33
51
|
}
|
|
34
52
|
// 🎓 [SDK OFICIAL, 2026-09-16, pedido explícito: "vender el pipeline vía API... entre menos
|
|
@@ -59,11 +77,18 @@ export class HealerClient {
|
|
|
59
77
|
});
|
|
60
78
|
const texto = await respuesta.text();
|
|
61
79
|
const datos = texto ? JSON.parse(texto) : null;
|
|
80
|
+
if (respuesta.status === 409 && datos?.status === 'needs_confirmation')
|
|
81
|
+
throw new HealerNeedsConfirmationError(datos);
|
|
62
82
|
if (!respuesta.ok) {
|
|
63
83
|
throw new HealerApiError(respuesta.status, datos);
|
|
64
84
|
}
|
|
65
85
|
return datos;
|
|
66
86
|
}
|
|
87
|
+
/** The organization rule for the AI level and the pro repairs left this month (no AI, no cost). Check it before sending a job
|
|
88
|
+
* to know whether it would need the user's yes for free. */
|
|
89
|
+
async getInfo() {
|
|
90
|
+
return this.pedir('GET', '/v1/info');
|
|
91
|
+
}
|
|
67
92
|
/** Envía el código y devuelve de inmediato { job_id, app_id, status: "queued" } — sin esperar
|
|
68
93
|
* a que termine. Usar junto a getRepair() para armar tu propio loop de consulta, o preferir
|
|
69
94
|
* 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
|
-
export { verificarBase, aplicarReparacion, ErrorBaseModificada } from './aplicar.js';
|
|
3
|
+
export { verificarBase, aplicarReparacion, ErrorBaseModificada, HealerNeedsAcceptanceError } 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';
|
|
2
|
-
export { verificarBase, aplicarReparacion, ErrorBaseModificada } from './aplicar.js';
|
|
1
|
+
export { HealerClient, HealerApiError, HealerTimeoutError, HealerNeedsConfirmationError } from './client.js';
|
|
2
|
+
export { verificarBase, aplicarReparacion, ErrorBaseModificada, HealerNeedsAcceptanceError } 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. */
|
|
@@ -76,6 +78,27 @@ export interface ResultadoReparacion {
|
|
|
76
78
|
* la app corra en el runtime actual), no la reparación del bug. Son opcionales: ver aplicarReparacion().
|
|
77
79
|
*/
|
|
78
80
|
support_updates?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* The repair is verified, but Healer added a dependency so the tests could run and it lowers the quality score
|
|
83
|
+
* (known vulnerabilities or the Pentagon). Apply it only if the user accepts: aplicarReparacion needs
|
|
84
|
+
* { aceptarPuntajeMenor: true } when these files are included.
|
|
85
|
+
*/
|
|
86
|
+
requires_acceptance?: {
|
|
87
|
+
reason: string;
|
|
88
|
+
files: string[];
|
|
89
|
+
pentagono_before: number;
|
|
90
|
+
pentagono_after: number;
|
|
91
|
+
};
|
|
92
|
+
/** Only with bugReport: whether Healer reproduced the bug with a test before repairing, and whether it passes after. */
|
|
93
|
+
reproduction?: {
|
|
94
|
+
status: "reproduced" | "not_reproduced" | "could_not_write" | "unsupported";
|
|
95
|
+
test_file?: string;
|
|
96
|
+
test_content?: string;
|
|
97
|
+
attempts: number;
|
|
98
|
+
log?: string;
|
|
99
|
+
message: string;
|
|
100
|
+
passes_after?: boolean;
|
|
101
|
+
};
|
|
79
102
|
/**
|
|
80
103
|
* Failures found and fixed. Each failing check counts once; each auditor bug fixed and delivered counts
|
|
81
104
|
* one. Checks stop at the first failure, so "sin_correr" means others may not have run yet.
|
|
@@ -173,16 +196,28 @@ export interface SolicitudReparacion {
|
|
|
173
196
|
appIntent?: string;
|
|
174
197
|
startCommand?: string;
|
|
175
198
|
port?: number;
|
|
176
|
-
/** Con qué IA se repara. "free": proveedores gratis (Groq, NVIDIA y Gemini),
|
|
177
|
-
* "pro": las APIs pagas
|
|
178
|
-
*
|
|
179
|
-
*
|
|
199
|
+
/** Con qué IA se repara. "free": proveedores gratis (Groq, NVIDIA y Gemini), que pueden guardar lo que reciben, y el código
|
|
200
|
+
* puede usarse para entrenar. "pro": las APIs pagas, nada se usa para entrenar. Sin mandarlo vale la política de la
|
|
201
|
+
* organización (pro, salvo que el dueño la cambie en el panel). Si tocaría free y la organización pide confirmar, submitRepair
|
|
202
|
+
* y repair tiran HealerNeedsConfirmationError y no se encola nada. */
|
|
180
203
|
aiLevel?: 'free' | 'pro';
|
|
204
|
+
/** Solo después de que la persona dijo que sí al nivel free para ESTE trabajo. */
|
|
205
|
+
confirmFree?: boolean;
|
|
206
|
+
/** Revisar sin reparar y sin IA (compilación, tests y seguridad). */
|
|
207
|
+
reviewOnly?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* The bug as the user tells it (what they did, what they expected, what happened). Healer first writes a test that
|
|
210
|
+
* reproduces it and checks that it fails with the current code; only then repairs, and that test must pass after.
|
|
211
|
+
* If it does not reproduce, nothing is repaired blindly (see reproduction in the result). Needs files, not repositoryUrl.
|
|
212
|
+
*/
|
|
213
|
+
bugReport?: string;
|
|
181
214
|
}
|
|
182
215
|
export interface EnvioAceptado {
|
|
183
216
|
job_id: string;
|
|
184
217
|
app_id: string;
|
|
185
218
|
status: 'queued';
|
|
219
|
+
ai_level?: 'free' | 'pro' | 'none';
|
|
220
|
+
ai_level_reason?: string;
|
|
186
221
|
}
|
|
187
222
|
/** 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
223
|
export type PendingKind = 'preexisting_lint' | 'did_not_run' | 'dependency' | 'not_delivered' | 'not_fixed';
|
|
@@ -211,6 +246,19 @@ export interface HealerReport {
|
|
|
211
246
|
unverified_suggestions: number;
|
|
212
247
|
code_changed: boolean;
|
|
213
248
|
}
|
|
249
|
+
/** GET /v1/info: the organization rule for the AI level and the pro repairs left this month. No AI, no cost. */
|
|
250
|
+
export interface HealerInfo {
|
|
251
|
+
server: 'healer';
|
|
252
|
+
remote_connector_version: string;
|
|
253
|
+
ai_level_default: 'pro' | 'free';
|
|
254
|
+
/** "ask": free never runs without the user's yes (HealerNeedsConfirmationError). */
|
|
255
|
+
when_free: 'ask' | 'auto';
|
|
256
|
+
repairs: {
|
|
257
|
+
used: number;
|
|
258
|
+
limit: number | null;
|
|
259
|
+
extra: number;
|
|
260
|
+
} | null;
|
|
261
|
+
}
|
|
214
262
|
/** One page to check in a screen review (POST /v1/screen). */
|
|
215
263
|
export interface ScreenPage {
|
|
216
264
|
path: string;
|
|
@@ -256,6 +304,14 @@ export interface ScreenReviewResult {
|
|
|
256
304
|
*/
|
|
257
305
|
/** The last lines the app's server printed, when it did not start or a page did not load. */
|
|
258
306
|
server_log?: string;
|
|
307
|
+
/** Services the pages called that were not running in the sandbox: the review is incomplete, not necessarily the app. */
|
|
308
|
+
missing_services?: {
|
|
309
|
+
address: string;
|
|
310
|
+
requests: number;
|
|
311
|
+
pages: string[];
|
|
312
|
+
found_in?: string;
|
|
313
|
+
hint: string;
|
|
314
|
+
}[];
|
|
259
315
|
start: {
|
|
260
316
|
command: string;
|
|
261
317
|
port: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meiti/healer-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|