claude-code-session-manager 0.138.0 → 0.140.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +1 -1
- package/README.md +352 -79
- package/dist/assets/AppSettings-CMFEM68R.js +2 -0
- package/dist/assets/History--JwsFnbn.js +2 -0
- package/dist/assets/HomeClaudeConfig-ijEXs--3.js +3 -0
- package/dist/assets/{Panel-CeDiyuNn.js → Panel-CALyU0pe.js} +1 -1
- package/dist/assets/ProjectClaudeConfig-sdlA-fUb.js +26 -0
- package/dist/assets/Scheduler-YT3j8SUa.js +16 -0
- package/dist/assets/{SkillReferenceGraph-CFMK8NJh.js → SkillReferenceGraph-CxAuwhNN.js} +1 -1
- package/dist/assets/Skills-DtRzghn5.js +67 -0
- package/dist/assets/{TiptapBody-D1kTj-tn.js → TiptapBody-DApeu7x8.js} +60 -54
- package/dist/assets/ViewTabs-B7qLXRAH.js +1 -0
- package/dist/assets/{VoiceButton-CZeyPM31.js → VoiceButton-DtStfv1H.js} +1 -1
- package/dist/assets/{historyTotals-B00l64Jw.js → historyTotals-ydfnwepc.js} +1 -1
- package/dist/assets/index-CtxruO1L.js +3121 -0
- package/dist/assets/{index-62tyjEQB.css → index-DKXdXfka.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +467 -451
- package/package.json +17 -6
- package/plugins/AGENTS.md +60 -0
- package/plugins/CLAUDE.md +1 -60
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/skills/builder/SKILL.md +12 -4
- package/plugins/session-manager-dev/skills/builder/scripts/publish-preflight.cjs +255 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +36 -22
- package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +5 -4
- package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +4 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +16 -12
- package/plugins/session-manager-dev/skills/maintaining-md-network/migrate-to-agents-md.md +15 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +50 -2
- package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +10 -10
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +117 -112
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdDuplicates.cjs +182 -0
- package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/mdLinks.cjs +340 -0
- package/scripts/README.md +2 -0
- package/scripts/hooks/guard-tool-risk.cjs +91 -0
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +217 -0
- package/scripts/ops-sweep.cjs +53 -23
- package/scripts/scheduler-mcp-server.cjs +360 -35
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +2 -2
- package/src/main/config.cjs +112 -8
- package/src/main/docEdit.cjs +6 -1
- package/src/main/exchanges.cjs +70 -5
- package/src/main/files.cjs +7 -27
- package/src/main/health.cjs +48 -15
- package/src/main/historyAggregator.cjs +172 -63
- package/src/main/historyDashboard.cjs +87 -17
- package/src/main/index.cjs +78 -4
- package/src/main/ipcSchemas.cjs +233 -20
- package/src/main/lib/AGENTS.md +54 -0
- package/src/main/lib/CLAUDE.md +1 -54
- package/src/main/lib/agent-cli/adapters/codex.cjs +5 -2
- package/src/main/lib/agent-cli/agentCliIpc.cjs +18 -2
- package/src/main/lib/agent-cli/agentCliSessionStore.cjs +1 -0
- package/src/main/lib/agent-cli/agentCliTurn.cjs +20 -2
- package/src/main/lib/agent-cli/geminiContextDefaults.cjs +94 -0
- package/src/main/lib/claude/effectiveModelInfo.cjs +92 -22
- package/src/main/lib/claude/jobSandboxPolicy.cjs +202 -0
- package/src/main/lib/claude/modelPricing.cjs +148 -0
- package/src/main/lib/claude/personaToolScope.cjs +12 -6
- package/src/main/lib/claude/rateLimitDetect.cjs +13 -2
- package/src/main/lib/claude/runClaudeP.cjs +6 -1
- package/src/main/lib/claude/toolRiskIpc.cjs +177 -0
- package/src/main/lib/claude/toolRiskMarks.cjs +373 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +27 -6
- package/src/main/lib/ephemeralCwd.cjs +37 -2
- package/src/main/lib/epic/delegationReadiness.cjs +42 -9
- package/src/main/lib/epic/epicAdminRoutes.cjs +121 -0
- package/src/main/lib/epic/epicJobReceipt.cjs +87 -0
- package/src/main/lib/epic/epicOutsideRead.cjs +423 -0
- package/src/main/lib/epic/epicOutsideState.cjs +233 -0
- package/src/main/lib/epic/epicSettle.cjs +1 -1
- package/src/main/lib/epic/epicStateWatcher.cjs +157 -0
- package/src/main/lib/epic/epicSweepValidator.cjs +7 -2
- package/src/main/lib/epic/epicValidationHook.cjs +24 -4
- package/src/main/lib/epic/externalRef.cjs +37 -0
- package/src/main/lib/epic/externalRefIndex.cjs +136 -0
- package/src/main/lib/epic/guardSpawnSettings.cjs +57 -1
- package/src/main/lib/epic/restorableSessions.cjs +151 -17
- package/src/main/lib/epic/transcriptUsage.cjs +197 -0
- package/src/main/lib/externalContract.cjs +137 -0
- package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +176 -5
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +186 -9
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -6
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +50 -8
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +218 -4
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +19 -3
- package/src/main/lib/feedback-remote/feedbackImages.cjs +171 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +11 -10
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +167 -21
- package/src/main/lib/feedback-remote/needsYouAdminRoutes.cjs +133 -0
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +50 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +285 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +98 -1
- package/src/main/lib/feedback-remote/remoteIpcDispatch.cjs +5 -0
- package/src/main/lib/git/branchSweep.cjs +209 -4
- package/src/main/lib/git/gitWorktree.cjs +41 -5
- package/src/main/lib/guardShims.cjs +1 -1
- package/src/main/lib/historyRollup.cjs +58 -5
- package/src/main/lib/insideHome.cjs +27 -1
- package/src/main/lib/mcpToolCatalog.cjs +232 -25
- package/src/main/lib/mdDocCensus.cjs +59 -78
- package/src/main/lib/mdDocRefs.cjs +71 -93
- package/src/main/lib/mdNetworkScan.cjs +245 -250
- package/src/main/lib/mdReviewRecord.cjs +22 -9
- package/src/main/lib/memoryMdNetwork.cjs +5 -12
- package/src/main/lib/opsOwnership.cjs +18 -2
- package/src/main/lib/opsRetentionSettings.cjs +28 -4
- package/src/main/lib/persona-macro/agentAdminRoutes.cjs +121 -0
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +90 -20
- package/src/main/lib/persona-macro/macroJobIpc.cjs +144 -46
- package/src/main/lib/persona-macro/macroJobStatus.cjs +87 -9
- package/src/main/lib/persona-macro/macroLibrary.cjs +95 -5
- package/src/main/lib/persona-macro/personaImportHealth.cjs +78 -17
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +96 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +11 -0
- package/src/main/lib/prd/depSlugResolve.cjs +104 -4
- package/src/main/lib/prd/prdAdminRoutes.cjs +35 -2
- package/src/main/lib/prd/prdCreate.cjs +351 -23
- package/src/main/lib/prd/prdDisposition.cjs +11 -2
- package/src/main/lib/prd/prdFrontmatter.cjs +96 -3
- package/src/main/lib/process/loginItem.cjs +171 -0
- package/src/main/lib/process/loginItemPlan.cjs +193 -0
- package/src/main/lib/project-pages/playerBridge.cjs +4 -0
- package/src/main/lib/project-pages/videoReview.cjs +268 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +229 -0
- package/src/main/lib/promptSessionSchema.cjs +4 -0
- package/src/main/lib/remoteTranscriptTail.cjs +32 -1
- package/src/main/lib/scheduler/cpuSample.cjs +131 -4
- package/src/main/lib/scheduler/fixPlanSlug.cjs +4 -3
- package/src/main/lib/scheduler/loadGate.cjs +24 -6
- package/src/main/lib/scheduler/planRecordHarvest.cjs +108 -0
- package/src/main/lib/scheduler/planRecordRetention.cjs +144 -0
- package/src/main/lib/scheduler/queueStore.cjs +7 -0
- package/src/main/lib/scheduler/rcaReport.cjs +21 -1
- package/src/main/lib/scheduler/reaperHelpers.cjs +35 -5
- package/src/main/lib/scheduler/runLogRetention.cjs +104 -3
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/scheduler/schedulerBatch.cjs +25 -48
- package/src/main/lib/scheduler/schedulerPaths.cjs +12 -0
- package/src/main/lib/scheduler/sessionSlots.cjs +176 -21
- package/src/main/lib/scheduler/validationQuality.cjs +282 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +254 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +641 -0
- package/src/main/lib/tasks/taskIpc.cjs +80 -0
- package/src/main/lib/tasks/taskLedger.cjs +502 -0
- package/src/main/lib/tasks/taskRun.cjs +313 -0
- package/src/main/lib/tasks/taskSwitch.cjs +120 -0
- package/src/main/lib/telemetry/auditEvents.cjs +176 -0
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +45 -0
- package/src/main/loginItemIpc.cjs +35 -0
- package/src/main/loopEfficiencyHandlers.cjs +11 -2
- package/src/main/projectPages.cjs +6 -15
- package/src/main/promptSessionEvents.cjs +9 -1
- package/src/main/queueOps.cjs +260 -3
- package/src/main/runVerify.cjs +53 -25
- package/src/main/scheduler/AGENTS.md +26 -0
- package/src/main/scheduler/CLAUDE.md +1 -26
- package/src/main/scheduler/budget.cjs +239 -9
- package/src/main/scheduler/cancelDependents.cjs +154 -0
- package/src/main/scheduler/prdParser.cjs +4 -1
- package/src/main/scheduler/starvation.cjs +20 -18
- package/src/main/scheduler.cjs +774 -64
- package/src/main/supervisor.cjs +5 -1
- package/src/main/templates/PRD_AUTHORING.md +7 -1
- package/src/main/transcripts.cjs +62 -7
- package/src/main/validationQualityHandlers.cjs +199 -0
- package/src/main/webRemote.cjs +132 -20
- package/src/preload/api.d.ts +434 -28
- package/src/preload/apiSurface.cjs +7 -0
- package/src/preload/apiSurface.json +485 -81
- package/src/preload/index.cjs +38 -5
- package/src/seed/agents/validator.md +19 -8
- package/dist/assets/AgentLibrary-C1d_D7uQ.js +0 -2
- package/dist/assets/AppSettings-CgDhqrsU.js +0 -2
- package/dist/assets/Button-Bk23rEnZ.js +0 -1
- package/dist/assets/DocumentEditorPane-BqY5Nq6W.js +0 -1
- package/dist/assets/Extensions-CXem-uwI.js +0 -2
- package/dist/assets/History-BwO3coo4.js +0 -2
- package/dist/assets/Library-BDV69fSe.js +0 -32
- package/dist/assets/ListDetail-CD-Fm6mh.js +0 -1
- package/dist/assets/ProjectClaudeConfig-NjdKdwe8.js +0 -25
- package/dist/assets/ProvenanceBadge-Bu8NmI_R.js +0 -1
- package/dist/assets/Scheduler-CkhTvG7C.js +0 -16
- package/dist/assets/Settings-COT34hBF.js +0 -2
- package/dist/assets/Skills-BgexoUkQ.js +0 -29
- package/dist/assets/SourceChip-BXjcdeb1.js +0 -1
- package/dist/assets/SystemPrompt-CeeH3EeW.js +0 -1
- package/dist/assets/Toggle-CENi19iK.js +0 -1
- package/dist/assets/ViewTabs-DDBb0x96.js +0 -1
- package/dist/assets/claude-settings-schema-COigsajx.js +0 -3
- package/dist/assets/index-CgCxpunJ.js +0 -3116
|
@@ -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
|
+
}
|
|
627
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';
|
|
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
|
|
@@ -836,6 +950,38 @@ function fallbackReasonText(reason) {
|
|
|
836
950
|
return r;
|
|
837
951
|
}
|
|
838
952
|
|
|
953
|
+
/**
|
|
954
|
+
* findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId }) → { epicId, status } | null
|
|
955
|
+
*
|
|
956
|
+
* The OPEN (proposed/active) reply-fallback Epic already minted in toCwd for
|
|
957
|
+
* this thread — the (asking Epic toEpicId, replier fromCwd/fromEpicId) pair —
|
|
958
|
+
* or null. Completed or archived (removed from the active index) Epics never
|
|
959
|
+
* match. Tolerates rows with missing/partial `source`. Never throws.
|
|
960
|
+
*/
|
|
961
|
+
function findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId } = {}) {
|
|
962
|
+
const sameCwd = (x, y) => typeof x === 'string' && typeof y === 'string' && x && y
|
|
963
|
+
&& path.resolve(x) === path.resolve(y);
|
|
964
|
+
let sessions;
|
|
965
|
+
try {
|
|
966
|
+
sessions = readActiveIndex(toCwd).sessions;
|
|
967
|
+
} catch {
|
|
968
|
+
return null;
|
|
969
|
+
}
|
|
970
|
+
const wantFromEpicId = fromEpicId || null;
|
|
971
|
+
for (const [id, row] of Object.entries(sessions || {})) {
|
|
972
|
+
if (!row || typeof row !== 'object') continue;
|
|
973
|
+
if (row.status !== 'proposed' && row.status !== 'active') continue;
|
|
974
|
+
const src = row.source && typeof row.source === 'object' ? row.source : null;
|
|
975
|
+
if (!src || src.producer !== 'cross-project-feedback') continue;
|
|
976
|
+
const replyOf = src.replyOf && typeof src.replyOf === 'object' ? src.replyOf : null;
|
|
977
|
+
if (!replyOf || replyOf.epicId !== toEpicId || !sameCwd(replyOf.cwd, toCwd)) continue;
|
|
978
|
+
if (!sameCwd(src.fromCwd, fromCwd)) continue;
|
|
979
|
+
if ((src.fromEpicId || null) !== wantFromEpicId) continue;
|
|
980
|
+
return { epicId: row.id || id, status: row.status };
|
|
981
|
+
}
|
|
982
|
+
return null;
|
|
983
|
+
}
|
|
984
|
+
|
|
839
985
|
/**
|
|
840
986
|
* openReplyFallbackSession(input, deps?) → { ok, epicId, toCwd, ... } | { ok: false, status, error }
|
|
841
987
|
*
|
|
@@ -871,6 +1017,28 @@ async function openReplyFallbackSession(input = {}, deps = {}) {
|
|
|
871
1017
|
if (!isSessionManagerProject(toCwd)) return bad(400, `${toCwd} is not a Session Manager project`);
|
|
872
1018
|
if (toCwd === fromCwd) return bad(400, 'the reply fallback must land in a DIFFERENT project');
|
|
873
1019
|
|
|
1020
|
+
// Idempotent per thread: at most one OPEN fallback Epic per (asking Epic,
|
|
1021
|
+
// replier Epic). A second reply on the same thread joins the open one
|
|
1022
|
+
// instead of minting a duplicate (2026-11-21: two Epics, plan queued twice).
|
|
1023
|
+
const replyOf = { cwd: toCwd, epicId: toEpicId };
|
|
1024
|
+
const existing = findOpenReplyFallback(toCwd, { toEpicId, fromCwd, fromEpicId });
|
|
1025
|
+
if (existing) {
|
|
1026
|
+
const outcome = singleLine(input.outcome) || 'unknown';
|
|
1027
|
+
const reason = singleLine(input.reason) || 'unknown';
|
|
1028
|
+
try {
|
|
1029
|
+
audit('epic_cross_project_reply_fallback_reused', {
|
|
1030
|
+
cwd: toCwd,
|
|
1031
|
+
epicId: existing.epicId,
|
|
1032
|
+
replyOf,
|
|
1033
|
+
fromCwd,
|
|
1034
|
+
fromEpicId,
|
|
1035
|
+
outcome,
|
|
1036
|
+
reason,
|
|
1037
|
+
});
|
|
1038
|
+
} catch { /* audit is best-effort */ }
|
|
1039
|
+
return { ok: true, epicId: existing.epicId, reused: true, status: existing.status, toCwd, fromCwd, replyOf, reason };
|
|
1040
|
+
}
|
|
1041
|
+
|
|
874
1042
|
const original = input.original && typeof input.original === 'object' ? input.original : {};
|
|
875
1043
|
const proposal = original.proposal && typeof original.proposal === 'object' ? original.proposal : {};
|
|
876
1044
|
const originalTitle = singleLine(original.title) || '(untitled request)';
|
|
@@ -906,7 +1074,6 @@ async function openReplyFallbackSession(input = {}, deps = {}) {
|
|
|
906
1074
|
acceptanceCriteria,
|
|
907
1075
|
});
|
|
908
1076
|
|
|
909
|
-
const replyOf = { cwd: toCwd, epicId: toEpicId };
|
|
910
1077
|
let minted;
|
|
911
1078
|
try {
|
|
912
1079
|
minted = await mint(toCwd, {
|
|
@@ -1097,9 +1264,13 @@ module.exports = {
|
|
|
1097
1264
|
composeFeedbackIntake,
|
|
1098
1265
|
resolveOriginAsk,
|
|
1099
1266
|
resolveReplyTo,
|
|
1267
|
+
REPLY_MODES,
|
|
1268
|
+
DEFAULT_REPLY_MODE,
|
|
1100
1269
|
validateFeedbackInput,
|
|
1101
1270
|
openFeedbackSession,
|
|
1271
|
+
recordExternalRefWithRetry,
|
|
1102
1272
|
readEpicGoal,
|
|
1273
|
+
findOpenReplyFallback,
|
|
1103
1274
|
openReplyFallbackSession,
|
|
1104
1275
|
listFeedbackTargets,
|
|
1105
1276
|
registerAdminRoute,
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
* active-index.json delegation). Reads use epicMint.cjs's readActiveIndex.
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
|
+
const crypto = require('node:crypto');
|
|
36
37
|
const fs = require('node:fs');
|
|
37
38
|
const path = require('node:path');
|
|
38
39
|
|
|
@@ -54,6 +55,11 @@ const REPLY_OUTCOMES = Object.freeze(['done', 'blocked', 'question']);
|
|
|
54
55
|
const RECEIPT_NOTICE = 'cross-project-reply-sent';
|
|
55
56
|
const REPLY_NOTICE = 'cross-project-reply';
|
|
56
57
|
const FALLBACK_NOTICE = 'cross-project-reply-fallback';
|
|
58
|
+
/** Event mode (source.replyTo.mode 'event'): the asker keeps its own records,
|
|
59
|
+
* so the reply is data in the audit row — never a chat prompt or a fallback. */
|
|
60
|
+
const EVENT_MODE_REASON = 'asker-requested-event';
|
|
61
|
+
const AUDIT_MESSAGE_CHARS = 2000;
|
|
62
|
+
const AUDIT_MAX_REFERENCES = 10;
|
|
57
63
|
|
|
58
64
|
/** Per-Y promise chain: cap check → deliver → receipt run one at a time. */
|
|
59
65
|
const threadLocks = new Map();
|
|
@@ -171,9 +177,37 @@ function receiptFields(appendResult) {
|
|
|
171
177
|
};
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
|
|
180
|
+
/** The thread's receipts on Y — the cap count and the latest one (for the
|
|
181
|
+
* identical-retry check) come from the same read. */
|
|
182
|
+
function readReceipts(cwd, epicId) {
|
|
175
183
|
const events = readActiveIndex(cwd).events[epicId];
|
|
176
|
-
return Array.isArray(events) ? events.filter((e) => e && e.notice === RECEIPT_NOTICE)
|
|
184
|
+
return Array.isArray(events) ? events.filter((e) => e && e.notice === RECEIPT_NOTICE) : [];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** reply.hash on every receipt: an identical retry (same outcome + message)
|
|
188
|
+
* of the thread's latest reply is the same reply, not a new one. */
|
|
189
|
+
function replyHash(outcome, message) {
|
|
190
|
+
return crypto.createHash('sha256').update(`${outcome}\n${message}`).digest('hex');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The delivery fields an earlier receipt recorded, returned to an identical
|
|
194
|
+
* retry instead of delivering again. */
|
|
195
|
+
function earlierDelivery(receipt, { targetCwd, rt, threadField, sent }) {
|
|
196
|
+
const r = receipt.reply || {};
|
|
197
|
+
return {
|
|
198
|
+
ok: true,
|
|
199
|
+
alreadyDelivered: true,
|
|
200
|
+
delivery: r.delivery || 'delivered',
|
|
201
|
+
toCwd: targetCwd,
|
|
202
|
+
toEpicId: r.toEpicId || rt.epicId || null,
|
|
203
|
+
...(r.fallbackEpicId ? { fallbackEpicId: r.fallbackEpicId } : {}),
|
|
204
|
+
...(r.reused ? { reused: true } : {}),
|
|
205
|
+
...(r.reason ? { reason: r.reason } : {}),
|
|
206
|
+
...threadField,
|
|
207
|
+
receiptOnReplyingEpic: true,
|
|
208
|
+
repliesUsed: sent,
|
|
209
|
+
repliesLeft: Math.max(0, MAX_REPLIES_PER_THREAD - sent),
|
|
210
|
+
};
|
|
177
211
|
}
|
|
178
212
|
|
|
179
213
|
/**
|
|
@@ -219,6 +253,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
219
253
|
if (!resolved.ok) return bad(400, resolved.error);
|
|
220
254
|
const rt = resolved.thread;
|
|
221
255
|
const legacy = resolved.legacy;
|
|
256
|
+
const eventMode = resolved.mode === 'event';
|
|
222
257
|
const threadField = legacy ? { thread: 'legacy' } : {};
|
|
223
258
|
if (input.toEpicId !== undefined && input.toEpicId !== null && input.toEpicId !== rt.epicId) {
|
|
224
259
|
return bad(403, `this session may only reply to Epic ${rt.epicId}, the one that asked`);
|
|
@@ -237,12 +272,25 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
237
272
|
}
|
|
238
273
|
|
|
239
274
|
return withThreadLock(`${realOr(replierCwd)}\u0000${yId}`, async () => {
|
|
240
|
-
// 4.
|
|
241
|
-
const
|
|
275
|
+
// 4. Identical retry, then cap.
|
|
276
|
+
const receipts = readReceipts(replierCwd, yId);
|
|
277
|
+
const sent = receipts.length;
|
|
278
|
+
const hash = replyHash(outcome, message);
|
|
279
|
+
const latest = receipts[sent - 1];
|
|
280
|
+
if (latest && latest.reply && latest.reply.hash === hash) {
|
|
281
|
+
return earlierDelivery(latest, { targetCwd, rt, threadField, sent });
|
|
282
|
+
}
|
|
242
283
|
if (sent >= MAX_REPLIES_PER_THREAD) {
|
|
243
284
|
return bad(429, `reply limit of ${MAX_REPLIES_PER_THREAD} reached for this thread`);
|
|
244
285
|
}
|
|
245
286
|
|
|
287
|
+
if (eventMode) {
|
|
288
|
+
return replyAsEvent({
|
|
289
|
+
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y,
|
|
290
|
+
message, outcome, referencePaths, hash,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
246
294
|
// The fallback (default: crossProjectFeedback.openReplyFallbackSession,
|
|
247
295
|
// the only cross-project mint authority) opens a NEW proposed Epic in the
|
|
248
296
|
// asking project. `openFallback: null` disables it (409 fallbackNeeded).
|
|
@@ -267,13 +315,29 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
267
315
|
});
|
|
268
316
|
if (!opened || !opened.ok || typeof opened.epicId !== 'string') return opened;
|
|
269
317
|
const project = path.basename(targetCwd);
|
|
318
|
+
const reused = opened.reused === true;
|
|
319
|
+
// A reused fallback Epic already carries the first reply in its opening
|
|
320
|
+
// prompt; this one must land in it too, or its text is lost.
|
|
321
|
+
let landedInFallback = null;
|
|
322
|
+
if (reused) {
|
|
323
|
+
landedInFallback = await deliverIntoReusedFallback({
|
|
324
|
+
sendPrompt, appendEvent, targetCwd, epicId: opened.epicId,
|
|
325
|
+
replierCwd, yId, y, outcome, message, referencePaths,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
270
328
|
// Receipt on Y — counts toward the per-thread cap like a delivered reply.
|
|
271
329
|
const receipt = await appendEvent(replierCwd, yId,
|
|
272
|
-
|
|
330
|
+
reused
|
|
331
|
+
? `Reply to ${rt.epicId} in ${project} fell back into the open session ${opened.epicId} in ${project} (${reason}).`
|
|
332
|
+
: `Reply to ${rt.epicId} in ${project} fell back to a new proposed session ${opened.epicId} in ${project} (${reason}).`,
|
|
273
333
|
{
|
|
274
334
|
notice: RECEIPT_NOTICE,
|
|
275
335
|
allowInactive: true,
|
|
276
|
-
reply: {
|
|
336
|
+
reply: {
|
|
337
|
+
fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
|
|
338
|
+
delivery: 'fallback', toEpicId: rt.epicId, fallbackEpicId: opened.epicId, reason,
|
|
339
|
+
...(reused ? { reused: true } : {}),
|
|
340
|
+
},
|
|
277
341
|
});
|
|
278
342
|
// Best-effort receipt on X, only while X is still in A's active index.
|
|
279
343
|
let receiptOnAskingEpic = false;
|
|
@@ -281,7 +345,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
281
345
|
if (readActiveIndex(targetCwd).sessions[rt.epicId]) {
|
|
282
346
|
const r = await appendEvent(targetCwd, rt.epicId,
|
|
283
347
|
`A reply from ${path.basename(replierCwd)} (${outcome}) could not be delivered here (${reason}); `
|
|
284
|
-
+ `it opened as a new proposed session ${opened.epicId}
|
|
348
|
+
+ (reused ? `it was added to the open session ${opened.epicId}.` : `it opened as a new proposed session ${opened.epicId}.`),
|
|
285
349
|
{ notice: FALLBACK_NOTICE, allowInactive: true, reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, fallbackEpicId: opened.epicId } });
|
|
286
350
|
receiptOnAskingEpic = !!(r && r.ok);
|
|
287
351
|
}
|
|
@@ -293,6 +357,7 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
293
357
|
toCwd: targetCwd,
|
|
294
358
|
toEpicId: rt.epicId,
|
|
295
359
|
fallbackEpicId: opened.epicId,
|
|
360
|
+
...(reused ? { reused: true, landedInFallback } : {}),
|
|
296
361
|
receiptOnAskingEpic,
|
|
297
362
|
...threadField,
|
|
298
363
|
...receiptFields(receipt),
|
|
@@ -340,7 +405,11 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
340
405
|
{
|
|
341
406
|
notice: RECEIPT_NOTICE,
|
|
342
407
|
allowInactive: true,
|
|
343
|
-
reply: {
|
|
408
|
+
reply: {
|
|
409
|
+
fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths, hash,
|
|
410
|
+
delivery, toEpicId: x.id,
|
|
411
|
+
...(delivery === 'event-only' && sendResult && sendResult.reason ? { reason: sendResult.reason } : {}),
|
|
412
|
+
},
|
|
344
413
|
});
|
|
345
414
|
|
|
346
415
|
// 7. Audit.
|
|
@@ -368,12 +437,107 @@ async function sendFeedbackReply(input, deps = {}) {
|
|
|
368
437
|
});
|
|
369
438
|
}
|
|
370
439
|
|
|
440
|
+
/**
|
|
441
|
+
* replyAsEvent(ctx) → Promise<result>. Event-mode delivery, run inside the
|
|
442
|
+
* per-Epic lock after the cap check: append the reply event on X only when
|
|
443
|
+
* replyTo.epicId names an active Epic in replyTo.cwd, write the receipt on Y,
|
|
444
|
+
* and put what an outside app needs to match and read the reply into the
|
|
445
|
+
* audit row. Never prompts a chat, never opens a fallback session.
|
|
446
|
+
*/
|
|
447
|
+
async function replyAsEvent({
|
|
448
|
+
appendEvent, audit, sent, rt, targetCwd, replierCwd, yId, y, message, outcome, referencePaths, hash,
|
|
449
|
+
}) {
|
|
450
|
+
const replyMeta = { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths };
|
|
451
|
+
let eventOnAskingEpic = false;
|
|
452
|
+
const x = nonEmpty(rt.epicId) ? readActiveIndex(targetCwd).sessions[rt.epicId] : null;
|
|
453
|
+
if (x && x.status === 'active') {
|
|
454
|
+
const prompt = composeReplyPrompt({
|
|
455
|
+
fromCwd: replierCwd, fromEpicId: yId, fromGoalText: y.goalText, outcome, message, referencePaths,
|
|
456
|
+
});
|
|
457
|
+
try {
|
|
458
|
+
const appended = await appendEvent(targetCwd, x.id, prompt, { notice: REPLY_NOTICE, reply: replyMeta });
|
|
459
|
+
eventOnAskingEpic = !!(appended && appended.ok);
|
|
460
|
+
} catch { eventOnAskingEpic = false; }
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const project = path.basename(targetCwd);
|
|
464
|
+
const receipt = await appendEvent(replierCwd, yId,
|
|
465
|
+
`Reply recorded as an event for ${rt.epicId ? `${rt.epicId} in ` : ''}${project} (${outcome}, event-only).`,
|
|
466
|
+
{
|
|
467
|
+
notice: RECEIPT_NOTICE,
|
|
468
|
+
allowInactive: true,
|
|
469
|
+
reply: {
|
|
470
|
+
...replyMeta, hash, delivery: 'event-only', reason: EVENT_MODE_REASON,
|
|
471
|
+
...(rt.epicId ? { toEpicId: rt.epicId } : {}),
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
const externalRef = y.source && y.source.externalRef;
|
|
476
|
+
audit('epic_cross_project_reply', {
|
|
477
|
+
cwd: targetCwd,
|
|
478
|
+
epicId: rt.epicId || null,
|
|
479
|
+
fromCwd: replierCwd,
|
|
480
|
+
fromEpicId: yId,
|
|
481
|
+
outcome,
|
|
482
|
+
delivery: 'event-only',
|
|
483
|
+
mode: 'event',
|
|
484
|
+
...(externalRef ? { externalRef } : {}),
|
|
485
|
+
message: message.slice(0, AUDIT_MESSAGE_CHARS),
|
|
486
|
+
referencePaths: referencePaths.slice(0, AUDIT_MAX_REFERENCES),
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
return {
|
|
490
|
+
ok: true,
|
|
491
|
+
delivery: 'event-only',
|
|
492
|
+
reason: EVENT_MODE_REASON,
|
|
493
|
+
toCwd: targetCwd,
|
|
494
|
+
toEpicId: rt.epicId || null,
|
|
495
|
+
eventOnAskingEpic,
|
|
496
|
+
...receiptFields(receipt),
|
|
497
|
+
repliesUsed: sent + 1,
|
|
498
|
+
repliesLeft: MAX_REPLIES_PER_THREAD - sent - 1,
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
|
|
371
502
|
const nonEmpty = (v) => typeof v === 'string' && v.length > 0;
|
|
372
503
|
|
|
504
|
+
/**
|
|
505
|
+
* deliverIntoReusedFallback(ctx) → Promise<'delivered'|'event-only'|'event-failed'>
|
|
506
|
+
* A later reply on a thread whose open fallback Epic F was reused: an ACTIVE
|
|
507
|
+
* F gets the same event + prompt as a delivered reply; a PROPOSED F (no chat
|
|
508
|
+
* running yet) gets the reply as an event on its chain (allowInactive).
|
|
509
|
+
*/
|
|
510
|
+
async function deliverIntoReusedFallback({
|
|
511
|
+
sendPrompt, appendEvent, targetCwd, epicId, replierCwd, yId, y, outcome, message, referencePaths,
|
|
512
|
+
}) {
|
|
513
|
+
const f = readActiveIndex(targetCwd).sessions[epicId] || {};
|
|
514
|
+
const active = f.status === 'active';
|
|
515
|
+
const prompt = composeReplyPrompt({
|
|
516
|
+
fromCwd: replierCwd, fromEpicId: yId, fromGoalText: y.goalText, outcome, message, referencePaths,
|
|
517
|
+
});
|
|
518
|
+
let appended;
|
|
519
|
+
try {
|
|
520
|
+
appended = await appendEvent(targetCwd, epicId, prompt, {
|
|
521
|
+
notice: REPLY_NOTICE,
|
|
522
|
+
...(active ? {} : { allowInactive: true }),
|
|
523
|
+
reply: { fromCwd: replierCwd, fromEpicId: yId, outcome, referencePaths },
|
|
524
|
+
});
|
|
525
|
+
} catch { appended = null; }
|
|
526
|
+
if (!appended || !appended.ok) return 'event-failed';
|
|
527
|
+
if (!active) return 'event-only';
|
|
528
|
+
let sendResult;
|
|
529
|
+
try {
|
|
530
|
+
sendResult = await sendPrompt(epicId, prompt, { sessionId: f.claudeSessionId, cwd: f.cwd || targetCwd });
|
|
531
|
+
} catch { sendResult = null; }
|
|
532
|
+
const d = sendResult && sendResult.disposition;
|
|
533
|
+
return d === 'sent' || d === 'queued' ? 'delivered' : 'event-only';
|
|
534
|
+
}
|
|
535
|
+
|
|
373
536
|
/**
|
|
374
537
|
* resolveThread(src) — pure. The thread a replying Epic's `source` names:
|
|
375
538
|
* { ok: true, thread: { cwd, epicId, claudeSessionId }, legacy } or { ok: false, error }.
|
|
376
|
-
* A complete replyTo → legacy false
|
|
539
|
+
* A complete replyTo → legacy false; a replyTo with mode 'event' needs only a cwd
|
|
540
|
+
* (→ mode: 'event'). A pre-reply-thread request Epic (no
|
|
377
541
|
* replyTo key, no replyOf, fromCwd + fromEpicId set) → legacy true, no
|
|
378
542
|
* session pin. Every refusal says why and points at feedback_open_session.
|
|
379
543
|
*/
|
|
@@ -381,6 +545,19 @@ function resolveThread(src) {
|
|
|
381
545
|
const s = src && typeof src === 'object' ? src : {};
|
|
382
546
|
const isRequest = s.producer === 'cross-project-feedback';
|
|
383
547
|
const rt = s.replyTo;
|
|
548
|
+
// Event mode needs only the asker's cwd; epicId/claudeSessionId may be null.
|
|
549
|
+
if (isRequest && rt && typeof rt === 'object' && rt.mode === 'event' && nonEmpty(rt.cwd)) {
|
|
550
|
+
return {
|
|
551
|
+
ok: true,
|
|
552
|
+
thread: {
|
|
553
|
+
cwd: rt.cwd,
|
|
554
|
+
epicId: nonEmpty(rt.epicId) ? rt.epicId : null,
|
|
555
|
+
claudeSessionId: nonEmpty(rt.claudeSessionId) ? rt.claudeSessionId : null,
|
|
556
|
+
},
|
|
557
|
+
legacy: false,
|
|
558
|
+
mode: 'event',
|
|
559
|
+
};
|
|
560
|
+
}
|
|
384
561
|
if (isRequest && rt && typeof rt === 'object'
|
|
385
562
|
&& nonEmpty(rt.cwd) && nonEmpty(rt.epicId) && nonEmpty(rt.claudeSessionId)) {
|
|
386
563
|
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));
|