nexakit 0.13.0 → 0.13.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "nexakit",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "nexakit",
9
- "version": "0.13.0",
9
+ "version": "0.13.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@agentclientprotocol/sdk": "^2.7.0",
@@ -25,6 +25,10 @@
25
25
  // y, si es una orden, coincide exactamente con `ordenesPermitidas` y no está encadenada. El resto se rechaza y se
26
26
  // anota. Las reglas persistentes de la persona (`permissions.allow`) no se aplican gracias a `--gemini-dir`; las del
27
27
  // repo (`.gemini/`) se rechazan por la lista blanca de personalizaciones, que sigue vigente en este modo.
28
+ // Peticiones de edición reales (agy 1.5.16, capturadas con `NEXAKIT_DEPURAR_ACP`): `kind: edit` con `name: write_file`
29
+ // (`rawInput` = { Path, Content, Overwrite? }) y `name: edit_file` (`rawInput` = { Path, Target, Replacement }); la entrada
30
+ // se repite en `args`, `locations` y en un `content` de tipo diff. `Target` es texto (el fragmento que se reemplaza), no
31
+ // una ruta. El título lleva una ruta relativa larga con `..` que no se usa. Solo se admiten las claves observadas.
28
32
  // Órdenes en modo escritura: DESACTIVADAS por defecto en todas las plataformas (`ORDENES_ACTIVAS`, `comprobarOrdenes`).
29
33
  // Antigravity escribe solo dentro de la copia y no ejecuta órdenes; las pruebas las ejecuta el orquestador. Motivos,
30
34
  // comprobados con sesiones reales contra agy 1.5.14 y 1.5.16 en macOS (`gemini-3.8-flash-low`, unos 11 000 tokens cada
@@ -46,7 +50,7 @@
46
50
  // solo en macOS y con agy 1.5.14 o superior de la serie 1.5 se conserva, detrás de la opción inyectable `ordenesActivas`
47
51
  // (`true` fuerza órdenes aprobables; `'verificar'` aplica la plataforma y la versión), para pruebas y para reactivarla.
48
52
  import { execFile, spawn } from 'node:child_process';
49
- import { lstatSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, statSync } from 'node:fs';
53
+ import { closeSync, fchmodSync, lstatSync, mkdirSync, mkdtempSync, openSync, readdirSync, realpathSync, rmSync, statSync, writeSync } from 'node:fs';
50
54
  import { readFile } from 'node:fs/promises';
51
55
  import { tmpdir } from 'node:os';
52
56
  import path from 'node:path';
@@ -118,12 +122,17 @@ export function esComponenteProtegido(parte) {
118
122
  }
119
123
  /** Claves de `rawInput` que contienen una ruta (nombres normalizados: minúsculas y sin `_` ni `-`). */
120
124
  const CLAVES_RUTA = new Set(['path', 'filepath', 'absolutepath', 'targetfile', 'file', 'directory', 'directorypath', 'dir', 'searchpath', 'oldpath', 'newpath', 'from', 'to', 'source', 'destination', 'dest']);
121
- const CLAVES_TEXTO = ['content', 'contents', 'text', 'newtext', 'oldtext', 'newstring', 'oldstring', 'replacement', 'description', 'instruction'];
125
+ // Claves de texto observadas en agy 1.5.16: `write_file` manda `Path`, `Content` y `Overwrite`; `edit_file` manda `Path`,
126
+ // `Target` (el fragmento que se reemplaza, NO una ruta) y `Replacement`.
127
+ const CLAVES_TEXTO = new Set(['content', 'contents', 'text', 'newtext', 'oldtext', 'newstring', 'oldstring', 'replacement', 'target', 'description', 'instruction']);
128
+ const CLAVES_SOLO_EDIT_FILE = new Set(['target', 'replacement']);
129
+ /** Claves booleanas admitidas (`write_file` manda `Overwrite`). */
130
+ const CLAVES_BOOLEANAS = new Set(['overwrite']);
122
131
  const CLAVES_LECTURA = ['offset', 'limit', 'line', 'startline', 'endline'];
123
132
  const CLAVES_BUSQUEDA = ['query', 'pattern', 'glob', 'include', 'exclude', 'regex', 'casesensitive'];
124
133
  /** Lista cerrada de claves de `rawInput` admitidas por tipo de petición; cualquier otra rechaza la petición. */
