workerssuper 5.0.4
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.
- package/.claude-plugin/marketplace.json +20 -0
- package/.claude-plugin/plugin.json +13 -0
- package/.codex/INSTALL.md +67 -0
- package/.cursor-plugin/plugin.json +18 -0
- package/.gitattributes +18 -0
- package/.github/FUNDING.yml +3 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +52 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +34 -0
- package/.github/ISSUE_TEMPLATE/platform_support.md +23 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +87 -0
- package/.opencode/INSTALL.md +83 -0
- package/.opencode/plugins/superpowers.js +107 -0
- package/CHANGELOG.md +13 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/GEMINI.md +2 -0
- package/LICENSE +21 -0
- package/README.md +187 -0
- package/RELEASE-NOTES.md +1057 -0
- package/agents/code-reviewer.md +48 -0
- package/commands/brainstorm.md +5 -0
- package/commands/execute-plan.md +5 -0
- package/commands/write-plan.md +5 -0
- package/docs/README.codex.md +126 -0
- package/docs/README.opencode.md +130 -0
- package/docs/plans/2025-11-22-opencode-support-design.md +294 -0
- package/docs/plans/2025-11-22-opencode-support-implementation.md +1095 -0
- package/docs/plans/2025-11-28-skills-improvements-from-user-feedback.md +711 -0
- package/docs/plans/2026-01-17-visual-brainstorming.md +571 -0
- package/docs/superpowers/plans/2026-01-22-document-review-system.md +301 -0
- package/docs/superpowers/plans/2026-02-19-visual-brainstorming-refactor.md +523 -0
- package/docs/superpowers/plans/2026-03-11-zero-dep-brainstorm-server.md +479 -0
- package/docs/superpowers/specs/2026-01-22-document-review-system-design.md +136 -0
- package/docs/superpowers/specs/2026-02-19-visual-brainstorming-refactor-design.md +162 -0
- package/docs/superpowers/specs/2026-03-11-zero-dep-brainstorm-server-design.md +118 -0
- package/docs/testing.md +303 -0
- package/docs/windows/polyglot-hooks.md +212 -0
- package/gemini-extension.json +6 -0
- package/hooks/hooks-cursor.json +10 -0
- package/hooks/hooks.json +16 -0
- package/hooks/run-hook.cmd +46 -0
- package/hooks/session-start +57 -0
- package/package.json +5 -0
- package/skills/brainstorming/SKILL.md +164 -0
- package/skills/brainstorming/scripts/frame-template.html +214 -0
- package/skills/brainstorming/scripts/helper.js +88 -0
- package/skills/brainstorming/scripts/server.cjs +338 -0
- package/skills/brainstorming/scripts/start-server.sh +153 -0
- package/skills/brainstorming/scripts/stop-server.sh +55 -0
- package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
- package/skills/brainstorming/visual-companion.md +286 -0
- package/skills/dispatching-parallel-agents/SKILL.md +182 -0
- package/skills/executing-plans/SKILL.md +70 -0
- package/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/skills/receiving-code-review/SKILL.md +213 -0
- package/skills/requesting-code-review/SKILL.md +105 -0
- package/skills/requesting-code-review/code-reviewer.md +146 -0
- package/skills/subagent-driven-development/SKILL.md +277 -0
- package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +26 -0
- package/skills/subagent-driven-development/implementer-prompt.md +113 -0
- package/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/skills/systematic-debugging/CREATION-LOG.md +119 -0
- package/skills/systematic-debugging/SKILL.md +296 -0
- package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/skills/systematic-debugging/find-polluter.sh +63 -0
- package/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/skills/systematic-debugging/test-academic.md +14 -0
- package/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/skills/test-driven-development/SKILL.md +371 -0
- package/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/skills/using-git-worktrees/SKILL.md +218 -0
- package/skills/using-superpowers/SKILL.md +115 -0
- package/skills/using-superpowers/references/codex-tools.md +25 -0
- package/skills/using-superpowers/references/gemini-tools.md +33 -0
- package/skills/verification-before-completion/SKILL.md +139 -0
- package/skills/writing-plans/SKILL.md +145 -0
- package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
- package/skills/writing-skills/SKILL.md +655 -0
- package/skills/writing-skills/anthropic-best-practices.md +1150 -0
- package/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
- package/skills/writing-skills/graphviz-conventions.dot +172 -0
- package/skills/writing-skills/persuasion-principles.md +187 -0
- package/skills/writing-skills/render-graphs.js +168 -0
- package/skills/writing-skills/testing-skills-with-subagents.md +384 -0
- package/tests/brainstorm-server/package-lock.json +36 -0
- package/tests/brainstorm-server/package.json +10 -0
- package/tests/brainstorm-server/server.test.js +424 -0
- package/tests/brainstorm-server/windows-lifecycle.test.sh +351 -0
- package/tests/brainstorm-server/ws-protocol.test.js +392 -0
- package/tests/claude-code/README.md +158 -0
- package/tests/claude-code/analyze-token-usage.py +168 -0
- package/tests/claude-code/run-skill-tests.sh +187 -0
- package/tests/claude-code/test-document-review-system.sh +177 -0
- package/tests/claude-code/test-helpers.sh +202 -0
- package/tests/claude-code/test-subagent-driven-development-integration.sh +314 -0
- package/tests/claude-code/test-subagent-driven-development.sh +165 -0
- package/tests/explicit-skill-requests/prompts/action-oriented.txt +3 -0
- package/tests/explicit-skill-requests/prompts/after-planning-flow.txt +17 -0
- package/tests/explicit-skill-requests/prompts/claude-suggested-it.txt +11 -0
- package/tests/explicit-skill-requests/prompts/i-know-what-sdd-means.txt +8 -0
- package/tests/explicit-skill-requests/prompts/mid-conversation-execute-plan.txt +3 -0
- package/tests/explicit-skill-requests/prompts/please-use-brainstorming.txt +1 -0
- package/tests/explicit-skill-requests/prompts/skip-formalities.txt +3 -0
- package/tests/explicit-skill-requests/prompts/subagent-driven-development-please.txt +1 -0
- package/tests/explicit-skill-requests/prompts/use-systematic-debugging.txt +1 -0
- package/tests/explicit-skill-requests/run-all.sh +70 -0
- package/tests/explicit-skill-requests/run-claude-describes-sdd.sh +100 -0
- package/tests/explicit-skill-requests/run-extended-multiturn-test.sh +113 -0
- package/tests/explicit-skill-requests/run-haiku-test.sh +144 -0
- package/tests/explicit-skill-requests/run-multiturn-test.sh +143 -0
- package/tests/explicit-skill-requests/run-test.sh +136 -0
- package/tests/opencode/run-tests.sh +163 -0
- package/tests/opencode/setup.sh +73 -0
- package/tests/opencode/test-plugin-loading.sh +72 -0
- package/tests/opencode/test-priority.sh +198 -0
- package/tests/opencode/test-tools.sh +104 -0
- package/tests/skill-triggering/prompts/dispatching-parallel-agents.txt +8 -0
- package/tests/skill-triggering/prompts/executing-plans.txt +1 -0
- package/tests/skill-triggering/prompts/requesting-code-review.txt +3 -0
- package/tests/skill-triggering/prompts/systematic-debugging.txt +11 -0
- package/tests/skill-triggering/prompts/test-driven-development.txt +7 -0
- package/tests/skill-triggering/prompts/writing-plans.txt +10 -0
- package/tests/skill-triggering/run-all.sh +60 -0
- package/tests/skill-triggering/run-test.sh +88 -0
- package/tests/subagent-driven-dev/go-fractals/design.md +81 -0
- package/tests/subagent-driven-dev/go-fractals/plan.md +172 -0
- package/tests/subagent-driven-dev/go-fractals/scaffold.sh +45 -0
- package/tests/subagent-driven-dev/run-test.sh +106 -0
- package/tests/subagent-driven-dev/svelte-todo/design.md +70 -0
- package/tests/subagent-driven-dev/svelte-todo/plan.md +222 -0
- package/tests/subagent-driven-dev/svelte-todo/scaffold.sh +46 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
# Zero-Dependency Brainstorm Server Implementation Plan
|
|
2
|
+
|
|
3
|
+
> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
4
|
+
|
|
5
|
+
**Goal:** Replace the brainstorm server's vendored node_modules with a single zero-dependency `server.js` using Node built-ins.
|
|
6
|
+
|
|
7
|
+
**Architecture:** Single file with WebSocket protocol (RFC 6455 text frames), HTTP server (`http` module), and file watching (`fs.watch`). Exports protocol functions for unit testing when required as a module.
|
|
8
|
+
|
|
9
|
+
**Tech Stack:** Node.js built-ins only: `http`, `crypto`, `fs`, `path`
|
|
10
|
+
|
|
11
|
+
**Spec:** `docs/superpowers/specs/2026-03-11-zero-dep-brainstorm-server-design.md`
|
|
12
|
+
|
|
13
|
+
**Existing tests:** `tests/brainstorm-server/ws-protocol.test.js` (unit), `tests/brainstorm-server/server.test.js` (integration)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## File Map
|
|
18
|
+
|
|
19
|
+
- **Create:** `skills/brainstorming/scripts/server.js` — the zero-dep replacement
|
|
20
|
+
- **Modify:** `skills/brainstorming/scripts/start-server.sh:94,100` — change `index.js` to `server.js`
|
|
21
|
+
- **Modify:** `.gitignore:6` — remove the `!skills/brainstorming/scripts/node_modules/` exception
|
|
22
|
+
- **Delete:** `skills/brainstorming/scripts/index.js`
|
|
23
|
+
- **Delete:** `skills/brainstorming/scripts/package.json`
|
|
24
|
+
- **Delete:** `skills/brainstorming/scripts/package-lock.json`
|
|
25
|
+
- **Delete:** `skills/brainstorming/scripts/node_modules/` (714 files)
|
|
26
|
+
- **No changes:** `skills/brainstorming/scripts/helper.js`, `skills/brainstorming/scripts/frame-template.html`, `skills/brainstorming/scripts/stop-server.sh`
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Chunk 1: WebSocket Protocol Layer
|
|
31
|
+
|
|
32
|
+
### Task 1: Implement WebSocket protocol exports
|
|
33
|
+
|
|
34
|
+
**Files:**
|
|
35
|
+
- Create: `skills/brainstorming/scripts/server.js`
|
|
36
|
+
- Test: `tests/brainstorm-server/ws-protocol.test.js` (already exists)
|
|
37
|
+
|
|
38
|
+
- [ ] **Step 1: Create server.js with OPCODES constant and computeAcceptKey**
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
const crypto = require('crypto');
|
|
42
|
+
|
|
43
|
+
const OPCODES = { TEXT: 0x01, CLOSE: 0x08, PING: 0x09, PONG: 0x0A };
|
|
44
|
+
const WS_MAGIC = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11';
|
|
45
|
+
|
|
46
|
+
function computeAcceptKey(clientKey) {
|
|
47
|
+
return crypto.createHash('sha1').update(clientKey + WS_MAGIC).digest('base64');
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- [ ] **Step 2: Implement encodeFrame**
|
|
52
|
+
|
|
53
|
+
Server frames are never masked. Three length encodings:
|
|
54
|
+
- payload < 126: 2-byte header (FIN+opcode, length)
|
|
55
|
+
- 126-65535: 4-byte header (FIN+opcode, 126, 16-bit length)
|
|
56
|
+
- > 65535: 10-byte header (FIN+opcode, 127, 64-bit length)
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
function encodeFrame(opcode, payload) {
|
|
60
|
+
const fin = 0x80;
|
|
61
|
+
const len = payload.length;
|
|
62
|
+
let header;
|
|
63
|
+
|
|
64
|
+
if (len < 126) {
|
|
65
|
+
header = Buffer.alloc(2);
|
|
66
|
+
header[0] = fin | opcode;
|
|
67
|
+
header[1] = len;
|
|
68
|
+
} else if (len < 65536) {
|
|
69
|
+
header = Buffer.alloc(4);
|
|
70
|
+
header[0] = fin | opcode;
|
|
71
|
+
header[1] = 126;
|
|
72
|
+
header.writeUInt16BE(len, 2);
|
|
73
|
+
} else {
|
|
74
|
+
header = Buffer.alloc(10);
|
|
75
|
+
header[0] = fin | opcode;
|
|
76
|
+
header[1] = 127;
|
|
77
|
+
header.writeBigUInt64BE(BigInt(len), 2);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Buffer.concat([header, payload]);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- [ ] **Step 3: Implement decodeFrame**
|
|
85
|
+
|
|
86
|
+
Client frames are always masked. Returns `{ opcode, payload, bytesConsumed }` or `null` for incomplete. Throws on unmasked frames.
|
|
87
|
+
|
|
88
|
+
```js
|
|
89
|
+
function decodeFrame(buffer) {
|
|
90
|
+
if (buffer.length < 2) return null;
|
|
91
|
+
|
|
92
|
+
const firstByte = buffer[0];
|
|
93
|
+
const secondByte = buffer[1];
|
|
94
|
+
const opcode = firstByte & 0x0F;
|
|
95
|
+
const masked = (secondByte & 0x80) !== 0;
|
|
96
|
+
let payloadLen = secondByte & 0x7F;
|
|
97
|
+
let offset = 2;
|
|
98
|
+
|
|
99
|
+
if (!masked) throw new Error('Client frames must be masked');
|
|
100
|
+
|
|
101
|
+
if (payloadLen === 126) {
|
|
102
|
+
if (buffer.length < 4) return null;
|
|
103
|
+
payloadLen = buffer.readUInt16BE(2);
|
|
104
|
+
offset = 4;
|
|
105
|
+
} else if (payloadLen === 127) {
|
|
106
|
+
if (buffer.length < 10) return null;
|
|
107
|
+
payloadLen = Number(buffer.readBigUInt64BE(2));
|
|
108
|
+
offset = 10;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const maskOffset = offset;
|
|
112
|
+
const dataOffset = offset + 4;
|
|
113
|
+
const totalLen = dataOffset + payloadLen;
|
|
114
|
+
if (buffer.length < totalLen) return null;
|
|
115
|
+
|
|
116
|
+
const mask = buffer.slice(maskOffset, dataOffset);
|
|
117
|
+
const data = Buffer.alloc(payloadLen);
|
|
118
|
+
for (let i = 0; i < payloadLen; i++) {
|
|
119
|
+
data[i] = buffer[dataOffset + i] ^ mask[i % 4];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return { opcode, payload: data, bytesConsumed: totalLen };
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- [ ] **Step 4: Add module exports at the bottom of the file**
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
module.exports = { computeAcceptKey, encodeFrame, decodeFrame, OPCODES };
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
- [ ] **Step 5: Run unit tests**
|
|
133
|
+
|
|
134
|
+
Run: `cd tests/brainstorm-server && node ws-protocol.test.js`
|
|
135
|
+
Expected: All tests pass (handshake, encoding, decoding, boundaries, edge cases)
|
|
136
|
+
|
|
137
|
+
- [ ] **Step 6: Commit**
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
git add skills/brainstorming/scripts/server.js
|
|
141
|
+
git commit -m "Add WebSocket protocol layer for zero-dep brainstorm server"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Chunk 2: HTTP Server and Application Logic
|
|
147
|
+
|
|
148
|
+
### Task 2: Add HTTP server, file watching, and WebSocket connection handling
|
|
149
|
+
|
|
150
|
+
**Files:**
|
|
151
|
+
- Modify: `skills/brainstorming/scripts/server.js`
|
|
152
|
+
- Test: `tests/brainstorm-server/server.test.js` (already exists)
|
|
153
|
+
|
|
154
|
+
- [ ] **Step 1: Add configuration and constants at top of server.js (after requires)**
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
const http = require('http');
|
|
158
|
+
const fs = require('fs');
|
|
159
|
+
const path = require('path');
|
|
160
|
+
|
|
161
|
+
const PORT = process.env.BRAINSTORM_PORT || (49152 + Math.floor(Math.random() * 16383));
|
|
162
|
+
const HOST = process.env.BRAINSTORM_HOST || '127.0.0.1';
|
|
163
|
+
const URL_HOST = process.env.BRAINSTORM_URL_HOST || (HOST === '127.0.0.1' ? 'localhost' : HOST);
|
|
164
|
+
const SCREEN_DIR = process.env.BRAINSTORM_DIR || '/tmp/brainstorm';
|
|
165
|
+
|
|
166
|
+
const MIME_TYPES = {
|
|
167
|
+
'.html': 'text/html', '.css': 'text/css', '.js': 'application/javascript',
|
|
168
|
+
'.json': 'application/json', '.png': 'image/png', '.jpg': 'image/jpeg',
|
|
169
|
+
'.jpeg': 'image/jpeg', '.gif': 'image/gif', '.svg': 'image/svg+xml'
|
|
170
|
+
};
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- [ ] **Step 2: Add WAITING_PAGE, template loading at module scope, and helper functions**
|
|
174
|
+
|
|
175
|
+
Load `frameTemplate` and `helperInjection` at module scope so they're accessible to `wrapInFrame` and `handleRequest`. They only read files from `__dirname` (the scripts directory), which is valid whether the module is required or run directly.
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
const WAITING_PAGE = `<!DOCTYPE html>
|
|
179
|
+
<html>
|
|
180
|
+
<head><title>Brainstorm Companion</title>
|
|
181
|
+
<style>body { font-family: system-ui, sans-serif; padding: 2rem; max-width: 800px; margin: 0 auto; }
|
|
182
|
+
h1 { color: #333; } p { color: #666; }</style>
|
|
183
|
+
</head>
|
|
184
|
+
<body><h1>Brainstorm Companion</h1>
|
|
185
|
+
<p>Waiting for Claude to push a screen...</p></body></html>`;
|
|
186
|
+
|
|
187
|
+
const frameTemplate = fs.readFileSync(path.join(__dirname, 'frame-template.html'), 'utf-8');
|
|
188
|
+
const helperScript = fs.readFileSync(path.join(__dirname, 'helper.js'), 'utf-8');
|
|
189
|
+
const helperInjection = '<script>\n' + helperScript + '\n</script>';
|
|
190
|
+
|
|
191
|
+
function isFullDocument(html) {
|
|
192
|
+
const trimmed = html.trimStart().toLowerCase();
|
|
193
|
+
return trimmed.startsWith('<!doctype') || trimmed.startsWith('<html');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function wrapInFrame(content) {
|
|
197
|
+
return frameTemplate.replace('<!-- CONTENT -->', content);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function getNewestScreen() {
|
|
201
|
+
const files = fs.readdirSync(SCREEN_DIR)
|
|
202
|
+
.filter(f => f.endsWith('.html'))
|
|
203
|
+
.map(f => {
|
|
204
|
+
const fp = path.join(SCREEN_DIR, f);
|
|
205
|
+
return { path: fp, mtime: fs.statSync(fp).mtime.getTime() };
|
|
206
|
+
})
|
|
207
|
+
.sort((a, b) => b.mtime - a.mtime);
|
|
208
|
+
return files.length > 0 ? files[0].path : null;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- [ ] **Step 3: Add HTTP request handler**
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
function handleRequest(req, res) {
|
|
216
|
+
if (req.method === 'GET' && req.url === '/') {
|
|
217
|
+
const screenFile = getNewestScreen();
|
|
218
|
+
let html = screenFile
|
|
219
|
+
? (raw => isFullDocument(raw) ? raw : wrapInFrame(raw))(fs.readFileSync(screenFile, 'utf-8'))
|
|
220
|
+
: WAITING_PAGE;
|
|
221
|
+
|
|
222
|
+
if (html.includes('</body>')) {
|
|
223
|
+
html = html.replace('</body>', helperInjection + '\n</body>');
|
|
224
|
+
} else {
|
|
225
|
+
html += helperInjection;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
229
|
+
res.end(html);
|
|
230
|
+
} else if (req.method === 'GET' && req.url.startsWith('/files/')) {
|
|
231
|
+
const fileName = req.url.slice(7); // strip '/files/'
|
|
232
|
+
const filePath = path.join(SCREEN_DIR, path.basename(fileName));
|
|
233
|
+
if (!fs.existsSync(filePath)) {
|
|
234
|
+
res.writeHead(404);
|
|
235
|
+
res.end('Not found');
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
239
|
+
const contentType = MIME_TYPES[ext] || 'application/octet-stream';
|
|
240
|
+
res.writeHead(200, { 'Content-Type': contentType });
|
|
241
|
+
res.end(fs.readFileSync(filePath));
|
|
242
|
+
} else {
|
|
243
|
+
res.writeHead(404);
|
|
244
|
+
res.end('Not found');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- [ ] **Step 4: Add WebSocket connection handling**
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
const clients = new Set();
|
|
253
|
+
|
|
254
|
+
function handleUpgrade(req, socket) {
|
|
255
|
+
const key = req.headers['sec-websocket-key'];
|
|
256
|
+
if (!key) { socket.destroy(); return; }
|
|
257
|
+
|
|
258
|
+
const accept = computeAcceptKey(key);
|
|
259
|
+
socket.write(
|
|
260
|
+
'HTTP/1.1 101 Switching Protocols\r\n' +
|
|
261
|
+
'Upgrade: websocket\r\n' +
|
|
262
|
+
'Connection: Upgrade\r\n' +
|
|
263
|
+
'Sec-WebSocket-Accept: ' + accept + '\r\n\r\n'
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
let buffer = Buffer.alloc(0);
|
|
267
|
+
clients.add(socket);
|
|
268
|
+
|
|
269
|
+
socket.on('data', (chunk) => {
|
|
270
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
271
|
+
while (buffer.length > 0) {
|
|
272
|
+
let result;
|
|
273
|
+
try {
|
|
274
|
+
result = decodeFrame(buffer);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
socket.end(encodeFrame(OPCODES.CLOSE, Buffer.alloc(0)));
|
|
277
|
+
clients.delete(socket);
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!result) break;
|
|
281
|
+
buffer = buffer.slice(result.bytesConsumed);
|
|
282
|
+
|
|
283
|
+
switch (result.opcode) {
|
|
284
|
+
case OPCODES.TEXT:
|
|
285
|
+
handleMessage(result.payload.toString());
|
|
286
|
+
break;
|
|
287
|
+
case OPCODES.CLOSE:
|
|
288
|
+
socket.end(encodeFrame(OPCODES.CLOSE, Buffer.alloc(0)));
|
|
289
|
+
clients.delete(socket);
|
|
290
|
+
return;
|
|
291
|
+
case OPCODES.PING:
|
|
292
|
+
socket.write(encodeFrame(OPCODES.PONG, result.payload));
|
|
293
|
+
break;
|
|
294
|
+
case OPCODES.PONG:
|
|
295
|
+
break;
|
|
296
|
+
default:
|
|
297
|
+
// Unsupported opcode — close with 1003
|
|
298
|
+
const closeBuf = Buffer.alloc(2);
|
|
299
|
+
closeBuf.writeUInt16BE(1003);
|
|
300
|
+
socket.end(encodeFrame(OPCODES.CLOSE, closeBuf));
|
|
301
|
+
clients.delete(socket);
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
socket.on('close', () => clients.delete(socket));
|
|
308
|
+
socket.on('error', () => clients.delete(socket));
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function handleMessage(text) {
|
|
312
|
+
let event;
|
|
313
|
+
try {
|
|
314
|
+
event = JSON.parse(text);
|
|
315
|
+
} catch (e) {
|
|
316
|
+
console.error('Failed to parse WebSocket message:', e.message);
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
console.log(JSON.stringify({ source: 'user-event', ...event }));
|
|
320
|
+
if (event.choice) {
|
|
321
|
+
const eventsFile = path.join(SCREEN_DIR, '.events');
|
|
322
|
+
fs.appendFileSync(eventsFile, JSON.stringify(event) + '\n');
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function broadcast(msg) {
|
|
327
|
+
const frame = encodeFrame(OPCODES.TEXT, Buffer.from(JSON.stringify(msg)));
|
|
328
|
+
for (const socket of clients) {
|
|
329
|
+
try { socket.write(frame); } catch (e) { clients.delete(socket); }
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
- [ ] **Step 5: Add debounce timer map**
|
|
335
|
+
|
|
336
|
+
```js
|
|
337
|
+
const debounceTimers = new Map();
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
File watching logic is inlined in `startServer` (Step 6) to keep watcher lifecycle together with server lifecycle and include an `error` handler per spec.
|
|
341
|
+
|
|
342
|
+
- [ ] **Step 6: Add startServer function and conditional main**
|
|
343
|
+
|
|
344
|
+
`frameTemplate` and `helperInjection` are already at module scope (Step 2). `startServer` just creates the screen dir, starts the HTTP server, watcher, and logs startup info.
|
|
345
|
+
|
|
346
|
+
```js
|
|
347
|
+
function startServer() {
|
|
348
|
+
if (!fs.existsSync(SCREEN_DIR)) fs.mkdirSync(SCREEN_DIR, { recursive: true });
|
|
349
|
+
|
|
350
|
+
const server = http.createServer(handleRequest);
|
|
351
|
+
server.on('upgrade', handleUpgrade);
|
|
352
|
+
|
|
353
|
+
const watcher = fs.watch(SCREEN_DIR, (eventType, filename) => {
|
|
354
|
+
if (!filename || !filename.endsWith('.html')) return;
|
|
355
|
+
if (debounceTimers.has(filename)) clearTimeout(debounceTimers.get(filename));
|
|
356
|
+
debounceTimers.set(filename, setTimeout(() => {
|
|
357
|
+
debounceTimers.delete(filename);
|
|
358
|
+
const filePath = path.join(SCREEN_DIR, filename);
|
|
359
|
+
if (eventType === 'rename' && fs.existsSync(filePath)) {
|
|
360
|
+
const eventsFile = path.join(SCREEN_DIR, '.events');
|
|
361
|
+
if (fs.existsSync(eventsFile)) fs.unlinkSync(eventsFile);
|
|
362
|
+
console.log(JSON.stringify({ type: 'screen-added', file: filePath }));
|
|
363
|
+
} else if (eventType === 'change') {
|
|
364
|
+
console.log(JSON.stringify({ type: 'screen-updated', file: filePath }));
|
|
365
|
+
}
|
|
366
|
+
broadcast({ type: 'reload' });
|
|
367
|
+
}, 100));
|
|
368
|
+
});
|
|
369
|
+
watcher.on('error', (err) => console.error('fs.watch error:', err.message));
|
|
370
|
+
|
|
371
|
+
server.listen(PORT, HOST, () => {
|
|
372
|
+
const info = JSON.stringify({
|
|
373
|
+
type: 'server-started', port: Number(PORT), host: HOST,
|
|
374
|
+
url_host: URL_HOST, url: 'http://' + URL_HOST + ':' + PORT,
|
|
375
|
+
screen_dir: SCREEN_DIR
|
|
376
|
+
});
|
|
377
|
+
console.log(info);
|
|
378
|
+
fs.writeFileSync(path.join(SCREEN_DIR, '.server-info'), info + '\n');
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (require.main === module) {
|
|
383
|
+
startServer();
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
- [ ] **Step 7: Run integration tests**
|
|
388
|
+
|
|
389
|
+
The test directory already has a `package.json` with `ws` as a dependency. Install it if needed, then run tests.
|
|
390
|
+
|
|
391
|
+
Run: `cd tests/brainstorm-server && npm install && node server.test.js`
|
|
392
|
+
Expected: All tests pass
|
|
393
|
+
|
|
394
|
+
- [ ] **Step 8: Commit**
|
|
395
|
+
|
|
396
|
+
```bash
|
|
397
|
+
git add skills/brainstorming/scripts/server.js
|
|
398
|
+
git commit -m "Add HTTP server, WebSocket handling, and file watching to server.js"
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## Chunk 3: Swap and Cleanup
|
|
404
|
+
|
|
405
|
+
### Task 3: Update start-server.sh and remove old files
|
|
406
|
+
|
|
407
|
+
**Files:**
|
|
408
|
+
- Modify: `skills/brainstorming/scripts/start-server.sh:94,100`
|
|
409
|
+
- Modify: `.gitignore:6`
|
|
410
|
+
- Delete: `skills/brainstorming/scripts/index.js`
|
|
411
|
+
- Delete: `skills/brainstorming/scripts/package.json`
|
|
412
|
+
- Delete: `skills/brainstorming/scripts/package-lock.json`
|
|
413
|
+
- Delete: `skills/brainstorming/scripts/node_modules/` (entire directory)
|
|
414
|
+
|
|
415
|
+
- [ ] **Step 1: Update start-server.sh — change `index.js` to `server.js`**
|
|
416
|
+
|
|
417
|
+
Two lines to change:
|
|
418
|
+
|
|
419
|
+
Line 94: `env BRAINSTORM_DIR="$SCREEN_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" node server.js`
|
|
420
|
+
|
|
421
|
+
Line 100: `nohup env BRAINSTORM_DIR="$SCREEN_DIR" BRAINSTORM_HOST="$BIND_HOST" BRAINSTORM_URL_HOST="$URL_HOST" node server.js > "$LOG_FILE" 2>&1 &`
|
|
422
|
+
|
|
423
|
+
- [ ] **Step 2: Remove the gitignore exception for node_modules**
|
|
424
|
+
|
|
425
|
+
In `.gitignore`, delete line 6: `!skills/brainstorming/scripts/node_modules/`
|
|
426
|
+
|
|
427
|
+
- [ ] **Step 3: Delete old files**
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
git rm skills/brainstorming/scripts/index.js
|
|
431
|
+
git rm skills/brainstorming/scripts/package.json
|
|
432
|
+
git rm skills/brainstorming/scripts/package-lock.json
|
|
433
|
+
git rm -r skills/brainstorming/scripts/node_modules/
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
- [ ] **Step 4: Run both test suites**
|
|
437
|
+
|
|
438
|
+
Run: `cd tests/brainstorm-server && node ws-protocol.test.js && node server.test.js`
|
|
439
|
+
Expected: All tests pass
|
|
440
|
+
|
|
441
|
+
- [ ] **Step 5: Commit**
|
|
442
|
+
|
|
443
|
+
```bash
|
|
444
|
+
git add skills/brainstorming/scripts/ .gitignore
|
|
445
|
+
git commit -m "Remove vendored node_modules, swap to zero-dep server.js"
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Task 4: Manual smoke test
|
|
449
|
+
|
|
450
|
+
- [ ] **Step 1: Start the server manually**
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
cd skills/brainstorming/scripts
|
|
454
|
+
BRAINSTORM_DIR=/tmp/brainstorm-smoke BRAINSTORM_PORT=9876 node server.js
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
Expected: `server-started` JSON printed with port 9876
|
|
458
|
+
|
|
459
|
+
- [ ] **Step 2: Open browser to http://localhost:9876**
|
|
460
|
+
|
|
461
|
+
Expected: Waiting page with "Waiting for Claude to push a screen..."
|
|
462
|
+
|
|
463
|
+
- [ ] **Step 3: Write an HTML file to the screen directory**
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
echo '<h2>Hello from smoke test</h2>' > /tmp/brainstorm-smoke/test.html
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
Expected: Browser reloads and shows "Hello from smoke test" wrapped in frame template
|
|
470
|
+
|
|
471
|
+
- [ ] **Step 4: Verify WebSocket works — check browser console**
|
|
472
|
+
|
|
473
|
+
Open browser dev tools. The WebSocket connection should show as connected (no errors in console). The frame template's status indicator should show "Connected".
|
|
474
|
+
|
|
475
|
+
- [ ] **Step 5: Stop server with Ctrl-C, clean up**
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
rm -rf /tmp/brainstorm-smoke
|
|
479
|
+
```
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Document Review System Design
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Add two new review stages to the superpowers workflow:
|
|
6
|
+
|
|
7
|
+
1. **Spec Document Review** - After brainstorming, before writing-plans
|
|
8
|
+
2. **Plan Document Review** - After writing-plans, before implementation
|
|
9
|
+
|
|
10
|
+
Both follow the iterative loop pattern used by implementation reviews.
|
|
11
|
+
|
|
12
|
+
## Spec Document Reviewer
|
|
13
|
+
|
|
14
|
+
**Purpose:** Verify the spec is complete, consistent, and ready for implementation planning.
|
|
15
|
+
|
|
16
|
+
**Location:** `skills/brainstorming/spec-document-reviewer-prompt.md`
|
|
17
|
+
|
|
18
|
+
**What it checks for:**
|
|
19
|
+
|
|
20
|
+
| Category | What to Look For |
|
|
21
|
+
|----------|------------------|
|
|
22
|
+
| Completeness | TODOs, placeholders, "TBD", incomplete sections |
|
|
23
|
+
| Coverage | Missing error handling, edge cases, integration points |
|
|
24
|
+
| Consistency | Internal contradictions, conflicting requirements |
|
|
25
|
+
| Clarity | Ambiguous requirements |
|
|
26
|
+
| YAGNI | Unrequested features, over-engineering |
|
|
27
|
+
|
|
28
|
+
**Output format:**
|
|
29
|
+
```
|
|
30
|
+
## Spec Review
|
|
31
|
+
|
|
32
|
+
**Status:** Approved | Issues Found
|
|
33
|
+
|
|
34
|
+
**Issues (if any):**
|
|
35
|
+
- [Section X]: [issue] - [why it matters]
|
|
36
|
+
|
|
37
|
+
**Recommendations (advisory):**
|
|
38
|
+
- [suggestions that don't block approval]
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**Review loop:** Issues found -> brainstorming agent fixes -> re-review -> repeat until approved.
|
|
42
|
+
|
|
43
|
+
**Dispatch mechanism:** Use the Task tool with `subagent_type: general-purpose`. The reviewer prompt template provides the full prompt. The brainstorming skill's controller dispatches the reviewer.
|
|
44
|
+
|
|
45
|
+
## Plan Document Reviewer
|
|
46
|
+
|
|
47
|
+
**Purpose:** Verify the plan is complete, matches the spec, and has proper task decomposition.
|
|
48
|
+
|
|
49
|
+
**Location:** `skills/writing-plans/plan-document-reviewer-prompt.md`
|
|
50
|
+
|
|
51
|
+
**What it checks for:**
|
|
52
|
+
|
|
53
|
+
| Category | What to Look For |
|
|
54
|
+
|----------|------------------|
|
|
55
|
+
| Completeness | TODOs, placeholders, incomplete tasks |
|
|
56
|
+
| Spec Alignment | Plan covers spec requirements, no scope creep |
|
|
57
|
+
| Task Decomposition | Tasks atomic, clear boundaries |
|
|
58
|
+
| Task Syntax | Checkbox syntax on tasks and steps |
|
|
59
|
+
| Chunk Size | Each chunk under 1000 lines |
|
|
60
|
+
|
|
61
|
+
**Chunk definition:** A chunk is a logical grouping of tasks within the plan document, delimited by `## Chunk N: <name>` headings. The writing-plans skill creates these boundaries based on logical phases (e.g., "Foundation", "Core Features", "Integration"). Each chunk should be self-contained enough to review independently.
|
|
62
|
+
|
|
63
|
+
**Spec alignment verification:** The reviewer receives both:
|
|
64
|
+
1. The plan document (or current chunk)
|
|
65
|
+
2. The path to the spec document for reference
|
|
66
|
+
|
|
67
|
+
The reviewer reads both and compares requirements coverage.
|
|
68
|
+
|
|
69
|
+
**Output format:** Same as spec reviewer, but scoped to the current chunk.
|
|
70
|
+
|
|
71
|
+
**Review process (chunk-by-chunk):**
|
|
72
|
+
1. Writing-plans creates chunk N
|
|
73
|
+
2. Controller dispatches plan-document-reviewer with chunk N content and spec path
|
|
74
|
+
3. Reviewer reads chunk and spec, returns verdict
|
|
75
|
+
4. If issues: writing-plans agent fixes chunk N, goto step 2
|
|
76
|
+
5. If approved: proceed to chunk N+1
|
|
77
|
+
6. Repeat until all chunks approved
|
|
78
|
+
|
|
79
|
+
**Dispatch mechanism:** Same as spec reviewer - Task tool with `subagent_type: general-purpose`.
|
|
80
|
+
|
|
81
|
+
## Updated Workflow
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
brainstorming -> spec -> SPEC REVIEW LOOP -> writing-plans -> plan -> PLAN REVIEW LOOP -> implementation
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Spec Review Loop:**
|
|
88
|
+
1. Spec complete
|
|
89
|
+
2. Dispatch reviewer
|
|
90
|
+
3. If issues: fix -> goto 2
|
|
91
|
+
4. If approved: proceed
|
|
92
|
+
|
|
93
|
+
**Plan Review Loop:**
|
|
94
|
+
1. Chunk N complete
|
|
95
|
+
2. Dispatch reviewer for chunk N
|
|
96
|
+
3. If issues: fix -> goto 2
|
|
97
|
+
4. If approved: next chunk or implementation
|
|
98
|
+
|
|
99
|
+
## Markdown Task Syntax
|
|
100
|
+
|
|
101
|
+
Tasks and steps use checkbox syntax:
|
|
102
|
+
|
|
103
|
+
```markdown
|
|
104
|
+
- [ ] ### Task 1: Name
|
|
105
|
+
|
|
106
|
+
- [ ] **Step 1:** Description
|
|
107
|
+
- File: path
|
|
108
|
+
- Command: cmd
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Error Handling
|
|
112
|
+
|
|
113
|
+
**Review loop termination:**
|
|
114
|
+
- No hard iteration limit - loops continue until reviewer approves
|
|
115
|
+
- If loop exceeds 5 iterations, the controller should surface this to the human for guidance
|
|
116
|
+
- The human can choose to: continue iterating, approve with known issues, or abort
|
|
117
|
+
|
|
118
|
+
**Disagreement handling:**
|
|
119
|
+
- Reviewers are advisory - they flag issues but don't block
|
|
120
|
+
- If the agent believes reviewer feedback is incorrect, it should explain why in its fix
|
|
121
|
+
- If disagreement persists after 3 iterations on the same issue, surface to human
|
|
122
|
+
|
|
123
|
+
**Malformed reviewer output:**
|
|
124
|
+
- Controller should validate reviewer output has required fields (Status, Issues if applicable)
|
|
125
|
+
- If malformed, re-dispatch reviewer with a note about expected format
|
|
126
|
+
- After 2 malformed responses, surface to human
|
|
127
|
+
|
|
128
|
+
## Files to Change
|
|
129
|
+
|
|
130
|
+
**New files:**
|
|
131
|
+
- `skills/brainstorming/spec-document-reviewer-prompt.md`
|
|
132
|
+
- `skills/writing-plans/plan-document-reviewer-prompt.md`
|
|
133
|
+
|
|
134
|
+
**Modified files:**
|
|
135
|
+
- `skills/brainstorming/SKILL.md` - add review loop after spec written
|
|
136
|
+
- `skills/writing-plans/SKILL.md` - add chunk-by-chunk review loop, update task syntax examples
|