@teamclaws/teamclaw 2026.4.4 → 2026.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ui/app.js CHANGED
@@ -5,6 +5,8 @@
5
5
  const API_BASE = "/api/v1";
6
6
  let ws = null;
7
7
  let currentFilter = "all";
8
+ let taskKeywordFilter = "";
9
+ let terminalTasksVisible = 20;
8
10
  let activeTab = "tasks";
9
11
  let teamState = { workers: [], tasks: [], controllerRuns: [], messages: [], clarifications: [], modelReadiness: null, externalWorkerInstall: null };
10
12
  let selectedExternalWorkerRole = "developer";
@@ -46,6 +48,7 @@
46
48
  "tab.planning": "Planning",
47
49
  "tab.tasks": "Tasks",
48
50
  "tab.workspace": "Workspace",
51
+ "tab.teamauto": "TeamAuto",
49
52
  "tab.clarifications": "Clarifications",
50
53
  "tab.messages": "Messages",
51
54
  "tab.manualTask": "Manual Task",
@@ -99,6 +102,41 @@
99
102
  "runtime.title": "TeamClaw is installed but cannot work yet.",
100
103
  "runtime.noModel": "No TeamClaw model is configured for this instance.",
101
104
  "runtime.noAuth": "No usable OpenClaw auth profile was found for TeamClaw.",
105
+ "gh.login": "Sign in with GitHub",
106
+ "teamauto.refreshRepos": "Refresh repos",
107
+ "teamauto.bind": "Bind",
108
+ "teamauto.bindStageVerify": "Verifying access",
109
+ "teamauto.bindStageClone": "Cloning repository",
110
+ "teamauto.bindStageNorms": "Learning repo conventions",
111
+ "teamauto.bindReady": "Repository ready",
112
+ "teamauto.bindFailed": "Binding failed",
113
+ "teamauto.close": "Close",
114
+ "teamauto.provisioning": "preparing",
115
+ "teamauto.provisionFailed": "setup failed",
116
+ "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.",
117
+ "teamauto.loginFirst": "Sign in to GitHub first (top-right Login).",
118
+ "teamauto.loadingRepos": "Loading your repos...",
119
+ "teamauto.noCandidates": "No selectable repos (check GitHub login). You can type owner/repo manually:",
120
+ "teamauto.needRepo": "Select a repository first",
121
+ "teamauto.active": "active",
122
+ "teamauto.disabled": "disabled",
123
+ "teamauto.paused": "paused",
124
+ "teamauto.sweep": "Sweep now",
125
+ "teamauto.disable": "Disable",
126
+ "teamauto.enable": "Enable",
127
+ "teamauto.unbind": "Unbind",
128
+ "teamauto.save": "Save config",
129
+ "teamauto.saved": "Saved",
130
+ "teamauto.schedule": "Schedule",
131
+ "teamauto.maxPerSweep": "Max/sweep",
132
+ "teamauto.fullReview": "Full review",
133
+ "teamauto.takeOwnership": "Take ownership",
134
+ "teamauto.lastSweep": "Last sweep",
135
+ "teamauto.norms": "Norms",
136
+ "teamauto.confirmUnbind": "Unbind this repo?",
137
+ "teamauto.empty": "No repos bound yet. Pick one above and click Bind.",
138
+ "teamauto.activity": "Activity",
139
+ "teamauto.activityEmpty": "No TeamAuto activity yet - sweeps and write-backs will appear here.",
102
140
  "worker.add": "Add worker",
103
141
  "worker.hide": "Hide worker command",
104
142
  "worker.cardTitle": "Register a new external worker",
@@ -115,6 +153,9 @@
115
153
  "filter.blocked": "Blocked",
116
154
  "filter.completed": "Completed",
117
155
  "filter.failed": "Failed",
156
+ "tasks.searchPlaceholder": "Filter by keyword...",
157
+ "tasks.showMore": "Show {n} more completed",
158
+ "tasks.noMatch": "No tasks match the keyword",
118
159
  "priority.low": "Low",
119
160
  "priority.medium": "Medium",
120
161
  "priority.high": "High",
@@ -135,6 +176,7 @@
135
176
  "tab.planning": "规划",
136
177
  "tab.tasks": "任务",
137
178
  "tab.workspace": "工作区",
179
+ "tab.teamauto": "TeamAuto",
138
180
  "tab.clarifications": "澄清",
139
181
  "tab.messages": "消息",
140
182
  "tab.manualTask": "手动任务",
@@ -188,6 +230,41 @@
188
230
  "runtime.title": "TeamClaw 已安装,但当前还无法工作。",
189
231
  "runtime.noModel": "当前实例还没有为 TeamClaw 配置模型。",
190
232
  "runtime.noAuth": "未找到 TeamClaw 可用的 OpenClaw 认证配置。",
