Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: OpenCode Ollama TUI provider with slashdo-free completion path (#1814)

[._.]/ Adam Eivy416d4cb86de5
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2023ebb789..d30e296a48 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -1,6 +1,7 @@
## Added
- Shell page now has a **Fullscreen** button that promotes the terminal to a full-viewport overlay (above the sidebar), hiding the stacked header/tabs/quick-commands toolbars so the TUI gets the whole screen — a major mobile usability win where those toolbars previously ate most of the display. Fullscreen keeps a compact, horizontally-scrollable control bar (Exit, Ctrl+C, Paste, arrow/Enter keys) so you can still drive a TUI by thumb, and the Ctrl+C/Paste labels now collapse on small screens to save width.
+- OpenCode Ollama **TUI** provider for CoS tasks. The TUI completion workflow is now provider-aware: a slashdo-free TUI (OpenCode, which doesn't load Claude Code `/do:*` slash commands) gets a plain `git` + forge-CLI commit → push → open-PR-for-review → `.agent-done` sentinel handoff instead of `/do:pr` / `/do:push`, so an OpenCode TUI agent can actually complete an automated task. The manual path opens the PR/MR (GitHub `gh` or GitLab `glab`) for review without auto-merging. Ships `opencode-ollama-tui` to existing installs via migration 152. (#1814)
## Fixed
diff --git a/data.reference/providers.json b/data.reference/providers.json
index 4e16786aea..3468cf81f6 100644
--- a/data.reference/providers.json
+++ b/data.reference/providers.json
@@ -173,6 +173,24 @@
"secretEnvVars": [],
"headlessArgs": []
},
+ "opencode-ollama-tui": {
+ "id": "opencode-ollama-tui",
+ "name": "OpenCode Ollama TUI (local model)",
+ "type": "tui",
+ "command": "opencode",
+ "args": [],
+ "models": [],
+ "defaultModel": null,
+ "ollamaBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"ollama\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"Ollama (local)\",\"options\":{\"baseURL\":\"http://localhost:11434/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "tuiPromptDelayMs": 2500,
+ "tuiIdleTimeoutMs": 180000
+ },
"antigravity-tui": {
"id": "antigravity-tui",
"name": "Antigravity TUI",
diff --git a/scripts/migrations/152-opencode-ollama-tui-provider.js b/scripts/migrations/152-opencode-ollama-tui-provider.js
new file mode 100644
index 0000000000..1548c818e0
--- /dev/null
+++ b/scripts/migrations/152-opencode-ollama-tui-provider.js
@@ -0,0 +1,99 @@
+/**
+ * Ship the "OpenCode Ollama TUI" provider to existing installs.
+ *
+ * Background: issue-1814 (follow-up to issue-1802, which shipped only the headless
+ * CLI variant via migration 149). The CLI variant completes through the graceful
+ * CLI light path; the TUI was held back because the CoS TUI-task completion path
+ * assumed slashdo (`/do:pr` / `/do:push`), which OpenCode can't execute. issue-1814
+ * makes `buildTuiCompletionSection` provider-aware (a slashdo-free TUI gets a plain
+ * `git` / `gh` commit→push→PR→sentinel workflow), so the OpenCode TUI can now
+ * complete an automated task — hence shipping the provider here.
+ *
+ * `setup-data.js` merges *missing* provider entries from data.reference, but only
+ * when an install actually re-runs setup. This migration delivers the provider on
+ * a plain server restart too, and is the canonical path for deployed installs to
+ * pick it up. Purely additive: a brand-new id, so there's no rename or pinned-id
+ * rewrite to do. Adds the provider only when missing — idempotent; an existing key
+ * is left untouched.
+ *
+ * Kept in lockstep with data.reference/providers.json and
+ * server/lib/aiToolkit/defaults/providers.sample.json. Frozen here as the
+ * historical record this migration installs; later default changes ride their own
+ * migrations rather than mutating this one.
+ */
+
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
+
+const PROVIDERS_REL_PATH = 'data/providers.json';
+
+// Inline OpenCode config: declare the local Ollama daemon as an openai-compatible
+// provider and auto-approve tools (the OpenCode equivalent of claude's
+// --dangerously-skip-permissions — appropriate for PortOS's single-user trusted
+// box). Identical to the CLI variant's config (migration 149) — the TUI and CLI
+// providers point at the same daemon. OPENCODE_CONFIG_CONTENT has the highest
+// config precedence in OpenCode.
+const OPENCODE_CONFIG_CONTENT = '{"permission":"allow","provider":{"ollama":{"npm":"@ai-sdk/openai-compatible","name":"Ollama (local)","options":{"baseURL":"http://localhost:11434/v1"}}}}';
+
+const OPENCODE_OLLAMA_TUI = {
+ id: 'opencode-ollama-tui',
+ name: 'OpenCode Ollama TUI (local model)',
+ type: 'tui',
+ command: 'opencode',
+ // The TUI spawner appends `--model ollama/<id>`; no `run` subcommand and no
+ // permission flag (OPENCODE_CONFIG_CONTENT already sets permission:"allow").
+ args: [],
+ models: [],
+ defaultModel: null,
+ ollamaBacked: true,
+ timeout: 600000,
+ enabled: false,
+ envVars: { OPENCODE_CONFIG_CONTENT },
+ secretEnvVars: [],
+ tuiPromptDelayMs: 2500,
+ tuiIdleTimeoutMs: 180000,
+};
+
+export default {
+ async up({ rootDir }) {
+ const providersPath = join(rootDir, PROVIDERS_REL_PATH);
+ const raw = await readFile(providersPath, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) {
+ console.log(`📄 ${PROVIDERS_REL_PATH} not present — skipping (fresh install seeds OpenCode Ollama TUI from data.reference)`);
+ return;
+ }
+
+ let config;
+ try {
+ config = JSON.parse(raw);
+ } catch (err) {
+ console.log(`⚠️ ${PROVIDERS_REL_PATH}: invalid JSON, skipping (${err.message})`);
+ return;
+ }
+
+ if (!config || typeof config !== 'object' || !config.providers || typeof config.providers !== 'object') {
+ console.log(`⚠️ ${PROVIDERS_REL_PATH}: unexpected shape, skipping`);
+ return;
+ }
+
+ const providers = config.providers;
+ let changed = false;
+
+ for (const def of [OPENCODE_OLLAMA_TUI]) {
+ if (!providers[def.id]) {
+ providers[def.id] = { ...def, envVars: { ...def.envVars } };
+ changed = true;
+ console.log(`📝 ${PROVIDERS_REL_PATH}: added ${def.id} provider`);
+ }
+ }
+
+ if (changed) {
+ await writeFile(providersPath, `${JSON.stringify(config, null, 2)}\n`);
+ } else {
+ console.log(`✅ ${PROVIDERS_REL_PATH}: OpenCode Ollama TUI provider already present — no change`);
+ }
+ },
+};
diff --git a/scripts/migrations/152-opencode-ollama-tui-provider.test.js b/scripts/migrations/152-opencode-ollama-tui-provider.test.js
new file mode 100644
index 0000000000..b79b28fc9b
--- /dev/null
+++ b/scripts/migrations/152-opencode-ollama-tui-provider.test.js
@@ -0,0 +1,110 @@
+/**
+ * Test for migration 152 — add the OpenCode Ollama TUI provider to existing
+ * installs. Picked up by server/vitest.config.js's `../scripts/**\/*.test.js`
+ * glob.
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './152-opencode-ollama-tui-provider.js';
+
+const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+describe('migration 152 — OpenCode Ollama TUI provider', () => {
+ let rootDir;
+ let providersPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-152-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ providersPath = join(rootDir, 'data/providers.json');
+ });
+
+ afterEach(() => {
+ rmSync(rootDir, { recursive: true, force: true });
+ });
+
+ it('adds the OpenCode Ollama TUI provider to an existing install', async () => {
+ writeJson(providersPath, {
+ activeProvider: 'claude-code',
+ providers: {
+ 'claude-code': { id: 'claude-code', type: 'cli', command: 'claude' },
+ 'opencode-ollama': { id: 'opencode-ollama', type: 'cli', command: 'opencode' },
+ },
+ });
+
+ await migration.up({ rootDir });
+
+ const out = readJson(providersPath);
+ const tui = out.providers['opencode-ollama-tui'];
+ expect(tui.type).toBe('tui');
+ expect(tui.command).toBe('opencode');
+ expect(tui.args).toEqual([]);
+ expect(tui.ollamaBacked).toBe(true);
+ expect(tui.enabled).toBe(false);
+ expect(tui.tuiPromptDelayMs).toBe(2500);
+ expect(tui.tuiIdleTimeoutMs).toBe(180000);
+ // unrelated providers + active provider untouched
+ expect(out.providers['claude-code']).toBeDefined();
+ expect(out.providers['opencode-ollama']).toBeDefined();
+ expect(out.activeProvider).toBe('claude-code');
+ });
+
+ it('declares a valid inline OpenCode config pointing at the local Ollama daemon', async () => {
+ writeJson(providersPath, { providers: {} });
+
+ await migration.up({ rootDir });
+
+ const out = readJson(providersPath);
+ const cfg = JSON.parse(out.providers['opencode-ollama-tui'].envVars.OPENCODE_CONFIG_CONTENT);
+ expect(cfg.permission).toBe('allow');
+ expect(cfg.provider.ollama.npm).toBe('@ai-sdk/openai-compatible');
+ expect(cfg.provider.ollama.options.baseURL).toBe('http://localhost:11434/v1');
+ });
+
+ it('does not overwrite a user-customized opencode-ollama-tui entry', async () => {
+ writeJson(providersPath, {
+ providers: {
+ 'opencode-ollama-tui': {
+ id: 'opencode-ollama-tui', type: 'tui', command: 'opencode',
+ enabled: true, models: ['qwen2.5-coder:32b'], defaultModel: 'qwen2.5-coder:32b',
+ },
+ },
+ });
+
+ await migration.up({ rootDir });
+
+ const out = readJson(providersPath);
+ // existing TUI entry preserved untouched
+ expect(out.providers['opencode-ollama-tui'].enabled).toBe(true);
+ expect(out.providers['opencode-ollama-tui'].models).toEqual(['qwen2.5-coder:32b']);
+ });
+
+ it('is idempotent — a second run makes no changes', async () => {
+ writeJson(providersPath, {
+ providers: { 'claude-code': { id: 'claude-code', type: 'cli', command: 'claude' } },
+ });
+
+ await migration.up({ rootDir });
+ const afterFirst = readFileSync(providersPath, 'utf-8');
+ await migration.up({ rootDir });
+ expect(readFileSync(providersPath, 'utf-8')).toBe(afterFirst);
+ });
+
+ it('is a no-op when data/providers.json does not exist (fresh install)', async () => {
+ await migration.up({ rootDir });
+ expect(existsSync(providersPath)).toBe(false);
+ });
+
+ it('does not modify the file on invalid JSON', async () => {
+ writeFileSync(providersPath, '{ not valid json');
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+});
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index ce619a5854..e5b9ec857f 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -94,6 +94,24 @@
"secretEnvVars": [],
"headlessArgs": []
},
+ "opencode-ollama-tui": {
+ "id": "opencode-ollama-tui",
+ "name": "OpenCode Ollama TUI (local model)",
+ "type": "tui",
+ "command": "opencode",
+ "args": [],
+ "models": [],
+ "defaultModel": null,
+ "ollamaBacked": true,
+ "timeout": 600000,
+ "enabled": false,
+ "envVars": {
+ "OPENCODE_CONFIG_CONTENT": "{\"permission\":\"allow\",\"provider\":{\"ollama\":{\"npm\":\"@ai-sdk/openai-compatible\",\"name\":\"Ollama (local)\",\"options\":{\"baseURL\":\"http://localhost:11434/v1\"}}}}"
+ },
+ "secretEnvVars": [],
+ "tuiPromptDelayMs": 2500,
+ "tuiIdleTimeoutMs": 180000
+ },
"codex": {
"id": "codex",
"name": "Codex CLI",
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index a1033a463b..8904a0f7a1 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -323,7 +323,8 @@ export async function spawnAgentForTask(task) {
// inside buildAgentPrompt — see its doc comment.
const prompt = await buildAgentPrompt(task, config, workspacePath, worktreeInfo, isTruthyMeta, {
providerType: provider.type,
- providerId: provider.id
+ providerId: provider.id,
+ providerCommand: provider.command
});
// Create agent directory
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index c48cdc15ca..47c5764a95 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -18,6 +18,7 @@ import { runPromptThroughProvider } from '../lib/promptRunner.js';
import { readJSONFile, loadSlashdoFile, PATHS, tryReadFile } from '../lib/fileUtils.js';
import { DEFAULT_REVIEWER, DEFAULT_REVIEWERS, DEFAULT_REVIEW_STOP_MODE, LOCAL_LLM_REVIEWERS, normalizeReviewers, buildReviewWithArgs } from '../lib/validation.js';
import { PROVIDER_TYPES } from '../lib/aiToolkit/constants.js';
+import { isOpencodeCommand } from '../lib/providerModels.js';
import * as jiraService from './jira.js';
import { emitLog } from './cosEvents.js';
@@ -364,20 +365,25 @@ ${rprBody ? `\n### /do:rpr Reference (full procedure)\n\nWhen following the proc
* @param {boolean} opts.isReadOnly
* @param {boolean} opts.isTui
* @param {string} opts.tuiCompletionCommand - `/do:pr` or `/do:push`
+ * @param {boolean} [opts.slashdoFree] - TUI without slashdo (OpenCode): the bullet
+ * points at the manual git/gh Completion Workflow instead of a `/do:*` command.
* @param {Object|null} opts.worktreeInfo
* @param {boolean} opts.willOpenPR
* @param {boolean} opts.willReviewLoop
* @returns {string|null}
*/
export function buildCompletionGuidelineBullet({
- isReadOnly, isTui, tuiCompletionCommand,
+ isReadOnly, isTui, tuiCompletionCommand, slashdoFree = false,
worktreeInfo, willOpenPR, willReviewLoop,
}) {
if (isReadOnly) {
return '**This is a read-only task.** Do NOT commit, push, or modify any files in the repository. Only read data and generate reports.';
}
if (isTui) {
- return `On successful completion, YOU run the Completion Workflow above (\`${tuiCompletionCommand}\`, then write the sentinel and stop — PortOS closes the session once it sees the sentinel; do NOT run \`/quit\`).`;
+ const howTo = slashdoFree
+ ? 'the Completion Workflow above (plain `git`/`gh` commands — this provider has no slashdo commands)'
+ : `the Completion Workflow above (\`${tuiCompletionCommand}\`)`;
+ return `On successful completion, YOU run ${howTo}, then write the sentinel and stop — PortOS closes the session once it sees the sentinel; do NOT run \`/quit\`.`;
}
if (worktreeInfo && willOpenPR) {
const reviewSuffix = willReviewLoop
@@ -417,14 +423,18 @@ export function buildCompletionGuidelineBullet({
* light prompt instructs the agent to run `/simplify` and `/do:pr` itself
* instead of relying on PortOS's post-exit push+PR. The spawner must then
* pass `openPR: false` to `cleanupAgentWorktree` to avoid double-firing.
+ * @param {string} [options.providerCommand] - Provider launch command (e.g. `'opencode'`).
+ * Used to detect a slashdo-free TUI (OpenCode): such a TUI can't run `/do:pr` / `/do:push`,
+ * so its completion workflow falls back to plain `git`/`gh` commands.
*/
export async function buildAgentPrompt(task, config, workspaceDir, worktreeInfo = null, isTruthyMetaFn = (v) => v === true || v === 'true', options = {}) {
const providerType = options.providerType || PROVIDER_TYPES.API;
const providerId = options.providerId || null;
+ const providerCommand = options.providerCommand || null;
const isTui = providerType === PROVIDER_TYPES.TUI;
if (LIGHT_CONTEXT_PROVIDER_TYPES.has(providerType)) {
- return buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui, providerId });
+ return buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui, providerId, providerCommand });
}
// Full path: API providers don't read CLAUDE.md natively, so always include it.
@@ -665,7 +675,8 @@ ${skillSection ? `## Task-Type Skill Guidelines\n\n${skillSection}\n` : ''}${too
${(() => {
const bullet = buildCompletionGuidelineBullet({
isReadOnly: isTruthyMetaFn(task.metadata?.readOnly),
- isTui, tuiCompletionCommand, worktreeInfo, willOpenPR, willReviewLoop,
+ isTui, tuiCompletionCommand, slashdoFree: isTui && isOpencodeCommand(providerCommand),
+ worktreeInfo, willOpenPR, willReviewLoop,
});
return bullet ? `- ${bullet}` : '';
})()}
@@ -704,7 +715,7 @@ Begin working on the task now.`;
* Falls back gracefully when worktree/jira/pipeline metadata is absent — only
* the present sections render.
*/
-export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui = true, providerId = null } = {}) {
+export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTruthyMetaFn, { isTui = true, providerId = null, providerCommand = null } = {}) {
const willOpenPR = isTruthyMetaFn(task.metadata?.openPR);
const willReviewLoop = isTruthyMetaFn(task.metadata?.reviewLoop);
const simplifyEnabled = isTruthyMetaFn(task.metadata?.simplify);
@@ -721,6 +732,11 @@ export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTrut
// Other CLI providers (codex, antigravity) can't — they get the legacy
// commit-only block where PortOS handles push+PR on exit.
const hasSlashdo = !isTui && (providerId === 'claude-code' || providerId === 'claude-code-bedrock');
+ // A TUI that does NOT load Claude Code slash commands (OpenCode) can't run
+ // `/do:pr` / `/do:push`, so its completion workflow uses plain git/gh instead.
+ // Keyed on the launch command (not the id) so a path-configured or renamed
+ // OpenCode provider is still recognised — mirrors the arg-builder gate.
+ const tuiSlashdoFree = isTui && isOpencodeCommand(providerCommand);
const sections = [];
@@ -785,7 +801,9 @@ export function buildLightContextPrompt(task, workspaceDir, worktreeInfo, isTrut
sections.push(buildReviewLoopFollowUpSection(task.metadata || {}, { verbose: false }));
} else if (isTui) {
sections.push(buildTuiCompletionSection({
- willOpenPR, willReviewLoop, simplifyEnabled, providerId, sentinelPath: `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`,
+ willOpenPR, willReviewLoop, simplifyEnabled, providerId, slashdoFree: tuiSlashdoFree,
+ sentinelPath: `${worktreeInfo?.worktreePath || workspaceDir}/.agent-done`,
+ branchName: worktreeInfo?.branchName || null,
reviewers: lightReviewers, reviewStopMode: lightReviewStopMode, reviewerApplies: lightReviewerApplies
}));
} else {
@@ -857,8 +875,15 @@ function buildPostPRMergeSteps(startStep, { reviewers = DEFAULT_REVIEWERS, revie
/**
* TUI completion-workflow block. The TUI owns its own commit → push → PR
* pipeline via slashdo commands and signals "done" with a sentinel file.
+ *
+ * When `slashdoFree` is set (an OpenCode TUI, which does not load Claude Code
+ * slash commands), the agent can't run `/do:pr` / `/do:push`, so it delegates to
+ * the plain-git/`gh` variant below — same sentinel handshake, no slashdo.
*/
-function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabled, sentinelPath, providerId = null, reviewers = DEFAULT_REVIEWERS, reviewStopMode = DEFAULT_REVIEW_STOP_MODE, reviewerApplies = false }) {
+function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabled, sentinelPath, providerId = null, slashdoFree = false, branchName = null, reviewers = DEFAULT_REVIEWERS, reviewStopMode = DEFAULT_REVIEW_STOP_MODE, reviewerApplies = false }) {
+ if (slashdoFree) {
+ return buildManualTuiCompletionSection({ willOpenPR, simplifyEnabled, sentinelPath, branchName });
+ }
const cmd = willOpenPR ? '/do:pr' : '/do:push';
const reviewArgs = willOpenPR && willReviewLoop ? buildReviewWithArgs(reviewers, reviewStopMode, reviewerApplies) : '';
const reviewerArg = reviewArgs ? ` ${reviewArgs}` : '';
@@ -902,6 +927,81 @@ function buildTuiCompletionSection({ willOpenPR, willReviewLoop, simplifyEnabled
].join('\n');
}
+/**
+ * Manual (slashdo-free) TUI completion-workflow block — for an OpenCode TUI that
+ * does NOT load Claude Code slash commands and so can't run `/do:pr` / `/do:push`.
+ * Drives the same commit → push → (PR) → sentinel handshake with plain `git` / `gh`
+ * commands, so the `.agent-done` signal still fires and the task completes.
+ *
+ * PortOS forces `openPR:false, skipMerge:true` on TUI worktree cleanup (see
+ * agentTuiSpawning.js), so nothing happens after the agent exits — the agent owns
+ * the push, and the PR + merge when one is requested, itself.
+ *
+ * No automated review loop is emitted: OpenCode can't invoke the CLI reviewers, so
+ * (unlike `buildPostPRMergeSteps`) the merge step is unconditional rather than gated
+ * on a review-loop verdict.
+ */
+function buildManualTuiCompletionSection({ willOpenPR, simplifyEnabled, sentinelPath, branchName = null }) {
+ const branchRef = branchName || 'HEAD';
+ const simplifyStep = simplifyEnabled
+ ? `1. Before committing, ${SIMPLIFY_INLINE_REVIEW} and fix any findings.`
+ : '1. (simplify disabled — skip)';
+ const sentinelTail = willOpenPR ? ' ## PR\n <PR URL>' : ' ## Branch\n <branch name>';
+
+ const lines = [
+ '## Completion Workflow',
+ 'This provider does NOT have slashdo (`/do:*`) commands, so finish the handoff with plain `git` / `gh`. Run these in order:',
+ '',
+ simplifyStep,
+ '2. Stage only the files you changed (never `git add -A` / `git add .`) and commit with a conventional message (`feat:`/`fix:`/`breaking:` prefix, no Co-Authored-By annotations):',
+ '',
+ ' ```bash',
+ ' git add <file> [<file> ...]',
+ ' git commit -m "feat: <description>"',
+ ' ```',
+ '3. Push your branch (it is a fresh worktree branch, so set upstream on first push):',
+ '',
+ ' ```bash',
+ ` git push -u origin ${branchRef}`,
+ ' ```',
+ ];
+
+ let step = 4;
+ if (willOpenPR) {
+ lines.push(
+ `${step++}. Open a pull request against the default branch and capture the PR URL it prints:`,
+ '',
+ ' ```bash',
+ ' gh pr create --fill',
+ ' ```',
+ `${step++}. Merge the PR and delete the branch:`,
+ '',
+ ' ```bash',
+ ' gh pr merge "<PR_URL>" --merge --delete-branch',
+ ' ```',
+ `${step++}. Confirm the merge before exiting: \`gh pr view "<PR_URL>" --json state -q .state\` must return \`MERGED\`. If it returns \`OPEN\` or \`CLOSED\`, investigate (failing check, branch protection), fix, and retry.`,
+ );
+ }
+
+ lines.push(
+ `${step}. Write a short markdown summary (~5–15 lines) to the completion sentinel, then stop — this sentinel is the done signal. PortOS polls it every 2s, finalizes the run, and closes the session for you. Do NOT run \`/quit\` (it's a UI command, not something you can invoke) and do NOT wait for anything after writing the sentinel.`,
+ '',
+ ' ```bash',
+ ` cat > "${sentinelPath}" <<'EOF'`,
+ ' ## Summary',
+ ' <one-sentence statement of what was accomplished>',
+ '',
+ ' ## Changes',
+ ' - <key file or area>: <what changed and why>',
+ '',
+ sentinelTail,
+ ' EOF',
+ ' ```',
+ );
+
+ return lines.join('\n');
+}
+
/**
* CLI (non-TUI) completion block.
*
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index 04e5149021..933d9cbb2d 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -209,6 +209,64 @@ describe('buildLightContextPrompt', () => {
expect(prompt).not.toMatch(/gh pr merge/);
});
+ it('emits a slashdo-free git/gh Completion Workflow for an OpenCode TUI + openPR', () => {
+ // OpenCode TUI doesn't load Claude Code slash commands, so /do:pr / /do:push
+ // would be uninvokable. The agent must commit, push, open + merge the PR, and
+ // write the sentinel with plain git/gh — PortOS does NOT push or merge post-exit.
+ const prompt = buildLightContextPrompt(
+ makeTask({ metadata: { simplify: true, openPR: true } }),
+ '/r',
+ { branchName: 'claim/issue-1', worktreePath: '/tmp/wt' },
+ isTruthyMeta,
+ { isTui: true, providerId: 'opencode-ollama-tui', providerCommand: 'opencode' });
+ expect(prompt).toMatch(/## Completion Workflow/);
+ // No slashdo commands anywhere in the workflow.
+ expect(prompt).not.toMatch(/`\/do:pr`/);
+ expect(prompt).not.toMatch(/`\/do:push`/);
+ expect(prompt).not.toMatch(/`\/simplify`/);
+ // /simplify is a Claude built-in — OpenCode gets the inline equivalent.
+ expect(prompt).toMatch(/review your changed code for reuse, quality, and efficiency/i);
+ // Plain git/gh commit → push → PR → merge → verify.
+ expect(prompt).toMatch(/git commit -m/);
+ expect(prompt).toMatch(/git push -u origin claim\/issue-1/);
+ expect(prompt).toMatch(/gh pr create --fill/);
+ expect(prompt).toMatch(/gh pr merge "<PR_URL>" --merge --delete-branch/);
+ expect(prompt).toMatch(/gh pr view "<PR_URL>" --json state -q \.state/);
+ expect(prompt).toMatch(/MERGED/);
+ // Sentinel handshake still drives completion; never tell the agent to run /quit.
+ expect(prompt).toMatch(/\.agent-done/);
+ expect(prompt).toMatch(/NOT run `\/quit`/);
+ expect(prompt).not.toMatch(/^\s*\d+\.\s*`\/quit`/m);
+ });
+
+ it('OpenCode TUI without openPR pushes the branch but opens no PR', () => {
+ const prompt = buildLightContextPrompt(
+ makeTask({ metadata: { openPR: false } }),
+ '/r',
+ { branchName: 'claim/issue-2', worktreePath: '/tmp/wt' },
+ isTruthyMeta,
+ { isTui: true, providerId: 'opencode-ollama-tui', providerCommand: 'opencode' });
+ expect(prompt).toMatch(/## Completion Workflow/);
+ expect(prompt).not.toMatch(/`\/do:push`/);
+ expect(prompt).toMatch(/git push -u origin claim\/issue-2/);
+ // No PR is opened, so no gh pr create / merge steps.
+ expect(prompt).not.toMatch(/gh pr create/);
+ expect(prompt).not.toMatch(/gh pr merge/);
+ expect(prompt).toMatch(/\.agent-done/);
+ });
+
+ it('a non-OpenCode TUI (claude-code-tui) keeps the slashdo /do:pr workflow', () => {
+ // providerCommand is the gate — a claude TUI must NOT fall into the manual path.
+ const prompt = buildLightContextPrompt(
+ makeTask({ metadata: { openPR: true } }),
+ '/r',
+ { branchName: 'b', worktreePath: '/tmp/wt' },
+ isTruthyMeta,
+ { isTui: true, providerId: 'claude-code-tui', providerCommand: 'claude' });
+ expect(prompt).toMatch(/`\/do:pr`/);
+ expect(prompt).not.toMatch(/gh pr create/);
+ });
+
it('emits a non-TUI "Completion" block (no slashdo) for non-Claude CLI agents', () => {
const prompt = buildLightContextPrompt(
makeTask({ metadata: { openPR: true } }),