From 33e0520469f1d28d83cd80d25ea49fc39044a24e Mon Sep 17 00:00:00 2001 From: Ilya Krasnov <232380238+yiaany@users.noreply.github.com> Date: Sun, 1 Nov 2026 18:57:50 +0500 Subject: [PATCH] feat(cli): ship terminal messenger alpha with WebRTC calls and npm packaging --- .github/dependabot.yml | 10 + .github/workflows/cli.yml | 41 ++ .gitignore | 7 + CONTRIBUTING.md | 54 ++ README.md | 52 +- SECURITY.md | 7 + THIRD_PARTY_NOTICES.md | 8 + cli/LICENSE | 21 + cli/README.md | 360 ++++++++++ cli/THIRD_PARTY_NOTICES.md | 23 + cli/bin/gitmsg.mjs | 40 ++ cli/bin/runtime.mjs | 22 + cli/package-lock.json | 1221 +++++++++++++++++++++++++++++++ cli/package.json | 70 ++ cli/scripts/build.ts | 19 + cli/scripts/check-package.ts | 24 + cli/scripts/release-check.mjs | 19 + cli/scripts/run-bun.mjs | 6 + cli/scripts/smoke-package.mjs | 40 ++ cli/src/app.tsx | 772 ++++++++++++++++++++ cli/src/brand.tsx | 6 + cli/src/browser.ts | 20 + cli/src/call-device.ts | 78 ++ cli/src/call-native.ts | 92 +++ cli/src/call-view.tsx | 39 + cli/src/call-worker.ts | 58 ++ cli/src/calls.ts | 58 ++ cli/src/clipboard-bridge.ts | 27 + cli/src/clipboard-targets.ts | 25 + cli/src/clipboard.ts | 22 + cli/src/command-menu.tsx | 18 + cli/src/commands.ts | 32 + cli/src/composer.tsx | 30 + cli/src/config.ts | 3 + cli/src/credentials.ts | 25 + cli/src/device-flow.ts | 76 ++ cli/src/github.ts | 32 + cli/src/help.tsx | 16 + cli/src/image-input.ts | 37 + cli/src/image-view.tsx | 100 +++ cli/src/images.ts | 49 ++ cli/src/main.tsx | 29 + cli/src/motion.tsx | 107 +++ cli/src/presentation.ts | 17 + cli/src/room-keys.ts | 47 ++ cli/src/rooms.ts | 305 ++++++++ cli/src/safety.ts | 40 ++ cli/src/theme.tsx | 5 + cli/src/themes.ts | 13 + cli/src/voice-data.ts | 47 ++ cli/src/voice-view.tsx | 76 ++ cli/src/voice.ts | 121 ++++ cli/tests/auth.test.ts | 135 ++++ cli/tests/call-webrtc.test.ts | 52 ++ cli/tests/calls.test.ts | 111 +++ cli/tests/clipboard.test.ts | 28 + cli/tests/features.test.ts | 177 +++++ cli/tests/fixtures.ts | 20 + cli/tests/package.test.ts | 43 ++ cli/tests/presentation.test.ts | 20 + cli/tests/rooms.test.ts | 184 +++++ cli/tests/themes.test.ts | 32 + cli/tests/ui.test.tsx | 1228 ++++++++++++++++++++++++++++++++ cli/tests/voice.test.ts | 59 ++ cli/tsconfig.json | 18 + docs/CLI.md | 145 ++++ docs/CLI_RELEASE.md | 118 +++ docs/CLI_RELEASE_REVIEW.md | 71 ++ docs/PROTOCOL.md | 11 + docs/PUBLISHING.md | 4 + scripts/check-secrets.mjs | 2 +- src/lib/protocol.ts | 2 +- tests/secrets.test.ts | 2 +- tsconfig.json | 2 +- 74 files changed, 6924 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/cli.yml create mode 100644 cli/LICENSE create mode 100644 cli/README.md create mode 100644 cli/THIRD_PARTY_NOTICES.md create mode 100755 cli/bin/gitmsg.mjs create mode 100644 cli/bin/runtime.mjs create mode 100644 cli/package-lock.json create mode 100644 cli/package.json create mode 100644 cli/scripts/build.ts create mode 100644 cli/scripts/check-package.ts create mode 100644 cli/scripts/release-check.mjs create mode 100644 cli/scripts/run-bun.mjs create mode 100644 cli/scripts/smoke-package.mjs create mode 100644 cli/src/app.tsx create mode 100644 cli/src/brand.tsx create mode 100644 cli/src/browser.ts create mode 100644 cli/src/call-device.ts create mode 100644 cli/src/call-native.ts create mode 100644 cli/src/call-view.tsx create mode 100644 cli/src/call-worker.ts create mode 100644 cli/src/calls.ts create mode 100644 cli/src/clipboard-bridge.ts create mode 100644 cli/src/clipboard-targets.ts create mode 100644 cli/src/clipboard.ts create mode 100644 cli/src/command-menu.tsx create mode 100644 cli/src/commands.ts create mode 100644 cli/src/composer.tsx create mode 100644 cli/src/config.ts create mode 100644 cli/src/credentials.ts create mode 100644 cli/src/device-flow.ts create mode 100644 cli/src/github.ts create mode 100644 cli/src/help.tsx create mode 100644 cli/src/image-input.ts create mode 100644 cli/src/image-view.tsx create mode 100644 cli/src/images.ts create mode 100644 cli/src/main.tsx create mode 100644 cli/src/motion.tsx create mode 100644 cli/src/presentation.ts create mode 100644 cli/src/room-keys.ts create mode 100644 cli/src/rooms.ts create mode 100644 cli/src/safety.ts create mode 100644 cli/src/theme.tsx create mode 100644 cli/src/themes.ts create mode 100644 cli/src/voice-data.ts create mode 100644 cli/src/voice-view.tsx create mode 100644 cli/src/voice.ts create mode 100644 cli/tests/auth.test.ts create mode 100644 cli/tests/call-webrtc.test.ts create mode 100644 cli/tests/calls.test.ts create mode 100644 cli/tests/clipboard.test.ts create mode 100644 cli/tests/features.test.ts create mode 100644 cli/tests/fixtures.ts create mode 100644 cli/tests/package.test.ts create mode 100644 cli/tests/presentation.test.ts create mode 100644 cli/tests/rooms.test.ts create mode 100644 cli/tests/themes.test.ts create mode 100644 cli/tests/ui.test.tsx create mode 100644 cli/tests/voice.test.ts create mode 100644 cli/tsconfig.json create mode 100644 docs/CLI.md create mode 100644 docs/CLI_RELEASE.md create mode 100644 docs/CLI_RELEASE_REVIEW.md diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fe3632b..df6311f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,16 @@ updates: groups: minor-and-patch: update-types: [minor, patch] + - package-ecosystem: npm + directory: /cli + schedule: + interval: weekly + open-pull-requests-limit: 5 + groups: + bun-runtime: + patterns: ["@oven/bun-*"] + opentui: + patterns: ["@opentui/*"] - package-ecosystem: github-actions directory: / schedule: diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml new file mode 100644 index 0000000..8850330 --- /dev/null +++ b/.github/workflows/cli.yml @@ -0,0 +1,41 @@ +name: Terminal client + +on: + push: + pull_request: + +permissions: + contents: read + +concurrency: + group: cli-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + runs-on: ${{ matrix.os }} + timeout-minutes: 15 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + fetch-depth: 0 + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + node-version: 26 + cache: npm + cache-dependency-path: cli/package-lock.json + - run: npm ci --include=dev --include=optional --ignore-scripts + working-directory: cli + - run: npm run release:check + working-directory: cli + - run: node bin/gitmsg.mjs --help + working-directory: cli + - run: npm pack --pack-destination "$RUNNER_TEMP" + working-directory: cli + - run: npm run test:package -- "$RUNNER_TEMP"/yiaany-gitmsg-*.tgz + working-directory: cli diff --git a/.gitignore b/.gitignore index 467450f..3ac490c 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,10 @@ credentials.json /events/ /media/ /exports/ +# Terminal build output and accidental local CLI credentials. +/cli/dist/ +/cli/*.tgz +.gitmsg-local/ +gitmsg-auth.json +gitmsg-room-key.txt +.gitmsg-room-key-*.txt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f6df1e5..536ada6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,6 +37,59 @@ Use synthetic screenshots and the PR checklist. Never attach tokens, cookies, private chat exports, room keys, real invite links or full network captures. Security bugs go through [SECURITY.md](SECURITY.md), not public issues. +## Terminal client + +The OpenTUI application lives in **`cli/`**, with a separate npm manifest/lockfile. +It reuses the website's protocol, encryption and call state machine; do not fork +the wire format just to make a terminal feature easier. CLI dependencies do not +belong in the Next.js root package. + +Use **Node >=26.4** (OpenTUI's declared engine). Optional npm dependencies provide +the pinned Bun runtime; no separate shell installer is needed: + +```sh +cd cli +npm ci --include=dev --include=optional --ignore-scripts +npm run dev +``` + +`npm run dev` needs a real terminal. Read [CLI usage](docs/CLI.md) for sign-in; +contributors need no production token/client secret. For a separate OAuth app, +enable Device Flow and supply only its public Client ID. Unit/UI tests require no +credentials, microphone permission or real GitHub writes. + +Before a CLI PR, from `cli/`: + +```sh +npm run release:check +``` + +Also run the root website tests/typecheck/build for shared protocol changes. The +CI jobs are separate so CLI native dependencies do not enter a website build. + +Useful paths: + +| Path | Purpose | +| --- | --- | +| `cli/src/app.tsx`, `motion.tsx`, `themes.ts` | Terminal screens, input, animation and themes | +| `cli/src/rooms.ts`, `github.ts`, `device-flow.ts` | Validated GitHub operations and device login | +| `cli/src/credentials.ts`, `room-keys.ts` | OS credential and room-key storage boundaries | +| `cli/src/call-*.ts`, `call-view.tsx`, `calls.ts` | Audio devices, isolated Node WebRTC worker and ASCII UI | +| `cli/bin/`, `cli/scripts/` | Fixed-executable launcher, builds and publication allowlist | +| `cli/tests/` | Synthetic transport, rendering, native WebRTC and failure-path tests | + +Preserve drafts, keyboard/mouse navigation, compact layouts, themes and reduced +motion. Microphone diagrams must use measured levels; no fake presence, connection +success or clipboard acknowledgement. Calls/recording never start on an incoming +event or while merely reading a chat. Keep audio queues bounded; stop devices and +workers after cancellation, denial, hangup, sign-out and exit. Never load the +native WebRTC module directly into Bun: it runs in the isolated Node worker. + +Use synthetic screenshots. Real OAuth, invites, sends and calls require explicit +consent and private test accounts/rooms. Do not connect tests to somebody's inbox. +Publishing or promoting an npm tag is not a side effect of a PR or test run; follow +the [separate release gates](docs/CLI_RELEASE.md). + ## Project guardrails - Keep interface copy **English** and follow the current components, spacing and @@ -62,6 +115,7 @@ Security bugs go through [SECURITY.md](SECURITY.md), not public issues. | `src/lib/protocol.ts`, `room-crypto.ts` | Event validation, history and encryption | | `src/lib/audio-call.ts` | Direct audio lifecycle and resource cleanup | | `src/components/` | Messenger UI and browser integrations | +| `cli/` | Separately packaged OpenTUI messenger, native audio and tests | | `tests/`, `scripts/check-secrets.mjs` | Regression checks and publication safety | | `docs/`, `public/integrations/`, `plugins/` | Protocol, CLI and opt-in integrations | diff --git a/README.md b/README.md index e09b0e6..2c1b92d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

Your DMs. Their version control. Our questionable judgment.
- A real messenger built on GitHub. Yes, every “lol” is a commit. + A real messenger built on GitHub. Now in your terminal. Yes, every “lol” is a commit.

@@ -25,7 +25,8 @@

