Skip to content

refactor: extract lib/heuristics.mjs + lib/operations.mjs (Phase 0)#41

Open
vidhartbhatia wants to merge 4 commits into
mainfrom
phase0-extract-heuristics-operations
Open

refactor: extract lib/heuristics.mjs + lib/operations.mjs (Phase 0)#41
vidhartbhatia wants to merge 4 commits into
mainfrom
phase0-extract-heuristics-operations

Conversation

@vidhartbhatia
Copy link
Copy Markdown
Collaborator

Phase 0: Extract shared lib modules

Problem

extension.mjs and mcp-server.mjs duplicate tool classification logic, brag-entry orchestration, and atomicWriteText. Adding Agency hooks (Phase 1) would triplicate this.

Solution

Extract shared logic into two new dependency-free lib/ modules:

  • lib/heuristics.mjs - Tool classification sets, extraction helpers, isBragRequest, composite classifyToolUse()
  • lib/operations.mjs - Shared saveBragEntry/reviewBragEntries/generateWorkLog with { ok: true/false } returns
  • atomicWriteText moved from both entry points into lib/storage.mjs

Test results

177 tests, 0 failures (was 127). Three-model adversarial council review passed.

Bug fixes included

  • isBragRequest false negatives on mixed prompts (caught by skeptic review)
  • git config fallback NPE risk in extension.mjs (caught by architect review)

Partial progress on #22.

vidhartbhatia and others added 4 commits May 12, 2026 11:04
Extract tool classification sets (FILE_CREATE_TOOLS, FILE_EDIT_TOOLS,
PR_TOOLS, SHELL_TOOLS), extraction helpers (extractFilePath,
extractPrInfo, detectShellGitAction), brag keyword detection
(isBragRequest), and composite classifier (classifyToolUse) into a
reusable, dependency-free lib module.

extension.mjs now imports from lib/heuristics.mjs and uses
classifyToolUse() in onPostToolUse instead of inline classification.

test/heuristics.test.mjs has 33 tests covering all extracted functions.
test/extension.test.mjs updated to import from lib/heuristics.mjs
instead of re-implementing inline copies.

158 tests passing (was 127).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Extract saveBragEntry, reviewBragEntries, and generateWorkLog into
lib/operations.mjs with discriminated { ok: true/false } returns.
Both extension.mjs and mcp-server.mjs now delegate to these shared
operations instead of duplicating validate-create-persist-backup logic.

Move atomicWriteText from inline definitions in both entry points
into lib/storage.mjs where it belongs alongside atomicWriteJSON.

test/operations.test.mjs adds 16 tests covering all three operations
including whitespace-only summary validation edge cases.
test/storage.test.mjs adds 2 tests for atomicWriteText.

176 tests passing (was 158).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add lib/heuristics.mjs and lib/operations.mjs to release.yml tarball
validation required[] array. Update AGENTS.md §2 (architecture: new
modules in lib table), §3 (test count 107→176), §4 (atomicWriteText
unified in storage.mjs), §5 (test table with new test files), and
§9 (repo navigation: heuristics.mjs, operations.mjs entries).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…allback

isBragRequest: The BRAG_EXCLUDE_REGEX (/brag(?:ging|gart)/i) caused
false negatives on prompts containing both 'bragging' and standalone
'brag' (e.g. 'bragging rights brag'). The \b word boundary already
prevents matching 'bragging' or 'braggart', making the exclude
redundant. Removed per adversarial council skeptic review.

extension.mjs: Align git config fallback with mcp-server.mjs — add
null-safe ?? { enabled: false, push: false } guard to prevent NPE
when config.git is undefined. Per architect review.

177 tests passing (was 176).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@vidhartbhatia vidhartbhatia requested a review from a team as a code owner May 12, 2026 21:58
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