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
fix(cos): remove git stash from agent workflows and enforce do:push for commits
Adam Eivyd086bdfcebc9
diff --git a/client/src/components/apps/tabs/GitTab.jsx b/client/src/components/apps/tabs/GitTab.jsxindex 29816948ba..a3207a03c8 100644--- a/client/src/components/apps/tabs/GitTab.jsx+++ b/client/src/components/apps/tabs/GitTab.jsx@@ -170,11 +170,10 @@ export default function GitTab({ appId: _appId, appName, repoPath }) {if (result) {const parts = [];for (const [key, val] of Object.entries(result)) {- if (key !== 'stashed' && key !== 'stashRestored' && key !== 'currentBranch' && val) {+ if (key !== 'currentBranch' && val) {parts.push(`${key}: ${val}`);}}- if (result.stashed) parts.push(result.stashRestored ? 'stash restored' : 'stash conflict');toast.success(`Branches updated — ${parts.join(', ')}`);}await loadGitInfo();diff --git a/data.sample/prompts/stages/cos-agent-briefing.md b/data.sample/prompts/stages/cos-agent-briefing.mdindex d397a12963..e172d4466e 100644--- a/data.sample/prompts/stages/cos-agent-briefing.md+++ b/data.sample/prompts/stages/cos-agent-briefing.md@@ -44,9 +44,17 @@ Your job is to complete the assigned task independently and efficiently.- Follow existing code patterns and conventions in the project- Make minimal, targeted changes to accomplish the goal- Test your changes when test commands are available+- **Commit and push using `/do:push`** — this handles changelog updates, staging specific files, writing a conventional commit message, and pushing safely. If `/do:push` is unavailable, follow its conventions manually: stage specific files by name, use `feat:`/`fix:`/`breaking:` prefix, no Co-Authored-By annotations, and push with `git pull --rebase && git push`.- If you encounter blockers, document them clearly in your output- **Never update the PortOS changelog (`.changelog/`) for work on managed apps** — the PortOS changelog tracks PortOS core changes only. Work done on external/managed applications belongs in those projects' own changelogs, not in PortOS+## Git Hygiene (CRITICAL)++- **Before starting work**, run `git status` to verify a clean working tree. Do NOT stash or discard uncommitted changes — other agents may be working concurrently and expecting those changes to be present. If the tree is dirty, only commit files YOU changed for this task.+- **NEVER use `git stash`** in any form (`git stash push`, `git stash pop`, `--autostash`, 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.+- **Only commit files YOU changed** for this task. Never use `git add -A` or `git add .` — always stage specific files by name.+- **Commit directly to the current branch.** Do NOT create feature branches or PRs unless explicitly instructed.+## Working Environment- You have full access to the filesystem via MCP toolsdiff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex cb6b37d7ee..12d401fc0a 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -311,7 +311,7 @@ export async function spawnAgentForTask(task) {return null;} else if (pullResult.success && !pullResult.upToDate && !pullResult.skipped) {emitLog('info', `📥 Pulled latest for ${resolvedAppName || 'workspace'} (branch: ${pullResult.branch})`, {- taskId: task.id, workspace: workspacePath, branch: pullResult.branch, stashed: pullResult.stashed+ taskId: task.id, workspace: workspacePath, branch: pullResult.branch});} else if (!pullResult.success) {emitLog('warn', `⚠️ Pre-task git pull error: ${pullResult.error}`, { taskId: task.id, workspace: workspacePath });diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.jsindex bd91bf7e73..0b83b722fb 100644--- a/server/services/agentPromptBuilder.js+++ b/server/services/agentPromptBuilder.js@@ -315,11 +315,13 @@ ${skillSection ? `## Task-Type Skill Guidelines\n\n${skillSection}\n` : ''}${too- If blocked, explain clearly why- Never update the PortOS changelog (\`.changelog/\`) for work on managed apps — the PortOS changelog tracks PortOS core changes only- **BTW Messages**: The user may send you additional context while you work. Check for a \`BTW.md\` file in your working directory root — if it exists, read it for important messages from the user. Incorporate that context into your work. Do not delete or modify BTW.md.-${isTruthyMetaFn(task.metadata?.readOnly) ? `- **This is a read-only task.** Do NOT commit, push, or modify any files in the repository. Only read data and generate reports.` : task.metadata?.app && worktreeInfo && willOpenPR ? `- Commit code after each feature or bug fix using the git tools or /cam skill. A pull request will be automatically created when your task completes — do NOT open a PR manually.` : task.metadata?.app && worktreeInfo ? `- Commit code after each feature or bug fix using the git tools or /cam skill. Your worktree branch will be automatically merged back to the source branch when your task completes — do NOT open a PR.` : `- Commit code after each feature or bug fix using the git tools or /cam skill`}+${isTruthyMetaFn(task.metadata?.readOnly) ? `- **This is a read-only task.** Do NOT commit, push, or modify any files in the repository. Only read data and generate reports.` : task.metadata?.app && worktreeInfo && willOpenPR ? `- A pull request will be automatically created when your task completes — do NOT open a PR manually.` : task.metadata?.app && worktreeInfo ? `- Your worktree branch will be automatically merged back to the source branch when your task completes — do NOT open a PR.` : ``}## Git Hygiene (CRITICAL)- **Before starting work**, run \`git status\` to verify a clean working tree. Do NOT stash or discard uncommitted changes — other agents may be working concurrently and expecting those changes to be present. If the tree is dirty, only commit files YOU changed for this task.+- **NEVER use \`git stash\`** in any form (\`git stash push\`, \`git stash pop\`, \`--autostash\`, 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.- **Only commit files YOU changed** for this task. Never use \`git add -A\` or \`git add .\` — always stage specific files by name.+- **Commit and push using \`/do:push\`** — this handles changelog updates, staging specific files, writing a conventional commit message, and pushing safely. If \`/do:push\` is unavailable, follow its conventions manually: stage specific files, use \`feat:\`/\`fix:\`/\`breaking:\` prefix, no Co-Authored-By annotations, and push with \`git pull --rebase && git push\`.${worktreeInfo ? `- **Your PR should contain only your task's commits.** If you see unrelated commits in your branch history, something is wrong — do not open a PR with other agents' work.` : `- **Commit directly to the current branch.** Do NOT create feature branches or PRs unless explicitly instructed.`}## Working Directorydiff --git a/server/services/git.js b/server/services/git.jsindex af67392c5a..962bbee218 100644--- a/server/services/git.js+++ b/server/services/git.js@@ -254,10 +254,8 @@ export async function updateBranches(dir) {const currentBranch = await getBranch(dir);const allBranches = await getBranches(dir);const trackBranches = allBranches.filter(b => b.tracking).map(b => b.name);- let stashed = false;- let stashRestored = false;- const results = { stashed, stashRestored: false, currentBranch };+ const results = { currentBranch };// Update non-current branches via fetch refspec (no checkout needed)for (const branch of trackBranches.filter(b => b !== currentBranch)) {@@ -266,20 +264,14 @@ export async function updateBranches(dir) {}// Update current branch if it's one of the tracked branches — requires merge+ // Skip if working tree is dirty — other agents may own those uncommitted changesif (trackBranches.includes(currentBranch)) {if (!status.clean) {- await execGit(['stash', 'push', '-m', 'portos-auto-stash'], dir);- stashed = true;- results.stashed = true;+ results[currentBranch] = 'skipped-dirty';+ } else {+ const r = await execGit(['merge', '--ff-only', `origin/${currentBranch}`], dir, { ignoreExitCode: true });+ results[currentBranch] = r.stderr?.includes('fatal') ? 'failed' : 'updated';}- const r = await execGit(['merge', '--ff-only', `origin/${currentBranch}`], dir, { ignoreExitCode: true });- results[currentBranch] = r.stderr?.includes('fatal') ? 'failed' : 'updated';- }-- if (stashed) {- const popResult = await execGit(['stash', 'pop'], dir, { ignoreExitCode: true });- stashRestored = !popResult.stderr?.includes('CONFLICT');- results.stashRestored = stashRestored;}return results;@@ -577,63 +569,47 @@ export function hasChangelogDir(dir) {/*** Ensure workspace has the latest code from origin before agent work begins.* Scripted pull: fetch + fast-forward merge on the dev/default branch.- * If the working tree is dirty, stashes changes first and restores after.- * Returns conflict info if the pull can't be completed cleanly.+ * If the working tree is dirty, skips the pull — other agents may own those+ * uncommitted changes and stashing could interfere with their work.** @param {string} dir - Git repository directory- * @returns {{ success: boolean, branch: string, stashed: boolean, conflict: boolean, error: string|null }}- */-/**- * Pop stash and clean up if the pop produces merge conflicts.- * Returns { conflict: boolean, stderr: string }+ * @returns {{ success: boolean, branch: string, conflict: boolean, error: string|null }}*/-async function popStashSafely(dir) {- const result = await execGit(['stash', 'pop'], dir, { ignoreExitCode: true });- const output = `${result.stdout || ''} ${result.stderr || ''}`;- if (output.includes('CONFLICT') || result.exitCode !== 0) {- await execGit(['checkout', '--', '.'], dir, { ignoreExitCode: true });- await execGit(['stash', 'drop'], dir, { ignoreExitCode: true });- return { conflict: true, stderr: result.stderr || '' };- }- return { conflict: false, stderr: '' };-}export async function ensureLatest(dir) {const gitCheck = await isRepo(dir).catch(() => false);- if (!gitCheck) return { success: true, branch: null, stashed: false, conflict: false, error: null, skipped: 'not-a-repo' };+ if (!gitCheck) return { success: true, branch: null, conflict: false, error: null, skipped: 'not-a-repo' };const currentBranch = await getBranch(dir).catch(() => null);- if (!currentBranch) return { success: true, branch: null, stashed: false, conflict: false, error: null, skipped: 'no-branch' };+ if (!currentBranch) return { success: true, branch: null, conflict: false, error: null, skipped: 'no-branch' };// Check for remote — no remote means nothing to pullconst remote = await getRemote(dir).catch(() => null);- if (!remote?.origin) return { success: true, branch: currentBranch, stashed: false, conflict: false, error: null, skipped: 'no-remote' };+ if (!remote?.origin) return { success: true, branch: currentBranch, conflict: false, error: null, skipped: 'no-remote' };// Fetch latest refs from originconst fetchResult = await execGit(['fetch', 'origin'], dir, { ignoreExitCode: true });if (fetchResult.stderr?.includes('fatal')) {- return { success: false, branch: currentBranch, stashed: false, conflict: false, error: `fetch failed: ${fetchResult.stderr}` };+ return { success: false, branch: currentBranch, conflict: false, error: `fetch failed: ${fetchResult.stderr}` };}// Check if remote tracking branch existsconst remoteRef = await execGit(['rev-parse', `origin/${currentBranch}`], dir, { ignoreExitCode: true });if (remoteRef.stderr?.includes('unknown revision')) {- return { success: true, branch: currentBranch, stashed: false, conflict: false, error: null, skipped: 'no-remote-tracking' };+ return { success: true, branch: currentBranch, conflict: false, error: null, skipped: 'no-remote-tracking' };}// Check if already up to dateconst localHead = (await execGit(['rev-parse', 'HEAD'], dir)).stdout.trim();const remoteHead = remoteRef.stdout.trim();if (localHead === remoteHead) {- return { success: true, branch: currentBranch, stashed: false, conflict: false, error: null, upToDate: true };+ return { success: true, branch: currentBranch, conflict: false, error: null, upToDate: true };}- // Stash dirty working tree if needed+ // Skip pull if working tree is dirty — other agents may own those changesconst status = await getStatus(dir).catch(() => ({ clean: true }));- let stashed = false;if (!status.clean) {- await execGit(['stash', 'push', '-m', 'cos-pre-task-autostash'], dir);- stashed = true;+ return { success: true, branch: currentBranch, conflict: false, error: null, skipped: 'dirty-working-tree' };}// Try fast-forward merge first (safest — no rewrite)@@ -641,14 +617,7 @@ export async function ensureLatest(dir) {const mergeOk = !mergeResult.stderr?.includes('fatal') && !mergeResult.stderr?.includes('Not possible to fast-forward');if (mergeOk) {- // Fast-forward succeeded- if (stashed) {- const { conflict, stderr } = await popStashSafely(dir);- if (conflict) {- return { success: false, branch: currentBranch, stashed: true, conflict: true, error: `stash pop conflict after fast-forward: ${stderr}` };- }- }- return { success: true, branch: currentBranch, stashed, conflict: false, error: null };+ return { success: true, branch: currentBranch, conflict: false, error: null };}// Fast-forward failed — local branch has diverged. Try rebase.@@ -658,27 +627,15 @@ export async function ensureLatest(dir) {if (!rebaseOk) {// Rebase failed — abort and report conflictawait execGit(['rebase', '--abort'], dir, { ignoreExitCode: true });- if (stashed) {- await popStashSafely(dir);- }return {success: false,branch: currentBranch,- stashed,conflict: true,error: `branch ${currentBranch} has diverged from origin and rebase has conflicts: ${rebaseResult.stderr}`};}- // Rebase succeeded- if (stashed) {- const { conflict, stderr } = await popStashSafely(dir);- if (conflict) {- return { success: false, branch: currentBranch, stashed: true, conflict: true, error: `stash pop conflict after rebase: ${stderr}` };- }- }-- return { success: true, branch: currentBranch, stashed, conflict: false, error: null };+ return { success: true, branch: currentBranch, conflict: false, error: null };}/**diff --git a/server/services/pm2Standardizer.js b/server/services/pm2Standardizer.jsindex 62703ce7c2..314d669f4e 100644--- a/server/services/pm2Standardizer.js+++ b/server/services/pm2Standardizer.js@@ -320,25 +320,10 @@ export async function createGitBackup(repoPath) {const timestamp = Date.now();const branch = `portos-backup-${timestamp}`;- // Check for uncommitted changes- const { stdout: status } = await execAsync('git status --porcelain', { cwd: repoPath, windowsHide: true });- const hasChanges = status.trim().length > 0;-- if (hasChanges) {- // Stash changes- await execAsync('git stash push -m "PortOS standardization backup"', { cwd: repoPath, windowsHide: true })- .catch(() => null); // Ignore if nothing to stash- }-- // Create backup branch+ // Create backup branch from current HEAD (captures committed state without stashing)await execAsync(`git branch ${branch}`, { cwd: repoPath, windowsHide: true });- if (hasChanges) {- // Pop stash- await execAsync('git stash pop', { cwd: repoPath, windowsHide: true }).catch(() => null);- }-- return { success: true, branch, hadChanges: hasChanges };+ return { success: true, branch };}/**diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex d87f7862f2..fc4525b076 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -639,7 +639,7 @@ For each comment, read the referenced file and critically evaluate the suggestioEither way, resolve every thread — the goal is zero unresolved threads before merge.After evaluating all threads:-- If any code changes were made: run the project's test suite to verify, then commit and push following the project's push conventions (e.g., \`git pull --rebase --autostash && git push\`)+- If any code changes were made: run the project's test suite to verify, then commit and push using \`/do:push\` (or manually: stage specific files, conventional commit prefix, \`git pull --rebase && git push\`)### 5d. Resolve ALL threads via GraphQL mutation (both fixed and dismissed):