@yunhozz/arc 0.0.0-stage → 0.1.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 (125) hide show
  1. package/MANIFEST.sha256 +96 -0
  2. package/README.md +265 -2
  3. package/bin/arc.mjs +3 -0
  4. package/claude/agents/arc-coder.md +67 -0
  5. package/claude/agents/arc-planner.md +74 -0
  6. package/claude/agents/arc-qa.md +68 -0
  7. package/claude/agents/arc-reviewer.md +65 -0
  8. package/claude/agents/arc-scouter.md +63 -0
  9. package/claude/skill/SKILL.md +370 -0
  10. package/claude/skill/hooks/git-policy.json +208 -0
  11. package/claude/skill/hooks/role-git-guard.mjs +98 -0
  12. package/claude/skill/models.toml +64 -0
  13. package/claude/skill/references/commit.md +77 -0
  14. package/claude/skill/references/git-recovery.md +46 -0
  15. package/claude/skill/references/handoff-prep.md +102 -0
  16. package/claude/skill/references/handoff.md +100 -0
  17. package/claude/skill/references/limits.md +42 -0
  18. package/claude/skill/references/planning.md +250 -0
  19. package/claude/skill/references/superpowers/LICENSE +21 -0
  20. package/claude/skill/references/superpowers/brainstorming/SKILL.md +225 -0
  21. package/claude/skill/references/superpowers/brainstorming/builder-check-prompt.md +23 -0
  22. package/claude/skill/references/superpowers/brainstorming/scripts/frame-template.html +213 -0
  23. package/claude/skill/references/superpowers/brainstorming/scripts/helper.js +167 -0
  24. package/claude/skill/references/superpowers/brainstorming/scripts/server.cjs +723 -0
  25. package/claude/skill/references/superpowers/brainstorming/scripts/start-server.sh +209 -0
  26. package/claude/skill/references/superpowers/brainstorming/scripts/stop-server.sh +120 -0
  27. package/claude/skill/references/superpowers/brainstorming/visual-companion.md +299 -0
  28. package/claude/skill/references/superpowers/provenance.json +26 -0
  29. package/claude/skill/references/superpowers/test-driven-development/SKILL.md +330 -0
  30. package/claude/skill/references/superpowers/test-driven-development/writing-good-tests.md +198 -0
  31. package/claude/skill/references/superpowers/writing-plans/SKILL.md +204 -0
  32. package/claude/skill/references/verification.md +125 -0
  33. package/claude/skill/references/visual-companion.md +16 -0
  34. package/claude/skill/scripts/apply-models.py +31 -0
  35. package/claude/skill/scripts/model_config.py +211 -0
  36. package/codex/agents/arc-coder.toml +37 -0
  37. package/codex/agents/arc-planner.toml +38 -0
  38. package/codex/agents/arc-qa.toml +24 -0
  39. package/codex/agents/arc-reviewer.toml +25 -0
  40. package/codex/agents/arc-scouter.toml +37 -0
  41. package/codex/skill/SKILL.md +356 -0
  42. package/codex/skill/models.toml +64 -0
  43. package/codex/skill/references/commit.md +100 -0
  44. package/codex/skill/references/git-recovery.md +64 -0
  45. package/codex/skill/references/handoff-prep.md +153 -0
  46. package/codex/skill/references/handoff-worktree.md +93 -0
  47. package/codex/skill/references/handoff.md +181 -0
  48. package/codex/skill/references/limits.md +43 -0
  49. package/codex/skill/references/planning.md +287 -0
  50. package/codex/skill/references/superpowers/LICENSE +21 -0
  51. package/codex/skill/references/superpowers/brainstorming/SKILL.md +225 -0
  52. package/codex/skill/references/superpowers/brainstorming/builder-check-prompt.md +23 -0
  53. package/codex/skill/references/superpowers/brainstorming/scripts/frame-template.html +213 -0
  54. package/codex/skill/references/superpowers/brainstorming/scripts/helper.js +167 -0
  55. package/codex/skill/references/superpowers/brainstorming/scripts/server.cjs +723 -0
  56. package/codex/skill/references/superpowers/brainstorming/scripts/start-server.sh +209 -0
  57. package/codex/skill/references/superpowers/brainstorming/scripts/stop-server.sh +120 -0
  58. package/codex/skill/references/superpowers/brainstorming/visual-companion.md +299 -0
  59. package/codex/skill/references/superpowers/provenance.json +26 -0
  60. package/codex/skill/references/superpowers/test-driven-development/SKILL.md +330 -0
  61. package/codex/skill/references/superpowers/test-driven-development/writing-good-tests.md +198 -0
  62. package/codex/skill/references/superpowers/writing-plans/SKILL.md +204 -0
  63. package/codex/skill/references/verification.md +163 -0
  64. package/codex/skill/references/visual-companion.md +23 -0
  65. package/codex/skill/scripts/apply-models.py +207 -0
  66. package/codex/skill/scripts/model_config.py +362 -0
  67. package/install.command +5 -0
  68. package/lib/cli/choices.mjs +47 -0
  69. package/lib/cli/completion.mjs +53 -0
  70. package/lib/cli/index.mjs +55 -0
  71. package/lib/cli/preset.mjs +29 -0
  72. package/lib/cli/progress.mjs +10 -0
  73. package/lib/cli/root.mjs +20 -0
  74. package/lib/cli/uninstall.mjs +17 -0
  75. package/lib/installer/acquisition.mjs +77 -0
  76. package/lib/installer/global-config.mjs +43 -0
  77. package/lib/installer/install.mjs +28 -0
  78. package/lib/installer/language.mjs +13 -0
  79. package/lib/installer/limits.mjs +21 -0
  80. package/lib/installer/manifest.mjs +37 -0
  81. package/lib/installer/package-references.mjs +32 -0
  82. package/lib/installer/plan.mjs +62 -0
  83. package/lib/installer/preset.mjs +26 -0
  84. package/lib/installer/runtime-config.mjs +85 -0
  85. package/lib/installer/shell-completion.mjs +29 -0
  86. package/lib/installer/stage-cleanup.mjs +40 -0
  87. package/lib/installer/superpowers.mjs +113 -0
  88. package/lib/installer/targets.mjs +55 -0
  89. package/lib/installer/transaction.mjs +91 -0
  90. package/lib/installer/uninstall.mjs +32 -0
  91. package/lib/limits.mjs +13 -0
  92. package/lib/models/config.mjs +58 -0
  93. package/lib/models/index.mjs +2 -0
  94. package/lib/models/profiles.mjs +111 -0
  95. package/lib/policy/claude-hook.mjs +40 -0
  96. package/lib/policy/render.mjs +74 -0
  97. package/lib/policy/role-policy.json +577 -0
  98. package/lib/safe-fs/index.mjs +67 -0
  99. package/lib/safe-fs/native.mjs +54 -0
  100. package/native/binding.c +157 -0
  101. package/native/binding.gyp +1 -0
  102. package/package.json +43 -4
  103. package/prebuilds/darwin-arm64/arc_safe_fs.node +0 -0
  104. package/prebuilds/darwin-x64/arc_safe_fs.node +0 -0
  105. package/prebuilds/index.json +64 -0
  106. package/prebuilds/linux-arm64-gnu/arc_safe_fs.node +0 -0
  107. package/prebuilds/linux-x64-gnu/arc_safe_fs.node +0 -0
  108. package/scripts/build-native.mjs +36 -0
  109. package/scripts/check-installer-parity.mjs +59 -0
  110. package/scripts/update-manifest.mjs +28 -0
  111. package/scripts/update-role-policy.mjs +15 -0
  112. package/scripts/update-superpowers.mjs +4 -0
  113. package/scripts/vendor-toml.mjs +40 -0
  114. package/vendor/toml/LICENSE +24 -0
  115. package/vendor/toml/dist/date.js +156 -0
  116. package/vendor/toml/dist/error.js +67 -0
  117. package/vendor/toml/dist/extract.js +293 -0
  118. package/vendor/toml/dist/index.js +34 -0
  119. package/vendor/toml/dist/parse.js +164 -0
  120. package/vendor/toml/dist/primitive.js +151 -0
  121. package/vendor/toml/dist/stringify.js +219 -0
  122. package/vendor/toml/dist/struct.js +156 -0
  123. package/vendor/toml/dist/util.js +57 -0
  124. package/vendor/toml/package.json +6 -0
  125. package/vendor/toml/provenance.json +35 -0
