@codewizard-dt/bootstrap 2.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/.github/workflows/build.yml +88 -0
  2. package/.github/workflows/security.yml +24 -0
  3. package/.gitleaks.toml +15 -0
  4. package/README.md +472 -0
  5. package/bin/cli.js +47 -0
  6. package/lib/README.md +27 -0
  7. package/lib/hooks/README.md +316 -0
  8. package/lib/hooks/env-file-guard.js +45 -0
  9. package/lib/hooks/git-protected-ops-block.js +77 -0
  10. package/lib/hooks/lib/serena-languages.js +158 -0
  11. package/lib/hooks/lib/serena.js +787 -0
  12. package/lib/hooks/mv-absolute-path-block.js +53 -0
  13. package/lib/hooks/serena-bash-grep-block.js +501 -0
  14. package/lib/hooks/serena-edit-guard.js +74 -0
  15. package/lib/hooks/serena-first-glob-guard.js +94 -0
  16. package/lib/hooks/serena-first-guard.js +74 -0
  17. package/lib/hooks/serena-first-read-guard.js +167 -0
  18. package/lib/hooks/serena-pre-delegation.js +117 -0
  19. package/lib/hooks/serena-session-reset.js +45 -0
  20. package/lib/hooks/serena-usage-tracker.js +186 -0
  21. package/lib/hooks/serena-write-guard.js +58 -0
  22. package/lib/prompts/README.md +16 -0
  23. package/lib/prompts/migrate-wiki.md +111 -0
  24. package/lib/prompts/setup-deployment.md +322 -0
  25. package/lib/prompts/setup-design-system.md +162 -0
  26. package/lib/prompts/setup-strict-typechecks.md +139 -0
  27. package/lib/scripts/README.md +49 -0
  28. package/lib/scripts/bootstrap-serena.sh +145 -0
  29. package/lib/scripts/build-mcp-guide.sh +108 -0
  30. package/lib/scripts/install-global.sh +78 -0
  31. package/lib/scripts/install-mcps.sh +131 -0
  32. package/lib/scripts/lib.sh +154 -0
  33. package/lib/scripts/merge-gitignore.sh +65 -0
  34. package/lib/scripts/migrate-project.sh +273 -0
  35. package/lib/scripts/setup-deployment.sh +104 -0
  36. package/lib/scripts/setup-project.sh +55 -0
  37. package/lib/scripts/setup-runner.sh +99 -0
  38. package/lib/scripts/setup-strict-typechecks.sh +29 -0
  39. package/lib/scripts/startup.sh +42 -0
  40. package/lib/scripts/sync-wiki-scaffold.sh +104 -0
  41. package/lib/scripts/templates/CLAUDE-env-safety.md +3 -0
  42. package/lib/scripts/templates/CLAUDE-wiki.md +60 -0
  43. package/lib/scripts/templates/gitignore +136 -0
  44. package/lib/scripts/templates/guides/stubs/00-header.md +15 -0
  45. package/lib/scripts/templates/guides/stubs/brave-search.md +20 -0
  46. package/lib/scripts/templates/guides/stubs/context7.md +26 -0
  47. package/lib/scripts/templates/guides/stubs/playwright.md +26 -0
  48. package/lib/scripts/templates/guides/stubs/serena.md +219 -0
  49. package/lib/scripts/templates/wiki/conventions.md +100 -0
  50. package/lib/scripts/templates/wiki/dashboard.html +1733 -0
  51. package/lib/scripts/templates/wiki/hot.md +21 -0
  52. package/lib/scripts/templates/wiki/index.md +46 -0
  53. package/lib/scripts/templates/wiki/knowledge/concepts/.gitkeep +0 -0
  54. package/lib/scripts/templates/wiki/knowledge/entities/components/.gitkeep +0 -0
  55. package/lib/scripts/templates/wiki/knowledge/entities/organisations/.gitkeep +0 -0
  56. package/lib/scripts/templates/wiki/knowledge/entities/people/.gitkeep +0 -0
  57. package/lib/scripts/templates/wiki/knowledge/entities/tools/.gitkeep +0 -0
  58. package/lib/scripts/templates/wiki/knowledge/sources/.gitkeep +0 -0
  59. package/lib/scripts/templates/wiki/log.md +14 -0
  60. package/lib/scripts/templates/wiki/work/bugs/.gitkeep +0 -0
  61. package/lib/scripts/templates/wiki/work/bugs/archive/index.md +6 -0
  62. package/lib/scripts/templates/wiki/work/bugs/index.md +12 -0
  63. package/lib/scripts/templates/wiki/work/bugs/lifecycle.md +39 -0
  64. package/lib/scripts/templates/wiki/work/decisions/.gitkeep +0 -0
  65. package/lib/scripts/templates/wiki/work/decisions/archive/index.md +6 -0
  66. package/lib/scripts/templates/wiki/work/decisions/index.md +12 -0
  67. package/lib/scripts/templates/wiki/work/decisions/lifecycle.md +42 -0
  68. package/lib/scripts/templates/wiki/work/requirements/.gitkeep +0 -0
  69. package/lib/scripts/templates/wiki/work/requirements/archive/index.md +6 -0
  70. package/lib/scripts/templates/wiki/work/requirements/index.md +12 -0
  71. package/lib/scripts/templates/wiki/work/requirements/lifecycle.md +34 -0
  72. package/lib/scripts/templates/wiki/work/roadmaps/.gitkeep +0 -0
  73. package/lib/scripts/templates/wiki/work/roadmaps/archive/index.md +6 -0
  74. package/lib/scripts/templates/wiki/work/roadmaps/index.md +12 -0
  75. package/lib/scripts/templates/wiki/work/roadmaps/lifecycle.md +32 -0
  76. package/lib/scripts/templates/wiki/work/tasks/.gitkeep +0 -0
  77. package/lib/scripts/templates/wiki/work/tasks/archive/index.md +6 -0
  78. package/lib/scripts/templates/wiki/work/tasks/index.md +12 -0
  79. package/lib/scripts/templates/wiki/work/tasks/lifecycle.md +39 -0
  80. package/lib/scripts/templates/wiki/work/uat/.gitkeep +0 -0
  81. package/lib/scripts/templates/wiki/work/uat/archive/index.md +6 -0
  82. package/lib/scripts/templates/wiki/work/uat/index.md +12 -0
  83. package/lib/scripts/templates/wiki/work/uat/lifecycle.md +48 -0
  84. package/lib/scripts/templates/wiki/work/uat/screenshots/.gitkeep +0 -0
  85. package/lib/scripts/update-project.sh +75 -0
  86. package/lib/scripts/wiki-dashboard-server.js +146 -0
  87. package/lib/skills/README.md +146 -0
  88. package/lib/skills/anti-slop/SKILL.md +183 -0
  89. package/lib/skills/bug-close/SKILL.md +136 -0
  90. package/lib/skills/bug-file/SKILL.md +114 -0
  91. package/lib/skills/bug-triage/SKILL.md +140 -0
  92. package/lib/skills/company-align/SKILL.md +203 -0
  93. package/lib/skills/debug-logs/SKILL.md +129 -0
  94. package/lib/skills/decision-create/SKILL.md +220 -0
  95. package/lib/skills/decision-finalize/SKILL.md +181 -0
  96. package/lib/skills/decision-next/SKILL.md +129 -0
  97. package/lib/skills/decision-walkthrough/SKILL.md +169 -0
  98. package/lib/skills/demo/SKILL.md +183 -0
  99. package/lib/skills/elevator-pitch/SKILL.md +125 -0
  100. package/lib/skills/eval-create/SKILL.md +344 -0
  101. package/lib/skills/eval-gap/SKILL.md +150 -0
  102. package/lib/skills/eval-run/SKILL.md +214 -0
  103. package/lib/skills/extract-feature/SKILL.md +344 -0
  104. package/lib/skills/flashcard/SKILL.md +513 -0
  105. package/lib/skills/frontend-taste/SKILL.md +184 -0
  106. package/lib/skills/gap-assess/SKILL.md +97 -0
  107. package/lib/skills/git-commit/SKILL.md +164 -0
  108. package/lib/skills/lint/SKILL.md +99 -0
  109. package/lib/skills/marp-slideshow/SKILL.md +212 -0
  110. package/lib/skills/mermaid-flowchart/SKILL.md +194 -0
  111. package/lib/skills/now/SKILL.md +36 -0
  112. package/lib/skills/port-feature/SKILL.md +315 -0
  113. package/lib/skills/power-mode/SKILL.md +184 -0
  114. package/lib/skills/primer/SKILL.md +84 -0
  115. package/lib/skills/project-readme/SKILL.md +166 -0
  116. package/lib/skills/req-compile/SKILL.md +131 -0
  117. package/lib/skills/req-create/SKILL.md +124 -0
  118. package/lib/skills/req-extract-decisions/SKILL.md +241 -0
  119. package/lib/skills/req-finalize/SKILL.md +251 -0
  120. package/lib/skills/req-retire/SKILL.md +185 -0
  121. package/lib/skills/req-update/SKILL.md +265 -0
  122. package/lib/skills/research/SKILL.md +250 -0
  123. package/lib/skills/research-company/SKILL.md +345 -0
  124. package/lib/skills/roadmap-add/SKILL.md +238 -0
  125. package/lib/skills/roadmap-create/SKILL.md +223 -0
  126. package/lib/skills/roadmap-next/SKILL.md +132 -0
  127. package/lib/skills/security-audit/SKILL.md +246 -0
  128. package/lib/skills/serena-config/SKILL.md +92 -0
  129. package/lib/skills/simplify/SKILL.md +227 -0
  130. package/lib/skills/tackle/SKILL.md +156 -0
  131. package/lib/skills/task-add/SKILL.md +208 -0
  132. package/lib/skills/task-audit/SKILL.md +294 -0
  133. package/lib/skills/task-trash/SKILL.md +115 -0
  134. package/lib/skills/task-update/SKILL.md +136 -0
  135. package/lib/skills/uat-auto/SKILL.md +69 -0
  136. package/lib/skills/uat-auto-plus/SKILL.md +115 -0
  137. package/lib/skills/uat-generate/SKILL.md +289 -0
  138. package/lib/skills/uat-skip/SKILL.md +169 -0
  139. package/lib/skills/uat-walk/SKILL.md +164 -0
  140. package/lib/skills/uat-walk/UAT-CORE.md +140 -0
  141. package/lib/skills/update-docs/SKILL.md +75 -0
  142. package/lib/skills/wiki-archive/SKILL.md +96 -0
  143. package/lib/skills/wiki-ingest/SKILL.md +139 -0
  144. package/lib/skills/wiki-lint/SKILL.md +131 -0
  145. package/lib/skills/wiki-query/SKILL.md +71 -0
  146. package/lib/skills/wiki-rotate-log/SKILL.md +90 -0
  147. package/lib/skills/wiki-tidy/SKILL.md +107 -0
  148. package/package.json +32 -0
  149. package/raw/.gitkeep +0 -0
  150. package/raw/design-principles.md +65 -0
  151. package/raw/guides/command-anti-patterns.md +79 -0
  152. package/raw/guides/deployment-strategy.md +448 -0
  153. package/raw/guides/evals-framework.md +452 -0
  154. package/raw/guides/mcp-tools.md +335 -0
  155. package/raw/guides/task-spec.md +79 -0
  156. package/raw/guides/type-checking-templates/README.md +112 -0
  157. package/raw/guides/type-checking-templates/eslint/eslint.config.ts +105 -0
  158. package/raw/guides/type-checking-templates/python/mypy.ini +69 -0
  159. package/raw/guides/type-checking-templates/python/pyproject.toml +164 -0
  160. package/raw/guides/type-checking-templates/python/pyrightconfig.json +67 -0
  161. package/raw/guides/type-checking-templates/tsconfig/tsconfig.app.jsonc +45 -0
  162. package/raw/guides/type-checking-templates/tsconfig/tsconfig.lib.jsonc +44 -0
  163. package/raw/guides/type-checking-templates/tsconfig/tsconfig.node-esm.jsonc +40 -0
  164. package/raw/guides/type-checking-templates/tsconfig/tsconfig.node.jsonc +34 -0
  165. package/raw/guides/type-checking-templates/tsconfig/tsconfig.vite-root.json +8 -0
  166. package/raw/harness-notes.md +20 -0
  167. package/raw/house-style/components/Badge.tsx +16 -0
  168. package/raw/house-style/components/Button.tsx +32 -0
  169. package/raw/house-style/components/Card.tsx +26 -0
  170. package/raw/house-style/components/Chip.tsx +57 -0
  171. package/raw/house-style/components/IconButton.tsx +67 -0
  172. package/raw/house-style/components/Modal.tsx +18 -0
  173. package/raw/house-style/components/Stepper.tsx +141 -0
  174. package/raw/house-style/components/icons.tsx +128 -0
  175. package/raw/house-style/preview/src/index.css +46 -0
  176. package/raw/house-style/tokens/tailwind.preset.ts +49 -0
  177. package/raw/house-style/tokens/tokens.json +62 -0
  178. package/raw/llm-wiki-2.md +162 -0
  179. package/raw/llm-wiki.md +75 -0
  180. package/raw/research/dark-mode-theme/index.md +85 -0
  181. package/raw/research/dark-mode-theme/sources.md +49 -0
  182. package/raw/research/serena-mcp-disconnect/index.md +81 -0
  183. package/raw/research/serena-mcp-disconnect/sources.md +87 -0
  184. package/raw/research/wiki-tooling-improvements/index.md +126 -0
  185. package/raw/research/wiki-tooling-improvements/sources.md +73 -0
  186. package/raw/software-factory-case-study.pdf +0 -0
