Skip to content

Limit cyclomatic complexity to 10 - #17

Merged
HugoLopes45 merged 5 commits into
mainfrom
chore/complexity-lint
Nov 11, 2026
Merged

HugoLopes45 merged 5 commits into
mainfrom
chore/complexity-lint

Conversation

@HugoLopes45

Copy link
Copy Markdown
Owner

Why

The turn_end handler had a cyclomatic complexity of 35. A change to one strategy risked another, as the shake-gate bug fixed in #16 showed. This PR adds pi-claude-pro's complexity lint (ESLint complexity at most 10, run on Node's type-stripped source) to npm run check, and splits the five functions above the limit.

Changes

  • scripts/lint.ts, npm run lint, and check now runs the lint. tsconfig.json includes scripts. CONTRIBUTING documents the rule.
  • Split without behavior change: turn_end and session_before_compact in extensions/index.ts, src/prune.ts, src/shake.ts, src/stale.ts. src/tool-calls.ts gets a shared newestToolResults generator.
  • Two intended deltas:
    • turn_end returns early without a model, after background.invalidate. Before, it computed a plan with no edits and returned nothing.
    • A focused /compact no longer cancels the background note itself, because handoff cancels it before it requests a note. A new test pins this.
  • eslint devDependency with a minimatch ^11 override: every minimatch 10.x has GHSA-g3hv-75wg-m249, and ESLint 10.14 pins ^10.2.6. npm audit reports 0 vulnerabilities. The lockfile adds 67 packages from registry.npmjs.org and removes none.

Verification

  • npm run check: tsc, lint clean, 97 tests passed.
  • Four new characterization tests (early-threshold wait, note start below the threshold, no retry of a failed note at Pi's threshold, focused /compact cancel) pass on the code before the split. Each one fails when its branch is removed, in the old code and in the new.
  • An independent read-only review (hl-code-review) compared the code line by line with the base and found the two deltas safe. Its two findings are fixed in d2af352: the messages are built inside the try again, and the focused-cancel test is added.

turn_end checked Pi's raw token count, not the planned result, before shaking after a handoff. When pruning alone reached the target, the default methodOrder still elided old code blocks and broke the cache once more.

The README said old file reads are still replaced with Pi's compaction off. Since edits happen only at the threshold, nothing changes then; the README now says so.

Install dependencies without lifecycle scripts in CI and release: the release job can request an npm publish token, and no dependency needs its install script for the checks.
The turn_end handler had a complexity of 35, so a change to one strategy risked another, as the shake gate bug showed. The lint is pi-claude-pro's: ESLint's complexity rule on Node's type-stripped source, run by npm run check.

The split keeps behavior. Three characterization tests pin paths no test covered, and each fails when its branch is removed, on the old code and on the new: waiting for a background note at an early threshold, starting a note only below the threshold, and not retrying a failed note at Pi's threshold. A focused /compact no longer cancels the background note itself, because handoff always cancels it before writing a new note.

minimatch is overridden to 11 for ESLint, because every 10.x release has GHSA-g3hv-75wg-m249 and the lint does not depend on the differences.
# Conflicts:
#	README.md
#	extensions/index.ts
#	package-lock.json
…act cancel

The split built the messages before the try, so an error there would stop turn_end instead of falling back to the next method. The new test pins that a focused /compact cancels an unfinished background note before it requests its own; it fails when handoff no longer cancels.
@HugoLopes45 HugoLopes45 self-assigned this Nov 11, 2026
npm 10, shipped with Node 22, applies a nested override only to the package it names, so npm ci rejected the lockfile's minimatch 11 under @eslint/config-array.
@HugoLopes45
HugoLopes45 merged commit ed522ed into main Nov 11, 2026
6 checks passed
@HugoLopes45
HugoLopes45 deleted the chore/complexity-lint branch November 11, 2026 14:09
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