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: link node_modules into claim worktrees so agents can run tests (#9052)
[._.]/ Adam Eivy6d1031d83c57
diff --git a/scripts/link-worktree-deps.js b/scripts/link-worktree-deps.jsnew file mode 100644index 0000000000..4ab279c303--- /dev/null+++ b/scripts/link-worktree-deps.js@@ -0,0 +1,35 @@+#!/usr/bin/env node+/**+ * Link node_modules from the source checkout into a worktree.+ *+ * This script symlinks the root, client/, and server/ node_modules directories+ * from the primary checkout into a fresh worktree, allowing agents to run tests+ * and npm commands without installing dependencies inside the worktree (which+ * would corrupt the primary checkout through symlinks).+ *+ * Usage: node scripts/link-worktree-deps.js <worktree-path>+ *+ * This is called by the Claim Issue prompt's Phase 2 to set up dependencies+ * immediately after `git worktree add`, before any agent work begins.+ */++import { fileURLToPath } from 'url';+import { dirname, join } from 'path';+import { linkWorktreeDependencies } from '../server/services/worktreeManager.js';++const __dirname = dirname(fileURLToPath(import.meta.url));+const repoRoot = dirname(__dirname);+const worktreePath = process.argv[2];++if (!worktreePath) {+ console.error('❌ Usage: node scripts/link-worktree-deps.js <worktree-path>');+ process.exit(1);+}++try {+ await linkWorktreeDependencies(repoRoot, worktreePath);+ console.log(`✓ Linked node_modules into ${worktreePath}`);+} catch (err) {+ console.error(`❌ Failed to link node_modules: ${err.message}`);+ process.exit(1);+}diff --git a/scripts/link-worktree-deps.test.js b/scripts/link-worktree-deps.test.jsnew file mode 100644index 0000000000..96fa0c268d--- /dev/null+++ b/scripts/link-worktree-deps.test.js@@ -0,0 +1,112 @@+import { describe, it, expect, beforeEach, afterEach } from 'vitest';+import { mkdir, rmdir, stat, readlink, writeFile } from 'fs/promises';+import { join } from 'path';+import { tmpdir } from 'os';+import { execSync } from 'child_process';+import { linkWorktreeDependencies } from '../server/services/worktreeManager.js';++describe('link-worktree-deps', () => {+ let tempDir;+ let sourceDir;+ let worktreeDir;++ beforeEach(async () => {+ // Create temporary directories for testing+ const timestamp = Date.now();+ tempDir = join(tmpdir(), `link-deps-test-${timestamp}`);+ sourceDir = join(tempDir, 'source');+ worktreeDir = join(tempDir, 'worktree');++ await mkdir(sourceDir, { recursive: true });+ await mkdir(join(sourceDir, 'client'), { recursive: true });+ await mkdir(join(sourceDir, 'server'), { recursive: true });+ await mkdir(join(sourceDir, 'node_modules'), { recursive: true });+ await mkdir(join(sourceDir, 'client', 'node_modules'), { recursive: true });+ await mkdir(join(sourceDir, 'server', 'node_modules'), { recursive: true });+ await mkdir(join(sourceDir, 'unrelated'), { recursive: true });++ // Create package.json files so the helper recognizes client/server as needing symlinks+ await Promise.all([+ writeFile(join(sourceDir, 'package.json'), '{}'),+ writeFile(join(sourceDir, 'client', 'package.json'), '{}'),+ writeFile(join(sourceDir, 'server', 'package.json'), '{}'),+ ]);++ await mkdir(worktreeDir, { recursive: true });+ await mkdir(join(worktreeDir, 'client'), { recursive: true });+ await mkdir(join(worktreeDir, 'server'), { recursive: true });++ await Promise.all([+ writeFile(join(worktreeDir, 'package.json'), '{}'),+ writeFile(join(worktreeDir, 'client', 'package.json'), '{}'),+ writeFile(join(worktreeDir, 'server', 'package.json'), '{}'),+ ]);+ });++ afterEach(async () => {+ // Cleanup+ if (tempDir) {+ try {+ execSync(`rm -rf "${tempDir}"`);+ } catch {+ // Ignore cleanup errors+ }+ }+ });++ it('creates symlinks for root, client, and server node_modules', async () => {+ await linkWorktreeDependencies(sourceDir, worktreeDir);++ // Verify symlinks were created+ const rootLink = await readlink(join(worktreeDir, 'node_modules'));+ expect(rootLink).toBe(join(sourceDir, 'node_modules'));++ const clientLink = await readlink(join(worktreeDir, 'client', 'node_modules'));+ expect(clientLink).toBe(join(sourceDir, 'client', 'node_modules'));++ const serverLink = await readlink(join(worktreeDir, 'server', 'node_modules'));+ expect(serverLink).toBe(join(sourceDir, 'server', 'node_modules'));+ });++ it('preserves pre-existing entries without modifying them', async () => {+ // Create a pre-existing directory (not a symlink) for client node_modules+ // This should be preserved+ await mkdir(join(worktreeDir, 'client', 'node_modules', 'existing-dep'), { recursive: true });++ // Run the link function+ await linkWorktreeDependencies(sourceDir, worktreeDir);++ // Verify the pre-existing directory structure in client/node_modules still exists+ const stat1 = await stat(join(worktreeDir, 'client', 'node_modules', 'existing-dep'));+ expect(stat1.isDirectory()).toBe(true);+ expect(stat1.isSymbolicLink()).toBe(false);++ // Server node_modules should have been created as a symlink (it wasn't pre-existing)+ const serverLink = await readlink(join(worktreeDir, 'server', 'node_modules'));+ expect(serverLink).toBe(join(sourceDir, 'server', 'node_modules'));+ });++ it('does not touch the primary checkout node_modules', async () => {+ const sourceNodeModulesStat = await stat(join(sourceDir, 'node_modules'));+ expect(sourceNodeModulesStat.isDirectory()).toBe(true);++ await linkWorktreeDependencies(sourceDir, worktreeDir);++ // Verify source is still an ordinary directory (not modified)+ const sourceNodeModuleStatAfter = await stat(join(sourceDir, 'node_modules'));+ expect(sourceNodeModuleStatAfter.isDirectory()).toBe(true);+ expect(sourceNodeModuleStatAfter.isSymbolicLink()).toBe(false);+ });++ it('skips missing source directories gracefully', async () => {+ // Remove the source node_modules (simulate a repo that doesn't have them)+ execSync(`rm -rf "${join(sourceDir, 'node_modules')}"`);++ // Should not throw+ await linkWorktreeDependencies(sourceDir, worktreeDir);++ // root node_modules should not exist in worktree since source doesn't have it+ const exists = await stat(join(worktreeDir, 'node_modules')).catch(() => null);+ expect(exists).toBeNull();+ });+});diff --git a/server/services/taskPromptDefaults/integrity.snapshot.json b/server/services/taskPromptDefaults/integrity.snapshot.jsonindex d28db49d9e..9fb367193b 100644--- a/server/services/taskPromptDefaults/integrity.snapshot.json+++ b/server/services/taskPromptDefaults/integrity.snapshot.json@@ -12,7 +12,7 @@"better-test-quality": "ab53a477cd194a5c4fbda09d901a3775","branch-cleanup": "8fdeb4acc2749816a47ca318b6602721","branch-reconcile": "ae6e8164698faebc2a5fd4fecb3d41e8",- "claim-issue": "811ff55f4e797ee554b43f5c0911bc19",+ "claim-issue": "22d254dd59ee7d59496f703fefdacb90","claim-issue-gitlab": "542e10eb02e850fb40d11fab6497deee","claim-issue-jira": "64ccd403371ea2b55c53b665b789dd38","code-quality": "6762542233cdffb86d4e2244945bf52b",@@ -74,7 +74,7 @@"better-structural-drift": 1,"better-test-quality": 1,"branch-reconcile": 7,- "claim-issue": 35,+ "claim-issue": 36,"claim-issue-gitlab": 31,"claim-issue-jira": 20,"code-quality": 4,@@ -189,7 +189,8 @@"d735d14f7936ada5621b8e96b53549cc","0651e646940cc96677cf87d4764bd88d","b9360ef3018be5fce3e0413cae86a20d",- "f6f3c5865744d46da2edde702beecf27"+ "f6f3c5865744d46da2edde702beecf27",+ "811ff55f4e797ee554b43f5c0911bc19"],"claim-issue-gitlab": ["fae92c45c89c65455930b4b06a1b88c4",diff --git a/server/services/taskPromptDefaults/prompts.js b/server/services/taskPromptDefaults/prompts.jsindex eca429f048..a92a57c71a 100644--- a/server/services/taskPromptDefaults/prompts.js+++ b/server/services/taskPromptDefaults/prompts.js@@ -2793,6 +2793,8 @@ WORKTREE="{worktreesRoot}/claim-{appSlug}-issue-\${NUM}"mkdir -p {worktreesRoot}git fetch origin maingit worktree add --no-track -b "claim/issue-\${NUM}" "\${WORKTREE}" origin/main+# Link node_modules from the primary checkout so tests can run immediately:+node {repoRoot}/scripts/link-worktree-deps.js "\${WORKTREE}"# Cross-machine claim markers (best-effort — do not abort the run if these fail):gh issue edit "\${NUM}" --add-assignee @me 2>/dev/nullgh issue edit "\${NUM}" --add-label in-progress 2>/dev/nulldiff --git a/server/services/taskPromptDefaults/versions.js b/server/services/taskPromptDefaults/versions.jsindex 3d596a621a..eb15719383 100644--- a/server/services/taskPromptDefaults/versions.js+++ b/server/services/taskPromptDefaults/versions.js@@ -99,7 +99,7 @@ export const PROMPT_VERSIONS = {// slashdo /do:next skill — its next/issue-<num> branch and sibling worktree convention// differ from this flow's claim/issue-<num>, which is what made a /do:next-created PR// invisible to the watchdog's live-claim check (#8161; server/lib/planIds.js).-PROMPT_VERSIONS['claim-issue'] = 35;+PROMPT_VERSIONS['claim-issue'] = 36;PROMPT_VERSIONS['claim-issue-gitlab'] = 31;PROMPT_VERSIONS['claim-issue-jira'] = 20;