claude-everything-workflow 0.1.5 → 0.1.7

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 +56 -9
  2. package/package.json +1 -1
  3. package/rules/common/hooks.md +2 -1
  4. package/rules/common/skills-learning.md +9 -0
  5. package/scripts/install.ps1 +80 -43
  6. package/scripts/install.sh +56 -3
  7. package/scripts/verify-harness.js +225 -5
  8. package/settings.json +3 -40
  9. package/skills/README.md +35 -0
  10. package/skills/brainstorming/scripts/frame-template.html +25 -26
  11. package/skills/brainstorming/scripts/helper.js +101 -22
  12. package/skills/brainstorming/scripts/server.cjs +399 -30
  13. package/skills/brainstorming/scripts/start-server.sh +70 -9
  14. package/skills/brainstorming/scripts/stop-server.sh +66 -2
  15. package/skills/brainstorming/visual-companion.md +33 -22
  16. package/skills/context-budget/SKILL.md +59 -0
  17. package/skills/iterative-retrieval/SKILL.md +75 -0
  18. package/skills/learn/.gitkeep +0 -0
  19. package/skills/learn/README.md +15 -0
  20. package/skills/learn/debugging/.gitkeep +0 -0
  21. package/skills/learn/pr/.gitkeep +0 -0
  22. package/skills/learn/testing/.gitkeep +0 -0
  23. package/skills/subagent-driven-development/SKILL.md +425 -0
  24. package/skills/subagent-driven-development/implementer-prompt.md +139 -0
  25. package/skills/subagent-driven-development/scripts/review-package +44 -0
  26. package/skills/subagent-driven-development/scripts/sdd-workspace +22 -0
  27. package/skills/subagent-driven-development/scripts/task-brief +40 -0
  28. package/skills/subagent-driven-development/task-reviewer-prompt.md +188 -0
  29. package/skills/using-superpowers/SKILL.md +75 -0
  30. package/skills/writing-plans/SKILL.md +25 -2
  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
