taskcarry 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. taskcarry/__init__.py +3 -0
  2. taskcarry/__main__.py +4 -0
  3. taskcarry/adapter_contracts.py +166 -0
  4. taskcarry/agy_turns.py +282 -0
  5. taskcarry/api.py +111 -0
  6. taskcarry/board.py +313 -0
  7. taskcarry/board_assets/board.css +1087 -0
  8. taskcarry/board_assets/board.js +1187 -0
  9. taskcarry/board_assets/browse.js +214 -0
  10. taskcarry/board_assets/index.html +43 -0
  11. taskcarry/board_assets/taskcarry-icon.ico +0 -0
  12. taskcarry/board_assets/taskcarry-mark.svg +28 -0
  13. taskcarry/board_data.py +466 -0
  14. taskcarry/chat_joins.py +157 -0
  15. taskcarry/cli.py +119 -0
  16. taskcarry/codex_capture.py +184 -0
  17. taskcarry/codex_host.py +293 -0
  18. taskcarry/collaboration_exchange.py +316 -0
  19. taskcarry/connection.py +159 -0
  20. taskcarry/continuity.py +300 -0
  21. taskcarry/contracts.py +165 -0
  22. taskcarry/conversation_capture.py +669 -0
  23. taskcarry/core.py +896 -0
  24. taskcarry/cycle_contracts.py +73 -0
  25. taskcarry/discovery.py +434 -0
  26. taskcarry/discovery_contracts.py +52 -0
  27. taskcarry/exchange_contracts.py +67 -0
  28. taskcarry/exchange_endpoint.py +377 -0
  29. taskcarry/exchange_packets.py +142 -0
  30. taskcarry/experience_contracts.py +129 -0
  31. taskcarry/experience_exchange.py +214 -0
  32. taskcarry/experience_notes.py +433 -0
  33. taskcarry/experience_storage.py +125 -0
  34. taskcarry/experience_tools.py +26 -0
  35. taskcarry/feishu/__init__.py +1 -0
  36. taskcarry/feishu/display.py +122 -0
  37. taskcarry/feishu/project_watch.py +145 -0
  38. taskcarry/feishu/review_sets.py +80 -0
  39. taskcarry/feishu/sender.py +42 -0
  40. taskcarry/feishu/subscription.py +193 -0
  41. taskcarry/feishu/windows_agent.py +287 -0
  42. taskcarry/feishu/windows_secret.py +34 -0
  43. taskcarry/gitops.py +170 -0
  44. taskcarry/governance.py +88 -0
  45. taskcarry/governance_cycle.py +775 -0
  46. taskcarry/identification.py +82 -0
  47. taskcarry/integration.py +663 -0
  48. taskcarry/maintenance.py +118 -0
  49. taskcarry/mcp.py +183 -0
  50. taskcarry/member_join.py +184 -0
  51. taskcarry/member_routing.py +145 -0
  52. taskcarry/onboarding.py +272 -0
  53. taskcarry/onboarding_complete.py +252 -0
  54. taskcarry/path_batches.py +19 -0
  55. taskcarry/preservation.py +257 -0
  56. taskcarry/project_collaboration.py +453 -0
  57. taskcarry/project_history.py +166 -0
  58. taskcarry/project_identity.py +51 -0
  59. taskcarry/project_recovery.py +824 -0
  60. taskcarry/recovery_contracts.py +25 -0
  61. taskcarry/recovery_files.py +153 -0
  62. taskcarry/recovery_git.py +234 -0
  63. taskcarry/remote_capture.py +89 -0
  64. taskcarry/remote_transfer.py +356 -0
  65. taskcarry/role_connection.py +215 -0
  66. taskcarry/setup.py +597 -0
  67. taskcarry/shared_workbench.py +480 -0
  68. taskcarry/skill_data/taskcarry-experience-recovery/SKILL.md +37 -0
  69. taskcarry/skill_data/taskcarry-governance-reconcile/SKILL.md +47 -0
  70. taskcarry/skill_data/taskcarry-governance-reconcile/references/daily-governance.md +72 -0
  71. taskcarry/skill_data/taskcarry-project-setup/SKILL.md +48 -0
  72. taskcarry/skill_data/taskcarry-project-setup/references/onboarding.md +198 -0
  73. taskcarry/skill_data/taskcarry-task-delivery/SKILL.md +32 -0
  74. taskcarry/skill_data/taskcarry-task-delivery/references/conditional-experience.md +93 -0
  75. taskcarry/skill_data/taskcarry-task-delivery/references/worker-channel.md +41 -0
  76. taskcarry/source_review_set.py +80 -0
  77. taskcarry/state_format.py +47 -0
  78. taskcarry/store.py +472 -0
  79. taskcarry/task_context.py +141 -0
  80. taskcarry/text_handback.py +98 -0
  81. taskcarry/transfer_contracts.py +18 -0
  82. taskcarry/updates.py +351 -0
  83. taskcarry/workbench.py +625 -0
  84. taskcarry/workbench_contracts.py +32 -0
  85. taskcarry/workbuddy_capture.py +451 -0
  86. taskcarry/workbuddy_setup.py +212 -0
  87. taskcarry/worker_channel.py +859 -0
  88. taskcarry/worker_contracts.py +190 -0
  89. taskcarry/worker_storage.py +60 -0
  90. taskcarry/worker_tools.py +111 -0
  91. taskcarry-0.3.2.dist-info/METADATA +203 -0
  92. taskcarry-0.3.2.dist-info/RECORD +105 -0
  93. taskcarry-0.3.2.dist-info/WHEEL +5 -0
  94. taskcarry-0.3.2.dist-info/entry_points.txt +5 -0
  95. taskcarry-0.3.2.dist-info/licenses/LICENSE +21 -0
  96. taskcarry-0.3.2.dist-info/licenses/LICENSE_SCOPE.md +31 -0
  97. taskcarry-0.3.2.dist-info/top_level.txt +2 -0
  98. taskcarry_https/__init__.py +1 -0
  99. taskcarry_https/consent.py +207 -0
  100. taskcarry_https/reader.py +132 -0
  101. taskcarry_https/review.py +116 -0
  102. taskcarry_https/server.py +163 -0
  103. taskcarry_https/team.py +335 -0
  104. taskcarry_https/team_host.py +109 -0
  105. taskcarry_https/web_host.py +82 -0
