MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / _handle_command

Method _handle_command

core/daemon.py:114–193  ·  view source on GitHub ↗

Handle a user command (prompt). The 0.5B model on port 8081 plans the task into numbered steps. Each step is added as a dependent task so the 7B agent works through them one at a time. If the planner is unavailable, times out, or returns fewer than 2 steps,

(self, data: Dict)

Source from the content-addressed store, hash-verified

112 return {"status": "ok", "message": "pong"}
113
114 async def _handle_command(self, data: Dict) -> Dict:
115 """Handle a user command (prompt).
116
117 The 0.5B model on port 8081 plans the task into numbered steps.
118 Each step is added as a dependent task so the 7B agent works through
119 them one at a time.
120
121 If the planner is unavailable, times out, or returns fewer than 2 steps,
122 the prompt is queued as a single direct task. Planner failure is always
123 silent (logged only) and never surfaces as an error.
124 """
125 prompt = data.get("prompt", "")
126 if not prompt:
127 return {"status": "error", "message": "No prompt provided"}
128
129 # Log to episodic log
130 self.state.log_action("command_received", prompt[:200])
131
132 # ── plannd integration (Change 1) ────────────────────────────────────
133 no_plan = data.get("no_plan", False)
134 if not no_plan:
135 try:
136 from core.planner_client import send_plan_request_async
137 steps = await asyncio.wait_for(
138 send_plan_request_async(prompt),
139 timeout=180.0,
140 )
141 if steps and len(steps) > 1:
142 if data.get("plan_only", False):
143 task_ids = []
144 info(f"plannd: returned {len(steps)}-step plan (plan_only)")
145 else:
146 # Inject original prompt into step 1 (the create step)
147 # so the executor has full requirements context.
148 # Later steps (run/verify) are usually self-contained
149 # and don't need the full prompt — just the step.
150 total = len(steps)
151 enriched = []
152 for i, step in enumerate(steps):
153 if i == 0:
154 # Step 1: full context — the executor needs
155 # all requirements to write the code
156 enriched.append(
157 f"User's full request: {prompt}\n\n"
158 f"Your task (step {i+1}/{total}): {step}\n\n"
159 "Write the COMPLETE file with ALL features "
160 "described above. Do not skip any requirement."
161 )
162 else:
163 enriched.append(
164 f"Previous context: {prompt[:200]}\n\n"
165 f"Your task (step {i+1}/{total}): {step}\n\n"
166 "Complete only this step."
167 )
168 task_ids = self.planner.add_tasks(enriched)
169 info(f"plannd: queued {len(steps)}-step plan")
170 return {
171 "status": "ok",

Callers

nothing calls this directly

Calls 8

send_plan_request_asyncFunction · 0.90
infoFunction · 0.90
warningFunction · 0.90
appendMethod · 0.80
add_tasksMethod · 0.80
getMethod · 0.45
log_actionMethod · 0.45
add_taskMethod · 0.45

Tested by

no test coverage detected