- The good stuff · + The good stuff · + Terminal CLI · Self-host · Contribute · Break something? @@ -33,6 +34,53 @@ --- +## ☎️ Your terminal can make phone calls now + +**Chat. Send voice notes. Call your friends. Without leaving the terminal.** +An actual OpenTUI messenger, not `curl` wearing a trench coat. + +> **Bill Gates pays for our DMs. We brought the ASCII art.** +> Your terminal is a phone. Your database is GitHub. Your messages are commits. +> This is either peak engineering or a cry for help. **Holy shit, it works.** +> +> The Bill Gates part is a joke: GitHub is owned by Microsoft, not a personal +> sponsorship. API quotas, storage, hosting and your network costs still apply. +> Live audio is peer-to-peer, not a Microsoft-funded conference bridge. + +### One install. One command. Your own GitHub account. + +**npm release candidate:** `@yiaany/gitmsg@0.1.0-alpha.0`. The commands below are +for **after the first alpha is published**; registry ownership/authorization is +still a release gate. The unrelated npm package `gitmsg` is **not this project**. + +With **Node.js >=26.4** and npm: + +```sh +npm install --global @yiaany/gitmsg@alpha +gitmsg +``` + +That's it. npm installs the matching Bun runtime too; no separate shell installer. +Choose **Continue with GitHub**, approve the one-time code, and use your own chats. +No token paste, client secret or personal OAuth app required. Want your own OAuth +app or an existing GitHub API token from your credential manager? [You can →](docs/CLI.md#your-own-github-connection) + +- **Real WebRTC audio calls.** Connecting spinner, connected timer, themed ASCII + art and a voice diagram driven by your actual microphone. Not random bars. +- **Messages, images, voice notes, Copy / Reply, per-chat drafts and five themes.** +- **Optional `/secure` encryption.** New content and call signaling use shared + AES-256-GCM keys; audio uses WebRTC transport encryption. +- **`gitmsg` or `git message`**, from any directory. It never commits your project. + +Alpha caveats: calls need two-person private-chat metadata; incoming calls follow +the open conversation. No TURN means some networks won't connect. A real +website-to-CLI call still needs live acceptance testing. OAuth asks for broad +`repo` access; standard messages are GitHub-readable. This is not an audited +Signal replacement or an offline messenger. + +**[CLI quick start & commands](docs/CLI.md)** · **[Full terminal manual](cli/README.md)** · +**[Contribute to the CLI](CONTRIBUTING.md#terminal-client)** · **[Release checklist](docs/CLI_RELEASE.md)** + ## 💬 Wait, this actually works? **Chats are repositories. Messages are commits.** “I never said that” now comes with a `git log`. diff --git a/SECURITY.md b/SECURITY.md index 3790dbc..0799795 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -39,6 +39,13 @@ against other users or production chat repositories without permission. networks cannot connect. Standard SDP can disclose IP addresses in Git history. - Public profiles/channels are public. Never make chat/settings/Saved Messages repositories public when opening this **source-code** repository. +- The terminal OAuth Client ID is public configuration, not a client secret. + Device Flow still requires GitHub approval and requests broad `repo read:user` + access. Tokens use an OS credential store or session memory, never a plaintext + fallback. Keep npm authorization and room-key backups outside source/artifacts. +- npm installs pinned platform runtime/native dependencies. The CLI never fetches + an executable at launch; dependency integrity is not an independent security + audit. [CLI release gates](docs/CLI_RELEASE.md) cover the exact package archive. See [safe publication](docs/PUBLISHING.md) for the release checklist. Secret scanners reduce accidents; they cannot prove the absence of all sensitive data. diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index d2ad1e6..a6195ed 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -56,3 +56,11 @@ the upstream `app/globals.css` and `components/kokonutui/ai-prompt.tsx`. `qrcode-generator` 2.0.4: Copyright (c) 2009 Kazuhiko Arase, MIT License. The full MIT terms above apply to this notice. + +# Terminal client + +The separately packaged OpenTUI client uses React, OpenTUI, platform Bun runtimes +and the isolated Node WebRTC dependency. Package-specific licensing boundaries +and upstream native-code notices are listed in +[`cli/THIRD_PARTY_NOTICES.md`](cli/THIRD_PARTY_NOTICES.md), which is also included +in its npm allowlist. Website-only components/fonts are not part of that payload. diff --git a/cli/LICENSE b/cli/LICENSE new file mode 100644 index 0000000..18133bb --- /dev/null +++ b/cli/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 gitmsg contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/cli/README.md b/cli/README.md new file mode 100644 index 0000000..71e0f9a --- /dev/null +++ b/cli/README.md @@ -0,0 +1,360 @@ +# gitmsg / terminal + +**Your terminal is a phone now. Your DMs are commits.** An OpenTUI messenger using +the website's actual event validation, WebRTC calls and AES-GCM protocol. + +> Bill Gates pays for our DMs. We brought the ASCII art. +> (A joke, not a sponsorship: GitHub belongs to Microsoft. Quotas, storage, +> network and hosting costs still apply. Live audio is peer-to-peer.) + +## Install once. Launch whenever. + +**Release candidate, not published yet:** `@yiaany/gitmsg@0.1.0-alpha.0`. +After the maintainer authorizes the first npm alpha: + +```sh +npm install --global @yiaany/gitmsg@alpha +gitmsg +``` + +Requires **Node.js >=26.4** and npm. npm installs a pinned platform-specific Bun +runtime as an optional dependency; no separate Bun setup or launch-time download. +Do not omit optional dependencies. `git message` launches the same app. To update, +repeat the install command. To uninstall, use `npm uninstall --global @yiaany/gitmsg`; +sign out/revoke access separately if desired. + +The npm name **`gitmsg` is an unrelated package**. Do not run `npx gitmsg` expecting +this client. `@yiaany/gitmsg` is the proposed release name; availability is not a +reservation or proof of npm-scope ownership. [Release gates](https://github.com/yiaany/gitmsg/blob/main/docs/CLI_RELEASE.md). + +This package is separate from the Next.js website. It does not change Vercel's +runtime, dependencies, OAuth callback or production environment variables. + +## Development + +Use **Node.js >=26.4** (matching OpenTUI's declared requirement). The pinned +**Bun 1.4.4** dependency renders the UI through native FFI; Node runs the launcher, +isolated WebRTC worker and unit tests. Native audio calls also require the optional +`@roamhq/wrtc` binary for your platform (macOS/Linux arm64/x64, Windows x64). +Windows arm64 native calls are not supported by this dependency. + +```sh +cd cli +npm ci --include=dev --include=optional --ignore-scripts +npm test +npm run typecheck +npm run test:ui +npm run build +node bin/gitmsg.mjs +``` + +After an npm install puts the binaries on PATH, `gitmsg` and +**`git message`** open the same interface. No Git alias or Git configuration is +written. Start in any project: the launcher switches to its own package directory, +disables Bun's automatic `.env` loading, and never shells out to Git. + +## Your GitHub, without copying a token + +1. Choose **Continue with GitHub**. The separate terminal OAuth App's public ID is + bundled; users do not need to register their own app. Device Flow uses no + callback listener and **no client secret**. Review the app name before approving. +2. To use your own app, choose **Use a different OAuth App**, or supply its public + ID via `GITMSG_CLIENT_ID`. Enable Device Flow in that app's GitHub settings. +3. The UI shows `https://github.com/login/device` and an eight-character code. + Click the link (or press Enter) to open your browser. Verify the app + name/permissions in GitHub, enter the code and authorize. Only the fixed GitHub + URL is opened; codes/tokens are never put in it. SSH never opens a remote browser. +4. The CLI polls at GitHub's interval, honors `slow_down`, expires/cancels cleanly, + verifies `/user`, then saves the token to the **OS credential store**. + +OAuth requests `repo read:user`: `repo` is broad access to private repositories, +**not** room-specific permission. No `workflow`, organization administration or +Actions scopes are requested. GitHub App least-privilege onboarding is a later, +separate flow; this alpha does not pretend OAuth is narrowly scoped. + +The bundled **OAuth Client ID is intentionally public**, not an API token or +client secret. It cannot log in as you without GitHub authorization. Keep your +OAuth application's Device Flow enabled; users verify the app and permissions on +GitHub. Public IDs can still be copied/abused, so do not treat branding as proof +that a login request is trustworthy. The CLI contains no website client secret. + +Credentials use Bun's experimental Secrets API: macOS Keychain, Linux libsecret +(an unlocked secret-service daemon is required), or Windows Credential Manager +with device-local persistence. **There is no plaintext fallback.** If saving fails, +the UI says so and the token stays in memory for that session only. A credential +manager can optionally supply `GITMSG_TOKEN` for a session; it is not saved. +The CLI never imports `gh` credentials or silently reads `GITHUB_TOKEN`. + +`gitmsg auth logout` removes only this client's local vault entry. Revoke actual +authorization in GitHub **Settings → Applications**. Expired tokens require a new +Device Flow; refresh tokens are deliberately not retained in this alpha. + +## Choose a room + +Hover a chat in the sidebar for **×**, or select it and press **X / Delete**. +After confirmation it is hidden from this device's list, **not deleted from +GitHub**: history, repository and membership remain unchanged. `/join owner/repo` +restores it, including its session draft. Hidden IDs are scoped to the account +and saved in the system credential store; if unavailable they last this session. + +- **Join existing:** paste `owner/repo` or a plain GitHub repository URL. The CLI + requires an active **private** repo with a valid `.gitmsg/room.json`. It never + initializes or overwrites an unmarked repo. Public channels are not supported yet. +- **Create private:** enter a name, review `OWNER/gitmsg-NAME`, then explicitly + confirm. Cancel is selected by default. Only a new private repo, its initial + commit and the compatible room marker are created — no local project upload. +- **Invite a friend:** click **+ Invite** or type `/invite @username`. Review and + confirm granting repository **write access**. Only administrators can invite. +- **Accept invitations:** `/inbox` shows pending private gitmsg invitations. Accept + explicitly; the room marker is checked before opening. `/join` also accepts a + GitHub `/invitations` link and offers the matching pending invitation. + Sharing a URL alone grants **no access**. Encryption keys must be shared separately. + +## Clean UI and commands + +`/help` contains the full command list, keyboard controls and privacy notes. There +are no permanent navigation banners. `Ctrl+K` opens the chat picker. Sidebar rows +show friendly titles (or `Conversation N` for generated IDs), latest loaded text +and unsent-draft indicators. Explicit two-person room metadata supplies peer names; +message authors are never guessed to be recipients. + +Sidebar: **↑↓** highlight, **Enter** open, **→** open directly in the composer. +History: **←** sidebar, **↑↓** scroll, **→ / Enter** compose. Composer: **↑** history, +**←** sidebar when empty or at the start; ordinary text-cursor arrows are preserved +inside a draft. **Alt+←** opens +the sidebar even while drafting. **Ctrl+G** invites from anywhere in the chat. +`Tab` / `Shift+Tab` cycle sidebar, history, Invite and composer. `Esc` steps back; +on narrow terminals, sidebar navigation opens the picker. Drafts and recent history stay separate for each +chat **in memory**; they are cleared on exit/sign-out. Previously validated room +metadata and loaded history display immediately while messages refresh in the +background. Switching does not disable typing or wait for that refresh; stale +responses cannot replace the selected chat. Writes still revalidate access, +repository privacy, branch and encryption policy against GitHub. + +Short 180 ms eased transitions run on OpenTUI's shared animation clock at a target +of **60 FPS**, pausing on completion rather than continuously redrawing the app. +Real frame rate depends on terminal/PTY throughput. Set `GITMSG_REDUCED_MOTION=1` +to disable motion. No animations trigger GitHub calls. + +### Appearance and commands + +The two-row `gitmsg` wordmark uses OpenTUI's built-in **ASCIIFont `tiny`**, as +documented in [ASCIIFont](https://opentui.com/docs/components/ascii-font/), +not hand-drawn glyphs or a web font. A separate header leaves clear space above +the sidebar. The messenger +uses quiet split surfaces instead of nested cards: a chat rail, a clear +conversation, and a compact composer with a thin rounded outline and bottom breathing room. Sidebar cards +have inset padding; opened rooms use a quiet fill and keyboard focus a brighter +fill plus a small chevron. Chat cards and messages use subtle rounded outlines; +sidebar action labels are vertically centered in their highlights. Messages have a two-row gap, +and only message bodies participate in text selection. New messages fade in; +pending text sends have an indeterminate signal that disappears on +success or failure. It is not a delivery/read receipt or upload percentage. + +The composer soft-wraps long drafts, grows upwards to five text rows (three in +short terminals), then scrolls internally while keeping its bottom edge fixed. +**Enter** sends; **Shift+Enter** inserts a newline where supported; **Ctrl+J** is +the newline fallback. The 4,000-character limit also applies to pasted text. +Up moves through wrapped rows and opens history only from the first row. +Already running terminal processes keep their old UI until restarted; rebuilding +does not hot-reload authenticated sessions or discard their in-memory drafts. + +Hover a message for **Copy / Reply** underneath; the action row reserves space so +messages do not jump. Copy preserves line breaks. Select terminal text and use +**Ctrl+C** (copies instead of quitting when selected), **Ctrl+Shift+C**, or **⌘C** +in the browser preview. Holding **Shift** while dragging bypasses terminal mouse +handling for the browser/terminal's own text selection. With no selection, plain +Ctrl+C still quits; copy-only shortcuts never quit. Native local clipboard writes +fall back to terminal OSC52; SSH never writes the remote host clipboard. The +browser bridge copies through the browser clipboard API and reports denial. + +Copy shows progress and a short **✓ Copied** beside that message, only after a +confirmed clipboard write. No extra banner or second confirmation button. The +preview writes during the original Copy click, before a PTY round trip loses +user activation; the native CLI writes to the OS clipboard. OSC52-only terminals +can report a request, not a verified write. + +**Reply** opens a cancellable quote above the composer, preserves the draft and +stores its target separately per chat. Only Enter/Send Image sends it. Replies +use the shared `replyTo` protocol (encrypted inside secure-room events). Click a +reply's quote to jump to a loaded original. Deleted/locked messages cannot be +copied or selected as reply targets. **Esc / ×** cancels a pending reply. + +Type **/** in the composer or chat picker to see **every slash command**. Keep +typing to filter; **↑↓** select; **Tab** or **Enter** completes. Enter on an exact +command runs it. Argument-taking commands complete with a trailing space. +**Esc** hides suggestions without changing your draft. `//` stays literal text. + +**/themes** opens live previews of **Mono** (default, entirely grayscale), +**Violet**, **Tokyo Night**, **Catppuccin Mocha**, and **Paper** (light). +**↑↓** or a click previews, **Enter** applies, **Esc** restores the previous theme. +All surfaces, inputs, focus rings, image status text and help share semantic +colors. Themes last for the session; `GITMSG_THEME=paper` selects a startup theme +without writing any preference, credential or chat file. + +Design references: [OpenTUI examples](https://opentui.com/packages/opentui-examples/), +[animation clock](https://opentui.com/docs/application-apis/animation), +[Tokyo Night](https://github.com/folke/tokyonight.nvim), +[Catppuccin palette](https://github.com/catppuccin/palette). +The latter two contribute color references, not copied application layouts. + +Invitations have a dedicated result panel with **Copy invitation link** and +**Invite another friend**. Clipboard support depends on terminal OSC52 permissions; +if unavailable, select the displayed link. All access grants still need confirmation. + +Commands: `/chats`, `/new [name]`, `/join owner/repo`, `/invite @username`, `/inbox`, +`/attach /absolute/image.png`, `/voice`, `/secure`, `/call`, `/hangup`, `/themes`, `/refresh`, `/logout`, `/help`. Commands never become +chat commits. Unknown commands are refused. Use `//` for a literal leading slash. + +**Paste images:** in a native local terminal, **Ctrl+V** explicitly reads an image +from the OS clipboard, without shell commands or temporary files. A single pasted +absolute image path (including quoted paths or local `file://` URLs) also opens a +preview; ordinary text paste is unchanged. The local browser PTY preview supports +image paste and file drop by transferring bytes over its authenticated bridge, +not by injecting file data into terminal text. SSH and bridge sessions never read +the server's clipboard. Terminal/clipboard support varies; `/attach` is the +fallback. No clipboard polling or automatic upload. + +`/attach` and image paste open a local preview, with **Send Image first and selected**. +**Enter** explicitly confirms; **↓ → Enter** selects Cancel; **Esc** cancels. +Pasting preserves the existing draft. Only the +explicitly confirmed image is uploaded, never a folder or other project files. +PNG, JPEG, GIF (still preview) and WebP are supported, up to 2 MiB. Remote images +are loaded from authenticated GitHub blobs, size/hash checked, then decrypted if +necessary. The latest four images load automatically. Click any image or its +filename (including an unloaded older image) to open a large, centered preview +with a rounded frame, filename, dimensions and size. **Esc**, **Enter** or **× Close** +returns to the same conversation and draft. Viewing is read-only, reuses verified +cached bytes and cancels pending reads when closed. +Previews are limited to 16 megapixels and downscaled in memory; terminal cell/pixel +geometry preserves aspect ratio. Verified image bytes have a bounded in-memory +cache (eight images/eight MiB per session). Native Kitty/Sixel +terminals show graphics; other terminals get color-block previews, not fake URLs. + +Reading/opening a room creates nothing. Only submitting a nonempty message writes +an event. New event files use unique IDs; existing messages are not overwritten. +No auto-retry of writes: an explicit retry of an ambiguous send checks the same +event path before sending, avoiding a duplicate while the process remains open. +If initialization fails after repository creation, the UI reports that the repo +already exists; it neither recreates nor deletes it. + +## What works, and what does not (yet) + +### Voice messages + +Click **● Voice** or run `/voice`. Recording starts only after this action and +device permission. The five-row cell waveform grows with measured RMS loudness; +there is no fake audio animation. Native recording uses OpenTUI `Audio.openCapture` +at 16 kHz mono; the browser PTY uses the browser microphone, never the server's. +Both produce bounded PCM16 WAV in memory (60 seconds, under 2 MiB). No `ffmpeg`, +shell process, project-file upload or plaintext recording file is used. + +**Enter** stops recording; the preview starts on **Cancel**. Select **Listen** or +**Send Voice** with arrows/Enter or the mouse. Esc cancels and releases the input. +Drafts are preserved. Click **▶ Play / ■ Stop** on a received voice to listen +inside the terminal. Native playback supports these PCM WAV recordings; the +browser bridge also plays the website's WebM/Ogg/MP4 attachments. Unsupported +devices/codecs and denied permissions show an error, never a pretend success. + +### `/secure` + +Open a chat and type `/secure`, then explicitly confirm. The administrator enables +the shared `gitmsg/security.json` policy. New text, reply targets and attachment +metadata use **AES-256-GCM** with a cryptographically random 256-bit room key; +image and voice bytes are separately authenticated/encrypted before upload. +GitHub receives only ciphertext and a key fingerprint, **never the secret key**. + +Save the key to the system credential store, or explicitly choose **Enable + +create private key backup** on macOS/Linux. This alternative displays its exact +home-directory path before confirmation, creates a new owner-only `0600` file, +verifies it and never overwrites an existing file or follows a symlink. It is an +**unencrypted private backup**, not an OS keychain substitute; protect your disk. +If durable storage fails, no policy is written. An ambiguous GitHub response +retains the same saved key so an explicit retry does not generate a different one. + +Use `/secure import /absolute/key-file` or `GITMSG_KEY_FILE` to load a separately +shared owner-only backup. Never paste the raw key into a message or store it in +the chat repository. `/secure` offers an explicit **Copy secret key** action for +sharing through another trusted channel. Missing/wrong keys and policy loss fail +closed instead of sending plaintext. Keys are scoped to account, chat and branch. + +This protects **new content**, not earlier plaintext commits, sender identities, +timestamps, ciphertext sizes, a leaked key or a compromised endpoint. A hash +alone is not encryption. Losing every key copy makes content unrecoverable. + +### WebRTC audio calls + +Click **◉ Call** or run `/call` in a writable private direct chat. Its room marker +must name exactly two participants, including you; the partner is verified through +GitHub, never guessed from a repository name or message author. The confirmation +defaults to **Cancel**. An incoming offer does not open the microphone: **A / Answer** +accepts it, **H / Decline** refuses it. Incoming discovery currently follows the +open conversation, not a background inbox of every repository. + +The CLI reuses the website's `AudioCall` engine and bounded **offer / answer / end** +protocol. Only signaling is committed to GitHub; `/secure` also encrypts that SDP. +Live audio uses **WebRTC DTLS-SRTP**, with the website's STUN servers and **no TURN +relay**. Restrictive NAT/firewalls may prevent a direct connection. Standard-mode +SDP can expose network addresses to GitHub and the peer; encryption does not hide +call metadata. Your partner must keep a compatible gitmsg client open. + +The themed ASCII panel shows preparing/ringing/connecting/connected/ended states, +a connection spinner, elapsed connected time, and local/remote **measured RMS** +levels. Only connection animation is decorative; the voice diagram is never +randomized. **M** mutes, **H** hangs up, `/hangup` ends the call from chat. **Esc** +hides an active panel without hanging up; click Call to return. Drafts survive. +Hangup, sign-out, exit and device failures release audio resources. Voice-message +recording is blocked during calls. + +Native calls capture/play 48 kHz mono PCM through OpenTUI and isolate pinned +`@roamhq/wrtc@0.10.0` in Node (the native module is not loaded into Bun). PCM queues +are bounded and no recording is saved. Use headphones: this native capture path +does not promise browser-grade echo cancellation. SSH refuses server audio. The +local browser preview instead uses browser WebRTC, microphone and speakers over +authenticated local control IPC; it never opens server audio devices. + +Automated tests include decoded non-silent synthetic WebRTC audio between two +isolated workers, signaling encryption, cancellation and UI/level rendering. +They do **not** establish real microphone/speaker quality or a tested cross-device +website-to-terminal call; those need two consenting accounts and devices. + +- Keyboard-driven room selection, themed split-pane chat, narrow-terminal + layout, scrolling and a controlled message composer. +- Real text sends; loaded history materializes edits, deletes and reactions from + other clients. **A commit is not a read receipt.** No invented presence/messages. +- Latest **300 event commits**, canonical Git order, ETags, one read at a time, + 5-second polling (60 seconds unfocused) and rate-limit/error backoff. +- Existing secure rooms: optionally supply `GITMSG_KEY_FILE` with an absolute path to an + owner-only room-key backup **outside the source repository**. Keys never go in + arguments, config, GitHub requests or diagnostics. Missing/wrong keys, malformed + policies or encrypted-history downgrades refuse plaintext sends. +- Terminal control/OSC/bidi sequences are stripped from rendered remote data. + Recognizable tokens, private keys and room-key links are blocked in drafts. + This is best-effort accident prevention, **not** a complete DLP/security audit. +- Image viewing/uploading, voice messages, WebRTC audio calls, secure-mode setup and invitations are + implemented. Video calls, search, pagination beyond the recent window and + composing edits/reactions are not implemented. + +Standard chat is GitHub-readable. Deletion is a tombstone, not Git-history erasure. +Encryption protects content, not metadata or a compromised device. Quotas and +hosting limits still apply. See [security boundaries](https://github.com/yiaany/gitmsg/blob/main/docs/ENCRYPTION.md). + +## Distribution safety + +`npm run build` bundles only application code and shared protocol logic; OpenTUI +React and the BSD-2-Clause `@roamhq/wrtc` native dependency remain normal npm +dependencies with their own licenses/notices. `npm run pack:check` previews the explicit +package allowlist: launcher, built entry point, Node WebRTC worker, README, MIT license and package +metadata. No source maps, chat exports, `.env`, key backups or local config. + +Do not publish, force-push, change repository visibility or enable an OAuth App +on somebody's behalf as a side effect of development. Before any release, settle +the npm name, verify the bundled public OAuth App and its permissions, run the secret +scanner and package-content checks, audit dependencies and test real Device Flow +and two consenting accounts in a dedicated private test room. Unit/UI tests use +only synthetic, in-memory GitHub responses; they do not prove live OAuth works. + +Maintainers: [CLI release checklist](https://github.com/yiaany/gitmsg/blob/main/docs/CLI_RELEASE.md). Contributors: +[terminal development guide](https://github.com/yiaany/gitmsg/blob/main/CONTRIBUTING.md#terminal-client). + +MIT. Dependencies retain their own [licenses and notices](THIRD_PARTY_NOTICES.md). diff --git a/cli/THIRD_PARTY_NOTICES.md b/cli/THIRD_PARTY_NOTICES.md new file mode 100644 index 0000000..24a104b --- /dev/null +++ b/cli/THIRD_PARTY_NOTICES.md @@ -0,0 +1,23 @@ +# Terminal client dependencies + +gitmsg application code is MIT licensed; see LICENSE. Dependencies are separately +distributed npm packages, not relicensed by this project. Keep their licenses and +native-code notices with any redistribution, including a standalone binary. + +| Dependency | Purpose | License | +| --- | --- | --- | +| `@opentui/core`, `@opentui/react` 0.8.1 | Native terminal rendering, React integration and audio | MIT | +| `react` 19.3.1 | UI runtime | MIT | +| `@oven/bun-*` 1.4.4 | Platform-specific Bun runtime, installed by npm | MIT, with upstream third-party notices | +| `@roamhq/wrtc` / platform packages 0.10.0 | Isolated Node WebRTC audio engine | BSD-2-Clause, with upstream libwebrtc notices | + +The runtime and native modules contain third-party software with additional +upstream notices. Consult the installed packages and upstream projects: +[OpenTUI](https://github.com/anomalyco/opentui), +[React](https://github.com/facebook/react), +[Bun](https://github.com/oven-sh/bun), +[node-webrtc](https://github.com/WonderInventions/node-webrtc). + +Tokyo Night and Catppuccin themes use palette references, not application code. +No Telegram application source, logos, web fonts or website-only UI dependencies +are bundled in the npm terminal package. diff --git a/cli/bin/gitmsg.mjs b/cli/bin/gitmsg.mjs new file mode 100755 index 0000000..b560b44 --- /dev/null +++ b/cli/bin/gitmsg.mjs @@ -0,0 +1,40 @@ +#!/usr/bin/env node +import { spawn } from "node:child_process"; +import { existsSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { bunExecutable, supportedNode } from "./runtime.mjs"; + +const root = fileURLToPath(new URL("../", import.meta.url)); +const args = process.argv.slice(2); +if (args.includes("--help") || args.includes("-h")) { + console.log(`gitmsg — real conversations, real commits + +gitmsg Open the terminal messenger +gitmsg owner/repo Open an existing private chat +git message Same messenger, when installed on PATH +gitmsg auth logout Remove this client's locally saved credential + +Install: npm install --global @yiaany/gitmsg@alpha +Requires Node >=26.4.0. A pinned platform Bun runtime is installed by npm. +Choose Continue with GitHub for one-time-code sign-in. No client secret is used. +GITMSG_CLIENT_ID optionally overrides the bundled PUBLIC terminal OAuth App ID. +Tokens use the OS credential store when available, otherwise session memory only. +GITMSG_TOKEN is an optional, session-only credential-manager environment override. +GITMSG_KEY_FILE optionally points to a private room-key backup outside the repo. +No tokens/messages in command arguments. No automatic Git commits or pushes in your cwd. +Package: @yiaany/gitmsg (alpha), not the unrelated npm package named gitmsg.`); +} else if (!supportedNode()) { + console.error("gitmsg requires Node.js >=26.4.0. Upgrade Node before launching the terminal client."); + process.exitCode = 1; +} else { + const entry = fileURLToPath(new URL("../dist/main.js", import.meta.url)); + if (!existsSync(entry)) { + console.error("Built entry point missing. Reinstall @yiaany/gitmsg, or run npm run build from cli/ for a source checkout."); + process.exitCode = 1; + } else { + // Fixed executable/arguments; never run a shell or load the caller's .env files. + const child = spawn(bunExecutable(), ["--no-env-file", entry, ...args], { cwd: root, stdio: "inherit", shell: false, env: { ...process.env, GITMSG_NODE_EXECUTABLE: process.execPath } }); + child.on("error", () => { console.error("Bun runtime unavailable. Reinstall with optional dependencies, or provide Bun >=1.4.4 on PATH. No installer was run at launch."); process.exitCode = 1; }); + child.on("exit", (code, signal) => { process.exitCode = code ?? (signal ? 130 : 1); }); + } +} diff --git a/cli/bin/runtime.mjs b/cli/bin/runtime.mjs new file mode 100644 index 0000000..e00b27d --- /dev/null +++ b/cli/bin/runtime.mjs @@ -0,0 +1,22 @@ +import { createRequire } from "node:module"; + +const require = createRequire(import.meta.url); +export function supportedNode(version = process.versions.node) { + const [major, minor] = version.split(".").map(Number); + return major > 26 || (major === 26 && minor >= 4); +} +export function runtimePackage(platform = process.platform, arch = process.arch, musl = false) { + if (!["darwin", "linux", "win32"].includes(platform) || !["arm64", "x64"].includes(arch)) return null; + const os = platform === "win32" ? "windows" : platform; + const cpu = arch === "arm64" ? "aarch64" : "x64"; + return `@oven/bun-${os}-${cpu}${platform === "linux" && musl ? "-musl" : ""}`; +} +export function bunExecutable() { + const musl = process.platform === "linux" && !process.report?.getReport().header.glibcVersionRuntime; + const name = runtimePackage(process.platform, process.arch, musl); + if (name) { + try { return require.resolve(`${name}/bin/${process.platform === "win32" ? "bun.exe" : "bun"}`); } + catch { /* Source installs / --omit=optional may use an existing local Bun. */ } + } + return "bun"; +} diff --git a/cli/package-lock.json b/cli/package-lock.json new file mode 100644 index 0000000..c116054 --- /dev/null +++ b/cli/package-lock.json @@ -0,0 +1,1221 @@ +{ + "name": "@yiaany/gitmsg", + "version": "0.1.0-alpha.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "@yiaany/gitmsg", + "version": "0.1.0-alpha.0", + "license": "MIT", + "dependencies": { + "@opentui/core": "0.8.1", + "@opentui/react": "0.8.1", + "@roamhq/wrtc": "0.10.0", + "react": "19.3.1" + }, + "bin": { + "git-message": "bin/gitmsg.mjs", + "gitmsg": "bin/gitmsg.mjs" + }, + "devDependencies": { + "@types/bun": "1.4.4", + "@types/react": "19.3.0", + "tsx": "4.23.1", + "typescript": "6.0.3" + }, + "engines": { + "node": ">=26.4.0" + }, + "optionalDependencies": { + "@oven/bun-darwin-aarch64": "1.4.4", + "@oven/bun-darwin-x64": "1.4.4", + "@oven/bun-linux-aarch64": "1.4.4", + "@oven/bun-linux-aarch64-musl": "1.4.4", + "@oven/bun-linux-x64": "1.4.4", + "@oven/bun-linux-x64-musl": "1.4.4", + "@oven/bun-windows-aarch64": "1.4.4", + "@oven/bun-windows-x64": "1.4.4" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@opentui/core": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core/-/core-0.8.1.tgz", + "integrity": "sha512-WmnpnVZn2MdyYNEahQNn4k3OrIkQKfcwPVrX/DjguLtl/S2g5fPeXCqHZjCg2GLMf1N4HJap0LEkTPJEvfrDXw==", + "license": "MIT", + "dependencies": { + "bun-ffi-structs": "0.3.1", + "diff": "9.0.0", + "marked": "17.0.1", + "string-width": "7.2.0" + }, + "engines": { + "bun": ">=1.3.14", + "node": ">=26.4.0" + }, + "optionalDependencies": { + "@opentui/core-darwin-arm64": "0.8.1", + "@opentui/core-darwin-x64": "0.8.1", + "@opentui/core-linux-arm64": "0.8.1", + "@opentui/core-linux-arm64-musl": "0.8.1", + "@opentui/core-linux-x64": "0.8.1", + "@opentui/core-linux-x64-musl": "0.8.1", + "@opentui/core-win32-arm64": "0.8.1", + "@opentui/core-win32-x64": "0.8.1" + }, + "peerDependencies": { + "web-tree-sitter": "0.25.10" + } + }, + "node_modules/@opentui/core-darwin-arm64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-darwin-arm64/-/core-darwin-arm64-0.8.1.tgz", + "integrity": "sha512-22jdbN55W9hCraw6k1y3TklzCvF90UJG7d1wvtUYwsn9LOEvOZn+i3fUyqkpP+kBgL31RBt+sB4RKsUmNzjWaw==", + "cpu": [ + "arm64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@opentui/core-darwin-x64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-darwin-x64/-/core-darwin-x64-0.8.1.tgz", + "integrity": "sha512-rlqzXisgUl3U7WmrWySFLLZq6x9ZQiSRSGLyyULBFWTZLJY4qrs2a7y/8B0NpIFY7Ngku17qVIKcVwQZZBoLbw==", + "cpu": [ + "x64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@opentui/core-linux-arm64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-linux-arm64/-/core-linux-arm64-0.8.1.tgz", + "integrity": "sha512-UtJzpwvAy67RU60T1IFNBYHH3tUrmcIHsLrNI+8WFFxoOk6btwRp67NKiZd3qoDcztTz2q/yKf9KQI0yr+P6MQ==", + "cpu": [ + "arm64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@opentui/core-linux-arm64-musl": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-linux-arm64-musl/-/core-linux-arm64-musl-0.8.1.tgz", + "integrity": "sha512-BzVCOuG5Vw/nB9ffLwZq82uEg0f0BE4wkd5EvrqOET9qK5D5emT4Zo8tZJFY8NG0/xBuWj6S9xVpazQWjZR17A==", + "cpu": [ + "arm64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@opentui/core-linux-x64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-linux-x64/-/core-linux-x64-0.8.1.tgz", + "integrity": "sha512-du4V6YlGvCWs/ggc6Tj7Oc7qaoYdPpzwAeJMKUbjrg+Zv5zweNHFMN4YLbzIutTi6Ukz4KsW/hwEaQIjXHlUcA==", + "cpu": [ + "x64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@opentui/core-linux-x64-musl": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-linux-x64-musl/-/core-linux-x64-musl-0.8.1.tgz", + "integrity": "sha512-RB/u2G5X4KpW1/rT5iabCLYbmfMWKF3OASj2Z29+RAj38I7caRU3/TTntpX3CpHzjQrDTVWyMYzcnu+WFF8thg==", + "cpu": [ + "x64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@opentui/core-win32-arm64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-win32-arm64/-/core-win32-arm64-0.8.1.tgz", + "integrity": "sha512-wF5AZRWDCjkfRHT1cRfyvHkf+RI/Pxjb0oMFVg2h2ayndBu8CSgyQDhtNgZd0ON+xrP4xceikCkHDhDLe5bv1w==", + "cpu": [ + "arm64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@opentui/core-win32-x64": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/core-win32-x64/-/core-win32-x64-0.8.1.tgz", + "integrity": "sha512-+rIrkvwBJMGWdXn4GGQAmM4y+RH1Xvb9nveNyJ58SOsTOBqyWyi+63qMlxe58WVl+sVAJodEjAILcWdwrzMJ3Q==", + "cpu": [ + "x64" + ], + "license": "MIT AND LGPL-2.1-or-later", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@opentui/core/node_modules/bun-ffi-structs": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/bun-ffi-structs/-/bun-ffi-structs-0.3.1.tgz", + "integrity": "sha512-3gM7PpVWLyrwxWjcilSiGuhWanhZivvo6l0u573NziPH6f/gwk6McbaYgn7oJWov6pKGRTDbrg94W5DcJsKTtQ==", + "license": "MIT", + "peerDependencies": { + "typescript": "^5" + } + }, + "node_modules/@opentui/core/node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "license": "Apache-2.0", + "peer": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/@opentui/react": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@opentui/react/-/react-0.8.1.tgz", + "integrity": "sha512-2Suc127MY7iLkgzFjyKJVsML4PZHhtc+lOXgQhP4bP6zxgNCBlGm/FxX0fDbp5RpuogKyIix9s57YnpxQB54nw==", + "license": "MIT", + "dependencies": { + "@opentui/core": "0.8.1", + "react-reconciler": "^0.33.0" + }, + "peerDependencies": { + "react": ">=19.2.0", + "react-devtools-core": "^7.0.1", + "ws": "^8.18.0" + } + }, + "node_modules/@oven/bun-darwin-aarch64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.4.4.tgz", + "integrity": "sha512-zW/hxwc8sJAILGwB5eTC4i48ouGXf0V4lrxmEOk3JIE6JkYVW1TZh1E2pIempqsezgW1sckTIIDudFON8bJ2Mw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oven/bun-darwin-x64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.4.4.tgz", + "integrity": "sha512-oKGcxLsvh4oHjAo28nPm8c/xN0o/OmGyj1IHYc94vprkWsW2hNg2keEZt5f40cI5Hvu4jDlSRTR0UNpv1UIAxw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@oven/bun-linux-aarch64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.4.4.tgz", + "integrity": "sha512-ZTVtpf9zmHSBVPX1sBwe5agGb/rN34yPGg/Hby8e2Ax2uCUA2URZKlZH7qLntK7qaFJCMXh9v0GWNYN2zINz1w==", + "cpu": [ + "arm64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oven/bun-linux-aarch64-musl": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64-musl/-/bun-linux-aarch64-musl-1.4.4.tgz", + "integrity": "sha512-QFd0P+mHJxbZFbUla4MgiE5OwxysHaUIYxL2pPNkpWtaI7v4ShOpr8OhBmsuyB0xn5rv/ZJnPsj2y8+bB9+g/A==", + "cpu": [ + "arm64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oven/bun-linux-x64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.4.4.tgz", + "integrity": "sha512-CHbbkmHVM28T1GFq+6GL4Ao4ujwwYwj1CxFFwEFzLanPfNsId9AhbIP0Q4reWuWBkGimUkoQygrK7Rgjtj3vog==", + "cpu": [ + "x64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oven/bun-linux-x64-musl": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-musl/-/bun-linux-x64-musl-1.4.4.tgz", + "integrity": "sha512-lEEjNOJJrbGZu2NVcPI4uXdILcpspezWkA8R/Jr0RCGhM6zQd0Y7JBIIKNAmbX59EeWpeEz7Q78iLbpcAUypUA==", + "cpu": [ + "x64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@oven/bun-windows-aarch64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-windows-aarch64/-/bun-windows-aarch64-1.4.4.tgz", + "integrity": "sha512-n0ep5ZRPCZY1+dqFJpnnRUZB1wy4GYU6At8RF+pyzySCLjkN9R4rFh2PtBHAgF/lg1vOl3/CeER3pDM+p40ATA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@oven/bun-windows-x64": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.4.4.tgz", + "integrity": "sha512-a3LNctBVO8PjePsFZfwDleF2JXYf2BfQ1u/PLRnBDLnC2Riml+4+LgJpKj4xRGhB92KweGyQI5PXaTkP9qypMQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@roamhq/wrtc": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc/-/wrtc-0.10.0.tgz", + "integrity": "sha512-yFqQQ0EV1ZUHaphh3tmjoxPi2wzhW2vjmzoAVNRRLUjXYd2e1nvwi9TKfE2w4WNvNws/hBkouvOt23Xo9FkXkQ==", + "license": "BSD-2-Clause", + "optionalDependencies": { + "@roamhq/wrtc-darwin-arm64": "0.10.0", + "@roamhq/wrtc-darwin-x64": "0.10.0", + "@roamhq/wrtc-linux-arm64": "0.10.0", + "@roamhq/wrtc-linux-x64": "0.10.0", + "@roamhq/wrtc-win32-x64": "0.10.0", + "domexception": "^4.0.0" + } + }, + "node_modules/@roamhq/wrtc-darwin-arm64": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc-darwin-arm64/-/wrtc-darwin-arm64-0.10.0.tgz", + "integrity": "sha512-vFdi79jWuPHcnUcnuOjTvyKtmY/RI2xRQo9Y6RsIjIlYePN/7LTy00c+Ivrz4prYAPbp0oHscl7PDV64VUqGTQ==", + "cpu": [ + "arm64" + ], + "license": "BSD-2-Clause", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@roamhq/wrtc-darwin-x64": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc-darwin-x64/-/wrtc-darwin-x64-0.10.0.tgz", + "integrity": "sha512-H6852g2xYCuaR+/TrthpdMafs4bMfAUEpvRDhsIguzrK7Dz+MKpNI8MkwdqJN8W65J+7w7k+YqXIkTHe7Fz/cg==", + "cpu": [ + "x64" + ], + "license": "BSD-2-Clause", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@roamhq/wrtc-linux-arm64": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc-linux-arm64/-/wrtc-linux-arm64-0.10.0.tgz", + "integrity": "sha512-fEuJbNjprxQG6QlFd2iqBW9x028RDSho6izVg7gyt8irdPiXWOxzOxNnYMs/B2fohBTd1wD4Qxfivl07/dCR8A==", + "cpu": [ + "arm64" + ], + "license": "BSD-2-Clause", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@roamhq/wrtc-linux-x64": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc-linux-x64/-/wrtc-linux-x64-0.10.0.tgz", + "integrity": "sha512-H32lK2eFg3sVb/9nkHIX5HIisxFoS82Gpesuea+zqAyRpRzSd5NpFXx28bVy9wQyRrNtj8k0bTUgEzWRzSbYCA==", + "cpu": [ + "x64" + ], + "license": "BSD-2-Clause", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@roamhq/wrtc-win32-x64": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/@roamhq/wrtc-win32-x64/-/wrtc-win32-x64-0.10.0.tgz", + "integrity": "sha512-wEVXMvLrBizdLyrd+Zc7zb7zpwUuHUBXwrdIvI69e3i/AA8YsVYI2xo/sxk6GoQ+o8a14ONc4SStDS35TCjg+w==", + "cpu": [ + "x64" + ], + "license": "BSD-2-Clause", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/bun": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/@types/bun/-/bun-1.4.4.tgz", + "integrity": "sha512-9wkRDXUXK124pEnAutE6n/l18j+i9GC5IAHK8TmX/2nlySETmky0OU6yL5U8pW1AoKh++AN9auDCr647BfurjQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "bun-types": "1.4.4" + } + }, + "node_modules/@types/node": { + "version": "26.6.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-26.6.6.tgz", + "integrity": "sha512-MzQj+8Kx3XI40OmUAE6Qoh58ZMNstNNMwn2nfd3qWsfe7nDNSqJNzes4njhz6AHwrSHOffSLwXU6yb474Q4aog==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~8.9.0" + } + }, + "node_modules/@types/node/node_modules/undici-types": { + "version": "8.9.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.9.0.tgz", + "integrity": "sha512-KTDyRTYX8sWmKXAikPHHSyc63CRPETMctyjKFupcC6OBLXT3xsN0e9aF7m+mIXutFWpUXuedtowG7iLOzp0kQg==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/react": { + "version": "19.3.0", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.0.tgz", + "integrity": "sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==", + "dev": true, + "license": "MIT", + "dependencies": { + "csstype": "^3.2.2" + } + }, + "node_modules/ansi-regex": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.5.0.tgz", + "integrity": "sha512-zhvbbbdt1kbw7EJ9OQoxmQcuaNR9P5kTj7e/YdmOSU10aHWbycofJxA6jKfoEy3vlLdctOF9ZHaxLtmSm998wQ==", + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/bun-types": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/bun-types/-/bun-types-1.4.4.tgz", + "integrity": "sha512-yjrJh5oGX7mMPKGd19YXyIjmEuj4G4zNC30bs7PM9Az7NQ3ndF3j6hbeRdvJTRQEhJ/FYQwW0a2moweEi2hMxQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/node": "*", + "undici-types": "*" + } + }, + "node_modules/csstype": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", + "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/diff": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-9.0.0.tgz", + "integrity": "sha512-svtcdpS8CgJyqAjEQIXdb3OjhFVVYjzGAPO8WGCmRbrml64SPw/jJD4GoE98aR7r25A0XcgrK3F02yw9R/vhQw==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/domexception": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/domexception/-/domexception-4.0.0.tgz", + "integrity": "sha512-A2is4PLG+eeSfoTMA95/s4pvAoSo2mKtiM5jlHkAVewmiO8ISFTFKZjH7UAM1Atli/OT/7JHOrJRJiMKUZKYBw==", + "license": "MIT", + "optional": true, + "dependencies": { + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/emoji-regex": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.6.0.tgz", + "integrity": "sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A==", + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/get-east-asian-width": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.7.0.tgz", + "integrity": "sha512-XjH1AECxf0giL2V1aU8vKyRR2ppRUb5c0EvT7zuJTokQ74bNo52zOtghqdWIqrhUD79fo3x0WfKZdOqxF6LG1Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/marked": { + "version": "17.0.1", + "resolved": "https://registry.npmjs.org/marked/-/marked-17.0.1.tgz", + "integrity": "sha512-boeBdiS0ghpWcSwoNm/jJBwdpFaMnZWRzjA6SkUMYb40SVaN1x7mmfGKp0jvexGcx+7y2La5zRZsYFZI6Qpypg==", + "license": "MIT", + "bin": { + "marked": "bin/marked.js" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/react": { + "version": "19.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-19.3.1.tgz", + "integrity": "sha512-QNhWdt7nrgVWWQG58QuGsAR3jv3Hbe4mb4vz7w2csnHavciZJgda1CPNaldF6eVxv90ud3jUXpKlHL69gO38yw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/react-devtools-core": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-7.0.1.tgz", + "integrity": "sha512-C3yNvRHaizlpiASzy7b9vbnBGLrhvdhl1CbdU6EnZgxPNbai60szdLtl+VL76UNOt5bOoVTOz5rNWZxgGt+Gsw==", + "license": "MIT", + "peer": true, + "dependencies": { + "shell-quote": "^1.6.1", + "ws": "^7" + } + }, + "node_modules/react-devtools-core/node_modules/ws": { + "version": "7.5.13", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.13.tgz", + "integrity": "sha512-rsKI6xDBFVf4r/x8XyChGK04QR/XHroxs/jUcoWvtEZM8TPU/X/uIY9B1CsSzYws9ZJb/6bbBu7dPhFW00CAoA==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/react-reconciler": { + "version": "0.33.0", + "resolved": "https://registry.npmjs.org/react-reconciler/-/react-reconciler-0.33.0.tgz", + "integrity": "sha512-KetWRytFv1epdpJc3J4G75I4WrplZE5jOL7Yq0p34+OVOKF4Se7WrdIdVC45XsSSmUTlht2FM/fM1FZb1mfQeA==", + "license": "MIT", + "dependencies": { + "scheduler": "^0.27.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "peerDependencies": { + "react": "^19.2.0" + } + }, + "node_modules/scheduler": { + "version": "0.27.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.27.0.tgz", + "integrity": "sha512-eNv+WrVbKu1f3vbYJT/xtiF5syA5HPIMtf9IgY/nKg0sWqzAUEvqY/xm7OcZc/qafLx/iO9FgOmeSAp4v5ti/Q==", + "license": "MIT" + }, + "node_modules/shell-quote": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.12.0.tgz", + "integrity": "sha512-PcByqNyT/38F2kDNi006HAMRJaULuBzq/FOsw3qdZvX/GA9W/jamDaRskgHjubHiftXK5sIFxLNkvrXUwcof6Q==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "license": "MIT", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/strip-ansi": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz", + "integrity": "sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w==", + "license": "MIT", + "dependencies": { + "ansi-regex": "^6.2.2" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/tsx": { + "version": "4.23.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.23.1.tgz", + "integrity": "sha512-GQHnkIfxyx1wYCOS/wonik5MVRZU9hi1TEZmzGZSCJB1y9YgoZ8H6itNE/u4suE+yLmOzuE4E5S4TZ/ZX2wcWQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "~0.28.0" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "8.12.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-8.12.3.tgz", + "integrity": "sha512-EXE4ydL3S76dFb27UFjNVZHTyv/TLdATj/KUe29ptdcg6qXL48J2tZ3126E5kICj5jn781OR+XlVH1N6Mz8jbA==", + "dev": true, + "license": "MIT" + }, + "node_modules/web-tree-sitter": { + "version": "0.25.10", + "resolved": "https://registry.npmjs.org/web-tree-sitter/-/web-tree-sitter-0.25.10.tgz", + "integrity": "sha512-Y09sF44/13XvgVKgO2cNDw5rGk6s26MgoZPXLESvMXeefBf7i6/73eFurre0IsTW6E14Y0ArIzhUMmjoc7xyzA==", + "license": "MIT", + "peer": true, + "peerDependencies": { + "@types/emscripten": "^1.40.0" + }, + "peerDependenciesMeta": { + "@types/emscripten": { + "optional": true + } + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "optional": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/ws": { + "version": "8.22.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.1.tgz", + "integrity": "sha512-oyL6OPYme/CmiFvNuGzeoxCJ4nOrZE2O1FwM9MWM1AsGri6nLXB2pg+lNA8aLeXMSav0J6eIVS1j6vUPzUtK9g==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git a/cli/package.json b/cli/package.json new file mode 100644 index 0000000..cc6f0c6 --- /dev/null +++ b/cli/package.json @@ -0,0 +1,70 @@ +{ + "name": "@yiaany/gitmsg", + "version": "0.1.0-alpha.0", + "description": "GitHub-backed terminal chat with WebRTC calls, voice notes and optional encryption. Yes, your DMs are commits.", + "type": "module", + "license": "MIT", + "engines": { + "node": ">=26.4.0" + }, + "bin": { + "gitmsg": "bin/gitmsg.mjs", + "git-message": "bin/gitmsg.mjs" + }, + "files": [ + "bin/gitmsg.mjs", + "bin/runtime.mjs", + "dist/main.js", + "dist/call-worker.js", + "README.md", + "LICENSE", + "THIRD_PARTY_NOTICES.md" + ], + "scripts": { + "dev": "node scripts/run-bun.mjs src/main.tsx", + "build": "node scripts/run-bun.mjs scripts/build.ts", + "typecheck": "tsc --noEmit", + "test": "tsx --test tests/*.test.ts", + "test:ui": "node scripts/run-bun.mjs test tests/ui.test.tsx", + "pack:check": "tsx scripts/check-package.ts", + "test:package": "node scripts/smoke-package.mjs", + "release:check": "node scripts/release-check.mjs", + "prepack": "npm run build", + "prepublishOnly": "npm run release:check" + }, + "dependencies": { + "@opentui/core": "0.8.1", + "@opentui/react": "0.8.1", + "@roamhq/wrtc": "0.10.0", + "react": "19.3.1" + }, + "devDependencies": { + "@types/bun": "1.4.4", + "@types/react": "19.3.0", + "tsx": "4.23.1", + "typescript": "6.0.3" + }, + "optionalDependencies": { + "@oven/bun-darwin-aarch64": "1.4.4", + "@oven/bun-darwin-x64": "1.4.4", + "@oven/bun-linux-aarch64": "1.4.4", + "@oven/bun-linux-aarch64-musl": "1.4.4", + "@oven/bun-linux-x64": "1.4.4", + "@oven/bun-linux-x64-musl": "1.4.4", + "@oven/bun-windows-aarch64": "1.4.4", + "@oven/bun-windows-x64": "1.4.4" + }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/", + "tag": "alpha" + }, + "homepage": "https://github.com/yiaany/gitmsg#readme", + "bugs": { "url": "https://github.com/yiaany/gitmsg/issues" }, + "keywords": ["gitmsg", "terminal", "chat", "github", "webrtc", "opentui"], + "repository": { + "type": "git", + "url": "https://github.com/yiaany/gitmsg.git", + "directory": "cli" + } +} diff --git a/cli/scripts/build.ts b/cli/scripts/build.ts new file mode 100644 index 0000000..8d8ab4c --- /dev/null +++ b/cli/scripts/build.ts @@ -0,0 +1,19 @@ +import { copyFile, mkdir } from "node:fs/promises"; +import { fileURLToPath } from "node:url"; + +const root = fileURLToPath(new URL("../", import.meta.url)); +const result = await Bun.build({ + entrypoints: [root + "src/main.tsx"], + outdir: root + "dist", + naming: "main.js", + target: "bun", + packages: "external", + sourcemap: "none", + tsconfig: root + "tsconfig.json", +}); +if (!result.success) throw new Error("Terminal client build failed."); +const worker = await Bun.build({ entrypoints: [root + "src/call-worker.ts"], outdir: root + "dist", naming: "call-worker.js", target: "node", packages: "external", sourcemap: "none" }); +if (!worker.success) throw new Error("WebRTC worker build failed."); +await mkdir(root + "dist", { recursive: true }); +await copyFile(new URL("../../LICENSE", import.meta.url), root + "LICENSE"); +console.log("Built terminal client. No credentials, source maps or chat exports included."); diff --git a/cli/scripts/check-package.ts b/cli/scripts/check-package.ts new file mode 100644 index 0000000..58ba27e --- /dev/null +++ b/cli/scripts/check-package.ts @@ -0,0 +1,24 @@ +import { execFileSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import { basename } from "node:path"; +import { secretKinds } from "../../scripts/check-secrets.mjs"; + +const cwd = fileURLToPath(new URL("../", import.meta.url)); +try { + const npm = process.env.npm_execpath; + if (!npm || basename(npm) !== "npm-cli.js") throw new Error(); + const reports = JSON.parse(execFileSync(process.execPath, [npm, "pack", "--dry-run", "--ignore-scripts", "--json"], { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] })); + const paths: string[] = reports[0].files.map((file: { path: string }) => file.path).sort(); + const expected = ["LICENSE", "README.md", "THIRD_PARTY_NOTICES.md", "bin/gitmsg.mjs", "bin/runtime.mjs", "dist/main.js", "dist/call-worker.js", "package.json"].sort(); + if (JSON.stringify(paths) !== JSON.stringify(expected)) throw new Error(); + for (const path of paths) { + const bytes = readFileSync(cwd + path); + const text = bytes.toString("utf8"); + if (bytes.includes(0) || secretKinds(text).length || /(?:\/Users\/[^/\s]+\/|\/private\/var\/folders\/|file:\.\.\/)/.test(text)) throw new Error(); + } + console.log(JSON.stringify({ checkedPackageFiles: paths, secretFindings: 0, published: false }, null, 2)); +} catch { + console.error("Package check failed: build first, inspect the allowlist and rerun the redacted source scanner. No raw content printed."); + process.exitCode = 1; +} diff --git a/cli/scripts/release-check.mjs b/cli/scripts/release-check.mjs new file mode 100644 index 0000000..deaa3bd --- /dev/null +++ b/cli/scripts/release-check.mjs @@ -0,0 +1,19 @@ +import { spawnSync } from "node:child_process"; +import { basename, resolve } from "node:path"; +import { fileURLToPath } from "node:url"; + +const root = fileURLToPath(new URL("../", import.meta.url)); +const npm = process.env.npm_execpath; +if (!npm || basename(npm) !== "npm-cli.js") throw new Error("Use npm run release:check."); +for (const [cwd, args] of [ + [resolve(root, ".."), ["run", "check:secrets"]], + [root, ["run", "typecheck"]], + [root, ["test"]], + [root, ["run", "test:ui"]], + [root, ["run", "build"]], + [root, ["run", "pack:check"]], +]) { + const result = spawnSync(process.execPath, [npm, ...args], { cwd, stdio: "inherit", shell: false }); + if (result.error || result.status !== 0) process.exit(1); +} +console.log("Local release checks passed. Nothing was pushed or published. Registry ownership, dependency audit and live acceptance checks are separate release gates."); diff --git a/cli/scripts/run-bun.mjs b/cli/scripts/run-bun.mjs new file mode 100644 index 0000000..be946e7 --- /dev/null +++ b/cli/scripts/run-bun.mjs @@ -0,0 +1,6 @@ +import { spawn } from "node:child_process"; +import { bunExecutable } from "../bin/runtime.mjs"; + +const child = spawn(bunExecutable(), ["--no-env-file", ...process.argv.slice(2)], { stdio: "inherit", shell: false }); +child.on("error", () => { console.error("Bun runtime unavailable. Install optional dependencies or provide Bun >=1.4.4 on PATH."); process.exitCode = 1; }); +child.on("exit", (code, signal) => { process.exitCode = code ?? (signal ? 130 : 1); }); diff --git a/cli/scripts/smoke-package.mjs b/cli/scripts/smoke-package.mjs new file mode 100644 index 0000000..a921983 --- /dev/null +++ b/cli/scripts/smoke-package.mjs @@ -0,0 +1,40 @@ +// Installs only an explicitly selected local archive into a fresh temporary prefix. +// Never logs npm config, reads app credentials, starts OAuth or sends GitHub writes. +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { existsSync, mkdtempSync } from "node:fs"; +import { basename, join, resolve } from "node:path"; +import { tmpdir } from "node:os"; +import { pathToFileURL } from "node:url"; + +const archive = process.argv[2] && resolve(process.argv[2]); +const npm = process.env.npm_execpath; +if (!archive || !archive.endsWith(".tgz") || !existsSync(archive) || !npm || basename(npm) !== "npm-cli.js") throw new Error("Use npm run test:package -- /absolute/path/to/reviewed.tgz"); +const prefix = mkdtempSync(join(tmpdir(), "gitmsg-package-smoke-")); +const offline = process.env.GITMSG_PACKAGE_TEST_OFFLINE === "1"; +const installed = spawnSync(process.execPath, [npm, "install", "--global", "--prefix", prefix, ...(offline ? ["--offline"] : []), "--registry=https://registry.npmjs.org/", "--ignore-scripts", "--no-audit", "--no-fund", "--json", archive], { encoding: "utf8", shell: false }); +if (installed.error || installed.status !== 0) { + let failure; try { failure = JSON.parse(installed.stdout).error; } catch {} + const registryPath = String(failure?.summary ?? "").match(/https:\/\/registry\.npmjs\.org\/[A-Za-z0-9@%_.\/-]+/)?.[0]; + console.error(JSON.stringify({ npmError: failure?.code ?? installed.error?.code ?? "INSTALL_FAILED", publicRegistryPath: registryPath })); + throw new Error("Isolated archive install failed. Check registry access or warm the public cache for an offline test; raw npm output was not printed."); +} +const packageRoot = process.platform === "win32" ? join(prefix, "node_modules", "@yiaany", "gitmsg") : join(prefix, "lib", "node_modules", "@yiaany", "gitmsg"); +const { bunExecutable } = await import(pathToFileURL(join(packageRoot, "bin", "runtime.mjs")).href); +const runtime = bunExecutable(); +assert.notEqual(runtime, "bun", "The tarball install must resolve its npm-provided Bun, not depend on PATH"); +assert.ok(runtime.startsWith(prefix)); +const launcher = join(packageRoot, "bin", "gitmsg.mjs"); +const help = spawnSync(process.execPath, [launcher, "--help"], { encoding: "utf8", shell: false }); +assert.equal(help.status, 0); assert.match(help.stdout, /@yiaany\/gitmsg/); +assert.ok(existsSync(process.platform === "win32" ? join(prefix, "gitmsg.cmd") : join(prefix, "bin", "gitmsg"))); +assert.ok(existsSync(process.platform === "win32" ? join(prefix, "git-message.cmd") : join(prefix, "bin", "git-message"))); +// No TTY: this must load the real runtime/UI and reject before reading a vault, +// starting sign-in, opening microphone devices or contacting GitHub. +const startup = spawnSync(process.execPath, [launcher], { encoding: "utf8", shell: false, timeout: 15000, env: { ...process.env, GITMSG_TOKEN: "", GITMSG_KEY_FILE: "" } }); +assert.equal(startup.status, 1); assert.match(startup.stderr, /interactive messenger needs a terminal/); +if (process.platform !== "win32" || process.arch !== "arm64") { + const worker = spawnSync(process.execPath, [join(packageRoot, "dist", "call-worker.js")], { encoding: "utf8", shell: false, timeout: 15000 }); + assert.equal(worker.status, 0, "Packaged Node WebRTC worker must load and exit without opening audio devices"); +} +console.log(JSON.stringify({ installedLocalArchive: true, offline, npmRuntimeResolved: true, launchers: ["gitmsg", "git-message"], nonTTYStartupChecked: true, prefix, published: false }, null, 2)); diff --git a/cli/src/app.tsx b/cli/src/app.tsx new file mode 100644 index 0000000..89b2173 --- /dev/null +++ b/cli/src/app.tsx @@ -0,0 +1,772 @@ +import { useEffect, useRef, useState } from "react"; +import { useBlur, useFocus, useKeyboard, usePaste, useRenderer, useTerminalDimensions, type InputProps } from "@opentui/react"; +import { ClientError, publicError, terminalText } from "./safety"; +import { requestDeviceCode, waitForAuthorization, type DeviceCode } from "./device-flow"; +import { forgetCredential, readCredential, saveCredential, type Vault } from "./credentials"; +import { GitHub } from "./github"; +import { Rooms, loadRoomKey, type History, type Invitation, type TerminalRoom } from "./rooms"; +import type { Actor, Attachment, Message } from "../../src/lib/protocol"; +import { command, commandSuggestions, roomLink } from "./commands"; +import { localImage, pastedImagePath, type LocalImage } from "./images"; +import { clipboardImage, subscribeImages } from "./image-input"; +import { ChatImage, checkImage, ImageLightbox, ImageView } from "./image-view"; +import { Help } from "./help"; +import { conversationName } from "./presentation"; +import { ChatRow, FocusFrame, MessageBubble, Panel, Reveal, SendActivity } from "./motion"; +import type { ScrollBoxRenderable, TextareaRenderable } from "@opentui/core"; +import { ThemeContext, useTheme } from "./theme"; +import { THEMES, themeById, type Theme } from "./themes"; +import { Brand } from "./brand"; +import { CommandMenu } from "./command-menu"; +import { Composer } from "./composer"; +import { copyText as writeClipboard, type CopyText } from "./clipboard"; +import { messageCopyTargets } from "./clipboard-targets"; +import { GITHUB_DEVICE_URL, openGitHubLogin, type OpenBrowser } from "./browser"; +import { exportKey, generateKey, keyFingerprint } from "../../src/lib/room-crypto"; +import { privateBackupPath, readPrivateBackup, readRoomKey, savePrivateBackup, saveRoomKey } from "./room-keys"; +import { voiceDriver, type VoiceDriver } from "./voice"; +import { VoiceMessage, VoiceRecorder } from "./voice-view"; +import type { LocalVoice } from "./voice-data"; +import { TerminalCalls, type TerminalCallView } from "./calls"; +import { CallPanel } from "./call-view"; +import type { CallDeviceFactory, CallLevels } from "./call-device"; + +type Screen = "loading" | "signin" | "client" | "device" | "choose" | "join" | "name" | "confirm" | "chat" | "logout" | "help" | "invite" | "inviteConfirm" | "inviteDone" | "inbox" | "accept" | "image" | "themes" | "remove" | "voice" | "secure" | "call" | "callConfirm"; +type Focus = "composer" | "history" | "sidebar" | "invite"; +export type AppProps = { vault: Vault; initialClientId?: string; initialRepo?: string; initialToken?: string; roomKey?: CryptoKey | null; createRooms?: (token: string) => Rooms; readLocalImage?: typeof localImage; readClipboardImage?: typeof clipboardImage; receiveImages?: typeof subscribeImages; copyText?: CopyText; openBrowser?: OpenBrowser; audio?: VoiceDriver; callDevice?: CallDeviceFactory; readKeyBackup?: typeof readPrivateBackup; reducedMotion?: boolean; initialTheme?: string }; + +// Explicit focused colors and a line cursor prevent a block cursor from painting +// the first placeholder letter white when the empty input receives focus. +function Field(props: InputProps) { + const c = useTheme(); + return ; +} + +export function App(props: AppProps) { + const [theme, setTheme] = useState(() => themeById(props.initialTheme)); + return ; +} + +function Messenger({ vault, initialClientId = "", initialRepo, initialToken, roomKey = null, createRooms, readLocalImage = localImage, readClipboardImage = clipboardImage, receiveImages = subscribeImages, copyText, openBrowser = openGitHubLogin, audio, callDevice, readKeyBackup = readPrivateBackup, reducedMotion = false, theme, setTheme }: AppProps & { theme: Theme; setTheme: (theme: Theme) => void }) { + const c = useTheme(); + const selection = { backgroundColor: c.panel, focusedBackgroundColor: c.panel, textColor: c.muted, focusedTextColor: c.text, selectedBackgroundColor: c.elevated, selectedTextColor: c.accent, showDescription: false }; + const renderer = useRenderer(); + const { width, height } = useTerminalDimensions(); + const [screen, setScreen] = useState("loading"); + const screenRef = useRef(screen); screenRef.current = screen; + const [clientId, setClientId] = useState(initialClientId); + const [device, setDevice] = useState(null); + const openingBrowser = useRef(false); + const [actor, setActor] = useState(null); + const [rooms, setRooms] = useState([]); + const [room, setRoom] = useState(null); + const [removeId, setRemoveId] = useState(""); + const hiddenRooms = useRef(new Set()); + const [securePolicy, setSecurePolicy] = useState(false); + const [secureKey, setSecureKey] = useState(null); + const [secureBackup, setSecureBackup] = useState(false); + const [secureRooms, setSecureRooms] = useState(new Set()); + const driver = audio ?? voiceDriver(); + const [history, setHistory] = useState(); + const calls = useRef(null); + const [callView, setCallView] = useState(null); + const [callLevels, setCallLevels] = useState({ local: 0, remote: 0 }); + const callTarget = useRef(null); + const [name, setName] = useState(""); + const [draft, setDraft] = useState(""); + const [composerRows, setComposerRows] = useState(1); + const [reply, setReply] = useState(null); + const [replyFocusRequest, setReplyFocusRequest] = useState(0); + const replies = useRef(new Map()); + const [repoInput, setRepoInput] = useState(""); + const [commandInput, setCommandInput] = useState(""); + const [pickerIndex, setPickerIndex] = useState(0); + const [inviteLogin, setInviteLogin] = useState(""); + const [inviteUrl, setInviteUrl] = useState(""); + const [invitations, setInvitations] = useState([]); + const [invitation, setInvitation] = useState(null); + const [image, setImage] = useState(null); + const [viewedImage, setViewedImage] = useState<{ room: TerminalRoom; attachment: Attachment } | null>(null); + const viewingImage = useRef(false); viewingImage.current = !!viewedImage; + const [notice, setNotice] = useState(""); + const [noticeIsError, setNoticeIsError] = useState(false); + const [busy, setBusy] = useState(false); + const [sending, setSending] = useState(false); + const [slashIndex, setSlashIndex] = useState(0); + const [slashDismissed, setSlashDismissed] = useState(false); + const themeBefore = useRef(theme); + const themesReturn = useRef("choose"); + const [focus, setFocus] = useState("composer"); + const [titles, setTitles] = useState>({}); + const [peers, setPeers] = useState>({}); + const [previews, setPreviews] = useState>({}); + const [roomBranches, setRoomBranches] = useState>({}); + const [sidebarIndex, setSidebarIndex] = useState(0); + const sidebar = useRef(null); + const timeline = useRef(null); + const service = useRef(null); + const viewer = useRef(null); + const savedCredential = useRef(false); + const alive = useRef(true), active = useRef(true), working = useRef(false); + const authorization = useRef(null); + const lifetime = useRef(new AbortController()); + const historyRequest = useRef(null); + const historyRef = useRef(undefined); + const roomRef = useRef(null); + const histories = useRef(new Map()); + const roomCache = useRef(new Map()); + const navigation = useRef(0); + const attaching = useRef(false); + const drafts = useRef(new Map()); + const draftRef = useRef(""); + const pollCooldown = useRef(0); + useEffect(() => { + if (!process.connected || !process.send) return; + let previous = ""; + const publish = () => { + const targets = screenRef.current === "chat" && !viewingImage.current ? messageCopyTargets(renderer, historyRef.current?.messages ?? [], terminalText) : []; + const serialized = JSON.stringify(targets); + if (serialized !== previous && process.connected) { previous = serialized; process.send?.({ type: "gitmsg:copy-targets", targets }); } + }; + renderer.addPostProcessFn(publish); + return () => { renderer.removePostProcessFn(publish); if (process.connected) process.send?.({ type: "gitmsg:copy-targets", targets: [] }); }; + }, [renderer]); + const roomKeyId = (target: TerminalRoom) => `${target.id.toLowerCase()}:${target.branch}`; + const hiddenSlot = (account: number) => ({ service: "fun.gitmsg.terminal.ui", name: `${account}:hidden-chats` }); + async function rememberHidden() { + if (!viewer.current) return; + try { await vault.set({ ...hiddenSlot(viewer.current.id), value: JSON.stringify([...hiddenRooms.current]), persist: "local" }); } + catch { setNotice("Chat list changed for this session only · local storage unavailable."); } + } + function requestRemove(id: string) { if (!working.current) { setRemoveId(id); setScreen("remove"); } } + async function removeChat() { + const id = removeId; + hiddenRooms.current.add(id.toLowerCase()); + const remaining = rooms.filter(room => room.toLowerCase() !== id.toLowerCase()); + setRooms(remaining); setSidebarIndex(0); + if (roomRef.current?.id.toLowerCase() === id.toLowerCase()) { + navigation.current++; historyRequest.current?.abort(); historyRequest.current = null; + if (remaining[0]) await open(remaining[0]); + else { roomRef.current = null; historyRef.current = undefined; setRoom(null); setHistory(undefined); setReply(null); setScreen("choose"); } + } else back(); + await rememberHidden(); + } + function showVoice() { + if (!roomRef.current?.canWrite || working.current || calls.current?.busy) return; + setNotice(""); setScreen("voice"); + } + async function sendVoice(voice: LocalVoice) { + if (working.current || !service.current || !roomRef.current || !actor) return; + working.current = true; setBusy(true); + const target = roomRef.current; + try { + const attachment = await service.current.uploadVoice(target, voice, true, historyRef.current); + await service.current.send(target, actor, "", historyRef.current, [attachment], reply?.id); + setReplyTarget(null); setScreen("chat"); setNotice("Voice sent"); + try { await refresh(target, true); } catch { errorNotice(new ClientError("Voice sent, but refresh failed. Do not resend.")); } + } finally { working.current = false; if (alive.current) setBusy(false); } + } + function errorNotice(error: unknown) { if (alive.current) { setNoticeIsError(true); setNotice(publicError(error)); } } + async function openLogin() { + if (openingBrowser.current) return; + openingBrowser.current = true; + try { await openBrowser(); } catch (error) { errorNotice(error); } + finally { openingBrowser.current = false; } + } + async function copy(value: string, inline = false) { + try { + const result = await (copyText ? copyText(value) : writeClipboard(value, renderer)); + if (alive.current && !inline) { setNoticeIsError(false); setNotice(result === "copied" ? "Copied" : "Copy requested · check your clipboard"); } + return result; + } catch (error) { if (!inline) errorNotice(error); return "failed" as const; } + } + function setReplyTarget(message: Message | null) { + if (!roomRef.current) return; + const key = roomKeyId(roomRef.current); + if (message) replies.current.set(key, message); else replies.current.delete(key); + setReply(message); + setFocus("composer"); + // The same target can be clicked twice; native mouse focus still changes. + setReplyFocusRequest(value => value + 1); + } + function updateDraft(value: string) { + setSlashIndex(0); setSlashDismissed(false); + draftRef.current = value; setDraft(value); + if (roomRef.current) drafts.current.set(roomKeyId(roomRef.current), value); + } + function updateCommand(value: string) { setCommandInput(value); setSlashIndex(0); setSlashDismissed(false); } + const slashValue = screen === "chat" && focus === "composer" ? draft : screen === "choose" ? commandInput : ""; + const suggestions = commandSuggestions(slashValue); + const showCommands = !busy && !slashDismissed && suggestions.length > 0; + function completeCommand(usage: string) { + const value = usage.split(" ")[0] + (usage.includes(" ") ? " " : ""); + if (screen === "chat") updateDraft(value); else updateCommand(value); + setSlashDismissed(true); + } + async function refresh(target = roomRef.current, force = false) { + if (!target || !service.current) return; + const source = service.current; + if (historyRequest.current) { if (!force) return; historyRequest.current.abort(); } + const controller = new AbortController(); historyRequest.current = controller; + try { + const next = await source.history(target, force ? undefined : histories.current.get(roomKeyId(target)), controller.signal); + if (controller.signal.aborted || !alive.current || service.current !== source) return; + histories.current.set(roomKeyId(target), next); + void calls.current?.observe(target, next.events); + const last = next.messages.at(-1); + if (last) setPreviews(value => ({ ...value, [target.id]: last.locked ? "Encrypted message" : terminalText(last.text || (last.attachments?.length ? "Image attachment" : "Message"), 30).replace(/\s+/g, " ") })); + if (roomRef.current && roomKeyId(roomRef.current) === roomKeyId(target)) { historyRef.current = next; setHistory(next); } + } finally { if (historyRequest.current === controller) historyRequest.current = null; } + } + async function open(input: string, nextFocus: Focus = "composer") { + if (!service.current) return; + const source = service.current; + const id = roomLink(input), request = ++navigation.current; + // Previously validated metadata is a UI cache only. Every write still validates + // repository visibility, write access, branch and encryption against GitHub. + const next = roomCache.current.get(id.toLowerCase()) ?? await source.open(id); + if (!alive.current || request !== navigation.current || service.current !== source) return; + roomCache.current.set(next.id.toLowerCase(), next); + if (hiddenRooms.current.delete(next.id.toLowerCase())) void rememberHidden(); + renderer.clearSelection(); + if (roomRef.current) drafts.current.set(roomKeyId(roomRef.current), draftRef.current); + historyRequest.current?.abort(); historyRequest.current = null; + const previous = histories.current.get(roomKeyId(next)); + historyRef.current = previous; roomRef.current = next; + setHistory(previous); setRoom(next); updateDraft(drafts.current.get(roomKeyId(next)) ?? ""); + setReply(replies.current.get(roomKeyId(next)) ?? null); + setTitles(value => ({ ...value, [next.id]: next.title })); + setRoomBranches(value => ({ ...value, [next.id]: next.branch })); + const peer = next.participants?.find(login => login.toLowerCase() !== viewer.current?.login.toLowerCase()); + if (peer) setPeers(value => ({ ...value, [next.id]: peer })); + setRooms(value => value.includes(next.id) ? value : [...value, next.id]); + setSidebarIndex(Math.max(0, rooms.indexOf(next.id))); + setFocus(nextFocus); setScreen("chat"); setNotice(""); + // Never disable the input or block another selection on history I/O. + void refresh(next).catch(error => { if (request === navigation.current) errorNotice(error); }); + } + async function connected(token: string) { + const next = createRooms ? createRooms(token) : new Rooms(new GitHub(token, fetch, lifetime.current.signal), roomKey); + const user = await next.user(); + if (!alive.current) return; + service.current = next; viewer.current = user; setActor(user); setScreen("choose"); + next.setKeyLoader(async target => await readRoomKey(vault, user.id, target) ?? await readKeyBackup(user.id, target)); + calls.current?.dispose(); + calls.current = new TerminalCalls(next, user, view => { + if (!alive.current) return; + setCallView(view); + if (view?.phase === "incoming" && screenRef.current !== "voice") setScreen("call"); + }, value => { if (alive.current) setCallLevels(value); }, callDevice); + try { + try { + const raw = await vault.get(hiddenSlot(user.id)), ids: unknown = raw ? JSON.parse(raw) : []; + if (Array.isArray(ids)) hiddenRooms.current = new Set(ids.filter((id): id is string => typeof id === "string" && /^[a-z0-9-]+\/[a-z0-9_.-]+$/.test(id)).slice(0, 200)); + } catch { /* An unavailable keychain must not block session-only sign-in. */ } + const list = (await next.list()).filter(id => !hiddenRooms.current.has(id.toLowerCase())); + if (!alive.current || service.current !== next) return; + setRooms(list); + // Bounded read-only decoration; don't expose raw repository IDs while it loads. + void (async () => { + for (let start = 0; start < Math.min(24, list.length) && alive.current && service.current === next; start += 3) { + await Promise.allSettled(list.slice(start, start + 3).map(async id => { + const metadata = await next.open(id); + if (!alive.current || service.current !== next) return; + roomCache.current.set(id.toLowerCase(), metadata); + setTitles(value => ({ ...value, [id]: metadata.title })); + const peer = metadata.participants?.find(login => login.toLowerCase() !== user.login.toLowerCase()); + if (peer) setPeers(value => ({ ...value, [id]: peer })); + })); + } + })(); + } catch (error) { errorNotice(error); } + if (initialRepo && alive.current && service.current === next) { + try { await open(initialRepo); } + catch (error) { + if (error instanceof ClientError && error.status === 404) { try { await runCommand(`/join ${initialRepo}`); } catch (joinError) { errorNotice(joinError); } } + else errorNotice(error); + } + } + } + async function task(run: () => Promise) { + if (working.current) return; + working.current = true; setBusy(true); setNotice(""); setNoticeIsError(false); + try { await run(); } catch (error) { + if (error instanceof ClientError) pollCooldown.current = Math.max(pollCooldown.current, Date.now() + error.retryAfterMs); + errorNotice(error); + } finally { working.current = false; if (alive.current) setBusy(false); } + } + useEffect(() => { + alive.current = true; + void (async () => { + try { + if (initialToken) { await connected(initialToken); return; } + let credential; + try { credential = await readCredential(vault); } + catch { setNotice("Keychain unavailable · sign-in will last for this session only."); } + if (!alive.current) return; + if (credential) { savedCredential.current = true; setClientId(credential.clientId); await connected(credential.token); } + else setScreen(initialClientId ? "signin" : "client"); + } catch (error) { if (alive.current) { setScreen(initialClientId ? "signin" : "client"); errorNotice(error); } } + })(); + return () => { alive.current = false; calls.current?.dispose(); authorization.current?.abort(); historyRequest.current?.abort(); lifetime.current.abort(); }; + }, []); + useEffect(() => { + if (!notice || noticeIsError || busy) return; + const timer = setTimeout(() => setNotice(""), 8000); + return () => clearTimeout(timer); + }, [notice, noticeIsError, busy]); + useFocus(() => { active.current = true; }); + useBlur(() => { active.current = false; }); + useEffect(() => { + if (screen !== "chat" && screen !== "call" && !calls.current?.busy) return; + let stopped = false, failures = 0; + let timer: ReturnType; + const poll = async () => { + if (stopped) return; + try { if (Date.now() >= pollCooldown.current) { await refresh(); const calling = calls.current?.activeRoom; if (calling && calling.id !== roomRef.current?.id) await refresh(calling); } failures = 0; } + catch (error) { + if (!stopped) { failures++; errorNotice(error); } + if (error instanceof ClientError) pollCooldown.current = Date.now() + error.retryAfterMs; + } + if (!stopped) timer = setTimeout(poll, Math.max(calls.current?.busy ? 3000 : active.current ? 5000 : 60000, Math.min(60000, (calls.current?.busy ? 3000 : 5000) * 2 ** failures), pollCooldown.current - Date.now())); + }; + timer = setTimeout(poll, 5000); + return () => { stopped = true; clearTimeout(timer); }; + }, [screen, room?.id, room?.branch, !!callView && callView.phase !== "finished"]); + useEffect(() => { + if (screen === "chat" && focus === "sidebar") sidebar.current?.scrollChildIntoView(`sidebar-row-${sidebarIndex}`, { align: "nearest" }); + }, [sidebarIndex, focus, screen]); + useEffect(() => { + // Mouse focus may move into the timeline before a Reply click is handled. + // Reassert editor focus even when the React focus value was already composer. + if (screen === "chat" && focus === "composer" && !viewedImage) (renderer.root.findDescendantById("composer") as TextareaRenderable | undefined)?.focus(); + }, [replyFocusRequest, focus, screen, viewedImage]); + useEffect(() => { if (width < 90 && focus === "sidebar") setScreen("choose"); }, [width]); + function focusSidebar() { + setSidebarIndex(Math.max(0, rooms.indexOf(roomRef.current?.id ?? ""))); + if (width < 90) { setPickerIndex(Math.max(0, rooms.indexOf(roomRef.current?.id ?? ""))); setScreen("choose"); } + else setFocus("sidebar"); + } + function showInvite() { if (!working.current && roomRef.current) { setInviteLogin(""); setScreen("invite"); } } + function back() { if (screenRef.current === "image") setImage(null); setScreen(roomRef.current ? "chat" : actor ? "choose" : initialClientId ? "signin" : "client"); setNotice(""); setFocus("composer"); } + function selectRoom(id: string, nextFocus: Focus = "composer") { + const request = navigation.current + 1; + void open(id, nextFocus).catch(error => { if (request === navigation.current) errorNotice(error); }); + } + function stageImage(preview: LocalImage) { + if (screenRef.current !== "chat" || !roomRef.current || working.current || viewingImage.current) throw new ClientError("Open a chat and finish the current action before attaching an image."); + if (!roomRef.current.canWrite) throw new ClientError("This conversation is read-only."); + checkImage(preview.bytes); setImage(preview); setScreen("image"); + } + async function attach(read: () => Promise) { + const target = roomRef.current, request = navigation.current; + if (!target || working.current || attaching.current || screenRef.current !== "chat") return; + attaching.current = true; + try { + const preview = await read(); + if (!alive.current) return; + if (roomRef.current !== target || request !== navigation.current) throw new ClientError("Conversation changed. Paste the image again in the intended chat."); + stageImage(preview); + } catch (error) { errorNotice(error); } + finally { attaching.current = false; } + } + useEffect(() => receiveImages(preview => { try { stageImage(preview); } catch (error) { errorNotice(error); } }, errorNotice), [receiveImages]); + usePaste(event => { + if (screen !== "chat" || focus !== "composer" || working.current || viewedImage) return; + const path = pastedImagePath(new TextDecoder().decode(event.bytes)); + if (!path) return; + event.preventDefault(); + void attach(() => readLocalImage(path)); + }); + useKeyboard(key => { + const copyShortcut = key.name === "c" && (key.ctrl || key.meta || key.super); + if (copyShortcut) { + const editor = renderer.root.findDescendantById("composer") as TextareaRenderable | undefined; + const selected = renderer.getSelection()?.getSelectedText() || (editor?.hasSelection() ? editor.getSelectedText() : ""); + if (selected || key.shift || key.meta || key.super) { key.preventDefault(); if (selected) void copy(selected); return; } + if (key.ctrl) { key.preventDefault(); alive.current = false; calls.current?.dispose(); authorization.current?.abort(); historyRequest.current?.abort(); lifetime.current.abort(); renderer.destroy(); return; } + } + if (viewedImage) { + key.preventDefault(); + if (key.name === "escape" || key.name === "return") setViewedImage(null); + return; + } + if (screen === "call") { + key.preventDefault(); + if (key.name === "h") { void calls.current?.end().catch(errorNotice); if (!callView) back(); } + if (key.name === "m") calls.current?.mute(); + if (key.name === "a" && callView?.phase === "incoming") void calls.current?.accept().catch(errorNotice); + if (key.name === "escape") { if (!callView) void calls.current?.end().catch(errorNotice); if (callView?.phase === "finished") calls.current?.dismiss(); back(); } + return; + } + if (screen === "device" && key.name === "return") { key.preventDefault(); void openLogin(); return; } + if (screen === "voice") { + if (key.name === "escape" && !working.current) { key.preventDefault(); back(); } + return; + } + if (screen === "themes") { + if (["up", "down", "return", "escape"].includes(key.name)) { + key.preventDefault(); + if (key.name === "escape") { setTheme(themeBefore.current); setScreen(themesReturn.current); } + else if (key.name === "return") { setScreen(themesReturn.current); } + else setTheme(THEMES[(THEMES.indexOf(theme) + (key.name === "down" ? 1 : -1) + THEMES.length) % THEMES.length]); + return; + } + } + if (showCommands && ["up", "down", "tab", "return", "escape"].includes(key.name)) { + if (key.name === "return" && suggestions.some(([usage]) => usage.split(" ")[0] === slashValue)) { /* An exact command runs normally. */ } + else { + key.preventDefault(); + if (key.name === "escape") setSlashDismissed(true); + else if (key.name === "tab" || key.name === "return") completeCommand(suggestions[Math.min(slashIndex, suggestions.length - 1)][0]); + else setSlashIndex(value => (value + (key.name === "down" ? 1 : -1) + suggestions.length) % suggestions.length); + return; + } + } + if (key.name === "escape") { + key.preventDefault(); + if (screen === "device") { authorization.current?.abort(); return; } + if (!working.current) { + if (screen === "chat") { + if (reply && focus === "composer") { setReplyTarget(null); return; } + if (focus === "composer" || focus === "invite") setFocus("history"); + else if (focus === "history") focusSidebar(); + else { setScreen("choose"); setCommandInput(""); } + } else back(); + } + return; + } + if (screen === "chat" && !busy) { + if (key.ctrl && key.name === "v") { + key.preventDefault(); + if (renderer.capabilities?.remote && readClipboardImage === clipboardImage) errorNotice(new ClientError("Use your terminal's image paste, drop a file, or /attach. The remote host clipboard is not read.")); + else void attach(readClipboardImage); + return; + } + if (key.ctrl && key.name === "g") { key.preventDefault(); showInvite(); return; } + if (key.name === "tab") { + key.preventDefault(); + const order: Focus[] = width >= 90 ? ["sidebar", "history", "invite", "composer"] : ["history", "invite", "composer"]; + setFocus(order[(order.indexOf(focus) + (key.shift ? -1 : 1) + order.length) % order.length]); return; + } + if (focus === "sidebar") { + if (["delete", "backspace", "x"].includes(key.name) && rooms[sidebarIndex]) { key.preventDefault(); requestRemove(rooms[sidebarIndex]); return; } + if (["up", "down", "home", "end"].includes(key.name)) { + key.preventDefault(); setSidebarIndex(value => key.name === "home" ? 0 : key.name === "end" ? rooms.length + 2 : Math.max(0, Math.min(rooms.length + 2, value + (key.name === "down" ? 1 : -1)))); return; + } + if (key.name === "return") { key.preventDefault(); choose(String(options[sidebarIndex]?.value ?? room?.id)); return; } + if (key.name === "right") { + key.preventDefault(); + const id = rooms[sidebarIndex]; + if (id && id !== roomRef.current?.id) selectRoom(id, "composer"); + else setFocus("composer"); + return; + } + } else if (focus === "history") { + if (key.name === "left") { key.preventDefault(); focusSidebar(); return; } + if (key.name === "right") { key.preventDefault(); setFocus("composer"); return; } + if (key.name === "return" || key.name === "down" && timeline.current && timeline.current.scrollTop >= timeline.current.scrollHeight - timeline.current.viewport.height) { key.preventDefault(); setFocus("composer"); return; } + } else if (focus === "invite") { + if (key.name === "return") { key.preventDefault(); showInvite(); return; } + if (key.name === "left") { key.preventDefault(); setFocus("history"); return; } + if (key.name === "down") { key.preventDefault(); setFocus("composer"); return; } + } else if (focus === "composer") { + if (key.name === "up" && !key.shift && !key.ctrl && !key.meta) { + const editor = renderer.root.findDescendantById("composer") as TextareaRenderable | undefined; + if (editor && editor.scrollY + editor.visualCursor.visualRow === 0) { key.preventDefault(); setFocus("history"); return; } + } + if (key.name === "left" && !key.shift && !key.ctrl && (!draftRef.current || (renderer.root.findDescendantById("composer") as TextareaRenderable | undefined)?.cursorOffset === 0)) { key.preventDefault(); focusSidebar(); return; } + if (key.meta && key.name === "left") { key.preventDefault(); focusSidebar(); return; } + } + } + if (actor && key.ctrl && key.name === "k" && !working.current) { key.preventDefault(); setPickerIndex(Math.max(0, rooms.indexOf(roomRef.current?.id ?? ""))); setScreen("choose"); setCommandInput(""); } + if (screen === "choose" && !commandInput && ["up", "down"].includes(key.name) && !busy) { + key.preventDefault(); setPickerIndex(value => (value + (key.name === "down" ? 1 : -1) + rooms.length + 3) % (rooms.length + 3)); + } + if (screen === "chat" && key.ctrl && key.name === "r") { key.preventDefault(); void task(async () => { if (Date.now() < pollCooldown.current) throw new ClientError("GitHub cooldown is active. Please wait."); await refresh(); }); } + }); + async function authorize() { + await task(async () => { + const controller = new AbortController(); authorization.current = controller; + const code = await requestDeviceCode(clientId.trim(), { signal: controller.signal }); + if (!alive.current) return; + setDevice(code); setScreen("device"); + try { + const credential = await waitForAuthorization(clientId.trim(), code, { signal: controller.signal }); + if (!alive.current || controller.signal.aborted) return; + await connected(credential.token); + if (!alive.current || controller.signal.aborted) return; + try { await saveCredential(vault, credential); savedCredential.current = true; } catch { setNotice("Signed in for this session · OS keychain unavailable."); } + } catch (error) { if (alive.current) setScreen(initialClientId ? "signin" : "client"); throw error; } + finally { if (alive.current) setDevice(null); } + }); + } + async function inbox() { const values = await service.current!.invitations(); if (alive.current) { setInvitations(values); setScreen("inbox"); } } + async function runCommand(value: string) { + const parsed = command(value); + if (!parsed) return false; + const { name: action, argument } = parsed; + if (action === "help") setScreen("help"); + else if (action === "themes") { themeBefore.current = theme; themesReturn.current = screen; setScreen("themes"); } + else if (!actor) throw new ClientError("Sign in before using this command."); + else if (action === "chats") { setRooms(current => [...new Set([...current])]); setScreen("choose"); } + else if (action === "new") { setName(argument); setScreen(argument ? "confirm" : "name"); } + else if (action === "join") { + if (!argument) setScreen("join"); + else { + const id = roomLink(argument); + const pending = (await service.current!.invitations()).find(i => i.repo.toLowerCase() === id.toLowerCase()); + if (pending) { setInvitation(pending); setScreen("accept"); } else await open(id); + } + } else if (action === "inbox") await inbox(); + else if (action === "logout") setScreen("logout"); + else if (action === "refresh") { if (Date.now() < pollCooldown.current) throw new ClientError("GitHub cooldown is active. Please wait."); await refresh(); } + else if (action === "invite") { + if (!roomRef.current) throw new ClientError("Open a chat before inviting a friend."); + const login = argument.replace(/^@/, ""); setInviteLogin(login); setScreen(login ? "inviteConfirm" : "invite"); + } else if (action === "attach") { + if (!roomRef.current) throw new ClientError("Open a chat before attaching an image."); + const preview = await readLocalImage(argument); checkImage(preview.bytes); setImage(preview); setScreen("image"); + } else if (action === "voice") { + if (!roomRef.current?.canWrite) throw new ClientError("Open a writable chat before recording."); + if (calls.current?.busy) throw new ClientError("End the call before recording a voice message."); + setScreen("voice"); + } else if (action === "call") { + if (!roomRef.current) throw new ClientError("Open a private direct chat before calling."); + if (calls.current?.busy) { setScreen("call"); return true; } + await service.current!.callRoom(roomRef.current, actor!); + callTarget.current = roomRef.current; setScreen("callConfirm"); + } else if (action === "hangup") { + await calls.current?.end(); + } else if (action === "secure") { + const target = roomRef.current; + if (!target || !service.current) throw new ClientError("Open a chat before enabling encryption."); + const policy = await service.current.policy(target); + let key = await service.current.roomKey(target); + let backup = !!roomKey || !!await readKeyBackup(actor!.id, target); + if (argument.startsWith("import ")) { + key = await loadRoomKey(argument.slice(7).trim()); + if (!key) throw new ClientError("Choose a valid key backup."); + if (policy.enabled && await keyFingerprint(key) !== policy.keyId) throw new ClientError("This key does not match the chat. Nothing was changed."); + try { await saveRoomKey(vault, actor!.id, target, key); } catch { /* Explicit owner-only backup remains the durable source. */ } + service.current.setRoomKey(target, key); backup = true; + await refresh(target, true); + } else if (argument) throw new ClientError("Use /secure or /secure import /absolute/key-file. Never paste a raw key into the composer."); + if (policy.enabled && key && await keyFingerprint(key) !== policy.keyId) key = null; + setSecurePolicy(policy.enabled); setSecureKey(key); setSecureBackup(backup); setScreen("secure"); + if (policy.enabled) setSecureRooms(value => new Set([...value, roomKeyId(target)])); + } + return true; + } + async function submit(value: string) { + if (!value.trim()) return; + await task(async () => { + const origin = screen === "chat" && roomRef.current ? roomKeyId(roomRef.current) : null; + if (await runCommand(value)) { + if (origin) drafts.current.set(origin, ""); + if (origin && roomRef.current && roomKeyId(roomRef.current) === origin) updateDraft(""); + setCommandInput(""); return; + } + if (!roomRef.current || !actor || !service.current) throw new ClientError("Choose a chat first, or type /help."); + const current = roomRef.current; + setSending(true); + try { + const result = await service.current.send(current, actor, value.startsWith("//") ? value.slice(1) : value, historyRef.current, [], reply?.id); + if (!alive.current) return; + updateDraft(""); setReplyTarget(null); setNotice(result.sha === "already-confirmed" ? "Sent · confirmed, no duplicate" : "Sent"); + try { await refresh(current, true); } catch { throw new ClientError("Sent, but refresh failed. Use /refresh; do not resend."); } + } finally { if (alive.current) setSending(false); } + }); + } + const choose = (value: string) => { + if (busy) return; + setCommandInput(""); + if (value === "+new") { setName(""); setScreen("name"); } + else if (value === "+join") setScreen("join"); + else if (value === "+inbox") void task(inbox); + else selectRoom(value); + }; + const label = (id: string) => { + const name = conversationName(titles[id], peers[id]); + return name === "Conversation" && rooms.length > 1 ? `Conversation ${rooms.indexOf(id) + 1}` : name; + }; + const options = [ + ...rooms.map(id => ({ name: `${room?.id === id ? "● " : " "}${label(id)}`, description: "", value: id })), + { name: "+ New chat", description: "", value: "+new" }, { name: "↗ Join chat", description: "", value: "+join" }, { name: "↓ Invitations", description: "", value: "+inbox" }, + ]; + const panelWidth = Math.max(24, Math.min(76, width - 6)); + const composerWidth = Math.max(1, width - (width >= 90 ? 33 : 2) - 6); + const maxComposerRows = height < 26 ? 3 : 5; + const visibleComposerRows = Math.min(composerRows, maxComposerRows); + const autoImages = new Set(history?.messages.flatMap(message => message.locked ? [] : (message.attachments ?? []).filter(a => a.mime.startsWith("image/"))).slice(-4).map(a => a.id)); + const inputBox = { height: 3, flexShrink: 0, border: ["bottom"] as ("bottom")[], borderColor: c.accent, backgroundColor: c.panel, paddingX: 1 }; + const confirm = (label: string, onConfirm: () => Promise, cancel = back, primaryFirst = false) => { + const options = [{ name: "Cancel", description: "", value: false }, { name: label, description: "", value: true }]; + return { if (option?.value === "copy" && secureKey) void task(async () => { await copy(await exportKey(secureKey)); }); else back(); }} /> + : <> + {`Optional unencrypted owner-only backup (0600): ${privateBackupPath(actor!.id, roomRef.current!)}`} + { if (busy) return; if (option?.value === "custom") setScreen("client"); else void authorize(); }} /> + } + {screen === "client" && <> + Public Client ID · Device Flow must be enabled. + Requests repo + read:user. Never enter a token or Client Secret. + void authorize()} focused={!busy} placeholder="Public client ID" maxLength={100} /> + } + {screen === "device" && device && <> + { event.stopPropagation(); void openLogin(); }}>{GITHUB_DEVICE_URL} ↗{device.user_code} + Check the app name and permissions, then enter this code.Waiting for approval… + } + {screen === "choose" && <> + { + if (option?.value === "copy") void copy(inviteUrl); + else if (option?.value === "another") showInvite(); + else back(); + }} /> + } + {screen === "inbox" && <> + {!invitations.length ? No pending chat invitations. :