claude-code-session-manager 0.142.0 → 0.144.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 +22 -107
- package/dist/assets/AppSettings-Z68gQiVE.js +2 -0
- package/dist/assets/{History-DpZuJXi1.js → History-C3E6y_7t.js} +2 -2
- package/dist/assets/HomeClaudeConfig-Yd1vXzBn.js +5 -0
- package/dist/assets/{Panel-BjdJjhqt.js → Panel-CnfWs46Z.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-CP0Wsg-H.js +26 -0
- package/dist/assets/Scheduler-D8un7N3B.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Cqyu4mef.js → SkillReferenceGraph-DRtZV1Al.js} +1 -1
- package/dist/assets/{Skills-vv0noNVI.js → Skills-Bg5O2Hyn.js} +23 -23
- package/dist/assets/{TiptapBody-CXi8Pvut.js → TiptapBody-BdzoBmqu.js} +27 -27
- package/dist/assets/{Toggle-CiYCWLjh.js → Toggle-Dt5K1OXt.js} +1 -1
- package/dist/assets/{VoiceButton-4NKKd1sC.js → VoiceButton-CTLyRgdF.js} +1 -1
- package/dist/assets/{historyTotals-DDunb8Ch.js → historyTotals-B2_KWBga.js} +1 -1
- package/dist/assets/{index-Cn5E9958.js → index-446b69rr.js} +715 -714
- package/dist/assets/{index-DVHIHoJf.css → index-BJ5TJvmz.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +438 -435
- package/package.json +6 -4
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +23 -16
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +16 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/weekly-consolidation.md +87 -0
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +381 -6
- package/src/main/adminRouteRegistry.cjs +16 -0
- package/src/main/agentLibrary.cjs +60 -11
- package/src/main/agentsIpc.cjs +19 -0
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +214 -7
- package/src/main/config.cjs +5 -1
- package/src/main/health.cjs +92 -14
- package/src/main/index.cjs +16 -4
- package/src/main/ipcSchemas.cjs +61 -1
- package/src/main/lib/claude/agentArmory.cjs +128 -0
- package/src/main/lib/claude/agentModelResolve.cjs +3 -2
- package/src/main/lib/claude/agentSnapshot.cjs +24 -3
- package/src/main/lib/claude/builtinTools.cjs +110 -0
- package/src/main/lib/claude/environmentProfiles.cjs +1 -1
- package/src/main/lib/claude/headlessMcpServers.cjs +138 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +8 -2
- package/src/main/lib/claude/personaToolScope.cjs +77 -6
- package/src/main/lib/demo-video-kit/cast.md +10 -1
- package/src/main/lib/demo-video-kit/character.cjs +77 -21
- package/src/main/lib/demo-video-kit/kind-tiktok.md +5 -1
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -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/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactRetention.cjs +55 -9
- package/src/main/lib/epic/artifactStore.cjs +78 -35
- package/src/main/lib/epic/delegationReadiness.cjs +10 -3
- package/src/main/lib/epic/epicDepsSync.cjs +66 -0
- package/src/main/lib/epic/epicEventLog.cjs +45 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +38 -1
- package/src/main/lib/epic/epicSettle.cjs +48 -4
- package/src/main/lib/epic/epicSpawnPlan.cjs +3 -1
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicValidationHook.cjs +22 -3
- package/src/main/lib/epic/planReviewInput.cjs +123 -0
- package/src/main/lib/epic/restorableSessions.cjs +1 -0
- package/src/main/lib/epic/scriptStartedBy.cjs +71 -0
- package/src/main/lib/externalContract.cjs +24 -1
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/createdProjects.cjs +291 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +24 -2
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +96 -8
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +54 -3
- package/src/main/lib/feedback-remote/pendingReplies.cjs +22 -0
- package/src/main/lib/feedback-remote/projectCreate.cjs +415 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +94 -4
- package/src/main/lib/feedback-remote/replyClaims.cjs +168 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +29 -1
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +43 -2
- package/src/main/lib/feedback-remote/servicePairLocalRoutes.cjs +91 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +47 -7
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +99 -1
- 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 +119 -10
- package/src/main/lib/mcpToolCatalog.cjs +144 -12
- package/src/main/lib/mcpToolsProbe.cjs +19 -2
- package/src/main/lib/opsOwnership.cjs +113 -28
- package/src/main/lib/packs/packCatalog.cjs +98 -5
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +6 -0
- package/src/main/lib/persona-macro/builtinMacros.cjs +6 -4
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +9 -0
- package/src/main/lib/persona-macro/personaLoadout.cjs +58 -0
- package/src/main/lib/persona-macro/personaMerge.cjs +11 -3
- package/src/main/lib/persona-macro/personaUpgrade.cjs +96 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +1 -1
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +140 -0
- package/src/main/lib/prd/prdCreate.cjs +395 -229
- package/src/main/lib/prd/prdCriteria.cjs +7 -4
- package/src/main/lib/prd/prdFrontmatter.cjs +5 -2
- package/src/main/lib/prd/prdMcpReachWarnings.cjs +44 -0
- package/src/main/lib/prd/prdSandboxWarnings.cjs +49 -0
- package/src/main/lib/process/peerChatSession.cjs +165 -0
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoScriptPress.cjs +266 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +371 -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/promptSessionSchema.cjs +2 -0
- package/src/main/lib/scheduler/baselineGate.cjs +31 -2
- package/src/main/lib/scheduler/criteriaChecks.cjs +164 -20
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +13 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +215 -55
- package/src/main/lib/scheduler/planReleaseRoute.cjs +110 -0
- package/src/main/lib/scheduler/planReviewSchema.cjs +182 -0
- package/src/main/lib/scheduler/planReviewStats.cjs +63 -0
- package/src/main/lib/scheduler/planReviewStore.cjs +128 -0
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +60 -2
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/sandboxEnvironmentLimit.cjs +141 -0
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +15 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/scheduler/slotsRoute.cjs +101 -87
- package/src/main/lib/scheduler/upgradeDrain.cjs +32 -5
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +28 -7
- package/src/main/lib/tasks/memoryConsolidation.cjs +123 -39
- package/src/main/lib/tasks/mitigationReview.cjs +21 -1
- package/src/main/lib/tasks/taskAdminRoutes.cjs +104 -17
- package/src/main/lib/tasks/taskLedger.cjs +2 -2
- package/src/main/lib/tasks/taskRun.cjs +3 -1
- package/src/main/lib/tasks/weeklyConsolidationInputs.cjs +178 -0
- package/src/main/lib/telemetry/auditEvents.cjs +21 -24
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/projectPages.cjs +22 -14
- package/src/main/promptSessionEvents.cjs +16 -1
- package/src/main/pty.cjs +14 -2
- package/src/main/queueOps.cjs +1 -1
- package/src/main/runVerify.cjs +4 -3
- package/src/main/scheduler/planReviewHold.cjs +140 -0
- package/src/main/scheduler/prdParser.cjs +1 -0
- package/src/main/scheduler/reviewLadder.cjs +2 -0
- package/src/main/scheduler/utilizationHold.cjs +101 -6
- package/src/main/scheduler.cjs +1055 -107
- package/src/main/seedAgentPersonas.cjs +11 -6
- package/src/main/seedStatus.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +22 -2
- package/src/main/webRemote.cjs +47 -7
- package/src/preload/api.d.ts +118 -2
- package/src/preload/apiSurface.json +42 -0
- package/src/preload/index.cjs +11 -0
- package/src/seed/agents/architect.md +28 -43
- package/src/seed/agents/demo-video-builder.md +15 -8
- package/src/seed/agents/dev-lead.md +3 -1
- package/src/seed/agents/md-network-curator.md +27 -0
- package/src/seed/agents/plan-reviewer.md +47 -0
- package/src/seed/agents/validator.md +21 -19
- package/dist/assets/AppSettings-BcZgIvvY.js +0 -2
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +0 -3
- package/dist/assets/ProjectClaudeConfig-BTClYV6i.js +0 -26
- package/dist/assets/Scheduler-DPobKx1Z.js +0 -16
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* criterion can be checked mechanically:
|
|
9
9
|
* - command: spec is one gate command; must pass prdGateFiles.validateGate.
|
|
10
10
|
* - file: spec is a repo-relative path string, or { path, contains? }.
|
|
11
|
-
* - http: spec is a loopback URL string, or { url, status? } (status defaults
|
|
11
|
+
* - http: spec is a loopback URL string, or { url, status?, contains? } (status defaults
|
|
12
|
+
* to 200; contains is one-line text the response body must include).
|
|
12
13
|
* - manual: spec is optional one-line guidance for the human/validator.
|
|
13
14
|
*
|
|
14
15
|
* Pure, no I/O. normalizeCriteria throws a CriteriaError naming the 1-based
|
|
@@ -71,9 +72,9 @@ function normalizeFile(spec, idx) {
|
|
|
71
72
|
function normalizeHttp(spec, idx) {
|
|
72
73
|
const obj = typeof spec === 'string' ? { url: spec } : spec;
|
|
73
74
|
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
74
|
-
throw new CriteriaError(idx, 'http check spec must be a loopback URL or { url, status? }.');
|
|
75
|
+
throw new CriteriaError(idx, 'http check spec must be a loopback URL or { url, status?, contains? }.');
|
|
75
76
|
}
|
|
76
|
-
const extra = Object.keys(obj).filter((k) => k !== 'url' && k !== 'status');
|
|
77
|
+
const extra = Object.keys(obj).filter((k) => k !== 'url' && k !== 'status' && k !== 'contains');
|
|
77
78
|
if (extra.length) throw new CriteriaError(idx, `http check spec has unknown key(s): ${extra.join(', ')}.`);
|
|
78
79
|
const raw = oneLine(obj.url, 2000, 'http check url', idx);
|
|
79
80
|
let url;
|
|
@@ -93,7 +94,9 @@ function normalizeHttp(spec, idx) {
|
|
|
93
94
|
if (!Number.isInteger(status) || status < 100 || status > 599) {
|
|
94
95
|
throw new CriteriaError(idx, 'http check status must be an integer from 100 to 599.');
|
|
95
96
|
}
|
|
96
|
-
|
|
97
|
+
const out = { url: url.href, status };
|
|
98
|
+
if (obj.contains !== undefined) out.contains = oneLine(obj.contains, CONTAINS_MAX_CHARS, 'http check contains', idx);
|
|
99
|
+
return out;
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
function normalizeCheck(check, idx) {
|
|
@@ -83,8 +83,8 @@ function splitFrontmatter(raw) {
|
|
|
83
83
|
* JSON array of { id, statement, check: { kind, spec? } } — see parseCriteria.
|
|
84
84
|
*/
|
|
85
85
|
|
|
86
|
-
const RECOGNIZED_KEYS = new Set(['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria']);
|
|
87
|
-
const EMIT_ORDER = ['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria'];
|
|
86
|
+
const RECOGNIZED_KEYS = new Set(['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria', 'planReview']);
|
|
87
|
+
const EMIT_ORDER = ['title', 'cwd', 'estimateMinutes', 'parallelGroup', 'sourcePromptId', 'sourceTabId', 'tag', 'agentType', 'createdVia', 'issuedAt', 'dependsOn', 'fixes', 'quietMachine', 'disposition', 'planId', 'deliverable', 'artifactPaths', 'macroId', 'effort', 'voiceId', 'riskTools', 'preflight', 'criteria', 'planReview'];
|
|
88
88
|
// Mirrors modelCatalog.cjs CATALOG_FLOOR.effortLevels. A closed set so the
|
|
89
89
|
// value is always safe as a frontmatter line and as a --effort argv token.
|
|
90
90
|
const PRD_EFFORT_LEVELS = Object.freeze(['low', 'medium', 'high', 'xhigh', 'max']);
|
|
@@ -274,6 +274,9 @@ function applyKey(fm, key, after) {
|
|
|
274
274
|
// round-trips the string.
|
|
275
275
|
fm.agentType = String(v);
|
|
276
276
|
return;
|
|
277
|
+
case 'planReview':
|
|
278
|
+
if (String(v) === 'required') fm.planReview = 'required';
|
|
279
|
+
return;
|
|
277
280
|
case 'createdVia':
|
|
278
281
|
fm.createdVia = String(v);
|
|
279
282
|
return;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* prdMcpReachWarnings.cjs — advisory rule: a PRD whose persona (declared mcpServers + mcp__<server>__
|
|
3
|
+
* tools) or riskTools name an MCP server a headless job cannot load (undefined for the cwd, or
|
|
4
|
+
* credential-bearing) will park capability_unknown / capability_credentialed. Never blocks a write,
|
|
5
|
+
* never throws (an unreadable persona or resolver yields no warning).
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
const RISK_MCP_RE = /^mcp__([^_](?:[^_]|_(?!_))*)__/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {any} input createPrd()'s input shape.
|
|
13
|
+
* @param {{ resolve: (o: { cwd?: string }) => { known: Record<string, any>, credentialed: Record<string, string> },
|
|
14
|
+
* readPersonaServers: (input: any) => string[]|null }} deps
|
|
15
|
+
* @returns {string[]}
|
|
16
|
+
*/
|
|
17
|
+
function mcpReachWarnings(input, deps) {
|
|
18
|
+
try {
|
|
19
|
+
const personaServers = deps.readPersonaServers(input);
|
|
20
|
+
if (!Array.isArray(personaServers)) return [];
|
|
21
|
+
const { known, credentialed } = deps.resolve({ cwd: input?.cwd });
|
|
22
|
+
const out = [];
|
|
23
|
+
for (const name of personaServers) {
|
|
24
|
+
if (Object.prototype.hasOwnProperty.call(credentialed || {}, name)) {
|
|
25
|
+
out.push(`persona MCP server \`${name}\` is credential-bearing (${credentialed[name]}) — the job will park capability_credentialed. Move the secret to a vault ref (environment profile) or drop the server from the persona.`);
|
|
26
|
+
} else if (!Object.prototype.hasOwnProperty.call(known || {}, name)) {
|
|
27
|
+
out.push(`persona MCP server \`${name}\` is not defined in ~/.claude.json, <cwd>/.mcp.json or the local project scope for this cwd — the job will park capability_unknown. Define the server there or remove it from the persona's tools/mcpServers.`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const risk = Array.isArray(input?.riskTools) ? input.riskTools : [];
|
|
32
|
+
for (const rule of risk) {
|
|
33
|
+
const m = typeof rule === 'string' ? RISK_MCP_RE.exec(rule) : null;
|
|
34
|
+
if (!m || seen.has(m[1]) || personaServers.includes(m[1])) continue;
|
|
35
|
+
seen.add(m[1]);
|
|
36
|
+
out.push(`riskTools clears \`${rule}\` but the persona never loads MCP server \`${m[1]}\` — the tool is cleared yet unreachable. Add it to the persona's tools or mcpServers.`);
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
} catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = { mcpReachWarnings };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* prdSandboxWarnings.cjs — pure advisory rule: a PRD that lists a path under `.claude/` in its
|
|
3
|
+
* files AND mentions `git mv` / `git rm` / `rm` in its goal, notes or criteria will park, because
|
|
4
|
+
* job Bash cannot write under `.claude/` in the sandbox (Self PRD 1326). Any path under
|
|
5
|
+
* `.claude/agents/` or `.claude/commands/` warns unconditionally (no verb needed): all writes there
|
|
6
|
+
* are refused, Edit/Write included. Never blocks a write.
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const VERB_RE = /\bgit\s+(mv|rm)\b|(^|[\s`'"(;&|])rm(?=$|[\s.,;:)`'"])/m;
|
|
11
|
+
|
|
12
|
+
/** @param {unknown} p */
|
|
13
|
+
function isClaudePath(p) {
|
|
14
|
+
return typeof p === 'string' && p.split('/').some((seg) => seg === '.claude');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** `.claude` followed by agents, commands, skills, hooks or settings*.json: every write there is refused (Bash, Edit, Write). */
|
|
18
|
+
function isProtectedClaudePath(p) {
|
|
19
|
+
if (typeof p !== 'string') return false;
|
|
20
|
+
const segs = p.split('/');
|
|
21
|
+
return segs.some((seg, i) => seg === '.claude' && (['agents', 'commands', 'skills', 'hooks'].includes(segs[i + 1]) || /^settings[^/]*\.json$/.test(segs[i + 1] ?? '')));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns `[]` or a one-element array holding the warning (spread-compatible with sizingWarnings).
|
|
26
|
+
* @param {any} input createPrd()'s input shape.
|
|
27
|
+
* @returns {string[]}
|
|
28
|
+
*/
|
|
29
|
+
function sandboxWarnings(input) {
|
|
30
|
+
const files = Array.isArray(input?.files) ? input.files : [];
|
|
31
|
+
const protectedPaths = files.filter(isProtectedClaudePath);
|
|
32
|
+
if (protectedPaths.length > 0) {
|
|
33
|
+
return [
|
|
34
|
+
`files lists ${protectedPaths.map((p) => `\`${p}\``).join(', ')} under .claude/agents, .claude/commands, .claude/skills, .claude/hooks or .claude/settings*.json — the job sandbox cannot write there (Bash, Edit and Write are all refused), so the job will fail. Remove the path from files; the architect must edit these inline. See PRD_AUTHORING.md#job-sandbox-limits.`,
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
const bad = files.filter(isClaudePath);
|
|
38
|
+
if (bad.length === 0) return [];
|
|
39
|
+
const ac = Array.isArray(input?.acceptanceCriteria) ? input.acceptanceCriteria : [];
|
|
40
|
+
const text = [input?.goal, input?.implementationNotes, ...ac]
|
|
41
|
+
.filter((s) => typeof s === 'string')
|
|
42
|
+
.join('\n');
|
|
43
|
+
if (!VERB_RE.test(text)) return [];
|
|
44
|
+
return [
|
|
45
|
+
`files lists ${bad.map((p) => `\`${p}\``).join(', ')} under .claude/ and the PRD mentions git mv / git rm / rm — Bash writes there are refused by the job sandbox, so the job will park. Remove the verb or the path; the architect edits protected .claude/ paths inline. See PRD_AUTHORING.md#job-sandbox-limits.`,
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
module.exports = { sandboxWarnings };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* peerChatSession.cjs — given the accepted socket of a loopback HTTP request,
|
|
5
|
+
* find the client process and read SM_CHAT_SESSION_ID / SM_PROJECT_ROOT from
|
|
6
|
+
* its environment (or its nearest ancestor's; up to 6 hops). Lets a press made
|
|
7
|
+
* from an SM chat (agent curl from its Bash tool) record the asking Epic.
|
|
8
|
+
*
|
|
9
|
+
* Read-only, same-uid processes only. Never logs or returns the environment —
|
|
10
|
+
* only the two variables. Never throws or rejects; null on any miss.
|
|
11
|
+
* SECURITY: the resolved chat/Epic is self-asserted by any same-uid process
|
|
12
|
+
* (it can set these variables to anything). It is provenance only and must
|
|
13
|
+
* never be used to authorize anything.
|
|
14
|
+
* Linux: /proc. darwin: lsof + ps (execFile, no shell). Others: null.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const nodeFs = require('fs');
|
|
18
|
+
const childProcess = require('child_process');
|
|
19
|
+
|
|
20
|
+
const ID_RE = /^[A-Za-z0-9-]{8,64}$/;
|
|
21
|
+
const MAX_HOPS = 6;
|
|
22
|
+
const DEADLINE_MS = 1500;
|
|
23
|
+
|
|
24
|
+
function pickVars(envMap) {
|
|
25
|
+
const id = envMap.SM_CHAT_SESSION_ID;
|
|
26
|
+
if (typeof id !== 'string' || !ID_RE.test(id)) return null;
|
|
27
|
+
const root = envMap.SM_PROJECT_ROOT;
|
|
28
|
+
return { chatSessionId: id, projectRoot: typeof root === 'string' && root ? root : null };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseEnviron(buf) {
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const part of String(buf).split('\0')) {
|
|
34
|
+
const i = part.indexOf('=');
|
|
35
|
+
if (i <= 0) continue;
|
|
36
|
+
const k = part.slice(0, i);
|
|
37
|
+
if (k === 'SM_CHAT_SESSION_ID' || k === 'SM_PROJECT_ROOT') out[k] = part.slice(i + 1);
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ── Linux ──────────────────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
function findInode(fs, clientLocalPort, serverPort) {
|
|
45
|
+
const lp = clientLocalPort.toString(16).toUpperCase().padStart(4, '0');
|
|
46
|
+
const rp = serverPort.toString(16).toUpperCase().padStart(4, '0');
|
|
47
|
+
for (const f of ['/proc/net/tcp', '/proc/net/tcp6']) {
|
|
48
|
+
let text;
|
|
49
|
+
try { text = fs.readFileSync(f, 'utf8'); } catch { continue; }
|
|
50
|
+
for (const line of String(text).split('\n').slice(1)) {
|
|
51
|
+
const c = line.trim().split(/\s+/);
|
|
52
|
+
if (c.length < 10) continue;
|
|
53
|
+
const l = (c[1] || '').split(':')[1];
|
|
54
|
+
const r = (c[2] || '').split(':')[1];
|
|
55
|
+
if (l && r && l.toUpperCase() === lp && r.toUpperCase() === rp && c[9] && c[9] !== '0') return c[9];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function findPidByInode(fs, inode, uid, deadline, now) {
|
|
62
|
+
const want = `socket:[${inode}]`;
|
|
63
|
+
let pids;
|
|
64
|
+
try { pids = fs.readdirSync('/proc').filter((n) => /^\d+$/.test(n)); } catch { return null; }
|
|
65
|
+
for (const pid of pids) {
|
|
66
|
+
if (now() > deadline) return null;
|
|
67
|
+
try {
|
|
68
|
+
if (uid != null && fs.statSync(`/proc/${pid}`).uid !== uid) continue;
|
|
69
|
+
for (const fd of fs.readdirSync(`/proc/${pid}/fd`)) {
|
|
70
|
+
try {
|
|
71
|
+
if (fs.readlinkSync(`/proc/${pid}/fd/${fd}`) === want) return Number(pid);
|
|
72
|
+
} catch { /* fd vanished / EACCES */ }
|
|
73
|
+
}
|
|
74
|
+
} catch { /* EACCES / gone */ }
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function linuxResolve(socket, deps, deadline, now) {
|
|
80
|
+
const fs = deps.fs || nodeFs;
|
|
81
|
+
const uid = deps.getuid ? deps.getuid() : (typeof process.getuid === 'function' ? process.getuid() : null);
|
|
82
|
+
const inode = findInode(fs, socket.remotePort, socket.localPort);
|
|
83
|
+
if (!inode) return null;
|
|
84
|
+
let pid = findPidByInode(fs, inode, uid, deadline, now);
|
|
85
|
+
for (let hop = 0; pid && hop <= MAX_HOPS && now() <= deadline; hop++) {
|
|
86
|
+
try {
|
|
87
|
+
const found = pickVars(parseEnviron(fs.readFileSync(`/proc/${pid}/environ`, 'latin1')));
|
|
88
|
+
if (found) return found;
|
|
89
|
+
} catch { /* unreadable */ }
|
|
90
|
+
let ppid = 0;
|
|
91
|
+
try {
|
|
92
|
+
const stat = String(fs.readFileSync(`/proc/${pid}/stat`, 'latin1'));
|
|
93
|
+
ppid = Number(stat.slice(stat.lastIndexOf(')') + 2).split(' ')[1]);
|
|
94
|
+
} catch { return null; }
|
|
95
|
+
if (!Number.isInteger(ppid) || ppid <= 1) return null;
|
|
96
|
+
pid = ppid;
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ── darwin ─────────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
function run(execFile, file, args, timeout) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
try {
|
|
106
|
+
execFile(file, args, { timeout, maxBuffer: 4 * 1024 * 1024 }, (err, stdout) => resolve(err ? null : String(stdout)));
|
|
107
|
+
} catch { resolve(null); }
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function darwinResolve(socket, deps, deadline, now) {
|
|
112
|
+
const execFile = deps.execFile || childProcess.execFile;
|
|
113
|
+
const left = () => Math.max(100, Math.min(1000, deadline - now()));
|
|
114
|
+
const out = await run(execFile, 'lsof', ['-nP', `-iTCP:${socket.remotePort}`, '-sTCP:ESTABLISHED', '-Fp'], left());
|
|
115
|
+
if (!out) return null;
|
|
116
|
+
const self = process.pid;
|
|
117
|
+
const pids = out.split('\n').filter((l) => /^p\d+$/.test(l)).map((l) => Number(l.slice(1))).filter((p) => p !== self);
|
|
118
|
+
for (let pid of pids.slice(0, 4)) {
|
|
119
|
+
for (let hop = 0; hop <= MAX_HOPS && now() < deadline; hop++) {
|
|
120
|
+
const cmd = await run(execFile, 'ps', ['-E', '-ww', '-o', 'command=', '-p', String(pid)], left());
|
|
121
|
+
if (cmd) {
|
|
122
|
+
const env = {};
|
|
123
|
+
// ps -E prints argv then the environment: the LAST match is the env's.
|
|
124
|
+
const id = [...cmd.matchAll(/ SM_CHAT_SESSION_ID=(\S+)/g)].pop();
|
|
125
|
+
const root = [...cmd.matchAll(/ SM_PROJECT_ROOT=(\S+)/g)].pop();
|
|
126
|
+
if (id) env.SM_CHAT_SESSION_ID = id[1];
|
|
127
|
+
if (root) env.SM_PROJECT_ROOT = root[1];
|
|
128
|
+
const found = pickVars(env);
|
|
129
|
+
if (found) return found;
|
|
130
|
+
}
|
|
131
|
+
const pp = await run(execFile, 'ps', ['-o', 'ppid=', '-p', String(pid)], left());
|
|
132
|
+
const ppid = Number(String(pp || '').trim());
|
|
133
|
+
if (!Number.isInteger(ppid) || ppid <= 1) break;
|
|
134
|
+
pid = ppid;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {{ remotePort?: number, localPort?: number }} socket
|
|
142
|
+
* @param {{ fs?: any, execFile?: any, getuid?: () => number, platform?: string, now?: () => number }} [deps]
|
|
143
|
+
* @returns {Promise<{ chatSessionId: string, projectRoot: string|null } | null>}
|
|
144
|
+
*/
|
|
145
|
+
async function resolvePeerChatSession(socket, deps = {}) {
|
|
146
|
+
try {
|
|
147
|
+
if (!socket || !Number.isInteger(socket.remotePort) || !Number.isInteger(socket.localPort)) return null;
|
|
148
|
+
const now = deps.now || Date.now;
|
|
149
|
+
const deadline = now() + DEADLINE_MS;
|
|
150
|
+
const platform = deps.platform || process.platform;
|
|
151
|
+
if (platform === 'linux') return linuxResolve(socket, deps, deadline, now) || null;
|
|
152
|
+
if (platform === 'darwin') {
|
|
153
|
+
let timer;
|
|
154
|
+
const cap = new Promise((r) => { timer = setTimeout(() => r(null), DEADLINE_MS); });
|
|
155
|
+
try {
|
|
156
|
+
return (await Promise.race([darwinResolve(socket, deps, deadline, now), cap])) || null;
|
|
157
|
+
} finally { clearTimeout(timer); }
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
module.exports = { resolvePeerChatSession };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* videoPressLines.cjs — a scripted Demo Video press: validate its choices and
|
|
5
|
+
* build exactly the prompt lines the Project Home composer sends for the same
|
|
6
|
+
* choices, so a scripted press runs the same job as a human press.
|
|
7
|
+
*
|
|
8
|
+
* Pure: no fs, no IPC. Mirrors renderer composerTemplates.ts (VIDEO_KINDS,
|
|
9
|
+
* videoLengthsFor, voiceLine, videoPromptLines); main may not import renderer
|
|
10
|
+
* code, so __tests__/videoPressLines.test.cjs asserts the two stay identical.
|
|
11
|
+
* Whether a voice exists in the project's library is the route's check, not this one.
|
|
12
|
+
*
|
|
13
|
+
* parseScriptPress(body) -> { ok: true, cfg } | { ok: false, error } (error: one line)
|
|
14
|
+
* body: { kind, target?, length?, style?, character?, voiceId?, focus?, reviewFirst? }
|
|
15
|
+
* cfg (renderer VideoCfg shape): { kind, target, style, length, mascot, review, focus, voice? }
|
|
16
|
+
* pressLines(cfg) -> string[]
|
|
17
|
+
*
|
|
18
|
+
* Review first travels only as cfg.review (the press's reviewStage), never as a
|
|
19
|
+
* line; a 'Review:' or 'Replace entry:' line in target or focus is refused so a
|
|
20
|
+
* script cannot forge an owner approval or overwrite an entry.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const { VOICE_ID_RE } = require('../demo-video-kit/voiceLibrary.cjs');
|
|
24
|
+
|
|
25
|
+
const VIDEO_KINDS = Object.freeze(['Project demo', 'Blog post', 'Feature', 'TikTok', 'Marketing']);
|
|
26
|
+
const KIND_SLUGS = Object.freeze({
|
|
27
|
+
'project-demo': 'Project demo',
|
|
28
|
+
'blog-post': 'Blog post',
|
|
29
|
+
feature: 'Feature',
|
|
30
|
+
tiktok: 'TikTok',
|
|
31
|
+
marketing: 'Marketing',
|
|
32
|
+
});
|
|
33
|
+
const VIDEO_STYLES = Object.freeze(['Auto', 'Professional', 'Fun', 'Animated whiteboard', 'Kinetic typography']);
|
|
34
|
+
const TARGET_REQUIRED_KINDS = Object.freeze(['Blog post', 'Feature']);
|
|
35
|
+
const MAX_TARGET = 500;
|
|
36
|
+
const MAX_FOCUS = 2000;
|
|
37
|
+
const RESERVED_LINE_RE = /^\s*(review|replace entry)\s*:/im;
|
|
38
|
+
const CONTROL_RE = /[\u0000-\u001f\u007f]/;
|
|
39
|
+
const FOCUS_CONTROL_RE = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
40
|
+
|
|
41
|
+
/** The length chips a kind offers: 15 s only for TikTok (renderer videoLengthsFor). */
|
|
42
|
+
function videoLengthsFor(kind) {
|
|
43
|
+
return kind === 'TikTok' ? [15, 30, 60] : [30, 60];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function fail(error) {
|
|
47
|
+
return { ok: false, error };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parseScriptPress(body) {
|
|
51
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) return fail('press body must be an object');
|
|
52
|
+
|
|
53
|
+
const rawKind = body.kind;
|
|
54
|
+
if (typeof rawKind !== 'string') return fail(`kind is required: one of ${VIDEO_KINDS.join(', ')}`);
|
|
55
|
+
const kind = VIDEO_KINDS.includes(rawKind) ? rawKind : Object.prototype.hasOwnProperty.call(KIND_SLUGS, rawKind) ? KIND_SLUGS[rawKind] : null;
|
|
56
|
+
if (!kind) return fail(`unknown kind '${oneLine(rawKind)}': one of ${VIDEO_KINDS.join(', ')} (or its slug)`);
|
|
57
|
+
|
|
58
|
+
let length = 30;
|
|
59
|
+
if (body.length !== undefined) {
|
|
60
|
+
const allowed = videoLengthsFor(kind);
|
|
61
|
+
if (typeof body.length !== 'number' || !allowed.includes(body.length)) {
|
|
62
|
+
return fail(`length for ${kind} must be one of ${allowed.join(', ')}`);
|
|
63
|
+
}
|
|
64
|
+
length = body.length;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let style = 'Auto';
|
|
68
|
+
if (body.style !== undefined) {
|
|
69
|
+
if (typeof body.style !== 'string' || !VIDEO_STYLES.includes(body.style)) {
|
|
70
|
+
return fail(`style must be one of ${VIDEO_STYLES.join(', ')}`);
|
|
71
|
+
}
|
|
72
|
+
style = body.style;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let mascot = true;
|
|
76
|
+
if (body.character !== undefined) {
|
|
77
|
+
if (typeof body.character !== 'boolean') return fail('character must be true or false');
|
|
78
|
+
mascot = body.character;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let review = false;
|
|
82
|
+
if (body.reviewFirst !== undefined) {
|
|
83
|
+
if (typeof body.reviewFirst !== 'boolean') return fail('reviewFirst must be true or false');
|
|
84
|
+
review = body.reviewFirst;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let voice;
|
|
88
|
+
if (body.voiceId !== undefined) {
|
|
89
|
+
if (typeof body.voiceId !== 'string' || !VOICE_ID_RE.test(body.voiceId)) {
|
|
90
|
+
return fail(`voiceId must match ${VOICE_ID_RE}`);
|
|
91
|
+
}
|
|
92
|
+
voice = body.voiceId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let target = '';
|
|
96
|
+
if (body.target !== undefined) {
|
|
97
|
+
if (typeof body.target !== 'string') return fail('target must be a string');
|
|
98
|
+
if (CONTROL_RE.test(body.target)) return fail('target must be one line with no control characters');
|
|
99
|
+
target = body.target.trim();
|
|
100
|
+
if (target.length > MAX_TARGET) return fail(`target must be at most ${MAX_TARGET} characters`);
|
|
101
|
+
if (RESERVED_LINE_RE.test(target)) return fail("target may not carry a 'Review:' or 'Replace entry:' line");
|
|
102
|
+
}
|
|
103
|
+
if (TARGET_REQUIRED_KINDS.includes(kind) && !target) return fail(`target is required for a ${kind} video`);
|
|
104
|
+
|
|
105
|
+
let focus = '';
|
|
106
|
+
if (body.focus !== undefined) {
|
|
107
|
+
if (typeof body.focus !== 'string') return fail('focus must be a string');
|
|
108
|
+
if (FOCUS_CONTROL_RE.test(body.focus)) return fail('focus may not contain control characters');
|
|
109
|
+
focus = body.focus.trim();
|
|
110
|
+
if (focus.length > MAX_FOCUS) return fail(`focus must be at most ${MAX_FOCUS} characters`);
|
|
111
|
+
if (RESERVED_LINE_RE.test(focus)) return fail("focus may not carry a 'Review:' or 'Replace entry:' line");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const cfg = { kind, target, style, length, mascot, review, focus };
|
|
115
|
+
if (voice) cfg.voice = voice;
|
|
116
|
+
return { ok: true, cfg };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Same lines as renderer videoPromptLines(cfg); a target is named only for a non-demo kind. */
|
|
120
|
+
function pressLines(cfg) {
|
|
121
|
+
const lines = [`Video kind: ${cfg.kind}`];
|
|
122
|
+
const target = (cfg.target || '').trim();
|
|
123
|
+
if (cfg.kind !== 'Project demo' && target) lines.push(`Video target: ${target}`);
|
|
124
|
+
lines.push(`Video style: ${cfg.style}`);
|
|
125
|
+
const voice = typeof cfg.voice === 'string' ? cfg.voice.trim() : '';
|
|
126
|
+
if (voice) lines.push(`Voice: ${voice}`);
|
|
127
|
+
lines.push(`Video length: ${cfg.length}`, `Character: ${cfg.mascot ? 'on' : 'off'}`);
|
|
128
|
+
const focus = (cfg.focus || '').trim();
|
|
129
|
+
if (focus) lines.push(focus);
|
|
130
|
+
return lines;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function oneLine(s) {
|
|
134
|
+
return String(s).replace(/[\u0000-\u001f\u007f]+/g, ' ').slice(0, 80);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
module.exports = {
|
|
138
|
+
parseScriptPress,
|
|
139
|
+
pressLines,
|
|
140
|
+
VIDEO_KINDS,
|
|
141
|
+
VIDEO_STYLES,
|
|
142
|
+
KIND_SLUGS,
|
|
143
|
+
MAX_TARGET,
|
|
144
|
+
MAX_FOCUS,
|
|
145
|
+
};
|