claude-code-session-manager 0.141.0 → 0.143.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +76 -153
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
- package/dist/assets/Scheduler-CNLjn90m.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/Toggle-CYajnSdx.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/index-CdTppjKR.js +3133 -0
- package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +496 -484
- package/package.json +6 -4
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/hooks/hooks.json +15 -0
- package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +2 -0
- package/scripts/hooks/guard-tool-risk.cjs +5 -1
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
- package/scripts/scheduler-mcp-server.cjs +1032 -112
- package/src/main/adminRouteRegistry.cjs +69 -0
- package/src/main/agentLibrary.cjs +72 -4
- package/src/main/agentsIpc.cjs +3 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +336 -23
- package/src/main/config.cjs +35 -1
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +129 -2
- package/src/main/index.cjs +110 -52
- package/src/main/ipcSchemas.cjs +172 -8
- package/src/main/lib/AGENTS.md +1 -1
- package/src/main/lib/chatBootRecovery.cjs +2 -0
- package/src/main/lib/claude/agentModelResolve.cjs +51 -25
- package/src/main/lib/claude/agentSnapshot.cjs +186 -0
- package/src/main/lib/claude/environmentProfiles.cjs +242 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
- package/src/main/lib/claude/personaToolScope.cjs +82 -31
- package/src/main/lib/claude/runClaudeP.cjs +4 -2
- package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
- package/src/main/lib/claude/usageCircuit.cjs +49 -21
- package/src/main/lib/claude/vaultRefs.cjs +277 -0
- package/src/main/lib/demo-video-kit/capture.cjs +282 -12
- package/src/main/lib/demo-video-kit/cast.md +52 -0
- package/src/main/lib/demo-video-kit/character.cjs +778 -30
- package/src/main/lib/demo-video-kit/checks.cjs +120 -1
- package/src/main/lib/demo-video-kit/export.cjs +218 -0
- package/src/main/lib/demo-video-kit/frames.cjs +104 -9
- package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
- package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
- package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
- package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
- package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
- package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
- package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
- package/src/main/lib/epic/artifactIpc.cjs +153 -0
- package/src/main/lib/epic/artifactNotice.cjs +72 -0
- package/src/main/lib/epic/artifactRetention.cjs +356 -0
- package/src/main/lib/epic/artifactStore.cjs +435 -0
- package/src/main/lib/epic/delegationReadiness.cjs +83 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +258 -0
- package/src/main/lib/epic/epicMint.cjs +43 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
- package/src/main/lib/epic/epicOutsideState.cjs +18 -4
- package/src/main/lib/epic/epicPurge.cjs +347 -0
- package/src/main/lib/epic/epicReopen.cjs +5 -2
- package/src/main/lib/epic/epicSettle.cjs +4 -13
- package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +94 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +48 -4
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
- package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
- package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
- package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
- package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
- package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
- package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
- package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
- package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
- package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
- package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
- package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
- package/src/main/lib/git/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +182 -4
- package/src/main/lib/mcpToolCatalog.cjs +399 -29
- package/src/main/lib/opsOwnership.cjs +141 -28
- package/src/main/lib/opsRetentionSettings.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
- package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
- package/src/main/lib/phaseProjection.cjs +103 -0
- package/src/main/lib/prd/depSlugResolve.cjs +4 -13
- package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
- package/src/main/lib/prd/prdCreate.cjs +387 -228
- package/src/main/lib/prd/prdCriteria.cjs +228 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
- package/src/main/lib/prd/prdGateFiles.cjs +125 -49
- package/src/main/lib/prd/prdSizing.cjs +3 -1
- package/src/main/lib/process/cleanEnv.cjs +52 -1
- package/src/main/lib/process/leftoverRenice.cjs +178 -0
- package/src/main/lib/process/memoryScope.cjs +31 -3
- package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
- package/src/main/lib/project-pages/voicePreview.cjs +196 -0
- package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
- package/src/main/lib/scheduler/cpuSample.cjs +133 -42
- package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
- package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
- package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
- package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
- package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
- package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
- package/src/main/lib/tasks/mitigationReview.cjs +314 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
- package/src/main/lib/tasks/taskIpc.cjs +22 -18
- package/src/main/lib/tasks/taskLedger.cjs +147 -25
- package/src/main/lib/tasks/taskRun.cjs +186 -17
- package/src/main/lib/tasks/taskSwitch.cjs +85 -12
- package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
- package/src/main/lib/telemetry/auditEvents.cjs +204 -6
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
- package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
- package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
- package/src/main/lib/toolUseClassify.cjs +181 -0
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +21 -1
- package/src/main/pty.cjs +77 -0
- package/src/main/queueOps.cjs +33 -14
- package/src/main/runVerify.cjs +74 -9
- package/src/main/scheduler/AGENTS.md +1 -0
- package/src/main/scheduler/budget.cjs +6 -5
- package/src/main/scheduler/prdParser.cjs +46 -13
- package/src/main/scheduler/reviewLadder.cjs +9 -25
- package/src/main/scheduler/utilizationHold.cjs +191 -0
- package/src/main/scheduler.cjs +1932 -213
- package/src/main/templates/PRD_AUTHORING.md +11 -3
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +576 -39
- package/src/preload/apiSurface.json +223 -7
- package/src/preload/index.cjs +48 -1
- package/src/seed/agents/architect.md +6 -1
- package/src/seed/agents/blender-artist.md +2 -1
- package/src/seed/agents/competitive-analyst.md +3 -1
- package/src/seed/agents/competitive-researcher.md +2 -1
- package/src/seed/agents/demo-video-builder.md +98 -87
- package/src/seed/agents/dev-lead.md +3 -3
- package/src/seed/agents/project-home-builder.md +9 -31
- package/src/seed/agents/validator.md +23 -23
- package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
- package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
- package/dist/assets/Scheduler-cyr61UAC.js +0 -16
- package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
- package/dist/assets/index-B2TQz3nd.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* worktreeDeps.cjs —
|
|
2
|
+
* worktreeDeps.cjs — link the main checkout's gitignored top-level
|
|
3
3
|
* dependency dirs (node_modules, .venv, venv) into a fresh worktree.
|
|
4
4
|
*
|
|
5
|
+
* node_modules is never linked whole: the worktree gets a REAL node_modules
|
|
6
|
+
* folder holding one symlink per entry of the main checkout's node_modules
|
|
7
|
+
* (packages, scope folders such as @types linked whole, and .bin; other dot
|
|
8
|
+
* entries — .vite, .cache, .package-lock.json — are not linked, so caches and
|
|
9
|
+
* npm's hidden lockfile stay worktree-local). Why: npm ci reads node_modules'
|
|
10
|
+
* entries and removes each one; through a whole-folder link that deletes the
|
|
11
|
+
* main checkout's packages (2026-11-24: a widget gate's
|
|
12
|
+
* `npm --prefix web/feedback-widget ci` emptied the main checkout's
|
|
13
|
+
* web/feedback-widget/node_modules). With per-entry links an install removes
|
|
14
|
+
* only links. .venv/venv keep the whole-folder link.
|
|
15
|
+
*
|
|
5
16
|
* `git worktree add` checks out tracked files only, so a job worktree has no
|
|
6
17
|
* dependencies and executors park needs_review. A gitignore pattern like
|
|
7
18
|
* `node_modules/` (trailing slash) matches directories only and a symlink is
|
|
@@ -36,7 +47,20 @@
|
|
|
36
47
|
* linked. If that sync fails the name is skipped and the executor's own `uv`
|
|
37
48
|
* call builds a worktree-local env — never the main one.
|
|
38
49
|
*
|
|
39
|
-
*
|
|
50
|
+
* Nested npm packages (e.g. web/remote-app) get the same treatment for their
|
|
51
|
+
* node_modules: for each TRACKED package.json whose dir is at most
|
|
52
|
+
* NESTED_MAX_DEPTH segments deep (never under node_modules), at most
|
|
53
|
+
* NESTED_MAX_PACKAGES of the eligible ones (main has `<dir>/node_modules`, it is
|
|
54
|
+
* gitignored there, the worktree has none — filtered before the cap), the dir is
|
|
55
|
+
* built from per-entry links to the main checkout's (as above) and `/<dir>/node_modules` goes to info/exclude
|
|
56
|
+
* after the link succeeds. Ineligible packages are not reported as skipped. pnpm projects skip this — their
|
|
57
|
+
* offline install already builds every workspace node_modules per worktree.
|
|
58
|
+
*
|
|
59
|
+
* syncNodeModulesLinks refreshes those per-entry links on a reused Epic worktree (the
|
|
60
|
+
* links are a snapshot; the old whole-folder link saw packages added to main later).
|
|
61
|
+
*
|
|
62
|
+
* Never throws; failures land in `skipped` (nested entries as `<rel> (<reason>)`);
|
|
63
|
+
* a failed node_modules build is removed again (links only, never their targets).
|
|
40
64
|
*/
|
|
41
65
|
'use strict';
|
|
42
66
|
|
|
@@ -47,6 +71,8 @@ const { execGit } = require('./gitExec.cjs');
|
|
|
47
71
|
const { runWorktreeSetup } = require('./worktreeSetup.cjs');
|
|
48
72
|
|
|
49
73
|
const DEFAULT_DEP_DIRS = ['node_modules', '.venv', 'venv'];
|
|
74
|
+
const NESTED_MAX_DEPTH = 3;
|
|
75
|
+
const NESTED_MAX_PACKAGES = 20;
|
|
50
76
|
|
|
51
77
|
function isDir(p) {
|
|
52
78
|
try { return fs.statSync(p).isDirectory(); } catch { return false; }
|
|
@@ -56,6 +82,49 @@ function exists(p) {
|
|
|
56
82
|
try { fs.lstatSync(p); return true; } catch { return false; }
|
|
57
83
|
}
|
|
58
84
|
|
|
85
|
+
/** True for a node_modules entry that gets a link: anything not dot-prefixed, plus `.bin`. */
|
|
86
|
+
function isLinkedModulesEntry(name) {
|
|
87
|
+
return !name.startsWith('.') || name === '.bin';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Link every linked entry of `src` (a main-checkout node_modules) that `dest` (a real
|
|
92
|
+
* worktree node_modules folder) lacks. Existing dest entries — links or real — are never
|
|
93
|
+
* touched. `strict` rethrows a symlink failure (initial build); otherwise failures are
|
|
94
|
+
* skipped per entry. Returns the count of links made.
|
|
95
|
+
*/
|
|
96
|
+
function linkMissingModulesEntries(src, dest, strict) {
|
|
97
|
+
let added = 0;
|
|
98
|
+
for (const e of fs.readdirSync(src, { withFileTypes: true })) {
|
|
99
|
+
if (!isLinkedModulesEntry(e.name)) continue;
|
|
100
|
+
const link = path.join(dest, e.name);
|
|
101
|
+
if (exists(link)) continue;
|
|
102
|
+
const target = path.join(src, e.name);
|
|
103
|
+
try {
|
|
104
|
+
fs.symlinkSync(target, link, isDir(target) ? 'dir' : 'file');
|
|
105
|
+
added++;
|
|
106
|
+
} catch (err) {
|
|
107
|
+
if (strict) throw err;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return added;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Create `dest` as a real directory holding one symlink per linked entry of `src` (a
|
|
115
|
+
* node_modules folder). Throws on failure after removing whatever it created at `dest`;
|
|
116
|
+
* removal unlinks links only — it never follows them into `src`.
|
|
117
|
+
*/
|
|
118
|
+
function linkModulesEntries(src, dest) {
|
|
119
|
+
fs.mkdirSync(dest);
|
|
120
|
+
try {
|
|
121
|
+
linkMissingModulesEntries(src, dest, true);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
try { fs.rmSync(dest, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
59
128
|
async function isIgnored(cwd, name) {
|
|
60
129
|
try {
|
|
61
130
|
await execGit(cwd, ['check-ignore', '-q', name], { timeout: 10_000 });
|
|
@@ -190,6 +259,69 @@ function addExcludes(mainCwd, names) {
|
|
|
190
259
|
return addExcludeLines(mainCwd, names.map((n) => `/${n}`));
|
|
191
260
|
}
|
|
192
261
|
|
|
262
|
+
/**
|
|
263
|
+
* Dirs (posix, relative) of tracked nested package.json files in worktreeCwd, at most
|
|
264
|
+
* NESTED_MAX_DEPTH segments deep and never under a node_modules segment. Sorted. Never throws.
|
|
265
|
+
*/
|
|
266
|
+
async function nestedPackageDirs(worktreeCwd) {
|
|
267
|
+
try {
|
|
268
|
+
const specs = [];
|
|
269
|
+
for (let d = 1; d <= NESTED_MAX_DEPTH; d++) specs.push(`:(glob)${'*/'.repeat(d)}package.json`);
|
|
270
|
+
const out = await execGit(worktreeCwd, ['ls-files', '-z', '--', ...specs], { timeout: 10_000 });
|
|
271
|
+
const dirs = new Set();
|
|
272
|
+
for (const f of out.split('\0')) {
|
|
273
|
+
if (!f) continue;
|
|
274
|
+
const segs = f.split('/').slice(0, -1);
|
|
275
|
+
if (!segs.length || segs.length > NESTED_MAX_DEPTH || segs.includes('node_modules')) continue;
|
|
276
|
+
dirs.add(segs.join('/'));
|
|
277
|
+
}
|
|
278
|
+
return [...dirs].sort();
|
|
279
|
+
} catch { return []; }
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Build `<dir>/node_modules` (per-entry links) for nested npm packages; pushes into linked/skipped. Never throws.
|
|
284
|
+
* Filter first (main has it, it is gitignored, the worktree has none), then cap at
|
|
285
|
+
* NESTED_MAX_PACKAGES, so ineligible packages never take a slot and never appear in
|
|
286
|
+
* `skipped`. `skipped` gets only eligible packages left unlinked, as `<rel> (<reason>)`.
|
|
287
|
+
* The info/exclude line is written only after the links succeed; if that write fails
|
|
288
|
+
* the folder of links is removed again so status stays clean.
|
|
289
|
+
*/
|
|
290
|
+
async function linkNestedNodeModules(mainCwd, worktreeCwd, linked, skipped) {
|
|
291
|
+
try {
|
|
292
|
+
if (isPnpmProject(mainCwd)) return;
|
|
293
|
+
const eligible = [];
|
|
294
|
+
for (const dir of await nestedPackageDirs(worktreeCwd)) {
|
|
295
|
+
const rel = `${dir}/node_modules`;
|
|
296
|
+
try {
|
|
297
|
+
if (!isDir(path.join(mainCwd, rel)) || exists(path.join(worktreeCwd, rel))) continue;
|
|
298
|
+
if (!(await isIgnored(mainCwd, rel))) continue;
|
|
299
|
+
eligible.push(rel);
|
|
300
|
+
} catch { /* ineligible */ }
|
|
301
|
+
}
|
|
302
|
+
for (const rel of eligible.slice(NESTED_MAX_PACKAGES)) {
|
|
303
|
+
skipped.push(`${rel} (over the ${NESTED_MAX_PACKAGES}-package cap)`);
|
|
304
|
+
}
|
|
305
|
+
for (const rel of eligible.slice(0, NESTED_MAX_PACKAGES)) {
|
|
306
|
+
const src = path.join(mainCwd, rel);
|
|
307
|
+
const dest = path.join(worktreeCwd, rel);
|
|
308
|
+
try {
|
|
309
|
+
linkModulesEntries(src, dest);
|
|
310
|
+
} catch (err) {
|
|
311
|
+
skipped.push(`${rel} (symlink failed: ${(err && err.code) || (err && err.message) || err})`);
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
await addExcludes(mainCwd, [rel]);
|
|
316
|
+
linked.push(rel);
|
|
317
|
+
} catch (err) {
|
|
318
|
+
try { fs.rmSync(dest, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
319
|
+
skipped.push(`${rel} (exclude write failed: ${(err && err.code) || (err && err.message) || err})`);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} catch { /* best-effort */ }
|
|
323
|
+
}
|
|
324
|
+
|
|
193
325
|
/**
|
|
194
326
|
* @param {{ mainCwd: string, worktreeCwd: string, names?: string[] }} opts
|
|
195
327
|
* @returns {Promise<{ linked: string[], skipped: string[], installed: string[], setup: object }>}
|
|
@@ -219,12 +351,14 @@ async function linkDependencyDirs({ mainCwd, worktreeCwd, names = DEFAULT_DEP_DI
|
|
|
219
351
|
}
|
|
220
352
|
// Exclude first: a link without its exclude line would dirty status.
|
|
221
353
|
await addExcludes(mainCwd, [name]);
|
|
222
|
-
|
|
354
|
+
if (name === 'node_modules') linkModulesEntries(src, dest);
|
|
355
|
+
else fs.symlinkSync(src, dest, 'dir');
|
|
223
356
|
linked.push(name);
|
|
224
357
|
} catch {
|
|
225
358
|
skipped.push(name);
|
|
226
359
|
}
|
|
227
360
|
}
|
|
361
|
+
if (names.includes('node_modules')) await linkNestedNodeModules(mainCwd, worktreeCwd, linked, skipped);
|
|
228
362
|
// Project warm-up (.session-manager.json worktreeSetup) runs after linking so it sees node_modules.
|
|
229
363
|
// Both createWorktree and the scheduler's verify scratch worktree come through here. mainCwd lets
|
|
230
364
|
// same-project setups serialize and reports a config missing from the worktree; the outcome is
|
|
@@ -238,4 +372,48 @@ async function linkDependencyDirs({ mainCwd, worktreeCwd, names = DEFAULT_DEP_DI
|
|
|
238
372
|
return { linked, skipped, installed, setup };
|
|
239
373
|
}
|
|
240
374
|
|
|
241
|
-
|
|
375
|
+
/**
|
|
376
|
+
* Refresh one worktree node_modules (`rel`) against the main checkout's: link entries main
|
|
377
|
+
* gained since the snapshot, unlink worktree links whose target is gone. Skips unless the
|
|
378
|
+
* worktree folder is a real directory (a whole-folder symlink is left alone). Reads main
|
|
379
|
+
* only. Never throws.
|
|
380
|
+
*/
|
|
381
|
+
function syncModulesDir(mainCwd, worktreeCwd, rel, counts) {
|
|
382
|
+
try {
|
|
383
|
+
const dest = path.join(worktreeCwd, rel);
|
|
384
|
+
const st = fs.lstatSync(dest);
|
|
385
|
+
if (st.isSymbolicLink() || !st.isDirectory()) return;
|
|
386
|
+
const src = path.join(mainCwd, rel);
|
|
387
|
+
if (isDir(src)) counts.added += linkMissingModulesEntries(src, dest, false);
|
|
388
|
+
for (const name of fs.readdirSync(dest)) {
|
|
389
|
+
const link = path.join(dest, name);
|
|
390
|
+
try {
|
|
391
|
+
if (!fs.lstatSync(link).isSymbolicLink() || fs.existsSync(link)) continue;
|
|
392
|
+
fs.unlinkSync(link); // removes the dangling link itself, never a target
|
|
393
|
+
counts.removed++;
|
|
394
|
+
} catch { /* best-effort per entry */ }
|
|
395
|
+
}
|
|
396
|
+
} catch { /* absent or unreadable */ }
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Bring a reused (long-lived Epic) worktree's per-entry node_modules links up to date with
|
|
401
|
+
* the main checkout — root plus each nested npm package (same set linkNestedNodeModules
|
|
402
|
+
* considers). pnpm projects are skipped (their worktree node_modules is a real install).
|
|
403
|
+
* No-op under SM_WORKTREE_DEP_LINK_DISABLE=1. Never throws.
|
|
404
|
+
* @param {{ mainCwd: string, worktreeCwd: string }} opts
|
|
405
|
+
* @returns {Promise<{ added: number, removed: number }>}
|
|
406
|
+
*/
|
|
407
|
+
async function syncNodeModulesLinks({ mainCwd, worktreeCwd }) {
|
|
408
|
+
const counts = { added: 0, removed: 0 };
|
|
409
|
+
try {
|
|
410
|
+
if (process.env.SM_WORKTREE_DEP_LINK_DISABLE === '1') return counts;
|
|
411
|
+
if (!mainCwd || !worktreeCwd || isPnpmProject(mainCwd)) return counts;
|
|
412
|
+
const rels = ['node_modules'];
|
|
413
|
+
for (const dir of await nestedPackageDirs(worktreeCwd)) rels.push(`${dir}/node_modules`);
|
|
414
|
+
for (const rel of rels) syncModulesDir(mainCwd, worktreeCwd, rel, counts);
|
|
415
|
+
} catch { /* best-effort */ }
|
|
416
|
+
return counts;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
module.exports = { linkDependencyDirs, syncNodeModulesLinks, isPnpmProject, isUvProject, DEFAULT_DEP_DIRS, NESTED_MAX_PACKAGES };
|