@ekravo/cli 0.0.0-stage → 0.1.113

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/UpdateCLI.md ADDED
@@ -0,0 +1,147 @@
1
+ # Updating and releasing the Ekravo CLI
2
+
3
+ Read this file before updating or publishing the CLI. Verify current source, tags,
4
+ and release state rather than assuming the versions or paths from an old chat.
5
+ Native release archives also include this guide at `share/ekravo/UpdateCLI.md`.
6
+
7
+ ## Find the correct repository
8
+
9
+ The CLI repository is `https://github.com/EOSKILLZ/ACHECLI`, with default branch
10
+ `master`. Confirm with `git remote -v` and `gh repo view`. The website and the
11
+ desktop app are separate repositories. A CLI directory inside a workspace can be
12
+ a snapshot; do not publish it as the CLI repository.
13
+
14
+ Read `AGENTS.md` and applicable release/testing guidance. Use Corepack with the
15
+ `packageManager` version in `package.json`; this repository uses pnpm, not npm.
16
+ Never include unrelated working-tree changes or publish credentials.
17
+
18
+ ## Prepare a release
19
+
20
+ 1. Fetch `origin` and tags. Inspect `gh release list --repo EOSKILLZ/ACHECLI` and
21
+ the current package version. Pick a new, unused stable version.
22
+ 2. Add regression tests for behavior changes. Update the package version with
23
+ `node scripts/set-version.js v<VERSION>`. Review the complete diff.
24
+ 3. Run `pnpm run verify`: lint, typecheck, native binary build, unit tests, and
25
+ smoke tests. Run the shared-fixture terminal tests for visible CLI changes.
26
+ Resolve failures; do not disable checks. On Windows, use LF source files so
27
+ checkout CRLF conversion does not produce Biome formatting failures.
28
+ 4. Push the feature branch, open a PR, and merge the reviewed change into
29
+ `master`. Do not tag an unrelated commit or overwrite a published tag.
30
+ 5. Tag the exact merged commit `v<VERSION>` and push the tag. The workflow
31
+ `.github/workflows/release.yml` validates, builds five platforms, packages,
32
+ smoke-tests, and publishes a stable GitHub release. Wait for completion;
33
+ a pushed tag alone is not a completed release.
34
+
35
+ ## When GitHub Actions is unavailable
36
+
37
+ GitHub Actions previously failed with `startup_failure` when account minutes
38
+ were exhausted. Inspect the run before assuming code is broken. Do not keep
39
+ retrying an unchanged billing failure.
40
+
41
+ Use the repository build/package scripts on available build hosts. Each build
42
+ replaces `dist`, so package or stage it before building the next target:
43
+
44
+ ```text
45
+ node scripts/build-binary.js --target <TARGET>
46
+ node scripts/package-release-asset.js --os <OS> --arch <ARCH> --outDir <STAGING>
47
+ ```
48
+
49
+ | TARGET | OS | ARCH | Required archive |
50
+ | --- | --- | --- | --- |
51
+ | windows-x64 | windows | amd64 | ekravo_windows_amd64.zip |
52
+ | linux-x64 | linux | amd64 | ekravo_linux_amd64.tar.gz |
53
+ | linux-arm64 | linux | arm64 | ekravo_linux_arm64.tar.gz |
54
+ | darwin-x64 | darwin | amd64 | ekravo_darwin_amd64.tar.gz |
55
+ | darwin-arm64 | darwin | arm64 | ekravo_darwin_arm64.tar.gz |
56
+
57
+ Use native platform build/validation where possible, especially macOS signing
58
+ and native clipboard dependencies. Cross-compiling is not proof of runtime
59
+ compatibility. Never relabel an old binary as a new version.
60
+
61
+ Cross-built Bun macOS executables can contain an invalid code-page digest after
62
+ the embedded payload is written. Repair their ad-hoc signatures before packaging
63
+ using native `codesign` or a verified portable signer, and verify the signed code
64
+ pages. Native macOS runtime testing remains separate from digest verification.
65
+
66
+ Create a **draft** release, upload all archives, `scripts/install.ps1`,
67
+ `scripts/install.sh`, and `checksums.txt`. The checksum file uses SHA-256 in
68
+ standard `HASH FILENAME` format for all five archives. Verify archive layout
69
+ (`bin/` and `share/ekravo/`), versions, bundled proxy-helper architecture, checksums,
70
+ and installer/update behavior before publishing the draft as the latest stable
71
+ release. Document any platform validation limitations in the release notes.
72
+ Do not expose a partial release to auto-updaters.
73
+
74
+ ## Verify users can download the release
75
+
76
+ The private GitHub repository is exposed to users through the website mirror:
77
+
78
+ - Metadata: `https://ekravo.com/cli-releases/api/repos/EOSKILLZ/ACHECLI/releases/latest`
79
+ - Assets: `https://ekravo.com/cli-releases/dl/EOSKILLZ/ACHECLI/releases/download/<TAG>/<ASSET>`
80
+ - Windows installer: `https://ekravo.com/cli/install.ps1`
81
+
82
+ After publication, verify the mirror returns the new tag and can download an
83
+ archive whose SHA-256 matches the release checksum. Allow for mirror caching.
84
+ Test installation/update in an isolated temporary installation and home, never
85
+ overwrite the developer's installed CLI just to validate a release. An ordinary
86
+ CLI release needs no website deployment if the mirror and installer work.
87
+
88
+ ## How existing users update
89
+
90
+ Run `ekravo update` (or `ekravo update --force` for an explicitly requested
91
+ noninteractive update), then `ekravo --version`. Inside Ekravo, `/update` exposes
92
+ the update action and auto-update toggle.
93
+
94
+ Auto-update is **opt-in**, disabled by default. Enabled native installations
95
+ check at interactive startup. On Windows, the running executable is rotated
96
+ and the new version takes effect on the next launch; quit and reopen Ekravo.
97
+ Linux/macOS hand off to the new executable. Update checks can be cached for
98
+ 24 hours; explicit `ekravo update` skips the cache. Source runs, Homebrew installs,
99
+ protocol/print modes, `--no-auto-update`, and `EKRAVO_NO_UPDATE_CHECK` skip the
100
+ automatic update path. Never silently change a user's update preference.
101
+
102
+ Windows update validation must also account for install and temporary directories
103
+ on different drives. Older updaters can fail with `EXDEV` when moving an executable
104
+ from `%TEMP%` on C: into a custom installation on D:. Test the default installation
105
+ drive separately. If an existing client hits this error, reinstall with the
106
+ PowerShell installer below using the same `EKRAVO_INSTALL_DIR`; do not treat a
107
+ successful release upload as proof that this older updater can cross volumes.
108
+
109
+ Windows users can also reinstall the latest native build with:
110
+
111
+ ```powershell
112
+ irm https://ekravo.com/cli/install.ps1 | iex
113
+ ```
114
+
115
+ ## Reasoning regression to preserve
116
+
117
+ Managed Ekravo providers must send `include_reasoning: true` through
118
+ `src/extensions/ekravo-reasoning.ts`, registered in both the main CLI and bot
119
+ worker extension factories. The website API only exposes separate reasoning
120
+ when requested. The pinned SDK maps `reasoning` / `reasoning_content` deltas
121
+ to native thinking blocks. Keep the answer in text blocks; do not turn reasoning
122
+ into normal assistant text or force a model's reasoning effort/budget.
123
+
124
+ Relevant tests: `ekravo-reasoning.test.ts`, agent-runner tests, thinking-steps
125
+ renderer tests, and hide-thinking tests. Report push, merge, tag, assets,
126
+ publication, mirror verification, and remaining limitations accurately.
127
+
128
+ ## Image support regression to preserve
129
+
130
+ The website must advertise the stored model vision capability as `input_modalities`
131
+ in `/v1/models`, and the CLI must preserve it in its model registry. Do not infer
132
+ vision support from model names or mark every model as image-capable.
133
+
134
+ The clipboard extension uses the SDK image resizer. Ship `bin/photon_rs_bg.wasm`
135
+ with every platform archive and preserve it through native installers, package
136
+ postinstall, local installation, and self-update. Test image paste without the
137
+ build machine's original Photon WASM file so missing runtime resources are caught.
138
+ The shared-fixture terminal test is `clipboard-image-paste.test.ts`.
139
+
140
+ Also bundle Photon in shared resources: older updaters only copy that directory.
141
+ `src/auxiliary-files/image-runtime.ts` restores the omitted file beside the Ekravo
142
+ executable at startup. Verify a real upgrade from the previous stable release,
143
+ not just a fresh installation with the latest installer.
144
+
145
+ Windows image paste uses **Alt+V**; macOS/Linux use **Ctrl+V**. `/paste-image` is
146
+ the fallback when the terminal intercepts paste shortcuts. Image instructions are
147
+ in `docs/images.md` and bundled at `share/ekravo/images.md`.
package/bin/ekravo.js ADDED
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from "node:child_process"
3
+ import { existsSync } from "node:fs"
4
+ import { join, dirname } from "node:path"
5
+ import { fileURLToPath } from "node:url"
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
+ const isWin = process.platform === "win32"
9
+ const binName = isWin ? "ekravo.exe" : "ekravo"
10
+ const binPath = join(__dirname, "..", "dist", "bin", binName)
11
+
12
+ if (!existsSync(binPath)) {
13
+ console.error(`[ekravo] binary not found at ${binPath}`)
14
+ console.error(`[ekravo] run \`node scripts/postinstall.js\` or reinstall @ekravo/cli`)
15
+ process.exit(1)
16
+ }
17
+
18
+ const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit" })
19
+ process.exit(result.status ?? (result.error ? 1 : 0))
package/package.json CHANGED
@@ -1,6 +1,155 @@
1
1
  {
2
2
  "name": "@ekravo/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.113",
4
+ "description": "ekravo — a coding agent CLI powered by Cast AI, built on Ekravo",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "bin": {
8
+ "ekravo": "./bin/ekravo.js"
9
+ },
10
+ "files": [
11
+ "dist/",
12
+ "bin/",
13
+ "scripts/postinstall.js",
14
+ "scripts/patch-pi-ai-oauth.js",
15
+ "scripts/copy-resources.js",
16
+ "scripts/set-version.js",
17
+ "README.md",
18
+ "UpdateCLI.md",
19
+ "LICENSE"
20
+ ],
21
+ "scripts": {
22
+ "clean": "rm -rf dist",
23
+ "build": "tsc --noEmit && node scripts/copy-resources.js --dev",
24
+ "build:proxy-helper": "node scripts/build-proxy-helper.js",
25
+ "build:binary": "node scripts/build-binary.js",
26
+ "install:local": "node scripts/install-local.js",
27
+ "build:binary-linux-arm64": "node scripts/build-binary.js --target linux-arm64",
28
+ "build:binary-linux-x64": "node scripts/build-binary.js --target linux-x64",
29
+ "build:binary-windows-x64": "node scripts/build-binary.js --target windows-x64",
30
+ "dev": "make -C tools/proxy-helper/ copy-for-dev && bun run --preload ./src/set-package-dir.ts src/entry.ts",
31
+ "dev:overlay": "scripts/dev-overlay.sh",
32
+ "dev:setup": "bun run --preload ./src/set-package-dir.ts src/entry.ts setup",
33
+ "lint": "biome check src/ scripts/ tests/",
34
+ "lint:fix": "biome check --write src/ scripts/ tests/",
35
+ "typecheck": "tsc --noEmit",
36
+ "check": "pnpm run lint && pnpm run typecheck",
37
+ "test": "vitest run --dir src",
38
+ "test:smoke": "vitest run --config tests/smoke/vitest.config.ts",
39
+ "test:e2e:tui": "pnpm run build:binary && node scripts/run-tui-e2e.js",
40
+ "test:e2e:tui:debug": "pnpm run build:binary && node scripts/run-tui-e2e.js --debug",
41
+ "test:e2e:tui:trace": "pnpm run build:binary && node scripts/run-tui-e2e.js --trace",
42
+ "test:e2e:tui:trace:replay": "node scripts/run-tui-e2e.js replay",
43
+ "test:e2e:acp": "pnpm run build:binary && vitest run --config tests/e2e/acp/vitest.config.ts",
44
+ "postinstall": "node scripts/postinstall.js",
45
+ "prepare": "husky",
46
+ "verify": "pnpm run check && pnpm run build:binary && pnpm run test && pnpm run test:smoke"
47
+ },
48
+ "piConfig": {
49
+ "name": "ekravo",
50
+ "configDir": ".config/ekravo/harness"
51
+ },
52
+ "dependencies": {
53
+ "@agentclientprotocol/sdk": "0.19.2",
54
+ "@bulkhead-ai/core": "^0.7.0",
55
+ "@clack/prompts": "^1.3.0",
56
+ "@earendil-works/pi-coding-agent": "0.84.1",
57
+ "@earendil-works/pi-tui": "0.84.1",
58
+ "@modelcontextprotocol/ext-apps": "^1.7.1",
59
+ "@modelcontextprotocol/sdk": "^1.29.0",
60
+ "@shikijs/cli": "^4.0.2",
61
+ "@types/diff": "^8.0.0",
62
+ "@types/proper-lockfile": "^4.1.4",
63
+ "@types/ssh2": "^1.15.5",
64
+ "@xterm/headless": "^6.0.0",
65
+ "diff": "^9.0.0",
66
+ "micromatch": "^4.0.8",
67
+ "open": "^10.2.0",
68
+ "proper-lockfile": "^4.1.2",
69
+ "shell-quote": "1.8.4",
70
+ "shiki": "^4.0.2",
71
+ "ssh2": "^1.17.0",
72
+ "tar": "^7.5.22",
73
+ "undici": "^8.10.0",
74
+ "uuid": "^14.0.0",
75
+ "wcwidth": "^1.0.1",
76
+ "yaml": "^2.8.4",
77
+ "zod": "^4.4.3"
78
+ },
79
+ "peerDependencies": {
80
+ "typebox": "*"
81
+ },
82
+ "optionalDependencies": {
83
+ "@mariozechner/clipboard-darwin-arm64": "0.3.6",
84
+ "@mariozechner/clipboard-darwin-universal": "0.3.6",
85
+ "@mariozechner/clipboard-darwin-x64": "0.3.6",
86
+ "@mariozechner/clipboard-linux-arm64-gnu": "0.3.6",
87
+ "@mariozechner/clipboard-linux-arm64-musl": "0.3.6",
88
+ "@mariozechner/clipboard-linux-x64-gnu": "0.3.6",
89
+ "@mariozechner/clipboard-linux-x64-musl": "0.3.6",
90
+ "@mariozechner/clipboard-win32-arm64-msvc": "0.3.6",
91
+ "@mariozechner/clipboard-win32-x64-msvc": "0.3.6"
92
+ },
93
+ "devDependencies": {
94
+ "@biomejs/biome": "^2.5.3",
95
+ "@earendil-works/pi-ai": "0.84.1",
96
+ "@microsoft/tui-test": "0.0.4",
97
+ "@mixmark-io/domino": "^2.2.0",
98
+ "@types/micromatch": "^4.0.10",
99
+ "@types/node": "^22.19.18",
100
+ "@types/shell-quote": "^1.7.5",
101
+ "@types/tar": "^7.0.87",
102
+ "@types/turndown": "^5.0.6",
103
+ "@types/ws": "^8.18.1",
104
+ "husky": "^9.1.7",
105
+ "node-pty": "^1.1.0",
106
+ "playwright": "1.59.1",
107
+ "supports-color": "^10.2.2",
108
+ "tsx": "^4.21.0",
109
+ "turndown": "^7.2.4",
110
+ "typescript": "^5.9.3",
111
+ "vitest": "^3.2.4",
112
+ "ws": "^8.21.3"
113
+ },
114
+ "engines": {
115
+ "node": ">=22.19.0"
116
+ },
117
+ "packageManager": "pnpm@10.8.1",
118
+ "pnpm": {
119
+ "overrides": {
120
+ "cross-spawn": "7.1.2"
121
+ },
122
+ "onlyBuiltDependencies": [
123
+ "@biomejs/biome",
124
+ "esbuild",
125
+ "koffi",
126
+ "node-pty",
127
+ "protobufjs"
128
+ ],
129
+ "ignoredOptionalDependencies": [
130
+ "cpu-features",
131
+ "nan"
132
+ ],
133
+ "patchedDependencies": {
134
+ "playwright-core@1.59.1": "patches/playwright-core@1.59.1.patch",
135
+ "@earendil-works/pi-ai@0.84.1": "patches/@earendil-works__pi-ai@0.84.1.patch",
136
+ "@earendil-works/pi-tui@0.84.1": "patches/@earendil-works__pi-tui@0.84.1.patch",
137
+ "@earendil-works/pi-coding-agent@0.84.1": "patches/@earendil-works__pi-coding-agent@0.84.1.patch"
138
+ },
139
+ "supportedArchitectures": {
140
+ "os": [
141
+ "current",
142
+ "linux"
143
+ ],
144
+ "cpu": [
145
+ "current",
146
+ "x64"
147
+ ],
148
+ "libc": [
149
+ "current",
150
+ "glibc",
151
+ "musl"
152
+ ]
153
+ }
154
+ }
155
+ }
@@ -0,0 +1,183 @@
1
+ // Copy non-TypeScript resources that tsc doesn't handle.
2
+ //
3
+ // --dev (used by `build`): theme files from node_modules → src/modes/interactive/theme/
4
+ // export-html templates → src/core/export-html/
5
+ // so `bun run src/cli.ts` resolves assets via pi-mono's getters
6
+ // (getThemesDir, getExportTemplateDir) relative to ekravo's project root
7
+ //
8
+ // default (used by `build-binary`): theme files from node_modules → dist/share/ekravo/theme/
9
+ // export-html templates → dist/share/ekravo/export-html/
10
+ // plus package.json → dist/share/ekravo/
11
+ // so the compiled binary resolves assets from the shared data directory
12
+ //
13
+ // --test (used by vitest's globalSetup): the default layout, minus the artifacts other
14
+ // build steps produce (tools/proxy-helper/bin/*), and it
15
+ // no-ops when dist/share/ekravo is already newer than the
16
+ // sources. Tests read dist/share/ekravo directly, so a
17
+ // fresh checkout must regenerate it before the suite runs.
18
+
19
+ import {
20
+ cpSync,
21
+ existsSync,
22
+ mkdirSync,
23
+ readdirSync,
24
+ readFileSync,
25
+ realpathSync,
26
+ statSync,
27
+ writeFileSync,
28
+ } from "node:fs"
29
+ import { createRequire } from "node:module"
30
+ import { platform } from "node:os"
31
+ import { dirname, join } from "node:path"
32
+ import { fileURLToPath } from "node:url"
33
+
34
+ const projectRoot = join(dirname(fileURLToPath(import.meta.url)), "..")
35
+ const piAgentDist = join(projectRoot, "node_modules", "@earendil-works", "pi-coding-agent", "dist")
36
+
37
+ const themeFiles = ["dark.json", "light.json", "theme-schema.json"]
38
+ const themeSrc = join(piAgentDist, "modes", "interactive", "theme")
39
+
40
+ // Skip TypeScript declarations and source maps when staging export-html — only template.{html,css,js}
41
+ // and vendor/*.min.js are read at runtime, so .d.ts/.map files are pure payload bloat.
42
+ const exportHtmlSkipSuffixes = [".d.ts", ".d.ts.map", ".js.map"]
43
+ const exportHtmlSrc = join(piAgentDist, "core", "export-html")
44
+
45
+ const isDev = process.argv.includes("--dev")
46
+ // Test mode stages the dist layout tests read, but skips artifacts produced by other build
47
+ // steps (the Go proxy-helper binary), and no-ops when the staged copy is already up to date.
48
+ const isTest = !isDev && process.argv.includes("--test")
49
+ const shareDir = join(projectRoot, "dist", "share", "ekravo")
50
+ const stampPath = join(projectRoot, "dist", ".copy-resources.stamp")
51
+ const themeDest = isDev ? join(projectRoot, "src", "modes", "interactive", "theme") : join(shareDir, "theme")
52
+ const exportHtmlDest = isDev ? join(projectRoot, "src", "core", "export-html") : join(shareDir, "export-html")
53
+
54
+ // Everything the non-dev copy reads. Used by --test to decide whether the staged copy is stale.
55
+ const ekravoThemesSrc = join(projectRoot, "themes")
56
+ const oauthSrc = join(projectRoot, "resources", "oauth")
57
+ const resourceSources = [
58
+ themeSrc,
59
+ exportHtmlSrc,
60
+ ekravoThemesSrc,
61
+ oauthSrc,
62
+ join(projectRoot, "package.json"),
63
+ join(projectRoot, "UpdateCLI.md"),
64
+ join(projectRoot, "docs", "images.md"),
65
+ ]
66
+
67
+ function newestMtimeMs(path) {
68
+ let newest = statSync(path).mtimeMs
69
+ if (!statSync(path).isDirectory()) return newest
70
+ for (const entry of readdirSync(path, { withFileTypes: true })) {
71
+ if (entry.isDirectory()) {
72
+ newest = Math.max(newest, newestMtimeMs(join(path, entry.name)))
73
+ } else if (!exportHtmlSkipSuffixes.some((suffix) => entry.name.endsWith(suffix))) {
74
+ newest = Math.max(newest, statSync(join(path, entry.name)).mtimeMs)
75
+ }
76
+ }
77
+ return newest
78
+ }
79
+
80
+ function isUpToDate() {
81
+ if (!existsSync(stampPath) || !existsSync(shareDir)) return false
82
+ const stagedAt = statSync(stampPath).mtimeMs
83
+ // package.json lands in the share dir; if it went missing the copy has to run again.
84
+ if (!existsSync(join(shareDir, "package.json"))) return false
85
+ // A missing source is stale, not up to date — let the copy report it by name.
86
+ if (!resourceSources.every((source) => existsSync(source))) return false
87
+ return resourceSources.every((source) => newestMtimeMs(source) <= stagedAt)
88
+ }
89
+
90
+ if (isTest && isUpToDate()) {
91
+ console.log("copy-resources: dist/share/ekravo is newer than its sources, skipping")
92
+ process.exit(0)
93
+ }
94
+
95
+ // Fail with the missing path rather than an ENOENT from deep inside cpSync.
96
+ const missingSources = resourceSources.filter((source) => !existsSync(source))
97
+ if (missingSources.length > 0) {
98
+ throw new Error(`resource source(s) missing: ${missingSources.join(", ")}`)
99
+ }
100
+
101
+ mkdirSync(themeDest, { recursive: true })
102
+
103
+ for (const file of themeFiles) {
104
+ cpSync(join(themeSrc, file), join(themeDest, file))
105
+ }
106
+
107
+ cpSync(exportHtmlSrc, exportHtmlDest, {
108
+ recursive: true,
109
+ filter: (src) => !exportHtmlSkipSuffixes.some((suffix) => src.endsWith(suffix)),
110
+ })
111
+
112
+ // Post-process export HTML template to inject the ekravo version number.
113
+ const pkg = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8"))
114
+ // Match src/utils.ts getVersion() mapping (0.0.0 → "dev").
115
+ const appVersion = pkg.version && pkg.version !== "0.0.0" ? pkg.version : "dev"
116
+ // Inject a single inline script just before </body> that sets the version
117
+ // and dynamically patches the DOM after renderHeader() has already run.
118
+ // renderHeader() stays upstream code, so this survives template.js refactors.
119
+ const templateHtmlPath = join(exportHtmlDest, "template.html")
120
+ let templateHtml = readFileSync(templateHtmlPath, "utf-8")
121
+ templateHtml = templateHtml.replace(
122
+ "</body>",
123
+ `<script>
124
+ (function() {
125
+ window.__EKRAVO_VERSION = ${JSON.stringify(appVersion)};
126
+ const container = document.querySelector('.header-info');
127
+ if (!container) return;
128
+ const el = document.createElement('div');
129
+ el.className = 'info-item';
130
+ el.innerHTML = '<span class="info-label">Version:</span><span class="info-value">' + window.__EKRAVO_VERSION + '</span>';
131
+ container.appendChild(el);
132
+ })();
133
+ </script>
134
+ </body>`,
135
+ )
136
+ writeFileSync(templateHtmlPath, templateHtml, "utf-8")
137
+
138
+ // ekravo's own themes live outside node_modules — copy them alongside the upstream themes
139
+ const ekravoThemeFiles = readdirSync(ekravoThemesSrc).filter((f) => f.endsWith(".json"))
140
+ for (const file of ekravoThemeFiles) {
141
+ cpSync(join(ekravoThemesSrc, file), join(themeDest, file))
142
+ }
143
+
144
+ if (!isDev) {
145
+ const resourceRequire = createRequire(import.meta.url)
146
+ const photonEntry = resourceRequire.resolve("@silvia-odwyer/photon-node", { paths: [realpathSync(piAgentDist)] })
147
+ const photonWasmSrc = join(dirname(photonEntry), "photon_rs_bg.wasm")
148
+ // dist/bin only exists once a binary build has run; unit-test runs must not need one.
149
+ const distBinDir = join(projectRoot, "dist", "bin")
150
+ if (existsSync(distBinDir)) {
151
+ cpSync(photonWasmSrc, join(distBinDir, "photon_rs_bg.wasm"))
152
+ }
153
+ cpSync(photonWasmSrc, join(shareDir, "photon_rs_bg.wasm"))
154
+ cpSync(join(projectRoot, "package.json"), join(shareDir, "package.json"))
155
+ cpSync(join(projectRoot, "UpdateCLI.md"), join(shareDir, "UpdateCLI.md"))
156
+ cpSync(join(projectRoot, "docs", "images.md"), join(shareDir, "images.md"))
157
+
158
+ // Copy custom OAuth page templates
159
+ const oauthDest = join(shareDir, "oauth")
160
+ mkdirSync(oauthDest, { recursive: true })
161
+ cpSync(oauthSrc, oauthDest, { recursive: true })
162
+
163
+ // Copy proxy-helper binary built by scripts/build-proxy-helper.js. Test runs skip it:
164
+ // the binary comes from `build:proxy-helper`, not from this script, and no test reads it.
165
+ if (!isTest) {
166
+ const buildTargetOS = process.env.EKRAVO_BUILD_TARGET_OS || platform()
167
+ const proxyHelperName =
168
+ buildTargetOS === "win32" || buildTargetOS === "windows" ? "proxy-helper.exe" : "proxy-helper"
169
+ const proxyHelperSrc = join(projectRoot, "tools", "proxy-helper", "bin", proxyHelperName)
170
+ const proxyHelperBinDest = join(shareDir, "bin")
171
+ if (!existsSync(proxyHelperSrc)) {
172
+ throw new Error(`proxy-helper binary not found: ${proxyHelperSrc}`)
173
+ }
174
+ mkdirSync(proxyHelperBinDest, { recursive: true })
175
+ cpSync(proxyHelperSrc, join(proxyHelperBinDest, proxyHelperName))
176
+ }
177
+
178
+ // Only write the up-to-date stamp once the whole copy succeeded, so a failed or
179
+ // interrupted run can never make a later --test run skip the regeneration.
180
+ if (isTest) {
181
+ writeFileSync(stampPath, `${new Date().toISOString()}\n`, "utf-8")
182
+ }
183
+ }
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-install patch for @earendil-works/pi-ai OAuth pages.
4
+ *
5
+ * Replaces the hardcoded Pi-branded HTML in pi-ai's oauth-page.js with a
6
+ * renderer that reads Ekravo templates from EKRAVO_OAUTH_TEMPLATE_DIR.
7
+ * The templates themselves live in resources/oauth/ — designers iterate
8
+ * on them without touching node_modules or refreshing this patch.
9
+ *
10
+ * If the env var is missing or the template can't be read, the renderer
11
+ * falls through to a minimal unbranded HTML fallback. We deliberately avoid
12
+ * upstream's Pi-branded fallback (ekravo shipping competitor branding is the
13
+ * exact failure mode this patch exists to eliminate), and we avoid throwing
14
+ * (the token is already saved by the time the renderer is called — blank-
15
+ * paging the user mid-flow is worse UX than a degraded-looking page).
16
+ *
17
+ * Remove when upstream supports configurable OAuth page templates.
18
+ * Tracking: TODO - open upstream issue against pi-mono for OAuth page customization.
19
+ */
20
+ import { existsSync, writeFileSync } from "node:fs"
21
+ import { join } from "node:path"
22
+
23
+ const target = join(process.cwd(), "node_modules", "@earendil-works", "pi-ai", "dist", "auth", "oauth", "oauth-page.js")
24
+
25
+ const patched = `import { readFileSync } from "node:fs";
26
+ function escapeHtml(value) {
27
+ return value
28
+ .replaceAll("&", "&amp;")
29
+ .replaceAll("<", "&lt;")
30
+ .replaceAll(">", "&gt;")
31
+ .replaceAll('"', "&quot;")
32
+ .replaceAll("'", "&#39;");
33
+ }
34
+ function renderPage(options) {
35
+ const templateDir = process.env.EKRAVO_OAUTH_TEMPLATE_DIR;
36
+ if (templateDir) {
37
+ try {
38
+ const filePath = templateDir + "/" + (options.template || "default") + ".html";
39
+ let html = readFileSync(filePath, "utf-8");
40
+ html = html.replaceAll("{{TITLE}}", escapeHtml(options.title || ""));
41
+ html = html.replaceAll("{{HEADING}}", escapeHtml(options.heading || ""));
42
+ html = html.replaceAll("{{MESSAGE}}", escapeHtml(options.message || ""));
43
+ html = html.replaceAll("{{DETAILS}}", options.details ? \`<div class="details">\${escapeHtml(options.details)}</div>\` : "");
44
+ return html;
45
+ }
46
+ catch {
47
+ // fall through to minimal unbranded fallback
48
+ }
49
+ }
50
+ const title = escapeHtml(options.title || "");
51
+ const heading = escapeHtml(options.heading || "");
52
+ const message = escapeHtml(options.message || "");
53
+ const details = options.details ? escapeHtml(options.details) : undefined;
54
+ return \`<!doctype html>
55
+ <html lang="en">
56
+ <head>
57
+ <meta charset="utf-8" />
58
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
59
+ <title>\${title}</title>
60
+ <style>
61
+ body { font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 480px; margin: 48px auto; padding: 24px; line-height: 1.5; color: #111; }
62
+ h1 { font-size: 20px; margin: 0 0 12px; }
63
+ p { margin: 0 0 12px; color: #555; }
64
+ .details { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: #f5f5f5; padding: 12px; border-radius: 6px; white-space: pre-wrap; word-break: break-word; }
65
+ </style>
66
+ </head>
67
+ <body>
68
+ <h1>\${heading}</h1>
69
+ <p>\${message}</p>
70
+ \${details ? \`<div class="details">\${details}</div>\` : ""}
71
+ </body>
72
+ </html>\`;
73
+ }
74
+ export function oauthSuccessHtml(message) {
75
+ return renderPage({
76
+ title: "Authentication successful",
77
+ heading: "Authentication successful",
78
+ message,
79
+ template: "success",
80
+ });
81
+ }
82
+ export function oauthErrorHtml(message, details) {
83
+ return renderPage({
84
+ title: "Authentication failed",
85
+ heading: "Authentication failed",
86
+ message,
87
+ details,
88
+ template: "error",
89
+ });
90
+ }
91
+ //# sourceMappingURL=oauth-page.js.map
92
+ `
93
+
94
+ try {
95
+ if (!existsSync(target)) throw new Error(`Expected upstream file not found: ${target}`)
96
+ writeFileSync(target, patched)
97
+ console.log("[patch-pi-ai-oauth] Patched pi-ai OAuth page templates.")
98
+ } catch (err) {
99
+ console.error("[patch-pi-ai-oauth] Could not patch file:", err instanceof Error ? err.message : String(err))
100
+ process.exit(1)
101
+ }