opencode-swarm 7.82.2 → 7.84.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 -1
- package/dist/cli/capability-probe-jevmgwmf.js +18 -0
- package/dist/cli/config-doctor-4tcdd9vt.js +35 -0
- package/dist/cli/dispatch-k86d928w.js +477 -0
- package/dist/cli/evidence-summary-service-g2znnd33.js +320 -0
- package/dist/cli/explorer-gz70sm9b.js +16 -0
- package/dist/cli/gate-evidence-y8zn7fe2.js +29 -0
- package/dist/cli/guardrail-explain-tcamcdfy.js +30 -0
- package/dist/cli/guardrail-log-fd14n96q.js +15 -0
- package/dist/cli/index-293f68mj.js +13538 -0
- package/dist/cli/index-8ra2qpk8.js +29027 -0
- package/dist/cli/index-a76rekgs.js +67 -0
- package/dist/cli/index-a82d6d87.js +1241 -0
- package/dist/cli/index-b9v501fr.js +371 -0
- package/dist/cli/index-bcp79s17.js +1673 -0
- package/dist/cli/index-ckntc5gf.js +91 -0
- package/dist/cli/index-d9fbxaqd.js +2314 -0
- package/dist/cli/index-e7h9bb6v.js +233 -0
- package/dist/cli/index-e8pk68cc.js +540 -0
- package/dist/cli/index-eb85wtx9.js +242 -0
- package/dist/cli/index-f8r50m3h.js +14505 -0
- package/dist/cli/index-fjwwrwr5.js +37 -0
- package/dist/cli/index-hz59hg4h.js +452 -0
- package/dist/cli/index-j710h2ge.js +412 -0
- package/dist/cli/index-jfgr5gye.js +110 -0
- package/dist/cli/index-jtqkh8jf.js +119 -0
- package/dist/cli/index-p0arc26j.js +28 -0
- package/dist/cli/index-p0ye10nd.js +222 -0
- package/dist/cli/index-pv2xmc9k.js +2391 -0
- package/dist/cli/index-red8fm8p.js +2914 -0
- package/dist/cli/index-wg3r6acj.js +2042 -0
- package/dist/cli/index-xw0bcy0v.js +583 -0
- package/dist/cli/index-yhsmmv2z.js +339 -0
- package/dist/cli/index-yx44zd0p.js +40 -0
- package/dist/cli/index-zfsbaaqh.js +29 -0
- package/dist/cli/index.js +73 -69703
- package/dist/cli/knowledge-store-n4x6zyk7.js +73 -0
- package/dist/cli/pending-delegations-pz61mrsz.js +255 -0
- package/dist/cli/pr-subscriptions-y1nn36e5.js +33 -0
- package/dist/cli/schema-c2dbzhm8.js +168 -0
- package/dist/cli/skill-generator-a5ehggyg.js +55 -0
- package/dist/cli/task-envelope-qn0qtnh0.js +90 -0
- package/dist/cli/telemetry-9bbyxrvn.js +20 -0
- package/dist/cli/workspace-snapshot-w58jr2ga.js +90 -0
- package/dist/commands/guardrail-explain.d.ts +1 -0
- package/dist/commands/guardrail-log.d.ts +1 -0
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/registry.d.ts +14 -0
- package/dist/config/index.d.ts +2 -2
- package/dist/config/schema.d.ts +7 -0
- package/dist/hooks/guardrails/audit-log.d.ts +114 -0
- package/dist/hooks/repo-graph-builder.d.ts +4 -1
- package/dist/index.js +3615 -2378
- package/dist/services/diagnose-service.d.ts +5 -0
- package/dist/services/guardrail-explain-service.d.ts +42 -0
- package/dist/services/guardrail-log-service.d.ts +10 -0
- package/dist/tools/repo-graph/types.d.ts +6 -0
- package/package.json +2 -2
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/utils/bun-compat.ts
|
|
3
|
+
import {
|
|
4
|
+
spawn as nodeSpawn,
|
|
5
|
+
spawnSync as nodeSpawnSync
|
|
6
|
+
} from "child_process";
|
|
7
|
+
import * as fsSync from "fs";
|
|
8
|
+
import * as fsPromises from "fs/promises";
|
|
9
|
+
import * as path from "path";
|
|
10
|
+
var WINDOWS_RENAME_MAX_RETRIES = 3;
|
|
11
|
+
var WINDOWS_RENAME_RETRY_DELAY_MS = 50;
|
|
12
|
+
var tempCounter = 0;
|
|
13
|
+
function getBun() {
|
|
14
|
+
const g = globalThis;
|
|
15
|
+
return g.Bun;
|
|
16
|
+
}
|
|
17
|
+
function bunFile(filePath) {
|
|
18
|
+
const bun = getBun();
|
|
19
|
+
if (bun?.file) {
|
|
20
|
+
return bun.file(filePath);
|
|
21
|
+
}
|
|
22
|
+
let cachedSize;
|
|
23
|
+
return {
|
|
24
|
+
async text() {
|
|
25
|
+
return fsPromises.readFile(filePath, "utf-8");
|
|
26
|
+
},
|
|
27
|
+
async arrayBuffer() {
|
|
28
|
+
const buf = await fsPromises.readFile(filePath);
|
|
29
|
+
const ab = new ArrayBuffer(buf.byteLength);
|
|
30
|
+
new Uint8Array(ab).set(buf);
|
|
31
|
+
return ab;
|
|
32
|
+
},
|
|
33
|
+
async exists() {
|
|
34
|
+
try {
|
|
35
|
+
await fsPromises.access(filePath, fsSync.constants.F_OK);
|
|
36
|
+
return true;
|
|
37
|
+
} catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
get size() {
|
|
42
|
+
if (cachedSize !== undefined)
|
|
43
|
+
return cachedSize;
|
|
44
|
+
try {
|
|
45
|
+
cachedSize = fsSync.statSync(filePath).size;
|
|
46
|
+
} catch {
|
|
47
|
+
cachedSize = 0;
|
|
48
|
+
}
|
|
49
|
+
return cachedSize;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async function bunWrite(filePath, data) {
|
|
54
|
+
const bun = getBun();
|
|
55
|
+
if (bun?.write) {
|
|
56
|
+
return bun.write(filePath, data);
|
|
57
|
+
}
|
|
58
|
+
const dir = path.dirname(filePath);
|
|
59
|
+
const tempName = `.${path.basename(filePath)}.${process.pid}.${Date.now()}.${tempCounter++}.${Math.random().toString(36).slice(2, 10)}.tmp`;
|
|
60
|
+
const tempPath = path.join(dir, tempName);
|
|
61
|
+
let buffer;
|
|
62
|
+
if (typeof data === "string") {
|
|
63
|
+
buffer = data;
|
|
64
|
+
} else if (data instanceof ArrayBuffer) {
|
|
65
|
+
buffer = new Uint8Array(data);
|
|
66
|
+
} else if (ArrayBuffer.isView(data)) {
|
|
67
|
+
buffer = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
68
|
+
} else {
|
|
69
|
+
buffer = new Uint8Array(0);
|
|
70
|
+
}
|
|
71
|
+
try {
|
|
72
|
+
await fsPromises.mkdir(dir, { recursive: true });
|
|
73
|
+
} catch {}
|
|
74
|
+
await fsPromises.writeFile(tempPath, buffer);
|
|
75
|
+
let lastError;
|
|
76
|
+
for (let attempt = 0;attempt < WINDOWS_RENAME_MAX_RETRIES; attempt++) {
|
|
77
|
+
try {
|
|
78
|
+
await fsPromises.rename(tempPath, filePath);
|
|
79
|
+
lastError = undefined;
|
|
80
|
+
break;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
lastError = err;
|
|
83
|
+
const code = err.code;
|
|
84
|
+
if (code !== "EEXIST" && code !== "EBUSY" && code !== "EPERM") {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
await new Promise((r) => setTimeout(r, WINDOWS_RENAME_RETRY_DELAY_MS));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (lastError) {
|
|
91
|
+
try {
|
|
92
|
+
await fsPromises.unlink(tempPath);
|
|
93
|
+
} catch {}
|
|
94
|
+
throw lastError;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const dirFd = await fsPromises.open(dir, "r");
|
|
98
|
+
try {
|
|
99
|
+
await dirFd.sync();
|
|
100
|
+
} finally {
|
|
101
|
+
await dirFd.close();
|
|
102
|
+
}
|
|
103
|
+
} catch {}
|
|
104
|
+
const stats = await fsPromises.stat(filePath);
|
|
105
|
+
return stats.size;
|
|
106
|
+
}
|
|
107
|
+
function bunHash(input) {
|
|
108
|
+
const bun = getBun();
|
|
109
|
+
if (bun?.hash) {
|
|
110
|
+
const r = bun.hash(input);
|
|
111
|
+
return typeof r === "bigint" ? r : BigInt(r);
|
|
112
|
+
}
|
|
113
|
+
let bytes;
|
|
114
|
+
if (typeof input === "string") {
|
|
115
|
+
bytes = new TextEncoder().encode(input);
|
|
116
|
+
} else if (input instanceof ArrayBuffer) {
|
|
117
|
+
bytes = new Uint8Array(input);
|
|
118
|
+
} else {
|
|
119
|
+
bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
|
|
120
|
+
}
|
|
121
|
+
let hash = 5381n;
|
|
122
|
+
for (const b of bytes) {
|
|
123
|
+
hash = hash * 33n + BigInt(b) & 0xffffffffffffffffn;
|
|
124
|
+
}
|
|
125
|
+
return hash;
|
|
126
|
+
}
|
|
127
|
+
function killProcessTreeImpl(pid, signal, directKill, wasDetached) {
|
|
128
|
+
if (typeof pid !== "number" || pid <= 0) {
|
|
129
|
+
directKill();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (process.platform === "win32") {
|
|
133
|
+
try {
|
|
134
|
+
nodeSpawnSync("taskkill", ["/PID", String(pid), "/T", "/F"]);
|
|
135
|
+
} catch {
|
|
136
|
+
directKill();
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (wasDetached) {
|
|
141
|
+
try {
|
|
142
|
+
process.kill(-pid, signal ?? "SIGKILL");
|
|
143
|
+
return;
|
|
144
|
+
} catch {}
|
|
145
|
+
}
|
|
146
|
+
directKill();
|
|
147
|
+
}
|
|
148
|
+
function streamFromNode(pipe) {
|
|
149
|
+
const collected = new Promise((resolve) => {
|
|
150
|
+
if (!pipe) {
|
|
151
|
+
resolve(Buffer.alloc(0));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const chunks = [];
|
|
155
|
+
pipe.on("data", (chunk) => {
|
|
156
|
+
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
|
|
157
|
+
});
|
|
158
|
+
pipe.on("end", () => resolve(Buffer.concat(chunks)));
|
|
159
|
+
pipe.on("error", () => resolve(Buffer.concat(chunks)));
|
|
160
|
+
});
|
|
161
|
+
const toWebReadable = () => {
|
|
162
|
+
if (!pipe) {
|
|
163
|
+
return new ReadableStream({
|
|
164
|
+
start(controller) {
|
|
165
|
+
controller.close();
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const r = pipe;
|
|
170
|
+
if (typeof r.toWeb === "function") {
|
|
171
|
+
return r.toWeb();
|
|
172
|
+
}
|
|
173
|
+
return new ReadableStream({
|
|
174
|
+
start(controller) {
|
|
175
|
+
pipe.on("data", (chunk) => {
|
|
176
|
+
controller.enqueue(typeof chunk === "string" ? new TextEncoder().encode(chunk) : new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
177
|
+
});
|
|
178
|
+
pipe.on("end", () => controller.close());
|
|
179
|
+
pipe.on("error", (err) => controller.error(err));
|
|
180
|
+
},
|
|
181
|
+
cancel() {
|
|
182
|
+
const destroyable = pipe;
|
|
183
|
+
if (typeof destroyable.destroy === "function") {
|
|
184
|
+
try {
|
|
185
|
+
destroyable.destroy();
|
|
186
|
+
} catch {}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
return {
|
|
192
|
+
async text() {
|
|
193
|
+
return (await collected).toString("utf-8");
|
|
194
|
+
},
|
|
195
|
+
async bytes() {
|
|
196
|
+
const b = await collected;
|
|
197
|
+
return new Uint8Array(b.buffer, b.byteOffset, b.byteLength);
|
|
198
|
+
},
|
|
199
|
+
getReader() {
|
|
200
|
+
return toWebReadable().getReader();
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function mapStdio(v) {
|
|
205
|
+
return v ?? "pipe";
|
|
206
|
+
}
|
|
207
|
+
function streamFromBun(stream) {
|
|
208
|
+
if (!stream || typeof stream !== "object") {
|
|
209
|
+
const empty = {
|
|
210
|
+
async text() {
|
|
211
|
+
return "";
|
|
212
|
+
},
|
|
213
|
+
async bytes() {
|
|
214
|
+
return new Uint8Array(0);
|
|
215
|
+
},
|
|
216
|
+
getReader() {
|
|
217
|
+
return new ReadableStream({
|
|
218
|
+
start(controller) {
|
|
219
|
+
controller.close();
|
|
220
|
+
}
|
|
221
|
+
}).getReader();
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
return empty;
|
|
225
|
+
}
|
|
226
|
+
const candidate = stream;
|
|
227
|
+
const collect = async () => {
|
|
228
|
+
if (typeof candidate.getReader !== "function") {
|
|
229
|
+
return new Uint8Array(0);
|
|
230
|
+
}
|
|
231
|
+
const reader = candidate.getReader();
|
|
232
|
+
const chunks = [];
|
|
233
|
+
for (;; ) {
|
|
234
|
+
const { done, value } = await reader.read();
|
|
235
|
+
if (done)
|
|
236
|
+
break;
|
|
237
|
+
if (value)
|
|
238
|
+
chunks.push(value);
|
|
239
|
+
}
|
|
240
|
+
const total = chunks.reduce((acc, c) => acc + c.byteLength, 0);
|
|
241
|
+
const out = new Uint8Array(total);
|
|
242
|
+
let off = 0;
|
|
243
|
+
for (const c of chunks) {
|
|
244
|
+
out.set(c, off);
|
|
245
|
+
off += c.byteLength;
|
|
246
|
+
}
|
|
247
|
+
return out;
|
|
248
|
+
};
|
|
249
|
+
const text = typeof candidate.text === "function" ? () => candidate.text() : async () => new TextDecoder().decode(await collect());
|
|
250
|
+
const bytes = typeof candidate.bytes === "function" ? () => candidate.bytes() : collect;
|
|
251
|
+
const getReader = typeof candidate.getReader === "function" ? () => candidate.getReader() : () => new ReadableStream({
|
|
252
|
+
start(controller) {
|
|
253
|
+
controller.close();
|
|
254
|
+
}
|
|
255
|
+
}).getReader();
|
|
256
|
+
return { text, bytes, getReader };
|
|
257
|
+
}
|
|
258
|
+
function bunSpawn(cmd, options) {
|
|
259
|
+
const bun = getBun();
|
|
260
|
+
if (bun?.spawn) {
|
|
261
|
+
const proc2 = bun.spawn(cmd, options);
|
|
262
|
+
return {
|
|
263
|
+
stdout: streamFromBun(proc2.stdout),
|
|
264
|
+
stderr: streamFromBun(proc2.stderr),
|
|
265
|
+
exited: proc2.exited,
|
|
266
|
+
get exitCode() {
|
|
267
|
+
return proc2.exitCode;
|
|
268
|
+
},
|
|
269
|
+
kill(sig) {
|
|
270
|
+
if (options?.killProcessTree) {
|
|
271
|
+
killProcessTreeImpl(proc2.pid, sig, () => proc2.kill(sig), false);
|
|
272
|
+
} else {
|
|
273
|
+
proc2.kill(sig);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const [file, ...args] = cmd;
|
|
279
|
+
const detached = options?.killProcessTree === true;
|
|
280
|
+
const proc = nodeSpawn(file, args, {
|
|
281
|
+
cwd: options?.cwd,
|
|
282
|
+
env: options?.env,
|
|
283
|
+
detached,
|
|
284
|
+
windowsHide: true,
|
|
285
|
+
stdio: [
|
|
286
|
+
mapStdio(options?.stdin),
|
|
287
|
+
mapStdio(options?.stdout),
|
|
288
|
+
mapStdio(options?.stderr)
|
|
289
|
+
]
|
|
290
|
+
});
|
|
291
|
+
const killChild = (signal) => {
|
|
292
|
+
if (detached) {
|
|
293
|
+
killProcessTreeImpl(proc.pid, signal, () => proc.kill(signal), true);
|
|
294
|
+
} else {
|
|
295
|
+
proc.kill(signal);
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
let timeoutHandle;
|
|
299
|
+
const exited = new Promise((resolve) => {
|
|
300
|
+
proc.on("exit", (code) => resolve(code ?? 0));
|
|
301
|
+
proc.on("error", () => resolve(1));
|
|
302
|
+
if (options?.timeout && options.timeout > 0) {
|
|
303
|
+
timeoutHandle = setTimeout(() => {
|
|
304
|
+
try {
|
|
305
|
+
killChild("SIGKILL");
|
|
306
|
+
} catch {}
|
|
307
|
+
}, options.timeout);
|
|
308
|
+
if (typeof timeoutHandle.unref === "function") {
|
|
309
|
+
timeoutHandle.unref();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}).finally(() => {
|
|
313
|
+
if (timeoutHandle !== undefined)
|
|
314
|
+
clearTimeout(timeoutHandle);
|
|
315
|
+
});
|
|
316
|
+
return {
|
|
317
|
+
stdout: streamFromNode(proc.stdout),
|
|
318
|
+
stderr: streamFromNode(proc.stderr),
|
|
319
|
+
exited,
|
|
320
|
+
get exitCode() {
|
|
321
|
+
return proc.exitCode;
|
|
322
|
+
},
|
|
323
|
+
kill(signal) {
|
|
324
|
+
killChild(signal);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function bunSpawnSync(cmd, options) {
|
|
329
|
+
const bun = getBun();
|
|
330
|
+
if (bun?.spawnSync) {
|
|
331
|
+
const result2 = bun.spawnSync(cmd, options);
|
|
332
|
+
return result2;
|
|
333
|
+
}
|
|
334
|
+
let argv;
|
|
335
|
+
let mergedOptions;
|
|
336
|
+
if (Array.isArray(cmd)) {
|
|
337
|
+
argv = cmd;
|
|
338
|
+
mergedOptions = { ...options ?? {} };
|
|
339
|
+
} else {
|
|
340
|
+
argv = cmd.cmd;
|
|
341
|
+
mergedOptions = {
|
|
342
|
+
cwd: cmd.cwd,
|
|
343
|
+
env: cmd.env,
|
|
344
|
+
stdin: "pipe",
|
|
345
|
+
timeout: cmd.timeout,
|
|
346
|
+
...options ?? {}
|
|
347
|
+
};
|
|
348
|
+
if (cmd.stdin !== undefined) {
|
|
349
|
+
mergedOptions.stdin = cmd.stdin;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const [file, ...args] = argv;
|
|
353
|
+
const result = nodeSpawnSync(file, args, {
|
|
354
|
+
cwd: mergedOptions.cwd,
|
|
355
|
+
env: mergedOptions.env,
|
|
356
|
+
input: mergedOptions.stdin instanceof Uint8Array || typeof mergedOptions.stdin === "string" ? mergedOptions.stdin : undefined,
|
|
357
|
+
timeout: mergedOptions.timeout,
|
|
358
|
+
windowsHide: true
|
|
359
|
+
});
|
|
360
|
+
const stdout = result.stdout instanceof Buffer ? new Uint8Array(result.stdout.buffer, result.stdout.byteOffset, result.stdout.byteLength) : typeof result.stdout === "string" ? new TextEncoder().encode(result.stdout) : new Uint8Array(0);
|
|
361
|
+
const stderr = result.stderr instanceof Buffer ? new Uint8Array(result.stderr.buffer, result.stderr.byteOffset, result.stderr.byteLength) : typeof result.stderr === "string" ? new TextEncoder().encode(result.stderr) : new Uint8Array(0);
|
|
362
|
+
const exitCode = result.status ?? (result.signal ? 128 : 1);
|
|
363
|
+
return {
|
|
364
|
+
stdout,
|
|
365
|
+
stderr,
|
|
366
|
+
exitCode,
|
|
367
|
+
success: exitCode === 0 && !result.error
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export { bunFile, bunWrite, bunHash, bunSpawn, bunSpawnSync };
|