@multiclawcli/dashboard 0.0.0-stage → 0.1.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.
Files changed (40) hide show
  1. package/LICENSE +21 -0
  2. package/components.json +16 -0
  3. package/dist/client/assets/index-B7LsRfEa.css +1 -0
  4. package/dist/client/assets/index-EMPKFi-_.js +58 -0
  5. package/dist/client/index.html +13 -0
  6. package/dist/server/DashboardServer.d.ts +14 -0
  7. package/dist/server/DashboardServer.js +37 -0
  8. package/dist/server/DashboardServer.js.map +1 -0
  9. package/dist/server/WebSocketHub.d.ts +9 -0
  10. package/dist/server/WebSocketHub.js +31 -0
  11. package/dist/server/WebSocketHub.js.map +1 -0
  12. package/dist/server/index.d.ts +2 -0
  13. package/dist/server/index.js +2 -0
  14. package/dist/server/index.js.map +1 -0
  15. package/index.html +12 -0
  16. package/package.json +41 -3
  17. package/postcss.config.js +3 -0
  18. package/src/client/App.tsx +62 -0
  19. package/src/client/components/AgentCard.tsx +50 -0
  20. package/src/client/components/LogPanel.tsx +41 -0
  21. package/src/client/components/StageList.tsx +30 -0
  22. package/src/client/components/ui/badge.tsx +28 -0
  23. package/src/client/components/ui/button.tsx +43 -0
  24. package/src/client/components/ui/card.tsx +22 -0
  25. package/src/client/components/ui/scroll-area.tsx +43 -0
  26. package/src/client/components/ui/separator.tsx +23 -0
  27. package/src/client/hooks/useWebSocket.ts +33 -0
  28. package/src/client/index.css +31 -0
  29. package/src/client/lib/utils.ts +6 -0
  30. package/src/client/main.tsx +8 -0
  31. package/src/client/store/useOrchestrationStore.ts +79 -0
  32. package/src/server/DashboardServer.ts +56 -0
  33. package/src/server/WebSocketHub.ts +35 -0
  34. package/src/server/index.ts +2 -0
  35. package/tailwind.config.js +50 -0
  36. package/tsconfig.json +12 -0
  37. package/tsconfig.server.json +9 -0
  38. package/tsconfig.server.tsbuildinfo +1 -0
  39. package/vite.config.ts +25 -0
  40. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DashboardServer.js","sourceRoot":"","sources":["../../src/server/DashboardServer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAA;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAO7C,MAAM,OAAO,eAAe;IAK1B,YAAY,OAA+B;QACzC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QAExB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;QAElF,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YAC3C,IAAI,QAAQ,GAAG,IAAI,CAAC,IAAI,CACtB,UAAU,EACV,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,GAAI,CAC1C,CAAA;YACD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;gBAAE,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;YAE5E,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;YAClC,MAAM,IAAI,GAA2B;gBACnC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,iBAAiB;gBAC9C,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe;aAC5C,CAAA;YACD,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;YAC5C,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;YAC3D,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,YAAY,EAAE,CAAC,CAAA;YACjE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,MAAM,GAAG,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;QACxD,IAAI,CAAC,GAAG,GAAG,IAAI,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAA;IAC9D,CAAC;IAED,KAAK;QACH,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAA;IACjF,CAAC;IAED,YAAY,CAAC,QAAkB;QAC7B,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;IAClD,CAAC;IAED,IAAI;QACF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACrB,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ import { WebSocketServer } from "ws";
