Repository navigation
feat: Pi-style iterative planning for OpenCode plugin - #318
Conversation
Move ChecklistItem, parseChecklist, extractDoneSteps, and markCompletedSteps from Pi extension to @plannotator/shared for reuse by the OpenCode plugin. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Rewrite the OpenCode plugin to match Pi's planning methodology: - Inject rich iterative planning prompt when agent is "plan" (explore → update plan → ask user loop, structured plan format) - File-based submit_plan: reads plan from disk instead of requiring it as a string arg. Resolves path from OpenCode's system prompt, falls back to PLAN.md - Suppress plan_exit via tool.definition hook (directs to submit_plan) - Add PLANNOTATOR_ALLOW_SUBAGENTS env var for #289 - Pass planFilePath to denial feedback template - Keep existing subagent/build/title guards intact Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Cache agents list (static per session, was fetched every LLM call) - Remove TOCTOU: drop redundant file.exists() before file.text() - Eliminate duplicate system.join() by reusing joined string - Resolve getSharingEnabled() once in submit_plan instead of twice - Use path.join() instead of string concatenation for file paths Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Keep plan_exit compatibility, but remove plan_exit from the normal injected prompt. Specifically:
Why this is the right balance:
So the principle is:
|
Replace plugin-global resolvedPlanFilePath and prompt-path parsing with
per-session plan files at ~/.plannotator/session-plans/opencode/{id}/plan.md.
Remove resolvePlanFilePath() regex (fixes spaces-in-path and cross-session
race). Make planning prompt tool-neutral (no write/edit references) so it
works with apply_patch models. Strip OpenCode's native read-only and
experimental-mode prompt lines before injecting Plannotator's planning prompt.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Replace session-scoped plan files with a shared plan directory at ~/.plannotator/session-plans/opencode/. Agent picks the filename, submit_plan takes a path arg and validates it (absolute, inside plan dir, exists, readable, non-empty) with canonical path checks to defeat traversal and symlink escapes. Remove summary and plan string args. Planning prompt is now tool-neutral and directs the agent to reuse the same file on feedback, not create new ones. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
All points from this comment are addressed. Here's the full rationale for what changed and why: plan_exit handling (this comment):
Plan storage (from external review feedback):
submit_plan simplification:
Planning prompt:
|
|
Re: subagent prompt injection concern — |
OpenCode's plan mode permission ruleset only allows edits to .opencode/plans/*.md and $XDG_DATA_HOME/opencode/plans/*.md. Our custom ~/.plannotator/session-plans/opencode/ path was blocked by PermissionDeniedError at the tool level regardless of prompt stripping. Switch to the XDG path that OpenCode already allows. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Restructure the planning prompt as a phased workflow: Explore → Ask → Write → Submit. The agent now explores the codebase before creating a plan file or asking questions, producing better-researched plans for existing codebases. Greenfield tasks can skip straight to questions. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
For this to work reliably, shouldn't the submit_plan tool be hidden from context? How would OpenCode know not to use this? I'm a little confused about how this all works. |
PR #318 replaced the original text-based submit_plan with a file-path-only version and split prompt injection between plan/non-plan agents. This caused regressions: the agent couldn't figure out file paths from non-plan agents, and the 80+ line prompt with TodoWrite replacements was fragile against OpenCode upstream changes. This restores the original submit_plan(plan) that accepts markdown text directly — the contract that worked uniformly across all agents — and keeps the file-based workflow as submit_plan_file(path) for users who want persistent plan files. Key changes: - Two tools: submit_plan (text) + submit_plan_file (path) - Unified prompt for all primary agents (not just plan mode) - Removed aggressive TodoWrite string replacements and system-reminder - Kept adversarial stripping of OpenCode's STRICTLY FORBIDDEN rules - Extracted shared server helpers to reduce duplication Addresses #328 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* fix: restore uniform submit_plan and add submit_plan_file for OpenCode PR #318 replaced the original text-based submit_plan with a file-path-only version and split prompt injection between plan/non-plan agents. This caused regressions: the agent couldn't figure out file paths from non-plan agents, and the 80+ line prompt with TodoWrite replacements was fragile against OpenCode upstream changes. This restores the original submit_plan(plan) that accepts markdown text directly — the contract that worked uniformly across all agents — and keeps the file-based workflow as submit_plan_file(path) for users who want persistent plan files. Key changes: - Two tools: submit_plan (text) + submit_plan_file (path) - Unified prompt for all primary agents (not just plan mode) - Removed aggressive TodoWrite string replacements and system-reminder - Kept adversarial stripping of OpenCode's STRICTLY FORBIDDEN rules - Extracted shared server helpers to reduce duplication Addresses #328 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: single submit_plan with auto-detect text/path for OpenCode Collapses submit_plan + submit_plan_file back into one tool that auto-detects whether the argument is plan text or a file path. First submission: agent passes markdown text (simple, works from any agent). On deny: response includes the history path where the plan was saved, so the agent can Edit the file for targeted revisions and resubmit with the path. Key changes: - One tool: submit_plan(plan) accepts text or absolute .md file path - Server surfaces historyPath through waitForDecision (already saved by saveToHistory, just not returned before) - Deny response includes file path hint for Edit-based revision workflow - Unified prompt for all primary agents (~25 lines, no TodoWrite warfare) - Still strips OpenCode's STRICTLY FORBIDDEN rules and suppresses plan_exit Addresses #328 and rcdailey's feedback on PR #333 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: remove historyPath leak, error on missing file paths, restore two-tier prompt - Remove historyPath from deny flow — internal history directory should not be exposed to agents. Text submissions get text feedback; file submissions get file feedback. No crossover. - Error when agent passes an absolute .md path that doesn't exist instead of silently treating it as plan text. - Restore two-tier prompt: plan agent gets full planning instructions, other primary agents get a minimal reminder (matching pre-v0.13.0 behavior). - Clean up stale prompt copy referencing historyPath-based revision flow. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> * fix: restore todowrite override, strengthen planning prompt, remove noisy logs - Override todowrite description to defer to submit_plan during active planning - Tool description now instructs agent to explore and ask questions before submitting - Sequenced planning prompt: explore, ask, then write - Remove success logs from integration saves (stderr was bleeding through) - Append resubmit reminder to OpenCode deny feedback Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Summary
Rewrites the OpenCode plugin's planning experience with file-based plan storage, an exploration-first prompt, and interactive browser review.
What changed
$XDG_DATA_HOME/opencode/plans/(defaults to~/.local/share/opencode/plans/), matching OpenCode's native permission-allowed path. Agent picks the filename, revises the same file on feedback.submit_plan(path)— Takes a file path (not plan text). Validates: absolute path, canonical containment (symlink/traversal protection), file exists, readable, non-empty. Opens browser review UI.write/edittool references in the prompt. Works with GPT models usingapply_patch.plan_exitsuppressed —tool.definitionhook rewrites description to redirect tosubmit_plan.submit_planhidden from subagents by default viaprimary_tools.PLANNOTATOR_ALLOW_SUBAGENTS=1makes it visible (visibility toggle only — no prompt injection for subagents, see Subagents Can't findsubmit_plantool #289).@plannotator/shared/checklistfor cross-plugin reuse.How it works
~/.local/share/opencode/plans/submit_plan(path: "...")→ plugin validates path, reads content, opens browser UIsubmit_planagainTest plan
bun test apps/opencode-plugin/plan-mode.test.ts— 13 tests passbun run build:opencode— builds successfully./tests/manual/local/sandbox-opencode.sh~/.local/share/opencode/plans/, callssubmit_plan— noPermissionDeniedError/plannotator-reviewworks with sample changesCloses #289, closes #63, closes #152, closes #129, closes #183
🤖 Generated with Claude Code