@songsid/agend 2.4.0-beta.27 → 2.4.0-beta.28

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 (141) hide show
  1. package/dist/agent-cli-instructions.md +2 -1
  2. package/dist/agent-cli.js +6 -0
  3. package/dist/agent-cli.js.map +1 -1
  4. package/dist/build-provenance.json +1 -1
  5. package/dist/channel/mcp-tools.js +1 -1
  6. package/dist/channel/mcp-tools.js.map +1 -1
  7. package/dist/claude-turn-boundaries.d.ts +15 -0
  8. package/dist/claude-turn-boundaries.js +88 -0
  9. package/dist/claude-turn-boundaries.js.map +1 -0
  10. package/dist/contact-auth-service.js +3 -0
  11. package/dist/contact-auth-service.js.map +1 -1
  12. package/dist/contact-auth-store.d.ts +16 -0
  13. package/dist/contact-auth-store.js +61 -1
  14. package/dist/contact-auth-store.js.map +1 -1
  15. package/dist/daemon.d.ts +12 -1
  16. package/dist/daemon.js +130 -19
  17. package/dist/daemon.js.map +1 -1
  18. package/dist/delivery-outbox.d.ts +38 -0
  19. package/dist/delivery-outbox.js +81 -1
  20. package/dist/delivery-outbox.js.map +1 -1
  21. package/dist/fleet-manager.d.ts +17 -1
  22. package/dist/fleet-manager.js +239 -16
  23. package/dist/fleet-manager.js.map +1 -1
  24. package/dist/general-knowledge/skills/concepts/SKILL.md +5 -0
  25. package/dist/general-knowledge/skills/task-board/SKILL.md +14 -0
  26. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +1 -1
  27. package/dist/hub/group-policy/resources.d.ts +1 -1
  28. package/dist/hub/roles/clock.d.ts +1 -1
  29. package/dist/hub/roles/clock.js +3 -2
  30. package/dist/hub/roles/clock.js.map +1 -1
  31. package/dist/hub/roles/read.d.ts +2 -0
  32. package/dist/hub/roles/read.js +15 -6
  33. package/dist/hub/roles/read.js.map +1 -1
  34. package/dist/hub/settings-directory-decision.js +11 -5
  35. package/dist/hub/settings-directory-decision.js.map +1 -1
  36. package/dist/hub/settings-member-address-decision.js +1 -1
  37. package/dist/hub/settings-member-address-decision.js.map +1 -1
  38. package/dist/hub/store.d.ts +4 -0
  39. package/dist/hub/store.js +19 -4
  40. package/dist/hub/store.js.map +1 -1
  41. package/dist/locale.js +17 -1
  42. package/dist/locale.js.map +1 -1
  43. package/dist/outbound-schemas.d.ts +3 -0
  44. package/dist/outbound-schemas.js +4 -2
  45. package/dist/outbound-schemas.js.map +1 -1
  46. package/dist/request-context-activation.js +14 -3
  47. package/dist/request-context-activation.js.map +1 -1
  48. package/dist/request-context-call.d.ts +1 -0
  49. package/dist/request-context-call.js.map +1 -1
  50. package/dist/request-context-compatibility.js +10 -2
  51. package/dist/request-context-compatibility.js.map +1 -1
  52. package/dist/request-context-control-api.d.ts +18 -0
  53. package/dist/request-context-control-api.js +4 -2
  54. package/dist/request-context-control-api.js.map +1 -1
  55. package/dist/request-context-drain-projection.d.ts +8 -0
  56. package/dist/request-context-drain-projection.js +40 -0
  57. package/dist/request-context-drain-projection.js.map +1 -0
  58. package/dist/request-context-drain.d.ts +9 -0
  59. package/dist/request-context-drain.js +63 -4
  60. package/dist/request-context-drain.js.map +1 -1
  61. package/dist/request-context-human.d.ts +6 -0
  62. package/dist/request-context-human.js +24 -1
  63. package/dist/request-context-human.js.map +1 -1
  64. package/dist/request-context-migration.d.ts +11 -0
  65. package/dist/request-context-migration.js +16 -3
  66. package/dist/request-context-migration.js.map +1 -1
  67. package/dist/request-context-reply-pending.d.ts +16 -0
  68. package/dist/request-context-reply-pending.js +77 -0
  69. package/dist/request-context-reply-pending.js.map +1 -0
  70. package/dist/request-context-resolution.d.ts +35 -0
  71. package/dist/request-context-resolution.js +86 -0
  72. package/dist/request-context-resolution.js.map +1 -0
  73. package/dist/request-context-retirement.d.ts +2 -0
  74. package/dist/request-context-retirement.js.map +1 -1
  75. package/dist/runtime-build-info.js +1 -1
  76. package/dist/runtime-build-info.js.map +1 -1
  77. package/dist/scheduler/db.js +9 -0
  78. package/dist/scheduler/db.js.map +1 -1
  79. package/dist/scheduler/task-board-text.d.ts +3 -6
  80. package/dist/scheduler/task-board-text.js +15 -10
  81. package/dist/scheduler/task-board-text.js.map +1 -1
  82. package/dist/scheduler/task-board-unread.d.ts +90 -0
  83. package/dist/scheduler/task-board-unread.js +192 -0
  84. package/dist/scheduler/task-board-unread.js.map +1 -0
  85. package/dist/scheduler/task-board.d.ts +324 -6
  86. package/dist/scheduler/task-board.js +786 -47
  87. package/dist/scheduler/task-board.js.map +1 -1
  88. package/dist/settings-effect.js +17 -2
  89. package/dist/settings-effect.js.map +1 -1
  90. package/dist/task-board-tool.js +24 -3
  91. package/dist/task-board-tool.js.map +1 -1
  92. package/dist/task-board-waker.d.ts +53 -2
  93. package/dist/task-board-waker.js +183 -12
  94. package/dist/task-board-waker.js.map +1 -1
  95. package/dist/transcript-monitor.d.ts +6 -1
  96. package/dist/transcript-monitor.js +59 -4
  97. package/dist/transcript-monitor.js.map +1 -1
  98. package/dist/transcript-turns.d.ts +3 -0
  99. package/dist/transcript-turns.js +5 -0
  100. package/dist/transcript-turns.js.map +1 -1
  101. package/dist/ui/fleet-task-activity.js +164 -24
  102. package/dist/ui/fleet-task-card.js +77 -13
  103. package/dist/ui/fleet-task-common.js +14 -0
  104. package/dist/ui/fleet-task-flow.js +353 -0
  105. package/dist/ui/fleet-task-md.js +1 -1
  106. package/dist/ui/fleet-task-run.js +98 -22
  107. package/dist/ui/fleet-task-thread.js +245 -0
  108. package/dist/ui/fleet-task-unread.js +100 -0
  109. package/dist/ui/fleet-task-view.js +6 -5
  110. package/dist/ui/fleet-task-wake.js +140 -0
  111. package/dist/ui/fleet-tasks.js +13 -6
  112. package/dist/ui/panel-windows-cli.js +2 -2
  113. package/dist/ui/request-context-control.js +51 -13
  114. package/dist/ui/shared/access-overview.css +1 -1
  115. package/dist/ui/shared/app-i18n.js +2 -2
  116. package/dist/ui/shared/app-shell.js +4 -1
  117. package/dist/ui/shared/app-stream.js +3 -1
  118. package/dist/ui/shared/app.css +8 -2
  119. package/dist/ui/shared/app.js +3 -0
  120. package/dist/ui/shared/task-board.css +164 -0
  121. package/dist/ui/shared/ui-icons.js +3 -0
  122. package/dist/ui/task-unread.js +70 -0
  123. package/dist/ui/windows-cli-catalog.js +33 -6
  124. package/dist/update-goback.js +3 -1
  125. package/dist/update-goback.js.map +1 -1
  126. package/dist/web-api.d.ts +45 -1
  127. package/dist/web-api.js +184 -6
  128. package/dist/web-api.js.map +1 -1
  129. package/dist/windows-cli-api.js +4 -2
  130. package/dist/windows-cli-api.js.map +1 -1
  131. package/dist/windows-cli.d.ts +40 -1
  132. package/dist/windows-cli.js +93 -11
  133. package/dist/windows-cli.js.map +1 -1
  134. package/dist/windows-shortcuts.d.ts +3 -22
  135. package/dist/windows-shortcuts.js +5 -45
  136. package/dist/windows-shortcuts.js.map +1 -1
  137. package/dist/workflow-templates/default.md +3 -2
  138. package/dist/wsl-host.d.ts +52 -0
  139. package/dist/wsl-host.js +97 -0
  140. package/dist/wsl-host.js.map +1 -0
  141. package/package.json +1 -1
