@teamclaws/teamclaw 2026.8.0 → 2026.8.1
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/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +381 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-service.js +393 -0
- package/dist/src/controller/controller-tools.js +582 -0
- package/dist/src/controller/delivery-report.js +458 -0
- package/dist/src/controller/github-auth.js +564 -0
- package/dist/src/controller/http-server.js +6032 -0
- package/dist/src/controller/kickoff-orchestrator.js +220 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/orchestration-manifest.js +173 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/prompt-injector.js +187 -0
- package/dist/src/controller/role-inference.js +35 -0
- package/dist/src/controller/task-router.js +67 -0
- package/dist/src/controller/tunnel-manager.js +548 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1648 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +131 -0
- package/dist/src/install-defaults.js +1 -0
- package/dist/src/interaction-contracts.js +531 -0
- package/dist/src/networking.js +91 -0
- package/dist/src/openclaw-workspace.js +903 -0
- package/dist/src/prompt-policy.js +373 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/roles.js +349 -0
- package/dist/src/state.js +183 -0
- package/dist/src/task-executor.js +1033 -0
- package/dist/src/teamauto/github-client.js +192 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +201 -0
- package/dist/src/teamauto/scanner.js +179 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +688 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +243 -0
- package/dist/src/ui/app.js +4292 -0
- package/dist/src/ui/assets/teamclaw-app-icon.png +0 -0
- package/dist/src/ui/github-login.html +296 -0
- package/dist/src/ui/index.html +414 -0
- package/dist/src/ui/style.css +2611 -0
- package/dist/src/worker/http-handler.js +146 -0
- package/dist/src/worker/message-queue.js +24 -0
- package/dist/src/worker/prompt-injector.js +42 -0
- package/dist/src/worker/skill-installer.js +253 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +234 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,4292 @@
|
|
|
1
|
+
// TeamClaw Web UI
|
|
2
|
+
(function () {
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const API_BASE = "/api/v1";
|
|
6
|
+
let ws = null;
|
|
7
|
+
let currentFilter = "all";
|
|
8
|
+
let taskKeywordFilter = "";
|
|
9
|
+
let terminalTasksVisible = 20;
|
|
10
|
+
let activeTab = "tasks";
|
|
11
|
+
let teamState = { workers: [], tasks: [], controllerRuns: [], messages: [], clarifications: [], modelReadiness: null, externalWorkerInstall: null };
|
|
12
|
+
let selectedExternalWorkerRole = "developer";
|
|
13
|
+
let selectedExternalWorkerDiscoveryMode = "mdns";
|
|
14
|
+
let externalWorkerInstallVisible = false;
|
|
15
|
+
let selectedTaskId = null;
|
|
16
|
+
let selectedTaskDetail = null;
|
|
17
|
+
let selectedTaskDetailTab = "details";
|
|
18
|
+
let taskTimelineAutoFollow = true;
|
|
19
|
+
let workspaceTree = [];
|
|
20
|
+
let selectedWorkspacePath = null;
|
|
21
|
+
let selectedWorkspaceFile = null;
|
|
22
|
+
let selectedWorkspaceView = "source";
|
|
23
|
+
let workspaceLoaded = false;
|
|
24
|
+
let clarificationPromptOpen = false;
|
|
25
|
+
let activeClarificationId = null;
|
|
26
|
+
let dismissedClarificationIds = [];
|
|
27
|
+
let reconnectTimer = null;
|
|
28
|
+
let reconnectAttempts = 0;
|
|
29
|
+
let isConnecting = false;
|
|
30
|
+
const CONTROLLER_SESSION_STORAGE_KEY = "teamclaw.controllerSessionKey";
|
|
31
|
+
const CONTROLLER_CONVERSATION_STORAGE_KEY = "teamclaw.controllerConversation";
|
|
32
|
+
const LANGUAGE_STORAGE_KEY = "teamclaw.ui.language";
|
|
33
|
+
let controllerConversation = loadControllerConversation();
|
|
34
|
+
let controllerCommandPending = false;
|
|
35
|
+
const initialUiState = parseInitialUiState();
|
|
36
|
+
let initialUiStateApplied = false;
|
|
37
|
+
let currentLanguage = loadLanguage();
|
|
38
|
+
|
|
39
|
+
const TRANSLATIONS = {
|
|
40
|
+
en: {
|
|
41
|
+
"action.refresh": "Refresh",
|
|
42
|
+
"action.close": "Close",
|
|
43
|
+
"action.dismiss": "Dismiss",
|
|
44
|
+
"action.copyCommand": "Copy command",
|
|
45
|
+
"action.copied": "Copied",
|
|
46
|
+
"sidebar.workers": "Workers",
|
|
47
|
+
"sidebar.roles": "Roles",
|
|
48
|
+
"tab.planning": "Planning",
|
|
49
|
+
"tab.tasks": "Tasks",
|
|
50
|
+
"tab.workspace": "Workspace",
|
|
51
|
+
"tab.teamauto": "TeamAuto",
|
|
52
|
+
"tab.clarifications": "Clarifications",
|
|
53
|
+
"tab.messages": "Messages",
|
|
54
|
+
"tab.manualTask": "Manual Task",
|
|
55
|
+
"planning.title": "Team Planning",
|
|
56
|
+
"planning.description": "Submit a requirement via the command bar below. Complex projects (3+ roles) will trigger a team kickoff meeting where each role assesses the requirement collaboratively.",
|
|
57
|
+
"planning.sessions": "Sessions",
|
|
58
|
+
"planning.requirement": "Requirement",
|
|
59
|
+
"planning.kickoff": "Team Kickoff Meeting",
|
|
60
|
+
"planning.controllerOutput": "Controller Output",
|
|
61
|
+
"planning.originalRequest": "Original Request",
|
|
62
|
+
"planning.requiredRoles": "Required Roles",
|
|
63
|
+
"planning.plannedTasks": "Planned Tasks",
|
|
64
|
+
"planning.deferredTasks": "Deferred Tasks",
|
|
65
|
+
"planning.clarificationsNeeded": "Clarifications Needed",
|
|
66
|
+
"planning.notes": "Notes",
|
|
67
|
+
"planning.noControllerOutput": "No controller output yet.",
|
|
68
|
+
"workspace.preview": "Preview",
|
|
69
|
+
"workspace.selectFile": "Select a file",
|
|
70
|
+
"workspace.openRaw": "Open Raw",
|
|
71
|
+
"workspace.source": "Source",
|
|
72
|
+
"workspace.files": "Files",
|
|
73
|
+
"messages.panelNote": "Controller activity is persisted here so you can follow requirement intake, orchestration, and follow-up runs from the web UI.",
|
|
74
|
+
"manualTask.note": "Raw human requirements should go to the controller conversation first. Use this form only for explicit manual task injection or testing.",
|
|
75
|
+
"manualTask.title": "Title",
|
|
76
|
+
"manualTask.description": "Description",
|
|
77
|
+
"manualTask.skills": "Recommended Skills",
|
|
78
|
+
"manualTask.priority": "Priority",
|
|
79
|
+
"manualTask.assignedRole": "Assigned Role",
|
|
80
|
+
"manualTask.autoAssign": "Auto-assign",
|
|
81
|
+
"manualTask.create": "Create Manual Task",
|
|
82
|
+
"manualTask.titlePlaceholder": "Task title...",
|
|
83
|
+
"manualTask.descriptionPlaceholder": "Execution-ready task description...",
|
|
84
|
+
"manualTask.skillsPlaceholder": "Comma-separated skill slugs, e.g. find-skills, ui-ux-pro-max",
|
|
85
|
+
"empty.noWorkers": "No workers connected",
|
|
86
|
+
"empty.noTasks": "No tasks yet",
|
|
87
|
+
"empty.noTasksWithStatus": "No tasks with status \"{status}\"",
|
|
88
|
+
"empty.noClarifications": "No clarification requests",
|
|
89
|
+
"empty.noControllerActivity": "No controller activity yet",
|
|
90
|
+
"toast.taskCompleted": "Task completed",
|
|
91
|
+
"toast.taskFailed": "Task failed",
|
|
92
|
+
"toast.clarificationRequested": "Clarification needed",
|
|
93
|
+
"toast.clarificationAnswered": "Clarification answered",
|
|
94
|
+
"toast.teamautoPrefix": "TeamAuto",
|
|
95
|
+
"toast.workerOnline": "Worker online",
|
|
96
|
+
"toast.workerOffline": "Worker offline",
|
|
97
|
+
"toast.taskCreated": "Task created",
|
|
98
|
+
"toast.taskUpdated": "Task updated",
|
|
99
|
+
"toast.messageNew": "New message",
|
|
100
|
+
"toast.settingsTitle": "Toast notifications",
|
|
101
|
+
"toast.enableAll": "Enable all",
|
|
102
|
+
"toast.disableAll": "Disable all",
|
|
103
|
+
"toast.freqTaskCompleted": "Low - once per task",
|
|
104
|
+
"toast.freqTaskCreated": "Medium - once per flow stage",
|
|
105
|
+
"toast.freqTaskUpdated": "High - several times per task lifecycle",
|
|
106
|
+
"toast.freqClarification": "Rare - only when a worker needs a human decision",
|
|
107
|
+
"toast.freqWorker": "Topology-dependent - external workers rare; provisioned workers may cycle every task (idle TTL 120s)",
|
|
108
|
+
"toast.freqTeamauto": "Low - per sweep, claim, or write-back",
|
|
109
|
+
"toast.freqMessageNew": "High - every controller message",
|
|
110
|
+
"toast.taBind": "TeamAuto: repo bound",
|
|
111
|
+
"toast.taProvision": "TeamAuto: repo ready",
|
|
112
|
+
"toast.taTask": "TeamAuto: task queued",
|
|
113
|
+
"toast.taSweep": "TeamAuto: sweep finished",
|
|
114
|
+
"toast.taWriteback": "TeamAuto: write-back posted",
|
|
115
|
+
"toast.freqTaBind": "Rare - once per repo at bind time",
|
|
116
|
+
"toast.freqTaProvision": "Rare - once per repo after clone + norms",
|
|
117
|
+
"toast.freqTaTask": "Medium - each claimed issue/PR per sweep",
|
|
118
|
+
"toast.freqTaSweep": "Highest - every sweep cycle of every bound repo (cron)",
|
|
119
|
+
"toast.freqTaWriteback": "Medium - each comment/PR posted to GitHub",
|
|
120
|
+
"empty.noMessages": "No messages yet",
|
|
121
|
+
"empty.noPlanningSessions": "No planning sessions yet",
|
|
122
|
+
"empty.noKickoffData": "No kickoff data",
|
|
123
|
+
"empty.workspaceLoading": "Workspace tree loading…",
|
|
124
|
+
"empty.noWorkspaceFiles": "No project files in the workspace yet.",
|
|
125
|
+
"empty.selectFileSource": "Select a file from the workspace tree to view its source.",
|
|
126
|
+
"empty.selectFilePreview": "Select a file from the workspace tree to preview Markdown or HTML output.",
|
|
127
|
+
"empty.selectTask": "Select a task",
|
|
128
|
+
"empty.taskDetail": "Select a task to inspect its execution details.",
|
|
129
|
+
"empty.taskMessages": "No messages on this task yet.",
|
|
130
|
+
"empty.taskHistory": "No execution history recorded yet.",
|
|
131
|
+
"empty.copiedControllerReply": "Controller finished without a textual reply.",
|
|
132
|
+
"runtime.title": "TeamClaw is installed but cannot work yet.",
|
|
133
|
+
"runtime.noModel": "No TeamClaw model is configured for this instance.",
|
|
134
|
+
"runtime.noAuth": "No usable OpenClaw auth profile was found for TeamClaw.",
|
|
135
|
+
"gh.login": "Sign in with GitHub",
|
|
136
|
+
"teamauto.refreshRepos": "Refresh repos",
|
|
137
|
+
"teamauto.bind": "Bind",
|
|
138
|
+
"teamauto.bindStageVerify": "Verifying access",
|
|
139
|
+
"teamauto.bindStageClone": "Cloning repository",
|
|
140
|
+
"teamauto.bindStageNorms": "Learning repo conventions",
|
|
141
|
+
"teamauto.bindReady": "Repository ready",
|
|
142
|
+
"teamauto.bindFailed": "Binding failed",
|
|
143
|
+
"teamauto.close": "Close",
|
|
144
|
+
"teamauto.provisioning": "preparing",
|
|
145
|
+
"teamauto.provisionFailed": "setup failed",
|
|
146
|
+
"teamauto.hint": "Pick one of your GitHub repositories. TeamClaw sweeps it on its own schedule, reviews issues/PRs, takes ownership of unassigned issues, and posts results with teamclaw markers.",
|
|
147
|
+
"teamauto.scheduleHint": "Schedules: */N * * * * (every N min), M * * * * (hourly at :M), 0 */N * * * (every N h), M H * * * (daily at H:M), @hourly, @daily, @weekly, @monthly. Sweeps align to the clock and survive restarts.",
|
|
148
|
+
"teamauto.loginFirst": "Sign in to GitHub first (top-right Login).",
|
|
149
|
+
"teamauto.loadingRepos": "Loading your repos...",
|
|
150
|
+
"teamauto.noCandidates": "No selectable repos (check GitHub login). You can type owner/repo manually:",
|
|
151
|
+
"teamauto.needRepo": "Select a repository first",
|
|
152
|
+
"teamauto.active": "active",
|
|
153
|
+
"teamauto.disabled": "disabled",
|
|
154
|
+
"teamauto.paused": "paused",
|
|
155
|
+
"teamauto.sweep": "Sweep now",
|
|
156
|
+
"teamauto.disable": "Disable",
|
|
157
|
+
"teamauto.enable": "Enable",
|
|
158
|
+
"teamauto.unbind": "Unbind",
|
|
159
|
+
"teamauto.save": "Save config",
|
|
160
|
+
"teamauto.saved": "Saved",
|
|
161
|
+
"teamauto.schedule": "Schedule",
|
|
162
|
+
"teamauto.maxPerSweep": "Max/sweep",
|
|
163
|
+
"teamauto.fullReview": "Full review",
|
|
164
|
+
"teamauto.takeOwnership": "Take ownership",
|
|
165
|
+
"teamauto.lastSweep": "Last sweep",
|
|
166
|
+
"teamauto.norms": "Norms",
|
|
167
|
+
"teamauto.confirmUnbind": "Unbind this repo?",
|
|
168
|
+
"teamauto.empty": "No repos bound yet. Pick one above and click Bind.",
|
|
169
|
+
"teamauto.activity": "Activity",
|
|
170
|
+
"teamauto.activityEmpty": "No TeamAuto activity yet - sweeps and write-backs will appear here.",
|
|
171
|
+
"worker.add": "Add worker",
|
|
172
|
+
"worker.hide": "Hide worker command",
|
|
173
|
+
"worker.cardTitle": "Register a new external worker",
|
|
174
|
+
"worker.cardSubtitle": "Choose a role and discovery mode, then copy a one-line installer command for the target machine.",
|
|
175
|
+
"worker.role": "Role",
|
|
176
|
+
"worker.discovery": "Controller discovery",
|
|
177
|
+
"worker.discoveryMdns": "LAN auto-discovery (mDNS)",
|
|
178
|
+
"worker.discoveryManual": "Manual controller URL (LAN IP)",
|
|
179
|
+
"worker.recommendedUrl": "Recommended controller URL: ",
|
|
180
|
+
"filter.all": "All",
|
|
181
|
+
"filter.pending": "Pending",
|
|
182
|
+
"filter.assigned": "Assigned",
|
|
183
|
+
"filter.in_progress": "In Progress",
|
|
184
|
+
"filter.blocked": "Blocked",
|
|
185
|
+
"filter.completed": "Completed",
|
|
186
|
+
"filter.failed": "Failed",
|
|
187
|
+
"tasks.searchPlaceholder": "Filter by keyword...",
|
|
188
|
+
"tasks.showMore": "Show {n} more completed",
|
|
189
|
+
"tasks.noMatch": "No tasks match the keyword",
|
|
190
|
+
"priority.low": "Low",
|
|
191
|
+
"priority.medium": "Medium",
|
|
192
|
+
"priority.high": "High",
|
|
193
|
+
"priority.critical": "Critical",
|
|
194
|
+
"detail.kicker": "Task Details",
|
|
195
|
+
"live.idle": "Idle",
|
|
196
|
+
"clarification.kicker": "Clarification needed",
|
|
197
|
+
"clarification.title": "Human input required"
|
|
198
|
+
},
|
|
199
|
+
zh: {
|
|
200
|
+
"action.refresh": "刷新",
|
|
201
|
+
"action.close": "关闭",
|
|
202
|
+
"action.dismiss": "稍后处理",
|
|
203
|
+
"action.copyCommand": "复制命令",
|
|
204
|
+
"action.copied": "已复制",
|
|
205
|
+
"sidebar.workers": "成员",
|
|
206
|
+
"sidebar.roles": "角色",
|
|
207
|
+
"tab.planning": "规划",
|
|
208
|
+
"tab.tasks": "任务",
|
|
209
|
+
"tab.workspace": "工作区",
|
|
210
|
+
"tab.teamauto": "TeamAuto",
|
|
211
|
+
"tab.clarifications": "澄清",
|
|
212
|
+
"tab.messages": "消息",
|
|
213
|
+
"tab.manualTask": "手动任务",
|
|
214
|
+
"planning.title": "团队规划",
|
|
215
|
+
"planning.description": "通过下方命令栏提交需求。复杂项目(3 个及以上角色)会触发团队 kickoff 会议,由各角色协作评估需求。",
|
|
216
|
+
"planning.sessions": "会话",
|
|
217
|
+
"planning.requirement": "需求",
|
|
218
|
+
"planning.kickoff": "团队 Kickoff 会议",
|
|
219
|
+
"planning.controllerOutput": "Controller 输出",
|
|
220
|
+
"planning.originalRequest": "原始请求",
|
|
221
|
+
"planning.requiredRoles": "所需角色",
|
|
222
|
+
"planning.plannedTasks": "计划任务",
|
|
223
|
+
"planning.deferredTasks": "延后任务",
|
|
224
|
+
"planning.clarificationsNeeded": "待澄清问题",
|
|
225
|
+
"planning.notes": "备注",
|
|
226
|
+
"planning.noControllerOutput": "暂无 controller 输出。",
|
|
227
|
+
"workspace.preview": "预览",
|
|
228
|
+
"workspace.selectFile": "选择文件",
|
|
229
|
+
"workspace.openRaw": "打开原始文件",
|
|
230
|
+
"workspace.source": "源码",
|
|
231
|
+
"workspace.files": "文件",
|
|
232
|
+
"messages.panelNote": "这里会保留 controller 活动,方便你在 Web UI 中跟踪需求 intake、编排过程和后续跟进。",
|
|
233
|
+
"manualTask.note": "原始人工需求应先发送到 controller 对话。这个表单仅用于明确的手动任务注入或测试。",
|
|
234
|
+
"manualTask.title": "标题",
|
|
235
|
+
"manualTask.description": "描述",
|
|
236
|
+
"manualTask.skills": "推荐技能",
|
|
237
|
+
"manualTask.priority": "优先级",
|
|
238
|
+
"manualTask.assignedRole": "指定角色",
|
|
239
|
+
"manualTask.autoAssign": "自动分配",
|
|
240
|
+
"manualTask.create": "创建手动任务",
|
|
241
|
+
"manualTask.titlePlaceholder": "任务标题...",
|
|
242
|
+
"manualTask.descriptionPlaceholder": "可直接执行的任务描述...",
|
|
243
|
+
"manualTask.skillsPlaceholder": "逗号分隔的 skill slug,例如 find-skills, ui-ux-pro-max",
|
|
244
|
+
"empty.noWorkers": "暂无已连接成员",
|
|
245
|
+
"empty.noTasks": "暂无任务",
|
|
246
|
+
"empty.noTasksWithStatus": "没有状态为“{status}”的任务",
|
|
247
|
+
"empty.noClarifications": "暂无澄清请求",
|
|
248
|
+
"empty.noControllerActivity": "暂无 controller 活动",
|
|
249
|
+
"toast.taskCompleted": "任务完成",
|
|
250
|
+
"toast.taskFailed": "任务失败",
|
|
251
|
+
"toast.clarificationRequested": "需要澄清",
|
|
252
|
+
"toast.clarificationAnswered": "澄清已回答",
|
|
253
|
+
"toast.teamautoPrefix": "TeamAuto",
|
|
254
|
+
"toast.workerOnline": "Worker 上线",
|
|
255
|
+
"toast.workerOffline": "Worker 下线",
|
|
256
|
+
"toast.taskCreated": "任务已创建",
|
|
257
|
+
"toast.taskUpdated": "任务更新",
|
|
258
|
+
"toast.messageNew": "新消息",
|
|
259
|
+
"toast.settingsTitle": "Toast 通知管理",
|
|
260
|
+
"toast.enableAll": "全部启用",
|
|
261
|
+
"toast.disableAll": "全部关闭",
|
|
262
|
+
"toast.freqTaskCompleted": "低 - 每任务一次",
|
|
263
|
+
"toast.freqTaskCreated": "中 - 每阶段一次",
|
|
264
|
+
"toast.freqTaskUpdated": "高 - 每任务生命周期多次",
|
|
265
|
+
"toast.freqClarification": "很少 - 仅当 worker 需要人来决策时",
|
|
266
|
+
"toast.freqWorker": "视拓扑而定 - 外部 worker 很少;按需供给 worker 可能每任务上下线一次(空闲 120 秒回收)",
|
|
267
|
+
"toast.freqTeamauto": "低 - 每次扫描/认领/回写",
|
|
268
|
+
"toast.freqMessageNew": "高 - 每条 controller 消息",
|
|
269
|
+
"toast.taBind": "TeamAuto:仓库已绑定",
|
|
270
|
+
"toast.taProvision": "TeamAuto:仓库就绪",
|
|
271
|
+
"toast.taTask": "TeamAuto:任务入队",
|
|
272
|
+
"toast.taSweep": "TeamAuto:扫描完成",
|
|
273
|
+
"toast.taWriteback": "TeamAuto:已回写",
|
|
274
|
+
"toast.freqTaBind": "很少 - 每仓库绑定一次",
|
|
275
|
+
"toast.freqTaProvision": "很少 - 每仓库克隆学习完成后一次",
|
|
276
|
+
"toast.freqTaTask": "中 - 每次扫描认领的 issue/PR",
|
|
277
|
+
"toast.freqTaSweep": "最高 - 每个绑定仓库每个周期都触发(cron)",
|
|
278
|
+
"toast.freqTaWriteback": "中 - 每次向 GitHub 发评论/PR",
|
|
279
|
+
"empty.noMessages": "暂无消息",
|
|
280
|
+
"empty.noPlanningSessions": "暂无规划会话",
|
|
281
|
+
"empty.noKickoffData": "暂无 kickoff 数据",
|
|
282
|
+
"empty.workspaceLoading": "工作区树加载中…",
|
|
283
|
+
"empty.noWorkspaceFiles": "工作区中还没有项目文件。",
|
|
284
|
+
"empty.selectFileSource": "从工作区文件树选择文件以查看源码。",
|
|
285
|
+
"empty.selectFilePreview": "从工作区文件树选择文件以预览 Markdown 或 HTML 输出。",
|
|
286
|
+
"empty.selectTask": "选择一个任务",
|
|
287
|
+
"empty.taskDetail": "选择一个任务以查看执行细节。",
|
|
288
|
+
"empty.taskMessages": "该任务暂无消息。",
|
|
289
|
+
"empty.taskHistory": "暂无执行历史。",
|
|
290
|
+
"empty.copiedControllerReply": "Controller 已完成,但没有文本回复。",
|
|
291
|
+
"runtime.title": "TeamClaw 已安装,但当前还无法工作。",
|
|
292
|
+
"runtime.noModel": "当前实例还没有为 TeamClaw 配置模型。",
|
|
293
|
+
"runtime.noAuth": "未找到 TeamClaw 可用的 OpenClaw 认证配置。",
|
|
294
|
+
"gh.login": "使用 GitHub 登录",
|
|
295
|
+
"teamauto.refreshRepos": "刷新仓库",
|
|
296
|
+
"teamauto.bind": "绑定",
|
|
297
|
+
"teamauto.bindStageVerify": "验证访问权限",
|
|
298
|
+
"teamauto.bindStageClone": "克隆仓库中",
|
|
299
|
+
"teamauto.bindStageNorms": "学习仓库规范",
|
|
300
|
+
"teamauto.bindReady": "仓库就绪",
|
|
301
|
+
"teamauto.bindFailed": "绑定失败",
|
|
302
|
+
"teamauto.close": "关闭",
|
|
303
|
+
"teamauto.provisioning": "准备中",
|
|
304
|
+
"teamauto.provisionFailed": "准备失败",
|
|
305
|
+
"teamauto.hint": "选择你的 GitHub 仓库。TeamClaw 按各自节奏定时扫描,自主 review issue/PR、认领未分配 issue,并以 teamclaw 标识写回结果。",
|
|
306
|
+
"teamauto.scheduleHint": "支持的表达式:*/N * * * *(每 N 分钟)、M * * * *(每小时第 M 分)、0 */N * * *(每 N 小时)、M H * * *(每天 H:M)、@hourly、@daily、@weekly、@monthly。扫描按墙钟对齐,重启后自动恢复。",
|
|
307
|
+
"teamauto.loginFirst": "请先登录 GitHub(右上角 Login)。",
|
|
308
|
+
"teamauto.loadingRepos": "正在加载你的仓库...",
|
|
309
|
+
"teamauto.noCandidates": "无可选仓库(请检查 GitHub 登录),可手动输入 owner/repo:",
|
|
310
|
+
"teamauto.needRepo": "请先选择一个仓库",
|
|
311
|
+
"teamauto.active": "运行中",
|
|
312
|
+
"teamauto.disabled": "已停用",
|
|
313
|
+
"teamauto.paused": "已暂停",
|
|
314
|
+
"teamauto.sweep": "立即扫描",
|
|
315
|
+
"teamauto.disable": "停用",
|
|
316
|
+
"teamauto.enable": "启用",
|
|
317
|
+
"teamauto.unbind": "解绑",
|
|
318
|
+
"teamauto.save": "保存配置",
|
|
319
|
+
"teamauto.saved": "已保存",
|
|
320
|
+
"teamauto.schedule": "节奏",
|
|
321
|
+
"teamauto.maxPerSweep": "每轮上限",
|
|
322
|
+
"teamauto.fullReview": "全量 review",
|
|
323
|
+
"teamauto.takeOwnership": "认领 issue",
|
|
324
|
+
"teamauto.lastSweep": "上次扫描",
|
|
325
|
+
"teamauto.norms": "协作规范",
|
|
326
|
+
"teamauto.confirmUnbind": "确定解绑该仓库?",
|
|
327
|
+
"teamauto.empty": "尚未绑定仓库。在上方选择后点击绑定。",
|
|
328
|
+
"teamauto.activity": "动态",
|
|
329
|
+
"teamauto.activityEmpty": "暂无 TeamAuto 动态-扫描与写回会出现在这里。",
|
|
330
|
+
"worker.add": "添加 worker",
|
|
331
|
+
"worker.hide": "隐藏 worker 命令",
|
|
332
|
+
"worker.cardTitle": "注册新的外部 worker",
|
|
333
|
+
"worker.cardSubtitle": "选择角色和发现方式,然后复制目标机器可直接执行的一行安装命令。",
|
|
334
|
+
"worker.role": "角色",
|
|
335
|
+
"worker.discovery": "Controller 发现方式",
|
|
336
|
+
"worker.discoveryMdns": "局域网自动发现(mDNS)",
|
|
337
|
+
"worker.discoveryManual": "手动填写 controller 地址(局域网 IP)",
|
|
338
|
+
"worker.recommendedUrl": "推荐的 controller 地址:",
|
|
339
|
+
"filter.all": "全部",
|
|
340
|
+
"filter.pending": "待处理",
|
|
341
|
+
"filter.assigned": "已分配",
|
|
342
|
+
"filter.in_progress": "进行中",
|
|
343
|
+
"filter.blocked": "阻塞",
|
|
344
|
+
"filter.completed": "已完成",
|
|
345
|
+
"filter.failed": "失败",
|
|
346
|
+
"tasks.searchPlaceholder": "关键字过滤...",
|
|
347
|
+
"tasks.showMore": "再显示 {n} 条已结束",
|
|
348
|
+
"tasks.noMatch": "没有匹配关键字的任务",
|
|
349
|
+
"priority.low": "低",
|
|
350
|
+
"priority.medium": "中",
|
|
351
|
+
"priority.high": "高",
|
|
352
|
+
"priority.critical": "紧急",
|
|
353
|
+
"detail.kicker": "任务详情",
|
|
354
|
+
"live.idle": "空闲",
|
|
355
|
+
"clarification.kicker": "需要澄清",
|
|
356
|
+
"clarification.title": "需要人工输入"
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
function $(selector) { return document.querySelector(selector); }
|
|
361
|
+
function $$(selector) { return document.querySelectorAll(selector); }
|
|
362
|
+
|
|
363
|
+
function loadLanguage() {
|
|
364
|
+
try {
|
|
365
|
+
var stored = window.localStorage.getItem(LANGUAGE_STORAGE_KEY);
|
|
366
|
+
return stored === "zh" ? "zh" : "en";
|
|
367
|
+
} catch (_err) {
|
|
368
|
+
return "en";
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function t(key, params) {
|
|
373
|
+
var template = (TRANSLATIONS[currentLanguage] && TRANSLATIONS[currentLanguage][key]) || TRANSLATIONS.en[key] || key;
|
|
374
|
+
return template.replace(/\{(\w+)\}/g, function (_match, name) {
|
|
375
|
+
return params && params[name] != null ? String(params[name]) : "";
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function setLanguage(language) {
|
|
380
|
+
currentLanguage = language === "zh" ? "zh" : "en";
|
|
381
|
+
try {
|
|
382
|
+
window.localStorage.setItem(LANGUAGE_STORAGE_KEY, currentLanguage);
|
|
383
|
+
} catch (_err) {}
|
|
384
|
+
document.documentElement.lang = currentLanguage === "zh" ? "zh-CN" : "en";
|
|
385
|
+
applyStaticTranslations();
|
|
386
|
+
refreshAll();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function applyStaticTranslations() {
|
|
390
|
+
$$("[data-i18n]").forEach(function (element) {
|
|
391
|
+
var key = element.getAttribute("data-i18n");
|
|
392
|
+
if (key) {
|
|
393
|
+
element.textContent = t(key);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
$$("[data-i18n-placeholder]").forEach(function (element) {
|
|
397
|
+
var key = element.getAttribute("data-i18n-placeholder");
|
|
398
|
+
if (key) {
|
|
399
|
+
element.setAttribute("placeholder", t(key));
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
var languageToggle = $("#language-toggle");
|
|
403
|
+
if (languageToggle) {
|
|
404
|
+
languageToggle.textContent = currentLanguage === "zh" ? "English" : "中文";
|
|
405
|
+
}
|
|
406
|
+
var filters = {
|
|
407
|
+
all: "filter.all",
|
|
408
|
+
pending: "filter.pending",
|
|
409
|
+
assigned: "filter.assigned",
|
|
410
|
+
in_progress: "filter.in_progress",
|
|
411
|
+
blocked: "filter.blocked",
|
|
412
|
+
completed: "filter.completed",
|
|
413
|
+
failed: "filter.failed"
|
|
414
|
+
};
|
|
415
|
+
$$("[data-filter]").forEach(function (button) {
|
|
416
|
+
var key = filters[button.getAttribute("data-filter") || "all"];
|
|
417
|
+
if (key) button.textContent = t(key);
|
|
418
|
+
});
|
|
419
|
+
["low", "medium", "high", "critical"].forEach(function (priority) {
|
|
420
|
+
var option = $('#task-priority option[value="' + priority + '"]');
|
|
421
|
+
if (option) option.textContent = t("priority." + priority);
|
|
422
|
+
});
|
|
423
|
+
var planningHeader = $(".planning-sessions-header");
|
|
424
|
+
if (planningHeader) planningHeader.textContent = t("planning.sessions");
|
|
425
|
+
var workspaceKicker = $(".workspace-sidebar-panel .workspace-panel-kicker");
|
|
426
|
+
if (workspaceKicker) workspaceKicker.textContent = t("tab.workspace");
|
|
427
|
+
var workspaceTitle = $(".workspace-sidebar-panel h3");
|
|
428
|
+
if (workspaceTitle) workspaceTitle.textContent = t("workspace.files");
|
|
429
|
+
var planningPaneTitles = $$(".planning-pane-title");
|
|
430
|
+
if (planningPaneTitles[0]) planningPaneTitles[0].textContent = t("planning.requirement");
|
|
431
|
+
if (planningPaneTitles[1]) planningPaneTitles[1].textContent = t("planning.kickoff");
|
|
432
|
+
var promptKicker = $(".clarification-prompt-kicker");
|
|
433
|
+
if (promptKicker) promptKicker.textContent = t("clarification.kicker");
|
|
434
|
+
var promptTitle = $("#clarification-prompt-title");
|
|
435
|
+
if (promptTitle) promptTitle.textContent = t("clarification.title");
|
|
436
|
+
var promptClose = $("#clarification-prompt-close");
|
|
437
|
+
if (promptClose) promptClose.textContent = t("action.dismiss");
|
|
438
|
+
var detailKicker = $(".task-detail-kicker");
|
|
439
|
+
if (detailKicker) detailKicker.textContent = t("detail.kicker");
|
|
440
|
+
var detailClose = $("#task-detail-close");
|
|
441
|
+
if (detailClose) detailClose.textContent = t("action.close");
|
|
442
|
+
var detailRefresh = $("#task-detail-refresh");
|
|
443
|
+
if (detailRefresh) detailRefresh.textContent = t("action.refresh");
|
|
444
|
+
var liveBadge = $("#task-detail-live-badge");
|
|
445
|
+
if (liveBadge && liveBadge.textContent === "Idle") liveBadge.textContent = t("live.idle");
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function parseInitialUiState() {
|
|
449
|
+
try {
|
|
450
|
+
const params = new URLSearchParams(window.location.search || "");
|
|
451
|
+
// Hash routing (#/tab/<name>) wins over legacy query params and survives
|
|
452
|
+
// refresh; query params are kept for old bookmarks/links.
|
|
453
|
+
const hashMatch = /^#\/tab\/([a-z][a-z0-9-]*)$/i.exec(window.location.hash || "");
|
|
454
|
+
return {
|
|
455
|
+
tab: hashMatch ? hashMatch[1] : (params.get("tab") || ""),
|
|
456
|
+
taskId: params.get("taskId") || "",
|
|
457
|
+
planningRun: params.get("planningRun") || "",
|
|
458
|
+
};
|
|
459
|
+
} catch (_err) {
|
|
460
|
+
return { tab: "", taskId: "", planningRun: "" };
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function getSessionStorage() {
|
|
465
|
+
try {
|
|
466
|
+
return window.sessionStorage;
|
|
467
|
+
} catch (_err) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function loadControllerConversation() {
|
|
473
|
+
const storage = getSessionStorage();
|
|
474
|
+
if (!storage) return [];
|
|
475
|
+
try {
|
|
476
|
+
const raw = storage.getItem(CONTROLLER_CONVERSATION_STORAGE_KEY);
|
|
477
|
+
const parsed = raw ? JSON.parse(raw) : [];
|
|
478
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
479
|
+
} catch (_err) {
|
|
480
|
+
return [];
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function saveControllerConversation() {
|
|
485
|
+
const storage = getSessionStorage();
|
|
486
|
+
if (!storage) return;
|
|
487
|
+
storage.setItem(CONTROLLER_CONVERSATION_STORAGE_KEY, JSON.stringify(controllerConversation.slice(-50)));
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function getControllerSessionKey() {
|
|
491
|
+
const storage = getSessionStorage();
|
|
492
|
+
const fallback = "default";
|
|
493
|
+
if (!storage) return fallback;
|
|
494
|
+
let sessionKey = storage.getItem(CONTROLLER_SESSION_STORAGE_KEY);
|
|
495
|
+
if (!sessionKey) {
|
|
496
|
+
sessionKey = (window.crypto && typeof window.crypto.randomUUID === "function")
|
|
497
|
+
? window.crypto.randomUUID()
|
|
498
|
+
: ("web-" + Date.now());
|
|
499
|
+
storage.setItem(CONTROLLER_SESSION_STORAGE_KEY, sessionKey);
|
|
500
|
+
}
|
|
501
|
+
return sessionKey;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function createControllerConversationEntry(entry) {
|
|
505
|
+
return Object.assign({
|
|
506
|
+
id: "controller-ui-" + Date.now() + "-" + Math.random().toString(36).slice(2, 8),
|
|
507
|
+
createdAt: Date.now(),
|
|
508
|
+
}, entry);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function appendControllerConversation(entry) {
|
|
512
|
+
controllerConversation = controllerConversation.concat([createControllerConversationEntry(entry)]).slice(-50);
|
|
513
|
+
saveControllerConversation();
|
|
514
|
+
renderMessages(teamState.messages || []);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function escapeHtml(str) {
|
|
518
|
+
const div = document.createElement("div");
|
|
519
|
+
div.textContent = str == null ? "" : String(str);
|
|
520
|
+
return div.innerHTML;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
async function copyText(text) {
|
|
524
|
+
if (!text) return;
|
|
525
|
+
if (navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
526
|
+
await navigator.clipboard.writeText(text);
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
var textarea = document.createElement("textarea");
|
|
530
|
+
textarea.value = text;
|
|
531
|
+
textarea.setAttribute("readonly", "readonly");
|
|
532
|
+
textarea.style.position = "absolute";
|
|
533
|
+
textarea.style.left = "-9999px";
|
|
534
|
+
document.body.appendChild(textarea);
|
|
535
|
+
textarea.select();
|
|
536
|
+
document.execCommand("copy");
|
|
537
|
+
document.body.removeChild(textarea);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
function formatTime(ts) {
|
|
541
|
+
if (!ts) return "";
|
|
542
|
+
const d = new Date(ts);
|
|
543
|
+
const h = String(d.getHours()).padStart(2, "0");
|
|
544
|
+
const m = String(d.getMinutes()).padStart(2, "0");
|
|
545
|
+
const s = String(d.getSeconds()).padStart(2, "0");
|
|
546
|
+
return h + ":" + m + ":" + s;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
function humanizeStatus(value) {
|
|
550
|
+
return String(value || "").replace(/_/g, " ").replace(/-/g, " ");
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function normalizeArray(value) {
|
|
554
|
+
return Array.isArray(value) ? value : [];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function sortClarifications(items) {
|
|
558
|
+
return normalizeArray(items).slice().sort(function (left, right) {
|
|
559
|
+
return (right.updatedAt || right.createdAt || 0) - (left.updatedAt || left.createdAt || 0);
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
function pendingClarifications() {
|
|
564
|
+
return sortClarifications(teamState.clarifications).filter(function (item) {
|
|
565
|
+
return !item.answer && (item.status || "pending") === "pending";
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function isTerminalPlanningStatus(status) {
|
|
570
|
+
return ["completed", "failed", "cancelled"].indexOf(String(status || "").toLowerCase()) !== -1;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function activePlanningRunCount() {
|
|
574
|
+
return normalizeArray(teamState.controllerRuns).filter(function (run) {
|
|
575
|
+
return run.manifest && run.manifest.kickoffPlan && !isTerminalPlanningStatus(run.status);
|
|
576
|
+
}).length;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function activeTaskCount() {
|
|
580
|
+
return normalizeArray(teamState.tasks).filter(function (task) {
|
|
581
|
+
return ["assigned", "in_progress", "review"].indexOf(task.status) !== -1;
|
|
582
|
+
}).length;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function blockedTaskCount() {
|
|
586
|
+
return normalizeArray(teamState.tasks).filter(function (task) {
|
|
587
|
+
return task.status === "blocked";
|
|
588
|
+
}).length;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function isNearBottom(element) {
|
|
592
|
+
if (!element) return true;
|
|
593
|
+
return (element.scrollHeight - element.scrollTop - element.clientHeight) < 48;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
function formatBytes(value) {
|
|
597
|
+
const bytes = Number(value || 0);
|
|
598
|
+
if (!bytes) return "0 B";
|
|
599
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
600
|
+
let size = bytes;
|
|
601
|
+
let unitIndex = 0;
|
|
602
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
603
|
+
size /= 1024;
|
|
604
|
+
unitIndex += 1;
|
|
605
|
+
}
|
|
606
|
+
const digits = size >= 10 || unitIndex === 0 ? 0 : 1;
|
|
607
|
+
return size.toFixed(digits) + " " + units[unitIndex];
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function isWorkspacePreviewAvailable(file) {
|
|
611
|
+
return !!file && (file.previewType === "markdown" || file.previewType === "html");
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function sanitizeUrl(url) {
|
|
615
|
+
const value = String(url || "").trim();
|
|
616
|
+
if (!value) return "#";
|
|
617
|
+
if (/^(https?:|mailto:)/i.test(value)) {
|
|
618
|
+
return value;
|
|
619
|
+
}
|
|
620
|
+
if (value.startsWith("/") || value.startsWith("./") || value.startsWith("../") || !value.includes(":")) {
|
|
621
|
+
return value;
|
|
622
|
+
}
|
|
623
|
+
return "#";
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function normalizeSkillList(skills) {
|
|
627
|
+
if (!Array.isArray(skills)) {
|
|
628
|
+
return [];
|
|
629
|
+
}
|
|
630
|
+
return skills
|
|
631
|
+
.map(function (skill) { return String(skill || "").trim(); })
|
|
632
|
+
.filter(Boolean);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
function renderSkillPills(skills, className) {
|
|
636
|
+
const items = normalizeSkillList(skills);
|
|
637
|
+
if (items.length === 0) {
|
|
638
|
+
return "";
|
|
639
|
+
}
|
|
640
|
+
return '<div class="' + escapeHtml(className || "skill-pills") + '">' + items.map(function (skill) {
|
|
641
|
+
return '<span class="skill-pill">' + escapeHtml(skill) + "</span>";
|
|
642
|
+
}).join("") + "</div>";
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
function renderMarkdownInline(text) {
|
|
646
|
+
const codeTokens = [];
|
|
647
|
+
let safe = escapeHtml(text || "");
|
|
648
|
+
safe = safe.replace(/`([^`]+)`/g, function (_match, code) {
|
|
649
|
+
const token = "@@CODE-TOKEN-" + codeTokens.length + "@@";
|
|
650
|
+
codeTokens.push("<code>" + escapeHtml(code) + "</code>");
|
|
651
|
+
return token;
|
|
652
|
+
});
|
|
653
|
+
safe = safe.replace(/\[([^\]]+)\]\(([^)]+)\)/g, function (_match, label, url) {
|
|
654
|
+
return '<a href="' + escapeHtml(sanitizeUrl(url)) + '" target="_blank" rel="noreferrer">' + escapeHtml(label) + "</a>";
|
|
655
|
+
});
|
|
656
|
+
safe = safe.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
|
657
|
+
safe = safe.replace(/__([^_]+)__/g, "<strong>$1</strong>");
|
|
658
|
+
safe = safe.replace(/\*([^*]+)\*/g, "<em>$1</em>");
|
|
659
|
+
safe = safe.replace(/_([^_]+)_/g, "<em>$1</em>");
|
|
660
|
+
codeTokens.forEach(function (tokenValue, index) {
|
|
661
|
+
safe = safe.replace("@@CODE-TOKEN-" + index + "@@", tokenValue);
|
|
662
|
+
});
|
|
663
|
+
return safe;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function parseMarkdownTableRow(line) {
|
|
667
|
+
const trimmed = String(line || "").trim().replace(/^\|/, "").replace(/\|$/, "");
|
|
668
|
+
return trimmed.split("|").map(function (cell) {
|
|
669
|
+
return renderMarkdownInline(cell.trim());
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
function renderMarkdown(markdown) {
|
|
674
|
+
const codeBlocks = [];
|
|
675
|
+
const lines = String(markdown || "")
|
|
676
|
+
.replace(/\r\n?/g, "\n")
|
|
677
|
+
.replace(/```([\w-]*)\n([\s\S]*?)```/g, function (_match, language, code) {
|
|
678
|
+
const token = "@@FENCE-BLOCK-" + codeBlocks.length + "@@";
|
|
679
|
+
codeBlocks.push(
|
|
680
|
+
'<pre><code data-language="' + escapeHtml(language || "") + '">' + escapeHtml(code.replace(/\n$/, "")) + "</code></pre>"
|
|
681
|
+
);
|
|
682
|
+
return token;
|
|
683
|
+
})
|
|
684
|
+
.split("\n");
|
|
685
|
+
const html = [];
|
|
686
|
+
let index = 0;
|
|
687
|
+
|
|
688
|
+
while (index < lines.length) {
|
|
689
|
+
const rawLine = lines[index] || "";
|
|
690
|
+
const line = rawLine.trim();
|
|
691
|
+
|
|
692
|
+
if (!line) {
|
|
693
|
+
index += 1;
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
if (/^@@FENCE-BLOCK-\d+@@$/.test(line)) {
|
|
698
|
+
const blockIndex = Number(line.replace(/\D/g, ""));
|
|
699
|
+
html.push(codeBlocks[blockIndex] || "");
|
|
700
|
+
index += 1;
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (/^#{1,6}\s+/.test(line)) {
|
|
705
|
+
const level = Math.min(6, line.match(/^#+/)[0].length);
|
|
706
|
+
html.push("<h" + level + ">" + renderMarkdownInline(line.slice(level).trim()) + "</h" + level + ">");
|
|
707
|
+
index += 1;
|
|
708
|
+
continue;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (/^>\s?/.test(line)) {
|
|
712
|
+
const quoteLines = [];
|
|
713
|
+
while (index < lines.length && /^>\s?/.test((lines[index] || "").trim())) {
|
|
714
|
+
quoteLines.push(renderMarkdownInline((lines[index] || "").trim().replace(/^>\s?/, "")));
|
|
715
|
+
index += 1;
|
|
716
|
+
}
|
|
717
|
+
html.push("<blockquote><p>" + quoteLines.join("<br>") + "</p></blockquote>");
|
|
718
|
+
continue;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
if (/^[-*_]{3,}$/.test(line)) {
|
|
722
|
+
html.push("<hr>");
|
|
723
|
+
index += 1;
|
|
724
|
+
continue;
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
if (line.includes("|") && index + 1 < lines.length && /^\s*\|?[\s:-]+\|[\s|:-]*$/.test(lines[index + 1] || "")) {
|
|
728
|
+
const headers = parseMarkdownTableRow(line);
|
|
729
|
+
const rows = [];
|
|
730
|
+
index += 2;
|
|
731
|
+
while (index < lines.length && (lines[index] || "").includes("|")) {
|
|
732
|
+
rows.push(parseMarkdownTableRow(lines[index]));
|
|
733
|
+
index += 1;
|
|
734
|
+
}
|
|
735
|
+
html.push(
|
|
736
|
+
"<table><thead><tr>" + headers.map(function (cell) { return "<th>" + cell + "</th>"; }).join("") + "</tr></thead>" +
|
|
737
|
+
"<tbody>" + rows.map(function (row) {
|
|
738
|
+
return "<tr>" + row.map(function (cell) { return "<td>" + cell + "</td>"; }).join("") + "</tr>";
|
|
739
|
+
}).join("") + "</tbody></table>"
|
|
740
|
+
);
|
|
741
|
+
continue;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (/^([-*+]\s+|\d+\.\s+)/.test(line)) {
|
|
745
|
+
const ordered = /^\d+\.\s+/.test(line);
|
|
746
|
+
const items = [];
|
|
747
|
+
while (index < lines.length) {
|
|
748
|
+
const current = (lines[index] || "").trim();
|
|
749
|
+
const matchesList = ordered ? /^\d+\.\s+/.test(current) : /^[-*+]\s+/.test(current);
|
|
750
|
+
if (!matchesList) {
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
items.push(renderMarkdownInline(current.replace(/^([-*+]\s+|\d+\.\s+)/, "")));
|
|
754
|
+
index += 1;
|
|
755
|
+
}
|
|
756
|
+
html.push((ordered ? "<ol>" : "<ul>") + items.map(function (item) {
|
|
757
|
+
return "<li>" + item + "</li>";
|
|
758
|
+
}).join("") + (ordered ? "</ol>" : "</ul>"));
|
|
759
|
+
continue;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
const paragraphLines = [];
|
|
763
|
+
while (index < lines.length) {
|
|
764
|
+
const currentLine = lines[index] || "";
|
|
765
|
+
const current = currentLine.trim();
|
|
766
|
+
if (!current ||
|
|
767
|
+
/^@@FENCE-BLOCK-\d+@@$/.test(current) ||
|
|
768
|
+
/^#{1,6}\s+/.test(current) ||
|
|
769
|
+
/^>\s?/.test(current) ||
|
|
770
|
+
/^[-*_]{3,}$/.test(current) ||
|
|
771
|
+
/^([-*+]\s+|\d+\.\s+)/.test(current) ||
|
|
772
|
+
(current.includes("|") && index + 1 < lines.length && /^\s*\|?[\s:-]+\|[\s|:-]*$/.test(lines[index + 1] || ""))) {
|
|
773
|
+
break;
|
|
774
|
+
}
|
|
775
|
+
paragraphLines.push(renderMarkdownInline(current));
|
|
776
|
+
index += 1;
|
|
777
|
+
}
|
|
778
|
+
html.push("<p>" + paragraphLines.join(" ") + "</p>");
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return html.join("");
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function renderMarkdownContent(content) {
|
|
785
|
+
return renderMarkdown(String(content || ""));
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function renderMarkdownCard(content) {
|
|
789
|
+
return '<div class="task-detail-card markdown-body">' + renderMarkdownContent(content) + "</div>";
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function normalizeTextValue(value) {
|
|
793
|
+
return String(value == null ? "" : value).replace(/\s+/g, " ").trim();
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
function renderContractChips(items, className) {
|
|
797
|
+
const normalized = Array.isArray(items)
|
|
798
|
+
? items.map(function (item) { return normalizeTextValue(item); }).filter(Boolean)
|
|
799
|
+
: [];
|
|
800
|
+
if (normalized.length === 0) {
|
|
801
|
+
return "";
|
|
802
|
+
}
|
|
803
|
+
return '<div class="' + escapeHtml(className || "contract-chip-row") + '">' + normalized.map(function (item) {
|
|
804
|
+
return '<span class="contract-chip">' + escapeHtml(item) + "</span>";
|
|
805
|
+
}).join("") + "</div>";
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function renderContractList(items, formatter, className) {
|
|
809
|
+
const values = Array.isArray(items) ? items.filter(Boolean) : [];
|
|
810
|
+
if (values.length === 0) {
|
|
811
|
+
return "";
|
|
812
|
+
}
|
|
813
|
+
return '<ul class="' + escapeHtml(className || "contract-list") + '">' + values.map(function (item) {
|
|
814
|
+
return "<li>" + formatter(item) + "</li>";
|
|
815
|
+
}).join("") + "</ul>";
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function renderContractMetaRows(rows) {
|
|
819
|
+
const items = (rows || []).filter(function (row) {
|
|
820
|
+
return row && normalizeTextValue(row.label) && normalizeTextValue(row.value);
|
|
821
|
+
});
|
|
822
|
+
if (items.length === 0) {
|
|
823
|
+
return "";
|
|
824
|
+
}
|
|
825
|
+
return '<div class="contract-meta-grid">' + items.map(function (row) {
|
|
826
|
+
return (
|
|
827
|
+
'<div class="contract-meta-item">' +
|
|
828
|
+
' <div class="contract-meta-label">' + escapeHtml(row.label) + "</div>" +
|
|
829
|
+
' <div class="contract-meta-value">' + escapeHtml(row.value) + "</div>" +
|
|
830
|
+
"</div>"
|
|
831
|
+
);
|
|
832
|
+
}).join("") + "</div>";
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function renderContractSection(title, bodyHtml) {
|
|
836
|
+
if (!normalizeTextValue(bodyHtml)) {
|
|
837
|
+
return "";
|
|
838
|
+
}
|
|
839
|
+
return (
|
|
840
|
+
'<div class="contract-section">' +
|
|
841
|
+
' <div class="contract-section-title">' + escapeHtml(title) + "</div>" +
|
|
842
|
+
bodyHtml +
|
|
843
|
+
"</div>"
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function renderContractMarkdownBody(content) {
|
|
848
|
+
if (!normalizeTextValue(content)) {
|
|
849
|
+
return "";
|
|
850
|
+
}
|
|
851
|
+
return '<div class="contract-markdown markdown-body">' + renderMarkdownContent(content) + "</div>";
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
function renderContractCard(options) {
|
|
855
|
+
const tone = options && options.tone ? " contract-card-" + options.tone : "";
|
|
856
|
+
const kicker = options && options.kicker ? '<div class="contract-card-kicker">' + escapeHtml(options.kicker) + "</div>" : "";
|
|
857
|
+
const title = options && options.title ? '<h4 class="contract-card-title">' + escapeHtml(options.title) + "</h4>" : "";
|
|
858
|
+
const meta = options && options.metaHtml ? options.metaHtml : "";
|
|
859
|
+
const sections = Array.isArray(options && options.sections)
|
|
860
|
+
? options.sections.filter(function (section) { return normalizeTextValue(section); }).join("")
|
|
861
|
+
: "";
|
|
862
|
+
const footer = options && options.footerHtml ? options.footerHtml : "";
|
|
863
|
+
|
|
864
|
+
if (!kicker && !title && !meta && !sections && !footer) {
|
|
865
|
+
return "";
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return (
|
|
869
|
+
'<div class="contract-card' + tone + '">' +
|
|
870
|
+
' <div class="contract-card-header">' +
|
|
871
|
+
kicker +
|
|
872
|
+
title +
|
|
873
|
+
meta +
|
|
874
|
+
" </div>" +
|
|
875
|
+
sections +
|
|
876
|
+
footer +
|
|
877
|
+
"</div>"
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function renderResultContractCard(contract) {
|
|
882
|
+
if (!contract || !normalizeTextValue(contract.summary)) {
|
|
883
|
+
return "";
|
|
884
|
+
}
|
|
885
|
+
const deliverables = Array.isArray(contract.deliverables) ? contract.deliverables : [];
|
|
886
|
+
const followUps = Array.isArray(contract.followUps) ? contract.followUps : [];
|
|
887
|
+
return renderContractCard({
|
|
888
|
+
tone: contract.outcome || "completed",
|
|
889
|
+
kicker: "Structured Result Contract",
|
|
890
|
+
title: contract.summary,
|
|
891
|
+
metaHtml: renderContractMetaRows([
|
|
892
|
+
{ label: "Outcome", value: humanizeStatus(contract.outcome || "completed") },
|
|
893
|
+
{ label: "Deliverables", value: String(deliverables.length) },
|
|
894
|
+
{ label: "Follow-ups", value: String(followUps.length) },
|
|
895
|
+
]),
|
|
896
|
+
sections: [
|
|
897
|
+
renderContractSection("Deliverables", renderContractList(deliverables, function (item) {
|
|
898
|
+
const prefix = escapeHtml(item.kind || "artifact") + ": " + escapeHtml(item.value || "");
|
|
899
|
+
var liveLink = "";
|
|
900
|
+
if (item.artifactType === "web-app" && item.liveUrl) {
|
|
901
|
+
liveLink = ' <a class="deliverable-live-link" href="' + escapeHtml(item.liveUrl) + '" target="_blank" rel="noopener">Live Preview</a>';
|
|
902
|
+
}
|
|
903
|
+
return prefix + (item.summary ? ' <span class="contract-inline-note">— ' + escapeHtml(item.summary) + "</span>" : "") + liveLink;
|
|
904
|
+
})),
|
|
905
|
+
renderContractSection("Key Points", renderContractList(contract.keyPoints, function (item) {
|
|
906
|
+
return renderMarkdownInline(item);
|
|
907
|
+
})),
|
|
908
|
+
renderContractSection("Blockers", renderContractList(contract.blockers, function (item) {
|
|
909
|
+
return renderMarkdownInline(item);
|
|
910
|
+
})),
|
|
911
|
+
renderContractSection("Follow-ups", renderContractList(followUps, function (item) {
|
|
912
|
+
const prefix = escapeHtml(item.type || "follow-up") + (item.targetRole ? " (" + escapeHtml(item.targetRole) + ")" : "");
|
|
913
|
+
return prefix + ": " + renderMarkdownInline(item.reason || "");
|
|
914
|
+
})),
|
|
915
|
+
renderContractSection("Open Questions", renderContractList(contract.questions, function (item) {
|
|
916
|
+
return renderMarkdownInline(item);
|
|
917
|
+
})),
|
|
918
|
+
renderContractSection("Notes", renderContractMarkdownBody(contract.notes)),
|
|
919
|
+
],
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function renderProgressContractCard(contract) {
|
|
924
|
+
if (!contract || !normalizeTextValue(contract.summary)) {
|
|
925
|
+
return "";
|
|
926
|
+
}
|
|
927
|
+
return renderContractCard({
|
|
928
|
+
tone: contract.status || "in_progress",
|
|
929
|
+
kicker: "Structured Progress Contract",
|
|
930
|
+
title: contract.summary,
|
|
931
|
+
metaHtml: renderContractMetaRows([
|
|
932
|
+
{ label: "Status", value: humanizeStatus(contract.status || "in_progress") },
|
|
933
|
+
{ label: "Blockers", value: String((contract.blockers || []).length) },
|
|
934
|
+
]),
|
|
935
|
+
sections: [
|
|
936
|
+
renderContractSection("Current Step", renderContractMarkdownBody(contract.currentStep)),
|
|
937
|
+
renderContractSection("Next Step", renderContractMarkdownBody(contract.nextStep)),
|
|
938
|
+
renderContractSection("Blockers", renderContractList(contract.blockers, function (item) {
|
|
939
|
+
return renderMarkdownInline(item);
|
|
940
|
+
})),
|
|
941
|
+
],
|
|
942
|
+
});
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function renderHandoffContractCard(contract) {
|
|
946
|
+
if (!contract || !normalizeTextValue(contract.summary)) {
|
|
947
|
+
return "";
|
|
948
|
+
}
|
|
949
|
+
return renderContractCard({
|
|
950
|
+
tone: "handoff",
|
|
951
|
+
kicker: "Structured Handoff Contract",
|
|
952
|
+
title: contract.summary,
|
|
953
|
+
metaHtml: renderContractMetaRows([
|
|
954
|
+
{ label: "Target Role", value: contract.targetRole || "—" },
|
|
955
|
+
{ label: "Artifacts", value: String((contract.artifacts || []).length) },
|
|
956
|
+
]),
|
|
957
|
+
sections: [
|
|
958
|
+
renderContractSection("Reason", renderContractMarkdownBody(contract.reason)),
|
|
959
|
+
renderContractSection("Expected Next Step", renderContractMarkdownBody(contract.expectedNextStep)),
|
|
960
|
+
],
|
|
961
|
+
footerHtml: renderContractChips(contract.artifacts, "contract-chip-row contract-reference-row"),
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function renderTeamMessageContractCard(contract) {
|
|
966
|
+
if (!contract || !normalizeTextValue(contract.summary)) {
|
|
967
|
+
return "";
|
|
968
|
+
}
|
|
969
|
+
return renderContractCard({
|
|
970
|
+
tone: contract.intent || "update",
|
|
971
|
+
kicker: "Structured Message Contract",
|
|
972
|
+
title: contract.summary,
|
|
973
|
+
metaHtml: renderContractMetaRows([
|
|
974
|
+
{ label: "Intent", value: humanizeStatus(contract.intent || "update") },
|
|
975
|
+
{ label: "Needs Response", value: contract.needsResponse ? "Yes" : "No" },
|
|
976
|
+
{ label: "Requested Role", value: contract.requestedRole || "—" },
|
|
977
|
+
]),
|
|
978
|
+
sections: [
|
|
979
|
+
renderContractSection("Details", renderContractMarkdownBody(contract.details)),
|
|
980
|
+
renderContractSection("Requested Action", renderContractMarkdownBody(contract.requestedAction)),
|
|
981
|
+
],
|
|
982
|
+
footerHtml: renderContractChips(contract.references, "contract-chip-row contract-reference-row"),
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
function renderControllerManifestCard(manifest) {
|
|
987
|
+
if (!manifest || !normalizeTextValue(manifest.requirementSummary)) {
|
|
988
|
+
return "";
|
|
989
|
+
}
|
|
990
|
+
const createdTasks = Array.isArray(manifest.createdTasks) ? manifest.createdTasks : [];
|
|
991
|
+
const deferredTasks = Array.isArray(manifest.deferredTasks) ? manifest.deferredTasks : [];
|
|
992
|
+
return renderContractCard({
|
|
993
|
+
tone: "manifest",
|
|
994
|
+
kicker: "Structured Manifest",
|
|
995
|
+
title: manifest.requirementSummary,
|
|
996
|
+
metaHtml: renderContractMetaRows([
|
|
997
|
+
{ label: "Required Roles", value: String((manifest.requiredRoles || []).length) },
|
|
998
|
+
{ label: "Created Tasks", value: String(createdTasks.length) },
|
|
999
|
+
{ label: "Deferred Tasks", value: String(deferredTasks.length) },
|
|
1000
|
+
]),
|
|
1001
|
+
sections: [
|
|
1002
|
+
renderContractSection("Required Roles", renderContractChips(manifest.requiredRoles, "contract-chip-row contract-role-row")),
|
|
1003
|
+
renderContractSection("Created Tasks", renderContractList(createdTasks, function (item) {
|
|
1004
|
+
const roleLabel = item.assignedRole ? " (" + escapeHtml(item.assignedRole) + ")" : "";
|
|
1005
|
+
return '<strong>' + escapeHtml(item.title || "Task") + roleLabel + "</strong>: " + renderMarkdownInline(item.expectedOutcome || "");
|
|
1006
|
+
})),
|
|
1007
|
+
renderContractSection("Deferred Tasks", renderContractList(deferredTasks, function (item) {
|
|
1008
|
+
const roleLabel = item.assignedRole ? " (" + escapeHtml(item.assignedRole) + ")" : "";
|
|
1009
|
+
return '<strong>' + escapeHtml(item.title || "Task") + roleLabel + "</strong>: " + renderMarkdownInline(item.blockedBy || "") + " — create when " + renderMarkdownInline(item.whenReady || "");
|
|
1010
|
+
})),
|
|
1011
|
+
renderContractSection("Clarifications", renderContractList(manifest.clarificationQuestions, function (item) {
|
|
1012
|
+
return renderMarkdownInline(item);
|
|
1013
|
+
})),
|
|
1014
|
+
renderContractSection("Handoff Plan", renderContractMarkdownBody(manifest.handoffPlan)),
|
|
1015
|
+
renderContractSection("Notes", renderContractMarkdownBody(manifest.notes)),
|
|
1016
|
+
],
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
var ROLE_ICONS = {
|
|
1021
|
+
architect: "🏗️",
|
|
1022
|
+
developer: "💻",
|
|
1023
|
+
designer: "🎨",
|
|
1024
|
+
"security-engineer": "🔒",
|
|
1025
|
+
qa: "🧪",
|
|
1026
|
+
devops: "⚙️",
|
|
1027
|
+
"tech-lead": "👨💻",
|
|
1028
|
+
"data-engineer": "📊",
|
|
1029
|
+
"ml-engineer": "🤖",
|
|
1030
|
+
"infra-engineer": "🖧",
|
|
1031
|
+
"dba": "🗄️",
|
|
1032
|
+
};
|
|
1033
|
+
|
|
1034
|
+
function renderKickoffMeetingPanel(kickoffPlan) {
|
|
1035
|
+
if (!kickoffPlan || !Array.isArray(kickoffPlan.assessments) || kickoffPlan.assessments.length === 0) {
|
|
1036
|
+
return "";
|
|
1037
|
+
}
|
|
1038
|
+
var assessments = kickoffPlan.assessments;
|
|
1039
|
+
var needed = assessments.filter(function (a) { return a.needed; }).length;
|
|
1040
|
+
var notNeeded = assessments.length - needed;
|
|
1041
|
+
|
|
1042
|
+
var header =
|
|
1043
|
+
'<div class="kickoff-panel-header">' +
|
|
1044
|
+
' <div class="kickoff-panel-icon">🤝</div>' +
|
|
1045
|
+
' <div class="kickoff-panel-heading">' +
|
|
1046
|
+
' <h4>Team Kickoff Meeting</h4>' +
|
|
1047
|
+
' <div class="kickoff-panel-meta">' +
|
|
1048
|
+
assessments.length + " roles assessed · " +
|
|
1049
|
+
needed + " confirmed" +
|
|
1050
|
+
(notNeeded > 0 ? " · " + notNeeded + " dismissed" : "") +
|
|
1051
|
+
" </div>" +
|
|
1052
|
+
" </div>" +
|
|
1053
|
+
"</div>";
|
|
1054
|
+
|
|
1055
|
+
var roleCards = assessments.map(function (a) {
|
|
1056
|
+
var icon = ROLE_ICONS[a.role] || "👤";
|
|
1057
|
+
var statusCls = a.needed ? "kickoff-role-needed" : "kickoff-role-dismissed";
|
|
1058
|
+
var statusLabel = a.needed ? "Confirmed" : "Not Needed";
|
|
1059
|
+
|
|
1060
|
+
var scopeHtml = a.scope
|
|
1061
|
+
? '<div class="kickoff-role-scope">' + renderMarkdownContent(a.scope) + "</div>"
|
|
1062
|
+
: "";
|
|
1063
|
+
|
|
1064
|
+
var tasksHtml = "";
|
|
1065
|
+
if (Array.isArray(a.suggestedTasks) && a.suggestedTasks.length > 0) {
|
|
1066
|
+
tasksHtml =
|
|
1067
|
+
'<div class="kickoff-role-detail">' +
|
|
1068
|
+
' <div class="kickoff-detail-label">📋 Suggested Tasks</div>' +
|
|
1069
|
+
' <ul class="kickoff-detail-list">' +
|
|
1070
|
+
a.suggestedTasks.map(function (t) { return "<li>" + escapeHtml(t) + "</li>"; }).join("") +
|
|
1071
|
+
" </ul>" +
|
|
1072
|
+
"</div>";
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
var risksHtml = "";
|
|
1076
|
+
if (Array.isArray(a.risks) && a.risks.length > 0) {
|
|
1077
|
+
risksHtml =
|
|
1078
|
+
'<div class="kickoff-role-detail">' +
|
|
1079
|
+
' <div class="kickoff-detail-label">⚠️ Risks</div>' +
|
|
1080
|
+
' <ul class="kickoff-detail-list kickoff-risks">' +
|
|
1081
|
+
a.risks.map(function (r) { return "<li>" + escapeHtml(r) + "</li>"; }).join("") +
|
|
1082
|
+
" </ul>" +
|
|
1083
|
+
"</div>";
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
var depsHtml = "";
|
|
1087
|
+
if (Array.isArray(a.dependencies) && a.dependencies.length > 0) {
|
|
1088
|
+
depsHtml =
|
|
1089
|
+
'<div class="kickoff-role-detail">' +
|
|
1090
|
+
' <div class="kickoff-detail-label">🔗 Dependencies</div>' +
|
|
1091
|
+
' <div class="kickoff-deps">' +
|
|
1092
|
+
a.dependencies.map(function (d) { return '<span class="kickoff-dep-chip">' + escapeHtml(d) + "</span>"; }).join("") +
|
|
1093
|
+
" </div>" +
|
|
1094
|
+
"</div>";
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
return (
|
|
1098
|
+
'<div class="kickoff-role-card ' + statusCls + '">' +
|
|
1099
|
+
' <div class="kickoff-role-header">' +
|
|
1100
|
+
' <span class="kickoff-role-icon">' + icon + "</span>" +
|
|
1101
|
+
' <span class="kickoff-role-name">' + escapeHtml(a.role) + "</span>" +
|
|
1102
|
+
' <span class="kickoff-role-badge ' + statusCls + '">' + statusLabel + "</span>" +
|
|
1103
|
+
" </div>" +
|
|
1104
|
+
scopeHtml +
|
|
1105
|
+
tasksHtml +
|
|
1106
|
+
risksHtml +
|
|
1107
|
+
depsHtml +
|
|
1108
|
+
"</div>"
|
|
1109
|
+
);
|
|
1110
|
+
}).join("");
|
|
1111
|
+
|
|
1112
|
+
var summaryHtml = "";
|
|
1113
|
+
if (kickoffPlan.summary) {
|
|
1114
|
+
summaryHtml =
|
|
1115
|
+
'<div class="kickoff-summary">' +
|
|
1116
|
+
' <div class="kickoff-summary-label">Discussion Summary</div>' +
|
|
1117
|
+
' <div class="kickoff-summary-body markdown-body">' + renderMarkdownContent(kickoffPlan.summary) + "</div>" +
|
|
1118
|
+
"</div>";
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
return (
|
|
1122
|
+
'<div class="controller-run-section">' +
|
|
1123
|
+
' <div class="kickoff-panel">' +
|
|
1124
|
+
header +
|
|
1125
|
+
' <div class="kickoff-role-grid">' + roleCards + "</div>" +
|
|
1126
|
+
summaryHtml +
|
|
1127
|
+
" </div>" +
|
|
1128
|
+
"</div>"
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// ── Planning Tab ───────────────────────────────────────────────────────
|
|
1133
|
+
var selectedPlanningRunId = null;
|
|
1134
|
+
|
|
1135
|
+
function renderPlanningTab(runs) {
|
|
1136
|
+
var sessionList = $("#planning-session-list");
|
|
1137
|
+
if (!sessionList) return;
|
|
1138
|
+
|
|
1139
|
+
var planningRuns = (runs || [])
|
|
1140
|
+
.filter(function (r) { return r && r.manifest; })
|
|
1141
|
+
.sort(function (a, b) { return (b.updatedAt || 0) - (a.updatedAt || 0); });
|
|
1142
|
+
|
|
1143
|
+
if (planningRuns.length === 0) {
|
|
1144
|
+
sessionList.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noPlanningSessions")) + "</div>";
|
|
1145
|
+
showPlanningEmpty();
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// Auto-select first if nothing selected or selection is gone
|
|
1150
|
+
if (!selectedPlanningRunId || !planningRuns.some(function (r) { return r.id === selectedPlanningRunId; })) {
|
|
1151
|
+
selectedPlanningRunId = planningRuns[0].id;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
sessionList.innerHTML = planningRuns.map(function (run) {
|
|
1155
|
+
var manifest = run.manifest || {};
|
|
1156
|
+
var kp = manifest.kickoffPlan || {};
|
|
1157
|
+
var assessments = kp.assessments || [];
|
|
1158
|
+
var needed = assessments.filter(function (a) { return a.needed; }).length;
|
|
1159
|
+
var roles = (manifest.requiredRoles || []).length;
|
|
1160
|
+
var isActive = run.id === selectedPlanningRunId;
|
|
1161
|
+
var status = String(run.status || "active");
|
|
1162
|
+
var title = manifest.requirementSummary || run.title || "Untitled";
|
|
1163
|
+
if (title.length > 60) title = title.slice(0, 57) + "…";
|
|
1164
|
+
|
|
1165
|
+
return (
|
|
1166
|
+
'<button type="button" class="planning-session-btn' + (isActive ? " active" : "") + '" data-planning-run="' + escapeHtml(run.id) + '">' +
|
|
1167
|
+
' <div class="planning-session-title-row"><span class="planning-session-status ' + escapeHtml(status) + '"></span><div class="planning-session-title">' + escapeHtml(title) + "</div></div>" +
|
|
1168
|
+
' <div class="planning-session-meta">' + escapeHtml(humanizeStatus(status)) + " · " + roles + " roles" + (assessments.length ? " · " + needed + " confirmed" : "") + " · " + escapeHtml(formatTime(run.updatedAt) || "") + "</div>" +
|
|
1169
|
+
"</button>"
|
|
1170
|
+
);
|
|
1171
|
+
}).join("");
|
|
1172
|
+
|
|
1173
|
+
// Render selected run
|
|
1174
|
+
renderPlanningDetail(planningRuns.find(function (r) { return r.id === selectedPlanningRunId; }));
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
function showPlanningEmpty() {
|
|
1178
|
+
var empty = $("#planning-empty");
|
|
1179
|
+
var split = $("#planning-split");
|
|
1180
|
+
if (empty) empty.style.display = "";
|
|
1181
|
+
if (split) split.style.display = "none";
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
function renderPlanningDetail(run) {
|
|
1185
|
+
var empty = $("#planning-empty");
|
|
1186
|
+
var split = $("#planning-split");
|
|
1187
|
+
var reqEl = $("#planning-requirement");
|
|
1188
|
+
var kickoffEl = $("#planning-kickoff");
|
|
1189
|
+
|
|
1190
|
+
if (!run || !run.manifest) {
|
|
1191
|
+
showPlanningEmpty();
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
if (empty) empty.style.display = "none";
|
|
1196
|
+
if (split) split.style.display = "";
|
|
1197
|
+
|
|
1198
|
+
// Left pane: requirement + manifest summary
|
|
1199
|
+
if (reqEl) {
|
|
1200
|
+
var manifest = run.manifest;
|
|
1201
|
+
var reqLines = [];
|
|
1202
|
+
reqLines.push('<h3>' + escapeHtml(manifest.requirementSummary || run.title || "") + '</h3>');
|
|
1203
|
+
reqLines.push('<div class="planning-req-original">' + renderMarkdownContent(run.request || "") + '</div>');
|
|
1204
|
+
|
|
1205
|
+
// Manifest details
|
|
1206
|
+
if (manifest.requiredRoles && manifest.requiredRoles.length) {
|
|
1207
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.requiredRoles")) + "</div>");
|
|
1208
|
+
reqLines.push('<div class="kickoff-deps">' + manifest.requiredRoles.map(function (r) {
|
|
1209
|
+
var icon = ROLE_ICONS[r] || "👤";
|
|
1210
|
+
return '<span class="kickoff-dep-chip">' + icon + " " + escapeHtml(r) + "</span>";
|
|
1211
|
+
}).join("") + "</div></div>");
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
var created = Array.isArray(manifest.createdTasks) ? manifest.createdTasks : [];
|
|
1215
|
+
var deferred = Array.isArray(manifest.deferredTasks) ? manifest.deferredTasks : [];
|
|
1216
|
+
if (created.length) {
|
|
1217
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.plannedTasks")) + " (" + created.length + ")</div>");
|
|
1218
|
+
reqLines.push('<ul class="planning-task-list">');
|
|
1219
|
+
created.forEach(function (t) {
|
|
1220
|
+
var roleLabel = t.assignedRole ? ' <span class="planning-role-tag">' + escapeHtml(t.assignedRole) + "</span>" : "";
|
|
1221
|
+
reqLines.push("<li>" + escapeHtml(t.title || "Task") + roleLabel + "</li>");
|
|
1222
|
+
});
|
|
1223
|
+
reqLines.push("</ul></div>");
|
|
1224
|
+
}
|
|
1225
|
+
if (deferred.length) {
|
|
1226
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.deferredTasks")) + " (" + deferred.length + ")</div>");
|
|
1227
|
+
reqLines.push('<ul class="planning-task-list planning-deferred">');
|
|
1228
|
+
deferred.forEach(function (t) {
|
|
1229
|
+
var roleLabel = t.assignedRole ? ' <span class="planning-role-tag">' + escapeHtml(t.assignedRole) + "</span>" : "";
|
|
1230
|
+
reqLines.push("<li>" + escapeHtml(t.title || "Task") + roleLabel + "</li>");
|
|
1231
|
+
});
|
|
1232
|
+
reqLines.push("</ul></div>");
|
|
1233
|
+
}
|
|
1234
|
+
if (Array.isArray(manifest.clarificationQuestions) && manifest.clarificationQuestions.length) {
|
|
1235
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.clarificationsNeeded")) + "</div>");
|
|
1236
|
+
reqLines.push('<ul class="planning-task-list planning-deferred">');
|
|
1237
|
+
manifest.clarificationQuestions.forEach(function (question) {
|
|
1238
|
+
reqLines.push("<li>" + escapeHtml(question) + "</li>");
|
|
1239
|
+
});
|
|
1240
|
+
reqLines.push("</ul></div>");
|
|
1241
|
+
}
|
|
1242
|
+
if (manifest.handoffPlan) {
|
|
1243
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">Handoff Plan</div>');
|
|
1244
|
+
reqLines.push('<div class="planning-req-body markdown-body">' + renderMarkdownContent(manifest.handoffPlan) + "</div></div>");
|
|
1245
|
+
}
|
|
1246
|
+
if (manifest.notes) {
|
|
1247
|
+
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.notes")) + "</div>");
|
|
1248
|
+
reqLines.push('<div class="planning-req-body markdown-body">' + renderMarkdownContent(manifest.notes) + "</div></div>");
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
reqEl.innerHTML = reqLines.join("");
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
// Right pane: kickoff meeting or generic controller output
|
|
1255
|
+
if (kickoffEl) {
|
|
1256
|
+
if (run.manifest.kickoffPlan) {
|
|
1257
|
+
kickoffEl.innerHTML = renderKickoffContent(run.manifest.kickoffPlan);
|
|
1258
|
+
} else {
|
|
1259
|
+
kickoffEl.innerHTML =
|
|
1260
|
+
'<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.originalRequest")) + '</div><div class="planning-req-body markdown-body">' + renderMarkdownContent(run.request || "") + "</div></div>" +
|
|
1261
|
+
'<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.controllerOutput")) + '</div><div class="planning-req-body markdown-body">' + renderMarkdownContent(run.reply || t("planning.noControllerOutput")) + "</div></div>";
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function renderKickoffContent(kp) {
|
|
1267
|
+
if (!kp || !Array.isArray(kp.assessments) || kp.assessments.length === 0) {
|
|
1268
|
+
return '<div class="empty-state">' + escapeHtml(t("empty.noKickoffData")) + "</div>";
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
var assessments = kp.assessments;
|
|
1272
|
+
var html = [];
|
|
1273
|
+
|
|
1274
|
+
// Stats bar
|
|
1275
|
+
var needed = assessments.filter(function (a) { return a.needed; }).length;
|
|
1276
|
+
var dismissed = assessments.length - needed;
|
|
1277
|
+
html.push(
|
|
1278
|
+
'<div class="kickoff-stats-bar">' +
|
|
1279
|
+
' <div class="kickoff-stat"><span class="kickoff-stat-num">' + assessments.length + '</span><span class="kickoff-stat-label">Assessed</span></div>' +
|
|
1280
|
+
' <div class="kickoff-stat kickoff-stat-ok"><span class="kickoff-stat-num">' + needed + '</span><span class="kickoff-stat-label">Confirmed</span></div>' +
|
|
1281
|
+
(dismissed > 0 ? ' <div class="kickoff-stat kickoff-stat-dim"><span class="kickoff-stat-num">' + dismissed + '</span><span class="kickoff-stat-label">Dismissed</span></div>' : "") +
|
|
1282
|
+
"</div>"
|
|
1283
|
+
);
|
|
1284
|
+
|
|
1285
|
+
// Role cards
|
|
1286
|
+
assessments.forEach(function (a) {
|
|
1287
|
+
var icon = ROLE_ICONS[a.role] || "👤";
|
|
1288
|
+
var statusCls = a.needed ? "kickoff-role-needed" : "kickoff-role-dismissed";
|
|
1289
|
+
var statusLabel = a.needed ? "Confirmed" : "Not Needed";
|
|
1290
|
+
|
|
1291
|
+
var sections = [];
|
|
1292
|
+
|
|
1293
|
+
if (a.scope) {
|
|
1294
|
+
sections.push(
|
|
1295
|
+
'<div class="kickoff-role-scope"><div class="markdown-body">' + renderMarkdownContent(a.scope) + "</div></div>"
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
if (Array.isArray(a.suggestedTasks) && a.suggestedTasks.length > 0) {
|
|
1300
|
+
sections.push(
|
|
1301
|
+
'<details class="kickoff-collapsible" open>' +
|
|
1302
|
+
' <summary class="kickoff-detail-label">📋 Suggested Tasks (' + a.suggestedTasks.length + ")</summary>" +
|
|
1303
|
+
' <ul class="kickoff-detail-list">' +
|
|
1304
|
+
a.suggestedTasks.map(function (t) { return "<li>" + escapeHtml(t) + "</li>"; }).join("") +
|
|
1305
|
+
" </ul>" +
|
|
1306
|
+
"</details>"
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
if (Array.isArray(a.risks) && a.risks.length > 0) {
|
|
1311
|
+
sections.push(
|
|
1312
|
+
'<details class="kickoff-collapsible">' +
|
|
1313
|
+
' <summary class="kickoff-detail-label">⚠️ Risks (' + a.risks.length + ")</summary>" +
|
|
1314
|
+
' <ul class="kickoff-detail-list kickoff-risks">' +
|
|
1315
|
+
a.risks.map(function (r) { return "<li>" + escapeHtml(r) + "</li>"; }).join("") +
|
|
1316
|
+
" </ul>" +
|
|
1317
|
+
"</details>"
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
if (Array.isArray(a.dependencies) && a.dependencies.length > 0) {
|
|
1322
|
+
sections.push(
|
|
1323
|
+
'<details class="kickoff-collapsible">' +
|
|
1324
|
+
' <summary class="kickoff-detail-label">🔗 Dependencies (' + a.dependencies.length + ")</summary>" +
|
|
1325
|
+
' <div class="kickoff-deps">' +
|
|
1326
|
+
a.dependencies.map(function (d) { return '<span class="kickoff-dep-chip">' + escapeHtml(d) + "</span>"; }).join("") +
|
|
1327
|
+
" </div>" +
|
|
1328
|
+
"</details>"
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
html.push(
|
|
1333
|
+
'<div class="kickoff-role-card ' + statusCls + '">' +
|
|
1334
|
+
' <div class="kickoff-role-header">' +
|
|
1335
|
+
' <span class="kickoff-role-icon">' + icon + "</span>" +
|
|
1336
|
+
' <span class="kickoff-role-name">' + escapeHtml(a.role) + "</span>" +
|
|
1337
|
+
' <span class="kickoff-role-badge ' + statusCls + '">' + statusLabel + "</span>" +
|
|
1338
|
+
" </div>" +
|
|
1339
|
+
sections.join("") +
|
|
1340
|
+
"</div>"
|
|
1341
|
+
);
|
|
1342
|
+
});
|
|
1343
|
+
|
|
1344
|
+
// Summary
|
|
1345
|
+
if (kp.summary) {
|
|
1346
|
+
html.push(
|
|
1347
|
+
'<div class="kickoff-summary">' +
|
|
1348
|
+
' <div class="kickoff-summary-label">Discussion Summary</div>' +
|
|
1349
|
+
' <div class="kickoff-summary-body markdown-body">' + renderMarkdownContent(kp.summary) + "</div>" +
|
|
1350
|
+
"</div>"
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
return html.join("");
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
function buildMessageDisplayContent(message) {
|
|
1358
|
+
const content = normalizeTextValue(message && message.content);
|
|
1359
|
+
const contract = message && message.contract ? message.contract : null;
|
|
1360
|
+
if (!contract || !normalizeTextValue(contract.summary)) {
|
|
1361
|
+
return renderMarkdownContent(content);
|
|
1362
|
+
}
|
|
1363
|
+
const detailContent = normalizeTextValue(contract.details || "");
|
|
1364
|
+
if (!content || content === normalizeTextValue(contract.summary) || content === detailContent) {
|
|
1365
|
+
return "";
|
|
1366
|
+
}
|
|
1367
|
+
return renderMarkdownContent(message.content || "");
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function findWorkspaceNodeByPath(nodes, relativePath) {
|
|
1371
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
1372
|
+
const node = nodes[index];
|
|
1373
|
+
if (node.path === relativePath) {
|
|
1374
|
+
return node;
|
|
1375
|
+
}
|
|
1376
|
+
if (node.type === "directory" && node.children && node.children.length) {
|
|
1377
|
+
const found = findWorkspaceNodeByPath(node.children, relativePath);
|
|
1378
|
+
if (found) {
|
|
1379
|
+
return found;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
return null;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/** Merge lazy-loaded children into the workspace tree data model. */
|
|
1387
|
+
function mergeWorkspaceSubtree(dirPath, entries) {
|
|
1388
|
+
var dirNode = findWorkspaceNodeByPath(workspaceTree, dirPath);
|
|
1389
|
+
if (dirNode && dirNode.type === "directory") {
|
|
1390
|
+
dirNode.children = entries;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
function findDefaultWorkspacePath(nodes) {
|
|
1395
|
+
const preferredNames = ["README.md", "SPEC.md", "index.html"];
|
|
1396
|
+
const queue = [].concat(nodes || []);
|
|
1397
|
+
let firstFile = null;
|
|
1398
|
+
|
|
1399
|
+
while (queue.length > 0) {
|
|
1400
|
+
const node = queue.shift();
|
|
1401
|
+
if (!node) continue;
|
|
1402
|
+
if (node.type === "file") {
|
|
1403
|
+
if (!firstFile) {
|
|
1404
|
+
firstFile = node.path;
|
|
1405
|
+
}
|
|
1406
|
+
if (preferredNames.indexOf(node.name) !== -1) {
|
|
1407
|
+
return node.path;
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
if (node.type === "directory" && Array.isArray(node.children)) {
|
|
1411
|
+
queue.push.apply(queue, node.children);
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
return firstFile;
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
function isTaskLive(task) {
|
|
1419
|
+
return !!task && ["assigned", "in_progress", "review"].indexOf(task.status) !== -1;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
function getTaskById(taskId) {
|
|
1423
|
+
return (teamState.tasks || []).find(function (task) { return task.id === taskId; }) || null;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
function getSelectedTaskExecution() {
|
|
1427
|
+
if (!selectedTaskDetail || !selectedTaskDetail.task || !selectedTaskDetail.task.execution) {
|
|
1428
|
+
return { events: [] };
|
|
1429
|
+
}
|
|
1430
|
+
return selectedTaskDetail.task.execution;
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
function showError(message) {
|
|
1434
|
+
// Non-blocking toast instead of a native alert(): native dialogs freeze
|
|
1435
|
+
// the page and steal focus, and multiple rapid errors queue up behind
|
|
1436
|
+
// each other. Toasts stack, auto-dismiss, and are click-dismissible.
|
|
1437
|
+
let container = document.getElementById("toast-container");
|
|
1438
|
+
if (!container) {
|
|
1439
|
+
container = document.createElement("div");
|
|
1440
|
+
container.id = "toast-container";
|
|
1441
|
+
container.style.cssText = "position:fixed;bottom:24px;right:24px;z-index:2000;display:flex;flex-direction:column;gap:10px;max-width:min(420px,80vw);";
|
|
1442
|
+
document.body.appendChild(container);
|
|
1443
|
+
}
|
|
1444
|
+
const toast = document.createElement("div");
|
|
1445
|
+
toast.className = "app-toast app-toast-error";
|
|
1446
|
+
toast.style.cssText = "background:#7f1d1d;color:#fff;padding:12px 16px;border-radius:10px;"
|
|
1447
|
+
+ "box-shadow:0 8px 24px rgba(0,0,0,0.35);font-size:13px;line-height:1.45;"
|
|
1448
|
+
+ "cursor:pointer;opacity:0;transition:opacity 0.25s ease;";
|
|
1449
|
+
toast.textContent = message;
|
|
1450
|
+
container.appendChild(toast);
|
|
1451
|
+
requestAnimationFrame(function () { toast.style.opacity = "1"; });
|
|
1452
|
+
const dismiss = function () {
|
|
1453
|
+
toast.style.opacity = "0";
|
|
1454
|
+
setTimeout(function () { toast.remove(); }, 250);
|
|
1455
|
+
};
|
|
1456
|
+
toast.onclick = dismiss;
|
|
1457
|
+
setTimeout(dismiss, 5000);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
var TOAST_PREFS_KEY = "teamclaw.toast.prefs.v1";
|
|
1461
|
+
var TOAST_EVENT_DEFS = [
|
|
1462
|
+
{ id: "task:completed", titleKey: "toast.taskCompleted", freqKey: "toast.freqTaskCompleted" },
|
|
1463
|
+
{ id: "task:created", titleKey: "toast.taskCreated", freqKey: "toast.freqTaskCreated" },
|
|
1464
|
+
{ id: "task:updated", titleKey: "toast.taskUpdated", freqKey: "toast.freqTaskUpdated" },
|
|
1465
|
+
{ id: "clarification:requested", titleKey: "toast.clarificationRequested", freqKey: "toast.freqClarification" },
|
|
1466
|
+
{ id: "clarification:answered", titleKey: "toast.clarificationAnswered", freqKey: "toast.freqClarification" },
|
|
1467
|
+
{ id: "worker:online", titleKey: "toast.workerOnline", freqKey: "toast.freqWorker" },
|
|
1468
|
+
{ id: "worker:offline", titleKey: "toast.workerOffline", freqKey: "toast.freqWorker" },
|
|
1469
|
+
{ id: "teamauto:activity", titleKey: "toast.teamautoPrefix", freqKey: "toast.freqTeamauto" },
|
|
1470
|
+
{ id: "teamauto:activity:bind", titleKey: "toast.taBind", freqKey: "toast.freqTaBind" },
|
|
1471
|
+
{ id: "teamauto:activity:provision", titleKey: "toast.taProvision", freqKey: "toast.freqTaProvision" },
|
|
1472
|
+
{ id: "teamauto:activity:task", titleKey: "toast.taTask", freqKey: "toast.freqTaTask" },
|
|
1473
|
+
{ id: "teamauto:activity:sweep", titleKey: "toast.taSweep", freqKey: "toast.freqTaSweep" },
|
|
1474
|
+
{ id: "teamauto:activity:writeback", titleKey: "toast.taWriteback", freqKey: "toast.freqTaWriteback" },
|
|
1475
|
+
{ id: "message:new", titleKey: "toast.messageNew", freqKey: "toast.freqMessageNew" },
|
|
1476
|
+
];
|
|
1477
|
+
|
|
1478
|
+
function loadToastPrefs() {
|
|
1479
|
+
try {
|
|
1480
|
+
var raw = window.localStorage.getItem(TOAST_PREFS_KEY);
|
|
1481
|
+
if (raw) {
|
|
1482
|
+
var parsed = JSON.parse(raw);
|
|
1483
|
+
if (parsed && typeof parsed === "object") {
|
|
1484
|
+
return parsed;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
} catch (_err) {}
|
|
1488
|
+
return {};
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
function toastEnabled(eventId) {
|
|
1492
|
+
// All event toasts are enabled by default; users opt out per event.
|
|
1493
|
+
return loadToastPrefs()[eventId] !== false;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
function setToastPref(eventId, enabled) {
|
|
1497
|
+
var prefs = loadToastPrefs();
|
|
1498
|
+
prefs[eventId] = !!enabled;
|
|
1499
|
+
try {
|
|
1500
|
+
window.localStorage.setItem(TOAST_PREFS_KEY, JSON.stringify(prefs));
|
|
1501
|
+
} catch (_err) {}
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
function workerEventLabel(data) {
|
|
1505
|
+
data = data || {};
|
|
1506
|
+
return String(data.id || data.workerId || data.name || data.role || "");
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
function messageEventLabel(data) {
|
|
1510
|
+
data = data || {};
|
|
1511
|
+
var from = data.fromRole || data.role || data.sender || "";
|
|
1512
|
+
var text = String(data.text || data.content || data.body || "").slice(0, 80);
|
|
1513
|
+
return (from ? from + ": " : "") + text;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
function toggleToastSettingsPanel() {
|
|
1517
|
+
var existing = document.getElementById("toast-settings-panel");
|
|
1518
|
+
if (existing) {
|
|
1519
|
+
existing.remove();
|
|
1520
|
+
return;
|
|
1521
|
+
}
|
|
1522
|
+
var panel = document.createElement("div");
|
|
1523
|
+
panel.id = "toast-settings-panel";
|
|
1524
|
+
panel.style.cssText = "position:fixed;top:64px;right:16px;z-index:2100;background:#111827;color:#fff;"
|
|
1525
|
+
+ "border-radius:12px;box-shadow:0 12px 32px rgba(0,0,0,0.4);padding:16px;"
|
|
1526
|
+
+ "min-width:320px;max-width:min(430px,92vw);font-size:13px;line-height:1.5;";
|
|
1527
|
+
var head = document.createElement("div");
|
|
1528
|
+
head.style.cssText = "display:flex;align-items:center;justify-content:space-between;margin-bottom:10px;";
|
|
1529
|
+
var title = document.createElement("div");
|
|
1530
|
+
title.style.fontWeight = "600";
|
|
1531
|
+
title.textContent = t("toast.settingsTitle");
|
|
1532
|
+
var close = document.createElement("button");
|
|
1533
|
+
close.type = "button";
|
|
1534
|
+
close.textContent = t("teamauto.close");
|
|
1535
|
+
close.style.cssText = "background:none;border:1px solid rgba(255,255,255,0.3);color:#fff;border-radius:6px;padding:2px 8px;cursor:pointer;font-size:12px;";
|
|
1536
|
+
close.addEventListener("click", function () { panel.remove(); });
|
|
1537
|
+
head.appendChild(title);
|
|
1538
|
+
head.appendChild(close);
|
|
1539
|
+
panel.appendChild(head);
|
|
1540
|
+
var prefs = loadToastPrefs();
|
|
1541
|
+
TOAST_EVENT_DEFS.forEach(function (def) {
|
|
1542
|
+
var row = document.createElement("label");
|
|
1543
|
+
row.style.cssText = "display:flex;gap:10px;align-items:flex-start;padding:7px 0;border-top:1px solid rgba(255,255,255,0.08);cursor:pointer;";
|
|
1544
|
+
var box = document.createElement("input");
|
|
1545
|
+
box.type = "checkbox";
|
|
1546
|
+
box.checked = prefs[def.id] !== false;
|
|
1547
|
+
box.style.marginTop = "3px";
|
|
1548
|
+
box.addEventListener("change", function () {
|
|
1549
|
+
setToastPref(def.id, box.checked);
|
|
1550
|
+
});
|
|
1551
|
+
var text = document.createElement("div");
|
|
1552
|
+
var name = document.createElement("div");
|
|
1553
|
+
name.style.fontWeight = "600";
|
|
1554
|
+
name.textContent = t(def.titleKey);
|
|
1555
|
+
var freq = document.createElement("div");
|
|
1556
|
+
freq.style.cssText = "opacity:0.65;font-size:12px;";
|
|
1557
|
+
freq.textContent = t(def.freqKey);
|
|
1558
|
+
text.appendChild(name);
|
|
1559
|
+
text.appendChild(freq);
|
|
1560
|
+
row.appendChild(box);
|
|
1561
|
+
row.appendChild(text);
|
|
1562
|
+
panel.appendChild(row);
|
|
1563
|
+
});
|
|
1564
|
+
var foot = document.createElement("div");
|
|
1565
|
+
foot.style.cssText = "display:flex;gap:8px;justify-content:flex-end;margin-top:10px;";
|
|
1566
|
+
var allOn = document.createElement("button");
|
|
1567
|
+
allOn.type = "button";
|
|
1568
|
+
allOn.textContent = t("toast.enableAll");
|
|
1569
|
+
var allOff = document.createElement("button");
|
|
1570
|
+
allOff.type = "button";
|
|
1571
|
+
allOff.textContent = t("toast.disableAll");
|
|
1572
|
+
[allOn, allOff].forEach(function (btn) {
|
|
1573
|
+
btn.style.cssText = "background:rgba(255,255,255,0.1);border:1px solid rgba(255,255,255,0.25);color:#fff;border-radius:6px;padding:4px 10px;cursor:pointer;font-size:12px;";
|
|
1574
|
+
});
|
|
1575
|
+
allOn.addEventListener("click", function () {
|
|
1576
|
+
TOAST_EVENT_DEFS.forEach(function (def) { setToastPref(def.id, true); });
|
|
1577
|
+
panel.remove();
|
|
1578
|
+
toggleToastSettingsPanel();
|
|
1579
|
+
});
|
|
1580
|
+
allOff.addEventListener("click", function () {
|
|
1581
|
+
TOAST_EVENT_DEFS.forEach(function (def) { setToastPref(def.id, false); });
|
|
1582
|
+
panel.remove();
|
|
1583
|
+
toggleToastSettingsPanel();
|
|
1584
|
+
});
|
|
1585
|
+
foot.appendChild(allOff);
|
|
1586
|
+
foot.appendChild(allOn);
|
|
1587
|
+
panel.appendChild(foot);
|
|
1588
|
+
document.body.appendChild(panel);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
var toastSettingsToggle = $("#toast-settings-toggle");
|
|
1592
|
+
if (toastSettingsToggle) {
|
|
1593
|
+
toastSettingsToggle.addEventListener("click", function (event) {
|
|
1594
|
+
event.stopPropagation();
|
|
1595
|
+
toggleToastSettingsPanel();
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
const recentNoticeKeys = {};
|
|
1600
|
+
|
|
1601
|
+
function showNotice(eventId, kind, title, body) {
|
|
1602
|
+
// Status-change toasts (task/worker/clarification/TeamAuto events).
|
|
1603
|
+
// Per-event toggles persist in localStorage (all on by default);
|
|
1604
|
+
// deduped against event bursts and capped so a busy team cannot
|
|
1605
|
+
// flood the corner.
|
|
1606
|
+
if (!toastEnabled(eventId)) {
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
const now = Date.now();
|
|
1610
|
+
const dedupeKey = kind + "|" + title + "|" + body;
|
|
1611
|
+
if (recentNoticeKeys[dedupeKey] && now - recentNoticeKeys[dedupeKey] < 4000) {
|
|
1612
|
+
return;
|
|
1613
|
+
}
|
|
1614
|
+
recentNoticeKeys[dedupeKey] = now;
|
|
1615
|
+
if (Object.keys(recentNoticeKeys).length > 200) {
|
|
1616
|
+
for (var staleKey in recentNoticeKeys) {
|
|
1617
|
+
if (now - recentNoticeKeys[staleKey] >= 4000) {
|
|
1618
|
+
delete recentNoticeKeys[staleKey];
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
let container = document.getElementById("toast-container");
|
|
1623
|
+
if (!container) {
|
|
1624
|
+
container = document.createElement("div");
|
|
1625
|
+
container.id = "toast-container";
|
|
1626
|
+
container.style.cssText = "position:fixed;bottom:24px;right:24px;z-index:2000;display:flex;flex-direction:column;gap:10px;max-width:min(420px,80vw);";
|
|
1627
|
+
document.body.appendChild(container);
|
|
1628
|
+
}
|
|
1629
|
+
while (container.children.length >= 6) {
|
|
1630
|
+
container.removeChild(container.firstChild);
|
|
1631
|
+
}
|
|
1632
|
+
const toast = document.createElement("div");
|
|
1633
|
+
const bg = kind === "success" ? "#14532d" : kind === "attention" ? "#7f1d1d" : "#1e3a5f";
|
|
1634
|
+
toast.style.cssText = "background:" + bg + ";color:#fff;padding:12px 16px;border-radius:10px;"
|
|
1635
|
+
+ "box-shadow:0 8px 24px rgba(0,0,0,0.35);font-size:13px;line-height:1.45;"
|
|
1636
|
+
+ "cursor:pointer;opacity:0;transition:opacity 0.25s ease;";
|
|
1637
|
+
const titleEl = document.createElement("div");
|
|
1638
|
+
titleEl.style.cssText = "font-weight:600;";
|
|
1639
|
+
titleEl.textContent = title;
|
|
1640
|
+
const bodyEl = document.createElement("div");
|
|
1641
|
+
bodyEl.style.cssText = "opacity:.85;margin-top:2px;";
|
|
1642
|
+
bodyEl.textContent = body;
|
|
1643
|
+
toast.appendChild(titleEl);
|
|
1644
|
+
toast.appendChild(bodyEl);
|
|
1645
|
+
container.appendChild(toast);
|
|
1646
|
+
requestAnimationFrame(function () { toast.style.opacity = "1"; });
|
|
1647
|
+
const dismiss = function () {
|
|
1648
|
+
toast.style.opacity = "0";
|
|
1649
|
+
setTimeout(function () { toast.remove(); }, 250);
|
|
1650
|
+
};
|
|
1651
|
+
toast.onclick = dismiss;
|
|
1652
|
+
setTimeout(dismiss, 6000);
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
async function apiRequest(path, options) {
|
|
1656
|
+
const res = await fetch(API_BASE + path, options);
|
|
1657
|
+
let data = {};
|
|
1658
|
+
try {
|
|
1659
|
+
data = await res.json();
|
|
1660
|
+
} catch (_err) {
|
|
1661
|
+
data = {};
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
if (!res.ok) {
|
|
1665
|
+
const message = data && (data.error || data.message)
|
|
1666
|
+
? (data.error || data.message)
|
|
1667
|
+
: ("Request failed: " + res.status);
|
|
1668
|
+
throw new Error(message);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
return data;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
function apiGet(path) {
|
|
1675
|
+
return apiRequest(path);
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
function apiPost(path, body) {
|
|
1679
|
+
return apiRequest(path, {
|
|
1680
|
+
method: "POST",
|
|
1681
|
+
headers: { "Content-Type": "application/json" },
|
|
1682
|
+
body: JSON.stringify(body),
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
async function refreshWorkspaceTree(silent) {
|
|
1687
|
+
try {
|
|
1688
|
+
const data = await apiGet("/workspace/tree");
|
|
1689
|
+
workspaceTree = data.entries || [];
|
|
1690
|
+
workspaceLoaded = true;
|
|
1691
|
+
renderWorkspaceTree(workspaceTree);
|
|
1692
|
+
|
|
1693
|
+
const nextPath = selectedWorkspacePath && findWorkspaceNodeByPath(workspaceTree, selectedWorkspacePath)
|
|
1694
|
+
? selectedWorkspacePath
|
|
1695
|
+
: findDefaultWorkspacePath(workspaceTree);
|
|
1696
|
+
|
|
1697
|
+
if (!nextPath) {
|
|
1698
|
+
selectedWorkspacePath = null;
|
|
1699
|
+
selectedWorkspaceFile = null;
|
|
1700
|
+
selectedWorkspaceView = "source";
|
|
1701
|
+
renderWorkspaceFile();
|
|
1702
|
+
return;
|
|
1703
|
+
}
|
|
1704
|
+
|
|
1705
|
+
if (nextPath !== selectedWorkspacePath || !selectedWorkspaceFile) {
|
|
1706
|
+
await loadWorkspaceFile(nextPath, { silent: true });
|
|
1707
|
+
} else if (activeTab === "workspace") {
|
|
1708
|
+
await loadWorkspaceFile(nextPath, { keepView: true, silent: true });
|
|
1709
|
+
}
|
|
1710
|
+
} catch (err) {
|
|
1711
|
+
console.error("Failed to load workspace tree:", err);
|
|
1712
|
+
if (!silent) {
|
|
1713
|
+
showError(err instanceof Error ? err.message : "Failed to load workspace tree");
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
async function loadWorkspaceFile(relativePath, options) {
|
|
1719
|
+
const settings = Object.assign({ keepView: false, silent: false }, options || {});
|
|
1720
|
+
try {
|
|
1721
|
+
const data = await apiGet("/workspace/file?path=" + encodeURIComponent(relativePath));
|
|
1722
|
+
selectedWorkspacePath = relativePath;
|
|
1723
|
+
selectedWorkspaceFile = data.file || null;
|
|
1724
|
+
if (settings.keepView && selectedWorkspaceView === "preview" && isWorkspacePreviewAvailable(selectedWorkspaceFile)) {
|
|
1725
|
+
// User explicitly chose preview and new file supports it — keep preview
|
|
1726
|
+
} else {
|
|
1727
|
+
// Default: md/html show preview, everything else shows source
|
|
1728
|
+
selectedWorkspaceView = isWorkspacePreviewAvailable(selectedWorkspaceFile) ? "preview" : "source";
|
|
1729
|
+
}
|
|
1730
|
+
updateWorkspaceTreeSelection();
|
|
1731
|
+
renderWorkspaceFile();
|
|
1732
|
+
} catch (err) {
|
|
1733
|
+
console.error("Failed to load workspace file:", err);
|
|
1734
|
+
if (!settings.silent) {
|
|
1735
|
+
showError(err instanceof Error ? err.message : "Failed to load workspace file");
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
function renderWorkspaceTree(nodes) {
|
|
1741
|
+
const container = $("#workspace-tree");
|
|
1742
|
+
if (!container) return;
|
|
1743
|
+
|
|
1744
|
+
if (!workspaceLoaded) {
|
|
1745
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.workspaceLoading")) + "</div>";
|
|
1746
|
+
return;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
if (!nodes || nodes.length === 0) {
|
|
1750
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noWorkspaceFiles")) + "</div>";
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// Capture currently expanded directories before re-render
|
|
1755
|
+
var expandedDirs = new Set();
|
|
1756
|
+
var toggles = container.querySelectorAll(".workspace-tree-dir-toggle");
|
|
1757
|
+
for (var i = 0; i < toggles.length; i++) {
|
|
1758
|
+
var toggle = toggles[i];
|
|
1759
|
+
var li = toggle.closest(".workspace-tree-folder");
|
|
1760
|
+
var children = li ? li.querySelector(".workspace-tree-children") : null;
|
|
1761
|
+
if (children && children.style.display !== "none") {
|
|
1762
|
+
expandedDirs.add(toggle.dataset.dirPath);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
container.innerHTML = renderWorkspaceTreeNodes(nodes);
|
|
1767
|
+
|
|
1768
|
+
// Restore expanded directories
|
|
1769
|
+
if (expandedDirs.size > 0) {
|
|
1770
|
+
var newToggles = container.querySelectorAll(".workspace-tree-dir-toggle");
|
|
1771
|
+
for (var j = 0; j < newToggles.length; j++) {
|
|
1772
|
+
var toggleEl = newToggles[j];
|
|
1773
|
+
if (expandedDirs.has(toggleEl.dataset.dirPath)) {
|
|
1774
|
+
var parentLi = toggleEl.closest(".workspace-tree-folder");
|
|
1775
|
+
var childrenDiv = parentLi ? parentLi.querySelector(".workspace-tree-children") : null;
|
|
1776
|
+
if (childrenDiv) {
|
|
1777
|
+
childrenDiv.style.display = "";
|
|
1778
|
+
var arrow = toggleEl.querySelector(".workspace-tree-arrow");
|
|
1779
|
+
if (arrow) arrow.textContent = "▾";
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
function renderWorkspaceTreeNodes(nodes) {
|
|
1787
|
+
return '<ul class="workspace-tree-list">' + nodes.map(function (node) {
|
|
1788
|
+
if (node.type === "directory") {
|
|
1789
|
+
const hasChildren = node.children && node.children.length > 0;
|
|
1790
|
+
const isLazy = !node.children; // children === undefined means not yet loaded
|
|
1791
|
+
return (
|
|
1792
|
+
'<li class="workspace-tree-folder">' +
|
|
1793
|
+
' <div class="workspace-tree-dir-toggle' + (isLazy ? ' is-lazy' : '') + '" data-dir-path="' + escapeHtml(node.path) + '">' +
|
|
1794
|
+
' <span class="workspace-tree-arrow">▸</span>' +
|
|
1795
|
+
' <span class="workspace-tree-label">' + escapeHtml(node.name) + "</span>" +
|
|
1796
|
+
" </div>" +
|
|
1797
|
+
' <div class="workspace-tree-children" style="display:none">' +
|
|
1798
|
+
(hasChildren ? renderWorkspaceTreeNodes(node.children) : '') +
|
|
1799
|
+
" </div>" +
|
|
1800
|
+
"</li>"
|
|
1801
|
+
);
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
const selectedClass = node.path === selectedWorkspacePath ? " is-selected" : "";
|
|
1805
|
+
const previewBadge = node.previewType === "markdown"
|
|
1806
|
+
? "MD"
|
|
1807
|
+
: (node.previewType === "html" ? "HTML" : "FILE");
|
|
1808
|
+
|
|
1809
|
+
return (
|
|
1810
|
+
'<li>' +
|
|
1811
|
+
' <button type="button" class="workspace-tree-file' + selectedClass + '" data-workspace-path="' + escapeHtml(node.path) + '">' +
|
|
1812
|
+
' <span class="workspace-tree-icon">' + escapeHtml(previewBadge) + "</span>" +
|
|
1813
|
+
' <span class="workspace-tree-label">' + escapeHtml(node.name) + "</span>" +
|
|
1814
|
+
" </button>" +
|
|
1815
|
+
"</li>"
|
|
1816
|
+
);
|
|
1817
|
+
}).join("") + "</ul>";
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
/** Update only the selected highlight in the tree without re-rendering (preserves expand state). */
|
|
1821
|
+
function updateWorkspaceTreeSelection() {
|
|
1822
|
+
var container = $("#workspace-tree");
|
|
1823
|
+
if (!container) return;
|
|
1824
|
+
var buttons = container.querySelectorAll(".workspace-tree-file");
|
|
1825
|
+
for (var i = 0; i < buttons.length; i++) {
|
|
1826
|
+
var btn = buttons[i];
|
|
1827
|
+
var isSelected = btn.dataset.workspacePath === selectedWorkspacePath;
|
|
1828
|
+
btn.classList.toggle("is-selected", isSelected);
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
function renderWorkspaceFile() {
|
|
1833
|
+
const fileName = $("#workspace-file-name");
|
|
1834
|
+
const fileMeta = $("#workspace-file-meta");
|
|
1835
|
+
const openRaw = $("#workspace-open-raw");
|
|
1836
|
+
|
|
1837
|
+
if (fileName) {
|
|
1838
|
+
fileName.textContent = selectedWorkspaceFile ? selectedWorkspaceFile.name : t("workspace.selectFile");
|
|
1839
|
+
}
|
|
1840
|
+
if (fileMeta) {
|
|
1841
|
+
fileMeta.textContent = selectedWorkspaceFile
|
|
1842
|
+
? [selectedWorkspaceFile.path, formatBytes(selectedWorkspaceFile.size), humanizeStatus(selectedWorkspaceFile.previewType)].join(" • ")
|
|
1843
|
+
: "Choose a workspace file to inspect source or preview output.";
|
|
1844
|
+
}
|
|
1845
|
+
if (openRaw) {
|
|
1846
|
+
if (selectedWorkspaceFile && selectedWorkspaceFile.rawUrl) {
|
|
1847
|
+
openRaw.href = selectedWorkspaceFile.rawUrl;
|
|
1848
|
+
openRaw.classList.remove("hidden");
|
|
1849
|
+
} else {
|
|
1850
|
+
openRaw.classList.add("hidden");
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
const sourceTab = $("#workspace-view-source");
|
|
1855
|
+
const previewTab = $("#workspace-view-preview");
|
|
1856
|
+
if (sourceTab) {
|
|
1857
|
+
sourceTab.classList.toggle("active", selectedWorkspaceView === "source");
|
|
1858
|
+
}
|
|
1859
|
+
if (previewTab) {
|
|
1860
|
+
const previewEnabled = isWorkspacePreviewAvailable(selectedWorkspaceFile);
|
|
1861
|
+
previewTab.disabled = !previewEnabled;
|
|
1862
|
+
previewTab.classList.toggle("active", selectedWorkspaceView === "preview" && previewEnabled);
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
renderWorkspaceSource();
|
|
1866
|
+
renderWorkspacePreview();
|
|
1867
|
+
syncWorkspaceViewPanels();
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
function renderWorkspaceSource() {
|
|
1871
|
+
const container = $("#workspace-source-view");
|
|
1872
|
+
if (!container) return;
|
|
1873
|
+
|
|
1874
|
+
if (!selectedWorkspaceFile) {
|
|
1875
|
+
container.innerHTML = '<div class="workspace-preview-empty">' + escapeHtml(t("empty.selectFileSource")) + "</div>";
|
|
1876
|
+
return;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
if (selectedWorkspaceFile.previewType === "binary") {
|
|
1880
|
+
container.innerHTML = '<div class="workspace-preview-empty">This file looks binary. Use <strong>Open Raw</strong> to inspect or download it.</div>';
|
|
1881
|
+
return;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
const content = selectedWorkspaceFile.content || "";
|
|
1885
|
+
const lines = content.split("\n");
|
|
1886
|
+
const warning = selectedWorkspaceFile.truncated
|
|
1887
|
+
? '<div class="workspace-source-warning">Showing the first 256 KB of this file for UI performance.</div>'
|
|
1888
|
+
: "";
|
|
1889
|
+
|
|
1890
|
+
container.innerHTML =
|
|
1891
|
+
'<div class="workspace-source-shell">' +
|
|
1892
|
+
warning +
|
|
1893
|
+
'<div class="workspace-source-lines">' +
|
|
1894
|
+
lines.map(function (line, index) {
|
|
1895
|
+
return (
|
|
1896
|
+
'<div class="workspace-source-line">' +
|
|
1897
|
+
' <div class="workspace-source-line-number">' + (index + 1) + "</div>" +
|
|
1898
|
+
' <div class="workspace-source-line-text">' + (line ? escapeHtml(line) : " ") + "</div>" +
|
|
1899
|
+
"</div>"
|
|
1900
|
+
);
|
|
1901
|
+
}).join("") +
|
|
1902
|
+
"</div>" +
|
|
1903
|
+
"</div>";
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
function renderWorkspacePreview() {
|
|
1907
|
+
const container = $("#workspace-preview-view");
|
|
1908
|
+
if (!container) return;
|
|
1909
|
+
|
|
1910
|
+
if (!selectedWorkspaceFile) {
|
|
1911
|
+
container.innerHTML = '<div class="workspace-preview-empty">' + escapeHtml(t("empty.selectFilePreview")) + "</div>";
|
|
1912
|
+
return;
|
|
1913
|
+
}
|
|
1914
|
+
|
|
1915
|
+
if (selectedWorkspaceFile.previewType === "markdown") {
|
|
1916
|
+
container.innerHTML = '<div class="workspace-markdown-preview markdown-body">' + renderMarkdownContent(selectedWorkspaceFile.content) + "</div>";
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
if (selectedWorkspaceFile.previewType === "html") {
|
|
1921
|
+
container.innerHTML = '<iframe class="workspace-preview-frame" sandbox="allow-scripts allow-forms" src="' + escapeHtml(selectedWorkspaceFile.rawUrl) + '"></iframe>';
|
|
1922
|
+
return;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
container.innerHTML = '<div class="workspace-preview-empty">Preview is available for Markdown and HTML files. This file stays in source mode.</div>';
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
function syncWorkspaceViewPanels() {
|
|
1929
|
+
const sourcePanel = $("#workspace-source-view");
|
|
1930
|
+
const previewPanel = $("#workspace-preview-view");
|
|
1931
|
+
if (sourcePanel) {
|
|
1932
|
+
sourcePanel.classList.toggle("active", selectedWorkspaceView === "source");
|
|
1933
|
+
}
|
|
1934
|
+
if (previewPanel) {
|
|
1935
|
+
previewPanel.classList.toggle("active", selectedWorkspaceView === "preview");
|
|
1936
|
+
}
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
function connectWebSocket() {
|
|
1940
|
+
if (isConnecting) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
const protocol = location.protocol === "https:" ? "wss" : "ws";
|
|
1944
|
+
const wsUrl = `${protocol}://${location.host}/ws`;
|
|
1945
|
+
|
|
1946
|
+
isConnecting = true;
|
|
1947
|
+
setStatus("connecting");
|
|
1948
|
+
ws = new WebSocket(wsUrl);
|
|
1949
|
+
|
|
1950
|
+
ws.onopen = function () {
|
|
1951
|
+
isConnecting = false;
|
|
1952
|
+
reconnectAttempts = 0;
|
|
1953
|
+
if (reconnectTimer) {
|
|
1954
|
+
clearTimeout(reconnectTimer);
|
|
1955
|
+
reconnectTimer = null;
|
|
1956
|
+
}
|
|
1957
|
+
setStatus("connected");
|
|
1958
|
+
refreshAll();
|
|
1959
|
+
};
|
|
1960
|
+
|
|
1961
|
+
ws.onclose = function () {
|
|
1962
|
+
isConnecting = false;
|
|
1963
|
+
setStatus("disconnected");
|
|
1964
|
+
scheduleReconnect();
|
|
1965
|
+
};
|
|
1966
|
+
|
|
1967
|
+
ws.onerror = function () {
|
|
1968
|
+
ws.close();
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
ws.onmessage = function (event) {
|
|
1972
|
+
try {
|
|
1973
|
+
const msg = JSON.parse(event.data);
|
|
1974
|
+
handleWsEvent(msg);
|
|
1975
|
+
} catch (_err) {
|
|
1976
|
+
console.error("Invalid WS message:", event.data);
|
|
1977
|
+
}
|
|
1978
|
+
};
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
function scheduleReconnect() {
|
|
1982
|
+
if (reconnectTimer || isConnecting) {
|
|
1983
|
+
return;
|
|
1984
|
+
}
|
|
1985
|
+
reconnectAttempts += 1;
|
|
1986
|
+
const delay = Math.min(10000, 1000 * Math.max(1, reconnectAttempts));
|
|
1987
|
+
reconnectTimer = window.setTimeout(function () {
|
|
1988
|
+
reconnectTimer = null;
|
|
1989
|
+
connectWebSocket();
|
|
1990
|
+
}, delay);
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
function setStatus(status) {
|
|
1994
|
+
const dot = $("#connection-status");
|
|
1995
|
+
if (dot) {
|
|
1996
|
+
dot.className = "status-dot " + status;
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
/* function renmderRuntimeAlert(modelReadiness) keeps the legacy marker: TeamClaw is installed but cannot work yet. */
|
|
2001
|
+
function renderRuntimeAlert() {
|
|
2002
|
+
var alertEl = $("#runtime-alert");
|
|
2003
|
+
if (!alertEl) return;
|
|
2004
|
+
var readiness = teamState.modelReadiness;
|
|
2005
|
+
if (!readiness || readiness.status === "ready") {
|
|
2006
|
+
alertEl.classList.add("hidden");
|
|
2007
|
+
alertEl.innerHTML = "";
|
|
2008
|
+
return;
|
|
2009
|
+
}
|
|
2010
|
+
var detailBits = [];
|
|
2011
|
+
if (!readiness.hasConfiguredModel) {
|
|
2012
|
+
detailBits.push(t("runtime.noModel"));
|
|
2013
|
+
}
|
|
2014
|
+
if (!readiness.hasAuthProfiles) {
|
|
2015
|
+
detailBits.push(t("runtime.noAuth"));
|
|
2016
|
+
}
|
|
2017
|
+
alertEl.classList.remove("hidden");
|
|
2018
|
+
alertEl.innerHTML = (
|
|
2019
|
+
"<strong>" + escapeHtml(t("runtime.title")) + "</strong> " +
|
|
2020
|
+
escapeHtml(readiness.message || detailBits.join(" ")) +
|
|
2021
|
+
(detailBits.length ? (" " + escapeHtml(detailBits.join(" "))) : "")
|
|
2022
|
+
);
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
function renderExternalWorkerInstallToggle() {
|
|
2026
|
+
var button = $("#worker-install-toggle");
|
|
2027
|
+
if (!button) return;
|
|
2028
|
+
var available = Boolean(teamState.externalWorkerInstall);
|
|
2029
|
+
button.hidden = !available;
|
|
2030
|
+
button.disabled = !available;
|
|
2031
|
+
button.textContent = externalWorkerInstallVisible ? t("worker.hide") : t("worker.add");
|
|
2032
|
+
// Source-contract note: keep the legacy English marker after externalWorkerInstallVisible: Add worker.
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
function buildExternalWorkerCommand(info, roleId, discoveryMode) {
|
|
2036
|
+
if (!info || !roleId) return "";
|
|
2037
|
+
var prefix = discoveryMode === "manual" ? (info.manualCommandPrefix || "") : (info.autoDiscoveryCommandPrefix || "");
|
|
2038
|
+
var suffix = discoveryMode === "manual" ? (info.manualControllerUrlFlag || "") : "";
|
|
2039
|
+
return (prefix + roleId + suffix).trim();
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
function renderExternalWorkerInstallCard() {
|
|
2043
|
+
// Source-contract note: keep the legacy English markers "Register a new external worker" and "Copy command".
|
|
2044
|
+
var card = $("#external-worker-install");
|
|
2045
|
+
if (!card) return;
|
|
2046
|
+
var info = teamState.externalWorkerInstall;
|
|
2047
|
+
if (!info || !externalWorkerInstallVisible) {
|
|
2048
|
+
card.classList.add("hidden");
|
|
2049
|
+
return;
|
|
2050
|
+
}
|
|
2051
|
+
var roles = Array.isArray(info.roles) ? info.roles : [];
|
|
2052
|
+
if (!roles.length) {
|
|
2053
|
+
card.classList.add("hidden");
|
|
2054
|
+
card.innerHTML = "";
|
|
2055
|
+
return;
|
|
2056
|
+
}
|
|
2057
|
+
if (!roles.some(function (role) { return role.id === selectedExternalWorkerRole; })) {
|
|
2058
|
+
selectedExternalWorkerRole = roles[0].id;
|
|
2059
|
+
}
|
|
2060
|
+
if (selectedExternalWorkerDiscoveryMode === "manual" && !info.recommendedControllerUrl) {
|
|
2061
|
+
selectedExternalWorkerDiscoveryMode = "mdns";
|
|
2062
|
+
}
|
|
2063
|
+
var roleOptions = roles.map(function (role) {
|
|
2064
|
+
return '<option value="' + escapeHtml(role.id) + '"' + (role.id === selectedExternalWorkerRole ? " selected" : "") + ">" +
|
|
2065
|
+
escapeHtml((role.icon ? role.icon + " " : "") + (role.label || role.id)) +
|
|
2066
|
+
"</option>";
|
|
2067
|
+
}).join("");
|
|
2068
|
+
var command = buildExternalWorkerCommand(info, selectedExternalWorkerRole, selectedExternalWorkerDiscoveryMode);
|
|
2069
|
+
var discoveryOptions = [
|
|
2070
|
+
'<option value="mdns"' + (selectedExternalWorkerDiscoveryMode === "mdns" ? " selected" : "") + ">" + escapeHtml(t("worker.discoveryMdns")) + "</option>",
|
|
2071
|
+
'<option value="manual"' + (selectedExternalWorkerDiscoveryMode === "manual" ? " selected" : "") + (info.recommendedControllerUrl ? "" : " disabled") + ">" + escapeHtml(t("worker.discoveryManual")) + "</option>",
|
|
2072
|
+
].join("");
|
|
2073
|
+
var note = selectedExternalWorkerDiscoveryMode === "manual"
|
|
2074
|
+
? (info.manualControllerWarning || "")
|
|
2075
|
+
: (info.autoDiscoveryWarning || "");
|
|
2076
|
+
var manualDetail = selectedExternalWorkerDiscoveryMode === "manual" && info.recommendedControllerUrl
|
|
2077
|
+
? '<div class="worker-install-note">' + escapeHtml(t("worker.recommendedUrl")) + '<code>' + escapeHtml(info.recommendedControllerUrl) + "</code></div>"
|
|
2078
|
+
: "";
|
|
2079
|
+
card.classList.remove("hidden");
|
|
2080
|
+
card.innerHTML = (
|
|
2081
|
+
'<div class="worker-install-head">' +
|
|
2082
|
+
'<div>' +
|
|
2083
|
+
"<h3>" + escapeHtml(t("worker.cardTitle")) + "</h3>" +
|
|
2084
|
+
'<div class="worker-install-subtitle">' + escapeHtml(t("worker.cardSubtitle")) + "</div>" +
|
|
2085
|
+
"</div>" +
|
|
2086
|
+
'<button type="button" class="worker-install-copy" data-worker-install-copy="true">' + escapeHtml(t("action.copyCommand")) + "</button>" +
|
|
2087
|
+
"</div>" +
|
|
2088
|
+
'<div class="worker-install-controls">' +
|
|
2089
|
+
'<div class="worker-install-field">' +
|
|
2090
|
+
'<label for="worker-install-role">' + escapeHtml(t("worker.role")) + "</label>" +
|
|
2091
|
+
'<select id="worker-install-role" data-worker-install-role="true">' + roleOptions + "</select>" +
|
|
2092
|
+
"</div>" +
|
|
2093
|
+
'<div class="worker-install-field">' +
|
|
2094
|
+
'<label for="worker-install-discovery">' + escapeHtml(t("worker.discovery")) + "</label>" +
|
|
2095
|
+
'<select id="worker-install-discovery" data-worker-install-discovery="true">' + discoveryOptions + "</select>" +
|
|
2096
|
+
"</div>" +
|
|
2097
|
+
"</div>" +
|
|
2098
|
+
'<pre class="worker-install-command"><code>' + escapeHtml(command) + "</code></pre>" +
|
|
2099
|
+
manualDetail +
|
|
2100
|
+
'<div class="worker-install-note' + (selectedExternalWorkerDiscoveryMode === "manual" ? " warning" : "") + '">' + escapeHtml(note) + "</div>"
|
|
2101
|
+
);
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
function renderActivitySignals() {
|
|
2105
|
+
var planningCount = activePlanningRunCount();
|
|
2106
|
+
var taskActive = activeTaskCount();
|
|
2107
|
+
var taskBlocked = blockedTaskCount();
|
|
2108
|
+
var clarificationCount = pendingClarifications().length;
|
|
2109
|
+
|
|
2110
|
+
var planningBadge = $("#planning-tab-count");
|
|
2111
|
+
var tasksBadge = $("#tasks-tab-count");
|
|
2112
|
+
var clarificationsBadge = $("#clarifications-tab-count");
|
|
2113
|
+
var planningSignal = $("#planning-tab-signal");
|
|
2114
|
+
var tasksSignal = $("#tasks-tab-signal");
|
|
2115
|
+
var clarificationsSignal = $("#clarifications-tab-signal");
|
|
2116
|
+
var planningTab = $('[data-tab="planning"]');
|
|
2117
|
+
var tasksTab = $('[data-tab="tasks"]');
|
|
2118
|
+
var clarificationsTab = $('[data-tab="clarifications"]');
|
|
2119
|
+
|
|
2120
|
+
if (planningBadge) {
|
|
2121
|
+
planningBadge.textContent = String(planningCount);
|
|
2122
|
+
planningBadge.className = "tab-badge" + (planningCount > 0 ? " tone-active" : "");
|
|
2123
|
+
planningBadge.style.display = planningCount > 0 ? "" : "none";
|
|
2124
|
+
}
|
|
2125
|
+
if (tasksBadge) {
|
|
2126
|
+
var taskCount = taskBlocked > 0 ? taskBlocked : taskActive;
|
|
2127
|
+
tasksBadge.textContent = String(taskCount);
|
|
2128
|
+
tasksBadge.className = "tab-badge" + (taskBlocked > 0 ? " tone-attention" : taskActive > 0 ? " tone-active" : "");
|
|
2129
|
+
tasksBadge.style.display = taskCount > 0 ? "" : "none";
|
|
2130
|
+
}
|
|
2131
|
+
if (clarificationsBadge) {
|
|
2132
|
+
clarificationsBadge.textContent = String(clarificationCount);
|
|
2133
|
+
clarificationsBadge.className = "tab-badge" + (clarificationCount > 0 ? " tone-attention" : "");
|
|
2134
|
+
clarificationsBadge.style.display = clarificationCount > 0 ? "" : "none";
|
|
2135
|
+
}
|
|
2136
|
+
if (planningSignal) {
|
|
2137
|
+
planningSignal.className = "tab-signal" + (planningCount > 0 ? " tone-active" : "");
|
|
2138
|
+
}
|
|
2139
|
+
if (tasksSignal) {
|
|
2140
|
+
tasksSignal.className = "tab-signal" + (taskBlocked > 0 ? " tone-attention" : taskActive > 0 ? " tone-active" : "");
|
|
2141
|
+
}
|
|
2142
|
+
if (clarificationsSignal) {
|
|
2143
|
+
clarificationsSignal.className = "tab-signal" + (clarificationCount > 0 ? " tone-attention" : "");
|
|
2144
|
+
}
|
|
2145
|
+
if (planningTab) {
|
|
2146
|
+
planningTab.classList.toggle("has-active", planningCount > 0);
|
|
2147
|
+
planningTab.classList.toggle("has-attention", false);
|
|
2148
|
+
}
|
|
2149
|
+
if (tasksTab) {
|
|
2150
|
+
tasksTab.classList.toggle("has-active", taskActive > 0);
|
|
2151
|
+
tasksTab.classList.toggle("has-attention", taskBlocked > 0);
|
|
2152
|
+
}
|
|
2153
|
+
if (clarificationsTab) {
|
|
2154
|
+
clarificationsTab.classList.toggle("has-active", false);
|
|
2155
|
+
clarificationsTab.classList.toggle("has-attention", clarificationCount > 0);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
function syncClarificationPrompt(options) {
|
|
2160
|
+
var pending = pendingClarifications();
|
|
2161
|
+
dismissedClarificationIds = dismissedClarificationIds.filter(function (id) {
|
|
2162
|
+
return pending.some(function (item) { return item.id === id; });
|
|
2163
|
+
});
|
|
2164
|
+
|
|
2165
|
+
if (pending.length === 0) {
|
|
2166
|
+
clarificationPromptOpen = false;
|
|
2167
|
+
activeClarificationId = null;
|
|
2168
|
+
renderClarificationPrompt();
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
var active = pending.find(function (item) { return item.id === activeClarificationId; });
|
|
2173
|
+
if (!active) {
|
|
2174
|
+
active = pending.find(function (item) { return dismissedClarificationIds.indexOf(item.id) === -1; }) || pending[0];
|
|
2175
|
+
activeClarificationId = active ? active.id : null;
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
if (!clarificationPromptOpen && active && dismissedClarificationIds.indexOf(active.id) === -1) {
|
|
2179
|
+
clarificationPromptOpen = true;
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
if (options && options.forceOpen && active) {
|
|
2183
|
+
clarificationPromptOpen = true;
|
|
2184
|
+
activeClarificationId = active.id;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
renderClarificationPrompt();
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
function renderClarificationPrompt() {
|
|
2191
|
+
var modal = $("#clarification-prompt-modal");
|
|
2192
|
+
var body = $("#clarification-prompt-body");
|
|
2193
|
+
if (!modal || !body) return;
|
|
2194
|
+
|
|
2195
|
+
var pending = pendingClarifications();
|
|
2196
|
+
var active = pending.find(function (item) { return item.id === activeClarificationId; });
|
|
2197
|
+
if (!clarificationPromptOpen || !active) {
|
|
2198
|
+
modal.classList.remove("open");
|
|
2199
|
+
modal.setAttribute("aria-hidden", "true");
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
|
|
2203
|
+
modal.classList.add("open");
|
|
2204
|
+
modal.setAttribute("aria-hidden", "false");
|
|
2205
|
+
body.innerHTML = renderClarificationCards([active], { compact: false, linkToTask: true });
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
function handleWsEvent(event) {
|
|
2209
|
+
const taskId = event && event.data
|
|
2210
|
+
? (event.data.taskId || event.data.id || null)
|
|
2211
|
+
: null;
|
|
2212
|
+
|
|
2213
|
+
switch (event.type) {
|
|
2214
|
+
case "controller:run":
|
|
2215
|
+
handleControllerRunEvent(event.data || {});
|
|
2216
|
+
break;
|
|
2217
|
+
case "task:execution":
|
|
2218
|
+
handleTaskExecutionEvent(event.data || {});
|
|
2219
|
+
break;
|
|
2220
|
+
case "worker:online":
|
|
2221
|
+
refreshAll();
|
|
2222
|
+
showNotice("worker:online", "info", t("toast.workerOnline"), workerEventLabel(event.data));
|
|
2223
|
+
break;
|
|
2224
|
+
case "worker:offline":
|
|
2225
|
+
refreshAll();
|
|
2226
|
+
showNotice("worker:offline", "info", t("toast.workerOffline"), workerEventLabel(event.data));
|
|
2227
|
+
break;
|
|
2228
|
+
case "task:created":
|
|
2229
|
+
refreshAll();
|
|
2230
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2231
|
+
refreshTaskDetail(true);
|
|
2232
|
+
}
|
|
2233
|
+
showNotice("task:created", "info", t("toast.taskCreated"), (event.data || {}).title || taskId || "");
|
|
2234
|
+
break;
|
|
2235
|
+
case "task:updated":
|
|
2236
|
+
refreshAll();
|
|
2237
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2238
|
+
refreshTaskDetail(true);
|
|
2239
|
+
}
|
|
2240
|
+
showNotice("task:updated", "info", t("toast.taskUpdated"), (event.data || {}).title || taskId || "");
|
|
2241
|
+
break;
|
|
2242
|
+
case "message:new":
|
|
2243
|
+
refreshAll();
|
|
2244
|
+
showNotice("message:new", "info", t("toast.messageNew"), messageEventLabel(event.data));
|
|
2245
|
+
break;
|
|
2246
|
+
case "task:completed": {
|
|
2247
|
+
refreshAll();
|
|
2248
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2249
|
+
refreshTaskDetail(true);
|
|
2250
|
+
}
|
|
2251
|
+
const doneData = event.data || {};
|
|
2252
|
+
const doneStatus = String(doneData.status || "").toLowerCase();
|
|
2253
|
+
const doneFailed = doneStatus === "failed" || doneStatus === "blocked";
|
|
2254
|
+
showNotice("task:completed", doneFailed ? "attention" : "success",
|
|
2255
|
+
t(doneFailed ? "toast.taskFailed" : "toast.taskCompleted"),
|
|
2256
|
+
doneData.title || taskId || "");
|
|
2257
|
+
break;
|
|
2258
|
+
}
|
|
2259
|
+
case "clarification:requested":
|
|
2260
|
+
refreshAll();
|
|
2261
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2262
|
+
refreshTaskDetail(true);
|
|
2263
|
+
}
|
|
2264
|
+
showNotice("clarification:requested", "attention", t("toast.clarificationRequested"), (event.data || {}).question || taskId || "");
|
|
2265
|
+
break;
|
|
2266
|
+
case "clarification:answered":
|
|
2267
|
+
refreshAll();
|
|
2268
|
+
if (selectedTaskId && taskId && taskId === selectedTaskId) {
|
|
2269
|
+
refreshTaskDetail(true);
|
|
2270
|
+
}
|
|
2271
|
+
showNotice("clarification:answered", "info", t("toast.clarificationAnswered"), (event.data || {}).question || taskId || "");
|
|
2272
|
+
break;
|
|
2273
|
+
case "teamauto:activity": {
|
|
2274
|
+
const entry = event.data || {};
|
|
2275
|
+
const kindId = "teamauto:activity:" + String(entry.kind || "activity");
|
|
2276
|
+
if (toastEnabled("teamauto:activity") && toastEnabled(kindId)) {
|
|
2277
|
+
showNotice(kindId, "info", t("toast.teamautoPrefix") + " - " + String(entry.kind || "activity"),
|
|
2278
|
+
String(entry.repoId || "") + (entry.text ? " - " + String(entry.text) : ""));
|
|
2279
|
+
}
|
|
2280
|
+
break;
|
|
2281
|
+
}
|
|
2282
|
+
case "report:ready":
|
|
2283
|
+
handleReportReady(event.data || {});
|
|
2284
|
+
break;
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
function handleReportReady(data) {
|
|
2289
|
+
const reportUrl = data.reportUrl;
|
|
2290
|
+
const projectName = data.projectName || "Project";
|
|
2291
|
+
const status = data.status || "completed";
|
|
2292
|
+
const icon = status === "completed" ? "✅" : status === "partial" ? "⚠️" : "❌";
|
|
2293
|
+
|
|
2294
|
+
// Create toast notification
|
|
2295
|
+
let container = document.getElementById("toast-container");
|
|
2296
|
+
if (!container) {
|
|
2297
|
+
container = document.createElement("div");
|
|
2298
|
+
container.id = "toast-container";
|
|
2299
|
+
container.style.cssText = "position:fixed;top:16px;right:16px;z-index:10000;display:flex;flex-direction:column;gap:8px;";
|
|
2300
|
+
document.body.appendChild(container);
|
|
2301
|
+
}
|
|
2302
|
+
|
|
2303
|
+
const toast = document.createElement("div");
|
|
2304
|
+
toast.style.cssText = "background:#1a365d;color:#fff;padding:14px 20px;border-radius:10px;"
|
|
2305
|
+
+ "box-shadow:0 8px 24px rgba(0,0,0,.2);font-size:14px;max-width:380px;"
|
|
2306
|
+
+ "animation:slideIn .3s ease;cursor:pointer;display:flex;flex-direction:column;gap:6px;";
|
|
2307
|
+
toast.innerHTML = '<div style="font-weight:600;">' + icon + " Delivery Report Ready</div>"
|
|
2308
|
+
+ '<div style="opacity:.85;font-size:13px;">' + escapeHtmlInline(projectName) + " — " + status + "</div>"
|
|
2309
|
+
+ '<div style="font-size:12px;opacity:.7;">Click to open report</div>';
|
|
2310
|
+
toast.onclick = function () {
|
|
2311
|
+
if (reportUrl) window.open(reportUrl, "_blank");
|
|
2312
|
+
toast.remove();
|
|
2313
|
+
};
|
|
2314
|
+
|
|
2315
|
+
container.appendChild(toast);
|
|
2316
|
+
setTimeout(function () { toast.style.opacity = "0"; toast.style.transition = "opacity .5s"; }, 8000);
|
|
2317
|
+
setTimeout(function () { toast.remove(); }, 8500);
|
|
2318
|
+
|
|
2319
|
+
// Add animation keyframes if not already present
|
|
2320
|
+
if (!document.getElementById("toast-anim-style")) {
|
|
2321
|
+
const style = document.createElement("style");
|
|
2322
|
+
style.id = "toast-anim-style";
|
|
2323
|
+
style.textContent = "@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }";
|
|
2324
|
+
document.head.appendChild(style);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
function escapeHtmlInline(str) {
|
|
2329
|
+
return String(str).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
async function refreshAll() {
|
|
2333
|
+
try {
|
|
2334
|
+
const statusRes = await apiGet("/team/status");
|
|
2335
|
+
let rolesRes = { roles: [] };
|
|
2336
|
+
try {
|
|
2337
|
+
rolesRes = await apiGet("/roles");
|
|
2338
|
+
} catch (rolesErr) {
|
|
2339
|
+
console.error("Failed to load roles:", rolesErr);
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2342
|
+
teamState = {
|
|
2343
|
+
workers: statusRes.workers || [],
|
|
2344
|
+
tasks: statusRes.tasks || [],
|
|
2345
|
+
controllerRuns: statusRes.controllerRuns || [],
|
|
2346
|
+
messages: statusRes.messages || [],
|
|
2347
|
+
clarifications: statusRes.clarifications || [],
|
|
2348
|
+
modelReadiness: statusRes.modelReadiness || null,
|
|
2349
|
+
externalWorkerInstall: statusRes.externalWorkerInstall || null,
|
|
2350
|
+
};
|
|
2351
|
+
|
|
2352
|
+
renderWorkers(teamState.workers);
|
|
2353
|
+
renderTasks(teamState.tasks);
|
|
2354
|
+
renderPlanningTab(teamState.controllerRuns);
|
|
2355
|
+
renderControllerRuns(teamState.controllerRuns);
|
|
2356
|
+
renderClarifications(teamState.clarifications);
|
|
2357
|
+
renderMessages(teamState.messages);
|
|
2358
|
+
renderRoles(rolesRes.roles || []);
|
|
2359
|
+
renderRuntimeAlert();
|
|
2360
|
+
renderExternalWorkerInstallToggle();
|
|
2361
|
+
renderExternalWorkerInstallCard();
|
|
2362
|
+
renderActivitySignals();
|
|
2363
|
+
syncClarificationPrompt();
|
|
2364
|
+
|
|
2365
|
+
const teamName = $("#team-name");
|
|
2366
|
+
if (teamName) {
|
|
2367
|
+
teamName.textContent = statusRes.teamName || "Team";
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
syncSelectedTaskSummary();
|
|
2371
|
+
if (activeTab === "workspace") {
|
|
2372
|
+
await refreshWorkspaceTree(true);
|
|
2373
|
+
}
|
|
2374
|
+
} catch (err) {
|
|
2375
|
+
console.error("Failed to refresh:", err);
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
function renderWorkers(workers) {
|
|
2380
|
+
const container = $("#workers-list");
|
|
2381
|
+
if (!container) return;
|
|
2382
|
+
|
|
2383
|
+
if (workers.length === 0) {
|
|
2384
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noWorkers")) + "</div>";
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
container.innerHTML = workers.map(function (worker) {
|
|
2389
|
+
var staleBadge = worker.staleRemovable
|
|
2390
|
+
? '<span class="worker-status stale" title="Ghost record from a previous gateway process">stale</span>'
|
|
2391
|
+
: "";
|
|
2392
|
+
return (
|
|
2393
|
+
'<div class="worker-card' + (worker.staleRemovable ? " worker-card-stale" : "") + '" data-worker-id="' + escapeHtml(worker.id) + '">' +
|
|
2394
|
+
' <span class="worker-icon">' + escapeHtml(worker.label || worker.role).charAt(0) + '</span>' +
|
|
2395
|
+
' <span class="worker-label">' + escapeHtml(worker.label || worker.role) + '</span>' +
|
|
2396
|
+
' <span class="worker-status ' + escapeHtml(worker.status || "offline") + '">' + escapeHtml(worker.status || "offline") + "</span>" +
|
|
2397
|
+
staleBadge +
|
|
2398
|
+
(worker.staleRemovable
|
|
2399
|
+
? '<button class="btn btn-small worker-remove-btn" type="button" data-remove-worker="' + escapeHtml(worker.id) + '">Remove</button>'
|
|
2400
|
+
: "") +
|
|
2401
|
+
"</div>"
|
|
2402
|
+
);
|
|
2403
|
+
}).join("");
|
|
2404
|
+
|
|
2405
|
+
container.querySelectorAll("[data-remove-worker]").forEach(function (btn) {
|
|
2406
|
+
btn.addEventListener("click", function () {
|
|
2407
|
+
var workerId = btn.getAttribute("data-remove-worker");
|
|
2408
|
+
if (!workerId) return;
|
|
2409
|
+
btn.disabled = true;
|
|
2410
|
+
apiRequest("/workers/" + encodeURIComponent(workerId), { method: "DELETE" })
|
|
2411
|
+
.then(function () {
|
|
2412
|
+
showError("Removed stale worker record " + workerId);
|
|
2413
|
+
refreshAll();
|
|
2414
|
+
})
|
|
2415
|
+
.catch(function (err) { showError(err instanceof Error ? err.message : "Failed to remove worker"); btn.disabled = false; });
|
|
2416
|
+
});
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
const TERMINAL_STATUSES = { completed: true, failed: true };
|
|
2421
|
+
const PRIORITY_WEIGHT = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
2422
|
+
|
|
2423
|
+
function taskComparator(left, right) {
|
|
2424
|
+
const terminalL = TERMINAL_STATUSES[left.status] ? 1 : 0;
|
|
2425
|
+
const terminalR = TERMINAL_STATUSES[right.status] ? 1 : 0;
|
|
2426
|
+
if (terminalL !== terminalR) { return terminalL - terminalR; }
|
|
2427
|
+
const prioL = PRIORITY_WEIGHT[left.priority || "medium"] ?? 2;
|
|
2428
|
+
const prioR = PRIORITY_WEIGHT[right.priority || "medium"] ?? 2;
|
|
2429
|
+
if (prioL !== prioR) { return prioL - prioR; }
|
|
2430
|
+
return (right.updatedAt || 0) - (left.updatedAt || 0);
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2433
|
+
function taskMatchesKeyword(task, keyword) {
|
|
2434
|
+
if (!keyword) { return true; }
|
|
2435
|
+
const haystack = [task.id, task.title, task.description, task.assignedRole, task.createdBy, task.assignedWorkerId]
|
|
2436
|
+
.filter(Boolean).join(" ").toLowerCase();
|
|
2437
|
+
return haystack.includes(keyword);
|
|
2438
|
+
}
|
|
2439
|
+
|
|
2440
|
+
function renderTasks(tasks) {
|
|
2441
|
+
const container = $("#tasks-board");
|
|
2442
|
+
if (!container) return;
|
|
2443
|
+
|
|
2444
|
+
const filtered = (currentFilter === "all"
|
|
2445
|
+
? tasks
|
|
2446
|
+
: tasks.filter(function (task) { return task.status === currentFilter; }))
|
|
2447
|
+
.filter(function (task) { return taskMatchesKeyword(task, taskKeywordFilter); });
|
|
2448
|
+
|
|
2449
|
+
if (filtered.length === 0) {
|
|
2450
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(
|
|
2451
|
+
taskKeywordFilter
|
|
2452
|
+
? t("tasks.noMatch")
|
|
2453
|
+
: currentFilter !== "all"
|
|
2454
|
+
? t("empty.noTasksWithStatus", { status: currentFilter })
|
|
2455
|
+
: t("empty.noTasks")
|
|
2456
|
+
) + "</div>";
|
|
2457
|
+
return;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
const sorted = filtered.slice().sort(taskComparator);
|
|
2461
|
+
// Active tasks render in full; terminal ones chunk so long-lived installs
|
|
2462
|
+
// with hundreds of completed tasks stay fast and meaningful.
|
|
2463
|
+
const activeTasks = sorted.filter(function (task) { return !TERMINAL_STATUSES[task.status]; });
|
|
2464
|
+
const terminalTasks = sorted.filter(function (task) { return TERMINAL_STATUSES[task.status]; });
|
|
2465
|
+
const visibleTerminal = terminalTasks.slice(0, terminalTasksVisible);
|
|
2466
|
+
const hiddenTerminal = terminalTasks.length - visibleTerminal.length;
|
|
2467
|
+
const visibleList = activeTasks.concat(visibleTerminal);
|
|
2468
|
+
|
|
2469
|
+
const showMoreHtml = hiddenTerminal > 0
|
|
2470
|
+
? '<button id="tasks-show-more" class="btn btn-small tasks-show-more" type="button">' + escapeHtml(t("tasks.showMore", { n: hiddenTerminal })) + "</button>"
|
|
2471
|
+
: "";
|
|
2472
|
+
|
|
2473
|
+
container.innerHTML = visibleList.map(function (task) {
|
|
2474
|
+
const priority = task.priority || "medium";
|
|
2475
|
+
const status = task.status || "pending";
|
|
2476
|
+
const assignee = task.assignedWorkerId
|
|
2477
|
+
? "Assigned to " + task.assignedWorkerId
|
|
2478
|
+
: (task.assignedRole ? "Role: " + task.assignedRole : "Unassigned");
|
|
2479
|
+
const recommendedSkills = normalizeSkillList(task.recommendedSkills);
|
|
2480
|
+
const creatorBadge = task.createdBy
|
|
2481
|
+
? '<span class="task-origin-badge">' + escapeHtml(task.createdBy) + "</span>"
|
|
2482
|
+
: "";
|
|
2483
|
+
const contractSummary = task.resultContract
|
|
2484
|
+
? '<div class="task-contract-summary clamp"><strong>Result:</strong> ' + escapeHtml(task.resultContract.summary || "") + "</div>"
|
|
2485
|
+
: task.lastHandoff
|
|
2486
|
+
? '<div class="task-contract-summary clamp"><strong>Handoff:</strong> ' + escapeHtml(task.lastHandoff.summary || "") + "</div>"
|
|
2487
|
+
: task.progressContract
|
|
2488
|
+
? '<div class="task-contract-summary clamp"><strong>Progress:</strong> ' + escapeHtml(task.progressContract.summary || "") + "</div>"
|
|
2489
|
+
: "";
|
|
2490
|
+
const note = task.progress
|
|
2491
|
+
? '<div class="task-note clamp">' + escapeHtml(task.progress).slice(0, 220) + "</div>"
|
|
2492
|
+
: "";
|
|
2493
|
+
const clarification = task.clarificationRequestId
|
|
2494
|
+
? '<span>Clarification: ' + escapeHtml(task.clarificationRequestId) + "</span>"
|
|
2495
|
+
: "";
|
|
2496
|
+
const liveClass = isTaskLive(task) ? " is-live" : "";
|
|
2497
|
+
|
|
2498
|
+
return (
|
|
2499
|
+
'<div class="task-card' + liveClass + '" data-task-id="' + escapeHtml(task.id) + '" tabindex="0" role="button" aria-label="Open details for ' + escapeHtml(task.title) + '">' +
|
|
2500
|
+
' <span class="task-priority ' + escapeHtml(priority) + '">' + escapeHtml(priority) + "</span>" +
|
|
2501
|
+
' <div class="task-body">' +
|
|
2502
|
+
' <div class="task-title-row"><div class="task-title">' + escapeHtml(task.title) + "</div>" + creatorBadge + "</div>" +
|
|
2503
|
+
(task.description ? '<div class="task-desc clamp">' + escapeHtml(task.description).slice(0, 220) + "</div>" : "") +
|
|
2504
|
+
renderSkillPills(recommendedSkills, "skill-pills task-skill-pills") +
|
|
2505
|
+
contractSummary +
|
|
2506
|
+
note +
|
|
2507
|
+
' <div class="task-meta">' +
|
|
2508
|
+
' <span class="task-status-badge ' + escapeHtml(status) + '">' + escapeHtml(humanizeStatus(status)) + "</span>" +
|
|
2509
|
+
" <span>" + escapeHtml(assignee) + "</span>" +
|
|
2510
|
+
clarification +
|
|
2511
|
+
" <span>" + escapeHtml(formatTime(task.updatedAt)) + "</span>" +
|
|
2512
|
+
" </div>" +
|
|
2513
|
+
" </div>" +
|
|
2514
|
+
"</div>"
|
|
2515
|
+
);
|
|
2516
|
+
}).join("") + showMoreHtml;
|
|
2517
|
+
|
|
2518
|
+
const showMoreBtn = $("#tasks-show-more");
|
|
2519
|
+
if (showMoreBtn) {
|
|
2520
|
+
showMoreBtn.addEventListener("click", function () {
|
|
2521
|
+
terminalTasksVisible += 20;
|
|
2522
|
+
renderTasks(teamState.tasks || []);
|
|
2523
|
+
});
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
function renderControllerRuns(runs) {
|
|
2528
|
+
const container = $("#controller-runs");
|
|
2529
|
+
if (!container) return;
|
|
2530
|
+
|
|
2531
|
+
const recentRuns = (runs || [])
|
|
2532
|
+
.slice()
|
|
2533
|
+
.sort(function (left, right) { return (right.updatedAt || 0) - (left.updatedAt || 0); })
|
|
2534
|
+
.slice(0, 12);
|
|
2535
|
+
|
|
2536
|
+
if (recentRuns.length === 0) {
|
|
2537
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noControllerActivity")) + "</div>";
|
|
2538
|
+
return;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
container.innerHTML = recentRuns.map(function (run) {
|
|
2542
|
+
const execution = run.execution || {};
|
|
2543
|
+
const events = Array.isArray(execution.events) ? execution.events.slice(-5) : [];
|
|
2544
|
+
const status = run.status || execution.status || "pending";
|
|
2545
|
+
const source = run.source === "task_follow_up"
|
|
2546
|
+
? (run.sourceTaskTitle ? "Follow-up after " + run.sourceTaskTitle : "Workflow follow-up")
|
|
2547
|
+
: "Human intake";
|
|
2548
|
+
const createdTasks = Array.isArray(run.createdTaskIds) ? run.createdTaskIds : [];
|
|
2549
|
+
const createdTaskButtons = createdTasks.length > 0
|
|
2550
|
+
? '<div class="controller-run-created-tasks">' + createdTasks.map(function (taskId) {
|
|
2551
|
+
return '<button type="button" class="controller-run-task-link" data-open-task-id="' + escapeHtml(taskId) + '">' + escapeHtml(taskId) + "</button>";
|
|
2552
|
+
}).join("") + "</div>"
|
|
2553
|
+
: "";
|
|
2554
|
+
const manifestBlock = run.manifest
|
|
2555
|
+
? '<div class="controller-run-section"><div class="controller-run-section-title">Manifest</div>' + renderControllerManifestCard(run.manifest) + "</div>"
|
|
2556
|
+
: "";
|
|
2557
|
+
const kickoffBlock = run.manifest && run.manifest.kickoffPlan
|
|
2558
|
+
? renderKickoffMeetingPanel(run.manifest.kickoffPlan)
|
|
2559
|
+
: "";
|
|
2560
|
+
const replyBlock = run.reply
|
|
2561
|
+
? '<div class="controller-run-section"><div class="controller-run-section-title">Reply</div><div class="markdown-body">' + renderMarkdownContent(run.reply) + "</div></div>"
|
|
2562
|
+
: "";
|
|
2563
|
+
const errorBlock = run.error
|
|
2564
|
+
? '<div class="controller-run-section"><div class="controller-run-section-title">Error</div><div class="markdown-body">' + renderMarkdownContent(run.error) + "</div></div>"
|
|
2565
|
+
: "";
|
|
2566
|
+
const eventsBlock = events.length > 0
|
|
2567
|
+
? '<div class="controller-run-events">' + events.map(function (event) {
|
|
2568
|
+
const meta = [event.source || "", formatTime(event.createdAt)].filter(Boolean).join(" • ");
|
|
2569
|
+
return (
|
|
2570
|
+
'<div class="controller-run-event">' +
|
|
2571
|
+
' <div class="controller-run-event-header">' +
|
|
2572
|
+
' <span class="controller-run-event-label">' + escapeHtml(humanizeStatus(event.phase || event.type || "event")) + '</span>' +
|
|
2573
|
+
' <span class="controller-run-event-meta">' + escapeHtml(meta) + "</span>" +
|
|
2574
|
+
" </div>" +
|
|
2575
|
+
' <div class="controller-run-event-body markdown-body">' + renderMarkdownContent(event.message || "") + "</div>" +
|
|
2576
|
+
"</div>"
|
|
2577
|
+
);
|
|
2578
|
+
}).join("") + "</div>"
|
|
2579
|
+
: "";
|
|
2580
|
+
|
|
2581
|
+
return (
|
|
2582
|
+
'<article class="controller-run-card">' +
|
|
2583
|
+
' <div class="controller-run-header">' +
|
|
2584
|
+
' <div class="controller-run-heading">' +
|
|
2585
|
+
' <div class="controller-run-kicker">' + escapeHtml(source) + "</div>" +
|
|
2586
|
+
' <h3>' + escapeHtml(run.title || "Controller run") + "</h3>" +
|
|
2587
|
+
' <div class="controller-run-meta">Session: ' + escapeHtml(run.sessionKey || "—") + ' • Updated: ' + escapeHtml(formatTime(run.updatedAt) || "—") + "</div>" +
|
|
2588
|
+
" </div>" +
|
|
2589
|
+
' <span class="controller-run-status ' + escapeHtml(status) + '">' + escapeHtml(humanizeStatus(status)) + "</span>" +
|
|
2590
|
+
" </div>" +
|
|
2591
|
+
' <div class="controller-run-section"><div class="controller-run-section-title">Request</div><div class="markdown-body">' + renderMarkdownContent(run.request || "") + "</div></div>" +
|
|
2592
|
+
manifestBlock +
|
|
2593
|
+
kickoffBlock +
|
|
2594
|
+
replyBlock +
|
|
2595
|
+
errorBlock +
|
|
2596
|
+
(createdTaskButtons
|
|
2597
|
+
? '<div class="controller-run-section"><div class="controller-run-section-title">Created Tasks</div>' + createdTaskButtons + "</div>"
|
|
2598
|
+
: "") +
|
|
2599
|
+
eventsBlock +
|
|
2600
|
+
"</article>"
|
|
2601
|
+
);
|
|
2602
|
+
}).join("");
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
function syncSelectedTaskSummary() {
|
|
2606
|
+
if (!selectedTaskId || !selectedTaskDetail) {
|
|
2607
|
+
return;
|
|
2608
|
+
}
|
|
2609
|
+
|
|
2610
|
+
const latestTask = getTaskById(selectedTaskId);
|
|
2611
|
+
if (!latestTask) {
|
|
2612
|
+
closeTaskDetail();
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
const existingExecution = getSelectedTaskExecution();
|
|
2617
|
+
const mergedExecution = Object.assign({}, existingExecution, latestTask.execution || {});
|
|
2618
|
+
if (existingExecution.events) {
|
|
2619
|
+
mergedExecution.events = existingExecution.events;
|
|
2620
|
+
}
|
|
2621
|
+
selectedTaskDetail.task = Object.assign({}, selectedTaskDetail.task || {}, latestTask, {
|
|
2622
|
+
execution: mergedExecution,
|
|
2623
|
+
});
|
|
2624
|
+
renderTaskDetail();
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
async function openTaskDetail(taskId) {
|
|
2628
|
+
selectedTaskId = taskId;
|
|
2629
|
+
selectedTaskDetailTab = "details";
|
|
2630
|
+
taskTimelineAutoFollow = true;
|
|
2631
|
+
selectedTaskDetail = {
|
|
2632
|
+
task: getTaskById(taskId),
|
|
2633
|
+
messages: [],
|
|
2634
|
+
clarifications: [],
|
|
2635
|
+
};
|
|
2636
|
+
const modal = $("#task-detail-modal");
|
|
2637
|
+
if (modal) {
|
|
2638
|
+
modal.classList.add("open");
|
|
2639
|
+
modal.setAttribute("aria-hidden", "false");
|
|
2640
|
+
}
|
|
2641
|
+
renderTaskDetail();
|
|
2642
|
+
await refreshTaskDetail(false);
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
function closeTaskDetail() {
|
|
2646
|
+
selectedTaskId = null;
|
|
2647
|
+
selectedTaskDetail = null;
|
|
2648
|
+
selectedTaskDetailTab = "details";
|
|
2649
|
+
taskTimelineAutoFollow = true;
|
|
2650
|
+
const modal = $("#task-detail-modal");
|
|
2651
|
+
if (modal) {
|
|
2652
|
+
modal.classList.remove("open");
|
|
2653
|
+
modal.setAttribute("aria-hidden", "true");
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
async function refreshTaskDetail(silent) {
|
|
2658
|
+
if (!selectedTaskId) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
try {
|
|
2663
|
+
const data = await apiGet("/tasks/" + selectedTaskId + "/execution");
|
|
2664
|
+
selectedTaskDetail = {
|
|
2665
|
+
task: data.task || null,
|
|
2666
|
+
messages: data.messages || [],
|
|
2667
|
+
clarifications: data.clarifications || [],
|
|
2668
|
+
};
|
|
2669
|
+
renderTaskDetail();
|
|
2670
|
+
} catch (err) {
|
|
2671
|
+
console.error("Failed to load task detail:", err);
|
|
2672
|
+
if (!silent) {
|
|
2673
|
+
showError(err instanceof Error ? err.message : "Failed to load task detail");
|
|
2674
|
+
}
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
function renderTaskDetail() {
|
|
2679
|
+
const task = selectedTaskDetail && selectedTaskDetail.task ? selectedTaskDetail.task : null;
|
|
2680
|
+
const title = $("#task-detail-title");
|
|
2681
|
+
const subtitle = $("#task-detail-subtitle");
|
|
2682
|
+
const liveBadge = $("#task-detail-live-badge");
|
|
2683
|
+
|
|
2684
|
+
if (title) {
|
|
2685
|
+
title.textContent = task ? task.title : t("empty.selectTask");
|
|
2686
|
+
}
|
|
2687
|
+
if (subtitle) {
|
|
2688
|
+
subtitle.textContent = task
|
|
2689
|
+
? [
|
|
2690
|
+
"Task ID: " + task.id,
|
|
2691
|
+
task.assignedWorkerId ? "Worker: " + task.assignedWorkerId : null,
|
|
2692
|
+
task.assignedRole ? "Role: " + task.assignedRole : null,
|
|
2693
|
+
].filter(Boolean).join(" • ")
|
|
2694
|
+
: "";
|
|
2695
|
+
}
|
|
2696
|
+
if (liveBadge) {
|
|
2697
|
+
const live = isTaskLive(task);
|
|
2698
|
+
liveBadge.textContent = live ? "Live" : (task ? humanizeStatus(task.status) : "Idle");
|
|
2699
|
+
liveBadge.classList.toggle("is-live", live);
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
renderTaskDetailTabCounts(task);
|
|
2703
|
+
renderTaskDetailOverview(task);
|
|
2704
|
+
renderTaskDetailTimeline(task);
|
|
2705
|
+
renderTaskDetailClarifications();
|
|
2706
|
+
renderTaskDetailMessages();
|
|
2707
|
+
syncTaskDetailTab();
|
|
2708
|
+
if (selectedTaskDetailTab === "timeline" && taskTimelineAutoFollow) {
|
|
2709
|
+
requestAnimationFrame(scrollTaskTimelineToBottom);
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
|
|
2713
|
+
function renderTaskDetailOverview(task) {
|
|
2714
|
+
const container = $("#task-detail-details");
|
|
2715
|
+
if (!container) return;
|
|
2716
|
+
|
|
2717
|
+
if (!task) {
|
|
2718
|
+
container.innerHTML = '<div class="task-detail-empty">' + escapeHtml(t("empty.taskDetail")) + "</div>";
|
|
2719
|
+
return;
|
|
2720
|
+
}
|
|
2721
|
+
|
|
2722
|
+
const execution = task.execution || {};
|
|
2723
|
+
const stats = [
|
|
2724
|
+
{ label: "Status", value: humanizeStatus(task.status) },
|
|
2725
|
+
{ label: "Priority", value: task.priority || "medium" },
|
|
2726
|
+
{ label: "Assigned Worker", value: task.assignedWorkerId || "—" },
|
|
2727
|
+
{ label: "Assigned Role", value: task.assignedRole || "—" },
|
|
2728
|
+
{ label: "Created", value: formatTime(task.createdAt) || "—" },
|
|
2729
|
+
{ label: "Updated", value: formatTime(task.updatedAt) || "—" },
|
|
2730
|
+
{ label: "Started", value: formatTime(task.startedAt || execution.startedAt) || "—" },
|
|
2731
|
+
{ label: "Completed", value: formatTime(task.completedAt || execution.endedAt) || "—" },
|
|
2732
|
+
{ label: "Run ID", value: execution.runId || "—" },
|
|
2733
|
+
{ label: "Execution Status", value: execution.status ? humanizeStatus(execution.status) : "—" },
|
|
2734
|
+
{ label: "Events", value: String(execution.eventCount || (execution.events ? execution.events.length : 0) || 0) },
|
|
2735
|
+
{ label: "Created By", value: task.createdBy || "—" },
|
|
2736
|
+
];
|
|
2737
|
+
|
|
2738
|
+
container.innerHTML =
|
|
2739
|
+
'<div class="task-detail-grid">' +
|
|
2740
|
+
stats.map(function (item) {
|
|
2741
|
+
return (
|
|
2742
|
+
'<div class="task-detail-stat">' +
|
|
2743
|
+
' <div class="task-detail-stat-label">' + escapeHtml(item.label) + "</div>" +
|
|
2744
|
+
' <div class="task-detail-stat-value">' + escapeHtml(item.value) + "</div>" +
|
|
2745
|
+
"</div>"
|
|
2746
|
+
);
|
|
2747
|
+
}).join("") +
|
|
2748
|
+
"</div>" +
|
|
2749
|
+
'<div class="task-detail-section">' +
|
|
2750
|
+
" <h3>Description</h3>" +
|
|
2751
|
+
renderMarkdownCard(task.description || "No description") +
|
|
2752
|
+
"</div>" +
|
|
2753
|
+
(normalizeSkillList(task.recommendedSkills).length > 0
|
|
2754
|
+
? '<div class="task-detail-section"><h3>Recommended Skills</h3>' + renderSkillPills(task.recommendedSkills, "skill-pills task-detail-skill-pills") + "</div>"
|
|
2755
|
+
: "") +
|
|
2756
|
+
(task.progress
|
|
2757
|
+
? '<div class="task-detail-section"><h3>Latest Progress</h3>' + renderMarkdownCard(task.progress) + "</div>"
|
|
2758
|
+
: "") +
|
|
2759
|
+
(task.progressContract
|
|
2760
|
+
? '<div class="task-detail-section"><h3>Structured Progress</h3>' + renderProgressContractCard(task.progressContract) + "</div>"
|
|
2761
|
+
: "") +
|
|
2762
|
+
(task.result
|
|
2763
|
+
? '<div class="task-detail-section"><h3>Result</h3>' + renderMarkdownCard(task.result) + "</div>"
|
|
2764
|
+
: "") +
|
|
2765
|
+
(task.resultContract
|
|
2766
|
+
? '<div class="task-detail-section"><h3>Structured Result</h3>' + renderResultContractCard(task.resultContract) + "</div>"
|
|
2767
|
+
: "") +
|
|
2768
|
+
(task.lastHandoff
|
|
2769
|
+
? '<div class="task-detail-section"><h3>Last Handoff</h3>' + renderHandoffContractCard(task.lastHandoff) + "</div>"
|
|
2770
|
+
: "") +
|
|
2771
|
+
(task.error
|
|
2772
|
+
? '<div class="task-detail-section"><h3>Error</h3>' + renderMarkdownCard(task.error) + "</div>"
|
|
2773
|
+
: "");
|
|
2774
|
+
}
|
|
2775
|
+
|
|
2776
|
+
function renderTaskDetailTabCounts(task) {
|
|
2777
|
+
var counts = {
|
|
2778
|
+
details: task ? 1 : 0,
|
|
2779
|
+
timeline: normalizeArray(getSelectedTaskExecution().events).length,
|
|
2780
|
+
clarifications: normalizeArray(selectedTaskDetail && selectedTaskDetail.clarifications).length,
|
|
2781
|
+
messages: normalizeArray(selectedTaskDetail && selectedTaskDetail.messages).length,
|
|
2782
|
+
};
|
|
2783
|
+
$$("[data-task-detail-tab-count]").forEach(function (node) {
|
|
2784
|
+
var name = node.dataset.taskDetailTabCount || "";
|
|
2785
|
+
var count = counts[name] || 0;
|
|
2786
|
+
node.textContent = count > 0 ? String(count) : "";
|
|
2787
|
+
node.className = "task-detail-tab-count" + (count > 0 ? " has-items" : "");
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
function scrollTaskTimelineToBottom() {
|
|
2792
|
+
var container = $("#task-detail-timeline");
|
|
2793
|
+
if (!container) return;
|
|
2794
|
+
container.scrollTop = container.scrollHeight;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
function syncTaskTimelineFollowState() {
|
|
2798
|
+
if (selectedTaskDetailTab !== "timeline") return;
|
|
2799
|
+
var container = $("#task-detail-timeline");
|
|
2800
|
+
if (!container) return;
|
|
2801
|
+
taskTimelineAutoFollow = isNearBottom(container);
|
|
2802
|
+
}
|
|
2803
|
+
|
|
2804
|
+
function renderMessageCards(messages) {
|
|
2805
|
+
return normalizeArray(messages).map(function (message) {
|
|
2806
|
+
const from = message.fromRole || message.from || "unknown";
|
|
2807
|
+
const type = (message.contract && message.contract.intent) || message.type || "direct";
|
|
2808
|
+
const contractBlock = renderTeamMessageContractCard(message.contract);
|
|
2809
|
+
const rawContent = buildMessageDisplayContent(message);
|
|
2810
|
+
const meta = [
|
|
2811
|
+
message.toRole ? ("to " + message.toRole) : null,
|
|
2812
|
+
message.taskId ? ("task " + message.taskId) : null,
|
|
2813
|
+
formatTime(message.createdAt),
|
|
2814
|
+
].filter(Boolean).join(" • ");
|
|
2815
|
+
|
|
2816
|
+
return (
|
|
2817
|
+
'<div class="message-card">' +
|
|
2818
|
+
' <div class="message-header">' +
|
|
2819
|
+
' <span class="message-from">' + escapeHtml(from) + "</span>" +
|
|
2820
|
+
' <span class="message-type ' + escapeHtml(type) + '">' + escapeHtml(humanizeStatus(type)) + "</span>" +
|
|
2821
|
+
" </div>" +
|
|
2822
|
+
(meta ? '<div class="message-meta">' + escapeHtml(meta) + "</div>" : "") +
|
|
2823
|
+
contractBlock +
|
|
2824
|
+
(rawContent ? '<div class="message-content markdown-body">' + rawContent + "</div>" : "") +
|
|
2825
|
+
"</div>"
|
|
2826
|
+
);
|
|
2827
|
+
}).join("");
|
|
2828
|
+
}
|
|
2829
|
+
|
|
2830
|
+
function renderClarificationCards(items, options) {
|
|
2831
|
+
var opts = options || {};
|
|
2832
|
+
return normalizeArray(items).map(function (item) {
|
|
2833
|
+
const status = item.status || "pending";
|
|
2834
|
+
const context = item.context
|
|
2835
|
+
? '<div class="clarification-context"><strong>Context:</strong> ' + escapeHtml(item.context) + "</div>"
|
|
2836
|
+
: "";
|
|
2837
|
+
const taskLink = opts.linkToTask && item.taskId
|
|
2838
|
+
? '<button type="button" class="btn btn-small" data-open-task-id="' + escapeHtml(item.taskId) + '">Open task</button>'
|
|
2839
|
+
: "";
|
|
2840
|
+
const answerBlock = status === "pending"
|
|
2841
|
+
? (
|
|
2842
|
+
'<form class="clarification-answer-form" data-clarification-id="' + escapeHtml(item.id) + '">' +
|
|
2843
|
+
' <label class="clarification-label" for="answer-' + escapeHtml(item.id) + '">Answer as human</label>' +
|
|
2844
|
+
' <textarea id="answer-' + escapeHtml(item.id) + '" name="answer" rows="3" placeholder="Type the exact clarification answer..." required></textarea>' +
|
|
2845
|
+
' <div class="clarification-actions">' +
|
|
2846
|
+
taskLink +
|
|
2847
|
+
' <button type="submit" class="btn btn-primary">Submit Answer</button>' +
|
|
2848
|
+
" </div>" +
|
|
2849
|
+
"</form>"
|
|
2850
|
+
)
|
|
2851
|
+
: (
|
|
2852
|
+
'<div class="clarification-answer">' +
|
|
2853
|
+
' <strong>Answer:</strong> ' + escapeHtml(item.answer || "") +
|
|
2854
|
+
(item.answeredBy ? ' <span class="clarification-answer-meta">(by ' + escapeHtml(item.answeredBy) + ')</span>' : "") +
|
|
2855
|
+
"</div>"
|
|
2856
|
+
);
|
|
2857
|
+
|
|
2858
|
+
return (
|
|
2859
|
+
'<div class="clarification-card' + (opts.compact ? " clarification-card-compact" : "") + '">' +
|
|
2860
|
+
' <div class="clarification-header">' +
|
|
2861
|
+
' <span class="clarification-status ' + escapeHtml(status) + '">' + escapeHtml(humanizeStatus(status)) + "</span>" +
|
|
2862
|
+
' <span class="clarification-time">' + escapeHtml(formatTime(item.updatedAt || item.createdAt)) + "</span>" +
|
|
2863
|
+
" </div>" +
|
|
2864
|
+
' <div class="clarification-question">' + escapeHtml(item.question) + "</div>" +
|
|
2865
|
+
' <div class="clarification-meta">' +
|
|
2866
|
+
' <span><strong>Task:</strong> ' + escapeHtml(item.taskId) + "</span>" +
|
|
2867
|
+
' <span><strong>Role:</strong> ' + escapeHtml(item.requestedByRole || "unknown") + "</span>" +
|
|
2868
|
+
' <span><strong>Requester:</strong> ' + escapeHtml(item.requestedByWorkerId || item.requestedBy || "unknown") + "</span>" +
|
|
2869
|
+
" </div>" +
|
|
2870
|
+
' <div class="clarification-reason"><strong>Blocked because:</strong> ' + escapeHtml(item.blockingReason) + "</div>" +
|
|
2871
|
+
context +
|
|
2872
|
+
answerBlock +
|
|
2873
|
+
"</div>"
|
|
2874
|
+
);
|
|
2875
|
+
}).join("");
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
function renderTaskDetailClarifications() {
|
|
2879
|
+
var container = $("#task-detail-clarifications");
|
|
2880
|
+
if (!container) return;
|
|
2881
|
+
var items = normalizeArray(selectedTaskDetail && selectedTaskDetail.clarifications);
|
|
2882
|
+
if (!items.length) {
|
|
2883
|
+
container.innerHTML = '<div class="task-detail-empty">No clarifications on this task.</div>';
|
|
2884
|
+
return;
|
|
2885
|
+
}
|
|
2886
|
+
container.innerHTML = '<div class="clarifications-list">' + renderClarificationCards(items, { linkToTask: false }) + "</div>";
|
|
2887
|
+
}
|
|
2888
|
+
|
|
2889
|
+
function renderTaskDetailMessages() {
|
|
2890
|
+
var container = $("#task-detail-messages");
|
|
2891
|
+
if (!container) return;
|
|
2892
|
+
var items = normalizeArray(selectedTaskDetail && selectedTaskDetail.messages);
|
|
2893
|
+
if (!items.length) {
|
|
2894
|
+
container.innerHTML = '<div class="task-detail-empty">' + escapeHtml(t("empty.taskMessages")) + "</div>";
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
container.innerHTML = '<div class="messages-feed">' + renderMessageCards(items) + "</div>";
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
function buildTimelineMessageBody(message) {
|
|
2901
|
+
const contractBlock = renderTeamMessageContractCard(message && message.contract);
|
|
2902
|
+
const rawContent = buildMessageDisplayContent(message);
|
|
2903
|
+
return (contractBlock || "") + (rawContent ? '<div class="timeline-raw-markdown markdown-body">' + rawContent + "</div>" : "");
|
|
2904
|
+
}
|
|
2905
|
+
|
|
2906
|
+
function buildTimelineClarificationBody(item) {
|
|
2907
|
+
const answerBlock = item && item.answer
|
|
2908
|
+
? '<div class="timeline-contract-note"><strong>Answer:</strong> ' + renderMarkdownInline(item.answer) + "</div>"
|
|
2909
|
+
: "";
|
|
2910
|
+
const contextBlock = item && item.context
|
|
2911
|
+
? '<div class="timeline-contract-note"><strong>Context:</strong> ' + renderMarkdownInline(item.context) + "</div>"
|
|
2912
|
+
: "";
|
|
2913
|
+
return (
|
|
2914
|
+
'<div class="timeline-contract-note"><strong>Question:</strong> ' + renderMarkdownInline(item.question || "") + "</div>" +
|
|
2915
|
+
'<div class="timeline-contract-note"><strong>Blocking Reason:</strong> ' + renderMarkdownInline(item.blockingReason || "") + "</div>" +
|
|
2916
|
+
contextBlock +
|
|
2917
|
+
answerBlock
|
|
2918
|
+
);
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
function buildTimelineEntries(task) {
|
|
2922
|
+
if (!task || !selectedTaskDetail) {
|
|
2923
|
+
return [];
|
|
2924
|
+
}
|
|
2925
|
+
|
|
2926
|
+
const executionEvents = (getSelectedTaskExecution().events || []).map(function (event) {
|
|
2927
|
+
return {
|
|
2928
|
+
kind: "execution",
|
|
2929
|
+
createdAt: event.createdAt || 0,
|
|
2930
|
+
label: humanizeStatus(event.phase || event.type),
|
|
2931
|
+
meta: [event.source || "execution", event.workerId || event.role || event.stream].filter(Boolean).join(" • "),
|
|
2932
|
+
bodyHtml: renderMarkdownContent(event.message || ""),
|
|
2933
|
+
};
|
|
2934
|
+
});
|
|
2935
|
+
|
|
2936
|
+
const messages = (selectedTaskDetail.messages || []).map(function (message) {
|
|
2937
|
+
return {
|
|
2938
|
+
kind: "message",
|
|
2939
|
+
createdAt: message.createdAt || 0,
|
|
2940
|
+
label: humanizeStatus((message.contract && message.contract.intent) || message.type || "message"),
|
|
2941
|
+
meta: [
|
|
2942
|
+
message.fromRole || message.from || "unknown",
|
|
2943
|
+
message.toRole ? ("to " + message.toRole) : null,
|
|
2944
|
+
message.contract && message.contract.needsResponse ? "response expected" : null,
|
|
2945
|
+
].filter(Boolean).join(" • "),
|
|
2946
|
+
bodyHtml: buildTimelineMessageBody(message),
|
|
2947
|
+
};
|
|
2948
|
+
});
|
|
2949
|
+
|
|
2950
|
+
const clarifications = (selectedTaskDetail.clarifications || []).map(function (item) {
|
|
2951
|
+
return {
|
|
2952
|
+
kind: "clarification",
|
|
2953
|
+
createdAt: item.updatedAt || item.createdAt || 0,
|
|
2954
|
+
label: item.status === "answered" ? "clarification answered" : "clarification requested",
|
|
2955
|
+
meta: [
|
|
2956
|
+
item.requestedByRole || "unknown role",
|
|
2957
|
+
item.requestedByWorkerId || item.requestedBy || null,
|
|
2958
|
+
].filter(Boolean).join(" • "),
|
|
2959
|
+
bodyHtml: buildTimelineClarificationBody(item),
|
|
2960
|
+
};
|
|
2961
|
+
});
|
|
2962
|
+
|
|
2963
|
+
return executionEvents.concat(messages).concat(clarifications).sort(function (left, right) {
|
|
2964
|
+
return (left.createdAt || 0) - (right.createdAt || 0);
|
|
2965
|
+
});
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function renderTaskDetailTimeline(task) {
|
|
2969
|
+
const container = $("#task-detail-timeline");
|
|
2970
|
+
if (!container) return;
|
|
2971
|
+
|
|
2972
|
+
if (!task) {
|
|
2973
|
+
container.innerHTML = '<div class="task-detail-empty">No task selected.</div>';
|
|
2974
|
+
return;
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
const entries = buildTimelineEntries(task);
|
|
2978
|
+
if (entries.length === 0) {
|
|
2979
|
+
container.innerHTML = '<div class="task-detail-empty">' + escapeHtml(t("empty.taskHistory")) + "</div>";
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
container.innerHTML = '<div class="task-detail-timeline">' +
|
|
2984
|
+
entries.map(function (entry) {
|
|
2985
|
+
return (
|
|
2986
|
+
'<article class="timeline-entry ' + escapeHtml(entry.kind) + '">' +
|
|
2987
|
+
' <div class="timeline-entry-header">' +
|
|
2988
|
+
' <div class="timeline-entry-label">' + escapeHtml(entry.label) + "</div>" +
|
|
2989
|
+
' <div class="timeline-entry-meta">' + escapeHtml(formatTime(entry.createdAt)) + "</div>" +
|
|
2990
|
+
" </div>" +
|
|
2991
|
+
(entry.meta ? '<div class="timeline-entry-meta">' + escapeHtml(entry.meta) + "</div>" : "") +
|
|
2992
|
+
' <div class="timeline-entry-body markdown-body">' + (entry.bodyHtml || renderMarkdownContent(entry.body || "")) + "</div>" +
|
|
2993
|
+
"</article>"
|
|
2994
|
+
);
|
|
2995
|
+
}).join("") +
|
|
2996
|
+
"</div>";
|
|
2997
|
+
|
|
2998
|
+
container.onscroll = syncTaskTimelineFollowState;
|
|
2999
|
+
if (taskTimelineAutoFollow) {
|
|
3000
|
+
requestAnimationFrame(scrollTaskTimelineToBottom);
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
function syncTaskDetailTab() {
|
|
3005
|
+
$$(".task-detail-tab").forEach(function (tab) {
|
|
3006
|
+
tab.classList.toggle("active", tab.dataset.taskDetailTab === selectedTaskDetailTab);
|
|
3007
|
+
});
|
|
3008
|
+
["details", "timeline", "clarifications", "messages"].forEach(function (name) {
|
|
3009
|
+
const panel = $("#task-detail-" + name);
|
|
3010
|
+
if (panel) {
|
|
3011
|
+
panel.classList.toggle("active", name === selectedTaskDetailTab);
|
|
3012
|
+
}
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
|
|
3016
|
+
function handleTaskExecutionEvent(payload) {
|
|
3017
|
+
if (!payload || !selectedTaskId || payload.taskId !== selectedTaskId) {
|
|
3018
|
+
return;
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
if (!selectedTaskDetail) {
|
|
3022
|
+
selectedTaskDetail = {
|
|
3023
|
+
task: getTaskById(selectedTaskId),
|
|
3024
|
+
messages: [],
|
|
3025
|
+
clarifications: [],
|
|
3026
|
+
};
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
const task = selectedTaskDetail.task || getTaskById(selectedTaskId) || { id: selectedTaskId };
|
|
3030
|
+
const execution = Object.assign({ events: [] }, task.execution || {}, payload.execution || {});
|
|
3031
|
+
const events = Array.isArray(execution.events) ? execution.events.slice() : [];
|
|
3032
|
+
if (payload.event) {
|
|
3033
|
+
events.push(payload.event);
|
|
3034
|
+
}
|
|
3035
|
+
execution.events = events;
|
|
3036
|
+
task.execution = execution;
|
|
3037
|
+
selectedTaskDetail.task = Object.assign({}, task);
|
|
3038
|
+
|
|
3039
|
+
renderTaskDetail();
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
function handleControllerRunEvent(payload) {
|
|
3043
|
+
if (!payload || !payload.id) {
|
|
3044
|
+
return;
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
const runs = (teamState.controllerRuns || []).slice();
|
|
3048
|
+
const index = runs.findIndex(function (run) { return run.id === payload.id; });
|
|
3049
|
+
if (index === -1) {
|
|
3050
|
+
runs.push(payload);
|
|
3051
|
+
} else {
|
|
3052
|
+
runs[index] = Object.assign({}, runs[index], payload);
|
|
3053
|
+
}
|
|
3054
|
+
teamState.controllerRuns = runs;
|
|
3055
|
+
renderControllerRuns(teamState.controllerRuns);
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
function renderClarifications(clarifications) {
|
|
3059
|
+
const container = $("#clarifications-list");
|
|
3060
|
+
if (!container) return;
|
|
3061
|
+
|
|
3062
|
+
if (clarifications.length === 0) {
|
|
3063
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noClarifications")) + "</div>";
|
|
3064
|
+
return;
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
container.innerHTML = renderClarificationCards(sortClarifications(clarifications), { linkToTask: true });
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
function renderMessages(messages) {
|
|
3071
|
+
const container = $("#messages-feed");
|
|
3072
|
+
if (!container) return;
|
|
3073
|
+
|
|
3074
|
+
const recent = (messages || [])
|
|
3075
|
+
.concat(controllerConversation || [])
|
|
3076
|
+
.sort(function (left, right) {
|
|
3077
|
+
return (right.createdAt || 0) - (left.createdAt || 0);
|
|
3078
|
+
})
|
|
3079
|
+
.slice(0, 50);
|
|
3080
|
+
if (recent.length === 0) {
|
|
3081
|
+
container.innerHTML = '<div class="empty-state">' + escapeHtml(t("empty.noMessages")) + "</div>";
|
|
3082
|
+
return;
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
container.innerHTML = renderMessageCards(recent);
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
function renderRoles(roles) {
|
|
3089
|
+
const container = $("#roles-list");
|
|
3090
|
+
if (!container) return;
|
|
3091
|
+
|
|
3092
|
+
container.innerHTML = roles.map(function (role) {
|
|
3093
|
+
return (
|
|
3094
|
+
'<div class="role-chip">' +
|
|
3095
|
+
" <span>" + escapeHtml(role.icon || "") + "</span>" +
|
|
3096
|
+
" <span>" + escapeHtml(role.label) + "</span>" +
|
|
3097
|
+
"</div>"
|
|
3098
|
+
);
|
|
3099
|
+
}).join("");
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
function tabNameFromHash() {
|
|
3103
|
+
const match = /^#\/tab\/([a-z][a-z0-9-]*)$/i.exec(window.location.hash || "");
|
|
3104
|
+
const name = match ? match[1] : "";
|
|
3105
|
+
if (!name) { return ""; }
|
|
3106
|
+
// $$ returns a NodeList: it has forEach but NOT .some - convert first.
|
|
3107
|
+
const known = Array.from($$(".tab")).some(function (item) { return item.dataset.tab === name; });
|
|
3108
|
+
return known ? name : "";
|
|
3109
|
+
}
|
|
3110
|
+
|
|
3111
|
+
function syncTabHash(tab) {
|
|
3112
|
+
try {
|
|
3113
|
+
const target = "#/tab/" + tab;
|
|
3114
|
+
if (window.location.hash !== target) {
|
|
3115
|
+
window.history.replaceState(null, "", target);
|
|
3116
|
+
}
|
|
3117
|
+
} catch (_err) {
|
|
3118
|
+
// Embedded/non-browser hosts without history API - hash is best-effort.
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
|
|
3122
|
+
function activateTab(nextTab) {
|
|
3123
|
+
activeTab = nextTab || "tasks";
|
|
3124
|
+
$$(".tab").forEach(function (item) {
|
|
3125
|
+
item.classList.toggle("active", item.dataset.tab === activeTab);
|
|
3126
|
+
});
|
|
3127
|
+
syncTabHash(activeTab);
|
|
3128
|
+
$$(".tab-panel").forEach(function (panel) { panel.classList.remove("active"); });
|
|
3129
|
+
const panel = $("#tab-" + activeTab);
|
|
3130
|
+
if (panel) {
|
|
3131
|
+
panel.classList.add("active");
|
|
3132
|
+
}
|
|
3133
|
+
if (activeTab === "workspace") {
|
|
3134
|
+
refreshWorkspaceTree(false);
|
|
3135
|
+
}
|
|
3136
|
+
if (activeTab === "teamauto") {
|
|
3137
|
+
refreshTeamAutoTab();
|
|
3138
|
+
}
|
|
3139
|
+
renderActivitySignals();
|
|
3140
|
+
}
|
|
3141
|
+
|
|
3142
|
+
$$(".tab").forEach(function (tab) {
|
|
3143
|
+
tab.addEventListener("click", function () {
|
|
3144
|
+
activateTab(tab.dataset.tab || "tasks");
|
|
3145
|
+
});
|
|
3146
|
+
});
|
|
3147
|
+
|
|
3148
|
+
// Hash deep links: boot on #/tab/<name> (refresh keeps the current tab) and
|
|
3149
|
+
// follow hashchange (browser back/forward between tabs).
|
|
3150
|
+
const bootTab = tabNameFromHash();
|
|
3151
|
+
if (bootTab) {
|
|
3152
|
+
activateTab(bootTab);
|
|
3153
|
+
}
|
|
3154
|
+
window.addEventListener("hashchange", function () {
|
|
3155
|
+
const fromHash = tabNameFromHash();
|
|
3156
|
+
if (fromHash && fromHash !== activeTab) {
|
|
3157
|
+
activateTab(fromHash);
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
3160
|
+
|
|
3161
|
+
$$(".filter-btn").forEach(function (btn) {
|
|
3162
|
+
btn.addEventListener("click", function () {
|
|
3163
|
+
$$(".filter-btn").forEach(function (item) { item.classList.remove("active"); });
|
|
3164
|
+
btn.classList.add("active");
|
|
3165
|
+
currentFilter = btn.dataset.filter;
|
|
3166
|
+
terminalTasksVisible = 20;
|
|
3167
|
+
renderTasks(teamState.tasks || []);
|
|
3168
|
+
});
|
|
3169
|
+
});
|
|
3170
|
+
|
|
3171
|
+
const taskKeywordInput = $("#task-keyword");
|
|
3172
|
+
if (taskKeywordInput) {
|
|
3173
|
+
taskKeywordInput.addEventListener("input", function () {
|
|
3174
|
+
taskKeywordFilter = taskKeywordInput.value.trim().toLowerCase();
|
|
3175
|
+
terminalTasksVisible = 20;
|
|
3176
|
+
renderTasks(teamState.tasks || []);
|
|
3177
|
+
});
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
const workspaceTreeRefresh = $("#workspace-tree-refresh");
|
|
3181
|
+
if (workspaceTreeRefresh) {
|
|
3182
|
+
workspaceTreeRefresh.addEventListener("click", function () {
|
|
3183
|
+
refreshWorkspaceTree(false);
|
|
3184
|
+
});
|
|
3185
|
+
}
|
|
3186
|
+
|
|
3187
|
+
const workspaceTreeContainer = $("#workspace-tree");
|
|
3188
|
+
if (workspaceTreeContainer) {
|
|
3189
|
+
workspaceTreeContainer.addEventListener("click", function (event) {
|
|
3190
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
3191
|
+
if (!target) return;
|
|
3192
|
+
|
|
3193
|
+
// Directory toggle (lazy-load on first expand)
|
|
3194
|
+
const dirToggle = target.closest(".workspace-tree-dir-toggle");
|
|
3195
|
+
if (dirToggle) {
|
|
3196
|
+
const li = dirToggle.closest(".workspace-tree-folder");
|
|
3197
|
+
if (!li) return;
|
|
3198
|
+
const childrenContainer = li.querySelector(".workspace-tree-children");
|
|
3199
|
+
if (!childrenContainer) return;
|
|
3200
|
+
const arrow = dirToggle.querySelector(".workspace-tree-arrow");
|
|
3201
|
+
const isOpen = childrenContainer.style.display !== "none";
|
|
3202
|
+
|
|
3203
|
+
if (isOpen) {
|
|
3204
|
+
childrenContainer.style.display = "none";
|
|
3205
|
+
if (arrow) arrow.textContent = "▸";
|
|
3206
|
+
} else {
|
|
3207
|
+
childrenContainer.style.display = "";
|
|
3208
|
+
if (arrow) arrow.textContent = "▾";
|
|
3209
|
+
// Lazy-load if not yet loaded
|
|
3210
|
+
if (dirToggle.classList.contains("is-lazy")) {
|
|
3211
|
+
dirToggle.classList.remove("is-lazy");
|
|
3212
|
+
var dirPath = dirToggle.dataset.dirPath || "";
|
|
3213
|
+
childrenContainer.innerHTML = '<div class="workspace-tree-loading">Loading…</div>';
|
|
3214
|
+
apiGet("/workspace/subtree?path=" + encodeURIComponent(dirPath)).then(function (data) {
|
|
3215
|
+
var entries = data.entries || [];
|
|
3216
|
+
mergeWorkspaceSubtree(dirPath, entries);
|
|
3217
|
+
if (entries.length === 0) {
|
|
3218
|
+
childrenContainer.innerHTML = '<div class="workspace-tree-empty">(empty)</div>';
|
|
3219
|
+
} else {
|
|
3220
|
+
childrenContainer.innerHTML = renderWorkspaceTreeNodes(entries);
|
|
3221
|
+
}
|
|
3222
|
+
}).catch(function () {
|
|
3223
|
+
childrenContainer.innerHTML = '<div class="workspace-tree-empty">Failed to load</div>';
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
|
|
3230
|
+
// File click
|
|
3231
|
+
const button = target.closest("[data-workspace-path]");
|
|
3232
|
+
const relativePath = button && button.dataset ? button.dataset.workspacePath : "";
|
|
3233
|
+
if (!relativePath) {
|
|
3234
|
+
return;
|
|
3235
|
+
}
|
|
3236
|
+
loadWorkspaceFile(relativePath, { keepView: true, silent: false });
|
|
3237
|
+
});
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
$$(".workspace-view-tab").forEach(function (tab) {
|
|
3241
|
+
tab.addEventListener("click", function () {
|
|
3242
|
+
const nextView = tab.dataset.workspaceView || "source";
|
|
3243
|
+
if (nextView === "preview" && !isWorkspacePreviewAvailable(selectedWorkspaceFile)) {
|
|
3244
|
+
return;
|
|
3245
|
+
}
|
|
3246
|
+
selectedWorkspaceView = nextView;
|
|
3247
|
+
renderWorkspaceFile();
|
|
3248
|
+
});
|
|
3249
|
+
});
|
|
3250
|
+
|
|
3251
|
+
const tasksBoard = $("#tasks-board");
|
|
3252
|
+
if (tasksBoard) {
|
|
3253
|
+
tasksBoard.addEventListener("click", function (event) {
|
|
3254
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
3255
|
+
const card = target ? target.closest(".task-card") : null;
|
|
3256
|
+
if (card && card.dataset.taskId) {
|
|
3257
|
+
openTaskDetail(card.dataset.taskId);
|
|
3258
|
+
}
|
|
3259
|
+
});
|
|
3260
|
+
|
|
3261
|
+
tasksBoard.addEventListener("keydown", function (event) {
|
|
3262
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
3263
|
+
const card = target ? target.closest(".task-card") : null;
|
|
3264
|
+
if (!card || !card.dataset.taskId) {
|
|
3265
|
+
return;
|
|
3266
|
+
}
|
|
3267
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
3268
|
+
event.preventDefault();
|
|
3269
|
+
openTaskDetail(card.dataset.taskId);
|
|
3270
|
+
}
|
|
3271
|
+
});
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3274
|
+
const taskDetailClose = $("#task-detail-close");
|
|
3275
|
+
if (taskDetailClose) {
|
|
3276
|
+
taskDetailClose.addEventListener("click", closeTaskDetail);
|
|
3277
|
+
}
|
|
3278
|
+
$$("[data-task-detail-close]").forEach(function (node) {
|
|
3279
|
+
node.addEventListener("click", closeTaskDetail);
|
|
3280
|
+
});
|
|
3281
|
+
|
|
3282
|
+
const taskDetailRefresh = $("#task-detail-refresh");
|
|
3283
|
+
if (taskDetailRefresh) {
|
|
3284
|
+
taskDetailRefresh.addEventListener("click", function () {
|
|
3285
|
+
refreshTaskDetail(false);
|
|
3286
|
+
});
|
|
3287
|
+
}
|
|
3288
|
+
|
|
3289
|
+
$$(".task-detail-tab").forEach(function (tab) {
|
|
3290
|
+
tab.addEventListener("click", function () {
|
|
3291
|
+
selectedTaskDetailTab = tab.dataset.taskDetailTab || "details";
|
|
3292
|
+
if (selectedTaskDetailTab === "timeline") {
|
|
3293
|
+
taskTimelineAutoFollow = true;
|
|
3294
|
+
}
|
|
3295
|
+
syncTaskDetailTab();
|
|
3296
|
+
renderTaskDetail();
|
|
3297
|
+
});
|
|
3298
|
+
});
|
|
3299
|
+
|
|
3300
|
+
const clarificationPromptClose = $("#clarification-prompt-close");
|
|
3301
|
+
if (clarificationPromptClose) {
|
|
3302
|
+
clarificationPromptClose.addEventListener("click", function () {
|
|
3303
|
+
if (activeClarificationId && dismissedClarificationIds.indexOf(activeClarificationId) === -1) {
|
|
3304
|
+
dismissedClarificationIds.push(activeClarificationId);
|
|
3305
|
+
}
|
|
3306
|
+
clarificationPromptOpen = false;
|
|
3307
|
+
renderClarificationPrompt();
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
$$("[data-clarification-prompt-close]").forEach(function (node) {
|
|
3311
|
+
node.addEventListener("click", function () {
|
|
3312
|
+
if (activeClarificationId && dismissedClarificationIds.indexOf(activeClarificationId) === -1) {
|
|
3313
|
+
dismissedClarificationIds.push(activeClarificationId);
|
|
3314
|
+
}
|
|
3315
|
+
clarificationPromptOpen = false;
|
|
3316
|
+
renderClarificationPrompt();
|
|
3317
|
+
});
|
|
3318
|
+
});
|
|
3319
|
+
|
|
3320
|
+
document.addEventListener("keydown", function (event) {
|
|
3321
|
+
if (event.key === "Escape") {
|
|
3322
|
+
closeTaskDetail();
|
|
3323
|
+
}
|
|
3324
|
+
});
|
|
3325
|
+
|
|
3326
|
+
const taskForm = $("#create-task-form");
|
|
3327
|
+
if (taskForm) {
|
|
3328
|
+
taskForm.addEventListener("submit", async function (event) {
|
|
3329
|
+
event.preventDefault();
|
|
3330
|
+
const title = $("#task-title").value.trim();
|
|
3331
|
+
const desc = $("#task-desc").value.trim();
|
|
3332
|
+
const recommendedSkills = normalizeSkillList(
|
|
3333
|
+
($("#task-recommended-skills").value || "").split(","),
|
|
3334
|
+
);
|
|
3335
|
+
const priority = $("#task-priority").value;
|
|
3336
|
+
const role = $("#task-role").value;
|
|
3337
|
+
|
|
3338
|
+
if (!title || !desc) return;
|
|
3339
|
+
|
|
3340
|
+
try {
|
|
3341
|
+
const body = { title: title, description: desc, priority: priority, createdBy: "boss" };
|
|
3342
|
+
if (role) {
|
|
3343
|
+
body.assignedRole = role;
|
|
3344
|
+
}
|
|
3345
|
+
if (recommendedSkills.length > 0) {
|
|
3346
|
+
body.recommendedSkills = recommendedSkills;
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
await apiPost("/tasks", body);
|
|
3350
|
+
taskForm.reset();
|
|
3351
|
+
refreshAll();
|
|
3352
|
+
} catch (err) {
|
|
3353
|
+
console.error("Failed to create task:", err);
|
|
3354
|
+
showError(err instanceof Error ? err.message : "Failed to create task");
|
|
3355
|
+
}
|
|
3356
|
+
});
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
document.addEventListener("submit", async function (event) {
|
|
3360
|
+
const form = event.target;
|
|
3361
|
+
if (!(form instanceof HTMLFormElement) || !form.matches(".clarification-answer-form")) {
|
|
3362
|
+
return;
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
event.preventDefault();
|
|
3366
|
+
const clarificationId = form.dataset.clarificationId;
|
|
3367
|
+
const answerInput = form.querySelector('textarea[name="answer"]');
|
|
3368
|
+
const submitButton = form.querySelector('button[type="submit"]');
|
|
3369
|
+
const answer = answerInput ? answerInput.value.trim() : "";
|
|
3370
|
+
|
|
3371
|
+
if (!clarificationId || !answer) {
|
|
3372
|
+
showError("Please provide an answer before submitting.");
|
|
3373
|
+
return;
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
if (submitButton) {
|
|
3377
|
+
submitButton.disabled = true;
|
|
3378
|
+
}
|
|
3379
|
+
|
|
3380
|
+
try {
|
|
3381
|
+
await apiPost("/clarifications/" + clarificationId + "/answer", {
|
|
3382
|
+
answer: answer,
|
|
3383
|
+
answeredBy: "simulated-human",
|
|
3384
|
+
});
|
|
3385
|
+
dismissedClarificationIds = dismissedClarificationIds.filter(function (id) { return id !== clarificationId; });
|
|
3386
|
+
if (activeClarificationId === clarificationId) {
|
|
3387
|
+
activeClarificationId = null;
|
|
3388
|
+
}
|
|
3389
|
+
refreshAll();
|
|
3390
|
+
if (selectedTaskId) {
|
|
3391
|
+
refreshTaskDetail(true);
|
|
3392
|
+
}
|
|
3393
|
+
} catch (err) {
|
|
3394
|
+
console.error("Failed to answer clarification:", err);
|
|
3395
|
+
showError(err instanceof Error ? err.message : "Failed to answer clarification");
|
|
3396
|
+
} finally {
|
|
3397
|
+
if (submitButton) {
|
|
3398
|
+
submitButton.disabled = false;
|
|
3399
|
+
}
|
|
3400
|
+
}
|
|
3401
|
+
});
|
|
3402
|
+
|
|
3403
|
+
const controllerRunsContainer = $("#controller-runs");
|
|
3404
|
+
if (controllerRunsContainer) {
|
|
3405
|
+
controllerRunsContainer.addEventListener("click", function (event) {
|
|
3406
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
3407
|
+
const button = target ? target.closest("[data-open-task-id]") : null;
|
|
3408
|
+
const taskId = button && button.dataset ? button.dataset.openTaskId : "";
|
|
3409
|
+
if (taskId) {
|
|
3410
|
+
openTaskDetail(taskId);
|
|
3411
|
+
}
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
|
|
3415
|
+
var languageToggle = $("#language-toggle");
|
|
3416
|
+
if (languageToggle) {
|
|
3417
|
+
languageToggle.addEventListener("click", function () {
|
|
3418
|
+
setLanguage(currentLanguage === "zh" ? "en" : "zh");
|
|
3419
|
+
});
|
|
3420
|
+
}
|
|
3421
|
+
|
|
3422
|
+
document.addEventListener("click", function (event) {
|
|
3423
|
+
var target = event.target instanceof Element ? event.target : null;
|
|
3424
|
+
var toggle = target ? target.closest("#worker-install-toggle") : null;
|
|
3425
|
+
if (toggle) {
|
|
3426
|
+
externalWorkerInstallVisible = !externalWorkerInstallVisible;
|
|
3427
|
+
renderExternalWorkerInstallToggle();
|
|
3428
|
+
renderExternalWorkerInstallCard();
|
|
3429
|
+
return;
|
|
3430
|
+
}
|
|
3431
|
+
var button = target ? target.closest("[data-open-task-id]") : null;
|
|
3432
|
+
var taskId = button && button.dataset ? button.dataset.openTaskId : "";
|
|
3433
|
+
if (!taskId || (controllerRunsContainer && controllerRunsContainer.contains(button))) {
|
|
3434
|
+
return;
|
|
3435
|
+
}
|
|
3436
|
+
activateTab("tasks");
|
|
3437
|
+
openTaskDetail(taskId);
|
|
3438
|
+
});
|
|
3439
|
+
|
|
3440
|
+
document.addEventListener("change", function (event) {
|
|
3441
|
+
var target = event.target instanceof Element ? event.target : null;
|
|
3442
|
+
if (!target) return;
|
|
3443
|
+
if (target.matches("[data-worker-install-role]")) {
|
|
3444
|
+
selectedExternalWorkerRole = target.value || selectedExternalWorkerRole;
|
|
3445
|
+
renderExternalWorkerInstallCard();
|
|
3446
|
+
return;
|
|
3447
|
+
}
|
|
3448
|
+
if (target.matches("[data-worker-install-discovery]")) {
|
|
3449
|
+
selectedExternalWorkerDiscoveryMode = target.value === "manual" ? "manual" : "mdns";
|
|
3450
|
+
renderExternalWorkerInstallCard();
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
|
|
3454
|
+
document.addEventListener("click", function (event) {
|
|
3455
|
+
var target = event.target instanceof Element ? event.target : null;
|
|
3456
|
+
var button = target ? target.closest("[data-worker-install-copy]") : null;
|
|
3457
|
+
if (!button) return;
|
|
3458
|
+
var command = buildExternalWorkerCommand(
|
|
3459
|
+
teamState.externalWorkerInstall,
|
|
3460
|
+
selectedExternalWorkerRole,
|
|
3461
|
+
selectedExternalWorkerDiscoveryMode,
|
|
3462
|
+
);
|
|
3463
|
+
copyText(command).then(function () {
|
|
3464
|
+
button.textContent = t("action.copied");
|
|
3465
|
+
window.setTimeout(function () {
|
|
3466
|
+
button.textContent = t("action.copyCommand");
|
|
3467
|
+
}, 1200);
|
|
3468
|
+
}).catch(function (err) {
|
|
3469
|
+
console.error(err);
|
|
3470
|
+
showError(err instanceof Error ? err.message : "Failed to copy command");
|
|
3471
|
+
});
|
|
3472
|
+
});
|
|
3473
|
+
|
|
3474
|
+
// Planning session sub-tab click handler
|
|
3475
|
+
var planningSessionList = $("#planning-session-list");
|
|
3476
|
+
if (planningSessionList) {
|
|
3477
|
+
planningSessionList.addEventListener("click", function (event) {
|
|
3478
|
+
var target = event.target instanceof Element ? event.target : null;
|
|
3479
|
+
var btn = target ? target.closest("[data-planning-run]") : null;
|
|
3480
|
+
var runId = btn && btn.dataset ? btn.dataset.planningRun : "";
|
|
3481
|
+
if (runId && runId !== selectedPlanningRunId) {
|
|
3482
|
+
selectedPlanningRunId = runId;
|
|
3483
|
+
renderPlanningTab(teamState.controllerRuns);
|
|
3484
|
+
}
|
|
3485
|
+
});
|
|
3486
|
+
}
|
|
3487
|
+
|
|
3488
|
+
const cmdInput = $("#command-input");
|
|
3489
|
+
const cmdSend = $("#command-send");
|
|
3490
|
+
|
|
3491
|
+
function handleCommand() {
|
|
3492
|
+
const cmd = (cmdInput && cmdInput.value ? cmdInput.value : "").trim();
|
|
3493
|
+
if (!cmd || !cmdInput || controllerCommandPending) return;
|
|
3494
|
+
cmdInput.value = "";
|
|
3495
|
+
|
|
3496
|
+
if (cmd === "/status" || cmd === "/s") {
|
|
3497
|
+
refreshAll();
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
if (cmd.startsWith("/assign ")) {
|
|
3502
|
+
const parts = cmd.split(" ");
|
|
3503
|
+
const taskId = parts[1];
|
|
3504
|
+
const role = parts[2];
|
|
3505
|
+
if (taskId && role) {
|
|
3506
|
+
apiPost("/tasks/" + taskId + "/assign", { targetRole: role })
|
|
3507
|
+
.then(function () { refreshAll(); })
|
|
3508
|
+
.catch(function (err) {
|
|
3509
|
+
console.error(err);
|
|
3510
|
+
showError(err instanceof Error ? err.message : "Failed to assign task");
|
|
3511
|
+
});
|
|
3512
|
+
}
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
controllerCommandPending = true;
|
|
3517
|
+
if (cmdSend) {
|
|
3518
|
+
cmdSend.disabled = true;
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
appendControllerConversation({
|
|
3522
|
+
from: "human",
|
|
3523
|
+
fromRole: "human",
|
|
3524
|
+
type: "controller-input",
|
|
3525
|
+
content: cmd,
|
|
3526
|
+
});
|
|
3527
|
+
|
|
3528
|
+
apiPost("/controller/intake", {
|
|
3529
|
+
message: cmd,
|
|
3530
|
+
sessionKey: getControllerSessionKey(),
|
|
3531
|
+
}).then(function (data) {
|
|
3532
|
+
appendControllerConversation({
|
|
3533
|
+
from: "controller",
|
|
3534
|
+
fromRole: "controller",
|
|
3535
|
+
type: "controller-reply",
|
|
3536
|
+
content: data && data.reply ? data.reply : t("empty.copiedControllerReply"),
|
|
3537
|
+
});
|
|
3538
|
+
refreshAll();
|
|
3539
|
+
}).catch(function (err) {
|
|
3540
|
+
console.error(err);
|
|
3541
|
+
appendControllerConversation({
|
|
3542
|
+
from: "controller",
|
|
3543
|
+
fromRole: "controller",
|
|
3544
|
+
type: "controller-error",
|
|
3545
|
+
content: err instanceof Error ? err.message : "Failed to send message to controller",
|
|
3546
|
+
});
|
|
3547
|
+
showError(err instanceof Error ? err.message : "Failed to send message to controller");
|
|
3548
|
+
}).finally(function () {
|
|
3549
|
+
controllerCommandPending = false;
|
|
3550
|
+
if (cmdSend) {
|
|
3551
|
+
cmdSend.disabled = false;
|
|
3552
|
+
}
|
|
3553
|
+
});
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
if (cmdSend) {
|
|
3557
|
+
cmdSend.addEventListener("click", handleCommand);
|
|
3558
|
+
}
|
|
3559
|
+
|
|
3560
|
+
if (cmdInput) {
|
|
3561
|
+
cmdInput.addEventListener("keydown", function (event) {
|
|
3562
|
+
if (event.key === "Enter") {
|
|
3563
|
+
handleCommand();
|
|
3564
|
+
}
|
|
3565
|
+
});
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
async function applyInitialUiState() {
|
|
3569
|
+
if (initialUiStateApplied) {
|
|
3570
|
+
return;
|
|
3571
|
+
}
|
|
3572
|
+
initialUiStateApplied = true;
|
|
3573
|
+
|
|
3574
|
+
if (initialUiState.planningRun) {
|
|
3575
|
+
selectedPlanningRunId = initialUiState.planningRun;
|
|
3576
|
+
renderPlanningTab(teamState.controllerRuns);
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
if (initialUiState.tab) {
|
|
3580
|
+
// Only activate a tab that actually exists (guards stale links).
|
|
3581
|
+
// Array.from: NodeList has no .some.
|
|
3582
|
+
const tabExists = Array.from($$(".tab")).some(function (item) { return item.dataset.tab === initialUiState.tab; });
|
|
3583
|
+
if (tabExists) {
|
|
3584
|
+
activateTab(initialUiState.tab);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
|
|
3588
|
+
if (initialUiState.taskId) {
|
|
3589
|
+
await openTaskDetail(initialUiState.taskId);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
|
|
3593
|
+
var WORKSPACE_PROMPT_DISMISSED_KEY = "teamclaw.workspacePromptDismissed";
|
|
3594
|
+
|
|
3595
|
+
function updateWorkspacePathIndicator() {
|
|
3596
|
+
var el = $("#workspace-current-path-value");
|
|
3597
|
+
if (!el) return;
|
|
3598
|
+
apiGet("/workspace/status").then(function (data) {
|
|
3599
|
+
if (data && typeof data.workspaceDir === "string") {
|
|
3600
|
+
el.textContent = data.workspaceDir + (data.isDefault ? " (default)" : "");
|
|
3601
|
+
el.title = data.workspaceDir;
|
|
3602
|
+
}
|
|
3603
|
+
}).catch(function () { /* leave placeholder */ });
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3606
|
+
function openWorkspacePromptModal(currentPath) {
|
|
3607
|
+
var modal = $("#workspace-prompt-modal");
|
|
3608
|
+
var pathEl = $("#workspace-prompt-path");
|
|
3609
|
+
var input = $("#workspace-prompt-input");
|
|
3610
|
+
if (!modal || !pathEl || !input) return;
|
|
3611
|
+
pathEl.textContent = currentPath || "(unknown)";
|
|
3612
|
+
input.value = currentPath || "";
|
|
3613
|
+
modal.classList.add("open");
|
|
3614
|
+
modal.setAttribute("aria-hidden", "false");
|
|
3615
|
+
}
|
|
3616
|
+
|
|
3617
|
+
function closeWorkspacePromptModal() {
|
|
3618
|
+
var modal = $("#workspace-prompt-modal");
|
|
3619
|
+
if (!modal) return;
|
|
3620
|
+
modal.classList.remove("open");
|
|
3621
|
+
modal.setAttribute("aria-hidden", "true");
|
|
3622
|
+
}
|
|
3623
|
+
|
|
3624
|
+
function promptWorkspaceIfDefault() {
|
|
3625
|
+
if (localStorage.getItem(WORKSPACE_PROMPT_DISMISSED_KEY) === "1") {
|
|
3626
|
+
return;
|
|
3627
|
+
}
|
|
3628
|
+
apiGet("/workspace/status").then(function (data) {
|
|
3629
|
+
if (!data || data.isDefault !== true) {
|
|
3630
|
+
return;
|
|
3631
|
+
}
|
|
3632
|
+
openWorkspacePromptModal(data.workspaceDir);
|
|
3633
|
+
}).catch(function () {
|
|
3634
|
+
// status endpoint unavailable - skip the prompt silently
|
|
3635
|
+
});
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
function bindWorkspacePrompt() {
|
|
3639
|
+
var modal = $("#workspace-prompt-modal");
|
|
3640
|
+
if (!modal || modal.dataset.bound === "true") return;
|
|
3641
|
+
modal.dataset.bound = "true";
|
|
3642
|
+
|
|
3643
|
+
modal.addEventListener("click", function (event) {
|
|
3644
|
+
if (event.target && event.target.hasAttribute && event.target.hasAttribute("data-workspace-prompt-close")) {
|
|
3645
|
+
localStorage.setItem(WORKSPACE_PROMPT_DISMISSED_KEY, "1");
|
|
3646
|
+
closeWorkspacePromptModal();
|
|
3647
|
+
}
|
|
3648
|
+
});
|
|
3649
|
+
|
|
3650
|
+
var browse = $("#workspace-prompt-browse");
|
|
3651
|
+
var input = $("#workspace-prompt-input");
|
|
3652
|
+
var apply = $("#workspace-prompt-apply");
|
|
3653
|
+
|
|
3654
|
+
if (browse) {
|
|
3655
|
+
browse.addEventListener("click", function () {
|
|
3656
|
+
if (typeof window.showDirectoryPicker === "function") {
|
|
3657
|
+
window.showDirectoryPicker({ mode: "readwrite", id: "teamclaw-workspace" })
|
|
3658
|
+
.then(function (handle) {
|
|
3659
|
+
if (input) {
|
|
3660
|
+
input.value = handle.name || input.value;
|
|
3661
|
+
input.dataset.verifiedPath = "";
|
|
3662
|
+
}
|
|
3663
|
+
showError("Browser directory picker cannot return full server paths; please type the absolute path instead.");
|
|
3664
|
+
})
|
|
3665
|
+
.catch(function () {
|
|
3666
|
+
/* user cancelled */
|
|
3667
|
+
});
|
|
3668
|
+
} else {
|
|
3669
|
+
showError("This browser does not support a native directory picker; please type the absolute path instead.");
|
|
3670
|
+
}
|
|
3671
|
+
});
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
if (apply) {
|
|
3675
|
+
apply.addEventListener("click", function () {
|
|
3676
|
+
var value = input && typeof input.value === "string" ? input.value.trim() : "";
|
|
3677
|
+
if (!value || value.indexOf("/") !== 0) {
|
|
3678
|
+
showError("Please enter an absolute path starting with /");
|
|
3679
|
+
return;
|
|
3680
|
+
}
|
|
3681
|
+
apply.disabled = true;
|
|
3682
|
+
apiPost("/workspace/change-dir", { workspaceDir: value }).then(function () {
|
|
3683
|
+
localStorage.setItem(WORKSPACE_PROMPT_DISMISSED_KEY, "1");
|
|
3684
|
+
closeWorkspacePromptModal();
|
|
3685
|
+
showError("Workspace updated to " + value + ". Restart the gateway (openclaw gateway restart) to apply it.");
|
|
3686
|
+
updateWorkspacePathIndicator();
|
|
3687
|
+
}).catch(function (err) {
|
|
3688
|
+
showError(err instanceof Error ? err.message : "Failed to update workspace directory");
|
|
3689
|
+
}).finally(function () {
|
|
3690
|
+
apply.disabled = false;
|
|
3691
|
+
});
|
|
3692
|
+
});
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
|
|
3696
|
+
applyStaticTranslations();
|
|
3697
|
+
renderWorkspaceTree(workspaceTree);
|
|
3698
|
+
renderWorkspaceFile();
|
|
3699
|
+
refreshAll().then(applyInitialUiState).catch(function () {});
|
|
3700
|
+
connectWebSocket();
|
|
3701
|
+
bindWorkspacePrompt();
|
|
3702
|
+
promptWorkspaceIfDefault();
|
|
3703
|
+
updateWorkspacePathIndicator();
|
|
3704
|
+
bindModelSettings();
|
|
3705
|
+
bindGithubCorner();
|
|
3706
|
+
|
|
3707
|
+
function bindModelSettings() {
|
|
3708
|
+
/* Module-level IIFE helper: delegated here to keep startup order simple. */
|
|
3709
|
+
var opener = document.createElement("button");
|
|
3710
|
+
opener.className = "btn btn-small";
|
|
3711
|
+
opener.type = "button";
|
|
3712
|
+
opener.id = "model-settings-open";
|
|
3713
|
+
opener.textContent = "Models";
|
|
3714
|
+
var refreshBtn = document.querySelector("#workspace-tree-refresh");
|
|
3715
|
+
if (refreshBtn && refreshBtn.parentElement) {
|
|
3716
|
+
refreshBtn.parentElement.appendChild(opener);
|
|
3717
|
+
opener.addEventListener("click", openModelSettings);
|
|
3718
|
+
}
|
|
3719
|
+
|
|
3720
|
+
var modal = document.querySelector("#model-settings-modal");
|
|
3721
|
+
if (!modal || modal.dataset.bound === "true") return;
|
|
3722
|
+
modal.dataset.bound = "true";
|
|
3723
|
+
|
|
3724
|
+
modal.addEventListener("click", function (event) {
|
|
3725
|
+
if (event.target && event.target.hasAttribute && event.target.hasAttribute("data-model-settings-close")) {
|
|
3726
|
+
closeModelSettings();
|
|
3727
|
+
}
|
|
3728
|
+
});
|
|
3729
|
+
|
|
3730
|
+
var save = document.querySelector("#model-settings-save");
|
|
3731
|
+
if (save) {
|
|
3732
|
+
save.addEventListener("click", function () {
|
|
3733
|
+
var defaultSelect = document.querySelector("#model-settings-default");
|
|
3734
|
+
var payload = { roleModelOverrides: {} };
|
|
3735
|
+
if (defaultSelect && defaultSelect.value) {
|
|
3736
|
+
payload.defaultModel = defaultSelect.value;
|
|
3737
|
+
}
|
|
3738
|
+
modal.querySelectorAll("[data-role-model]").forEach(function (sel) {
|
|
3739
|
+
var role = sel.getAttribute("data-role-model");
|
|
3740
|
+
if (role && sel.value) {
|
|
3741
|
+
payload.roleModelOverrides[role] = sel.value;
|
|
3742
|
+
}
|
|
3743
|
+
});
|
|
3744
|
+
save.disabled = true;
|
|
3745
|
+
apiRequest("/models/config", {
|
|
3746
|
+
method: "PUT",
|
|
3747
|
+
headers: { "Content-Type": "application/json" },
|
|
3748
|
+
body: JSON.stringify(payload),
|
|
3749
|
+
}).then(function () {
|
|
3750
|
+
showError("Model settings saved. Hot-reload applies; restart the gateway if needed.");
|
|
3751
|
+
closeModelSettings();
|
|
3752
|
+
}).catch(function (err) {
|
|
3753
|
+
showError(err instanceof Error ? err.message : "Failed to save model settings");
|
|
3754
|
+
}).finally(function () {
|
|
3755
|
+
save.disabled = false;
|
|
3756
|
+
});
|
|
3757
|
+
});
|
|
3758
|
+
}
|
|
3759
|
+
}
|
|
3760
|
+
|
|
3761
|
+
function bindGithubCorner() {
|
|
3762
|
+
var cornerLogin = document.querySelector("#github-corner-login");
|
|
3763
|
+
if (cornerLogin && !cornerLogin.dataset.bound) {
|
|
3764
|
+
cornerLogin.dataset.bound = "true";
|
|
3765
|
+
cornerLogin.addEventListener("click", function () {
|
|
3766
|
+
window.open("/ui/auth/github", "_blank", "noopener");
|
|
3767
|
+
pollGithubAuthStatus(360);
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
var cornerUser = document.querySelector("#github-corner-user");
|
|
3771
|
+
if (cornerUser && !cornerUser.dataset.bound) {
|
|
3772
|
+
cornerUser.dataset.bound = "true";
|
|
3773
|
+
cornerUser.addEventListener("click", function () {
|
|
3774
|
+
apiRequest("/auth/github/logout", { method: "POST" }).catch(function () { /* refresh below regardless */ }).finally(function () {
|
|
3775
|
+
refreshGithubAuthStatus();
|
|
3776
|
+
});
|
|
3777
|
+
});
|
|
3778
|
+
cornerUser.addEventListener("keydown", function (event) {
|
|
3779
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
3780
|
+
event.preventDefault();
|
|
3781
|
+
cornerUser.click();
|
|
3782
|
+
}
|
|
3783
|
+
});
|
|
3784
|
+
}
|
|
3785
|
+
// Keep the header-corner login state fresh.
|
|
3786
|
+
setInterval(refreshGithubAuthStatus, 10000);
|
|
3787
|
+
refreshGithubAuthStatus();
|
|
3788
|
+
}
|
|
3789
|
+
|
|
3790
|
+
var githubAuthPollTimer = null;
|
|
3791
|
+
function pollGithubAuthStatus(attemptsLeft) {
|
|
3792
|
+
if (githubAuthPollTimer) clearTimeout(githubAuthPollTimer);
|
|
3793
|
+
if (attemptsLeft <= 0) return;
|
|
3794
|
+
githubAuthPollTimer = setTimeout(function () {
|
|
3795
|
+
apiGet("/auth/github/status").then(function (status) {
|
|
3796
|
+
if (status && status.authenticated) {
|
|
3797
|
+
renderGithubCorner(status);
|
|
3798
|
+
} else {
|
|
3799
|
+
pollGithubAuthStatus(attemptsLeft - 1);
|
|
3800
|
+
}
|
|
3801
|
+
}).catch(function () {
|
|
3802
|
+
pollGithubAuthStatus(attemptsLeft - 1);
|
|
3803
|
+
});
|
|
3804
|
+
}, 2500);
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
function renderGithubCorner(status) {
|
|
3808
|
+
var loginBtn = document.querySelector("#github-corner-login");
|
|
3809
|
+
var userChip = document.querySelector("#github-corner-user");
|
|
3810
|
+
if (!loginBtn || !userChip) return;
|
|
3811
|
+
if (status.authenticated && status.account) {
|
|
3812
|
+
var nameEl = document.querySelector("#github-corner-name");
|
|
3813
|
+
if (nameEl) nameEl.textContent = "@" + status.account.login;
|
|
3814
|
+
var av = document.querySelector("#github-corner-avatar");
|
|
3815
|
+
if (av) {
|
|
3816
|
+
if (status.account.avatarUrl) {
|
|
3817
|
+
av.src = status.account.avatarUrl;
|
|
3818
|
+
av.classList.remove("hidden");
|
|
3819
|
+
} else {
|
|
3820
|
+
av.classList.add("hidden");
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3823
|
+
userChip.classList.remove("hidden");
|
|
3824
|
+
loginBtn.hidden = true;
|
|
3825
|
+
} else {
|
|
3826
|
+
userChip.classList.add("hidden");
|
|
3827
|
+
loginBtn.textContent = t("gh.login");
|
|
3828
|
+
loginBtn.hidden = false;
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
|
|
3832
|
+
function refreshGithubAuthStatus() {
|
|
3833
|
+
apiGet("/auth/github/status").then(renderGithubCorner).catch(function () {
|
|
3834
|
+
/* controller offline - keep the corner as-is */
|
|
3835
|
+
});
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3838
|
+
function openModelSettings() {
|
|
3839
|
+
var modal = document.querySelector("#model-settings-modal");
|
|
3840
|
+
if (!modal) return;
|
|
3841
|
+
apiGet("/models/config").then(function (catalog) {
|
|
3842
|
+
var options = [];
|
|
3843
|
+
(catalog.providers || []).forEach(function (provider) {
|
|
3844
|
+
(provider.models || []).forEach(function (modelId) {
|
|
3845
|
+
options.push({ value: provider.id + "/" + modelId, label: provider.id + " / " + modelId });
|
|
3846
|
+
});
|
|
3847
|
+
if (!provider.models || provider.models.length === 0) {
|
|
3848
|
+
options.push({ value: provider.id, label: provider.id + " (provider default)" });
|
|
3849
|
+
}
|
|
3850
|
+
});
|
|
3851
|
+
if (catalog.defaultModel && !options.some(function (opt) { return opt.value === catalog.defaultModel; })) {
|
|
3852
|
+
options.unshift({ value: catalog.defaultModel, label: catalog.defaultModel + " (current)" });
|
|
3853
|
+
}
|
|
3854
|
+
|
|
3855
|
+
var defaultSelect = document.querySelector("#model-settings-default");
|
|
3856
|
+
if (defaultSelect) {
|
|
3857
|
+
defaultSelect.innerHTML = options.map(function (opt) {
|
|
3858
|
+
return '<option value="' + escapeHtml(opt.value) + '">' + escapeHtml(opt.label) + "</option>";
|
|
3859
|
+
}).join("");
|
|
3860
|
+
defaultSelect.value = catalog.defaultModel || (options.length ? options[0].value : "");
|
|
3861
|
+
}
|
|
3862
|
+
|
|
3863
|
+
var rolesEl = document.querySelector("#model-settings-roles");
|
|
3864
|
+
if (rolesEl) {
|
|
3865
|
+
rolesEl.innerHTML = (catalog.roles || []).map(function (role) {
|
|
3866
|
+
var current = (catalog.roleModelOverrides || {})[role.id] || "";
|
|
3867
|
+
return (
|
|
3868
|
+
'<label class="model-settings-field">' +
|
|
3869
|
+
' <span class="model-settings-label">' + escapeHtml(role.label) + '</span>' +
|
|
3870
|
+
' <select data-role-model="' + escapeHtml(role.id) + '">' +
|
|
3871
|
+
' <option value="">(use default)</option>' +
|
|
3872
|
+
options.map(function (opt) {
|
|
3873
|
+
return '<option value="' + escapeHtml(opt.value) + '"' + (current === opt.value ? " selected" : "") + '>' + escapeHtml(opt.label) + "</option>";
|
|
3874
|
+
}).join("") +
|
|
3875
|
+
" </select>" +
|
|
3876
|
+
"</label>"
|
|
3877
|
+
);
|
|
3878
|
+
}).join("");
|
|
3879
|
+
}
|
|
3880
|
+
|
|
3881
|
+
modal.classList.add("open");
|
|
3882
|
+
modal.setAttribute("aria-hidden", "false");
|
|
3883
|
+
}).catch(function (err) {
|
|
3884
|
+
showError(err instanceof Error ? err.message : "Failed to load model catalog");
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3888
|
+
function closeModelSettings() {
|
|
3889
|
+
var modal = document.querySelector("#model-settings-modal");
|
|
3890
|
+
if (!modal) return;
|
|
3891
|
+
modal.classList.remove("open");
|
|
3892
|
+
modal.setAttribute("aria-hidden", "true");
|
|
3893
|
+
}
|
|
3894
|
+
// ==================== TeamAuto tab ====================
|
|
3895
|
+
|
|
3896
|
+
var teamAutoCandidates = [];
|
|
3897
|
+
var teamAutoCandidatesLoaded = false;
|
|
3898
|
+
|
|
3899
|
+
function teamAutoSetMsg(text, ok) {
|
|
3900
|
+
var el = $("#teamauto-bind-msg");
|
|
3901
|
+
if (!el) { return; }
|
|
3902
|
+
el.textContent = text || "";
|
|
3903
|
+
el.className = "teamauto-msg" + (text ? (ok ? " ok" : " err") : "");
|
|
3904
|
+
}
|
|
3905
|
+
|
|
3906
|
+
function loadTeamAutoCandidates(force) {
|
|
3907
|
+
if (teamAutoCandidatesLoaded && !force) { return Promise.resolve(); }
|
|
3908
|
+
var select = $("#teamauto-repo-select");
|
|
3909
|
+
if (select) { select.innerHTML = '<option>' + escapeHtml(t("teamauto.loadingRepos")) + "</option>"; }
|
|
3910
|
+
return apiGet("/teamauto/repo-candidates").then(function (data) {
|
|
3911
|
+
teamAutoCandidates = (data && data.candidates) || [];
|
|
3912
|
+
teamAutoCandidatesLoaded = true;
|
|
3913
|
+
if (!select) { return; }
|
|
3914
|
+
if (!teamAutoCandidates.length) {
|
|
3915
|
+
select.innerHTML = '<option value="">' + escapeHtml(t("teamauto.noCandidates")) + "</option>";
|
|
3916
|
+
return;
|
|
3917
|
+
}
|
|
3918
|
+
select.innerHTML = teamAutoCandidates.map(function (r) {
|
|
3919
|
+
return '<option value="' + escapeHtml(r.id) + '">' + escapeHtml(r.id + (r.private ? " (private)" : "")) + "</option>";
|
|
3920
|
+
}).join("");
|
|
3921
|
+
}).catch(function (err) {
|
|
3922
|
+
if (select) { select.innerHTML = '<option value="">' + escapeHtml(t("teamauto.loginFirst")) + "</option>"; }
|
|
3923
|
+
teamAutoSetMsg(err instanceof Error ? err.message : String(err), false);
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
function renderTeamAutoRepos(status) {
|
|
3928
|
+
var wrap = $("#teamauto-repos");
|
|
3929
|
+
if (!wrap) { return; }
|
|
3930
|
+
var repos = (status && status.repos) || [];
|
|
3931
|
+
if (!repos.length) {
|
|
3932
|
+
wrap.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamauto.empty")) + "</div>";
|
|
3933
|
+
return;
|
|
3934
|
+
}
|
|
3935
|
+
wrap.innerHTML = repos.map(function (r) {
|
|
3936
|
+
var badge = !r.enabled
|
|
3937
|
+
? '<span class="teamauto-badge">' + escapeHtml(t("teamauto.disabled")) + "</span>"
|
|
3938
|
+
: r.provision && r.provision.status === "provisioning"
|
|
3939
|
+
? '<span class="teamauto-badge" title="' + escapeHtml(r.provision.message || "") + '">' + escapeHtml(t("teamauto.provisioning")) + "</span>"
|
|
3940
|
+
: r.provision && r.provision.status === "failed"
|
|
3941
|
+
? '<span class="teamauto-badge warn" title="' + escapeHtml(r.provision.message || "") + '">' + escapeHtml(t("teamauto.provisionFailed")) + "</span>"
|
|
3942
|
+
: r.pausedReason
|
|
3943
|
+
? '<span class="teamauto-badge warn" title="' + escapeHtml(r.pausedReason) + '">' + escapeHtml(t("teamauto.paused")) + "</span>"
|
|
3944
|
+
: '<span class="teamauto-badge on">' + escapeHtml(t("teamauto.active")) + "</span>";
|
|
3945
|
+
var when = r.lastSweepAt ? new Date(r.lastSweepAt).toLocaleString() : "-";
|
|
3946
|
+
var norms = r.norms ? escapeHtml(r.norms.commitStyle) : "...";
|
|
3947
|
+
var fr = r.policy.actions.fullReview;
|
|
3948
|
+
return '<div class="teamauto-card card" data-repo="' + escapeHtml(r.id) + '">' +
|
|
3949
|
+
'<div class="teamauto-card-head"><span class="teamauto-repo-name">' + escapeHtml(r.id) + "</span>" + badge + "</div>" +
|
|
3950
|
+
'<div class="teamauto-meta">' +
|
|
3951
|
+
escapeHtml(t("teamauto.schedule")) + ": <code>" + escapeHtml(r.schedule) + "</code> | " +
|
|
3952
|
+
escapeHtml(t("teamauto.lastSweep")) + ": " + escapeHtml(when) +
|
|
3953
|
+
(r.lastSweepSummary ? " | " + escapeHtml(r.lastSweepSummary) : "") +
|
|
3954
|
+
"<br>" + escapeHtml(t("teamauto.norms")) + ": " + norms +
|
|
3955
|
+
(r.pausedReason ? '<br><span class="teamauto-warn-text">' + escapeHtml(r.pausedReason) + "</span>" : "") +
|
|
3956
|
+
"</div>" +
|
|
3957
|
+
'<div class="teamauto-config-row">' +
|
|
3958
|
+
'<label>' + escapeHtml(t("teamauto.schedule")) + ' <input data-cfg="schedule" type="text" value="' + escapeHtml(r.schedule) + '" spellcheck="false"></label>' +
|
|
3959
|
+
'<label>' + escapeHtml(t("teamauto.maxPerSweep")) + ' <input data-cfg="maxTasksPerSweep" type="number" min="1" max="20" value="' + r.policy.maxTasksPerSweep + '"></label>' +
|
|
3960
|
+
'<label>' + escapeHtml(t("teamauto.fullReview")) + ' <select data-cfg="fullReview">' +
|
|
3961
|
+
["off", "weekly", "daily"].map(function (v) { return '<option value="' + v + '"' + (fr === v ? " selected" : "") + ">" + v + "</option>"; }).join("") +
|
|
3962
|
+
"</select></label>" +
|
|
3963
|
+
'<label>' + escapeHtml(t("teamauto.takeOwnership")) + ' <select data-cfg="takeOwnership">' +
|
|
3964
|
+
'<option value="true"' + (r.policy.actions.takeOwnership ? " selected" : "") + ">on</option>" +
|
|
3965
|
+
'<option value="false"' + (!r.policy.actions.takeOwnership ? " selected" : "") + ">off</option>" +
|
|
3966
|
+
"</select></label>" +
|
|
3967
|
+
'<button class="btn btn-small" data-act="save">' + escapeHtml(t("teamauto.save")) + "</button>" +
|
|
3968
|
+
"</div>" +
|
|
3969
|
+
'<div class="teamauto-actions">' +
|
|
3970
|
+
'<button class="btn btn-small" data-act="sweep">' + escapeHtml(t("teamauto.sweep")) + "</button>" +
|
|
3971
|
+
'<button class="btn btn-small" data-act="toggle">' + escapeHtml(t(r.enabled ? "teamauto.disable" : "teamauto.enable")) + "</button>" +
|
|
3972
|
+
'<button class="btn btn-small btn-danger" data-act="unbind">' + escapeHtml(t("teamauto.unbind")) + "</button>" +
|
|
3973
|
+
"</div></div>";
|
|
3974
|
+
}).join("");
|
|
3975
|
+
}
|
|
3976
|
+
|
|
3977
|
+
var teamAutoBusy = false;
|
|
3978
|
+
function renderTeamAutoActivity(activity) {
|
|
3979
|
+
var wrap = $("#teamauto-activity");
|
|
3980
|
+
if (!wrap) { return; }
|
|
3981
|
+
var list = activity || [];
|
|
3982
|
+
if (!list.length) {
|
|
3983
|
+
wrap.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamauto.activityEmpty")) + "</div>";
|
|
3984
|
+
return;
|
|
3985
|
+
}
|
|
3986
|
+
wrap.innerHTML = list.slice(0, 30).map(function (e) {
|
|
3987
|
+
var when = new Date(e.at || 0).toLocaleString();
|
|
3988
|
+
return '<div class="teamauto-activity-item">'
|
|
3989
|
+
+ '<span class="teamauto-activity-kind k-' + escapeHtml(String(e.kind || "sweep")) + '">' + escapeHtml(String(e.kind || "")) + "</span>"
|
|
3990
|
+
+ '<span class="teamauto-activity-text"><b>' + escapeHtml(String(e.repoId || "")) + "</b> " + escapeHtml(String(e.text || "")) + "</span>"
|
|
3991
|
+
+ '<span class="teamauto-activity-time">' + escapeHtml(when) + "</span>"
|
|
3992
|
+
+ "</div>";
|
|
3993
|
+
}).join("");
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3996
|
+
function refreshTeamAutoTab() {
|
|
3997
|
+
if (teamAutoBusy) { return; }
|
|
3998
|
+
teamAutoBusy = true;
|
|
3999
|
+
void loadTeamAutoCandidates(false);
|
|
4000
|
+
apiGet("/teamauto/repos").then(renderTeamAutoRepos).catch(function () {
|
|
4001
|
+
/* scheduler not running yet */
|
|
4002
|
+
}).finally(function () { teamAutoBusy = false; });
|
|
4003
|
+
apiGet("/teamauto/activity").then(function (data) {
|
|
4004
|
+
renderTeamAutoActivity((data && data.activity) || []);
|
|
4005
|
+
}).catch(function () { /* activity is best-effort */ });
|
|
4006
|
+
}
|
|
4007
|
+
|
|
4008
|
+
function bindTeamAutoTabEvents() {
|
|
4009
|
+
var bindBtn = $("#teamauto-bind");
|
|
4010
|
+
if (bindBtn && !bindBtn.dataset.bound) {
|
|
4011
|
+
bindBtn.dataset.bound = "true";
|
|
4012
|
+
bindBtn.addEventListener("click", function () {
|
|
4013
|
+
var select = $("#teamauto-repo-select");
|
|
4014
|
+
var repo = select ? select.value.trim() : "";
|
|
4015
|
+
if (!repo || !/^[\w.-]+\/[\w.-]+$/.test(repo)) {
|
|
4016
|
+
teamAutoSetMsg(t("teamauto.needRepo"), false);
|
|
4017
|
+
return;
|
|
4018
|
+
}
|
|
4019
|
+
var sched = $("#teamauto-schedule");
|
|
4020
|
+
bindBtn.disabled = true;
|
|
4021
|
+
teamAutoSetMsg("...");
|
|
4022
|
+
teamAutoBindWithOverlay(repo, sched && sched.value.trim() ? sched.value.trim() : undefined)
|
|
4023
|
+
.then(function (ok) {
|
|
4024
|
+
if (ok) { teamAutoSetMsg(repo + " -> " + t("teamauto.active"), true); refreshTeamAutoTab(); }
|
|
4025
|
+
})
|
|
4026
|
+
.finally(function () { bindBtn.disabled = false; });
|
|
4027
|
+
});
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
function teamAutoSetBindStage(stage, note, isError) {
|
|
4031
|
+
var overlay = $("#teamauto-bind-overlay");
|
|
4032
|
+
if (!overlay) { return; }
|
|
4033
|
+
overlay.querySelectorAll(".ta-bind-steps li").forEach(function (li) {
|
|
4034
|
+
var n = parseInt(li.getAttribute("data-stage") || "0", 10);
|
|
4035
|
+
li.classList.toggle("done", !isError && n < stage);
|
|
4036
|
+
li.classList.toggle("active", !isError && n === stage);
|
|
4037
|
+
li.classList.toggle("error", !!isError && n === stage);
|
|
4038
|
+
});
|
|
4039
|
+
var noteEl = $("#teamauto-bind-note");
|
|
4040
|
+
if (noteEl) { noteEl.textContent = note || ""; noteEl.className = "ta-bind-note" + (isError ? " err" : ""); }
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
function teamAutoBindWithOverlay(repo, schedule) {
|
|
4044
|
+
var overlay = $("#teamauto-bind-overlay");
|
|
4045
|
+
var closeBtn = $("#teamauto-bind-overlay-close");
|
|
4046
|
+
var titleEl = $("#teamauto-bind-title");
|
|
4047
|
+
if (!overlay) {
|
|
4048
|
+
return apiRequest("/teamauto/repos", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo, schedule: schedule }) })
|
|
4049
|
+
.then(function () { return true; })
|
|
4050
|
+
.catch(function (err) { teamAutoSetMsg(err instanceof Error ? err.message : String(err), false); return false; });
|
|
4051
|
+
}
|
|
4052
|
+
if (titleEl) { titleEl.textContent = t("teamauto.bind") + ": " + repo; }
|
|
4053
|
+
if (closeBtn) {
|
|
4054
|
+
closeBtn.classList.add("is-hidden");
|
|
4055
|
+
closeBtn.addEventListener("click", function () { overlay.classList.add("is-hidden"); }, { once: true });
|
|
4056
|
+
}
|
|
4057
|
+
overlay.classList.remove("is-hidden");
|
|
4058
|
+
teamAutoSetBindStage(1, "");
|
|
4059
|
+
return apiRequest("/teamauto/repos", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo, schedule: schedule }) })
|
|
4060
|
+
.catch(function (err) {
|
|
4061
|
+
teamAutoSetBindStage(1, err instanceof Error ? err.message : String(err), true);
|
|
4062
|
+
if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
|
|
4063
|
+
return null;
|
|
4064
|
+
})
|
|
4065
|
+
.then(function (created) {
|
|
4066
|
+
if (created === null) { return false; }
|
|
4067
|
+
// Poll the background provision (clone + norms) until it settles.
|
|
4068
|
+
var deadline = Date.now() + 300000;
|
|
4069
|
+
var lastStage = 1;
|
|
4070
|
+
function poll() {
|
|
4071
|
+
if (Date.now() > deadline) {
|
|
4072
|
+
teamAutoSetBindStage(lastStage, "timeout", true);
|
|
4073
|
+
if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
|
|
4074
|
+
return Promise.resolve(false);
|
|
4075
|
+
}
|
|
4076
|
+
return apiRequest("/teamauto/repos", { method: "GET" }).then(function (data) {
|
|
4077
|
+
var list = (data && data.repos) || [];
|
|
4078
|
+
var hit = null;
|
|
4079
|
+
for (var i = 0; i < list.length; i++) { if (list[i] && list[i].id === repo) { hit = list[i]; break; } }
|
|
4080
|
+
var provision = (hit && hit.provision) || (hit ? { status: "ready" } : null);
|
|
4081
|
+
if (!provision) { return new Promise(function (r) { setTimeout(r, 1500); }).then(poll); }
|
|
4082
|
+
if (provision.status === "failed") {
|
|
4083
|
+
teamAutoSetBindStage(lastStage, t("teamauto.bindFailed") + ": " + (provision.message || ""), true);
|
|
4084
|
+
if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
|
|
4085
|
+
return false;
|
|
4086
|
+
}
|
|
4087
|
+
var stage = /norm/i.test(provision.message || "") ? 3 : 2;
|
|
4088
|
+
lastStage = Math.max(lastStage, stage);
|
|
4089
|
+
teamAutoSetBindStage(stage, provision.message || "");
|
|
4090
|
+
if (provision.status === "ready") {
|
|
4091
|
+
teamAutoSetBindStage(4, t("teamauto.bindReady"));
|
|
4092
|
+
setTimeout(function () { overlay.classList.add("is-hidden"); }, 900);
|
|
4093
|
+
return true;
|
|
4094
|
+
}
|
|
4095
|
+
return new Promise(function (r) { setTimeout(r, 1500); }).then(poll);
|
|
4096
|
+
}).catch(function () { return new Promise(function (r) { setTimeout(r, 1500); }).then(poll); });
|
|
4097
|
+
}
|
|
4098
|
+
return poll();
|
|
4099
|
+
});
|
|
4100
|
+
}
|
|
4101
|
+
var refreshBtn = $("#teamauto-repos-refresh");
|
|
4102
|
+
if (refreshBtn && !refreshBtn.dataset.bound) {
|
|
4103
|
+
refreshBtn.dataset.bound = "true";
|
|
4104
|
+
refreshBtn.addEventListener("click", function () {
|
|
4105
|
+
refreshBtn.disabled = true;
|
|
4106
|
+
void loadTeamAutoCandidates(true).finally(function () { refreshBtn.disabled = false; });
|
|
4107
|
+
});
|
|
4108
|
+
}
|
|
4109
|
+
var wrap = $("#teamauto-repos");
|
|
4110
|
+
if (wrap && !wrap.dataset.bound) {
|
|
4111
|
+
wrap.dataset.bound = "true";
|
|
4112
|
+
wrap.addEventListener("click", function (event) {
|
|
4113
|
+
var btn = event.target;
|
|
4114
|
+
if (!(btn instanceof Element) || btn.tagName !== "BUTTON") { return; }
|
|
4115
|
+
var card = btn.closest("[data-repo]");
|
|
4116
|
+
if (!card) { return; }
|
|
4117
|
+
var repoId = card.getAttribute("data-repo");
|
|
4118
|
+
var act = btn.getAttribute("data-act");
|
|
4119
|
+
var encoded = encodeURIComponent(repoId);
|
|
4120
|
+
btn.disabled = true;
|
|
4121
|
+
var call;
|
|
4122
|
+
if (act === "sweep") {
|
|
4123
|
+
call = apiRequest("/teamauto/repos/" + encoded + "/sweep", { method: "POST" })
|
|
4124
|
+
.then(function (body) { teamAutoSetMsg(body && body.summary ? body.summary : "sweep done", true); });
|
|
4125
|
+
} else if (act === "unbind") {
|
|
4126
|
+
if (!window.confirm(t("teamauto.confirmUnbind"))) { btn.disabled = false; return; }
|
|
4127
|
+
call = apiRequest("/teamauto/repos/" + encoded, { method: "DELETE" });
|
|
4128
|
+
} else if (act === "toggle") {
|
|
4129
|
+
var enabling = btn.textContent.trim() !== t("teamauto.disable");
|
|
4130
|
+
call = apiRequest("/teamauto/repos/" + encoded, {
|
|
4131
|
+
method: "PATCH",
|
|
4132
|
+
headers: { "Content-Type": "application/json" },
|
|
4133
|
+
body: JSON.stringify({ enabled: enabling }),
|
|
4134
|
+
});
|
|
4135
|
+
} else if (act === "save") {
|
|
4136
|
+
var payload = {};
|
|
4137
|
+
card.querySelectorAll("[data-cfg]").forEach(function (el) {
|
|
4138
|
+
var key = el.getAttribute("data-cfg");
|
|
4139
|
+
if (key === "schedule") { payload.schedule = el.value.trim(); }
|
|
4140
|
+
if (key === "maxTasksPerSweep") { payload.maxTasksPerSweep = Number(el.value) || undefined; }
|
|
4141
|
+
if (key === "fullReview") { payload.fullReview = el.value; }
|
|
4142
|
+
if (key === "takeOwnership") { payload.takeOwnership = el.value === "true"; }
|
|
4143
|
+
});
|
|
4144
|
+
call = apiRequest("/teamauto/repos/" + encoded, {
|
|
4145
|
+
method: "PATCH",
|
|
4146
|
+
headers: { "Content-Type": "application/json" },
|
|
4147
|
+
body: JSON.stringify(payload),
|
|
4148
|
+
}).then(function () { teamAutoSetMsg(t("teamauto.saved"), true); });
|
|
4149
|
+
}
|
|
4150
|
+
if (call) {
|
|
4151
|
+
call.catch(function (err) { teamAutoSetMsg(err instanceof Error ? err.message : String(err), false); })
|
|
4152
|
+
.finally(function () { refreshTeamAutoTab(); });
|
|
4153
|
+
} else {
|
|
4154
|
+
btn.disabled = false;
|
|
4155
|
+
}
|
|
4156
|
+
});
|
|
4157
|
+
}
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
bindTeamAutoTabEvents();
|
|
4161
|
+
setInterval(function () {
|
|
4162
|
+
if (activeTab === "teamauto") { refreshTeamAutoTab(); }
|
|
4163
|
+
}, 10000);
|
|
4164
|
+
|
|
4165
|
+
|
|
4166
|
+
// Tunnel sharing (internet gate for the local web UI). The settings UI is
|
|
4167
|
+
// a header-triggered popover; while the MANAGED tunnel (*.teamclaw.dev) is
|
|
4168
|
+
// active its URL surfaces as #tunnel-live-pill in the header (self-hosted
|
|
4169
|
+
// hostnames live in the user's Cloudflare dashboard and are not shown).
|
|
4170
|
+
function initTunnelPanel() {
|
|
4171
|
+
const wrap = document.getElementById("tunnel-popover");
|
|
4172
|
+
const pill = document.getElementById("tunnel-live-pill");
|
|
4173
|
+
const toggleBtn = document.getElementById("tunnel-settings-toggle");
|
|
4174
|
+
if (!wrap || wrap.dataset.bound) return;
|
|
4175
|
+
wrap.dataset.bound = "true";
|
|
4176
|
+
const openPopover = () => { wrap.hidden = false; };
|
|
4177
|
+
const closePopover = () => { wrap.hidden = true; };
|
|
4178
|
+
if (toggleBtn) toggleBtn.addEventListener("click", () => { wrap.hidden = !wrap.hidden; });
|
|
4179
|
+
wrap.addEventListener("click", (e) => {
|
|
4180
|
+
if (e.target.getAttribute && e.target.getAttribute("data-act") === "close") closePopover();
|
|
4181
|
+
});
|
|
4182
|
+
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && !wrap.hidden) closePopover(); });
|
|
4183
|
+
// Visitor view: when the dashboard itself is reached through a tunnel
|
|
4184
|
+
// domain, management APIs are gated - degrade to a provenance note
|
|
4185
|
+
// instead of a spinner that can never resolve.
|
|
4186
|
+
const host = (location.hostname || "").toLowerCase();
|
|
4187
|
+
const isLocalView = host === "127.0.0.1" || host === "localhost" || host.endsWith(".local");
|
|
4188
|
+
if (!isLocalView) {
|
|
4189
|
+
wrap.querySelector(".tunnel-state").innerHTML = '<span class="tunnel-note">This dashboard is shared via a TeamClaw tunnel.</span>';
|
|
4190
|
+
if (toggleBtn) toggleBtn.hidden = true;
|
|
4191
|
+
return;
|
|
4192
|
+
}
|
|
4193
|
+
const render = (st) => {
|
|
4194
|
+
// Header pill: managed tunnel only (*.teamclaw.dev). Self-hosted
|
|
4195
|
+
// hostnames are managed in the user's Cloudflare dashboard.
|
|
4196
|
+
if (pill) {
|
|
4197
|
+
if (st.active && st.mode === "managed" && st.hostname) {
|
|
4198
|
+
pill.href = "https://" + st.hostname;
|
|
4199
|
+
pill.textContent = st.hostname;
|
|
4200
|
+
pill.hidden = false;
|
|
4201
|
+
} else {
|
|
4202
|
+
pill.hidden = true;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
var progress = st.startOp && st.startOp.running
|
|
4206
|
+
? '<div class="tunnel-note">Starting tunnel: ' + escapeHtml(st.startOp.phase) + '…</div>'
|
|
4207
|
+
: (st.install && st.install.running
|
|
4208
|
+
? '<div class="tunnel-note">cloudflared ' + escapeHtml(st.install.phase) + (st.install.percent != null ? ' ' + st.install.percent + '%' : '') + '…</div>'
|
|
4209
|
+
: '');
|
|
4210
|
+
if (progress) { wrap.querySelector(".tunnel-state").innerHTML = progress; return; }
|
|
4211
|
+
if (st.active && st.mode === "quick") {
|
|
4212
|
+
wrap.querySelector(".tunnel-state").innerHTML =
|
|
4213
|
+
'<div class="tunnel-on">Quick tunnel: ' + (st.hostname ? '<a href="https://' + st.hostname + '" target="_blank" rel="noopener">https://' + st.hostname + '</a>' : 'waiting for URL…') + '</div>'
|
|
4214
|
+
+ '<div class="tunnel-note">One-off URL - dies on restart. Anyone with the link can open the dashboard.</div>'
|
|
4215
|
+
+ '<button class="btn btn-small" data-act="stop">Stop sharing</button>';
|
|
4216
|
+
return;
|
|
4217
|
+
}
|
|
4218
|
+
if (st.active && st.mode === "self-hosted") {
|
|
4219
|
+
wrap.querySelector(".tunnel-state").innerHTML =
|
|
4220
|
+
'<div class="tunnel-on">Self-hosted Cloudflare tunnel: live on your own domain</div>'
|
|
4221
|
+
+ '<div class="tunnel-note">Public hostname is managed in your Cloudflare Zero Trust dashboard.</div>'
|
|
4222
|
+
+ '<button class="btn btn-small" data-act="stop">Stop sharing</button>';
|
|
4223
|
+
return;
|
|
4224
|
+
}
|
|
4225
|
+
if (st.active) {
|
|
4226
|
+
wrap.querySelector(".tunnel-state").innerHTML =
|
|
4227
|
+
'<div class="tunnel-on">Live: <a href="https://' + st.hostname + '" target="_blank" rel="noopener">https://' + st.hostname + '</a></div>'
|
|
4228
|
+
+ '<div class="tunnel-token">Gate token: <b>' + st.gateToken + '</b></div>'
|
|
4229
|
+
+ '<button class="btn btn-small" data-act="stop">Stop sharing</button>';
|
|
4230
|
+
return;
|
|
4231
|
+
}
|
|
4232
|
+
if (st.cloudflaredInstalled === false) {
|
|
4233
|
+
wrap.querySelector(".tunnel-state").innerHTML = '<div class="tunnel-note">cloudflared connector is not installed.</div>'
|
|
4234
|
+
+ '<button class="btn btn-small btn-primary" data-act="install">Install cloudflared</button>';
|
|
4235
|
+
return;
|
|
4236
|
+
}
|
|
4237
|
+
// Idle: self-hosted (env token detected -> one click; otherwise token
|
|
4238
|
+
// input) alongside the managed share button.
|
|
4239
|
+
var html = '';
|
|
4240
|
+
if (st.envTokenDetected) {
|
|
4241
|
+
html += '<div class="tunnel-note">Connector token detected via TEAMCLAW_TUNNEL_TOKEN — ready to start.</div>'
|
|
4242
|
+
+ '<button class="btn btn-small btn-primary" data-act="start-self">Start self-hosted tunnel</button>';
|
|
4243
|
+
} else {
|
|
4244
|
+
html += '<div class="tunnel-note">Self-hosted tunnel (your own Cloudflare account/domain):</div>'
|
|
4245
|
+
+ '<input type="password" class="tunnel-token-input" data-input="token" placeholder="Cloudflare connector token" autocomplete="off">'
|
|
4246
|
+
+ '<button class="btn btn-small btn-primary" data-act="start-self-token">Start self-hosted tunnel</button>'
|
|
4247
|
+
+ '<details class="tunnel-setup-help"><summary>How to get a token & set up the tunnel</summary>'
|
|
4248
|
+
+ '<div class="tunnel-note">Cloudflare Zero Trust → Networks → Tunnels → your tunnel → copy token. Point its public hostname at this machine’s URL (Service: HTTP + the controller port shown in the docs). Protect it with Cloudflare Access — self-hosted domains skip the TeamClaw gate.</div></details>';
|
|
4249
|
+
}
|
|
4250
|
+
html += '<div class="tunnel-note">— or —</div>'
|
|
4251
|
+
+ '<button class="btn btn-small" data-act="start">Share via *.teamclaw.dev</button>'
|
|
4252
|
+
+ '<span class="tunnel-note">requires GitHub login</span>'
|
|
4253
|
+
+ '<div class="tunnel-note">— or —</div>'
|
|
4254
|
+
+ '<button class="btn btn-small" data-act="start-quick">Anonymous one-off tunnel (trycloudflare.com)</button>'
|
|
4255
|
+
+ '<div class="tunnel-note">No account needed. Random URL, dies on restart, anyone with the link can open the dashboard - use for quick demos only. Needs the cloudflared binary.</div>';
|
|
4256
|
+
wrap.querySelector(".tunnel-state").innerHTML = html;
|
|
4257
|
+
};
|
|
4258
|
+
const refresh = () => apiGet("/tunnel/status").then((st) => render(st || {})).catch(() => {});
|
|
4259
|
+
wrap.addEventListener("click", (e) => {
|
|
4260
|
+
const act = e.target.getAttribute && e.target.getAttribute("data-act");
|
|
4261
|
+
if (!act) return;
|
|
4262
|
+
e.target.disabled = true;
|
|
4263
|
+
var call;
|
|
4264
|
+
if (act === "start-quick") {
|
|
4265
|
+
call = apiRequest("/tunnel/start-quick", { method: "POST" });
|
|
4266
|
+
} else if (act === "start-self" || act === "start-self-token") {
|
|
4267
|
+
const opts = { method: "POST", headers: { "Content-Type": "application/json" } };
|
|
4268
|
+
if (act === "start-self-token") {
|
|
4269
|
+
const input = wrap.querySelector('[data-input="token"]');
|
|
4270
|
+
if (!input || !input.value.trim()) {
|
|
4271
|
+
wrap.querySelector(".tunnel-state").innerHTML = '<div class="tunnel-err">Paste a Cloudflare connector token first.</div>';
|
|
4272
|
+
return;
|
|
4273
|
+
}
|
|
4274
|
+
opts.body = JSON.stringify({ token: input.value.trim() });
|
|
4275
|
+
}
|
|
4276
|
+
call = apiRequest("/tunnel/start-self-hosted", opts);
|
|
4277
|
+
} else {
|
|
4278
|
+
call = act === "start" ? apiRequest("/tunnel/start", { method: "POST" })
|
|
4279
|
+
: act === "install" ? apiRequest("/tunnel/install-cloudflared", { method: "POST" })
|
|
4280
|
+
: apiRequest("/tunnel/stop", { method: "POST" });
|
|
4281
|
+
}
|
|
4282
|
+
call.then(refresh).catch((err) => { wrap.querySelector(".tunnel-state").innerHTML = '<div class="tunnel-err">' + escapeHtml(String(err.message || err)) + "</div>"; });
|
|
4283
|
+
});
|
|
4284
|
+
refresh();
|
|
4285
|
+
setInterval(refresh, 5000);
|
|
4286
|
+
}
|
|
4287
|
+
// Script loads at end of body: DOM is already parsed - run immediately
|
|
4288
|
+
// (DOMContentLoaded may have already fired).
|
|
4289
|
+
initTunnelPanel();
|
|
4290
|
+
})();
|
|
4291
|
+
|
|
4292
|
+
|