-
Notifications
You must be signed in to change notification settings - Fork 0
feat(agentic): programmatic hexplan generation #192
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?
Conversation
Move hexplan creation from AI agent to API layer. The tRPC router now creates hexplan tiles deterministically before prompt building: - Parent tiles: auto-generate step list from subtask children - Leaf tiles: create single "Execute the task" step This eliminates the need for hexPlanInitializerPath parameter and simplifies the prompt builder to always expect an existing hexplan. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Add HEXFRAME_MCP_SERVER environment variable (defaults to "hexframe") and pass it through to buildPrompt, replacing hardcoded MCP tool names in execution instructions with the configurable server name. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe PR refactors the hexplan generation and execution model. It removes the initialization-based flow (hexPlanInitializerPath) and replaces it with automatic generation of hexplans based on tile type (parent vs. leaf). This includes updating documentation, simplifying the MCP tool input schema, adding new content generator utilities, and threading the new model through prompt construction and agentic routing. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Areas requiring extra attention:
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
UBIQUITOUS.md (1)
85-87: Docs: make Direction-0 and leaf-hexplan wording consistent with auto-generated single-step behavior.
- Line 86: “(…for the parent tile)” → “(…for the tile)”
- Line 120-121 vs Line 242-243: clarify leaf hexplan is auto-seeded with a single step (optionally with instruction), rather than implying a fully authored multi-step plan.
Also applies to: 118-123, 240-243
src/server/api/routers/agentic/agentic.ts (1)
409-446:instructionis silently ignored once a hexplan exists (likely regression).
Currentlyinstructiononly affectsgenerateLeafHexplanContent(...)during first-time hexplan creation. On subsequent calls, the instruction is dropped entirely from the prompt path.One minimal fix: inject
instructioninto the<task>content for this run (without mutating the stored hexplan):- task: { - title: hexecuteContext.task.title, - content: hexecuteContext.task.content || undefined, - coords: taskCoords - }, + task: { + title: hexecuteContext.task.title, + content: [ + hexecuteContext.task.content?.trim(), + instruction ? `Instruction:\n${instruction}` : undefined + ].filter(Boolean).join('\n\n') || undefined, + coords: taskCoords + },Apply the same change in both
executeTaskandhexecute.Also applies to: 563-600
🧹 Nitpick comments (6)
src/env.js (1)
37-39: ConstrainHEXFRAME_MCP_SERVERto a safe identifier charset (avoid malformedmcp__*__tool names).- HEXFRAME_MCP_SERVER: z.string().default("hexframe"), + HEXFRAME_MCP_SERVER: z + .string() + .trim() + .regex(/^[a-zA-Z0-9_-]+$/, "Invalid MCP server name") + .default("hexframe"),Also applies to: 80-81
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts (2)
2-5: Avoid duplicating the MCP server default in tests (reduce drift risk).Consider exporting a single
DEFAULT_MCP_SERVERfrom a shared config module (or from env module) and importing it here, rather than redefining'hexframe'in test code.
480-529: Generator tests: add an explicit “no children” expectation or guard.
generateParentHexplanContent([])currently has an undefined/implicit contract; either add a test asserting the intended output, or make the helper throw if called with 0 children to prevent accidental use on leaf tiles.CLAUDE.md (1)
84-91: Clarify that “Leaf” can still have context children (only “no subtask children”).
Right now “Leaf Tile: Has no subtask children (directions 1-6)” implies it, but adding an explicit sentence avoids readers interpreting “leaf” as “no children at all” (which conflicts with the negative-direction context model). As per coding guidelines / learnings, keep the subtask-vs-context distinction crisp.src/server/api/routers/agentic/agentic.ts (1)
422-465: Extract a shared “ensureHexplanTile(...)” helper to avoid drift between endpoints.
The “create hexplan if missing” + “choose parent vs leaf” logic is duplicated; a small shared helper (module-local) would reduce future divergence (e.g., when you tweak status token rules or add idempotency handling).Also applies to: 576-623
src/lib/domains/agentic/utils/prompt-builder.ts (1)
139-200: Make step detection robust (avoidincludes('📋')/includes('🔴')).
includes(...)can be tripped by arbitrary user text (e.g., an instruction containing 📋), which can incorrectly force the “pending steps” branch forever. Prefer line-based detection:- const hasPendingSteps = hexPlan.includes('📋') - const hasBlockedSteps = hexPlan.includes('🔴') + const hasPendingSteps = /^📋\s/m.test(hexPlan) + const hasBlockedSteps = /^🔴\s/m.test(hexPlan)Optional: if
hasBlockedStepsis true, consider surfacing BLOCKED even if pending steps exist (or explicitly instruct “resolve blockers first”), since blocked steps often gate progress.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
CLAUDE.md(2 hunks)UBIQUITOUS.md(3 hunks)src/app/services/mcp/handlers/tools.ts(3 hunks)src/env.js(2 hunks)src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts(21 hunks)src/lib/domains/agentic/utils/index.ts(1 hunks)src/lib/domains/agentic/utils/prompt-builder.ts(4 hunks)src/server/api/routers/agentic/agentic.ts(6 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Always use absolute imports with
~/prefix instead of relative imports (./or../) in TypeScript and JavaScript files
Files:
src/env.jssrc/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tssrc/lib/domains/agentic/utils/index.tssrc/lib/domains/agentic/utils/prompt-builder.tssrc/app/services/mcp/handlers/tools.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Implement Domain-Driven Design patterns in TypeScript files within/src/lib/domains/with clear boundaries between mapping, IAM, and other domains. Reference/src/lib/domains/README.mdfor domain implementation details
Use the hierarchical tile architecture for hexframe tiles: positive directions 1-6 for subtask children, negative directions -1 to -6 for context children, and direction 0 for hexplan (execution state and agent guidance). Tiles can have both subtask and context children simultaneously
In AI orchestration and hexplan implementation, agents must use emoji prefixes when updating hexplan tiles: 🟡 STARTED for task begun, ✅ COMPLETED for task finished, 🔴 BLOCKED for task stuck. Use standard MCP tools (getItemByCoords,updateItem) for hexplan updates
Implement Hexframe's execution philosophy: define system structure as a hierarchy with context and subtasks, run hexecute autonomously, monitor progress via hexplan tiles at direction-0, adjust by editing relevant hexplan tiles and restarting. Structure serves as the control interface, not chat history
Files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tssrc/lib/domains/agentic/utils/index.tssrc/lib/domains/agentic/utils/prompt-builder.tssrc/app/services/mcp/handlers/tools.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Use Vitest (not Jest) for all tests in TypeScript files
Files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts
src/server/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Backend must use tRPC for type-safe API with server-side caching and optimizations. Reference
/src/server/README.mdfor backend architecture details
Files:
src/server/api/routers/agentic/agentic.ts
src/app/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Frontend must use Next.js 15 App Router with progressive enhancement, following static → progressive → dynamic component patterns, and implement localStorage caching for performance. Reference
/src/app/map/README.mdfor UI architecture
Files:
src/app/services/mcp/handlers/tools.ts
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: The hexplan initialization system is itself a Hexframe system that demonstrates self-referential application of the model: it reads task hierarchies, analyzes context and subtask structure, generates initial hexplan tiles at direction-0, and sets up execution state for autonomous runs
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to **/*.{ts,tsx} : Implement Hexframe's execution philosophy: define system structure as a hierarchy with context and subtasks, run hexecute autonomously, monitor progress via hexplan tiles at direction-0, adjust by editing relevant hexplan tiles and restarting. Structure serves as the control interface, not chat history
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to **/*.{ts,tsx} : Use the hierarchical tile architecture for hexframe tiles: positive directions 1-6 for subtask children, negative directions -1 to -6 for context children, and direction 0 for hexplan (execution state and agent guidance). Tiles can have both subtask and context children simultaneously
📚 Learning: 2025-12-06T16:06:30.756Z
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to **/*.{ts,tsx} : Implement Hexframe's execution philosophy: define system structure as a hierarchy with context and subtasks, run hexecute autonomously, monitor progress via hexplan tiles at direction-0, adjust by editing relevant hexplan tiles and restarting. Structure serves as the control interface, not chat history
Applied to files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tsUBIQUITOUS.mdsrc/lib/domains/agentic/utils/prompt-builder.tsCLAUDE.mdsrc/app/services/mcp/handlers/tools.ts
📚 Learning: 2025-12-06T16:06:30.756Z
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to **/*.{ts,tsx} : In AI orchestration and hexplan implementation, agents must use emoji prefixes when updating hexplan tiles: 🟡 STARTED for task begun, ✅ COMPLETED for task finished, 🔴 BLOCKED for task stuck. Use standard MCP tools (`getItemByCoords`, `updateItem`) for hexplan updates
Applied to files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tsUBIQUITOUS.mdsrc/lib/domains/agentic/utils/prompt-builder.tsCLAUDE.mdsrc/app/services/mcp/handlers/tools.ts
📚 Learning: 2025-12-06T16:06:30.756Z
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to **/*.{ts,tsx} : Use the hierarchical tile architecture for hexframe tiles: positive directions 1-6 for subtask children, negative directions -1 to -6 for context children, and direction 0 for hexplan (execution state and agent guidance). Tiles can have both subtask and context children simultaneously
Applied to files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tsUBIQUITOUS.mdsrc/lib/domains/agentic/utils/prompt-builder.tsCLAUDE.mdsrc/app/services/mcp/handlers/tools.ts
📚 Learning: 2025-12-06T16:06:30.756Z
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: The hexplan initialization system is itself a Hexframe system that demonstrates self-referential application of the model: it reads task hierarchies, analyzes context and subtask structure, generates initial hexplan tiles at direction-0, and sets up execution state for autonomous runs
Applied to files:
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.tssrc/server/api/routers/agentic/agentic.tsUBIQUITOUS.mdsrc/lib/domains/agentic/utils/prompt-builder.tsCLAUDE.mdsrc/app/services/mcp/handlers/tools.ts
📚 Learning: 2025-12-06T16:06:30.756Z
Learnt from: CR
Repo: Diplow/hexframe PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T16:06:30.756Z
Learning: Applies to src/server/**/*.{ts,tsx} : Backend must use tRPC for type-safe API with server-side caching and optimizations. Reference `/src/server/README.md` for backend architecture details
Applied to files:
src/server/api/routers/agentic/agentic.ts
🧬 Code graph analysis (3)
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts (2)
src/lib/domains/agentic/utils/prompt-builder.ts (4)
PromptData(16-34)buildPrompt(216-229)generateParentHexplanContent(42-56)generateLeafHexplanContent(62-78)src/lib/domains/agentic/utils/index.ts (4)
PromptData(10-10)buildPrompt(6-6)generateParentHexplanContent(7-7)generateLeafHexplanContent(8-8)
src/server/api/routers/agentic/agentic.ts (3)
src/lib/domains/mapping/utils/index.ts (2)
CoordSystem(11-11)Direction(10-10)src/lib/domains/agentic/utils/prompt-builder.ts (2)
generateParentHexplanContent(42-56)generateLeafHexplanContent(62-78)src/env.js (2)
env(7-92)env(7-92)
src/lib/domains/agentic/utils/prompt-builder.ts (2)
src/lib/domains/agentic/utils/index.ts (2)
generateParentHexplanContent(7-7)generateLeafHexplanContent(8-8)src/lib/domains/agentic/services/serializers/xml-serializer.ts (1)
escapeXML(59-66)
🪛 LanguageTool
UBIQUITOUS.md
[style] ~113-~113: Consider using “who” when you are referring to a person instead of an object.
Context: ... Hexplan (Direction 0) A special child that stores execution state and progress. Th...
(THAT_WHO)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: ESLint
- GitHub Check: Build
- GitHub Check: Tests - Phase 1 (Main Suite)
- GitHub Check: Tests - Phase 2 (React Components)
🔇 Additional comments (6)
src/lib/domains/agentic/utils/index.ts (1)
5-10: Re-export expansion looks correct (public API wiring).src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts (1)
6-478: v5 PromptData fixture updates + hexplan status coverage look solid.UBIQUITOUS.md (1)
11-20: Leaf/Parent definitions match the execution model shift.src/app/services/mcp/handlers/tools.ts (1)
729-733: Hexecute tool update correctly dropshexPlanInitializerPathand forwards only runtime instruction.Also applies to: 749-752, 765-768
src/lib/domains/agentic/utils/prompt-builder.ts (2)
36-78: Good: generator outputs match the emoji/status conventions used by the execution loop.
Having API-owned deterministic initialization (🟡 STARTED + 📋 steps) is a clean separation, and keeps prompt building pure. Based on learnings, this matches the hexplan-as-control-interface approach.
216-223: LGTM: hasSubtasks derived from structural children and threaded into hexplan rendering.
This keeps orchestration decisions deterministic and local to prompt rendering.
| **The hexplan serves two audiences:** | ||
| 1. **For agents**: Tracks what's done, what's next, and any user adjustments | ||
| 2. **For humans**: Provides visibility into task progress for review and course-correction | ||
|
|
||
| **Hexplan content differs by tile type:** | ||
| - **Parent tile hexplan**: List of subtasks to execute in order (can be generated programmatically from children) | ||
| - **Leaf tile hexplan**: Agent's plan to complete the concrete work | ||
|
|
||
| **Update protocol:** Agents use standard MCP tools (`getItemByCoords`, `updateItem`) with emoji prefixes: | ||
| - 🟡 STARTED: Task began | ||
| - ✅ COMPLETED: Task finished | ||
| - 🔴 BLOCKED: Task stuck | ||
| **Status markers:** | ||
| - 📋 Pending (not started) | ||
| - 🟡 In progress | ||
| - ✅ Completed | ||
| - 🔴 Blocked (needs user intervention) | ||
|
|
||
| **Human-in-the-loop control:** | ||
| - Read `[1, 0]` to see top-level progress | ||
| - Edit `[1, 2, 0]` to adjust a specific subtask's approach | ||
| - Edit any hexplan to adjust the approach | ||
| - Mark steps as completed to skip them | ||
| - Add instructions at any level — agent incorporates them on next run | ||
|
|
||
| **Implementation:** The MCP `hexecute` tool in `src/app/services/mcp/handlers/tools.ts` reads hexplan tiles and includes them in prompts. Agents update using standard `updateItem` calls. | ||
|
|
||
| ### Hexplan Initialization: Hexframe Bootstrapping Hexframe | ||
|
|
||
| Since the hexplan is central to Hexframe execution, there's a **default Hexframe system for initializing hexplans**. This is Hexframe using its own formalism to define the system that creates hexplans for other systems. | ||
|
|
||
| The hexplan initialization system: | ||
| 1. Reads a task hierarchy | ||
| 2. Analyzes context and subtask structure | ||
| 3. Generates initial hexplan tiles at direction-0 for each task | ||
| 4. Sets up the execution state for autonomous runs | ||
| - Add instructions — agent incorporates them on next run | ||
|
|
||
| This bootstrap system is itself a Hexframe system — demonstrating the self-referential power of the model. | ||
| **Implementation:** The MCP `hexecute` tool reads hexplan tiles and includes them in prompts. Agents update using standard `updateItem` calls. |
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.
Align status/emoji vocabulary with the repo’s agent update conventions.
This section introduces 📋 Pending / 🟡 In progress / ✅ Completed / 🔴 Blocked, while the repo guidance emphasizes 🟡 STARTED / ✅ COMPLETED / 🔴 BLOCKED when agents update hexplan tiles. Consider making the “agent-written tokens” explicit (and keep 📋 as “pending step” if desired). Based on learnings, agents must use the emoji prefixes when updating hexplan tiles.
| // 3. Create hexplan tile if it doesn't exist | ||
| let hexPlanContent = hexecuteContext.hexPlan | ||
| if (!hexPlanContent) { | ||
| const taskId = parseInt(hexecuteContext.task.id, 10) | ||
| const taskCoord = CoordSystem.parseId(taskCoords) | ||
| const hexplanCoords = { | ||
| ...taskCoord, | ||
| path: [...taskCoord.path, Direction.Center] | ||
| } | ||
|
|
||
| // 3. Build the hexecute prompt (pure function, no I/O) | ||
| // Generate hexplan content based on tile type | ||
| const hasSubtasks = hexecuteContext.structuralChildren.length > 0 | ||
| hexPlanContent = hasSubtasks | ||
| ? generateParentHexplanContent(hexecuteContext.structuralChildren) | ||
| : generateLeafHexplanContent(hexecuteContext.task.title, instruction) | ||
|
|
||
| // Create the hexplan tile | ||
| await ctx.mappingService.items.crud.addItemToMap({ | ||
| parentId: taskId, | ||
| coords: hexplanCoords, | ||
| title: 'Hexplan', | ||
| content: hexPlanContent | ||
| }) | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
# First, let's look at the full context around lines 422-445 and 576-599
cd /repo
wc -l src/server/api/routers/agentic/agentic.tsRepository: Diplow/hexframe
Length of output: 177
🏁 Script executed:
# Read the section around lines 422-445
sed -n '410,460p' src/server/api/routers/agentic/agentic.tsRepository: Diplow/hexframe
Length of output: 1989
🏁 Script executed:
# Read the section around lines 576-599
sed -n '560,620p' src/server/api/routers/agentic/agentic.tsRepository: Diplow/hexframe
Length of output: 2341
🏁 Script executed:
# Find the Task model/entity to determine ID type
find . -type f \( -name "*.ts" -o -name "*.tsx" \) | xargs grep -l "interface Task\|type Task\|class Task" | grep -E "(domain|model|type)" | head -10Repository: Diplow/hexframe
Length of output: 41
🏁 Script executed:
# Find addItemToMap implementation
rg "addItemToMap" -A 15 --type tsRepository: Diplow/hexframe
Length of output: 50372
🏁 Script executed:
# Find Task interface/type definition
rg "interface Task|type Task" -A 5 src/lib/domains --type ts | head -50Repository: Diplow/hexframe
Length of output: 41
🏁 Script executed:
# Find the actual addItemToMap implementation in mapping service
find src -name "*.ts" -path "*/service*" -o -path "*/crud*" | head -10Repository: Diplow/hexframe
Length of output: 574
🏁 Script executed:
# Search for addItemToMap implementation
rg "addItemToMap.*\{" -A 20 --type ts src/server | head -100Repository: Diplow/hexframe
Length of output: 9415
🏁 Script executed:
# Look for any UNIQUE constraints or duplicate handling on map_items
rg "UNIQUE|duplicate|conflict" --type ts src/lib/domains/mappingRepository: Diplow/hexframe
Length of output: 2852
🏁 Script executed:
# Check the mapping service items crud file
find src -name "*items*" -path "*mapping*" -type fRepository: Diplow/hexframe
Length of output: 159
🏁 Script executed:
# Find the mapping service items crud
find src/lib/domains/mapping -name "*crud*" -o -name "*items*" | grep -E "(crud|items)" | head -10Repository: Diplow/hexframe
Length of output: 262
🏁 Script executed:
# Look for Task entity in agentic domain
find src/lib/domains/agentic -type f -name "*.ts" | xargs grep -l "interface Task\|type Task\|class Task" | head -5Repository: Diplow/hexframe
Length of output: 41
🏁 Script executed:
# Search for addItemToMap method implementation directly
rg "async addItemToMap|addItemToMap.*=" src/lib/domains/mapping --type ts -A 30Repository: Diplow/hexframe
Length of output: 11101
🏁 Script executed:
# Check map-items table schema for uniqueness
cat src/server/db/schema/_tables/mapping/map-items.tsRepository: Diplow/hexframe
Length of output: 3751
🏁 Script executed:
# Get full addItemToMap implementation
sed -n '1,100p' src/lib/domains/mapping/services/_item-services/_item-crud.service.ts | head -150Repository: Diplow/hexframe
Length of output: 3356
🏁 Script executed:
# Find where hexecuteContext.task comes from and its type
rg "getHexecuteContext" -A 20 --type ts src/lib/domains | head -80Repository: Diplow/hexframe
Length of output: 2480
🏁 Script executed:
# Check the exact lines 422-445 and 576-599 in agentic.ts to see which functions they're in
sed -n '395,450p' src/server/api/routers/agentic/agentic.ts | cat -nRepository: Diplow/hexframe
Length of output: 2645
🏁 Script executed:
# Also check lines 550-625 to see the second occurrence
sed -n '550,625p' src/server/api/routers/agentic/agentic.ts | cat -nRepository: Diplow/hexframe
Length of output: 3353
🏁 Script executed:
# Check if there's try-catch around the addItemToMap in both functions
sed -n '28,52p' src/server/api/routers/agentic/agentic.tsRepository: Diplow/hexframe
Length of output: 871
🏁 Script executed:
# Check the complete addItemToMap to see if it handles unique violations
sed -n '44,150p' src/lib/domains/mapping/services/_item-services/_item-crud.service.tsRepository: Diplow/hexframe
Length of output: 3203
Handle hexplan creation race condition and validate ID parsing.
Two issues with hexplan creation:
-
Race/duplication: The
if (!hexPlanContent)check followed byaddItemToMapis not atomic. Two concurrent requests can both observe missing hexplan and attempt creation. Since the DB has a UNIQUE constraint on(coord_user_id, coord_group_id, path), the second call will fail with an unhandled error. Wrap in try-catch to detect "already exists" errors and re-fetch, or make the operation idempotent (e.g., use an upsert pattern). -
ID parsing:
parseInt(hexecuteContext.task.id, 10)assumes numeric string IDs. While task.id comes from the DB integer column and is safe in practice, validate explicitly or handle NaN to avoid silent failures if ID format changes.
Also applies to lines 576–599 (identical hexplan creation block in the hexecute query). Both instances should be extracted to a shared helper function to reduce duplication.
🤖 Prompt for AI Agents
In src/server/api/routers/agentic/agentic.ts around lines 422-445, the hexplan
creation is vulnerable to a race that can cause UNIQUE-constraint DB errors and
also blindly parses task.id with parseInt; wrap the create logic in a try-catch
that catches unique-constraint (or duplicate key) errors, on such an error
re-fetch the existing hexplan tile instead of failing, and otherwise surface
other errors; validate the result of parseInt(task.id, 10) (throw or handle if
NaN) or use the original numeric id type, and replace the inline block with a
shared helper function (used also at the identical block at lines ~576-599) that
performs: validate id, compute coords, generate content, attempt addItemToMap
inside try-catch handling “already exists” by fetching and returning the
existing tile, making the operation idempotent.
Move hexplan creation from AI agent to API layer. The tRPC router now creates hexplan tiles deterministically before prompt building:
This eliminates the need for hexPlanInitializerPath parameter and simplifies the prompt builder to always expect an existing hexplan.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor
Chores
✏️ Tip: You can customize this high-level summary in your review settings.