dsh-work-fish 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +76 -2
  3. package/THIRD-PARTY-NOTICES.md +59 -0
  4. package/board/client.js +1041 -0
  5. package/cordis.patch.yml +172 -0
  6. package/core/approve-paths.mjs +387 -0
  7. package/core/approve-paths.test.mjs +241 -0
  8. package/core/approve.mjs +182 -0
  9. package/core/bootstrap.mjs +185 -0
  10. package/core/events.mjs +80 -0
  11. package/core/guard.mjs +155 -0
  12. package/core/index.mjs +637 -0
  13. package/core/parse.mjs +310 -0
  14. package/core/persona.mjs +98 -0
  15. package/core/report.mjs +370 -0
  16. package/core/skills.mjs +111 -0
  17. package/docs/DETAIL.md +1 -0
  18. package/docs/DETAIL.zh.md +1 -0
  19. package/docs/preview.webp +0 -0
  20. package/icon.png +0 -0
  21. package/locale/en.json +7 -0
  22. package/locale/zh.json +7 -0
  23. package/package.json +69 -4
  24. package/rules/code-rules.md +92 -0
  25. package/rules/experience-pool.md +59 -0
  26. package/rules/file-rules.md +134 -0
  27. package/rules/memory-rules.md +91 -0
  28. package/rules/task-rules.md +71 -0
  29. package/skills/code-review/LICENSE +202 -0
  30. package/skills/code-review/NOTICE.md +75 -0
  31. package/skills/code-review/SKILL.md +155 -0
  32. package/skills/code-review/upstream/README.md +258 -0
  33. package/skills/code-review/upstream/code-review.command.md +110 -0
  34. package/skills/code-review/upstream/plugin.json +10 -0
  35. package/skills/code-simplifier/LICENSE +202 -0
  36. package/skills/code-simplifier/NOTICE.md +72 -0
  37. package/skills/code-simplifier/SKILL.md +126 -0
  38. package/skills/code-simplifier/agents/code-simplifier.md +52 -0
  39. package/skills/code-simplifier/upstream/plugin.json +9 -0
  40. package/skills/comfyui-h3/SKILL.md +455 -0
  41. package/skills/comfyui-h3/reference/failures.md +84 -0
  42. package/skills/comfyui-h3/reference/serial-production.md +173 -0
  43. package/skills/delete-gate/SKILL.md +48 -0
  44. package/skills/doc-writing/SKILL.md +152 -0
  45. package/skills/doc-writing/reference/skeletons.md +81 -0
  46. package/skills/feature-dev/LICENSE +202 -0
  47. package/skills/feature-dev/NOTICE.md +67 -0
  48. package/skills/feature-dev/SKILL.md +181 -0
  49. package/skills/feature-dev/agents/code-architect.md +34 -0
  50. package/skills/feature-dev/agents/code-explorer.md +51 -0
  51. package/skills/feature-dev/agents/code-reviewer.md +46 -0
  52. package/skills/feature-dev/upstream/README.md +412 -0
  53. package/skills/feature-dev/upstream/feature-dev.command.md +125 -0
  54. package/skills/feature-dev/upstream/plugin.json +9 -0
  55. package/skills/frontend-design/LICENSE.txt +177 -0
  56. package/skills/frontend-design/SKILL.md +71 -0
  57. package/skills/git-flow/SKILL.md +80 -0
  58. package/skills/plan-revision/SKILL.md +54 -0
  59. package/skills/task-setup/SKILL.md +124 -0
  60. package/template/AGENTS.template.md +28 -0
  61. package/template/memory/pool/experience.md +9 -0
  62. package/template/memory/preferences.md +17 -0
  63. package/template/memory/projects/README.md +6 -0
  64. package/template/memory/user-profile.md +33 -0
  65. package/template/persona-core.md +32 -0
  66. package/template/persona-user.md +0 -0
  67. package/template/rules/user-rules.md +20 -0
  68. package/template/rules-index.md +50 -0
  69. package/template/tasks/index.md +34 -0
  70. package/tools/lib/paths.mjs +31 -0
  71. package/tools/lib/persona.mjs +454 -0
  72. package/tools/lib/taskboard.mjs +708 -0
  73. package/tools/wf-audit.cmd +3 -0
  74. package/tools/wf-audit.ps1 +242 -0
  75. package/tools/wf-mem.mjs +336 -0
  76. package/tools/wf-metrics.mjs +601 -0
  77. package/tools/wf-persona.mjs +337 -0
  78. package/tools/wf-pool.mjs +250 -0
  79. package/tools/wf-preview.mjs +240 -0
  80. package/tools/wf-recent.mjs +168 -0
  81. package/tools/wf-review.mjs +650 -0
  82. package/tools/wf-rule.mjs +407 -0
  83. package/tools/wf-snapshot.mjs +100 -0
  84. package/tools/wf-spec.mjs +882 -0
  85. package/tools/wf-task.mjs +298 -0
