Files
hermes-agent/agent/plan_prompt.py
Teknium be5c6a2fd8 refactor(agent/prompt): remove dead code, unify duplicated helpers, compact docstrings across prompt/skill/redaction modules
Dead (zero refs): coding_system_blocks, get_friendly_tool_labels, get_scan_ordered_skills_dirs,
_project_quarantine_cache_clear, clear_stable_prefixes, _redact_http_request_target_query_params,
_has_http_method_substring, PromptCachePlan.marker_count, display _diff_* colour thunks (-> _diff_ansi),
pass-through RedactingFormatter.__init__.
Unified: _slugify -> slugify_skill_name; reload diff -> diff_command_snapshots; _is_summary_item ->
is_compaction_summary_message alias; sanitizer walkers -> _sanitize_messages/_sanitize_structure;
assignment redaction passes -> _redact_assignments/_should_redact_assignment; quiet-mode tool lines -> _CUTE_LINES table.
2026-09-02 13:53:57 -07:00

83 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""``/plan`` — build the plan-mode prompt: a saved markdown implementation plan, no execution.
A first-class built-in (the former bundled skill fell off capped Telegram/Discord
command menus). No engine, no model-tool footprint: every surface feeds
:func:`build_plan_prompt` to the agent as a normal turn, like ``/learn`` and
``/init``, so system prompt and history stay untouched (prompt-cache safe).
"""
from __future__ import annotations
# Plan-mode ground rules + authoring craft, distilled from the retired bundled
# skill (writing-craft adapted from obra/superpowers).
_PLAN_MODE_RULES = """\
For this turn, you are in PLAN MODE — planning only.
- Do not implement code.
- Do not edit project files except the plan markdown file itself.
- Do not run mutating terminal commands, commit, push, or perform external
actions.
- You may inspect the repo or other context with read-only commands/tools
when needed.
- Your deliverable is a markdown plan saved inside the active workspace under
`.hermes/plans/YYYY-MM-DD_HHMMSS-<slug>.md` (create the directory if
needed; Hermes file tools are backend-aware, so this relative path keeps
the plan with the workspace on local, docker, ssh, modal, and daytona
backends). If the runtime provides a specific target path, use that exact
path instead.
"""
_PLAN_CRAFT = """\
Write the plan for an implementer with zero context for the codebase and
questionable taste. A good plan makes implementation obvious — if someone has
to guess, the plan is incomplete.
Structure (include the sections that are relevant):
- Goal — one sentence.
- Current context / assumptions.
- Architecture / proposed approach — 2-3 sentences.
- Step-by-step tasks. Each task is bite-sized (2-5 minutes of focused work),
names exact file paths (`src/models/user.py`, not "the model file"),
includes complete copy-pasteable code where code is needed, and exact
commands with expected output for verification.
- Tests / validation — for code tasks, follow the TDD cycle per task: write
the failing test, run it to verify failure, implement minimally, run to
verify pass, commit.
- Risks, tradeoffs, and open questions.
Principles: DRY, YAGNI, TDD, frequent commits. Avoid vague tasks ("add
authentication"), incomplete code ("add validation here"), and unverifiable
steps ("test it works" — instead: the exact command and its expected output).
Interaction style:
- If the request is clear enough, write the plan directly.
- If it is genuinely underspecified, ask a brief clarifying question instead
of guessing.
- After saving the plan, reply briefly with what you planned and the saved
path, and offer to execute it (e.g. via subagent-driven development) —
but do not start executing in this turn.
"""
def build_plan_prompt(task: str = "") -> str:
"""Build the plan-mode prompt; empty *task* asks the agent to infer it from conversation context."""
task = (task or "").strip()
if task:
task_block = f"Task to plan:\n{task}\n"
else:
task_block = (
"No explicit task was given with /plan — infer the task from the "
"current conversation context (the thing we have been discussing "
"or working toward). If the conversation does not imply a task, "
"ask a brief clarifying question.\n"
)
return (
"[/plan — plan mode]\n\n"
+ _PLAN_MODE_RULES
+ "\n"
+ task_block
+ "\n"
+ _PLAN_CRAFT
)