claude-code-session-manager 0.139.0 → 0.141.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 +20 -4
- package/dist/assets/AppSettings-DExeJhqQ.js +2 -0
- package/dist/assets/History-DJMiuXyK.js +2 -0
- package/dist/assets/{HomeClaudeConfig-CGD2Onjv.js → HomeClaudeConfig-CTp2tkZ4.js} +2 -2
- package/dist/assets/{Panel-Csyd9HbD.js → Panel-Bf1Cf8UL.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-C-jlYpC_.js → ProjectClaudeConfig-BWPpypf9.js} +1 -1
- package/dist/assets/Scheduler-cyr61UAC.js +16 -0
- package/dist/assets/{SkillReferenceGraph-DcscPXAG.js → SkillReferenceGraph-Ba4TkX2C.js} +1 -1
- package/dist/assets/{Skills-BpGRKOcY.js → Skills-C1v91GEO.js} +26 -26
- package/dist/assets/{TiptapBody-DSU3769X.js → TiptapBody-BrcWVpiW.js} +1 -1
- package/dist/assets/{ViewTabs-C0PRZx4_.js → ViewTabs-DXhOWFG0.js} +1 -1
- package/dist/assets/{VoiceButton-D2rMurNg.js → VoiceButton-qivnDV6K.js} +1 -1
- package/dist/assets/{historyTotals-TcIQs2sh.js → historyTotals-CMCPTKqC.js} +1 -1
- package/dist/assets/index-B2TQz3nd.js +3121 -0
- package/dist/assets/{index-BCySPdtU.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +423 -426
- package/package.json +5 -2
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/skills/builder/SKILL.md +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +29 -19
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
- package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
- package/scripts/README.md +1 -0
- package/scripts/hooks/guard-tool-risk.cjs +91 -0
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
- package/scripts/ops-sweep.cjs +53 -23
- package/scripts/scheduler-mcp-server.cjs +205 -18
- package/src/main/build-info.json +4 -4
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +88 -5
- package/src/main/historyDashboard.cjs +69 -4
- package/src/main/index.cjs +56 -2
- package/src/main/ipcSchemas.cjs +122 -16
- package/src/main/lib/AGENTS.md +54 -0
- package/src/main/lib/CLAUDE.md +1 -54
- package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
- package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
- package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
- package/src/main/lib/claude/effectiveModelInfo.cjs +90 -20
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/personaToolScope.cjs +12 -6
- package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
- package/src/main/lib/claude/runClaudeP.cjs +6 -1
- package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
- package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
- package/src/main/lib/ephemeralCwd.cjs +37 -2
- package/src/main/lib/epic/delegationReadiness.cjs +42 -9
- package/src/main/lib/epic/epicAdminRoutes.cjs +25 -5
- package/src/main/lib/epic/epicOutsideRead.cjs +118 -1
- package/src/main/lib/epic/epicOutsideState.cjs +2 -2
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/externalContract.cjs +31 -5
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +55 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +106 -11
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +47 -19
- package/src/main/lib/feedback-remote/needsYouStore.cjs +6 -2
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
- package/src/main/lib/git/branchSweep.cjs +209 -4
- package/src/main/lib/git/gitWorktree.cjs +41 -5
- package/src/main/lib/guardShims.cjs +1 -1
- package/src/main/lib/historyRollup.cjs +26 -0
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +132 -13
- package/src/main/lib/mdDocCensus.cjs +59 -78
- package/src/main/lib/mdDocRefs.cjs +71 -93
- package/src/main/lib/mdNetworkScan.cjs +245 -250
- package/src/main/lib/mdReviewRecord.cjs +22 -9
- package/src/main/lib/memoryMdNetwork.cjs +5 -12
- package/src/main/lib/opsOwnership.cjs +18 -2
- package/src/main/lib/opsRetentionSettings.cjs +28 -4
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
- package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
- package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
- package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
- package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/depSlugResolve.cjs +104 -4
- package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
- package/src/main/lib/prd/prdCreate.cjs +377 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +121 -3
- package/src/main/lib/process/loginItem.cjs +171 -0
- package/src/main/lib/process/loginItemPlan.cjs +193 -0
- package/src/main/lib/project-pages/playerBridge.cjs +4 -0
- package/src/main/lib/project-pages/videoReview.cjs +268 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
- package/src/main/lib/scheduler/cpuSample.cjs +131 -4
- package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
- package/src/main/lib/scheduler/loadGate.cjs +24 -6
- package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
- package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
- package/src/main/lib/scheduler/preflightCheck.cjs +97 -0
- package/src/main/lib/scheduler/queueStore.cjs +7 -0
- package/src/main/lib/scheduler/rcaReport.cjs +21 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
- package/src/main/lib/scheduler/reviewNotice.cjs +39 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
- package/src/main/lib/scheduler/schedulerPaths.cjs +3 -0
- package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
- package/src/main/lib/scheduler/validationQuality.cjs +282 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
- package/src/main/lib/tasks/taskIpc.cjs +80 -0
- package/src/main/lib/tasks/taskLedger.cjs +502 -0
- package/src/main/lib/tasks/taskRun.cjs +313 -0
- package/src/main/lib/tasks/taskSwitch.cjs +120 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +10 -1
- package/src/main/projectPages.cjs +6 -15
- package/src/main/promptSessionEvents.cjs +9 -1
- package/src/main/queueOps.cjs +260 -3
- package/src/main/runVerify.cjs +53 -25
- package/src/main/scheduler/AGENTS.md +26 -0
- package/src/main/scheduler/CLAUDE.md +1 -26
- package/src/main/scheduler/budget.cjs +239 -9
- package/src/main/scheduler/cancelDependents.cjs +154 -0
- package/src/main/scheduler/prdParser.cjs +19 -1
- package/src/main/scheduler/reviewLadder.cjs +36 -3
- package/src/main/scheduler/starvation.cjs +89 -18
- package/src/main/scheduler.cjs +1080 -89
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +14 -1
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +10 -2
- package/src/preload/api.d.ts +364 -21
- package/src/preload/apiSurface.json +89 -10
- package/src/preload/index.cjs +23 -2
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AppSettings-CUfWY9vN.js +0 -2
- package/dist/assets/History-DDnqaLyw.js +0 -2
- package/dist/assets/Scheduler-NLs08fx7.js +0 -16
- package/dist/assets/index-C-d0DCre.js +0 -3124
|
@@ -16,7 +16,10 @@
|
|
|
16
16
|
* - newestRecordName(names) — pure: the newest record file name, or null.
|
|
17
17
|
* - parseReviewRecord(text) — pure: the template fields; never throws.
|
|
18
18
|
* - readMdReview(root, { epicIds }) — newest record + validation record paths
|
|
19
|
-
*
|
|
19
|
+
* for each safe Epic id, read from disk in plan-records/<epicId>/ (the
|
|
20
|
+
* machine-local, never-committed namespace) merged with the legacy
|
|
21
|
+
* reviews/validation/<epicId>/ history. On a file-name clash the
|
|
22
|
+
* plan-records copy wins.
|
|
20
23
|
*/
|
|
21
24
|
|
|
22
25
|
const fsp = require('node:fs/promises');
|
|
@@ -244,11 +247,14 @@ async function readMdReview(root, opts = {}) {
|
|
|
244
247
|
/** @type {string} */
|
|
245
248
|
let docsDir;
|
|
246
249
|
/** @type {string} */
|
|
247
|
-
let
|
|
250
|
+
let planRecordsDir;
|
|
251
|
+
/** @type {string} */
|
|
252
|
+
let legacyValidationDir;
|
|
248
253
|
try {
|
|
249
254
|
projectRoot = resolveProjectRoot(root);
|
|
250
255
|
docsDir = opsPath(root, 'reviews', 'docs');
|
|
251
|
-
|
|
256
|
+
planRecordsDir = opsPath(root, 'plan-records');
|
|
257
|
+
legacyValidationDir = opsPath(root, 'reviews', 'validation');
|
|
252
258
|
} catch (err) {
|
|
253
259
|
return { ok: false, error: err instanceof Error ? err.message : String(err) };
|
|
254
260
|
}
|
|
@@ -273,12 +279,19 @@ async function readMdReview(root, opts = {}) {
|
|
|
273
279
|
const ids = Array.isArray(opts.epicIds) ? opts.epicIds : [];
|
|
274
280
|
for (const id of ids) {
|
|
275
281
|
if (typeof id !== 'string' || !EPIC_ID_RE.test(id) || validation[id]) continue;
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
.
|
|
281
|
-
|
|
282
|
+
/** @type {Map<string, string>} file name -> repo-relative path */
|
|
283
|
+
const byName = new Map();
|
|
284
|
+
// plan-records first so its copy wins a name clash with the legacy folder.
|
|
285
|
+
for (const base of [planRecordsDir, legacyValidationDir]) {
|
|
286
|
+
const dir = path.join(base, id);
|
|
287
|
+
for (const e of await listDir(dir)) {
|
|
288
|
+
if (!e.isFile() || !e.name.endsWith('.md') || byName.has(e.name)) continue;
|
|
289
|
+
byName.set(e.name, rel(projectRoot, path.join(dir, e.name)));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Ordered by file name so the last entry is the newest record (the
|
|
293
|
+
// renderer's pickValidationPath takes the last one).
|
|
294
|
+
validation[id] = [...byName.keys()].sort().map((n) => /** @type {string} */ (byName.get(n)));
|
|
282
295
|
}
|
|
283
296
|
|
|
284
297
|
return { ok: true, record, recordPath, validation };
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const fs = require('node:fs');
|
|
11
11
|
const path = require('node:path');
|
|
12
|
+
const { linksOf } = require('../../../plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs');
|
|
12
13
|
|
|
13
14
|
const ROOT_MAX_BYTES = 16 * 1024;
|
|
14
15
|
const MAX_DOCS = 60;
|
|
@@ -18,7 +19,6 @@ const HITS_PER_DOC = 3;
|
|
|
18
19
|
const HITS_TOTAL = 8;
|
|
19
20
|
const MAX_LINE_CHARS = 200;
|
|
20
21
|
|
|
21
|
-
const MD_LINK_RE = /\]\(([^)\s]+\.md)(#[^)]*)?\)/g;
|
|
22
22
|
const TERM_RE = /`([^`\n]{4,80})`/g;
|
|
23
23
|
const ROOT_DOC = 'CLAUDE.md';
|
|
24
24
|
|
|
@@ -35,18 +35,11 @@ function safeRead(readFile, abs) {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** Docs the root CLAUDE.md links to, by the shared link convention (mdLinks.cjs). */
|
|
38
39
|
function extractLinkedDocs(rootText) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
while ((m = MD_LINK_RE.exec(rootText)) !== null) {
|
|
43
|
-
const target = m[1];
|
|
44
|
-
if (/^(?:https?|file):\/\//i.test(target)) continue;
|
|
45
|
-
const norm = path.posix.normalize(target);
|
|
46
|
-
if (norm.startsWith('..') || norm.startsWith('/')) continue;
|
|
47
|
-
out.push(norm);
|
|
48
|
-
}
|
|
49
|
-
return out;
|
|
40
|
+
return linksOf({ path: ROOT_DOC, text: rootText })
|
|
41
|
+
.filter((l) => !l.escapes && /\.md$/i.test(l.to))
|
|
42
|
+
.map((l) => l.to);
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
function extractTerms(body) {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
* - lib/epic/epicMint.cjs (raw fs tmp+rename)
|
|
28
28
|
* - lib/scheduler/queueStore.cjs (raw fs tmp+rename)
|
|
29
29
|
* - lib/telemetry/opsErrorLog.cjs (raw fs append, JSONL error log)
|
|
30
|
+
* - lib/tasks/taskLedger.cjs (raw fs append + atomicFs bodies)
|
|
30
31
|
* Renderer callers declare their writer id through the IPC payload.
|
|
31
32
|
*/
|
|
32
33
|
|
|
@@ -70,6 +71,16 @@ const OWNERS = Object.freeze({
|
|
|
70
71
|
// the renderer through the generic config:write-json IPC with writer:
|
|
71
72
|
// 'ui-prefs'; no dedicated main-process module. See ui-prefs/README.md.
|
|
72
73
|
'ui-prefs': 'ui-prefs',
|
|
74
|
+
// The Task ledger: one summary JSONL line per Task event (a Task = one
|
|
75
|
+
// headless claude -p run for this project) in tasks/<YYYY-MM-DD>.jsonl, plus
|
|
76
|
+
// tasks/bodies/<taskId>.json prompt/output bodies. lib/tasks/taskLedger.cjs is
|
|
77
|
+
// the ONLY writer; routes, IPC and history read through it. See tasks/README.md.
|
|
78
|
+
'tasks': 'tasks',
|
|
79
|
+
// Per-run plan records (validator + ship/deploy records), laid out as
|
|
80
|
+
// plan-records/<epic-id>/<slug>.md. Machine-local runtime state: the
|
|
81
|
+
// scheduler copies them out of job worktrees and prunes them after the Epic
|
|
82
|
+
// completes. See plan-records/README.md.
|
|
83
|
+
'plan-records': 'scheduler',
|
|
73
84
|
});
|
|
74
85
|
|
|
75
86
|
/**
|
|
@@ -80,7 +91,8 @@ const OWNERS = Object.freeze({
|
|
|
80
91
|
* runtime state all the same, so it lives only in this set.
|
|
81
92
|
*/
|
|
82
93
|
const RUNTIME_NAMESPACES = Object.freeze([
|
|
83
|
-
'scheduler', 'prompt-sessions', 'feedback', 'logs', 'ui-prefs', 'memory-clusters',
|
|
94
|
+
'scheduler', 'prompt-sessions', 'feedback', 'logs', 'ui-prefs', 'memory-clusters', 'tasks',
|
|
95
|
+
'plan-records',
|
|
84
96
|
]);
|
|
85
97
|
|
|
86
98
|
/** Writer id for the per-namespace self-ignore file. */
|
|
@@ -303,7 +315,11 @@ function resolveProjectRoot(cwd, { opsInternal = 'normalize' } = {}) {
|
|
|
303
315
|
// `unknown` deliberately does NOT throw here: reads and dispatch must keep
|
|
304
316
|
// working; assertOpsWrite is the choke point that refuses the WRITE.
|
|
305
317
|
const root = classifyCwd(cwd).projectRoot;
|
|
306
|
-
|
|
318
|
+
// refuseMissingInTmp:false — a MISSING path is not a write target this
|
|
319
|
+
// resolver can refuse; readers need its path, and existence-aware callers
|
|
320
|
+
// report it themselves (see ephemeralCwd.cjs). Existing tmpdir roots and
|
|
321
|
+
// linked worktrees are still refused below.
|
|
322
|
+
if (isEphemeralCwd(root, { refuseMissingInTmp: false })) {
|
|
307
323
|
const err = new Error(
|
|
308
324
|
`resolveProjectRoot: refusing ephemeral cwd (tmpdir or linked git worktree), got "${cwd}"`,
|
|
309
325
|
);
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Storage: ~/.claude/session-manager/ops-retention.json
|
|
5
5
|
* Shape (DEFAULTS): { runLogs:{maxAgeDays,keepPerSlug}, runsArchiveDays, auditLogMonths,
|
|
6
|
-
* reservedMarkersKeep }
|
|
6
|
+
* reservedMarkersKeep, tasksDays, planRecordsDays }
|
|
7
|
+
* tasksDays: Task ledger day files + bodies (lib/tasks/taskLedger.cjs pruneOld).
|
|
8
|
+
* planRecordsDays: plan-records/<epic-id>/ folders of completed/orphan Epics
|
|
9
|
+
* (lib/scheduler/planRecordRetention.cjs prunePlanRecords).
|
|
7
10
|
* Archived transcripts are kept forever (fixed policy, not a setting).
|
|
8
11
|
*
|
|
9
12
|
* Top-level in lib/ (no domain fits: read by scheduler, telemetry and epic sweeps alike).
|
|
@@ -22,6 +25,8 @@ const DEFAULTS = Object.freeze({
|
|
|
22
25
|
runsArchiveDays: 30,
|
|
23
26
|
auditLogMonths: 6,
|
|
24
27
|
reservedMarkersKeep: 100,
|
|
28
|
+
tasksDays: 30,
|
|
29
|
+
planRecordsDays: 14,
|
|
25
30
|
});
|
|
26
31
|
|
|
27
32
|
// [min, max] per integer field; out-of-range values clamp, non-integers round.
|
|
@@ -31,6 +36,8 @@ const BOUNDS = Object.freeze({
|
|
|
31
36
|
runsArchiveDays: [1, 3650],
|
|
32
37
|
auditLogMonths: [1, 120],
|
|
33
38
|
reservedMarkersKeep: [1, 100000],
|
|
39
|
+
tasksDays: [1, 3650],
|
|
40
|
+
planRecordsDays: [1, 3650],
|
|
34
41
|
});
|
|
35
42
|
|
|
36
43
|
function storePath() {
|
|
@@ -64,7 +71,7 @@ function validatePatch(patch) {
|
|
|
64
71
|
if (rk !== 'maxAgeDays' && rk !== 'keepPerSlug') throw new Error(`Invalid ops retention config: runLogs.${rk}`);
|
|
65
72
|
out.runLogs[rk] = num(`runLogs.${rk}`, rv);
|
|
66
73
|
}
|
|
67
|
-
} else if (k === 'runsArchiveDays' || k === 'auditLogMonths' || k === 'reservedMarkersKeep') {
|
|
74
|
+
} else if (k === 'runsArchiveDays' || k === 'auditLogMonths' || k === 'reservedMarkersKeep' || k === 'tasksDays' || k === 'planRecordsDays') {
|
|
68
75
|
out[k] = num(k, v);
|
|
69
76
|
} else {
|
|
70
77
|
throw new Error(`Invalid ops retention config: unknown key ${k}`);
|
|
@@ -88,7 +95,7 @@ function sanitizeStored(data) {
|
|
|
88
95
|
};
|
|
89
96
|
}
|
|
90
97
|
}
|
|
91
|
-
for (const key of ['runsArchiveDays', 'auditLogMonths', 'reservedMarkersKeep']) {
|
|
98
|
+
for (const key of ['runsArchiveDays', 'auditLogMonths', 'reservedMarkersKeep', 'tasksDays', 'planRecordsDays']) {
|
|
92
99
|
const v = int(key, data[key]);
|
|
93
100
|
if (v !== undefined) out[key] = v;
|
|
94
101
|
}
|
|
@@ -113,6 +120,8 @@ function withDefaults(stored) {
|
|
|
113
120
|
runsArchiveDays: s.runsArchiveDays ?? DEFAULTS.runsArchiveDays,
|
|
114
121
|
auditLogMonths: s.auditLogMonths ?? DEFAULTS.auditLogMonths,
|
|
115
122
|
reservedMarkersKeep: s.reservedMarkersKeep ?? DEFAULTS.reservedMarkersKeep,
|
|
123
|
+
tasksDays: s.tasksDays ?? DEFAULTS.tasksDays,
|
|
124
|
+
planRecordsDays: s.planRecordsDays ?? DEFAULTS.planRecordsDays,
|
|
116
125
|
};
|
|
117
126
|
}
|
|
118
127
|
|
|
@@ -136,7 +145,9 @@ function write(patch) {
|
|
|
136
145
|
|
|
137
146
|
/**
|
|
138
147
|
* Dry-run report of what each policy would free, via the sweeps' own
|
|
139
|
-
* eligibility code. Read-only. opts: { now, runsDir, plansRoot, jobs, liveKeys
|
|
148
|
+
* eligibility code. Read-only. opts: { now, runsDir, plansRoot, jobs, liveKeys,
|
|
149
|
+
* projectRoot, epicStatus }. planRecords is reported only when projectRoot is given;
|
|
150
|
+
* epicStatus defaults to reading that project's prompt-sessions/<id>.json.
|
|
140
151
|
*/
|
|
141
152
|
function preview(opts) {
|
|
142
153
|
const o = opts || {};
|
|
@@ -167,10 +178,23 @@ function preview(opts) {
|
|
|
167
178
|
dryRun: true,
|
|
168
179
|
});
|
|
169
180
|
const tmp = staleTmpSweep.sweepStaleTmp(plansRoot, { now, dryRun: true });
|
|
181
|
+
let planRecords = null;
|
|
182
|
+
if (o.projectRoot) {
|
|
183
|
+
const planRecordRetention = require('./scheduler/planRecordRetention.cjs');
|
|
184
|
+
const pr = planRecordRetention.prunePlanRecords({
|
|
185
|
+
projectRoot: o.projectRoot,
|
|
186
|
+
epicStatus: typeof o.epicStatus === 'function' ? o.epicStatus : planRecordRetention.defaultEpicStatus(o.projectRoot),
|
|
187
|
+
now,
|
|
188
|
+
days: s.planRecordsDays,
|
|
189
|
+
dryRun: true,
|
|
190
|
+
});
|
|
191
|
+
planRecords = { folders: pr.removed.length };
|
|
192
|
+
}
|
|
170
193
|
return {
|
|
171
194
|
runLogs: { files: report.eligible.reduce((n, e) => n + e.removeFiles.length, 0) + report.dodFiles.length, bytes: report.eligibleSummary.bytes },
|
|
172
195
|
runsArchive: { entries: archive.removedFiles, bytes: archive.freedBytes },
|
|
173
196
|
tmp: { files: tmp.removedFiles, bytes: tmp.freedBytes },
|
|
197
|
+
...(planRecords ? { planRecords } : {}),
|
|
174
198
|
};
|
|
175
199
|
}
|
|
176
200
|
|
|
@@ -6,6 +6,9 @@
|
|
|
6
6
|
* macro's persona under the scheduler's budget instead of a chat turn.
|
|
7
7
|
* Never mints an Epic (single-creator law): the caller supplies epicId.
|
|
8
8
|
* A press may carry a lower per-run effort, written as the PRD's `effort` frontmatter.
|
|
9
|
+
* A project's own Video tool (library macro, surface 'project-video', projects
|
|
10
|
+
* [cwd], with a job) dispatches the same way: artifact-only, or a committing PRD
|
|
11
|
+
* when job.repoPaths is set, with an optional review stage when job.review is set.
|
|
9
12
|
*
|
|
10
13
|
* Plain Node, no Electron imports; all I/O is injected.
|
|
11
14
|
*/
|
|
@@ -14,6 +17,7 @@ const path = require('node:path');
|
|
|
14
17
|
const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
|
|
15
18
|
const { kebabCase } = require('../util/kebabCase.cjs');
|
|
16
19
|
const { PRD_EFFORT_LEVELS } = require('../prd/prdFrontmatter.cjs');
|
|
20
|
+
const { renderMacroPrompt } = require('./macroLibrary.cjs');
|
|
17
21
|
|
|
18
22
|
const ACTIVE = new Set(['pending', 'held', 'running']);
|
|
19
23
|
const RETRYABLE = new Set(['needs_review', 'failed']);
|
|
@@ -55,21 +59,67 @@ function rawEntryIdFor(kind, extra, t) {
|
|
|
55
59
|
return kebabCase(custom ? custom[1] : name, { maxLen: 40, fallback: 'overview' });
|
|
56
60
|
}
|
|
57
61
|
|
|
62
|
+
const VIDEO_INDEX_REL = 'session-manager-operations/project-pages/videos/{id}/index.html';
|
|
63
|
+
// Same string as video-review-store's REVIEW_MATERIAL_REL (asserted by the IPC wiring test).
|
|
64
|
+
const REVIEW_MATERIAL_REL = 'session-manager-operations/project-pages/videos/{id}/review/material.json';
|
|
65
|
+
|
|
66
|
+
const oneLine = (v) => String(v).replace(/[\r\n]+/g, ' ').trim();
|
|
67
|
+
|
|
68
|
+
// A caller can never forge a review decision: every 'Review:' line goes, and
|
|
69
|
+
// only the internal `review` param writes one back.
|
|
70
|
+
function stripReviewLines(extra) {
|
|
71
|
+
return extra.split(/\r?\n/).filter((l) => !/^\s*review:/i.test(l)).join('\n').trim();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function reviewLine(review) {
|
|
75
|
+
if (!review || typeof review !== 'object') return '';
|
|
76
|
+
if (review.decision === 'approved' && typeof review.at === 'string' && oneLine(review.at)) {
|
|
77
|
+
return `Review: approved by the owner at ${oneLine(review.at)}`;
|
|
78
|
+
}
|
|
79
|
+
if (review.decision === 'changes' && typeof review.note === 'string' && oneLine(review.note)) {
|
|
80
|
+
return `Review: changes requested: ${oneLine(review.note)}`;
|
|
81
|
+
}
|
|
82
|
+
return '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// A project's own Video tool: only from the library, only on the Video surface,
|
|
86
|
+
// only for exactly this project, only with a job declaration.
|
|
87
|
+
function resolveProjectTool(macros, macroId, cwd) {
|
|
88
|
+
const m = (Array.isArray(macros) ? macros : []).find((x) => x && x.id === macroId);
|
|
89
|
+
if (!m || m.builtin || m.surface !== 'project-video' || !m.job || typeof m.job !== 'object') return null;
|
|
90
|
+
if (!Array.isArray(m.projects) || m.projects.length !== 1 || m.projects[0] !== cwd) return null;
|
|
91
|
+
return m;
|
|
92
|
+
}
|
|
93
|
+
|
|
58
94
|
async function dispatchMacroJob(
|
|
59
|
-
{ cwd, macroId, epicId, extraInstructions, effort } = {},
|
|
60
|
-
{ createPrd, listRows, archivePrd, builtins = BUILTIN_MACROS, now = Date.now } = {},
|
|
95
|
+
{ cwd, macroId, epicId, extraInstructions, effort, inputValues, review } = {},
|
|
96
|
+
{ createPrd, listRows, archivePrd, builtins = BUILTIN_MACROS, macros = [], now = Date.now } = {},
|
|
61
97
|
) {
|
|
62
|
-
const
|
|
98
|
+
const builtin = (builtins || []).find((m) => m && m.id === macroId);
|
|
99
|
+
const tool = builtin ? null : resolveProjectTool(macros, macroId, cwd);
|
|
100
|
+
const macro = builtin || tool;
|
|
63
101
|
if (!macro || !macro.job) return { ok: false, error: `macro ${macroId} has no background job declaration` };
|
|
64
102
|
if (typeof epicId !== 'string' || !epicId.trim()) return { ok: false, error: 'epicId is required — a background build joins an existing Epic' };
|
|
65
103
|
if (typeof cwd !== 'string' || !cwd) return { ok: false, error: 'cwd is required' };
|
|
66
104
|
if (typeof createPrd !== 'function') return { ok: false, error: 'createPrd is not available' };
|
|
67
105
|
|
|
106
|
+
let prompt = macro.prompt;
|
|
107
|
+
if (tool) {
|
|
108
|
+
const r = renderMacroPrompt(tool.prompt, tool.inputs, inputValues);
|
|
109
|
+
if (!r.ok) return { ok: false, error: r.error };
|
|
110
|
+
prompt = r.prompt;
|
|
111
|
+
}
|
|
112
|
+
|
|
68
113
|
const t = now();
|
|
69
|
-
const
|
|
70
|
-
const
|
|
114
|
+
const rLine = reviewLine(review);
|
|
115
|
+
const extra = [stripReviewLines(typeof extraInstructions === 'string' ? extraInstructions : ''), rLine].filter(Boolean).join('\n');
|
|
116
|
+
const entryKind = tool ? 'video' : macro.job.entryKind;
|
|
71
117
|
const entryId = entryKind ? entryIdFor(entryKind, extra, t) : null;
|
|
72
|
-
const
|
|
118
|
+
const stage = tool && tool.job.review ? (review && review.decision === 'approved' ? 'final' : 'review') : null;
|
|
119
|
+
const repoPaths = tool && Array.isArray(tool.job.repoPaths) && tool.job.repoPaths.length ? tool.job.repoPaths.slice() : null;
|
|
120
|
+
const artifactPaths = tool
|
|
121
|
+
? [(stage === 'review' ? REVIEW_MATERIAL_REL : VIDEO_INDEX_REL).split('{id}').join(entryId)]
|
|
122
|
+
: macro.job.artifactPaths.map((p) => (entryId ? p.split('{id}').join(entryId) : p));
|
|
73
123
|
const absPaths = artifactPaths.map((p) => path.join(cwd, p));
|
|
74
124
|
for (const s of [cwd, ...absPaths]) {
|
|
75
125
|
if (s.includes("'") || /[\r\n]/.test(s)) return { ok: false, error: "cwd or artifact path contains a character the gate cannot quote (single quote or newline)" };
|
|
@@ -93,33 +143,53 @@ async function dispatchMacroJob(
|
|
|
93
143
|
}
|
|
94
144
|
|
|
95
145
|
const slug = `${kebabCase(macro.label, { maxLen: 30, fallback: 'macro' })}-build-${t.toString(36)}${Math.random().toString(36).slice(2, 5)}`;
|
|
96
|
-
let goal = extra ? `${
|
|
146
|
+
let goal = extra ? `${prompt}\n\nAdditional instructions: ${extra}` : prompt;
|
|
97
147
|
if (entryId) goal += `\n\nEntry id: ${entryId}. Save with ${entryKind === 'video' ? 'videoId' : 'pageId'} = ${entryId}.`;
|
|
148
|
+
if (stage === 'review') {
|
|
149
|
+
goal += `\n\nReview stage: save the review material for entry ${entryId} with one project_video_review_write call (images and short text), then end; do not build or save the video in this run.`;
|
|
150
|
+
}
|
|
98
151
|
|
|
152
|
+
const saveTool = stage === 'review' ? 'the project_video_review_write tool' : 'the save tool your persona names';
|
|
99
153
|
const input = {
|
|
100
|
-
title: `${macro.label}: background build`,
|
|
154
|
+
title: `${macro.label}: ${stage === 'review' ? 'review material' : 'background build'}`,
|
|
101
155
|
slug,
|
|
102
156
|
cwd,
|
|
103
157
|
agentType: macro.agentName,
|
|
104
158
|
tag: macro.tag,
|
|
105
|
-
deliverable: 'artifact',
|
|
106
|
-
artifactPaths,
|
|
107
|
-
files: artifactPaths,
|
|
108
159
|
estimateMinutes: macro.job.estimateMinutes,
|
|
109
160
|
macroId,
|
|
110
161
|
sourcePromptId: epicId,
|
|
111
162
|
disposition: 'new-head',
|
|
112
163
|
goal,
|
|
113
|
-
acceptanceCriteria: [
|
|
114
|
-
`${artifactPaths[0]} is written during this run by the save tool your persona names, never by hand.`,
|
|
115
|
-
'Nothing in the repository is committed. No commit is the expected result: once the gate is green, end with SCHEDULER_VERDICT: PASS, never FAIL for the missing commit.',
|
|
116
|
-
],
|
|
117
|
-
implementationNotes:
|
|
118
|
-
`Work as the ${macro.agentName} persona (your system prompt) end to end. This build was started from Project Home and no one is watching: never stop to ask. `
|
|
119
|
-
+ 'Build outside the repository (mktemp -d under ~/.cache). SM_PROJECT_ROOT is the project main checkout; the save tool writes there, so omit its cwd. '
|
|
120
|
-
+ 'This build is artifact-only (deliverable: artifact) and lands no commit by design: a green gate with no commit means SCHEDULER_VERDICT: PASS.',
|
|
121
164
|
gate: absPaths.map((p) => buildGate(p, t)),
|
|
122
165
|
};
|
|
166
|
+
if (repoPaths) {
|
|
167
|
+
Object.assign(input, {
|
|
168
|
+
files: repoPaths,
|
|
169
|
+
acceptanceCriteria: [
|
|
170
|
+
`${artifactPaths[0]} is written during this run by ${saveTool}, never by hand. That entry is saved by the save tool and is never committed.`,
|
|
171
|
+
`This run must commit its changes under ${repoPaths.join(', ')} (stage only those paths). With nothing to commit it fails like any PRD.`,
|
|
172
|
+
],
|
|
173
|
+
implementationNotes:
|
|
174
|
+
`Work as the ${macro.agentName} persona (your system prompt) end to end. This build was started from Project Home and no one is watching: never stop to ask. `
|
|
175
|
+
+ 'SM_PROJECT_ROOT is the project main checkout; the save tool writes there, so omit its cwd. '
|
|
176
|
+
+ `This build lands a commit: change files only under ${repoPaths.join(', ')}, commit them, and never commit the saved entry.`,
|
|
177
|
+
});
|
|
178
|
+
} else {
|
|
179
|
+
Object.assign(input, {
|
|
180
|
+
deliverable: 'artifact',
|
|
181
|
+
artifactPaths,
|
|
182
|
+
files: artifactPaths,
|
|
183
|
+
acceptanceCriteria: [
|
|
184
|
+
`${artifactPaths[0]} is written during this run by ${saveTool}, never by hand.`,
|
|
185
|
+
'Nothing in the repository is committed. No commit is the expected result: once the gate is green, end with SCHEDULER_VERDICT: PASS, never FAIL for the missing commit.',
|
|
186
|
+
],
|
|
187
|
+
implementationNotes:
|
|
188
|
+
`Work as the ${macro.agentName} persona (your system prompt) end to end. This build was started from Project Home and no one is watching: never stop to ask. `
|
|
189
|
+
+ 'Build outside the repository (mktemp -d under ~/.cache). SM_PROJECT_ROOT is the project main checkout; the save tool writes there, so omit its cwd. '
|
|
190
|
+
+ 'This build is artifact-only (deliverable: artifact) and lands no commit by design: a green gate with no commit means SCHEDULER_VERDICT: PASS.',
|
|
191
|
+
});
|
|
192
|
+
}
|
|
123
193
|
if (typeof effort === 'string' && PRD_EFFORT_LEVELS.includes(effort)) input.effort = effort;
|
|
124
194
|
|
|
125
195
|
let res;
|
|
@@ -129,7 +199,7 @@ async function dispatchMacroJob(
|
|
|
129
199
|
return { ok: false, error: `createPrd failed: ${e?.message ?? e}` };
|
|
130
200
|
}
|
|
131
201
|
if (!res || res.ok === false) return { ok: false, error: res?.error || 'createPrd failed' };
|
|
132
|
-
return { ok: true, slug, epicId };
|
|
202
|
+
return { ok: true, slug, epicId, entryId, stage };
|
|
133
203
|
}
|
|
134
204
|
|
|
135
205
|
module.exports = { dispatchMacroJob };
|
|
@@ -7,7 +7,18 @@
|
|
|
7
7
|
*
|
|
8
8
|
* deps: { schemas, validatePath, readActiveIndex, createPrd, loadJobs,
|
|
9
9
|
* archivePrd, appendResponseEventWithReason?, dispatchMacroJob?,
|
|
10
|
-
* macroJobStatuses?, readHistoryTail?, builtins?
|
|
10
|
+
* macroJobStatuses?, readHistoryTail?, builtins?, listMacros?
|
|
11
|
+
* (default macroLibrary.listMacros), videoReview? (default
|
|
12
|
+
* project-pages/videoReview.cjs), listReviews?,
|
|
13
|
+
* checkProjectVideoToolRunnable? (default projectVideoToolCheck.cjs) }
|
|
14
|
+
*
|
|
15
|
+
* runToolJob is the one dispatch path: macros:dispatch-job calls it without a
|
|
16
|
+
* review decision; the review-decision IPC calls it with one. After an ok
|
|
17
|
+
* dispatch of a project Video tool it records the entry's review dispatch
|
|
18
|
+
* (dispatch.json), so every tool entry links to its tool, run and inputs.
|
|
19
|
+
* Before dispatching a library 'project-video' tool with a job it runs
|
|
20
|
+
* checkProjectVideoToolRunnable; a refusal returns { ok: false, error } with
|
|
21
|
+
* no PRD written and the job-not-queued notice. Built-ins are never checked.
|
|
11
22
|
*
|
|
12
23
|
* When a dispatch returns ok:false for an Epic that exists in the cwd's
|
|
13
24
|
* active-index.json (and no build is already running for it — `activeSlug`),
|
|
@@ -22,6 +33,7 @@
|
|
|
22
33
|
const { dispatchMacroJob: realDispatch } = require('./macroJobDispatch.cjs');
|
|
23
34
|
const { macroJobStatuses: realStatuses } = require('./macroJobStatus.cjs');
|
|
24
35
|
const { BUILTIN_MACROS } = require('./builtinMacros.cjs');
|
|
36
|
+
const macroLibrary = require('./macroLibrary.cjs');
|
|
25
37
|
|
|
26
38
|
const JOB_NOT_QUEUED_NOTICE = 'job-not-queued';
|
|
27
39
|
|
|
@@ -29,68 +41,154 @@ function noticeText(label, error) {
|
|
|
29
41
|
return `${label} background build was not queued: ${error} — press it again in Project Home ▸ Tools to retry.`;
|
|
30
42
|
}
|
|
31
43
|
|
|
32
|
-
function
|
|
44
|
+
function defaultCheckRunnable() {
|
|
45
|
+
return require('./projectVideoToolCheck.cjs').checkProjectVideoToolRunnable;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function defaultVideoReview() {
|
|
49
|
+
return require('../project-pages/videoReview.cjs');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const findById = (list, id) => (Array.isArray(list) ? list : []).find((m) => m && m.id === id);
|
|
53
|
+
|
|
54
|
+
/** Built-in label first, then the library tool's label, then the id itself. */
|
|
55
|
+
async function appendNotice(deps, macros, cwd, macroId, epicId, error) {
|
|
56
|
+
if (typeof deps.appendResponseEventWithReason !== 'function') return;
|
|
57
|
+
try {
|
|
58
|
+
const macro = findById(deps.builtins || BUILTIN_MACROS, macroId) || findById(macros, macroId);
|
|
59
|
+
const label = (macro && macro.label) || macroId;
|
|
60
|
+
const res = await deps.appendResponseEventWithReason(
|
|
61
|
+
cwd, epicId, noticeText(label, error),
|
|
62
|
+
{ notice: JOB_NOT_QUEUED_NOTICE, allowInactive: true },
|
|
63
|
+
);
|
|
64
|
+
if (res && res.ok === false) console.warn('[macroJobIpc] job-not-queued notice not appended', epicId, res.reason);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.warn('[macroJobIpc] job-not-queued notice append failed', epicId, e?.message ?? e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function listLibraryMacros(deps) {
|
|
71
|
+
const list = typeof deps.listMacros === 'function' ? deps.listMacros : macroLibrary.listMacros;
|
|
72
|
+
const macros = await list();
|
|
73
|
+
return Array.isArray(macros) ? macros : [];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* runToolJob(deps, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review })
|
|
78
|
+
* `cwd` must already be validated. Returns dispatchMacroJob's result.
|
|
79
|
+
*/
|
|
80
|
+
async function runToolJob(deps = {}, { cwd, macroId, epicId, extraInstructions, inputValues, effort, review } = {}) {
|
|
33
81
|
const dispatch = deps.dispatchMacroJob || realDispatch;
|
|
34
|
-
const
|
|
35
|
-
const
|
|
82
|
+
const index = deps.readActiveIndex(cwd);
|
|
83
|
+
const sessions = index && index.sessions ? index.sessions : {};
|
|
84
|
+
const entry = Object.prototype.hasOwnProperty.call(sessions, epicId) ? sessions[epicId] : null;
|
|
85
|
+
const notActive = `epic ${epicId} is not an active session in this project`;
|
|
86
|
+
if (!entry) return { ok: false, error: notActive };
|
|
36
87
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{ notice: JOB_NOT_QUEUED_NOTICE, allowInactive: true },
|
|
45
|
-
);
|
|
46
|
-
if (res && res.ok === false) console.warn('[macroJobIpc] job-not-queued notice not appended', epicId, res.reason);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
console.warn('[macroJobIpc] job-not-queued notice append failed', epicId, e?.message ?? e);
|
|
88
|
+
let macros = [];
|
|
89
|
+
let result;
|
|
90
|
+
try {
|
|
91
|
+
macros = await listLibraryMacros(deps);
|
|
92
|
+
if (entry.status !== 'active') {
|
|
93
|
+
await appendNotice(deps, macros, cwd, macroId, epicId, notActive);
|
|
94
|
+
return { ok: false, error: notActive };
|
|
49
95
|
}
|
|
96
|
+
const refusal = await projectVideoRefusal(deps, macros, cwd, macroId);
|
|
97
|
+
if (refusal) {
|
|
98
|
+
await appendNotice(deps, macros, cwd, macroId, epicId, refusal);
|
|
99
|
+
return { ok: false, error: refusal };
|
|
100
|
+
}
|
|
101
|
+
const args = { cwd, macroId, epicId, extraInstructions, effort };
|
|
102
|
+
if (inputValues !== undefined) args.inputValues = inputValues;
|
|
103
|
+
if (review !== undefined) args.review = review;
|
|
104
|
+
const dispatchDeps = {
|
|
105
|
+
createPrd: deps.createPrd,
|
|
106
|
+
listRows: async () => deps.loadJobs(),
|
|
107
|
+
archivePrd: (slug, rowCwd) => deps.archivePrd(slug, rowCwd),
|
|
108
|
+
macros,
|
|
109
|
+
};
|
|
110
|
+
if (deps.builtins) dispatchDeps.builtins = deps.builtins;
|
|
111
|
+
result = await dispatch(args, dispatchDeps);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
await appendNotice(deps, macros, cwd, macroId, epicId, e?.message ?? String(e));
|
|
114
|
+
throw e;
|
|
115
|
+
}
|
|
116
|
+
if (result && result.ok === false && !result.activeSlug) {
|
|
117
|
+
await appendNotice(deps, macros, cwd, macroId, epicId, result.error || 'unknown error');
|
|
50
118
|
}
|
|
119
|
+
if (result && result.ok === true && result.entryId) {
|
|
120
|
+
const isBuiltin = !!findById(deps.builtins || BUILTIN_MACROS, macroId);
|
|
121
|
+
const tool = isBuiltin ? null : findById(macros, macroId);
|
|
122
|
+
if (tool && !tool.builtin && macroLibrary.isProjectVideoTool(tool, cwd)) {
|
|
123
|
+
await recordToolDispatch(deps, cwd, result, { macroId, epicId, inputValues, extraInstructions });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The runnable-check error for a library 'project-video' tool with a job, or
|
|
131
|
+
* null (built-ins, other macros and runnable tools).
|
|
132
|
+
*/
|
|
133
|
+
async function projectVideoRefusal(deps, macros, cwd, macroId) {
|
|
134
|
+
if (findById(deps.builtins || BUILTIN_MACROS, macroId)) return null;
|
|
135
|
+
const tool = findById(macros, macroId);
|
|
136
|
+
if (!tool || tool.builtin || tool.surface !== 'project-video' || !tool.job || typeof tool.job !== 'object') return null;
|
|
137
|
+
const check = deps.checkProjectVideoToolRunnable || defaultCheckRunnable();
|
|
138
|
+
const verdict = await check({ cwd, agentName: tool.agentName, job: tool.job });
|
|
139
|
+
return verdict && verdict.ok === false ? verdict.error : null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Best effort: a failed record is logged and never changes the dispatch result. */
|
|
143
|
+
async function recordToolDispatch(deps, cwd, result, { macroId, epicId, inputValues, extraInstructions }) {
|
|
144
|
+
try {
|
|
145
|
+
const videoReview = deps.videoReview || defaultVideoReview();
|
|
146
|
+
const rec = await videoReview.recordDispatch(cwd, result.entryId, {
|
|
147
|
+
macroId,
|
|
148
|
+
epicId,
|
|
149
|
+
slug: result.slug,
|
|
150
|
+
stage: result.stage || 'final',
|
|
151
|
+
inputValues: inputValues && typeof inputValues === 'object' ? inputValues : {},
|
|
152
|
+
extraInstructions: typeof extraInstructions === 'string' ? extraInstructions : '',
|
|
153
|
+
});
|
|
154
|
+
if (rec && rec.ok === false) console.warn('[macroJobIpc] review dispatch not recorded', result.entryId, rec.error);
|
|
155
|
+
} catch (e) {
|
|
156
|
+
console.warn('[macroJobIpc] review dispatch record failed', result.entryId, e?.message ?? e);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function registerMacroJobIpc(ipcMain, deps = {}) {
|
|
161
|
+
const statuses = deps.macroJobStatuses || realStatuses;
|
|
51
162
|
|
|
52
163
|
ipcMain.handle('macros:dispatch-job', async (_event, rawPayload) => {
|
|
53
164
|
const payload = deps.schemas.macrosDispatchJob.parse(rawPayload);
|
|
54
165
|
const cwd = deps.validatePath(payload.cwd);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await appendNotice(cwd, payload.macroId, payload.epicId, refused.error);
|
|
64
|
-
return refused;
|
|
65
|
-
}
|
|
66
|
-
let result;
|
|
67
|
-
try {
|
|
68
|
-
result = await dispatch(
|
|
69
|
-
{ cwd, macroId: payload.macroId, epicId: payload.epicId, extraInstructions: payload.extraInstructions, effort: payload.effort },
|
|
70
|
-
{
|
|
71
|
-
createPrd: deps.createPrd,
|
|
72
|
-
listRows: async () => deps.loadJobs(),
|
|
73
|
-
archivePrd: (slug, rowCwd) => deps.archivePrd(slug, rowCwd),
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
} catch (e) {
|
|
77
|
-
await appendNotice(cwd, payload.macroId, payload.epicId, e?.message ?? String(e));
|
|
78
|
-
throw e;
|
|
79
|
-
}
|
|
80
|
-
if (result && result.ok === false && !result.activeSlug) {
|
|
81
|
-
await appendNotice(cwd, payload.macroId, payload.epicId, result.error || 'unknown error');
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
166
|
+
return runToolJob(deps, {
|
|
167
|
+
cwd,
|
|
168
|
+
macroId: payload.macroId,
|
|
169
|
+
epicId: payload.epicId,
|
|
170
|
+
extraInstructions: payload.extraInstructions,
|
|
171
|
+
inputValues: payload.inputValues,
|
|
172
|
+
effort: payload.effort,
|
|
173
|
+
});
|
|
84
174
|
});
|
|
85
175
|
|
|
86
176
|
ipcMain.handle('macros:job-status', async (_event, rawPayload) => {
|
|
87
177
|
const payload = deps.schemas.macrosJobStatus.parse(rawPayload);
|
|
88
178
|
const cwd = deps.validatePath(payload.cwd);
|
|
179
|
+
let macros = [];
|
|
180
|
+
try {
|
|
181
|
+
macros = await listLibraryMacros(deps);
|
|
182
|
+
} catch (e) {
|
|
183
|
+
console.warn('[macroJobIpc] macro library unreadable for job-status', e?.message ?? e);
|
|
184
|
+
}
|
|
89
185
|
return statuses({ cwd }, {
|
|
90
186
|
loadJobs: deps.loadJobs,
|
|
187
|
+
macros,
|
|
91
188
|
...(deps.readHistoryTail ? { readHistoryTail: deps.readHistoryTail } : {}),
|
|
189
|
+
...(deps.listReviews ? { listReviews: deps.listReviews } : {}),
|
|
92
190
|
});
|
|
93
191
|
});
|
|
94
192
|
}
|
|
95
193
|
|
|
96
|
-
module.exports = { registerMacroJobIpc, JOB_NOT_QUEUED_NOTICE };
|
|
194
|
+
module.exports = { registerMacroJobIpc, runToolJob, JOB_NOT_QUEUED_NOTICE };
|