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

fix: give pipeline stages their own prompt, and tell the tool-free gate its reply is the deliverable

[._.]/ Adam Eivy91947610146b
diff --git a/server/services/agentCompletionCleanup.js b/server/services/agentCompletionCleanup.js
index 1e3d7278d2..6cec40ba8c 100644
--- a/server/services/agentCompletionCleanup.js
+++ b/server/services/agentCompletionCleanup.js
@@ -149,6 +149,11 @@ export async function handlePipelineProgression(task, agentId, success) {
if (publicReviewPostureForProfile(nextStage.executionProfile)) {
for (const key of ['provider', 'providerId', 'model', 'effort']) delete nextTask.metadata[key];
}
+ // The previous stage's agent payload must not travel: `description` above IS
+ // this stage's prompt, and addTask only promotes it to `metadata.prompt` when
+ // none is set — an inherited one made every stage after the first run on the
+ // stage before it's instructions.
+ delete nextTask.metadata.prompt;
if (nextStage.model) nextTask.metadata.model = nextStage.model;
if (nextStage.providerId) {
nextTask.metadata.provider = nextStage.providerId;
diff --git a/server/services/agentCompletionCleanup.test.js b/server/services/agentCompletionCleanup.test.js
index c4a548ce88..c959cc0943 100644
--- a/server/services/agentCompletionCleanup.test.js
+++ b/server/services/agentCompletionCleanup.test.js
@@ -90,6 +90,17 @@ describe('handlePipelineProgression', () => {
expect(nextTask.metadata.effort).toBe('xhigh');
});
+ it('does not carry the previous stage prompt into the next stage task', async () => {
+ // addTask promotes a multi-line description to metadata.prompt only when
+ // none is set, so an inherited prompt made stage 1+ run on stage 0's text.
+ const task = { id: 't', taskType: 'user', metadata: { prompt: 'stage-0 instructions\nmore', context: 'note', pipeline: runningPipeline() } };
+ await handlePipelineProgression(task, 'agent-1', true);
+ const [nextTask] = addTask.mock.calls[0];
+ expect(nextTask.metadata).not.toHaveProperty('prompt');
+ expect(nextTask.metadata.context).toBe('note');
+ expect(nextTask.description).toBe('do stage work in {appName}');
+ });
+
it('leaves effort unset when the next stage has no effort pin', async () => {
const task = { id: 't', taskType: 'user', metadata: { pipeline: runningPipeline() } };
await handlePipelineProgression(task, 'agent-1', true);
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index ad7091102e..edc23c8114 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -28,6 +28,7 @@ import { buildCompactionSection, buildTaskBlock, reconcileSplitContext } from '.
import { applySlashdoInvocation } from './promptSections/slashdo.js';
import { manualForgeCli, resolveManualForgeCli } from './promptSections/forge.js';
import { buildPlannerAttributionSection } from './promptSections/plannerAttribution.js';
+import { isPublicReviewNoToolProfile } from '../lib/agentExecutionProfiles.js';
import {
DISCARD_WORKTREE_NOTE,
buildActionOutputCompletionSection,
@@ -38,6 +39,7 @@ import {
NO_CHANGE_AUDIT_GUIDANCE,
buildProgrammaticOutputCompletionSection,
buildReadOnlyCompletionSection,
+ buildToolFreeReasoningCompletionSection,
buildResumeSection,
buildSentinelWriteSteps,
buildTuiCompletionSection,
@@ -409,6 +411,9 @@ export async function buildAgentPrompt(task, config, workspaceDir, worktreeInfo
// `pending` BEFORE this flag existed (persisted across an upgrade) are still
// recognized without a metadata migration.
const noCodeOutput = isTruthyMetaFn(task.metadata?.noCodeOutput) || isCreativeDirectorTask;
+ // A tool-free public-review stage has no sentinel, API, or command to reach
+ // for: its reply IS the deliverable. Wins over every other completion contract.
+ const toolFreeReasoning = isPublicReviewNoToolProfile(task.metadata?.executionProfile);
const noChangeSuccess = isTruthyMetaFn(task.metadata?.noChangeSuccess);
const isWorktreeOnExistingBranch = isPrBranchWorktree(task, worktreeInfo);
const worktreeCommitNote = worktreeInfo
@@ -511,7 +516,9 @@ After completing your work and before committing, ${simplifyInstruction}. Fix an
// worktree disposal (`discardWorktree`) pick the reasoning-payload contract.
// A task doing external work during the run must not be told the sentinel is
// its output channel.
- const tuiCompletionSection = noCodeOutput
+ const tuiCompletionSection = toolFreeReasoning
+ ? buildToolFreeReasoningCompletionSection()
+ : noCodeOutput
? buildActionOutputCompletionSection({ isTui, sentinelPath })
: discardWorktree
? buildProgrammaticOutputCompletionSection(sentinelPath)
@@ -738,7 +745,7 @@ ${(() => {
isTui, tuiCompletionCommand, slashdoFree: isTui && !canRunSlashCommands,
worktreeInfo, willOpenPR, prCompletion, discardWorktree, noCodeOutput, noChangeSuccess,
leavePrOpen: leavesPrForHuman(task),
- isPrFollowUp: isReviewLoopFollowUp, claimFlow,
+ isPrFollowUp: isReviewLoopFollowUp, claimFlow, toolFreeReasoning,
});
return bullet ? `- ${bullet}` : '';
})()}
@@ -748,7 +755,9 @@ ${(() => {
- **NEVER use \`git stash\`** in any form (\`git stash push\`, \`git stash pop\`, etc.). This is a multi-agent system — stashing can silently destroy or corrupt another agent's or the user's in-progress work. Work around uncommitted changes instead. (Note: the backend may use \`--autostash\` in user-triggered pull operations — that is safe because those are single-user UI actions, not concurrent agent operations.)
- **Only commit files YOU changed** for this task. Never use \`git add -A\` or \`git add .\` — always stage specific files by name.
${noChangeSuccess ? `- **No-change audits may exit cleanly.** ${NO_CHANGE_AUDIT_GUIDANCE}` : ''}
-${noCodeOutput
+${toolFreeReasoning
+ ? `- **No git at all.** You have no tools; the Completion section above is the whole contract.`
+ : noCodeOutput
? `- **Do NOT commit, push, or open a PR.** This task changes no code — its result is delivered by the API call or command described above. Without this, a no-worktree task of this shape was told to \`/do:push\` **directly to the branch it is standing on**, which for a task running in the app's live checkout is its default branch.`
: discardWorktree
? `- **Do NOT commit, push, or open a PR.** This worktree is discarded on exit — your only output is the completion sentinel (see the Completion section above).`
@@ -833,6 +842,7 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, isTruthyMet
// derive from a CD task's `creativeDirector` marker so pre-upgrade `pending`
// tasks (queued before this flag existed) are recognized without a migration.
const noCodeOutput = isTruthyMetaFn(task.metadata?.noCodeOutput) || !!task.metadata?.creativeDirector;
+ const toolFreeReasoning = isPublicReviewNoToolProfile(task.metadata?.executionProfile);
const noChangeSuccess = isTruthyMetaFn(task.metadata?.noChangeSuccess);
const isReviewLoopFollowUp = isTruthyMetaFn(task.metadata?.reviewLoopFollowUp);
const isWorktreeOnExistingBranch = isPrBranchWorktree(task, worktreeInfo);
@@ -1004,7 +1014,11 @@ function buildLightContextSections(task, workspaceDir, worktreeInfo, isTruthyMet
// matters in production — every `tui`/`cli` provider returns from the light
// path above and never reaches the other two, so a fix applied only there is
// no fix at all for anything a subscription-quota job can run.
- if (noCodeOutput) {
+ if (toolFreeReasoning) {
+ // No tools at all: the reply is the deliverable (see the full path's
+ // tuiCompletionSection ternary for the same precedence).
+ contractSections.push(buildToolFreeReasoningCompletionSection());
+ } else if (noCodeOutput) {
contractSections.push(buildActionOutputCompletionSection({
isTui,
sentinelPath: resolveSentinelPath(worktreeInfo, workspaceDir, agentId),
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index 727f2a6944..2270c0ba61 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -281,6 +281,29 @@ describe('reconcileSplitContext', () => {
});
});
+describe('tool-free public-review stage completion', () => {
+ // The Eligibility Gate runs with every tool removed. The No-Code contract
+ // (deliver via an API call, then write the sentinel) sent the model narrating
+ // "I will now update PortOS" instead of printing the JSON envelope.
+ const gateTask = () => makeTask({
+ metadata: {
+ context: 'Security scan status: passed.', noCodeOutput: true, discardWorktree: true, openPR: false,
+ executionProfile: 'public-review-gate',
+ },
+ });
+
+ it('tells the model its reply is the deliverable and never mentions a sentinel or API action', () => {
+ const prompt = buildLightContextPrompt(gateTask(), '/repo', null, isTruthyMeta, {
+ providerId: 'claude-ollama', providerCommand: 'claude',
+ });
+ expect(prompt).toMatch(/## Completion \(Tool-Free Reasoning\)/);
+ expect(prompt).toMatch(/final message of this reply/);
+ expect(prompt).not.toMatch(/## Completion \(No Code Output\)/);
+ expect(prompt).not.toMatch(/\.agent-done/);
+ expect(prompt).not.toMatch(/API request or command/);
+ });
+});
+
describe('no-code / API-action task completion (CD agents must NOT be told to /do:push)', () => {
// A Creative Director agent's deliverable is an HTTP PATCH described in its
// prompt, not a commit — so it must get the No-Code completion section, never
diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.js
index e23f6bae05..73cad94f2c 100644
--- a/server/services/cosTaskStore.js
+++ b/server/services/cosTaskStore.js
@@ -577,11 +577,17 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
// NOTE and re-classifying a multi-line edit of it would overwrite the task's
// real prompt. A producer that already wrote `metadata.prompt` wins over the
// inference. See `server/lib/cosTaskPrompt.js` for the full contract.
- const splitMetadata = splitTaskPromptFields(newTask.metadata);
- if (splitMetadata !== newTask.metadata) newTask = { ...newTask, metadata: splitMetadata };
// Markdown task rows are one-line records. Preserve every generated prompt
// in the newline-safe metadata field before persistence, including raw
// on-demand tasks that bypass the queue generator's normalization pass.
+ //
+ // This runs BEFORE the context reclassification below on purpose: a producer
+ // that hands over a multi-line description AND a multi-line context note (the
+ // pr-reviewer generator's security-scan summary) means the description is the
+ // prompt and the note is the note. Reclassifying first promoted the note to
+ // `prompt`, which then counted as an explicit producer prompt and silently
+ // discarded the stage instructions — Stage 2 ran with no gate rules and no
+ // output contract.
if (typeof newTask.description === 'string' && newTask.description.includes('\n')) {
newTask = {
...newTask,
@@ -594,6 +600,8 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignore
},
};
}
+ const splitMetadata = splitTaskPromptFields(newTask.metadata);
+ if (splitMetadata !== newTask.metadata) newTask = { ...newTask, metadata: splitMetadata };
// Add task to top or bottom based on position parameter
if (taskData.position === 'top') {
diff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.js
index 2c6c3b1741..83acc80442 100644
--- a/server/services/cosTaskStore.test.js
+++ b/server/services/cosTaskStore.test.js
@@ -419,6 +419,30 @@ describe('cosTaskStore.addTask', () => {
expect(reloaded.metadata.prompt).toBe(fullPrompt);
});
+ it('keeps a multiline raw description as the prompt when a multiline context note rides along', async () => {
+ // The pr-reviewer generator hands over the stage instructions as the
+ // description and the security-scan summary as a multi-line context note.
+ // Reclassifying the note first made it the "explicit" prompt and dropped
+ // the instructions, so Stage 2 ran with no gate rules and no output contract.
+ const stagePrompt = '[Improvement: Example] PR Eligibility Gate (Stage 2)\n\n## Gate\n\nReturn JSON only.';
+ const scanNote = 'Security scan status: passed.\nReviewed 1 external pull request.';
+ const created = await addTask({
+ id: 'sys-stage-with-note',
+ status: 'pending',
+ priority: 'MEDIUM',
+ priorityValue: 2,
+ description: stagePrompt,
+ metadata: { context: scanNote },
+ section: 'pending',
+ }, 'internal', { raw: true });
+ expect(created.description).toBe('[Improvement: Example] PR Eligibility Gate (Stage 2)');
+ expect(created.metadata.prompt).toBe(stagePrompt);
+ expect(created.metadata.context).toBe(scanNote);
+ const reloaded = await getTaskById('sys-stage-with-note');
+ expect(reloaded.metadata.prompt).toBe(stagePrompt);
+ expect(reloaded.metadata.context).toBe(scanNote);
+ });
+
it('preserves an explicitly empty prompt while normalizing a multiline raw description', async () => {
const created = await addTask({
id: 'sys-cleared-scheduled-prompt',
diff --git a/server/services/promptSections/completion.js b/server/services/promptSections/completion.js
index 629f1fc17d..e90904ebf7 100644
--- a/server/services/promptSections/completion.js
+++ b/server/services/promptSections/completion.js
@@ -45,7 +45,12 @@ export function buildCompletionGuidelineBullet({
isReadOnly, isTui, tuiCompletionCommand, slashdoFree = false,
worktreeInfo, willOpenPR, prCompletion = PR_COMPLETIONS.MERGE_ON_GREEN, discardWorktree = false, noCodeOutput = false,
leavePrOpen = false, isPrFollowUp = false, claimFlow = false, noChangeSuccess = false, whenDone = null,
+ toolFreeReasoning = false,
}) {
+ // Checked before every other contract: a tool-free stage cannot write a
+ // sentinel, call an API, or run a command, so any of the bullets below would
+ // send it chasing an output channel it does not have.
+ if (toolFreeReasoning) return TOOL_FREE_REASONING_BULLET;
// A PR follow-up (review-loop or merge-only) already carries its own PRIMARY
// OBJECTIVE section with the full procedure, and its cleanup runs with
// `skipMerge`. The generic "your branch is merged back automatically" bullet
@@ -187,6 +192,23 @@ and do NOT revert its commits unless they are actually wrong.
`;
}
+const TOOL_FREE_REASONING_BULLET = '**You have no tools.** Do not try to run commands, read or write files, or call an API — none of that is available. Your entire deliverable is the final message of this reply: the exact JSON object described in your task instructions, and nothing after it. PortOS reads it from the transcript.';
+
+/**
+ * Completion block for a **tool-free reasoning** stage (pr-reviewer's
+ * Eligibility Gate). The CLI runs with every tool removed, so the sentinel and
+ * API-action contracts are impossible to satisfy; the only channel out is the
+ * reply itself, which PortOS parses for the task's JSON envelope.
+ */
+export function buildToolFreeReasoningCompletionSection() {
+ return [
+ '## Completion (Tool-Free Reasoning)',
+ TOOL_FREE_REASONING_BULLET,
+ '',
+ 'Do not narrate a plan to apply the decision, and do not wait for anything after the JSON — the reply ends there.',
+ ].join('\n');
+}
+
/**
* Completion block for a **programmatic-output** (throwaway-worktree) task: the
* agent reasons in a worktree that is discarded on exit, so it must NOT commit,