claude-code-session-manager 0.141.0 → 0.142.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/README.md +80 -70
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-DDunb8Ch.js} +1 -1
- package/dist/assets/index-Cn5E9958.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 +4 -2
- package/plugins/AGENTS.md +4 -3
- 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/develop/SKILL.md +52 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +1 -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 +732 -110
- package/src/main/adminRouteRegistry.cjs +59 -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 +231 -16
- package/src/main/config.cjs +30 -0
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +91 -0
- package/src/main/index.cjs +98 -48
- package/src/main/ipcSchemas.cjs +161 -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 +43 -0
- package/src/main/lib/demo-video-kit/character.cjs +722 -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 +99 -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/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- 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/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 +310 -0
- package/src/main/lib/epic/artifactStore.cjs +392 -0
- package/src/main/lib/epic/delegationReadiness.cjs +76 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +214 -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/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +81 -2
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +37 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
- 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 +2 -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 +189 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
- 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/worktreeDeps.cjs +77 -2
- package/src/main/lib/mcpToolCatalog.cjs +304 -28
- package/src/main/lib/opsOwnership.cjs +29 -1
- 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 +263 -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 +41 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -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/videoReviewIpc.cjs +3 -2
- 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 +169 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -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 +0 -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 +237 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
- package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
- package/src/main/lib/tasks/mitigationReview.cjs +294 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
- 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 +207 -6
- 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/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +5 -0
- package/src/main/pty.cjs +68 -0
- package/src/main/queueOps.cjs +32 -13
- 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 +101 -0
- package/src/main/scheduler.cjs +1414 -189
- package/src/main/templates/PRD_AUTHORING.md +5 -2
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +529 -38
- package/src/preload/apiSurface.json +209 -7
- package/src/preload/index.cjs +46 -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 +87 -83
- 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 +9 -10
- 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
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* siteFeedbackService — the ONE implementation of every website-feedback widget setting and
|
|
4
|
+
* inbox action. The desktop UI (IPC) and the Feedback MCP (admin routes) both call these
|
|
5
|
+
* functions, so the two can never disagree. Data path:
|
|
6
|
+
* session-manager-operations/architecture/site-feedback.md.
|
|
7
|
+
*
|
|
8
|
+
* Widgets (sealed drop boxes on the bilko.run relay):
|
|
9
|
+
* createWidget / listWidgets / updateWidget / deleteWidget / getSnippet
|
|
10
|
+
* - createWidget generates the box key pair (feedbackSeal), registers the box on the relay
|
|
11
|
+
* (feedbackRelayClient) and only then stores the private key (feedbackBoxKeys).
|
|
12
|
+
* - Relay error codes are passed through verbatim as `error`, with a one-line `message`.
|
|
13
|
+
* getIdentitySecret / rotateIdentitySecret — the box's reporter-signing HMAC secret, local
|
|
14
|
+
* keystore only (never the relay, never the widget); the site owner pastes it into their backend.
|
|
15
|
+
* Inbox (decrypted reports in <project>/session-manager-operations/feedback-inbox/):
|
|
16
|
+
* listItems / getItem / getImage / setStatus / linkEpic delegate to siteFeedbackInbox;
|
|
17
|
+
* drainNow / startDrainLoop delegate to feedbackBoxDrain.
|
|
18
|
+
*
|
|
19
|
+
* Every function resolves `{ ok: true, ... }` or `{ ok: false, error, message }` and never
|
|
20
|
+
* throws. Nothing here logs report text, image bytes, a private key or the device token.
|
|
21
|
+
*/
|
|
22
|
+
'use strict';
|
|
23
|
+
|
|
24
|
+
const fsp = require('node:fs/promises');
|
|
25
|
+
|
|
26
|
+
const WIDGET_SCRIPT_URL = 'https://bilko.run/projects/session-manager/widget/v1/feedback.js';
|
|
27
|
+
const KEY_PREFIX = 'fbk1_';
|
|
28
|
+
const MAX_ORIGINS = 10;
|
|
29
|
+
const MAX_LABEL = 80;
|
|
30
|
+
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
31
|
+
const GONE_HINT = 'This widget no longer exists on bilko.run - create a new one';
|
|
32
|
+
|
|
33
|
+
/** One-line human explanations for the relay codes the UI and MCP pass through verbatim. */
|
|
34
|
+
const RELAY_ERROR_MESSAGES = Object.freeze({
|
|
35
|
+
not_linked: 'This desktop is not paired with bilko.run yet - pair it in App Settings > Phone remote first',
|
|
36
|
+
not_enabled: 'Website feedback is not enabled for this bilko.run account yet',
|
|
37
|
+
box_limit_reached: 'This bilko.run account already has the most feedback widgets it may have - delete one first',
|
|
38
|
+
device_token_required: 'Only the paired desktop can do this - the request did not carry its device token',
|
|
39
|
+
rate_limited: 'bilko.run is rate limiting these requests - wait a minute and try again',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @typedef {{ ok: false, error: string, message: string, status?: number, retryAfterSec?: number }} Failure
|
|
44
|
+
* @typedef {{ ok: false, status: number, error: string, retryAfterSec?: number }} RelayFailure
|
|
45
|
+
* @typedef {{ boxId: string, label?: string, allowedOrigins?: string[], state?: string, pending?: number }} RelayBox
|
|
46
|
+
* @typedef {{
|
|
47
|
+
* createBox: (input: { label: string, publicKey: string, allowedOrigins: string[] }) => Promise<{ ok: true, boxId: string, state?: string, createdAt?: string } | RelayFailure>,
|
|
48
|
+
* listBoxes: () => Promise<{ ok: true, boxes: RelayBox[] } | RelayFailure>,
|
|
49
|
+
* patchBox: (boxId: string, patch: { label?: string, allowedOrigins?: string[], state?: 'open'|'paused' }) => Promise<{ ok: true, box: RelayBox } | RelayFailure>,
|
|
50
|
+
* deleteBox: (boxId: string) => Promise<{ ok: true } | RelayFailure>,
|
|
51
|
+
* listEnvelopes: (boxId: string, limit?: number) => Promise<any>,
|
|
52
|
+
* getEnvelope: (boxId: string, envelopeId: string) => Promise<any>,
|
|
53
|
+
* ackEnvelope: (boxId: string, envelopeId: string) => Promise<any>,
|
|
54
|
+
* }} ServiceRelay
|
|
55
|
+
* @typedef {import('./feedbackBoxKeys.cjs')} ServiceKeystore
|
|
56
|
+
* @typedef {import('./siteFeedbackInbox.cjs')} ServiceInbox
|
|
57
|
+
* @typedef {'open'|'in_progress'|'resolved'|'wontfix'} InboxStatus
|
|
58
|
+
* @typedef {{ drainOnce: (deps?: any) => Promise<any>, startDrainLoop: (opts?: any) => { drainNow: () => Promise<any>, stop: () => void } }} ServiceDrain
|
|
59
|
+
* @typedef {{ relay?: ServiceRelay, keystore?: ServiceKeystore, inbox?: ServiceInbox, drain?: ServiceDrain,
|
|
60
|
+
* seal?: { generateBoxKeypair: () => { publicKey: string, privateKeyJwk: object }, keyFingerprint: (pk: string) => string } }} ServiceDeps
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} error
|
|
65
|
+
* @param {string} [message]
|
|
66
|
+
* @returns {Failure}
|
|
67
|
+
*/
|
|
68
|
+
function failure(error, message) {
|
|
69
|
+
return { ok: false, error, message: message || RELAY_ERROR_MESSAGES[/** @type {keyof typeof RELAY_ERROR_MESSAGES} */ (error)] || `bilko.run refused the request (${error})` };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A relay failure passed through verbatim, with its one-line explanation.
|
|
74
|
+
* @param {RelayFailure} r
|
|
75
|
+
* @returns {Failure}
|
|
76
|
+
*/
|
|
77
|
+
function relayFailure(r) {
|
|
78
|
+
/** @type {Failure} */
|
|
79
|
+
const out = { ...failure(r.error), status: r.status };
|
|
80
|
+
return typeof r.retryAfterSec === 'number' ? { ...out, retryAfterSec: r.retryAfterSec } : out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @param {unknown} e */
|
|
84
|
+
function errMessage(e) {
|
|
85
|
+
return e instanceof Error ? e.message : String(e);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @param {unknown} v @returns {v is string} */
|
|
89
|
+
function nonEmpty(v) {
|
|
90
|
+
return typeof v === 'string' && v.length > 0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Normalise each origin to new URL(o).origin and drop duplicates. Only https:, or
|
|
95
|
+
* http://localhost / http://127.0.0.1, and 1-10 entries.
|
|
96
|
+
* @param {unknown} origins
|
|
97
|
+
* @returns {{ ok: true, origins: string[] } | Failure}
|
|
98
|
+
*/
|
|
99
|
+
function normalizeOrigins(origins) {
|
|
100
|
+
if (!Array.isArray(origins)) return failure('invalid_allowed_origins', 'allowedOrigins must be a list of 1-10 origins');
|
|
101
|
+
/** @type {string[]} */
|
|
102
|
+
const out = [];
|
|
103
|
+
for (const o of origins) {
|
|
104
|
+
if (typeof o !== 'string') return failure('invalid_allowed_origins', 'Every allowed origin must be a string');
|
|
105
|
+
/** @type {URL} */
|
|
106
|
+
let url;
|
|
107
|
+
try {
|
|
108
|
+
url = new URL(o.trim());
|
|
109
|
+
} catch {
|
|
110
|
+
return failure('invalid_allowed_origins', `Not a valid origin: ${o.slice(0, 200)}`);
|
|
111
|
+
}
|
|
112
|
+
const ok = url.protocol === 'https:'
|
|
113
|
+
|| (url.protocol === 'http:' && (url.hostname === 'localhost' || url.hostname === '127.0.0.1'));
|
|
114
|
+
if (!ok) {
|
|
115
|
+
return failure('invalid_allowed_origins', `Origin must be https, or http://localhost / http://127.0.0.1: ${o.slice(0, 200)}`);
|
|
116
|
+
}
|
|
117
|
+
if (!out.includes(url.origin)) out.push(url.origin);
|
|
118
|
+
}
|
|
119
|
+
if (out.length < 1 || out.length > MAX_ORIGINS) {
|
|
120
|
+
return failure('invalid_allowed_origins', `allowedOrigins must hold 1-${MAX_ORIGINS} distinct origins`);
|
|
121
|
+
}
|
|
122
|
+
return { ok: true, origins: out };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @param {unknown} label @returns {{ ok: true, label: string } | Failure} */
|
|
126
|
+
function normalizeLabel(label) {
|
|
127
|
+
const s = typeof label === 'string' ? label.trim() : '';
|
|
128
|
+
if (s.length < 1 || s.length > MAX_LABEL) return failure('invalid_label', `label must be 1-${MAX_LABEL} characters`);
|
|
129
|
+
return { ok: true, label: s };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The one-line embed for a box.
|
|
134
|
+
* @param {string} boxId
|
|
135
|
+
* @param {string} fingerprint
|
|
136
|
+
*/
|
|
137
|
+
function snippetFor(boxId, fingerprint) {
|
|
138
|
+
return `<script src="${WIDGET_SCRIPT_URL}" data-key="${KEY_PREFIX}${boxId}.${fingerprint}" async></script>`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** @returns {ServiceRelay} */
|
|
142
|
+
function defaultRelay() {
|
|
143
|
+
const { createRelayClient } = require('./feedbackRelayClient.cjs');
|
|
144
|
+
return createRelayClient({
|
|
145
|
+
getDeviceToken: () => require('../../webRemote.cjs').getLinkedDeviceToken(),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* A service instance. Every dependency is injectable (tests); the defaults are the real
|
|
151
|
+
* relay client (paired device token), keystore, inbox and drain.
|
|
152
|
+
* @param {ServiceDeps} [deps]
|
|
153
|
+
*/
|
|
154
|
+
function createSiteFeedbackService(deps = {}) {
|
|
155
|
+
/** @type {ServiceRelay | null} */
|
|
156
|
+
let lazyRelay = deps.relay || null;
|
|
157
|
+
const relay = () => (lazyRelay = lazyRelay || defaultRelay());
|
|
158
|
+
const keystore = () => deps.keystore || require('./feedbackBoxKeys.cjs');
|
|
159
|
+
const inbox = () => deps.inbox || require('./siteFeedbackInbox.cjs');
|
|
160
|
+
const drain = () => deps.drain || require('./feedbackBoxDrain.cjs');
|
|
161
|
+
const seal = () => deps.seal || require('./feedbackSeal.cjs');
|
|
162
|
+
const drainDeps = () => ({ relay: relay(), keystore: keystore(), inbox: inbox() });
|
|
163
|
+
/** @type {{ drainNow: () => Promise<any>, stop: () => void } | null} */
|
|
164
|
+
let loop = null;
|
|
165
|
+
|
|
166
|
+
/** @param {string} boxId */
|
|
167
|
+
async function localBox(boxId) {
|
|
168
|
+
const all = await keystore().listBoxes();
|
|
169
|
+
return all.find((b) => b.boxId === boxId) || null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* @param {{ cwd: string, label: string, allowedOrigins: string[] }} p
|
|
174
|
+
*/
|
|
175
|
+
async function createWidget(p) {
|
|
176
|
+
const { cwd, label, allowedOrigins } = p || /** @type {any} */ ({});
|
|
177
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
178
|
+
const l = normalizeLabel(label);
|
|
179
|
+
if (!l.ok) return l;
|
|
180
|
+
const o = normalizeOrigins(allowedOrigins);
|
|
181
|
+
if (!o.ok) return o;
|
|
182
|
+
try {
|
|
183
|
+
const kp = seal().generateBoxKeypair();
|
|
184
|
+
const fingerprint = seal().keyFingerprint(kp.publicKey);
|
|
185
|
+
const created = await relay().createBox({ label: l.label, publicKey: kp.publicKey, allowedOrigins: o.origins });
|
|
186
|
+
if (!created.ok) return relayFailure(created);
|
|
187
|
+
try {
|
|
188
|
+
await keystore().addBox({
|
|
189
|
+
boxId: created.boxId, projectCwd: cwd, label: l.label, publicKey: kp.publicKey,
|
|
190
|
+
fingerprint, privateKeyJwk: /** @type {Record<string, unknown>} */ (kp.privateKeyJwk),
|
|
191
|
+
});
|
|
192
|
+
} catch (e) {
|
|
193
|
+
// Without its private key the box could never be opened: take it back off the relay.
|
|
194
|
+
await relay().deleteBox(created.boxId).catch(() => {});
|
|
195
|
+
return failure('keystore_failed', `The widget key could not be saved: ${errMessage(e)}`);
|
|
196
|
+
}
|
|
197
|
+
return { ok: /** @type {const} */ (true), boxId: created.boxId, fingerprint, snippet: snippetFor(created.boxId, fingerprint) };
|
|
198
|
+
} catch (e) {
|
|
199
|
+
return failure('internal', errMessage(e));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Local records merged with relay state. A local box the relay no longer lists is 'gone'.
|
|
205
|
+
* When the relay cannot be read, widgets carry state 'unknown' and `relayError` says why.
|
|
206
|
+
* @param {{ cwd?: string }} [p]
|
|
207
|
+
*/
|
|
208
|
+
async function listWidgets(p = {}) {
|
|
209
|
+
try {
|
|
210
|
+
const cwd = p && nonEmpty(p.cwd) ? p.cwd : undefined;
|
|
211
|
+
const local = await keystore().listBoxes(cwd ? { projectCwd: cwd } : undefined);
|
|
212
|
+
const remote = await relay().listBoxes();
|
|
213
|
+
/** @type {Map<string, RelayBox>} */
|
|
214
|
+
const byId = new Map();
|
|
215
|
+
if (remote.ok) for (const b of remote.boxes) if (b && nonEmpty(b.boxId)) byId.set(b.boxId, b);
|
|
216
|
+
const widgets = local.map((b) => {
|
|
217
|
+
const r = byId.get(b.boxId);
|
|
218
|
+
const base = {
|
|
219
|
+
boxId: b.boxId,
|
|
220
|
+
projectCwd: b.projectCwd,
|
|
221
|
+
fingerprint: b.fingerprint,
|
|
222
|
+
createdAt: b.createdAt,
|
|
223
|
+
snippet: snippetFor(b.boxId, b.fingerprint),
|
|
224
|
+
};
|
|
225
|
+
if (!remote.ok) {
|
|
226
|
+
return { ...base, label: b.label, allowedOrigins: /** @type {string[]} */ ([]), state: 'unknown', pending: null, hint: null };
|
|
227
|
+
}
|
|
228
|
+
if (!r) {
|
|
229
|
+
return { ...base, label: b.label, allowedOrigins: /** @type {string[]} */ ([]), state: 'gone', pending: 0, hint: GONE_HINT };
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
...base,
|
|
233
|
+
label: typeof r.label === 'string' ? r.label : b.label,
|
|
234
|
+
allowedOrigins: Array.isArray(r.allowedOrigins) ? r.allowedOrigins : [],
|
|
235
|
+
state: typeof r.state === 'string' ? r.state : 'unknown',
|
|
236
|
+
pending: typeof r.pending === 'number' ? r.pending : 0,
|
|
237
|
+
hint: null,
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
return remote.ok
|
|
241
|
+
? { ok: /** @type {const} */ (true), widgets }
|
|
242
|
+
: { ok: /** @type {const} */ (true), widgets, relayError: relayFailure(remote) };
|
|
243
|
+
} catch (e) {
|
|
244
|
+
return failure('internal', errMessage(e));
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* @param {{ boxId: string, label?: string, allowedOrigins?: string[], state?: 'open'|'paused' }} p
|
|
250
|
+
*/
|
|
251
|
+
async function updateWidget(p) {
|
|
252
|
+
const { boxId, label, allowedOrigins, state } = p || /** @type {any} */ ({});
|
|
253
|
+
if (!nonEmpty(boxId)) return failure('invalid_input', 'boxId is required');
|
|
254
|
+
/** @type {{ label?: string, allowedOrigins?: string[], state?: 'open'|'paused' }} */
|
|
255
|
+
const patch = {};
|
|
256
|
+
if (label !== undefined) {
|
|
257
|
+
const l = normalizeLabel(label);
|
|
258
|
+
if (!l.ok) return l;
|
|
259
|
+
patch.label = l.label;
|
|
260
|
+
}
|
|
261
|
+
if (allowedOrigins !== undefined) {
|
|
262
|
+
const o = normalizeOrigins(allowedOrigins);
|
|
263
|
+
if (!o.ok) return o;
|
|
264
|
+
patch.allowedOrigins = o.origins;
|
|
265
|
+
}
|
|
266
|
+
if (state !== undefined) {
|
|
267
|
+
if (state !== 'open' && state !== 'paused') return failure('invalid_state', "state must be 'open' or 'paused'");
|
|
268
|
+
patch.state = state;
|
|
269
|
+
}
|
|
270
|
+
if (Object.keys(patch).length === 0) return failure('invalid_input', 'Nothing to update: give label, allowedOrigins or state');
|
|
271
|
+
try {
|
|
272
|
+
if (!(await localBox(boxId))) return failure('not_found', `No widget ${boxId} on this desktop`);
|
|
273
|
+
const r = await relay().patchBox(boxId, patch);
|
|
274
|
+
if (!r.ok) {
|
|
275
|
+
if (r.status === 404 && r.error === 'box_not_found') return { ...relayFailure(r), message: GONE_HINT };
|
|
276
|
+
return relayFailure(r);
|
|
277
|
+
}
|
|
278
|
+
const b = r.box || /** @type {RelayBox} */ ({ boxId });
|
|
279
|
+
return {
|
|
280
|
+
ok: /** @type {const} */ (true),
|
|
281
|
+
widget: { boxId, label: b.label, allowedOrigins: b.allowedOrigins, state: b.state, pending: b.pending },
|
|
282
|
+
};
|
|
283
|
+
} catch (e) {
|
|
284
|
+
return failure('internal', errMessage(e));
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Deletes on the relay, then locally. A box the relay no longer has is removed locally too.
|
|
290
|
+
* @param {{ boxId: string }} p
|
|
291
|
+
*/
|
|
292
|
+
async function deleteWidget(p) {
|
|
293
|
+
const boxId = p && p.boxId;
|
|
294
|
+
if (!nonEmpty(boxId)) return failure('invalid_input', 'boxId is required');
|
|
295
|
+
try {
|
|
296
|
+
if (!(await localBox(boxId))) return failure('not_found', `No widget ${boxId} on this desktop`);
|
|
297
|
+
const r = await relay().deleteBox(boxId);
|
|
298
|
+
if (!r.ok && !(r.status === 404 && r.error === 'box_not_found')) return relayFailure(r);
|
|
299
|
+
await keystore().removeBox(boxId);
|
|
300
|
+
return { ok: /** @type {const} */ (true), boxId };
|
|
301
|
+
} catch (e) {
|
|
302
|
+
return failure('internal', errMessage(e));
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** @param {{ boxId: string }} p */
|
|
307
|
+
async function getSnippet(p) {
|
|
308
|
+
const boxId = p && p.boxId;
|
|
309
|
+
if (!nonEmpty(boxId)) return failure('invalid_input', 'boxId is required');
|
|
310
|
+
try {
|
|
311
|
+
const b = await localBox(boxId);
|
|
312
|
+
if (!b) return failure('not_found', `No widget ${boxId} on this desktop`);
|
|
313
|
+
return { ok: /** @type {const} */ (true), boxId, fingerprint: b.fingerprint, snippet: snippetFor(boxId, b.fingerprint) };
|
|
314
|
+
} catch (e) {
|
|
315
|
+
return failure('internal', errMessage(e));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* @param {string | { boxId: string }} p
|
|
321
|
+
* @param {boolean} rotate
|
|
322
|
+
*/
|
|
323
|
+
async function identitySecret(p, rotate) {
|
|
324
|
+
const boxId = typeof p === 'string' ? p : p && p.boxId;
|
|
325
|
+
if (!nonEmpty(boxId)) return failure('invalid_input', 'boxId is required');
|
|
326
|
+
try {
|
|
327
|
+
if (!(await localBox(boxId))) return failure('not_found', `No widget ${boxId} on this desktop`);
|
|
328
|
+
const ks = keystore();
|
|
329
|
+
const secret = rotate ? await ks.rotateIdentitySecret(boxId) : await ks.getIdentitySecret(boxId);
|
|
330
|
+
if (!secret) return failure('not_found', `No widget ${boxId} on this desktop`);
|
|
331
|
+
return { ok: /** @type {const} */ (true), boxId, identitySecret: secret };
|
|
332
|
+
} catch (e) {
|
|
333
|
+
return failure('internal', errMessage(e));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The box's reporter-signing secret, created on first request. Never logged, never sent to
|
|
339
|
+
* the relay; only the desktop UI asks for it, on an explicit user action.
|
|
340
|
+
* @param {string | { boxId: string }} p
|
|
341
|
+
*/
|
|
342
|
+
function getIdentitySecret(p) {
|
|
343
|
+
return identitySecret(p, false);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Replace the box's reporter-signing secret. @param {string | { boxId: string }} p */
|
|
347
|
+
function rotateIdentitySecret(p) {
|
|
348
|
+
return identitySecret(p, true);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/** @param {{ cwd: string, status?: InboxStatus }} p */
|
|
352
|
+
async function listItems(p) {
|
|
353
|
+
const { cwd, status } = p || /** @type {any} */ ({});
|
|
354
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
355
|
+
try {
|
|
356
|
+
return { ok: /** @type {const} */ (true), items: await inbox().list(cwd, status ? { status } : {}) };
|
|
357
|
+
} catch (e) {
|
|
358
|
+
return failure('invalid_input', errMessage(e));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** @param {{ cwd: string, hostId: string }} p */
|
|
363
|
+
async function getItem(p) {
|
|
364
|
+
const { cwd, hostId } = p || /** @type {any} */ ({});
|
|
365
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
366
|
+
try {
|
|
367
|
+
const item = await inbox().get(cwd, hostId);
|
|
368
|
+
if (!item) return failure('not_found', `No feedback item ${hostId}`);
|
|
369
|
+
return { ok: /** @type {const} */ (true), item };
|
|
370
|
+
} catch (e) {
|
|
371
|
+
return failure('invalid_input', errMessage(e));
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* One stored image as a data URL, only after its bytes sniff as PNG.
|
|
377
|
+
* @param {{ cwd: string, hostId: string, which?: 'screenshot'|'annotated' }} p
|
|
378
|
+
*/
|
|
379
|
+
async function getImage(p) {
|
|
380
|
+
const { cwd, hostId, which = 'annotated' } = p || /** @type {any} */ ({});
|
|
381
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
382
|
+
if (which !== 'screenshot' && which !== 'annotated') return failure('invalid_input', "which must be 'screenshot' or 'annotated'");
|
|
383
|
+
try {
|
|
384
|
+
const item = await inbox().get(cwd, hostId);
|
|
385
|
+
if (!item) return failure('not_found', `No feedback item ${hostId}`);
|
|
386
|
+
const file = item.imagePaths[/** @type {'screenshot'|'annotated'} */ (which)];
|
|
387
|
+
if (!file) return failure('not_found', `Feedback item ${hostId} has no ${which} image`);
|
|
388
|
+
const buf = await fsp.readFile(file);
|
|
389
|
+
if (buf.length < PNG_SIGNATURE.length || !buf.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE)) {
|
|
390
|
+
return failure('not_png', `The stored ${which} image is not a PNG`);
|
|
391
|
+
}
|
|
392
|
+
return { ok: /** @type {const} */ (true), hostId, which, dataUrl: `data:image/png;base64,${buf.toString('base64')}` };
|
|
393
|
+
} catch (e) {
|
|
394
|
+
return failure('invalid_input', errMessage(e));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/** @param {{ cwd: string, hostId: string, status: InboxStatus, note?: string | null }} p */
|
|
399
|
+
async function setStatus(p) {
|
|
400
|
+
const { cwd, hostId, status, note } = p || /** @type {any} */ ({});
|
|
401
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
402
|
+
try {
|
|
403
|
+
return { ok: /** @type {const} */ (true), meta: await inbox().setStatus(cwd, hostId, status, note ?? null) };
|
|
404
|
+
} catch (e) {
|
|
405
|
+
const msg = errMessage(e);
|
|
406
|
+
return failure(/no item/.test(msg) ? 'not_found' : 'invalid_input', msg);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** @param {{ cwd: string, hostId: string, epicId: string }} p */
|
|
411
|
+
async function linkEpic(p) {
|
|
412
|
+
const { cwd, hostId, epicId } = p || /** @type {any} */ ({});
|
|
413
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
414
|
+
try {
|
|
415
|
+
return { ok: /** @type {const} */ (true), meta: await inbox().linkEpic(cwd, hostId, epicId) };
|
|
416
|
+
} catch (e) {
|
|
417
|
+
const msg = errMessage(e);
|
|
418
|
+
return failure(/no item/.test(msg) ? 'not_found' : 'invalid_input', msg);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/** Delete one stored item (its report, images and meta). @param {{ cwd: string, hostId: string }} p */
|
|
423
|
+
async function removeItem(p) {
|
|
424
|
+
const { cwd, hostId } = p || /** @type {any} */ ({});
|
|
425
|
+
if (!nonEmpty(cwd)) return failure('invalid_input', 'cwd is required');
|
|
426
|
+
try {
|
|
427
|
+
const r = await inbox().remove(cwd, hostId);
|
|
428
|
+
if (!r.removed) return failure('not_found', `No feedback item ${hostId}`);
|
|
429
|
+
return { ok: /** @type {const} */ (true), hostId };
|
|
430
|
+
} catch (e) {
|
|
431
|
+
return failure('invalid_input', errMessage(e));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** One drain pass now (shares a pass already running). */
|
|
436
|
+
async function drainNow() {
|
|
437
|
+
try {
|
|
438
|
+
const result = loop ? await loop.drainNow() : await drain().drainOnce(drainDeps());
|
|
439
|
+
return { ok: /** @type {const} */ (true), ...result };
|
|
440
|
+
} catch (e) {
|
|
441
|
+
return failure('internal', errMessage(e));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Start the periodic drain once (idempotent).
|
|
447
|
+
* @param {{ intervalMs?: number }} [opts]
|
|
448
|
+
*/
|
|
449
|
+
function startDrainLoop(opts = {}) {
|
|
450
|
+
if (!loop) loop = drain().startDrainLoop({ ...drainDeps(), ...(opts || {}) });
|
|
451
|
+
return loop;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function stopDrainLoop() {
|
|
455
|
+
if (loop) loop.stop();
|
|
456
|
+
loop = null;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return {
|
|
460
|
+
createWidget, listWidgets, updateWidget, deleteWidget, getSnippet,
|
|
461
|
+
getIdentitySecret, rotateIdentitySecret,
|
|
462
|
+
listItems, getItem, getImage, setStatus, linkEpic, removeItem, drainNow,
|
|
463
|
+
startDrainLoop, stopDrainLoop,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const defaultService = createSiteFeedbackService();
|
|
468
|
+
|
|
469
|
+
module.exports = {
|
|
470
|
+
...defaultService,
|
|
471
|
+
createSiteFeedbackService,
|
|
472
|
+
normalizeOrigins,
|
|
473
|
+
snippetFor,
|
|
474
|
+
RELAY_ERROR_MESSAGES,
|
|
475
|
+
GONE_HINT,
|
|
476
|
+
WIDGET_SCRIPT_URL,
|
|
477
|
+
};
|
|
@@ -36,7 +36,16 @@
|
|
|
36
36
|
* linked. If that sync fails the name is skipped and the executor's own `uv`
|
|
37
37
|
* call builds a worktree-local env — never the main one.
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* Nested npm packages (e.g. web/remote-app) get the same treatment for their
|
|
40
|
+
* node_modules: for each TRACKED package.json whose dir is at most
|
|
41
|
+
* NESTED_MAX_DEPTH segments deep (never under node_modules), at most
|
|
42
|
+
* NESTED_MAX_PACKAGES of the eligible ones (main has `<dir>/node_modules`, it is
|
|
43
|
+
* gitignored there, the worktree has none — filtered before the cap), the dir is
|
|
44
|
+
* linked from the main checkout and `/<dir>/node_modules` goes to info/exclude
|
|
45
|
+
* after the link succeeds. Ineligible packages are not reported as skipped. pnpm projects skip this — their
|
|
46
|
+
* offline install already builds every workspace node_modules per worktree.
|
|
47
|
+
*
|
|
48
|
+
* Never throws; failures land in `skipped` (nested entries as `<rel> (<reason>)`).
|
|
40
49
|
*/
|
|
41
50
|
'use strict';
|
|
42
51
|
|
|
@@ -47,6 +56,8 @@ const { execGit } = require('./gitExec.cjs');
|
|
|
47
56
|
const { runWorktreeSetup } = require('./worktreeSetup.cjs');
|
|
48
57
|
|
|
49
58
|
const DEFAULT_DEP_DIRS = ['node_modules', '.venv', 'venv'];
|
|
59
|
+
const NESTED_MAX_DEPTH = 3;
|
|
60
|
+
const NESTED_MAX_PACKAGES = 20;
|
|
50
61
|
|
|
51
62
|
function isDir(p) {
|
|
52
63
|
try { return fs.statSync(p).isDirectory(); } catch { return false; }
|
|
@@ -190,6 +201,69 @@ function addExcludes(mainCwd, names) {
|
|
|
190
201
|
return addExcludeLines(mainCwd, names.map((n) => `/${n}`));
|
|
191
202
|
}
|
|
192
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Dirs (posix, relative) of tracked nested package.json files in worktreeCwd, at most
|
|
206
|
+
* NESTED_MAX_DEPTH segments deep and never under a node_modules segment. Sorted. Never throws.
|
|
207
|
+
*/
|
|
208
|
+
async function nestedPackageDirs(worktreeCwd) {
|
|
209
|
+
try {
|
|
210
|
+
const specs = [];
|
|
211
|
+
for (let d = 1; d <= NESTED_MAX_DEPTH; d++) specs.push(`:(glob)${'*/'.repeat(d)}package.json`);
|
|
212
|
+
const out = await execGit(worktreeCwd, ['ls-files', '-z', '--', ...specs], { timeout: 10_000 });
|
|
213
|
+
const dirs = new Set();
|
|
214
|
+
for (const f of out.split('\0')) {
|
|
215
|
+
if (!f) continue;
|
|
216
|
+
const segs = f.split('/').slice(0, -1);
|
|
217
|
+
if (!segs.length || segs.length > NESTED_MAX_DEPTH || segs.includes('node_modules')) continue;
|
|
218
|
+
dirs.add(segs.join('/'));
|
|
219
|
+
}
|
|
220
|
+
return [...dirs].sort();
|
|
221
|
+
} catch { return []; }
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Link `<dir>/node_modules` for nested npm packages; pushes into linked/skipped. Never throws.
|
|
226
|
+
* Filter first (main has it, it is gitignored, the worktree has none), then cap at
|
|
227
|
+
* NESTED_MAX_PACKAGES, so ineligible packages never take a slot and never appear in
|
|
228
|
+
* `skipped`. `skipped` gets only eligible packages left unlinked, as `<rel> (<reason>)`.
|
|
229
|
+
* The info/exclude line is written only after the symlink succeeds; if that write fails
|
|
230
|
+
* the link is removed again so status stays clean.
|
|
231
|
+
*/
|
|
232
|
+
async function linkNestedNodeModules(mainCwd, worktreeCwd, linked, skipped) {
|
|
233
|
+
try {
|
|
234
|
+
if (isPnpmProject(mainCwd)) return;
|
|
235
|
+
const eligible = [];
|
|
236
|
+
for (const dir of await nestedPackageDirs(worktreeCwd)) {
|
|
237
|
+
const rel = `${dir}/node_modules`;
|
|
238
|
+
try {
|
|
239
|
+
if (!isDir(path.join(mainCwd, rel)) || exists(path.join(worktreeCwd, rel))) continue;
|
|
240
|
+
if (!(await isIgnored(mainCwd, rel))) continue;
|
|
241
|
+
eligible.push(rel);
|
|
242
|
+
} catch { /* ineligible */ }
|
|
243
|
+
}
|
|
244
|
+
for (const rel of eligible.slice(NESTED_MAX_PACKAGES)) {
|
|
245
|
+
skipped.push(`${rel} (over the ${NESTED_MAX_PACKAGES}-package cap)`);
|
|
246
|
+
}
|
|
247
|
+
for (const rel of eligible.slice(0, NESTED_MAX_PACKAGES)) {
|
|
248
|
+
const src = path.join(mainCwd, rel);
|
|
249
|
+
const dest = path.join(worktreeCwd, rel);
|
|
250
|
+
try {
|
|
251
|
+
fs.symlinkSync(src, dest, 'dir');
|
|
252
|
+
} catch (err) {
|
|
253
|
+
skipped.push(`${rel} (symlink failed: ${(err && err.code) || (err && err.message) || err})`);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
await addExcludes(mainCwd, [rel]);
|
|
258
|
+
linked.push(rel);
|
|
259
|
+
} catch (err) {
|
|
260
|
+
try { fs.unlinkSync(dest); } catch { /* best-effort */ }
|
|
261
|
+
skipped.push(`${rel} (exclude write failed: ${(err && err.code) || (err && err.message) || err})`);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} catch { /* best-effort */ }
|
|
265
|
+
}
|
|
266
|
+
|
|
193
267
|
/**
|
|
194
268
|
* @param {{ mainCwd: string, worktreeCwd: string, names?: string[] }} opts
|
|
195
269
|
* @returns {Promise<{ linked: string[], skipped: string[], installed: string[], setup: object }>}
|
|
@@ -225,6 +299,7 @@ async function linkDependencyDirs({ mainCwd, worktreeCwd, names = DEFAULT_DEP_DI
|
|
|
225
299
|
skipped.push(name);
|
|
226
300
|
}
|
|
227
301
|
}
|
|
302
|
+
if (names.includes('node_modules')) await linkNestedNodeModules(mainCwd, worktreeCwd, linked, skipped);
|
|
228
303
|
// Project warm-up (.session-manager.json worktreeSetup) runs after linking so it sees node_modules.
|
|
229
304
|
// Both createWorktree and the scheduler's verify scratch worktree come through here. mainCwd lets
|
|
230
305
|
// same-project setups serialize and reports a config missing from the worktree; the outcome is
|
|
@@ -238,4 +313,4 @@ async function linkDependencyDirs({ mainCwd, worktreeCwd, names = DEFAULT_DEP_DI
|
|
|
238
313
|
return { linked, skipped, installed, setup };
|
|
239
314
|
}
|
|
240
315
|
|
|
241
|
-
module.exports = { linkDependencyDirs, isPnpmProject, isUvProject, DEFAULT_DEP_DIRS };
|
|
316
|
+
module.exports = { linkDependencyDirs, isPnpmProject, isUvProject, DEFAULT_DEP_DIRS, NESTED_MAX_PACKAGES };
|