Repository navigation
fix: restore build integrity across all 13 packages #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
92c5afa
6265bd2
00aa3ab
81406f3
a4be943
8e62afd
19b139d
6f8185e
09a7082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| concurrency: | ||
| group: ci-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build-test: | ||
| name: Build and test all packages | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Full history is needed: the secret scan compares the PR's commits | ||
| # against origin/main, and the dist-vs-source check diffs the tree. | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 10.33.2 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22 | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| # Packages are built in dependency order. codeflow-core is the root of | ||
| # the graph; everything else depends on it transitively. | ||
| # | ||
| # codeflow-core | ||
| # ├── codeflow-store | ||
| # │ ├── codeflow-prd | ||
| # │ ├── codeflow-analysis | ||
| # │ ├── codeflow-versioning | ||
| # │ └── codeflow-agent | ||
| # ├── codeflow-mcp | ||
| # ├── codeflow-execution | ||
| # │ └── codeflow-dtwin | ||
| # ├── codeflow-canvas | ||
| # ├── codeflow-evolution | ||
| # └── codeflow-master (consumes all of the above + CodeRag) | ||
| # | ||
| # CodeRag is built before the packages that consume its types | ||
| # (codeflow-canvas, codeflow-versioning, codeflow-master). | ||
| - name: Build packages in dependency order | ||
| run: | | ||
| set -euo pipefail | ||
| for pkg in \ | ||
| codeflow-core \ | ||
| codeflow-store \ | ||
| codeflow-prd \ | ||
| codeflow-analysis \ | ||
| codeflow-mcp \ | ||
| codeflow-execution \ | ||
| codeflow-dtwin \ | ||
| CodeRag \ | ||
| codeflow-canvas \ | ||
| codeflow-evolution \ | ||
| codeflow-versioning \ | ||
| codeflow-agent \ | ||
| Codeflow_master | ||
| do | ||
| echo "::group::build $pkg" | ||
| npm --prefix "packages/$pkg" run build | ||
| echo "::endgroup::" | ||
| done | ||
|
|
||
| - name: Test packages | ||
| run: | | ||
| set -uo pipefail | ||
| failed=0 | ||
| for pkg in \ | ||
| codeflow-store \ | ||
| codeflow-prd \ | ||
| codeflow-analysis \ | ||
| codeflow-mcp \ | ||
| codeflow-execution \ | ||
| codeflow-dtwin \ | ||
| codeflow-canvas \ | ||
| codeflow-evolution \ | ||
| codeflow-versioning \ | ||
| codeflow-agent \ | ||
| CodeRag \ | ||
| Codeflow_master | ||
| do | ||
| echo "::group::test $pkg" | ||
| if ! npm --prefix "packages/$pkg" test; then | ||
| echo "::error::$pkg tests failed" | ||
| failed=1 | ||
| fi | ||
| echo "::endgroup::" | ||
| done | ||
| exit $failed | ||
|
|
||
| # dist/ is committed to this repository, so a stale dist/ means the | ||
| # published artifact does not match the source. Rebuilding and diffing | ||
| # catches that before it reaches npm. | ||
| # Two things can go wrong here, and `git diff` only catches the first: | ||
| # a committed file that the build no longer produces, and a file the | ||
| # build produces that was never committed. The second is the one that | ||
| # silently ships a broken package - the entry point exists in the | ||
| # exports map but is missing from the published tarball. | ||
| - name: Verify committed dist/ matches source | ||
| run: | | ||
| set -euo pipefail | ||
| git config --global --add safe.directory "$GITHUB_WORKSPACE" | ||
|
|
||
| if ! git diff --exit-code -- 'packages/*/dist'; then | ||
| echo "::error::Committed dist/ is stale. Run 'pnpm -r build' and commit the result." | ||
| git diff --stat -- 'packages/*/dist' | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Files the build produced that are not in the index. `dist` is | ||
| # gitignored, so a new build output has to be added explicitly. | ||
| # | ||
| # Only the packages that commit dist/ are checked. codeflow-core, | ||
| # CodeRag and the IDE build their output at publish time instead, | ||
| # so their dist/ is deliberately absent from the repository. | ||
| dist_paths=() | ||
| for pkg in codeflow-store codeflow-prd codeflow-analysis codeflow-mcp \ | ||
| codeflow-execution codeflow-dtwin codeflow-canvas \ | ||
| codeflow-evolution codeflow-versioning codeflow-agent; do | ||
| dist_paths+=(":(glob)packages/$pkg/dist/**") | ||
| done | ||
|
|
||
| untracked="$(git ls-files --others --ignored --exclude-standard -- "${dist_paths[@]}")" | ||
| if [[ -n "$untracked" ]]; then | ||
| echo "::error::Built dist/ files are not committed. Run 'git add -f packages/*/dist' and commit." | ||
| echo "$untracked" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # A package that imports a module it does not declare works locally by | ||
| # way of a hoisted copy and fails in CI, where the install is isolated. | ||
| - name: Check for undeclared imports | ||
| run: python3 scripts/check-undeclared-imports.py | ||
|
|
||
| # The build and test loops name packages by their directory under | ||
| # packages/, which differs from the npm package name for two of them. | ||
| - name: Check CI package paths | ||
| run: python3 scripts/check-ci-package-paths.py | ||
|
|
||
| # A package can declare an entry point in its exports map that the | ||
| # build never produces. TypeScript compiles fine and the failure only | ||
| # shows up in the installed package, as ERR_MODULE_NOT_FOUND. | ||
| - name: Check declared exports resolve | ||
| run: node scripts/check-exports-resolve.mjs | ||
|
|
||
| # gitleaks is not preinstalled on the runner image, so the repo's | ||
| # `pnpm secrets:scan` script fails with "gitleaks: not found". | ||
| # | ||
| # The scan is scoped to the commits this PR introduces. A full-history | ||
| # scan reports four leaks that predate this branch - a Gemini key and | ||
| # an NVIDIA key committed in 10fbd89 (2026-04-02), and a MiniMax key | ||
| # in 1f713b5 (2026-05-26). They are not in the current tree, but they | ||
| # are still in git history and those credentials should be rotated. | ||
| # This gate blocks NEW leaks; purging history is a separate operation. | ||
| - name: Secret scan | ||
| uses: gitleaks/gitleaks-action@v2 | ||
| env: | ||
| # The action requires a token to scan pull requests. | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| version: v8.28.0 | ||
| args: >- | ||
| detect --source . --redact --config .gitleaks.toml | ||
| --log-opts="origin/main..HEAD" | ||
|
|
||
| codeql: | ||
| name: Analyze (${{ matrix.language }}) | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| security-events: write | ||
| packages: read | ||
| actions: read | ||
| contents: read | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| language: [javascript-typescript] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: ${{ matrix.language }} | ||
|
|
||
| - uses: github/codeql-action/autobuild@v3 | ||
|
|
||
| - uses: github/codeql-action/analyze@v3 | ||
| with: | ||
| category: "/language:${{ matrix.language }}" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # pnpm workspace settings for the CodeFlow monorepo. | ||
| # | ||
| # link-workspace-packages | ||
| # Link a workspace package instead of fetching it from the registry when the | ||
| # local version satisfies the declared range. Without this, a package whose | ||
| # local version drifts outside the declared range is silently resolved from | ||
| # npm — so local edits to that package never reach the running app. | ||
| # | ||
| # prefer-workspace-packages | ||
| # When the local version and the published version are identical, pnpm still | ||
| # prefers the registry. prefer-workspace-packages makes the workspace copy | ||
| # win the tie, so a package is always built and consumed from source. | ||
| link-workspace-packages=true | ||
| prefer-workspace-packages=true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,71 @@ | ||
| import type { Stats } from "node:fs"; | ||
| import fs from "node:fs/promises"; | ||
|
|
||
| /** | ||
| * Timestamp-resolution safety margin. | ||
| * | ||
| * The kernel stamps inodes from the *coarse* system clock and truncates it to | ||
| * the filesystem's timestamp granularity, so several writes that land inside | ||
| * the same granularity window share one mtime value. Measured on this host: | ||
| * ~4ms on ext4 (deltas of 0.0ms and 4.000014ms alternate across rapid | ||
| * writes); ext3/HFS+ use 1s and FAT/exFAT use 2s. | ||
| * | ||
| * Consequence: a cache that trusts mtime alone can hand back content that | ||
| * was already overwritten — the cached entry looks fresh even though the | ||
| * file changed. | ||
| * | ||
| * The fingerprint (mtime + size + inode) is therefore only conclusive once | ||
| * the mtime observed at read time is already older than one granularity | ||
| * window: the mtime recorded at read time is the start of the window the | ||
| * content was written in, so any write that happens after such a read | ||
| * necessarily lands on a strictly greater timestamp and is detected. While | ||
| * the file is still inside the window the fingerprint proves nothing, and | ||
| * the file is read again. | ||
| * | ||
| * The margin must exceed the coarsest plausible filesystem granularity (2s | ||
| * for FAT/exFAT) plus the coarse-clock lag, hence 4s. Files modified within | ||
| * that window are simply re-read until they age out of it. | ||
| */ | ||
| const MTIME_RESOLUTION_MARGIN_MS = 4000; | ||
|
|
||
| type CacheEntry = { | ||
| content: string; | ||
| mtimeMs: number; | ||
| size: number; | ||
| ino: number; | ||
| /** | ||
| * Wall-clock time at which the read that produced `content` started. | ||
| * The fingerprint is conclusive only when the mtime observed for that read | ||
| * was already outside the filesystem's timestamp resolution window. | ||
| */ | ||
| readAt: number; | ||
| }; | ||
|
|
||
| export class FileCache { | ||
| private readonly cache = new Map<string, CacheEntry>(); | ||
|
|
||
| async read(filePath: string): Promise<string> { | ||
| // The read is timestamped *before* stat() so the anchor used by the | ||
| // conclusiveness check is never later than the moment the content was | ||
| // actually obtained. | ||
| const readAt = Date.now(); | ||
| // stat() is taken before the read on purpose: the recorded mtime must | ||
| // never describe a write that is newer than the content we hold, or a | ||
| // later rewrite could hide behind an unchanged fingerprint. | ||
| const stats = await fs.stat(filePath); | ||
| const cached = this.cache.get(filePath); | ||
|
|
||
| if (cached && cached.mtimeMs === stats.mtimeMs) { | ||
| if (cached && this.matchesFingerprint(cached, stats) && this.isConclusive(cached)) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a source file is rewritten to different same-length content within the filesystem's timestamp-resolution window, this guard is the new behavior that prevents returning stale cached retrieval content. The existing page-index test changes the file size and manually invalidates the cache, so it does not cover this case; add a direct regression test for the same-fingerprint rewrite. AGENTS.md reference: packages/CodeRag/AGENTS.md:L25-L26 Useful? React with 👍 / 👎. |
||
| return cached.content; | ||
| } | ||
|
|
||
| const content = await fs.readFile(filePath, "utf8"); | ||
| this.cache.set(filePath, { | ||
| content, | ||
| mtimeMs: stats.mtimeMs | ||
| mtimeMs: stats.mtimeMs, | ||
| size: stats.size, | ||
| ino: stats.ino, | ||
| readAt | ||
| }); | ||
| return content; | ||
| } | ||
|
|
@@ -31,4 +77,25 @@ export class FileCache { | |
| clear(): void { | ||
| this.cache.clear(); | ||
| } | ||
|
|
||
| /** | ||
| * Cheap fingerprint check. mtime alone is not enough (see | ||
| * MTIME_RESOLUTION_MARGIN_MS), but a change in size or inode always | ||
| * invalidates the entry. | ||
| */ | ||
| private matchesFingerprint(cached: CacheEntry, stats: Stats): boolean { | ||
| return cached.mtimeMs === stats.mtimeMs && cached.size === stats.size && cached.ino === stats.ino; | ||
| } | ||
|
|
||
| /** | ||
| * True when the fingerprint provably identifies the cached content. | ||
| * | ||
| * The mtime recorded at read time was already older than one resolution | ||
| * window, so every write that happens afterwards bumps it and is detected | ||
| * by the fingerprint. While the file is still inside the window a rewrite | ||
| * is invisible to the fingerprint, so the file has to be read again. | ||
| */ | ||
| private isConclusive(cached: CacheEntry): boolean { | ||
| return cached.mtimeMs <= cached.readAt - MTIME_RESOLUTION_MARGIN_MS; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
npm ciis run insidepackages/CodeRag, the tracked lockfile still declares@abhinav2203/codeflow-coreas^1.1.2and locks1.1.2, while this manifest now requires^1.1.7; npm ci exits when the lock and manifest dependencies do not match (npm ci docs). Update the package lock alongside this dependency change.Useful? React with 👍 / 👎.