ai-or-die 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 (78) hide show
  1. package/.cursor/commands/commit-push.md +18 -0
  2. package/.github/agents/architect.md +26 -0
  3. package/.github/agents/engineer.md +29 -0
  4. package/.github/agents/qa-reviewer.md +31 -0
  5. package/.github/agents/researcher.md +30 -0
  6. package/.github/agents/troubleshooter.md +33 -0
  7. package/.github/copilot-instructions.md +55 -0
  8. package/.github/pull_request_template.md +21 -0
  9. package/.github/workflows/build-binaries.yml +76 -0
  10. package/.github/workflows/ci.yml +70 -0
  11. package/.github/workflows/release-on-main.yml +73 -0
  12. package/.prompts/log.md +9 -0
  13. package/AGENTS.md +84 -0
  14. package/CHANGELOG.md +25 -0
  15. package/CLAUDE.md +130 -0
  16. package/CONTRIBUTING.md +76 -0
  17. package/LICENSE +22 -0
  18. package/README.md +165 -0
  19. package/bin/ai-or-die.js +203 -0
  20. package/docs/.nojekyll +1 -0
  21. package/docs/README.md +37 -0
  22. package/docs/adrs/0000-template.md +35 -0
  23. package/docs/adrs/0001-bridge-base-class.md +53 -0
  24. package/docs/adrs/0002-devtunnels-over-ngrok.md +56 -0
  25. package/docs/adrs/0003-multi-tool-architecture.md +71 -0
  26. package/docs/adrs/0004-cross-platform-support.md +101 -0
  27. package/docs/adrs/0005-single-binary-distribution.md +58 -0
  28. package/docs/agent-instructions/00-philosophy.md +55 -0
  29. package/docs/agent-instructions/01-research-and-web.md +49 -0
  30. package/docs/agent-instructions/02-testing-and-validation.md +63 -0
  31. package/docs/agent-instructions/03-tooling-and-pipelines.md +59 -0
  32. package/docs/architecture/bridge-pattern.md +510 -0
  33. package/docs/architecture/overview.md +216 -0
  34. package/docs/architecture/websocket-protocol.md +609 -0
  35. package/docs/history/README.md +26 -0
  36. package/docs/specs/authentication.md +167 -0
  37. package/docs/specs/bridges.md +210 -0
  38. package/docs/specs/client-app.md +308 -0
  39. package/docs/specs/e2e-testing.md +311 -0
  40. package/docs/specs/server.md +334 -0
  41. package/docs/specs/session-store.md +170 -0
  42. package/docs/specs/usage-analytics.md +342 -0
  43. package/nul +0 -0
  44. package/package.json +54 -0
  45. package/scripts/build-sea.js +187 -0
  46. package/scripts/pty-sea-shim.js +21 -0
  47. package/scripts/publish-both.sh +21 -0
  48. package/scripts/release-pr.sh +73 -0
  49. package/scripts/smoke-test-binary.js +190 -0
  50. package/scripts/validate.ps1 +25 -0
  51. package/scripts/validate.sh +16 -0
  52. package/sea-bootstrap.js +54 -0
  53. package/site/ADVANCED_ANALYTICS.md +174 -0
  54. package/site/index.html +151 -0
  55. package/site/script.js +17 -0
  56. package/site/style.css +60 -0
  57. package/src/base-bridge.js +340 -0
  58. package/src/claude-bridge.js +48 -0
  59. package/src/codex-bridge.js +27 -0
  60. package/src/copilot-bridge.js +29 -0
  61. package/src/gemini-bridge.js +26 -0
  62. package/src/public/app.js +2123 -0
  63. package/src/public/auth.js +244 -0
  64. package/src/public/icon-generator.js +26 -0
  65. package/src/public/icons.js +36 -0
  66. package/src/public/index.html +397 -0
  67. package/src/public/manifest.json +45 -0
  68. package/src/public/plan-detector.js +186 -0
  69. package/src/public/service-worker.js +108 -0
  70. package/src/public/session-manager.js +1124 -0
  71. package/src/public/splits.js +574 -0
  72. package/src/public/style.css +2090 -0
  73. package/src/server.js +1269 -0
  74. package/src/terminal-bridge.js +49 -0
  75. package/src/usage-analytics.js +494 -0
  76. package/src/usage-reader.js +895 -0
  77. package/src/utils/auth.js +123 -0
  78. package/src/utils/session-store.js +181 -0
