claude-code-session-manager 0.137.0 → 0.139.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 +339 -82
- package/dist/assets/{AppSettings-l7NTc0yu.js → AppSettings-CUfWY9vN.js} +2 -2
- package/dist/assets/History-DDnqaLyw.js +2 -0
- package/dist/assets/HomeClaudeConfig-CGD2Onjv.js +3 -0
- package/dist/assets/{Panel-BuInRmA0.js → Panel-Csyd9HbD.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-C-jlYpC_.js +26 -0
- package/dist/assets/{Scheduler-B7sn2mUw.js → Scheduler-NLs08fx7.js} +9 -9
- package/dist/assets/{SkillReferenceGraph-DwV0Ueyc.js → SkillReferenceGraph-DcscPXAG.js} +1 -1
- package/dist/assets/Skills-BpGRKOcY.js +67 -0
- package/dist/assets/{TiptapBody-Bl8hDhhS.js → TiptapBody-DSU3769X.js} +60 -54
- package/dist/assets/ViewTabs-C0PRZx4_.js +1 -0
- package/dist/assets/{VoiceButton-DJx-jY4r.js → VoiceButton-D2rMurNg.js} +1 -1
- package/dist/assets/{historyTotals-Cgjm5q24.js → historyTotals-TcIQs2sh.js} +1 -1
- package/dist/assets/{index-62tyjEQB.css → index-BCySPdtU.css} +1 -1
- package/dist/assets/index-C-d0DCre.js +3124 -0
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +471 -452
- package/package.json +13 -5
- 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 +12 -5
- package/scripts/README.md +1 -0
- package/scripts/scheduler-mcp-server.cjs +161 -18
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +53 -2
- package/src/main/exchanges.cjs +70 -5
- package/src/main/historyAggregator.cjs +84 -58
- package/src/main/historyDashboard.cjs +18 -13
- package/src/main/index.cjs +35 -9
- package/src/main/ipcSchemas.cjs +133 -5
- package/src/main/lib/claude/effectiveModelInfo.cjs +2 -2
- package/src/main/lib/claude/modelPricing.cjs +148 -0
- package/src/main/lib/demo-video-kit/checks.cjs +16 -0
- package/src/main/lib/epic/epicAdminRoutes.cjs +101 -0
- package/src/main/lib/epic/epicAttachments.cjs +143 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicMint.cjs +4 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +306 -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/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +111 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +121 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +83 -1
- 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 +287 -1
- 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 +281 -0
- package/src/main/lib/feedback-remote/remoteFrameAssembler.cjs +113 -0
- package/src/main/lib/historyRollup.cjs +32 -5
- package/src/main/lib/mcpToolCatalog.cjs +111 -14
- package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
- package/src/main/lib/persona-macro/macroLibrary.cjs +7 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/process/bootStdioGuard.cjs +32 -0
- package/src/main/lib/process/stdioGuard.cjs +115 -0
- package/src/main/lib/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -0
- package/src/main/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loopEfficiencyHandlers.cjs +1 -1
- package/src/main/scheduler.cjs +29 -0
- package/src/main/templates/PRD_AUTHORING.md +1 -0
- package/src/main/transcripts.cjs +62 -7
- package/src/main/webRemote.cjs +122 -18
- package/src/preload/api.d.ts +98 -9
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +415 -83
- package/src/preload/index.cjs +17 -3
- package/src/seed/agents/demo-video-builder.md +10 -7
- package/dist/assets/AgentLibrary-DV0DTZDC.js +0 -2
- package/dist/assets/Button-Cmfkgjfa.js +0 -1
- package/dist/assets/DocumentEditorPane-MTljV-Uw.js +0 -1
- package/dist/assets/Extensions-Cc1Q_8id.js +0 -2
- package/dist/assets/History-CFo-1DHo.js +0 -2
- package/dist/assets/Library-C_ibFiOx.js +0 -32
- package/dist/assets/ListDetail-ByULG209.js +0 -1
- package/dist/assets/ProjectClaudeConfig-yqqVtHY7.js +0 -25
- package/dist/assets/ProvenanceBadge-CJvnQReI.js +0 -1
- package/dist/assets/Settings-DRRSJksU.js +0 -2
- package/dist/assets/Skills-DVYHA9gV.js +0 -29
- package/dist/assets/SourceChip-DfJ5_5rV.js +0 -1
- package/dist/assets/SystemPrompt-f11wGllK.js +0 -1
- package/dist/assets/Toggle-DaxeFDFp.js +0 -1
- package/dist/assets/ViewTabs-DRtgFKRw.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-iQ6pdyuS.js +0 -3116
|
@@ -86,6 +86,8 @@ const {
|
|
|
86
86
|
MINT_AUTHORITY_CROSS_PROJECT_FEEDBACK,
|
|
87
87
|
} = require('../epic/epicMint.cjs');
|
|
88
88
|
const { appendAuditEvent } = require('../telemetry/auditLog.cjs');
|
|
89
|
+
const { normalizeExternalRef } = require('../epic/externalRef.cjs');
|
|
90
|
+
const { recordExternalRef, findEpicByExternalRef, withExternalRefLock } = require('../epic/externalRefIndex.cjs');
|
|
89
91
|
const { OPS_ROOT_DIR, opsPath } = require('../opsOwnership.cjs');
|
|
90
92
|
const { readJsonOrSync } = require('../util/atomicFs.cjs');
|
|
91
93
|
const { resolveProjectContext } = require('../projectRootResolve.cjs');
|
|
@@ -199,7 +201,27 @@ function resolveReplyTo(fromCwd, fromEpicId) {
|
|
|
199
201
|
return { cwd: fromCwd, epicId: fromEpicId, claudeSessionId };
|
|
200
202
|
}
|
|
201
203
|
|
|
204
|
+
/** How the asking side wants a reply delivered: 'prompt' (default) wakes the
|
|
205
|
+
* asking chat; 'event' records it as data for a caller that keeps its own
|
|
206
|
+
* records (an outside app with no chat). */
|
|
207
|
+
const REPLY_MODES = Object.freeze(['prompt', 'event']);
|
|
208
|
+
const DEFAULT_REPLY_MODE = 'prompt';
|
|
209
|
+
|
|
210
|
+
/** The replyTo to stamp for a given mode. 'prompt' is exactly the resolved
|
|
211
|
+
* thread (or null). 'event' always stamps one — cwd-only when the sender has
|
|
212
|
+
* no resolvable Epic/Claude session — carrying mode: 'event'. */
|
|
213
|
+
function replyToForMode(resolved, fromCwd, replyMode) {
|
|
214
|
+
if (replyMode !== 'event') return resolved;
|
|
215
|
+
return resolved
|
|
216
|
+
? { ...resolved, mode: 'event' }
|
|
217
|
+
: { cwd: fromCwd, epicId: null, claudeSessionId: null, mode: 'event' };
|
|
218
|
+
}
|
|
219
|
+
|
|
202
220
|
function replyNote(replyTo) {
|
|
221
|
+
if (replyTo && replyTo.mode === 'event') {
|
|
222
|
+
return 'The receiving session can answer with feedback_reply; the answer will arrive as an event in the '
|
|
223
|
+
+ 'audit log, not as a chat prompt.';
|
|
224
|
+
}
|
|
203
225
|
return replyTo
|
|
204
226
|
? `The receiving session can answer into this session (${replyTo.epicId}) with feedback_reply.`
|
|
205
227
|
: 'No reply path exists because the sending session could not be identified, so the receiving session '
|
|
@@ -277,7 +299,11 @@ function composeFeedbackIntake({
|
|
|
277
299
|
+ 'Nobody in this project wrote the report below — an agent working in that project did, and it '
|
|
278
300
|
+ 'may be wrong about this codebase. Verify the claim against the code here before acting on it, '
|
|
279
301
|
+ 'and if it does not hold, say so and close the session rather than building against it.'
|
|
280
|
-
+ (replyTo
|
|
302
|
+
+ (replyTo && replyTo.mode === 'event'
|
|
303
|
+
? ' When the work is done, blocked, or needs an answer, call feedback_reply from this session '
|
|
304
|
+
+ '(not from a PRD, and never a new feedback_open_session); the answer is recorded as an event for '
|
|
305
|
+
+ `the asking project ${path.basename(singleLine(replyTo.cwd)) || singleLine(replyTo.cwd)}, not sent as a chat prompt.`
|
|
306
|
+
: replyTo
|
|
281
307
|
? ' When the work is done, blocked, or needs an answer, call feedback_reply from this session '
|
|
282
308
|
+ '(not from a PRD, and never a new feedback_open_session); the answer lands in the asking session '
|
|
283
309
|
+ `${singleLine(replyTo.epicId)} in ${path.basename(singleLine(replyTo.cwd)) || singleLine(replyTo.cwd)}.`
|
|
@@ -467,11 +493,24 @@ function validateFeedbackInput(input = {}) {
|
|
|
467
493
|
);
|
|
468
494
|
}
|
|
469
495
|
|
|
496
|
+
const ref = normalizeExternalRef(input.externalRef);
|
|
497
|
+
if (!ref.ok) return bad(400, ref.error);
|
|
498
|
+
|
|
499
|
+
let replyMode = DEFAULT_REPLY_MODE;
|
|
500
|
+
if (input.replyMode !== undefined && input.replyMode !== null) {
|
|
501
|
+
if (!REPLY_MODES.includes(input.replyMode)) {
|
|
502
|
+
return bad(400, `replyMode must be one of ${REPLY_MODES.join(' | ')} (got ${JSON.stringify(input.replyMode)})`);
|
|
503
|
+
}
|
|
504
|
+
replyMode = input.replyMode;
|
|
505
|
+
}
|
|
506
|
+
|
|
470
507
|
return {
|
|
471
508
|
ok: true,
|
|
472
509
|
value: {
|
|
473
510
|
toCwd,
|
|
474
511
|
fromCwd,
|
|
512
|
+
externalRef: ref.value,
|
|
513
|
+
replyMode,
|
|
475
514
|
title,
|
|
476
515
|
body,
|
|
477
516
|
tag,
|
|
@@ -624,7 +663,78 @@ async function openFeedbackSession(input, deps = {}) {
|
|
|
624
663
|
const checked = validateFeedbackInput(input);
|
|
625
664
|
if (!checked.ok) return checked;
|
|
626
665
|
const v = checked.value;
|
|
666
|
+
const collaborators = { mint, appendReceipt, notify, audit: deps.appendAudit || appendAuditEvent };
|
|
667
|
+
|
|
668
|
+
if (!v.externalRef) return mintFeedbackSession(v, input, deps, collaborators);
|
|
669
|
+
|
|
670
|
+
// Lookup + mint under one per-(toCwd, ref) lock, so concurrent repeats of
|
|
671
|
+
// one handoff produce one Epic. A repeat mints nothing, spends no macro
|
|
672
|
+
// auto-start grant, and writes no receipt or audit row.
|
|
673
|
+
const externalRef = v.externalRef;
|
|
674
|
+
return withExternalRefLock({ cwd: v.toCwd, externalRef }, async () => {
|
|
675
|
+
const found = await findEpicByExternalRef({ cwd: v.toCwd, externalRef });
|
|
676
|
+
if (found) {
|
|
677
|
+
if (found.producer !== FEEDBACK_PRODUCER || found.fromCwd !== v.fromCwd) {
|
|
678
|
+
return {
|
|
679
|
+
ok: false,
|
|
680
|
+
status: 409,
|
|
681
|
+
error: `externalRef ${JSON.stringify(externalRef)} already names Epic ${found.epicId} in ${v.toCwd}, `
|
|
682
|
+
+ 'opened by a different sender. Use a different externalRef.',
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
ok: true,
|
|
687
|
+
epicId: found.epicId,
|
|
688
|
+
status: 'existing',
|
|
689
|
+
existing: true,
|
|
690
|
+
externalRef,
|
|
691
|
+
toCwd: v.toCwd,
|
|
692
|
+
fromCwd: v.fromCwd,
|
|
693
|
+
note: `This externalRef was already handed off: Epic ${found.epicId} in the receiving project`
|
|
694
|
+
+ `${found.open ? ' is still open' : ' is no longer open (completed)'}. No new session was opened.`,
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
const result = await mintFeedbackSession(v, input, deps, collaborators);
|
|
698
|
+
if (result.ok) {
|
|
699
|
+
const recorded = await recordExternalRefWithRetry(
|
|
700
|
+
deps.recordExternalRef || recordExternalRef,
|
|
701
|
+
{ cwd: v.toCwd, externalRef, epicId: result.epicId, producer: FEEDBACK_PRODUCER, fromCwd: v.fromCwd },
|
|
702
|
+
'[crossProjectFeedback]',
|
|
703
|
+
);
|
|
704
|
+
// The Epic exists either way; say plainly that a repeat may not find it.
|
|
705
|
+
if (!recorded) return { ...result, externalRefRecorded: false };
|
|
706
|
+
}
|
|
707
|
+
return result;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* recordExternalRefWithRetry(record, args, logTag) → Promise<boolean>
|
|
713
|
+
*
|
|
714
|
+
* Runs after a successful mint, so a failure must never fail the call: try
|
|
715
|
+
* once, retry once, then warn and report false so the caller can add
|
|
716
|
+
* `externalRefRecorded: false` to its success answer.
|
|
717
|
+
*/
|
|
718
|
+
async function recordExternalRefWithRetry(record, args, logTag) {
|
|
719
|
+
let lastErr;
|
|
720
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
721
|
+
try {
|
|
722
|
+
await record(args);
|
|
723
|
+
return true;
|
|
724
|
+
} catch (e) {
|
|
725
|
+
lastErr = e;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
console.warn(`${logTag} recordExternalRef failed twice for ${JSON.stringify(args.externalRef)} → ${args.epicId}:`,
|
|
729
|
+
lastErr?.message ?? lastErr);
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
const FEEDBACK_PRODUCER = 'cross-project-feedback';
|
|
627
734
|
|
|
735
|
+
/** The validated half of openFeedbackSession: auto-start accounting, mint,
|
|
736
|
+
* audit, notify, receipt. */
|
|
737
|
+
async function mintFeedbackSession(v, input, deps, { mint, appendReceipt, notify, audit }) {
|
|
628
738
|
const originClaudeSessionId =
|
|
629
739
|
typeof input.originClaudeSessionId === 'string' && input.originClaudeSessionId
|
|
630
740
|
? input.originClaudeSessionId
|
|
@@ -660,7 +770,7 @@ async function openFeedbackSession(input, deps = {}) {
|
|
|
660
770
|
}
|
|
661
771
|
|
|
662
772
|
const originAsk = resolveOriginAsk(v.fromCwd, v.fromEpicId);
|
|
663
|
-
const replyTo = resolveReplyTo(v.fromCwd, v.fromEpicId);
|
|
773
|
+
const replyTo = replyToForMode(resolveReplyTo(v.fromCwd, v.fromEpicId), v.fromCwd, v.replyMode);
|
|
664
774
|
|
|
665
775
|
const { goalText, openingPrompt, sections } = composeFeedbackIntake({
|
|
666
776
|
fromCwd: v.fromCwd,
|
|
@@ -692,8 +802,9 @@ async function openFeedbackSession(input, deps = {}) {
|
|
|
692
802
|
openingPrompt,
|
|
693
803
|
sections,
|
|
694
804
|
source: {
|
|
695
|
-
producer:
|
|
805
|
+
producer: FEEDBACK_PRODUCER,
|
|
696
806
|
fromCwd: v.fromCwd,
|
|
807
|
+
...(v.externalRef ? { externalRef: v.externalRef } : {}),
|
|
697
808
|
...(v.fromEpicId ? { fromEpicId: v.fromEpicId } : {}),
|
|
698
809
|
...(replyTo ? { replyTo } : {}),
|
|
699
810
|
...(auto.granted
|
|
@@ -733,7 +844,7 @@ async function openFeedbackSession(input, deps = {}) {
|
|
|
733
844
|
return { ok: false, status: 500, error: `could not open the feedback session: ${e.message}` };
|
|
734
845
|
}
|
|
735
846
|
|
|
736
|
-
|
|
847
|
+
audit('epic_cross_project_feedback', {
|
|
737
848
|
cwd: v.toCwd,
|
|
738
849
|
epicId: minted.epicId,
|
|
739
850
|
fromCwd: v.fromCwd,
|
|
@@ -777,12 +888,15 @@ async function openFeedbackSession(input, deps = {}) {
|
|
|
777
888
|
toCwd: v.toCwd,
|
|
778
889
|
fromCwd: v.fromCwd,
|
|
779
890
|
tag: v.tag,
|
|
891
|
+
...(v.externalRef ? { externalRef: v.externalRef } : {}),
|
|
780
892
|
status: auto.granted ? 'auto-approved' : 'proposed',
|
|
781
893
|
...(v.autoStart || macroAuto ? { autoStart: auto.granted ? { granted: true } : { granted: false, reason: auto.reason } } : {}),
|
|
782
894
|
receiptOnOriginEpic,
|
|
783
895
|
// True only when source.replyTo was stamped — the MCP note keys its
|
|
784
896
|
// feedback_reply promise off this, never off the delivery alone.
|
|
785
897
|
replyThread: Boolean(replyTo),
|
|
898
|
+
// Always echoed so every caller can confirm the mode it got.
|
|
899
|
+
replyMode: v.replyMode,
|
|
786
900
|
// Say plainly what did NOT happen, same posture as create-prd's
|
|
787
901
|
// `enqueued: false` — never let a caller report this as "work started".
|
|
788
902
|
note: (macroGranted
|
|
@@ -1097,8 +1211,11 @@ module.exports = {
|
|
|
1097
1211
|
composeFeedbackIntake,
|
|
1098
1212
|
resolveOriginAsk,
|
|
1099
1213
|
resolveReplyTo,
|
|
1214
|
+
REPLY_MODES,
|
|
1215
|
+
DEFAULT_REPLY_MODE,
|
|
1100
1216
|
validateFeedbackInput,
|
|
1101
1217
|
openFeedbackSession,
|
|
1218
|
+
recordExternalRefWithRetry,
|
|
1102
1219
|
readEpicGoal,
|
|
1103
1220
|
openReplyFallbackSession,
|
|
1104
1221
|
listFeedbackTargets,
|
|
@@ -54,6 +54,11 @@ const REPLY_OUTCOMES = Object.freeze(['done', 'blocked', 'question']);
|
|
|
54
54
|
const RECEIPT_NOTICE = 'cross-project-reply-sent';
|
|
55
55
|
const REPLY_NOTICE = 'cross-project-reply';
|
|
56
56
|
const FALLBACK_NOTICE = 'cross-project-reply-fallback';
|
|
57
|
+
/** Event mode (source.replyTo.mode 'event'): the asker keeps its own records,
|
|
58
|
+
* so the reply is data in the audit row — never a chat prompt or a fallback. */
|
|
59
|
+
const EVENT_MODE_REASON = 'asker-requested-event';
|
|
60
|
+
const AUDIT_MESSAGE_CHARS = 2000;
|
|
61
|
+
const AUDIT_MAX_REFERENCES = 10;
|
|
57
62
|
|
|
58
63
|
/** Per-Y promise chain: cap check → deliver → receipt run one at a time. */
|
|
59
64
|
const threadLocks = new Map();
|
|
@@ -219,6 +224,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
219
224
|
if (!resolved.ok) return bad(400, resolved.error);
|
|
220
225
|
const rt = resolved.thread;
|
|
221
226
|
const legacy = resolved.legacy;
|
|
227
|
+
const eventMode = resolved.mode === 'event';
|
|
222
228
|
const threadField = legacy ? { thread: 'legacy' } : {};
|
|
223
229
|
if (input.toEpicId !== undefined && input.toEpicId !== null && input.toEpicId !== rt.epicId) {
|
|
224
230
|
return bad(403, `this session may only reply to Epic ${rt.epicId}, the one that asked`);
|
|
@@ -243,6 +249,13 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
243
249
|
return bad(429, `reply limit of ${MAX_REPLIES_PER_THREAD} reached for this thread`);
|
|
244
250
|
}
|
|
245
251
|
|
|
252
|
+
if (eventMode) {
|
|
253
|
+
return replyAsEvent({
|
|
254
|
+
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y,
|
|
255
|
+
message, outcome, referencePaths,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
246
259
|
// The fallback (default: crossProjectFeedback.openReplyFallbackSession,
|
|
247
260
|
// the only cross-project mint authority) opens a NEW proposed Epic in the
|
|
248
261
|
// asking project. `openFallback: null` disables it (409 fallbackNeeded).
|
|
@@ -368,12 +381,68 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
368
381
|
});
|
|
369
382
|
}
|
|
370
383
|
|
|
384
|
+
/**
|
|
385
|
+
* replyAsEvent(ctx) → Promise<result>. Event-mode delivery, run inside the
|
|
386
|
+
* per-Epic lock after the cap check: append the reply event on X only when
|
|
387
|
+
* replyTo.epicId names an active Epic in replyTo.cwd, write the receipt on Y,
|
|
388
|
+
* and put what an outside app needs to match and read the reply into the
|
|
389
|
+
* audit row. Never prompts a chat, never opens a fallback session.
|
|
390
|
+
*/
|
|
391
|
+
async function replyAsEvent({
|
|
392
|
+
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y, message, outcome, referencePaths,
|
|
393
|
+
}) {
|
|
394
|
+
const replyMeta = { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths };
|
|
395
|
+
let eventOnAskingEpic = false;
|
|
396
|
+
const x = nonEmpty(rt.epicId) ? readActiveIndex(targetCwd).sessions[rt.epicId] : null;
|
|
397
|
+
if (x && x.status === 'active') {
|
|
398
|
+
const prompt = composeReplyPrompt({
|
|
399
|
+
fromCwd: replierCwd, fromEpicId: yId, fromGoalText: y.goalText, outcome, message, referencePaths,
|
|
400
|
+
});
|
|
401
|
+
try {
|
|
402
|
+
const appended = await appendEvent(targetCwd, x.id, prompt, { notice: REPLY_NOTICE, reply: replyMeta });
|
|
403
|
+
eventOnAskingEpic = !!(appended && appended.ok);
|
|
404
|
+
} catch { eventOnAskingEpic = false; }
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
const project = path.basename(targetCwd);
|
|
408
|
+
const receipt = await appendEvent(replierCwd, yId,
|
|
409
|
+
`Reply recorded as an event for ${rt.epicId ? `${rt.epicId} in ` : ''}${project} (${outcome}, event-only).`,
|
|
410
|
+
{ notice: RECEIPT_NOTICE, allowInactive: true, reply: replyMeta });
|
|
411
|
+
|
|
412
|
+
const externalRef = y.source && y.source.externalRef;
|
|
413
|
+
audit('epic_cross_project_reply', {
|
|
414
|
+
cwd: targetCwd,
|
|
415
|
+
epicId: rt.epicId || null,
|
|
416
|
+
fromCwd: replierCwd,
|
|
417
|
+
fromEpicId: yId,
|
|
418
|
+
outcome,
|
|
419
|
+
delivery: 'event-only',
|
|
420
|
+
mode: 'event',
|
|
421
|
+
...(externalRef ? { externalRef } : {}),
|
|
422
|
+
message: message.slice(0, AUDIT_MESSAGE_CHARS),
|
|
423
|
+
referencePaths: referencePaths.slice(0, AUDIT_MAX_REFERENCES),
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
return {
|
|
427
|
+
ok: true,
|
|
428
|
+
delivery: 'event-only',
|
|
429
|
+
reason: EVENT_MODE_REASON,
|
|
430
|
+
toCwd: targetCwd,
|
|
431
|
+
toEpicId: rt.epicId || null,
|
|
432
|
+
eventOnAskingEpic,
|
|
433
|
+
...receiptFields(receipt),
|
|
434
|
+
repliesUsed: sent + 1,
|
|
435
|
+
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
371
439
|
const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
|
|
372
440
|
|
|
373
441
|
/**
|
|
374
442
|
* resolveThread(src) — pure. The thread a replying Epic's `source` names:
|
|
375
443
|
* { ok: true, thread: { cwd, epicId, claudeSessionId }, legacy } or { ok: false, error }.
|
|
376
|
-
* A complete replyTo → legacy false
|
|
444
|
+
* A complete replyTo → legacy false; a replyTo with mode 'event' needs only a cwd
|
|
445
|
+
* (→ mode: 'event'). A pre-reply-thread request Epic (no
|
|
377
446
|
* replyTo key, no replyOf, fromCwd + fromEpicId set) → legacy true, no
|
|
378
447
|
* session pin. Every refusal says why and points at feedback_open_session.
|
|
379
448
|
*/
|
|
@@ -381,6 +450,19 @@ function resolveThread(src) {
|
|
|
381
450
|
const s = src && typeof src === 'object' ? src : {};
|
|
382
451
|
const isRequest = s.producer === 'cross-project-feedback';
|
|
383
452
|
const rt = s.replyTo;
|
|
453
|
+
// Event mode needs only the asker's cwd; epicId/claudeSessionId may be null.
|
|
454
|
+
if (isRequest && rt && typeof rt === 'object' && rt.mode === 'event' && nonEmpty(rt.cwd)) {
|
|
455
|
+
return {
|
|
456
|
+
ok: true,
|
|
457
|
+
thread: {
|
|
458
|
+
cwd: rt.cwd,
|
|
459
|
+
epicId: nonEmpty(rt.epicId) ? rt.epicId : null,
|
|
460
|
+
claudeSessionId: nonEmpty(rt.claudeSessionId) ? rt.claudeSessionId : null,
|
|
461
|
+
},
|
|
462
|
+
legacy: false,
|
|
463
|
+
mode: 'event',
|
|
464
|
+
};
|
|
465
|
+
}
|
|
384
466
|
if (isRequest && rt && typeof rt === 'object'
|
|
385
467
|
&& nonEmpty(rt.cwd) && nonEmpty(rt.epicId) && nonEmpty(rt.claudeSessionId)) {
|
|
386
468
|
return { ok: true, thread: { cwd: rt.cwd, epicId: rt.epicId, claudeSessionId: rt.claudeSessionId }, legacy: false };
|
|
@@ -5,19 +5,22 @@
|
|
|
5
5
|
* through customerFeedbackInbox.cjs:
|
|
6
6
|
* GET /admin/customer-feedback/inbox?pull=1&includeHidden=1 -> { ok, items, pulled? }
|
|
7
7
|
* POST /admin/customer-feedback/status {id, status, note?} -> { ok, item }
|
|
8
|
-
* POST /admin/customer-feedback/submit {title, body, tag}
|
|
8
|
+
* POST /admin/customer-feedback/submit {title, body, tag, imagePaths?} -> { ok, item, warning? } | { ok:false, error }
|
|
9
9
|
*
|
|
10
10
|
* submit is the customer path (no owner token needed): it runs the exact
|
|
11
|
-
* submit the
|
|
11
|
+
* submit the Feedback panel's customerFeedback:submit IPC uses
|
|
12
12
|
* (customerFeedbackIpc.submitFeedback -> customerFeedbackClient.submit), so the
|
|
13
13
|
* item + receipt land in the same local mirror. os.homedir() is replaced with
|
|
14
14
|
* `~` in title and body first; the body text is never echoed or logged.
|
|
15
|
+
* imagePaths (absolute only) are prepared by submitFeedback; image bytes are
|
|
16
|
+
* never logged or echoed.
|
|
15
17
|
*
|
|
16
18
|
* Deliberately NO route that mints an Epic (SINGLE-CREATOR LAW, epicMint.cjs).
|
|
17
19
|
* Responses never carry the owner token — the inbox lib redacts it from errors.
|
|
18
20
|
*/
|
|
19
21
|
'use strict';
|
|
20
22
|
|
|
23
|
+
const path = require('path');
|
|
21
24
|
const { readBody, sendJson } = require('./localAdminHttp.cjs');
|
|
22
25
|
|
|
23
26
|
/** @param {any} dep */
|
|
@@ -123,13 +126,20 @@ function submitHandler(submitDep) {
|
|
|
123
126
|
return;
|
|
124
127
|
}
|
|
125
128
|
const submit = submitDep || require('./customerFeedbackIpc.cjs').submitFeedback;
|
|
126
|
-
const { title, body: text, tag } = parsed.data;
|
|
127
|
-
|
|
129
|
+
const { title, body: text, tag, imagePaths } = parsed.data;
|
|
130
|
+
if (imagePaths && !imagePaths.every((x) => path.isAbsolute(x))) {
|
|
131
|
+
sendJson(res, 400, { ok: false, error: 'imagePaths must be absolute paths' });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const result = await submit({
|
|
135
|
+
title: redactHome(title), body: redactHome(text), tag,
|
|
136
|
+
...(imagePaths && imagePaths.length ? { imagePaths } : {}),
|
|
137
|
+
});
|
|
128
138
|
if (!result || !result.ok) {
|
|
129
139
|
sendJson(res, 502, { ok: false, error: result && typeof result.error === 'string' ? result.error : 'submit failed' });
|
|
130
140
|
return;
|
|
131
141
|
}
|
|
132
|
-
sendJson(res, 200, { ok: true, item: result.item });
|
|
142
|
+
sendJson(res, 200, { ok: true, item: result.item, ...(typeof result.warning === 'string' && result.warning ? { warning: result.warning } : {}) });
|
|
133
143
|
} catch (/** @type {any} */ e) {
|
|
134
144
|
sendJson(res, 500, { ok: false, error: e && e.message ? String(e.message) : 'submit failed' });
|
|
135
145
|
}
|
|
@@ -138,7 +148,7 @@ function submitHandler(submitDep) {
|
|
|
138
148
|
|
|
139
149
|
/**
|
|
140
150
|
* @param {any} adminHttp
|
|
141
|
-
* @param {{ inbox?: any, submit?: (p: { title: string, body: string, tag: string }) => Promise<any> }} [opts] test seams
|
|
151
|
+
* @param {{ inbox?: any, submit?: (p: { title: string, body: string, tag: string, imagePaths?: string[] }) => Promise<any> }} [opts] test seams
|
|
142
152
|
*/
|
|
143
153
|
function registerAdminRoute(adminHttp, opts = {}) {
|
|
144
154
|
adminHttp.registerRoute('GET', '/admin/customer-feedback/inbox', inboxHandler(opts.inbox));
|
|
@@ -25,12 +25,16 @@ const MAX_ITEMS = 500;
|
|
|
25
25
|
const MAX_LOOKUP = 100;
|
|
26
26
|
const TIMEOUT_MS = 15000;
|
|
27
27
|
const SCHEMA_VERSION = 1;
|
|
28
|
+
const MAX_IMAGES = 5;
|
|
29
|
+
const MAX_IMAGE_DATA_URL = 2000000;
|
|
30
|
+
const IMAGE_DATA_URL_RE = /^data:image\/(png|jpeg|webp|gif);base64,/;
|
|
28
31
|
const RATE_LIMIT_ERROR = 'Too many submissions — try again in a minute.';
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* @typedef {{ id: string, receipt: string|null, tag: string, title: string, body: string,
|
|
32
35
|
* submittedAt: number, status: string, statusNote: string|null,
|
|
33
|
-
* statusAt: number|string|null, seenStatusAt: number|string|null }} FeedbackItem
|
|
36
|
+
* statusAt: number|string|null, seenStatusAt: number|string|null, imageCount?: number }} FeedbackItem
|
|
37
|
+
* @typedef {{ dataUrl: string, mime: string }} FeedbackImage
|
|
34
38
|
* @typedef {{ fetchImpl?: typeof fetch, storeFile?: string, now?: () => number, appVersion?: string }} Deps
|
|
35
39
|
*/
|
|
36
40
|
|
|
@@ -49,8 +53,30 @@ function fromWireType(type) {
|
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @
|
|
56
|
+
* Re-checks shape and size of already-prepared images (feedbackImages.cjs does the real prep).
|
|
57
|
+
* @param {unknown} raw
|
|
58
|
+
* @returns {{ ok: true, images: FeedbackImage[] } | { ok: false, error: string }}
|
|
59
|
+
*/
|
|
60
|
+
function validateImages(raw) {
|
|
61
|
+
if (raw === undefined || raw === null) return { ok: true, images: [] };
|
|
62
|
+
if (!Array.isArray(raw)) return { ok: false, error: 'Images must be a list.' };
|
|
63
|
+
if (raw.length > MAX_IMAGES) return { ok: false, error: `Attach at most ${MAX_IMAGES} images.` };
|
|
64
|
+
/** @type {FeedbackImage[]} */
|
|
65
|
+
const images = [];
|
|
66
|
+
for (const entry of raw) {
|
|
67
|
+
const e = entry && typeof entry === 'object' ? /** @type {{ dataUrl?: unknown, mime?: unknown }} */ (entry) : {};
|
|
68
|
+
if (typeof e.dataUrl !== 'string' || typeof e.mime !== 'string' || !IMAGE_DATA_URL_RE.test(e.dataUrl)) {
|
|
69
|
+
return { ok: false, error: 'Each image must be a PNG, JPEG, WebP or GIF data URL.' };
|
|
70
|
+
}
|
|
71
|
+
if (e.dataUrl.length > MAX_IMAGE_DATA_URL) return { ok: false, error: 'An image is too large to send.' };
|
|
72
|
+
images.push({ dataUrl: e.dataUrl, mime: e.mime });
|
|
73
|
+
}
|
|
74
|
+
return { ok: true, images };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @param {{ title?: unknown, body?: unknown, tag?: unknown, images?: unknown }} input
|
|
79
|
+
* @returns {{ ok: true, value: { title: string, body: string, tag: string, images: FeedbackImage[] } } | { ok: false, error: string }}
|
|
54
80
|
*/
|
|
55
81
|
function validateSubmission(input) {
|
|
56
82
|
const src = input || {};
|
|
@@ -64,7 +90,9 @@ function validateSubmission(input) {
|
|
|
64
90
|
if (typeof tag !== 'string' || !TAGS.includes(/** @type {any} */ (tag))) {
|
|
65
91
|
return { ok: false, error: `Tag must be one of: ${TAGS.join(', ')}.` };
|
|
66
92
|
}
|
|
67
|
-
|
|
93
|
+
const imgs = validateImages(src.images);
|
|
94
|
+
if (!imgs.ok) return imgs;
|
|
95
|
+
return { ok: true, value: { title, body, tag, images: imgs.images } };
|
|
68
96
|
}
|
|
69
97
|
|
|
70
98
|
function defaultStoreFile() {
|
|
@@ -137,15 +165,24 @@ async function errorText(res, fallback) {
|
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
/**
|
|
140
|
-
* @param {
|
|
168
|
+
* @param {number} acked @param {number} sent @returns {string|null}
|
|
169
|
+
*/
|
|
170
|
+
function imageWarning(acked, sent) {
|
|
171
|
+
if (sent === 0 || acked === sent) return null;
|
|
172
|
+
if (acked <= 0) return 'Sent without the images — the feedback service does not accept images yet.';
|
|
173
|
+
return `Only ${acked} of ${sent} images were accepted by the feedback service.`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @param {{ title?: unknown, body?: unknown, tag?: unknown, images?: unknown }} input
|
|
141
178
|
* @param {Deps} [deps]
|
|
142
|
-
* @returns {Promise<{ ok: true, item: FeedbackItem } | { ok: false, error: string }>}
|
|
179
|
+
* @returns {Promise<{ ok: true, item: FeedbackItem, warning?: string } | { ok: false, error: string }>}
|
|
143
180
|
*/
|
|
144
181
|
async function submit(input, deps) {
|
|
145
182
|
const v = validateSubmission(input);
|
|
146
183
|
if (!v.ok) return v;
|
|
147
184
|
const c = ctx(deps);
|
|
148
|
-
const { title, body, tag } = v.value;
|
|
185
|
+
const { title, body, tag, images } = v.value;
|
|
149
186
|
try {
|
|
150
187
|
const res = await c.fetchImpl(`${resolveFeedbackBase()}/api/projects/${FEEDBACK_SLUG}/feedback`, {
|
|
151
188
|
method: 'POST',
|
|
@@ -156,6 +193,7 @@ async function submit(input, deps) {
|
|
|
156
193
|
title,
|
|
157
194
|
description: body,
|
|
158
195
|
client: { app: 'session-manager', version: c.appVersion, platform: process.platform },
|
|
196
|
+
...(images.length > 0 ? { images } : {}),
|
|
159
197
|
}),
|
|
160
198
|
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
161
199
|
});
|
|
@@ -164,6 +202,8 @@ async function submit(input, deps) {
|
|
|
164
202
|
/** @type {any} */
|
|
165
203
|
const j = await res.json().catch(() => null);
|
|
166
204
|
if (!j || typeof j.id !== 'string' || !j.id) return { ok: false, error: 'Feedback service returned an unexpected response.' };
|
|
205
|
+
const acked = typeof j.imageCount === 'number' ? j.imageCount : 0;
|
|
206
|
+
const warning = imageWarning(acked, images.length);
|
|
167
207
|
/** @type {FeedbackItem} */
|
|
168
208
|
const item = {
|
|
169
209
|
id: j.id,
|
|
@@ -176,9 +216,10 @@ async function submit(input, deps) {
|
|
|
176
216
|
statusNote: null,
|
|
177
217
|
statusAt: null,
|
|
178
218
|
seenStatusAt: null,
|
|
219
|
+
imageCount: images.length ? acked : 0,
|
|
179
220
|
};
|
|
180
221
|
await mutateStore(c.storeFile, (items) => [item, ...items]);
|
|
181
|
-
return { ok: true, item };
|
|
222
|
+
return { ok: true, item, ...(warning ? { warning } : {}) };
|
|
182
223
|
} catch (e) {
|
|
183
224
|
return { ok: false, error: `Could not reach the feedback service: ${e instanceof Error ? e.message : String(e)}` };
|
|
184
225
|
}
|
|
@@ -249,6 +290,7 @@ module.exports = {
|
|
|
249
290
|
TAGS,
|
|
250
291
|
MAX_TITLE,
|
|
251
292
|
MAX_BODY,
|
|
293
|
+
MAX_IMAGES,
|
|
252
294
|
resolveFeedbackBase,
|
|
253
295
|
toWireType,
|
|
254
296
|
fromWireType,
|