@sixb/desktop 0.1.0 → 0.2.1
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 +27 -3
- package/dist/generate.d.ts +17 -2
- package/dist/generate.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -60
- package/dist/index.js.map +6 -6
- package/dist/shell/bridge.d.ts +33 -0
- package/dist/shell/bridge.d.ts.map +1 -0
- package/dist/shell/preload.d.ts +2 -0
- package/dist/shell/preload.d.ts.map +1 -0
- package/dist/shell/runner.d.ts +60 -0
- package/dist/shell/runner.d.ts.map +1 -0
- package/dist/shell/window.d.ts +14 -8
- package/dist/shell/window.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/generate.ts +42 -5
- package/src/index.ts +10 -2
- package/src/shell/bridge.ts +41 -0
- package/src/shell/main.ts +153 -12
- package/src/shell/preload.ts +47 -0
- package/src/shell/runner.ts +296 -0
- package/src/shell/window.ts +25 -39
package/README.md
CHANGED
|
@@ -24,17 +24,19 @@ origin. Both generate the same Electron app first:
|
|
|
24
24
|
▼
|
|
25
25
|
.sixb/desktop/app/ rewritten on every call (src/generate.ts)
|
|
26
26
|
main.js the main process, compiled from src/shell/main.ts
|
|
27
|
+
preload.js what the page can reach, compiled from src/shell/preload.ts
|
|
27
28
|
shell.json name, app URL, API origin
|
|
28
29
|
index.html the page shown while the app loads
|
|
29
|
-
|
|
30
|
+
icon.png
|
|
30
31
|
│
|
|
31
32
|
├─ openDesktopApp electron .sixb/desktop/app
|
|
32
33
|
└─ buildDesktopApp @electron/packager ─▶ .sixb/desktop/dist/
|
|
33
34
|
```
|
|
34
35
|
|
|
35
36
|
The window loads the app from where it is served; `app/` is not compiled into the binary. The
|
|
36
|
-
page runs sandboxed, with no Node and
|
|
37
|
-
|
|
37
|
+
page runs sandboxed, with no Node, and reaches the shell only through what `src/shell/bridge.ts`
|
|
38
|
+
exposes, which says how to add to it. The window stays on the app and API origins
|
|
39
|
+
(`src/shell/window.ts`): any other link opens in the user's browser.
|
|
38
40
|
|
|
39
41
|
### macOS builds
|
|
40
42
|
|
|
@@ -71,6 +73,28 @@ The session is an ordinary browser session, kept in the window's persistent cook
|
|
|
71
73
|
launches open straight into the app. `src/shell/navigation.ts` holds those two decisions as a pure
|
|
72
74
|
function; `src/shell/main.ts` wires them to the window.
|
|
73
75
|
|
|
76
|
+
### Running the agent on this computer
|
|
77
|
+
|
|
78
|
+
`writeDesktopApp` compiles the runner the CLI names into `.sixb/desktop/runner`, and packaging copies it
|
|
79
|
+
to `Resources/runner`, outside the archive, because a program has to be a file of its own to run.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
page ── useDesktop().computer ──▶ main.ts (isAppUrl, native dialogs) ──▶ src/shell/runner.ts
|
|
83
|
+
│ JSON lines, stdin/stdout
|
|
84
|
+
project API ◀── sessions, turns, device sign-in ── sixb-runner ◀──────────┘
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
- **The runner holds the sign-in**, where `sixb login` keeps its own, which the agent's sandbox denies.
|
|
88
|
+
The keychain wouldn't do: `security find-generic-password` answers from inside the sandbox. The main
|
|
89
|
+
process only opens the approval page, if `isApiPage` accepts it.
|
|
90
|
+
- **The window's sign-in is denied too.** It's a plain cookie in the app's data folder, so the shell names
|
|
91
|
+
that folder to the runner, whose sandboxes deny it.
|
|
92
|
+
- **It can't outlive the app.** It ends with its stdin, and `before-quit` lets a running turn record its
|
|
93
|
+
end, within a limit. While the app is open it restarts after a wait that grows.
|
|
94
|
+
- **The agent needs a runtime** for its own `sixb`. A `bun` script beside the runner stands in, last on
|
|
95
|
+
the PATH so that a person's own wins. The PATH comes from their login shell, as an app opened from the
|
|
96
|
+
Dock is given a bare one.
|
|
97
|
+
|
|
74
98
|
### Title bar
|
|
75
99
|
|
|
76
100
|
On macOS the window has no title bar: the app draws to the top edge and the window controls float
|
package/dist/generate.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface DesktopAppOptions {
|
|
|
5
5
|
readonly appUrl: string;
|
|
6
6
|
/** The project's API. Its sign-in pages are where the window is approved. */
|
|
7
7
|
readonly apiOrigin: string;
|
|
8
|
+
/**
|
|
9
|
+
* What the app compiles to run the agent on this computer: the CLI names its own, as this package
|
|
10
|
+
* doesn't depend on it. Without one, the app has no way to run the agent here: see `writeRunner`.
|
|
11
|
+
*/
|
|
12
|
+
readonly runnerEntry?: string;
|
|
8
13
|
}
|
|
9
14
|
/** The Electron app `writeDesktopApp` generated, and what it is called. */
|
|
10
15
|
export interface GeneratedApp {
|
|
@@ -14,13 +19,23 @@ export interface GeneratedApp {
|
|
|
14
19
|
/** The app's icon in `dir`, when it declares one. */
|
|
15
20
|
readonly icon: string | null;
|
|
16
21
|
}
|
|
17
|
-
/**
|
|
18
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Where a project's desktop app is generated (`app`), what runs the agent is compiled (`runner`, beside
|
|
24
|
+
* the app as everything in the app's directory ships inside its archive), and it's packaged (`dist`).
|
|
25
|
+
*/
|
|
26
|
+
export declare function desktopDir(projectRoot: string, part: "app" | "dist" | "runner"): string;
|
|
19
27
|
/**
|
|
20
28
|
* Writes the Electron app that opens `appUrl` into the project's `.sixb/desktop/app`. The directory
|
|
21
29
|
* is build-owned, like the rest of `.sixb`: it is cleared on every call.
|
|
22
30
|
*/
|
|
23
31
|
export declare function writeDesktopApp(options: DesktopAppOptions): Promise<GeneratedApp>;
|
|
32
|
+
/**
|
|
33
|
+
* Compiles what runs the agent into one program, so that the app needs nothing installed, and a `bun`
|
|
34
|
+
* beside it. The agent's own `sixb` runs on Bun or Node, which a person may have neither of, and the
|
|
35
|
+
* program can stand in for Bun: last on the PATH the shell gives it, after any they have. Returns its
|
|
36
|
+
* directory: null with no entry, and on Windows, which has no local sandbox to run the agent in.
|
|
37
|
+
*/
|
|
38
|
+
export declare function writeRunner(options: DesktopAppOptions): Promise<string | null>;
|
|
24
39
|
/** The page the window shows while the app loads, and when it cannot reach the app. */
|
|
25
40
|
export declare function renderShellPage(template: string, page: {
|
|
26
41
|
readonly name: string;
|
package/dist/generate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,iBAAiB;IAChC,gFAAgF;IAChF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,qGAAqG;IACrG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B;AAED,2EAA2E;AAC3E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,qDAAqD;IACrD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAKD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,CAEvF;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CA4CvF;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqBpF;AAED,uFAAuF;AACvF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC/E,MAAM,CAYR"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAA4C,MAAM,YAAY,CAAA;AAI7F,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEnD,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,KAAK,IAAI,IAAI,CAAA;CACd;AAED,MAAM,WAAW,YAAY;IAC3B,oFAAoF;IACpF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CACzB;AAMD,0EAA0E;AAC1E,wBAAsB,cAAc,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,CAAC,CA2BvF;AAED,qFAAqF;AACrF,wBAAsB,eAAe,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAoCvF"}
|
package/dist/index.js
CHANGED
|
@@ -139,62 +139,8 @@ function run([input, output]) {
|
|
|
139
139
|
}
|
|
140
140
|
`;
|
|
141
141
|
|
|
142
|
-
// src/shell/
|
|
143
|
-
var
|
|
144
|
-
var HIDDEN_TITLE_BAR_CSS = [
|
|
145
|
-
`#sixb-desktop-drag{position:fixed;top:0;left:0;right:0;height:${CONTROLS_HEIGHT_PX}px;`,
|
|
146
|
-
"z-index:2147483647;pointer-events:none;-webkit-app-region:drag}",
|
|
147
|
-
`${[
|
|
148
|
-
"a",
|
|
149
|
-
"button",
|
|
150
|
-
"input",
|
|
151
|
-
"select",
|
|
152
|
-
"textarea",
|
|
153
|
-
"summary",
|
|
154
|
-
"label",
|
|
155
|
-
"[role=button]",
|
|
156
|
-
"[role=link]",
|
|
157
|
-
"[role=tab]",
|
|
158
|
-
"[role=menuitem]",
|
|
159
|
-
"[role=switch]",
|
|
160
|
-
"[role=checkbox]",
|
|
161
|
-
"[role=combobox]",
|
|
162
|
-
"[contenteditable]",
|
|
163
|
-
"[tabindex]:not([tabindex='-1'])"
|
|
164
|
-
].join(",")}{-webkit-app-region:no-drag}`,
|
|
165
|
-
`[data-slot="sidebar-inner"]{padding-top:calc(${CONTROLS_HEIGHT_PX}px - 0.5rem)}`
|
|
166
|
-
].join("");
|
|
167
|
-
var HIDDEN_TITLE_BAR_PRELOAD = `(() => {
|
|
168
|
-
const mark = () => {
|
|
169
|
-
const root = document.documentElement
|
|
170
|
-
if (!root) return false
|
|
171
|
-
root.dataset.sixbDesktop = "inset"
|
|
172
|
-
root.style.setProperty("--sixb-desktop-controls-height", "${CONTROLS_HEIGHT_PX}px")
|
|
173
|
-
return true
|
|
174
|
-
}
|
|
175
|
-
if (!mark()) {
|
|
176
|
-
const observer = new MutationObserver(() => {
|
|
177
|
-
if (mark()) observer.disconnect()
|
|
178
|
-
})
|
|
179
|
-
observer.observe(document, { childList: true })
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const addHandle = () => {
|
|
183
|
-
if (!document.body || document.getElementById("sixb-desktop-drag")) return
|
|
184
|
-
const handle = document.createElement("div")
|
|
185
|
-
handle.id = "sixb-desktop-drag"
|
|
186
|
-
handle.setAttribute("aria-hidden", "true")
|
|
187
|
-
// First in the body, not last: the draggable area is built in document order, so a control
|
|
188
|
-
// is only cut out of it if it comes after the handle.
|
|
189
|
-
document.body.prepend(handle)
|
|
190
|
-
}
|
|
191
|
-
if (document.readyState === "loading") {
|
|
192
|
-
document.addEventListener("DOMContentLoaded", addHandle, { once: true })
|
|
193
|
-
} else {
|
|
194
|
-
addHandle()
|
|
195
|
-
}
|
|
196
|
-
})()
|
|
197
|
-
`;
|
|
142
|
+
// src/shell/runner.ts
|
|
143
|
+
var RUNNER_BINARY = "sixb-runner";
|
|
198
144
|
|
|
199
145
|
// src/generate.ts
|
|
200
146
|
var SHELL_SOURCE_DIR = fileURLToPath(new URL("../src/shell", import.meta.url));
|
|
@@ -226,20 +172,38 @@ async function writeDesktopApp(options) {
|
|
|
226
172
|
`),
|
|
227
173
|
writeFile(join(dir, "shell.json"), `${JSON.stringify(config, null, 2)}
|
|
228
174
|
`),
|
|
229
|
-
writeFile(join(dir, "preload.js"), HIDDEN_TITLE_BAR_PRELOAD),
|
|
230
175
|
writeFile(join(dir, "index.html"), renderShellPage(template, { ...config, icon: !!icon }))
|
|
231
176
|
]);
|
|
232
177
|
await run([
|
|
233
178
|
process.execPath,
|
|
234
179
|
"build",
|
|
235
180
|
join(SHELL_SOURCE_DIR, "main.ts"),
|
|
181
|
+
join(SHELL_SOURCE_DIR, "preload.ts"),
|
|
236
182
|
"--target=node",
|
|
237
183
|
"--format=cjs",
|
|
238
184
|
"--external=electron",
|
|
239
|
-
`--
|
|
185
|
+
`--outdir=${dir}`
|
|
240
186
|
], "Could not compile the desktop shell.");
|
|
241
187
|
return { dir, name: identity.name, version, icon };
|
|
242
188
|
}
|
|
189
|
+
async function writeRunner(options) {
|
|
190
|
+
const dir = desktopDir(options.projectRoot, "runner");
|
|
191
|
+
await rm(dir, { recursive: true, force: true });
|
|
192
|
+
if (!options.runnerEntry || process.platform === "win32")
|
|
193
|
+
return null;
|
|
194
|
+
await mkdir(dir, { recursive: true });
|
|
195
|
+
await run([
|
|
196
|
+
process.execPath,
|
|
197
|
+
"build",
|
|
198
|
+
"--compile",
|
|
199
|
+
options.runnerEntry,
|
|
200
|
+
`--outfile=${join(dir, RUNNER_BINARY)}`
|
|
201
|
+
], "Could not compile what runs the agent.");
|
|
202
|
+
await writeFile(join(dir, "bun"), `#!/bin/sh
|
|
203
|
+
BUN_BE_BUN=1 exec "$(dirname "$0")/${RUNNER_BINARY}" "$@"
|
|
204
|
+
`, { mode: 493 });
|
|
205
|
+
return dir;
|
|
206
|
+
}
|
|
243
207
|
function renderShellPage(template, page) {
|
|
244
208
|
const initial = Array.from(page.name.trim())[0]?.toUpperCase() ?? "";
|
|
245
209
|
const markup = {
|
|
@@ -279,6 +243,9 @@ var packageRequire = createRequire(import.meta.url);
|
|
|
279
243
|
var PACKAGER_SCRIPT = fileURLToPath2(new URL("../src/packager.mjs", import.meta.url));
|
|
280
244
|
async function openDesktopApp(options) {
|
|
281
245
|
const app = await writeDesktopApp(options);
|
|
246
|
+
await writeRunner(options).catch((error) => {
|
|
247
|
+
console.error("[SixbDesktop] Conversations will run in the cloud.", error);
|
|
248
|
+
});
|
|
282
249
|
const log = join2(dirname(app.dir), "electron.log");
|
|
283
250
|
const electron = Bun.spawn([electronBinary(), app.dir], {
|
|
284
251
|
stdio: ["ignore", "ignore", Bun.file(log)]
|
|
@@ -300,6 +267,7 @@ async function openDesktopApp(options) {
|
|
|
300
267
|
}
|
|
301
268
|
async function buildDesktopApp(options) {
|
|
302
269
|
const app = await writeDesktopApp(options);
|
|
270
|
+
const runner = await writeRunner(options);
|
|
303
271
|
const out = desktopDir(options.projectRoot, "dist");
|
|
304
272
|
await rm2(out, { recursive: true, force: true });
|
|
305
273
|
const mac = process.platform === "darwin";
|
|
@@ -312,6 +280,7 @@ async function buildDesktopApp(options) {
|
|
|
312
280
|
appVersion: app.version,
|
|
313
281
|
electronVersion: packageRequire("electron/package.json").version,
|
|
314
282
|
...mac && app.icon ? { icon: await macIcon(app.icon) } : {},
|
|
283
|
+
...runner ? { extraResource: [runner] } : {},
|
|
315
284
|
...notarize ? { osxSign: {}, osxNotarize: notarize } : {}
|
|
316
285
|
});
|
|
317
286
|
if (!mac)
|
|
@@ -372,7 +341,7 @@ function electronBinary() {
|
|
|
372
341
|
return packageRequire("electron");
|
|
373
342
|
} catch {
|
|
374
343
|
const electronDir = dirname(packageRequire.resolve("electron/package.json"));
|
|
375
|
-
throw new Error("[SixbDesktop] Electron's binary is missing: its install script did not run. " + `Run \`bun
|
|
344
|
+
throw new Error("[SixbDesktop] Electron's binary is missing: its install script did not run. " + `Run \`bun ${join2(electronDir, "install.js")}\`, then try again.`);
|
|
376
345
|
}
|
|
377
346
|
}
|
|
378
347
|
export {
|
|
@@ -380,4 +349,4 @@ export {
|
|
|
380
349
|
openDesktopApp
|
|
381
350
|
};
|
|
382
351
|
|
|
383
|
-
//# debugId=
|
|
352
|
+
//# debugId=D20C8A734FA0DFE264756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.ts", "../src/generate.ts", "../src/identity.ts", "../src/run.ts", "../src/mac-icon.ts", "../src/shell/
|
|
3
|
+
"sources": ["../src/index.ts", "../src/generate.ts", "../src/identity.ts", "../src/run.ts", "../src/mac-icon.ts", "../src/shell/runner.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { mkdir, readdir, rm } from \"node:fs/promises\"\nimport { createRequire } from \"node:module\"\nimport { dirname, join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { type DesktopAppOptions, desktopDir, writeDesktopApp } from \"./generate\"\nimport { bundleIdentifier } from \"./identity\"\nimport { run } from \"./run\"\n\nexport type { DesktopAppOptions } from \"./generate\"\n\nexport interface DesktopWindow {\n /** Resolves with Electron's exit code once the user quits it. */\n readonly exited: Promise<number>\n close(): void\n}\n\nexport interface DesktopBuild {\n /** What to hand to users: a zip of the app on macOS, the app's folder elsewhere. */\n readonly path: string\n /** Whether it was signed and notarized, and so opens without a warning. */\n readonly signed: boolean\n}\n\nconst packageRequire = createRequire(import.meta.url)\n// From the package's `src`, like the shell: see `SHELL_SOURCE_DIR`.\nconst PACKAGER_SCRIPT = fileURLToPath(new URL(\"../src/packager.mjs\", import.meta.url))\n\n/** Opens the app in a desktop window. `sixb dev --desktop` calls this. */\nexport async function openDesktopApp(options: DesktopAppOptions): Promise<DesktopWindow> {\n const app = await writeDesktopApp(options)\n // Chromium writes plenty to stderr when all is well, so it goes to a file, named if the window\n // quits on its own with an error.\n const log = join(dirname(app.dir), \"electron.log\")\n const electron = Bun.spawn([electronBinary(), app.dir], {\n stdio: [\"ignore\", \"ignore\", Bun.file(log)],\n })\n let closing = false\n const exited = electron.exited.then((code) => {\n if (code !== 0 && !closing) {\n console.error(`[SixbDesktop] The desktop window quit with exit code ${code}. See ${log}.`)\n }\n return code\n })\n return {\n exited,\n close: () => {\n closing = true\n electron.kill()\n },\n }\n}\n\n/** Packages the app for this machine's platform. `sixb desktop build` calls this. */\nexport async function buildDesktopApp(options: DesktopAppOptions): Promise<DesktopBuild> {\n const app = await writeDesktopApp(options)\n const out = desktopDir(options.projectRoot, \"dist\")\n await rm(out, { recursive: true, force: true })\n\n const mac = process.platform === \"darwin\"\n const notarize = mac ? appleNotarization() : null\n const packaged = await packageApp({\n dir: app.dir,\n name: app.name,\n out,\n appBundleId: bundleIdentifier(options.appUrl),\n appVersion: app.version,\n electronVersion: (packageRequire(\"electron/package.json\") as { readonly version: string })\n .version,\n ...(mac && app.icon ? { icon: await macIcon(app.icon) } : {}),\n // Signs with the Developer ID certificate in the keychain, which notarization requires.\n ...(notarize ? { osxSign: {}, osxNotarize: notarize } : {}),\n })\n if (!mac) return { path: packaged, signed: false }\n\n const name = (await readdir(packaged)).find((entry) => entry.endsWith(\".app\"))\n if (!name) throw new Error(`[SixbDesktop] The packaged app is missing from ${packaged}.`)\n const bundle = join(packaged, name)\n // Packaging breaks the ad-hoc signature Electron ships with. macOS calls a downloaded app with a\n // broken signature damaged, and offers no way to open it; signed ad hoc, it can be allowed.\n if (!notarize) {\n await run([\"codesign\", \"--force\", \"--deep\", \"--sign\", \"-\", bundle], \"Could not sign the app.\")\n }\n // `ditto`, not `zip`: it keeps the bundle's symlinks, and with them its signature.\n const zip = `${packaged}.zip`\n await run([\"ditto\", \"-c\", \"-k\", \"--keepParent\", bundle, zip], \"Could not zip the app.\")\n return { path: zip, signed: notarize !== null }\n}\n\n/**\n * An App Store Connect API key, which notarizes the app so macOS opens it without a warning.\n * Without one, the app is built unsigned.\n */\nfunction appleNotarization(): {\n readonly appleApiKey: string\n readonly appleApiKeyId: string\n readonly appleApiIssuer: string\n} | null {\n const { APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER } = process.env\n if (!APPLE_API_KEY && !APPLE_API_KEY_ID && !APPLE_API_ISSUER) return null\n if (!APPLE_API_KEY || !APPLE_API_KEY_ID || !APPLE_API_ISSUER) {\n throw new Error(\n \"[SixbDesktop] Set all of APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER to sign the \" +\n \"macOS app, or none of them to build it unsigned.\"\n )\n }\n return {\n appleApiKey: APPLE_API_KEY,\n appleApiKeyId: APPLE_API_KEY_ID,\n appleApiIssuer: APPLE_API_ISSUER,\n }\n}\n\n/**\n * The packager wants `.icns`: every size macOS shows, scaled from the 1024-pixel icon, in one file.\n * `sips` and `iconutil` ship with every Mac. Written beside the app, not in it: everything in the\n * app's directory ships inside the bundle.\n */\nasync function macIcon(png: string): Promise<string> {\n const desktop = dirname(dirname(png))\n const iconset = join(desktop, \"icon.iconset\")\n await rm(iconset, { recursive: true, force: true })\n await mkdir(iconset)\n const sizes = [16, 32, 128, 256, 512].flatMap((points) => [\n { name: `icon_${points}x${points}.png`, pixels: points },\n { name: `icon_${points}x${points}@2x.png`, pixels: points * 2 },\n ])\n await Promise.all(\n sizes.map(({ name, pixels }) =>\n run(\n [\"sips\", \"-z\", `${pixels}`, `${pixels}`, png, \"--out\", join(iconset, name)],\n \"Could not scale the icon.\"\n )\n )\n )\n const icns = join(desktop, \"icon.icns\")\n await run([\"iconutil\", \"-c\", \"icns\", iconset, \"-o\", icns], \"Could not convert the icon.\")\n return icns\n}\n\n/**\n * Runs `@electron/packager` into `options.out`, which starts empty, and resolves with the one\n * directory it wrote there. Under Electron's own binary, which doubles as the Node the packager was\n * written for: under Bun, the packager fails whenever it verifies a download (its checksum\n * dependency does not load).\n */\nasync function packageApp(\n options: { readonly out: string } & Record<string, unknown>\n): Promise<string> {\n const packager = Bun.spawn(\n [electronBinary(), PACKAGER_SCRIPT, JSON.stringify({ ...options, quiet: true })],\n {\n stdio: [\"ignore\", \"inherit\", \"inherit\"],\n // Without the second, Electron's file system reads the `app.asar` the packager writes as a\n // directory.\n env: { ...process.env, ELECTRON_RUN_AS_NODE: \"1\", ELECTRON_NO_ASAR: \"1\" },\n }\n )\n if ((await packager.exited) !== 0) {\n throw new Error(\"[SixbDesktop] Packaging failed. See the output above.\")\n }\n const [written] = await readdir(options.out)\n if (!written) throw new Error(`[SixbDesktop] The packager wrote nothing to ${options.out}.`)\n return join(options.out, written)\n}\n\n// Outside Electron, `require(\"electron\")` is the path of the binary its install script fetched.\nfunction electronBinary(): string {\n try {\n return packageRequire(\"electron\") as string\n } catch {\n const electronDir = dirname(packageRequire.resolve(\"electron/package.json\"))\n throw new Error(\n \"[SixbDesktop] Electron's binary is missing: its install script did not run. \" +\n `Run \\`bun
|
|
6
|
-
"import { mkdir, readFile, rm, writeFile } from \"node:fs/promises\"\nimport { join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { readAppIdentity } from \"./identity\"\nimport { drawMacIcon } from \"./mac-icon\"\nimport { run } from \"./run\"\nimport type { ShellConfig } from \"./shell/navigation\"\nimport {
|
|
5
|
+
"import { mkdir, readdir, rm } from \"node:fs/promises\"\nimport { createRequire } from \"node:module\"\nimport { dirname, join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { type DesktopAppOptions, desktopDir, writeDesktopApp, writeRunner } from \"./generate\"\nimport { bundleIdentifier } from \"./identity\"\nimport { run } from \"./run\"\n\nexport type { DesktopAppOptions } from \"./generate\"\n\nexport interface DesktopWindow {\n /** Resolves with Electron's exit code once the user quits it. */\n readonly exited: Promise<number>\n close(): void\n}\n\nexport interface DesktopBuild {\n /** What to hand to users: a zip of the app on macOS, the app's folder elsewhere. */\n readonly path: string\n /** Whether it was signed and notarized, and so opens without a warning. */\n readonly signed: boolean\n}\n\nconst packageRequire = createRequire(import.meta.url)\n// From the package's `src`, like the shell: see `SHELL_SOURCE_DIR`.\nconst PACKAGER_SCRIPT = fileURLToPath(new URL(\"../src/packager.mjs\", import.meta.url))\n\n/** Opens the app in a desktop window. `sixb dev --desktop` calls this. */\nexport async function openDesktopApp(options: DesktopAppOptions): Promise<DesktopWindow> {\n const app = await writeDesktopApp(options)\n // The window is still worth opening without it, for a project not using the agent: conversations\n // run in the cloud. A build, which people get, fails instead.\n await writeRunner(options).catch((error: unknown) => {\n console.error(\"[SixbDesktop] Conversations will run in the cloud.\", error)\n })\n // Chromium writes plenty to stderr when all is well, so it goes to a file, named if the window\n // quits on its own with an error.\n const log = join(dirname(app.dir), \"electron.log\")\n const electron = Bun.spawn([electronBinary(), app.dir], {\n stdio: [\"ignore\", \"ignore\", Bun.file(log)],\n })\n let closing = false\n const exited = electron.exited.then((code) => {\n if (code !== 0 && !closing) {\n console.error(`[SixbDesktop] The desktop window quit with exit code ${code}. See ${log}.`)\n }\n return code\n })\n return {\n exited,\n close: () => {\n closing = true\n electron.kill()\n },\n }\n}\n\n/** Packages the app for this machine's platform. `sixb desktop build` calls this. */\nexport async function buildDesktopApp(options: DesktopAppOptions): Promise<DesktopBuild> {\n const app = await writeDesktopApp(options)\n const runner = await writeRunner(options)\n const out = desktopDir(options.projectRoot, \"dist\")\n await rm(out, { recursive: true, force: true })\n\n const mac = process.platform === \"darwin\"\n const notarize = mac ? appleNotarization() : null\n const packaged = await packageApp({\n dir: app.dir,\n name: app.name,\n out,\n appBundleId: bundleIdentifier(options.appUrl),\n appVersion: app.version,\n electronVersion: (packageRequire(\"electron/package.json\") as { readonly version: string })\n .version,\n ...(mac && app.icon ? { icon: await macIcon(app.icon) } : {}),\n // Beside the app's archive, not in it: a program has to be a file of its own to run.\n ...(runner ? { extraResource: [runner] } : {}),\n // Signs with the Developer ID certificate in the keychain, which notarization requires.\n ...(notarize ? { osxSign: {}, osxNotarize: notarize } : {}),\n })\n if (!mac) return { path: packaged, signed: false }\n\n const name = (await readdir(packaged)).find((entry) => entry.endsWith(\".app\"))\n if (!name) throw new Error(`[SixbDesktop] The packaged app is missing from ${packaged}.`)\n const bundle = join(packaged, name)\n // Packaging breaks the ad-hoc signature Electron ships with. macOS calls a downloaded app with a\n // broken signature damaged, and offers no way to open it; signed ad hoc, it can be allowed.\n if (!notarize) {\n await run([\"codesign\", \"--force\", \"--deep\", \"--sign\", \"-\", bundle], \"Could not sign the app.\")\n }\n // `ditto`, not `zip`: it keeps the bundle's symlinks, and with them its signature.\n const zip = `${packaged}.zip`\n await run([\"ditto\", \"-c\", \"-k\", \"--keepParent\", bundle, zip], \"Could not zip the app.\")\n return { path: zip, signed: notarize !== null }\n}\n\n/**\n * An App Store Connect API key, which notarizes the app so macOS opens it without a warning.\n * Without one, the app is built unsigned.\n */\nfunction appleNotarization(): {\n readonly appleApiKey: string\n readonly appleApiKeyId: string\n readonly appleApiIssuer: string\n} | null {\n const { APPLE_API_KEY, APPLE_API_KEY_ID, APPLE_API_ISSUER } = process.env\n if (!APPLE_API_KEY && !APPLE_API_KEY_ID && !APPLE_API_ISSUER) return null\n if (!APPLE_API_KEY || !APPLE_API_KEY_ID || !APPLE_API_ISSUER) {\n throw new Error(\n \"[SixbDesktop] Set all of APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER to sign the \" +\n \"macOS app, or none of them to build it unsigned.\"\n )\n }\n return {\n appleApiKey: APPLE_API_KEY,\n appleApiKeyId: APPLE_API_KEY_ID,\n appleApiIssuer: APPLE_API_ISSUER,\n }\n}\n\n/**\n * The packager wants `.icns`: every size macOS shows, scaled from the 1024-pixel icon, in one file.\n * `sips` and `iconutil` ship with every Mac. Written beside the app, not in it: everything in the\n * app's directory ships inside the bundle.\n */\nasync function macIcon(png: string): Promise<string> {\n const desktop = dirname(dirname(png))\n const iconset = join(desktop, \"icon.iconset\")\n await rm(iconset, { recursive: true, force: true })\n await mkdir(iconset)\n const sizes = [16, 32, 128, 256, 512].flatMap((points) => [\n { name: `icon_${points}x${points}.png`, pixels: points },\n { name: `icon_${points}x${points}@2x.png`, pixels: points * 2 },\n ])\n await Promise.all(\n sizes.map(({ name, pixels }) =>\n run(\n [\"sips\", \"-z\", `${pixels}`, `${pixels}`, png, \"--out\", join(iconset, name)],\n \"Could not scale the icon.\"\n )\n )\n )\n const icns = join(desktop, \"icon.icns\")\n await run([\"iconutil\", \"-c\", \"icns\", iconset, \"-o\", icns], \"Could not convert the icon.\")\n return icns\n}\n\n/**\n * Runs `@electron/packager` into `options.out`, which starts empty, and resolves with the one\n * directory it wrote there. Under Electron's own binary, which doubles as the Node the packager was\n * written for: under Bun, the packager fails whenever it verifies a download (its checksum\n * dependency does not load).\n */\nasync function packageApp(\n options: { readonly out: string } & Record<string, unknown>\n): Promise<string> {\n const packager = Bun.spawn(\n [electronBinary(), PACKAGER_SCRIPT, JSON.stringify({ ...options, quiet: true })],\n {\n stdio: [\"ignore\", \"inherit\", \"inherit\"],\n // Without the second, Electron's file system reads the `app.asar` the packager writes as a\n // directory.\n env: { ...process.env, ELECTRON_RUN_AS_NODE: \"1\", ELECTRON_NO_ASAR: \"1\" },\n }\n )\n if ((await packager.exited) !== 0) {\n throw new Error(\"[SixbDesktop] Packaging failed. See the output above.\")\n }\n const [written] = await readdir(options.out)\n if (!written) throw new Error(`[SixbDesktop] The packager wrote nothing to ${options.out}.`)\n return join(options.out, written)\n}\n\n// Outside Electron, `require(\"electron\")` is the path of the binary its install script fetched.\nfunction electronBinary(): string {\n try {\n return packageRequire(\"electron\") as string\n } catch {\n const electronDir = dirname(packageRequire.resolve(\"electron/package.json\"))\n throw new Error(\n \"[SixbDesktop] Electron's binary is missing: its install script did not run. \" +\n `Run \\`bun ${join(electronDir, \"install.js\")}\\`, then try again.`\n )\n }\n}\n",
|
|
6
|
+
"import { mkdir, readFile, rm, writeFile } from \"node:fs/promises\"\nimport { join } from \"node:path\"\nimport { fileURLToPath } from \"node:url\"\nimport { readAppIdentity } from \"./identity\"\nimport { drawMacIcon } from \"./mac-icon\"\nimport { run } from \"./run\"\nimport type { ShellConfig } from \"./shell/navigation\"\nimport { RUNNER_BINARY } from \"./shell/runner\"\n\nexport interface DesktopAppOptions {\n /** The Sixb project. The desktop app is generated under its `.sixb/desktop`. */\n readonly projectRoot: string\n /** Where the app is served. The window opens it; the desktop app takes its name and icon from it. */\n readonly appUrl: string\n /** The project's API. Its sign-in pages are where the window is approved. */\n readonly apiOrigin: string\n /**\n * What the app compiles to run the agent on this computer: the CLI names its own, as this package\n * doesn't depend on it. Without one, the app has no way to run the agent here: see `writeRunner`.\n */\n readonly runnerEntry?: string\n}\n\n/** The Electron app `writeDesktopApp` generated, and what it is called. */\nexport interface GeneratedApp {\n readonly dir: string\n readonly name: string\n readonly version: string\n /** The app's icon in `dir`, when it declares one. */\n readonly icon: string | null\n}\n\n// Read from the package's `src`, which ships, whether this module runs from `src` or `dist`.\nconst SHELL_SOURCE_DIR = fileURLToPath(new URL(\"../src/shell\", import.meta.url))\n\n/**\n * Where a project's desktop app is generated (`app`), what runs the agent is compiled (`runner`, beside\n * the app as everything in the app's directory ships inside its archive), and it's packaged (`dist`).\n */\nexport function desktopDir(projectRoot: string, part: \"app\" | \"dist\" | \"runner\"): string {\n return join(projectRoot, \".sixb\", \"desktop\", part)\n}\n\n/**\n * Writes the Electron app that opens `appUrl` into the project's `.sixb/desktop/app`. The directory\n * is build-owned, like the rest of `.sixb`: it is cleared on every call.\n */\nexport async function writeDesktopApp(options: DesktopAppOptions): Promise<GeneratedApp> {\n const identity = await readAppIdentity(options.appUrl)\n const version = await readProjectVersion(options.projectRoot)\n const dir = desktopDir(options.projectRoot, \"app\")\n await rm(dir, { recursive: true, force: true })\n await mkdir(dir, { recursive: true })\n\n const config: ShellConfig = {\n name: identity.name,\n appUrl: new URL(options.appUrl).href,\n apiOrigin: new URL(options.apiOrigin).origin,\n }\n const manifest = {\n name: \"sixb-desktop-app\",\n // Names the folder the window's cookies are kept in, so each app has its own sign-in.\n productName: identity.name,\n version,\n private: true,\n main: \"main.js\",\n }\n const icon = identity.icon ? await writeIcon(dir, identity.icon) : null\n const template = await readFile(join(SHELL_SOURCE_DIR, \"index.html\"), \"utf-8\")\n await Promise.all([\n writeFile(join(dir, \"package.json\"), `${JSON.stringify(manifest, null, 2)}\\n`),\n writeFile(join(dir, \"shell.json\"), `${JSON.stringify(config, null, 2)}\\n`),\n writeFile(join(dir, \"index.html\"), renderShellPage(template, { ...config, icon: !!icon })),\n ])\n\n // Electron loads plain JavaScript. A child process, because an in-process `Bun.build()` that\n // wedges takes its caller down with it.\n await run(\n [\n process.execPath,\n \"build\",\n join(SHELL_SOURCE_DIR, \"main.ts\"),\n join(SHELL_SOURCE_DIR, \"preload.ts\"),\n \"--target=node\",\n \"--format=cjs\",\n \"--external=electron\",\n `--outdir=${dir}`,\n ],\n \"Could not compile the desktop shell.\"\n )\n return { dir, name: identity.name, version, icon }\n}\n\n/**\n * Compiles what runs the agent into one program, so that the app needs nothing installed, and a `bun`\n * beside it. The agent's own `sixb` runs on Bun or Node, which a person may have neither of, and the\n * program can stand in for Bun: last on the PATH the shell gives it, after any they have. Returns its\n * directory: null with no entry, and on Windows, which has no local sandbox to run the agent in.\n */\nexport async function writeRunner(options: DesktopAppOptions): Promise<string | null> {\n const dir = desktopDir(options.projectRoot, \"runner\")\n await rm(dir, { recursive: true, force: true })\n if (!options.runnerEntry || process.platform === \"win32\") return null\n await mkdir(dir, { recursive: true })\n await run(\n [\n process.execPath,\n \"build\",\n \"--compile\",\n options.runnerEntry,\n `--outfile=${join(dir, RUNNER_BINARY)}`,\n ],\n \"Could not compile what runs the agent.\"\n )\n await writeFile(\n join(dir, \"bun\"),\n `#!/bin/sh\\nBUN_BE_BUN=1 exec \"$(dirname \"$0\")/${RUNNER_BINARY}\" \"$@\"\\n`,\n { mode: 0o755 }\n )\n return dir\n}\n\n/** The page the window shows while the app loads, and when it cannot reach the app. */\nexport function renderShellPage(\n template: string,\n page: { readonly name: string; readonly appUrl: string; readonly icon: boolean }\n): string {\n const initial = Array.from(page.name.trim())[0]?.toUpperCase() ?? \"\"\n const markup: Record<string, string> = {\n name: escapeHtml(page.name),\n host: escapeHtml(new URL(page.appUrl).host),\n appUrl: escapeHtml(page.appUrl),\n // The app's icon, or the first letter of its name standing in for one.\n mark: page.icon\n ? '<img class=\"mark\" src=\"icon.png\" alt=\"\" />'\n : `<div class=\"mark\" aria-hidden=\"true\">${escapeHtml(initial)}</div>`,\n }\n return template.replaceAll(/\\{\\{(\\w+)\\}\\}/g, (_match, key: string) => markup[key] ?? \"\")\n}\n\n/** Writes the app's icon into `dir` as `icon.png`; on macOS, drawn the way macOS draws app icons. */\nasync function writeIcon(dir: string, png: Uint8Array): Promise<string> {\n const icon = join(dir, \"icon.png\")\n if (process.platform !== \"darwin\") {\n await writeFile(icon, png)\n return icon\n }\n // The original goes beside the app, not in it: everything in the app's directory ships.\n const source = join(dir, \"..\", \"icon-source.png\")\n await writeFile(source, png)\n await drawMacIcon(source, icon)\n return icon\n}\n\nasync function readProjectVersion(projectRoot: string): Promise<string> {\n try {\n const manifest: unknown = JSON.parse(await readFile(join(projectRoot, \"package.json\"), \"utf-8\"))\n const version = (manifest as { readonly version?: unknown } | null)?.version\n return typeof version === \"string\" ? version : \"0.0.0\"\n } catch {\n return \"0.0.0\"\n }\n}\n\nfunction escapeHtml(value: string): string {\n return value\n .replaceAll(\"&\", \"&\")\n .replaceAll(\"<\", \"<\")\n .replaceAll(\">\", \">\")\n .replaceAll('\"', \""\")\n}\n",
|
|
7
7
|
"/** What the desktop app takes from the web app it opens. */\nexport interface AppIdentity {\n /** The app's name: `metadata.title` in `app/layout.tsx`. */\n readonly name: string\n /**\n * The app's maskable icon, such as `app/public/icon-maskable-512.png`, or else its largest PNG\n * icon, such as `app/public/icon-512.png`.\n */\n readonly icon: Uint8Array | null\n}\n\n/**\n * Reads the app's web app manifest, the one a browser installs the app from. The desktop app is\n * the same app installed another way, so it takes the same name and icon and has no settings of\n * its own.\n */\nexport async function readAppIdentity(appUrl: string): Promise<AppIdentity> {\n const manifestUrl = new URL(\"/app.webmanifest\", appUrl)\n const manifest: unknown = await (await fetchFromApp(manifestUrl)).json()\n const { name, icons } = (typeof manifest === \"object\" && manifest !== null ? manifest : {}) as {\n readonly name?: unknown\n readonly icons?: unknown\n }\n\n const iconUrl = desktopIcon(icons, manifestUrl)\n return {\n name: typeof name === \"string\" && name.trim() ? name.trim() : \"Sixb\",\n icon: iconUrl ? new Uint8Array(await (await fetchFromApp(iconUrl)).arrayBuffer()) : null,\n }\n}\n\n/**\n * The app's id on the desktop, from the address it opens: `https://orders.acme.com` becomes\n * `com.acme.orders`. Each deployment gets its own, so a staging build installs beside production.\n */\nexport function bundleIdentifier(appUrl: string): string {\n const labels = new URL(appUrl).hostname\n .split(\".\")\n .reverse()\n .map((label) => label.toLowerCase().replaceAll(/[^a-z0-9-]/g, \"-\"))\n .filter(Boolean)\n return (labels.length > 1 ? labels : [\"local\", ...labels]).join(\".\")\n}\n\n// A maskable icon is drawn to its edges for a platform to cut its own shape from, which is what\n// macOS does with it. Any other icon may carry its own shape and margins.\nfunction desktopIcon(icons: unknown, manifestUrl: URL): URL | null {\n let best: { readonly url: URL; readonly rank: readonly [number, number] } | null = null\n for (const icon of Array.isArray(icons) ? icons : []) {\n if (typeof icon !== \"object\" || icon === null) continue\n const { src, sizes, type, purpose } = icon as Record<string, unknown>\n if (typeof src !== \"string\") continue\n const url = new URL(src, manifestUrl)\n if (type === undefined ? !url.pathname.endsWith(\".png\") : type !== \"image/png\") continue\n\n const maskable = typeof purpose === \"string\" && purpose.split(/\\s+/).includes(\"maskable\")\n const size = Math.max(\n 0,\n ...(typeof sizes === \"string\" ? sizes.split(/\\s+/) : []).map(\n (entry) => Number.parseInt(entry, 10) || 0\n )\n )\n const rank = [maskable ? 1 : 0, size] as const\n if (!best || rank[0] > best.rank[0] || (rank[0] === best.rank[0] && rank[1] > best.rank[1])) {\n best = { url, rank }\n }\n }\n return best?.url ?? null\n}\n\nasync function fetchFromApp(url: URL): Promise<Response> {\n let response: Response\n try {\n response = await fetch(url)\n } catch (error) {\n throw new Error(\n `[SixbDesktop] Could not reach ${url} (${error instanceof Error ? error.message : error}). ` +\n \"The desktop app takes its name and icon from the app, so the app must be running there.\"\n )\n }\n if (!response.ok) throw new Error(`[SixbDesktop] ${url} answered ${response.status}.`)\n return response\n}\n",
|
|
8
8
|
"/** Runs a command to completion, quietly unless it fails: then it throws `failure` and its errors. */\nexport async function run(command: readonly string[], failure: string): Promise<void> {\n const child = Bun.spawn([...command], {\n stdio: [\"ignore\", \"ignore\", \"pipe\"],\n timeout: 120_000,\n })\n const [exitCode, errors] = await Promise.all([child.exited, new Response(child.stderr).text()])\n if (exitCode !== 0) {\n throw new Error(`[SixbDesktop] ${failure}${errors.trim() ? `\\n${errors.trim()}` : \"\"}`)\n }\n}\n",
|
|
9
9
|
"import { run } from \"./run\"\n\n/**\n * Draws `png` the way macOS draws app icons, into `out`: on Apple's grid, a rounded square of 824\n * pixels with continuous corners in a canvas of 1024, over the soft shadow Apple's own icons have.\n * An icon drawn to its edges otherwise stands larger than every other icon in the Dock.\n */\nexport async function drawMacIcon(png: string, out: string): Promise<void> {\n await run(\n [\"osascript\", \"-l\", \"JavaScript\", \"-e\", MAC_ICON_SCRIPT, png, out],\n \"Could not draw the macOS icon.\"\n )\n}\n\n// AppKit, through the JavaScript `osascript` runs, which every Mac has. The corner is the curve\n// UIKit rounds continuous corners with; with this radius it matches the outline of Apple's Notes\n// icon to a few pixels, and the shadow matches its shadow.\nconst MAC_ICON_SCRIPT = `\nObjC.import(\"AppKit\")\nObjC.import(\"CoreGraphics\")\n\nfunction run([input, output]) {\n const canvas = 1024\n const body = 824\n const radius = 185.4\n const min = (canvas - body) / 2\n const max = min + body\n\n // One corner, as offsets in radii from the edge it leaves and the edge it joins.\n const corner = [\n [[1.52866483, 0]],\n [[0.66993427, 0.065496], [1.08849323, 0], [0.86840689, 0.02065986]],\n [[0.63149399, 0.074911]],\n [[0.074911, 0.63149399], [0.37282392, 0.16906933], [0.16906933, 0.37282392]],\n [[0.065496, 0.66993427]],\n [[0, 1.52866483], [0.02065986, 0.86840689], [0, 1.08849323]],\n ]\n const corners = [\n ([u, v]) => $.NSMakePoint(max - u * radius, max - v * radius),\n ([u, v]) => $.NSMakePoint(max - v * radius, min + u * radius),\n ([u, v]) => $.NSMakePoint(min + u * radius, min + v * radius),\n ([u, v]) => $.NSMakePoint(min + v * radius, max - u * radius),\n ]\n const shape = $.NSBezierPath.bezierPath\n shape.moveToPoint(corners[3]([0, 1.52866483]))\n for (const at of corners) {\n for (const [to, c1, c2] of corner) {\n if (c1) shape.curveToPointControlPoint1ControlPoint2(at(to), at(c1), at(c2))\n else shape.lineToPoint(at(to))\n }\n }\n shape.closePath\n\n const image = $.NSImage.alloc.initWithContentsOfFile(input)\n if (image.isNil()) throw new Error(\"Cannot read \" + input)\n const bitmap = $.NSBitmapImageRep.alloc\n .initWithBitmapDataPlanesPixelsWidePixelsHighBitsPerSampleSamplesPerPixelHasAlphaIsPlanarColorSpaceNameBytesPerRowBitsPerPixel(\n null, canvas, canvas, 8, 4, true, false, $.NSDeviceRGBColorSpace, 0, 0\n )\n const context = $.NSGraphicsContext.graphicsContextWithBitmapImageRep(bitmap)\n $.NSGraphicsContext.setCurrentContext(context)\n context.setImageInterpolation($.NSImageInterpolationHigh)\n\n const shadow = $.NSShadow.alloc.init\n shadow.setShadowOffset($.NSMakeSize(0, -8))\n shadow.setShadowBlurRadius(30)\n shadow.setShadowColor($.NSColor.colorWithWhiteAlpha(0, 0.22))\n shadow.set\n // A layer, so the shadow falls from the clipped icon and not from the clip.\n $.CGContextBeginTransparencyLayer(context.CGContext, null)\n shape.addClip\n image.drawInRectFromRectOperationFraction(\n $.NSMakeRect(min, min, body, body), $.NSZeroRect, $.NSCompositingOperationSourceOver, 1\n )\n $.CGContextEndTransparencyLayer(context.CGContext)\n context.flushGraphics\n\n const png = bitmap.representationUsingTypeProperties($.NSBitmapImageFileTypePNG, $.NSDictionary.dictionary)\n if (!png.writeToFileAtomically(output, true)) throw new Error(\"Cannot write \" + output)\n}\n`\n",
|
|
10
|
-
"import type { ShellConfig } from \"./navigation\"\n\n/**\n * Whether the window itself may show `url`: only the app and the API that serves its sign-in\n * pages. Anything else a page links to opens in the user's browser instead.\n */\nexport function mayNavigate(config: ShellConfig, url: string): boolean {\n try {\n const { origin } = new URL(url)\n return origin === new URL(config.appUrl).origin || origin === new URL(config.apiOrigin).origin\n } catch {\n return false\n }\n}\n\n/**\n * Whether `url` is on the app's own origin. Camera, location and the like are the app's to ask for,\n * and not a frame it embeds from elsewhere.\n */\nexport function isAppUrl(config: ShellConfig, url: string): boolean {\n try {\n return new URL(url).origin === new URL(config.appUrl).origin\n } catch {\n return false\n }\n}\n\n/**\n * What the window paints before a page has: the loading page's own background, so the window\n * opens, and passes from that page to the app, without a flash of white.\n */\nexport const WINDOW_BACKGROUND = { light: \"#fafafa\", dark: \"#0a0a0a\" } as const\n\n/** The band at the top of a window without a title bar where macOS draws the window controls. */\nexport const CONTROLS_HEIGHT_PX = 36\n\n/**\n * Styles for a window without a title bar, inserted into every page it shows.\n *\n * The page reaches the top edge, under the window controls, so two things a title bar did have\n * to come from the page: somewhere to grab the window, and room for the controls.\n * - `#sixb-desktop-drag` (added by the preload) is the drag handle: a strip across the top, above\n * the page. It ignores the pointer, and every control is cut out of the draggable area, so\n * buttons and links under the strip still take their clicks and the space between them moves\n * the window. Something clickable that is none of the things listed here needs\n * `-webkit-app-region: no-drag` of its own.\n * - The shared sidebar is moved down so most apps need nothing. Other layouts can use\n * `html[data-sixb-desktop]` and `--sixb-desktop-controls-height`, which the preload sets.\n */\nexport const HIDDEN_TITLE_BAR_CSS = [\n `#sixb-desktop-drag{position:fixed;top:0;left:0;right:0;height:${CONTROLS_HEIGHT_PX}px;`,\n \"z-index:2147483647;pointer-events:none;-webkit-app-region:drag}\",\n `${[\n \"a\",\n \"button\",\n \"input\",\n \"select\",\n \"textarea\",\n \"summary\",\n \"label\",\n \"[role=button]\",\n \"[role=link]\",\n \"[role=tab]\",\n \"[role=menuitem]\",\n \"[role=switch]\",\n \"[role=checkbox]\",\n \"[role=combobox]\",\n \"[contenteditable]\",\n \"[tabindex]:not([tabindex='-1'])\",\n ].join(\",\")}{-webkit-app-region:no-drag}`,\n `[data-slot=\"sidebar-inner\"]{padding-top:calc(${CONTROLS_HEIGHT_PX}px - 0.5rem)}`,\n].join(\"\")\n\n/**\n * The preload of a window without a title bar: runs in every page before the page's own scripts.\n *\n * It marks `<html>` the moment the element exists, so an app can read the mark on its first\n * render, and adds the drag handle once there is a body to hold it. Written to a file by\n * `writeDesktopApp`, which is why it is source text and not a function.\n */\nexport const HIDDEN_TITLE_BAR_PRELOAD = `(() => {\n const mark = () => {\n const root = document.documentElement\n if (!root) return false\n root.dataset.sixbDesktop = \"inset\"\n root.style.setProperty(\"--sixb-desktop-controls-height\", \"${CONTROLS_HEIGHT_PX}px\")\n return true\n }\n if (!mark()) {\n const observer = new MutationObserver(() => {\n if (mark()) observer.disconnect()\n })\n observer.observe(document, { childList: true })\n }\n\n const addHandle = () => {\n if (!document.body || document.getElementById(\"sixb-desktop-drag\")) return\n const handle = document.createElement(\"div\")\n handle.id = \"sixb-desktop-drag\"\n handle.setAttribute(\"aria-hidden\", \"true\")\n // First in the body, not last: the draggable area is built in document order, so a control\n // is only cut out of it if it comes after the handle.\n document.body.prepend(handle)\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", addHandle, { once: true })\n } else {\n addHandle()\n }\n})()\n`\n"
|
|
10
|
+
"import { spawn } from \"node:child_process\"\nimport { delimiter } from \"node:path\"\n\n/** The program `writeDesktopApp` compiles, in the runner's directory. */\nexport const RUNNER_BINARY = \"sixb-runner\"\n\n/** How long a person's shell gets to say what their PATH is. */\nconst LOGIN_SHELL_WAIT_MS = 3_000\n/** How long a page waits to hear which folders are allowed, before asking for one instead. */\nconst FOLDERS_WAIT_MS = 10_000\n/** How long the runner gets to end a running turn and close its sessions. */\nconst STOP_WAIT_MS = 12_000\nconst RESTART_WAIT_MS = { first: 2_000, longest: 60_000 } as const\n/** Running this long, the runner wasn't what failed quickly: the next restart waits the least again. */\nconst STEADY_MS = 60_000\n/** Exit status of a runner whose sign-in ended. */\nconst EXIT_SIGNED_OUT = 3\n\nexport interface RunnerProcess {\n /** One line of JSON from the runner. */\n onLine(listener: (line: string) => void): void\n readonly exited: Promise<number>\n write(line: string): void\n /** Close its stdin, which it ends with. */\n end(): void\n kill(): void\n}\n\nexport interface DesktopComputer {\n readonly id: string\n readonly name: string\n}\n\ntype RunnerCommand = {\n readonly type: \"allow\" | \"forget\"\n readonly folder: string\n}\n\n/**\n * The main process's hold on the program that runs the agent on this computer: it starts it, keeps it\n * started while the app is open, and stops it on quit. It holds no sign-in: the program does, and\n * only says where to send the person to approve one.\n */\nexport class DesktopRunner {\n private process: RunnerProcess | null = null\n private computer: DesktopComputer | null = null\n private folderList: readonly string[] = []\n private waitingForComputer: {\n readonly resolve: (computer: DesktopComputer) => void\n readonly reject: (error: Error) => void\n }[] = []\n private foldersKnown = false\n private waitingForFolders: ((folders: readonly string[]) => void)[] = []\n private unsent: RunnerCommand[] = []\n private restart: ReturnType<typeof setTimeout> | null = null\n private restartWait: number = RESTART_WAIT_MS.first\n private stopping = false\n\n constructor(\n private readonly options: {\n readonly start: () => RunnerProcess\n /** A page in the system browser to approve this computer's sign-in on. */\n readonly onSignIn: (url: string) => void\n readonly onProblem: (message: string) => void\n }\n ) {}\n\n start(): void {\n if (this.stopping) return\n const started = Date.now()\n const process = this.options.start()\n this.process = process\n process.onLine((line) => this.hear(line))\n for (const command of this.unsent.splice(0)) process.write(JSON.stringify(command))\n void process.exited.then((code) => {\n this.process = null\n if (this.stopping) return\n if (Date.now() - started >= STEADY_MS) this.restartWait = RESTART_WAIT_MS.first\n // A sign-in that ended is no problem to report: started again, it waits for a new one.\n if (code !== EXIT_SIGNED_OUT) {\n this.options.onProblem(`What runs the agent quit with exit code ${code}.`)\n }\n // Told it failed, not that there's nothing to run on: a message mustn't go elsewhere on a guess.\n for (const { reject } of this.waitingForComputer.splice(0)) {\n reject(new Error(\"[SixbDesktop] What runs the agent on this computer couldn't start.\"))\n }\n this.answerFolders()\n this.restart = setTimeout(() => this.start(), this.restartWait)\n this.restartWait = Math.min(this.restartWait * 2, RESTART_WAIT_MS.longest)\n })\n }\n\n /** This computer, once the runner has said. Rejects if it quits before it does. */\n about(): Promise<DesktopComputer> {\n if (this.computer) return Promise.resolve(this.computer)\n return new Promise((resolve, reject) => this.waitingForComputer.push({ resolve, reject }))\n }\n\n /** The folders allowed, once the runner knows: a page asking early mustn't take them for none. */\n folders(): Promise<readonly string[]> {\n if (this.foldersKnown) return Promise.resolve(this.folderList)\n return new Promise((resolve) => {\n // A runner that can't read its config keeps trying, and a message mustn't wait on that for good.\n const timer = setTimeout(() => this.answerFolders(), FOLDERS_WAIT_MS)\n this.waitingForFolders.push((folders) => {\n clearTimeout(timer)\n resolve(folders)\n })\n })\n }\n\n allow(folder: string): void {\n this.send({ type: \"allow\", folder })\n // A page asking right after choosing finds it there, before the runner has said so.\n if (!this.folderList.includes(folder)) this.folderList = [...this.folderList, folder]\n }\n\n forget(folder: string): void {\n this.send({ type: \"forget\", folder })\n this.folderList = this.folderList.filter((known) => known !== folder)\n }\n\n /** Let it end a running turn and close its sessions, within a limit. */\n async stop(): Promise<void> {\n this.stopping = true\n if (this.restart) clearTimeout(this.restart)\n const process = this.process\n if (!process) return\n process.end()\n let timer: ReturnType<typeof setTimeout> | undefined\n const late = new Promise<\"late\">((resolve) => {\n timer = setTimeout(() => resolve(\"late\"), STOP_WAIT_MS)\n })\n if ((await Promise.race([process.exited, late])) === \"late\") process.kill()\n clearTimeout(timer)\n }\n\n private send(command: RunnerCommand): void {\n if (this.process) this.process.write(JSON.stringify(command))\n else this.unsent.push(command)\n }\n\n private answerFolders(): void {\n this.foldersKnown = true\n for (const answer of this.waitingForFolders.splice(0)) answer(this.folderList)\n }\n\n private hear(line: string): void {\n let event: Record<string, unknown>\n try {\n event = JSON.parse(line)\n } catch {\n return\n }\n switch (event.type) {\n case \"computer\":\n if (typeof event.id === \"string\" && typeof event.name === \"string\") {\n const computer = { id: event.id, name: event.name }\n this.computer = computer\n for (const { resolve } of this.waitingForComputer.splice(0)) resolve(computer)\n }\n return\n case \"folders\":\n if (Array.isArray(event.folders)) this.folderList = event.folders.map(String)\n this.answerFolders()\n return\n // Nothing runs in the list on file until it's signed in: none, so the next message asks, and\n // answering signs in. It would otherwise wait on a sign-in nobody was asked for.\n case \"signed-out\":\n case \"signed-out-waiting\":\n this.folderList = []\n this.answerFolders()\n return\n // It can't say which until the project answers: the last it said, for now.\n case \"unreachable\":\n this.answerFolders()\n return\n case \"sign-in\":\n if (typeof event.url === \"string\") this.options.onSignIn(event.url)\n return\n case \"sign-in-failed\":\n this.folderList = []\n if (typeof event.message === \"string\") this.options.onProblem(event.message)\n return\n case \"session.lost\":\n case \"error\":\n if (typeof event.message === \"string\") this.options.onProblem(event.message)\n }\n }\n}\n\n/** The runner as a child process of this one, its stderr for the app's own log. */\nexport function startRunnerProcess(\n command: readonly [string, ...string[]],\n env: NodeJS.ProcessEnv\n): RunnerProcess {\n const [file, ...args] = command\n const child = spawn(file, args, { env, stdio: [\"pipe\", \"pipe\", \"inherit\"] })\n // A runner that's gone by the time this writes: its restart is what answers that.\n child.stdin.on(\"error\", () => {})\n const exited = new Promise<number>((resolve) => {\n child.once(\"error\", () => resolve(-1))\n child.once(\"exit\", (code) => resolve(code ?? -1))\n })\n return {\n onLine(listener) {\n let rest = \"\"\n child.stdout.setEncoding(\"utf8\").on(\"data\", (chunk: string) => {\n rest += chunk\n const lines = rest.split(\"\\n\")\n rest = lines.pop() ?? \"\"\n for (const line of lines) listener(line)\n })\n },\n exited,\n write: (line) => void child.stdin.write(`${line}\\n`),\n end: () => void child.stdin.end(),\n kill: () => void child.kill(\"SIGKILL\"),\n }\n}\n\n/**\n * The environment the runner, and the agent's commands, run in. An app opened from the Dock gets a\n * bare PATH, so the person's shell says what theirs is: the agent uses the tools they do. The `bun`\n * beside the runner comes last, for someone with neither Bun nor Node.\n */\nexport async function runnerEnvironment(\n runnerDir: string,\n base: NodeJS.ProcessEnv\n): Promise<NodeJS.ProcessEnv> {\n const shell = await readLoginShell(base.SHELL).catch(() => null)\n const env = Object.fromEntries(\n // What a terminal `sixb dev` was told about its own project is no business of this one.\n Object.entries(base).filter(([name]) => !name.startsWith(\"SIXB_\"))\n )\n return {\n ...env,\n PATH: [shell?.path ?? base.PATH ?? \"\", runnerDir].join(delimiter),\n // Where `sixb` keeps its sign-in, and so what the agent's commands are kept from.\n ...(shell?.configHome ? { XDG_CONFIG_HOME: shell.configHome } : {}),\n }\n}\n\n/**\n * Between markers, as a shell's startup files may print whatever they like.\n *\n * In a session of its own, with no terminal: an interactive shell takes over the one it inherits. Under\n * `sixb dev --desktop` that's the person's, and whatever reads a key or a mouse move there meanwhile is\n * stopped by it, for good, leaving the terminal as it was.\n *\n * A limit of its own, and a kill that can't be ignored: an interactive shell ignores `execFile`'s, and\n * what it started can hold the pipe open long after it's gone. A startup file that waits on a person\n * mustn't stop the agent.\n */\nfunction readLoginShell(\n shell: string | undefined\n): Promise<{ readonly path: string; readonly configHome: string } | null> {\n if (!shell) return Promise.resolve(null)\n return new Promise((resolve) => {\n // `spawn`, not `execFile`, which ignores `detached`.\n const child = spawn(\n shell,\n [\"-ilc\", 'printf \"__SIXB_SHELL__%s\\\\n%s__SIXB_SHELL__\" \"$PATH\" \"$XDG_CONFIG_HOME\"'],\n { detached: true, stdio: [\"ignore\", \"pipe\", \"ignore\"] }\n )\n let printed = \"\"\n const said = () => {\n const [path, configHome] =\n /__SIXB_SHELL__(.*)__SIXB_SHELL__/s.exec(printed)?.[1]?.split(\"\\n\") ?? []\n return path ? { path, configHome: configHome ?? \"\" } : null\n }\n const timer = setTimeout(() => {\n // The whole group: it's alone in it, with whatever its startup files began.\n if (child.pid) {\n try {\n process.kill(-child.pid, \"SIGKILL\")\n } catch {\n // Gone already.\n }\n }\n // What it said counts, whatever it left holding the pipe.\n resolve(said())\n }, LOGIN_SHELL_WAIT_MS)\n child.stdout.on(\"data\", (chunk) => {\n printed += String(chunk)\n })\n child.once(\"error\", () => {\n clearTimeout(timer)\n resolve(null)\n })\n child.once(\"close\", () => {\n clearTimeout(timer)\n resolve(said())\n })\n })\n}\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": ";;AAAA,kBAAS,uBAAgB;AACzB;AACA,0BAAkB;AAClB,0BAAS;;;ACHT;AACA;AACA;;;
|
|
13
|
-
"debugId": "
|
|
12
|
+
"mappings": ";;AAAA,kBAAS,uBAAgB;AACzB;AACA,0BAAkB;AAClB,0BAAS;;;ACHT;AACA;AACA;;;ACcO,eAAe,eAAe,CAAC,QAAsC;AAAA,EAC1E,MAAM,cAAc,IAAI,IAAI,oBAAoB,MAAM;AAAA,EACtD,MAAM,WAAoB,OAAO,MAAM,aAAa,WAAW,GAAG,KAAK;AAAA,EACvE,QAAQ,MAAM,UAAW,OAAO,aAAa,YAAY,aAAa,OAAO,WAAW,CAAC;AAAA,EAKzF,MAAM,UAAU,YAAY,OAAO,WAAW;AAAA,EAC9C,OAAO;AAAA,IACL,MAAM,OAAO,SAAS,YAAY,KAAK,KAAK,IAAI,KAAK,KA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K,aAAa,YAAY,sBAC/C;AAAA;AAAA;",
|
|
13
|
+
"debugId": "D20C8A734FA0DFE264756E2164756E21",
|
|
14
14
|
"names": []
|
|
15
15
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** The name a page finds the desktop app under, through `useDesktop` in `@sixb/client/hooks`. */
|
|
2
|
+
export declare const DESKTOP_BRIDGE_NAME = "sixbDesktop";
|
|
3
|
+
/** How the page's `computer` methods reach the main process. */
|
|
4
|
+
export declare const COMPUTER_CHANNELS: {
|
|
5
|
+
readonly about: "sixb:computer:about";
|
|
6
|
+
readonly folders: "sixb:computer:folders";
|
|
7
|
+
readonly pickFolder: "sixb:computer:pick-folder";
|
|
8
|
+
readonly allowFolder: "sixb:computer:allow-folder";
|
|
9
|
+
readonly forgetFolder: "sixb:computer:forget-folder";
|
|
10
|
+
};
|
|
11
|
+
type Invoke = (channel: string, ...args: unknown[]) => Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* What the shell offers the page. `SixbDesktop` in `@sixb/client` is the page's view of this, and
|
|
14
|
+
* `tests/app.test.ts` holds the two together.
|
|
15
|
+
*
|
|
16
|
+
* The page is remote, and anything here is open to whatever runs in it. To offer more:
|
|
17
|
+
* 1. Add one narrow method here, calling `ipcRenderer.invoke`, never a general way to run a command
|
|
18
|
+
* or read a file. The page asks; the person decides, in a native dialog, what it gets.
|
|
19
|
+
* 2. Handle it in `main.ts`, refusing any sender that `isAppUrl` does not accept.
|
|
20
|
+
* 3. Add it to `SixbDesktop` as optional, because a page can outlive the shell it runs in.
|
|
21
|
+
*/
|
|
22
|
+
export declare function desktopBridge<const Platform extends NodeJS.Platform>(platform: Platform, invoke: Invoke): {
|
|
23
|
+
platform: Platform;
|
|
24
|
+
computer: {
|
|
25
|
+
about: () => Promise<any>;
|
|
26
|
+
folders: () => Promise<any>;
|
|
27
|
+
pickFolder: () => Promise<any>;
|
|
28
|
+
allowFolder: (folder: string) => Promise<any>;
|
|
29
|
+
forgetFolder: (folder: string) => Promise<any>;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/shell/bridge.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,eAAO,MAAM,mBAAmB,gBAAgB,CAAA;AAEhD,gEAAgE;AAChE,eAAO,MAAM,iBAAiB;;;;;;CAMpB,CAAA;AAIV,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,CAAC,QAAQ,SAAS,MAAM,CAAC,QAAQ,EAClE,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM;;;;;;8BAQY,MAAM;+BACL,MAAM;;EAGlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preload.d.ts","sourceRoot":"","sources":["../../src/shell/preload.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The program `writeDesktopApp` compiles, in the runner's directory. */
|
|
2
|
+
export declare const RUNNER_BINARY = "sixb-runner";
|
|
3
|
+
export interface RunnerProcess {
|
|
4
|
+
/** One line of JSON from the runner. */
|
|
5
|
+
onLine(listener: (line: string) => void): void;
|
|
6
|
+
readonly exited: Promise<number>;
|
|
7
|
+
write(line: string): void;
|
|
8
|
+
/** Close its stdin, which it ends with. */
|
|
9
|
+
end(): void;
|
|
10
|
+
kill(): void;
|
|
11
|
+
}
|
|
12
|
+
export interface DesktopComputer {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The main process's hold on the program that runs the agent on this computer: it starts it, keeps it
|
|
18
|
+
* started while the app is open, and stops it on quit. It holds no sign-in: the program does, and
|
|
19
|
+
* only says where to send the person to approve one.
|
|
20
|
+
*/
|
|
21
|
+
export declare class DesktopRunner {
|
|
22
|
+
private readonly options;
|
|
23
|
+
private process;
|
|
24
|
+
private computer;
|
|
25
|
+
private folderList;
|
|
26
|
+
private waitingForComputer;
|
|
27
|
+
private foldersKnown;
|
|
28
|
+
private waitingForFolders;
|
|
29
|
+
private unsent;
|
|
30
|
+
private restart;
|
|
31
|
+
private restartWait;
|
|
32
|
+
private stopping;
|
|
33
|
+
constructor(options: {
|
|
34
|
+
readonly start: () => RunnerProcess;
|
|
35
|
+
/** A page in the system browser to approve this computer's sign-in on. */
|
|
36
|
+
readonly onSignIn: (url: string) => void;
|
|
37
|
+
readonly onProblem: (message: string) => void;
|
|
38
|
+
});
|
|
39
|
+
start(): void;
|
|
40
|
+
/** This computer, once the runner has said. Rejects if it quits before it does. */
|
|
41
|
+
about(): Promise<DesktopComputer>;
|
|
42
|
+
/** The folders allowed, once the runner knows: a page asking early mustn't take them for none. */
|
|
43
|
+
folders(): Promise<readonly string[]>;
|
|
44
|
+
allow(folder: string): void;
|
|
45
|
+
forget(folder: string): void;
|
|
46
|
+
/** Let it end a running turn and close its sessions, within a limit. */
|
|
47
|
+
stop(): Promise<void>;
|
|
48
|
+
private send;
|
|
49
|
+
private answerFolders;
|
|
50
|
+
private hear;
|
|
51
|
+
}
|
|
52
|
+
/** The runner as a child process of this one, its stderr for the app's own log. */
|
|
53
|
+
export declare function startRunnerProcess(command: readonly [string, ...string[]], env: NodeJS.ProcessEnv): RunnerProcess;
|
|
54
|
+
/**
|
|
55
|
+
* The environment the runner, and the agent's commands, run in. An app opened from the Dock gets a
|
|
56
|
+
* bare PATH, so the person's shell says what theirs is: the agent uses the tools they do. The `bun`
|
|
57
|
+
* beside the runner comes last, for someone with neither Bun nor Node.
|
|
58
|
+
*/
|
|
59
|
+
export declare function runnerEnvironment(runnerDir: string, base: NodeJS.ProcessEnv):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C,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;KAC9C;IAGH,KAAK,IAAI,IAAI;IAyBb,mFAAmF;IACnF,KAAK,IAAI,OAAO,CAAC,eAAe,CAAC;IAKjC,kGAAkG;IAClG,OAAO,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAYrC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAM3B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK5B,wEAAwE;IAClE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAc3B,OAAO,CAAC,IAAI;IAKZ,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,IAAI;CA0Cb;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EACvC,GAAG,EAAE,MAAM,CAAC,UAAU,GACrB,aAAa,CAwBf;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,CAAC,UAAU,GACtB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAY5B"}
|
package/dist/shell/window.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export declare function mayNavigate(config: ShellConfig, url: string): boolean;
|
|
|
9
9
|
* and not a frame it embeds from elsewhere.
|
|
10
10
|
*/
|
|
11
11
|
export declare function isAppUrl(config: ShellConfig, url: string): boolean;
|
|
12
|
+
/** Whether `url` is a web page of the project's API, the only place a sign-in is approved. */
|
|
13
|
+
export declare function isApiPage(config: ShellConfig, url: string): boolean;
|
|
12
14
|
/**
|
|
13
15
|
* What the window paints before a page has: the loading page's own background, so the window
|
|
14
16
|
* opens, and passes from that page to the app, without a flash of white.
|
|
@@ -17,6 +19,18 @@ export declare const WINDOW_BACKGROUND: {
|
|
|
17
19
|
readonly light: "#fafafa";
|
|
18
20
|
readonly dark: "#0a0a0a";
|
|
19
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* What the window's page runs with. The page is remote: it gets no Node and a world apart from the
|
|
24
|
+
* preload's, on every platform, and reaches the shell only through what the preload exposes.
|
|
25
|
+
*/
|
|
26
|
+
export declare function pageWebPreferences(preload: string): {
|
|
27
|
+
sandbox: boolean;
|
|
28
|
+
contextIsolation: boolean;
|
|
29
|
+
nodeIntegration: boolean;
|
|
30
|
+
preload: string;
|
|
31
|
+
};
|
|
32
|
+
/** Only macOS draws window controls over the page; elsewhere the title bar stays. */
|
|
33
|
+
export declare function hasHiddenTitleBar(platform: NodeJS.Platform): boolean;
|
|
20
34
|
/** The band at the top of a window without a title bar where macOS draws the window controls. */
|
|
21
35
|
export declare const CONTROLS_HEIGHT_PX = 36;
|
|
22
36
|
/**
|
|
@@ -33,12 +47,4 @@ export declare const CONTROLS_HEIGHT_PX = 36;
|
|
|
33
47
|
* `html[data-sixb-desktop]` and `--sixb-desktop-controls-height`, which the preload sets.
|
|
34
48
|
*/
|
|
35
49
|
export declare const HIDDEN_TITLE_BAR_CSS: string;
|
|
36
|
-
/**
|
|
37
|
-
* The preload of a window without a title bar: runs in every page before the page's own scripts.
|
|
38
|
-
*
|
|
39
|
-
* It marks `<html>` the moment the element exists, so an app can read the mark on its first
|
|
40
|
-
* render, and adds the drag handle once there is a body to hold it. Written to a file by
|
|
41
|
-
* `writeDesktopApp`, which is why it is source text and not a function.
|
|
42
|
-
*/
|
|
43
|
-
export declare const HIDDEN_TITLE_BAR_PRELOAD = "(() => {\n const mark = () => {\n const root = document.documentElement\n if (!root) return false\n root.dataset.sixbDesktop = \"inset\"\n root.style.setProperty(\"--sixb-desktop-controls-height\", \"36px\")\n return true\n }\n if (!mark()) {\n const observer = new MutationObserver(() => {\n if (mark()) observer.disconnect()\n })\n observer.observe(document, { childList: true })\n }\n\n const addHandle = () => {\n if (!document.body || document.getElementById(\"sixb-desktop-drag\")) return\n const handle = document.createElement(\"div\")\n handle.id = \"sixb-desktop-drag\"\n handle.setAttribute(\"aria-hidden\", \"true\")\n // First in the body, not last: the draggable area is built in document order, so a control\n // is only cut out of it if it comes after the handle.\n document.body.prepend(handle)\n }\n if (document.readyState === \"loading\") {\n document.addEventListener(\"DOMContentLoaded\", addHandle, { once: true })\n } else {\n addHandle()\n }\n})()\n";
|
|
44
50
|
//# sourceMappingURL=window.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/shell/window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAOrE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAMlE;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB;;;CAAiD,CAAA;AAE/E,iGAAiG;AACjG,eAAO,MAAM,kBAAkB,KAAK,CAAA;AAEpC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,oBAAoB,QAsBvB,CAAA
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/shell/window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C;;;GAGG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAOrE;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAMlE;AAED,8FAA8F;AAC9F,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CASnE;AAED;;;GAGG;AACH,eAAO,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