@herbertgao/pi-extensions 2026.9.6 → 2026.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -8
- package/THIRD_PARTY_NOTICES.md +0 -4
- package/node_modules/@narumitw/pi-btw/README.md +2 -0
- package/node_modules/@narumitw/pi-btw/dist/index.ts +284 -365
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +3 -3
- package/node_modules/@narumitw/pi-btw/package.json +52 -53
- package/node_modules/@narumitw/pi-btw/src/bring-to-main.ts +494 -547
- package/node_modules/@narumitw/pi-btw/src/btw.ts +814 -856
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +673 -674
- package/node_modules/@narumitw/pi-btw/src/keybindings.ts +228 -270
- package/node_modules/@narumitw/pi-btw/src/main-tree-picker.ts +309 -318
- package/node_modules/@narumitw/pi-btw/src/menu.ts +416 -454
- package/node_modules/@narumitw/pi-btw/src/settings.ts +203 -219
- package/node_modules/@narumitw/pi-btw/src/side-thread.ts +173 -201
- package/node_modules/@narumitw/pi-btw/src/text.ts +21 -23
- package/node_modules/@narumitw/pi-btw/src/transcript-markdown.ts +65 -0
- package/node_modules/@narumitw/pi-btw/src/transcript-pager.ts +611 -662
- package/node_modules/grok-mermaid/CHANGELOG.md +46 -0
- package/node_modules/grok-mermaid/LICENSE +205 -0
- package/node_modules/grok-mermaid/README.md +191 -0
- package/node_modules/grok-mermaid/dist/ansi.d.ts +16 -0
- package/node_modules/grok-mermaid/dist/ansi.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/ansi.js +23 -0
- package/node_modules/grok-mermaid/dist/ansi.js.map +1 -0
- package/node_modules/grok-mermaid/dist/canvas.d.ts +87 -0
- package/node_modules/grok-mermaid/dist/canvas.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/canvas.js +366 -0
- package/node_modules/grok-mermaid/dist/canvas.js.map +1 -0
- package/node_modules/grok-mermaid/dist/graph.d.ts +74 -0
- package/node_modules/grok-mermaid/dist/graph.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/graph.js +91 -0
- package/node_modules/grok-mermaid/dist/graph.js.map +1 -0
- package/node_modules/grok-mermaid/dist/index.d.ts +32 -0
- package/node_modules/grok-mermaid/dist/index.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/index.js +100 -0
- package/node_modules/grok-mermaid/dist/index.js.map +1 -0
- package/node_modules/grok-mermaid/dist/labels.d.ts +62 -0
- package/node_modules/grok-mermaid/dist/labels.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/labels.js +324 -0
- package/node_modules/grok-mermaid/dist/labels.js.map +1 -0
- package/node_modules/grok-mermaid/dist/layout-seq.d.ts +12 -0
- package/node_modules/grok-mermaid/dist/layout-seq.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/layout-seq.js +194 -0
- package/node_modules/grok-mermaid/dist/layout-seq.js.map +1 -0
- package/node_modules/grok-mermaid/dist/layout.d.ts +87 -0
- package/node_modules/grok-mermaid/dist/layout.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/layout.js +881 -0
- package/node_modules/grok-mermaid/dist/layout.js.map +1 -0
- package/node_modules/grok-mermaid/dist/parse.d.ts +83 -0
- package/node_modules/grok-mermaid/dist/parse.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/parse.js +1151 -0
- package/node_modules/grok-mermaid/dist/parse.js.map +1 -0
- package/node_modules/grok-mermaid/dist/source-box.d.ts +18 -0
- package/node_modules/grok-mermaid/dist/source-box.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/source-box.js +78 -0
- package/node_modules/grok-mermaid/dist/source-box.js.map +1 -0
- package/node_modules/grok-mermaid/dist/types.d.ts +42 -0
- package/node_modules/grok-mermaid/dist/types.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/types.js +1 -0
- package/node_modules/grok-mermaid/dist/types.js.map +1 -0
- package/node_modules/grok-mermaid/dist/width-data.d.ts +2 -0
- package/node_modules/grok-mermaid/dist/width-data.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/width-data.js +994 -0
- package/node_modules/grok-mermaid/dist/width-data.js.map +1 -0
- package/node_modules/grok-mermaid/dist/width.d.ts +18 -0
- package/node_modules/grok-mermaid/dist/width.d.ts.map +1 -0
- package/node_modules/grok-mermaid/dist/width.js +76 -0
- package/node_modules/grok-mermaid/dist/width.js.map +1 -0
- package/node_modules/grok-mermaid/package.json +49 -0
- package/node_modules/grok-mermaid/src/ansi.ts +34 -0
- package/node_modules/grok-mermaid/src/canvas.ts +373 -0
- package/node_modules/grok-mermaid/src/graph.ts +142 -0
- package/node_modules/grok-mermaid/src/index.ts +104 -0
- package/node_modules/grok-mermaid/src/labels.ts +326 -0
- package/node_modules/grok-mermaid/src/layout-seq.ts +203 -0
- package/node_modules/grok-mermaid/src/layout.ts +1015 -0
- package/node_modules/grok-mermaid/src/parse.ts +1189 -0
- package/node_modules/grok-mermaid/src/source-box.ts +89 -0
- package/node_modules/grok-mermaid/src/types.ts +43 -0
- package/node_modules/grok-mermaid/src/width-data.ts +993 -0
- package/node_modules/grok-mermaid/src/width.ts +74 -0
- package/node_modules/pi-lens/CHANGELOG.md +239 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +3 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings.js +30 -4
- package/node_modules/pi-lens/dist/clients/agent-behavior-client.js +2 -0
- package/node_modules/pi-lens/dist/clients/bash-file-access.js +26 -0
- package/node_modules/pi-lens/dist/clients/biome-client.js +1 -1
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +403 -35
- package/node_modules/pi-lens/dist/clients/bootstrap.js +6 -1
- package/node_modules/pi-lens/dist/clients/cascade-format.js +200 -4
- package/node_modules/pi-lens/dist/clients/code-quality-warnings.js +10 -2
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +16 -1
- package/node_modules/pi-lens/dist/clients/diagnostic-dispositions.js +12 -1
- package/node_modules/pi-lens/dist/clients/dispatch/ast-grep-catalog.js +65 -0
- package/node_modules/pi-lens/dist/clients/dispatch/auxiliary-lsp.js +28 -0
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +9 -2
- package/node_modules/pi-lens/dist/clients/dispatch/finding-policy.js +222 -0
- package/node_modules/pi-lens/dist/clients/dispatch/indent-detect.js +389 -13
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +175 -25
- package/node_modules/pi-lens/dist/clients/dispatch/rule-ignores.js +62 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +21 -41
- package/node_modules/pi-lens/dist/clients/dispatch/runners/biome-check.js +6 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +7 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/shfmt.js +2 -12
- package/node_modules/pi-lens/dist/clients/dispatch/runners/tree-sitter.js +2 -21
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +1 -1
- package/node_modules/pi-lens/dist/clients/dispatch/types.js +4 -1
- package/node_modules/pi-lens/dist/clients/disposition-publish.js +1 -0
- package/node_modules/pi-lens/dist/clients/effective-config.js +1 -1
- package/node_modules/pi-lens/dist/clients/file-kinds.js +26 -1
- package/node_modules/pi-lens/dist/clients/file-role.js +21 -21
- package/node_modules/pi-lens/dist/clients/file-utils.js +156 -10
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +56 -9
- package/node_modules/pi-lens/dist/clients/format-service.js +39 -21
- package/node_modules/pi-lens/dist/clients/formatters.js +60 -13
- package/node_modules/pi-lens/dist/clients/generation-guard.js +2 -2
- package/node_modules/pi-lens/dist/clients/git-guard.js +11 -3
- package/node_modules/pi-lens/dist/clients/indent-retarget.js +78 -8
- package/node_modules/pi-lens/dist/clients/installer/index.js +333 -114
- package/node_modules/pi-lens/dist/clients/instance-reaper-state.js +7 -0
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +20 -10
- package/node_modules/pi-lens/dist/clients/language-profile.js +23 -1
- package/node_modules/pi-lens/dist/clients/language-registry.js +5 -1
- package/node_modules/pi-lens/dist/clients/latency-logger.js +4 -1
- package/node_modules/pi-lens/dist/clients/lens-engine.js +12 -3
- package/node_modules/pi-lens/dist/clients/lens-events.js +2 -1
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +79 -0
- package/node_modules/pi-lens/dist/clients/live-bus-emitter.js +2 -1
- package/node_modules/pi-lens/dist/clients/lsp/client.js +25 -21
- package/node_modules/pi-lens/dist/clients/lsp/config.js +2 -2
- package/node_modules/pi-lens/dist/clients/lsp/index.js +7 -0
- package/node_modules/pi-lens/dist/clients/lsp/launch.js +16 -4
- package/node_modules/pi-lens/dist/clients/lsp/server.js +19 -2
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +2 -1
- package/node_modules/pi-lens/dist/clients/lsp-mutation.js +5 -3
- package/node_modules/pi-lens/dist/clients/map-with-concurrency.js +12 -8
- package/node_modules/pi-lens/dist/clients/mcp/session.js +36 -4
- package/node_modules/pi-lens/dist/clients/ndjson-logger.js +24 -7
- package/node_modules/pi-lens/dist/clients/observed-mutation.js +40 -2
- package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +23 -3
- package/node_modules/pi-lens/dist/clients/opengrep-client.js +110 -15
- package/node_modules/pi-lens/dist/clients/path-utils.js +123 -3
- package/node_modules/pi-lens/dist/clients/performance-report.js +5 -1
- package/node_modules/pi-lens/dist/clients/php-cs-fixer-config.js +1 -1
- package/node_modules/pi-lens/dist/clients/pipeline.js +74 -5
- package/node_modules/pi-lens/dist/clients/project-diagnostics/cache.js +37 -5
- package/node_modules/pi-lens/dist/clients/project-diagnostics/fresh-fetch.js +145 -18
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/dead-code.js +4 -1
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +59 -3
- package/node_modules/pi-lens/dist/clients/project-lens-config.js +45 -2
- package/node_modules/pi-lens/dist/clients/read-guard.js +70 -11
- package/node_modules/pi-lens/dist/clients/resource-sampler.js +147 -9
- package/node_modules/pi-lens/dist/clients/ruff-client.js +1 -1
- package/node_modules/pi-lens/dist/clients/runtime-agent-end.js +33 -5
- package/node_modules/pi-lens/dist/clients/runtime-context.js +6 -2
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +77 -7
- package/node_modules/pi-lens/dist/clients/runtime-session.js +21 -2
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +43 -12
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +330 -85
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +147 -17
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +258 -5
- package/node_modules/pi-lens/dist/clients/scratch-tree-policy.js +6 -0
- package/node_modules/pi-lens/dist/clients/session-event-guard.js +50 -5
- package/node_modules/pi-lens/dist/clients/sg-runner.js +23 -11
- package/node_modules/pi-lens/dist/clients/sgconfig.js +79 -2
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +6 -41
- package/node_modules/pi-lens/dist/clients/test-runner-delivery.js +43 -0
- package/node_modules/pi-lens/dist/clients/tool-agreement.js +423 -0
- package/node_modules/pi-lens/dist/clients/tool-config.js +50 -0
- package/node_modules/pi-lens/dist/clients/tool-cwd.js +47 -76
- package/node_modules/pi-lens/dist/clients/tool-policy.js +163 -7
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +120 -0
- package/node_modules/pi-lens/dist/clients/tree-sitter-query-loader.js +127 -189
- package/node_modules/pi-lens/dist/clients/widget-state.js +98 -0
- package/node_modules/pi-lens/dist/clients/word-index.js +5 -2
- package/node_modules/pi-lens/dist/clients/write-ordering-guard.js +7 -0
- package/node_modules/pi-lens/dist/index.js +27416 -24153
- package/node_modules/pi-lens/dist/mcp/server.js +5 -2
- package/node_modules/pi-lens/dist/tools/lens-diagnostic-mark.js +7 -1
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +168 -53
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +244 -72
- package/node_modules/pi-lens/docs/audit1.md +5 -5
- package/node_modules/pi-lens/docs/dependencies.md +11 -0
- package/node_modules/pi-lens/docs/dispositions.md +52 -0
- package/node_modules/pi-lens/docs/environment-variables.md +2 -2
- package/node_modules/pi-lens/docs/features.md +4 -4
- package/node_modules/pi-lens/docs/globalconfig.md +3 -1
- package/node_modules/pi-lens/docs/language-coverage.md +1 -0
- package/node_modules/pi-lens/docs/pi-lens-fixer.md +53 -94
- package/node_modules/pi-lens/docs/pi-lens-investigator.md +43 -38
- package/node_modules/pi-lens/docs/pi-lens-retro.md +97 -0
- package/node_modules/pi-lens/docs/pi-lens-reviewer.md +53 -66
- package/node_modules/pi-lens/docs/release-qa-baseline.md +22 -0
- package/node_modules/pi-lens/docs/settings.md +7 -4
- package/node_modules/pi-lens/docs/tree-sitter_rules_catalog.md +1 -1
- package/node_modules/pi-lens/docs/usage.md +2 -0
- package/node_modules/pi-lens/package.json +1 -1
- package/node_modules/pi-lens/rules/tree-sitter-queries/typescript/sql-injection.yml +24 -12
- package/node_modules/pi-lens/scripts/analyze-pi-lens-logs.mjs +40 -0
- package/node_modules/pi-lens/skills/pi-lens-ast-grep/SKILL.md +15 -0
- package/node_modules/pi-lens/skills/pi-lens-lsp-navigation/SKILL.md +7 -0
- package/package.json +6 -11
- package/node_modules/@luxusai/pi-hindsight/CHANGELOG.md +0 -376
- package/node_modules/@luxusai/pi-hindsight/README.md +0 -92
- package/node_modules/@luxusai/pi-hindsight/docs/adr/001-memory-lifecycle-and-scope.md +0 -56
- package/node_modules/@luxusai/pi-hindsight/docs/adr/002-explicit-routing-strategy-seam.md +0 -169
- package/node_modules/@luxusai/pi-hindsight/docs/adr/003-tui-memory-mode-vocabulary.md +0 -107
- package/node_modules/@luxusai/pi-hindsight/docs/adr/004-lifeos-dual-bank-design.md +0 -89
- package/node_modules/@luxusai/pi-hindsight/docs/adr/005-domain-banks-and-agent-first-surface.md +0 -189
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/assets/logos/pi-hindsight-logo-dark@2x.webp +0 -0
- package/node_modules/@luxusai/pi-hindsight/docs/coding-memory-evaluation.md +0 -54
- package/node_modules/@luxusai/pi-hindsight/docs/compatibility.md +0 -75
- package/node_modules/@luxusai/pi-hindsight/docs/hindsight-core-functions.md +0 -300
- package/node_modules/@luxusai/pi-hindsight/docs/mission-and-mental-model-quality.md +0 -158
- package/node_modules/@luxusai/pi-hindsight/docs/next-opt-out-design.md +0 -164
- package/node_modules/@luxusai/pi-hindsight/docs/risky-memory-modes.md +0 -139
- package/node_modules/@luxusai/pi-hindsight/docs/starter-mental-model-suggestions.md +0 -74
- package/node_modules/@luxusai/pi-hindsight/docs/surface-reference.md +0 -261
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-operations.ts +0 -151
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-selection.ts +0 -18
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-settings-presenter.ts +0 -46
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/bank-templates.ts +0 -383
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/banking.ts +0 -240
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/knowledge-page-seed.ts +0 -176
- package/node_modules/@luxusai/pi-hindsight/extensions/banks/retain-strategies.ts +0 -178
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client-retry.ts +0 -41
- package/node_modules/@luxusai/pi-hindsight/extensions/client/client.ts +0 -386
- package/node_modules/@luxusai/pi-hindsight/extensions/client/fetch-compat.ts +0 -39
- package/node_modules/@luxusai/pi-hindsight/extensions/client/timeout.ts +0 -34
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-defaults.ts +0 -140
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-model.ts +0 -61
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-editing-registry.ts +0 -925
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-field-paths.ts +0 -247
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-normalize.ts +0 -547
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config-writer.ts +0 -480
- package/node_modules/@luxusai/pi-hindsight/extensions/config/config.ts +0 -182
- package/node_modules/@luxusai/pi-hindsight/extensions/config/setup-gate.ts +0 -86
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-execute.ts +0 -1010
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-parse.ts +0 -175
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-plan.ts +0 -425
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-presentation.ts +0 -210
- package/node_modules/@luxusai/pi-hindsight/extensions/imports/import-sessions.ts +0 -817
- package/node_modules/@luxusai/pi-hindsight/extensions/index.ts +0 -25
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/git-seed.ts +0 -319
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-recall.ts +0 -196
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-retain.ts +0 -189
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle-runtime.ts +0 -65
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/memory-lifecycle.ts +0 -260
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/mental-models.ts +0 -244
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/observation-scopes.ts +0 -59
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-cleanup.ts +0 -82
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall-visibility.ts +0 -45
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/recall.ts +0 -331
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-cursor.ts +0 -354
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-job-builder.ts +0 -66
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain-receipts.ts +0 -132
- package/node_modules/@luxusai/pi-hindsight/extensions/lifecycle/retain.ts +0 -228
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-bank-template-operations.ts +0 -74
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-config-operations.ts +0 -16
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-control-operations.ts +0 -648
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-diagnostics-operations.ts +0 -105
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-identity.ts +0 -68
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-service.ts +0 -71
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-operation-types.ts +0 -13
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-recall-operations.ts +0 -162
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-retain-operations.ts +0 -131
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-scope.ts +0 -104
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/memory-session-operations.ts +0 -37
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/operation-catalog.ts +0 -893
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/reflect-presenter.ts +0 -35
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/scope-migrate.ts +0 -177
- package/node_modules/@luxusai/pi-hindsight/extensions/operations/tools.ts +0 -7
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/flush-presenter.ts +0 -21
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/jsonl-queue-store.ts +0 -112
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-delivery.ts +0 -111
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-lock.ts +0 -214
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue-operations.ts +0 -70
- package/node_modules/@luxusai/pi-hindsight/extensions/queue/queue.ts +0 -392
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/bank-template-presentation.ts +0 -45
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/commands.ts +0 -9
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/guided-setup.ts +0 -860
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/prefill-input.ts +0 -105
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-flow.ts +0 -189
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-server-probe.ts +0 -299
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-actions.ts +0 -201
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-facts.ts +0 -47
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-render.ts +0 -239
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui-types.ts +0 -50
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/setup-tui.ts +0 -259
- package/node_modules/@luxusai/pi-hindsight/extensions/tui/tool-presenters.ts +0 -77
- package/node_modules/@luxusai/pi-hindsight/extensions/types.ts +0 -534
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/diagnostics.ts +0 -319
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/messages.ts +0 -325
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/sanitize.ts +0 -42
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-memory-meta.ts +0 -244
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session-operations.ts +0 -56
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/session.ts +0 -50
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-fields.ts +0 -167
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status-health.ts +0 -207
- package/node_modules/@luxusai/pi-hindsight/extensions/utils/status.ts +0 -120
- package/node_modules/@luxusai/pi-hindsight/extensions/version.ts +0 -8
- package/node_modules/@luxusai/pi-hindsight/package.json +0 -118
- package/node_modules/@luxusai/pi-hindsight/skills/hindsight-memory-doctor/SKILL.md +0 -75
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONE filter stack a findings surface applies before a diagnostic reaches
|
|
3
|
+
* the agent: inline `pi-lens-ignore` comments (#442), stored dispositions
|
|
4
|
+
* (#690 — false-positive/suppress/defer), and the project's `.pi-lens.json`
|
|
5
|
+
* `rules.<id>.disable`/`select` policy, in that order.
|
|
6
|
+
*
|
|
7
|
+
* The order is load-bearing and is the one the per-edit dispatcher established:
|
|
8
|
+
* inline suppression first (the user's in-file intent), then the stored marks,
|
|
9
|
+
* then the project policy — so the policy filter sees the same set the per-edit
|
|
10
|
+
* path produces, with no double counting and no policy-rejected leftovers.
|
|
11
|
+
*
|
|
12
|
+
* #3088: these were three separate calls open-coded in `lens-diagnostics.ts`'s
|
|
13
|
+
* `mode=full` merge and nothing at all on the `lens_diagnostics source=lsp` /
|
|
14
|
+
* `lsp_diagnostics` probe lane — so a finding an agent had marked
|
|
15
|
+
* `false-positive` was hidden in `mode=delta`/`mode=full` and re-reported on
|
|
16
|
+
* the lane `skills/pi-lens-lsp-navigation` steers agents to as PRIMARY. Both
|
|
17
|
+
* lanes call this module now: `applyFindingPolicy` for surfaces that already
|
|
18
|
+
* hold dispatch `Diagnostic`s, `applyLspFindingPolicy` for the probe lane,
|
|
19
|
+
* which holds raw `LSPDiagnostic`s.
|
|
20
|
+
*/
|
|
21
|
+
import { applyDispositions, hasAnyDispositionMarks, } from "../diagnostic-dispositions.js";
|
|
22
|
+
import { loadPiLensProjectConfig } from "../project-lens-config.js";
|
|
23
|
+
import { retagAuxiliaryDiagnostics } from "./auxiliary-lsp.js";
|
|
24
|
+
import { applyInlineSuppressions } from "./inline-suppressions.js";
|
|
25
|
+
import { applyRulePolicy, rulePolicyMapFromConfig } from "./rule-policy.js";
|
|
26
|
+
import { convertLspDiagnostics } from "./utils/lsp-diagnostics.js";
|
|
27
|
+
/**
|
|
28
|
+
* Inline suppression → stored dispositions → project rule policy, over
|
|
29
|
+
* diagnostics that already carry dispatch identity (`tool`/`rule`/`line`).
|
|
30
|
+
*/
|
|
31
|
+
export function applyFindingPolicy(diagnostics, options) {
|
|
32
|
+
const inlineKept = applyInlineSuppressions(diagnostics, options.content);
|
|
33
|
+
const disposed = filterDisposed(inlineKept, options);
|
|
34
|
+
return { kept: applyRulePolicy(disposed, options.policyMap), inlineKept };
|
|
35
|
+
}
|
|
36
|
+
/** The project's `.pi-lens.json` `rules.<id>.disable`/`select` policy map.
|
|
37
|
+
* One derivation for every surface that filters by it — `loadPiLensProjectConfig`
|
|
38
|
+
* is mtime-cached, so repeated calls in one sweep cost one stat. */
|
|
39
|
+
export function loadProjectRulePolicyMap(cwd) {
|
|
40
|
+
return rulePolicyMapFromConfig(loadPiLensProjectConfig(cwd).rules);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Disposition filter over the candidate identities a mark can carry.
|
|
44
|
+
*
|
|
45
|
+
* With no `identities` provider this is `applyDispositions` on the diagnostics
|
|
46
|
+
* themselves — one anchor pair per diagnostic, the behavior every existing
|
|
47
|
+
* caller has. With one, the SAME `applyDispositions` runs over the flattened
|
|
48
|
+
* candidate list — no second strict/weak implementation to drift away from it
|
|
49
|
+
* (#1617's single-source rule) — and a diagnostic drops when ANY of its
|
|
50
|
+
* candidate identities was disposed.
|
|
51
|
+
*/
|
|
52
|
+
function filterDisposed(diagnostics, options) {
|
|
53
|
+
const identities = options.identities;
|
|
54
|
+
if (!identities) {
|
|
55
|
+
return applyDispositions(diagnostics, options.cwd, options.filePath, options.content);
|
|
56
|
+
}
|
|
57
|
+
// Same zero-I/O hoist the cache-only modes use (#1625 F2): with no marks at
|
|
58
|
+
// all there is nothing a candidate expansion could match, so the probe lane
|
|
59
|
+
// pays no per-finding allocation for the overwhelmingly common empty store.
|
|
60
|
+
if (!diagnostics.length || !hasAnyDispositionMarks(options.cwd)) {
|
|
61
|
+
return diagnostics;
|
|
62
|
+
}
|
|
63
|
+
const expanded = diagnostics.flatMap((diagnostic) => identities(diagnostic).map((identity) => ({
|
|
64
|
+
diagnostic,
|
|
65
|
+
candidate: {
|
|
66
|
+
...identity,
|
|
67
|
+
message: diagnostic.message,
|
|
68
|
+
...(diagnostic.line !== undefined && { line: diagnostic.line }),
|
|
69
|
+
...(diagnostic.semantic !== undefined && {
|
|
70
|
+
semantic: diagnostic.semantic,
|
|
71
|
+
}),
|
|
72
|
+
},
|
|
73
|
+
})));
|
|
74
|
+
const survivors = new Set(applyDispositions(expanded.map((entry) => entry.candidate), options.cwd, options.filePath, options.content));
|
|
75
|
+
const disposed = new Set();
|
|
76
|
+
for (const entry of expanded) {
|
|
77
|
+
if (!survivors.has(entry.candidate))
|
|
78
|
+
disposed.add(entry.diagnostic);
|
|
79
|
+
}
|
|
80
|
+
return disposed.size === 0
|
|
81
|
+
? diagnostics
|
|
82
|
+
: diagnostics.filter((diagnostic) => !disposed.has(diagnostic));
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* #3088 / AGENTS.md shape 26: the identity spellings a mark against a probe
|
|
86
|
+
* finding can carry, derived from the surfaces that RENDER it rather than
|
|
87
|
+
* guessed:
|
|
88
|
+
*
|
|
89
|
+
* - `convertLspDiagnostics` + `retagAuxiliaryDiagnostics` — the canonical
|
|
90
|
+
* dispatch identity (`tool: "lsp"`, or the auxiliary's own id, and
|
|
91
|
+
* `rule: "<source>:<code>"`). This is what the widget footer, `mode=delta`
|
|
92
|
+
* and `mode=full` render, so it is the spelling of a mark made anywhere
|
|
93
|
+
* else in the session.
|
|
94
|
+
* - `formatDiag` in `tools/lsp-diagnostics.ts` — the probe's OWN text render
|
|
95
|
+
* is `[<source>] (<code>)`, so a mark made from THIS lane's output carries
|
|
96
|
+
* `tool: "<source>"`, `rule: "<code>"`.
|
|
97
|
+
*
|
|
98
|
+
* plus, for each, the form with `tool` omitted: `lens_diagnostic_mark`'s
|
|
99
|
+
* `tool` parameter is optional and #3088's own reproduction omits it. A
|
|
100
|
+
* single-spelling filter honors a mark made on one surface while re-reporting
|
|
101
|
+
* the same finding when the mark was made on the other, which is exactly the
|
|
102
|
+
* non-convergence #3088 reported.
|
|
103
|
+
*/
|
|
104
|
+
function probeIdentities(canonical, raw) {
|
|
105
|
+
const rendered = [
|
|
106
|
+
[canonical.tool, canonical.rule],
|
|
107
|
+
];
|
|
108
|
+
if (raw !== undefined &&
|
|
109
|
+
(raw.source !== undefined || raw.code !== undefined)) {
|
|
110
|
+
rendered.push([
|
|
111
|
+
raw.source,
|
|
112
|
+
raw.code === undefined ? undefined : String(raw.code),
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
115
|
+
return expandRenderedIdentities(rendered);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* #3102: the identity spellings a mark against a surface that renders a
|
|
119
|
+
* finding's RULE but never its TOOL can carry — the turn-end late-auxiliary
|
|
120
|
+
* advisory (`<file>:<line>:<col> [<rule>] <message>`) and the cold-neighbour
|
|
121
|
+
* cascade run (`line N, col M rule=<rule>: <message>`). Both print the
|
|
122
|
+
* canonical dispatch `rule`, so a mark made ELSEWHERE (the widget, `mode=full`)
|
|
123
|
+
* carries the full `(tool, rule)` pair while a mark made from the surface's own
|
|
124
|
+
* output has no tool to pass on — and `lens_diagnostic_mark`'s `tool` parameter
|
|
125
|
+
* is optional. Honoring only one of the two spellings is exactly the
|
|
126
|
+
* non-convergence #3088 reported, so both go through the SAME expansion
|
|
127
|
+
* `probeIdentities` uses.
|
|
128
|
+
*/
|
|
129
|
+
export function renderedRuleIdentities(diagnostic) {
|
|
130
|
+
return expandRenderedIdentities([[diagnostic.tool, diagnostic.rule]]);
|
|
131
|
+
}
|
|
132
|
+
/** Every rendered `(tool, rule)` spelling plus the `tool`-omitted form of
|
|
133
|
+
* each, de-duplicated, in order. One derivation for both callers. */
|
|
134
|
+
function expandRenderedIdentities(rendered) {
|
|
135
|
+
const out = [];
|
|
136
|
+
const seen = new Set();
|
|
137
|
+
for (const [tool, rule] of rendered) {
|
|
138
|
+
// Both spellings also in the `tool`-omitted form the mark tool admits.
|
|
139
|
+
for (const candidateTool of [tool, undefined]) {
|
|
140
|
+
const key = `${candidateTool ?? ""}\u0000${rule ?? ""}`;
|
|
141
|
+
if (seen.has(key))
|
|
142
|
+
continue;
|
|
143
|
+
seen.add(key);
|
|
144
|
+
out.push({
|
|
145
|
+
...(candidateTool !== undefined && { tool: candidateTool }),
|
|
146
|
+
...(rule !== undefined && { rule }),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
/* No drop COUNT is returned here on purpose (round 2 F1): the number an agent
|
|
153
|
+
* is shown has to be scoped to that caller's severity threshold, and this
|
|
154
|
+
* module must not learn about a threshold its other caller (`mode=full`) does
|
|
155
|
+
* not have. `kept` versus the input is all a caller needs to derive its own. */
|
|
156
|
+
/**
|
|
157
|
+
* The probe lane's entry point: the same stack, over RAW LSP diagnostics.
|
|
158
|
+
*
|
|
159
|
+
* Identity comes from the two shared converters the widget footer already runs
|
|
160
|
+
* on this very path (`convertLspDiagnostics` + `retagAuxiliaryDiagnostics`),
|
|
161
|
+
* never a third derivation — a second copy of the conversion giving the same
|
|
162
|
+
* finding a different `rule`, and orphaning every mark against it, is the #692
|
|
163
|
+
* defect itself.
|
|
164
|
+
*
|
|
165
|
+
* `retagAuxiliaryDiagnostics` is used for its in-place re-tag only; its own
|
|
166
|
+
* drop set (native aux comments, `skipTestFiles`) is deliberately ignored here
|
|
167
|
+
* because `applyAuxiliarySuppressions` already applied exactly that filter to
|
|
168
|
+
* these diagnostics at collection time — re-dropping would double-apply a
|
|
169
|
+
* filter this route owns upstream.
|
|
170
|
+
*/
|
|
171
|
+
export function applyLspFindingPolicy(diagnostics, options) {
|
|
172
|
+
if (!diagnostics.length)
|
|
173
|
+
return { kept: diagnostics, inlineKept: diagnostics };
|
|
174
|
+
const content = options.content ?? "";
|
|
175
|
+
// `convertLspDiagnostics` drops entries with no start line, which would
|
|
176
|
+
// break the 1:1 index alignment `retagAuxiliaryDiagnostics` and the map-back
|
|
177
|
+
// below depend on. Partition first so the converted array IS aligned with
|
|
178
|
+
// `anchored`; a line-less entry passes straight through (it carries no line
|
|
179
|
+
// for an anchor to bind to, and dropping it would silently lose a finding
|
|
180
|
+
// this filter has no claim over).
|
|
181
|
+
const anchored = [];
|
|
182
|
+
for (const diagnostic of diagnostics) {
|
|
183
|
+
if (diagnostic.range?.start?.line !== undefined)
|
|
184
|
+
anchored.push(diagnostic);
|
|
185
|
+
}
|
|
186
|
+
if (!anchored.length)
|
|
187
|
+
return { kept: diagnostics, inlineKept: diagnostics };
|
|
188
|
+
const converted = convertLspDiagnostics(anchored, options.filePath);
|
|
189
|
+
retagAuxiliaryDiagnostics(converted, anchored, content, {
|
|
190
|
+
cwd: options.cwd,
|
|
191
|
+
fileRole: options.fileRole,
|
|
192
|
+
});
|
|
193
|
+
// `convertLspDiagnostics` maps its (pre-filtered) input 1:1, so `converted[i]`
|
|
194
|
+
// belongs to `anchored[i]`. Pair them up front and work from the pairing: a
|
|
195
|
+
// converted entry with no counterpart is simply never paired, so it can never
|
|
196
|
+
// be dropped — fail open, never hide a finding this filter could not identify.
|
|
197
|
+
const rawByConverted = new Map();
|
|
198
|
+
for (const [index, diagnostic] of converted.entries()) {
|
|
199
|
+
const raw = anchored[index];
|
|
200
|
+
if (raw !== undefined)
|
|
201
|
+
rawByConverted.set(diagnostic, raw);
|
|
202
|
+
}
|
|
203
|
+
const { kept, inlineKept } = applyFindingPolicy(converted, {
|
|
204
|
+
cwd: options.cwd,
|
|
205
|
+
filePath: options.filePath,
|
|
206
|
+
content,
|
|
207
|
+
policyMap: options.policyMap,
|
|
208
|
+
identities: (diagnostic) => probeIdentities(diagnostic, rawByConverted.get(diagnostic)),
|
|
209
|
+
});
|
|
210
|
+
const survivorsOf = (survivors) => {
|
|
211
|
+
if (survivors.length === converted.length)
|
|
212
|
+
return diagnostics;
|
|
213
|
+
const keptConverted = new Set(survivors);
|
|
214
|
+
const dropped = new Set();
|
|
215
|
+
for (const [diagnostic, raw] of rawByConverted) {
|
|
216
|
+
if (!keptConverted.has(diagnostic))
|
|
217
|
+
dropped.add(raw);
|
|
218
|
+
}
|
|
219
|
+
return diagnostics.filter((d) => !dropped.has(d));
|
|
220
|
+
};
|
|
221
|
+
return { kept: survivorsOf(kept), inlineKept: survivorsOf(inlineKept) };
|
|
222
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
const DEFAULT_INDENTATION = { style: "space", width: 2 };
|
|
2
2
|
/**
|
|
3
3
|
* Infer the prevailing indentation convention from lines that are indented.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Formatter callers use it only as a conservative fallback when the repository
|
|
5
|
+
* has no config. It has two pieces of lexical knowledge: the `/* … *\/` block
|
|
6
|
+
* comment and the multi-line template literal, whose interior lines are
|
|
7
|
+
* alignment rather than nesting; everything else is counted as written.
|
|
6
8
|
*/
|
|
7
9
|
export function detectIndentation(content) {
|
|
8
|
-
const lines = content.split(/\r?\n/);
|
|
10
|
+
const lines = structuralLines(content.split(/\r?\n/));
|
|
9
11
|
const tabs = lines.filter((line) => /^\t+\S/.test(line)).length;
|
|
10
12
|
const spaceCounts = lines
|
|
11
13
|
.map((line) => line.match(/^ +(?=\S)/)?.[0].length ?? 0)
|
|
@@ -15,20 +17,394 @@ export function detectIndentation(content) {
|
|
|
15
17
|
if (tabs > spaceCounts.length)
|
|
16
18
|
return { style: "tab", width: 1 };
|
|
17
19
|
if (spaceCounts.length > tabs) {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const minimum = Math.min(...spaceCounts);
|
|
21
|
+
// 0 is GCD's identity, so seeding the fold both satisfies "reduce needs an
|
|
22
|
+
// initial value" and leaves every result unchanged.
|
|
23
|
+
const gcd = spaceCounts.reduce((unit, count) => greatestCommonDivisor(unit, count), 0);
|
|
24
|
+
const nonBlank = lines
|
|
25
|
+
.map((line) => line.match(/^( *)\S/)?.[1]?.length)
|
|
26
|
+
.filter((count) => count !== undefined);
|
|
27
|
+
const hasStructuralBoundary = nonBlank.some((count, index) => {
|
|
28
|
+
const previous = nonBlank[index - 1];
|
|
29
|
+
return count === minimum && previous !== undefined && previous < minimum;
|
|
30
|
+
});
|
|
31
|
+
if (hasStructuralBoundary && minimum <= 8) {
|
|
32
|
+
return { style: "space", width: minimum };
|
|
33
|
+
}
|
|
34
|
+
// A continuation line can be the shallowest observed line even though it
|
|
35
|
+
// is not one indentation unit from the surrounding structure. GCD gives
|
|
36
|
+
// those aligned runs their structural unit (for example 4/6 -> 2).
|
|
37
|
+
if (gcd < minimum && gcd <= 8) {
|
|
38
|
+
return { style: "space", width: gcd };
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
// A file containing only nested runs (for example 6/12 spaces) has no
|
|
41
|
+
// evidence that its first run is one unit rather than three or six. Do
|
|
42
|
+
// not impose a formatter style on that ambiguous evidence.
|
|
43
|
+
return undefined;
|
|
29
44
|
}
|
|
30
45
|
return DEFAULT_INDENTATION;
|
|
31
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Whether the line opens a block comment that it does not also close. A `/*`
|
|
49
|
+
* that follows a `//` on the same line is inside a line comment, not an
|
|
50
|
+
* opener; a `//` that follows the `/*` (a URL in a banner) is not.
|
|
51
|
+
*/
|
|
52
|
+
function opensBlockComment(line) {
|
|
53
|
+
const blockAt = line.indexOf("/*");
|
|
54
|
+
if (blockAt < 0)
|
|
55
|
+
return false;
|
|
56
|
+
const lineAt = line.indexOf("//");
|
|
57
|
+
if (lineAt >= 0 && lineAt < blockAt)
|
|
58
|
+
return false;
|
|
59
|
+
return line.indexOf("*/", blockAt + 2) < 0;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* One boolean per line: true when the line sits *inside* a terminated block
|
|
63
|
+
* comment, so its leading space is alignment on the opener's `*` column, not
|
|
64
|
+
* a nesting unit. The opener line itself is false (its own indentation *is*
|
|
65
|
+
* structural). An opener that never closes was a `/*` inside a string or a
|
|
66
|
+
* regex, so its lines are left false rather than silently swallowed.
|
|
67
|
+
*
|
|
68
|
+
* Shared by {@link structuralLines} (drops the lines from indentation
|
|
69
|
+
* detection's own evidence — a top-level JSDoc otherwise contributes a run
|
|
70
|
+
* of 1-space lines, so a 2- or 4-space file with doc comments reads as width
|
|
71
|
+
* 1 and a tab file with a top-level JSDoc reads as spaces, #3039 F1/F2) and
|
|
72
|
+
* by `clients/indent-retarget.ts`'s `retargetReplacementIndentation`, which
|
|
73
|
+
* must not pick its base nesting unit from a comment's alignment column
|
|
74
|
+
* either (#3052) — one lexer for "which lines carry structure", not two.
|
|
75
|
+
*/
|
|
76
|
+
export function blockCommentInteriorMask(lines) {
|
|
77
|
+
const mask = Array.from({ length: lines.length }, () => false);
|
|
78
|
+
let pendingStart = -1;
|
|
79
|
+
for (const [i, line] of lines.entries()) {
|
|
80
|
+
if (pendingStart >= 0) {
|
|
81
|
+
mask[i] = true;
|
|
82
|
+
if (line.includes("*/"))
|
|
83
|
+
pendingStart = -1;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (opensBlockComment(line))
|
|
87
|
+
pendingStart = i;
|
|
88
|
+
}
|
|
89
|
+
if (pendingStart >= 0) {
|
|
90
|
+
for (let i = pendingStart + 1; i < lines.length; i += 1)
|
|
91
|
+
mask[i] = false;
|
|
92
|
+
}
|
|
93
|
+
return mask;
|
|
94
|
+
}
|
|
95
|
+
/** Whether `stack` holds a frame the mask (or its fail-safe) must treat as
|
|
96
|
+
* "inside a template" — every frame except `"block"`. A `/* … *\/` comment
|
|
97
|
+
* nested in the tracked span (plain code, or inside a `${ … }` substitution)
|
|
98
|
+
* is not itself template evidence; {@link blockCommentInteriorMask} already
|
|
99
|
+
* excludes a top-level block comment's own lines. */
|
|
100
|
+
function hasLiveFrame(stack) {
|
|
101
|
+
return stack.some((frame) => frame.kind !== "block");
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Advance a lexical stack over one line of source, mutating it in place.
|
|
105
|
+
* Shared by {@link templateLiteralInteriorMask}'s per-line pass. `stack`
|
|
106
|
+
* empty means plain code; a `"template"` frame means raw template text; an
|
|
107
|
+
* `"expr"` frame means code inside a `${ … }` substitution, with its own
|
|
108
|
+
* brace-depth counter so a nested `{`/`}` (an object literal, a block) does
|
|
109
|
+
* not close the substitution early — only the brace that returns the counter
|
|
110
|
+
* to 0, the one that matches the `${`, does; a `"block"` frame means a
|
|
111
|
+
* `/* … *\/` comment, so a JSDoc's own backtick (a fenced code sample, an
|
|
112
|
+
* inline `` `x` ``) never opens a tracked template that then swallows real
|
|
113
|
+
* code up to whatever later backtick happens to close it (#3059 review F1,
|
|
114
|
+
* AGENTS.md shape 43 — prose mistaken for executable structure).
|
|
115
|
+
*
|
|
116
|
+
* A backtick, `//`, `/*`, or quote character means nothing while `//` has
|
|
117
|
+
* already started a line comment, a `/* … *\/` comment is open, or a quoted
|
|
118
|
+
* string is open, so all three states resolve before the general
|
|
119
|
+
* per-character switch (line comments run to EOL; quoted strings skip
|
|
120
|
+
* everything up to their own unescaped terminator, taking a backtick inside
|
|
121
|
+
* them out of consideration the same way; a block comment skips everything,
|
|
122
|
+
* backticks included, up to its own `*\/`, possibly spanning lines).
|
|
123
|
+
*
|
|
124
|
+
* A regex literal (`` /pattern/flags ``) has its own resolution: the same
|
|
125
|
+
* class of problem as a `/* … *\/` comment or a quoted string, since a
|
|
126
|
+
* backtick or `/*` inside one must not be read as a real opener either
|
|
127
|
+
* (#3120). Disambiguating `/` from division in general needs a real
|
|
128
|
+
* tokenizer with full grammar context — a first-pass heuristic tried here
|
|
129
|
+
* over-declined the corpus 54 files vs 5 for a real fix, so {@link
|
|
130
|
+
* isRegexOpenerPosition} only recognises `/` as an opener in positions
|
|
131
|
+
* where JS grammar makes a value expression, never a divisor: immediately
|
|
132
|
+
* after `(`, `,`, `=`, `:`, `[`, `!`, `&`, `|`, `?`, a `return`/`typeof`/
|
|
133
|
+
* `case` keyword, or at line start. (`{`, `}`, and `;` were tried too —
|
|
134
|
+
* dropped, not just unused: `}` is grammatically unsound on its own
|
|
135
|
+
* (`x = {a:1} / 2` is division, not a regex opener, and both sibling
|
|
136
|
+
* lexers in this tree — `tests/support/sweep-kit.ts`,
|
|
137
|
+
* `scripts/check-pr-body.mjs`'s `blankCommentsAndStrings` — exclude it for
|
|
138
|
+
* that reason), and measurement showed `{`/`}`/`;` firing 10/0/6 times
|
|
139
|
+
* across a 25,553-file corpus (own tree plus `node_modules`, every
|
|
140
|
+
* extension biome/prettier/ruff/shfmt format) with zero verdict
|
|
141
|
+
* differences either way — see #3120 PR round 2.) Anywhere else (after an
|
|
142
|
+
* identifier, a digit, `)`, `]`, a string, or a template) is left alone
|
|
143
|
+
* exactly as before this state existed — division stays division, so the
|
|
144
|
+
* gate can only ever add masking correctness, never remove it, MODULO the
|
|
145
|
+
* closing-scan's own correctness (see {@link skipRegexLiteral}'s doc
|
|
146
|
+
* comment: the position gate alone is not sufficient — a misfired skip
|
|
147
|
+
* that swallows an odd number of backticks can still invert parity for
|
|
148
|
+
* the rest of the file; measured against the same corpus, this changed
|
|
149
|
+
* 0 files' verdicts, but 158 of 181 gate firings on the corpus's 882
|
|
150
|
+
* Markdown files alone accepted a false close before the closing-scan's
|
|
151
|
+
* own tightening below cut that to 19). A recognised opener is skipped to its own
|
|
152
|
+
* closing `/` (honouring `[...]` character classes and `\` escapes) by
|
|
153
|
+
* {@link skipRegexLiteral} the same way `skipQuoted` skips a string;
|
|
154
|
+
* everything inside — backticks, `/*`, quotes — is consumed without
|
|
155
|
+
* touching `stack`. A regex literal cannot itself contain a literal
|
|
156
|
+
* newline, so this resolves entirely within one line; the position gate
|
|
157
|
+
* fires on every `/` that starts a line (for instance a Markdown path
|
|
158
|
+
* like `/src`), not only on shapes that can actually close as a regex —
|
|
159
|
+
* it is the closing scan's own `-1` fallback, not the gate, that makes an
|
|
160
|
+
* unclosed or wrongly-shaped match safe.
|
|
161
|
+
*/
|
|
162
|
+
function advanceTemplateState(line, stack) {
|
|
163
|
+
let j = 0;
|
|
164
|
+
while (j < line.length) {
|
|
165
|
+
const top = stack[stack.length - 1];
|
|
166
|
+
if (top?.kind === "template") {
|
|
167
|
+
if (line[j] === "\\") {
|
|
168
|
+
j += 2; // an escaped character, including an escaped backtick, \`
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (line.startsWith("${", j)) {
|
|
172
|
+
stack.push({ kind: "expr", braceDepth: 1 });
|
|
173
|
+
j += 2;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (line[j] === "`") {
|
|
177
|
+
stack.pop();
|
|
178
|
+
j += 1;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
j += 1;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (top?.kind === "block") {
|
|
185
|
+
const closeAt = line.indexOf("*/", j);
|
|
186
|
+
if (closeAt < 0)
|
|
187
|
+
return; // still inside the comment at EOL
|
|
188
|
+
stack.pop();
|
|
189
|
+
j = closeAt + 2;
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
// Plain code, at the top level or inside a `${ … }` substitution.
|
|
193
|
+
if (line.startsWith("//", j))
|
|
194
|
+
return; // rest of line is a line comment
|
|
195
|
+
if (line.startsWith("/*", j)) {
|
|
196
|
+
stack.push({ kind: "block" });
|
|
197
|
+
j += 2;
|
|
198
|
+
continue;
|
|
199
|
+
}
|
|
200
|
+
if (line[j] === "/" && isRegexOpenerPosition(line, j)) {
|
|
201
|
+
const after = skipRegexLiteral(line, j);
|
|
202
|
+
if (after >= 0) {
|
|
203
|
+
j = after;
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
// No closing `/` before EOL: not actually a regex literal at this
|
|
207
|
+
// position (the heuristic misfired, or the line just ends mid-token).
|
|
208
|
+
// Fall through and scan `/` as an ordinary character, unchanged from
|
|
209
|
+
// before this state existed.
|
|
210
|
+
}
|
|
211
|
+
const ch = line[j];
|
|
212
|
+
if (ch === '"' || ch === "'") {
|
|
213
|
+
j = skipQuoted(line, j, ch);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if (ch === "`") {
|
|
217
|
+
stack.push({ kind: "template" });
|
|
218
|
+
j += 1;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
if (top?.kind === "expr") {
|
|
222
|
+
if (ch === "{") {
|
|
223
|
+
top.braceDepth += 1;
|
|
224
|
+
j += 1;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (ch === "}") {
|
|
228
|
+
top.braceDepth -= 1;
|
|
229
|
+
j += 1;
|
|
230
|
+
if (top.braceDepth === 0)
|
|
231
|
+
stack.pop();
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
j += 1;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** Skip a single- or double-quoted string starting at `quote`, honoring `\`
|
|
239
|
+
* escapes, so a backtick (or anything else) inside it is never inspected. */
|
|
240
|
+
function skipQuoted(line, start, quote) {
|
|
241
|
+
let j = start + 1;
|
|
242
|
+
while (j < line.length) {
|
|
243
|
+
if (line[j] === "\\") {
|
|
244
|
+
j += 2;
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (line[j] === quote)
|
|
248
|
+
return j + 1;
|
|
249
|
+
j += 1;
|
|
250
|
+
}
|
|
251
|
+
return line.length; // unterminated on this line; nothing more to find
|
|
252
|
+
}
|
|
253
|
+
/** The set of characters that make a following `/` unambiguous — JS grammar
|
|
254
|
+
* only accepts a value expression there, never a divisor. */
|
|
255
|
+
const REGEX_OPENER_PUNCTUATION = new Set([
|
|
256
|
+
"(",
|
|
257
|
+
",",
|
|
258
|
+
"=",
|
|
259
|
+
":",
|
|
260
|
+
"[",
|
|
261
|
+
"!",
|
|
262
|
+
"&",
|
|
263
|
+
"|",
|
|
264
|
+
"?",
|
|
265
|
+
]);
|
|
266
|
+
/** A `return`, `typeof`, or `case` keyword, word-bounded, immediately before
|
|
267
|
+
* (modulo trailing whitespace) the position under test. */
|
|
268
|
+
const REGEX_OPENER_KEYWORD = /(?:^|[^A-Za-z0-9_$])(?:return|typeof|case)$/;
|
|
269
|
+
/**
|
|
270
|
+
* Whether `line[at]` (a `/`) sits in a position where JS grammar makes it a
|
|
271
|
+
* regex-literal opener rather than division: immediately after one of
|
|
272
|
+
* {@link REGEX_OPENER_PUNCTUATION}, a `return`/`typeof`/`case` keyword, or
|
|
273
|
+
* at the start of the line (#3120). Deliberately narrower than every legal
|
|
274
|
+
* regex position (an arrow function's `=>`, for instance, is not
|
|
275
|
+
* recognised) — a missed opener leaves `/` division-shaped exactly like
|
|
276
|
+
* before this state existed, so under-recognition is inert while
|
|
277
|
+
* over-recognition would corrupt real code.
|
|
278
|
+
*/
|
|
279
|
+
function isRegexOpenerPosition(line, at) {
|
|
280
|
+
const before = line.slice(0, at).replace(/[ \t]+$/, "");
|
|
281
|
+
if (before === "")
|
|
282
|
+
return true; // line start (modulo leading whitespace)
|
|
283
|
+
if (REGEX_OPENER_KEYWORD.test(before))
|
|
284
|
+
return true;
|
|
285
|
+
return REGEX_OPENER_PUNCTUATION.has(before.at(-1) ?? "");
|
|
286
|
+
}
|
|
287
|
+
/** Regex flag letters JS accepts after a literal's closing `/`. */
|
|
288
|
+
const REGEX_FLAG_CHARS = "dgimsuvy";
|
|
289
|
+
/**
|
|
290
|
+
* Skip a regex literal starting at its opening `/` (`start`), honoring
|
|
291
|
+
* `[...]` character classes (a `/` or unescaped `]` inside one closes
|
|
292
|
+
* nothing) and `\` escapes, mirroring {@link skipQuoted}. Returns the index
|
|
293
|
+
* just past the closing `/`, or -1 if none is found before EOL — a regex
|
|
294
|
+
* literal cannot contain a literal newline, so an unclosed scan means this
|
|
295
|
+
* was not actually one.
|
|
296
|
+
*
|
|
297
|
+
* The position gate ({@link isRegexOpenerPosition}) alone is not enough:
|
|
298
|
+
* it fires on every `/` that starts a value-expression position, including
|
|
299
|
+
* prose that merely looks like one — a Markdown line like `` Layout: /src
|
|
300
|
+
* `bin/cli` and friends. `` gates on the `:` before `/src`, and the first
|
|
301
|
+
* `/` found afterward (inside the backticked `` `bin/cli` ``) would
|
|
302
|
+
* otherwise read as a valid close, swallowing the backtick and inverting
|
|
303
|
+
* template-tracking parity for the rest of the file. A closing `/` is
|
|
304
|
+
* accepted only when it is followed by zero or more regex flag letters
|
|
305
|
+
* ({@link REGEX_FLAG_CHARS}) and then a NON-IDENTIFIER character (or
|
|
306
|
+
* EOL) — `/src/cli` and friends` has an identifier character (`c`) right
|
|
307
|
+
* after the candidate close, which a real regex literal's own syntax
|
|
308
|
+
* forbids (flags must be immediately followed by a statement terminator,
|
|
309
|
+
* not more identifier text), so it is rejected and the scan returns -1
|
|
310
|
+
* instead.
|
|
311
|
+
*
|
|
312
|
+
* This narrows the false-close family, it does not close it: when what
|
|
313
|
+
* follows the false close is instead a NON-identifier character (a
|
|
314
|
+
* backtick, a space, `)`, `.` — anything outside `[A-Za-z0-9_$]`), this
|
|
315
|
+
* check does not fire either, and the same corruption is still possible
|
|
316
|
+
* in principle. Round 3 F2 measured the residual directly rather than
|
|
317
|
+
* asserting it away: of the 19 regex-shaped matches that still survive
|
|
318
|
+
* in the corpus's Markdown files after this check (round 2's own count),
|
|
319
|
+
* NONE has a backtick inside its matched span — every survivor is either
|
|
320
|
+
* a genuine regex literal in a fenced code sample or ASCII-art/prose that
|
|
321
|
+
* happens to satisfy the grammar without ever touching a `` ` `` — so the
|
|
322
|
+
* residual is 0 of 25,553 corpus files and 0 of those 19 matches, not
|
|
323
|
+
* merely untested. The only check that closes the family completely is
|
|
324
|
+
* counting backticks in the consumed span and rejecting an odd count —
|
|
325
|
+
* which is exactly the shape a real `` /`foo`/ `` regex literal (a
|
|
326
|
+
* pattern that legitimately contains backticks) also has, so rejecting
|
|
327
|
+
* it would re-introduce the over-decline this PR's own first-pass
|
|
328
|
+
* heuristic was rejected for (#3120's own history). Left as a measured,
|
|
329
|
+
* documented limit rather than tightened further.
|
|
330
|
+
*/
|
|
331
|
+
function skipRegexLiteral(line, start) {
|
|
332
|
+
let j = start + 1;
|
|
333
|
+
let inClass = false;
|
|
334
|
+
while (j < line.length) {
|
|
335
|
+
const c = line[j];
|
|
336
|
+
if (c === "\\") {
|
|
337
|
+
j += 2;
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
if (inClass) {
|
|
341
|
+
if (c === "]")
|
|
342
|
+
inClass = false;
|
|
343
|
+
j += 1;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
if (c === "[") {
|
|
347
|
+
inClass = true;
|
|
348
|
+
j += 1;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (c === "/") {
|
|
352
|
+
let k = j + 1;
|
|
353
|
+
while (k < line.length && REGEX_FLAG_CHARS.includes(line[k] ?? ""))
|
|
354
|
+
k += 1;
|
|
355
|
+
if (k < line.length && /[A-Za-z0-9_$]/.test(line[k] ?? ""))
|
|
356
|
+
return -1;
|
|
357
|
+
return j + 1;
|
|
358
|
+
}
|
|
359
|
+
j += 1;
|
|
360
|
+
}
|
|
361
|
+
return -1; // unterminated on this line; not a regex literal after all
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* One boolean per line: true when the line sits *inside* a multi-line
|
|
365
|
+
* template literal (or a `${ … }` substitution nested in one), so its leading
|
|
366
|
+
* space is alignment on the surrounding text or expression, not a nesting
|
|
367
|
+
* unit — the same shape as {@link blockCommentInteriorMask} for `/* … *\/`
|
|
368
|
+
* (#3059, a fourth member of AGENTS.md defect 49). The opener line itself is
|
|
369
|
+
* false (its own indentation *is* structural); a backtick inside a `//` line
|
|
370
|
+
* comment or a quoted string must not open a template (`advanceTemplateState`
|
|
371
|
+
* resolves both before treating a backtick as an opener); `${ … }` nesting
|
|
372
|
+
* and escaped backticks are tracked through the frame stack so neither an
|
|
373
|
+
* object literal inside a substitution nor an escaped backtick in template
|
|
374
|
+
* text closes anything early. A template that never closes by EOF was
|
|
375
|
+
* (like an unterminated block comment) something this lexer misread — a
|
|
376
|
+
* backtick inside a regex literal, say — so its lines are left false rather
|
|
377
|
+
* than silently swallowed.
|
|
378
|
+
*/
|
|
379
|
+
export function templateLiteralInteriorMask(lines) {
|
|
380
|
+
const mask = Array.from({ length: lines.length }, () => false);
|
|
381
|
+
const stack = [];
|
|
382
|
+
let openLine = -1;
|
|
383
|
+
for (const [i, line] of lines.entries()) {
|
|
384
|
+
if (hasLiveFrame(stack)) {
|
|
385
|
+
mask[i] = true;
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
openLine = i;
|
|
389
|
+
}
|
|
390
|
+
advanceTemplateState(line, stack);
|
|
391
|
+
}
|
|
392
|
+
if (hasLiveFrame(stack)) {
|
|
393
|
+
for (let i = openLine + 1; i < lines.length; i += 1)
|
|
394
|
+
mask[i] = false;
|
|
395
|
+
}
|
|
396
|
+
return mask;
|
|
397
|
+
}
|
|
398
|
+
function structuralLines(lines) {
|
|
399
|
+
const blockCommentMask = blockCommentInteriorMask(lines);
|
|
400
|
+
const templateMask = templateLiteralInteriorMask(lines);
|
|
401
|
+
return lines.filter((_, index) => !blockCommentMask[index] && !templateMask[index]);
|
|
402
|
+
}
|
|
403
|
+
function greatestCommonDivisor(left, right) {
|
|
404
|
+
while (right !== 0)
|
|
405
|
+
[left, right] = [right, left % right];
|
|
406
|
+
return left;
|
|
407
|
+
}
|
|
32
408
|
/** Whether the content supplied evidence from which a style can be inferred. */
|
|
33
409
|
export function hasDetectableIndentation(content) {
|
|
34
410
|
return /^(?:\t+| {1,})\S/m.test(content);
|