claude-everything-workflow 0.1.4 → 0.1.6

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 (35) hide show
  1. package/README.md +50 -19
  2. package/hooks/check-code-size.js +111 -0
  3. package/package.json +1 -1
  4. package/rules/02-code-size.md +11 -2
  5. package/rules/common/hooks.md +2 -1
  6. package/rules/common/skills-learning.md +7 -0
  7. package/scripts/install.ps1 +80 -43
  8. package/scripts/install.sh +56 -3
  9. package/scripts/verify-harness.js +156 -26
  10. package/settings.json +8 -40
  11. package/skills/brainstorming/scripts/frame-template.html +25 -26
  12. package/skills/brainstorming/scripts/helper.js +101 -22
  13. package/skills/brainstorming/scripts/server.cjs +399 -30
  14. package/skills/brainstorming/scripts/start-server.sh +70 -9
  15. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  16. package/skills/brainstorming/visual-companion.md +33 -22
  17. package/skills/learn/.gitkeep +0 -0
  18. package/skills/learn/README.md +15 -0
  19. package/skills/learn/debugging/.gitkeep +0 -0
  20. package/skills/learn/pr/.gitkeep +0 -0
  21. package/skills/learn/testing/.gitkeep +0 -0
  22. package/skills/subagent-driven-development/SKILL.md +425 -0
  23. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  24. package/skills/subagent-driven-development/scripts/review-package +44 -0
  25. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  26. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  27. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  28. package/skills/using-superpowers/SKILL.md +75 -0
  29. package/skills/writing-plans/SKILL.md +25 -2
  30. package/commands/acceptance.md +0 -73
  31. package/hooks/evaluate-session.js +0 -59
  32. package/hooks/pre-compact.js +0 -92
  33. package/hooks/runtime/session-utils.js +0 -45
  34. package/hooks/session-end.js +0 -62
  35. package/hooks/session-start.js +0 -60
