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: keep the worktree link containment guard module-private (#12633)
[._.]/ Adam Eivy83cd3b5da0b0
diff --git a/server/lib/README.md b/server/lib/README.mdindex 053e306c8a..5335cfe05f 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -559,7 +559,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `taskTargetScope.js` | Target scope for a scheduled task type: `INSTALL_WIDE_TASK_TYPES`, `MANAGED_APP_TARGET_TASK_TYPES`, `PROGRAMMATIC_SCHEDULED_TASK_TYPES`, `isProgrammaticScheduledTaskType`, `requiresManagedAppTarget`, `requiresInstallWideTarget`. Declared here (not in `services/taskScheduleRegistry.js`, which re-exports it) so `quotaBurnValidation.js` can reject a burn reference with the wrong target scope without importing upward into services. || `taxonomyTally.js` | Generic taxonomy tally + top-N-line render engine shared by the two Layered Intelligence leaf taxonomies (`services/layeredIntelligenceRejections.js`, `layeredIntelligenceExecutionFailures.js`). `createTaxonomyTally({predicate, select, field, vocabulary, sentinel, glossFn, gapWording})` is the single composed seam — it binds a taxonomy config into `{summarize, format}`, where `summarize(records)` yields the three-bucket `{entries, unknown, unclassified, diagnosed, total}` tally (commonest-first + taxonomy-order tie-break) and `format(records, limit)` renders one prompt line naming every non-zero gap. Also exports the two leaf utilities the classifiers use directly: `normalizeToken(value)` (lowercase + separator-collapse for label/category matching) and `formatTaxonomyToken(token, labels)` (gloss-map render, nullish→'', unglossed passthrough). Pure leaf — imports nothing from the LI graph. || `appPromptPlaceholders.js` | `applyAppPlaceholders(text, app)` — expand `{appName}` / `{repoPath}` / `{appId}` / `{appSlug}` in a CoS prompt template. The ONE owner of that chain: four renderers (`cosTaskGenerator.js`'s claim-work router and JIRA per-ticket builder, `cosTaskPreStepBlocks.js`'s scheduled builder, `referenceRepos.js`) each used to spell it themselves and drifted. Function-form replacers throughout, since a name/path/id is free text a `$` can appear in. Callers expand their own injected blocks (`{trackerInstructions}`, `{modeInstructions}`) FIRST — those blocks carry app placeholders of their own. Pure. |-| `worktreeNodeModules.js` | Workspace-aware `node_modules` provisioning for a worktree (#12633). `provisionWorkspaceNodeModules(sourceRoot, worktreeRoot)` builds a real `node_modules` directory when the source's holds workspace links (`@scope/pkg -> ../../packages/pkg`): every entry is symlinked back to the source except those links, which are recreated so they resolve INSIDE the worktree (a plain directory symlink resolves them against the source checkout, so a worktree ahead of the source's branch silently tests stale workspace code). Returns `false` and creates nothing when there are no workspace links. `assertLinkWithinWorktree` is the containment guard run on every recreated link; `removeProvisionedNodeModules` undoes the farm and only touches a directory carrying `WORKTREE_NODE_MODULES_MARKER`, so a real `npm install` is never mistaken for it. Consumed by `services/worktreeManager.js#linkWorktreeDependencies`. |+| `worktreeNodeModules.js` | Workspace-aware `node_modules` provisioning for a worktree (#12633). `provisionWorkspaceNodeModules(sourceRoot, worktreeRoot)` builds a real `node_modules` directory when the source's holds workspace links (`@scope/pkg -> ../../packages/pkg`): every entry is symlinked back to the source except those links, which are recreated so they resolve INSIDE the worktree (a plain directory symlink resolves them against the source checkout, so a worktree ahead of the source's branch silently tests stale workspace code). Returns `false` and creates nothing when there are no workspace links. Every recreated link is checked to resolve inside the worktree, else provisioning fails; `removeProvisionedNodeModules` undoes the farm and only touches a directory carrying `WORKTREE_NODE_MODULES_MARKER`, so a real `npm install` is never mistaken for it. Consumed by `services/worktreeManager.js#linkWorktreeDependencies`. || `worktreeOwnership.js` | Pure ownership gate for destructive worktree operations. `worktreeOwnershipReason()` applies root, agent-id, lock, active-agent, liveness and claim policies IN THAT ORDER, so an unconditional hold always outranks a claim and callers never re-derive the precedence from the slug; the claim hold has two opt-outs (`allowStaleClaim` for reapers, `allowLiveClaim` for the dispatch side). `worktreeAgentId()` is separator-safe; `isHumanClaimWorktree()` and `isAgentWorktreeId()` make the protected namespaces explicit; `worktreeHoldExpiresAt()` names when a hold lapses on its own (the stale-claim window) so callers can wait exactly that long. `appWorktreeSlug(app)` is the per-app segment (`<name-slug>-<8 id chars>`) that claim prompts render INSIDE the `claim-` prefix — `data/cos/worktrees/` is one directory shared by every managed app, so a work-item-only name collides whenever two apps carry the same issue number or PLAN slug. || `xmlEntities.js` | Shared dependency-free XML/HTML entity decoder. `decodeXmlEntities(str, extraEntities?)` — single-pass (double-decode-safe) decode of the five predefined named entities + decimal/hex numeric refs, with an optional caller-supplied extra-entity map (e.g. `{ nbsp: ' ', zwnj: '' }`). Unknown/out-of-range refs left untouched. Used by the Apple Health XML parser, Claude changelog feed, Pinterest RSS, generic feeds, and Gmail HTML-to-text. |diff --git a/server/lib/worktreeNodeModules.js b/server/lib/worktreeNodeModules.jsindex 09bf957918..b5855470d6 100644--- a/server/lib/worktreeNodeModules.js+++ b/server/lib/worktreeNodeModules.js@@ -70,7 +70,7 @@ function workspaceLinkTarget(sourceRoot, worktreeRoot, { target, resolved }) {* lexically (no realpath) so a workspace package the branch deleted still* passes while a link escaping to the source checkout does not.*/-export async function assertLinkWithinWorktree(worktreeRoot, linkPath) {+async function assertLinkWithinWorktree(worktreeRoot, linkPath) {const resolved = await resolveLink(linkPath);if (!isInside(worktreeRoot, resolved)) {throw new Error(`Workspace link ${linkPath} resolves outside the worktree (${resolved})`);diff --git a/server/lib/worktreeNodeModules.test.js b/server/lib/worktreeNodeModules.test.jsindex 6b26ec3071..5f9755723d 100644--- a/server/lib/worktreeNodeModules.test.js+++ b/server/lib/worktreeNodeModules.test.js@@ -3,7 +3,6 @@ import { existsSync, lstatSync, mkdirSync, mkdtempSync, readdirSync, realpathSynimport { tmpdir } from 'os';import { join } from 'path';import {- assertLinkWithinWorktree,provisionWorkspaceNodeModules,removeProvisionedNodeModules,} from './worktreeNodeModules.js';@@ -35,13 +34,6 @@ describe('worktree node_modules provisioning', () => {expect(existsSync(join(root, 'worktree', 'node_modules'))).toBe(false);});- it('rejects a link that resolves outside the worktree', async () => {- const { source, worktree } = fixture();- mkdirSync(join(worktree, 'node_modules'));- symlinkSync(join(source, 'packages', 'core'), join(worktree, 'node_modules', 'escaped'), 'dir');- await expect(assertLinkWithinWorktree(worktree, join(worktree, 'node_modules', 'escaped'))).rejects.toThrow('outside the worktree');- });-it('removes only a provisioned directory, leaving a real install untouched', async () => {const { source, worktree } = fixture();expect(await provisionWorkspaceNodeModules(source, worktree)).toBe(true);