Skip to content

Conversation

@Diplow
Copy link
Owner

@Diplow Diplow commented Dec 15, 2025

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

Summary by CodeRabbit

  • New Features

    • Automated hexplan generation based on tile type (parent vs leaf).
  • Refactor

    • Tile architecture now strictly enforces leaf or parent designation.
    • Status markers updated from emoji-based to readable format (Pending, In progress, Completed, Blocked).
    • Simplified hexplan execution model.
  • Chores

    • Added environment configuration option.
    • Updated development practices documentation.

✏️ Tip: You can customize this high-level summary in your review settings.

Diplow and others added 2 commits December 15, 2025 00:50
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>
@vercel
Copy link

vercel bot commented Dec 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
hexframe Ready Ready Preview, Comment Dec 15, 2025 0:30am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

The 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

Cohort / File(s) Summary
Documentation updates
CLAUDE.md, UBIQUITOUS.md
Updated conceptual guidance to reflect new hexplan-driven execution model: tiles are either parent (orchestration) or leaf (concrete work), never both. Replaced initialization/bootstrapping descriptions with automatic hexplan generation on hexecute. Added status markers (Pending, In progress, Completed, Blocked) and clarified dual-audience content framing.
MCP tool schema simplification
src/app/services/mcp/handlers/tools.ts
Removed hexPlanInitializerPath from hexecute input schema. Updated instruction parameter description from initialization-focused to execution-focused. Simplified handler to pass only instruction to underlying hexecute call.
Environment configuration
src/env.js
Added new HEXFRAME_MCP_SERVER environment variable to server schema with default value "hexframe" and corresponding runtime mapping.
Hexplan generation utilities
src/lib/domains/agentic/utils/prompt-builder.ts
Introduced two new exported content generators: generateParentHexplanContent() for parent tiles and generateLeafHexplanContent() for leaf tiles. Made hexPlan required in PromptData interface. Removed instruction and hexPlanInitializerPath fields. Refactored buildHexplanSection() to accept hasSubtasks boolean instead of hexPlanInitializerPath. Added logic to return COMPLETE or BLOCKED status when no pending steps remain.
Utility exports
src/lib/domains/agentic/utils/index.ts
Added exports for generateParentHexplanContent and generateLeafHexplanContent alongside existing buildPrompt and PromptData exports.
Test suite migration
src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts
Migrated tests to new v5 API surface using hexplan content model with emoji-prefixed steps. Updated PromptData fixtures to remove instruction and hexPlanInitializerPath. Added new test suites for content generators (generateParentHexplanContent, generateLeafHexplanContent). Reorganized tests into labeled groups and expanded coverage for status rendering (COMPLETE, BLOCKED) and XML-escaping behavior. Replaced hardcoded 'hexframe' with DEFAULT_MCP_SERVER.
Agentic router refactoring
src/server/api/routers/agentic/agentic.ts
Imported new content generators (generateParentHexplanContent, generateLeafHexplanContent). Added hexplan creation flow: auto-generate hexplan if missing, compute content based on tile type (parent vs. leaf), and persist via mappingService. Replaced hardcoded/context-derived mcpServerName with env.HEXFRAME_MCP_SERVER. Removed all hexPlanInitializerPath references. Threaded hexPlanContent through prompt construction. Updated streaming response to include hexecutePrompt for transparency.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • src/lib/domains/agentic/utils/prompt-builder.ts: Core signature changes to PromptData interface and buildHexplanSection() function; validation that hexPlan is now always required and the new content generators handle both parent and leaf tile cases correctly.
  • src/server/api/routers/agentic/agentic.ts: Hexplan generation and propagation logic; ensure hexPlanContent is correctly computed and threaded through all prompt-building paths; verify env.HEXFRAME_MCP_SERVER is consistently used.
  • Test migration accuracy: Confirm new test fixtures and content generator tests cover edge cases (missing instruction in leaf tiles, parent tile step ordering, status marker rendering).
  • Interface contract changes: Verify all call sites of buildHexplanSection() and buildPrompt() have been updated with the new signatures and parameter types.