@@ -0,0 +1,1041 @@
1
+ /**
2
+ * Browser half of Work Fish (`dsh-work-fish` client entry).
3
+ *
4
+ * One surface: the task panel. It draws no character of its own; what it shows
5
+ * is the thing only Work Fish can show: the ledger.
6
+ *
7
+ * Three mounts:
8
+ *
9
+ * - `conversation.session.header.utilities` — a button that toggles the
10
+ * panel, plus a seat that publishes the current session's composer actions
11
+ * so the panel's "问大肥鱼" line can hand a question to that session;
12
+ * - `shell.overlay` — the panel itself, floating over every page and dragged
13
+ * by its own header;
14
+ * - `settings.section` — the persona editor and read-only host facts.
15
+ *
16
+ * The panel opens from the header button. `GET /wf/events` is the long poll that
17
+ * tells it to refresh after a write elsewhere moved the ledger.
18
+ *
19
+ * @module dsh-work-fish/client
20
+ */
21
+
22
+ window.__ModuleLoader__.load({
23
+ id: 'dsh-work-fish',
24
+ factory(require) {
25
+ const React = require('react')
26
+ const h = React.createElement
27
+
28
+ /** `react-dom`, used to float the panel and its portal host outside the header. */
29
+ let reactDomModule
30
+ function reactDOM() {
31
+ if (reactDomModule !== undefined) return reactDomModule
32
+ try {
33
+ const dom = require('react-dom')
34
+ if (typeof dom?.createPortal === 'function') {
35
+ reactDomModule = dom
36
+ return dom
37
+ }
38
+ } catch {
39
+ reactDomModule = null
40
+ }
41
+ return null
42
+ }
43
+
44
+ /** Must match `ROUTE_PREFIX` in `core/index.mjs`. */
45
+ const ROUTE = '/wf'
46
+
47
+ /** Client-side identity, shared with the tests. */
48
+ const BOARD_ATTR = 'data-wf-board'
49
+ const SEAT_ATTR = 'data-wf-seat'
50
+ const ROW_ATTR = 'data-wf-row'
51
+
52
+ /** Panel geometry: one width, a drag handle, and the viewport clamp. */
53
+ const PANEL_WIDTH = 400
54
+ const PANEL_HEIGHT = 540
55
+ const POSITION_KEY = 'wf:board-position:v1'
56
+
57
+ /** Refresh cadence while the panel is open, in milliseconds. */
58
+ const POLL_MS = 60_000
59
+
60
+ /** The CSS this module installs once. */
61
+ const CSS = `
62
+ :root{--wf-danger:#c02b2b;--wf-warn:#8a5d0c;--wf-success:#1f8a55;--wf-on-accent:#fff}
63
+ [data-wf-board]{position:fixed;z-index:31;display:flex;flex-direction:column;border-radius:16px;background:var(--dsw-alias-bg-base,#fff);border:1px solid var(--dsw-alias-border-l2,#e3e8f2);box-shadow:0 28px 72px rgba(15,23,42,.28),0 4px 14px rgba(15,23,42,.08);color:var(--dsw-alias-label-primary,#1d2433);overflow:hidden}
64
+ [data-wf-board] *{box-sizing:border-box}
65
+ [data-wf-board] .jp-head{padding:12px 14px 0;border-bottom:1px solid var(--dsw-alias-border-l1,#eef1f7);cursor:grab;user-select:none;flex:none}
66
+ [data-wf-board][data-dragging="true"] .jp-head{cursor:grabbing}
67
+ [data-wf-board] .jp-title-row{display:flex;align-items:center;gap:9px}
68
+ [data-wf-board] .jp-avatar{width:26px;height:26px;border-radius:8px;background:linear-gradient(135deg,#e8efff,#d6e2ff);display:flex;align-items:center;justify-content:center;font-size:14px;flex:none;box-shadow:inset 0 0 0 1px rgba(77,107,254,.14)}
69
+ [data-wf-board] .jp-title{font-size:13.5px;font-weight:600;letter-spacing:.01em}
70
+ [data-wf-board] .jp-close{margin-left:auto;width:26px;height:26px;border-radius:7px;border:1px solid var(--dsw-alias-border-l1,#eef1f7);background:0 0;color:var(--dsw-alias-label-tertiary,#8b96ab);font-size:12px;line-height:1;cursor:pointer;flex:none}
71
+ [data-wf-board] .jp-close:hover{background:var(--dsw-alias-interactive-bg-hover,#f2f5fb);color:var(--dsw-alias-label-primary,#1d2433)}
72
+ [data-wf-board] .jp-sub{font-size:11px;color:var(--dsw-alias-label-tertiary,#8b96ab);margin-top:3px}
73
+ [data-wf-board] .jp-tabs{display:flex;gap:2px;margin:10px 0 0;padding:3px;background:var(--dsw-alias-bg-layer-2,#f1f4fa);border-radius:9px}
74
+ [data-wf-board] .jp-tab{flex:1;min-width:0;height:28px;padding:0;border:0;border-radius:7px;background:0 0;color:var(--dsw-alias-label-secondary,#6b7488);font:inherit;font-size:11px;line-height:1;cursor:pointer;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
75
+ [data-wf-board] .jp-tab:hover{color:var(--dsw-alias-label-primary,#1d2433)}
76
+ [data-wf-board] .jp-tab[data-active="true"]{background:var(--dsw-alias-bg-base,#fff);color:var(--dsw-alias-label-primary,#1d2433);font-weight:600;box-shadow:0 1px 4px rgba(15,23,42,.12)}
77
+ [data-wf-board] .jp-list{flex:1;min-height:0;overflow-y:auto;padding:10px 12px 12px;display:flex;flex-direction:column;gap:8px;scrollbar-width:thin;scrollbar-color:rgba(120,132,160,.35) transparent}
78
+ [data-wf-board] .jp-list::-webkit-scrollbar{width:8px}
79
+ [data-wf-board] .jp-list::-webkit-scrollbar-thumb{background:rgba(120,132,160,.28);border-radius:4px;border:2px solid transparent;background-clip:content-box}
80
+ [data-wf-board] .jp-alert{font-size:11px;color:var(--wf-warn);background:color-mix(in srgb,var(--wf-warn) 8%,transparent);border:1px solid color-mix(in srgb,var(--wf-warn) 28%,transparent);border-radius:7px;padding:5px 8px}
81
+ [data-wf-board] .jp-row{border:1px solid var(--dsw-alias-border-l1,#eef1f7);border-radius:10px;padding:9px 10px;background:var(--dsw-alias-bg-base,#fff);transition:border-color .12s,box-shadow .12s}
82
+ [data-wf-board] .jp-row:hover{border-color:var(--dsw-alias-border-l2,#e3e8f2);box-shadow:0 2px 10px rgba(15,23,42,.06)}
83
+ [data-wf-board] .jp-row[data-overdue="true"]{border-color:color-mix(in srgb,var(--wf-danger) 35%,transparent);background:color-mix(in srgb,var(--wf-danger) 4%,transparent)}
84
+ [data-wf-board] .jp-row-top{display:flex;align-items:center;gap:6px}
85
+ [data-wf-board] .jp-tag{font-size:10.5px;padding:2px 7px;border-radius:999px;background:var(--dsw-alias-bg-layer-2,#f1f4fa);color:var(--dsw-alias-label-secondary,#6b7488);font-weight:500}
86
+ [data-wf-board] .jp-tag[data-kind="inProgress"]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 12%,transparent);color:var(--dsw-alias-state-business-primary,#4d6bfe)}
87
+ [data-wf-board] .jp-tag[data-kind="waiting"]{background:color-mix(in srgb,var(--wf-warn) 14%,transparent);color:var(--wf-warn)}
88
+ [data-wf-board] .jp-tag[data-kind="done"]{background:color-mix(in srgb,var(--wf-success) 12%,transparent);color:var(--wf-success)}
89
+ [data-wf-board] .jp-id{font:10.5px/1 Consolas,monospace;color:var(--dsw-alias-label-tertiary,#81858c)}
90
+ [data-wf-board] .jp-overdue{margin-left:auto;font-size:10.5px;color:var(--wf-danger);font-weight:500}
91
+ [data-wf-board] .jp-row-title{font-size:12.5px;font-weight:600;margin-top:5px;line-height:1.45}
92
+ [data-wf-board] .jp-meta{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#8b96ab);margin-top:3px}
93
+ [data-wf-board] .jp-next{font-size:10.5px;color:var(--dsw-alias-label-secondary,#6b7488);margin-top:5px;background:var(--dsw-alias-bg-layer-1,#f7f9fd);border-radius:6px;padding:4px 7px;line-height:1.45}
94
+ [data-wf-board] .jp-next b{color:var(--dsw-alias-state-business-primary,#4d6bfe);font-weight:600;margin-right:2px}
95
+ [data-wf-board] .jp-acts{display:flex;gap:6px;margin-top:8px;flex-wrap:wrap}
96
+ [data-wf-board] .jp-act{height:27px;padding:0 10px;border:.5px solid var(--dsw-alias-border-l3,#d5dbe7);border-radius:6px;background:0 0;color:var(--dsw-alias-label-primary,#1d2433);font:inherit;font-size:11.5px;cursor:pointer}
97
+ [data-wf-board] .jp-act:hover{background:var(--dsw-alias-interactive-bg-hover,#f2f5fb);border-color:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--dsw-alias-state-business-primary,#4d6bfe)}
98
+ [data-wf-board] .jp-act[data-primary="true"]{background:var(--dsw-alias-state-business-primary,#4d6bfe);border-color:transparent;color:var(--wf-on-accent)}
99
+ [data-wf-board] .jp-act:disabled{opacity:.45;cursor:default}
100
+ [data-wf-board] .jp-compose{margin-top:8px;border:1px solid var(--dsw-alias-border-l1,#eef1f7);border-radius:8px;padding:8px;background:var(--dsw-alias-bg-layer-1,#f7f9fd);display:flex;flex-direction:column;gap:6px}
101
+ [data-wf-board] .jp-input{width:100%;height:29px;padding:0 9px;border:1px solid var(--dsw-alias-border-l2,#e3e8f2);border-radius:7px;background:var(--dsw-alias-bg-base,#fff);color:var(--dsw-alias-label-primary,#1d2433);font:inherit;font-size:11.5px}
102
+ [data-wf-board] .jp-input:focus{outline:none;border-color:var(--dsw-alias-state-business-primary,#4d6bfe);box-shadow:0 0 0 2px color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 16%,transparent)}
103
+ [data-wf-board] .jp-chips{display:flex;gap:5px;flex-wrap:wrap}
104
+ [data-wf-board] .jp-chip{display:inline-flex;align-items:center;min-height:26px;padding:0 9px;border-radius:999px;border:1px solid var(--dsw-alias-border-l2,#e3e8f2);background:var(--dsw-alias-bg-base,#fff);color:var(--dsw-alias-label-secondary,#6b7488);font-size:11px;cursor:pointer}
105
+ [data-wf-board] .jp-chip:hover{border-color:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--dsw-alias-state-business-primary,#4d6bfe)}
106
+ [data-wf-board] .jp-toast{font-size:11px;color:var(--dsw-alias-label-secondary,#6b7488);background:var(--dsw-alias-bg-layer-2,#eef2ff);border-radius:7px;padding:6px 9px}
107
+ [data-wf-board] .jp-empty{font-size:11px;color:var(--dsw-alias-label-tertiary,#8b96ab);text-align:center;padding:24px 0}
108
+ [data-wf-board] .jp-foot{border-top:1px solid var(--dsw-alias-border-l1,#eef1f7);padding:9px 14px 11px;display:flex;flex-direction:column;gap:6px;flex:none}
109
+ [data-wf-board] .jp-ask{display:flex;align-items:center;gap:7px}
110
+ [data-wf-board] .jp-ask input{flex:1;min-width:0;height:32px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#e3e8f2);border-radius:8px;background:var(--dsw-alias-bg-layer-1,#f7f9fd);color:var(--dsw-alias-label-primary,#1d2433);font:inherit;font-size:11.5px}
111
+ [data-wf-board] .jp-ask input:focus{outline:none;border-color:var(--dsw-alias-state-business-primary,#4d6bfe);background:var(--dsw-alias-bg-base,#fff)}
112
+ [data-wf-board] .jp-send{width:33px;height:33px;flex:none;border:0;border-radius:50%;background:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--wf-on-accent);font-size:13px;cursor:pointer}
113
+ [data-wf-board] .jp-send:disabled{opacity:.35;cursor:default}
114
+ [data-wf-board] .jp-note{font-size:10.5px;color:var(--dsw-alias-label-tertiary,#81858c);text-align:right}
115
+ [data-wf-seat]{display:inline-flex;align-items:center;gap:6px;height:26px;padding:0 9px;border:.5px solid var(--dsw-alias-border-l2,#e3e8f2);border-radius:999px;background:0 0;color:var(--dsw-alias-label-secondary,#6b7488);font:inherit;font-size:11.5px;cursor:pointer}
116
+ [data-wf-seat]:hover{background:var(--dsw-alias-interactive-bg-hover,#f2f5fb);color:var(--dsw-alias-label-primary,#1d2433)}
117
+ [data-wf-seat][data-open="true"]{background:color-mix(in srgb,var(--dsw-alias-state-business-primary,#4d6bfe) 10%,transparent);color:var(--dsw-alias-state-business-primary,#4d6bfe);border-color:transparent}
118
+ [data-wf-seat] .jp-seat-count{font-variant-numeric:tabular-nums;color:var(--wf-danger);font-weight:600}
119
+ [data-wf-settings]{width:100%;font-size:13px;line-height:22px;color:var(--dsw-alias-label-primary,#1d2433)}
120
+ [data-wf-settings] .jps-alert{display:flex;align-items:center;gap:10px;margin:0 0 18px;padding:0 0 12px;border-bottom:.5px solid var(--dsw-alias-border-l2,#e3e8f2);font-size:12px;line-height:18px;color:var(--dsw-alias-state-warn-primary,var(--wf-warn))}
121
+ [data-wf-settings] .jps-alert-dot{flex:none;width:6px;height:6px;border-radius:50%;background:currentColor}
122
+ [data-wf-settings] .jps-alert-text{flex:1;min-width:0}
123
+ [data-wf-settings] .jps-card{box-sizing:border-box;width:100%;padding:0 16px 4px;border:.5px solid var(--dsw-alias-settings-card-stroke,var(--dsw-alias-border-l3,#d5dbe7));border-radius:var(--dsw-radius-xl,20px);background:var(--dsw-alias-settings-card-fill,var(--dsw-alias-bg-layer-2,#f1f4fa))}
124
+ [data-wf-settings] .jps-card+.jps-card{margin-top:20px}
125
+ [data-wf-settings] .jps-title{margin:0;padding:14px 0 2px;font-size:14px;line-height:20px;font-weight:600}
126
+ [data-wf-settings] .jps-row{display:grid;grid-template-columns:minmax(0,1fr) 208px;align-items:center;column-gap:16px;padding:12px 0;border-bottom:.5px solid var(--dsw-alias-border-l2,#e3e8f2)}
127
+ [data-wf-settings] .jps-row[data-span="full"]{grid-template-columns:minmax(0,1fr)}
128
+ [data-wf-settings] .jps-card .jps-row:last-child{border-bottom:none}
129
+ [data-wf-settings] .jps-label{font-size:14px;line-height:20px}
130
+ [data-wf-settings] .jps-hint{margin-top:2px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#6b7488)}
131
+ [data-wf-settings] .jps-value{justify-self:end;min-width:0;font-size:12px;line-height:18px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary,#6b7488);text-align:right;word-break:break-all}
132
+ [data-wf-settings] .jps-btn{height:30px;padding:0 12px;border:.5px solid var(--dsw-alias-border-l3,#d5dbe7);border-radius:var(--dsw-radius-sm,8px);background:0 0;color:var(--dsw-alias-label-primary,#1d2433);font:inherit;font-size:13px;line-height:20px;cursor:pointer}
133
+ [data-wf-settings] .jps-btn:hover{background:var(--dsw-alias-interactive-bg-hover,#f2f5fb)}
134
+ [data-wf-settings] .jps-btn[data-primary="true"]{border-color:transparent;background:var(--dsw-alias-state-business-primary,#4d6bfe);color:var(--wf-on-accent)}
135
+ [data-wf-settings] .jps-btn[data-primary="true"][disabled]{background:var(--dsw-alias-bg-layer-2,#f1f4fa);color:var(--dsw-alias-label-tertiary,#8b96ab);cursor:default}
136
+ [data-wf-settings] .jps-btn[data-size="sm"]{height:26px;padding:0 8px;font-size:12px}
137
+ [data-wf-settings] .jps-editor{display:flex;flex-direction:column;gap:8px;margin-top:8px;padding-bottom:12px}
138
+ [data-wf-settings] .jps-textarea{width:100%;height:132px;min-height:96px;padding:10px 12px;border:.5px solid var(--dsw-alias-border-l2,#e3e8f2);border-radius:var(--dsw-radius-sm,8px);background:var(--dsw-alias-bg-base,#fff);color:inherit;font-family:inherit;font-size:13px;line-height:20px;resize:vertical}
139
+ [data-wf-settings] .jps-textarea[data-invalid]{border-color:var(--dsw-alias-state-error-primary,var(--wf-danger))}
140
+ [data-wf-settings] .jps-foot{display:flex;align-items:center;gap:12px}
141
+ [data-wf-settings] .jps-count{font-size:12px;line-height:18px;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-secondary,#6b7488)}
142
+ [data-wf-settings] .jps-count[data-over="true"]{color:var(--dsw-alias-state-error-primary,var(--wf-danger))}
143
+ [data-wf-settings] .jps-status{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary,#6b7488)}
144
+ [data-wf-settings] .jps-note-inline{font-size:12px;line-height:18px;color:var(--dsw-alias-state-warn-primary,var(--wf-warn))}
145
+ [data-wf-settings] .jps-foot-actions{margin-left:auto;display:flex;align-items:center;gap:8px}
146
+ @media (max-width:420px){[data-wf-settings] .jps-row{grid-template-columns:minmax(0,1fr);row-gap:8px}[data-wf-settings] .jps-value{justify-self:start;text-align:left}}
147
+ @media (prefers-reduced-motion: reduce){[data-wf-board] *{transition:none!important}}
148
+ `
149
+
150
+ /** Install the stylesheet once per document, replacing a stale one on reload. */
151
+ function installCss() {
152
+ if (typeof document === 'undefined') return
153
+ const id = 'wf-css'
154
+ let style = document.getElementById(id)
155
+ if (style === null) {
156
+ style = document.createElement('style')
157
+ style.id = id
158
+ document.head.appendChild(style)
159
+ }
160
+ if (style.textContent !== CSS) style.textContent = CSS
161
+ }
162
+
163
+ /**
164
+ * Installed before the first component renders: a reloaded module must not
165
+ * paint with the sheet left behind by the previous generation.
166
+ */
167
+ installCss()
168
+
169
+ /** Report one activation fact to the host's diagnostics route. */
170
+ function report(payload) {
171
+ try {
172
+ void fetch(`${ROUTE}/client-report`, {
173
+ method: 'POST',
174
+ headers: { 'content-type': 'application/json' },
175
+ body: JSON.stringify(payload),
176
+ }).catch(() => {})
177
+ } catch {
178
+ return
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Module-level open flag: the header seat and the overlay panel mount in
184
+ * different slots but the same window, so one tiny store beats threading
185
+ * props through the slot API.
186
+ */
187
+ let boardOpen = false
188
+
189
+ /** @type {Set<(open: boolean) => void>} */
190
+ const openListeners = new Set()
191
+
192
+ /**
193
+ * Open or close the panel and tell every mounted consumer.
194
+ * @param {boolean} next desired state.
195
+ */
196
+ function setBoardOpen(next) {
197
+ if (boardOpen === next) return
198
+ boardOpen = next
199
+ for (const listener of [...openListeners]) {
200
+ try {
201
+ listener(next)
202
+ } catch {
203
+ continue
204
+ }
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Subscribe to the open state.
210
+ * @param {(open: boolean) => void} listener called on every change.
211
+ * @returns {() => void} unsubscribe.
212
+ */
213
+ function subscribeBoard(listener) {
214
+ openListeners.add(listener)
215
+ return () => openListeners.delete(listener)
216
+ }
217
+
218
+ /**
219
+ * Read the saved panel position, or place it above the composer corner.
220
+ * @returns {{x: number, y: number}} viewport coordinates.
221
+ */
222
+ function readPosition() {
223
+ if (typeof window === 'undefined') return { x: 0, y: 0 }
224
+ const fallback = clampPosition(window.innerWidth - PANEL_WIDTH - 28, window.innerHeight - PANEL_HEIGHT - 40)
225
+ try {
226
+ const raw = window.localStorage.getItem(POSITION_KEY)
227
+ if (raw !== null) {
228
+ const parsed = JSON.parse(raw)
229
+ if (Number.isFinite(parsed?.x) && Number.isFinite(parsed?.y)) {
230
+ return clampPosition(parsed.x, parsed.y)
231
+ }
232
+ }
233
+ } catch {
234
+ return fallback
235
+ }
236
+ return fallback
237
+ }
238
+
239
+ /**
240
+ * Keep the panel inside the viewport.
241
+ * @param {number} x left.
242
+ * @param {number} y top.
243
+ * @returns {{x: number, y: number}} clamped position.
244
+ */
245
+ function clampPosition(x, y) {
246
+ const maxX = Math.max(8, window.innerWidth - Math.min(PANEL_WIDTH, window.innerWidth - 16) - 8)
247
+ const maxY = Math.max(8, window.innerHeight - 140)
248
+ return { x: Math.min(Math.max(8, x), maxX), y: Math.min(Math.max(8, y), maxY) }
249
+ }
250
+
251
+ /** Persist one panel position. */
252
+ function savePosition(position) {
253
+ try {
254
+ window.localStorage.setItem(POSITION_KEY, JSON.stringify(position))
255
+ } catch {
256
+ return
257
+ }
258
+ }
259
+
260
+ /** The weekday label the ledger uses. */
261
+ const WEEKDAY = { Mon: '周一', Tue: '周二', Wed: '周三', Thu: '周四', Fri: '周五', Sat: '周六', Sun: '周日' }
262
+
263
+ /** Read the maximum revision across the active rows. */
264
+ function maxRevision(data) {
265
+ let max = 0
266
+ for (const rows of [data?.inProgress, data?.todo, data?.waiting]) {
267
+ for (const row of Array.isArray(rows) ? rows : []) {
268
+ if (Number.isFinite(row?.rev)) max = Math.max(max, row.rev)
269
+ }
270
+ }
271
+ return max
272
+ }
273
+
274
+ /**
275
+ * Session-scoped facts the conversational seat offers the global panel.
276
+ *
277
+ * The panel mounts once over every page, so it cannot read a session's
278
+ * composer directly; the header seat publishes those facts here instead.
279
+ */
280
+ let sessionBridge = { sessionId: '', running: false, inputActions: null }
281
+ const sessionBridgeListeners = new Set()
282
+
283
+ /** Merge a patch and notify only when a field actually changed. */
284
+ function bridgeUpdate(patch) {
285
+ const next = { ...sessionBridge, ...patch }
286
+ if (
287
+ next.sessionId === sessionBridge.sessionId &&
288
+ next.running === sessionBridge.running &&
289
+ next.inputActions === sessionBridge.inputActions
290
+ ) {
291
+ return
292
+ }
293
+ sessionBridge = next
294
+ for (const listener of sessionBridgeListeners) listener(sessionBridge)
295
+ }
296
+
297
+ /** Subscribe to bridge updates; returns the unsubscribe. */
298
+ function bridgeSubscribe(listener) {
299
+ sessionBridgeListeners.add(listener)
300
+ return () => sessionBridgeListeners.delete(listener)
301
+ }
302
+
303
+ /** One task row, its actions, and the inline composer. */
304
+ function TaskRow({ row, kind, api }) {
305
+ const overdue = Number.isFinite(row?.overdueDays) && row.overdueDays > 0
306
+ const meta = []
307
+ if (kind === 'waiting') {
308
+ if (row.who) meta.push(`等 ${row.who}`)
309
+ if (row.what) meta.push(row.what)
310
+ if (row.nudge) meta.push(`催 ${row.nudge}`)
311
+ } else if (kind === 'done') {
312
+ if (row.completed) meta.push(`完成 ${row.completed}`)
313
+ if (row.deliverable) meta.push(row.deliverable)
314
+ } else {
315
+ meta.push(`截止 ${row.dueRaw || '未定'}`)
316
+ }
317
+ if (row.priority) meta.push(`优先级 ${row.priority}`)
318
+ if (Number.isFinite(row.rev) && row.rev > 0) meta.push(`r${row.rev}`)
319
+
320
+ const id = row.id || ''
321
+ const busy = id !== '' && api.busyKey.startsWith(`${id}:`)
322
+ const composing = api.compose !== null && api.compose.id === id
323
+ const canWrite = api.writes === true && id !== '' && Number.isInteger(row.rev) && row.rev > 0
324
+ const act = (action, body = {}) => api.action(action, { id, expectRev: row.rev, ...body })
325
+ const openCompose = (mode) => api.setCompose({ id, rev: row.rev, mode, text: '', result: '', deliverable: '' })
326
+
327
+ const actions = []
328
+ if (canWrite) {
329
+ if (kind === 'todo') {
330
+ actions.push(h('button', { key: 'start', className: 'jp-act', 'data-primary': 'true', disabled: busy, onClick: () => act('start') }, busy ? '写入中…' : '开始'))
331
+ } else if (kind === 'inProgress') {
332
+ actions.push(h('button', { key: 'advance', className: 'jp-act', disabled: busy, onClick: () => openCompose('advance') }, '推进'))
333
+ actions.push(h('button', { key: 'finish', className: 'jp-act', disabled: busy, onClick: () => openCompose('finish') }, '完成'))
334
+ actions.push(h('button', { key: 'pause', className: 'jp-act', disabled: busy, onClick: () => act('pause') }, '暂停'))
335
+ } else if (kind === 'waiting') {
336
+ actions.push(h('button', { key: 'nudge', className: 'jp-act', disabled: busy, onClick: () => act('nudge', { text: '催办' }) }, '催一下'))
337
+ actions.push(h('button', { key: 'resume', className: 'jp-act', 'data-primary': 'true', disabled: busy, onClick: () => act('resume') }, '继续'))
338
+ }
339
+ }
340
+
341
+ const composeNode =
342
+ composing === false
343
+ ? null
344
+ : h(
345
+ 'div',
346
+ { className: 'jp-compose' },
347
+ api.compose.mode === 'advance'
348
+ ? h(
349
+ React.Fragment,
350
+ null,
351
+ h('input', {
352
+ className: 'jp-input',
353
+ autoFocus: true,
354
+ placeholder: '写一句进展…',
355
+ value: api.compose.text,
356
+ onChange: (event) => api.updateCompose({ text: event.target.value }),
357
+ onKeyDown: (event) => {
358
+ if (event.key === 'Enter' && !event.nativeEvent?.isComposing) {
359
+ event.preventDefault()
360
+ api.submitCompose()
361
+ }
362
+ },
363
+ }),
364
+ h(
365
+ 'div',
366
+ { className: 'jp-chips' },
367
+ ...['已提交', '等评审', '已改完', '卡住了'].map((quick) =>
368
+ h('button', { key: quick, type: 'button', className: 'jp-chip', onClick: () => api.updateCompose({ text: quick }) }, quick),
369
+ ),
370
+ ),
371
+ )
372
+ : h(
373
+ React.Fragment,
374
+ null,
375
+ h('input', {
376
+ className: 'jp-input',
377
+ autoFocus: true,
378
+ placeholder: '结果(默认:已完成)',
379
+ value: api.compose.result,
380
+ onChange: (event) => api.updateCompose({ result: event.target.value }),
381
+ }),
382
+ h('input', {
383
+ className: 'jp-input',
384
+ placeholder: '交付物(可选)',
385
+ value: api.compose.deliverable,
386
+ onChange: (event) => api.updateCompose({ deliverable: event.target.value }),
387
+ }),
388
+ ),
389
+ h(
390
+ 'div',
391
+ { className: 'jp-acts' },
392
+ h(
393
+ 'button',
394
+ {
395
+ className: 'jp-act',
396
+ 'data-primary': 'true',
397
+ disabled: busy || (api.compose.mode === 'advance' && api.compose.text.trim() === ''),
398
+ onClick: () => api.submitCompose(),
399
+ },
400
+ busy ? '写入中…' : '记录',
401
+ ),
402
+ h('button', { className: 'jp-act', disabled: busy, onClick: () => api.setCompose(null) }, '取消'),
403
+ ),
404
+ )
405
+
406
+ return h(
407
+ 'div',
408
+ { className: 'jp-row', [ROW_ATTR]: row.id, 'data-overdue': overdue ? 'true' : undefined },
409
+ h(
410
+ 'div',
411
+ { className: 'jp-row-top' },
412
+ h('span', { className: 'jp-tag', 'data-kind': kind }, kind === 'waiting' ? '等待' : kind === 'todo' ? '待办' : kind === 'done' ? '已做' : '进行中'),
413
+ row.id ? h('span', { className: 'jp-id' }, row.id) : null,
414
+ overdue ? h('span', { className: 'jp-overdue' }, `逾期 ${row.overdueDays} 天`) : null,
415
+ ),
416
+ h('div', { className: 'jp-row-title' }, row.title || '(无标题)'),
417
+ meta.length > 0 ? h('div', { className: 'jp-meta' }, meta.join(' · ')) : null,
418
+ row.next ? h('div', { className: 'jp-next' }, h('b', null, '下一步'), ' ', row.next) : null,
419
+ actions.length > 0 ? h('div', { className: 'jp-acts' }, ...actions) : null,
420
+ composeNode,
421
+ )
422
+ }
423
+
424
+ /** The floating task panel: header handle, four tabs, rows, ask line. */
425
+ function TaskPanel({ position, onMove, onClose, data, error, loading, tabs, activeTab, onTab, draft, onDraft, onSend, canSend, toast, api }) {
426
+ const rows =
427
+ data === null
428
+ ? []
429
+ : activeTab === 'inProgress'
430
+ ? data.inProgress
431
+ : activeTab === 'todo'
432
+ ? data.todo
433
+ : activeTab === 'waiting'
434
+ ? data.waiting
435
+ : data.doneToday
436
+ const kind = activeTab === 'done' ? 'done' : activeTab
437
+ const counts = data?.counts ?? {}
438
+ const weekday = WEEKDAY[data?.today?.weekday] ?? ''
439
+ const alerts = Array.isArray(data?.alerts) ? data.alerts.slice(0, 2) : []
440
+ const empty = data !== null && rows.length === 0
441
+ const drag = React.useRef(null)
442
+ const [dragging, setDragging] = React.useState(false)
443
+
444
+ const onPointerDown = (event) => {
445
+ if (event.button !== 0) return
446
+ /** Buttons inside the header (the close control) must stay clickable. */
447
+ if (event.target instanceof Element && event.target.closest('button') !== null) return
448
+ event.currentTarget.setPointerCapture?.(event.pointerId)
449
+ drag.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, originX: position.x, originY: position.y }
450
+ setDragging(true)
451
+ }
452
+ const onPointerMove = (event) => {
453
+ const state = drag.current
454
+ if (state === null || state.pointerId !== event.pointerId) return
455
+ onMove(clampPosition(state.originX + (event.clientX - state.startX), state.originY + (event.clientY - state.startY)))
456
+ }
457
+ const onPointerUp = (event) => {
458
+ const state = drag.current
459
+ if (state === null || state.pointerId !== event.pointerId) return
460
+ drag.current = null
461
+ setDragging(false)
462
+ event.currentTarget.releasePointerCapture?.(event.pointerId)
463
+ onMove(position, true)
464
+ }
465
+
466
+ return h(
467
+ 'div',
468
+ {
469
+ [BOARD_ATTR]: 'true',
470
+ 'data-dragging': dragging ? 'true' : undefined,
471
+ style: {
472
+ left: `${position.x}px`,
473
+ top: `${position.y}px`,
474
+ width: `${Math.min(PANEL_WIDTH, typeof window === 'undefined' ? PANEL_WIDTH : window.innerWidth - 16)}px`,
475
+ height: `${Math.min(PANEL_HEIGHT, typeof window === 'undefined' ? PANEL_HEIGHT : window.innerHeight - 32)}px`,
476
+ },
477
+ role: 'dialog',
478
+ 'aria-label': '大肥鱼任务',
479
+ },
480
+ h(
481
+ 'div',
482
+ { className: 'jp-head', onPointerDown, onPointerMove, onPointerUp, onPointerCancel: onPointerUp },
483
+ h(
484
+ 'div',
485
+ { className: 'jp-title-row' },
486
+ h('span', { className: 'jp-avatar' }, '🐋'),
487
+ h('span', { className: 'jp-title' }, '大肥鱼 · 任务'),
488
+ h('button', { className: 'jp-close', type: 'button', 'aria-label': '关闭', onClick: onClose }, '✕'),
489
+ ),
490
+ h(
491
+ 'div',
492
+ { className: 'jp-sub' },
493
+ data === null
494
+ ? loading
495
+ ? '读取台账…'
496
+ : '台账不可读'
497
+ : `${data.today?.label ?? ''} ${weekday} · 逾期 ${counts.overdue ?? 0} · 活跃 ${counts.active ?? 0} · r${maxRevision(data)}`,
498
+ ),
499
+ h(
500
+ 'div',
501
+ { className: 'jp-tabs' },
502
+ tabs.map((tab) =>
503
+ h(
504
+ 'button',
505
+ {
506
+ key: tab.id,
507
+ type: 'button',
508
+ className: 'jp-tab',
509
+ 'data-active': activeTab === tab.id ? 'true' : undefined,
510
+ onClick: () => onTab(tab.id),
511
+ },
512
+ `${tab.label} ${tab.count}`,
513
+ ),
514
+ ),
515
+ ),
516
+ ),
517
+ h(
518
+ 'div',
519
+ { className: 'jp-list' },
520
+ toast ? h('div', { className: 'jp-toast' }, toast) : null,
521
+ error !== null ? h('div', { className: 'jp-alert' }, error) : null,
522
+ ...alerts.map((alert) => h('div', { key: alert, className: 'jp-alert' }, alert)),
523
+ empty ? h('div', { className: 'jp-empty' }, loading ? '读取台账…' : '这一栏是空的') : null,
524
+ rows.map((row) => h(TaskRow, { key: `${kind}:${row.id || row.title}`, row, kind, api })),
525
+ ),
526
+ h(
527
+ 'div',
528
+ { className: 'jp-foot' },
529
+ h(
530
+ 'div',
531
+ { className: 'jp-ask' },
532
+ h('input', {
533
+ value: draft,
534
+ placeholder: canSend ? '问大肥鱼,或让他推进…' : '到会话页才能发',
535
+ disabled: !canSend,
536
+ onChange: (event) => onDraft(event.target.value),
537
+ onKeyDown: (event) => {
538
+ if (event.key === 'Enter' && !event.nativeEvent?.isComposing) {
539
+ event.preventDefault()
540
+ onSend()
541
+ }
542
+ },
543
+ }),
544
+ h('button', { className: 'jp-send', type: 'button', disabled: !canSend || draft.trim() === '', onClick: onSend, 'aria-label': '发送' }, '↑'),
545
+ ),
546
+ h('div', { className: 'jp-note' }, '读自任务台账 · 打开时每 60 秒刷新'),
547
+ ),
548
+ )
549
+ }
550
+
551
+ /** The panel's data, writes and event subscription, mounted once. */
552
+ function BoardSurface() {
553
+ const [open, setOpen] = React.useState(boardOpen)
554
+ const [position, setPosition] = React.useState(readPosition)
555
+ const [data, setData] = React.useState(null)
556
+ const [error, setError] = React.useState(null)
557
+ const [loading, setLoading] = React.useState(false)
558
+ const [activeTab, setActiveTab] = React.useState('inProgress')
559
+ const [draft, setDraft] = React.useState('')
560
+ const [busyKey, setBusyKey] = React.useState('')
561
+ const [compose, setCompose] = React.useState(null)
562
+ const [toast, setToast] = React.useState('')
563
+ const [session, setSession] = React.useState(sessionBridge)
564
+
565
+ React.useEffect(() => subscribeBoard(setOpen), [])
566
+ React.useEffect(() => bridgeSubscribe(setSession), [])
567
+
568
+ const canSend = typeof session.inputActions?.setDraft === 'function' && typeof session.inputActions?.submit === 'function'
569
+
570
+ /** Fetch the task payload; never throws into render. */
571
+ const load = React.useCallback(async () => {
572
+ setLoading(true)
573
+ try {
574
+ const response = await fetch(`${ROUTE}/tasks`, { headers: { accept: 'application/json' }, cache: 'no-store' })
575
+ const body = await response.json()
576
+ if (!response.ok || body?.ok !== true) throw new Error(body?.detail || body?.message || `HTTP ${response.status}`)
577
+ setData(body)
578
+ setError(null)
579
+ } catch (failure) {
580
+ setError(`台账读取失败:${String(failure?.message ?? failure)}`)
581
+ } finally {
582
+ setLoading(false)
583
+ }
584
+ }, [])
585
+
586
+ /**
587
+ * Read once so the header button can show an overdue count, then refresh on
588
+ * the slow cadence while closed and the fast one while open.
589
+ */
590
+ React.useEffect(() => {
591
+ void load()
592
+ const timer = window.setInterval(() => {
593
+ if (!open) void load()
594
+ }, 5 * 60000)
595
+ return () => window.clearInterval(timer)
596
+ }, [load, open])
597
+
598
+ React.useEffect(() => {
599
+ if (!open) return undefined
600
+ void load()
601
+ const timer = window.setInterval(() => void load(), POLL_MS)
602
+ return () => window.clearInterval(timer)
603
+ }, [open, load])
604
+
605
+ /**
606
+ * Host events: a write elsewhere moved the ledger. The first poll
607
+ * subscribes from "now", so remounting the panel cannot replay an event
608
+ * that happened before it existed; after that the cursor follows the
609
+ * host's sequence — zero included, because a restarted host starts its
610
+ * sequence over.
611
+ */
612
+ React.useEffect(() => {
613
+ let alive = true
614
+ let since = null
615
+ const controller = new AbortController()
616
+ const run = async () => {
617
+ while (alive) {
618
+ try {
619
+ const query = since === null ? '?wait=8000' : `?since=${since}&wait=8000`
620
+ const response = await fetch(`${ROUTE}/events${query}`, {
621
+ headers: { accept: 'application/json' },
622
+ cache: 'no-store',
623
+ signal: controller.signal,
624
+ })
625
+ const body = await response.json()
626
+ if (body?.ok !== true) throw new Error(body?.message ?? 'events')
627
+ if (typeof body.since === 'number') since = body.since
628
+ for (const event of Array.isArray(body.events) ? body.events : []) {
629
+ if (event?.type === 'changed') void load()
630
+ }
631
+ } catch {
632
+ if (!alive) return
633
+ await new Promise((resolve) => window.setTimeout(resolve, 4000))
634
+ }
635
+ }
636
+ }
637
+ void run()
638
+ return () => {
639
+ alive = false
640
+ controller.abort()
641
+ }
642
+ }, [load])
643
+
644
+ /** Escape closes the panel, so it never sits in the way. */
645
+ React.useEffect(() => {
646
+ if (!open) return undefined
647
+ const onKey = (event) => {
648
+ if (event.key === 'Escape') setBoardOpen(false)
649
+ }
650
+ document.addEventListener('keydown', onKey)
651
+ return () => document.removeEventListener('keydown', onKey)
652
+ }, [open])
653
+
654
+ /** Move the panel, optionally persisting the result. */
655
+ const moveTo = React.useCallback((next, persist = false) => {
656
+ setPosition(next)
657
+ if (persist) savePosition(next)
658
+ }, [])
659
+
660
+ /** POST one task mutation, then reload the payload. */
661
+ const write = React.useCallback(
662
+ async (action, body) => {
663
+ setBusyKey(`${body.id}:${action}`)
664
+ try {
665
+ const response = await fetch(`${ROUTE}/tasks/${action}`, {
666
+ method: 'POST',
667
+ headers: { 'content-type': 'application/json', 'x-wf': '1' },
668
+ body: JSON.stringify(body),
669
+ })
670
+ const result = await response.json().catch(() => null)
671
+ if (!response.ok || result?.ok !== true) {
672
+ if (result?.verdict === 'STALE') setToast(`台账刚被改过(r${result.currentRev ?? '?'}),已刷新`)
673
+ else setToast(result?.message || `写入失败(HTTP ${response.status})`)
674
+ setCompose(null)
675
+ await load()
676
+ return false
677
+ }
678
+ const label = action === 'finish' ? '已完成' : action === 'start' ? '已开始' : action === 'pause' ? '已暂停' : action === 'nudge' ? '已记催办' : '已记录'
679
+ setToast(label)
680
+ setCompose(null)
681
+ await load()
682
+ return true
683
+ } catch (failure) {
684
+ setToast(`写入失败:${String(failure?.message ?? failure)}`)
685
+ return false
686
+ } finally {
687
+ setBusyKey('')
688
+ }
689
+ },
690
+ [load],
691
+ )
692
+
693
+ /** Patch the open composer. */
694
+ const updateCompose = React.useCallback((patch) => {
695
+ setCompose((current) => (current === null ? null : { ...current, ...patch }))
696
+ }, [])
697
+
698
+ /** Submit the open composer as advance or finish. */
699
+ const submitCompose = React.useCallback(() => {
700
+ if (compose === null) return
701
+ if (compose.mode === 'advance') {
702
+ const text = compose.text.trim()
703
+ if (text === '') return
704
+ void write('advance', { id: compose.id, expectRev: compose.rev, text })
705
+ } else {
706
+ void write('finish', {
707
+ id: compose.id,
708
+ expectRev: compose.rev,
709
+ result: compose.result.trim() || '已完成',
710
+ deliverable: compose.deliverable.trim() || undefined,
711
+ })
712
+ }
713
+ }, [compose, write])
714
+
715
+ /**
716
+ * The status line lives for four seconds; `toast` is its only owner.
717
+ */
718
+ React.useEffect(() => {
719
+ if (toast === '') return undefined
720
+ const timer = window.setTimeout(() => setToast(''), 4000)
721
+ return () => window.clearTimeout(timer)
722
+ }, [toast])
723
+
724
+ const onSend = () => {
725
+ const value = draft.trim()
726
+ if (value === '' || !canSend) return
727
+ try {
728
+ session.inputActions.setDraft(value)
729
+ session.inputActions.submit()
730
+ setDraft('')
731
+ } catch {
732
+ setError('发送失败:当前会话不接受输入')
733
+ }
734
+ }
735
+
736
+ const tabs = [
737
+ { id: 'inProgress', label: '进行中', count: data?.inProgress?.length ?? 0 },
738
+ { id: 'todo', label: '待办', count: data?.todo?.length ?? 0 },
739
+ { id: 'waiting', label: '等待', count: data?.waiting?.length ?? 0 },
740
+ { id: 'done', label: '今日', count: data?.doneToday?.length ?? 0 },
741
+ ]
742
+ const api = {
743
+ writes: data?.writes === true,
744
+ busyKey,
745
+ compose,
746
+ action: write,
747
+ setCompose,
748
+ updateCompose,
749
+ submitCompose,
750
+ }
751
+
752
+ if (!open) return null
753
+
754
+ const panel = h(TaskPanel, {
755
+ position,
756
+ onMove: moveTo,
757
+ onClose: () => setBoardOpen(false),
758
+ data,
759
+ error,
760
+ loading,
761
+ tabs,
762
+ activeTab,
763
+ onTab: setActiveTab,
764
+ draft,
765
+ onDraft: setDraft,
766
+ onSend,
767
+ canSend,
768
+ toast,
769
+ api,
770
+ })
771
+
772
+ const dom = reactDOM()
773
+ if (dom !== null && typeof document !== 'undefined') return dom.createPortal(panel, document.body)
774
+ return panel
775
+ }
776
+
777
+ /** Button in the conversation header: opens the panel and publishes session facts. */
778
+ function SessionSeat(props) {
779
+ const sessionId = typeof props?.sessionId === 'string' ? props.sessionId : ''
780
+ const inputActions = props?.inputActions ?? null
781
+ const running =
782
+ typeof props?.useSessionStatus === 'function'
783
+ ? props.useSessionStatus((statuses) => statuses?.get?.(sessionId)?.running === true)
784
+ : false
785
+ const [open, setOpen] = React.useState(boardOpen)
786
+ const [overdue, setOverdue] = React.useState(0)
787
+
788
+ React.useEffect(() => subscribeBoard(setOpen), [])
789
+ React.useEffect(() => {
790
+ bridgeUpdate({ sessionId, inputActions })
791
+ return () => bridgeUpdate({ sessionId: '', inputActions: null })
792
+ }, [sessionId, inputActions])
793
+ React.useEffect(() => {
794
+ bridgeUpdate({ running })
795
+ }, [running])
796
+
797
+ /** A cheap overdue count for the badge; the panel does the real reading. */
798
+ React.useEffect(() => {
799
+ let alive = true
800
+ const tick = async () => {
801
+ try {
802
+ const response = await fetch(`${ROUTE}/tasks`, { headers: { accept: 'application/json' }, cache: 'no-store' })
803
+ const body = await response.json()
804
+ if (alive && body?.ok === true) setOverdue(Number(body?.counts?.overdue ?? 0))
805
+ } catch {
806
+ return
807
+ }
808
+ }
809
+ void tick()
810
+ const timer = window.setInterval(() => void tick(), 5 * 60000)
811
+ return () => {
812
+ alive = false
813
+ window.clearInterval(timer)
814
+ }
815
+ }, [])
816
+
817
+ return h(
818
+ 'button',
819
+ {
820
+ type: 'button',
821
+ [SEAT_ATTR]: 'true',
822
+ 'data-open': open ? 'true' : undefined,
823
+ title: '大肥鱼任务台账',
824
+ onClick: () => setBoardOpen(!boardOpen),
825
+ },
826
+ h('span', null, '🐋 任务'),
827
+ overdue > 0 ? h('span', { className: 'jp-seat-count' }, overdue > 9 ? '9+' : String(overdue)) : null,
828
+ )
829
+ }
830
+
831
+ /**
832
+ * Settings → 大肥鱼: the persona editor plus read-only host facts — only
833
+ * what Work Fish itself owns.
834
+ */
835
+ function WorkFishSettings() {
836
+ const [info, setInfo] = React.useState(null)
837
+ const [error, setError] = React.useState(null)
838
+
839
+ /** Fetch the host's diagnostics; never throws into render. */
840
+ const loadInfo = React.useCallback(async () => {
841
+ try {
842
+ const response = await fetch(`${ROUTE}/info`, { headers: { accept: 'application/json' }, cache: 'no-store' })
843
+ const body = await response.json()
844
+ if (!response.ok || body?.ok !== true) throw new Error(body?.detail || body?.message || `HTTP ${response.status}`)
845
+ setInfo(body)
846
+ setError(null)
847
+ } catch (failure) {
848
+ setError(String(failure?.message ?? failure))
849
+ }
850
+ }, [])
851
+
852
+ React.useEffect(() => {
853
+ void loadInfo()
854
+ }, [loadInfo])
855
+
856
+ const [persona, setPersona] = React.useState(null)
857
+ const [personaDraft, setPersonaDraft] = React.useState('')
858
+ const [personaNote, setPersonaNote] = React.useState(null)
859
+ const [personaBusy, setPersonaBusy] = React.useState(false)
860
+
861
+ /** Read the current persona (mode, bytes, revision, user text). */
862
+ const loadPersona = React.useCallback(async () => {
863
+ try {
864
+ const response = await fetch(`${ROUTE}/persona`, { headers: { accept: 'application/json' }, cache: 'no-store' })
865
+ const body = await response.json()
866
+ if (!response.ok || body?.ok !== true) throw new Error(body?.message || `HTTP ${response.status}`)
867
+ setPersona(body)
868
+ setPersonaDraft(typeof body.user === 'string' ? body.user : '')
869
+ } catch (failure) {
870
+ setPersonaNote({ kind: 'error', text: `读取人设失败:${String(failure?.message ?? failure)}` })
871
+ }
872
+ }, [])
873
+
874
+ React.useEffect(() => {
875
+ void loadPersona()
876
+ }, [loadPersona])
877
+
878
+ /** UTF-8 byte count, the unit the store enforces. */
879
+ const personaBytes = (() => {
880
+ const text = personaDraft
881
+ try {
882
+ return new TextEncoder().encode(text).length
883
+ } catch {
884
+ return text.length
885
+ }
886
+ })()
887
+ const personaLimit = persona?.limit ?? 32768
888
+ const personaOver = personaBytes > personaLimit
889
+ /** Nothing to save until the draft differs from what is stored. */
890
+ const personaDirty = persona !== null && personaDraft.trimEnd() !== String(persona.user ?? '').trimEnd()
891
+
892
+ /** Put the user section, CAS-guarded by the revision we read. */
893
+ const savePersona = async () => {
894
+ if (personaBusy) return
895
+ if (personaOver) {
896
+ setPersonaNote({ kind: 'error', text: `超限 ${personaBytes - personaLimit} 字节,先删一些再保存。` })
897
+ return
898
+ }
899
+ setPersonaBusy(true)
900
+ try {
901
+ const response = await fetch(`${ROUTE}/persona`, {
902
+ method: 'PUT',
903
+ headers: { 'content-type': 'application/json', 'x-wf': '1' },
904
+ body: JSON.stringify({ mode: 'user', text: personaDraft, expectRevision: persona?.revision }),
905
+ })
906
+ const body = await response.json().catch(() => null)
907
+ if (response.ok && body?.ok === true) {
908
+ setPersonaNote({ kind: 'ok', text: '已保存,下一步对话生效(无需重启)。' })
909
+ await loadPersona()
910
+ } else if (response.status === 409) {
911
+ setPersonaNote({ kind: 'error', text: '人设已在别处改动,先点「重新载入」再保存。' })
912
+ } else {
913
+ setPersonaNote({ kind: 'error', text: `${body?.message ?? `HTTP ${response.status}`}` })
914
+ }
915
+ } catch (failure) {
916
+ setPersonaNote({ kind: 'error', text: String(failure?.message ?? failure) })
917
+ } finally {
918
+ setPersonaBusy(false)
919
+ }
920
+ }
921
+
922
+ const alertLine = (() => {
923
+ const unreadable = info !== null && info?.ledger?.readable === false
924
+ if (error === null && !unreadable) return null
925
+ return h(
926
+ 'div',
927
+ { className: 'jps-alert' },
928
+ h('span', { className: 'jps-alert-dot' }),
929
+ h('span', { className: 'jps-alert-text' }, error !== null ? '运行信息没读出来,设置仍可用' : '台账读不到,面板是空的'),
930
+ h('button', { type: 'button', className: 'jps-btn', 'data-size': 'sm', 'data-primary': 'true', onClick: () => void loadInfo() }, '重试'),
931
+ )
932
+ })()
933
+
934
+ const infoRow = (label, value, hint) =>
935
+ h(
936
+ 'div',
937
+ { className: 'jps-row' },
938
+ h('div', null, h('div', { className: 'jps-label' }, label), hint === undefined ? null : h('div', { className: 'jps-hint' }, hint)),
939
+ h('div', { className: 'jps-value' }, value),
940
+ )
941
+
942
+ const personaHint = persona?.mode === 'full' ? '整段人设生效中,此页只改补充' : '清空后保存即回出厂人设'
943
+
944
+ const factsCard = h(
945
+ 'section',
946
+ { className: 'jps-card' },
947
+ h('h3', { className: 'jps-title' }, '台账'),
948
+ infoRow('台账', info?.ledger?.path ?? '—', '唯一事实来源,面板与 CLI 读写同一份'),
949
+ infoRow('写入', info?.allowWrites === true ? '允许' : '已关闭', '关掉后面板只能读'),
950
+ )
951
+
952
+ const personaCard = h(
953
+ 'section',
954
+ { className: 'jps-card' },
955
+ h('h3', { className: 'jps-title' }, '人设'),
956
+ h(
957
+ 'div',
958
+ { className: 'jps-row', 'data-span': 'full' },
959
+ h(
960
+ 'div',
961
+ null,
962
+ h('div', { className: 'jps-label' }, '补充'),
963
+ h('div', { className: 'jps-hint' }, personaHint),
964
+ h(
965
+ 'div',
966
+ { className: 'jps-editor' },
967
+ h('textarea', {
968
+ className: 'jps-textarea',
969
+ 'data-invalid': personaOver ? 'true' : undefined,
970
+ spellCheck: false,
971
+ value: personaDraft,
972
+ placeholder: '叫我老板;回答简短些,先给结论。',
973
+ onChange: (event) => setPersonaDraft(event.target.value),
974
+ }),
975
+ h(
976
+ 'div',
977
+ { className: 'jps-foot' },
978
+ h('span', { className: 'jps-count', 'data-over': personaOver ? 'true' : undefined }, `${personaBytes} / ${personaLimit} 字节`),
979
+ personaOver
980
+ ? h('span', { className: 'jps-note-inline' }, `超出 ${personaBytes - personaLimit} 字节`)
981
+ : personaNote === null
982
+ ? null
983
+ : h('span', { className: personaNote.kind === 'ok' ? 'jps-status' : 'jps-note-inline' }, personaNote.text),
984
+ h(
985
+ 'span',
986
+ { className: 'jps-foot-actions' },
987
+ h('button', { type: 'button', className: 'jps-btn', 'data-size': 'sm', onClick: () => void loadPersona() }, '重新载入'),
988
+ h(
989
+ 'button',
990
+ {
991
+ type: 'button',
992
+ className: 'jps-btn',
993
+ 'data-primary': 'true',
994
+ disabled: personaBusy || personaOver || !personaDirty,
995
+ onClick: () => void savePersona(),
996
+ },
997
+ personaBusy ? '处理中…' : '保存',
998
+ ),
999
+ ),
1000
+ ),
1001
+ ),
1002
+ ),
1003
+ ),
1004
+ )
1005
+
1006
+ return h('div', { 'data-wf-settings': 'true' }, alertLine, factsCard, personaCard)
1007
+ }
1008
+
1009
+ report({ phase: 'factory' })
1010
+
1011
+ return {
1012
+ inject: ['slots'],
1013
+ apply(ctx) {
1014
+ try {
1015
+ ctx.slots.inject('shell.overlay', () =>
1016
+ ctx.slots.register({ name: 'shell.overlay', id: 'work-fish-board', order: 40 }, BoardSurface),
1017
+ )
1018
+ report({ phase: 'applied', slot: 'shell.overlay' })
1019
+ } catch (error) {
1020
+ report({ phase: 'apply-failed', slot: 'shell.overlay', detail: String(error?.message ?? error) })
1021
+ }
1022
+ try {
1023
+ ctx.slots.inject('conversation.session.header.utilities', () =>
1024
+ ctx.slots.register({ name: 'conversation.session.header.utilities', id: 'wf-seat', order: 100 }, SessionSeat),
1025
+ )
1026
+ report({ phase: 'applied', slot: 'conversation.session.header.utilities' })
1027
+ } catch (error) {
1028
+ report({ phase: 'apply-failed', slot: 'conversation.session.header.utilities', detail: String(error?.message ?? error) })
1029
+ }
1030
+ try {
1031
+ ctx.slots.inject('settings.section', () =>
1032
+ ctx.slots.register({ name: 'settings.section', id: 'work-fish', order: 30, label: () => '大肥鱼' }, WorkFishSettings),
1033
+ )
1034
+ report({ phase: 'applied', slot: 'settings.section' })
1035
+ } catch (error) {
1036
+ report({ phase: 'apply-failed', slot: 'settings.section', detail: String(error?.message ?? error) })
1037
+ }
1038
+ },
1039
+ }
1040
+ },
1041
+ })