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
|
@@ -34,11 +34,12 @@ const path = require('node:path');
|
|
|
34
34
|
const crypto = require('node:crypto');
|
|
35
35
|
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
36
36
|
const { resolveProjectContext } = require('../projectRootResolve.cjs');
|
|
37
|
-
const { opsPath, OPS_ROOT_DIR } = require('../opsOwnership.cjs');
|
|
37
|
+
const { opsPath, OPS_ROOT_DIR, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
38
38
|
const config = require('../../config.cjs');
|
|
39
39
|
const { schemas, ENTRY_ID_RE } = require('../../ipcSchemas.cjs');
|
|
40
40
|
const { validateCharacterJson, validateCharacterJs, voiceIdRefsOf, inspectCharacter, characterDir, MAX_JSON_BYTES: MAX_CHARACTER_JSON_BYTES, MAX_JS_BYTES: MAX_CHARACTER_JS_BYTES } = require('../demo-video-kit/character.cjs');
|
|
41
41
|
const voiceLibrary = require('../demo-video-kit/voiceLibrary.cjs');
|
|
42
|
+
const projectSounds = require('../demo-video-kit/projectSounds.cjs');
|
|
42
43
|
const { checkHtmlLimits, checkPostCaption, TIKTOK_CHECK_IDS } = require('../demo-video-kit/checks.cjs');
|
|
43
44
|
const { injectPlayerBridge } = require('../project-pages/playerBridge.cjs');
|
|
44
45
|
const { readMatrix, matrixJsonSchema, MAX_MATRIX_BYTES } = require('../project-pages/competitiveMatrix.cjs');
|
|
@@ -63,6 +64,8 @@ const VIDEO_OUTCOMES = ['season-complete'];
|
|
|
63
64
|
const OUTCOME_TEXT_MAX = 300;
|
|
64
65
|
const OUTCOME_BODY_KEYS = ['cwd', 'videoId', 'outcome', 'text'];
|
|
65
66
|
const OUTCOME_WRITE_BODY_MAX = 64 * 1024;
|
|
67
|
+
/** Character write body cap: js + json, every project sound WAV as base64, and 128 KiB of overhead. */
|
|
68
|
+
const CHARACTER_WRITE_BODY_MAX = MAX_CHARACTER_JS_BYTES * 2 + base64LengthFor(projectSounds.MAX_SOUNDS_TOTAL_BYTES) + 128 * 1024;
|
|
66
69
|
|
|
67
70
|
// Each detector is a linear regex scan; the input is capped first.
|
|
68
71
|
const REMOTE_REFERENCE_CHECKS = [
|
|
@@ -457,7 +460,9 @@ function registerAdminRoute(adminHttp) {
|
|
|
457
460
|
// POST /admin/project-home/videos/outcome/write {cwd, videoId, outcome, text} -> videos/<videoId>/outcome.json
|
|
458
461
|
adminHttp.registerRoute('POST', '/admin/project-home/videos/outcome/write', outcomeWriteHandler);
|
|
459
462
|
|
|
460
|
-
// POST /admin/project-home/character/write {cwd, json, js, replace?} -> videos/_character/
|
|
463
|
+
// POST /admin/project-home/character/write {cwd, json, js, replace?, sounds?} -> videos/_character/
|
|
464
|
+
// (sounds = { <name>: <base64 WAV> } for every file-backed sound, written to sounds/<name>.wav;
|
|
465
|
+
// answers {ok, path, bytes, sounds: <names written>})
|
|
461
466
|
adminHttp.registerRoute('POST', '/admin/project-home/character/write', characterWriteHandler);
|
|
462
467
|
|
|
463
468
|
// POST /admin/project-home/matrix/read {cwd?} -> {ok, matrix|null, error, path, schema}
|
|
@@ -641,10 +646,78 @@ async function outcomeWriteHandler(req, res) {
|
|
|
641
646
|
}
|
|
642
647
|
}
|
|
643
648
|
|
|
649
|
+
/**
|
|
650
|
+
* Checks a character write's `sounds` payload ({ <name>: <base64 WAV> }) against the
|
|
651
|
+
* file-backed sounds `jsonObj` declares: exactly one entry per name, valid base64, each
|
|
652
|
+
* WAV within its kind's cap and readable, and the total within MAX_SOUNDS_TOTAL_BYTES.
|
|
653
|
+
* -> {files: [{name, buffer}]} | {error}. Errors never echo the payload.
|
|
654
|
+
*/
|
|
655
|
+
function checkSoundPayload(jsonObj, sounds) {
|
|
656
|
+
const payload = sounds === undefined || sounds === null ? {} : sounds;
|
|
657
|
+
if (typeof payload !== 'object' || Array.isArray(payload)) {
|
|
658
|
+
return { error: 'sounds payload must be an object of { name: base64 WAV }' };
|
|
659
|
+
}
|
|
660
|
+
const names = projectSounds.fileBackedSoundNames(jsonObj);
|
|
661
|
+
for (const name of names) {
|
|
662
|
+
if (!Object.prototype.hasOwnProperty.call(payload, name)) {
|
|
663
|
+
return { error: `sound '${name}' has no WAV: send it as sounds.${name} (project_character_write soundPaths.${name})` };
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
for (const key of Object.keys(payload)) {
|
|
667
|
+
if (!names.includes(key)) return { error: `sound '${key}' was sent but character.json declares no file-backed sound by that name` };
|
|
668
|
+
}
|
|
669
|
+
const files = [];
|
|
670
|
+
let total = 0;
|
|
671
|
+
for (const name of names) {
|
|
672
|
+
const b64 = payload[name];
|
|
673
|
+
if (typeof b64 !== 'string' || b64.length % 4 !== 0 || !BASE64_RE.test(b64)) {
|
|
674
|
+
return { error: `sound '${name}' is not valid base64` };
|
|
675
|
+
}
|
|
676
|
+
const kind = projectSounds.findProjectSound(jsonObj, name).kind;
|
|
677
|
+
const cap = kind === 'sfx' ? projectSounds.MAX_SFX_WAV_BYTES : projectSounds.MAX_BED_WAV_BYTES;
|
|
678
|
+
const label = `sound '${name}'`;
|
|
679
|
+
if (b64.length > base64LengthFor(cap)) {
|
|
680
|
+
return { error: `${label} is over the ${cap}-byte limit for a ${kind === 'sfx' ? 'sound effect' : 'music bed'}` };
|
|
681
|
+
}
|
|
682
|
+
const buffer = Buffer.from(b64, 'base64');
|
|
683
|
+
const wavErr = projectSounds.checkSoundWav(buffer, label, kind);
|
|
684
|
+
if (wavErr) return { error: wavErr };
|
|
685
|
+
total += buffer.length;
|
|
686
|
+
files.push({ name, buffer });
|
|
687
|
+
}
|
|
688
|
+
if (total > projectSounds.MAX_SOUNDS_TOTAL_BYTES) {
|
|
689
|
+
return { error: `sounds total ${total} bytes exceed the ${projectSounds.MAX_SOUNDS_TOTAL_BYTES}-byte limit` };
|
|
690
|
+
}
|
|
691
|
+
return { files };
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/** Removes every entry of soundsDir(cwd) that is not a declared <name>.wav; removes the folder when nothing is declared. */
|
|
695
|
+
async function pruneSounds(cwd, names) {
|
|
696
|
+
const dir = projectSounds.soundsDir(cwd);
|
|
697
|
+
let entries;
|
|
698
|
+
try {
|
|
699
|
+
entries = await fs.promises.readdir(dir);
|
|
700
|
+
} catch (e) {
|
|
701
|
+
if (e && e.code === 'ENOENT') return;
|
|
702
|
+
throw e;
|
|
703
|
+
}
|
|
704
|
+
const keep = new Set(names.map((n) => `${n}.wav`));
|
|
705
|
+
for (const entry of entries) {
|
|
706
|
+
if (keep.has(entry)) continue;
|
|
707
|
+
const abs = path.join(dir, entry);
|
|
708
|
+
assertOpsWrite(abs, 'project-home');
|
|
709
|
+
await fs.promises.rm(abs, { recursive: true, force: true });
|
|
710
|
+
}
|
|
711
|
+
if (names.length === 0) {
|
|
712
|
+
assertOpsWrite(dir, 'project-home');
|
|
713
|
+
await fs.promises.rmdir(dir);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
644
717
|
async function characterWriteHandler(req, res) {
|
|
645
718
|
let raw;
|
|
646
719
|
try {
|
|
647
|
-
raw = await readBody(req,
|
|
720
|
+
raw = await readBody(req, CHARACTER_WRITE_BODY_MAX);
|
|
648
721
|
} catch (e) {
|
|
649
722
|
sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
|
|
650
723
|
return;
|
|
@@ -687,6 +760,11 @@ async function characterWriteHandler(req, res) {
|
|
|
687
760
|
sendJson(res, 400, { ok: false, error: `character.json exceeds the ${MAX_CHARACTER_JSON_BYTES}-byte limit (${jsonBytes} bytes as saved)` });
|
|
688
761
|
return;
|
|
689
762
|
}
|
|
763
|
+
const soundPayload = checkSoundPayload(jsonObj, body.sounds);
|
|
764
|
+
if (soundPayload.error) {
|
|
765
|
+
sendJson(res, 400, { ok: false, error: `character.json invalid: ${soundPayload.error}` });
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
690
768
|
const jsErr = validateCharacterJs(body.js, [...REMOTE_REFERENCE_CHECKS, ...NETWORK_CHECKS]);
|
|
691
769
|
if (jsErr) {
|
|
692
770
|
sendJson(res, 400, { ok: false, error: jsErr });
|
|
@@ -707,10 +785,22 @@ async function characterWriteHandler(req, res) {
|
|
|
707
785
|
try {
|
|
708
786
|
const dir = characterDir(resolved.cwd);
|
|
709
787
|
await fs.promises.mkdir(dir, { recursive: true });
|
|
788
|
+
for (const f of soundPayload.files) {
|
|
789
|
+
await config.writeBinaryAtomic(projectSounds.soundFile(resolved.cwd, f.name), f.buffer, { writer: 'project-home' });
|
|
790
|
+
}
|
|
710
791
|
const jsPath = path.join(dir, 'character.js');
|
|
711
792
|
await config.writeTextAtomic(jsPath, body.js, { writer: 'project-home' });
|
|
712
793
|
await config.writeTextAtomic(path.join(dir, 'character.json'), jsonText, { writer: 'project-home' });
|
|
713
|
-
|
|
794
|
+
// character.json is saved: the persona is usable, so a stale-WAV prune failure is reported, never a 500.
|
|
795
|
+
let pruneError;
|
|
796
|
+
try {
|
|
797
|
+
await pruneSounds(resolved.cwd, soundPayload.files.map((f) => f.name));
|
|
798
|
+
} catch (e) {
|
|
799
|
+
pruneError = e?.message ?? String(e);
|
|
800
|
+
}
|
|
801
|
+
const answer = { ok: true, path: dir, bytes: Buffer.byteLength(body.js, 'utf8'), sounds: soundPayload.files.map((f) => f.name) };
|
|
802
|
+
if (pruneError !== undefined) answer.pruneError = pruneError;
|
|
803
|
+
sendJson(res, 200, answer);
|
|
714
804
|
} catch (e) {
|
|
715
805
|
sendJson(res, 500, { ok: false, error: e?.message ?? 'write failed' });
|
|
716
806
|
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* replyClaims.cjs — the single decider for whether a cross-project reply's
|
|
3
|
+
* release claim is true.
|
|
4
|
+
*
|
|
5
|
+
* Used by crossProjectReply.cjs (the app route) and
|
|
6
|
+
* scripts/scheduler-mcp-server.cjs (the MCP server), so it must load outside
|
|
7
|
+
* Electron: requires only node built-ins, ../util/atomicFs.cjs and
|
|
8
|
+
* ../git/gitExec.cjs.
|
|
9
|
+
*
|
|
10
|
+
* - findUnfilledPlaceholders: version-ish template tokens left in a message
|
|
11
|
+
* ('{version}', '{{appVersion}}', '${release}', '<semver>', ...).
|
|
12
|
+
* - findSessionManagerVersions: the x.y.z a message names as a Session
|
|
13
|
+
* Manager release ('Session Manager 0.143.0', 'SM v0.143.0').
|
|
14
|
+
* - normalizeReleaseClaim: validates a caller's `{ commits }` claim.
|
|
15
|
+
* - isSessionManagerRepo / checkReleaseContains: verify with git that tag
|
|
16
|
+
* v<version> contains every claimed commit. Never throws.
|
|
17
|
+
*/
|
|
18
|
+
'use strict';
|
|
19
|
+
|
|
20
|
+
const path = require('node:path');
|
|
21
|
+
const { readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
22
|
+
|
|
23
|
+
const SM_PACKAGE_NAME = 'claude-code-session-manager';
|
|
24
|
+
const VERSION_RE = /^\d+\.\d+\.\d+$/;
|
|
25
|
+
const COMMIT_RE = /^[0-9a-f]{7,40}$/i;
|
|
26
|
+
const MAX_COMMITS = 20;
|
|
27
|
+
|
|
28
|
+
/** True only for a string of 7-40 hex chars (either case) — the one commit-hash rule. */
|
|
29
|
+
function isCommitHash(v) {
|
|
30
|
+
return typeof v === 'string' && COMMIT_RE.test(v);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const PLACEHOLDER_NAMES = [
|
|
34
|
+
'version', 'appversion', 'app_version', 'app-version', 'release',
|
|
35
|
+
'releaseversion', 'release_version', 'smversion', 'sm_version', 'semver',
|
|
36
|
+
];
|
|
37
|
+
// Longest first so alternation never stops at a prefix ('release' vs 'release_version').
|
|
38
|
+
const NAME_ALT = PLACEHOLDER_NAMES.slice()
|
|
39
|
+
.sort((a, b) => b.length - a.length)
|
|
40
|
+
.map((n) => n.replace(/[-_]/g, (c) => `\\${c}`))
|
|
41
|
+
.join('|');
|
|
42
|
+
const INNER = `[ \\t]*(?:${NAME_ALT})[ \\t]*`;
|
|
43
|
+
// Two-char openers before one-char ones so '{{x}}' / '${x}' match whole.
|
|
44
|
+
const PLACEHOLDER_SRC = [
|
|
45
|
+
`\\{\\{${INNER}\\}\\}`,
|
|
46
|
+
`\\$\\{${INNER}\\}`,
|
|
47
|
+
`\\{${INNER}\\}`,
|
|
48
|
+
`<${INNER}>`,
|
|
49
|
+
`\\[${INNER}\\]`,
|
|
50
|
+
`%${INNER}%`,
|
|
51
|
+
].join('|');
|
|
52
|
+
|
|
53
|
+
function findUnfilledPlaceholders(message, opts = {}) {
|
|
54
|
+
if (typeof message !== 'string') return [];
|
|
55
|
+
const allowVersionToken = !!(opts && opts.allowVersionToken);
|
|
56
|
+
const re = new RegExp(PLACEHOLDER_SRC, 'gi');
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const m of message.matchAll(re)) {
|
|
59
|
+
const tok = m[0];
|
|
60
|
+
if (allowVersionToken && tok === '{version}') continue;
|
|
61
|
+
if (!out.includes(tok)) out.push(tok);
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const SM_VERSION_SRC = '\\b(?:[Ss][Ee][Ss][Ss][Ii][Oo][Nn] [Mm][Aa][Nn][Aa][Gg][Ee][Rr]|SM)'
|
|
67
|
+
+ '(?:\\s+(?:release|version|app))?\\s+v?(\\d+\\.\\d+\\.\\d+)\\b';
|
|
68
|
+
|
|
69
|
+
function findSessionManagerVersions(message) {
|
|
70
|
+
if (typeof message !== 'string') return [];
|
|
71
|
+
const out = [];
|
|
72
|
+
for (const m of message.matchAll(new RegExp(SM_VERSION_SRC, 'g'))) {
|
|
73
|
+
if (!out.includes(m[1])) out.push(m[1]);
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function isPlainObject(v) {
|
|
79
|
+
if (!v || typeof v !== 'object' || Array.isArray(v)) return false;
|
|
80
|
+
const proto = Object.getPrototypeOf(v);
|
|
81
|
+
return proto === Object.prototype || proto === null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeReleaseClaim(raw) {
|
|
85
|
+
const fail = (error) => ({ ok: false, error });
|
|
86
|
+
if (!isPlainObject(raw)) return fail('release must be an object { commits: [...] }');
|
|
87
|
+
const keys = Object.keys(raw);
|
|
88
|
+
if (keys.length !== 1 || keys[0] !== 'commits') {
|
|
89
|
+
return fail('release must have exactly one key, commits');
|
|
90
|
+
}
|
|
91
|
+
const { commits } = raw;
|
|
92
|
+
if (!Array.isArray(commits) || commits.length < 1 || commits.length > MAX_COMMITS) {
|
|
93
|
+
return fail(`release.commits must be an array of 1-${MAX_COMMITS} commit hashes`);
|
|
94
|
+
}
|
|
95
|
+
const out = [];
|
|
96
|
+
for (const c of commits) {
|
|
97
|
+
if (!isCommitHash(c)) {
|
|
98
|
+
return fail(`release.commits has an invalid commit hash: ${JSON.stringify(c)}`);
|
|
99
|
+
}
|
|
100
|
+
const lc = c.toLowerCase();
|
|
101
|
+
if (!out.includes(lc)) out.push(lc);
|
|
102
|
+
}
|
|
103
|
+
return { ok: true, value: { commits: out } };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isSessionManagerRepo(cwd) {
|
|
107
|
+
if (typeof cwd !== 'string' || !cwd) return false;
|
|
108
|
+
let pkg;
|
|
109
|
+
try {
|
|
110
|
+
pkg = readJsonOrSync(path.join(cwd, 'package.json'), null);
|
|
111
|
+
} catch {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
return !!pkg && typeof pkg === 'object' && !Array.isArray(pkg) && pkg.name === SM_PACKAGE_NAME;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function defaultRunGit(cwd, args) {
|
|
118
|
+
const { execGit } = require('../git/gitExec.cjs');
|
|
119
|
+
return execGit(cwd, args, { timeout: 15000 });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function checkReleaseContains(input, opts = {}) {
|
|
123
|
+
try {
|
|
124
|
+
const { repoCwd, version, commits } = input || {};
|
|
125
|
+
if (typeof version !== 'string' || !VERSION_RE.test(version)) {
|
|
126
|
+
return { ok: false, error: `release version ${JSON.stringify(version)} is not x.y.z` };
|
|
127
|
+
}
|
|
128
|
+
if (typeof repoCwd !== 'string' || !repoCwd) {
|
|
129
|
+
return { ok: false, error: 'no repository to check the release against' };
|
|
130
|
+
}
|
|
131
|
+
const claim = normalizeReleaseClaim({ commits });
|
|
132
|
+
if (!claim.ok) return { ok: false, error: claim.error };
|
|
133
|
+
const runGit = (opts && typeof opts.runGit === 'function') ? opts.runGit : defaultRunGit;
|
|
134
|
+
const tag = `v${version}`;
|
|
135
|
+
const git = async (args) => { await runGit(repoCwd, args); };
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await git(['rev-parse', '-q', '--verify', `refs/tags/${tag}^{commit}`]);
|
|
139
|
+
} catch {
|
|
140
|
+
return { ok: false, error: `release tag ${tag} does not exist` };
|
|
141
|
+
}
|
|
142
|
+
for (const c of claim.value.commits) {
|
|
143
|
+
try {
|
|
144
|
+
await git(['rev-parse', '-q', '--verify', `${c}^{commit}`]);
|
|
145
|
+
} catch {
|
|
146
|
+
return { ok: false, error: `commit ${c} is not known to this repository` };
|
|
147
|
+
}
|
|
148
|
+
try {
|
|
149
|
+
await git(['merge-base', '--is-ancestor', c, tag]);
|
|
150
|
+
} catch {
|
|
151
|
+
return { ok: false, error: `release tag ${tag} does not contain commit ${c}` };
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { ok: true, tag };
|
|
155
|
+
} catch (err) {
|
|
156
|
+
return { ok: false, error: `release check failed: ${err && err.message ? err.message : String(err)}` };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
findUnfilledPlaceholders,
|
|
162
|
+
findSessionManagerVersions,
|
|
163
|
+
normalizeReleaseClaim,
|
|
164
|
+
isSessionManagerRepo,
|
|
165
|
+
checkReleaseContains,
|
|
166
|
+
isCommitHash,
|
|
167
|
+
MAX_COMMITS,
|
|
168
|
+
};
|
|
@@ -25,16 +25,23 @@
|
|
|
25
25
|
* in another project; events_read keeps epic_state_changed rows only for a
|
|
26
26
|
* ledger (cwd, epicId) and epic_cross_project_reply rows only for a ledger
|
|
27
27
|
* (fromCwd, fromEpicId).
|
|
28
|
+
* - project_create is pinned to the pairing's owner-approved projects folder:
|
|
29
|
+
* no service.projectRoot -> refused (403, 'refused:projectRoot'); a given
|
|
30
|
+
* parentDir that does not path.resolve() to projectRoot -> refused (403,
|
|
31
|
+
* 'refused:parentDir'); otherwise the route gets parentDir = projectRoot and
|
|
32
|
+
* fromCwd = service.homeCwd (a caller's fromCwd is overwritten).
|
|
28
33
|
*
|
|
29
34
|
* response is null for a notification (no id). audit is null for anything but
|
|
30
35
|
* tools/call, else { tool, result } (result: 'ok' | 'error:<status>' |
|
|
31
|
-
* 'refused:scope' | 'refused:fromCwd' | 'refused:ledger' |
|
|
36
|
+
* 'refused:scope' | 'refused:fromCwd' | 'refused:ledger' |
|
|
37
|
+
* 'refused:projectRoot' | 'refused:parentDir' | 'error:invalid-params'
|
|
32
38
|
* | 'error:invoke').
|
|
33
39
|
*
|
|
34
40
|
* No Electron, no I/O of its own.
|
|
35
41
|
*/
|
|
36
42
|
'use strict';
|
|
37
43
|
|
|
44
|
+
const path = require('node:path');
|
|
38
45
|
const { SERVICE_TOOLS, EVENTS_READ_KINDS } = require('./serviceMcpTools.cjs');
|
|
39
46
|
const { SUPPORTED_PROTOCOL_VERSIONS } = require('../mcpStdioServer.cjs');
|
|
40
47
|
|
|
@@ -160,6 +167,27 @@ async function runTool(tool, args, { service, invoke, store }) {
|
|
|
160
167
|
}
|
|
161
168
|
return { answer, result: isOk(answer) ? 'ok' : `error:${answer.status}` };
|
|
162
169
|
}
|
|
170
|
+
case 'project_create': {
|
|
171
|
+
const projectRoot = typeof service.projectRoot === 'string' && service.projectRoot !== '' ? service.projectRoot : null;
|
|
172
|
+
if (projectRoot === null) {
|
|
173
|
+
return {
|
|
174
|
+
answer: { status: 403, json: { ok: false, error: 'this pairing has no approved projects folder; re-pair to grant project_create' } },
|
|
175
|
+
result: 'refused:projectRoot',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const given = args.parentDir;
|
|
179
|
+
if (given !== undefined && given !== null && given !== ''
|
|
180
|
+
&& (typeof given !== 'string' || given.includes('\0') || path.resolve(given) !== projectRoot)) {
|
|
181
|
+
return {
|
|
182
|
+
answer: { status: 403, json: { ok: false, error: 'parentDir must be the projects folder approved at pairing', projectRoot } },
|
|
183
|
+
result: 'refused:parentDir',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const req = tool.toRequest({ ...args, parentDir: projectRoot });
|
|
187
|
+
req.body = { ...req.body, parentDir: projectRoot, fromCwd: service.homeCwd };
|
|
188
|
+
const answer = await callInvoke(invoke, req);
|
|
189
|
+
return { answer, result: isOk(answer) ? 'ok' : `error:${answer.status}` };
|
|
190
|
+
}
|
|
163
191
|
default: {
|
|
164
192
|
const answer = await callInvoke(invoke, tool.toRequest(args));
|
|
165
193
|
return { answer, result: isOk(answer) ? 'ok' : `error:${answer.status}` };
|
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
* macro_run({ cwd, id, inputs?, effort?, externalRef? }) -> POST /admin/macros/run
|
|
11
11
|
* epic_get({ cwd, id | externalRef, receipt? }) -> GET /admin/epic?cwd=&id=|externalRef=&receipt=1
|
|
12
12
|
* events_read({ after?, kinds?, limit? }) -> GET /admin/events?after=&kinds=&limit=
|
|
13
|
+
* project_create({ name, externalRef, github?, parentDir? }) -> POST /admin/projects/create
|
|
13
14
|
*
|
|
14
15
|
* The four tools the stdio server (scripts/scheduler-mcp-server.cjs) also
|
|
15
16
|
* serves share their inputSchema OBJECTS with it — that server imports them
|
|
16
17
|
* from here, so a service and a local agent see the same names and schemas.
|
|
17
18
|
* Their descriptions come from mcpToolCatalog.cjs via composeDescription.
|
|
18
19
|
*
|
|
19
|
-
* macro_run and
|
|
20
|
+
* macro_run, events_read and project_create are SERVICE-ONLY in v1: they are not catalog
|
|
20
21
|
* entries (the external-contract fingerprint stays put) and the stdio server
|
|
21
22
|
* never registers them — a local agent keeps no Epic-starting tool
|
|
22
23
|
* (SINGLE-CREATOR law). No inputSchema uses a top-level oneOf/anyOf (the
|
|
@@ -166,6 +167,31 @@ const EVENTS_READ_INPUT_SCHEMA = {
|
|
|
166
167
|
},
|
|
167
168
|
};
|
|
168
169
|
|
|
170
|
+
const PROJECT_CREATE_INPUT_SCHEMA = {
|
|
171
|
+
type: 'object',
|
|
172
|
+
properties: {
|
|
173
|
+
name: { type: 'string', description: 'Folder name of the new project (becomes <projects folder>/<name>).' },
|
|
174
|
+
externalRef: {
|
|
175
|
+
type: 'string',
|
|
176
|
+
description: 'Your own id for this project. A repeat call with the same externalRef creates nothing new and answers status existing.',
|
|
177
|
+
},
|
|
178
|
+
github: {
|
|
179
|
+
type: ['boolean', 'object'],
|
|
180
|
+
description: 'Optional: also create a GitHub repo and set it as origin. Pass true (create the repo with defaults), '
|
|
181
|
+
+ 'false (no repo, same as omitting it), or { private: true, owner? } (create it private, optionally under a given owner).',
|
|
182
|
+
properties: {
|
|
183
|
+
private: { type: 'boolean', description: 'Create the repo private (true).' },
|
|
184
|
+
owner: { type: 'string', description: 'Optional: GitHub user or org to own the repo; defaults to the signed-in account.' },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
parentDir: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
description: 'Optional: the projects folder. Only the folder the owner approved at pairing is accepted; omit it to use that folder.',
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
required: ['name', 'externalRef'],
|
|
193
|
+
};
|
|
194
|
+
|
|
169
195
|
const CATALOG_BY_NAME = new Map(MCP_TOOL_CATALOG.map((entry) => [entry.name, entry]));
|
|
170
196
|
|
|
171
197
|
function catalogDescription(name) {
|
|
@@ -258,6 +284,20 @@ const SERVICE_TOOLS = Object.freeze([
|
|
|
258
284
|
return { method: 'GET', path: '/admin/events', query };
|
|
259
285
|
},
|
|
260
286
|
},
|
|
287
|
+
{
|
|
288
|
+
name: 'project_create',
|
|
289
|
+
description: 'Create a new project folder in the projects folder the owner approved at pairing: git with one empty '
|
|
290
|
+
+ 'commit, the Session Manager operations root, and optionally a private GitHub repo (github: { private: true }) set '
|
|
291
|
+
+ 'as origin. Idempotent by externalRef: a repeat answers status existing with the same cwd and repo. Then open its '
|
|
292
|
+
+ 'first session with feedback_open_session (toCwd = cwd). Answer: { ok, status, cwd, name, externalRef, repo, github? }.',
|
|
293
|
+
inputSchema: PROJECT_CREATE_INPUT_SCHEMA,
|
|
294
|
+
toRequest: (args) => {
|
|
295
|
+
const body = { name: args?.name, externalRef: args?.externalRef };
|
|
296
|
+
if (args?.github !== undefined) body.github = args.github;
|
|
297
|
+
if (args?.parentDir !== undefined) body.parentDir = args.parentDir;
|
|
298
|
+
return { method: 'POST', path: '/admin/projects/create', body };
|
|
299
|
+
},
|
|
300
|
+
},
|
|
261
301
|
].map((tool) => Object.freeze(tool)));
|
|
262
302
|
|
|
263
303
|
// Fail at require time if the tool list and the pairing grant list drift.
|
|
@@ -269,7 +309,7 @@ const SERVICE_TOOLS = Object.freeze([
|
|
|
269
309
|
}
|
|
270
310
|
|
|
271
311
|
/** Names served only to a paired service, never by the local stdio server. */
|
|
272
|
-
const SERVICE_ONLY_TOOL_NAMES = Object.freeze(['macro_run', 'events_read']);
|
|
312
|
+
const SERVICE_ONLY_TOOL_NAMES = Object.freeze(['macro_run', 'events_read', 'project_create']);
|
|
273
313
|
|
|
274
314
|
module.exports = {
|
|
275
315
|
SERVICE_TOOLS,
|
|
@@ -281,4 +321,5 @@ module.exports = {
|
|
|
281
321
|
EPIC_GET_INPUT_SCHEMA,
|
|
282
322
|
MACRO_RUN_INPUT_SCHEMA,
|
|
283
323
|
EVENTS_READ_INPUT_SCHEMA,
|
|
324
|
+
PROJECT_CREATE_INPUT_SCHEMA,
|
|
284
325
|
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/**
|
|
3
|
+
* servicePairLocalRoutes.cjs — POST /admin/services/pair-local (start) and
|
|
4
|
+
* POST /admin/services/pair-local/confirm on the token-guarded loopback admin
|
|
5
|
+
* transport, so a same-machine agent can pair a service with no window step.
|
|
6
|
+
* Auth is the transport's job (401 before the handler runs).
|
|
7
|
+
*/
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const { z } = require('zod');
|
|
11
|
+
|
|
12
|
+
/** @param {string} error */
|
|
13
|
+
function statusOf(error) {
|
|
14
|
+
if (error === 'web_remote_off' || error === 'no_paired_device') return 409;
|
|
15
|
+
if (error === 'not_local_pairing' || error === 'no_pending_service') return 404;
|
|
16
|
+
if (error === 'sas_mismatch') return 403;
|
|
17
|
+
return 400;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{ registerRoute: (method: string, path: string, handler: (req: import('node:http').IncomingMessage, res: import('node:http').ServerResponse) => Promise<void>) => void }} adminHttp
|
|
22
|
+
* @param {{ webRemote?: any }} [opts]
|
|
23
|
+
*/
|
|
24
|
+
function registerAdminRoute(adminHttp, { webRemote } = {}) {
|
|
25
|
+
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
26
|
+
const { SERVICE_TOOL_NAMES } = require('./servicePairings.cjs');
|
|
27
|
+
const wr = () => webRemote || require('../../webRemote.cjs');
|
|
28
|
+
const path = require('node:path');
|
|
29
|
+
|
|
30
|
+
const startSchema = z.object({
|
|
31
|
+
name: z.string().min(1).max(80),
|
|
32
|
+
homeCwd: z.string().min(1).refine((p) => path.isAbsolute(p), 'homeCwd must be an absolute path'),
|
|
33
|
+
tools: z.array(z.enum(/** @type {[string, ...string[]]} */ (SERVICE_TOOL_NAMES))).min(1),
|
|
34
|
+
projectRoot: z.string().min(1).optional(),
|
|
35
|
+
}).strict();
|
|
36
|
+
const confirmSchema = z.object({
|
|
37
|
+
pairingId: z.string().min(1),
|
|
38
|
+
sas: z.string().regex(/^\d{6}$/),
|
|
39
|
+
}).strict();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @template {z.ZodTypeAny} S
|
|
43
|
+
* @param {import('node:http').IncomingMessage} req @param {import('node:http').ServerResponse} res @param {S} schema
|
|
44
|
+
* @returns {Promise<z.infer<S> | null>}
|
|
45
|
+
*/
|
|
46
|
+
async function parse(req, res, schema) {
|
|
47
|
+
const raw = await readBody(req);
|
|
48
|
+
let json;
|
|
49
|
+
try {
|
|
50
|
+
json = raw ? JSON.parse(raw) : {};
|
|
51
|
+
} catch {
|
|
52
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const r = schema.safeParse(json);
|
|
56
|
+
if (!r.success) {
|
|
57
|
+
const i = r.error.issues[0];
|
|
58
|
+
sendJson(res, 400, { ok: false, error: `${(i.path || []).join('.') || 'body'}: ${i.message}` });
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
return r.data;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
adminHttp.registerRoute('POST', '/admin/services/pair-local', async (req, res) => {
|
|
65
|
+
const b = await parse(req, res, startSchema);
|
|
66
|
+
if (!b) return;
|
|
67
|
+
const r = await wr().servicePairStartLocal({ name: b.name, homeCwd: b.homeCwd, scope: b.tools, projectRoot: b.projectRoot });
|
|
68
|
+
if (!r || !r.ok) {
|
|
69
|
+
const error = (r && r.error) || 'pairing failed';
|
|
70
|
+
sendJson(res, statusOf(error), { ok: false, error });
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const { code, pairingId, codeExpiresAt, deviceId } = r;
|
|
74
|
+
sendJson(res, 200, { ok: true, code, pairingId, codeExpiresAt, deviceId });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
adminHttp.registerRoute('POST', '/admin/services/pair-local/confirm', async (req, res) => {
|
|
78
|
+
const b = await parse(req, res, confirmSchema);
|
|
79
|
+
if (!b) return;
|
|
80
|
+
const r = await wr().confirmServiceSasLocal(b.pairingId, b.sas);
|
|
81
|
+
if (!r || !r.ok) {
|
|
82
|
+
const error = (r && r.error) || 'confirm failed';
|
|
83
|
+
sendJson(res, statusOf(error), { ok: false, error });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const { pubKey: _omit, ...service } = r.service || {};
|
|
87
|
+
sendJson(res, 200, { ok: true, service });
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = { registerAdminRoute };
|
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
* File (default ~/.claude/session-manager/remote-services.json, mode 0600):
|
|
8
8
|
* { version: 1, pending: [...], services: [...] }
|
|
9
9
|
*
|
|
10
|
-
* - pending: { pairingId, name, homeCwd, scope, createdAt, expiresAt } — a
|
|
10
|
+
* - pending: { pairingId, name, homeCwd, scope, projectRoot, createdAt, expiresAt } — a
|
|
11
11
|
* pairing the owner started; lives 10 minutes (the relay code itself lasts 5).
|
|
12
|
-
* - services: { serviceId, name, homeCwd, scope, pubKey, relayClientId,
|
|
12
|
+
* - services: { serviceId, name, homeCwd, scope, projectRoot, pubKey, relayClientId,
|
|
13
13
|
* pairedAt, lastSeenAt, opened: [{ cwd, epicId, externalRef?, at }] } — a
|
|
14
14
|
* confirmed service with its pinned P-256 public key and the ledger of Epics
|
|
15
15
|
* it opened (newest 1000), each keyed by project + id: an Epic id matches
|
|
16
16
|
* only in the project the service opened it in.
|
|
17
|
+
* - projectRoot: the owner-approved projects folder project_create creates
|
|
18
|
+
* into — required when scope grants project_create, null otherwise (and for
|
|
19
|
+
* a record saved before the field existed).
|
|
17
20
|
*
|
|
18
21
|
* State is read once from disk (missing/corrupt = empty) and kept in memory;
|
|
19
22
|
* every mutation is written atomically, serialized through one queue. Reads
|
|
@@ -40,6 +43,7 @@ const SERVICE_TOOL_NAMES = Object.freeze([
|
|
|
40
43
|
'macro_run',
|
|
41
44
|
'epic_get',
|
|
42
45
|
'events_read',
|
|
46
|
+
'project_create',
|
|
43
47
|
]);
|
|
44
48
|
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
45
49
|
|
|
@@ -62,6 +66,15 @@ function validateHomeCwd(homeCwd) {
|
|
|
62
66
|
return homeCwd;
|
|
63
67
|
}
|
|
64
68
|
|
|
69
|
+
/** Required (absolute, no NUL, resolved) when the scope grants project_create; null otherwise. */
|
|
70
|
+
function validateProjectRoot(projectRoot, scope) {
|
|
71
|
+
if (!scope.includes('project_create')) return null;
|
|
72
|
+
if (typeof projectRoot !== 'string' || projectRoot.length === 0 || !path.isAbsolute(projectRoot) || projectRoot.includes('\0')) {
|
|
73
|
+
throw new Error('projectRoot must be an absolute path when scope includes project_create');
|
|
74
|
+
}
|
|
75
|
+
return path.resolve(projectRoot);
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
function validateScope(scope) {
|
|
66
79
|
if (!Array.isArray(scope) || scope.length === 0) throw new Error('scope must be a non-empty list of tool names');
|
|
67
80
|
for (const t of scope) {
|
|
@@ -107,31 +120,52 @@ function validateExternalRef(externalRef) {
|
|
|
107
120
|
return externalRef;
|
|
108
121
|
}
|
|
109
122
|
|
|
123
|
+
const PAIRED_VIA = ['window', 'local'];
|
|
124
|
+
|
|
110
125
|
function publicService(s) {
|
|
111
126
|
return {
|
|
112
127
|
serviceId: s.serviceId,
|
|
113
128
|
name: s.name,
|
|
114
129
|
homeCwd: s.homeCwd,
|
|
115
130
|
scope: [...s.scope],
|
|
131
|
+
projectRoot: typeof s.projectRoot === 'string' ? s.projectRoot : null,
|
|
116
132
|
pubKey: s.pubKey,
|
|
117
133
|
relayClientId: s.relayClientId,
|
|
118
134
|
pairedAt: s.pairedAt,
|
|
119
135
|
lastSeenAt: s.lastSeenAt,
|
|
136
|
+
pairedVia: s.pairedVia === 'local' ? 'local' : 'window',
|
|
120
137
|
};
|
|
121
138
|
}
|
|
122
139
|
|
|
123
140
|
function publicPending(p) {
|
|
124
|
-
return {
|
|
141
|
+
return {
|
|
142
|
+
pairingId: p.pairingId,
|
|
143
|
+
name: p.name,
|
|
144
|
+
homeCwd: p.homeCwd,
|
|
145
|
+
scope: [...p.scope],
|
|
146
|
+
projectRoot: typeof p.projectRoot === 'string' ? p.projectRoot : null,
|
|
147
|
+
createdAt: p.createdAt,
|
|
148
|
+
expiresAt: p.expiresAt,
|
|
149
|
+
pairedVia: p.pairedVia === 'local' ? 'local' : 'window',
|
|
150
|
+
};
|
|
125
151
|
}
|
|
126
152
|
|
|
127
153
|
function normalizeLoaded(raw) {
|
|
128
154
|
const empty = { version: STORE_VERSION, pending: [], services: [] };
|
|
129
155
|
if (!raw || typeof raw !== 'object') return empty;
|
|
130
|
-
const
|
|
156
|
+
const rootOf = (x) => (typeof x.projectRoot === 'string' && x.projectRoot !== '' ? x.projectRoot : null);
|
|
157
|
+
const pending = Array.isArray(raw.pending)
|
|
158
|
+
? raw.pending.filter((p) => p && typeof p.pairingId === 'string').map((p) => ({ ...p, projectRoot: rootOf(p) }))
|
|
159
|
+
: [];
|
|
131
160
|
const services = Array.isArray(raw.services)
|
|
132
161
|
? raw.services
|
|
133
162
|
.filter((s) => s && typeof s.serviceId === 'string' && typeof s.pubKey === 'string')
|
|
134
|
-
.map((s) => ({
|
|
163
|
+
.map((s) => ({
|
|
164
|
+
...s,
|
|
165
|
+
scope: Array.isArray(s.scope) ? s.scope : [],
|
|
166
|
+
projectRoot: rootOf(s),
|
|
167
|
+
opened: Array.isArray(s.opened) ? s.opened : [],
|
|
168
|
+
}))
|
|
135
169
|
: [];
|
|
136
170
|
return { version: STORE_VERSION, pending, services };
|
|
137
171
|
}
|
|
@@ -173,15 +207,19 @@ function createServicePairings({ filePath, now } = {}) {
|
|
|
173
207
|
}
|
|
174
208
|
|
|
175
209
|
return {
|
|
176
|
-
createPending({ name, homeCwd, scope } = /** @type {any} */ ({})) {
|
|
210
|
+
createPending({ name, homeCwd, scope, projectRoot, pairedVia = 'window' } = /** @type {any} */ ({})) {
|
|
177
211
|
let entry;
|
|
178
212
|
try {
|
|
179
213
|
const t = clock();
|
|
214
|
+
if (!PAIRED_VIA.includes(pairedVia)) throw new Error(`pairedVia must be one of: ${PAIRED_VIA.join(', ')}`);
|
|
215
|
+
const grants = validateScope(scope);
|
|
180
216
|
entry = {
|
|
181
217
|
pairingId: crypto.randomUUID(),
|
|
182
218
|
name: validateName(name),
|
|
183
219
|
homeCwd: validateHomeCwd(homeCwd),
|
|
184
|
-
scope:
|
|
220
|
+
scope: grants,
|
|
221
|
+
projectRoot: validateProjectRoot(projectRoot, grants),
|
|
222
|
+
pairedVia,
|
|
185
223
|
createdAt: t,
|
|
186
224
|
expiresAt: t + PENDING_TTL_MS,
|
|
187
225
|
};
|
|
@@ -226,10 +264,12 @@ function createServicePairings({ filePath, now } = {}) {
|
|
|
226
264
|
name: p.name,
|
|
227
265
|
homeCwd: p.homeCwd,
|
|
228
266
|
scope: [...p.scope],
|
|
267
|
+
projectRoot: typeof p.projectRoot === 'string' ? p.projectRoot : null,
|
|
229
268
|
pubKey: key,
|
|
230
269
|
relayClientId: relayId,
|
|
231
270
|
pairedAt: t,
|
|
232
271
|
lastSeenAt: t,
|
|
272
|
+
pairedVia: p.pairedVia === 'local' ? 'local' : 'window',
|
|
233
273
|
opened: [],
|
|
234
274
|
};
|
|
235
275
|
s.services.push(svc);
|