2
+ import type { MultiClawEvent } from "@multiclawcli/core";
3
+ export declare class WebSocketHub {
4
+ private wss;
5
+ private clients;
6
+ private history;
7
+ constructor(wss: WebSocketServer, acceptClientEvents?: boolean);
8
+ broadcast(event: MultiClawEvent): void;
9
+ }
@@ -0,0 +1,31 @@
1
+ export class WebSocketHub {
2
+ constructor(wss, acceptClientEvents = false) {
3
+ this.clients = new Set();
4
+ this.history = [];
5
+ this.wss = wss;
6
+ this.wss.on("connection", (ws) => {
7
+ this.clients.add(ws);
8
+ for (const e of this.history)
9
+ ws.send(JSON.stringify(e));
10
+ if (acceptClientEvents) {
11
+ ws.on("message", (data) => {
12
+ try {
13
+ const event = JSON.parse(data.toString());
14
+ this.broadcast(event);
15
+ }
16
+ catch { /* ignore */ }
17
+ });
18
+ }
19
+ ws.on("close", () => this.clients.delete(ws));
20
+ });
21
+ }
22
+ broadcast(event) {
23
+ this.history.push(event);
24
+ const msg = JSON.stringify(event);
25
+ for (const ws of this.clients) {
26
+ if (ws.readyState === ws.OPEN)
27
+ ws.send(msg);
28
+ }
29
+ }
30
+ }
31
+ //# sourceMappingURL=WebSocketHub.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebSocketHub.js","sourceRoot":"","sources":["../../src/server/WebSocketHub.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,YAAY;IAKvB,YAAY,GAAoB,EAAE,kBAAkB,GAAG,KAAK;QAHpD,YAAO,GAAG,IAAI,GAAG,EAAa,CAAA;QAC9B,YAAO,GAAqB,EAAE,CAAA;QAGpC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE;YAC/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;YACpB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO;gBAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;YAExD,IAAI,kBAAkB,EAAE,CAAC;gBACvB,EAAE,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE;oBACxB,IAAI,CAAC;wBACH,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAmB,CAAA;wBAC3D,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;oBACvB,CAAC;oBAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAA;YACJ,CAAC;YAED,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,SAAS,CAAC,KAAqB;QAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QACjC,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAC9B,IAAI,EAAE,CAAC,UAAU,KAAK,EAAE,CAAC,IAAI;gBAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export { DashboardServer } from "./DashboardServer";
2
+ export type { DashboardServerOptions } from "./DashboardServer";
@@ -0,0 +1,2 @@
1
+ export { DashboardServer } from "./DashboardServer";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA"}
package/index.html ADDED
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>MultiClaw Dashboard</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="/src/client/main.tsx"></script>
11
+ </body>
12
+ </html>
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@multiclawcli/dashboard",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "exports": {
6
+ "./server": {
7
+ "types": "./dist/server/index.d.ts",
8
+ "default": "./dist/server/index.js"
9
+ }
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "dependencies": {
15
+ "ws": "^8.16.0",
16
+ "zustand": "^4.5.0",
17
+ "react": "^18.2.0",
18
+ "react-dom": "^18.2.0",
19
+ "class-variance-authority": "^0.7.0",
20
+ "clsx": "^2.1.0",
21
+ "tailwind-merge": "^2.2.0",
22
+ "lucide-react": "^0.400.0",
23
+ "@radix-ui/react-scroll-area": "^1.0.5",
24
+ "@radix-ui/react-slot": "^1.0.2",
25
+ "@radix-ui/react-separator": "^1.0.3",
26
+ "@multiclawcli/core": "0.1.0"
27
+ },
28
+ "devDependencies": {
29
+ "@vitejs/plugin-react": "^4.2.0",
30
+ "vite": "^5.1.0",
31
+ "tailwindcss": "^3.4.0",
32
+ "tailwindcss-animate": "^1.0.7",
33
+ "autoprefixer": "^10.4.0",
34
+ "postcss": "^8.4.0",
35
+ "typescript": "^5.4.0",
36
+ "@types/react": "^18.2.0",
37
+ "@types/react-dom": "^18.2.0",
38
+ "@types/ws": "^8.5.0"
39
+ },
40
+ "scripts": {
41
+ "build": "vite build && tsc -p tsconfig.server.json",
42
+ "dev:client": "vite"
43
+ }
6
44
  }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ plugins: { tailwindcss: {}, autoprefixer: {} },
