taskchef 8.2.1 → 8.3.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskchef",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "Dispatch work from a data-only workspace to visible Codex project tasks.",
5
5
  "author": {
6
6
  "name": "Favo Yang",
package/README.md CHANGED
@@ -179,13 +179,14 @@ Use $taskchef-executor to execute and report this delegated TaskChef assignment.
179
179
 
180
180
  ### Model roles
181
181
 
182
- TaskChef can apply personal Planner, Implementer, and Reviewer model preferences
183
- from `~/.codex/agents/`. Planning-only tasks use Planner, while coding tasks and
184
- single tasks that plan and then execute use Implementer throughout. To apply
185
- both models, finish a Planner task that saves its plan, then create a separate
186
- Implementer task using that plan. Reviewer preferences apply when a workflow
187
- explicitly starts a review subagent. Explicit per-task model choices take
188
- precedence, and changes affect only tasks created afterward.
182
+ TaskChef can apply personal Orchestrator, Planner, Implementer, and Reviewer
183
+ model preferences from `~/.codex/agents/`. Every delegated task uses the
184
+ Orchestrator preference for its visible parent. For repository work, a combined
185
+ investigate-or-plan-and-implement request runs fresh Planner, Implementer, and
186
+ Reviewer subagents in that order. A direct implementation, or a later request
187
+ to implement prior investigation, skips the Planner and runs a fresh Implementer
188
+ and Reviewer in the same visible task. Explicit model choices take precedence
189
+ for the role they target.
189
190
 
190
191
  ## Work with and report executors
191
192
 
package/docs/spec.md CHANGED
@@ -259,7 +259,8 @@ the final link, preserving the delegate skill's immediate-return contract.
259
259
  NOT place a blank line between the invocation and marker or inline the
260
260
  executor protocol into a new instruction.
261
261
  4. It MUST call `record_task` with `threadId: null` before native creation.
262
- 5. It MUST create exactly one native Codex executor and return immediately.
262
+ 5. It MUST create exactly one native Codex executor using the resolved
263
+ Orchestrator preference when configured, then return immediately.
263
264
  6. The executor MUST read its own `CODEX_THREAD_ID` and call `link_task`
264
265
  before substantive work. It MUST NOT use parent/session identity or guess.
265
266
  7. After initial linking, the executor MUST establish a `turnRef`. It MUST use
@@ -274,6 +275,17 @@ the final link, preserving the delegate skill's immediate-return contract.
274
275
  TaskChef MUST atomically close it as `interrupted` before appending the new
275
276
  working turn; the executor MUST NOT report semantic `failed` for recovery.
276
277
 
278
+ For repository work, the visible executor MUST route an explicit combined
279
+ investigate-or-plan-and-implement request through a fresh Planner, then a fresh
280
+ Implementer, then a fresh Reviewer. A direct implementation request, or a later
281
+ request to implement prior investigation or planning, MUST skip the Planner and
282
+ use a fresh Implementer followed by a fresh Reviewer in the same visible task.
283
+ It MUST resolve the applicable role preference immediately before creating a
284
+ child when agent TOML exists; absent agent configuration inherits the parent's
285
+ model settings without requiring Python. It MUST keep at most one writing agent
286
+ active and verify child results. TaskChef persists only the visible executor's
287
+ lifecycle and MUST NOT store or infer child phases, identities, or usage.
288
+
277
289
  Normal executor completion MUST stop after the terminal callback and return
278
290
  normally. It MUST NOT archive, hand off, close, navigate away from, or otherwise
279
291
  terminate the Codex task merely because work completed. Archive is authorized
package/docs/workflows.md CHANGED
@@ -149,6 +149,16 @@ Record-before-create makes native creation failure observable. Executor
149
149
  self-linking removes dispatcher-side polling, task search, title matching, and
150
150
  parent/child identity inference.
151
151
 
152
+ The created executor is the stable visible owner. For repository work, an
153
+ explicit combined investigate-or-plan-and-implement request runs a fresh
154
+ Planner, Implementer, and Reviewer in that order. Direct implementation and a
155
+ later request to implement prior investigation skip the Planner and run a fresh
156
+ Implementer and Reviewer in the same visible task. Each role is resolved
157
+ immediately before use when agent TOML exists; absent configuration inherits the
158
+ parent's settings without requiring Python. Only one writer may be active.
159
+ TaskChef records only the executor's ordinary request/result timeline; it does
160
+ not track child phases or identities.
161
+
152
162
  The generated task begins with the complete assignment, adds the local reporting
153
163
  authorization paragraph separated by a blank line, leaves one blank line,
154
164
  then places one explicit `$taskchef-executor` invocation immediately before its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskchef",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "A non-blocking interactive dispatcher for visible Codex tasks.",
5
5
  "license": "MIT",
6
6
  "author": "Favo Yang",
@@ -12,7 +12,7 @@ import re
12
12
  import sys
13
13
  import tomllib
14
14
 
15
- ROLES = ('planner', 'implementer', 'reviewer')
15
+ ROLES = ('orchestrator', 'planner', 'implementer', 'reviewer')
16
16
  EFFORTS = ('none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra')
17
17
 
18
18
 
@@ -120,7 +120,7 @@ def resolve(codex_home=None, explicit_model=None, explicit_effort=None):
120
120
  'availability': availability, 'problems': errors,
121
121
  'taskOverrides': overrides,
122
122
  'subagentOverrides': {('reasoning_effort' if k == 'thinking' else k): v for k, v in overrides.items()},
123
- 'fallback': 'inherit parent settings' if role == 'reviewer' else 'native new-task default (not guaranteed dispatcher inheritance)'})
123
+ 'fallback': 'native new-task default' if role == 'orchestrator' else 'inherit parent settings'})
124
124
  model_options = [] if catalog is None else [
125
125
  {'value': slug, 'label': entry.get('display_name') or slug,
126
126
  'efforts': [level['effort'] for level in entry['supported_reasoning_levels']]}
@@ -5,8 +5,8 @@ description: "Dispatch work received in the canonical TaskChef workspace into Co
5
5
 
6
6
  # TaskChef Delegate
7
7
 
8
- Create real Codex tasks through the canonical per-user TaskChef data workspace
9
- and return immediately.
8
+ Create stable visible TaskChef parent tasks through the canonical per-user
9
+ TaskChef data workspace and return immediately.
10
10
 
11
11
  ## Invocation boundary
12
12
 
@@ -33,7 +33,8 @@ stop and report that the TaskChef plugin must be reloaded or installed.
33
33
  - Treat only AGENTS.md, taskchef.json, tasks.jsonl, config-audit.jsonl, and
34
34
  TaskChef's private backups and maintenance artifacts as managed dispatcher
35
35
  state. Preserve unrelated user-owned paths.
36
- - Use real Codex tasks, never collaboration or subagent tools.
36
+ - Use real Codex tasks for visible delegated work. The dispatcher never uses
37
+ collaboration or subagent tools; the created executor may use them internally.
37
38
  - Never use hooks, schedules, daemons, background monitors, recent-task
38
39
  searches, transcripts, hidden reasoning, or polling for identity.
39
40
  - Never wait for delegated work after native creation.
@@ -50,13 +51,11 @@ stop and report that the TaskChef plugin must be reloaded or installed.
50
51
  3. Route against configured project `name`, `description`, and canonical
51
52
  `githubRepos`; use `path` only as checkout identity. Require exactly one
52
53
  match and an exact native-project path. Ask instead of guessing.
53
- Select `planner` for a requested planning assignment and `implementer` for
54
- coding work. Use the personal `modelRoles` from preparation;
55
- resolve explicit user choices and follow [model roles](references/model-roles.md).
56
- Small coding changes need no separate planning task. For a planning/coding
57
- split, the saved plan is the handoff to a separately requested implementation
58
- assignment; do not switch models during a turn or coordinate phases automatically.
59
- Resolve configuration problems before recording the task.
54
+ Select the `orchestrator` preference from preparation for every visible
55
+ parent. Resolve explicit choices and follow
56
+ [model roles](references/model-roles.md). Missing configuration means omit
57
+ model overrides; surface invalid or unavailable configuration before
58
+ recording the task.
60
59
  4. Build each executor instruction in this exact shape:
61
60
 
62
61
  - Begin with the actual assignment on the first line and keep its complete
@@ -76,7 +75,8 @@ stop and report that the TaskChef plugin must be reloaded or installed.
76
75
  5. Before creating each executor, call `record_task` exactly once with `id`,
77
76
  `project`, `title`, the exact marked `instruction`, and `threadId: null`.
78
77
  6. Create one real Codex task using the exact configured project, an appropriate
79
- native environment, the marked instruction, and a short title.
78
+ native environment, the marked instruction, a short title, and the resolved
79
+ orchestrator model and effort overrides when present.
80
80
  7. Return immediately. Preserve a returned provisional client ID only for the
81
81
  created-thread directive. Do not call `link_task` from the dispatcher even
82
82
  when creation returns a durable ID; the child must self-link.
@@ -1,52 +1,29 @@
1
- # Dispatch model roles
1
+ # Model roles
2
2
 
3
- Preparation includes personal model previews. Role preferences use native Codex
4
- agent TOML under `$CODEX_HOME/agents/` (default `~/.codex/agents/`); they are
5
- optional. The resolver requires Python 3.11+.
3
+ TaskChef reads optional personal role preferences from native Codex agent TOML
4
+ in `$CODEX_HOME/agents/` (default `~/.codex/agents/`). Only model and reasoning
5
+ effort are adapted; TaskChef does not load the files' instructions, tools, or
6
+ permissions.
6
7
 
7
- Select `planner` for a planning assignment or `implementer` for coding. Pass
8
- its `taskOverrides` as native `model` and `thinking` arguments only after checking
9
- those values against the current create-task tool's supported model/effort
10
- choices. A missing role means omit both arguments and use the native new-task
11
- default. This is not guaranteed to inherit the dispatcher's model.
8
+ For a new visible task, select `orchestrator` from the `modelRoles` returned by
9
+ `prepare_dispatch`. Pass its `taskOverrides` as the native task's `model` and
10
+ `thinking` only after checking that the current creation interface supports
11
+ them. Missing configuration means omit both overrides. Invalid or unavailable
12
+ configuration must be reported rather than silently ignored.
12
13
 
13
- Explicit user model choices take precedence over the personal role and native
14
- defaults. An explicit model without explicit effort omits effort and uses the native
15
- interface's omission behavior; do not mix in a different role's effort or claim
16
- a specific effective effort without evidence. Explicit effort
17
- alone replaces the resolved role effort. To resolve explicit choices, or recheck a preview after configuration
18
- changes, run:
14
+ Explicit user choices take precedence. An explicit model without an explicit
15
+ effort omits effort; do not combine it with a configured effort from another
16
+ model. To resolve an explicit choice, run the packaged resolver before creating
17
+ the task:
19
18
 
20
19
  ```sh
21
- python3 <plugin-root>/scripts/roles/resolve_roles.py --role implementer --model <user-model> --effort <user-effort>
20
+ python3 <plugin-root>/scripts/roles/resolve_roles.py --role orchestrator --model <model> [--effort <effort>]
22
21
  ```
23
22
 
24
- Omit flags the user did not specify. Resolve the plugin root from this skill's
25
- real path, two parents above the skill directory. Do not substitute dispatcher
26
- paths for the target project or infer model names from skill prose.
23
+ Resolve `<plugin-root>` from this skill's installed path. Omit flags the user
24
+ did not specify. The local model catalog is advisory; the current native tool
25
+ is authoritative about supported model and effort values.
27
26
 
28
- Report malformed profiles, duplicate names, unavailable models/efforts, and
29
- resolver failures. Do not quietly fall back and claim preferences were honored.
30
- The local model catalog is advisory: explain if a current native tool disproves
31
- its stale warning. Otherwise resolve the problem or obtain a valid explicit
32
- choice before task creation. Native creation failures retain normal TaskChef
33
- failure reporting. A preparation without role fields supports historical
34
- installations: check role files before deciding that no preferences exist.
35
-
36
- Only model and effort are adapted. The native agent file's instructions, tools,
37
- permissions, and other settings are not applied by create-task arguments. A
38
- role name in a title is not a native role selector. If the native interface adds
39
- a role selector, use it only with verified effective settings.
40
-
41
- For a plan-to-implementation handoff, a planner assignment can save
42
- `plans/addition.md` describing a pure addition function and the acceptance
43
- example `2 + 3 = 5`. A later implementer assignment reads that exact plan,
44
- implements the function, runs the example, and uses fresh reviewer subagents.
45
- The dispatcher returns after each creation; it does not wait for or launch
46
- subsequent phases automatically. A small addition change can instead go
47
- straight to the implementer.
48
-
49
- A single assignment that asks to plan and then execute is an implementation
50
- assignment. Use the implementer model for that whole task; do not switch models
51
- mid-turn. To apply both configured roles, dispatch a planner task first, wait
52
- for its saved plan, then dispatch a separate implementer task using that plan.
27
+ The visible executor resolves Planner, Implementer, and Reviewer preferences
28
+ itself when it starts those subagents. The dispatcher does not create or wait
29
+ for those children.
@@ -60,6 +60,40 @@ UUID is the lifecycle identity. Retry a possibly lost working callback with the
60
60
  same `turnRef`; never generate a replacement for the same prompt or bypass a
61
61
  link-pending state.
62
62
 
63
+ ## Coordinate the assignment
64
+
65
+ Keep this visible task as the stable owner of the assignment and its follow-ups.
66
+ For repository work, use these tight routes:
67
+
68
+ - An explicit investigate-or-plan-and-implement request starts a fresh Planner,
69
+ then a fresh Implementer, then a fresh Reviewer.
70
+ - A direct implementation request starts a fresh Implementer, then a fresh
71
+ Reviewer; skip the Planner.
72
+ - A later request to implement prior investigation or planning stays in this
73
+ visible task and starts a fresh Implementer, then a fresh Reviewer.
74
+
75
+ Make the Reviewer read-only and cover the complete change. Use the installed
76
+ `$branch-review-subagent-loop` when available or required by repository policy.
77
+ TaskChef tracks only this parent task's lifecycle; do not report child phases or
78
+ identities to TaskChef.
79
+
80
+ Immediately before starting a child, check the Codex agents directory. If it
81
+ contains no TOML files, inherit the parent's model settings without invoking
82
+ Python. Otherwise resolve that role with the packaged resolver and use its
83
+ `subagentOverrides` when valid:
84
+
85
+ ```sh
86
+ python3 <plugin-root>/scripts/roles/resolve_roles.py --role <planner|implementer|reviewer>
87
+ ```
88
+
89
+ Resolve `<plugin-root>` from this skill's installed path. Missing configuration
90
+ means inherit the parent's model settings. Surface invalid or unavailable
91
+ configuration instead of silently ignoring it. Give each child only the goal,
92
+ scope, repository or worktree, relevant instructions, and validation expected;
93
+ ask it to return changed files, tests, and blockers. Keep at most one writing
94
+ agent active, verify its result, and use a fresh writer before another review
95
+ when review finds a valid issue.
96
+
63
97
  ## Finish every execution turn
64
98
 
65
99
  Before ending, call `report_state` with the same `turnRef` and `turnId` values
@@ -190,5 +190,5 @@ ${f?`${d("light")}{${f}}`:""}`}function qs({theme:n,color:l,colorScheme:r,name:o
190
190
  *
191
191
  * This source code is licensed under the MIT license.
192
192
  * See the LICENSE file in the root directory of this source tree.
193
- */const k_=[["path",{d:"M7 3.34a10 10 0 1 1 -4.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 4.995 -8.336z",key:"svg-0"}]],B_=Mt("filled","circle-filled","CircleFilled",k_);function H_({onConnection:n,onError:l,onSnapshot:r}){const o=new EventSource("/api/events");return o.addEventListener("open",()=>n(!0)),o.addEventListener("error",()=>n(!1)),o.addEventListener("snapshot",s=>{n(!0),r(JSON.parse(s.data))}),o.addEventListener("dashboard-error",s=>{const c=JSON.parse(s.data);l(c.message??"The task log is temporarily unavailable.")}),o}async function Ai(n,l){const r=await fetch(n,l),o=await r.json().catch(()=>({}));if(!r.ok)throw Object.assign(new Error(o.message??"Request failed."),{payload:o});return o}async function U_(){return(await Ai("/api/health")).taskchefVersion}async function Y_(n,l,r){return Ai(`/api/settings/${encodeURIComponent(n)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schemaVersion:1,model:l,effort:r})})}async function q_(n){return(await Ai(`/api/tasks/${encodeURIComponent(n)}`)).task}async function V_(n){return(await Ai(`/api/tasks/${encodeURIComponent(n)}/open-codex`,{method:"POST"})).message??null}async function G_(n,l,r){const o=new AbortController,s=window.setTimeout(()=>o.abort(),1e4);try{return{ok:!0,task:(await Ai(`/api/tasks/${encodeURIComponent(n.id)}/manual-transition`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schemaVersion:1,actionId:r,expected:{status:n.status,turnRef:n.turnRef,threadId:n.threadId,updatedAt:n.updatedAt},targetStatus:l}),signal:o.signal})).task}}catch(c){const f=c.payload;return{ok:!1,code:(f==null?void 0:f.code)??(o.signal.aborted?"request_timeout":"network_error"),message:(f==null?void 0:f.message)??(o.signal.aborted?"Task state change timed out. Try again.":"Task state changes are temporarily unavailable. Try again."),task:(f==null?void 0:f.task)??null}}finally{window.clearTimeout(s)}}function X_(){const[n,l]=x.useState([]),[r,o]=x.useState(null),[s,c]=x.useState(null),[f,d]=x.useState(!0),[p,h]=x.useState(null),[b,y]=x.useState(null),[v,w]=x.useState(0);x.useEffect(()=>{const C=new AbortController;return d(!0),c(null),fetch("/api/settings",{signal:C.signal}).then(async A=>{if(!A.ok)throw new Error("Settings preview could not be loaded.");const N=await A.json();l(N.profiles),o(N.usageProvider??null)}).catch(A=>{C.signal.aborted||c(A.message)}).finally(()=>{C.signal.aborted||d(!1)}),()=>C.abort()},[v]),x.useEffect(()=>{if(y(null),!p)return;const C=window.setTimeout(()=>y(p),400);return()=>window.clearTimeout(C)},[p]);const R=n.find(C=>C.id==="personal"),T=async(C,A,N)=>{h(C.role),c(null),l(_=>_.map(j=>j.id!=="personal"?j:{...j,roles:j.roles.map($=>$.role===C.role?{...$,model:A,effort:N}:$)}));try{const _=await Y_(C.role,A,N);l([_.profile])}catch(_){l(j=>j.map($=>$.id!=="personal"?$:{...$,roles:$.roles.map(L=>L.role===C.role?C:L)})),c(_ instanceof Error?_.message:"Model role could not be saved.")}finally{h(null)}};return g.jsxs(Ut,{gap:"md","aria-label":"Model settings",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:2,size:"h3",children:"Model roles"}),g.jsx(ul,{"aria-label":"Refresh","aria-busy":f,"aria-disabled":f||p!==null,className:"taskchef-icon-button",color:"gray",variant:"subtle",size:"lg",onClick:()=>{f||p||(d(!0),w(C=>C+1))},children:g.jsx(M_,{className:f?"taskchef-refresh-spinning":void 0,size:18,stroke:1.8})})]}),g.jsx(_e,{c:"dimmed",size:"sm",children:"Your models for planning, implementation, and review."}),s&&g.jsx(Mn,{color:"red",role:"alert",children:s}),R&&g.jsxs(g.Fragment,{children:[R.problems.map(C=>g.jsx(Mn,{color:"yellow",children:C},C)),R.roles.map(C=>{var A,N;return g.jsx(gn,{withBorder:!0,p:"md",children:g.jsxs(Ut,{gap:"xs",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:3,size:"h4",tt:"capitalize",children:C.role}),g.jsx(Jo,{color:["invalid","unavailable"].includes(C.status)?"red":C.status==="missing"?"gray":"teal",children:C.status})]}),g.jsxs($p,{cols:{base:1,sm:2},children:[g.jsx(Wo,{label:"Model","aria-label":`${C.role} model`,"aria-busy":f||p!==null,data:R.modelOptions??[],value:typeof C.model=="string"?C.model:null,readOnly:f||p!==null,allowDeselect:!1,searchable:!0,onChange:_=>{var L;if(f||p||!_)return;const j=(L=R.modelOptions)==null?void 0:L.find(D=>D.value===_),$=typeof C.effort=="string"&&(j!=null&&j.efforts.includes(C.effort))?C.effort:j==null?void 0:j.efforts[0];$&&T(C,_,$)}}),g.jsx(Wo,{label:"Reasoning effort","aria-label":`${C.role} reasoning effort`,"aria-busy":f||p!==null,data:(((N=(A=R.modelOptions)==null?void 0:A.find(_=>_.value===C.model))==null?void 0:N.efforts)??[]).map(_=>({value:_,label:_})),value:typeof C.effort=="string"?C.effort:null,disabled:typeof C.model!="string",readOnly:f||p!==null,allowDeselect:!1,onChange:_=>{!f&&!p&&_&&typeof C.model=="string"&&T(C,C.model,_)}})]}),g.jsxs(_e,{size:"sm",style:{overflowWrap:"anywhere"},children:["Source: ",C.displaySource??C.source??"No role file"]}),b===C.role&&g.jsx(_e,{c:"dimmed",size:"sm",role:"status",children:"Saving…"}),C.problems.map(_=>g.jsx(Mn,{color:"red",children:_},_))]})},C.role)})]}),r&&g.jsx(gn,{withBorder:!0,p:"md",children:g.jsxs(Ut,{gap:"xs",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:3,size:"h4",children:"Usage provider"}),g.jsx(Jo,{color:r.status==="available"?"teal":"red",children:r.status})]}),g.jsxs(_e,{children:[r.provider,r.version?` ${r.version}`:" version unavailable"]}),g.jsx(_e,{c:"dimmed",size:"sm",children:"Version reported by the executable TaskChef uses for token and cost estimates."})]})})]})}const I_=50,Z_="Turn interrupted before a terminal report.",ZS=[{value:"",label:"All"},{value:"working",label:"Working"},{value:"needs input",label:"Needs input"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}],Q_=new Map([["created","Task created"],["task_started","Task started"],["follow_up_started","Follow-up started"],["completed","Task completed"],["needs_input","Task needs input"],["failed","Task failed"],["manual_completed","Task manually completed"],["manual_failed","Task manually failed"],["archive_succeeded","Chat archived"],["archive_failed","Chat archive failed"],["unresolved","Task updated"]]),K_=new Map([["24h",1440*60*1e3],["7d",10080*60*1e3],["all",null]]);function F_(n){return Date.parse(n.meaningfulUpdatedAt??n.updatedAt??n.createdAt)}function QS(n){return n.status===null?"unresolved":n.status.replaceAll("_"," ")}function J_(n){return{status:n.status,turnRef:n.turnRef,threadId:n.threadId,updatedAt:n.updatedAt}}function P_(n,l){return!!l&&n.status===l.status&&n.turnRef===l.turnRef&&n.threadId===l.threadId&&n.updatedAt===l.updatedAt}function Db({requestTask:n,expected:l,responseTask:r,selectedTask:o}){const s=(o==null?void 0:o.id)===n.id?o:n;return P_(s,l)?r??s:s}function W_(n){var s;const l=n.latestTurn??null,r=(l==null?void 0:l.result)??null,o=(l==null?void 0:l.requestSummary)??(l?"Request not recorded by this TaskChef version.":n.title);return{turnRef:(l==null?void 0:l.turnRef)??(l==null?void 0:l.turnId)??n.turnRef??n.turnId??null,turnId:(l==null?void 0:l.turnId)??n.turnId??null,startedAt:(l==null?void 0:l.startedAt)??n.updatedAt??n.createdAt??null,requestSummary:o,resultStatus:(r==null?void 0:r.status)??(n.status==="working"?"working":n.status),resultSummary:(r==null?void 0:r.summary)??(n.status==="working"?"In progress":((s=n.lastResult)==null?void 0:s.summary)??n.summary??"No result reported."),resultUpdatedAt:(r==null?void 0:r.updatedAt)??null}}function eN(n){var r;const l=n.result??null;return{status:(l==null?void 0:l.status)??"working",summary:(l==null?void 0:l.summary)??"In progress",updatedAt:(l==null?void 0:l.updatedAt)??n.startedAt,...((r=n.provenance)==null?void 0:r.kind)==="dashboard_manual"?{sourceLabel:"Manual dashboard change"}:{}}}function tN(n,l=[]){if(Array.isArray(n.turns))return n.turns;if(!n.latestTurn)return l;const r=[...l],o=r.length-1,s=n.latestTurn.turnRef??n.latestTurn.turnId,c=o>=0?r[o].turnRef??r[o].turnId:null,f=o>=0&&c===null&&s!==null&&r[o].turnId==null&&n.latestTurn.turnId==null&&JSON.stringify({...r[o],turnRef:null})===JSON.stringify({...n.latestTurn,turnRef:null});return o>=0&&(c===s||f)?r[o]=n.latestTurn:(n.schemaVersion>=8&&o>=0&&r[o].result===null&&(r[o]={...r[o],result:{status:"interrupted",summary:Z_,updatedAt:n.latestTurn.startedAt}}),r.push(n.latestTurn)),r}function nu(n){return Q_.get(n.event)??"Task updated"}function nN(n,l,r=Date.now()){const o=K_.get(l);if(o===null)return!0;if(o===void 0)return!1;const s=F_(n);return Number.isFinite(s)&&s>=r-o}function KS(n,{project:l="",status:r="",date:o="all",now:s=Date.now()}={}){return n.filter(c=>(!l||c.project.name===l)&&(!r||QS(c)===r)&&nN(c,o,s))}function lN(n,{project:l="",date:r="all",now:o=Date.now()}={}){const s=KS(n,{project:l,date:r,now:o});return Object.fromEntries(ZS.map(({value:c})=>[c,c?s.filter(f=>QS(f)===c).length:s.length]))}function aN(n){return JSON.stringify([n.id,n.turnRef??n.turnId??null,n.turnId??null,n.status??"unresolved"])}function oN(n,l){try{const r=JSON.parse(n),o=JSON.parse(l);return Array.isArray(r)&&Array.isArray(o)&&r.length===o.length&&r[1]===null&&o[1]!==null&&r[2]===null&&o[2]===null&&r[3]!=="working"&&r.every((s,c)=>c===1||s===o[c])}catch{return!1}}function rN(n){var l,r;return n.status==="working"?n.lastResult?"follow_up_started":"task_started":((r=(l=n.latestTurn)==null?void 0:l.provenance)==null?void 0:r.kind)==="dashboard_manual"?`manual_${n.status}`:n.status??"unresolved"}function FS(n,l){return JSON.stringify(l==="created"?[n.id,null,l,n.createdAt??null]:[n.id,n.turnRef??n.turnId??null,l])}function iN(n,l){var r,o,s;return l==="created"?n.createdAt??n.updatedAt??null:((r=n.lastResult)==null?void 0:r.status)===n.status&&(((o=n.lastResult)==null?void 0:o.turnRef)??((s=n.lastResult)==null?void 0:s.turnId))===(n.turnRef??n.turnId)?n.lastResult.updatedAt:n.updatedAt??n.createdAt??null}function sN(n,l){var r,o,s;return["completed","needs_input","failed","manual_completed","manual_failed"].includes(l)?((r=n.lastResult)==null?void 0:r.status)===n.status&&(((o=n.lastResult)==null?void 0:o.turnRef)??((s=n.lastResult)==null?void 0:s.turnId))===(n.turnRef??n.turnId)?n.lastResult.summary:n.summary??null:null}function qo(n,l=rN(n)){const r=l==="created";return Object.freeze({id:FS(n,l),taskId:n.id,title:n.title,status:r?"working":n.status,event:l,turnRef:r?null:n.turnRef??n.turnId??null,turnId:r?null:n.turnId??null,timestamp:iN(n,l),summary:sN(n,l)})}function Ks(n){var o;const l=n.lastResult;if(!l)return null;const r=((o=l.provenance)==null?void 0:o.kind)==="dashboard_manual"?`manual_${l.status}`:l.status;return Object.freeze({id:FS({...n,turnRef:l.turnRef??l.turnId,turnId:l.turnId},r),taskId:n.id,title:n.title,status:l.status,event:r,turnRef:l.turnRef??l.turnId??null,turnId:l.turnId??null,timestamp:l.updatedAt,summary:l.summary})}function cN(n,l){return`${l?"Open current task details":"Show task availability"} for ${n.title}: ${nu(n)}`}function uN(n){return`Dismiss ${nu(n)} notification for ${n.title}`}function $b(n,l){return n.filter(({id:r})=>r!==l)}function fN({initialized:n,notifications:l,seenIds:r=new Set,signatures:o},s){const c=new Map(o);for(const p of s)c.set(p.id,aN(p));const f=new Set(r);if(!n){for(const p of s){f.add(qo(p,"created").id);const h=Ks(p);h&&f.add(h.id),f.add(qo(p).id)}return{additions:[],notifications:l,seenIds:f,signatures:c}}const d=[];for(const p of s){const h=[];if(o.has(p.id)){if(o.get(p.id)!==c.get(p.id)&&!oN(o.get(p.id),c.get(p.id))){h.push(qo(p));const y=Ks(p);y&&h.push(y)}}else{const y=Ks(p);(p.turnRef||p.turnId||p.status!=="working"||y)&&(h.push(qo(p)),y&&h.push(y)),h.push(qo(p,"created"))}for(const y of h)f.has(y.id)||d.push(y),f.add(y.id);const b=Ks(p);b&&f.add(b.id),f.add(qo(p).id)}return{additions:d,notifications:[...d,...l].slice(0,I_),seenIds:f,signatures:c}}function dN(n,l,r){const o=n.notifications.filter(({id:s})=>s!==l.id);return r?{...n,detailTaskId:l.taskId,detailOpened:!0,highlightTurnRef:l.turnRef??l.turnId,notifications:o,refreshGeneration:n.refreshGeneration+1}:{...n,notifications:o}}function Lb(n){return{...n,notifications:[]}}function kb(n,l){const r=Array.isArray(n.turns)&&Array.isArray(n.results),o=!Array.isArray(l.turns)&&!Array.isArray(l.results);return{...n,...l,...r&&o?{results:n.results,turns:n.turns,usage:n.usage}:{}}}function Fs(n){var l,r,o,s,c,f,d;return JSON.stringify([((l=n==null?void 0:n.usage)==null?void 0:l.generationTurnRef)??null,((r=n==null?void 0:n.usage)==null?void 0:r.status)??null,((o=n==null?void 0:n.usage)==null?void 0:o.updatedAt)??null,((c=(s=n==null?void 0:n.usage)==null?void 0:s.task)==null?void 0:c.totalTokens)??null,((d=(f=n==null?void 0:n.usage)==null?void 0:f.task)==null?void 0:d.estimatedCostUsd)??null])}const mN=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?(Z|[+-]\d{2}:\d{2})$/;function JS(n,l){const r=Bb(n),o=Bb(l);if(r===null||o===null)return null;const s=o-r;return s>=0?s:null}function PS(n){var r;const l=JS(n.startedAt,(r=n.result)==null?void 0:r.updatedAt);return l===0?null:l}function pN(n){const l=n.filter(s=>s.result!==null),r=l.map(PS).filter(s=>s!==null),o=r.length===0?l.length===0?0:null:r.reduce((s,c)=>s+c,0);return Object.freeze({terminalTurns:l.length,validTurns:r.length,totalMilliseconds:o===null||Number.isSafeInteger(o)?o:null})}function Bb(n){if(typeof n!="string")return null;const l=n.match(mN);if(!l)return null;const[,r,o,s,c,f,d,,p]=l,h=Number(r),b=Number(o),y=Number(s),v=Number(c),w=Number(f),R=Number(d),T=p==="Z"?0:Number(p.slice(1,3)),C=p==="Z"?0:Number(p.slice(4,6)),N=[31,h%4===0&&(h%100!==0||h%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];if(b<1||b>12||y<1||y>N[b-1]||v>23||w>59||R>59||T>23||C>59)return null;const _=Date.parse(n);return Number.isFinite(_)?_:null}const hm=1e3,vm=60*hm,gm=60*vm,hN=24*gm,vn="n/a";function WS(n){if(!Number.isFinite(n)||n<0)return null;if(n>0&&n<hm)return"<1s";const l=Math.floor(n/hm);if(n<vm)return`${l}s`;if(n<gm)return`${Math.floor(l/60)}m ${l%60}s`;const r=Math.floor(n/vm);if(n<hN)return`${Math.floor(r/60)}h ${r%60}m`;const o=Math.floor(n/gm);return`${Math.floor(o/24)}d ${o%24}h`}function ex(n){const l=n.turns===void 0?n.reportedWork:pN(n.turns??[]);if(l===void 0)return{accessibleLabel:"Reported work unavailable because terminal turn history is not available.",kind:"unavailable",title:"Reported wall-clock elapsed time requires the terminal turn history from the task detail projection.",value:vn};if(l.terminalTurns===0)return{accessibleLabel:"Reported work not yet reported. Unfinished turns are excluded.",kind:"not-reported",title:"Reported wall-clock elapsed time is added only after a turn reaches a terminal state.",value:vn};if(l.validTurns===0)return{accessibleLabel:"Reported work unavailable because completed turn timestamps are missing or invalid.",kind:"unavailable",title:"Reported wall-clock elapsed time is unavailable because no terminal turn has a valid start and end timestamp.",value:vn};const r=l.totalMilliseconds===null?null:WS(l.totalMilliseconds);if(r===null)return{accessibleLabel:"Reported work unavailable because the duration total is outside the supported range.",kind:"unavailable",title:"Reported wall-clock elapsed time is unavailable because the duration total is outside the supported range.",value:vn};const o=l.terminalTurns-l.validTurns,s=o>0?` ${o} terminal ${o===1?"turn was":"turns were"} unavailable and excluded.`:"";return{accessibleLabel:`Reported work ${r}. This is reported wall-clock elapsed time.${s}`,kind:"available",title:`Sum of valid terminal-turn wall-clock elapsed times; unfinished turns and idle gaps are excluded.${s}`,value:r}}function vN(n,l=Date.now()){const r=n.result===null,o=r?JS(n.startedAt,new Date(l).toISOString()):PS(n),s=r?"Elapsed so far":"Elapsed",c=o===null?vn:WS(o)??vn;return{accessibleLabel:`${s} ${o===null?"unavailable":c}. ${r?"Current":"Completed"} turn reported wall-clock elapsed time.`,kind:o===null?"unavailable":"available",label:s,title:o===null?"Reported wall-clock elapsed time is unavailable because the turn timestamps are missing, invalid, or reversed.":`Reported wall-clock elapsed time from startedAt ${r?"to the current time":"to result.updatedAt"}.`,value:c}}function lu(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2,notation:"compact"}).format(n)}function pi(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2}).format(n)}function er(n,l){return typeof n!="number"||!Number.isFinite(n)?"—":new Intl.NumberFormat(l,{currency:"USD",currencyDisplay:"narrowSymbol",maximumFractionDigits:2,minimumFractionDigits:2,style:"currency"}).format(n)}function tx(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2,minimumFractionDigits:2}).format(n)}function nx(n){var s;const l=n.usage,r=n.turnRef??((s=n.latestTurn)==null?void 0:s.turnRef)??null,o=(l==null?void 0:l.generationTurnRef)!=null&&r!=null&&l.generationTurnRef!==r;return n.status==="working"?l!=null&&l.task?Qd(l.task,!0):{kind:"pending",label:"Token usage pending"}:(l==null?void 0:l.status)==="calculating"||o?l.task?Qd(l.task,!0):{kind:"calculating",label:"Calculating token usage"}:(l==null?void 0:l.status)==="available"&&l.task?Qd(l.task,!1):!l&&n.threadId&&["completed","failed","needs_input"].includes(n.status??"")?{kind:"calculating",label:"Calculating token usage"}:{kind:"unavailable",label:(l==null?void 0:l.reason)??"Token usage unavailable"}}function Qd(n,l){const r=lu(n.totalTokens),o=n.estimatedCostUsd==null?"Estimated cost n/a":`Estimated cost ${er(n.estimatedCostUsd)}`;return{kind:"ready",knownSoFar:l,label:`${r} tokens · ${o}${l?" · known so far":""}`,usage:n}}function gN(n,l){var s,c;if(l.result===null)return{kind:"pending",label:"Turn usage pending"};const r=l.turnRef??l.turnId,o=r?(c=(s=n.usage)==null?void 0:s.turns)==null?void 0:c[r]:null;if((o==null?void 0:o.status)==="calculating")return{kind:"calculating",label:"Calculating turn usage"};if((o==null?void 0:o.status)==="available"&&typeof o.totalTokens=="number"){const f=pi(o.totalTokens),d=o.estimatedCostUsd==null?"Estimated cost n/a":`Estimated cost ${er(o.estimatedCostUsd)}`;return{kind:"ready",label:`${f} tokens · ${d}`}}return{kind:"unavailable",label:(o==null?void 0:o.reason)??"Turn usage unavailable"}}function yN(n,l){var c,f;const r=gN(n,l);if(r.kind==="ready"){const d=l.turnRef??l.turnId,p=d?(f=(c=n.usage)==null?void 0:c.turns)==null?void 0:f[d]:null,h=typeof(p==null?void 0:p.totalTokens)=="number"?pi(p.totalTokens):vn,b=typeof(p==null?void 0:p.totalTokens)=="number"?lu(p.totalTokens):vn,y=p==null?void 0:p.estimatedCostUsd,v=typeof y=="number"&&Number.isFinite(y),w=v?tx(y):vn;return{animated:!1,cost:{accessibleLabel:`Estimated cost ${v?er(y).toLowerCase():"unavailable"}`,value:w},kind:r.kind,note:null,title:r.label,tokens:{accessibleLabel:`${h} tokens`,value:b}}}const o=r.kind==="pending"?"Pending":r.kind==="calculating"?"Calculating":vn,s=r.kind==="unavailable"?"unavailable":o.toLowerCase();return{animated:r.kind==="pending"||r.kind==="calculating",cost:{accessibleLabel:`Estimated cost ${s}${r.kind==="unavailable"?`: ${r.label}`:""}`,value:o},kind:r.kind,note:r.kind==="unavailable"&&r.label!=="Turn usage unavailable"?r.label:null,title:r.label,tokens:{accessibleLabel:`Tokens ${s}${r.kind==="unavailable"?`: ${r.label}`:""}`,value:o}}}function bN(n){var l,r;return n.status!=="working"&&(((l=n.usage)==null?void 0:l.status)==="calculating"||Object.values(((r=n.usage)==null?void 0:r.turns)??{}).some(o=>o.status==="calculating"))}function SN(n){var R;const l=nx(n);if(l.kind==="pending"||l.kind==="calculating"){const T=l.kind==="pending"?"Pending":"Calculating";return{cost:{accessibleLabel:`Estimated cost ${T.toLowerCase()}`,animated:!0,title:l.label,value:T},kind:l.kind,tokens:{accessibleLabel:`Tokens ${T.toLowerCase()}`,animated:!0,title:l.label,value:T}}}if(l.kind==="unavailable"){const T=l.label==="Token usage unavailable"?"":`: ${l.label}`;return{cost:{accessibleLabel:`Estimated cost unavailable${T}`,animated:!1,title:l.label,value:vn},kind:"unavailable",tokens:{accessibleLabel:`Token usage unavailable${T}`,animated:!1,title:l.label,value:`${vn} tokens`}}}const r=lu(l.usage.totalTokens),o=pi(l.usage.totalTokens),s=l.usage.estimatedCostUsd,c=typeof s=="number"&&Number.isFinite(s),f=c?er(s):null,d=c?tx(s):null,p=l.knownSoFar?" · Updating…":"",h=l.knownSoFar?"; updating":"",b=c?p:"",y=c?h:"",v=l.usage.sourceUpdatedAt??l.usage.sampledAt??((R=n.usage)==null?void 0:R.updatedAt)??null,w=v&&!Number.isNaN(Date.parse(v))?` Cached usage updated ${new Date(v).toLocaleString()}.`:"";return{cost:{accessibleLabel:`Estimated cost ${f??"unavailable"}${y}.${w}`,animated:l.knownSoFar&&c,title:`${f===null?"Estimated cost unavailable":`Unrounded estimate: $${l.usage.estimatedCostUsd}`}${b}.${w}`,value:d??vn},kind:"ready",tokens:{accessibleLabel:`${o} tokens${h}.${w}`,animated:l.knownSoFar,title:`${o} tokens${p}.${w}`,value:`${r} tokens`}}}function xN(n){return n==="completed"?"teal":n==="needs_input"?"yellow":n==="failed"?"red":n==="working"?"blue":"gray"}function wN(n){return n===null?"Unresolved":n.replaceAll("_"," ")}const Kd=30,oi=6e4,fc=60*oi,Ga=24*fc;function lx(n){if(typeof n!="string"||n.trim()==="")return null;const l=Date.parse(n);return Number.isFinite(l)?{date:new Date(l),iso:new Date(l).toISOString(),milliseconds:l}:null}function Hb(n,{locale:l,timeZone:r}={}){const o=lx(n);return o?new Intl.DateTimeFormat(l,{dateStyle:"medium",timeStyle:"short",timeZone:r}).format(o.date):"—"}function CN(n,l){const r=Math.floor(n/fc),o=r===1?"1 hour":`${r} hours`;return l==="future"?`in ${o}`:`${o} ago`}function Lp(n,{now:l=Date.now(),locale:r,timeZone:o}={}){const s=lx(n);if(!s)return"—";const c=l-s.milliseconds,f=c<0,d=Math.abs(c);if(d<oi)return"just now";if(d<2*oi)return f?"in 1 minute":"1 minute ago";if(d<fc){const b=f?Math.ceil(d/oi):Math.floor(d/oi);return f?`in ${b} minutes`:`${b} minutes ago`}if(d<2*fc)return f?"in 1 hour":"1 hour ago";if(d<Ga)return CN(d,f?"future":"past");if(d<2*Ga)return f?"in 1 day":"1 day ago";if(d<Kd*Ga){const b=f?Math.ceil(d/Ga):Math.floor(d/Ga);return f?`in ${b} days`:`${b} days ago`}const p=f?Math.ceil(d/(Kd*Ga)):Math.floor(d/(Kd*Ga)),h=p===1?"1 month":`${p} months`;return f?`in ${h}`:`${h} ago`}function au({status:n}){return g.jsx(Jo,{className:"taskchef-status-badge",color:xN(n),size:"sm",variant:"light",children:wN(n)})}function Ub({notifications:n,announcements:l=n,onClear:r,onDismiss:o,onOpen:s,tasks:c,withinPortal:f=!0}){if(n.length===0)return null;const d=g.jsxs(g.Fragment,{children:[g.jsxs(gn,{"aria-label":"Task notifications",className:"taskchef-notifications",p:"sm",radius:"md",role:"region",shadow:"xl",withBorder:!0,children:[g.jsxs(St,{justify:"space-between",mb:"xs",children:[g.jsxs(St,{gap:6,children:[g.jsx(m_,{"aria-hidden":!0,size:16}),g.jsx(_e,{fw:700,size:"sm",children:"Updates"})]}),g.jsx(il,{onClick:r,size:"compact-xs",variant:"subtle",children:"Clear all"})]}),g.jsx(Un.Autosize,{className:"taskchef-notification-scroll",mah:"min(55vh, 520px)",type:"auto",children:g.jsx(Ut,{className:"taskchef-notification-list",gap:6,children:n.map(p=>{const h=c.some(w=>w.id===p.taskId),b=`notification-${Math.abs(RN(p.id))}`,y=`${b}-summary`,v=`${b}-metadata`;return g.jsx(gn,{className:"taskchef-notification",p:"xs",radius:"sm",children:g.jsxs(St,{align:"flex-start",gap:"xs",wrap:"nowrap",children:[g.jsxs("button",{"aria-describedby":[p.summary?y:null,v].filter(Boolean).join(" "),"aria-label":cN(p,h),className:"taskchef-notification-open",onClick:()=>s(p),type:"button",children:[g.jsxs(St,{gap:"xs",justify:"space-between",wrap:"nowrap",children:[g.jsx(_e,{fw:700,size:"sm",children:nu(p)}),g.jsx(au,{status:p.status})]}),g.jsx(_e,{lineClamp:1,size:"sm",children:p.title}),p.summary&&g.jsx(_e,{className:"taskchef-preserve-lines",id:y,lineClamp:3,size:"xs",children:p.summary}),g.jsxs(_e,{c:"dimmed",id:v,size:"xs",children:[Lp(p.timestamp),h?"":" · Task no longer available"]})]}),g.jsx(Zn,{label:"Dismiss notification",children:g.jsx(ul,{"aria-label":uN(p),color:"gray",onClick:()=>o(p),size:"compact-sm",variant:"subtle",children:g.jsx(IS,{"aria-hidden":!0,size:14})})})]})},p.id)})})})]}),g.jsx(ue,{"aria-atomic":"true","aria-live":"polite",className:"taskchef-visually-hidden",role:"status",children:l.map(TN).join(" ")})]});return f?g.jsx(ep,{children:d}):d}function TN(n){return[nu(n),n.title,n.summary,n.turnRef?`Turn ref ${n.turnRef}`:null,Lp(n.timestamp)].filter(Boolean).map(l=>String(l).replace(/[.\s]+$/,"")).join(". ")+"."}function RN(n){let l=0;for(const r of n)l=(l<<5)-l+r.charCodeAt(0)|0;return l}const EN=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]+$/,AN=/https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9._-]+)\/(issues|pull)\/([1-9]\d*)(?![A-Za-z0-9_])|([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9._-]+)#([1-9]\d*)(?![A-Za-z0-9_])|#([1-9]\d*)(?![A-Za-z0-9_])|https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9_-])?)\/?(?=$|[\s#),.;:!?'"\]}>])/gi,_N=/https?:\/\/[^\s<>"'`]+/gi;function Qo(n){return!(n!=null&&n.owner)||!(n!=null&&n.repository)?null:`${n.owner.toLowerCase()}/${n.repository.toLowerCase()}`}function ax(n){const l=new Map;for(const r of n){const o=Qo(r);if(!o)continue;const s=r.repository.toLowerCase(),c=l.get(s)??new Set;c.add(o),l.set(s,c)}return new Set([...l].filter(([,r])=>r.size>1).map(([r])=>r))}function ym(n,l){return l.has(n.repository.toLowerCase())?`${n.owner}/${n.repository}`:n.repository}function ox(n,{related:l=!1}={}){const r=ax(n);let o=null;return n.map(s=>{if(s.provider!=="github"&&!s.owner)return s.label??s.text;const c=Qo(s),f=ym(s,r);if(s.type==="repository")return f;if(l){const d=c===o?`#${s.number}`:`${f} #${s.number}`;return o=c,d}return s.type==="pull"?`${f} PR #${s.number}`:s.type==="issue"?`${f} Issue #${s.number}`:`${f} #${s.number}`})}function NN(n,l){const r=String(n.number??""),o=String(l.number??"");return r.length-o.length||r.localeCompare(o)}function MN(n){const l=new Map,r=new Set,o=new Set,s=new Set;for(const f of n??[]){const d=Qo(f),p=f.number?`${d}#${f.number}`:null;if(f.type==="repository"||!d||r.has(f.label)||s.has(f.url)||p&&o.has(p))continue;r.add(f.label),s.add(f.url),p&&o.add(p);const h=l.get(d)??[];h.push(f),l.set(d,h)}const c=ax(n??[]);return[...l.values()].map(f=>[...f].sort(NN)).sort((f,d)=>{const p=ym(f[0],c),h=ym(d[0],c);return p.localeCompare(h,void 0,{sensitivity:"base"})||Qo(f[0]).localeCompare(Qo(d[0]))})}function rx(n){const l=Qo(n);return l?n.type==="repository"?l:n.type==="pull"?`${l} PR #${n.number}`:n.type==="issue"?`${l} Issue #${n.number}`:`${l} #${n.number}`:n.label??n.text}function ix(n,l){return`${n.toLowerCase()}/${l.toLowerCase()}`}function sx(n){return n!=="."&&n!==".."}function cx(n){if(typeof n!="string")return null;let l=n.trim();const r=l.match(/^https?:\/\/(?:www\.)?github\.com\/([^/?#]+)\/([^/?#]+?)(?:\.git)?\/?$/i);if(r&&(l=`${r[1]}/${r[2]}`),!EN.test(l))return null;const[o,s]=l.split("/");return sx(s)?ix(o,s):null}function jN(n){var s;const l=String(n??""),r=ux(l),o=[];for(const c of l.matchAll(AN)){const f=c.index,d=f>0?l[f-1]:"";let p=null;const h=r.find(C=>f>=C.start&&f<C.end);if(h){const C=!!(c[1]||c[9]);let A=null;try{A=new URL(h.text).hostname.toLowerCase()}catch{}if(!(C&&f===h.start&&(A==="github.com"||A==="www.github.com"))||!fx(h.text))continue;p={end:h.end,suffix:h.text.slice(c[0].length),text:h.text}}if(c[8]&&/[\w&#/]/.test(d)||(c[5]||c[1]||c[9])&&/[\w/]/.test(d))continue;let b=c[1]??c[5]??c[9]??null,y=c[2]??c[6]??c[10]??null;c[9]&&(y=y.replace(/\.git$/i,""));const v=c[4]??c[7]??c[8]??null,w=(s=c[3])==null?void 0:s.toLowerCase(),R=c[9]?"repository":w==="pull"?"pull":w==="issues"?"issue":"generic",T=!!(b&&y);if(T){if(!sx(y))continue;[b,y]=ix(b,y).split("/")}o.push({end:(p==null?void 0:p.end)??f+c[0].length,explicit:T,number:v,owner:b,repository:y,start:f,text:(p==null?void 0:p.text)??c[0],type:R,urlSuffix:(p==null?void 0:p.suffix)??""})}return o}function ON(n){const l=new Set(n.filter(({explicit:r})=>r).map(({owner:r,repository:o})=>`${r}/${o}`));return l.size===1?[...l][0]:null}function zN(n){const l=new Set((n??[]).map(cx).filter(Boolean));return l.size===1?[...l][0]:null}function DN(n,l){const r=n.explicit?`${n.owner}/${n.repository}`:l;if(!r)return null;const[o,s]=r.split("/");if(n.type==="repository")return{kind:"link",label:`${o}/${s}`,number:null,owner:o,provider:"github",repository:s,text:n.text,type:n.type,url:`https://github.com/${o}/${s}${n.urlSuffix}`};const c=n.type==="pull"?"pull":"issues";return{kind:"link",label:`${o}/${s}#${n.number}`,number:n.number,owner:o,provider:"github",repository:s,text:n.text,type:n.type,url:`https://github.com/${o}/${s}/${c}/${n.number}${n.urlSuffix}`}}function $N(n){let l=n,r;do{r=l,l=l.replace(/[.,;:!?]+$/u,"");for(const[o,s]of[["(",")"],["[","]"],["{","}"]])for(;l.endsWith(s);){const c=[...l].filter(d=>d===o).length;if([...l].filter(d=>d===s).length<=c)break;l=l.slice(0,-1)}}while(l!==r);return l}function ux(n){const l=[];for(const r of String(n??"").matchAll(_N)){const o=$N(r[0]);o&&l.push({end:r.index+o.length,start:r.index,text:o})}return l}function LN(n){const l=n.slice(n.indexOf("//")+2).split(/[?#]/u,1)[0],r=l.indexOf("/");return r<0?!1:l.slice(r).split("/").some(o=>{try{const s=decodeURIComponent(o);return s==="."||s===".."}catch{return!0}})}function fx(n){try{const l=new URL(n);return!l.hostname||l.username||l.password||n.includes("\\")||LN(n)?null:l.href}catch{return null}}function kN(n){const l=[];for(const r of ux(n)){const o=fx(r.text);o&&l.push({end:r.end,kind:"link",label:r.text,provider:"web",start:r.start,text:r.text,type:"url",url:o})}return l}function BN(n,{projectRepositories:l=[],taskRepository:r=null}={}){const o=String(n??""),s=jN(o),f=ON(s)??cx(r)??zN(l),d=[];let p=0;for(const h of s){h.start>p&&d.push({kind:"text",text:o.slice(p,h.start)});const b=DN(h,f);b?d.push(b):d.push({kind:"ambiguous",reason:`GitHub reference ${h.text} is not linked because the repository is ambiguous.`,text:h.text}),p=h.end}return p<o.length&&d.push({kind:"text",text:o.slice(p)}),d}function HN(n,l={}){const r=String(n??""),o=BN(r,l),s=[];let c=0;for(const h of o){const b=r.indexOf(h.text,c);b<0||(h.kind!=="text"&&s.push({end:b+h.text.length,segment:h,start:b}),c=b+h.text.length)}const f=kN(r).filter(h=>!s.some(({end:b,start:y})=>h.start<b&&h.end>y));if(f.length===0)return o;s.push(...f.map(h=>({end:h.end,segment:h,start:h.start}))),s.sort((h,b)=>h.start-b.start);const d=[];let p=0;for(const h of s)h.start<p||(h.start>p&&d.push({kind:"text",text:r.slice(p,h.start)}),d.push(h.segment),p=h.end);return p<r.length&&d.push({kind:"text",text:r.slice(p)}),d}function dx({task:n}){const l=n.relatedGitHubLinks??[];if(l.length===0&&!n.relatedGitHubLinksTruncated)return null;const r=MN(l),o=ox(r.flat(),{related:!0});let s=0;return g.jsxs(ue,{"aria-label":`Related GitHub links for ${n.title}`,className:"taskchef-github-groups",component:"nav",children:[r.map(c=>g.jsx(St,{className:"taskchef-github-group",gap:5,wrap:"wrap",children:c.map(f=>{const d=o[s];s+=1;const p=f.type==="pull"?", GitHub pull request":f.type==="issue"?", GitHub issue":" on GitHub";return g.jsx(Lc,{"aria-label":`${rx(f)}${p} (opens in a new tab)`,className:"taskchef-github-link",href:f.url,rel:"noopener noreferrer",size:"xs",target:"_blank",children:d},f.url)})},`${c[0].owner}/${c[0].repository}`)),n.relatedGitHubLinksTruncated&&g.jsx(_e,{c:"dimmed",size:"xs",children:"More links in task history"})]})}function dc({task:n,text:l}){const r=HN(l,{projectRepositories:n.project.githubRepos,taskRepository:n.relatedGitHubRepository}),o=r.filter(f=>f.kind==="link"),s=ox(o);let c=0;return r.map((f,d)=>{if(f.kind==="text")return f.text;if(f.kind==="ambiguous")return g.jsx("span",{"aria-label":f.reason,className:"taskchef-github-reference-ambiguous",tabIndex:0,title:f.reason,children:f.text},`${d}:${f.text}`);const p=s[c];c+=1;const h=f.type==="pull"?", GitHub pull request":f.type==="issue"?", GitHub issue":f.owner?" on GitHub":"";return g.jsx(Lc,{"aria-label":`${rx(f)}${h} (opens in a new tab)`,className:"taskchef-github-link",href:f.url,rel:"noopener noreferrer",target:"_blank",children:p},`${d}:${f.url}`)})}function mx({loading:n,onClick:l,taskTitle:r}){return g.jsx(il,{"aria-label":`Open chat for ${r}`,leftSection:g.jsx(T_,{"aria-hidden":!0,size:15}),loading:n,onClick:l,size:"compact-sm",variant:"default",children:"Open chat"})}function ou({children:n,className:l="",...r}){return g.jsx("span",{className:`taskchef-shimmer ${l}`.trim(),"data-animation":"text-shimmer",...r,children:n})}const px=x.createContext(null);function UN({children:n,now:l}){return g.jsx(px,{value:l,children:n})}function mc({icon:n,label:l,value:r}){const[o,s]=x.useState(!1);x.useContext(px);const c=o?Hb(r):Lp(r),f=Hb(r),d=f==="—",p=f==="—"?"Updated time unavailable":o?"Show relative time":`Exact time: ${f}. Show exact time`;return g.jsx(Zn,{label:p,children:g.jsxs(kl,{"aria-label":d?`${l}: unavailable.`:`${l}: ${c}. ${o?"Show relative time":"Show exact time"}`,className:"taskchef-time",disabled:d,onClick:()=>s(h=>!h),children:[n??g.jsx(b_,{"aria-hidden":!0,size:12}),g.jsx("bdi",{className:"taskchef-time-label",children:c})]})})}function hx({children:n,variant:l}){return g.jsx(ue,{className:`taskchef-stats taskchef-${l}-stats`,component:"div",children:n})}function va({children:n,usageState:l}){return g.jsx(ue,{className:"taskchef-stat","data-usage-state":l,children:n})}function Ko({accessibleLabel:n,animated:l=!1,icon:r,title:o,value:s}){return g.jsx(Zn,{events:{focus:!0,hover:!0,touch:!1},label:o,multiline:!0,children:g.jsxs(_e,{"aria-label":n,className:"taskchef-stat-content",component:"span",size:"xs",tabIndex:0,children:[r,g.jsx("bdi",{children:l?g.jsx(ou,{children:s}):s})]})})}function YN({task:n}){const l=ex(n),r=SN(n);return g.jsxs(hx,{variant:"card",children:[g.jsx(va,{children:g.jsx(mc,{icon:g.jsx(VS,{"aria-hidden":!0,size:14}),label:`Updated time for ${n.title}`,value:n.meaningfulUpdatedAt??n.updatedAt})}),g.jsx(va,{children:g.jsx(Ko,{accessibleLabel:l.accessibleLabel,icon:g.jsx(GS,{"aria-hidden":!0,size:14}),title:l.title,value:l.value})}),g.jsxs(va,{usageState:r.kind,children:[g.jsx(Ko,{accessibleLabel:r.tokens.accessibleLabel,animated:r.tokens.animated,icon:g.jsx(XS,{"aria-hidden":!0,size:14}),title:r.tokens.title,value:r.tokens.value}),g.jsxs(_e,{className:"taskchef-visually-hidden",component:"span",role:"status",children:[r.tokens.accessibleLabel,"; ",r.cost.accessibleLabel]})]}),g.jsx(va,{usageState:r.kind,children:g.jsx(Ko,{accessibleLabel:r.cost.accessibleLabel,animated:r.cost.animated,icon:g.jsx(qS,{"aria-hidden":!0,size:14}),title:r.cost.title,value:r.cost.value})})]})}function qN({onOpenCodex:n,onOpenDetail:l,task:r}){const o=W_(r);return g.jsx(gn,{className:"taskchef-task-row",component:"article",p:"md",radius:"md",withBorder:!0,children:g.jsxs(Ut,{className:"taskchef-task-main",gap:"sm",children:[g.jsxs(ue,{children:[g.jsxs(ue,{className:"taskchef-card-heading",children:[g.jsx(Wt,{order:3,size:"h5",children:g.jsx("button",{className:"taskchef-title-button",onClick:()=>l(r),type:"button",children:r.title})}),g.jsxs(Ut,{align:"flex-end",className:"taskchef-card-metadata",gap:4,children:[g.jsx(au,{status:r.status}),g.jsx(mx,{onClick:()=>n(r),taskTitle:r.title})]})]}),g.jsx(_e,{c:"dimmed",mt:2,size:"xs",children:r.project.name})]}),g.jsxs(ue,{className:"taskchef-summary-grid",children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Request"}),g.jsx(_e,{className:"taskchef-preserve-lines",lineClamp:3,size:"sm",children:g.jsx(dc,{task:r,text:o.requestSummary})}),g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Result"}),g.jsx(_e,{className:"taskchef-preserve-lines",lineClamp:3,size:"sm",children:o.resultStatus==="working"?g.jsx(ou,{children:o.resultSummary}):g.jsx(dc,{task:r,text:o.resultSummary})})]}),g.jsx(dx,{task:r}),g.jsx(YN,{task:r})]})})}function VN({highlightTurnRef:n,task:l}){const r=tN(l,[]);return r!=null&&r.length?g.jsx(Ut,{gap:"sm",children:[...r].reverse().map((o,s)=>{const c=eN(o),f=o.turnRef??o.turnId??`turn-${s}`,d=f===n,p=yN(l,o);return g.jsx(gn,{className:`taskchef-turn${d?" taskchef-turn-highlighted":""}`,"data-turn-ref":f,p:"sm",radius:"md",tabIndex:d?-1:void 0,withBorder:!0,children:g.jsxs(Ut,{gap:7,children:[g.jsxs(ue,{className:"taskchef-turn-heading",children:[g.jsx(_e,{c:"dimmed",size:"xs",children:c.sourceLabel}),g.jsx(au,{status:c.status})]}),g.jsxs(ue,{children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Request"}),g.jsx(_e,{className:"taskchef-preserve-lines",size:"sm",children:g.jsx(dc,{task:l,text:o.requestSummary??"Request not recorded."})})]}),g.jsxs(ue,{children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Result"}),g.jsx(_e,{className:"taskchef-preserve-lines",size:"sm",children:c.status==="working"?g.jsx(ou,{children:c.summary}):g.jsx(dc,{task:l,text:c.summary})})]}),g.jsxs(hx,{variant:"turn",children:[g.jsx(va,{children:g.jsx(mc,{icon:g.jsx(VS,{"aria-hidden":!0,size:14}),label:"Turn update time",value:c.updatedAt})}),g.jsx(va,{children:g.jsx(GN,{turn:o})}),g.jsx(va,{usageState:p.kind,children:g.jsx(Ko,{accessibleLabel:p.tokens.accessibleLabel,animated:p.animated,icon:g.jsx(XS,{"aria-hidden":!0,size:14}),title:p.title,value:p.tokens.value})}),g.jsx(va,{usageState:p.kind,children:g.jsx(Ko,{accessibleLabel:p.cost.accessibleLabel,animated:p.animated,icon:g.jsx(qS,{"aria-hidden":!0,size:14}),title:p.title,value:p.cost.value})})]}),p.note&&g.jsx(_e,{c:"dimmed",size:"xs",children:p.note})]})},f)})}):g.jsx(_e,{c:"dimmed",size:"sm",children:"No turn history has been recorded."})}function GN({turn:n}){const l=XN(n.result===null),r=vN(n,l);return g.jsx(Ko,{accessibleLabel:r.accessibleLabel,icon:g.jsx(GS,{"aria-hidden":!0,size:14}),title:r.title,value:r.value})}function XN(n){const[l,r]=x.useState(()=>Date.now());return x.useEffect(()=>{if(!n)return;r(Date.now());const o=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(o)},[n]),l}function IN({task:n}){const l=nx(n),r=ex(n),o=l.kind==="ready"?l:null,s=(o==null?void 0:o.usage.cachedInputTokens)??0,c=(o==null?void 0:o.usage.inputTokens)??0,f=o&&c+s>0?`${Math.round(s/(c+s)*100)}%`:"n/a",d=Object.keys((o==null?void 0:o.usage.models)??{}).join(", "),p=l.kind==="pending"?"Pending":l.kind==="calculating"?"Calculating":"n/a",h=l.kind==="unavailable"?"unavailable":p.toLowerCase(),b=[{accessibleValue:o?`${pi(o.usage.totalTokens)} tokens`:l.label,animated:l.kind==="pending"||l.kind==="calculating",label:o!=null&&o.knownSoFar?"Tokens · known so far":"Tokens",title:o?`${pi(o.usage.totalTokens)} tokens`:l.label,value:o?lu(o.usage.totalTokens):p},{accessibleValue:o?o.usage.estimatedCostUsd==null?"Estimated cost unavailable":`Estimated cost ${er(o.usage.estimatedCostUsd)}`:`Estimated cost ${h}${l.kind==="unavailable"?`: ${l.label}`:""}`,animated:l.kind==="pending"||l.kind==="calculating",label:"Estimated cost",title:(o==null?void 0:o.usage.estimatedCostUsd)==null?"Estimated cost unavailable":`Unrounded estimate: $${o.usage.estimatedCostUsd}`,value:o?o.usage.estimatedCostUsd==null?"n/a":er(o.usage.estimatedCostUsd):p},{accessibleValue:r.accessibleLabel,label:"Reported work",title:r.title,value:r.value},...o?[{accessibleValue:d||"Model unavailable",label:"Model",title:d||"Model unavailable",value:d||"n/a"},{accessibleValue:f==="n/a"?"Cache ratio unavailable":`Cache ratio ${f}`,label:"Cache ratio",title:f==="n/a"?"Cache ratio unavailable because no input-token total is available.":void 0,value:f}]:[]];return g.jsxs(ue,{"aria-live":"polite",children:[g.jsx(ue,{className:"taskchef-metrics",children:b.map(({accessibleValue:y,animated:v,label:w,title:R,value:T})=>g.jsxs(gn,{className:"taskchef-metric",p:"sm",radius:"md",withBorder:!0,children:[g.jsx(_e,{c:"dimmed",size:"xs",children:w}),g.jsx(_e,{"aria-label":y,className:"taskchef-metric-value",fw:650,size:"sm",title:R,children:v?g.jsx(ou,{children:T}):T})]},w))}),l.kind==="unavailable"&&l.label!=="Token usage unavailable"&&g.jsx(_e,{c:"dimmed",mt:"xs",size:"xs",children:l.label})]})}function ZN({busy:n,error:l,highlightTurnRef:r,onClose:o,onCopy:s,onOpenCodex:c,onTransition:f,opened:d,task:p,notifications:h,notice:b}){var C;const y=Rm("(max-width: 48em)"),[v,w]=x.useState(null);if(x.useEffect(()=>{d||w(null)},[d]),x.useEffect(()=>{d&&r&&requestAnimationFrame(()=>{var A;(A=document.querySelector(`[data-turn-ref="${CSS.escape(r)}"]`))==null||A.focus()})},[r,d,(C=p==null?void 0:p.turns)==null?void 0:C.length,p==null?void 0:p.updatedAt]),x.useEffect(()=>{v&&(!p||!Yb(p).includes(v))&&w(null)},[v,p==null?void 0:p.status]),!p)return null;const R=Yb(p),T=g.jsxs(Ut,{gap:"lg",children:[h,g.jsxs(ue,{children:[g.jsxs(St,{align:"flex-start",gap:"sm",justify:"space-between",wrap:"nowrap",children:[g.jsxs(ue,{children:[g.jsx(_e,{c:"teal",fw:700,size:"xs",tt:"uppercase",children:p.project.name}),g.jsx(Wt,{id:"task-detail-title",order:2,size:"h3",tabIndex:-1,children:p.title})]}),g.jsx(au,{status:p.status})]}),g.jsxs(St,{gap:"xs",mt:"md",children:[g.jsx(mx,{loading:n,onClick:c,taskTitle:p.title}),g.jsxs(xt,{position:"bottom-start",shadow:"md",withinPortal:!0,zIndex:360,children:[g.jsx(xt.Target,{children:g.jsx(Zn,{label:"More task actions",children:g.jsx(ul,{"aria-label":"More task actions",disabled:n,variant:"default",children:g.jsx(w_,{"aria-hidden":!0,size:17})})})}),g.jsxs(xt.Dropdown,{children:[g.jsx(xt.Item,{leftSection:g.jsx(g_,{size:14}),onClick:s,children:"Copy Task ID"}),R.includes("completed")&&g.jsx(xt.Item,{leftSection:g.jsx(h_,{size:14}),onClick:()=>w("completed"),children:"Mark completed"}),R.includes("failed")&&g.jsx(xt.Item,{color:"red",leftSection:g.jsx(IS,{size:14}),onClick:()=>w("failed"),children:"Mark failed"})]})]})]}),g.jsx(ue,{mt:"sm",children:g.jsx(dx,{task:p})})]}),v&&g.jsx(QN,{busy:n,onCancel:()=>w(null),onTransition:f,status:v},v),b&&g.jsx(Mn,{color:"teal",role:"status",children:b}),l&&g.jsx(Mn,{color:"red",role:"alert",children:l}),g.jsxs("section",{"aria-labelledby":"usage-heading",children:[g.jsx(Wt,{id:"usage-heading",mb:"xs",order:3,size:"h5",children:"Usage"}),g.jsx(IN,{task:p})]}),g.jsx(Uc,{}),g.jsxs("section",{"aria-labelledby":"activity-heading",children:[g.jsx(Wt,{id:"activity-heading",mb:"sm",order:3,size:"h5",children:"Activity timeline"}),g.jsx(VN,{highlightTurnRef:r,task:p})]}),g.jsxs("section",{"aria-labelledby":"instruction-heading",children:[g.jsx(Wt,{id:"instruction-heading",mb:"xs",order:3,size:"h5",children:"Original instruction"}),g.jsx(ue,{className:"taskchef-code-panel",component:"pre",children:p.instruction})]}),g.jsxs("section",{"aria-labelledby":"metadata-heading",children:[g.jsx(Wt,{id:"metadata-heading",mb:"xs",order:3,size:"h5",children:"Metadata"}),g.jsxs("dl",{className:"taskchef-metadata",children:[g.jsx("dt",{children:"Task ID"}),g.jsx("dd",{children:p.id}),g.jsx("dt",{children:"Thread ID"}),g.jsx("dd",{children:p.threadId??"—"}),g.jsx("dt",{children:"Current turn ref"}),g.jsx("dd",{children:p.turnRef??"—"}),g.jsx("dt",{children:"Project path"}),g.jsx("dd",{children:p.project.path}),g.jsx("dt",{children:"Created"}),g.jsx("dd",{children:g.jsx(mc,{label:"Created time",value:p.createdAt})}),g.jsx("dt",{children:"Updated"}),g.jsx("dd",{children:g.jsx(mc,{label:"Updated time",value:p.meaningfulUpdatedAt??p.updatedAt})}),g.jsx("dt",{children:"Updated by"}),g.jsx("dd",{children:p.updatedBy??"—"})]})]})]});return y?g.jsx(Gn,{closeOnClickOutside:!n,closeOnEscape:!n,onClose:o,opened:d,overlayProps:{backgroundOpacity:.55,blur:2},position:"bottom",scrollAreaComponent:Un.Autosize,size:"92%",title:g.jsx("span",{className:"taskchef-visually-hidden",children:"Task details"}),trapFocus:!0,zIndex:300,children:T}):g.jsx(In,{"aria-labelledby":"task-detail-title",closeOnClickOutside:!n,closeOnEscape:!n,onClose:o,opened:d,overlayProps:{backgroundOpacity:.55,blur:2},scrollAreaComponent:Un.Autosize,size:"min(820px, calc(100vw - 32px))",title:g.jsx("span",{className:"taskchef-visually-hidden",children:"Task details"}),trapFocus:!0,zIndex:300,children:T})}function Yb(n){return n.status==="completed"?["failed"]:n.status==="failed"?["completed"]:n.status==="working"||n.status==="needs_input"?["completed","failed"]:[]}function QN({busy:n,onCancel:l,onTransition:r,status:o}){const s=x.useRef(crypto.randomUUID());return g.jsxs(Mn,{color:o==="failed"?"red":"teal",role:"alert",title:`Mark task ${o}?`,children:[g.jsx(_e,{mb:"sm",size:"sm",children:"This interrupts active work and appends an audited manual dashboard turn."}),g.jsxs(St,{gap:"xs",children:[g.jsx(il,{color:o==="failed"?"red":"teal",loading:n,onClick:async()=>{const c=await r(o,s.current);c.ok?(l(),requestAnimationFrame(()=>{var f;return(f=document.getElementById("task-detail-title"))==null?void 0:f.focus()})):c.rotateActionId&&(s.current=crypto.randomUUID())},size:"compact-sm",children:"Confirm"}),g.jsx(il,{disabled:n,onClick:l,size:"compact-sm",variant:"default",children:"Cancel"})]})]})}const KN={primaryColor:"teal",colors:{teal:["#e6fcf5","#c3fae8","#96f2d7","#63e6be","#38d9a9","#20c997","#087f5b","#067052","#055e46","#044d39"]},defaultRadius:"md",fontFamily:"Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",headings:{fontFamily:"inherit",fontWeight:"680"},components:{Button:{defaultProps:{radius:"md"}},Paper:{defaultProps:{radius:"md"}}}};var Vb;const qb=(Vb=document.querySelector('meta[name="taskchef-style-nonce"]'))==null?void 0:Vb.content;function FN({totalCount:n,visibleCount:l}){return g.jsxs(_e,{"aria-live":"polite",className:"taskchef-results-summary",id:"task-results-summary",children:["Tasks: ",l," of ",n]})}function JN({connect:n=!0,initialFilters:l={},initialTasks:r=[]}){const[o,s]=x.useState(()=>window.location.hash==="#settings");x.useEffect(()=>{const me=()=>s(window.location.hash==="#settings");return window.addEventListener("hashchange",me),()=>window.removeEventListener("hashchange",me)},[]);const[c,f]=x.useState(r),[d,p]=x.useState(),[h,b]=x.useState(!1),[y,v]=x.useState(null),[w,R]=x.useState(null),[T,C]=x.useState(l.project??""),[A,N]=x.useState(l.status??""),[_,j]=x.useState(l.date??"all"),[$,L]=x.useState(()=>Date.now()),[D,H]=x.useState(null),[W,le]=x.useState(!1),[ae,te]=x.useState(!1),[J,V]=x.useState(null),[ce,O]=x.useState(null),[B,U]=x.useState(null),[Q,P]=x.useState({initialized:r.length>0,announcements:[],notifications:[],seenIds:new Set,signatures:new Map}),M=(D==null?void 0:D.id)??null,Y=x.useRef(M);Y.current=M;const F=x.useRef(0),re=x.useRef(null),ie=x.useRef(Fs(null)),fe=x.useCallback(me=>{f(me.tasks),p(me.projectIndex),P(qe=>{const ze=fN(qe,me.tasks);return{initialized:!0,announcements:ze.additions,notifications:ze.notifications,seenIds:ze.seenIds,signatures:ze.signatures}}),v(me.healthy===!1?"The task log is temporarily unavailable. Showing the last valid snapshot.":null);const Me=Y.current;if(Me){const qe=me.tasks.find(ze=>ze.id===Me);qe&&H(ze=>ze?kb(ze,qe):qe)}},[]);x.useEffect(()=>{const me=window.setInterval(()=>L(Date.now()),3e4);return()=>window.clearInterval(me)},[]),x.useEffect(()=>{if(!n)return;U_().then(R).catch(()=>R(null));const me=H_({onConnection:b,onError:v,onSnapshot:fe});return()=>me.close()},[fe,n]);const ge=x.useCallback(async(me,Me=null)=>{const qe=++F.current;re.current=me.updatedAt,ie.current=Fs(me),H(ze=>(ze==null?void 0:ze.id)===me.id?kb(ze,me):me),le(!0),U(Me),V(null),O(null);try{for(let ze=0;ze<=40;ze+=1){if(qe!==F.current)return;const Je=await q_(me.id);if(qe!==F.current||(re.current=Je.updatedAt,ie.current=Fs(Je),H(Je),!bN(Je)||ze===40))return;await new Promise(ct=>window.setTimeout(ct,1500))}}catch{qe===F.current&&V("Task activity is temporarily unavailable. Showing the latest list snapshot.")}},[]),de=c.find(me=>me.id===M)??null,he=Fs(de);x.useEffect(()=>{!W||!M||!n||de&&(de.updatedAt===re.current&&he===ie.current||ge(de,B))},[de==null?void 0:de.updatedAt,he]);const Oe=x.useMemo(()=>[{label:"All projects",value:""},...[...new Set(c.map(me=>me.project.name))].sort().map(me=>({label:me,value:me}))],[c]),be=x.useMemo(()=>KS(c,{project:T,status:A,date:_,now:$}),[c,T,A,_,$]),Ce=x.useMemo(()=>lN(c,{project:T,date:_,now:$}),[c,T,_,$]),Se=ZS.map(({label:me,value:Me})=>({label:Ce[Me]>0?`${me} ${Ce[Me]}`:me,value:Me}));async function Ne(me){te(!0);try{const Me=await V_(me.id);Me&&v(Me)}catch{v("Codex could not be opened. Open the project and select the recorded task instead.")}finally{te(!1)}}async function st(me,Me){if(!D)return{ok:!1};const qe=D,ze=J_(qe);te(!0),V(null);const Je=await G_(qe,me,Me);return te(!1),Je.task&&(H(ct=>Db({requestTask:qe,expected:ze,responseTask:Je.task,selectedTask:ct})),f(ct=>ct.map(jt=>jt.id===qe.id?Db({requestTask:qe,expected:ze,responseTask:Je.task,selectedTask:jt}):jt))),Je.ok&&Je.task?(U(Je.task.turnRef??Je.task.turnId),{ok:!0}):(V(Je.message??"Task state could not be changed."),{ok:!1,rotateActionId:Je.code==="stale_task"})}function at(me){const Me=c.find(ze=>ze.id===me.taskId),qe=dN({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:Q.notifications,refreshGeneration:F.current},me,!!Me);if(P(ze=>({...ze,notifications:qe.notifications})),!Me){v("This task is no longer present in the current snapshot.");return}ge(Me,qe.highlightTurnRef)}return g.jsx(c0,{defaultColorScheme:"auto",getStyleNonce:qb?()=>qb:void 0,theme:KN,children:g.jsxs(UN,{now:$,children:[g.jsxs(Yn,{className:"taskchef-shell",padding:0,children:[g.jsx(mi,{className:"taskchef-header",component:"header",size:1080,children:g.jsxs(St,{className:"taskchef-header-layout",align:"stretch",justify:"space-between",wrap:"nowrap",children:[g.jsxs(ue,{className:"taskchef-header-copy",children:[g.jsxs(_e,{c:"var(--taskchef-accent)",fw:750,size:"xs",tt:"uppercase",children:["TaskChef ",w&&g.jsxs("span",{className:"taskchef-version",children:["v",w]})]}),g.jsxs(St,{gap:"sm",mt:5,wrap:"nowrap",children:[g.jsx(WN,{}),g.jsx(Wt,{order:1,size:"h2",children:"Dashboard"})]})]}),g.jsxs(Ut,{align:"flex-end",className:"taskchef-header-actions",gap:0,justify:"space-between",children:[g.jsxs(St,{"aria-live":"polite",className:"taskchef-connection",gap:7,role:"status",wrap:"nowrap",children:[g.jsx(B_,{"aria-hidden":!0,color:h?"var(--mantine-color-teal-6)":"var(--mantine-color-yellow-6)",size:9}),g.jsx(_e,{c:"dimmed",size:"xs",children:h?"Live":n?"Connecting…":"Fixture preview"})]}),g.jsxs(St,{className:"taskchef-header-icon-row",gap:2,justify:"flex-end",wrap:"nowrap",children:[g.jsx(Zn,{label:"Settings",children:g.jsx(ul,{className:"taskchef-icon-button",component:"a",href:"#settings","aria-label":"Settings","aria-current":o?"page":void 0,variant:"subtle",color:"gray",size:"lg",children:g.jsx(O_,{size:18,stroke:1.8})})}),g.jsx(PN,{})]})]})]})}),g.jsx(Yn.Main,{children:g.jsxs(mi,{className:"taskchef-main",pb:80,size:1080,children:[(d==null?void 0:d.status)==="unavailable"&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{size:18}),mb:"md",title:"Project index unavailable",children:"Task history is still visible. Verify the index and inspect backups before making project changes."}),(d==null?void 0:d.status)==="available"&&d.missingProjects.length>0&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{size:18}),mb:"md",title:"Historical projects are missing from the current index",children:d.missingProjects.map(me=>g.jsxs(_e,{size:"sm",children:[me.snapshotNames.join(", "),": ",me.taskCount," task(s). Run ",g.jsx("code",{children:"taskchef backup list --json"})," and preview any restore; the dashboard never restores automatically."]},me.path))}),o?g.jsxs(Ut,{gap:"md",children:[g.jsx(il,{component:"a",href:"#",variant:"subtle",size:"sm",leftSection:g.jsx(f_,{size:16}),style:{alignSelf:"flex-start"},children:"Back to tasks"}),g.jsx(X_,{})]}):g.jsxs(g.Fragment,{children:[g.jsx(gn,{className:"taskchef-toolbar",p:"sm",radius:"md",withBorder:!0,children:g.jsxs(Ut,{gap:"sm",children:[g.jsxs(St,{align:"end",gap:"sm",children:[g.jsx(Wo,{"aria-label":"Project",data:Oe,label:"Project",onChange:me=>C(me??""),size:"sm",value:T}),g.jsx(Wo,{"aria-label":"Updated",data:[{label:"Latest 24 hours",value:"24h"},{label:"Latest 7 days",value:"7d"},{label:"All time",value:"all"}],label:"Updated",onChange:me=>j(me??"all"),size:"sm",value:_})]}),g.jsxs(ue,{children:[g.jsx(_e,{className:"taskchef-filter-label",mb:5,children:"Status"}),g.jsx(tu,{"aria-label":"Status",data:Se,fullWidth:!0,onChange:N,size:"xs",value:A})]})]})}),g.jsx(FN,{totalCount:c.length,visibleCount:be.length}),y&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{"aria-hidden":!0,size:17}),mt:"md",role:"status",children:g.jsxs(St,{gap:"sm",justify:"space-between",wrap:"nowrap",children:[g.jsx(_e,{size:"sm",children:y}),g.jsx(Ja,{"aria-label":"Dismiss dashboard message",onClick:()=>v(null),size:"sm"})]})}),g.jsxs(Ut,{"aria-describedby":"task-results-summary","aria-label":"Tasks",component:"section",gap:"sm",mt:"xs",children:[be.map(me=>g.jsx(qN,{onOpenCodex:Ne,onOpenDetail:Me=>void ge(Me),task:me},me.id)),be.length===0&&g.jsxs(gn,{className:"taskchef-empty",p:48,ta:"center",withBorder:!0,children:[g.jsx(Wt,{order:2,size:"h4",children:"No tasks match these filters"}),g.jsx(_e,{c:"dimmed",mt:4,size:"sm",children:"Choose a different project, date, or status."})]})]})]})]})})]}),g.jsx(ZN,{busy:ae,error:J,highlightTurnRef:B,onClose:()=>{ae||(F.current+=1,le(!1),U(null))},onCopy:()=>{D&&(O(null),navigator.clipboard.writeText(D.id).then(()=>O("Task ID copied."),()=>O("Clipboard access is unavailable. Copy the Task ID from metadata.")))},onOpenCodex:()=>D&&void Ne(D),onTransition:st,opened:W,task:D,notice:ce,notifications:W?g.jsx(Ub,{announcements:Q.announcements,notifications:Q.notifications,onClear:()=>P(me=>({...me,notifications:Lb({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:me.notifications,refreshGeneration:F.current}).notifications})),onDismiss:me=>P(Me=>({...Me,notifications:$b(Me.notifications,me.id)})),onOpen:at,tasks:c,withinPortal:!1}):null}),!W&&g.jsx(Ub,{announcements:Q.announcements,notifications:Q.notifications,onClear:()=>P(me=>({...me,notifications:Lb({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:me.notifications,refreshGeneration:F.current}).notifications})),onDismiss:me=>P(Me=>({...Me,notifications:$b(Me.notifications,me.id)})),onOpen:at,tasks:c})]})})}function PN(){const{setColorScheme:n}=l0(),l=a0("light"),r=l==="dark"?"light":"dark";return g.jsx(Zn,{label:`Use ${r} theme`,children:g.jsx(ul,{"aria-label":`Use ${r} theme`,className:"taskchef-icon-button",color:"gray",onClick:()=>n(r),size:"lg",variant:"subtle",children:l==="dark"?g.jsx($_,{"aria-hidden":!0,size:18,stroke:1.8}):g.jsx(__,{"aria-hidden":!0,size:18,stroke:1.8})})})}function WN(){const n=a0("light");return g.jsx("img",{alt:"","aria-hidden":!0,className:"taskchef-brand-icon",height:"42",src:n==="dark"?"/assets/taskchef-dark.svg":"/assets/taskchef.svg",width:"42"})}B2.createRoot(document.getElementById("root")).render(g.jsx(x.StrictMode,{children:g.jsx(JN,{})}));
193
+ */const k_=[["path",{d:"M7 3.34a10 10 0 1 1 -4.995 8.984l-.005 -.324l.005 -.324a10 10 0 0 1 4.995 -8.336z",key:"svg-0"}]],B_=Mt("filled","circle-filled","CircleFilled",k_);function H_({onConnection:n,onError:l,onSnapshot:r}){const o=new EventSource("/api/events");return o.addEventListener("open",()=>n(!0)),o.addEventListener("error",()=>n(!1)),o.addEventListener("snapshot",s=>{n(!0),r(JSON.parse(s.data))}),o.addEventListener("dashboard-error",s=>{const c=JSON.parse(s.data);l(c.message??"The task log is temporarily unavailable.")}),o}async function Ai(n,l){const r=await fetch(n,l),o=await r.json().catch(()=>({}));if(!r.ok)throw Object.assign(new Error(o.message??"Request failed."),{payload:o});return o}async function U_(){return(await Ai("/api/health")).taskchefVersion}async function Y_(n,l,r){return Ai(`/api/settings/${encodeURIComponent(n)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schemaVersion:1,model:l,effort:r})})}async function q_(n){return(await Ai(`/api/tasks/${encodeURIComponent(n)}`)).task}async function V_(n){return(await Ai(`/api/tasks/${encodeURIComponent(n)}/open-codex`,{method:"POST"})).message??null}async function G_(n,l,r){const o=new AbortController,s=window.setTimeout(()=>o.abort(),1e4);try{return{ok:!0,task:(await Ai(`/api/tasks/${encodeURIComponent(n.id)}/manual-transition`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({schemaVersion:1,actionId:r,expected:{status:n.status,turnRef:n.turnRef,threadId:n.threadId,updatedAt:n.updatedAt},targetStatus:l}),signal:o.signal})).task}}catch(c){const f=c.payload;return{ok:!1,code:(f==null?void 0:f.code)??(o.signal.aborted?"request_timeout":"network_error"),message:(f==null?void 0:f.message)??(o.signal.aborted?"Task state change timed out. Try again.":"Task state changes are temporarily unavailable. Try again."),task:(f==null?void 0:f.task)??null}}finally{window.clearTimeout(s)}}function X_(){const[n,l]=x.useState([]),[r,o]=x.useState(null),[s,c]=x.useState(null),[f,d]=x.useState(!0),[p,h]=x.useState(null),[b,y]=x.useState(null),[v,w]=x.useState(0);x.useEffect(()=>{const C=new AbortController;return d(!0),c(null),fetch("/api/settings",{signal:C.signal}).then(async A=>{if(!A.ok)throw new Error("Settings preview could not be loaded.");const N=await A.json();l(N.profiles),o(N.usageProvider??null)}).catch(A=>{C.signal.aborted||c(A.message)}).finally(()=>{C.signal.aborted||d(!1)}),()=>C.abort()},[v]),x.useEffect(()=>{if(y(null),!p)return;const C=window.setTimeout(()=>y(p),400);return()=>window.clearTimeout(C)},[p]);const R=n.find(C=>C.id==="personal"),T=async(C,A,N)=>{h(C.role),c(null),l(_=>_.map(j=>j.id!=="personal"?j:{...j,roles:j.roles.map($=>$.role===C.role?{...$,model:A,effort:N}:$)}));try{const _=await Y_(C.role,A,N);l([_.profile])}catch(_){l(j=>j.map($=>$.id!=="personal"?$:{...$,roles:$.roles.map(L=>L.role===C.role?C:L)})),c(_ instanceof Error?_.message:"Model role could not be saved.")}finally{h(null)}};return g.jsxs(Ut,{gap:"md","aria-label":"Model settings",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:2,size:"h3",children:"Model roles"}),g.jsx(ul,{"aria-label":"Refresh","aria-busy":f,"aria-disabled":f||p!==null,className:"taskchef-icon-button",color:"gray",variant:"subtle",size:"lg",onClick:()=>{f||p||(d(!0),w(C=>C+1))},children:g.jsx(M_,{className:f?"taskchef-refresh-spinning":void 0,size:18,stroke:1.8})})]}),g.jsx(_e,{c:"dimmed",size:"sm",children:"Your models for orchestration, planning, implementation, and review."}),s&&g.jsx(Mn,{color:"red",role:"alert",children:s}),R&&g.jsxs(g.Fragment,{children:[R.problems.map(C=>g.jsx(Mn,{color:"yellow",children:C},C)),R.roles.map(C=>{var A,N;return g.jsx(gn,{withBorder:!0,p:"md",children:g.jsxs(Ut,{gap:"xs",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:3,size:"h4",tt:"capitalize",children:C.role}),g.jsx(Jo,{color:["invalid","unavailable"].includes(C.status)?"red":C.status==="missing"?"gray":"teal",children:C.status})]}),g.jsxs($p,{cols:{base:1,sm:2},children:[g.jsx(Wo,{label:"Model","aria-label":`${C.role} model`,"aria-busy":f||p!==null,data:R.modelOptions??[],value:typeof C.model=="string"?C.model:null,readOnly:f||p!==null,allowDeselect:!1,searchable:!0,onChange:_=>{var L;if(f||p||!_)return;const j=(L=R.modelOptions)==null?void 0:L.find(D=>D.value===_),$=typeof C.effort=="string"&&(j!=null&&j.efforts.includes(C.effort))?C.effort:j==null?void 0:j.efforts[0];$&&T(C,_,$)}}),g.jsx(Wo,{label:"Reasoning effort","aria-label":`${C.role} reasoning effort`,"aria-busy":f||p!==null,data:(((N=(A=R.modelOptions)==null?void 0:A.find(_=>_.value===C.model))==null?void 0:N.efforts)??[]).map(_=>({value:_,label:_})),value:typeof C.effort=="string"?C.effort:null,disabled:typeof C.model!="string",readOnly:f||p!==null,allowDeselect:!1,onChange:_=>{!f&&!p&&_&&typeof C.model=="string"&&T(C,C.model,_)}})]}),g.jsxs(_e,{size:"sm",style:{overflowWrap:"anywhere"},children:["Source: ",C.displaySource??C.source??"No role file"]}),b===C.role&&g.jsx(_e,{c:"dimmed",size:"sm",role:"status",children:"Saving…"}),C.problems.map(_=>g.jsx(Mn,{color:"red",children:_},_))]})},C.role)})]}),r&&g.jsx(gn,{withBorder:!0,p:"md",children:g.jsxs(Ut,{gap:"xs",children:[g.jsxs(St,{justify:"space-between",children:[g.jsx(Wt,{order:3,size:"h4",children:"Usage provider"}),g.jsx(Jo,{color:r.status==="available"?"teal":"red",children:r.status})]}),g.jsxs(_e,{children:[r.provider,r.version?` ${r.version}`:" version unavailable"]}),g.jsx(_e,{c:"dimmed",size:"sm",children:"Version reported by the executable TaskChef uses for token and cost estimates."})]})})]})}const I_=50,Z_="Turn interrupted before a terminal report.",ZS=[{value:"",label:"All"},{value:"working",label:"Working"},{value:"needs input",label:"Needs input"},{value:"completed",label:"Completed"},{value:"failed",label:"Failed"}],Q_=new Map([["created","Task created"],["task_started","Task started"],["follow_up_started","Follow-up started"],["completed","Task completed"],["needs_input","Task needs input"],["failed","Task failed"],["manual_completed","Task manually completed"],["manual_failed","Task manually failed"],["archive_succeeded","Chat archived"],["archive_failed","Chat archive failed"],["unresolved","Task updated"]]),K_=new Map([["24h",1440*60*1e3],["7d",10080*60*1e3],["all",null]]);function F_(n){return Date.parse(n.meaningfulUpdatedAt??n.updatedAt??n.createdAt)}function QS(n){return n.status===null?"unresolved":n.status.replaceAll("_"," ")}function J_(n){return{status:n.status,turnRef:n.turnRef,threadId:n.threadId,updatedAt:n.updatedAt}}function P_(n,l){return!!l&&n.status===l.status&&n.turnRef===l.turnRef&&n.threadId===l.threadId&&n.updatedAt===l.updatedAt}function Db({requestTask:n,expected:l,responseTask:r,selectedTask:o}){const s=(o==null?void 0:o.id)===n.id?o:n;return P_(s,l)?r??s:s}function W_(n){var s;const l=n.latestTurn??null,r=(l==null?void 0:l.result)??null,o=(l==null?void 0:l.requestSummary)??(l?"Request not recorded by this TaskChef version.":n.title);return{turnRef:(l==null?void 0:l.turnRef)??(l==null?void 0:l.turnId)??n.turnRef??n.turnId??null,turnId:(l==null?void 0:l.turnId)??n.turnId??null,startedAt:(l==null?void 0:l.startedAt)??n.updatedAt??n.createdAt??null,requestSummary:o,resultStatus:(r==null?void 0:r.status)??(n.status==="working"?"working":n.status),resultSummary:(r==null?void 0:r.summary)??(n.status==="working"?"In progress":((s=n.lastResult)==null?void 0:s.summary)??n.summary??"No result reported."),resultUpdatedAt:(r==null?void 0:r.updatedAt)??null}}function eN(n){var r;const l=n.result??null;return{status:(l==null?void 0:l.status)??"working",summary:(l==null?void 0:l.summary)??"In progress",updatedAt:(l==null?void 0:l.updatedAt)??n.startedAt,...((r=n.provenance)==null?void 0:r.kind)==="dashboard_manual"?{sourceLabel:"Manual dashboard change"}:{}}}function tN(n,l=[]){if(Array.isArray(n.turns))return n.turns;if(!n.latestTurn)return l;const r=[...l],o=r.length-1,s=n.latestTurn.turnRef??n.latestTurn.turnId,c=o>=0?r[o].turnRef??r[o].turnId:null,f=o>=0&&c===null&&s!==null&&r[o].turnId==null&&n.latestTurn.turnId==null&&JSON.stringify({...r[o],turnRef:null})===JSON.stringify({...n.latestTurn,turnRef:null});return o>=0&&(c===s||f)?r[o]=n.latestTurn:(n.schemaVersion>=8&&o>=0&&r[o].result===null&&(r[o]={...r[o],result:{status:"interrupted",summary:Z_,updatedAt:n.latestTurn.startedAt}}),r.push(n.latestTurn)),r}function nu(n){return Q_.get(n.event)??"Task updated"}function nN(n,l,r=Date.now()){const o=K_.get(l);if(o===null)return!0;if(o===void 0)return!1;const s=F_(n);return Number.isFinite(s)&&s>=r-o}function KS(n,{project:l="",status:r="",date:o="all",now:s=Date.now()}={}){return n.filter(c=>(!l||c.project.name===l)&&(!r||QS(c)===r)&&nN(c,o,s))}function lN(n,{project:l="",date:r="all",now:o=Date.now()}={}){const s=KS(n,{project:l,date:r,now:o});return Object.fromEntries(ZS.map(({value:c})=>[c,c?s.filter(f=>QS(f)===c).length:s.length]))}function aN(n){return JSON.stringify([n.id,n.turnRef??n.turnId??null,n.turnId??null,n.status??"unresolved"])}function oN(n,l){try{const r=JSON.parse(n),o=JSON.parse(l);return Array.isArray(r)&&Array.isArray(o)&&r.length===o.length&&r[1]===null&&o[1]!==null&&r[2]===null&&o[2]===null&&r[3]!=="working"&&r.every((s,c)=>c===1||s===o[c])}catch{return!1}}function rN(n){var l,r;return n.status==="working"?n.lastResult?"follow_up_started":"task_started":((r=(l=n.latestTurn)==null?void 0:l.provenance)==null?void 0:r.kind)==="dashboard_manual"?`manual_${n.status}`:n.status??"unresolved"}function FS(n,l){return JSON.stringify(l==="created"?[n.id,null,l,n.createdAt??null]:[n.id,n.turnRef??n.turnId??null,l])}function iN(n,l){var r,o,s;return l==="created"?n.createdAt??n.updatedAt??null:((r=n.lastResult)==null?void 0:r.status)===n.status&&(((o=n.lastResult)==null?void 0:o.turnRef)??((s=n.lastResult)==null?void 0:s.turnId))===(n.turnRef??n.turnId)?n.lastResult.updatedAt:n.updatedAt??n.createdAt??null}function sN(n,l){var r,o,s;return["completed","needs_input","failed","manual_completed","manual_failed"].includes(l)?((r=n.lastResult)==null?void 0:r.status)===n.status&&(((o=n.lastResult)==null?void 0:o.turnRef)??((s=n.lastResult)==null?void 0:s.turnId))===(n.turnRef??n.turnId)?n.lastResult.summary:n.summary??null:null}function qo(n,l=rN(n)){const r=l==="created";return Object.freeze({id:FS(n,l),taskId:n.id,title:n.title,status:r?"working":n.status,event:l,turnRef:r?null:n.turnRef??n.turnId??null,turnId:r?null:n.turnId??null,timestamp:iN(n,l),summary:sN(n,l)})}function Ks(n){var o;const l=n.lastResult;if(!l)return null;const r=((o=l.provenance)==null?void 0:o.kind)==="dashboard_manual"?`manual_${l.status}`:l.status;return Object.freeze({id:FS({...n,turnRef:l.turnRef??l.turnId,turnId:l.turnId},r),taskId:n.id,title:n.title,status:l.status,event:r,turnRef:l.turnRef??l.turnId??null,turnId:l.turnId??null,timestamp:l.updatedAt,summary:l.summary})}function cN(n,l){return`${l?"Open current task details":"Show task availability"} for ${n.title}: ${nu(n)}`}function uN(n){return`Dismiss ${nu(n)} notification for ${n.title}`}function $b(n,l){return n.filter(({id:r})=>r!==l)}function fN({initialized:n,notifications:l,seenIds:r=new Set,signatures:o},s){const c=new Map(o);for(const p of s)c.set(p.id,aN(p));const f=new Set(r);if(!n){for(const p of s){f.add(qo(p,"created").id);const h=Ks(p);h&&f.add(h.id),f.add(qo(p).id)}return{additions:[],notifications:l,seenIds:f,signatures:c}}const d=[];for(const p of s){const h=[];if(o.has(p.id)){if(o.get(p.id)!==c.get(p.id)&&!oN(o.get(p.id),c.get(p.id))){h.push(qo(p));const y=Ks(p);y&&h.push(y)}}else{const y=Ks(p);(p.turnRef||p.turnId||p.status!=="working"||y)&&(h.push(qo(p)),y&&h.push(y)),h.push(qo(p,"created"))}for(const y of h)f.has(y.id)||d.push(y),f.add(y.id);const b=Ks(p);b&&f.add(b.id),f.add(qo(p).id)}return{additions:d,notifications:[...d,...l].slice(0,I_),seenIds:f,signatures:c}}function dN(n,l,r){const o=n.notifications.filter(({id:s})=>s!==l.id);return r?{...n,detailTaskId:l.taskId,detailOpened:!0,highlightTurnRef:l.turnRef??l.turnId,notifications:o,refreshGeneration:n.refreshGeneration+1}:{...n,notifications:o}}function Lb(n){return{...n,notifications:[]}}function kb(n,l){const r=Array.isArray(n.turns)&&Array.isArray(n.results),o=!Array.isArray(l.turns)&&!Array.isArray(l.results);return{...n,...l,...r&&o?{results:n.results,turns:n.turns,usage:n.usage}:{}}}function Fs(n){var l,r,o,s,c,f,d;return JSON.stringify([((l=n==null?void 0:n.usage)==null?void 0:l.generationTurnRef)??null,((r=n==null?void 0:n.usage)==null?void 0:r.status)??null,((o=n==null?void 0:n.usage)==null?void 0:o.updatedAt)??null,((c=(s=n==null?void 0:n.usage)==null?void 0:s.task)==null?void 0:c.totalTokens)??null,((d=(f=n==null?void 0:n.usage)==null?void 0:f.task)==null?void 0:d.estimatedCostUsd)??null])}const mN=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,3}))?(Z|[+-]\d{2}:\d{2})$/;function JS(n,l){const r=Bb(n),o=Bb(l);if(r===null||o===null)return null;const s=o-r;return s>=0?s:null}function PS(n){var r;const l=JS(n.startedAt,(r=n.result)==null?void 0:r.updatedAt);return l===0?null:l}function pN(n){const l=n.filter(s=>s.result!==null),r=l.map(PS).filter(s=>s!==null),o=r.length===0?l.length===0?0:null:r.reduce((s,c)=>s+c,0);return Object.freeze({terminalTurns:l.length,validTurns:r.length,totalMilliseconds:o===null||Number.isSafeInteger(o)?o:null})}function Bb(n){if(typeof n!="string")return null;const l=n.match(mN);if(!l)return null;const[,r,o,s,c,f,d,,p]=l,h=Number(r),b=Number(o),y=Number(s),v=Number(c),w=Number(f),R=Number(d),T=p==="Z"?0:Number(p.slice(1,3)),C=p==="Z"?0:Number(p.slice(4,6)),N=[31,h%4===0&&(h%100!==0||h%400===0)?29:28,31,30,31,30,31,31,30,31,30,31];if(b<1||b>12||y<1||y>N[b-1]||v>23||w>59||R>59||T>23||C>59)return null;const _=Date.parse(n);return Number.isFinite(_)?_:null}const hm=1e3,vm=60*hm,gm=60*vm,hN=24*gm,vn="n/a";function WS(n){if(!Number.isFinite(n)||n<0)return null;if(n>0&&n<hm)return"<1s";const l=Math.floor(n/hm);if(n<vm)return`${l}s`;if(n<gm)return`${Math.floor(l/60)}m ${l%60}s`;const r=Math.floor(n/vm);if(n<hN)return`${Math.floor(r/60)}h ${r%60}m`;const o=Math.floor(n/gm);return`${Math.floor(o/24)}d ${o%24}h`}function ex(n){const l=n.turns===void 0?n.reportedWork:pN(n.turns??[]);if(l===void 0)return{accessibleLabel:"Reported work unavailable because terminal turn history is not available.",kind:"unavailable",title:"Reported wall-clock elapsed time requires the terminal turn history from the task detail projection.",value:vn};if(l.terminalTurns===0)return{accessibleLabel:"Reported work not yet reported. Unfinished turns are excluded.",kind:"not-reported",title:"Reported wall-clock elapsed time is added only after a turn reaches a terminal state.",value:vn};if(l.validTurns===0)return{accessibleLabel:"Reported work unavailable because completed turn timestamps are missing or invalid.",kind:"unavailable",title:"Reported wall-clock elapsed time is unavailable because no terminal turn has a valid start and end timestamp.",value:vn};const r=l.totalMilliseconds===null?null:WS(l.totalMilliseconds);if(r===null)return{accessibleLabel:"Reported work unavailable because the duration total is outside the supported range.",kind:"unavailable",title:"Reported wall-clock elapsed time is unavailable because the duration total is outside the supported range.",value:vn};const o=l.terminalTurns-l.validTurns,s=o>0?` ${o} terminal ${o===1?"turn was":"turns were"} unavailable and excluded.`:"";return{accessibleLabel:`Reported work ${r}. This is reported wall-clock elapsed time.${s}`,kind:"available",title:`Sum of valid terminal-turn wall-clock elapsed times; unfinished turns and idle gaps are excluded.${s}`,value:r}}function vN(n,l=Date.now()){const r=n.result===null,o=r?JS(n.startedAt,new Date(l).toISOString()):PS(n),s=r?"Elapsed so far":"Elapsed",c=o===null?vn:WS(o)??vn;return{accessibleLabel:`${s} ${o===null?"unavailable":c}. ${r?"Current":"Completed"} turn reported wall-clock elapsed time.`,kind:o===null?"unavailable":"available",label:s,title:o===null?"Reported wall-clock elapsed time is unavailable because the turn timestamps are missing, invalid, or reversed.":`Reported wall-clock elapsed time from startedAt ${r?"to the current time":"to result.updatedAt"}.`,value:c}}function lu(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2,notation:"compact"}).format(n)}function pi(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2}).format(n)}function er(n,l){return typeof n!="number"||!Number.isFinite(n)?"—":new Intl.NumberFormat(l,{currency:"USD",currencyDisplay:"narrowSymbol",maximumFractionDigits:2,minimumFractionDigits:2,style:"currency"}).format(n)}function tx(n,l){return new Intl.NumberFormat(l,{maximumFractionDigits:2,minimumFractionDigits:2}).format(n)}function nx(n){var s;const l=n.usage,r=n.turnRef??((s=n.latestTurn)==null?void 0:s.turnRef)??null,o=(l==null?void 0:l.generationTurnRef)!=null&&r!=null&&l.generationTurnRef!==r;return n.status==="working"?l!=null&&l.task?Qd(l.task,!0):{kind:"pending",label:"Token usage pending"}:(l==null?void 0:l.status)==="calculating"||o?l.task?Qd(l.task,!0):{kind:"calculating",label:"Calculating token usage"}:(l==null?void 0:l.status)==="available"&&l.task?Qd(l.task,!1):!l&&n.threadId&&["completed","failed","needs_input"].includes(n.status??"")?{kind:"calculating",label:"Calculating token usage"}:{kind:"unavailable",label:(l==null?void 0:l.reason)??"Token usage unavailable"}}function Qd(n,l){const r=lu(n.totalTokens),o=n.estimatedCostUsd==null?"Estimated cost n/a":`Estimated cost ${er(n.estimatedCostUsd)}`;return{kind:"ready",knownSoFar:l,label:`${r} tokens · ${o}${l?" · known so far":""}`,usage:n}}function gN(n,l){var s,c;if(l.result===null)return{kind:"pending",label:"Turn usage pending"};const r=l.turnRef??l.turnId,o=r?(c=(s=n.usage)==null?void 0:s.turns)==null?void 0:c[r]:null;if((o==null?void 0:o.status)==="calculating")return{kind:"calculating",label:"Calculating turn usage"};if((o==null?void 0:o.status)==="available"&&typeof o.totalTokens=="number"){const f=pi(o.totalTokens),d=o.estimatedCostUsd==null?"Estimated cost n/a":`Estimated cost ${er(o.estimatedCostUsd)}`;return{kind:"ready",label:`${f} tokens · ${d}`}}return{kind:"unavailable",label:(o==null?void 0:o.reason)??"Turn usage unavailable"}}function yN(n,l){var c,f;const r=gN(n,l);if(r.kind==="ready"){const d=l.turnRef??l.turnId,p=d?(f=(c=n.usage)==null?void 0:c.turns)==null?void 0:f[d]:null,h=typeof(p==null?void 0:p.totalTokens)=="number"?pi(p.totalTokens):vn,b=typeof(p==null?void 0:p.totalTokens)=="number"?lu(p.totalTokens):vn,y=p==null?void 0:p.estimatedCostUsd,v=typeof y=="number"&&Number.isFinite(y),w=v?tx(y):vn;return{animated:!1,cost:{accessibleLabel:`Estimated cost ${v?er(y).toLowerCase():"unavailable"}`,value:w},kind:r.kind,note:null,title:r.label,tokens:{accessibleLabel:`${h} tokens`,value:b}}}const o=r.kind==="pending"?"Pending":r.kind==="calculating"?"Calculating":vn,s=r.kind==="unavailable"?"unavailable":o.toLowerCase();return{animated:r.kind==="pending"||r.kind==="calculating",cost:{accessibleLabel:`Estimated cost ${s}${r.kind==="unavailable"?`: ${r.label}`:""}`,value:o},kind:r.kind,note:r.kind==="unavailable"&&r.label!=="Turn usage unavailable"?r.label:null,title:r.label,tokens:{accessibleLabel:`Tokens ${s}${r.kind==="unavailable"?`: ${r.label}`:""}`,value:o}}}function bN(n){var l,r;return n.status!=="working"&&(((l=n.usage)==null?void 0:l.status)==="calculating"||Object.values(((r=n.usage)==null?void 0:r.turns)??{}).some(o=>o.status==="calculating"))}function SN(n){var R;const l=nx(n);if(l.kind==="pending"||l.kind==="calculating"){const T=l.kind==="pending"?"Pending":"Calculating";return{cost:{accessibleLabel:`Estimated cost ${T.toLowerCase()}`,animated:!0,title:l.label,value:T},kind:l.kind,tokens:{accessibleLabel:`Tokens ${T.toLowerCase()}`,animated:!0,title:l.label,value:T}}}if(l.kind==="unavailable"){const T=l.label==="Token usage unavailable"?"":`: ${l.label}`;return{cost:{accessibleLabel:`Estimated cost unavailable${T}`,animated:!1,title:l.label,value:vn},kind:"unavailable",tokens:{accessibleLabel:`Token usage unavailable${T}`,animated:!1,title:l.label,value:`${vn} tokens`}}}const r=lu(l.usage.totalTokens),o=pi(l.usage.totalTokens),s=l.usage.estimatedCostUsd,c=typeof s=="number"&&Number.isFinite(s),f=c?er(s):null,d=c?tx(s):null,p=l.knownSoFar?" · Updating…":"",h=l.knownSoFar?"; updating":"",b=c?p:"",y=c?h:"",v=l.usage.sourceUpdatedAt??l.usage.sampledAt??((R=n.usage)==null?void 0:R.updatedAt)??null,w=v&&!Number.isNaN(Date.parse(v))?` Cached usage updated ${new Date(v).toLocaleString()}.`:"";return{cost:{accessibleLabel:`Estimated cost ${f??"unavailable"}${y}.${w}`,animated:l.knownSoFar&&c,title:`${f===null?"Estimated cost unavailable":`Unrounded estimate: $${l.usage.estimatedCostUsd}`}${b}.${w}`,value:d??vn},kind:"ready",tokens:{accessibleLabel:`${o} tokens${h}.${w}`,animated:l.knownSoFar,title:`${o} tokens${p}.${w}`,value:`${r} tokens`}}}function xN(n){return n==="completed"?"teal":n==="needs_input"?"yellow":n==="failed"?"red":n==="working"?"blue":"gray"}function wN(n){return n===null?"Unresolved":n.replaceAll("_"," ")}const Kd=30,oi=6e4,fc=60*oi,Ga=24*fc;function lx(n){if(typeof n!="string"||n.trim()==="")return null;const l=Date.parse(n);return Number.isFinite(l)?{date:new Date(l),iso:new Date(l).toISOString(),milliseconds:l}:null}function Hb(n,{locale:l,timeZone:r}={}){const o=lx(n);return o?new Intl.DateTimeFormat(l,{dateStyle:"medium",timeStyle:"short",timeZone:r}).format(o.date):"—"}function CN(n,l){const r=Math.floor(n/fc),o=r===1?"1 hour":`${r} hours`;return l==="future"?`in ${o}`:`${o} ago`}function Lp(n,{now:l=Date.now(),locale:r,timeZone:o}={}){const s=lx(n);if(!s)return"—";const c=l-s.milliseconds,f=c<0,d=Math.abs(c);if(d<oi)return"just now";if(d<2*oi)return f?"in 1 minute":"1 minute ago";if(d<fc){const b=f?Math.ceil(d/oi):Math.floor(d/oi);return f?`in ${b} minutes`:`${b} minutes ago`}if(d<2*fc)return f?"in 1 hour":"1 hour ago";if(d<Ga)return CN(d,f?"future":"past");if(d<2*Ga)return f?"in 1 day":"1 day ago";if(d<Kd*Ga){const b=f?Math.ceil(d/Ga):Math.floor(d/Ga);return f?`in ${b} days`:`${b} days ago`}const p=f?Math.ceil(d/(Kd*Ga)):Math.floor(d/(Kd*Ga)),h=p===1?"1 month":`${p} months`;return f?`in ${h}`:`${h} ago`}function au({status:n}){return g.jsx(Jo,{className:"taskchef-status-badge",color:xN(n),size:"sm",variant:"light",children:wN(n)})}function Ub({notifications:n,announcements:l=n,onClear:r,onDismiss:o,onOpen:s,tasks:c,withinPortal:f=!0}){if(n.length===0)return null;const d=g.jsxs(g.Fragment,{children:[g.jsxs(gn,{"aria-label":"Task notifications",className:"taskchef-notifications",p:"sm",radius:"md",role:"region",shadow:"xl",withBorder:!0,children:[g.jsxs(St,{justify:"space-between",mb:"xs",children:[g.jsxs(St,{gap:6,children:[g.jsx(m_,{"aria-hidden":!0,size:16}),g.jsx(_e,{fw:700,size:"sm",children:"Updates"})]}),g.jsx(il,{onClick:r,size:"compact-xs",variant:"subtle",children:"Clear all"})]}),g.jsx(Un.Autosize,{className:"taskchef-notification-scroll",mah:"min(55vh, 520px)",type:"auto",children:g.jsx(Ut,{className:"taskchef-notification-list",gap:6,children:n.map(p=>{const h=c.some(w=>w.id===p.taskId),b=`notification-${Math.abs(RN(p.id))}`,y=`${b}-summary`,v=`${b}-metadata`;return g.jsx(gn,{className:"taskchef-notification",p:"xs",radius:"sm",children:g.jsxs(St,{align:"flex-start",gap:"xs",wrap:"nowrap",children:[g.jsxs("button",{"aria-describedby":[p.summary?y:null,v].filter(Boolean).join(" "),"aria-label":cN(p,h),className:"taskchef-notification-open",onClick:()=>s(p),type:"button",children:[g.jsxs(St,{gap:"xs",justify:"space-between",wrap:"nowrap",children:[g.jsx(_e,{fw:700,size:"sm",children:nu(p)}),g.jsx(au,{status:p.status})]}),g.jsx(_e,{lineClamp:1,size:"sm",children:p.title}),p.summary&&g.jsx(_e,{className:"taskchef-preserve-lines",id:y,lineClamp:3,size:"xs",children:p.summary}),g.jsxs(_e,{c:"dimmed",id:v,size:"xs",children:[Lp(p.timestamp),h?"":" · Task no longer available"]})]}),g.jsx(Zn,{label:"Dismiss notification",children:g.jsx(ul,{"aria-label":uN(p),color:"gray",onClick:()=>o(p),size:"compact-sm",variant:"subtle",children:g.jsx(IS,{"aria-hidden":!0,size:14})})})]})},p.id)})})})]}),g.jsx(ue,{"aria-atomic":"true","aria-live":"polite",className:"taskchef-visually-hidden",role:"status",children:l.map(TN).join(" ")})]});return f?g.jsx(ep,{children:d}):d}function TN(n){return[nu(n),n.title,n.summary,n.turnRef?`Turn ref ${n.turnRef}`:null,Lp(n.timestamp)].filter(Boolean).map(l=>String(l).replace(/[.\s]+$/,"")).join(". ")+"."}function RN(n){let l=0;for(const r of n)l=(l<<5)-l+r.charCodeAt(0)|0;return l}const EN=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]+$/,AN=/https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9._-]+)\/(issues|pull)\/([1-9]\d*)(?![A-Za-z0-9_])|([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9._-]+)#([1-9]\d*)(?![A-Za-z0-9_])|#([1-9]\d*)(?![A-Za-z0-9_])|https?:\/\/(?:www\.)?github\.com\/([A-Za-z0-9](?:[A-Za-z0-9-]{0,38}))\/([A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9_-])?)\/?(?=$|[\s#),.;:!?'"\]}>])/gi,_N=/https?:\/\/[^\s<>"'`]+/gi;function Qo(n){return!(n!=null&&n.owner)||!(n!=null&&n.repository)?null:`${n.owner.toLowerCase()}/${n.repository.toLowerCase()}`}function ax(n){const l=new Map;for(const r of n){const o=Qo(r);if(!o)continue;const s=r.repository.toLowerCase(),c=l.get(s)??new Set;c.add(o),l.set(s,c)}return new Set([...l].filter(([,r])=>r.size>1).map(([r])=>r))}function ym(n,l){return l.has(n.repository.toLowerCase())?`${n.owner}/${n.repository}`:n.repository}function ox(n,{related:l=!1}={}){const r=ax(n);let o=null;return n.map(s=>{if(s.provider!=="github"&&!s.owner)return s.label??s.text;const c=Qo(s),f=ym(s,r);if(s.type==="repository")return f;if(l){const d=c===o?`#${s.number}`:`${f} #${s.number}`;return o=c,d}return s.type==="pull"?`${f} PR #${s.number}`:s.type==="issue"?`${f} Issue #${s.number}`:`${f} #${s.number}`})}function NN(n,l){const r=String(n.number??""),o=String(l.number??"");return r.length-o.length||r.localeCompare(o)}function MN(n){const l=new Map,r=new Set,o=new Set,s=new Set;for(const f of n??[]){const d=Qo(f),p=f.number?`${d}#${f.number}`:null;if(f.type==="repository"||!d||r.has(f.label)||s.has(f.url)||p&&o.has(p))continue;r.add(f.label),s.add(f.url),p&&o.add(p);const h=l.get(d)??[];h.push(f),l.set(d,h)}const c=ax(n??[]);return[...l.values()].map(f=>[...f].sort(NN)).sort((f,d)=>{const p=ym(f[0],c),h=ym(d[0],c);return p.localeCompare(h,void 0,{sensitivity:"base"})||Qo(f[0]).localeCompare(Qo(d[0]))})}function rx(n){const l=Qo(n);return l?n.type==="repository"?l:n.type==="pull"?`${l} PR #${n.number}`:n.type==="issue"?`${l} Issue #${n.number}`:`${l} #${n.number}`:n.label??n.text}function ix(n,l){return`${n.toLowerCase()}/${l.toLowerCase()}`}function sx(n){return n!=="."&&n!==".."}function cx(n){if(typeof n!="string")return null;let l=n.trim();const r=l.match(/^https?:\/\/(?:www\.)?github\.com\/([^/?#]+)\/([^/?#]+?)(?:\.git)?\/?$/i);if(r&&(l=`${r[1]}/${r[2]}`),!EN.test(l))return null;const[o,s]=l.split("/");return sx(s)?ix(o,s):null}function jN(n){var s;const l=String(n??""),r=ux(l),o=[];for(const c of l.matchAll(AN)){const f=c.index,d=f>0?l[f-1]:"";let p=null;const h=r.find(C=>f>=C.start&&f<C.end);if(h){const C=!!(c[1]||c[9]);let A=null;try{A=new URL(h.text).hostname.toLowerCase()}catch{}if(!(C&&f===h.start&&(A==="github.com"||A==="www.github.com"))||!fx(h.text))continue;p={end:h.end,suffix:h.text.slice(c[0].length),text:h.text}}if(c[8]&&/[\w&#/]/.test(d)||(c[5]||c[1]||c[9])&&/[\w/]/.test(d))continue;let b=c[1]??c[5]??c[9]??null,y=c[2]??c[6]??c[10]??null;c[9]&&(y=y.replace(/\.git$/i,""));const v=c[4]??c[7]??c[8]??null,w=(s=c[3])==null?void 0:s.toLowerCase(),R=c[9]?"repository":w==="pull"?"pull":w==="issues"?"issue":"generic",T=!!(b&&y);if(T){if(!sx(y))continue;[b,y]=ix(b,y).split("/")}o.push({end:(p==null?void 0:p.end)??f+c[0].length,explicit:T,number:v,owner:b,repository:y,start:f,text:(p==null?void 0:p.text)??c[0],type:R,urlSuffix:(p==null?void 0:p.suffix)??""})}return o}function ON(n){const l=new Set(n.filter(({explicit:r})=>r).map(({owner:r,repository:o})=>`${r}/${o}`));return l.size===1?[...l][0]:null}function zN(n){const l=new Set((n??[]).map(cx).filter(Boolean));return l.size===1?[...l][0]:null}function DN(n,l){const r=n.explicit?`${n.owner}/${n.repository}`:l;if(!r)return null;const[o,s]=r.split("/");if(n.type==="repository")return{kind:"link",label:`${o}/${s}`,number:null,owner:o,provider:"github",repository:s,text:n.text,type:n.type,url:`https://github.com/${o}/${s}${n.urlSuffix}`};const c=n.type==="pull"?"pull":"issues";return{kind:"link",label:`${o}/${s}#${n.number}`,number:n.number,owner:o,provider:"github",repository:s,text:n.text,type:n.type,url:`https://github.com/${o}/${s}/${c}/${n.number}${n.urlSuffix}`}}function $N(n){let l=n,r;do{r=l,l=l.replace(/[.,;:!?]+$/u,"");for(const[o,s]of[["(",")"],["[","]"],["{","}"]])for(;l.endsWith(s);){const c=[...l].filter(d=>d===o).length;if([...l].filter(d=>d===s).length<=c)break;l=l.slice(0,-1)}}while(l!==r);return l}function ux(n){const l=[];for(const r of String(n??"").matchAll(_N)){const o=$N(r[0]);o&&l.push({end:r.index+o.length,start:r.index,text:o})}return l}function LN(n){const l=n.slice(n.indexOf("//")+2).split(/[?#]/u,1)[0],r=l.indexOf("/");return r<0?!1:l.slice(r).split("/").some(o=>{try{const s=decodeURIComponent(o);return s==="."||s===".."}catch{return!0}})}function fx(n){try{const l=new URL(n);return!l.hostname||l.username||l.password||n.includes("\\")||LN(n)?null:l.href}catch{return null}}function kN(n){const l=[];for(const r of ux(n)){const o=fx(r.text);o&&l.push({end:r.end,kind:"link",label:r.text,provider:"web",start:r.start,text:r.text,type:"url",url:o})}return l}function BN(n,{projectRepositories:l=[],taskRepository:r=null}={}){const o=String(n??""),s=jN(o),f=ON(s)??cx(r)??zN(l),d=[];let p=0;for(const h of s){h.start>p&&d.push({kind:"text",text:o.slice(p,h.start)});const b=DN(h,f);b?d.push(b):d.push({kind:"ambiguous",reason:`GitHub reference ${h.text} is not linked because the repository is ambiguous.`,text:h.text}),p=h.end}return p<o.length&&d.push({kind:"text",text:o.slice(p)}),d}function HN(n,l={}){const r=String(n??""),o=BN(r,l),s=[];let c=0;for(const h of o){const b=r.indexOf(h.text,c);b<0||(h.kind!=="text"&&s.push({end:b+h.text.length,segment:h,start:b}),c=b+h.text.length)}const f=kN(r).filter(h=>!s.some(({end:b,start:y})=>h.start<b&&h.end>y));if(f.length===0)return o;s.push(...f.map(h=>({end:h.end,segment:h,start:h.start}))),s.sort((h,b)=>h.start-b.start);const d=[];let p=0;for(const h of s)h.start<p||(h.start>p&&d.push({kind:"text",text:r.slice(p,h.start)}),d.push(h.segment),p=h.end);return p<r.length&&d.push({kind:"text",text:r.slice(p)}),d}function dx({task:n}){const l=n.relatedGitHubLinks??[];if(l.length===0&&!n.relatedGitHubLinksTruncated)return null;const r=MN(l),o=ox(r.flat(),{related:!0});let s=0;return g.jsxs(ue,{"aria-label":`Related GitHub links for ${n.title}`,className:"taskchef-github-groups",component:"nav",children:[r.map(c=>g.jsx(St,{className:"taskchef-github-group",gap:5,wrap:"wrap",children:c.map(f=>{const d=o[s];s+=1;const p=f.type==="pull"?", GitHub pull request":f.type==="issue"?", GitHub issue":" on GitHub";return g.jsx(Lc,{"aria-label":`${rx(f)}${p} (opens in a new tab)`,className:"taskchef-github-link",href:f.url,rel:"noopener noreferrer",size:"xs",target:"_blank",children:d},f.url)})},`${c[0].owner}/${c[0].repository}`)),n.relatedGitHubLinksTruncated&&g.jsx(_e,{c:"dimmed",size:"xs",children:"More links in task history"})]})}function dc({task:n,text:l}){const r=HN(l,{projectRepositories:n.project.githubRepos,taskRepository:n.relatedGitHubRepository}),o=r.filter(f=>f.kind==="link"),s=ox(o);let c=0;return r.map((f,d)=>{if(f.kind==="text")return f.text;if(f.kind==="ambiguous")return g.jsx("span",{"aria-label":f.reason,className:"taskchef-github-reference-ambiguous",tabIndex:0,title:f.reason,children:f.text},`${d}:${f.text}`);const p=s[c];c+=1;const h=f.type==="pull"?", GitHub pull request":f.type==="issue"?", GitHub issue":f.owner?" on GitHub":"";return g.jsx(Lc,{"aria-label":`${rx(f)}${h} (opens in a new tab)`,className:"taskchef-github-link",href:f.url,rel:"noopener noreferrer",target:"_blank",children:p},`${d}:${f.url}`)})}function mx({loading:n,onClick:l,taskTitle:r}){return g.jsx(il,{"aria-label":`Open chat for ${r}`,leftSection:g.jsx(T_,{"aria-hidden":!0,size:15}),loading:n,onClick:l,size:"compact-sm",variant:"default",children:"Open chat"})}function ou({children:n,className:l="",...r}){return g.jsx("span",{className:`taskchef-shimmer ${l}`.trim(),"data-animation":"text-shimmer",...r,children:n})}const px=x.createContext(null);function UN({children:n,now:l}){return g.jsx(px,{value:l,children:n})}function mc({icon:n,label:l,tooltipLabel:r,value:o}){const[s,c]=x.useState(!1);x.useContext(px);const f=s?Hb(o):Lp(o),d=Hb(o),p=d==="—",h=d==="—"?"Updated time unavailable":s?"Show relative time":`Exact time: ${d}. Show exact time`;return g.jsx(Zn,{events:{focus:!0,hover:!0,touch:!1},label:r??h,children:g.jsxs(kl,{"aria-label":p?`${l}: unavailable.`:`${l}: ${f}. ${s?"Show relative time":"Show exact time"}`,className:"taskchef-time",disabled:p,onClick:()=>c(b=>!b),children:[n??g.jsx(b_,{"aria-hidden":!0,size:12}),g.jsx("bdi",{className:"taskchef-time-label",children:f})]})})}function hx({children:n,variant:l}){return g.jsx(ue,{className:`taskchef-stats taskchef-${l}-stats`,component:"div",children:n})}function va({children:n,usageState:l}){return g.jsx(ue,{className:"taskchef-stat","data-usage-state":l,children:n})}function Ko({accessibleLabel:n,animated:l=!1,icon:r,title:o,value:s}){return g.jsx(Zn,{events:{focus:!0,hover:!0,touch:!1},label:o,multiline:!0,children:g.jsxs(_e,{"aria-label":n,className:"taskchef-stat-content",component:"span",size:"xs",tabIndex:0,children:[r,g.jsx("bdi",{children:l?g.jsx(ou,{children:s}):s})]})})}function YN({task:n}){const l=ex(n),r=SN(n);return g.jsxs(hx,{variant:"card",children:[g.jsx(va,{children:g.jsx(mc,{icon:g.jsx(VS,{"aria-hidden":!0,size:14}),label:`Updated time for ${n.title}`,tooltipLabel:"Updated at",value:n.meaningfulUpdatedAt??n.updatedAt})}),g.jsx(va,{children:g.jsx(Ko,{accessibleLabel:l.accessibleLabel,icon:g.jsx(GS,{"aria-hidden":!0,size:14}),title:"Duration",value:l.value})}),g.jsxs(va,{usageState:r.kind,children:[g.jsx(Ko,{accessibleLabel:r.tokens.accessibleLabel,animated:r.tokens.animated,icon:g.jsx(XS,{"aria-hidden":!0,size:14}),title:"Tokens",value:r.tokens.value}),g.jsxs(_e,{className:"taskchef-visually-hidden",component:"span",role:"status",children:[r.tokens.accessibleLabel,"; ",r.cost.accessibleLabel]})]}),g.jsx(va,{usageState:r.kind,children:g.jsx(Ko,{accessibleLabel:r.cost.accessibleLabel,animated:r.cost.animated,icon:g.jsx(qS,{"aria-hidden":!0,size:14}),title:"Estimated cost",value:r.cost.value})})]})}function qN({onOpenCodex:n,onOpenDetail:l,task:r}){const o=W_(r);return g.jsx(gn,{className:"taskchef-task-row",component:"article",p:"md",radius:"md",withBorder:!0,children:g.jsxs(Ut,{className:"taskchef-task-main",gap:"sm",children:[g.jsxs(ue,{children:[g.jsxs(ue,{className:"taskchef-card-heading",children:[g.jsx(Wt,{order:3,size:"h5",children:g.jsx("button",{className:"taskchef-title-button",onClick:()=>l(r),type:"button",children:r.title})}),g.jsxs(Ut,{align:"flex-end",className:"taskchef-card-metadata",gap:4,children:[g.jsx(au,{status:r.status}),g.jsx(mx,{onClick:()=>n(r),taskTitle:r.title})]})]}),g.jsx(_e,{c:"dimmed",mt:2,size:"xs",children:r.project.name})]}),g.jsxs(ue,{className:"taskchef-summary-grid",children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Request"}),g.jsx(_e,{className:"taskchef-preserve-lines",lineClamp:3,size:"sm",children:g.jsx(dc,{task:r,text:o.requestSummary})}),g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Result"}),g.jsx(_e,{className:"taskchef-preserve-lines",lineClamp:3,size:"sm",children:o.resultStatus==="working"?g.jsx(ou,{children:o.resultSummary}):g.jsx(dc,{task:r,text:o.resultSummary})})]}),g.jsx(dx,{task:r}),g.jsx(YN,{task:r})]})})}function VN({highlightTurnRef:n,task:l}){const r=tN(l,[]);return r!=null&&r.length?g.jsx(Ut,{gap:"sm",children:[...r].reverse().map((o,s)=>{const c=eN(o),f=o.turnRef??o.turnId??`turn-${s}`,d=f===n,p=yN(l,o);return g.jsx(gn,{className:`taskchef-turn${d?" taskchef-turn-highlighted":""}`,"data-turn-ref":f,p:"sm",radius:"md",tabIndex:d?-1:void 0,withBorder:!0,children:g.jsxs(Ut,{gap:7,children:[g.jsxs(ue,{className:"taskchef-turn-heading",children:[g.jsx(_e,{c:"dimmed",size:"xs",children:c.sourceLabel}),g.jsx(au,{status:c.status})]}),g.jsxs(ue,{children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Request"}),g.jsx(_e,{className:"taskchef-preserve-lines",size:"sm",children:g.jsx(dc,{task:l,text:o.requestSummary??"Request not recorded."})})]}),g.jsxs(ue,{children:[g.jsx(_e,{c:"dimmed",className:"taskchef-field-label",size:"xs",children:"Result"}),g.jsx(_e,{className:"taskchef-preserve-lines",size:"sm",children:c.status==="working"?g.jsx(ou,{children:c.summary}):g.jsx(dc,{task:l,text:c.summary})})]}),g.jsxs(hx,{variant:"turn",children:[g.jsx(va,{children:g.jsx(mc,{icon:g.jsx(VS,{"aria-hidden":!0,size:14}),label:"Turn update time",tooltipLabel:"Updated at",value:c.updatedAt})}),g.jsx(va,{children:g.jsx(GN,{turn:o})}),g.jsx(va,{usageState:p.kind,children:g.jsx(Ko,{accessibleLabel:p.tokens.accessibleLabel,animated:p.animated,icon:g.jsx(XS,{"aria-hidden":!0,size:14}),title:"Tokens",value:p.tokens.value})}),g.jsx(va,{usageState:p.kind,children:g.jsx(Ko,{accessibleLabel:p.cost.accessibleLabel,animated:p.animated,icon:g.jsx(qS,{"aria-hidden":!0,size:14}),title:"Estimated cost",value:p.cost.value})})]}),p.note&&g.jsx(_e,{c:"dimmed",size:"xs",children:p.note})]})},f)})}):g.jsx(_e,{c:"dimmed",size:"sm",children:"No turn history has been recorded."})}function GN({turn:n}){const l=XN(n.result===null),r=vN(n,l);return g.jsx(Ko,{accessibleLabel:r.accessibleLabel,icon:g.jsx(GS,{"aria-hidden":!0,size:14}),title:"Duration",value:r.value})}function XN(n){const[l,r]=x.useState(()=>Date.now());return x.useEffect(()=>{if(!n)return;r(Date.now());const o=window.setInterval(()=>r(Date.now()),1e3);return()=>window.clearInterval(o)},[n]),l}function IN({task:n}){const l=nx(n),r=ex(n),o=l.kind==="ready"?l:null,s=Object.keys((o==null?void 0:o.usage.models)??{}).join(", "),c=o==null?void 0:o.usage.estimatedCostUsd,f=typeof c=="number"&&Number.isFinite(c),d=l.kind==="pending"?"Pending":l.kind==="calculating"?"Calculating":"n/a",p=l.kind==="unavailable"?"unavailable":d.toLowerCase(),h=[{accessibleValue:o?`${pi(o.usage.totalTokens)} tokens`:l.label,animated:l.kind==="pending"||l.kind==="calculating"||(o==null?void 0:o.knownSoFar),label:"Tokens",title:o?`${pi(o.usage.totalTokens)} tokens`:l.label,value:o?lu(o.usage.totalTokens):d},{accessibleValue:o?o.usage.estimatedCostUsd==null?"Estimated cost unavailable":`Estimated cost ${er(o.usage.estimatedCostUsd)}`:`Estimated cost ${p}${l.kind==="unavailable"?`: ${l.label}`:""}`,animated:l.kind==="pending"||l.kind==="calculating"||(o==null?void 0:o.knownSoFar)&&f,label:"Estimated cost",title:(o==null?void 0:o.usage.estimatedCostUsd)==null?"Estimated cost unavailable":`Unrounded estimate: $${o.usage.estimatedCostUsd}`,value:o?o.usage.estimatedCostUsd==null?"n/a":er(o.usage.estimatedCostUsd):d},{accessibleValue:r.accessibleLabel,label:"Duration",title:r.title,value:r.value},{accessibleValue:s||"Models unavailable",label:"Models",title:s||"Models unavailable",value:s||"n/a"}];return g.jsxs(ue,{"aria-live":"polite",children:[g.jsx(ue,{className:"taskchef-metrics",children:h.map(({accessibleValue:b,animated:y,label:v,title:w,value:R})=>g.jsxs(gn,{className:"taskchef-metric",p:"sm",radius:"md",withBorder:!0,children:[g.jsx(_e,{c:"dimmed",size:"xs",children:v}),g.jsx(_e,{"aria-label":b,className:"taskchef-metric-value",fw:650,size:"sm",title:w,children:y?g.jsx(ou,{children:R}):R})]},v))}),l.kind==="unavailable"&&l.label!=="Token usage unavailable"&&g.jsx(_e,{c:"dimmed",mt:"xs",size:"xs",children:l.label})]})}function ZN({busy:n,error:l,highlightTurnRef:r,onClose:o,onCopy:s,onOpenCodex:c,onTransition:f,opened:d,task:p,notifications:h,notice:b}){var C;const y=Rm("(max-width: 48em)"),[v,w]=x.useState(null);if(x.useEffect(()=>{d||w(null)},[d]),x.useEffect(()=>{d&&r&&requestAnimationFrame(()=>{var A;(A=document.querySelector(`[data-turn-ref="${CSS.escape(r)}"]`))==null||A.focus()})},[r,d,(C=p==null?void 0:p.turns)==null?void 0:C.length,p==null?void 0:p.updatedAt]),x.useEffect(()=>{v&&(!p||!Yb(p).includes(v))&&w(null)},[v,p==null?void 0:p.status]),!p)return null;const R=Yb(p),T=g.jsxs(Ut,{gap:"lg",children:[h,g.jsxs(ue,{children:[g.jsxs(St,{align:"flex-start",gap:"sm",justify:"space-between",wrap:"nowrap",children:[g.jsxs(ue,{children:[g.jsx(_e,{c:"teal",fw:700,size:"xs",tt:"uppercase",children:p.project.name}),g.jsx(Wt,{id:"task-detail-title",order:2,size:"h3",tabIndex:-1,children:p.title})]}),g.jsx(au,{status:p.status})]}),g.jsxs(St,{gap:"xs",mt:"md",children:[g.jsx(mx,{loading:n,onClick:c,taskTitle:p.title}),g.jsxs(xt,{position:"bottom-start",shadow:"md",withinPortal:!0,zIndex:360,children:[g.jsx(xt.Target,{children:g.jsx(Zn,{label:"More task actions",children:g.jsx(ul,{"aria-label":"More task actions",disabled:n,variant:"default",children:g.jsx(w_,{"aria-hidden":!0,size:17})})})}),g.jsxs(xt.Dropdown,{children:[g.jsx(xt.Item,{leftSection:g.jsx(g_,{size:14}),onClick:s,children:"Copy Task ID"}),R.includes("completed")&&g.jsx(xt.Item,{leftSection:g.jsx(h_,{size:14}),onClick:()=>w("completed"),children:"Mark completed"}),R.includes("failed")&&g.jsx(xt.Item,{color:"red",leftSection:g.jsx(IS,{size:14}),onClick:()=>w("failed"),children:"Mark failed"})]})]})]}),g.jsx(ue,{mt:"sm",children:g.jsx(dx,{task:p})})]}),v&&g.jsx(QN,{busy:n,onCancel:()=>w(null),onTransition:f,status:v},v),b&&g.jsx(Mn,{color:"teal",role:"status",children:b}),l&&g.jsx(Mn,{color:"red",role:"alert",children:l}),g.jsxs("section",{"aria-labelledby":"usage-heading",children:[g.jsx(Wt,{id:"usage-heading",mb:"xs",order:3,size:"h5",children:"Usage"}),g.jsx(IN,{task:p})]}),g.jsx(Uc,{}),g.jsxs("section",{"aria-labelledby":"activity-heading",children:[g.jsx(Wt,{id:"activity-heading",mb:"sm",order:3,size:"h5",children:"Activity timeline"}),g.jsx(VN,{highlightTurnRef:r,task:p})]}),g.jsxs("section",{"aria-labelledby":"instruction-heading",children:[g.jsx(Wt,{id:"instruction-heading",mb:"xs",order:3,size:"h5",children:"Original instruction"}),g.jsx(ue,{className:"taskchef-code-panel",component:"pre",children:p.instruction})]}),g.jsxs("section",{"aria-labelledby":"metadata-heading",children:[g.jsx(Wt,{id:"metadata-heading",mb:"xs",order:3,size:"h5",children:"Metadata"}),g.jsxs("dl",{className:"taskchef-metadata",children:[g.jsx("dt",{children:"Task ID"}),g.jsx("dd",{children:p.id}),g.jsx("dt",{children:"Thread ID"}),g.jsx("dd",{children:p.threadId??"—"}),g.jsx("dt",{children:"Current turn ref"}),g.jsx("dd",{children:p.turnRef??"—"}),g.jsx("dt",{children:"Project path"}),g.jsx("dd",{children:p.project.path}),g.jsx("dt",{children:"Created"}),g.jsx("dd",{children:g.jsx(mc,{label:"Created time",value:p.createdAt})}),g.jsx("dt",{children:"Updated"}),g.jsx("dd",{children:g.jsx(mc,{label:"Updated time",value:p.meaningfulUpdatedAt??p.updatedAt})}),g.jsx("dt",{children:"Updated by"}),g.jsx("dd",{children:p.updatedBy??"—"})]})]})]});return y?g.jsx(Gn,{closeOnClickOutside:!n,closeOnEscape:!n,onClose:o,opened:d,overlayProps:{backgroundOpacity:.55,blur:2},position:"bottom",scrollAreaComponent:Un.Autosize,size:"92%",title:g.jsx("span",{className:"taskchef-visually-hidden",children:"Task details"}),trapFocus:!0,zIndex:300,children:T}):g.jsx(In,{"aria-labelledby":"task-detail-title",closeOnClickOutside:!n,closeOnEscape:!n,onClose:o,opened:d,overlayProps:{backgroundOpacity:.55,blur:2},scrollAreaComponent:Un.Autosize,size:"min(820px, calc(100vw - 32px))",title:g.jsx("span",{className:"taskchef-visually-hidden",children:"Task details"}),trapFocus:!0,zIndex:300,children:T})}function Yb(n){return n.status==="completed"?["failed"]:n.status==="failed"?["completed"]:n.status==="working"||n.status==="needs_input"?["completed","failed"]:[]}function QN({busy:n,onCancel:l,onTransition:r,status:o}){const s=x.useRef(crypto.randomUUID());return g.jsxs(Mn,{color:o==="failed"?"red":"teal",role:"alert",title:`Mark task ${o}?`,children:[g.jsx(_e,{mb:"sm",size:"sm",children:"This interrupts active work and appends an audited manual dashboard turn."}),g.jsxs(St,{gap:"xs",children:[g.jsx(il,{color:o==="failed"?"red":"teal",loading:n,onClick:async()=>{const c=await r(o,s.current);c.ok?(l(),requestAnimationFrame(()=>{var f;return(f=document.getElementById("task-detail-title"))==null?void 0:f.focus()})):c.rotateActionId&&(s.current=crypto.randomUUID())},size:"compact-sm",children:"Confirm"}),g.jsx(il,{disabled:n,onClick:l,size:"compact-sm",variant:"default",children:"Cancel"})]})]})}const KN={primaryColor:"teal",colors:{teal:["#e6fcf5","#c3fae8","#96f2d7","#63e6be","#38d9a9","#20c997","#087f5b","#067052","#055e46","#044d39"]},defaultRadius:"md",fontFamily:"Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, Segoe UI, sans-serif",headings:{fontFamily:"inherit",fontWeight:"680"},components:{Button:{defaultProps:{radius:"md"}},Paper:{defaultProps:{radius:"md"}}}};var Vb;const qb=(Vb=document.querySelector('meta[name="taskchef-style-nonce"]'))==null?void 0:Vb.content;function FN({totalCount:n,visibleCount:l}){return g.jsxs(_e,{"aria-live":"polite",className:"taskchef-results-summary",id:"task-results-summary",children:["Tasks: ",l," of ",n]})}function JN({connect:n=!0,initialFilters:l={},initialTasks:r=[]}){const[o,s]=x.useState(()=>window.location.hash==="#settings");x.useEffect(()=>{const me=()=>s(window.location.hash==="#settings");return window.addEventListener("hashchange",me),()=>window.removeEventListener("hashchange",me)},[]);const[c,f]=x.useState(r),[d,p]=x.useState(),[h,b]=x.useState(!1),[y,v]=x.useState(null),[w,R]=x.useState(null),[T,C]=x.useState(l.project??""),[A,N]=x.useState(l.status??""),[_,j]=x.useState(l.date??"all"),[$,L]=x.useState(()=>Date.now()),[D,H]=x.useState(null),[W,le]=x.useState(!1),[ae,te]=x.useState(!1),[J,V]=x.useState(null),[ce,O]=x.useState(null),[B,U]=x.useState(null),[Q,P]=x.useState({initialized:r.length>0,announcements:[],notifications:[],seenIds:new Set,signatures:new Map}),M=(D==null?void 0:D.id)??null,Y=x.useRef(M);Y.current=M;const F=x.useRef(0),re=x.useRef(null),ie=x.useRef(Fs(null)),fe=x.useCallback(me=>{f(me.tasks),p(me.projectIndex),P(qe=>{const ze=fN(qe,me.tasks);return{initialized:!0,announcements:ze.additions,notifications:ze.notifications,seenIds:ze.seenIds,signatures:ze.signatures}}),v(me.healthy===!1?"The task log is temporarily unavailable. Showing the last valid snapshot.":null);const Me=Y.current;if(Me){const qe=me.tasks.find(ze=>ze.id===Me);qe&&H(ze=>ze?kb(ze,qe):qe)}},[]);x.useEffect(()=>{const me=window.setInterval(()=>L(Date.now()),3e4);return()=>window.clearInterval(me)},[]),x.useEffect(()=>{if(!n)return;U_().then(R).catch(()=>R(null));const me=H_({onConnection:b,onError:v,onSnapshot:fe});return()=>me.close()},[fe,n]);const ge=x.useCallback(async(me,Me=null)=>{const qe=++F.current;re.current=me.updatedAt,ie.current=Fs(me),H(ze=>(ze==null?void 0:ze.id)===me.id?kb(ze,me):me),le(!0),U(Me),V(null),O(null);try{for(let ze=0;ze<=40;ze+=1){if(qe!==F.current)return;const Je=await q_(me.id);if(qe!==F.current||(re.current=Je.updatedAt,ie.current=Fs(Je),H(Je),!bN(Je)||ze===40))return;await new Promise(ct=>window.setTimeout(ct,1500))}}catch{qe===F.current&&V("Task activity is temporarily unavailable. Showing the latest list snapshot.")}},[]),de=c.find(me=>me.id===M)??null,he=Fs(de);x.useEffect(()=>{!W||!M||!n||de&&(de.updatedAt===re.current&&he===ie.current||ge(de,B))},[de==null?void 0:de.updatedAt,he]);const Oe=x.useMemo(()=>[{label:"All projects",value:""},...[...new Set(c.map(me=>me.project.name))].sort().map(me=>({label:me,value:me}))],[c]),be=x.useMemo(()=>KS(c,{project:T,status:A,date:_,now:$}),[c,T,A,_,$]),Ce=x.useMemo(()=>lN(c,{project:T,date:_,now:$}),[c,T,_,$]),Se=ZS.map(({label:me,value:Me})=>({label:Ce[Me]>0?`${me} ${Ce[Me]}`:me,value:Me}));async function Ne(me){te(!0);try{const Me=await V_(me.id);Me&&v(Me)}catch{v("Codex could not be opened. Open the project and select the recorded task instead.")}finally{te(!1)}}async function st(me,Me){if(!D)return{ok:!1};const qe=D,ze=J_(qe);te(!0),V(null);const Je=await G_(qe,me,Me);return te(!1),Je.task&&(H(ct=>Db({requestTask:qe,expected:ze,responseTask:Je.task,selectedTask:ct})),f(ct=>ct.map(jt=>jt.id===qe.id?Db({requestTask:qe,expected:ze,responseTask:Je.task,selectedTask:jt}):jt))),Je.ok&&Je.task?(U(Je.task.turnRef??Je.task.turnId),{ok:!0}):(V(Je.message??"Task state could not be changed."),{ok:!1,rotateActionId:Je.code==="stale_task"})}function at(me){const Me=c.find(ze=>ze.id===me.taskId),qe=dN({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:Q.notifications,refreshGeneration:F.current},me,!!Me);if(P(ze=>({...ze,notifications:qe.notifications})),!Me){v("This task is no longer present in the current snapshot.");return}ge(Me,qe.highlightTurnRef)}return g.jsx(c0,{defaultColorScheme:"auto",getStyleNonce:qb?()=>qb:void 0,theme:KN,children:g.jsxs(UN,{now:$,children:[g.jsxs(Yn,{className:"taskchef-shell",padding:0,children:[g.jsx(mi,{className:"taskchef-header",component:"header",size:1080,children:g.jsxs(St,{className:"taskchef-header-layout",align:"stretch",justify:"space-between",wrap:"nowrap",children:[g.jsxs(ue,{className:"taskchef-header-copy",children:[g.jsxs(_e,{c:"var(--taskchef-accent)",fw:750,size:"xs",tt:"uppercase",children:["TaskChef ",w&&g.jsxs("span",{className:"taskchef-version",children:["v",w]})]}),g.jsxs(St,{gap:"sm",mt:5,wrap:"nowrap",children:[g.jsx(WN,{}),g.jsx(Wt,{order:1,size:"h2",children:"Dashboard"})]})]}),g.jsxs(Ut,{align:"flex-end",className:"taskchef-header-actions",gap:0,justify:"space-between",children:[g.jsxs(St,{"aria-live":"polite",className:"taskchef-connection",gap:7,role:"status",wrap:"nowrap",children:[g.jsx(B_,{"aria-hidden":!0,color:h?"var(--mantine-color-teal-6)":"var(--mantine-color-yellow-6)",size:9}),g.jsx(_e,{c:"dimmed",size:"xs",children:h?"Live":n?"Connecting…":"Fixture preview"})]}),g.jsxs(St,{className:"taskchef-header-icon-row",gap:2,justify:"flex-end",wrap:"nowrap",children:[g.jsx(Zn,{label:"Settings",children:g.jsx(ul,{className:"taskchef-icon-button",component:"a",href:"#settings","aria-label":"Settings","aria-current":o?"page":void 0,variant:"subtle",color:"gray",size:"lg",children:g.jsx(O_,{size:18,stroke:1.8})})}),g.jsx(PN,{})]})]})]})}),g.jsx(Yn.Main,{children:g.jsxs(mi,{className:"taskchef-main",pb:80,size:1080,children:[(d==null?void 0:d.status)==="unavailable"&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{size:18}),mb:"md",title:"Project index unavailable",children:"Task history is still visible. Verify the index and inspect backups before making project changes."}),(d==null?void 0:d.status)==="available"&&d.missingProjects.length>0&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{size:18}),mb:"md",title:"Historical projects are missing from the current index",children:d.missingProjects.map(me=>g.jsxs(_e,{size:"sm",children:[me.snapshotNames.join(", "),": ",me.taskCount," task(s). Run ",g.jsx("code",{children:"taskchef backup list --json"})," and preview any restore; the dashboard never restores automatically."]},me.path))}),o?g.jsxs(Ut,{gap:"md",children:[g.jsx(il,{component:"a",href:"#",variant:"subtle",size:"sm",leftSection:g.jsx(f_,{size:16}),style:{alignSelf:"flex-start"},children:"Back to tasks"}),g.jsx(X_,{})]}):g.jsxs(g.Fragment,{children:[g.jsx(gn,{className:"taskchef-toolbar",p:"sm",radius:"md",withBorder:!0,children:g.jsxs(Ut,{gap:"sm",children:[g.jsxs(St,{align:"end",gap:"sm",children:[g.jsx(Wo,{"aria-label":"Project",data:Oe,label:"Project",onChange:me=>C(me??""),size:"sm",value:T}),g.jsx(Wo,{"aria-label":"Updated",data:[{label:"Latest 24 hours",value:"24h"},{label:"Latest 7 days",value:"7d"},{label:"All time",value:"all"}],label:"Updated",onChange:me=>j(me??"all"),size:"sm",value:_})]}),g.jsxs(ue,{children:[g.jsx(_e,{className:"taskchef-filter-label",mb:5,children:"Status"}),g.jsx(tu,{"aria-label":"Status",data:Se,fullWidth:!0,onChange:N,size:"xs",value:A})]})]})}),g.jsx(FN,{totalCount:c.length,visibleCount:be.length}),y&&g.jsx(Mn,{color:"yellow",icon:g.jsx(Zd,{"aria-hidden":!0,size:17}),mt:"md",role:"status",children:g.jsxs(St,{gap:"sm",justify:"space-between",wrap:"nowrap",children:[g.jsx(_e,{size:"sm",children:y}),g.jsx(Ja,{"aria-label":"Dismiss dashboard message",onClick:()=>v(null),size:"sm"})]})}),g.jsxs(Ut,{"aria-describedby":"task-results-summary","aria-label":"Tasks",component:"section",gap:"sm",mt:"xs",children:[be.map(me=>g.jsx(qN,{onOpenCodex:Ne,onOpenDetail:Me=>void ge(Me),task:me},me.id)),be.length===0&&g.jsxs(gn,{className:"taskchef-empty",p:48,ta:"center",withBorder:!0,children:[g.jsx(Wt,{order:2,size:"h4",children:"No tasks match these filters"}),g.jsx(_e,{c:"dimmed",mt:4,size:"sm",children:"Choose a different project, date, or status."})]})]})]})]})})]}),g.jsx(ZN,{busy:ae,error:J,highlightTurnRef:B,onClose:()=>{ae||(F.current+=1,le(!1),U(null))},onCopy:()=>{D&&(O(null),navigator.clipboard.writeText(D.id).then(()=>O("Task ID copied."),()=>O("Clipboard access is unavailable. Copy the Task ID from metadata.")))},onOpenCodex:()=>D&&void Ne(D),onTransition:st,opened:W,task:D,notice:ce,notifications:W?g.jsx(Ub,{announcements:Q.announcements,notifications:Q.notifications,onClear:()=>P(me=>({...me,notifications:Lb({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:me.notifications,refreshGeneration:F.current}).notifications})),onDismiss:me=>P(Me=>({...Me,notifications:$b(Me.notifications,me.id)})),onOpen:at,tasks:c,withinPortal:!1}):null}),!W&&g.jsx(Ub,{announcements:Q.announcements,notifications:Q.notifications,onClear:()=>P(me=>({...me,notifications:Lb({detailTaskId:M,detailOpened:W,highlightTurnRef:B,notifications:me.notifications,refreshGeneration:F.current}).notifications})),onDismiss:me=>P(Me=>({...Me,notifications:$b(Me.notifications,me.id)})),onOpen:at,tasks:c})]})})}function PN(){const{setColorScheme:n}=l0(),l=a0("light"),r=l==="dark"?"light":"dark";return g.jsx(Zn,{label:`Use ${r} theme`,children:g.jsx(ul,{"aria-label":`Use ${r} theme`,className:"taskchef-icon-button",color:"gray",onClick:()=>n(r),size:"lg",variant:"subtle",children:l==="dark"?g.jsx($_,{"aria-hidden":!0,size:18,stroke:1.8}):g.jsx(__,{"aria-hidden":!0,size:18,stroke:1.8})})})}function WN(){const n=a0("light");return g.jsx("img",{alt:"","aria-hidden":!0,className:"taskchef-brand-icon",height:"42",src:n==="dark"?"/assets/taskchef-dark.svg":"/assets/taskchef.svg",width:"42"})}B2.createRoot(document.getElementById("root")).render(g.jsx(x.StrictMode,{children:g.jsx(JN,{})}));
194
194
  //# sourceMappingURL=app.js.map