125
134
  const CLAVES_ADMITIDAS = {
126
- edit: new Set([...CLAVES_RUTA, ...CLAVES_TEXTO]),
135
+ edit: new Set([...CLAVES_RUTA, ...CLAVES_TEXTO, ...CLAVES_BOOLEANAS]),
127
136
  delete: new Set(CLAVES_RUTA),
128
137
  move: new Set(CLAVES_RUTA),
129
138
  read: new Set([...CLAVES_RUTA, ...CLAVES_LECTURA]),
@@ -258,6 +267,9 @@ function analizarPeticion(tipo, llamada) {
258
267
  vistas.add(normal);
259
268
  if (!admitidas.has(normal))
260
269
  return rechazo(`campo no reconocido: ${recortar(clave)}`);
270
+ if (CLAVES_SOLO_EDIT_FILE.has(normal) && llamada['name'] !== undefined && llamada['name'] !== 'edit_file') {
271
+ return rechazo(`campo no reconocido: ${recortar(clave)}`);
272
+ }
261
273
  if (tipo === 'execute') {
262
274
  if (normal === 'bypasssandbox') {
263
275
  // Salir del sandbox nunca se aprueba: solo vale `false` explícito.
@@ -289,6 +301,14 @@ function analizarPeticion(tipo, llamada) {
289
301
  return rechazo(`el campo ${clave} no es un texto`);
290
302
  resultado.rutas.push(valor);
291
303
  }
304
+ else if (CLAVES_BOOLEANAS.has(normal)) {
305
+ if (typeof valor !== 'boolean')
306
+ return rechazo(`el campo ${clave} no es un booleano`);
307
+ }
308
+ else if (CLAVES_TEXTO.has(normal)) {
309
+ if (typeof valor !== 'string')
310
+ return rechazo(`el campo ${clave} no es un texto`);
311
+ }
292
312
  }
293
313
  return resultado;
294
314
  }
@@ -309,13 +329,14 @@ export function motivoPermisoRechazado(escritura, llamada, ordenesActivas = ORDE
309
329
  if (llamada['name'] !== undefined && llamada['name'] !== HERRAMIENTA_ORDENES) {
310
330
  return `la herramienta no es ${HERRAMIENTA_ORDENES}: ${recortar(String(llamada['name']))}`;
311
331
  }
312
- // agy repite la entrada de la orden en `args`: si dice otra cosa que `rawInput`, no se sabe cuál se ejecuta.
313
- if (llamada['args'] !== undefined) {
314
- if (!esObjeto(llamada['args']))
315
- return 'la orden trae args que no son un objeto';
316
- if (canonico(llamada['args']) !== canonico(llamada['rawInput']))
317
- return 'la orden trae args distintos de rawInput';
318
- }
332
+ }
333
+ // agy repite la entrada de la herramienta en `args` (órdenes, `write_file`, `edit_file`): si dice otra cosa que
334
+ // `rawInput`, no se sabe cuál se usa y la ruta validada podría no ser la que se escribe.
335
+ if ((TIPOS_ESCRITURA.has(tipo) || tipo === 'execute') && llamada['args'] !== undefined) {
336
+ if (!esObjeto(llamada['args']))
337
+ return 'la petición trae args que no son un objeto';
338
+ if (canonico(llamada['args']) !== canonico(llamada['rawInput']))
339
+ return 'la petición trae args distintos de rawInput';
319
340
  }
320
341
  const peticion = analizarPeticion(tipo, llamada);
321
342
  if (peticion.motivo !== null)
@@ -353,6 +374,87 @@ export function motivoPermisoRechazado(escritura, llamada, ordenesActivas = ORDE
353
374
  return 'la petición no declara ninguna ruta';
354
375
  return null;
355
376
  }
377
+ /** Variable de entorno de depuración: ruta absoluta de un archivo donde se anota el resumen de cada petición de permiso. */
378
+ export const VARIABLE_DEPURAR_ACP = 'NEXAKIT_DEPURAR_ACP';
379
+ const MAX_ELEMENTOS_DEPURACION = 20;
380
+ const MAX_PROFUNDIDAD_DEPURACION = 6;
381
+ function resumirValorSinTexto(valor, profundidad = 0) {
382
+ if (typeof valor === 'string')
383
+ return valor.length;
384
+ if (valor === null || typeof valor !== 'object')
385
+ return valor;
386
+ if (profundidad >= MAX_PROFUNDIDAD_DEPURACION)
387
+ return '…';
388
+ if (Array.isArray(valor))
389
+ return valor.slice(0, MAX_ELEMENTOS_DEPURACION).map((v) => resumirValorSinTexto(v, profundidad + 1));
390
+ return Object.fromEntries(Object.entries(valor).map(([k, v]) => [k, resumirValorSinTexto(v, profundidad + 1)]));
391
+ }
392
+ /**
393
+ * Resumen acotado de una petición de permiso para el registro de depuración: guarda solo `kind`, `name`, `rutas`
394
+ * y los nombres de las claves de `rawInput` con la longitud de cada texto, nunca el contenido de los textos.
395
+ */
396
+ export function resumirParaDepuracion(llamada) {
397
+ const rutas = [];
398
+ if (Array.isArray(llamada['locations'])) {
399
+ for (const l of llamada['locations']) {
400
+ if (esObjeto(l) && typeof l['path'] === 'string')
401
+ rutas.push(l['path']);
402
+ }
403
+ }
404
+ if (Array.isArray(llamada['content'])) {
405
+ for (const c of llamada['content']) {
406
+ if (esObjeto(c) && c['type'] === 'diff' && typeof c['path'] === 'string')
407
+ rutas.push(c['path']);
408
+ }
409
+ }
410
+ const crudo = llamada['rawInput'];
411
+ const claves = {};
412
+ if (esObjeto(crudo)) {
413
+ for (const [k, v] of Object.entries(crudo)) {
414
+ if (CLAVES_RUTA.has(normalizarClave(k)) && typeof v === 'string')
415
+ rutas.push(v);
416
+ claves[k] = resumirValorSinTexto(v);
417
+ }
418
+ }
419
+ return {
420
+ kind: texto(llamada['kind']),
421
+ name: texto(llamada['name']),
422
+ rutas: [...new Set(rutas)],
423
+ claves,
424
+ };
425
+ }
426
+ /**
427
+ * Con `NEXAKIT_DEPURAR_ACP=<ruta absoluta>` anota (una línea JSON por petición, archivo 0o600, nunca en enlace
428
+ * simbólico) solo `kind`, `name`, `rutas`, las claves de `rawInput` con la longitud de cada texto (nunca su contenido)
429
+ * y la decisión definitiva con su motivo. Nunca lanza.
430
+ */
431
+ function depurarPermiso(llamada, motivo) {
432
+ const destino = process.env[VARIABLE_DEPURAR_ACP];
433
+ if (destino === undefined || destino === '' || !path.isAbsolute(destino))
434
+ return;
435
+ try {
436
+ const info = lstatSync(destino, { throwIfNoEntry: false });
437
+ if (info?.isSymbolicLink())
438
+ return;
439
+ const linea = JSON.stringify({
440
+ momento: new Date().toISOString(),
441
+ decision: motivo === null ? 'aprobada' : 'rechazada',
442
+ motivo,
443
+ toolCall: resumirParaDepuracion(llamada),
444
+ });
445
+ const fd = openSync(destino, 'a', 0o600);
446
+ try {
447
+ fchmodSync(fd, 0o600);
448
+ writeSync(fd, `${linea}\n`);
449
+ }
450
+ finally {
451
+ closeSync(fd);
452
+ }
453
+ }
454
+ catch {
455
+ // La depuración nunca debe romper el encargo.
456
+ }
457
+ }
356
458
  class ErrorNoInstalado extends Error {
357
459
  constructor() {
358
460
  super(NO_INSTALADO);
@@ -956,11 +1058,13 @@ class ConectorAntigravity {
956
1058
  if (motivo === null) {
957
1059
  const permitir = opciones.find((o) => o['kind'] === 'allow_once' && typeof o['optionId'] === 'string');
958
1060
  if (permitir) {
1061
+ depurarPermiso(llamada, null);
959
1062
  enCurso?.resultado.aprobaciones?.push({ tipo: 'session/request_permission', detalle: recortar(`Permiso aprobado: ${detalle}`) });
960
1063
  return { outcome: { outcome: 'selected', optionId: permitir['optionId'] } };
961
1064
  }
962
1065
  motivo = 'no hay opción de permitir una vez';
963
1066
  }
1067
+ depurarPermiso(llamada, motivo);
964
1068
  }
965
1069
  enCurso?.resultado.denegaciones.push({
966
1070
  tipo: 'session/request_permission',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nexakit",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Asistente por pasos de skills verificadas por SHA-256, coordinación entre agentes y memoria por proyecto para Claude Code y Codex.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -25,6 +25,10 @@
25
25
  // y, si es una orden, coincide exactamente con `ordenesPermitidas` y no está encadenada. El resto se rechaza y se
26
26
  // anota. Las reglas persistentes de la persona (`permissions.allow`) no se aplican gracias a `--gemini-dir`; las del
27
27
  // repo (`.gemini/`) se rechazan por la lista blanca de personalizaciones, que sigue vigente en este modo.
28
+ // Peticiones de edición reales (agy 1.5.16, capturadas con `NEXAKIT_DEPURAR_ACP`): `kind: edit` con `name: write_file`
29
+ // (`rawInput` = { Path, Content, Overwrite? }) y `name: edit_file` (`rawInput` = { Path, Target, Replacement }); la entrada
30
+ // se repite en `args`, `locations` y en un `content` de tipo diff. `Target` es texto (el fragmento que se reemplaza), no
31
+ // una ruta. El título lleva una ruta relativa larga con `..` que no se usa. Solo se admiten las claves observadas.
28
32
  // Órdenes en modo escritura: DESACTIVADAS por defecto en todas las plataformas (`ORDENES_ACTIVAS`, `comprobarOrdenes`).
29
33
  // Antigravity escribe solo dentro de la copia y no ejecuta órdenes; las pruebas las ejecuta el orquestador. Motivos,
30
34
  // comprobados con sesiones reales contra agy 1.5.14 y 1.5.16 en macOS (`gemini-3.8-flash-low`, unos 11 000 tokens cada
@@ -47,7 +51,7 @@
47
51
  // (`true` fuerza órdenes aprobables; `'verificar'` aplica la plataforma y la versión), para pruebas y para reactivarla.
48
52
  import { execFile, spawn } from 'node:child_process';
49
53
  import type { ChildProcess } from 'node:child_process';
50
- import { lstatSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, statSync } from 'node:fs';
54
+ import { closeSync, fchmodSync, lstatSync, mkdirSync, mkdtempSync, openSync, readdirSync, realpathSync, rmSync, statSync, writeSync } from 'node:fs';
51
55
  import { readFile } from 'node:fs/promises';
52
56
  import { tmpdir } from 'node:os';
53
57
  import path from 'node:path';
@@ -163,12 +167,17 @@ export function esComponenteProtegido(parte: string): boolean {
163
167
 
164
168
  /** Claves de `rawInput` que contienen una ruta (nombres normalizados: minúsculas y sin `_` ni `-`). */
165
169
  const CLAVES_RUTA = new Set(['path', 'filepath', 'absolutepath', 'targetfile', 'file', 'directory', 'directorypath', 'dir', 'searchpath', 'oldpath', 'newpath', 'from', 'to', 'source', 'destination', 'dest']);
166
- const CLAVES_TEXTO = ['content', 'contents', 'text', 'newtext', 'oldtext', 'newstring', 'oldstring', 'replacement', 'description', 'instruction'];
170
+ // Claves de texto observadas en agy 1.5.16: `write_file` manda `Path`, `Content` y `Overwrite`; `edit_file` manda `Path`,
171
+ // `Target` (el fragmento que se reemplaza, NO una ruta) y `Replacement`.
172
+ const CLAVES_TEXTO = new Set(['content', 'contents', 'text', 'newtext', 'oldtext', 'newstring', 'oldstring', 'replacement', 'target', 'description', 'instruction']);
173
+ const CLAVES_SOLO_EDIT_FILE = new Set(['target', 'replacement']);
174
+ /** Claves booleanas admitidas (`write_file` manda `Overwrite`). */
175
+ const CLAVES_BOOLEANAS = new Set(['overwrite']);
167
176
  const CLAVES_LECTURA = ['offset', 'limit', 'line', 'startline', 'endline'];
168
177
  const CLAVES_BUSQUEDA = ['query', 'pattern', 'glob', 'include', 'exclude', 'regex', 'casesensitive'];
169
178
  /** Lista cerrada de claves de `rawInput` admitidas por tipo de petición; cualquier otra rechaza la petición. */
170
179
  const CLAVES_ADMITIDAS: Record<string, Set<string>> = {
171
- edit: new Set([...CLAVES_RUTA, ...CLAVES_TEXTO]),
180
+ edit: new Set([...CLAVES_RUTA, ...CLAVES_TEXTO, ...CLAVES_BOOLEANAS]),
172
181
  delete: new Set(CLAVES_RUTA),
173
182
  move: new Set(CLAVES_RUTA),
174
183
  read: new Set([...CLAVES_RUTA, ...CLAVES_LECTURA]),
@@ -298,6 +307,9 @@ function analizarPeticion(tipo: string, llamada: Record<string, unknown>): Petic
298
307
  if (vistas.has(normal)) return rechazo(`clave repetida con otra capitalización: ${recortar(clave)}`);
299
308
  vistas.add(normal);
300
309
  if (!admitidas.has(normal)) return rechazo(`campo no reconocido: ${recortar(clave)}`);
310
+ if (CLAVES_SOLO_EDIT_FILE.has(normal) && llamada['name'] !== undefined && llamada['name'] !== 'edit_file') {
311
+ return rechazo(`campo no reconocido: ${recortar(clave)}`);
312
+ }
301
313
  if (tipo === 'execute') {
302
314
  if (normal === 'bypasssandbox') {
303
315
  // Salir del sandbox nunca se aprueba: solo vale `false` explícito.
@@ -318,6 +330,10 @@ function analizarPeticion(tipo: string, llamada: Record<string, unknown>): Petic
318
330
  } else if (CLAVES_RUTA.has(normal)) {
319
331
  if (typeof valor !== 'string') return rechazo(`el campo ${clave} no es un texto`);
320
332
  resultado.rutas.push(valor);
333
+ } else if (CLAVES_BOOLEANAS.has(normal)) {
334
+ if (typeof valor !== 'boolean') return rechazo(`el campo ${clave} no es un booleano`);
335
+ } else if (CLAVES_TEXTO.has(normal)) {
336
+ if (typeof valor !== 'string') return rechazo(`el campo ${clave} no es un texto`);
321
337
  }
322
338
  }
323
339
  return resultado;
@@ -342,11 +358,12 @@ export function motivoPermisoRechazado(
342
358
  if (llamada['name'] !== undefined && llamada['name'] !== HERRAMIENTA_ORDENES) {
343
359
  return `la herramienta no es ${HERRAMIENTA_ORDENES}: ${recortar(String(llamada['name']))}`;
344
360
  }
345
- // agy repite la entrada de la orden en `args`: si dice otra cosa que `rawInput`, no se sabe cuál se ejecuta.
346
- if (llamada['args'] !== undefined) {
347
- if (!esObjeto(llamada['args'])) return 'la orden trae args que no son un objeto';
348
- if (canonico(llamada['args']) !== canonico(llamada['rawInput'])) return 'la orden trae args distintos de rawInput';
349
- }
361
+ }
362
+ // agy repite la entrada de la herramienta en `args` (órdenes, `write_file`, `edit_file`): si dice otra cosa que
363
+ // `rawInput`, no se sabe cuál se usa y la ruta validada podría no ser la que se escribe.
364
+ if ((TIPOS_ESCRITURA.has(tipo) || tipo === 'execute') && llamada['args'] !== undefined) {
365
+ if (!esObjeto(llamada['args'])) return 'la petición trae args que no son un objeto';
366
+ if (canonico(llamada['args']) !== canonico(llamada['rawInput'])) return 'la petición trae args distintos de rawInput';
350
367
  }
351
368
  const peticion = analizarPeticion(tipo, llamada);
352
369
  if (peticion.motivo !== null) return peticion.motivo;
@@ -376,6 +393,85 @@ export function motivoPermisoRechazado(
376
393
  return null;
377
394
  }
378
395
 
396
+ /** Variable de entorno de depuración: ruta absoluta de un archivo donde se anota el resumen de cada petición de permiso. */
397
+ export const VARIABLE_DEPURAR_ACP = 'NEXAKIT_DEPURAR_ACP';
398
+ const MAX_ELEMENTOS_DEPURACION = 20;
399
+ const MAX_PROFUNDIDAD_DEPURACION = 6;
400
+
401
+ function resumirValorSinTexto(valor: unknown, profundidad = 0): unknown {
402
+ if (typeof valor === 'string') return valor.length;
403
+ if (valor === null || typeof valor !== 'object') return valor;
404
+ if (profundidad >= MAX_PROFUNDIDAD_DEPURACION) return '…';
405
+ if (Array.isArray(valor)) return valor.slice(0, MAX_ELEMENTOS_DEPURACION).map((v) => resumirValorSinTexto(v, profundidad + 1));
406
+ return Object.fromEntries(Object.entries(valor).map(([k, v]) => [k, resumirValorSinTexto(v, profundidad + 1)]));
407
+ }
408
+
409
+ /**
410
+ * Resumen acotado de una petición de permiso para el registro de depuración: guarda solo `kind`, `name`, `rutas`
411
+ * y los nombres de las claves de `rawInput` con la longitud de cada texto, nunca el contenido de los textos.
412
+ */
413
+ export function resumirParaDepuracion(llamada: Record<string, unknown>): {
414
+ kind: string | null;
415
+ name: string | null;
416
+ rutas: string[];
417
+ claves: Record<string, unknown>;
418
+ } {
419
+ const rutas: string[] = [];
420
+ if (Array.isArray(llamada['locations'])) {
421
+ for (const l of llamada['locations']) {
422
+ if (esObjeto(l) && typeof l['path'] === 'string') rutas.push(l['path']);
423
+ }
424
+ }
425
+ if (Array.isArray(llamada['content'])) {
426
+ for (const c of llamada['content']) {
427
+ if (esObjeto(c) && c['type'] === 'diff' && typeof c['path'] === 'string') rutas.push(c['path']);
428
+ }
429
+ }
430
+ const crudo = llamada['rawInput'];
431
+ const claves: Record<string, unknown> = {};
432
+ if (esObjeto(crudo)) {
433
+ for (const [k, v] of Object.entries(crudo)) {
434
+ if (CLAVES_RUTA.has(normalizarClave(k)) && typeof v === 'string') rutas.push(v);
435
+ claves[k] = resumirValorSinTexto(v);
436
+ }
437
+ }
438
+ return {
439
+ kind: texto(llamada['kind']),
440
+ name: texto(llamada['name']),
441
+ rutas: [...new Set(rutas)],
442
+ claves,
443
+ };
444
+ }
445
+
446
+ /**
447
+ * Con `NEXAKIT_DEPURAR_ACP=<ruta absoluta>` anota (una línea JSON por petición, archivo 0o600, nunca en enlace
448
+ * simbólico) solo `kind`, `name`, `rutas`, las claves de `rawInput` con la longitud de cada texto (nunca su contenido)
449
+ * y la decisión definitiva con su motivo. Nunca lanza.
450
+ */
451
+ function depurarPermiso(llamada: Record<string, unknown>, motivo: string | null): void {
452
+ const destino = process.env[VARIABLE_DEPURAR_ACP];
453
+ if (destino === undefined || destino === '' || !path.isAbsolute(destino)) return;
454
+ try {
455
+ const info = lstatSync(destino, { throwIfNoEntry: false });
456
+ if (info?.isSymbolicLink()) return;
457
+ const linea = JSON.stringify({
458
+ momento: new Date().toISOString(),
459
+ decision: motivo === null ? 'aprobada' : 'rechazada',
460
+ motivo,
461
+ toolCall: resumirParaDepuracion(llamada),
462
+ });
463
+ const fd = openSync(destino, 'a', 0o600);
464
+ try {
465
+ fchmodSync(fd, 0o600);
466
+ writeSync(fd, `${linea}\n`);
467
+ } finally {
468
+ closeSync(fd);
469
+ }
470
+ } catch {
471
+ // La depuración nunca debe romper el encargo.
472
+ }
473
+ }
474
+
379
475
  class ErrorNoInstalado extends Error {
380
476
  constructor() {
381
477
  super(NO_INSTALADO);
@@ -1002,11 +1098,13 @@ class ConectorAntigravity implements Conector {
1002
1098
  if (motivo === null) {
1003
1099
  const permitir = opciones.find((o) => o['kind'] === 'allow_once' && typeof o['optionId'] === 'string');
1004
1100
  if (permitir) {
1101
+ depurarPermiso(llamada, null);
1005
1102
  enCurso?.resultado.aprobaciones?.push({ tipo: 'session/request_permission', detalle: recortar(`Permiso aprobado: ${detalle}`) });
1006
1103
  return { outcome: { outcome: 'selected', optionId: permitir['optionId'] as string } };
1007
1104
  }
1008
1105
  motivo = 'no hay opción de permitir una vez';
1009
1106
  }
1107
+ depurarPermiso(llamada, motivo);
1010
1108
  }
1011
1109
  enCurso?.resultado.denegaciones.push({
1012
1110
  tipo: 'session/request_permission',