@@ -50,6 +50,8 @@ function managedFiles() {
50
50
  "skills/continuous-learning-v2",
51
51
  "skills/test-driven-development",
52
52
  "skills/e2e-testing",
53
+ "skills/using-superpowers",
54
+ "skills/subagent-driven-development",
53
55
  "skills/brainstorming",
54
56
  "skills/using-git-worktrees",
55
57
  "skills/executing-plans",
@@ -232,10 +234,30 @@ function checkHookConfigReferences() {
232
234
 
233
235
  collect(settings.hooks);
234
236
 
237
+ const LEGACY_HOOK_PATTERNS = [
238
+ "scripts/hooks/run-with-flags.js",
239
+ "scripts/hooks/commit-quality.js",
240
+ "scripts/hooks/session-start.js",
241
+ "scripts/hooks/session-end.js",
242
+ "scripts/lib/hook-flags.js",
243
+ "hooks/observe.js",
244
+ "hooks/review-confidence.js",
245
+ "hooks/session-start.js",
246
+ "hooks/session-end.js",
247
+ "hooks/evaluate-session.js",
248
+ "hooks/pre-compact.js",
249
+ "hooks/runtime/session-utils.js",
250
+ ];
251
+
235
252
  for (const command of commands) {
236
253
  if (command.includes("$HOME/.codex")) {
237
254
  fail("settings.json should not point hooks at ~/.codex");
238
255
  }
256
+ for (const legacy of LEGACY_HOOK_PATTERNS) {
257
+ if (command.includes(legacy)) {
258
+ fail(`settings.json contains legacy hook path: ${legacy}`);
259
+ }
260
+ }
239
261
  const matches = [...command.matchAll(/\$HOME\/\.claude\/([^" ]+)/g)];
240
262
  for (const match of matches) {
241
263
  const referenced = match[1];
@@ -244,6 +266,43 @@ function checkHookConfigReferences() {
244
266
  }
245
267
  }
246
268
  }
269
+
270
+ // 验证安装脚本包含旧版 Hook 清理逻辑
271
+ for (const installer of ["scripts/install.sh", "scripts/install.ps1"]) {
272
+ if (!exists(installer)) continue;
273
+ const body = read(installer);
274
+ if (!body.includes("LEGACY_HOOK_PATTERNS") && !body.includes("isLegacyHook")) {
275
+ fail(`${installer} should include legacy hook path cleanup logic`);
276
+ }
277
+ }
278
+ }
279
+
280
+ function checkGitHubWorkflows() {
281
+ requireTokens(".github/workflows/ci.yml", [
282
+ "pull_request",
283
+ "npm run verify",
284
+ "npm run pack:dry-run",
285
+ ]);
286
+
287
+ requireTokens(".github/workflows/npm-publish.yml", [
288
+ "workflow_dispatch",
289
+ "id-token: write",
290
+ "node-version: 22.14.0",
291
+ "package-manager-cache: false",
292
+ "npm install -g npm@11.5.1",
293
+ "npm view \"$PACKAGE_NAME\" version --registry=https://registry.npmjs.org",
294
+ "BASE_VERSION=\"${REGISTRY_VERSION:-$LOCAL_VERSION}\"",
295
+ "npm version \"$VERSION\" --no-git-tag-version",
296
+ "npm publish",
297
+ "git push --follow-tags origin HEAD:main",
298
+ "[skip npm]",
299
+ ]);
300
+
301
+ requireTokens("README.md", [
302
+ "npm 自动发布",
303
+ "受信任的发布商",
304
+ "npm registry 的当前 `latest` 版本",
305
+ ]);
247
306
  }
248
307
 
249
308
  function checkLearningPathPolicy() {
@@ -291,7 +350,6 @@ function checkLearningPathPolicy() {
291
350
 
292
351
  function checkRouterTargets() {
293
352
  const expected = [
294
- ["commands/acceptance.md", ["commands/verify.md"]],
295
353
  ["commands/code-review.md", ["agents/code-reviewer.md"]],
296
354
  [
297
355
  "commands/tdd.md",
@@ -329,25 +387,6 @@ function checkRouterTargets() {
329
387
  }
330
388
  }
331
389
 
332
- function checkAcceptanceGate() {
333
- requireTokens("README.md", [
334
- "`/acceptance`",
335
- "/verify` -> `/acceptance` -> `/pr`",
336
- "没有 acceptance,不把复杂任务声明为验收通过",
337
- ]);
338
-
339
- requireTokens("commands/acceptance.md", [
340
- "验收结果: [通过/部分通过/失败/依据不足]",
341
- "需求覆盖:",
342
- "验收标准:",
343
- "测试证据:",
344
- "未验收项:",
345
- "范围外改动:",
346
- "剩余风险:",
347
- "不要把“测试通过”等同于“验收通过”",
348
- ]);
349
- }
350
-
351
390
  function checkNpmPackageSurface() {
352
391
  requireTokens("package.json", [
353
392
  '"name": "claude-everything-workflow"',
@@ -379,6 +418,43 @@ function checkNpmPackageSurface() {
379
418
  }
380
419
 
381
420
  function checkSkillLinks() {
421
+ requireTokens("skills/using-superpowers/SKILL.md", [
422
+ "Skill Invocation Rule",
423
+ "Task arrives",
424
+ "approved plan + SDD/commit approved?",
425
+ "external skill learning or edit?",
426
+ "process skills before implementation skills",
427
+ "skills/brainstorming/SKILL.md",
428
+ "skills/systematic-debugging/SKILL.md",
429
+ "skills/verification-before-completion/SKILL.md",
430
+ "User instructions",
431
+ ]);
432
+
433
+ requireTokens("skills/subagent-driven-development/SKILL.md", [
434
+ ".superpowers/sdd/progress.md",
435
+ "scripts/task-brief",
436
+ "scripts/review-package BASE HEAD",
437
+ "task-reviewer-prompt.md",
438
+ "Local Git Boundary",
439
+ "skills/executing-plans/SKILL.md",
440
+ ]);
441
+
442
+ requireTokens("skills/subagent-driven-development/task-reviewer-prompt.md", [
443
+ "Spec Compliance",
444
+ "Task quality",
445
+ "Cannot verify from diff",
446
+ "[BRIEF_FILE]",
447
+ "[DIFF_FILE]",
448
+ ]);
449
+
450
+ for (const script of [
451
+ "skills/subagent-driven-development/scripts/sdd-workspace",
452
+ "skills/subagent-driven-development/scripts/task-brief",
453
+ "skills/subagent-driven-development/scripts/review-package",
454
+ ]) {
455
+ if (!exists(script)) fail(`${script} is missing`);
456
+ }
457
+
382
458
  const expected = [
383
459
  ["agents/e2e-runner.md", "skills/e2e-testing/SKILL.md"],
384
460
  ["agents/tdd-guide.md", "skills/test-driven-development/SKILL.md"],
@@ -415,6 +491,9 @@ function checkSkillLinks() {
415
491
  "agents/code-reviewer.md",
416
492
  "skills/systematic-debugging/SKILL.md",
417
493
  "skills/verification-before-completion/SKILL.md",
494
+ "skills/subagent-driven-development/SKILL.md",
495
+ "## Global Constraints",
496
+ "**Interfaces:**",
418
497
  "Completion Loop",
419
498
  "`/verify`",
420
499
  "`/pr`",
@@ -549,6 +628,13 @@ function requireTokens(file, tokens) {
549
628
  function checkSuperpowersDevLoop() {
550
629
  requireTokens("README.md", [
551
630
  "Superpowers 风格开发闭环",
631
+ "using-superpowers",
632
+ "subagent-driven-development",
633
+ ".superpowers/sdd",
634
+ "Global Constraints",
635
+ "Interfaces",
636
+ "?key=",
637
+ "4 小时",
552
638
  "using-git-worktrees",
553
639
  "executing-plans",
554
640
  "verification-before-completion",
@@ -571,6 +657,12 @@ function checkSuperpowersDevLoop() {
571
657
  "PR Gate",
572
658
  ]);
573
659
 
660
+ requireTokens("rules/common/skills-learning.md", [
661
+ "skills/using-superpowers/SKILL.md",
662
+ "process skill 优先于 implementation skill",
663
+ "不凭记忆执行 skill",
664
+ ]);
665
+
574
666
  requireTokens("skills/brainstorming/SKILL.md", [
575
667
  "Spec Gate",
576
668
  "reviewed and approved the saved spec",
@@ -580,6 +672,9 @@ function checkSuperpowersDevLoop() {
580
672
  "## Preconditions",
581
673
  "approved spec",
582
674
  "Plan Gate",
675
+ "## Global Constraints",
676
+ "**Interfaces:**",
677
+ "skills/subagent-driven-development/SKILL.md",
583
678
  ]);
584
679
 
585
680
  requireTokens("skills/test-driven-development/SKILL.md", [
@@ -605,6 +700,30 @@ function checkSuperpowersDevLoop() {
605
700
  "docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md",
606
701
  "Write design doc",
607
702
  ]);
703
+
704
+ requireTokens("skills/brainstorming/visual-companion.md", [
705
+ "session key",
706
+ "?key=",
707
+ "4 hours idle",
708
+ "--idle-timeout-minutes",
709
+ "same port",
710
+ ]);
711
+
712
+ requireTokens("skills/brainstorming/scripts/server.cjs", [
713
+ "BRAINSTORM_TOKEN",
714
+ "BRAINSTORM_TOKEN_FILE",
715
+ "timingSafeEqualStr",
716
+ "Cache-Control",
717
+ "X-Frame-Options",
718
+ "Default 4 hours",
719
+ ]);
720
+
721
+ requireTokens("skills/brainstorming/scripts/start-server.sh", [
722
+ "--idle-timeout-minutes",
723
+ "BRAINSTORM_TOKEN_FILE",
724
+ "umask 077",
725
+ ".last-token",
726
+ ]);
608
727
  }
609
728
 
610
729
  function checkForbiddenCommandDrift() {
@@ -650,6 +769,11 @@ function checkScriptLayout() {
650
769
  "scripts/lib/utils.js",
651
770
  "scripts/learning/utils.js",
652
771
  "hooks/review-confidence.js",
772
+ "hooks/session-start.js",
773
+ "hooks/session-end.js",
774
+ "hooks/evaluate-session.js",
775
+ "hooks/pre-compact.js",
776
+ "hooks/runtime/session-utils.js",
653
777
  ]) {
654
778
  if (exists(legacyPath)) {
655
779
  fail(`${legacyPath} should not exist after script layout cleanup`);
@@ -659,10 +783,9 @@ function checkScriptLayout() {
659
783
  for (const requiredPath of [
660
784
  "hooks/runtime/run-with-flags.js",
661
785
  "hooks/runtime/hook-flags.js",
662
- "hooks/runtime/session-utils.js",
663
- "hooks/session-start.js",
664
- "hooks/session-end.js",
665
786
  "hooks/commit-quality.js",
787
+ "hooks/check-console-log.js",
788
+ "hooks/check-code-size.js",
666
789
  "scripts/learning/review-confidence.js",
667
790
  "scripts/learning/project-utils.js",
668
791
  "scripts/learning/projects.js",
@@ -676,8 +799,10 @@ function checkScriptLayout() {
676
799
 
677
800
  requireTokens("settings.json", [
678
801
  "hooks/runtime/run-with-flags.js",
679
- "hooks/session-start.js",
680
- "hooks/session-end.js",
802
+ "hooks/check-console-log.js",
803
+ "hooks/check-code-size.js",
804
+ "hooks/commit-quality.js",
805
+ "skills/continuous-learning-v2/hooks/observe-v2.js",
681
806
  ]);
682
807
 
683
808
  requireTokens("scripts/install.ps1", [
@@ -705,6 +830,11 @@ function checkScriptLayout() {
705
830
  "scripts/hooks/run-with-flags.js",
706
831
  "scripts/lib/hook-flags.js",
707
832
  "hooks/review-confidence.js",
833
+ "hooks/session-start.js",
834
+ "hooks/session-end.js",
835
+ "hooks/evaluate-session.js",
836
+ "hooks/pre-compact.js",
837
+ "hooks/runtime/session-utils.js",
708
838
  ]) {
709
839
  if (body.includes(forbidden)) {
710
840
  fail(`${file} references legacy path ${forbidden}`);
@@ -863,9 +993,9 @@ function main() {
863
993
  checkReadmeTreePaths();
864
994
  checkInstallRuntimePolicy();
865
995
  checkHookConfigReferences();
996
+ checkGitHubWorkflows();
866
997
  checkLearningPathPolicy();
867
998
  checkRouterTargets();
868
- checkAcceptanceGate();
869
999
  checkNpmPackageSurface();
870
1000
  checkSkillLinks();
871
1001
  checkRuleLoadingPolicy();
package/settings.json CHANGED
@@ -1,19 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/claude-code-settings.json",
3
3
  "hooks": {
4
- "SessionStart": [
5
- {
6
- "matcher": "*",
7
- "hooks": [
8
- {
9
- "type": "command",
10
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" session:start \"$HOME/.claude/hooks/session-start.js\" minimal,standard,strict",
11
- "timeout": 5
12
- }
13
- ]
14
- }
15
- ],
16
-
17
4
  "PostToolUse": [
18
5
  {
19
6
  "matcher": "Edit|Write|MultiEdit",
@@ -22,6 +9,11 @@
22
9
  "type": "command",
23
10
  "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" post:edit:console-log \"$HOME/.claude/hooks/check-console-log.js\" standard,strict",
24
11
  "timeout": 5
12
+ },
13
+ {
14
+ "type": "command",
15
+ "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" post:edit:code-size \"$HOME/.claude/hooks/check-code-size.js\" standard,strict",
16
+ "timeout": 5
25
17
  }
26
18
  ]
27
19
  },
@@ -37,41 +29,17 @@
37
29
  ]
38
30
  }
39
31
  ],
40
- "Stop": [
32
+ "PreToolUse": [
41
33
  {
42
- "matcher": "*",
34
+ "matcher": "Bash",
43
35
  "hooks": [
44
36
  {
45
37
  "type": "command",
46
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" stop:evaluate-session \"$HOME/.claude/hooks/evaluate-session.js\" strict",
38
+ "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" pre:bash:commit-quality \"$HOME/.claude/hooks/commit-quality.js\" standard,strict",
47
39
  "timeout": 10
48
40
  }
49
41
  ]
50
42
  }
51
- ],
52
- "SessionEnd": [
53
- {
54
- "matcher": "*",
55
- "hooks": [
56
- {
57
- "type": "command",
58
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" session:end \"$HOME/.claude/hooks/session-end.js\" minimal,standard,strict",
59
- "timeout": 5
60
- }
61
- ]
62
- }
63
- ],
64
- "PreCompact": [
65
- {
66
- "matcher": "*",
67
- "hooks": [
68
- {
69
- "type": "command",
70
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" precompact:save-context \"$HOME/.claude/hooks/pre-compact.js\" minimal,standard,strict",
71
- "timeout": 5
72
- }
73
- ]
74
- }
75
43
  ]
76
44
  }
77
45
  }
@@ -9,11 +9,11 @@
9
9
  *
10
10
  * This template provides a consistent frame with:
11
11
  * - OS-aware light/dark theming
12
- * - Fixed header and selection indicator bar
12
+ * - Header branding and connection status
13
13
  * - Scrollable main content area
14
14
  * - CSS helpers for common UI patterns
15
15
  *
16
- * Content is injected via placeholder comment in #claude-content.
16
+ * Content is injected via placeholder comment in #frame-content.
17
17
  */
18
18
 
19
19
  * { box-sizing: border-box; margin: 0; padding: 0; }
@@ -63,34 +63,37 @@
63
63
  }
64
64
 
65
65
  /* ===== FRAME STRUCTURE ===== */
66
- .header {
67
- background: var(--bg-secondary);
68
- padding: 0.5rem 1.5rem;
69
- display: flex;
70
- justify-content: space-between;
71
- align-items: center;
72
- border-bottom: 1px solid var(--border);
73
- flex-shrink: 0;
66
+ .brand { display: flex; align-items: center; min-width: 0; overflow: hidden; color: var(--text-secondary); line-height: 1; }
67
+ .brand a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 0.5rem; min-width: 0; max-width: 100%; line-height: 1; }
68
+ .brand-copy { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1; transform: translateY(-1px); }
69
+ .brand-logo { display: block; height: 1em; width: auto; max-width: 180px; flex-shrink: 0; filter: invert(1); }
70
+ @media (prefers-color-scheme: dark) {
71
+ .brand-logo { filter: none; }
74
72
  }
75
- .header h1 { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }
76
- .header .status { font-size: 0.7rem; color: var(--success); display: flex; align-items: center; gap: 0.4rem; }
77
- .header .status::before { content: ''; width: 6px; height: 6px; background: var(--success); border-radius: 50%; }
73
+ .status { font-size: 0.7rem; color: var(--status-color, var(--success)); display: flex; align-items: center; gap: 0.4rem; justify-self: end; white-space: nowrap; line-height: 1; }
74
+ .status::before { content: ''; width: 6px; height: 6px; background: var(--status-color, var(--success)); border-radius: 50%; }
78
75
 
79
76
  .main { flex: 1; overflow-y: auto; }
80
- #claude-content { padding: 2rem; min-height: 100%; }
77
+ #frame-content { padding: 2rem; min-height: 100%; }
81
78
 
82
- .indicator-bar {
79
+ .header {
83
80
  background: var(--bg-secondary);
84
- border-top: 1px solid var(--border);
81
+ border-bottom: 1px solid var(--border);
85
82
  padding: 0.5rem 1.5rem;
86
83
  flex-shrink: 0;
87
- text-align: center;
84
+ display: grid;
85
+ grid-template-columns: minmax(0, 1fr) auto;
86
+ align-items: center;
87
+ gap: 1rem;
88
+ min-height: 42px;
88
89
  }
89
- .indicator-bar span {
90
+ .header .brand { justify-self: start; width: 100%; font-size: 0.75rem; line-height: 1; }
91
+ .header .status { grid-column: 2; line-height: 1; }
92
+ .header span {
90
93
  font-size: 0.75rem;
91
94
  color: var(--text-secondary);
92
95
  }
93
- .indicator-bar .selected-text {
96
+ .header .selected-text {
94
97
  color: var(--accent);
95
98
  font-weight: 500;
96
99
  }
@@ -196,19 +199,15 @@
196
199
  </head>
197
200
  <body>
198
201
  <div class="header">
199
- <h1><a href="https://github.com/obra/superpowers" style="color: inherit; text-decoration: none;">Superpowers Brainstorming</a></h1>
200
- <div class="status">Connected</div>
202
+ <!-- BRANDING -->
203
+ <div class="status">Connecting…</div>
201
204
  </div>
202
205
 
203
206
  <div class="main">
204
- <div id="claude-content">
207
+ <div id="frame-content">
205
208
  <!-- CONTENT -->
206
209
  </div>
207
210
  </div>
208
211
 
209
- <div class="indicator-bar">
210
- <span id="indicator-text">Click an option above, then return to the terminal</span>
211
- </div>
212
-
213
212
  </body>
214
213
  </html>
@@ -1,26 +1,120 @@
1
1
  (function() {
2
- const WS_URL = 'ws://' + window.location.host;
2
+ const MIN_RECONNECT_MS = 500;
3
+ const MAX_RECONNECT_MS = 30000;
4
+ const TOMBSTONE_AFTER_MS = 15000; // show the "paused" overlay after this long disconnected
5
+
6
+ // Pure: next backoff delay (doubles, capped). Exported for unit tests.
7
+ function nextReconnectDelay(current, max) {
8
+ return Math.min(current * 2, max);
9
+ }
10
+ if (typeof module !== 'undefined' && module.exports) {
11
+ module.exports = { nextReconnectDelay, MIN_RECONNECT_MS, MAX_RECONNECT_MS, TOMBSTONE_AFTER_MS };
12
+ }
13
+
14
+ // Everything below is browser-only; bail out when loaded in Node (tests).
15
+ if (typeof window === 'undefined') return;
16
+
3
17
  let ws = null;
4
18
  let eventQueue = [];
19
+ let reconnectDelay = MIN_RECONNECT_MS;
20
+ let reconnectTimer = null;
21
+ let disconnectedSince = null;
22
+ let everConnected = false;
23
+ let tombstoneShown = false;
24
+
25
+ function sessionKey() {
26
+ try {
27
+ return window.sessionStorage && window.sessionStorage.getItem('brainstorm-session-key');
28
+ } catch (e) {}
29
+ return null;
30
+ }
31
+
32
+ function websocketUrl() {
33
+ const key = sessionKey();
34
+ return 'ws://' + window.location.host + (key ? '/?key=' + encodeURIComponent(key) : '');
35
+ }
36
+
37
+ function reloadAfterRecovery() {
38
+ const key = sessionKey();
39
+ if (key) {
40
+ window.location.replace('/?key=' + encodeURIComponent(key));
41
+ } else {
42
+ window.location.reload();
43
+ }
44
+ }
45
+
46
+ // Reflect connection state in the frame's status pill (absent on full-doc screens).
47
+ function setStatus(state) {
48
+ const el = document.querySelector('.status');
49
+ if (!el) return;
50
+ const map = {
51
+ connecting: ['Connecting…', 'var(--text-tertiary)'],
52
+ connected: ['Connected', 'var(--success)'],
53
+ reconnecting: ['Reconnecting…', 'var(--warning)'],
54
+ disconnected: ['Disconnected', 'var(--error)']
55
+ };
56
+ const [text, color] = map[state] || map.disconnected;
57
+ el.textContent = text;
58
+ el.style.setProperty('--status-color', color);
59
+ }
60
+
61
+ // Self-styled so it works on framed and full-document screens alike.
62
+ function showTombstone() {
63
+ if (tombstoneShown) return;
64
+ tombstoneShown = true;
65
+ const el = document.createElement('div');
66
+ el.id = 'bs-tombstone';
67
+ el.style.cssText = 'position:fixed;inset:0;z-index:99999;display:flex;' +
68
+ 'align-items:center;justify-content:center;padding:2rem;text-align:center;' +
69
+ 'background:rgba(20,20,22,0.92);color:#f5f5f7;font-family:system-ui,sans-serif';
70
+ el.innerHTML = '<div style="max-width:480px">' +
71
+ '<h2 style="margin:0 0 .5rem;font-weight:600">Companion paused</h2>' +
72
+ '<p style="margin:0;opacity:.85">This brainstorm companion has stopped. ' +
73
+ 'Ask your coding agent to bring it back — this page reconnects automatically.</p></div>';
74
+ if (document.body) document.body.appendChild(el);
75
+ }
5
76
 
6
77
  function connect() {
7
- ws = new WebSocket(WS_URL);
78
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
79
+ setStatus(everConnected ? 'reconnecting' : 'connecting');
80
+ ws = new WebSocket(websocketUrl());
8
81
 
9
82
  ws.onopen = () => {
83
+ const recovered = tombstoneShown;
84
+ everConnected = true;
85
+ disconnectedSince = null;
86
+ reconnectDelay = MIN_RECONNECT_MS;
87
+ tombstoneShown = false;
88
+ setStatus('connected');
10
89
  eventQueue.forEach(e => ws.send(JSON.stringify(e)));
11
90
  eventQueue = [];
91
+ // Recovered from a tombstoned outage (e.g. the server restarted on the same
92
+ // port) — reload through the keyed bootstrap when possible so the cookie is
93
+ // refreshed before the visible URL returns to bare /.
94
+ if (recovered) reloadAfterRecovery();
12
95
  };
13
96
 
14
97
  ws.onmessage = (msg) => {
15
- const data = JSON.parse(msg.data);
16
- if (data.type === 'reload') {
17
- window.location.reload();
18
- }
98
+ let data;
99
+ try { data = JSON.parse(msg.data); } catch (e) { return; }
100
+ if (data.type === 'reload') window.location.reload();
19
101
  };
20
102
 
21
103
  ws.onclose = () => {
22
- setTimeout(connect, 1000);
104
+ ws = null;
105
+ if (disconnectedSince === null) disconnectedSince = Date.now();
106
+ if (Date.now() - disconnectedSince >= TOMBSTONE_AFTER_MS) {
107
+ setStatus('disconnected');
108
+ showTombstone();
109
+ } else {
110
+ setStatus('reconnecting');
111
+ }
112
+ reconnectTimer = setTimeout(connect, reconnectDelay);
113
+ reconnectDelay = nextReconnectDelay(reconnectDelay, MAX_RECONNECT_MS);
23
114
  };
115
+
116
+ // Let onclose own reconnection so we don't schedule it twice.
117
+ ws.onerror = () => { try { ws.close(); } catch (e) {} };
24
118
  }
25
119
 
26
120
  function sendEvent(event) {
@@ -44,21 +138,6 @@
44
138
  id: target.id || null
45
139
  });
46
140
 
47
- // Update indicator bar (defer so toggleSelect runs first)
48
- setTimeout(() => {
49
- const indicator = document.getElementById('indicator-text');
50
- if (!indicator) return;
51
- const container = target.closest('.options') || target.closest('.cards');
52
- const selected = container ? container.querySelectorAll('.selected') : [];
53
- if (selected.length === 0) {
54
- indicator.textContent = 'Click an option above, then return to the terminal';
55
- } else if (selected.length === 1) {
56
- const label = selected[0].querySelector('h3, .content h3, .card-body h3')?.textContent?.trim() || selected[0].dataset.choice;
57
- indicator.innerHTML = '<span class="selected-text">' + label + ' selected</span> — return to terminal to continue';
58
- } else {
59
- indicator.innerHTML = '<span class="selected-text">' + selected.length + ' selected</span> — return to terminal to continue';
60
- }
61
- }, 0);
62
141
  });
63
142
 
64
143
  // Frame UI: selection tracking