3
+ }
@@ -0,0 +1,62 @@
1
+ import React, { useState, useEffect } from "react"
2
+ import { Badge } from "@/components/ui/badge"
3
+ import { Separator } from "@/components/ui/separator"
4
+ import { useWebSocket } from "./hooks/useWebSocket"
5
+ import { useOrchestrationStore } from "./store/useOrchestrationStore"
6
+ import { StageList } from "./components/StageList"
7
+ import { LogPanel } from "./components/LogPanel"
8
+
9
+ export function App() {
10
+ const apply = useOrchestrationStore((s) => s.apply)
11
+ const { name, running, success, totalDuration } = useOrchestrationStore()
12
+ const [selected, setSelected] = useState<string | null>(null)
13
+ const [elapsed, setElapsed] = useState(0)
14
+
15
+ useWebSocket(apply)
16
+
17
+ useEffect(() => {
18
+ if (!running) { setElapsed(0); return }
19
+ const start = Date.now()
20
+ const id = setInterval(() => setElapsed(Date.now() - start), 1000)
21
+ return () => clearInterval(id)
22
+ }, [running])
23
+
24
+ const statusBadge = running
25
+ ? <Badge className="bg-green-500 hover:bg-green-500/80">运行中</Badge>
26
+ : success === undefined
27
+ ? <Badge variant="secondary">等待中</Badge>
28
+ : success
29
+ ? <Badge className="bg-green-500 hover:bg-green-500/80">完成</Badge>
30
+ : <Badge variant="destructive">存在失败</Badge>
31
+
32
+ const displayDuration = totalDuration != null
33
+ ? totalDuration
34
+ : running ? elapsed : null
35
+
36
+ return (
37
+ <div className="h-screen flex flex-col bg-background">
38
+ <header className="flex items-center justify-between px-6 py-3 border-b">
39
+ <h1 className="text-base font-semibold">
40
+ MultiClaw{name && <span className="text-muted-foreground font-normal"> · {name}</span>}
41
+ </h1>
42
+ <div className="flex items-center gap-3 text-sm">
43
+ {displayDuration != null && (
44
+ <span className="text-muted-foreground">
45
+ ⏱ {(displayDuration / 1000).toFixed(1)}s
46
+ </span>
47
+ )}
48
+ {statusBadge}
49
+ </div>
50
+ </header>
51
+ <main className="flex-1 flex gap-4 p-4 overflow-hidden">
52
+ <div className="w-80 overflow-auto">
53
+ <StageList onSelect={setSelected} selectedId={selected} />
54
+ </div>
55
+ <Separator orientation="vertical" />
56
+ <div className="flex-1 overflow-hidden">
57
+ <LogPanel agentId={selected} />
58
+ </div>
59
+ </main>
60
+ </div>
61
+ )
62
+ }
@@ -0,0 +1,50 @@
1
+ import React from "react"
2
+ import { Card, CardContent } from "@/components/ui/card"
3
+ import { Badge } from "@/components/ui/badge"
4
+ import { cn } from "@/lib/utils"
5
+
6
+ type AgentStatus = "pending" | "running" | "retrying" | "success" | "failed" | "skipped"
7
+
8
+ const STATUS_CONFIG: Record<AgentStatus, {
9
+ label: string
10
+ variant: "secondary" | "default" | "destructive" | "outline"
11
+ className?: string
12
+ }> = {
13
+ pending: { label: "等待中", variant: "secondary" },
14
+ running: { label: "运行中", variant: "default", className: "animate-pulse" },
15
+ retrying: { label: "重试中", variant: "default", className: "animate-pulse bg-yellow-500 hover:bg-yellow-500/80" },
16
+ success: { label: "完成", variant: "default", className: "bg-green-500 hover:bg-green-500/80" },
17
+ failed: { label: "失败", variant: "destructive" },
18
+ skipped: { label: "跳过", variant: "outline" },
19
+ }
20
+
21
+ export function AgentCard({ agent, onClick, selected }: {
22
+ agent: { name: string; icon?: string; status: string; duration?: number }
23
+ onClick: () => void
24
+ selected?: boolean
25
+ }) {
26
+ const cfg = STATUS_CONFIG[agent.status as AgentStatus] ?? STATUS_CONFIG.pending
27
+ return (
28
+ <Card
29
+ onClick={onClick}
30
+ className={cn("cursor-pointer hover:bg-accent transition-colors", selected && "bg-accent ring-1 ring-ring")}
31
+ >
32
+ <CardContent className="flex items-center justify-between p-3">
33
+ <div className="flex items-center gap-2">
34
+ <span>{agent.icon ?? "▶"}</span>
35
+ <span className="font-medium text-sm">{agent.name}</span>
36
+ </div>
37
+ <div className="flex items-center gap-2">
38
+ {agent.duration != null && (
39
+ <span className="text-xs text-muted-foreground">
40
+ {(agent.duration / 1000).toFixed(1)}s
41
+ </span>
42
+ )}
43
+ <Badge variant={cfg.variant} className={cn(cfg.className)}>
44
+ {cfg.label}
45
+ </Badge>
46
+ </div>
47
+ </CardContent>
48
+ </Card>
49
+ )
50
+ }
@@ -0,0 +1,41 @@
1
+ import React, { useEffect, useRef } from "react"
2
+ import { useOrchestrationStore } from "../store/useOrchestrationStore"
3
+
4
+ export function LogPanel({ agentId }: { agentId: string | null }) {
5
+ const agents = useOrchestrationStore((s) => s.agents)
6
+ const scrollRef = useRef<HTMLDivElement>(null)
7
+ const userScrolled = useRef(false)
8
+ const logs = agentId ? agents[agentId]?.logs ?? "" : ""
9
+ const agentName = agentId ? agents[agentId]?.name : null
10
+
11
+ const handleScroll = () => {
12
+ const el = scrollRef.current
13
+ if (!el) return
14
+ userScrolled.current = el.scrollHeight - el.scrollTop - el.clientHeight > 50
15
+ }
16
+
17
+ useEffect(() => {
18
+ if (userScrolled.current) return
19
+ const el = scrollRef.current
20
+ if (el) el.scrollTop = el.scrollHeight
21
+ }, [logs])
22
+
23
+ return (
24
+ <div
25
+ ref={scrollRef}
26
+ onScroll={handleScroll}
27
+ className="h-full overflow-auto rounded-lg border bg-zinc-950 text-zinc-100"
28
+ >
29
+ <div className="p-4 font-mono text-sm">
30
+ {agentId ? (
31
+ <>
32
+ <p className="text-zinc-400 mb-3 text-xs">📄 {agentName} 日志</p>
33
+ <pre className="whitespace-pre-wrap leading-relaxed">{logs}</pre>
34
+ </>
35
+ ) : (
36
+ <p className="text-zinc-500">← 选择一个 Agent 查看实时日志</p>
37
+ )}
38
+ </div>
39
+ </div>
40
+ )
41
+ }
@@ -0,0 +1,30 @@
1
+ import React from "react"
2
+ import { Separator } from "@/components/ui/separator"
3
+ import { useOrchestrationStore } from "../store/useOrchestrationStore"
4
+ import { AgentCard } from "./AgentCard"
5
+
6
+ export function StageList({ onSelect, selectedId }: { onSelect: (agentId: string) => void; selectedId?: string | null }) {
7
+ const { stages, agents } = useOrchestrationStore()
8
+ return (
9
+ <div className="space-y-4">
10
+ {stages.map((stage, idx) => (
11
+ <div key={stage.stageIndex}>
12
+ {idx > 0 && <Separator className="my-3" />}
13
+ <p className="text-xs font-semibold text-muted-foreground mb-2 uppercase tracking-wide">
14
+ Stage {stage.stageIndex + 1}
15
+ </p>
16
+ <div className="space-y-2">
17
+ {stage.agents.map((a) => (
18
+ <AgentCard
19
+ key={a.id}
20
+ agent={agents[a.id] ?? { name: a.name, icon: a.icon, status: "pending" }}
21
+ onClick={() => onSelect(a.id)}
22
+ selected={selectedId === a.id}
23
+ />
24
+ ))}
25
+ </div>
26
+ </div>
27
+ ))}
28
+ </div>
29
+ )
30
+ }
@@ -0,0 +1,28 @@
1
+ import * as React from "react"
2
+ import { cva, type VariantProps } from "class-variance-authority"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ const badgeVariants = cva(
6
+ "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
7
+ {
8
+ variants: {
9
+ variant: {
10
+ default: "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",
11
+ secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
12
+ destructive: "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",
13
+ outline: "text-foreground",
14
+ },
15
+ },
16
+ defaultVariants: { variant: "default" },
17
+ }
18
+ )
19
+
20
+ export interface BadgeProps
21
+ extends React.HTMLAttributes<HTMLDivElement>,
22
+ VariantProps<typeof badgeVariants> {}
23
+
24
+ function Badge({ className, variant, ...props }: BadgeProps) {
25
+ return <div className={cn(badgeVariants({ variant }), className)} {...props} />
26
+ }
27
+
28
+ export { Badge, badgeVariants }
@@ -0,0 +1,43 @@
1
+ import * as React from "react"
2
+ import { Slot } from "@radix-ui/react-slot"
3
+ import { cva, type VariantProps } from "class-variance-authority"
4
+ import { cn } from "@/lib/utils"
5
+
6
+ const buttonVariants = cva(
7
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
8
+ {
9
+ variants: {
10
+ variant: {
11
+ default: "bg-primary text-primary-foreground shadow hover:bg-primary/90",
12
+ destructive: "bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
13
+ outline: "border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
14
+ secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
15
+ ghost: "hover:bg-accent hover:text-accent-foreground",
16
+ link: "text-primary underline-offset-4 hover:underline",
17
+ },
18
+ size: {
19
+ default: "h-9 px-4 py-2",
20
+ sm: "h-8 rounded-md px-3 text-xs",
21
+ lg: "h-10 rounded-md px-8",
22
+ icon: "h-9 w-9",
23
+ },
24
+ },
25
+ defaultVariants: { variant: "default", size: "default" },
26
+ }
27
+ )
28
+
29
+ export interface ButtonProps
30
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
31
+ VariantProps<typeof buttonVariants> {
32
+ asChild?: boolean
33
+ }
34
+
35
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
36
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
37
+ const Comp = asChild ? Slot : "button"
38
+ return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
39
+ }
40
+ )
41
+ Button.displayName = "Button"
42
+
43
+ export { Button, buttonVariants }
@@ -0,0 +1,22 @@
1
+ import * as React from "react"
2
+ import { cn } from "@/lib/utils"
3
+
4
+ const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
5
+ ({ className, ...props }, ref) => (
6
+ <div
7
+ ref={ref}
8
+ className={cn("rounded-xl border bg-card text-card-foreground shadow", className)}
9
+ {...props}
10
+ />
11
+ )
12
+ )
13
+ Card.displayName = "Card"
14
+
15
+ const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
16
+ ({ className, ...props }, ref) => (
17
+ <div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
18
+ )
19
+ )
20
+ CardContent.displayName = "CardContent"
21
+
22
+ export { Card, CardContent }
@@ -0,0 +1,43 @@
1
+ import * as React from "react"
2
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ const ScrollArea = React.forwardRef<
6
+ React.ElementRef<typeof ScrollAreaPrimitive.Root>,
7
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
8
+ >(({ className, children, ...props }, ref) => (
9
+ <ScrollAreaPrimitive.Root
10
+ ref={ref}
11
+ className={cn("relative overflow-hidden", className)}
12
+ {...props}
13
+ >
14
+ <ScrollAreaPrimitive.Viewport className="h-full w-full rounded-[inherit]">
15
+ {children}
16
+ </ScrollAreaPrimitive.Viewport>
17
+ <ScrollBar />
18
+ <ScrollAreaPrimitive.Corner />
19
+ </ScrollAreaPrimitive.Root>
20
+ ))
21
+ ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName
22
+
23
+ const ScrollBar = React.forwardRef<
24
+ React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
25
+ React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>
26
+ >(({ className, orientation = "vertical", ...props }, ref) => (
27
+ <ScrollAreaPrimitive.ScrollAreaScrollbar
28
+ ref={ref}
29
+ orientation={orientation}
30
+ className={cn(
31
+ "flex touch-none select-none transition-colors",
32
+ orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]",
33
+ orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]",
34
+ className
35
+ )}
36
+ {...props}
37
+ >
38
+ <ScrollAreaPrimitive.ScrollAreaThumb className="relative flex-1 rounded-full bg-border" />
39
+ </ScrollAreaPrimitive.ScrollAreaScrollbar>
40
+ ))
41
+ ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName
42
+
43
+ export { ScrollArea, ScrollBar }
@@ -0,0 +1,23 @@
1
+ import * as React from "react"
2
+ import * as SeparatorPrimitive from "@radix-ui/react-separator"
3
+ import { cn } from "@/lib/utils"
4
+
5
+ const Separator = React.forwardRef<
6
+ React.ElementRef<typeof SeparatorPrimitive.Root>,
7
+ React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
8
+ >(({ className, orientation = "horizontal", decorative = true, ...props }, ref) => (
9
+ <SeparatorPrimitive.Root
10
+ ref={ref}
11
+ decorative={decorative}
12
+ orientation={orientation}
13
+ className={cn(
14
+ "shrink-0 bg-border",
15
+ orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
16
+ className
17
+ )}
18
+ {...props}
19
+ />
20
+ ))
21
+ Separator.displayName = SeparatorPrimitive.Root.displayName
22
+
23
+ export { Separator }
@@ -0,0 +1,33 @@
1
+ import { useEffect, useRef } from "react"
2
+ import type { MultiClawEvent } from "@multiclawcli/core"
3
+
4
+ export function useWebSocket(onEvent: (e: MultiClawEvent) => void): void {
5
+ const ref = useRef(onEvent)
6
+ ref.current = onEvent
7
+ // 编排完成后停止重连,避免 server 已关闭时持续刷错误
8
+ const doneRef = useRef(false)
9
+
10
+ useEffect(() => {
11
+ const wsUrl = `ws://${location.host}`
12
+ let ws: WebSocket
13
+ let retry: ReturnType<typeof setTimeout>
14
+
15
+ const connect = () => {
16
+ if (doneRef.current) return
17
+ ws = new WebSocket(wsUrl)
18
+ ws.onmessage = (msg) => {
19
+ try {
20
+ const event = JSON.parse(msg.data) as MultiClawEvent
21
+ if (event.type === "orchestration:complete") doneRef.current = true
22
+ ref.current(event)
23
+ } catch {}
24
+ }
25
+ ws.onclose = () => {
26
+ if (!doneRef.current) retry = setTimeout(connect, 1500)
27
+ }
28
+ }
29
+ connect()
30
+
31
+ return () => { clearTimeout(retry); ws?.close() }
32
+ }, [])
33
+ }
@@ -0,0 +1,31 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ @layer base {
6
+ :root {
7
+ --background: 0 0% 100%;
8
+ --foreground: 222.2 84% 4.9%;
9
+ --card: 0 0% 100%;
10
+ --card-foreground: 222.2 84% 4.9%;
11
+ --primary: 221.2 83.2% 53.3%;
12
+ --primary-foreground: 210 40% 98%;
13
+ --secondary: 210 40% 96.1%;
14
+ --secondary-foreground: 222.2 47.4% 11.2%;
15
+ --muted: 210 40% 96.1%;
16
+ --muted-foreground: 215.4 16.3% 46.9%;
17
+ --accent: 210 40% 96.1%;
18
+ --accent-foreground: 222.2 47.4% 11.2%;
19
+ --destructive: 0 84.2% 60.2%;
20
+ --destructive-foreground: 210 40% 98%;
21
+ --border: 214.3 31.8% 91.4%;
22
+ --input: 214.3 31.8% 91.4%;
23
+ --ring: 221.2 83.2% 53.3%;
24
+ --radius: 0.5rem;
25
+ }
26
+ }
27
+
28
+ @layer base {
29
+ * { @apply border-border; }
30
+ body { @apply bg-background text-foreground; }
31
+ }
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx"
2
+ import { twMerge } from "tailwind-merge"
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
@@ -0,0 +1,8 @@
1
+ import React from "react"
2
+ import ReactDOM from "react-dom/client"
3
+ import { App } from "./App"
4
+ import "./index.css"
5
+
6
+ ReactDOM.createRoot(document.getElementById("root")!).render(
7
+ <React.StrictMode><App /></React.StrictMode>
8
+ )
@@ -0,0 +1,79 @@
1
+ import { create } from "zustand"
2
+ import type { MultiClawEvent, StageInfo, AgentStatus } from "@multiclawcli/core"
3
+
4
+ const stripAnsi = (str: string) => str.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, "")
5
+
6
+ interface AgentState {
7
+ id: string
8
+ name: string
9
+ icon?: string
10
+ status: AgentStatus
11
+ duration?: number
12
+ logs: string
13
+ }
14
+
15
+ interface OrchestrationState {
16
+ name: string
17
+ running: boolean
18
+ success?: boolean
19
+ totalDuration?: number
20
+ stages: StageInfo[]
21
+ agents: Record<string, AgentState>
22
+ apply: (e: MultiClawEvent) => void
23
+ }
24
+
25
+ export const useOrchestrationStore = create<OrchestrationState>((set) => ({
26
+ name: "",
27
+ running: false,
28
+ stages: [],
29
+ agents: {},
30
+ apply: (e) => set((state) => {
31
+ const agents = { ...state.agents }
32
+ switch (e.type) {
33
+ case "orchestration:start": {
34
+ const map: Record<string, AgentState> = {}
35
+ for (const stage of e.payload.stages) {
36
+ for (const a of stage.agents) {
37
+ map[a.id] = { id: a.id, name: a.name, icon: a.icon, status: "pending", logs: "" }
38
+ }
39
+ }
40
+ return { name: e.payload.name, running: true, stages: e.payload.stages, agents: map }
41
+ }
42
+ case "agent:start":
43
+ agents[e.payload.agentId] = { ...agents[e.payload.agentId], status: "running" }
44
+ return { agents }
45
+ case "agent:output":
46
+ agents[e.payload.agentId] = {
47
+ ...agents[e.payload.agentId],
48
+ logs: (agents[e.payload.agentId]?.logs ?? "") + stripAnsi(e.payload.chunk),
49
+ }
50
+ return { agents }
51
+ case "agent:retrying":
52
+ agents[e.payload.agentId] = {
53
+ ...agents[e.payload.agentId],
54
+ status: "retrying",
55
+ logs: (agents[e.payload.agentId]?.logs ?? "") + `\n🔄 第 ${e.payload.attempt} 次重试 (共 ${e.payload.maxAttempts} 次)...\n`,
56
+ }
57
+ return { agents }
58
+ case "agent:complete":
59
+ agents[e.payload.agentId] = {
60
+ ...agents[e.payload.agentId], status: "success", duration: e.payload.duration,
61
+ }
62
+ return { agents }
63
+ case "agent:failed":
64
+ agents[e.payload.agentId] = {
65
+ ...agents[e.payload.agentId], status: "failed", duration: e.payload.duration,
66
+ }
67
+ return { agents }
68
+ case "agent:skipped":
69
+ agents[e.payload.agentId] = {
70
+ ...agents[e.payload.agentId], status: "skipped",
71
+ }
72
+ return { agents }
73
+ case "orchestration:complete":
74
+ return { running: false, success: e.payload.success, totalDuration: e.payload.totalDuration }
75
+ default:
76
+ return {}
77
+ }
78
+ }),
79
+ }))