@@ -0,0 +1,1733 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="color-scheme" content="light dark">
7
+ <title>Wiki Dashboard</title>
8
+ <link rel="icon" href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20100%20100'%3E%3Ctext%20y='0.9em'%20font-size='90'%3E%F0%9F%93%8B%3C/text%3E%3C/svg%3E">
9
+ <style>
10
+ /* ---- Design tokens (light theme defaults) ---- */
11
+ :root {
12
+ --bg: #f6f7f9;
13
+ --panel-bg: #ffffff;
14
+ --panel-border: #e2e5ea;
15
+ --panel-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
16
+ --header-bg: #ffffff;
17
+ --header-border: #e2e5ea;
18
+ --text: #1a1f29;
19
+ --text-muted: #667085;
20
+ --text-faint: #98a2b3;
21
+ --accent: #2f6feb;
22
+ --accent-contrast: #ffffff;
23
+ --count-bg: #eef2f8;
24
+ --count-text: #344256;
25
+ --archive-bg: #fafbfc;
26
+ --archive-border: #eceef1;
27
+ --btn-bg: #ffffff;
28
+ --btn-border: #d0d5dd;
29
+ --btn-hover-bg: #f2f4f7;
30
+ --divider: #eceef1;
31
+ --badge-neutral-bg: #eef2f8;
32
+ --badge-neutral-text: #475467;
33
+ --badge-accent-bg: #e7efff;
34
+ --badge-accent-text: #2258c9;
35
+ --badge-good-bg: #e4f5ea;
36
+ --badge-good-text: #197a43;
37
+ --badge-bad-bg: #fdebea;
38
+ --badge-bad-text: #b42318;
39
+ --badge-muted-bg: #f2f4f7;
40
+ --badge-muted-text: #98a2b3;
41
+ --code-bg: #f2f4f7;
42
+ --mono: ui-monospace, "SF Mono", "SFMono-Regular", "Menlo", "Consolas", monospace;
43
+ --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
44
+ }
45
+
46
+ /* ---- Dark theme (passive OS fallback) ---- */
47
+ @media (prefers-color-scheme: dark) {
48
+ :root {
49
+ --bg: #0e1117;
50
+ --panel-bg: #161b22;
51
+ --panel-border: #262c36;
52
+ --panel-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
53
+ --header-bg: #161b22;
54
+ --header-border: #262c36;
55
+ --text: #e6edf3;
56
+ --text-muted: #9aa7b4;
57
+ --text-faint: #6e7a89;
58
+ --accent: #4f8bff;
59
+ --accent-contrast: #0e1117;
60
+ --count-bg: #21262d;
61
+ --count-text: #c2cdd8;
62
+ --archive-bg: #12161d;
63
+ --archive-border: #21262d;
64
+ --btn-bg: #21262d;
65
+ --btn-border: #30363d;
66
+ --btn-hover-bg: #2a313a;
67
+ --divider: #21262d;
68
+ --badge-neutral-bg: #21262d;
69
+ --badge-neutral-text: #aeb9c5;
70
+ --badge-accent-bg: #17263f;
71
+ --badge-accent-text: #6ea1ff;
72
+ --badge-good-bg: #12291c;
73
+ --badge-good-text: #4cc078;
74
+ --badge-bad-bg: #34181a;
75
+ --badge-bad-text: #f0857c;
76
+ --badge-muted-bg: #1b2027;
77
+ --badge-muted-text: #6e7a89;
78
+ --code-bg: #1b2027;
79
+ }
80
+ }
81
+
82
+ /* ---- Explicit theme overrides (localStorage choice wins over OS) ---- */
83
+ :root[data-theme="light"] {
84
+ --bg: #f6f7f9;
85
+ --panel-bg: #ffffff;
86
+ --panel-border: #e2e5ea;
87
+ --panel-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
88
+ --header-bg: #ffffff;
89
+ --header-border: #e2e5ea;
90
+ --text: #1a1f29;
91
+ --text-muted: #667085;
92
+ --text-faint: #98a2b3;
93
+ --accent: #2f6feb;
94
+ --accent-contrast: #ffffff;
95
+ --count-bg: #eef2f8;
96
+ --count-text: #344256;
97
+ --archive-bg: #fafbfc;
98
+ --archive-border: #eceef1;
99
+ --btn-bg: #ffffff;
100
+ --btn-border: #d0d5dd;
101
+ --btn-hover-bg: #f2f4f7;
102
+ --divider: #eceef1;
103
+ --badge-neutral-bg: #eef2f8;
104
+ --badge-neutral-text: #475467;
105
+ --badge-accent-bg: #e7efff;
106
+ --badge-accent-text: #2258c9;
107
+ --badge-good-bg: #e4f5ea;
108
+ --badge-good-text: #197a43;
109
+ --badge-bad-bg: #fdebea;
110
+ --badge-bad-text: #b42318;
111
+ --badge-muted-bg: #f2f4f7;
112
+ --badge-muted-text: #98a2b3;
113
+ --code-bg: #f2f4f7;
114
+ color-scheme: light;
115
+ }
116
+
117
+ :root[data-theme="dark"] {
118
+ --bg: #0e1117;
119
+ --panel-bg: #161b22;
120
+ --panel-border: #262c36;
121
+ --panel-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
122
+ --header-bg: #161b22;
123
+ --header-border: #262c36;
124
+ --text: #e6edf3;
125
+ --text-muted: #9aa7b4;
126
+ --text-faint: #6e7a89;
127
+ --accent: #4f8bff;
128
+ --accent-contrast: #0e1117;
129
+ --count-bg: #21262d;
130
+ --count-text: #c2cdd8;
131
+ --archive-bg: #12161d;
132
+ --archive-border: #21262d;
133
+ --btn-bg: #21262d;
134
+ --btn-border: #30363d;
135
+ --btn-hover-bg: #2a313a;
136
+ --divider: #21262d;
137
+ --badge-neutral-bg: #21262d;
138
+ --badge-neutral-text: #aeb9c5;
139
+ --badge-accent-bg: #17263f;
140
+ --badge-accent-text: #6ea1ff;
141
+ --badge-good-bg: #12291c;
142
+ --badge-good-text: #4cc078;
143
+ --badge-bad-bg: #34181a;
144
+ --badge-bad-text: #f0857c;
145
+ --badge-muted-bg: #1b2027;
146
+ --badge-muted-text: #6e7a89;
147
+ --code-bg: #1b2027;
148
+ color-scheme: dark;
149
+ }
150
+
151
+ * { box-sizing: border-box; }
152
+
153
+ html, body {
154
+ margin: 0;
155
+ padding: 0;
156
+ }
157
+
158
+ body {
159
+ background: var(--bg);
160
+ color: var(--text);
161
+ font-family: var(--sans);
162
+ font-size: 14px;
163
+ line-height: 1.5;
164
+ -webkit-font-smoothing: antialiased;
165
+ }
166
+
167
+ @media (prefers-reduced-motion: no-preference) {
168
+ body,
169
+ .panel,
170
+ .family-card,
171
+ .app-header,
172
+ .refresh-btn,
173
+ .theme-btn {
174
+ transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
175
+ }
176
+ }
177
+
178
+ a { color: var(--accent); }
179
+
180
+ /* ---- Header ---- */
181
+ .app-header {
182
+ position: sticky;
183
+ top: 0;
184
+ z-index: 10;
185
+ display: flex;
186
+ align-items: center;
187
+ justify-content: space-between;
188
+ gap: 16px;
189
+ flex-wrap: wrap;
190
+ padding: 14px 24px;
191
+ background: var(--header-bg);
192
+ border-bottom: 1px solid var(--header-border);
193
+ }
194
+
195
+ .crumbs {
196
+ display: flex;
197
+ align-items: baseline;
198
+ gap: 8px;
199
+ flex-wrap: wrap;
200
+ font-size: 15px;
201
+ font-weight: 600;
202
+ letter-spacing: 0.01em;
203
+ min-width: 0;
204
+ }
205
+
206
+ .crumbs a {
207
+ color: var(--text);
208
+ text-decoration: none;
209
+ }
210
+
211
+ .crumbs a:hover { color: var(--accent); }
212
+
213
+ .crumbs .crumb-sep {
214
+ color: var(--text-faint);
215
+ font-weight: 400;
216
+ }
217
+
218
+ .crumbs .crumb-current {
219
+ color: var(--text-muted);
220
+ font-weight: 500;
221
+ }
222
+
223
+ .header-meta {
224
+ display: flex;
225
+ align-items: center;
226
+ gap: 14px;
227
+ flex-wrap: wrap;
228
+ }
229
+
230
+ .last-updated {
231
+ font-family: var(--mono);
232
+ font-size: 12px;
233
+ color: var(--text-muted);
234
+ white-space: nowrap;
235
+ }
236
+
237
+ .last-updated strong {
238
+ color: var(--text);
239
+ font-weight: 600;
240
+ }
241
+
242
+ .refresh-btn,
243
+ .theme-btn {
244
+ appearance: none;
245
+ cursor: pointer;
246
+ font: inherit;
247
+ font-size: 13px;
248
+ display: inline-flex;
249
+ align-items: center;
250
+ gap: 6px;
251
+ padding: 6px 14px;
252
+ border-radius: 7px;
253
+ border: 1px solid var(--btn-border);
254
+ background: var(--btn-bg);
255
+ color: var(--text);
256
+ }
257
+
258
+ .theme-btn { padding: 6px 10px; }
259
+
260
+ .refresh-btn:hover,
261
+ .theme-btn:hover { background: var(--btn-hover-bg); }
262
+ .refresh-btn:active,
263
+ .theme-btn:active { transform: translateY(0.5px); }
264
+ .refresh-btn[data-loading="true"] { opacity: 0.6; pointer-events: none; }
265
+ .refresh-btn:focus-visible,
266
+ .theme-btn:focus-visible {
267
+ outline: 2px solid var(--accent);
268
+ outline-offset: 2px;
269
+ }
270
+
271
+ /* ---- View container ---- */
272
+ .view {
273
+ max-width: 1400px;
274
+ margin: 0 auto;
275
+ padding: 24px;
276
+ }
277
+
278
+ /* ---- Global empty / error banner ---- */
279
+ .banner {
280
+ max-width: 1400px;
281
+ margin: 0 auto;
282
+ padding: 0 24px;
283
+ }
284
+
285
+ .banner-msg {
286
+ margin: 8px 0 0;
287
+ padding: 10px 14px;
288
+ border-radius: 8px;
289
+ font-size: 13px;
290
+ background: var(--count-bg);
291
+ color: var(--text-muted);
292
+ border: 1px solid var(--panel-border);
293
+ }
294
+
295
+ .banner-msg[hidden] { display: none; }
296
+
297
+ /* ---- Overview: summary cards ---- */
298
+ .card-grid {
299
+ display: grid;
300
+ grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
301
+ gap: 18px;
302
+ }
303
+
304
+ .family-card {
305
+ display: flex;
306
+ flex-direction: column;
307
+ gap: 10px;
308
+ padding: 16px;
309
+ background: var(--panel-bg);
310
+ border: 1px solid var(--panel-border);
311
+ border-radius: 10px;
312
+ box-shadow: var(--panel-shadow);
313
+ color: inherit;
314
+ text-decoration: none;
315
+ }
316
+
317
+ .family-card:hover {
318
+ border-color: var(--accent);
319
+ }
320
+
321
+ .family-card:focus-visible {
322
+ outline: 2px solid var(--accent);
323
+ outline-offset: 2px;
324
+ }
325
+
326
+ .family-card .card-top {
327
+ display: flex;
328
+ align-items: center;
329
+ justify-content: space-between;
330
+ gap: 10px;
331
+ }
332
+
333
+ .family-card h2 {
334
+ margin: 0;
335
+ font-size: 13px;
336
+ font-weight: 600;
337
+ letter-spacing: 0.02em;
338
+ }
339
+
340
+ .card-breakdown {
341
+ display: flex;
342
+ flex-wrap: wrap;
343
+ gap: 6px;
344
+ min-height: 22px;
345
+ align-items: center;
346
+ }
347
+
348
+ .card-breakdown .empty-note { margin: 0; }
349
+
350
+ .card-archived {
351
+ font-size: 12px;
352
+ color: var(--text-faint);
353
+ border-top: 1px solid var(--divider);
354
+ padding-top: 8px;
355
+ margin-top: auto;
356
+ }
357
+
358
+ .panel-count {
359
+ font-family: var(--mono);
360
+ font-size: 12px;
361
+ font-weight: 600;
362
+ color: var(--count-text);
363
+ background: var(--count-bg);
364
+ padding: 2px 9px;
365
+ border-radius: 999px;
366
+ min-width: 24px;
367
+ text-align: center;
368
+ }
369
+
370
+ /* ---- Status badges ---- */
371
+ .badge {
372
+ display: inline-block;
373
+ font-family: var(--mono);
374
+ font-size: 10.5px;
375
+ font-weight: 600;
376
+ padding: 1px 8px;
377
+ border-radius: 999px;
378
+ white-space: nowrap;
379
+ }
380
+
381
+ .badge-neutral { background: var(--badge-neutral-bg); color: var(--badge-neutral-text); }
382
+ .badge-accent { background: var(--badge-accent-bg); color: var(--badge-accent-text); }
383
+ .badge-good { background: var(--badge-good-bg); color: var(--badge-good-text); }
384
+ .badge-bad { background: var(--badge-bad-bg); color: var(--badge-bad-text); }
385
+ .badge-muted { background: var(--badge-muted-bg); color: var(--badge-muted-text); }
386
+
387
+ /* ---- Family page panel ---- */
388
+ .panel {
389
+ display: flex;
390
+ flex-direction: column;
391
+ background: var(--panel-bg);
392
+ border: 1px solid var(--panel-border);
393
+ border-radius: 10px;
394
+ box-shadow: var(--panel-shadow);
395
+ }
396
+
397
+ .panel-header {
398
+ display: flex;
399
+ align-items: center;
400
+ justify-content: space-between;
401
+ gap: 10px;
402
+ padding: 14px 16px;
403
+ border-bottom: 1px solid var(--divider);
404
+ }
405
+
406
+ .panel-title {
407
+ margin: 0;
408
+ font-size: 13px;
409
+ font-weight: 600;
410
+ letter-spacing: 0.02em;
411
+ }
412
+
413
+ .panel-body {
414
+ display: flex;
415
+ flex-direction: column;
416
+ flex: 1;
417
+ padding: 12px 16px 16px;
418
+ gap: 12px;
419
+ }
420
+
421
+ .panel-active {
422
+ display: flex;
423
+ flex-direction: column;
424
+ gap: 12px;
425
+ min-height: 24px;
426
+ }
427
+
428
+ .empty-note {
429
+ color: var(--text-faint);
430
+ font-size: 12px;
431
+ font-style: italic;
432
+ }
433
+
434
+ /* ---- Item rows (two-line layout) ---- */
435
+ .wiki-item {
436
+ display: flex;
437
+ flex-direction: column;
438
+ gap: 3px;
439
+ min-width: 0;
440
+ }
441
+
442
+ .wiki-item .item-line1 {
443
+ display: flex;
444
+ align-items: baseline;
445
+ gap: 8px;
446
+ min-width: 0;
447
+ }
448
+
449
+ .wiki-item .item-id {
450
+ font-family: var(--mono);
451
+ font-size: 11px;
452
+ color: var(--text-faint);
453
+ flex-shrink: 0;
454
+ }
455
+
456
+ .wiki-item .item-label {
457
+ font-size: 13px;
458
+ min-width: 0;
459
+ overflow-wrap: anywhere;
460
+ }
461
+
462
+ .wiki-item a.item-label { text-decoration: none; }
463
+ .wiki-item a.item-label:hover { text-decoration: underline; }
464
+
465
+ .wiki-item .item-line2 {
466
+ display: flex;
467
+ align-items: baseline;
468
+ justify-content: space-between;
469
+ gap: 12px;
470
+ font-size: 12px;
471
+ color: var(--text-muted);
472
+ }
473
+
474
+ .wiki-item .item-summary {
475
+ min-width: 0;
476
+ overflow-wrap: anywhere;
477
+ }
478
+
479
+ .wiki-item .item-status-extra {
480
+ font-family: var(--mono);
481
+ font-size: 11px;
482
+ color: var(--text-muted);
483
+ flex-shrink: 0;
484
+ }
485
+
486
+ .wiki-item .item-meta {
487
+ display: flex;
488
+ align-items: baseline;
489
+ gap: 8px;
490
+ flex-shrink: 0;
491
+ margin-left: auto;
492
+ }
493
+
494
+ /* ---- Archived items ---- */
495
+ .panel-archive {
496
+ border-top: 1px solid var(--divider);
497
+ padding-top: 10px;
498
+ margin-top: auto;
499
+ }
500
+
501
+ .panel-archive > summary {
502
+ cursor: pointer;
503
+ list-style: none;
504
+ font-size: 12px;
505
+ color: var(--text-muted);
506
+ user-select: none;
507
+ display: flex;
508
+ align-items: center;
509
+ gap: 6px;
510
+ }
511
+
512
+ .panel-archive > summary::-webkit-details-marker { display: none; }
513
+
514
+ .panel-archive > summary::before {
515
+ content: "▸";
516
+ font-size: 10px;
517
+ color: var(--text-faint);
518
+ transition: transform 0.12s ease;
519
+ }
520
+
521
+ .panel-archive[open] > summary::before {
522
+ transform: rotate(90deg);
523
+ }
524
+
525
+ .panel-archive .archive-count {
526
+ font-family: var(--mono);
527
+ color: var(--text-faint);
528
+ }
529
+
530
+ .panel-archive-list {
531
+ background: var(--archive-bg);
532
+ border: 1px solid var(--archive-border);
533
+ border-radius: 7px;
534
+ margin-top: 8px;
535
+ padding: 10px 12px;
536
+ display: flex;
537
+ flex-direction: column;
538
+ gap: 8px;
539
+ font-size: 12px;
540
+ color: var(--text-muted);
541
+ }
542
+
543
+ .archive-item {
544
+ display: flex;
545
+ align-items: baseline;
546
+ gap: 8px;
547
+ flex-wrap: wrap;
548
+ }
549
+
550
+ .archive-item .item-id {
551
+ font-family: var(--mono);
552
+ font-size: 11px;
553
+ color: var(--text-faint);
554
+ flex-shrink: 0;
555
+ }
556
+
557
+ .archive-item .item-label {
558
+ min-width: 0;
559
+ overflow-wrap: anywhere;
560
+ }
561
+
562
+ .archive-item .item-date {
563
+ font-family: var(--mono);
564
+ font-size: 10.5px;
565
+ color: var(--text-faint);
566
+ margin-left: auto;
567
+ flex-shrink: 0;
568
+ }
569
+
570
+ /* ---- Item page ---- */
571
+ .back-link {
572
+ display: inline-flex;
573
+ align-items: center;
574
+ gap: 6px;
575
+ font-size: 13px;
576
+ text-decoration: none;
577
+ margin-bottom: 14px;
578
+ }
579
+
580
+ .back-link:hover { text-decoration: underline; }
581
+
582
+ .item-page {
583
+ background: var(--panel-bg);
584
+ border: 1px solid var(--panel-border);
585
+ border-radius: 10px;
586
+ box-shadow: var(--panel-shadow);
587
+ padding: 24px 28px 28px;
588
+ }
589
+
590
+ .fm-grid {
591
+ display: grid;
592
+ grid-template-columns: max-content 1fr;
593
+ gap: 4px 18px;
594
+ font-size: 12.5px;
595
+ padding: 12px 14px;
596
+ margin-bottom: 20px;
597
+ background: var(--archive-bg);
598
+ border: 1px solid var(--archive-border);
599
+ border-radius: 8px;
600
+ }
601
+
602
+ .fm-grid .fm-key {
603
+ font-family: var(--mono);
604
+ font-size: 11.5px;
605
+ color: var(--text-faint);
606
+ }
607
+
608
+ .fm-grid .fm-value {
609
+ color: var(--text-muted);
610
+ overflow-wrap: anywhere;
611
+ }
612
+
613
+ /* ---- Rendered markdown ---- */
614
+ .md { font-size: 14px; }
615
+ .md > :first-child { margin-top: 0; }
616
+
617
+ .md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
618
+ line-height: 1.3;
619
+ margin: 1.6em 0 0.5em;
620
+ }
621
+
622
+ .md h1 { font-size: 20px; }
623
+ .md h2 { font-size: 16px; border-bottom: 1px solid var(--divider); padding-bottom: 6px; }
624
+ .md h3 { font-size: 14.5px; }
625
+ .md h4, .md h5, .md h6 { font-size: 13.5px; }
626
+
627
+ .md p { margin: 0.7em 0; }
628
+
629
+ .md ul, .md ol {
630
+ margin: 0.6em 0;
631
+ padding-left: 24px;
632
+ }
633
+
634
+ .md li { margin: 3px 0; }
635
+
636
+ .md li.task-li {
637
+ list-style: none;
638
+ margin-left: -20px;
639
+ }
640
+
641
+ .md li.task-li input {
642
+ margin-right: 7px;
643
+ vertical-align: -1.5px;
644
+ }
645
+
646
+ .md code {
647
+ font-family: var(--mono);
648
+ font-size: 12px;
649
+ background: var(--code-bg);
650
+ padding: 1.5px 5px;
651
+ border-radius: 4px;
652
+ }
653
+
654
+ .md pre {
655
+ background: var(--code-bg);
656
+ border: 1px solid var(--divider);
657
+ border-radius: 8px;
658
+ padding: 12px 14px;
659
+ overflow-x: auto;
660
+ margin: 0.8em 0;
661
+ }
662
+
663
+ .md pre code {
664
+ background: none;
665
+ padding: 0;
666
+ font-size: 12px;
667
+ line-height: 1.55;
668
+ }
669
+
670
+ .md blockquote {
671
+ margin: 0.8em 0;
672
+ padding: 6px 14px;
673
+ border-left: 3px solid var(--panel-border);
674
+ color: var(--text-muted);
675
+ }
676
+
677
+ .md hr {
678
+ border: none;
679
+ border-top: 1px solid var(--divider);
680
+ margin: 1.4em 0;
681
+ }
682
+
683
+ .md table {
684
+ border-collapse: collapse;
685
+ margin: 0.8em 0;
686
+ font-size: 13px;
687
+ display: block;
688
+ overflow-x: auto;
689
+ max-width: 100%;
690
+ }
691
+
692
+ .md th, .md td {
693
+ border: 1px solid var(--panel-border);
694
+ padding: 5px 10px;
695
+ text-align: left;
696
+ }
697
+
698
+ .md th {
699
+ background: var(--count-bg);
700
+ font-weight: 600;
701
+ }
702
+
703
+ .not-found {
704
+ color: var(--text-muted);
705
+ font-style: italic;
706
+ }
707
+
708
+ @media (max-width: 480px) {
709
+ .view { padding: 16px; }
710
+ .banner { padding: 0 16px; }
711
+ .app-header { padding: 12px 16px; }
712
+ .item-page { padding: 18px 16px 20px; }
713
+ }
714
+ </style>
715
+ </head>
716
+ <body>
717
+ <script>
718
+ // Applied before first paint: explicit localStorage choice > OS preference.
719
+ (function () {
720
+ try {
721
+ var saved = localStorage.getItem('dashboard-theme');
722
+ if (saved === 'light' || saved === 'dark') {
723
+ document.documentElement.setAttribute('data-theme', saved);
724
+ }
725
+ } catch (e) { /* storage blocked -> OS media query governs */ }
726
+ })();
727
+ </script>
728
+
729
+ <header class="app-header">
730
+ <nav class="crumbs" id="crumbs" aria-label="Breadcrumb">
731
+ <a href="#/">Wiki Dashboard</a>
732
+ </nav>
733
+ <div class="header-meta">
734
+ <span class="last-updated" id="last-updated">Last updated: <strong>never</strong></span>
735
+ <button type="button" class="refresh-btn" id="refresh-btn" title="Reload wiki data">
736
+ <span aria-hidden="true">↻</span> Refresh
737
+ </button>
738
+ <button type="button" class="theme-btn" id="theme-btn" aria-label="Switch color theme" title="Switch color theme">
739
+ <span aria-hidden="true" id="theme-btn-icon">◐</span>
740
+ </button>
741
+ </div>
742
+ </header>
743
+
744
+ <div class="banner">
745
+ <p class="banner-msg" id="status-banner" hidden></p>
746
+ </div>
747
+
748
+ <main class="view" id="view"></main>
749
+
750
+ <script>
751
+ // ============================================================
752
+ // Wiki Dashboard — client logic
753
+ //
754
+ // Hash-routed single page:
755
+ // #/ -> overview (one summary card per family)
756
+ // #/<family> -> family page (active list + archived)
757
+ // #/<family>/<file>.md -> item page (rendered markdown)
758
+ //
759
+ // All fetched text is rendered via textContent / DOM builders,
760
+ // never innerHTML, so wiki markdown can never inject markup.
761
+ // ============================================================
762
+
763
+ 'use strict';
764
+
765
+ // The six families, in display order. Matches the wiki/work/ schema.
766
+ const FAMILIES = ['requirements', 'decisions', 'roadmaps', 'tasks', 'uat', 'bugs'];
767
+
768
+ const FAMILY_LABELS = {
769
+ requirements: 'Requirements',
770
+ decisions: 'Decisions',
771
+ roadmaps: 'Roadmaps',
772
+ tasks: 'Tasks',
773
+ uat: 'UAT',
774
+ bugs: 'Bugs',
775
+ };
776
+
777
+ // How often (ms) the poll loop re-fetches the family indexes.
778
+ const POLL_INTERVAL_MS = 5000;
779
+
780
+ // Known lifecycle status keywords (across all six lifecycle.md specs)
781
+ // and the badge tone each maps to.
782
+ const STATUS_TONES = {
783
+ 'todo': 'neutral',
784
+ 'open': 'neutral',
785
+ 'draft': 'neutral',
786
+ 'proposed': 'neutral',
787
+ 'pending': 'neutral',
788
+ 'in-progress': 'accent',
789
+ 'triaged': 'accent',
790
+ 'active': 'accent',
791
+ 'done': 'good',
792
+ 'passed': 'good',
793
+ 'accepted': 'good',
794
+ 'approved': 'good',
795
+ 'closed': 'good',
796
+ 'failed': 'bad',
797
+ 'trashed': 'muted',
798
+ 'skipped': 'muted',
799
+ 'retired': 'muted',
800
+ 'superseded': 'muted',
801
+ 'wontfix': 'muted',
802
+ 'duplicate': 'muted',
803
+ 'cannot-reproduce': 'muted',
804
+ };
805
+
806
+ const STATUS_KEYWORDS = Object.keys(STATUS_TONES);
807
+
808
+ // --- Extract the first known status keyword from a status string ---
809
+ // "in-progress · P2" -> "in-progress"; "11/12 items checked" -> null.
810
+ // Requires word boundaries so e.g. "abandoned" never matches "done".
811
+ function statusKeyword(statusText) {
812
+ if (!statusText) return null;
813
+ const lower = statusText.toLowerCase();
814
+ let best = null;
815
+ for (const kw of STATUS_KEYWORDS) {
816
+ const idx = lower.indexOf(kw);
817
+ if (idx === -1) continue;
818
+ const before = idx === 0 ? '' : lower[idx - 1];
819
+ const after = lower[idx + kw.length] || '';
820
+ if (/[a-z0-9-]/.test(before) || /[a-z0-9-]/.test(after)) continue;
821
+ if (best === null || idx < best.idx) best = { kw: kw, idx: idx };
822
+ }
823
+ return best ? best.kw : null;
824
+ }
825
+
826
+ // --- Build a status badge node for a keyword (tone-mapped pill) ---
827
+ function buildBadge(keyword) {
828
+ const el = document.createElement('span');
829
+ el.className = 'badge badge-' + (STATUS_TONES[keyword] || 'neutral');
830
+ el.textContent = keyword;
831
+ return el;
832
+ }
833
+
834
+ // --- Split a markdown table row into cells ---
835
+ // Splits on unescaped pipes only and unescapes \| -> | inside cells, so
836
+ // rows like "| [[TASK-009]] | ... extracted\|inferred ... |" stay intact.
837
+ // Returns the cell array, or null if the line is not a table row.
838
+ function parseTableCells(line) {
839
+ const t = line.trim();
840
+ if (t.length < 2 || t[0] !== '|' || t[t.length - 1] !== '|') return null;
841
+ const inner = t.slice(1, -1);
842
+ return inner
843
+ .split(/(?<!\\)\|/)
844
+ .map(function (c) { return c.replace(/\\\|/g, '|').trim(); });
845
+ }
846
+
847
+ // --- Parse a family index.md into an array of item objects ---
848
+ // Each item: { title, path, summary, status, archivedDate }
849
+ //
850
+ // Two supported source formats:
851
+ //
852
+ // 1. Active-index bullet lines (all sub-parts optional):
853
+ // - [TASK-NNN — Title](TASK-NNN-slug.md) — summary · status
854
+ // Separators matched literally: em dash — (U+2014) between title and
855
+ // summary; middle dot · (U+00B7) before status suffix(es).
856
+ //
857
+ // 2. Archive-index table rows:
858
+ // | [[TASK-NNN]] | Title | Final Status | Archived |
859
+ // A data row is identified by its first cell being a [[...]] wiki-link
860
+ // (the header and |----| separator rows fail that gate). Escaped
861
+ // pipes (\|) inside cells are handled. Archive rows have no markdown
862
+ // link, so path is null (slugs cannot be reliably derived from IDs).
863
+ //
864
+ // Non-bullet prose and the `_(none yet)_` placeholder yield no items.
865
+ function parseIndexMarkdown(text) {
866
+ if (!text) return [];
867
+ const items = [];
868
+ // Bullet + [text](target); optional " — rest-of-line" tail.
869
+ const lineRe = /^\s*[-*]\s+\[([^\]]+)\]\(([^)]+)\)(?:\s+—\s+(.*))?\s*$/;
870
+ const lines = text.split(/\r?\n/);
871
+ for (const line of lines) {
872
+ const m = line.match(lineRe);
873
+ if (m) {
874
+ const title = m[1].trim();
875
+ const path = m[2].trim();
876
+ let summary = null;
877
+ let status = null;
878
+ if (m[3] != null) {
879
+ // The tail is "summary · statusA · statusB". Split on the first
880
+ // middle-dot separator; everything before is the summary, the
881
+ // remaining dot-separated segments join back as the status string.
882
+ const parts = m[3].split(/\s+·\s+/);
883
+ summary = parts.shift().trim() || null;
884
+ if (parts.length) status = parts.join(' · ').trim() || null;
885
+ }
886
+ items.push({ title: title, path: path, summary: summary, status: status, archivedDate: null });
887
+ continue;
888
+ }
889
+
890
+ // Archive table row branch (additive; bullet regex takes precedence).
891
+ const cells = parseTableCells(line);
892
+ if (cells && cells.length >= 3) {
893
+ const idMatch = cells[0].match(/^\[\[([^\]]+)\]\]$/);
894
+ if (idMatch) {
895
+ items.push({
896
+ title: idMatch[1] + ' — ' + cells[1],
897
+ path: null,
898
+ summary: null,
899
+ status: cells[2] || null,
900
+ archivedDate: cells[3] || null,
901
+ });
902
+ }
903
+ }
904
+ }
905
+ return items;
906
+ }
907
+
908
+ // --- Fetch one file, returning parsed items ([] on any failure/404) ---
909
+ async function fetchIndexFile(url) {
910
+ try {
911
+ const resp = await fetch(url, { cache: 'no-store' });
912
+ if (!resp.ok) return []; // 404 (no archive/empty family) etc. -> zero items
913
+ const text = await resp.text();
914
+ return parseIndexMarkdown(text);
915
+ } catch (_err) {
916
+ return [];
917
+ }
918
+ }
919
+
920
+ // --- Fetch one family's active + archived items ---
921
+ async function fetchFamily(familyName) {
922
+ const [active, archived] = await Promise.all([
923
+ fetchIndexFile('/wiki/work/' + familyName + '/index.md'),
924
+ fetchIndexFile('/wiki/work/' + familyName + '/archive/index.md'),
925
+ ]);
926
+ return { active: active, archived: archived };
927
+ }
928
+
929
+ // --- Fetch + parse the wiki data for all six families ---
930
+ // Never rejects — per-family failures degrade to empty lists.
931
+ async function fetchWikiData() {
932
+ const results = await Promise.all(
933
+ FAMILIES.map(function (family) {
934
+ return fetchFamily(family).then(
935
+ function (data) { return data; },
936
+ function () { return { active: [], archived: [] }; }
937
+ );
938
+ })
939
+ );
940
+ const data = {};
941
+ FAMILIES.forEach(function (family, i) {
942
+ data[family] = results[i];
943
+ });
944
+ return data;
945
+ }
946
+
947
+ // --- Split a title into { id, label } on the em-dash separator ---
948
+ function splitTitle(title) {
949
+ const idx = title.indexOf(' — ');
950
+ if (idx === -1) return { id: null, label: title };
951
+ return {
952
+ id: title.slice(0, idx).trim(),
953
+ label: title.slice(idx + 3).trim(),
954
+ };
955
+ }
956
+
957
+ // ============================================================
958
+ // Routing
959
+ // ============================================================
960
+
961
+ // location.hash -> { view, family?, file? }. Unknown routes fall back
962
+ // to the overview; a bad file segment falls back to the family page.
963
+ function parseRoute() {
964
+ const hash = location.hash.replace(/^#\/?/, '');
965
+ if (!hash) return { view: 'overview' };
966
+ const parts = hash.split('/').map(function (p) {
967
+ try { return decodeURIComponent(p); } catch (e) { return p; }
968
+ });
969
+ const family = parts[0];
970
+ if (FAMILIES.indexOf(family) === -1) return { view: 'overview' };
971
+ if (parts.length === 1) return { view: 'family', family: family };
972
+ const file = parts.slice(1).join('/');
973
+ const fileOk =
974
+ /^(archive\/)?[A-Za-z0-9][A-Za-z0-9 ._-]*\.md$/.test(file) &&
975
+ file.indexOf('..') === -1;
976
+ if (fileOk) return { view: 'item', family: family, file: file };
977
+ return { view: 'family', family: family };
978
+ }
979
+
980
+ function itemHash(family, path) {
981
+ return '#/' + family + '/' + path;
982
+ }
983
+
984
+ // ============================================================
985
+ // View: overview (summary cards)
986
+ // ============================================================
987
+
988
+ function buildFamilyCard(family, bucket) {
989
+ const active = bucket.active || [];
990
+ const archived = bucket.archived || [];
991
+
992
+ const card = document.createElement('a');
993
+ card.className = 'family-card';
994
+ card.href = '#/' + family;
995
+
996
+ const top = document.createElement('div');
997
+ top.className = 'card-top';
998
+ const h2 = document.createElement('h2');
999
+ h2.textContent = FAMILY_LABELS[family] || family;
1000
+ const count = document.createElement('span');
1001
+ count.className = 'panel-count';
1002
+ count.textContent = String(active.length);
1003
+ top.appendChild(h2);
1004
+ top.appendChild(count);
1005
+ card.appendChild(top);
1006
+
1007
+ // Per-status breakdown of active items.
1008
+ const breakdown = document.createElement('div');
1009
+ breakdown.className = 'card-breakdown';
1010
+ if (active.length === 0) {
1011
+ const note = document.createElement('span');
1012
+ note.className = 'empty-note';
1013
+ note.textContent = 'No active items.';
1014
+ breakdown.appendChild(note);
1015
+ } else {
1016
+ const counts = {};
1017
+ active.forEach(function (item) {
1018
+ const kw = statusKeyword(item.status) || 'active';
1019
+ counts[kw] = (counts[kw] || 0) + 1;
1020
+ });
1021
+ Object.keys(counts).forEach(function (kw) {
1022
+ const badge = buildBadge(kw);
1023
+ badge.textContent = counts[kw] + ' ' + kw;
1024
+ breakdown.appendChild(badge);
1025
+ });
1026
+ }
1027
+ card.appendChild(breakdown);
1028
+
1029
+ const arch = document.createElement('div');
1030
+ arch.className = 'card-archived';
1031
+ arch.textContent = archived.length + ' archived';
1032
+ card.appendChild(arch);
1033
+
1034
+ return card;
1035
+ }
1036
+
1037
+ function renderOverview(container, data) {
1038
+ container.textContent = '';
1039
+ const grid = document.createElement('div');
1040
+ grid.className = 'card-grid';
1041
+ FAMILIES.forEach(function (family) {
1042
+ const bucket = (data && data[family]) || { active: [], archived: [] };
1043
+ grid.appendChild(buildFamilyCard(family, bucket));
1044
+ });
1045
+ container.appendChild(grid);
1046
+ }
1047
+
1048
+ // ============================================================
1049
+ // View: family page
1050
+ // ============================================================
1051
+
1052
+ // Active row: two-line layout —
1053
+ // line 1: [ID chip] linked title
1054
+ // line 2: summary (muted) ......... [status badge + extra status text]
1055
+ function buildItemRow(item, family) {
1056
+ const row = document.createElement('div');
1057
+ row.className = 'wiki-item';
1058
+
1059
+ const parsed = splitTitle(item.title || '');
1060
+
1061
+ const line1 = document.createElement('div');
1062
+ line1.className = 'item-line1';
1063
+ if (parsed.id) {
1064
+ const idEl = document.createElement('span');
1065
+ idEl.className = 'item-id';
1066
+ idEl.textContent = parsed.id;
1067
+ line1.appendChild(idEl);
1068
+ }
1069
+ const labelEl = document.createElement(item.path ? 'a' : 'span');
1070
+ labelEl.className = 'item-label';
1071
+ labelEl.textContent = parsed.label || '(untitled)';
1072
+ if (item.path) {
1073
+ labelEl.href = itemHash(family, item.path);
1074
+ labelEl.title = item.path;
1075
+ }
1076
+ line1.appendChild(labelEl);
1077
+ row.appendChild(line1);
1078
+
1079
+ const kw = statusKeyword(item.status);
1080
+ if (item.summary || item.status) {
1081
+ const line2 = document.createElement('div');
1082
+ line2.className = 'item-line2';
1083
+
1084
+ const sumEl = document.createElement('span');
1085
+ sumEl.className = 'item-summary';
1086
+ sumEl.textContent = item.summary || '';
1087
+ line2.appendChild(sumEl);
1088
+
1089
+ const meta = document.createElement('span');
1090
+ meta.className = 'item-meta';
1091
+ if (item.status) {
1092
+ // Segments that exactly match a known keyword render as a badge;
1093
+ // everything else stays as plain mono text.
1094
+ const segments = item.status.split(' · ');
1095
+ const extras = [];
1096
+ let badged = false;
1097
+ segments.forEach(function (seg) {
1098
+ if (!badged && kw && seg.trim().toLowerCase() === kw) {
1099
+ meta.appendChild(buildBadge(kw));
1100
+ badged = true;
1101
+ } else {
1102
+ extras.push(seg.trim());
1103
+ }
1104
+ });
1105
+ if (extras.length) {
1106
+ const extraEl = document.createElement('span');
1107
+ extraEl.className = 'item-status-extra';
1108
+ extraEl.textContent = extras.join(' · ');
1109
+ meta.appendChild(extraEl);
1110
+ }
1111
+ }
1112
+ line2.appendChild(meta);
1113
+ row.appendChild(line2);
1114
+ }
1115
+
1116
+ return row;
1117
+ }
1118
+
1119
+ // Archived row: ID chip + title + final-status badge + archived date.
1120
+ // Unlinked: archive tables carry [[ID]] wiki-links, not paths, and
1121
+ // deriving a filename from an ID is unreliable (slugs vary).
1122
+ function buildArchiveRow(item) {
1123
+ const row = document.createElement('div');
1124
+ row.className = 'archive-item';
1125
+
1126
+ const parsed = splitTitle(item.title || '');
1127
+
1128
+ if (parsed.id) {
1129
+ const idEl = document.createElement('span');
1130
+ idEl.className = 'item-id';
1131
+ idEl.textContent = parsed.id;
1132
+ row.appendChild(idEl);
1133
+ }
1134
+
1135
+ const labelEl = document.createElement('span');
1136
+ labelEl.className = 'item-label';
1137
+ labelEl.textContent = parsed.label || '(untitled)';
1138
+ row.appendChild(labelEl);
1139
+
1140
+ const kw = statusKeyword(item.status);
1141
+ if (kw) row.appendChild(buildBadge(kw));
1142
+
1143
+ if (item.archivedDate) {
1144
+ const dateEl = document.createElement('span');
1145
+ dateEl.className = 'item-date';
1146
+ dateEl.textContent = item.archivedDate;
1147
+ row.appendChild(dateEl);
1148
+ }
1149
+
1150
+ return row;
1151
+ }
1152
+
1153
+ function emptyNote(text) {
1154
+ const note = document.createElement('span');
1155
+ note.className = 'empty-note';
1156
+ note.textContent = text;
1157
+ return note;
1158
+ }
1159
+
1160
+ function renderFamilyPage(container, family, data) {
1161
+ const bucket = (data && data[family]) || { active: [], archived: [] };
1162
+ const active = bucket.active || [];
1163
+ const archived = bucket.archived || [];
1164
+
1165
+ // Preserve the archive <details> open state across poll re-renders.
1166
+ const prevArchive = container.querySelector('.panel-archive');
1167
+ const archiveWasOpen = prevArchive ? prevArchive.open : false;
1168
+
1169
+ container.textContent = '';
1170
+
1171
+ const back = document.createElement('a');
1172
+ back.className = 'back-link';
1173
+ back.href = '#/';
1174
+ back.textContent = '← Overview';
1175
+ container.appendChild(back);
1176
+
1177
+ const panel = document.createElement('section');
1178
+ panel.className = 'panel';
1179
+
1180
+ const header = document.createElement('div');
1181
+ header.className = 'panel-header';
1182
+ const title = document.createElement('h2');
1183
+ title.className = 'panel-title';
1184
+ title.textContent = FAMILY_LABELS[family] || family;
1185
+ const count = document.createElement('span');
1186
+ count.className = 'panel-count';
1187
+ count.textContent = String(active.length);
1188
+ header.appendChild(title);
1189
+ header.appendChild(count);
1190
+ panel.appendChild(header);
1191
+
1192
+ const body = document.createElement('div');
1193
+ body.className = 'panel-body';
1194
+
1195
+ const activeArea = document.createElement('div');
1196
+ activeArea.className = 'panel-active';
1197
+ if (active.length === 0) {
1198
+ activeArea.appendChild(emptyNote('No active items.'));
1199
+ } else {
1200
+ active.forEach(function (item) {
1201
+ activeArea.appendChild(buildItemRow(item, family));
1202
+ });
1203
+ }
1204
+ body.appendChild(activeArea);
1205
+
1206
+ const details = document.createElement('details');
1207
+ details.className = 'panel-archive';
1208
+ details.open = archiveWasOpen;
1209
+ const summary = document.createElement('summary');
1210
+ summary.appendChild(document.createTextNode('Archived '));
1211
+ const archCount = document.createElement('span');
1212
+ archCount.className = 'archive-count';
1213
+ archCount.textContent = String(archived.length);
1214
+ summary.appendChild(archCount);
1215
+ details.appendChild(summary);
1216
+
1217
+ const list = document.createElement('div');
1218
+ list.className = 'panel-archive-list';
1219
+ if (archived.length === 0) {
1220
+ list.appendChild(emptyNote('Nothing archived.'));
1221
+ } else {
1222
+ archived.forEach(function (item) {
1223
+ list.appendChild(buildArchiveRow(item));
1224
+ });
1225
+ }
1226
+ details.appendChild(list);
1227
+ body.appendChild(details);
1228
+
1229
+ panel.appendChild(body);
1230
+ container.appendChild(panel);
1231
+ }
1232
+
1233
+ // ============================================================
1234
+ // View: item page (rendered markdown)
1235
+ // ============================================================
1236
+
1237
+ // Split "---\n...\n---\n" frontmatter off the top of a markdown file.
1238
+ function splitFrontmatter(text) {
1239
+ const m = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
1240
+ if (!m) return { frontmatter: null, body: text };
1241
+ return { frontmatter: m[1], body: text.slice(m[0].length) };
1242
+ }
1243
+
1244
+ // Top-level "key: value" lines only; quotes stripped from values.
1245
+ function parseFrontmatter(text) {
1246
+ const pairs = [];
1247
+ text.split(/\r?\n/).forEach(function (line) {
1248
+ const m = line.match(/^([A-Za-z_][A-Za-z0-9_-]*):\s*(.*)$/);
1249
+ if (!m) return;
1250
+ let value = m[2].trim().replace(/^"(.*)"$/, '$1');
1251
+ pairs.push([m[1], value]);
1252
+ });
1253
+ return pairs;
1254
+ }
1255
+
1256
+ // Resolve a markdown link target to a dashboard href.
1257
+ // Relative .md links become hash routes; absolute URLs pass through.
1258
+ function resolveLink(url, family) {
1259
+ if (/^[a-z][a-z0-9+.-]*:/i.test(url)) return { href: url, external: true };
1260
+ if (url.charAt(0) === '#') return { href: url, external: false };
1261
+ let clean = url.replace(/^\.\//, '');
1262
+ const cross = clean.match(/^\.\.\/([a-z]+)\/((?:archive\/)?[^/]+\.md)$/);
1263
+ if (cross && FAMILIES.indexOf(cross[1]) !== -1) {
1264
+ return { href: itemHash(cross[1], cross[2]), external: false };
1265
+ }
1266
+ if (/^(archive\/)?[^/]+\.md$/.test(clean)) {
1267
+ return { href: itemHash(family, clean), external: false };
1268
+ }
1269
+ // Anything else (images, deep relative paths): serve from the wiki tree.
1270
+ return { href: '/wiki/work/' + family + '/' + clean, external: false };
1271
+ }
1272
+
1273
+ // Append inline-formatted markdown (code, bold, italic, links) to a node.
1274
+ // Text is always attached via createTextNode/textContent — never markup.
1275
+ function renderInline(target, text, family) {
1276
+ const re = /(`[^`]+`)|\*\*([^*]+)\*\*|\*([^*]+)\*|\[([^\]]+)\]\(([^)\s]+)\)|(\[\[([^\]]+)\]\])/g;
1277
+ let last = 0;
1278
+ let m;
1279
+ while ((m = re.exec(text)) !== null) {
1280
+ if (m.index > last) {
1281
+ target.appendChild(document.createTextNode(text.slice(last, m.index)));
1282
+ }
1283
+ if (m[1]) {
1284
+ const code = document.createElement('code');
1285
+ code.textContent = m[1].slice(1, -1);
1286
+ target.appendChild(code);
1287
+ } else if (m[2] != null) {
1288
+ const strong = document.createElement('strong');
1289
+ strong.textContent = m[2];
1290
+ target.appendChild(strong);
1291
+ } else if (m[3] != null) {
1292
+ const em = document.createElement('em');
1293
+ em.textContent = m[3];
1294
+ target.appendChild(em);
1295
+ } else if (m[4] != null) {
1296
+ const resolved = resolveLink(m[5], family);
1297
+ const a = document.createElement('a');
1298
+ a.textContent = m[4];
1299
+ a.href = resolved.href;
1300
+ if (resolved.external) {
1301
+ a.target = '_blank';
1302
+ a.rel = 'noopener noreferrer';
1303
+ }
1304
+ target.appendChild(a);
1305
+ } else if (m[6]) {
1306
+ // [[wiki-link]] — no path to resolve; render as inline code.
1307
+ const wl = document.createElement('code');
1308
+ wl.textContent = m[7];
1309
+ target.appendChild(wl);
1310
+ }
1311
+ last = re.lastIndex;
1312
+ }
1313
+ if (last < text.length) {
1314
+ target.appendChild(document.createTextNode(text.slice(last)));
1315
+ }
1316
+ }
1317
+
1318
+ // Minimal escape-first block renderer: headings, lists (+ checkboxes),
1319
+ // fenced code, blockquotes, tables, hr, paragraphs.
1320
+ function renderMarkdown(md, family) {
1321
+ const root = document.createElement('article');
1322
+ root.className = 'md';
1323
+ const lines = md.split(/\r?\n/);
1324
+
1325
+ let para = [];
1326
+ let list = null; // { el, type, indentBase }
1327
+
1328
+ function flushPara() {
1329
+ if (!para.length) return;
1330
+ const p = document.createElement('p');
1331
+ renderInline(p, para.join(' '), family);
1332
+ root.appendChild(p);
1333
+ para = [];
1334
+ }
1335
+
1336
+ function flushList() {
1337
+ list = null;
1338
+ }
1339
+
1340
+ function ensureList(type) {
1341
+ if (list && list.type === type) return list.el;
1342
+ const el = document.createElement(type);
1343
+ root.appendChild(el);
1344
+ list = { el: el, type: type };
1345
+ return el;
1346
+ }
1347
+
1348
+ let i = 0;
1349
+ while (i < lines.length) {
1350
+ const line = lines[i];
1351
+
1352
+ // Fenced code block.
1353
+ const fence = line.match(/^\s*```/);
1354
+ if (fence) {
1355
+ flushPara(); flushList();
1356
+ const buf = [];
1357
+ i++;
1358
+ while (i < lines.length && !/^\s*```/.test(lines[i])) {
1359
+ buf.push(lines[i]);
1360
+ i++;
1361
+ }
1362
+ i++; // skip closing fence (or run off the end)
1363
+ const pre = document.createElement('pre');
1364
+ const code = document.createElement('code');
1365
+ code.textContent = buf.join('\n');
1366
+ pre.appendChild(code);
1367
+ root.appendChild(pre);
1368
+ continue;
1369
+ }
1370
+
1371
+ // Blank line.
1372
+ if (/^\s*$/.test(line)) {
1373
+ flushPara(); flushList();
1374
+ i++;
1375
+ continue;
1376
+ }
1377
+
1378
+ // Heading.
1379
+ const h = line.match(/^(#{1,6})\s+(.*)$/);
1380
+ if (h) {
1381
+ flushPara(); flushList();
1382
+ const el = document.createElement('h' + h[1].length);
1383
+ // Strip trailing inline-comment markers like "<!-- agent: x -->".
1384
+ renderInline(el, h[2].replace(/<!--.*?-->/g, '').trim(), family);
1385
+ root.appendChild(el);
1386
+ i++;
1387
+ continue;
1388
+ }
1389
+
1390
+ // Horizontal rule.
1391
+ if (/^\s*(-{3,}|\*{3,})\s*$/.test(line) && para.length === 0) {
1392
+ flushList();
1393
+ root.appendChild(document.createElement('hr'));
1394
+ i++;
1395
+ continue;
1396
+ }
1397
+
1398
+ // Blockquote (consecutive > lines collapse into one).
1399
+ if (/^\s*>/.test(line)) {
1400
+ flushPara(); flushList();
1401
+ const buf = [];
1402
+ while (i < lines.length && /^\s*>/.test(lines[i])) {
1403
+ buf.push(lines[i].replace(/^\s*>\s?/, ''));
1404
+ i++;
1405
+ }
1406
+ const bq = document.createElement('blockquote');
1407
+ const p = document.createElement('p');
1408
+ renderInline(p, buf.join(' '), family);
1409
+ bq.appendChild(p);
1410
+ root.appendChild(bq);
1411
+ continue;
1412
+ }
1413
+
1414
+ // Table: current line parses as cells and next line is a separator.
1415
+ const cells = parseTableCells(line);
1416
+ if (cells && i + 1 < lines.length) {
1417
+ const sepCells = parseTableCells(lines[i + 1]);
1418
+ const isSep = sepCells && sepCells.every(function (c) { return /^:?-{2,}:?$/.test(c); });
1419
+ if (isSep) {
1420
+ flushPara(); flushList();
1421
+ const table = document.createElement('table');
1422
+ const thead = document.createElement('thead');
1423
+ const headRow = document.createElement('tr');
1424
+ cells.forEach(function (c) {
1425
+ const th = document.createElement('th');
1426
+ renderInline(th, c, family);
1427
+ headRow.appendChild(th);
1428
+ });
1429
+ thead.appendChild(headRow);
1430
+ table.appendChild(thead);
1431
+ const tbody = document.createElement('tbody');
1432
+ i += 2;
1433
+ while (i < lines.length) {
1434
+ const rowCells = parseTableCells(lines[i]);
1435
+ if (!rowCells) break;
1436
+ const tr = document.createElement('tr');
1437
+ rowCells.forEach(function (c) {
1438
+ const td = document.createElement('td');
1439
+ renderInline(td, c, family);
1440
+ tr.appendChild(td);
1441
+ });
1442
+ tbody.appendChild(tr);
1443
+ i++;
1444
+ }
1445
+ table.appendChild(tbody);
1446
+ root.appendChild(table);
1447
+ continue;
1448
+ }
1449
+ }
1450
+
1451
+ // Bullet list item (with optional checkbox).
1452
+ const bullet = line.match(/^(\s*)[-*]\s+(.*)$/);
1453
+ if (bullet) {
1454
+ flushPara();
1455
+ const ul = ensureList('ul');
1456
+ const li = document.createElement('li');
1457
+ const indent = Math.min(Math.floor(bullet[1].length / 2), 4);
1458
+ if (indent > 0) li.style.marginLeft = (indent * 16) + 'px';
1459
+ const task = bullet[2].match(/^\[([ xX])\]\s+(.*)$/);
1460
+ if (task) {
1461
+ li.className = 'task-li';
1462
+ const cb = document.createElement('input');
1463
+ cb.type = 'checkbox';
1464
+ cb.disabled = true;
1465
+ cb.checked = task[1] !== ' ';
1466
+ li.appendChild(cb);
1467
+ renderInline(li, task[2], family);
1468
+ } else {
1469
+ renderInline(li, bullet[2], family);
1470
+ }
1471
+ ul.appendChild(li);
1472
+ i++;
1473
+ continue;
1474
+ }
1475
+
1476
+ // Ordered list item.
1477
+ const ordered = line.match(/^(\s*)\d+\.\s+(.*)$/);
1478
+ if (ordered) {
1479
+ flushPara();
1480
+ const ol = ensureList('ol');
1481
+ const li = document.createElement('li');
1482
+ const indent = Math.min(Math.floor(ordered[1].length / 2), 4);
1483
+ if (indent > 0) li.style.marginLeft = (indent * 16) + 'px';
1484
+ renderInline(li, ordered[2], family);
1485
+ ol.appendChild(li);
1486
+ i++;
1487
+ continue;
1488
+ }
1489
+
1490
+ // Plain paragraph text (consecutive lines join).
1491
+ flushList();
1492
+ para.push(line.trim());
1493
+ i++;
1494
+ }
1495
+
1496
+ flushPara();
1497
+ return root;
1498
+ }
1499
+
1500
+ async function renderItemPage(container, family, file) {
1501
+ container.textContent = '';
1502
+
1503
+ const back = document.createElement('a');
1504
+ back.className = 'back-link';
1505
+ back.href = '#/' + family;
1506
+ back.textContent = '← ' + (FAMILY_LABELS[family] || family);
1507
+ container.appendChild(back);
1508
+
1509
+ const page = document.createElement('div');
1510
+ page.className = 'item-page';
1511
+ container.appendChild(page);
1512
+
1513
+ let text = null;
1514
+ try {
1515
+ const resp = await fetch('/wiki/work/' + family + '/' + file, { cache: 'no-store' });
1516
+ if (resp.ok) text = await resp.text();
1517
+ } catch (_err) { /* fall through to not-found */ }
1518
+
1519
+ // A route change while fetching means this render is stale — bail.
1520
+ const route = parseRoute();
1521
+ if (!(route.view === 'item' && route.family === family && route.file === file)) return;
1522
+
1523
+ if (text === null) {
1524
+ const nf = document.createElement('p');
1525
+ nf.className = 'not-found';
1526
+ nf.textContent = 'Could not load ' + file + ' — it may have been moved or archived.';
1527
+ page.appendChild(nf);
1528
+ return;
1529
+ }
1530
+
1531
+ const split = splitFrontmatter(text);
1532
+
1533
+ if (split.frontmatter) {
1534
+ const pairs = parseFrontmatter(split.frontmatter);
1535
+ if (pairs.length) {
1536
+ const grid = document.createElement('div');
1537
+ grid.className = 'fm-grid';
1538
+ pairs.forEach(function (pair) {
1539
+ const key = document.createElement('span');
1540
+ key.className = 'fm-key';
1541
+ key.textContent = pair[0];
1542
+ grid.appendChild(key);
1543
+ const value = document.createElement('span');
1544
+ value.className = 'fm-value';
1545
+ const kw = pair[0] === 'status' ? statusKeyword(pair[1]) : null;
1546
+ if (kw) {
1547
+ value.appendChild(buildBadge(kw));
1548
+ } else {
1549
+ value.textContent = pair[1];
1550
+ }
1551
+ grid.appendChild(value);
1552
+ });
1553
+ page.appendChild(grid);
1554
+ }
1555
+ }
1556
+
1557
+ page.appendChild(renderMarkdown(split.body, family));
1558
+ }
1559
+
1560
+ // ============================================================
1561
+ // Shell: breadcrumbs, routing, polling, theme
1562
+ // ============================================================
1563
+
1564
+ let wikiData = null;
1565
+ let lastDataSerialized = null;
1566
+
1567
+ function updateCrumbs(route) {
1568
+ const nav = document.getElementById('crumbs');
1569
+ if (!nav) return;
1570
+ nav.textContent = '';
1571
+ const root = document.createElement('a');
1572
+ root.href = '#/';
1573
+ root.textContent = 'Wiki Dashboard';
1574
+ nav.appendChild(root);
1575
+ if (route.view === 'overview') return;
1576
+
1577
+ const sep1 = document.createElement('span');
1578
+ sep1.className = 'crumb-sep';
1579
+ sep1.textContent = '›';
1580
+ nav.appendChild(sep1);
1581
+
1582
+ if (route.view === 'family') {
1583
+ const cur = document.createElement('span');
1584
+ cur.className = 'crumb-current';
1585
+ cur.textContent = FAMILY_LABELS[route.family] || route.family;
1586
+ nav.appendChild(cur);
1587
+ return;
1588
+ }
1589
+
1590
+ const fam = document.createElement('a');
1591
+ fam.href = '#/' + route.family;
1592
+ fam.textContent = FAMILY_LABELS[route.family] || route.family;
1593
+ nav.appendChild(fam);
1594
+
1595
+ const sep2 = document.createElement('span');
1596
+ sep2.className = 'crumb-sep';
1597
+ sep2.textContent = '›';
1598
+ nav.appendChild(sep2);
1599
+
1600
+ const cur = document.createElement('span');
1601
+ cur.className = 'crumb-current';
1602
+ const idMatch = route.file.match(/^(?:archive\/)?([A-Z]+-\d+)/);
1603
+ cur.textContent = idMatch ? idMatch[1] : route.file;
1604
+ nav.appendChild(cur);
1605
+ }
1606
+
1607
+ function renderRoute() {
1608
+ const route = parseRoute();
1609
+ const container = document.getElementById('view');
1610
+ if (!container) return;
1611
+ updateCrumbs(route);
1612
+ if (route.view === 'family') {
1613
+ renderFamilyPage(container, route.family, wikiData);
1614
+ } else if (route.view === 'item') {
1615
+ renderItemPage(container, route.family, route.file);
1616
+ } else {
1617
+ renderOverview(container, wikiData);
1618
+ }
1619
+ }
1620
+
1621
+ function updateTimestamp(date) {
1622
+ const container = document.getElementById('last-updated');
1623
+ if (!container) return;
1624
+ const strong = container.querySelector('strong');
1625
+ if (strong) strong.textContent = date.toLocaleTimeString();
1626
+ }
1627
+
1628
+ function setBanner(message) {
1629
+ const banner = document.getElementById('status-banner');
1630
+ if (!banner) return;
1631
+ if (message) {
1632
+ banner.textContent = message;
1633
+ banner.hidden = false;
1634
+ } else {
1635
+ banner.textContent = '';
1636
+ banner.hidden = true;
1637
+ }
1638
+ }
1639
+
1640
+ // Overlap guard: true while a fetch cycle is in flight so a slow poll or
1641
+ // a rapid button mash can't stack overlapping fetch/render cycles.
1642
+ let refreshInFlight = false;
1643
+
1644
+ // One refresh cycle: fetch indexes, re-render the current view if the
1645
+ // data changed (or on force), stamp the timestamp. The item view is only
1646
+ // re-fetched on force (navigation handles its own first render).
1647
+ async function refresh(force) {
1648
+ if (refreshInFlight) return;
1649
+ refreshInFlight = true;
1650
+
1651
+ const btn = document.getElementById('refresh-btn');
1652
+ if (btn) btn.setAttribute('data-loading', 'true');
1653
+
1654
+ try {
1655
+ const data = await fetchWikiData();
1656
+ wikiData = data;
1657
+ const serialized = JSON.stringify(data);
1658
+ const changed = serialized !== lastDataSerialized;
1659
+ lastDataSerialized = serialized;
1660
+
1661
+ const route = parseRoute();
1662
+ if (route.view === 'item') {
1663
+ if (force) renderRoute();
1664
+ } else if (changed || force) {
1665
+ renderRoute();
1666
+ }
1667
+ updateTimestamp(new Date());
1668
+ setBanner(null);
1669
+ } catch (err) {
1670
+ setBanner('Could not load wiki data. Retrying…');
1671
+ } finally {
1672
+ refreshInFlight = false;
1673
+ if (btn) btn.removeAttribute('data-loading');
1674
+ }
1675
+ }
1676
+
1677
+ function startPolling() {
1678
+ setInterval(function () { refresh(false); }, POLL_INTERVAL_MS);
1679
+ }
1680
+
1681
+ // --- Theme toggle (explicit choice > OS preference) ---
1682
+ function resolvedTheme() {
1683
+ const attr = document.documentElement.getAttribute('data-theme');
1684
+ if (attr === 'light' || attr === 'dark') return attr;
1685
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
1686
+ }
1687
+
1688
+ function updateThemeButton() {
1689
+ const icon = document.getElementById('theme-btn-icon');
1690
+ if (icon) icon.textContent = resolvedTheme() === 'dark' ? '☀' : '☾';
1691
+ }
1692
+
1693
+ function initTheme() {
1694
+ const btn = document.getElementById('theme-btn');
1695
+ if (btn) {
1696
+ btn.addEventListener('click', function () {
1697
+ const next = resolvedTheme() === 'dark' ? 'light' : 'dark';
1698
+ document.documentElement.setAttribute('data-theme', next);
1699
+ try { localStorage.setItem('dashboard-theme', next); } catch (e) {}
1700
+ updateThemeButton();
1701
+ });
1702
+ }
1703
+ // Live OS flips apply only while no explicit choice is set.
1704
+ const mq = window.matchMedia('(prefers-color-scheme: dark)');
1705
+ const onChange = function () {
1706
+ if (!document.documentElement.getAttribute('data-theme')) updateThemeButton();
1707
+ };
1708
+ if (mq.addEventListener) mq.addEventListener('change', onChange);
1709
+ else if (mq.addListener) mq.addListener(onChange);
1710
+ updateThemeButton();
1711
+ }
1712
+
1713
+ // --- Boot ---
1714
+ function init() {
1715
+ const btn = document.getElementById('refresh-btn');
1716
+ if (btn) {
1717
+ btn.addEventListener('click', function () { refresh(true); });
1718
+ }
1719
+ window.addEventListener('hashchange', renderRoute);
1720
+ initTheme();
1721
+ renderRoute(); // paint the shell immediately (empty data)
1722
+ refresh(true); // then fill with first data
1723
+ startPolling();
1724
+ }
1725
+
1726
+ if (document.readyState === 'loading') {
1727
+ document.addEventListener('DOMContentLoaded', init);
1728
+ } else {
1729
+ init();
1730
+ }
1731
+ </script>
1732
+ </body>
1733
+ </html>