Skip to content

perf(cli/mcp): decouple analysis view contracts and defer tshark PATH probes - #13316

Merged
morluto merged 2 commits into
mainfrom
perf/cli-bundle-decoupling-and-lazy-probes
Nov 22, 2026
Merged

morluto merged 2 commits into
mainfrom
perf/cli-bundle-decoupling-and-lazy-probes

Conversation

@morluto

@morluto morluto commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Summary

Decouples global CLI/contract barrel imports (openBinaryToolContract, analysisViewResult summary schemas, nativeTargetOption, analysisEvidenceDeliveryOptions), splits src/composition/binaryDiagnostics.ts for handler-time lazy imports, and defers tshark (tsharkLocatable) PATH probes out of createServer startup (Refs #13275):

  1. Break global barrel edges across CLI & contract modules (129 files):
    • Extracted openBinaryOutputSchema & OPEN_BINARY_TOOL_CONTRACT into openBinaryToolContract.ts (re-exported from sessionToolContracts.ts and shared with toolOutputSchemaGroups.ts).
    • Extracted NATIVE_OPEN_HELP & nativeTarget into nativeTargetOption.ts and analysisEvidenceDeliveryOptions / cliEvidenceDeliveryInputError into analysisEvidenceDeliveryOptions.ts; switched analysisEvidenceDelivery.ts to dynamic await import(...) for AnalysisViewService, EvidenceBundleCommands, AnalysisEvidenceSources, and evidenceBundle (loading AnalysisViewService only when evidenceOutput !== undefined && input.detail === "summary").
    • Moved byteEntropyOutputSchema to byteEntropyOutputSchema.ts and electronFuseOutputSchemas to electronFuseOutputSchema.ts.
  2. Split analysisViewResult.ts summary schemas (48 domain-scoped modules):
    • Extracted artifactSchema, viewResultBaseFields, and summaryViewResultBase into analysisViewBase.ts (zero dependency on NATIVE_INVENTORY_OPERATIONS / NATIVE_OBSERVATION_OPERATIONS).
    • Extracted contract-referenced summary/page schemas into 48 slim files under src/domain/analysisView/summarySchemas/*.ts, re-exported by analysisViewResult.ts for backward compatibility while repointing domain *ToolContracts.ts, toolOutputSchemaGroups.ts, and ArtifactComparisonEvidence.ts so only analysisViewToolContracts.ts pulls in analysisViewResult.ts.
  3. Lazy binaryDiagnostics service handlers & deferred tsharkLocatable probe:
    • Widened inspectWithService / deliverWithService in contractCommand.ts to accept () => EvidenceInspectionService | Promise<EvidenceInspectionService>.
    • Split binaryDiagnostics.ts into 20 per-service modules under src/composition/binaryDiagnostics/*.ts and switched binaryDiagnosticsCommands.ts to dynamic await import(...) per command handler.
    • Added OptionalAvailabilityFeatures / observeOptionalFeatures to CapabilityAvailability.ts, moved packetCapture (tsharkLocatable) out of eager createServer startup probes in capabilityServices.ts, and evaluated it only in default sessionAvailabilityPolicy.ts when "artifact" is advertised (createServer.ts).

Problem and expected behavior

  • CLI one-shot commands (such as inspect-binary-hardening) and createServer startup eagerly pulled in analysisViewResult.ts (~1.3 MB bundled chunks), all 20 binary diagnostics composition services, and EvidenceBundle/AnalysisViewService graphs (~6 MB static ESM chunks across 193 modules), while createServer ran a subprocess tshark PATH lookup even when the "artifact" family was not advertised or a custom availability policy was active.
  • Expected behavior: identical CLI command discovery/execution, MCP schemas, tool catalogs, AnalysisView summary schemas, and capability availability diagnostics with 67.5% smaller static CLI module graphs and zero eager tshark spawn on server startup.

Change and scope

Follow the contribution scope.
Not applicable (internal module-graph decoupling, dynamic handler imports, and lazy capability availability within existing CLI/MCP boundaries).

Contract and boundary impact

  • Semantic owner and earliest changed stage: openBinaryToolContract.ts, analysisViewBase.ts, CapabilityAvailability.ts, capabilityServices.ts, sessionAvailabilityPolicy.ts.
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: preserved (cliContractCommandParity, cliContractSchemaParity, cliToolCoverage, and docs:check all pass).
  • Provider, bridge, target-format, or platform compatibility: preserved (tsharkLocatable deferred to "artifact" family policy evaluation; 3 Linux-only availability cases skipped on darwin).
  • Evidence, artifact, provenance, or reconstruction contract: preserved (analysisViewResult.ts re-exports all extracted schemas identically).
  • Target selection, authority, upstream behavior, and cleanup details: preserved (updated barrel spies in binaryDiagnosticsCliCleanup.test.ts, pwntoolsCliRemediation.test.ts, pwntoolsCliFinalization.test.ts to target direct module owners binaryLayout.js / recordedCrash.js).
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: verified via npm run build:cached and npm run docs:check.

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated:
    • packetCaptureAvailability.test.ts: verifies deferred tsharkLocatable detection on binary_session and confirms skipping when "artifact" is unadvertised or custom availabilityPolicy is supplied.
    • Updated barrel spies in binaryDiagnosticsCliCleanup.test.ts, pwntoolsCliRemediation.test.ts, and pwntoolsCliFinalization.test.ts.
  • Base reproduction or other evidence (dist/cli-runtime/, Apple M5 arm64, Node v24.22.1):
    • 7-root static ESM graph: 193 chunks (6,079,227 B) -> 118 chunks (1,974,876 B) (-38.9% chunks, -67.5% / -4,104,351 B)
    • binaryDiagnosticsCommands static ESM graph: 154 chunks (5,395,355 B) -> 66 chunks (1,193,860 B) (-57.1% chunks, -77.9% / -4,201,495 B)
    • node scripts/rea.mjs inspect-binary-hardening <sample.bin> --json: loaded dist/cli-runtime/ chunks 194 -> 147 (6,089,776 B -> 2,283,357 B, -62.5%); cold 495.2 ms -> 346.7 ms, warm median 735.7 ms -> 343.9 ms (2.14x faster).
  • User-visible CLI/MCP output (if applicable): unchanged command/MCP output with faster startup and zero unnecessary tshark probe on startup.
  • Remaining proof gaps: 3 Linux-only packet capture availability tests skipped on darwin.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run format:check (8,676 files) — passed
  • npm run build:cached (3/3 in 8.744s) — passed
  • npm run check:fast (typecheck, lint, verify:architecture-guards across 3,018 source files) — passed
  • npm run verify:module-boundaries (4,680 files) & npm run docs:check (8/8) — passed
  • npm run test:focused (14 compiled boundary suites including packetCaptureAvailability.test.ts & cliLazyRegistration.test.ts) — 14/14 files, 1,016 passed | 3 Linux-only skipped (it.runIf(linux))
  • npm run test:focused (unsandboxed CLI startup/cleanup suites: tests/boundary/cli/cliStartupImports.test.ts 6/6, tests/process-global/pwntoolsCliFinalization.test.ts 13/13) — 2/2 files, 19/19 passed
  • npm run test:local (35 non-HTTP server/view/contract/cli unit suites) — 35/35 files, 293 passed | 3 pre-existing win32 skips
  • npm run test:local (unsandboxed HTTP server suites: serveEnvironmentState.test.ts 25/25, serveStreamableHttp.test.ts 69/69, serveEnvironment.test.ts 12/12, nodeHttpBridge.test.ts 9/9) — 4/4 files, 115/115 passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none (analysisViewResult.ts and binaryDiagnostics.ts preserve re-exports for existing consumers).
  • Real Hopper/Ghidra, browser, or OS coverage: Node v24.22.1 CLI/MCP compiled-runtime suites on darwin.
  • Package or release metadata impact: verify:module-boundaries and docs:check pass across all updated modules.
  • Security, privacy, process, or containment review: deferred tsharkLocatable respects hostRestrictedAvailability policies and does not alter capability authorization semantics.

Author readiness

Human owner:

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T14:44:41.781856Z 8ddedbb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5 Tier: plus

[Medium impact] The PR appears safe to merge; no actionable regression was found.

Summary

Splits shared contracts and summary schemas into smaller modules. Diagnostic services and evidence-delivery modules now load when requested. tshark discovery moves from startup to default session-status checks.

  • Contracts load focused analysis-view schemas instead of a broad result module.
  • CLI commands load only the service and delivery code they need.
  • The server checks for tshark when packet-capture status is requested.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  CLI["CLI command"] --> Contracts["Small contracts and options"]
  CLI -->|"handler runs"| Service["Selected diagnostic service"]
  CLI -->|"summary with evidence_output"| View["AnalysisViewService"]
  CLI -->|"evidence_output"| Bundle["EvidenceBundleCommands"]
  Server["createServer"] -->|"later binary_session request"| Policy["Availability policy"]
  Policy -->|"default policy and artifact advertised"| Probe["tshark PATH lookup"]
Loading

Reviews (3) · Last reviewed commit: "test(cli): separate one-shot import suit..." · Reviewed by Greptile

Comment thread src/cli/binaryDiagnosticsCommands.ts Resolved
@morluto morluto changed the title perf(cli,mcp): decouple analysisViewResult/session contracts from CLI paths and defer tshark PATH probes perf(cli/mcp): decouple analysis view contracts and defer tshark PATH probes Nov 22, 2026
@morluto
morluto force-pushed the perf/cli-bundle-decoupling-and-lazy-probes branch from 8427825 to 8ddedbb Compare November 22, 2026 14:42
@morluto

morluto commented Nov 22, 2026

Copy link
Copy Markdown
Owner Author

@greptileai review

@morluto
morluto enabled auto-merge (squash) November 22, 2026 14:52
@morluto
morluto merged commit 787b5aa into main Nov 22, 2026
52 checks passed
@morluto
morluto deleted the perf/cli-bundle-decoupling-and-lazy-probes branch November 22, 2026 14:54
@morluto morluto added area: cli CLI adapter and one-shot commands performance Performance regressions, scaling limits, and bounded-resource work provider: tshark Analysis provider / engine: tshark labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli CLI adapter and one-shot commands performance Performance regressions, scaling limits, and bounded-resource work provider: tshark Analysis provider / engine: tshark

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant