Skip to content

synced the fork from the main repository - #1074

Closed
pakorn269 wants to merge 68 commits into
obra:mainfrom
pakorn269:main
Closed

pakorn269 wants to merge 68 commits into
obra:mainfrom
pakorn269:main

Conversation

@pakorn269

Copy link
Copy Markdown

What problem are you trying to solve?

What does this PR change?

Is this change appropriate for the core library?

What alternatives did you consider?

Does this PR contain multiple unrelated changes?

Existing PRs

  • I have reviewed all open AND closed PRs for duplicates or prior art
  • Related PRs:

Environment tested

Harness (e.g. Claude Code, Cursor) Harness version Model Model version/ID

Evaluation

  • What was the initial prompt you (or your human partner) used to start
    the session that led to this change?
  • How many eval sessions did you run AFTER making the change?
  • How did outcomes change compared to before the change?

Rigor

  • If this is a skills change: I used superpowers:writing-skills and
    completed adversarial pressure testing (paste results below)
  • This change was tested adversarially, not just on the happy path
  • I did not modify carefully-tuned content (Red Flags table,
    rationalizations, "human partner" language) without extensive evals
    showing the change is an improvement

Human review

  • A human has reviewed the COMPLETE proposed diff before submission

google-labs-jules Bot and others added 30 commits March 14, 2026 01:06
Refactored `handleUpgrade` in `skills/brainstorming/scripts/server.js` by
extracting the WebSocket communication and listener setup logic into a
new function `setupSocketCommunication`. This separates the HTTP
handshake from the data stream handling, improving readability and
maintainability.

Verified with unit tests in `tests/brainstorm-server/ws-protocol.test.js`.

Co-authored-by: pakorn269 <[email protected]>
Converted `getBootstrapContent` to an async function and replaced
synchronous `fs.readFileSync` with `fs.promises.readFile`. This prevents
blocking the Node.js event loop during plugin initialization and system
prompt transformation.

Changes:
- Updated `.opencode/plugins/superpowers.js`
- `getBootstrapContent` is now `async`
- Uses `await fs.promises.readFile` with `try-catch` for existence check
- Updated `experimental.chat.system.transform` to await bootstrap content

Co-authored-by: pakorn269 <[email protected]>
…dge cases

- Modified `skills/writing-skills/render-graphs.js` to export functions and support nameless digraphs and Windows line endings.
- Created `tests/writing-skills/render-graphs.test.js` with comprehensive test cases.
- Improved robustness of `extractGraphBody` by using `indexOf`/`lastIndexOf` for brace matching.
- Verified all tests pass in the sandbox environment.

Co-authored-by: pakorn269 <[email protected]>
- Replaced `fs.readFileSync` with `fs.promises.readFile` for root requests.
- Replaced `fs.readFileSync` with `fs.createReadStream` for static files.
- Refactored `getNewestScreen` to use asynchronous directory listing and stat calls.
- Added proper error handling for I/O operations and streams.
- Improved throughput from ~50 req/s to ~92 req/s in local benchmarks.

Co-authored-by: pakorn269 <[email protected]>
- Exported `wrapInFrame` and `isFullDocument` from `server.js` for testing.
- Created `tests/brainstorm-server/helpers.test.js` with comprehensive test cases.
- Fixed a bug in `wrapInFrame` where special characters like `$&` in the content were being misinterpreted by `String.prototype.replace`.
- Verified all tests pass.

Co-authored-by: pakorn269 <[email protected]>
…-usage.py

Replaced the broad `except Exception:` clause in `tests/claude-code/analyze-token-usage.py` with specific exceptions: `json.JSONDecodeError`, `KeyError`, `AttributeError`, and `TypeError`. This prevents the script from silently ignoring unexpected errors while still safely skipping malformed log entries.

Co-authored-by: pakorn269 <[email protected]>
…ync in render-graphs.js.

- Use spawnSync with arguments array to avoid shell interpretation.
- Update dot availability check to use spawnSync('dot', ['-V']).
- Improve error handling for process execution.

Co-authored-by: pakorn269 <[email protected]>
…de-15747818286365662443

🧹 [code health] extract socket handling logic from handleUpgrade
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…5938830699180

⚡ Optimize plugin bootstrap with async I/O
…4586452728125148765

