@clagentic/console 1.0.0-beta.1
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/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
// Codex App-Server Protocol Client
|
|
2
|
+
// ---------------------------------
|
|
3
|
+
// Manages a codex app-server child process with bidirectional JSON-RPC
|
|
4
|
+
// communication over stdin/stdout. Replaces the SDK exec mode to enable
|
|
5
|
+
// interactive approval flows.
|
|
6
|
+
|
|
7
|
+
var { spawn } = require("child_process");
|
|
8
|
+
var readline = require("readline");
|
|
9
|
+
var path = require("path");
|
|
10
|
+
var { createRequire } = require("module");
|
|
11
|
+
|
|
12
|
+
// --- Find the codex binary path ---
|
|
13
|
+
// Mirrors the logic from @openai/codex-sdk findCodexPath()
|
|
14
|
+
|
|
15
|
+
var PLATFORM_PACKAGE_BY_TARGET = {
|
|
16
|
+
"aarch64-apple-darwin": "@openai/codex-darwin-arm64",
|
|
17
|
+
"x86_64-apple-darwin": "@openai/codex-darwin-x64",
|
|
18
|
+
"aarch64-unknown-linux-musl": "@openai/codex-linux-arm64",
|
|
19
|
+
"x86_64-unknown-linux-musl": "@openai/codex-linux-x64",
|
|
20
|
+
"x86_64-pc-windows-msvc": "@openai/codex-win32-x64",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function getTargetTriple() {
|
|
24
|
+
var arch = process.arch;
|
|
25
|
+
var platform = process.platform;
|
|
26
|
+
if (platform === "darwin") {
|
|
27
|
+
return arch === "arm64" ? "aarch64-apple-darwin" : "x86_64-apple-darwin";
|
|
28
|
+
}
|
|
29
|
+
if (platform === "linux") {
|
|
30
|
+
return arch === "arm64" ? "aarch64-unknown-linux-musl" : "x86_64-unknown-linux-musl";
|
|
31
|
+
}
|
|
32
|
+
if (platform === "win32") {
|
|
33
|
+
return "x86_64-pc-windows-msvc";
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function findCodexPath() {
|
|
39
|
+
var triple = getTargetTriple();
|
|
40
|
+
if (!triple) throw new Error("Unsupported platform: " + process.platform + "/" + process.arch);
|
|
41
|
+
|
|
42
|
+
var platformPkg = PLATFORM_PACKAGE_BY_TARGET[triple];
|
|
43
|
+
if (!platformPkg) throw new Error("No codex binary package for: " + triple);
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
var codexPkgJson = require.resolve("@openai/codex/package.json");
|
|
47
|
+
var codexRequire = createRequire(codexPkgJson);
|
|
48
|
+
var platformPkgJson = codexRequire.resolve(platformPkg + "/package.json");
|
|
49
|
+
var vendorRoot = path.join(path.dirname(platformPkgJson), "vendor");
|
|
50
|
+
var binaryName = process.platform === "win32" ? "codex.exe" : "codex";
|
|
51
|
+
return path.join(vendorRoot, triple, "codex", binaryName);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw new Error("Could not find codex binary: " + e.message);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// --- Config serialization ---
|
|
58
|
+
// Flattens a nested config object into --config key=value pairs.
|
|
59
|
+
// Values are serialized as TOML literals (strings quoted, others raw).
|
|
60
|
+
// e.g. { mcp_servers: { "clay-tools": { command: "node", args: ["a.js"] } } }
|
|
61
|
+
// -> ["mcp_servers.clay-tools.command=\"node\"", "mcp_servers.clay-tools.args=[\"a.js\"]"]
|
|
62
|
+
|
|
63
|
+
function serializeConfig(obj, prefix) {
|
|
64
|
+
var result = [];
|
|
65
|
+
var keys = Object.keys(obj);
|
|
66
|
+
for (var i = 0; i < keys.length; i++) {
|
|
67
|
+
var key = keys[i];
|
|
68
|
+
var val = obj[key];
|
|
69
|
+
var fullKey = prefix ? prefix + "." + key : key;
|
|
70
|
+
|
|
71
|
+
if (val === null || val === undefined) continue;
|
|
72
|
+
|
|
73
|
+
if (typeof val === "object" && !Array.isArray(val)) {
|
|
74
|
+
// Recurse for nested objects
|
|
75
|
+
var nested = serializeConfig(val, fullKey);
|
|
76
|
+
for (var j = 0; j < nested.length; j++) {
|
|
77
|
+
result.push(nested[j]);
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
// Leaf value: serialize as TOML
|
|
81
|
+
result.push(fullKey + "=" + toTomlValue(val));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function toTomlValue(val) {
|
|
88
|
+
if (typeof val === "string") return JSON.stringify(val);
|
|
89
|
+
if (typeof val === "boolean") return val ? "true" : "false";
|
|
90
|
+
if (typeof val === "number") return String(val);
|
|
91
|
+
if (Array.isArray(val)) return "[" + val.map(function(v) { return toTomlValue(v); }).join(", ") + "]";
|
|
92
|
+
return JSON.stringify(val);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// --- CodexAppServer ---
|
|
96
|
+
|
|
97
|
+
function CodexAppServer(executablePath, opts) {
|
|
98
|
+
this.proc = null;
|
|
99
|
+
this.rl = null;
|
|
100
|
+
this.nextId = 1;
|
|
101
|
+
this.pendingRequests = {}; // id -> { resolve, reject, timer }
|
|
102
|
+
// eventHandler kept for backward-compat but superseded by the multiplexer below.
|
|
103
|
+
// Use addEventHandler / removeEventHandler instead of setting this directly.
|
|
104
|
+
this.eventHandler = null;
|
|
105
|
+
this._eventHandlers = []; // [{ threadId: string|null, fn: function }]
|
|
106
|
+
this.executablePath = executablePath || findCodexPath();
|
|
107
|
+
this.opts = opts || {};
|
|
108
|
+
this.started = false;
|
|
109
|
+
this._stderrBuf = "";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
CodexAppServer.prototype.start = function() {
|
|
113
|
+
var self = this;
|
|
114
|
+
|
|
115
|
+
return new Promise(function(resolve, reject) {
|
|
116
|
+
try {
|
|
117
|
+
var args = ["app-server"];
|
|
118
|
+
var env = Object.assign({}, process.env, self.opts.env || {});
|
|
119
|
+
|
|
120
|
+
// Pass config overrides via --config key=value flags
|
|
121
|
+
if (self.opts.config) {
|
|
122
|
+
var configArgs = serializeConfig(self.opts.config, "");
|
|
123
|
+
for (var ci = 0; ci < configArgs.length; ci++) {
|
|
124
|
+
args.push("--config", configArgs[ci]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
console.log("[codex-app-server] Spawning:", self.executablePath, args.join(" "));
|
|
129
|
+
|
|
130
|
+
self.proc = spawn(self.executablePath, args, {
|
|
131
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
132
|
+
env: env,
|
|
133
|
+
cwd: self.opts.cwd || process.cwd(),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
self.proc.on("error", function(err) {
|
|
137
|
+
console.error("[codex-app-server] Process error:", err.message);
|
|
138
|
+
if (!self.started) {
|
|
139
|
+
reject(err);
|
|
140
|
+
}
|
|
141
|
+
self._rejectAllPending(err);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
self.proc.on("exit", function(code, signal) {
|
|
145
|
+
console.log("[codex-app-server] Process exited: code=" + code + " signal=" + signal);
|
|
146
|
+
self.started = false;
|
|
147
|
+
self._rejectAllPending(new Error("Process exited: code=" + code));
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// Collect stderr for debugging
|
|
151
|
+
self.proc.stderr.on("data", function(chunk) {
|
|
152
|
+
var text = chunk.toString();
|
|
153
|
+
self._stderrBuf += text;
|
|
154
|
+
// Print stderr lines as they come
|
|
155
|
+
var lines = self._stderrBuf.split("\n");
|
|
156
|
+
while (lines.length > 1) {
|
|
157
|
+
var line = lines.shift();
|
|
158
|
+
if (line.trim()) console.log("[codex-app-server stderr]", line);
|
|
159
|
+
}
|
|
160
|
+
self._stderrBuf = lines[0] || "";
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Set up line-based JSON-RPC reading from stdout
|
|
164
|
+
self.rl = readline.createInterface({
|
|
165
|
+
input: self.proc.stdout,
|
|
166
|
+
crlfDelay: Infinity,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
self.rl.on("line", function(line) {
|
|
170
|
+
if (!line.trim()) return;
|
|
171
|
+
try {
|
|
172
|
+
var msg = JSON.parse(line);
|
|
173
|
+
self._handleMessage(msg);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
console.error("[codex-app-server] Failed to parse line:", line.substring(0, 200));
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
self.rl.on("close", function() {
|
|
180
|
+
console.log("[codex-app-server] stdout closed");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
self.started = true;
|
|
184
|
+
resolve();
|
|
185
|
+
} catch (e) {
|
|
186
|
+
reject(e);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
CodexAppServer.prototype._handleMessage = function(msg) {
|
|
192
|
+
// Response to a request we sent
|
|
193
|
+
if (msg.id !== undefined && msg.id !== null && (msg.result !== undefined || msg.error !== undefined)) {
|
|
194
|
+
var pending = this.pendingRequests[msg.id];
|
|
195
|
+
if (pending) {
|
|
196
|
+
delete this.pendingRequests[msg.id];
|
|
197
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
198
|
+
if (msg.error) {
|
|
199
|
+
pending.reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
200
|
+
} else {
|
|
201
|
+
pending.resolve(msg.result);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Server-initiated request (has id + method) or notification (has method, no id)
|
|
208
|
+
if (msg.method) {
|
|
209
|
+
var threadId = (msg.params && msg.params.threadId) || null;
|
|
210
|
+
var dispatched = false;
|
|
211
|
+
|
|
212
|
+
// Multiplexed handlers (registered via addEventHandler).
|
|
213
|
+
// A handler with a known threadId only receives events for that thread.
|
|
214
|
+
// A handler with threadId=null receives all events (used during thread/start
|
|
215
|
+
// before the threadId is known, then updated once it is).
|
|
216
|
+
var handlers = this._eventHandlers;
|
|
217
|
+
for (var hi = 0; hi < handlers.length; hi++) {
|
|
218
|
+
var entry = handlers[hi];
|
|
219
|
+
if (entry.threadId === null || entry.threadId === threadId) {
|
|
220
|
+
entry.fn(msg);
|
|
221
|
+
dispatched = true;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// Legacy single-handler fallback (only used if no multiplexed handlers registered)
|
|
226
|
+
if (!dispatched) {
|
|
227
|
+
if (this.eventHandler) {
|
|
228
|
+
this.eventHandler(msg);
|
|
229
|
+
} else {
|
|
230
|
+
console.log("[codex-app-server] Unhandled event:", msg.method);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// Send a JSON-RPC request (expects a response)
|
|
237
|
+
CodexAppServer.prototype.send = function(method, params, timeoutMs) {
|
|
238
|
+
var self = this;
|
|
239
|
+
var id = this.nextId++;
|
|
240
|
+
timeoutMs = timeoutMs || 30000;
|
|
241
|
+
|
|
242
|
+
return new Promise(function(resolve, reject) {
|
|
243
|
+
if (!self.proc || !self.started) {
|
|
244
|
+
return reject(new Error("App-server not started"));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
var timer = setTimeout(function() {
|
|
248
|
+
delete self.pendingRequests[id];
|
|
249
|
+
reject(new Error("Request timeout: " + method + " (id=" + id + ")"));
|
|
250
|
+
}, timeoutMs);
|
|
251
|
+
|
|
252
|
+
self.pendingRequests[id] = { resolve: resolve, reject: reject, timer: timer };
|
|
253
|
+
|
|
254
|
+
var msg = { jsonrpc: "2.0", id: id, method: method };
|
|
255
|
+
if (params !== undefined) msg.params = params;
|
|
256
|
+
|
|
257
|
+
self._write(msg);
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
// Send a JSON-RPC notification (no response expected)
|
|
262
|
+
CodexAppServer.prototype.notify = function(method, params) {
|
|
263
|
+
if (!this.proc || !this.started) return;
|
|
264
|
+
|
|
265
|
+
var msg = { jsonrpc: "2.0", method: method };
|
|
266
|
+
if (params !== undefined) msg.params = params;
|
|
267
|
+
|
|
268
|
+
this._write(msg);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// Respond to a server-initiated request
|
|
272
|
+
CodexAppServer.prototype.respond = function(id, result) {
|
|
273
|
+
if (!this.proc || !this.started) return;
|
|
274
|
+
|
|
275
|
+
var msg = { jsonrpc: "2.0", id: id, result: result };
|
|
276
|
+
this._write(msg);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Respond with an error to a server-initiated request
|
|
280
|
+
CodexAppServer.prototype.respondError = function(id, code, message) {
|
|
281
|
+
if (!this.proc || !this.started) return;
|
|
282
|
+
|
|
283
|
+
var msg = { jsonrpc: "2.0", id: id, error: { code: code || -1, message: message || "Error" } };
|
|
284
|
+
this._write(msg);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
CodexAppServer.prototype._write = function(msg) {
|
|
288
|
+
if (!this.proc || !this.proc.stdin || this.proc.stdin.destroyed) return;
|
|
289
|
+
try {
|
|
290
|
+
this.proc.stdin.write(JSON.stringify(msg) + "\n");
|
|
291
|
+
} catch (e) {
|
|
292
|
+
console.error("[codex-app-server] Write error:", e.message);
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
CodexAppServer.prototype._rejectAllPending = function(err) {
|
|
297
|
+
var ids = Object.keys(this.pendingRequests);
|
|
298
|
+
for (var i = 0; i < ids.length; i++) {
|
|
299
|
+
var pending = this.pendingRequests[ids[i]];
|
|
300
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
301
|
+
pending.reject(err);
|
|
302
|
+
}
|
|
303
|
+
this.pendingRequests = {};
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// Register an event handler for a specific thread (or null to receive all events).
|
|
307
|
+
// Returns a handle object that can be passed to removeEventHandler or updateHandlerThreadId.
|
|
308
|
+
CodexAppServer.prototype.addEventHandler = function(fn, threadId) {
|
|
309
|
+
var entry = { fn: fn, threadId: threadId || null };
|
|
310
|
+
this._eventHandlers.push(entry);
|
|
311
|
+
return entry;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// Remove a previously registered handler.
|
|
315
|
+
CodexAppServer.prototype.removeEventHandler = function(entry) {
|
|
316
|
+
var next = [];
|
|
317
|
+
for (var i = 0; i < this._eventHandlers.length; i++) {
|
|
318
|
+
if (this._eventHandlers[i] !== entry) next.push(this._eventHandlers[i]);
|
|
319
|
+
}
|
|
320
|
+
this._eventHandlers = next;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// Update the threadId filter on a handler once the thread ID is known.
|
|
324
|
+
// Until called, the handler receives all events (threadId=null).
|
|
325
|
+
CodexAppServer.prototype.updateHandlerThreadId = function(entry, threadId) {
|
|
326
|
+
entry.threadId = threadId || null;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
CodexAppServer.prototype.stop = function() {
|
|
330
|
+
this.started = false;
|
|
331
|
+
this._rejectAllPending(new Error("Stopped"));
|
|
332
|
+
|
|
333
|
+
if (this.rl) {
|
|
334
|
+
this.rl.close();
|
|
335
|
+
this.rl = null;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (this.proc) {
|
|
339
|
+
try {
|
|
340
|
+
this.proc.stdin.end();
|
|
341
|
+
} catch (e) {}
|
|
342
|
+
try {
|
|
343
|
+
this.proc.kill("SIGTERM");
|
|
344
|
+
} catch (e) {}
|
|
345
|
+
this.proc = null;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
module.exports = {
|
|
350
|
+
CodexAppServer: CodexAppServer,
|
|
351
|
+
findCodexPath: findCodexPath,
|
|
352
|
+
};
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// YOKE - Yoke Overrides Known Engines
|
|
2
|
+
// Public entry point.
|
|
3
|
+
|
|
4
|
+
var iface = require("./interface");
|
|
5
|
+
var instructions = require("./instructions");
|
|
6
|
+
var createClaudeAdapter = require("./adapters/claude").createClaudeAdapter;
|
|
7
|
+
var createCodexAdapter = require("./adapters/codex").createCodexAdapter;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Wrap adapter.createQuery to inject cross-vendor project instructions.
|
|
11
|
+
*
|
|
12
|
+
* Scans the project directory for instruction files (CLAUDE.md, AGENTS.md,
|
|
13
|
+
* .cursorrules, etc.) that the current vendor does NOT natively read,
|
|
14
|
+
* and merges them into queryOpts.systemPrompt before calling the real
|
|
15
|
+
* createQuery. This way every adapter gets project context regardless
|
|
16
|
+
* of which vendor wrote the instruction file.
|
|
17
|
+
*/
|
|
18
|
+
function wrapCreateQuery(adapter, defaultCwd) {
|
|
19
|
+
var originalCreateQuery = adapter.createQuery.bind(adapter);
|
|
20
|
+
|
|
21
|
+
adapter.createQuery = function(queryOpts) {
|
|
22
|
+
queryOpts = queryOpts || {};
|
|
23
|
+
var projectDir = (queryOpts && queryOpts.cwd) || defaultCwd;
|
|
24
|
+
var merged = instructions.scanAndMerge(projectDir, adapter.vendor);
|
|
25
|
+
|
|
26
|
+
if (merged) {
|
|
27
|
+
var parts = [];
|
|
28
|
+
if (queryOpts.systemPrompt) parts.push(queryOpts.systemPrompt);
|
|
29
|
+
parts.push(merged);
|
|
30
|
+
queryOpts.systemPrompt = parts.join("\n\n");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return originalCreateQuery(queryOpts);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a YOKE adapter.
|
|
39
|
+
*
|
|
40
|
+
* @param {object} opts
|
|
41
|
+
* @param {string} [opts.vendor="claude"] - Adapter vendor name
|
|
42
|
+
* @param {string} opts.cwd - Project working directory
|
|
43
|
+
* @param {object} [opts.adapterOpts] - Vendor-specific adapter construction options
|
|
44
|
+
* @returns {Adapter}
|
|
45
|
+
*/
|
|
46
|
+
function createAdapter(opts) {
|
|
47
|
+
var vendor = (opts && opts.vendor) || "claude";
|
|
48
|
+
var adapter;
|
|
49
|
+
if (vendor === "claude") {
|
|
50
|
+
adapter = createClaudeAdapter(opts);
|
|
51
|
+
} else if (vendor === "codex") {
|
|
52
|
+
adapter = createCodexAdapter(opts);
|
|
53
|
+
} else {
|
|
54
|
+
throw new Error("[YOKE] Unknown adapter vendor: " + vendor);
|
|
55
|
+
}
|
|
56
|
+
iface.validateAdapter(adapter);
|
|
57
|
+
wrapCreateQuery(adapter, opts && opts.cwd);
|
|
58
|
+
return adapter;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Check which vendors have valid auth credentials.
|
|
63
|
+
* Result is cached after first call (auth state doesn't change during runtime).
|
|
64
|
+
* Call invalidateAuthCache() to force re-check (e.g. after login).
|
|
65
|
+
*/
|
|
66
|
+
var _authCache = null;
|
|
67
|
+
var _lastAuthLogKey = null;
|
|
68
|
+
var _lastAuthLogAt = 0;
|
|
69
|
+
|
|
70
|
+
function logAuthCheck(auth) {
|
|
71
|
+
var key = JSON.stringify(auth || {});
|
|
72
|
+
var now = Date.now();
|
|
73
|
+
if (_lastAuthLogKey === key && now - _lastAuthLogAt < 30000) return;
|
|
74
|
+
_lastAuthLogKey = key;
|
|
75
|
+
_lastAuthLogAt = now;
|
|
76
|
+
console.log("[yoke] Auth check: claude=" + auth.claude + " codex=" + auth.codex);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function checkAuth() {
|
|
80
|
+
if (_authCache) return _authCache;
|
|
81
|
+
|
|
82
|
+
var execSync = require("child_process").execSync;
|
|
83
|
+
var execFileSync = require("child_process").execFileSync;
|
|
84
|
+
|
|
85
|
+
function lookupBinary(name) {
|
|
86
|
+
try {
|
|
87
|
+
if (process.platform === "win32") {
|
|
88
|
+
return execFileSync("where", [name], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }).trim().split(/\r?\n/)[0] || null;
|
|
89
|
+
}
|
|
90
|
+
return execFileSync("which", [name], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }).trim().split(/\r?\n/)[0] || null;
|
|
91
|
+
} catch (e) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function parseClaudeAuthStatusJson(out) {
|
|
97
|
+
if (!out) return null;
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(out);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isClaudeLoggedInText(out) {
|
|
106
|
+
if (!out) return false;
|
|
107
|
+
var text = String(out).toLowerCase();
|
|
108
|
+
if (text.indexOf("not logged in") !== -1) return false;
|
|
109
|
+
if (text.indexOf("login method:") !== -1) return true;
|
|
110
|
+
if (text.indexOf("logged in") !== -1) return true;
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function hasThirdPartyProviderAuth() {
|
|
115
|
+
// Claude Code supports third-party providers via env vars. When these are set,
|
|
116
|
+
// `claude auth status` reports "not logged in" because there is no OAuth session,
|
|
117
|
+
// but Claude Code itself authenticates directly through the provider.
|
|
118
|
+
var env = process.env;
|
|
119
|
+
if (env.CLAUDE_CODE_USE_BEDROCK === "1"
|
|
120
|
+
&& (env.AWS_BEARER_TOKEN_BEDROCK
|
|
121
|
+
|| env.AWS_ACCESS_KEY_ID
|
|
122
|
+
|| env.AWS_PROFILE
|
|
123
|
+
|| env.AWS_SESSION_TOKEN)) {
|
|
124
|
+
return "bedrock";
|
|
125
|
+
}
|
|
126
|
+
if (env.CLAUDE_CODE_USE_VERTEX === "1") return "vertex";
|
|
127
|
+
if (env.ANTHROPIC_API_KEY) return "api_key";
|
|
128
|
+
if (env.ANTHROPIC_AUTH_TOKEN) return "auth_token";
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function checkClaude() {
|
|
133
|
+
var provider = hasThirdPartyProviderAuth();
|
|
134
|
+
if (provider) {
|
|
135
|
+
console.log("[yoke] Claude auth via third-party provider: " + provider);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
var out = execSync("claude auth status --json", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
|
141
|
+
var parsed = parseClaudeAuthStatusJson(out);
|
|
142
|
+
if (parsed) return !!parsed.loggedIn;
|
|
143
|
+
console.warn("[yoke] Claude auth status JSON parse failed; falling back to text output");
|
|
144
|
+
} catch (e) {
|
|
145
|
+
var stdout = e && e.stdout ? String(e.stdout) : "";
|
|
146
|
+
if (stdout) {
|
|
147
|
+
var parsedFallback = parseClaudeAuthStatusJson(stdout);
|
|
148
|
+
if (parsedFallback) return !!parsedFallback.loggedIn;
|
|
149
|
+
}
|
|
150
|
+
console.warn("[yoke] Claude auth status JSON check failed; falling back to text output:", e.message);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
var textOut = execSync("claude auth status --text", { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
|
155
|
+
return isClaudeLoggedInText(textOut);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function resolveCodexBinary() {
|
|
162
|
+
var fs = require("fs");
|
|
163
|
+
var findCodexPath = require("./codex-app-server").findCodexPath;
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
var codexBin = findCodexPath();
|
|
167
|
+
if (codexBin && fs.existsSync(codexBin)) return codexBin;
|
|
168
|
+
} catch (e) {}
|
|
169
|
+
|
|
170
|
+
return lookupBinary("codex");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function checkCodex() {
|
|
174
|
+
try {
|
|
175
|
+
var codexBin = resolveCodexBinary();
|
|
176
|
+
if (!codexBin) return false;
|
|
177
|
+
execFileSync(codexBin, ["login", "status"], { timeout: 5000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
|
178
|
+
return true;
|
|
179
|
+
} catch (e) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
_authCache = { claude: checkClaude(), codex: checkCodex() };
|
|
185
|
+
logAuthCheck(_authCache);
|
|
186
|
+
return _authCache;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Check which vendor binaries are installed (regardless of auth status).
|
|
191
|
+
*
|
|
192
|
+
* Result is cached at module scope because the check runs two execFileSync
|
|
193
|
+
* calls per invocation and is triggered once per project context on daemon
|
|
194
|
+
* startup. With N projects this used to cost ~2N synchronous subprocesses;
|
|
195
|
+
* caching collapses it to two total. The cache is invalidated alongside
|
|
196
|
+
* the auth cache (via invalidateAuthCache) since "just installed" is the
|
|
197
|
+
* same situation as "just logged in" from the daemon's perspective.
|
|
198
|
+
*/
|
|
199
|
+
var _installedCache = null;
|
|
200
|
+
|
|
201
|
+
function checkInstalled() {
|
|
202
|
+
if (_installedCache) return _installedCache;
|
|
203
|
+
|
|
204
|
+
var fs = require("fs");
|
|
205
|
+
var execFileSync = require("child_process").execFileSync;
|
|
206
|
+
var result = { claude: false, codex: false };
|
|
207
|
+
try {
|
|
208
|
+
if (process.platform === "win32") execFileSync("where", ["claude"], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
|
|
209
|
+
else execFileSync("which", ["claude"], { timeout: 3000, stdio: ["pipe", "pipe", "pipe"] });
|
|
210
|
+
result.claude = true;
|
|
211
|
+
} catch (e) {}
|
|
212
|
+
try {
|
|
213
|
+
var codexBin = null;
|
|
214
|
+
try {
|
|
215
|
+
var findCodexPath = require("./codex-app-server").findCodexPath;
|
|
216
|
+
codexBin = findCodexPath();
|
|
217
|
+
if (codexBin && fs.existsSync(codexBin)) {
|
|
218
|
+
result.codex = true;
|
|
219
|
+
_installedCache = result;
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {}
|
|
223
|
+
|
|
224
|
+
var whichOut = process.platform === "win32"
|
|
225
|
+
? execFileSync("where", ["codex"], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] })
|
|
226
|
+
: execFileSync("which", ["codex"], { timeout: 3000, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] });
|
|
227
|
+
if (whichOut.trim()) result.codex = true;
|
|
228
|
+
} catch (e) {}
|
|
229
|
+
_installedCache = result;
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function invalidateAuthCache() {
|
|
234
|
+
_authCache = null;
|
|
235
|
+
_installedCache = null;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Create adapters for all authenticated vendors.
|
|
240
|
+
* Claude may be shared across projects, but Codex is instantiated per project
|
|
241
|
+
* so its app-server and bridge stay scoped to a single project slug.
|
|
242
|
+
* Returns { adapters: { vendor: Adapter }, auth: { vendor: boolean } }
|
|
243
|
+
*/
|
|
244
|
+
var _sharedClaudeAdapter = null;
|
|
245
|
+
|
|
246
|
+
function createAdapters(opts) {
|
|
247
|
+
opts = opts || {};
|
|
248
|
+
// Gate adapter creation on binary installation, not OAuth auth status.
|
|
249
|
+
// Claude Code supports multiple auth modes (OAuth, Bedrock, Vertex, API key)
|
|
250
|
+
// that `claude auth status` does not always detect. Runtime auth failures are
|
|
251
|
+
// handled downstream via query-level error detection.
|
|
252
|
+
var installed = checkInstalled();
|
|
253
|
+
var auth = { claude: false, codex: false };
|
|
254
|
+
var adapters = {};
|
|
255
|
+
|
|
256
|
+
if (installed.claude) {
|
|
257
|
+
try {
|
|
258
|
+
if (!_sharedClaudeAdapter) {
|
|
259
|
+
_sharedClaudeAdapter = createAdapter({ vendor: "claude", cwd: opts.cwd });
|
|
260
|
+
}
|
|
261
|
+
adapters.claude = _sharedClaudeAdapter;
|
|
262
|
+
auth.claude = true;
|
|
263
|
+
console.log("[yoke] Adapter created: claude");
|
|
264
|
+
} catch (e) {
|
|
265
|
+
console.error("[yoke] Failed to create adapter for claude:", e.message);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (installed.codex) {
|
|
270
|
+
try {
|
|
271
|
+
adapters.codex = createAdapter({ vendor: "codex", cwd: opts.cwd, slug: opts.slug });
|
|
272
|
+
auth.codex = true;
|
|
273
|
+
console.log("[yoke] Adapter created: codex");
|
|
274
|
+
} catch (e) {
|
|
275
|
+
console.error("[yoke] Failed to create adapter for codex:", e.message);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return { adapters: adapters, auth: auth };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Lazy-create an adapter for a vendor that wasn't available at startup.
|
|
284
|
+
* Re-checks auth, creates adapter if now logged in.
|
|
285
|
+
* Returns the adapter or null.
|
|
286
|
+
*/
|
|
287
|
+
async function lazyCreateAdapter(adapters, vendor, opts) {
|
|
288
|
+
opts = opts || {};
|
|
289
|
+
|
|
290
|
+
// Force re-check since user may have logged in after server start
|
|
291
|
+
invalidateAuthCache();
|
|
292
|
+
var installed = checkInstalled();
|
|
293
|
+
if (!installed[vendor]) return null;
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
var ad = createAdapter({ vendor: vendor, cwd: opts.cwd, slug: opts.slug });
|
|
297
|
+
if (typeof ad.init === "function") {
|
|
298
|
+
await ad.init(opts || {});
|
|
299
|
+
}
|
|
300
|
+
console.log("[yoke] Lazy adapter created: " + vendor);
|
|
301
|
+
adapters[vendor] = ad;
|
|
302
|
+
return ad;
|
|
303
|
+
} catch (e) {
|
|
304
|
+
console.error("[yoke] Failed to lazy-create adapter for " + vendor + ":", e.message);
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
module.exports = {
|
|
310
|
+
createAdapter: createAdapter,
|
|
311
|
+
createAdapters: createAdapters,
|
|
312
|
+
lazyCreateAdapter: lazyCreateAdapter,
|
|
313
|
+
checkAuth: checkAuth,
|
|
314
|
+
checkInstalled: checkInstalled,
|
|
315
|
+
invalidateAuthCache: invalidateAuthCache,
|
|
316
|
+
TOOL_POLICIES: iface.TOOL_POLICIES,
|
|
317
|
+
validateAdapter: iface.validateAdapter,
|
|
318
|
+
validateQueryHandle: iface.validateQueryHandle,
|
|
319
|
+
};
|