Skip to content

Commit 72f7111

Browse files
authored
refactor: restructure plan mode with shift+tab toggle and system prompt injection (#5)
* refactor(plan): restructure planning mode with shift+tab toggle and system prompt injection * docs: update changelog
1 parent 6e04305 commit 72f7111

2 files changed

Lines changed: 44 additions & 25 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ All notable changes to agent-stuff are documented here.
44

55

66

7-
## docs/update-readme-extensions
7+
8+
9+
10+
11+
## refactor/plan-mode-restructure
12+
13+
Plan mode now supports two entry points: **Shift+Tab** for instant toggling with the planning system prompt injected via `before_agent_start` (#5), and the existing **/plan** command for one-shot planning flows. The restructuring separates the reusable `PLAN_SYSTEM_PROMPT` constant from command-specific logic, enabling seamless mode switching without prompting for input on toggle. Read-only tool restrictions and bash command filtering remain intact, maintaining the safety guarantees of planning mode while improving UX for users who frequently switch between exploratory and implementation phases.
14+
15+
## [1.0.0](https://github.com/kostyay/agent-stuff/pull/4) - 2026-03-02
816

917
Updated the README to document two new extensions and clarify project structure. Added [`git-rebase-master.ts`](#4) extension which automates rebasing against main/master branches with LLM-powered conflict resolution, and documented the new [`sandbox/`](#4) directory enabling OS-level sandboxing for bash commands via `sandbox-exec` on macOS and bubblewrap on Linux with configurable filesystem and network restrictions. Also clarified the `.github/` directory location in the project structure overview.
1018

11-
## git-rebase-master
19+
## [1.0.0](https://github.com/kostyay/agent-stuff/pull/2) - 2026-03-02
1220

1321
Added `/git-rebase-master` command that fetches the latest `main` or `master`
1422
from origin and rebases the current branch onto it. The extension auto-detects
@@ -22,7 +30,7 @@ new `autoBranch` option on `performCommit`.
2230
`/commit-push-pr` now creates PRs in ready mode by default instead of draft
2331
mode, streamlining the publish workflow for most use cases.
2432

25-
## docs/update-readme-and-sandbox
33+
## [1.0.0](https://github.com/kostyay/agent-stuff/pull/3) - 2026-03-02
2634

2735
The commit extension was overhauled to dramatically reduce token consumption by gathering changelog context deterministically through git/gh commands and calling the model once for summary generation, with the new `/merge-pr` command streamlining the full pre-merge workflow including changelog updates, incremental PR description refresh, and squash-merge with cleanup. The sandbox extension now supports runtime toggling via `/sandbox on` and `/sandbox off` commands with a visual status indicator, eliminating the need to restart. An auto-release workflow now replaces the npm-publish pipeline, automatically creating GitHub tags and releases on main merges when `package.json` version changes, with release notes extracted from `CHANGELOG.md` via a new Python script that falls back to the git commit log. (#3)
2836

pi-extensions/plan.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
/**
2-
* /plan - One-shot planning mode
2+
* Plan Mode Extension
33
*
4-
* Usage: /plan <prompt>
4+
* Provides two ways to enter planning mode:
55
*
6-
* Enters a read-only planning flow:
7-
* 1. Restricts tools to read-only (read, bash safe-only, grep, find, ls, ask_question)
8-
* 2. Agent explores codebase, asks clarifying questions via ask_question
9-
* 3. Agent presents plan in sections, validates each with ask_question
10-
* 4. On completion, asks user where to save and whether to execute
6+
* 1. **Shift+Tab** — Toggles plan mode on/off instantly. Tools are restricted
7+
* to read-only and the planning system prompt is injected via
8+
* `before_agent_start`. The user types their message normally in the editor.
9+
*
10+
* 2. **/plan <prompt>** One-shot planning: enters plan mode and immediately
11+
* sends the prompt to the agent with planning instructions.
12+
*
13+
* In plan mode:
14+
* - Tools are restricted to read-only (read, bash safe-only, grep, find, ls, ask_question)
15+
* - Bash commands are filtered to a safe allowlist
16+
* - The system prompt is augmented with planning instructions
17+
* - On agent completion, the user is offered save/execute/refine options
1118
*
1219
* Depends on kbrainstorm extension for the ask_question tool.
1320
*/
@@ -128,14 +135,12 @@ function getTextContent(message: AssistantMessage): string {
128135

129136
// ── Planning prompt ──────────────────────────────────────────────────────
130137

131-
function buildPlanPrompt(userPrompt: string): string {
132-
return `[PLAN MODE ACTIVE - READ ONLY]
138+
/** System prompt appended via `before_agent_start` when plan mode is active. */
139+
const PLAN_SYSTEM_PROMPT = `[PLAN MODE ACTIVE - READ ONLY]
133140
134141
You are in planning mode. You MUST NOT make any file changes.
135142
Your tools are restricted to read-only operations.
136143
137-
Your task: ${userPrompt}
138-
139144
Follow this process:
140145
1. Explore the codebase to understand the current state relevant to the task (read files, search, grep, etc.)
141146
2. Ask clarifying questions using ask_question (one question at a time, prefer multiple choice when possible)
@@ -154,6 +159,10 @@ Important:
154159
- Use ask_question for ALL questions to the user (never ask in plain text)
155160
- Be thorough in exploration before proposing the plan
156161
- Keep each plan section focused and concise`;
162+
163+
/** Builds a user message for the /plan command's one-shot flow. */
164+
function buildPlanPrompt(userPrompt: string): string {
165+
return `${PLAN_SYSTEM_PROMPT}\n\nYour task: ${userPrompt}`;
157166
}
158167

159168
// ── Extension ────────────────────────────────────────────────────────────
@@ -230,27 +239,29 @@ export default function planExtension(pi: ExtensionAPI) {
230239
},
231240
});
232241

233-
// ── Ctrl+Tab shortcut to toggle modes ───────────────────────────────
242+
// ── Shift+Tab shortcut to toggle modes ───────────────────────────────
234243

235244
pi.registerShortcut("shift+tab", {
236245
description: "Toggle between agent and plan mode",
237246
handler: async (ctx) => {
238247
if (planActive) {
239-
// Switch back to agent mode immediately
240248
exitPlanMode(ctx);
241249
ctx.ui.notify("Switched to agent mode.", "info");
242-
return;
250+
} else {
251+
enterPlanMode(ctx);
252+
ctx.ui.notify("Entered plan mode (read-only). Type your message below.", "info");
243253
}
254+
},
255+
});
244256

245-
// Entering plan mode — ask for a prompt
246-
const prompt = await ctx.ui.input("What do you want to plan?", "");
247-
if (!prompt?.trim()) return;
257+
// ── Inject planning system prompt ────────────────────────────────────
248258

249-
planPrompt = prompt.trim();
250-
enterPlanMode(ctx);
251-
ctx.ui.notify("Entered plan mode (read-only). Planning...", "info");
252-
pi.sendUserMessage(buildPlanPrompt(planPrompt));
253-
},
259+
pi.on("before_agent_start", async (event) => {
260+
if (!planActive) return;
261+
262+
return {
263+
systemPrompt: event.systemPrompt + "\n\n" + PLAN_SYSTEM_PROMPT,
264+
};
254265
});
255266

256267
// ── Block unsafe bash commands ───────────────────────────────────────

0 commit comments

Comments
 (0)