Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/lib/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ export function isStandaloneBinary(): boolean {
}

export function isStandaloneModuleUrl(url: string): boolean {
return url.includes("/$bunfs/") || /^file:\/\/\/[A-Za-z]:\/~BUN\//.test(url);
try {
const parsed = new URL(url);
if (parsed.protocol !== "file:" || parsed.host !== "") return false;
// Bun may encode the Windows virtual root's tilde; decode one URL layer only.
const path = decodeURIComponent(parsed.pathname);
return path.startsWith("/$bunfs/") || /^\/[A-Za-z]:\/~BUN\//.test(path);
} catch {
return false;
}
}

/** Directory containing the compiled executable and its copied runtime assets. */
Expand Down
2 changes: 1 addition & 1 deletion structure/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ A source area can be described by more than one doc, because these docs are orga
| `src/index.ts` | [`runtime.md`](runtime.md) |
| `src/integrations/` | [`clients/integrations.md`](clients/integrations.md) |
| `src/lab/` | [`runtime.md`](runtime.md)<br>[`adapters/compatibility-lab.md`](adapters/compatibility-lab.md) |
| `src/lib/` | [`overview.md`](overview.md)<br>[`runtime.md`](runtime.md)<br>[`transports/byte-accounting.md`](transports/byte-accounting.md)<br>[`transports/responses-wire-shapes.md`](transports/responses-wire-shapes.md)<br>[`transports/responses-failover.md`](transports/responses-failover.md)<br>[`transports/responses-spend.md`](transports/responses-spend.md)<br>[`transports/inventory.md`](transports/inventory.md)<br>[`gui-and-management-api.md`](gui-and-management-api.md)<br>[`dashboard-and-usage.md`](dashboard-and-usage.md)<br>[`clients/integrations.md`](clients/integrations.md)<br>[`ops/docs-and-release.md`](ops/docs-and-release.md) |
| `src/lib/` | [`overview.md`](overview.md)<br>[`runtime.md`](runtime.md)<br>[`transports/byte-accounting.md`](transports/byte-accounting.md)<br>[`transports/responses-wire-shapes.md`](transports/responses-wire-shapes.md)<br>[`transports/responses-failover.md`](transports/responses-failover.md)<br>[`transports/responses-spend.md`](transports/responses-spend.md)<br>[`transports/inventory.md`](transports/inventory.md)<br>[`gui-and-management-api.md`](gui-and-management-api.md)<br>[`dashboard-and-usage.md`](dashboard-and-usage.md)<br>[`clients/integrations.md`](clients/integrations.md)<br>[`ops/service-and-sidecars.md`](ops/service-and-sidecars.md)<br>[`ops/docs-and-release.md`](ops/docs-and-release.md) |
| `src/link/` | [`remote-link.md`](remote-link.md) |
| `src/oauth/` | [`runtime.md`](runtime.md)<br>[`transports/inventory.md`](transports/inventory.md)<br>[`providers-and-adapters.md`](providers-and-adapters.md)<br>[`providers/xai-grok.md`](providers/xai-grok.md) |
| `src/plugins/` | [`ops/plugins.md`](ops/plugins.md) |
Expand Down
1 change: 1 addition & 0 deletions structure/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@
"title": "Background Service And Sidecars",
"scope": "Service install/repair, platform launchers, tray, and sidecar processes.",
"documents": [
"src/lib/",
"src/server/",
"src/service-manager-probe.ts",
"src/sidecar/",
Expand Down
9 changes: 6 additions & 3 deletions structure/ops/service-and-sidecars.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ The service loads the optional `compactionRouting` block from persisted configur
[Responses ingress](../transports/responses-failover.md#compaction-routing-overrides) applies it to individual compaction
requests whose trigger the block names.

Standalone binaries use `src/lib/standalone.ts` to detect the Bun `$bunfs` runtime and
`src/service/state.ts` to compose durable service commands as `<execPath> start`, without a
source-tree CLI path. The copied `gui/dist` directory is located by `src/server/gui-static.ts`;
Standalone binaries use `src/lib/standalone.ts` to recognize hostless `file:` module URLs
whose decoded pathname begins at Bun's `$bunfs` or Windows `~BUN` virtual root. The helper
decodes one URL layer, so encoded Windows tildes work while network-host and nested source
paths do not impersonate a bundled module. `src/service/state.ts` composes durable service
commands as `<execPath> start`, without a source-tree CLI path. The copied `gui/dist`
directory is located by `src/server/gui-static.ts`;
`OPENCODEX_GUI_DIST` remains an explicit override.

## Bun updater ownership transaction
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/standalone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ test("compiled module URL markers are recognized on POSIX and Windows", () => {
expect(isStandaloneModuleUrl("file:///Users/x/src/lib/standalone.ts")).toBe(false);
});

test("encoded Windows Bun virtual roots are recognized once", () => {
expect(isStandaloneModuleUrl("file:///B:/%7EBUN/root/ocx.exe")).toBe(true);
expect(isStandaloneModuleUrl("file:///B:/%7eBUN/root/ocx.exe")).toBe(true);
expect(isStandaloneModuleUrl("file:///B:/%257EBUN/root/ocx.exe")).toBe(false);
});

test("network hosts and nested Bun markers remain source URLs", () => {
expect(isStandaloneModuleUrl("file://server/$bunfs/root/index.ts")).toBe(false);
expect(isStandaloneModuleUrl("file:///Users/x/$bunfs/root/index.ts")).toBe(false);
expect(isStandaloneModuleUrl("https://example.test/$bunfs/root/index.ts")).toBe(false);
expect(isStandaloneModuleUrl("file:///B:/%XXBUN/root/index.ts")).toBe(false);
});

test("standaloneRoot follows the running executable", () => {
expect(standaloneRoot()).toBe(dirname(realpathSync(process.execPath)));
});
Loading