@@ -0,0 +1,1187 @@
1
+ "use strict";
2
+
3
+ const $ = (id) => document.getElementById(id);
4
+ const say = (zh, en) => (english ? en : zh);
5
+ let english = false;
6
+ let ticket = "";
7
+ const launchKey = /^[A-Za-z0-9_-]{43}$/.test(location.hash.slice(1))
8
+ ? location.hash.slice(1)
9
+ : "";
10
+ try {
11
+ english = sessionStorage.getItem("tc-language") === "en";
12
+ ticket = launchKey || sessionStorage.getItem("tc-session") || "";
13
+ if (ticket) sessionStorage.setItem("tc-session", ticket);
14
+ } catch {
15
+ ticket = launchKey;
16
+ }
17
+ if (launchKey) history.replaceState(null, "", location.pathname + location.search);
18
+
19
+ const words = {
20
+ workspace: ["项目工作区", "Workspace"],
21
+ overview: ["项目总览", "Overview"],
22
+ brief: ["项目全局简报", "Project brief"],
23
+ reviews: ["交稿跟进", "Submissions"],
24
+ tasks: ["任务与成员", "Tasks & people"],
25
+ sources: ["共享资料", "Shared work"],
26
+ experience: ["项目经验", "Project lessons"],
27
+ optional: ["可选", "Optional"],
28
+ tools: ["本机工具", "Local tools"],
29
+ local: ["本机", "This computer"],
30
+ localBoard: ["本地看板", "Local board"],
31
+ refresh: ["刷新", "Refresh"],
32
+ skip: ["跳至内容", "Skip to content"],
33
+ };
34
+ const labels = {
35
+ active: ["进行中", "Active"],
36
+ waiting: ["等待中", "Waiting"],
37
+ paused: ["已暂停", "Paused"],
38
+ complete: ["已完成", "Complete"],
39
+ revoked: ["已撤权", "Revoked"],
40
+ proposed: ["提议中", "Proposed"],
41
+ retired: ["已停用", "Retired"],
42
+ received: ["已收件", "Received"],
43
+ technically_received: ["技术已收件", "Technical receipt"],
44
+ needs_revision: ["需要修订", "Revision requested"],
45
+ needs_decision: ["需作决定", "Decision needed"],
46
+ pending: ["待核对", "Awaiting review"],
47
+ unknown: ["证据不足", "Evidence needed"],
48
+ candidate: ["候选可用", "Candidate"],
49
+ not_applicable: ["条件不符", "Conditions differ"],
50
+ review_required: ["需要重估", "Recheck"],
51
+ };
52
+ const boardViews = new Set(["reviews", ...Array.from(document.querySelectorAll(".nav[data-view]"), el => el.dataset.view)]);
53
+ function requestedView() {
54
+ const requested = new URLSearchParams(location.search).get("view");
55
+ return boardViews.has(requested) ? requested : "overview";
56
+ }
57
+ let board,
58
+ view = requestedView(),
59
+ notifications,
60
+ routes,
61
+ release,
62
+ toastTimer;
63
+ let readSerial = 0;
64
+ const word = (key) => words[key][english ? 1 : 0];
65
+ const label = (key) =>
66
+ labels[key]?.[english ? 1 : 0] || key || say("未知", "Unknown");
67
+ const text = (tag, cls, value) => {
68
+ const el = document.createElement(tag);
69
+ if (cls) el.className = cls;
70
+ if (value !== undefined) el.textContent = value;
71
+ return el;
72
+ };
73
+ const box = (...children) => {
74
+ const el = text("div");
75
+ el.append(...children);
76
+ return el;
77
+ };
78
+ function button(caption, className, handler) {
79
+ const el = text("button", className, caption);
80
+ el.type = "button";
81
+ el.addEventListener("click", handler);
82
+ return el;
83
+ }
84
+ function icon(kind) {
85
+ const el = text("i", "ico " + kind);
86
+ el.setAttribute("aria-hidden", "true");
87
+ return el;
88
+ }
89
+ function pill(value, color) {
90
+ return text("span", "pill " + color, value);
91
+ }
92
+ function time(value) {
93
+ if (!value) return say("暂无记录", "No record");
94
+ return new Intl.DateTimeFormat(english ? "en-GB" : "zh-CN", {
95
+ month: "short",
96
+ day: "numeric",
97
+ hour: "2-digit",
98
+ minute: "2-digit",
99
+ hour12: false,
100
+ }).format(new Date(value));
101
+ }
102
+ function member(id) {
103
+ return (
104
+ board.members.items.find((x) => x.binding_id === id)?.display_name ||
105
+ board.owners.find((x) => x.id === id)?.name || id
106
+ );
107
+ }
108
+ function task(id) {
109
+ return board.tasks.items.find((x) => x.task_id === id)?.title || id;
110
+ }
111
+ function taskTag(references, showLabel = true) {
112
+ const tasks = new Map();
113
+ for (const ref of Array.isArray(references) ? references : [references]) {
114
+ if (ref.task_id) tasks.set(ref.task_id, ref.task_title || task(ref.task_id));
115
+ }
116
+ const prefix = say("关联任务:", "Linked task: ");
117
+ const title = [...tasks.values()].join(say("、", ", ")) || say("未关联", "Unassigned");
118
+ const tag = text("span", "task-tag");
119
+ if (showLabel) tag.append(text("span", "task-tag-label", prefix));
120
+ tag.append(text("span", "task-tag-title", title));
121
+ tag.title = prefix + title;
122
+ return tag;
123
+ }
124
+ function announce(message) {
125
+ $("toast").textContent = message;
126
+ $("toast").classList.add("shown");
127
+ clearTimeout(toastTimer);
128
+ toastTimer = setTimeout(() => $("toast").classList.remove("shown"), 2400);
129
+ }
130
+ function clearAnnouncement() {
131
+ clearTimeout(toastTimer);
132
+ $("toast").classList.remove("shown");
133
+ $("toast").textContent = "";
134
+ }
135
+ async function api(path, body) {
136
+ const options = {
137
+ cache: "no-store",
138
+ headers: { "X-TaskCarry-Board": ticket },
139
+ };
140
+ if (body !== undefined) {
141
+ options.method = "POST";
142
+ options.headers["Content-Type"] = "application/json";
143
+ options.body = JSON.stringify(body);
144
+ }
145
+ const response = await fetch("/api/" + path, options);
146
+ const data = await response.json();
147
+ if (!response.ok) throw new Error(data.error || "unavailable");
148
+ return data;
149
+ }
150
+ function errorText(reason) {
151
+ if (reason === "access")
152
+ return say(
153
+ "请从本机启动入口重新打开这个项目的看板。",
154
+ "Reopen this board from its local launcher.",
155
+ );
156
+ if (reason === "BOARD_CHANGED")
157
+ return say(
158
+ "项目已有更新,请刷新后继续。",
159
+ "The project changed. Refresh to continue.",
160
+ );
161
+ if (reason === "CAPTURE_CHANGED" || reason === "CAPTURE_UNAVAILABLE")
162
+ return say("这个对话的设置已有变化,请按成员卡上的最新状态重试。",
163
+ "This chat's settings changed. Check the member card and try again.");
164
+ if (reason === "CAPTURE_HOOK_CHANGED") return say("这个对话的保存配置已手动修改。请让管家核对本目录的设置。","This chat's capture settings were edited manually. Ask your manager to check the workspace settings.");
165
+ if (reason === "HOST_UNAVAILABLE") return say("无法启动本机 Codex 读取程序。请确认 Codex 已安装,再重试。","The local Codex reader could not start. Check that Codex is installed and retry.");
166
+ if (reason === "HOST_TIMEOUT" || reason === "BUSY") return say("读取程序或项目正忙,请稍后再试。","The reader or project is busy. Please retry shortly.");
167
+ if (reason === "invalid")
168
+ return say(
169
+ "请核对输入的两项信息,再试一次。",
170
+ "Check both fields and try again.",
171
+ );
172
+ return say(
173
+ "暂时无法核实这项内容。请刷新或重新打开项目。",
174
+ "This information is unavailable. Refresh or reopen the project.",
175
+ );
176
+ }
177
+ function heading(title, sub) {
178
+ const row = text("div", "page-heading");
179
+ row.append(box(text("h1", "", title), text("p", "meta", sub)));
180
+ return row;
181
+ }
182
+ function sectionHeading(title, action) {
183
+ const row = text("div", "section-head");
184
+ row.append(text("h2", "", title));
185
+ if (action) row.append(action);
186
+ return row;
187
+ }
188
+ function openDialog(kicker, title, ...children) {
189
+ clearAnnouncement();
190
+ readSerial++;
191
+ $("drawer-kicker").textContent = kicker;
192
+ $("drawer-title").textContent = title;
193
+ $("drawer-body").replaceChildren(...children);
194
+ if (!$("drawer").open) $("drawer").showModal();
195
+ }
196
+ function kv(entries) {
197
+ const list = text("dl", "kv");
198
+ for (const [key, value] of entries)
199
+ list.append(text("dt", "", key), text("dd", "", value ?? "—"));
200
+ return list;
201
+ }
202
+ async function refresh() {
203
+ if ($("drawer").open) $("drawer").close();
204
+ $("content").setAttribute("aria-busy", "true");
205
+ $("refresh").disabled = true;
206
+ try {
207
+ board = await api("board");
208
+ clearListCache();
209
+ notifications = null;
210
+ if (view === "tools") await loadTools();
211
+ render();
212
+ } catch (err) {
213
+ board = null;
214
+ const message = text("section", "empty-page");
215
+ message.append(
216
+ text("h1", "", say("本地项目看板", "Local project board")),
217
+ text("p", "detail", errorText(err.message)),
218
+ );
219
+ $("content").replaceChildren(message);
220
+ } finally {
221
+ $("refresh").disabled = false;
222
+ $("content").setAttribute("aria-busy", "false");
223
+ }
224
+ }
225
+ async function setView(next, fromHistory = false) {
226
+ clearAnnouncement();
227
+ if (view !== next) {
228
+ savedScroll[view] = window.scrollY;
229
+ if (!fromHistory) {
230
+ const url = new URL(location.href);
231
+ if (next === "overview") url.searchParams.delete("view");
232
+ else url.searchParams.set("view", next);
233
+ history.pushState(null, "", url.pathname + url.search);
234
+ }
235
+ }
236
+ view = next;
237
+ if (view === "tools" && !notifications) await loadTools();
238
+ render();
239
+ window.scrollTo(0, savedScroll[next] || 0);
240
+ }
241
+ function syncLabels() {
242
+ document.documentElement.lang = english ? "en" : "zh-CN";
243
+ document
244
+ .querySelectorAll("[data-t]")
245
+ .forEach((el) => (el.textContent = word(el.dataset.t)));
246
+ document.querySelectorAll("[data-view]").forEach((el) => {
247
+ const selected = el.dataset.view === view || (view === "reviews" && el.dataset.view === "overview");
248
+ el.classList.toggle("active", selected);
249
+ if (selected) el.setAttribute("aria-current", "page");
250
+ else el.removeAttribute("aria-current");
251
+ });
252
+ $("lang").textContent = english ? "中文" : "EN";
253
+ $("crumb-view").textContent = word(view);
254
+ $("dismiss").setAttribute("aria-label", say("关闭", "Close"));
255
+ }
256
+ function metric(name, n, kind, action) {
257
+ const el = button("", "metric", action);
258
+ const mark = text("span", "metric-icon");
259
+ mark.append(icon(kind));
260
+ el.append(text("span", "name", name), text("strong", "", n), mark);
261
+ return el;
262
+ }
263
+ function kicker(kind, name) {
264
+ const el = text("div", "panel-kicker");
265
+ el.append(icon(kind), text("span", "", name));
266
+ return el;
267
+ }
268
+ function reviewVersion(revision, verdict, color) {
269
+ const el = pill("r" + revision + " " + label(verdict), color);
270
+ el.title = say("交稿第 " + revision + " 版 · ", "Submission revision " + revision + " · ") + label(verdict);
271
+ return el;
272
+ }
273
+ function reviewRow(r) {
274
+ const row = text("li", "submission-row");
275
+ const meta = text("div", "entry-meta");
276
+ meta.append(text("span", "byline", member(r.binding_id)), taskTag(r));
277
+ const timeline = text("div", "review-versions");
278
+ if (r.previous)
279
+ timeline.append(
280
+ reviewVersion(r.previous.handback_revision, r.previous.verdict, "gray"),
281
+ text("span", "revision-arrow", "→"),
282
+ );
283
+ timeline.append(reviewVersion(r.revision, r.verdict || "pending", isPending(r) ? "amber" : "green"));
284
+ row.append(
285
+ text("h3", "submission-title", sourceName(r.sources[0])), meta, timeline,
286
+ button(say("查看本次交稿 · " + r.sources.length + " 份", "View submission · " + r.sources.length + (r.sources.length === 1 ? " file" : " files")), "text-btn review-open", () =>
287
+ showHandback(r),
288
+ ),
289
+ );
290
+ return row;
291
+ }
292
+ function reviewList(items) {
293
+ const list = text("ul", "submission-list");
294
+ for (const item of items) list.append(reviewRow(item));
295
+ return list;
296
+ }
297
+ function experienceCard(item) {
298
+ const el = text("article", "panel insight");
299
+ el.append(kicker("diamond", word("experience")));
300
+ if (!item || item.withheld) {
301
+ el.append(
302
+ text(
303
+ "p",
304
+ "empty",
305
+ item
306
+ ? say("依据暂不可读", "Evidence unavailable")
307
+ : say("尚无可读的经验", "No lessons available"),
308
+ ),
309
+ );
310
+ return el;
311
+ }
312
+ el.append(text("h3", "", item.problem), text("p", "detail", item.suggestion));
313
+ el.append(text("p", "detail", say("适用范围 · ", "Scope · ") +
314
+ (item.scope === "project" ? board.project : task(item.task_id))));
315
+ el.append(
316
+ pill(
317
+ lessonState(item.state),
318
+ item.state === "active" ? "green" : "gray",
319
+ ),
320
+ );
321
+ const actions = text("div", "actions");
322
+ actions.append(
323
+ button(say("查看依据与反馈 →", "View evidence and feedback →"), "text-btn", () =>
324
+ showExperience(item),
325
+ ),
326
+ );
327
+ el.append(actions);
328
+ return el;
329
+ }
330
+ function showExperience(item, back) {
331
+ const rule = (list) =>
332
+ (list || []).map((x) => x.key + " = " + x.equals).join(" · ") || "—";
333
+ const grouped = (item.exclusion_groups || [])
334
+ .map((group) => "(" + rule(group) + ")")
335
+ .join(" / ");
336
+ openDialog(
337
+ word("experience"),
338
+ item.problem,
339
+ text("p", "detail", item.suggestion),
340
+ kv([
341
+ [
342
+ say("适用范围", "Scope"),
343
+ item.scope === "project" ? word("workspace") : task(item.task_id),
344
+ ],
345
+ [
346
+ say("经验状态", "Lifecycle"),
347
+ lessonState(item.state),
348
+ ],
349
+ [say("适用前提", "Prerequisites"), rule(item.applies_when)],
350
+ [
351
+ say("反例", "Exceptions"),
352
+ [rule(item.exclusions), grouped].filter(Boolean).join(" / "),
353
+ ],
354
+ [say("重估条件", "Recheck when"), rule(item.reevaluate_when)],
355
+ [
356
+ say("尚待核对的条件", "Conditions to check"),
357
+ (item.missing_evidence || [])
358
+ .map((x) => (typeof x === "string" ? x : x.key))
359
+ .filter(Boolean)
360
+ .join(" · ") || "—",
361
+ ],
362
+ [
363
+ say("依据的版次", "Evidence revision"),
364
+ item.reason_codes.includes("bound_version_changed")
365
+ ? say(
366
+ "所引用的资料已有新版",
367
+ "The referenced source has a newer revision",
368
+ )
369
+ : "—",
370
+ ],
371
+ [
372
+ say("同版反馈 / 反例", "Feedback / counterevidence"),
373
+ (item.feedback_limited ? "≥" : "") +
374
+ item.feedback_count +
375
+ " / " +
376
+ item.feedback_warning,
377
+ ],
378
+ ]),
379
+ );
380
+ if (back) $("drawer-body").prepend(button(say("‹ 返回资料", "‹ Back to source"), "text-btn", back));
381
+ for (const feedback of item.feedback) {
382
+ const row = text("p", "reading-note");
383
+ row.append(text("strong", "", member(feedback.owner_binding_id) || ""), document.createTextNode(" · " + feedback.summary));
384
+ $("drawer-body").append(row);
385
+ }
386
+ for (const ref of item.basis) {
387
+ const name = ref.display_title || ref.reference_id;
388
+ const caption = name + " · r" + ref.revision + say(" 原文", " original");
389
+ const row = text("div", "actions");
390
+ row.append(
391
+ button(caption, "text-btn", () => showSource(ref)),
392
+ text(
393
+ "span",
394
+ "source-id",
395
+ say("当前 r", "Current r") + ref.current_revision,
396
+ ),
397
+ );
398
+ $("drawer-body").append(row);
399
+ }
400
+ }
401
+ async function copyText(value, message) {
402
+ const languageAtCopy = english;
403
+ try {
404
+ await navigator.clipboard.writeText(value);
405
+ if (languageAtCopy === english) announce(message);
406
+ } catch {
407
+ const input = document.createElement("textarea");
408
+ input.value = value;
409
+ input.readOnly = true;
410
+ openDialog(word("sources"), say("复制引用", "Copy reference"), input);
411
+ input.select();
412
+ }
413
+ }
414
+ function copyRef(ref) {
415
+ return copyText(ref.reference_id + " rev " + ref.revision + " (" + ref.content_sha256.slice(0, 8) + ")",
416
+ say("已复制准确引用", "Exact reference copied"));
417
+ }
418
+ async function showSource(ref, back, handback) {
419
+ openDialog(
420
+ word("sources"),
421
+ ref.display_title || ref.reference_id,
422
+ text("p", "detail", say("正在读取…", "Reading…")),
423
+ );
424
+ const token = readSerial;
425
+ const body = $("drawer-body");
426
+ let original = "";
427
+ const pre = text("pre", "preview");
428
+ const actions = text("div", "actions");
429
+ async function readPage(offset) {
430
+ try {
431
+ const params = new URLSearchParams({
432
+ id: ref.reference_id,
433
+ rev: ref.revision,
434
+ sha: ref.content_sha256,
435
+ offset,
436
+ });
437
+ const data = await api("source?" + params);
438
+ if (token !== readSerial || !$("drawer").open) return;
439
+ original += data.text || "";
440
+ pre.textContent = original;
441
+ actions.replaceChildren(
442
+ button(say("复制给工作对话", "Copy for work chat"), "primary", () => copyFollowup(ref, data.current, handback)),
443
+ button(say("复制准确引用", "Copy exact reference"), "secondary", () => copyRef(ref)),
444
+ button(say("版本记录", "Version history"), "secondary", () =>
445
+ showHistory(ref, () => showSource(ref, back, handback))),
446
+ );
447
+ if (data.next !== null)
448
+ actions.append(
449
+ button(say("读下一页", "Read next page"), "secondary", (e) => {
450
+ e.currentTarget.disabled = true;
451
+ readPage(data.next);
452
+ }),
453
+ );
454
+ const info = document.createElement("details");
455
+ info.append(text("summary", "", say("资料信息与指纹", "Source details and hash")), kv([
456
+ [say("资料编号", "Source"), ref.reference_id],
457
+ [say("关联任务", "Linked task"), data.task_title || task(data.task_id)],
458
+ [say("共享者", "Shared by"), member(data.owner_binding_id)],
459
+ [say("大小", "Size"), data.size + " B"],
460
+ ]), text("p", "full-hash", "SHA-256 " + ref.content_sha256));
461
+ const versionBar = text("div", "actions");
462
+ if (back) versionBar.append(button(say("‹ 返回", "‹ Back"), "text-btn", back));
463
+ versionBar.append(text("span", "rev", say("资料第 ", "Source r") + ref.revision + say(" 版", "")));
464
+ versionBar.append(taskTag(data));
465
+ if (data.current.revision !== ref.revision)
466
+ versionBar.append(button(say("查看最新版 r", "View latest r") + data.current.revision, "text-btn",
467
+ () => showSource(data.current, () => showSource(ref, back, handback))));
468
+ let content = pre;
469
+ if (data.image) {
470
+ content = document.createElement("img");
471
+ content.className = "source-image";
472
+ content.alt = ref.display_title || ref.reference_id;
473
+ content.addEventListener("error", () => content.replaceWith(text("p", "empty",
474
+ say("浏览器无法显示这张图,可复制资料引用。", "This image could not be displayed. You can copy its reference."))));
475
+ content.src = "data:" + data.media_type + ";base64," + data.image;
476
+ } else if (data.text === null) {
477
+ content = text("p", "empty", data.image_unavailable === "size"
478
+ ? say("这张图超过 4 MiB,可复制准确引用在工作对话中查看。", "Image exceeds 4 MiB. Use its reference in your work chat.")
479
+ : say("此格式只显示文件信息。", "Metadata only for this format."));
480
+ }
481
+ body.replaceChildren(versionBar, actions, content, info);
482
+ for (const related of data.related) {
483
+ const caption = say("相关经验 · ", "Related lesson · ") + related.note.problem +
484
+ " (" + say("引用 ", "cites ") + related.cited_revisions.map(n => "r" + n).join(", ") + ")";
485
+ body.append(button(caption, "text-btn", () =>
486
+ showExperience(related.note, () => showSource(ref, back, handback))));
487
+ }
488
+ if (data.limited)
489
+ body.append(
490
+ text(
491
+ "p",
492
+ "detail",
493
+ say("已到预览大小上限。", "Preview size limit reached."),
494
+ ),
495
+ );
496
+ } catch (err) {
497
+ if (token === readSerial)
498
+ body.replaceChildren(text("p", "message", errorText(err.message)));
499
+ }
500
+ }
501
+ await readPage(0);
502
+ }
503
+ function sourceTable(items) {
504
+ const frame = text("div", "tablebox");
505
+ if (!items.length) {
506
+ frame.append(
507
+ text(
508
+ "p",
509
+ "empty",
510
+ say("尚无项目共享资料。", "No project-shared work yet."),
511
+ ),
512
+ );
513
+ return frame;
514
+ }
515
+ const table = document.createElement("table");
516
+ const head = table.createTHead().insertRow();
517
+ for (const name of [
518
+ say("成果名称", "Work"),
519
+ say("关联任务", "Linked task"),
520
+ say("修订", "Revision"),
521
+ say("共享者", "Shared by"),
522
+ say("指纹 / 复制", "Hash / Copy"),
523
+ say("更新时间", "Updated"),
524
+ ])
525
+ head.append(text("th", "", name));
526
+ const body = table.createTBody();
527
+ for (const ref of items) {
528
+ const row = body.insertRow();
529
+ const doc = text("div", "doc-row");
530
+ const mark = text("span", "doc-icon");
531
+ mark.append(icon("files"));
532
+ doc.append(
533
+ mark,
534
+ box(
535
+ button(ref.display_title || ref.reference_id, "doc-title", () =>
536
+ showSource(ref),
537
+ ),
538
+ text("small", "", ref.reference_id),
539
+ ),
540
+ );
541
+ row.insertCell().append(doc);
542
+ row.insertCell().append(taskTag(ref, false));
543
+ row.insertCell().append(text("span", "rev", "r" + ref.revision));
544
+ row.insertCell().textContent = member(ref.owner_binding_id);
545
+ const copy = button(ref.content_sha256.slice(0, 8), "copy", () =>
546
+ copyRef(ref),
547
+ );
548
+ copy.append(icon("files"));
549
+ copy.setAttribute(
550
+ "aria-label",
551
+ say("复制引用 ", "Copy reference ") + ref.reference_id,
552
+ );
553
+ row.insertCell().append(copy);
554
+ row.insertCell().textContent = ref.published_at
555
+ ? time(ref.published_at)
556
+ : say("时间未知", "Unknown");
557
+ }
558
+ frame.append(table);
559
+ return frame;
560
+ }
561
+ function gotoButton(name, target) {
562
+ return button(name + " →", "text-btn", () => setView(target));
563
+ }
564
+ function overview(main) {
565
+ main.append(
566
+ heading(
567
+ board.project,
568
+ say("最近项目更新 ", "Last project update ") + time(board.updated_at),
569
+ ),
570
+ );
571
+ const kpis = text("section", "kpis");
572
+ kpis.append(
573
+ metric(say("工作任务", "Tasks"), board.tasks.total, "tasks", () => setView("tasks")),
574
+ metric(say("已登记岗位", "Registered roles"), board.members.total, "grid", async () => {
575
+ await setView("tasks");
576
+ $("people-section").scrollIntoView();
577
+ }),
578
+ metric(word("sources"), board.sources.total, "files", () => setView("sources")),
579
+ metric(
580
+ say("待处理交稿", "Pending reviews"),
581
+ board.reviews.pending,
582
+ "diamond",
583
+ openPending,
584
+ ),
585
+ );
586
+ const pending = board.reviews.items.filter(isPending).slice(0, 3);
587
+ main.append(
588
+ kpis,
589
+ sectionHeading(say("需要跟进", "Needs attention"),
590
+ button(say("查看交稿记录 →", "All submissions →"), "text-btn", () => openReviews(""))),
591
+ pending.length ? reviewList(pending) : text("p", "empty overview-empty", say("当前没有待跟进的交稿。", "No submissions need attention.")),
592
+ sectionHeading(
593
+ say("最近共享", "Recent publications"),
594
+ gotoButton(say("全部资料", "All sources"), "sources"),
595
+ ),
596
+ recentPublications(board.recent),
597
+ );
598
+ }
599
+ function more(main, section) {
600
+ const group = board[section];
601
+ if (!group.more) return;
602
+ const area = text("div", "section-foot");
603
+ area.append(
604
+ button(say("显示更多", "Show more"), "secondary", async (e) => {
605
+ e.currentTarget.disabled = true;
606
+ try {
607
+ const batch = await api(
608
+ "page?" +
609
+ new URLSearchParams({
610
+ section,
611
+ page: group.page + 1,
612
+ stamp: board.stamp,
613
+ }),
614
+ );
615
+ group.items.push(...batch.items);
616
+ group.page = batch.page;
617
+ group.more = batch.more;
618
+ render();
619
+ } catch (err) {
620
+ announce(errorText(err.message));
621
+ render();
622
+ }
623
+ }),
624
+ );
625
+ main.append(area);
626
+ }
627
+ function taskRows(items) {
628
+ const list = text("div", "list");
629
+ for (const item of items) {
630
+ const card = text("article", "line-card task-row");
631
+ card.append(
632
+ text("h3", "", item.title || item.task_id),
633
+ pill(
634
+ label(item.state),
635
+ { active: "blue", waiting: "amber", paused: "gray", complete: "green" }[
636
+ item.state
637
+ ] || "gray",
638
+ ),
639
+ );
640
+ list.append(card);
641
+ }
642
+ if (!list.children.length)
643
+ list.append(text("p", "empty", say("暂无任务。", "No tasks yet.")));
644
+ return list;
645
+ }
646
+ function tasks(main) {
647
+ main.append(heading(word("tasks"), board.project), sectionHeading(say("工作任务", "Tasks")));
648
+ browseSection(main, "tasks");
649
+ const people = text("section", "section-gap");
650
+ people.id = "people-section";
651
+ people.append(sectionHeading(say("项目成员", "Members")));
652
+ const cards = text("div", "members");
653
+ const former = text("div", "members");
654
+ const captureSlots = new Map();
655
+ for (const m of board.members.items) {
656
+ const card = text("article", "panel member");
657
+ const name = m.role_label || m.display_name || m.binding_id;
658
+ card.append(text("h3", "", name), text("p", "detail", board.project));
659
+ if (board.settings_enabled && m.state === "active" && ["governor", "worker"].includes(m.role)) {
660
+ const slot = text("div", "member-capture");
661
+ card.append(slot);
662
+ captureSlots.set(m.binding_id, {slot, name});
663
+ }
664
+ (m.state === "revoked" ? former : cards).append(card);
665
+ }
666
+ people.append(cards);
667
+ if (captureSlots.size) {
668
+ const help = text("p", "capture-help", say(
669
+ "开启后,队友可按需读取这个对话最近共享的 8 轮问答。关闭后停止新增,已共享的问答仍可读。",
670
+ "When on, teammates can read the last 8 shared exchanges in this chat. Turning sharing off stops new exchanges and keeps those already shared available."));
671
+ help.id = "member-capture-help";
672
+ people.append(help);
673
+ }
674
+ if (former.childElementCount) {
675
+ const past = document.createElement("details");
676
+ past.className = "former-members";
677
+ past.append(text("summary", "", say("已撤回的岗位", "Revoked roles") + " (" + former.childElementCount + ")"), former);
678
+ people.append(past);
679
+ }
680
+ main.append(people);
681
+ more(main, "members");
682
+ if (captureSlots.size) memberCaptures(captureSlots);
683
+ }
684
+ async function loadTools() {
685
+ try {
686
+ notifications = await api("reminders");
687
+ } catch {
688
+ notifications = { error: true };
689
+ }
690
+ }
691
+ function formPanel(action) {
692
+ const real = board.settings_enabled && !board.standby;
693
+ const secretField = (name, title) => {
694
+ const wrap = text("label", "form-label", title);
695
+ const input = document.createElement("input");
696
+ input.name = name;
697
+ input.type = "password";
698
+ input.autocomplete = "off";
699
+ input.required = true;
700
+ input.readOnly = !real;
701
+ input.maxLength = name === "url" ? 2048 : 1024;
702
+ wrap.append(input);
703
+ return [wrap, input];
704
+ };
705
+ const form = document.createElement("form");
706
+ const [addressLabel, url] = secretField(
707
+ "url",
708
+ say("机器人 Webhook 地址", "Robot webhook URL"),
709
+ );
710
+ url.placeholder = "https://open.feishu.cn/open-apis/bot/v2/hook/…";
711
+ const [keyLabel, secret] = secretField(
712
+ "secret",
713
+ say("签名密钥", "Signing key"),
714
+ );
715
+ const submit = text(
716
+ "button",
717
+ "primary",
718
+ say("保存并开启提醒", "Save and turn on"),
719
+ );
720
+ submit.type = "submit";
721
+ const updateSubmit = () => { submit.disabled = !real || !url.value.trim() || !secret.value.trim(); };
722
+ updateSubmit();
723
+ form.addEventListener("input", updateSubmit);
724
+ const actions = text("div", "actions");
725
+ actions.append(submit);
726
+ const info = text(
727
+ "p",
728
+ "detail",
729
+ real
730
+ ? say(
731
+ "本项目新共享的成果会发送到这个机器人所在的群。",
732
+ "New project shares go to the group for this robot.",
733
+ )
734
+ : say(
735
+ "此预览只展示设置。请在自己的项目看板中配置。",
736
+ "Settings preview. Configure notifications in your own project board.",
737
+ ),
738
+ );
739
+ form.append(info, addressLabel, keyLabel, actions);
740
+ form.addEventListener("submit", async (e) => {
741
+ e.preventDefault();
742
+ if (!real) return;
743
+ const values = { action: "enable", url: url.value, secret: secret.value };
744
+ url.value = "";
745
+ secret.value = "";
746
+ submit.disabled = true;
747
+ await change(values);
748
+ updateSubmit();
749
+ });
750
+ openDialog(
751
+ word("tools"),
752
+ action === "change"
753
+ ? say("更换飞书机器人", "Change Feishu robot")
754
+ : say("设置飞书机器人", "Set up Feishu robot"),
755
+ form,
756
+ );
757
+ }
758
+ async function change(body) {
759
+ try {
760
+ notifications = await api("reminders", body);
761
+ if ($("drawer").open) $("drawer").close();
762
+ render();
763
+ announce(say("提醒设置已更新", "Notification settings updated"));
764
+ } catch (err) {
765
+ announce(errorText(err.message));
766
+ }
767
+ }
768
+ function toolsPage(main) {
769
+ main.append(heading(word("tools"), board.project));
770
+ const card = text("section", "panel tool-card");
771
+ card.append(
772
+ kicker("sliders", say("项目通知", "Project notifications")),
773
+ text("h3", "", say("飞书群提醒", "Feishu group updates")),
774
+ );
775
+ const n = notifications;
776
+ if (!n || n.error || !n.supported)
777
+ card.append(
778
+ text(
779
+ "p",
780
+ "detail",
781
+ n?.error
782
+ ? say("状态暂不可读", "Status unavailable")
783
+ : say("此功能适用于 Windows。", "Available on Windows."),
784
+ ),
785
+ );
786
+ else {
787
+ card.append(
788
+ pill(
789
+ n.enabled
790
+ ? n.running
791
+ ? say("提醒已开启", "On")
792
+ : say("已开启,后台未确认", "Enabled, process unconfirmed")
793
+ : n.configured
794
+ ? say("提醒已暂停", "Paused")
795
+ : say("尚未配置", "Not configured"),
796
+ n.enabled ? "green" : "gray",
797
+ ),
798
+ );
799
+ card.append(
800
+ text(
801
+ "p",
802
+ "detail",
803
+ say(
804
+ "只把本项目新共享的成果发到指定群。关闭看板后,已开启的提醒会继续发送。",
805
+ "New project shares go to the chosen group. Closing the board leaves enabled updates running.",
806
+ ),
807
+ ),
808
+ kv([
809
+ [
810
+ say("登录后自动恢复", "At Windows sign-in"),
811
+ n.login_start === null
812
+ ? say("未知", "Unknown")
813
+ : n.login_start
814
+ ? say("已开启", "On")
815
+ : say("未开启", "Off"),
816
+ ],
817
+ [
818
+ say("最近成功发送", "Last accepted"),
819
+ time(n.last_success ? n.last_success * 1000 : null),
820
+ ],
821
+ [
822
+ say("已发送 / 失败 / 待核实", "Accepted / failed / unknown"),
823
+ [n.accepted, n.failed, n.unknown].join(" / "),
824
+ ],
825
+ ]),
826
+ );
827
+ const a = text("div", "actions");
828
+ const setup = button(
829
+ n.configured
830
+ ? say("更换机器人", "Change robot")
831
+ : say("设置机器人", "Set up robot"),
832
+ "primary",
833
+ () => formPanel(n.configured ? "change" : "first"),
834
+ );
835
+ a.append(setup);
836
+ if (n.configured) {
837
+ const toggle = button(
838
+ n.enabled
839
+ ? say("暂停群提醒", "Pause updates")
840
+ : say("恢复群提醒", "Resume updates"),
841
+ "secondary",
842
+ () => change({ action: n.enabled ? "pause" : "resume" }),
843
+ );
844
+ toggle.disabled = !board.settings_enabled || board.standby;
845
+ a.append(toggle);
846
+ const forget = button(
847
+ say("停用并清除", "Turn off and clear"),
848
+ "secondary",
849
+ () =>
850
+ openDialog(
851
+ word("tools"),
852
+ say("清除本项目的机器人?", "Clear this project’s robot?"),
853
+ text(
854
+ "p",
855
+ "detail",
856
+ board.project +
857
+ " · " +
858
+ say(
859
+ "群提醒将停止,保存的地址和签名密钥会从本机订阅中清除。",
860
+ "Updates will stop and saved credentials will be cleared.",
861
+ ),
862
+ ),
863
+ button(say("确认停用并清除", "Confirm removal"), "secondary", () =>
864
+ change({ action: "forget" }),
865
+ ),
866
+ button(say("取消", "Cancel"), "secondary", () => $("drawer").close()),
867
+ ),
868
+ );
869
+ forget.disabled = toggle.disabled;
870
+ a.append(forget);
871
+ }
872
+ card.append(a);
873
+ if (!board.settings_enabled || board.standby)
874
+ card.append(text("p", "detail", say("如需管理群提醒,请打开负责发送提醒的电脑上的主项目看板。",
875
+ "To manage these updates, open the primary project board on the computer that sends them.")));
876
+ }
877
+ main.append(card);
878
+ const pair = text("div", "split");
879
+ const route = text("article", "panel tool-card");
880
+ route.append(
881
+ kicker("window", say("跨机协作", "Remote access")),
882
+ text("h3", "", say("本机协作入口", "Local collaboration routes")),
883
+ );
884
+ const result = text("div", "route-result");
885
+ result.setAttribute("role", "status");
886
+ const check = button("", "secondary", async () => {
887
+ routes = { state: "checking" };
888
+ showRoutes();
889
+ try {
890
+ routes = await api("routes", {});
891
+ } catch {
892
+ routes = { state: "unknown" };
893
+ }
894
+ routes.checkedAt = new Date();
895
+ if (route.isConnected) showRoutes();
896
+ else if (view === "tools") render();
897
+ });
898
+ function showRoutes() {
899
+ result.replaceChildren();
900
+ check.disabled = routes?.state === "checking";
901
+ check.textContent = !routes ? say("检查入口", "Check routes") : check.disabled
902
+ ? say("正在检查…", "Checking…") : say("重新检查", "Check again");
903
+ if (routes?.state === "checked") {
904
+ const state = enabled => enabled ? say("已配置", "Configured") : say("未配置", "Not configured");
905
+ result.append(kv([
906
+ [say("私网入口(Serve)", "Private HTTPS (Serve)"), state(routes.serve)],
907
+ [say("公网入口(Funnel)", "Public HTTPS (Funnel)"), state(routes.funnel)],
908
+ ]));
909
+ } else {
910
+ const message = {
911
+ checking: say("正在读取本机 Tailscale 配置…", "Reading this computer’s Tailscale settings…"),
912
+ unavailable: say("本机未找到 Tailscale。安装后可重新检查。", "Tailscale was not found on this computer. Install it and check again."),
913
+ timeout: say("检查超时。请确认 Tailscale 正在运行,再重新检查。", "The check timed out. Make sure Tailscale is running and try again."),
914
+ unknown: say("未能读取入口状态。请查看本机 Tailscale 后重新检查。", "Could not read the route status. Check Tailscale on this computer and try again."),
915
+ };
916
+ result.append(text("p", "detail", message[routes?.state] ||
917
+ say("查看这台电脑已配置的 Tailscale HTTPS 入口。", "Check the Tailscale HTTPS routes configured on this computer.")));
918
+ }
919
+ if (routes?.checkedAt)
920
+ result.append(text("p", "detail", say("检查时间 ", "Checked at ") +
921
+ routes.checkedAt.toLocaleTimeString(english ? "en-GB" : "zh-CN", {hour12: false})));
922
+ }
923
+ showRoutes();
924
+ route.append(result, check);
925
+ const version = text("article", "panel tool-card");
926
+ version.append(
927
+ kicker("files", say("版本", "Version")),
928
+ text("h3", "", say("官方发行版本", "Official releases")),
929
+ text(
930
+ "p",
931
+ "detail",
932
+ say("本机运行版本 ", "Running version ") + board.runtime_version,
933
+ ),
934
+ );
935
+ if (release) {
936
+ const msg =
937
+ release.confirmed && release.version
938
+ ? say("已核实的正式版本 ", "Verified stable release ") + release.version
939
+ : say(
940
+ "本次未能确认最新正式版。",
941
+ "Latest stable release not confirmed.",
942
+ );
943
+ version.append(text("p", "detail", msg));
944
+ }
945
+ version.append(
946
+ button(say("检查更新", "Check for updates"), "secondary", async (e) => {
947
+ e.currentTarget.disabled = true;
948
+ try {
949
+ release = await api("release", {});
950
+ } catch {
951
+ release = { state: "unknown" };
952
+ }
953
+ render();
954
+ }),
955
+ );
956
+ if (release?.url) {
957
+ const link = text("a", "text-btn", say(" 查看发行页", " Release details"));
958
+ link.href = release.url;
959
+ link.target = "_blank";
960
+ link.rel = "noreferrer";
961
+ version.append(link);
962
+ }
963
+ pair.append(route, version);
964
+ main.append(pair);
965
+ }
966
+ const queryApi = (name, fields) =>
967
+ api(name + "?" + new URLSearchParams(Object.entries(fields).filter(([, v]) => v !== undefined && v !== null && v !== "")));
968
+ async function openBriefEntry(revision, id) {
969
+ const page = view;
970
+ try {
971
+ const {entry} = await queryApi("project_overview", {revision, entry_id:id});
972
+ if (view === page) openDialog(word("brief"), entry.title, text("p","detail",entry.summary), ...recordLinks(entry));
973
+ } catch (err) { announce(errorText(err.message)); }
974
+ }
975
+
976
+ function projectBrief(main) {
977
+ const panel = text("section", "panel project-brief");
978
+ panel.setAttribute("aria-label", word("brief"));
979
+ main.append(heading(word("brief"), board.project), panel);
980
+ renderSnapshot(panel);
981
+ }
982
+
983
+ async function renderSnapshot(panel, revision, cursors = []) {
984
+ try {
985
+ panel.setAttribute("aria-busy", "true");
986
+ panel.querySelectorAll("button").forEach(el => { el.disabled = true; });
987
+ const result = await queryApi("project_overview", { revision, cursor: cursors.at(-1), limit: 12 });
988
+ if (!panel.isConnected) return;
989
+ panel.replaceChildren();
990
+ if (!result.published) {
991
+ panel.append(text("p", "meta", say("管家尚未发布简报。", "The first project brief is pending.")));
992
+ return;
993
+ }
994
+ panel.append(text("p", "meta", "r" + result.revision + " · " + time(result.updated_at)));
995
+ if (result.later_evidence) panel.append(text("p","meta",say("此版之后还有项目更新。","New project records are available since this revision.")));
996
+ for (const entry of result.items) {
997
+ const row = text("div", "brief-entry");
998
+ row.append(button(entry.title, "text-btn", () => openBriefEntry(result.revision, entry.id)), text("p", "detail", entry.summary));
999
+ panel.append(row);
1000
+ }
1001
+ const actions = text("div", "actions");
1002
+ if (cursors.length) actions.append(button(say("上一页", "Previous page"), "quiet",
1003
+ () => renderSnapshot(panel, result.revision, cursors.slice(0, -1))));
1004
+ if (result.next_cursor) actions.append(button(say("下一页", "Next page"), "quiet",
1005
+ () => renderSnapshot(panel, result.revision, [...cursors, result.next_cursor])));
1006
+ if (result.revision > 1) actions.append(button(say("上一版", "Previous revision"), "quiet",
1007
+ () => renderSnapshot(panel, result.revision - 1)));
1008
+ if (revision) actions.append(button(say("返回最新版", "Latest revision"), "quiet", () => renderSnapshot(panel)));
1009
+ if (actions.childElementCount) panel.append(actions);
1010
+ } catch (err) {
1011
+ if (panel.isConnected) panel.replaceChildren(text("p", "meta", errorText(err.message)));
1012
+ } finally {
1013
+ panel.removeAttribute("aria-busy");
1014
+ }
1015
+ }
1016
+
1017
+ async function openDecision(title, fields) {
1018
+ openDialog(say("项目历史", "Project history"), title);
1019
+ const serial = readSerial;
1020
+ const body = $("drawer-body");
1021
+ const pre = text("pre", "preview");
1022
+ const next = button(say("下一页", "Next page"), "quiet", () => read(offset));
1023
+ let offset = 0;
1024
+ async function read(position) {
1025
+ next.disabled = true;
1026
+ try {
1027
+ const data = await queryApi("project_history", { ...fields, offset: position });
1028
+ if (serial !== readSerial) return;
1029
+ pre.textContent += data.text;
1030
+ offset = data.next_offset;
1031
+ next.hidden = data.complete;
1032
+ next.disabled = false;
1033
+ if (data.complete) {
1034
+ const record = JSON.parse(pre.textContent);
1035
+ pre.textContent = JSON.stringify(record, null, 2);
1036
+ }
1037
+ } catch (err) { if (serial === readSerial) announce(errorText(err.message)); }
1038
+ }
1039
+ body.append(pre, next);
1040
+ await read(0);
1041
+ }
1042
+
1043
+ function recordLinks(record) {
1044
+ const links = (record.sources || []).map(ref => button(ref.reference_id + " · r" + ref.revision, "text-btn",
1045
+ () => showSource(ref)));
1046
+ if (record.decision) links.push(button(say("查看决定依据", "Read the decision"), "text-btn",
1047
+ () => openDecision(say("决定原件", "Decision record"), record.decision)));
1048
+ return links;
1049
+ }
1050
+
1051
+ const chosenChat = new Map();
1052
+ async function memberCaptures(slots, focusOwner) {
1053
+ let inventory;
1054
+ try { inventory = await api("capture"); }
1055
+ catch (err) {
1056
+ for (const {slot} of slots.values()) {
1057
+ if (slot.isConnected) slot.replaceChildren(button(say("重新读取对话设置","Retry conversation settings"),
1058
+ "text-btn", () => memberCaptures(slots)));
1059
+ }
1060
+ return;
1061
+ }
1062
+ for (const [owner, {slot, name}] of slots) {
1063
+ if (!slot.isConnected) continue;
1064
+ const chats = inventory.sessions.filter(item => item.owner === owner);
1065
+ slot.replaceChildren();
1066
+ const active = chats.filter(item => item.state === "active");
1067
+ const configured = chats.filter(item => item.generation > 0);
1068
+ const item = chats.length === 1 ? chats[0] : chats.find(c => c.conversation_id === chosenChat.get(owner))
1069
+ || (active.length === 1 ? active[0] : configured.length === 1 ? configured[0] : null);
1070
+ if (chats.length > 1) {
1071
+ const selector = text("select","chat-select");
1072
+ selector.setAttribute("aria-label", say("选择对话","Select chat") + " · " + name);
1073
+ const placeholder = text("option","",say("选择要设置的对话","Select a chat")); placeholder.value = "";
1074
+ selector.append(placeholder);
1075
+ for (const c of chats) {
1076
+ const option = text("option","", (c.provider || "AGY") + " · " + c.conversation_id.slice(0,8)
1077
+ + (c.state === "active" ? say(" · 已开启"," · On") : ""));
1078
+ option.value = c.conversation_id; option.title = c.conversation_id; selector.append(option);
1079
+ }
1080
+ selector.value = item?.conversation_id || "";
1081
+ selector.onchange = () => { chosenChat.set(owner, selector.value); memberCaptures(slots,owner); };
1082
+ slot.append(selector);
1083
+ }
1084
+ const on = item?.state === "active";
1085
+ const caption = say("保存对话原文","Save transcript");
1086
+ async function change(action) {
1087
+ status.textContent = on ? say("关闭中", "Stopping…") : say("开启中", "Starting…");
1088
+ toggle.setAttribute("aria-busy","true");
1089
+ slot.querySelectorAll("button,select").forEach(el => { el.disabled = true; });
1090
+ try {
1091
+ await api("capture",{owner,conversation_id:item.conversation_id,action,generation:item.generation});
1092
+ } catch (err) { announce(errorText(err.message)); }
1093
+ await memberCaptures(slots,owner);
1094
+ }
1095
+ const toggle = button("", "capture-toggle", () => {
1096
+ if (item) change(on ? "close" : item.state === "paused" ? "resume" : "enable");
1097
+ });
1098
+ const status = text("small","meta capture-state",on ? say("开启","On") : say("关闭","Off"));
1099
+ status.setAttribute("aria-hidden","true");
1100
+ toggle.append(text("span","capture-title",caption),status,text("span","switch-track"));
1101
+ toggle.setAttribute("role","switch"); toggle.setAttribute("aria-checked",String(on));
1102
+ toggle.setAttribute("aria-label",caption + " · " + name);
1103
+ const reason = board.standby ? say("备用看板仅可查看设置。","Settings are read-only on this standby board.")
1104
+ : !chats.length ? say("此岗位尚未关联可共享的对话。","This role has no linked conversation available for sharing.")
1105
+ : !item ? say("先选择要设置的对话。","Select a conversation first.") : "";
1106
+ toggle.disabled = Boolean(reason);
1107
+ toggle.setAttribute("aria-describedby","member-capture-help");
1108
+ const controls = text("div","capture-controls");
1109
+ if (reason) {
1110
+ controls.tabIndex = 0;
1111
+ controls.setAttribute("aria-label",name + " · " + reason);
1112
+ controls.title = reason;
1113
+ }
1114
+ controls.append(toggle);
1115
+ slot.append(controls);
1116
+ if (focusOwner === owner && !reason) toggle.focus({preventScroll:true});
1117
+ }
1118
+ }
1119
+
1120
+ function render() {
1121
+ syncLabels();
1122
+ if (!board) return;
1123
+ const main = $("content");
1124
+ main.replaceChildren();
1125
+ if (view === "overview") overview(main);
1126
+ else if (view === "brief") projectBrief(main);
1127
+ else if (view === "tasks") tasks(main);
1128
+ else if (["sources", "experience", "reviews"].includes(view)) {
1129
+ main.append(heading(word(view), board.project));
1130
+ if (view === "experience") {
1131
+ main.append(text("p", "detail", say(
1132
+ "选配台账:仅存放显式登记、带来源与适用前提的关键经验(不会自动采集日常对话;不使用本项完全不影响多 AI 协作与版本交接)。",
1133
+ "Optional ledger: stores only lessons explicitly recorded with source revisions and preconditions (never auto-scraped from casual chat; completely optional for multi-AI collaboration)."
1134
+ )));
1135
+ }
1136
+ browseSection(main, view);
1137
+ } else {
1138
+ toolsPage(main);
1139
+ if (board.settings_enabled) {
1140
+ if (notifications?.configured) {
1141
+ const prefs = text("section","panel");
1142
+ const caption = say("内部团队群的讨论提醒","Discussion notices for an internal team group");
1143
+ const select = text("select","quiet"); select.setAttribute("aria-label",caption);
1144
+ for (const [mode,zh,en] of [["off","关闭","Off"],["mentions","明确请人跟进时","When follow-up is requested"],["all","所有纪要更新","All memo updates"]]) {
1145
+ const option = text("option","",say(zh,en)); option.value = mode; select.append(option);
1146
+ }
1147
+ select.value = notifications.discussions || "off";
1148
+ select.onchange = async () => {
1149
+ select.disabled = true;
1150
+ try { const saved = await api("discussion-notices",{mode:select.value}); notifications.discussions = saved.mode; }
1151
+ catch (err) { select.value = notifications.discussions || "off"; announce(errorText(err.message)); }
1152
+ finally { select.disabled = false; }
1153
+ };
1154
+ prefs.append(sectionHeading(caption),select); main.append(prefs);
1155
+ }
1156
+ }
1157
+ }
1158
+ document.title = board.project + " · " + word(view) + " | TaskCarry";
1159
+ }
1160
+ $("dismiss").addEventListener("click", () => $("drawer").close());
1161
+ $("drawer").addEventListener("close", () => {
1162
+ if ($("drawer").open) return;
1163
+ readSerial++;
1164
+ $("drawer-body").replaceChildren();
1165
+ });
1166
+ document
1167
+ .querySelectorAll("[data-view]")
1168
+ .forEach((el) =>
1169
+ el.addEventListener("click", () => setView(el.dataset.view)),
1170
+ );
1171
+ window.addEventListener("popstate", () => {
1172
+ if ($("drawer").open) $("drawer").close();
1173
+ setView(requestedView(), true);
1174
+ });
1175
+ $("refresh").addEventListener("click", refresh);
1176
+ $("lang").addEventListener("click", () => {
1177
+ clearAnnouncement();
1178
+ english = !english;
1179
+ try {
1180
+ sessionStorage.setItem("tc-language", english ? "en" : "zh");
1181
+ } catch {}
1182
+ if ($("drawer").open) $("drawer").close();
1183
+ if (board) render();
1184
+ else refresh();
1185
+ });
1186
+ syncLabels();
1187
+ refresh();