claude-code-session-manager 0.133.1 → 0.135.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/dist/assets/AgentLibrary-DRlcF1YD.js +2 -0
- package/dist/assets/{AppSettings-DwnfV9-4.js → AppSettings-CBhYHKGI.js} +2 -2
- package/dist/assets/{Button-CObXxw7b.js → Button-DtBUGvGI.js} +1 -1
- package/dist/assets/{DocumentEditorPane-CgB5IuOY.js → DocumentEditorPane-C82c7Qtl.js} +1 -1
- package/dist/assets/{Extensions-Fuhshcl6.js → Extensions-Kn-oUD2_.js} +2 -2
- package/dist/assets/{History-DbUV4jxK.js → History-B4c3Uz9u.js} +2 -2
- package/dist/assets/{Library-COr79GyT.js → Library-1RpLT-aH.js} +1 -1
- package/dist/assets/{ListDetail-DY53nXya.js → ListDetail-xr0oxNkv.js} +1 -1
- package/dist/assets/{Panel-D7NX5iP8.js → Panel-O8XPrpJu.js} +1 -1
- package/dist/assets/{ProjectClaudeConfig-DuWzM8qA.js → ProjectClaudeConfig-DBGhhzg2.js} +5 -5
- package/dist/assets/{ProvenanceBadge-AnwE1p5X.js → ProvenanceBadge-DSaizfZL.js} +1 -1
- package/dist/assets/Scheduler-D2_5NyiR.js +16 -0
- package/dist/assets/{Settings-tt0VZCyz.js → Settings-Clgqb3Lq.js} +2 -2
- package/dist/assets/{SkillReferenceGraph-D_rxqWgq.js → SkillReferenceGraph-D80RA7kR.js} +1 -1
- package/dist/assets/{Skills-BVQPJZaF.js → Skills-DNG7tHSf.js} +10 -10
- package/dist/assets/{SourceChip-DC5XD8KC.js → SourceChip-D-Imzszd.js} +1 -1
- package/dist/assets/{SystemPrompt-XnvP0_cS.js → SystemPrompt-CGlOpUQA.js} +1 -1
- package/dist/assets/{TiptapBody-B_TNEADm.js → TiptapBody-CJFGfBdz.js} +28 -28
- package/dist/assets/{Toggle-CxQO8pGN.js → Toggle-0Ff0bPa_.js} +1 -1
- package/dist/assets/{ViewTabs-CEjnWPD9.js → ViewTabs-BCMYQwo_.js} +1 -1
- package/dist/assets/{VoiceButton-B-6gdmKe.js → VoiceButton-JzyC6DAB.js} +1 -1
- package/dist/assets/geist-sans-latin-300-normal-C3kkMBb6.woff2 +0 -0
- package/dist/assets/geist-sans-latin-400-normal-gapTbOY8.woff2 +0 -0
- package/dist/assets/geist-sans-latin-500-normal-uokXdC-Q.woff2 +0 -0
- package/dist/assets/geist-sans-latin-600-normal-DFOURf8L.woff2 +0 -0
- package/dist/assets/geist-sans-latin-700-normal-BmN9tIp5.woff2 +0 -0
- package/dist/assets/{historyTotals-dT8vcKzX.js → historyTotals-B01WPBwh.js} +1 -1
- package/dist/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/dist/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
- package/dist/assets/{index-5QIl5Kcd.css → index-CjQ_p5y7.css} +1 -1
- package/dist/assets/index-rt7pTODX.js +3116 -0
- package/dist/assets/newsreader-latin-400-italic-CEihAR-f.woff2 +0 -0
- package/dist/assets/newsreader-latin-400-normal-BFBkh4jY.woff2 +0 -0
- package/dist/assets/newsreader-latin-500-normal-B66TYsaK.woff2 +0 -0
- package/dist/assets/newsreader-latin-600-normal-30OJ_TG_.woff2 +0 -0
- package/dist/assets/newsreader-latin-700-normal-rIgV_oaK.woff2 +0 -0
- package/dist/index.html +2 -5
- package/dist-web/app.css +1 -1
- package/dist-web/app.js +409 -404
- package/dist-web/index.html +0 -3
- package/package.json +1 -1
- package/plugins/session-manager-dev/skills/develop/standards.md +1 -1
- package/scripts/scheduler-mcp-server.cjs +31 -0
- package/src/main/agentLibrary.cjs +27 -4
- package/src/main/build-info.json +4 -4
- package/src/main/chatRunner.cjs +9 -0
- package/src/main/config.cjs +22 -0
- package/src/main/crashDiagnostics.cjs +10 -2
- package/src/main/index.cjs +34 -25
- package/src/main/ipcSchemas.cjs +6 -0
- package/src/main/lib/agent-cli/agentCliEvents.cjs +8 -0
- package/src/main/lib/demo-video-kit/capture.cjs +4 -37
- package/src/main/lib/demo-video-kit/character.cjs +20 -2
- package/src/main/lib/demo-video-kit/checks.cjs +82 -1
- package/src/main/lib/demo-video-kit/frames.cjs +3 -28
- package/src/main/lib/demo-video-kit/playwrightLoader.cjs +67 -0
- package/src/main/lib/demo-video-kit/seedKit.cjs +2 -2
- package/src/main/lib/demo-video-kit/sound.cjs +5 -2
- package/src/main/lib/epic/epicMint.cjs +1 -3
- package/src/main/lib/epic/promptSessionsCreateEpic.cjs +37 -4
- package/src/main/lib/epic/restorableSessions.cjs +88 -0
- package/src/main/lib/feedback-remote/customerFeedbackAdminRoutes.cjs +56 -1
- package/src/main/lib/feedback-remote/customerFeedbackIpc.cjs +21 -3
- package/src/main/lib/feedback-remote/remoteAssets.cjs +25 -1
- package/src/main/lib/mcpToolCatalog.cjs +15 -0
- package/src/main/lib/persona-macro/agentPersonaSchema.cjs +10 -1
- package/src/main/lib/persona-macro/builtinMacros.cjs +3 -2
- package/src/main/lib/persona-macro/macroJobDispatch.cjs +3 -2
- package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +22 -0
- package/src/main/lib/prd/listPrdsSingleFlight.cjs +79 -0
- package/src/main/lib/prd/prdAgentType.cjs +17 -7
- package/src/main/lib/prd/prdFrontmatter.cjs +25 -1
- package/src/main/lib/scheduler/scheduleJobSchema.cjs +3 -0
- package/src/main/lib/telemetry/crashTelemetry.cjs +10 -5
- package/src/main/lib/telemetry/telemetryBoot.cjs +77 -4
- package/src/main/lib/telemetry/telemetryClient.cjs +54 -9
- package/src/main/lib/telemetry/telemetryConsent.cjs +3 -0
- package/src/main/lib/telemetry/telemetryCounters.cjs +7 -2
- package/src/main/lib/telemetry/telemetrySettings.cjs +5 -0
- package/src/main/promptSessionEvents.cjs +7 -1
- package/src/main/pty.cjs +2 -2
- package/src/main/runVerify.cjs +2 -2
- package/src/main/scheduler/prdParser.cjs +18 -2
- package/src/main/scheduler.cjs +156 -18
- package/src/main/seedAgentPersonas.cjs +24 -0
- package/src/main/seedStatus.cjs +5 -2
- package/src/main/telemetryIpc.cjs +1 -5
- package/src/main/templates/PRD_AUTHORING.md +2 -2
- package/src/preload/api.d.ts +37 -16
- package/src/preload/apiSurface.json +7 -0
- package/src/preload/index.cjs +3 -1
- package/src/seed/agents/demo-video-builder.md +7 -2
- package/src/seed/agents/project-home-builder.md +4 -2
- package/dist/assets/AgentLibrary-BTIBmZkM.js +0 -2
- package/dist/assets/Scheduler-BHfx0rXd.js +0 -16
- package/dist/assets/index-BLORXCcT.js +0 -3111
- package/src/main/lib/telemetry/telemetryBacklog.cjs +0 -607
package/src/preload/api.d.ts
CHANGED
|
@@ -456,6 +456,10 @@ export interface AgentPersona {
|
|
|
456
456
|
model: string | null;
|
|
457
457
|
/** Per-Epic reasoning effort (`effort:` frontmatter; a `models.catalog` effort level). Null = inherit. Passed to the claude spawn as `--effort` (never `auto`). */
|
|
458
458
|
effort: string | null;
|
|
459
|
+
/** Default agent CLI for New Session (`agentCli:` frontmatter); null = Claude Code (or an unknown on-disk value). */
|
|
460
|
+
agentCli?: AgentCliDetectRow['id'] | null;
|
|
461
|
+
/** Default model for that CLI (`agentCliModel:` frontmatter); null when unset or agentCli is null. */
|
|
462
|
+
agentCliModel?: string | null;
|
|
459
463
|
color: string | null;
|
|
460
464
|
/** Epic intent tags (tagLibrary.ts's TAG_LIBRARY) this persona is associated with. */
|
|
461
465
|
tags: AgentPersonaTag[];
|
|
@@ -495,6 +499,10 @@ export interface AgentPersonaSaveInput {
|
|
|
495
499
|
model: string;
|
|
496
500
|
/** Effort level, or `'inherit'`/omitted to write no `effort:` line. */
|
|
497
501
|
effort?: string;
|
|
502
|
+
/** Default agent CLI for New Session. Omit to keep the existing file's value; `'claude'` removes it (and the model). */
|
|
503
|
+
agentCli?: 'claude' | AgentCliDetectRow['id'];
|
|
504
|
+
/** Model for a non-Claude agentCli; ignored otherwise. Carried over with agentCli when agentCli is omitted. */
|
|
505
|
+
agentCliModel?: string;
|
|
498
506
|
color: string;
|
|
499
507
|
tags: AgentPersonaTag[];
|
|
500
508
|
/** Project cwds (or the `'*'` sentinel) this persona's Action button appears in. Omit to keep the existing file's value; `[]` clears it. */
|
|
@@ -715,18 +723,6 @@ export interface TelemetryLastError {
|
|
|
715
723
|
at: number;
|
|
716
724
|
}
|
|
717
725
|
|
|
718
|
-
export interface TelemetryBacklogSummary {
|
|
719
|
-
projectsScanned: number;
|
|
720
|
-
filesScanned: number;
|
|
721
|
-
linesEnqueued: number;
|
|
722
|
-
linesConfirmed: number;
|
|
723
|
-
linesSkipped: number;
|
|
724
|
-
filesCompleted: number;
|
|
725
|
-
watermarksRewound: number;
|
|
726
|
-
reason: string;
|
|
727
|
-
ranAt: string;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
726
|
export interface TelemetryStatus {
|
|
731
727
|
pendingCount: number;
|
|
732
728
|
sentCount: number;
|
|
@@ -739,7 +735,6 @@ export interface TelemetryStatus {
|
|
|
739
735
|
lastError: TelemetryLastError | null;
|
|
740
736
|
lastFlushAt: number | null;
|
|
741
737
|
lastFlushReason: string | null;
|
|
742
|
-
backlog: TelemetryBacklogSummary | null;
|
|
743
738
|
}
|
|
744
739
|
|
|
745
740
|
export interface TelemetrySetConfigResult {
|
|
@@ -798,6 +793,9 @@ export interface ScheduleJobRuntime {
|
|
|
798
793
|
|
|
799
794
|
export interface ScheduleJob {
|
|
800
795
|
macroId?: string | null;
|
|
796
|
+
/** PRD frontmatter artifact-only declaration (PRD 3114). */
|
|
797
|
+
deliverable?: 'artifact' | null;
|
|
798
|
+
artifactPaths?: string[] | null;
|
|
801
799
|
slug: string;
|
|
802
800
|
title: string;
|
|
803
801
|
cwd: string | null;
|
|
@@ -2544,7 +2542,8 @@ export interface SessionManagerAPI {
|
|
|
2544
2542
|
readPrd: (slug: string) => Promise<{ ok: boolean; text?: string; error?: string }>;
|
|
2545
2543
|
readLog: (runId: string, slug: string) => Promise<{ ok: boolean; text?: string; error?: string }>;
|
|
2546
2544
|
writePrd: (slug: string, body: string) => Promise<{ ok: true; bytesWritten: number } | { ok: false; error: string }>;
|
|
2547
|
-
|
|
2545
|
+
/** Omit `cwd` for the machine-wide list; pass a project cwd to scope it. */
|
|
2546
|
+
listPrds: (cwd?: string) => Promise<PrdListItem[]>;
|
|
2548
2547
|
health: () => Promise<ScheduleHealthSnapshot>;
|
|
2549
2548
|
/** Queue-health header verdict — reuses classifyQueueHealth so this can
|
|
2550
2549
|
* never disagree with the starvation watchdog. `cwd` null/omitted =
|
|
@@ -2810,6 +2809,9 @@ export interface SessionManagerAPI {
|
|
|
2810
2809
|
listArchived: (payload: { cwd: string }) => Promise<{ ok: boolean; ids: string[]; error?: string }>;
|
|
2811
2810
|
/** This project's earlier Claude Code sessions no Epic owns yet, newest first (restore-as-new-Epic picker). */
|
|
2812
2811
|
listRestorable: (payload: { cwd: string }) => Promise<PromptSessionsListRestorableResult>;
|
|
2812
|
+
/** Interactive (non-headless) restorable sessions across every known project, newest first.
|
|
2813
|
+
* Resolves `{ ok: false, error }` on a refused `limit` or a lister failure — never rejects. */
|
|
2814
|
+
listRestorableRecent: (opts?: { limit?: number }) => Promise<PromptSessionsListRestorableRecentResult | { ok: false; error: string }>;
|
|
2813
2815
|
readArchived: (payload: { cwd: string; epicId: string }) => Promise<{ exists: boolean; data: unknown; error?: string }>;
|
|
2814
2816
|
readSessionTranscript: (payload: { cwd: string; sessionId: string }) => Promise<{ exists: boolean; text: string; error?: string }>;
|
|
2815
2817
|
writeArchive: (payload: { cwd: string; epicId: string; archive: Record<string, unknown> }) => Promise<{ ok: true }>;
|
|
@@ -2932,6 +2934,22 @@ export interface PromptSessionsListRestorableResult {
|
|
|
2932
2934
|
truncated: boolean;
|
|
2933
2935
|
}
|
|
2934
2936
|
|
|
2937
|
+
// ─────────────────────────────────── PromptSessions list-restorable-recent (restorableSessions.cjs listRecentRestorableSessions)
|
|
2938
|
+
/** A RestorableSession from any known project, tagged with the project it belongs to. */
|
|
2939
|
+
export type RecentRestorableSession = RestorableSession & {
|
|
2940
|
+
/** Project root the transcript belongs to. */
|
|
2941
|
+
cwd: string;
|
|
2942
|
+
};
|
|
2943
|
+
|
|
2944
|
+
export interface PromptSessionsListRestorableRecentResult {
|
|
2945
|
+
/** Newest first by mtime, across projects. */
|
|
2946
|
+
sessions: RecentRestorableSession[];
|
|
2947
|
+
/** Projects whose transcripts were read by this call. */
|
|
2948
|
+
projectsRead: number;
|
|
2949
|
+
/** Some project's walk, or the project list, stopped with candidates left. */
|
|
2950
|
+
truncated: boolean;
|
|
2951
|
+
}
|
|
2952
|
+
|
|
2935
2953
|
// ─────────────────────────────────── PromptSessions create-worktree (main-side createEpicWorktree)
|
|
2936
2954
|
export interface PromptSessionsCreateWorktreePayload {
|
|
2937
2955
|
cwd: string;
|
|
@@ -2993,8 +3011,11 @@ export interface PromptSessionEventAppendedPayload {
|
|
|
2993
3011
|
at: string;
|
|
2994
3012
|
prdSlug?: string;
|
|
2995
3013
|
text?: string;
|
|
2996
|
-
/** 'job-not-queued' = a macro's background build could not be queued for this Epic (macroJobIpc.cjs)
|
|
2997
|
-
|
|
3014
|
+
/** 'job-not-queued' = a macro's background build could not be queued for this Epic (macroJobIpc.cjs);
|
|
3015
|
+
* 'build-done' / 'build-failed' = a macro's background-build PRD finished (scheduler.cjs notifyOriginatingTab). */
|
|
3016
|
+
notice?: 'job-not-queued' | 'build-done' | 'build-failed';
|
|
3017
|
+
/** The saved Project Home entry a 'build-done' notice names, when its meta.json was readable. */
|
|
3018
|
+
buildOutput?: { kind: 'video' | 'knowledge'; id: string; title: string };
|
|
2998
3019
|
};
|
|
2999
3020
|
}
|
|
3000
3021
|
|
|
@@ -1847,6 +1847,13 @@
|
|
|
1847
1847
|
"kind": "invoke",
|
|
1848
1848
|
"remote": "read"
|
|
1849
1849
|
},
|
|
1850
|
+
{
|
|
1851
|
+
"ns": "promptSessions",
|
|
1852
|
+
"method": "listRestorableRecent",
|
|
1853
|
+
"channel": "promptSessions:list-restorable-recent",
|
|
1854
|
+
"kind": "invoke",
|
|
1855
|
+
"remote": "read"
|
|
1856
|
+
},
|
|
1850
1857
|
{
|
|
1851
1858
|
"ns": "promptSessions",
|
|
1852
1859
|
"method": "readArchived",
|
package/src/preload/index.cjs
CHANGED
|
@@ -329,7 +329,7 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
329
329
|
readPrd: (slug) => ipcRenderer.invoke('schedule:read-prd', { slug }),
|
|
330
330
|
readLog: (runId, slug) => ipcRenderer.invoke('schedule:read-log', { runId, slug }),
|
|
331
331
|
writePrd: (slug, body) => ipcRenderer.invoke('schedule:write-prd', { slug, body }),
|
|
332
|
-
listPrds: () => ipcRenderer.invoke('schedule:list-prds'),
|
|
332
|
+
listPrds: (cwd) => ipcRenderer.invoke('schedule:list-prds', cwd ? { cwd } : undefined),
|
|
333
333
|
health: () => ipcRenderer.invoke('schedule:health'),
|
|
334
334
|
// Queue-health header: one honest verdict for "why does the queue look
|
|
335
335
|
// stale" (saturated/blocked/idle/stalled/paused/launch-blocked), scoped
|
|
@@ -637,6 +637,8 @@ contextBridge.exposeInMainWorld('api', {
|
|
|
637
637
|
listArchived: (payload) => ipcRenderer.invoke('promptSessions:list-archived', payload),
|
|
638
638
|
/** This project's earlier Claude Code sessions no Epic owns yet (restore-as-new-Epic picker). */
|
|
639
639
|
listRestorable: (payload) => ipcRenderer.invoke('promptSessions:list-restorable', payload),
|
|
640
|
+
/** Interactive restorable sessions across every known project, newest first; each row carries its cwd. */
|
|
641
|
+
listRestorableRecent: (opts) => ipcRenderer.invoke('promptSessions:list-restorable-recent', opts),
|
|
640
642
|
readArchived: (payload) => ipcRenderer.invoke('promptSessions:read-archived', payload),
|
|
641
643
|
readSessionTranscript: (payload) => ipcRenderer.invoke('promptSessions:read-session-transcript', payload),
|
|
642
644
|
/** Mutate-tier archive write for markCompleted (main builds the path; single-writer 'epics'). */
|
|
@@ -5,7 +5,7 @@ tools: Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__proj
|
|
|
5
5
|
title: 'Project Home — Demo Video'
|
|
6
6
|
model: opus
|
|
7
7
|
effort: max
|
|
8
|
-
seedVersion:
|
|
8
|
+
seedVersion: 11
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
You are the demo-video-builder. You make a short animated demo, 30 seconds or 1 minute long per `<length_and_pacing>`, that shows someone what this
|
|
@@ -101,7 +101,8 @@ Use the shared kit in `~/.claude/session-manager/demo-video-kit/`. It needs only
|
|
|
101
101
|
- `frames.cjs`: `sampleFrames({ htmlPath, lengthS })` seeks the finished document and returns per-frame stats plus a contact sheet. Look at the sheet; no blank frame may last past 0.5 s.
|
|
102
102
|
- `checks.cjs`: `node checks.cjs input.json` with `{ captions, narration, closing, lines, speechS, lengthS, frames, html }` must exit 0 before you save. Fix every failing check and run it again.
|
|
103
103
|
- `_character`: reuse the mascot in the project's session-manager-operations/project-pages/videos/_character/ when it exists (read `character.json` and `character.js`). Otherwise design one per `<character>` and save it once with `project_character_write`.
|
|
104
|
-
|
|
104
|
+
The soundtrack must come from sound.cjs's mix. Never hand-write ffmpeg mixing, ducking, sidechain or filter graphs for the soundtrack.
|
|
105
|
+
If any kit tool (capture.cjs, sound.cjs, frames.cjs, checks.cjs) fails, the run stops. Report the exact command and its error, and save nothing. Never build a replacement for a failed kit tool.
|
|
105
106
|
</kit>
|
|
106
107
|
|
|
107
108
|
<character>
|
|
@@ -284,4 +285,8 @@ all, that is a Session Manager launch bug, not an obstacle to route around: say
|
|
|
284
285
|
the absolute path of the HTML file you built in your final result, and stop. Don't start Session
|
|
285
286
|
Manager's MCP server yourself, call its admin API, write the saved file by hand, or build any
|
|
286
287
|
other workaround or tooling, in the target project or anywhere else.
|
|
288
|
+
If a kit tool (capture.cjs, sound.cjs, frames.cjs, checks.cjs) fails, the run fails. Report the
|
|
289
|
+
exact command and its error, save nothing, and stop. Do not call `project_video_write`. Do not
|
|
290
|
+
hand-write an ffmpeg mixer or filter graph for the soundtrack; the soundtrack comes only from
|
|
291
|
+
sound.cjs's mix.
|
|
287
292
|
</when_things_fail>
|
|
@@ -5,7 +5,7 @@ tools: Read, Grep, Glob, Bash, Write, Edit, mcp__session-manager-scheduler__proj
|
|
|
5
5
|
title: Project Home — Builder
|
|
6
6
|
model: sonnet
|
|
7
7
|
effort: medium
|
|
8
|
-
seedVersion:
|
|
8
|
+
seedVersion: 6
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
You are the project-home-builder. You write ONE Knowledge Page per run. The page you produce is often the first thing a person sees
|
|
@@ -77,7 +77,9 @@ Produce exactly one complete HTML document:
|
|
|
77
77
|
5. Call `project_page_write` exactly once with `{ pageId: <Entry id>, title, topic, htmlPath or html }`
|
|
78
78
|
(use `htmlPath`, an absolute path to a .html file you wrote, for a large document). It
|
|
79
79
|
validates the document and writes it as that Knowledge Page.
|
|
80
|
-
6. Report back in one or two lines what the page covers.
|
|
80
|
+
6. Report back in one or two lines what the page covers. When this runs as a scheduled build, its
|
|
81
|
+
PRD forbids committing, so no commit is the expected result: once `project_page_write` returned
|
|
82
|
+
ok and the PRD's gate exits 0, end with SCHEDULER_VERDICT: PASS, never FAIL for the missing commit.
|
|
81
83
|
</process>
|
|
82
84
|
|
|
83
85
|
<when_things_fail>
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{bf as J,ba as Ne,aN as v,Z as A,b7 as ne,b5 as C,ax as e,l as H,b4 as Y,a7 as Ce,aC as M,bq as $e,b as I,aD as ke,aK as Se,b2 as Le,bi as se,M as De,d as U,E as Ee,a9 as Te}from"./index-BLORXCcT.js";import{P as ae}from"./Panel-D7NX5iP8.js";import{L as oe}from"./ListDetail-DY53nXya.js";import{V as Oe}from"./ViewTabs-CEjnWPD9.js";import{S as re}from"./SourceChip-DC5XD8KC.js";import{B as R}from"./Button-CObXxw7b.js";import{r as Pe}from"./claude-settings-schema-COigsajx.js";import"./monaco-editor-BsIlgG7c.js";function ie(t,a){const s=J();Ne([s?`${s}/.claude/agents`:null,...t.map(i=>`${i}/.claude/agents`)],a)}function Re({onOpenPersona:t}){const[a,s]=v.useState(A[0].tag),{personas:i,refresh:d}=ne(r=>C.error(r.message||"failed to load agent personas"));ie([],()=>{d()});const f=A.find(r=>r.tag===a)??null;return e.jsx(ae,{toolbar:e.jsxs("span",{className:"text-fg-faint",children:[A.length," tag",A.length===1?"":"s"]}),children:e.jsx(oe,{sidebar:e.jsx("div",{className:"py-1",children:A.map(r=>{const p=Y(r.tag),y=a===r.tag,m=(i==null?void 0:i.filter(h=>h.tags.includes(r.tag)).length)??0;return e.jsxs("button",{onClick:()=>{s(r.tag)},className:`w-full text-left px-3 py-1.5 text-xs flex items-center gap-2 border-l-2 ${y?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,children:[e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-mono font-semibold ${p.bg} ${p.text} ${p.border?"border border-current/30":""}`,children:["#",r.tag]}),e.jsx("span",{className:"truncate",children:r.label}),m>0&&e.jsx("span",{className:"ml-auto text-[10.5px] text-fg-faint font-mono shrink-0",children:m})]},r.tag)})}),detail:f?e.jsx(Fe,{entry:f,personas:i,onOpenPersona:t}):e.jsx(H,{title:"select a tag"})})})}const Ae=v.memo(Re);function Fe({entry:t,personas:a,onOpenPersona:s}){const i=Y(t.tag),d=Ce(t.tag),f=(a==null?void 0:a.filter(r=>r.tags.includes(t.tag)))??[];return e.jsxs("div",{className:"p-4 space-y-4 max-w-3xl",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("span",{className:`px-2 py-1 rounded text-xs font-mono font-semibold ${i.bg} ${i.text} ${i.border?"border border-current/30":""}`,children:["#",t.tag]}),e.jsx("span",{className:"text-sm font-semibold text-fg",children:t.label})]}),e.jsx("div",{className:"text-xs text-fg-dim leading-relaxed",children:t.description}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"/develop eagerness"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developEagerness})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"develops via"}),e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] rounded border border-line text-fg-dim font-mono",children:t.developsVia})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"agents carrying this tag"}),a===null?e.jsx("div",{className:"text-xs text-fg-faint italic",children:"loading…"}):e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[f.map(r=>e.jsx("button",{onClick:()=>s==null?void 0:s(r.name),title:`Open ${r.name} in Personas`,className:"inline-flex items-center bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim hover:text-fg hover:bg-bg-hi",children:r.name},r.name)),f.length===0&&e.jsx("span",{className:"text-xs text-fg-faint italic mr-1",children:"no agent carries this tag yet."})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:"opening framing — sent before the human's goal"}),e.jsx("pre",{className:"text-xs text-fg-dim whitespace-pre-wrap bg-bg-elev border border-line rounded p-3 leading-relaxed font-sans",children:d.initialPromptTemplate})]})]})}const Be=new Set(A.map(t=>t.tag));function le(t){return t.filter(a=>Be.has(a))}function Me(t,a={}){return{name:t.name,originalName:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??void 0,color:t.color??"",tags:le(t.tags),projects:t.projects,action:t.action??void 0,actionLabel:t.actionLabel??void 0,title:t.title??void 0,body:t.body,...a}}const Ve=t=>{const[a,s]=t.split(".");return Number(a)+(s?Number(s)/100:0)};function We(t){const a=/Effort is supported on ([^.]*?)(?:, with|\.|$)/.exec(t);if(!a)return[];const s=[];for(const i of a[1].split(/,\s*|\s+and\s+/)){const d=/^(\w+)\s+(\d+(?:\.\d+)?)$/.exec(i.trim());d&&s.push({family:d[1].toLowerCase(),version:Ve(d[2])})}return s}var ee,te;const Ie=We(String(((te=(ee=Pe.properties)==null?void 0:ee.effortLevel)==null?void 0:te.description)??""));function Ke(t,a){const s=new RegExp(`${a}-(\\d+)(?:-(\\d{1,2})(?!\\d))?`,"i").exec(t);if(s)return Number(s[1])+(s[2]?Number(s[2])/100:0);const i=new RegExp(`claude-(\\d+)(?:-(\\d{1,2}))?-${a}`,"i").exec(t);return i?Number(i[1])+(i[2]?Number(i[2])/100:0):null}function _e(t,a=Ie){if(!t||t==="inherit"||a.length===0)return null;const s=M(t);if(!s)return null;const i=a.filter(f=>f.family===s);if(i.length===0)return!1;const d=Ke(t,s);return d===null?null:d>=Math.min(...i.map(f=>f.version))}const Z=["Read","Grep","Glob","Bash","Write","Edit","WebFetch","WebSearch","Task"],Ge=["","red","orange","yellow","green","cyan","blue","purple","pink"],de={red:"#c0392b",orange:"#b85c34",yellow:"#c9a227",green:"#6f7d52",cyan:"#3f8f8a",blue:"#4a6fa5",purple:"#7a6a8a",pink:"#b45a80"};function G(t){return{name:t.name,description:t.description??"",tools:t.tools,model:t.model??"inherit",effort:t.effort??"inherit",color:t.color??"",tags:t.tags,body:t.body}}const Q={name:"new-agent",description:"",tools:["Read","Grep"],model:"inherit",effort:"inherit",color:"",tags:[],body:""};function ze(t){const a=new Map;for(const s of t){const i=typeof s.cwd=="string"?ke(s.cwd):"";i&&!a.has(i)&&a.set(i,{cwd:i,name:Se(i)})}return[...a.values()].sort((s,i)=>s.name.localeCompare(i.name)||s.cwd.localeCompare(i.cwd))}function ce(t){return[...t.fields.filter(a=>a!=="name"),...t.bodyOverridden?["full body"]:[]]}function He(t){return(t.overrideDetails??[]).map(a=>`${a.project}: ${ce(a).join(", ")||"overlay"}`).join(`
|
|
2
|
-
`)}function Ue(){const[t,a]=v.useState("personas"),{personas:s,refresh:i}=ne(n=>C.error(n.message||"failed to load agent personas")),[d,f]=v.useState(null),[r,p]=v.useState(""),[y,m]=v.useState(null),[h,x]=v.useState(!1),[N,L]=v.useState(!1),[j,S]=v.useState(null),[D,w]=v.useState(!1),c=v.useRef(!0);v.useEffect(()=>()=>{c.current=!1},[]);const b=$e(n=>n.tabs),o=v.useMemo(()=>ze(b),[b]),[$,k]=v.useState(null),T=o.find(n=>n.cwd===$)??null,O=async n=>{await i()&&n&&f(n)};ie(o.map(n=>n.cwd),()=>O()),v.useEffect(()=>{const n=Le();n&&f(n);const u=E=>f(E.detail);return window.addEventListener("sm:select-persona",u),()=>window.removeEventListener("sm:select-persona",u)},[]);const V=e.jsx(Oe,{options:[{key:"personas",label:"Personas"},{key:"tags",label:"Tags"}],active:t,onChange:a});if(t==="tags")return e.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[e.jsx("div",{className:"px-3 py-1.5 border-b border-line",children:V}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Ae,{onOpenPersona:n=>{f(n),m(null),x(!1),a("personas")}})})]});if(s===null)return e.jsx(H,{title:"loading…"});const F=r.toLowerCase(),W=s.filter(n=>!F||n.name.toLowerCase().includes(F)||(n.description??"").toLowerCase().includes(F)),l=s.find(n=>n.name===d)??s[0]??null,g=y??(l?G(l):null),q=!!y&&!!l&&JSON.stringify(y)!==JSON.stringify(G(l)),B=h,xe=n=>{m(null),x(!1),L(!1),S(null),f(n)},ge=n=>m(u=>({...u??(l?G(l):Q),...n})),he=()=>{m({...Q}),x(!0),L(!1)},pe=()=>{g&&(m({...g,name:g.name+"-copy"}),x(!0))},ue=()=>{m(null),x(!1)},be=async()=>{if(g){if(!/^[a-z][a-z0-9-]*$/.test(g.name)){C.error('agent name must be lowercase, hyphenated (e.g. "my-agent")');return}w(!0);try{const n=B?null:l,u={name:g.name,originalName:n==null?void 0:n.name,description:g.description,tools:g.tools,model:g.model,effort:g.effort,color:g.color,tags:le(g.tags),body:g.body},E=n?Me(n,u):u;await window.api.agents.savePersona(E),C.info(B?`created ${g.name}`:`saved ${g.name}`),m(null),x(!1),await O(g.name)}catch(n){C.error(n.message||"failed to save agent persona")}finally{w(!1)}}},ve=async()=>{if(l){w(!0);try{await window.api.agents.deletePersona({name:l.name}),C.info(`deleted ${l.name}`),L(!1),m(null),x(!1),await O()}catch(n){C.error(n.message||"failed to delete agent persona")}finally{w(!1)}}},je=async n=>{w(!0);try{await window.api.agents.deletePersona({name:n}),C.info(`deleted ${n}`),S(null),d===n&&(m(null),x(!1)),await O()}catch(u){C.error(u.message||"failed to delete agent persona")}finally{w(!1)}},we=async(n,u)=>{if(l)try{await window.api.agents.removeOverride({name:l.name,projectCwd:n}),C.info(`removed ${u}'s override of ${l.name}`),await O(l.name)}catch(E){C.error(E.message||"failed to remove override")}},ye=async n=>{if(!l||!T)return;const{cwd:u,name:E}=T;w(!0);try{n.model==="inherit"&&n.effort==="inherit"?(await window.api.agents.removeOverride({name:l.name,projectCwd:u}),C.info(`cleared ${E}'s override of ${l.name}`)):(await window.api.agents.savePersona({name:l.name,projectCwd:u,description:"",tools:[],color:"",tags:[],body:"",model:n.model,effort:n.effort}),C.info(`saved ${E}'s override of ${l.name}`)),await O(l.name)}catch(K){C.error(K.message||"failed to save project override")}finally{w(!1)}};return e.jsx(ae,{toolbar:e.jsxs(e.Fragment,{children:[V,e.jsxs("span",{className:"text-fg-faint",children:[s.length," persona",s.length===1?"":"s"]}),e.jsx("input",{value:r,onChange:n=>p(n.target.value),placeholder:"filter…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-40"}),e.jsx("div",{className:"flex-1"}),e.jsx(R,{variant:"primary",onClick:he,children:"+ New agent"})]}),children:e.jsx(oe,{sidebar:e.jsxs("div",{className:"py-1",children:[B&&e.jsx("div",{className:"w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 bg-bg-hi text-fg border-l-2 border-accent",children:e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsx("span",{className:"truncate font-mono",children:g==null?void 0:g.name}),e.jsx("span",{className:"shrink-0 text-[10px] font-semibold text-accent",children:"new"})]})}),W.length===0&&!B?e.jsx("div",{className:"px-3 py-1 text-xs text-fg-faint italic",children:"no agent personas found"}):W.map(n=>{const u=!B&&n.name===d,E=u&&q,K=j===n.name;return e.jsxs("div",{"data-agent-row":n.name,className:`group w-full text-left px-3 py-1 text-xs flex flex-col gap-0.5 border-l-2 cursor-pointer ${u?"bg-bg-hi text-fg border-accent":"text-fg-dim hover:text-fg hover:bg-bg-hi border-transparent"}`,onClick:()=>xe(n.name),children:[e.jsxs("span",{className:"flex items-center gap-2 justify-between w-full",children:[e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:n.color?de[n.color]??n.color:"var(--fg-faint, #999)",opacity:n.color?1:.35}}),e.jsx("span",{className:"truncate font-mono",children:n.name})]}),e.jsxs("span",{className:"shrink-0 flex items-center gap-1.5",children:[E&&e.jsx("span",{className:"text-[10px] font-semibold text-accent",children:"unsaved"}),!E&&n.overridingProjects.length>0&&e.jsx("span",{title:He(n),children:e.jsxs(I,{tone:"dim",children:[n.overridingProjects.length," override",n.overridingProjects.length>1?"s":""]})}),K?e.jsxs("span",{className:"flex items-center gap-1",onClick:_=>_.stopPropagation(),children:[e.jsx("button",{onClick:()=>je(n.name),disabled:D,title:`Delete ${n.name}`,className:"text-[10px] font-semibold text-red-400 hover:text-red-300",children:"confirm"}),e.jsx("button",{onClick:()=>S(null),title:"Cancel",className:"text-[10px] text-fg-faint hover:text-fg",children:"cancel"})]}):e.jsx("button",{onClick:_=>{_.stopPropagation(),S(n.name)},title:`Delete ${n.name}`,className:"opacity-0 group-hover:opacity-100 text-fg-faint hover:text-red-400 transition-opacity",children:"×"})]})]}),n.description&&e.jsx("span",{className:"truncate text-fg-faint",children:n.description})]},n.name)})]}),detail:g?e.jsx(Je,{obj:g,set:ge,saved:l,dirty:q,isNew:B,busy:D,confirmDelete:N,setConfirmDelete:L,onDuplicate:pe,onRevert:ue,onSave:be,onDelete:ve,onDropOverride:we,projects:o,selected:T,onSelect:k,onSaveOverride:ye}):e.jsx(H,{title:"select an agent"})})})}const at=v.memo(Ue);function Je({obj:t,set:a,saved:s,dirty:i,isNew:d,busy:f,confirmDelete:r,setConfirmDelete:p,onDuplicate:y,onRevert:m,onSave:h,onDelete:x,onDropOverride:N,projects:L,selected:j,onSelect:S,onSaveOverride:D}){const w=J(),c=!d&&s?s.path:`${w??"~"}/.claude/agents/${t.name}.md`,b=i||d;return e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-line flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm font-semibold text-fg font-mono",children:t.name}),d?e.jsx(I,{tone:"accent",children:"unsaved draft"}):i?e.jsx(I,{tone:"warn",children:"edited"}):e.jsx(I,{tone:"good",children:"saved"}),e.jsx("span",{className:"ml-auto min-w-0",children:e.jsx(re,{path:c})})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsx(P,{label:"name",hint:"Filename on disk — lowercase, hyphenated.",children:e.jsx("input",{value:t.name,onChange:o=>a({name:o.target.value.toLowerCase()}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg font-mono"})}),e.jsx(P,{label:"description",hint:"Shown in the list and in agent pickers.",children:e.jsx("input",{value:t.description,onChange:o=>a({description:o.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1 text-xs text-fg"})}),e.jsx(fe,{value:t.model,onChange:o=>a({model:o})}),e.jsx(me,{value:t.effort,model:t.model,onChange:o=>a({effort:o})}),!d&&s&&e.jsx(Ye,{saved:s,projects:L,selected:j,onSelect:S,busy:f,onSave:D}),e.jsx(P,{label:"tools",hint:`${t.tools.length} of ${Z.length} granted. Anything not ticked is refused at call time.`,children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Z.map(o=>{const $=t.tools.includes(o);return e.jsx("button",{onClick:()=>a({tools:$?t.tools.filter(k=>k!==o):[...t.tools,o]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${$?"bg-sage/15 text-sage-dark border-sage/30":"bg-bg-hi text-fg-faint border-line"}`,children:o},o)})})}),e.jsx(P,{label:"color",children:e.jsx("div",{className:"flex gap-1.5",children:Ge.map(o=>e.jsx("button",{title:o||"none",onClick:()=>a({color:o}),className:"w-5 h-5 rounded",style:{background:o?de[o]:"transparent",border:t.color===o?"2px solid var(--accent, #b85c34)":"1px solid var(--line, #555)"}},o||"none"))})}),e.jsx(P,{label:"tags",hint:"Session mission tags this persona is associated with — shown as the default agent on the Tags tab.",children:e.jsx("div",{className:"flex flex-wrap gap-1.5",children:A.map(o=>{const $=t.tags.includes(o.tag),k=Y(o.tag);return e.jsxs("button",{onClick:()=>a({tags:$?t.tags.filter(T=>T!==o.tag):[...t.tags,o.tag]}),className:`px-2 py-0.5 rounded-full text-[11px] font-mono border ${$?`${k.bg} ${k.text} ${k.border?"border-current/30":"border-transparent"}`:"bg-bg-hi text-fg-faint border-line"}`,children:["#",o.tag]},o.tag)})})}),e.jsx(P,{label:"definition",hint:"The system prompt this persona runs under.",children:e.jsx("textarea",{rows:9,value:t.body,onChange:o=>a({body:o.target.value}),className:"w-full bg-bg border border-line rounded px-2 py-1.5 text-xs text-fg font-mono leading-relaxed resize-y"})}),e.jsx(P,{label:"project overrides",hint:"Open projects that shadow this definition with a local copy.",children:s&&(s.overrideDetails??[]).length>0?e.jsx("div",{className:"flex flex-wrap gap-1.5",children:(s.overrideDetails??[]).map(o=>e.jsxs("span",{className:"inline-flex items-center gap-1.5 bg-bg-elev border border-line rounded px-2 py-0.5 text-[11px] font-mono text-fg-dim",children:[o.project,e.jsx("button",{onClick:()=>N(o.cwd,o.project),title:"Drop the local copy",className:"text-fg-faint hover:text-fg",children:"×"})]},o.cwd))}):e.jsx("div",{className:"text-xs text-fg-faint italic",children:d?"save first to see project overrides.":"no open project overlays this agent — the global definition applies everywhere."})})]}),e.jsx("div",{className:"px-4 py-2.5 border-t border-line flex items-center gap-2 flex-wrap",children:r?e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"text-xs text-fg-dim",children:["Delete ",e.jsx("strong",{className:"font-mono",children:t.name})," and its file?"]}),e.jsx(R,{variant:"danger",onClick:x,disabled:f,children:"Delete"}),e.jsx(R,{onClick:()=>p(!1),children:"Keep"})]}):e.jsxs(e.Fragment,{children:[e.jsx(R,{onClick:y,disabled:f,children:"Duplicate"}),!d&&e.jsx(R,{variant:"danger",onClick:()=>p(!0),disabled:f,children:"Delete"}),e.jsx("div",{className:"flex-1"}),b&&e.jsx("span",{className:"text-[11px] text-fg-faint",children:"unsaved changes"}),e.jsx(R,{onClick:m,disabled:!b||f,children:"Revert"}),e.jsx(R,{variant:"primary",onClick:h,disabled:!b||f,children:f?"Saving…":d?"Create":"Save"})]})})]})}function P({label:t,hint:a,children:s}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint mb-1.5 font-mono",children:t}),s,a&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug",children:a})]})}const z="latest",X="Blocked by the availableModels allowlist in your Claude settings";function fe({value:t,onChange:a,label:s="default model",hint:i,testIdPrefix:d="",inheritLabel:f}){var F,W;const{catalog:r,loading:p,degraded:y,refresh:m}=se(null),h=r?["inherit",...r.aliases]:[...De],x=(r==null?void 0:r.availableModels)??null,N=l=>!!x&&l!=="inherit"&&!x.includes(l),L=(l,g)=>!!x&&!x.includes(l)&&!(g&&x.includes(g)),j=t||"inherit",S=((F=/\[[^\]]*\]$/.exec(j))==null?void 0:F[0])??"",D=h.includes(j),w=!D&&r&&M(j)&&h.includes(M(j)+S)?M(j)+S:null,c=D?j:w??j,b=M(c),o=((W=/\[[^\]]*\]$/.exec(c))==null?void 0:W[0])??"",$=!!r&&j!=="inherit"&&!!b&&h.includes(c),k=$?r.models.filter(l=>M(l)===b).map(l=>l+o):[],T=D?z:j,O={};if(r)for(const l of h)N(l)&&(O[l]=X);const V={};for(const l of k)L(l,b)&&(V[l]=X);return e.jsxs(P,{label:s,hint:i??"This persona's default model for its Epics — sets the --model an Epic launches with (Terminal + Chat both honor it). 'inherit' falls back to each view's own default, not this Settings page. Cheap models for read-only personas; opus for judgement calls.",children:[e.jsx("div",{"data-testid":`${d}model-row`,children:e.jsx(U,{options:h,value:c,onChange:a,mono:!0,blocked:O,labels:f?{inherit:f}:void 0})}),$&&e.jsxs("div",{className:"mt-2","data-testid":`${d}model-version-row`,children:[e.jsx("div",{className:"text-[10.5px] text-fg-faint mb-1 font-mono",children:"version"}),e.jsx(U,{options:[z,...k],value:T,onChange:l=>a(l===z?c:l),mono:!0,blocked:V})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint mt-1 leading-snug flex items-center gap-2",children:[e.jsx("span",{children:r?`Models are live-read from the installed claude CLI${y?" (cached — CLI probe unavailable)":""}. "latest" keeps the floating alias.`:p?"Loading model catalog…":"catalog unavailable — showing the standard list."}),e.jsx("button",{"data-testid":`${d}model-catalog-refresh`,onClick:()=>{m()},disabled:p,className:"underline text-fg-dim disabled:opacity-40",children:"refresh"})]})]})}function me({value:t,model:a,onChange:s,label:i="effort",testIdPrefix:d="",inheritLabel:f}){const{catalog:r}=se(null),p=r&&r.effortLevels.length?["inherit",...r.effortLevels]:[...Ee],y=(r==null?void 0:r.settingsEffortLevels)??[],m=r?p.filter(N=>N!=="inherit"&&!y.includes(N)):[],h=t||"inherit",x=h!=="inherit"&&_e(a)===!1;return e.jsxs(P,{label:i,hint:r?`Effort levels are live-read from the installed claude CLI (what /effort accepts). ${m.length?`${m.join(", ")} ${m.length>1?"are":"is"} session-only — settings.json accepts ${y.join(", ")}. `:""}'inherit' writes no effort: line.`:"catalog unavailable — showing the standard list. 'inherit' writes no effort: line.",children:[e.jsx("div",{"data-testid":`${d}effort-row`,children:e.jsx(U,{options:p,value:h,onChange:s,mono:!0,labels:f?{inherit:f}:void 0})}),m.length>0&&e.jsx("div",{className:"text-[11px] text-fg-faint mt-1 font-mono","data-testid":`${d}effort-session-only`,children:m.map(N=>`${N} (session-only)`).join(" · ")}),x&&e.jsx("div",{className:"text-[11px] text-amber-400 mt-1 leading-snug","data-testid":`${d}effort-unsupported-note`,children:"The selected model does not support effort — the CLI will ignore this setting."})]})}function Ye({saved:t,projects:a,selected:s,onSelect:i,busy:d,onSave:f}){var S,D,w;const r=J(),p=new Map;for(const c of a)p.set(c.name,(p.get(c.name)??0)+1);const y=c=>{var k;const b=(p.get(c.name)??0)>1?Te(c.cwd,r):c.name,o=(k=t.overrideDetails)==null?void 0:k.find(T=>T.cwd===c.cwd);if(!o)return b;const $=ce(o);return`${b} — ${$.length?`overrides ${$.join(", ")}`:"overlay"}`},m=s?(S=t.overrideDetails)==null?void 0:S.find(c=>c.cwd===s.cwd):void 0,h=!!(m!=null&&m.bodyOverridden),x=((D=m==null?void 0:m.values)==null?void 0:D.model)??"inherit",N=((w=m==null?void 0:m.values)==null?void 0:w.effort)??"inherit",L=t.model??"inherit",j=t.effort??"inherit";return e.jsxs("div",{"data-testid":"project-override-block",className:s?"border border-accent/40 rounded p-3 space-y-3 bg-accent/5":"border border-dashed border-line rounded p-3 space-y-3",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:`text-[10.5px] font-semibold uppercase tracking-wide font-mono ${s?"text-accent":"text-fg-faint"}`,children:"project override"}),e.jsxs("select",{"data-testid":"override-project-select",value:(s==null?void 0:s.cwd)??"",onChange:c=>i(c.target.value||null),disabled:d||a.length===0,className:"rounded-md border border-line bg-bg px-2 py-1.5 font-mono text-[12.5px] text-fg disabled:opacity-60",children:[e.jsx("option",{value:"",children:"Choose a project…"}),a.map(c=>e.jsx("option",{value:c.cwd,children:y(c)},c.cwd))]})]}),a.length===0?e.jsx("div",{"data-testid":"project-override-none",className:"text-[11px] text-fg-faint leading-snug",children:"No open project tabs — open a project tab to override this persona's model or effort for it."}):s?e.jsxs("div",{"data-testid":"project-override",className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(I,{tone:"accent",children:[s.name," only"]}),e.jsx("span",{className:"ml-auto min-w-0",children:e.jsx(re,{path:`${s.cwd}/.claude/agents/${t.name}.md`})})]}),e.jsxs("div",{className:"text-[11px] text-fg-faint leading-snug",children:["Changes what the SCHEDULER (and new Epics) spawn for ",e.jsx("strong",{children:s.name})," only — a frontmatter-only overlay with just the keys you set; the persona's body stays the global one. The global model/effort rows edit the machine-wide persona and are never touched here."]}),h&&e.jsxs("div",{"data-testid":"project-override-fullbody",className:"text-[11px] text-amber-400 leading-snug",children:[s.name,' already has a FULL-BODY override of this persona (its own definition text). It is shown as-is and not converted to a frontmatter-only overlay — edit that file directly, or drop it with × under "project overrides" below.']}),e.jsxs("fieldset",{disabled:d||h,className:"space-y-3 border-0 p-0 m-0 min-w-0",children:[e.jsx(fe,{value:x,onChange:c=>{h||f({model:c,effort:N})},label:"project model",hint:"'use global' writes no model: line in the overlay.",testIdPrefix:"override-",inheritLabel:"use global"}),e.jsx(me,{value:N,model:x!=="inherit"?x:L,onChange:c=>{h||f({model:x,effort:c})},label:"project effort",testIdPrefix:"override-",inheritLabel:"use global"})]}),e.jsx("div",{"data-testid":"override-provenance",className:"text-[11px] font-mono text-fg-dim space-y-0.5",children:[["model",L,x],["effort",j,N]].map(([c,b,o])=>e.jsxs("div",{"data-testid":`override-provenance-${c}`,children:[c,": ",o!=="inherit"?e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global)"})," → ",e.jsx("span",{className:"text-accent",children:o})," ",e.jsx("span",{className:"text-fg-faint",children:"(this project)"})]}):e.jsxs(e.Fragment,{children:[b," ",e.jsx("span",{className:"text-fg-faint",children:"(global — not overridden)"})]})]},c))})]}):e.jsx("div",{"data-testid":"project-override-unselected",className:"text-[11px] text-fg-faint leading-snug",children:"Pick an open project to see or set this persona's model and effort for that project only. A project that already overrides this persona says what it overrides."})]})}export{at as AgentLibrary};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{aT as Ce,aG as re,al as Ee,b0 as gs,aq as Se,ak as ue,ao as te,b5 as H,bm as Oe,bl as pe,bp as Et,aN as f,ai as xe,bv as xs,ax as t,c as Ve,I as me,L as mt,p as ms,K as ge,u as bs,V as ws,e as vs,X as js,a$ as Ns,bj as tt,bc as ys,aX as ks,af as bt,aE as _t,bu as $e,Q as Fe,aL as _e,a as st,a_ as nt,U as Tt,y as Lt,o as Ot,q as Ss,m as at,G as it,O as $s,g as ie,h as B,am as Ft,bn as Cs,aM as Ps,x as Ds,aP as qt,by as Bt,Z as Rs,aH as wt,bd as vt,l as ye,z as jt,aV as Nt,k as As,b3 as Ms,a4 as Is,v as Ht,W as Es,bq as yt,aZ as _s}from"./index-BLORXCcT.js";import{f as Ts,a as Ls,s as Os}from"./historyTotals-dT8vcKzX.js";import"./monaco-editor-BsIlgG7c.js";function Fs(e){const s=new Map(e.map(r=>[r.slug,r])),n=new Map,a=new Set,d=[];function l(r){n.set(r,1),d.push(r);const i=s.get(r);for(const o of(i==null?void 0:i.dependsOn)??[]){if(!s.has(o))continue;const c=n.get(o);if(c===1){const p=d.indexOf(o);for(let u=p;u<d.length;u++)a.add(d[u])}else c===void 0&&l(o)}d.pop(),n.set(r,2)}for(const r of e)n.has(r.slug)||l(r.slug);return a}function qs(e,s){return(e.dependsOn??[]).map(n=>{const a=s.get(n);return a?{slug:n,status:a.status,missing:!1,needsReview:a.status==="needs_review"}:{slug:n,status:null,missing:!0,needsReview:!1}})}function Bs(e,s,n){const a=new Set(e.map(c=>c.slug)),d=new Set;for(const c of e)for(const p of c.dependsOn??[])a.has(p)&&d.add(p);const l=new Map,r=[];for(const c of e){const p=n.has(c.slug)?void 0:(c.dependsOn??[]).find(u=>a.has(u)&&!n.has(u));p?(l.has(p)||l.set(p,[]),l.get(p).push(c)):r.push(c)}const i=(c,p)=>c.slug.localeCompare(p.slug);r.sort(i);for(const c of l.values())c.sort(i);function o(c,p,u){const h=qs(c,s),x=n.has(c.slug);u.add(c.slug);const m=x?[]:(l.get(c.slug)??[]).filter(w=>!u.has(w.slug)).map(w=>o(w,p+1,u));return u.delete(c.slug),{row:c,depth:p,children:m,blockers:h,blocked:h.some(w=>!w.missing&&w.status!=="completed"),hasNeedsReviewBlocker:h.some(w=>w.needsReview),hasMissingDep:h.some(w=>w.missing),cycle:x,parallelEligible:(c.dependsOn??[]).length===0&&!d.has(c.slug)}}return r.map(c=>o(c,0,new Set))}function Gt(e,s,n){const a=new Map((n??e).map(c=>[c.slug,c])),d=Fs(e),l=[],r=new Map,i=new Map;for(const c of e){const p=Ce(c,s),u=p.epicId??"__none__";r.has(u)||(l.push(u),r.set(u,[]),i.set(u,{epicId:p.epicId,label:p.known&&p.label?p.label:p.epicId?`Epic ${p.epicId.slice(0,12)}…`:"No Epic",known:p.known})),r.get(u).push(c)}const o=l.map(c=>{const p=i.get(c),u=r.get(c),h=Bs(u,a,d),x={};for(const m of u){const w=m.status??"unknown";x[w]=(x[w]??0)+1}return{epicId:p.epicId,label:p.label,known:p.known,nodes:h,counts:x,total:u.length}});return o.sort((c,p)=>c.epicId===null?1:p.epicId===null?-1:c.known!==p.known?c.known?-1:1:c.label.localeCompare(p.label)),o}function qe(e){const s=[],n=a=>{s.push(a);for(const d of a.children)n(d)};for(const a of e)n(a);return s}function Ke(e){return String(e??"").replace(/^\d+-/,"")}function Te(e){const s=new Set,n=new Map;for(const a of e){s.add(a.slug);const d=Ke(a.slug),l=n.get(d);l?l.push(a.slug):n.set(d,[a.slug])}return e.map(a=>{const d=a.dependsOn;if(!d||d.length===0)return a;let l=!1;const r=d.map(i=>{if(s.has(i))return i;const o=n.get(Ke(i));return o&&o.length===1?(l=!0,o[0]):i});return l?{...a,dependsOn:r}:a})}const Hs=15e4,Je=e=>e==="completed"||e==="skipped",ke=e=>e==="running"||e==="investigating",Wt=e=>e==="failed"||e==="needs_review"||e==="quarantined",Gs=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Vt(e){if(e<=5e3)return"~now";if(e<6e4)return`~${Math.round(e/1e3)}s`;const s=Math.round(e/6e4);return s<60?`~${s}m`:`~${Math.floor(s/60)}h${String(s%60).padStart(2,"0")}m`}function Ut(e,s){const n=e.estimateMinutes?e.estimateMinutes*6e4:null;return n?`${Math.min(99,Math.floor(s/n*100))}%`:Ee(s)}function Ws(e){let s=0,n=0;for(const a of e)if(a.status==="completed"&&a.startedAt&&a.finishedAt){const d=Date.parse(a.finishedAt)-Date.parse(a.startedAt);d>0&&(s+=d,n++)}return n===0?Hs:s/n}function Le(e){const s=re(e);return s===null?1/0:Number(s)}function Xe(e,s){const n=Le(e.slug)-Le(s.slug);return n!==0&&!Number.isNaN(n)?n:e.slug.localeCompare(s.slug)}function Vs(e){let s=0;for(const n of e.statusHistory??[])n.to==="pending"&&n.from!==null&&s++;return s}function Us(e){return e.some(n=>ke(n.status))?"active":e.every(n=>Je(n.status))?"done":e.filter(n=>n.status!=="quarantined").length===0?"draft":"queued"}function zs(e,s,n,a){switch(e){case"done":return`${s.doneCount}/${s.rows.length} done`;case"running":return`${s.runningCount} running · ${n}`;case"held":return`${s.heldCount} held`;case"blocked":return`${s.blockedCount+a} blocked`;default:return`${n} ready`}}function Qs(e,s){return e._firstNum!==s._firstNum?e._firstNum<s._firstNum?-1:1:e._firstSlug.localeCompare(s._firstSlug)}function Ys(e,s){const n=new Map(e.map(l=>[l.row.slug,l.row.slug])),a=l=>{for(;n.get(l)!==l;)n.set(l,n.get(n.get(l))),l=n.get(l);return l};for(const l of e)for(const r of l.row.dependsOn??[])s.has(r)&&n.set(a(l.row.slug),a(r));const d=new Map;for(const l of e){const r=a(l.row.slug),i=d.get(r);i?i.push(l):d.set(r,[l])}return[...d.values()]}function Ks(e,s){if(e.length>0&&e.every(n=>!!n.row.planId)){const n=new Map;for(const a of e){const d=n.get(a.row.planId);d?d.push(a):n.set(a.row.planId,[a])}return[...n.values()]}return Ys(e,s)}function Js(e,s,n,a){const d=[],l=[e];for(a.add(e.row.slug);l.length>0;){const r=l.pop();d.push(r);for(const i of r.row.dependsOn??[])if(n.has(i)&&!a.has(i)){a.add(i);const o=s.get(i);o&&l.push(o)}}return d}function Xs(e,s){const n=new Map(e.map(i=>[i.row.slug,i])),a=new Set,d=[],l=e.filter(i=>Ke(i.row.slug).startsWith("validate-")).sort((i,o)=>Xe({slug:i.row.slug},{slug:o.row.slug}));for(const i of l)a.has(i.row.slug)||d.push({nodes:Js(i,n,s,a),validateSlug:i.row.slug});const r=e.filter(i=>!a.has(i.row.slug));if(r.length>0){const i=new Set(r.map(o=>o.row.slug));for(const o of Ks(r,i))d.push({nodes:o,validateSlug:null})}return d}function Zs(e){return e.replace(/^validate[\s:-]*/i,"").trim()}function rt(e,s){if(e.length===0)return[];const n=Te(e),a=s.now??Date.now(),d=s.avgDurationMs??Ws(n),l=Math.max(1,s.concurrency??1),r=new Map(n.map(u=>[u.slug,u])),i=u=>u.status==="pending"&&(u.dependsOn??[]).every(h=>r.get(h)===void 0||r.get(h).status==="completed"),o=new Map;n.filter(i).sort(Xe).forEach((u,h)=>o.set(u.slug,h));const c=Gt(n,s.sessions,n),p=[];for(const u of c){const h=qe(u.nodes),x=new Set(h.map(S=>S.row.slug)),m=new Map(h.map(S=>[S.row.slug,S])),w=[];for(const S of Xs(h,x)){const y=S.nodes,L=new Set(y.map(j=>j.row.slug)),k=new Map,E=new Set,D=j=>{const $=m.get(j);return($.row.dependsOn??[]).filter(q=>L.has(q)&&!($.cycle&&m.get(q).cycle))},P=j=>{const $=k.get(j);if($!==void 0)return $;if(E.has(j))return 0;E.add(j);let q=0;for(const W of D(j))q=Math.max(q,P(W));return E.delete(j),k.set(j,q+1),q+1};for(const j of y)P(j.row.slug);const T=y.map(j=>{const $=j.row,q=($.dependsOn??[]).filter(W=>x.has(W));return{slug:$.slug,title:$.title,status:$.status,stage:k.get($.slug),prdNumber:re($.slug),rowKind:"dep",rowTrailing:"",cycle:j.cycle,estimateMinutes:$.estimateMinutes??null,deps:q,crossEpicDeps:($.dependsOn??[]).filter(W=>!x.has(W)),blockers:j.blockers,job:$}});T.sort(Xe);const K=T.reduce((j,$)=>Math.max(j,$.stage),0),V=new Map;for(const j of T){const $=j.job,q=m.get(j.slug),W=$.status;let U;if(Je(W)){const g=$.startedAt&&$.finishedAt?Date.parse($.finishedAt)-Date.parse($.startedAt):NaN;U={kind:"done",trailing:g>0?Ee(g):"",held:!1,blocked:!1}}else if(ke(W)){const g=$.startedAt?Math.max(0,a-Date.parse($.startedAt)):null;U={kind:"running",trailing:g===null?"":Ut($,g),held:!1,blocked:!1}}else if(W==="failed")U={kind:"failed",trailing:"failed",held:!1,blocked:!1};else if(W==="needs_review")U={kind:"review",trailing:"review",held:!1,blocked:!1};else if(W==="quarantined")U={kind:"quarantined",trailing:"quarantined",held:!1,blocked:!1};else{const g=q.blockers.filter(v=>!v.missing&&v.status!=="completed");if(g.length>0){const v=g.some(C=>Gs(C.status)),R=g[0].slug;U={kind:"dep",trailing:`←${re(R)??R}`,held:!v,blocked:v}}else if($.heldReason)U={kind:"gate",trailing:"gate",held:!0,blocked:!1};else{const v=Vs($),R=o.get($.slug)??0;U=v>0?{kind:"retry",trailing:`${v} ${v===1?"retry":"retries"}`,held:!1,blocked:!1}:{kind:"eta",trailing:Vt(R*d/l),held:!1,blocked:!1}}}V.set(j.slug,U)}const z=[];for(let j=1;j<=K;j++){const $=T.filter(_=>_.stage===j),q=$.find(_=>{const Z=V.get(_.slug).kind;return _.status==="pending"&&(Z==="eta"||Z==="retry")});if(q){const _=V.get(q.slug);_.kind="next",_.trailing="next"}let W=0,U=0,g=0,v=0,R=0,C=0;for(const _ of $){const Z=V.get(_.slug);_.rowKind=Z.kind,_.rowTrailing=Z.trailing,Je(_.status)?W++:ke(_.status)?U++:_.status==="pending"?(R++,Z.held&&g++,Z.blocked&&v++):Wt(_.status)&&C++}const M=W===$.length?"done":U>0?"running":v+C>0?"blocked":g>0?"held":"pending",O={n:j,rows:$,doneCount:W,runningCount:U,heldCount:g,blockedCount:v};z.push({...O,state:M,summary:zs(M,O,R,C)})}let J=0;for(const j of T){const $=j.estimateMinutes?j.estimateMinutes*6e4:d;if(j.status==="pending")J+=$;else if(ke(j.status)){const q=j.job.startedAt?Math.max(0,a-Date.parse(j.job.startedAt)):0;J+=Math.max(0,$-q)}}const X=T.reduce((j,$)=>Math.min(j,Le($.slug)),1/0),se=T.reduce((j,$)=>Math.max(j,Le($.slug)),-1/0),Y=u.known?gs(u.label).title:u.label,A=S.validateSlug?T.find(j=>j.slug===S.validateSlug):void 0,F=A&&Zs(A.title)||Y;w.push({epicId:u.epicId,waveIndex:0,index:0,label:F,epicLabel:Y,validateSlug:S.validateSlug,width:z.reduce((j,$)=>Math.max(j,$.rows.length),0),status:Us(T),prdCount:T.length,stageCount:K,doneCount:z.reduce((j,$)=>j+$.doneCount,0),runningCount:z.reduce((j,$)=>j+$.runningCount,0),heldCount:z.reduce((j,$)=>j+$.heldCount,0),blockedCount:z.reduce((j,$)=>j+$.blockedCount,0),etaMs:J/l,stages:z,_firstNum:X,_lastNum:se,_firstSlug:T[0].slug})}w.sort(Qs),w.forEach((S,y)=>{S.waveIndex=y+1});const N=w.filter(S=>S.validateSlug===null);N.forEach((S,y)=>{N.length>1&&(S.label=`${S.label} · plan ${y+1}/${N.length}`)});for(const S of w)p.push(S)}return p.sort((u,h)=>{if(u._lastNum!==h._lastNum)return u._lastNum>h._lastNum?-1:1;const x=(u.epicId??"").localeCompare(h.epicId??"");return x!==0?x:u.waveIndex-h.waveIndex}),p.map(({_firstNum:u,_lastNum:h,_firstSlug:x,...m},w)=>({...m,index:w+1}))}function en(e,s=Date.now()){const n=Te(e),a=new Map(n.map(x=>[x.slug,x])),d=new Date(s).toDateString();let l=0,r=0,i=0,o=0,c=0,p=0,u=0;for(const x of n)x.status==="pending"?(r++,(x.dependsOn??[]).every(w=>a.get(w)===void 0||a.get(w).status==="completed")&&l++):ke(x.status)?u++:x.status==="failed"?i++:x.status==="needs_review"?o++:x.status==="quarantined"?c++:x.status==="completed"&&x.finishedAt&&new Date(Date.parse(x.finishedAt)).toDateString()===d&&p++;let h=null;if(i+o+c>0){for(const x of rt(n,{sessions:{},now:s}))for(const m of x.stages)if(m.rows.some(w=>Wt(w.status))){(h===null||m.n<h)&&(h=m.n);break}}return{readyNow:l,totalQueued:r,heldByDeps:r-l,needsYou:i+o+c,needsYouStage:h,failedCount:i,needsReviewCount:o,doneToday:p,inFlight:u}}function tn(e){const s=new Map;for(const o of e.stages)for(const c of o.rows)s.set(c.slug,c);const n=o=>{var c;return((c=s.get(o))==null?void 0:c.cycle)===!0},a=new Map,d=new Set,l=(o,c)=>o.chain.length!==c.chain.length?o.chain.length>c.chain.length:o.est!==c.est?o.est>c.est:o.chain.join("\0")<c.chain.join("\0"),r=o=>{const c=a.get(o);if(c)return c;const p=s.get(o),u=p.estimateMinutes??0;if(d.has(o))return{chain:[o],est:u};d.add(o);let h=null;for(const m of p.deps){if(!s.has(m)||p.cycle&&n(m))continue;const w=r(m);(!h||l(w,h))&&(h=w)}d.delete(o);const x=h?{chain:[...h.chain,o],est:h.est+u}:{chain:[o],est:u};return a.set(o,x),x};let i=null;for(const o of s.keys()){const c=r(o);(!i||l(c,i))&&(i=c)}return i?i.chain:[]}const sn=300*6e4,nn={five_hour:"5-hour",session:"5-hour",weekly_all:"weekly",weekly:"weekly"};function an(e){return nn[e]??e.replace(/_/g," ")}function zt({snap:e,now:s,avgDurationMs:n,runningJobs:a}){const{config:d,jobs:l,paused:r,nextReset:i,utilization:o,utilizationWindow:c,effectiveConcurrency:p}=e;let u=0,h=0;for(const y of l)y.status==="pending"?u++:y.status==="completed"&&h++;const x=a.length,m=u+x,w=(p==null?void 0:p.cap)??5;if(x>0){const y=a.reduce((P,T)=>(P.startedAt??"")<(T.startedAt??"")?P:T),L=y.startedAt?s-Date.parse(y.startedAt):0,k=h+x,E=h+m,D=x>1?` · ${x}/${w} parallel`:"";return{kind:"running",line1:`Running ${k}/${E}${D} · ${Se(L)}`,line2:x===1?y.title:a.map(P=>P.title).join(", "),tooltip:a.map(P=>`${P.slug} (g${P.parallelGroup})`).join("; ")}}if(r){const y=r.resumeAt?Date.parse(r.resumeAt)-s:null;return{kind:"paused",line1:{rate_limit:"Paused — tokens exhausted",auth:"Paused — authentication failed",network:"Paused — network unreachable",reset_failure:"Paused — billing data unavailable",manual:"Paused — manual (you paused the queue)"}[r.reason]??`Paused — ${r.reason}`,line2:r.reason==="auth"?"Run `claude` in any terminal to refresh credentials, then Resume":y!==null&&y>0?`auto-resume ${ue(Date.parse(r.resumeAt))} (in ${te(y)})`:r.resumeAt?"resuming…":"no auto-resume scheduled",tooltip:r.resumeAt??"",action:{label:"Resume",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately"}}}if(m===0)return{kind:"idle",line1:"No work queued",line2:null};if((d.firePolicy??"when-available")==="manual")return{kind:"manual",line1:`Manual · ${u} pending`,line2:"click Fire next batch now to fire",action:{label:"Fire next batch now",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress."}};const S=d.utilizationThreshold??90;if(o==null)return{kind:"auto-soon",line1:`Auto · ${u} pending`,line2:"checking token availability…"};if(o>=S){const y=i?Date.parse(i)-s:null,L=c?an(c):null,k=y===null||Number.isNaN(y)||y>sn,E=y&&y>0?`resets ${ue(Date.parse(i))} (in ${te(y)})`:null;let D;return k?D=`${L??"binding"} window — long hold${E?`, ${E}`:", reset time unknown"}`:D=E?`${L?`${L} window `:""}next ${E}`:"will fire when usage drops",{kind:"auto-throttled",line1:`Auto · throttled (util ${o.toFixed(0)}% ≥ ${S}%)`,line2:D}}return{kind:"auto-soon",line1:`Auto · ${u} pending · util ${o.toFixed(0)}%`,line2:"fires within 2 min (poll cycle)"}}const rn=15e3,ln=new Set(["failed","needs_review","quarantined"]);function on(e){for(let s=e.parentElement;s;s=s.parentElement){const n=getComputedStyle(s).overflowY;if(n==="auto"||n==="scroll")return s}return null}function kt(){const s=Array.from(document.querySelectorAll("[data-job-row]")).find(a=>ln.has(a.dataset.jobStatus??""));if(!s)return;const n=on(s);n&&ks(n,s,{block:"nearest",behavior:"smooth"})}function dn(e,s){var n;switch(e.kind){case"paused":return`paused: scheduler is paused (${e.reason??"manual"})`;case"launch-blocked":return`launch-blocked: ${e.agentType} jobs can't launch${(n=e.block)!=null&&n.kind?` (${e.block.kind})`:""}`;case"idle":return"idle: 0 pending";case"saturated":{const a=s!=null?`, oldest ${te(s)}`:"";return`saturated: ${e.totalSlots??"?"} slot(s) busy${a}`}case"blocked":{const a=e.blockedChains.length;return`blocked: ${e.pending} pending, ${e.dispatchable} dispatchable — ${a} chain${a===1?"":"s"} stuck behind a failed/skipped dependency`}case"stalled":return`stalled: no dispatch attempt in ${e.idleMs!=null?te(e.idleMs):"?"} with ${e.dispatchable} dispatchable`;case"running":default:return`running: ${e.runningCount} in flight, ${e.pending} pending`}}function cn(e){const[s,n]=f.useState(null),a=tt(),d=ys(),l=a&&d;return f.useEffect(()=>{if(!l)return;let r=!0,i=!1,o=!1;const c=()=>{i||(i=!0,window.api.schedule.queueHealth(e).then(u=>{i=!1,o=!1,r&&n(u)},u=>{i=!1,!o&&(o=!0,H.error(`Queue health refresh failed: ${u instanceof Error?u.message:String(u)}`))}))};c();const p=setInterval(c,rn);return()=>{r=!1,clearInterval(p)}},[e,l]),s}const un={running:{dot:"bg-sage",text:"text-sage-dark"},paused:{dot:"bg-amber-500",text:"text-amber-600"},idle:{dot:"bg-fg-faint",text:"text-fg-faint"}};function pn(e,s,n){return e==="paused"||e==="launch-blocked"?"paused":e==="running"||e==="saturated"?"running":e?"idle":s?"paused":n>0?"running":"idle"}const Ue="px-2.5 py-1.5 rounded border border-line text-[12.5px] font-medium text-fg-dim hover:text-fg hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed whitespace-nowrap";function fn(e,s,n,a){var d;if(e==="agent"){const l=((d=a==null?void 0:a.cwd)==null?void 0:d.split("/").filter(Boolean).pop())||"another session",r=a!=null&&a.reason?` — "${a.reason}"`:"",i=s?new Date(s).getTime()-n:null,o=i==null?"":i>0?` — auto-resumes in ${te(i)}`:" — auto-resume pending";return`Paused by an agent in ${l}${r}${o}. Click Resume to restart now.`}if(e==="auth")return"Scheduler paused: Claude sign-in expired or invalid. Restart the app or re-run `claude login`, then Resume.";if(e==="rate_limit"){if(s){const l=new Date(s).getTime()-n;return l>0?`Paused for rate limit — resumes in ${te(l)}`:"Paused for rate limit — resume pending"}return"Paused for rate limit"}return e==="network"?"Paused: billing endpoint unreachable for 30+ min.":e==="manual"?"Scheduler paused manually — no new jobs start; running jobs continue. Click Resume to restart.":`Scheduler paused (${e})`}function hn({now:e}){const s=Oe(p=>p.snapshot);if(!s)return null;const n=s.paused,a=Object.entries(s.launchBlocks??{}),d=Object.entries(s.launchMitigations??{}),l=(n==null?void 0:n.reason)==="auth"||(n==null?void 0:n.reason)==="network",r="flex items-start gap-3 border-b px-0 py-1.5 text-[12.5px]",i="bg-red-950/10 border-red-700/30 text-red-800",o="bg-amber-400/10 border-amber-600/30 text-amber-700",c="shrink-0 px-2 py-0.5 rounded border border-current/40 hover:bg-white/20 text-[12px] font-medium";return t.jsxs(t.Fragment,{children:[n&&t.jsxs("div",{"data-testid":"pause-banner",className:`${r} ${l?i:o}`,children:[t.jsx("span",{className:"flex-1 leading-snug",children:fn(n.reason,n.resumeAt,e,n.by)}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Resume"})]}),a.map(([p,u])=>t.jsxs("div",{"data-testid":"launch-block-banner",className:`${r} ${i}`,children:[t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:["Launches for ",t.jsx("span",{className:"font-mono",children:p})," jobs are failing before any work starts",u.httpStatus?` (HTTP ${u.httpStatus}, ${u.kind})`:` (${u.kind})`,u.exhausted?" — held until the Claude CLI version changes or you press Retry now.":u.until?` — next automatic probe ${new Date(u.until).getTime()>e?`in ${te(new Date(u.until).getTime()-e)}`:"on the next tick"}.`:"."]}),t.jsx("div",{className:"opacity-80",children:u.hint}),t.jsxs("div",{className:"font-mono text-[11.5px] opacity-70 truncate",title:u.message,children:[u.attempts," failed probe",u.attempts===1?"":"s",u.claudeVersion?` · CLI ${u.claudeVersion}`:"",u.lastSlug?` · last: ${u.lastSlug}`:""," · ",u.message]})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),className:c,children:"Retry now"})]},`launch-block-${p}`)),d.map(([p,u])=>t.jsx("div",{"data-testid":"launch-mitigation-banner",className:`${r} ${o}`,children:t.jsxs("div",{className:"flex-1 leading-snug min-w-0",children:[t.jsxs("div",{className:"font-medium",children:[t.jsx("span",{className:"font-mono",children:p})," jobs are running in degraded mode"," ","(",t.jsx("span",{className:"font-mono",children:Object.entries(u.env).map(([h,x])=>`${h}=${x}`).join(" ")}),")",u.claudeVersion?` since CLI ${u.claudeVersion}`:"","."]}),t.jsx("div",{className:"opacity-80",children:u.hint})]})},`launch-mitigation-${p}`))]})}function gn({scopeCwd:e,subView:s,onSubView:n,filterText:a,onFilterText:d,planMode:l,onPlanMode:r,planToolsRef:i}){const o=Oe(C=>C.snapshot),c=pe(C=>C.sessions),p=cn(e),u=Et(),[h,x]=f.useState(()=>Date.now()),[m,w]=f.useState("—");f.useEffect(()=>{const C=setInterval(()=>x(Date.now()),3e4);return()=>clearInterval(C)},[]),f.useEffect(()=>{let C=!0;return Ts(30).then(M=>{if(!C||!M.ok||!M.data)return;const O=new Date,_=Be=>String(Be).padStart(2,"0"),Z=`${O.getFullYear()}-${_(O.getMonth()+1)}-${_(O.getDate())}`;w(Ls(Os(M.data,{day:Z})))}),()=>{C=!1}},[]);const N=f.useMemo(()=>((o==null?void 0:o.jobs)??[]).filter(C=>!e||C.cwd===e),[o,e]),S=f.useMemo(()=>en(N,h),[N,h]),y=f.useMemo(()=>{const C=rt(N,{sessions:c,now:h}),M=O=>C.filter(_=>_.status===O).length;return{active:M("active"),queued:M("queued"),draft:M("draft")}},[N,c,h]),L=f.useMemo(()=>{const C=new Date(h).toDateString(),M=[];for(const O of N)if(O.status==="completed"&&O.startedAt&&O.finishedAt&&new Date(Date.parse(O.finishedAt)).toDateString()===C){const _=Date.parse(O.finishedAt)-Date.parse(O.startedAt);_>0&&M.push(_)}return M.length?Math.round(M.reduce((O,_)=>O+_,0)/M.length/6e4):null},[N,h]);if(!o)return null;const k=p&&!p.unknown?p.verdict??null:null,E=p&&!p.unknown?p.slots??null:null,D=o.paused,P=pn((k==null?void 0:k.kind)??null,!!D,S.inFlight),T=un[P],K=N.filter(C=>C.status==="pending").length,V=N.filter(C=>C.status==="running").length,z=zt({snap:{...o,jobs:N},now:h,avgDurationMs:0,runningJobs:N.filter(C=>C.status==="running")}),J=p!=null&&p.unknown?`Queue health: unknown — ${p.reason??"state unavailable"}`:k?dn(k,(p==null?void 0:p.oldestRunningAgeMs)??null):"queue health loading…",X=xe(o.lastRunAt?Date.parse(o.lastRunAt):null,h),se=p!=null&&p.lastDispatchAttemptAt?xe(Date.parse(p.lastDispatchAttemptAt),h):"never",Y=[J,z.line1,k?`dispatchable ${k.dispatchable} · needs_review ${k.needsReviewCount}`:null,(p==null?void 0:p.oldestRunningAgeMs)!=null?`oldest running ${te(p.oldestRunningAgeMs)} (any project)`:null,`last batch fired ${X} (lastRunAt — advances only when a job launches)`,`last dispatch attempt ${se} (advances on every driver evaluation)`].filter(Boolean).join(`
|
|
2
|
-
`),A=o.utilization,F=o.pollHealth,j=F!=null&&!F.lastPollOk,$=xs(o.utilizationWindow),q=o.nextReset?Date.parse(o.nextReset):null,W=q?q>h?te(q-h):"soon":"—",U=(u==null?void 0:u.total)??5,g=(u==null?void 0:u.envOverride)===!0,v=o.config.firePolicy??"when-available",R=K===0&&V===0;return t.jsxs("div",{"data-testid":"scheduler-top-bands",className:"shrink-0 px-[18px]",children:[t.jsxs(Ve,{height:40,testId:"queue-health-header",className:"gap-3",children:[t.jsx("h1",{className:"m-0 font-serif text-[21px] font-semibold leading-none tracking-tight text-fg",children:"Scheduler"}),t.jsx("span",{className:"w-px h-[20px] bg-rule-structural","aria-hidden":"true"}),t.jsxs("span",{className:`inline-flex items-center gap-1.5 text-[12.5px] font-medium ${T.text}`,"data-testid":"scheduler-state-word","data-state":P,children:[t.jsx("span",{className:`w-2 h-2 rounded-full ${T.dot}`,"aria-hidden":"true"}),P]}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-meta",children:[S.inFlight," in flight · ",S.heldByDeps," held · last batch ",X]}),t.jsxs(me,{title:Y,testId:"scheduler-verdict-info",popoverTestId:"scheduler-info-popover",children:[t.jsx("pre",{className:"m-0 mb-2 whitespace-pre-wrap font-mono text-[11.5px] text-fg-dim",children:Y}),mt.scheduler&&t.jsx(ms,{content:mt.scheduler})]}),t.jsxs("span",{className:"ml-auto flex items-center gap-2",children:[t.jsx("button",{type:"button",onClick:()=>window.api.schedule.rescan().then(H.fromOutcome).catch(()=>H.error("Failed to rescan")),title:"Re-scan the prds/ folder. Use when you've added or edited PRDs on disk and want the queue to reflect them immediately.",className:Ue,children:"Refresh"}),D?t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resume(),title:"Clear the pause and resume queue immediately",className:Ue,children:"Resume"}):t.jsx("button",{type:"button",onClick:()=>window.api.schedule.pause(),title:"Stop NEW dispatch. Running jobs are not killed.",className:Ue,children:"Pause"}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire batch")),disabled:R,title:"Bypasses the billing-usage poll. Use when the meter is rate-limited or you want immediate progress.",className:"px-3 py-1.5 rounded bg-accent text-white text-[12.5px] font-semibold whitespace-nowrap disabled:opacity-40 disabled:cursor-not-allowed hover:opacity-90",children:"Fire next batch"})]})]}),t.jsx(hn,{now:h}),t.jsxs(Ve,{height:70,testId:"scheduler-kpi-band",children:[t.jsx(ge,{testId:"kpi-window",label:$?`${$} used`:"Window used",info:j?`Billing poll failing — this reading may be outdated (last good reading ${xe(F.lastPollAt,h)}). Machine-wide ${$??"binding"} window.`:`Share of the machine-wide ${$??"binding"} billing window consumed — the window closest to its limit.`,value:A==null?"—":`${Math.round(A)}%`,sub:`resets in ${W}`,third:t.jsx(bs,{pct:A??0,tone:j?"bg-amber-500":"bg-accent"})}),t.jsx(ge,{testId:"kpi-slots",label:"Slots",info:`Machine-wide session pool (${(E==null?void 0:E.source)==="env"?"SM_SESSION_SLOTS override":"Home tab cap"}), not scoped to this project`,value:E?`${E.inUse}/${E.total}`:"—",sub:"in use",third:E?t.jsx(ws,{filled:E.inUse,total:E.total}):null}),t.jsx(ge,{testId:"kpi-ready",label:"Ready now",info:"Pending rows whose dependsOn chain is fully satisfied right now",value:S.readyNow,sub:`of ${S.totalQueued} queued`,third:`${S.heldByDeps} held by deps`}),S.needsYou>0?t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsx("button",{type:"button","data-testid":"kpi-needs-you-jump",onClick:kt,className:"font-semibold text-accent hover:underline",title:"Scroll to the first failed / needs-review / quarantined row",children:S.needsYou}),sub:t.jsx("button",{type:"button",onClick:kt,className:"hover:underline",children:S.needsYouStage!=null?`blocking stage ${S.needsYouStage}`:"need attention"}),third:[S.failedCount>0&&`${S.failedCount} failed`,S.needsReviewCount>0&&`${S.needsReviewCount} needs review`,S.needsYou-S.failedCount-S.needsReviewCount>0&&`${S.needsYou-S.failedCount-S.needsReviewCount} quarantined`].filter(Boolean).join(" · ")}):t.jsx(ge,{testId:"kpi-needs-you",label:"Needs you",value:t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-[15px]",children:[t.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-sage","aria-hidden":"true"}),"all clear"]}),third:"0 failed · 0 needs review"}),t.jsx(ge,{testId:"kpi-done",label:"Done today",value:S.doneToday,sub:L!=null?`avg ${L}m`:"avg —",third:t.jsx("span",{"data-testid":"kpi-done-spend",children:m})}),t.jsx(ge,{testId:"kpi-concurrency",label:"Concurrency",info:"Start-jobs policy, concurrency cap and utilization threshold",infoTestId:"kpi-concurrency-info",infoAlignRight:!0,infoContent:t.jsxs("label",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"text-fg",children:"Start jobs"}),t.jsxs("select",{"data-testid":"kpi-fire-policy",value:v,onChange:C=>window.api.schedule.setConfig({firePolicy:C.target.value}),className:"border border-line bg-bg-hi rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"when-available: poll usage and fire when tokens are below threshold. manual: only on Run now.","aria-label":"Start jobs policy",children:[t.jsx("option",{value:"when-available",children:"when available"}),t.jsx("option",{value:"manual",children:"manually"})]})]}),value:t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(js,{value:U,min:0,max:(u==null?void 0:u.max)??10,disabled:g,onChange:C=>{Ns(C).catch(M=>{H.error(`Could not set session slots: ${M instanceof Error?M.message:String(M)}`)})},title:g?"pinned by SM_SESSION_SLOTS — unset the env var to edit":"Machine-wide claude -p session slots, shared with chat runs"}),g&&t.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-amber-600 bg-amber-400/10 border border-amber-400/30 rounded px-1 py-0",title:"Pinned by SM_SESSION_SLOTS — unset the env var to edit",children:"env"})]}),sub:"at once",third:v==="when-available"?t.jsxs("span",{children:["pause above"," ",t.jsx(vs,{value:o.config.utilizationThreshold??90,min:0,max:100,testId:"kpi-threshold",title:"Holds new dispatches when the highest of the 5-hour and weekly usage windows is at/above this percent (when-available policy only). Not the executor rate-limit pause — click to edit",onCommit:C=>window.api.schedule.setConfig({utilizationThreshold:C})})]}):null})]}),t.jsxs(Ve,{height:30,testId:"scheduler-plans-toolbar",className:"gap-3",children:[t.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:"Plans"}),t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint whitespace-nowrap","data-testid":"scheduler-plans-meta",children:[y.active," active · ",y.queued," queued · ",y.draft," draft · ",N.length," PRDs"]}),t.jsxs("span",{className:"ml-auto flex items-center gap-3",children:[t.jsx("span",{ref:i,className:"contents","data-testid":"scheduler-plan-tools"}),t.jsx("input",{type:"text",value:a,onChange:C=>d(C.target.value),placeholder:"filter PRDs…","aria-label":"Filter PRDs by title, slug, or project","data-testid":"scheduler-filter-input",className:"w-[180px] bg-bg-hi border border-line rounded px-2 py-0.5 text-[12px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint"}),t.jsx("span",{className:"inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Plan view mode",children:[["graph","Graph"],["list","List"],["critical","Critical path"]].map(([C,M])=>t.jsx("button",{type:"button","data-testid":`plan-mode-${C}`,"aria-pressed":l===C&&s==="queue",onClick:()=>{r(C),n("queue")},className:`px-2 py-0.5 text-[12px] ${l===C&&s==="queue"?"bg-bg-elev font-semibold text-fg":"text-fg-dim hover:text-fg"}`,children:M},C))}),t.jsx("span",{className:"w-px h-[16px] bg-rule-structural","aria-hidden":"true"}),[["prds","PRDs","Authored PRD source files on disk — edit, lint, archive, or queue them."],["history","History","The last 50 completed and failed jobs."],["machine","Machine","Machine-wide config that applies to every project — not this project’s live queue."]].map(([C,M,O])=>t.jsx("button",{type:"button",onClick:()=>n(C),"aria-pressed":s===C,title:O,className:`text-[12.5px] ${s===C?"font-semibold text-fg":"text-fg-faint hover:text-fg-dim"}`,children:M},C))]})]})]})}function Qt({options:e,value:s,onChange:n,pillPadding:a="px-3 py-1.5"}){return t.jsx("div",{className:"flex gap-1.5 flex-wrap",children:e.map(d=>{const l=d.value===s;return t.jsxs("button",{type:"button",onClick:()=>n(d.value),className:`rounded-full ${a} text-[12.5px] border transition-colors ${l?"bg-accent text-white border-accent font-semibold":"bg-bg-hi text-fg-dim border-line hover:border-fg-faint font-medium"}`,children:[d.label,d.count!==void 0&&t.jsxs("span",{children:[" ",d.count]})]},d.value)})})}function Yt(e,s=60){const n=e.trim();return n.length<=s?n:`${n.slice(0,s-1)}…`}function xn(e){return qe([e]).filter(s=>s.children.length===0).map(s=>s.row.slug)}function Kt(e){return e.nodes.map(s=>({rootSlug:s.row.slug,label:s.row.title||s.row.slug,terminals:xn(s)}))}function mn(e){const s=new Map;for(const n of e){const a=Kt(n);n.nodes.forEach((d,l)=>{const r=a.filter((i,o)=>o!==l);for(const i of qe([d]))s.set(i.row.slug,r)})}return s}function Jt({job:e,headChoices:s}){const[n,a]=f.useState(!1),d=f.useCallback((l,r)=>{a(!0),window.api.schedule.setPrdDisposition({slug:e.slug,cwd:e.cwd??void 0,disposition:l,dependsOn:r}).then(H.fromOutcome).catch(()=>H.error("Failed to change disposition")).finally(()=>a(!1))},[e.slug,e.cwd]);return e.disposition!=="append"&&s.length===0?null:t.jsxs("select",{"data-testid":"job-row-disposition-control",disabled:n,value:"",onChange:l=>{const r=l.target.value;if(r==="__new-head__")d("new-head");else if(r){const i=s.find(o=>o.rootSlug===r);i&&d("append",i.terminals)}},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border border-line/60 rounded px-1.5 py-0.5 cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed",title:"Change this wave's relationship to the rest of the Epic's plan",children:[t.jsx("option",{value:"",disabled:!0,children:"change disposition…"}),e.disposition==="append"&&t.jsx("option",{value:"__new-head__",children:"promote to new head"}),s.map(l=>t.jsxs("option",{value:l.rootSlug,children:["attach behind: ",Yt(l.label,40)]},l.rootSlug))]})}function bn(e,s,n=null){if(s.length===0||e.length===0)return e;const a=new Set,d=new Set;for(const r of e){a.add(r.slug);for(const i of bt(r))d.add(i)}const l=[];for(const r of s)r.archived!==!0||a.has(r.slug)||n&&r.cwd!==n||bt(r).some(i=>d.has(i))&&(a.add(r.slug),l.push({slug:r.slug,title:r.title,cwd:r.cwd,parallelGroup:r.parallelGroup,estimateMinutes:r.estimateMinutes,bodyPreview:"",status:r.archivedStatus??"completed",runId:null,startedAt:null,finishedAt:null,exitCode:null,error:null,dependsOn:r.dependsOn??void 0,sourcePromptId:r.sourcePromptId??null,epicId:r.epicId??null,synthetic:!0}));return l.length===0?e:[...e,...l]}const wn=[],vn=new Set(["failed","needs_review","quarantined"]);function jn(e){switch(e.status){case"completed":case"skipped":return"bg-sage";case"running":case"investigating":return"bg-accent";case"failed":return"bg-accent";case"needs_review":return"bg-butter";case"quarantined":return"bg-butter/60";default:return e.rowKind==="eta"||e.rowKind==="next"||e.rowKind==="retry"?"border border-fg-faint bg-transparent":"bg-fg-faint/40"}}function Nn(e){switch(e.status){case"running":case"investigating":return"bg-butter/10";case"failed":return"bg-accent/10";case"needs_review":return"bg-butter/25";default:return""}}function yn(e){switch(e.rowKind){case"running":case"dep":case"failed":return"text-accent";case"review":return"text-butter font-semibold";default:return"text-fg-faint"}}function kn({row:e,elapsedMs:s,listIndex:n,onFocused:a,headChoices:d=wn}){const[l,r]=f.useState(!1),i=e.job,o=s!==null&&e.rowKind==="running"?Ut(i,s):e.rowTrailing,c=e.status==="completed"||e.status==="skipped",p=e.rowKind==="dep"&&e.blockers.some(h=>!h.missing&&h.status!==null&&vn.has(h.status)),u=c||p;return t.jsxs("div",{role:"listitem","data-testid":"prd-row","data-slug":e.slug,className:"border-t border-rule-inner first:border-t-0",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":i.status,"data-job-index":n,onClick:()=>r(h=>!h),onFocus:()=>a(n),"aria-expanded":l,"aria-label":`${e.prdNumber?`PRD ${e.prdNumber}, `:""}${i.title}, ${i.status}${o?`, ${o}`:""}`,title:i.title,className:`w-full h-[31px] py-1 px-2 text-left flex items-center gap-1.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${Nn(e)}`,children:[t.jsx("span",{"aria-hidden":"true",className:`shrink-0 w-[7px] h-[7px] rounded-full ${jn(e)}`}),t.jsx("span",{className:"shrink-0 font-mono text-[10.5px] text-fg-faint w-[30px]",children:e.prdNumber?`#${e.prdNumber}`:""}),t.jsx("span",{className:`flex-1 min-w-0 truncate text-[12.5px] leading-tight ${u?"text-fg-faint":"text-fg font-medium"}`,children:i.title}),t.jsx("span",{"data-testid":"prd-row-trailing",className:`shrink-0 font-mono text-[10.5px] ${yn(e)}`,children:o})]}),l&&t.jsx(Sn,{row:e,elapsedMs:s,headChoices:d})]})}const Xt=f.memo(kn);function Sn({row:e,elapsedMs:s,headChoices:n}){const a=e.job,[d,l]=f.useState(!1),r=pe(x=>x.sessions),i=f.useMemo(()=>Ce(a,r),[a,r]),o=i.known&&i.epicId?r[i.epicId]:null,c=f.useCallback(x=>_t(x),[]),p="font-mono text-[11.5px] text-fg-dim leading-snug break-words",u="text-[12px] font-semibold bg-transparent border-0 cursor-pointer p-0",h=a.error?a.error.split(`
|
|
3
|
-
`)[0]:null;return t.jsxs("div",{"data-testid":"prd-row-detail",className:"px-3 py-2 bg-bg-elev/50 border-t border-rule-inner flex flex-col gap-1",children:[t.jsxs("div",{className:p,children:[a.status.replace(/_/g," "),a.exitCode!==null&&` · exit ${a.exitCode}`,a.verifierVerdict&&` · ${$e(a.verifierVerdict)}`,a.startedAt&&` · started ${ue(Date.parse(a.startedAt))}`,a.finishedAt&&` · finished ${ue(Date.parse(a.finishedAt))}`,s===null&&e.rowTrailing&&e.rowKind==="done"?` · took ${e.rowTrailing}`:""]}),e.cycle&&t.jsxs("div",{className:`${p} text-accent`,"data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",e.blockers.map(x=>x.slug).join(" ↔ ")||"self-referencing"]}),!e.cycle&&e.blockers.length>0&&t.jsxs("div",{className:p,"data-testid":"job-row-blockers",children:["depends on ",e.blockers.map(x=>`${x.slug} (${x.missing?"missing":(x.status??"unknown").replace(/_/g," ")})`).join(", ")]}),a.status==="pending"&&a.heldReason&&t.jsxs("div",{className:`${p} text-amber-400/90`,"data-testid":"job-row-held-reason",children:["held · ",a.heldReason]}),h&&t.jsx("div",{className:`${p} text-accent/80`,children:h}),!a.synthetic&&t.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1 pt-0.5",children:[o&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:o.goalText,onClick:()=>c(o.id),className:`${u} text-accent hover:text-accent/80`,children:"view epic →"}),a.runId&&t.jsx("button",{type:"button",onClick:()=>l(!0),className:`${u} text-fg-dim hover:text-fg`,children:"view log →"}),a.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(a.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:`${u} text-accent hover:text-accent/80`,children:"adopt PRD →"}),a.status!=="pending"&&a.status!=="running"&&a.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(a.slug,a.cwd??void 0),className:`${u} text-fg-dim hover:text-fg`,children:"reset to pending →"}),a.disposition&&(a.status==="pending"||a.status==="quarantined")&&t.jsx(Jt,{job:a,headChoices:n})]}),d&&a.runId&&t.jsx(Fe,{runId:a.runId,slug:a.slug,title:a.title||a.slug,onClose:()=>l(!1)})]})}const ce=190,$n=7,Cn=5,Pn=[],Zt=e=>e==="completed"||e==="skipped",es=e=>e==="running"||e==="investigating",ts=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Re(e){return es(e.status)?0:ts(e.status)?1:Zt(e.status)?3:2}const Dn={done:"text-sage",running:"text-accent",held:"text-fg-faint",pending:"text-fg-faint",blocked:"text-butter"},Rn={done:"bg-sage",running:"bg-accent",held:"bg-fg-faint/50",pending:"bg-fg-faint/50",blocked:"bg-butter"};function An(e,s){return e.every(n=>Zt(n.status))?`+${e.length} done`:e.every(n=>n.rowKind==="dep"&&n.blockers.some(a=>!a.missing&&a.status!==null&&ts(a.status)))?`+${e.length} blocked`:`+${e.length} in stage ${s}`}function Mn({stage:e,epicId:s,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:r}){const[i,o]=f.useState(!1),c=f.useMemo(()=>e.rows.filter(k=>!(a.has(k.slug)&&(k.status==="completed"||k.status==="failed"))).map((k,E)=>({r:k,i:E})).sort((k,E)=>Re(k.r)-Re(E.r)||k.i-E.i).map(k=>k.r),[e.rows,a]),p=f.useMemo(()=>c.filter(k=>Re(k)<=1).length,[c]),u=Math.max(e.state==="done"?Cn:$n,p),h=i?c:c.slice(0,u),x=i?[]:c.slice(u),m=c.find(k=>k.status==="failed"),w=c.find(k=>k.status==="needs_review"),N=p>0&&(m!==void 0||w!==void 0),S=h.reduce((k,E,D)=>Re(E)<=1?D:k,-1),y=k=>t.jsx(Xt,{row:k,elapsedMs:es(k.status)&&k.job.startedAt?n-Date.parse(k.job.startedAt):null,listIndex:d.get(k.slug)??0,onFocused:r,headChoices:l.get(k.slug)??Pn},k.slug),L="flex-1 min-w-0 truncate h-[24px] text-[11.5px] font-medium text-fg-dim hover:text-fg border border-rule-structural rounded-sm bg-transparent cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"stage-column","data-stage":e.n,style:{width:ce},className:"shrink-0 border-l border-rule-structural first:border-l-0 flex flex-col self-stretch",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center gap-1.5 px-2 border-b border-rule-inner","data-testid":"stage-header",children:[t.jsx("span",{"aria-hidden":"true",className:`w-[7px] h-[7px] rounded-full shrink-0 ${Rn[e.state]}`}),t.jsxs("span",{className:`text-[10px] font-semibold uppercase tracking-wide ${Dn[e.state]}`,children:["Stage ",e.n]}),e.state==="blocked"&&t.jsx(me,{title:"Rows in this stage are failed / need review / are quarantined, or wait on one that is."}),t.jsx("span",{"data-testid":"stage-summary",className:"ml-auto font-mono text-[10.5px] text-fg-dim truncate",children:e.summary})]}),t.jsx("div",{role:"presentation",children:h.map((k,E)=>t.jsxs("div",{children:[y(k),N&&E===S&&t.jsxs("div",{"data-testid":"stage-attention-actions",className:"flex gap-1.5 px-2 py-1.5 border-t border-rule-inner",children:[m&&t.jsxs("button",{type:"button","data-testid":"stage-retry",title:`Reset ${m.slug} to pending`,onClick:()=>{window.api.schedule.resetJob(m.slug,m.job.cwd??void 0).then(D=>{D.ok||H.error(D.error??`Failed to reset ${m.slug}`)}).catch(()=>H.error(`Failed to reset ${m.slug}`))},className:L,children:["Retry ",m.prdNumber?`#${m.prdNumber}`:m.slug]}),w&&t.jsxs("button",{type:"button","data-testid":"stage-review",disabled:!s,title:s?"Open the authoring Epic — a needs_review PRD is a question routed back to it":"No authoring Epic recorded for this plan",onClick:()=>{s&&_t(s)},className:L,children:["Review ",w.prdNumber?`#${w.prdNumber}`:w.slug]})]})]},k.slug))}),(x.length>0||i&&c.length>u)&&t.jsx("button",{type:"button","data-testid":"stage-footer","aria-expanded":i,onClick:()=>o(k=>!k),className:"mt-auto h-[26px] border-t border-rule-inner font-mono text-[11px] text-fg-faint hover:text-fg-dim bg-transparent cursor-pointer",children:i?"show less ▴":`${An(x,e.n)} ▾`})]})}const we=6,ze=4,Ie=4,St=12,$t=5,ss=2,Ct=4,In={done:"bg-sage",running:"bg-accent",attention:"bg-butter",failed:"bg-red-600",pending:"bg-fg-faint/50"};function En(e){return e==="completed"||e==="skipped"?"done":e==="running"||e==="investigating"?"running":e==="failed"?"failed":e==="needs_review"||e==="quarantined"?"attention":"pending"}function _n(e){const s=[],n=[],a=[];let d=$t;for(const l of e){const r=Math.max(1,Math.ceil(l.rows.length/Ie));n.push(d),a.push(r*we),l.rows.forEach((i,o)=>{s.push({x:d+Math.floor(o/Ie)*we,y:ss+o%Ie*we,tone:En(i.status),title:`${i.prdNumber?`#${i.prdNumber}`:i.slug} ${i.title} — ${i.status}`})}),d+=r*we+St}return{dots:s,stageX:n,stageW:a,width:Math.max(0,d-St)+$t}}function ve(e,s){return e.findIndex(n=>n.rows.some(a=>s(a.status)))}const Ze=e=>e==="running"||e==="investigating",et=e=>e==="failed"||e==="needs_review"||e==="quarantined";function Tn({stages:e,first:s,perView:n,onSeek:a}){const d=f.useMemo(()=>_n(e),[e]),l=f.useMemo(()=>ve(e,Ze)>=0,[e]),r=f.useMemo(()=>ve(e,et)>=0,[e]),i=f.useRef(!1),o=e.length,c=Math.min(o-1,s+n-1),p=d.stageX[Math.min(s,o-1)]??0,u=(d.stageX[c]??0)+(d.stageW[c]??0),h=m=>{const w=m.currentTarget.getBoundingClientRect(),N=m.clientX-w.left;let S=0;for(let y=0;y<o;y++)d.stageX[y]<=N&&(S=y);a(Math.max(0,Math.min(o-1,S-Math.floor(n/2))))},x="px-2 h-[20px] text-[11.5px] disabled:opacity-40 disabled:cursor-not-allowed";return t.jsxs("div",{"data-testid":"plan-minimap",className:"h-[28px] flex items-center gap-3 px-3 border-t border-rule-inner",children:[t.jsxs("span",{className:"shrink-0 flex items-center gap-1 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Whole graph",t.jsx(me,{title:"Every PRD in this plan as one dot, grouped by stage. The rust box is the range of stages shown below — drag it to scroll."})]}),t.jsxs("div",{"data-testid":"plan-minimap-dots",role:"presentation",className:"relative shrink min-w-0 overflow-hidden cursor-ew-resize touch-none",style:{width:d.width,height:Ie*we-(we-ze)+2*ss},onPointerDown:m=>{var w,N;i.current=!0,(N=(w=m.currentTarget).setPointerCapture)==null||N.call(w,m.pointerId),h(m)},onPointerMove:m=>{i.current&&h(m)},onPointerUp:()=>{i.current=!1},onPointerCancel:()=>{i.current=!1},children:[d.dots.map((m,w)=>t.jsx("span",{title:m.title,"data-tone":m.tone,className:`absolute rounded-[1px] ${In[m.tone]}`,style:{left:m.x,top:m.y,width:ze,height:ze}},w)),t.jsx("span",{"data-testid":"plan-minimap-brush","aria-hidden":"true",className:"absolute top-0 bottom-0 border border-accent bg-accent/10 rounded-[2px] pointer-events-none",style:{left:p-Ct,width:u-p+2*Ct}})]}),t.jsxs("span",{className:"ml-auto shrink-0 font-mono text-[11.5px] text-fg-faint","data-testid":"plan-minimap-range",children:["stages ",Math.min(s+1,o),"–",c+1," of ",o]}),t.jsxs("span",{className:"shrink-0 inline-flex border border-line rounded overflow-hidden",role:"group","aria-label":"Jump the stage window",children:[t.jsx("button",{type:"button","data-testid":"minimap-running",disabled:!l,title:l?"Scroll to the lowest stage with a running PRD":"No stage has a running PRD",onClick:()=>a(ve(e,Ze)),className:`${x} text-fg-dim hover:text-fg`,children:"Running"}),t.jsx("button",{type:"button","data-testid":"minimap-blockers",disabled:!r,title:r?"Scroll to the lowest stage with a failed / needs-review / quarantined PRD":"No stage has a failed, needs-review or quarantined PRD",onClick:()=>a(ve(e,et)),className:`${x} text-fg-dim hover:text-fg border-l border-line`,children:"Blockers"})]})]})}const Ln=148;function On({stages:e,onSeek:s}){if(e.length===0)return null;const n=e[0].n,a=e[e.length-1].n;return t.jsxs("div",{"data-testid":"further-stages",style:{width:Ln},className:"shrink-0 border-l border-rule-structural flex flex-col",children:[t.jsxs("div",{className:"h-[30px] shrink-0 flex items-center px-2 border-b border-rule-inner text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Stage ",n,"–",a]}),t.jsxs("div",{className:"h-[22px] shrink-0 flex items-center gap-1 px-2 text-[10.5px] font-semibold uppercase tracking-wide text-fg-faint",children:["Further stages",t.jsx(me,{title:"Stages beyond the visible window. Click one to scroll the stage columns to it."})]}),e.map(d=>{const l=d.rows.length===0?0:d.doneCount/d.rows.length*100;return t.jsxs("button",{type:"button","data-testid":"further-stage-row","data-stage":d.n,title:`${d.summary} — scroll to stage ${d.n}`,onClick:()=>s(d.n-1),className:"h-[26px] px-2 flex items-center gap-2 border-t border-rule-inner bg-transparent hover:bg-bg-hi cursor-pointer text-left",children:[t.jsxs("span",{className:"font-mono text-[10.5px] text-fg-dim w-[50px] whitespace-nowrap shrink-0",children:["stage ",d.n]}),t.jsx("span",{role:"progressbar","aria-valuenow":d.doneCount,"aria-valuemin":0,"aria-valuemax":d.rows.length,className:"flex-1 h-[4px] rounded-sm bg-rule-inner overflow-hidden",children:t.jsx("span",{className:"block h-full bg-sage",style:{width:`${l}%`}})})]},d.n)})]})}const Fn=[],qn=e=>e==="running"||e==="investigating";function Bn(e){const s=tn(e),n=new Map,a=new Map;for(const i of e.stages){a.set(i.n,i.rows.length);for(const o of i.rows)n.set(o.slug,o)}const d=new Map;let l=0;const r=[];for(const i of s){const o=n.get(i);l+=o.estimateMinutes??0,d.set(o.stage,(d.get(o.stage)??0)+1),r.push({row:o,totalMinutes:l,othersInStage:0})}for(const i of r)i.othersInStage=(a.get(i.row.stage)??0)-(d.get(i.row.stage)??0);return r}function Hn({plan:e,now:s,indexBySlug:n,headChoicesBySlug:a,onRowFocused:d}){const l=f.useMemo(()=>Bn(e),[e]);return t.jsx("div",{"data-testid":"critical-path",className:"border-t border-rule-structural max-w-[640px]",children:l.map(({row:r,totalMinutes:i,othersInStage:o})=>t.jsxs("div",{"data-testid":"critical-entry","data-slug":r.slug,children:[t.jsxs("div",{className:"flex items-start",children:[t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(Xt,{row:r,elapsedMs:qn(r.status)&&r.job.startedAt?s-Date.parse(r.job.startedAt):null,listIndex:n.get(r.slug)??0,onFocused:d,headChoices:a.get(r.slug)??Fn})}),t.jsxs("span",{"data-testid":"critical-est",className:"shrink-0 h-[31px] px-3 flex items-center gap-2 font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:[t.jsx("span",{title:"estimateMinutes",children:r.estimateMinutes?`${r.estimateMinutes}m`:"—"}),t.jsxs("span",{className:"text-fg-dim",title:"Running total along the chain",children:["Σ ",i,"m"]})]})]}),o>0&&t.jsxs("div",{"data-testid":"critical-others",className:"h-[22px] px-3 flex items-center font-mono text-[11.5px] text-fg-faint border-t border-rule-inner",children:["stage ",r.stage," · +",o," not on the critical path"]})]},r.slug))})}const Pt=1,Dt=1350,Gn={active:"border-l-accent",queued:"border-l-rule-structural",done:"border-l-sage",draft:"border-l-fg-faint/40 border-dashed"},Wn={active:{label:"ACTIVE",cls:"bg-accent text-white border border-accent"},queued:{label:"QUEUED",cls:"text-fg-dim border border-fg-faint"},done:{label:"DONE",cls:"text-sage-dark border border-sage"},draft:{label:"DRAFT",cls:"text-fg-faint border border-dashed border-fg-faint"}},Vn=e=>String(e).padStart(2,"0");function Un({plan:e}){const s=Math.max(1,e.prdCount),n=e.doneCount/s*100,a=e.runningCount/s*100;return t.jsxs("span",{"data-testid":"plan-progress",role:"progressbar","aria-valuenow":e.doneCount,"aria-valuemin":0,"aria-valuemax":e.prdCount,className:"flex w-[160px] h-[5px] rounded-sm overflow-hidden bg-rule-inner shrink-0",children:[t.jsx("span",{className:"h-full bg-sage",style:{width:`${n}%`}}),t.jsx("span",{className:"h-full bg-accent",style:{width:`${a}%`}})]})}function zn({plan:e,mode:s="graph",now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:r,onOpenPrds:i}){var se,Y;const[o,c]=f.useState(e.status==="active"||e.status==="queued"),[p,u]=f.useState(!1),h=f.useRef(null),[x,m]=f.useState(0),[w,N]=f.useState(Dt),S=f.useMemo(()=>{const A=ve(e.stages,Ze);return A>=0?A:Math.max(0,ve(e.stages,et))},[e.stages]);f.useLayoutEffect(()=>{if(!o)return;const A=h.current,F=(A==null?void 0:A.clientWidth)||Dt,j=Math.max(0,Math.min(S,e.stageCount-Math.max(1,Math.ceil(F/ce))));A!=null&&A.clientWidth&&N(A.clientWidth),A&&(A.scrollLeft=j*ce),m(j)},[o]);const y=f.useMemo(()=>{let A=null;for(const F of e.stages)for(const j of F.rows){if(!j.job.runId)continue;const $=j.job.finishedAt?Date.parse(j.job.finishedAt):0;(!A||$>A.at)&&(A={runId:j.job.runId,slug:j.slug,title:j.title,at:$})}return A},[e.stages]),L=_e((Y=(se=e.stages[0])==null?void 0:se.rows[0])==null?void 0:Y.job.cwd)??"—",k=Wn[e.status],E=Math.max(1,Math.ceil(w/ce)),D=Math.max(0,Math.min(x-Pt,e.stageCount)),P=Math.min(e.stageCount,x+E+Pt),T=A=>{const F=Math.max(0,Math.min(e.stageCount-1,A));h.current&&(h.current.scrollLeft=F*ce),m(F)},K=Math.min(e.stageCount,x+E),V=A=>{const F=A.currentTarget,j=Math.floor(F.scrollLeft/ce);j!==x&&m(j),F.clientWidth&&F.clientWidth!==w&&N(F.clientWidth)},z="h-[24px] px-3 text-[12px] font-medium text-fg border border-rule-structural rounded-sm bg-transparent hover:bg-bg-hi cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed shrink-0",J=(()=>{switch(e.status){case"active":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Pauses the WHOLE scheduler (machine-wide) — there is no per-plan pause.",onClick:()=>{window.api.schedule.pause().catch(()=>H.error("Failed to pause the scheduler"))},className:z,children:"Pause plan"});case"queued":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Fires the next scheduler batch machine-wide (force tick) — it does not target this plan.",onClick:()=>{window.api.schedule.forceTick().then(H.fromOutcome).catch(()=>H.error("Failed to fire the next batch"))},className:z,children:"Run now"});case"done":return t.jsx("button",{type:"button","data-testid":"plan-action",disabled:!y,title:y?`Open the run log of ${y.slug}, the plan's last run`:"No run log recorded for this plan",onClick:()=>u(!0),className:z,children:"View run"});case"draft":return t.jsx("button",{type:"button","data-testid":"plan-action",title:"Open the PRDs sub-view on this plan's first PRD (the PRDs view has no per-Epic filter).",onClick:()=>{var A,F;return i==null?void 0:i(((F=(A=e.stages[0])==null?void 0:A.rows[0])==null?void 0:F.slug)??null)},className:z,children:"Schedule…"})}})(),X=e.etaMs>0?` · ${Vt(e.etaMs)} left`:"";return t.jsxs("section",{"data-testid":"plan-band","data-epic-id":e.epicId??"","data-plan-status":e.status,className:`border-l-[3px] ${Gn[e.status]} border-b border-rule-structural`,children:[t.jsxs("div",{className:"h-[32px] flex items-center gap-2.5 px-3","data-testid":"plan-header",children:[t.jsx("button",{type:"button","aria-expanded":o,"aria-label":o?"Collapse plan":"Expand plan","data-testid":"plan-toggle",onClick:()=>c(A=>!A),className:"shrink-0 w-[14px] text-[11px] text-fg-faint hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:o?"▾":"▸"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint shrink-0",children:Vn(e.index)}),t.jsx("span",{className:"font-serif text-[15px] font-bold text-fg truncate shrink-0 max-w-[320px]",title:e.epicLabel!==e.label?`${e.label} — ${e.epicLabel}`:e.label,"data-testid":"plan-label",children:e.label}),t.jsx("span",{"data-testid":"plan-chip",className:`shrink-0 rounded-sm px-1.5 py-[1px] text-[10px] font-bold tracking-wide ${k.cls}`,children:k.label}),t.jsx("span",{"aria-hidden":"true",className:"shrink-0 w-px h-[16px] bg-rule-structural"}),t.jsx("span",{className:"font-mono text-[11.5px] text-fg-faint truncate min-w-0","data-testid":"plan-meta",children:e.validateSlug!=null&&e.epicLabel!==e.label?t.jsxs(t.Fragment,{children:[L," · ",e.epicLabel," · ",e.prdCount," PRD",e.prdCount===1?"":"s"," · ",e.width," wide · ",e.stageCount," stage",e.stageCount===1?"":"s"]}):t.jsxs(t.Fragment,{children:[L," · ",e.prdCount," PRD",e.prdCount===1?"":"s",e.width>1?` · ${e.width} wide`:""," · ",e.stageCount," stage",e.stageCount===1?"":"s"]})}),t.jsx(me,{title:`${e.doneCount} done · ${e.runningCount} running · ${e.heldCount} held · ${e.blockedCount} blocked`}),t.jsxs("span",{className:"ml-auto font-mono text-[11.5px] text-fg-dim shrink-0","data-testid":"plan-progress-label",children:[e.doneCount,"/",e.prdCount,X]}),t.jsx(Un,{plan:e}),J]}),o&&s==="critical"&&t.jsx(Hn,{plan:e,now:n,indexBySlug:d,headChoicesBySlug:l,onRowFocused:r}),o&&s!=="critical"&&e.status==="active"&&t.jsx(Tn,{stages:e.stages,first:x,perView:E,onSeek:T}),o&&s!=="critical"&&t.jsxs("div",{className:"flex border-t border-rule-structural",children:[t.jsxs("div",{ref:h,"data-testid":"plan-stages",onScroll:V,className:"flex flex-1 min-w-0 overflow-x-auto",children:[D>0&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:D*ce}}),e.stages.slice(D,P).map(A=>t.jsx(Mn,{stage:A,epicId:e.epicId,now:n,hidden:a,indexBySlug:d,headChoicesBySlug:l,onRowFocused:r},A.n)),P<e.stageCount&&t.jsx("div",{"aria-hidden":"true",className:"shrink-0",style:{width:(e.stageCount-P)*ce}})]}),t.jsx(On,{stages:e.stages.slice(K),onSeek:T})]}),p&&y&&t.jsx(Fe,{runId:y.runId,slug:y.slug,title:y.title||y.slug,onClose:()=>u(!1)})]})}function Qn({section:e,children:s}){const[n,a]=f.useState(!0),d=Object.entries(e.counts).map(([l,r])=>`${r} ${l.replace(/_/g," ")}`).join(" · ");return t.jsxs("div",{className:"border-t border-line","data-testid":"backlog-epic-section","data-epic-id":e.epicId??"",children:[t.jsxs("button",{type:"button",onClick:()=>a(l=>!l),className:"w-full flex items-center gap-2.5 px-[18px] py-2.5 bg-bg-elev/60 hover:bg-bg-elev text-left","aria-expanded":n,title:e.label,children:[t.jsx("span",{className:`text-fg-faint inline-flex shrink-0 transition-transform duration-150 ${n?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(st,{name:"chevron",size:12})}),t.jsx("span",{className:"font-serif text-[14.5px] font-semibold text-fg truncate","data-testid":"backlog-epic-label",children:e.label}),t.jsxs("span",{className:"font-mono text-[11px] text-fg-faint shrink-0",children:[e.total," PRD",e.total===1?"":"s"]}),t.jsx("span",{className:"font-mono text-[11px] text-fg-faint truncate",children:d})]}),n&&s]})}const Yn=[],Kn=[],Jn={depth:0,blockers:Yn,blocked:!1,hasNeedsReviewBlocker:!1,hasMissingDep:!1,cycle:!1,parallelEligible:!1};function Xn(e){return e.missing?`${e.slug} (missing)`:e.needsReview?`${e.slug} (needs review)`:`${e.slug} (${(e.status??"unknown").replace(/_/g," ")})`}function Zn(e){return e.missing?"text-accent":e.needsReview?"text-butter font-semibold":e.status==="completed"?"text-sage":"text-amber-400/90"}function ea({job:e,eta:s,elapsedMs:n,avgDurationMs:a,listIndex:d,onFocused:l,hold:r,backlog:i=Jn,headChoices:o=Kn}){const[c,p]=f.useState(!1),[u,h]=f.useState(!1),x=pe(P=>P.sessions),m=f.useMemo(()=>Ce(e,x),[e,x]),w=m.known&&m.epicId?x[m.epicId]:null,N=f.useCallback(P=>{nt(P),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))},[]),S=e.status==="running",y=e.status==="failed";let L=null;S&&n!==null?L=`${Ee(n)} elapsed`:e.status==="completed"&&e.startedAt&&e.finishedAt?L=`took ${Se(Date.parse(e.finishedAt)-Date.parse(e.startedAt))}`:s&&(L=s);const k=e.error??null,E=y&&k?k.split(`
|
|
4
|
-
`)[0]:e.status==="needs_review"&&e.verifierVerdict?$e(e.verifierVerdict):null,D=S&&n!==null?Math.min(.99,n/a):0;return t.jsxs("div",{role:"listitem",className:"border-t border-line",children:[t.jsxs("button",{type:"button","data-job-row":!0,"data-job-status":e.status,"data-job-index":d,"data-depth":i.depth,onClick:()=>p(P=>!P),onFocus:()=>l(d),style:i.depth>0?{paddingLeft:18+i.depth*20}:void 0,className:`w-full text-left grid grid-cols-[116px_1fr_auto_auto] items-center gap-4 px-[18px] py-3.5 hover:bg-bg/40 focus:outline-none focus:ring-1 focus:ring-accent focus:ring-inset ${c?"bg-bg-elev/40":""}`,"aria-expanded":c,"aria-label":`${re(e.slug)?`PRD ${re(e.slug)}, `:""}${e.title}, ${e.status}${L?`, ${L}`:""}`,title:e.title,children:[t.jsx(Tt,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug",children:[re(e.slug)&&t.jsx(Lt,{n:re(e.slug)}),e.title,t.jsx(Ot,{leaked:e.leakedDescendants}),t.jsx(Ss,{count:e.leftoverCount,truncated:e.leftoverPathsTruncated,salvagePatch:e.salvagePatch}),i.parallelEligible&&t.jsx("span",{"data-testid":"job-row-parallel-eligible",title:"No dependsOn, and nothing in this Epic depends on it — can run any time a slot is free",className:"text-[10px] font-semibold uppercase tracking-wide text-sage/90 bg-sage/10 border border-sage/30 rounded px-1.5 py-0.5",children:"parallel"})]}),i.cycle&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-accent font-mono","data-testid":"job-row-cycle-warning",children:["⚠ dependsOn cycle — ",i.blockers.map(P=>P.slug).join(" ↔ ")||"self-referencing"]}),!i.cycle&&i.blockers.length>0&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 font-mono","data-testid":"job-row-blockers",children:[t.jsx("span",{className:i.blocked||i.hasMissingDep?"text-amber-400/90":"text-fg-faint",children:i.blocked||i.hasMissingDep?"blocked by ":"depends on "}),i.blockers.map((P,T)=>t.jsxs("span",{className:Zn(P),children:[T>0&&", ",Xn(P)]},P.slug))]}),E&&t.jsx("div",{className:`text-[12.5px] mt-0.5 ${y?"text-accent/80":"text-fg-faint"}`,children:E}),r&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-hold",children:r.dep?t.jsxs(t.Fragment,{children:["held · waiting on ",r.dep," (",r.depStatus,")"]}):t.jsxs(t.Fragment,{children:["held · ",r.reason??"launch blocked"]})}),!r&&e.status==="pending"&&e.heldReason&&t.jsxs("div",{className:"text-[12.5px] mt-0.5 text-amber-400/90 font-mono","data-testid":"job-row-held-reason",children:["held · ",e.heldReason]}),t.jsx(at,{epicId:m.epicId,label:m.label?Yt(m.label):null,onOpen:N,testId:"job-row-prompt-session-chip",className:"mt-0.5"})]}),t.jsx(it,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint shrink-0",children:[t.jsx($s,{status:e.status,overrun:e.overrun}),L,t.jsx("span",{className:`text-fg-faint inline-flex transition-transform duration-150 ${c?"rotate-90":""}`,"aria-hidden":"true",children:t.jsx(st,{name:"chevron",size:14})})]})]}),S&&!c&&t.jsx("div",{className:"h-1 bg-line mx-[18px] mb-3 rounded-full overflow-hidden",children:t.jsx("div",{className:"h-full bg-accent transition-all duration-1000",style:{width:`${Math.max(4,D*100)}%`}})}),c&&t.jsxs("div",{className:"px-[18px] py-5 grid grid-cols-[repeat(auto-fit,minmax(160px,1fr))] gap-5 bg-bg-elev/50 border-t border-line",children:[t.jsxs(ie,{label:"Status",children:[t.jsx(B,{k:"result",v:e.exitCode!==null?`exit ${e.exitCode}`:"—"}),t.jsx(B,{k:"state",v:e.status.replace(/_/g," ")}),e.verifierVerdict&&t.jsx(B,{k:"verdict",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:Ft(e.leakedDescendants),wrap:!0}),e.leftoverCount!=null&&e.leftoverCount>0&&t.jsx(B,{k:"uncommitted",v:`${e.leftoverCount} file${e.leftoverCount===1?"":"s"}${e.leftoverPathsTruncated?"+":""}: ${(e.leftoverPaths??[]).join(", ")}${e.salvagePatch?` — salvaged to ${e.salvagePatch}`:""}`,wrap:!0}),k&&t.jsx(B,{k:"error",v:k.split(`
|
|
5
|
-
`)[0],wrap:!0})]}),e.statusHistory&&e.statusHistory.length>0&&t.jsx(ie,{label:"History",children:t.jsx("div",{className:"grid gap-1",children:e.statusHistory.map((P,T)=>t.jsxs("div",{className:"font-mono text-xs leading-relaxed",children:[t.jsxs("div",{className:"text-fg",children:[P.from??"(new)"," → ",P.to,t.jsxs("span",{className:"text-fg-faint",children:[" · ",ue(Date.parse(P.at))]})]}),P.reason&&t.jsx("div",{className:"text-fg-faint break-words",children:P.reason})]},T))})}),t.jsxs(ie,{label:"Timing",children:[t.jsx(B,{k:"started",v:e.startedAt?ue(Date.parse(e.startedAt)):"—"}),t.jsx(B,{k:"finished",v:e.finishedAt?ue(Date.parse(e.finishedAt)):"—"}),t.jsx(B,{k:"duration",v:e.startedAt&&e.finishedAt?Se(Date.parse(e.finishedAt)-Date.parse(e.startedAt)):S&&n!==null?Ee(n):"—"})]}),t.jsxs(ie,{label:"Location",children:[t.jsx(B,{k:"group",v:`${e.parallelGroup} · ${e.slug}`}),t.jsx(B,{k:"cwd",v:e.cwd??"—",wrap:!0}),t.jsx(B,{k:"session",v:m.label??m.epicId??"—",wrap:!0}),t.jsx(B,{k:"session id",v:m.epicId??"—",wrap:!0}),t.jsx(B,{k:"prompt id",v:e.sourcePromptId??"—",wrap:!0}),t.jsx(B,{k:"source tab",v:e.sourceTabId??"—",wrap:!0})]}),t.jsx(ie,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-1.5 items-start",children:[w&&t.jsx("button",{type:"button","data-testid":"job-row-prompt-session-link",title:w.goalText,onClick:()=>N(w.id),className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"view epic →"}),e.runId&&t.jsx("button",{type:"button",onClick:()=>h(!0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"view log →"}),e.status==="quarantined"&&t.jsx("button",{type:"button","data-testid":"job-row-adopt-prd",title:"Stamp this PRD's provenance so the scheduler will run it — no unstamped PRD runs automatically.",onClick:()=>{window.api.schedule.adoptPrd(e.slug).then(H.fromOutcome).catch(()=>H.error("Failed to adopt PRD"))},className:"text-[13px] font-semibold text-accent hover:text-accent/80 bg-transparent border-0 cursor-pointer p-0",children:"adopt PRD →"}),e.status!=="pending"&&e.status!=="running"&&e.status!=="quarantined"&&t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(e.slug,e.cwd??void 0),className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer p-0",children:"reset to pending →"}),e.disposition&&(e.status==="pending"||e.status==="quarantined")&&t.jsx(Jt,{job:e,headChoices:o})]})})]}),u&&e.runId&&t.jsx(Fe,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>h(!1)})]})}const ta=f.memo(ea);function sa({supervisorConfig:e,onSetConfig:s,onBack:n}){const[a,d]=f.useState([]),[l,r]=f.useState(()=>Date.now()),i=tt();f.useEffect(()=>{if(!i)return;window.api.supervisor.getLog().then(d).catch(()=>{}),r(Date.now());const c=setInterval(()=>r(Date.now()),5e3);return()=>clearInterval(c)},[i]);const o={enabled:(e==null?void 0:e.enabled)??!0,intervalMinutes:(e==null?void 0:e.intervalMinutes)??15,maxConcurrentProbes:(e==null?void 0:e.maxConcurrentProbes)??2,probeStaleThresholdMinutes:(e==null?void 0:e.probeStaleThresholdMinutes)??10};return t.jsxs("div",{className:"bg-bg-elev/60",children:[t.jsxs("div",{className:"px-3 py-2 flex items-center gap-2 border-b border-line",children:[t.jsx("button",{type:"button",onClick:n,className:"text-[10px] text-fg-faint hover:text-fg-dim",title:"Back to queue",children:"← queue"}),t.jsx("span",{className:"text-[11px] font-medium text-fg-dim",children:"Supervisor"}),t.jsx("button",{type:"button",onClick:()=>window.api.supervisor.getLog().then(d).catch(()=>{}),className:"ml-auto text-[10px] text-fg-faint hover:text-fg-dim underline",title:"Refresh log",children:"refresh"})]}),t.jsxs("div",{className:"px-3 py-2 space-y-1.5 border-b border-line",children:[t.jsx("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider",children:"Config"}),t.jsxs("div",{className:"flex items-center gap-3 flex-wrap text-[10px] text-fg-faint",children:[t.jsxs("label",{className:"flex items-center gap-1",children:[t.jsx("input",{type:"checkbox",checked:o.enabled,onChange:c=>s({enabled:c.target.checked}),className:"cursor-pointer"}),t.jsx("span",{children:"enabled"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"How often to check for wedged jobs (minutes)",children:[t.jsx("span",{children:"interval"}),t.jsx("input",{type:"number",min:5,max:60,value:o.intervalMinutes,onChange:c=>s({intervalMinutes:Number(c.target.value)}),className:"w-10 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Max concurrent Opus probes per tick",children:[t.jsx("span",{children:"probes"}),t.jsx("input",{type:"number",min:1,max:5,value:o.maxConcurrentProbes,onChange:c=>s({maxConcurrentProbes:Number(c.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"})]}),t.jsxs("label",{className:"flex items-center gap-1",title:"Probe a job only if no JSONL event in this many minutes",children:[t.jsx("span",{children:"stale"}),t.jsx("input",{type:"number",min:5,max:30,value:o.probeStaleThresholdMinutes,onChange:c=>s({probeStaleThresholdMinutes:Number(c.target.value)}),className:"w-8 bg-bg border border-line rounded px-1 py-0.5 font-mono"}),t.jsx("span",{children:"min"})]})]})]}),t.jsxs("div",{className:"px-3 py-2",children:[t.jsxs("div",{className:"text-[9px] text-fg-faint uppercase tracking-wider mb-1",children:["Recent probes (last ",a.length,")"]}),a.length===0?t.jsx("div",{className:"text-[10px] text-fg-faint italic",children:"No probes yet."}):t.jsx("div",{className:"space-y-0.5 max-h-64 overflow-y-auto",children:a.map((c,p)=>t.jsx(na,{entry:c,now:l},`${c.ts}-${p}`))})]})]})}function na({entry:e,now:s}){const n=e.action!=="none",a=te(s-e.ts);return t.jsxs("div",{className:`text-[10px] px-1.5 py-1 rounded font-mono ${n?"bg-red-500/10 border border-red-500/20":"bg-bg/40"}`,title:e.reason,children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsxs("span",{className:"text-fg-faint shrink-0",children:[a," ago"]}),t.jsx("span",{className:`shrink-0 px-1 rounded ${e.verdict==="stuck"?"text-red-400 bg-red-500/10":"text-green-500/70"}`,children:e.verdict}),t.jsx("span",{className:"truncate text-fg-dim",children:e.jobSlug}),n&&t.jsxs("span",{className:"shrink-0 text-red-400",children:[e.action,e.targetPid?` pid=${e.targetPid}`:""]}),e.costUsd!==null&&t.jsxs("span",{className:"shrink-0 text-fg-faint",children:["$",e.costUsd.toFixed(3)]})]}),t.jsx("div",{className:"text-fg-faint truncate mt-0.5",children:e.reason})]})}const aa=[{title:"Start a session",body:"In Sessions, pick an Agent and a Mission, describe the outcome you want, then Approve & start. Its thread writes the PRD files into that session's own folder."},{title:"Queue what it wrote",body:"The PRDs tab lists every file the session produced. Queue one, or the whole session, and they appear here."},{title:"Leave it alone",body:"Jobs start themselves inside your window, pause on rate-limit, and resume at the reset. History records how each ended."}],ia=[{term:"Session",def:"One goal, one Claude session, and the folder of PRDs written to reach it."},{term:"PRD",def:"One markdown file = one job. Authored by the session."},{term:"5-hour window",def:"Your Claude billing window, on a rolling clock."},{term:"Session pool",def:"5 slots shared with terminal and session chats."}];function ra({navigate:e}){return t.jsx("div",{className:"overflow-y-auto h-full",children:t.jsx("div",{className:"px-9 py-6 max-w-[900px] mx-auto",children:t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl px-9 py-8",children:[t.jsx("h2",{className:"m-0 font-serif text-[25px] font-semibold text-fg",children:"Nothing to run yet — the scheduler needs a session."}),t.jsx("p",{className:"mt-2 mb-6 text-[14.5px] text-fg-dim leading-relaxed max-w-[580px]",children:"You don't write PRDs here. A session breaks its goal into numbered PRD files, and this page runs them in order. Two steps, once."}),t.jsx("div",{className:"grid grid-cols-3 gap-3.5",children:aa.map((s,n)=>{const a=n===0;return t.jsxs("div",{className:`bg-bg border rounded-xl px-4 py-4 flex flex-col gap-2 ${a?"border-accent shadow-[0_0_0_3px_rgba(184,92,52,.09)]":"border-line"}`,children:[t.jsx("span",{className:`w-6 h-6 rounded-full grid place-items-center font-mono text-[12px] font-semibold ${a?"bg-accent text-white":"bg-bg-elev text-fg-dim"}`,children:n+1}),t.jsx("h3",{className:"m-0 text-[15px] font-semibold text-fg",children:s.title}),t.jsx("p",{className:"m-0 text-[13.5px] text-fg-dim leading-relaxed",children:s.body}),a&&t.jsx("button",{type:"button",onClick:()=>e==null?void 0:e("terminal"),className:"self-start bg-accent text-white rounded-lg px-3.5 py-1.5 text-[13px] font-semibold mt-1",children:"Go to Sessions →"})]},s.title)})}),t.jsx("dl",{className:"flex mt-[22px] pt-4 border-t border-line gap-5 flex-wrap",children:ia.map(({term:s,def:n})=>t.jsxs("div",{className:"flex-1 min-w-[150px]",children:[t.jsx("dt",{className:"text-[13.5px] font-semibold text-fg mb-0.5",children:s}),t.jsx("dd",{className:"m-0 text-[12.5px] text-fg-faint leading-relaxed",children:n})]},s))})]})})})}const la=5e3;let Ae=null,Ne=null;async function Rt(e){const s=Date.now();return!(e!=null&&e.fresh)&&Ae&&s-Ae.at<la?Ae.result:Ne||(Ne=(async()=>{try{const n=await window.api.schedule.lintQueue();return Ae={result:n,at:Date.now()},n}finally{Ne=null}})(),Ne)}function oa({health:e,jobCount:s,lastRunAt:n,nextReset:a,now:d,onOpenSupervisor:l}){const[r,i]=f.useState(!1),[o,c]=f.useState(null),[p,u]=f.useState(!1),h=`${s}:${n??""}`;f.useEffect(()=>{let D=!0;return u(!0),Rt().then(P=>{D&&c(P)}).catch(()=>{}).finally(()=>{D&&u(!1)}),()=>{D=!1}},[h]);let x=0,m=0;const w=o?o.reports.filter(D=>D.findings.length>0):[];for(const D of w)for(const P of D.findings)P.severity==="error"?x++:m++;const N=x===0&&m===0,S=o?`graph lint ${x} error${x===1?"":"s"}, ${m} warn${m===1?"":"s"}`:`graph lint ${p?"scanning…":"idle"}`,y=(e==null?void 0:e.consecutiveFailures)??0,k=[e?`${y} poll failure${y===1?"":"s"} in current streak`:null,S].filter(Boolean).join(" · "),E="text-accent hover:underline bg-transparent border-0 p-0 cursor-pointer text-[12px]";return t.jsxs("div",{"data-testid":"scheduler-footer",className:"border-t border-rule-structural",children:[t.jsxs("div",{className:"h-[28px] flex items-center gap-2 px-[18px] font-mono text-[11.5px] text-fg-faint",children:[t.jsx("span",{"data-testid":"footer-summary",className:"truncate",children:k}),t.jsx("button",{type:"button","data-testid":"footer-info","aria-expanded":r,onClick:()=>i(D=>!D),className:"bg-transparent border-0 p-0 cursor-pointer",children:t.jsx(me,{title:"Scheduler poll health and queue-lint findings — click for the full detail"})}),t.jsxs("span",{className:"ml-auto flex items-center gap-3 shrink-0",children:[t.jsxs("span",{"data-testid":"footer-timing",children:[a?t.jsxs("span",{title:`next 5h reset: ${a}`,children:["reset ",te(Date.parse(a)-d)]}):null,a&&n?" · ":null,n?t.jsxs("span",{title:n,children:["last run ",te(d-Date.parse(n))," ago"]}):null]}),t.jsx("button",{type:"button","data-testid":"footer-supervisor",onClick:l,title:"Open supervisor log and settings",className:E,children:"supervisor"}),t.jsx("button",{type:"button","data-testid":"footer-folder",onClick:()=>window.api.schedule.openFolder(),className:E,children:"folder"})]})]}),r&&t.jsxs("div",{"data-testid":"footer-detail",className:"px-[18px] pb-2 space-y-2 font-mono text-[12px] text-fg-dim border-t border-rule-inner pt-2",children:[e&&t.jsxs("div",{className:"space-y-0.5",children:[t.jsxs("div",{children:["booted: ",xe(e.bootedAt,d)]}),t.jsxs("div",{children:["last poll: ",xe(e.lastPollAt,d)," · ",e.lastPollOk?"ok":"failed"]}),e.backoffNextAt!==null&&e.backoffNextAt>d&&t.jsxs("div",{children:["retry in: ",te(e.backoffNextAt-d)]}),e.nextResetCached&&t.jsxs("div",{children:["cached reset: ",ue(Date.parse(e.nextResetCached))]}),e.runningJobs.length>0&&t.jsxs("div",{children:["running: ",e.runningJobs.map(D=>`${D.slug}(pid ${D.pid})`).join(", ")]})]}),o&&t.jsxs("div",{className:"space-y-1",children:[N?t.jsxs("div",{className:"text-sage",children:["✓ no issues in ",o.reports.length," PRD",o.reports.length!==1?"s":""]}):w.map(D=>t.jsxs("div",{children:[t.jsx("div",{className:"text-fg-dim truncate",title:D.slug,children:D.slug}),D.findings.map((P,T)=>t.jsxs("div",{className:`pl-3 truncate ${P.severity==="error"?"text-accent/80":"text-butter/90"}`,title:P.snippet,children:[P.severity==="error"?"✗":"⚠"," L",P.line,": ",P.snippet]},`${D.slug}-${T}`))]},D.slug)),t.jsx("button",{type:"button","data-testid":"footer-rerun-lint",onClick:()=>{u(!0),Rt({fresh:!0}).then(c).catch(()=>{}).finally(()=>u(!1))},className:"text-fg-faint hover:text-fg-dim underline",children:p?"…":"rerun lint"})]})]})]})}const da=5,ca=1440*60*1e3,Me=10,ua=["all","running","investigating","pending","completed","skipped","needs_review","failed","quarantined"];async function pa(e){if(!e)return{text:"",status:"all"};const s=await qt(e);return{text:"",status:ua.includes(s.queueFilterStatus)?s.queueFilterStatus:"all"}}function fa(e,s){return e?Bt(e,{queueFilterStatus:s.status}):Promise.resolve()}function At(e,s){if(s.status==="all"&&!s.text)return e;const n=s.text.toLowerCase();return e.filter(a=>{if(s.status!=="all"&&a.status!==s.status)return!1;if(!n)return!0;const d=_e(a.cwd)??"";return a.title.toLowerCase().includes(n)||a.slug.toLowerCase().includes(n)||d.toLowerCase().includes(n)})}async function ha(e){if(!e)return new Set;const s=await qt(e);return Array.isArray(s.hiddenCompletedSlugs)?new Set(s.hiddenCompletedSlugs.filter(n=>typeof n=="string")):new Set}function ga(e,s){return e?Bt(e,{hiddenCompletedSlugs:[...s]}):Promise.resolve()}function xa({scopeCwd:e=null,navigate:s,filterText:n,planMode:a="graph",onOpenPrds:d,planToolsEl:l=null}){var xt;const r=Oe(b=>b.snapshot),i=f.useMemo(()=>!r||!e?r:{...r,jobs:r.jobs.filter(b=>b.cwd===e)},[r,e]),[o,c]=f.useState(null),[p,u]=f.useState(()=>Date.now()),[h,x]=f.useState(new Set),[m,w]=f.useState(!1),[N,S]=f.useState({text:"",status:"all"}),y=f.useMemo(()=>n===void 0?N:{...N,text:n},[N,n]),[L,k]=f.useState(!1),[E,D]=f.useState("queue"),P=f.useRef(null),[T,K]=f.useState(0),[V,z]=f.useState(""),J=tt(),X=f.useRef(!1),se=f.useRef(!1),Y=f.useRef(h);Y.current=h;const A=f.useRef(N);A.current=N,f.useEffect(()=>{let b=!1;return X.current=!1,se.current=!1,ha(e).then(I=>{!b&&!X.current&&x(I)}),pa(e).then(I=>{!b&&!se.current&&S(I)}),()=>{b=!0}},[e]),f.useEffect(()=>(window.api.schedule.health().then(c).catch(()=>{}),window.api.schedule.onState(()=>{window.api.schedule.health().then(c).catch(()=>{})})),[]),f.useEffect(()=>{if(!J)return;u(Date.now());const b=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(b)},[J]);const F=f.useMemo(()=>{if(!i)return 15e4;const b=[];for(const I of i.jobs)if(I.status==="completed"&&I.startedAt&&I.finishedAt){const G=Date.parse(I.finishedAt)-Date.parse(I.startedAt);G>0&&b.push(G)}return b.length===0?15e4:b.reduce((I,G)=>I+G,0)/b.length},[i]),j=f.useRef(new Map);f.useEffect(()=>{if(!i)return;const b=[];for(const I of i.jobs){const G=j.current.get(I.slug);G&&G!==I.status&&b.push(`${I.title}: ${G} → ${I.status}`),j.current.set(I.slug,I.status)}b.length>0&&z(b.join("; "))},[i]);const $=f.useMemo(()=>{var I;const b=new Map;for(const G of((I=i==null?void 0:i.lastTick)==null?void 0:I.holds)??[])b.set(G.slug,G);return b},[i==null?void 0:i.lastTick]),q=pe(b=>b.sessions),W=f.useMemo(()=>i?Gt(Te(i.jobs),q,r!=null&&r.jobs?Te(r.jobs):void 0):[],[i,q,r]),U=Cs(),g=f.useMemo(()=>i?At(bn(i.jobs,U,e),y):[],[i,U,e,y]),v=(xt=i==null?void 0:i.effectiveConcurrency)==null?void 0:xt.cap,R=f.useMemo(()=>a==="list"?[]:rt(g,{sessions:q,avgDurationMs:F,concurrency:v}),[a,g,q,F,v]),[C,M]=f.useState(1),O=R.map(b=>`${b.epicId??""}#${b.waveIndex}`).join(",");f.useEffect(()=>{M(1)},[e,y.status,y.text,O]);const _=Math.max(1,Math.ceil(R.length/Me)),Z=Math.min(C,_),Be=f.useMemo(()=>R.slice((Z-1)*Me,Z*Me),[R,Z]),as=f.useMemo(()=>{const b=new Map;let I=0;for(const G of R)for(const Q of G.stages)for(const ae of Q.rows)b.set(ae.slug,I++);return b},[R]),is=f.useMemo(()=>mn(W),[W]),rs=h,lt=f.useCallback(b=>{var be;const I=(be=P.current)==null?void 0:be.querySelectorAll("[data-job-row]");if(!I||I.length===0)return;const G=Array.from(I),Q=G.findIndex(ne=>ne.dataset.jobIndex===String(T)),ae=ne=>{const fe=G[ne];if(!fe)return;const he=Number(fe.dataset.jobIndex);K(he),fe.focus()};b.key==="ArrowDown"?(b.preventDefault(),ae(Q===-1?0:Math.min(Q+1,G.length-1))):b.key==="ArrowUp"&&(b.preventDefault(),ae(Q===-1?G.length-1:Math.max(Q-1,0)))},[T]),ot=f.useCallback(b=>{K(b)},[]),dt=f.useCallback(b=>{const I=A.current;se.current=!0,A.current=b,S(b),fa(e,b).catch(()=>{A.current===b&&(A.current=I,S(I),H.error("Couldn't save queue filter — reverted."))})},[e]),ct=f.useCallback(b=>{const I=Y.current;X.current=!0,Y.current=b,x(b),ga(e,b).catch(()=>{Y.current===b&&(Y.current=I,x(I),H.error("Couldn't save hidden completed jobs — reverted."))})},[e]);if(!i)return null;if(E==="supervisor")return t.jsx(sa,{supervisorConfig:i.config.supervisor,onSetConfig:b=>window.api.schedule.setConfig({supervisor:b}),onBack:()=>D("queue")});const{jobs:ee,paused:ut,lastRunAt:ls,nextReset:os,effectiveConcurrency:He}=i;if(ee.length===0)return t.jsx(ra,{navigate:s});const le={pending:0,running:0,investigating:0,completed:0,needs_review:0,failed:0};for(const b of ee)b.status in le&&le[b.status]++;const Ge=ee.filter(b=>b.status==="running"),ds=zt({snap:i,now:p,avgDurationMs:F,runningJobs:Ge}),je=At(ee,y),cs=ma(je),{inline:Pe,collapsedCount:We}=ba(je,h,p,m),us=wa(Pe,ee,cs,F,ds.kind,p),pt=()=>{const b=new Set(h);for(const I of ee)(I.status==="completed"||I.status==="failed")&&b.add(I.slug);ct(b)},ft=async()=>{const b=ee.filter(Q=>Q.status!=="running").length;if(b===0)return;const I=`Archive ${b} non-running PRD${b===1?"":"s"} and remove from the queue?
|
|
6
|
-
|
|
7
|
-
Files are moved to prds-archived/<timestamp>/ and can be restored from disk. Running jobs are kept.`;if(!window.confirm(I))return;const G=await window.api.schedule.clearQueue();G.ok||H.error(`Clear queue failed: ${G.error??"unknown error"}`)},ht=()=>{ct(new Set),w(!1)},gt=a==="list"?Pe.some(b=>b.status==="completed"):ee.some(b=>(b.status==="completed"||b.status==="skipped")&&!h.has(b.slug)),ps=ee.filter(b=>(b.status==="completed"||b.status==="failed")&&h.has(b.slug)).length,oe=a==="list",De=oe?"":"px-[18px] py-2";return t.jsxs("div",{className:"overflow-y-auto h-full",children:[t.jsx("div",{"aria-live":"polite","aria-atomic":"true",className:"sr-only",children:V}),t.jsxs("div",{className:oe?"px-9 py-6 max-w-[1100px] mx-auto space-y-4":"",children:[o&&o.consecutiveFailures>5&&o.lastFailureKind==="meter_rate_limited"&&!ut&&!L&&t.jsx("div",{className:De,children:t.jsxs("div",{className:oe?"flex items-center gap-3 px-4 py-3 bg-amber-400/15 border border-amber-400/30 rounded-xl":"flex items-center gap-3 -mx-[18px] px-[18px] py-1 bg-amber-400/15 border-y border-amber-400/30",children:[t.jsx("span",{"aria-hidden":"true",children:"⚠"}),t.jsxs("span",{className:"text-[13.5px] text-amber-400/90",children:[t.jsx("strong",{className:"font-semibold",children:"Usage meter unavailable"})," — last good reading"," ",xe(o.lastPollAt,p),". Firing on a conservative estimate until it recovers."]}),t.jsx("button",{type:"button",onClick:()=>k(!0),className:"ml-auto text-[12px] text-amber-400/70 hover:text-amber-400 shrink-0",title:"Dismiss this banner. The scheduler continues firing normally.",children:"Dismiss"})]})}),oe&&Ge.length>0&&(()=>{const b=(He==null?void 0:He.cap)??5,I=ee.filter(G=>G.status==="pending").length;return t.jsxs("div",{className:`flex items-center gap-2 text-[12px] font-mono ${De}`,children:[t.jsxs("span",{className:"px-2 py-0.5 rounded bg-amber-400/20 text-amber-400 shrink-0",children:[Ge.length,"/",b," running"]}),I>0&&t.jsxs("span",{className:"text-fg-faint",children:["+",I," ready in this group"]})]})})(),oe&&ee.length>0&&t.jsx("div",{className:De,children:t.jsx(ja,{showText:n===void 0,filter:y,onChange:dt})}),!oe&&t.jsxs("div",{"data-testid":"plan-graph",children:[l&&Ps.createPortal(t.jsx(va,{jobCount:je.length,counts:le,filter:y,onFilter:dt,hiddenInGraph:ps,onUnhideAll:ht,hasInlineCompleted:gt,onClearCompleted:pt,onClearQueue:ft,clearQueueDisabled:ee.every(b=>b.status==="running")}),l),R.length===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:P,role:"list","aria-label":"Job queue",onKeyDown:lt,children:Be.map(b=>t.jsx(zn,{plan:b,mode:a,now:p,hidden:rs,indexBySlug:as,headChoicesBySlug:is,onRowFocused:ot,onOpenPrds:d},`${b.epicId??"__none__"}#${b.waveIndex}`))}),t.jsx(Ds,{page:Z,pageSize:Me,totalItems:R.length,onPageChange:M})]}),oe&&t.jsxs("div",{className:"bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-[18px] py-3 bg-bg-elev",children:[t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[je.length," job",je.length!==1?"s":""]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("span",{className:"font-mono text-[12px] text-fg-faint",children:[le.pending,"p · ",le.running,"r · ",le.completed,"d",le.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",le.failed,"f"]})]}),gt&&t.jsx("button",{type:"button",onClick:pt,className:"text-[12.5px] text-fg-dim hover:text-fg bg-transparent border-0 cursor-pointer font-medium",title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:ft,disabled:ee.every(b=>b.status==="running"),className:"text-[12px] text-accent border border-accent/40 hover:bg-accent/10 rounded-md px-2.5 py-1 cursor-pointer font-medium disabled:opacity-40 disabled:cursor-not-allowed",title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})]}),Pe.length===0&&We===0&&t.jsx("div",{className:"px-[18px] py-6 text-[13px] text-fg-faint italic",children:"no matching jobs"}),t.jsx("div",{ref:P,role:"list","aria-label":"Job queue",onKeyDown:lt,children:(()=>{const b=new Set(Pe.map(Q=>Q.slug));let I=0;return W.map(Q=>{const ae=Kt(Q),be=Q.nodes.map(ne=>{const fe=qe([ne]).filter(he=>b.has(he.row.slug)).map(he=>({node:he,listIndex:I++}));return{headRootSlug:ne.row.slug,rows:fe}}).filter(ne=>ne.rows.length>0);return{section:Q,heads:be,headChoices:ae}}).filter(Q=>Q.heads.length>0).map(({section:Q,heads:ae,headChoices:be})=>t.jsx(Qn,{section:Q,children:ae.map(({headRootSlug:ne,rows:fe},he)=>t.jsxs("div",{"data-testid":"backlog-head-group",children:[ae.length>1&&t.jsxs("div",{className:"px-[18px] pt-2.5 pb-1 text-[11px] font-mono uppercase tracking-wide text-fg-faint bg-bg-elev/30 border-t border-line/60","data-testid":"backlog-head-label",children:["Plan ",he+1," of ",ae.length]}),fe.map(({node:de,listIndex:fs})=>t.jsx(ta,{job:de.row,backlog:de,eta:us.get(de.row.slug)??null,elapsedMs:de.row.status==="running"&&de.row.startedAt?p-Date.parse(de.row.startedAt):null,avgDurationMs:F,listIndex:fs,hold:$.get(de.row.slug),onFocused:ot,headChoices:be.filter(hs=>hs.rootSlug!==ne)},de.row.slug))]},ne))},Q.epicId??"__none__"))})()}),We>0&&t.jsxs("button",{type:"button",onClick:()=>w(b=>!b),className:"w-full text-left text-[12px] text-fg-faint hover:text-fg-dim px-[18px] py-3 border-t border-line",title:m?"Re-collapse old/cleared completed":"Show all completed (incl. cleared and >24h)",children:[m?"▾":"▸"," ",We," more completed",t.jsx("span",{className:"ml-1.5 font-mono text-[11.5px] text-fg-faint",children:"· fresh & capped at 5 shown inline"}),h.size>0&&t.jsx("span",{className:"ml-2 underline",onClick:b=>{b.stopPropagation(),ht()},children:"un-hide"})]})]}),oe&&!ut&&t.jsx("div",{className:De,children:t.jsxs("div",{className:"flex gap-2.5 bg-sage/10 border border-sage/30 rounded-xl px-3.5 py-2.5 text-[13.5px] text-fg-dim leading-relaxed",children:[t.jsx("span",{"aria-hidden":"true",children:"✓"}),t.jsxs("span",{children:[t.jsx("strong",{className:"font-semibold text-fg",children:"Nothing needed from you."})," ","Close the app if you like — jobs keep running, and History shows how each one ended."]})]})})]}),t.jsx(oa,{health:o,jobCount:ee.length,lastRunAt:ls,nextReset:os,now:p,onOpenSupervisor:()=>D("supervisor")})]})}function ma(e){const s=new Map(e.map(l=>[l.slug,l])),n=l=>(l.dependsOn??[]).filter(r=>{var i;return((i=s.get(r))==null?void 0:i.status)!=="completed"}).length,a=e.filter(l=>l.status==="running"||l.status==="pending").sort((l,r)=>n(l)-n(r)||l.slug.localeCompare(r.slug)),d=new Map;return a.forEach((l,r)=>d.set(l.slug,r)),d}function ba(e,s,n,a){if(a)return{inline:e,collapsedCount:0};const d=e.filter(c=>c.status==="completed").sort((c,p)=>{const u=c.finishedAt?Date.parse(c.finishedAt):0;return(p.finishedAt?Date.parse(p.finishedAt):0)-u}),l=new Set;let r=0;for(const c of d){if(r>=da)break;s.has(c.slug)||c.finishedAt&&n-Date.parse(c.finishedAt)>ca||(l.add(c.slug),r++)}const i=[];let o=0;for(const c of e){if(c.status==="failed"&&s.has(c.slug)){o++;continue}if(c.status!=="completed"){i.push(c);continue}l.has(c.slug)?i.push(c):o++}return{inline:i,collapsedCount:o}}function wa(e,s,n,a,d,l){const r=new Map;if(d==="paused"||d==="manual"||d==="auto-throttled"){for(const c of e)r.set(c.slug,null);return r}const i=s.find(c=>c.status==="running"&&c.startedAt),o=i!=null&&i.startedAt?l-Date.parse(i.startedAt):0;for(const c of e){if(c.status!=="pending"){r.set(c.slug,null);continue}const p=n.get(c.slug)??0;let u=p*a;p>0&&(u-=Math.min(a,o)),r.set(c.slug,u<=5e3?"~now":`~${Se(u)}`)}return r}const ns=[{label:"All",value:"all"},{label:"Running",value:"running"},{label:"Investigating",value:"investigating"},{label:"Pending",value:"pending"},{label:"Completed",value:"completed"},{label:"Skipped",value:"skipped"},{label:"Needs review",value:"needs_review"},{label:"Failed",value:"failed"},{label:"Quarantined",value:"quarantined"}];function va({jobCount:e,counts:s,filter:n,onFilter:a,hiddenInGraph:d,onUnhideAll:l,hasInlineCompleted:r,onClearCompleted:i,onClearQueue:o,clearQueueDisabled:c}){const p="block w-full text-left px-2 py-1 text-[12px] hover:bg-bg-hi disabled:opacity-40 disabled:cursor-not-allowed bg-transparent border-0 cursor-pointer";return t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"font-mono text-[11.5px] text-fg-faint whitespace-nowrap","data-testid":"plan-tools-counts",children:[e," job",e!==1?"s":""," · ",s.pending,"p · ",s.running,"r · ",s.completed,"d",s.failed>0&&t.jsxs("span",{className:"text-accent",children:[" · ",s.failed,"f"]})]}),d>0&&t.jsxs("button",{type:"button",onClick:l,className:"text-[12px] text-fg-faint hover:text-fg-dim underline bg-transparent border-0 cursor-pointer whitespace-nowrap",title:"Show the completed/failed jobs hidden by Clear completed",children:[d," hidden · un-hide"]}),t.jsx("select",{"data-testid":"scheduler-status-filter","aria-label":"Filter by status",value:n.status,onChange:u=>a({...n,status:u.target.value}),className:"bg-bg-hi border border-line rounded px-1 py-0.5 text-[12px] text-fg-dim",title:"Filter the plan graph by job status",children:ns.map(u=>t.jsx("option",{value:u.value,children:u.value==="all"?"all statuses":u.label.toLowerCase()},u.value))}),t.jsx(me,{title:"Queue actions",testId:"plan-tools-menu",popoverTestId:"plan-tools-menu-popover",alignRight:!0,glyph:"⋯",widthCls:"w-52",children:t.jsxs("div",{className:"-mx-3 -my-2",children:[r&&t.jsx("button",{type:"button",onClick:i,className:`${p} text-fg-dim`,title:"Hide completed jobs from this view (queue.json unchanged — they remain in history)",children:"Clear completed"}),t.jsx("button",{type:"button",onClick:o,disabled:c,className:`${p} text-accent`,title:"Archive every non-running PRD (moved to prds-archived/<timestamp>/) and remove them from the queue. Running jobs are kept.",children:"Archive & clear queue…"})]})})]})}function ja({filter:e,onChange:s,showText:n}){const a=ns;return t.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[n&&t.jsxs("div",{className:"relative flex-1 min-w-[200px] max-w-[320px]",children:[t.jsx("span",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-faint inline-flex","aria-hidden":"true",children:t.jsx(st,{name:"search",size:15})}),t.jsx("input",{type:"text",value:e.text,onChange:d=>s({...e,text:d.target.value}),placeholder:"filter jobs…",className:"w-full bg-bg-hi border border-line rounded-xl py-2 pl-9 pr-3 text-[13.5px] text-fg placeholder:text-fg-faint focus:outline-none focus:border-fg-faint","aria-label":"Filter jobs by title, slug, or project"})]}),t.jsx(Qt,{options:a,value:e.status,onChange:d=>s({...e,status:d})})]})}const Na=new Set(["discussion","portfolio"]);new Set(Rs.map(e=>e.tag).filter(e=>!Na.has(e)));const ya=["title","cwd","estimateMinutes","parallelGroup","sourcePromptId","sourceTabId","tag","agentType","dependsOn","disposition","planId"];function ka(e,s){return!Array.isArray(e)||!Array.isArray(s)?!1:e.length===s.length&&e.every((n,a)=>n===s[a])}function Sa(e){if(e==null)return"";if(typeof e=="boolean"||typeof e=="number")return String(e);const s=String(e);return s===""||/^(true|false|null|~)$/.test(s)||/^-?\d+(\.\d+)?$/.test(s)||/^\s|\s$/.test(s)||s.startsWith("'")||s.startsWith('"')||s.includes(`
|
|
8
|
-
`)?s.includes("'")?`"${s.replace(/"/g,'\\"')}"`:`'${s}'`:s}function $a(e,s){var d;const n=[];for(const l of ya){const r=e[l];if(r==null||r===""||Array.isArray(r)&&r.length===0)continue;const i=(d=e._raw)==null?void 0:d[l];if(i&&(Array.isArray(r)?ka(i.parsed,r):i.parsed===r)){n.push(i.line);continue}if(typeof r=="number"){n.push(`${l}: ${r}`);continue}if(Array.isArray(r)){n.push(`${l}: [${r.join(", ")}]`);continue}n.push(`${l}: ${Sa(r)}`)}if(e.extras)for(const l of Object.keys(e.extras)){const r=e.extras[l];!r||!r.lines.length||n.push(r.lines.join(`
|
|
9
|
-
`))}return`---
|
|
10
|
-
${n.join(`
|
|
11
|
-
`)}
|
|
12
|
-
---
|
|
13
|
-
${s}`}function Qe(e){return e.filter(s=>!s.archived)}function Ca(e){nt(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Ye({label:e,tip:s,onClick:n,disabled:a,primary:d}){return t.jsx(Is,{content:s,align:"bottom-center",children:t.jsx("button",{title:s,onClick:n,disabled:a,className:`px-2 py-0.5 text-xs rounded border disabled:opacity-40 disabled:cursor-not-allowed ${d?"text-accent border-accent/50 hover:bg-bg-hi":"text-fg-dim border-line hover:text-fg hover:bg-bg-hi"}`,children:e})})}function Pa({scopeCwd:e=null}){const[s,n]=f.useState([]),[a,d]=f.useState(null),[l,r]=f.useState(null),[i,o]=f.useState(null),[c,p]=f.useState(!1),[u,h]=f.useState(!0),[x,m]=f.useState(new Set),[w,N]=f.useState(!1),[S,y]=f.useState(!1),[L,k]=f.useState(!1),[E,D]=f.useState(null);f.useEffect(()=>{let g=!0;return window.api.schedule.listPrds().then(v=>{g&&(n(Qe(v)),h(!1))}).catch(v=>{g&&(h(!1),H.error(`Scheduler: failed to load PRD list — ${v instanceof Error?v.message:"unknown error"}`))}),()=>{g=!1}},[]);const P=Oe(g=>g.snapshot),T=pe(g=>g.sessions);f.useEffect(()=>{P&&d(P)},[P]);const K=f.useMemo(()=>[...s].filter(g=>!e||g.cwd===e).sort((g,v)=>v.mtimeMs-g.mtimeMs||g.slug.localeCompare(v.slug)),[s,e]);f.useEffect(()=>{const g=Ms();g&&r(g);const v=R=>r(R.detail);return window.addEventListener("sm:select-prd",v),()=>window.removeEventListener("sm:select-prd",v)},[]);const V=f.useMemo(()=>(a==null?void 0:a.jobs.find(g=>g.slug===l))??null,[a,l]),z=wt(V);function J(g){var R;const v=(R=s.find(C=>C.slug===g))==null?void 0:R.cwd;return v?`${v}/session-manager-operations/scheduler/prds/${g}.md`:null}f.useEffect(()=>{if(!l)return;const g=J(l);g&&vt.getState().openFile(g)},[l,s]);function X(g){r(g),o(null),p(!1)}function se(){r(null)}async function Y(){if(!l)return;if(!(V!=null&&V.runId)){o("no log available (job has not run yet)"),p(v=>!v);return}const g=await window.api.schedule.readLog(V.runId,l);o(g.ok?g.text??"":`error: ${g.error}`),p(v=>!v)}if(u)return t.jsx(ye,{title:"loading PRDs…"});const A=g=>{m(v=>{const R=new Set(v);return R.has(g)?R.delete(g):R.add(g),R})};!(K.length>0&&K.every(g=>x.has(g.slug)))&&K.some(g=>x.has(g.slug));const j=()=>m(new Set);async function $(){try{const g=await window.api.schedule.listPrds();n(Qe(g))}catch{}}async function q(){const g=`new-prd-${Date.now()}`,v=$a({title:"New PRD",cwd:"",estimateMinutes:60,parallelGroup:99},`## Task
|
|
14
|
-
|
|
15
|
-
Describe the task here.
|
|
16
|
-
`);try{const R=await window.api.schedule.writePrd(g,v);if(!R.ok){H.error(`Failed to create PRD: ${R.error}`);return}const C=await window.api.schedule.listPrds();n(Qe(C)),X(g)}catch(R){H.error(`Failed to create PRD: ${R instanceof Error?R.message:String(R)}`)}}async function W(){var g;k(!0),D(null);try{const v=[...x],R=await window.api.schedule.archivePrds(v);if(!R.ok)D(R.error??"archive failed");else{const C=((g=R.results)==null?void 0:g.filter(M=>!M.ok))??[];C.length>0&&H.warn(`Archive: ${C.length} of ${R.results.length} PRD${C.length===1?"":"s"} failed to move`),j(),N(!1),await $()}}catch(v){D(v instanceof Error?v.message:String(v))}finally{k(!1)}}async function U(g,v){k(!0),D(null);try{const R=[];for(const M of x){const O={slug:M};g!==null&&(O.parallelGroup=g),v!==null&&(O.estimateMinutes=v),R.push(O)}const C=await window.api.schedule.retagPrds(R);if(!C.ok)D(C.error??"retag failed");else{j(),y(!1),await $();for(const M of C.results)if(M.newSlug&&M.newSlug!==M.slug){const O=J(M.slug),_=J(M.newSlug);O&&_&&vt.getState().renameOpenFile(O,_)}l&&C.results.some(M=>M.slug===l&&M.newSlug&&M.newSlug!==M.slug)&&r(null)}}catch(R){D(R instanceof Error?R.message:String(R))}finally{k(!1)}}return t.jsxs(t.Fragment,{children:[l?t.jsxs("div",{className:"h-full flex flex-col min-h-0",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border-b border-line flex-wrap shrink-0",children:[t.jsx("button",{type:"button",onClick:se,className:"text-[11px] text-fg-faint hover:text-fg",children:"← PRDs"}),t.jsx("span",{className:"font-mono text-xs text-fg-dim truncate",children:l}),t.jsx(jt,{status:z}),t.jsx("div",{className:"flex-1"}),t.jsx(Ye,{label:"Reset",tip:"Reset failed job to pending",onClick:()=>{var g;window.api.schedule.resetJob(l,((g=s.find(v=>v.slug===l))==null?void 0:g.cwd)||void 0)},disabled:z!=="failed"}),t.jsx(Ye,{label:"Run now",tip:"Run all pending jobs immediately",onClick:()=>{Nt()}}),t.jsx(Ye,{label:c?"Hide log":"Last run log",tip:"Toggle most recent run log",onClick:Y})]}),t.jsx("div",{className:"flex-1 min-h-0",children:t.jsx(As,{})}),c&&i!==null&&t.jsxs("div",{className:"border-t border-line max-h-64 overflow-auto bg-bg-elev",children:[t.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2 border-b border-line sticky top-0 bg-bg-elev",children:[t.jsxs("span",{className:"text-[10px] text-fg-faint font-mono",children:["run log",V!=null&&V.runId?` — ${V.runId}`:""]}),t.jsx("button",{onClick:()=>p(!1),className:"ml-auto text-[10px] text-fg-faint hover:text-fg",children:"close"})]}),t.jsx("pre",{className:"p-3 text-[11px] font-mono text-fg-dim whitespace-pre-wrap",children:i})]})]}):t.jsxs("div",{className:"px-6 py-5 overflow-auto",children:[t.jsxs("div",{className:"flex items-start justify-between mb-5 gap-4",children:[t.jsxs("p",{className:"text-[14px] text-fg-dim leading-relaxed max-w-[560px]",children:["PRDs are the source the scheduler runs from. Each one becomes a"," ",t.jsx("code",{className:"font-mono text-[13px]",children:"claude -p"})," job when you queue it. This is where you write and edit the source — to watch a run in progress, use the Queue tab."]}),t.jsx("button",{type:"button",onClick:q,className:"shrink-0 bg-accent text-white rounded-lg px-4 py-[9px] text-[13.5px] font-semibold leading-none",children:"+ New PRD"})]}),x.size>0&&t.jsxs("div",{className:"mb-4 px-4 py-2 bg-bg border border-line rounded-lg flex items-center gap-2",children:[t.jsxs("span",{className:"text-xs text-fg-dim",children:[x.size," selected"]}),t.jsx("div",{className:"flex-1"}),t.jsx("button",{type:"button",onClick:()=>N(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Archive…"}),t.jsx("button",{type:"button",onClick:()=>y(!0),className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Retag…"}),t.jsx("button",{type:"button",onClick:j,className:"text-xs px-3 py-1.5 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Clear"})]}),K.length===0?t.jsx(ye,{title:"no PRDs found"}):t.jsx("div",{className:"grid gap-3",children:K.map(g=>{const v=a==null?void 0:a.jobs.find(_=>_.slug===g.slug),R=wt(v),C=Ce({epicId:g.epicId??(v==null?void 0:v.epicId)??null,sourcePromptId:g.sourcePromptId??(v==null?void 0:v.sourcePromptId)??null,sourceTabId:(v==null?void 0:v.sourceTabId)??null},T),M=(v==null?void 0:v.status)==="running",O=(v==null?void 0:v.status)==="needs_review";return t.jsxs("div",{className:"flex items-stretch bg-bg-elev border border-line rounded-2xl overflow-hidden",children:[t.jsx("label",{className:"flex items-center px-3 cursor-pointer hover:bg-bg-hi",children:t.jsx("input",{type:"checkbox",checked:x.has(g.slug),onChange:()=>A(g.slug),className:"accent-accent w-3.5 h-3.5"})}),t.jsxs("div",{className:"flex-1 min-w-0 py-4 pr-2",children:[t.jsxs("div",{className:"flex items-center gap-2.5 mb-[5px] flex-wrap",children:[re(g.slug)&&t.jsx(Lt,{n:re(g.slug)}),t.jsx("button",{type:"button",onClick:()=>X(g.slug),className:"font-serif text-[18px] font-semibold text-fg leading-tight hover:underline text-left",children:g.title||g.slug}),t.jsx(jt,{status:R}),(v==null?void 0:v.status)&&t.jsx("span",{className:"sr-only",children:v.status})]}),t.jsxs("div",{className:"flex items-center gap-4 font-mono text-xs text-fg-faint flex-wrap",children:[t.jsx(it,{cwd:g.cwd}),t.jsx(at,{epicId:C.epicId,label:C.label,onOpen:Ca}),g.estimateMinutes!=null&&t.jsxs("span",{children:[g.estimateMinutes,"m"]}),t.jsxs("span",{className:"opacity-60",title:"parallelGroup — a unique-per-PRD display hint, never an ordering barrier. dependsOn is the real ordering primitive.",children:["g",g.parallelGroup]}),g.dependsOn&&g.dependsOn.length>0&&t.jsxs("span",{title:`depends on: ${g.dependsOn.join(", ")}`,children:["⛓ ",g.dependsOn.length," dep",g.dependsOn.length===1?"":"s"]}),t.jsxs("span",{children:["edited ",xe(g.mtimeMs,Date.now())]})]}),t.jsx("button",{type:"button",onClick:()=>X(g.slug),className:"mt-1.5 font-mono text-[11px] text-fg-faint hover:text-fg-dim leading-none",children:g.slug}),O&&t.jsxs("div",{className:"mt-3 space-y-2",children:[(v==null?void 0:v.verifierVerdict)&&t.jsxs("div",{className:"text-xs text-fg-faint",children:["verdict: ",t.jsx("span",{className:"font-mono",children:$e(v.verifierVerdict)})]}),t.jsx("button",{type:"button",onClick:()=>window.api.schedule.resetJob(g.slug,g.cwd||void 0),className:"text-xs px-2.5 py-1 rounded border border-line text-fg-dim hover:text-fg hover:bg-bg-hi",children:"Re-fire"})]})]}),t.jsx("div",{className:"flex flex-col gap-2 items-stretch px-[18px] py-4",children:t.jsx("button",{type:"button",onClick:()=>{Nt()},disabled:M,className:"bg-fg text-bg rounded-lg px-[18px] py-2 text-[13px] font-semibold whitespace-nowrap disabled:opacity-50",children:M?"Running…":"Queue job"})})]},g.slug)})})]}),t.jsx(Da,{open:w,count:x.size,busy:L,onClose:()=>N(!1),onConfirm:W}),t.jsx(Ra,{open:S,count:x.size,busy:L,onClose:()=>y(!1),onConfirm:U})]})}function Da({open:e,count:s,busy:n,onClose:a,onConfirm:d}){return t.jsxs(Ht,{open:e,onClose:a,title:"Archive PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Move ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s"," to"," ",t.jsx("span",{className:"font-mono",children:"prds-archived/<timestamp>/"}),"?"]}),t.jsx("p",{className:"text-[10px] text-fg-faint mt-2",children:"Files are renamed, never deleted. Restore manually from disk if needed."}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:d,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Archiving…":`Archive ${s}`})]})]})}function Ra({open:e,count:s,busy:n,onClose:a,onConfirm:d}){const[l,r]=f.useState(""),[i,o]=f.useState(""),[c,p]=f.useState(null);f.useEffect(()=>{e&&(r(""),o(""),p(null))},[e]);function u(){p(null);let h=null,x=null;if(l.trim()){const m=Number(l);if(!Number.isInteger(m)||m<0||m>999){p("parallelGroup must be 0–999");return}h=m}if(i.trim()){const m=Number(i);if(!Number.isInteger(m)||m<=0){p("estimateMinutes must be a positive integer");return}x=m}if(h===null&&x===null){p("set at least one field");return}d(h,x)}return t.jsxs(Ht,{open:e,onClose:a,title:"Retag PRDs",children:[t.jsxs("p",{className:"text-xs text-fg-dim",children:["Update ",t.jsx("span",{className:"font-mono",children:s})," PRD",s===1?"":"s",". Leave a field blank to keep its current value."]}),t.jsxs("p",{className:"text-[10px] text-fg-faint mt-2",children:["Changing parallelGroup on an ",t.jsx("span",{className:"font-mono",children:"NN-kebab"})," slug renames the file. Every change is logged to ",t.jsx("span",{className:"font-mono",children:"retag-log.jsonl"})," so it's reversible."]}),t.jsxs("div",{className:"mt-3 space-y-2",children:[t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"parallelGroup:"}),t.jsx("input",{type:"number",min:0,max:999,value:l,onChange:h=>r(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]}),t.jsxs("label",{className:"flex items-center gap-2 text-xs",children:[t.jsx("span",{className:"w-32 text-fg-faint",children:"estimateMinutes:"}),t.jsx("input",{type:"number",min:1,value:i,onChange:h=>o(h.target.value),placeholder:"(unchanged)",className:"flex-1 bg-bg border border-line rounded px-2 py-1 font-mono text-xs"})]})]}),c&&t.jsx("div",{className:"mt-2 text-[10px] text-red-300",children:c}),t.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[t.jsx("button",{type:"button",onClick:a,disabled:n,className:"px-2 py-1 text-xs border border-line rounded text-fg-dim hover:text-fg disabled:opacity-40",children:"Cancel"}),t.jsx("button",{type:"button",onClick:u,disabled:n||s===0,className:"px-2 py-1 text-xs border border-accent/60 text-accent rounded hover:bg-bg-hi disabled:opacity-40",children:n?"Retagging…":`Retag ${s}`})]})]})}function Aa(e){nt(e),window.dispatchEvent(new CustomEvent("sm:navigate",{detail:"terminal"}))}function Mt(e){return e?e.slice(0,10):""}const Ma=[{value:"all",label:"All"},{value:"completed",label:"Completed"},{value:"skipped",label:"Skipped"},{value:"failed",label:"Failed"}];function Ia({scopeCwd:e=null}){const[s,n]=f.useState(null),[a,d]=f.useState(!0),[l,r]=f.useState(""),[i,o]=f.useState(""),[c,p]=f.useState(""),[u,h]=f.useState("all");f.useEffect(()=>{d(!0),window.api.schedule.getHistory().then(N=>n(N)).catch(N=>n({ok:!1,jobs:[],error:N instanceof Error?N.message:String(N)})).finally(()=>d(!1))},[]);const x=f.useMemo(()=>{if(!(s!=null&&s.jobs))return[];const N=new Set;for(const S of s.jobs){const y=_e(S.cwd);y&&N.add(y)}return[...N].sort()},[s]),m=f.useMemo(()=>s!=null&&s.jobs?s.jobs.filter(N=>!(e&&N.cwd!==e||u!=="all"&&N.status!==u||l&&_e(N.cwd)!==l||i&&Mt(N.finishedAt)<i||c&&Mt(N.finishedAt)>c)):[],[s,u,l,i,c,e]);if(a)return t.jsx(ye,{title:"Loading history…"});if(!(s!=null&&s.ok)||s.error)return t.jsxs("div",{className:"p-4 text-xs text-red-300",children:["Failed to load history: ",(s==null?void 0:s.error)??"unknown error"]});if(s.jobs.length===0)return t.jsx(ye,{title:"No history yet",hint:"Completed and failed jobs appear here."});const w=u!=="all"||!!l||!!i||!!c;return t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 py-2.5 border-b border-line flex-wrap",children:[t.jsx(Qt,{options:Ma,value:u,onChange:h,pillPadding:"px-3 py-1"}),t.jsx("span",{className:"w-px h-4 bg-line mx-1","aria-hidden":"true"}),x.length>0&&t.jsxs("select",{value:l,onChange:N=>r(N.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-[12.5px] text-fg-dim max-w-[12rem] font-medium",children:[t.jsx("option",{value:"",children:"All projects"}),x.map(N=>t.jsx("option",{value:N,children:N},N))]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"from"}),t.jsx("input",{type:"date",value:i,onChange:N=>o(N.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 text-[12px] text-fg-faint",children:[t.jsx("span",{children:"to"}),t.jsx("input",{type:"date",value:c,onChange:N=>p(N.target.value),className:"bg-bg-hi border border-line rounded-lg px-2 py-1 text-fg-dim font-mono text-[12px]"})]}),t.jsxs("span",{className:"text-[12px] text-fg-faint ml-auto font-mono",children:[m.length," / ",s.jobs.length]}),w&&t.jsx("button",{type:"button",onClick:()=>{h("all"),r(""),o(""),p("")},className:"text-[12px] text-fg-faint hover:text-fg-dim underline",children:"clear"})]}),t.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto",children:m.length===0?t.jsx(ye,{title:"No matches",hint:"Try adjusting the filters."}):t.jsxs("div",{className:"mx-4 my-3 bg-bg-hi border border-line rounded-2xl overflow-hidden",children:[t.jsx("div",{className:"flex items-center px-[18px] py-3 bg-bg-elev",children:t.jsxs("span",{className:"font-serif text-base font-semibold text-fg",children:[m.length," job",m.length!==1?"s":""]})}),m.map(N=>t.jsx(Ea,{job:N},`${N.slug}-${N.finishedAt??""}`))]})})]})}function Ea({job:e}){const[s,n]=f.useState(!1),[a,d]=f.useState(!1),l=pe(h=>h.sessions),r=f.useMemo(()=>Ce(e,l),[e,l]),i=e.startedAt&&e.finishedAt?Date.parse(e.finishedAt)-Date.parse(e.startedAt):null,o=e.startedAt?new Date(e.startedAt).toLocaleString():"—",c=e.finishedAt?new Date(e.finishedAt).toLocaleString():"—",p=i!==null?Se(i):"—",u=e.exitCode!==null?String(e.exitCode):"—";return t.jsxs("div",{className:"border-t border-line/60",children:[t.jsxs("button",{type:"button",className:`w-full text-left grid items-center gap-4 px-[18px] py-3.5 cursor-pointer transition-colors hover:bg-bg-elev ${s?"bg-bg-elev":"bg-transparent"}`,style:{gridTemplateColumns:"116px 1fr auto auto"},onClick:()=>n(h=>!h),"aria-expanded":s,children:[t.jsx(Tt,{status:e.status}),t.jsxs("div",{className:"min-w-0",children:[t.jsxs("div",{className:"flex items-baseline gap-2 text-[14.5px] font-medium text-fg leading-snug text-pretty",children:[e.title,t.jsx(Ot,{leaked:e.leakedDescendants})]}),e.error&&!s&&(e.status==="failed"||e.status==="needs_review")&&t.jsx("div",{className:"text-[12.5px] mt-0.5 text-accent/80 truncate",children:e.error}),r.epicId&&t.jsx("span",{className:"flex mt-0.5",children:t.jsx(at,{epicId:r.epicId,label:r.label,onOpen:Aa})})]}),t.jsx(it,{cwd:e.cwd}),t.jsxs("span",{className:"inline-flex items-center gap-2.5 font-mono text-xs text-fg-faint whitespace-nowrap",children:[p,t.jsx("span",{className:"inline-flex transition-transform duration-150",style:{transform:s?"rotate(90deg)":"none"},"aria-hidden":"true",children:"›"})]})]}),s&&t.jsxs("div",{className:"grid gap-5 px-[18px] pt-1 pb-5 bg-bg-elev",style:{gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))"},children:[t.jsxs(ie,{label:"Status",children:[t.jsx(B,{k:"result",v:u}),t.jsx(B,{k:"state",v:e.status.replace("_"," ")}),e.verifierVerdict&&t.jsx(B,{k:"verifier",v:$e(e.verifierVerdict)}),e.leakedDescendants&&e.leakedDescendants.length>0&&t.jsx(B,{k:"leaked",v:Ft(e.leakedDescendants),wrap:!0})]}),t.jsxs(ie,{label:"Timing",children:[t.jsx(B,{k:"started",v:o}),t.jsx(B,{k:"finished",v:c}),t.jsx(B,{k:"duration",v:p})]}),t.jsxs(ie,{label:"Location",children:[t.jsx(B,{k:"group",v:e.parallelGroup!=null?String(e.parallelGroup):"—"}),t.jsx(B,{k:"slug",v:e.slug}),t.jsx(B,{k:"epic",v:r.label??r.epicId??"—",wrap:!0}),e.cwd&&t.jsx(B,{k:"cwd",v:e.cwd,wrap:!0})]}),t.jsx(ie,{label:"Actions",children:t.jsxs("div",{className:"flex flex-col gap-2 items-start",children:[e.runId&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),d(!0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"view log →"}),e.status!=="pending"&&t.jsx("button",{type:"button",onClick:h=>{h.stopPropagation(),window.api.schedule.resetJob(e.slug,e.cwd??void 0)},className:"text-[13px] font-semibold text-fg-dim hover:text-fg bg-transparent border-0 p-0 cursor-pointer",children:"reset to pending →"}),e.error&&t.jsx("p",{className:"text-[12px] text-accent/90 mt-1 break-words whitespace-pre-wrap max-w-sm m-0",children:e.error})]})})]}),a&&e.runId&&t.jsx(Fe,{runId:e.runId,slug:e.slug,title:e.title||e.slug,onClose:()=>d(!1)})]})}function _a(){const e=Et(),[s,n]=f.useState(null);return f.useEffect(()=>{var d,l;let a=!0;return(l=(d=window.api.schedule).worktreeBase)==null||l.call(d).then(r=>{a&&n(r)}).catch(()=>{}),()=>{a=!1}},[]),t.jsxs("div",{className:"max-w-[760px] space-y-6",children:[t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"Session pool"}),t.jsxs("p",{className:"mt-0 mb-3 text-[13px] text-fg-dim leading-relaxed",children:["One machine-wide pool of concurrent Claude sessions. Scheduler jobs and Epic chat runs each request a slot before launching; work waits when the pool is full. Adjustable from 0 (pauses new launches) to ",(e==null?void 0:e.max)??10," on the Home tab, default 5 — or pin it with"," ",t.jsx("code",{className:"font-mono text-[12px]",children:"SM_SESSION_SLOTS"})," (clamped 0–",(e==null?void 0:e.max)??10,")."]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Es,{total:(e==null?void 0:e.total)??5,inUse:(e==null?void 0:e.inUse)??0,size:"md"}),t.jsx("span",{className:"ml-2 font-mono text-[12.5px] text-fg-faint",children:e?`${e.inUse} / ${e.total} in use`:"loading…"})]}),e&&e.holders.length>0&&t.jsx("ul",{className:"mt-2 mb-0 pl-0 list-none space-y-0.5",children:e.holders.map((a,d)=>t.jsxs("li",{className:"font-mono text-[12px] text-fg-dim",children:[a.owner," ",t.jsxs("span",{className:"text-fg-faint",children:["since ",new Date(a.at).toLocaleTimeString()]})]},d))})]}),t.jsxs("section",{className:"border border-line rounded-xl bg-bg-hi px-5 py-4",children:[t.jsx("h2",{className:"m-0 mb-1 font-serif text-[18px] font-semibold text-fg",children:"On disk"}),t.jsxs("p",{className:"mt-0 mb-2 text-[13px] text-fg-dim leading-relaxed",children:["Global runtime state is deliberately small — everything project-scoped lives inside that project's ",t.jsx("code",{className:"font-mono text-[12px]",children:"session-manager-operations/"})," folder."]}),t.jsxs("ul",{className:"m-0 pl-0 list-none space-y-1 font-mono text-[12px] text-fg-dim",children:[t.jsxs("li",{children:["~/.claude/session-manager/scheduler-machine.json ",t.jsx("span",{className:"text-fg-faint",children:"— policy + pause state"})]}),t.jsxs("li",{"data-testid":"worktree-base-path",children:[s??"…","/session-manager-epic-worktrees/ ",t.jsx("span",{className:"text-fg-faint",children:"— Epic git worktrees (SM_WORKTREE_ROOT overrides)"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/state/ ",t.jsx("span",{className:"text-fg-faint",children:"— per-project queue + history"})]}),t.jsxs("li",{children:["<project>/session-manager-operations/scheduler/epics/<epic>/prds/ ",t.jsx("span",{className:"text-fg-faint",children:"— PRD sources, per session"})]})]})]})]})}const It="sm.schedulerTab.subView";function Ta({navigate:e}={}){var m;const[s,n]=f.useState("graph"),[a,d]=f.useState(""),[l,r]=f.useState(null),[i,o]=f.useState(()=>{const w=localStorage.getItem(It);return w==="prds"||w==="history"||w==="machine"?w:"queue"}),c=yt(w=>w.tabs),p=yt(w=>w.activeTabId),u=((m=c.find(w=>w.id===p))==null?void 0:m.cwd)??null,h=u;f.useEffect(()=>{u&&(pe.getState().hydrate(u),pe.getState().hydrateArchived(u))},[u]);const x=f.useCallback(w=>{w&&_s(w),o("prds")},[]);return f.useEffect(()=>{localStorage.setItem(It,i)},[i]),t.jsxs("div",{className:"h-full flex flex-col",children:[t.jsx(gn,{scopeCwd:h,subView:i,onSubView:o,filterText:a,onFilterText:d,planMode:s,onPlanMode:n,planToolsRef:r}),t.jsxs("div",{className:"flex-1 min-h-0",children:[i==="queue"&&t.jsx(xa,{scopeCwd:h,navigate:e,filterText:a,planMode:s,onOpenPrds:x,planToolsEl:l}),i==="prds"&&t.jsx(Pa,{scopeCwd:h}),i==="history"&&t.jsx(Ia,{scopeCwd:h}),i==="machine"&&t.jsx("div",{className:"h-full overflow-y-auto px-9 py-6",children:t.jsx(_a,{})})]})]})}const qa=f.memo(Ta);export{qa as Scheduler};
|