233
+ "gh.login": "使用 GitHub 登录",
234
+ "teamauto.refreshRepos": "刷新仓库",
235
+ "teamauto.bind": "绑定",
236
+ "teamauto.bindStageVerify": "验证访问权限",
237
+ "teamauto.bindStageClone": "克隆仓库中",
238
+ "teamauto.bindStageNorms": "学习仓库规范",
239
+ "teamauto.bindReady": "仓库就绪",
240
+ "teamauto.bindFailed": "绑定失败",
241
+ "teamauto.close": "关闭",
242
+ "teamauto.provisioning": "准备中",
243
+ "teamauto.provisionFailed": "准备失败",
244
+ "teamauto.hint": "选择你的 GitHub 仓库。TeamClaw 按各自节奏定时扫描,自主 review issue/PR、认领未分配 issue,并以 teamclaw 标识写回结果。",
245
+ "teamauto.loginFirst": "请先登录 GitHub(右上角 Login)。",
246
+ "teamauto.loadingRepos": "正在加载你的仓库...",
247
+ "teamauto.noCandidates": "无可选仓库(请检查 GitHub 登录),可手动输入 owner/repo:",
248
+ "teamauto.needRepo": "请先选择一个仓库",
249
+ "teamauto.active": "运行中",
250
+ "teamauto.disabled": "已停用",
251
+ "teamauto.paused": "已暂停",
252
+ "teamauto.sweep": "立即扫描",
253
+ "teamauto.disable": "停用",
254
+ "teamauto.enable": "启用",
255
+ "teamauto.unbind": "解绑",
256
+ "teamauto.save": "保存配置",
257
+ "teamauto.saved": "已保存",
258
+ "teamauto.schedule": "节奏",
259
+ "teamauto.maxPerSweep": "每轮上限",
260
+ "teamauto.fullReview": "全量 review",
261
+ "teamauto.takeOwnership": "认领 issue",
262
+ "teamauto.lastSweep": "上次扫描",
263
+ "teamauto.norms": "协作规范",
264
+ "teamauto.confirmUnbind": "确定解绑该仓库?",
265
+ "teamauto.empty": "尚未绑定仓库。在上方选择后点击绑定。",
266
+ "teamauto.activity": "动态",
267
+ "teamauto.activityEmpty": "暂无 TeamAuto 动态-扫描与写回会出现在这里。",
191
268
  "worker.add": "添加 worker",
192
269
  "worker.hide": "隐藏 worker 命令",
193
270
  "worker.cardTitle": "注册新的外部 worker",
@@ -204,6 +281,9 @@
204
281
  "filter.blocked": "阻塞",
205
282
  "filter.completed": "已完成",
206
283
  "filter.failed": "失败",
284
+ "tasks.searchPlaceholder": "关键字过滤...",
285
+ "tasks.showMore": "再显示 {n} 条已结束",
286
+ "tasks.noMatch": "没有匹配关键字的任务",
207
287
  "priority.low": "低",
208
288
  "priority.medium": "中",
209
289
  "priority.high": "高",
@@ -306,8 +386,11 @@
306
386
  function parseInitialUiState() {
307
387
  try {
308
388
  const params = new URLSearchParams(window.location.search || "");
389
+ // Hash routing (#/tab/<name>) wins over legacy query params and survives
390
+ // refresh; query params are kept for old bookmarks/links.
391
+ const hashMatch = /^#\/tab\/([a-z][a-z0-9-]*)$/i.exec(window.location.hash || "");
309
392
  return {
310
- tab: params.get("tab") || "",
393
+ tab: hashMatch ? hashMatch[1] : (params.get("tab") || ""),
311
394
  taskId: params.get("taskId") || "",
312
395
  planningRun: params.get("planningRun") || "",
313
396
  };
@@ -2028,24 +2111,60 @@
2028
2111
  });
2029
2112
  }
2030
2113
 
