@castlemilk/omega 0.1.4 → 0.1.5
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/dist/cli.js +47 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -82,6 +82,7 @@ import { fileURLToPath } from "url";
|
|
|
82
82
|
import open from "open";
|
|
83
83
|
var __filename = fileURLToPath(import.meta.url);
|
|
84
84
|
var __dirname = path.dirname(__filename);
|
|
85
|
+
var API = process.env.HARNESS_API_URL || "http://localhost:4000";
|
|
85
86
|
function startBundledServer() {
|
|
86
87
|
const serverPath = path.resolve(__dirname, "server.js");
|
|
87
88
|
if (existsSync(serverPath)) {
|
|
@@ -89,17 +90,60 @@ function startBundledServer() {
|
|
|
89
90
|
}
|
|
90
91
|
return void 0;
|
|
91
92
|
}
|
|
93
|
+
async function waitForApi(maxMs = 15e3) {
|
|
94
|
+
const deadline = Date.now() + maxMs;
|
|
95
|
+
while (Date.now() < deadline) {
|
|
96
|
+
try {
|
|
97
|
+
const res = await fetch(`${API}/projects`);
|
|
98
|
+
if (res.ok) return;
|
|
99
|
+
} catch {
|
|
100
|
+
}
|
|
101
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
102
|
+
}
|
|
103
|
+
throw new Error("Server did not become ready in time");
|
|
104
|
+
}
|
|
105
|
+
async function ensureProject() {
|
|
106
|
+
const cwd = process.cwd();
|
|
107
|
+
const name = path.basename(cwd);
|
|
108
|
+
try {
|
|
109
|
+
const listRes = await fetch(`${API}/projects`);
|
|
110
|
+
const projects = await listRes.json();
|
|
111
|
+
const existing = projects.find((p) => p.path === cwd);
|
|
112
|
+
if (existing) {
|
|
113
|
+
console.log(`Using existing project: ${name}`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const createRes = await fetch(`${API}/projects`, {
|
|
117
|
+
method: "POST",
|
|
118
|
+
headers: { "Content-Type": "application/json" },
|
|
119
|
+
body: JSON.stringify({ name, path: cwd })
|
|
120
|
+
});
|
|
121
|
+
if (createRes.ok) {
|
|
122
|
+
console.log(`Added project: ${name}`);
|
|
123
|
+
} else {
|
|
124
|
+
console.warn("Could not auto-add project:", await createRes.text());
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.warn("Could not auto-detect project:", err);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
92
130
|
var uiCmd = new Command3("ui").description("Open the harness web UI").action(async () => {
|
|
93
131
|
const server = startBundledServer() ?? spawn("pnpm", ["--filter", "@omega/server", "dev"], {
|
|
94
132
|
stdio: "inherit",
|
|
95
133
|
shell: true
|
|
96
134
|
});
|
|
97
|
-
setTimeout(async () => {
|
|
98
|
-
await open("http://localhost:4000");
|
|
99
|
-
}, 2500);
|
|
100
135
|
server.on("exit", (code) => {
|
|
101
136
|
process.exit(code ?? 0);
|
|
102
137
|
});
|
|
138
|
+
try {
|
|
139
|
+
await waitForApi();
|
|
140
|
+
await ensureProject();
|
|
141
|
+
await open(API);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error(err);
|
|
144
|
+
server.kill();
|
|
145
|
+
process.exit(1);
|
|
146
|
+
}
|
|
103
147
|
});
|
|
104
148
|
|
|
105
149
|
// ../../apps/cli/src/commands/skill.ts
|