codepiper 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 (149) hide show
  1. package/.env.example +28 -0
  2. package/CHANGELOG.md +10 -0
  3. package/LEGAL_NOTICE.md +39 -0
  4. package/LICENSE +21 -0
  5. package/README.md +524 -0
  6. package/package.json +90 -0
  7. package/packages/cli/package.json +13 -0
  8. package/packages/cli/src/commands/analytics.ts +157 -0
  9. package/packages/cli/src/commands/attach.ts +299 -0
  10. package/packages/cli/src/commands/audit.ts +50 -0
  11. package/packages/cli/src/commands/auth.ts +261 -0
  12. package/packages/cli/src/commands/daemon.ts +162 -0
  13. package/packages/cli/src/commands/doctor.ts +303 -0
  14. package/packages/cli/src/commands/env-set.ts +162 -0
  15. package/packages/cli/src/commands/hook-forward.ts +268 -0
  16. package/packages/cli/src/commands/keys.ts +77 -0
  17. package/packages/cli/src/commands/kill.ts +19 -0
  18. package/packages/cli/src/commands/logs.ts +419 -0
  19. package/packages/cli/src/commands/model.ts +172 -0
  20. package/packages/cli/src/commands/policy-set.ts +185 -0
  21. package/packages/cli/src/commands/policy.ts +227 -0
  22. package/packages/cli/src/commands/providers.ts +114 -0
  23. package/packages/cli/src/commands/resize.ts +34 -0
  24. package/packages/cli/src/commands/send.ts +184 -0
  25. package/packages/cli/src/commands/sessions.ts +202 -0
  26. package/packages/cli/src/commands/slash.ts +92 -0
  27. package/packages/cli/src/commands/start.ts +243 -0
  28. package/packages/cli/src/commands/stop.ts +19 -0
  29. package/packages/cli/src/commands/tail.ts +137 -0
  30. package/packages/cli/src/commands/workflow.ts +786 -0
  31. package/packages/cli/src/commands/workspace.ts +127 -0
  32. package/packages/cli/src/lib/api.ts +78 -0
  33. package/packages/cli/src/lib/args.ts +72 -0
  34. package/packages/cli/src/lib/format.ts +93 -0
  35. package/packages/cli/src/main.ts +563 -0
  36. package/packages/core/package.json +7 -0
  37. package/packages/core/src/config.ts +30 -0
  38. package/packages/core/src/errors.ts +38 -0
  39. package/packages/core/src/eventBus.ts +56 -0
  40. package/packages/core/src/eventBusAdapter.ts +143 -0
  41. package/packages/core/src/index.ts +10 -0
  42. package/packages/core/src/sqliteEventBus.ts +336 -0
  43. package/packages/core/src/types.ts +63 -0
  44. package/packages/daemon/package.json +11 -0
  45. package/packages/daemon/src/api/analyticsRoutes.ts +343 -0
  46. package/packages/daemon/src/api/authRoutes.ts +344 -0
  47. package/packages/daemon/src/api/bodyLimit.ts +133 -0
  48. package/packages/daemon/src/api/envSetRoutes.ts +170 -0
  49. package/packages/daemon/src/api/gitRoutes.ts +409 -0
  50. package/packages/daemon/src/api/hooks.ts +588 -0
  51. package/packages/daemon/src/api/inputPolicy.ts +249 -0
  52. package/packages/daemon/src/api/notificationRoutes.ts +532 -0
  53. package/packages/daemon/src/api/policyRoutes.ts +234 -0
  54. package/packages/daemon/src/api/policySetRoutes.ts +445 -0
  55. package/packages/daemon/src/api/routeUtils.ts +28 -0
  56. package/packages/daemon/src/api/routes.ts +1004 -0
  57. package/packages/daemon/src/api/server.ts +1388 -0
  58. package/packages/daemon/src/api/settingsRoutes.ts +367 -0
  59. package/packages/daemon/src/api/sqliteErrors.ts +47 -0
  60. package/packages/daemon/src/api/stt.ts +143 -0
  61. package/packages/daemon/src/api/terminalRoutes.ts +200 -0
  62. package/packages/daemon/src/api/validation.ts +287 -0
  63. package/packages/daemon/src/api/validationRoutes.ts +174 -0
  64. package/packages/daemon/src/api/workflowRoutes.ts +567 -0
  65. package/packages/daemon/src/api/workspaceRoutes.ts +151 -0
  66. package/packages/daemon/src/api/ws.ts +1588 -0
  67. package/packages/daemon/src/auth/apiRateLimiter.ts +73 -0
  68. package/packages/daemon/src/auth/authMiddleware.ts +305 -0
  69. package/packages/daemon/src/auth/authService.ts +496 -0
  70. package/packages/daemon/src/auth/rateLimiter.ts +137 -0
  71. package/packages/daemon/src/config/pricing.ts +79 -0
  72. package/packages/daemon/src/crypto/encryption.ts +196 -0
  73. package/packages/daemon/src/db/db.ts +2745 -0
  74. package/packages/daemon/src/db/index.ts +16 -0
  75. package/packages/daemon/src/db/migrations.ts +182 -0
  76. package/packages/daemon/src/db/policyDb.ts +349 -0
  77. package/packages/daemon/src/db/schema.sql +408 -0
  78. package/packages/daemon/src/db/workflowDb.ts +464 -0
  79. package/packages/daemon/src/git/gitUtils.ts +544 -0
  80. package/packages/daemon/src/index.ts +6 -0
  81. package/packages/daemon/src/main.ts +525 -0
  82. package/packages/daemon/src/notifications/pushNotifier.ts +369 -0
  83. package/packages/daemon/src/providers/codexAppServerScaffold.ts +49 -0
  84. package/packages/daemon/src/providers/registry.ts +111 -0
  85. package/packages/daemon/src/providers/types.ts +82 -0
  86. package/packages/daemon/src/sessions/auditLogger.ts +103 -0
  87. package/packages/daemon/src/sessions/policyEngine.ts +165 -0
  88. package/packages/daemon/src/sessions/policyMatcher.ts +114 -0
  89. package/packages/daemon/src/sessions/policyTypes.ts +94 -0
  90. package/packages/daemon/src/sessions/ptyProcess.ts +141 -0
  91. package/packages/daemon/src/sessions/sessionManager.ts +1770 -0
  92. package/packages/daemon/src/sessions/tmuxSession.ts +1073 -0
  93. package/packages/daemon/src/sessions/transcriptManager.ts +110 -0
  94. package/packages/daemon/src/sessions/transcriptParser.ts +149 -0
  95. package/packages/daemon/src/sessions/transcriptTailer.ts +214 -0
  96. package/packages/daemon/src/tracking/tokenTracker.ts +168 -0
  97. package/packages/daemon/src/workflows/contextManager.ts +83 -0
  98. package/packages/daemon/src/workflows/index.ts +31 -0
  99. package/packages/daemon/src/workflows/resultExtractor.ts +118 -0
  100. package/packages/daemon/src/workflows/waitConditionPoller.ts +131 -0
  101. package/packages/daemon/src/workflows/workflowParser.ts +217 -0
  102. package/packages/daemon/src/workflows/workflowRunner.ts +969 -0
  103. package/packages/daemon/src/workflows/workflowTypes.ts +188 -0
  104. package/packages/daemon/src/workflows/workflowValidator.ts +533 -0
  105. package/packages/providers/claude-code/package.json +11 -0
  106. package/packages/providers/claude-code/src/index.ts +7 -0
  107. package/packages/providers/claude-code/src/overlaySettings.ts +198 -0
  108. package/packages/providers/claude-code/src/provider.ts +311 -0
  109. package/packages/web/dist/android-chrome-192x192.png +0 -0
  110. package/packages/web/dist/android-chrome-512x512.png +0 -0
  111. package/packages/web/dist/apple-touch-icon.png +0 -0
  112. package/packages/web/dist/assets/AnalyticsPage-BIopKWRf.js +17 -0
  113. package/packages/web/dist/assets/PoliciesPage-CjdLN3dl.js +11 -0
  114. package/packages/web/dist/assets/SessionDetailPage-BtSA0V0M.js +179 -0
  115. package/packages/web/dist/assets/SettingsPage-Dbbz4Ca5.js +37 -0
  116. package/packages/web/dist/assets/WorkflowsPage-Dv6f3GgU.js +1 -0
  117. package/packages/web/dist/assets/chart-vendor-DlOHLaCG.js +49 -0
  118. package/packages/web/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
  119. package/packages/web/dist/assets/css.worker-BvV5MPou.js +93 -0
  120. package/packages/web/dist/assets/editor.worker-CKy7Pnvo.js +26 -0
  121. package/packages/web/dist/assets/html.worker-BLJhxQJQ.js +470 -0
  122. package/packages/web/dist/assets/index-BbdhRfr2.css +1 -0
  123. package/packages/web/dist/assets/index-hgphORiw.js +204 -0
  124. package/packages/web/dist/assets/json.worker-usMZ-FED.js +58 -0
  125. package/packages/web/dist/assets/monaco-core-B_19GPAS.css +1 -0
  126. package/packages/web/dist/assets/monaco-core-DQ5Mk8AK.js +1234 -0
  127. package/packages/web/dist/assets/monaco-react-DfZNWvtW.js +11 -0
  128. package/packages/web/dist/assets/monacoSetup-DvBj52bT.js +1 -0
  129. package/packages/web/dist/assets/pencil-Dbczxz59.js +11 -0
  130. package/packages/web/dist/assets/react-vendor-B5MgMUHH.js +136 -0
  131. package/packages/web/dist/assets/refresh-cw-B0MGsYPL.js +6 -0
  132. package/packages/web/dist/assets/tabs-C8LsWiR5.js +1 -0
  133. package/packages/web/dist/assets/terminal-vendor-Cs8KPbV3.js +9 -0
  134. package/packages/web/dist/assets/terminal-vendor-LcAfv9l9.css +32 -0
  135. package/packages/web/dist/assets/trash-2-Btlg0d4l.js +6 -0
  136. package/packages/web/dist/assets/ts.worker-DGHjMaqB.js +67731 -0
  137. package/packages/web/dist/favicon.ico +0 -0
  138. package/packages/web/dist/icon.svg +1 -0
  139. package/packages/web/dist/index.html +29 -0
  140. package/packages/web/dist/manifest.json +29 -0
  141. package/packages/web/dist/og-image.png +0 -0
  142. package/packages/web/dist/originals/android-chrome-192x192.png +0 -0
  143. package/packages/web/dist/originals/android-chrome-512x512.png +0 -0
  144. package/packages/web/dist/originals/apple-touch-icon.png +0 -0
  145. package/packages/web/dist/originals/favicon.ico +0 -0
  146. package/packages/web/dist/piper.svg +1 -0
  147. package/packages/web/dist/sounds/codepiper-soft-chime.wav +0 -0
  148. package/packages/web/dist/sw.js +257 -0
  149. package/scripts/postinstall-link-workspaces.mjs +58 -0