@@ -0,0 +1,225 @@
1
+ ---
2
+ name: brainstorming
3
+ description: "You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation)."
4
+ ---
5
+
6
+ # Brainstorming
7
+
8
+ You are very good at building. You build what you believe your human
9
+ partner wants, and that belief is usually thinner than it feels. This
10
+ skill is for finding out what they actually want, and why, before
11
+ anything gets built.
12
+
13
+ People often haven't finished working out what they want. Good questions
14
+ help them think it through. When you understand the why, you make the
15
+ hundred decisions they never mention the way they would have made them.
16
+
17
+ ## First: What Do You Actually Know?
18
+
19
+ Before you reply, ask yourself: what do I know about what they want, and
20
+ why?
21
+
22
+ - **Everything that matters is in the request** ("make the icon cornflower
23
+ blue"). This is a quick, clear task. Do it, and say what you did.
24
+ - **Something non-trivial is missing.** Start the conversation.
25
+
26
+ ## Your First Message
27
+
28
+ Your first message is two things, in this order:
29
+
30
+ 1. One line letting them know that if they'd rather skip the questions and
31
+ have you just start, they can say so. If they take you up on it, this
32
+ skill is done: state any significant how-it-gets-made choice
33
+ (platform, language, medium) in one plain line, then do what they
34
+ asked through the normal workflow.
35
+ 2. One open question that gets them describing. Ask about a real moment
36
+ or a concrete picture: "What's the moment you find yourself wishing
37
+ this existed?" or "Tell me about the people who'll be in the room."
38
+
39
+ That's the whole message.
40
+
41
+ ## The Conversation
42
+
43
+ Each message ends with one question: a single sentence with no list of
44
+ example answers hanging off it. Use plain language, pitched just a little
45
+ above where your human partner is. Match their vocabulary; never use
46
+ process jargon.
47
+
48
+ Be clear and concise. Lead with what matters. Avoid jargon. When you
49
+ report what you found, give them the most important findings and offer
50
+ the rest.
51
+
52
+ **Get them describing.** Open questions come first. Their own words carry
53
+ intent that your options can't. Offer a short menu only when they're
54
+ stuck. When they say "just guess" or "what do you think?", propose
55
+ something concrete.
56
+
57
+ **How it gets made.** Every project rests on choices about medium, tools,
58
+ materials, and resources: the platform, programming language, and
59
+ libraries for an app; the medium for a piece of art. Find out early which
60
+ of those choices they want to make, which they're handing to you, and what
61
+ they already have to work with. Someone with strong views or skills will
62
+ want to talk it through. Someone counting on you needs sensible defaults,
63
+ said in plain words. When there's existing work, build on what it already
64
+ uses. Any choice you make goes in the design as your call, never as
65
+ something they agreed to.
66
+
67
+ **Ground to cover.** This is territory, not a script. Never read these
68
+ out as questions:
69
+
70
+ - what kind of thing this is, and what makes it special
71
+ - why now, and what success looks like to them
72
+ - goals, non-goals, and anti-goals (what would make this a failure even
73
+ if it technically works)
74
+ - prior art: what they've seen elsewhere, loved or hated
75
+ - current state: what exists now, what they've tried
76
+ - the details they care about
77
+
78
+ **Questions that work** anchor in specifics: "Walk me through the last
79
+ time...", "If it could only do one of these well, which?", "What would
80
+ make you wince if I got it wrong?" A guess they can correct ("I'm
81
+ guessing this is because X keeps biting you?") often beats a question.
82
+
83
+ **Offer recon.** Once you have a bit of grounding and looking would help,
84
+ offer to go look: their codebase or project, their own files and data,
85
+ or the web. Say what you'd look for. They decide whether you go.
86
+
87
+ **Think wide privately.** Before you propose anything, come up with
88
+ several ideas and drop the weak ones, including any that fight what
89
+ they've told you about why. Show the comparison only when it helps them
90
+ decide.
91
+
92
+ **Show, don't tell.** Offer the visual companion (below) whenever seeing
93
+ would help more than reading:
94
+
95
+ - something they'll look at: a screen, a page, a printout, a sign
96
+ - a layout or arrangement: of a screen, a room, a schedule
97
+ - a flow or a sequence of steps
98
+ - options that would look different from each other
99
+ - a structure that's easier to see than read: a diagram, a timeline, a map
100
+
101
+ Once they've accepted, use it for mockups to react to, side-by-side
102
+ options, and throwaway prototypes they can click.
103
+
104
+ **Spike to feel things out.** Agentic work is waterfall, but very, very
105
+ fast. A quick throwaway build is often the cheapest way to learn what
106
+ they want or whether something works. Offer one when it would help.
107
+ When they just want to spike, get out of the way. Spikes get no tests
108
+ or minimal ones, aren't bulletproof, and skip the plan, implementation,
109
+ and review process. Bring what the spike taught you back into the
110
+ conversation.
111
+
112
+ ## Play It Back
113
+
114
+ Play back as you go. As soon as you understand one part well enough to
115
+ describe it (what it's for and who it serves, say, or how one piece
116
+ behaves), describe that part back in about 200-300 words, then return to
117
+ questions about the next part. Playback and questions alternate through
118
+ the whole conversation; the last chunk covers whatever is left.
119
+
120
+ Mark anything you're guessing as your guess; only what they said goes in
121
+ as theirs. End each chunk by asking what's wrong or missing.
122
+
123
+ Before you send a chunk, check it: does it describe something they'll
124
+ look at, like a page, a screen, a schedule, or a printout? If so, and
125
+ they haven't seen the visual companion offer yet, send the offer instead
126
+ (its own message, below) and hold the chunk for the next message. Once
127
+ they've accepted, put a mockup next to the description.
128
+
129
+ ## Size the Work
130
+
131
+ Once you understand what they want, pick a size and say it in plain
132
+ words. They can override it.
133
+
134
+ | Size | The full description | Then |
135
+ |------|----------------------|------|
136
+ | A quick, clear task | the request itself | do it |
137
+ | A small change | in chat | build it through the normal workflow |
138
+ | A project with a written design | a written design document | a full plan (for software: superpowers:writing-plans) |
139
+
140
+ If it grows mid-task, stop, say so, and step up a size.
141
+
142
+ If this is really several independent projects, say so, agree on an
143
+ order, and brainstorm them one at a time.
144
+
145
+ ## The Written Design
146
+
147
+ For a project, write a plain document a talented builder in the domain
148
+ could plan from without going back to your human partner. Cover:
149
+
150
+ - intent and the why
151
+ - goals, non-goals, anti-goals
152
+ - constraints
153
+ - the parts of the how they decided, as they decided them
154
+ - what's left to the builder
155
+
156
+ **Where it goes:** in a software repo,
157
+ `docs/superpowers/specs/YYYY-MM-DD-<topic>-design.md`, committed.
158
+ Otherwise, ask. Your human partner's preferences override both.
159
+
160
+ **Builder check:** dispatch a fresh subagent with
161
+ `builder-check-prompt.md` in this directory. When you tell your human
162
+ partner you're writing it up, say a reviewer will read it first and you
163
+ may come back once with a few questions. Don't hand over the document
164
+ until the check is back. Sort what the builder asks into three piles:
165
+
166
+ - **Answered already** by the conversation or the project: put the answer
167
+ in the document.
168
+ - **Minor:** a sensible builder could settle it without changing what gets
169
+ built. Settle it yourself and mark it in the document as your call.
170
+ - **Theirs:** only your human partner can answer it, and the answer changes
171
+ what gets built.
172
+
173
+ Bring the "theirs" pile in one message, most important first. Update the
174
+ document with their answers, then hand it over with a short list of the
175
+ calls you made so they can check those while reading. That's the only
176
+ round of questions the check produces. Without a subagent tool, read the
177
+ document as that builder yourself.
178
+
179
+ <HARD-GATE>
180
+ Nothing gets built until your human partner approves the full
181
+ description: in chat for a small change, the document for a project.
182
+ Building includes writing product code, scaffolding, installing
183
+ dependencies, creating projects, and invoking an implementation skill.
184
+ Reading and exploring are fine.
185
+
186
+ Two exceptions. If they opted out of the questions, the skill is done
187
+ and the gate goes with it. A spike they said yes to may be built; it
188
+ stays labeled throwaway, and keeping what it produced is a new request
189
+ that comes back through this gate.
190
+
191
+ After a project's document is approved, the next step is the plan. For
192
+ software, invoke superpowers:writing-plans and no other skill.
193
+ </HARD-GATE>
194
+
195
+ ## Red Flags
196
+
197
+ | Thought | Reality |
198
+ |---------|---------|
199
+ | "I'll offer options to save them effort" | Options steer. Ask them to describe it first. |
200
+ | "I'll fill in sensible defaults" | Good. Say them out loud. A default they never heard is one they couldn't reject. |
201
+ | "I should explain the process first" | Ask your question. The process shows itself. |
202
+ | "They said 'sounds good' to the idea" | Approval covers what you showed them. A description you haven't written isn't approved. |
203
+ | "The spike works, I'll keep building on it" | Keeping it is a new request. Back through the gate. |
204
+
205
+ ## Visual Companion
206
+
207
+ A browser tab for showing mockups, diagrams, and prototypes. It's a
208
+ tool, not a mode: accepting it doesn't send every question to the
209
+ browser.
210
+
211
+ **Offer it just-in-time.** Offer it the first time one of the moments
212
+ above comes up, never upfront. The offer is its own message with nothing
213
+ else in it:
214
+
215
+ > "This might be easier if I show you. Want me to open a browser tab with some mockups?"
216
+
217
+ If they decline, stay in text and don't offer again unless they raise it.
218
+
219
+ **Per question, ask: would they understand this better by seeing it?**
220
+ Mockups, layouts, diagrams, and side-by-side designs go in the browser.
221
+ Requirements, scope, tradeoffs, and conceptual choices stay in text. A
222
+ question about a UI topic isn't automatically a visual question.
223
+
224
+ If they accept, read `visual-companion.md` in this directory before
225
+ starting the server.
@@ -0,0 +1,23 @@
1
+ # Builder Check Prompt
2
+
3
+ Dispatch a fresh general-purpose subagent with this prompt once the
4
+ written design exists. Fill in the domain and the document path.
5
+
6
+ ```
7
+ You are a talented [DOMAIN, e.g. "software engineer", "event planner",
8
+ "bakery consultant"]. You've been handed a design document and asked to
9
+ put together a plan to build what it describes. You will not be able to
10
+ talk to the person who wrote it.
11
+
12
+ Read [DOCUMENT_PATH].
13
+
14
+ Report only the questions you'd still need answered before you could plan
15
+ this well: places where you'd have to guess and a wrong guess would
16
+ matter. For each, give the question and why the answer changes the plan.
17
+ Rank them by importance.
18
+
19
+ Skip anything the document explicitly leaves to the builder, and anything
20
+ you could reasonably decide yourself. Skip nitpicks about wording.
21
+
22
+ If nothing important is left, say "nothing important left".
23
+ ```
@@ -0,0 +1,213 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Superpowers Brainstorming</title>
6
+ <style>
7
+ /*
8
+ * BRAINSTORM COMPANION FRAME TEMPLATE
9
+ *
10
+ * This template provides a consistent frame with:
11
+ * - OS-aware light/dark theming
12
+ * - Header branding and connection status
13
+ * - Scrollable main content area
14
+ * - CSS helpers for common UI patterns
15
+ *
16
+ * Content is injected via placeholder comment in #frame-content.
17
+ */
18
+
19
+ * { box-sizing: border-box; margin: 0; padding: 0; }
20
+ html, body { height: 100%; overflow: hidden; }
21
+
22
+ /* ===== THEME VARIABLES ===== */
23
+ :root {
24
+ --bg-primary: #f5f5f7;
25
+ --bg-secondary: #ffffff;
26
+ --bg-tertiary: #e5e5e7;
27
+ --border: #d1d1d6;
28
+ --text-primary: #1d1d1f;
29
+ --text-secondary: #86868b;
30
+ --text-tertiary: #aeaeb2;
31
+ --accent: #0071e3;
32
+ --accent-hover: #0077ed;
33
+ --success: #34c759;
34
+ --warning: #ff9f0a;
35
+ --error: #ff3b30;
36
+ --selected-bg: #e8f4fd;
37
+ --selected-border: #0071e3;
38
+ }
39
+
40
+ @media (prefers-color-scheme: dark) {
41
+ :root {
42
+ --bg-primary: #1d1d1f;
43
+ --bg-secondary: #2d2d2f;
44
+ --bg-tertiary: #3d3d3f;
45
+ --border: #424245;
46
+ --text-primary: #f5f5f7;
47
+ --text-secondary: #86868b;
48
+ --text-tertiary: #636366;
49
+ --accent: #0a84ff;
50
+ --accent-hover: #409cff;
51
+ --selected-bg: rgba(10, 132, 255, 0.15);
52
+ --selected-border: #0a84ff;
53
+ }
54
+ }
55
+
56
+ body {
57
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
58
+ background: var(--bg-primary);
59
+ color: var(--text-primary);
60
+ display: flex;
61
+ flex-direction: column;
62
+ line-height: 1.5;
63
+ }
64
+
65
+ /* ===== FRAME STRUCTURE ===== */
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; }
72
+ }
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%; }
75
+
76
+ .main { flex: 1; overflow-y: auto; }
77
+ #frame-content { padding: 2rem; min-height: 100%; }
78
+
79
+ .header {
80
+ background: var(--bg-secondary);
81
+ border-bottom: 1px solid var(--border);
82
+ padding: 0.5rem 1.5rem;
83
+ flex-shrink: 0;
84
+ display: grid;
85
+ grid-template-columns: minmax(0, 1fr) auto;
86
+ align-items: center;
87
+ gap: 1rem;
88
+ min-height: 42px;
89
+ }
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 {
93
+ font-size: 0.75rem;
94
+ color: var(--text-secondary);
95
+ }
96
+ .header .selected-text {
97
+ color: var(--accent);
98
+ font-weight: 500;
99
+ }
100
+
101
+ /* ===== TYPOGRAPHY ===== */
102
+ h2 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; }
103
+ h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
104
+ .subtitle { color: var(--text-secondary); margin-bottom: 1.5rem; }
105
+ .section { margin-bottom: 2rem; }
106
+ .label { font-size: 0.7rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
107
+
108
+ /* ===== OPTIONS (for A/B/C choices) ===== */
109
+ .options { display: flex; flex-direction: column; gap: 0.75rem; }
110
+ .option {
111
+ background: var(--bg-secondary);
112
+ border: 2px solid var(--border);
113
+ border-radius: 12px;
114
+ padding: 1rem 1.25rem;
115
+ cursor: pointer;
116
+ transition: all 0.15s ease;
117
+ display: flex;
118
+ align-items: flex-start;
119
+ gap: 1rem;
120
+ }
121
+ .option:hover { border-color: var(--accent); }
122
+ .option.selected { background: var(--selected-bg); border-color: var(--selected-border); }
123
+ .option .letter {
124
+ background: var(--bg-tertiary);
125
+ color: var(--text-secondary);
126
+ width: 1.75rem; height: 1.75rem;
127
+ border-radius: 6px;
128
+ display: flex; align-items: center; justify-content: center;
129
+ font-weight: 600; font-size: 0.85rem; flex-shrink: 0;
130
+ }
131
+ .option.selected .letter { background: var(--accent); color: white; }
132
+ .option .content { flex: 1; }
133
+ .option .content h3 { font-size: 0.95rem; margin-bottom: 0.15rem; }
134
+ .option .content p { color: var(--text-secondary); font-size: 0.85rem; margin: 0; }
135
+
136
+ /* ===== CARDS (for showing designs/mockups) ===== */
137
+ .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
138
+ .card {
139
+ background: var(--bg-secondary);
140
+ border: 1px solid var(--border);
141
+ border-radius: 12px;
142
+ overflow: hidden;
143
+ cursor: pointer;
144
+ transition: all 0.15s ease;
145
+ }
146
+ .card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
147
+ .card.selected { border-color: var(--selected-border); border-width: 2px; }
148
+ .card-image { background: var(--bg-tertiary); aspect-ratio: 16/10; display: flex; align-items: center; justify-content: center; }
149
+ .card-body { padding: 1rem; }
150
+ .card-body h3 { margin-bottom: 0.25rem; }
151
+ .card-body p { color: var(--text-secondary); font-size: 0.85rem; }
152
+
153
+ /* ===== MOCKUP CONTAINER ===== */
154
+ .mockup {
155
+ background: var(--bg-secondary);
156
+ border: 1px solid var(--border);
157
+ border-radius: 12px;
158
+ overflow: hidden;
159
+ margin-bottom: 1.5rem;
160
+ }
161
+ .mockup-header {
162
+ background: var(--bg-tertiary);
163
+ padding: 0.5rem 1rem;
164
+ font-size: 0.75rem;
165
+ color: var(--text-secondary);
166
+ border-bottom: 1px solid var(--border);
167
+ }
168
+ .mockup-body { padding: 1.5rem; }
169
+
170
+ /* ===== SPLIT VIEW (side-by-side comparison) ===== */
171
+ .split { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
172
+ @media (max-width: 700px) { .split { grid-template-columns: 1fr; } }
173
+
174
+ /* ===== PROS/CONS ===== */
175
+ .pros-cons { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem 0; }
176
+ .pros, .cons { background: var(--bg-secondary); border-radius: 8px; padding: 1rem; }
177
+ .pros h4 { color: var(--success); font-size: 0.85rem; margin-bottom: 0.5rem; }
178
+ .cons h4 { color: var(--error); font-size: 0.85rem; margin-bottom: 0.5rem; }
179
+ .pros ul, .cons ul { margin-left: 1.25rem; font-size: 0.85rem; color: var(--text-secondary); }
180
+ .pros li, .cons li { margin-bottom: 0.25rem; }
181
+
182
+ /* ===== PLACEHOLDER (for mockup areas) ===== */
183
+ .placeholder {
184
+ background: var(--bg-tertiary);
185
+ border: 2px dashed var(--border);
186
+ border-radius: 8px;
187
+ padding: 2rem;
188
+ text-align: center;
189
+ color: var(--text-tertiary);
190
+ }
191
+
192
+ /* ===== INLINE MOCKUP ELEMENTS ===== */
193
+ .mock-nav { background: var(--accent); color: white; padding: 0.75rem 1rem; display: flex; gap: 1.5rem; font-size: 0.9rem; }
194
+ .mock-sidebar { background: var(--bg-tertiary); padding: 1rem; min-width: 180px; }
195
+ .mock-content { padding: 1.5rem; flex: 1; }
196
+ .mock-button { background: var(--accent); color: white; border: none; padding: 0.5rem 1rem; border-radius: 6px; font-size: 0.85rem; }
197
+ .mock-input { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem; width: 100%; }
198
+ </style>
199
+ </head>
200
+ <body>
201
+ <div class="header">
202
+ <!-- BRANDING -->
203
+ <div class="status">Connecting…</div>
204
+ </div>
205
+
206
+ <div class="main">
207
+ <div id="frame-content">
208
+ <!-- CONTENT -->
209
+ </div>
210
+ </div>
211
+
212
+ </body>
213
+ </html>
@@ -0,0 +1,167 @@
1
+ (function() {
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
+
17
+ let ws = null;
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
+ }
76
+
77
+ function connect() {
78
+ if (reconnectTimer) { clearTimeout(reconnectTimer); reconnectTimer = null; }
79
+ setStatus(everConnected ? 'reconnecting' : 'connecting');
80
+ ws = new WebSocket(websocketUrl());
81
+
82
+ ws.onopen = () => {
83
+ const recovered = tombstoneShown;
84
+ everConnected = true;
85
+ disconnectedSince = null;
86
+ reconnectDelay = MIN_RECONNECT_MS;
87
+ tombstoneShown = false;
88
+ setStatus('connected');
89
+ eventQueue.forEach(e => ws.send(JSON.stringify(e)));
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();
95
+ };
96
+
97
+ ws.onmessage = (msg) => {
98
+ let data;
99
+ try { data = JSON.parse(msg.data); } catch (e) { return; }
100
+ if (data.type === 'reload') window.location.reload();
101
+ };
102
+
103
+ ws.onclose = () => {
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);
114
+ };
115
+
116
+ // Let onclose own reconnection so we don't schedule it twice.
117
+ ws.onerror = () => { try { ws.close(); } catch (e) {} };
118
+ }
119
+
120
+ function sendEvent(event) {
121
+ event.timestamp = Date.now();
122
+ if (ws && ws.readyState === WebSocket.OPEN) {
123
+ ws.send(JSON.stringify(event));
124
+ } else {
125
+ eventQueue.push(event);
126
+ }
127
+ }
128
+
129
+ // Capture clicks on choice elements
130
+ document.addEventListener('click', (e) => {
131
+ const target = e.target.closest('[data-choice]');
132
+ if (!target) return;
133
+
134
+ sendEvent({
135
+ type: 'click',
136
+ text: target.textContent.trim(),
137
+ choice: target.dataset.choice,
138
+ id: target.id || null
139
+ });
140
+
141
+ });
142
+
143
+ // Frame UI: selection tracking
144
+ window.selectedChoice = null;
145
+
146
+ window.toggleSelect = function(el) {
147
+ const container = el.closest('.options') || el.closest('.cards');
148
+ const multi = container && container.dataset.multiselect !== undefined;
149
+ if (container && !multi) {
150
+ container.querySelectorAll('.option, .card').forEach(o => o.classList.remove('selected'));
151
+ }
152
+ if (multi) {
153
+ el.classList.toggle('selected');
154
+ } else {
155
+ el.classList.add('selected');
156
+ }
157
+ window.selectedChoice = el.dataset.choice;
158
+ };
159
+
160
+ // Expose API for explicit use
161
+ window.brainstorm = {
162
+ send: sendEvent,
163
+ choice: (value, metadata = {}) => sendEvent({ type: 'choice', value, ...metadata })
164
+ };
165
+
166
+ connect();
167
+ })();