@@ -18,7 +18,7 @@ import { chatPath, detailsPath } from "/assets/app-route.js";
18
18
  import { Icon } from "/assets/ui-icons.js";
19
19
  import { ActivityBlock, activityDrawCtx, activityOffered, activityPrefs, activitySnapshot, observeActivity } from "./chat-activity.js";
20
20
  import { SHOWN, TIME_SLACK_MS, hasSubstance } from "./chat-activity-groups.js";
21
- import { Who } from "./fleet-task-common.js";
21
+ import { Who, waitsOn } from "./fleet-task-common.js";
22
22
 
23
23
  register("taskrun", {
24
24
  en: {
@@ -30,6 +30,8 @@ register("taskrun", {
30
30
  noSteps: "This agent's runtime does not offer its steps.",
31
31
  waiting: "Not started: {0} will update this once it takes the card", waitingNobody: "Not started: whoever takes the card will update this",
32
32
  viaSubs: "The work is in its sub tasks: each one's agent updates its own card", nothingYet: "No state or result written yet",
33
+ runningUnclaimed: "Running · not claimed", unclaimedTip: "{0} is working and this is the card it was given, but it has not moved it to In progress (it did not claim it): what it is doing now is probably this card",
34
+ unclaimedNote: "{0} is working and has this card, but has not claimed it — the board shows work only once a card is in progress.",
33
35
  },
34
36
  "zh-TW": {
35
37
  title: "Agent 活動", running: "執行中", needs: "等你回應", stuck: "似乎卡住", idle: "閒置", sharedMark: "忙碌中 · {0} 張卡", byAgent: "Agent", byAgentTip: "由 Agent 做的",
@@ -40,6 +42,8 @@ register("taskrun", {
40
42
  noSteps: "這個 Agent 的執行環境沒有提供步驟。",
41
43
  waiting: "待啟動:{0} 接手後會在這裡更新", waitingNobody: "待啟動:有人接手後會在這裡更新",
42
44
  viaSubs: "工作在子任務裡:各子任務的 Agent 會在自己的卡上更新", nothingYet: "還沒有目前狀態或產出",
45
+ runningUnclaimed: "執行中・尚未認領", unclaimedTip: "{0} 正在執行,而這是交給它的卡,但它還沒有把卡片移到進行中(沒有認領):它現在做的很可能就是這張",
46
+ unclaimedNote: "{0} 正在執行,手上有這張卡,但還沒有認領——卡片要移到進行中,板子才會顯示有人在做。",
43
47
  },
44
48
  });
45
49
 
@@ -62,6 +66,22 @@ export function inProgressBy(cards) {
62
66
  return out;
63
67
  }
64
68
 
69
+ /**
70
+ * The open cards each instance has that it could start now — nothing left to wait for (the card's own `unmetDeps`, and one it cannot see) —
71
+ * by name, as card numbers. A main task that follows its sub tasks aside (its sub tasks are the work). With `inProgressBy`, what says whether a
72
+ * working instance with nothing in progress is probably on its one open card (`runUnclaimed`).
73
+ */
74
+ export function readyOpenBy(cards) {
75
+ const out = new Map();
76
+ for (const c of Array.isArray(cards) ? cards : []) {
77
+ if (!c || c.status !== "open" || !c.assignee) continue;
78
+ if (c.kind === "main" && c.progress && c.progress.total > 0) continue;
79
+ if (waitsOn(c)) continue;
80
+ out.set(c.assignee, [...(out.get(c.assignee) || []), c.id]);
81
+ }
82
+ return out;
83
+ }
84
+
65
85
  /**
66
86
  * The state of each named instance the viewer sees (`dotState`: working, needs, stuck, idle, stopped…), as a map by name —
67
87
  * read from the dashboard's store state `{ instances, exec, awaiting }`. A name the viewer does not see is not in it.
@@ -71,24 +91,73 @@ export function instanceStates(store, names) {
71
91
  const instances = (store && store.instances) || [];
72
92
  for (const name of names) {
73
93
  const it = instances.find((i) => i.name === name);
74
- if (it) out.set(name, dotState(it, ((store && store.exec) || {})[name], ((store && store.awaiting) || {})[name]));
94
+ if (it) { const state = dotState(it, ((store && store.exec) || {})[name], ((store && store.awaiting) || {})[name]); out.set(name, state); noteState(name, state); }
75
95
  }
76
96
  return out;
77
97
  }
78
98
 
99
+ // When THIS page saw an instance start working (it was not working, then it was): `runUnclaimed` does not take work that began before a card was
100
+ // handed over for work on it (a chat, another job). Nothing is stored or sent: a page opened while the instance is already working has no start
101
+ // (undefined: it cannot say, and does not hold that against the card). Updated wherever a state is read.
102
+ const lastSeen = new Map();
103
+ const workStarts = new Map();
104
+ function noteState(name, state) {
105
+ const was = lastSeen.get(name);
106
+ lastSeen.set(name, state);
107
+ if (state !== "working") workStarts.delete(name);
108
+ else if (was !== undefined && was !== "working" && !workStarts.has(name)) workStarts.set(name, Date.now());
109
+ }
110
+ /** Tests only: what this page has seen of the instances' states. */
111
+ export function forgetWorkStarts() { lastSeen.clear(); workStarts.clear(); }
112
+ /** When this page saw `name` start working (epoch ms), or undefined. */
113
+ export const workStartOf = (name) => workStarts.get(name);
114
+
115
+ /** A working instance began before the card was handed to it this long ago (clock slack) is not taken to be on that card. */
116
+ const HAND_SLACK_MS = 10_000;
117
+
118
+ /**
119
+ * What an instance is doing on a card that is still open, though it is working: it was given the card (the board told it — `card.handedAt`),
120
+ * can start it, has nothing in progress and no other open card it could be on, and did not start working before it was handed the card — so what
121
+ * it is doing now is probably this card, which it has not claimed. An INFERENCE like `runOf`'s (an agent is one continuing session): `{ instance,
122
+ * state: "working", shared: 0, unclaimed: true }`, or null. An agent once worked for six minutes on an assigned card without claiming it, and
123
+ * the board said nothing; the notice now asks it to claim first, and this says what it cannot hide. Not an agent that is only chatting: a card the
124
+ * board never handed it (no `handedAt`) is not evidence, and neither is work this page saw begin before the hand-over (`workStartOf`).
125
+ * `ctx`: { states, doing, ready, workStart? } — `readyOpenBy` of the board; without `ready` (a caller from before) there is no such run;
126
+ * `workStart` (a Map by name) stands in for what this page observed.
127
+ */
128
+ export function runUnclaimed(card, ctx) {
129
+ const name = card && card.assignee;
130
+ if (!name || !ctx || card.status !== "open" || waitsOn(card)) return null;
131
+ if (card.kind === "main" && card.progress && card.progress.total > 0) return null;
132
+ const handed = Date.parse(card.handedAt || "");
133
+ if (!Number.isFinite(handed)) return null; // the board never handed it to this instance: not evidence
134
+ if (!(ctx.states && ctx.states.get(name) === "working")) return null;
135
+ if (((ctx.doing && ctx.doing.get(name)) || 0) > 0) return null; // a card in progress is its work
136
+ const mine = ctx.ready && ctx.ready.get(name);
137
+ if (!mine || mine.length !== 1 || mine[0] !== card.id) return null; // none, or several it could be on: nothing says which
138
+ const began = ctx.workStart ? ctx.workStart.get(name) : workStartOf(name);
139
+ if (began !== undefined && began < handed - HAND_SLACK_MS) return null; // it was already at work before the card came: that work is something else
140
+ return { instance: name, state: "working", shared: 0, unclaimed: true };
141
+ }
142
+
79
143
  /**
80
- * What a card's assignee is doing on it, or null (nothing to say): { instance, state: working | needs | stuck | idle, shared }
144
+ * What a card's assignee is doing on it, or null (nothing to say): { instance, state: working | needs | stuck | idle, shared, unclaimed? }
81
145
  * — `shared`: how many cards the assignee has in progress when that is more than this one (then which one it is on is
82
- * not known), else 0. Only a card in progress has one, and only while its assignee is an instance the viewer sees, running.
83
- * A main task that follows its sub tasks has its running sub tasks' (the strongest); `subs`: the ones the page shows.
84
- * `ctx`: { states, doing } — `instanceStates` of the instances with a card in progress, and `inProgressBy` of the board.
146
+ * not known), else 0; `unclaimed`: it is working on the card it was given without having claimed it (`runUnclaimed`). Only a card in progress
147
+ * has one (or an open one the working assignee probably is on), and only while its assignee is an instance the viewer sees, running.
148
+ * A main task that follows its sub tasks has its running sub tasks' (the strongest, a claimed one first); `subs`: the ones the page shows.
149
+ * `ctx`: { states, doing, ready } — `instanceStates` of the instances with a card in progress or open, `inProgressBy` and `readyOpenBy` of the board.
85
150
  */
86
151
  export function runOf(card, ctx, subs = []) {
87
- if (!card || card.status !== "claimed") return null;
152
+ if (!card) return null;
88
153
  if (card.kind === "main" && card.progress && card.progress.total > 0) {
89
- const runs = (subs || []).map((s) => runOf(s, ctx)).filter(Boolean).sort((a, b) => RUN_RANK[a.state] - RUN_RANK[b.state]);
154
+ if (card.status !== "claimed" && card.status !== "open") return null;
155
+ const runs = (subs || []).map((s) => runOf(s, ctx)).filter(Boolean)
156
+ .sort((a, b) => RUN_RANK[a.state] - RUN_RANK[b.state] || (a.unclaimed ? 1 : 0) - (b.unclaimed ? 1 : 0));
90
157
  return runs[0] || null;
91
158
  }
159
+ if (card.status === "open") return runUnclaimed(card, ctx);
160
+ if (card.status !== "claimed") return null;
92
161
  const name = card.assignee;
93
162
  if (!name || !ctx) return null;
94
163
  const state = ctx.states && ctx.states.get(name);
@@ -101,7 +170,7 @@ export function runOf(card, ctx, subs = []) {
101
170
  const signature = (states) => [...states].map(([name, state]) => `${name}\u0000${state}`).sort().join("\u0001");
102
171
 
103
172
  /**
104
- * What the board needs to say "running" on every tile and row: `{ states, doing }` for `runOf`. ONE read of the dashboard's
173
+ * What the board needs to say "running" on every tile and row: `{ states, doing, ready }` for `runOf`. ONE read of the dashboard's
105
174
  * store for the whole board, and only of the instances that have a card in progress (the only ones a mark can name):
106
175
  * it redraws when one of THOSE states changes, not on every store change (a status poll, a message) — a tile or a row
107
176
  * subscribes to nothing. Computed from the store as it is at each draw, so a card that came in progress is never drawn
@@ -109,16 +178,18 @@ const signature = (states) => [...states].map(([name, state]) => `${name}\u0000$
109
178
  */
110
179
  export function useRunContext(cards) {
111
180
  const doing = useMemo(() => inProgressBy(cards), [cards]);
181
+ const ready = useMemo(() => readyOpenBy(cards), [cards]);
182
+ const names = useMemo(() => [...new Set([...doing.keys(), ...ready.keys()])], [doing, ready]);
112
183
  const [, redraw] = useState(0);
113
- const states = instanceStates(appStore.get(), doing.keys());
184
+ const states = instanceStates(appStore.get(), names);
114
185
  const drawn = useRef("");
115
186
  drawn.current = signature(states);
116
187
  useEffect(() => {
117
- const changed = () => signature(instanceStates(appStore.get(), doing.keys())) !== drawn.current;
188
+ const changed = () => signature(instanceStates(appStore.get(), names)) !== drawn.current;
118
189
  if (changed()) redraw((n) => n + 1); // moved between the draw and this subscription
119
190
  return appStore.subscribe(() => { if (changed()) redraw((n) => n + 1); });
120
- }, [doing]);
121
- return useMemo(() => ({ states, doing }), [doing, drawn.current]);
191
+ }, [names]);
192
+ return useMemo(() => ({ states, doing, ready }), [doing, ready, drawn.current]);
122
193
  }
123
194
 
124
195
  /**
@@ -164,8 +235,8 @@ const stateWord = (state) => t(`taskrun.${state === "working" ? "running" : stat
164
235
  /** "Running" (or "Busy · N cards", "Needs you", "Looks stuck") beside a tile's or a row's number; idle says nothing there. */
165
236
  export function RunMark({ run }) {
166
237
  if (!run || run.state === "idle") return null;
167
- const word = run.state === "working" && run.shared ? t("taskrun.sharedMark", run.shared) : stateWord(run.state);
168
- return html`<span class=${`tr-mark s-${run.state}${run.shared ? " shared" : ""}`} title=${`${run.instance}: ${word}`}>
238
+ const word = run.unclaimed ? t("taskrun.runningUnclaimed") : run.state === "working" && run.shared ? t("taskrun.sharedMark", run.shared) : stateWord(run.state);
239
+ return html`<span class=${`tr-mark s-${run.state}${run.shared ? " shared" : ""}${run.unclaimed ? " unclaimed" : ""}`} title=${run.unclaimed ? t("taskrun.unclaimedTip", run.instance) : `${run.instance}: ${word}`}>
169
240
  <span class="tr-dot" aria-hidden="true"></span>${word}</span>`;
170
241
  }
171
242
 
@@ -198,9 +269,10 @@ function useFeed(name, on, busy) {
198
269
  * card, work that lives in its sub tasks, or just that nothing is written. `run`: this card's `runOf`, if any — an assignee
199
270
  * that has the card in progress and is idle says so (the one thing it can know).
200
271
  */
201
- export function handoffNote(card, { derived = false, run = null } = {}) {
272
+ export function handoffNote(card, { derived = false, run = null, baton = "" } = {}) {
202
273
  if (run && run.state === "idle") return t("taskrun.idleNote", run.instance);
203
- if (card.status === "open") return card.assignee ? t("taskrun.waiting", card.assignee) : t("taskrun.waitingNobody");
274
+ // `baton`: where the card stands in the hand-over (waits for S-1, handed to dev, dev read it…) — fleet-task-flow.js's line for it.
275
+ if (card.status === "open") return baton || (card.assignee ? t("taskrun.waiting", card.assignee) : t("taskrun.waitingNobody"));
204
276
  return derived ? t("taskrun.viaSubs") : t("taskrun.nothingYet");
205
277
  }
206
278
 
@@ -211,24 +283,26 @@ export function handoffNote(card, { derived = false, run = null } = {}) {
211
283
  * conversation stays). With a state or result, or while the assignee is working, it opens up: who, their state, the way to their
212
284
  * conversation, the live steps (an admin, tool progress on), then the fields (`shown`) and the buttons for the empty ones.
213
285
  * `doing`: `inProgressBy` of the board. `derived`: a main task that follows its sub tasks has no agent of its own (its sub
214
- * tasks' pages do), whatever its assignee field says.
286
+ * tasks' pages do), whatever its assignee field says — what they are doing is `flow` (fleet-task-flow.js's `FlowLines`, drawn when
287
+ * `flowOn`: a sub task is running, waiting for the person, handed on…), and without it the block is the one quiet line. `baton`: a card
288
+ * that waits to start says where the hand-over stands, in words (`handoffNote`).
215
289
  */
216
- export function AgentRun({ card, detail, doing, derived = false, shown = [], adders = [] }) {
290
+ export function AgentRun({ card, detail, doing, ready = null, derived = false, shown = [], adders = [], flow = null, flowOn = false, baton = "" }) {
217
291
  const store = useStore(appStore); // one card's page: one subscription
218
292
  useStore(activityPrefs);
219
293
  const name = !derived && card.assignee ? card.assignee : null;
220
294
  const it = name ? (store.instances || []).find((i) => i.name === name) : null;
221
- const run = it ? runOf(card, { states: instanceStates(store, [name]), doing }) : null;
295
+ const run = it ? runOf(card, { states: instanceStates(store, [name]), doing, ready }) : null;
222
296
  const live = !!run && run.state !== "idle";
223
297
  const offered = live && activityOffered() && activityPrefs.get().on;
224
298
  useFeed(name, offered, live);
225
299
  const chat = it ? html`<a class="btn btn-sm tr-open" href=${chatPath(name)} title=${t("taskrun.openChatTip", name)}><${Icon} name="chat" size=${14} />${t("taskrun.openChat")}</a>` : null;
226
300
  const extras = adders.length ? html`<span class="tp-adders">${adders}</span>` : null;
227
- if (!live && !shown.length) {
301
+ if (!live && !shown.length && !flowOn) {
228
302
  return html`<section class="tr-run tp-agent is-strip" aria-label=${t("taskrun.title")}>
229
303
  <span class="tp-agent-icon" aria-hidden="true"><${Icon} name="bot" size=${16} /></span>
230
304
  <span class="tr-title">${t("taskrun.title")}</span>
231
- <span class="tp-agent-note">${handoffNote(card, { derived, run })}</span>
305
+ <span class="tp-agent-note">${handoffNote(card, { derived, run, baton })}</span>
232
306
  <span class="tb-grow"></span>${extras}${chat}
233
307
  </section>`;
234
308
  }
@@ -246,8 +320,10 @@ export function AgentRun({ card, detail, doing, derived = false, shown = [], add
246
320
  <span class="tb-grow"></span>
247
321
  ${chat}
248
322
  </div>
323
+ ${flowOn ? flow : null}
249
324
  ${run && run.state === "idle" ? html`<p class="muted tr-note">${t("taskrun.idleNote", name)}</p>` : null}
250
325
  ${run && run.shared ? html`<p class="muted tr-note">${t("taskrun.sharedNote", name, run.shared)}</p>` : null}
326
+ ${run && run.unclaimed ? html`<p class="tr-note tr-unclaimed">${t("taskrun.unclaimedNote", name)}</p>` : null}
251
327
  ${group ? html`<${ActivityBlock} group=${group} ctx=${activityDrawCtx(name)} />` : null}
252
328
  ${off ? html`<p class="muted tr-note">${t("taskrun.stepsOff", name)} <a class="link" href=${detailsPath(name)}>${t("taskrun.stepsOffLink")}</a></p>` : null}
253
329
  ${none ? html`<p class="muted tr-note">${t("taskrun.noSteps")}</p>` : null}
@@ -0,0 +1,245 @@
1
+ // Comment threads on a card's page (Fleet › Tasks › a card; docs/design/task-board.md, "Comment threads"): what each comment of
2
+ // the activity stream offers — reply, react, edit, resolve a thread, copy, copy link, delete — as an issue tracker's comment
3
+ // menu does, and the recipient chip under the comment box (who a comment is for).
4
+ // Shared with the rest of the page, not new: the app's `Menu` (the ⋯ and the chip's list, `ui-menu.js`), the chat's reaction chip
5
+ // and quick picker (`.msg-reactions .reaction`, `QUICK_REACTIONS` of chat-thread.js), the chat's Markdown (`MdBody`), `confirmDialog`
6
+ // and `toast`. The rules themselves are the board's (scheduler/task-board.ts); this module only asks and shows — a refusal is
7
+ // said in the page's words (`tasks.err.*`). No style attribute anywhere (the CSP).
8
+ import { html, useEffect, useRef, useState } from "/assets/app-html.js";
9
+ import { t, register } from "/assets/app-i18n.js";
10
+ import { Icon } from "/assets/ui-icons.js";
11
+ import { Menu } from "/assets/ui-menu.js";
12
+ import { QUICK_REACTIONS } from "/assets/chat-thread.js";
13
+
14
+ register("taskthread", {
15
+ en: {
16
+ reply: "Reply", react: "Add reaction", edit: "Edit", resolve: "Resolve thread", reopen: "Reopen thread", copy: "Copy", copyLink: "Copy link", delete: "Delete",
17
+ more: "Comment actions", copied: "Copied", linkCopied: "Link to the comment copied", copyFailed: "Could not copy",
18
+ edited: "edited", editedTip: "Edited {0}", save: "Save", cancel: "Cancel", editHint: "Ctrl+Enter saves · Esc drops the change", editLabel: "Edit the comment",
19
+ deleted: "This comment was deleted", deleteTitle: "Delete this comment?", deleteMsg: "Its words, reactions and files go. A line stays where it was, so the replies under it still make sense.",
20
+ reactions: "Reactions", reactedWith: "{0} reacted with {1}", reactedYou: "You", reactedMore: "{0} and {1} more", reactMine: "{0} (yours: press to take it back)",
21
+ replyingTo: "Replying to {0}", replyTo: "Reply to {0}", replyHint: "Reply — @ names an instance (Ctrl+Enter sends)",
22
+ resolved: "Resolved thread", resolvedBy: "Resolved by {0}", replyCount: "{0} replies", replyOne: "1 reply", showThread: "Show the thread", hideThread: "Hide the thread",
23
+ toNobody: "No agent notified", toSend: "{0} · starts when sent", toLabel: "Who this comment is for", toTip: "Who is woken when you send this comment. An @name in the text still wakes that instance too.",
24
+ toNobodyTip: "Nobody is woken (an @name in the text still is)", toWaits: "{0} · won't wake until the card is ready",
25
+ toWaitsTip: "This card still waits for another card, so a plain comment does not wake {0} yet (it reads the card when it can start). Choose {0} in the list to wake it now; an @name wakes it too.", groupAssignee: "Assignee", groupDispatcher: "Handed out by", groupWatchers: "Watching the card",
26
+ groupLead: "Project lead", groupLeadBoard: "Board leader", groupOthers: "Other instances", boardOff: "{0} (task board off)",
27
+ },
28
+ "zh-TW": {
29
+ reply: "回覆", react: "新增反應", edit: "編輯", resolve: "解決討論串", reopen: "重新開啟討論串", copy: "複製", copyLink: "複製連結", delete: "刪除",
30
+ more: "留言動作", copied: "已複製", linkCopied: "已複製這則留言的連結", copyFailed: "無法複製",
31
+ edited: "已編輯", editedTip: "編輯於 {0}", save: "儲存", cancel: "取消", editHint: "Ctrl+Enter 儲存 · Esc 放棄修改", editLabel: "編輯留言",
32
+ deleted: "這則留言已刪除", deleteTitle: "刪除這則留言?", deleteMsg: "內容、反應和附件都會移除。原位置會留一行,底下的回覆才讀得通。",
33
+ reactions: "反應", reactedWith: "{0} 用 {1} 回應", reactedYou: "你", reactedMore: "{0} 等 {1} 人", reactMine: "{0}(你按的:再按一次收回)",
34
+ replyingTo: "回覆 {0}", replyTo: "回覆 {0}", replyHint: "回覆 — 輸入 @ 可選 Agent(Ctrl+Enter 送出)",
35
+ resolved: "已解決的討論串", resolvedBy: "由 {0} 解決", replyCount: "{0} 則回覆", replyOne: "1 則回覆", showThread: "展開討論串", hideThread: "收合討論串",
36
+ toNobody: "不通知 Agent", toSend: "{0} · 送出後開始處理", toLabel: "這則留言要給誰", toTip: "送出時叫醒誰。文字裡的 @名稱照樣會叫醒該 Agent。",
37
+ toNobodyTip: "不叫醒任何人(文字裡的 @名稱照樣會)", toWaits: "{0} · 卡片可以開始前不會叫醒",
38
+ toWaitsTip: "這張卡還在等別張卡,所以一般留言暫時不會叫醒 {0}(它能開始時會讀到這張卡)。要現在叫醒它,請在清單裡選 {0};寫 @名稱 也會叫醒。", groupAssignee: "負責人", groupDispatcher: "派工者", groupWatchers: "關注這張卡的",
39
+ groupLead: "專案 leader", groupLeadBoard: "任務板 leader", groupOthers: "其他 Agent", boardOff: "{0}(任務板關閉)",
40
+ },
41
+ });
42
+
43
+ // ── Threads (pure: tests import these) ─────────────────────
44
+
45
+ /** The comment entries a thread is made of keep their order; `rootOf` walks a reply up to its thread's first comment. */
46
+ export function rootOf(entry, byId) {
47
+ let cur = entry;
48
+ for (let hops = 0; cur && cur.parentId !== undefined && cur.parentId !== null && hops < 64; hops++) {
49
+ const up = byId.get(cur.parentId);
50
+ if (!up) break;
51
+ cur = up;
52
+ }
53
+ return cur;
54
+ }
55
+
56
+ /**
57
+ * The stream's entries with each reply moved under its thread's first comment: `{ ...root, replies: [entries in time order] }`;
58
+ * a comment whose parent is not among `all` (outside the page's window, left out of sight) stands alone. Only comments are
59
+ * grouped; a progress note, a history line or a comment the filter hid keeps its place. `all`: every comment of the card
60
+ * (a reply under a filter still finds its thread).
61
+ */
62
+ export function threadize(entries, all) {
63
+ const byId = new Map();
64
+ for (const e of all) if (e.type === "comment" && e.id !== undefined) byId.set(e.id, e);
65
+ const shown = new Set(entries.filter((e) => e.type === "comment" && e.id !== undefined).map((e) => e.id));
66
+ const replies = new Map();
67
+ const out = [];
68
+ for (const e of entries) {
69
+ if (e.type !== "comment" || e.parentId === undefined || e.parentId === null) { out.push(e); continue; }
70
+ const root = rootOf(e, byId);
71
+ if (!root || root === e || !shown.has(root.id)) { out.push(e); continue; }
72
+ (replies.get(root.id) || replies.set(root.id, []).get(root.id)).push(e);
73
+ }
74
+ return out.map((e) => (e.type === "comment" && replies.has(e.id) ? { ...e, replies: replies.get(e.id) } : e));
75
+ }
76
+
77
+ /** A reaction as its chip says it: the emoji, the number, whether it is the viewer's, and who (the tooltip). */
78
+ export function reactionView(reaction, viewer) {
79
+ const by = Array.isArray(reaction.by) ? reaction.by : [];
80
+ // The host says whether the chip is the viewer's (by their key); a host that does not, by name and kind as before.
81
+ const mine = typeof reaction.mine === "boolean" ? reaction.mine : !!viewer && by.some((b) => b.name === viewer.name && b.kind === viewer.kind);
82
+ // The viewer's own entry is "You"; another account with the same name still reads as that name.
83
+ let skipped = false;
84
+ const others = by.filter((b) => { if (mine && !skipped && viewer && b.name === viewer.name && b.kind === viewer.kind) { skipped = true; return false; } return true; }).map((b) => b.name);
85
+ const who = [...(mine ? [t("taskthread.reactedYou")] : []), ...others].slice(0, 3);
86
+ const rest = by.length - who.length;
87
+ const list = rest > 0 ? t("taskthread.reactedMore", who.join(", "), rest) : who.join(", ");
88
+ return { emoji: reaction.emoji, count: by.length, mine, label: t("taskthread.reactedWith", list, reaction.emoji) };
89
+ }
90
+
91
+ /**
92
+ * Whether the viewer wrote the comment (an edit is its author's). The host says (`mine`, from the writer's own key: two people who
93
+ * are both "web-user" are not each other); a host that does not say is read by the same name and the same kind.
94
+ */
95
+ export const wroteComment = (entry, viewer) => !!viewer && (typeof entry.mine === "boolean" ? entry.mine : entry.who === viewer.name && entry.by === viewer.kind);
96
+
97
+ /** A comment's address: the card's page, the comment's anchor (`#c42`, which scrolls to it and lights it). */
98
+ export const commentHash = (id) => `#c${id}`;
99
+ export function commentUrl(href, cardId, id) {
100
+ const u = new URL(href);
101
+ u.searchParams.set("card", cardId);
102
+ u.hash = commentHash(id);
103
+ return u.toString();
104
+ }
105
+ /** The comment an address names (`#c42`), or null. */
106
+ export const commentInHash = (hash) => { const m = /^#c(\d{1,12})$/.exec(String(hash || "")); return m ? Number(m[1]) : null; };
107
+
108
+ /**
109
+ * Whom a comment may be for, as the recipient chip lists them: groups in order — the card's assignee, who handed it out, who
110
+ * watches it, its leader, then every other instance of the fleet — each name once (the first group that has it). `fleet`:
111
+ * [{ name, off }] (the fleet's instances; one with the task board off is listed, not choosable). `detail`: the card read
112
+ * (watchers, inheritedWatchers, leader).
113
+ */
114
+ export function recipientGroups({ card, detail, fleet }) {
115
+ const known = new Map((fleet || []).map((n) => [n.name, n]));
116
+ const seen = new Set();
117
+ const take = (names) => names.filter((n) => known.has(n) && !seen.has(n) && (seen.add(n), true)).map((n) => known.get(n));
118
+ const groups = [];
119
+ const add = (key, title, names) => { const list = take(names); if (list.length) groups.push({ key, title, names: list }); };
120
+ add("assignee", "taskthread.groupAssignee", card.assignee ? [card.assignee] : []);
121
+ add("dispatcher", "taskthread.groupDispatcher", card.dispatcher && card.dispatcher.kind === "instance" ? [card.dispatcher.name] : []);
122
+ add("watchers", "taskthread.groupWatchers", [...((detail && detail.watchers) || []), ...((detail && detail.inheritedWatchers) || [])]);
123
+ const lead = detail && detail.leader;
124
+ add("lead", lead && lead.via === "board" ? "taskthread.groupLeadBoard" : "taskthread.groupLead", lead ? [lead.name] : []);
125
+ add("others", "taskthread.groupOthers", (fleet || []).map((n) => n.name));
126
+ return groups;
127
+ }
128
+
129
+ /**
130
+ * Who the comment box starts with (null: nobody is notified). A reply: the author of the comment it answers, when that is an
131
+ * instance the board can wake. Otherwise the card's assignee, when it is an instance the board can wake and the card is not
132
+ * finished (a finished card's talk is rarely an order; choosing someone still wakes them). A person or no assignee: nobody.
133
+ * On a card that still waits on another card the assignee is the chip's name but `holdsRecipient` says it is not woken yet.
134
+ */
135
+ export function defaultRecipient({ card, reply = null, fleet }) {
136
+ const live = (name) => !!name && (fleet || []).some((n) => n.name === name && !n.off);
137
+ if (reply && reply.by === "instance" && live(reply.who)) return reply.who;
138
+ const finished = card.status === "done" || card.status === "cancelled";
139
+ if (!finished && live(card.assignee)) return card.assignee;
140
+ return null;
141
+ }
142
+
143
+ /**
144
+ * Whether the chip's starting name is held back: a new comment (not a reply) on an open card that still waits on another card, whose
145
+ * assignee is the name the chip starts with. The comment then goes with no recipient list, as #4367's rule has it: the assignee reads it
146
+ * when the card can start, and is not woken now. Choosing it in the list is asking for it by name — that sends it and wakes it.
147
+ */
148
+ export function holdsRecipient({ card, reply = null, initial }) {
149
+ if (reply || !initial || initial !== card.assignee) return false;
150
+ return card.status === "open" && ((card.unmetDeps || []).length > 0 || card.hiddenUnmet > 0);
151
+ }
152
+
153
+ // ── The recipient chip ─────────────────────────────────────
154
+
155
+ /** The chip under the comment box: who this comment is for ("dev · starts when sent"); a click lists the others. `held`: the name is the card's assignee, not woken until the card is ready. */
156
+ export function RecipientChip({ groups, value, onChange, disabled = false, held = false }) {
157
+ const label = value ? t(held ? "taskthread.toWaits" : "taskthread.toSend", value) : t("taskthread.toNobody");
158
+ const items = [];
159
+ for (const g of groups) {
160
+ items.push({ key: `h-${g.key}`, heading: true, label: t(g.title) });
161
+ for (const n of g.names) items.push({ key: `n-${n.name}`, label: n.off ? t("taskthread.boardOff", n.name) : n.name, checked: value === n.name, disabled: !!n.off, title: n.off ? t("tasks.boardOffHint") : undefined, onSelect: () => onChange(n.name) });
162
+ }
163
+ items.push({ key: "nobody", label: t("taskthread.toNobody"), checked: value === null, title: t("taskthread.toNobodyTip"), onSelect: () => onChange(null) });
164
+ return html`<${Menu} cls="tc-to-menu" label=${t("taskthread.toLabel")} fit disabled=${disabled} items=${items} triggerClass="tc-to"
165
+ trigger=${html`<${Icon} name=${value ? "bot" : "bell"} size=${14} /><span class="tc-to-text" title=${value ? (held ? t("taskthread.toWaitsTip", value) : t("taskthread.toTip")) : t("taskthread.toNobodyTip")}>${label}</span><${Icon} name="chevron" size=${14} />`} />`;
166
+ }
167
+
168
+ // ── A comment's tools ──────────────────────────────────────
169
+
170
+ /** The ⋯ menu's items for one comment (pure: tests import it). `ctx`: { writable, viewer, root, resolved }, `act(name)` runs one. */
171
+ export function commentMenuItems(entry, ctx, act) {
172
+ const writable = !!ctx.writable && !!ctx.viewer;
173
+ const mine = writable && wroteComment(entry, ctx.viewer);
174
+ return [
175
+ writable && !entry.deleted ? { key: "reply", label: t("taskthread.reply"), icon: "reply", onSelect: () => act("reply") } : null,
176
+ writable && !entry.deleted ? { key: "react", label: t("taskthread.react"), icon: "smile", onSelect: () => act("react") } : null,
177
+ mine && !entry.deleted && entry.kind === "comment" ? { key: "edit", label: t("taskthread.edit"), icon: "edit", onSelect: () => act("edit") } : null,
178
+ writable && ctx.root ? { key: "resolve", label: ctx.resolved ? t("taskthread.reopen") : t("taskthread.resolve"), icon: "check", onSelect: () => act("resolve") } : null,
179
+ !entry.deleted ? { key: "copy", label: t("taskthread.copy"), icon: "copy", onSelect: () => act("copy") } : null,
180
+ { key: "link", label: t("taskthread.copyLink"), icon: "link", onSelect: () => act("link") },
181
+ writable && !entry.deleted ? { key: "delete", label: t("taskthread.delete"), icon: "trash", danger: true, onSelect: () => act("delete") } : null,
182
+ ].filter(Boolean);
183
+ }
184
+
185
+ /** The reaction button and the ⋯ menu at a comment's top right. */
186
+ export function CommentTools({ entry, ctx, act }) {
187
+ const items = commentMenuItems(entry, ctx, act);
188
+ const writable = !!ctx.writable && !!ctx.viewer && !entry.deleted;
189
+ return html`<span class="tl-tools">
190
+ ${writable ? html`<button type="button" class="icon-btn tl-tool" title=${t("taskthread.react")} aria-label=${t("taskthread.react")} aria-haspopup="true" aria-expanded=${ctx.picking === entry.id ? "true" : "false"}
191
+ onClick=${() => act("react")}><${Icon} name="smile" size=${16} /></button>` : null}
192
+ <${Menu} cls="tl-menu" label=${t("taskthread.more")} fit items=${items} />
193
+ </span>`;
194
+ }
195
+
196
+ /** The quick reactions (the chat's own set), shown under a comment while "Add reaction" is open. */
197
+ export function ReactionPicker({ onPick, onClose }) {
198
+ const ref = useRef(null);
199
+ useEffect(() => {
200
+ const first = ref.current && ref.current.querySelector("button");
201
+ if (first) first.focus({ preventScroll: true });
202
+ const key = (e) => { if (e.key === "Escape") { e.stopPropagation(); onClose(); } };
203
+ const away = (e) => { if (ref.current && !ref.current.contains(e.target) && !(e.target.closest && e.target.closest(".tl-tools"))) onClose(); };
204
+ document.addEventListener("keydown", key, true);
205
+ document.addEventListener("pointerdown", away, true);
206
+ return () => { document.removeEventListener("keydown", key, true); document.removeEventListener("pointerdown", away, true); };
207
+ }, []);
208
+ return html`<div class="react-pick tl-pick" ref=${ref} role="group" aria-label=${t("taskthread.reactions")}>${QUICK_REACTIONS.map((e) =>
209
+ html`<button key=${e} type="button" class="chip-btn react-opt" aria-label=${e} onClick=${() => onPick(e)}>${e}</button>`)}</div>`;
210
+ }
211
+
212
+ /** A comment's reactions as the chat's chips: the emoji and the number; the viewer's is accented, and pressing it takes it back. */
213
+ export function ReactionBar({ entry, ctx, onReact }) {
214
+ const list = (entry.reactions || []).map((r) => reactionView(r, ctx.viewer)).filter((r) => r.count > 0);
215
+ if (!list.length) return null;
216
+ const live = !!ctx.writable && !!ctx.viewer;
217
+ return html`<div class="msg-reactions react-bar tl-reacts" role="group" aria-label=${t("taskthread.reactions")}>${list.map((r) => live
218
+ ? html`<button key=${r.emoji} type="button" class=${`reaction react-chip${r.mine ? " mine" : ""}`} aria-pressed=${r.mine ? "true" : "false"} title=${r.mine ? t("taskthread.reactMine", r.label) : r.label} aria-label=${r.label}
219
+ onClick=${() => onReact(r.emoji, !r.mine)}><span class="e">${r.emoji}</span><span class="n">${r.count}</span></button>`
220
+ : html`<span key=${r.emoji} class=${`reaction react-chip${r.mine ? " mine" : ""}`} role="img" title=${r.label} aria-label=${r.label}><span class="e">${r.emoji}</span><span class="n">${r.count}</span></span>`)}</div>`;
221
+ }
222
+
223
+ /** Editing a comment's words in place: Ctrl+Enter or Save keeps them, Esc or Cancel drops the change. `onSave(text)` resolves "ok" when it is kept. */
224
+ export function EditBox({ entry, onSave, onCancel }) {
225
+ const [text, setText] = useState(entry.text);
226
+ const [saving, setSaving] = useState(false);
227
+ const box = useRef(null);
228
+ useEffect(() => { const el = box.current; if (el) { el.focus({ preventScroll: true }); try { el.setSelectionRange(el.value.length, el.value.length); } catch { /* no selection API */ } } }, []);
229
+ const same = text.trim() === entry.text.trim();
230
+ async function save() {
231
+ if (saving || !text.trim() || same) { if (same) onCancel(); return; }
232
+ setSaving(true);
233
+ try { if ((await onSave(text.trim())) === "ok") onCancel(); } finally { setSaving(false); }
234
+ }
235
+ return html`<div class="tl-edit">
236
+ <textarea ref=${box} rows="3" value=${text} aria-label=${t("taskthread.editLabel")} onInput=${(e) => setText(e.target.value)}
237
+ onKeyDown=${(e) => {
238
+ if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); onCancel(); }
239
+ else if (e.key === "Enter" && (e.ctrlKey || e.metaKey) && !e.isComposing) { e.preventDefault(); void save(); }
240
+ }}></textarea>
241
+ <div class="tl-edit-foot"><span class="muted tl-edit-hint">${t("taskthread.editHint")}</span>
242
+ <button type="button" class="btn btn-sm" onClick=${onCancel}>${t("taskthread.cancel")}</button>
243
+ <button type="button" class="btn btn-primary btn-sm" disabled=${saving || !text.trim()} onClick=${() => void save()}>${t("taskthread.save")}</button></div>
244
+ </div>`;
245
+ }
@@ -0,0 +1,100 @@
1
+ // What is new for this person on the board (Fleet › Tasks; docs/design/task-board.md, "Unread"): a dot with the number on the card that has
2
+ // something new (the board's tile, the list's row), and a strip at the top of Home and of a project's board that names the cards and says
3
+ // why — "dev answered you", "web-user replied to your comment", "dev mentioned you", "Waiting for your confirmation". Opening a card marks
4
+ // it read (task-unread.js). The numbers come from the app store (`taskUnread`, read from the server by task-unread.js): nothing here
5
+ // asks for anything, stores anything or carries a comment's words. A tile and a row never subscribe to the store themselves: the board reads
6
+ // it once (`useUnreadCards`) and redraws only when it changes. No style attribute anywhere (the CSP).
7
+ import { html, useEffect, useRef, useState } from "/assets/app-html.js";
8
+ import { t, register } from "/assets/app-i18n.js";
9
+ import { appStore } from "/assets/app-store.js";
10
+ import { Icon } from "/assets/ui-icons.js";
11
+ import { relTime } from "./fleet-task-common.js";
12
+ import { installTaskUnread } from "./task-unread.js";
13
+
14
+ register("taskunread", {
15
+ en: {
16
+ title: "{0} task cards with new replies", titleOne: "1 task card has new replies", mark: "{0} new", markTip: "New for you: {0}",
17
+ "reason.answer": "{0} answered you", "reason.reply": "{0} replied to your comment", "reason.mention": "{0} mentioned you",
18
+ "reason.review": "Waiting for your confirmation", "reason.blocked": "Waiting for your answer", more: "+{0} more", seeMore: "{0} more cards", showFewer: "Show fewer",
19
+ short_answer: "Answered", short_reply: "Replied", short_mention: "Mentioned", short_review: "To confirm", short_blocked: "To answer",
20
+ },
21
+ "zh-TW": {
22
+ title: "{0} 張任務卡有新回覆", titleOne: "1 張任務卡有新回覆", mark: "{0} 則新動態", markTip: "給你的新動態:{0}",
23
+ "reason.answer": "{0} 回覆了你", "reason.reply": "{0} 回覆了你的留言", "reason.mention": "{0} 提到了你",
24
+ "reason.review": "等你確認", "reason.blocked": "等你回答", more: "另外 {0} 則", seeMore: "還有 {0} 張卡", showFewer: "收合",
25
+ short_answer: "已回覆", short_reply: "回覆你", short_mention: "提到你", short_review: "待確認", short_blocked: "待回答",
26
+ },
27
+ });
28
+
29
+ const EMPTY = Object.freeze({});
30
+ /** The strongest first: what a card with several reasons says (the server orders them so, and sends them so). */
31
+ const SHOWN = 5;
32
+
33
+ /** The unread by card number the board draws marks from, redrawing the board only when the store's unread itself changes. */
34
+ export function useUnreadCards() {
35
+ const [, redraw] = useState(0);
36
+ const seen = useRef(null);
37
+ seen.current = appStore.get().taskUnread || null;
38
+ useEffect(() => {
39
+ installTaskUnread(); // a tab from before an upgrade has this panel but not the new app.js
40
+ const changed = () => (appStore.get().taskUnread || null) !== seen.current;
41
+ if (changed()) redraw((n) => n + 1);
42
+ return appStore.subscribe(() => { if (changed()) redraw((n) => n + 1); });
43
+ }, []);
44
+ const u = seen.current;
45
+ return (u && u.enabled && u.cards) || EMPTY;
46
+ }
47
+
48
+ /**
49
+ * A card's mark: its own unread and, for a main task, its sub tasks' (a reply on a sub task is news on the main task's tile too) —
50
+ * `{ n, reasons }` (reasons strongest first, each once), or null when none. Pure: tests import it.
51
+ */
52
+ export function markFor(card, subs, unread) {
53
+ const own = unread && unread[card.id];
54
+ const list = [own, ...(subs || []).map((s) => unread && unread[s.id])].filter(Boolean);
55
+ if (!list.length) return null;
56
+ const order = ["review", "blocked", "reply", "answer", "mention"];
57
+ const reasons = order.filter((r) => list.some((u) => (u.reasons || []).includes(r)));
58
+ return { n: list.reduce((a, u) => a + (u.n || 0), 0), reasons };
59
+ }
60
+
61
+ /** The strip's heading: how many cards (one has its own sentence: "1 cards" is not English). */
62
+ export const stripTitle = (n) => (n === 1 ? t("taskunread.titleOne") : t("taskunread.title", n));
63
+
64
+ /** The words for one card's reason: who did it (the card's newest) and what. */
65
+ export const reasonText = (u) => {
66
+ const r = (u.reasons && u.reasons[0]) || "answer";
67
+ return t(`taskunread.reason.${r}`, u.by || "");
68
+ };
69
+
70
+ /** The dot on a tile or a row: the number, and — to a screen reader — what is new. Nothing when there is none. */
71
+ export function UnreadMark({ unread }) {
72
+ if (!unread || !unread.n) return null;
73
+ const why = t(`taskunread.short_${(unread.reasons && unread.reasons[0]) || "answer"}`);
74
+ return html`<span class="tb-unread" role="img" aria-label=${t("taskunread.markTip", why)} title=${t("taskunread.markTip", why)}><span class="tb-unread-dot" aria-hidden="true"></span>${unread.n > 1 ? html`<span class="tb-unread-n">${unread.n}</span>` : null}</span>`;
75
+ }
76
+
77
+ /**
78
+ * The strip: the cards with something new, newest first (the first few; a line says how many more), each with its number, title
79
+ * and why. `cards`: the board's cards, for their titles (a card the board does not carry shows its number). Nothing when there is nothing.
80
+ */
81
+ export function UnreadStrip({ cards, onOpen }) {
82
+ const unread = useUnreadCards();
83
+ // M-3908: "N more cards" opens the rest in the strip itself (each row opens its card, as the first five do); "Show fewer" folds it again.
84
+ const [all, setAll] = useState(false);
85
+ const codes = Object.keys(unread).sort((a, b) => (unread[a].at < unread[b].at ? 1 : unread[a].at > unread[b].at ? -1 : 0));
86
+ if (!codes.length) return null;
87
+ const byId = new Map((cards || []).map((c) => [c.id, c]));
88
+ const shown = all ? codes : codes.slice(0, SHOWN);
89
+ return html`<section class="tb-waiting tb-unread-strip" aria-label=${stripTitle(codes.length)}>
90
+ <h3 class="tb-section-title"><${Icon} name="bell" size=${16} />${stripTitle(codes.length)}</h3>
91
+ <ul class="rows">${shown.map((code) => {
92
+ const u = unread[code], card = byId.get(code);
93
+ return html`<li key=${code} class="row-item tb-unread-row" data-unread=${code}>
94
+ <button type="button" class="tb-wait-title" onClick=${() => onOpen(code)}><span class="tb-code">${code}</span> ${card ? card.title : ""}</button>
95
+ <span class="muted tb-unread-meta">${reasonText(u)}${u.n > 1 ? ` · ${t("taskunread.more", u.n - 1)}` : ""} · ${relTime(u.at)}</span>
96
+ </li>`;
97
+ })}</ul>
98
+ ${codes.length > SHOWN ? html`<p class="tb-unread-more"><button type="button" class="tb-link" aria-expanded=${all ? "true" : "false"} onClick=${() => setAll(!all)}>${all ? t("taskunread.showFewer") : t("taskunread.seeMore", codes.length - SHOWN)}</button></p>` : null}
99
+ </section>`;
100
+ }