🧪 Improve DOT extraction robustness and add unit tests
…17512225024792107044

⚡ Optimize brainstorming server with asynchronous I/O
…e-10323492790304569838

🧪 Add tests for wrapInFrame and fix replacement bug
…age-16657757307016695504

🧹 [code health] fix broad except in analyze-token-usage.py
…02689618182365617

🔒 Fix command injection vulnerability in render-graphs.js
💡 What: Automatically add `tabindex="0"` and `role="button"` to `[data-choice]` elements. Add keyboard listener for Enter/Space to trigger click, and `:focus-visible` styles.
🎯 Why: Brainstorming options were missing keyboard accessibility. Screen readers didn't announce them as interactive, and keyboard users couldn't activate them or see what was focused.
♿ Accessibility:
- Added semantic `role="button"`
- Added `tabindex="0"` for sequential keyboard navigation
- Added keyboard interaction (`Enter` and `Space`) to activate choices
- Added visible focus indicators (`:focus-visible`)

Co-authored-by: pakorn269 <[email protected]>
Modify isFullDocument to slice the first 20 characters before checking for `<!doctype` or `<html`, avoiding large memory allocations on full screen HTML outputs.
Added a .jules/bolt.md learning entry.

Co-authored-by: pakorn269 <[email protected]>
…instorm server

Added an `Origin` header validation check to the WebSocket upgrade handler in `skills/brainstorming/scripts/server.js`. Previously, a malicious website visited by a user could connect to the local brainstorm server and silently send forged choice events to Claude. The fix ensures that only allowed hostnames (`localhost`, `127.0.0.1`, or configured `HOST`) can establish a WebSocket connection. Appropriate tests were also added.

Co-authored-by: pakorn269 <[email protected]>
…b link

- Added `aria-live="polite"` to the dynamic `#indicator-text` element in `frame-template.html` so screen readers announce when a brainstorming option is selected.
- Added `target="_blank"`, `rel="noopener noreferrer"`, and an `aria-label` to the GitHub repository link to improve security, usability, and screen reader context for external links.

Co-authored-by: pakorn269 <[email protected]>
…11y-4681468131147141390

🎨 Palette: Keyboard Accessibility for Brainstorming Options
…on-9441776950517467304

⚡ Bolt: Optimize isFullDocument string allocation
…usage-5362172667138532979

🧪 Add tests for analyze_main_session in analyze-token-usage.py
…690580969

