diff --git a/apps/x/packages/core/src/agents/runtime.ts b/apps/x/packages/core/src/agents/runtime.ts index 24bfbc36..20242113 100644 --- a/apps/x/packages/core/src/agents/runtime.ts +++ b/apps/x/packages/core/src/agents/runtime.ts @@ -1331,14 +1331,16 @@ The user has turned on **code mode** and the composer chip is set to **${agentDi 1. By toggling the chip in the composer (preferred). 2. By asking you directly in chat ("use codex", "switch to claude", "do this with ${otherDisplay}", etc.). When the user explicitly asks to use a different agent in the current message, honor that — use \`${otherAgent}\` instead of \`${codeMode}\` for this turn, and briefly mention they can also toggle it via the chip for stickiness. -**Persistent session for this chat — session name: \`${sessionName}\`.** This chat uses one named agent session so the agent keeps context across your requests. The session must be created once before it can be used (\`-s\` only resumes; it does not create). +**Persistent session for this chat — session name: \`${sessionName}\`.** This chat uses one named agent session so the agent keeps context across your requests. The session must exist before it can be prompted (\`-s\` only resumes; it does not create). -**1. First coding action in this chat — create the session:** +**1. First coding action in this chat — ensure the session exists:** \`\`\` -npx acpx@latest --approve-all --cwd sessions new --name ${sessionName} +npx acpx@latest --approve-all --cwd sessions ensure --name ${sessionName} \`\`\` +(\`ensure\` creates the session if missing and reuses it if it already exists — safe to call when reopening this chat later.) + **2. Then run the prompt:** \`\`\` @@ -1351,6 +1353,8 @@ npx acpx@latest --approve-all --cwd -s ${sessionName} " -s ${sessionName} "" \`\`\` +Run these as **separate, sequential** \`executeCommand\` calls — issue the \`sessions ensure\` call first and WAIT for it to finish, then issue the prompt call. Do NOT fire both in the same turn / batch. + Where \`\` is either \`claude\` or \`codex\` — pick based on (in priority order): an explicit in-chat override → the chip setting (\`${codeMode}\`). Use \`${sessionName}\` exactly — do NOT invent a different name, and do NOT use \`exec\` (it is one-shot and forgets). If the user's message is clearly NOT a coding request (small talk, an unrelated question), answer directly without invoking the coding agent. Code mode signals readiness, not that every message must route through the agent.`; diff --git a/apps/x/packages/core/src/application/assistant/skills/code-with-agents/skill.ts b/apps/x/packages/core/src/application/assistant/skills/code-with-agents/skill.ts index c8346298..e98c05e6 100644 --- a/apps/x/packages/core/src/application/assistant/skills/code-with-agents/skill.ts +++ b/apps/x/packages/core/src/application/assistant/skills/code-with-agents/skill.ts @@ -62,14 +62,16 @@ Pick \`\` — **stable for this whole chat**: - If the "# Code Mode (Active)" block gives a session name (e.g. \`rowboat-\`), use that exact name. - Otherwise pick one short, kebab-case name and **reuse it for every coding call this turn and in follow-ups** — never a new name each time. -**\`-s\` resumes an existing session; it does NOT create one.** So create the session once at the start, then prompt: +**\`-s\` resumes an existing session; it does NOT create one.** So ensure the session exists once at the start, then prompt: -**1. First coding action in this chat — create the session:** +**1. First coding action in this chat — ensure the session exists:** \`\`\` -npx acpx@latest --approve-all --cwd sessions new --name +npx acpx@latest --approve-all --cwd sessions ensure --name \`\`\` +(\`ensure\` creates the session if missing and reuses it if it already exists — so reopening this chat later just resumes the same session instead of erroring.) + **2. Then run the prompt:** \`\`\` @@ -82,13 +84,15 @@ npx acpx@latest --approve-all --cwd -s " npx acpx@latest --approve-all --cwd -s "" \`\`\` +**Run steps 1 and 2 as separate, sequential \`executeCommand\` calls.** Issue the \`sessions ensure\` call FIRST, wait for it to finish, and only THEN issue the prompt call. Do NOT fire both in the same turn / batch — each must surface and complete its own permission + command block before the next begins. + Do NOT use \`exec\` — it is one-shot and forgets everything. Concrete example: \`\`\` -# First coding message in the chat — create, then prompt: -npx acpx@latest --approve-all --cwd "G:\\Blogging\\myblog" claude sessions new --name diskspace-check +# First coding message in the chat — ensure the session, then prompt: +npx acpx@latest --approve-all --cwd "G:\\Blogging\\myblog" claude sessions ensure --name diskspace-check npx acpx@latest --approve-all --cwd "G:\\Blogging\\myblog" claude -s diskspace-check "Check the system disk space and report total, used, and free space." # Follow-up in the same chat — reuse the session, no create: @@ -97,7 +101,7 @@ npx acpx@latest --approve-all --cwd "G:\\Blogging\\myblog" claude -s diskspace-c ### Critical: flag order -\`--approve-all\` and \`--cwd\` are GLOBAL flags and MUST appear BEFORE the agent name. \`sessions new --name \` and \`-s \` come AFTER the agent name: +\`--approve-all\` and \`--cwd\` are GLOBAL flags and MUST appear BEFORE the agent name. \`sessions ensure --name \` and \`-s \` come AFTER the agent name: - ✓ Correct: \`npx acpx@latest --approve-all --cwd -s ""\` - ✗ Wrong: \`npx acpx@latest --approve-all -s "..."\` (will fail) @@ -117,7 +121,7 @@ After the command finishes: - Refer to file paths as plain text. Do NOT use \`\`\`file:path\`\`\` reference blocks. (This overrides the global "always wrap paths in filepath blocks" rule — for code-mode output, plain text.) - Only add your own explanation if the command failed (non-zero exit): - Exit code 5 — permissions were denied (shouldn't happen with \`--approve-all\`; flag it). - - Exit code 4 / "No acpx session found" — the \`-s \` session doesn't exist yet. Create it once with \`npx acpx@latest --cwd sessions new --name \`, then retry the prompt. (\`-s\` only resumes; it never creates.) + - Exit code 4 / "No acpx session found" — the \`-s \` session doesn't exist yet. Create it once with \`npx acpx@latest --approve-all --cwd sessions ensure --name \`, then retry the prompt. (\`-s\` only resumes; it never creates.) - "command not found" / agent not installed, or an auth/sign-in error — the agent isn't set up. Tell the user to install or sign in to the agent via **Settings → Code Mode**, where Rowboat shows the install and sign-in status. ---