Tool to send cross-session opencode messages, including as request-response pattern
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add zeroconf command to enable mdns setting

rektide 915297ea f10b5efa

+76 -6
+76 -6
cli.ts
··· 1 1 #!/usr/bin/env node 2 2 3 - import { readdir, readFile, access } from "node:fs/promises"; 3 + import { readdir, readFile, access, writeFile, mkdir } from "node:fs/promises"; 4 4 import { join } from "node:path"; 5 5 import { homedir } from "node:os"; 6 6 ··· 43 43 return sessionDir === pattern; 44 44 } 45 45 46 - const regexPattern = pattern 47 - .replace(/\*/g, ".*") 48 - .replace(/\?/g, "."); 46 + const regexPattern = pattern.replace(/\*/g, ".*").replace(/\?/g, "."); 49 47 const regex = new RegExp(`^${regexPattern}$`); 50 48 51 49 return regex.test(sessionDir); ··· 102 100 } 103 101 } 104 102 103 + async function enableMdns(): Promise<void> { 104 + const configPath1 = join(homedir(), ".config", "opencode", "opencode.json"); 105 + const configPath2 = join(homedir(), ".opencode", "opencode.json"); 106 + 107 + let config1Exists = false; 108 + let config2Exists = false; 109 + let config1HasMdns = false; 110 + let config2HasMdns = false; 111 + 112 + try { 113 + await access(configPath1); 114 + config1Exists = true; 115 + const content = await readFile(configPath1, "utf-8"); 116 + const config = JSON.parse(content); 117 + config1HasMdns = config.server?.mdns !== undefined; 118 + } catch {} 119 + 120 + try { 121 + await access(configPath2); 122 + config2Exists = true; 123 + const content = await readFile(configPath2, "utf-8"); 124 + const config = JSON.parse(content); 125 + config2HasMdns = config.server?.mdns !== undefined; 126 + } catch {} 127 + 128 + let targetFile: string; 129 + let existingConfig: any = {}; 130 + 131 + if (config1HasMdns) { 132 + targetFile = configPath1; 133 + const content = await readFile(configPath1, "utf-8"); 134 + existingConfig = JSON.parse(content); 135 + } else if (config2HasMdns) { 136 + targetFile = configPath2; 137 + const content = await readFile(configPath2, "utf-8"); 138 + existingConfig = JSON.parse(content); 139 + } else if (config1Exists && !config2Exists) { 140 + targetFile = configPath1; 141 + const content = await readFile(configPath1, "utf-8"); 142 + existingConfig = JSON.parse(content); 143 + } else if (config2Exists && !config1Exists) { 144 + targetFile = configPath2; 145 + const content = await readFile(configPath2, "utf-8"); 146 + existingConfig = JSON.parse(content); 147 + } else { 148 + targetFile = configPath1; 149 + if (config1Exists) { 150 + const content = await readFile(configPath1, "utf-8"); 151 + existingConfig = JSON.parse(content); 152 + } 153 + } 154 + 155 + existingConfig.server = existingConfig.server || {}; 156 + existingConfig.server.mdns = true; 157 + 158 + if (!existingConfig.$schema) { 159 + existingConfig.$schema = "https://opencode.ai/config.json"; 160 + } 161 + 162 + const targetDir = join(targetFile, ".."); 163 + await mkdir(targetDir, { recursive: true }); 164 + await writeFile(targetFile, JSON.stringify(existingConfig, null, 2)); 165 + console.log(`Enabled mdns in ${targetFile}`); 166 + } 167 + 105 168 const command = process.argv[2]; 106 169 const options: { dir?: string } = {}; 107 170 ··· 116 179 const dir = options.dir; 117 180 const sessions = await listSessions(dir); 118 181 displaySessions(sessions); 182 + } else if (command === "zeroconf") { 183 + await enableMdns(); 119 184 } else { 120 - console.log("Usage: node cli.ts list [--dir <pattern>]"); 121 - console.log(" list List all sessions"); 185 + console.log("Usage: node cli.ts <command>"); 186 + console.log(""); 187 + console.log("Commands:"); 188 + console.log(" list List all sessions"); 189 + console.log(" zeroconf Enable mDNS zeroconf setting in OpenCode config"); 190 + console.log(""); 191 + console.log("List options:"); 122 192 console.log(" -d, --dir Filter sessions by directory pattern"); 123 193 process.exit(1); 124 194 }