refactor: extract lib/heuristics.mjs + lib/operations.mjs (Phase 0)#41
Open
vidhartbhatia wants to merge 4 commits into
Open
refactor: extract lib/heuristics.mjs + lib/operations.mjs (Phase 0)#41vidhartbhatia wants to merge 4 commits into
vidhartbhatia wants to merge 4 commits into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 0: Extract shared lib modules
Problem
extension.mjsandmcp-server.mjsduplicate tool classification logic, brag-entry orchestration, andatomicWriteText. 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, compositeclassifyToolUse()lib/operations.mjs- SharedsaveBragEntry/reviewBragEntries/generateWorkLogwith{ ok: true/false }returnsatomicWriteTextmoved from both entry points intolib/storage.mjsTest results
177 tests, 0 failures (was 127). Three-model adversarial council review passed.
Bug fixes included
isBragRequestfalse negatives on mixed prompts (caught by skeptic review)Partial progress on #22.