claude-code-session-manager 0.143.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/README.md +3 -1
- package/dist/assets/AppSettings-Z68gQiVE.js +2 -0
- package/dist/assets/{History-DTttbvPb.js → History-C3E6y_7t.js} +2 -2
- package/dist/assets/HomeClaudeConfig-Yd1vXzBn.js +5 -0
- package/dist/assets/{Panel-B_D4Bg7L.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-D1b2aiol.js → SkillReferenceGraph-DRtZV1Al.js} +1 -1
- package/dist/assets/{Skills-cfV7sgk6.js → Skills-Bg5O2Hyn.js} +23 -23
- package/dist/assets/{TiptapBody-DVXtEIVy.js → TiptapBody-BdzoBmqu.js} +27 -27
- package/dist/assets/{Toggle-CYajnSdx.js → Toggle-Dt5K1OXt.js} +1 -1
- package/dist/assets/{VoiceButton-DJ4gGRuE.js → VoiceButton-CTLyRgdF.js} +1 -1
- package/dist/assets/{historyTotals-D3MoHY2U.js → historyTotals-B2_KWBga.js} +1 -1
- package/dist/assets/{index-CdTppjKR.js → index-446b69rr.js} +698 -697
- 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 +439 -436
- package/package.json +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +14 -13
- 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 -1
- package/scripts/scheduler-mcp-server.cjs +77 -0
- package/src/main/adminRouteRegistry.cjs +6 -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 +109 -0
- package/src/main/health.cjs +59 -17
- package/src/main/index.cjs +4 -0
- package/src/main/ipcSchemas.cjs +50 -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/epic/epicDepsSync.cjs +66 -0
- 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/epicValidationHook.cjs +9 -1
- 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 +12 -0
- 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/macroAdminRoutes.cjs +24 -3
- package/src/main/lib/feedback-remote/pendingReplies.cjs +8 -4
- package/src/main/lib/feedback-remote/projectCreate.cjs +415 -0
- package/src/main/lib/feedback-remote/replyClaims.cjs +15 -6
- 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 +1 -1
- package/src/main/lib/git/worktreeDeps.cjs +9 -3
- package/src/main/lib/mcpToolCatalog.cjs +43 -5
- package/src/main/lib/mcpToolsProbe.cjs +19 -2
- 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 +94 -0
- package/src/main/lib/prd/prdCreate.cjs +48 -5
- 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/videoScriptPress.cjs +6 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +24 -4
- package/src/main/lib/promptSessionSchema.cjs +2 -0
- package/src/main/lib/scheduler/baselineGate.cjs +31 -2
- package/src/main/lib/scheduler/planRecordHarvest.cjs +104 -12
- 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/sandboxEnvironmentLimit.cjs +141 -0
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +2 -0
- package/src/main/lib/scheduler/upgradeDrain.cjs +32 -5
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +12 -2
- package/src/main/lib/tasks/memoryConsolidation.cjs +109 -37
- package/src/main/lib/tasks/taskAdminRoutes.cjs +26 -14
- package/src/main/lib/tasks/taskRun.cjs +3 -1
- package/src/main/lib/tasks/weeklyConsolidationInputs.cjs +178 -0
- package/src/main/projectPages.cjs +22 -14
- package/src/main/pty.cjs +3 -0
- package/src/main/runVerify.cjs +3 -2
- 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 +7 -2
- package/src/main/scheduler.cjs +532 -78
- package/src/main/seedAgentPersonas.cjs +11 -6
- package/src/main/seedStatus.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +16 -1
- package/src/main/webRemote.cjs +47 -7
- package/src/preload/api.d.ts +71 -1
- package/src/preload/apiSurface.json +28 -0
- package/src/preload/index.cjs +9 -0
- package/src/seed/agents/architect.md +28 -43
- 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 +2 -1
- package/dist/assets/AppSettings-BO4jDVGO.js +0 -2
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +0 -3
- package/dist/assets/ProjectClaudeConfig-DPnDJKcr.js +0 -26
- package/dist/assets/Scheduler-CNLjn90m.js +0 -16
package/src/main/chatRunner.cjs
CHANGED
|
@@ -56,7 +56,9 @@ const { developLoopOffSettingsArgs } = require('./lib/epic/developLoopSpawn.cjs'
|
|
|
56
56
|
const packSpawnArgs = require('./lib/packs/packSpawnArgs.cjs');
|
|
57
57
|
const { resolveEpicEffort, effortArgs } = require('./lib/claude/agentEffortResolve.cjs');
|
|
58
58
|
const { planEpicSpawn, resolveEpicTurnModel } = require('./lib/epic/epicSpawnPlan.cjs');
|
|
59
|
+
const { buildPersonaToolScope, personaToolScopeArgs, skillDenyArgs } = require('./lib/claude/personaToolScope.cjs');
|
|
59
60
|
const epicWorktreeMint = require('./lib/epic/epicWorktreeMint.cjs');
|
|
61
|
+
const epicDepsSync = require('./lib/epic/epicDepsSync.cjs');
|
|
60
62
|
const logs = require('./logs.cjs');
|
|
61
63
|
const chatInflight = require('./lib/chatInflight.cjs');
|
|
62
64
|
const { feedChildStdin } = require('./lib/process/childStdin.cjs');
|
|
@@ -903,6 +905,12 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
903
905
|
settle();
|
|
904
906
|
return;
|
|
905
907
|
}
|
|
908
|
+
// Long-lived Epic worktree: refresh its node_modules links from the project checkout
|
|
909
|
+
// (fire-and-forget, throttled). The sync runs after the CLI is spawned, so it normally
|
|
910
|
+
// lands before the agent's first tool call but is not awaited; the next turn guarantees it.
|
|
911
|
+
if (plan.execCwd && plan.execCwd !== cwd) {
|
|
912
|
+
epicDepsSync.syncEpicWorktreeDeps({ projectCwd: cwd, worktreeCwd: plan.execCwd });
|
|
913
|
+
}
|
|
906
914
|
// Agent-CLI turn plan (agentCliTurn.cjs): command, argv, stdin, auth env, parser, transcript.
|
|
907
915
|
let agentPlan = null;
|
|
908
916
|
if (isAgentCli) {
|
|
@@ -920,6 +928,29 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
920
928
|
? cleanChildEnv({ PATH: pathWithUserBins(), SM_CHAT_SESSION_ID: sessionId, SM_PROJECT_ROOT: cwd, ...artifactsEnv, ...agentPlan.envExtra })
|
|
921
929
|
: null;
|
|
922
930
|
|
|
931
|
+
// Gear binds chat (stamped snapshots only): same tool/MCP/pack/skill scope a job gets.
|
|
932
|
+
let gearArgs = [];
|
|
933
|
+
if (!isAgentCli && plan.persona && plan.persona.snapshot) {
|
|
934
|
+
try {
|
|
935
|
+
const gear = gearChatArgs({ snapshot: plan.persona.snapshot, cwd: plan.execCwd || cwd, projectRoot: cwd });
|
|
936
|
+
gearArgs = gear.args;
|
|
937
|
+
// Persona-declared packs load with the Epic's (as for jobs); known ones only.
|
|
938
|
+
const snapPacks = (Array.isArray(plan.persona.snapshot.packs) ? plan.persona.snapshot.packs.map(String) : [])
|
|
939
|
+
.filter((p) => !(agentEpic?.packs || []).map(String).includes(p));
|
|
940
|
+
if (gear.args.length && snapPacks.length) {
|
|
941
|
+
const extra = packSpawnArgs.composePackSpawnArgs({ packIds: snapPacks });
|
|
942
|
+
packPluginDirArgs = [...packPluginDirArgs, ...(Array.isArray(extra.pluginDirArgs) ? extra.pluginDirArgs : [])];
|
|
943
|
+
if (extra.laws) packLaws = packLaws ? `${packLaws}\n\n${extra.laws}` : extra.laws;
|
|
944
|
+
}
|
|
945
|
+
for (const message of gear.errors) {
|
|
946
|
+
try {
|
|
947
|
+
opsErrorLog.appendError({ cwd, scope: 'chatRunner', level: 'warn', code: 'capability_unknown', tabId, tags: [], message, meta: { sessionId } });
|
|
948
|
+
} catch { /* logging must never fail a turn */ }
|
|
949
|
+
if (!silent) broadcast('chat:run:notice', { tabId, sessionId, message });
|
|
950
|
+
}
|
|
951
|
+
} catch { gearArgs = []; }
|
|
952
|
+
}
|
|
953
|
+
|
|
923
954
|
const useResume = plan.useResume;
|
|
924
955
|
if (!agentPlan && useResume !== !!resume) {
|
|
925
956
|
try {
|
|
@@ -942,6 +973,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
942
973
|
'--dangerously-skip-permissions',
|
|
943
974
|
...loopOffArgs,
|
|
944
975
|
...packPluginDirArgs,
|
|
976
|
+
...gearArgs,
|
|
945
977
|
...(packLaws ? ['--append-system-prompt', packLaws] : []),
|
|
946
978
|
'--output-format', 'stream-json',
|
|
947
979
|
'--verbose',
|
|
@@ -1655,6 +1687,82 @@ function registerChatHandlers() {
|
|
|
1655
1687
|
|
|
1656
1688
|
}
|
|
1657
1689
|
|
|
1690
|
+
const undecidedLogged = new Set();
|
|
1691
|
+
|
|
1692
|
+
/**
|
|
1693
|
+
* Gear for a chat turn (PRD 4768): the argv that gives an Epic whose pinned snapshot carries
|
|
1694
|
+
* `gearBindsChat` the same scope a job gets — persona tools, strict MCP with the declared servers,
|
|
1695
|
+
* packs' skill allow-list. HEADLESS_DISALLOWED_TOOLS is deliberately NOT applied to chat.
|
|
1696
|
+
* Unstamped (older) snapshots and Unbound personas add nothing; Undecided runs unscoped.
|
|
1697
|
+
* An unknown declared server/pack never crashes the turn: it is dropped and reported in `errors`.
|
|
1698
|
+
* Pure apart from reading ~/.claude.json and <cwd>/.mcp.json (declared servers), the pack catalog and the seeded MCP entry (injectable for tests).
|
|
1699
|
+
* `projectRoot` is the Epic's main project cwd: a worktree `cwd` still sees servers under projects[<main root>].
|
|
1700
|
+
* @param {{ snapshot: any, cwd?: string, projectRoot?: string, deps?: { home?: string, knownMcpServers?: Record<string, object>, listPacks?: () => { packs: any[] }, listUnpackedSkills?: () => string[], log?: (msg: string) => void } }} opts
|
|
1701
|
+
* @returns {{ args: string[], errors: string[] }}
|
|
1702
|
+
*/
|
|
1703
|
+
function gearChatArgs({ snapshot, cwd, projectRoot, deps = {} }) {
|
|
1704
|
+
const none = { args: [], errors: [] };
|
|
1705
|
+
if (!snapshot || snapshot.gearBindsChat !== true) return none;
|
|
1706
|
+
const loadout = snapshot.loadout;
|
|
1707
|
+
if (loadout === 'unbound') return none;
|
|
1708
|
+
if (loadout === 'undecided') {
|
|
1709
|
+
const key = String(snapshot.name || '');
|
|
1710
|
+
if (!undecidedLogged.has(key)) {
|
|
1711
|
+
undecidedLogged.add(key);
|
|
1712
|
+
try { (deps.log || ((m) => logs.writeLine({ scope: 'chatRunner', level: 'info', message: m })))(`persona "${key}" is undecided about gear; chat runs unscoped`); } catch { /* logging must never fail a turn */ }
|
|
1713
|
+
}
|
|
1714
|
+
return none;
|
|
1715
|
+
}
|
|
1716
|
+
let known = deps.knownMcpServers;
|
|
1717
|
+
/** @type {Record<string, string>} */
|
|
1718
|
+
let credentialed = {};
|
|
1719
|
+
if (!known) {
|
|
1720
|
+
try {
|
|
1721
|
+
const r = require('./lib/claude/headlessMcpServers.cjs').resolveHeadlessMcpServers({ cwd, projectRoot, ...(deps.home ? { home: deps.home } : {}) });
|
|
1722
|
+
known = r.known;
|
|
1723
|
+
credentialed = r.credentialed;
|
|
1724
|
+
} catch { known = {}; }
|
|
1725
|
+
}
|
|
1726
|
+
let catalog = [];
|
|
1727
|
+
try { catalog = (deps.listPacks || require('./lib/packs/packCatalog.cjs').listPacks)().packs || []; } catch { catalog = []; }
|
|
1728
|
+
let unpacked = [];
|
|
1729
|
+
try { unpacked = (deps.listUnpackedSkills || require('./lib/packs/packCatalog.cjs').listUnpackedSkills)(); } catch { unpacked = []; }
|
|
1730
|
+
const packs = Array.isArray(snapshot.packs) ? snapshot.packs.map(String) : [];
|
|
1731
|
+
const knownPackIds = new Set(catalog.map((p) => String(p.id)));
|
|
1732
|
+
const declared = Array.isArray(snapshot.mcpServers) ? snapshot.mcpServers.map(String) : [];
|
|
1733
|
+
const scope = buildPersonaToolScope(snapshot.tools, { loadout, disallowed: [] });
|
|
1734
|
+
const attempt = personaToolScopeArgs(scope, { mcpServers: known, declaredServers: declared, packs, knownPacks: [...knownPackIds] });
|
|
1735
|
+
/** @type {string[]} */ const errors = [];
|
|
1736
|
+
let scopeArgs = attempt.args;
|
|
1737
|
+
let equipped = packs;
|
|
1738
|
+
if (attempt.refusal) {
|
|
1739
|
+
// Run without the unknown capability instead of failing the turn: drop it and re-derive.
|
|
1740
|
+
const bad = new Set();
|
|
1741
|
+
let r = attempt.refusal;
|
|
1742
|
+
let guard = 0;
|
|
1743
|
+
let curDeclared = declared;
|
|
1744
|
+
let curPacks = packs;
|
|
1745
|
+
let curScope = scope;
|
|
1746
|
+
let cur = attempt;
|
|
1747
|
+
while (r && guard++ < 50) {
|
|
1748
|
+
bad.add(r.name);
|
|
1749
|
+
errors.push(Object.prototype.hasOwnProperty.call(credentialed, r.name)
|
|
1750
|
+
? `Gear: "${r.name}" is not available (${credentialed[r.name]}); this turn runs without it.`
|
|
1751
|
+
: `Gear: "${r.name}" is not available; this turn runs without it.`);
|
|
1752
|
+
curDeclared = curDeclared.filter((d) => d !== r.name);
|
|
1753
|
+
curPacks = curPacks.filter((p) => p !== r.name);
|
|
1754
|
+
curScope = curScope ? { tools: curScope.tools.filter((t) => !(t.startsWith('mcp__') && t.slice(5).split('__')[0] === r.name) && t !== r.name) } : curScope;
|
|
1755
|
+
cur = personaToolScopeArgs(curScope, { mcpServers: known, declaredServers: curDeclared, packs: curPacks, knownPacks: [...knownPackIds] });
|
|
1756
|
+
r = cur.refusal;
|
|
1757
|
+
}
|
|
1758
|
+
scopeArgs = cur.args;
|
|
1759
|
+
equipped = curPacks;
|
|
1760
|
+
}
|
|
1761
|
+
const installedSkills = [...new Set([...catalog.flatMap((p) => p.skills || []), ...unpacked].map(String))];
|
|
1762
|
+
const deny = skillDenyArgs({ installedSkills, equippedPacks: equipped, packCatalog: catalog, loadout });
|
|
1763
|
+
return { args: [...scopeArgs, ...deny], errors };
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1658
1766
|
module.exports = {
|
|
1659
1767
|
run,
|
|
1660
1768
|
cancel,
|
|
@@ -1666,6 +1774,7 @@ module.exports = {
|
|
|
1666
1774
|
registerChatHandlers,
|
|
1667
1775
|
noteChatRunOrigin,
|
|
1668
1776
|
turnInstructionFor,
|
|
1777
|
+
gearChatArgs,
|
|
1669
1778
|
shouldFollowUp,
|
|
1670
1779
|
parseStopSignal,
|
|
1671
1780
|
splitStopSignal,
|
package/src/main/health.cjs
CHANGED
|
@@ -845,6 +845,52 @@ function evaluateVisibleRuntimeState(results = []) {
|
|
|
845
845
|
};
|
|
846
846
|
}
|
|
847
847
|
|
|
848
|
+
/**
|
|
849
|
+
* collectRuntimeStateHealth(roots, { findTracked, findVisible })
|
|
850
|
+
* → Promise<{ components: { tracked_runtime_state, visible_runtime_state }, issues }>
|
|
851
|
+
*
|
|
852
|
+
* Runs both runtime-state checks over `roots` (sequentially). Each side has its
|
|
853
|
+
* own failure handling: a throw on one side sets only that component to
|
|
854
|
+
* { ok: true, error } and adds no issues for it — the other side still reports.
|
|
855
|
+
* Non-critical: neither component ever sets ok=false.
|
|
856
|
+
*/
|
|
857
|
+
async function collectRuntimeStateHealth(roots = [], { findTracked, findVisible } = {}) {
|
|
858
|
+
const list = Array.isArray(roots) ? roots : [];
|
|
859
|
+
const components = {};
|
|
860
|
+
const visibleIssues = [];
|
|
861
|
+
const trackedIssues = [];
|
|
862
|
+
|
|
863
|
+
try {
|
|
864
|
+
const visible = [];
|
|
865
|
+
for (const cwd of list) {
|
|
866
|
+
visible.push({ cwd, count: (await findVisible(cwd)).length });
|
|
867
|
+
}
|
|
868
|
+
const visibleEval = evaluateVisibleRuntimeState(visible);
|
|
869
|
+
components.visible_runtime_state = visibleEval.component;
|
|
870
|
+
visibleIssues.push(...visibleEval.issues);
|
|
871
|
+
} catch (e) {
|
|
872
|
+
components.visible_runtime_state = { ok: true, error: e && e.message };
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
try {
|
|
876
|
+
const hits = [];
|
|
877
|
+
for (const cwd of list) {
|
|
878
|
+
const n = (await findTracked(cwd)).length;
|
|
879
|
+
if (n > 0) hits.push({ cwd, count: n });
|
|
880
|
+
}
|
|
881
|
+
components.tracked_runtime_state = hits.length === 0
|
|
882
|
+
? { ok: true }
|
|
883
|
+
: { ok: true, warn: true, projects: hits };
|
|
884
|
+
for (const h of hits) {
|
|
885
|
+
trackedIssues.push(`warn: ${h.cwd} tracks ${h.count} Session Manager runtime-state file(s) in git — untrack from its main checkout`);
|
|
886
|
+
}
|
|
887
|
+
} catch (e) {
|
|
888
|
+
components.tracked_runtime_state = { ok: true, error: e && e.message };
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
return { components, issues: [...visibleIssues, ...trackedIssues] };
|
|
892
|
+
}
|
|
893
|
+
|
|
848
894
|
/**
|
|
849
895
|
* evaluateCredentialHealth({ credState, now }) → { component, issues }
|
|
850
896
|
*
|
|
@@ -1515,28 +1561,23 @@ async function check(opts = {}) {
|
|
|
1515
1561
|
// 6.76. Tracked runtime state: projects that committed Session Manager
|
|
1516
1562
|
// runtime namespaces. Warning only (never flips ok) — untrack via
|
|
1517
1563
|
// runtimeStateUntrack.untrackRuntimeState from the project's main checkout.
|
|
1564
|
+
// Each check fails on its own inside collectRuntimeStateHealth; only a
|
|
1565
|
+
// failure computing the roots blanks both.
|
|
1566
|
+
let runtimeRoots = null;
|
|
1518
1567
|
try {
|
|
1519
|
-
|
|
1520
|
-
const hits = [];
|
|
1521
|
-
const visible = [];
|
|
1522
|
-
for (const cwd of roots) {
|
|
1523
|
-
const n = (await findTrackedRuntimeState(cwd)).length;
|
|
1524
|
-
if (n > 0) hits.push({ cwd, count: n });
|
|
1525
|
-
visible.push({ cwd, count: (await findVisibleRuntimeState(cwd)).length });
|
|
1526
|
-
}
|
|
1527
|
-
const visibleEval = evaluateVisibleRuntimeState(visible);
|
|
1528
|
-
status.components.visible_runtime_state = visibleEval.component;
|
|
1529
|
-
status.issues.push(...visibleEval.issues);
|
|
1530
|
-
status.components.tracked_runtime_state = hits.length === 0
|
|
1531
|
-
? { ok: true }
|
|
1532
|
-
: { ok: true, warn: true, projects: hits };
|
|
1533
|
-
for (const h of hits) {
|
|
1534
|
-
status.issues.push(`warn: ${h.cwd} tracks ${h.count} Session Manager runtime-state file(s) in git — untrack from its main checkout`);
|
|
1535
|
-
}
|
|
1568
|
+
runtimeRoots = [...new Set(allProjectCwds())].slice(0, 100).filter((cwd) => fs.existsSync(cwd));
|
|
1536
1569
|
} catch (e) {
|
|
1537
1570
|
status.components.tracked_runtime_state = { ok: true, error: e.message };
|
|
1538
1571
|
status.components.visible_runtime_state = { ok: true, error: e.message };
|
|
1539
1572
|
}
|
|
1573
|
+
if (runtimeRoots) {
|
|
1574
|
+
const runtime = await collectRuntimeStateHealth(runtimeRoots, {
|
|
1575
|
+
findTracked: findTrackedRuntimeState,
|
|
1576
|
+
findVisible: findVisibleRuntimeState,
|
|
1577
|
+
});
|
|
1578
|
+
Object.assign(status.components, runtime.components);
|
|
1579
|
+
status.issues.push(...runtime.issues);
|
|
1580
|
+
}
|
|
1540
1581
|
|
|
1541
1582
|
// 6.8. Credential health (informational-but-loud): is the Claude OAuth token
|
|
1542
1583
|
// usable? An expired/absent token silently voids every headless `claude -p`
|
|
@@ -1631,6 +1672,7 @@ module.exports = {
|
|
|
1631
1672
|
evaluateBuildFreshness,
|
|
1632
1673
|
evaluateMainDepLinks,
|
|
1633
1674
|
evaluateVisibleRuntimeState,
|
|
1675
|
+
collectRuntimeStateHealth,
|
|
1634
1676
|
WORKTREE_SAFETY_PATHS,
|
|
1635
1677
|
latestStarveEscalationReasons,
|
|
1636
1678
|
DISPATCH_STALL_THRESHOLD_MS,
|
package/src/main/index.cjs
CHANGED
|
@@ -393,6 +393,10 @@ function relaunchViaNpx() {
|
|
|
393
393
|
async function rebootApp({ force = false } = {}) {
|
|
394
394
|
if (force) {
|
|
395
395
|
logReboot('force reboot requested — immediate, not draining');
|
|
396
|
+
// This reboot IS the restart any pending request asked for; never leave one
|
|
397
|
+
// behind for the next boot to drain and restart a second time.
|
|
398
|
+
const retired = upgradeDrain.retireRestartRequestBestEffort();
|
|
399
|
+
if (!retired.ok) logReboot(`could not retire restart request (continuing): ${retired.error}`);
|
|
396
400
|
return performReboot();
|
|
397
401
|
}
|
|
398
402
|
const request = upgradeDrain.requestRestart({ reason: 'user-reboot', requestedBy: 'user' });
|
package/src/main/ipcSchemas.cjs
CHANGED
|
@@ -838,8 +838,48 @@ const setSessionSlotsSchema = z.object({
|
|
|
838
838
|
// only after a production incident (see scheduleJobSchema.cjs's header).
|
|
839
839
|
// Full field-level rules live in lib/persona-macro/agentPersonaSchema.cjs, mirroring
|
|
840
840
|
// AgentPersonaSaveInput (src/preload/api.d.ts) field-for-field.
|
|
841
|
-
|
|
841
|
+
// A project override (projectCwd set) may also carry the gear keys, validated with the persona
|
|
842
|
+
// frontmatter rules (saveOverlay re-checks the serialized lines). AgentPersonaSaveSchema is
|
|
843
|
+
// .strict(), so the gear keys are split off, validated here, and merged back.
|
|
844
|
+
const AgentOverlayGearSchema = z.object({
|
|
845
|
+
loadout: z.enum(['undecided', 'bare', 'equipped', 'unbound']).optional(),
|
|
846
|
+
mcpServers: z.array(z.string().trim().min(1).max(200)).max(64).optional(),
|
|
847
|
+
packs: z.array(z.string().trim().min(1).max(200)).max(64).optional(),
|
|
848
|
+
environment: z.string().trim().regex(/^[a-z0-9][a-z0-9-]*$/, 'environment must be a lowercase, hyphenated profile name').optional(),
|
|
849
|
+
}).strict();
|
|
850
|
+
const GEAR_KEYS = ['loadout', 'mcpServers', 'packs', 'environment'];
|
|
851
|
+
const agentsSavePersona = z.record(z.string(), z.unknown()).transform((raw, ctx) => {
|
|
852
|
+
/** @type {Record<string, unknown>} */
|
|
853
|
+
const gear = {};
|
|
854
|
+
const rest = { ...raw };
|
|
855
|
+
const hasCwd = rest.projectCwd !== undefined;
|
|
856
|
+
for (const k of GEAR_KEYS) {
|
|
857
|
+
if (k in rest) { gear[k] = rest[k]; delete rest[k]; }
|
|
858
|
+
}
|
|
859
|
+
// Global saves take the gear keys via AgentPersonaSaveSchema; 'undecided' is overlay-only.
|
|
860
|
+
if (!hasCwd && gear.loadout === 'undecided') {
|
|
861
|
+
ctx.addIssue({ code: 'custom', path: ['loadout'], message: "loadout 'undecided' is accepted only on a project override (projectCwd set)" });
|
|
862
|
+
return z.NEVER;
|
|
863
|
+
}
|
|
864
|
+
if (!hasCwd) {
|
|
865
|
+
const base = AgentPersonaSaveSchema.safeParse({ ...rest, ...gear });
|
|
866
|
+
if (!base.success) {
|
|
867
|
+
for (const i of base.error.issues) ctx.addIssue({ code: 'custom', path: i.path, message: i.message });
|
|
868
|
+
return z.NEVER;
|
|
869
|
+
}
|
|
870
|
+
return base.data;
|
|
871
|
+
}
|
|
872
|
+
const base = AgentPersonaSaveSchema.safeParse(rest);
|
|
873
|
+
const g = AgentOverlayGearSchema.safeParse(gear);
|
|
874
|
+
if (!base.success || !g.success) {
|
|
875
|
+
for (const r of [base, g]) if (!r.success) for (const i of r.error.issues) ctx.addIssue({ code: 'custom', path: i.path, message: i.message });
|
|
876
|
+
return z.NEVER;
|
|
877
|
+
}
|
|
878
|
+
return { ...base.data, ...g.data };
|
|
879
|
+
});
|
|
842
880
|
// agents:remove-override — an OPEN project's override, keyed by its absolute cwd (never a folder name).
|
|
881
|
+
const agentsTakeBundledPersona = z.object({ name: PersonaNameSchema }).strict();
|
|
882
|
+
const agentsDismissPersonaUpgrade = z.object({ name: PersonaNameSchema, bundledVersion: z.number().int().min(1) }).strict();
|
|
843
883
|
const agentsRemoveOverride = z.object({ name: PersonaNameSchema, projectCwd: ProjectCwdSchema }).strict();
|
|
844
884
|
// agents:delete-persona — a kebab-case name only; `.strict()` also bars deletePersona's injectable `globalDir`.
|
|
845
885
|
const agentsDeletePersona = z.object({ name: PersonaNameSchema }).strict();
|
|
@@ -1101,6 +1141,11 @@ const agentsResolveEpicModel = z.object({
|
|
|
1101
1141
|
}).strict();
|
|
1102
1142
|
const agentsResolveEpicEffort = agentsResolveEpicModel;
|
|
1103
1143
|
|
|
1144
|
+
// agents:armory — gear read model; cwd optional (global gear only when absent).
|
|
1145
|
+
const agentsArmory = z.object({
|
|
1146
|
+
cwd: z.string().min(1).max(4096).optional(),
|
|
1147
|
+
}).strict();
|
|
1148
|
+
|
|
1104
1149
|
// ──────────────────────────────────────────── Project Pages (PRD 932)
|
|
1105
1150
|
// Same validation split as projectBriefCwd above: real path validation is
|
|
1106
1151
|
// config.cjs's validatePath at first fs access in projectPages.cjs.
|
|
@@ -1518,6 +1563,7 @@ const webRemoteServicePairStart = z.object({
|
|
|
1518
1563
|
name: z.string().min(1).max(64).regex(/^[^\r\n]+$/),
|
|
1519
1564
|
homeCwd: z.string().min(1).max(4096),
|
|
1520
1565
|
scope: z.array(z.string().min(1).max(64)).min(1).max(16),
|
|
1566
|
+
projectRoot: z.string().min(1).max(4096).optional(),
|
|
1521
1567
|
}).strict();
|
|
1522
1568
|
const webRemoteServiceConfirmSas = z.object({
|
|
1523
1569
|
pairingId: z.string().regex(WEB_REMOTE_UUID_RE),
|
|
@@ -1998,6 +2044,8 @@ module.exports = {
|
|
|
1998
2044
|
exchangesList,
|
|
1999
2045
|
agentsSavePersona,
|
|
2000
2046
|
agentsRemoveOverride,
|
|
2047
|
+
agentsTakeBundledPersona,
|
|
2048
|
+
agentsDismissPersonaUpgrade,
|
|
2001
2049
|
agentsDeletePersona,
|
|
2002
2050
|
claudeConfigRead,
|
|
2003
2051
|
claudeConfigPatch,
|
|
@@ -2028,6 +2076,7 @@ module.exports = {
|
|
|
2028
2076
|
modelsCatalog,
|
|
2029
2077
|
agentsResolveEpicModel,
|
|
2030
2078
|
agentsResolveEpicEffort,
|
|
2079
|
+
agentsArmory,
|
|
2031
2080
|
delegationReadinessCwd,
|
|
2032
2081
|
appCreateProjectFolder,
|
|
2033
2082
|
telemetrySetConfig,
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* agentArmory.cjs — the Armory read model: one pure aggregate of catalogs that
|
|
5
|
+
* already exist (built-in tools + bundled skills, configured MCP servers with
|
|
6
|
+
* their last-known tools, packs + loose skills, tool-risk marks). No registry
|
|
7
|
+
* file, no probes run here. Every source is injected (`deps`); a source that
|
|
8
|
+
* throws adds a message to `errors` and leaves its group empty. Never throws.
|
|
9
|
+
*
|
|
10
|
+
* Deps (all optional, default to the real modules):
|
|
11
|
+
* - getBuiltinTools() -> { tools, skills }
|
|
12
|
+
* - listPacks() -> { packs, errors } ; listUnpackedSkills() -> string[]
|
|
13
|
+
* - listMcpServers({ cwd }) -> [{ name, scope }] (same config reader as mcpToolsProbe)
|
|
14
|
+
* - getMcpProbe({ name, scope, cwd }) -> { ok, tools: (string|{name})[] } | null (last result only)
|
|
15
|
+
* - loadMarks({ cwd }) -> { system, project } risk-mark layers
|
|
16
|
+
* - listEnvironments() -> { name, summary }[] (default: built-in profiles of environmentProfiles.cjs)
|
|
17
|
+
* - bannedTools: string[] (the scheduler's HEADLESS_DISALLOWED_TOOLS, passed by the caller)
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const os = require('node:os');
|
|
21
|
+
const path = require('node:path');
|
|
22
|
+
|
|
23
|
+
/** @param {unknown} e */
|
|
24
|
+
const msg = (e) => String((e && /** @type {Error} */ (e).message) || e);
|
|
25
|
+
|
|
26
|
+
/** Default probe source: the last checkConfiguredMcpServer result held in memory. */
|
|
27
|
+
function defaultGetMcpProbe({ name, scope }) {
|
|
28
|
+
return require('../mcpToolsProbe.cjs').lastProbe(scope, name);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Real MCP config reader: user ~/.claude.json + <cwd>/.mcp.json via claudeConfig (as mcpToolsProbe). */
|
|
32
|
+
async function defaultListMcpServers({ cwd }) {
|
|
33
|
+
const claudeConfig = require('../claudeConfig.cjs');
|
|
34
|
+
const out = [];
|
|
35
|
+
const user = await claudeConfig.read({ fileId: 'claudeJson', scope: 'user', home: os.homedir() });
|
|
36
|
+
for (const name of Object.keys((user.data && user.data.mcpServers) || {})) out.push({ name, scope: 'user' });
|
|
37
|
+
if (typeof cwd === 'string' && path.isAbsolute(cwd)) {
|
|
38
|
+
const proj = await claudeConfig.read({ fileId: 'mcpJson', scope: 'project', cwd });
|
|
39
|
+
for (const name of Object.keys((proj.data && proj.data.mcpServers) || {})) out.push({ name, scope: 'project' });
|
|
40
|
+
}
|
|
41
|
+
// Plugin-provided servers have no config file here; they appear once checked.
|
|
42
|
+
for (const e of require('../mcpToolsProbe.cjs').probedServers('plugin')) out.push({ name: e.name, scope: 'plugin' });
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function defaultListEnvironments() {
|
|
47
|
+
const { BUILTIN_ENVIRONMENTS } = require('./environmentProfiles.cjs');
|
|
48
|
+
return Object.entries(BUILTIN_ENVIRONMENTS).map(([name, p]) => ({ name, summary: p.description }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function defaultLoadMarks({ cwd }) {
|
|
52
|
+
const m = require('./toolRiskMarks.cjs');
|
|
53
|
+
return {
|
|
54
|
+
system: m.readMarksLayer(m.systemMarksPath(os.homedir())),
|
|
55
|
+
project: typeof cwd === 'string' && cwd ? m.readMarksLayer(m.projectMarksPath(cwd)) : null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {{ cwd?: string, deps?: Record<string, any> }} [opts]
|
|
61
|
+
*/
|
|
62
|
+
async function buildArmory({ cwd, deps } = {}) {
|
|
63
|
+
const d = deps || {};
|
|
64
|
+
/** @type {string[]} */ const errors = [];
|
|
65
|
+
const out = { builtins: [], bundledSkills: [], mcpServers: [], packs: [], unpackedSkills: [], environments: [], errors };
|
|
66
|
+
|
|
67
|
+
/** Run one source; on failure record and return the fallback. */
|
|
68
|
+
const guard = async (label, fn, fallback) => {
|
|
69
|
+
try { return await fn(); } catch (e) { errors.push(`${label}: ${msg(e)}`); return fallback; }
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const banned = new Set(Array.isArray(d.bannedTools) ? d.bannedTools : []);
|
|
73
|
+
let floor = [];
|
|
74
|
+
try { floor = require('./personaToolScope.cjs').HEADLESS_TOOL_FLOOR; } catch (e) { errors.push(`toolFloor: ${msg(e)}`); }
|
|
75
|
+
const floorSet = new Set(floor);
|
|
76
|
+
|
|
77
|
+
const marks = await guard('toolRiskMarks', async () => (d.loadMarks || defaultLoadMarks)({ cwd }), null);
|
|
78
|
+
const isRisky = (tool) => {
|
|
79
|
+
if (!marks) return false;
|
|
80
|
+
try { return !!require('./toolRiskMarks.cjs').resolveMark({ tool }, marks); } catch { return false; }
|
|
81
|
+
};
|
|
82
|
+
const badgesFor = (name, { floorable = true } = {}) => {
|
|
83
|
+
/** @type {('risky'|'banned'|'floor')[]} */ const b = [];
|
|
84
|
+
if (isRisky(name)) b.push('risky');
|
|
85
|
+
if (banned.has(name)) b.push('banned');
|
|
86
|
+
if (floorable && floorSet.has(name)) b.push('floor');
|
|
87
|
+
return b;
|
|
88
|
+
};
|
|
89
|
+
const item = (name, opts) => ({ id: name, label: name, badges: badgesFor(name, opts) });
|
|
90
|
+
|
|
91
|
+
const builtin = await guard('builtinTools', async () => (d.getBuiltinTools || require('./builtinTools.cjs').getBuiltinTools)(), null);
|
|
92
|
+
if (builtin) {
|
|
93
|
+
out.builtins = (builtin.tools || []).map((t) => item(t));
|
|
94
|
+
out.bundledSkills = (builtin.skills || []).map((s) => item(s, { floorable: false }));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const packRes = await guard('packs', async () => (d.listPacks || require('../packs/packCatalog.cjs').listPacks)(), null);
|
|
98
|
+
if (packRes) {
|
|
99
|
+
out.packs = (packRes.packs || []).map((p) => ({
|
|
100
|
+
id: p.id, label: p.label || p.id, badges: [], skills: [...(p.skills || [])], source: p.source,
|
|
101
|
+
}));
|
|
102
|
+
for (const e of packRes.errors || []) errors.push(`packs: ${e.dir}: ${e.error}`);
|
|
103
|
+
}
|
|
104
|
+
out.unpackedSkills = await guard('unpackedSkills', async () => [...(d.listUnpackedSkills || require('../packs/packCatalog.cjs').listUnpackedSkills)()], []);
|
|
105
|
+
|
|
106
|
+
const servers = await guard('mcpServers', async () => (d.listMcpServers || defaultListMcpServers)({ cwd }), []);
|
|
107
|
+
for (const s of servers) {
|
|
108
|
+
let status = 'not-checked';
|
|
109
|
+
let tools = [];
|
|
110
|
+
try {
|
|
111
|
+
const probe = await (d.getMcpProbe || defaultGetMcpProbe)({ name: s.name, scope: s.scope, cwd });
|
|
112
|
+
if (probe && probe.ok === false) status = 'failing';
|
|
113
|
+
else if (probe && Array.isArray(probe.tools)) {
|
|
114
|
+
status = 'checked';
|
|
115
|
+
tools = probe.tools
|
|
116
|
+
.map((t) => (typeof t === 'string' ? t : t && t.name))
|
|
117
|
+
.filter((n) => typeof n === 'string' && n)
|
|
118
|
+
.map((n) => ({ id: `mcp__${s.name}__${n}`, label: n, badges: badgesFor(`mcp__${s.name}__${n}`, { floorable: false }) }));
|
|
119
|
+
}
|
|
120
|
+
} catch (e) { errors.push(`mcpProbe ${s.name}: ${msg(e)}`); }
|
|
121
|
+
out.mcpServers.push({ id: s.name, label: s.name, badges: [], tools, status, scope: s.scope });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
out.environments = await guard('environments', async () => (d.listEnvironments || defaultListEnvironments)(), []);
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
module.exports = { buildArmory };
|
|
@@ -257,7 +257,7 @@ const DEFAULT_PRD_AGENT_TYPE = 'dev-lead';
|
|
|
257
257
|
* read) and this module's frontmatter-stripped-body cap.
|
|
258
258
|
*
|
|
259
259
|
* @param {{ cwd: string, agentType: string|null, deps?: object }} opts
|
|
260
|
-
* @returns {Promise<{ model: string|null, systemPrompt: string|null, personaPath: string|null, tools: string[]|null, refusal: null|{ code: 'persona_missing'|'persona_invalid', detail: string } }>}
|
|
260
|
+
* @returns {Promise<{ model: string|null, systemPrompt: string|null, personaPath: string|null, tools: string[]|null, loadout?: 'undecided'|'bare'|'equipped'|'unbound', refusal: null|{ code: 'persona_missing'|'persona_invalid', detail: string } }>}
|
|
261
261
|
*/
|
|
262
262
|
async function resolvePrdPersonaForSpawn({ cwd, agentType, deps = {} } = {}) {
|
|
263
263
|
const name = agentType || DEFAULT_PRD_AGENT_TYPE;
|
|
@@ -295,7 +295,8 @@ async function resolvePrdPersonaForSpawn({ cwd, agentType, deps = {} } = {}) {
|
|
|
295
295
|
const systemPrompt = buildPersonaBodyText(body, persona.path, { uncapped });
|
|
296
296
|
const parseTools = deps.parseTools || require('../../agentLibrary.cjs').parseTools;
|
|
297
297
|
const list = parseTools(typeof fm.tools === 'string' ? fm.tools : '');
|
|
298
|
-
|
|
298
|
+
const { loadoutState } = require('../persona-macro/personaLoadout.cjs');
|
|
299
|
+
return { model, systemPrompt, personaPath: persona.path, tools: list.length ? list : null, loadout: loadoutState(fm), refusal: null };
|
|
299
300
|
} catch (err) {
|
|
300
301
|
const msg = err && err.message ? err.message : String(err);
|
|
301
302
|
return refuse('persona_invalid', `agentType '${name}' persona ${persona.path || '(unknown path)'} could not be parsed: ${msg}`, persona.path || null);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* agent), stored locally and content-addressed.
|
|
6
6
|
*
|
|
7
7
|
* A snapshot freezes exactly the agent definition a run used:
|
|
8
|
-
* { name, bodySha256, body, model, effort, tools, mcpServers, packs, seedVersion, environment }
|
|
8
|
+
* { name, bodySha256, body, model, effort, tools, mcpServers, packs, seedVersion, environment, gearBindsChat, loadout }
|
|
9
9
|
* Its id is the sha256 of its canonical JSON (keys sorted at every depth), so
|
|
10
10
|
* equal definitions share one id and any edit (body, model, tools, ...) mints
|
|
11
11
|
* a new one. A resume can therefore re-run precisely the definition it pinned.
|
|
@@ -36,6 +36,7 @@ const crypto = require('node:crypto');
|
|
|
36
36
|
const fsp = require('node:fs/promises');
|
|
37
37
|
const { opsPath, assertOpsWrite } = require('../opsOwnership.cjs');
|
|
38
38
|
const atomicFs = require('../util/atomicFs.cjs');
|
|
39
|
+
const { loadoutState } = require('../persona-macro/personaLoadout.cjs');
|
|
39
40
|
|
|
40
41
|
const WRITER = 'agents';
|
|
41
42
|
const ID_RE = /^[0-9a-f]{64}$/;
|
|
@@ -107,6 +108,23 @@ async function buildAgentSnapshot({ cwd, agentType, packs, deps = {} } = {}) {
|
|
|
107
108
|
return { id: null, snapshot: null, refusal: { code: env.code, detail } };
|
|
108
109
|
}
|
|
109
110
|
|
|
111
|
+
// Persona-declared capabilities (`mcpServers:` / `packs:`) are part of the snapshot, so every
|
|
112
|
+
// caller (epicMint, epicAgentRefresh, scheduler) records the same resolved set.
|
|
113
|
+
let declaredServers = [];
|
|
114
|
+
let declaredPacks = [];
|
|
115
|
+
if (fm) {
|
|
116
|
+
try {
|
|
117
|
+
const { parseCapabilityList } = require('../../agentLibrary.cjs');
|
|
118
|
+
declaredServers = parseCapabilityList(fm.mcpServers);
|
|
119
|
+
declaredPacks = parseCapabilityList(fm.packs);
|
|
120
|
+
} catch { /* no declared capabilities */ }
|
|
121
|
+
}
|
|
122
|
+
const mergedPacks = [];
|
|
123
|
+
for (const p of [...declaredPacks, ...(Array.isArray(packs) ? packs : [])]) {
|
|
124
|
+
const id = String(p);
|
|
125
|
+
if (!mergedPacks.includes(id)) mergedPacks.push(id);
|
|
126
|
+
}
|
|
127
|
+
|
|
110
128
|
const body = resolved.systemPrompt || '';
|
|
111
129
|
const tools = Array.isArray(resolved.tools) ? resolved.tools.map(String) : null;
|
|
112
130
|
const snapshot = {
|
|
@@ -116,10 +134,13 @@ async function buildAgentSnapshot({ cwd, agentType, packs, deps = {} } = {}) {
|
|
|
116
134
|
model: resolved.model || null,
|
|
117
135
|
effort: effort || null,
|
|
118
136
|
tools,
|
|
119
|
-
mcpServers: mcpServersFromTools(tools),
|
|
120
|
-
packs:
|
|
137
|
+
mcpServers: [...new Set([...declaredServers.map((d) => String(d).trim()).filter(Boolean), ...mcpServersFromTools(tools)])].sort(),
|
|
138
|
+
packs: mergedPacks,
|
|
121
139
|
seedVersion,
|
|
122
140
|
environment: { id: env.id, hash: env.hash },
|
|
141
|
+
// Gear applies to chat turns only for snapshots stamped true; older snapshots lack the key (falsy).
|
|
142
|
+
gearBindsChat: true,
|
|
143
|
+
loadout: loadoutState(fm),
|
|
123
144
|
};
|
|
124
145
|
return { id: snapshotId(snapshot), snapshot, refusal: null };
|
|
125
146
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* builtinTools.cjs — learns the claude CLI's real built-in tool and bundled-skill
|
|
5
|
+
* names from the stream-json `system`/`init` event of a minimal run. The init
|
|
6
|
+
* event is emitted before the first API call, so the child is killed on init and
|
|
7
|
+
* no model tokens are spent. Cached in memory per CLI version; any failure
|
|
8
|
+
* returns FALLBACK_TOOLS (source 'fallback') and never throws.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const os = require('node:os');
|
|
12
|
+
const { resolveClaudeBin, probeClaudeVersion } = require('./claudeBin.cjs');
|
|
13
|
+
const { killTree, detachedSpawnOpts } = require('../process/killTree.cjs');
|
|
14
|
+
const { cleanChildEnv } = require('../process/cleanEnv.cjs');
|
|
15
|
+
|
|
16
|
+
const FALLBACK_TOOLS = ['Read', 'Grep', 'Glob', 'Bash', 'Write', 'Edit', 'WebFetch', 'WebSearch', 'Task', 'Agent', 'Skill', 'NotebookEdit', 'TodoWrite'];
|
|
17
|
+
const PROBE_TIMEOUT_MS = 20_000;
|
|
18
|
+
const OUTPUT_CAP_BYTES = 2 * 1024 * 1024;
|
|
19
|
+
|
|
20
|
+
/** @type {Map<string, { tools: string[], skills: string[], source: 'cli' | 'fallback', cliVersion: string | null }>} */
|
|
21
|
+
const cache = new Map();
|
|
22
|
+
|
|
23
|
+
const strings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x) : []);
|
|
24
|
+
|
|
25
|
+
/** Probe argv: pinned model, no user MCP, no user/project/local settings or plugins. */
|
|
26
|
+
function probeArgs() {
|
|
27
|
+
return ['--model', 'haiku', '-p', 'hi', '--output-format', 'stream-json', '--verbose', '--strict-mcp-config', '--setting-sources', 'project'];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Spawn the probe; resolve with the parsed init event or null. Never rejects.
|
|
32
|
+
* @returns {Promise<Record<string, any> | null>}
|
|
33
|
+
*/
|
|
34
|
+
function runProbe(spawn, claudeBin) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
let child = null;
|
|
37
|
+
let settled = false;
|
|
38
|
+
let buf = '';
|
|
39
|
+
let bytes = 0;
|
|
40
|
+
let timer = null;
|
|
41
|
+
const finish = (value) => {
|
|
42
|
+
if (settled) return;
|
|
43
|
+
settled = true;
|
|
44
|
+
if (timer) clearTimeout(timer);
|
|
45
|
+
if (child && child.pid) { try { killTree(child.pid, 'SIGKILL'); } catch { /* */ } }
|
|
46
|
+
else if (child && typeof child.kill === 'function') { try { child.kill('SIGKILL'); } catch { /* */ } }
|
|
47
|
+
resolve(value);
|
|
48
|
+
};
|
|
49
|
+
const feed = (chunk) => {
|
|
50
|
+
if (settled) return;
|
|
51
|
+
bytes += chunk.length;
|
|
52
|
+
buf += chunk.toString();
|
|
53
|
+
let nl;
|
|
54
|
+
while ((nl = buf.indexOf('\n')) >= 0) {
|
|
55
|
+
const line = buf.slice(0, nl).trim();
|
|
56
|
+
buf = buf.slice(nl + 1);
|
|
57
|
+
if (!line) continue;
|
|
58
|
+
let evt;
|
|
59
|
+
try { evt = JSON.parse(line); } catch { return finish(null); }
|
|
60
|
+
if (evt && evt.type === 'system' && evt.subtype === 'init') return finish(evt);
|
|
61
|
+
}
|
|
62
|
+
if (bytes > OUTPUT_CAP_BYTES) finish(null);
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
child = spawn(claudeBin, probeArgs(), {
|
|
66
|
+
cwd: os.tmpdir(),
|
|
67
|
+
env: cleanChildEnv(),
|
|
68
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
69
|
+
windowsHide: true,
|
|
70
|
+
...detachedSpawnOpts(),
|
|
71
|
+
});
|
|
72
|
+
timer = setTimeout(() => finish(null), PROBE_TIMEOUT_MS);
|
|
73
|
+
if (child.stdout) child.stdout.on('data', feed);
|
|
74
|
+
child.on('error', () => finish(null));
|
|
75
|
+
child.on('close', () => finish(null));
|
|
76
|
+
} catch {
|
|
77
|
+
finish(null);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {{ spawn?: Function, claudeBin?: string, cliVersion?: string | null }} [opts]
|
|
84
|
+
* @returns {Promise<{ tools: string[], skills: string[], source: 'cli' | 'fallback', cliVersion: string | null }>}
|
|
85
|
+
*/
|
|
86
|
+
async function getBuiltinTools({ spawn, claudeBin, cliVersion } = {}) {
|
|
87
|
+
let version = cliVersion || null;
|
|
88
|
+
try {
|
|
89
|
+
if (!version) version = await probeClaudeVersion();
|
|
90
|
+
} catch { /* version stays null */ }
|
|
91
|
+
const key = version || 'unknown';
|
|
92
|
+
const hit = cache.get(key);
|
|
93
|
+
if (hit) return { ...hit, tools: [...hit.tools], skills: [...hit.skills] };
|
|
94
|
+
try {
|
|
95
|
+
const doSpawn = spawn || require('node:child_process').spawn;
|
|
96
|
+
const init = await runProbe(doSpawn, claudeBin || resolveClaudeBin());
|
|
97
|
+
const tools = init ? strings(init.tools).filter((t) => !t.startsWith('mcp__')) : [];
|
|
98
|
+
if (init && tools.length) {
|
|
99
|
+
const result = { tools, skills: strings(init.skills), source: /** @type {const} */ ('cli'), cliVersion: version };
|
|
100
|
+
cache.set(key, result);
|
|
101
|
+
return { ...result, tools: [...tools], skills: [...result.skills] };
|
|
102
|
+
}
|
|
103
|
+
} catch { /* fall through */ }
|
|
104
|
+
return { tools: [...FALLBACK_TOOLS], skills: [], source: 'fallback', cliVersion: version };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Test hook — forget cached probes. */
|
|
108
|
+
function __resetForTests() { cache.clear(); }
|
|
109
|
+
|
|
110
|
+
module.exports = { getBuiltinTools, FALLBACK_TOOLS, __resetForTests };
|