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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: extend system/user prompt split to all Claude Code agents
Adam Eivyeb26f98aedb8
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 18b582c334..9d051fe620 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,8 @@## CoS Agents-- **Local-model Claude agents now launch in a lean, isolated mode.** CoS agents on the Ollama-backed Claude providers (`claude-ollama`, `claude-ollama-tui`) previously inherited your full personal Claude Code environment — hooks, plugins, MCP servers, global CLAUDE.md — which reliably derailed small local models (a live eval showed qwen3.6:35b answering a session-start hook instead of its task). These sessions now spawn with `--bare --strict-mcp-config` (no hooks, no plugins, no MCP tool schemas, no CLAUDE.md auto-discovery), authenticating through the provider's existing `ANTHROPIC_BASE_URL` + `ANTHROPIC_AUTH_TOKEN` (pointed at your local Ollama), and get the same plain-`git`/`gh` completion workflow OpenCode agents use instead of slashdo commands bare mode can't load. The PortOS operating contract (worktree coordinates, completion sentinel protocol) also moves out of the pasted prompt into a real system prompt via `--append-system-prompt-file` — saved beside the agent's `prompt.txt` as `system-prompt.md` — so weak models weight it as instructions rather than conversation. Standard Claude/Codex/OpenCode providers are unchanged.+- **Local-model Claude agents now launch in a lean, isolated mode.** CoS agents on the Ollama-backed Claude providers (`claude-ollama`, `claude-ollama-tui`) previously inherited your full personal Claude Code environment — hooks, plugins, MCP servers, global CLAUDE.md — which reliably derailed small local models (a live eval showed qwen3.6:35b answering a session-start hook instead of its task). These sessions now spawn with `--bare --strict-mcp-config` (no hooks, no plugins, no MCP tool schemas, no CLAUDE.md auto-discovery), authenticating through the provider's existing `ANTHROPIC_BASE_URL` + `ANTHROPIC_AUTH_TOKEN` (pointed at your local Ollama), and get the same plain-`git`/`gh` completion workflow OpenCode agents use instead of slashdo commands bare mode can't load. In the same eval, once isolated this way qwen3.6:35b wrote a correct, test-passing helper (verified 46/46) end to end — the failures were the environment, not the model.+- **Every Claude Code agent now separates its task from the PortOS operating contract.** For all Claude providers (TUI and headless CLI, local and hosted), the PortOS coordination boilerplate — worktree branch, completion-sentinel protocol, git/PR workflow — now rides in a real system prompt via `--append-system-prompt-file` (saved beside the agent's `prompt.txt` as `system-prompt.md`), while the pasted/stdin prompt carries only the task. The model weights the contract as standing instructions rather than conversation, and hosted providers get better prompt-cache reuse on the stable system block. The prompt content is byte-identical to before — only its placement changed. Codex, Antigravity, and OpenCode agents (no equivalent flag) keep the combined prompt unchanged.## Creative Writing Quality Enginediff --git a/server/services/agentCliSpawning.test.js b/server/services/agentCliSpawning.test.jsindex 9400e38117..6bda283ce6 100644--- a/server/services/agentCliSpawning.test.js+++ b/server/services/agentCliSpawning.test.js@@ -238,6 +238,18 @@ describe('buildCliSpawnConfig', () => {expect(config.args).not.toContain('--append-system-prompt-file');});+ it('adds the system-prompt file to a STANDARD claude CLI WITHOUT lean flags', () => {+ const config = buildCliSpawnConfig(+ { id: 'claude-code', command: 'claude' },+ 'claude-opus-4-8',+ {},+ { systemPromptFile: '/data/cos/agents/agent-2/system-prompt.md' },+ );+ expect(config.args).not.toContain('--bare');+ const idx = config.args.indexOf('--append-system-prompt-file');+ expect(config.args[idx + 1]).toBe('/data/cos/agents/agent-2/system-prompt.md');+ });+describe('Bedrock model-id mapping', () => {// buildCliSpawnConfig reads process.env for the Bedrock signal; isolate the// tests from whatever the host/CI environment happens to set.diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 9aa70df66b..79c28f8eaa 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -23,6 +23,7 @@ import { analyzeAgentFailure, resolveFailedTaskUpdate } from './agentErrorAnalysimport { createAgentRun, completeAgentRun, checkForTaskCommit } from './agentRunTracking.js';import { buildAgentPrompt, getAppWorkspace } from './agentPromptBuilder.js';import { isOllamaClaudeProvider, isClaudeCommand } from '../lib/providerModels.js';+import { PROVIDER_TYPES } from '../lib/aiToolkit/constants.js';import { buildCliSpawnConfig, isClaudeCliProvider, isTuiProvider, getClaudeSettingsEnv, spawnDirectly } from './agentCliSpawning.js';import { extractCodexAssistantTail } from '../lib/codexAssistantExtract.js';import { buildTuiSpawnConfig, spawnTuiAgent } from './agentTuiSpawning.js';@@ -335,13 +336,21 @@ export async function spawnAgentForTask(task) {// Lean mode: an Ollama-backed Claude session gets `--bare --strict-mcp-config`// (see applyLeanClaudeArgs) so the user's personal environment — hooks,// plugins, MCP servers, global CLAUDE.md — doesn't drown the small local- // model. Lean sessions also split the prompt: the PortOS operating contract- // rides in a system-prompt file (`--append-system-prompt-file`) while the- // pasted/stdin prompt carries only the task itself. Split stays gated on- // lean mode until `--append-system-prompt-file` is validated on the- // standard interactive claude providers.+ // model. This is orthogonal to the prompt split below.const leanMode = isOllamaClaudeProvider(provider);- const splitSystemPrompt = leanMode && isClaudeCommand(provider.command);++ // System/user prompt split: for ANY Claude Code session (TUI or headless+ // CLI), the PortOS operating contract rides in a real system prompt via+ // `--append-system-prompt-file` while the pasted/stdin prompt carries only+ // the task — so the model weights the contract as instructions, not+ // conversation (and hosted providers get better prompt-cache reuse on the+ // stable system block). Gated on a light-context Claude command: non-Claude+ // providers (codex, antigravity, opencode) have no equivalent flag and keep+ // the combined prompt; API providers never take the light path so the split+ // is a no-op for them. `--append-system-prompt-file` validated on claude CLI+ // v2.1.201 in both `--print` and stream-json arg shapes.+ const isLightContext = isTui || provider.type === PROVIDER_TYPES.CLI;+ const splitSystemPrompt = isLightContext && isClaudeCommand(provider.command);// Build the agent prompt. `provider.type` drives the light-vs-full split// inside buildAgentPrompt — see its doc comment.diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.jsindex 228acb9a44..ba8ea082ad 100644--- a/server/services/agentPromptBuilder.test.js+++ b/server/services/agentPromptBuilder.test.js@@ -602,7 +602,7 @@ describe('buildAgentPrompt — provider type routing', () => {expect(prompt).toMatch(/^## Completion$/m);});- describe('split system/user prompt (lean Ollama claude)', () => {+ describe('split system/user prompt (Claude providers)', () => {const wt = { branchName: 'cos/t/a', worktreePath: '/tmp/wt', baseBranch: 'main' };const splitTask = () => makeTask({ metadata: { context: 'Some context', openPR: false } });@@ -648,6 +648,28 @@ describe('buildAgentPrompt — provider type routing', () => {{ providerType: 'tui', providerId: 'claude-code-tui', providerCommand: 'claude' });expect(prompt).toMatch(/\/do:push/);});++ it('splits a STANDARD (non-lean) claude TUI too, keeping slashdo in the system prompt', async () => {+ const parts = await buildAgentPrompt(+ splitTask(), {}, '/r', wt, isTruthyMeta,+ { providerType: 'tui', providerId: 'claude-code-tui', providerCommand: 'claude', split: true });+ // Task in the user prompt, contract (with slashdo — NOT slashdo-free) in system.+ expect(parts.userPrompt).toMatch(/Add a button to the dashboard/);+ expect(parts.userPrompt).not.toMatch(/## Completion Workflow/);+ expect(parts.systemPrompt).toMatch(/## Completion Workflow/);+ expect(parts.systemPrompt).toMatch(/\/do:push/);+ });++ it('split parts carry exactly the combined prompt for a standard claude CLI (no drift)', async () => {+ const opts = { providerType: 'cli', providerId: 'claude-code', providerCommand: 'claude' };+ const combined = await buildAgentPrompt(splitTask(), {}, '/r', wt, isTruthyMeta, opts);+ const parts = await buildAgentPrompt(splitTask(), {}, '/r', wt, isTruthyMeta, { ...opts, split: true });+ const reassembled = parts.userPrompt.replace(+ /\n\nBegin working on the task now\.\n$/,+ '\n\n' + parts.systemPrompt.replace(/\n$/, '') + '\n\nBegin working on the task now.\n'+ );+ expect(reassembled).toBe(combined);+ });});it('full-context (api) review-loop follow-up emits merge command WITHOUT --auto and includes MERGED verification', async () => {