🧪 [testing improvement] Add tests for calculate_cost in analyze-token-usage.py
pakorn269 and others added 28 commits March 24, 2026 20:28
Sync upstream/main (March 2026)
🛡️ Sentinel: [HIGH] Fix DOM-based XSS in helper.js indicator
🎨 Palette: Sync aria-pressed with visual selection states
Security: add 10MB MAX_BUFFER_SIZE cap on WebSocket buffer to prevent
memory exhaustion DoS (closes duplicate PRs #24 #28 #32 #33 #37 #41 #44).

Performance: replace String.prototype.replace() with lastIndexOf+slice in
both wrapInFrame and handleRequest for multi-megabyte HTML payloads
(closes duplicate PRs #19 #22 #26 #29 #30 #35 #38 #39 #42).

Update .jules/sentinel.md and .jules/bolt.md with learnings.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Fix WS DoS buffer exhaustion + optimize string ops in server.cjs
Replaces the expensive `html.trimStart().substring(...)` sequence with
a bounded regular expression `^\s*(?:<!doctype|<html)`. This avoids copying
multi-megabyte HTML strings into memory just to test the prefix, dropping
the CPU/event-loop time for a 5MB payload from ~5-18ms to ~0.28ms.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
- Added a visually appealing empty state with an accessible loading spinner to `server.cjs` waiting page.
- Added dynamic connection state styling (transitions, text, and `aria-live` region) to `frame-template.html` and `helper.js`.
- Fixed an outdated string assertion in `server.test.js`.
- Documented learning in `.Jules/palette.md`.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
- Export extractAndStripFrontmatter and normalizePath for testing.
- Create tests/opencode/superpowers-utils.test.js with comprehensive test cases.
- Verify tests catch regressions and maintain passing status.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Consolidate duplicated `test` function logic across `helpers.test.js`,
`server.test.js`, and `ws-protocol.test.js` into a new shared helper
`test-utils.js`.

The new `createSuite` utility supports both synchronous and asynchronous
(Promise-returning) tests, which were used across the different files.
It also provides a standardized `summary` reporting mechanism.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
- Make startServer() async using fs.promises.mkdir/readdir to avoid
  blocking the event loop during initialization (from PR #52)
- Document async startup learning in .jules/bolt.md

Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Validates the Host header in handleRequest to block DNS rebinding attacks. Handles IPv6 loopback, HOST=0.0.0.0 LAN bypass, and malformed header edge cases.
Avoids searching for <!-- CONTENT --> marker and slicing the template string on every request by caching the start/end slices at module load time.
…atter

Avoids large string allocation and regex engine overhead when extracting frontmatter from potentially large files by using startsWith/indexOf/slice instead of a full-document regex match.
Replaces generic div containers with header/main/footer landmarks and adds aria-busy to the waiting screen, ensuring screen readers can navigate the brainstorm UI regardless of LLM-generated content.
* docs: add Codex App compatibility design spec (PRI-823)

Design for making using-git-worktrees, finishing-a-development-branch,
and subagent-driven-development skills work in the Codex App's sandboxed
worktree environment. Read-only environment detection via git-dir vs
git-common-dir comparison, ~48 lines across 4 files, zero breaking changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: address spec review feedback for PRI-823

Fix three Important issues from spec review:
- Clarify Step 1.5 placement relative to existing Steps 2/3
- Re-derive environment state at cleanup time instead of relying on
  earlier skill output
- Acknowledge pre-existing Step 5 cleanup inconsistency

Also: precise step references, exact codex-tools.md content, clearer
Integration section update instructions.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: address team review feedback for PRI-823 spec

- Add commit SHA + data loss warning to handoff payload (HIGH)
- Add explicit commit step before handoff (HIGH)
- Remove misleading "mark as externally managed" from Path B
- Add executing-plans 1-line edit (was missing)
- Add branch name derivation rules
- Add conditional UI language for non-App environments
- Add sandbox fallback for permission errors
- Add STOP directive after Step 0 reporting

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: clarify executing-plans in What Does NOT Change section

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: add cleanup guard test (#5) and sandbox fallback test (#10) to spec

Both tests address real risk scenarios:
- #5: cleanup guard bug would delete Codex App's own worktree (data loss)
- #10: Local thread sandbox fallback needs manual Codex App validation

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs: add implementation plan for Codex App compatibility (PRI-823)

8 tasks covering: environment detection in using-git-worktrees,
Step 1.5 + cleanup guard in finishing-a-development-branch,
Integration line updates, codex-tools.md docs, automated tests,
and final verification.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* docs(codex-tools): add named agent dispatch mapping for Codex (obra#647)

* fix(writing-skills): correct false 'only two fields' frontmatter claim (obra#882)

* Replace subagent review loops with lightweight inline self-review

The subagent review loop (dispatching a fresh agent to review plans/specs)
doubled execution time (~25 min overhead) without measurably improving plan
quality. Regression testing across 5 versions (v3.6.0 through v5.0.4) with
5 trials each showed identical plan sizes, task counts, and quality scores
regardless of whether the review loop ran.

Changes:
- writing-plans: Replace subagent Plan Review Loop with inline Self-Review
  checklist (spec coverage, placeholder scan, type consistency)
- writing-plans: Add explicit "No Placeholders" section listing plan failures
  (TBD, vague descriptions, undefined references, "similar to Task N")
- brainstorming: Replace subagent Spec Review Loop with inline Spec Self-Review
  (placeholder scan, internal consistency, scope check, ambiguity check)
- Both skills now use "look at it with fresh eyes" framing

Testing: 5 trials with the new skill show self-review catches 3-5 real bugs
per run (spawn positions, API mismatches, seed bugs, grid indexing) in ~30s
instead of ~25 min. Remaining defects are comparable to the subagent approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>

* Revert "Replace subagent review loops with lightweight inline self-review"

This reverts commit bf8f757.

* Reapply "Replace subagent review loops with lightweight inline self-review"

This reverts commit b045fa3.

* Add v5.0.6 release notes

* Move brainstorm server metadata to .meta/ subdirectory

Metadata files (.server-info, .events, .server.pid, .server.log,
.server-stopped) were stored in the same directory served over HTTP,
making them accessible via the /files/ route. They now live in a .meta/
subdirectory that is not web-accessible.

Also fixes a stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁

* Revert "Move brainstorm server metadata to .meta/ subdirectory"

This reverts commit ab500da.

* Separate brainstorm server content and state into peer directories

The session directory now contains two peers: content/ (HTML served to
the browser) and state/ (events, server-info, pid, log). Previously
all files shared a single directory, making server state and user
interaction data accessible over the /files/ HTTP route.

Also fixes stale test assertion ("Waiting for Claude" → "Waiting for
the agent").

Reported-By: 吉田仁

* Fix owner-PID false positive when owner runs as different user

ownerAlive() treated EPERM (permission denied) the same as ESRCH
(process not found), causing the server to self-terminate within 60s
whenever the owner process ran as a different user. This affected WSL
(owner is a Windows process), Tailscale SSH, and any cross-user
scenario.

The fix: `return e.code === 'EPERM'` — if we get permission denied,
the process is alive; we just can't signal it.

Tested on Linux via Tailscale SSH with a root-owned grandparent PID:
- Server survives past the 60s lifecycle check (EPERM = alive)
- Server still shuts down when owner genuinely dies (ESRCH = dead)

Fixes obra#879

* Fix owner-PID lifecycle monitoring for cross-platform reliability

Two bugs caused the brainstorm server to self-terminate within 60s:

1. ownerAlive() treated EPERM (permission denied) as "process dead".
   When the owner PID belongs to a different user (Tailscale SSH,
   system daemons), process.kill(pid, 0) throws EPERM — but the
   process IS alive. Fixed: return e.code === 'EPERM'.

2. On WSL, the grandparent PID resolves to a short-lived subprocess
   that exits before the first 60s lifecycle check. The PID is
   genuinely dead (ESRCH), so the EPERM fix alone doesn't help.
   Fixed: validate the owner PID at server startup — if it's already
   dead, it was a bad resolution, so disable monitoring and rely on
   the 30-minute idle timeout.

This also removes the Windows/MSYS2-specific OWNER_PID="" carve-out
from start-server.sh, since the server now handles invalid PIDs
generically at startup regardless of platform.

Tested on Linux (magic-kingdom) via Tailscale SSH:
- Root-owned owner PID (EPERM): server survives ✓
- Dead owner PID at startup (WSL sim): monitoring disabled, survives ✓
- Valid owner that dies: server shuts down within 60s ✓

Fixes obra#879

* Release v5.0.6: inline self-review, brainstorm server restructure, owner-PID fixes

---------

Co-authored-by: Drew Ritter <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Drew Ritter <[email protected]>
Co-authored-by: Jesse Vincent <[email protected]>
Refactored `getNewestScreen` and `startServer` to use asynchronous `fs.promises` instead of synchronous file I/O operations (`fs.readdirSync`, `fs.statSync`). Processing file stats in a sequential `for...of` loop avoids blocking the event loop while avoiding EMFILE errors.

Co-authored-by: pakorn269 <[email protected]>
💡 What: Added a visually hidden "Skip to content" link that reveals on focus, and added global :focus-visible outlines to interactive elements.
🎯 Why: Improves keyboard navigation accessibility for screen readers and power users, establishing a better baseline for generated HTML.
♿ Accessibility: Implements standard web accessibility skip link pattern and ensures keyboard focus is clearly visible across the template.

Co-authored-by: pakorn269 <[email protected]>
… handling

🛡️ Sentinel: [CRITICAL] Fix object property spoofing in Brainstorm Server
⚡ Bolt: [performance improvement] Async file operations
…storm template

🎨 Palette: Add skip-to-content link and focus styles
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
💡 What: Sliced the string before evaluating the regex in `isFullDocument`.
🎯 Why: To avoid evaluating the regex on the entire multi-megabyte HTML string, which blocks the event loop.
📊 Impact: Reduces evaluation time for 5MB payloads significantly (e.g., from ~9.15ms to ~0.40ms).
🔬 Measurement: Run the test suite and benchmark `isFullDocument` with a 5MB payload to observe the speedup.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
- Add connecting CSS class to frame-template.html
- Update initial status class to connecting
- Update helper.js ws.onclose to transition to connecting instead of disconnected

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant