@herbertgao/pi-extensions 2026.8.13 → 2026.8.15
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 +19 -14
- package/THIRD_PARTY_NOTICES.md +0 -1
- package/node_modules/@czottmann/pi-automode/CHANGELOG.md +19 -0
- package/node_modules/@czottmann/pi-automode/README.md +5 -1
- package/node_modules/@czottmann/pi-automode/extensions/auto-mode/classifier.ts +126 -13
- package/node_modules/@czottmann/pi-automode/extensions/auto-mode/config.ts +7 -3
- package/node_modules/@czottmann/pi-automode/extensions/auto-mode/constants.ts +2 -0
- package/node_modules/@czottmann/pi-automode/extensions/auto-mode/hard-deny.ts +134 -23
- package/node_modules/@czottmann/pi-automode/package.json +1 -1
- package/node_modules/@herbertgao/{pi-stash → pi-bark}/LICENSE +4 -5
- package/node_modules/@herbertgao/pi-bark/README.md +44 -0
- package/node_modules/@herbertgao/pi-bark/assets/pi-icon.png +0 -0
- package/node_modules/@herbertgao/pi-bark/package.json +53 -0
- package/node_modules/@herbertgao/pi-bark/src/index.ts +178 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +3 -3
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +2 -1
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +8 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +2 -2
- package/node_modules/@narumitw/pi-btw/README.md +125 -88
- package/node_modules/@narumitw/pi-btw/dist/index.ts +140 -45
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
- package/node_modules/@narumitw/pi-btw/package.json +5 -8
- package/node_modules/@narumitw/pi-btw/src/btw.ts +31 -26
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +106 -17
- package/node_modules/@narumitw/pi-btw/src/menu.ts +34 -2
- package/node_modules/@narumitw/pi-btw/src/settings.ts +16 -0
- package/node_modules/@tifan/pi-handoff/README.md +36 -13
- package/node_modules/@tifan/pi-handoff/package.json +2 -2
- package/node_modules/@tifan/pi-handoff/src/index.ts +160 -4
- package/node_modules/@tifan/pi-preferred-thinking/README.md +1 -1
- package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
- package/node_modules/@tifan/pi-preferred-thinking/src/index.ts +15 -2
- package/node_modules/@tifan/pi-recap/README.md +1 -1
- package/node_modules/@tifan/pi-recap/package.json +2 -2
- package/node_modules/@tifan/pi-recap/src/index.ts +15 -0
- package/node_modules/@tifan/pi-rename/README.md +42 -21
- package/node_modules/@tifan/pi-rename/package.json +1 -1
- package/node_modules/@tifan/pi-rename/src/index.ts +62 -11
- package/node_modules/@tifan/pi-rename/src/language.ts +18 -0
- package/node_modules/@tifan/pi-rename/src/models.ts +69 -13
- package/node_modules/@tifan/pi-rename/src/naming.ts +36 -7
- package/node_modules/@tifan/pi-rename/src/sanitize.ts +22 -14
- package/node_modules/pi-lens/CHANGELOG.md +320 -0
- package/node_modules/pi-lens/config/dependency-cruiser-eager-allowlist.json +79 -0
- package/node_modules/pi-lens/dist/clients/actionable-warnings-logger.js +16 -1
- package/node_modules/pi-lens/dist/clients/ast-grep-client.js +13 -6
- package/node_modules/pi-lens/dist/clients/availability-probe-flight.js +12 -0
- package/node_modules/pi-lens/dist/clients/biome-client.js +7 -0
- package/node_modules/pi-lens/dist/clients/blocker-freshness.js +20 -0
- package/node_modules/pi-lens/dist/clients/bounded-telemetry.js +56 -19
- package/node_modules/pi-lens/dist/clients/build-identity.js +95 -0
- package/node_modules/pi-lens/dist/clients/bus-publish.js +3 -0
- package/node_modules/pi-lens/dist/clients/cache/rule-cache.js +2 -1
- package/node_modules/pi-lens/dist/clients/cache-observability.js +2 -1
- package/node_modules/pi-lens/dist/clients/cascade-logger.js +15 -1
- package/node_modules/pi-lens/dist/clients/dead-code-client.js +14 -11
- package/node_modules/pi-lens/dist/clients/degradation-ledger.js +56 -4
- package/node_modules/pi-lens/dist/clients/demoted-finding-render.js +14 -0
- package/node_modules/pi-lens/dist/clients/dependency-checker.js +20 -3
- package/node_modules/pi-lens/dist/clients/deps/minimatch.js +1 -1
- package/node_modules/pi-lens/dist/clients/dispatch/collect-later-tier.js +39 -0
- package/node_modules/pi-lens/dist/clients/dispatch/dispatcher.js +150 -9
- package/node_modules/pi-lens/dist/clients/dispatch/fact-store.js +231 -9
- package/node_modules/pi-lens/dist/clients/dispatch/integration.js +205 -100
- package/node_modules/pi-lens/dist/clients/dispatch/pending-runner-findings.js +87 -0
- package/node_modules/pi-lens/dist/clients/dispatch/plan.js +21 -5
- package/node_modules/pi-lens/dist/clients/dispatch/runners/ast-grep-napi.js +174 -55
- package/node_modules/pi-lens/dist/clients/dispatch/runners/eslint.js +5 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-lint.js +16 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/helm-render.js +54 -9
- package/node_modules/pi-lens/dist/clients/dispatch/runners/index.js +1 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/lsp.js +37 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/markdownlint.js +4 -1
- package/node_modules/pi-lens/dist/clients/dispatch/runners/oxlint.js +11 -4
- package/node_modules/pi-lens/dist/clients/dispatch/runners/psscriptanalyzer.js +4 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/rust-clippy.js +8 -3
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/runner-helpers.js +76 -25
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/spawn-outcome.js +4 -0
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/tool-failure.js +19 -7
- package/node_modules/pi-lens/dist/clients/dispatch/runners/utils/toolchain-availability.js +7 -13
- package/node_modules/pi-lens/dist/clients/dispatch/runners/yaml-rule-parser.js +51 -17
- package/node_modules/pi-lens/dist/clients/event-loop-monitor.js +66 -1
- package/node_modules/pi-lens/dist/clients/file-utils.js +157 -7
- package/node_modules/pi-lens/dist/clients/finding-delivery-gate.js +5 -0
- package/node_modules/pi-lens/dist/clients/formatters.js +28 -3
- package/node_modules/pi-lens/dist/clients/git-guard.js +197 -47
- package/node_modules/pi-lens/dist/clients/git-tracked-ignore.js +32 -1
- package/node_modules/pi-lens/dist/clients/govulncheck-client.js +5 -1
- package/node_modules/pi-lens/dist/clients/gzip-stage-write.js +7 -0
- package/node_modules/pi-lens/dist/clients/installer/index.js +131 -34
- package/node_modules/pi-lens/dist/clients/installer/managed-tool-refresh.js +3 -1
- package/node_modules/pi-lens/dist/clients/instance-reaper.js +4 -13
- package/node_modules/pi-lens/dist/clients/instance-registry-lock.js +145 -0
- package/node_modules/pi-lens/dist/clients/instance-registry.js +432 -122
- package/node_modules/pi-lens/dist/clients/jscpd-client.js +6 -1
- package/node_modules/pi-lens/dist/clients/language-profile.js +4 -2
- package/node_modules/pi-lens/dist/clients/latency-logger.js +19 -1
- package/node_modules/pi-lens/dist/clients/lens-flag-registry.js +8 -0
- package/node_modules/pi-lens/dist/clients/lens-map.js +3 -1
- package/node_modules/pi-lens/dist/clients/lsp/cascade-tier.js +4 -0
- package/node_modules/pi-lens/dist/clients/lsp/client.js +516 -31
- package/node_modules/pi-lens/dist/clients/lsp/config.js +25 -2
- package/node_modules/pi-lens/dist/clients/lsp/diagnostic-binding.js +9 -4
- package/node_modules/pi-lens/dist/clients/lsp/index.js +509 -182
- package/node_modules/pi-lens/dist/clients/lsp/jvm-runtime.js +5 -0
- package/node_modules/pi-lens/dist/clients/lsp/launch.js +36 -8
- package/node_modules/pi-lens/dist/clients/lsp/pending-aux-coverage.js +116 -4
- package/node_modules/pi-lens/dist/clients/lsp/server.js +142 -13
- package/node_modules/pi-lens/dist/clients/lsp/session-roots.js +99 -0
- package/node_modules/pi-lens/dist/clients/lsp/workspace-diagnostics-cache.js +16 -6
- package/node_modules/pi-lens/dist/clients/lsp/workspace-sweep-hold.js +32 -23
- package/node_modules/pi-lens/dist/clients/lsp-mutation.js +16 -2
- package/node_modules/pi-lens/dist/clients/mcp/analyze.js +12 -6
- package/node_modules/pi-lens/dist/clients/mcp/session.js +14 -1
- package/node_modules/pi-lens/dist/clients/memory-sampler.js +23 -1
- package/node_modules/pi-lens/dist/clients/message-end-attribution.js +30 -0
- package/node_modules/pi-lens/dist/clients/metrics-history.js +21 -4
- package/node_modules/pi-lens/dist/clients/opaque-mutation-scan.js +232 -18
- package/node_modules/pi-lens/dist/clients/package-manager.js +6 -18
- package/node_modules/pi-lens/dist/clients/path-keyed-map.js +14 -1
- package/node_modules/pi-lens/dist/clients/path-utils.js +32 -0
- package/node_modules/pi-lens/dist/clients/pipeline.js +0 -8
- package/node_modules/pi-lens/dist/clients/process-singletons.js +210 -0
- package/node_modules/pi-lens/dist/clients/project-diagnostics/runner-adapters/madge.js +2 -1
- package/node_modules/pi-lens/dist/clients/project-diagnostics/scanner.js +10 -4
- package/node_modules/pi-lens/dist/clients/project-snapshot.js +33 -11
- package/node_modules/pi-lens/dist/clients/read-guard-logger.js +24 -2
- package/node_modules/pi-lens/dist/clients/read-guard.js +74 -7
- package/node_modules/pi-lens/dist/clients/recent-touches.js +17 -5
- package/node_modules/pi-lens/dist/clients/review-graph/builder.js +639 -62
- package/node_modules/pi-lens/dist/clients/review-graph/tsconfig-paths.js +5 -1
- package/node_modules/pi-lens/dist/clients/review-graph-logger.js +21 -1
- package/node_modules/pi-lens/dist/clients/runtime-coordinator.js +68 -0
- package/node_modules/pi-lens/dist/clients/runtime-session.js +30 -12
- package/node_modules/pi-lens/dist/clients/runtime-tool-call.js +15 -0
- package/node_modules/pi-lens/dist/clients/runtime-tool-result.js +106 -7
- package/node_modules/pi-lens/dist/clients/runtime-turn.js +242 -27
- package/node_modules/pi-lens/dist/clients/safe-spawn.js +158 -18
- package/node_modules/pi-lens/dist/clients/security-scan-client.js +48 -17
- package/node_modules/pi-lens/dist/clients/session-lifecycle.js +238 -42
- package/node_modules/pi-lens/dist/clients/sg-runner.js +27 -15
- package/node_modules/pi-lens/dist/clients/shared-checkout-guard.js +338 -0
- package/node_modules/pi-lens/dist/clients/spawn-output-cap.js +37 -0
- package/node_modules/pi-lens/dist/clients/spawn-timeout-cooldown.js +15 -1
- package/node_modules/pi-lens/dist/clients/startup-scan.js +6 -7
- package/node_modules/pi-lens/dist/clients/startup-timing.js +69 -4
- package/node_modules/pi-lens/dist/clients/string-utils.js +20 -0
- package/node_modules/pi-lens/dist/clients/test-runner-client.js +419 -88
- package/node_modules/pi-lens/dist/clients/tool-policy.js +1 -1
- package/node_modules/pi-lens/dist/clients/tree-sitter-client.js +11 -5
- package/node_modules/pi-lens/dist/clients/tree-sitter-logger.js +17 -1
- package/node_modules/pi-lens/dist/clients/warm-attach.js +8 -10
- package/node_modules/pi-lens/dist/clients/word-index-logger.js +13 -1
- package/node_modules/pi-lens/dist/clients/word-index-store.js +448 -0
- package/node_modules/pi-lens/dist/clients/word-index.js +582 -104
- package/node_modules/pi-lens/dist/clients/workspace-topology.js +17 -0
- package/node_modules/pi-lens/dist/clients/zizmor-config.js +26 -6
- package/node_modules/pi-lens/dist/index.js +11243 -6651
- package/node_modules/pi-lens/dist/mcp/build-staleness.js +8 -7
- package/node_modules/pi-lens/dist/mcp/cli.js +3 -1
- package/node_modules/pi-lens/dist/mcp/server.js +6 -1
- package/node_modules/pi-lens/dist/tools/lens-diagnostics.js +4 -0
- package/node_modules/pi-lens/dist/tools/lsp-diagnostics.js +14 -5
- package/node_modules/pi-lens/dist/tools/lsp-navigation.js +3 -1
- package/node_modules/pi-lens/docs/agent-guide.md +4 -2
- package/node_modules/pi-lens/docs/ast-grep_rules_catalog.md +41 -10
- package/node_modules/pi-lens/docs/astplayground.md +26 -17
- package/node_modules/pi-lens/package.json +5 -1
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/c-no-malloc-free-test.yml +20 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-malloc-free-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/cpp-no-printf-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-fmt-println-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-panic-in-lib-test.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-no-underscore-func-name-test.yml +18 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-errors-is-test.yml +15 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/go-prefer-string-builder-test.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/hyphenated-svg-attribute-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-lateinit-test.yml +17 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-nullable-boolean-test.yml +15 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-println-test.yml +19 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unnecessary-let-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-unsafe-cast-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-no-var-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-data-class-test.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/kotlin-prefer-is-empty-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-important-test.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-raw-types-test.yml +30 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-string-concat-in-loop-test.yml +100 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/no-system-out-println-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/prefer-string-is-empty-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/python-optional-type-test.yml +9 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/reducible-list-comprehension-test.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/ruby-symbol-to-proc-candidate-test.yml +10 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rule-tests/rust-no-chars-enumerate-test.yml +7 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/c-no-malloc-free.yml +39 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-malloc-free.yml +45 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/cpp-no-printf.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-fmt-println.yml +43 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-panic-in-lib.yml +41 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-no-underscore-func-name.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-errors-is.yml +40 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/go-prefer-string-builder.yml +43 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/hyphenated-svg-attribute.yml +32 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-lateinit.yml +37 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-nullable-boolean.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-println.yml +42 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unnecessary-let.yml +28 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-unsafe-cast.yml +28 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-no-var.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-data-class.yml +66 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/kotlin-prefer-is-empty.yml +35 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-important.yml +21 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-raw-types.yml +33 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-string-concat-in-loop.yml +90 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/no-system-out-println.yml +16 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/prefer-string-is-empty.yml +11 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/python-optional-type.yml +22 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/reducible-list-comprehension.yml +29 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/ruby-symbol-to-proc-candidate.yml +25 -0
- package/node_modules/pi-lens/rules/ast-grep-rules/rules/rust-no-chars-enumerate.yml +19 -0
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +35 -0
- package/node_modules/pi-mcp-adapter/README.md +5 -2
- package/node_modules/pi-mcp-adapter/cli.js +4 -4
- package/node_modules/pi-mcp-adapter/commands.ts +1 -1
- package/node_modules/pi-mcp-adapter/config.ts +1 -0
- package/node_modules/pi-mcp-adapter/dist/config.js +1 -0
- package/node_modules/pi-mcp-adapter/dist/config.js.map +1 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +24 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +336 -0
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +1 -0
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +3 -1
- package/node_modules/pi-mcp-adapter/dist/types.js.map +1 -1
- package/node_modules/pi-mcp-adapter/index.ts +90 -6
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +124 -32
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -2
- package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +89 -0
- package/node_modules/pi-mcp-adapter/mcp-references.ts +9 -1
- package/node_modules/pi-mcp-adapter/package.json +1 -1
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +62 -22
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +1 -1
- package/node_modules/pi-mcp-adapter/server-manager.ts +6 -0
- package/node_modules/pi-mcp-adapter/types.ts +3 -1
- package/node_modules/pi-web-access/CHANGELOG.md +42 -0
- package/node_modules/pi-web-access/README.md +26 -10
- package/node_modules/pi-web-access/curator-page.ts +12 -3
- package/node_modules/pi-web-access/curator-server.ts +3 -1
- package/node_modules/pi-web-access/extract.ts +88 -13
- package/node_modules/pi-web-access/gemini-search.ts +10 -5
- package/node_modules/pi-web-access/github-extract.ts +47 -3
- package/node_modules/pi-web-access/index.ts +40 -40
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/page-query.ts +61 -8
- package/node_modules/pi-web-access/xcrawl.ts +264 -0
- package/package.json +19 -22
- package/node_modules/@herbertgao/pi-stash/README.md +0 -34
- package/node_modules/@herbertgao/pi-stash/package.json +0 -51
- package/node_modules/@herbertgao/pi-stash/src/index.ts +0 -118
- package/node_modules/@tifan/pi-titlebar-spinner/README.md +0 -24
- package/node_modules/@tifan/pi-titlebar-spinner/package.json +0 -39
- package/node_modules/@tifan/pi-titlebar-spinner/src/index.ts +0 -49
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared-checkout WIP guard (#2007).
|
|
3
|
+
*
|
|
4
|
+
* THE HAZARD. Several agent sessions can run against ONE checkout. Nothing
|
|
5
|
+
* in git binds a session to a directory, so when one session runs
|
|
6
|
+
* `git checkout <branch>`, git overwrites the tracked files another live
|
|
7
|
+
* session was editing. The work is not recoverable: it was never committed
|
|
8
|
+
* and never stashed. The reported incident lost uncommitted edits to three
|
|
9
|
+
* files between two observations minutes apart.
|
|
10
|
+
*
|
|
11
|
+
* THE ANSWER IS REFUSAL, NOT RESCUE. An auto-stash would be invisible
|
|
12
|
+
* machinery that moves another session's work somewhere it did not ask for,
|
|
13
|
+
* and `git stash` is repo-global across worktrees, so the rescue would be a
|
|
14
|
+
* second instance of the same defect. This guard instead DECLINES the
|
|
15
|
+
* command and says who else is here. The operator resolves it the way the
|
|
16
|
+
* design contract already says to: commit, or take a dedicated
|
|
17
|
+
* `git worktree`.
|
|
18
|
+
*
|
|
19
|
+
* THREE FACTS MUST ALL HOLD BEFORE ANYTHING IS DECLINED, cheapest first:
|
|
20
|
+
*
|
|
21
|
+
* 1. The bash input really invokes a git verb that rewrites the working
|
|
22
|
+
* tree, read from git's own COMMAND POSITION. Pure string work, no I/O —
|
|
23
|
+
* see `WORKTREE_MUTATING_GIT_MATCHER`. The directory judged is the one
|
|
24
|
+
* the invocation TARGETS, which `-C` and `--work-tree` can move away
|
|
25
|
+
* from the caller's cwd.
|
|
26
|
+
* 2. Another live pi-lens session is in the SAME WORKING TREE.
|
|
27
|
+
* `selectLivePeerInstances` (clients/instance-registry.ts) owns liveness
|
|
28
|
+
* and is the single source of truth for it; warm-attach reads the same
|
|
29
|
+
* predicate in `"exact"` mode. Path containment alone is not identity
|
|
30
|
+
* here, in either direction: a peer at the repo root and a command run
|
|
31
|
+
* from a subdirectory DO share one tree, while a linked worktree nested
|
|
32
|
+
* under the main checkout shares nothing with it. Containment against
|
|
33
|
+
* the toplevel is the pre-filter; `git rev-parse --show-toplevel` is the
|
|
34
|
+
* decision. No peer means nothing to protect.
|
|
35
|
+
* 3. The working tree actually carries uncommitted work. A clean tree can
|
|
36
|
+
* be switched freely.
|
|
37
|
+
*
|
|
38
|
+
* That ordering is the cost story: the two `git` probes run only after a
|
|
39
|
+
* genuine worktree-mutating command in a genuinely shared checkout, which is
|
|
40
|
+
* rare. Ordinary bash traffic pays one string classification.
|
|
41
|
+
*
|
|
42
|
+
* UNKNOWN IS NOT CLEAN (catalog shape 10). When `git status` cannot answer,
|
|
43
|
+
* the guard declines with its OWN reason rather than assuming the tree is
|
|
44
|
+
* clean, and records a counted degradation so a repeatedly broken probe is
|
|
45
|
+
* visible instead of silently permissive.
|
|
46
|
+
*
|
|
47
|
+
* The TOPLEVEL probes fail open, deliberately and asymmetrically to the
|
|
48
|
+
* dirtiness probe: a candidate peer whose `git rev-parse --show-toplevel`
|
|
49
|
+
* fails is dropped, and the allow record folds into `no_peer_session`; a cwd
|
|
50
|
+
* whose probe fails folds into `not_a_git_worktree`. Both read as facts in
|
|
51
|
+
* latency.log when they may be a timeout or a lock. Chosen because failing
|
|
52
|
+
* closed here would let a broken probe block every branch switch; the cost is
|
|
53
|
+
* that those two reasons are not distinguishable from the genuine cases.
|
|
54
|
+
*
|
|
55
|
+
* NO LATCHES HERE (catalog shape 17). Every decision is recomputed from the
|
|
56
|
+
* registry and the tree. Repeat-suppression for telemetry lives in the
|
|
57
|
+
* degradation ledger, which already re-arms at `session_start`.
|
|
58
|
+
*/
|
|
59
|
+
import { emitBounded } from "./bounded-telemetry.js";
|
|
60
|
+
import { collectGitInvocations, detectGuardedGitVerb, matchGitVerbAtCommandPosition, resolveGitTargetDirectory, } from "./git-guard.js";
|
|
61
|
+
import { getInstanceRoots, readInstanceRegistry, selectLivePeerInstances, } from "./instance-registry.js";
|
|
62
|
+
import { realIsPidAlive } from "./instance-reaper.js";
|
|
63
|
+
import { logLatency } from "./latency-logger.js";
|
|
64
|
+
import { resolveGitToplevel } from "./opaque-mutation-scan.js";
|
|
65
|
+
import { normalizeFilePath } from "./path-utils.js";
|
|
66
|
+
import { safeSpawnAsync } from "./safe-spawn.js";
|
|
67
|
+
import { truncatedByOutputCap } from "./spawn-output-cap.js";
|
|
68
|
+
/** Verbs that rewrite tracked files unconditionally. */
|
|
69
|
+
const ALWAYS_MUTATING_VERBS = new Set([
|
|
70
|
+
"checkout",
|
|
71
|
+
"switch",
|
|
72
|
+
"restore",
|
|
73
|
+
"merge",
|
|
74
|
+
"rebase",
|
|
75
|
+
"pull",
|
|
76
|
+
"cherry-pick",
|
|
77
|
+
"revert",
|
|
78
|
+
]);
|
|
79
|
+
/** `git reset` touches the working tree only in these modes. */
|
|
80
|
+
const RESET_WORKTREE_MODES = new Set([
|
|
81
|
+
"--hard",
|
|
82
|
+
"--merge",
|
|
83
|
+
"--keep",
|
|
84
|
+
]);
|
|
85
|
+
/** `git stash` subcommands that only read. Everything else moves files. */
|
|
86
|
+
const READ_ONLY_STASH_SUBCOMMANDS = new Set([
|
|
87
|
+
"list",
|
|
88
|
+
"show",
|
|
89
|
+
]);
|
|
90
|
+
/**
|
|
91
|
+
* `git clean` in dry-run mode reports and deletes nothing.
|
|
92
|
+
*
|
|
93
|
+
* Short flags CLUSTER (`git clean -nfd` is `-n -f -d`), so an exact-token set
|
|
94
|
+
* would read `-nfd` as mutating and decline a command that touches nothing.
|
|
95
|
+
* Match the letter inside any short cluster, and `--dry-run` exactly.
|
|
96
|
+
*/
|
|
97
|
+
function isCleanDryRun(argsAfterVerb) {
|
|
98
|
+
return argsAfterVerb.some((arg) => arg === "--dry-run" ||
|
|
99
|
+
(arg.startsWith("-") && !arg.startsWith("--") && arg.includes("n")));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The verb question for the shared-checkout guard. Every other part of the
|
|
103
|
+
* classification (wrappers, `$IFS`, substitutions, PATHEXT, text consumers)
|
|
104
|
+
* is the #1063 git-guard machinery, reused rather than re-implemented.
|
|
105
|
+
*
|
|
106
|
+
* `indirectAlwaysMatches` is FALSE here on purpose. The commit gate is a
|
|
107
|
+
* policy an agent may want to evade, so it fails closed on any indirect
|
|
108
|
+
* `git`. This guard protects an agent from its own accident, so failing
|
|
109
|
+
* closed on `xargs git status` would cost far more than it saves; the
|
|
110
|
+
* indirect path stays armed only when the argv also carries a governed verb.
|
|
111
|
+
*
|
|
112
|
+
* DELIBERATELY OUT OF SCOPE: `git apply` and `git am`. They add the caller's
|
|
113
|
+
* own patch on top of the tree and fail loudly into `.rej` files rather than
|
|
114
|
+
* discarding tracked content wholesale, and `git apply` is the sanctioned
|
|
115
|
+
* replacement for the forbidden `git stash`. Blocking it would push
|
|
116
|
+
* operators back toward stash.
|
|
117
|
+
*/
|
|
118
|
+
export const WORKTREE_MUTATING_GIT_MATCHER = {
|
|
119
|
+
id: "worktree-mutating",
|
|
120
|
+
indirectAlwaysMatches: false,
|
|
121
|
+
// `git checkout --help` opens documentation and changes nothing. This
|
|
122
|
+
// guard can afford to read a leading help flag as documentation; the
|
|
123
|
+
// commit gate cannot — see `suppressPostVerbHelp`'s own docstring.
|
|
124
|
+
suppressPostVerbHelp: true,
|
|
125
|
+
matchesVerb(verb, argsAfterVerb) {
|
|
126
|
+
if (ALWAYS_MUTATING_VERBS.has(verb))
|
|
127
|
+
return true;
|
|
128
|
+
if (verb === "reset") {
|
|
129
|
+
return argsAfterVerb.some((arg) => RESET_WORKTREE_MODES.has(arg));
|
|
130
|
+
}
|
|
131
|
+
if (verb === "stash") {
|
|
132
|
+
const subcommand = argsAfterVerb.find((arg) => !arg.startsWith("-"));
|
|
133
|
+
return (subcommand === undefined || !READ_ONLY_STASH_SUBCOMMANDS.has(subcommand));
|
|
134
|
+
}
|
|
135
|
+
if (verb === "clean")
|
|
136
|
+
return !isCleanDryRun(argsAfterVerb);
|
|
137
|
+
return false;
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
/** True when this one git invocation's subcommand rewrites tracked files. */
|
|
141
|
+
function matchesWorktreeMutatingVerb(gitTokens) {
|
|
142
|
+
return matchGitVerbAtCommandPosition(gitTokens, WORKTREE_MUTATING_GIT_MATCHER);
|
|
143
|
+
}
|
|
144
|
+
/** True when this bash input runs a git verb that rewrites tracked files. */
|
|
145
|
+
export function isWorktreeMutatingGitAttempt(toolName, input) {
|
|
146
|
+
return detectGuardedGitVerb(toolName, input, WORKTREE_MUTATING_GIT_MATCHER);
|
|
147
|
+
}
|
|
148
|
+
// A `git status --porcelain --untracked-files=all` listing over a huge
|
|
149
|
+
// untracked tree (an unignored `node_modules`, a vendored dependency dump) can
|
|
150
|
+
// run to many MiB. This is a blast-radius bound on a wedged or runaway git, not
|
|
151
|
+
// a working limit; 16 MiB matches the sibling git-status probes
|
|
152
|
+
// (`opaque-mutation-scan.ts`'s `MAX_GIT_STATUS_OUTPUT_BYTES` and
|
|
153
|
+
// `git-tracked-ignore.ts`'s `MAX_LS_FILES_OUTPUT_BYTES`, both 16 MiB). Without
|
|
154
|
+
// it `outputTruncated` can never fire, so the truncation guard below was
|
|
155
|
+
// dormant (#2100 F3).
|
|
156
|
+
const MAX_GIT_STATUS_OUTPUT_BYTES = 16 * 1024 * 1024;
|
|
157
|
+
/**
|
|
158
|
+
* Ask git whether the working tree carries uncommitted work.
|
|
159
|
+
*
|
|
160
|
+
* Deliberately narrower than `recoverOpaqueChangesViaGit`: that function
|
|
161
|
+
* answers WHICH files changed inside a time window and stats each one, which
|
|
162
|
+
* drops deletions and costs one stat per entry. Here the only question is
|
|
163
|
+
* whether ANY entry exists, so a truncated listing is still a definite
|
|
164
|
+
* `dirty` — a prefix of dirt is dirt.
|
|
165
|
+
*/
|
|
166
|
+
export async function probeWorkingTreeState(root) {
|
|
167
|
+
const result = await safeSpawnAsync("git", ["status", "--porcelain", "--untracked-files=all"], { cwd: root, timeout: 5000, maxOutputBytes: MAX_GIT_STATUS_OUTPUT_BYTES });
|
|
168
|
+
// Read truncation FIRST (#2100 F3), through the shared seam that
|
|
169
|
+
// git-tracked-ignore uses. Reaching the cap makes safe-spawn kill the tree,
|
|
170
|
+
// which settles as `error` + null status on POSIX and status 1 on Windows —
|
|
171
|
+
// both of which the failure check below reads as `unknown`. So a definite
|
|
172
|
+
// dirty (we captured 16 MiB of porcelain) was being downgraded to `unknown`
|
|
173
|
+
// the moment the cap fired. Timeout and abort keep their own classification
|
|
174
|
+
// and fall through to `unknown`, since a hung git cannot prove dirtiness.
|
|
175
|
+
if (truncatedByOutputCap(result))
|
|
176
|
+
return "dirty";
|
|
177
|
+
if (result.error || (result.status !== 0 && result.status !== null)) {
|
|
178
|
+
return "unknown";
|
|
179
|
+
}
|
|
180
|
+
return (result.stdout ?? "").trim().length > 0 ? "dirty" : "clean";
|
|
181
|
+
}
|
|
182
|
+
function logAllow(root, reasonCategory) {
|
|
183
|
+
logLatency({
|
|
184
|
+
type: "phase",
|
|
185
|
+
toolName: "shared-checkout-guard",
|
|
186
|
+
phase: "shared_checkout_guard_allow",
|
|
187
|
+
filePath: root,
|
|
188
|
+
durationMs: 0,
|
|
189
|
+
metadata: { decision: "allowed", reasonCategory },
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function describePeers(peers) {
|
|
193
|
+
const pids = peers.slice(0, 4).map((peer) => peer.pid);
|
|
194
|
+
const suffix = peers.length > pids.length ? ", …" : "";
|
|
195
|
+
return `${peers.length} other live pi-lens session${peers.length === 1 ? "" : "s"} (pid ${pids.join(", ")}${suffix})`;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Decide whether one worktree-mutating git command may run here.
|
|
199
|
+
*
|
|
200
|
+
* Never throws: a registry read that fails yields an empty peer list, which
|
|
201
|
+
* reads as "no shared checkout" and allows. That direction is deliberate —
|
|
202
|
+
* the registry is observability substrate and an outage of it must not
|
|
203
|
+
* start refusing every branch switch on every machine.
|
|
204
|
+
*/
|
|
205
|
+
export async function evaluateSharedCheckoutGuard(toolName, input, cwd, deps = {}) {
|
|
206
|
+
if (!isWorktreeMutatingGitAttempt(toolName, input))
|
|
207
|
+
return { block: false };
|
|
208
|
+
// #2007: `git -C <dir>` and `--work-tree` retarget the command at a
|
|
209
|
+
// DIFFERENT directory. Evaluating the caller's cwd would inspect the wrong
|
|
210
|
+
// working tree and allow the destructive command against a shared one, so
|
|
211
|
+
// every targeted directory is evaluated and the first contended one wins.
|
|
212
|
+
const targets = resolveGuardTargets(toolName, input, cwd);
|
|
213
|
+
let entries;
|
|
214
|
+
try {
|
|
215
|
+
entries = await (deps.readRegistry ?? readInstanceRegistry)();
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
logAllow(normalizeFilePath(cwd), "registry_unreadable");
|
|
219
|
+
return { block: false };
|
|
220
|
+
}
|
|
221
|
+
for (const target of targets) {
|
|
222
|
+
const decision = await evaluateOneTarget(target, entries, deps);
|
|
223
|
+
if (decision.block)
|
|
224
|
+
return decision;
|
|
225
|
+
}
|
|
226
|
+
return { block: false };
|
|
227
|
+
}
|
|
228
|
+
/** Distinct directories the command's git invocations actually target. */
|
|
229
|
+
function resolveGuardTargets(toolName, input, cwd) {
|
|
230
|
+
const targets = new Set();
|
|
231
|
+
for (const gitTokens of collectGitInvocations(toolName, input)) {
|
|
232
|
+
if (!matchesWorktreeMutatingVerb(gitTokens))
|
|
233
|
+
continue;
|
|
234
|
+
targets.add(resolveGitTargetDirectory(gitTokens, cwd));
|
|
235
|
+
}
|
|
236
|
+
// A wrapper or substitution form the token scan cannot attribute to a
|
|
237
|
+
// directory still matched the classifier, so fall back to the cwd rather
|
|
238
|
+
// than evaluating nothing.
|
|
239
|
+
if (targets.size === 0)
|
|
240
|
+
targets.add(cwd);
|
|
241
|
+
return [...targets];
|
|
242
|
+
}
|
|
243
|
+
async function evaluateOneTarget(cwd, entries, deps) {
|
|
244
|
+
const root = normalizeFilePath(cwd);
|
|
245
|
+
const resolveToplevel = deps.resolveToplevel ?? resolveGitToplevel;
|
|
246
|
+
const toplevel = await resolveToplevel(cwd);
|
|
247
|
+
if (toplevel === undefined) {
|
|
248
|
+
logAllow(root, "not_a_git_worktree");
|
|
249
|
+
return { block: false };
|
|
250
|
+
}
|
|
251
|
+
const normalizedToplevel = normalizeFilePath(toplevel);
|
|
252
|
+
// Containment against the TOPLEVEL, not against the caller's directory:
|
|
253
|
+
// two sessions in sibling subdirectories of one checkout share it, and
|
|
254
|
+
// comparing them to each other would miss that. Every directory in a
|
|
255
|
+
// working tree is under its own toplevel, so this pre-filter can only
|
|
256
|
+
// admit candidates, never drop a real peer.
|
|
257
|
+
const candidates = selectLivePeerInstances(entries, normalizedToplevel, deps.now ?? Date.now(), deps.isPidAlive ?? realIsPidAlive, "containment");
|
|
258
|
+
// Path containment is NOT shared-checkout identity. A linked worktree sits
|
|
259
|
+
// at a path nested under the main checkout — this repo puts agent
|
|
260
|
+
// worktrees under `.claude/worktrees/` — and shares no working files with
|
|
261
|
+
// it. Confirm each candidate belongs to the SAME working tree before
|
|
262
|
+
// declining anything, or the guard tells an operator already inside a
|
|
263
|
+
// dedicated worktree to go get a dedicated worktree.
|
|
264
|
+
//
|
|
265
|
+
// #2130: confirm against EVERY root the candidate serves, not only
|
|
266
|
+
// `projectRoot`. `selectLivePeerInstances` admits a candidate when ANY of
|
|
267
|
+
// its roots overlaps the target, so resolving the index-0 root alone drops
|
|
268
|
+
// a peer admitted on a SECONDARY root — and dropping the only peer allows
|
|
269
|
+
// the destructive command. `getInstanceRoots` is the single reader for
|
|
270
|
+
// registry root identity precisely so no caller re-derives it from the
|
|
271
|
+
// scalar field.
|
|
272
|
+
//
|
|
273
|
+
// Cost: at most one `git rev-parse` per distinct root, capped by
|
|
274
|
+
// `INSTANCE_ROOT_CAP` (32) and memoized below, on a path that already
|
|
275
|
+
// spawns one `rev-parse` for the target. The loop short-circuits on the
|
|
276
|
+
// first matching root, so the common single-root peer costs exactly what it
|
|
277
|
+
// did before.
|
|
278
|
+
const toplevelMemo = new Map();
|
|
279
|
+
const resolveToplevelOnce = async (dir) => {
|
|
280
|
+
if (toplevelMemo.has(dir))
|
|
281
|
+
return toplevelMemo.get(dir);
|
|
282
|
+
const resolved = await resolveToplevel(dir);
|
|
283
|
+
toplevelMemo.set(dir, resolved);
|
|
284
|
+
return resolved;
|
|
285
|
+
};
|
|
286
|
+
const peers = [];
|
|
287
|
+
for (const candidate of candidates) {
|
|
288
|
+
for (const candidateRoot of getInstanceRoots(candidate)) {
|
|
289
|
+
const peerToplevel = await resolveToplevelOnce(candidateRoot);
|
|
290
|
+
if (peerToplevel !== undefined &&
|
|
291
|
+
normalizeFilePath(peerToplevel) === normalizedToplevel) {
|
|
292
|
+
peers.push(candidate);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (peers.length === 0) {
|
|
298
|
+
logAllow(root, "no_peer_session");
|
|
299
|
+
return { block: false };
|
|
300
|
+
}
|
|
301
|
+
const state = await (deps.probeWorkingTree ?? probeWorkingTreeState)(cwd);
|
|
302
|
+
if (state === "clean") {
|
|
303
|
+
logAllow(root, "working_tree_clean");
|
|
304
|
+
return { block: false };
|
|
305
|
+
}
|
|
306
|
+
if (state === "unknown") {
|
|
307
|
+
emitBounded("shared_checkout_probe_failed", root, {
|
|
308
|
+
toolName: "shared-checkout-guard",
|
|
309
|
+
durationMs: 0,
|
|
310
|
+
metadata: { decision: "blocked", peerCount: peers.length },
|
|
311
|
+
}, {
|
|
312
|
+
ledgerKind: "shared-checkout-probe",
|
|
313
|
+
risingEdgePer: "identity",
|
|
314
|
+
reason: "git status could not report working-tree state",
|
|
315
|
+
});
|
|
316
|
+
return {
|
|
317
|
+
block: true,
|
|
318
|
+
unknown: true,
|
|
319
|
+
reason: "🔴 WORKING-TREE CHANGE BLOCKED (--lens-checkout-guard): git could not report whether this checkout has uncommitted work, and it is shared with " +
|
|
320
|
+
`${describePeers(peers)}. Re-run the command once git answers, or take a dedicated git worktree.`,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
emitBounded("shared_checkout_switch_blocked", root, {
|
|
324
|
+
toolName: "shared-checkout-guard",
|
|
325
|
+
durationMs: 0,
|
|
326
|
+
metadata: { decision: "blocked", peerCount: peers.length },
|
|
327
|
+
}, {
|
|
328
|
+
ledgerKind: "shared-checkout-wip",
|
|
329
|
+
risingEdgePer: "identity",
|
|
330
|
+
reason: "worktree-mutating git command declined on a shared checkout",
|
|
331
|
+
});
|
|
332
|
+
return {
|
|
333
|
+
block: true,
|
|
334
|
+
reason: "🔴 WORKING-TREE CHANGE BLOCKED (--lens-checkout-guard): this checkout has uncommitted changes and is shared with " +
|
|
335
|
+
`${describePeers(peers)}. The command would discard work that may not be yours. ` +
|
|
336
|
+
"Commit the changes first, or run this in a dedicated git worktree.",
|
|
337
|
+
};
|
|
338
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one reading of `SpawnResult.outputTruncated` (#2100).
|
|
3
|
+
*
|
|
4
|
+
* Its own module for the same reason `ledger-bounds.ts` is: `spawn-outcome.ts`
|
|
5
|
+
* is on the shared runner path that dozens of test files reach with a bare
|
|
6
|
+
* `vi.mock("safe-spawn.js")`, and importing a VALUE from safe-spawn there makes
|
|
7
|
+
* every one of those mocks have to re-export it. This module has no imports, so
|
|
8
|
+
* nobody has to mock it.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* True when `outputTruncated` is the OUTPUT CAP's own verdict about this run,
|
|
12
|
+
* and not a detail of some other ending.
|
|
13
|
+
*
|
|
14
|
+
* A timeout or an abort can carry `outputTruncated` too. Those endings own
|
|
15
|
+
* their own classification, so they are excluded here rather than reported as
|
|
16
|
+
* truncation.
|
|
17
|
+
*
|
|
18
|
+
* Typed structurally so `SpawnResult` and runner-level result shapes that
|
|
19
|
+
* re-spell `failure` can both use it.
|
|
20
|
+
*/
|
|
21
|
+
export function truncatedByOutputCap(result) {
|
|
22
|
+
return (result.outputTruncated === true &&
|
|
23
|
+
result.failure !== "timeout" &&
|
|
24
|
+
result.failure !== "aborted");
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True when `stopForOutputLimit` started terminating the child.
|
|
28
|
+
*
|
|
29
|
+
* Windows reports that termination as status 1 without a signal or failure,
|
|
30
|
+
* while POSIX commonly reports SIGTERM. This field avoids reconstructing our
|
|
31
|
+
* action from either platform's exit shape.
|
|
32
|
+
*/
|
|
33
|
+
export function killedForOutputCap(result) {
|
|
34
|
+
return (result.killedForOutputCap === true &&
|
|
35
|
+
result.failure !== "timeout" &&
|
|
36
|
+
result.failure !== "aborted");
|
|
37
|
+
}
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import path from "node:path";
|
|
26
26
|
import { logLatency } from "./latency-logger.js";
|
|
27
|
+
import { normalizeLoggedPath } from "./path-utils.js";
|
|
27
28
|
const COOLDOWN_STATE_KEY = Symbol.for("pi-lens:spawn-timeout-cooldown");
|
|
28
29
|
const _global = globalThis;
|
|
29
30
|
if (!_global[COOLDOWN_STATE_KEY]) {
|
|
@@ -57,11 +58,24 @@ export function noteSpawnTimeout(input) {
|
|
|
57
58
|
phase: input.phase,
|
|
58
59
|
atMs: Date.now(),
|
|
59
60
|
});
|
|
61
|
+
// #2229 review round 1, F3, reverted in round 3 (R2-F2): normalizing
|
|
62
|
+
// `filePath` here is fine (it is `logLatency`'s emit-seam field, a
|
|
63
|
+
// display value with no reader). `metadata.command` is NOT a display
|
|
64
|
+
// value — `safe-spawn-timeout-teardown.test.ts` reads it back to match
|
|
65
|
+
// the cooldown row against the RAW command, and `cooldownKey` above
|
|
66
|
+
// deliberately keys on basename because the same binary arrives in
|
|
67
|
+
// multiple spellings across call sites. Normalizing it changed a
|
|
68
|
+
// correlation key's contents, which is a behavior change other code
|
|
69
|
+
// reads, not just a display fix — narrower than what F3 asked for.
|
|
70
|
+
// `filePath` and `metadata.command` can legitimately show two spellings
|
|
71
|
+
// of the same command in one record; if that turns out to matter, the
|
|
72
|
+
// fix belongs in a follow-up that stops `filePath` from carrying
|
|
73
|
+
// commands at all, not in widening this field's normalization.
|
|
60
74
|
logLatency({
|
|
61
75
|
type: "phase",
|
|
62
76
|
toolName: input.tool,
|
|
63
77
|
phase: "spawn_timeout_cooldown",
|
|
64
|
-
filePath: input.command,
|
|
78
|
+
filePath: normalizeLoggedPath(input.command),
|
|
65
79
|
durationMs: input.durationMs ?? 0,
|
|
66
80
|
status: "cooldown_armed",
|
|
67
81
|
metadata: {
|
|
@@ -15,7 +15,7 @@ import { getProjectIgnoreMatcher, } from "./file-utils.js";
|
|
|
15
15
|
import { isAtOrAboveHomeDir } from "./path-utils.js";
|
|
16
16
|
import { getStartupScanMaxSourceFilesDerived } from "./project-scale.js";
|
|
17
17
|
import { shouldRecurseIntoDir, walkTreeStackAsync, walkTreeStackSync, } from "./source-walker.js";
|
|
18
|
-
import { getDirectoryMarkers } from "./workspace-topology.js";
|
|
18
|
+
import { getDirectoryMarkers, registerWorkspaceTopologyReset, } from "./workspace-topology.js";
|
|
19
19
|
export const PROJECT_ROOT_MARKERS = [
|
|
20
20
|
".git",
|
|
21
21
|
"package.json",
|
|
@@ -217,15 +217,14 @@ export function countSourceFilesWithinLimit(dir, limit) {
|
|
|
217
217
|
// startup-scan verdict path via `walkSourceCount`.
|
|
218
218
|
return walkSourceCount(dir, limit, Number.POSITIVE_INFINITY).count;
|
|
219
219
|
}
|
|
220
|
-
//
|
|
220
|
+
// Session-lifetime memo for the (cwd, homeDir, maxSourceFiles) tuple. The
|
|
221
221
|
// underlying computation walks the entire project root counting source
|
|
222
222
|
// files and is dominated by ignoreMatcher.isIgnored() calls; on a 2k-file
|
|
223
|
-
// project it costs ~2-3s the first time.
|
|
224
|
-
//
|
|
225
|
-
//
|
|
226
|
-
// are also captured by the project snapshot freshness check upstream —
|
|
227
|
-
// in-process memoisation is safe for the duration of a single pi process.
|
|
223
|
+
// project it costs ~2-3s the first time. The topology-reset registry clears
|
|
224
|
+
// this memo at session start, so each session re-derives its answer. The memo
|
|
225
|
+
// remains valid until the next session-start reset.
|
|
228
226
|
const startupScanContextCache = new BoundedLruCache(32);
|
|
227
|
+
registerWorkspaceTopologyReset(() => startupScanContextCache.clear());
|
|
229
228
|
function startupScanCacheKey(cwd, options) {
|
|
230
229
|
return [
|
|
231
230
|
normalizeMapKey(path.resolve(cwd)),
|
|
@@ -6,6 +6,7 @@ import { performance } from "node:perf_hooks";
|
|
|
6
6
|
// wherever this file is imported, including test-only measurement code that
|
|
7
7
|
// has no business flipping a global switch.
|
|
8
8
|
import { PI_LENS_EVAL_STARTED_MS } from "./eval-timestamp.js";
|
|
9
|
+
import { getProcessSingleton, nextModuleEvaluationOrdinal, } from "./process-singletons.js";
|
|
9
10
|
/**
|
|
10
11
|
* Startup timing for pi-lens.
|
|
11
12
|
*
|
|
@@ -20,9 +21,30 @@ import { PI_LENS_EVAL_STARTED_MS } from "./eval-timestamp.js";
|
|
|
20
21
|
export const PI_LENS_LOADED_FROM = import.meta.url.endsWith(".js")
|
|
21
22
|
? "dist"
|
|
22
23
|
: "source";
|
|
24
|
+
// `loadMs`/`loadedAtMs` deliberately stay at module scope: they measure THIS
|
|
25
|
+
// evaluation's own load cost, so a second evaluation must get its own numbers
|
|
26
|
+
// rather than adopt the first's (#2146 class sweep — per-evaluation by design).
|
|
23
27
|
let loadMs;
|
|
24
28
|
let loadedAtMs;
|
|
25
|
-
|
|
29
|
+
/**
|
|
30
|
+
* The host-ready anchor is a once-PER-PROCESS latch, so it lives on the shared
|
|
31
|
+
* process singleton (#2146). Left at module scope it was consumed once per
|
|
32
|
+
* module evaluation, which meant a nine-evaluation process could emit the
|
|
33
|
+
* "first session" host-ready delay nine times.
|
|
34
|
+
*/
|
|
35
|
+
const HOST_READY_ANCHOR_FAMILY = "startup-timing.host-ready-anchor";
|
|
36
|
+
const HOST_READY_ANCHOR_VERSION = 1;
|
|
37
|
+
function hostReadyAnchorState() {
|
|
38
|
+
return getProcessSingleton(HOST_READY_ANCHOR_FAMILY, HOST_READY_ANCHOR_VERSION, () => ({ consumed: false }));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 1-based count of pi-lens module-graph evaluations in this process (#2146).
|
|
42
|
+
*
|
|
43
|
+
* Captured at module scope so it advances exactly once per evaluation, and
|
|
44
|
+
* carried on `host_boot.metadata.evaluationOrdinal` so multi-evaluation hosts
|
|
45
|
+
* are greppable in `latency.log`.
|
|
46
|
+
*/
|
|
47
|
+
export const PI_LENS_EVALUATION_ORDINAL = nextModuleEvaluationOrdinal();
|
|
26
48
|
/**
|
|
27
49
|
* Record the load-complete time. Call once, as the first statement in the
|
|
28
50
|
* extension entry's module body — by then every import has been evaluated, so
|
|
@@ -42,14 +64,15 @@ export function getPiLensLoadedAtMs() {
|
|
|
42
64
|
}
|
|
43
65
|
/** Consume the process-lifetime first-session host-ready anchor exactly once. */
|
|
44
66
|
export function consumeHostReadyDelayAnchor() {
|
|
45
|
-
|
|
67
|
+
const state = hostReadyAnchorState();
|
|
68
|
+
if (state.consumed)
|
|
46
69
|
return false;
|
|
47
|
-
|
|
70
|
+
state.consumed = true;
|
|
48
71
|
return true;
|
|
49
72
|
}
|
|
50
73
|
/** Test seam for the process-lifetime session-state registry probe boundary. */
|
|
51
74
|
export function resetHostReadyDelayAnchorForTests() {
|
|
52
|
-
|
|
75
|
+
hostReadyAnchorState().consumed = false;
|
|
53
76
|
}
|
|
54
77
|
/** ms from pi process start to pi-lens load-complete, or undefined if unmarked. */
|
|
55
78
|
export function getPiLensLoadMs() {
|
|
@@ -63,3 +86,45 @@ export function getPiLensEvalMs() {
|
|
|
63
86
|
? undefined
|
|
64
87
|
: Math.max(0, loadMs - PI_LENS_HOST_BOOT_MS);
|
|
65
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Build the three startup latency records the extension entry emits at module
|
|
91
|
+
* scope (`extension_loaded`, `host_boot`, `extension_eval`).
|
|
92
|
+
*
|
|
93
|
+
* A builder rather than three inline `logLatency` calls in `index.ts` so the
|
|
94
|
+
* record CONTENT is testable: `logLatency` is a no-op under `PI_LENS_TEST_MODE`,
|
|
95
|
+
* and `index.ts`'s module body cannot be re-run per assertion. `index.ts` maps
|
|
96
|
+
* the returned records straight into `logLatency`, so this is the production
|
|
97
|
+
* shape, not a parallel path.
|
|
98
|
+
*
|
|
99
|
+
* `host_boot` carries `evaluationOrdinal` (#2146): one `host_boot` line is one
|
|
100
|
+
* module-graph evaluation, and the ordinal makes a multi-evaluation host
|
|
101
|
+
* greppable instead of inferable by counting lines per pid.
|
|
102
|
+
*/
|
|
103
|
+
export function buildStartupTimingRecords(input) {
|
|
104
|
+
return [
|
|
105
|
+
{
|
|
106
|
+
type: "phase",
|
|
107
|
+
filePath: "<pi-lens>",
|
|
108
|
+
phase: "extension_loaded",
|
|
109
|
+
durationMs: input.loadMs,
|
|
110
|
+
metadata: { loadedFrom: PI_LENS_LOADED_FROM },
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
type: "phase",
|
|
114
|
+
filePath: "<pi-lens>",
|
|
115
|
+
phase: "host_boot",
|
|
116
|
+
durationMs: PI_LENS_HOST_BOOT_MS,
|
|
117
|
+
metadata: {
|
|
118
|
+
loadedFrom: PI_LENS_LOADED_FROM,
|
|
119
|
+
evaluationOrdinal: PI_LENS_EVALUATION_ORDINAL,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
type: "phase",
|
|
124
|
+
filePath: "<pi-lens>",
|
|
125
|
+
phase: "extension_eval",
|
|
126
|
+
durationMs: input.evalMs,
|
|
127
|
+
metadata: { loadedFrom: PI_LENS_LOADED_FROM },
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ordinal (code-unit) string comparator for identity-feeding sorts — cache
|
|
3
|
+
* keys, dedupe keys, hashes, and signatures. Refs #2155, #2165.
|
|
4
|
+
*
|
|
5
|
+
* `localeCompare` orders strings by locale-dependent collation (the DEFAULT
|
|
6
|
+
* `Array.prototype.sort`, with no comparator, does not — it compares UTF-16
|
|
7
|
+
* code units, which is already ordinal). Locale-dependent order is fine for
|
|
8
|
+
* a list a human reads. It is a bug (SonarCloud S2871) when the sorted
|
|
9
|
+
* result feeds an identity: two processes — or one process whose locale
|
|
10
|
+
* changes — can order the same input differently under `localeCompare` and
|
|
11
|
+
* mint different keys for equivalent state, producing a silent cache or
|
|
12
|
+
* dedupe miss.
|
|
13
|
+
*
|
|
14
|
+
* Use this comparator whenever a sort's output becomes a key, a hash input,
|
|
15
|
+
* or a signature compared for equality later. Keep `localeCompare` for
|
|
16
|
+
* sorting that only affects what a person reads.
|
|
17
|
+
*/
|
|
18
|
+
export function compareOrdinal(a, b) {
|
|
19
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
20
|
+
}
|