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

address review (codex): expand ~ in getAppWorkspace, not just at the spawn boundary

[._.]/ Adam Eivyb47aee4f00f5
diff --git a/server/services/agentPromptBuilder.js b/server/services/agentPromptBuilder.js
index d7c33a503b..ec283fbcfd 100644
--- a/server/services/agentPromptBuilder.js
+++ b/server/services/agentPromptBuilder.js
@@ -15,7 +15,7 @@ import { buildPrompt } from './promptService.js';
import { getToolsSummaryForPrompt } from './tools.js';
import { getActiveProvider } from './providers.js';
import { runPromptThroughProvider } from '../lib/promptRunner.js';
-import { readJSONFile, loadSlashdoFile, loadSlashdoLib, writeResolvedSlashdoBody, PATHS, tryReadFile } from '../lib/fileUtils.js';
+import { readJSONFile, loadSlashdoFile, loadSlashdoLib, writeResolvedSlashdoBody, PATHS, tryReadFile, expandHome } from '../lib/fileUtils.js';
import { DEFAULT_REVIEWER, DEFAULT_REVIEWERS, DEFAULT_REVIEW_STOP_MODE, LOCAL_LLM_REVIEWERS, MODEL_CAPABLE_CLI_REVIEWERS, normalizeReviewers, normalizeReviewUsernames, normalizeOptionalReviewers, normalizeReviewerMaxRounds, resolveReviewUsernames, resolveOptionalReviewers, resolveReviewerMaxRounds, resolveReviewerModels, reviewerModelsFromDefaults, resolveKeyedReviewers, buildReviewWithArgs, buildReviewersCsv } from '../lib/validation.js';
import { PROVIDER_TYPES } from '../lib/aiToolkit/constants.js';
import { canTypeSlashCommands, resolveSlashdoInvocation, buildSlashdoSection, unreachableReviewerIncludes, SLASHDO_INLINE_BUDGET_CHARS } from '../lib/slashdoInvocation.js';
@@ -2025,7 +2025,13 @@ export async function getAppWorkspace(appName) {
if (!app) return unresolved(`App '${appName}' not found in apps registry`);
if (!app.repoPath) return unresolved(`App '${appName}' has no repoPath`);
- return app.repoPath;
+ // Expand here, not just at the spawn boundary. Callers do more with this than
+ // spawn into it: agentLifecycle persists it as an agent's `sourceWorkspace`,
+ // and the worktree cleanup/merge paths later hand that value to a child
+ // process as its cwd. Node never shell-expands `~`, so returning the raw
+ // tilde form would let a task start (the spawn path expands) and then strand
+ // its worktree and branch when cleanup runs against a path that doesn't exist.
+ return expandHome(app.repoPath);
}
/**
diff --git a/server/services/agentPromptBuilder.test.js b/server/services/agentPromptBuilder.test.js
index eb3db9c876..9ac977d4f4 100644
--- a/server/services/agentPromptBuilder.test.js
+++ b/server/services/agentPromptBuilder.test.js
@@ -50,6 +50,9 @@ vi.mock('../lib/fileUtils.js', async (importOriginal) => {
return {
...actual,
loadSlashdoFile: vi.fn().mockResolvedValue(null),
+ // getAppWorkspace reads data/apps.json through this — mocked so the tilde
+ // tests below never touch the real registry.
+ readJSONFile: vi.fn(actual.readJSONFile),
// #3110 — staging the resolved copy is real disk I/O; mocked so tests can
// assert the pointer path without writing under data/.
writeResolvedSlashdoBody: vi.fn().mockResolvedValue(null),
@@ -66,7 +69,7 @@ vi.mock('./codeReview.js', () => ({
getCodeReviewDefaults: vi.fn().mockResolvedValue({ reviewers: ['copilot'] }),
}));
-import { buildLightContextPrompt, buildAgentPrompt, buildCompletionGuidelineBullet, reconcileSplitContext, buildReviewLoopFollowUpSection } from './agentPromptBuilder.js';
+import { buildLightContextPrompt, buildAgentPrompt, buildCompletionGuidelineBullet, reconcileSplitContext, buildReviewLoopFollowUpSection, getAppWorkspace } from './agentPromptBuilder.js';
import { getCodeReviewDefaults } from './codeReview.js'; // mocked above — control the configured default
import { isTruthyMeta } from './agentState.js';
import { buildPrompt } from './promptService.js'; // mocked above — inspect call args
@@ -1943,3 +1946,32 @@ describe('buildAgentPrompt — slashdo prompt-size controls', () => {
});
});
});
+
+describe('getAppWorkspace — tilde expansion (#3180)', () => {
+ // Callers do more than spawn into this: agentLifecycle persists it as an
+ // agent's sourceWorkspace, and worktree cleanup/merge later hand that value
+ // to a child process as cwd. Node never shell-expands `~`, so a raw tilde
+ // here lets a task start (the spawn path expands) and then strands its
+ // worktree and branch when cleanup runs against a path that doesn't exist.
+ it('returns an expanded path so worktree cleanup can use it as a cwd', async () => {
+ const { homedir } = await import('os');
+ const { join } = await import('path');
+ const { readJSONFile } = await import('../lib/fileUtils.js');
+
+ readJSONFile.mockResolvedValueOnce({
+ apps: { 'tilde-app': { name: 'Tilde App', repoPath: '~/some-repo' } },
+ });
+
+ const resolved = await getAppWorkspace('tilde-app');
+ expect(resolved).toBe(join(homedir(), 'some-repo'));
+ expect(resolved.startsWith('~')).toBe(false);
+ });
+
+ it('leaves an already-absolute repoPath untouched', async () => {
+ const { readJSONFile } = await import('../lib/fileUtils.js');
+ readJSONFile.mockResolvedValueOnce({
+ apps: { 'abs-app': { name: 'Abs App', repoPath: '/srv/repos/abs-app' } },
+ });
+ expect(await getAppWorkspace('abs-app')).toBe('/srv/repos/abs-app');
+ });
+});