oh-langfuse 0.1.20 → 0.1.21
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/README.md +1 -1
- package/package.json +13 -4
- package/scripts/real-self-verify.mjs +0 -414
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oh-langfuse",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Use npm scripts to configure Claude Code / OpenCode / Codex with Langfuse tracing.",
|
|
@@ -10,7 +10,15 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"bin",
|
|
13
|
-
"scripts",
|
|
13
|
+
"scripts/codex-langfuse-check.mjs",
|
|
14
|
+
"scripts/codex-langfuse-setup.mjs",
|
|
15
|
+
"scripts/json-utils.mjs",
|
|
16
|
+
"scripts/langfuse-check.mjs",
|
|
17
|
+
"scripts/langfuse-setup.mjs",
|
|
18
|
+
"scripts/opencode-langfuse-check.mjs",
|
|
19
|
+
"scripts/opencode-langfuse-run.mjs",
|
|
20
|
+
"scripts/opencode-langfuse-setup.mjs",
|
|
21
|
+
"scripts/resolve-opencode-cli.mjs",
|
|
14
22
|
"langfuse_hook.py",
|
|
15
23
|
"codex_langfuse_notify.py",
|
|
16
24
|
"README.md",
|
|
@@ -20,8 +28,9 @@
|
|
|
20
28
|
],
|
|
21
29
|
"scripts": {
|
|
22
30
|
"start": "node bin/cli.js",
|
|
23
|
-
"check": "node --check bin/cli.js",
|
|
24
|
-
"
|
|
31
|
+
"check": "node --check bin/cli.js",
|
|
32
|
+
"self:verify": "node scripts/real-self-verify.mjs",
|
|
33
|
+
"pack:check": "npm pack --dry-run",
|
|
25
34
|
"claude:setup": "node scripts/langfuse-setup.mjs",
|
|
26
35
|
"claude:check": "node scripts/langfuse-check.mjs",
|
|
27
36
|
"langfuse:setup": "node scripts/langfuse-setup.mjs",
|
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import crypto from "node:crypto";
|
|
5
|
-
import { spawnSync } from "node:child_process";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { resolveOpencodeCli } from "./resolve-opencode-cli.mjs";
|
|
8
|
-
|
|
9
|
-
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
10
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(rootDir, "package.json"), "utf8"));
|
|
11
|
-
|
|
12
|
-
const DEFAULT_LANGFUSE_BASE_URL = "http://120.46.221.227:3000";
|
|
13
|
-
const DEFAULT_LANGFUSE_PUBLIC_KEY = "pk-lf-da0c90a7-6e93-4eb7-bb86-c1047c8d187d";
|
|
14
|
-
const DEFAULT_LANGFUSE_SECRET_KEY = "sk-lf-0269b85d-bfdc-442c-bfa3-e737954e3315";
|
|
15
|
-
|
|
16
|
-
function parseArgs(argv) {
|
|
17
|
-
const args = { _: [] };
|
|
18
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
19
|
-
const raw = argv[i];
|
|
20
|
-
if (!raw.startsWith("--")) {
|
|
21
|
-
args._.push(raw);
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
const eq = raw.indexOf("=");
|
|
25
|
-
if (eq !== -1) {
|
|
26
|
-
args[raw.slice(2, eq)] = raw.slice(eq + 1);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const key = raw.slice(2);
|
|
30
|
-
const next = argv[i + 1];
|
|
31
|
-
if (next && !next.startsWith("--")) {
|
|
32
|
-
args[key] = next;
|
|
33
|
-
i += 1;
|
|
34
|
-
} else {
|
|
35
|
-
args[key] = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return args;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function printHelp() {
|
|
42
|
-
console.log(`${packageJson.name} real self verification`);
|
|
43
|
-
console.log("");
|
|
44
|
-
console.log("Usage:");
|
|
45
|
-
console.log(" npm run self:verify -- --targets=opencode --userId=h00613222");
|
|
46
|
-
console.log(" node scripts/real-self-verify.mjs --targets=claude,opencode,codex --userId=h00613222");
|
|
47
|
-
console.log("");
|
|
48
|
-
console.log("What it does:");
|
|
49
|
-
console.log(" 1. Runs the real setup command for each target unless --skip-install is set.");
|
|
50
|
-
console.log(" 2. Starts the actual Claude/OpenCode/Codex CLI with a unique validation marker.");
|
|
51
|
-
console.log(" 3. Polls Langfuse Public API until that marker appears in traces/observations.");
|
|
52
|
-
console.log("");
|
|
53
|
-
console.log("Options:");
|
|
54
|
-
console.log(" --targets=opencode,claude,codex");
|
|
55
|
-
console.log(" --userId=<id> Required unless LANGFUSE_USER_ID is set.");
|
|
56
|
-
console.log(" --langfuseBaseUrl=<url> Defaults to package default or LANGFUSE_BASEURL.");
|
|
57
|
-
console.log(" --publicKey=<key> Defaults to package default or LANGFUSE_PUBLIC_KEY.");
|
|
58
|
-
console.log(" --secretKey=<key> Defaults to package default or LANGFUSE_SECRET_KEY.");
|
|
59
|
-
console.log(" --marker=<text> Override generated validation marker.");
|
|
60
|
-
console.log(" --timeoutMs=180000 Langfuse polling timeout.");
|
|
61
|
-
console.log(" --triggerTimeoutMs=300000 Per CLI invocation timeout.");
|
|
62
|
-
console.log(" --skip-install Do not run setup first.");
|
|
63
|
-
console.log(" --skip-trigger Only install and poll for a pre-existing marker.");
|
|
64
|
-
console.log(" --allow-trigger-failure Poll Langfuse even if the CLI command exits non-zero.");
|
|
65
|
-
console.log(" --opencodeCmd=<path> Override OpenCode CLI path.");
|
|
66
|
-
console.log(" --claudeCmd=<path> Override Claude CLI path.");
|
|
67
|
-
console.log(" --codexCmd=<path> Override Codex CLI path.");
|
|
68
|
-
console.log(" --prompt=<text> Override the validation prompt.");
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function splitTargets(raw) {
|
|
72
|
-
const value = String(raw || "opencode").trim();
|
|
73
|
-
const out = value
|
|
74
|
-
.split(/[, ]+/)
|
|
75
|
-
.map((x) => x.trim().toLowerCase())
|
|
76
|
-
.filter(Boolean);
|
|
77
|
-
const allowed = new Set(["claude", "opencode", "codex"]);
|
|
78
|
-
for (const target of out) {
|
|
79
|
-
if (!allowed.has(target)) throw new Error(`Unsupported target: ${target}`);
|
|
80
|
-
}
|
|
81
|
-
return out.length ? [...new Set(out)] : ["opencode"];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function makeMarker() {
|
|
85
|
-
return `real-self-verify-${packageJson.name}-${Date.now()}-${crypto.randomBytes(4).toString("hex")}`;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function shellNeeded(command) {
|
|
89
|
-
return process.platform === "win32" && /\.(cmd|bat)$/i.test(command);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function run(command, args, options = {}) {
|
|
93
|
-
const result = spawnSync(command, args, {
|
|
94
|
-
cwd: options.cwd || rootDir,
|
|
95
|
-
env: { ...process.env, ...(options.env || {}) },
|
|
96
|
-
encoding: "utf8",
|
|
97
|
-
stdio: options.stdio || "pipe",
|
|
98
|
-
timeout: options.timeoutMs,
|
|
99
|
-
windowsHide: true,
|
|
100
|
-
shell: shellNeeded(command),
|
|
101
|
-
});
|
|
102
|
-
return {
|
|
103
|
-
command,
|
|
104
|
-
args,
|
|
105
|
-
status: result.status ?? (result.error ? 1 : 0),
|
|
106
|
-
stdout: result.stdout || "",
|
|
107
|
-
stderr: result.stderr || "",
|
|
108
|
-
error: result.error,
|
|
109
|
-
signal: result.signal,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function printRunResult(label, result) {
|
|
114
|
-
const status = result.status === 0 ? "OK" : "FAIL";
|
|
115
|
-
console.log(`[${status}] ${label}: ${result.command} ${result.args.join(" ")}`);
|
|
116
|
-
const text = `${result.stdout}\n${result.stderr}`.trim();
|
|
117
|
-
if (text) {
|
|
118
|
-
const clipped = text.length > 5000 ? `${text.slice(0, 5000)}\n...<clipped>` : text;
|
|
119
|
-
console.log(clipped);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function findOnPath(names) {
|
|
124
|
-
for (const name of names) {
|
|
125
|
-
const probe = run(name, ["--version"], { timeoutMs: 15000 });
|
|
126
|
-
if (probe.status === 0) return name;
|
|
127
|
-
}
|
|
128
|
-
return "";
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function configFromArgs(args) {
|
|
132
|
-
return {
|
|
133
|
-
baseUrl:
|
|
134
|
-
String(args.langfuseBaseUrl || args.langfuseHost || args.host || process.env.LANGFUSE_BASEURL || process.env.LANGFUSE_HOST || DEFAULT_LANGFUSE_BASE_URL),
|
|
135
|
-
publicKey: String(args.publicKey || process.env.LANGFUSE_PUBLIC_KEY || DEFAULT_LANGFUSE_PUBLIC_KEY),
|
|
136
|
-
secretKey: String(args.secretKey || process.env.LANGFUSE_SECRET_KEY || DEFAULT_LANGFUSE_SECRET_KEY),
|
|
137
|
-
userId: String(args.userId || args.userid || process.env.LANGFUSE_USER_ID || process.env.CC_USER_ID || "").trim(),
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function setupTarget(target, config, args) {
|
|
142
|
-
const cli = path.join(rootDir, "bin", "cli.js");
|
|
143
|
-
const setupArgs = [
|
|
144
|
-
cli,
|
|
145
|
-
"setup",
|
|
146
|
-
target,
|
|
147
|
-
"--yes",
|
|
148
|
-
`--userId=${config.userId}`,
|
|
149
|
-
`--langfuseBaseUrl=${config.baseUrl}`,
|
|
150
|
-
`--publicKey=${config.publicKey}`,
|
|
151
|
-
`--secretKey=${config.secretKey}`,
|
|
152
|
-
];
|
|
153
|
-
if (args.npmRegistry) setupArgs.push(`--npmRegistry=${args.npmRegistry}`);
|
|
154
|
-
if (args.pipIndexUrl) setupArgs.push(`--pipIndexUrl=${args.pipIndexUrl}`);
|
|
155
|
-
if (args["skip-plugin-install"]) setupArgs.push("--skip-plugin-install");
|
|
156
|
-
if (args["no-set-env"]) setupArgs.push("--no-set-env");
|
|
157
|
-
if (args.cmd) setupArgs.push(`--cmd=${args.cmd}`);
|
|
158
|
-
const result = run(process.execPath, setupArgs, { stdio: "inherit", timeoutMs: Number(args.setupTimeoutMs || 600000) });
|
|
159
|
-
return result.status;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function validationPrompt(marker, target, customPrompt) {
|
|
163
|
-
if (customPrompt) return String(customPrompt).replaceAll("{marker}", marker).replaceAll("{target}", target);
|
|
164
|
-
return [
|
|
165
|
-
`This is an automated real self-verification run for ${packageJson.name}.`,
|
|
166
|
-
`Validation marker: ${marker}`,
|
|
167
|
-
"Reply with the validation marker exactly once and do not run tools.",
|
|
168
|
-
].join("\n");
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function triggerClaude(prompt, args, env) {
|
|
172
|
-
const cmd = String(args.claudeCmd || findOnPath(process.platform === "win32" ? ["claude.cmd", "claude"] : ["claude"]));
|
|
173
|
-
if (!cmd) return { status: 127, stdout: "", stderr: "Claude CLI not found. Set --claudeCmd=<path>.", command: "claude", args: [] };
|
|
174
|
-
const candidates = [
|
|
175
|
-
["-p", prompt],
|
|
176
|
-
["--print", prompt],
|
|
177
|
-
];
|
|
178
|
-
let last = null;
|
|
179
|
-
for (const candidate of candidates) {
|
|
180
|
-
last = run(cmd, candidate, { env, timeoutMs: Number(args.triggerTimeoutMs || 300000) });
|
|
181
|
-
if (last.status === 0) return last;
|
|
182
|
-
}
|
|
183
|
-
return last;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function triggerOpenCode(prompt, args, env) {
|
|
187
|
-
const cmd = resolveOpencodeCli(args.opencodeCmd || args.cmd);
|
|
188
|
-
if (!cmd) return { status: 127, stdout: "", stderr: "OpenCode CLI not found. Set --opencodeCmd=<path>.", command: "opencode", args: [] };
|
|
189
|
-
const candidates = [
|
|
190
|
-
["run", prompt],
|
|
191
|
-
["run", "--print", prompt],
|
|
192
|
-
[prompt],
|
|
193
|
-
];
|
|
194
|
-
let last = null;
|
|
195
|
-
for (const candidate of candidates) {
|
|
196
|
-
last = run(cmd, candidate, { env, timeoutMs: Number(args.triggerTimeoutMs || 300000) });
|
|
197
|
-
if (last.status === 0) return last;
|
|
198
|
-
}
|
|
199
|
-
return last;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function triggerCodex(prompt, args, env) {
|
|
203
|
-
const cmd = String(args.codexCmd || findOnPath(process.platform === "win32" ? ["codex.cmd", "codex"] : ["codex"]));
|
|
204
|
-
if (!cmd) return { status: 127, stdout: "", stderr: "Codex CLI not found. Set --codexCmd=<path>.", command: "codex", args: [] };
|
|
205
|
-
const candidates = [
|
|
206
|
-
["exec", prompt],
|
|
207
|
-
["exec", "--skip-git-repo-check", prompt],
|
|
208
|
-
];
|
|
209
|
-
let last = null;
|
|
210
|
-
for (const candidate of candidates) {
|
|
211
|
-
last = run(cmd, candidate, { env, timeoutMs: Number(args.triggerTimeoutMs || 300000) });
|
|
212
|
-
if (last.status === 0) return last;
|
|
213
|
-
}
|
|
214
|
-
return last;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function apiBase(baseUrl) {
|
|
218
|
-
const trimmed = String(baseUrl || "").replace(/\/+$/, "");
|
|
219
|
-
return trimmed.endsWith("/api/public") ? trimmed : `${trimmed}/api/public`;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function basicAuth(publicKey, secretKey) {
|
|
223
|
-
return `Basic ${Buffer.from(`${publicKey}:${secretKey}`, "utf8").toString("base64")}`;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
async function langfuseGet(config, pathname, params = {}) {
|
|
227
|
-
const url = new URL(`${apiBase(config.baseUrl)}${pathname}`);
|
|
228
|
-
for (const [key, value] of Object.entries(params)) {
|
|
229
|
-
if (value !== undefined && value !== null && String(value) !== "") url.searchParams.set(key, String(value));
|
|
230
|
-
}
|
|
231
|
-
const response = await fetch(url, {
|
|
232
|
-
headers: {
|
|
233
|
-
accept: "application/json",
|
|
234
|
-
authorization: basicAuth(config.publicKey, config.secretKey),
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
if (!response.ok) {
|
|
238
|
-
const body = await response.text().catch(() => "");
|
|
239
|
-
const error = new Error(`Langfuse API ${response.status} ${response.statusText}: ${body.slice(0, 500)}`);
|
|
240
|
-
error.status = response.status;
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
return await response.json();
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function dataArray(value) {
|
|
247
|
-
if (Array.isArray(value)) return value;
|
|
248
|
-
if (Array.isArray(value?.data)) return value.data;
|
|
249
|
-
if (Array.isArray(value?.items)) return value.items;
|
|
250
|
-
return [];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function containsMarker(value, marker) {
|
|
254
|
-
try {
|
|
255
|
-
return JSON.stringify(value).includes(marker);
|
|
256
|
-
} catch {
|
|
257
|
-
return false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function idOf(value) {
|
|
262
|
-
return value?.id || value?.traceId || value?.trace_id || "";
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
async function findLangfuseMarker(config, marker, { since, target }) {
|
|
266
|
-
const baseParams = {
|
|
267
|
-
limit: 100,
|
|
268
|
-
fromTimestamp: since.toISOString(),
|
|
269
|
-
};
|
|
270
|
-
const traceQueries = [
|
|
271
|
-
{ ...baseParams, userId: config.userId },
|
|
272
|
-
baseParams,
|
|
273
|
-
];
|
|
274
|
-
|
|
275
|
-
for (const params of traceQueries) {
|
|
276
|
-
let traces;
|
|
277
|
-
try {
|
|
278
|
-
traces = await langfuseGet(config, "/traces", params);
|
|
279
|
-
} catch (error) {
|
|
280
|
-
if (error.status === 404) continue;
|
|
281
|
-
throw error;
|
|
282
|
-
}
|
|
283
|
-
for (const trace of dataArray(traces)) {
|
|
284
|
-
if (containsMarker(trace, marker)) return { kind: "trace-list", target, id: idOf(trace), item: trace };
|
|
285
|
-
}
|
|
286
|
-
for (const trace of dataArray(traces).slice(0, 25)) {
|
|
287
|
-
const id = idOf(trace);
|
|
288
|
-
if (!id) continue;
|
|
289
|
-
try {
|
|
290
|
-
const detail = await langfuseGet(config, `/traces/${encodeURIComponent(id)}`);
|
|
291
|
-
if (containsMarker(detail, marker)) return { kind: "trace-detail", target, id, item: detail };
|
|
292
|
-
} catch (error) {
|
|
293
|
-
if (error.status !== 404) throw error;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const observationQueries = [
|
|
299
|
-
["/observations", { ...baseParams, userId: config.userId }],
|
|
300
|
-
["/observations", baseParams],
|
|
301
|
-
["/v2/observations", { ...baseParams, fields: "core,basic,usage", userId: config.userId }],
|
|
302
|
-
["/v2/observations", { ...baseParams, fields: "core,basic,usage" }],
|
|
303
|
-
];
|
|
304
|
-
for (const [pathname, params] of observationQueries) {
|
|
305
|
-
try {
|
|
306
|
-
const observations = await langfuseGet(config, pathname, params);
|
|
307
|
-
for (const observation of dataArray(observations)) {
|
|
308
|
-
if (containsMarker(observation, marker)) return { kind: pathname, target, id: idOf(observation), item: observation };
|
|
309
|
-
}
|
|
310
|
-
} catch (error) {
|
|
311
|
-
if (error.status === 404 || error.status === 400) continue;
|
|
312
|
-
throw error;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return null;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
async function pollLangfuse(config, marker, options) {
|
|
320
|
-
const timeoutMs = Number(options.timeoutMs || 180000);
|
|
321
|
-
const pollMs = Number(options.pollMs || 5000);
|
|
322
|
-
const deadline = Date.now() + timeoutMs;
|
|
323
|
-
const since = options.since || new Date(Date.now() - 10 * 60 * 1000);
|
|
324
|
-
let lastError = null;
|
|
325
|
-
|
|
326
|
-
while (Date.now() <= deadline) {
|
|
327
|
-
try {
|
|
328
|
-
const found = await findLangfuseMarker(config, marker, { since, target: options.target });
|
|
329
|
-
if (found) return found;
|
|
330
|
-
console.log(`[WAIT] Langfuse has not returned marker yet (${marker}).`);
|
|
331
|
-
} catch (error) {
|
|
332
|
-
lastError = error;
|
|
333
|
-
console.log(`[WAIT] Langfuse query failed: ${error.message}`);
|
|
334
|
-
}
|
|
335
|
-
await new Promise((resolve) => setTimeout(resolve, pollMs));
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (lastError) throw new Error(`Timed out waiting for marker. Last Langfuse error: ${lastError.message}`);
|
|
339
|
-
throw new Error(`Timed out waiting for marker in Langfuse: ${marker}`);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
async function main() {
|
|
343
|
-
const args = parseArgs(process.argv.slice(2));
|
|
344
|
-
if (args.help || args.h) {
|
|
345
|
-
printHelp();
|
|
346
|
-
return 0;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const config = configFromArgs(args);
|
|
350
|
-
if (!config.userId) throw new Error("Missing --userId or LANGFUSE_USER_ID. Real verification needs a user id to install and filter traces.");
|
|
351
|
-
const targets = splitTargets(args.targets || args.target || args._[0]);
|
|
352
|
-
const marker = String(args.marker || makeMarker());
|
|
353
|
-
const since = new Date();
|
|
354
|
-
const results = [];
|
|
355
|
-
|
|
356
|
-
console.log(`[INFO] Package: ${packageJson.name}@${packageJson.version}`);
|
|
357
|
-
console.log(`[INFO] Targets: ${targets.join(", ")}`);
|
|
358
|
-
console.log(`[INFO] Langfuse: ${config.baseUrl}`);
|
|
359
|
-
console.log(`[INFO] User ID: ${config.userId}`);
|
|
360
|
-
console.log(`[INFO] Marker: ${marker}`);
|
|
361
|
-
console.log("");
|
|
362
|
-
|
|
363
|
-
for (const target of targets) {
|
|
364
|
-
if (!args["skip-install"]) {
|
|
365
|
-
const code = setupTarget(target, config, args);
|
|
366
|
-
if (code !== 0) throw new Error(`Setup failed for ${target} with exit code ${code}.`);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const prompt = validationPrompt(marker, target, args.prompt);
|
|
370
|
-
const env = {
|
|
371
|
-
TRACE_TO_LANGFUSE: "true",
|
|
372
|
-
LANGFUSE_PUBLIC_KEY: config.publicKey,
|
|
373
|
-
LANGFUSE_SECRET_KEY: config.secretKey,
|
|
374
|
-
LANGFUSE_BASEURL: config.baseUrl,
|
|
375
|
-
LANGFUSE_HOST: config.baseUrl,
|
|
376
|
-
LANGFUSE_USER_ID: config.userId,
|
|
377
|
-
CC_USER_ID: config.userId,
|
|
378
|
-
CC_LANGFUSE_USER_ID: config.userId,
|
|
379
|
-
CODEX_LANGFUSE_USER_ID: config.userId,
|
|
380
|
-
OHAI_REAL_SELF_VERIFY_MARKER: marker,
|
|
381
|
-
OHAI_REAL_SELF_VERIFY_TARGET: target,
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
if (!args["skip-trigger"]) {
|
|
385
|
-
const trigger =
|
|
386
|
-
target === "claude"
|
|
387
|
-
? triggerClaude(prompt, args, env)
|
|
388
|
-
: target === "opencode"
|
|
389
|
-
? triggerOpenCode(prompt, args, env)
|
|
390
|
-
: triggerCodex(prompt, args, env);
|
|
391
|
-
printRunResult(`${target} trigger`, trigger);
|
|
392
|
-
if (trigger.status !== 0 && !args["allow-trigger-failure"]) {
|
|
393
|
-
throw new Error(`${target} trigger failed before Langfuse polling. Use --allow-trigger-failure to poll anyway.`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
const found = await pollLangfuse(config, marker, { ...args, since, target });
|
|
398
|
-
console.log(`[OK] Langfuse marker found for ${target}: ${found.kind} ${found.id || ""}`.trim());
|
|
399
|
-
results.push({ target, marker, langfuse: { kind: found.kind, id: found.id || "" } });
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
console.log("");
|
|
403
|
-
console.log(JSON.stringify({ ok: true, package: packageJson.name, marker, results }, null, 2));
|
|
404
|
-
return 0;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
main()
|
|
408
|
-
.then((code) => {
|
|
409
|
-
process.exitCode = code;
|
|
410
|
-
})
|
|
411
|
-
.catch((error) => {
|
|
412
|
-
console.error(`[FAIL] ${error?.message || String(error)}`);
|
|
413
|
-
process.exitCode = 1;
|
|
414
|
-
});
|