@pavanyn/docugen 1.1.1 → 1.3.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/LICENSE +20 -4
- package/README.md +12 -6
- package/dist/agents/cli-backend.d.ts.map +1 -1
- package/dist/agents/cli-backend.js +10 -1
- package/dist/agents/cli-backend.js.map +1 -1
- package/dist/changes/schema.d.ts +21 -60
- package/dist/changes/schema.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +45 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/answer.js +2 -2
- package/dist/commands/answer.js.map +1 -1
- package/dist/commands/ask.d.ts.map +1 -1
- package/dist/commands/ask.js +5 -3
- package/dist/commands/ask.js.map +1 -1
- package/dist/commands/audit-docs.d.ts +39 -0
- package/dist/commands/audit-docs.d.ts.map +1 -0
- package/dist/commands/audit-docs.js +192 -0
- package/dist/commands/audit-docs.js.map +1 -0
- package/dist/commands/bootstrap.d.ts.map +1 -1
- package/dist/commands/bootstrap.js +3 -37
- package/dist/commands/bootstrap.js.map +1 -1
- package/dist/commands/document.d.ts +30 -0
- package/dist/commands/document.d.ts.map +1 -0
- package/dist/commands/document.js +177 -0
- package/dist/commands/document.js.map +1 -0
- package/dist/commands/inference-policy.d.ts +11 -0
- package/dist/commands/inference-policy.d.ts.map +1 -0
- package/dist/commands/inference-policy.js +47 -0
- package/dist/commands/inference-policy.js.map +1 -0
- package/dist/commands/triage.js +2 -2
- package/dist/commands/triage.js.map +1 -1
- package/dist/config/paths.d.ts +4 -0
- package/dist/config/paths.d.ts.map +1 -1
- package/dist/config/paths.js +4 -0
- package/dist/config/paths.js.map +1 -1
- package/dist/config/schema.d.ts +60 -304
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +31 -9
- package/dist/config/schema.js.map +1 -1
- package/dist/detect/inventory-infra.d.ts +51 -0
- package/dist/detect/inventory-infra.d.ts.map +1 -0
- package/dist/detect/inventory-infra.js +247 -0
- package/dist/detect/inventory-infra.js.map +1 -0
- package/dist/detect/inventory-manifests.d.ts +60 -0
- package/dist/detect/inventory-manifests.d.ts.map +1 -0
- package/dist/detect/inventory-manifests.js +791 -0
- package/dist/detect/inventory-manifests.js.map +1 -0
- package/dist/detect/inventory.d.ts +110 -0
- package/dist/detect/inventory.d.ts.map +1 -0
- package/dist/detect/inventory.js +494 -0
- package/dist/detect/inventory.js.map +1 -0
- package/dist/detect/signatures.d.ts +9 -0
- package/dist/detect/signatures.d.ts.map +1 -1
- package/dist/detect/signatures.js +271 -32
- package/dist/detect/signatures.js.map +1 -1
- package/dist/detect/stack.d.ts +10 -0
- package/dist/detect/stack.d.ts.map +1 -1
- package/dist/detect/stack.js +88 -16
- package/dist/detect/stack.js.map +1 -1
- package/dist/extract/config/index.d.ts.map +1 -1
- package/dist/extract/config/index.js +6 -3
- package/dist/extract/config/index.js.map +1 -1
- package/dist/extract/csharp-constants.d.ts +25 -0
- package/dist/extract/csharp-constants.d.ts.map +1 -0
- package/dist/extract/csharp-constants.js +181 -0
- package/dist/extract/csharp-constants.js.map +1 -0
- package/dist/extract/csharp-source.d.ts +100 -0
- package/dist/extract/csharp-source.d.ts.map +1 -0
- package/dist/extract/csharp-source.js +514 -0
- package/dist/extract/csharp-source.js.map +1 -0
- package/dist/extract/endpoints/aspnet-chains.d.ts +50 -0
- package/dist/extract/endpoints/aspnet-chains.d.ts.map +1 -0
- package/dist/extract/endpoints/aspnet-chains.js +263 -0
- package/dist/extract/endpoints/aspnet-chains.js.map +1 -0
- package/dist/extract/endpoints/aspnet-controllers.d.ts +26 -0
- package/dist/extract/endpoints/aspnet-controllers.d.ts.map +1 -0
- package/dist/extract/endpoints/aspnet-controllers.js +367 -0
- package/dist/extract/endpoints/aspnet-controllers.js.map +1 -0
- package/dist/extract/endpoints/aspnet-minimal.d.ts +21 -0
- package/dist/extract/endpoints/aspnet-minimal.d.ts.map +1 -0
- package/dist/extract/endpoints/aspnet-minimal.js +608 -0
- package/dist/extract/endpoints/aspnet-minimal.js.map +1 -0
- package/dist/extract/endpoints/aspnet-routes.d.ts +45 -0
- package/dist/extract/endpoints/aspnet-routes.d.ts.map +1 -0
- package/dist/extract/endpoints/aspnet-routes.js +63 -0
- package/dist/extract/endpoints/aspnet-routes.js.map +1 -0
- package/dist/extract/endpoints/aspnet.d.ts +26 -0
- package/dist/extract/endpoints/aspnet.d.ts.map +1 -0
- package/dist/extract/endpoints/aspnet.js +54 -0
- package/dist/extract/endpoints/aspnet.js.map +1 -0
- package/dist/extract/endpoints/django.d.ts.map +1 -1
- package/dist/extract/endpoints/django.js +107 -4
- package/dist/extract/endpoints/django.js.map +1 -1
- package/dist/extract/endpoints/drf.d.ts +97 -0
- package/dist/extract/endpoints/drf.d.ts.map +1 -0
- package/dist/extract/endpoints/drf.js +501 -0
- package/dist/extract/endpoints/drf.js.map +1 -0
- package/dist/extract/endpoints/fastapi.d.ts.map +1 -1
- package/dist/extract/endpoints/fastapi.js +2 -1
- package/dist/extract/endpoints/fastapi.js.map +1 -1
- package/dist/extract/endpoints/fastify.d.ts +7 -0
- package/dist/extract/endpoints/fastify.d.ts.map +1 -0
- package/dist/extract/endpoints/fastify.js +438 -0
- package/dist/extract/endpoints/fastify.js.map +1 -0
- package/dist/extract/endpoints/flask.d.ts +77 -0
- package/dist/extract/endpoints/flask.d.ts.map +1 -0
- package/dist/extract/endpoints/flask.js +571 -0
- package/dist/extract/endpoints/flask.js.map +1 -0
- package/dist/extract/endpoints/go-http.d.ts +43 -0
- package/dist/extract/endpoints/go-http.d.ts.map +1 -0
- package/dist/extract/endpoints/go-http.js +148 -0
- package/dist/extract/endpoints/go-http.js.map +1 -0
- package/dist/extract/endpoints/go-routes.d.ts +54 -0
- package/dist/extract/endpoints/go-routes.d.ts.map +1 -0
- package/dist/extract/endpoints/go-routes.js +726 -0
- package/dist/extract/endpoints/go-routes.js.map +1 -0
- package/dist/extract/endpoints/hono.d.ts +7 -0
- package/dist/extract/endpoints/hono.d.ts.map +1 -0
- package/dist/extract/endpoints/hono.js +278 -0
- package/dist/extract/endpoints/hono.js.map +1 -0
- package/dist/extract/endpoints/index.d.ts.map +1 -1
- package/dist/extract/endpoints/index.js +57 -3
- package/dist/extract/endpoints/index.js.map +1 -1
- package/dist/extract/endpoints/js-router-ast.d.ts +42 -0
- package/dist/extract/endpoints/js-router-ast.d.ts.map +1 -0
- package/dist/extract/endpoints/js-router-ast.js +183 -0
- package/dist/extract/endpoints/js-router-ast.js.map +1 -0
- package/dist/extract/endpoints/js-routers.d.ts +190 -0
- package/dist/extract/endpoints/js-routers.d.ts.map +1 -0
- package/dist/extract/endpoints/js-routers.js +740 -0
- package/dist/extract/endpoints/js-routers.js.map +1 -0
- package/dist/extract/endpoints/koa.d.ts +7 -0
- package/dist/extract/endpoints/koa.d.ts.map +1 -0
- package/dist/extract/endpoints/koa.js +239 -0
- package/dist/extract/endpoints/koa.js.map +1 -0
- package/dist/extract/endpoints/laravel-routes.d.ts +57 -0
- package/dist/extract/endpoints/laravel-routes.d.ts.map +1 -0
- package/dist/extract/endpoints/laravel-routes.js +483 -0
- package/dist/extract/endpoints/laravel-routes.js.map +1 -0
- package/dist/extract/endpoints/laravel.d.ts +23 -0
- package/dist/extract/endpoints/laravel.d.ts.map +1 -0
- package/dist/extract/endpoints/laravel.js +518 -0
- package/dist/extract/endpoints/laravel.js.map +1 -0
- package/dist/extract/endpoints/nest-middleware.d.ts +43 -0
- package/dist/extract/endpoints/nest-middleware.d.ts.map +1 -0
- package/dist/extract/endpoints/nest-middleware.js +134 -0
- package/dist/extract/endpoints/nest-middleware.js.map +1 -0
- package/dist/extract/endpoints/nest.d.ts +1 -0
- package/dist/extract/endpoints/nest.d.ts.map +1 -1
- package/dist/extract/endpoints/nest.js +36 -2
- package/dist/extract/endpoints/nest.js.map +1 -1
- package/dist/extract/endpoints/python.d.ts.map +1 -1
- package/dist/extract/endpoints/python.js +44 -1
- package/dist/extract/endpoints/python.js.map +1 -1
- package/dist/extract/endpoints/rails-routes.d.ts +40 -0
- package/dist/extract/endpoints/rails-routes.d.ts.map +1 -0
- package/dist/extract/endpoints/rails-routes.js +588 -0
- package/dist/extract/endpoints/rails-routes.js.map +1 -0
- package/dist/extract/endpoints/rails.d.ts +23 -0
- package/dist/extract/endpoints/rails.d.ts.map +1 -0
- package/dist/extract/endpoints/rails.js +236 -0
- package/dist/extract/endpoints/rails.js.map +1 -0
- package/dist/extract/endpoints/spring-constants.d.ts +55 -0
- package/dist/extract/endpoints/spring-constants.d.ts.map +1 -0
- package/dist/extract/endpoints/spring-constants.js +174 -0
- package/dist/extract/endpoints/spring-constants.js.map +1 -0
- package/dist/extract/endpoints/spring.d.ts +35 -0
- package/dist/extract/endpoints/spring.d.ts.map +1 -0
- package/dist/extract/endpoints/spring.js +446 -0
- package/dist/extract/endpoints/spring.js.map +1 -0
- package/dist/extract/go-source.d.ts +119 -0
- package/dist/extract/go-source.d.ts.map +1 -0
- package/dist/extract/go-source.js +404 -0
- package/dist/extract/go-source.js.map +1 -0
- package/dist/extract/inflect.d.ts +15 -0
- package/dist/extract/inflect.d.ts.map +1 -0
- package/dist/extract/inflect.js +103 -0
- package/dist/extract/inflect.js.map +1 -0
- package/dist/extract/java-source.d.ts +84 -0
- package/dist/extract/java-source.d.ts.map +1 -0
- package/dist/extract/java-source.js +402 -0
- package/dist/extract/java-source.js.map +1 -0
- package/dist/extract/jobs/dotnet-jobs.d.ts +27 -0
- package/dist/extract/jobs/dotnet-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/dotnet-jobs.js +205 -0
- package/dist/extract/jobs/dotnet-jobs.js.map +1 -0
- package/dist/extract/jobs/index.d.ts.map +1 -1
- package/dist/extract/jobs/index.js +23 -1
- package/dist/extract/jobs/index.js.map +1 -1
- package/dist/extract/jobs/laravel-jobs.d.ts +35 -0
- package/dist/extract/jobs/laravel-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/laravel-jobs.js +223 -0
- package/dist/extract/jobs/laravel-jobs.js.map +1 -0
- package/dist/extract/jobs/python-call-args.d.ts +66 -0
- package/dist/extract/jobs/python-call-args.d.ts.map +1 -0
- package/dist/extract/jobs/python-call-args.js +196 -0
- package/dist/extract/jobs/python-call-args.js.map +1 -0
- package/dist/extract/jobs/python-jobs.d.ts +18 -0
- package/dist/extract/jobs/python-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/python-jobs.js +259 -0
- package/dist/extract/jobs/python-jobs.js.map +1 -0
- package/dist/extract/jobs/python-queue-jobs.d.ts +15 -0
- package/dist/extract/jobs/python-queue-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/python-queue-jobs.js +251 -0
- package/dist/extract/jobs/python-queue-jobs.js.map +1 -0
- package/dist/extract/jobs/rails-jobs.d.ts +36 -0
- package/dist/extract/jobs/rails-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/rails-jobs.js +309 -0
- package/dist/extract/jobs/rails-jobs.js.map +1 -0
- package/dist/extract/jobs/spring-jobs.d.ts +23 -0
- package/dist/extract/jobs/spring-jobs.d.ts.map +1 -0
- package/dist/extract/jobs/spring-jobs.js +302 -0
- package/dist/extract/jobs/spring-jobs.js.map +1 -0
- package/dist/extract/php-source.d.ts +71 -0
- package/dist/extract/php-source.d.ts.map +1 -0
- package/dist/extract/php-source.js +297 -0
- package/dist/extract/php-source.js.map +1 -0
- package/dist/extract/ruby-source.d.ts +62 -0
- package/dist/extract/ruby-source.d.ts.map +1 -0
- package/dist/extract/ruby-source.js +353 -0
- package/dist/extract/ruby-source.js.map +1 -0
- package/dist/extract/schema/decorated-orm.d.ts.map +1 -1
- package/dist/extract/schema/decorated-orm.js +3 -1
- package/dist/extract/schema/decorated-orm.js.map +1 -1
- package/dist/extract/schema/drizzle-scan.d.ts +97 -0
- package/dist/extract/schema/drizzle-scan.d.ts.map +1 -0
- package/dist/extract/schema/drizzle-scan.js +567 -0
- package/dist/extract/schema/drizzle-scan.js.map +1 -0
- package/dist/extract/schema/drizzle.d.ts +27 -0
- package/dist/extract/schema/drizzle.d.ts.map +1 -0
- package/dist/extract/schema/drizzle.js +452 -0
- package/dist/extract/schema/drizzle.js.map +1 -0
- package/dist/extract/schema/efcore-fluent.d.ts +47 -0
- package/dist/extract/schema/efcore-fluent.d.ts.map +1 -0
- package/dist/extract/schema/efcore-fluent.js +118 -0
- package/dist/extract/schema/efcore-fluent.js.map +1 -0
- package/dist/extract/schema/efcore-scan.d.ts +60 -0
- package/dist/extract/schema/efcore-scan.d.ts.map +1 -0
- package/dist/extract/schema/efcore-scan.js +189 -0
- package/dist/extract/schema/efcore-scan.js.map +1 -0
- package/dist/extract/schema/efcore.d.ts +18 -0
- package/dist/extract/schema/efcore.d.ts.map +1 -0
- package/dist/extract/schema/efcore.js +628 -0
- package/dist/extract/schema/efcore.js.map +1 -0
- package/dist/extract/schema/gorm.d.ts +49 -0
- package/dist/extract/schema/gorm.d.ts.map +1 -0
- package/dist/extract/schema/gorm.js +475 -0
- package/dist/extract/schema/gorm.js.map +1 -0
- package/dist/extract/schema/index.d.ts.map +1 -1
- package/dist/extract/schema/index.js +30 -3
- package/dist/extract/schema/index.js.map +1 -1
- package/dist/extract/schema/jpa-scan.d.ts +60 -0
- package/dist/extract/schema/jpa-scan.d.ts.map +1 -0
- package/dist/extract/schema/jpa-scan.js +318 -0
- package/dist/extract/schema/jpa-scan.js.map +1 -0
- package/dist/extract/schema/jpa.d.ts +29 -0
- package/dist/extract/schema/jpa.d.ts.map +1 -0
- package/dist/extract/schema/jpa.js +288 -0
- package/dist/extract/schema/jpa.js.map +1 -0
- package/dist/extract/schema/js-schema-sources.d.ts +47 -0
- package/dist/extract/schema/js-schema-sources.d.ts.map +1 -0
- package/dist/extract/schema/js-schema-sources.js +111 -0
- package/dist/extract/schema/js-schema-sources.js.map +1 -0
- package/dist/extract/schema/knex-table.d.ts +52 -0
- package/dist/extract/schema/knex-table.d.ts.map +1 -0
- package/dist/extract/schema/knex-table.js +348 -0
- package/dist/extract/schema/knex-table.js.map +1 -0
- package/dist/extract/schema/knex.d.ts +43 -0
- package/dist/extract/schema/knex.d.ts.map +1 -0
- package/dist/extract/schema/knex.js +470 -0
- package/dist/extract/schema/knex.js.map +1 -0
- package/dist/extract/schema/laravel-blueprint.d.ts +22 -0
- package/dist/extract/schema/laravel-blueprint.d.ts.map +1 -0
- package/dist/extract/schema/laravel-blueprint.js +337 -0
- package/dist/extract/schema/laravel-blueprint.js.map +1 -0
- package/dist/extract/schema/laravel-migrations.d.ts +22 -0
- package/dist/extract/schema/laravel-migrations.d.ts.map +1 -0
- package/dist/extract/schema/laravel-migrations.js +241 -0
- package/dist/extract/schema/laravel-migrations.js.map +1 -0
- package/dist/extract/schema/mikro-orm.d.ts +53 -0
- package/dist/extract/schema/mikro-orm.d.ts.map +1 -0
- package/dist/extract/schema/mikro-orm.js +370 -0
- package/dist/extract/schema/mikro-orm.js.map +1 -0
- package/dist/extract/schema/mongoose.d.ts.map +1 -1
- package/dist/extract/schema/mongoose.js +3 -1
- package/dist/extract/schema/mongoose.js.map +1 -1
- package/dist/extract/schema/python-model-scan.d.ts +66 -0
- package/dist/extract/schema/python-model-scan.d.ts.map +1 -0
- package/dist/extract/schema/python-model-scan.js +392 -0
- package/dist/extract/schema/python-model-scan.js.map +1 -0
- package/dist/extract/schema/python-models.d.ts +15 -7
- package/dist/extract/schema/python-models.d.ts.map +1 -1
- package/dist/extract/schema/python-models.js +274 -213
- package/dist/extract/schema/python-models.js.map +1 -1
- package/dist/extract/schema/rails-schema.d.ts +22 -0
- package/dist/extract/schema/rails-schema.d.ts.map +1 -0
- package/dist/extract/schema/rails-schema.js +259 -0
- package/dist/extract/schema/rails-schema.js.map +1 -0
- package/dist/extract/schema/reconcile.d.ts +27 -0
- package/dist/extract/schema/reconcile.d.ts.map +1 -0
- package/dist/extract/schema/reconcile.js +69 -0
- package/dist/extract/schema/reconcile.js.map +1 -0
- package/dist/extract/schema/sql-ddl.d.ts +0 -9
- package/dist/extract/schema/sql-ddl.d.ts.map +1 -1
- package/dist/extract/schema/sql-ddl.js +83 -17
- package/dist/extract/schema/sql-ddl.js.map +1 -1
- package/dist/extract/test-sources.d.ts +11 -0
- package/dist/extract/test-sources.d.ts.map +1 -0
- package/dist/extract/test-sources.js +26 -0
- package/dist/extract/test-sources.js.map +1 -0
- package/dist/features/schema.d.ts +19 -75
- package/dist/features/schema.d.ts.map +1 -1
- package/dist/features/schema.js +1 -1
- package/dist/features/schema.js.map +1 -1
- package/dist/governance/schema.d.ts +16 -82
- package/dist/governance/schema.d.ts.map +1 -1
- package/dist/graph/store.d.ts +116 -185
- package/dist/graph/store.d.ts.map +1 -1
- package/dist/graph/store.js +2 -2
- package/dist/graph/store.js.map +1 -1
- package/dist/infer/cards.d.ts.map +1 -1
- package/dist/infer/cards.js +28 -1
- package/dist/infer/cards.js.map +1 -1
- package/dist/infer/context.d.ts.map +1 -1
- package/dist/infer/context.js +8 -25
- package/dist/infer/context.js.map +1 -1
- package/dist/infer/types.d.ts +15 -293
- package/dist/infer/types.d.ts.map +1 -1
- package/dist/legacy/plans.d.ts +20 -103
- package/dist/legacy/plans.d.ts.map +1 -1
- package/dist/legacy/schema.d.ts +244 -685
- package/dist/legacy/schema.d.ts.map +1 -1
- package/dist/migrations/schema.d.ts +17 -65
- package/dist/migrations/schema.d.ts.map +1 -1
- package/dist/narrate/audit-commands.d.ts +42 -0
- package/dist/narrate/audit-commands.d.ts.map +1 -0
- package/dist/narrate/audit-commands.js +248 -0
- package/dist/narrate/audit-commands.js.map +1 -0
- package/dist/narrate/audit-facts.d.ts +15 -0
- package/dist/narrate/audit-facts.d.ts.map +1 -0
- package/dist/narrate/audit-facts.js +118 -0
- package/dist/narrate/audit-facts.js.map +1 -0
- package/dist/narrate/audit-mechanical.d.ts +102 -0
- package/dist/narrate/audit-mechanical.d.ts.map +1 -0
- package/dist/narrate/audit-mechanical.js +533 -0
- package/dist/narrate/audit-mechanical.js.map +1 -0
- package/dist/narrate/audit-render.d.ts +35 -0
- package/dist/narrate/audit-render.d.ts.map +1 -0
- package/dist/narrate/audit-render.js +154 -0
- package/dist/narrate/audit-render.js.map +1 -0
- package/dist/narrate/audit-types.d.ts +86 -0
- package/dist/narrate/audit-types.d.ts.map +1 -0
- package/dist/narrate/audit-types.js +12 -0
- package/dist/narrate/audit-types.js.map +1 -0
- package/dist/narrate/audit.d.ts +136 -0
- package/dist/narrate/audit.d.ts.map +1 -0
- package/dist/narrate/audit.js +693 -0
- package/dist/narrate/audit.js.map +1 -0
- package/dist/narrate/engine.d.ts +124 -0
- package/dist/narrate/engine.d.ts.map +1 -0
- package/dist/narrate/engine.js +707 -0
- package/dist/narrate/engine.js.map +1 -0
- package/dist/narrate/evidence.d.ts +36 -0
- package/dist/narrate/evidence.d.ts.map +1 -0
- package/dist/narrate/evidence.js +138 -0
- package/dist/narrate/evidence.js.map +1 -0
- package/dist/narrate/factcheck.d.ts +30 -0
- package/dist/narrate/factcheck.d.ts.map +1 -0
- package/dist/narrate/factcheck.js +338 -0
- package/dist/narrate/factcheck.js.map +1 -0
- package/dist/narrate/plan.d.ts +20 -0
- package/dist/narrate/plan.d.ts.map +1 -0
- package/dist/narrate/plan.js +79 -0
- package/dist/narrate/plan.js.map +1 -0
- package/dist/narrate/planners/items-data.d.ts +14 -0
- package/dist/narrate/planners/items-data.d.ts.map +1 -0
- package/dist/narrate/planners/items-data.js +269 -0
- package/dist/narrate/planners/items-data.js.map +1 -0
- package/dist/narrate/planners/items-evidence.d.ts +37 -0
- package/dist/narrate/planners/items-evidence.d.ts.map +1 -0
- package/dist/narrate/planners/items-evidence.js +137 -0
- package/dist/narrate/planners/items-evidence.js.map +1 -0
- package/dist/narrate/planners/items.d.ts +3 -0
- package/dist/narrate/planners/items.d.ts.map +1 -0
- package/dist/narrate/planners/items.js +130 -0
- package/dist/narrate/planners/items.js.map +1 -0
- package/dist/narrate/planners/shared.d.ts +45 -0
- package/dist/narrate/planners/shared.d.ts.map +1 -0
- package/dist/narrate/planners/shared.js +139 -0
- package/dist/narrate/planners/shared.js.map +1 -0
- package/dist/narrate/planners/synthesis-flows.d.ts +3 -0
- package/dist/narrate/planners/synthesis-flows.d.ts.map +1 -0
- package/dist/narrate/planners/synthesis-flows.js +94 -0
- package/dist/narrate/planners/synthesis-flows.js.map +1 -0
- package/dist/narrate/planners/synthesis-security.d.ts +3 -0
- package/dist/narrate/planners/synthesis-security.d.ts.map +1 -0
- package/dist/narrate/planners/synthesis-security.js +180 -0
- package/dist/narrate/planners/synthesis-security.js.map +1 -0
- package/dist/narrate/planners/synthesis-shared.d.ts +31 -0
- package/dist/narrate/planners/synthesis-shared.d.ts.map +1 -0
- package/dist/narrate/planners/synthesis-shared.js +137 -0
- package/dist/narrate/planners/synthesis-shared.js.map +1 -0
- package/dist/narrate/planners/synthesis.d.ts +11 -0
- package/dist/narrate/planners/synthesis.d.ts.map +1 -0
- package/dist/narrate/planners/synthesis.js +367 -0
- package/dist/narrate/planners/synthesis.js.map +1 -0
- package/dist/narrate/questions.d.ts +14 -0
- package/dist/narrate/questions.d.ts.map +1 -0
- package/dist/narrate/questions.js +42 -0
- package/dist/narrate/questions.js.map +1 -0
- package/dist/narrate/render.d.ts +36 -0
- package/dist/narrate/render.d.ts.map +1 -0
- package/dist/narrate/render.js +233 -0
- package/dist/narrate/render.js.map +1 -0
- package/dist/narrate/sanitize.d.ts +28 -0
- package/dist/narrate/sanitize.d.ts.map +1 -0
- package/dist/narrate/sanitize.js +190 -0
- package/dist/narrate/sanitize.js.map +1 -0
- package/dist/narrate/store.d.ts +16 -0
- package/dist/narrate/store.d.ts.map +1 -0
- package/dist/narrate/store.js +206 -0
- package/dist/narrate/store.js.map +1 -0
- package/dist/narrate/types.d.ts +161 -0
- package/dist/narrate/types.d.ts.map +1 -0
- package/dist/narrate/types.js +74 -0
- package/dist/narrate/types.js.map +1 -0
- package/dist/pilot/schema.d.ts +17 -105
- package/dist/pilot/schema.d.ts.map +1 -1
- package/dist/pipeline.d.ts +6 -0
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +8 -0
- package/dist/pipeline.js.map +1 -1
- package/dist/plans/schema.d.ts +43 -137
- package/dist/plans/schema.d.ts.map +1 -1
- package/dist/privacy/benign.d.ts +2 -0
- package/dist/privacy/benign.d.ts.map +1 -0
- package/dist/privacy/benign.js +59 -0
- package/dist/privacy/benign.js.map +1 -0
- package/dist/privacy/redact-code.d.ts +25 -0
- package/dist/privacy/redact-code.d.ts.map +1 -0
- package/dist/privacy/redact-code.js +251 -0
- package/dist/privacy/redact-code.js.map +1 -0
- package/dist/privacy/redact-config.d.ts +46 -0
- package/dist/privacy/redact-config.d.ts.map +1 -0
- package/dist/privacy/redact-config.js +471 -0
- package/dist/privacy/redact-config.js.map +1 -0
- package/dist/privacy/redact-files.d.ts +29 -0
- package/dist/privacy/redact-files.d.ts.map +1 -0
- package/dist/privacy/redact-files.js +163 -0
- package/dist/privacy/redact-files.js.map +1 -0
- package/dist/privacy/redact-keyless.d.ts +20 -0
- package/dist/privacy/redact-keyless.d.ts.map +1 -0
- package/dist/privacy/redact-keyless.js +291 -0
- package/dist/privacy/redact-keyless.js.map +1 -0
- package/dist/privacy/redact-keys.d.ts +32 -0
- package/dist/privacy/redact-keys.d.ts.map +1 -0
- package/dist/privacy/redact-keys.js +160 -0
- package/dist/privacy/redact-keys.js.map +1 -0
- package/dist/privacy/redact-shape.d.ts +42 -0
- package/dist/privacy/redact-shape.d.ts.map +1 -0
- package/dist/privacy/redact-shape.js +313 -0
- package/dist/privacy/redact-shape.js.map +1 -0
- package/dist/privacy/redact.d.ts +34 -5
- package/dist/privacy/redact.d.ts.map +1 -1
- package/dist/privacy/redact.js +171 -46
- package/dist/privacy/redact.js.map +1 -1
- package/dist/questions/store.d.ts +1 -0
- package/dist/questions/store.d.ts.map +1 -1
- package/dist/questions/store.js +31 -30
- package/dist/questions/store.js.map +1 -1
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +7 -0
- package/dist/render/index.js.map +1 -1
- package/dist/render/pages/config.d.ts.map +1 -1
- package/dist/render/pages/config.js +2 -3
- package/dist/render/pages/config.js.map +1 -1
- package/dist/render/pages/readme.d.ts.map +1 -1
- package/dist/render/pages/readme.js +4 -0
- package/dist/render/pages/readme.js.map +1 -1
- package/dist/render/pages/tech-stack.d.ts +16 -0
- package/dist/render/pages/tech-stack.d.ts.map +1 -0
- package/dist/render/pages/tech-stack.js +147 -0
- package/dist/render/pages/tech-stack.js.map +1 -0
- package/dist/requirements/ids.d.ts +13 -0
- package/dist/requirements/ids.d.ts.map +1 -0
- package/dist/requirements/ids.js +90 -0
- package/dist/requirements/ids.js.map +1 -0
- package/dist/requirements/store.d.ts +2 -2
- package/dist/requirements/store.d.ts.map +1 -1
- package/dist/requirements/store.js +55 -57
- package/dist/requirements/store.js.map +1 -1
- package/dist/util/boundaries.d.ts.map +1 -1
- package/dist/util/boundaries.js +32 -19
- package/dist/util/boundaries.js.map +1 -1
- package/dist/util/generated.js +1 -1
- package/dist/util/generated.js.map +1 -1
- package/dist/util/human-records.d.ts +7 -0
- package/dist/util/human-records.d.ts.map +1 -0
- package/dist/util/human-records.js +23 -0
- package/dist/util/human-records.js.map +1 -0
- package/dist/verify/expected.d.ts.map +1 -1
- package/dist/verify/expected.js +50 -0
- package/dist/verify/expected.js.map +1 -1
- package/dist/walkthrough/capture.d.ts +14 -184
- package/dist/walkthrough/capture.d.ts.map +1 -1
- package/dist/walkthrough/schema.d.ts +32 -218
- package/dist/walkthrough/schema.d.ts.map +1 -1
- package/package.json +3 -3
- package/prompts/doc-audit.v1.md +83 -0
- package/prompts/doc-unit.v1.md +97 -0
- package/prompts/doc-unit.v2.md +116 -0
- package/prompts/doc-verify.v1.md +43 -0
- package/prompts/doc-verify.v2.md +67 -0
- package/prompts/feature-card.v2.md +4 -1
|
@@ -0,0 +1,707 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { extractJsonObject } from '../infer/cards.js';
|
|
6
|
+
import { redactSecrets } from '../privacy/redact.js';
|
|
7
|
+
import { renderAnswersForPrompt } from '../questions/store.js';
|
|
8
|
+
import { toPosix } from '../util/paths.js';
|
|
9
|
+
import { compareStrings } from '../util/sort.js';
|
|
10
|
+
import { buildEvidence } from './evidence.js';
|
|
11
|
+
import { factCheckClaims } from './factcheck.js';
|
|
12
|
+
import { inlineText, safeId } from './sanitize.js';
|
|
13
|
+
import { UNIT_LIMITS, unitBodySchema } from './types.js';
|
|
14
|
+
/** Bumped whenever a prompt changes, so stored units are regenerated. */
|
|
15
|
+
export const UNIT_PROMPT_VERSION = 'doc-unit.v2';
|
|
16
|
+
export const VERIFY_PROMPT_VERSION = 'doc-verify.v2';
|
|
17
|
+
/** After this many backend failures in a row, the rest of the run is not attempted. */
|
|
18
|
+
export const MAX_CONSECUTIVE_BACKEND_FAILURES = 3;
|
|
19
|
+
/**
|
|
20
|
+
* What a stored unit depends on beyond its prompt.
|
|
21
|
+
*
|
|
22
|
+
* A guard removed in a file the unit was never shown changes what the fact
|
|
23
|
+
* check would have let through, and a different model writes different prose.
|
|
24
|
+
* Neither appears in the prompt, so both are folded into the cache key.
|
|
25
|
+
*/
|
|
26
|
+
export function cacheSalt(endpoints, model) {
|
|
27
|
+
const facts = endpoints
|
|
28
|
+
.map((endpoint) => `${endpoint.method} ${endpoint.path} ${[...endpoint.middleware].sort(compareStrings).join(',')}`)
|
|
29
|
+
.sort(compareStrings)
|
|
30
|
+
.join('\n');
|
|
31
|
+
return createHash('sha256').update(`${model ?? ''}\u0000${facts}`).digest('hex').slice(0, 16);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build the exact prompt for a unit without calling anything.
|
|
35
|
+
*
|
|
36
|
+
* Separate from generation so a dry run can report what would be sent, and
|
|
37
|
+
* what it would cost, from the same code that sends it.
|
|
38
|
+
*/
|
|
39
|
+
export async function prepareUnit(args) {
|
|
40
|
+
const template = await loadPrompt(UNIT_PROMPT_VERSION);
|
|
41
|
+
const evidence = await buildEvidence({
|
|
42
|
+
root: args.root,
|
|
43
|
+
requests: args.spec.evidence,
|
|
44
|
+
limits: args.limits,
|
|
45
|
+
redact: args.redactSecrets,
|
|
46
|
+
});
|
|
47
|
+
const recorded = args.answers.get(args.spec.id)?.answers ?? [];
|
|
48
|
+
// Redaction is applied to each piece of repository text, not to the finished
|
|
49
|
+
// prompt. The template and its block markers are ours; a redactor that took a
|
|
50
|
+
// marker for a token would cut away the prompt's own structure.
|
|
51
|
+
let promptRedactions = 0;
|
|
52
|
+
const clean = (text) => {
|
|
53
|
+
if (!args.redactSecrets)
|
|
54
|
+
return text;
|
|
55
|
+
const result = redactSecrets(text);
|
|
56
|
+
promptRedactions += result.count;
|
|
57
|
+
return result.text;
|
|
58
|
+
};
|
|
59
|
+
const raw = fill(template, {
|
|
60
|
+
TASK: clean(args.spec.task),
|
|
61
|
+
SECTIONS: args.spec.sections
|
|
62
|
+
.map((section) => `- \`${section.id}\` — ${clean(section.heading)}: ${section.about}`)
|
|
63
|
+
.join('\n'),
|
|
64
|
+
FACTS: asData(clean(args.spec.facts.trim() === '' ? '_None._' : args.spec.facts)),
|
|
65
|
+
ANSWERS: asData(clean(renderAnswersForPrompt(recorded))),
|
|
66
|
+
// Already redacted, file by file, when the excerpts were built.
|
|
67
|
+
EVIDENCE: asData(evidence.text),
|
|
68
|
+
// Marks where repository text begins and ends. Derived from that text, so
|
|
69
|
+
// the prompt stays reproducible and the cache key with it, while nothing
|
|
70
|
+
// written in the repository beforehand can know it.
|
|
71
|
+
DELIM: createHash('sha256').update(`${args.spec.id} ${args.spec.facts} ${evidence.text}`).digest('hex').slice(0, 16),
|
|
72
|
+
});
|
|
73
|
+
const redacted = { text: raw, count: promptRedactions };
|
|
74
|
+
const inputHash = createHash('sha256')
|
|
75
|
+
.update([
|
|
76
|
+
UNIT_PROMPT_VERSION,
|
|
77
|
+
args.verify ? VERIFY_PROMPT_VERSION : 'unverified',
|
|
78
|
+
// Things that change the result without changing the prompt: the facts
|
|
79
|
+
// the fact check compares against, and which model is asked.
|
|
80
|
+
args.salt ?? '',
|
|
81
|
+
redacted.text,
|
|
82
|
+
].join('\u0000'))
|
|
83
|
+
.digest('hex')
|
|
84
|
+
.slice(0, 32);
|
|
85
|
+
return {
|
|
86
|
+
spec: args.spec,
|
|
87
|
+
evidence,
|
|
88
|
+
prompt: redacted.text,
|
|
89
|
+
inputHash,
|
|
90
|
+
redactions: evidence.redactions + redacted.count,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Generate every unit, one at a time.
|
|
95
|
+
*
|
|
96
|
+
* Each unit passes through four gates, in order of how cheaply they can say no:
|
|
97
|
+
* the response must parse; every claim must cite lines it was shown; claims
|
|
98
|
+
* must not disagree with extracted facts; and a second model pass must judge
|
|
99
|
+
* each survivor supported by its cited lines. A claim that fails any gate is
|
|
100
|
+
* removed and recorded, never repaired.
|
|
101
|
+
*/
|
|
102
|
+
export async function generateUnits(options) {
|
|
103
|
+
const units = [];
|
|
104
|
+
const failures = [];
|
|
105
|
+
const reused = [];
|
|
106
|
+
let calls = 0;
|
|
107
|
+
// A backend that fails repeatedly is down, out of quota, or misconfigured.
|
|
108
|
+
// Asking it another fifty times helps nobody and, on a metered backend that
|
|
109
|
+
// bills failed requests, costs money.
|
|
110
|
+
let backendFailures = 0;
|
|
111
|
+
let lastBackendFailure = '';
|
|
112
|
+
for (const [index, spec] of options.specs.entries()) {
|
|
113
|
+
if (backendFailures >= MAX_CONSECUTIVE_BACKEND_FAILURES) {
|
|
114
|
+
failures.push({
|
|
115
|
+
id: spec.id,
|
|
116
|
+
title: spec.title,
|
|
117
|
+
kind: 'backend',
|
|
118
|
+
reason: `Not attempted: the backend failed ${backendFailures} times in a row. Last failure: ${lastBackendFailure}`,
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const prepared = await prepareUnit({
|
|
123
|
+
root: options.root,
|
|
124
|
+
spec,
|
|
125
|
+
answers: options.answers,
|
|
126
|
+
limits: options.limits,
|
|
127
|
+
redactSecrets: options.redactSecrets,
|
|
128
|
+
verify: options.verify,
|
|
129
|
+
salt: cacheSalt(options.endpoints, options.model),
|
|
130
|
+
});
|
|
131
|
+
const previous = options.previous?.get(spec.id);
|
|
132
|
+
if (options.force !== true &&
|
|
133
|
+
previous !== undefined &&
|
|
134
|
+
previous.inputHash === prepared.inputHash &&
|
|
135
|
+
previous.promptVersion === UNIT_PROMPT_VERSION) {
|
|
136
|
+
// Headings, facts and order come from the plan, so a reused unit still
|
|
137
|
+
// reflects a retitled section without paying for the prose again.
|
|
138
|
+
units.push(reframe(previous, spec));
|
|
139
|
+
reused.push(spec.id);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
options.logger.info(` [${index + 1}/${options.specs.length}] ${spec.title}`);
|
|
143
|
+
options.logger.info(` disclosure: ${prepared.evidence.includedFiles.length} file(s), ${Buffer.byteLength(prepared.prompt)} bytes, ` +
|
|
144
|
+
`provider=${options.backend.id}, model=${options.model ?? 'backend-default'}, redactions=${prepared.redactions}`);
|
|
145
|
+
options.logger.info(` files: ${prepared.evidence.includedFiles.join(', ') || '(none)'}`);
|
|
146
|
+
if (prepared.evidence.includedFiles.length === 0) {
|
|
147
|
+
failures.push({ id: spec.id, title: spec.title, reason: 'No source could be read for this unit.', kind: 'content' });
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
calls += 1;
|
|
151
|
+
const outcome = await options.backend.run({
|
|
152
|
+
prompt: prepared.prompt,
|
|
153
|
+
cwd: options.root,
|
|
154
|
+
timeoutMs: options.timeoutMs,
|
|
155
|
+
...(options.model === undefined ? {} : { model: options.model }),
|
|
156
|
+
});
|
|
157
|
+
if (!outcome.ok) {
|
|
158
|
+
failures.push({ id: spec.id, title: spec.title, reason: outcome.reason, kind: 'backend' });
|
|
159
|
+
backendFailures += 1;
|
|
160
|
+
lastBackendFailure = outcome.reason;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
backendFailures = 0;
|
|
164
|
+
const parsed = parseUnitBody(outcome.text);
|
|
165
|
+
if (!parsed.ok) {
|
|
166
|
+
failures.push({ id: spec.id, title: spec.title, reason: parsed.reason, kind: 'content' });
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const removed = [];
|
|
170
|
+
const questions = [...parsed.body.unknowns];
|
|
171
|
+
const bySection = new Map();
|
|
172
|
+
const known = new Set(spec.sections.map((section) => section.id));
|
|
173
|
+
for (const section of parsed.body.sections) {
|
|
174
|
+
if (!known.has(section.id)) {
|
|
175
|
+
for (const claim of section.claims) {
|
|
176
|
+
removed.push({
|
|
177
|
+
sectionId: section.id,
|
|
178
|
+
text: claim.text,
|
|
179
|
+
stage: 'citation',
|
|
180
|
+
reason: `It was filed under '${section.id}', which is not a section of this unit.`,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
const cited = [];
|
|
186
|
+
for (const claim of section.claims) {
|
|
187
|
+
const issue = citationIssue(claim, prepared.evidence.ranges);
|
|
188
|
+
if (issue === undefined)
|
|
189
|
+
cited.push(normaliseClaim(claim));
|
|
190
|
+
else
|
|
191
|
+
removed.push({ sectionId: section.id, text: claim.text, stage: 'citation', reason: issue });
|
|
192
|
+
}
|
|
193
|
+
const checked = factCheckClaims(cited, options.endpoints, subjectOf(spec, section.id));
|
|
194
|
+
removed.push(...checked.removed.map((item) => ({ sectionId: section.id, ...item })));
|
|
195
|
+
questions.push(...checked.questions);
|
|
196
|
+
if (checked.kept.length > 0) {
|
|
197
|
+
bySection.set(section.id, [...(bySection.get(section.id) ?? []), ...checked.kept]);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
let status = 'skipped';
|
|
201
|
+
if (options.verify && bySection.size > 0) {
|
|
202
|
+
calls += 1;
|
|
203
|
+
const verdict = await verifyClaims({
|
|
204
|
+
spec,
|
|
205
|
+
bySection,
|
|
206
|
+
evidenceText: prepared.evidence.text,
|
|
207
|
+
backend: options.backend,
|
|
208
|
+
root: options.root,
|
|
209
|
+
timeoutMs: options.timeoutMs,
|
|
210
|
+
redactSecrets: options.redactSecrets,
|
|
211
|
+
...(options.model === undefined ? {} : { model: options.model }),
|
|
212
|
+
});
|
|
213
|
+
if (verdict.ok) {
|
|
214
|
+
status = 'checked';
|
|
215
|
+
removed.push(...verdict.removed);
|
|
216
|
+
for (const [sectionId, kept] of verdict.kept) {
|
|
217
|
+
if (kept.length === 0)
|
|
218
|
+
bySection.delete(sectionId);
|
|
219
|
+
else
|
|
220
|
+
bySection.set(sectionId, [...kept]);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
// Fail closed. Verification was asked for and did not happen, so these
|
|
225
|
+
// statements have not passed the check the page would say they passed.
|
|
226
|
+
// Publishing them anyway is how a rejected statement reached a page.
|
|
227
|
+
failures.push({
|
|
228
|
+
id: spec.id,
|
|
229
|
+
title: spec.title,
|
|
230
|
+
kind: 'backend',
|
|
231
|
+
reason: `The statements were written but could not be verified, so none were published: ${verdict.reason}`,
|
|
232
|
+
});
|
|
233
|
+
backendFailures += 1;
|
|
234
|
+
lastBackendFailure = verdict.reason;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (options.verify) {
|
|
239
|
+
status = 'checked';
|
|
240
|
+
}
|
|
241
|
+
const unknowns = dedupeUnknowns(questions).slice(0, UNIT_LIMITS.unknowns);
|
|
242
|
+
if (bySection.size === 0 && unknowns.length === 0) {
|
|
243
|
+
failures.push({
|
|
244
|
+
id: spec.id,
|
|
245
|
+
title: spec.title,
|
|
246
|
+
kind: 'content',
|
|
247
|
+
reason: removed.length === 0
|
|
248
|
+
? 'The model established nothing for this unit from the supplied source.'
|
|
249
|
+
: `All ${removed.length} statement(s) were removed by the citation, fact and verification checks.`,
|
|
250
|
+
});
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
units.push({
|
|
254
|
+
id: spec.id,
|
|
255
|
+
slug: spec.slug,
|
|
256
|
+
page: spec.page,
|
|
257
|
+
title: spec.title,
|
|
258
|
+
order: spec.order,
|
|
259
|
+
sections: spec.sections
|
|
260
|
+
.filter((section) => bySection.has(section.id))
|
|
261
|
+
.map((section) => ({ ...section, claims: bySection.get(section.id) ?? [] })),
|
|
262
|
+
unknowns,
|
|
263
|
+
producedBy: options.backend.id,
|
|
264
|
+
promptVersion: UNIT_PROMPT_VERSION,
|
|
265
|
+
inputHash: prepared.inputHash,
|
|
266
|
+
verification: { status, removed },
|
|
267
|
+
sources: await hashSources(options.root, prepared.evidence.includedFiles),
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
units: units.sort(compareUnits),
|
|
272
|
+
failures: failures.sort((a, b) => compareStrings(a.id, b.id)),
|
|
273
|
+
reused,
|
|
274
|
+
calls,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
export function compareUnits(a, b) {
|
|
278
|
+
return compareStrings(a.page, b.page) || a.order - b.order || compareStrings(a.id, b.id);
|
|
279
|
+
}
|
|
280
|
+
/** Content hash of a source file, with line endings normalised so a checkout setting cannot change it. */
|
|
281
|
+
export async function hashSource(root, file) {
|
|
282
|
+
try {
|
|
283
|
+
const contents = await fs.readFile(path.join(root, file), 'utf8');
|
|
284
|
+
// A byte-order mark is an editor setting too, not a change to the code.
|
|
285
|
+
const normalised = (contents.charCodeAt(0) === 0xfeff ? contents.slice(1) : contents).replace(/\r\n/g, '\n');
|
|
286
|
+
return createHash('sha256').update(normalised).digest('hex').slice(0, 16);
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
async function hashSources(root, files) {
|
|
293
|
+
const sources = [];
|
|
294
|
+
for (const file of [...files].sort(compareStrings)) {
|
|
295
|
+
const hash = await hashSource(root, file);
|
|
296
|
+
if (hash !== undefined)
|
|
297
|
+
sources.push({ file, hash });
|
|
298
|
+
}
|
|
299
|
+
return sources;
|
|
300
|
+
}
|
|
301
|
+
/** The files a unit was written from that have since changed or gone. */
|
|
302
|
+
export async function changedSources(root, unit) {
|
|
303
|
+
const changed = [];
|
|
304
|
+
for (const source of unit.sources) {
|
|
305
|
+
if ((await hashSource(root, source.file)) !== source.hash)
|
|
306
|
+
changed.push(source.file);
|
|
307
|
+
}
|
|
308
|
+
return changed;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* The endpoint a section is about, read from its planner-written heading.
|
|
312
|
+
*
|
|
313
|
+
* Inside the section for `DELETE /users/:id`, "this endpoint requires
|
|
314
|
+
* authentication" names no endpoint, so the fact check needs to be told which
|
|
315
|
+
* one is meant. Headings are fixed by the plan, never by the model.
|
|
316
|
+
*/
|
|
317
|
+
function subjectOf(spec, sectionId) {
|
|
318
|
+
const heading = spec.sections.find((section) => section.id === sectionId)?.heading ?? '';
|
|
319
|
+
// The heading is a code span whose fence may be longer than one backtick,
|
|
320
|
+
// padded with a space, when the path itself contains a backtick.
|
|
321
|
+
const match = /^(`+) ?(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|ALL) (\/\S*?) ?\1(?!`)/.exec(heading);
|
|
322
|
+
return match === null ? undefined : { method: match[2], path: match[3] };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Remove statements whose citations no longer point at anything.
|
|
326
|
+
*
|
|
327
|
+
* A link to a deleted file, or to a line past the end of one, cannot be
|
|
328
|
+
* followed, and a statement a reader cannot check is the thing this lane does
|
|
329
|
+
* not publish. Run when the guide is rendered, with no model.
|
|
330
|
+
*/
|
|
331
|
+
export async function withLiveCitations(root, unit) {
|
|
332
|
+
const lineCounts = new Map();
|
|
333
|
+
const lineCount = async (file) => {
|
|
334
|
+
if (lineCounts.has(file))
|
|
335
|
+
return lineCounts.get(file);
|
|
336
|
+
let count;
|
|
337
|
+
try {
|
|
338
|
+
const target = path.resolve(root, file);
|
|
339
|
+
const relation = path.relative(path.resolve(root), target);
|
|
340
|
+
if (!relation.startsWith('..') && !path.isAbsolute(relation)) {
|
|
341
|
+
count = countLines(await fs.readFile(target, 'utf8'));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
catch {
|
|
345
|
+
count = undefined;
|
|
346
|
+
}
|
|
347
|
+
lineCounts.set(file, count);
|
|
348
|
+
return count;
|
|
349
|
+
};
|
|
350
|
+
const sections = [];
|
|
351
|
+
for (const section of unit.sections) {
|
|
352
|
+
const claims = [];
|
|
353
|
+
for (const claim of section.claims) {
|
|
354
|
+
let live = claim.evidence.length > 0;
|
|
355
|
+
for (const evidence of claim.evidence) {
|
|
356
|
+
const count = await lineCount(evidence.file);
|
|
357
|
+
if (count === undefined || evidence.line === undefined || evidence.line > count)
|
|
358
|
+
live = false;
|
|
359
|
+
}
|
|
360
|
+
if (live)
|
|
361
|
+
claims.push(claim);
|
|
362
|
+
}
|
|
363
|
+
if (claims.length > 0)
|
|
364
|
+
sections.push({ ...section, claims });
|
|
365
|
+
}
|
|
366
|
+
return { ...unit, sections };
|
|
367
|
+
}
|
|
368
|
+
/** Apply the current plan's headings, facts and order to a stored unit. */
|
|
369
|
+
export function reframe(unit, spec) {
|
|
370
|
+
const specs = new Map(spec.sections.map((section) => [section.id, section]));
|
|
371
|
+
return {
|
|
372
|
+
...unit,
|
|
373
|
+
slug: spec.slug,
|
|
374
|
+
page: spec.page,
|
|
375
|
+
title: spec.title,
|
|
376
|
+
order: spec.order,
|
|
377
|
+
sections: unit.sections
|
|
378
|
+
// Same id is not enough: the statements were written for a particular
|
|
379
|
+
// subject, named by the heading. If the plan now gives that id to a
|
|
380
|
+
// different heading, they describe something else and are dropped
|
|
381
|
+
// rather than printed under the new subject's verified fact line.
|
|
382
|
+
.filter((section) => specs.get(section.id)?.heading === section.heading)
|
|
383
|
+
.map((section) => ({ ...(specs.get(section.id) ?? section), claims: section.claims })),
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* The JSON object in a reply that has the given key.
|
|
388
|
+
*
|
|
389
|
+
* A reply may open with prose, and prose may contain braces: "I checked
|
|
390
|
+
* DELETE /users/{id}." Taking the first brace would parse `{id}`, fail, and
|
|
391
|
+
* discard a perfectly good answer after it.
|
|
392
|
+
*/
|
|
393
|
+
export function extractJsonWithKey(text, key) {
|
|
394
|
+
for (let start = text.indexOf('{'); start !== -1; start = text.indexOf('{', start + 1)) {
|
|
395
|
+
const candidate = extractJsonObject(text.slice(start));
|
|
396
|
+
if (candidate === undefined)
|
|
397
|
+
continue;
|
|
398
|
+
try {
|
|
399
|
+
const parsed = JSON.parse(candidate);
|
|
400
|
+
if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed) && key in parsed)
|
|
401
|
+
return parsed;
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
// Not JSON from this brace; try the next one.
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return undefined;
|
|
408
|
+
}
|
|
409
|
+
/** Locate, trim and validate the JSON object in a model response. */
|
|
410
|
+
export function parseUnitBody(text) {
|
|
411
|
+
const raw = extractJsonWithKey(text, 'sections') ?? extractJsonWithKey(text, 'unknowns');
|
|
412
|
+
if (raw === undefined)
|
|
413
|
+
return { ok: false, reason: 'The model returned no JSON object with the expected fields.' };
|
|
414
|
+
const result = unitBodySchema.safeParse(trimOverlong(raw));
|
|
415
|
+
if (!result.success) {
|
|
416
|
+
return {
|
|
417
|
+
ok: false,
|
|
418
|
+
reason: `The model's JSON did not match the required shape: ${result.error.issues
|
|
419
|
+
.slice(0, 5)
|
|
420
|
+
.map((issue) => `${issue.path.join('.') || '(root)'} — ${issue.message}`)
|
|
421
|
+
.join('; ')}`,
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
return { ok: true, body: sanitiseBody(result.data) };
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Reduce everything the model wrote to single lines of plain prose.
|
|
428
|
+
*
|
|
429
|
+
* Done once here, before anything is checked or stored, so the checks and the
|
|
430
|
+
* page see the same text. See sanitize.ts for why a line break is dangerous.
|
|
431
|
+
*/
|
|
432
|
+
function sanitiseBody(body) {
|
|
433
|
+
const seen = new Set();
|
|
434
|
+
return {
|
|
435
|
+
sections: body.sections.map((section) => ({
|
|
436
|
+
id: section.id,
|
|
437
|
+
claims: section.claims
|
|
438
|
+
.map((claim) => ({ text: inlineText(withoutVerdictShape(claim.text)), evidence: claim.evidence }))
|
|
439
|
+
.filter((claim) => claim.text.length > 0),
|
|
440
|
+
})),
|
|
441
|
+
unknowns: body.unknowns
|
|
442
|
+
.map((unknown) => ({
|
|
443
|
+
id: safeId(unknown.id),
|
|
444
|
+
question: inlineText(unknown.question, 500),
|
|
445
|
+
why: inlineText(unknown.why, 500),
|
|
446
|
+
options: unknown.options.map((option) => inlineText(option, 200)).filter((option) => option.length > 0),
|
|
447
|
+
}))
|
|
448
|
+
.filter((unknown) => {
|
|
449
|
+
if (unknown.question.length === 0 || seen.has(unknown.id))
|
|
450
|
+
return false;
|
|
451
|
+
seen.add(unknown.id);
|
|
452
|
+
return true;
|
|
453
|
+
}),
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Keep the first N entries of a list the model over-filled.
|
|
458
|
+
*
|
|
459
|
+
* Every kept entry is still validated in full, so this admits nothing the
|
|
460
|
+
* schema would refuse; it only stops one long list discarding a whole unit.
|
|
461
|
+
*/
|
|
462
|
+
function trimOverlong(raw) {
|
|
463
|
+
if (raw === null || typeof raw !== 'object' || Array.isArray(raw))
|
|
464
|
+
return raw;
|
|
465
|
+
const body = { ...raw };
|
|
466
|
+
if (Array.isArray(body['unknowns']))
|
|
467
|
+
body['unknowns'] = body['unknowns'].slice(0, UNIT_LIMITS.unknowns);
|
|
468
|
+
if (Array.isArray(body['sections'])) {
|
|
469
|
+
body['sections'] = body['sections'].slice(0, UNIT_LIMITS.sections).map((section) => {
|
|
470
|
+
if (section === null || typeof section !== 'object' || Array.isArray(section))
|
|
471
|
+
return section;
|
|
472
|
+
const copy = { ...section };
|
|
473
|
+
if (Array.isArray(copy['claims']))
|
|
474
|
+
copy['claims'] = copy['claims'].slice(0, UNIT_LIMITS.claimsPerSection);
|
|
475
|
+
return copy;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
return body;
|
|
479
|
+
}
|
|
480
|
+
/** Why a claim's citations are unacceptable, or undefined when all are valid. */
|
|
481
|
+
export function citationIssue(claim, ranges) {
|
|
482
|
+
for (const evidence of claim.evidence) {
|
|
483
|
+
const file = normalisePath(evidence.file);
|
|
484
|
+
if (file === undefined)
|
|
485
|
+
return `It cites an invalid or non-relative path: '${evidence.file}'.`;
|
|
486
|
+
const fileRanges = ranges.filter((range) => range.file === file);
|
|
487
|
+
if (fileRanges.length === 0)
|
|
488
|
+
return `It cites '${evidence.file}', which was not in the supplied source.`;
|
|
489
|
+
if (evidence.line === undefined)
|
|
490
|
+
return `It cites '${evidence.file}' without a line number.`;
|
|
491
|
+
const line = evidence.line;
|
|
492
|
+
if (!fileRanges.some((range) => line >= range.startLine && line <= range.endLine)) {
|
|
493
|
+
return `It cites '${evidence.file}:${line}', a line that was not in the supplied source.`;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
function normaliseClaim(claim) {
|
|
499
|
+
return {
|
|
500
|
+
text: claim.text.trim(),
|
|
501
|
+
evidence: claim.evidence.map((item) => ({
|
|
502
|
+
file: normalisePath(item.file) ?? item.file,
|
|
503
|
+
...(item.line === undefined ? {} : { line: item.line }),
|
|
504
|
+
})),
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
function normalisePath(value) {
|
|
508
|
+
const normalised = path.posix.normalize(toPosix(value).replace(/^\.\//, ''));
|
|
509
|
+
if (path.posix.isAbsolute(normalised) || normalised === '..' || normalised.startsWith('../'))
|
|
510
|
+
return undefined;
|
|
511
|
+
return normalised;
|
|
512
|
+
}
|
|
513
|
+
function dedupeUnknowns(unknowns) {
|
|
514
|
+
const seen = new Set();
|
|
515
|
+
return unknowns.filter((unknown) => {
|
|
516
|
+
if (seen.has(unknown.id))
|
|
517
|
+
return false;
|
|
518
|
+
seen.add(unknown.id);
|
|
519
|
+
return true;
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* The second pass: a fresh model call that only judges.
|
|
524
|
+
*
|
|
525
|
+
* It sees the claims and the same excerpts, and returns a verdict per claim.
|
|
526
|
+
* Anything not explicitly `supported` is removed — including a claim the
|
|
527
|
+
* checker simply forgot to rule on, because an unjudged claim has not passed.
|
|
528
|
+
*/
|
|
529
|
+
async function verifyClaims(args) {
|
|
530
|
+
const numbered = [];
|
|
531
|
+
for (const [sectionId, claims] of args.bySection) {
|
|
532
|
+
for (const claim of claims)
|
|
533
|
+
numbered.push({ n: numbered.length + 1, sectionId, claim });
|
|
534
|
+
}
|
|
535
|
+
// Chosen now, so nothing written earlier can contain it: not the repository,
|
|
536
|
+
// not the statements. Only a reply carrying it is the checker's own answer.
|
|
537
|
+
const nonce = randomUUID();
|
|
538
|
+
// The pieces are redacted, never the assembled prompt: a redactor that took
|
|
539
|
+
// the run code for a token would leave the checker unable to return it.
|
|
540
|
+
const clean = (text) => (args.redactSecrets ? redactSecrets(text).text : text);
|
|
541
|
+
const template = await loadPrompt(VERIFY_PROMPT_VERSION);
|
|
542
|
+
const raw = fill(template, {
|
|
543
|
+
NONCE: nonce,
|
|
544
|
+
FACTS: asData(clean(args.spec.facts.trim() === '' ? '_None._' : args.spec.facts)),
|
|
545
|
+
CLAIMS: numbered
|
|
546
|
+
.map((item) => `${item.n}. ${asData(clean(item.claim.text))}\n cites: ${item.claim.evidence
|
|
547
|
+
.map((evidence) => `${evidence.file}:${evidence.line ?? '?'}`)
|
|
548
|
+
.join(', ')}`)
|
|
549
|
+
.join('\n'),
|
|
550
|
+
EVIDENCE: asData(args.evidenceText),
|
|
551
|
+
});
|
|
552
|
+
const prompt = raw;
|
|
553
|
+
const outcome = await args.backend.run({
|
|
554
|
+
prompt,
|
|
555
|
+
cwd: args.root,
|
|
556
|
+
timeoutMs: args.timeoutMs,
|
|
557
|
+
...(args.model === undefined ? {} : { model: args.model }),
|
|
558
|
+
});
|
|
559
|
+
if (!outcome.ok)
|
|
560
|
+
return { ok: false, reason: outcome.reason };
|
|
561
|
+
const verdicts = parseVerdicts(outcome.text, nonce);
|
|
562
|
+
if (verdicts === undefined)
|
|
563
|
+
return { ok: false, reason: 'The checker returned no readable verdicts.' };
|
|
564
|
+
const kept = new Map();
|
|
565
|
+
const removed = [];
|
|
566
|
+
for (const sectionId of args.bySection.keys())
|
|
567
|
+
kept.set(sectionId, []);
|
|
568
|
+
for (const item of numbered) {
|
|
569
|
+
const verdict = verdicts.get(item.n);
|
|
570
|
+
if (verdict?.verdict === 'supported') {
|
|
571
|
+
kept.get(item.sectionId)?.push(item.claim);
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
removed.push({
|
|
575
|
+
sectionId: item.sectionId,
|
|
576
|
+
text: item.claim.text,
|
|
577
|
+
stage: 'verification',
|
|
578
|
+
reason: verdict === undefined
|
|
579
|
+
? 'The checker gave no verdict for it, so it was not confirmed.'
|
|
580
|
+
: `Judged ${verdict.verdict}: ${verdict.reason}`,
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
return { ok: true, kept, removed };
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* The checker's verdicts, or undefined when the reply cannot be trusted.
|
|
587
|
+
*
|
|
588
|
+
* A reply is read only from JSON objects that carry this call's nonce. The
|
|
589
|
+
* statements being judged are quoted in the prompt and may be quoted back, and
|
|
590
|
+
* a statement can be written to look like a verdict object; without the nonce,
|
|
591
|
+
* "the first object with a `verdicts` key" could be one the writer supplied.
|
|
592
|
+
* If the reply holds more than one object with the nonce and they disagree on
|
|
593
|
+
* any statement, it is ambiguous, and an ambiguous reply is not a verdict.
|
|
594
|
+
*/
|
|
595
|
+
export function parseVerdicts(text, nonce) {
|
|
596
|
+
const replies = topLevelJsonObjects(text).filter((candidate) => candidate['nonce'] === nonce && Array.isArray(candidate['verdicts']));
|
|
597
|
+
if (replies.length === 0)
|
|
598
|
+
return undefined;
|
|
599
|
+
const merged = new Map();
|
|
600
|
+
for (const reply of replies) {
|
|
601
|
+
const own = new Map();
|
|
602
|
+
for (const entry of reply['verdicts']) {
|
|
603
|
+
if (entry === null || typeof entry !== 'object')
|
|
604
|
+
continue;
|
|
605
|
+
const record = entry;
|
|
606
|
+
const n = record['n'];
|
|
607
|
+
const verdict = record['verdict'];
|
|
608
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || typeof verdict !== 'string')
|
|
609
|
+
continue;
|
|
610
|
+
if (verdict !== 'supported' && verdict !== 'unsupported' && verdict !== 'contradicted')
|
|
611
|
+
continue;
|
|
612
|
+
// Two verdicts for one statement inside one reply: the stricter stands.
|
|
613
|
+
const previous = own.get(n);
|
|
614
|
+
if (previous === undefined || (previous.verdict === 'supported' && verdict !== 'supported')) {
|
|
615
|
+
own.set(n, { verdict, reason: typeof record['reason'] === 'string' ? inlineText(record['reason'], 400) : '' });
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
for (const [n, verdict] of own) {
|
|
619
|
+
const existing = merged.get(n);
|
|
620
|
+
if (existing !== undefined && existing.verdict !== verdict.verdict)
|
|
621
|
+
return undefined;
|
|
622
|
+
merged.set(n, verdict);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
return merged;
|
|
626
|
+
}
|
|
627
|
+
/** Every JSON object that starts at the top level of a reply, in order. */
|
|
628
|
+
function topLevelJsonObjects(text) {
|
|
629
|
+
const found = [];
|
|
630
|
+
let from = 0;
|
|
631
|
+
for (;;) {
|
|
632
|
+
const start = text.indexOf('{', from);
|
|
633
|
+
if (start === -1)
|
|
634
|
+
break;
|
|
635
|
+
const candidate = extractJsonObject(text.slice(start));
|
|
636
|
+
let parsed;
|
|
637
|
+
if (candidate !== undefined) {
|
|
638
|
+
try {
|
|
639
|
+
parsed = JSON.parse(candidate);
|
|
640
|
+
}
|
|
641
|
+
catch {
|
|
642
|
+
parsed = undefined;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
if (candidate !== undefined && parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
646
|
+
found.push(parsed);
|
|
647
|
+
// Skip past it: objects nested inside are not replies of their own.
|
|
648
|
+
from = start + candidate.length;
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
from = start + 1;
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return found;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Repository or model text, made unable to end the block it is quoted in.
|
|
658
|
+
*
|
|
659
|
+
* Prompts wrap untrusted material between `<<<BEGIN x>>>` and `<<<END x>>>`
|
|
660
|
+
* lines. Text containing such a line could close the block early and continue
|
|
661
|
+
* as if it were instructions, so the marker shape is broken wherever it occurs.
|
|
662
|
+
*/
|
|
663
|
+
function asData(text) {
|
|
664
|
+
return text.replace(/<<<\s*(BEGIN|END)\b/gi, '<< <$1');
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Remove what would make a statement look like a checker's reply.
|
|
668
|
+
*
|
|
669
|
+
* Statements are prose. One that carries `{"verdicts": [...]}` is either an
|
|
670
|
+
* accident or an attempt to answer the question it is about to be asked.
|
|
671
|
+
*/
|
|
672
|
+
function withoutVerdictShape(text) {
|
|
673
|
+
return text.replace(/["'`]\s*(verdicts?|nonce)\s*["'`]\s*:/gi, '$1 -');
|
|
674
|
+
}
|
|
675
|
+
function countLines(contents) {
|
|
676
|
+
if (contents === '')
|
|
677
|
+
return 0;
|
|
678
|
+
const lines = contents.split('\n').length;
|
|
679
|
+
// A final newline ends the last line; it does not start another.
|
|
680
|
+
return contents.endsWith('\n') ? lines - 1 : lines;
|
|
681
|
+
}
|
|
682
|
+
function fill(template, values) {
|
|
683
|
+
// Function replacement: `$&` and friends in source code must stay literal.
|
|
684
|
+
return template.replace(/\{\{([A-Z]+)\}\}/g, (match, key) => values[key] ?? match);
|
|
685
|
+
}
|
|
686
|
+
const promptCache = new Map();
|
|
687
|
+
async function loadPrompt(version) {
|
|
688
|
+
const cached = promptCache.get(version);
|
|
689
|
+
if (cached !== undefined)
|
|
690
|
+
return cached;
|
|
691
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
692
|
+
for (const candidate of [
|
|
693
|
+
path.resolve(here, '..', '..', 'prompts', `${version}.md`),
|
|
694
|
+
path.resolve(here, '..', '..', '..', 'prompts', `${version}.md`),
|
|
695
|
+
]) {
|
|
696
|
+
try {
|
|
697
|
+
const contents = await fs.readFile(candidate, 'utf8');
|
|
698
|
+
promptCache.set(version, contents);
|
|
699
|
+
return contents;
|
|
700
|
+
}
|
|
701
|
+
catch {
|
|
702
|
+
// Try the next location.
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
throw new Error(`Could not locate prompt pack ${version}.md`);
|
|
706
|
+
}
|
|
707
|
+
//# sourceMappingURL=engine.js.map
|