clideck 1.22.2
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/LICENSE +21 -0
- package/README.md +77 -0
- package/activity.js +56 -0
- package/agent-presets.json +93 -0
- package/assets/clideck-themes.jpg +0 -0
- package/bin/clideck.js +2 -0
- package/config.js +96 -0
- package/handlers.js +297 -0
- package/opencode-bridge.js +148 -0
- package/opencode-plugin/clideck-bridge.js +24 -0
- package/package.json +47 -0
- package/paths.js +41 -0
- package/plugin-loader.js +285 -0
- package/plugins/trim-clip/clideck-plugin.json +13 -0
- package/plugins/trim-clip/client.js +31 -0
- package/plugins/trim-clip/index.js +10 -0
- package/plugins/voice-input/clideck-plugin.json +49 -0
- package/plugins/voice-input/client.js +196 -0
- package/plugins/voice-input/index.js +342 -0
- package/plugins/voice-input/python/mel_filters.npz +0 -0
- package/plugins/voice-input/python/whisper_turbo.py +416 -0
- package/plugins/voice-input/python/worker.py +135 -0
- package/public/fx/bold-beep-idle.mp3 +0 -0
- package/public/fx/default-beep.mp3 +0 -0
- package/public/fx/echo-beep-idle.mp3 +0 -0
- package/public/fx/musical-beep-idle.mp3 +0 -0
- package/public/fx/small-bleep-idle.mp3 +0 -0
- package/public/fx/soft-beep.mp3 +0 -0
- package/public/fx/space-idle.mp3 +0 -0
- package/public/img/claude-code.png +0 -0
- package/public/img/clideck-logo-icon.png +0 -0
- package/public/img/clideck-logo-terminal-panel.png +0 -0
- package/public/img/codex.png +0 -0
- package/public/img/gemini.png +0 -0
- package/public/img/opencode.png +0 -0
- package/public/index.html +243 -0
- package/public/js/app.js +794 -0
- package/public/js/color-mode.js +51 -0
- package/public/js/confirm.js +27 -0
- package/public/js/creator.js +201 -0
- package/public/js/drag.js +134 -0
- package/public/js/folder-picker.js +81 -0
- package/public/js/hotkeys.js +90 -0
- package/public/js/nav.js +56 -0
- package/public/js/profiles.js +22 -0
- package/public/js/prompts.js +325 -0
- package/public/js/settings.js +489 -0
- package/public/js/state.js +15 -0
- package/public/js/terminals.js +905 -0
- package/public/js/toast.js +62 -0
- package/public/js/utils.js +27 -0
- package/public/tailwind.css +1 -0
- package/server.js +126 -0
- package/sessions.js +375 -0
- package/telemetry-receiver.js +129 -0
- package/themes.js +247 -0
- package/transcript.js +90 -0
- package/utils.js +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Or Kuntzman
|
|
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,77 @@
|
|
|
1
|
+
# CliDeck
|
|
2
|
+
|
|
3
|
+
One screen for all your AI coding agents.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
You're running Claude Code, Codex, and Gemini CLI in separate terminals. You switch between them constantly, forget which one finished, and lose sessions when you close the lid. CliDeck puts them all on one screen with live status, so you always know what's happening.
|
|
8
|
+
|
|
9
|
+
CliDeck is a local dashboard that runs all your CLI agents in one browser tab. It tracks which agents are working, which are idle, and notifies you when they need attention. Everything runs on your machine — nothing leaves localhost.
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -g clideck
|
|
15
|
+
clideck
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Open [http://localhost:4000](http://localhost:4000). Click **+**, pick an agent, start working.
|
|
19
|
+
|
|
20
|
+
Or run directly without installing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx clideck
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## What You Get
|
|
27
|
+
|
|
28
|
+
- **Live status** — see which agents are working and which are done, without checking each terminal
|
|
29
|
+
- **Session resume** — close CliDeck, reopen it tomorrow, resume your Claude Code conversation where you left off
|
|
30
|
+
- **Notifications** — browser and sound alerts the moment an agent finishes or needs input
|
|
31
|
+
- **Message previews** — latest output from each agent, right in the sidebar
|
|
32
|
+
- **Projects** — group sessions by project with drag-and-drop
|
|
33
|
+
- **Search** — find any session by name or scroll back through transcript content
|
|
34
|
+
- **Prompt Library** — save reusable prompts and paste them into any terminal by typing `//`
|
|
35
|
+
- **Plugins** — ships with Voice Input and Trim Clip. Build your own with the plugin API
|
|
36
|
+
- **15 themes** — dark and light built-in, plus custom theme support
|
|
37
|
+
- **Zero interference** — native PTY terminals, your keystrokes go straight to the agent, nothing in between
|
|
38
|
+
|
|
39
|
+
## Supported Agents
|
|
40
|
+
|
|
41
|
+
CliDeck auto-detects whether each agent is working or idle:
|
|
42
|
+
|
|
43
|
+
| Agent | Status detection | Setup |
|
|
44
|
+
|-------|-----------------|-------|
|
|
45
|
+
| **Claude Code** | Automatic | Nothing to configure |
|
|
46
|
+
| **Codex** | Automatic | One-click setup in CliDeck |
|
|
47
|
+
| **Gemini CLI** | Automatic | One-click setup in CliDeck |
|
|
48
|
+
| **OpenCode** | Via plugin bridge | One-click setup in CliDeck |
|
|
49
|
+
| **Shell** | I/O activity only | None |
|
|
50
|
+
|
|
51
|
+
Claude Code works out of the box. Other agents need a one-time configuration that CliDeck walks you through.
|
|
52
|
+
|
|
53
|
+
## How It Works
|
|
54
|
+
|
|
55
|
+
Each agent runs in a native terminal (PTY). CliDeck receives lightweight status signals from agents via OpenTelemetry — it sees *that* an agent is working, not *what* it's working on. Your prompts and responses are never read or stored by CliDeck.
|
|
56
|
+
|
|
57
|
+
OpenTelemetry runs locally between the agent and CliDeck. No data is collected, transmitted, or stored outside your machine.
|
|
58
|
+
|
|
59
|
+
## Prompt Library
|
|
60
|
+
|
|
61
|
+
Save prompts you use often and paste them into any terminal session instantly. Open the Prompts panel from the sidebar, click **+** to add a prompt with a name and text.
|
|
62
|
+
|
|
63
|
+
To use a prompt, type `//` in any terminal — an autocomplete dropdown appears. Type a few letters to filter, arrow keys to navigate, Enter to paste. The prompt text is sent directly to the active terminal.
|
|
64
|
+
|
|
65
|
+
## Platform Support
|
|
66
|
+
|
|
67
|
+
Tested on **macOS** and **Windows**. Works in any modern browser. Linux: untested — if you try it, open an issue and let me know.
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
Full setup guides, agent configuration, and plugin development:
|
|
72
|
+
|
|
73
|
+
**[Documentation](https://clideck.dev/)**
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT
|
package/activity.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Per-session I/O tracking and burst detection.
|
|
2
|
+
// Broadcasts rate + burst data so the frontend can derive working/idle status.
|
|
3
|
+
|
|
4
|
+
let interval = null;
|
|
5
|
+
const net = {}; // id → byte counters
|
|
6
|
+
const stream = {}; // id → burst timing
|
|
7
|
+
|
|
8
|
+
function ensure(id) {
|
|
9
|
+
if (!net[id]) net[id] = { in: 0, out: 0, prevIn: 0, prevOut: 0 };
|
|
10
|
+
if (!stream[id]) stream[id] = { lastOutAt: 0, burstStart: 0 };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function trackIn(id, bytes) {
|
|
14
|
+
ensure(id);
|
|
15
|
+
net[id].in += bytes;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function trackOut(id, data) {
|
|
19
|
+
ensure(id);
|
|
20
|
+
const now = Date.now();
|
|
21
|
+
const s = stream[id];
|
|
22
|
+
net[id].out += data.length;
|
|
23
|
+
if (now - s.lastOutAt > 2000) s.burstStart = now;
|
|
24
|
+
s.lastOutAt = now;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function start(sessions, broadcast) {
|
|
28
|
+
if (interval) return;
|
|
29
|
+
interval = setInterval(() => {
|
|
30
|
+
if (!sessions.size) return;
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const stats = {};
|
|
33
|
+
for (const [id] of sessions) {
|
|
34
|
+
ensure(id);
|
|
35
|
+
const n = net[id];
|
|
36
|
+
const s = stream[id];
|
|
37
|
+
const rawRateOut = n.out - n.prevOut;
|
|
38
|
+
const rawRateIn = n.in - n.prevIn;
|
|
39
|
+
n.prevOut = n.out;
|
|
40
|
+
n.prevIn = n.in;
|
|
41
|
+
const silence = s.lastOutAt ? now - s.lastOutAt : 0;
|
|
42
|
+
const burstMs = s.burstStart && silence < 2000 ? now - s.burstStart : 0;
|
|
43
|
+
stats[id] = { rawRateOut, rawRateIn, burstMs };
|
|
44
|
+
}
|
|
45
|
+
if (Object.keys(stats).length) broadcast({ type: 'stats', stats });
|
|
46
|
+
}, 1000);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function stop() {
|
|
50
|
+
clearInterval(interval);
|
|
51
|
+
interval = null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function clear(id) { delete net[id]; delete stream[id]; }
|
|
55
|
+
|
|
56
|
+
module.exports = { start, stop, trackIn, trackOut, clear };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"presetId": "claude-code",
|
|
4
|
+
"name": "Claude Code",
|
|
5
|
+
"icon": "/img/claude-code.png",
|
|
6
|
+
"command": "claude",
|
|
7
|
+
"isAgent": true,
|
|
8
|
+
"canResume": true,
|
|
9
|
+
"resumeCommand": "claude --resume {{sessionId}}",
|
|
10
|
+
"sessionIdPattern": "Session ID:\\s+([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})",
|
|
11
|
+
"outputMarker": "\u23fa",
|
|
12
|
+
"telemetryConfigPath": "Built-in (no configuration needed)",
|
|
13
|
+
"telemetryEnv": {
|
|
14
|
+
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
|
|
15
|
+
"OTEL_LOGS_EXPORTER": "otlp",
|
|
16
|
+
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
|
|
17
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:{{port}}",
|
|
18
|
+
"OTEL_LOGS_EXPORT_INTERVAL": "2000"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"presetId": "codex",
|
|
23
|
+
"name": "Codex",
|
|
24
|
+
"icon": "/img/codex.png",
|
|
25
|
+
"command": "codex --no-alt-screen",
|
|
26
|
+
"isAgent": true,
|
|
27
|
+
"canResume": true,
|
|
28
|
+
"resumeCommand": "codex resume {{sessionId}} --no-alt-screen",
|
|
29
|
+
"sessionIdPattern": "Session:\\s+([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})",
|
|
30
|
+
"outputMarker": "\u2022",
|
|
31
|
+
"telemetryConfigPath": "~/.codex/config.toml",
|
|
32
|
+
"telemetryEnv": {
|
|
33
|
+
"OTEL_LOGS_EXPORTER": "otlp",
|
|
34
|
+
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
|
|
35
|
+
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:{{port}}",
|
|
36
|
+
"OTEL_LOGS_EXPORT_INTERVAL": "2000"
|
|
37
|
+
},
|
|
38
|
+
"telemetrySetup": "For best experience, add to ~/.codex/config.toml:\n\n[otel]\nexporter = { otlp-http = { endpoint = \"http://localhost:{{port}}/v1/logs\", protocol = \"json\" } }",
|
|
39
|
+
"telemetryAutoSetup": {
|
|
40
|
+
"label": "Configure automatically"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"presetId": "gemini-cli",
|
|
45
|
+
"name": "Gemini CLI",
|
|
46
|
+
"icon": "/img/gemini.png",
|
|
47
|
+
"command": "gemini",
|
|
48
|
+
"isAgent": true,
|
|
49
|
+
"canResume": true,
|
|
50
|
+
"resumeCommand": "gemini --resume {{sessionId}}",
|
|
51
|
+
"sessionIdPattern": "Session ID:\\s+([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})",
|
|
52
|
+
"outputMarker": "\u2726",
|
|
53
|
+
"telemetryConfigPath": "~/.gemini/settings.json",
|
|
54
|
+
"telemetryEnv": {
|
|
55
|
+
"GEMINI_TELEMETRY_ENABLED": "true",
|
|
56
|
+
"GEMINI_TELEMETRY_TARGET": "local",
|
|
57
|
+
"GEMINI_TELEMETRY_OTLP_ENDPOINT": "http://localhost:{{port}}",
|
|
58
|
+
"GEMINI_TELEMETRY_OTLP_PROTOCOL": "http"
|
|
59
|
+
},
|
|
60
|
+
"telemetrySetup": "For best experience, add to ~/.gemini/settings.json:\n\n{\n \"telemetry\": {\n \"enabled\": true,\n \"target\": \"local\",\n \"otlpEndpoint\": \"http://localhost:{{port}}/v1/logs\",\n \"otlpProtocol\": \"http\",\n \"logPrompts\": true\n }\n}",
|
|
61
|
+
"telemetryAutoSetup": {
|
|
62
|
+
"label": "Configure automatically"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"presetId": "opencode",
|
|
67
|
+
"name": "OpenCode",
|
|
68
|
+
"icon": "/img/opencode.png",
|
|
69
|
+
"command": "opencode",
|
|
70
|
+
"isAgent": true,
|
|
71
|
+
"canResume": true,
|
|
72
|
+
"resumeCommand": "opencode --session {{sessionId}}",
|
|
73
|
+
"sessionIdPattern": "(ses_[a-zA-Z0-9]{10,})",
|
|
74
|
+
"outputMarker": "\u2502",
|
|
75
|
+
"bridge": "opencode",
|
|
76
|
+
"pluginPath": "~/.config/opencode/plugins/clideck-bridge.js",
|
|
77
|
+
"pluginSetup": "Install the CliDeck bridge plugin to enable real-time status and resume.\n\ncp opencode-plugin/clideck-bridge.js ~/.config/opencode/plugins/",
|
|
78
|
+
"telemetryAutoSetup": {
|
|
79
|
+
"label": "Install plugin"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"presetId": "shell",
|
|
84
|
+
"name": "Shell",
|
|
85
|
+
"icon": "terminal",
|
|
86
|
+
"command": "/bin/zsh",
|
|
87
|
+
"isAgent": false,
|
|
88
|
+
"canResume": false,
|
|
89
|
+
"resumeCommand": null,
|
|
90
|
+
"sessionIdPattern": null,
|
|
91
|
+
"outputMarker": null
|
|
92
|
+
}
|
|
93
|
+
]
|
|
Binary file
|
package/bin/clideck.js
ADDED
package/config.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
const { readFileSync, writeFileSync, existsSync } = require('fs');
|
|
2
|
+
const { join } = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const { DATA_DIR } = require('./paths');
|
|
5
|
+
const { defaultShell, binName } = require('./utils');
|
|
6
|
+
|
|
7
|
+
const CONFIG_PATH = join(DATA_DIR, 'config.json');
|
|
8
|
+
|
|
9
|
+
const DEFAULTS = {
|
|
10
|
+
defaultPath: join(os.homedir(), 'Documents'),
|
|
11
|
+
commands: [
|
|
12
|
+
{
|
|
13
|
+
id: '1', label: 'Shell', icon: 'terminal', command: defaultShell, enabled: true,
|
|
14
|
+
defaultPath: '', isAgent: false, canResume: false, resumeCommand: null, sessionIdPattern: null,
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
confirmClose: true,
|
|
18
|
+
notifySoundEnabled: true,
|
|
19
|
+
notifySound: 'soft-beep',
|
|
20
|
+
defaultTheme: 'catppuccin-mocha',
|
|
21
|
+
defaultShell,
|
|
22
|
+
prompts: [],
|
|
23
|
+
projects: [],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function deepCopy(obj) { return JSON.parse(JSON.stringify(obj)); }
|
|
27
|
+
|
|
28
|
+
const PRESETS = JSON.parse(readFileSync(join(__dirname, 'agent-presets.json'), 'utf8'));
|
|
29
|
+
for (const p of PRESETS) if (p.presetId === 'shell') p.command = defaultShell;
|
|
30
|
+
|
|
31
|
+
function matchPreset(cmd) {
|
|
32
|
+
const bin = binName(cmd.command);
|
|
33
|
+
return PRESETS.find(p => binName(p.command) === bin);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function migrate(cfg) {
|
|
37
|
+
// Migrate profiles → defaultTheme
|
|
38
|
+
if (cfg.profiles && !cfg.defaultTheme) {
|
|
39
|
+
const defProfile = cfg.profiles.find(p => p.id === cfg.defaultProfile) || cfg.profiles[0];
|
|
40
|
+
cfg.defaultTheme = defProfile?.themeId || 'default';
|
|
41
|
+
}
|
|
42
|
+
delete cfg.profiles;
|
|
43
|
+
delete cfg.defaultProfile;
|
|
44
|
+
if (!cfg.defaultTheme || cfg.defaultTheme === 'solarized-dark') cfg.defaultTheme = 'catppuccin-mocha';
|
|
45
|
+
// Backfill and sync fields from presets
|
|
46
|
+
for (const cmd of cfg.commands) {
|
|
47
|
+
const preset = matchPreset(cmd);
|
|
48
|
+
// Icon always syncs from preset — the preset is the source of truth for logos
|
|
49
|
+
if (preset) cmd.icon = preset.icon;
|
|
50
|
+
else if (!cmd.icon) cmd.icon = 'terminal';
|
|
51
|
+
if (cmd.isAgent === undefined) cmd.isAgent = preset?.isAgent ?? false;
|
|
52
|
+
if (cmd.canResume === undefined) cmd.canResume = preset?.canResume ?? false;
|
|
53
|
+
if (cmd.resumeCommand === undefined) cmd.resumeCommand = preset?.resumeCommand || null;
|
|
54
|
+
if (cmd.sessionIdPattern === undefined) cmd.sessionIdPattern = preset?.sessionIdPattern || null;
|
|
55
|
+
if (cmd.outputMarker === undefined) cmd.outputMarker = preset?.outputMarker || null;
|
|
56
|
+
// Claude Code telemetry is built-in, always on
|
|
57
|
+
if (preset?.presetId === 'claude-code') cmd.telemetryEnabled = true;
|
|
58
|
+
else if (cmd.telemetryEnabled === undefined) cmd.telemetryEnabled = false;
|
|
59
|
+
if (cmd.telemetryStatus === undefined) cmd.telemetryStatus = null;
|
|
60
|
+
// Sync bridge config from preset
|
|
61
|
+
if (preset?.bridge) cmd.bridge = preset.bridge;
|
|
62
|
+
// Codex: add --no-alt-screen to avoid blank screen in embedded xterm
|
|
63
|
+
if (preset?.presetId === 'codex') {
|
|
64
|
+
if (cmd.command === 'codex') cmd.command = preset.command;
|
|
65
|
+
if (cmd.resumeCommand === 'codex resume {{sessionId}}') cmd.resumeCommand = preset.resumeCommand;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Auto-add any shipped presets not yet in the commands list
|
|
69
|
+
for (const preset of PRESETS) {
|
|
70
|
+
const exists = cfg.commands.some(c => matchPreset(c)?.presetId === preset.presetId);
|
|
71
|
+
if (!exists) {
|
|
72
|
+
cfg.commands.push({
|
|
73
|
+
id: crypto.randomUUID(), label: preset.name, icon: preset.icon,
|
|
74
|
+
command: preset.command, enabled: true, defaultPath: '',
|
|
75
|
+
isAgent: preset.isAgent, canResume: preset.canResume,
|
|
76
|
+
resumeCommand: preset.resumeCommand, sessionIdPattern: preset.sessionIdPattern,
|
|
77
|
+
outputMarker: preset.outputMarker || null,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!cfg.projects) cfg.projects = [];
|
|
82
|
+
return cfg;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function load() {
|
|
86
|
+
if (!existsSync(CONFIG_PATH)) return deepCopy(DEFAULTS);
|
|
87
|
+
try {
|
|
88
|
+
return migrate({ ...deepCopy(DEFAULTS), ...JSON.parse(readFileSync(CONFIG_PATH, 'utf8')) });
|
|
89
|
+
} catch { return deepCopy(DEFAULTS); }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function save(config) {
|
|
93
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
module.exports = { load, save };
|
package/handlers.js
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
const { readFileSync, writeFileSync, mkdirSync, existsSync, copyFileSync, unlinkSync } = require('fs');
|
|
2
|
+
const { join, dirname } = require('path');
|
|
3
|
+
const os = require('os');
|
|
4
|
+
const config = require('./config');
|
|
5
|
+
const sessions = require('./sessions');
|
|
6
|
+
const themes = require('./themes');
|
|
7
|
+
const presets = JSON.parse(readFileSync(join(__dirname, 'agent-presets.json'), 'utf8'));
|
|
8
|
+
const { listDirs, binName, defaultShell } = require('./utils');
|
|
9
|
+
for (const p of presets) if (p.presetId === 'shell') p.command = defaultShell;
|
|
10
|
+
const transcript = require('./transcript');
|
|
11
|
+
const plugins = require('./plugin-loader');
|
|
12
|
+
|
|
13
|
+
let cfg = config.load();
|
|
14
|
+
if (detectTelemetryConfig(cfg)) config.save(cfg);
|
|
15
|
+
|
|
16
|
+
function detectTelemetryConfig(c) {
|
|
17
|
+
const home = os.homedir();
|
|
18
|
+
const port = '4000';
|
|
19
|
+
let changed = false;
|
|
20
|
+
for (const cmd of c.commands || []) {
|
|
21
|
+
const bin = binName(cmd.command);
|
|
22
|
+
const preset = presets.find(p => binName(p.command) === bin);
|
|
23
|
+
if (!preset) continue;
|
|
24
|
+
let detected = false;
|
|
25
|
+
if (preset.presetId === 'claude-code') {
|
|
26
|
+
detected = true;
|
|
27
|
+
} else if (preset.presetId === 'codex') {
|
|
28
|
+
try {
|
|
29
|
+
const content = readFileSync(join(home, '.codex', 'config.toml'), 'utf8');
|
|
30
|
+
detected = content.includes('[otel]') && content.includes(`localhost:${port}`);
|
|
31
|
+
} catch {}
|
|
32
|
+
} else if (preset.presetId === 'gemini-cli') {
|
|
33
|
+
try {
|
|
34
|
+
const s = JSON.parse(readFileSync(join(home, '.gemini', 'settings.json'), 'utf8'));
|
|
35
|
+
detected = !!s.telemetry?.enabled && (s.telemetry?.otlpEndpoint || '').includes(`localhost:${port}`);
|
|
36
|
+
} catch {}
|
|
37
|
+
} else if (preset.presetId === 'opencode') {
|
|
38
|
+
const ocPlugins = join(home, '.config', 'opencode', 'plugins');
|
|
39
|
+
detected = existsSync(join(ocPlugins, 'clideck-bridge.js')) || existsSync(join(ocPlugins, 'termix-bridge.js'));
|
|
40
|
+
} else { continue; }
|
|
41
|
+
if (detected !== !!cmd.telemetryEnabled) {
|
|
42
|
+
cmd.telemetryEnabled = detected;
|
|
43
|
+
cmd.telemetryStatus = detected ? { ok: true } : null;
|
|
44
|
+
changed = true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (changed) console.log('Config: synced telemetry/plugin state from detected config files');
|
|
48
|
+
return changed;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function onConnection(ws) {
|
|
52
|
+
sessions.clients.add(ws);
|
|
53
|
+
|
|
54
|
+
ws.send(JSON.stringify({ type: 'config', config: cfg }));
|
|
55
|
+
ws.send(JSON.stringify({ type: 'themes', themes }));
|
|
56
|
+
ws.send(JSON.stringify({ type: 'presets', presets }));
|
|
57
|
+
ws.send(JSON.stringify({ type: 'sessions', list: sessions.list() }));
|
|
58
|
+
ws.send(JSON.stringify({ type: 'sessions.resumable', list: sessions.getResumable() }));
|
|
59
|
+
ws.send(JSON.stringify({ type: 'transcript.cache', cache: transcript.getCache() }));
|
|
60
|
+
ws.send(JSON.stringify({ type: 'plugins', list: plugins.getInfo() }));
|
|
61
|
+
sessions.sendBuffers(ws);
|
|
62
|
+
|
|
63
|
+
ws.on('message', (raw) => {
|
|
64
|
+
let msg;
|
|
65
|
+
try { msg = JSON.parse(raw); } catch { return; }
|
|
66
|
+
|
|
67
|
+
switch (msg.type) {
|
|
68
|
+
case 'create': sessions.create(msg, ws, cfg); break;
|
|
69
|
+
case 'session.resume': sessions.resume(msg, ws, cfg); break;
|
|
70
|
+
case 'session.restart': console.log('[handler] session.restart', msg.id); sessions.restart(msg, ws, cfg); break;
|
|
71
|
+
case 'input': sessions.input(msg); break;
|
|
72
|
+
case 'session.statusReport':
|
|
73
|
+
if (sessions.getSessions().has(msg.id)) plugins.notifyStatus(msg.id, !!msg.working);
|
|
74
|
+
break;
|
|
75
|
+
case 'resize': sessions.resize(msg); break;
|
|
76
|
+
case 'rename': sessions.rename(msg); break;
|
|
77
|
+
case 'close': sessions.close(msg); break;
|
|
78
|
+
|
|
79
|
+
case 'config.get':
|
|
80
|
+
ws.send(JSON.stringify({ type: 'config', config: cfg }));
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
case 'config.update':
|
|
84
|
+
cfg = { ...cfg, ...msg.config };
|
|
85
|
+
detectTelemetryConfig(cfg);
|
|
86
|
+
config.save(cfg);
|
|
87
|
+
sessions.broadcast({ type: 'config', config: cfg });
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
case 'session.theme': {
|
|
91
|
+
const ok = sessions.setTheme(msg.id, msg.themeId);
|
|
92
|
+
if (ok) sessions.broadcast({ type: 'session.theme', id: msg.id, themeId: msg.themeId });
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
case 'telemetry.autosetup': {
|
|
97
|
+
const preset = presets.find(p => p.presetId === msg.presetId);
|
|
98
|
+
if (!preset?.telemetryAutoSetup) break;
|
|
99
|
+
// Only allow if caller has a live session using this preset's command
|
|
100
|
+
const liveSessions = sessions.list();
|
|
101
|
+
const hasLive = liveSessions.some(s => {
|
|
102
|
+
const cmd = cfg.commands.find(c => c.id === s.commandId);
|
|
103
|
+
return cmd && binName(cmd.command) === binName(preset.command);
|
|
104
|
+
});
|
|
105
|
+
if (!hasLive) break;
|
|
106
|
+
const result = applyTelemetryConfig(preset);
|
|
107
|
+
// Persist telemetry state in config
|
|
108
|
+
for (const cmd of cfg.commands) {
|
|
109
|
+
if (binName(cmd.command) === binName(preset.command)) {
|
|
110
|
+
cmd.telemetryEnabled = result.success;
|
|
111
|
+
cmd.telemetryStatus = result.success ? { ok: true } : { ok: false, error: result.message };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
config.save(cfg);
|
|
115
|
+
sessions.broadcast({ type: 'config', config: cfg });
|
|
116
|
+
ws.send(JSON.stringify({
|
|
117
|
+
type: 'telemetry.autosetup.result',
|
|
118
|
+
presetId: msg.presetId,
|
|
119
|
+
success: result.success,
|
|
120
|
+
output: result.message,
|
|
121
|
+
}));
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
case 'telemetry.configure': {
|
|
126
|
+
const preset = presets.find(p => p.presetId === msg.presetId);
|
|
127
|
+
if (!preset) break;
|
|
128
|
+
const enable = !!msg.enable;
|
|
129
|
+
let result;
|
|
130
|
+
if (enable) {
|
|
131
|
+
result = applyTelemetryConfig(preset);
|
|
132
|
+
} else {
|
|
133
|
+
result = removeTelemetryConfig(preset);
|
|
134
|
+
}
|
|
135
|
+
// Update all matching commands in config
|
|
136
|
+
for (const cmd of cfg.commands) {
|
|
137
|
+
if (binName(cmd.command) === binName(preset.command)) {
|
|
138
|
+
cmd.telemetryEnabled = enable && result.success;
|
|
139
|
+
cmd.telemetryStatus = enable
|
|
140
|
+
? (result.success ? { ok: true } : { ok: false, error: result.message })
|
|
141
|
+
: null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
config.save(cfg);
|
|
145
|
+
sessions.broadcast({ type: 'config', config: cfg });
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
case 'session.mute': {
|
|
150
|
+
const ok = sessions.setMute(msg.id, msg.muted);
|
|
151
|
+
if (ok) sessions.broadcast({ type: 'session.mute', id: msg.id, muted: !!msg.muted });
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
case 'session.setProject': {
|
|
156
|
+
const ok = sessions.setProject(msg.id, msg.projectId);
|
|
157
|
+
if (ok) sessions.broadcast({ type: 'session.setProject', id: msg.id, projectId: msg.projectId });
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Client reports latest preview text — stored in memory, persisted by auto-save
|
|
162
|
+
case 'session.setPreview':
|
|
163
|
+
sessions.setPreview(msg.id, msg.text, msg.timestamp);
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case 'project.delete': {
|
|
167
|
+
const proj = cfg.projects?.find(p => p.id === msg.id);
|
|
168
|
+
if (!proj) break;
|
|
169
|
+
// Kill all sessions in this project
|
|
170
|
+
for (const s of sessions.list()) {
|
|
171
|
+
if (s.projectId === msg.id) sessions.close({ id: s.id });
|
|
172
|
+
}
|
|
173
|
+
cfg.projects = cfg.projects.filter(p => p.id !== msg.id);
|
|
174
|
+
config.save(cfg);
|
|
175
|
+
sessions.broadcast({ type: 'config', config: cfg });
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
case 'dirs.list': {
|
|
180
|
+
const target = msg.path || cfg.defaultPath;
|
|
181
|
+
const result = listDirs(target);
|
|
182
|
+
const entries = Array.isArray(result) ? result : [];
|
|
183
|
+
const error = result.error || undefined;
|
|
184
|
+
ws.send(JSON.stringify({ type: 'dirs', path: target, entries, error }));
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
case 'plugin.settings.update':
|
|
189
|
+
plugins.updateSetting(msg.pluginId, msg.key, msg.value);
|
|
190
|
+
sessions.broadcast({ type: 'plugins', list: plugins.getInfo() });
|
|
191
|
+
break;
|
|
192
|
+
|
|
193
|
+
default:
|
|
194
|
+
if (msg.type?.startsWith('plugin.')) plugins.handleMessage(msg);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
ws.on('close', () => sessions.clients.delete(ws));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Deterministic telemetry config writers per agent — no AI, no YOLO
|
|
203
|
+
function applyTelemetryConfig(preset) {
|
|
204
|
+
const port = '4000';
|
|
205
|
+
const home = os.homedir();
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
if (preset.presetId === 'codex') {
|
|
209
|
+
const configPath = join(home, '.codex', 'config.toml');
|
|
210
|
+
let content = '';
|
|
211
|
+
if (existsSync(configPath)) content = readFileSync(configPath, 'utf8');
|
|
212
|
+
if (content.includes('[otel]')) return { success: true, message: 'Already configured' };
|
|
213
|
+
const section = `\n[otel]\nexporter = { otlp-http = { endpoint = "http://localhost:${port}/v1/logs", protocol = "json" } }\n`;
|
|
214
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
215
|
+
writeFileSync(configPath, content.trimEnd() + '\n' + section);
|
|
216
|
+
return { success: true, message: 'Added [otel] section to ~/.codex/config.toml' };
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (preset.presetId === 'gemini-cli') {
|
|
220
|
+
const configPath = join(home, '.gemini', 'settings.json');
|
|
221
|
+
let settings = {};
|
|
222
|
+
if (existsSync(configPath)) {
|
|
223
|
+
try { settings = JSON.parse(readFileSync(configPath, 'utf8')); } catch {}
|
|
224
|
+
}
|
|
225
|
+
if (settings.telemetry?.enabled && settings.telemetry?.otlpEndpoint) {
|
|
226
|
+
return { success: true, message: 'Already configured' };
|
|
227
|
+
}
|
|
228
|
+
settings.telemetry = {
|
|
229
|
+
...settings.telemetry,
|
|
230
|
+
enabled: true,
|
|
231
|
+
target: 'local',
|
|
232
|
+
otlpEndpoint: `http://localhost:${port}/v1/logs`,
|
|
233
|
+
otlpProtocol: 'http',
|
|
234
|
+
logPrompts: true,
|
|
235
|
+
};
|
|
236
|
+
mkdirSync(dirname(configPath), { recursive: true });
|
|
237
|
+
writeFileSync(configPath, JSON.stringify(settings, null, 2) + '\n');
|
|
238
|
+
return { success: true, message: 'Added telemetry section to ~/.gemini/settings.json' };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (preset.presetId === 'opencode') {
|
|
242
|
+
const pluginDir = join(home, '.config', 'opencode', 'plugins');
|
|
243
|
+
const src = join(__dirname, 'opencode-plugin', 'clideck-bridge.js');
|
|
244
|
+
mkdirSync(pluginDir, { recursive: true });
|
|
245
|
+
copyFileSync(src, join(pluginDir, 'clideck-bridge.js'));
|
|
246
|
+
// Remove old termix-bridge.js if present
|
|
247
|
+
const old = join(pluginDir, 'termix-bridge.js');
|
|
248
|
+
if (existsSync(old)) try { unlinkSync(old); } catch {}
|
|
249
|
+
return { success: true, message: 'Installed bridge plugin to ~/.config/opencode/plugins/' };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return { success: false, message: `No auto-setup for ${preset.presetId}` };
|
|
253
|
+
} catch (err) {
|
|
254
|
+
return { success: false, message: err.message };
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function removeTelemetryConfig(preset) {
|
|
259
|
+
const home = os.homedir();
|
|
260
|
+
|
|
261
|
+
try {
|
|
262
|
+
if (preset.presetId === 'codex') {
|
|
263
|
+
const configPath = join(home, '.codex', 'config.toml');
|
|
264
|
+
if (!existsSync(configPath)) return { success: true, message: 'No config file to clean' };
|
|
265
|
+
let content = readFileSync(configPath, 'utf8');
|
|
266
|
+
// Remove [otel] section and everything until the next section or EOF
|
|
267
|
+
content = content.replace(/\n?\[otel\][^\[]*/, '');
|
|
268
|
+
writeFileSync(configPath, content.trimEnd() + '\n');
|
|
269
|
+
return { success: true, message: 'Removed [otel] section from ~/.codex/config.toml' };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (preset.presetId === 'gemini-cli') {
|
|
273
|
+
const configPath = join(home, '.gemini', 'settings.json');
|
|
274
|
+
if (!existsSync(configPath)) return { success: true, message: 'No config file to clean' };
|
|
275
|
+
let settings = {};
|
|
276
|
+
try { settings = JSON.parse(readFileSync(configPath, 'utf8')); } catch {}
|
|
277
|
+
delete settings.telemetry;
|
|
278
|
+
writeFileSync(configPath, JSON.stringify(settings, null, 2) + '\n');
|
|
279
|
+
return { success: true, message: 'Removed telemetry section from ~/.gemini/settings.json' };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (preset.presetId === 'opencode') {
|
|
283
|
+
const dir = join(home, '.config', 'opencode', 'plugins');
|
|
284
|
+
try { unlinkSync(join(dir, 'clideck-bridge.js')); } catch {}
|
|
285
|
+
try { unlinkSync(join(dir, 'termix-bridge.js')); } catch {}
|
|
286
|
+
return { success: true, message: 'Removed bridge plugin' };
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return { success: false, message: `No removal logic for ${preset.presetId}` };
|
|
290
|
+
} catch (err) {
|
|
291
|
+
return { success: false, message: err.message };
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function getConfig() { return cfg; }
|
|
296
|
+
|
|
297
|
+
module.exports = { onConnection, getConfig };
|