@lukstei/dsh-client-kanban 0.0.0-stage → 0.2.2-rc.5.3

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.
@@ -0,0 +1,576 @@
1
+ import type { SessionListState } from "@deepseek-ai/dsh-api-session-controller/client";
2
+ import type {
3
+ WorkspaceId,
4
+ WorkspaceSnapshot,
5
+ } from "@deepseek-ai/dsh-api-workspace-controller/client";
6
+ import type { ObservableSnapshot } from "@deepseek-ai/dsh-client-store";
7
+ import type { SessionStatusSnapshot } from "@deepseek-ai/dsh-client-ui-session/client";
8
+ import type { InjectFace } from "@deepseek-ai/dsh-client-ui-slots";
9
+ import type { SessionId } from "@deepseek-ai/dsh-session/types";
10
+ import type { TypertRemoteNamespaceMap } from "@deepseek-ai/dsh-typert-protocol";
11
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
12
+ import { searchRequestSchema } from "../search.ts";
13
+ import type { KanbanLane, KanbanRecord } from "../types.ts";
14
+ import { KanbanIcon } from "./KanbanIcon.tsx";
15
+ import { KanbanSection } from "./KanbanSection.tsx";
16
+ import {
17
+ filterPartitionedSessions,
18
+ getStoredKanbanWorkspace,
19
+ isKanbanTransitionAllowed,
20
+ isSessionEligibleForHydration,
21
+ isSessionInWorkspace,
22
+ setStoredKanbanWorkspace,
23
+ } from "./store.ts";
24
+ import { useKanban, useStore } from "./use-kanban.ts";
25
+
26
+ export interface KanbanPaneInjected {
27
+ readonly sessionsList: ObservableSnapshot<SessionListState>;
28
+ readonly workspacesList: ObservableSnapshot<WorkspaceSnapshot>;
29
+ readonly sessionStatus: ObservableSnapshot<SessionStatusSnapshot>;
30
+ readonly searchSessions: TypertRemoteNamespaceMap["kanban"]["search"];
31
+ readonly searchResultLimit: number;
32
+ readonly currentSessionId?: SessionId;
33
+ readonly selectPanel: (id: string | null) => void;
34
+ readonly refreshProjections?: (id: SessionId) => Promise<void>;
35
+ readonly startTask: (workspaceId?: WorkspaceId) => Promise<void>;
36
+ readonly prepareTask: (
37
+ prompt: string,
38
+ workspaceId?: WorkspaceId,
39
+ ) => Promise<void>;
40
+ readonly startPreparedTask: (id: SessionId, prompt: string) => Promise<void>;
41
+ readonly selectSession: (id: SessionId) => void;
42
+ readonly markDone: (id: SessionId) => Promise<void>;
43
+ readonly reopen: (id: SessionId) => Promise<void>;
44
+ readonly deleteSession: (id: SessionId) => Promise<void>;
45
+ readonly holdSession: (id: SessionId) => Promise<void>;
46
+ readonly unholdSession: (id: SessionId) => Promise<void>;
47
+ readonly pinSession: (id: SessionId) => Promise<void>;
48
+ readonly unpinSession: (id: SessionId) => Promise<void>;
49
+ }
50
+
51
+ export type KanbanPaneProps = InjectFace<KanbanPaneInjected>;
52
+
53
+ /**
54
+ * Purpose: Render the full interactive Kanban board container with workspace filtering and 4-column lane layout.
55
+ * Contract:
56
+ * - Inputs: KanbanPaneProps injected with observable session/workspace stores and operational dispatchers.
57
+ * - Outputs: Rendered JSX element for the Kanban board view.
58
+ * - Throws / Errors: Never throws.
59
+ */
60
+ export function KanbanPane({
61
+ sessionsList,
62
+ workspacesList,
63
+ sessionStatus,
64
+ searchSessions,
65
+ searchResultLimit,
66
+ currentSessionId,
67
+ refreshProjections,
68
+ startTask,
69
+ prepareTask,
70
+ startPreparedTask,
71
+ selectSession,
72
+ markDone,
73
+ reopen,
74
+ deleteSession,
75
+ holdSession,
76
+ unholdSession,
77
+ pinSession,
78
+ unpinSession,
79
+ }: KanbanPaneProps) {
80
+ const [userWorkspaceId, setUserWorkspaceId] = useState<string | null>(() =>
81
+ getStoredKanbanWorkspace(),
82
+ );
83
+ const [isStarting, setIsStarting] = useState(false);
84
+ const [isPreparingTask, setIsPreparingTask] = useState(false);
85
+ const [isRecycleOver, setIsRecycleOver] = useState(false);
86
+ const [activeDragSourceLane, setActiveDragSourceLane] = useState<
87
+ KanbanLane | undefined
88
+ >();
89
+ const [searchQuery, setSearchQuery] = useState("");
90
+ const query = searchQuery.trim();
91
+ const [searchState, setSearchState] = useState<
92
+ | { status: "pending" }
93
+ | {
94
+ status: "settled";
95
+ query: string;
96
+ scope: string;
97
+ workspaceId: WorkspaceId | "ungrouped" | undefined;
98
+ result: Awaited<ReturnType<KanbanPaneInjected["searchSessions"]>>;
99
+ }
100
+ >({ status: "pending" });
101
+
102
+ useEffect(() => {
103
+ if (typeof window === "undefined") return;
104
+ const handleStorage = () => {
105
+ setUserWorkspaceId(getStoredKanbanWorkspace());
106
+ };
107
+ window.addEventListener("dsh-kanban-workspace-change", handleStorage);
108
+ window.addEventListener("storage", handleStorage);
109
+ return () => {
110
+ window.removeEventListener("dsh-kanban-workspace-change", handleStorage);
111
+ window.removeEventListener("storage", handleStorage);
112
+ };
113
+ }, []);
114
+
115
+ const handleDragStart = useCallback(
116
+ (_id: SessionId, sourceLane: KanbanLane) => {
117
+ setActiveDragSourceLane(sourceLane);
118
+ },
119
+ [],
120
+ );
121
+
122
+ const handleDragEnd = useCallback(() => {
123
+ setActiveDragSourceLane(undefined);
124
+ }, []);
125
+
126
+ const board = useKanban(sessionsList, workspacesList, sessionStatus);
127
+ const listSnapshot = useStore(sessionsList);
128
+
129
+ const handleSelectWorkspace = (id: string) => {
130
+ setUserWorkspaceId(id);
131
+ setStoredKanbanWorkspace(id);
132
+ };
133
+
134
+ // Default to user's saved selection if valid; otherwise default to current session's workspace or most recent workspace
135
+ const isUngroupedSelected = userWorkspaceId === "ungrouped";
136
+
137
+ const selectedWorkspace = useMemo(() => {
138
+ if (isUngroupedSelected) return null;
139
+ if (
140
+ userWorkspaceId !== null &&
141
+ board.sortedWorkspaces.some((w) => w.workspaceId === userWorkspaceId)
142
+ ) {
143
+ return (
144
+ board.sortedWorkspaces.find((w) => w.workspaceId === userWorkspaceId) ??
145
+ null
146
+ );
147
+ }
148
+ if (currentSessionId) {
149
+ const match = board.sortedWorkspaces.find((w) =>
150
+ w.sessionIds.includes(currentSessionId),
151
+ );
152
+ if (match) return match;
153
+ }
154
+ return board.sortedWorkspaces[0] ?? null;
155
+ }, [
156
+ isUngroupedSelected,
157
+ userWorkspaceId,
158
+ currentSessionId,
159
+ board.sortedWorkspaces,
160
+ ]);
161
+
162
+ const effectiveWorkspaceId = isUngroupedSelected
163
+ ? "ungrouped"
164
+ : selectedWorkspace?.workspaceId;
165
+
166
+ const handleStartTask = async () => {
167
+ if (isStarting) return;
168
+ setIsStarting(true);
169
+ try {
170
+ await startTask(effectiveWorkspaceId as WorkspaceId | undefined);
171
+ } finally {
172
+ setIsStarting(false);
173
+ }
174
+ };
175
+
176
+ const handlePrepareTask = async (prompt: string) => {
177
+ try {
178
+ await prepareTask(
179
+ prompt,
180
+ effectiveWorkspaceId as WorkspaceId | undefined,
181
+ );
182
+ } finally {
183
+ setIsPreparingTask(false);
184
+ }
185
+ };
186
+
187
+ const requestedHydrationRef = useRef<Set<SessionId>>(new Set());
188
+
189
+ useEffect(() => {
190
+ if (!refreshProjections) return;
191
+
192
+ const targetIds = new Set<SessionId>();
193
+ const now = Date.now();
194
+ if (selectedWorkspace) {
195
+ for (const id of listSnapshot.ids) {
196
+ if (!requestedHydrationRef.current.has(id)) {
197
+ const summary = listSnapshot.byId[id];
198
+ if (
199
+ summary &&
200
+ isSessionInWorkspace(summary, selectedWorkspace) &&
201
+ isSessionEligibleForHydration(summary, now) &&
202
+ summary.projectionValues?.kanban === undefined
203
+ ) {
204
+ targetIds.add(id);
205
+ }
206
+ }
207
+ }
208
+ } else {
209
+ for (const id of listSnapshot.ids) {
210
+ const summary = listSnapshot.byId[id];
211
+ if (
212
+ summary === undefined ||
213
+ requestedHydrationRef.current.has(id) ||
214
+ !isSessionEligibleForHydration(summary, now)
215
+ )
216
+ continue;
217
+ if (
218
+ isUngroupedSelected &&
219
+ board.sortedWorkspaces.some((workspace) =>
220
+ isSessionInWorkspace(summary, workspace),
221
+ )
222
+ )
223
+ continue;
224
+ const values = summary.projectionValues;
225
+ if (values === undefined || values.kanban === undefined) {
226
+ targetIds.add(id);
227
+ }
228
+ }
229
+ }
230
+
231
+ for (const id of targetIds) {
232
+ requestedHydrationRef.current.add(id);
233
+ void refreshProjections(id).catch((err: unknown) => {
234
+ console.warn(`[Kanban] Failed to hydrate projections for ${id}:`, err);
235
+ });
236
+ }
237
+ }, [
238
+ selectedWorkspace,
239
+ isUngroupedSelected,
240
+ board.sortedWorkspaces,
241
+ listSnapshot,
242
+ refreshProjections,
243
+ ]);
244
+
245
+ const workspaceCounts = board.workspaceCounts;
246
+ const sortedWorkspaces = board.sortedWorkspaces;
247
+
248
+ // Partition sessions into lanes using their projectionValues.kanban records
249
+ const partitioned = useMemo(() => {
250
+ return board.partition(
251
+ effectiveWorkspaceId as WorkspaceId | "ungrouped" | undefined,
252
+ );
253
+ }, [board, effectiveWorkspaceId]);
254
+
255
+ const searchScope = JSON.stringify(
256
+ partitioned.todo
257
+ .concat(partitioned.active, partitioned.review, partitioned.done)
258
+ .map((session) => session.id)
259
+ .sort(),
260
+ );
261
+
262
+ useEffect(() => {
263
+ setSearchState({ status: "pending" });
264
+ if (query === "") return;
265
+ const controller = new AbortController();
266
+ const timer = setTimeout(() => {
267
+ const sessionIds = searchRequestSchema.shape.sessionIds.parse(
268
+ JSON.parse(searchScope),
269
+ );
270
+ void searchSessions({ query, sessionIds }, controller.signal).then(
271
+ (result) => {
272
+ if (!controller.signal.aborted) {
273
+ setSearchState({
274
+ status: "settled",
275
+ query,
276
+ scope: searchScope,
277
+ workspaceId: effectiveWorkspaceId,
278
+ result,
279
+ });
280
+ }
281
+ },
282
+ );
283
+ }, 250);
284
+ return () => {
285
+ clearTimeout(timer);
286
+ controller.abort();
287
+ };
288
+ }, [query, searchSessions, searchScope, effectiveWorkspaceId]);
289
+
290
+ const searchResult =
291
+ searchState.status === "settled" &&
292
+ searchState.query === query &&
293
+ searchState.workspaceId === effectiveWorkspaceId &&
294
+ searchState.scope === searchScope
295
+ ? searchState.result
296
+ : undefined;
297
+
298
+ const displayedPartitioned = useMemo(() => {
299
+ if (query === "") return partitioned;
300
+ const matchingIds = new Set(
301
+ searchResult !== undefined && searchResult.ok
302
+ ? searchResult.value.items.map((item) => item.sessionId)
303
+ : [],
304
+ );
305
+ return filterPartitionedSessions(partitioned, matchingIds);
306
+ }, [partitioned, query, searchResult]);
307
+
308
+ let searchMessage = "";
309
+ if (query !== "") {
310
+ if (searchResult === undefined) {
311
+ searchMessage = "Searching session contents…";
312
+ } else if (!searchResult.ok) {
313
+ searchMessage = `Search failed: ${searchResult.error.message}`;
314
+ } else if (searchResult.value.hasMore) {
315
+ searchMessage = `Search limited to ${searchResultLimit} sessions in this workspace. Narrow your query.`;
316
+ } else if (
317
+ Object.values(displayedPartitioned).every(
318
+ (sessions) => sessions.length === 0,
319
+ )
320
+ ) {
321
+ searchMessage = "No matching sessions in this workspace.";
322
+ }
323
+ }
324
+
325
+ const handleDropSession = async (
326
+ sessionId: SessionId,
327
+ targetLane: KanbanLane,
328
+ ) => {
329
+ setActiveDragSourceLane(undefined);
330
+ const summary = listSnapshot.byId[sessionId];
331
+ const record = summary?.projectionValues?.kanban as
332
+ | KanbanRecord
333
+ | undefined;
334
+ if (!summary || !record) return;
335
+
336
+ const sourceLane = board.getLane(sessionId);
337
+ if (!isKanbanTransitionAllowed(sourceLane, targetLane)) return;
338
+
339
+ if (targetLane === "todo") {
340
+ await holdSession(sessionId);
341
+ } else if (targetLane === "review") {
342
+ if (sourceLane === "done") {
343
+ await reopen(sessionId);
344
+ } else {
345
+ await unholdSession(sessionId);
346
+ }
347
+ } else if (targetLane === "active") {
348
+ if (summary.blank) {
349
+ await startPreparedTask(sessionId, record.prompt ?? "");
350
+ } else if (record.heldAt !== undefined) {
351
+ await unholdSession(sessionId);
352
+ }
353
+ } else if (targetLane === "done") {
354
+ await markDone(sessionId);
355
+ }
356
+ };
357
+
358
+ const handleTogglePin = useCallback(
359
+ async (sessionId: SessionId) => {
360
+ const summary = listSnapshot.byId[sessionId];
361
+ // type-safe: projectionValues is typed Record<string, unknown> by SessionSummary
362
+ const record = summary?.projectionValues?.kanban as
363
+ | KanbanRecord
364
+ | undefined;
365
+ if (!record) return;
366
+ if (record.pinnedAt !== undefined) {
367
+ await unpinSession(sessionId);
368
+ } else {
369
+ await pinSession(sessionId);
370
+ }
371
+ },
372
+ [listSnapshot.byId, pinSession, unpinSession],
373
+ );
374
+
375
+ return (
376
+ <div className="dsh-kanban-pane">
377
+ <div className="dsh-kanban-topbar">
378
+ <div className="dsh-kanban-topbar-left">
379
+ <div className="dsh-kanban-title" title="Kanban">
380
+ <KanbanIcon size={18} />
381
+ </div>
382
+ {sortedWorkspaces.length > 0 && (
383
+ <div className="dsh-kanban-workspace-scroll">
384
+ {sortedWorkspaces.map((ws) => {
385
+ const label =
386
+ ws.title ||
387
+ ws.path.split("/").filter(Boolean).pop() ||
388
+ ws.workspaceId;
389
+ const counts = workspaceCounts.get(ws.workspaceId);
390
+ const running = counts ? counts.running : 0;
391
+ const inReview = counts ? counts.inReview : 0;
392
+ const alerts = counts ? counts.alerts : 0;
393
+ return (
394
+ <button
395
+ key={ws.workspaceId}
396
+ type="button"
397
+ onClick={() => handleSelectWorkspace(ws.workspaceId)}
398
+ className={`dsh-kanban-ws-btn ${effectiveWorkspaceId === ws.workspaceId ? "active" : ""}`}
399
+ title={ws.path}
400
+ >
401
+ <span>{label}</span>
402
+ {(running > 0 || inReview > 0 || alerts > 0) && (
403
+ <span className="dsh-kanban-ws-badges">
404
+ {running > 0 && (
405
+ <span
406
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-top"
407
+ title={`${running} running`}
408
+ >
409
+ {running}
410
+ </span>
411
+ )}
412
+ {alerts > 0 && (
413
+ <span
414
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-alert"
415
+ title={`${alerts} requiring attention`}
416
+ >
417
+ {alerts}
418
+ </span>
419
+ )}
420
+ {inReview > 0 && (
421
+ <span
422
+ className="dsh-kanban-ws-badge dsh-kanban-ws-badge-bottom"
423
+ title={`${inReview} in review`}
424
+ >
425
+ {inReview}
426
+ </span>
427
+ )}
428
+ </span>
429
+ )}
430
+ </button>
431
+ );
432
+ })}
433
+ {(isUngroupedSelected ||
434
+ Object.values(listSnapshot.byId).some(
435
+ (s) =>
436
+ s &&
437
+ !sortedWorkspaces.some((w) => isSessionInWorkspace(s, w)),
438
+ )) && (
439
+ <button
440
+ type="button"
441
+ onClick={() => handleSelectWorkspace("ungrouped")}
442
+ className={`dsh-kanban-ws-btn ${effectiveWorkspaceId === "ungrouped" ? "active" : ""}`}
443
+ title="Other Sessions"
444
+ >
445
+ <span>Other Sessions</span>
446
+ </button>
447
+ )}
448
+ </div>
449
+ )}
450
+ </div>
451
+ </div>
452
+
453
+ <div className="dsh-kanban-controls">
454
+ <button
455
+ type="button"
456
+ className="dsh-kanban-btn-start"
457
+ onClick={handleStartTask}
458
+ disabled={isStarting}
459
+ title="Start task immediately with native prompt input"
460
+ >
461
+ {isStarting ? "Starting..." : "+ Start task"}
462
+ </button>
463
+ <button
464
+ type="button"
465
+ className="dsh-kanban-btn-prepare"
466
+ onClick={() => setIsPreparingTask(true)}
467
+ title="Prepare task with prompt"
468
+ >
469
+ Prepare task
470
+ </button>
471
+ <div className="dsh-kanban-search-box">
472
+ <input
473
+ type="search"
474
+ className="dsh-kanban-search-input"
475
+ placeholder="Search sessions..."
476
+ value={searchQuery}
477
+ onChange={(e) => setSearchQuery(e.target.value)}
478
+ aria-label="Search sessions"
479
+ />
480
+ </div>
481
+ </div>
482
+
483
+ {searchMessage && (
484
+ <div className="dsh-kanban-search-status" role="status">
485
+ {searchMessage}
486
+ </div>
487
+ )}
488
+
489
+ <div
490
+ className="dsh-kanban-scroll"
491
+ aria-busy={query !== "" && searchResult === undefined}
492
+ >
493
+ <KanbanSection
494
+ lane="todo"
495
+ title="To Do"
496
+ sessions={displayedPartitioned.todo}
497
+ selectedSessionId={currentSessionId}
498
+ isPreparing={isPreparingTask}
499
+ activeDragSourceLane={activeDragSourceLane}
500
+ getAlert={board.getAlert}
501
+ onSelect={selectSession}
502
+ onDropSession={handleDropSession}
503
+ onDragStart={handleDragStart}
504
+ onDragEnd={handleDragEnd}
505
+ onSubmitPrepare={handlePrepareTask}
506
+ onCancelPrepare={() => setIsPreparingTask(false)}
507
+ />
508
+
509
+ <KanbanSection
510
+ lane="active"
511
+ title="Active"
512
+ sessions={displayedPartitioned.active}
513
+ selectedSessionId={currentSessionId}
514
+ activeDragSourceLane={activeDragSourceLane}
515
+ getAlert={board.getAlert}
516
+ onSelect={selectSession}
517
+ onDropSession={handleDropSession}
518
+ onDragStart={handleDragStart}
519
+ onDragEnd={handleDragEnd}
520
+ />
521
+
522
+ <KanbanSection
523
+ lane="review"
524
+ title="Review"
525
+ sessions={displayedPartitioned.review}
526
+ selectedSessionId={currentSessionId}
527
+ activeDragSourceLane={activeDragSourceLane}
528
+ getAlert={board.getAlert}
529
+ onSelect={selectSession}
530
+ onDropSession={handleDropSession}
531
+ onDragStart={handleDragStart}
532
+ onDragEnd={handleDragEnd}
533
+ />
534
+
535
+ <KanbanSection
536
+ lane="done"
537
+ title="Done"
538
+ sessions={displayedPartitioned.done}
539
+ selectedSessionId={currentSessionId}
540
+ activeDragSourceLane={activeDragSourceLane}
541
+ getAlert={board.getAlert}
542
+ onSelect={selectSession}
543
+ onDropSession={handleDropSession}
544
+ onDragStart={handleDragStart}
545
+ onDragEnd={handleDragEnd}
546
+ onTogglePin={handleTogglePin}
547
+ />
548
+ </div>
549
+
550
+ {activeDragSourceLane !== undefined && (
551
+ <div
552
+ className={`dsh-kanban-recycle-bin ${isRecycleOver ? "is-drag-over" : ""}`}
553
+ onDragOver={(e) => {
554
+ e.preventDefault();
555
+ e.dataTransfer.dropEffect = "move";
556
+ if (!isRecycleOver) setIsRecycleOver(true);
557
+ }}
558
+ onDragLeave={() => setIsRecycleOver(false)}
559
+ onDrop={async (e) => {
560
+ e.preventDefault();
561
+ setIsRecycleOver(false);
562
+ setActiveDragSourceLane(undefined);
563
+ const rawId = e.dataTransfer.getData("text/plain");
564
+ const sessionId = rawId as SessionId;
565
+ if (sessionId && listSnapshot.byId[sessionId]) {
566
+ await deleteSession(sessionId);
567
+ }
568
+ }}
569
+ >
570
+ <span>🗑️</span>
571
+ <span>Drop here to remove from board</span>
572
+ </div>
573
+ )}
574
+ </div>
575
+ );
576
+ }
@@ -0,0 +1,46 @@
1
+ import type { PropsRuntime } from "@deepseek-ai/dsh-client-ui-slots";
2
+ import type { KanbanPaneInjected } from "./KanbanPane.tsx";
3
+ import { KanbanStatusDot } from "./KanbanStatusDot.tsx";
4
+ import { formatKanbanAlertLabel } from "./store.ts";
5
+ import { useKanban } from "./use-kanban.ts";
6
+
7
+ /**
8
+ * Purpose: Render the sidebar's Kanban lane and alert indicator in a split pane.
9
+ * Contract:
10
+ * - Inputs: Bound Session identity and the sidebar's reactive stores.
11
+ * - Outputs: An accessible dot using the sidebar's classification and paint rules.
12
+ * - Throws / Errors: Missing required stores fail at the call site.
13
+ */
14
+ export function KanbanPaneStatus({
15
+ sessionId,
16
+ sessionsList,
17
+ workspacesList,
18
+ sessionStatus,
19
+ }: Pick<PropsRuntime<"split.pane.status">, "sessionId"> &
20
+ Pick<
21
+ KanbanPaneInjected,
22
+ "sessionsList" | "workspacesList" | "sessionStatus"
23
+ >) {
24
+ const board = useKanban(sessionsList, workspacesList, sessionStatus);
25
+ const lane = board.getLane(sessionId);
26
+ const alert = board.getAlert(sessionId);
27
+ const label =
28
+ alert === undefined
29
+ ? {
30
+ todo: "To Do",
31
+ active: "In Progress",
32
+ review: "In Review",
33
+ done: "Done",
34
+ }[lane]
35
+ : formatKanbanAlertLabel(alert);
36
+ return (
37
+ <span
38
+ className="dsh-kanban-pane-status"
39
+ role="img"
40
+ aria-label={label}
41
+ title={label}
42
+ >
43
+ <KanbanStatusDot state={alert === undefined ? lane : "alert"} />
44
+ </span>
45
+ );
46
+ }