@@ -48,8 +48,13 @@ function managedFiles() {
48
48
  "commands",
49
49
  "agents",
50
50
  "skills/continuous-learning-v2",
51
+ "skills/README.md",
51
52
  "skills/test-driven-development",
52
53
  "skills/e2e-testing",
54
+ "skills/context-budget",
55
+ "skills/iterative-retrieval",
56
+ "skills/using-superpowers",
57
+ "skills/subagent-driven-development",
53
58
  "skills/brainstorming",
54
59
  "skills/using-git-worktrees",
55
60
  "skills/executing-plans",
@@ -232,10 +237,30 @@ function checkHookConfigReferences() {
232
237
 
233
238
  collect(settings.hooks);
234
239
 
240
+ const LEGACY_HOOK_PATTERNS = [
241
+ "scripts/hooks/run-with-flags.js",
242
+ "scripts/hooks/commit-quality.js",
243
+ "scripts/hooks/session-start.js",
244
+ "scripts/hooks/session-end.js",
245
+ "scripts/lib/hook-flags.js",
246
+ "hooks/observe.js",
247
+ "hooks/review-confidence.js",
248
+ "hooks/session-start.js",
249
+ "hooks/session-end.js",
250
+ "hooks/evaluate-session.js",
251
+ "hooks/pre-compact.js",
252
+ "hooks/runtime/session-utils.js",
253
+ ];
254
+
235
255
  for (const command of commands) {
236
256
  if (command.includes("$HOME/.codex")) {
237
257
  fail("settings.json should not point hooks at ~/.codex");
238
258
  }
259
+ for (const legacy of LEGACY_HOOK_PATTERNS) {
260
+ if (command.includes(legacy)) {
261
+ fail(`settings.json contains legacy hook path: ${legacy}`);
262
+ }
263
+ }
239
264
  const matches = [...command.matchAll(/\$HOME\/\.claude\/([^" ]+)/g)];
240
265
  for (const match of matches) {
241
266
  const referenced = match[1];
@@ -244,6 +269,43 @@ function checkHookConfigReferences() {
244
269
  }
245
270
  }
246
271
  }
272
+
273
+ // 验证安装脚本包含旧版 Hook 清理逻辑
274
+ for (const installer of ["scripts/install.sh", "scripts/install.ps1"]) {
275
+ if (!exists(installer)) continue;
276
+ const body = read(installer);
277
+ if (!body.includes("LEGACY_HOOK_PATTERNS") && !body.includes("isLegacyHook")) {
278
+ fail(`${installer} should include legacy hook path cleanup logic`);
279
+ }
280
+ }
281
+ }
282
+
283
+ function checkGitHubWorkflows() {
284
+ requireTokens(".github/workflows/ci.yml", [
285
+ "pull_request",
286
+ "npm run verify",
287
+ "npm run pack:dry-run",
288
+ ]);
289
+
290
+ requireTokens(".github/workflows/npm-publish.yml", [
291
+ "workflow_dispatch",
292
+ "id-token: write",
293
+ "node-version: 22.14.0",
294
+ "package-manager-cache: false",
295
+ "npm install -g npm@11.5.1",
296
+ "npm view \"$PACKAGE_NAME\" version --registry=https://registry.npmjs.org",
297
+ "BASE_VERSION=\"${REGISTRY_VERSION:-$LOCAL_VERSION}\"",
298
+ "npm version \"$VERSION\" --no-git-tag-version",
299
+ "npm publish",
300
+ "git push --follow-tags origin HEAD:main",
301
+ "[skip npm]",
302
+ ]);
303
+
304
+ requireTokens("README.md", [
305
+ "npm 自动发布",
306
+ "受信任的发布商",
307
+ "npm registry 的当前 `latest` 版本",
308
+ ]);
247
309
  }
248
310
 
249
311
  function checkLearningPathPolicy() {
@@ -289,6 +351,55 @@ function checkLearningPathPolicy() {
289
351
  ]);
290
352
  }
291
353
 
354
+ function checkSkillCategoryIndex() {
355
+ requireTokens("skills/README.md", [
356
+ "正式 skill 保持 `skills/<skill-name>/SKILL.md` 平铺结构",
357
+ "Process / 门禁",
358
+ "Engineering / 开发实践",
359
+ "Harness / 上下文与编排",
360
+ "Meta / Skill 管理",
361
+ "Learn / 学习沉淀",
362
+ ]);
363
+
364
+ const indexed = new Set(
365
+ [...read("skills/README.md").matchAll(/^- `([^`]+)`:/gm)].map(
366
+ (match) => match[1],
367
+ ),
368
+ );
369
+ const skillsDir = rel("skills");
370
+ const actual = fs
371
+ .readdirSync(skillsDir, { withFileTypes: true })
372
+ .filter((entry) => entry.isDirectory())
373
+ .map((entry) => entry.name)
374
+ .filter((name) => name !== "learn")
375
+ .filter((name) => exists(path.join("skills", name, "SKILL.md")))
376
+ .sort();
377
+
378
+ for (const name of actual) {
379
+ if (!indexed.has(name)) {
380
+ fail(`skills/README.md should categorize skill ${name}`);
381
+ }
382
+ }
383
+
384
+ for (const name of indexed) {
385
+ if (name === "learn") continue;
386
+ if (!exists(path.join("skills", name, "SKILL.md"))) {
387
+ fail(`skills/README.md lists missing skill ${name}`);
388
+ }
389
+ }
390
+
391
+ requireTokens("README.md", [
392
+ "Skill 分类索引",
393
+ "物理目录保持平铺以兼容发现",
394
+ "只有学习产物使用物理分类目录 `skills/learn/<category>/`",
395
+ ]);
396
+
397
+ requireTokens("rules/common/skills-learning.md", [
398
+ "正式 skill 目录保持 `skills/<skill-name>/SKILL.md` 平铺结构",
399
+ "分类维护在 `skills/README.md`",
400
+ ]);
401
+ }
402
+
292
403
  function checkRouterTargets() {
293
404
  const expected = [
294
405
  ["commands/code-review.md", ["agents/code-reviewer.md"]],
@@ -359,6 +470,43 @@ function checkNpmPackageSurface() {
359
470
  }
360
471
 
361
472
  function checkSkillLinks() {
473
+ requireTokens("skills/using-superpowers/SKILL.md", [
474
+ "Skill Invocation Rule",
475
+ "Task arrives",
476
+ "approved plan + SDD/commit approved?",
477
+ "external skill learning or edit?",
478
+ "process skills before implementation skills",
479
+ "skills/brainstorming/SKILL.md",
480
+ "skills/systematic-debugging/SKILL.md",
481
+ "skills/verification-before-completion/SKILL.md",
482
+ "User instructions",
483
+ ]);
484
+
485
+ requireTokens("skills/subagent-driven-development/SKILL.md", [
486
+ ".superpowers/sdd/progress.md",
487
+ "scripts/task-brief",
488
+ "scripts/review-package BASE HEAD",
489
+ "task-reviewer-prompt.md",
490
+ "Local Git Boundary",
491
+ "skills/executing-plans/SKILL.md",
492
+ ]);
493
+
494
+ requireTokens("skills/subagent-driven-development/task-reviewer-prompt.md", [
495
+ "Spec Compliance",
496
+ "Task quality",
497
+ "Cannot verify from diff",
498
+ "[BRIEF_FILE]",
499
+ "[DIFF_FILE]",
500
+ ]);
501
+
502
+ for (const script of [
503
+ "skills/subagent-driven-development/scripts/sdd-workspace",
504
+ "skills/subagent-driven-development/scripts/task-brief",
505
+ "skills/subagent-driven-development/scripts/review-package",
506
+ ]) {
507
+ if (!exists(script)) fail(`${script} is missing`);
508
+ }
509
+
362
510
  const expected = [
363
511
  ["agents/e2e-runner.md", "skills/e2e-testing/SKILL.md"],
364
512
  ["agents/tdd-guide.md", "skills/test-driven-development/SKILL.md"],
@@ -395,6 +543,9 @@ function checkSkillLinks() {
395
543
  "agents/code-reviewer.md",
396
544
  "skills/systematic-debugging/SKILL.md",
397
545
  "skills/verification-before-completion/SKILL.md",
546
+ "skills/subagent-driven-development/SKILL.md",
547
+ "## Global Constraints",
548
+ "**Interfaces:**",
398
549
  "Completion Loop",
399
550
  "`/verify`",
400
551
  "`/pr`",
@@ -453,6 +604,21 @@ function checkSkillLinks() {
453
604
  "skipped checks",
454
605
  "remaining risk",
455
606
  ]);
607
+
608
+ requireTokens("skills/context-budget/SKILL.md", [
609
+ "MCP 默认策略",
610
+ "通用",
611
+ "MCP 明显优于 CLI/API/原生能力",
612
+ "报告格式",
613
+ ]);
614
+
615
+ requireTokens("skills/iterative-retrieval/SKILL.md", [
616
+ "Dispatch",
617
+ "Evaluate",
618
+ "Refine",
619
+ "最多跑 3 轮",
620
+ "回传格式",
621
+ ]);
456
622
  }
457
623
 
458
624
  function checkRuleLoadingPolicy() {
@@ -529,7 +695,16 @@ function requireTokens(file, tokens) {
529
695
  function checkSuperpowersDevLoop() {
530
696
  requireTokens("README.md", [
531
697
  "Superpowers 风格开发闭环",
698
+ "using-superpowers",
699
+ "subagent-driven-development",
700
+ ".superpowers/sdd",
701
+ "Global Constraints",
702
+ "Interfaces",
703
+ "?key=",
704
+ "4 小时",
532
705
  "using-git-worktrees",
706
+ "context-budget",
707
+ "iterative-retrieval",
533
708
  "executing-plans",
534
709
  "verification-before-completion",
535
710
  "没有 spec,不进入 plan",
@@ -551,6 +726,12 @@ function checkSuperpowersDevLoop() {
551
726
  "PR Gate",
552
727
  ]);
553
728
 
729
+ requireTokens("rules/common/skills-learning.md", [
730
+ "skills/using-superpowers/SKILL.md",
731
+ "process skill 优先于 implementation skill",
732
+ "不凭记忆执行 skill",
733
+ ]);
734
+
554
735
  requireTokens("skills/brainstorming/SKILL.md", [
555
736
  "Spec Gate",
556
737
  "reviewed and approved the saved spec",
@@ -560,6 +741,9 @@ function checkSuperpowersDevLoop() {
560
741
  "## Preconditions",
561
742
  "approved spec",
562
743
  "Plan Gate",
744
+ "## Global Constraints",
745
+ "**Interfaces:**",
746
+ "skills/subagent-driven-development/SKILL.md",
563
747
  ]);
564
748
 
565
749
  requireTokens("skills/test-driven-development/SKILL.md", [
@@ -585,6 +769,30 @@ function checkSuperpowersDevLoop() {
585
769
  "docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md",
586
770
  "Write design doc",
587
771
  ]);
772
+
773
+ requireTokens("skills/brainstorming/visual-companion.md", [
774
+ "session key",
775
+ "?key=",
776
+ "4 hours idle",
777
+ "--idle-timeout-minutes",
778
+ "same port",
779
+ ]);
780
+
781
+ requireTokens("skills/brainstorming/scripts/server.cjs", [
782
+ "BRAINSTORM_TOKEN",
783
+ "BRAINSTORM_TOKEN_FILE",
784
+ "timingSafeEqualStr",
785
+ "Cache-Control",
786
+ "X-Frame-Options",
787
+ "Default 4 hours",
788
+ ]);
789
+
790
+ requireTokens("skills/brainstorming/scripts/start-server.sh", [
791
+ "--idle-timeout-minutes",
792
+ "BRAINSTORM_TOKEN_FILE",
793
+ "umask 077",
794
+ ".last-token",
795
+ ]);
588
796
  }
589
797
 
590
798
  function checkForbiddenCommandDrift() {
@@ -630,6 +838,11 @@ function checkScriptLayout() {
630
838
  "scripts/lib/utils.js",
631
839
  "scripts/learning/utils.js",
632
840
  "hooks/review-confidence.js",
841
+ "hooks/session-start.js",
842
+ "hooks/session-end.js",
843
+ "hooks/evaluate-session.js",
844
+ "hooks/pre-compact.js",
845
+ "hooks/runtime/session-utils.js",
633
846
  ]) {
634
847
  if (exists(legacyPath)) {
635
848
  fail(`${legacyPath} should not exist after script layout cleanup`);
@@ -639,10 +852,8 @@ function checkScriptLayout() {
639
852
  for (const requiredPath of [
640
853
  "hooks/runtime/run-with-flags.js",
641
854
  "hooks/runtime/hook-flags.js",
642
- "hooks/runtime/session-utils.js",
643
- "hooks/session-start.js",
644
- "hooks/session-end.js",
645
855
  "hooks/commit-quality.js",
856
+ "hooks/check-console-log.js",
646
857
  "hooks/check-code-size.js",
647
858
  "scripts/learning/review-confidence.js",
648
859
  "scripts/learning/project-utils.js",
@@ -657,8 +868,10 @@ function checkScriptLayout() {
657
868
 
658
869
  requireTokens("settings.json", [
659
870
  "hooks/runtime/run-with-flags.js",
660
- "hooks/session-start.js",
661
- "hooks/session-end.js",
871
+ "hooks/check-console-log.js",
872
+ "hooks/check-code-size.js",
873
+ "hooks/commit-quality.js",
874
+ "skills/continuous-learning-v2/hooks/observe-v2.js",
662
875
  ]);
663
876
 
664
877
  requireTokens("scripts/install.ps1", [
@@ -686,6 +899,11 @@ function checkScriptLayout() {
686
899
  "scripts/hooks/run-with-flags.js",
687
900
  "scripts/lib/hook-flags.js",
688
901
  "hooks/review-confidence.js",
902
+ "hooks/session-start.js",
903
+ "hooks/session-end.js",
904
+ "hooks/evaluate-session.js",
905
+ "hooks/pre-compact.js",
906
+ "hooks/runtime/session-utils.js",
689
907
  ]) {
690
908
  if (body.includes(forbidden)) {
691
909
  fail(`${file} references legacy path ${forbidden}`);
@@ -844,7 +1062,9 @@ function main() {
844
1062
  checkReadmeTreePaths();
845
1063
  checkInstallRuntimePolicy();
846
1064
  checkHookConfigReferences();
1065
+ checkGitHubWorkflows();
847
1066
  checkLearningPathPolicy();
1067
+ checkSkillCategoryIndex();
848
1068
  checkRouterTargets();
849
1069
  checkNpmPackageSurface();
850
1070
  checkSkillLinks();
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",
@@ -42,41 +29,17 @@
42
29
  ]
43
30
  }
44
31
  ],
45
- "Stop": [
32
+ "PreToolUse": [
46
33
  {
47
- "matcher": "*",
34
+ "matcher": "Bash",
48
35
  "hooks": [
49
36
  {
50
37
  "type": "command",
51
- "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",
52
39
  "timeout": 10
53
40
  }
54
41
  ]
55
42
  }
56
- ],
57
- "SessionEnd": [
58
- {
59
- "matcher": "*",
60
- "hooks": [
61
- {
62
- "type": "command",
63
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" session:end \"$HOME/.claude/hooks/session-end.js\" minimal,standard,strict",
64
- "timeout": 5
65
- }
66
- ]
67
- }
68
- ],
69
- "PreCompact": [
70
- {
71
- "matcher": "*",
72
- "hooks": [
73
- {
74
- "type": "command",
75
- "command": "node \"$HOME/.claude/hooks/runtime/run-with-flags.js\" precompact:save-context \"$HOME/.claude/hooks/pre-compact.js\" minimal,standard,strict",
76
- "timeout": 5
77
- }
78
- ]
79
- }
80
43
  ]
81
44
  }
82
45
  }
@@ -0,0 +1,35 @@
1
+ # Skills 分类索引
2
+
3
+ 正式 skill 保持 `skills/<skill-name>/SKILL.md` 平铺结构,兼容 Claude Code、Codex 和打包安装的发现方式。分类只在本索引维护,不用物理嵌套目录;需要长材料时,放到对应 skill 的 `references/`。
4
+
5
+ ## Process / 门禁
6
+
7
+ - `using-superpowers`:非平凡任务的 skill 路由、优先级和完成声明纪律。
8
+ - `brainstorming`:复杂/高风险任务的 Spec Gate。
9
+ - `writing-plans`:已批准 spec 到实施计划的 Plan Gate。
10
+ - `executing-plans`:按已批准计划顺序执行。
11
+ - `subagent-driven-development`:用户批准 commit/PR/SDD handling 后的任务拆分、审查和进度账本。
12
+ - `using-git-worktrees`:脏工作区、高风险或并行任务的隔离工作区准备。
13
+ - `verification-before-completion`:完成、通过、已修复或 ready 声明前的新鲜验证门。
14
+
15
+ ## Engineering / 开发实践
16
+
17
+ - `test-driven-development`:行为变化的 Red Test Gate。
18
+ - `systematic-debugging`:失败、异常结果和 flaky 行为的根因调试。
19
+ - `e2e-testing`:Playwright E2E 模式、CI、制品和 flaky 处理。
20
+ - `documentation-lookup`:第三方库/API 的最新文档查询。
21
+
22
+ ## Harness / 上下文与编排
23
+
24
+ - `context-budget`:审计上下文、MCP、agent 和 skill 常驻开销。
25
+ - `iterative-retrieval`:subagent 和大仓库探索的迭代检索闭环。
26
+ - `continuous-learning-v2`:Hook 观察、project/global instinct、学习评估和演化。
27
+
28
+ ## Meta / Skill 管理
29
+
30
+ - `skill-creator`:创建或更新 skill 的结构和质量规则。
31
+ - `find-skills`:查找可安装或本地已有 skill。
32
+
33
+ ## Learn / 学习沉淀
34
+
35
+ 学习目录 `learn/` 经 `/learn-eval` 质量门确认学习模式,必须继续按 `skills/learn/<category>/` 分类保存。
@@ -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