claude-code-session-manager 0.141.0 → 0.143.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 +76 -153
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BO4jDVGO.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DTttbvPb.js} +1 -1
- package/dist/assets/HomeClaudeConfig-DADP5bfn.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-B_D4Bg7L.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-DPnDJKcr.js} +7 -7
- package/dist/assets/Scheduler-CNLjn90m.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-D1b2aiol.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-cfV7sgk6.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-DVXtEIVy.js} +1 -1
- package/dist/assets/Toggle-CYajnSdx.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-DJ4gGRuE.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-D3MoHY2U.js} +1 -1
- package/dist/assets/index-CdTppjKR.js +3133 -0
- package/dist/assets/{index-DKXdXfka.css → index-DVHIHoJf.css} +1 -1
- package/dist/index.html +2 -2
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +496 -484
- package/package.json +6 -4
- package/plugins/AGENTS.md +4 -3
- package/plugins/session-manager-dev/.claude-plugin/plugin.json +1 -1
- package/plugins/session-manager-dev/hooks/hooks.json +15 -0
- package/plugins/session-manager-dev/hooks/residue-check.cjs +241 -0
- package/plugins/session-manager-dev/skills/builder/SKILL.md +5 -0
- package/plugins/session-manager-dev/skills/develop/SKILL.md +58 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +2 -0
- package/scripts/hooks/guard-tool-risk.cjs +5 -1
- package/scripts/hooks/lib/guard-tool-risk-policy.cjs +158 -1
- package/scripts/scheduler-mcp-server.cjs +1032 -112
- package/src/main/adminRouteRegistry.cjs +69 -0
- package/src/main/agentLibrary.cjs +72 -4
- package/src/main/agentsIpc.cjs +3 -2
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +336 -23
- package/src/main/config.cjs +35 -1
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +129 -2
- package/src/main/index.cjs +110 -52
- package/src/main/ipcSchemas.cjs +172 -8
- package/src/main/lib/AGENTS.md +1 -1
- package/src/main/lib/chatBootRecovery.cjs +2 -0
- package/src/main/lib/claude/agentModelResolve.cjs +51 -25
- package/src/main/lib/claude/agentSnapshot.cjs +186 -0
- package/src/main/lib/claude/environmentProfiles.cjs +242 -0
- package/src/main/lib/claude/jobSandboxPolicy.cjs +241 -33
- package/src/main/lib/claude/personaToolScope.cjs +82 -31
- package/src/main/lib/claude/runClaudeP.cjs +4 -2
- package/src/main/lib/claude/toolRiskMarks.cjs +41 -1
- package/src/main/lib/claude/usageCircuit.cjs +49 -21
- package/src/main/lib/claude/vaultRefs.cjs +277 -0
- package/src/main/lib/demo-video-kit/capture.cjs +282 -12
- package/src/main/lib/demo-video-kit/cast.md +52 -0
- package/src/main/lib/demo-video-kit/character.cjs +778 -30
- package/src/main/lib/demo-video-kit/checks.cjs +120 -1
- package/src/main/lib/demo-video-kit/export.cjs +218 -0
- package/src/main/lib/demo-video-kit/frames.cjs +104 -9
- package/src/main/lib/demo-video-kit/kind-marketing.md +121 -0
- package/src/main/lib/demo-video-kit/kind-tiktok.md +103 -0
- package/src/main/lib/demo-video-kit/kokoroSay.cjs +205 -0
- package/src/main/lib/demo-video-kit/project-home-html.md +43 -0
- package/src/main/lib/demo-video-kit/projectSounds.cjs +191 -0
- package/src/main/lib/demo-video-kit/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- package/src/main/lib/demo-video-kit/sound.cjs +166 -9
- package/src/main/lib/demo-video-kit/standalone.cjs +231 -0
- package/src/main/lib/demo-video-kit/voiceLane.cjs +233 -0
- package/src/main/lib/demo-video-kit/voiceLibrary.cjs +312 -0
- package/src/main/lib/epic/activeIndexMerge.cjs +5 -0
- package/src/main/lib/epic/artifactAdminRoutes.cjs +211 -0
- package/src/main/lib/epic/artifactIpc.cjs +153 -0
- package/src/main/lib/epic/artifactNotice.cjs +72 -0
- package/src/main/lib/epic/artifactRetention.cjs +356 -0
- package/src/main/lib/epic/artifactStore.cjs +435 -0
- package/src/main/lib/epic/delegationReadiness.cjs +83 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +258 -0
- package/src/main/lib/epic/epicMint.cjs +43 -1
- package/src/main/lib/epic/epicOutsideRead.cjs +1 -0
- package/src/main/lib/epic/epicOutsideState.cjs +18 -4
- package/src/main/lib/epic/epicPurge.cjs +347 -0
- package/src/main/lib/epic/epicReopen.cjs +5 -2
- package/src/main/lib/epic/epicSettle.cjs +4 -13
- package/src/main/lib/epic/epicSpawnPlan.cjs +57 -4
- package/src/main/lib/epic/epicStateEmitter.cjs +248 -0
- package/src/main/lib/epic/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +94 -4
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +48 -4
- package/src/main/lib/feedback-remote/autoStartedSession.cjs +1 -1
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +478 -127
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +16 -3
- package/src/main/lib/feedback-remote/customerFeedbackClient.cjs +11 -6
- package/src/main/lib/feedback-remote/customerFeedbackInbox.cjs +26 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +5 -2
- package/src/main/lib/feedback-remote/feedbackBoxDrain.cjs +409 -0
- package/src/main/lib/feedback-remote/feedbackBoxKeys.cjs +218 -0
- package/src/main/lib/feedback-remote/feedbackEnvelope.cjs +163 -0
- package/src/main/lib/feedback-remote/feedbackRelayClient.cjs +164 -0
- package/src/main/lib/feedback-remote/feedbackReport.cjs +234 -0
- package/src/main/lib/feedback-remote/feedbackSeal.cjs +217 -0
- package/src/main/lib/feedback-remote/localAdminHttp.cjs +108 -2
- package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +32 -1
- package/src/main/lib/feedback-remote/needsYouIpc.cjs +17 -0
- package/src/main/lib/feedback-remote/needsYouStore.cjs +177 -6
- package/src/main/lib/feedback-remote/pendingReplies.cjs +207 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +282 -14
- package/src/main/lib/feedback-remote/replyClaims.cjs +159 -0
- package/src/main/lib/feedback-remote/serviceClient.cjs +429 -0
- package/src/main/lib/feedback-remote/serviceMcpSession.cjs +252 -0
- package/src/main/lib/feedback-remote/serviceMcpTools.cjs +284 -0
- package/src/main/lib/feedback-remote/servicePairings.cjs +313 -0
- package/src/main/lib/feedback-remote/serviceStdioBridge.cjs +290 -0
- package/src/main/lib/feedback-remote/siteFeedbackAdminRoutes.cjs +295 -0
- package/src/main/lib/feedback-remote/siteFeedbackInbox.cjs +598 -0
- package/src/main/lib/feedback-remote/siteFeedbackIpc.cjs +86 -0
- package/src/main/lib/feedback-remote/siteFeedbackService.cjs +477 -0
- package/src/main/lib/git/gitWorktree.cjs +8 -0
- package/src/main/lib/git/runtimeStateUntrack.cjs +15 -1
- package/src/main/lib/git/worktreeDeps.cjs +182 -4
- package/src/main/lib/mcpToolCatalog.cjs +399 -29
- package/src/main/lib/opsOwnership.cjs +141 -28
- package/src/main/lib/opsRetentionSettings.cjs +27 -5
- package/src/main/lib/persona-macro/builtinMacros.cjs +7 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +52 -8
- package/src/main/lib/persona-macro/macroJobIpc.cjs +16 -6
- package/src/main/lib/persona-macro/macroLibrary.cjs +49 -7
- package/src/main/lib/persona-macro/personaFrontmatterSchema.cjs +83 -0
- package/src/main/lib/persona-macro/projectVideoToolCheck.cjs +3 -0
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +309 -0
- package/src/main/lib/phaseProjection.cjs +103 -0
- package/src/main/lib/prd/depSlugResolve.cjs +4 -13
- package/src/main/lib/prd/prdBodyPatch.cjs +12 -17
- package/src/main/lib/prd/prdCreate.cjs +387 -228
- package/src/main/lib/prd/prdCriteria.cjs +228 -0
- package/src/main/lib/prd/prdFrontmatter.cjs +43 -3
- package/src/main/lib/prd/prdGateFiles.cjs +125 -49
- package/src/main/lib/prd/prdSizing.cjs +3 -1
- package/src/main/lib/process/cleanEnv.cjs +52 -1
- package/src/main/lib/process/leftoverRenice.cjs +178 -0
- package/src/main/lib/process/memoryScope.cjs +31 -3
- package/src/main/lib/project-pages/pagesLibrary.cjs +72 -6
- package/src/main/lib/project-pages/videoPressLines.cjs +145 -0
- package/src/main/lib/project-pages/videoReviewIpc.cjs +3 -2
- package/src/main/lib/project-pages/videoScriptPress.cjs +260 -0
- package/src/main/lib/project-pages/videoScriptRunRoute.cjs +351 -0
- package/src/main/lib/project-pages/videoScriptSwitchIpc.cjs +49 -0
- package/src/main/lib/project-pages/videoScriptSwitchRoute.cjs +173 -0
- package/src/main/lib/project-pages/voiceAdminRoutes.cjs +175 -0
- package/src/main/lib/project-pages/voicePreview.cjs +196 -0
- package/src/main/lib/project-pages/voicesIpc.cjs +186 -0
- package/src/main/lib/promptSessionSchema.cjs +6 -0
- package/src/main/lib/scheduler/cancelledRow.cjs +57 -0
- package/src/main/lib/scheduler/cpuSample.cjs +133 -42
- package/src/main/lib/scheduler/criteriaChecks.cjs +313 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/heldSchedulerTurns.cjs +238 -0
- package/src/main/lib/scheduler/jobMemoryStats.cjs +324 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +152 -54
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +191 -0
- package/src/main/lib/scheduler/queueStore.cjs +16 -0
- package/src/main/lib/scheduler/rcaReport.cjs +79 -15
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +18 -0
- package/src/main/lib/scheduler/scheduleJobTransitions.cjs +47 -0
- package/src/main/lib/scheduler/schedulerConfig.cjs +47 -0
- package/src/main/lib/scheduler/schedulerPaths.cjs +9 -3
- package/src/main/lib/scheduler/schedulerRuntimeState.cjs +50 -1
- package/src/main/lib/scheduler/sessionSlots.cjs +5 -1
- package/src/main/lib/scheduler/slotsRoute.cjs +251 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/usageHoldRoute.cjs +97 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +152 -11
- package/src/main/lib/tasks/memoryConsolidation.cjs +312 -0
- package/src/main/lib/tasks/mitigationReview.cjs +314 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +390 -25
- package/src/main/lib/tasks/taskIpc.cjs +22 -18
- package/src/main/lib/tasks/taskLedger.cjs +147 -25
- package/src/main/lib/tasks/taskRun.cjs +186 -17
- package/src/main/lib/tasks/taskSwitch.cjs +85 -12
- package/src/main/lib/tasks/taskSwitchRoute.cjs +172 -0
- package/src/main/lib/telemetry/auditEvents.cjs +204 -6
- package/src/main/lib/telemetry/auditLog.cjs +6 -2
- package/src/main/lib/telemetry/eventsAdminRoutes.cjs +198 -6
- package/src/main/lib/telemetry/webhookDelivery.cjs +205 -0
- package/src/main/lib/telemetry/webhookRegistry.cjs +281 -0
- package/src/main/lib/toolUseClassify.cjs +181 -0
- package/src/main/lib/util/atomicFs.cjs +2 -2
- package/src/main/lib/util/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +21 -1
- package/src/main/pty.cjs +77 -0
- package/src/main/queueOps.cjs +33 -14
- package/src/main/runVerify.cjs +74 -9
- package/src/main/scheduler/AGENTS.md +1 -0
- package/src/main/scheduler/budget.cjs +6 -5
- package/src/main/scheduler/prdParser.cjs +46 -13
- package/src/main/scheduler/reviewLadder.cjs +9 -25
- package/src/main/scheduler/utilizationHold.cjs +191 -0
- package/src/main/scheduler.cjs +1932 -213
- package/src/main/templates/PRD_AUTHORING.md +11 -3
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +576 -39
- package/src/preload/apiSurface.json +223 -7
- package/src/preload/index.cjs +48 -1
- package/src/seed/agents/architect.md +6 -1
- package/src/seed/agents/blender-artist.md +2 -1
- package/src/seed/agents/competitive-analyst.md +3 -1
- package/src/seed/agents/competitive-researcher.md +2 -1
- package/src/seed/agents/demo-video-builder.md +98 -87
- package/src/seed/agents/dev-lead.md +3 -3
- package/src/seed/agents/project-home-builder.md +9 -31
- package/src/seed/agents/validator.md +23 -23
- package/dist/assets/AppSettings-DExeJhqQ.js +0 -2
- package/dist/assets/HomeClaudeConfig-CTp2tkZ4.js +0 -3
- package/dist/assets/Scheduler-cyr61UAC.js +0 -16
- package/dist/assets/ViewTabs-DXhOWFG0.js +0 -1
- package/dist/assets/index-B2TQz3nd.js +0 -3121
- package/src/main/lib/epic/epicStateWatcher.cjs +0 -157
package/src/main/chatRunner.cjs
CHANGED
|
@@ -19,6 +19,8 @@ const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
|
|
|
19
19
|
* — pure parser for `/context`
|
|
20
20
|
* STOP_SENTINEL: string — exported for tests
|
|
21
21
|
* __setExecutor(fn): void — test seam
|
|
22
|
+
* recordNeedsInput / recordAnswerIfOpen — Epic event log: job.needs_input
|
|
23
|
+
* on a stop-signal turn, human.answer on the reply
|
|
22
24
|
*
|
|
23
25
|
* IPC events broadcast to the renderer:
|
|
24
26
|
* chat:run:queued { tabId, sessionId, position } — waiting behind a busy lane
|
|
@@ -39,9 +41,9 @@ const { sendIfAlive } = require('./lib/sendToRenderer.cjs');
|
|
|
39
41
|
const { spawn } = require('node:child_process');
|
|
40
42
|
const { ipcMain } = require('electron');
|
|
41
43
|
const { resolveClaudeBin, claudeSpawnTarget } = require('./lib/claude/claudeBin.cjs');
|
|
42
|
-
const { cleanChildEnv, pathWithUserBins } = require('./lib/process/cleanEnv.cjs');
|
|
44
|
+
const { cleanChildEnv, pathWithUserBins, assertNoCredentials } = require('./lib/process/cleanEnv.cjs');
|
|
43
45
|
const { recordExchange, formatAskedResult } = require('./exchanges.cjs');
|
|
44
|
-
const { classifyToolUse } = require('./lib/toolUseClassify.cjs');
|
|
46
|
+
const { classifyToolUse, humanMessageSummary } = require('./lib/toolUseClassify.cjs');
|
|
45
47
|
const { extractJson } = require('./lib/util/extractJson.cjs');
|
|
46
48
|
const { classifyPromptTicket } = require('./lib/classifyPromptTicket.cjs');
|
|
47
49
|
const sessionSlots = require('./lib/scheduler/sessionSlots.cjs');
|
|
@@ -53,7 +55,7 @@ const { developLoopOffSettingsArgs } = require('./lib/epic/developLoopSpawn.cjs'
|
|
|
53
55
|
// Called through the module object (not destructured) so tests can inject a catalog.
|
|
54
56
|
const packSpawnArgs = require('./lib/packs/packSpawnArgs.cjs');
|
|
55
57
|
const { resolveEpicEffort, effortArgs } = require('./lib/claude/agentEffortResolve.cjs');
|
|
56
|
-
const { planEpicSpawn } = require('./lib/epic/epicSpawnPlan.cjs');
|
|
58
|
+
const { planEpicSpawn, resolveEpicTurnModel } = require('./lib/epic/epicSpawnPlan.cjs');
|
|
57
59
|
const epicWorktreeMint = require('./lib/epic/epicWorktreeMint.cjs');
|
|
58
60
|
const logs = require('./logs.cjs');
|
|
59
61
|
const chatInflight = require('./lib/chatInflight.cjs');
|
|
@@ -63,6 +65,10 @@ const { createHeadTailBuffer } = require('./lib/util/headTailBuffer.cjs');
|
|
|
63
65
|
const { isNonClaudeAgentCli } = require('./lib/agent-cli/agentCliEvents.cjs');
|
|
64
66
|
const { planAgentCliTurn } = require('./lib/agent-cli/agentCliTurn.cjs');
|
|
65
67
|
const { writeNativeSession } = require('./lib/agent-cli/agentCliSessionStore.cjs');
|
|
68
|
+
// Module object (not destructured) so tests can stub the append.
|
|
69
|
+
const epicEventLog = require('./lib/epic/epicEventLog.cjs');
|
|
70
|
+
const artifactStore = require('./lib/epic/artifactStore.cjs');
|
|
71
|
+
const { postArtifactReadyNotice } = require('./lib/epic/artifactNotice.cjs');
|
|
66
72
|
|
|
67
73
|
// Caps on per-run stream buffers (a run can last hours).
|
|
68
74
|
const STDERR_TAIL_MAX = 64 * 1024;
|
|
@@ -275,8 +281,8 @@ const SCHEDULER_TURN_INSTRUCTION =
|
|
|
275
281
|
`IMPORTANT: This turn was started by the scheduler and nobody is watching. ` +
|
|
276
282
|
`Never ask questions and never print ${STOP_SENTINEL}. Act on the message below with ` +
|
|
277
283
|
`the /develop skill's Phase 2 rules (reset, fix the spec, archive, or queue a fix wave). ` +
|
|
278
|
-
`
|
|
279
|
-
`of what you did.\n\n`;
|
|
284
|
+
`Give everything left open an outcome (queue, decide, schedule or close it), and end ` +
|
|
285
|
+
`with a short report of what you did.\n\n`;
|
|
280
286
|
|
|
281
287
|
/**
|
|
282
288
|
* Picks the instruction block that opens a turn: scheduler turns and
|
|
@@ -320,9 +326,10 @@ function consumeSchedulerPrompt(tabId, prompt) {
|
|
|
320
326
|
}
|
|
321
327
|
|
|
322
328
|
// ─── Hard wall-clock kill ceiling ────────────────────────────────────────
|
|
323
|
-
// Defined here (ahead of CHAT_MODE_TRUTH_INSTRUCTION) so
|
|
324
|
-
//
|
|
325
|
-
// duplicate that could drift from the
|
|
329
|
+
// Defined here (ahead of the relay-note TTL and CHAT_MODE_TRUTH_INSTRUCTION) so
|
|
330
|
+
// the relay TTL and the prompt's stated budget are always derived from this
|
|
331
|
+
// single constant — never a hand-written duplicate that could drift from the
|
|
332
|
+
// real timer below.
|
|
326
333
|
const KILL_CEILING_MS = 30 * 60 * 1000; // 30 minutes
|
|
327
334
|
const KILL_CEILING_MIN = KILL_CEILING_MS / 60_000;
|
|
328
335
|
// 80% warning point — gives the model a turn-visible nudge to wrap up before
|
|
@@ -330,6 +337,57 @@ const KILL_CEILING_MIN = KILL_CEILING_MS / 60_000;
|
|
|
330
337
|
// re: making KILL_CEILING_MS itself configurable.
|
|
331
338
|
const WARN_CEILING_MS = Math.floor(KILL_CEILING_MS * 0.8);
|
|
332
339
|
|
|
340
|
+
// tab+prompt keys of relayed external sends (Web Remote phone / admin API) awaiting
|
|
341
|
+
// their run(): each entry is a FIFO of relay names, consumed once per EXTERNAL run.
|
|
342
|
+
// A note only lives as long as its send can still produce a run: the ack window,
|
|
343
|
+
// plus the time a 'queued' send waits for the in-flight turn ahead of it (bounded by
|
|
344
|
+
// the kill ceiling). A send that resolves without a run drops its note at once.
|
|
345
|
+
const EXTERNAL_RELAYS = new Set(['web-remote', 'admin-api']);
|
|
346
|
+
const relayPrompts = new Map();
|
|
347
|
+
const EXTERNAL_SEND_ACK_TIMEOUT_MS = 8000;
|
|
348
|
+
const RELAY_RUN_START_WINDOW_MS = KILL_CEILING_MS;
|
|
349
|
+
const RELAY_PROMPT_TTL_MS = EXTERNAL_SEND_ACK_TIMEOUT_MS + RELAY_RUN_START_WINDOW_MS;
|
|
350
|
+
function noteRelayPrompt(tabId, prompt, relay) {
|
|
351
|
+
if (!EXTERNAL_RELAYS.has(relay)) return null;
|
|
352
|
+
const now = Date.now();
|
|
353
|
+
for (const [k, v] of relayPrompts) {
|
|
354
|
+
const live = v.filter((e) => e.expires >= now);
|
|
355
|
+
if (live.length) relayPrompts.set(k, live); else relayPrompts.delete(k);
|
|
356
|
+
}
|
|
357
|
+
const key = `${tabId}\n${prompt}`;
|
|
358
|
+
const list = relayPrompts.get(key) || [];
|
|
359
|
+
const entry = { relay, expires: now + RELAY_PROMPT_TTL_MS };
|
|
360
|
+
list.push(entry);
|
|
361
|
+
relayPrompts.set(key, list);
|
|
362
|
+
return entry;
|
|
363
|
+
}
|
|
364
|
+
// Removes exactly one send's note (by identity) — a same-text note of another send stays.
|
|
365
|
+
function dropRelayPrompt(tabId, prompt, entry) {
|
|
366
|
+
const key = `${tabId}\n${prompt}`;
|
|
367
|
+
const list = relayPrompts.get(key);
|
|
368
|
+
if (!list) return;
|
|
369
|
+
const i = list.indexOf(entry);
|
|
370
|
+
if (i >= 0) list.splice(i, 1);
|
|
371
|
+
if (!list.length) relayPrompts.delete(key);
|
|
372
|
+
}
|
|
373
|
+
function relayNoteCount(tabId, prompt) {
|
|
374
|
+
const now = Date.now();
|
|
375
|
+
return (relayPrompts.get(`${tabId}\n${prompt}`) || []).filter((e) => e.expires >= now).length;
|
|
376
|
+
}
|
|
377
|
+
function consumeRelayPrompt(tabId, prompt) {
|
|
378
|
+
const key = `${tabId}\n${prompt}`;
|
|
379
|
+
const list = relayPrompts.get(key);
|
|
380
|
+
if (!list) return null;
|
|
381
|
+
const now = Date.now();
|
|
382
|
+
let hit = null;
|
|
383
|
+
while (list.length && !hit) {
|
|
384
|
+
const e = list.shift();
|
|
385
|
+
if (e.expires >= now) hit = e.relay;
|
|
386
|
+
}
|
|
387
|
+
if (!list.length) relayPrompts.delete(key);
|
|
388
|
+
return hit;
|
|
389
|
+
}
|
|
390
|
+
|
|
333
391
|
// Instruction prepended to every prompt. Tells the agent the truth about this
|
|
334
392
|
// execution mode: this Chat tab is a one-shot headless `claude -p` run — no
|
|
335
393
|
// process survives after this turn ends, so background shells, scheduled
|
|
@@ -346,7 +404,8 @@ const CHAT_MODE_TRUTH_INSTRUCTION =
|
|
|
346
404
|
`timeout, then report the actual result. This turn is hard-killed after ` +
|
|
347
405
|
`${KILL_CEILING_MIN} minutes of wall-clock. Size every synchronous poll to ` +
|
|
348
406
|
`finish inside that budget; if the work cannot fit, do the part that fits, ` +
|
|
349
|
-
`report exactly what landed, and
|
|
407
|
+
`report exactly what landed, and queue or schedule what remains; only a step ` +
|
|
408
|
+
`that needs the human goes back to them. End this turn with ` +
|
|
350
409
|
`either a real result or an explicit statement that the user needs to ` +
|
|
351
410
|
`reply for the work to continue.\n\n`;
|
|
352
411
|
|
|
@@ -382,6 +441,140 @@ function releaseOrphanSession(sessionId) { orphanSessions.delete(sessionId); pum
|
|
|
382
441
|
// flight (tabId → opts). Counted by run()'s tabBusy; cancel() can drop them.
|
|
383
442
|
const pendingStart = new Map();
|
|
384
443
|
|
|
444
|
+
// ─── Epic event log: questions and answers ────────────────────────────────
|
|
445
|
+
// An Epic chat's sessionId IS its Epic id (EPIC : CLI session = 1:1). A run
|
|
446
|
+
// that ends on the stop signal appends job.needs_input (Epic-level: no slug)
|
|
447
|
+
// with the parsed questions; the next human-sent prompt on that session is
|
|
448
|
+
// the answer and appends human.answer. Fire-and-forget: an event-log failure
|
|
449
|
+
// never breaks a chat turn.
|
|
450
|
+
|
|
451
|
+
/** sessionId → { cwd, questions } for a question still waiting on a human. */
|
|
452
|
+
const openQuestions = new Map();
|
|
453
|
+
|
|
454
|
+
function appendChatEpicEvent(cwd, epicId, event) {
|
|
455
|
+
if (typeof cwd !== 'string' || !cwd || typeof epicId !== 'string' || !epicId) return Promise.resolve(null);
|
|
456
|
+
let p;
|
|
457
|
+
try {
|
|
458
|
+
p = epicEventLog.appendEpicEvent(cwd, epicId, event);
|
|
459
|
+
} catch (err) {
|
|
460
|
+
p = Promise.reject(err);
|
|
461
|
+
}
|
|
462
|
+
return Promise.resolve(p).catch((err) => {
|
|
463
|
+
console.error('[chatRunner] epic event append failed', event?.kind, err?.message ?? err);
|
|
464
|
+
return null;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Poke the Epic outside-state emitter (lib/epic/epicStateEmitter.cjs) at a
|
|
470
|
+
* turn's acceptance and settle — the only moments that time the 'working' and
|
|
471
|
+
* 'needs_input' outside states. Lazy require; never throws, never alters a turn.
|
|
472
|
+
*/
|
|
473
|
+
function pokeState(cwd, sessionId) {
|
|
474
|
+
if (typeof cwd !== 'string' || !cwd || typeof sessionId !== 'string' || !sessionId) return;
|
|
475
|
+
try {
|
|
476
|
+
require('./lib/epic/epicStateEmitter.cjs').pokeEpicState(cwd, sessionId);
|
|
477
|
+
} catch (err) {
|
|
478
|
+
console.error('[chatRunner] epic state poke failed', sessionId, err?.message ?? err);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/** Staging folder for a chat session's artifacts, or null (unsafe id / mkdir failure — logged). */
|
|
483
|
+
function chatArtifactsDir(sessionId) {
|
|
484
|
+
try {
|
|
485
|
+
return artifactStore.stagingDirFor({ runId: sessionId });
|
|
486
|
+
} catch (err) {
|
|
487
|
+
console.error('[chatRunner] artifact staging dir unavailable', sessionId, err?.message ?? err);
|
|
488
|
+
return null;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Ingest a finished turn's staging folder into artifacts/<epic-id>/. An Epic chat's sessionId IS
|
|
494
|
+
* its Epic id. Fire-and-forget: errors and skipped files are logged, never thrown.
|
|
495
|
+
*/
|
|
496
|
+
function ingestChatArtifacts({ cwd, sessionId, srcDir }) {
|
|
497
|
+
let p;
|
|
498
|
+
try {
|
|
499
|
+
p = artifactStore.ingestDir({ projectRoot: cwd, epicId: sessionId, srcDir, producer: { epicId: sessionId, sessionId } });
|
|
500
|
+
} catch (err) {
|
|
501
|
+
p = Promise.reject(err);
|
|
502
|
+
}
|
|
503
|
+
return Promise.resolve(p).then(async (res) => {
|
|
504
|
+
for (const s of res?.skipped || []) console.error('[chatRunner] artifact not ingested', s.path, s.reason);
|
|
505
|
+
// One 'artifact-ready' notice per ingest batch, only when something landed (never throws).
|
|
506
|
+
if (res && Array.isArray(res.published) && res.published.length > 0) {
|
|
507
|
+
await postArtifactReadyNotice({ cwd, epicId: sessionId, entries: res.published });
|
|
508
|
+
}
|
|
509
|
+
return res;
|
|
510
|
+
}).catch((err) => {
|
|
511
|
+
console.error('[chatRunner] artifact ingest failed', sessionId, err?.message ?? err);
|
|
512
|
+
return null;
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Append job.needs_input for an Epic chat turn that asked questions and
|
|
518
|
+
* remember them so the next human prompt is recorded as the answer.
|
|
519
|
+
* @param {{ cwd: string, sessionId: string, questions: string[], answerBody?: string }} args
|
|
520
|
+
*/
|
|
521
|
+
function recordNeedsInput({ cwd, sessionId, questions, answerBody }) {
|
|
522
|
+
const qs = Array.isArray(questions) ? questions.filter((q) => typeof q === 'string') : [];
|
|
523
|
+
openQuestions.set(sessionId, { cwd, questions: qs });
|
|
524
|
+
return appendChatEpicEvent(cwd, sessionId, {
|
|
525
|
+
kind: 'job.needs_input',
|
|
526
|
+
source: 'chat',
|
|
527
|
+
sessionId,
|
|
528
|
+
questions: qs,
|
|
529
|
+
...(typeof answerBody === 'string' && answerBody ? { answerBody } : {}),
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Append human.answer when a human-sent prompt answers this session's open
|
|
535
|
+
* questions. Scheduler-originated prompts are not answers (the question stays
|
|
536
|
+
* open). Returns the append promise, or null when nothing was open.
|
|
537
|
+
* @param {{ cwd?: string, sessionId: string, prompt: string, origin?: string }} args
|
|
538
|
+
*/
|
|
539
|
+
function recordAnswerIfOpen({ cwd, sessionId, prompt, origin }) {
|
|
540
|
+
const open = openQuestions.get(sessionId);
|
|
541
|
+
if (!open || origin === 'scheduler') return null;
|
|
542
|
+
openQuestions.delete(sessionId);
|
|
543
|
+
return appendChatEpicEvent(cwd || open.cwd, sessionId, {
|
|
544
|
+
kind: 'human.answer',
|
|
545
|
+
source: 'chat',
|
|
546
|
+
sessionId,
|
|
547
|
+
questions: open.questions,
|
|
548
|
+
answer: typeof prompt === 'string' ? prompt : '',
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Append the message event for a prompt on an Epic chat (sessionId = Epic id):
|
|
554
|
+
* - origin 'human' (a desktop composer submit) → human.message { via: 'desktop' };
|
|
555
|
+
* - origin 'external' tagged relay 'web-remote' (the paired phone) → human.message { via: 'web-remote' };
|
|
556
|
+
* - origin 'external' tagged relay 'admin-api' (POST /admin/chat/send-prompt, which
|
|
557
|
+
* agents also call) → external.message { via: 'admin-api' }.
|
|
558
|
+
* The relay tag is noted by enqueueExternalPrompt and consumed once by run().
|
|
559
|
+
* Untagged external, 'scheduler', 'inbound-proposal', no origin and a boot-recovery
|
|
560
|
+
* re-send (chatBootRecovery.cjs stamps bootRecovery: true) log nothing. This is the
|
|
561
|
+
* event log only — the auto-approval human-prompt ledger (noteChatRunOrigin) still
|
|
562
|
+
* counts origin 'human' alone. Fire-and-forget; a failure is logged by
|
|
563
|
+
* appendChatEpicEvent, never thrown.
|
|
564
|
+
* @param {{ cwd?: string, sessionId: string, prompt: string, origin?: string, bootRecovery?: boolean, relay?: string | null }} args
|
|
565
|
+
*/
|
|
566
|
+
function recordHumanMessage({ cwd, sessionId, prompt, origin, bootRecovery, relay }) {
|
|
567
|
+
if (bootRecovery === true) return null;
|
|
568
|
+
let kind; let via;
|
|
569
|
+
if (origin === 'human') { kind = 'human.message'; via = 'desktop'; }
|
|
570
|
+
else if (origin === 'external' && relay === 'web-remote') { kind = 'human.message'; via = 'web-remote'; }
|
|
571
|
+
else if (origin === 'external' && relay === 'admin-api') { kind = 'external.message'; via = 'admin-api'; }
|
|
572
|
+
else return null;
|
|
573
|
+
let summary;
|
|
574
|
+
try { summary = humanMessageSummary(prompt); } catch { return null; }
|
|
575
|
+
return appendChatEpicEvent(cwd, sessionId, { kind, source: 'chat', sessionId, via, ...summary });
|
|
576
|
+
}
|
|
577
|
+
|
|
385
578
|
// Indirection so tests can stub the spawn without launching claude.
|
|
386
579
|
let executor = executeRun;
|
|
387
580
|
function __setExecutor(fn) { executor = fn || executeRun; }
|
|
@@ -399,6 +592,8 @@ function __resetQueueForTests() {
|
|
|
399
592
|
orphanSessions.clear();
|
|
400
593
|
waiting.length = 0;
|
|
401
594
|
pendingStart.clear();
|
|
595
|
+
openQuestions.clear();
|
|
596
|
+
relayPrompts.clear();
|
|
402
597
|
sessionSlots.__resetForTests();
|
|
403
598
|
}
|
|
404
599
|
|
|
@@ -429,6 +624,10 @@ function run(opts) {
|
|
|
429
624
|
// A scheduler-originated prompt (tagged by enqueueExternalPrompt) is re-identified
|
|
430
625
|
// here by tab + exact text, since it travels through the renderer's chat:run.
|
|
431
626
|
if (!opts.silent && consumeSchedulerPrompt(opts.tabId, opts.prompt)) opts = { ...opts, origin: 'scheduler' };
|
|
627
|
+
// A relayed external send (Web Remote / admin API) is re-identified the same way;
|
|
628
|
+
// the relay only picks the event-log kind, never the origin. Only an external run
|
|
629
|
+
// takes a note: a same-text desktop prompt must not steal a queued phone send's tag.
|
|
630
|
+
if (!opts.silent && opts.origin === 'external' && opts.relay === undefined) opts = { ...opts, relay: consumeRelayPrompt(opts.tabId, opts.prompt) };
|
|
432
631
|
// Per-tab exclusivity still holds — two `claude -p --resume` against ONE
|
|
433
632
|
// sessionId must never overlap — but it is now enforced in pump() (which
|
|
434
633
|
// refuses to start a run for a tab that already has one live) rather than by
|
|
@@ -453,6 +652,13 @@ function run(opts) {
|
|
|
453
652
|
// still dropped, since queueing one would delay real work to no benefit.
|
|
454
653
|
return { accepted: false, reason: 'tab-busy-silent' };
|
|
455
654
|
}
|
|
655
|
+
// A human prompt sent after a needs-input turn is that question's answer.
|
|
656
|
+
if (!opts.silent) recordAnswerIfOpen(opts);
|
|
657
|
+
// Once per prompt: the held-for-worktree re-entry below carries the mark.
|
|
658
|
+
if (!opts.silent && !opts.humanMessageRecorded) {
|
|
659
|
+
recordHumanMessage(opts);
|
|
660
|
+
opts = { ...opts, humanMessageRecorded: true };
|
|
661
|
+
}
|
|
456
662
|
|
|
457
663
|
// A New Epic's turn 1 races the fire-and-forget worktree mint: only when a mint is
|
|
458
664
|
// actually in flight for this Epic, hold the submission (<=90s, never rejects) so the
|
|
@@ -466,11 +672,13 @@ function run(opts) {
|
|
|
466
672
|
pendingStart.delete(opts.tabId);
|
|
467
673
|
run({ ...opts, worktreeDirHint: wt && wt.dir ? wt.dir : undefined });
|
|
468
674
|
});
|
|
675
|
+
if (!opts.silent) pokeState(opts.cwd, opts.sessionId);
|
|
469
676
|
return { accepted: true, queued: tabBusy };
|
|
470
677
|
}
|
|
471
678
|
|
|
472
679
|
waiting.push(opts);
|
|
473
680
|
pump();
|
|
681
|
+
if (!opts.silent) pokeState(opts.cwd, opts.sessionId);
|
|
474
682
|
return { accepted: true, queued: tabBusy };
|
|
475
683
|
}
|
|
476
684
|
|
|
@@ -510,6 +718,7 @@ function pump() {
|
|
|
510
718
|
liveSessions.delete(job.sessionId);
|
|
511
719
|
sessionSlots.release(slotToken);
|
|
512
720
|
pump();
|
|
721
|
+
if (!job.silent) pokeState(job.cwd, job.sessionId);
|
|
513
722
|
});
|
|
514
723
|
}
|
|
515
724
|
// Anyone still waiting gets a 1-based position update. Silent (automated
|
|
@@ -623,7 +832,13 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
623
832
|
// originProjectRoot on create-prd/open-session/readiness calls so those
|
|
624
833
|
// routes can resolve the right project even from a worktree pwd. See
|
|
625
834
|
// projectRootResolve.cjs.
|
|
626
|
-
|
|
835
|
+
// SM_ARTIFACTS_DIR: a per-session staging folder OUTSIDE the repo (artifactStore.stagingDirFor);
|
|
836
|
+
// whatever the agent writes there is ingested into the Artifacts store when the turn closes
|
|
837
|
+
// (ingestChatArtifacts below), so it shows in the File Explorer with no merge. runId = sessionId,
|
|
838
|
+
// the same folder the Epic's Terminal view gets (pty.cjs) — EPIC : CLI session = 1:1.
|
|
839
|
+
const artifactsDir = chatArtifactsDir(sessionId);
|
|
840
|
+
const artifactsEnv = artifactsDir ? { SM_ARTIFACTS_DIR: artifactsDir } : {};
|
|
841
|
+
const childEnv = cleanChildEnv({ PATH: pathWithUserBins(), SM_CHAT_SESSION_ID: sessionId, SM_PROJECT_ROOT: cwd, ...artifactsEnv });
|
|
627
842
|
|
|
628
843
|
// Prepend the stop-signal protocol instruction and the chat-mode truth
|
|
629
844
|
// instruction to every prompt
|
|
@@ -639,7 +854,9 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
639
854
|
// throws; falls back to the hardcoded 'sonnet' literal when there's no
|
|
640
855
|
// Epic, no agentType, or the persona has no model/'inherit' — --model
|
|
641
856
|
// must never be left unpinned (CLAUDE.md model-pinning rule).
|
|
642
|
-
|
|
857
|
+
// A pinned Epic (agentSnapshotId, epicSpawnPlan.cjs's resolveEpicTurnModel) takes its model
|
|
858
|
+
// from the AgentSnapshot frozen at mint, so a later persona edit never reaches it.
|
|
859
|
+
const model = isAgentCli ? null : resolveEpicTurnModel({ cwd, claudeSessionId: sessionId });
|
|
643
860
|
// Persona `effort:` (same overlay-aware persona, agentEffortResolve.cjs);
|
|
644
861
|
// effortArgs() yields NO tokens for inherit/absent/dangling.
|
|
645
862
|
const effortFlags = isAgentCli ? [] : effortArgs(resolveEpicEffort({ cwd, claudeSessionId: sessionId }).effort);
|
|
@@ -700,7 +917,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
700
917
|
}
|
|
701
918
|
}
|
|
702
919
|
const agentEnv = agentPlan
|
|
703
|
-
? cleanChildEnv({ PATH: pathWithUserBins(), SM_CHAT_SESSION_ID: sessionId, SM_PROJECT_ROOT: cwd, ...agentPlan.envExtra })
|
|
920
|
+
? cleanChildEnv({ PATH: pathWithUserBins(), SM_CHAT_SESSION_ID: sessionId, SM_PROJECT_ROOT: cwd, ...artifactsEnv, ...agentPlan.envExtra })
|
|
704
921
|
: null;
|
|
705
922
|
|
|
706
923
|
const useResume = plan.useResume;
|
|
@@ -837,6 +1054,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
837
1054
|
target = { ...target, command: wrapped.command, args: wrapped.args, argv0: undefined };
|
|
838
1055
|
}
|
|
839
1056
|
}
|
|
1057
|
+
assertNoCredentials(agentPlan ? agentEnv : childEnv, { site: agentPlan ? 'chat-agent' : 'chat' });
|
|
840
1058
|
if (agentPlan) agentPlan.transcript.userPrompt(fullPrompt);
|
|
841
1059
|
thisChild = spawn(target.command, target.args || chatArgs, {
|
|
842
1060
|
...(target.argv0 ? { argv0: target.argv0 } : {}),
|
|
@@ -934,6 +1152,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
934
1152
|
answerBody: signal.answerBody,
|
|
935
1153
|
raw: text,
|
|
936
1154
|
});
|
|
1155
|
+
recordNeedsInput({ cwd, sessionId, questions: signal.questions, answerBody: signal.answerBody });
|
|
937
1156
|
// Record durable exchange off the hot path — UI must not wait on Haiku
|
|
938
1157
|
recordExchange({
|
|
939
1158
|
sessionId,
|
|
@@ -1118,6 +1337,7 @@ function executeRun({ tabId, sessionId, prompt, cwd, resume, silent, onSilentRes
|
|
|
1118
1337
|
}, { code: 'exit-no-result' });
|
|
1119
1338
|
}
|
|
1120
1339
|
}
|
|
1340
|
+
if (artifactsDir) ingestChatArtifacts({ cwd, sessionId, srcDir: artifactsDir });
|
|
1121
1341
|
settle();
|
|
1122
1342
|
});
|
|
1123
1343
|
};
|
|
@@ -1170,8 +1390,17 @@ function cancel(tabId) {
|
|
|
1170
1390
|
// directly, reusing send()'s existing queued-vs-immediate branching rather
|
|
1171
1391
|
// than duplicating it here.
|
|
1172
1392
|
|
|
1173
|
-
const EXTERNAL_SEND_ACK_TIMEOUT_MS = 8000;
|
|
1174
1393
|
const pendingExternalSends = new Map(); // requestId -> { resolve, timer }
|
|
1394
|
+
// requestId -> expiry timer. A send that timed out may still be acked by the
|
|
1395
|
+
// renderer; a late ack that produced a run confirms the held-turn entries it carried.
|
|
1396
|
+
const timedOutExternalSends = new Map();
|
|
1397
|
+
const TIMED_OUT_SEND_TTL_MS = 10 * 60 * 1000;
|
|
1398
|
+
|
|
1399
|
+
function rememberTimedOutSend(requestId) {
|
|
1400
|
+
const t = setTimeout(() => { timedOutExternalSends.delete(requestId); }, TIMED_OUT_SEND_TTL_MS);
|
|
1401
|
+
t.unref?.();
|
|
1402
|
+
timedOutExternalSends.set(requestId, t);
|
|
1403
|
+
}
|
|
1175
1404
|
|
|
1176
1405
|
function hasLiveWindow() {
|
|
1177
1406
|
try {
|
|
@@ -1181,17 +1410,73 @@ function hasLiveWindow() {
|
|
|
1181
1410
|
|
|
1182
1411
|
/**
|
|
1183
1412
|
* Resolves { disposition, reason? } once the renderer reports what it did, or
|
|
1184
|
-
* { disposition: 'unconfirmed', reason: '
|
|
1413
|
+
* { disposition: 'unconfirmed', reason: 'no-window' } / { disposition: 'unconfirmed',
|
|
1414
|
+
* reason: 'timeout', requestId } (a late ack may still confirm a held batch). Never rejects.
|
|
1415
|
+
*/
|
|
1416
|
+
// tabId -> identity key of the usage hold last audited for it (one audit per tab per hold).
|
|
1417
|
+
const heldTurnAuditKeys = new Map();
|
|
1418
|
+
|
|
1419
|
+
function schedulerHoldKey(hold) {
|
|
1420
|
+
try {
|
|
1421
|
+
const { holdIdentityKey } = require('./scheduler/utilizationHold.cjs');
|
|
1422
|
+
if (typeof holdIdentityKey === 'function') return holdIdentityKey(hold);
|
|
1423
|
+
} catch { /* fall through to the local key */ }
|
|
1424
|
+
return `${hold.reason}|${hold.window ?? ''}|${hold.resetsAt ?? ''}`;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Usage-hold seam: a scheduler-started turn under an active hold is deferred to the
|
|
1429
|
+
* held store (no broadcast, no claude process). Returns the disposition, or null
|
|
1430
|
+
* when the turn may run now. Required lazily to keep load order safe.
|
|
1185
1431
|
*/
|
|
1432
|
+
function holdSchedulerTurn(tabId, prompt, extra) {
|
|
1433
|
+
const heldSchedulerTurns = require('./lib/scheduler/heldSchedulerTurns.cjs');
|
|
1434
|
+
const hold = heldSchedulerTurns.currentHold();
|
|
1435
|
+
if (!hold) return null;
|
|
1436
|
+
// A drain batch held again keeps its original entries; re-deferring it would
|
|
1437
|
+
// nest coalesced headers on the next delivery.
|
|
1438
|
+
if (extra.heldBatch === true) return { disposition: 'held', reason: hold.reason };
|
|
1439
|
+
const { sessionId, cwd, heldKind } = extra;
|
|
1440
|
+
const entry = heldSchedulerTurns.defer({ tabId, prompt, kind: heldKind || 'scheduler-notice', sessionId, cwd, hold });
|
|
1441
|
+
const key = schedulerHoldKey(hold);
|
|
1442
|
+
if (heldTurnAuditKeys.get(tabId) !== key) {
|
|
1443
|
+
heldTurnAuditKeys.set(tabId, key);
|
|
1444
|
+
// The turn kind is `heldKind`: appendAuditEvent spreads fields over the record,
|
|
1445
|
+
// so a `kind` field would overwrite the event kind itself.
|
|
1446
|
+
require('./lib/telemetry/auditLog.cjs').appendAuditEvent('scheduler_turn_held', {
|
|
1447
|
+
tabId,
|
|
1448
|
+
heldKind: entry.kind,
|
|
1449
|
+
reason: hold.reason ?? null,
|
|
1450
|
+
window: hold.window ?? null,
|
|
1451
|
+
percent: hold.percent ?? null,
|
|
1452
|
+
threshold: hold.threshold ?? null,
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
return { disposition: 'held', reason: hold.reason };
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1186
1458
|
function enqueueExternalPrompt(tabId, prompt, extra = {}) {
|
|
1187
|
-
const { sessionId, cwd, origin } = extra ?? {};
|
|
1459
|
+
const { sessionId, cwd, origin, relay } = extra ?? {};
|
|
1460
|
+
if (origin === 'scheduler') {
|
|
1461
|
+
const heldResult = holdSchedulerTurn(tabId, prompt, extra ?? {});
|
|
1462
|
+
if (heldResult) return Promise.resolve(heldResult);
|
|
1463
|
+
}
|
|
1188
1464
|
if (!hasLiveWindow()) return Promise.resolve({ disposition: 'unconfirmed', reason: 'no-window' });
|
|
1189
1465
|
if (origin === 'scheduler') noteSchedulerPrompt(tabId, prompt);
|
|
1466
|
+
const note = origin !== 'scheduler' && relay !== undefined ? noteRelayPrompt(tabId, prompt, relay) : null;
|
|
1190
1467
|
const requestId = require('node:crypto').randomUUID();
|
|
1191
|
-
return new Promise((
|
|
1468
|
+
return new Promise((done) => {
|
|
1469
|
+
// A send that produced no run (refused / unconfirmed) never leaves its note behind.
|
|
1470
|
+
const resolve = (result) => {
|
|
1471
|
+
if (note && (result.disposition === 'refused' || result.disposition === 'unconfirmed')) {
|
|
1472
|
+
dropRelayPrompt(tabId, prompt, note);
|
|
1473
|
+
}
|
|
1474
|
+
done(result);
|
|
1475
|
+
};
|
|
1192
1476
|
const timer = setTimeout(() => {
|
|
1193
1477
|
pendingExternalSends.delete(requestId);
|
|
1194
|
-
|
|
1478
|
+
rememberTimedOutSend(requestId);
|
|
1479
|
+
resolve({ disposition: 'unconfirmed', reason: 'timeout', requestId });
|
|
1195
1480
|
}, EXTERNAL_SEND_ACK_TIMEOUT_MS);
|
|
1196
1481
|
timer.unref?.();
|
|
1197
1482
|
pendingExternalSends.set(requestId, { resolve, timer });
|
|
@@ -1207,7 +1492,20 @@ function enqueueExternalPrompt(tabId, prompt, extra = {}) {
|
|
|
1207
1492
|
|
|
1208
1493
|
function settleExternalSend({ requestId, disposition, reason }) {
|
|
1209
1494
|
const entry = pendingExternalSends.get(requestId);
|
|
1210
|
-
if (!entry)
|
|
1495
|
+
if (!entry) {
|
|
1496
|
+
const late = timedOutExternalSends.get(requestId);
|
|
1497
|
+
if (late === undefined) return;
|
|
1498
|
+
clearTimeout(late);
|
|
1499
|
+
timedOutExternalSends.delete(requestId);
|
|
1500
|
+
if (disposition !== 'refused' && disposition !== 'unconfirmed') {
|
|
1501
|
+
try {
|
|
1502
|
+
require('./lib/scheduler/heldSchedulerTurns.cjs').confirmLateDelivery(requestId);
|
|
1503
|
+
} catch (err) {
|
|
1504
|
+
console.error('[chatRunner] confirmLateDelivery failed:', err);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return;
|
|
1508
|
+
}
|
|
1211
1509
|
clearTimeout(entry.timer);
|
|
1212
1510
|
pendingExternalSends.delete(requestId);
|
|
1213
1511
|
entry.resolve({ disposition, ...(reason !== undefined ? { reason } : {}) });
|
|
@@ -1226,7 +1524,8 @@ const EXTERNAL_NEW_SESSION_TIMEOUT_MS = 30000;
|
|
|
1226
1524
|
const pendingExternalNewSessions = new Map(); // requestId -> { resolve, timer }
|
|
1227
1525
|
|
|
1228
1526
|
/**
|
|
1229
|
-
*
|
|
1527
|
+
* Every payload key (incl. a boolean `reviewStage`) is broadcast unchanged.
|
|
1528
|
+
* @returns {Promise<{ ok: true, epicId: string, entryId?: string, slug?: string, stage?: 'review'|'final'|null } | { ok: false, reason: 'no-window'|'timeout'|'launch-failed', error: string }>}
|
|
1230
1529
|
*/
|
|
1231
1530
|
function startExternalNewSession(payload) {
|
|
1232
1531
|
if (!hasLiveWindow()) {
|
|
@@ -1244,13 +1543,20 @@ function startExternalNewSession(payload) {
|
|
|
1244
1543
|
});
|
|
1245
1544
|
}
|
|
1246
1545
|
|
|
1247
|
-
function settleExternalNewSession({ requestId, ok, epicId, error }) {
|
|
1546
|
+
function settleExternalNewSession({ requestId, ok, epicId, error, entryId, slug, stage }) {
|
|
1248
1547
|
const entry = pendingExternalNewSessions.get(requestId);
|
|
1249
1548
|
if (!entry) return;
|
|
1250
1549
|
clearTimeout(entry.timer);
|
|
1251
1550
|
pendingExternalNewSessions.delete(requestId);
|
|
1252
|
-
if (ok && epicId)
|
|
1253
|
-
|
|
1551
|
+
if (ok && epicId) {
|
|
1552
|
+
entry.resolve({
|
|
1553
|
+
ok: true,
|
|
1554
|
+
epicId,
|
|
1555
|
+
...(entryId !== undefined ? { entryId } : {}),
|
|
1556
|
+
...(slug !== undefined ? { slug } : {}),
|
|
1557
|
+
...(stage !== undefined ? { stage } : {}),
|
|
1558
|
+
});
|
|
1559
|
+
} else entry.resolve({ ok: false, reason: 'launch-failed', error: error || 'renderer could not start the session' });
|
|
1254
1560
|
}
|
|
1255
1561
|
|
|
1256
1562
|
// Read-only: is a chat turn for this tab running, being dispatched, parked
|
|
@@ -1287,7 +1593,7 @@ function registerAdminRoute(adminHttp) {
|
|
|
1287
1593
|
sendJson(res, 400, { ok: false, error: e?.message ?? 'invalid body' });
|
|
1288
1594
|
return;
|
|
1289
1595
|
}
|
|
1290
|
-
const outcome = await enqueueExternalPrompt(body.tabId, body.prompt);
|
|
1596
|
+
const outcome = await enqueueExternalPrompt(body.tabId, body.prompt, { relay: 'admin-api' });
|
|
1291
1597
|
sendJson(res, 200, {
|
|
1292
1598
|
ok: outcome.disposition !== 'refused',
|
|
1293
1599
|
disposition: outcome.disposition,
|
|
@@ -1363,6 +1669,8 @@ module.exports = {
|
|
|
1363
1669
|
shouldFollowUp,
|
|
1364
1670
|
parseStopSignal,
|
|
1365
1671
|
splitStopSignal,
|
|
1672
|
+
recordNeedsInput,
|
|
1673
|
+
recordAnswerIfOpen,
|
|
1366
1674
|
parseContextUsageMarkdown,
|
|
1367
1675
|
STOP_SENTINEL,
|
|
1368
1676
|
// Both instruction blocks are exported so the renderer's preamble splitter
|
|
@@ -1378,10 +1686,15 @@ module.exports = {
|
|
|
1378
1686
|
enqueueExternalPrompt,
|
|
1379
1687
|
settleExternalSend,
|
|
1380
1688
|
EXTERNAL_SEND_ACK_TIMEOUT_MS,
|
|
1689
|
+
RELAY_RUN_START_WINDOW_MS,
|
|
1690
|
+
RELAY_PROMPT_TTL_MS,
|
|
1691
|
+
__relayNoteCount: relayNoteCount,
|
|
1381
1692
|
requestExternalNewSession,
|
|
1382
1693
|
startExternalNewSession,
|
|
1383
1694
|
settleExternalNewSession,
|
|
1384
1695
|
isTabBusy,
|
|
1385
1696
|
EXTERNAL_NEW_SESSION_TIMEOUT_MS,
|
|
1386
1697
|
registerAdminRoute,
|
|
1698
|
+
// test-only: the chat turn-end artifact ingest (chatRunnerArtifactNotice.test.cjs)
|
|
1699
|
+
__ingestChatArtifacts: ingestChatArtifacts,
|
|
1387
1700
|
};
|
package/src/main/config.cjs
CHANGED
|
@@ -19,7 +19,7 @@ const fs = require('node:fs');
|
|
|
19
19
|
const fsp = require('node:fs/promises');
|
|
20
20
|
const path = require('node:path');
|
|
21
21
|
const os = require('node:os');
|
|
22
|
-
const { assertOpsWrite, opsPath, OWNERS, OPS_ROOT_DIR } = require('./lib/opsOwnership.cjs');
|
|
22
|
+
const { assertOpsWrite, ensureRuntimeIgnoreForPath, opsPath, OWNERS, OPS_ROOT_DIR } = require('./lib/opsOwnership.cjs');
|
|
23
23
|
const { walkImports } = require('./lib/persona-macro/personaImportHealth.cjs');
|
|
24
24
|
const chokidar = require('chokidar');
|
|
25
25
|
const logs = require('./logs.cjs');
|
|
@@ -108,6 +108,34 @@ function registerPromptSessionsRoot(p) {
|
|
|
108
108
|
addAllowedRoot(abs.slice(0, idx));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/**
|
|
112
|
+
* markCompleted's status edge, main side. The renderer's markCompleted lands
|
|
113
|
+
* the completion durably by writing the Epic's archive
|
|
114
|
+
* (`prompt-sessions/<epicId>.json`, `session.status === 'completed'`) through
|
|
115
|
+
* config:write-json. That write IS the active/proposed -> completed edge, so
|
|
116
|
+
* it goes through lib/epic/epicTransitions.cjs's transitionEpic (prior status
|
|
117
|
+
* read from the mirror the archive is about to overwrite). An illegal edge
|
|
118
|
+
* throws, so the archive write is refused. A non-archive write, or any other
|
|
119
|
+
* path, passes through untouched. Required lazily: epicTransitions pulls in
|
|
120
|
+
* the audit + event logs, which config.cjs's own load must not depend on.
|
|
121
|
+
*/
|
|
122
|
+
function transitionEpicArchiveWrite(p, data) {
|
|
123
|
+
if (!p || typeof p !== 'string' || !data || typeof data !== 'object') return;
|
|
124
|
+
const sess = data.session;
|
|
125
|
+
if (!sess || typeof sess !== 'object' || sess.status !== 'completed') return;
|
|
126
|
+
const { parseEpicMirrorPath, readEpicMirrorStatus } = require('./lib/epic/epicStatusMirror.cjs');
|
|
127
|
+
let parsed;
|
|
128
|
+
try { parsed = parseEpicMirrorPath(expandHome(p)); } catch { parsed = null; }
|
|
129
|
+
if (!parsed) return;
|
|
130
|
+
const { transitionEpic } = require('./lib/epic/epicTransitions.cjs');
|
|
131
|
+
const prior = readEpicMirrorStatus(parsed.cwd, parsed.epicId);
|
|
132
|
+
const epic = { id: parsed.epicId, cwd: parsed.cwd, status: prior };
|
|
133
|
+
const ok = prior
|
|
134
|
+
? transitionEpic(epic, 'completed', { reason: 'markCompleted', source: 'config:write-json:archive' })
|
|
135
|
+
: transitionEpic(epic, 'completed', { reason: 'markCompleted', source: 'config:write-json:archive-no-prior-mirror', allowAnyFrom: true });
|
|
136
|
+
if (!ok) throw new Error(`Epic ${parsed.epicId}: illegal status transition ${prior} -> completed`);
|
|
137
|
+
}
|
|
138
|
+
|
|
111
139
|
function validatePath(abs) {
|
|
112
140
|
const real = realResolve(abs);
|
|
113
141
|
for (const root of allowedRoots) {
|
|
@@ -265,6 +293,7 @@ async function writeRendererText(abs, text, { writer, importedBy } = {}) {
|
|
|
265
293
|
throw new Error(`Write outside allowed write boundaries: ${real}`);
|
|
266
294
|
}
|
|
267
295
|
assertOpsWrite(real, writer);
|
|
296
|
+
ensureRuntimeIgnoreForPath(real);
|
|
268
297
|
await atomicFs.writeTextAtomic(real, text, {});
|
|
269
298
|
const stat = await fsp.stat(real);
|
|
270
299
|
return { ok: true, mtimeMs: stat.mtimeMs };
|
|
@@ -340,6 +369,7 @@ async function writeTextAtomic(abs, text, opts = {}) {
|
|
|
340
369
|
const real = validatePath(expandHome(abs));
|
|
341
370
|
validateWrite(real);
|
|
342
371
|
assertOpsWrite(real, opts.writer);
|
|
372
|
+
ensureRuntimeIgnoreForPath(real);
|
|
343
373
|
await atomicFs.writeTextAtomic(real, text, opts);
|
|
344
374
|
const stat = await fsp.stat(real);
|
|
345
375
|
return { ok: true, mtimeMs: stat.mtimeMs };
|
|
@@ -353,6 +383,7 @@ async function writeBinaryAtomic(abs, buffer, opts = {}) {
|
|
|
353
383
|
const real = validatePath(expandHome(abs));
|
|
354
384
|
validateWrite(real);
|
|
355
385
|
assertOpsWrite(real, opts.writer);
|
|
386
|
+
ensureRuntimeIgnoreForPath(real);
|
|
356
387
|
const dir = path.dirname(real);
|
|
357
388
|
await fsp.mkdir(dir, { recursive: true });
|
|
358
389
|
const tmp = `${real}.tmp-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
@@ -381,6 +412,7 @@ function writeJsonSync(abs, data, opts = {}) {
|
|
|
381
412
|
const real = validatePath(expandHome(abs));
|
|
382
413
|
validateWrite(real);
|
|
383
414
|
assertOpsWrite(real, opts.writer);
|
|
415
|
+
ensureRuntimeIgnoreForPath(real);
|
|
384
416
|
atomicFs.writeJsonAtomicSync(real, data, opts);
|
|
385
417
|
const stat = fs.statSync(real);
|
|
386
418
|
return { ok: true, mtimeMs: stat.mtimeMs };
|
|
@@ -629,6 +661,7 @@ function registerConfigHandlers() {
|
|
|
629
661
|
// (lib/opsOwnership.cjs). Ignored outside the ops root; required inside it.
|
|
630
662
|
ipcMain.handle('config:write-json', v(s.configWriteJson, ({ path: p, data, writer }) => {
|
|
631
663
|
registerPromptSessionsRoot(p);
|
|
664
|
+
transitionEpicArchiveWrite(p, data);
|
|
632
665
|
return writeJson(p, data, { writer });
|
|
633
666
|
}));
|
|
634
667
|
ipcMain.handle('config:write-text', v(s.configWriteText, ({ path: p, text, writer, importedBy }) => writeRendererText(p, text, { writer, importedBy })));
|
|
@@ -672,6 +705,7 @@ module.exports = {
|
|
|
672
705
|
addAllowedRoot,
|
|
673
706
|
getAllowedRoots,
|
|
674
707
|
registerPromptSessionsRoot,
|
|
708
|
+
transitionEpicArchiveWrite,
|
|
675
709
|
validatePath,
|
|
676
710
|
validateWrite,
|
|
677
711
|
realResolve,
|