Skip to content

feat(base2): add JavaScript Control-Flow Verification Rule to system prompt...#872

Open
chicagoist wants to merge 1 commit into
CodebuffAI:mainfrom
chicagoist:feat/js-control-flow-verification
Open

feat(base2): add JavaScript Control-Flow Verification Rule to system prompt...#872
chicagoist wants to merge 1 commit into
CodebuffAI:mainfrom
chicagoist:feat/js-control-flow-verification

Conversation

@chicagoist

Copy link
Copy Markdown

prompt...

Pull Request: Add JavaScript Control-Flow Verification Rule to Buffy Agent


Repository: CodebuffAI/codebuff
Target file: agents/base2/base2.ts
Target section: systemPrompt# General guidelines
Branch: main


Title

feat(base2): add JavaScript Control-Flow Verification Rule to system prompt

Problem

When debugging JS in HTML files, the agent falls into a "syntax-blind loop":
it sees node --check fail, fixes brace imbalances mechanically, and declares
success when the parser passes — without verifying the code actually executes.

Real-world case study (30-round debugging cycle)
  1. Agent ran node --check → SyntaxError (missing braces)
  2. 10+ rounds of string-replacement fixes
  3. node --check passed → agent declared "fixed"
  4. All interactive features were still broken

Root cause: quiz logic was wrapped in if (boxes.length > 0) where boxes = querySelectorAll('.answerbox[contenteditable]'). Those elements were removed
during a UI migration to checkboxes. boxes.length was always 0. Code was
syntactically valid but logically dead. The agent had grep, file reading,
and DOM analysis — but no mandatory checklist to use them.

This is a recurring class of bugs. The fix is not a new tool — it's a
mandatory methodology encoded in the system prompt.


Proposed Change

One new bullet in # General guidelines, placed after the closing backtick of
the Composio conditional block
(${ENABLE_COMPOSIO_TOOLS ? ... : ''}) and
before the literal line # Spawning agents guidelines.

Unified diff

--- a/agents/base2/base2.ts
+++ b/agents/base2/base2.ts
@@ systemPrompt template literal, General guidelines section @@
 - **Discover and install skills:** ...
 ${ENABLE_COMPOSIO_TOOLS
   ? `...`
   : ''
 }
+- **JavaScript Debugging:** After fixing JS syntax errors, do NOT stop at
+  \`node --check\` passing — the code may be syntactically valid but logically
+  dead. Verify: (1) every \`querySelector(All)\` target exists in the HTML body,
+  (2) execution reaches every \`addEventListener\` (trace from IIFE entry through
+  all wrapping \`if\` conditions), (3) no \`if (elements.length > 0)\` guard wraps
+  live logic around removed DOM elements. Only after all three checks pass should
+  the fix be considered complete.
 # Spawning agents guidelines

Rationale for single bullet

Existing guidelines use compact - **Topic:** Actionable instruction format.
This follows the same style. The three sub-checks are inline for brevity while
remaining specific enough to execute.


The Three Rules (reference)

# Rule Check
1 DOM cross-reference grep '<selector>' *.html → at least 1 match must exist
2 Execution-path trace From IIFE entry to each addEventListener — every wrapping if must be reachable
3 boxes.length > 0 pattern Any guard wrapping >10 lines of logic is a red flag after UI migration

Contribution Checklist

  • Change scoped to agents/ (per CONTRIBUTING.md)
  • No backend, database, billing, deployment, or secret-management code
  • Follows existing code style (template literal, bullet format)
  • Single bullet, minimal change — no structural refactoring
  • Applies to all modes (free/default/max/fast) — rule is in shared systemPrompt

Alternatives Considered

Approach Verdict
New instructionsPrompt section ❌ Too verbose, breaks existing flow
Separate skill file ❌ Must be loaded manually each session
Single bullet in Guidelines ✅ Always active, minimal, consistent

License

By submitting this pull request, I confirm that my contribution is made under
the terms of the project's license.

…prompt

Add a mandatory three-check rule to the General guidelines section:
1. DOM-selector cross-reference — verify querySelector targets exist
2. Execution-path trace — confirm addEventListener calls are reachable
3. boxes.length > 0 pattern — detect dead guards after UI migration

Prevents the recurring class of bugs where JS is syntactically valid
(node --check passes) but logically dead due to unreachable code wrapped
in a falsy condition referencing removed DOM elements.
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