Possibly related PRs

  • Develop #128: Restructures MCP tool handlers and input normalization in the same file (src/app/services/mcp/handlers/tools.ts); may have overlapping changes to the hexecute tool interface.
  • Develop #181: Both PRs overhaul the hexPlan initialization model and modify hexecute/prompt-building code paths; may introduce conflicting approaches.
  • Develop #127: Reworks src/app/services/mcp/handlers/tools.ts into a centralized MCP tools registry framework; directly overlaps with hexecute tool changes in this PR.

Poem

A rabbit hops through the hexframe's lanes,
Where tiles now choose: parent or leaves,
No more init scripts, just generation's refrains—
Auto-planning flows, the agent believes! 🐰✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: introducing programmatic hexplan generation at the API layer instead of agent-based generation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch develop

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: instruction is silently ignored once a hexplan exists (likely regression).
Currently instruction only affects generateLeafHexplanContent(...) during first-time hexplan creation. On subsequent calls, the instruction is dropped entirely from the prompt path.

One minimal fix: inject instruction into 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 executeTask and hexecute.

Also applies to: 563-600

🧹 Nitpick comments (6)
src/env.js (1)

37-39: Constrain HEXFRAME_MCP_SERVER to a safe identifier charset (avoid malformed mcp__*__ 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_SERVER from 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 (avoid includes('📋') / 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 hasBlockedSteps is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e22cb0 and 9a2217e.

📒 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.js
  • src/lib/domains/agentic/utils/__tests__/prompt-builder.test.ts
  • src/server/api/routers/agentic/agentic.ts
  • src/lib/domains/agentic/utils/index.ts
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • src/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.md for 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.ts
  • src/server/api/routers/agentic/agentic.ts
  • src/lib/domains/agentic/utils/index.ts
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • src/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.md for 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.md for 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.ts
  • src/server/api/routers/agentic/agentic.ts
  • UBIQUITOUS.md
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • CLAUDE.md
  • src/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.ts
  • src/server/api/routers/agentic/agentic.ts
  • UBIQUITOUS.md
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • CLAUDE.md
  • src/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.ts
  • src/server/api/routers/agentic/agentic.ts
  • UBIQUITOUS.md
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • CLAUDE.md
  • src/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.ts
  • src/server/api/routers/agentic/agentic.ts
  • UBIQUITOUS.md
  • src/lib/domains/agentic/utils/prompt-builder.ts
  • CLAUDE.md
  • src/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 drops hexPlanInitializerPath and 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.

Comment on lines +158 to +178
**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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Comment on lines +422 to +445
// 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
})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 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.ts

Repository: 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.ts

Repository: 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.ts

Repository: 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 -10

Repository: Diplow/hexframe

Length of output: 41


🏁 Script executed:

# Find addItemToMap implementation
rg "addItemToMap" -A 15 --type ts

Repository: 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 -50

Repository: 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 -10

Repository: Diplow/hexframe

Length of output: 574


🏁 Script executed:

# Search for addItemToMap implementation
rg "addItemToMap.*\{" -A 20 --type ts src/server | head -100

Repository: 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/mapping

Repository: Diplow/hexframe

Length of output: 2852


🏁 Script executed:

# Check the mapping service items crud file
find src -name "*items*" -path "*mapping*" -type f

Repository: 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 -10

Repository: 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 -5

Repository: 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 30

Repository: Diplow/hexframe

Length of output: 11101


🏁 Script executed:

# Check map-items table schema for uniqueness
cat src/server/db/schema/_tables/mapping/map-items.ts

Repository: 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 -150

Repository: 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 -80

Repository: 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 -n

Repository: 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 -n

Repository: 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.ts

Repository: 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.ts

Repository: Diplow/hexframe

Length of output: 3203


Handle hexplan creation race condition and validate ID parsing.

Two issues with hexplan creation:

  1. Race/duplication: The if (!hexPlanContent) check followed by addItemToMap is 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).

  2. 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.

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.

2 participants