2114
+ const TERMINAL_STATUSES = { completed: true, failed: true };
2115
+ const PRIORITY_WEIGHT = { critical: 0, high: 1, medium: 2, low: 3 };
2116
+
2117
+ function taskComparator(left, right) {
2118
+ const terminalL = TERMINAL_STATUSES[left.status] ? 1 : 0;
2119
+ const terminalR = TERMINAL_STATUSES[right.status] ? 1 : 0;
2120
+ if (terminalL !== terminalR) { return terminalL - terminalR; }
2121
+ const prioL = PRIORITY_WEIGHT[left.priority || "medium"] ?? 2;
2122
+ const prioR = PRIORITY_WEIGHT[right.priority || "medium"] ?? 2;
2123
+ if (prioL !== prioR) { return prioL - prioR; }
2124
+ return (right.updatedAt || 0) - (left.updatedAt || 0);
2125
+ }
2126
+
2127
+ function taskMatchesKeyword(task, keyword) {
2128
+ if (!keyword) { return true; }
2129
+ const haystack = [task.id, task.title, task.description, task.assignedRole, task.createdBy, task.assignedWorkerId]
2130
+ .filter(Boolean).join(" ").toLowerCase();
2131
+ return haystack.includes(keyword);
2132
+ }
2133
+
2031
2134
  function renderTasks(tasks) {
2032
2135
  const container = $("#tasks-board");
2033
2136
  if (!container) return;
2034
2137
 
2035
- const filtered = currentFilter === "all"
2138
+ const filtered = (currentFilter === "all"
2036
2139
  ? tasks
2037
- : tasks.filter(function (task) { return task.status === currentFilter; });
2140
+ : tasks.filter(function (task) { return task.status === currentFilter; }))
2141
+ .filter(function (task) { return taskMatchesKeyword(task, taskKeywordFilter); });
2038
2142
 
2039
2143
  if (filtered.length === 0) {
2040
2144
  container.innerHTML = '<div class="empty-state">' + escapeHtml(
2041
- currentFilter !== "all"
2042
- ? t("empty.noTasksWithStatus", { status: currentFilter })
2043
- : t("empty.noTasks")
2145
+ taskKeywordFilter
2146
+ ? t("tasks.noMatch")
2147
+ : currentFilter !== "all"
2148
+ ? t("empty.noTasksWithStatus", { status: currentFilter })
2149
+ : t("empty.noTasks")
2044
2150
  ) + "</div>";
2045
2151
  return;
2046
2152
  }
2047
2153
 
2048
- container.innerHTML = filtered.map(function (task) {
2154
+ const sorted = filtered.slice().sort(taskComparator);
2155
+ // Active tasks render in full; terminal ones chunk so long-lived installs
2156
+ // with hundreds of completed tasks stay fast and meaningful.
2157
+ const activeTasks = sorted.filter(function (task) { return !TERMINAL_STATUSES[task.status]; });
2158
+ const terminalTasks = sorted.filter(function (task) { return TERMINAL_STATUSES[task.status]; });
2159
+ const visibleTerminal = terminalTasks.slice(0, terminalTasksVisible);
2160
+ const hiddenTerminal = terminalTasks.length - visibleTerminal.length;
2161
+ const visibleList = activeTasks.concat(visibleTerminal);
2162
+
2163
+ const showMoreHtml = hiddenTerminal > 0
2164
+ ? '<button id="tasks-show-more" class="btn btn-small tasks-show-more" type="button">' + escapeHtml(t("tasks.showMore", { n: hiddenTerminal })) + "</button>"
2165
+ : "";
2166
+
2167
+ container.innerHTML = visibleList.map(function (task) {
2049
2168
  const priority = task.priority || "medium";
2050
2169
  const status = task.status || "pending";
2051
2170
  const assignee = task.assignedWorkerId
@@ -2088,7 +2207,15 @@
2088
2207
  " </div>" +
2089
2208
  "</div>"
2090
2209
  );
2091
- }).join("");
2210
+ }).join("") + showMoreHtml;
2211
+
2212
+ const showMoreBtn = $("#tasks-show-more");
2213
+ if (showMoreBtn) {
2214
+ showMoreBtn.addEventListener("click", function () {
2215
+ terminalTasksVisible += 20;
2216
+ renderTasks(teamState.tasks || []);
2217
+ });
2218
+ }
2092
2219
  }
2093
2220
 
2094
2221
  function renderControllerRuns(runs) {
@@ -2666,11 +2793,32 @@
2666
2793
  }).join("");
2667
2794
  }
2668
2795
 
2796
+ function tabNameFromHash() {
2797
+ const match = /^#\/tab\/([a-z][a-z0-9-]*)$/i.exec(window.location.hash || "");
2798
+ const name = match ? match[1] : "";
2799
+ if (!name) { return ""; }
2800
+ // $$ returns a NodeList: it has forEach but NOT .some - convert first.
2801
+ const known = Array.from($$(".tab")).some(function (item) { return item.dataset.tab === name; });
2802
+ return known ? name : "";
2803
+ }
2804
+
2805
+ function syncTabHash(tab) {
2806
+ try {
2807
+ const target = "#/tab/" + tab;
2808
+ if (window.location.hash !== target) {
2809
+ window.history.replaceState(null, "", target);
2810
+ }
2811
+ } catch (_err) {
2812
+ // Embedded/non-browser hosts without history API - hash is best-effort.
2813
+ }
2814
+ }
2815
+
2669
2816
  function activateTab(nextTab) {
2670
2817
  activeTab = nextTab || "tasks";
2671
2818
  $$(".tab").forEach(function (item) {
2672
2819
  item.classList.toggle("active", item.dataset.tab === activeTab);
2673
2820
  });
2821
+ syncTabHash(activeTab);
2674
2822
  $$(".tab-panel").forEach(function (panel) { panel.classList.remove("active"); });
2675
2823
  const panel = $("#tab-" + activeTab);
2676
2824
  if (panel) {
@@ -2679,6 +2827,9 @@
2679
2827
  if (activeTab === "workspace") {
2680
2828
  refreshWorkspaceTree(false);
2681
2829
  }
2830
+ if (activeTab === "teamauto") {
2831
+ refreshTeamAutoTab();
2832
+ }
2682
2833
  renderActivitySignals();
2683
2834
  }
2684
2835
 
@@ -2688,15 +2839,38 @@
2688
2839
  });
