@opencode/browse 0.0.11-dev.76 → 0.0.11-dev.77
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-qpkh40gh.mjs → cli-mx6tbg2m.mjs} +63 -52
- package/dist/cli.mjs +30 -19
- package/dist/{helpers-kp0j46jt.mjs → helpers-hgm1z9h5.mjs} +2 -2
- package/dist/{index-0dcypq31.mjs → index-yzz55kxm.mjs} +1 -1
- package/dist/{main-brv9dhy5.mjs → main-1fdejpga.mjs} +9 -9
- package/dist/{main-ajza8egc.mjs → main-6chyyr6j.mjs} +44 -39
- package/dist/{main-rt6g5418.mjs → main-8z9d979q.mjs} +15 -15
- package/dist/{setup-j76yv51b.mjs → main-b7g6460c.mjs} +3608 -4406
- package/dist/{main-gevbt7h7.mjs → main-csnx585b.mjs} +151 -151
- package/dist/{main-nqmm7pdz.mjs → main-cymarjp4.mjs} +47 -47
- package/dist/main-j2ehvkhk.mjs +465 -0
- package/dist/main-r3a6053j.mjs +157 -0
- package/dist/main-s7017yah.mjs +161 -0
- package/dist/main-sjrzyg3x.mjs +73 -0
- package/dist/main-vgzr4689.mjs +61 -0
- package/dist/{main-eej5z0y5.mjs → main-zq79yb8r.mjs} +6 -6
- package/dist/main-zya5ttbr.mjs +4 -0
- package/dist/{mcp-sy8qgkyr.mjs → mcp-h0qcxhqc.mjs} +138 -137
- package/dist/migrate-pgckfkg5.mjs +233 -0
- package/dist/{relay-ateyg5ax.mjs → relay-gafgjtav.mjs} +128 -123
- package/dist/runtime-update-p2pnfdy1.mjs +156 -0
- package/dist/setup-fhhjnx9r.mjs +956 -0
- package/dist/{skill-text-x7sccp6h.mjs → skill-text-6p6scqwe.mjs} +2 -2
- package/dist/{supervisor-0rvjpf4e.mjs → supervisor-06t66v4t.mjs} +38 -17
- package/dist/{update-rbd2025v.mjs → update-7hagfdc0.mjs} +3 -3
- package/dist/{version-4cjr3wpp.mjs → version-hhcvk9wm.mjs} +1 -1
- package/package.json +1 -1
- package/skills/browse/SKILL.md +2 -2
- package/dist/main-7wgmq04v.mjs +0 -303
- package/dist/main-exnm62gg.mjs +0 -4
- package/dist/main-hm4fcpfz.mjs +0 -131
- package/dist/main-rn7hdcq2.mjs +0 -805
- package/dist/runtime-update-70gqzynp.mjs +0 -200
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import {
|
|
2
|
+
writePrivateJsonFileSync
|
|
3
|
+
} from "./main-vgzr4689.mjs";
|
|
4
|
+
import {
|
|
5
|
+
bundledPairingCodeTtlMs,
|
|
6
|
+
mintPairingCode,
|
|
7
|
+
writeExtensionPairing
|
|
8
|
+
} from "./main-r3a6053j.mjs";
|
|
9
|
+
import {
|
|
10
|
+
configRoot2,
|
|
11
|
+
cacheRoot,
|
|
12
|
+
devExtensionUrl,
|
|
13
|
+
devExtensionFolder
|
|
14
|
+
} from "./main-j2ehvkhk.mjs";
|
|
15
|
+
|
|
16
|
+
// src/setup/dev-extension.ts
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { crc32, inflateRawSync } from "node:zlib";
|
|
21
|
+
var devExtensionRecord = (root = cacheRoot()) => path.join(root, "extension.json");
|
|
22
|
+
function installedDevExtension(root = cacheRoot()) {
|
|
23
|
+
try {
|
|
24
|
+
const record = JSON.parse(readFileSync(devExtensionRecord(root), "utf8"));
|
|
25
|
+
return typeof record.sha256 === "string" && existsSync(path.join(devExtensionFolder(root), "manifest.json")) ? record : undefined;
|
|
26
|
+
} catch {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function syncDevExtension(extension, options = {}) {
|
|
31
|
+
const root = options.root ?? cacheRoot();
|
|
32
|
+
const folder = devExtensionFolder(root);
|
|
33
|
+
if (installedDevExtension(root)?.sha256 === extension.sha256)
|
|
34
|
+
return "current";
|
|
35
|
+
const url = devExtensionUrl(extension, options.env);
|
|
36
|
+
const response = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(120000), headers: { "user-agent": "browse/dev" } });
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
throw new Error(`downloading the dev extension from ${url} failed: HTTP ${response.status}`);
|
|
39
|
+
const zip = Buffer.from(await response.arrayBuffer());
|
|
40
|
+
const sha256 = createHash("sha256").update(zip).digest("hex");
|
|
41
|
+
if (zip.length !== extension.size || sha256 !== extension.sha256)
|
|
42
|
+
throw new Error(`the dev extension from ${url} isn't the one this version was built with (sha256 ${sha256}, ${zip.length} bytes)`);
|
|
43
|
+
mkdirSync(root, { recursive: true });
|
|
44
|
+
const staging = path.join(root, `.extension-${process.pid}-${Date.now()}`);
|
|
45
|
+
const old = `${staging}-old`;
|
|
46
|
+
rmSync(staging, { recursive: true, force: true });
|
|
47
|
+
try {
|
|
48
|
+
for (const entry of unzip(zip)) {
|
|
49
|
+
const target = path.join(staging, ...entry.name.split("/"));
|
|
50
|
+
mkdirSync(path.dirname(target), { recursive: true });
|
|
51
|
+
if (!entry.directory)
|
|
52
|
+
writeFileSync(target, entry.data);
|
|
53
|
+
}
|
|
54
|
+
const manifest = JSON.parse(readFileSync(path.join(staging, "manifest.json"), "utf8"));
|
|
55
|
+
if (!manifest.key)
|
|
56
|
+
throw new Error("the dev extension has no manifest key, so it wouldn't have browse's unpacked ID");
|
|
57
|
+
writeExtensionPairing(staging, mintPairingCode(undefined, { ttlMs: bundledPairingCodeTtlMs }));
|
|
58
|
+
const build = (() => {
|
|
59
|
+
try {
|
|
60
|
+
return JSON.parse(readFileSync(path.join(staging, "build.json"), "utf8")).build;
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
})();
|
|
65
|
+
if (existsSync(folder))
|
|
66
|
+
renameSync(folder, old);
|
|
67
|
+
renameSync(staging, folder);
|
|
68
|
+
const version = manifest.version_name ?? manifest.version;
|
|
69
|
+
const record = { ...version ? { version } : {}, file: extension.file, sha256, ...build ? { build } : {}, installedAt: new Date().toISOString() };
|
|
70
|
+
writeFileSync(devExtensionRecord(root), JSON.stringify(record, null, 2) + `
|
|
71
|
+
`);
|
|
72
|
+
return "updated";
|
|
73
|
+
} finally {
|
|
74
|
+
rmSync(staging, { recursive: true, force: true });
|
|
75
|
+
rmSync(old, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function unzip(zip) {
|
|
79
|
+
let end = -1;
|
|
80
|
+
for (let offset = zip.length - 22;offset >= Math.max(0, zip.length - 22 - 65535); offset--)
|
|
81
|
+
if (zip.readUInt32LE(offset) === 101010256) {
|
|
82
|
+
end = offset;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (end < 0)
|
|
86
|
+
throw new Error("not a zip archive");
|
|
87
|
+
const count = zip.readUInt16LE(end + 10);
|
|
88
|
+
let offset = zip.readUInt32LE(end + 16);
|
|
89
|
+
const entries = [];
|
|
90
|
+
for (let index = 0;index < count; index++) {
|
|
91
|
+
if (zip.readUInt32LE(offset) !== 33639248)
|
|
92
|
+
throw new Error("corrupt zip central directory");
|
|
93
|
+
const method = zip.readUInt16LE(offset + 10);
|
|
94
|
+
const crc = zip.readUInt32LE(offset + 16);
|
|
95
|
+
const compressed = zip.readUInt32LE(offset + 20);
|
|
96
|
+
const size = zip.readUInt32LE(offset + 24);
|
|
97
|
+
const nameLength = zip.readUInt16LE(offset + 28);
|
|
98
|
+
const extraLength = zip.readUInt16LE(offset + 30);
|
|
99
|
+
const commentLength = zip.readUInt16LE(offset + 32);
|
|
100
|
+
const mode = zip.readUInt32LE(offset + 38) >>> 16;
|
|
101
|
+
const local = zip.readUInt32LE(offset + 42);
|
|
102
|
+
const name = zip.toString("utf8", offset + 46, offset + 46 + nameLength);
|
|
103
|
+
offset += 46 + nameLength + extraLength + commentLength;
|
|
104
|
+
if (!name || name.startsWith("/") || name.includes("\\") || name.split("/").some((part) => part === ".." || part === "."))
|
|
105
|
+
throw new Error(`unsafe path in zip: ${JSON.stringify(name)}`);
|
|
106
|
+
if ((mode & 61440) === 40960)
|
|
107
|
+
throw new Error(`symbolic link in zip: ${name}`);
|
|
108
|
+
if (compressed === 4294967295 || size === 4294967295)
|
|
109
|
+
throw new Error("ZIP64 archives aren't supported");
|
|
110
|
+
const directory = name.endsWith("/");
|
|
111
|
+
if (directory) {
|
|
112
|
+
entries.push({ name: name.slice(0, -1), directory, data: Buffer.alloc(0) });
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (zip.readUInt32LE(local) !== 67324752)
|
|
116
|
+
throw new Error(`corrupt zip entry ${name}`);
|
|
117
|
+
const start = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
|
|
118
|
+
const raw = zip.subarray(start, start + compressed);
|
|
119
|
+
const data = method === 0 ? Buffer.from(raw) : method === 8 ? inflateRawSync(raw) : undefined;
|
|
120
|
+
if (!data)
|
|
121
|
+
throw new Error(`unsupported compression method ${method} for ${name}`);
|
|
122
|
+
if (data.length !== size || crc32(data) !== crc)
|
|
123
|
+
throw new Error(`zip entry ${name} is corrupt`);
|
|
124
|
+
entries.push({ name, directory, data });
|
|
125
|
+
}
|
|
126
|
+
return entries;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/relay/config.ts
|
|
130
|
+
import fs from "node:fs";
|
|
131
|
+
import path2 from "node:path";
|
|
132
|
+
var relayConfigPath = (root = configRoot2()) => path2.join(root, "config.json");
|
|
133
|
+
function parseHostname(input) {
|
|
134
|
+
if (typeof input !== "string")
|
|
135
|
+
return;
|
|
136
|
+
const value = input.trim().toLowerCase();
|
|
137
|
+
if (value === "127.0.0.1" || value === "localhost")
|
|
138
|
+
return "127.0.0.1";
|
|
139
|
+
if (value === "0.0.0.0")
|
|
140
|
+
return "0.0.0.0";
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
function readRelayConfig(root = configRoot2()) {
|
|
144
|
+
try {
|
|
145
|
+
const value = JSON.parse(fs.readFileSync(relayConfigPath(root), "utf8"));
|
|
146
|
+
const hostname = parseHostname(value?.hostname);
|
|
147
|
+
return hostname === undefined ? {} : { hostname };
|
|
148
|
+
} catch {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function writeRelayConfig(config, root = configRoot2()) {
|
|
153
|
+
writePrivateJsonFileSync(relayConfigPath(root), config, { ensureParent: true });
|
|
154
|
+
}
|
|
155
|
+
var relayHostname = (root = configRoot2()) => readRelayConfig(root).hostname ?? "127.0.0.1";
|
|
156
|
+
function isLocalPeer(socket) {
|
|
157
|
+
const remote = socket.remoteAddress?.replace(/^::ffff:/, "");
|
|
158
|
+
return remote !== undefined && (remote === "::1" || remote.startsWith("127."));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { parseHostname, readRelayConfig, writeRelayConfig, relayHostname, isLocalPeer, installedDevExtension, syncDevExtension };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ensurePrivateDirectorySync
|
|
3
|
+
} from "./main-vgzr4689.mjs";
|
|
4
|
+
import {
|
|
5
|
+
dataRoot
|
|
6
|
+
} from "./main-j2ehvkhk.mjs";
|
|
7
|
+
|
|
8
|
+
// src/relay/secrets.ts
|
|
9
|
+
import crypto from "node:crypto";
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
var relayTokenQueryParam = "opencodeBrowserToken";
|
|
13
|
+
var tokenPattern = /^[A-Za-z0-9_-]{43}$/;
|
|
14
|
+
function relayTokenPath(root = dataRoot()) {
|
|
15
|
+
return path.join(root, "relay-token");
|
|
16
|
+
}
|
|
17
|
+
function relayToken(root = dataRoot()) {
|
|
18
|
+
return readOrCreateSecret(relayTokenPath(root), () => crypto.randomBytes(32).toString("base64url"), (value) => tokenPattern.test(value));
|
|
19
|
+
}
|
|
20
|
+
function relayAuthorization(root = dataRoot()) {
|
|
21
|
+
return `Bearer ${relayToken(root)}`;
|
|
22
|
+
}
|
|
23
|
+
function secretsEqual(expected, actual) {
|
|
24
|
+
if (actual === undefined)
|
|
25
|
+
return false;
|
|
26
|
+
const a = crypto.createHash("sha256").update(expected).digest();
|
|
27
|
+
const b = crypto.createHash("sha256").update(actual).digest();
|
|
28
|
+
return crypto.timingSafeEqual(a, b) && expected.length === actual.length;
|
|
29
|
+
}
|
|
30
|
+
function readOrCreateSecret(file, generate, valid) {
|
|
31
|
+
const existing = readSecret(file);
|
|
32
|
+
if (existing !== undefined && valid(existing))
|
|
33
|
+
return existing;
|
|
34
|
+
ensurePrivateDirectory(path.dirname(file));
|
|
35
|
+
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
36
|
+
fs.writeFileSync(temporary, `${generate()}
|
|
37
|
+
`, { mode: 384 });
|
|
38
|
+
try {
|
|
39
|
+
if (existing === undefined) {
|
|
40
|
+
try {
|
|
41
|
+
fs.linkSync(temporary, file);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error.code !== "EEXIST")
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
fs.renameSync(temporary, file);
|
|
48
|
+
}
|
|
49
|
+
} finally {
|
|
50
|
+
fs.rmSync(temporary, { force: true });
|
|
51
|
+
}
|
|
52
|
+
const created = readSecret(file);
|
|
53
|
+
if (created === undefined || !valid(created))
|
|
54
|
+
throw new Error(`Could not create ${file}`);
|
|
55
|
+
return created;
|
|
56
|
+
}
|
|
57
|
+
function readSecret(file) {
|
|
58
|
+
try {
|
|
59
|
+
const stat = fs.statSync(file);
|
|
60
|
+
if (process.platform !== "win32" && (stat.mode & 63) !== 0)
|
|
61
|
+
fs.chmodSync(file, 384);
|
|
62
|
+
return fs.readFileSync(file, "utf8").trim();
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error.code === "ENOENT")
|
|
65
|
+
return;
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function ensurePrivateDirectory(directory = dataRoot()) {
|
|
70
|
+
ensurePrivateDirectorySync(directory);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { relayTokenQueryParam, relayToken, relayAuthorization, secretsEqual, ensurePrivateDirectory };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isString
|
|
3
|
+
} from "./main-yf9xhpn4.mjs";
|
|
4
|
+
// src/fs-durability.ts
|
|
5
|
+
import crypto from "node:crypto";
|
|
6
|
+
import fsSync from "node:fs";
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
var unsupportedDirectorySyncCodes = new Set(["EPERM", "EINVAL", "ENOTSUP"]);
|
|
10
|
+
function isNodeError(error) {
|
|
11
|
+
return error instanceof Error && "code" in error;
|
|
12
|
+
}
|
|
13
|
+
function isUnsupportedDirectorySyncError(error) {
|
|
14
|
+
return isNodeError(error) && isString(error.code) && unsupportedDirectorySyncCodes.has(error.code);
|
|
15
|
+
}
|
|
16
|
+
async function writeJsonFileAtomically(filePath, value, options = {}) {
|
|
17
|
+
const directory = path.dirname(filePath);
|
|
18
|
+
await fs.mkdir(directory, {
|
|
19
|
+
recursive: true,
|
|
20
|
+
...options.dirMode === undefined ? {} : { mode: options.dirMode }
|
|
21
|
+
});
|
|
22
|
+
if (options.dirMode !== undefined) {
|
|
23
|
+
await fs.chmod(directory, options.dirMode);
|
|
24
|
+
}
|
|
25
|
+
const temporaryPath = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
26
|
+
let renamed = false;
|
|
27
|
+
try {
|
|
28
|
+
await fs.writeFile(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
29
|
+
`, { mode: 384 });
|
|
30
|
+
await fs.rename(temporaryPath, filePath);
|
|
31
|
+
renamed = true;
|
|
32
|
+
await fs.chmod(filePath, 384);
|
|
33
|
+
} finally {
|
|
34
|
+
if (!renamed)
|
|
35
|
+
await fs.rm(temporaryPath, { force: true }).catch(() => {});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function ensurePrivateDirectorySync(directory) {
|
|
39
|
+
fsSync.mkdirSync(directory, { recursive: true, mode: 448 });
|
|
40
|
+
if (process.platform !== "win32")
|
|
41
|
+
fsSync.chmodSync(directory, 448);
|
|
42
|
+
}
|
|
43
|
+
function writePrivateJsonFileSync(filePath, value, options = {}) {
|
|
44
|
+
if (options.ensureParent)
|
|
45
|
+
ensurePrivateDirectorySync(path.dirname(filePath));
|
|
46
|
+
const temporaryPath = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
47
|
+
let renamed = false;
|
|
48
|
+
try {
|
|
49
|
+
fsSync.writeFileSync(temporaryPath, `${JSON.stringify(value, null, 2)}
|
|
50
|
+
`, { mode: 384 });
|
|
51
|
+
fsSync.renameSync(temporaryPath, filePath);
|
|
52
|
+
renamed = true;
|
|
53
|
+
if (process.platform !== "win32")
|
|
54
|
+
fsSync.chmodSync(filePath, 384);
|
|
55
|
+
} finally {
|
|
56
|
+
if (!renamed)
|
|
57
|
+
fsSync.rmSync(temporaryPath, { force: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { isNodeError, isUnsupportedDirectorySyncError, writeJsonFileAtomically, ensurePrivateDirectorySync, writePrivateJsonFileSync };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isNodeError
|
|
3
|
-
} from "./main-
|
|
3
|
+
} from "./main-vgzr4689.mjs";
|
|
4
4
|
import {
|
|
5
5
|
isValidSessionId2
|
|
6
|
-
} from "./main-
|
|
6
|
+
} from "./main-6chyyr6j.mjs";
|
|
7
7
|
import {
|
|
8
8
|
isSome,
|
|
9
9
|
decodeUnknownOption,
|
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
Struct,
|
|
15
15
|
ArraySchema,
|
|
16
16
|
NullOr
|
|
17
|
-
} from "./main-
|
|
17
|
+
} from "./main-csnx585b.mjs";
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
} from "./main-
|
|
19
|
+
stateRoot
|
|
20
|
+
} from "./main-j2ehvkhk.mjs";
|
|
21
21
|
|
|
22
22
|
// src/session-manager/journal.ts
|
|
23
23
|
import fs from "node:fs";
|
|
@@ -39,7 +39,7 @@ var JournalEntry = Struct({
|
|
|
39
39
|
});
|
|
40
40
|
var decodeJournalEntry = decodeUnknownOption(JournalEntry);
|
|
41
41
|
var defaultJournalBaseDir = () => {
|
|
42
|
-
return path.join(
|
|
42
|
+
return path.join(stateRoot(), "sessions");
|
|
43
43
|
};
|
|
44
44
|
function journalPathForSession(baseDir, sessionId) {
|
|
45
45
|
return path.join(baseDir, sessionId, "journal.jsonl");
|