clauderipple 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +229 -0
  2. package/LICENSE +674 -0
  3. package/README.ko.md +328 -0
  4. package/README.md +372 -0
  5. package/bin/clauderipple.js +12 -0
  6. package/dist/app/assets/trayDownTemplate.png +0 -0
  7. package/dist/app/assets/trayDownTemplate@2x.png +0 -0
  8. package/dist/app/assets/trayTemplate.png +0 -0
  9. package/dist/app/assets/trayTemplate@2x.png +0 -0
  10. package/dist/app/assets/trayWarnTemplate.png +0 -0
  11. package/dist/app/assets/trayWarnTemplate@2x.png +0 -0
  12. package/dist/app/assets/trayWin.png +0 -0
  13. package/dist/app/assets/trayWin@2x.png +0 -0
  14. package/dist/app/assets/trayWinDown.png +0 -0
  15. package/dist/app/assets/trayWinDown@2x.png +0 -0
  16. package/dist/app/assets/trayWinWarn.png +0 -0
  17. package/dist/app/assets/trayWinWarn@2x.png +0 -0
  18. package/dist/app/dist/main.js +518 -0
  19. package/dist/cli/src/browser.js +21 -0
  20. package/dist/cli/src/bundle.js +51 -0
  21. package/dist/cli/src/certs.js +33 -0
  22. package/dist/cli/src/claude-auth.js +112 -0
  23. package/dist/cli/src/codex.js +172 -0
  24. package/dist/cli/src/gen-certs.js +7 -0
  25. package/dist/cli/src/hooks/agent-title.js +160 -0
  26. package/dist/cli/src/index.js +489 -0
  27. package/dist/cli/src/launchd.js +183 -0
  28. package/dist/cli/src/picker.js +166 -0
  29. package/dist/cli/src/probe.js +55 -0
  30. package/dist/cli/src/runtime.js +62 -0
  31. package/dist/cli/src/schtasks.js +134 -0
  32. package/dist/cli/src/settings.js +142 -0
  33. package/dist/cli/src/supervisor.js +100 -0
  34. package/dist/cli/src/tray.js +85 -0
  35. package/dist/router/src/admin.js +945 -0
  36. package/dist/router/src/bootstrap.js +80 -0
  37. package/dist/router/src/certs.js +65 -0
  38. package/dist/router/src/compat.js +172 -0
  39. package/dist/router/src/config.js +179 -0
  40. package/dist/router/src/health.js +45 -0
  41. package/dist/router/src/identity.js +51 -0
  42. package/dist/router/src/index.js +144 -0
  43. package/dist/router/src/ingress/models.js +29 -0
  44. package/dist/router/src/ingress/server.js +400 -0
  45. package/dist/router/src/ingress/translate.js +457 -0
  46. package/dist/router/src/log.js +81 -0
  47. package/dist/router/src/picker.js +74 -0
  48. package/dist/router/src/presets.js +267 -0
  49. package/dist/router/src/providers/anthropic-observed.js +88 -0
  50. package/dist/router/src/providers/anthropic-token-file.js +48 -0
  51. package/dist/router/src/providers/anthropic.js +203 -0
  52. package/dist/router/src/providers/chatgpt/auth.js +226 -0
  53. package/dist/router/src/providers/chatgpt/index.js +274 -0
  54. package/dist/router/src/providers/chatgpt/sse.js +28 -0
  55. package/dist/router/src/providers/chatgpt/translate.js +393 -0
  56. package/dist/router/src/providers/claude-oauth.js +252 -0
  57. package/dist/router/src/providers/openai/index.js +193 -0
  58. package/dist/router/src/providers/openai/translate.js +504 -0
  59. package/dist/router/src/proxy.js +724 -0
  60. package/dist/router/src/redact.js +43 -0
  61. package/dist/router/src/requestlog.js +346 -0
  62. package/dist/router/src/routing.js +113 -0
  63. package/dist/router/src/version.js +8 -0
  64. package/dist/router/src/x509.js +203 -0
  65. package/dist/ui/app.js +1228 -0
  66. package/dist/ui/i18n.js +95 -0
  67. package/dist/ui/index.html +104 -0
  68. package/dist/ui/presets-fallback.js +61 -0
  69. package/dist/ui/style.css +347 -0
  70. package/docs/ARCHITECTURE.md +441 -0
  71. package/package.json +66 -0