2689
2840
  });
2690
2841
 
2842
+ // Hash deep links: boot on #/tab/<name> (refresh keeps the current tab) and
2843
+ // follow hashchange (browser back/forward between tabs).
2844
+ const bootTab = tabNameFromHash();
2845
+ if (bootTab) {
2846
+ activateTab(bootTab);
2847
+ }
2848
+ window.addEventListener("hashchange", function () {
2849
+ const fromHash = tabNameFromHash();
2850
+ if (fromHash && fromHash !== activeTab) {
2851
+ activateTab(fromHash);
2852
+ }
2853
+ });
2854
+
2691
2855
  $$(".filter-btn").forEach(function (btn) {
2692
2856
  btn.addEventListener("click", function () {
2693
2857
  $$(".filter-btn").forEach(function (item) { item.classList.remove("active"); });
2694
2858
  btn.classList.add("active");
2695
2859
  currentFilter = btn.dataset.filter;
2860
+ terminalTasksVisible = 20;
2696
2861
  renderTasks(teamState.tasks || []);
2697
2862
  });
2698
2863
  });
2699
2864
 
2865
+ const taskKeywordInput = $("#task-keyword");
2866
+ if (taskKeywordInput) {
2867
+ taskKeywordInput.addEventListener("input", function () {
2868
+ taskKeywordFilter = taskKeywordInput.value.trim().toLowerCase();
2869
+ terminalTasksVisible = 20;
2870
+ renderTasks(teamState.tasks || []);
2871
+ });
2872
+ }
2873
+
2700
2874
  const workspaceTreeRefresh = $("#workspace-tree-refresh");