@@ -0,0 +1,53 @@
1
+ # ADR-0001: Extract BaseBridge for CLI Tool Integration
2
+
3
+ ## Status
4
+
5
+ **Accepted**
6
+
7
+ ## Date
8
+
9
+ 2025-06-01
10
+
11
+ ## Context
12
+
13
+ The project currently ships three bridge classes -- `ClaudeBridge`, `CodexBridge`, and `AgentBridge` -- that each manage CLI process spawning, session lifecycle, output buffering, and terminal resizing. Approximately 95% of the code across these three files is identical; the only meaningful differences are:
14
+
15
+ 1. The CLI binary name and its search paths.
16
+ 2. The default arguments passed at spawn time.
17
+ 3. A handful of tool-specific flags (e.g. dangerous-command approval in Claude).
18
+
19
+ With three additional tools on the roadmap (Copilot CLI, Gemini Code, and a generic terminal bridge), duplicating this pattern further would create a maintenance burden where every cross-cutting fix (e.g. a reconnection bug, a Windows path issue) must be applied in six or more places.
20
+
21
+ ## Decision
22
+
23
+ Extract a `BaseBridge` base class that encapsulates the shared behaviour:
24
+
25
+ - **Platform-aware command discovery** -- use `os.homedir()` instead of `process.env.HOME`, and call `where` on Windows / `which` on Unix to locate binaries.
26
+ - **Session lifecycle** -- `startSession`, `stopSession`, `resizeSession`, `getSessionOutput`, and the internal `sessions` Map.
27
+ - **Output buffering** -- ring-buffer of the last N lines (default 1000) for reconnection support.
28
+ - **Process management** -- `node-pty` spawn with `xterm-256color` on Unix and ConPTY on Windows.
29
+
30
+ Each concrete bridge (e.g. `ClaudeBridge extends BaseBridge`) only needs to supply:
31
+
32
+ - `toolName` -- human-readable label.
33
+ - `binaryNames` -- ordered list of binary names / paths to search.
34
+ - `buildArgs(options)` -- returns the argument array for a given session.
35
+ - (optional) `dangerousFlags` -- patterns that trigger the plan-approval UI.
36
+
37
+ ## Consequences
38
+
39
+ ### Positive
40
+
41
+ - Adding a new tool bridge becomes a ~30-line subclass instead of a full copy-paste of 200+ lines.
42
+ - Cross-platform fixes (Windows path handling, ConPTY quirks) are applied once in `BaseBridge`.
43
+ - Unit tests can cover the base class exhaustively; subclass tests only need to verify tool-specific argument construction.
44
+
45
+ ### Negative
46
+
47
+ - Introduces an inheritance hierarchy, which can become rigid if tools diverge significantly in the future.
48
+ - Existing bridges need to be refactored, which touches stable code.
49
+
50
+ ### Neutral
51
+
52
+ - No user-facing behaviour change; this is a purely internal refactor.
53
+ - The WebSocket protocol and session store remain unchanged.
@@ -0,0 +1,56 @@
1
+ # ADR-0002: Replace ngrok with Microsoft Dev Tunnels
2
+
3
+ ## Status
4
+
5
+ **Accepted**
6
+
7
+ ## Date
8
+
9
+ 2025-06-15
10
+
11
+ ## Context
12
+
13
+ The project uses the `@ngrok/ngrok` npm package (v1.4.0) to expose the local server to the internet for remote access. This approach has several drawbacks:
14
+
15
+ 1. **Third-party npm dependency** -- `@ngrok/ngrok` pulls in native binaries via postinstall scripts, which complicates installs on locked-down machines and adds supply-chain surface area.
16
+ 2. **Security posture** -- traffic routes through ngrok's infrastructure, which is a third-party tunnel provider outside the user's control. Enterprise environments often block ngrok domains outright.
17
+ 3. **Cost** -- ngrok's free tier has bandwidth and connection limits; paid tiers add ongoing cost for a feature that many users need only occasionally.
18
+ 4. **Platform inconsistency** -- the npm package handles its own binary management, which has led to intermittent install failures on Windows and ARM Linux.
19
+
20
+ Microsoft Dev Tunnels (`devtunnel` CLI) is a free alternative backed by Azure infrastructure. It supports persistent tunnel names, access control via Microsoft/GitHub accounts, and is pre-installed in GitHub Codespaces and VS Code remote environments.
21
+
22
+ ## Decision
23
+
24
+ Replace the `@ngrok/ngrok` npm dependency with a shell-out to the `devtunnel` CLI:
25
+
26
+ ```
27
+ devtunnel host -p <port> --allow-anonymous
28
+ ```
29
+
30
+ Key implementation details:
31
+
32
+ - **No npm dependency** -- spawn `devtunnel` as a child process rather than importing an npm package. This removes `@ngrok/ngrok` from `package.json` entirely.
33
+ - **CLI discovery** -- use the same platform-aware discovery pattern from `BaseBridge` to locate `devtunnel` (or `devtunnel.exe` on Windows) in PATH.
34
+ - **Output parsing** -- parse the tunnel URL from the CLI's stdout (it prints `Connect via browser: https://<id>.devtunnels.ms`).
35
+ - **Lifecycle management** -- the tunnel process is tied to the server's lifecycle; it is killed on SIGINT/SIGTERM alongside the Express server.
36
+ - **Fallback messaging** -- if `devtunnel` is not found, log a clear message with install instructions rather than crashing.
37
+
38
+ ## Consequences
39
+
40
+ ### Positive
41
+
42
+ - Removes the `@ngrok/ngrok` npm dependency and its native binary postinstall step.
43
+ - Traffic routes through Microsoft/Azure infrastructure, which is more acceptable in enterprise environments.
44
+ - Free tier has generous limits (no bandwidth cap for anonymous tunnels).
45
+ - Cross-platform: `devtunnel` CLI ships for Windows, macOS, and Linux (x64 and ARM64).
46
+
47
+ ### Negative
48
+
49
+ - Requires the user to install the `devtunnel` CLI separately (`winget install Microsoft.devtunnel`, `brew install devtunnel`, or direct download). This is an external prerequisite that the app cannot auto-install.
50
+ - Microsoft account or GitHub sign-in is required for first-time `devtunnel` setup (one-time `devtunnel user login`).
51
+ - Less programmatic control compared to an in-process SDK -- we rely on parsing CLI output, which could break if the output format changes.
52
+
53
+ ### Neutral
54
+
55
+ - The tunnel feature remains opt-in (activated via `--tunnel` flag); users who do not need remote access are unaffected.
56
+ - The WebSocket protocol and client code require no changes -- the tunnel is transparent at the HTTP/WS layer.
@@ -0,0 +1,71 @@
1
+ # ADR-0003: Multi-Tool Architecture
2
+
3
+ ## Status
4
+
5
+ **Accepted**
6
+
7
+ ## Date
8
+
9
+ 2025-07-01
10
+
11
+ ## Context
12
+
13
+ ai-or-die started as a single-purpose web frontend for the Claude Code CLI. Over time, support was added for OpenAI Codex and Cursor Agent, each via a dedicated bridge class and hardcoded UI elements. The roadmap now includes Copilot CLI, Gemini Code Assist, and a generic terminal mode, which means:
14
+
15
+ 1. **Hardcoded tool lists do not scale.** Every new tool requires edits in the server constructor, the WebSocket message handler, the REST API routes, and the client-side UI (tool cards, session tabs, icons).
16
+ 2. **The client must know about every tool at build time.** Adding a tool that is not installed on a given server should not break the UI or require a code change -- the card should simply not appear.
17
+ 3. **Each tool has different "dangerous" command patterns** that the plan-approval UI needs to intercept (e.g. `rm -rf` for a generic terminal, `--dangerously-skip-permissions` for Claude).
18
+
19
+ ## Decision
20
+
21
+ Adopt a tool-agnostic architecture with the following components:
22
+
23
+ ### Server-side: Tool Registry
24
+
25
+ The server maintains a `toolRegistry` -- an ordered list of tool descriptors built at startup by probing which CLI binaries are available:
26
+
27
+ ```js
28
+ {
29
+ id: 'claude',
30
+ name: 'Claude',
31
+ bridge: claudeBridge, // BaseBridge subclass instance
32
+ available: true, // binary was found on this machine
33
+ dangerousPatterns: [/--dangerously-skip-permissions/],
34
+ icon: 'claude', // maps to a client-side icon set
35
+ description: 'Anthropic Claude Code'
36
+ }
37
+ ```
38
+
39
+ A new `/api/tools` REST endpoint returns the list of available tools (minus internal fields like `bridge`), so the client can render the UI dynamically.
40
+
41
+ ### Client-side: Dynamic UI Card Generation
42
+
43
+ The landing page fetches `/api/tools` on load and generates one "Start" card per available tool. No tool-specific markup exists in `index.html` -- all cards are built from the same template in `app.js`. Tool icons are resolved from a shared sprite or CSS class map.
44
+
45
+ ### WebSocket Protocol: Unified Messages
46
+
47
+ The existing WebSocket messages (`create_session`, `start_claude`, `input`, `resize`, `stop`) are generalized:
48
+
49
+ - `start_claude` becomes `start_tool` with a `toolId` field.
50
+ - Session objects carry a `toolId` so the server routes messages to the correct bridge.
51
+ - All other messages (`input`, `resize`, `stop`, `join_session`, `leave_session`) remain unchanged -- they operate on sessions, not tools.
52
+
53
+ ## Consequences
54
+
55
+ ### Positive
56
+
57
+ - Adding a new tool requires only a `BaseBridge` subclass and a registry entry -- no client code changes.
58
+ - The UI stays clean regardless of how many tools are registered; unavailable tools simply do not render.
59
+ - Each tool can declare its own dangerous-command patterns, which the plan-detector evaluates at runtime.
60
+ - Server operators can disable tools via environment variables or config without touching code.
61
+
62
+ ### Negative
63
+
64
+ - The `/api/tools` endpoint is a new network request on page load, adding a small latency hit before the UI renders.
65
+ - Dynamic card generation is slightly harder to debug than static HTML.
66
+ - Tool icons/branding must be managed as a shared asset set rather than inline SVGs.
67
+
68
+ ### Neutral
69
+
70
+ - Backward compatibility is maintained: existing `start_claude` messages are internally aliased to `start_tool { toolId: 'claude' }` so older clients continue to work during the transition.
71
+ - Session persistence format gains a `toolId` field; sessions without one default to `'claude'` for migration.
@@ -0,0 +1,101 @@
1
+ # ADR-0004: Cross-Platform Support (Windows + Linux)
2
+
3
+ ## Status
4
+
5
+ **Accepted**
6
+
7
+ ## Date
8
+
9
+ 2025-07-15
10
+
11
+ ## Context
12
+
13
+ The original codebase was written with Linux (and macOS) as the sole target. Several patterns in the code are not portable:
14
+
15
+ 1. **`process.env.HOME`** -- undefined on Windows, where the equivalent is `process.env.USERPROFILE` or `os.homedir()`.
16
+ 2. **`which` for command discovery** -- Windows uses `where.exe` instead.
17
+ 3. **Hardcoded Unix paths** -- e.g. `/usr/local/bin/claude`, `/home/ec2-user/.claude/local/claude`.
18
+ 4. **`node-pty` defaults** -- Linux uses the Unix PTY subsystem; Windows requires ConPTY (available since Windows 10 version 1809).
19
+ 5. **Default shell** -- the bridges implicitly assume `/bin/bash` or similar; Windows should default to PowerShell (`pwsh` or `powershell.exe`).
20
+
21
+ Users on Windows (especially WSL2 and native Windows with `node-pty` ConPTY support) have reported install and runtime failures stemming from these assumptions.
22
+
23
+ ## Decision
24
+
25
+ Introduce platform detection at the `BaseBridge` level (see ADR-0001) with the following changes:
26
+
27
+ ### Command Discovery
28
+
29
+ ```js
30
+ const os = require('os');
31
+ const { execFileSync } = require('child_process');
32
+
33
+ function commandExists(binary) {
34
+ const checker = process.platform === 'win32' ? 'where.exe' : 'which';
35
+ try {
36
+ execFileSync(checker, [binary], { stdio: 'ignore' });
37
+ return true;
38
+ } catch {
39
+ return false;
40
+ }
41
+ }
42
+ ```
43
+
44
+ ### Home Directory
45
+
46
+ Replace all uses of `process.env.HOME` with `os.homedir()`, which returns the correct value on every platform.
47
+
48
+ ### Search Paths
49
+
50
+ Each bridge's `binaryNames` list includes both Unix and Windows variants:
51
+
52
+ ```js
53
+ // ClaudeBridge
54
+ binaryNames: [
55
+ 'claude',
56
+ path.join(os.homedir(), '.claude', 'local', 'claude'), // Unix
57
+ path.join(os.homedir(), '.claude', 'local', 'claude.exe'), // Windows
58
+ '/usr/local/bin/claude',
59
+ ]
60
+ ```
61
+
62
+ Non-existent paths are silently skipped during discovery.
63
+
64
+ ### PTY Configuration
65
+
66
+ ```js
67
+ const ptyOptions = {
68
+ name: process.platform === 'win32' ? 'conpty' : 'xterm-256color',
69
+ cols: options.cols || 80,
70
+ rows: options.rows || 24,
71
+ cwd: options.workingDir,
72
+ env: process.env,
73
+ ...(process.platform === 'win32' && { useConpty: true }),
74
+ };
75
+ ```
76
+
77
+ ### Default Shell (generic terminal bridge)
78
+
79
+ For the planned generic terminal tool, the default shell is:
80
+
81
+ - **Windows**: `pwsh.exe` (PowerShell 7+), falling back to `powershell.exe`, then `cmd.exe`.
82
+ - **Linux/macOS**: `$SHELL`, falling back to `/bin/bash`, then `/bin/sh`.
83
+
84
+ ## Consequences
85
+
86
+ ### Positive
87
+
88
+ - The application works out of the box on Windows 10 1809+ (with ConPTY) and all supported Linux distributions.
89
+ - WSL2 users can run the server natively on Windows or inside the WSL2 VM -- both paths work.
90
+ - CI can run a test matrix across `ubuntu-latest` and `windows-latest` to catch regressions.
91
+
92
+ ### Negative
93
+
94
+ - Windows ConPTY has known quirks with certain escape sequences; some terminal rendering may differ from Unix.
95
+ - `node-pty` native compilation on Windows requires build tools (Visual Studio Build Tools or `windows-build-tools`), which adds install friction.
96
+ - Testing surface area doubles -- every bridge test must pass on both platforms.
97
+
98
+ ### Neutral
99
+
100
+ - macOS support comes for free since it shares the Unix PTY path; no additional work is needed.
101
+ - The `--tunnel` feature (Dev Tunnels) already supports both platforms, so no tunnel-specific changes are required.
@@ -0,0 +1,58 @@
1
+ # ADR 0005: Single Binary Distribution via Node.js SEA
2
+
3
+ ## Status
4
+
5
+ Accepted
6
+
7
+ ## Context
8
+
9
+ Users currently install ai-or-die via `npm install -g ai-or-die` or `npx ai-or-die`, both of which require Node.js and npm to be pre-installed. A single binary distribution would allow download-and-run without a Node.js runtime, simplifying distribution and onboarding.
10
+
11
+ The main challenge is the `@lydell/node-pty` dependency, which ships platform-specific prebuilt native `.node` files and helper binaries (conpty.dll, OpenConsole.exe on Windows; spawn-helper on Linux).
12
+
13
+ ## Decision
14
+
15
+ Use **Node.js Single Executable Application (SEA)**, available as a stable feature since Node 22. This is the only actively maintained, officially supported approach for packaging Node.js apps as standalone binaries.
16
+
17
+ ### Build pipeline
18
+
19
+ 1. **esbuild** bundles all JavaScript into `dist/bundle.js`, with `@lydell/node-pty` marked as external (native modules cannot be bundled)
20
+ 2. Static assets (`src/public/**`) and platform-specific native `.node` prebuilts are collected as SEA assets
21
+ 3. `node --experimental-sea-config` generates a preparation blob
22
+ 4. The blob is injected into a copy of the Node binary using `postject`
23
+ 5. The resulting binary is uploaded to GitHub Releases
24
+
25
+ ### Runtime behavior
26
+
27
+ A `sea-bootstrap.js` wrapper detects SEA mode and:
28
+ - Extracts native `.node` files to a temp directory
29
+ - Patches `Module._resolveFilename` to redirect `@lydell/node-pty` requires
30
+ - Cleans up the temp directory on exit
31
+
32
+ Static assets are served from the SEA blob via a custom Express middleware that uses `sea.getRawAsset()`.
33
+
34
+ ## Alternatives Considered
35
+
36
+ | Option | Why not |
37
+ |--------|---------|
38
+ | `pkg` (Vercel) | Deprecated since 2023, unmaintained |
39
+ | `nexe` | Sporadic maintenance, limited Node 22+ support |
40
+ | Bun compile | Requires Bun runtime; `@lydell/node-pty` is Node-specific |
41
+ | Standalone tarball | Not a single file; still requires manual extraction |
42
+
43
+ ## Consequences
44
+
45
+ ### Positive
46
+ - Zero-install distribution: download binary, run it
47
+ - Binaries attached to GitHub Releases automatically
48
+ - No Node.js runtime required on user machines
49
+
50
+ ### Negative
51
+ - Binary size ~80-100MB (includes Node.js runtime)
52
+ - Native addon extraction to temp directory at startup adds ~100ms
53
+ - Must build on each target platform (no cross-compilation)
54
+ - External CLI tools (Claude, Copilot, Gemini) must still be installed separately
55
+
56
+ ### Neutral
57
+ - npm installation remains the primary distribution method
58
+ - SEA binaries are a convenience alternative, not a replacement
@@ -0,0 +1,55 @@
1
+ # Core Philosophy
2
+
3
+ ## Prime Directive
4
+
5
+ We do not guess. We research, we plan, we test, then we code.
6
+
7
+ ## Principles
8
+
9
+ ### 1. Documentation Drives Code
10
+
11
+ No code is written without a corresponding spec in `docs/specs/`. If the docs say X and the code says Y, the code is wrong. Before implementing any feature:
12
+
13
+ - Check `docs/specs/` for existing specification
14
+ - If no spec exists, write one first
15
+ - After implementation, update the spec to reflect the final state
16
+
17
+ ### 2. Research Before Implementing
18
+
19
+ Every agent must search the web for current best practices before coding. Training data goes stale. Libraries change. APIs evolve. Before adding any dependency or implementing any pattern:
20
+
21
+ - Search for the current recommended approach
22
+ - Verify library versions are not deprecated
23
+ - Check for known CVEs or security advisories
24
+ - Document findings in the relevant ADR if it's an architectural decision
25
+
26
+ ### 3. Test Alongside Code
27
+
28
+ No pull request without tests for new behavior. Tests are not an afterthought — they are written alongside (or before) the implementation. Target 90% coverage for all new code.
29
+
30
+ ### 4. Measure Twice, Cut Once
31
+
32
+ Plan before executing. Read the existing code before modifying it. Understand the bridge pattern, the WebSocket protocol, and the session lifecycle before touching any of them. Check `docs/adrs/` for past architectural decisions to avoid regression.
33
+
34
+ ### 5. Cross-Platform Always
35
+
36
+ Every code change must consider both Windows and Linux. Use `os.homedir()` not `process.env.HOME`. Use `path.join()` not string concatenation. Test path handling for both OS types. The CI pipeline runs on both platforms — if it doesn't pass on both, it doesn't merge.
37
+
38
+ ## The CEO Model
39
+
40
+ When tackling complex tasks, the initiating agent acts as CEO — orchestrating sub-agents as workers. The CEO:
41
+
42
+ - Breaks the task into independent, parallelizable units
43
+ - Delegates to specialized agents (architect, engineer, QA, etc.)
44
+ - Monitors progress and resolves blockers
45
+ - Ensures the final result is coherent and tested
46
+
47
+ ## Decision Records
48
+
49
+ Significant architectural decisions are recorded in `docs/adrs/`. Before making a decision that affects:
50
+ - How tools are integrated (bridge pattern)
51
+ - How data flows (WebSocket protocol)
52
+ - What dependencies are used
53
+ - How the system is deployed
54
+
55
+ Write an ADR first. The format is in `docs/adrs/0000-template.md`.
@@ -0,0 +1,49 @@
1
+ # Research and Web Usage
2
+
3
+ ## Internet is First-Class
4
+
5
+ The internet is not optional. Agents must use web search to find current best practices before coding. Do not rely solely on training data for:
6
+
7
+ - Library APIs and versions
8
+ - Security advisories
9
+ - Platform-specific behavior
10
+ - Current recommended patterns
11
+
12
+ ## When to Research
13
+
14
+ ### Before Adding Dependencies
15
+
16
+ - Search for the package's current status (maintained? deprecated?)
17
+ - Check npm download trends and last publish date
18
+ - Look for known vulnerabilities (`npm audit` equivalent)
19
+ - Verify compatibility with Node.js 16+
20
+
21
+ ### Before Implementing Patterns
22
+
23
+ - Search for "[pattern] best practices [year]"
24
+ - Look for cross-platform gotchas (especially Windows + Linux)
25
+ - Check if the framework/library has built-in solutions
26
+
27
+ ### Before Making Architectural Decisions
28
+
29
+ - Search for alternatives and their tradeoffs
30
+ - Find 3+ sources before committing to an approach
31
+ - Document sources in the ADR
32
+
33
+ ## Validation Protocol
34
+
35
+ 1. **Version Check**: Before using any API, search for its current documentation
36
+ 2. **CVE Check**: Before adding dependencies, search for known vulnerabilities
37
+ 3. **Platform Check**: Before using OS-specific features, verify cross-platform support
38
+ 4. **Deprecation Check**: Before using any pattern, verify it's not deprecated
39
+
40
+ ## Information Saturation
41
+
42
+ Research until you reach information saturation — the point where new searches return the same information you already have. Only then proceed to implementation.
43
+
44
+ ## Citation in ADRs
45
+
46
+ When writing Architecture Decision Records, cite external sources:
47
+ - Link to documentation pages
48
+ - Reference Stack Overflow answers or GitHub issues
49
+ - Note the date of the research (information has a shelf life)
@@ -0,0 +1,63 @@
1
+ # Testing and Validation
2
+
3
+ ## Coverage Target
4
+
5
+ Target 90% code coverage for all new code. This is not optional for new features or refactors. Existing code without tests should be covered when modified.
6
+
7
+ ## Test-Driven Approach
8
+
9
+ Write tests alongside implementation, not after. The workflow:
10
+
11
+ 1. Write the test describing expected behavior
12
+ 2. Implement the code to make the test pass
13
+ 3. Refactor if needed, keeping tests green
14
+
15
+ ## Test Framework
16
+
17
+ - **Framework**: Mocha with Node.js built-in `assert`
18
+ - **Location**: `test/` directory
19
+ - **Naming**: `name.test.js`
20
+ - **Running**: `npm test`
21
+
22
+ ## Test Guidelines
23
+
24
+ - Write fast, isolated unit tests
25
+ - Avoid network calls and real CLI spawning in tests — mock process spawns
26
+ - Use temp directories for file system tests (see `session-store.test.js` pattern)
27
+ - Test cross-platform behavior: path construction, command resolution, shell detection
28
+
29
+ ## Self-Validation
30
+
31
+ Before committing, every agent must:
32
+
33
+ 1. Run `npm test` — all tests pass
34
+ 2. Run `npm start` — server boots without errors
35
+ 3. Run `scripts/validate.sh` (Linux) or `scripts/validate.ps1` (Windows)
36
+ 4. Verify the change doesn't break existing functionality
37
+
38
+ ## What to Test
39
+
40
+ ### For Bridge Changes
41
+ - Command discovery on mock file systems
42
+ - Session lifecycle (start, input, resize, stop)
43
+ - Error handling (command not found, process crash)
44
+ - Platform-specific paths
45
+
46
+ ### For Server Changes
47
+ - REST API responses (status codes, JSON structure)
48
+ - WebSocket message handling
49
+ - Session creation and deletion
50
+ - Auth middleware behavior
51
+
52
+ ### For Client Changes
53
+ - Manual browser testing (create session, select tool, verify output)
54
+ - Check mobile responsiveness
55
+ - Verify WebSocket reconnection
56
+
57
+ ## When Tests Fail
58
+
59
+ If tests fail, fix them before moving on. Do not:
60
+ - Skip failing tests
61
+ - Comment out assertions
62
+ - Reduce coverage to make the build pass
63
+ - Commit with known failures
@@ -0,0 +1,59 @@
1
+ # Tooling and Pipelines
2
+
3
+ ## Automation Rule
4
+
5
+ If you perform a verification task twice, script it. All scripts live in the `scripts/` directory.
6
+
7
+ ### Current Scripts
8
+
9
+ - `scripts/validate.sh` — Linux validation (lint, test, docs check)
10
+ - `scripts/validate.ps1` — Windows validation (same checks)
11
+ - `scripts/release-pr.sh` — Release process automation
12
+
13
+ ## CI/CD Pipeline
14
+
15
+ ### GitHub Actions
16
+
17
+ The CI pipeline (`.github/workflows/ci.yml`) runs on every push and PR:
18
+
19
+ 1. **Matrix**: Runs on both `ubuntu-latest` and `windows-latest`
20
+ 2. **Install**: `npm ci`
21
+ 3. **Lint**: ESLint check
22
+ 4. **Test**: `npm test` with coverage reporting
23
+ 5. **Audit**: `npm audit` for security vulnerabilities
24
+ 6. **Docs Check**: Verify docs/ structure exists
25
+
26
+ ### Release Pipeline
27
+
28
+ The release pipeline (`.github/workflows/release-on-main.yml`) triggers on push to main:
29
+
30
+ 1. Read version from `package.json`
31
+ 2. Check if git tag already exists
32
+ 3. Create GitHub Release with tag
33
+ 4. Publish to npm
34
+
35
+ ## Tool Creation Guidelines
36
+
37
+ When creating new scripts:
38
+
39
+ - Use `#!/bin/bash` for Linux scripts, PowerShell for Windows
40
+ - Include error handling and meaningful exit codes
41
+ - Add usage instructions as comments at the top
42
+ - Make scripts idempotent (safe to run multiple times)
43
+
44
+ ## Dependency Management
45
+
46
+ - Pin major versions in `package.json` (use `^` for minor/patch)
47
+ - Run `npm audit` before adding any new dependency
48
+ - Prefer packages with:
49
+ - Active maintenance (commits within last 6 months)
50
+ - No known vulnerabilities
51
+ - Cross-platform support
52
+ - Minimal transitive dependencies
53
+
54
+ ## Code Quality
55
+
56
+ - **Linter**: ESLint (configured in project)
57
+ - **Style**: 2-space indentation, semicolons, single quotes
58
+ - **Naming**: kebab-case files, PascalCase classes, camelCase functions
59
+ - **Comments**: Only where the logic isn't self-evident