Skip to content

perf(init): pre-compute dir listing and send _prevPhases for cross-phase caching#307

Merged
betegon merged 6 commits intofeat/init-commandfrom
feat/precompute-dir-listing
Mar 3, 2026
Merged

perf(init): pre-compute dir listing and send _prevPhases for cross-phase caching#307
betegon merged 6 commits intofeat/init-commandfrom
feat/precompute-dir-listing

Conversation

@betegon
Copy link
Member

@betegon betegon commented Feb 27, 2026

Summary

Two optimizations to reduce round-trips during the init wizard:

  1. Pre-computed directory listing — sends a pre-computed directory listing with the first API call so the server can skip its initial list-dir suspend. Saves one full HTTP round-trip in the discover-context step.

  2. _prevPhases for cross-phase caching — tracks per-step result history (stepHistory) and sends _prevPhases with each resume payload. This lets the server reuse results from earlier phases (e.g. the read-files phase can reuse data from analyze) without re-requesting them.

Changes

  • Exports precomputeDirListing from local-ops.ts — reuses the existing listDir function with the same params the server would request (recursive, maxDepth 3, maxEntries 500). The wizard runner calls it before startAsync and includes the result as dirListing in inputData.
  • Adds a stepHistory map to track accumulated local-op results per step. Each resume payload now includes _prevPhases containing results from prior phases of the same step.

Companion server change: getsentry/cli-init-api#16

Test plan

  • Init tests pass (bun test test/lib/init/)
  • Lint passes
  • End-to-end with local dev server

🤖 Generated with Claude Code

Scans the project directory locally and sends the listing with the
initial workflow request. This lets the server's discover-context step
skip its list-dir suspend, saving one full round-trip.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (api) Add --data/-d flag and auto-detect JSON body in fields by BYK in #320
  • (formatters) Render all terminal output as markdown by BYK in #297
  • (init) Add init command for guided Sentry project setup by betegon in #283
  • (issue-list) Global limit with fair distribution, compound cursor, and richer progress by BYK in #306
  • (trace) Add sentry trace logs subcommand (Add CLI support for fetching logs associated with a trace #247) by BYK in #311

Bug Fixes 🐛

Api

  • Use numeric project ID to avoid "not actively selected" error by betegon in #312
  • Use limit param for issues endpoint page size by BYK in #309
  • Auto-correct ':' to '=' in --field values with a warning by BYK in #302

Formatters

  • Expand streaming table to fill terminal width by betegon in #314
  • Fix HTML entities and escaped underscores in table output by betegon in #313

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (nightly) Push to GHCR from artifacts dir so layer titles are bare filenames by BYK in #301
  • (region) Resolve DSN org prefix at resolution layer by BYK in #316
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308
  • (trace-logs) Timestamp_precise is a number, not a string by BYK in #323
  • Added auth headers in the mastra client by MathurAditya724 in #264

Internal Changes 🔧

Api

  • Upgrade @sentry/api to 0.21.0, remove raw HTTP pagination workarounds by BYK in #321
  • Wire listIssuesPaginated through @sentry/api SDK for type safety by BYK in #310

Other

  • (init) Pre-compute dir listing and send _prevPhases for cross-phase caching by betegon in #307

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Codecov Results 📊

108 passed | Total: 108 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -2324
Passed Tests 📉 -2324
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 3093 uncovered lines.
✅ Project coverage is 82.33%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
local-ops.ts 97.94% ⚠️ 7 Missing
wizard-runner.ts 99.45% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    81.23%    82.33%     +1.1%
==========================================
  Files          121       129        +8
  Lines        16711     17502      +791
  Branches         0         0         —
==========================================
+ Hits         13574     14409      +835
- Misses        3137      3093       -44
- Partials         0         0         —

Generated by Codecov Action

betegon and others added 5 commits March 3, 2026 17:05
Combines the precomputed directory listing logic with the createRun()
call that was added in the base branch.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ry[] directly

Extract inline entry shape into a named DirEntry type and add
precomputeDirListing() that returns DirEntry[] instead of LocalOpResult,
so callers get the entries array directly without type assertions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@betegon betegon changed the title perf(init): pre-compute directory listing before first API call perf(init): pre-compute dir listing and send _prevPhases for cross-phase caching Mar 3, 2026
@betegon betegon marked this pull request as ready for review March 3, 2026 17:09
@betegon betegon merged commit 5313a92 into feat/init-command Mar 3, 2026
17 checks passed
@betegon betegon deleted the feat/precompute-dir-listing branch March 3, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant