backeer-codex 0.1.1 → 0.3.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.
@@ -0,0 +1,45 @@
1
+ import path from "node:path";
2
+ import { loadConnectionProfiles, saveConnectionProfiles, connectionProfile } from "backeer-opencode/live-profiles";
3
+ import { LiveSessionManager } from "backeer-opencode/live-session-manager";
4
+ import { runManagedLiveMcp } from "backeer-opencode/live-managed-mcp";
5
+ import { configDirectory } from "./config.mjs";
6
+
7
+ export function connectionsFile(env = process.env) {
8
+ return env.BACKEER_LIVE_PROFILES_FILE
9
+ ? path.resolve(env.BACKEER_LIVE_PROFILES_FILE)
10
+ : path.join(configDirectory(env), "opencode-connections.json");
11
+ }
12
+
13
+ export async function runOpenCodeCLI(args, { env = process.env, output = process.stdout } = {}) {
14
+ const file = connectionsFile(env);
15
+ const [command = "connections", ...values] = args;
16
+ if (command === "mcp" && values.length === 0) return runManagedLiveMcp({ profilesFile: file });
17
+ const profiles = await loadConnectionProfiles(file);
18
+ if (command === "connections" && values.length === 0) {
19
+ output.write(`${JSON.stringify({ connections: profiles.map(({ name, url, directory }) => ({ name, url, directory })) }, null, 2)}\n`);
20
+ return;
21
+ }
22
+ if (command === "add" && values.length === 4) {
23
+ const [name, url, tokenFile, directory] = values;
24
+ if (profiles.some(profile => profile.name === name)) {
25
+ throw new Error("Connection already exists. Remove it explicitly before adding a replacement.");
26
+ }
27
+ const profile = connectionProfile({ name, url, tokenFile: path.resolve(tokenFile), directory });
28
+ await saveConnectionProfiles(file, [...profiles, profile]);
29
+ output.write(`Saved connection: ${profile.name}. No session started and no credentials copied.\n`);
30
+ return;
31
+ }
32
+ if (command === "remove" && values.length === 1) {
33
+ if (!profiles.some(profile => profile.name === values[0])) throw new Error("Connection not found.");
34
+ await saveConnectionProfiles(file, profiles.filter(profile => profile.name !== values[0]));
35
+ output.write("Connection removed. Remote OpenCode work continues.\n");
36
+ return;
37
+ }
38
+ if (command === "sessions" && values.length === 1) {
39
+ const manager = new LiveSessionManager({ profilesFile: file });
40
+ try { output.write(`${JSON.stringify(await manager.listSessions(values[0]), null, 2)}\n`); }
41
+ finally { await manager.close(); }
42
+ return;
43
+ }
44
+ throw new Error("Usage: backeer-codex opencode [connections|add <name> <loopback-url> <token-file> <remote-project-directory>|remove <name>|sessions <name>|mcp]");
45
+ }