claude-code-session-manager 0.135.1 → 0.136.1
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/dist/assets/{AgentLibrary-BBY7E1ag.js → AgentLibrary-DsJcjUSt.js} +1 -1
- package/dist/assets/{AppSettings-vMiIi0xn.js → AppSettings-DS_d4o5R.js} +1 -1
- package/dist/assets/{Button-C0Z090Ui.js → Button-CVbZqtPJ.js} +1 -1
- package/dist/assets/{DocumentEditorPane-Ds10W8SZ.js → DocumentEditorPane-C4G5oeng.js} +1 -1
- package/dist/assets/{Extensions-CjPiz2I5.js → Extensions-ifcqZDuK.js} +2 -2
- package/dist/assets/{History-Bm3KXXs1.js → History-CBFAmFB7.js} +1 -1
- package/dist/assets/{Library-D-khizDg.js → Library-DlUH_fFF.js} +1 -1
- package/dist/assets/{ListDetail-CJYpp8fW.js → ListDetail-DrzkqaSM.js} +1 -1
- package/dist/assets/{Panel-BHFGylfy.js → Panel-Bjr5sT2j.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-DIzNAala.js → ProjectClaudeConfig-BEJAWpS2.js} +1 -1
- package/dist/assets/{ProvenanceBadge-CYryeTYF.js → ProvenanceBadge-Dlq0DSL2.js} +1 -1
- package/dist/assets/{Scheduler-BS82wfRP.js → Scheduler-CdwNo2AT.js} +1 -1
- package/dist/assets/{Settings-DWPHJ94d.js → Settings-BMy1KcDY.js} +1 -1
- package/dist/assets/{SkillReferenceGraph-Cf2M7YNq.js → SkillReferenceGraph-CqngCjO5.js} +1 -1
- package/dist/assets/{Skills-DLq55Odf.js → Skills-DCoKjG_1.js} +1 -1
- package/dist/assets/{SourceChip-CHxAzRlD.js → SourceChip-mjf4AO7V.js} +1 -1
- package/dist/assets/{SystemPrompt-BYtKMAr3.js → SystemPrompt-BDv0OwoH.js} +1 -1
- package/dist/assets/{TiptapBody-O_Gfq0Ha.js → TiptapBody-BdPKStNP.js} +1 -1
- package/dist/assets/{Toggle-BJOUI5NY.js → Toggle-CaLQyunk.js} +1 -1
- package/dist/assets/{ViewTabs-kkvNGu-S.js → ViewTabs-DVLIAjik.js} +1 -1
- package/dist/assets/{VoiceButton-3i-6ju2L.js → VoiceButton-CUXKeY0C.js} +1 -1
- package/dist/assets/{historyTotals-CHrIptK1.js → historyTotals-07_oiLDE.js} +1 -1
- package/dist/assets/{index-CjQ_p5y7.css → index-62tyjEQB.css} +1 -1
- package/dist/assets/index-CgSMvkqr.js +3116 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +412 -412
- package/package.json +1 -1
- package/plugins/CLAUDE.md +2 -0
- package/plugins/packs/apple-design/.claude-plugin/plugin.json +6 -0
- package/plugins/packs/apple-design/laws.md +14 -0
- package/plugins/packs/apple-design/skills/hig-layout-and-accessibility/SKILL.md +152 -0
- package/plugins/packs/apple-design/skills/liquid-glass-adoption/SKILL.md +132 -0
- package/plugins/packs/apple-design/sm-pack.json +5 -0
- package/plugins/packs/apple-swift-core/.claude-plugin/plugin.json +12 -0
- package/plugins/packs/apple-swift-core/laws.md +13 -0
- package/plugins/packs/apple-swift-core/skills/swift-concurrency/SKILL.md +160 -0
- package/plugins/packs/apple-swift-core/skills/swiftui-state-and-navigation/SKILL.md +165 -0
- package/plugins/packs/apple-swift-core/sm-pack.json +5 -0
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +23 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +9 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +5 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +100 -5
- package/plugins/session-manager-dev/skills/send-feedback/SKILL.md +52 -3
- package/scripts/scheduler-mcp-server.cjs +71 -5
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +26 -2
- package/src/main/index.cjs +4 -0
- package/src/main/ipcSchemas.cjs +13 -0
- package/src/main/lib/claude/agentModelResolve.cjs +23 -0
- package/src/main/lib/epic/epicMint.cjs +12 -6
- package/src/main/lib/epic/promptSessionsCreateEpic.cjs +8 -4
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +204 -8
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +375 -0
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +2 -0
- package/src/main/lib/mcpToolCatalog.cjs +40 -4
- package/src/main/lib/mdNetworkScan.cjs +61 -11
- package/src/main/lib/mdReviewRecord.cjs +287 -0
- package/src/main/lib/packs/packCatalog.cjs +120 -0
- package/src/main/lib/packs/packSpawnArgs.cjs +59 -0
- package/src/main/lib/packs/packsIpc.cjs +76 -0
- package/src/main/lib/persona-macro/builtinMacros.cjs +3 -2
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/prdCreate.cjs +2 -2
- package/src/main/lib/promptSessionSchema.cjs +8 -0
- package/src/main/projectPages.cjs +19 -0
- package/src/main/promptSessionEvents.cjs +8 -1
- package/src/main/scheduler.cjs +23 -2
- package/src/preload/api.d.ts +71 -0
- package/src/preload/apiSurface.json +21 -0
- package/src/preload/index.cjs +7 -0
- package/src/seed/agents/demo-video-builder.md +5 -3
- package/dist/assets/index-D9qgN9_V.js +0 -3116
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* crossProjectReply.cjs — the RETURN LEG of the project-to-project conduit.
|
|
5
|
+
*
|
|
6
|
+
* crossProjectFeedback.cjs mints a `proposed` Epic Y in Project-B for a
|
|
7
|
+
* finding sent from Epic X in Project-A, and stamps Y with
|
|
8
|
+
* `source.replyTo = { cwd, epicId, claudeSessionId }` — the thread back to X.
|
|
9
|
+
* This module lets the session running Y answer INTO X rather than open yet
|
|
10
|
+
* another proposed session in Project-A: the reply lands as an event on X's
|
|
11
|
+
* chain (notice 'cross-project-reply') plus X's next chat prompt, which
|
|
12
|
+
* resumes X's own Claude session even when its tab is closed.
|
|
13
|
+
*
|
|
14
|
+
* THE THREAD RULE. A reply may only go to the one Epic that asked:
|
|
15
|
+
* - the replying Epic Y is resolved ONLY from the caller's
|
|
16
|
+
* originClaudeSessionId (set by chatRunner for interactive chat runs,
|
|
17
|
+
* never for scheduler jobs) — never from an agent-supplied Epic id;
|
|
18
|
+
* - Y must be a cross-project-feedback Epic carrying a complete replyTo;
|
|
19
|
+
* anything else is a NEW request, which is feedback_open_session's job;
|
|
20
|
+
* - the target is replyTo.epicId and nothing else (toEpicId may only
|
|
21
|
+
* restate it);
|
|
22
|
+
* - at most MAX_REPLIES_PER_THREAD replies per Y, serialized per Y in
|
|
23
|
+
* memory, so two agents bouncing replies cannot loop forever.
|
|
24
|
+
* The reply is sent through chatRunner.enqueueExternalPrompt with no human
|
|
25
|
+
* origin, so it is never recorded in humanPromptLedger and can never be
|
|
26
|
+
* replayed as an autoStart humanRequestQuote.
|
|
27
|
+
*
|
|
28
|
+
* Single-writer law: every write goes through promptSessionEvents.cjs's
|
|
29
|
+
* appendResponseEventWithReason (writer 'scheduler', the existing
|
|
30
|
+
* active-index.json delegation). Reads use epicMint.cjs's readActiveIndex.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const fs = require('node:fs');
|
|
34
|
+
const path = require('node:path');
|
|
35
|
+
|
|
36
|
+
const config = require('../../config.cjs');
|
|
37
|
+
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
38
|
+
const { readActiveIndex } = require('../epic/epicMint.cjs');
|
|
39
|
+
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
40
|
+
const { resolveProjectContext } = require('../projectRootResolve.cjs');
|
|
41
|
+
|
|
42
|
+
/** crossProjectFeedback.cjs is required lazily: its fallback path may require
|
|
43
|
+
* this module, and a top-level require both ways would hand one side a
|
|
44
|
+
* half-built exports object. */
|
|
45
|
+
function feedbackConduit() {
|
|
46
|
+
return require('./crossProjectFeedback.cjs');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const MAX_REPLIES_PER_THREAD = 3;
|
|
50
|
+
const REPLY_OUTCOMES = Object.freeze(['done', 'blocked', 'question']);
|
|
51
|
+
const RECEIPT_NOTICE = 'cross-project-reply-sent';
|
|
52
|
+
const REPLY_NOTICE = 'cross-project-reply';
|
|
53
|
+
const FALLBACK_NOTICE = 'cross-project-reply-fallback';
|
|
54
|
+
|
|
55
|
+
/** Per-Y promise chain: cap check → deliver → receipt run one at a time. */
|
|
56
|
+
const threadLocks = new Map();
|
|
57
|
+
|
|
58
|
+
function withThreadLock(key, fn) {
|
|
59
|
+
const prev = threadLocks.get(key) || Promise.resolve();
|
|
60
|
+
const run = prev.then(fn, fn);
|
|
61
|
+
const tail = run.then(() => {}, () => {});
|
|
62
|
+
threadLocks.set(key, tail);
|
|
63
|
+
tail.then(() => { if (threadLocks.get(key) === tail) threadLocks.delete(key); });
|
|
64
|
+
return run;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function bad(status, error, extra = {}) {
|
|
68
|
+
return { ok: false, status, error, ...extra };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function singleLine(s) {
|
|
72
|
+
return String(s ?? '').replace(/\r?\n/g, ' ').trim();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function realOr(p) {
|
|
76
|
+
try { return fs.realpathSync(p); } catch { return p; }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* composeReplyPrompt({ fromCwd, fromEpicId, fromGoalText, outcome, message,
|
|
81
|
+
* referencePaths }) → string. Pure. The framing tells X's agent the text came
|
|
82
|
+
* from an agent elsewhere, not from its human.
|
|
83
|
+
*/
|
|
84
|
+
function composeReplyPrompt({ fromCwd, fromEpicId, fromGoalText, outcome, message, referencePaths = [] }) {
|
|
85
|
+
const cwd = singleLine(fromCwd);
|
|
86
|
+
const base = path.basename(cwd) || cwd;
|
|
87
|
+
const goal = singleLine(fromGoalText);
|
|
88
|
+
const lines = [
|
|
89
|
+
`REPLY FROM ANOTHER PROJECT: ${base} (${cwd}), session ${singleLine(fromEpicId)}`
|
|
90
|
+
+ `${goal ? ` — "${goal}"` : ''} — outcome: ${outcome}.`,
|
|
91
|
+
'Nobody in this project wrote this. An agent in that project did, and it may be wrong about '
|
|
92
|
+
+ 'this codebase — verify before acting.',
|
|
93
|
+
'',
|
|
94
|
+
String(message).trim(),
|
|
95
|
+
];
|
|
96
|
+
if (referencePaths.length) {
|
|
97
|
+
lines.push('');
|
|
98
|
+
for (const p of referencePaths) lines.push(`Reference: ${singleLine(p)}`);
|
|
99
|
+
}
|
|
100
|
+
return lines.join('\n');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function validateReplyInput(input) {
|
|
104
|
+
if (!input || typeof input !== 'object') return bad(400, 'body must be an object');
|
|
105
|
+
const { MAX_BODY_CHARS, MAX_REFERENCES } = feedbackConduit();
|
|
106
|
+
const message = typeof input.message === 'string' ? input.message.trim() : '';
|
|
107
|
+
if (!message) return bad(400, 'message is required');
|
|
108
|
+
if (message.length > MAX_BODY_CHARS) {
|
|
109
|
+
return bad(400, `message is ${message.length} chars; cap is ${MAX_BODY_CHARS}`);
|
|
110
|
+
}
|
|
111
|
+
if (!REPLY_OUTCOMES.includes(input.outcome)) {
|
|
112
|
+
return bad(400, `outcome must be one of ${REPLY_OUTCOMES.join(' | ')}`);
|
|
113
|
+
}
|
|
114
|
+
let referencePaths = [];
|
|
115
|
+
if (input.referencePaths !== undefined && input.referencePaths !== null) {
|
|
116
|
+
if (!Array.isArray(input.referencePaths) || !input.referencePaths.every((p) => typeof p === 'string')) {
|
|
117
|
+
return bad(400, 'referencePaths must be an array of strings');
|
|
118
|
+
}
|
|
119
|
+
if (input.referencePaths.length > MAX_REFERENCES) {
|
|
120
|
+
return bad(400, `too many referencePaths (${input.referencePaths.length}); cap is ${MAX_REFERENCES}`);
|
|
121
|
+
}
|
|
122
|
+
referencePaths = input.referencePaths.slice();
|
|
123
|
+
}
|
|
124
|
+
return { ok: true, value: { message, outcome: input.outcome, referencePaths } };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function defaultSendPrompt(tabId, prompt, extra) {
|
|
128
|
+
return require('../../chatRunner.cjs').enqueueExternalPrompt(tabId, prompt, extra);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function defaultAppendEvent(cwd, epicId, text, meta) {
|
|
132
|
+
return require('../../promptSessionEvents.cjs').appendResponseEventWithReason(cwd, epicId, text, meta);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function defaultResolveEpicId(cwd, claudeSessionId) {
|
|
136
|
+
return require('../prd/prdCreate.cjs').resolveSourcePromptIdFromClaudeSession(cwd, claudeSessionId);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The request Y was opened with: its title (goalText), source.proposal, and
|
|
140
|
+
* the sources of its 'reference' intake sections. */
|
|
141
|
+
function originalRequest(y) {
|
|
142
|
+
const sections = Array.isArray(y.sections) ? y.sections : [];
|
|
143
|
+
return {
|
|
144
|
+
title: typeof y.goalText === 'string' ? y.goalText : '',
|
|
145
|
+
proposal: (y.source && y.source.proposal && typeof y.source.proposal === 'object') ? y.source.proposal : {},
|
|
146
|
+
referencePaths: sections
|
|
147
|
+
.filter((s) => s && s.part === 'reference' && typeof s.source === 'string' && s.source)
|
|
148
|
+
.map((s) => s.source),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function countReceipts(cwd, epicId) {
|
|
153
|
+
const events = readActiveIndex(cwd).events[epicId];
|
|
154
|
+
return Array.isArray(events) ? events.filter((e) => e && e.notice === RECEIPT_NOTICE).length : 0;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* sendFeedbackReply(input, deps) → Promise<result>
|
|
159
|
+
*
|
|
160
|
+
* input: { message, outcome, referencePaths?, toEpicId?, fromCwd,
|
|
161
|
+
* originProjectRoot?, originClaudeSessionId }
|
|
162
|
+
* deps: { sendPrompt, appendEvent, resolveEpicId, appendAudit, openFallback }
|
|
163
|
+
* openFallback defaults to crossProjectFeedback.openReplyFallbackSession;
|
|
164
|
+
* pass null to get a 409 fallbackNeeded instead.
|
|
165
|
+
*/
|
|
166
|
+
async function sendFeedbackReply(input, deps = {}) {
|
|
167
|
+
const sendPrompt = deps.sendPrompt || defaultSendPrompt;
|
|
168
|
+
const appendEvent = deps.appendEvent || defaultAppendEvent;
|
|
169
|
+
const resolveEpicId = deps.resolveEpicId || defaultResolveEpicId;
|
|
170
|
+
const audit = deps.appendAudit || appendAuditEvent;
|
|
171
|
+
|
|
172
|
+
// 1. Validation.
|
|
173
|
+
const valid = validateReplyInput(input);
|
|
174
|
+
if (!valid.ok) return valid;
|
|
175
|
+
const { message, outcome, referencePaths } = valid.value;
|
|
176
|
+
|
|
177
|
+
// 2. Identity — Y comes ONLY from the caller's chat session id.
|
|
178
|
+
const originClaudeSessionId = typeof input.originClaudeSessionId === 'string' ? input.originClaudeSessionId : '';
|
|
179
|
+
const rawCwd = input.originProjectRoot || input.fromCwd;
|
|
180
|
+
if (!originClaudeSessionId || !rawCwd || typeof rawCwd !== 'string') {
|
|
181
|
+
return bad(403, 'feedback_reply needs the calling chat session identity; scheduled jobs and unidentified callers cannot reply');
|
|
182
|
+
}
|
|
183
|
+
const replierCwd = resolveProjectContext({ cwd: rawCwd }).cwd;
|
|
184
|
+
let yId = null;
|
|
185
|
+
try {
|
|
186
|
+
yId = replierCwd ? resolveEpicId(replierCwd, originClaudeSessionId) : null;
|
|
187
|
+
} catch {
|
|
188
|
+
yId = null;
|
|
189
|
+
}
|
|
190
|
+
if (!yId) return bad(403, 'no Epic in the calling project owns this chat session — cannot reply');
|
|
191
|
+
const yIndex = readActiveIndex(replierCwd);
|
|
192
|
+
const y = yIndex.sessions[yId];
|
|
193
|
+
if (!y) return bad(403, 'no Epic in the calling project owns this chat session — cannot reply');
|
|
194
|
+
|
|
195
|
+
// 3. Thread.
|
|
196
|
+
const src = y.source || {};
|
|
197
|
+
const rt = src.replyTo;
|
|
198
|
+
const threadComplete = src.producer === 'cross-project-feedback' && rt && typeof rt === 'object'
|
|
199
|
+
&& typeof rt.cwd === 'string' && rt.cwd
|
|
200
|
+
&& typeof rt.epicId === 'string' && rt.epicId
|
|
201
|
+
&& typeof rt.claudeSessionId === 'string' && rt.claudeSessionId;
|
|
202
|
+
if (!threadComplete) {
|
|
203
|
+
return bad(400, 'this session is not answering a cross-project request with a reply thread — '
|
|
204
|
+
+ 'a new request to another project goes through feedback_open_session');
|
|
205
|
+
}
|
|
206
|
+
if (input.toEpicId !== undefined && input.toEpicId !== null && input.toEpicId !== rt.epicId) {
|
|
207
|
+
return bad(403, `this session may only reply to Epic ${rt.epicId}, the one that asked`);
|
|
208
|
+
}
|
|
209
|
+
let targetCwd;
|
|
210
|
+
try {
|
|
211
|
+
targetCwd = config.validatePath(path.resolve(rt.cwd));
|
|
212
|
+
} catch (e) {
|
|
213
|
+
return bad(400, `replyTo.cwd rejected: ${e.message}`);
|
|
214
|
+
}
|
|
215
|
+
if (!feedbackConduit().isSessionManagerProject(targetCwd)) {
|
|
216
|
+
return bad(400, `${targetCwd} is not a Session Manager project`);
|
|
217
|
+
}
|
|
218
|
+
if (realOr(targetCwd) === realOr(path.resolve(replierCwd))) {
|
|
219
|
+
return bad(400, 'replyTo points at the replying project itself — use /develop inside this Epic');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return withThreadLock(`${realOr(replierCwd)}\u0000${yId}`, async () => {
|
|
223
|
+
// 4. Cap.
|
|
224
|
+
const sent = countReceipts(replierCwd, yId);
|
|
225
|
+
if (sent >= MAX_REPLIES_PER_THREAD) {
|
|
226
|
+
return bad(429, `reply limit of ${MAX_REPLIES_PER_THREAD} reached for this thread`);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// The fallback (default: crossProjectFeedback.openReplyFallbackSession,
|
|
230
|
+
// the only cross-project mint authority) opens a NEW proposed Epic in the
|
|
231
|
+
// asking project. `openFallback: null` disables it (409 fallbackNeeded).
|
|
232
|
+
const openFallback = Object.prototype.hasOwnProperty.call(deps, 'openFallback')
|
|
233
|
+
? deps.openFallback
|
|
234
|
+
: (args) => feedbackConduit().openReplyFallbackSession(args);
|
|
235
|
+
const fallback = async (reason) => {
|
|
236
|
+
if (typeof openFallback !== 'function') {
|
|
237
|
+
return bad(409, `the asking Epic cannot take a reply: ${reason}`, { fallbackNeeded: true, reason });
|
|
238
|
+
}
|
|
239
|
+
const opened = await openFallback({
|
|
240
|
+
reason,
|
|
241
|
+
toCwd: targetCwd,
|
|
242
|
+
toEpicId: rt.epicId,
|
|
243
|
+
fromCwd: replierCwd,
|
|
244
|
+
fromEpicId: yId,
|
|
245
|
+
message,
|
|
246
|
+
outcome,
|
|
247
|
+
referencePaths,
|
|
248
|
+
originClaudeSessionId,
|
|
249
|
+
original: originalRequest(y),
|
|
250
|
+
});
|
|
251
|
+
if (!opened || !opened.ok || typeof opened.epicId !== 'string') return opened;
|
|
252
|
+
const project = path.basename(targetCwd);
|
|
253
|
+
// Receipt on Y — counts toward the per-thread cap like a delivered reply.
|
|
254
|
+
await appendEvent(replierCwd, yId,
|
|
255
|
+
`Reply to ${rt.epicId} in ${project} fell back to a new proposed session ${opened.epicId} in ${project} (${reason}).`,
|
|
256
|
+
{
|
|
257
|
+
notice: RECEIPT_NOTICE,
|
|
258
|
+
allowInactive: true,
|
|
259
|
+
reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, fallbackEpicId: opened.epicId, reason },
|
|
260
|
+
});
|
|
261
|
+
// Best-effort receipt on X, only while X is still in A's active index.
|
|
262
|
+
let receiptOnAskingEpic = false;
|
|
263
|
+
try {
|
|
264
|
+
if (readActiveIndex(targetCwd).sessions[rt.epicId]) {
|
|
265
|
+
const r = await appendEvent(targetCwd, rt.epicId,
|
|
266
|
+
`A reply from ${path.basename(replierCwd)} (${outcome}) could not be delivered here (${reason}); `
|
|
267
|
+
+ `it opened as a new proposed session ${opened.epicId}.`,
|
|
268
|
+
{ notice: FALLBACK_NOTICE, allowInactive: true, reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, fallbackEpicId: opened.epicId } });
|
|
269
|
+
receiptOnAskingEpic = !!(r && r.ok);
|
|
270
|
+
}
|
|
271
|
+
} catch { receiptOnAskingEpic = false; }
|
|
272
|
+
return {
|
|
273
|
+
ok: true,
|
|
274
|
+
delivery: 'fallback',
|
|
275
|
+
reason,
|
|
276
|
+
toCwd: targetCwd,
|
|
277
|
+
toEpicId: rt.epicId,
|
|
278
|
+
fallbackEpicId: opened.epicId,
|
|
279
|
+
receiptOnAskingEpic,
|
|
280
|
+
repliesUsed: sent + 1,
|
|
281
|
+
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// 5. Deliver.
|
|
286
|
+
const x = readActiveIndex(targetCwd).sessions[rt.epicId];
|
|
287
|
+
if (!x) return fallback('missing');
|
|
288
|
+
if (x.status !== 'active') return fallback('not-active');
|
|
289
|
+
if (x.claudeSessionId !== rt.claudeSessionId) return fallback('session-mismatch');
|
|
290
|
+
|
|
291
|
+
const prompt = composeReplyPrompt({
|
|
292
|
+
fromCwd: replierCwd,
|
|
293
|
+
fromEpicId: yId,
|
|
294
|
+
fromGoalText: y.goalText,
|
|
295
|
+
outcome,
|
|
296
|
+
message,
|
|
297
|
+
referencePaths,
|
|
298
|
+
});
|
|
299
|
+
const appended = await appendEvent(targetCwd, x.id, prompt, {
|
|
300
|
+
notice: REPLY_NOTICE,
|
|
301
|
+
reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
|
|
302
|
+
});
|
|
303
|
+
if (!appended || !appended.ok) return fallback((appended && appended.reason) || 'append-failed');
|
|
304
|
+
|
|
305
|
+
let sendResult;
|
|
306
|
+
try {
|
|
307
|
+
sendResult = await sendPrompt(x.id, prompt, { sessionId: x.claudeSessionId, cwd: x.cwd || targetCwd });
|
|
308
|
+
} catch (e) {
|
|
309
|
+
sendResult = { disposition: 'unconfirmed', reason: e && e.message ? e.message : 'send-error' };
|
|
310
|
+
}
|
|
311
|
+
const disposition = sendResult && sendResult.disposition;
|
|
312
|
+
if (disposition === 'refused') return fallback(`send-refused:${sendResult.reason || 'unknown'}`);
|
|
313
|
+
const delivery = disposition === 'sent' || disposition === 'queued' ? 'delivered' : 'event-only';
|
|
314
|
+
|
|
315
|
+
// 6. Receipt on Y (counts toward the cap).
|
|
316
|
+
await appendEvent(replierCwd, yId,
|
|
317
|
+
`Reply sent to ${x.id} in ${path.basename(targetCwd)} (${outcome}, ${delivery}).`,
|
|
318
|
+
{
|
|
319
|
+
notice: RECEIPT_NOTICE,
|
|
320
|
+
allowInactive: true,
|
|
321
|
+
reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// 7. Audit.
|
|
325
|
+
audit('epic_cross_project_reply', {
|
|
326
|
+
cwd: targetCwd,
|
|
327
|
+
epicId: x.id,
|
|
328
|
+
fromCwd: replierCwd,
|
|
329
|
+
fromEpicId: yId,
|
|
330
|
+
outcome,
|
|
331
|
+
delivery,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return {
|
|
335
|
+
ok: true,
|
|
336
|
+
delivery,
|
|
337
|
+
toCwd: targetCwd,
|
|
338
|
+
toEpicId: x.id,
|
|
339
|
+
repliesUsed: sent + 1,
|
|
340
|
+
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
341
|
+
...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
|
|
342
|
+
};
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Registers POST /admin/feedback/reply on the loopback admin transport —
|
|
347
|
+
* mirrors crossProjectFeedback.registerAdminRoute; auth is the transport's. */
|
|
348
|
+
function registerAdminRoute(adminHttp, deps) {
|
|
349
|
+
adminHttp.registerRoute('POST', '/admin/feedback/reply', async (req, res) => {
|
|
350
|
+
const raw = await readBody(req);
|
|
351
|
+
let parsed;
|
|
352
|
+
try {
|
|
353
|
+
parsed = raw ? JSON.parse(raw) : {};
|
|
354
|
+
} catch {
|
|
355
|
+
sendJson(res, 400, { ok: false, error: 'invalid JSON body' });
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
const result = await sendFeedbackReply(parsed, deps);
|
|
359
|
+
if (!result.ok) {
|
|
360
|
+
const { ok: _ok, status, ...rest } = result;
|
|
361
|
+
sendJson(res, status ?? 400, { ok: false, ...rest });
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
sendJson(res, 200, result);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
module.exports = {
|
|
369
|
+
MAX_REPLIES_PER_THREAD,
|
|
370
|
+
REPLY_OUTCOMES,
|
|
371
|
+
composeReplyPrompt,
|
|
372
|
+
validateReplyInput,
|
|
373
|
+
sendFeedbackReply,
|
|
374
|
+
registerAdminRoute,
|
|
375
|
+
};
|
|
@@ -62,6 +62,8 @@ const PATH_FENCED_CHANNELS = Object.freeze({
|
|
|
62
62
|
'promptSessions:read-session-transcript': { field: 'cwd', mode: 'root' },
|
|
63
63
|
// Project Home > Tools > Review MD network link map (main/projectPages.cjs): cwd inside a registered root.
|
|
64
64
|
'project-pages:md-network': { field: 'cwd', mode: 'root' },
|
|
65
|
+
// Project Home > Tools > Review MD network review record (main/projectPages.cjs): cwd inside a registered root.
|
|
66
|
+
'project-pages:md-review': { field: 'cwd', mode: 'root' },
|
|
65
67
|
// Project Home ▸ Tools ▸ Competitor matrix (main/projectPages.cjs): read-only, cwd inside a registered root.
|
|
66
68
|
'project-pages:matrix': { field: 'cwd', mode: 'root' },
|
|
67
69
|
// Epic Changes view (main/lib/epic/epicChanges.cjs): diffs a repo, so cwd must sit inside a registered root.
|
|
@@ -298,9 +298,34 @@ const MCP_TOOL_CATALOG = [
|
|
|
298
298
|
+ 'lands as `proposed` and runs only if a human in the RECEIVING project presses "Approve & start". '
|
|
299
299
|
+ 'With a verified autoStart + humanRequestQuote the result status is `auto-approved` and the session '
|
|
300
300
|
+ 'starts on its own; otherwise it stays proposed (check the note for the reason). '
|
|
301
|
-
+ '
|
|
302
|
-
+ '
|
|
303
|
-
+ '
|
|
301
|
+
+ 'Do not block waiting for an answer, and do not tell the user the other project has "been fixed" '
|
|
302
|
+
+ 'or "is working on it". Report only that the proposal was delivered, or that the session was '
|
|
303
|
+
+ 'auto-approved and is starting. The receiving session can answer later with feedback_reply only '
|
|
304
|
+
+ 'when the call comes from a Session Manager Epic chat session that Session Manager can identify; that '
|
|
305
|
+
+ 'answer lands in your Epic as an event and a new prompt. From a scheduled job or a plain terminal '
|
|
306
|
+
+ 'session there is no reply path — check the result note.',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: 'feedback_reply',
|
|
310
|
+
group: 'feedback',
|
|
311
|
+
purpose: 'Answer the project that asked. Only for a session that was opened by ANOTHER project\'s '
|
|
312
|
+
+ 'feedback_open_session: the reply lands in the Epic that asked — as an event on its chain plus its '
|
|
313
|
+
+ 'next chat prompt — not as a new proposed session.',
|
|
314
|
+
whenToUse: 'Use once the work the other project asked for is verified (outcome "done"), or when you are '
|
|
315
|
+
+ 'blocked or need an answer from it (outcome "blocked" / "question"). Send "done" only after the work '
|
|
316
|
+
+ 'is verified — name the commit or version in the message.',
|
|
317
|
+
whenNotToUse: 'Do not use for a NEW request to another project — that is feedback_open_session. It is refused '
|
|
318
|
+
+ 'for any other target than the Epic that asked (toEpicId may only restate it), refused in a session '
|
|
319
|
+
+ 'that was not opened by another project, and refused inside a scheduled job — a job reports in its result.',
|
|
320
|
+
exampleArgs: {
|
|
321
|
+
message: 'Fixed in commit abc1234 and released in v1.2.3; the admin API now returns field F.',
|
|
322
|
+
outcome: 'done',
|
|
323
|
+
referencePaths: ['/home/bilko/Projects/other-project/src/api.ts'],
|
|
324
|
+
},
|
|
325
|
+
notes: 'Capped at 3 replies per thread. Identity comes from this session only; it cannot be passed in. '
|
|
326
|
+
+ 'The result delivery is "delivered" (into the asking session), "event-only" (recorded on the asking '
|
|
327
|
+
+ 'Epic, its session not prompted) or "fallback" (the asking Epic could not take it, so a new proposed '
|
|
328
|
+
+ 'session opened in that project). Never report that the other project acted on the reply.',
|
|
304
329
|
},
|
|
305
330
|
{
|
|
306
331
|
name: 'project_home_write',
|
|
@@ -592,7 +617,18 @@ const MCP_RECIPES = [
|
|
|
592
617
|
steps: [
|
|
593
618
|
'Call feedback_list_projects to get the exact toCwd for the receiving project — never guess a path.',
|
|
594
619
|
'Call feedback_open_session with toCwd, fromCwd, a one-line title, and a self-contained body (symptom, where observed, expected behavior, suspected cause).',
|
|
595
|
-
'The call only delivers a PROPOSED session in the receiving project — nothing runs until a human there presses Approve & start
|
|
620
|
+
'The call only delivers a PROPOSED session in the receiving project — nothing runs until a human there presses Approve & start.',
|
|
621
|
+
'The receiving session can answer with feedback_reply only when the call comes from a Session Manager Epic chat session that Session Manager can identify; the answer lands in your Epic as an event and a new prompt.',
|
|
622
|
+
],
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
id: 'reply-to-the-project-that-asked',
|
|
626
|
+
title: 'Reply to the project that asked',
|
|
627
|
+
steps: [
|
|
628
|
+
'Confirm this session was opened by another project\'s feedback_open_session — feedback_reply refuses any other session.',
|
|
629
|
+
'Do the work and verify it (gate green, commit landed, release named if it needs one).',
|
|
630
|
+
'Call feedback_reply with message (what was done, with commit/version) and outcome "done" — or "blocked" / "question" when you cannot finish.',
|
|
631
|
+
'Read the result delivery: "delivered", "event-only" or "fallback". Report only that; never say the other project acted. At most 3 replies per thread.',
|
|
596
632
|
],
|
|
597
633
|
},
|
|
598
634
|
];
|
|
@@ -26,18 +26,24 @@
|
|
|
26
26
|
* existing. A failing git call degrades to a census warning, never an error.
|
|
27
27
|
* Docs in record collections (opts.recordFolders / heuristic) leave orphans.
|
|
28
28
|
*
|
|
29
|
-
* Followed
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* Followed — every reference an agent follows, matching the maintaining-md-network
|
|
30
|
+
* skill's link convention: inline `[text](target)` links (images too) and
|
|
31
|
+
* `<target.md>` autolinks, outside code fences, inline code and HTML comments;
|
|
32
|
+
* backticked `path.md` tokens (outside fences and comments) resolved repo-root
|
|
33
|
+
* first, then against the doc's folder; and `@path.md` imports resolved against
|
|
34
|
+
* the doc's folder. For links, ignored: any `scheme:` target (http(s):, mailto:,
|
|
35
|
+
* ...), `/absolute` and `//host` targets, and `#anchor`-only links; `#fragment`
|
|
36
|
+
* and `?query` are stripped and the rest resolves against the linking doc's
|
|
37
|
+
* folder; a target outside the project, or one that does not exist, is a broken
|
|
38
|
+
* link. A backticked path or import is an edge only when it resolves to a doc;
|
|
39
|
+
* one that resolves to nothing is never a broken link (the census lists dead
|
|
40
|
+
* backticked paths as deadRefs). Backticked non-.md paths are never edges.
|
|
35
41
|
*/
|
|
36
42
|
|
|
37
43
|
const fs = require('node:fs');
|
|
38
44
|
const path = require('node:path');
|
|
39
45
|
const { execGit } = require('./git/gitExec.cjs');
|
|
40
|
-
const { censusMdDocs, parseGitLog } = require('./mdDocCensus.cjs');
|
|
46
|
+
const { censusMdDocs, parseGitLog, importsOf } = require('./mdDocCensus.cjs');
|
|
41
47
|
const { backtickPaths, assessRefs, mentionPatterns, parseMentions } = require('./mdDocRefs.cjs');
|
|
42
48
|
|
|
43
49
|
const ROOT_DOC = 'CLAUDE.md';
|
|
@@ -67,6 +73,7 @@ const AUTOLINK_RE = /<([^<>\s]{1,1024})>/g;
|
|
|
67
73
|
/**
|
|
68
74
|
* @typedef {{ path: string, text: string }} MdFile a doc: repo-relative POSIX path + text
|
|
69
75
|
* @typedef {{ line: number, target: string, to: string, escapes: boolean }} MdLink
|
|
76
|
+
* @typedef {MdLink & { kind: 'link' | 'path' | 'import' }} MdRef a followed reference; only `link` ones can be broken
|
|
70
77
|
* `target` as written (fragment/query stripped); `to` resolved repo-relative
|
|
71
78
|
* @typedef {'hub' | 'owner' | 'doc'} MdNetworkNodeType
|
|
72
79
|
* @typedef {{ id: string, path: string, depth: number, type: MdNetworkNodeType, linksOut: number, linkedFrom: number }} MdNetworkNode
|
|
@@ -295,6 +302,45 @@ function linksOf(file) {
|
|
|
295
302
|
return links;
|
|
296
303
|
}
|
|
297
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Memo for refsOf's doc-independent parse: backticked `.md` tokens and `@` imports.
|
|
307
|
+
* @type {WeakMap<MdFile, { tokens: string[], imports: string[] }>}
|
|
308
|
+
*/
|
|
309
|
+
const pathRefMemo = new WeakMap();
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* A doc's followed references: its markdown links (kind `link`, as linksOf),
|
|
313
|
+
* then its `@` imports and backticked `.md` paths that resolve to a doc per
|
|
314
|
+
* `isDoc` (kinds `import` / `path`, line 0). A backticked token tries the
|
|
315
|
+
* repo-root form first, then the doc-relative one.
|
|
316
|
+
* @param {MdFile} file @param {(relPath: string) => boolean} isDoc
|
|
317
|
+
* @returns {MdRef[]}
|
|
318
|
+
*/
|
|
319
|
+
function refsOf(file, isDoc) {
|
|
320
|
+
const from = toRepoPath(file.path);
|
|
321
|
+
let parsed = pathRefMemo.get(file);
|
|
322
|
+
if (!parsed) {
|
|
323
|
+
parsed = {
|
|
324
|
+
tokens: backtickPaths(file.text).filter((t) => t.endsWith('.md')),
|
|
325
|
+
imports: importsOf(file.text, from),
|
|
326
|
+
};
|
|
327
|
+
pathRefMemo.set(file, parsed);
|
|
328
|
+
}
|
|
329
|
+
/** @type {MdRef[]} */
|
|
330
|
+
const refs = linksOf(file).map((l) => ({ ...l, kind: /** @type {const} */ ('link') }));
|
|
331
|
+
for (const imp of parsed.imports) {
|
|
332
|
+
const to = toRepoPath(imp);
|
|
333
|
+
if (isDoc(to)) refs.push({ line: 0, target: imp, to, escapes: false, kind: 'import' });
|
|
334
|
+
}
|
|
335
|
+
const dir = path.posix.dirname(from);
|
|
336
|
+
for (const tok of parsed.tokens) {
|
|
337
|
+
const forms = dir === '.' ? [toRepoPath(tok)] : [toRepoPath(tok), toRepoPath(path.posix.join(dir, tok))];
|
|
338
|
+
const to = forms.find((f) => f !== '..' && !f.startsWith('../') && isDoc(f));
|
|
339
|
+
if (to !== undefined) refs.push({ line: 0, target: tok, to, escapes: false, kind: 'path' });
|
|
340
|
+
}
|
|
341
|
+
return refs;
|
|
342
|
+
}
|
|
343
|
+
|
|
298
344
|
/** @param {string} id @param {number} depth @returns {MdNetworkNodeType} */
|
|
299
345
|
function nodeType(id, depth) {
|
|
300
346
|
if (depth === 0) return 'hub';
|
|
@@ -334,6 +380,8 @@ function buildMdNetwork({ files = [], root = ROOT_DOC, exists, records } = {}) {
|
|
|
334
380
|
const folders = foldersOf(docs.keys());
|
|
335
381
|
/** @param {string} p */
|
|
336
382
|
const present = (p) => p === '.' || docs.has(p) || folders.has(p) || (exists !== undefined && exists(p) === true);
|
|
383
|
+
/** @param {string} p */
|
|
384
|
+
const isDoc = (p) => docs.has(p);
|
|
337
385
|
|
|
338
386
|
/** @type {Map<string, number>} */
|
|
339
387
|
const depth = new Map([[rootPath, 0]]);
|
|
@@ -354,8 +402,8 @@ function buildMdNetwork({ files = [], root = ROOT_DOC, exists, records } = {}) {
|
|
|
354
402
|
const file = docs.get(from);
|
|
355
403
|
if (!file) continue;
|
|
356
404
|
const nextDepth = (depth.get(from) ?? 0) + 1;
|
|
357
|
-
for (const link of
|
|
358
|
-
const broken = link.escapes || !present(link.to);
|
|
405
|
+
for (const link of refsOf(file, isDoc)) {
|
|
406
|
+
const broken = link.kind === 'link' && (link.escapes || !present(link.to));
|
|
359
407
|
if (broken) {
|
|
360
408
|
const where = `${from}:${link.line} → ${link.target}`;
|
|
361
409
|
if (!findingKeys.has(where)) {
|
|
@@ -513,16 +561,18 @@ async function scanMdNetwork(cwd, deps = {}, opts = {}) {
|
|
|
513
561
|
const queued = new Set([ROOT_DOC]);
|
|
514
562
|
/** @type {Set<string>} */
|
|
515
563
|
const unvouched = new Set();
|
|
564
|
+
/** @param {string} p */
|
|
565
|
+
const isDocPath = (p) => docSet.has(p);
|
|
516
566
|
for (let wave = [rootFile]; wave.length > 0; ) {
|
|
517
567
|
/** @type {string[]} */
|
|
518
568
|
const next = [];
|
|
519
569
|
for (const file of wave) {
|
|
520
|
-
for (const link of
|
|
570
|
+
for (const link of refsOf(file, isDocPath)) {
|
|
521
571
|
if (link.escapes || queued.has(link.to)) continue;
|
|
522
572
|
if (docSet.has(link.to)) {
|
|
523
573
|
queued.add(link.to);
|
|
524
574
|
next.push(link.to);
|
|
525
|
-
} else if (link.to !== '.' && !trackedSet.has(link.to) && !trackedFolders.has(link.to)) {
|
|
575
|
+
} else if (link.kind === 'link' && link.to !== '.' && !trackedSet.has(link.to) && !trackedFolders.has(link.to)) {
|
|
526
576
|
unvouched.add(link.to);
|
|
527
577
|
}
|
|
528
578
|
}
|