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.
- package/.env.example +28 -0
- package/CHANGELOG.md +10 -0
- package/LEGAL_NOTICE.md +39 -0
- package/LICENSE +21 -0
- package/README.md +524 -0
- package/package.json +90 -0
- package/packages/cli/package.json +13 -0
- package/packages/cli/src/commands/analytics.ts +157 -0
- package/packages/cli/src/commands/attach.ts +299 -0
- package/packages/cli/src/commands/audit.ts +50 -0
- package/packages/cli/src/commands/auth.ts +261 -0
- package/packages/cli/src/commands/daemon.ts +162 -0
- package/packages/cli/src/commands/doctor.ts +303 -0
- package/packages/cli/src/commands/env-set.ts +162 -0
- package/packages/cli/src/commands/hook-forward.ts +268 -0
- package/packages/cli/src/commands/keys.ts +77 -0
- package/packages/cli/src/commands/kill.ts +19 -0
- package/packages/cli/src/commands/logs.ts +419 -0
- package/packages/cli/src/commands/model.ts +172 -0
- package/packages/cli/src/commands/policy-set.ts +185 -0
- package/packages/cli/src/commands/policy.ts +227 -0
- package/packages/cli/src/commands/providers.ts +114 -0
- package/packages/cli/src/commands/resize.ts +34 -0
- package/packages/cli/src/commands/send.ts +184 -0
- package/packages/cli/src/commands/sessions.ts +202 -0
- package/packages/cli/src/commands/slash.ts +92 -0
- package/packages/cli/src/commands/start.ts +243 -0
- package/packages/cli/src/commands/stop.ts +19 -0
- package/packages/cli/src/commands/tail.ts +137 -0
- package/packages/cli/src/commands/workflow.ts +786 -0
- package/packages/cli/src/commands/workspace.ts +127 -0
- package/packages/cli/src/lib/api.ts +78 -0
- package/packages/cli/src/lib/args.ts +72 -0
- package/packages/cli/src/lib/format.ts +93 -0
- package/packages/cli/src/main.ts +563 -0
- package/packages/core/package.json +7 -0
- package/packages/core/src/config.ts +30 -0
- package/packages/core/src/errors.ts +38 -0
- package/packages/core/src/eventBus.ts +56 -0
- package/packages/core/src/eventBusAdapter.ts +143 -0
- package/packages/core/src/index.ts +10 -0
- package/packages/core/src/sqliteEventBus.ts +336 -0
- package/packages/core/src/types.ts +63 -0
- package/packages/daemon/package.json +11 -0
- package/packages/daemon/src/api/analyticsRoutes.ts +343 -0
- package/packages/daemon/src/api/authRoutes.ts +344 -0
- package/packages/daemon/src/api/bodyLimit.ts +133 -0
- package/packages/daemon/src/api/envSetRoutes.ts +170 -0
- package/packages/daemon/src/api/gitRoutes.ts +409 -0
- package/packages/daemon/src/api/hooks.ts +588 -0
- package/packages/daemon/src/api/inputPolicy.ts +249 -0
- package/packages/daemon/src/api/notificationRoutes.ts +532 -0
- package/packages/daemon/src/api/policyRoutes.ts +234 -0
- package/packages/daemon/src/api/policySetRoutes.ts +445 -0
- package/packages/daemon/src/api/routeUtils.ts +28 -0
- package/packages/daemon/src/api/routes.ts +1004 -0
- package/packages/daemon/src/api/server.ts +1388 -0
- package/packages/daemon/src/api/settingsRoutes.ts +367 -0
- package/packages/daemon/src/api/sqliteErrors.ts +47 -0
- package/packages/daemon/src/api/stt.ts +143 -0
- package/packages/daemon/src/api/terminalRoutes.ts +200 -0
- package/packages/daemon/src/api/validation.ts +287 -0
- package/packages/daemon/src/api/validationRoutes.ts +174 -0
- package/packages/daemon/src/api/workflowRoutes.ts +567 -0
- package/packages/daemon/src/api/workspaceRoutes.ts +151 -0
- package/packages/daemon/src/api/ws.ts +1588 -0
- package/packages/daemon/src/auth/apiRateLimiter.ts +73 -0
- package/packages/daemon/src/auth/authMiddleware.ts +305 -0
- package/packages/daemon/src/auth/authService.ts +496 -0
- package/packages/daemon/src/auth/rateLimiter.ts +137 -0
- package/packages/daemon/src/config/pricing.ts +79 -0
- package/packages/daemon/src/crypto/encryption.ts +196 -0
- package/packages/daemon/src/db/db.ts +2745 -0
- package/packages/daemon/src/db/index.ts +16 -0
- package/packages/daemon/src/db/migrations.ts +182 -0
- package/packages/daemon/src/db/policyDb.ts +349 -0
- package/packages/daemon/src/db/schema.sql +408 -0
- package/packages/daemon/src/db/workflowDb.ts +464 -0
- package/packages/daemon/src/git/gitUtils.ts +544 -0
- package/packages/daemon/src/index.ts +6 -0
- package/packages/daemon/src/main.ts +525 -0
- package/packages/daemon/src/notifications/pushNotifier.ts +369 -0
- package/packages/daemon/src/providers/codexAppServerScaffold.ts +49 -0
- package/packages/daemon/src/providers/registry.ts +111 -0
- package/packages/daemon/src/providers/types.ts +82 -0
- package/packages/daemon/src/sessions/auditLogger.ts +103 -0
- package/packages/daemon/src/sessions/policyEngine.ts +165 -0
- package/packages/daemon/src/sessions/policyMatcher.ts +114 -0
- package/packages/daemon/src/sessions/policyTypes.ts +94 -0
- package/packages/daemon/src/sessions/ptyProcess.ts +141 -0
- package/packages/daemon/src/sessions/sessionManager.ts +1770 -0
- package/packages/daemon/src/sessions/tmuxSession.ts +1073 -0
- package/packages/daemon/src/sessions/transcriptManager.ts +110 -0
- package/packages/daemon/src/sessions/transcriptParser.ts +149 -0
- package/packages/daemon/src/sessions/transcriptTailer.ts +214 -0
- package/packages/daemon/src/tracking/tokenTracker.ts +168 -0
- package/packages/daemon/src/workflows/contextManager.ts +83 -0
- package/packages/daemon/src/workflows/index.ts +31 -0
- package/packages/daemon/src/workflows/resultExtractor.ts +118 -0
- package/packages/daemon/src/workflows/waitConditionPoller.ts +131 -0
- package/packages/daemon/src/workflows/workflowParser.ts +217 -0
- package/packages/daemon/src/workflows/workflowRunner.ts +969 -0
- package/packages/daemon/src/workflows/workflowTypes.ts +188 -0
- package/packages/daemon/src/workflows/workflowValidator.ts +533 -0
- package/packages/providers/claude-code/package.json +11 -0
- package/packages/providers/claude-code/src/index.ts +7 -0
- package/packages/providers/claude-code/src/overlaySettings.ts +198 -0
- package/packages/providers/claude-code/src/provider.ts +311 -0
- package/packages/web/dist/android-chrome-192x192.png +0 -0
- package/packages/web/dist/android-chrome-512x512.png +0 -0
- package/packages/web/dist/apple-touch-icon.png +0 -0
- package/packages/web/dist/assets/AnalyticsPage-BIopKWRf.js +17 -0
- package/packages/web/dist/assets/PoliciesPage-CjdLN3dl.js +11 -0
- package/packages/web/dist/assets/SessionDetailPage-BtSA0V0M.js +179 -0
- package/packages/web/dist/assets/SettingsPage-Dbbz4Ca5.js +37 -0
- package/packages/web/dist/assets/WorkflowsPage-Dv6f3GgU.js +1 -0
- package/packages/web/dist/assets/chart-vendor-DlOHLaCG.js +49 -0
- package/packages/web/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/packages/web/dist/assets/css.worker-BvV5MPou.js +93 -0
- package/packages/web/dist/assets/editor.worker-CKy7Pnvo.js +26 -0
- package/packages/web/dist/assets/html.worker-BLJhxQJQ.js +470 -0
- package/packages/web/dist/assets/index-BbdhRfr2.css +1 -0
- package/packages/web/dist/assets/index-hgphORiw.js +204 -0
- package/packages/web/dist/assets/json.worker-usMZ-FED.js +58 -0
- package/packages/web/dist/assets/monaco-core-B_19GPAS.css +1 -0
- package/packages/web/dist/assets/monaco-core-DQ5Mk8AK.js +1234 -0
- package/packages/web/dist/assets/monaco-react-DfZNWvtW.js +11 -0
- package/packages/web/dist/assets/monacoSetup-DvBj52bT.js +1 -0
- package/packages/web/dist/assets/pencil-Dbczxz59.js +11 -0
- package/packages/web/dist/assets/react-vendor-B5MgMUHH.js +136 -0
- package/packages/web/dist/assets/refresh-cw-B0MGsYPL.js +6 -0
- package/packages/web/dist/assets/tabs-C8LsWiR5.js +1 -0
- package/packages/web/dist/assets/terminal-vendor-Cs8KPbV3.js +9 -0
- package/packages/web/dist/assets/terminal-vendor-LcAfv9l9.css +32 -0
- package/packages/web/dist/assets/trash-2-Btlg0d4l.js +6 -0
- package/packages/web/dist/assets/ts.worker-DGHjMaqB.js +67731 -0
- package/packages/web/dist/favicon.ico +0 -0
- package/packages/web/dist/icon.svg +1 -0
- package/packages/web/dist/index.html +29 -0
- package/packages/web/dist/manifest.json +29 -0
- package/packages/web/dist/og-image.png +0 -0
- package/packages/web/dist/originals/android-chrome-192x192.png +0 -0
- package/packages/web/dist/originals/android-chrome-512x512.png +0 -0
- package/packages/web/dist/originals/apple-touch-icon.png +0 -0
- package/packages/web/dist/originals/favicon.ico +0 -0
- package/packages/web/dist/piper.svg +1 -0
- package/packages/web/dist/sounds/codepiper-soft-chime.wav +0 -0
- package/packages/web/dist/sw.js +257 -0
- package/scripts/postinstall-link-workspaces.mjs +58 -0
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { runAnalyticsCommand } from "./commands/analytics";
|
|
4
|
+
import { runAttachCommand } from "./commands/attach";
|
|
5
|
+
import { runAuditCommand } from "./commands/audit";
|
|
6
|
+
import { runAuthCommand } from "./commands/auth";
|
|
7
|
+
import { runDaemonCommand } from "./commands/daemon";
|
|
8
|
+
import { runDoctorCommand } from "./commands/doctor";
|
|
9
|
+
import { runEnvSetCommand } from "./commands/env-set";
|
|
10
|
+
import { runHookForwardCommand } from "./commands/hook-forward";
|
|
11
|
+
import { runKeysCommand } from "./commands/keys";
|
|
12
|
+
import { runKillCommand } from "./commands/kill";
|
|
13
|
+
import { runLogsCommand } from "./commands/logs";
|
|
14
|
+
import { runModelCommand } from "./commands/model";
|
|
15
|
+
import { runPolicyCommand } from "./commands/policy";
|
|
16
|
+
import { runPolicySetCommand } from "./commands/policy-set";
|
|
17
|
+
import { runProvidersCommand } from "./commands/providers";
|
|
18
|
+
import { runResizeCommand } from "./commands/resize";
|
|
19
|
+
import { runSendCommand } from "./commands/send";
|
|
20
|
+
import { runSessionsCommand } from "./commands/sessions";
|
|
21
|
+
import { runSlashCommand } from "./commands/slash";
|
|
22
|
+
import { runStartCommand } from "./commands/start";
|
|
23
|
+
import { runStopCommand } from "./commands/stop";
|
|
24
|
+
import { runTailCommand } from "./commands/tail";
|
|
25
|
+
import { runWorkflowCommand } from "./commands/workflow";
|
|
26
|
+
import { runWorkspaceCommand } from "./commands/workspace";
|
|
27
|
+
|
|
28
|
+
const COMMANDS = {
|
|
29
|
+
auth: runAuthCommand,
|
|
30
|
+
daemon: runDaemonCommand,
|
|
31
|
+
start: runStartCommand,
|
|
32
|
+
stop: runStopCommand,
|
|
33
|
+
kill: runKillCommand,
|
|
34
|
+
resize: runResizeCommand,
|
|
35
|
+
sessions: runSessionsCommand,
|
|
36
|
+
attach: runAttachCommand,
|
|
37
|
+
send: runSendCommand,
|
|
38
|
+
keys: runKeysCommand,
|
|
39
|
+
slash: runSlashCommand,
|
|
40
|
+
tail: runTailCommand,
|
|
41
|
+
model: runModelCommand,
|
|
42
|
+
providers: runProvidersCommand,
|
|
43
|
+
policy: runPolicyCommand,
|
|
44
|
+
"policy-set": runPolicySetCommand,
|
|
45
|
+
audit: runAuditCommand,
|
|
46
|
+
analytics: runAnalyticsCommand,
|
|
47
|
+
workspace: runWorkspaceCommand,
|
|
48
|
+
"env-set": runEnvSetCommand,
|
|
49
|
+
logs: runLogsCommand,
|
|
50
|
+
doctor: runDoctorCommand,
|
|
51
|
+
workflow: runWorkflowCommand,
|
|
52
|
+
"hook-forward": runHookForwardCommand,
|
|
53
|
+
} as const;
|
|
54
|
+
|
|
55
|
+
type CommandName = keyof typeof COMMANDS;
|
|
56
|
+
|
|
57
|
+
function printUsage(): void {
|
|
58
|
+
console.log(`Usage: codepiper <command> [options]
|
|
59
|
+
|
|
60
|
+
Commands:
|
|
61
|
+
auth Manage authentication (status, reset-password, reset-mfa, sessions)
|
|
62
|
+
daemon Start/stop/status of the codepiper daemon
|
|
63
|
+
start Start a new session
|
|
64
|
+
stop Stop a session gracefully
|
|
65
|
+
kill Force kill a session
|
|
66
|
+
resize Resize a session terminal
|
|
67
|
+
sessions List all sessions
|
|
68
|
+
attach Attach to a session (interactive or follow mode)
|
|
69
|
+
send Send text to a session
|
|
70
|
+
keys Send key sequences to a session
|
|
71
|
+
slash Execute a slash command in a session
|
|
72
|
+
tail Tail session output log
|
|
73
|
+
model Get or switch model for a session (claude-code only)
|
|
74
|
+
providers List supported providers and capabilities
|
|
75
|
+
policy Manage permission policies (list, get, create, update, delete, toggle, default)
|
|
76
|
+
policy-set Manage policy sets (list, get, create, update, delete, add-policy, remove-policy)
|
|
77
|
+
audit View policy decision audit log
|
|
78
|
+
analytics View analytics (overview, sessions, tools, costs, activity)
|
|
79
|
+
workspace Manage workspaces (list, get, create, update, delete)
|
|
80
|
+
env-set Manage environment sets (list, get, create, update, delete)
|
|
81
|
+
logs View event logs for a session
|
|
82
|
+
doctor Run diagnostics and health checks
|
|
83
|
+
workflow Manage and execute workflows
|
|
84
|
+
|
|
85
|
+
Internal Commands (called by hooks, not for direct use):
|
|
86
|
+
hook-forward Forward hook events to daemon
|
|
87
|
+
|
|
88
|
+
Options:
|
|
89
|
+
-h, --help Show help for a command
|
|
90
|
+
|
|
91
|
+
Examples:
|
|
92
|
+
codepiper daemon --detach # Start daemon in background
|
|
93
|
+
codepiper daemon stop # Stop daemon
|
|
94
|
+
codepiper start --provider claude-code --dir /path # Start session
|
|
95
|
+
codepiper start --provider codex --dir /path # Start Codex session
|
|
96
|
+
codepiper stop <session-id> # Stop session
|
|
97
|
+
codepiper sessions # List sessions
|
|
98
|
+
codepiper attach <session-id> # Attach to session
|
|
99
|
+
codepiper policy list # List all policies
|
|
100
|
+
codepiper policy-set list # List policy sets
|
|
101
|
+
codepiper analytics # View analytics overview
|
|
102
|
+
codepiper workspace list # List workspaces
|
|
103
|
+
codepiper audit --session <id> # View audit log
|
|
104
|
+
|
|
105
|
+
For more information, visit: https://github.com/codepiper/codepiper
|
|
106
|
+
`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function printCommandHelp(command: CommandName): void {
|
|
110
|
+
const help: Record<CommandName, string> = {
|
|
111
|
+
auth: `Usage: codepiper auth <subcommand> [options]
|
|
112
|
+
|
|
113
|
+
Manage authentication and security settings.
|
|
114
|
+
|
|
115
|
+
Subcommands:
|
|
116
|
+
status Show auth configuration status
|
|
117
|
+
reset-password Reset the dashboard password
|
|
118
|
+
reset-mfa Disable two-factor authentication
|
|
119
|
+
sessions List active login sessions
|
|
120
|
+
revoke-all Revoke all active sessions
|
|
121
|
+
|
|
122
|
+
Options:
|
|
123
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
124
|
+
|
|
125
|
+
Examples:
|
|
126
|
+
codepiper auth status
|
|
127
|
+
codepiper auth reset-password
|
|
128
|
+
codepiper auth reset-mfa
|
|
129
|
+
codepiper auth sessions
|
|
130
|
+
codepiper auth revoke-all`,
|
|
131
|
+
|
|
132
|
+
daemon: `Usage: codepiper daemon [start|stop|status] [options]
|
|
133
|
+
|
|
134
|
+
Start, stop, or check status of the codepiper daemon.
|
|
135
|
+
|
|
136
|
+
Subcommands:
|
|
137
|
+
start Start the daemon (default if no subcommand)
|
|
138
|
+
stop Stop the running daemon
|
|
139
|
+
status Show daemon status
|
|
140
|
+
|
|
141
|
+
Options:
|
|
142
|
+
-s, --socket <path> Unix socket path (default: /tmp/codepiper.sock)
|
|
143
|
+
--detach Start daemon in background
|
|
144
|
+
--web Enable web dashboard
|
|
145
|
+
--port <port> HTTP port for web dashboard (default: 3000)
|
|
146
|
+
--web-dir <directory> Custom web assets directory
|
|
147
|
+
|
|
148
|
+
Examples:
|
|
149
|
+
codepiper daemon # Start daemon (foreground)
|
|
150
|
+
codepiper daemon --detach # Start daemon (background)
|
|
151
|
+
codepiper daemon --detach --socket /tmp/codepiper-dev.sock
|
|
152
|
+
codepiper daemon --detach --web # Background + web dashboard
|
|
153
|
+
codepiper daemon stop # Stop daemon
|
|
154
|
+
codepiper daemon status # Check daemon status
|
|
155
|
+
|
|
156
|
+
Environment Variables:
|
|
157
|
+
CODEPIPER_SOCKET Unix socket path (default: /tmp/codepiper.sock)
|
|
158
|
+
CODEPIPER_DB_PATH SQLite database path (default: ~/.codepiper/codepiper.db)
|
|
159
|
+
CODEPIPER_WS_PORT WebSocket port (default: 9999)
|
|
160
|
+
CODEPIPER_HTTP_PORT HTTP port (default: 3000, overridden by --port)`,
|
|
161
|
+
|
|
162
|
+
start: `Usage: codepiper start [options]
|
|
163
|
+
|
|
164
|
+
Start a new session with the specified provider.
|
|
165
|
+
|
|
166
|
+
Options:
|
|
167
|
+
-p, --provider <provider> Provider to use (claude-code, codex)
|
|
168
|
+
-d, --dir <directory> Working directory (default: current directory)
|
|
169
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
170
|
+
-b, --billing <mode> Billing mode: subscription (default) or api
|
|
171
|
+
--dangerous Bypass CodePiper policy checks for this session
|
|
172
|
+
--env-set <id> Environment set to apply (repeatable)
|
|
173
|
+
--worktree Enable git worktree isolation
|
|
174
|
+
--create-branch <name> Create a new branch in worktree
|
|
175
|
+
--workspace <id> Workspace to use
|
|
176
|
+
--validate Validate configuration before starting
|
|
177
|
+
-- [args...] Additional arguments to pass to the provider
|
|
178
|
+
|
|
179
|
+
Examples:
|
|
180
|
+
codepiper start --provider claude-code
|
|
181
|
+
codepiper start -p claude-code -d /path/to/repo
|
|
182
|
+
codepiper start -p codex -d /path/to/repo
|
|
183
|
+
codepiper start --provider claude-code --worktree --create-branch feature-x
|
|
184
|
+
codepiper start --provider codex --dangerous
|
|
185
|
+
codepiper start --provider claude-code --env-set prod-keys
|
|
186
|
+
codepiper start --provider claude-code -- --verbose`,
|
|
187
|
+
|
|
188
|
+
stop: `Usage: codepiper stop <session-id> [options]
|
|
189
|
+
|
|
190
|
+
Stop a session gracefully.
|
|
191
|
+
|
|
192
|
+
Options:
|
|
193
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
194
|
+
|
|
195
|
+
Examples:
|
|
196
|
+
codepiper stop abc123def`,
|
|
197
|
+
|
|
198
|
+
kill: `Usage: codepiper kill <session-id> [options]
|
|
199
|
+
|
|
200
|
+
Force kill a session.
|
|
201
|
+
|
|
202
|
+
Options:
|
|
203
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
204
|
+
|
|
205
|
+
Examples:
|
|
206
|
+
codepiper kill abc123def`,
|
|
207
|
+
|
|
208
|
+
resize: `Usage: codepiper resize <session-id> <cols> <rows> [options]
|
|
209
|
+
|
|
210
|
+
Resize a session terminal.
|
|
211
|
+
|
|
212
|
+
Options:
|
|
213
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
214
|
+
|
|
215
|
+
Examples:
|
|
216
|
+
codepiper resize abc123def 120 40`,
|
|
217
|
+
|
|
218
|
+
sessions: `Usage: codepiper sessions [options]
|
|
219
|
+
|
|
220
|
+
List all sessions managed by the daemon.
|
|
221
|
+
|
|
222
|
+
Options:
|
|
223
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
224
|
+
-f, --format <format> Output format (table, json) (default: table)
|
|
225
|
+
-p, --provider <provider> Filter by provider
|
|
226
|
+
--status <status> Filter by status
|
|
227
|
+
|
|
228
|
+
Examples:
|
|
229
|
+
codepiper sessions
|
|
230
|
+
codepiper sessions --format json
|
|
231
|
+
codepiper sessions --provider claude-code --status RUNNING`,
|
|
232
|
+
|
|
233
|
+
attach: `Usage: codepiper attach <session-id> [options]
|
|
234
|
+
|
|
235
|
+
Attach to a running session for interactive use or to follow output.
|
|
236
|
+
|
|
237
|
+
Options:
|
|
238
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
239
|
+
-f, --follow Follow mode (read-only, no input)
|
|
240
|
+
|
|
241
|
+
Examples:
|
|
242
|
+
codepiper attach abc123def
|
|
243
|
+
codepiper attach abc123def --follow`,
|
|
244
|
+
|
|
245
|
+
send: `Usage: codepiper send <session-id> [text] [options]
|
|
246
|
+
|
|
247
|
+
Send text and/or an image to a session.
|
|
248
|
+
|
|
249
|
+
Options:
|
|
250
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
251
|
+
-n, --newline Append newline (default: true)
|
|
252
|
+
--no-newline Don't append newline
|
|
253
|
+
-i, --image <path-or-url> Attach an image (local file or URL)
|
|
254
|
+
|
|
255
|
+
Examples:
|
|
256
|
+
codepiper send abc123def "What is the capital of France?"
|
|
257
|
+
codepiper send abc123def "Analyze this" --image ./screenshot.png
|
|
258
|
+
codepiper send abc123def --image ./chart.png
|
|
259
|
+
codepiper send abc123def -i https://example.com/diagram.png "Explain this"
|
|
260
|
+
codepiper send abc123def "partial text" --no-newline`,
|
|
261
|
+
|
|
262
|
+
keys: `Usage: codepiper keys <session-id> <key...> [options]
|
|
263
|
+
|
|
264
|
+
Send key sequences to a session.
|
|
265
|
+
|
|
266
|
+
Options:
|
|
267
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
268
|
+
|
|
269
|
+
Supported keys:
|
|
270
|
+
ctrl+c, ctrl+d, ctrl+r, enter, escape, tab, up, down, left, right
|
|
271
|
+
|
|
272
|
+
Examples:
|
|
273
|
+
codepiper keys abc123def ctrl+c
|
|
274
|
+
codepiper keys abc123def enter
|
|
275
|
+
codepiper keys abc123def up up enter`,
|
|
276
|
+
|
|
277
|
+
slash: `Usage: codepiper slash <session-id> <command> [args...] [options]
|
|
278
|
+
|
|
279
|
+
Execute a slash command in a session.
|
|
280
|
+
|
|
281
|
+
Options:
|
|
282
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
283
|
+
|
|
284
|
+
Examples:
|
|
285
|
+
codepiper slash abc123def status
|
|
286
|
+
codepiper slash abc123def help
|
|
287
|
+
codepiper slash abc123def clear`,
|
|
288
|
+
|
|
289
|
+
model: `Usage: codepiper model <session-id> [model] [options]
|
|
290
|
+
|
|
291
|
+
Get or switch model for a session (claude-code only).
|
|
292
|
+
|
|
293
|
+
Options:
|
|
294
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
295
|
+
|
|
296
|
+
Available models:
|
|
297
|
+
sonnet, opus, haiku, opusplan
|
|
298
|
+
claude-sonnet-4-5, claude-opus-4-6, claude-haiku-4-5
|
|
299
|
+
|
|
300
|
+
Examples:
|
|
301
|
+
codepiper model abc123def # Get current model
|
|
302
|
+
codepiper model abc123def sonnet # Switch to sonnet
|
|
303
|
+
codepiper model abc123def claude-opus-4-6 # Switch to opus`,
|
|
304
|
+
|
|
305
|
+
providers: `Usage: codepiper providers [options]
|
|
306
|
+
|
|
307
|
+
List provider capabilities reported by the daemon.
|
|
308
|
+
|
|
309
|
+
Options:
|
|
310
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
311
|
+
-f, --format <format> Output format (table, json) (default: table)
|
|
312
|
+
|
|
313
|
+
Examples:
|
|
314
|
+
codepiper providers
|
|
315
|
+
codepiper providers --format json`,
|
|
316
|
+
|
|
317
|
+
policy: `Usage: codepiper policy <subcommand> [options]
|
|
318
|
+
|
|
319
|
+
Manage permission policies.
|
|
320
|
+
|
|
321
|
+
Subcommands:
|
|
322
|
+
list List all policies
|
|
323
|
+
get <id> Show policy details
|
|
324
|
+
create Create a new policy
|
|
325
|
+
update <id> Update a policy
|
|
326
|
+
delete <id> Delete a policy
|
|
327
|
+
toggle <id> Toggle policy enabled/disabled
|
|
328
|
+
|
|
329
|
+
Options:
|
|
330
|
+
--session <id> Filter by or assign to session
|
|
331
|
+
--name <name> Policy name
|
|
332
|
+
--rules <json> Policy rules (JSON string)
|
|
333
|
+
--priority <n> Policy priority
|
|
334
|
+
--enabled <bool> Enable/disable
|
|
335
|
+
|
|
336
|
+
Examples:
|
|
337
|
+
codepiper policy list
|
|
338
|
+
codepiper policy list --session abc123def
|
|
339
|
+
codepiper policy get 1
|
|
340
|
+
codepiper policy create --name "Allow reads" --rules '[{"pattern":"Read","action":"allow"}]'
|
|
341
|
+
codepiper policy toggle 1`,
|
|
342
|
+
|
|
343
|
+
"policy-set": `Usage: codepiper policy-set <subcommand> [options]
|
|
344
|
+
|
|
345
|
+
Manage policy sets.
|
|
346
|
+
|
|
347
|
+
Subcommands:
|
|
348
|
+
list List all policy sets
|
|
349
|
+
get <id> Show policy set details with member policies
|
|
350
|
+
create Create a new policy set
|
|
351
|
+
update <id> Update a policy set
|
|
352
|
+
delete <id> Delete a policy set
|
|
353
|
+
add-policy <set-id> <policy-id> Add a policy to the set
|
|
354
|
+
remove-policy <set-id> <policy-id> Remove a policy from the set
|
|
355
|
+
|
|
356
|
+
Options:
|
|
357
|
+
--name <name> Set name
|
|
358
|
+
--description <desc> Set description
|
|
359
|
+
--default Mark as default (auto-applied to new sessions)
|
|
360
|
+
|
|
361
|
+
Examples:
|
|
362
|
+
codepiper policy-set list
|
|
363
|
+
codepiper policy-set create --name "Production" --default
|
|
364
|
+
codepiper policy-set add-policy 1 5`,
|
|
365
|
+
|
|
366
|
+
audit: `Usage: codepiper audit [options]
|
|
367
|
+
|
|
368
|
+
View policy decision audit log.
|
|
369
|
+
|
|
370
|
+
Options:
|
|
371
|
+
--session <id> Filter by session
|
|
372
|
+
--limit <n> Number of decisions to show (default: 50)
|
|
373
|
+
-s, --socket <path> Daemon socket path
|
|
374
|
+
|
|
375
|
+
Examples:
|
|
376
|
+
codepiper audit
|
|
377
|
+
codepiper audit --session abc123def
|
|
378
|
+
codepiper audit --limit 100`,
|
|
379
|
+
|
|
380
|
+
analytics: `Usage: codepiper analytics [subcommand] [options]
|
|
381
|
+
|
|
382
|
+
View analytics and usage statistics.
|
|
383
|
+
|
|
384
|
+
Subcommands:
|
|
385
|
+
overview Summary statistics (default)
|
|
386
|
+
sessions Session metrics
|
|
387
|
+
tools Tool usage breakdown
|
|
388
|
+
costs Token costs and billing
|
|
389
|
+
activity Activity timeline
|
|
390
|
+
|
|
391
|
+
Options:
|
|
392
|
+
--days <n> Time range in days (default: 7)
|
|
393
|
+
-s, --socket <path> Daemon socket path
|
|
394
|
+
|
|
395
|
+
Examples:
|
|
396
|
+
codepiper analytics
|
|
397
|
+
codepiper analytics costs --days 30
|
|
398
|
+
codepiper analytics tools`,
|
|
399
|
+
|
|
400
|
+
workspace: `Usage: codepiper workspace <subcommand> [options]
|
|
401
|
+
|
|
402
|
+
Manage workspaces.
|
|
403
|
+
|
|
404
|
+
Subcommands:
|
|
405
|
+
list List all workspaces
|
|
406
|
+
get <id> Show workspace details
|
|
407
|
+
create Create a new workspace
|
|
408
|
+
update <id> Update a workspace
|
|
409
|
+
delete <id> Delete a workspace
|
|
410
|
+
|
|
411
|
+
Options:
|
|
412
|
+
--name <name> Workspace name
|
|
413
|
+
--path <path> Workspace directory path
|
|
414
|
+
--description <desc> Workspace description
|
|
415
|
+
|
|
416
|
+
Examples:
|
|
417
|
+
codepiper workspace list
|
|
418
|
+
codepiper workspace create --name "Backend" --path /opt/repos/backend
|
|
419
|
+
codepiper workspace get 1`,
|
|
420
|
+
|
|
421
|
+
"env-set": `Usage: codepiper env-set <subcommand> [options]
|
|
422
|
+
|
|
423
|
+
Manage environment variable sets.
|
|
424
|
+
|
|
425
|
+
Subcommands:
|
|
426
|
+
list List all environment sets
|
|
427
|
+
get <id> Show env set details with variables
|
|
428
|
+
create Create a new env set
|
|
429
|
+
update <id> Update an env set
|
|
430
|
+
delete <id> Delete an env set
|
|
431
|
+
|
|
432
|
+
Options:
|
|
433
|
+
--name <name> Set name
|
|
434
|
+
--description <desc> Set description
|
|
435
|
+
--var KEY=VALUE Add a variable (repeatable)
|
|
436
|
+
|
|
437
|
+
Examples:
|
|
438
|
+
codepiper env-set list
|
|
439
|
+
codepiper env-set create --name "Production" --var API_KEY=xxx --var DB_HOST=prod-db
|
|
440
|
+
codepiper env-set get 1`,
|
|
441
|
+
|
|
442
|
+
tail: `Usage: codepiper tail <session-id> [options]
|
|
443
|
+
|
|
444
|
+
Tail the session output log file.
|
|
445
|
+
|
|
446
|
+
Options:
|
|
447
|
+
-f, --follow Follow mode (stream new output)
|
|
448
|
+
-n, --lines <count> Number of lines to show (default: 50)
|
|
449
|
+
|
|
450
|
+
Examples:
|
|
451
|
+
codepiper tail abc123def
|
|
452
|
+
codepiper tail abc123def --lines 100
|
|
453
|
+
codepiper tail abc123def --follow`,
|
|
454
|
+
|
|
455
|
+
logs: `Usage: codepiper logs <session-id> [options]
|
|
456
|
+
|
|
457
|
+
View event logs for a session.
|
|
458
|
+
|
|
459
|
+
Options:
|
|
460
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
461
|
+
-f, --follow Follow mode (stream new events)
|
|
462
|
+
-n, --tail <count> Number of events to show (default: 100)
|
|
463
|
+
--since <event-id> Show events after this ID
|
|
464
|
+
--format <format> Output format (pretty, json) (default: pretty)
|
|
465
|
+
|
|
466
|
+
Examples:
|
|
467
|
+
codepiper logs abc123def
|
|
468
|
+
codepiper logs abc123def --tail 50
|
|
469
|
+
codepiper logs abc123def --follow
|
|
470
|
+
codepiper logs abc123def --format json`,
|
|
471
|
+
|
|
472
|
+
doctor: `Usage: codepiper doctor [options]
|
|
473
|
+
|
|
474
|
+
Run diagnostics to check the health of the codepiper installation.
|
|
475
|
+
|
|
476
|
+
Checks:
|
|
477
|
+
- Claude Code installation and version
|
|
478
|
+
- Environment variables (ANTHROPIC_API_KEY warning)
|
|
479
|
+
- Daemon status
|
|
480
|
+
|
|
481
|
+
Options:
|
|
482
|
+
-s, --socket <path> Daemon socket path (default: /tmp/codepiper.sock)
|
|
483
|
+
|
|
484
|
+
Examples:
|
|
485
|
+
codepiper doctor`,
|
|
486
|
+
|
|
487
|
+
workflow: `Usage: codepiper workflow <subcommand> [options]
|
|
488
|
+
|
|
489
|
+
Manage and execute workflows.
|
|
490
|
+
|
|
491
|
+
Subcommands:
|
|
492
|
+
create Create a workflow from a YAML or JSON file
|
|
493
|
+
list List all workflows
|
|
494
|
+
show Show a workflow definition
|
|
495
|
+
run Execute a workflow
|
|
496
|
+
status Get execution status
|
|
497
|
+
cancel Cancel a running execution
|
|
498
|
+
logs View execution logs
|
|
499
|
+
|
|
500
|
+
Examples:
|
|
501
|
+
codepiper workflow create workflow.yaml
|
|
502
|
+
codepiper workflow list
|
|
503
|
+
codepiper workflow run <workflow-id>
|
|
504
|
+
codepiper workflow status <execution-id>`,
|
|
505
|
+
|
|
506
|
+
"hook-forward": `Usage: codepiper hook-forward
|
|
507
|
+
|
|
508
|
+
INTERNAL COMMAND - Not for direct use
|
|
509
|
+
|
|
510
|
+
This command is called by Claude Code hooks to forward events to the daemon.
|
|
511
|
+
It reads JSON from stdin, POSTs to the daemon's hooks endpoint, and handles
|
|
512
|
+
PermissionRequest responses.
|
|
513
|
+
|
|
514
|
+
Environment variables (set by daemon when spawning session):
|
|
515
|
+
CODEPIPER_UNIX_SOCK Path to daemon socket
|
|
516
|
+
CODEPIPER_SESSION Session ID for metadata
|
|
517
|
+
CODEPIPER_SECRET Authentication token
|
|
518
|
+
|
|
519
|
+
Exit codes:
|
|
520
|
+
0 Success
|
|
521
|
+
2 Block action (for PermissionRequest deny)
|
|
522
|
+
1 Error`,
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
console.log(help[command]);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
async function main(): Promise<void> {
|
|
529
|
+
const args = process.argv.slice(2);
|
|
530
|
+
|
|
531
|
+
if (args.length === 0 || args[0] === "-h" || args[0] === "--help") {
|
|
532
|
+
printUsage();
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const command = args[0] as CommandName;
|
|
537
|
+
|
|
538
|
+
if (args[1] === "-h" || args[1] === "--help") {
|
|
539
|
+
if (command in COMMANDS) {
|
|
540
|
+
printCommandHelp(command);
|
|
541
|
+
} else {
|
|
542
|
+
printUsage();
|
|
543
|
+
}
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (!(command in COMMANDS)) {
|
|
548
|
+
console.error(`Error: Unknown command '${command}'`);
|
|
549
|
+
console.error("Run 'codepiper --help' for usage information.");
|
|
550
|
+
process.exit(1);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
const commandArgs = args.slice(1);
|
|
554
|
+
|
|
555
|
+
try {
|
|
556
|
+
await COMMANDS[command](commandArgs);
|
|
557
|
+
} catch (error: any) {
|
|
558
|
+
console.error(`Error: ${error.message}`);
|
|
559
|
+
process.exit(1);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
main();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration management for the CodePiper system
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
export interface Config {
|
|
8
|
+
socketPath: string;
|
|
9
|
+
dataDir: string;
|
|
10
|
+
maxSessions: number;
|
|
11
|
+
logLevel: "debug" | "info" | "warn" | "error";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function getDefaultConfig(): Config {
|
|
15
|
+
const homeDir = process.env.HOME || process.env.USERPROFILE || "/tmp";
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
socketPath: "/tmp/codepiper.sock",
|
|
19
|
+
dataDir: join(homeDir, ".codepiper"),
|
|
20
|
+
maxSessions: 10,
|
|
21
|
+
logLevel: "info",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function loadConfig(custom?: Partial<Config>): Config {
|
|
26
|
+
return {
|
|
27
|
+
...getDefaultConfig(),
|
|
28
|
+
...custom,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error types for the CodePiper system
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export class CodePiperError extends Error {
|
|
6
|
+
constructor(message: string) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "CodePiperError";
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class SessionNotFoundError extends CodePiperError {
|
|
13
|
+
constructor(public sessionId: string) {
|
|
14
|
+
super(`Session not found: ${sessionId}`);
|
|
15
|
+
this.name = "SessionNotFoundError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class ProviderError extends CodePiperError {
|
|
20
|
+
constructor(
|
|
21
|
+
public provider: string,
|
|
22
|
+
message: string
|
|
23
|
+
) {
|
|
24
|
+
super(`[${provider}] ${message}`);
|
|
25
|
+
this.name = "ProviderError";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class InvalidSessionStateError extends CodePiperError {
|
|
30
|
+
constructor(
|
|
31
|
+
public sessionId: string,
|
|
32
|
+
public expectedState: string,
|
|
33
|
+
public actualState: string
|
|
34
|
+
) {
|
|
35
|
+
super(`Invalid session state for ${sessionId}: expected ${expectedState}, got ${actualState}`);
|
|
36
|
+
this.name = "InvalidSessionStateError";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event bus for inter-component communication
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
type Handler<T> = (data: T) => void;
|
|
6
|
+
type Unsubscribe = () => void;
|
|
7
|
+
|
|
8
|
+
export class EventBus<EventMap extends Record<string, any> = Record<string, any>> {
|
|
9
|
+
private handlers: Map<keyof EventMap, Set<Handler<any>>> = new Map();
|
|
10
|
+
|
|
11
|
+
on<K extends keyof EventMap>(event: K, handler: Handler<EventMap[K]>): Unsubscribe {
|
|
12
|
+
if (!this.handlers.has(event)) {
|
|
13
|
+
this.handlers.set(event, new Set());
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.handlers.get(event)?.add(handler);
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
const handlers = this.handlers.get(event);
|
|
20
|
+
if (handlers) {
|
|
21
|
+
handlers.delete(handler);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
once<K extends keyof EventMap>(event: K, handler: Handler<EventMap[K]>): Unsubscribe {
|
|
27
|
+
const wrappedHandler = (data: EventMap[K]) => {
|
|
28
|
+
handler(data);
|
|
29
|
+
unsubscribe();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const unsubscribe = this.on(event, wrappedHandler);
|
|
33
|
+
return unsubscribe;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
emit<K extends keyof EventMap>(event: K, data: EventMap[K]): void {
|
|
37
|
+
const handlers = this.handlers.get(event);
|
|
38
|
+
if (!handlers) return;
|
|
39
|
+
|
|
40
|
+
for (const handler of handlers) {
|
|
41
|
+
try {
|
|
42
|
+
handler(data);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(`Error in event handler for ${String(event)}:`, error);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
removeAllListeners<K extends keyof EventMap>(event?: K): void {
|
|
50
|
+
if (event) {
|
|
51
|
+
this.handlers.delete(event);
|
|
52
|
+
} else {
|
|
53
|
+
this.handlers.clear();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|