@@ -0,0 +1,85 @@
1
+ // The menu-bar / tray app, started from the CLI.
2
+ //
3
+ // Installed from npm there is no application bundle to double-click. Electron supplies the tray,
4
+ // and npm fetches the binary already built for this platform — but it is 270MB, which is not
5
+ // something to hand every person who only wants the router. So it is not a dependency: the tray
6
+ // command fetches it on request, once. Inside a packaged app the bundle is the Electron binary,
7
+ // so the same command simply relaunches it.
8
+ import { createRequire } from "node:module";
9
+ import { spawn, spawnSync } from "node:child_process";
10
+ import fs from "node:fs";
11
+ import path from "node:path";
12
+ import { runtime } from "./runtime.js";
13
+ /** Electron version to fetch on request. Kept in step with the one the app is developed against. */
14
+ const ELECTRON_RANGE = "^38.1.0";
15
+ /** The Electron executable installed alongside us, or null when the optional dependency is absent. */
16
+ export function electronPath() {
17
+ try {
18
+ const require = createRequire(import.meta.url);
19
+ // The electron package exports the path to its binary as its module value.
20
+ const value = require("electron");
21
+ return typeof value === "string" && fs.existsSync(value) ? value : null;
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ /**
28
+ * Starts the tray and returns immediately. `detached` outlives this process, which is what a
29
+ * command typed in a terminal wants; the supervisor uses the foreground form instead.
30
+ */
31
+ export function startTray(options = {}) {
32
+ const current = runtime();
33
+ if (current.packaged) {
34
+ // The packaged app IS the tray: relaunching its own binary with no script is what opens it.
35
+ const child = spawn(current.node, [], { detached: true, stdio: "ignore" });
36
+ child.unref();
37
+ return { ok: true, message: "✓ tray started" };
38
+ }
39
+ const electron = electronPath();
40
+ if (!electron) {
41
+ return {
42
+ ok: false,
43
+ message: "the tray needs Electron, which is about 270MB and is not installed by default.\nFetch it once with: clauderipple tray --install",
44
+ };
45
+ }
46
+ const main = current.trayMain;
47
+ if (!fs.existsSync(main)) {
48
+ return { ok: false, message: `the tray is not built: ${main} is missing (run: npm run build)` };
49
+ }
50
+ const child = spawn(electron, [main], {
51
+ detached: options.detached ?? true,
52
+ stdio: "ignore",
53
+ // Electron would otherwise re-enter as a plain Node process, since that is how the CLI runs.
54
+ env: { ...process.env, ELECTRON_RUN_AS_NODE: "" },
55
+ });
56
+ if (options.detached ?? true)
57
+ child.unref();
58
+ return { ok: true, message: "✓ tray started" };
59
+ }
60
+ /** The npm that came with the Node running us, as a script we can hand to that same Node. */
61
+ function npmCli() {
62
+ const candidates = [
63
+ path.resolve(path.dirname(process.execPath), "../lib/node_modules/npm/bin/npm-cli.js"),
64
+ path.resolve(path.dirname(process.execPath), "node_modules/npm/bin/npm-cli.js"),
65
+ ];
66
+ return candidates.find((candidate) => fs.existsSync(candidate)) ?? null;
67
+ }
68
+ /** Fetches Electron into this installation so the tray can run. Prints npm's own progress. */
69
+ export function installTrayRuntime() {
70
+ if (electronPath())
71
+ return { ok: true, message: "✓ Electron is already installed" };
72
+ const cli = npmCli();
73
+ if (!cli)
74
+ return { ok: false, message: `found no npm next to ${process.execPath}; install Electron yourself: npm install electron` };
75
+ const target = runtime().repo;
76
+ const result = spawnSync(process.execPath, [cli, "install", "--no-save", "--loglevel", "error", `electron@${ELECTRON_RANGE}`], {
77
+ cwd: target,
78
+ stdio: "inherit",
79
+ });
80
+ if (result.status !== 0)
81
+ return { ok: false, message: `npm could not install Electron into ${target}` };
82
+ return electronPath()
83
+ ? { ok: true, message: "✓ Electron installed — start the tray with: clauderipple tray" }
84
+ : { ok: false, message: `npm reported success but Electron is still not resolvable from ${target}` };
85
+ }