@rynfar/meridian 1.63.0 → 1.65.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.
- package/README.md +3 -2
- package/dist/{cli-hdyptm7z.js → cli-7cts44b5.js} +15672 -4267
- package/dist/cli-n8t34zmq.js +939 -0
- package/dist/{cli-m0p2bc8v.js → cli-pdpry6q0.js} +16 -3
- package/dist/cli.js +72 -13
- package/dist/meridian-v2.js +347 -0
- package/dist/{profileCli-39vshwdn.js → profileCli-ap7eg985.js} +2 -2
- package/dist/{profiles-0pyeqayw.js → profiles-4ajzjqhm.js} +1 -1
- package/dist/proxy/adapter.d.ts +16 -0
- package/dist/proxy/adapter.d.ts.map +1 -1
- package/dist/proxy/adapters/opencode.d.ts.map +1 -1
- package/dist/proxy/errors.d.ts.map +1 -1
- package/dist/proxy/passthroughTools.d.ts.map +1 -1
- package/dist/proxy/priorityAttestation.d.ts +35 -0
- package/dist/proxy/priorityAttestation.d.ts.map +1 -0
- package/dist/proxy/routing.d.ts +16 -2
- package/dist/proxy/routing.d.ts.map +1 -1
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/proxy/session/cache.d.ts +25 -2
- package/dist/proxy/session/cache.d.ts.map +1 -1
- package/dist/proxy/session/lineage.d.ts +1 -1
- package/dist/proxy/session/lineage.d.ts.map +1 -1
- package/dist/proxy/session/turnCoordinator.d.ts +2 -0
- package/dist/proxy/session/turnCoordinator.d.ts.map +1 -1
- package/dist/proxy/sessionStore.d.ts +133 -0
- package/dist/proxy/sessionStore.d.ts.map +1 -1
- package/dist/proxy/settings.d.ts +2 -0
- package/dist/proxy/settings.d.ts.map +1 -1
- package/dist/proxy/setup.d.ts +35 -10
- package/dist/proxy/setup.d.ts.map +1 -1
- package/dist/server.js +5 -5
- package/dist/setup-8fwgwhqh.js +33 -0
- package/package.json +9 -5
- package/plugin/meridian-v2.ts +335 -0
- package/plugin/meridian.ts +125 -20
- package/plugin/priority-attestation.ts +150 -0
- package/dist/cli-pc0mtjjv.js +0 -167
- package/dist/setup-0x573t61.js +0 -19
- package/dist/{cli-xfbhn15a.js → cli-0ed6j0vk.js} +3 -3
|
@@ -0,0 +1,939 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
__esm,
|
|
4
|
+
__require,
|
|
5
|
+
__toESM
|
|
6
|
+
} from "./cli-p9swy5t3.js";
|
|
7
|
+
|
|
8
|
+
// node_modules/isexe/windows.js
|
|
9
|
+
var require_windows = __commonJS((exports, module) => {
|
|
10
|
+
module.exports = isexe;
|
|
11
|
+
isexe.sync = sync;
|
|
12
|
+
var fs = __require("fs");
|
|
13
|
+
function checkPathExt(path, options) {
|
|
14
|
+
var pathext = options.pathExt !== undefined ? options.pathExt : process.env.PATHEXT;
|
|
15
|
+
if (!pathext) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
pathext = pathext.split(";");
|
|
19
|
+
if (pathext.indexOf("") !== -1) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
for (var i = 0;i < pathext.length; i++) {
|
|
23
|
+
var p = pathext[i].toLowerCase();
|
|
24
|
+
if (p && path.substr(-p.length).toLowerCase() === p) {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
function checkStat(stat, path, options) {
|
|
31
|
+
if (!stat.isSymbolicLink() && !stat.isFile()) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return checkPathExt(path, options);
|
|
35
|
+
}
|
|
36
|
+
function isexe(path, options, cb) {
|
|
37
|
+
fs.stat(path, function(er, stat) {
|
|
38
|
+
cb(er, er ? false : checkStat(stat, path, options));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function sync(path, options) {
|
|
42
|
+
return checkStat(fs.statSync(path), path, options);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// node_modules/isexe/mode.js
|
|
47
|
+
var require_mode = __commonJS((exports, module) => {
|
|
48
|
+
module.exports = isexe;
|
|
49
|
+
isexe.sync = sync;
|
|
50
|
+
var fs = __require("fs");
|
|
51
|
+
function isexe(path, options, cb) {
|
|
52
|
+
fs.stat(path, function(er, stat) {
|
|
53
|
+
cb(er, er ? false : checkStat(stat, options));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function sync(path, options) {
|
|
57
|
+
return checkStat(fs.statSync(path), options);
|
|
58
|
+
}
|
|
59
|
+
function checkStat(stat, options) {
|
|
60
|
+
return stat.isFile() && checkMode(stat, options);
|
|
61
|
+
}
|
|
62
|
+
function checkMode(stat, options) {
|
|
63
|
+
var mod = stat.mode;
|
|
64
|
+
var uid = stat.uid;
|
|
65
|
+
var gid = stat.gid;
|
|
66
|
+
var myUid = options.uid !== undefined ? options.uid : process.getuid && process.getuid();
|
|
67
|
+
var myGid = options.gid !== undefined ? options.gid : process.getgid && process.getgid();
|
|
68
|
+
var u = parseInt("100", 8);
|
|
69
|
+
var g = parseInt("010", 8);
|
|
70
|
+
var o = parseInt("001", 8);
|
|
71
|
+
var ug = u | g;
|
|
72
|
+
var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
|
|
73
|
+
return ret;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// node_modules/isexe/index.js
|
|
78
|
+
var require_isexe = __commonJS((exports, module) => {
|
|
79
|
+
var fs = __require("fs");
|
|
80
|
+
var core;
|
|
81
|
+
if (process.platform === "win32" || global.TESTING_WINDOWS) {
|
|
82
|
+
core = require_windows();
|
|
83
|
+
} else {
|
|
84
|
+
core = require_mode();
|
|
85
|
+
}
|
|
86
|
+
module.exports = isexe;
|
|
87
|
+
isexe.sync = sync;
|
|
88
|
+
function isexe(path, options, cb) {
|
|
89
|
+
if (typeof options === "function") {
|
|
90
|
+
cb = options;
|
|
91
|
+
options = {};
|
|
92
|
+
}
|
|
93
|
+
if (!cb) {
|
|
94
|
+
if (typeof Promise !== "function") {
|
|
95
|
+
throw new TypeError("callback not provided");
|
|
96
|
+
}
|
|
97
|
+
return new Promise(function(resolve, reject) {
|
|
98
|
+
isexe(path, options || {}, function(er, is) {
|
|
99
|
+
if (er) {
|
|
100
|
+
reject(er);
|
|
101
|
+
} else {
|
|
102
|
+
resolve(is);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
core(path, options || {}, function(er, is) {
|
|
108
|
+
if (er) {
|
|
109
|
+
if (er.code === "EACCES" || options && options.ignoreErrors) {
|
|
110
|
+
er = null;
|
|
111
|
+
is = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
cb(er, is);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function sync(path, options) {
|
|
118
|
+
try {
|
|
119
|
+
return core.sync(path, options || {});
|
|
120
|
+
} catch (er) {
|
|
121
|
+
if (options && options.ignoreErrors || er.code === "EACCES") {
|
|
122
|
+
return false;
|
|
123
|
+
} else {
|
|
124
|
+
throw er;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// node_modules/which/which.js
|
|
131
|
+
var require_which = __commonJS((exports, module) => {
|
|
132
|
+
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
|
|
133
|
+
var path = __require("path");
|
|
134
|
+
var COLON = isWindows ? ";" : ":";
|
|
135
|
+
var isexe = require_isexe();
|
|
136
|
+
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
|
|
137
|
+
var getPathInfo = (cmd, opt) => {
|
|
138
|
+
const colon = opt.colon || COLON;
|
|
139
|
+
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
|
|
140
|
+
...isWindows ? [process.cwd()] : [],
|
|
141
|
+
...(opt.path || process.env.PATH || "").split(colon)
|
|
142
|
+
];
|
|
143
|
+
const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
|
|
144
|
+
const pathExt = isWindows ? pathExtExe.split(colon) : [""];
|
|
145
|
+
if (isWindows) {
|
|
146
|
+
if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
|
|
147
|
+
pathExt.unshift("");
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
pathEnv,
|
|
151
|
+
pathExt,
|
|
152
|
+
pathExtExe
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
var which = (cmd, opt, cb) => {
|
|
156
|
+
if (typeof opt === "function") {
|
|
157
|
+
cb = opt;
|
|
158
|
+
opt = {};
|
|
159
|
+
}
|
|
160
|
+
if (!opt)
|
|
161
|
+
opt = {};
|
|
162
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
163
|
+
const found = [];
|
|
164
|
+
const step = (i) => new Promise((resolve, reject) => {
|
|
165
|
+
if (i === pathEnv.length)
|
|
166
|
+
return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
|
|
167
|
+
const ppRaw = pathEnv[i];
|
|
168
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
169
|
+
const pCmd = path.join(pathPart, cmd);
|
|
170
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
171
|
+
resolve(subStep(p, i, 0));
|
|
172
|
+
});
|
|
173
|
+
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
|
|
174
|
+
if (ii === pathExt.length)
|
|
175
|
+
return resolve(step(i + 1));
|
|
176
|
+
const ext = pathExt[ii];
|
|
177
|
+
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
178
|
+
if (!er && is) {
|
|
179
|
+
if (opt.all)
|
|
180
|
+
found.push(p + ext);
|
|
181
|
+
else
|
|
182
|
+
return resolve(p + ext);
|
|
183
|
+
}
|
|
184
|
+
return resolve(subStep(p, i, ii + 1));
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
188
|
+
};
|
|
189
|
+
var whichSync = (cmd, opt) => {
|
|
190
|
+
opt = opt || {};
|
|
191
|
+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
192
|
+
const found = [];
|
|
193
|
+
for (let i = 0;i < pathEnv.length; i++) {
|
|
194
|
+
const ppRaw = pathEnv[i];
|
|
195
|
+
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
196
|
+
const pCmd = path.join(pathPart, cmd);
|
|
197
|
+
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
198
|
+
for (let j = 0;j < pathExt.length; j++) {
|
|
199
|
+
const cur = p + pathExt[j];
|
|
200
|
+
try {
|
|
201
|
+
const is = isexe.sync(cur, { pathExt: pathExtExe });
|
|
202
|
+
if (is) {
|
|
203
|
+
if (opt.all)
|
|
204
|
+
found.push(cur);
|
|
205
|
+
else
|
|
206
|
+
return cur;
|
|
207
|
+
}
|
|
208
|
+
} catch (ex) {}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (opt.all && found.length)
|
|
212
|
+
return found;
|
|
213
|
+
if (opt.nothrow)
|
|
214
|
+
return null;
|
|
215
|
+
throw getNotFoundError(cmd);
|
|
216
|
+
};
|
|
217
|
+
module.exports = which;
|
|
218
|
+
which.sync = whichSync;
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
// node_modules/path-key/index.js
|
|
222
|
+
var require_path_key = __commonJS((exports, module) => {
|
|
223
|
+
var pathKey = (options = {}) => {
|
|
224
|
+
const environment = options.env || process.env;
|
|
225
|
+
const platform = options.platform || process.platform;
|
|
226
|
+
if (platform !== "win32") {
|
|
227
|
+
return "PATH";
|
|
228
|
+
}
|
|
229
|
+
return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
|
|
230
|
+
};
|
|
231
|
+
module.exports = pathKey;
|
|
232
|
+
module.exports.default = pathKey;
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// node_modules/cross-spawn/lib/util/resolveCommand.js
|
|
236
|
+
var require_resolveCommand = __commonJS((exports, module) => {
|
|
237
|
+
var path = __require("path");
|
|
238
|
+
var which = require_which();
|
|
239
|
+
var getPathKey = require_path_key();
|
|
240
|
+
function resolveCommandAttempt(parsed, withoutPathExt) {
|
|
241
|
+
const env = parsed.options.env || process.env;
|
|
242
|
+
const cwd = process.cwd();
|
|
243
|
+
const hasCustomCwd = parsed.options.cwd != null;
|
|
244
|
+
const shouldSwitchCwd = hasCustomCwd && process.chdir !== undefined && !process.chdir.disabled;
|
|
245
|
+
if (shouldSwitchCwd) {
|
|
246
|
+
try {
|
|
247
|
+
process.chdir(parsed.options.cwd);
|
|
248
|
+
} catch (err) {}
|
|
249
|
+
}
|
|
250
|
+
let resolved;
|
|
251
|
+
try {
|
|
252
|
+
resolved = which.sync(parsed.command, {
|
|
253
|
+
path: env[getPathKey({ env })],
|
|
254
|
+
pathExt: withoutPathExt ? path.delimiter : undefined
|
|
255
|
+
});
|
|
256
|
+
} catch (e) {} finally {
|
|
257
|
+
if (shouldSwitchCwd) {
|
|
258
|
+
process.chdir(cwd);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (resolved) {
|
|
262
|
+
resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
|
|
263
|
+
}
|
|
264
|
+
return resolved;
|
|
265
|
+
}
|
|
266
|
+
function resolveCommand(parsed) {
|
|
267
|
+
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
|
|
268
|
+
}
|
|
269
|
+
module.exports = resolveCommand;
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// node_modules/cross-spawn/lib/util/escape.js
|
|
273
|
+
var require_escape = __commonJS((exports, module) => {
|
|
274
|
+
var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
|
|
275
|
+
function escapeCommand(arg) {
|
|
276
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
277
|
+
return arg;
|
|
278
|
+
}
|
|
279
|
+
function escapeArgument(arg, doubleEscapeMetaChars) {
|
|
280
|
+
arg = `${arg}`;
|
|
281
|
+
arg = arg.replace(/(?=(\\+?)?)\1"/g, "$1$1\\\"");
|
|
282
|
+
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
|
|
283
|
+
arg = `"${arg}"`;
|
|
284
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
285
|
+
if (doubleEscapeMetaChars) {
|
|
286
|
+
arg = arg.replace(metaCharsRegExp, "^$1");
|
|
287
|
+
}
|
|
288
|
+
return arg;
|
|
289
|
+
}
|
|
290
|
+
exports.command = escapeCommand;
|
|
291
|
+
exports.argument = escapeArgument;
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// node_modules/shebang-regex/index.js
|
|
295
|
+
var require_shebang_regex = __commonJS((exports, module) => {
|
|
296
|
+
module.exports = /^#!(.*)/;
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
// node_modules/shebang-command/index.js
|
|
300
|
+
var require_shebang_command = __commonJS((exports, module) => {
|
|
301
|
+
var shebangRegex = require_shebang_regex();
|
|
302
|
+
module.exports = (string = "") => {
|
|
303
|
+
const match = string.match(shebangRegex);
|
|
304
|
+
if (!match) {
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
|
|
308
|
+
const binary = path.split("/").pop();
|
|
309
|
+
if (binary === "env") {
|
|
310
|
+
return argument;
|
|
311
|
+
}
|
|
312
|
+
return argument ? `${binary} ${argument}` : binary;
|
|
313
|
+
};
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
// node_modules/cross-spawn/lib/util/readShebang.js
|
|
317
|
+
var require_readShebang = __commonJS((exports, module) => {
|
|
318
|
+
var fs = __require("fs");
|
|
319
|
+
var shebangCommand = require_shebang_command();
|
|
320
|
+
function readShebang(command) {
|
|
321
|
+
const size = 150;
|
|
322
|
+
const buffer = Buffer.alloc(size);
|
|
323
|
+
let fd;
|
|
324
|
+
try {
|
|
325
|
+
fd = fs.openSync(command, "r");
|
|
326
|
+
fs.readSync(fd, buffer, 0, size, 0);
|
|
327
|
+
fs.closeSync(fd);
|
|
328
|
+
} catch (e) {}
|
|
329
|
+
return shebangCommand(buffer.toString());
|
|
330
|
+
}
|
|
331
|
+
module.exports = readShebang;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
// node_modules/cross-spawn/lib/parse.js
|
|
335
|
+
var require_parse = __commonJS((exports, module) => {
|
|
336
|
+
var path = __require("path");
|
|
337
|
+
var resolveCommand = require_resolveCommand();
|
|
338
|
+
var escape = require_escape();
|
|
339
|
+
var readShebang = require_readShebang();
|
|
340
|
+
var isWin = process.platform === "win32";
|
|
341
|
+
var isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
342
|
+
var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
|
|
343
|
+
function detectShebang(parsed) {
|
|
344
|
+
parsed.file = resolveCommand(parsed);
|
|
345
|
+
const shebang = parsed.file && readShebang(parsed.file);
|
|
346
|
+
if (shebang) {
|
|
347
|
+
parsed.args.unshift(parsed.file);
|
|
348
|
+
parsed.command = shebang;
|
|
349
|
+
return resolveCommand(parsed);
|
|
350
|
+
}
|
|
351
|
+
return parsed.file;
|
|
352
|
+
}
|
|
353
|
+
function parseNonShell(parsed) {
|
|
354
|
+
if (!isWin) {
|
|
355
|
+
return parsed;
|
|
356
|
+
}
|
|
357
|
+
const commandFile = detectShebang(parsed);
|
|
358
|
+
const needsShell = !isExecutableRegExp.test(commandFile);
|
|
359
|
+
if (parsed.options.forceShell || needsShell) {
|
|
360
|
+
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
361
|
+
parsed.command = path.normalize(parsed.command);
|
|
362
|
+
parsed.command = escape.command(parsed.command);
|
|
363
|
+
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
364
|
+
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
365
|
+
parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
|
|
366
|
+
parsed.command = process.env.comspec || "cmd.exe";
|
|
367
|
+
parsed.options.windowsVerbatimArguments = true;
|
|
368
|
+
}
|
|
369
|
+
return parsed;
|
|
370
|
+
}
|
|
371
|
+
function parse(command, args, options) {
|
|
372
|
+
if (args && !Array.isArray(args)) {
|
|
373
|
+
options = args;
|
|
374
|
+
args = null;
|
|
375
|
+
}
|
|
376
|
+
args = args ? args.slice(0) : [];
|
|
377
|
+
options = Object.assign({}, options);
|
|
378
|
+
const parsed = {
|
|
379
|
+
command,
|
|
380
|
+
args,
|
|
381
|
+
options,
|
|
382
|
+
file: undefined,
|
|
383
|
+
original: {
|
|
384
|
+
command,
|
|
385
|
+
args
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
return options.shell ? parsed : parseNonShell(parsed);
|
|
389
|
+
}
|
|
390
|
+
module.exports = parse;
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// node_modules/cross-spawn/lib/enoent.js
|
|
394
|
+
var require_enoent = __commonJS((exports, module) => {
|
|
395
|
+
var isWin = process.platform === "win32";
|
|
396
|
+
function notFoundError(original, syscall) {
|
|
397
|
+
return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
|
|
398
|
+
code: "ENOENT",
|
|
399
|
+
errno: "ENOENT",
|
|
400
|
+
syscall: `${syscall} ${original.command}`,
|
|
401
|
+
path: original.command,
|
|
402
|
+
spawnargs: original.args
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function hookChildProcess(cp, parsed) {
|
|
406
|
+
if (!isWin) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
const originalEmit = cp.emit;
|
|
410
|
+
cp.emit = function(name, arg1) {
|
|
411
|
+
if (name === "exit") {
|
|
412
|
+
const err = verifyENOENT(arg1, parsed);
|
|
413
|
+
if (err) {
|
|
414
|
+
return originalEmit.call(cp, "error", err);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return originalEmit.apply(cp, arguments);
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
function verifyENOENT(status, parsed) {
|
|
421
|
+
if (isWin && status === 1 && !parsed.file) {
|
|
422
|
+
return notFoundError(parsed.original, "spawn");
|
|
423
|
+
}
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
function verifyENOENTSync(status, parsed) {
|
|
427
|
+
if (isWin && status === 1 && !parsed.file) {
|
|
428
|
+
return notFoundError(parsed.original, "spawnSync");
|
|
429
|
+
}
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
module.exports = {
|
|
433
|
+
hookChildProcess,
|
|
434
|
+
verifyENOENT,
|
|
435
|
+
verifyENOENTSync,
|
|
436
|
+
notFoundError
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
// node_modules/cross-spawn/index.js
|
|
441
|
+
var require_cross_spawn = __commonJS((exports, module) => {
|
|
442
|
+
var cp = __require("child_process");
|
|
443
|
+
var parse = require_parse();
|
|
444
|
+
var enoent = require_enoent();
|
|
445
|
+
function spawn(command, args, options) {
|
|
446
|
+
const parsed = parse(command, args, options);
|
|
447
|
+
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
448
|
+
enoent.hookChildProcess(spawned, parsed);
|
|
449
|
+
return spawned;
|
|
450
|
+
}
|
|
451
|
+
function spawnSync(command, args, options) {
|
|
452
|
+
const parsed = parse(command, args, options);
|
|
453
|
+
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
454
|
+
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
module.exports = spawn;
|
|
458
|
+
module.exports.spawn = spawn;
|
|
459
|
+
module.exports.sync = spawnSync;
|
|
460
|
+
module.exports._parse = parse;
|
|
461
|
+
module.exports._enoent = enoent;
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// src/proxy/priorityAttestation.ts
|
|
465
|
+
import { chmodSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
466
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
467
|
+
import { homedir, platform } from "node:os";
|
|
468
|
+
import { dirname, join } from "node:path";
|
|
469
|
+
function configDirectory() {
|
|
470
|
+
return process.env.MERIDIAN_CONFIG_DIR ?? join(homedir(), ".config", "meridian");
|
|
471
|
+
}
|
|
472
|
+
function priorityAttestationKeyPath() {
|
|
473
|
+
return join(configDirectory(), PRIORITY_ATTESTATION_KEY_FILE);
|
|
474
|
+
}
|
|
475
|
+
function decodeCanonicalBase64Url(raw) {
|
|
476
|
+
if (!/^[A-Za-z0-9_-]+$/.test(raw))
|
|
477
|
+
return;
|
|
478
|
+
const decoded = Buffer.from(raw, "base64url");
|
|
479
|
+
return decoded.toString("base64url") === raw ? decoded : undefined;
|
|
480
|
+
}
|
|
481
|
+
function decodePriorityAttestationKey(raw) {
|
|
482
|
+
if (raw === undefined)
|
|
483
|
+
return;
|
|
484
|
+
const decoded = decodeCanonicalBase64Url(raw.trim());
|
|
485
|
+
return decoded?.length === 32 ? decoded : undefined;
|
|
486
|
+
}
|
|
487
|
+
function loadPriorityAttestationKey() {
|
|
488
|
+
const fromEnv = process.env[PRIORITY_ATTESTATION_KEY_ENV];
|
|
489
|
+
if (fromEnv !== undefined)
|
|
490
|
+
return decodePriorityAttestationKey(fromEnv);
|
|
491
|
+
try {
|
|
492
|
+
return decodePriorityAttestationKey(readFileSync(priorityAttestationKeyPath(), "utf8"));
|
|
493
|
+
} catch {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function readRequiredFileKey(path) {
|
|
498
|
+
let raw;
|
|
499
|
+
try {
|
|
500
|
+
raw = readFileSync(path, "utf8");
|
|
501
|
+
} catch {
|
|
502
|
+
throw new InvalidPriorityAttestationKeyError(path);
|
|
503
|
+
}
|
|
504
|
+
const key = decodePriorityAttestationKey(raw);
|
|
505
|
+
if (!key)
|
|
506
|
+
throw new InvalidPriorityAttestationKeyError(path);
|
|
507
|
+
return key;
|
|
508
|
+
}
|
|
509
|
+
function ensurePriorityAttestationKey() {
|
|
510
|
+
const fromEnv = process.env[PRIORITY_ATTESTATION_KEY_ENV];
|
|
511
|
+
if (fromEnv !== undefined) {
|
|
512
|
+
const key2 = decodePriorityAttestationKey(fromEnv);
|
|
513
|
+
if (!key2)
|
|
514
|
+
throw new InvalidPriorityAttestationKeyError(PRIORITY_ATTESTATION_KEY_ENV);
|
|
515
|
+
return { key: key2 };
|
|
516
|
+
}
|
|
517
|
+
const path = priorityAttestationKeyPath();
|
|
518
|
+
try {
|
|
519
|
+
const key2 = readRequiredFileKey(path);
|
|
520
|
+
if (platform() !== "win32")
|
|
521
|
+
chmodSync(path, 384);
|
|
522
|
+
return { key: key2, path };
|
|
523
|
+
} catch (error) {
|
|
524
|
+
if (!(error instanceof InvalidPriorityAttestationKeyError))
|
|
525
|
+
throw error;
|
|
526
|
+
try {
|
|
527
|
+
readFileSync(path);
|
|
528
|
+
throw error;
|
|
529
|
+
} catch (readError) {
|
|
530
|
+
if (readError === error)
|
|
531
|
+
throw error;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
535
|
+
const encoded = randomBytes(32).toString("base64url");
|
|
536
|
+
try {
|
|
537
|
+
writeFileSync(path, `${encoded}
|
|
538
|
+
`, { encoding: "utf8", flag: "wx", mode: 384 });
|
|
539
|
+
} catch (error) {
|
|
540
|
+
const code = typeof error === "object" && error !== null ? Reflect.get(error, "code") : undefined;
|
|
541
|
+
if (code !== "EEXIST")
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
const key = readRequiredFileKey(path);
|
|
545
|
+
if (platform() !== "win32")
|
|
546
|
+
chmodSync(path, 384);
|
|
547
|
+
return { key, path };
|
|
548
|
+
}
|
|
549
|
+
function isRecord(value) {
|
|
550
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
551
|
+
}
|
|
552
|
+
function isSafeAgentId(value) {
|
|
553
|
+
return value.length >= 1 && value.length <= 64 && value.trim() === value && /^[\x20-\x7E]+$/.test(value);
|
|
554
|
+
}
|
|
555
|
+
function parseCanonicalPayload(raw) {
|
|
556
|
+
if (Buffer.byteLength(raw) > MAX_PAYLOAD_BYTES)
|
|
557
|
+
return;
|
|
558
|
+
let value;
|
|
559
|
+
try {
|
|
560
|
+
value = JSON.parse(raw);
|
|
561
|
+
} catch {
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
if (!isRecord(value))
|
|
565
|
+
return;
|
|
566
|
+
if (Object.keys(value).join(",") !== "v,g,s,a,t,iat")
|
|
567
|
+
return;
|
|
568
|
+
if (value.v !== 1)
|
|
569
|
+
return;
|
|
570
|
+
if (value.g !== "oc1" && value.g !== "oc2b18314")
|
|
571
|
+
return;
|
|
572
|
+
if (typeof value.s !== "string" || !SAFE_ID_PATTERN.test(value.s))
|
|
573
|
+
return;
|
|
574
|
+
if (typeof value.a !== "string" || !isSafeAgentId(value.a))
|
|
575
|
+
return;
|
|
576
|
+
if (typeof value.t !== "string" || !TURN_DIGEST_PATTERN.test(value.t))
|
|
577
|
+
return;
|
|
578
|
+
if (typeof value.iat !== "number" || !Number.isSafeInteger(value.iat) || value.iat < 0)
|
|
579
|
+
return;
|
|
580
|
+
const canonical = JSON.stringify({
|
|
581
|
+
v: 1,
|
|
582
|
+
g: value.g,
|
|
583
|
+
s: value.s,
|
|
584
|
+
a: value.a,
|
|
585
|
+
t: value.t,
|
|
586
|
+
iat: value.iat
|
|
587
|
+
});
|
|
588
|
+
if (canonical !== raw)
|
|
589
|
+
return;
|
|
590
|
+
return {
|
|
591
|
+
generation: value.g,
|
|
592
|
+
sessionId: value.s,
|
|
593
|
+
agentId: value.a,
|
|
594
|
+
turnId: value.t,
|
|
595
|
+
issuedAt: value.iat
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function verifyPriorityAttestation(token, key = loadPriorityAttestationKey() ?? Buffer.alloc(0), nowSeconds = Math.floor(Date.now() / 1000)) {
|
|
599
|
+
if (!token || key.length !== 32 || Buffer.byteLength(token) > MAX_HEADER_BYTES)
|
|
600
|
+
return;
|
|
601
|
+
const match = TOKEN_PATTERN.exec(token);
|
|
602
|
+
if (!match?.[1] || !match[2])
|
|
603
|
+
return;
|
|
604
|
+
const payloadBytes = decodeCanonicalBase64Url(match[1]);
|
|
605
|
+
const suppliedMac = decodeCanonicalBase64Url(match[2]);
|
|
606
|
+
if (!payloadBytes || !suppliedMac || suppliedMac.length !== 32)
|
|
607
|
+
return;
|
|
608
|
+
const payloadRaw = payloadBytes.toString("utf8");
|
|
609
|
+
if (Buffer.from(payloadRaw, "utf8").compare(payloadBytes) !== 0)
|
|
610
|
+
return;
|
|
611
|
+
const payload = parseCanonicalPayload(payloadRaw);
|
|
612
|
+
if (!payload)
|
|
613
|
+
return;
|
|
614
|
+
if (payload.issuedAt < nowSeconds - MAX_PAST_AGE_SECONDS)
|
|
615
|
+
return;
|
|
616
|
+
if (payload.issuedAt > nowSeconds + MAX_FUTURE_SKEW_SECONDS)
|
|
617
|
+
return;
|
|
618
|
+
const expectedMac = createHmac("sha256", key).update(MAC_DOMAIN).update(payloadRaw).digest();
|
|
619
|
+
if (!timingSafeEqual(expectedMac, suppliedMac))
|
|
620
|
+
return;
|
|
621
|
+
return payload;
|
|
622
|
+
}
|
|
623
|
+
var PRIORITY_ATTESTATION_HEADER = "x-meridian-opencode-turn", PRIORITY_ATTESTATION_KEY_ENV = "MERIDIAN_OPENCODE_ATTESTATION_KEY", PRIORITY_ATTESTATION_KEY_FILE = "opencode-turn.key", TOKEN_PATTERN, MAC_DOMAIN = "meridian.opencode.turn.v1\x00", MAX_HEADER_BYTES = 768, MAX_PAYLOAD_BYTES = 384, MAX_PAST_AGE_SECONDS = 120, MAX_FUTURE_SKEW_SECONDS = 30, SAFE_ID_PATTERN, TURN_DIGEST_PATTERN, InvalidPriorityAttestationKeyError;
|
|
624
|
+
var init_priorityAttestation = __esm(() => {
|
|
625
|
+
TOKEN_PATTERN = /^v1\.([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/;
|
|
626
|
+
SAFE_ID_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
627
|
+
TURN_DIGEST_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
628
|
+
InvalidPriorityAttestationKeyError = class InvalidPriorityAttestationKeyError extends Error {
|
|
629
|
+
keyPath;
|
|
630
|
+
constructor(keyPath) {
|
|
631
|
+
super(`OpenCode routing attestation key is invalid at ${keyPath}`);
|
|
632
|
+
this.keyPath = keyPath;
|
|
633
|
+
this.name = "InvalidPriorityAttestationKeyError";
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
// src/proxy/setup.ts
|
|
639
|
+
var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
640
|
+
import { existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
641
|
+
import { homedir as homedir2, platform as platform2 } from "os";
|
|
642
|
+
import { basename, dirname as dirname2, join as join2 } from "path";
|
|
643
|
+
import { fileURLToPath } from "url";
|
|
644
|
+
import { applyEdits, modify, parse as parseJsonc } from "jsonc-parser";
|
|
645
|
+
|
|
646
|
+
// src/utils/lruMap.ts
|
|
647
|
+
class LRUMap {
|
|
648
|
+
maxSize;
|
|
649
|
+
onEvict;
|
|
650
|
+
map = new Map;
|
|
651
|
+
constructor(maxSize, onEvict) {
|
|
652
|
+
this.maxSize = maxSize;
|
|
653
|
+
this.onEvict = onEvict;
|
|
654
|
+
}
|
|
655
|
+
get size() {
|
|
656
|
+
return this.map.size;
|
|
657
|
+
}
|
|
658
|
+
get(key) {
|
|
659
|
+
const value = this.map.get(key);
|
|
660
|
+
if (value === undefined)
|
|
661
|
+
return;
|
|
662
|
+
this.map.delete(key);
|
|
663
|
+
this.map.set(key, value);
|
|
664
|
+
return value;
|
|
665
|
+
}
|
|
666
|
+
set(key, value) {
|
|
667
|
+
if (this.map.has(key)) {
|
|
668
|
+
this.map.delete(key);
|
|
669
|
+
} else if (this.map.size >= this.maxSize) {
|
|
670
|
+
this.evictOldest();
|
|
671
|
+
}
|
|
672
|
+
this.map.set(key, value);
|
|
673
|
+
return this;
|
|
674
|
+
}
|
|
675
|
+
has(key) {
|
|
676
|
+
return this.map.has(key);
|
|
677
|
+
}
|
|
678
|
+
delete(key) {
|
|
679
|
+
return this.map.delete(key);
|
|
680
|
+
}
|
|
681
|
+
clear() {
|
|
682
|
+
this.map.clear();
|
|
683
|
+
}
|
|
684
|
+
entries() {
|
|
685
|
+
return this.map.entries();
|
|
686
|
+
}
|
|
687
|
+
keys() {
|
|
688
|
+
return this.map.keys();
|
|
689
|
+
}
|
|
690
|
+
values() {
|
|
691
|
+
return this.map.values();
|
|
692
|
+
}
|
|
693
|
+
forEach(callbackfn) {
|
|
694
|
+
this.map.forEach((value, key) => callbackfn(value, key, this));
|
|
695
|
+
}
|
|
696
|
+
[Symbol.iterator]() {
|
|
697
|
+
return this.map[Symbol.iterator]();
|
|
698
|
+
}
|
|
699
|
+
evictOldest() {
|
|
700
|
+
const oldestKey = this.map.keys().next().value;
|
|
701
|
+
if (oldestKey === undefined)
|
|
702
|
+
return;
|
|
703
|
+
const oldestValue = this.map.get(oldestKey);
|
|
704
|
+
if (oldestValue === undefined)
|
|
705
|
+
return;
|
|
706
|
+
this.map.delete(oldestKey);
|
|
707
|
+
this.onEvict?.(oldestKey, oldestValue);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/proxy/setup.ts
|
|
712
|
+
init_priorityAttestation();
|
|
713
|
+
|
|
714
|
+
class UnparseableConfigError extends Error {
|
|
715
|
+
configPath;
|
|
716
|
+
constructor(configPath) {
|
|
717
|
+
super(`Could not parse ${configPath} — it may contain a syntax error.`);
|
|
718
|
+
this.configPath = configPath;
|
|
719
|
+
this.name = "UnparseableConfigError";
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
class MissingV2PluginError extends Error {
|
|
724
|
+
expectedPath;
|
|
725
|
+
constructor(expectedPath) {
|
|
726
|
+
super(`OpenCode V2 plugin bundle not found at ${expectedPath}`);
|
|
727
|
+
this.expectedPath = expectedPath;
|
|
728
|
+
this.name = "MissingV2PluginError";
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
class DuplicateMeridianConfigError extends Error {
|
|
733
|
+
configPath;
|
|
734
|
+
siblingPath;
|
|
735
|
+
constructor(configPath, siblingPath) {
|
|
736
|
+
super(`A Meridian entry in ${siblingPath} conflicts with setup target ${configPath}`);
|
|
737
|
+
this.configPath = configPath;
|
|
738
|
+
this.siblingPath = siblingPath;
|
|
739
|
+
this.name = "DuplicateMeridianConfigError";
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function parseOpencodeConfig(text) {
|
|
743
|
+
const errors = [];
|
|
744
|
+
const parsed = parseJsonc(text, errors, { allowTrailingComma: true });
|
|
745
|
+
if (errors.length > 0 || parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
return parsed;
|
|
749
|
+
}
|
|
750
|
+
function opencodeConfigDirectory() {
|
|
751
|
+
if (process.env.OPENCODE_CONFIG_DIR)
|
|
752
|
+
return process.env.OPENCODE_CONFIG_DIR;
|
|
753
|
+
if (process.env.XDG_CONFIG_HOME)
|
|
754
|
+
return join2(process.env.XDG_CONFIG_HOME, "opencode");
|
|
755
|
+
if (platform2() === "win32" && process.env.APPDATA)
|
|
756
|
+
return join2(process.env.APPDATA, "opencode");
|
|
757
|
+
return join2(homedir2(), ".config", "opencode");
|
|
758
|
+
}
|
|
759
|
+
function findOpencodeConfigPath() {
|
|
760
|
+
const dir = opencodeConfigDirectory();
|
|
761
|
+
const jsonPath = join2(dir, "opencode.json");
|
|
762
|
+
const jsoncPath = join2(dir, "opencode.jsonc");
|
|
763
|
+
return !existsSync(jsonPath) && existsSync(jsoncPath) ? jsoncPath : jsonPath;
|
|
764
|
+
}
|
|
765
|
+
function siblingOpencodeConfigPath(configPath) {
|
|
766
|
+
const name = basename(configPath);
|
|
767
|
+
if (name === "opencode.json")
|
|
768
|
+
return join2(dirname2(configPath), "opencode.jsonc");
|
|
769
|
+
if (name === "opencode.jsonc")
|
|
770
|
+
return join2(dirname2(configPath), "opencode.json");
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
function findPluginPath(fromUrl) {
|
|
774
|
+
const dir = dirname2(fileURLToPath(fromUrl));
|
|
775
|
+
return join2(dir, "..", "plugin", "meridian.ts");
|
|
776
|
+
}
|
|
777
|
+
var SUPPORTED_OPENCODE_V2_VERSION = "0.0.0-beta-18314";
|
|
778
|
+
function findV2PluginPath(fromUrl) {
|
|
779
|
+
const entryPath = fileURLToPath(fromUrl);
|
|
780
|
+
const dir = dirname2(entryPath);
|
|
781
|
+
if (entryPath.endsWith(".ts")) {
|
|
782
|
+
const sourcePlugin = join2(dir, "..", "plugin", "meridian-v2.ts");
|
|
783
|
+
if (existsSync(sourcePlugin))
|
|
784
|
+
return sourcePlugin;
|
|
785
|
+
throw new MissingV2PluginError(sourcePlugin);
|
|
786
|
+
}
|
|
787
|
+
const bundledPlugin = join2(dir, "meridian-v2.js");
|
|
788
|
+
if (existsSync(bundledPlugin))
|
|
789
|
+
return bundledPlugin;
|
|
790
|
+
throw new MissingV2PluginError(bundledPlugin);
|
|
791
|
+
}
|
|
792
|
+
function classifyOpenCodeVersion(output) {
|
|
793
|
+
const match = output.trim().match(/^(?:opencode2?\s+)?v?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)$/i);
|
|
794
|
+
const version = match?.[1];
|
|
795
|
+
if (!version)
|
|
796
|
+
return;
|
|
797
|
+
const major = Number(version.split(".", 1)[0]);
|
|
798
|
+
return {
|
|
799
|
+
generation: major === 1 ? "v1" : "v2",
|
|
800
|
+
version
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function detectOpenCodeGeneration(commands = process.env.OPENCODE_BIN ? [process.env.OPENCODE_BIN] : ["opencode", "opencode2"], probe = (command) => {
|
|
804
|
+
const result = import_cross_spawn.default.sync(command, ["--version"], {
|
|
805
|
+
encoding: "utf8",
|
|
806
|
+
timeout: 3000,
|
|
807
|
+
windowsHide: true
|
|
808
|
+
});
|
|
809
|
+
if (result.error || result.status !== 0)
|
|
810
|
+
return;
|
|
811
|
+
return String(result.stdout ?? "");
|
|
812
|
+
}) {
|
|
813
|
+
for (const command of commands) {
|
|
814
|
+
const output = probe(command);
|
|
815
|
+
if (!output)
|
|
816
|
+
continue;
|
|
817
|
+
const detected = classifyOpenCodeVersion(output);
|
|
818
|
+
if (detected)
|
|
819
|
+
return { ...detected, command };
|
|
820
|
+
}
|
|
821
|
+
return { generation: "v1" };
|
|
822
|
+
}
|
|
823
|
+
function pluginPathForGeneration(fromUrl, generation) {
|
|
824
|
+
return generation === "v2" ? findV2PluginPath(fromUrl) : findPluginPath(fromUrl);
|
|
825
|
+
}
|
|
826
|
+
var STALE_PATTERNS = [
|
|
827
|
+
"opencode-claude-max-proxy",
|
|
828
|
+
"claude-max-headers",
|
|
829
|
+
"meridian-agent-mode"
|
|
830
|
+
];
|
|
831
|
+
function pluginEntryPackage(entry) {
|
|
832
|
+
if (typeof entry === "string")
|
|
833
|
+
return entry;
|
|
834
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry))
|
|
835
|
+
return;
|
|
836
|
+
const packageName = Reflect.get(entry, "package");
|
|
837
|
+
return typeof packageName === "string" ? packageName : undefined;
|
|
838
|
+
}
|
|
839
|
+
function isMeridianEntry(entry) {
|
|
840
|
+
const packageName = pluginEntryPackage(entry);
|
|
841
|
+
if (!packageName)
|
|
842
|
+
return false;
|
|
843
|
+
return STALE_PATTERNS.some((pattern) => packageName.includes(pattern)) || packageName.includes("meridian.ts") || packageName.includes("meridian-v2.") || packageName.includes("@rynfar/meridian");
|
|
844
|
+
}
|
|
845
|
+
function checkPluginConfigured(configPath, expectedPluginPath) {
|
|
846
|
+
const selectedPath = configPath ?? findOpencodeConfigPath();
|
|
847
|
+
const siblingPath = configPath ? undefined : siblingOpencodeConfigPath(selectedPath);
|
|
848
|
+
const paths = siblingPath ? [selectedPath, siblingPath] : [selectedPath];
|
|
849
|
+
return paths.some((path) => {
|
|
850
|
+
if (!existsSync(path))
|
|
851
|
+
return false;
|
|
852
|
+
const config = parseOpencodeConfig(readFileSync2(path, "utf-8"));
|
|
853
|
+
if (config === null)
|
|
854
|
+
return false;
|
|
855
|
+
const plugins = [
|
|
856
|
+
...Array.isArray(config.plugin) ? config.plugin : [],
|
|
857
|
+
...Array.isArray(config.plugins) ? config.plugins : []
|
|
858
|
+
];
|
|
859
|
+
if (expectedPluginPath)
|
|
860
|
+
return plugins.some((entry) => pluginEntryPackage(entry) === expectedPluginPath);
|
|
861
|
+
return plugins.some(isMeridianEntry);
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
var pluginlessWarned = new LRUMap(256);
|
|
865
|
+
function clearPluginlessWarnings() {
|
|
866
|
+
pluginlessWarned.clear();
|
|
867
|
+
}
|
|
868
|
+
function notePluginlessOpenCodeRequest(input) {
|
|
869
|
+
if (!input.userAgent?.toLowerCase().startsWith("opencode/"))
|
|
870
|
+
return;
|
|
871
|
+
if (input.agentModeHeader)
|
|
872
|
+
return;
|
|
873
|
+
const key = input.sessionId || "(keyless)";
|
|
874
|
+
if (pluginlessWarned.get(key))
|
|
875
|
+
return;
|
|
876
|
+
pluginlessWarned.set(key, true);
|
|
877
|
+
const shortId = input.sessionId ? `${input.sessionId.slice(0, 12)}…` : "(no session header)";
|
|
878
|
+
return `OpenCode request without the Meridian plugin's agent headers (session ${shortId}). ` + `OpenCode runs its internal title/summary agents under your session id, so Meridian ` + `cannot tell them apart from your conversation: the first turn of each session can fail ` + `with a 400 or replay against a cold cache. Fix: meridian setup (or update the plugin).`;
|
|
879
|
+
}
|
|
880
|
+
function runSetup(pluginPath, configPath, generation = "v1") {
|
|
881
|
+
const path = configPath ?? findOpencodeConfigPath();
|
|
882
|
+
const dir = dirname2(path);
|
|
883
|
+
const targetField = generation === "v2" ? "plugins" : "plugin";
|
|
884
|
+
const otherField = generation === "v2" ? "plugin" : "plugins";
|
|
885
|
+
const siblingPath = siblingOpencodeConfigPath(path);
|
|
886
|
+
if (siblingPath && existsSync(siblingPath)) {
|
|
887
|
+
const siblingConfig = parseOpencodeConfig(readFileSync2(siblingPath, "utf-8"));
|
|
888
|
+
if (siblingConfig === null)
|
|
889
|
+
throw new UnparseableConfigError(siblingPath);
|
|
890
|
+
const siblingPlugins = [
|
|
891
|
+
...Array.isArray(siblingConfig.plugin) ? siblingConfig.plugin : [],
|
|
892
|
+
...Array.isArray(siblingConfig.plugins) ? siblingConfig.plugins : []
|
|
893
|
+
];
|
|
894
|
+
if (siblingPlugins.some(isMeridianEntry)) {
|
|
895
|
+
throw new DuplicateMeridianConfigError(path, siblingPath);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
if (!existsSync(path)) {
|
|
899
|
+
ensurePriorityAttestationKey();
|
|
900
|
+
if (!existsSync(dir))
|
|
901
|
+
mkdirSync2(dir, { recursive: true });
|
|
902
|
+
writeFileSync2(path, `${JSON.stringify({ [targetField]: [pluginPath] }, null, 2)}
|
|
903
|
+
`, "utf-8");
|
|
904
|
+
return { configPath: path, pluginPath, alreadyConfigured: false, removedStale: [], created: true };
|
|
905
|
+
}
|
|
906
|
+
const text = readFileSync2(path, "utf-8");
|
|
907
|
+
const config = parseOpencodeConfig(text);
|
|
908
|
+
if (config === null) {
|
|
909
|
+
throw new UnparseableConfigError(path);
|
|
910
|
+
}
|
|
911
|
+
const entries = (field) => Array.isArray(config[field]) ? config[field] : [];
|
|
912
|
+
const targetEntries = entries(targetField);
|
|
913
|
+
const otherEntries = entries(otherField);
|
|
914
|
+
const targetMeridian = targetEntries.filter(isMeridianEntry);
|
|
915
|
+
const otherMeridian = otherEntries.filter(isMeridianEntry);
|
|
916
|
+
const targetExact = targetMeridian.filter((entry) => pluginEntryPackage(entry) === pluginPath);
|
|
917
|
+
const removedStale = [...targetMeridian, ...otherMeridian].flatMap((entry) => {
|
|
918
|
+
const packageName = pluginEntryPackage(entry);
|
|
919
|
+
return packageName ? [packageName] : [];
|
|
920
|
+
});
|
|
921
|
+
const alreadyConfigured = targetMeridian.length === 1 && targetExact.length === 1 && otherMeridian.length === 0;
|
|
922
|
+
const targetPlugin = targetExact.length === 1 && targetMeridian.length === 1 ? targetExact[0] : pluginPath;
|
|
923
|
+
const targetPlugins = [
|
|
924
|
+
...targetEntries.filter((entry) => !isMeridianEntry(entry)),
|
|
925
|
+
targetPlugin
|
|
926
|
+
];
|
|
927
|
+
const otherPlugins = otherEntries.filter((entry) => !isMeridianEntry(entry));
|
|
928
|
+
let updated = text;
|
|
929
|
+
const formattingOptions = { insertSpaces: true, tabSize: 2 };
|
|
930
|
+
updated = applyEdits(updated, modify(updated, [targetField], targetPlugins, { formattingOptions }));
|
|
931
|
+
if (Array.isArray(config[otherField]) && otherMeridian.length > 0) {
|
|
932
|
+
updated = applyEdits(updated, modify(updated, [otherField], otherPlugins, { formattingOptions }));
|
|
933
|
+
}
|
|
934
|
+
ensurePriorityAttestationKey();
|
|
935
|
+
writeFileSync2(path, updated, "utf-8");
|
|
936
|
+
return { configPath: path, pluginPath, alreadyConfigured, removedStale, created: false };
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
export { LRUMap, PRIORITY_ATTESTATION_HEADER, verifyPriorityAttestation, init_priorityAttestation, UnparseableConfigError, MissingV2PluginError, DuplicateMeridianConfigError, findOpencodeConfigPath, findPluginPath, SUPPORTED_OPENCODE_V2_VERSION, findV2PluginPath, classifyOpenCodeVersion, detectOpenCodeGeneration, pluginPathForGeneration, checkPluginConfigured, clearPluginlessWarnings, notePluginlessOpenCodeRequest, runSetup };
|