claude-code-session-manager 0.143.0 → 0.145.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-BR5b6oof.js +2 -0
- package/dist/assets/{History-DTttbvPb.js → History-B4U0mCdK.js} +2 -2
- package/dist/assets/HomeClaudeConfig-DQqG7lFE.js +5 -0
- package/dist/assets/{Panel-B_D4Bg7L.js → Panel-CwsOJ0nI.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-BzRowu8x.js +26 -0
- package/dist/assets/Scheduler-dr7CNOcL.js +16 -0
- package/dist/assets/{SkillReferenceGraph-D1b2aiol.js → SkillReferenceGraph-CroBPY4C.js} +1 -1
- package/dist/assets/{Skills-cfV7sgk6.js → Skills-BiW2lCnD.js} +23 -23
- package/dist/assets/{TiptapBody-DVXtEIVy.js → TiptapBody-CYTkQiva.js} +27 -27
- package/dist/assets/{Toggle-CYajnSdx.js → Toggle-WFBYo8JI.js} +1 -1
- package/dist/assets/{VoiceButton-DJ4gGRuE.js → VoiceButton-DZu8dTpO.js} +1 -1
- package/dist/assets/{historyTotals-D3MoHY2U.js → historyTotals-B7KeXLSE.js} +1 -1
- package/dist/assets/{index-DVHIHoJf.css → index-BJ5TJvmz.css} +1 -1
- package/dist/assets/{index-CdTppjKR.js → index-hXRNm0UJ.js} +698 -697
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +442 -439
- package/package.json +4 -2
- package/plugins/session-manager-dev/skills/develop/SKILL.md +25 -19
- 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 +91 -0
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +9 -6
- 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 +139 -0
- package/src/main/config.cjs +12 -0
- package/src/main/health.cjs +59 -17
- package/src/main/index.cjs +6 -2
- package/src/main/ipcSchemas.cjs +55 -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 +100 -14
- package/src/main/lib/demo-video-kit/resumableRun.cjs +21 -14
- package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
- package/src/main/lib/epic/epicDepsSync.cjs +66 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +74 -2
- 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 +125 -0
- package/src/main/lib/epic/restorableSessions.cjs +1 -0
- package/src/main/lib/epic/scriptStartedBy.cjs +86 -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 +108 -14
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +5 -1
- 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 +35 -4
- 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 +95 -7
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +104 -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 +47 -7
- package/src/main/lib/mcpToolsProbe.cjs +19 -2
- package/src/main/lib/opsOwnership.cjs +2 -0
- 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 +49 -5
- package/src/main/lib/prd/prdFrontmatter.cjs +5 -2
- package/src/main/lib/prd/prdMcpReachWarnings.cjs +46 -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 +150 -0
- package/src/main/lib/scheduler/reviewNotice.cjs +3 -1
- 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 +118 -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 +298 -0
- package/src/main/projectPages.cjs +22 -14
- package/src/main/pty.cjs +3 -0
- package/src/main/runVerify.cjs +80 -5
- package/src/main/scheduler/gitTreeGuard.cjs +6 -0
- package/src/main/scheduler/planReviewHold.cjs +146 -0
- package/src/main/scheduler/prdParser.cjs +1 -0
- package/src/main/scheduler/prdPaths.cjs +10 -1
- package/src/main/scheduler/reviewLadder.cjs +2 -0
- package/src/main/scheduler/utilizationHold.cjs +7 -2
- package/src/main/scheduler.cjs +692 -86
- package/src/main/seedAgentPersonas.cjs +11 -6
- package/src/main/seedStatus.cjs +1 -1
- package/src/main/templates/PRD_AUTHORING.md +17 -2
- package/src/main/webRemote.cjs +69 -7
- package/src/preload/api.d.ts +79 -1
- package/src/preload/apiSurface.json +39 -0
- package/src/preload/index.cjs +11 -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
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* createdProjects.cjs — store of every project folder the project_create tool
|
|
6
|
+
* created. Pure Node — no Electron — importable in unit tests.
|
|
7
|
+
*
|
|
8
|
+
* File (default ~/.claude/session-manager/created-projects.json, mode 0600,
|
|
9
|
+
* override SM_CREATED_PROJECTS_FILE):
|
|
10
|
+
* { version: 1, projects: [{ cwd, fromCwd, externalRef, repo, createdAt }] }
|
|
11
|
+
*
|
|
12
|
+
* - A repeat project_create with the same (fromCwd, externalRef) answers with
|
|
13
|
+
* the same folder via findByRef.
|
|
14
|
+
* - The project list can include a folder before it has any Claude transcript
|
|
15
|
+
* via list().
|
|
16
|
+
*
|
|
17
|
+
* Mirrors servicePairings.cjs: state is read once from disk (missing/corrupt =
|
|
18
|
+
* empty) and kept in memory; every mutation is written atomically, serialized
|
|
19
|
+
* through one queue. Reads are synchronous over the in-memory copy. This store
|
|
20
|
+
* is the only writer of that file (it lives under ~/.claude, not an ops root).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const path = require('node:path');
|
|
24
|
+
const { writeTextAtomic, readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
25
|
+
|
|
26
|
+
const STORE_VERSION = 1;
|
|
27
|
+
const MAX_PROJECTS = 1000;
|
|
28
|
+
const MAX_EXTERNAL_REF_LEN = 200;
|
|
29
|
+
const MAX_REPO_LEN = 200;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @typedef {{ cwd: string, fromCwd: string, externalRef: string, repo: string | null, createdAt: number }} CreatedProject
|
|
33
|
+
* @typedef {{ version: number, projects: CreatedProject[] }} StoreState
|
|
34
|
+
* @typedef {{ cwd?: unknown, fromCwd?: unknown, externalRef?: unknown, repo?: unknown }} RecordInput
|
|
35
|
+
* @typedef {{
|
|
36
|
+
* findByRef: (fromCwd: unknown, externalRef: unknown) => CreatedProject | null,
|
|
37
|
+
* findByCwd: (cwd: unknown) => CreatedProject | null,
|
|
38
|
+
* record: (input: RecordInput) => Promise<CreatedProject>,
|
|
39
|
+
* setRepo: (cwd: unknown, repo: unknown) => Promise<CreatedProject | null>,
|
|
40
|
+
* list: () => CreatedProject[],
|
|
41
|
+
* }} CreatedProjectsStore
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/** @returns {string} */
|
|
45
|
+
function defaultFilePath() {
|
|
46
|
+
const override = process.env.SM_CREATED_PROJECTS_FILE;
|
|
47
|
+
if (typeof override === 'string' && override.length > 0) return override;
|
|
48
|
+
const { claudeHome } = require('../scheduler/schedulerPaths.cjs');
|
|
49
|
+
return path.join(claudeHome(), 'session-manager', 'created-projects.json');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {unknown} p
|
|
54
|
+
* @returns {p is string}
|
|
55
|
+
*/
|
|
56
|
+
function isAbsPath(p) {
|
|
57
|
+
return typeof p === 'string' && p.length > 0 && path.isAbsolute(p) && !p.includes('\0');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @param {unknown} p
|
|
62
|
+
* @param {string} label
|
|
63
|
+
* @returns {string}
|
|
64
|
+
*/
|
|
65
|
+
function validateAbs(p, label) {
|
|
66
|
+
if (!isAbsPath(p)) throw new Error(`${label} must be an absolute path`);
|
|
67
|
+
return path.resolve(p);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @param {unknown} ref
|
|
72
|
+
* @returns {string}
|
|
73
|
+
*/
|
|
74
|
+
function validateExternalRef(ref) {
|
|
75
|
+
if (typeof ref !== 'string' || ref.length === 0 || ref.length > MAX_EXTERNAL_REF_LEN) {
|
|
76
|
+
throw new Error(`externalRef must be a string of 1 to ${MAX_EXTERNAL_REF_LEN} chars`);
|
|
77
|
+
}
|
|
78
|
+
return ref;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @param {unknown} repo
|
|
83
|
+
* @param {boolean} allowNull
|
|
84
|
+
* @returns {string | null}
|
|
85
|
+
*/
|
|
86
|
+
function validateRepo(repo, allowNull) {
|
|
87
|
+
if (allowNull && (repo === undefined || repo === null)) return null;
|
|
88
|
+
if (typeof repo !== 'string' || repo.length === 0 || repo.length > MAX_REPO_LEN || /[\r\n\0]/.test(repo)) {
|
|
89
|
+
throw new Error(`repo must be a one-line string of 1 to ${MAX_REPO_LEN} chars`);
|
|
90
|
+
}
|
|
91
|
+
return repo;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @param {CreatedProject} e
|
|
96
|
+
* @returns {CreatedProject}
|
|
97
|
+
*/
|
|
98
|
+
function copy(e) {
|
|
99
|
+
return { cwd: e.cwd, fromCwd: e.fromCwd, externalRef: e.externalRef, repo: e.repo, createdAt: e.createdAt };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {unknown} e
|
|
104
|
+
* @returns {e is CreatedProject}
|
|
105
|
+
*/
|
|
106
|
+
function isEntry(e) {
|
|
107
|
+
if (!e || typeof e !== 'object') return false;
|
|
108
|
+
const r = /** @type {Record<string, unknown>} */ (e);
|
|
109
|
+
return isAbsPath(r.cwd) && isAbsPath(r.fromCwd)
|
|
110
|
+
&& typeof r.externalRef === 'string' && r.externalRef.length > 0
|
|
111
|
+
&& typeof r.createdAt === 'number';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* A repo read from disk: kept only when it passes validateRepo, else null.
|
|
116
|
+
* @param {unknown} repo
|
|
117
|
+
* @returns {string | null}
|
|
118
|
+
*/
|
|
119
|
+
function loadedRepo(repo) {
|
|
120
|
+
if (typeof repo !== 'string') return null;
|
|
121
|
+
try {
|
|
122
|
+
return validateRepo(repo, false);
|
|
123
|
+
} catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {unknown} raw
|
|
130
|
+
* @returns {StoreState}
|
|
131
|
+
*/
|
|
132
|
+
function normalizeLoaded(raw) {
|
|
133
|
+
/** @type {StoreState} */
|
|
134
|
+
const empty = { version: STORE_VERSION, projects: [] };
|
|
135
|
+
if (!raw || typeof raw !== 'object') return empty;
|
|
136
|
+
const list = /** @type {{ projects?: unknown }} */ (raw).projects;
|
|
137
|
+
if (!Array.isArray(list)) return empty;
|
|
138
|
+
const projects = list.filter(isEntry).map((e) => ({
|
|
139
|
+
cwd: path.resolve(e.cwd),
|
|
140
|
+
fromCwd: path.resolve(e.fromCwd),
|
|
141
|
+
externalRef: e.externalRef,
|
|
142
|
+
repo: loadedRepo(e.repo),
|
|
143
|
+
createdAt: e.createdAt,
|
|
144
|
+
}));
|
|
145
|
+
return { version: STORE_VERSION, projects: projects.slice(-MAX_PROJECTS) };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @param {{ filePath?: string, now?: () => number }} [opts]
|
|
150
|
+
* @returns {CreatedProjectsStore}
|
|
151
|
+
*/
|
|
152
|
+
function createCreatedProjects({ filePath, now } = {}) {
|
|
153
|
+
const file = filePath || defaultFilePath();
|
|
154
|
+
const clock = typeof now === 'function' ? now : () => Date.now();
|
|
155
|
+
/** @type {StoreState | null} */
|
|
156
|
+
let state = null;
|
|
157
|
+
/** @type {Promise<unknown>} */
|
|
158
|
+
let queue = Promise.resolve();
|
|
159
|
+
|
|
160
|
+
/** @returns {StoreState} */
|
|
161
|
+
function load() {
|
|
162
|
+
if (!state) state = normalizeLoaded(readJsonOrSync(file, null));
|
|
163
|
+
return state;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Run a mutation then persist; serialized so writes never interleave.
|
|
168
|
+
* @template T
|
|
169
|
+
* @param {(s: StoreState) => T} fn
|
|
170
|
+
* @returns {Promise<T>}
|
|
171
|
+
*/
|
|
172
|
+
function mutate(fn) {
|
|
173
|
+
const run = queue.then(async () => {
|
|
174
|
+
/** @type {StoreState} */
|
|
175
|
+
const next = JSON.parse(JSON.stringify(load()));
|
|
176
|
+
const result = fn(next);
|
|
177
|
+
await writeTextAtomic(file, `${JSON.stringify(next, null, 2)}\n`, { mode: 0o600 });
|
|
178
|
+
state = next;
|
|
179
|
+
return result;
|
|
180
|
+
});
|
|
181
|
+
queue = run.catch(() => {});
|
|
182
|
+
return run;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {StoreState} s
|
|
187
|
+
* @param {string} cwd
|
|
188
|
+
*/
|
|
189
|
+
function entryByCwd(s, cwd) {
|
|
190
|
+
return s.projects.find((e) => e.cwd === cwd) || null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* @param {StoreState} s
|
|
195
|
+
* @param {string} fromCwd
|
|
196
|
+
* @param {string} externalRef
|
|
197
|
+
*/
|
|
198
|
+
function entryByRef(s, fromCwd, externalRef) {
|
|
199
|
+
return s.projects.find((e) => e.fromCwd === fromCwd && e.externalRef === externalRef) || null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
findByRef(fromCwd, externalRef) {
|
|
204
|
+
if (!isAbsPath(fromCwd) || typeof externalRef !== 'string' || externalRef.length === 0) return null;
|
|
205
|
+
const e = entryByRef(load(), path.resolve(fromCwd), externalRef);
|
|
206
|
+
return e ? copy(e) : null;
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
findByCwd(cwd) {
|
|
210
|
+
if (!isAbsPath(cwd)) return null;
|
|
211
|
+
const e = entryByCwd(load(), path.resolve(cwd));
|
|
212
|
+
return e ? copy(e) : null;
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
record(input) {
|
|
216
|
+
/** @type {string} */ let cwd;
|
|
217
|
+
/** @type {string} */ let fromCwd;
|
|
218
|
+
/** @type {string} */ let externalRef;
|
|
219
|
+
/** @type {string | null} */ let repo;
|
|
220
|
+
try {
|
|
221
|
+
if (input === null || typeof input !== 'object' || Array.isArray(input)) {
|
|
222
|
+
throw new Error('record expects { cwd, fromCwd, externalRef, repo? }');
|
|
223
|
+
}
|
|
224
|
+
cwd = validateAbs(input.cwd, 'cwd');
|
|
225
|
+
fromCwd = validateAbs(input.fromCwd, 'fromCwd');
|
|
226
|
+
externalRef = validateExternalRef(input.externalRef);
|
|
227
|
+
repo = validateRepo(input.repo, true);
|
|
228
|
+
} catch (e) {
|
|
229
|
+
return Promise.reject(e);
|
|
230
|
+
}
|
|
231
|
+
return mutate((s) => {
|
|
232
|
+
const byCwd = entryByCwd(s, cwd);
|
|
233
|
+
if (byCwd) {
|
|
234
|
+
if (byCwd.fromCwd === fromCwd && byCwd.externalRef === externalRef) return copy(byCwd);
|
|
235
|
+
throw new Error(`cwd is already recorded under another externalRef: ${cwd}`);
|
|
236
|
+
}
|
|
237
|
+
const byRef = entryByRef(s, fromCwd, externalRef);
|
|
238
|
+
if (byRef) throw new Error(`externalRef already names a different cwd: ${byRef.cwd}`);
|
|
239
|
+
/** @type {CreatedProject} */
|
|
240
|
+
const entry = { cwd, fromCwd, externalRef, repo, createdAt: clock() };
|
|
241
|
+
s.projects.push(entry);
|
|
242
|
+
if (s.projects.length > MAX_PROJECTS) s.projects = s.projects.slice(-MAX_PROJECTS);
|
|
243
|
+
return copy(entry);
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
setRepo(cwd, repo) {
|
|
248
|
+
/** @type {string} */ let want;
|
|
249
|
+
/** @type {string} */ let value;
|
|
250
|
+
try {
|
|
251
|
+
want = validateAbs(cwd, 'cwd');
|
|
252
|
+
value = /** @type {string} */ (validateRepo(repo, false));
|
|
253
|
+
} catch (e) {
|
|
254
|
+
return Promise.reject(e);
|
|
255
|
+
}
|
|
256
|
+
return mutate((s) => {
|
|
257
|
+
const e = entryByCwd(s, want);
|
|
258
|
+
if (!e) return null;
|
|
259
|
+
e.repo = value;
|
|
260
|
+
return copy(e);
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
|
|
264
|
+
list() {
|
|
265
|
+
const items = load().projects.map((e, i) => ({ e, i }));
|
|
266
|
+
items.sort((a, b) => (b.e.createdAt - a.e.createdAt) || (b.i - a.i));
|
|
267
|
+
return items.map(({ e }) => copy(e));
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** @type {CreatedProjectsStore | null} */
|
|
273
|
+
let singleton = null;
|
|
274
|
+
|
|
275
|
+
/** @returns {CreatedProjectsStore} */
|
|
276
|
+
function getCreatedProjects() {
|
|
277
|
+
if (!singleton) singleton = createCreatedProjects();
|
|
278
|
+
return singleton;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function __resetCreatedProjectsForTests() {
|
|
282
|
+
singleton = null;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
module.exports = {
|
|
286
|
+
createCreatedProjects,
|
|
287
|
+
getCreatedProjects,
|
|
288
|
+
__resetCreatedProjectsForTests,
|
|
289
|
+
MAX_PROJECTS,
|
|
290
|
+
MAX_EXTERNAL_REF_LEN,
|
|
291
|
+
};
|
|
@@ -86,6 +86,7 @@ const {
|
|
|
86
86
|
MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK,
|
|
87
87
|
} = require('../epic/epicMint.cjs');
|
|
88
88
|
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
89
|
+
const { buildServiceStartedBy } = require('../epic/scriptStartedBy.cjs');
|
|
89
90
|
const { normalizeExternalRef } = require('../epic/externalRef.cjs');
|
|
90
91
|
const { recordExternalRef, findEpicByExternalRef, withExternalRefLock } = require('../epic/externalRefIndex.cjs');
|
|
91
92
|
const { OPS_ROOT_DIR, opsPath } = require('../opsOwnership.cjs');
|
|
@@ -583,8 +584,32 @@ function verifyAutoStart(v, originClaudeSessionId) {
|
|
|
583
584
|
}
|
|
584
585
|
|
|
585
586
|
const MAX_MACRO_AUTO_STARTS = 5;
|
|
587
|
+
/** Request-object key the in-process invoke() sets for a paired service call. */
|
|
588
|
+
const TRUSTED_SERVICE = Symbol.for('sm.trustedService');
|
|
586
589
|
const AUTO_START_TAGS = Object.freeze(['bug', 'feature']);
|
|
587
590
|
|
|
591
|
+
/**
|
|
592
|
+
* verifyServiceAutoStart(v, service) → { granted: true, ground:'service', serviceId, serviceName }
|
|
593
|
+
* | { granted: false, reason }
|
|
594
|
+
* `service` is the paired-service record RE-READ from the store at decision time
|
|
595
|
+
* (null when revoked). Its identity never comes from the request body.
|
|
596
|
+
*/
|
|
597
|
+
function verifyServiceAutoStart(v, service) {
|
|
598
|
+
if (!service) return { granted: false, reason: 'the paired service is no longer paired' };
|
|
599
|
+
const { startWorkAllows } = require('./servicePairings.cjs');
|
|
600
|
+
if (!v.autoStart) return { granted: false, reason: 'autoStart was not requested' };
|
|
601
|
+
if (!service.startWork || !service.startWork.targets || service.startWork.targets.length === 0) {
|
|
602
|
+
return { granted: false, reason: `the ${service.name} service has no start-work grant` };
|
|
603
|
+
}
|
|
604
|
+
if (!startWorkAllows(service, v.toCwd)) {
|
|
605
|
+
return { granted: false, reason: `the ${service.name} service's start-work grant does not cover ${path.basename(v.toCwd)}` };
|
|
606
|
+
}
|
|
607
|
+
if (!AUTO_START_TAGS.includes(v.tag)) {
|
|
608
|
+
return { granted: false, reason: `service auto-start covers bug and feature work only (tag was ${v.tag})` };
|
|
609
|
+
}
|
|
610
|
+
return { granted: true, ground: 'service', serviceId: service.serviceId, serviceName: service.name };
|
|
611
|
+
}
|
|
612
|
+
|
|
588
613
|
// Grants per sender Epic id. In memory, so a restart resets it — accepted
|
|
589
614
|
// because each press of a macro is a human act.
|
|
590
615
|
const macroGrantCounts = new Map();
|
|
@@ -739,11 +764,25 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
739
764
|
typeof input.originClaudeSessionId === 'string' && input.originClaudeSessionId
|
|
740
765
|
? input.originClaudeSessionId
|
|
741
766
|
: null;
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
//
|
|
745
|
-
|
|
746
|
-
|
|
767
|
+
// A call from a paired service (identity set only by the in-process invoke
|
|
768
|
+
// channel, never the body) is judged on the service ground alone: a service
|
|
769
|
+
// has no chat to quote and no macro.
|
|
770
|
+
const trustedServiceId = typeof deps.trustedServiceId === 'string' && deps.trustedServiceId ? deps.trustedServiceId : null;
|
|
771
|
+
let serviceAuto = null;
|
|
772
|
+
let macroAuto = null;
|
|
773
|
+
let auto;
|
|
774
|
+
if (trustedServiceId) {
|
|
775
|
+
let service = null;
|
|
776
|
+
try { service = deps.findService ? deps.findService(trustedServiceId) : null; } catch { service = null; }
|
|
777
|
+
serviceAuto = verifyServiceAutoStart(v, service);
|
|
778
|
+
auto = serviceAuto;
|
|
779
|
+
} else {
|
|
780
|
+
macroAuto = await verifyMacroAutoStart(v, originClaudeSessionId, deps);
|
|
781
|
+
auto = macroAuto && macroAuto.granted ? macroAuto : verifyAutoStart(v, originClaudeSessionId);
|
|
782
|
+
// A macro denial is the more specific reason when verifyAutoStart (no
|
|
783
|
+
// autoStart flag) would only say "not requested".
|
|
784
|
+
if (!auto.granted && macroAuto && !macroAuto.granted) auto = macroAuto;
|
|
785
|
+
}
|
|
747
786
|
const isMacro = auto.granted && auto.ground === 'macro';
|
|
748
787
|
// Reserve at grant time (re-checked after the verify's await so concurrent
|
|
749
788
|
// sends cannot overshoot the cap); released below if the mint throws.
|
|
@@ -756,6 +795,7 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
756
795
|
}
|
|
757
796
|
}
|
|
758
797
|
const macroGranted = auto.granted && auto.ground === 'macro';
|
|
798
|
+
const serviceGranted = auto.granted && auto.ground === 'service';
|
|
759
799
|
const verifiedAt = new Date().toISOString();
|
|
760
800
|
|
|
761
801
|
// The MCP client can't know its own Epic id — it only inherits the claude
|
|
@@ -809,7 +849,15 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
809
849
|
...(replyTo ? { replyTo } : {}),
|
|
810
850
|
...(auto.granted
|
|
811
851
|
? {
|
|
812
|
-
autoApprove:
|
|
852
|
+
autoApprove: serviceGranted
|
|
853
|
+
? {
|
|
854
|
+
requestedBy: 'service',
|
|
855
|
+
serviceId: auto.serviceId,
|
|
856
|
+
serviceName: auto.serviceName,
|
|
857
|
+
verifiedAt,
|
|
858
|
+
fromClaudeSessionId: null,
|
|
859
|
+
}
|
|
860
|
+
: macroGranted
|
|
813
861
|
? {
|
|
814
862
|
requestedBy: 'macro',
|
|
815
863
|
macroId: auto.macroId,
|
|
@@ -825,6 +873,7 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
825
873
|
},
|
|
826
874
|
}
|
|
827
875
|
: {}),
|
|
876
|
+
...(serviceGranted ? { startedBy: buildServiceStartedBy({ serviceId: auto.serviceId, name: auto.serviceName }) } : {}),
|
|
828
877
|
proposal: {
|
|
829
878
|
motivation: v.motivation,
|
|
830
879
|
originAsk,
|
|
@@ -853,7 +902,10 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
853
902
|
title: v.title,
|
|
854
903
|
series: v.series,
|
|
855
904
|
autoStartGranted: auto.granted,
|
|
856
|
-
autoStartReason: auto.granted
|
|
905
|
+
autoStartReason: auto.granted
|
|
906
|
+
? (serviceGranted ? `service grant ${auto.serviceId}` : macroGranted ? `macro grant ${auto.macroId}` : 'verified human request')
|
|
907
|
+
: auto.reason,
|
|
908
|
+
...(serviceGranted ? { serviceId: auto.serviceId, serviceName: auto.serviceName } : {}),
|
|
857
909
|
});
|
|
858
910
|
|
|
859
911
|
if (auto.granted) {
|
|
@@ -872,7 +924,9 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
872
924
|
+ (v.series ? ` [${seriesLine(v.series)}]` : '')
|
|
873
925
|
+ '. '
|
|
874
926
|
+ (auto.granted
|
|
875
|
-
? (
|
|
927
|
+
? (serviceGranted
|
|
928
|
+
? `It was auto-approved by the ${auto.serviceName} service grant and is starting in that project.`
|
|
929
|
+
: macroGranted
|
|
876
930
|
? `It was auto-approved by the "${auto.macroLabel}" macro (${auto.macroId}) and is starting in that project.`
|
|
877
931
|
: 'It was auto-approved at the human\'s explicit request and is starting in that project.')
|
|
878
932
|
: 'It will not run until a human in that project approves it.'),
|
|
@@ -890,7 +944,7 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
890
944
|
tag: v.tag,
|
|
891
945
|
...(v.externalRef ? { externalRef: v.externalRef } : {}),
|
|
892
946
|
status: auto.granted ? 'auto-approved' : 'proposed',
|
|
893
|
-
...(v.autoStart || macroAuto ? { autoStart: auto.granted ? { granted: true } : { granted: false, reason: auto.reason } } : {}),
|
|
947
|
+
...(v.autoStart || macroAuto || serviceAuto ? { autoStart: auto.granted ? { granted: true } : { granted: false, reason: auto.reason } } : {}),
|
|
894
948
|
receiptOnOriginEpic,
|
|
895
949
|
// True only when source.replyTo was stamped — the MCP note keys its
|
|
896
950
|
// feedback_reply promise off this, never off the delivery alone.
|
|
@@ -899,7 +953,13 @@ async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify
|
|
|
899
953
|
replyMode: v.replyMode,
|
|
900
954
|
// Say plainly what did NOT happen, same posture as create-prd's
|
|
901
955
|
// `enqueued: false` — never let a caller report this as "work started".
|
|
902
|
-
note: (
|
|
956
|
+
note: (serviceGranted
|
|
957
|
+
? `Delivered auto-approved by the ${auto.serviceName} service grant (set by the owner for this project): `
|
|
958
|
+
+ 'the session is starting in the receiving project. '
|
|
959
|
+
: serviceAuto && !auto.granted
|
|
960
|
+
? `Delivered as a PROPOSED session (not auto-approved: ${auto.reason}). Nothing runs and no `
|
|
961
|
+
+ 'tokens are spent until a human in that project presses Approve & start. '
|
|
962
|
+
: macroGranted
|
|
903
963
|
? `Auto-approved by the "${auto.macroLabel}" macro (${auto.macroId}), which the human launched this session `
|
|
904
964
|
+ 'from and which allows auto-start in this project: the session is starting in the receiving project. '
|
|
905
965
|
: auto.granted
|
|
@@ -1126,17 +1186,26 @@ async function openReplyFallbackSession(input = {}, deps = {}) {
|
|
|
1126
1186
|
* requires everywhere else: a PROJECT IS A CWD, resolved from transcript
|
|
1127
1187
|
* CONTENT, never by naively decoding a `~/.claude/projects/` folder name back
|
|
1128
1188
|
* into a path. A folder whose cwd cannot be resolved is DROPPED, not guessed.
|
|
1189
|
+
*
|
|
1190
|
+
* Two sources:
|
|
1191
|
+
* 1. transcript folders under `~/.claude/projects/` (above);
|
|
1192
|
+
* 2. the created-projects ledger (`createdProjects.cjs`, injectable as
|
|
1193
|
+
* `createdProjects`, default `getCreatedProjects()`), so a folder made by
|
|
1194
|
+
* project_create is a target before anyone has worked in it. Ledger cwds
|
|
1195
|
+
* are recorded main checkouts, so they skip resolveProjectContext; their
|
|
1196
|
+
* lastActivity is the later of transcript activity and createdAt, and a
|
|
1197
|
+
* cwd in both sources is listed once.
|
|
1129
1198
|
* Results are then filtered to directories that still exist AND already carry
|
|
1130
1199
|
* an operations root — exactly `openFeedbackSession`'s own precondition, so
|
|
1131
1200
|
* this list can't offer a target that would then be refused.
|
|
1132
1201
|
*/
|
|
1133
|
-
async function listFeedbackTargets({ limit = TARGET_SCAN_LIMIT, projectsDir } = {}) {
|
|
1202
|
+
async function listFeedbackTargets({ limit = TARGET_SCAN_LIMIT, projectsDir, createdProjects } = {}) {
|
|
1134
1203
|
const root = resolveProjectsDir(projectsDir);
|
|
1135
1204
|
let entries;
|
|
1136
1205
|
try {
|
|
1137
1206
|
entries = await fsp.readdir(root, { withFileTypes: true });
|
|
1138
1207
|
} catch {
|
|
1139
|
-
|
|
1208
|
+
entries = [];
|
|
1140
1209
|
}
|
|
1141
1210
|
const dirs = entries.filter((e) => e.isDirectory());
|
|
1142
1211
|
|
|
@@ -1166,6 +1235,19 @@ async function listFeedbackTargets({ limit = TARGET_SCAN_LIMIT, projectsDir } =
|
|
|
1166
1235
|
if (!prior || prior.lastActivity < mtimeMs) byCwd.set(cwd, { cwd, lastActivity: mtimeMs });
|
|
1167
1236
|
}
|
|
1168
1237
|
|
|
1238
|
+
// Second source: the created-projects ledger. A broken ledger never hides
|
|
1239
|
+
// the transcript-derived list.
|
|
1240
|
+
let ledgerEntries = [];
|
|
1241
|
+
try {
|
|
1242
|
+
const store = createdProjects || require('./createdProjects.cjs').getCreatedProjects();
|
|
1243
|
+
ledgerEntries = store.list();
|
|
1244
|
+
} catch { ledgerEntries = []; }
|
|
1245
|
+
for (const e of ledgerEntries) {
|
|
1246
|
+
if (!e || typeof e.cwd !== 'string' || typeof e.createdAt !== 'number') continue;
|
|
1247
|
+
const prior = byCwd.get(e.cwd);
|
|
1248
|
+
if (!prior || prior.lastActivity < e.createdAt) byCwd.set(e.cwd, { cwd: e.cwd, lastActivity: e.createdAt });
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1169
1251
|
const projects = [...byCwd.values()]
|
|
1170
1252
|
.filter((p) => isDirectory(p.cwd) && isSessionManagerProject(p.cwd))
|
|
1171
1253
|
.sort((a, b) => b.lastActivity - a.lastActivity)
|
|
@@ -1219,7 +1301,7 @@ async function resolveCwdFromTranscriptDir(dir) {
|
|
|
1219
1301
|
|
|
1220
1302
|
/** Registers both routes on the injected loopback admin transport. Mirrors
|
|
1221
1303
|
* prdCreate.cjs's registerAdminRoute — auth is the transport's job. */
|
|
1222
|
-
function registerAdminRoute(adminHttp) {
|
|
1304
|
+
function registerAdminRoute(adminHttp, { getServiceStore } = {}) {
|
|
1223
1305
|
adminHttp.registerRoute('POST', '/admin/feedback/open-session', async (req, res) => {
|
|
1224
1306
|
const raw = await readBody(req);
|
|
1225
1307
|
let parsed;
|
|
@@ -1229,7 +1311,17 @@ function registerAdminRoute(adminHttp) {
|
|
|
1229
1311
|
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
1230
1312
|
return;
|
|
1231
1313
|
}
|
|
1232
|
-
|
|
1314
|
+
// Service identity: only the in-process invoke() sets this symbol on the
|
|
1315
|
+
// request; an HTTP request cannot, and the body is never consulted.
|
|
1316
|
+
const trusted = req[TRUSTED_SERVICE];
|
|
1317
|
+
const trustedServiceId = trusted && typeof trusted.serviceId === 'string' ? trusted.serviceId : null;
|
|
1318
|
+
const lookup = getServiceStore || (() => require('../../webRemote.cjs').getServiceStore());
|
|
1319
|
+
const result = await openFeedbackSession(
|
|
1320
|
+
parsed,
|
|
1321
|
+
trustedServiceId
|
|
1322
|
+
? { trustedServiceId, findService: (id) => lookup().list().find((x) => x.serviceId === id) || null }
|
|
1323
|
+
: {},
|
|
1324
|
+
);
|
|
1233
1325
|
if (!result.ok) {
|
|
1234
1326
|
sendJson(res, result.status ?? 400, { ok: false, error: result.error });
|
|
1235
1327
|
return;
|
|
@@ -1257,6 +1349,8 @@ module.exports = {
|
|
|
1257
1349
|
MAX_REFERENCES,
|
|
1258
1350
|
MAX_MACRO_AUTO_STARTS,
|
|
1259
1351
|
verifyMacroAutoStart,
|
|
1352
|
+
verifyServiceAutoStart,
|
|
1353
|
+
TRUSTED_SERVICE,
|
|
1260
1354
|
quoteNamesTarget,
|
|
1261
1355
|
PROJECTS_DIR,
|
|
1262
1356
|
resolveProjectsDir,
|
|
@@ -239,7 +239,7 @@ function createAdminHttp() {
|
|
|
239
239
|
* serialized and streamed to the handler like an HTTP request body.
|
|
240
240
|
* Resolves { status, json } (json null when the handler wrote non-JSON).
|
|
241
241
|
*/
|
|
242
|
-
async function invoke(method, routePath, { body, query } = {}) {
|
|
242
|
+
async function invoke(method, routePath, { body, query, trustedService } = {}) {
|
|
243
243
|
const urlObj = new URL(routePath, 'http://127.0.0.1');
|
|
244
244
|
if (query) {
|
|
245
245
|
const params = query instanceof URLSearchParams ? query : new URLSearchParams(
|
|
@@ -249,6 +249,10 @@ function createAdminHttp() {
|
|
|
249
249
|
}
|
|
250
250
|
const payload = body === undefined ? '' : JSON.stringify(body);
|
|
251
251
|
const req = createInMemoryRequest(String(method).toUpperCase(), `${urlObj.pathname}${urlObj.search}`, payload);
|
|
252
|
+
// Trusted-channel service identity: a Symbol key no HTTP request can carry.
|
|
253
|
+
if (trustedService && typeof trustedService.serviceId === 'string') {
|
|
254
|
+
req[Symbol.for('sm.trustedService')] = { serviceId: trustedService.serviceId };
|
|
255
|
+
}
|
|
252
256
|
const res = createResponseShim();
|
|
253
257
|
try {
|
|
254
258
|
await dispatch(req, res);
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
* `onChanged()` exactly once so the Sessions HOT KEYS strip updates live,
|
|
45
45
|
* matching the IPC handlers in index.cjs.
|
|
46
46
|
*
|
|
47
|
-
* POST /admin/macros/run {cwd, id, inputs?, effort?, externalRef?}
|
|
47
|
+
* POST /admin/macros/run {cwd, id, inputs?, effort?, externalRef?, caller?}
|
|
48
48
|
* -> { ok, epicId, alreadyRunning, externalRef? }
|
|
49
49
|
* Starts a saved macro from a script (e.g. a systemd timer) through the
|
|
50
50
|
* renderer's press path (deps.startExternalNewSession: same persona, tag, AIM
|
|
@@ -58,6 +58,10 @@
|
|
|
58
58
|
* macro at most once per ref: it rides in the payload, is recorded in
|
|
59
59
|
* externalRefIndex and audited; a repeat with the same cwd + ref answers
|
|
60
60
|
* { existing: true } with that Epic (409 if another producer/macro owns the ref).
|
|
61
|
+
* caller ({pipeline?, runId?, step?, attempt?}, CallerSchema in
|
|
62
|
+
* epic/scriptStartedBy.cjs; invalid = 400, no launch) rides in the audit event as scriptCaller (the audit log stamps its own `caller`);
|
|
63
|
+
* every launch payload carries startedBy (deps.startedByFromRequest) so the Epic
|
|
64
|
+
* records it was script-started. The mint producer stays 'new-epic-ui'.
|
|
61
65
|
* 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>"}'
|
|
62
66
|
*/
|
|
63
67
|
'use strict';
|
|
@@ -70,6 +74,7 @@ const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
|
70
74
|
const { findHumanPromptContaining } = require('./humanPromptLedger.cjs');
|
|
71
75
|
const { readActiveIndex } = require('../epic/epicMint.cjs');
|
|
72
76
|
const { PRD_EFFORT_LEVELS } = require('../prd/prdFrontmatter.cjs');
|
|
77
|
+
const { CallerSchema, startedByFromRequest: defaultStartedByFromRequest } = require('../epic/scriptStartedBy.cjs');
|
|
73
78
|
const { normalizeExternalRef } = require('../epic/externalRef.cjs');
|
|
74
79
|
const { findEpicByExternalRef, recordExternalRef, withExternalRefLock } = require('../epic/externalRefIndex.cjs');
|
|
75
80
|
|
|
@@ -379,6 +384,14 @@ function runHandler(deps, libOpts) {
|
|
|
379
384
|
if (effort !== undefined && !PRD_EFFORT_LEVELS.includes(effort)) {
|
|
380
385
|
return bad(`effort must be one of: ${PRD_EFFORT_LEVELS.join(', ')}`);
|
|
381
386
|
}
|
|
387
|
+
let caller;
|
|
388
|
+
if (body.caller !== undefined) {
|
|
389
|
+
const parsedCaller = CallerSchema.safeParse(body.caller);
|
|
390
|
+
if (!parsedCaller.success) {
|
|
391
|
+
return bad(`caller: ${parsedCaller.error.issues?.[0]?.message ?? 'invalid'}`);
|
|
392
|
+
}
|
|
393
|
+
caller = parsedCaller.data;
|
|
394
|
+
}
|
|
382
395
|
const ref = normalizeExternalRef(body.externalRef);
|
|
383
396
|
if (!ref.ok) return bad(ref.error);
|
|
384
397
|
const rendered = macroLibrary.renderMacroPrompt(macro.prompt, macro.inputs, {
|
|
@@ -388,7 +401,7 @@ function runHandler(deps, libOpts) {
|
|
|
388
401
|
if (!rendered.ok) return bad(rendered.error);
|
|
389
402
|
|
|
390
403
|
if (ref.value !== undefined) {
|
|
391
|
-
await runWithExternalRef({ deps, res, cwd, macro, prompt: rendered.prompt, effort, externalRef: ref.value });
|
|
404
|
+
await runWithExternalRef({ deps, req, res, caller, cwd, macro, prompt: rendered.prompt, effort, externalRef: ref.value });
|
|
392
405
|
return;
|
|
393
406
|
}
|
|
394
407
|
|
|
@@ -411,6 +424,8 @@ function runHandler(deps, libOpts) {
|
|
|
411
424
|
|
|
412
425
|
if (refusedByUsageHold(deps, res)) return;
|
|
413
426
|
|
|
427
|
+
const startedBy = await (deps.startedByFromRequest || defaultStartedByFromRequest)(
|
|
428
|
+
{ route: '/admin/macros/run', caller, socket: req.socket }, deps);
|
|
414
429
|
const payload = {
|
|
415
430
|
cwd,
|
|
416
431
|
agentName: macro.agentName,
|
|
@@ -419,6 +434,7 @@ function runHandler(deps, libOpts) {
|
|
|
419
434
|
prompt: rendered.prompt,
|
|
420
435
|
macroId: macro.id,
|
|
421
436
|
via: 'script',
|
|
437
|
+
startedBy,
|
|
422
438
|
...(effort !== undefined ? { effort } : {}),
|
|
423
439
|
};
|
|
424
440
|
const launch = (async () => {
|
|
@@ -449,6 +465,7 @@ function runHandler(deps, libOpts) {
|
|
|
449
465
|
macroId: macro.id,
|
|
450
466
|
epicId: result.epicId,
|
|
451
467
|
alreadyRunning: false,
|
|
468
|
+
...(caller ? { scriptCaller: caller } : {}),
|
|
452
469
|
});
|
|
453
470
|
sendJson(res, 200, { ok: true, epicId: result.epicId, alreadyRunning: false });
|
|
454
471
|
};
|
|
@@ -491,7 +508,7 @@ function launchFailureError(result) {
|
|
|
491
508
|
* (cwd, externalRef) share one launch. The macro-wide findRunningEpic shortcut
|
|
492
509
|
* is skipped: a new ref is a new run even while another run is busy.
|
|
493
510
|
*/
|
|
494
|
-
async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, externalRef }) {
|
|
511
|
+
async function runWithExternalRef({ deps, req, res, caller, cwd, macro, prompt, effort, externalRef }) {
|
|
495
512
|
const isTabBusy = deps.isTabBusy || (() => false);
|
|
496
513
|
const existingAnswer = (epicId) => sendJson(res, 200, {
|
|
497
514
|
ok: true, epicId, existing: true, alreadyRunning: !!isTabBusy(epicId), externalRef,
|
|
@@ -529,6 +546,8 @@ async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, exter
|
|
|
529
546
|
|
|
530
547
|
if (refusedByUsageHold(deps, res)) return;
|
|
531
548
|
|
|
549
|
+
const startedBy = await (deps.startedByFromRequest || defaultStartedByFromRequest)(
|
|
550
|
+
{ route: '/admin/macros/run', caller, socket: req.socket }, deps);
|
|
532
551
|
const payload = {
|
|
533
552
|
cwd,
|
|
534
553
|
agentName: macro.agentName,
|
|
@@ -537,6 +556,7 @@ async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, exter
|
|
|
537
556
|
prompt,
|
|
538
557
|
macroId: macro.id,
|
|
539
558
|
via: 'script',
|
|
559
|
+
startedBy,
|
|
540
560
|
externalRef,
|
|
541
561
|
...(effort !== undefined ? { effort } : {}),
|
|
542
562
|
};
|
|
@@ -577,6 +597,7 @@ async function runWithExternalRef({ deps, res, cwd, macro, prompt, effort, exter
|
|
|
577
597
|
epicId: result.epicId,
|
|
578
598
|
alreadyRunning: false,
|
|
579
599
|
externalRef,
|
|
600
|
+
...(caller ? { scriptCaller: caller } : {}),
|
|
580
601
|
});
|
|
581
602
|
sendJson(res, 200, {
|
|
582
603
|
ok: true, epicId: result.epicId, alreadyRunning: false, externalRef,
|