2701
2875
  if (workspaceTreeRefresh) {
2702
2876
  workspaceTreeRefresh.addEventListener("click", function () {
@@ -3097,7 +3271,12 @@
3097
3271
  }
3098
3272
 
3099
3273
  if (initialUiState.tab) {
3100
- activateTab(initialUiState.tab);
3274
+ // Only activate a tab that actually exists (guards stale links).
3275
+ // Array.from: NodeList has no .some.
3276
+ const tabExists = Array.from($$(".tab")).some(function (item) { return item.dataset.tab === initialUiState.tab; });
3277
+ if (tabExists) {
3278
+ activateTab(initialUiState.tab);
3279
+ }
3101
3280
  }
3102
3281
 
3103
3282
  if (initialUiState.taskId) {
@@ -3217,6 +3396,7 @@
3217
3396
  promptWorkspaceIfDefault();
3218
3397
  updateWorkspacePathIndicator();
3219
3398
  bindModelSettings();
3399
+ bindGithubCorner();
3220
3400
 
3221
3401
  function bindModelSettings() {
3222
3402
  /* Module-level IIFE helper: delegated here to keep startup order simple. */
@@ -3272,6 +3452,83 @@
3272
3452
  }
3273
3453
  }
3274
3454
 
3455
+ function bindGithubCorner() {
3456
+ var cornerLogin = document.querySelector("#github-corner-login");
3457
+ if (cornerLogin && !cornerLogin.dataset.bound) {
3458
+ cornerLogin.dataset.bound = "true";
3459
+ cornerLogin.addEventListener("click", function () {
3460
+ window.open("/ui/auth/github", "_blank", "noopener");
3461
+ pollGithubAuthStatus(360);
3462
+ });
3463
+ }
3464
+ var cornerUser = document.querySelector("#github-corner-user");
3465
+ if (cornerUser && !cornerUser.dataset.bound) {
3466
+ cornerUser.dataset.bound = "true";
3467
+ cornerUser.addEventListener("click", function () {
3468
+ apiRequest("/auth/github/logout", { method: "POST" }).catch(function () { /* refresh below regardless */ }).finally(function () {
3469
+ refreshGithubAuthStatus();
3470
+ });
3471
+ });
3472
+ cornerUser.addEventListener("keydown", function (event) {
3473
+ if (event.key === "Enter" || event.key === " ") {
3474
+ event.preventDefault();
3475
+ cornerUser.click();
3476
+ }
3477
+ });
3478
+ }
3479
+ // Keep the header-corner login state fresh.
3480
+ setInterval(refreshGithubAuthStatus, 10000);
3481
+ refreshGithubAuthStatus();
3482
+ }
3483
+
3484
+ var githubAuthPollTimer = null;
3485
+ function pollGithubAuthStatus(attemptsLeft) {
3486
+ if (githubAuthPollTimer) clearTimeout(githubAuthPollTimer);
3487
+ if (attemptsLeft <= 0) return;
3488
+ githubAuthPollTimer = setTimeout(function () {
3489
+ apiGet("/auth/github/status").then(function (status) {
3490
+ if (status && status.authenticated) {
3491
+ renderGithubCorner(status);
3492
+ } else {
3493
+ pollGithubAuthStatus(attemptsLeft - 1);
3494
+ }
3495
+ }).catch(function () {
3496
+ pollGithubAuthStatus(attemptsLeft - 1);
3497
+ });
3498
+ }, 2500);
3499
+ }
3500
+
3501
+ function renderGithubCorner(status) {
3502
+ var loginBtn = document.querySelector("#github-corner-login");
3503
+ var userChip = document.querySelector("#github-corner-user");
3504
+ if (!loginBtn || !userChip) return;
3505
+ if (status.authenticated && status.account) {
3506
+ var nameEl = document.querySelector("#github-corner-name");
3507
+ if (nameEl) nameEl.textContent = "@" + status.account.login;
3508
+ var av = document.querySelector("#github-corner-avatar");
3509
+ if (av) {
3510
+ if (status.account.avatarUrl) {
3511
+ av.src = status.account.avatarUrl;
3512
+ av.classList.remove("hidden");
3513
+ } else {
3514
+ av.classList.add("hidden");
3515
+ }
3516
+ }
3517
+ userChip.classList.remove("hidden");
3518
+ loginBtn.hidden = true;
3519
+ } else {
3520
+ userChip.classList.add("hidden");
3521
+ loginBtn.textContent = t("gh.login");
3522
+ loginBtn.hidden = false;
3523
+ }
3524
+ }
3525
+
3526
+ function refreshGithubAuthStatus() {
3527
+ apiGet("/auth/github/status").then(renderGithubCorner).catch(function () {
3528
+ /* controller offline - keep the corner as-is */
3529
+ });
3530
+ }
3531
+
3275
3532
  function openModelSettings() {
3276
3533
  var modal = document.querySelector("#model-settings-modal");
3277
3534
  if (!modal) return;
@@ -3328,4 +3585,275 @@ function closeModelSettings() {
3328
3585
  modal.classList.remove("open");
3329
3586
  modal.setAttribute("aria-hidden", "true");
3330
3587
  }
3588
+ // ==================== TeamAuto tab ====================
3589
+
3590
+ var teamAutoCandidates = [];
3591
+ var teamAutoCandidatesLoaded = false;
3592
+
3593
+ function teamAutoSetMsg(text, ok) {
3594
+ var el = $("#teamauto-bind-msg");
3595
+ if (!el) { return; }
3596
+ el.textContent = text || "";
3597
+ el.className = "teamauto-msg" + (text ? (ok ? " ok" : " err") : "");
3598
+ }
3599
+
3600
+ function loadTeamAutoCandidates(force) {
3601
+ if (teamAutoCandidatesLoaded && !force) { return Promise.resolve(); }
3602
+ var select = $("#teamauto-repo-select");
3603
+ if (select) { select.innerHTML = '<option>' + escapeHtml(t("teamauto.loadingRepos")) + "</option>"; }
3604
+ return apiGet("/teamauto/repo-candidates").then(function (data) {
3605
+ teamAutoCandidates = (data && data.candidates) || [];
3606
+ teamAutoCandidatesLoaded = true;
3607
+ if (!select) { return; }
3608
+ if (!teamAutoCandidates.length) {
3609
+ select.innerHTML = '<option value="">' + escapeHtml(t("teamauto.noCandidates")) + "</option>";
3610
+ return;
3611
+ }
3612
+ select.innerHTML = teamAutoCandidates.map(function (r) {
3613
+ return '<option value="' + escapeHtml(r.id) + '">' + escapeHtml(r.id + (r.private ? " (private)" : "")) + "</option>";
3614
+ }).join("");
3615
+ }).catch(function (err) {
3616
+ if (select) { select.innerHTML = '<option value="">' + escapeHtml(t("teamauto.loginFirst")) + "</option>"; }
3617
+ teamAutoSetMsg(err instanceof Error ? err.message : String(err), false);
3618
+ });
3619
+ }
3620
+
3621
+ function renderTeamAutoRepos(status) {
3622
+ var wrap = $("#teamauto-repos");
3623
+ if (!wrap) { return; }
3624
+ var repos = (status && status.repos) || [];
3625
+ if (!repos.length) {
3626
+ wrap.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamauto.empty")) + "</div>";
3627
+ return;
3628
+ }
3629
+ wrap.innerHTML = repos.map(function (r) {
3630
+ var badge = !r.enabled
3631
+ ? '<span class="teamauto-badge">' + escapeHtml(t("teamauto.disabled")) + "</span>"
3632
+ : r.provision && r.provision.status === "provisioning"
3633
+ ? '<span class="teamauto-badge" title="' + escapeHtml(r.provision.message || "") + '">' + escapeHtml(t("teamauto.provisioning")) + "</span>"
3634
+ : r.provision && r.provision.status === "failed"
3635
+ ? '<span class="teamauto-badge warn" title="' + escapeHtml(r.provision.message || "") + '">' + escapeHtml(t("teamauto.provisionFailed")) + "</span>"
3636
+ : r.pausedReason
3637
+ ? '<span class="teamauto-badge warn" title="' + escapeHtml(r.pausedReason) + '">' + escapeHtml(t("teamauto.paused")) + "</span>"
3638
+ : '<span class="teamauto-badge on">' + escapeHtml(t("teamauto.active")) + "</span>";
3639
+ var when = r.lastSweepAt ? new Date(r.lastSweepAt).toLocaleString() : "-";
3640
+ var norms = r.norms ? escapeHtml(r.norms.commitStyle) : "...";
3641
+ var fr = r.policy.actions.fullReview;
3642
+ return '<div class="teamauto-card card" data-repo="' + escapeHtml(r.id) + '">' +
3643
+ '<div class="teamauto-card-head"><span class="teamauto-repo-name">' + escapeHtml(r.id) + "</span>" + badge + "</div>" +
3644
+ '<div class="teamauto-meta">' +
3645
+ escapeHtml(t("teamauto.schedule")) + ": <code>" + escapeHtml(r.schedule) + "</code> | " +
3646
+ escapeHtml(t("teamauto.lastSweep")) + ": " + escapeHtml(when) +
3647
+ (r.lastSweepSummary ? " | " + escapeHtml(r.lastSweepSummary) : "") +
3648
+ "<br>" + escapeHtml(t("teamauto.norms")) + ": " + norms +
3649
+ (r.pausedReason ? '<br><span class="teamauto-warn-text">' + escapeHtml(r.pausedReason) + "</span>" : "") +
3650
+ "</div>" +
3651
+ '<div class="teamauto-config-row">' +
3652
+ '<label>' + escapeHtml(t("teamauto.schedule")) + ' <input data-cfg="schedule" type="text" value="' + escapeHtml(r.schedule) + '" spellcheck="false"></label>' +
3653
+ '<label>' + escapeHtml(t("teamauto.maxPerSweep")) + ' <input data-cfg="maxTasksPerSweep" type="number" min="1" max="20" value="' + r.policy.maxTasksPerSweep + '"></label>' +
3654
+ '<label>' + escapeHtml(t("teamauto.fullReview")) + ' <select data-cfg="fullReview">' +
3655
+ ["off", "weekly", "daily"].map(function (v) { return '<option value="' + v + '"' + (fr === v ? " selected" : "") + ">" + v + "</option>"; }).join("") +
3656
+ "</select></label>" +
3657
+ '<label>' + escapeHtml(t("teamauto.takeOwnership")) + ' <select data-cfg="takeOwnership">' +
3658
+ '<option value="true"' + (r.policy.actions.takeOwnership ? " selected" : "") + ">on</option>" +
3659
+ '<option value="false"' + (!r.policy.actions.takeOwnership ? " selected" : "") + ">off</option>" +
3660
+ "</select></label>" +
3661
+ '<button class="btn btn-small" data-act="save">' + escapeHtml(t("teamauto.save")) + "</button>" +
3662
+ "</div>" +
3663
+ '<div class="teamauto-actions">' +
3664
+ '<button class="btn btn-small" data-act="sweep">' + escapeHtml(t("teamauto.sweep")) + "</button>" +
3665
+ '<button class="btn btn-small" data-act="toggle">' + escapeHtml(t(r.enabled ? "teamauto.disable" : "teamauto.enable")) + "</button>" +
3666
+ '<button class="btn btn-small btn-danger" data-act="unbind">' + escapeHtml(t("teamauto.unbind")) + "</button>" +
3667
+ "</div></div>";
3668
+ }).join("");
3669
+ }
3670
+
3671
+ var teamAutoBusy = false;
3672
+ function renderTeamAutoActivity(activity) {
3673
+ var wrap = $("#teamauto-activity");
3674
+ if (!wrap) { return; }
3675
+ var list = activity || [];
3676
+ if (!list.length) {
3677
+ wrap.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamauto.activityEmpty")) + "</div>";
3678
+ return;
3679
+ }
3680
+ wrap.innerHTML = list.slice(0, 30).map(function (e) {
3681
+ var when = new Date(e.at || 0).toLocaleString();
3682
+ return '<div class="teamauto-activity-item">'
3683
+ + '<span class="teamauto-activity-kind k-' + escapeHtml(String(e.kind || "sweep")) + '">' + escapeHtml(String(e.kind || "")) + "</span>"
3684
+ + '<span class="teamauto-activity-text"><b>' + escapeHtml(String(e.repoId || "")) + "</b> " + escapeHtml(String(e.text || "")) + "</span>"
3685
+ + '<span class="teamauto-activity-time">' + escapeHtml(when) + "</span>"
3686
+ + "</div>";
3687
+ }).join("");
3688
+ }
3689
+
3690
+ function refreshTeamAutoTab() {
3691
+ if (teamAutoBusy) { return; }
3692
+ teamAutoBusy = true;
3693
+ void loadTeamAutoCandidates(false);
3694
+ apiGet("/teamauto/repos").then(renderTeamAutoRepos).catch(function () {
3695
+ /* scheduler not running yet */
3696
+ }).finally(function () { teamAutoBusy = false; });
3697
+ apiGet("/teamauto/activity").then(function (data) {
3698
+ renderTeamAutoActivity((data && data.activity) || []);
3699
+ }).catch(function () { /* activity is best-effort */ });
3700
+ }
3701
+
3702
+ function bindTeamAutoTabEvents() {
3703
+ var bindBtn = $("#teamauto-bind");
3704
+ if (bindBtn && !bindBtn.dataset.bound) {
3705
+ bindBtn.dataset.bound = "true";
3706
+ bindBtn.addEventListener("click", function () {
3707
+ var select = $("#teamauto-repo-select");
3708
+ var repo = select ? select.value.trim() : "";
3709
+ if (!repo || !/^[\w.-]+\/[\w.-]+$/.test(repo)) {
3710
+ teamAutoSetMsg(t("teamauto.needRepo"), false);
3711
+ return;
3712
+ }
3713
+ var sched = $("#teamauto-schedule");
3714
+ bindBtn.disabled = true;
3715
+ teamAutoSetMsg("...");
3716
+ teamAutoBindWithOverlay(repo, sched && sched.value.trim() ? sched.value.trim() : undefined)
3717
+ .then(function (ok) {
3718
+ if (ok) { teamAutoSetMsg(repo + " -> " + t("teamauto.active"), true); refreshTeamAutoTab(); }
3719
+ })
3720
+ .finally(function () { bindBtn.disabled = false; });
3721
+ });
3722
+ }
3723
+
3724
+ function teamAutoSetBindStage(stage, note, isError) {
3725
+ var overlay = $("#teamauto-bind-overlay");
3726
+ if (!overlay) { return; }
3727
+ overlay.querySelectorAll(".ta-bind-steps li").forEach(function (li) {
3728
+ var n = parseInt(li.getAttribute("data-stage") || "0", 10);
3729
+ li.classList.toggle("done", !isError && n < stage);
3730
+ li.classList.toggle("active", !isError && n === stage);
3731
+ li.classList.toggle("error", !!isError && n === stage);
3732
+ });
3733
+ var noteEl = $("#teamauto-bind-note");
3734
+ if (noteEl) { noteEl.textContent = note || ""; noteEl.className = "ta-bind-note" + (isError ? " err" : ""); }
3735
+ }
3736
+
3737
+ function teamAutoBindWithOverlay(repo, schedule) {
3738
+ var overlay = $("#teamauto-bind-overlay");
3739
+ var closeBtn = $("#teamauto-bind-overlay-close");
3740
+ var titleEl = $("#teamauto-bind-title");
3741
+ if (!overlay) {
3742
+ return apiRequest("/teamauto/repos", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo, schedule: schedule }) })
3743
+ .then(function () { return true; })
3744
+ .catch(function (err) { teamAutoSetMsg(err instanceof Error ? err.message : String(err), false); return false; });
3745
+ }
3746
+ if (titleEl) { titleEl.textContent = t("teamauto.bind") + ": " + repo; }
3747
+ if (closeBtn) {
3748
+ closeBtn.classList.add("is-hidden");
3749
+ closeBtn.addEventListener("click", function () { overlay.classList.add("is-hidden"); }, { once: true });
3750
+ }
3751
+ overlay.classList.remove("is-hidden");
3752
+ teamAutoSetBindStage(1, "");
3753
+ return apiRequest("/teamauto/repos", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ repo: repo, schedule: schedule }) })
3754
+ .catch(function (err) {
3755
+ teamAutoSetBindStage(1, err instanceof Error ? err.message : String(err), true);
3756
+ if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
3757
+ return null;
3758
+ })
3759
+ .then(function (created) {
3760
+ if (created === null) { return false; }
3761
+ // Poll the background provision (clone + norms) until it settles.
3762
+ var deadline = Date.now() + 300000;
3763
+ var lastStage = 1;
3764
+ function poll() {
3765
+ if (Date.now() > deadline) {
3766
+ teamAutoSetBindStage(lastStage, "timeout", true);
3767
+ if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
3768
+ return Promise.resolve(false);
3769
+ }
3770
+ return apiRequest("/teamauto/repos", { method: "GET" }).then(function (data) {
3771
+ var list = (data && data.repos) || [];
3772
+ var hit = null;
3773
+ for (var i = 0; i < list.length; i++) { if (list[i] && list[i].id === repo) { hit = list[i]; break; } }
3774
+ var provision = (hit && hit.provision) || (hit ? { status: "ready" } : null);
3775
+ if (!provision) { return new Promise(function (r) { setTimeout(r, 1500); }).then(poll); }
3776
+ if (provision.status === "failed") {
3777
+ teamAutoSetBindStage(lastStage, t("teamauto.bindFailed") + ": " + (provision.message || ""), true);
3778
+ if (closeBtn) { closeBtn.classList.remove("is-hidden"); }
3779
+ return false;
3780
+ }
3781
+ var stage = /norm/i.test(provision.message || "") ? 3 : 2;
3782
+ lastStage = Math.max(lastStage, stage);
3783
+ teamAutoSetBindStage(stage, provision.message || "");
3784
+ if (provision.status === "ready") {
3785
+ teamAutoSetBindStage(4, t("teamauto.bindReady"));
3786
+ setTimeout(function () { overlay.classList.add("is-hidden"); }, 900);
3787
+ return true;
3788
+ }
3789
+ return new Promise(function (r) { setTimeout(r, 1500); }).then(poll);
3790
+ }).catch(function () { return new Promise(function (r) { setTimeout(r, 1500); }).then(poll); });
3791
+ }
3792
+ return poll();
3793
+ });
3794
+ }
3795
+ var refreshBtn = $("#teamauto-repos-refresh");
3796
+ if (refreshBtn && !refreshBtn.dataset.bound) {
3797
+ refreshBtn.dataset.bound = "true";
3798
+ refreshBtn.addEventListener("click", function () {
3799
+ refreshBtn.disabled = true;
3800
+ void loadTeamAutoCandidates(true).finally(function () { refreshBtn.disabled = false; });
3801
+ });
3802
+ }
3803
+ var wrap = $("#teamauto-repos");
3804
+ if (wrap && !wrap.dataset.bound) {
3805
+ wrap.dataset.bound = "true";
3806
+ wrap.addEventListener("click", function (event) {
3807
+ var btn = event.target;
3808
+ if (!(btn instanceof Element) || btn.tagName !== "BUTTON") { return; }
3809
+ var card = btn.closest("[data-repo]");
3810
+ if (!card) { return; }
3811
+ var repoId = card.getAttribute("data-repo");
3812
+ var act = btn.getAttribute("data-act");
3813
+ var encoded = encodeURIComponent(repoId);
3814
+ btn.disabled = true;
3815
+ var call;
3816
+ if (act === "sweep") {
3817
+ call = apiRequest("/teamauto/repos/" + encoded + "/sweep", { method: "POST" })
3818
+ .then(function (body) { teamAutoSetMsg(body && body.summary ? body.summary : "sweep done", true); });
3819
+ } else if (act === "unbind") {
3820
+ if (!window.confirm(t("teamauto.confirmUnbind"))) { btn.disabled = false; return; }
3821
+ call = apiRequest("/teamauto/repos/" + encoded, { method: "DELETE" });
3822
+ } else if (act === "toggle") {
3823
+ var enabling = btn.textContent.trim() !== t("teamauto.disable");
3824
+ call = apiRequest("/teamauto/repos/" + encoded, {
3825
+ method: "PATCH",
3826
+ headers: { "Content-Type": "application/json" },
3827
+ body: JSON.stringify({ enabled: enabling }),
3828
+ });
3829
+ } else if (act === "save") {
3830
+ var payload = {};
3831
+ card.querySelectorAll("[data-cfg]").forEach(function (el) {
3832
+ var key = el.getAttribute("data-cfg");
3833
+ if (key === "schedule") { payload.schedule = el.value.trim(); }
3834
+ if (key === "maxTasksPerSweep") { payload.maxTasksPerSweep = Number(el.value) || undefined; }
3835
+ if (key === "fullReview") { payload.fullReview = el.value; }
3836
+ if (key === "takeOwnership") { payload.takeOwnership = el.value === "true"; }
3837
+ });
3838
+ call = apiRequest("/teamauto/repos/" + encoded, {
3839
+ method: "PATCH",
3840
+ headers: { "Content-Type": "application/json" },
3841
+ body: JSON.stringify(payload),
3842
+ }).then(function () { teamAutoSetMsg(t("teamauto.saved"), true); });
3843
+ }
3844
+ if (call) {
3845
+ call.catch(function (err) { teamAutoSetMsg(err instanceof Error ? err.message : String(err), false); })
3846
+ .finally(function () { refreshTeamAutoTab(); });
3847
+ } else {
3848
+ btn.disabled = false;
3849
+ }
3850
+ });
3851
+ }
3852
+ }
3853
+
3854
+ bindTeamAutoTabEvents();
3855
+ setInterval(function () {
3856
+ if (activeTab === "teamauto") { refreshTeamAutoTab(); }
3857
+ }, 10000);
3858
+
3331
3859
  })();