claude-code-session-manager 0.141.0 → 0.142.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -70
- package/bin/cli.cjs +11 -0
- package/dist/assets/AppSettings-BcZgIvvY.js +2 -0
- package/dist/assets/{History-DJMiuXyK.js → History-DpZuJXi1.js} +1 -1
- package/dist/assets/HomeClaudeConfig-D32ZJtU-.js +3 -0
- package/dist/assets/{Panel-Bf1Cf8UL.js → Panel-BjdJjhqt.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-BWPpypf9.js → ProjectClaudeConfig-BTClYV6i.js} +7 -7
- package/dist/assets/Scheduler-DPobKx1Z.js +16 -0
- package/dist/assets/{SkillReferenceGraph-Ba4TkX2C.js → SkillReferenceGraph-Cqyu4mef.js} +1 -1
- package/dist/assets/{Skills-C1v91GEO.js → Skills-vv0noNVI.js} +5 -5
- package/dist/assets/{TiptapBody-BrcWVpiW.js → TiptapBody-CXi8Pvut.js} +1 -1
- package/dist/assets/Toggle-CiYCWLjh.js +1 -0
- package/dist/assets/{VoiceButton-qivnDV6K.js → VoiceButton-4NKKd1sC.js} +1 -1
- package/dist/assets/{historyTotals-CMCPTKqC.js → historyTotals-DDunb8Ch.js} +1 -1
- package/dist/assets/index-Cn5E9958.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 +4 -2
- package/plugins/AGENTS.md +4 -3
- 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/develop/SKILL.md +52 -18
- package/plugins/session-manager-dev/skills/develop/standards.md +3 -2
- package/scripts/README.md +1 -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 +732 -110
- package/src/main/adminRouteRegistry.cjs +59 -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 +231 -16
- package/src/main/config.cjs +30 -0
- package/src/main/docEdit.cjs +4 -2
- package/src/main/health.cjs +91 -0
- package/src/main/index.cjs +98 -48
- package/src/main/ipcSchemas.cjs +161 -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 +43 -0
- package/src/main/lib/demo-video-kit/character.cjs +722 -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 +99 -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/resumableRun.cjs +298 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +3 -3
- 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/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 +310 -0
- package/src/main/lib/epic/artifactStore.cjs +392 -0
- package/src/main/lib/epic/delegationReadiness.cjs +76 -2
- package/src/main/lib/epic/epicAgentRefresh.cjs +97 -0
- package/src/main/lib/epic/epicEventLog.cjs +214 -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/epicStatusMirror.cjs +34 -1
- package/src/main/lib/epic/epicTransitions.cjs +139 -0
- package/src/main/lib/epic/epicValidationHook.cjs +81 -2
- package/src/main/lib/epic/guardSpawnSettings.cjs +3 -2
- package/src/main/lib/externalContract.cjs +37 -4
- package/src/main/lib/feedback-remote/crossProjectReply.cjs +389 -126
- 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 +2 -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 +189 -0
- package/src/main/lib/feedback-remote/projectHomeAdminRoutes.cjs +188 -10
- 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/worktreeDeps.cjs +77 -2
- package/src/main/lib/mcpToolCatalog.cjs +304 -28
- package/src/main/lib/opsOwnership.cjs +29 -1
- 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 +263 -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 +41 -5
- package/src/main/lib/prd/prdCriteria.cjs +225 -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/videoReviewIpc.cjs +3 -2
- 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 +169 -0
- package/src/main/lib/scheduler/definitionOfDone.cjs +44 -5
- package/src/main/lib/scheduler/jobMemoryStats.cjs +313 -0
- package/src/main/lib/scheduler/loadGate.cjs +82 -4
- package/src/main/lib/scheduler/planRecordHarvest.cjs +32 -2
- package/src/main/lib/scheduler/prdOutcomeRecord.cjs +133 -0
- package/src/main/lib/scheduler/runLogRetention.cjs +42 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +5 -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 +0 -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 +237 -0
- package/src/main/lib/scheduler/toolClearance.cjs +258 -0
- package/src/main/lib/scheduler/validatorVerdictSchema.cjs +140 -10
- package/src/main/lib/tasks/memoryConsolidation.cjs +300 -0
- package/src/main/lib/tasks/mitigationReview.cjs +294 -0
- package/src/main/lib/tasks/taskAdminRoutes.cjs +312 -22
- 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 +207 -6
- 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/smfileRange.cjs +77 -0
- package/src/main/projectPages.cjs +3 -1
- package/src/main/promptSessionEvents.cjs +5 -0
- package/src/main/pty.cjs +68 -0
- package/src/main/queueOps.cjs +32 -13
- 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 +101 -0
- package/src/main/scheduler.cjs +1414 -189
- package/src/main/templates/PRD_AUTHORING.md +5 -2
- package/src/main/webRemote.cjs +463 -6
- package/src/preload/api.d.ts +529 -38
- package/src/preload/apiSurface.json +209 -7
- package/src/preload/index.cjs +46 -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 +87 -83
- 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 +9 -10
- 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
|
@@ -14,6 +14,8 @@ const { COMPLETED_EQUIVALENT_VERDICTS } = require('../lib/scheduler/terminalRunO
|
|
|
14
14
|
const { resolveIsFixPlan } = require('../lib/scheduler/fixPlanSlug.cjs');
|
|
15
15
|
const { GATE_AUTHORITY_VERDICTS } = require('../lib/scheduler/gateAuthority.cjs');
|
|
16
16
|
const { DEFAULT_PROJECT_CWD } = require('../lib/scheduler/schedulerBatch.cjs');
|
|
17
|
+
// Every automated selector skips a human-cancelled row (incident 2026-10-19 git-viewer: cancelled rows re-queued and merged).
|
|
18
|
+
const { isCancelledRow } = require('../lib/scheduler/cancelledRow.cjs');
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Resume-first recovery (PRD 1111). A job parked in needs_review with verdict
|
|
@@ -217,7 +219,7 @@ function isFinishReviewKillHealEligible(job) {
|
|
|
217
219
|
if (typeof job.landedCommit !== 'string' || job.landedCommit.length === 0) return false;
|
|
218
220
|
if (job.finishReviewHealAttemptedAt) return false;
|
|
219
221
|
if (job.integrationFailureKind) return false;
|
|
220
|
-
if (
|
|
222
|
+
if (isCancelledRow(job) || isRefireCapped(job)) return false;
|
|
221
223
|
return true;
|
|
222
224
|
}
|
|
223
225
|
|
|
@@ -596,23 +598,6 @@ function healRefusalReason(job, verdict, committedDuringRun) {
|
|
|
596
598
|
* gate or a real non-zero-exit error) is excluded — that failure is
|
|
597
599
|
* evidence, not silence, and must never become a heal candidate (PRD 1102).
|
|
598
600
|
*/
|
|
599
|
-
// A human cancelled this row (scheduler_cancel_job). Incident 2026-10-19
|
|
600
|
-
// (git-viewer): cancelled jobs were parked as 'failed' (source
|
|
601
|
-
// 'remote:cancelJob'), then selectFailedAutoResetTargets re-queued them 10
|
|
602
|
-
// minutes later and they ran and merged unwanted commits. Marker is
|
|
603
|
-
// `cancelledAt`; the statusHistory source is the fallback for rows cancelled
|
|
604
|
-
// before the marker existed. Every automated selector must skip these; only a
|
|
605
|
-
// human scheduler_reset_job revives one.
|
|
606
|
-
function isCancelledJob(job) {
|
|
607
|
-
if (!job) return false;
|
|
608
|
-
if (typeof job.cancelledAt === 'string' && job.cancelledAt) return true;
|
|
609
|
-
const history = Array.isArray(job.statusHistory) ? job.statusHistory : [];
|
|
610
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
611
|
-
if (history[i] && history[i].to === job.status) return history[i].source === 'remote:cancelJob';
|
|
612
|
-
}
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
601
|
function isFailedUnverifiedShaped(job) {
|
|
617
602
|
if (!job || job.status !== 'failed') return false;
|
|
618
603
|
if (job.verifierVerdict && RESCANNABLE_VERDICTS.has(job.verifierVerdict)) return true;
|
|
@@ -623,7 +608,7 @@ function isFailedUnverifiedShaped(job) {
|
|
|
623
608
|
}
|
|
624
609
|
|
|
625
610
|
function isRescanCandidate(job) {
|
|
626
|
-
if (!job ||
|
|
611
|
+
if (!job || isCancelledRow(job) || isRefireCapped(job)) return false;
|
|
627
612
|
// Default-ELIGIBLE: every needs_review row is a heal candidate unless its
|
|
628
613
|
// verdict is in RESCAN_EXCLUDED_VERDICTS. No runId requirement here — a row
|
|
629
614
|
// without one still gets the evidence rung and the unresolvable annotation.
|
|
@@ -655,7 +640,7 @@ function isTranscriptRescannable(job) {
|
|
|
655
640
|
function selectEvidenceScanTargets(jobs, now = Date.now()) {
|
|
656
641
|
const due = [];
|
|
657
642
|
for (const j of jobs ?? []) {
|
|
658
|
-
if (
|
|
643
|
+
if (isCancelledRow(j)) continue;
|
|
659
644
|
if (j.status !== 'needs_review' || !isRescanCandidate(j)) continue;
|
|
660
645
|
if (isTranscriptRescannable(j)) continue;
|
|
661
646
|
if (j.looksDone) continue;
|
|
@@ -785,7 +770,7 @@ function failedAutoResetDisabled() {
|
|
|
785
770
|
function selectFailedAutoResetTargets(jobs, now, thresholdMs) {
|
|
786
771
|
const targets = [];
|
|
787
772
|
for (const j of jobs ?? []) {
|
|
788
|
-
if (
|
|
773
|
+
if (isCancelledRow(j)) continue;
|
|
789
774
|
if (j.status !== 'failed') continue;
|
|
790
775
|
const attempts = j.failedAutoResetAttempts ?? 0;
|
|
791
776
|
if (attempts >= FAILED_AUTORESET_CAP) continue;
|
|
@@ -837,7 +822,7 @@ function selectFailedAutoResetTargets(jobs, now, thresholdMs) {
|
|
|
837
822
|
function findStuckFailedJobs(jobs, now, thresholdMs) {
|
|
838
823
|
const stuck = [];
|
|
839
824
|
for (const j of jobs ?? []) {
|
|
840
|
-
if (
|
|
825
|
+
if (isCancelledRow(j)) continue;
|
|
841
826
|
if (j.status !== 'failed') continue;
|
|
842
827
|
if (j.stuckFailedNotified === true) continue;
|
|
843
828
|
if (!isRescanCandidate(j)) continue;
|
|
@@ -906,7 +891,7 @@ function needsReviewAutoResolveDisabled() {
|
|
|
906
891
|
function selectExhaustedNeedsReviewTargets(jobs, now, thresholdMs) {
|
|
907
892
|
const targets = [];
|
|
908
893
|
for (const j of jobs ?? []) {
|
|
909
|
-
if (
|
|
894
|
+
if (isCancelledRow(j)) continue;
|
|
910
895
|
if (j.status !== 'needs_review') continue;
|
|
911
896
|
if (!isEligibleForNeedsReviewAutoResolve(j, jobs)) continue;
|
|
912
897
|
if ((j.exhaustedResolveAttempts ?? 0) > NEEDS_REVIEW_RESOLVE_CAP) continue;
|
|
@@ -949,7 +934,7 @@ function selectExhaustedNeedsReviewTargets(jobs, now, thresholdMs) {
|
|
|
949
934
|
function selectAutoFixTargets(jobs, { fixSlugExists, resolveJobRunId = resolveRunId }) {
|
|
950
935
|
const slugsInQueue = new Set(jobs.map((j) => j.slug));
|
|
951
936
|
return jobs.filter((job) => {
|
|
952
|
-
if (
|
|
937
|
+
if (isCancelledRow(job)) return false;
|
|
953
938
|
if (isRefireCapped(job)) return false;
|
|
954
939
|
if (job.status !== 'needs_review') return false;
|
|
955
940
|
// A job parked here because it was blocked by a sibling's foreign WIP
|
|
@@ -1117,7 +1102,6 @@ function selectResumeRecoveryBatch(jobs, { saturated = false } = {}) {
|
|
|
1117
1102
|
module.exports = {
|
|
1118
1103
|
selectResumeRecoveryBatch,
|
|
1119
1104
|
isRefireCapped,
|
|
1120
|
-
isCancelledJob,
|
|
1121
1105
|
selectResumeRecoveryTarget,
|
|
1122
1106
|
MECHANICALLY_RESOLVABLE_VERDICTS,
|
|
1123
1107
|
isMechanicalRecoveryFutile,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* scheduler/utilizationHold.cjs — the one rule deciding whether an automatic
|
|
6
|
+
* (non-human) scheduler tick may dispatch. Pure: no I/O, no clock (`now` is a
|
|
7
|
+
* parameter), so every caller (when-available, job-finish, dispatch-loop,
|
|
8
|
+
* slot-release ticks) agrees.
|
|
9
|
+
*
|
|
10
|
+
* Why every window: during a meter outage the top window (a 5-hour session
|
|
11
|
+
* at 97%) can reset while weekly_all in the same payload is still at 92%
|
|
12
|
+
* until Thursday. Reading only the binding window drops the hold at the
|
|
13
|
+
* session reset and the queue dispatches into the weekly limit (Self,
|
|
14
|
+
* 2026-11-23). A window whose reset has passed is skipped — never read as
|
|
15
|
+
* "no hold" for the others.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {{ window: string | null, percent: number | null, resetsAt: string | null }} UsageWindow
|
|
20
|
+
* @typedef {{
|
|
21
|
+
* percent: number | null,
|
|
22
|
+
* window: string | null,
|
|
23
|
+
* resetsAt: string | null,
|
|
24
|
+
* known: boolean,
|
|
25
|
+
* windows: UsageWindow[] | null,
|
|
26
|
+
* }} UtilizationReading
|
|
27
|
+
* @typedef {{
|
|
28
|
+
* reason: 'manual-fire-policy' | 'utilization-held',
|
|
29
|
+
* window: string | null,
|
|
30
|
+
* percent: number | null,
|
|
31
|
+
* threshold: number | null,
|
|
32
|
+
* resetsAt: string | null,
|
|
33
|
+
* detail: string,
|
|
34
|
+
* }} AutoDispatchHold
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Reset time as ms, or +Infinity when null/unparseable (counts as "resets last").
|
|
39
|
+
* @param {string | null | undefined} resetsAt
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
function resetMs(resetsAt) {
|
|
43
|
+
const ms = typeof resetsAt === 'string' ? Date.parse(resetsAt) : NaN;
|
|
44
|
+
return Number.isFinite(ms) ? ms : Infinity;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {{
|
|
49
|
+
* firePolicy: string | null | undefined,
|
|
50
|
+
* threshold: number | null | undefined,
|
|
51
|
+
* reading: UtilizationReading | null | undefined,
|
|
52
|
+
* now: number,
|
|
53
|
+
* }} args
|
|
54
|
+
* @returns {AutoDispatchHold | null}
|
|
55
|
+
*/
|
|
56
|
+
function evaluateAutoDispatchHold({ firePolicy, threshold, reading, now }) {
|
|
57
|
+
if (firePolicy === 'manual') {
|
|
58
|
+
return {
|
|
59
|
+
reason: 'manual-fire-policy',
|
|
60
|
+
window: null,
|
|
61
|
+
percent: null,
|
|
62
|
+
threshold: null,
|
|
63
|
+
resetsAt: null,
|
|
64
|
+
detail: 'fire policy is manual: only Run now dispatches',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (reading == null || reading.known !== true) return null;
|
|
68
|
+
if (typeof threshold !== 'number' || !Number.isFinite(threshold)) return null;
|
|
69
|
+
const limit = threshold;
|
|
70
|
+
|
|
71
|
+
/** @type {UsageWindow[]} */
|
|
72
|
+
const candidates = Array.isArray(reading.windows) && reading.windows.length > 0
|
|
73
|
+
? reading.windows
|
|
74
|
+
: [{ window: reading.window, percent: reading.percent, resetsAt: reading.resetsAt }];
|
|
75
|
+
|
|
76
|
+
/** @type {{ window: string | null, percent: number, resetsAt: string | null, resetAt: number } | null} */
|
|
77
|
+
let pick = null;
|
|
78
|
+
for (const c of candidates) {
|
|
79
|
+
if (!c) continue;
|
|
80
|
+
const percent = c.percent;
|
|
81
|
+
if (typeof percent !== 'number' || !Number.isFinite(percent)) continue;
|
|
82
|
+
const resetAt = resetMs(c.resetsAt);
|
|
83
|
+
if (resetAt <= now) continue; // already reset: its old reading no longer applies
|
|
84
|
+
if (percent < limit) continue;
|
|
85
|
+
if (pick === null || resetAt > pick.resetAt || (resetAt === pick.resetAt && percent > pick.percent)) {
|
|
86
|
+
pick = { window: c.window ?? null, percent, resetsAt: c.resetsAt ?? null, resetAt };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (pick === null) return null;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
reason: 'utilization-held',
|
|
93
|
+
window: pick.window,
|
|
94
|
+
percent: pick.percent,
|
|
95
|
+
threshold: limit,
|
|
96
|
+
resetsAt: pick.resetsAt,
|
|
97
|
+
detail: `${pick.window ?? 'binding'} window at ${String(pick.percent)}% ≥ ${String(limit)}%, resets ${pick.resetsAt ?? 'unknown'}`,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = { evaluateAutoDispatchHold };
|