claude-code-session-manager 0.125.1 → 0.127.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/bin/cli.cjs +71 -9
- package/bin/supervise.cjs +84 -0
- package/dist/assets/{AgentLibrary-DjEH5SoY.js → AgentLibrary-DKQznr7o.js} +1 -1
- package/dist/assets/{Button-B8NLivk-.js → Button-CZXqmIiM.js} +1 -1
- package/dist/assets/{DataModel-CHiBk8m_.js → DataModel-piyV33To.js} +1 -1
- package/dist/assets/{History-DttgrJO0.js → History-BxwtrKF2.js} +1 -1
- package/dist/assets/{Hooks-Bvy0BH1u.js → Hooks-DogeSPII.js} +1 -1
- package/dist/assets/{Library-UbBOgkkP.js → Library-BDt6EeQQ.js} +1 -1
- package/dist/assets/{ListDetail-xOyOpVZX.js → ListDetail-CwS-LKar.js} +1 -1
- package/dist/assets/{McpServers-CoGL0ddv.js → McpServers-D2HVljgS.js} +1 -1
- package/dist/assets/{Memory-Cise856d.js → Memory-hNzuOGn8.js} +1 -1
- package/dist/assets/{Panel-Cj72VO5s.js → Panel-BLDrsUeq.js} +1 -1
- package/dist/assets/{Permissions-BoJ9AB-G.js → Permissions-DzZ5vaJW.js} +1 -1
- package/dist/assets/{Plugins-DfT24sAZ.js → Plugins-Cz9yaxzG.js} +2 -2
- package/dist/assets/{ProvenanceBadge-ChkIslT4.js → ProvenanceBadge-CCgLO4m9.js} +1 -1
- package/dist/assets/{SaveBar-RCXr0jey.js → SaveBar-Shmn699J.js} +1 -1
- package/dist/assets/{Scheduler-B70tknnx.js → Scheduler-Bqr0WHNd.js} +1 -1
- package/dist/assets/{ScopeSwitcher-p_tgO5Sa.js → ScopeSwitcher-CBx1fB5g.js} +1 -1
- package/dist/assets/{Settings-wHiAxTfI.js → Settings-Ci8in-yF.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-D_Pt35vb.js → SkillReferenceGraph-BWwljba8.js} +1 -1
- package/dist/assets/{Skills-DUvOrgw9.js → Skills-BON6o-c4.js} +1 -1
- package/dist/assets/{SystemPrompt-BrNIdy68.js → SystemPrompt-D5epIYYs.js} +1 -1
- package/dist/assets/{TagLibrary-CDRatxXG.js → TagLibrary-C2qDZROJ.js} +1 -1
- package/dist/assets/{TiptapBody-BF8PxUDj.js → TiptapBody-SZhI3-bW.js} +1 -1
- package/dist/assets/{Toggle-CQH8NGXW.js → Toggle-C_qFDG0g.js} +1 -1
- package/dist/assets/{ViewTabs-DwnxqCVs.js → ViewTabs-C9q5WCEd.js} +1 -1
- package/dist/assets/{historyTotals-KINLTHQ4.js → historyTotals-BCl7IOhY.js} +1 -1
- package/dist/assets/{index-CfR3NU2t.js → index-CMIYLbPb.js} +581 -581
- package/dist/assets/{settingsSchema-BUcHqLnt.js → settingsSchema-BBrRBrBr.js} +1 -1
- package/dist/assets/{skillFrontmatter-BwwkyuMD.js → skillFrontmatter-B01qJk6N.js} +1 -1
- package/dist/assets/{useAgentsDirWatch-Coem9Wg-.js → useAgentsDirWatch-CuR3GSjS.js} +1 -1
- package/dist/index.html +1 -1
- package/dist-web/{assets/app.js → app.js} +351 -351
- package/dist-web/index.html +2 -2
- package/package.json +2 -2
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/develop/SKILL.md +3 -2
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +10 -2
- package/scripts/scheduler-mcp-server.cjs +56 -5
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +73 -6
- package/src/main/crashDiagnostics.cjs +83 -8
- package/src/main/health.cjs +16 -5
- package/src/main/index.cjs +32 -0
- package/src/main/lib/chatBootRecovery.cjs +136 -0
- package/src/main/lib/chatInflight.cjs +88 -0
- package/src/main/lib/epic/epicDelegationStats.cjs +1 -0
- package/src/main/lib/epic/epicMint.cjs +6 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +60 -6
- package/src/main/lib/epic/epicValidationHook.cjs +14 -2
- package/src/main/lib/epic/epicWorktreeMerge.cjs +9 -1
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +102 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +130 -15
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +71 -15
- package/src/main/lib/feedback-remote/remoteAssets.cjs +25 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +13 -2
- package/src/main/lib/git/gitExec.cjs +11 -1
- package/src/main/lib/git/gitWorktree.cjs +255 -9
- package/src/main/lib/git/jobWorktree.cjs +5 -0
- package/src/main/lib/mcpToolCatalog.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +12 -1
- package/src/main/lib/persona-macro/macroLibrary.cjs +78 -3
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/prdCreate.cjs +5 -1
- package/src/main/lib/prd/prdDeclaredPaths.cjs +29 -2
- package/src/main/lib/process/childWithLog.cjs +38 -95
- package/src/main/lib/process/memoryScope.cjs +140 -0
- package/src/main/lib/process/ozonePlatform.cjs +15 -0
- package/src/main/lib/process/procIdentity.cjs +10 -3
- package/src/main/lib/process/scopeOomPolicy.cjs +69 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -1
- package/src/main/lib/scheduler/cpuSample.cjs +147 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +40 -0
- package/src/main/lib/scheduler/jobLeftovers.cjs +204 -0
- package/src/main/lib/scheduler/jobSupervisorRecord.cjs +2 -1
- package/src/main/lib/scheduler/landedSinceRun.cjs +13 -5
- package/src/main/lib/scheduler/loadGate.cjs +116 -45
- package/src/main/lib/scheduler/queueStore.cjs +5 -2
- package/src/main/lib/scheduler/rcaReport.cjs +1 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +1 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +10 -3
- package/src/main/lib/scheduler/schedulerConfig.cjs +7 -2
- package/src/main/lib/telemetry/crashTelemetry.cjs +8 -4
- package/src/main/runVerify.cjs +59 -110
- package/src/main/scheduler/budget.cjs +31 -0
- package/src/main/scheduler/gitTreeGuard.cjs +51 -1
- package/src/main/scheduler/prdPaths.cjs +54 -0
- package/src/main/scheduler/reviewLadder.cjs +28 -5
- package/src/main/scheduler/starvation.cjs +22 -0
- package/src/main/scheduler.cjs +662 -90
- package/src/main/templates/PRD_AUTHORING.md +10 -3
- package/src/main/usage.cjs +4 -2
- package/src/main/webRemote.cjs +3 -0
- package/src/preload/api.d.ts +19 -3
- package/src/seed/agents/demo-video-builder.md +62 -14
- /package/dist-web/{assets/app.css → app.css} +0 -0
|
@@ -329,6 +329,7 @@ function branchNameFor(kind, key) {
|
|
|
329
329
|
* never be destroyed by this call.
|
|
330
330
|
*/
|
|
331
331
|
async function removeWorktreeDir(cwd, dir) {
|
|
332
|
+
await pinStrandedHead({ cwd, dir });
|
|
332
333
|
try {
|
|
333
334
|
await execGit(['worktree', 'remove', '--force', dir], { cwd, timeout: 15_000 });
|
|
334
335
|
} catch {
|
|
@@ -408,6 +409,7 @@ async function mainTreeFromWorktreeGitFile(dir) {
|
|
|
408
409
|
*/
|
|
409
410
|
async function teardownOrphanedCheckout(dir) {
|
|
410
411
|
const mainTree = await mainTreeFromWorktreeGitFile(dir);
|
|
412
|
+
await pinStrandedHead({ cwd: mainTree || dir, dir });
|
|
411
413
|
if (mainTree) {
|
|
412
414
|
try {
|
|
413
415
|
await execGit(['worktree', 'remove', '--force', dir], { cwd: mainTree, timeout: 15_000 });
|
|
@@ -872,7 +874,7 @@ async function createWorktree({ kind, cwd, key, fromRef }) {
|
|
|
872
874
|
// can legitimately re-fire after a transient failure) must not collide
|
|
873
875
|
// with `git worktree add`'s own branch/path checks.
|
|
874
876
|
await removeWorktreeDir(cwd, dir);
|
|
875
|
-
|
|
877
|
+
await deleteBranchKeepingUniqueCommits({ cwd, branch, key });
|
|
876
878
|
await execGit(['worktree', 'add', '-b', branch, dir, worktreeSource], { cwd, timeout: 30_000 });
|
|
877
879
|
} catch (e) {
|
|
878
880
|
activeWorktreeCount[kind] = Math.max(0, activeWorktreeCount[kind] - 1);
|
|
@@ -957,6 +959,37 @@ async function pathsIdenticalToBranch({ cwd, branch, paths }) {
|
|
|
957
959
|
return true;
|
|
958
960
|
}
|
|
959
961
|
|
|
962
|
+
/**
|
|
963
|
+
* Returns the entries of `paths` whose bytes in `dir` still equal the bytes in
|
|
964
|
+
* `cwd` (carried-but-untouched), plus entries absent from both (a carried
|
|
965
|
+
* deletion). Any read error, or a path resolving outside cwd/dir, leaves that
|
|
966
|
+
* path out. Never throws. Complexity: O(paths) — each file is read twice.
|
|
967
|
+
*/
|
|
968
|
+
async function unchangedCarriedPaths({ cwd, dir, paths }) {
|
|
969
|
+
const out = [];
|
|
970
|
+
if (!Array.isArray(paths) || !paths.length || !cwd || !dir) return out;
|
|
971
|
+
const inside = (root, abs) => {
|
|
972
|
+
const rel = path.relative(root, abs);
|
|
973
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
974
|
+
};
|
|
975
|
+
const readOrMissing = async (file) => {
|
|
976
|
+
try { return await fsp.readFile(file); }
|
|
977
|
+
catch (err) { if (err && err.code === 'ENOENT') return null; throw err; }
|
|
978
|
+
};
|
|
979
|
+
for (const p of paths) {
|
|
980
|
+
try {
|
|
981
|
+
if (typeof p !== 'string' || !p) continue;
|
|
982
|
+
const a = path.resolve(cwd, p);
|
|
983
|
+
const b = path.resolve(dir, p);
|
|
984
|
+
if (!inside(path.resolve(cwd), a) || !inside(path.resolve(dir), b)) continue;
|
|
985
|
+
const [baseBuf, wtBuf] = await Promise.all([readOrMissing(a), readOrMissing(b)]);
|
|
986
|
+
if (baseBuf === null && wtBuf === null) out.push(p);
|
|
987
|
+
else if (baseBuf !== null && wtBuf !== null && baseBuf.equals(wtBuf)) out.push(p);
|
|
988
|
+
} catch { /* read error: leave the path out */ }
|
|
989
|
+
}
|
|
990
|
+
return out;
|
|
991
|
+
}
|
|
992
|
+
|
|
960
993
|
/**
|
|
961
994
|
* Parses the path lists out of git's refusal to merge over dirty working-tree
|
|
962
995
|
* files. Git emits up to two distinct blocks — tracked paths under "local
|
|
@@ -1001,7 +1034,9 @@ function parseBlockingMergePaths(stderrText) {
|
|
|
1001
1034
|
* integrateBranch's `ok: false` results (the `reason` string is untouched).
|
|
1002
1035
|
* 'blocking_paths' = git refused up-front over dirty/untracked paths
|
|
1003
1036
|
* (auto-resolvable, PRD 1125); 'content_conflict' = a genuine 3-way
|
|
1004
|
-
* `CONFLICT (` (deterministic on every retry); '
|
|
1037
|
+
* `CONFLICT (` (deterministic on every retry); 'hook_rejected' = a git hook
|
|
1038
|
+
* (the identity guard) refused the commit — deterministic too; 'other' =
|
|
1039
|
+
* anything else.
|
|
1005
1040
|
* For content_conflict, reads the unmerged paths — MUST be called before
|
|
1006
1041
|
* `git merge --abort`, which clears them. Never throws; a failed read
|
|
1007
1042
|
* yields `conflictedPaths: []`. O(p log p) in the conflicted-path count.
|
|
@@ -1009,6 +1044,7 @@ function parseBlockingMergePaths(stderrText) {
|
|
|
1009
1044
|
async function classifyMergeFailure({ cwd, stderrText, stdoutText }) {
|
|
1010
1045
|
const blocking = parseBlockingMergePaths(stderrText);
|
|
1011
1046
|
if (blocking) return { failureKind: 'blocking_paths', blockingPaths: blocking };
|
|
1047
|
+
if (/identity-guard:/.test(`${stdoutText || ''}\n${stderrText || ''}`)) return { failureKind: 'hook_rejected' };
|
|
1012
1048
|
// git prints `CONFLICT (...)` lines on STDOUT, not stderr.
|
|
1013
1049
|
if (/CONFLICT \(/m.test(`${stdoutText || ''}\n${stderrText || ''}`)) {
|
|
1014
1050
|
let conflictedPaths = [];
|
|
@@ -1025,6 +1061,12 @@ async function classifyMergeFailure({ cwd, stderrText, stdoutText }) {
|
|
|
1025
1061
|
// a merge: one conflicted path outside this list means no auto-resolve at all.
|
|
1026
1062
|
const AUTO_RESOLVE_EXTENSIONS = new Set(['.md', '.markdown', '.txt', '.rst']);
|
|
1027
1063
|
|
|
1064
|
+
function mergeFailureReason(failureKind, text) {
|
|
1065
|
+
return failureKind === 'hook_rejected'
|
|
1066
|
+
? `merge blocked by a git hook: ${text}`
|
|
1067
|
+
: `merge failed (likely a real content conflict): ${text}`;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1028
1070
|
/**
|
|
1029
1071
|
* Renders `git merge-file -p --diff3` over the index's three conflict stages
|
|
1030
1072
|
* of `p`. Returns the merged text (with markers), or null when any stage is
|
|
@@ -1474,7 +1516,7 @@ async function integrateBranch({ cwd, branch, key, kind, carriedPaths, baseBranc
|
|
|
1474
1516
|
const retryText = (retryErr && (retryErr.stderrText || retryErr.message)) || String(retryErr);
|
|
1475
1517
|
const retryClass = await classifyMergeFailure({ cwd, stderrText: retryText, stdoutText: retryErr && retryErr.stdoutText });
|
|
1476
1518
|
try { await execGit(['merge', '--abort'], { cwd, timeout: 10_000 }); } catch { /* nothing to abort */ }
|
|
1477
|
-
return { ok: false, reason:
|
|
1519
|
+
return { ok: false, reason: mergeFailureReason(retryClass.failureKind, retryText), ...retryClass, baseHeadSha: await readHeadSha(cwd) };
|
|
1478
1520
|
}
|
|
1479
1521
|
}
|
|
1480
1522
|
}
|
|
@@ -1496,11 +1538,18 @@ async function integrateBranch({ cwd, branch, key, kind, carriedPaths, baseBranc
|
|
|
1496
1538
|
await execGit(['commit', '-m', mergeMessage], { cwd, timeout: 30_000 });
|
|
1497
1539
|
return { ok: true, integrated: true, mergeCommit: true, sha: await readHeadSha(cwd), autoResolved: 'pure_addition_concat', resolvedPaths: paths };
|
|
1498
1540
|
}
|
|
1499
|
-
} catch {
|
|
1541
|
+
} catch (autoErr) {
|
|
1542
|
+
const autoText = [autoErr && autoErr.stderrText, autoErr && autoErr.stdoutText, autoErr && autoErr.message].filter(Boolean).join('\n');
|
|
1543
|
+
if (autoText.includes('identity-guard:')) {
|
|
1544
|
+
try { await execGit(['merge', '--abort'], { cwd, timeout: 10_000 }); } catch { /* nothing to abort */ }
|
|
1545
|
+
return { ok: false, reason: mergeFailureReason('hook_rejected', autoText), failureKind: 'hook_rejected', baseHeadSha: await readHeadSha(cwd) };
|
|
1546
|
+
}
|
|
1547
|
+
/* otherwise fall through to the abort */
|
|
1548
|
+
}
|
|
1500
1549
|
}
|
|
1501
1550
|
// Abort a half-applied merge so `cwd` isn't left in a mid-merge state.
|
|
1502
1551
|
try { await execGit(['merge', '--abort'], { cwd, timeout: 10_000 }); } catch { /* nothing to abort */ }
|
|
1503
|
-
return { ok: false, reason:
|
|
1552
|
+
return { ok: false, reason: mergeFailureReason(failureClass.failureKind, stderrText), ...failureClass, baseHeadSha: await readHeadSha(cwd) };
|
|
1504
1553
|
}
|
|
1505
1554
|
}
|
|
1506
1555
|
|
|
@@ -1769,7 +1818,7 @@ async function reclaimTerminalJobOrphans({ cwd, terminalSlugs, isLive }) {
|
|
|
1769
1818
|
|
|
1770
1819
|
await removeWorktreeDir(cwd, entry.worktree);
|
|
1771
1820
|
if (entry.branch) {
|
|
1772
|
-
|
|
1821
|
+
await deleteBranchKeepingUniqueCommits({ cwd, branch: entry.branch, key: slug });
|
|
1773
1822
|
}
|
|
1774
1823
|
reclaimed.push(slug);
|
|
1775
1824
|
}
|
|
@@ -1829,15 +1878,19 @@ async function reconcileWorktreesOnBoot(cwds, opts = {}) {
|
|
|
1829
1878
|
const entries = parseWorktreeListPorcelain(out);
|
|
1830
1879
|
for (const entry of entries) {
|
|
1831
1880
|
if (!entry.worktree || !entry.worktree.startsWith(root + path.sep)) continue;
|
|
1832
|
-
const
|
|
1881
|
+
const branchKey = keyFromBranch(kind, entry.branch);
|
|
1882
|
+
// Worktree dirs are <root>/<hash>/<key>, so the basename is the slug/epic id
|
|
1883
|
+
// even when the checkout is detached or on a branch we do not own.
|
|
1884
|
+
const key = branchKey || path.basename(entry.worktree);
|
|
1833
1885
|
if (isLive && key && (await isLive(key, entry))) continue;
|
|
1834
1886
|
await removeWorktreeDir(cwd, entry.worktree);
|
|
1835
1887
|
checkoutsRemoved++;
|
|
1836
1888
|
// sm-land/* is the per-Epic integration branch, never a throwaway
|
|
1837
1889
|
// worktree branch — even if something else checked it out onto a
|
|
1838
1890
|
// worktree under this kind's root, this sweep must never delete it.
|
|
1839
|
-
|
|
1840
|
-
|
|
1891
|
+
// Only a branch of this kind's own prefix is ours to delete.
|
|
1892
|
+
if (branchKey && !entry.branch.startsWith(LAND_BRANCH_PREFIX)) {
|
|
1893
|
+
await deleteBranchKeepingUniqueCommits({ cwd, branch: entry.branch, key: branchKey });
|
|
1841
1894
|
}
|
|
1842
1895
|
}
|
|
1843
1896
|
try { await execGit(['worktree', 'prune'], { cwd, timeout: 10_000 }); } catch { /* best effort */ }
|
|
@@ -2274,7 +2327,197 @@ async function cleanupEpicWorktree({ cwd, dir, branch, keepBranch }) {
|
|
|
2274
2327
|
return cleanupWorktree({ kind: 'epic', cwd, dir, branch, keepBranch });
|
|
2275
2328
|
}
|
|
2276
2329
|
|
|
2330
|
+
// ──────────────────────────────────────────── stranded-HEAD reconciliation
|
|
2331
|
+
|
|
2332
|
+
function safePinKey(key) {
|
|
2333
|
+
return String(key || 'unknown').replace(/[^A-Za-z0-9._-]/g, '_').replace(/^\.+/, '_') || 'unknown';
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
/** Pins `sha` under STRANDED_REF_PREFIX/<key>/<sha>; returns the ref or null. Never throws. */
|
|
2337
|
+
async function pinCommit({ cwd, key, sha }) {
|
|
2338
|
+
try {
|
|
2339
|
+
const safeKey = safePinKey(key);
|
|
2340
|
+
const ref = `${sharedGitExec.STRANDED_REF_PREFIX}${safeKey}/${sha}`;
|
|
2341
|
+
await execGit(['update-ref', ref, sha], { cwd, timeout: 10_000 });
|
|
2342
|
+
return ref;
|
|
2343
|
+
} catch {
|
|
2344
|
+
return null;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
/**
|
|
2349
|
+
* Deletes `branch` (`git branch -D`), first pinning its tip under
|
|
2350
|
+
* refs/sm-stranded/<key>/ when it holds commits no other branch, tag or remote
|
|
2351
|
+
* has. A failed uniqueness check also pins (fail-safe). Never throws.
|
|
2352
|
+
*/
|
|
2353
|
+
async function deleteBranchKeepingUniqueCommits({ cwd, branch, key }) {
|
|
2354
|
+
try {
|
|
2355
|
+
let tip = null;
|
|
2356
|
+
try {
|
|
2357
|
+
tip = (await execGit(['rev-parse', '--verify', '--quiet', `refs/heads/${branch}^{commit}`], { cwd, timeout: 10_000 })).trim() || null;
|
|
2358
|
+
} catch { tip = null; }
|
|
2359
|
+
if (tip) {
|
|
2360
|
+
let unique = true;
|
|
2361
|
+
try {
|
|
2362
|
+
const out = await execGit(
|
|
2363
|
+
['rev-list', '--count', `refs/heads/${branch}`, '--not', `--exclude=${branch}`, '--branches', '--tags', '--remotes'],
|
|
2364
|
+
{ cwd, timeout: 10_000 }
|
|
2365
|
+
);
|
|
2366
|
+
const n = Number.parseInt(String(out).trim(), 10);
|
|
2367
|
+
unique = Number.isFinite(n) ? n > 0 : true;
|
|
2368
|
+
} catch { unique = true; }
|
|
2369
|
+
if (unique) await pinCommit({ cwd, key, sha: tip });
|
|
2370
|
+
}
|
|
2371
|
+
} catch { /* fall through to delete */ }
|
|
2372
|
+
try { await execGit(['branch', '-D', branch], { cwd, timeout: 10_000 }); } catch { /* already gone */ }
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
/**
|
|
2376
|
+
* Pins under refs/sm-stranded/<key>/ whose commit date is >= sinceMs and that
|
|
2377
|
+
* no branch, tag or remote holds. Returns [{ sha, ref }]; [] on any error.
|
|
2378
|
+
*/
|
|
2379
|
+
async function listStrandedPins({ cwd, key, sinceMs }) {
|
|
2380
|
+
try {
|
|
2381
|
+
const prefix = `${sharedGitExec.STRANDED_REF_PREFIX}${safePinKey(key)}/`;
|
|
2382
|
+
const out = await execGit(
|
|
2383
|
+
['for-each-ref', '--format=%(objectname)%09%(refname)%09%(committerdate:unix)', prefix],
|
|
2384
|
+
{ cwd, timeout: 10_000 }
|
|
2385
|
+
);
|
|
2386
|
+
const since = Number.isFinite(sinceMs) ? sinceMs : 0;
|
|
2387
|
+
const pins = [];
|
|
2388
|
+
for (const line of String(out).split('\n')) {
|
|
2389
|
+
if (!line.trim()) continue;
|
|
2390
|
+
const [sha, ref, ts] = line.split('\t');
|
|
2391
|
+
if (!sha || !ref) continue;
|
|
2392
|
+
if (Number(ts) * 1000 < since) continue;
|
|
2393
|
+
if ((await countCommitsOnNoRef(cwd, sha)) <= 0) continue;
|
|
2394
|
+
pins.push({ sha, ref });
|
|
2395
|
+
}
|
|
2396
|
+
return pins;
|
|
2397
|
+
} catch {
|
|
2398
|
+
return [];
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
/** True/false for `git merge-base --is-ancestor a b`; null on a real failure. */
|
|
2403
|
+
async function isAncestorOf(cwd, a, b) {
|
|
2404
|
+
try {
|
|
2405
|
+
await execGit(['merge-base', '--is-ancestor', a, b], { cwd, timeout: 10_000 });
|
|
2406
|
+
return true;
|
|
2407
|
+
} catch (e) {
|
|
2408
|
+
return e && e.code === 1 ? false : null;
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
|
|
2412
|
+
/** Commits reachable from `sha` that no branch, tag or remote holds; -1 on failure. Never throws. */
|
|
2413
|
+
async function countCommitsOnNoRef(cwd, sha) {
|
|
2414
|
+
try {
|
|
2415
|
+
const out = await execGit(['rev-list', '--count', sha, '--not', '--branches', '--tags', '--remotes'], { cwd, timeout: 10_000 });
|
|
2416
|
+
const n = Number.parseInt(String(out).trim(), 10);
|
|
2417
|
+
return Number.isFinite(n) ? n : -1;
|
|
2418
|
+
} catch {
|
|
2419
|
+
return -1;
|
|
2420
|
+
}
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
/** Commits in `from..to`; -1 on failure. Never throws. */
|
|
2424
|
+
async function countRange(cwd, from, to) {
|
|
2425
|
+
try {
|
|
2426
|
+
const out = await execGit(['rev-list', '--count', `${from}..${to}`], { cwd, timeout: 10_000 });
|
|
2427
|
+
const n = Number.parseInt(String(out).trim(), 10);
|
|
2428
|
+
return Number.isFinite(n) ? n : -1;
|
|
2429
|
+
} catch {
|
|
2430
|
+
return -1;
|
|
2431
|
+
}
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
/**
|
|
2435
|
+
* Compares a worktree's HEAD with its branch. aligned: HEAD is the tip or
|
|
2436
|
+
* behind it. on-other-ref: HEAD is held by some other branch/tag/remote (a PR
|
|
2437
|
+
* branch); no git writes. fast-forwarded: branch tip is an ancestor of HEAD and
|
|
2438
|
+
* every commit between is the run's own (held by no ref), so the branch ref
|
|
2439
|
+
* moved to HEAD (compare-and-swap update-ref). diverged: HEAD is pinned,
|
|
2440
|
+
* branch untouched. unknown: a ref did not resolve; no git writes.
|
|
2441
|
+
* Never throws.
|
|
2442
|
+
*/
|
|
2443
|
+
async function reconcileWorktreeHead({ cwd, dir, branch, key }) {
|
|
2444
|
+
let finalHead = null;
|
|
2445
|
+
let branchTip = null;
|
|
2446
|
+
try {
|
|
2447
|
+
finalHead = await tryResolveCommit(dir, 'HEAD^{commit}');
|
|
2448
|
+
branchTip = await tryResolveCommit(cwd, `refs/heads/${branch}^{commit}`);
|
|
2449
|
+
if (!finalHead || !branchTip) return { action: 'unknown', finalHead, branchTip, pinnedRef: null };
|
|
2450
|
+
if (finalHead === branchTip || (await isAncestorOf(cwd, finalHead, branchTip)) === true) {
|
|
2451
|
+
return { action: 'aligned', finalHead, branchTip, pinnedRef: null };
|
|
2452
|
+
}
|
|
2453
|
+
const unheld = await countCommitsOnNoRef(cwd, finalHead);
|
|
2454
|
+
if (unheld === 0) return { action: 'on-other-ref', finalHead, branchTip, pinnedRef: null };
|
|
2455
|
+
if (unheld > 0 && (await isAncestorOf(cwd, branchTip, finalHead)) === true
|
|
2456
|
+
&& (await countRange(cwd, branchTip, finalHead)) === unheld) {
|
|
2457
|
+
try {
|
|
2458
|
+
await execGit(['update-ref', `refs/heads/${branch}`, finalHead, branchTip], { cwd, timeout: 10_000 });
|
|
2459
|
+
return { action: 'fast-forwarded', finalHead, branchTip, pinnedRef: null };
|
|
2460
|
+
} catch { /* refused (branch moved) — fall through to diverged */ }
|
|
2461
|
+
}
|
|
2462
|
+
const pinnedRef = await pinCommit({ cwd, key: key || branch, sha: finalHead });
|
|
2463
|
+
return { action: 'diverged', finalHead, branchTip, pinnedRef };
|
|
2464
|
+
} catch {
|
|
2465
|
+
return { action: 'unknown', finalHead, branchTip, pinnedRef: null };
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* Pins commits recorded in the worktree's HEAD reflog (commit, cherry-pick,
|
|
2471
|
+
* revert) that no branch, tag or remote holds. A predecessor of a
|
|
2472
|
+
* `commit (amend)` entry is superseded and skipped. Newest first, capped at 20.
|
|
2473
|
+
* Returns [{ sha, ref }]; [] on any error. A failed count keeps the commit.
|
|
2474
|
+
*/
|
|
2475
|
+
async function pinUnlandedWorktreeCommits({ cwd, dir, branch, key }) {
|
|
2476
|
+
try {
|
|
2477
|
+
const out = await execGit(['reflog', 'show', '--format=%H%x09%gs', '-n', '200', 'HEAD'], { cwd: dir, timeout: 15_000 });
|
|
2478
|
+
const entries = out.split('\n').filter(Boolean).map((l) => {
|
|
2479
|
+
const i = l.indexOf('\t');
|
|
2480
|
+
return { sha: l.slice(0, i), subject: l.slice(i + 1) };
|
|
2481
|
+
});
|
|
2482
|
+
const candidates = [];
|
|
2483
|
+
const superseded = new Set();
|
|
2484
|
+
for (let i = 0; i < entries.length; i++) {
|
|
2485
|
+
const e = entries[i];
|
|
2486
|
+
if (!/^(commit|cherry-pick|revert)\b/.test(e.subject)) continue;
|
|
2487
|
+
if (/^commit \(amend\)/.test(e.subject) && entries[i + 1]) superseded.add(entries[i + 1].sha);
|
|
2488
|
+
candidates.push(e.sha);
|
|
2489
|
+
}
|
|
2490
|
+
const seen = new Set();
|
|
2491
|
+
const pinned = [];
|
|
2492
|
+
for (const sha of candidates) {
|
|
2493
|
+
if (pinned.length >= 20) break;
|
|
2494
|
+
if (seen.has(sha) || superseded.has(sha)) continue;
|
|
2495
|
+
seen.add(sha);
|
|
2496
|
+
if (!((await countCommitsOnNoRef(cwd, sha)) !== 0)) continue;
|
|
2497
|
+
const ref = await pinCommit({ cwd, key: key || branch, sha });
|
|
2498
|
+
if (ref) pinned.push({ sha, ref });
|
|
2499
|
+
}
|
|
2500
|
+
return pinned;
|
|
2501
|
+
} catch {
|
|
2502
|
+
return [];
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
/** Pins `dir`'s HEAD when no branch/tag/remote holds it. Swallows every error. */
|
|
2507
|
+
async function pinStrandedHead({ cwd, dir }) {
|
|
2508
|
+
try {
|
|
2509
|
+
if (!fs.existsSync(dir)) return;
|
|
2510
|
+
const out = (await execGit(['rev-list', '-1', 'HEAD', '--not', '--branches', '--tags', '--remotes'], { cwd: dir, timeout: 10_000 })).trim();
|
|
2511
|
+
if (!out) return;
|
|
2512
|
+
const head = (await execGit(['rev-parse', 'HEAD'], { cwd: dir, timeout: 10_000 })).trim();
|
|
2513
|
+
if (head) await pinCommit({ cwd: cwd || dir, key: path.basename(dir), sha: head });
|
|
2514
|
+
} catch { /* best-effort */ }
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2277
2517
|
module.exports = {
|
|
2518
|
+
reconcileWorktreeHead,
|
|
2519
|
+
pinUnlandedWorktreeCommits,
|
|
2520
|
+
resolveDefaultBranch,
|
|
2278
2521
|
KIND_CONFIG,
|
|
2279
2522
|
worktreeRootFor,
|
|
2280
2523
|
isWorktreeDisabled,
|
|
@@ -2289,6 +2532,7 @@ module.exports = {
|
|
|
2289
2532
|
createWorktree,
|
|
2290
2533
|
captureAndCarryBaseDiff,
|
|
2291
2534
|
pathsIdenticalToBranch,
|
|
2535
|
+
unchangedCarriedPaths,
|
|
2292
2536
|
resolveDefaultBranch,
|
|
2293
2537
|
getCurrentBranch,
|
|
2294
2538
|
isCarriedWipOnly,
|
|
@@ -2301,6 +2545,8 @@ module.exports = {
|
|
|
2301
2545
|
listCwdHolders,
|
|
2302
2546
|
hasLiveHolder,
|
|
2303
2547
|
reconcileWorktreesOnBoot,
|
|
2548
|
+
deleteBranchKeepingUniqueCommits,
|
|
2549
|
+
listStrandedPins,
|
|
2304
2550
|
sweepStaleWorktreeCheckouts,
|
|
2305
2551
|
mainTreeFromWorktreeGitFile,
|
|
2306
2552
|
getObservedWorktreeCount,
|
|
@@ -64,9 +64,14 @@ module.exports = {
|
|
|
64
64
|
cleanupJobWorktree: gitWorktree.cleanupJobWorktree,
|
|
65
65
|
salvageJobWorktreeDiff: gitWorktree.salvageJobWorktreeDiff,
|
|
66
66
|
salvageJobDirtyDelta: gitWorktree.salvageJobDirtyDelta,
|
|
67
|
+
reconcileWorktreeHead: gitWorktree.reconcileWorktreeHead,
|
|
68
|
+
listStrandedPins: gitWorktree.listStrandedPins,
|
|
69
|
+
pinUnlandedWorktreeCommits: gitWorktree.pinUnlandedWorktreeCommits,
|
|
70
|
+
resolveDefaultBranch: gitWorktree.resolveDefaultBranch,
|
|
67
71
|
parseWorktreeListPorcelain: gitWorktree.parseWorktreeListPorcelain,
|
|
68
72
|
reconcileWorktreesOnBoot: (cwds, opts = {}) => gitWorktree.reconcileWorktreesOnBoot(cwds, { kind: KIND, isLive: opts.isLive }),
|
|
69
73
|
reclaimTerminalJobOrphans: gitWorktree.reclaimTerminalJobOrphans,
|
|
74
|
+
unchangedCarriedPaths: gitWorktree.unchangedCarriedPaths,
|
|
70
75
|
// Test-only escape hatch for the in-memory concurrency counter.
|
|
71
76
|
_resetActiveWorktreeCountForTests(n = 0) { gitWorktree._resetActiveWorktreeCountForTests(KIND, n); },
|
|
72
77
|
_getActiveWorktreeCountForTests() { return gitWorktree._getActiveWorktreeCountForTests(KIND); },
|
|
@@ -246,7 +246,8 @@ const MCP_TOOL_CATALOG = [
|
|
|
246
246
|
whenToUse: 'Use to programmatically continue a conversation in a tab that is already open in the running app.',
|
|
247
247
|
whenNotToUse: 'Do not use to start new work in a project you are not already chatting in — that is /develop (scheduler_create_prd) or feedback_open_session.',
|
|
248
248
|
exampleArgs: { tabId: 'a1b2c3d4-tab-id', prompt: 'Please continue with the next step.' },
|
|
249
|
-
notes: '
|
|
249
|
+
notes: 'tabId is an open tab\'s id or an Epic id (Epic chats are keyed by Epic id), never a Claude session id. '
|
|
250
|
+
+ 'A refused send (unknown tab/Epic) returns ok false with disposition and reason; an unconfirmed send (no window or ack timeout) stays ok true.',
|
|
250
251
|
},
|
|
251
252
|
{
|
|
252
253
|
name: 'feedback_list_projects',
|
|
@@ -271,11 +272,14 @@ const MCP_TOOL_CATALOG = [
|
|
|
271
272
|
+ '`acceptanceCriteria`; put evidence, symptom and references in `body`. Name the file in THEIR repo '
|
|
272
273
|
+ 'that looks responsible if you know it. When one request is split into several proposals, send '
|
|
273
274
|
+ 'them ALL with one shared `series` {key, title, total} (plus each one\'s `index`) and summarise '
|
|
274
|
-
+ 'the overall plan in each motivation.
|
|
275
|
+
+ 'the overall plan in each motivation. THREE MODES: (1) agent-initiated (your own idea) = PROPOSED, a '
|
|
275
276
|
+ 'human in the receiving project must approve it; pass neither autoStart nor humanRequestQuote. '
|
|
276
277
|
+ '(2) human-requested = the human in THIS conversation explicitly asked for the work in that other '
|
|
277
278
|
+ 'project: pass `autoStart: true` plus `humanRequestQuote`, copied VERBATIM from their own message, '
|
|
278
|
-
+ '
|
|
279
|
+
+ 'whose quoted words themselves must name the target project. An unverified request silently falls back to PROPOSED. '
|
|
280
|
+
+ '(3) macro auto-start = a session launched from a macro with "Can start work in other projects" on '
|
|
281
|
+
+ 'auto-starts sends tagged `bug` or `feature` to allowed projects with no flag and no quote; otherwise it stays '
|
|
282
|
+
+ 'a proposal. Pass tag `bug` or `feature` for work you want started.',
|
|
279
283
|
whenNotToUse: 'WHEN NOT TO USE IT: for work in the project you are ALREADY in, run /develop inside the Epic you '
|
|
280
284
|
+ 'are already in — this tool refuses toCwd === fromCwd outright.',
|
|
281
285
|
exampleArgs: {
|
|
@@ -372,7 +376,7 @@ const MCP_TOOL_CATALOG = [
|
|
|
372
376
|
purpose: "List this project's HOT KEYS macros — the saved (agent, tag, prompt) one-click buttons shown "
|
|
373
377
|
+ "in the Sessions tab's HOT KEYS strip, via the session-manager app's admin API.",
|
|
374
378
|
whenToUse: 'Use to see what macros already exist for this project (including machine-wide `*` macros and '
|
|
375
|
-
+ 'built-ins) before deciding whether to add or
|
|
379
|
+
+ 'built-ins) before deciding whether to add, update or delete one.',
|
|
376
380
|
whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this only ever returns '
|
|
377
381
|
+ "macros visible to the resolved cwd, never another project's.",
|
|
378
382
|
exampleArgs: { cwd: '/home/bilko/Projects/session-manager' },
|
|
@@ -390,7 +394,8 @@ const MCP_TOOL_CATALOG = [
|
|
|
390
394
|
whenNotToUse: 'WHEN NOT TO USE IT: macros are scoped to the caller\'s own project — this call is refused if '
|
|
391
395
|
+ '`id` resolves to a macro not visible to this project. Built-in macros (`id` starting with `builtin-`) '
|
|
392
396
|
+ "cannot be edited through this route. A macro is a HUMAN's one-click button, not a task runner — never "
|
|
393
|
-
+ 'create or update one unless the human has actually asked for that macro to exist.'
|
|
397
|
+
+ 'create or update one unless the human has actually asked for that macro to exist. '
|
|
398
|
+
+ 'To remove a macro use macro_delete; never rewrite it into a placeholder.',
|
|
394
399
|
exampleArgs: {
|
|
395
400
|
cwd: '/home/bilko/Projects/session-manager',
|
|
396
401
|
label: 'Publish git + npm',
|
|
@@ -405,6 +410,23 @@ const MCP_TOOL_CATALOG = [
|
|
|
405
410
|
+ 'when pressing the macro; reference each in the prompt as {{name}}. Omitting `inputs` on update keeps '
|
|
406
411
|
+ 'the existing inputs; `[]` clears them.',
|
|
407
412
|
},
|
|
413
|
+
{
|
|
414
|
+
name: 'macro_delete',
|
|
415
|
+
group: 'macros',
|
|
416
|
+
purpose: "Remove one of this project's HOT KEYS macros via the session-manager app's admin API, through the same "
|
|
417
|
+
+ 'macroLibrary.cjs store the Sessions HOT KEYS strip reads from, so an open strip updates at once.',
|
|
418
|
+
whenToUse: 'Use when the human has asked for that macro to go, for example after its work moved to another project. '
|
|
419
|
+
+ 'Get the `id` from macro_list first.',
|
|
420
|
+
whenNotToUse: "WHEN NOT TO USE IT: a macro is a HUMAN's one-click button and this cannot be undone — never delete one "
|
|
421
|
+
+ "unless the human has asked for that macro to go. It always acts for the calling session's own project: there is "
|
|
422
|
+
+ 'no `cwd` argument, and a macro not listed for this project is refused. Built-in macros are refused. A macro shown '
|
|
423
|
+
+ 'in every project is refused too; only the human can remove it, from the HOT KEYS panel. Refused in a scheduled job '
|
|
424
|
+
+ "and outside a Session Manager session, because no human is there to ask. To change a macro, use macro_save. "
|
|
425
|
+
+ "Another project's macro belongs to that project: use feedback_open_session.",
|
|
426
|
+
exampleArgs: { id: 'blog-video-8d618a' },
|
|
427
|
+
notes: 'Returns { ok, deleted, macro }. `deleted: true` means the macro is gone and `macro` is its last copy. '
|
|
428
|
+
+ '`deleted: false` means other projects still list it, so only this project was dropped. A refusal comes back as an error result.',
|
|
429
|
+
},
|
|
408
430
|
{
|
|
409
431
|
name: 'session_manager_help',
|
|
410
432
|
group: 'help',
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
* These drive Project Home's one-click actions through the same (agent, tag,
|
|
7
7
|
* prompt) hot-key framework as user-created macros. `macroLibrary.cjs`'s
|
|
8
8
|
* `ensureBuiltins` seeds any entry here that is missing from macros.json, and
|
|
9
|
-
* upgrades
|
|
9
|
+
* upgrades a stored copy whose `builtinVersion` is behind this file when it is
|
|
10
|
+
* unedited: `updatedAt === createdAt`, OR its label/agent/tag match and its
|
|
11
|
+
* prompt is one of `priorPrompts` (the editor re-stamps `updatedAt` on every
|
|
12
|
+
* Save, so timestamps alone cannot prove a real edit). Changing a built-in
|
|
13
|
+
* prompt means moving the OLD prompt into `priorPrompts` (oldest first) and
|
|
14
|
+
* bumping `builtinVersion`; `builtinVersion === priorPrompts.length + 1`.
|
|
10
15
|
*
|
|
11
16
|
* Plain Node, no Electron imports.
|
|
12
17
|
*/
|
|
@@ -20,6 +25,7 @@ const BUILTIN_MACROS = Object.freeze([
|
|
|
20
25
|
surface: 'project-home',
|
|
21
26
|
projects: ['*'],
|
|
22
27
|
builtinVersion: 1,
|
|
28
|
+
priorPrompts: Object.freeze([]),
|
|
23
29
|
prompt:
|
|
24
30
|
"Generate this project's Project Home page: one self-contained HTML overview (what it is, who it is for, key features, structure, how to run it, key commands), grounded only in what you read in the repository. Save it with a single project_home_write call.",
|
|
25
31
|
}),
|
|
@@ -31,6 +37,11 @@ const BUILTIN_MACROS = Object.freeze([
|
|
|
31
37
|
surface: 'project-home',
|
|
32
38
|
projects: ['*'],
|
|
33
39
|
builtinVersion: 4,
|
|
40
|
+
priorPrompts: Object.freeze([
|
|
41
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository. Save it with a single project_demo_video_write call.',
|
|
42
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository, with a matching on-device narration track per the audio policy in the persona. Save it with a single project_demo_video_write call.',
|
|
43
|
+
'Generate a 30-second demo video for this project as one self-contained HTML/JavaScript animation that presents its main goals and key features, grounded only in what you read in the repository, with a matching on-device narration track: narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona. Save it with a single project_demo_video_write call passing htmlPath.',
|
|
44
|
+
]),
|
|
34
45
|
prompt:
|
|
35
46
|
"Generate a character and cute animated JavaScript video: a 30-second demo of this project as one self-contained HTML/JavaScript animation. Ground everything in what you read in the repository — invent an original mascot character whose look, name and personality match the project's theme and purpose, and tell the project's real goals and key features through it. The character, story and visuals must match the project's theme and purpose as read from the repository. Write the narration script first (hook, problem, solution, three features, call to action), then build every scene to match its line, with fun dynamic elements per the persona. Use the style named on a 'Video style: <name>' line in the additional instructions — Professional, Fun, Animated whiteboard, or Kinetic typography — otherwise pick the one that best fits the project. Narrate with Kokoro (kokoro-onnx) using a natural female (af_heart) or male (am_michael) voice per the audio policy in the persona. Save it with a single project_demo_video_write call passing htmlPath.",
|
|
36
47
|
}),
|
|
@@ -161,6 +161,8 @@ const MacroSchema = z.object({
|
|
|
161
161
|
createdAt: z.string().min(1).max(64),
|
|
162
162
|
updatedAt: z.string().min(1).max(64),
|
|
163
163
|
inputs: MacroInputsSchema.optional(),
|
|
164
|
+
// Projects this macro's session may start work in without approval. Set only by the app's IPC save.
|
|
165
|
+
autoStartTargets: MacroProjectsSchema.optional(),
|
|
164
166
|
}).superRefine(refineInputs);
|
|
165
167
|
|
|
166
168
|
const MacroSaveSchema = z.object({
|
|
@@ -176,6 +178,8 @@ const MacroSaveSchema = z.object({
|
|
|
176
178
|
surface: MacroSurfaceSchema.optional(),
|
|
177
179
|
// Omitted keeps the stored list on update; `[]` clears it.
|
|
178
180
|
inputs: MacroInputsSchema.optional(),
|
|
181
|
+
// Omitted keeps the stored list on update; `[]` clears it.
|
|
182
|
+
autoStartTargets: MacroProjectsSchema.optional(),
|
|
179
183
|
}).superRefine(refineInputs);
|
|
180
184
|
|
|
181
185
|
const MacroDeleteSchema = z.object({ id: MacroIdSchema });
|
|
@@ -186,6 +190,8 @@ const MacroSetProjectSchema = z.object({
|
|
|
186
190
|
enabled: z.boolean(),
|
|
187
191
|
});
|
|
188
192
|
|
|
193
|
+
const MacroRemoveFromProjectSchema = z.object({ id: MacroIdSchema, cwd: AbsolutePathSchema });
|
|
194
|
+
|
|
189
195
|
function defaultFilePath() {
|
|
190
196
|
return path.join(schedulerHome(), 'macros.json');
|
|
191
197
|
}
|
|
@@ -212,6 +218,12 @@ function macroVisibleIn(macro, cwd) {
|
|
|
212
218
|
return projects.includes(ALL_PROJECTS) || projects.includes(normalizeCwd(cwd));
|
|
213
219
|
}
|
|
214
220
|
|
|
221
|
+
/** True iff the macro may auto-start work in `toCwd`: autoStartTargets includes '*' or the normalized cwd. */
|
|
222
|
+
function macroAllowsAutoStart(macro, toCwd) {
|
|
223
|
+
const targets = (macro && macro.autoStartTargets) || [];
|
|
224
|
+
return targets.includes(ALL_PROJECTS) || targets.includes(normalizeCwd(toCwd));
|
|
225
|
+
}
|
|
226
|
+
|
|
215
227
|
function normalizeProjects(projects) {
|
|
216
228
|
const out = [];
|
|
217
229
|
for (const p of projects || []) {
|
|
@@ -298,9 +310,26 @@ function resolveBuiltins(opts) {
|
|
|
298
310
|
/**
|
|
299
311
|
* Pure. Seeds any `builtins` entry missing from `macros` (as `builtin: true`),
|
|
300
312
|
* and upgrades a stored built-in that is behind the shipped `builtinVersion`
|
|
301
|
-
* AND
|
|
302
|
-
*
|
|
313
|
+
* AND unedited: `updatedAt === createdAt`, OR `isShippedCopy` (label/agent/tag
|
|
314
|
+
* match and the prompt is one of the built-in's `priorPrompts`). A really
|
|
315
|
+
* edited built-in is left untouched. Changing a built-in prompt means moving
|
|
316
|
+
* the old prompt into `priorPrompts` in builtinMacros.cjs. Returns
|
|
317
|
+
* `{ macros, changed }`.
|
|
303
318
|
*/
|
|
319
|
+
/**
|
|
320
|
+
* True when `stored` matches an earlier shipped version of `builtin`. The
|
|
321
|
+
* editor stamps `updatedAt` on every Save (even an unchanged one), so
|
|
322
|
+
* timestamps alone cannot prove a real edit.
|
|
323
|
+
*/
|
|
324
|
+
function isShippedCopy(stored, builtin) {
|
|
325
|
+
return (
|
|
326
|
+
stored.label === builtin.label &&
|
|
327
|
+
stored.agentName === builtin.agentName &&
|
|
328
|
+
stored.tag === builtin.tag &&
|
|
329
|
+
(builtin.priorPrompts || []).includes(stored.prompt)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
304
333
|
function ensureBuiltins(macros, builtins) {
|
|
305
334
|
if (!builtins || builtins.length === 0) return { macros, changed: false };
|
|
306
335
|
let changed = false;
|
|
@@ -327,7 +356,7 @@ function ensureBuiltins(macros, builtins) {
|
|
|
327
356
|
}
|
|
328
357
|
const stored = next[idx];
|
|
329
358
|
const storedVersion = stored.builtinVersion || 0;
|
|
330
|
-
const neverEdited = stored.updatedAt === stored.createdAt;
|
|
359
|
+
const neverEdited = stored.updatedAt === stored.createdAt || isShippedCopy(stored, b);
|
|
331
360
|
if (storedVersion < b.builtinVersion && neverEdited) {
|
|
332
361
|
next[idx] = {
|
|
333
362
|
...stored,
|
|
@@ -511,6 +540,13 @@ async function saveMacro(input, opts = {}) {
|
|
|
511
540
|
} else {
|
|
512
541
|
saved.inputs = parsed.inputs;
|
|
513
542
|
}
|
|
543
|
+
if (parsed.autoStartTargets === undefined) {
|
|
544
|
+
// keep whatever the spread carried over
|
|
545
|
+
} else if (parsed.autoStartTargets.length === 0) {
|
|
546
|
+
delete saved.autoStartTargets;
|
|
547
|
+
} else {
|
|
548
|
+
saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
|
|
549
|
+
}
|
|
514
550
|
assertPlaceholdersDeclared(saved);
|
|
515
551
|
macros[idx] = saved;
|
|
516
552
|
} else {
|
|
@@ -527,6 +563,9 @@ async function saveMacro(input, opts = {}) {
|
|
|
527
563
|
updatedAt: now,
|
|
528
564
|
};
|
|
529
565
|
if (parsed.inputs && parsed.inputs.length > 0) saved.inputs = parsed.inputs;
|
|
566
|
+
if (parsed.autoStartTargets && parsed.autoStartTargets.length > 0) {
|
|
567
|
+
saved.autoStartTargets = normalizeProjects(parsed.autoStartTargets);
|
|
568
|
+
}
|
|
530
569
|
assertPlaceholdersDeclared(saved);
|
|
531
570
|
macros.push(saved);
|
|
532
571
|
}
|
|
@@ -580,6 +619,39 @@ async function setMacroProject(input, opts = {}) {
|
|
|
580
619
|
});
|
|
581
620
|
}
|
|
582
621
|
|
|
622
|
+
/**
|
|
623
|
+
* One project gives up a macro. The macro is deleted when `cwd` was its last
|
|
624
|
+
* project; otherwise only `cwd` is dropped, so one project can never take a
|
|
625
|
+
* button from another. Refuses a built-in, a '*' macro, and a macro not listed
|
|
626
|
+
* for `cwd`. Returns `{ ok: true, deleted, macro }` or `{ ok: false, error }`;
|
|
627
|
+
* when `deleted`, `macro` is the removed copy.
|
|
628
|
+
*/
|
|
629
|
+
async function removeMacroFromProject(input, opts = {}) {
|
|
630
|
+
const { id, cwd } = MacroRemoveFromProjectSchema.parse(input);
|
|
631
|
+
const filePath = resolvePath(opts);
|
|
632
|
+
const target = normalizeCwd(cwd);
|
|
633
|
+
return serialize(async () => {
|
|
634
|
+
const macros = await loadForWrite(filePath, opts);
|
|
635
|
+
const idx = macros.findIndex((m) => m.id === id);
|
|
636
|
+
if (idx === -1) return { ok: false, error: `macro not found: ${id}` };
|
|
637
|
+
const macro = macros[idx];
|
|
638
|
+
if (macro.builtin) return { ok: false, error: 'built-in macros cannot be deleted' };
|
|
639
|
+
if (macro.projects.includes(ALL_PROJECTS)) {
|
|
640
|
+
return { ok: false, error: `macro ${id} is shown in every project; only the human can remove it, from the HOT KEYS panel` };
|
|
641
|
+
}
|
|
642
|
+
if (!macro.projects.includes(target)) return { ok: false, error: `macro ${id} is not visible to ${target}` };
|
|
643
|
+
const projects = macro.projects.filter((p) => p !== target);
|
|
644
|
+
if (projects.length === 0) {
|
|
645
|
+
await writeStore(filePath, macros.filter((m) => m.id !== id));
|
|
646
|
+
return { ok: true, deleted: true, macro };
|
|
647
|
+
}
|
|
648
|
+
const updated = { ...macro, projects, updatedAt: new Date().toISOString() };
|
|
649
|
+
macros[idx] = updated;
|
|
650
|
+
await writeStore(filePath, macros);
|
|
651
|
+
return { ok: true, deleted: false, macro: updated };
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
583
655
|
module.exports = {
|
|
584
656
|
ALL_PROJECTS,
|
|
585
657
|
MACRO_INPUT_MAX_LEN,
|
|
@@ -589,14 +661,17 @@ module.exports = {
|
|
|
589
661
|
MacroSaveSchema,
|
|
590
662
|
MacroDeleteSchema,
|
|
591
663
|
MacroSetProjectSchema,
|
|
664
|
+
MacroRemoveFromProjectSchema,
|
|
592
665
|
macroPlaceholders,
|
|
593
666
|
defaultMacroValues,
|
|
594
667
|
renderMacroPrompt,
|
|
595
668
|
macroVisibleIn,
|
|
669
|
+
macroAllowsAutoStart,
|
|
596
670
|
listMacros,
|
|
597
671
|
saveMacro,
|
|
598
672
|
deleteMacro,
|
|
599
673
|
setMacroProject,
|
|
674
|
+
removeMacroFromProject,
|
|
600
675
|
defaultFilePath,
|
|
601
676
|
ensureBuiltins,
|
|
602
677
|
};
|
|
@@ -342,6 +342,17 @@ const SHIPPED_PERSONA_SEEDS = deepFreeze({
|
|
|
342
342
|
effort: "max",
|
|
343
343
|
},
|
|
344
344
|
},
|
|
345
|
+
{
|
|
346
|
+
commit: "seed-v5",
|
|
347
|
+
bodySha256: "503ab8eed370d546f0435ac56a1470a1af31c6c665a2660af8c94b4d9ed6361a",
|
|
348
|
+
fm: {
|
|
349
|
+
description: "30-second self-contained HTML/JS demo video for Project Home, saved via project_demo_video_write.",
|
|
350
|
+
tools: "Read, Grep, Glob, Bash, Write, Edit",
|
|
351
|
+
title: "Project Home — Demo Video",
|
|
352
|
+
model: "opus",
|
|
353
|
+
effort: "max",
|
|
354
|
+
},
|
|
355
|
+
},
|
|
345
356
|
],
|
|
346
357
|
"blender-artist": [
|
|
347
358
|
{
|