claude-code-session-manager 0.138.0 → 0.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +352 -79
- package/dist/assets/AppSettings-CMFEM68R.js +2 -0
- package/dist/assets/History--JwsFnbn.js +2 -0
- package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
- package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
- package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
- package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
- package/dist/assets/Skills-DtRzghn5.js +67 -0
- package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
- package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
- package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
- package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
- package/dist/assets/index-CtxruO1L.js +3121 -0
- package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +467 -451
- package/package.json +17 -6
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
- package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
- 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 +2 -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 +360 -35
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +2 -2
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/exchanges.cjs +70 -5
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +172 -63
- package/src/main/historyDashboard.cjs +87 -17
- package/src/main/index.cjs +78 -4
- package/src/main/ipcSchemas.cjs +233 -20
- 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 +92 -22
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/modelPricing.cjs +148 -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 +121 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
- package/src/main/lib/epic/epicOutsideState.cjs +233 -0
- package/src/main/lib/epic/epicSettle.cjs +1 -1
- package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +137 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
- package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
- package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
- 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 +58 -5
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +232 -25
- 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/agentAdminRoutes.cjs +121 -0
- 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 +351 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +96 -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/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- 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/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/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 +12 -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/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +11 -2
- 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 +4 -1
- package/src/main/scheduler/starvation.cjs +20 -18
- package/src/main/scheduler.cjs +774 -64
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +7 -1
- package/src/main/transcripts.cjs +62 -7
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +132 -20
- package/src/preload/api.d.ts +434 -28
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +485 -81
- package/src/preload/index.cjs +38 -5
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
- package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
- package/dist/assets/Button-Bk23rEnZ.js +0 -1
- package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
- package/dist/assets/Extensions-CXem-uwI.js +0 -2
- package/dist/assets/History-BwO3coo4.js +0 -2
- package/dist/assets/Library-BDV69fSe.js +0 -32
- package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
- package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
- package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
- package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
- package/dist/assets/Settings-COT34hBF.js +0 -2
- package/dist/assets/Skills-BgexoUkQ.js +0 -29
- package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
- package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
- package/dist/assets/Toggle-CENi19iK.js +0 -1
- package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-CgCxpunJ.js +0 -3116
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* the scheduler MCP) can list, create/update and delete a HOT KEYS macro
|
|
4
4
|
* for its own project, through the existing macroLibrary.cjs store:
|
|
5
5
|
* GET /admin/macros?cwd=… -> { ok, macros }
|
|
6
|
-
* POST /admin/macros/save {cwd, id?, label, agentName, tag, prompt, inputs?}
|
|
6
|
+
* POST /admin/macros/save {cwd, id?, label, agentName, tag, prompt, inputs?, surface?, job?}
|
|
7
7
|
* POST /admin/macros/delete {cwd, id, originClaudeSessionId?}
|
|
8
8
|
* -> { ok, deleted, macro }
|
|
9
9
|
* delete removes the macro from THIS project through
|
|
@@ -29,12 +29,23 @@
|
|
|
29
29
|
* human typed into body.originClaudeSessionId (humanPromptLedger) AND name
|
|
30
30
|
* every/all projects (or, for a 'project-home' macro, Project Home). Otherwise 400, no write, no onChanged, no audit.
|
|
31
31
|
*
|
|
32
|
+
* A save whose resulting surface is 'project-video' (one project's own Video
|
|
33
|
+
* tool, Project Home ▸ Video) may carry `job` (forwarded to saveMacro), always
|
|
34
|
+
* needs the same verified quote as a 'project-home' save, and ignores a
|
|
35
|
+
* caller's `projects`: a create stores [resolvedCwd], an update keeps the
|
|
36
|
+
* stored projects, so the library refuses a '*' or multi-project macro.
|
|
37
|
+
*
|
|
38
|
+
* Before the write, a save whose resulting macro is surface 'project-video'
|
|
39
|
+
* with a job (the sent job, or the stored one an update keeps) runs
|
|
40
|
+
* projectVideoToolCheck's checkProjectVideoToolRunnable (deps-injectable) for
|
|
41
|
+
* the resolved cwd and persona; a refusal is a 400 with the helper's error.
|
|
42
|
+
*
|
|
32
43
|
* Every successful save appends one `admin_macro_save` audit event and calls
|
|
33
44
|
* `onChanged()` exactly once so the Sessions HOT KEYS strip updates live,
|
|
34
45
|
* matching the IPC handlers in index.cjs.
|
|
35
46
|
*
|
|
36
|
-
* POST /admin/macros/run {cwd, id, inputs?, effort?}
|
|
37
|
-
* -> { ok, epicId, alreadyRunning }
|
|
47
|
+
* POST /admin/macros/run {cwd, id, inputs?, effort?, externalRef?}
|
|
48
|
+
* -> { ok, epicId, alreadyRunning, externalRef? }
|
|
38
49
|
* Starts a saved macro from a script (e.g. a systemd timer) through the
|
|
39
50
|
* renderer's press path (deps.startExternalNewSession: same persona, tag, AIM
|
|
40
51
|
* prompt and source.macroId, so autoStartTargets apply). Refused (400, no
|
|
@@ -43,6 +54,10 @@
|
|
|
43
54
|
* = the macro's defaults overlaid by `inputs`. While that macro's Epic is
|
|
44
55
|
* still running in the cwd it returns that Epic (alreadyRunning:true) instead
|
|
45
56
|
* of a second start. A launch failure is a 503 with no audit event.
|
|
57
|
+
* externalRef (normalizeExternalRef; invalid = 400), e.g. a date, starts the
|
|
58
|
+
* macro at most once per ref: it rides in the payload, is recorded in
|
|
59
|
+
* externalRefIndex and audited; a repeat with the same cwd + ref answers
|
|
60
|
+
* { existing: true } with that Epic (409 if another producer/macro owns the ref).
|
|
46
61
|
* curl -s -X POST "http://127.0.0.1:$(jq -r .port ~/.claude/session-manager/admin-api.json)/admin/macros/run" -H "Authorization: Bearer $(jq -r .token ~/.claude/session-manager/admin-api.json)" -H 'Content-Type: application/json' -d '{"cwd":"/abs/project","id":"<macro-id>"}'
|
|
47
62
|
*/
|
|
48
63
|
'use strict';
|
|
@@ -54,6 +69,8 @@ const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
|
54
69
|
const { findHumanPromptContaining } = require('./humanPromptLedger.cjs');
|
|
55
70
|
const { readActiveIndex } = require('../epic/epicMint.cjs');
|
|
56
71
|
const { PRD_EFFORT_LEVELS } = require('../prd/prdFrontmatter.cjs');
|
|
72
|
+
const { normalizeExternalRef } = require('../epic/externalRef.cjs');
|
|
73
|
+
const { findEpicByExternalRef, recordExternalRef, withExternalRefLock } = require('../epic/externalRefIndex.cjs');
|
|
57
74
|
|
|
58
75
|
const EVERY_PROJECT_RE = /(^|[^a-z0-9])(every|all|each)\s+(of\s+)?(my\s+|the\s+|our\s+)?projects?($|[^a-z0-9])/;
|
|
59
76
|
|
|
@@ -73,20 +90,23 @@ function quoteNamesProjectHome(quote) {
|
|
|
73
90
|
return PROJECT_HOME_RE.test(q);
|
|
74
91
|
}
|
|
75
92
|
|
|
93
|
+
const PROJECT_VIDEO_HINT =
|
|
94
|
+
"a Project Video tool (Project Home ▸ Video, this project only) needs humanRequestQuote (the human's words naming Project Home); the human can add one from Project Home ▸ Video";
|
|
76
95
|
const HUMAN_HINT = "the human can set 'Show in every project' in the macro editor";
|
|
77
96
|
const PROJECT_HOME_HINT =
|
|
78
97
|
"a Project Home tool is shown in every project's Project Home, so it needs humanRequestQuote (the human's words asking for a Project Home tool); the human can add one from Project Home ▸ Tools ▸ Add a tool";
|
|
79
98
|
|
|
80
|
-
/** Fail-closed check that a human asked for an all-projects macro (or a Project Home tool). */
|
|
81
|
-
function verifyAllProjectsRequest(body, { projectHome = false } = {}) {
|
|
82
|
-
const hint = projectHome ? PROJECT_HOME_HINT : HUMAN_HINT;
|
|
99
|
+
/** Fail-closed check that a human asked for an all-projects macro (or a Project Home / Project Video tool). */
|
|
100
|
+
function verifyAllProjectsRequest(body, { projectHome = false, projectVideo = false } = {}) {
|
|
101
|
+
const hint = projectVideo ? PROJECT_VIDEO_HINT : projectHome ? PROJECT_HOME_HINT : HUMAN_HINT;
|
|
102
|
+
const what = projectVideo ? 'a Project Video tool' : 'a macro shown in every project';
|
|
83
103
|
const quote = body.humanRequestQuote;
|
|
84
104
|
if (typeof quote !== 'string' || !quote.trim()) {
|
|
85
|
-
return { ok: false, reason:
|
|
105
|
+
return { ok: false, reason: `${what} needs humanRequestQuote (a verbatim human request); ${hint}` };
|
|
86
106
|
}
|
|
87
107
|
const origin = body.originClaudeSessionId;
|
|
88
108
|
if (typeof origin !== 'string' || origin.length < 1 || origin.length > 128) {
|
|
89
|
-
return { ok: false, reason:
|
|
109
|
+
return { ok: false, reason: `${what} needs originClaudeSessionId (1-128 chars); ${hint}` };
|
|
90
110
|
}
|
|
91
111
|
if (!findHumanPromptContaining(origin, quote)) {
|
|
92
112
|
return { ok: false, reason: `humanRequestQuote was not found in a prompt the human typed in this session; ${hint}` };
|
|
@@ -136,7 +156,7 @@ function listHandler(onChanged, libOpts) {
|
|
|
136
156
|
};
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
function saveHandler(onChanged, libOpts) {
|
|
159
|
+
function saveHandler(onChanged, libOpts, deps = {}) {
|
|
140
160
|
return async (req, res) => {
|
|
141
161
|
const body = await readJsonBody(req, res);
|
|
142
162
|
if (!body) return;
|
|
@@ -149,12 +169,6 @@ function saveHandler(onChanged, libOpts) {
|
|
|
149
169
|
sendJson(res, 400, { ok: false, error: 'built-in macros cannot be edited through this route' });
|
|
150
170
|
return;
|
|
151
171
|
}
|
|
152
|
-
const p = body.projects;
|
|
153
|
-
if (p !== undefined && !(Array.isArray(p) && p.length === 1 && p[0] === macroLibrary.ALL_PROJECTS)) {
|
|
154
|
-
sendJson(res, 400, { ok: false, error: 'projects: only ["*"] is accepted; omit it to use the current project' });
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const wantsAll = p !== undefined;
|
|
158
172
|
let input;
|
|
159
173
|
try {
|
|
160
174
|
input = macroLibrary.MacroSaveSchema.parse({
|
|
@@ -165,6 +179,7 @@ function saveHandler(onChanged, libOpts) {
|
|
|
165
179
|
prompt: body.prompt,
|
|
166
180
|
inputs: body.inputs,
|
|
167
181
|
surface: body.surface,
|
|
182
|
+
job: body.job,
|
|
168
183
|
});
|
|
169
184
|
} catch (e) {
|
|
170
185
|
sendJson(res, 400, { ok: false, error: e?.issues?.[0]?.message ?? e?.message ?? 'invalid payload' });
|
|
@@ -185,10 +200,18 @@ function saveHandler(onChanged, libOpts) {
|
|
|
185
200
|
}
|
|
186
201
|
const resultSurface = input.surface ?? existing?.surface ?? 'sessions';
|
|
187
202
|
const projectHome = resultSurface === 'project-home';
|
|
203
|
+
// A Project Video tool belongs to the resolved project only: a caller's `projects` is ignored.
|
|
204
|
+
const projectVideo = resultSurface === 'project-video';
|
|
205
|
+
const p = projectVideo ? undefined : body.projects;
|
|
206
|
+
if (p !== undefined && !(Array.isArray(p) && p.length === 1 && p[0] === macroLibrary.ALL_PROJECTS)) {
|
|
207
|
+
sendJson(res, 400, { ok: false, error: 'projects: only ["*"] is accepted; omit it to use the current project' });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const wantsAll = p !== undefined;
|
|
188
211
|
const allProjects = Boolean(existing?.projects.includes(macroLibrary.ALL_PROJECTS)) || wantsAll || projectHome;
|
|
189
212
|
let quote = null;
|
|
190
|
-
if (allProjects) {
|
|
191
|
-
const v = verifyAllProjectsRequest(body, { projectHome });
|
|
213
|
+
if (allProjects || projectVideo) {
|
|
214
|
+
const v = verifyAllProjectsRequest(body, { projectHome: projectHome || projectVideo, projectVideo });
|
|
192
215
|
if (!v.ok) {
|
|
193
216
|
sendJson(res, 400, { ok: false, error: v.reason });
|
|
194
217
|
return;
|
|
@@ -198,12 +221,22 @@ function saveHandler(onChanged, libOpts) {
|
|
|
198
221
|
if (!input.id) {
|
|
199
222
|
input = {
|
|
200
223
|
...input,
|
|
201
|
-
projects: wantsAll || projectHome ? [macroLibrary.ALL_PROJECTS] : [resolved.cwd],
|
|
224
|
+
projects: (wantsAll || projectHome) && !projectVideo ? [macroLibrary.ALL_PROJECTS] : [resolved.cwd],
|
|
202
225
|
surface: input.surface ?? 'sessions',
|
|
203
226
|
};
|
|
204
|
-
} else if (wantsAll || projectHome) {
|
|
227
|
+
} else if ((wantsAll || projectHome) && !projectVideo) {
|
|
205
228
|
input = { ...input, projects: [macroLibrary.ALL_PROJECTS] };
|
|
206
229
|
}
|
|
230
|
+
const resultJob = input.job !== undefined ? input.job : existing?.job;
|
|
231
|
+
if (projectVideo && resultJob && typeof resultJob === 'object') {
|
|
232
|
+
const check = deps.checkProjectVideoToolRunnable
|
|
233
|
+
|| require('../persona-macro/projectVideoToolCheck.cjs').checkProjectVideoToolRunnable;
|
|
234
|
+
const verdict = await check({ cwd: resolved.cwd, agentName: input.agentName ?? existing?.agentName, job: resultJob });
|
|
235
|
+
if (!verdict || verdict.ok === false) {
|
|
236
|
+
sendJson(res, 400, { ok: false, error: verdict?.error ?? 'project-video tool check failed' });
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
207
240
|
let macro;
|
|
208
241
|
try {
|
|
209
242
|
macro = await macroLibrary.saveMacro(input, libOpts);
|
|
@@ -344,12 +377,19 @@ function runHandler(deps, libOpts) {
|
|
|
344
377
|
if (effort !== undefined && !PRD_EFFORT_LEVELS.includes(effort)) {
|
|
345
378
|
return bad(`effort must be one of: ${PRD_EFFORT_LEVELS.join(', ')}`);
|
|
346
379
|
}
|
|
380
|
+
const ref = normalizeExternalRef(body.externalRef);
|
|
381
|
+
if (!ref.ok) return bad(ref.error);
|
|
347
382
|
const rendered = macroLibrary.renderMacroPrompt(macro.prompt, macro.inputs, {
|
|
348
383
|
...macroLibrary.defaultMacroValues(macro.inputs),
|
|
349
384
|
...(body.inputs || {}),
|
|
350
385
|
});
|
|
351
386
|
if (!rendered.ok) return bad(rendered.error);
|
|
352
387
|
|
|
388
|
+
if (ref.value !== undefined) {
|
|
389
|
+
await runWithExternalRef({ deps, res, cwd, macro, prompt: rendered.prompt, effort, externalRef: ref.value });
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
|
|
353
393
|
const key = `${cwd}\u0000${id}`;
|
|
354
394
|
const pending = inProgressRuns.get(key);
|
|
355
395
|
if (pending) {
|
|
@@ -410,15 +450,121 @@ function runHandler(deps, libOpts) {
|
|
|
410
450
|
};
|
|
411
451
|
}
|
|
412
452
|
|
|
453
|
+
/** 503 error text for a failed startExternalNewSession result. */
|
|
454
|
+
function launchFailureError(result) {
|
|
455
|
+
return result?.reason === 'timeout'
|
|
456
|
+
? 'timed out waiting for the window; the session may still start, check the Sessions queue before retrying'
|
|
457
|
+
: result?.error || 'launch failed';
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* The externalRef branch of /admin/macros/run. The lookup, launch and record
|
|
462
|
+
* run inside withExternalRefLock, so concurrent calls with the same
|
|
463
|
+
* (cwd, externalRef) share one launch. The macro-wide findRunningEpic shortcut
|
|
464
|
+
* is skipped: a new ref is a new run even while another run is busy.
|
|
465
|
+
*/
|
|
466
|
+
async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, externalRef }) {
|
|
467
|
+
const isTabBusy = deps.isTabBusy || (() => false);
|
|
468
|
+
const existingAnswer = (epicId) => sendJson(res, 200, {
|
|
469
|
+
ok: true, epicId, existing: true, alreadyRunning: !!isTabBusy(epicId), externalRef,
|
|
470
|
+
});
|
|
471
|
+
await withExternalRefLock({ cwd, externalRef }, async () => {
|
|
472
|
+
const key = `${cwd}\u0000${macro.id}\u0000${externalRef}`;
|
|
473
|
+
const pending = inProgressRuns.get(key);
|
|
474
|
+
if (pending) {
|
|
475
|
+
const first = await pending;
|
|
476
|
+
if (first.ok) existingAnswer(first.epicId);
|
|
477
|
+
else sendJson(res, 503, { ok: false, error: first.error || 'launch failed' });
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
const found = await findEpicByExternalRef({ cwd, externalRef });
|
|
481
|
+
if (found) {
|
|
482
|
+
if (found.producer !== 'new-epic-ui' || found.macroId !== macro.id) {
|
|
483
|
+
sendJson(res, 409, {
|
|
484
|
+
ok: false,
|
|
485
|
+
error: `externalRef ${externalRef} already names Epic ${found.epicId}, started by ${found.producer || 'an unknown producer'}${found.macroId ? ` for macro ${found.macroId}` : ''}, not by macro ${macro.id}`,
|
|
486
|
+
epicId: found.epicId,
|
|
487
|
+
externalRef,
|
|
488
|
+
});
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
existingAnswer(found.epicId);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const recent = recentRuns.get(key);
|
|
495
|
+
if (recent && Date.now() - recent.at < RECENT_START_MS) {
|
|
496
|
+
existingAnswer(recent.epicId);
|
|
497
|
+
return;
|
|
498
|
+
} else if (recent) {
|
|
499
|
+
recentRuns.delete(key);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const payload = {
|
|
503
|
+
cwd,
|
|
504
|
+
agentName: macro.agentName,
|
|
505
|
+
tag: macro.tag,
|
|
506
|
+
title: macro.label,
|
|
507
|
+
prompt,
|
|
508
|
+
macroId: macro.id,
|
|
509
|
+
via: 'script',
|
|
510
|
+
externalRef,
|
|
511
|
+
...(effort !== undefined ? { effort } : {}),
|
|
512
|
+
};
|
|
513
|
+
const launch = (async () => {
|
|
514
|
+
try {
|
|
515
|
+
return await deps.startExternalNewSession(payload);
|
|
516
|
+
} catch (e) {
|
|
517
|
+
return { ok: false, reason: 'launch-failed', error: e?.message ?? 'launch failed' };
|
|
518
|
+
}
|
|
519
|
+
})();
|
|
520
|
+
inProgressRuns.set(key, launch);
|
|
521
|
+
let result;
|
|
522
|
+
try {
|
|
523
|
+
result = await launch;
|
|
524
|
+
if (result && result.ok) recentRuns.set(key, { epicId: result.epicId, at: Date.now() });
|
|
525
|
+
} finally {
|
|
526
|
+
inProgressRuns.delete(key);
|
|
527
|
+
}
|
|
528
|
+
if (!result || !result.ok) {
|
|
529
|
+
sendJson(res, 503, { ok: false, error: launchFailureError(result) });
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
// The session already started; a failed write is retried once, then
|
|
533
|
+
// reported as externalRefRecorded: false (the open-session scan in
|
|
534
|
+
// findEpicByExternalRef still finds it while it is open).
|
|
535
|
+
// Required lazily: crossProjectFeedback.cjs is a heavy module this file
|
|
536
|
+
// otherwise never loads.
|
|
537
|
+
const { recordExternalRefWithRetry } = require('./crossProjectFeedback.cjs');
|
|
538
|
+
const recorded = await recordExternalRefWithRetry(
|
|
539
|
+
deps.recordExternalRef || recordExternalRef,
|
|
540
|
+
{ cwd, externalRef, epicId: result.epicId, producer: 'new-epic-ui', macroId: macro.id },
|
|
541
|
+
'[macroAdminRoutes]',
|
|
542
|
+
);
|
|
543
|
+
appendAuditEvent('admin_macro_run', {
|
|
544
|
+
route: '/admin/macros/run',
|
|
545
|
+
cwd,
|
|
546
|
+
macroId: macro.id,
|
|
547
|
+
epicId: result.epicId,
|
|
548
|
+
alreadyRunning: false,
|
|
549
|
+
externalRef,
|
|
550
|
+
});
|
|
551
|
+
sendJson(res, 200, {
|
|
552
|
+
ok: true, epicId: result.epicId, alreadyRunning: false, externalRef,
|
|
553
|
+
...(recorded ? {} : { externalRefRecorded: false }),
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
413
558
|
/**
|
|
414
559
|
* @param {{ onChanged?: () => void, startExternalNewSession?: (p: object) => Promise<any>,
|
|
415
|
-
* isTabBusy?: (tabId: string) => boolean, listPersonas?: () => Promise<Array<{name: string}
|
|
560
|
+
* isTabBusy?: (tabId: string) => boolean, listPersonas?: () => Promise<Array<{name: string}>>,
|
|
561
|
+
* checkProjectVideoToolRunnable?: (i: { cwd: string, agentName: string, job: object }) => Promise<{ ok: boolean, error?: string }> }} deps
|
|
416
562
|
*/
|
|
417
563
|
function registerAdminRoute(adminHttp, deps = {}, opts = {}) {
|
|
418
564
|
const { onChanged } = deps;
|
|
419
565
|
const libOpts = opts.filePath ? { filePath: opts.filePath } : undefined;
|
|
420
566
|
adminHttp.registerRoute('GET', '/admin/macros', listHandler(onChanged, libOpts));
|
|
421
|
-
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts));
|
|
567
|
+
adminHttp.registerRoute('POST', '/admin/macros/save', saveHandler(onChanged, libOpts, deps));
|
|
422
568
|
adminHttp.registerRoute('POST', '/admin/macros/delete', deleteHandler(onChanged, libOpts));
|
|
423
569
|
if (typeof deps.startExternalNewSession === 'function') {
|
|
424
570
|
adminHttp.registerRoute('POST', '/admin/macros/run', runHandler(deps, libOpts));
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* needsYouAdminRoutes.cjs — loopback admin HTTP routes so an outside app on
|
|
5
|
+
* this machine can put a "Needs you" item in front of the owner, take it back,
|
|
6
|
+
* and list its items, through needsYouStore.cjs:
|
|
7
|
+
* POST /admin/needs-you {app, id, title, why?, link?, options?, externalRef?}
|
|
8
|
+
* -> 200 { ok, item, created, changed } | 400 | 429 (item limit)
|
|
9
|
+
* POST /admin/needs-you/withdraw {app, id} -> 200 { ok, item } | 404 { ok:false, error:'not found' }
|
|
10
|
+
* GET /admin/needs-you?app=&status= -> 200 { ok, items }
|
|
11
|
+
*
|
|
12
|
+
* A post the store reports as `changed` (decided inside its write queue)
|
|
13
|
+
* appends one `needs_you_posted` audit row and calls deps.onChanged once; a
|
|
14
|
+
* post that changed nothing (an identical re-post, or an item already
|
|
15
|
+
* answered/withdrawn) writes no row and does not call it. A withdrawal
|
|
16
|
+
* appends `needs_you_withdrawn` and calls onChanged once.
|
|
17
|
+
* Answering is the human's, in the app — no route here.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
21
|
+
const needsYouStore = require('./needsYouStore.cjs');
|
|
22
|
+
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
23
|
+
|
|
24
|
+
const STATUSES = ['open', 'answered', 'withdrawn'];
|
|
25
|
+
|
|
26
|
+
/** Read + parse a JSON object body; on failure sends the 400 and returns null. */
|
|
27
|
+
async function readJsonBody(req, res) {
|
|
28
|
+
let raw;
|
|
29
|
+
try {
|
|
30
|
+
raw = await readBody(req);
|
|
31
|
+
} catch (e) {
|
|
32
|
+
sendJson(res, 400, { ok: false, error: `request body rejected: ${e?.message ?? 'unreadable'}` });
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
let body;
|
|
36
|
+
try {
|
|
37
|
+
body = raw ? JSON.parse(raw) : {};
|
|
38
|
+
} catch {
|
|
39
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (body === null || typeof body !== 'object' || Array.isArray(body)) {
|
|
43
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return body;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstIssue(e, fallback) {
|
|
50
|
+
return e?.issues?.[0]?.message ?? e?.message ?? fallback;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function postHandler(onChanged) {
|
|
54
|
+
return async (req, res) => {
|
|
55
|
+
const body = await readJsonBody(req, res);
|
|
56
|
+
if (!body) return;
|
|
57
|
+
let result;
|
|
58
|
+
try {
|
|
59
|
+
result = await needsYouStore.postNeedsYou(body);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
if (e?.code === 'NEEDS_YOU_LIMIT') {
|
|
62
|
+
sendJson(res, 429, { ok: false, error: e.message });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (Array.isArray(e?.issues)) {
|
|
66
|
+
sendJson(res, 400, { ok: false, error: firstIssue(e, 'invalid payload') });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
sendJson(res, 500, { ok: false, error: e?.message ?? 'post failed' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const { item, created, changed } = result;
|
|
73
|
+
if (changed) {
|
|
74
|
+
appendAuditEvent('needs_you_posted', {
|
|
75
|
+
route: '/admin/needs-you',
|
|
76
|
+
app: item.app,
|
|
77
|
+
id: item.id,
|
|
78
|
+
externalRef: item.externalRef,
|
|
79
|
+
created,
|
|
80
|
+
});
|
|
81
|
+
if (onChanged) onChanged();
|
|
82
|
+
}
|
|
83
|
+
sendJson(res, 200, { ok: true, item, created, changed });
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function withdrawHandler(onChanged) {
|
|
88
|
+
return async (req, res) => {
|
|
89
|
+
const body = await readJsonBody(req, res);
|
|
90
|
+
if (!body) return;
|
|
91
|
+
let item;
|
|
92
|
+
try {
|
|
93
|
+
item = await needsYouStore.withdrawNeedsYou({ app: body.app, id: body.id });
|
|
94
|
+
} catch (e) {
|
|
95
|
+
if (Array.isArray(e?.issues)) {
|
|
96
|
+
sendJson(res, 400, { ok: false, error: firstIssue(e, 'invalid payload') });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
sendJson(res, 500, { ok: false, error: e?.message ?? 'withdraw failed' });
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!item) {
|
|
103
|
+
sendJson(res, 404, { ok: false, error: 'not found' });
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
appendAuditEvent('needs_you_withdrawn', { route: '/admin/needs-you/withdraw', app: item.app, id: item.id });
|
|
107
|
+
if (onChanged) onChanged();
|
|
108
|
+
sendJson(res, 200, { ok: true, item });
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function listHandler() {
|
|
113
|
+
return async (_req, res, query) => {
|
|
114
|
+
const app = query.get('app') || undefined;
|
|
115
|
+
const status = query.get('status') || undefined;
|
|
116
|
+
if (status !== undefined && !STATUSES.includes(status)) {
|
|
117
|
+
sendJson(res, 400, { ok: false, error: `status must be one of ${STATUSES.join(', ')}` });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const items = await needsYouStore.listNeedsYou({ app, status });
|
|
121
|
+
sendJson(res, 200, { ok: true, items });
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** @param {{ onChanged?: () => void }} deps */
|
|
126
|
+
function registerAdminRoute(adminHttp, deps = {}) {
|
|
127
|
+
const { onChanged } = deps;
|
|
128
|
+
adminHttp.registerRoute('GET', '/admin/needs-you', listHandler());
|
|
129
|
+
adminHttp.registerRoute('POST', '/admin/needs-you', postHandler(onChanged));
|
|
130
|
+
adminHttp.registerRoute('POST', '/admin/needs-you/withdraw', withdrawHandler(onChanged));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
module.exports = { registerAdminRoute };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* needsYouIpc.cjs — renderer-facing IPC for the Dashboard's "Needs you" list,
|
|
6
|
+
* over needsYouStore.cjs:
|
|
7
|
+
* needsYou:list (no payload) -> { ok: true, items } (open items only)
|
|
8
|
+
* needsYou:answer { app, id, answer } -> { ok: true, item } | { ok: false, error }
|
|
9
|
+
*
|
|
10
|
+
* A successful answer appends one `needs_you_answered` audit row (app, id,
|
|
11
|
+
* answer, and the item's externalRef when it has one) so the outside app that
|
|
12
|
+
* posted the item can read the decision, then calls onChanged once. When the
|
|
13
|
+
* store refuses (no open item, or the answer is not one of its options) the
|
|
14
|
+
* handler returns an error in words and writes nothing.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const needsYouStore = require('./needsYouStore.cjs');
|
|
18
|
+
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{ ipcMain?: any, onChanged?: () => void }} [deps]
|
|
22
|
+
*/
|
|
23
|
+
function registerNeedsYouIpc(deps = {}) {
|
|
24
|
+
const ipcMain = deps.ipcMain || require('electron').ipcMain;
|
|
25
|
+
const { onChanged } = deps;
|
|
26
|
+
const { schemas: s, validated: v } = require('../../ipcSchemas.cjs');
|
|
27
|
+
|
|
28
|
+
ipcMain.handle('needsYou:list', v(s.needsYouList, async () => {
|
|
29
|
+
const items = await needsYouStore.listNeedsYou({ status: 'open' });
|
|
30
|
+
return { ok: true, items };
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
ipcMain.handle('needsYou:answer', v(s.needsYouAnswer, async ({ app, id, answer }) => {
|
|
34
|
+
const item = await needsYouStore.answerNeedsYou({ app, id, answer });
|
|
35
|
+
if (!item) {
|
|
36
|
+
return {
|
|
37
|
+
ok: false,
|
|
38
|
+
error: `There is no open question "${id}" from ${app} with the option "${answer}". It may already be answered or withdrawn.`,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/** @type {Record<string, unknown>} */
|
|
42
|
+
const row = { app: item.app, id: item.id, answer: item.answer };
|
|
43
|
+
if (item.externalRef) row.externalRef = item.externalRef;
|
|
44
|
+
appendAuditEvent('needs_you_answered', row);
|
|
45
|
+
if (onChanged) onChanged();
|
|
46
|
+
return { ok: true, item };
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = { registerNeedsYouIpc };
|