@hoilab/ada-cli 0.84.21 → 0.85.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/CHANGELOG.md +49 -2
- package/README.es.md +174 -0
- package/README.md +203 -658
- package/dist/ada-publico.d.ts +35 -0
- package/dist/ada-publico.d.ts.map +1 -0
- package/dist/ada-publico.js +40 -0
- package/dist/ada-publico.js.map +1 -0
- package/dist/cli/args.d.ts +3 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +11 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/audit-command.d.ts +15 -0
- package/dist/cli/audit-command.d.ts.map +1 -0
- package/dist/cli/audit-command.js +280 -0
- package/dist/cli/audit-command.js.map +1 -0
- package/dist/cli/banco-command.d.ts +15 -0
- package/dist/cli/banco-command.d.ts.map +1 -0
- package/dist/cli/banco-command.js +213 -0
- package/dist/cli/banco-command.js.map +1 -0
- package/dist/cli/cleanse-command.d.ts +11 -0
- package/dist/cli/cleanse-command.d.ts.map +1 -0
- package/dist/cli/cleanse-command.js +101 -0
- package/dist/cli/cleanse-command.js.map +1 -0
- package/dist/cli/commit-command.d.ts +31 -0
- package/dist/cli/commit-command.d.ts.map +1 -0
- package/dist/cli/commit-command.js +158 -0
- package/dist/cli/commit-command.js.map +1 -0
- package/dist/cli/computer-command.d.ts +12 -0
- package/dist/cli/computer-command.d.ts.map +1 -0
- package/dist/cli/computer-command.js +141 -0
- package/dist/cli/computer-command.js.map +1 -0
- package/dist/cli/discover-command.d.ts +18 -0
- package/dist/cli/discover-command.d.ts.map +1 -0
- package/dist/cli/discover-command.js +108 -0
- package/dist/cli/discover-command.js.map +1 -0
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +2 -1
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/hashline-command.d.ts +11 -0
- package/dist/cli/hashline-command.d.ts.map +1 -0
- package/dist/cli/hashline-command.js +106 -0
- package/dist/cli/hashline-command.js.map +1 -0
- package/dist/cli/home-screen.d.ts.map +1 -1
- package/dist/cli/home-screen.js +2 -2
- package/dist/cli/home-screen.js.map +1 -1
- package/dist/cli/import-command.d.ts +35 -0
- package/dist/cli/import-command.d.ts.map +1 -0
- package/dist/cli/import-command.js +164 -0
- package/dist/cli/import-command.js.map +1 -0
- package/dist/cli/politica-command.d.ts +20 -0
- package/dist/cli/politica-command.d.ts.map +1 -0
- package/dist/cli/politica-command.js +93 -0
- package/dist/cli/politica-command.js.map +1 -0
- package/dist/cli/refine-command.d.ts +18 -0
- package/dist/cli/refine-command.d.ts.map +1 -0
- package/dist/cli/refine-command.js +101 -0
- package/dist/cli/refine-command.js.map +1 -0
- package/dist/cli/review-command.d.ts +24 -0
- package/dist/cli/review-command.d.ts.map +1 -0
- package/dist/cli/review-command.js +168 -0
- package/dist/cli/review-command.js.map +1 -0
- package/dist/cli/schedule-command.d.ts +17 -0
- package/dist/cli/schedule-command.d.ts.map +1 -0
- package/dist/cli/schedule-command.js +117 -0
- package/dist/cli/schedule-command.js.map +1 -0
- package/dist/cli/serve-command.d.ts +72 -0
- package/dist/cli/serve-command.d.ts.map +1 -0
- package/dist/cli/serve-command.js +568 -0
- package/dist/cli/serve-command.js.map +1 -0
- package/dist/cli/startup-ui.d.ts.map +1 -1
- package/dist/cli/startup-ui.js +9 -3
- package/dist/cli/startup-ui.js.map +1 -1
- package/dist/cli/telegram-command.d.ts +18 -0
- package/dist/cli/telegram-command.d.ts.map +1 -0
- package/dist/cli/telegram-command.js +137 -0
- package/dist/cli/telegram-command.js.map +1 -0
- package/dist/cli/telemetria-command.d.ts +22 -0
- package/dist/cli/telemetria-command.d.ts.map +1 -0
- package/dist/cli/telemetria-command.js +127 -0
- package/dist/cli/telemetria-command.js.map +1 -0
- package/dist/cli/undo-command.d.ts +9 -0
- package/dist/cli/undo-command.d.ts.map +1 -0
- package/dist/cli/undo-command.js +56 -0
- package/dist/cli/undo-command.js.map +1 -0
- package/dist/cli/usage-command.d.ts +10 -0
- package/dist/cli/usage-command.d.ts.map +1 -0
- package/dist/cli/usage-command.js +209 -0
- package/dist/cli/usage-command.js.map +1 -0
- package/dist/cli/wiki-command.d.ts +9 -0
- package/dist/cli/wiki-command.d.ts.map +1 -0
- package/dist/cli/wiki-command.js +76 -0
- package/dist/cli/wiki-command.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +10 -11
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +3 -2
- package/dist/config.js.map +1 -1
- package/dist/core/ada.d.ts +58 -0
- package/dist/core/ada.d.ts.map +1 -0
- package/dist/core/ada.js +61 -0
- package/dist/core/ada.js.map +1 -0
- package/dist/core/advisor/guarda.d.ts +66 -0
- package/dist/core/advisor/guarda.d.ts.map +1 -0
- package/dist/core/advisor/guarda.js +191 -0
- package/dist/core/advisor/guarda.js.map +1 -0
- package/dist/core/advisor/runtime.d.ts +66 -0
- package/dist/core/advisor/runtime.d.ts.map +1 -0
- package/dist/core/advisor/runtime.js +121 -0
- package/dist/core/advisor/runtime.js.map +1 -0
- package/dist/core/advisor/sesion.d.ts +109 -0
- package/dist/core/advisor/sesion.d.ts.map +1 -0
- package/dist/core/advisor/sesion.js +139 -0
- package/dist/core/advisor/sesion.js.map +1 -0
- package/dist/core/agent-session.d.ts +85 -7
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +862 -78
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/agents/loader.d.ts +77 -0
- package/dist/core/agents/loader.d.ts.map +1 -0
- package/dist/core/agents/loader.js +154 -0
- package/dist/core/agents/loader.js.map +1 -0
- package/dist/core/aprobacion/generados.d.ts +37 -0
- package/dist/core/aprobacion/generados.d.ts.map +1 -0
- package/dist/core/aprobacion/generados.js +85 -0
- package/dist/core/aprobacion/generados.js.map +1 -0
- package/dist/core/aprobacion/politica-de-maquina.d.ts +90 -0
- package/dist/core/aprobacion/politica-de-maquina.d.ts.map +1 -0
- package/dist/core/aprobacion/politica-de-maquina.js +212 -0
- package/dist/core/aprobacion/politica-de-maquina.js.map +1 -0
- package/dist/core/aprobacion/politica.d.ts +90 -0
- package/dist/core/aprobacion/politica.d.ts.map +1 -0
- package/dist/core/aprobacion/politica.js +375 -0
- package/dist/core/aprobacion/politica.js.map +1 -0
- package/dist/core/arranque/atajos.d.ts +46 -0
- package/dist/core/arranque/atajos.d.ts.map +1 -0
- package/dist/core/arranque/atajos.js +113 -0
- package/dist/core/arranque/atajos.js.map +1 -0
- package/dist/core/audit/exportacion.d.ts +54 -0
- package/dist/core/audit/exportacion.d.ts.map +1 -0
- package/dist/core/audit/exportacion.js +265 -0
- package/dist/core/audit/exportacion.js.map +1 -0
- package/dist/core/audit/libro.d.ts +318 -0
- package/dist/core/audit/libro.d.ts.map +1 -0
- package/dist/core/audit/libro.js +508 -0
- package/dist/core/audit/libro.js.map +1 -0
- package/dist/core/audit/registro-sesion.d.ts +78 -0
- package/dist/core/audit/registro-sesion.d.ts.map +1 -0
- package/dist/core/audit/registro-sesion.js +202 -0
- package/dist/core/audit/registro-sesion.js.map +1 -0
- package/dist/core/audit/retencion.d.ts +82 -0
- package/dist/core/audit/retencion.d.ts.map +1 -0
- package/dist/core/audit/retencion.js +152 -0
- package/dist/core/audit/retencion.js.map +1 -0
- package/dist/core/audit/rutas.d.ts +23 -0
- package/dist/core/audit/rutas.d.ts.map +1 -0
- package/dist/core/audit/rutas.js +23 -0
- package/dist/core/audit/rutas.js.map +1 -0
- package/dist/core/auth-storage.d.ts +0 -3
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +21 -8
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/banco/almacenamiento.d.ts +18 -0
- package/dist/core/banco/almacenamiento.d.ts.map +1 -0
- package/dist/core/banco/almacenamiento.js +50 -0
- package/dist/core/banco/almacenamiento.js.map +1 -0
- package/dist/core/banco/analisis.d.ts +37 -0
- package/dist/core/banco/analisis.d.ts.map +1 -0
- package/dist/core/banco/analisis.js +164 -0
- package/dist/core/banco/analisis.js.map +1 -0
- package/dist/core/banco/bloques.d.ts +39 -0
- package/dist/core/banco/bloques.d.ts.map +1 -0
- package/dist/core/banco/bloques.js +84 -0
- package/dist/core/banco/bloques.js.map +1 -0
- package/dist/core/banco/cargas.d.ts +84 -0
- package/dist/core/banco/cargas.d.ts.map +1 -0
- package/dist/core/banco/cargas.js +520 -0
- package/dist/core/banco/cargas.js.map +1 -0
- package/dist/core/banco/comparar.d.ts +29 -0
- package/dist/core/banco/comparar.d.ts.map +1 -0
- package/dist/core/banco/comparar.js +28 -0
- package/dist/core/banco/comparar.js.map +1 -0
- package/dist/core/banco/ejecutar.d.ts +44 -0
- package/dist/core/banco/ejecutar.d.ts.map +1 -0
- package/dist/core/banco/ejecutar.js +183 -0
- package/dist/core/banco/ejecutar.js.map +1 -0
- package/dist/core/banco/generar.d.ts +24 -0
- package/dist/core/banco/generar.d.ts.map +1 -0
- package/dist/core/banco/generar.js +159 -0
- package/dist/core/banco/generar.js.map +1 -0
- package/dist/core/banco/mutaciones.d.ts +25 -0
- package/dist/core/banco/mutaciones.d.ts.map +1 -0
- package/dist/core/banco/mutaciones.js +215 -0
- package/dist/core/banco/mutaciones.js.map +1 -0
- package/dist/core/banco/tipos.d.ts +121 -0
- package/dist/core/banco/tipos.d.ts.map +1 -0
- package/dist/core/banco/tipos.js +16 -0
- package/dist/core/banco/tipos.js.map +1 -0
- package/dist/core/blobs/almacen.d.ts +81 -0
- package/dist/core/blobs/almacen.d.ts.map +1 -0
- package/dist/core/blobs/almacen.js +198 -0
- package/dist/core/blobs/almacen.js.map +1 -0
- package/dist/core/blobs/broker.d.ts +103 -0
- package/dist/core/blobs/broker.d.ts.map +1 -0
- package/dist/core/blobs/broker.js +204 -0
- package/dist/core/blobs/broker.js.map +1 -0
- package/dist/core/blobs/index.d.ts +70 -0
- package/dist/core/blobs/index.d.ts.map +1 -0
- package/dist/core/blobs/index.js +232 -0
- package/dist/core/blobs/index.js.map +1 -0
- package/dist/core/blobs/payload.d.ts +55 -0
- package/dist/core/blobs/payload.d.ts.map +1 -0
- package/dist/core/blobs/payload.js +255 -0
- package/dist/core/blobs/payload.js.map +1 -0
- package/dist/core/blobs/proveedor.d.ts +85 -0
- package/dist/core/blobs/proveedor.d.ts.map +1 -0
- package/dist/core/blobs/proveedor.js +196 -0
- package/dist/core/blobs/proveedor.js.map +1 -0
- package/dist/core/browser/cdp.d.ts +41 -0
- package/dist/core/browser/cdp.d.ts.map +1 -0
- package/dist/core/browser/cdp.js +119 -0
- package/dist/core/browser/cdp.js.map +1 -0
- package/dist/core/browser/politica.d.ts +51 -0
- package/dist/core/browser/politica.d.ts.map +1 -0
- package/dist/core/browser/politica.js +123 -0
- package/dist/core/browser/politica.js.map +1 -0
- package/dist/core/browser/sesion.d.ts +52 -0
- package/dist/core/browser/sesion.d.ts.map +1 -0
- package/dist/core/browser/sesion.js +176 -0
- package/dist/core/browser/sesion.js.map +1 -0
- package/dist/core/browser/tools.d.ts +16 -0
- package/dist/core/browser/tools.d.ts.map +1 -0
- package/dist/core/browser/tools.js +279 -0
- package/dist/core/browser/tools.js.map +1 -0
- package/dist/core/commit/diff.d.ts +56 -0
- package/dist/core/commit/diff.d.ts.map +1 -0
- package/dist/core/commit/diff.js +145 -0
- package/dist/core/commit/diff.js.map +1 -0
- package/dist/core/commit/mensaje.d.ts +80 -0
- package/dist/core/commit/mensaje.d.ts.map +1 -0
- package/dist/core/commit/mensaje.js +207 -0
- package/dist/core/commit/mensaje.js.map +1 -0
- package/dist/core/compactar/index.d.ts +52 -0
- package/dist/core/compactar/index.d.ts.map +1 -0
- package/dist/core/compactar/index.js +91 -0
- package/dist/core/compactar/index.js.map +1 -0
- package/dist/core/compactar/registro-denso.d.ts +160 -0
- package/dist/core/compactar/registro-denso.d.ts.map +1 -0
- package/dist/core/compactar/registro-denso.js +620 -0
- package/dist/core/compactar/registro-denso.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +3 -0
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts +4 -3
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +41 -32
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/computer/captura.d.ts +35 -0
- package/dist/core/computer/captura.d.ts.map +1 -0
- package/dist/core/computer/captura.js +140 -0
- package/dist/core/computer/captura.js.map +1 -0
- package/dist/core/computer/driver.d.ts +130 -0
- package/dist/core/computer/driver.d.ts.map +1 -0
- package/dist/core/computer/driver.js +206 -0
- package/dist/core/computer/driver.js.map +1 -0
- package/dist/core/computer/motor/actions.d.ts +109 -0
- package/dist/core/computer/motor/actions.d.ts.map +1 -0
- package/dist/core/computer/motor/actions.js +157 -0
- package/dist/core/computer/motor/actions.js.map +1 -0
- package/dist/core/computer/motor/bridge.d.ts +232 -0
- package/dist/core/computer/motor/bridge.d.ts.map +1 -0
- package/dist/core/computer/motor/bridge.js +2335 -0
- package/dist/core/computer/motor/bridge.js.map +1 -0
- package/dist/core/computer/motor/cdp.d.ts +107 -0
- package/dist/core/computer/motor/cdp.d.ts.map +1 -0
- package/dist/core/computer/motor/cdp.js +659 -0
- package/dist/core/computer/motor/cdp.js.map +1 -0
- package/dist/core/computer/motor/config.d.ts +23 -0
- package/dist/core/computer/motor/config.d.ts.map +1 -0
- package/dist/core/computer/motor/config.js +100 -0
- package/dist/core/computer/motor/config.js.map +1 -0
- package/dist/core/computer/motor/contract.d.ts +81 -0
- package/dist/core/computer/motor/contract.d.ts.map +1 -0
- package/dist/core/computer/motor/contract.js +14 -0
- package/dist/core/computer/motor/contract.js.map +1 -0
- package/dist/core/computer/motor/note.d.ts +37 -0
- package/dist/core/computer/motor/note.d.ts.map +1 -0
- package/dist/core/computer/motor/note.js +162 -0
- package/dist/core/computer/motor/note.js.map +1 -0
- package/dist/core/computer/motor/outline.d.ts +155 -0
- package/dist/core/computer/motor/outline.d.ts.map +1 -0
- package/dist/core/computer/motor/outline.js +590 -0
- package/dist/core/computer/motor/outline.js.map +1 -0
- package/dist/core/computer/motor/output.d.ts +18 -0
- package/dist/core/computer/motor/output.d.ts.map +1 -0
- package/dist/core/computer/motor/output.js +148 -0
- package/dist/core/computer/motor/output.js.map +1 -0
- package/dist/core/computer/motor/permissions.d.ts +41 -0
- package/dist/core/computer/motor/permissions.d.ts.map +1 -0
- package/dist/core/computer/motor/permissions.js +51 -0
- package/dist/core/computer/motor/permissions.js.map +1 -0
- package/dist/core/computer/motor/platform/architecture.d.ts +5 -0
- package/dist/core/computer/motor/platform/architecture.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/architecture.js +21 -0
- package/dist/core/computer/motor/platform/architecture.js.map +1 -0
- package/dist/core/computer/motor/platform/coerce.d.ts +4 -0
- package/dist/core/computer/motor/platform/coerce.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/coerce.js +17 -0
- package/dist/core/computer/motor/platform/coerce.js.map +1 -0
- package/dist/core/computer/motor/platform/index.d.ts +4 -0
- package/dist/core/computer/motor/platform/index.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/index.js +79 -0
- package/dist/core/computer/motor/platform/index.js.map +1 -0
- package/dist/core/computer/motor/platform/linux/backend.d.ts +3 -0
- package/dist/core/computer/motor/platform/linux/backend.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/linux/backend.js +173 -0
- package/dist/core/computer/motor/platform/linux/backend.js.map +1 -0
- package/dist/core/computer/motor/platform/linux/helper.d.ts +29 -0
- package/dist/core/computer/motor/platform/linux/helper.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/linux/helper.js +261 -0
- package/dist/core/computer/motor/platform/linux/helper.js.map +1 -0
- package/dist/core/computer/motor/platform/macos/backend.d.ts +3 -0
- package/dist/core/computer/motor/platform/macos/backend.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/macos/backend.js +124 -0
- package/dist/core/computer/motor/platform/macos/backend.js.map +1 -0
- package/dist/core/computer/motor/platform/macos/browser.d.ts +7 -0
- package/dist/core/computer/motor/platform/macos/browser.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/macos/browser.js +101 -0
- package/dist/core/computer/motor/platform/macos/browser.js.map +1 -0
- package/dist/core/computer/motor/platform/macos/helper-path.mjs +34 -0
- package/dist/core/computer/motor/platform/macos/helper.d.ts +32 -0
- package/dist/core/computer/motor/platform/macos/helper.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/macos/helper.js +277 -0
- package/dist/core/computer/motor/platform/macos/helper.js.map +1 -0
- package/dist/core/computer/motor/platform/macos/permissions.d.ts +4 -0
- package/dist/core/computer/motor/platform/macos/permissions.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/macos/permissions.js +118 -0
- package/dist/core/computer/motor/platform/macos/permissions.js.map +1 -0
- package/dist/core/computer/motor/platform/types.d.ts +263 -0
- package/dist/core/computer/motor/platform/types.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/types.js +2 -0
- package/dist/core/computer/motor/platform/types.js.map +1 -0
- package/dist/core/computer/motor/platform/windows/backend.d.ts +3 -0
- package/dist/core/computer/motor/platform/windows/backend.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/windows/backend.js +163 -0
- package/dist/core/computer/motor/platform/windows/backend.js.map +1 -0
- package/dist/core/computer/motor/platform/windows/helper.d.ts +18 -0
- package/dist/core/computer/motor/platform/windows/helper.d.ts.map +1 -0
- package/dist/core/computer/motor/platform/windows/helper.js +174 -0
- package/dist/core/computer/motor/platform/windows/helper.js.map +1 -0
- package/dist/core/computer/motor/root-selection.d.ts +6 -0
- package/dist/core/computer/motor/root-selection.d.ts.map +1 -0
- package/dist/core/computer/motor/root-selection.js +28 -0
- package/dist/core/computer/motor/root-selection.js.map +1 -0
- package/dist/core/computer/motor/runtime.d.ts +50 -0
- package/dist/core/computer/motor/runtime.d.ts.map +1 -0
- package/dist/core/computer/motor/runtime.js +119 -0
- package/dist/core/computer/motor/runtime.js.map +1 -0
- package/dist/core/computer/motor/state.d.ts +68 -0
- package/dist/core/computer/motor/state.d.ts.map +1 -0
- package/dist/core/computer/motor/state.js +100 -0
- package/dist/core/computer/motor/state.js.map +1 -0
- package/dist/core/computer/motor/view.d.ts +6 -0
- package/dist/core/computer/motor/view.d.ts.map +1 -0
- package/dist/core/computer/motor/view.js +185 -0
- package/dist/core/computer/motor/view.js.map +1 -0
- package/dist/core/computer/motor-ada.d.ts +159 -0
- package/dist/core/computer/motor-ada.d.ts.map +1 -0
- package/dist/core/computer/motor-ada.js +412 -0
- package/dist/core/computer/motor-ada.js.map +1 -0
- package/dist/core/computer/politica.d.ts +56 -0
- package/dist/core/computer/politica.d.ts.map +1 -0
- package/dist/core/computer/politica.js +163 -0
- package/dist/core/computer/politica.js.map +1 -0
- package/dist/core/computer/tools.d.ts +26 -0
- package/dist/core/computer/tools.d.ts.map +1 -0
- package/dist/core/computer/tools.js +399 -0
- package/dist/core/computer/tools.js.map +1 -0
- package/dist/core/context-breakdown.d.ts +80 -0
- package/dist/core/context-breakdown.d.ts.map +1 -0
- package/dist/core/context-breakdown.js +87 -0
- package/dist/core/context-breakdown.js.map +1 -0
- package/dist/core/credenciales/cliente.d.ts +60 -0
- package/dist/core/credenciales/cliente.d.ts.map +1 -0
- package/dist/core/credenciales/cliente.js +81 -0
- package/dist/core/credenciales/cliente.js.map +1 -0
- package/dist/core/credenciales/pool.d.ts +96 -0
- package/dist/core/credenciales/pool.d.ts.map +1 -0
- package/dist/core/credenciales/pool.js +128 -0
- package/dist/core/credenciales/pool.js.map +1 -0
- package/dist/core/credenciales/reposo.d.ts +93 -0
- package/dist/core/credenciales/reposo.d.ts.map +1 -0
- package/dist/core/credenciales/reposo.js +489 -0
- package/dist/core/credenciales/reposo.js.map +1 -0
- package/dist/core/credenciales/servidor.d.ts +55 -0
- package/dist/core/credenciales/servidor.d.ts.map +1 -0
- package/dist/core/credenciales/servidor.js +205 -0
- package/dist/core/credenciales/servidor.js.map +1 -0
- package/dist/core/defaults.d.ts +1 -0
- package/dist/core/defaults.d.ts.map +1 -1
- package/dist/core/defaults.js +9 -0
- package/dist/core/defaults.js.map +1 -1
- package/dist/core/descubrimiento/comandos.d.ts +30 -0
- package/dist/core/descubrimiento/comandos.d.ts.map +1 -0
- package/dist/core/descubrimiento/comandos.js +76 -0
- package/dist/core/descubrimiento/comandos.js.map +1 -0
- package/dist/core/descubrimiento/mcp.d.ts +42 -0
- package/dist/core/descubrimiento/mcp.d.ts.map +1 -0
- package/dist/core/descubrimiento/mcp.js +130 -0
- package/dist/core/descubrimiento/mcp.js.map +1 -0
- package/dist/core/descubrimiento/reglas.d.ts +61 -0
- package/dist/core/descubrimiento/reglas.d.ts.map +1 -0
- package/dist/core/descubrimiento/reglas.js +134 -0
- package/dist/core/descubrimiento/reglas.js.map +1 -0
- package/dist/core/descubrimiento/skills.d.ts +57 -0
- package/dist/core/descubrimiento/skills.d.ts.map +1 -0
- package/dist/core/descubrimiento/skills.js +113 -0
- package/dist/core/descubrimiento/skills.js.map +1 -0
- package/dist/core/dificultad/clasificador.d.ts +133 -0
- package/dist/core/dificultad/clasificador.d.ts.map +1 -0
- package/dist/core/dificultad/clasificador.js +288 -0
- package/dist/core/dificultad/clasificador.js.map +1 -0
- package/dist/core/edicion/diario.d.ts +37 -0
- package/dist/core/edicion/diario.d.ts.map +1 -0
- package/dist/core/edicion/diario.js +51 -0
- package/dist/core/edicion/diario.js.map +1 -0
- package/dist/core/edicion/hashline.d.ts +71 -0
- package/dist/core/edicion/hashline.d.ts.map +1 -0
- package/dist/core/edicion/hashline.js +111 -0
- package/dist/core/edicion/hashline.js.map +1 -0
- package/dist/core/edicion/hueco.d.ts +64 -0
- package/dist/core/edicion/hueco.d.ts.map +1 -0
- package/dist/core/edicion/hueco.js +162 -0
- package/dist/core/edicion/hueco.js.map +1 -0
- package/dist/core/edicion/limpiar-carga.d.ts +39 -0
- package/dist/core/edicion/limpiar-carga.d.ts.map +1 -0
- package/dist/core/edicion/limpiar-carga.js +121 -0
- package/dist/core/edicion/limpiar-carga.js.map +1 -0
- package/dist/core/edicion/observador.d.ts +80 -0
- package/dist/core/edicion/observador.d.ts.map +1 -0
- package/dist/core/edicion/observador.js +183 -0
- package/dist/core/edicion/observador.js.map +1 -0
- package/dist/core/edicion/parecido.d.ts +53 -0
- package/dist/core/edicion/parecido.d.ts.map +1 -0
- package/dist/core/edicion/parecido.js +145 -0
- package/dist/core/edicion/parecido.js.map +1 -0
- package/dist/core/edicion/parseo.d.ts +58 -0
- package/dist/core/edicion/parseo.d.ts.map +1 -0
- package/dist/core/edicion/parseo.js +124 -0
- package/dist/core/edicion/parseo.js.map +1 -0
- package/dist/core/edicion/reparacion.d.ts +67 -0
- package/dist/core/edicion/reparacion.d.ts.map +1 -0
- package/dist/core/edicion/reparacion.js +202 -0
- package/dist/core/edicion/reparacion.js.map +1 -0
- package/dist/core/edicion/sangria.d.ts +121 -0
- package/dist/core/edicion/sangria.d.ts.map +1 -0
- package/dist/core/edicion/sangria.js +341 -0
- package/dist/core/edicion/sangria.js.map +1 -0
- package/dist/core/edicion/tipos.d.ts +58 -0
- package/dist/core/edicion/tipos.d.ts.map +1 -0
- package/dist/core/edicion/tipos.js +160 -0
- package/dist/core/edicion/tipos.js.map +1 -0
- package/dist/core/engine-personality.d.ts +12 -0
- package/dist/core/engine-personality.d.ts.map +1 -0
- package/dist/core/engine-personality.js +53 -0
- package/dist/core/engine-personality.js.map +1 -0
- package/dist/core/errores/proveedor.d.ts +53 -0
- package/dist/core/errores/proveedor.d.ts.map +1 -0
- package/dist/core/errores/proveedor.js +191 -0
- package/dist/core/errores/proveedor.js.map +1 -0
- package/dist/core/estructural/buscar.d.ts +61 -0
- package/dist/core/estructural/buscar.d.ts.map +1 -0
- package/dist/core/estructural/buscar.js +261 -0
- package/dist/core/estructural/buscar.js.map +1 -0
- package/dist/core/estructural/editar.d.ts +36 -0
- package/dist/core/estructural/editar.d.ts.map +1 -0
- package/dist/core/estructural/editar.js +123 -0
- package/dist/core/estructural/editar.js.map +1 -0
- package/dist/core/estructural/tools.d.ts +11 -0
- package/dist/core/estructural/tools.d.ts.map +1 -0
- package/dist/core/estructural/tools.js +100 -0
- package/dist/core/estructural/tools.js.map +1 -0
- package/dist/core/experimental.d.ts.map +1 -1
- package/dist/core/experimental.js +10 -1
- package/dist/core/experimental.js.map +1 -1
- package/dist/core/extensiones/suplantacion.d.ts +49 -0
- package/dist/core/extensiones/suplantacion.d.ts.map +1 -0
- package/dist/core/extensiones/suplantacion.js +61 -0
- package/dist/core/extensiones/suplantacion.js.map +1 -0
- package/dist/core/extensiones/vigilancia.d.ts +54 -0
- package/dist/core/extensiones/vigilancia.d.ts.map +1 -0
- package/dist/core/extensiones/vigilancia.js +217 -0
- package/dist/core/extensiones/vigilancia.js.map +1 -0
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +21 -6
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/types.d.ts +23 -4
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/harness/fuentes-de-contexto.d.ts +29 -0
- package/dist/core/harness/fuentes-de-contexto.d.ts.map +1 -0
- package/dist/core/harness/fuentes-de-contexto.js +44 -0
- package/dist/core/harness/fuentes-de-contexto.js.map +1 -0
- package/dist/core/harness/refine.d.ts +40 -0
- package/dist/core/harness/refine.d.ts.map +1 -0
- package/dist/core/harness/refine.js +109 -0
- package/dist/core/harness/refine.js.map +1 -0
- package/dist/core/harness/store.d.ts +75 -0
- package/dist/core/harness/store.d.ts.map +1 -0
- package/dist/core/harness/store.js +149 -0
- package/dist/core/harness/store.js.map +1 -0
- package/dist/core/hooks/contract.d.ts +85 -0
- package/dist/core/hooks/contract.d.ts.map +1 -0
- package/dist/core/hooks/contract.js +140 -0
- package/dist/core/hooks/contract.js.map +1 -0
- package/dist/core/hooks/runner.d.ts +42 -0
- package/dist/core/hooks/runner.d.ts.map +1 -0
- package/dist/core/hooks/runner.js +85 -0
- package/dist/core/hooks/runner.js.map +1 -0
- package/dist/core/hooks/session-hooks.d.ts +62 -0
- package/dist/core/hooks/session-hooks.d.ts.map +1 -0
- package/dist/core/hooks/session-hooks.js +84 -0
- package/dist/core/hooks/session-hooks.js.map +1 -0
- package/dist/core/importar/formatos.d.ts +69 -0
- package/dist/core/importar/formatos.d.ts.map +1 -0
- package/dist/core/importar/formatos.js +235 -0
- package/dist/core/importar/formatos.js.map +1 -0
- package/dist/core/interactivo/deteccion.d.ts +44 -0
- package/dist/core/interactivo/deteccion.d.ts.map +1 -0
- package/dist/core/interactivo/deteccion.js +82 -0
- package/dist/core/interactivo/deteccion.js.map +1 -0
- package/dist/core/interactivo/sesion.d.ts +50 -0
- package/dist/core/interactivo/sesion.d.ts.map +1 -0
- package/dist/core/interactivo/sesion.js +156 -0
- package/dist/core/interactivo/sesion.js.map +1 -0
- package/dist/core/interactivo/tools.d.ts +21 -0
- package/dist/core/interactivo/tools.d.ts.map +1 -0
- package/dist/core/interactivo/tools.js +122 -0
- package/dist/core/interactivo/tools.js.map +1 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -1
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/lectura/mapa.d.ts +70 -0
- package/dist/core/lectura/mapa.d.ts.map +1 -0
- package/dist/core/lectura/mapa.js +177 -0
- package/dist/core/lectura/mapa.js.map +1 -0
- package/dist/core/lectura/pdf.d.ts +49 -0
- package/dist/core/lectura/pdf.d.ts.map +1 -0
- package/dist/core/lectura/pdf.js +337 -0
- package/dist/core/lectura/pdf.js.map +1 -0
- package/dist/core/limpieza/comprobadores.d.ts +28 -0
- package/dist/core/limpieza/comprobadores.d.ts.map +1 -0
- package/dist/core/limpieza/comprobadores.js +311 -0
- package/dist/core/limpieza/comprobadores.js.map +1 -0
- package/dist/core/limpieza/parseo.d.ts +19 -0
- package/dist/core/limpieza/parseo.d.ts.map +1 -0
- package/dist/core/limpieza/parseo.js +124 -0
- package/dist/core/limpieza/parseo.js.map +1 -0
- package/dist/core/limpieza/reparacion.d.ts +77 -0
- package/dist/core/limpieza/reparacion.d.ts.map +1 -0
- package/dist/core/limpieza/reparacion.js +254 -0
- package/dist/core/limpieza/reparacion.js.map +1 -0
- package/dist/core/limpieza/tipos.d.ts +56 -0
- package/dist/core/limpieza/tipos.d.ts.map +1 -0
- package/dist/core/limpieza/tipos.js +9 -0
- package/dist/core/limpieza/tipos.js.map +1 -0
- package/dist/core/lsp/cliente.d.ts +52 -0
- package/dist/core/lsp/cliente.d.ts.map +1 -0
- package/dist/core/lsp/cliente.js +232 -0
- package/dist/core/lsp/cliente.js.map +1 -0
- package/dist/core/lsp/descubrimiento.d.ts +62 -0
- package/dist/core/lsp/descubrimiento.d.ts.map +1 -0
- package/dist/core/lsp/descubrimiento.js +152 -0
- package/dist/core/lsp/descubrimiento.js.map +1 -0
- package/dist/core/lsp/ediciones.d.ts +59 -0
- package/dist/core/lsp/ediciones.d.ts.map +1 -0
- package/dist/core/lsp/ediciones.js +89 -0
- package/dist/core/lsp/ediciones.js.map +1 -0
- package/dist/core/lsp/extension.d.ts +28 -0
- package/dist/core/lsp/extension.d.ts.map +1 -0
- package/dist/core/lsp/extension.js +34 -0
- package/dist/core/lsp/extension.js.map +1 -0
- package/dist/core/lsp/tools.d.ts +45 -0
- package/dist/core/lsp/tools.d.ts.map +1 -0
- package/dist/core/lsp/tools.js +265 -0
- package/dist/core/lsp/tools.js.map +1 -0
- package/dist/core/mcp/client.d.ts +60 -0
- package/dist/core/mcp/client.d.ts.map +1 -0
- package/dist/core/mcp/client.js +139 -0
- package/dist/core/mcp/client.js.map +1 -0
- package/dist/core/mcp/manager.d.ts +86 -0
- package/dist/core/mcp/manager.d.ts.map +1 -0
- package/dist/core/mcp/manager.js +124 -0
- package/dist/core/mcp/manager.js.map +1 -0
- package/dist/core/mcp/tools.d.ts +15 -0
- package/dist/core/mcp/tools.d.ts.map +1 -0
- package/dist/core/mcp/tools.js +84 -0
- package/dist/core/mcp/tools.js.map +1 -0
- package/dist/core/memory-engine/audit-export.d.ts +56 -0
- package/dist/core/memory-engine/audit-export.d.ts.map +1 -0
- package/dist/core/memory-engine/audit-export.js +100 -0
- package/dist/core/memory-engine/audit-export.js.map +1 -0
- package/dist/core/memory-engine/audit-indice.d.ts +153 -0
- package/dist/core/memory-engine/audit-indice.d.ts.map +1 -0
- package/dist/core/memory-engine/audit-indice.js +271 -0
- package/dist/core/memory-engine/audit-indice.js.map +1 -0
- package/dist/core/memory-engine/audit.d.ts +18 -6
- package/dist/core/memory-engine/audit.d.ts.map +1 -1
- package/dist/core/memory-engine/audit.js +32 -50
- package/dist/core/memory-engine/audit.js.map +1 -1
- package/dist/core/memory-engine/engine.d.ts +21 -4
- package/dist/core/memory-engine/engine.d.ts.map +1 -1
- package/dist/core/memory-engine/engine.js +219 -55
- package/dist/core/memory-engine/engine.js.map +1 -1
- package/dist/core/memory-engine/inverted-index.d.ts.map +1 -1
- package/dist/core/memory-engine/inverted-index.js +67 -10
- package/dist/core/memory-engine/inverted-index.js.map +1 -1
- package/dist/core/memory-engine/keychain.d.ts.map +1 -1
- package/dist/core/memory-engine/keychain.js +1 -6
- package/dist/core/memory-engine/keychain.js.map +1 -1
- package/dist/core/memory-engine/observation-store.d.ts +0 -1
- package/dist/core/memory-engine/observation-store.d.ts.map +1 -1
- package/dist/core/memory-engine/observation-store.js +40 -12
- package/dist/core/memory-engine/observation-store.js.map +1 -1
- package/dist/core/memory-engine/refinements.d.ts +51 -0
- package/dist/core/memory-engine/refinements.d.ts.map +1 -0
- package/dist/core/memory-engine/refinements.js +99 -0
- package/dist/core/memory-engine/refinements.js.map +1 -0
- package/dist/core/memory-engine/scanner.d.ts.map +1 -1
- package/dist/core/memory-engine/scanner.js +25 -5
- package/dist/core/memory-engine/scanner.js.map +1 -1
- package/dist/core/memory-engine/security.d.ts.map +1 -1
- package/dist/core/memory-engine/security.js +131 -23
- package/dist/core/memory-engine/security.js.map +1 -1
- package/dist/core/memory-engine/session-indexer.d.ts.map +1 -1
- package/dist/core/memory-engine/session-indexer.js +8 -2
- package/dist/core/memory-engine/session-indexer.js.map +1 -1
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.d.ts.map +1 -1
- package/dist/core/memory-engine/tools.js +41 -8
- package/dist/core/memory-engine/tools.js.map +1 -1
- package/dist/core/memory-engine/types.d.ts +2 -0
- package/dist/core/memory-engine/types.d.ts.map +1 -1
- package/dist/core/memory-engine/types.js.map +1 -1
- package/dist/core/memory-engine/vault.d.ts.map +1 -1
- package/dist/core/memory-engine/vault.js +2 -2
- package/dist/core/memory-engine/vault.js.map +1 -1
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +2 -1
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-resolver.d.ts +1 -0
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +19 -7
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/models-store.d.ts.map +1 -1
- package/dist/core/models-store.js +2 -1
- package/dist/core/models-store.js.map +1 -1
- package/dist/core/muestreo-restringido.d.ts +49 -0
- package/dist/core/muestreo-restringido.d.ts.map +1 -0
- package/dist/core/muestreo-restringido.js +65 -0
- package/dist/core/muestreo-restringido.js.map +1 -0
- package/dist/core/orphan-process-journal.d.ts +48 -0
- package/dist/core/orphan-process-journal.d.ts.map +1 -0
- package/dist/core/orphan-process-journal.js +116 -0
- package/dist/core/orphan-process-journal.js.map +1 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +11 -6
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/pi-manifest.d.ts.map +1 -1
- package/dist/core/pi-manifest.js +2 -1
- package/dist/core/pi-manifest.js.map +1 -1
- package/dist/core/privacidad/categorias-especiales.d.ts +186 -0
- package/dist/core/privacidad/categorias-especiales.d.ts.map +1 -0
- package/dist/core/privacidad/categorias-especiales.js +745 -0
- package/dist/core/privacidad/categorias-especiales.js.map +1 -0
- package/dist/core/privacidad/tapar.d.ts +48 -0
- package/dist/core/privacidad/tapar.d.ts.map +1 -0
- package/dist/core/privacidad/tapar.js +66 -0
- package/dist/core/privacidad/tapar.js.map +1 -0
- package/dist/core/prompt-cache/diagnostics.d.ts +33 -0
- package/dist/core/prompt-cache/diagnostics.d.ts.map +1 -0
- package/dist/core/prompt-cache/diagnostics.js +100 -0
- package/dist/core/prompt-cache/diagnostics.js.map +1 -0
- package/dist/core/prompt-cache/index.d.ts +33 -0
- package/dist/core/prompt-cache/index.d.ts.map +1 -0
- package/dist/core/prompt-cache/index.js +189 -0
- package/dist/core/prompt-cache/index.js.map +1 -0
- package/dist/core/prompt-cache/payload.d.ts +58 -0
- package/dist/core/prompt-cache/payload.d.ts.map +1 -0
- package/dist/core/prompt-cache/payload.js +122 -0
- package/dist/core/prompt-cache/payload.js.map +1 -0
- package/dist/core/prompt-cache/stabilize.d.ts +65 -0
- package/dist/core/prompt-cache/stabilize.d.ts.map +1 -0
- package/dist/core/prompt-cache/stabilize.js +137 -0
- package/dist/core/prompt-cache/stabilize.js.map +1 -0
- package/dist/core/prompt-cache/stats.d.ts +55 -0
- package/dist/core/prompt-cache/stats.d.ts.map +1 -0
- package/dist/core/prompt-cache/stats.js +158 -0
- package/dist/core/prompt-cache/stats.js.map +1 -0
- package/dist/core/prompt-eleccion.d.ts +38 -0
- package/dist/core/prompt-eleccion.d.ts.map +1 -0
- package/dist/core/prompt-eleccion.js +46 -0
- package/dist/core/prompt-eleccion.js.map +1 -0
- package/dist/core/prompt-optimizer.d.ts +53 -0
- package/dist/core/prompt-optimizer.d.ts.map +1 -0
- package/dist/core/prompt-optimizer.js +138 -0
- package/dist/core/prompt-optimizer.js.map +1 -0
- package/dist/core/prompts/montar.d.ts +75 -0
- package/dist/core/prompts/montar.d.ts.map +1 -0
- package/dist/core/prompts/montar.js +146 -0
- package/dist/core/prompts/montar.js.map +1 -0
- package/dist/core/prompts/plantilla.d.ts +54 -0
- package/dist/core/prompts/plantilla.d.ts.map +1 -0
- package/dist/core/prompts/plantilla.js +153 -0
- package/dist/core/prompts/plantilla.js.map +1 -0
- package/dist/core/prompts/sistema.md +134 -0
- package/dist/core/provider-attribution.d.ts +24 -2
- package/dist/core/provider-attribution.d.ts.map +1 -1
- package/dist/core/provider-attribution.js +24 -42
- package/dist/core/provider-attribution.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +2 -1
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/remoto/destino.d.ts +38 -0
- package/dist/core/remoto/destino.d.ts.map +1 -0
- package/dist/core/remoto/destino.js +105 -0
- package/dist/core/remoto/destino.js.map +1 -0
- package/dist/core/remoto/ejecutor.d.ts +59 -0
- package/dist/core/remoto/ejecutor.d.ts.map +1 -0
- package/dist/core/remoto/ejecutor.js +225 -0
- package/dist/core/remoto/ejecutor.js.map +1 -0
- package/dist/core/remoto/ficheros.d.ts +29 -0
- package/dist/core/remoto/ficheros.d.ts.map +1 -0
- package/dist/core/remoto/ficheros.js +90 -0
- package/dist/core/remoto/ficheros.js.map +1 -0
- package/dist/core/remoto/registro-extension.d.ts +15 -0
- package/dist/core/remoto/registro-extension.d.ts.map +1 -0
- package/dist/core/remoto/registro-extension.js +17 -0
- package/dist/core/remoto/registro-extension.js.map +1 -0
- package/dist/core/remoto/tools.d.ts +28 -0
- package/dist/core/remoto/tools.d.ts.map +1 -0
- package/dist/core/remoto/tools.js +31 -0
- package/dist/core/remoto/tools.js.map +1 -0
- package/dist/core/resource-loader.d.ts +58 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +326 -8
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/revision/hallazgo.d.ts +51 -0
- package/dist/core/revision/hallazgo.d.ts.map +1 -0
- package/dist/core/revision/hallazgo.js +73 -0
- package/dist/core/revision/hallazgo.js.map +1 -0
- package/dist/core/revision/revisor.d.ts +81 -0
- package/dist/core/revision/revisor.d.ts.map +1 -0
- package/dist/core/revision/revisor.js +132 -0
- package/dist/core/revision/revisor.js.map +1 -0
- package/dist/core/revision/sarif.d.ts +30 -0
- package/dist/core/revision/sarif.d.ts.map +1 -0
- package/dist/core/revision/sarif.js +83 -0
- package/dist/core/revision/sarif.js.map +1 -0
- package/dist/core/scheduler/scheduler.d.ts +87 -0
- package/dist/core/scheduler/scheduler.d.ts.map +1 -0
- package/dist/core/scheduler/scheduler.js +178 -0
- package/dist/core/scheduler/scheduler.js.map +1 -0
- package/dist/core/sdk.d.ts +8 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +11 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/sesion/cerrar-llamadas-abiertas.d.ts +49 -0
- package/dist/core/sesion/cerrar-llamadas-abiertas.d.ts.map +1 -0
- package/dist/core/sesion/cerrar-llamadas-abiertas.js +77 -0
- package/dist/core/sesion/cerrar-llamadas-abiertas.js.map +1 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +2 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-diagnostics.d.ts +9 -0
- package/dist/core/settings-diagnostics.d.ts.map +1 -0
- package/dist/core/settings-diagnostics.js +21 -0
- package/dist/core/settings-diagnostics.js.map +1 -0
- package/dist/core/settings-manager.d.ts +156 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +255 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +51 -33
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +2 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts +17 -0
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +13 -5
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/telemetria/otlp.d.ts +122 -0
- package/dist/core/telemetria/otlp.d.ts.map +1 -0
- package/dist/core/telemetria/otlp.js +373 -0
- package/dist/core/telemetria/otlp.js.map +1 -0
- package/dist/core/tools/coercion-argumentos.d.ts +48 -0
- package/dist/core/tools/coercion-argumentos.d.ts.map +1 -0
- package/dist/core/tools/coercion-argumentos.js +99 -0
- package/dist/core/tools/coercion-argumentos.js.map +1 -0
- package/dist/core/tools/edit-diff.d.ts +0 -12
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +234 -12
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +28 -5
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
- package/dist/core/tools/file-mutation-queue.js +5 -0
- package/dist/core/tools/file-mutation-queue.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +2 -2
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/json-tolerante.d.ts +30 -0
- package/dist/core/tools/json-tolerante.d.ts.map +1 -0
- package/dist/core/tools/json-tolerante.js +70 -0
- package/dist/core/tools/json-tolerante.js.map +1 -0
- package/dist/core/tools/project-memory-tool.d.ts.map +1 -1
- package/dist/core/tools/project-memory-tool.js +4 -1
- package/dist/core/tools/project-memory-tool.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +17 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts +14 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +17 -1
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/trust-manager.d.ts.map +1 -1
- package/dist/core/trust-manager.js +2 -1
- package/dist/core/trust-manager.js.map +1 -1
- package/dist/core/turno-vacio/detectar.d.ts +38 -0
- package/dist/core/turno-vacio/detectar.d.ts.map +1 -0
- package/dist/core/turno-vacio/detectar.js +66 -0
- package/dist/core/turno-vacio/detectar.js.map +1 -0
- package/dist/core/undo/journal.d.ts +57 -0
- package/dist/core/undo/journal.d.ts.map +1 -0
- package/dist/core/undo/journal.js +178 -0
- package/dist/core/undo/journal.js.map +1 -0
- package/dist/core/urls-internas/auditoria.d.ts +10 -0
- package/dist/core/urls-internas/auditoria.d.ts.map +1 -0
- package/dist/core/urls-internas/auditoria.js +42 -0
- package/dist/core/urls-internas/auditoria.js.map +1 -0
- package/dist/core/urls-internas/boveda.d.ts +13 -0
- package/dist/core/urls-internas/boveda.d.ts.map +1 -0
- package/dist/core/urls-internas/boveda.js +40 -0
- package/dist/core/urls-internas/boveda.js.map +1 -0
- package/dist/core/urls-internas/lector.d.ts +30 -0
- package/dist/core/urls-internas/lector.d.ts.map +1 -0
- package/dist/core/urls-internas/lector.js +56 -0
- package/dist/core/urls-internas/lector.js.map +1 -0
- package/dist/core/urls-internas/memoria.d.ts +11 -0
- package/dist/core/urls-internas/memoria.d.ts.map +1 -0
- package/dist/core/urls-internas/memoria.js +25 -0
- package/dist/core/urls-internas/memoria.js.map +1 -0
- package/dist/core/urls-internas/parse.d.ts +28 -0
- package/dist/core/urls-internas/parse.d.ts.map +1 -0
- package/dist/core/urls-internas/parse.js +32 -0
- package/dist/core/urls-internas/parse.js.map +1 -0
- package/dist/core/urls-internas/reglas.d.ts +10 -0
- package/dist/core/urls-internas/reglas.d.ts.map +1 -0
- package/dist/core/urls-internas/reglas.js +31 -0
- package/dist/core/urls-internas/reglas.js.map +1 -0
- package/dist/core/usage/aggregate.d.ts +68 -0
- package/dist/core/usage/aggregate.d.ts.map +1 -0
- package/dist/core/usage/aggregate.js +93 -0
- package/dist/core/usage/aggregate.js.map +1 -0
- package/dist/core/usage/cuota/anthropic.d.ts +10 -0
- package/dist/core/usage/cuota/anthropic.d.ts.map +1 -0
- package/dist/core/usage/cuota/anthropic.js +63 -0
- package/dist/core/usage/cuota/anthropic.js.map +1 -0
- package/dist/core/usage/cuota/cache.d.ts +20 -0
- package/dist/core/usage/cuota/cache.d.ts.map +1 -0
- package/dist/core/usage/cuota/cache.js +36 -0
- package/dist/core/usage/cuota/cache.js.map +1 -0
- package/dist/core/usage/cuota/github-copilot.d.ts +9 -0
- package/dist/core/usage/cuota/github-copilot.d.ts.map +1 -0
- package/dist/core/usage/cuota/github-copilot.js +67 -0
- package/dist/core/usage/cuota/github-copilot.js.map +1 -0
- package/dist/core/usage/cuota/google-gemini.d.ts +9 -0
- package/dist/core/usage/cuota/google-gemini.d.ts.map +1 -0
- package/dist/core/usage/cuota/google-gemini.js +72 -0
- package/dist/core/usage/cuota/google-gemini.js.map +1 -0
- package/dist/core/usage/cuota/index.d.ts +25 -0
- package/dist/core/usage/cuota/index.d.ts.map +1 -0
- package/dist/core/usage/cuota/index.js +50 -0
- package/dist/core/usage/cuota/index.js.map +1 -0
- package/dist/core/usage/cuota/openai-codex.d.ts +9 -0
- package/dist/core/usage/cuota/openai-codex.d.ts.map +1 -0
- package/dist/core/usage/cuota/openai-codex.js +59 -0
- package/dist/core/usage/cuota/openai-codex.js.map +1 -0
- package/dist/core/usage/cuota/openrouter.d.ts +10 -0
- package/dist/core/usage/cuota/openrouter.d.ts.map +1 -0
- package/dist/core/usage/cuota/openrouter.js +47 -0
- package/dist/core/usage/cuota/openrouter.js.map +1 -0
- package/dist/core/usage/cuota/tipos.d.ts +50 -0
- package/dist/core/usage/cuota/tipos.d.ts.map +1 -0
- package/dist/core/usage/cuota/tipos.js +25 -0
- package/dist/core/usage/cuota/tipos.js.map +1 -0
- package/dist/core/web/busqueda-nativa.d.ts +82 -0
- package/dist/core/web/busqueda-nativa.d.ts.map +1 -0
- package/dist/core/web/busqueda-nativa.js +163 -0
- package/dist/core/web/busqueda-nativa.js.map +1 -0
- package/dist/core/web/destino.d.ts +58 -0
- package/dist/core/web/destino.d.ts.map +1 -0
- package/dist/core/web/destino.js +127 -0
- package/dist/core/web/destino.js.map +1 -0
- package/dist/core/web/proveedores/brave.d.ts +6 -0
- package/dist/core/web/proveedores/brave.d.ts.map +1 -0
- package/dist/core/web/proveedores/brave.js +20 -0
- package/dist/core/web/proveedores/brave.js.map +1 -0
- package/dist/core/web/proveedores/claves.d.ts +19 -0
- package/dist/core/web/proveedores/claves.d.ts.map +1 -0
- package/dist/core/web/proveedores/claves.js +36 -0
- package/dist/core/web/proveedores/claves.js.map +1 -0
- package/dist/core/web/proveedores/duckduckgo.d.ts +3 -0
- package/dist/core/web/proveedores/duckduckgo.d.ts.map +1 -0
- package/dist/core/web/proveedores/duckduckgo.js +109 -0
- package/dist/core/web/proveedores/duckduckgo.js.map +1 -0
- package/dist/core/web/proveedores/ecosia.d.ts +3 -0
- package/dist/core/web/proveedores/ecosia.d.ts.map +1 -0
- package/dist/core/web/proveedores/ecosia.js +72 -0
- package/dist/core/web/proveedores/ecosia.js.map +1 -0
- package/dist/core/web/proveedores/exa.d.ts +6 -0
- package/dist/core/web/proveedores/exa.d.ts.map +1 -0
- package/dist/core/web/proveedores/exa.js +24 -0
- package/dist/core/web/proveedores/exa.js.map +1 -0
- package/dist/core/web/proveedores/mojeek.d.ts +3 -0
- package/dist/core/web/proveedores/mojeek.d.ts.map +1 -0
- package/dist/core/web/proveedores/mojeek.js +65 -0
- package/dist/core/web/proveedores/mojeek.js.map +1 -0
- package/dist/core/web/proveedores/navegador.d.ts +10 -0
- package/dist/core/web/proveedores/navegador.d.ts.map +1 -0
- package/dist/core/web/proveedores/navegador.js +13 -0
- package/dist/core/web/proveedores/navegador.js.map +1 -0
- package/dist/core/web/proveedores/registro.d.ts +43 -0
- package/dist/core/web/proveedores/registro.d.ts.map +1 -0
- package/dist/core/web/proveedores/registro.js +49 -0
- package/dist/core/web/proveedores/registro.js.map +1 -0
- package/dist/core/web/proveedores/searxng.d.ts +9 -0
- package/dist/core/web/proveedores/searxng.d.ts.map +1 -0
- package/dist/core/web/proveedores/searxng.js +17 -0
- package/dist/core/web/proveedores/searxng.js.map +1 -0
- package/dist/core/web/proveedores/serper.d.ts +9 -0
- package/dist/core/web/proveedores/serper.d.ts.map +1 -0
- package/dist/core/web/proveedores/serper.js +19 -0
- package/dist/core/web/proveedores/serper.js.map +1 -0
- package/dist/core/web/proveedores/tavily.d.ts +6 -0
- package/dist/core/web/proveedores/tavily.d.ts.map +1 -0
- package/dist/core/web/proveedores/tavily.js +19 -0
- package/dist/core/web/proveedores/tavily.js.map +1 -0
- package/dist/core/web/proveedores/tipos.d.ts +36 -0
- package/dist/core/web/proveedores/tipos.d.ts.map +1 -0
- package/dist/core/web/proveedores/tipos.js +10 -0
- package/dist/core/web/proveedores/tipos.js.map +1 -0
- package/dist/core/web/registro-red.d.ts +43 -0
- package/dist/core/web/registro-red.d.ts.map +1 -0
- package/dist/core/web/registro-red.js +86 -0
- package/dist/core/web/registro-red.js.map +1 -0
- package/dist/core/web/scrapers/cisa-kev.d.ts +10 -0
- package/dist/core/web/scrapers/cisa-kev.d.ts.map +1 -0
- package/dist/core/web/scrapers/cisa-kev.js +38 -0
- package/dist/core/web/scrapers/cisa-kev.js.map +1 -0
- package/dist/core/web/scrapers/crates-io.d.ts +11 -0
- package/dist/core/web/scrapers/crates-io.d.ts.map +1 -0
- package/dist/core/web/scrapers/crates-io.js +29 -0
- package/dist/core/web/scrapers/crates-io.js.map +1 -0
- package/dist/core/web/scrapers/docs-rs.d.ts +10 -0
- package/dist/core/web/scrapers/docs-rs.d.ts.map +1 -0
- package/dist/core/web/scrapers/docs-rs.js +35 -0
- package/dist/core/web/scrapers/docs-rs.js.map +1 -0
- package/dist/core/web/scrapers/github.d.ts +3 -0
- package/dist/core/web/scrapers/github.d.ts.map +1 -0
- package/dist/core/web/scrapers/github.js +72 -0
- package/dist/core/web/scrapers/github.js.map +1 -0
- package/dist/core/web/scrapers/go-pkg.d.ts +7 -0
- package/dist/core/web/scrapers/go-pkg.d.ts.map +1 -0
- package/dist/core/web/scrapers/go-pkg.js +30 -0
- package/dist/core/web/scrapers/go-pkg.js.map +1 -0
- package/dist/core/web/scrapers/hex.d.ts +6 -0
- package/dist/core/web/scrapers/hex.d.ts.map +1 -0
- package/dist/core/web/scrapers/hex.js +27 -0
- package/dist/core/web/scrapers/hex.js.map +1 -0
- package/dist/core/web/scrapers/maven.d.ts +8 -0
- package/dist/core/web/scrapers/maven.d.ts.map +1 -0
- package/dist/core/web/scrapers/maven.js +41 -0
- package/dist/core/web/scrapers/maven.js.map +1 -0
- package/dist/core/web/scrapers/mdn.d.ts +6 -0
- package/dist/core/web/scrapers/mdn.d.ts.map +1 -0
- package/dist/core/web/scrapers/mdn.js +28 -0
- package/dist/core/web/scrapers/mdn.js.map +1 -0
- package/dist/core/web/scrapers/npm.d.ts +11 -0
- package/dist/core/web/scrapers/npm.d.ts.map +1 -0
- package/dist/core/web/scrapers/npm.js +57 -0
- package/dist/core/web/scrapers/npm.js.map +1 -0
- package/dist/core/web/scrapers/nuget.d.ts +8 -0
- package/dist/core/web/scrapers/nuget.d.ts.map +1 -0
- package/dist/core/web/scrapers/nuget.js +22 -0
- package/dist/core/web/scrapers/nuget.js.map +1 -0
- package/dist/core/web/scrapers/nvd.d.ts +7 -0
- package/dist/core/web/scrapers/nvd.d.ts.map +1 -0
- package/dist/core/web/scrapers/nvd.js +37 -0
- package/dist/core/web/scrapers/nvd.js.map +1 -0
- package/dist/core/web/scrapers/pypi.d.ts +6 -0
- package/dist/core/web/scrapers/pypi.d.ts.map +1 -0
- package/dist/core/web/scrapers/pypi.js +31 -0
- package/dist/core/web/scrapers/pypi.js.map +1 -0
- package/dist/core/web/scrapers/registro.d.ts +13 -0
- package/dist/core/web/scrapers/registro.d.ts.map +1 -0
- package/dist/core/web/scrapers/registro.js +65 -0
- package/dist/core/web/scrapers/registro.js.map +1 -0
- package/dist/core/web/scrapers/rubygems.d.ts +6 -0
- package/dist/core/web/scrapers/rubygems.d.ts.map +1 -0
- package/dist/core/web/scrapers/rubygems.js +23 -0
- package/dist/core/web/scrapers/rubygems.js.map +1 -0
- package/dist/core/web/scrapers/stackoverflow.d.ts +3 -0
- package/dist/core/web/scrapers/stackoverflow.d.ts.map +1 -0
- package/dist/core/web/scrapers/stackoverflow.js +46 -0
- package/dist/core/web/scrapers/stackoverflow.js.map +1 -0
- package/dist/core/web/scrapers/tipos.d.ts +42 -0
- package/dist/core/web/scrapers/tipos.d.ts.map +1 -0
- package/dist/core/web/scrapers/tipos.js +23 -0
- package/dist/core/web/scrapers/tipos.js.map +1 -0
- package/dist/core/web/texto.d.ts +10 -0
- package/dist/core/web/texto.d.ts.map +1 -0
- package/dist/core/web/texto.js +26 -0
- package/dist/core/web/texto.js.map +1 -0
- package/dist/core/web/tools.d.ts +91 -0
- package/dist/core/web/tools.d.ts.map +1 -0
- package/dist/core/web/tools.js +304 -0
- package/dist/core/web/tools.js.map +1 -0
- package/dist/core/wiki/almacen.d.ts +33 -0
- package/dist/core/wiki/almacen.d.ts.map +1 -0
- package/dist/core/wiki/almacen.js +93 -0
- package/dist/core/wiki/almacen.js.map +1 -0
- package/dist/core/wiki/citas.d.ts +111 -0
- package/dist/core/wiki/citas.d.ts.map +1 -0
- package/dist/core/wiki/citas.js +146 -0
- package/dist/core/wiki/citas.js.map +1 -0
- package/dist/core/workflows/agent-runner.d.ts +88 -0
- package/dist/core/workflows/agent-runner.d.ts.map +1 -0
- package/dist/core/workflows/agent-runner.js +312 -0
- package/dist/core/workflows/agent-runner.js.map +1 -0
- package/dist/core/workflows/builtins.d.ts +41 -0
- package/dist/core/workflows/builtins.d.ts.map +1 -0
- package/dist/core/workflows/builtins.js +283 -0
- package/dist/core/workflows/builtins.js.map +1 -0
- package/dist/core/workflows/contrato/esquema.d.ts +32 -0
- package/dist/core/workflows/contrato/esquema.d.ts.map +1 -0
- package/dist/core/workflows/contrato/esquema.js +25 -0
- package/dist/core/workflows/contrato/esquema.js.map +1 -0
- package/dist/core/workflows/contrato/reparar-argumentos.d.ts +69 -0
- package/dist/core/workflows/contrato/reparar-argumentos.d.ts.map +1 -0
- package/dist/core/workflows/contrato/reparar-argumentos.js +117 -0
- package/dist/core/workflows/contrato/reparar-argumentos.js.map +1 -0
- package/dist/core/workflows/contrato/validador.d.ts +30 -0
- package/dist/core/workflows/contrato/validador.d.ts.map +1 -0
- package/dist/core/workflows/contrato/validador.js +56 -0
- package/dist/core/workflows/contrato/validador.js.map +1 -0
- package/dist/core/workflows/contrato/yield.d.ts +65 -0
- package/dist/core/workflows/contrato/yield.d.ts.map +1 -0
- package/dist/core/workflows/contrato/yield.js +80 -0
- package/dist/core/workflows/contrato/yield.js.map +1 -0
- package/dist/core/workflows/goal-engine/engine.d.ts +151 -0
- package/dist/core/workflows/goal-engine/engine.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/engine.js +503 -0
- package/dist/core/workflows/goal-engine/engine.js.map +1 -0
- package/dist/core/workflows/goal-engine/errors.d.ts +7 -0
- package/dist/core/workflows/goal-engine/errors.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/errors.js +9 -0
- package/dist/core/workflows/goal-engine/errors.js.map +1 -0
- package/dist/core/workflows/goal-engine/index.d.ts +13 -0
- package/dist/core/workflows/goal-engine/index.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/index.js +8 -0
- package/dist/core/workflows/goal-engine/index.js.map +1 -0
- package/dist/core/workflows/goal-engine/persistence.d.ts +31 -0
- package/dist/core/workflows/goal-engine/persistence.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/persistence.js +145 -0
- package/dist/core/workflows/goal-engine/persistence.js.map +1 -0
- package/dist/core/workflows/goal-engine/prompts.d.ts +37 -0
- package/dist/core/workflows/goal-engine/prompts.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/prompts.js +131 -0
- package/dist/core/workflows/goal-engine/prompts.js.map +1 -0
- package/dist/core/workflows/goal-engine/state.d.ts +41 -0
- package/dist/core/workflows/goal-engine/state.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/state.js +397 -0
- package/dist/core/workflows/goal-engine/state.js.map +1 -0
- package/dist/core/workflows/goal-engine/tools.d.ts +31 -0
- package/dist/core/workflows/goal-engine/tools.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/tools.js +211 -0
- package/dist/core/workflows/goal-engine/tools.js.map +1 -0
- package/dist/core/workflows/goal-engine/types.d.ts +286 -0
- package/dist/core/workflows/goal-engine/types.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/types.js +17 -0
- package/dist/core/workflows/goal-engine/types.js.map +1 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.d.ts +23 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.d.ts.map +1 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.js +72 -0
- package/dist/core/workflows/goal-engine/worktree-fingerprint.js.map +1 -0
- package/dist/core/workflows/graph-sync.d.ts +67 -0
- package/dist/core/workflows/graph-sync.d.ts.map +1 -0
- package/dist/core/workflows/graph-sync.js +188 -0
- package/dist/core/workflows/graph-sync.js.map +1 -0
- package/dist/core/workflows/graph.d.ts +143 -0
- package/dist/core/workflows/graph.d.ts.map +1 -0
- package/dist/core/workflows/graph.js +319 -0
- package/dist/core/workflows/graph.js.map +1 -0
- package/dist/core/workflows/index.d.ts +26 -0
- package/dist/core/workflows/index.d.ts.map +1 -0
- package/dist/core/workflows/index.js +18 -0
- package/dist/core/workflows/index.js.map +1 -0
- package/dist/core/workflows/journal.d.ts +68 -0
- package/dist/core/workflows/journal.d.ts.map +1 -0
- package/dist/core/workflows/journal.js +83 -0
- package/dist/core/workflows/journal.js.map +1 -0
- package/dist/core/workflows/manager.d.ts +122 -0
- package/dist/core/workflows/manager.d.ts.map +1 -0
- package/dist/core/workflows/manager.js +351 -0
- package/dist/core/workflows/manager.js.map +1 -0
- package/dist/core/workflows/resolve-script.d.ts +35 -0
- package/dist/core/workflows/resolve-script.d.ts.map +1 -0
- package/dist/core/workflows/resolve-script.js +66 -0
- package/dist/core/workflows/resolve-script.js.map +1 -0
- package/dist/core/workflows/runtime.d.ts +62 -0
- package/dist/core/workflows/runtime.d.ts.map +1 -0
- package/dist/core/workflows/runtime.js +380 -0
- package/dist/core/workflows/runtime.js.map +1 -0
- package/dist/core/workflows/save-as-skill.d.ts +27 -0
- package/dist/core/workflows/save-as-skill.d.ts.map +1 -0
- package/dist/core/workflows/save-as-skill.js +54 -0
- package/dist/core/workflows/save-as-skill.js.map +1 -0
- package/dist/core/workflows/shared-store.d.ts +31 -0
- package/dist/core/workflows/shared-store.d.ts.map +1 -0
- package/dist/core/workflows/shared-store.js +80 -0
- package/dist/core/workflows/shared-store.js.map +1 -0
- package/dist/core/workflows/subagent-host.d.ts +50 -0
- package/dist/core/workflows/subagent-host.d.ts.map +1 -0
- package/dist/core/workflows/subagent-host.js +225 -0
- package/dist/core/workflows/subagent-host.js.map +1 -0
- package/dist/core/workflows/tool-workflow.d.ts +22 -0
- package/dist/core/workflows/tool-workflow.d.ts.map +1 -0
- package/dist/core/workflows/tool-workflow.js +120 -0
- package/dist/core/workflows/tool-workflow.js.map +1 -0
- package/dist/core/workflows/types.d.ts +191 -0
- package/dist/core/workflows/types.d.ts.map +1 -0
- package/dist/core/workflows/types.js +26 -0
- package/dist/core/workflows/types.js.map +1 -0
- package/dist/core/workflows/worktree.d.ts +42 -0
- package/dist/core/workflows/worktree.d.ts.map +1 -0
- package/dist/core/workflows/worktree.js +107 -0
- package/dist/core/workflows/worktree.js.map +1 -0
- package/dist/extensions/llama/index.d.ts.map +1 -1
- package/dist/extensions/llama/index.js +2 -0
- package/dist/extensions/llama/index.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +6 -2
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/extensions/remoto/index.d.ts +22 -0
- package/dist/extensions/remoto/index.d.ts.map +1 -0
- package/dist/extensions/remoto/index.js +54 -0
- package/dist/extensions/remoto/index.js.map +1 -0
- package/dist/index.d.ts +1 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -13
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts +4 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +26 -15
- package/dist/main.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js +4 -3
- package/dist/migrations.js.map +1 -1
- package/dist/modes/acp/acp-mode.d.ts +42 -0
- package/dist/modes/acp/acp-mode.d.ts.map +1 -0
- package/dist/modes/acp/acp-mode.js +190 -0
- package/dist/modes/acp/acp-mode.js.map +1 -0
- package/dist/modes/acp/events.d.ts +74 -0
- package/dist/modes/acp/events.d.ts.map +1 -0
- package/dist/modes/acp/events.js +116 -0
- package/dist/modes/acp/events.js.map +1 -0
- package/dist/modes/interactive/components/home-screen.d.ts.map +1 -1
- package/dist/modes/interactive/components/home-screen.js +2 -2
- package/dist/modes/interactive/components/home-screen.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts +9 -3
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +56 -12
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/prompt-optimization.d.ts +16 -0
- package/dist/modes/interactive/components/prompt-optimization.d.ts.map +1 -0
- package/dist/modes/interactive/components/prompt-optimization.js +46 -0
- package/dist/modes/interactive/components/prompt-optimization.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts +19 -2
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +180 -56
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
- package/dist/modes/interactive/components/settings-submenu.js +165 -0
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
- package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +74 -17
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +21 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +709 -75
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +4 -3
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts +16 -13
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +20 -6
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +11 -0
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +173 -0
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +29 -0
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +27 -5
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/server/attach.d.ts +56 -0
- package/dist/server/attach.d.ts.map +1 -0
- package/dist/server/attach.js +130 -0
- package/dist/server/attach.js.map +1 -0
- package/dist/server/extension-ops.d.ts +40 -0
- package/dist/server/extension-ops.d.ts.map +1 -0
- package/dist/server/extension-ops.js +146 -0
- package/dist/server/extension-ops.js.map +1 -0
- package/dist/server/pi-server-service.d.ts +85 -0
- package/dist/server/pi-server-service.d.ts.map +1 -0
- package/dist/server/pi-server-service.js +213 -0
- package/dist/server/pi-server-service.js.map +1 -0
- package/dist/server/scheduler-tick.d.ts +32 -0
- package/dist/server/scheduler-tick.d.ts.map +1 -0
- package/dist/server/scheduler-tick.js +47 -0
- package/dist/server/scheduler-tick.js.map +1 -0
- package/dist/server/serve.d.ts +25 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +83 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/server/transcript.d.ts +38 -0
- package/dist/server/transcript.d.ts.map +1 -0
- package/dist/server/transcript.js +176 -0
- package/dist/server/transcript.js.map +1 -0
- package/dist/skills/ada-engine/SKILL.md +153 -0
- package/dist/skills/skill-creator/SKILL.md +90 -0
- package/dist/telegram/api.d.ts +75 -0
- package/dist/telegram/api.d.ts.map +1 -0
- package/dist/telegram/api.js +104 -0
- package/dist/telegram/api.js.map +1 -0
- package/dist/telegram/bridge.d.ts +85 -0
- package/dist/telegram/bridge.d.ts.map +1 -0
- package/dist/telegram/bridge.js +182 -0
- package/dist/telegram/bridge.js.map +1 -0
- package/dist/telegram/journal.d.ts +67 -0
- package/dist/telegram/journal.d.ts.map +1 -0
- package/dist/telegram/journal.js +119 -0
- package/dist/telegram/journal.js.map +1 -0
- package/dist/telegram/servidor.d.ts +15 -0
- package/dist/telegram/servidor.d.ts.map +1 -0
- package/dist/telegram/servidor.js +74 -0
- package/dist/telegram/servidor.js.map +1 -0
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +2 -1
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/management-http.d.ts +5 -3
- package/dist/utils/management-http.d.ts.map +1 -1
- package/dist/utils/management-http.js +14 -10
- package/dist/utils/management-http.js.map +1 -1
- package/dist/utils/shell.d.ts +11 -0
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +11 -0
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/text.d.ts +8 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +9 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +29 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +25 -10
- package/docs/compliance.md +241 -0
- package/docs/containerization.md +24 -24
- package/docs/custom-provider.md +15 -12
- package/docs/development.md +47 -10
- package/docs/docs.json +14 -2
- package/docs/environment-variables.md +20 -17
- package/docs/extensions.md +62 -51
- package/docs/index.md +15 -21
- package/docs/json.md +10 -5
- package/docs/keybindings.md +5 -5
- package/docs/llama-cpp.md +9 -7
- package/docs/models.md +18 -12
- package/docs/packages.md +45 -45
- package/docs/prompt-templates.md +5 -5
- package/docs/providers.md +12 -12
- package/docs/quickstart.md +39 -39
- package/docs/rpc.md +21 -15
- package/docs/sdk.md +38 -38
- package/docs/security.md +26 -21
- package/docs/session-format.md +7 -7
- package/docs/sessions.md +14 -14
- package/docs/settings.md +47 -22
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +14 -13
- package/docs/terminal-setup.md +14 -14
- package/docs/termux.md +7 -7
- package/docs/themes.md +11 -11
- package/docs/tmux.md +4 -4
- package/docs/tui.md +3 -3
- package/docs/usage.md +54 -54
- package/docs/windows.md +2 -2
- package/examples/extensions/border-status-editor.ts +1 -1
- package/examples/extensions/git-checkpoint.ts +2 -2
- package/examples/extensions/notify.ts +3 -1
- package/examples/extensions/subagent/README.md +1 -1
- package/examples/extensions/subagent/index.ts +6 -1
- package/examples/extensions/titlebar-spinner.ts +1 -1
- package/examples/rpc-extension-ui.ts +1 -1
- package/examples/sdk/06-extensions.ts +1 -1
- package/examples/sdk/12-full-control.ts +9 -0
- package/examples/sdk/README.md +1 -1
- package/npm-shrinkwrap.json +35 -261
- package/package.json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C,UAAU,CAAC,CAAC;QAC/C,MAAM,iBAAiB,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,6BAA6B,CAAC,iBAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAElG,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AAAA,CACD;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,IAAY,EACZ,OAAe,EACf,OAAe,EACf,GAAW,EAC+B;IAC1C,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAAA,CAC3D","sourcesContent":["/**\n * Shared diff computation utilities for the edit and similar tools.\n */\n\nimport * as Diff from \"diff\";\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\ttext\n\t\t\t.normalize(\"NFKC\")\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nfunction splitLinesWithEndings(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+/g) ?? [];\n}\n\ninterface LineSpan {\n\tstart: number;\n\tend: number;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\ntype TextReplacement = Pick<MatchedEdit, \"matchIndex\" | \"matchLength\" | \"newText\">;\n\nfunction getLineSpans(content: string): LineSpan[] {\n\tlet offset = 0;\n\treturn splitLinesWithEndings(content).map((line) => {\n\t\tconst span = { start: offset, end: offset + line.length };\n\t\toffset = span.end;\n\t\treturn span;\n\t});\n}\n\nfunction getReplacementLineRange(lines: LineSpan[], replacement: TextReplacement) {\n\tconst replacementStart = replacement.matchIndex;\n\tconst replacementEnd = replacement.matchIndex + replacement.matchLength;\n\n\tlet startLine = -1;\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tconst line = lines[i];\n\t\tif (replacementStart >= line.start && replacementStart < line.end) {\n\t\t\tstartLine = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (startLine === -1) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\tlet endLine = startLine;\n\twhile (endLine < lines.length && lines[endLine].end < replacementEnd) {\n\t\tendLine++;\n\t}\n\tif (endLine >= lines.length) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\treturn { startLine, endLine: endLine + 1 };\n}\n\nfunction applyReplacements(content: string, replacements: TextReplacement[], offset = 0): string {\n\tlet result = content;\n\tfor (let i = replacements.length - 1; i >= 0; i--) {\n\t\tconst replacement = replacements[i];\n\t\tconst matchIndex = replacement.matchIndex - offset;\n\t\tresult =\n\t\t\tresult.substring(0, matchIndex) + replacement.newText + result.substring(matchIndex + replacement.matchLength);\n\t}\n\treturn result;\n}\n\n/**\n * Apply replacements matched against `baseContent` to `originalContent` while\n * preserving unchanged line blocks from the original.\n *\n * This is useful when `baseContent` is a normalized view of the original. Each\n * replacement is widened to the lines it actually touches, those touched lines\n * are rewritten from the normalized base, and all other lines are copied back\n * from `originalContent`. The actual replacement ranges drive preservation so\n * duplicate normalized lines cannot be aligned to the wrong occurrence.\n */\nexport function applyReplacementsPreservingUnchangedLines(\n\toriginalContent: string,\n\tbaseContent: string,\n\treplacements: TextReplacement[],\n): string {\n\tconst originalLines = splitLinesWithEndings(originalContent);\n\tconst baseLines = getLineSpans(baseContent);\n\tif (originalLines.length !== baseLines.length) {\n\t\tthrow new Error(\"Cannot preserve unchanged lines because the base content has a different line count.\");\n\t}\n\n\tconst groups: Array<{ startLine: number; endLine: number; replacements: TextReplacement[] }> = [];\n\tconst sortedReplacements = [...replacements].sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (const replacement of sortedReplacements) {\n\t\tconst range = getReplacementLineRange(baseLines, replacement);\n\t\tconst current = groups[groups.length - 1];\n\t\tif (current && range.startLine < current.endLine) {\n\t\t\tcurrent.endLine = Math.max(current.endLine, range.endLine);\n\t\t\tcurrent.replacements.push(replacement);\n\t\t\tcontinue;\n\t\t}\n\t\tgroups.push({ ...range, replacements: [replacement] });\n\t}\n\n\tlet originalLineIndex = 0;\n\tlet result = \"\";\n\tfor (const group of groups) {\n\t\tresult += originalLines.slice(originalLineIndex, group.startLine).join(\"\");\n\n\t\tconst groupStartOffset = baseLines[group.startLine].start;\n\t\tconst groupEndOffset = baseLines[group.endLine - 1].end;\n\t\tresult += applyReplacements(\n\t\t\tbaseContent.slice(groupStartOffset, groupEndOffset),\n\t\t\tgroup.replacements,\n\t\t\tgroupStartOffset,\n\t\t);\n\t\toriginalLineIndex = group.endLine;\n\t}\n\tresult += originalLines.slice(originalLineIndex).join(\"\");\n\n\treturn result;\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, return offsets in normalized space. Callers can use\n\t// the normalized content to compute replacements, then decide how much of\n\t// that normalized output should be written back.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\n\n/** Strip UTF-8 BOM if present, return both the BOM (if any) and the text without it */\nexport function stripBom(content: string): { bom: string; text: string } {\n\treturn content.startsWith(\"\\uFEFF\") ? { bom: \"\\uFEFF\", text: content.slice(1) } : { bom: \"\", text: content };\n}\n\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space and then\n * overlays those line-level changes onto the original content so unchanged line\n * blocks keep their original bytes.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst usedFuzzyMatch = initialMatches.some((match) => match.usedFuzzyMatch);\n\tconst replacementBaseContent = usedFuzzyMatch ? normalizeForFuzzyMatch(normalizedContent) : normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(replacementBaseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t}\n\n\t\tconst occurrences = countOccurrences(replacementBaseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: edit.newText,\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst baseContent = normalizedContent;\n\tconst newContent = usedFuzzyMatch\n\t\t? applyReplacementsPreservingUnchangedLines(normalizedContent, replacementBaseContent, matchedEdits)\n\t\t: applyReplacements(replacementBaseContent, matchedEdits);\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = stripBom(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], cwd);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit-diff.js","sourceRoot":"","sources":["../../../src/core/tools/edit-diff.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,UAAU,gBAAgB,CAAC,OAAe,EAAiB;IAChE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,CA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BAAiB,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAElG,oBAAoB;QACpB,OAAO,kBAAkB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACd,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACpE,CAAC;AAAA,CACD;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,IAAY,EACZ,OAAe,EACf,OAAe,EACf,GAAW,EAC+B;IAC1C,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;AAAA,CAC3D","sourcesContent":["/**\n * Shared diff computation utilities for the edit and similar tools.\n */\n\nimport * as Diff from \"diff\";\nimport { constants } from \"fs\";\nimport { access, readFile } from \"fs/promises\";\nimport { splitBom } from \"../../utils/text.ts\";\nimport { casarHuecoElidido } from \"../edicion/hueco.ts\";\nimport { limpiarCarga } from \"../edicion/limpiar-carga.ts\";\nimport { casarPorParecido } from \"../edicion/parecido.ts\";\nimport { casarIgnorandoSangria, coherenteConElBloque } from \"../edicion/sangria.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\n\nexport function detectLineEnding(content: string): \"\\r\\n\" | \"\\n\" {\n\tconst crlfIdx = content.indexOf(\"\\r\\n\");\n\tconst lfIdx = content.indexOf(\"\\n\");\n\tif (lfIdx === -1) return \"\\n\";\n\tif (crlfIdx === -1) return \"\\n\";\n\treturn crlfIdx < lfIdx ? \"\\r\\n\" : \"\\n\";\n}\n\nexport function normalizeToLF(text: string): string {\n\treturn text.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\");\n}\n\nexport function restoreLineEndings(text: string, ending: \"\\r\\n\" | \"\\n\"): string {\n\treturn ending === \"\\r\\n\" ? text.replace(/\\n/g, \"\\r\\n\") : text;\n}\n\n/**\n * Normalize text for fuzzy matching. Applies progressive transformations:\n * - Strip trailing whitespace from each line\n * - Normalize smart quotes to ASCII equivalents\n * - Normalize Unicode dashes/hyphens to ASCII hyphen\n * - Normalize special Unicode spaces to regular space\n */\n/**\n * NFKC, pero SOLO donde no cambia el número de caracteres.\n *\n * El texto normalizado no se usa únicamente para comparar. Cuando alguna\n * edición del lote necesita el camino difuso, `usedFuzzyMatch` es un `some()`\n * sobre TODAS (más abajo, en `applyEditsToNormalizedContent`), y esa forma\n * normalizada pasa a ser la base de escritura: `applyReplacementsPreservingUnchangedLines`\n * reescribe entonces cada línea del grupo tocado desde ella.\n *\n * Un `.normalize(\"NFKC\")` sobre el texto entero corrompía código que nadie\n * había pedido tocar. Medido sobre un fichero real, con dos ediciones en la\n * misma llamada —una difusa por comillas tipográficas, otra exacta en la línea\n * de abajo—:\n *\n * antes: const razon = compute(1) + \" ½ \";\n * después: const razon = compute(2) + \" 1⁄2 \";\n *\n * El disparador es cotidiano: comillas tipográficas o guiones largos en el\n * fichero y el modelo escribiendo los ASCII, que es lo normal en ficheros con\n * textos de interfaz.\n *\n * El corte está medido, no elegido a ojo. Las conversiones que aportan al\n * casado son 1:1 y se conservan:\n *\n * `,`→`,` `(`→`(` `A`→`A` `1`→`1` (ancho completo, 1 → 1)\n *\n * Las que corrompen cambian de longitud y se descartan:\n *\n * `½`→`1⁄2` (1 → 3) `fi`→`fi` (1 → 2) `e`+`◌́`→`é` (2 → 1)\n *\n * Lo que se pierde es casar formas descompuestas (`cafe`+acento combinante\n * contra `café`). Se acepta a propósito: es un caso estrecho frente a destruir\n * el fichero del usuario en silencio.\n *\n * SEGUNDA RAZÓN, y ahora es la principal: `applyReplacementsPreservingUnchangedLines`\n * traduce posiciones del texto normalizado a posiciones del original, y esa\n * traducción SOLO es válida si dentro de una línea las dos coordenadas\n * coinciden. Un NFKC completo rompería el mapeo (`½` ocupa 1 y `1⁄2` ocupa 3),\n * y con él el empalme sobre bytes originales. Mantener el 1:1 no es una\n * preferencia: es lo que hace correcta la función de traducción.\n *\n * Nota sobre por qué el 1:1 NO bastaba por sí solo, que es donde me equivoqué\n * primero: preservar la LONGITUD no es preservar el CONTENIDO. `“` y `\"` miden\n * lo mismo y son bytes distintos, así que restringir NFKC dejaba fuera el ½\n * pero seguía mutando comillas, guiones y espacios duros al escribir — y el\n * caso de las comillas produce un fichero que ni siquiera compila. Lo que\n * arregla eso es no escribir nunca desde el texto normalizado.\n */\nfunction nfkcCaracterAcaracter(text: string): string {\n\tlet salida = \"\";\n\tfor (const caracter of text) {\n\t\tconst normalizado = caracter.normalize(\"NFKC\");\n\t\tsalida += normalizado.length === caracter.length ? normalizado : caracter;\n\t}\n\treturn salida;\n}\n\nexport function normalizeForFuzzyMatch(text: string): string {\n\treturn (\n\t\tnfkcCaracterAcaracter(text)\n\t\t\t// Strip trailing whitespace per line\n\t\t\t.split(\"\\n\")\n\t\t\t.map((line) => line.trimEnd())\n\t\t\t.join(\"\\n\")\n\t\t\t// Smart single quotes → '\n\t\t\t.replace(/[\\u2018\\u2019\\u201A\\u201B]/g, \"'\")\n\t\t\t// Smart double quotes → \"\n\t\t\t.replace(/[\\u201C\\u201D\\u201E\\u201F]/g, '\"')\n\t\t\t// Various dashes/hyphens → -\n\t\t\t// U+2010 hyphen, U+2011 non-breaking hyphen, U+2012 figure dash,\n\t\t\t// U+2013 en-dash, U+2014 em-dash, U+2015 horizontal bar, U+2212 minus\n\t\t\t.replace(/[\\u2010\\u2011\\u2012\\u2013\\u2014\\u2015\\u2212]/g, \"-\")\n\t\t\t// Special spaces → regular space\n\t\t\t// U+00A0 NBSP, U+2002-U+200A various spaces, U+202F narrow NBSP,\n\t\t\t// U+205F medium math space, U+3000 ideographic space\n\t\t\t.replace(/[\\u00A0\\u2002-\\u200A\\u202F\\u205F\\u3000]/g, \" \")\n\t);\n}\n\nfunction splitLinesWithEndings(content: string): string[] {\n\treturn content.match(/[^\\n]*\\n|[^\\n]+/g) ?? [];\n}\n\ninterface LineSpan {\n\tstart: number;\n\tend: number;\n}\n\ninterface MatchedEdit {\n\teditIndex: number;\n\tmatchIndex: number;\n\tmatchLength: number;\n\tnewText: string;\n}\n\ntype TextReplacement = Pick<MatchedEdit, \"matchIndex\" | \"matchLength\" | \"newText\">;\n\nfunction getLineSpans(content: string): LineSpan[] {\n\tlet offset = 0;\n\treturn splitLinesWithEndings(content).map((line) => {\n\t\tconst span = { start: offset, end: offset + line.length };\n\t\toffset = span.end;\n\t\treturn span;\n\t});\n}\n\nfunction getReplacementLineRange(lines: LineSpan[], replacement: TextReplacement) {\n\tconst replacementStart = replacement.matchIndex;\n\tconst replacementEnd = replacement.matchIndex + replacement.matchLength;\n\n\tlet startLine = -1;\n\tfor (let i = 0; i < lines.length; i++) {\n\t\tconst line = lines[i];\n\t\tif (replacementStart >= line.start && replacementStart < line.end) {\n\t\t\tstartLine = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\tif (startLine === -1) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\tlet endLine = startLine;\n\twhile (endLine < lines.length && lines[endLine].end < replacementEnd) {\n\t\tendLine++;\n\t}\n\tif (endLine >= lines.length) {\n\t\tthrow new Error(\"Replacement range is outside the base content.\");\n\t}\n\n\treturn { startLine, endLine: endLine + 1 };\n}\n\nfunction applyReplacements(content: string, replacements: TextReplacement[], offset = 0): string {\n\tlet result = content;\n\tfor (let i = replacements.length - 1; i >= 0; i--) {\n\t\tconst replacement = replacements[i];\n\t\tconst matchIndex = replacement.matchIndex - offset;\n\t\tresult =\n\t\t\tresult.substring(0, matchIndex) + replacement.newText + result.substring(matchIndex + replacement.matchLength);\n\t}\n\treturn result;\n}\n\n/**\n * Apply replacements matched against `baseContent` to `originalContent` while\n * preserving unchanged line blocks from the original.\n *\n * This is useful when `baseContent` is a normalized view of the original. Each\n * replacement is widened to the lines it actually touches, those touched lines\n * are rewritten from the normalized base, and all other lines are copied back\n * from `originalContent`. The actual replacement ranges drive preservation so\n * duplicate normalized lines cannot be aligned to the wrong occurrence.\n */\nexport function applyReplacementsPreservingUnchangedLines(\n\toriginalContent: string,\n\tbaseContent: string,\n\treplacements: TextReplacement[],\n): string {\n\tconst originalLines = splitLinesWithEndings(originalContent);\n\tconst baseLines = getLineSpans(baseContent);\n\tif (originalLines.length !== baseLines.length) {\n\t\tthrow new Error(\"Cannot preserve unchanged lines because the base content has a different line count.\");\n\t}\n\n\tconst groups: Array<{ startLine: number; endLine: number; replacements: TextReplacement[] }> = [];\n\tconst sortedReplacements = [...replacements].sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (const replacement of sortedReplacements) {\n\t\tconst range = getReplacementLineRange(baseLines, replacement);\n\t\tconst current = groups[groups.length - 1];\n\t\tif (current && range.startLine < current.endLine) {\n\t\t\tcurrent.endLine = Math.max(current.endLine, range.endLine);\n\t\t\tcurrent.replacements.push(replacement);\n\t\t\tcontinue;\n\t\t}\n\t\tgroups.push({ ...range, replacements: [replacement] });\n\t}\n\n\t// Desplazamientos de inicio de cada línea en el ORIGINAL, para poder\n\t// traducir una posición del texto normalizado a su posición real.\n\tconst originalStarts: number[] = [];\n\t{\n\t\tlet acumulado = 0;\n\t\tfor (const linea of originalLines) {\n\t\t\toriginalStarts.push(acumulado);\n\t\t\tacumulado += linea.length;\n\t\t}\n\t}\n\n\t/**\n\t * De una posición en el texto normalizado a la misma posición en el\n\t * original.\n\t *\n\t * Dentro del TEXTO de una línea las dos coordenadas coinciden: todas las\n\t * sustituciones de `normalizeForFuzzyMatch` son de un carácter por otro\n\t * —incluido el NFKC, que ahora solo se aplica donde es 1:1— y lo único que\n\t * cambia la longitud es el recorte de espacios FINALES. Entre líneas sí\n\t * difieren, y por eso hay que ir línea a línea.\n\t *\n\t * PERO el recorte de espacios finales NO está «detrás de cualquier posición\n\t * que nos interese», que es lo que decía aquí y era falso: el LÍMITE de una\n\t * línea es una posición que interesa —la usan el final de un grupo y el\n\t * final de un reemplazo multilínea— y cae justo detrás del recorte. Sumar\n\t * el desplazamiento desde el principio dejaba esa posición DENTRO de la\n\t * línea original, tantos caracteres antes como espacios se hubieran\n\t * recortado. Medido, con dos ediciones en la misma llamada —una difusa por\n\t * comillas tipográficas y otra en una línea con tres espacios al final—:\n\t *\n\t * antes: const a = \"x\"; ⏎ const b = 1;\n\t * después: const a = \"z\"; const b = 1; ← dos líneas en una\n\t *\n\t * Se perdían los espacios finales y, con ellos, el SALTO DE LÍNEA que nadie\n\t * había pedido tocar. En JavaScript a veces sigue compilando; con un\n\t * comentario de línea delante se come la línea siguiente, y en Python o en\n\t * YAML destruye el fichero.\n\t *\n\t * Así que el límite se ancla al FINAL de la línea original y el resto sigue\n\t * anclado al principio. La posición del salto de línea (justo delante del\n\t * límite) se ancla también al principio a propósito: es donde acaba un\n\t * reemplazo que llega al final del TEXTO de la línea, y anclarla al final\n\t * se llevaría por delante los espacios que el modelo no ha nombrado.\n\t */\n\tfunction aOriginal(posicionNormalizada: number): number {\n\t\tfor (let i = 0; i < baseLines.length; i++) {\n\t\t\tconst linea = baseLines[i];\n\t\t\tif (posicionNormalizada >= linea.start && posicionNormalizada <= linea.end) {\n\t\t\t\tif (posicionNormalizada === linea.end) return originalStarts[i] + originalLines[i].length;\n\t\t\t\treturn originalStarts[i] + (posicionNormalizada - linea.start);\n\t\t\t}\n\t\t}\n\t\tthrow new Error(\"La posición normalizada cae fuera del contenido base.\");\n\t}\n\n\tlet originalLineIndex = 0;\n\tlet result = \"\";\n\tfor (const group of groups) {\n\t\tresult += originalLines.slice(originalLineIndex, group.startLine).join(\"\");\n\n\t\t// Se empalma sobre los BYTES ORIGINALES, no sobre la forma normalizada.\n\t\t//\n\t\t// Antes esta rama cortaba de `baseContent`, y eso reescribía cada línea\n\t\t// del grupo desde el texto normalizado. Consecuencia medida, con dos\n\t\t// ediciones en la misma llamada —una difusa, otra exacta en la línea de\n\t\t// abajo—:\n\t\t//\n\t\t// antes: const msg = \"el “titulo” va aqui\" + compute(1);\n\t\t// después: const msg = \"el \"titulo\" va aqui\" + compute(2);\n\t\t//\n\t\t// Nadie pidió tocar esas comillas, y el resultado ni siquiera compila:\n\t\t// quedan comillas rectas anidadas dentro de una cadena. Lo mismo pasaba\n\t\t// con `½` → `1⁄2`, con los guiones largos y con los espacios duros.\n\t\t//\n\t\t// La normalización es para CASAR. Restringirla a sustituciones de igual\n\t\t// longitud no basta: `“` y `\"` miden lo mismo y son bytes distintos, así\n\t\t// que \"preserva la longitud\" no es \"preserva el contenido\". Lo único que\n\t\t// lo garantiza es no escribir nunca desde el texto normalizado.\n\t\tconst inicioOriginal = aOriginal(baseLines[group.startLine].start);\n\t\tconst finOriginal = aOriginal(baseLines[group.endLine - 1].end);\n\t\tconst reubicadas = group.replacements.map((r) => ({\n\t\t\t...r,\n\t\t\tmatchIndex: aOriginal(r.matchIndex),\n\t\t\tmatchLength: aOriginal(r.matchIndex + r.matchLength) - aOriginal(r.matchIndex),\n\t\t}));\n\t\tresult += applyReplacements(originalContent.slice(inicioOriginal, finOriginal), reubicadas, inicioOriginal);\n\t\toriginalLineIndex = group.endLine;\n\t}\n\tresult += originalLines.slice(originalLineIndex).join(\"\");\n\n\treturn result;\n}\n\nexport interface FuzzyMatchResult {\n\t/** Whether a match was found */\n\tfound: boolean;\n\t/** The index where the match starts (in the content that should be used for replacement) */\n\tindex: number;\n\t/** Length of the matched text */\n\tmatchLength: number;\n\t/** Whether fuzzy matching was used (false = exact match) */\n\tusedFuzzyMatch: boolean;\n\t/**\n\t * The content to use for replacement operations.\n\t * When exact match: original content. When fuzzy match: normalized content.\n\t */\n\tcontentForReplacement: string;\n}\n\nexport interface Edit {\n\toldText: string;\n\tnewText: string;\n}\n\nexport interface AppliedEditsResult {\n\tbaseContent: string;\n\tnewContent: string;\n}\n\n/**\n * Find oldText in content, trying exact match first, then fuzzy match.\n * When fuzzy matching is used, the returned contentForReplacement is the\n * fuzzy-normalized version of the content (trailing whitespace stripped,\n * Unicode quotes/dashes normalized to ASCII).\n */\nexport function fuzzyFindText(content: string, oldText: string): FuzzyMatchResult {\n\t// Try exact match first\n\tconst exactIndex = content.indexOf(oldText);\n\tif (exactIndex !== -1) {\n\t\treturn {\n\t\t\tfound: true,\n\t\t\tindex: exactIndex,\n\t\t\tmatchLength: oldText.length,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// Try fuzzy match - work entirely in normalized space\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\tconst fuzzyIndex = fuzzyContent.indexOf(fuzzyOldText);\n\n\tif (fuzzyIndex === -1) {\n\t\treturn {\n\t\t\tfound: false,\n\t\t\tindex: -1,\n\t\t\tmatchLength: 0,\n\t\t\tusedFuzzyMatch: false,\n\t\t\tcontentForReplacement: content,\n\t\t};\n\t}\n\n\t// When fuzzy matching, return offsets in normalized space. Callers can use\n\t// the normalized content to compute replacements, then decide how much of\n\t// that normalized output should be written back.\n\treturn {\n\t\tfound: true,\n\t\tindex: fuzzyIndex,\n\t\tmatchLength: fuzzyOldText.length,\n\t\tusedFuzzyMatch: true,\n\t\tcontentForReplacement: fuzzyContent,\n\t};\n}\n\nfunction countOccurrences(content: string, oldText: string): number {\n\tconst fuzzyContent = normalizeForFuzzyMatch(content);\n\tconst fuzzyOldText = normalizeForFuzzyMatch(oldText);\n\treturn fuzzyContent.split(fuzzyOldText).length - 1;\n}\n\nfunction getNotFoundError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Could not find the exact text in ${path}. The old text must match exactly including all whitespace and newlines.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Could not find edits[${editIndex}] in ${path}. The oldText must match exactly including all whitespace and newlines.`,\n\t);\n}\n\nfunction getDuplicateError(path: string, editIndex: number, totalEdits: number, occurrences: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`Found ${occurrences} occurrences of the text in ${path}. The text must be unique. Please provide more context to make it unique.`,\n\t\t);\n\t}\n\treturn new Error(\n\t\t`Found ${occurrences} occurrences of edits[${editIndex}] in ${path}. Each oldText must be unique. Please provide more context to make it unique.`,\n\t);\n}\n\nfunction getEmptyOldTextError(path: string, editIndex: number, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(`oldText must not be empty in ${path}.`);\n\t}\n\treturn new Error(`edits[${editIndex}].oldText must not be empty in ${path}.`);\n}\n\nfunction getNoChangeError(path: string, totalEdits: number): Error {\n\tif (totalEdits === 1) {\n\t\treturn new Error(\n\t\t\t`No changes made to ${path}. The replacement produced identical content. This might indicate an issue with special characters or the text not existing as expected.`,\n\t\t);\n\t}\n\treturn new Error(`No changes made to ${path}. The replacements produced identical content.`);\n}\n\n/**\n * Apply one or more exact-text replacements to LF-normalized content.\n *\n * All edits are matched against the same original content. Replacements are\n * then applied in reverse order so offsets remain stable. If any edit needs\n * fuzzy matching, the operation runs in fuzzy-normalized content space and then\n * overlays those line-level changes onto the original content so unchanged line\n * blocks keep their original bytes.\n */\nexport function applyEditsToNormalizedContent(\n\tnormalizedContent: string,\n\tedits: Edit[],\n\tpath: string,\n): AppliedEditsResult {\n\tconst normalizedEdits = edits.map((edit) => ({\n\t\toldText: normalizeToLF(edit.oldText),\n\t\tnewText: normalizeToLF(edit.newText),\n\t}));\n\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tif (normalizedEdits[i].oldText.length === 0) {\n\t\t\tthrow getEmptyOldTextError(path, i, normalizedEdits.length);\n\t\t}\n\t}\n\n\tconst initialMatches = normalizedEdits.map((edit) => fuzzyFindText(normalizedContent, edit.oldText));\n\tconst usedFuzzyMatch = initialMatches.some((match) => match.usedFuzzyMatch);\n\tconst replacementBaseContent = usedFuzzyMatch ? normalizeForFuzzyMatch(normalizedContent) : normalizedContent;\n\n\tconst matchedEdits: MatchedEdit[] = [];\n\tfor (let i = 0; i < normalizedEdits.length; i++) {\n\t\tconst edit = normalizedEdits[i];\n\t\tconst matchResult = fuzzyFindText(replacementBaseContent, edit.oldText);\n\t\tif (!matchResult.found) {\n\t\t\t// Último intento antes de rechazar: casar ignorando la SANGRÍA.\n\t\t\t//\n\t\t\t// Es el error más frecuente que existe — Ada se indenta con tabuladores\n\t\t\t// y los modelos emiten espacios— y hasta ahora costaba un turno entero:\n\t\t\t// el modelo tenía que releer el fichero y reescribir el bloque a ciegas,\n\t\t\t// muchas veces repitiendo el mismo error.\n\t\t\t//\n\t\t\t// `casarIgnorandoSangria` devuelve `null` si el patrón sin sangría casa\n\t\t\t// en más de un sitio: quitar la sangría hace el patrón MENOS específico,\n\t\t\t// así que puede volver ambiguo algo que no lo era, y elegir por el\n\t\t\t// modelo cuál de los dos editar es peor que rechazar. Y re-sangra el\n\t\t\t// reemplazo con la sangría DEL FICHERO, no con la que mandó el modelo:\n\t\t\t// oh-my-pi casa más cargas que nosotros y de las diez que aplica, tres\n\t\t\t// corrompen, dos de ellas por esto. Aplicar no es aplicar bien.\n\t\t\tlet porSangria = casarIgnorandoSangria(replacementBaseContent, edit.oldText, edit.newText);\n\t\t\tif (!porSangria) {\n\t\t\t\t// Y antes de rendirse: quitarle al patrón el ruido que no es código.\n\t\t\t\t//\n\t\t\t\t// El caso más vergonzoso es el nuestro. `read` añade al final de lo\n\t\t\t\t// que devuelve `[Showing lines 1-5 of 5. Use offset=6 to continue.]`;\n\t\t\t\t// el modelo copia el bloque con la cabecera pegada y nosotros\n\t\t\t\t// rechazábamos la edición por «el texto no coincide exactamente».\n\t\t\t\t// Generábamos la contaminación y la castigábamos.\n\t\t\t\t//\n\t\t\t\t// `limpiarCarga` solo quita lo INEQUÍVOCO (vallas de markdown,\n\t\t\t\t// sentinelas de sobre, nuestra cabecera, y números de línea solo si\n\t\t\t\t// TODAS las líneas los llevan y van en orden). Preferimos dejar ruido\n\t\t\t\t// a borrar código: quitar de más casaría el patrón en el sitio\n\t\t\t\t// equivocado, y eso es corrupción silenciosa.\n\t\t\t\tconst limpia = limpiarCarga(edit.oldText);\n\t\t\t\tif (limpia.quitado.length > 0) {\n\t\t\t\t\tconst reintento = fuzzyFindText(replacementBaseContent, limpia.texto);\n\t\t\t\t\tif (reintento.found) {\n\t\t\t\t\t\tmatchedEdits.push({\n\t\t\t\t\t\t\teditIndex: i,\n\t\t\t\t\t\t\tmatchIndex: reintento.index,\n\t\t\t\t\t\t\tmatchLength: reintento.matchLength,\n\t\t\t\t\t\t\tnewText: coherenteConElBloque(\n\t\t\t\t\t\t\t\treplacementBaseContent.slice(reintento.index, reintento.index + reintento.matchLength),\n\t\t\t\t\t\t\t\tedit.newText,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tporSangria = casarIgnorandoSangria(replacementBaseContent, limpia.texto, edit.newText);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!porSangria) {\n\t\t\t\t// Y lo último: que el modelo haya elidido el medio con `...` entre dos\n\t\t\t\t// anclas, para no retipear lo que no cambia. `casarHuecoElidido`\n\t\t\t\t// compara las anclas con igualdad EXACTA de línea y exige que cada una\n\t\t\t\t// case en un solo sitio, porque este camino se traga líneas que el\n\t\t\t\t// modelo no ha nombrado: un fallo aquí no deja un espacio mal, borra\n\t\t\t\t// código.\n\t\t\t\tporSangria = casarHuecoElidido(replacementBaseContent, edit.oldText, edit.newText);\n\t\t\t}\n\t\t\tif (!porSangria) {\n\t\t\t\t// Último recurso: el modelo retecleó el contexto con una errata.\n\t\t\t\t//\n\t\t\t\t// Cuanto más contexto pedimos, más superficie tiene para equivocarse\n\t\t\t\t// en algo que no pretendía cambiar. `casarPorParecido` localiza por\n\t\t\t\t// similitud y —esto es lo que lo hace seguro— escribe la versión del\n\t\t\t\t// FICHERO en las líneas que el modelo solo estaba CITANDO. oh-my-pi\n\t\t\t\t// localiza igual pero escribe la errata, y su motor produce código que\n\t\t\t\t// no compila. Ver `core/edicion/parecido.ts`.\n\t\t\t\tconst porParecido = casarPorParecido(replacementBaseContent, edit.oldText, edit.newText);\n\t\t\t\tif (porParecido) {\n\t\t\t\t\tmatchedEdits.push({\n\t\t\t\t\t\teditIndex: i,\n\t\t\t\t\t\tmatchIndex: porParecido.indice,\n\t\t\t\t\t\tmatchLength: porParecido.longitud,\n\t\t\t\t\t\tnewText: porParecido.textoNuevo,\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tthrow getNotFoundError(path, i, normalizedEdits.length);\n\t\t\t}\n\t\t\tmatchedEdits.push({\n\t\t\t\teditIndex: i,\n\t\t\t\tmatchIndex: porSangria.indice,\n\t\t\t\tmatchLength: porSangria.longitud,\n\t\t\t\tnewText: porSangria.textoNuevo,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst occurrences = countOccurrences(replacementBaseContent, edit.oldText);\n\t\tif (occurrences > 1) {\n\t\t\tthrow getDuplicateError(path, i, normalizedEdits.length, occurrences);\n\t\t}\n\n\t\t// Coherencia de sangría, TAMBIÉN en el camino exacto.\n\t\t//\n\t\t// Cuando el `oldText` casa exacto, el `newText` se escribía tal cual y se\n\t\t// saltaba la lógica de sangría entera. Si el modelo teclea el bloque con\n\t\t// tabuladores en un fichero de espacios —cosa que hace constantemente— la\n\t\t// mezcla entraba sin que nadie la mirara. Medido: en Python es un\n\t\t// `TabError` y el fichero no arranca, y `parseo.ts` no cubre `.py`, así que\n\t\t// la red de reparación ni se despierta. Ver `edicion/sangria.ts`.\n\t\tconst trozoOriginal = replacementBaseContent.slice(\n\t\t\tmatchResult.index,\n\t\t\tmatchResult.index + matchResult.matchLength,\n\t\t);\n\t\tmatchedEdits.push({\n\t\t\teditIndex: i,\n\t\t\tmatchIndex: matchResult.index,\n\t\t\tmatchLength: matchResult.matchLength,\n\t\t\tnewText: coherenteConElBloque(trozoOriginal, edit.newText),\n\t\t});\n\t}\n\n\tmatchedEdits.sort((a, b) => a.matchIndex - b.matchIndex);\n\tfor (let i = 1; i < matchedEdits.length; i++) {\n\t\tconst previous = matchedEdits[i - 1];\n\t\tconst current = matchedEdits[i];\n\t\tif (previous.matchIndex + previous.matchLength > current.matchIndex) {\n\t\t\tthrow new Error(\n\t\t\t\t`edits[${previous.editIndex}] and edits[${current.editIndex}] overlap in ${path}. Merge them into one edit or target disjoint regions.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst baseContent = normalizedContent;\n\tconst newContent = usedFuzzyMatch\n\t\t? applyReplacementsPreservingUnchangedLines(normalizedContent, replacementBaseContent, matchedEdits)\n\t\t: applyReplacements(replacementBaseContent, matchedEdits);\n\n\tif (baseContent === newContent) {\n\t\tthrow getNoChangeError(path, normalizedEdits.length);\n\t}\n\n\treturn { baseContent, newContent };\n}\n\n/** Generate a standard unified patch. */\nexport function generateUnifiedPatch(path: string, oldContent: string, newContent: string, contextLines = 4): string {\n\treturn Diff.createTwoFilesPatch(path, path, oldContent, newContent, undefined, undefined, {\n\t\tcontext: contextLines,\n\t\theaderOptions: Diff.FILE_HEADERS_ONLY,\n\t});\n}\n\n/**\n * Generate a display-oriented diff string with line numbers and context.\n * Returns both the diff string and the first changed line number (in the new file).\n */\nexport function generateDiffString(\n\toldContent: string,\n\tnewContent: string,\n\tcontextLines = 4,\n): { diff: string; firstChangedLine: number | undefined } {\n\tconst parts = Diff.diffLines(oldContent, newContent);\n\tconst output: string[] = [];\n\n\tconst oldLines = oldContent.split(\"\\n\");\n\tconst newLines = newContent.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\tlet firstChangedLine: number | undefined;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Capture the first changed line (in the new file)\n\t\t\tif (firstChangedLine === undefined) {\n\t\t\t\tfirstChangedLine = newLineNum;\n\t\t\t}\n\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`+${lineNum} ${line}`);\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(`-${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\t\t\tconst hasLeadingChange = lastWasChange;\n\t\t\tconst hasTrailingChange = nextPartIsChange;\n\n\t\t\tif (hasLeadingChange && hasTrailingChange) {\n\t\t\t\tif (raw.length <= contextLines * 2) {\n\t\t\t\t\tfor (const line of raw) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tconst leadingLines = raw.slice(0, contextLines);\n\t\t\t\t\tconst trailingLines = raw.slice(raw.length - contextLines);\n\t\t\t\t\tconst skippedLines = raw.length - leadingLines.length - trailingLines.length;\n\n\t\t\t\t\tfor (const line of leadingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\n\t\t\t\t\tfor (const line of trailingLines) {\n\t\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\t\toldLineNum++;\n\t\t\t\t\t\tnewLineNum++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (hasLeadingChange) {\n\t\t\t\tconst shownLines = raw.slice(0, contextLines);\n\t\t\t\tconst skippedLines = raw.length - shownLines.length;\n\n\t\t\t\tfor (const line of shownLines) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\t\t\t} else if (hasTrailingChange) {\n\t\t\t\tconst skippedLines = Math.max(0, raw.length - contextLines);\n\t\t\t\tif (skippedLines > 0) {\n\t\t\t\t\toutput.push(` ${\"\".padStart(lineNumWidth, \" \")} ...`);\n\t\t\t\t\toldLineNum += skippedLines;\n\t\t\t\t\tnewLineNum += skippedLines;\n\t\t\t\t}\n\n\t\t\t\tfor (const line of raw.slice(skippedLines)) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(` ${lineNum} ${line}`);\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn { diff: output.join(\"\\n\"), firstChangedLine };\n}\n\nexport interface EditDiffResult {\n\tdiff: string;\n\tfirstChangedLine: number | undefined;\n}\n\nexport interface EditDiffError {\n\terror: string;\n}\n\n/**\n * Compute the diff for one or more edit operations without applying them.\n * Used for preview rendering in the TUI before the tool executes.\n */\nexport async function computeEditsDiff(\n\tpath: string,\n\tedits: Edit[],\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\tconst absolutePath = resolveToCwd(path, cwd);\n\n\ttry {\n\t\t// Check if file exists and is readable\n\t\ttry {\n\t\t\tawait access(absolutePath, constants.R_OK);\n\t\t} catch (error: unknown) {\n\t\t\tconst errorMessage = error instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\treturn { error: `Could not edit file: ${path}. ${errorMessage}.` };\n\t\t}\n\n\t\t// Read the file\n\t\tconst rawContent = await readFile(absolutePath, \"utf-8\");\n\n\t\t// Strip BOM before matching (LLM won't include invisible BOM in oldText)\n\t\tconst { text: content } = splitBom(rawContent);\n\t\tconst normalizedContent = normalizeToLF(content);\n\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\n\t\t// Generate the diff\n\t\treturn generateDiffString(baseContent, newContent);\n\t} catch (err) {\n\t\treturn { error: err instanceof Error ? err.message : String(err) };\n\t}\n}\n\n/**\n * Compute the diff for a single edit operation without applying it.\n * Kept as a convenience wrapper for single-edit callers.\n */\nexport async function computeEditDiff(\n\tpath: string,\n\toldText: string,\n\tnewText: string,\n\tcwd: string,\n): Promise<EditDiffResult | EditDiffError> {\n\treturn computeEditsDiff(path, [{ oldText, newText }], cwd);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.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AG,GAAG,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AA8IF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA0IjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) args.edits = parsed;\n\t\t} catch {}\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,GAAG,EAA2B,MAAM,wBAAwB,CAAC;AAGtE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAK5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EAKN,KAAK,aAAa,EAClB,KAAK,cAAc,EAKnB,MAAM,gBAAgB,CAAC;AAOxB,KAAK,WAAW,GAAG,cAAc,GAAG,aAAa,CAAC;AAElD,KAAK,eAAe,GAAG;IACtB,aAAa,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAaF,QAAA,MAAM,UAAU;;;;;;EASf,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;CAQnC,CAAC;AAEX,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAiBtD,MAAM,WAAW,eAAe;IAC/B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,qCAAqC;IACrC,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACpD,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,4DAA4D;IAC5D,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAChD;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AA6DD,KAAK,uBAAuB,GAAG,GAAG,GAAG;IACpC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AA8IF,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,EAAE,eAAe,CAAC,CA0IjF;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { splitBom } from \"../../utils/text.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { parsearJsonTolerante } from \"./json-tolerante.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn false;\n\t}\n\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array.\n\t// Others send a single edit object instead of a one-element edits array.\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\t// `parsearJsonTolerante` y no `JSON.parse`: la carga real de un modelo\n\t\t\t// trae TABULADORES CRUDOS dentro de los literales, el JSON los prohibe,\n\t\t\t// y el `catch` de abajo se tragaba ese error sin decir cual era. Medido:\n\t\t\t// 309 caracteres con 18 tabuladores, «Invalid control character», turno\n\t\t\t// perdido. Ver `json-tolerante.ts`, que explica por que vive en ESTE\n\t\t\t// paquete y no solo en `packages/ai`.\n\t\t\tconst parsed = parsearJsonTolerante(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = splitBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|
package/dist/core/tools/edit.js
CHANGED
|
@@ -3,9 +3,11 @@ import { constants } from "fs";
|
|
|
3
3
|
import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
5
|
import { renderDiff } from "../../modes/interactive/components/diff.js";
|
|
6
|
+
import { splitBom } from "../../utils/text.js";
|
|
6
7
|
import { getExperimentalToolSampling } from "../experimental.js";
|
|
7
|
-
import { applyEditsToNormalizedContent, computeEditsDiff, detectLineEnding, generateDiffString, generateUnifiedPatch, normalizeToLF, restoreLineEndings,
|
|
8
|
+
import { applyEditsToNormalizedContent, computeEditsDiff, detectLineEnding, generateDiffString, generateUnifiedPatch, normalizeToLF, restoreLineEndings, } from "./edit-diff.js";
|
|
8
9
|
import { withFileMutationQueue } from "./file-mutation-queue.js";
|
|
10
|
+
import { parsearJsonTolerante } from "./json-tolerante.js";
|
|
9
11
|
import { resolveToCwd } from "./path-utils.js";
|
|
10
12
|
import { renderToolPath, str } from "./render-utils.js";
|
|
11
13
|
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
@@ -30,6 +32,13 @@ export const editToolSystemPromptContribution = {
|
|
|
30
32
|
"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.",
|
|
31
33
|
],
|
|
32
34
|
};
|
|
35
|
+
function isSingleEditInput(value) {
|
|
36
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const edit = value;
|
|
40
|
+
return typeof edit.oldText === "string" && typeof edit.newText === "string";
|
|
41
|
+
}
|
|
33
42
|
const defaultEditOperations = {
|
|
34
43
|
readFile: (path) => fsReadFile(path),
|
|
35
44
|
writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
|
|
@@ -40,15 +49,29 @@ function prepareEditArguments(input) {
|
|
|
40
49
|
return input;
|
|
41
50
|
}
|
|
42
51
|
const args = input;
|
|
43
|
-
// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array
|
|
52
|
+
// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array.
|
|
53
|
+
// Others send a single edit object instead of a one-element edits array.
|
|
44
54
|
if (typeof args.edits === "string") {
|
|
45
55
|
try {
|
|
46
|
-
|
|
47
|
-
|
|
56
|
+
// `parsearJsonTolerante` y no `JSON.parse`: la carga real de un modelo
|
|
57
|
+
// trae TABULADORES CRUDOS dentro de los literales, el JSON los prohibe,
|
|
58
|
+
// y el `catch` de abajo se tragaba ese error sin decir cual era. Medido:
|
|
59
|
+
// 309 caracteres con 18 tabuladores, «Invalid control character», turno
|
|
60
|
+
// perdido. Ver `json-tolerante.ts`, que explica por que vive en ESTE
|
|
61
|
+
// paquete y no solo en `packages/ai`.
|
|
62
|
+
const parsed = parsearJsonTolerante(args.edits);
|
|
63
|
+
if (Array.isArray(parsed)) {
|
|
48
64
|
args.edits = parsed;
|
|
65
|
+
}
|
|
66
|
+
else if (isSingleEditInput(parsed)) {
|
|
67
|
+
args.edits = [parsed];
|
|
68
|
+
}
|
|
49
69
|
}
|
|
50
70
|
catch { }
|
|
51
71
|
}
|
|
72
|
+
else if (isSingleEditInput(args.edits)) {
|
|
73
|
+
args.edits = [args.edits];
|
|
74
|
+
}
|
|
52
75
|
const legacy = args;
|
|
53
76
|
if (typeof legacy.oldText !== "string" || typeof legacy.newText !== "string") {
|
|
54
77
|
return args;
|
|
@@ -205,7 +228,7 @@ export function createEditToolDefinition(cwd, options) {
|
|
|
205
228
|
const rawContent = buffer.toString("utf-8");
|
|
206
229
|
throwIfAborted();
|
|
207
230
|
// Strip BOM before matching. The model will not include an invisible BOM in oldText.
|
|
208
|
-
const { bom, text: content } =
|
|
231
|
+
const { bom, text: content } = splitBom(rawContent);
|
|
209
232
|
const originalEnding = detectLineEnding(content);
|
|
210
233
|
const normalizedContent = normalizeToLF(content);
|
|
211
234
|
const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAIhB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,QAAQ,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC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CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n\tstripBom,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(args.edits);\n\t\t\tif (Array.isArray(parsed)) args.edits = parsed;\n\t\t} catch {}\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = stripBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"edit.js","sourceRoot":"","sources":["../../../src/core/tools/edit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC/B,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,QAAQ,IAAI,UAAU,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACnG,OAAO,EAAe,IAAI,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,EAChB,gBAAgB,EAIhB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAQlE,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CACpC;IACC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACpB,WAAW,EACV,uJ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,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YAC3G,MAAM,SAAS,GAAI,OAAO,CAAC,aAAuC,IAAI,IAAI,SAAS,EAAE,CAAC;YACtF,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,OAAO,SAAS,CAAC;YAClB,CAAC;YACD,SAAS,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO,SAAS,CAAC;QAAA,CACjB;KACD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,OAAyB,EAAgC;IACpG,OAAO,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { Box, Container, Spacer, Text } from \"@earendil-works/pi-tui\";\nimport { constants } from \"fs\";\nimport { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from \"fs/promises\";\nimport { type Static, Type } from \"typebox\";\nimport { renderDiff } from \"../../modes/interactive/components/diff.ts\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { splitBom } from \"../../utils/text.ts\";\nimport { getExperimentalToolSampling } from \"../experimental.ts\";\nimport type { ToolDefinition } from \"../extensions/types.ts\";\nimport {\n\tapplyEditsToNormalizedContent,\n\tcomputeEditsDiff,\n\tdetectLineEnding,\n\ttype Edit,\n\ttype EditDiffError,\n\ttype EditDiffResult,\n\tgenerateDiffString,\n\tgenerateUnifiedPatch,\n\tnormalizeToLF,\n\trestoreLineEndings,\n} from \"./edit-diff.ts\";\nimport { withFileMutationQueue } from \"./file-mutation-queue.ts\";\nimport { parsearJsonTolerante } from \"./json-tolerante.ts\";\nimport { resolveToCwd } from \"./path-utils.ts\";\nimport { renderToolPath, str } from \"./render-utils.ts\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.ts\";\n\ntype EditPreview = EditDiffResult | EditDiffError;\n\ntype EditRenderState = {\n\tcallComponent?: EditCallRenderComponent;\n};\n\nconst replaceEditSchema = Type.Object(\n\t{\n\t\toldText: Type.String({\n\t\t\tdescription:\n\t\t\t\t\"Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.\",\n\t\t}),\n\t\tnewText: Type.String({ description: \"Replacement text for this targeted edit.\" }),\n\t},\n\t{},\n);\n\nconst editSchema = Type.Object(\n\t{\n\t\tpath: Type.String({ description: \"Path to the file to edit (relative or absolute)\" }),\n\t\tedits: Type.Array(replaceEditSchema, {\n\t\t\tdescription:\n\t\t\t\t\"One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.\",\n\t\t}),\n\t},\n\t{},\n);\n\nexport const editToolSystemPromptContribution = {\n\tsnippet: \"Make precise file edits with exact text replacement, including multiple disjoint edits in one call\",\n\tguidelines: [\n\t\t\"Use edit for precise changes (edits[].oldText must match exactly)\",\n\t\t\"When changing multiple separate locations in one file, use one edit call with multiple entries in edits[] instead of multiple edit calls\",\n\t\t\"Each edits[].oldText is matched against the original file, not after earlier edits are applied. Do not emit overlapping or nested edits. Merge nearby changes into one edit.\",\n\t\t\"Keep edits[].oldText as small as possible while still being unique in the file. Do not pad with large unchanged regions.\",\n\t],\n} as const;\n\nexport type EditToolInput = Static<typeof editSchema>;\ntype LegacyEditToolInput = EditToolInput & {\n\toldText?: unknown;\n\tnewText?: unknown;\n};\n\ntype SingleEditInput = { oldText: string; newText: string };\n\nfunction isSingleEditInput(value: unknown): value is SingleEditInput {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn false;\n\t}\n\n\tconst edit = value as Record<string, unknown>;\n\treturn typeof edit.oldText === \"string\" && typeof edit.newText === \"string\";\n}\n\nexport interface EditToolDetails {\n\t/** Display-oriented diff of the changes made */\n\tdiff: string;\n\t/** Standard unified patch of the changes made */\n\tpatch: string;\n\t/** Line number of the first change in the new file (for editor navigation) */\n\tfirstChangedLine?: number;\n}\n\n/**\n * Pluggable operations for the edit tool.\n * Override these to delegate file editing to remote systems (for example SSH).\n */\nexport interface EditOperations {\n\t/** Read file contents as a Buffer */\n\treadFile: (absolutePath: string) => Promise<Buffer>;\n\t/** Write content to a file */\n\twriteFile: (absolutePath: string, content: string) => Promise<void>;\n\t/** Check if file is readable and writable (throw if not) */\n\taccess: (absolutePath: string) => Promise<void>;\n}\n\nconst defaultEditOperations: EditOperations = {\n\treadFile: (path) => fsReadFile(path),\n\twriteFile: (path, content) => fsWriteFile(path, content, \"utf-8\"),\n\taccess: (path) => fsAccess(path, constants.R_OK | constants.W_OK),\n};\n\nexport interface EditToolOptions {\n\t/** Custom operations for file editing. Default: local filesystem */\n\toperations?: EditOperations;\n}\n\nfunction prepareEditArguments(input: unknown): EditToolInput {\n\tif (!input || typeof input !== \"object\") {\n\t\treturn input as EditToolInput;\n\t}\n\n\tconst args = input as Record<string, unknown>;\n\n\t// Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array.\n\t// Others send a single edit object instead of a one-element edits array.\n\tif (typeof args.edits === \"string\") {\n\t\ttry {\n\t\t\t// `parsearJsonTolerante` y no `JSON.parse`: la carga real de un modelo\n\t\t\t// trae TABULADORES CRUDOS dentro de los literales, el JSON los prohibe,\n\t\t\t// y el `catch` de abajo se tragaba ese error sin decir cual era. Medido:\n\t\t\t// 309 caracteres con 18 tabuladores, «Invalid control character», turno\n\t\t\t// perdido. Ver `json-tolerante.ts`, que explica por que vive en ESTE\n\t\t\t// paquete y no solo en `packages/ai`.\n\t\t\tconst parsed = parsearJsonTolerante(args.edits);\n\t\t\tif (Array.isArray(parsed)) {\n\t\t\t\targs.edits = parsed;\n\t\t\t} else if (isSingleEditInput(parsed)) {\n\t\t\t\targs.edits = [parsed];\n\t\t\t}\n\t\t} catch {}\n\t} else if (isSingleEditInput(args.edits)) {\n\t\targs.edits = [args.edits];\n\t}\n\n\tconst legacy = args as LegacyEditToolInput;\n\tif (typeof legacy.oldText !== \"string\" || typeof legacy.newText !== \"string\") {\n\t\treturn args as EditToolInput;\n\t}\n\n\tconst edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];\n\tedits.push({ oldText: legacy.oldText, newText: legacy.newText });\n\tconst { oldText: _oldText, newText: _newText, ...rest } = legacy;\n\treturn { ...rest, edits } as EditToolInput;\n}\n\nfunction validateEditInput(input: EditToolInput): { path: string; edits: Edit[] } {\n\tif (!Array.isArray(input.edits) || input.edits.length === 0) {\n\t\tthrow new Error(\"Edit tool input is invalid. edits must contain at least one replacement.\");\n\t}\n\treturn { path: input.path, edits: input.edits };\n}\n\ntype RenderableEditArgs = {\n\tpath?: string;\n\tfile_path?: string;\n\tedits?: Edit[];\n\toldText?: string;\n\tnewText?: string;\n};\n\ntype EditToolResultLike = {\n\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\tdetails?: EditToolDetails;\n};\n\ntype EditCallRenderComponent = Box & {\n\tpreview?: EditPreview;\n\tpreviewArgsKey?: string;\n\tpreviewPending?: boolean;\n\tsettledError?: boolean;\n};\n\nfunction createEditCallRenderComponent(): EditCallRenderComponent {\n\treturn Object.assign(new Box(1, 1, (text: string) => text), {\n\t\tpreview: undefined as EditPreview | undefined,\n\t\tpreviewArgsKey: undefined as string | undefined,\n\t\tpreviewPending: false,\n\t\tsettledError: false,\n\t});\n}\n\nfunction getEditCallRenderComponent(state: EditRenderState, lastComponent: unknown): EditCallRenderComponent {\n\tif (lastComponent instanceof Box) {\n\t\tconst component = lastComponent as EditCallRenderComponent;\n\t\tstate.callComponent = component;\n\t\treturn component;\n\t}\n\tif (state.callComponent) {\n\t\treturn state.callComponent;\n\t}\n\tconst component = createEditCallRenderComponent();\n\tstate.callComponent = component;\n\treturn component;\n}\n\nfunction getRenderablePreviewInput(args: RenderableEditArgs | undefined): { path: string; edits: Edit[] } | null {\n\tif (!args) {\n\t\treturn null;\n\t}\n\n\tconst path = typeof args.path === \"string\" ? args.path : typeof args.file_path === \"string\" ? args.file_path : null;\n\tif (!path) {\n\t\treturn null;\n\t}\n\n\tif (\n\t\tArray.isArray(args.edits) &&\n\t\targs.edits.length > 0 &&\n\t\targs.edits.every((edit) => typeof edit?.oldText === \"string\" && typeof edit?.newText === \"string\")\n\t) {\n\t\treturn { path, edits: args.edits };\n\t}\n\n\tif (typeof args.oldText === \"string\" && typeof args.newText === \"string\") {\n\t\treturn { path, edits: [{ oldText: args.oldText, newText: args.newText }] };\n\t}\n\n\treturn null;\n}\n\nfunction formatEditCall(args: RenderableEditArgs | undefined, theme: Theme, cwd: string): string {\n\tconst pathDisplay = renderToolPath(str(args?.file_path ?? args?.path), theme, cwd);\n\treturn `${theme.fg(\"toolTitle\", theme.bold(\"edit\"))} ${pathDisplay}`;\n}\n\nfunction formatEditResult(\n\targs: RenderableEditArgs | undefined,\n\tpreview: EditPreview | undefined,\n\tresult: EditToolResultLike,\n\ttheme: Theme,\n\tisError: boolean,\n): string | undefined {\n\tconst rawPath = str(args?.file_path ?? args?.path);\n\tconst previewDiff = preview && !(\"error\" in preview) ? preview.diff : undefined;\n\tconst previewError = preview && \"error\" in preview ? preview.error : undefined;\n\tif (isError) {\n\t\tconst errorText = result.content\n\t\t\t.filter((c) => c.type === \"text\")\n\t\t\t.map((c) => c.text || \"\")\n\t\t\t.join(\"\\n\");\n\t\tif (!errorText || errorText === previewError) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn theme.fg(\"error\", errorText);\n\t}\n\n\tconst resultDiff = result.details?.diff;\n\tif (resultDiff && resultDiff !== previewDiff) {\n\t\treturn renderDiff(resultDiff, { filePath: rawPath ?? undefined });\n\t}\n\n\treturn undefined;\n}\n\nfunction getEditHeaderBg(\n\tpreview: EditPreview | undefined,\n\tsettledError: boolean | undefined,\n\ttheme: Theme,\n): (text: string) => string {\n\tif (preview) {\n\t\tif (\"error\" in preview) {\n\t\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t\t}\n\t\treturn (text: string) => theme.bg(\"toolSuccessBg\", text);\n\t}\n\tif (settledError) {\n\t\treturn (text: string) => theme.bg(\"toolErrorBg\", text);\n\t}\n\treturn (text: string) => theme.bg(\"toolPendingBg\", text);\n}\n\nfunction buildEditCallComponent(\n\tcomponent: EditCallRenderComponent,\n\targs: RenderableEditArgs | undefined,\n\ttheme: Theme,\n\tcwd: string,\n): EditCallRenderComponent {\n\tcomponent.setBgFn(getEditHeaderBg(component.preview, component.settledError, theme));\n\tcomponent.clear();\n\tcomponent.addChild(new Text(formatEditCall(args, theme, cwd), 0, 0));\n\n\tif (!component.preview) {\n\t\treturn component;\n\t}\n\n\tconst body =\n\t\t\"error\" in component.preview ? theme.fg(\"error\", component.preview.error) : renderDiff(component.preview.diff);\n\tcomponent.addChild(new Spacer(1));\n\tcomponent.addChild(new Text(body, 0, 0));\n\treturn component;\n}\n\nfunction setEditPreview(\n\tcomponent: EditCallRenderComponent,\n\tpreview: EditPreview,\n\targsKey: string | undefined,\n): boolean {\n\tconst current = component.preview;\n\tconst changed =\n\t\tcurrent === undefined ||\n\t\t(\"error\" in current && \"error\" in preview\n\t\t\t? current.error !== preview.error\n\t\t\t: \"error\" in current !== \"error\" in preview) ||\n\t\t(!(\"error\" in current) &&\n\t\t\t!(\"error\" in preview) &&\n\t\t\t(current.diff !== preview.diff || current.firstChangedLine !== preview.firstChangedLine));\n\tcomponent.preview = preview;\n\tcomponent.previewArgsKey = argsKey;\n\tcomponent.previewPending = false;\n\treturn changed;\n}\n\nexport function createEditToolDefinition(\n\tcwd: string,\n\toptions?: EditToolOptions,\n): ToolDefinition<typeof editSchema, EditToolDetails | undefined, EditRenderState> {\n\tconst ops = options?.operations ?? defaultEditOperations;\n\treturn {\n\t\tname: \"edit\",\n\t\tlabel: \"edit\",\n\t\tdescription:\n\t\t\t\"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.\",\n\t\tpromptSnippet: editToolSystemPromptContribution.snippet,\n\t\tpromptGuidelines: [...editToolSystemPromptContribution.guidelines],\n\t\tparameters: editSchema,\n\t\tconstrainedSampling: getExperimentalToolSampling(),\n\t\trenderShell: \"self\",\n\t\tprepareArguments: prepareEditArguments,\n\t\tasync execute(_toolCallId, input: EditToolInput, signal?: AbortSignal, _onUpdate?, _ctx?) {\n\t\t\tconst { path, edits } = validateEditInput(input);\n\t\t\tconst absolutePath = resolveToCwd(path, cwd);\n\n\t\t\treturn withFileMutationQueue(absolutePath, async () => {\n\t\t\t\t// Do not reject from an abort event listener here: that would release the\n\t\t\t\t// mutation queue while an in-flight filesystem operation may still finish.\n\t\t\t\t// Checking signal.aborted after each await observes the same aborts while\n\t\t\t\t// keeping the queue locked until the current operation has settled.\n\t\t\t\tconst throwIfAborted = (): void => {\n\t\t\t\t\tif (signal?.aborted) throw new Error(\"Operation aborted\");\n\t\t\t\t};\n\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Check if file exists.\n\t\t\t\ttry {\n\t\t\t\t\tawait ops.access(absolutePath);\n\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\tthrowIfAborted();\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\terror instanceof Error && \"code\" in error ? `Error code: ${error.code}` : String(error);\n\t\t\t\t\tthrow new Error(`Could not edit file: ${path}. ${errorMessage}.`);\n\t\t\t\t}\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Read the file.\n\t\t\t\tconst buffer = await ops.readFile(absolutePath);\n\t\t\t\tconst rawContent = buffer.toString(\"utf-8\");\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\t// Strip BOM before matching. The model will not include an invisible BOM in oldText.\n\t\t\t\tconst { bom, text: content } = splitBom(rawContent);\n\t\t\t\tconst originalEnding = detectLineEnding(content);\n\t\t\t\tconst normalizedContent = normalizeToLF(content);\n\t\t\t\tconst { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst finalContent = bom + restoreLineEndings(newContent, originalEnding);\n\t\t\t\tawait ops.writeFile(absolutePath, finalContent);\n\t\t\t\tthrowIfAborted();\n\n\t\t\t\tconst diffResult = generateDiffString(baseContent, newContent);\n\t\t\t\tconst patch = generateUnifiedPatch(path, baseContent, newContent);\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: `Successfully replaced ${edits.length} block(s) in ${path}.`,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { diff: diffResult.diff, patch, firstChangedLine: diffResult.firstChangedLine },\n\t\t\t\t};\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst component = getEditCallRenderComponent(context.state, context.lastComponent);\n\t\t\tconst previewInput = getRenderablePreviewInput(args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\n\t\t\tif (component.previewArgsKey !== argsKey) {\n\t\t\t\tcomponent.preview = undefined;\n\t\t\t\tcomponent.previewArgsKey = argsKey;\n\t\t\t\tcomponent.previewPending = false;\n\t\t\t\tcomponent.settledError = false;\n\t\t\t}\n\n\t\t\tif (context.argsComplete && previewInput && !component.preview && !component.previewPending) {\n\t\t\t\tcomponent.previewPending = true;\n\t\t\t\tconst requestKey = argsKey;\n\t\t\t\tvoid computeEditsDiff(previewInput.path, previewInput.edits, context.cwd).then((preview) => {\n\t\t\t\t\tif (component.previewArgsKey === requestKey) {\n\t\t\t\t\t\tsetEditPreview(component, preview, requestKey);\n\t\t\t\t\t\tcontext.invalidate();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn buildEditCallComponent(component, args, theme, context.cwd);\n\t\t},\n\t\trenderResult(result, _options, theme, context) {\n\t\t\tconst callComponent = context.state.callComponent;\n\t\t\tconst previewInput = getRenderablePreviewInput(context.args as RenderableEditArgs | undefined);\n\t\t\tconst argsKey = previewInput\n\t\t\t\t? JSON.stringify({ path: previewInput.path, edits: previewInput.edits })\n\t\t\t\t: undefined;\n\t\t\tconst typedResult = result as EditToolResultLike;\n\t\t\tconst resultDiff = !context.isError ? typedResult.details?.diff : undefined;\n\t\t\tlet changed = false;\n\t\t\tif (callComponent) {\n\t\t\t\tif (typeof resultDiff === \"string\") {\n\t\t\t\t\tchanged =\n\t\t\t\t\t\tsetEditPreview(\n\t\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\t\t{ diff: resultDiff, firstChangedLine: typedResult.details?.firstChangedLine },\n\t\t\t\t\t\t\targsKey,\n\t\t\t\t\t\t) || changed;\n\t\t\t\t}\n\t\t\t\tif (callComponent.settledError !== context.isError) {\n\t\t\t\t\tcallComponent.settledError = context.isError;\n\t\t\t\t\tchanged = true;\n\t\t\t\t}\n\t\t\t\tif (changed) {\n\t\t\t\t\tbuildEditCallComponent(\n\t\t\t\t\t\tcallComponent,\n\t\t\t\t\t\tcontext.args as RenderableEditArgs | undefined,\n\t\t\t\t\t\ttheme,\n\t\t\t\t\t\tcontext.cwd,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst output = formatEditResult(context.args, callComponent?.preview, typedResult, theme, context.isError);\n\t\t\tconst component = (context.lastComponent as Container | undefined) ?? new Container();\n\t\t\tcomponent.clear();\n\t\t\tif (!output) {\n\t\t\t\treturn component;\n\t\t\t}\n\t\t\tcomponent.addChild(new Spacer(1));\n\t\t\tcomponent.addChild(new Text(output, 1, 0));\n\t\t\treturn component;\n\t\t},\n\t};\n}\n\nexport function createEditTool(cwd: string, options?: EditToolOptions): AgentTool<typeof editSchema> {\n\treturn wrapToolDefinition(createEditToolDefinition(cwd, options));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-mutation-queue.d.ts","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"AA4BA;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAiCjG","sourcesContent":["import { realpath } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { registrarPrevio } from \"../undo/journal.ts\";\n\nconst fileMutationQueues = new Map<string, Promise<void>>();\nlet registrationQueue = Promise.resolve();\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n\t);\n}\n\nasync function getMutationQueueKey(filePath: string): Promise<string> {\n\tconst resolvedPath = resolve(filePath);\n\ttry {\n\t\treturn await realpath(resolvedPath);\n\t} catch (error) {\n\t\tif (isMissingPathError(error)) {\n\t\t\treturn resolvedPath;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Serialize file mutation operations targeting the same file.\n * Operations for different files still run in parallel.\n */\nexport async function withFileMutationQueue<T>(filePath: string, fn: () => Promise<T>): Promise<T> {\n\t// Foto del estado anterior para `ada-cli undo`. Se engancha aquí porque es\n\t// el punto único por el que pasan `edit` y `write` — y por el que pasará\n\t// cualquier herramienta futura que escriba ficheros.\n\tregistrarPrevio(resolve(filePath));\n\tconst registration = registrationQueue.then(async () => {\n\t\tconst key = await getMutationQueueKey(filePath);\n\t\tconst currentQueue = fileMutationQueues.get(key) ?? Promise.resolve();\n\n\t\tlet releaseNext!: () => void;\n\t\tconst nextQueue = new Promise<void>((resolveQueue) => {\n\t\t\treleaseNext = resolveQueue;\n\t\t});\n\t\tconst chainedQueue = currentQueue.then(() => nextQueue);\n\t\tfileMutationQueues.set(key, chainedQueue);\n\n\t\treturn { key, currentQueue, chainedQueue, releaseNext };\n\t});\n\tregistrationQueue = registration.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\n\tconst { key, currentQueue, chainedQueue, releaseNext } = await registration;\n\tawait currentQueue;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\treleaseNext();\n\t\tif (fileMutationQueues.get(key) === chainedQueue) {\n\t\t\tfileMutationQueues.delete(key);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { realpath } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
+
import { registrarPrevio } from "../undo/journal.js";
|
|
3
4
|
const fileMutationQueues = new Map();
|
|
4
5
|
let registrationQueue = Promise.resolve();
|
|
5
6
|
function isMissingPathError(error) {
|
|
@@ -25,6 +26,10 @@ async function getMutationQueueKey(filePath) {
|
|
|
25
26
|
* Operations for different files still run in parallel.
|
|
26
27
|
*/
|
|
27
28
|
export async function withFileMutationQueue(filePath, fn) {
|
|
29
|
+
// Foto del estado anterior para `ada-cli undo`. Se engancha aquí porque es
|
|
30
|
+
// el punto único por el que pasan `edit` y `write` — y por el que pasará
|
|
31
|
+
// cualquier herramienta futura que escriba ficheros.
|
|
32
|
+
registrarPrevio(resolve(filePath));
|
|
28
33
|
const registration = registrationQueue.then(async () => {
|
|
29
34
|
const key = await getMutationQueueKey(filePath);
|
|
30
35
|
const currentQueue = fileMutationQueues.get(key) ?? Promise.resolve();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-mutation-queue.js","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"file-mutation-queue.js","sourceRoot":"","sources":["../../../src/core/tools/file-mutation-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAyB,CAAC;AAC5D,IAAI,iBAAiB,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;AAE1C,SAAS,kBAAkB,CAAC,KAAc,EAAW;IACpD,OAAO,CACN,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,CAAC,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CACrD,CAAC;AAAA,CACF;AAED,KAAK,UAAU,mBAAmB,CAAC,QAAgB,EAAmB;IACrE,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,CAAC;QACJ,OAAO,MAAM,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AAAA,CACD;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAI,QAAgB,EAAE,EAAoB,EAAc;IAClG,4EAA2E;IAC3E,6EAAyE;IACzE,qDAAqD;IACrD,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnC,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;QACvD,MAAM,GAAG,GAAG,MAAM,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAChD,MAAM,YAAY,GAAG,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAEtE,IAAI,WAAwB,CAAC;QAC7B,MAAM,SAAS,GAAG,IAAI,OAAO,CAAO,CAAC,YAAY,EAAE,EAAE,CAAC;YACrD,WAAW,GAAG,YAAY,CAAC;QAAA,CAC3B,CAAC,CAAC;QACH,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QACxD,kBAAkB,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAE1C,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;IAAA,CACxD,CAAC,CAAC;IACH,iBAAiB,GAAG,YAAY,CAAC,IAAI,CACpC,GAAG,EAAE,CAAC,SAAS,EACf,GAAG,EAAE,CAAC,SAAS,CACf,CAAC;IAEF,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,YAAY,CAAC;IAC5E,MAAM,YAAY,CAAC;IACnB,IAAI,CAAC;QACJ,OAAO,MAAM,EAAE,EAAE,CAAC;IACnB,CAAC;YAAS,CAAC;QACV,WAAW,EAAE,CAAC;QACd,IAAI,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,YAAY,EAAE,CAAC;YAClD,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;AAAA,CACD","sourcesContent":["import { realpath } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { registrarPrevio } from \"../undo/journal.ts\";\n\nconst fileMutationQueues = new Map<string, Promise<void>>();\nlet registrationQueue = Promise.resolve();\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn (\n\t\ttypeof error === \"object\" &&\n\t\terror !== null &&\n\t\t\"code\" in error &&\n\t\t(error.code === \"ENOENT\" || error.code === \"ENOTDIR\")\n\t);\n}\n\nasync function getMutationQueueKey(filePath: string): Promise<string> {\n\tconst resolvedPath = resolve(filePath);\n\ttry {\n\t\treturn await realpath(resolvedPath);\n\t} catch (error) {\n\t\tif (isMissingPathError(error)) {\n\t\t\treturn resolvedPath;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * Serialize file mutation operations targeting the same file.\n * Operations for different files still run in parallel.\n */\nexport async function withFileMutationQueue<T>(filePath: string, fn: () => Promise<T>): Promise<T> {\n\t// Foto del estado anterior para `ada-cli undo`. Se engancha aquí porque es\n\t// el punto único por el que pasan `edit` y `write` — y por el que pasará\n\t// cualquier herramienta futura que escriba ficheros.\n\tregistrarPrevio(resolve(filePath));\n\tconst registration = registrationQueue.then(async () => {\n\t\tconst key = await getMutationQueueKey(filePath);\n\t\tconst currentQueue = fileMutationQueues.get(key) ?? Promise.resolve();\n\n\t\tlet releaseNext!: () => void;\n\t\tconst nextQueue = new Promise<void>((resolveQueue) => {\n\t\t\treleaseNext = resolveQueue;\n\t\t});\n\t\tconst chainedQueue = currentQueue.then(() => nextQueue);\n\t\tfileMutationQueues.set(key, chainedQueue);\n\n\t\treturn { key, currentQueue, chainedQueue, releaseNext };\n\t});\n\tregistrationQueue = registration.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t);\n\n\tconst { key, currentQueue, chainedQueue, releaseNext } = await registration;\n\tawait currentQueue;\n\ttry {\n\t\treturn await fn();\n\t} finally {\n\t\treleaseNext();\n\t\tif (fileMutationQueues.get(key) === chainedQueue) {\n\t\t\tfileMutationQueues.delete(key);\n\t\t}\n\t}\n}\n"]}
|