package/.env.example ADDED
@@ -0,0 +1,28 @@
1
+ # CodePiper — Environment Configuration
2
+ # Copy to .env and edit as needed. Bun loads .env automatically.
3
+
4
+ # ── Networking ──────────────────────────────────────────────────────
5
+ # CODEPIPER_SOCKET=/tmp/codepiper.sock # Unix socket path
6
+ # CODEPIPER_HTTP_PORT=3000 # HTTP/web dashboard port
7
+ # CODEPIPER_WS_PORT=9999 # WebSocket port (standalone)
8
+
9
+ # ── Remote Access ───────────────────────────────────────────────────
10
+ # Comma-separated hostnames or origins allowed for WebSocket connections.
11
+ # Required when accessing from a non-localhost domain (reverse proxy, tunnel, etc.).
12
+ # CODEPIPER_ALLOWED_ORIGINS=myapp.example.com,other.dev
13
+
14
+ # ── Database ────────────────────────────────────────────────────────
15
+ # CODEPIPER_DB_PATH=~/.codepiper/codepiper.db # SQLite database path
16
+
17
+ # ── Security ───────────────────────────────────────────────────────
18
+ # CODEPIPER_SECRET= # Hook authentication secret (auto-generated if unset)
19
+
20
+ # ── Push Delivery (Optional) ───────────────────────────────────────
21
+ # CODEPIPER_PUSH_ENABLED=0 # Set to 1 to enable daemon web-push delivery
22
+ # CODEPIPER_PUSH_PUBLIC_KEY= # Base64URL VAPID public key
23
+ # CODEPIPER_PUSH_PRIVATE_KEY= # Base64URL VAPID private key
24
+ # CODEPIPER_PUSH_SUBJECT=mailto:you@example.com # VAPID subject (mailto: or https:// URL)
25
+
26
+ # ── Web Dashboard (Optional) ───────────────────────────────────────
27
+ # VITE_PUSH_PUBLIC_KEY= # Base64URL VAPID public key used by web push enrollment
28
+ # # Should match CODEPIPER_PUSH_PUBLIC_KEY
package/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to CodePiper are documented here.
4
+
5
+ This project follows [Semantic Versioning](https://semver.org/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Added
10
+ - Initial public baseline.
@@ -0,0 +1,39 @@
1
+ # Legal Notice & Compliance Disclaimer
2
+
3
+ ## Disclaimer of Liability
4
+
5
+ This software is an open-source tool provided "as is" without warranty of any kind, express or implied. The authors and contributors are NOT responsible for how users deploy, configure, or operate this software. Users are solely responsible for ensuring their usage complies with all applicable terms of service, laws, and regulations.
6
+
7
+ ## Third-Party Service Compliance
8
+
9
+ This software integrates with third-party AI services (including but not limited to Anthropic's Claude Code). By using this software, you acknowledge and agree that:
10
+
11
+ 1. **You are responsible for compliance** with all third-party terms of service, including but not limited to Anthropic's Consumer Terms of Service, Commercial Terms of Service, and Usage Policy.
12
+
13
+ 2. **Billing and usage**: You are responsible for understanding and managing your billing relationship with third-party providers. This software supports multiple billing modes — choosing the correct mode for your use case is your responsibility.
14
+
15
+ 3. **Automated access**: If you use this software for automated, programmatic, or non-human-driven workflows, you MUST use API key billing (not consumer subscription plans) as required by Anthropic's Terms of Service. The relevant clause states: *"Except when you are accessing our Services via an Anthropic API Key or where we otherwise explicitly permit it, [you may not] access the Services through automated or non-human means, whether through a bot, script, or otherwise."*
16
+
17
+ 4. **Rate limits and fair use**: You are responsible for staying within the usage limits of your chosen plan. Excessive automated usage on consumer plans may result in account suspension by the service provider.
18
+
19
+ 5. **Permission handling**: This software can auto-approve or auto-deny permission requests based on user-configured policies. You are solely responsible for configuring policies appropriately and for any consequences of automated permission decisions.
20
+
21
+ 6. **Data and privacy**: You are responsible for ensuring that data processed through sessions complies with applicable privacy laws and regulations. Sessions may access files, run commands, and interact with external services on your behalf.
22
+
23
+ 7. **No endorsement**: This software is not endorsed by, affiliated with, or sponsored by Anthropic or any other AI service provider. All trademarks belong to their respective owners.
24
+
25
+ ## Your Instance, Your Responsibility
26
+
27
+ This is a self-hosted tool. You run it on your own infrastructure, with your own accounts, under your own credentials. The project authors have no access to, control over, or visibility into how you use this software. Compliance with all applicable terms and policies is entirely your responsibility.
28
+
29
+ ## No Legal Advice
30
+
31
+ Nothing in this software or its documentation constitutes legal advice. If you are unsure whether your intended use complies with applicable terms, consult the relevant service provider's terms directly or seek legal counsel.
32
+
33
+ ## References
34
+
35
+ - [Anthropic Consumer Terms of Service](https://www.anthropic.com/legal/consumer-terms)
36
+ - [Anthropic Commercial Terms of Service](https://www.anthropic.com/legal/commercial-terms)
37
+ - [Anthropic Usage Policy](https://www.anthropic.com/legal/aup)
38
+ - [Claude Code Documentation](https://code.claude.com/docs)
39
+ - [Using Claude Code with Pro or Max plan](https://support.claude.com/en/articles/11145838-using-claude-code-with-your-pro-or-max-plan)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 CodePiper Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,524 @@
1
+ <p align="center">
2
+ <img src="assets/logo/logo-transparent.png" alt="CodePiper" width="480" />
3
+ </p>
4
+
5
+ <p align="center">
6
+ <strong>Run and manage multiple AI coding sessions from a single control plane</strong><br/>
7
+ CLI + Web dashboard &middot; Permission policies &middot; Workflow orchestration &middot; Analytics
8
+ </p>
9
+
10
+ ---
11
+
12
+ # CodePiper
13
+
14
+ CodePiper is a daemon that spawns, monitors, and controls multiple concurrent provider sessions (currently [Claude Code](https://code.claude.com) and Codex CLI). Each session runs inside its own tmux pane with a real TTY, so every interaction works as close as possible to a normal terminal.
15
+
16
+ You get a CLI (`codepiper`) for scripting and automation, and an optional web dashboard for visual monitoring with live terminal views, conversation rendering, token analytics, and policy management.
17
+
18
+ ## System At A Glance
19
+
20
+ ```text
21
+ User
22
+ |- codepiper CLI -----------.
23
+ | |
24
+ '- Web Dashboard -----------+--> Daemon API --> Session Manager
25
+ |- tmux runtime
26
+ |- SQLite
27
+ '- Provider Registry
28
+ |- Claude Code
29
+ '- Codex CLI
30
+ ```
31
+
32
+ **Key capabilities:**
33
+
34
+ - **Multi-session control** — Start, stop, attach, send text, and send key sequences to any session
35
+ - **Permission policies** — Auto-approve or deny tool use via glob-pattern rules with full audit log
36
+ - **Web dashboard** — Real-time terminal, conversation view, token charts, workflow runner
37
+ - **Workflow orchestration** — Chain multi-session tasks via YAML/JSON definitions
38
+ - **Analytics** — Token usage, model distribution, cache efficiency, estimated cost
39
+ - **Transcript tailing** — JSONL ingestion with crash-safe byte-offset resumption
40
+ - **Secure by default** — Unix socket, password + TOTP auth, encrypted env storage
41
+
42
+ ## Why Teams Use CodePiper
43
+
44
+ - **Multi-device continuity** — Keep sessions running on one machine and continue monitoring/responding from another device via web dashboard.
45
+ - **Parallel execution** — Run implementation, review, and verification sessions concurrently.
46
+ - **Safer autonomy** — Apply explicit policy guardrails (`allow|deny|ask`) with auditable decision logs.
47
+ - **Provider unification** — Operate Claude Code and Codex sessions from one control plane.
48
+ - **Recoverability** — Resume/recover sessions after interruptions instead of losing context.
49
+
50
+ ### Common Use Cases
51
+
52
+ - **Parallel feature delivery** — one session writes code, another reviews diffs, another runs tests.
53
+ - **Multi-repo operations** — manage related services/repositories from one dashboard.
54
+ - **Long-running task monitoring** — receive completion signals without babysitting each terminal.
55
+ - **Secure AI workflows** — enforce policy boundaries while keeping a full decision audit trail.
56
+ - **Cross-device continuity** — start on desktop, check status/respond from laptop or mobile.
57
+
58
+ ## Provider Availability (Codex vs Claude Code)
59
+
60
+ | Capability | Claude Code | Codex |
61
+ |------------|-------------|-------|
62
+ | Native hook events | Yes | No |
63
+ | Policy channel | `native-hooks` | `input-preflight` |
64
+ | Dangerous mode | Yes | Yes |
65
+ | Provider resume/fork | Yes | Yes |
66
+ | Tmux recover/adopt | Yes | Yes |
67
+ | Transcript tailing | Yes | No |
68
+ | Model switch API | Yes | No |
69
+ | Token analytics fidelity | High (transcript) | Partial (PTY) |
70
+ | Session detail logs/events tabs | Yes | No (hidden) |
71
+
72
+ Detailed matrix: `docs/features/provider-capability-matrix.md`.
73
+ Contributor onboarding guide: `docs/features/provider-extensibility.md`.
74
+
75
+ ```text
76
+ /providers capability metadata
77
+ |
78
+ v
79
+ Web session-detail tab resolver
80
+ - nativeHooks OR supportsTranscriptTailing
81
+ -> terminal/git/policies/logs/events
82
+ - otherwise
83
+ -> terminal/git/policies
84
+ ```
85
+
86
+ ## Prerequisites
87
+
88
+ CodePiper needs Bun + tmux, and at least one provider CLI.
89
+
90
+ ### Required (core runtime)
91
+
92
+ | Dependency | Minimum version | Install |
93
+ |------------|-----------------|---------|
94
+ | **Bun** | 1.3.5+ | [bun.sh](https://bun.sh) — `curl -fsSL https://bun.sh/install \| bash` |
95
+ | **tmux** | 3.0+ | [tmux wiki](https://github.com/tmux/tmux/wiki/Installing) — macOS: `brew install tmux` |
96
+
97
+ ### Required (choose provider CLI)
98
+
99
+ | Dependency | Minimum version | Install |
100
+ |------------|-----------------|---------|
101
+ | **Claude Code** | latest | [Claude Code install](https://code.claude.com/docs/en/installation) — `npm install -g @anthropic-ai/claude-code` |
102
+ | **Codex CLI** | latest | [OpenAI Codex docs](https://developers.openai.com/codex) |
103
+
104
+ ### Optional (feature-specific)
105
+
106
+ | Dependency | Needed for |
107
+ |------------|------------|
108
+ | **git** | Git panel/routes (`/git/*`), worktree automation |
109
+ | **HTTPS origin + Web Push VAPID keys** | Remote/mobile push notifications |
110
+ | **Custom STT command binary** | `/sessions/:id/terminal/transcribe` voice transcription |
111
+
112
+ **Platform:** Linux or macOS (Windows requires WSL).
113
+
114
+ Supported target matrix:
115
+
116
+ | OS | Architectures |
117
+ |----|---------------|
118
+ | Linux | `x64`, `arm64` |
119
+ | macOS | `arm64`, `x64` |
120
+
121
+ Verify prerequisites are available:
122
+
123
+ ```bash
124
+ bun --version # should print 1.3.5 or higher
125
+ tmux -V # should print tmux 3.x
126
+ claude -v # should print the Claude Code version
127
+ codex --version # optional: required only for codex provider sessions
128
+ git --version # optional: required for Git features
129
+ ```
130
+
131
+ Linux `tmux` quick installs:
132
+
133
+ ```bash
134
+ # Debian/Ubuntu
135
+ sudo apt-get update && sudo apt-get install -y tmux
136
+
137
+ # Fedora/RHEL
138
+ sudo dnf install -y tmux
139
+
140
+ # Alpine
141
+ sudo apk add tmux
142
+ ```
143
+
144
+ ## Quick Start
145
+
146
+ ### Install from npm (global)
147
+
148
+ Use this path when installing CodePiper as a published package.
149
+
150
+ ```bash
151
+ # 0. Prerequisites (required before installing CodePiper)
152
+ bun --version # 1.3.5+
153
+ tmux -V # 3.x
154
+
155
+ # 1. Install CodePiper globally from npm
156
+ npm i -g codepiper
157
+
158
+ # 2. Verify install and environment
159
+ codepiper doctor
160
+
161
+ # 3. Start daemon (CLI-only)
162
+ codepiper daemon
163
+
164
+ # 4. Or start daemon with web dashboard
165
+ codepiper daemon --web
166
+ ```
167
+
168
+ `codepiper` is distributed as source TypeScript entrypoints and requires a local Bun runtime. Bun is not bundled inside the npm tarball.
169
+
170
+ If Bun is missing, you will typically see:
171
+
172
+ ```bash
173
+ /usr/bin/env: bun: No such file or directory
174
+ ```
175
+
176
+ Install Bun from [bun.sh](https://bun.sh) and rerun.
177
+
178
+ For deployment, troubleshooting, and FAQ, see:
179
+
180
+ - `docs/operations/production-deployment.md`
181
+ - `docs/operations/troubleshooting.md`
182
+ - `docs/operations/faq.md`
183
+ - `docs/operations/release-checklist.md` (maintainers)
184
+
185
+ ### Install from source (development checkout)
186
+
187
+ ```bash
188
+ # 1. Clone and install
189
+ git clone <repo-url> && cd codepiper
190
+ bun install
191
+
192
+ # 2. Link the CLI globally (makes `codepiper` available everywhere)
193
+ bun link
194
+
195
+ # 3. Verify prerequisites
196
+ codepiper doctor
197
+
198
+ # 4. Start the daemon (CLI-only)
199
+ codepiper daemon
200
+
201
+ # 5. In another terminal — start a session
202
+ codepiper start -p claude-code -d /path/to/repo
203
+ codepiper start -p codex -d /path/to/repo
204
+ codepiper sessions # list active sessions
205
+ codepiper attach <session-id> # attach to terminal
206
+ tmux attach-session -t codepiper-<session-id> # direct local tmux attach
207
+ codepiper send <session-id> "hello" # send a prompt
208
+ ```
209
+
210
+ On first run the daemon creates `~/.codepiper/` with a SQLite database and encryption secrets. All files are created with owner-only permissions (`0o600`/`0o700`).
211
+
212
+ ### New User Path (Web-First, Recommended)
213
+
214
+ ```bash
215
+ # 1) Build web assets (one-time, or whenever web UI changes)
216
+ bun run build:web
217
+
218
+ # 2) Start daemon with web dashboard
219
+ codepiper daemon --web
220
+ # or custom port
221
+ codepiper daemon --web --port 3456
222
+ ```
223
+
224
+ Then:
225
+ 1. Open `http://127.0.0.1:3000` (or your custom port).
226
+ 2. Complete onboarding:
227
+ 1. Set admin password.
228
+ 2. Set up and verify MFA (required before first sign-in).
229
+ 3. Create your first session in **Sessions**.
230
+ 4. Send a prompt from terminal/conversation view.
231
+
232
+ ### First-Run Onboarding (Mandatory MFA)
233
+
234
+ Web onboarding is a strict two-step flow:
235
+ 1. Set your admin password.
236
+ 2. Complete TOTP MFA setup and verification.
237
+
238
+ Until MFA verification succeeds, the dashboard remains in onboarding mode and does not issue a normal authenticated session.
239
+
240
+ MFA disable/reset is CLI-only:
241
+ ```bash
242
+ codepiper auth reset-mfa
243
+ ```
244
+
245
+ ### Direct Tmux Attach
246
+
247
+ Use this when you want to attach from your local terminal without going through CLI streaming:
248
+
249
+ ```bash
250
+ tmux attach-session -t codepiper-<session-id>
251
+ ```
252
+
253
+ Detach safely without stopping the session:
254
+
255
+ ```bash
256
+ # in attached tmux client
257
+ # press Ctrl+B, then D
258
+
259
+ # or from another terminal
260
+ tmux detach-client -s codepiper-<session-id>
261
+ ```
262
+
263
+ Avoid `exit`/`Ctrl+D` unless you intentionally want to stop that session process.
264
+
265
+ You can get the session ID from:
266
+
267
+ ```bash
268
+ codepiper sessions
269
+ ```
270
+
271
+ ## Web Dashboard
272
+
273
+ The web dashboard is embedded in the daemon process. Start with `--web`:
274
+
275
+ ```bash
276
+ # Build the web assets first (one-time)
277
+ bun run build:web
278
+
279
+ # Start daemon with web dashboard (port 3000)
280
+ codepiper daemon --web
281
+
282
+ # Or with a custom port
283
+ codepiper daemon --web --port 3456
284
+ ```
285
+
286
+ Dashboard pages:
287
+ - **Dashboard** - Session overview, active count, total messages, tokens
288
+ - **Sessions** - List, create, stop sessions; attach to terminal or conversation view
289
+ - **Analytics** - Token usage over time, model distribution, cache hit rate, tool usage, estimated API cost
290
+ - **Workflows** - Create and run multi-session workflows
291
+ - **Policies** - Manage permission rules, policy sets, and audit log
292
+ - **Settings** - Workspaces, environment sets, daemon controls (session preservation, default policy fallback, SSH agent forwarding, Codex host-access profile, terminal feature toggles, restart)
293
+
294
+ Theme selection supports multiple built-in presets and applies to both dashboard UI and web terminal palette. Themes are config-driven from `packages/web/src/lib/themes/themePresets.ts` and documented in `docs/features/theme-system.md` for contributors.
295
+
296
+ Terminal interaction notes:
297
+ - Desktop: type directly in the terminal surface (keyboard passthrough is primary).
298
+ - Mobile/touch: input controls and key strip remain available for explicit entry.
299
+ - Scroll/history mode is entered by scrolling up and exits automatically at bottom.
300
+ - Status badge shows stream state (`live`, `history`, or `disconnected`).
301
+ - Cursor position/visibility are synchronized from tmux over WebSocket for provider-accurate prompt rendering.
302
+ - Desktop image context: use the floating paperclip to attach files, paste screenshots with Cmd/Ctrl+V, or use the floating clipboard button (when browser supports async clipboard read).
303
+ - Drag-and-drop image files onto terminal surface is supported on desktop.
304
+ - Image attachments support PNG/JPEG/GIF/WebP up to 10MB each, with queue safeguards (max 5 per add action, 12 pending).
305
+
306
+ Daemon settings include `codexHostAccessProfileEnabled` for users who need host-level Codex workflows (for example, GPG signing). When enabled, new Codex sessions launch with `--sandbox danger-full-access -a on-request`; defaults remain unchanged and existing sessions are unaffected.
307
+
308
+ Daemon settings also expose an experimental Codex app-server scaffold flag (`terminalFeatures.codexAppServerSpikeEnabled`). It is off by default and currently tracks enrollment metadata only; Codex runtime remains tmux CLI in this phase. This flag is intentionally enable/disable only (no canary) because CodePiper is designed for single-user self-hosted deployments where staged rollout percentages are not useful.
309
+
310
+ Notification/push caveats:
311
+ - System notifications and push require a secure context (`https://` or `localhost`).
312
+ - Browser push support varies by platform/browser; unsupported environments gracefully fall back to in-app notifications.
313
+ - On iOS/iPadOS Safari, web push generally requires a Home Screen installed web app.
314
+ - For remote/mobile push, the dashboard origin must be reachable over HTTPS from the target device/browser.
315
+ - For local-only deployments (`127.0.0.1`), push is limited to the same local browser context.
316
+
317
+ The dashboard uses React + Tailwind + shadcn/ui + Recharts, served as static assets from `packages/web/dist/`.
318
+
319
+ When installed from npm, published packages are expected to include prebuilt `packages/web/dist/` assets. When running from source checkout, build web assets yourself (`bun run build:web`) before `--web`.
320
+
321
+ ## CLI Reference
322
+
323
+ ```
324
+ codepiper <command> [options]
325
+ ```
326
+
327
+ ### Session Commands
328
+
329
+ | Command | Description | Example |
330
+ |---------|-------------|---------|
331
+ | `start` | Start a new session | `codepiper start -p claude-code -d /path/to/repo` |
332
+ | `sessions` | List all sessions | `codepiper sessions --format json` |
333
+ | `attach` | Attach to a session | `codepiper attach <id>` |
334
+ | `send` | Send text to a session | `codepiper send <id> "what is 2+2?"` |
335
+ | `keys` | Send key sequences | `codepiper keys <id> ctrl+c` |
336
+ | `slash` | Execute slash command | `codepiper slash <id> status` |
337
+ | `tail` | Tail session output | `codepiper tail <id> --follow` |
338
+ | `model` | Get/switch model | `codepiper model <id> opus` |
339
+ | `logs` | View event logs | `codepiper logs <id> --follow` |
340
+
341
+ `start` supports `--dangerous` to bypass CodePiper policy checks for that session. This should only be used in trusted environments.
342
+
343
+ ### Management Commands
344
+
345
+ | Command | Description | Example |
346
+ |---------|-------------|---------|
347
+ | `daemon` | Start the daemon | `codepiper daemon --web --port 3456` |
348
+ | `stop` | Stop a session | `codepiper stop <id>` |
349
+ | `kill` | Force kill a session | `codepiper kill <id>` |
350
+ | `resize` | Resize session terminal | `codepiper resize <id> 120 40` |
351
+ | `policy` | Manage permission policies | `codepiper policy get <id>` |
352
+ | `policy-set` | Manage policy sets | `codepiper policy-set list` |
353
+ | `audit` | View policy decision log | `codepiper audit <id>` |
354
+ | `analytics` | View analytics | `codepiper analytics overview` |
355
+ | `auth` | Authentication management | `codepiper auth status` |
356
+ | `providers` | List provider capabilities | `codepiper providers --format json` |
357
+ | `workspace` | Manage workspaces | `codepiper workspace list` |
358
+ | `env-set` | Manage environment sets | `codepiper env-set list` |
359
+ | `workflow` | Manage workflows | `codepiper workflow create workflow.yaml` |
360
+ | `doctor` | Health check | `codepiper doctor` |
361
+
362
+ ### Daemon Options
363
+
364
+ ```
365
+ codepiper daemon [options]
366
+
367
+ Options:
368
+ --web Enable web dashboard
369
+ --port <port> HTTP port (default: 3000)
370
+ --web-dir <directory> Custom web assets directory
371
+ --detach Run daemon in background
372
+
373
+ Environment Variables:
374
+ CODEPIPER_SOCKET Unix socket path (default: /tmp/codepiper.sock)
375
+ CODEPIPER_DB_PATH SQLite database path (default: ~/.codepiper/codepiper.db)
376
+ CODEPIPER_WS_PORT WebSocket port (default: 9999)
377
+ CODEPIPER_HTTP_PORT HTTP port (default: 3000, overridden by --port)
378
+ CODEPIPER_FORCE_SECURE_COOKIES Optional (`1`) to force `Secure` auth cookies behind TLS-terminating proxies
379
+ CODEPIPER_TRUST_PROXY_HEADERS Optional (`1`) to trust proxy headers (`X-Forwarded-For`, `X-Real-IP`, `X-Forwarded-Proto`) for client IP and secure-cookie inference
380
+ CODEPIPER_PUSH_ENABLED Optional daemon push delivery toggle (`1` to enable)
381
+ CODEPIPER_PUSH_PUBLIC_KEY Optional Base64URL VAPID public key for daemon push delivery
382
+ CODEPIPER_PUSH_PRIVATE_KEY Optional Base64URL VAPID private key for daemon push delivery
383
+ CODEPIPER_PUSH_SUBJECT Optional VAPID subject (`mailto:` or `https://` URL)
384
+ VITE_PUSH_PUBLIC_KEY Optional Base64URL VAPID public key for web push enrollment
385
+ ```
386
+
387
+ Run `codepiper <command> --help` for detailed help on any command.
388
+
389
+ ## Project Structure
390
+
391
+ ```
392
+ codepiper/
393
+ ├── packages/
394
+ │ ├── core/ # Shared types, event bus, config, errors
395
+ │ ├── daemon/ # Daemon with HTTP/WS API, analytics, policies
396
+ │ │ └── src/
397
+ │ │ ├── api/ # HTTP routes, WebSocket, analytics
398
+ │ │ ├── auth/ # Authentication service, middleware, rate limiter
399
+ │ │ ├── config/ # Pricing configuration
400
+ │ │ ├── crypto/ # AES-256-GCM encryption for env sets
401
+ │ │ ├── db/ # SQLite schema, migrations
402
+ │ │ ├── git/ # Git utilities (status, diff, log, branches)
403
+ │ │ ├── sessions/ # Session manager, tmux, transcripts, policies
404
+ │ │ ├── tracking/ # Token usage tracker
405
+ │ │ └── workflows/ # Workflow DSL, runner, built-in templates
406
+ │ ├── cli/ # CLI client (22 commands)
407
+ │ ├── web/ # React web dashboard (Vite + Tailwind + shadcn/ui)
408
+ │ └── providers/ # Provider adapters (currently claude-code overlay integration)
409
+ ├── docs/ # Architecture, API, implementation docs
410
+ └── CLAUDE.md # Development guidelines
411
+ ```
412
+
413
+ ## Architecture
414
+
415
+ ### Daemon
416
+
417
+ - **Process**: Long-running daemon managing all sessions
418
+ - **Storage**: SQLite (sessions, events, transcript offsets, policies, token usage)
419
+ - **API**: HTTP over Unix socket (`/tmp/codepiper.sock`) + optional HTTP port
420
+ - **Streaming**: WebSocket for real-time PTY output and events
421
+ - **Web**: Serves React SPA when started with `--web`
422
+ - **Analytics**: Token tracking, model distribution, cost estimation
423
+ - **Cleanup**: Auto-cleanup of old sessions on startup (24h threshold)
424
+
425
+ ### Providers
426
+
427
+ | Provider | Status | Transport |
428
+ |----------|--------|-----------|
429
+ | **claude-code** | Production | Tmux + native hooks + transcript tailing |
430
+ | **codex** | Foundation | Tmux + input preflight policy checks |
431
+
432
+ ### Data Flow
433
+
434
+ ```
435
+ Provider session (tmux)
436
+ ├── Claude Code: Hooks → SessionStart/Notification/PermissionRequest/Stop
437
+ ├── Claude Code: Transcript → token extraction → token_usage table
438
+ ├── Codex: PTY stream + preflight policy checks (no native hooks)
439
+ └── Statusline (provider-dependent) → session metadata snapshots
440
+
441
+ Daemon
442
+ ├── SQLite: sessions, events, token_usage, policies, workflows
443
+ ├── Unix socket: CLI commands
444
+ ├── HTTP: web dashboard API + static assets
445
+ └── WebSocket: real-time PTY streaming
446
+ ```
447
+
448
+ ## Analytics
449
+
450
+ Token analytics are transcript-driven (currently strongest with Claude Code):
451
+
452
+ - **Token tracking** - Input, output, cache creation, cache read tokens per request
453
+ - **Model distribution** - Usage breakdown across Opus, Sonnet, Haiku
454
+ - **Cache efficiency** - Cache hit rate as percentage of total input tokens
455
+ - **Estimated API cost** - Equivalent cost if billed per-token (informational for Max plan users)
456
+
457
+ For providers without transcript token hooks (e.g., Codex), session counts remain accurate but token/cost metrics may be partial.
458
+
459
+ Pricing configuration lives in `packages/daemon/src/config/pricing.ts` and can be updated when Anthropic changes rates.
460
+
461
+ ## Disclaimer
462
+
463
+ CodePiper is provided "as is" without warranty. **You are solely responsible for compliance** with all third-party terms of service, including Anthropic's. If using CodePiper for automated or non-human-driven workflows, you **must** use API key billing (`--billing api`) per [Anthropic's Terms of Service](https://www.anthropic.com/legal/consumer-terms). See [LEGAL_NOTICE.md](LEGAL_NOTICE.md) for full details.
464
+
465
+ ## Security
466
+
467
+ ### Billing Modes
468
+
469
+ Sessions support two billing modes via `--billing` flag or `billingMode` API parameter:
470
+ - **`subscription`** (default) — Scrubs `ANTHROPIC_API_KEY`, uses Max plan billing. For interactive, human-driven use.
471
+ - **`api`** — Preserves `ANTHROPIC_API_KEY`, uses API billing. **Required for automated/agentic workflows** per Anthropic ToS.
472
+
473
+ ### Local-First Security
474
+
475
+ - Unix socket communication restricted to current user
476
+ - Unix socket API is trusted local access (no session token required)
477
+ - HTTP/WebSocket dashboard routes enforce session auth when auth is configured
478
+ - MFA disable/reset is CLI-only (`codepiper auth reset-mfa`) to reduce browser downgrade risk
479
+ - Browser-originated mutating HTTP API requests require same-origin (CSRF mitigation)
480
+ - Input validation prevents injection attacks
481
+ - Audit logs for all permission decisions
482
+ - Remote access recommended via SSH port forwarding
483
+
484
+ ## Development
485
+
486
+ ```bash
487
+ # Run tests
488
+ bun test
489
+
490
+ # Run with coverage
491
+ bun test --coverage
492
+
493
+ # Lint
494
+ bun run lint
495
+
496
+ # Auto-fix
497
+ bun run lint:fix
498
+
499
+ # Full check (format + lint + test)
500
+ bun run check
501
+ ```
502
+
503
+ ## References
504
+
505
+ - [Claude Code CLI](https://code.claude.com/docs/en/cli-reference)
506
+ - [Claude Code Hooks](https://code.claude.com/docs/en/hooks)
507
+ - [Claude Code Settings](https://code.claude.com/docs/en/settings)
508
+ - [Bun PTY API](https://bun.com/blog/bun-v1.3.5)
509
+ - [Tmux Manual](https://www.man7.org/linux/man-pages/man1/tmux.1.html)
510
+ - [Documentation Index](docs/README.md)
511
+ - [Provider Capability Matrix](docs/features/provider-capability-matrix.md)
512
+ - [Provider Extensibility Guide](docs/features/provider-extensibility.md)
513
+ - [Production Deployment Guide](docs/operations/production-deployment.md)
514
+ - [Troubleshooting](docs/operations/troubleshooting.md)
515
+ - [FAQ](docs/operations/faq.md)
516
+ - [Release Checklist](docs/operations/release-checklist.md)
517
+ - [Contributing](CONTRIBUTING.md)
518
+ - [Security Policy](SECURITY.md)
519
+ - [Changelog](CHANGELOG.md)
520
+ - [TODO](TODO.md)
521
+
522
+ ## License
523
+
524
+ MIT