baxian 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/manager.d.ts +10 -9
- package/dist/agent/manager.d.ts.map +1 -1
- package/dist/agent/manager.js +181 -413
- package/dist/agent/manager.js.map +1 -1
- package/dist/agent/phase-signal-watcher.d.ts +1 -4
- package/dist/agent/phase-signal-watcher.d.ts.map +1 -1
- package/dist/agent/phase-signal-watcher.js +3 -22
- package/dist/agent/phase-signal-watcher.js.map +1 -1
- package/dist/agent/phase-signal.d.ts +1 -10
- package/dist/agent/phase-signal.d.ts.map +1 -1
- package/dist/agent/phase-signal.js +5 -8
- package/dist/agent/phase-signal.js.map +1 -1
- package/dist/agent/prompt.d.ts +1 -2
- package/dist/agent/prompt.d.ts.map +1 -1
- package/dist/agent/prompt.js +32 -63
- package/dist/agent/prompt.js.map +1 -1
- package/dist/agent/repo-store.d.ts +0 -1
- package/dist/agent/repo-store.d.ts.map +1 -1
- package/dist/agent/repo-store.js +0 -25
- package/dist/agent/repo-store.js.map +1 -1
- package/dist/agent/worktree.d.ts +1 -0
- package/dist/agent/worktree.d.ts.map +1 -1
- package/dist/agent/worktree.js +14 -0
- package/dist/agent/worktree.js.map +1 -1
- package/dist/api/agents.d.ts.map +1 -1
- package/dist/api/agents.js +4 -0
- package/dist/api/agents.js.map +1 -1
- package/dist/api/tasks.js +1 -1
- package/dist/api/tasks.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -1
- package/dist/cli.js.map +1 -1
- package/dist/event/handlers.d.ts.map +1 -1
- package/dist/event/handlers.js +10 -430
- package/dist/event/handlers.js.map +1 -1
- package/dist/event/server-handlers.d.ts.map +1 -1
- package/dist/event/server-handlers.js +21 -14
- package/dist/event/server-handlers.js.map +1 -1
- package/dist/shared/constants.d.ts +1 -1
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +0 -6
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/skills/server-feedback/SKILL.md +4 -2
- package/dist/terminal/attach.d.ts.map +1 -1
- package/dist/terminal/attach.js +8 -2
- package/dist/terminal/attach.js.map +1 -1
- package/dist/web/assets/index-OtgjyQI1.js +4 -0
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/dist/web/assets/index-DE_xpPQe.js +0 -4
package/dist/shared/types.d.ts
CHANGED
|
@@ -224,7 +224,7 @@ export interface ReviewRound {
|
|
|
224
224
|
startedAt: string;
|
|
225
225
|
completedAt?: string;
|
|
226
226
|
}
|
|
227
|
-
export type EventType = 'task.created' | 'task.assigned' | 'task.updated' | 'session.started' | '
|
|
227
|
+
export type EventType = 'task.created' | 'task.assigned' | 'task.updated' | 'session.started' | 'pr.created' | 'pr.updated' | 'pr.merged' | 'review.submitted' | 'review.max_rounds' | 'server.spec.ready' | 'server.spec.review.submitted' | 'server.spec.fix.submitted' | 'server.code.ready' | 'server.code.review.submitted' | 'server.code.fix.submitted' | 'server.code.published' | 'pr.fix.submitted' | 'agent.bootstrap_failed' | 'agent.bootstrap_succeeded' | 'agent.recovered' | 'human.intervention';
|
|
228
228
|
export interface BaxianEvent {
|
|
229
229
|
id: string;
|
|
230
230
|
type: EventType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/shared/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,OAAO,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,IAAI,CAAC;AACrC,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;AAC3C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,IAAI,CAAC;AAC1C,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,IAA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B,CAAC;IAAC,IAAI,EAAE,SAAS,EAAE,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,IAAI,EAAE,cAAc,EAAE,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -11,11 +11,11 @@ QA findings are INJECTED in your prompt (ids may look like `b0-f-1` when the rev
|
|
|
11
11
|
|
|
12
12
|
Every finding id gets EXACTLY ONE response item:
|
|
13
13
|
|
|
14
|
-
- `fix` —
|
|
14
|
+
- `fix` — apply the change. Code phase: commit in the worktree and put the SHA in `commitSha`. Spec phase: revise the spec doc in place — never commit it, and omit `commitSha`.
|
|
15
15
|
- `reject` — concrete rationale why the finding is wrong or not applicable. Never reject to save effort.
|
|
16
16
|
- `out-of-scope` — rationale plus where it is tracked (issue link or follow-up note).
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Do NOT push to any remote and do NOT open PRs in this phase — baxian reads your worktree directly.
|
|
19
19
|
|
|
20
20
|
## Output
|
|
21
21
|
|
|
@@ -25,6 +25,8 @@ Write `.baxian/review/response.json` in your worktree (`mkdir -p .baxian/review`
|
|
|
25
25
|
{"round":N,"responses":[{"findingId":"f-1","action":"fix","rationale":"...","commitSha":"abc1234"}]}
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
+
(`commitSha` only in code phase.)
|
|
29
|
+
|
|
28
30
|
Then emit the signal exactly once (kind comes from your prompt — `code-fixed` in code phase, `spec-fixed` in spec phase; token from your prompt):
|
|
29
31
|
|
|
30
32
|
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/terminal/attach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGlE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;
|
|
1
|
+
{"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/terminal/attach.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGlE,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,EAAE,CAAC;IAEf,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAMD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,UAAU,GAAG,aAAa,CA8BlG"}
|
package/dist/terminal/attach.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { shellQuote, wrapRemoteCommand, sshAuthArgs, sshTarget } from '../agent/runner.js';
|
|
2
2
|
// `host` is the resolved registry host (caller resolves the agent's ref). NO `-d`: it would detach
|
|
3
3
|
// real SSH users sharing the session. No mux/keepalive here — an interactive attach must survive blips.
|
|
4
|
+
// focus-events (server option) must be on BEFORE the client attaches, or tmux won't request focus
|
|
5
|
+
// reporting from its terminal — set it at attach time so pre-existing servers gain it too.
|
|
4
6
|
export function buildAttachInteractiveCommand(agent, host) {
|
|
5
7
|
if (agent.mode === 'remote') {
|
|
6
8
|
if (!host)
|
|
@@ -17,13 +19,17 @@ export function buildAttachInteractiveCommand(agent, host) {
|
|
|
17
19
|
'-t',
|
|
18
20
|
'--',
|
|
19
21
|
sshTarget(host),
|
|
20
|
-
wrapRemoteCommand(`tmux -
|
|
22
|
+
wrapRemoteCommand(`tmux set-option -g focus-events on 2>/dev/null || true; ` +
|
|
23
|
+
`tmux -u attach-session -t ${shellQuote(`=${agent.id}`)}`, 'login-interactive'),
|
|
21
24
|
],
|
|
22
25
|
};
|
|
23
26
|
}
|
|
27
|
+
// Single spawn, no shell: `;` is tmux's command separator within one invocation. A sequence
|
|
28
|
+
// aborts on the first error, so -q (suppress unknown-option errors) keeps a tmux that lacks
|
|
29
|
+
// focus-events from blocking the attach.
|
|
24
30
|
return {
|
|
25
31
|
file: 'tmux',
|
|
26
|
-
args: ['-u', 'attach-session', '-t', `=${agent.id}`],
|
|
32
|
+
args: ['-u', 'set-option', '-gq', 'focus-events', 'on', ';', 'attach-session', '-t', `=${agent.id}`],
|
|
27
33
|
};
|
|
28
34
|
}
|
|
29
35
|
//# sourceMappingURL=attach.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attach.js","sourceRoot":"","sources":["../../src/terminal/attach.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAS3F,mGAAmG;AACnG,wGAAwG;AACxG,MAAM,UAAU,6BAA6B,CAAC,KAAkB,EAAE,IAAiB;IACjF,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC,EAAE,uBAAuB,CAAC,CAAC;QAC5E,OAAO;YACL,IAAI,EAAE,KAAK;YACX,IAAI,EAAE;gBACJ,GAAG,WAAW,CAAC,IAAI,CAAC;gBACpB,IAAI,EAAE,mBAAmB;gBACzB,sGAAsG;gBACtG,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;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MAAM;QACZ,IAAI,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,GAAG,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;KACrG,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var rs=Object.defineProperty;var os=(t,s,r)=>s in t?rs(t,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[s]=r;var Y=(t,s,r)=>os(t,typeof s!="symbol"?s+"":s,r);import{r as o,j as e,c as as}from"./react-BG4Iuztk.js";import{x as is,a as cs}from"./xterm-D5X2JljJ.js";import{L as Re,u as Ht,a as ls,B as ds,b as us,R as fs,c as Ke}from"./router-eEZdpwQZ.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))a(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const u of i.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&a(u)}).observe(document,{childList:!0,subtree:!0});function r(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerPolicy&&(i.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?i.credentials="include":n.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function a(n){if(n.ep)return;n.ep=!0;const i=r(n);fetch(n.href,i)}})();const hs={"claude-code":"Claude Code",codex:"Codex"};function it(t){return t?hs[t]:null}function ct(t,s){const r=it(s);return r?`${t} (${r})`:t}const Ut=new Set(["merged","done","failed","cancelled"]),Wt=new Set(["in_progress","review","fixing","approved","merge-ready","ready","max_rounds"]),Ve=20,We=5*1024*1024,Pe=4,Qe="/api",lt="baxian.token",Fe="baxian:unauthorized";function dt(){try{return typeof localStorage<"u"?localStorage.getItem(lt):null}catch{return null}}function ms(t){try{localStorage.setItem(lt,t)}catch(s){console.error("Failed to save auth token to localStorage",s)}}function xs(){try{localStorage.removeItem(lt)}catch(t){console.error("Failed to clear auth token from localStorage",t)}}function Ae(t){const s=dt();return{...t??{},...s?{Authorization:`Bearer ${s}`}:{}}}class Te extends Error{constructor(s,r,a){super(r),this.status=s,this.details=a,this.name="ApiError"}}async function Ie(t){const s=await t.text();let r=s||`HTTP ${t.status}`,a;try{const n=JSON.parse(s);typeof n.error=="string"&&(r=n.error),Array.isArray(n.details)&&(a=n.details)}catch{}throw t.status===401&&typeof window<"u"&&window.dispatchEvent(new CustomEvent(Fe)),new Te(t.status,r,a)}async function ue(t){const s=await fetch(`${Qe}${t}`,{headers:Ae()});return s.ok||await Ie(s),s.json()}async function ps(){const t=await fetch("/health");return t.ok||await Ie(t),t.json()}async function ae(t,s,r){const a=s!==void 0,n=await fetch(`${Qe}${t}`,{method:"POST",headers:a?Ae({"Content-Type":"application/json"}):Ae(),body:a?JSON.stringify(s):void 0,signal:r==null?void 0:r.signal});return n.ok||await Ie(n),n.json()}async function yt(t,s,r){const a=await fetch(`${Qe}${t}`,{method:"PATCH",headers:Ae({"Content-Type":"application/json"}),body:s?JSON.stringify(s):void 0,signal:r==null?void 0:r.signal});if(a.ok||await Ie(a),a.status===204)return;const n=await a.text();if(n)return JSON.parse(n)}async function Me(t){const s=await fetch(`${Qe}${t}`,{method:"DELETE",headers:Ae()});if(s.ok||await Ie(s),s.status===204)return;const r=await s.text();if(r)return JSON.parse(r)}const X=encodeURIComponent;function Qt(t){return new Promise((s,r)=>{const a=new FileReader;a.onerror=()=>r(a.error??new Error("file read failed")),a.onload=()=>{const n=a.result;if(typeof n!="string"){r(new Error("unexpected FileReader result"));return}const i=n.indexOf(",");s(i>=0?n.slice(i+1):n)},a.readAsDataURL(t)})}const M={agents:{list:()=>ue("/agents"),get:t=>ue(`/agents/${X(t)}`),stop:t=>Me(`/agents/${X(t)}/session`),compact:t=>ae(`/agents/${X(t)}/compact`),probe:(t,s={},r)=>ae("/agents/probe",{mode:t,host:s.host,hostId:s.hostId},r),uploadImage:async(t,s)=>ae(`/agents/${X(t)}/images`,{dataBase64:await Qt(s)})},tasks:{list:async t=>{const s=new Map;for(const r of["active","pending"]){let a=0;for(;;){const n=await M.tasks.page(t,{category:r,offset:a});for(const i of n.tasks)s.set(i.id,i);if(!n.hasMore||n.tasks.length===0)break;a=n.nextOffset}}return[...s.values()]},page:(t,s={})=>{const r=[`projectId=${X(t)}`];return s.category&&r.push(`category=${s.category}`),r.push(`offset=${s.offset??0}`),ue(`/tasks?${r.join("&")}`)},get:t=>ue(`/tasks/${X(t)}`),create:t=>ae("/tasks",t),update:(t,s)=>yt(`/tasks/${X(t)}`,s),retry:t=>ae(`/tasks/${X(t)}/retry`),review:t=>ae(`/tasks/${X(t)}/review`),complete:t=>ae(`/tasks/${X(t)}/complete`),continue:t=>ae(`/tasks/${X(t)}/continue`),reviews:t=>ue(`/tasks/${X(t)}/reviews`),dispatch:(t,s)=>ae(`/tasks/${X(t)}/dispatch`,s)},projects:{list:()=>ue("/projects"),get:t=>ue(`/projects/${X(t)}`),create:t=>ae("/projects",t),delete:t=>Me(`/projects/${X(t)}`),addAgent:(t,s)=>ae(`/projects/${X(t)}/agents`,s),deleteAgent:(t,s)=>Me(`/projects/${X(t)}/agents/${X(s)}`),resumeAgent:(t,s)=>ae(`/projects/${X(t)}/agents/${X(s)}/resume`),bootstrap:t=>ae(`/projects/${X(t)}/bootstrap`)},hosts:{list:()=>ue("/hosts"),create:t=>ae("/hosts",t),update:(t,s)=>yt(`/hosts/${X(t)}`,s),delete:t=>Me(`/hosts/${X(t)}`),check:t=>ae("/hosts/check",t)},config:{get:()=>ue("/config")},health:{get:ps},server:{restart:()=>ae("/restart")}},Gt=o.createContext(null),bs={success:"border-[#bbf7d0] bg-[#f0fdf4] text-success",warn:"border-[#fde68a] bg-[#fef3c7] text-warn",error:"border-[#fecaca] bg-[#fef2f2] text-danger"},gs={success:"✅",warn:"⚠️",error:"❌"};let vs=1;function ys({children:t}){const[s,r]=o.useState([]),a=o.useCallback(i=>{r(u=>u.filter(f=>f.id!==i))},[]),n=o.useCallback(i=>{const u=vs++,f=i.durationMs??3e3;r(m=>[...m,{...i,id:u}]),setTimeout(()=>a(u),f)},[a]);return e.jsxs(Gt.Provider,{value:{show:n},children:[t,e.jsx("div",{className:"pointer-events-none fixed inset-x-4 top-4 z-[60] flex flex-col items-end gap-2",children:s.map(i=>e.jsx("div",{className:`pointer-events-auto w-full max-w-xs rounded-lg border px-4 py-3 shadow-toast ${bs[i.kind]}`,role:"status",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:"text-[14px]",children:gs[i.kind]}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[13px] font-semibold",children:i.title}),i.body&&e.jsx("div",{className:"mt-1 whitespace-pre-line text-[12px] text-og-700",children:i.body})]}),e.jsx("button",{type:"button",onClick:()=>a(i.id),className:"text-current opacity-50 transition-opacity hover:opacity-100","aria-label":"Dismiss",children:"✕"})]})},i.id))})]})}function fe(){const t=o.useContext(Gt);if(!t)throw new Error("useToast must be inside <ToastProvider>");return t}const Be="baxian.pendingRestart",js=500,ws=3e4,qt=o.createContext(null);function Ns(){try{const t=localStorage.getItem(Be);if(!t)return{count:0,baselineStartedAt:null};const s=JSON.parse(t);return{count:typeof s.count=="number"?s.count:0,baselineStartedAt:typeof s.baselineStartedAt=="string"?s.baselineStartedAt:null}}catch{return{count:0,baselineStartedAt:null}}}function ks(t){try{t.count<=0?localStorage.removeItem(Be):localStorage.setItem(Be,JSON.stringify(t))}catch{}}function Ss({children:t}){const s=Ns(),[r,a]=o.useState(s.count),[n,i]=o.useState(s.baselineStartedAt),[u,f]=o.useState(s.count>0?"pending":"idle"),[m,h]=o.useState(),b=o.useRef(s.count),g=o.useRef(s.count>0?"pending":"idle"),d=o.useRef(0),v=o.useCallback(N=>{b.current=N,a(N)},[]),I=o.useCallback(N=>{a(E=>{const y=N(E);return b.current=y,y})},[]),x=o.useCallback(N=>{g.current=N,f(N)},[]);o.useEffect(()=>{ks({count:r,baselineStartedAt:n})},[r,n]),o.useEffect(()=>{let N=!1;(async()=>{try{const y=await M.health.get();if(N)return;i(c=>c!==null&&y.startedAt!==c?(v(0),x("idle"),null):c)}catch{}})();const E=y=>{if(y.key===Be){if(y.newValue===null){if(g.current==="restarting"&&d.current>0){v(d.current),i(null);return}v(0),i(null),g.current!=="restarting"&&x("idle");return}try{const c=JSON.parse(y.newValue);typeof c.count=="number"&&(g.current==="restarting"&&c.count>b.current&&(d.current+=c.count-b.current),v(c.count),g.current!=="restarting"&&x(c.count>0?"pending":"idle")),typeof c.baselineStartedAt=="string"?i(c.baselineStartedAt):c.baselineStartedAt===null&&i(null)}catch{}}};return window.addEventListener("storage",E),()=>{N=!0,window.removeEventListener("storage",E)}},[v,x]);const p=o.useRef(!1),S=o.useCallback(()=>{I(N=>N+1),g.current==="restarting"?d.current+=1:x("pending"),i(N=>(N!==null||p.current||(p.current=!0,(async()=>{try{const E=await M.health.get();i(y=>y??E.startedAt)}catch{}finally{p.current=!1}})()),N))},[x,I]),_=o.useCallback(async()=>{d.current=0,h(void 0),x("restarting");let N;try{N=(await M.health.get()).startedAt}catch(y){x("failed"),h(`获取重启前 startedAt 失败: ${y instanceof Error?y.message:String(y)}`);return}try{await M.server.restart()}catch(y){if(!(y instanceof Te&&y.status===409)){x("failed"),h(`触发重启失败: ${y instanceof Error?y.message:String(y)}`);return}}const E=Date.now();for(;Date.now()-E<ws;){await new Promise(y=>setTimeout(y,js));try{const y=await M.health.get();if(y.startedAt!==N){const c=d.current;d.current=0,i(c>0?y.startedAt:null),v(c),x(c>0?"pending":"idle");return}}catch{}}x("failed"),h("重启超时(30s 未恢复)。请检查日志或手动 baxian start -c <path>")},[v,x]);return e.jsx(qt.Provider,{value:{phase:u,count:r,error:m,flagDirty:S,triggerRestart:_},children:t})}function Ge(){const t=o.useContext(qt);if(!t)throw new Error("usePendingRestart must be used inside PendingRestartProvider");return t}const Es=[500,1e3,2e3,4e3,8e3,15e3,3e4];class Kt{constructor(s){Y(this,"attempts",0);Y(this,"timer",null);Y(this,"delaysMs");this.opts=s,this.delaysMs=s.delaysMs??Es}schedule(){if(this.timer||!this.shouldReconnect())return;const s=this.delaysMs[Math.min(this.attempts,this.delaysMs.length-1)];this.attempts+=1,this.timer=setTimeout(()=>{this.timer=null,this.shouldReconnect()&&this.opts.reconnect()},s)}cancel(){this.timer&&(clearTimeout(this.timer),this.timer=null)}reset(){this.attempts=0}shouldReconnect(){return this.opts.shouldReconnect?this.opts.shouldReconnect():!0}}let jt=0;function Cs(){jt++;const t=Math.random().toString(36).slice(2,8);return`sub-${Date.now().toString(36)}-${jt}-${t}`}function Rs(t){return Array.from(new TextEncoder().encode(t)).map(s=>s.toString(16).padStart(2,"0")).join("")}function As(){return`${location.protocol==="https:"?"wss":"ws"}://${location.host}/api/stream`}const Ts=(t,s)=>s&&s.length>0?new WebSocket(t,s):new WebSocket(t);class Is{constructor(s={}){Y(this,"wsUrl");Y(this,"wsFactory");Y(this,"tokenProvider");Y(this,"ws",null);Y(this,"subs",new Map);Y(this,"snapshotPending",new Set);Y(this,"preSubscribeQueue",new Map);Y(this,"outbox",[]);Y(this,"reconnectScheduler");Y(this,"explicitlyClosed",!1);this.wsUrl=s.wsUrl??As(),this.wsFactory=s.wsFactory??Ts,this.tokenProvider=s.tokenProvider??dt,this.reconnectScheduler=new Kt({reconnect:()=>this.openSocket(),shouldReconnect:()=>!this.explicitlyClosed&&this.subs.size>0})}subscribe(s){const r=Cs(),a={subscriberId:r,agentId:s.agentId,mode:s.mode,onSnapshot:s.onSnapshot,onData:s.onData,onError:s.onError,onSessionGone:s.onSessionGone};return this.subs.set(r,a),this.snapshotPending.add(r),this.preSubscribeQueue.set(r,[]),this.ensureSocket(),this.wsSendOrQueue({op:"subscribe",subscriberId:r,agentId:s.agentId,mode:s.mode}),{subscriberId:r,unsubscribe:()=>this.unsubscribe(r)}}send(s,r){if(this.subs.has(s)){if(this.snapshotPending.has(s)){this.outbox.push({op:"input",subscriberId:s,data:r});return}this.wsSendOrQueue({op:"input",subscriberId:s,data:r})}}resize(s,r,a){const n=this.subs.get(s);n&&(n.lastSize={cols:r,rows:a},!this.snapshotPending.has(s)&&this.wsSendOrQueue({op:"resize",subscriberId:s,cols:r,rows:a}))}ping(){this.wsSendOrQueue({op:"ping"})}close(){if(this.explicitlyClosed=!0,this.reconnectScheduler.cancel(),this.reconnectScheduler.reset(),this.ws){try{this.ws.close()}catch{}this.ws=null}this.subs.clear(),this.snapshotPending.clear(),this.preSubscribeQueue.clear(),this.outbox=[]}unsubscribe(s){this.subs.has(s)&&(this.subs.delete(s),this.snapshotPending.delete(s),this.preSubscribeQueue.delete(s),this.wsSendOrQueue({op:"unsubscribe",subscriberId:s}),this.subs.size===0&&this.teardownSocket())}teardownSocket(){if(this.reconnectScheduler.cancel(),this.reconnectScheduler.reset(),this.outbox=[],this.ws){try{this.ws.close()}catch{}this.ws=null}}ensureSocket(){this.explicitlyClosed||this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)||this.openSocket()}openSocket(){if(this.explicitlyClosed)return;this.reconnectScheduler.cancel();const s=this.tokenProvider(),r=s?[`baxian.token.${Rs(s)}`]:void 0;let a;try{a=this.wsFactory(this.wsUrl,r)}catch(n){console.warn("[pane-stream] WebSocket constructor threw:",n),this.scheduleReconnect();return}this.ws=a,a.onopen=()=>{if(a!==this.ws)return;this.reconnectScheduler.reset();for(const i of this.subs.values()){this.snapshotPending.add(i.subscriberId),this.preSubscribeQueue.set(i.subscriberId,[]),i.snapshotSeq=void 0;try{a.send(JSON.stringify({op:"subscribe",subscriberId:i.subscriberId,agentId:i.agentId,mode:i.mode}))}catch(u){console.warn("[pane-stream] resubscribe send failed:",u)}}const n=this.outbox;this.outbox=[];for(const i of n)if(i.op!=="subscribe"){if("subscriberId"in i&&i.subscriberId){if(!this.subs.has(i.subscriberId))continue;if(this.snapshotPending.has(i.subscriberId)&&i.op!=="unsubscribe"){this.outbox.push(i);continue}}try{a.send(JSON.stringify(i))}catch(u){console.warn("[pane-stream] outbox flush failed:",u)}}},a.onmessage=n=>{if(a!==this.ws)return;let i;try{const u=typeof n.data=="string"?n.data:String(n.data);i=JSON.parse(u)}catch{return}this.handleMessage(i)},a.onclose=()=>{a===this.ws&&(this.ws=null,!this.explicitlyClosed&&this.subs.size!==0&&this.scheduleReconnect())},a.onerror=()=>{}}scheduleReconnect(){this.reconnectScheduler.schedule()}wsSendOrQueue(s){if(this.ws&&this.ws.readyState===WebSocket.OPEN)try{this.ws.send(JSON.stringify(s));return}catch(r){console.warn("[pane-stream] send failed, will queue:",r)}this.outbox.push(s)}handleMessage(s){var r,a;switch(s.type){case"snapshot":this.handleSnapshot(s);break;case"subscribed":this.handleSubscribed(s);break;case"data":this.dispatch(s);break;case"session_gone":for(const n of[...this.subs.values()])n.agentId===s.agentId&&((r=n.onSessionGone)==null||r.call(n));break;case"error":{if(s.subscriberId){const n=this.subs.get(s.subscriberId);(a=n==null?void 0:n.onError)==null||a.call(n,{code:s.code,message:s.message})}else console.warn("[pane-stream] connection-level error:",s.code,s.message);break}}}handleSnapshot(s){const r=this.subs.get(s.subscriberId);r&&r.onSnapshot({cols:s.cols,rows:s.rows,data:s.data})}handleSubscribed(s){const r=this.subs.get(s.subscriberId);if(!r)return;r.snapshotSeq=s.snapshotSeq,r.lastSize||(r.lastSize={cols:s.cols,rows:s.rows}),this.snapshotPending.delete(s.subscriberId);const a=this.preSubscribeQueue.get(s.subscriberId);if(this.preSubscribeQueue.delete(s.subscriberId),a)for(const n of a)n.seq>s.snapshotSeq&&r.onData(n.data);r.mode==="full"&&r.lastSize&&this.wsSendOrQueue({op:"resize",subscriberId:r.subscriberId,cols:r.lastSize.cols,rows:r.lastSize.rows}),this.flushOutboxForSub(s.subscriberId)}flushOutboxForSub(s){if(this.outbox.length===0||!this.ws||this.ws.readyState!==WebSocket.OPEN)return;const r=[];for(const a of this.outbox)if("subscriberId"in a&&a.subscriberId===s&&a.op!=="subscribe")try{this.ws.send(JSON.stringify(a))}catch(n){console.warn("[pane-stream] flushOutboxForSub send failed:",n)}else r.push(a);this.outbox=r}dispatch(s){for(const r of this.subs.values())if(r.agentId===s.agentId)if(this.snapshotPending.has(r.subscriberId)){const a=this.preSubscribeQueue.get(r.subscriberId);a&&a.push({seq:s.seq,data:s.data})}else r.onData(s.data)}}let Je=null;function Ye(){return Je||(Je=new Is),Je}function $s(t){const{agentId:s,mode:r}=t,a=o.useRef(null),n=o.useRef({onSnapshot:t.onSnapshot,onData:t.onData,onError:t.onError,onSessionGone:t.onSessionGone});n.current={onSnapshot:t.onSnapshot,onData:t.onData,onError:t.onError,onSessionGone:t.onSessionGone},o.useEffect(()=>{const m=Ye().subscribe({agentId:s,mode:r,onSnapshot:h=>n.current.onSnapshot(h),onData:h=>n.current.onData(h),onError:h=>{var b,g;return(g=(b=n.current).onError)==null?void 0:g.call(b,h)},onSessionGone:()=>{var h,b;return(b=(h=n.current).onSessionGone)==null?void 0:b.call(h)}});return a.current=m.subscriberId,()=>{a.current=null,m.unsubscribe()}},[s,r]);const i=o.useCallback(f=>{const m=a.current;m&&Ye().send(m,f)},[]),u=o.useCallback((f,m)=>{const h=a.current;h&&Ye().resize(h,f,m)},[]);return{send:i,resize:u}}const Ds=[{key:"up",label:"上",path:"M12 5l-6 6m6-6l6 6m-6-6v14"},{key:"down",label:"下",path:"M12 19l6-6m-6 6l-6-6m6 6V5"},{key:"left",label:"左",path:"M5 12l6-6m-6 6l6 6m-6-6h14"},{key:"right",label:"右",path:"M19 12l-6-6m6 6l-6 6m6-6H5"}],Le=Object.fromEntries(Ds.map(t=>[t.key,t]));function Oe({arrow:t,onPress:s}){return e.jsx("button",{type:"button","aria-label":`方向键 ${t.label}`,"data-arrow":t.key,onMouseDown:r=>r.preventDefault(),onClick:()=>s(t.key),className:"flex h-8 w-8 items-center justify-center rounded border border-hairline bg-surface text-og-700 transition-colors hover:bg-og-100 hover:text-og-1000 active:bg-og-200",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:t.path})})})}function Ps({onKey:t,className:s}){return e.jsxs("div",{role:"group","aria-label":"终端方向键",className:s??"flex flex-none items-center justify-center gap-1 border-t border-hairline bg-page px-3 py-2",children:[e.jsx(Oe,{arrow:Le.left,onPress:t}),e.jsx(Oe,{arrow:Le.up,onPress:t}),e.jsx(Oe,{arrow:Le.down,onPress:t}),e.jsx(Oe,{arrow:Le.right,onPress:t})]})}const Ms=Math.floor(We/1024/1024);function Ls({agentId:t,className:s}){const r=o.useRef(null),[a,n]=o.useState(!1),{show:i}=fe(),u=async f=>{var h;const m=(h=f.target.files)==null?void 0:h[0];if(f.target.value="",!!m){if(m.size>We){i({kind:"error",title:"图片过大",body:`单张图片不能超过 ${Ms} MiB`});return}n(!0);try{await M.agents.uploadImage(t,m),i({kind:"success",title:"图片已插入",body:"路径已粘贴到终端输入,补充说明后回车"})}catch(b){const g=b instanceof Te||b instanceof Error?b.message:String(b);i({kind:"error",title:"图片上传失败",body:g})}finally{n(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button","aria-label":"上传图片",disabled:a,onMouseDown:f=>f.preventDefault(),onClick:()=>{var f;return(f=r.current)==null?void 0:f.click()},className:s??"flex h-8 w-8 items-center justify-center rounded border border-hairline bg-surface text-og-700 transition-colors hover:bg-og-100 hover:text-og-1000 active:bg-og-200 disabled:cursor-not-allowed disabled:opacity-50",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),e.jsx("circle",{cx:"9",cy:"9",r:"2"}),e.jsx("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})]})}),e.jsx("input",{ref:r,type:"file",accept:"image/*",className:"hidden",onChange:u})]})}const Os={up:"A",down:"B",right:"C",left:"D"};function _s(t,s){return(s?"\x1BO":"\x1B[")+Os[t]}const wt=18,Fs=250,Bs=256*1024,Nt="#fdfdfd",zs='ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',Hs={background:Nt,foreground:"#474c55",cursor:"#1348dc",cursorAccent:Nt,selectionBackground:"#eaf0ff",black:"#0d0d0f",red:"#b91c1c",green:"#15803d",yellow:"#b45309",blue:"#1348dc",magenta:"#9333ea",cyan:"#0e7490",white:"#474c55",brightBlack:"#878e9b",brightRed:"#dc2626",brightGreen:"#16a34a",brightYellow:"#d97706",brightBlue:"#3080ff",brightMagenta:"#a855f7",brightCyan:"#0891b2",brightWhite:"#0d0d0f"},Us=/\x1b\[(?:\?[\d;]*c|>[\d;]*c|\??\d+;\d+R|\d+n)/g;function Ws(t){return t.replace(Us,"")}function Ee({agentId:t,mode:s,interactive:r=!1,maxLines:a,className:n,autoFocus:i=!0,deferFullUntilFocus:u=!1,arrowKeys:f=!1}){const m=o.useRef(null),h=o.useRef(null),b=o.useRef(null),g=o.useRef(null),d=o.useRef(!1),v=o.useRef(""),I=o.useRef([]),x=o.useRef(0),p=o.useRef(null),S=o.useRef(null),_=o.useRef(Promise.resolve()),N=o.useRef(0),[E,y]=o.useState(null),[c,$]=o.useState(!1),F=`${t}\0${s}\0${u?"1":"0"}`,[z,B]=o.useState({key:F,active:!1}),j=z.key===F&&z.active,L=s==="full"&&u,D=L&&!j?"preview":s,U=r&&D==="full",W=(w,P)=>P.length===0?Promise.resolve():new Promise(R=>{try{w.write(P,()=>R())}catch(ee){console.warn("[pane-terminal] write failed:",ee),R()}}),K=D==="preview",V=()=>{if(!K)return;const w=m.current,P=h.current;if(!w||!P)return;const ee=(P.buffer.active.cursorY+1)*wt;w.scrollTop=Math.max(0,ee-w.clientHeight)},se=(w,P)=>{_.current=_.current.then(async()=>{const R=h.current;if(!(!R||P!==N.current))try{await w(R),U&&R.scrollToBottom(),V()}catch(ee){console.warn("[pane-terminal] terminal task failed:",ee)}}).catch(R=>{console.warn("[pane-terminal] write chain failed:",R)})},l=(w,P)=>{se(R=>W(R,w),P)},T=()=>{p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),S.current!==null&&(clearTimeout(S.current),S.current=null)},H=()=>{T(),I.current=[],x.current=0},Z=()=>{T();const w=I.current;w.length!==0&&(I.current=[],x.current=0,l(w.join(""),N.current))},ne=w=>{if(w.length!==0){if(I.current.push(w),x.current+=w.length,x.current>=Bs){Z();return}p.current===null&&(p.current=requestAnimationFrame(Z)),S.current===null&&(S.current=setTimeout(Z,Fs))}},{send:te,resize:C}=$s({agentId:t,mode:D,onSnapshot:({cols:w,rows:P,data:R})=>{if(h.current)try{const ce=N.current+1;N.current=ce,H(),se(async de=>{var le;de.reset(),U?((le=g.current)==null||le.call(g),await W(de,R)):(w>0&&P>0&&de.resize(w,P),await W(de,R))},ce)}catch(ce){console.warn("[pane-terminal] snapshot write failed:",ce)}},onData:w=>{ne(w)},onError:w=>y(`${w.code}: ${w.message}`),onSessionGone:()=>$(!0)});o.useEffect(()=>{y(null),$(!1)},[t,D]),o.useEffect(()=>{v.current=""},[F]),o.useEffect(()=>{if(D!=="full")return;const w=v.current;w.length!==0&&(v.current="",te(w))},[te,D]);const Q=o.useCallback(()=>{!r||!L||j||(d.current=!0,B({key:F,active:!0}))},[F,j,r,L]),G=o.useCallback(w=>{const P=Ws(w);if(P.length!==0){if(L&&(!j||v.current.length>0)){v.current+=P,Q();return}te(P)}},[Q,j,te,L]);o.useEffect(()=>{const w=m.current;if(!w)return;let P=!1;const R=new is.Terminal({cursorBlink:r,disableStdin:!r,theme:Hs,fontFamily:zs,fontSize:13,lineHeight:1.4,scrollback:D==="full"?5e3:1e3}),ee=new cs.FitAddon;if(R.loadAddon(ee),R.open(w),h.current=R,b.current=ee,r&&(i||d.current)){d.current=!1;try{R.focus()}catch{}}r&&R.onData(G);const ce=()=>w.clientWidth>0&&w.clientHeight>0,de=(he=!1)=>{if(!ce())return!1;const ge=R.cols,De=R.rows;try{ee.fit()}catch{return!1}return U&&R.scrollToBottom(),R.cols>0&&R.rows>0&&(he||R.cols!==ge||R.rows!==De)&&C(R.cols,R.rows),!0};g.current=U?()=>de(!0):null;let le=null,ie=null,k=null,q=0;const re=()=>{le||(le=new ResizeObserver(()=>{ie&&clearTimeout(ie),ie=setTimeout(()=>{ie=null,de()},100)}),le.observe(w))},J=()=>{k=requestAnimationFrame(()=>{if(k=null,!(P||!U)){if(de(!0)){re();return}if(q++<5){J();return}re()}})};return J(),()=>{P=!0,k!==null&&cancelAnimationFrame(k),p.current!==null&&(cancelAnimationFrame(p.current),p.current=null),S.current!==null&&(clearTimeout(S.current),S.current=null),N.current++,I.current=[],x.current=0,_.current=Promise.resolve(),ie&&clearTimeout(ie),le==null||le.disconnect(),h.current=null,b.current=null,g.current=null;try{R.dispose()}catch(he){console.warn("[pane-terminal] dispose failed:",he)}}},[t,i,U,G,r,D,C]);const oe=()=>{var w;if(r){Q();try{(w=h.current)==null||w.focus()}catch{}}};o.useEffect(()=>{if(r)return;const w=m.current;if(!w)return;const P=R=>{R.stopPropagation()};return w.addEventListener("wheel",P,{capture:!0,passive:!0}),()=>w.removeEventListener("wheel",P,{capture:!0})},[r]);const O=a&&a>0?{maxHeight:`${a*wt}px`}:void 0;return e.jsxs("div",{className:n??"flex flex-col h-full w-full min-h-0 bg-[#fdfdfd]",children:[(E||c)&&e.jsx("div",{className:"border-b border-[#fecaca] bg-[#fef2f2] px-3 py-1 font-mono text-[11px] text-danger",children:c?"session ended":E}),e.jsx("div",{className:"flex flex-1 min-h-0 px-2 py-1.5",style:O,children:e.jsx("div",{ref:m,className:"flex-1 min-h-0 overflow-hidden",onMouseDown:oe})}),r&&f&&e.jsxs("div",{className:"grid grid-cols-[1fr_auto_1fr] gap-2 flex-none items-center border-t border-hairline bg-page px-3 py-2",children:[e.jsx("div",{className:"flex items-center",children:e.jsx(Ls,{agentId:t})}),e.jsx(Ps,{className:"flex items-center justify-center gap-1",onKey:w=>{var R,ee;const P=!!((ee=(R=h.current)==null?void 0:R.modes)!=null&&ee.applicationCursorKeysMode);G(_s(w,P))}})]})]})}const Qs={unknown:{label:"Unknown",cls:"pill pill-idle"},idle:{label:"Idle",cls:"pill pill-idle"},pending:{label:"Pending user",cls:"pill pill-warn"},working:{label:"Working",cls:"pill pill-live"},waiting:{label:"Waiting",cls:"pill pill-review"},error:{label:"Error",cls:"pill pill-warn"}},Gs={present:{label:"Session present",modifier:"status-dot--healthy"},absent:{label:"No session",modifier:"status-dot--warn"},unreachable:{label:"Host unreachable",modifier:"status-dot--danger"},unknown:{label:"Session unknown",modifier:"status-dot--warn"},starting:{label:"Starting session",modifier:"status-dot--info"}};function qs({state:t}){const{label:s,modifier:r}=Gs[t];return e.jsx("span",{role:"img","aria-label":s,title:s,className:`status-dot ml-2 ${r}`})}function Ks({agent:t,projectId:s,role:r,runtime:a,onDeleted:n,pendingRestart:i=!1,terminalLoading:u=!1,showTaskBinding:f=!0,terminalMode:m="activity-preview",active:h,onActivate:b}){var he,ge,De,mt,xt,pt,bt;const[g,d]=o.useState(!1),[v,I]=o.useState(null),{show:x}=fe(),{flagDirty:p}=Ge(),[S,_]=o.useState(!1),[N,E]=o.useState(null),[y,c]=o.useState(!1),[$,F]=o.useState(!1),[z,B]=o.useState(!1),[j,L]=o.useState(!1),[D,U]=o.useState(!1),W=o.useRef(null),K=o.useRef(null),V=o.useId(),se=o.useId();o.useEffect(()=>{if(!D)return;const A=we=>{var gt,vt;const xe=we.target;xe&&((gt=K.current)!=null&>.contains(xe)||(vt=W.current)!=null&&vt.contains(xe)||U(!1))},me=we=>{var xe;we.key==="Escape"&&(U(!1),(xe=W.current)==null||xe.focus())};return document.addEventListener("mousedown",A),document.addEventListener("keydown",me),()=>{document.removeEventListener("mousedown",A),document.removeEventListener("keydown",me)}},[D]),o.useEffect(()=>{var me;if(!D)return;const A=(me=K.current)==null?void 0:me.querySelector('[role="menuitem"]:not([disabled])');A==null||A.focus()},[D]);const l=(he=t.binding)==null?void 0:he.taskId,T=((ge=t.binding)==null?void 0:ge.status)==="awaiting_human",H=!!((De=t.binding)!=null&&De.creationToken)&&!((mt=t.binding)!=null&&mt.paneId)&&!T&&t.reason!=="PENDING_HUMAN",Z=H?{label:"Starting",cls:"pill pill-review"}:Qs[t.runtimeStatus],ne=H?"starting":t.tmuxSessionStatus,te=m==="activity-preview"&&!H&&(t.runtimeStatus==="working"||t.runtimeStatus==="pending"),C=m==="embedded-full",Q=C&&typeof b=="function",G=Q&&h===!0,oe=u||i||H,O=u?"Agent 状态加载中":i?"重启 baxian server 后可用":"Agent 正在启动",w=it(a),P=async()=>{d(!0),I(null);try{await M.agents.stop(t.id)}catch(A){I(A instanceof Error?A.message:String(A))}finally{d(!1)}},R=async()=>{if(l&&window.confirm(`请 QA 对 task ${l} 重审?这会让 QA agent 立即开始新一轮 review(reviewRound +1)。`)){F(!0);try{const A=await M.tasks.review(l);x({kind:"success",title:`已派 QA 重审 (round ${A.reviewRound})`})}catch(A){x({kind:"error",title:"Review 派发失败",body:A instanceof Error?A.message:String(A)})}finally{F(!1)}}},ee=async()=>{L(!0);try{(await M.projects.bootstrap(s)).ok?x({kind:"success",title:"Bootstrap retry 完成",body:"agent 状态将在下一次刷新生效。"}):x({kind:"warn",title:"Bootstrap retry 仍失败",body:"看一下红色错误卡的最新原因,按提示修复后再试。"})}catch(A){x({kind:"error",title:"Bootstrap retry 失败",body:A instanceof Error?A.message:String(A)})}finally{L(!1)}},ce=async()=>{if(window.confirm(`确认 Resume Agent ${t.id}?baxian 会清除 awaiting_human 状态,agent 重新可派遣。`)){B(!0);try{const A=await M.projects.resumeAgent(s,t.id);x({kind:"success",title:`Agent ${t.id} 已 Resume`,body:A.releasedBinding?"原任务已释放,agent 可接新任务。":"保留绑定(原任务仍 active)。"})}catch(A){x({kind:"error",title:"Resume 失败",body:A instanceof Error?A.message:String(A)})}finally{B(!1)}}},de=async()=>{c(!0);try{await M.agents.compact(t.id),x({kind:"success",title:`已向 Agent ${t.id} 发送 /compact`})}catch(A){x({kind:"error",title:"Compact 失败",body:A instanceof Error?A.message:String(A)})}finally{c(!1)}},le=async()=>{if(window.confirm(`确认删除 Agent ${t.id}?此操作不可撤销`)){_(!0),E(null);try{const A=await M.projects.deleteAgent(s,t.id);A!=null&&A.restartRequired&&p();const me=(A==null?void 0:A.removed)??[t.id];if(me.length>1){const we=me.filter(xe=>xe!==t.id).join(", ");x({kind:"warn",title:`已删除 Agent ${t.id}`,body:`配对的 QA Agent ${we} 也被一并移除。`})}else x({kind:"success",title:`Agent ${t.id} 已删除`});n==null||n()}catch(A){E(A instanceof Error?A.message:String(A))}finally{_(!1)}}},ie=Q&&!oe&&!G,k=["card flex h-full min-w-0 flex-col p-4",G?"ring-2 ring-accent":""].filter(Boolean).join(" "),q=["mb-2 mt-3 h-80 min-h-0 overflow-hidden border border-hairline bg-surface",ie?"cursor-pointer":""].filter(Boolean).join(" "),re=ie?()=>b==null?void 0:b():void 0,J=ie?A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),b==null||b())}:void 0;return e.jsxs("div",{className:k,"data-agent-card":Q?t.id:void 0,children:[e.jsxs("div",{className:"mb-3 flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"shrink-0 font-mono text-[11px] font-medium uppercase tracking-[0.05em] text-og-500",children:r}),e.jsx("span",{className:"min-w-0 truncate whitespace-nowrap font-display text-[14px] font-semibold text-og-1000",title:ct(t.id,a),children:t.id}),w&&e.jsxs("span",{className:"hidden shrink-0 whitespace-nowrap text-[12px] text-og-400 sm:inline",title:w,children:["(",w,")"]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-1",children:[T&&e.jsx("span",{className:"pill pill-warn",title:((xt=t.binding)==null?void 0:xt.awaitingReason)??"需人工处理",children:"Held"}),e.jsx("span",{className:Z.cls,children:Z.label}),t.stale&&e.jsx("span",{className:"pill pill-warn",title:t.observedAt?`Last observed at ${t.observedAt}`:void 0,children:"Stale"}),e.jsx(qs,{state:ne})]})]}),H&&e.jsx("div",{className:"mb-2 rounded-md border border-accent-soft bg-accent-soft/40 px-2.5 py-2 text-[12px] text-accent",children:"Agent 正在启动,终端可用后会自动刷新。"}),T&&e.jsxs("div",{className:"mb-2 rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-2.5 py-2 text-[12px] text-warn",children:[e.jsx("span",{className:"font-mono",children:(pt=t.binding)==null?void 0:pt.awaitingPhase}),((bt=t.binding)==null?void 0:bt.awaitingReason)&&e.jsxs("span",{children:[" · ",t.binding.awaitingReason]})]}),!H&&t.runtimeStatus==="pending"&&e.jsxs("div",{className:"mb-2 space-y-1 rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-2.5 py-2 text-[12px] text-warn",children:[e.jsx("div",{className:"font-medium",children:"等待人工介入"}),e.jsxs("div",{children:["Agent 正在等待人工输入。请打开 ",e.jsx(Re,{to:`/terminal/${t.id}`,className:"text-accent hover:text-accent-hover underline",children:"Terminal"})," 处理; 处理完后状态会随下一次观测刷新。"]})]}),t.latestError&&e.jsxs("div",{className:"mb-2 space-y-1 rounded-md border border-[#fecaca] bg-[#fef2f2] px-2.5 py-2 text-[12px] text-danger",children:[e.jsx("div",{className:"break-words font-medium",children:t.latestError.message}),e.jsxs("div",{className:"font-mono text-[11px] opacity-80",children:[t.latestError.reason," · ",t.latestError.occurredAt]})]}),t.latestBootstrapError&&e.jsxs("div",{className:"mb-2 space-y-1 rounded-md border border-[#fecaca] bg-[#fef2f2] px-2.5 py-2 text-[12px] text-danger",children:[e.jsx("div",{className:"break-words font-medium",children:t.latestBootstrapError.message}),t.latestBootstrapError.recommendation&&e.jsx("div",{className:"break-words",children:t.latestBootstrapError.recommendation}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"truncate font-mono text-[11px] opacity-80",children:[t.latestBootstrapError.reason," · ",t.latestBootstrapError.occurredAt]}),e.jsx("button",{type:"button",onClick:ee,disabled:j,className:"btn-secondary shrink-0 !border-[#fecaca] !text-danger hover:!bg-[#fef2f2] hover:!border-danger hover:!text-danger",children:j?"Retrying…":"Retry bootstrap"})]})]}),f&&l&&e.jsxs("div",{className:"mb-2 text-[12px] text-og-500",children:["Task: ",e.jsx("span",{className:"font-mono text-og-700",children:l})]}),te&&e.jsx("div",{className:"mb-2 overflow-hidden border border-hairline bg-surface",children:e.jsx(Ee,{agentId:t.id,mode:"preview",maxLines:6,interactive:!1})}),C&&e.jsx("div",{className:q,role:ie?"button":void 0,tabIndex:ie?0:void 0,"aria-label":ie?`激活 ${t.id} 终端`:void 0,onClick:re,onKeyDown:J,children:oe?e.jsx("div",{className:"flex h-full items-center justify-center px-3 text-[13px] text-og-500",children:O}):Q?G?e.jsx(Ee,{agentId:t.id,mode:"full",interactive:!0,autoFocus:!0}):e.jsx(Ee,{agentId:t.id,mode:"preview",interactive:!1}):e.jsx(Ee,{agentId:t.id,mode:"full",interactive:!0,autoFocus:!1,deferFullUntilFocus:!0})}),i&&e.jsx("div",{className:"mb-2 rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-2.5 py-1.5 text-[12px] text-warn",children:"⚠️ 重启 baxian server 后生效"}),e.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-x-auto scrollbar-none",children:[oe?e.jsx("span",{className:"shrink-0 cursor-not-allowed text-[13px] text-og-400",title:O,children:"Terminal"}):e.jsx(Re,{to:`/terminal/${t.id}`,className:"btn-secondary shrink-0",children:"Terminal"}),!i&&t.runtimeStatus==="working"&&e.jsx("button",{onClick:P,disabled:g,className:"btn-ghost shrink-0 !text-danger hover:!bg-[#fef2f2]",children:g?"Stopping…":"Stop"}),T&&e.jsx("button",{type:"button",onClick:ce,disabled:z,title:"清除 awaiting_human 状态,让 agent 重新可派遣",className:"btn-ghost shrink-0 !text-warn hover:!bg-[#fef3c7]/60",children:z?"Resuming…":"Resume"}),!i&&l&&r==="dev"&&e.jsx("button",{type:"button",onClick:R,disabled:$,title:`让 QA 立即对 task ${l} 跑一轮 review(需要该 task 已有 PR)`,className:"btn-ghost shrink-0 !text-accent hover:!bg-accent-soft",children:$?"Dispatching…":"Call review"})]}),e.jsxs("div",{className:"relative shrink-0",children:[e.jsx("button",{ref:W,id:se,type:"button",onClick:()=>U(A=>!A),disabled:S,"aria-haspopup":"menu","aria-expanded":D,"aria-controls":V,"aria-label":`Agent ${t.id} 操作菜单`,className:"flex h-8 w-8 items-center justify-center rounded text-og-500 transition-colors hover:bg-og-100 hover:text-og-1000 disabled:cursor-not-allowed disabled:opacity-50",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"1"}),e.jsx("circle",{cx:"12",cy:"5",r:"1"}),e.jsx("circle",{cx:"12",cy:"19",r:"1"})]})}),D&&e.jsxs("div",{ref:K,id:V,role:"menu","aria-labelledby":se,className:"absolute right-0 bottom-full z-10 mb-1 min-w-[140px] rounded-md border border-hairline bg-surface py-1 shadow-md",children:[e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{U(!1),de()},disabled:y||S,title:"向 agent runtime 发送 /compact 压缩上下文",className:"block w-full px-3 py-1.5 text-left text-[13px] text-og-1000 hover:bg-og-100 disabled:opacity-50 disabled:cursor-not-allowed",children:y?"Compacting…":"compact"}),e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{U(!1),le()},disabled:S||y,className:"block w-full px-3 py-1.5 text-left text-[13px] text-danger hover:bg-[#fef2f2] disabled:opacity-50 disabled:cursor-not-allowed",children:S?"Deleting…":"Delete"})]})]})]}),v&&e.jsx("div",{className:"mt-1.5 break-words text-[12px] text-danger",children:v}),N&&e.jsx("div",{className:"mt-1.5 break-words text-[12px] text-danger",children:N})]})}const Vs={sm:"max-w-md",md:"max-w-lg",lg:"max-w-2xl"},kt='input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [href], [tabindex]:not([tabindex="-1"])';function ve({open:t,onClose:s,title:r,titleContent:a,children:n,footer:i,size:u="md",dismissOnBackdrop:f=!0}){const m=o.useRef(null),h=o.useRef(null),b=o.useRef(!1),g=o.useRef(s);return o.useEffect(()=>{g.current=s},[s]),o.useEffect(()=>{if(!t)return;h.current=document.activeElement;const d=x=>{if(x.key==="Escape"){g.current();return}if(x.key!=="Tab")return;const p=m.current;if(!p)return;const S=Array.from(p.querySelectorAll(kt)).filter(y=>y.offsetParent!==null||y===document.activeElement);if(S.length===0){x.preventDefault();return}const _=S[0],N=S[S.length-1],E=document.activeElement;x.shiftKey&&(E===_||!p.contains(E))?(x.preventDefault(),N.focus()):!x.shiftKey&&(E===N||!p.contains(E))&&(x.preventDefault(),_.focus())};document.addEventListener("keydown",d);const v=document.body.style.overflow;document.body.style.overflow="hidden";const I=m.current;if(I){const x=I.querySelector(kt);x==null||x.focus()}return()=>{var x,p;document.removeEventListener("keydown",d),document.body.style.overflow=v,(p=(x=h.current)==null?void 0:x.focus)==null||p.call(x)}},[t]),t?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-og-1000/45 px-3 sm:px-4",onMouseDown:f?d=>{b.current=d.target===d.currentTarget}:void 0,onClick:f?d=>{d.target===d.currentTarget&&b.current&&g.current()}:void 0,role:"presentation",children:e.jsxs("div",{ref:m,className:`flex w-full ${Vs[u]} max-h-[90dvh] flex-col overflow-hidden rounded-lg border border-og-100 bg-surface shadow-modal`,onClick:d=>d.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":r,children:[e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-b border-hairline px-5 py-3",children:[e.jsx("h2",{title:r,className:"min-w-0 truncate font-display text-[15px] font-semibold tracking-tight text-og-1000",children:a??r}),e.jsx("button",{type:"button",onClick:()=>g.current(),className:"-mr-1 flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-og-400 transition-colors hover:bg-og-50 hover:text-og-800","aria-label":"Close",children:"✕"})]}),e.jsx("div",{className:"min-h-0 flex-1 overflow-auto px-5 py-4",children:n}),i&&e.jsx("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-hairline px-5 py-3",children:i})]})}):null}const St=200,Et=16e3,Js="baxian.draft.createTask:";function nt(t){return`${Js}${t??"*"}`}function Ct(t){try{const s=localStorage.getItem(t);if(!s)return null;const r=JSON.parse(s);if(!r||typeof r!="object")return null;const a=r,n=typeof a.title=="string"?a.title:"",i=typeof a.description=="string"?a.description:"",u=typeof a.projectId=="string"?a.projectId:"",f=typeof a.preferredAgentId=="string"?a.preferredAgentId:"",m=typeof a.updatedAt=="number"?a.updatedAt:void 0;return!n.trim()&&!i.trim()?null:{title:n,description:i,projectId:u,preferredAgentId:f,updatedAt:m}}catch{return null}}function Ys(t,s){const r=!s.title.trim()&&!s.description.trim();try{r?localStorage.removeItem(t):localStorage.setItem(t,JSON.stringify({...s,updatedAt:Date.now()}))}catch{}}function Rt(t){try{localStorage.removeItem(t)}catch{}}function Xs(t){const s=nt(t),r=Ct(s);if(!t)return r;const a=nt(void 0),n=Ct(a);if(!n||n.projectId!==t)return r;const i=!r||(n.updatedAt??0)>(r.updatedAt??0);if(i)try{localStorage.setItem(s,JSON.stringify(n))}catch{return n}try{localStorage.removeItem(a)}catch{}return i?n:r}const _e="w-full rounded-md border border-og-100 bg-surface px-2.5 py-1.5 text-[13px] text-og-800 placeholder:text-og-400 focus:border-accent focus:outline-none focus:ring-[3px] focus:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-50",Ne="mb-1.5 block text-[12px] font-medium text-og-700",At="mt-1 text-right text-[12px] text-og-400",Zs=Math.floor(We/1024/1024);function ut(t){const s=t.mode==="edit",{show:r}=fe(),a=s?t.task.projectId:t.projectId,n=s?t.task.title:"",i=s?t.task.description:"",u=s?t.task.preferredAgentId:"",[f,m]=o.useState([]),[h,b]=o.useState([]),[g,d]=o.useState(a??""),[v,I]=o.useState(u),[x,p]=o.useState(n),[S,_]=o.useState(i),[N,E]=o.useState([]),y=o.useRef(null),[c,$]=o.useState(!1),[F,z]=o.useState(null),[B,j]=o.useState(!1),L=o.useRef(0),D=o.useRef(0),U=o.useRef(0),W=o.useRef(new Set),K=s?null:nt(a);o.useEffect(()=>{if(!t.open)return;L.current+=1,D.current+=1;const k=L.current;m([]),b([]),W.current=new Set;const q=K?Xs(a):null;q&&W.current.add(q.projectId),d(a??(q==null?void 0:q.projectId)??""),I((q==null?void 0:q.preferredAgentId)||u),p((q==null?void 0:q.title)||n),_((q==null?void 0:q.description)||i),j(q!==null),z(null),$(!1),E([]),Promise.all([M.projects.list(),M.agents.list()]).then(([re,J])=>{k===L.current&&(m(re),b(J))}).catch(re=>{k===L.current&&z(re instanceof Error?re.message:String(re))})},[t.open,a,n,i,u,K]),o.useEffect(()=>{if(!(!t.open||!K)){if(U.current!==D.current){U.current=D.current;return}Ys(K,{title:x,description:S,projectId:g,preferredAgentId:v})}},[t.open,K,x,S,g,v]);const V=o.useMemo(()=>f.find(k=>k.id===g)??null,[f,g]),se=o.useMemo(()=>V?V.agent.flat().filter(k=>k.role==="dev"):[],[V]),l=o.useMemo(()=>new Set(h.map(k=>k.id)),[h]),T=o.useMemo(()=>se.filter(k=>l.has(k.id)),[se,l]),H=o.useMemo(()=>se.filter(k=>!l.has(k.id)),[se,l]);o.useEffect(()=>{s||V!==null&&v!==""&&!T.find(k=>k.id===v)&&I("")},[V,T,v,s]),o.useEffect(()=>{s||V&&T.length!==0&&(W.current.has(V.id)||(W.current.add(V.id),I(k=>k===""?T[0].id:k)))},[s,V,T]);const Z=!s||T.find(k=>k.id===v),ne=s&&!Z&&!!v,te=ne&&H.some(k=>k.id===v),C=te?`当前 dev "${v}" 在 baxian.json 中存在但 runtime 未加载,可能是手动编辑过配置文件;重启 server 可拉起`:ne?`当前 dev "${v}" 不在 runtime(可能已从 project 配置移除);保存可能失败,请确认或选择新 dev`:!g||T.length>0?null:H.length>0?"baxian.json 里有 dev agent 但 runtime 未加载(可能是手动编辑过配置);重启 server 后生效":null,Q=x.trim(),G=S.trim(),O=!!g&&Q.length>0&&G.length>0&&!c,w=()=>{c||t.onClose()},P=()=>{K&&(Rt(K),d(a??""),I(u),p(n),_(i),z(null),j(!1))},R=async k=>{var q,re;if(k.preventDefault(),!!O){$(!0),z(null);try{if(t.mode==="edit"){const J=await M.tasks.update(t.task.id,{title:Q,description:G,preferredAgentId:v});r({kind:"success",title:"任务已更新"}),(q=t.onUpdated)==null||q.call(t,J),t.onClose()}else{const J=N.length?await Promise.all(N.map(async ge=>({dataBase64:await Qt(ge),filename:ge.name}))):void 0,he=await M.tasks.create({projectId:g,title:Q,description:G,preferredAgentId:v,...J?{images:J}:{}});K&&Rt(K),r({kind:"success",title:"任务已创建"}),(re=t.onCreated)==null||re.call(t,he),t.onClose()}}catch(J){z(J instanceof Error?J.message:String(J))}finally{$(!1)}}},ee=k=>{const q=Array.from(k.target.files??[]);if(k.target.value="",q.length===0)return;const re=q.filter(J=>J.size>We?(r({kind:"error",title:"图片过大",body:`${J.name} 超过 ${Zs} MiB`}),!1):!0);E(J=>(J.length+re.length>Pe&&r({kind:"warn",title:`最多 ${Pe} 张图片`}),[...J,...re].slice(0,Pe)))},ce=k=>E(q=>q.filter((re,J)=>J!==k)),de=s?"编辑 Task":"新建 Task",le=s?c?"保存中…":"保存":c?"创建中…":"创建",ie=!s&&!a;return e.jsx(ve,{open:t.open,onClose:w,title:de,size:"md",dismissOnBackdrop:!1,footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:w,disabled:c,className:"btn-secondary",children:"取消"}),e.jsx("button",{type:"submit",form:"create-task-form",disabled:!O,className:"btn-primary",children:le})]}),children:e.jsxs("form",{id:"create-task-form",onSubmit:R,className:"space-y-3",children:[!s&&B&&e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-accent-soft bg-accent-soft/30 px-3 py-2 text-[12px] text-accent",children:[e.jsx("span",{children:"已恢复上次未提交的草稿"}),e.jsx("button",{type:"button",onClick:P,className:"shrink-0 underline hover:text-accent-hover",children:"丢弃"})]}),F&&e.jsx("div",{className:"rounded-md border border-[#fecaca] bg-[#fef2f2] px-3 py-2 text-[13px] text-danger",children:F}),ie&&e.jsxs("div",{children:[e.jsx("label",{className:Ne,htmlFor:"task-project",children:"Project"}),e.jsxs("select",{id:"task-project",value:g,onChange:k=>d(k.target.value),className:_e,disabled:c,required:!0,children:[e.jsx("option",{value:"",disabled:!0,children:"选择项目"}),f.map(k=>e.jsx("option",{value:k.id,children:k.id},k.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:Ne,htmlFor:"task-dev",children:"Dev Agent"}),e.jsxs("select",{id:"task-dev",value:v,onChange:k=>I(k.target.value),className:_e,disabled:c,children:[e.jsx("option",{value:"",children:"暂不指定"}),ne&&e.jsxs("option",{value:v,children:[v," ",te?"(待重启)":"(不在 runtime)"]}),T.map(k=>e.jsx("option",{value:k.id,children:k.id},k.id))]}),C&&e.jsx("div",{className:"mt-1 text-[12px] text-warn",children:C})]}),e.jsxs("div",{children:[e.jsx("label",{className:Ne,htmlFor:"task-title",children:"Title"}),e.jsx("input",{id:"task-title",type:"text",value:x,onChange:k=>p(k.target.value),maxLength:St,className:_e,placeholder:"一句话描述要做什么",disabled:c,required:!0}),e.jsxs("div",{className:At,children:[x.length," / ",St]})]}),e.jsxs("div",{children:[e.jsx("label",{className:Ne,htmlFor:"task-description",children:"Description"}),e.jsx("textarea",{id:"task-description",value:S,onChange:k=>_(k.target.value),maxLength:Et,rows:8,className:`${_e} font-mono text-[12px]`,placeholder:"详细描述任务,支持 markdown",disabled:c,required:!0}),e.jsxs("div",{className:At,children:[S.length," / ",Et]})]}),!s&&e.jsxs("div",{children:[e.jsx("label",{className:Ne,children:"图片(可选)"}),e.jsx("button",{type:"button",onClick:()=>{var k;return(k=y.current)==null?void 0:k.click()},disabled:c||N.length>=Pe,className:"btn-secondary",children:"添加图片"}),e.jsx("input",{ref:y,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:ee}),N.length>0&&e.jsx("ul",{className:"mt-2 space-y-1",children:N.map((k,q)=>e.jsxs("li",{className:"flex items-center justify-between rounded-md border border-og-100 bg-surface px-2.5 py-1.5",children:[e.jsx("span",{title:k.name,className:"truncate text-[12px] text-og-700",children:k.name}),e.jsx("button",{type:"button","aria-label":`移除图片 ${k.name}`,onClick:()=>ce(q),disabled:c,className:"ml-2 shrink-0 text-og-400 transition-colors hover:text-danger",children:"✕"})]},`${k.name}-${q}`))})]})]})})}function en(t){return Array.from(new TextEncoder().encode(t)).map(s=>s.toString(16).padStart(2,"0")).join("")}function tn(){return`${location.protocol==="https:"?"wss":"ws"}://${location.host}/api/realtime`}const sn=(t,s)=>s&&s.length>0?new WebSocket(t,s):new WebSocket(t);class nn{constructor(s={}){Y(this,"wsUrl");Y(this,"wsFactory");Y(this,"tokenProvider");Y(this,"ws",null);Y(this,"topics",new Map);Y(this,"cache",new Map);Y(this,"outbox",[]);Y(this,"reconnectScheduler");Y(this,"explicitlyClosed",!1);this.wsUrl=s.wsUrl??tn(),this.wsFactory=s.wsFactory??sn,this.tokenProvider=s.tokenProvider??dt,this.reconnectScheduler=new Kt({reconnect:()=>this.openSocket(),shouldReconnect:()=>!this.explicitlyClosed&&this.topics.size>0})}subscribe(s,r,a){let n=this.topics.get(s);const i=!n;return n||(n={data:new Set,error:new Set},this.topics.set(s,n)),n.data.add(r),a&&n.error.add(a),i?(this.ensureSocket(),this.wsSendOrQueue({op:"subscribe",topic:s})):this.cache.has(s)&&queueMicrotask(()=>{var u;(u=this.topics.get(s))!=null&&u.data.has(r)&&this.cache.has(s)&&r(this.cache.get(s))}),()=>this.unsubscribe(s,r,a)}close(){if(this.explicitlyClosed=!0,this.reconnectScheduler.cancel(),this.reconnectScheduler.reset(),this.ws){try{this.ws.close()}catch{}this.ws=null}this.topics.clear(),this.cache.clear(),this.outbox=[]}unsubscribe(s,r,a){const n=this.topics.get(s);n&&(n.data.delete(r),a&&n.error.delete(a),n.data.size===0&&n.error.size===0&&(this.topics.delete(s),this.cache.delete(s),this.wsSendOrQueue({op:"unsubscribe",topic:s}),this.topics.size===0&&this.teardownSocket()))}teardownSocket(){if(this.reconnectScheduler.cancel(),this.reconnectScheduler.reset(),this.outbox=[],this.ws){try{this.ws.close()}catch{}this.ws=null}}ensureSocket(){this.explicitlyClosed||this.ws&&(this.ws.readyState===WebSocket.OPEN||this.ws.readyState===WebSocket.CONNECTING)||this.openSocket()}openSocket(){if(this.explicitlyClosed)return;this.reconnectScheduler.cancel();const s=this.tokenProvider(),r=s?[`baxian.token.${en(s)}`]:void 0;let a;try{a=this.wsFactory(this.wsUrl,r)}catch(i){console.warn("[events-client] WebSocket constructor threw:",i),this.broadcastConnectionError({code:"connection_failed",message:i instanceof Error?i.message:"WebSocket constructor threw"}),this.scheduleReconnect();return}this.ws=a;let n=!1;a.onopen=()=>{if(a!==this.ws)return;n=!0,this.reconnectScheduler.reset();for(const u of this.topics.keys())try{a.send(JSON.stringify({op:"subscribe",topic:u}))}catch(f){console.warn("[events-client] resubscribe send failed:",f)}const i=this.outbox;this.outbox=[];for(const u of i)if(!(u.op==="subscribe"||u.op==="unsubscribe"))try{a.send(JSON.stringify(u))}catch(f){console.warn("[events-client] outbox flush failed:",f)}},a.onmessage=i=>{if(a!==this.ws)return;let u;try{const f=typeof i.data=="string"?i.data:String(i.data);u=JSON.parse(f)}catch{return}this.handleMessage(u)},a.onclose=()=>{a===this.ws&&(this.ws=null,!this.explicitlyClosed&&(n||this.broadcastConnectionError({code:"connection_failed",message:"WebSocket failed to connect (auth, network, or proxy issue)"}),this.topics.size!==0&&this.scheduleReconnect()))},a.onerror=()=>{}}scheduleReconnect(){this.reconnectScheduler.schedule()}broadcastConnectionError(s){for(const r of this.topics.values())for(const a of[...r.error])try{a(s)}catch(n){console.error("[events-client] error handler threw on connection error:",n)}}wsSendOrQueue(s){if(this.ws&&this.ws.readyState===WebSocket.OPEN)try{this.ws.send(JSON.stringify(s));return}catch(r){console.warn("[events-client] send failed, will queue:",r)}this.outbox.push(s)}handleMessage(s){switch(s.type){case"data":{const r=this.topics.get(s.topic);if(this.cache.set(s.topic,s.data),!r)return;for(const a of[...r.data])try{a(s.data)}catch(n){console.error(`[events-client] handler threw on ${s.topic}:`,n)}break}case"error":{const r={code:s.code,message:s.message};if(s.topic){const a=this.topics.get(s.topic);if(a)for(const n of[...a.error])try{n(r)}catch(i){console.error(`[events-client] error handler threw on ${s.topic}:`,i)}}else console.warn("[events-client] connection-level error:",s.code,s.message);break}}}}let Xe=null;function ft(){return Xe||(Xe=new nn),Xe}function Vt(){const[t,s]=o.useState(null),[r,a]=o.useState(!1),[n,i]=o.useState(null);return o.useEffect(()=>ft().subscribe("agents",f=>{i(null),s(f),a(!0)},f=>i(f)),[]),{data:t,loaded:r,error:n}}function rn(t){const[s,r]=o.useState(null),[a,n]=o.useState(!1),[i,u]=o.useState(null);return o.useEffect(()=>(r(null),n(!1),u(null),ft().subscribe(`task:${t}`,m=>{u(null),r(m),n(!0)},m=>u(m))),[t]),{data:s,loaded:a,error:i}}function Jt(t){const[s,r]=o.useState(null),[a,n]=o.useState(!1),[i,u]=o.useState(null);return o.useEffect(()=>{if(!t){r(null),n(!1),u(null);return}r(null),n(!1),u(null);let f=!1,m=!1,h=!1;const b=ft().subscribe(`project-tasks:${t}`,g=>{f||(m=!0,u(null),r(g),n(!0))},g=>{f||(u(g),!(m||h)&&(h=!0,M.tasks.list(t).then(d=>{f||m||(r(d),n(!0))},d=>{console.warn(`[useProjectTasks] REST fallback failed for ${t}:`,d)})))});return()=>{f=!0,b()}},[t]),{data:s,loaded:a,error:i}}let ze=null,be=null,He=null,Ce=0;const rt=new Set;function Yt(){rt.forEach(t=>t())}async function on(){const t=Ce;try{const s=await M.projects.list();if(t!==Ce)return;ze=s,He=null}catch(s){if(t!==Ce)return;He=s instanceof Error?s.message:String(s)}finally{t===Ce&&(be=null,Yt())}}function ot(){return be||(be=on(),be)}function an(){Ce+=1,ze=null,be=null,He=null,Yt()}typeof window<"u"&&window.addEventListener(Fe,an);async function cn(){const t=be!==null;await ot(),t&&await ot()}function qe(){const[,t]=o.useState(0);return o.useEffect(()=>{const s=()=>t(r=>r+1);return rt.add(s),ze===null&&!be&&ot(),()=>{rt.delete(s)}},[]),{projects:ze,error:He,refresh:cn}}const Xt=o.createContext(null);function ln({children:t}){const[s,r]=o.useState(null),a=o.useCallback(i=>r(i),[]),n=o.useCallback(()=>r(null),[]);return e.jsxs(Xt.Provider,{value:{openTask:a},children:[t,s!==null&&e.jsx(fn,{taskId:s,onClose:n,onOpenTask:r},s)]})}function $e(){const t=o.useContext(Xt);if(!t)throw new Error("useTaskDetail must be inside <TaskDetailProvider>");return t}const Tt=Ut,Zt={pending:"pill",in_progress:"pill pill-live",review:"pill pill-review",fixing:"pill pill-warn",approved:"pill pill-live","merge-ready":"pill pill-live",ready:"pill pill-live",merged:"pill pill-live",done:"pill pill-live",failed:"pill pill-warn",max_rounds:"pill pill-warn",cancelled:"pill"},dn={pending:"bg-og-300",in_progress:"bg-success",review:"bg-accent",fixing:"bg-warn",approved:"bg-success","merge-ready":"bg-success",ready:"bg-success",merged:"bg-success",done:"bg-success",failed:"bg-warn",max_rounds:"bg-warn",cancelled:"bg-og-300"};function un({status:t}){return e.jsx("span",{role:"img","aria-label":t,title:t,className:`inline-block h-2 w-2 shrink-0 rounded-full ${dn[t]??"bg-og-300"}`})}function ht(t){if(!t)return"";const s=t.match(/^task-(\d+)$/);return s?s[1]:t}function It({id:t,runtime:s}){const r=it(s);return t?e.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-baseline gap-1 align-baseline",title:ct(t,s),children:[e.jsx("span",{className:"min-w-0 truncate font-mono text-og-800",children:t}),r&&e.jsxs("span",{className:"hidden shrink-0 whitespace-nowrap text-[12px] text-og-400 sm:inline",children:["(",r,")"]})]}):e.jsx("span",{className:"font-mono text-og-800",children:"—"})}function $t(t){if(t==null)return"";const s=String(t).trim();if(!s)return"";const r=s.match(/^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2})(?::(\d{2}))?/);if(r)return`${r[1]} ${r[2]}:${r[3]??"00"}`;const a=new Date(s);return Number.isNaN(a.getTime())?s:a.toISOString().slice(0,19).replace("T"," ")}function fn({taskId:t,onClose:s,onOpenTask:r}){const{show:a}=fe(),[n,i]=o.useState(!1),[u,f]=o.useState(!1),[m,h]=o.useState(!1),[b,g]=o.useState(!1),[d,v]=o.useState(!1),[I,x]=o.useState(!1),[p,S]=o.useState(null),{data:_,loaded:N,error:E}=rn(t),{projects:y}=qe(),c=p??_,$=(E==null?void 0:E.message)??null,F=o.useMemo(()=>{const l=new Map;for(const T of y??[])for(const H of T.agent)for(const Z of H)l.set(Z.id,Z.runtime);return l},[y]);o.useEffect(()=>{p&&_&&_.updatedAt>=p.updatedAt&&S(null)},[p,_]);const z=l=>{S(l)},B=async()=>{if(c&&confirm(`确定取消 task ${c.id}?`)){f(!0);try{const l=await M.tasks.update(c.id,{status:"cancelled"});z(l),a({kind:"success",title:"任务已取消"})}catch(l){a({kind:"error",title:"取消失败",body:l instanceof Error?l.message:String(l)})}finally{f(!1)}}},j=async()=>{if(!c)return;const T=Ut.has(c.status)?`task ${c.id} 已是 ${c.status} 状态。手动请 QA 重审会再跑一轮 review,但状态机不会把 QA 结果带回主流程。继续?`:`请 QA 重审 task ${c.id}?这会让 QA agent 立即开始新一轮 review(reviewRound +1)。`;if(confirm(T)){g(!0);try{const H=await M.tasks.review(c.id);z(H),a({kind:"success",title:`已派 QA 重审 (round ${H.reviewRound})`})}catch(H){a({kind:"error",title:"Review 派发失败",body:H instanceof Error?H.message:String(H)})}finally{g(!1)}}},L=async()=>{if(!c)return;const l=c.status==="merged"?`task ${c.id} 已 merged。Retry 会用同样的标题/描述新建一个 task 从头跑,确定继续?`:`Retry task ${c.id}?这会新建一个 task 从头开始,旧 task 保留为历史。`;if(confirm(l)){h(!0);try{const T=await M.tasks.retry(c.id);a({kind:"success",title:`已新建 task ${T.id}`}),r(T.id)}catch(T){a({kind:"error",title:"Retry 失败",body:T instanceof Error?T.message:String(T)})}finally{h(!1)}}},D=async()=>{if(c&&confirm(`将合并 PR #${c.prNumber} 并收尾(删本地分支 + 压缩 agent 上下文),确定?`)){v(!0);try{const l=await M.tasks.complete(c.id);z(l),a({kind:"success",title:"已标记完成,开始收尾"})}catch(l){a({kind:"error",title:"标记完成失败",body:l instanceof Error?l.message:String(l)})}finally{v(!1)}}},U=async()=>{if(c&&confirm(`派 dev 再修一轮(round → ${c.reviewRound+1}),完成后自动转 QA review?`)){x(!0);try{const l=await M.tasks.continue(c.id);z(l),a({kind:"success",title:`已继续一轮 (round ${l.reviewRound})`})}catch(l){a({kind:"error",title:"继续一轮失败",body:l instanceof Error?l.message:String(l)})}finally{x(!1)}}},W=async()=>{if(c&&confirm(`确认完成 task ${c.id}?project.merge 为 auto 时由 baxian 自动执行合并。`)){v(!0);try{const l=await M.tasks.complete(c.id);z(l),a({kind:"success",title:`已确认(${l.status})`})}catch(l){a({kind:"error",title:"确认失败",body:l instanceof Error?l.message:String(l)})}finally{v(!1)}}};if(n&&c)return e.jsx(ut,{mode:"edit",open:!0,onClose:()=>i(!1),task:c,onUpdated:z});const K=c?`${c.id} ${c.title}`:t;return e.jsx(ve,{open:!0,onClose:s,title:K,titleContent:c?e.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-baseline gap-2",children:[e.jsx("span",{className:"shrink-0 font-mono text-og-400",children:c.id}),e.jsx("span",{className:"min-w-0 truncate text-og-1000",children:c.title})]}):void 0,size:"lg",footer:c?se(c):void 0,children:V()});function V(){if($&&!c)return e.jsxs("div",{className:"text-[13px] text-danger",children:["Error: ",$]});if(N&&!c)return e.jsxs("div",{className:"text-[13px] text-danger",children:["Task not found: ",t]});if(!c)return e.jsx("div",{className:"text-[13px] text-og-500",children:"Loading…"});const l=c.preferredAgentId==="",T=c.status==="approved"&&c.prNumber!==void 0,H=c.status==="merge-ready"&&c.prNumber!==void 0,Z=c.status==="ready",ne=c.status==="max_rounds"&&c.phase!=="spec",te=c.status==="max_rounds"&&c.phase==="spec";return e.jsxs("div",{children:[$&&e.jsxs("div",{className:"mb-4 text-[13px] text-danger",children:["Error: ",$]}),l&&e.jsx("div",{className:"mb-4 rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-3 py-2.5 text-[12px] text-warn",children:c.status==="pending"?e.jsxs(e.Fragment,{children:["This task has no dev assigned yet — click ",e.jsx("b",{className:"font-semibold",children:"Edit"})," to choose one, or use the Start button on any idle dev card."]}):e.jsxs(e.Fragment,{children:["This is a legacy task with no preferred dev (read-only in status ",e.jsx("b",{className:"font-semibold",children:c.status}),")."]})}),e.jsx("div",{className:"mb-2 flex flex-wrap items-center gap-3",children:e.jsx("span",{className:Zt[c.status],children:c.status})}),e.jsxs("div",{className:"mb-4 text-[12px] text-og-500",children:["Created at ",$t(c.createdAt),", Updated at ",$t(c.updatedAt)]}),T&&e.jsxs("div",{className:"mb-4 rounded-lg border border-[#bbf7d0] bg-[#f0fdf4] p-4 text-[13px] text-success",children:[e.jsx("div",{className:"font-semibold",children:"QA approved · verifying feedback"}),e.jsx("div",{className:"mt-1 text-og-700",children:"Dev keeps the task reserved while it checks whether all human or agent feedback has been handled."}),c.prUrl&&e.jsxs("a",{href:c.prUrl,target:"_blank",rel:"noopener noreferrer",className:"btn-secondary mt-3 !border-[#bbf7d0] !text-success hover:!bg-[#dcfce7] hover:!border-success",children:["Open PR #",c.prNumber]})]}),Z&&e.jsxs("div",{className:"mb-4 rounded-lg border border-[#bbf7d0] bg-[#f0fdf4] p-4 text-[13px] text-success",children:[e.jsx("div",{className:"font-semibold",children:"✅ 评审通过 · 等待人工确认"}),e.jsxs("div",{className:"mt-1 text-og-700",children:["Server review 完成(",c.reviewRound," 轮)。点击「确认」收尾",c.prNumber?"(merge:auto 时自动合并 PR)":"",",或「Cancel」丢弃。"]}),e.jsx(Dt,{taskId:c.id}),c.prUrl&&e.jsxs("a",{href:c.prUrl,target:"_blank",rel:"noopener noreferrer",className:"btn-secondary mt-3 !border-[#bbf7d0] !text-success hover:!bg-[#dcfce7] hover:!border-success",children:["Open PR #",c.prNumber]})]}),H&&e.jsxs("div",{className:"mb-4 rounded-lg border border-[#bbf7d0] bg-[#f0fdf4] p-4 text-[13px] text-success",children:[e.jsx("div",{className:"font-semibold",children:"✅ PR ready · 等待人工确认"}),e.jsx("div",{className:"mt-1 text-og-700",children:"Dev finished its post-approve checks — 点击「确认」收尾(merge:auto 时由 baxian 执行合并)。"}),c.prUrl&&e.jsxs("a",{href:c.prUrl,target:"_blank",rel:"noopener noreferrer",className:"btn-secondary mt-3 !border-[#bbf7d0] !text-success hover:!bg-[#dcfce7] hover:!border-success",children:["Open PR #",c.prNumber]})]}),ne&&e.jsxs("div",{className:"mb-4 rounded-lg border border-[#fde68a] bg-[#fef3c7]/60 p-4 text-[13px] text-warn",children:[e.jsxs("div",{className:"font-semibold",children:["已达 review 轮次上限(round ",c.reviewRound,")"]}),e.jsx("div",{className:"mt-1 text-og-700",children:"可「标记完成」合并收尾,或「继续一轮」由 dev 再修一轮(完成后自动转 QA review)。"}),e.jsx("div",{className:"mt-2 text-og-700",children:"轮次越多,Agent 越容易偏离重点。若无严重问题,建议先合并本次成果,剩余问题另开任务跟进。"})]}),te&&e.jsxs("div",{className:"mb-4 rounded-lg border border-[#fde68a] bg-[#fef3c7]/60 p-4 text-[13px] text-warn",children:[e.jsxs("div",{className:"font-semibold",children:["已达 spec review 轮次上限(round ",c.specReviewRound??0,")"]}),e.jsx("div",{className:"mt-1 text-og-700",children:"Spec 评审多轮未达成一致,任务已暂停。spec 是过程产物、没有可合并的成果, 可「Retry」新建任务从头跑(丢弃当前 worktree),或「Cancel」取消。"}),e.jsx("div",{className:"mt-2 text-og-700",children:"建议先查看下方评审记录定位分歧,细化任务描述后再 Retry。"}),e.jsx(Dt,{taskId:c.id})]}),e.jsx("pre",{className:"card mb-4 whitespace-pre-wrap p-4 text-[13px] text-og-800",children:c.description}),e.jsxs("div",{className:"card space-y-2 p-4 text-[13px]",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-x-6 gap-y-2 md:grid-cols-2",children:[e.jsxs("div",{className:"text-og-500",children:["Project: ",e.jsx("span",{className:"font-mono text-og-800",children:c.projectId})]}),e.jsxs("div",{className:"text-og-500",children:["Round: ",e.jsx("span",{className:"font-mono text-og-800",children:c.reviewRound})," ",e.jsxs("span",{children:["spec: ",e.jsx("span",{className:"font-mono text-og-800",children:c.specReviewRound??0})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-x-6 gap-y-2 md:grid-cols-2",children:[e.jsxs("div",{className:"text-og-500",children:["Dev: ",e.jsx(It,{id:c.agentId,runtime:F.get(c.agentId)})]}),e.jsxs("div",{className:"text-og-500",children:["QA: ",e.jsx(It,{id:c.qaAgentId??"",runtime:F.get(c.qaAgentId??"")})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-x-6 gap-y-2 md:grid-cols-2",children:[e.jsxs("div",{className:"text-og-500",children:["PR:"," ",c.prNumber?c.prUrl?e.jsxs("a",{href:c.prUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent hover:text-accent-hover",children:["#",c.prNumber]}):e.jsxs("span",{className:"font-mono text-og-800",children:["#",c.prNumber]}):e.jsx("span",{className:"text-og-400",children:"—"})]}),e.jsxs("div",{className:"text-og-500",children:["Branch: ",e.jsx("span",{className:"font-mono text-og-800",children:c.branch||"—"})]})]})]})]})}function se(l){const T=l.status==="max_rounds",H=T&&l.phase!=="spec",Z=T&&l.phase==="spec",ne=l.status==="ready"||l.status==="merge-ready",te=l.reviewMode==="server"&&l.status==="approved",C=l.status==="pending",Q=l.status==="pending"||l.status==="in_progress"||T||ne||te,G=(Tt.has(l.status)||Z)&&!!l.preferredAgentId,oe=!!l.prNumber&&!Z&&l.reviewMode!=="server",O=l.reviewMode==="server",w=H&&(!!l.prNumber||O),P=H&&(!!l.prNumber||O)&&!!l.agentId,R=O&&l.status==="approved",ee=l.preferredAgentId==="";return e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!C,onClick:()=>i(!0),className:"btn-secondary",children:"Edit"}),e.jsx("button",{type:"button",disabled:!Q||u,onClick:B,className:"btn-secondary !border-[#fecaca] !text-danger hover:!bg-[#fef2f2] hover:!border-danger",children:u?"Cancelling…":"Cancel"}),!H&&e.jsx("button",{type:"button",disabled:!G||m,onClick:L,title:Tt.has(l.status)||Z?ee?"Legacy task has no preferred dev to retry against":"新建一个 task 从头跑,丢弃当前 worktree/branch":`Cannot retry in status ${l.status}`,className:"btn-secondary",children:m?"Retrying…":"Retry"}),e.jsx("button",{type:"button",disabled:!oe||b,onClick:j,title:l.prNumber?Z?"spec 阶段达上限不支持 Call review":"让 QA agent 立即开始新一轮 review(reviewRound +1)":"该 task 还没有 PR,无法派 review",className:"btn-secondary !border-accent-soft !text-accent hover:!bg-accent-soft hover:!border-accent",children:b?"Dispatching…":"Call review"}),H&&e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!P||I,onClick:U,title:"派 dev 再修一轮,完成后自动转 QA review",className:"btn-secondary !border-accent-soft !text-accent hover:!bg-accent-soft hover:!border-accent",children:I?"Continuing…":"继续一轮"}),e.jsx("button",{type:"button",disabled:!w||d,onClick:D,title:"合并 PR 并收尾(删本地分支 + 压缩上下文)",className:"btn-secondary !border-[#bbf7d0] !text-success hover:!bg-[#dcfce7] hover:!border-success",children:d?"Completing…":"标记完成"})]}),ne&&e.jsx("button",{type:"button",disabled:d,onClick:W,title:"确认完成;merge:auto 时由 baxian 执行合并",className:"btn-secondary !border-[#bbf7d0] !text-success hover:!bg-[#dcfce7] hover:!border-success",children:d?"Confirming…":"确认"}),R&&e.jsx("button",{type:"button",disabled:d,onClick:W,title:"发布派发失败后重试 push/PR 步骤",className:"btn-secondary !border-accent-soft !text-accent hover:!bg-accent-soft hover:!border-accent",children:d?"Retrying…":"重试发布"})]})}}function Dt({taskId:t}){var i;const[s,r]=o.useState(null);if(o.useEffect(()=>{let u=!0;return M.tasks.reviews(t).then(f=>{u&&r(f)}).catch(()=>{u&&r([])}),()=>{u=!1}},[t]),!s||s.length===0)return null;const a=s[s.length-1],n=s.reduce((u,f)=>{var m;return u+(((m=f.findings)==null?void 0:m.findings.length)??0)},0);return e.jsxs("div",{className:"mt-2 text-[12px] text-og-700",children:["Review ",s.length," 轮 · 最终 verdict ",e.jsx("span",{className:"font-mono",children:((i=a.findings)==null?void 0:i.verdict)??"—"})," ","· findings 共 ",n," 条"]})}const Ze="baxian:terminal-activated";function es({group:t,projectId:s,agentsById:r,agentsLoaded:a,agentsError:n=!1,tasks:i,onDeleted:u,terminalMode:f="activity-preview"}){var F,z,B;const m=t.find(j=>j.role==="dev")??t[0],h=t.find(j=>j.role==="qa"),b=i.filter(j=>mn(j,m==null?void 0:m.id,h==null?void 0:h.id)),g=m?i.filter(j=>xn(j,s,m.id)).sort((j,L)=>j.createdAt.localeCompare(L.createdAt)):[],d=m?r.get(m.id):void 0,v=!!d&&d.runtimeStatus==="idle"&&((F=d.binding)==null?void 0:F.status)!=="awaiting_human"&&!((z=d.binding)!=null&&z.creationToken)&&!((B=d.binding)!=null&&B.taskId),I=`Agent group ${t.map(j=>j.id).join(" / ")}`,{openTask:x}=$e(),p=f==="embedded-full",S=o.useId(),[_,N]=o.useState(null);o.useEffect(()=>{if(!p)return;const j=U=>{U.composedPath().some(V=>V instanceof Element&&V.hasAttribute("data-agent-card"))||N(null)},L=U=>{if(U.key!=="Escape")return;const W=document.activeElement;W instanceof Element&&W.closest("[data-agent-card]")||N(null)},D=U=>{const W=U.detail;(W==null?void 0:W.groupId)!==S&&N(null)};return document.addEventListener("click",j),document.addEventListener("keydown",L),document.addEventListener(Ze,D),()=>{document.removeEventListener("click",j),document.removeEventListener("keydown",L),document.removeEventListener(Ze,D)}},[p,S]);const E=j=>{N(j),document.dispatchEvent(new CustomEvent(Ze,{detail:{groupId:S}}))},y=f==="embedded-full"?t.length<=1?"lg:grid-cols-1":t.length===2?"lg:grid-cols-2":t.length===3?"lg:grid-cols-3":"lg:grid-cols-4":"sm:grid-cols-2",c=!!m&&g.length>0,$=b.length===0&&!c;return e.jsxs("div",{role:"group","aria-label":I,className:"min-w-0",children:[c&&m&&e.jsx(hn,{tasks:g,devId:m.id,dispatchReady:v,label:I}),b.length>0&&e.jsx("div",{className:"card mb-2 max-h-28 overflow-y-auto divide-y divide-hairline",children:b.map(j=>{const L=j.phase==="spec"?j.specReviewRound??0:j.reviewRound;return e.jsxs("button",{type:"button",onClick:()=>x(j.id),className:"flex w-full items-center gap-3 px-3 py-2 text-left text-[13px] transition-colors hover:bg-og-50/60",children:[e.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[e.jsx("span",{className:"shrink-0 font-mono text-[11px] text-og-500",title:j.id,children:ht(j.id)}),e.jsx("span",{className:"truncate text-og-1000",children:j.title})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsxs("span",{className:"shrink-0 text-[12px] text-og-500",children:["Round ",L]}),e.jsx("span",{className:`${Zt[j.status]} shrink-0`,children:j.status})]})]},j.id)})}),$&&e.jsx("div",{className:"mb-2 rounded-lg border border-hairline bg-surface px-3 py-2 text-[13px] text-og-400","aria-label":`${I} no active task`,children:"暂无任务"}),e.jsx("div",{className:`grid grid-cols-1 ${y} gap-4`,children:t.map(j=>{const L=r.get(j.id),D=L??{id:j.id,projectId:s,runtimeStatus:"unknown",tmuxSessionStatus:"unknown",stale:!0};return e.jsx(Ks,{agent:D,projectId:s,role:j.role,runtime:j.runtime,pendingRestart:a&&!L,terminalLoading:!a&&!L&&!n,onDeleted:u,showTaskBinding:!1,terminalMode:f,...p?{active:_===j.id,onActivate:()=>E(j.id)}:{}},j.id)})})]})}function hn({tasks:t,devId:s,dispatchReady:r,label:a}){const{show:n}=fe(),{openTask:i}=$e(),[u,f]=o.useState(null),m=async h=>{f(h);try{await M.tasks.dispatch(h,{agentId:s}),n({kind:"success",title:`Task ${h} 已派给 ${s}`})}catch(b){n({kind:"error",title:"派遣失败",body:b instanceof Error?b.message:String(b)})}finally{f(null)}};return e.jsx("div",{role:"group",className:"card mb-2 max-h-28 overflow-y-auto divide-y divide-hairline","aria-label":`${a} claimable tasks for ${s}`,children:t.map(h=>{const b=h.preferredAgentId==="",g=u!==null;return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 text-[13px]",children:[e.jsxs("button",{type:"button",onClick:()=>i(h.id),className:"min-w-0 flex-1 flex items-center gap-2 text-left transition-colors hover:text-accent-hover",children:[e.jsx("span",{className:"shrink-0 font-mono text-[11px] text-og-500",title:h.id,children:ht(h.id)}),e.jsx("span",{className:"truncate text-og-1000",title:h.title,children:h.title}),b&&e.jsx("span",{className:"pill shrink-0",children:"未分配"})]}),e.jsx("button",{type:"button",onClick:()=>void m(h.id),disabled:!r||g,title:r?`派给 ${s} 并立即开始`:"Dev 当前不可派遣",className:"shrink-0 text-[13px] font-medium text-accent transition-colors hover:text-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",children:u===h.id?"Starting…":"Start"})]},h.id)})})}function mn(t,s,r){return!(!s||!Wt.has(t.status)||!(t.agentId===s||t.preferredAgentId===s)||r&&t.qaAgentId&&t.qaAgentId!==r)}function xn(t,s,r){return t.projectId!==s||t.status!=="pending"?!1:t.preferredAgentId===r||t.preferredAgentId===""}const pn=/^[a-z][a-z0-9-]{1,31}$/,bn=/^[A-Za-z0-9_-][A-Za-z0-9._-]*\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/,Pt="w-full rounded-md border border-og-100 bg-surface px-2.5 py-1.5 text-[13px] text-og-800 placeholder:text-og-400 focus:border-accent focus:outline-none focus:ring-[3px] focus:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-50",et="mb-1.5 block text-[12px] font-medium text-og-700",Mt="mt-1 text-[12px] text-danger";function gn({open:t,onClose:s,onCreated:r}){const[a,n]=o.useState(""),[i,u]=o.useState(""),[f,m]=o.useState(null),[h,b]=o.useState(!1),[g,d]=o.useState(null),[v,I]=o.useState({}),[x,p]=o.useState(new Set),S=o.useRef(0),{show:_}=fe(),{flagDirty:N}=Ge();o.useEffect(()=>{if(!t)return;S.current+=1;const $=S.current;n(""),u(""),m(null),d(null),I({}),p(new Set),M.config.get().then(F=>{$===S.current&&p(new Set(F.project.map(z=>z.id)))}).catch(()=>{})},[t]);const E=()=>{h||s()},y=()=>{const $={};return a?pn.test(a)?x.has(a)&&($.id="该 id 已被占用"):$.id="小写字母开头,只含 a-z 0-9 -,长度 2-32":$.id="必填",i?bn.test(i)||($.repo="需为 owner/repo 形式"):$.repo="必填",I($),Object.keys($).length===0},c=async $=>{if($.preventDefault(),!!y()){b(!0),d(null);try{const F=await M.projects.create({id:a,repo:i,merge:f});F.restartRequired&&N(),_({kind:"success",title:`项目 ${F.project.id} 已创建`}),r(F.project.id)}catch(F){d(F instanceof Error?F.message:String(F))}finally{b(!1)}}};return e.jsx(ve,{open:t,onClose:E,title:"新建项目",size:"md",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:E,disabled:h,className:"btn-secondary",children:"取消"}),e.jsx("button",{type:"submit",form:"create-project-form",disabled:h,className:"btn-primary",children:h?"创建中…":"创建"})]}),children:e.jsxs("form",{id:"create-project-form",onSubmit:c,className:"space-y-3",children:[g&&e.jsx("div",{className:"rounded-md border border-[#fecaca] bg-[#fef2f2] px-3 py-2 text-[13px] text-danger",children:g}),e.jsxs("div",{children:[e.jsx("label",{className:et,htmlFor:"proj-id",children:"项目 ID"}),e.jsx("input",{id:"proj-id",type:"text",value:a,onChange:$=>n($.target.value),className:Pt,placeholder:"kongkong",disabled:h}),v.id&&e.jsx("div",{className:Mt,children:v.id})]}),e.jsxs("div",{children:[e.jsx("label",{className:et,htmlFor:"proj-repo",children:"GitHub 仓库"}),e.jsx("input",{id:"proj-repo",type:"text",value:i,onChange:$=>u($.target.value),className:Pt,placeholder:"baxian-ai/baxian",disabled:h}),v.repo&&e.jsx("div",{className:Mt,children:v.repo})]}),e.jsxs("div",{children:[e.jsx("span",{className:et,children:"合并策略"}),e.jsxs("label",{className:"mb-1 flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"merge",checked:f===null,onChange:()=>m(null),disabled:h,className:"h-3.5 w-3.5 accent-[#1348dc]"}),e.jsx("span",{className:"text-[13px] text-og-800",children:"人类合并(默认)"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"merge",checked:f==="auto",onChange:()=>m("auto"),disabled:h,className:"h-3.5 w-3.5 accent-[#1348dc]"}),e.jsx("span",{className:"text-[13px] text-og-800",children:"QA Approve 后自动合并"})]})]})]})})}const Lt=/^[a-z][a-z0-9-]{1,31}$/,vn=500,ye="w-full rounded-md border border-og-100 bg-surface px-2.5 py-1.5 text-[13px] text-og-800 placeholder:text-og-400 focus:border-accent focus:outline-none focus:ring-[3px] focus:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-50",pe="mb-1.5 block text-[12px] font-medium text-og-700",Ot="mt-1 text-[12px] text-danger",tt="mt-1 text-[12px] text-og-500",je="h-3.5 w-3.5 accent-[#1348dc]",_t={id:"",role:"dev",pairWith:"",mode:"local",host:"",runtime:"",workdir:"",yolo:!0,model:"",addDirs:""};function yn(t){return t.alias?t.alias:`${t.user?`${t.user}@`:""}${t.hostname}${t.port!=null?`:${t.port}`:""}`}function ts({open:t,onClose:s,projectId:r,onCreated:a}){var te;const[n,i]=o.useState(_t),[u,f]=o.useState(null),[m,h]=o.useState([]),[b,g]=o.useState(new Set),[d,v]=o.useState(null),[I,x]=o.useState(!1),[p,S]=o.useState(!1),[_,N]=o.useState(null),E=o.useRef(null),y=o.useRef(null),c=o.useRef(0),{show:$}=fe(),{flagDirty:F}=Ge();o.useEffect(()=>{if(!t)return;c.current+=1;const C=c.current;i(_t),f(null),h([]),g(new Set),v(null),x(!1),N(null),M.config.get().then(Q=>{if(C!==c.current)return;const G=Q.project.find(O=>O.id===r)??null;f(G),h(Q.host??[]);const oe=new Set;Q.project.forEach(O=>O.agent.forEach(w=>w.forEach(P=>oe.add(P.id)))),g(oe)}).catch(()=>{})},[t,r]);const z=()=>{p||s()},B=o.useCallback(()=>{E.current&&E.current.abort();const C=new AbortController;E.current=C,x(!0),N(null);const Q=n.mode==="remote"?{hostId:n.host}:{};M.agents.probe(n.mode,Q,{signal:C.signal}).then(G=>{C.signal.aborted||(v(G),N(null))}).catch(G=>{C.signal.aborted||(v(null),N(G instanceof Error?G.message:String(G)))}).finally(()=>{E.current===C&&x(!1)})},[n.mode,n.host]);o.useEffect(()=>{if(t&&(v(null),E.current&&E.current.abort(),!(n.mode==="remote"&&!n.host)))return y.current&&clearTimeout(y.current),y.current=setTimeout(B,vn),()=>{y.current&&clearTimeout(y.current)}},[t,n.mode,n.host,B]),o.useEffect(()=>{t||E.current&&E.current.abort()},[t]),o.useEffect(()=>()=>{E.current&&E.current.abort(),y.current&&clearTimeout(y.current)},[]);const j=(u==null?void 0:u.agent.filter(C=>C.length===1&&C[0].role==="dev").map(C=>C[0]))??[],L=j.length>0,D=Lt.test(n.id)&&!b.has(n.id),U=n.mode==="local"||n.mode==="remote"&&n.host!=="",W=n.runtime!==""&&(n.runtime==="claude-code"?!!(d!=null&&d.runtimes["claude-code"].ok):!!(d!=null&&d.runtimes.codex.ok)),K=!!(d!=null&&d.tmux.ok),V=n.mode==="local"||!!((te=d==null?void 0:d.ssh)!=null&&te.ok),se=n.role==="dev"||n.role==="qa"&&n.pairWith!=="",l=!p&&D&&U&&se&&W&&K&&V,T=async C=>{if(C.preventDefault(),!!l){S(!0),N(null);try{const Q=n.addDirs.split(`
|
|
2
|
+
`).map(O=>O.trim()).filter(O=>O.length>0),G={id:n.id,role:n.role,runtime:n.runtime,mode:n.mode,...n.mode==="remote"?{host:n.host}:{},...n.workdir?{workdir:n.workdir}:{},yolo:n.yolo,...n.model.trim()?{model:n.model.trim()}:{},...Q.length>0?{addDirs:Q}:{},...n.role==="qa"?{pairWith:n.pairWith}:{}},oe=await M.projects.addAgent(r,G);oe.restartRequired&&F(),$({kind:"success",title:`Agent ${oe.agent.id} 已添加到 ${r}`}),a(),s()}catch(Q){N(Q instanceof Error?Q.message:String(Q))}finally{S(!1)}}},H=({rt:C})=>{if(n.mode==="remote"&&!n.host)return e.jsx("span",{className:"ml-2 text-[12px] text-og-400",children:"(请先选择 Host)"});if(I)return e.jsx("span",{className:"ml-2 text-[12px] text-og-400",children:"…探测中"});if(!d)return e.jsx("span",{className:"ml-2 text-[12px] text-og-400",children:"?"});const G=d.runtimes[C];return G.ok?e.jsxs("span",{className:"ml-2 text-[12px] text-success",children:["✓ ",G.path??""]}):e.jsxs("span",{className:"ml-2 text-[12px] text-danger",title:G.message,children:["⨯ ",G.message]})},Z=()=>n.mode==="remote"&&!n.host?null:I?e.jsx("div",{className:"text-[12px] text-og-400",children:"tmux: …探测中"}):d?d.tmux.ok?e.jsxs("div",{className:"text-[12px] text-success",children:["tmux: ✓ ",d.tmux.path??""]}):e.jsxs("div",{className:"text-[12px] text-danger",children:["tmux: ⨯ ",d.tmux.message]}):null,ne=()=>n.mode!=="remote"||!n.host||!(d!=null&&d.ssh)?null:d.ssh.ok?e.jsxs("div",{className:"text-[12px] text-success",children:["SSH: ✓ ",d.ssh.message]}):e.jsxs("div",{className:"text-[12px] text-danger",children:["SSH: ⨯ ",d.ssh.message]});return e.jsx(ve,{open:t,onClose:z,title:`添加 Agent 到 ${r}`,size:"lg",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:z,disabled:p,className:"btn-secondary",children:"取消"}),e.jsx("button",{type:"submit",form:"create-agent-form",disabled:!l,className:"btn-primary",children:p?"添加中…":"添加 Agent"})]}),children:e.jsxs("form",{id:"create-agent-form",onSubmit:T,className:"space-y-3",children:[_&&e.jsx("div",{className:"rounded-md border border-[#fecaca] bg-[#fef2f2] px-3 py-2 text-[13px] text-danger",children:_}),e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"agent-id",children:"Agent ID"}),e.jsx("input",{id:"agent-id",type:"text",value:n.id,onChange:C=>i({...n,id:C.target.value}),className:ye,placeholder:"kk-cc",disabled:p}),n.id&&!Lt.test(n.id)&&e.jsx("div",{className:Ot,children:"小写字母开头,只含 a-z 0-9 -,长度 2-32"}),n.id&&b.has(n.id)&&e.jsx("div",{className:Ot,children:"该 id 已被占用(全局唯一)"})]}),e.jsxs("div",{children:[e.jsx("span",{className:pe,children:"角色"}),e.jsxs("label",{className:"mr-4 inline-flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"role",checked:n.role==="dev",className:je,onChange:()=>i({...n,role:"dev",pairWith:""}),disabled:p}),e.jsx("span",{className:"text-[13px] text-og-800",children:"Dev"})]}),e.jsxs("label",{className:"inline-flex items-center gap-2",title:L?"":"请先创建一个 Dev Agent",children:[e.jsx("input",{type:"radio",name:"role",checked:n.role==="qa",className:je,onChange:()=>i({...n,role:"qa"}),disabled:p||!L}),e.jsx("span",{className:`text-[13px] ${L?"text-og-800":"text-og-400"}`,children:"QA"})]})]}),n.role==="qa"&&e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"pair-with",children:"配对 Dev Agent"}),e.jsxs("select",{id:"pair-with",value:n.pairWith,onChange:C=>i({...n,pairWith:C.target.value}),className:ye,disabled:p,children:[e.jsx("option",{value:"",children:"请选择"}),j.map(C=>e.jsxs("option",{value:C.id,children:[C.id," (dev, ",C.mode,")"]},C.id))]})]}),e.jsxs("div",{children:[e.jsx("span",{className:pe,children:"运行模式"}),e.jsxs("label",{className:"mr-4 inline-flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"mode",checked:n.mode==="local",className:je,onChange:()=>i({...n,mode:"local",host:""}),disabled:p}),e.jsx("span",{className:"text-[13px] text-og-800",children:"本机"})]}),e.jsxs("label",{className:"inline-flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"mode",checked:n.mode==="remote",className:je,onChange:()=>i({...n,mode:"remote"}),disabled:p}),e.jsx("span",{className:"text-[13px] text-og-800",children:"远程 (SSH)"})]})]}),n.mode==="remote"&&e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"host",children:"Host"}),m.length===0?e.jsx("div",{className:"rounded-md border border-og-100 bg-og-50/40 px-3 py-2 text-[12px] text-og-600",children:"还没有配置 Host。请先在右上角菜单的「Host 管理」中添加。"}):e.jsxs("select",{id:"host",value:n.host,onChange:C=>i({...n,host:C.target.value}),className:ye,disabled:p,children:[e.jsx("option",{value:"",children:"请选择 Host"}),m.map(C=>e.jsx("option",{value:C.id,children:yn(C)},C.id))]}),e.jsx("div",{className:tt,children:"私钥/跳板机仍可在 ~/.ssh/config 配置;端口/密码在「Host 管理」里设置。"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1.5 flex items-center justify-between",children:[e.jsx("span",{className:"text-[12px] font-medium text-og-700",children:"运行时"}),e.jsx("button",{type:"button",onClick:B,className:"text-[12px] text-accent transition-colors hover:text-accent-hover disabled:cursor-not-allowed disabled:opacity-50",disabled:p||I||n.mode==="remote"&&!n.host,children:"↻ 重新探测"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"runtime",checked:n.runtime==="claude-code",className:je,onChange:()=>i({...n,runtime:"claude-code"}),disabled:p||(d?!d.runtimes["claude-code"].ok:!1)}),e.jsx("span",{className:"text-[13px] text-og-800",children:"Claude Code"}),e.jsx(H,{rt:"claude-code"})]}),e.jsxs("label",{className:"mt-1 flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:"runtime",checked:n.runtime==="codex",className:je,onChange:()=>i({...n,runtime:"codex"}),disabled:p||(d?!d.runtimes.codex.ok:!1)}),e.jsx("span",{className:"text-[13px] text-og-800",children:"Codex"}),e.jsx(H,{rt:"codex"})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Z,{})}),e.jsx("div",{children:e.jsx(ne,{})})]}),e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"workdir",children:"Workdir(可选)"}),e.jsx("input",{id:"workdir",type:"text",value:n.workdir,onChange:C=>i({...n,workdir:C.target.value}),className:ye,placeholder:"留空时自动 clone 到 ~/.baxian/repos/<owner>/<repo>",disabled:p})]}),e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"model",children:"Model(可选)"}),e.jsx("input",{id:"model",type:"text",value:n.model,onChange:C=>i({...n,model:C.target.value}),className:ye,placeholder:n.runtime==="codex"?"例: o3 / gpt-4o(留空走 default)":"例: sonnet / opus / claude-sonnet-4-6(留空走 default)",disabled:p}),e.jsx("div",{className:tt,children:"透传到 launch 命令的 --model 参数;留空跟随 CLI 默认。"})]}),e.jsxs("div",{children:[e.jsx("label",{className:pe,htmlFor:"addDirs",children:"Additional Dirs(可选)"}),e.jsx("textarea",{id:"addDirs",value:n.addDirs,onChange:C=>i({...n,addDirs:C.target.value}),className:`${ye} font-mono text-[12px]`,rows:3,placeholder:`每行一个绝对路径,例:
|
|
3
|
+
/Users/me/shared-libs
|
|
4
|
+
/Users/me/extra-repo`,disabled:p}),e.jsx("div",{className:tt,children:"透传到 --add-dir。当前 YOLO 模式下不影响权限拦截,主要用于让 CLI 把额外目录纳入工作根。"})]}),e.jsx("div",{className:"rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-3 py-2.5",children:e.jsxs("label",{className:"flex cursor-pointer items-start gap-2",children:[e.jsx("input",{type:"checkbox",className:"mt-1 h-3.5 w-3.5 accent-[#1348dc]",checked:n.yolo,onChange:C=>i({...n,yolo:C.target.checked}),disabled:p}),e.jsxs("div",{className:"text-[13px] text-og-800",children:[e.jsx("div",{className:"font-medium",children:"YOLO 模式(推荐开启)"}),e.jsxs("div",{className:"mt-1 text-[12px] text-warn",children:["Agent 自主执行所有命令、文件改动,无需逐条确认。开启后体验更顺滑, 但",e.jsx("strong",{className:"font-semibold",children:"请确认在受控环境(容器、隔离 worktree)中运行"}),"。"]})]})]})})]})})}const Ft="***",ke="w-full rounded-md border border-og-100 bg-surface px-2.5 py-1.5 text-[13px] text-og-800 placeholder:text-og-400 focus:border-accent focus:outline-none focus:ring-[3px] focus:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-50",Se="mb-1.5 block text-[12px] font-medium text-og-700",st={hostname:"",port:"",alias:"",user:"",password:""};function jn(t){return t.alias?t.alias:`${t.user?`${t.user}@`:""}${t.hostname}${t.port!=null?`:${t.port}`:""}`}function wn({open:t,onClose:s}){const[r,a]=o.useState([]),[n,i]=o.useState("list"),[u,f]=o.useState(null),[m,h]=o.useState(!1),[b,g]=o.useState(!1),[d,v]=o.useState(st),[I,x]=o.useState(null),[p,S]=o.useState(!1),[_,N]=o.useState(!1),[E,y]=o.useState(null),{show:c}=fe(),$=o.useCallback(()=>{M.hosts.list().then(a).catch(l=>x(l instanceof Error?l.message:String(l)))},[]);o.useEffect(()=>{t&&(i("list"),f(null),v(st),x(null),y(null),$())},[t,$]);const F=()=>{f(null),h(!1),g(!1),v(st),x(null),y(null),i("form")},z=l=>{f(l.id??null),h(l.password===Ft),g(!1),v({hostname:l.hostname,port:l.port!=null?String(l.port):"",alias:l.alias??"",user:l.user??"",password:""}),x(null),y(null),i("form")},B=()=>{const l={hostname:d.hostname.trim()};return u?(l.port=d.port.trim()?Number(d.port):null,l.alias=d.alias.trim(),l.user=d.user.trim()):(d.port.trim()&&(l.port=Number(d.port)),d.alias.trim()&&(l.alias=d.alias.trim()),d.user.trim()&&(l.user=d.user.trim())),u&&b?l.password="":d.password&&(l.password=d.password),l},j=d.port.trim(),L=j===""||/^\d+$/.test(j)&&Number(j)>0&&Number(j)<=65535,D=d.hostname.trim().length>0&&L,U=async()=>{if(D){N(!0),y(null),x(null);try{const l=await M.hosts.check({...B(),...u?{id:u}:{}});y(l)}catch(l){x(l instanceof Error?l.message:String(l))}finally{N(!1)}}},W=async l=>{if(l.preventDefault(),!(!D||p)){S(!0),x(null);try{if(u)await M.hosts.update(u,B()),c({kind:"success",title:`Host ${u} 已更新`});else{const T=await M.hosts.create(B());c({kind:"success",title:`Host ${T.host.id} 已添加`})}$(),i("list")}catch(T){x(T instanceof Error?T.message:String(T))}finally{S(!1)}}},K=async l=>{x(null);try{await M.hosts.delete(l.id),c({kind:"success",title:`Host ${l.id} 已删除`}),$()}catch(T){x(T instanceof Error?T.message:String(T))}},V=e.jsx("button",{type:"button",onClick:s,className:"btn-secondary",children:"关闭"}),se=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>i("list"),disabled:p,className:"btn-secondary",children:"返回"}),e.jsx("button",{type:"submit",form:"host-form",disabled:!D||p,className:"btn-primary",children:p?"保存中…":"保存"})]});return e.jsxs(ve,{open:t,onClose:s,title:"Host 管理",size:"md",footer:n==="list"?V:se,children:[I&&e.jsx("div",{className:"mb-3 rounded-md border border-[#fecaca] bg-[#fef2f2] px-3 py-2 text-[13px] text-danger",children:I}),n==="list"?e.jsxs("div",{className:"space-y-3",children:[r.length===0?e.jsx("p",{className:"text-[13px] text-og-500",children:"还没有配置 Host。点击下方「添加 Host」。"}):e.jsx("ul",{className:"space-y-1.5",children:r.map(l=>e.jsxs("li",{className:"flex items-center justify-between gap-3 rounded-md border border-og-100 px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-og-800",children:jn(l)}),e.jsxs("div",{className:"truncate text-[12px] text-og-500",children:[(l.user?`${l.user}@`:"")+l.hostname,l.port!=null?`:${l.port}`:"",l.password===Ft?" · 密码已保存":""]})]}),e.jsxs("div",{className:"flex shrink-0 gap-2",children:[e.jsx("button",{type:"button",onClick:()=>z(l),className:"text-[12px] text-accent transition-colors hover:text-accent-hover",children:"编辑"}),e.jsx("button",{type:"button",onClick:()=>K(l),className:"text-[12px] text-danger transition-colors hover:opacity-80",children:"删除"})]})]},l.id))}),e.jsx("button",{type:"button",onClick:F,className:"btn-secondary w-full",children:"+ 添加 Host"})]}):e.jsxs("form",{id:"host-form",onSubmit:W,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:Se,htmlFor:"host-hostname",children:"Host 地址"}),e.jsx("input",{id:"host-hostname",type:"text",value:d.hostname,onChange:l=>v({...d,hostname:l.target.value}),className:ke,placeholder:"remote.example.com",disabled:p})]}),e.jsxs("div",{children:[e.jsx("label",{className:Se,htmlFor:"host-port",children:"端口(可选)"}),e.jsx("input",{id:"host-port",type:"text",inputMode:"numeric",value:d.port,onChange:l=>v({...d,port:l.target.value}),className:ke,placeholder:"22",disabled:p}),d.port.trim()!==""&&!L&&e.jsx("div",{className:"mt-1 text-[12px] text-danger",children:"端口需为 1–65535 的整数"})]}),e.jsxs("div",{children:[e.jsx("label",{className:Se,htmlFor:"host-alias",children:"别名(可选)"}),e.jsx("input",{id:"host-alias",type:"text",value:d.alias,onChange:l=>v({...d,alias:l.target.value}),className:ke,placeholder:"Prod worker",disabled:p})]}),e.jsxs("div",{children:[e.jsx("label",{className:Se,htmlFor:"host-user",children:"用户名(可选)"}),e.jsx("input",{id:"host-user",type:"text",value:d.user,onChange:l=>v({...d,user:l.target.value}),className:ke,placeholder:"留空则读 ~/.ssh/config 的 User",disabled:p})]}),e.jsxs("div",{children:[e.jsx("label",{className:Se,htmlFor:"host-password",children:"密码(可选)"}),e.jsx("input",{id:"host-password",type:"password",value:b?"":d.password,onChange:l=>v({...d,password:l.target.value}),className:ke,placeholder:m?"已设置,留空保持不变":"留空使用 key 认证",disabled:p||b,autoComplete:"new-password"}),u&&m&&e.jsxs("label",{className:"mt-1.5 flex items-center gap-2 text-[12px] text-og-700",children:[e.jsx("input",{type:"checkbox",className:"h-3.5 w-3.5 accent-[#1348dc]",checked:b,onChange:l=>g(l.target.checked),disabled:p}),"清除已保存的密码(改用 key 登录)"]})]}),e.jsxs("div",{className:"rounded-md border border-[#fde68a] bg-[#fef3c7]/60 px-3 py-2.5 text-[12px] text-warn",children:["建议为该 Host 配置好",e.jsx("strong",{className:"font-semibold",children:"免密码登入(SSH key)"}),"。 否则填写的密码将以",e.jsx("strong",{className:"font-semibold",children:"明文"}),"保存到 baxian.json 中。"]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:U,disabled:!D||_||p,className:"text-[12px] text-accent transition-colors hover:text-accent-hover disabled:cursor-not-allowed disabled:opacity-50",children:_?"测试中…":"测试连接"}),E&&e.jsxs("span",{className:`text-[12px] ${E.ok?"text-success":"text-danger"}`,children:[E.ok?"✓ ":"⨯ ",E.message]})]})]})]})}function Nn(){const{openTask:t}=$e(),{projects:s,error:r,refresh:a}=qe(),n=s??[],i=s!==null,[u,f]=o.useState(!1),[m,h]=o.useState(!1),[b,g]=o.useState(!1),[d,v]=o.useState({kind:"closed"}),{data:I,loaded:x,error:p}=Vt(),S=(p==null?void 0:p.message)??null,_=new Map((I??[]).map(B=>[B.id,B])),N=r??S,[E,y]=o.useState(!1),c=o.useRef(null),$=o.useRef(null),F=o.useId(),z=o.useId();return o.useEffect(()=>{if(!E)return;const B=L=>{var U,W;const D=L.target;D&&((U=$.current)!=null&&U.contains(D)||(W=c.current)!=null&&W.contains(D)||y(!1))},j=L=>{var D;L.key==="Escape"&&(y(!1),(D=c.current)==null||D.focus())};return document.addEventListener("mousedown",B),document.addEventListener("keydown",j),()=>{document.removeEventListener("mousedown",B),document.removeEventListener("keydown",j)}},[E]),e.jsxs("div",{children:[e.jsx("h1",{className:"sr-only",children:"Dashboard"}),e.jsxs("div",{className:"mb-6 flex flex-wrap items-center justify-end gap-2",children:[e.jsx("button",{onClick:()=>h(!0),disabled:n.length===0,"aria-describedby":n.length===0?"create-task-hint":void 0,className:"btn-primary",children:"+ 新建 Task"}),n.length===0&&e.jsx("span",{id:"create-task-hint",className:"self-center text-[12px] text-og-500",children:"请先创建项目"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:c,id:z,type:"button",onClick:()=>y(B=>!B),"aria-haspopup":"menu","aria-expanded":E,"aria-controls":F,"aria-label":"更多操作",className:"flex h-8 w-8 items-center justify-center rounded text-og-500 transition-colors hover:bg-og-100 hover:text-og-1000",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"1"}),e.jsx("circle",{cx:"12",cy:"5",r:"1"}),e.jsx("circle",{cx:"12",cy:"19",r:"1"})]})}),E&&e.jsxs("div",{ref:$,id:F,role:"menu","aria-labelledby":z,className:"absolute right-0 top-full z-10 mt-1 min-w-[140px] rounded-md border border-hairline bg-surface py-1 shadow-md",children:[e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{y(!1),f(!0)},className:"block w-full px-3 py-1.5 text-left text-[13px] text-og-800 hover:text-og-1000",children:"新建项目"}),e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{y(!1),g(!0)},className:"block w-full px-3 py-1.5 text-left text-[13px] text-og-800 hover:text-og-1000",children:"Host 管理"})]})]})]}),N&&e.jsxs("div",{className:"mb-4 text-[13px] text-danger",children:["Error: ",N]}),i&&n.length===0&&!r&&e.jsx("div",{className:"rounded-lg border border-hairline bg-surface py-12 text-center text-[13px] text-og-500",children:'还没有项目。点击右上角"更多"菜单 → "新建项目"开始。'}),n.map(B=>e.jsx(kn,{project:B,agentsById:_,agentsLoaded:x,agentsError:!!p,onAgentDeleted:a},B.id)),e.jsx(gn,{open:u,onClose:()=>f(!1),onCreated:B=>{f(!1),a(),v({kind:"asking",projectId:B})}}),e.jsx(wn,{open:b,onClose:()=>g(!1)}),e.jsx(ve,{open:d.kind==="asking",onClose:()=>v({kind:"closed"}),title:"项目已创建",size:"sm",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>v({kind:"closed"}),className:"btn-secondary",children:"稍后再加"}),e.jsx("button",{type:"button",onClick:()=>{d.kind==="asking"&&v({kind:"addingAgent",projectId:d.projectId})},className:"btn-primary",children:"继续添加 Agent"})]}),children:e.jsx("p",{className:"text-[13px] text-og-700",children:"现在添加第一个 Agent,还是稍后再加?"})}),d.kind==="addingAgent"&&e.jsx(ts,{open:!0,projectId:d.projectId,onClose:()=>v({kind:"closed"}),onCreated:()=>{a()}}),e.jsx(ut,{open:m,onClose:()=>h(!1),onCreated:B=>t(B.id)})]})}function kn({project:t,agentsById:s,agentsLoaded:r,agentsError:a,onAgentDeleted:n}){const{data:i,error:u}=Jt(t.id),f=i??[],m=(u==null?void 0:u.message)??null;return e.jsxs("div",{className:"mb-10",children:[e.jsxs("div",{className:"mb-3 -mx-2 flex items-baseline gap-x-3 gap-y-1 px-2 py-1",children:[e.jsx("h2",{className:"min-w-0 truncate font-display text-[17px] font-semibold tracking-tight text-og-1000",title:t.id,children:e.jsx(Re,{to:`/project/${t.id}`,className:"hover:text-accent-hover",children:t.id})}),e.jsx("span",{className:"hidden min-w-0 truncate font-mono text-[12px] text-og-500 sm:inline-block",title:t.repo,children:t.repo}),e.jsx(Re,{to:`/project/${t.id}`,className:"ml-auto text-[13px] text-accent hover:text-accent-hover","aria-label":`Details — ${t.id}`,children:"Details →"})]}),m&&e.jsxs("div",{className:"mb-2 text-[12px] text-danger",children:["任务列表加载失败:",m]}),t.agent.flat().length===0?e.jsx("div",{className:"rounded-lg border border-hairline bg-surface py-6 text-center text-[13px] text-og-500",children:"还没有 Agent。进入 Details 添加。"}):e.jsx("div",{className:t.agent.length===1?"space-y-3":"grid grid-cols-1 gap-3 xl:grid-cols-2",children:t.agent.map((h,b)=>e.jsx(es,{group:h,projectId:t.id,agentsById:s,agentsLoaded:r,agentsError:a,tasks:f,onDeleted:n,terminalMode:"embedded-full"},h.map(g=>g.id).join(":")||b))})]})}function Ue(t){const s=t.match(/^task-(\d+)$/);return s?parseInt(s[1],10):Number.NaN}function Sn(t,s){const r=Ue(t.id),a=Ue(s.id);return Number.isNaN(r)||Number.isNaN(a)?t.id.localeCompare(s.id):r-a}function En(t,s){const r=(s.updatedAt??"").localeCompare(t.updatedAt??"");if(r!==0)return r;const a=Ue(t.id),n=Ue(s.id);return Number.isNaN(a)||Number.isNaN(n)?s.id.localeCompare(t.id):n-a}function Bt(t,s){const[r,a]=o.useState(Ve);o.useEffect(()=>a(Ve),[s]);const n=t.slice(0,r),i=t.length>n.length;return{items:n,hasMore:i,loadMore:()=>a(f=>f+Ve),total:t.length}}function Cn(t){const[s,r]=o.useState([]),[a,n]=o.useState(!1),[i,u]=o.useState(!1),[f,m]=o.useState(!1),[h,b]=o.useState(null),g=o.useRef(0),d=o.useRef(0),v=o.useCallback(I=>{const x=++g.current,p=I==="first"?0:d.current;u(!0),b(null),M.tasks.page(t,{category:"done",offset:p}).then(S=>{g.current===x&&(r(_=>I==="first"?S.tasks:[..._,...S.tasks]),n(S.hasMore),d.current=S.nextOffset,m(!0),u(!1))},S=>{g.current===x&&(b(S instanceof Error?S.message:String(S)),u(!1))})},[t]);return o.useEffect(()=>{g.current+=1,d.current=0,r([]),n(!1),m(!1),b(null),u(!1)},[t]),{items:s,hasMore:a,loading:i,loaded:f,error:h,load:v}}function Rn({projectId:t,openTasks:s,onClose:r,className:a=""}){const n=o.useMemo(()=>s.filter(d=>Wt.has(d.status)).sort(En),[s]),i=o.useMemo(()=>s.filter(d=>d.status==="pending").sort(Sn),[s]),u=Bt(n,t),f=Bt(i,t),m=Cn(t),[h,b]=o.useState(!1);o.useEffect(()=>{b(!1)},[t]);const g=()=>{if(h){b(!1);return}b(!0),m.load("first")};return e.jsxs("aside",{"aria-label":"Task 面板",className:`flex flex-col rounded-lg border border-hairline bg-surface ${a}`,children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-hairline px-3 py-2",children:[e.jsx("h2",{className:"font-display text-[12px] font-semibold uppercase tracking-[0.06em] text-og-500",children:"Tasks"}),e.jsx("button",{type:"button",onClick:r,"aria-label":"关闭 Task 面板",className:"flex h-7 w-7 items-center justify-center rounded text-og-500 transition-colors hover:bg-og-100 hover:text-og-1000",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{children:[e.jsx(zt,{title:"IN PROGRESS",section:u,emptyHint:"暂无正在处理的任务"}),e.jsx(zt,{title:"PENDING",section:f,emptyHint:"暂无待处理的任务"}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:g,"aria-expanded":h,className:"flex w-full items-center justify-between px-3 py-2 text-left text-[11px] font-semibold uppercase tracking-[0.05em] text-og-500 transition-colors hover:bg-og-50/40",children:[e.jsx("span",{children:"DONE"}),e.jsx("span",{className:"font-normal normal-case text-accent",children:h?"收起":"查看"})]}),h&&e.jsx(An,{state:m})]})]})]})}function zt({title:t,section:s,emptyHint:r}){return e.jsxs("section",{"aria-label":t,className:"border-b border-hairline",children:[e.jsxs("div",{className:"px-3 py-2 text-[11px] font-semibold uppercase tracking-[0.05em] text-og-500",children:[t," ",e.jsxs("span",{className:"text-og-400",children:["(",s.total,")"]})]}),s.items.length===0?e.jsx("div",{className:"px-3 pb-3 text-[12px] text-og-400",children:r}):e.jsxs("div",{className:"divide-y divide-hairline",children:[s.items.map(a=>e.jsx(ss,{task:a},a.id)),s.hasMore&&e.jsx("button",{type:"button",onClick:s.loadMore,className:"w-full px-3 py-2 text-center text-[12px] text-accent transition-colors hover:bg-og-50/40",children:"加载更多"})]})]})}function An({state:t}){const s=t.loaded&&!t.error&&t.items.length===0;return e.jsxs("div",{className:"divide-y divide-hairline",children:[t.items.map(r=>e.jsx(ss,{task:r},r.id)),t.error&&e.jsxs("div",{className:"px-3 py-2 text-[12px] text-danger",children:["加载失败:",t.error]}),s&&e.jsx("div",{className:"px-3 pb-3 pt-1 text-[12px] text-og-400",children:"暂无已处理的任务"}),t.loading&&t.items.length===0&&e.jsx("div",{className:"px-3 py-3 text-center text-[12px] text-og-400",children:"加载中…"}),t.hasMore&&e.jsx("button",{type:"button",onClick:()=>t.load("more"),disabled:t.loading,className:"w-full px-3 py-2 text-center text-[12px] text-accent transition-colors hover:bg-og-50/40 disabled:opacity-50",children:t.loading?"加载中…":"加载更多"})]})}function ss({task:t}){const{openTask:s}=$e(),r=t.phase==="spec"?t.specReviewRound??0:t.reviewRound;return e.jsxs("button",{type:"button",onClick:()=>s(t.id),className:"flex w-full items-center gap-2 px-3 py-2 text-left text-[13px] transition-colors hover:bg-og-50/60",children:[e.jsx("span",{className:"shrink-0 font-mono text-[11px] text-og-500",title:t.id,children:ht(t.id)}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-og-1000",title:t.title,children:t.title}),t.phase==="spec"&&e.jsx("span",{className:"pill pill-review shrink-0",children:"spec"}),e.jsxs("span",{"aria-label":`Round ${r}`,className:"shrink-0 text-[11px] text-og-400",children:["R",r]}),e.jsx(un,{status:t.status})]})}const Tn=[],ns="baxian.taskPanel.open";function In(){try{return localStorage.getItem(ns)==="1"}catch{return!1}}function $n(){const{id:t}=Ht(),s=ls(),{show:r}=fe(),{openTask:a}=$e(),{refresh:n}=qe(),[i,u]=o.useState(null),[f,m]=o.useState(null),[h,b]=o.useState(!1),[g,d]=o.useState(!1),[v,I]=o.useState(In),[x,p]=o.useState(!1),[S,_]=o.useState(!1),[N,E]=o.useState(""),[y,c]=o.useState(!1),[$,F]=o.useState(null),z=o.useRef(null),B=o.useRef(null),j=o.useId(),L=o.useId(),D=o.useRef(0),{data:U,loaded:W,error:K}=Vt(),{data:V,error:se}=Jt(t),l=(K==null?void 0:K.message)??null,T=(se==null?void 0:se.message)??null,H=V??Tn,Z=new Map((U??[]).map(O=>[O.id,O])),ne=f??l??T,te=o.useCallback(async O=>{const w=++D.current;try{const P=await M.projects.get(O);if(w!==D.current)return;u(P),m(null)}catch(P){if(w!==D.current)return;m(P instanceof Error?P.message:String(P))}},[]);o.useEffect(()=>{t&&(u(null),m(null),te(t))},[t,te]),o.useEffect(()=>{if(!x)return;const O=P=>{var ee,ce;const R=P.target;R&&((ee=B.current)!=null&&ee.contains(R)||(ce=z.current)!=null&&ce.contains(R)||p(!1))},w=P=>{var R;P.key==="Escape"&&(p(!1),(R=z.current)==null||R.focus())};return document.addEventListener("mousedown",O),document.addEventListener("keydown",w),()=>{document.removeEventListener("mousedown",O),document.removeEventListener("keydown",w)}},[x]),o.useEffect(()=>{S||(E(""),F(null))},[S]),o.useEffect(()=>{try{localStorage.setItem(ns,v?"1":"0")}catch{}},[v]);const C=(i==null?void 0:i.agent.flat().length)??0,Q=C===0,G=!!i&&N.trim()===i.id,oe=async()=>{if(!(!i||!G||y)){c(!0),F(null);try{await M.projects.delete(i.id),await n(),r({kind:"success",title:`项目 ${i.id} 已删除`}),_(!1),s("/")}catch(O){F(O instanceof Error?O.message:String(O))}finally{c(!1)}}};return i?e.jsxs("div",{children:[ne&&e.jsxs("div",{className:"mb-4 text-[13px] text-danger",children:["Error: ",ne]}),e.jsxs("div",{className:"mb-6 flex items-baseline gap-x-3",children:[e.jsx("h1",{className:"min-w-0 truncate font-display text-[17px] font-semibold tracking-tight text-og-1000",title:i.id,children:i.id}),e.jsx("span",{className:"hidden min-w-0 truncate font-mono text-[12px] text-og-500 sm:inline-block",title:i.repo,children:i.repo}),e.jsxs("div",{className:"ml-auto flex items-center gap-1 self-center",children:[!v&&e.jsx("button",{type:"button",onClick:()=>I(!0),"aria-label":"打开 Task 面板",className:"btn-ghost",children:"Tasks"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{ref:z,id:L,type:"button",onClick:()=>p(O=>!O),"aria-haspopup":"menu","aria-expanded":x,"aria-controls":j,"aria-label":`项目 ${i.id} 操作菜单`,className:"flex h-8 w-8 items-center justify-center rounded text-og-500 transition-colors hover:bg-og-100 hover:text-og-1000",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"12",r:"1"}),e.jsx("circle",{cx:"12",cy:"5",r:"1"}),e.jsx("circle",{cx:"12",cy:"19",r:"1"})]})}),x&&e.jsxs("div",{ref:B,id:j,role:"menu","aria-labelledby":L,className:"absolute right-0 top-full z-10 mt-1 min-w-[180px] rounded-md border border-hairline bg-surface py-1 shadow-md",children:[e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{p(!1),b(!0)},className:"block w-full px-3 py-1.5 text-left text-[13px] text-og-800 hover:bg-og-100 hover:text-og-1000",children:"添加 Agent"}),e.jsx("div",{role:"none",className:"my-1 border-t border-hairline"}),e.jsx("button",{type:"button",role:"menuitem",onClick:()=>{p(!1),_(!0)},disabled:!Q,title:Q?void 0:`请先删除项目下的 ${C} 个 Agent`,className:"block w-full px-3 py-1.5 text-left text-[13px] text-danger hover:bg-[#fef2f2] disabled:cursor-not-allowed disabled:text-og-400 disabled:hover:bg-transparent",children:"删除项目…"})]})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-3 flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("h2",{className:"font-display text-[12px] font-semibold uppercase tracking-[0.06em] text-og-500",children:"Agents"}),e.jsx("button",{onClick:()=>d(!0),className:"btn-ghost",children:"+ 新建 Task"})]}),i.agent.flat().length===0?e.jsx("div",{className:"mb-8 rounded-lg border border-hairline bg-surface py-6 text-center text-[13px] text-og-500",children:"还没有 Agent,点击右上角菜单添加。"}):e.jsx("div",{className:"mb-8 space-y-5",children:i.agent.map((O,w)=>e.jsx(es,{group:O,projectId:i.id,agentsById:Z,agentsLoaded:W,agentsError:!!K,tasks:H,onDeleted:()=>{te(i.id)},terminalMode:"embedded-full"},O.map(P=>P.id).join(":")||w))})]}),v&&e.jsx(Rn,{projectId:i.id,openTasks:H,onClose:()=>I(!1),className:"w-full lg:w-[340px] lg:shrink-0 xl:w-[380px]"})]}),e.jsx(ts,{open:h,projectId:i.id,onClose:()=>b(!1),onCreated:()=>{te(i.id)}}),e.jsx(ut,{open:g,projectId:i.id,onClose:()=>d(!1),onCreated:O=>a(O.id)}),e.jsx(ve,{open:S,onClose:()=>{y||_(!1)},title:"删除项目",size:"sm",footer:e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:()=>_(!1),disabled:y,className:"btn-secondary",children:"取消"}),e.jsx("button",{type:"button",onClick:()=>void oe(),disabled:!G||y,className:"btn-secondary !text-danger hover:!bg-[#fef2f2] hover:!text-danger disabled:!text-og-300",children:y?"删除中…":"确认删除"})]}),children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-[13px] text-og-700",children:["将从 ",e.jsx("code",{className:"font-mono text-og-1000",children:"baxian.json"})," 中移除项目"," ",e.jsx("span",{className:"font-mono text-og-1000",children:i.id}),"。此操作不可撤销,且不会删除 Git 仓库本身。"]}),e.jsxs("p",{className:"text-[13px] text-og-700",children:["如需确认,请在下方输入项目 ID ",e.jsx("span",{className:"font-mono text-og-1000",children:i.id}),":"]}),e.jsx("input",{type:"text",value:N,onChange:O=>E(O.target.value),placeholder:i.id,autoComplete:"off",autoCorrect:"off",spellCheck:!1,disabled:y,"aria-label":"输入项目 ID 以确认删除",className:"w-full rounded border border-hairline bg-surface px-3 py-2 font-mono text-[13px] text-og-1000 focus:border-accent focus:outline-none"}),$&&e.jsx("div",{className:"rounded-md border border-[#fecaca] bg-[#fef2f2] px-3 py-2 text-[12px] text-danger",children:$})]})})]}):f?e.jsxs("div",{className:"text-[13px] text-danger",children:["Error: ",f]}):e.jsx("div",{className:"text-[13px] text-og-500",children:"Loading…"})}function Dn(){const{agentId:t}=Ht(),{projects:s}=qe(),r=o.useMemo(()=>{if(t)for(const a of s??[])for(const n of a.agent){const i=n.find(u=>u.id===t);if(i)return i.runtime}},[t,s]);return t?e.jsxs("div",{"data-testid":"terminal-page-container",className:"flex min-h-0 flex-1 flex-col overflow-hidden border border-hairline bg-surface",children:[e.jsxs("div",{className:"flex h-8 flex-none select-none items-center gap-3 border-b border-hairline bg-page px-3 font-mono text-[11px] text-og-500",children:[e.jsx("span",{"aria-hidden":!0,className:"block h-1.5 w-1.5 rounded-full bg-success"}),e.jsx("span",{className:"text-og-700",title:ct(t,r),children:t})]}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(Ee,{agentId:t,mode:"full",interactive:!0,arrowKeys:!0})})]}):e.jsx("div",{className:"text-[13px] text-danger",children:"No agent specified"})}function Pn(){const[t,s]=o.useState(!1);return e.jsx("button",{type:"button",onClick:()=>s(r=>!r),"aria-label":t?"切换为 Logo 图标":"切换为 Logo 文字",className:"flex h-7 min-w-[60px] shrink-0 items-center justify-center font-display text-[15px] font-semibold tracking-tight text-og-1000",children:t?e.jsx("span",{className:"inline-flex h-6 items-center leading-none",children:"baxian"}):e.jsx("img",{src:"/baxian-logo.png",alt:"baxian",width:20,height:24,className:"block h-6 w-auto"})})}function Mn(){const{phase:t,count:s,error:r,triggerRestart:a}=Ge();return t==="idle"?null:t==="failed"?e.jsxs("div",{className:"flex items-center justify-between border-b border-[#fecaca] bg-[#fef2f2] px-4 py-2",children:[e.jsxs("div",{className:"text-[13px] text-danger",children:["❌ 重启失败:",r]}),e.jsx("button",{onClick:()=>{a()},className:"btn-ghost !text-danger hover:!bg-[#fef2f2]",children:"重试"})]}):t==="restarting"?e.jsx("div",{className:"border-b border-accent-soft bg-accent-soft/40 px-4 py-2 text-[13px] text-accent",children:"🔄 重启中…"}):e.jsxs("div",{className:"flex items-center justify-between border-b border-[#fde68a] bg-[#fef3c7]/60 px-4 py-2",children:[e.jsxs("div",{className:"text-[13px] text-warn",children:["⚠️ 有 ",s," 项配置变更待重启 baxian server 才生效"]}),e.jsx("button",{onClick:()=>{a()},className:"btn-secondary !border-warn !text-warn hover:!bg-[#fef3c7] hover:!border-warn hover:!text-warn",children:"现在重启"})]})}function Ln(){const s=!us().pathname.startsWith("/terminal/");return e.jsxs("div",{className:"flex h-dvh flex-col bg-page",children:[e.jsx("nav",{className:"flex h-12 flex-none items-center border-b border-hairline bg-surface px-3 sm:px-6",children:e.jsxs(Re,{to:"/",className:"flex shrink-0 items-center gap-2 font-display text-[15px] font-semibold tracking-tight text-og-1000",children:[e.jsx("span",{"aria-hidden":!0,className:"block h-2.5 w-2.5 rounded-full bg-accent"}),"baxian"]})}),e.jsx(Mn,{}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto px-3 py-6 sm:px-6",children:[e.jsxs(fs,{children:[e.jsx(Ke,{path:"/",element:e.jsx(Nn,{})}),e.jsx(Ke,{path:"/project/:id",element:e.jsx($n,{})}),e.jsx(Ke,{path:"/terminal/:agentId",element:e.jsx(Dn,{})})]}),s&&e.jsx("footer",{className:"mt-auto flex justify-center pb-4 pt-24",children:e.jsx(Pn,{})})]})]})}function On(){return e.jsx(ds,{children:e.jsx(Ln,{})})}function _n({children:t}){const[s,r]=o.useState({kind:"probing"}),a=o.useRef(s);o.useEffect(()=>{a.current=s},[s]);const n=o.useCallback(async()=>{r({kind:"probing"});try{await M.config.get(),r({kind:"authorized"})}catch(i){if(i instanceof Te&&i.status===401){r({kind:"unauthorized"});return}const u=i instanceof Error?i.message:"无法连接服务器";r({kind:"error",message:u})}},[]);return o.useEffect(()=>{n()},[n]),o.useEffect(()=>{const i=()=>{a.current.kind!=="probing"&&r({kind:"unauthorized",message:"登录已失效,请重新输入令牌"})};return window.addEventListener(Fe,i),()=>window.removeEventListener(Fe,i)},[]),s.kind==="authorized"?e.jsx(e.Fragment,{children:t}):s.kind==="error"?e.jsxs(at,{title:"无法连接服务器",children:[e.jsx("p",{className:"text-[13px] text-og-600",children:s.message}),e.jsx("button",{type:"button",onClick:()=>{n()},className:"btn-primary mt-4 w-full",children:"重试"})]}):s.kind==="probing"?e.jsx(at,{title:"加载中",children:e.jsx("p",{className:"text-[13px] text-og-500",children:"正在检查登录状态…"})}):e.jsx(Fn,{message:s.message,onSubmit:async i=>{ms(i);try{await M.config.get(),r({kind:"authorized"})}catch(u){if(xs(),u instanceof Te&&u.status===401){r({kind:"unauthorized",message:"令牌无效,请重试"});return}const f=u instanceof Error?u.message:"登录失败";r({kind:"error",message:f})}}})}function at({title:t,children:s}){return e.jsx("div",{className:"flex min-h-dvh items-center justify-center bg-page px-4",children:e.jsxs("div",{className:"w-full max-w-sm rounded-lg border border-hairline bg-surface px-6 py-6",children:[e.jsx("h1",{className:"mb-3 font-display text-[16px] font-semibold tracking-tight text-og-1000",children:t}),s]})})}function Fn({message:t,onSubmit:s}){const[r,a]=o.useState(""),[n,i]=o.useState(!1),[u,f]=o.useState(void 0),m=async b=>{b.preventDefault();const g=r.trim();if(!g){f("请输入访问令牌");return}f(void 0),i(!0);try{await s(g)}finally{i(!1)}},h=u??t;return e.jsxs(at,{title:"登录 baxian",children:[e.jsx("p",{className:"mb-4 text-[13px] text-og-600",children:"服务器开启了访问鉴权,请输入访问令牌继续。"}),e.jsxs("form",{onSubmit:b=>{m(b)},children:[e.jsx("label",{className:"mb-1.5 block text-[12px] font-medium text-og-700",htmlFor:"baxian-token",children:"访问令牌"}),e.jsx("input",{id:"baxian-token",type:"password",autoComplete:"current-password",autoFocus:!0,value:r,onChange:b=>a(b.target.value),className:"w-full rounded-md border border-og-100 bg-surface px-2.5 py-1.5 font-mono text-[13px] text-og-800 placeholder:text-og-400 focus:border-accent focus:outline-none focus:ring-[3px] focus:ring-accent-soft disabled:cursor-not-allowed disabled:opacity-50",placeholder:"请输入服务器配置的 token",disabled:n}),h&&e.jsx("p",{role:"alert",className:"mt-2 text-[12px] text-danger",children:h}),e.jsx("button",{type:"submit",disabled:n,className:"btn-primary mt-4 w-full",children:n?"登录中…":"登录"})]})]})}as.createRoot(document.getElementById("root")).render(e.jsx(o.StrictMode,{children:e.jsx(Ss,{children:e.jsx(ys,{children:e.jsx(_n,{children:e.jsx(ln,{children:e.jsx(On,{})})})})})}));
|
package/dist/web/index.html
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/baxian-logo.png" />
|
|
7
7
|
<link rel="apple-touch-icon" href="/baxian-logo.png" />
|
|
8
8
|
<title>baxian</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-OtgjyQI1.js"></script>
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/react-BG4Iuztk.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/xterm-D5X2JljJ.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/router-eEZdpwQZ.js">
|