@myrialabs/clopen 0.4.39 → 0.4.40

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 (88) hide show
  1. package/backend/auth/permissions.ts +23 -0
  2. package/backend/database/crypto/secret-columns.ts +5 -1
  3. package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
  4. package/backend/database/migrations/index.ts +7 -0
  5. package/backend/database/queries/index.ts +6 -0
  6. package/backend/database/queries/worktree-branch-queries.ts +331 -0
  7. package/backend/db-client/cloning.test.ts +161 -0
  8. package/backend/db-client/cloning.ts +672 -0
  9. package/backend/db-client/connection-url.test.ts +117 -0
  10. package/backend/db-client/connection-url.ts +126 -0
  11. package/backend/db-client/drivers/mongodb.ts +2 -14
  12. package/backend/db-client/drivers/mysql.ts +2 -8
  13. package/backend/db-client/drivers/postgres.ts +10 -13
  14. package/backend/db-client/drivers/redis.ts +2 -6
  15. package/backend/db-client/env/detect.ts +438 -0
  16. package/backend/db-client/env/diff.ts +94 -0
  17. package/backend/db-client/env/env.test.ts +574 -0
  18. package/backend/db-client/env/index.ts +15 -0
  19. package/backend/db-client/env/naming.ts +202 -0
  20. package/backend/db-client/env/service.ts +487 -0
  21. package/backend/db-client/integrations/index.ts +7 -0
  22. package/backend/db-client/integrations/links.ts +41 -10
  23. package/backend/db-client/providers/neon/adapter.ts +522 -0
  24. package/backend/db-client/providers/neon/api-types.ts +182 -0
  25. package/backend/db-client/providers/neon/client.ts +298 -0
  26. package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
  27. package/backend/db-client/providers/neon/endpoints.ts +314 -0
  28. package/backend/db-client/providers/neon/list.test.ts +181 -0
  29. package/backend/db-client/providers/supabase/adapter.ts +25 -2
  30. package/backend/db-client/providers/types.ts +57 -0
  31. package/backend/env-files/discovery.ts +48 -0
  32. package/backend/env-files/edit.ts +213 -0
  33. package/backend/env-files/env-files.test.ts +515 -0
  34. package/backend/env-files/git.ts +27 -0
  35. package/backend/env-files/index.ts +44 -0
  36. package/backend/env-files/keys.ts +69 -0
  37. package/backend/env-files/parse.ts +157 -0
  38. package/backend/env-files/write.ts +229 -0
  39. package/backend/integrations/health.ts +18 -4
  40. package/backend/integrations/projections/types.ts +9 -2
  41. package/backend/integrations/registry/index.ts +3 -0
  42. package/backend/integrations/registry/providers/context7.ts +1 -0
  43. package/backend/integrations/registry/providers/firecrawl.ts +1 -0
  44. package/backend/integrations/registry/providers/github.ts +1 -0
  45. package/backend/integrations/registry/providers/neon.ts +55 -0
  46. package/backend/integrations/registry/providers/supabase.ts +1 -0
  47. package/backend/integrations/registry/providers/vercel.ts +1 -0
  48. package/backend/integrations/registry/types.ts +2 -0
  49. package/backend/work/start-work.ts +4 -0
  50. package/backend/worktrees/branching/engine.ts +557 -0
  51. package/backend/worktrees/branching/index.ts +56 -0
  52. package/backend/worktrees/branching/naming.test.ts +118 -0
  53. package/backend/worktrees/branching/naming.ts +97 -0
  54. package/backend/worktrees/branching/projector.test.ts +229 -0
  55. package/backend/worktrees/branching/projector.ts +139 -0
  56. package/backend/worktrees/branching/providers/neon.ts +220 -0
  57. package/backend/worktrees/branching/registry.ts +27 -0
  58. package/backend/worktrees/branching/service.ts +620 -0
  59. package/backend/worktrees/branching/suggest.test.ts +154 -0
  60. package/backend/worktrees/branching/suggest.ts +202 -0
  61. package/backend/worktrees/branching/types.ts +88 -0
  62. package/backend/worktrees/index.ts +7 -0
  63. package/backend/worktrees/service.ts +48 -1
  64. package/backend/ws/db-client/env.ts +142 -0
  65. package/backend/ws/db-client/index.ts +2 -0
  66. package/backend/ws/projects/index.ts +6 -1
  67. package/backend/ws/projects/info.ts +70 -6
  68. package/backend/ws/projects/overview.test.ts +108 -0
  69. package/backend/ws/projects/overview.ts +300 -0
  70. package/backend/ws/system/device-info.ts +307 -76
  71. package/backend/ws/worktrees/branching.ts +212 -0
  72. package/backend/ws/worktrees/crud.ts +33 -7
  73. package/backend/ws/worktrees/index.ts +14 -0
  74. package/dist/assets/{index-C8Gi-b6U.js → index-D4igjF6e.js} +1 -1
  75. package/dist/assets/{index-BrF6nqld.js → index-DONNwiXm.js} +1 -1
  76. package/dist/assets/main-BrfXH1bL.js +1205 -0
  77. package/dist/assets/main-CT1PygsW.css +1 -0
  78. package/dist/index.html +2 -2
  79. package/package.json +1 -1
  80. package/shared/constants/tool-icons.ts +6 -2
  81. package/shared/types/db-client/env.ts +192 -0
  82. package/shared/types/db-client/index.ts +1 -0
  83. package/shared/types/db-client/integrations.ts +30 -0
  84. package/shared/types/integrations.ts +9 -0
  85. package/shared/types/worktree-branching.ts +315 -0
  86. package/shared/utils/logger.ts +1 -0
  87. package/dist/assets/main-Bd3gb79F.css +0 -1
  88. package/dist/assets/main-Bo1hD7mt.js +0 -1191
package/dist/index.html CHANGED
@@ -58,8 +58,8 @@
58
58
  }
59
59
  })();
60
60
  </script>
61
- <script type="module" crossorigin src="/assets/main-Bo1hD7mt.js"></script>
62
- <link rel="stylesheet" crossorigin href="/assets/main-Bd3gb79F.css">
61
+ <script type="module" crossorigin src="/assets/main-BrfXH1bL.js"></script>
62
+ <link rel="stylesheet" crossorigin href="/assets/main-CT1PygsW.css">
63
63
  </head>
64
64
  <body
65
65
  class="min-h-dvh bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100 transition-colors duration-200"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myrialabs/clopen",
3
- "version": "0.4.39",
3
+ "version": "0.4.40",
4
4
  "description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
5
5
  "author": "Myria Labs",
6
6
  "license": "MIT",
@@ -75,13 +75,17 @@ export const PROVIDER_ICONS: Record<string, ToolIcon> = {
75
75
  firecrawl: { light: '<svg width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="8 34 560 560" xmlns="http://www.w3.org/2000/svg"><g><g transform=" translate(293.035, 553.013) scale(0.97724, 0.97724) translate(-533.035, -800.013)"><path d=" M603.4 416.3 C581,433 586.6,450.2 583.9,466.6 C583.2,470.5 577.8,469.2 576.5,465.7 C559.5,447 549.5,423.6 559.3,394.4 C577.2,340.8 614.2,311.2 594.2,288.4 C591,284.8 591.8,284.3 590.2,288.8 C572.5,339 363,338 428,536 C430.9,544.8 430.2,555.2 429.5,565.8 C429.3,569 427.1,571.3 424.2,570.1 C401.5,560.8 395.4,525.8 390.4,516.3 C389,513.6 387.5,514.5 385.7,518 C381,524.1 377.9,532.3 374.2,538.5 C336.9,600.7 343.6,664.3 368,715 C368.9,716.9 369.9,718.7 370.9,720.6 C371.9,722.7 373.1,724.8 374.2,726.8 C391.8,758.3 416,783.8 439.8,799.3 C442.6,801.2 446.3,798.5 445.3,795.2 C437.1,767.6 642.8,744.8 634.7,795.2 C634.1,798.6 637.3,801.3 640.2,799.4 C659.9,786.5 680.2,766.8 695.2,742 C696.4,740 697.6,738 698.7,735.9 C699.5,734.5 700.2,733.1 701,731.6 C711.2,711.6 717.8,688.8 718.1,663.6 C718.3,643.8 714.6,622.5 705.5,600.1 C703.8,595.8 700.2,616.5 684.4,613.3 C682.9,613 691.2,586.1 692.1,570.6 C692.4,563.3 690.7,544.7 683.2,524.1 C667.8,481.1 615.5,466.2 609.6,417.3 C609.2,414.6 605.5,414.7 603.4,416.3z " fill="#fa5d19" fill-opacity="1" fill-rule="nonzero"></animate></path></g><g transform=" translate(300, 470.504) scale(0.9650799999999999, 0.9650799999999999) translate(-510.283, -685.815)"><path d=" M410.1 771.9 C412.9,773.7 416.6,771.1 415.6,767.8 C407.4,740.2 411.5,708.6 427.7,684.6 C455.3,643.2 510.6,603.1 501.8,548.7 C501.2,545.3 505.3,543 507.9,545.4 C546.9,581 554.6,629 548.2,672 C547.6,675.7 552.3,677.7 554.7,674.8 C560.6,667.3 567.9,660.7 575.9,655.8 C577.8,654.6 580.5,655.5 581.2,657.7 C594.2,695.6 617.7,725.6 605,767.8 C604,771.1 607.6,773.8 610.5,771.9 C610.5,771.9 610.5,827.2 610.5,827.2 C610.5,827.2 410.1,827.2 410.1,827.2 C410.1,827.2 410.1,771.9 410.1,771.9z " fill="#ffffff" fill-opacity="1" fill-rule="nonzero"></path></g></g></svg>', dark: '<svg width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="8 34 560 560" xmlns="http://www.w3.org/2000/svg"><g><g transform=" translate(293.035, 553.013) scale(0.97724, 0.97724) translate(-533.035, -800.013)"><path d=" M603.4 416.3 C581,433 586.6,450.2 583.9,466.6 C583.2,470.5 577.8,469.2 576.5,465.7 C559.5,447 549.5,423.6 559.3,394.4 C577.2,340.8 614.2,311.2 594.2,288.4 C591,284.8 591.8,284.3 590.2,288.8 C572.5,339 363,338 428,536 C430.9,544.8 430.2,555.2 429.5,565.8 C429.3,569 427.1,571.3 424.2,570.1 C401.5,560.8 395.4,525.8 390.4,516.3 C389,513.6 387.5,514.5 385.7,518 C381,524.1 377.9,532.3 374.2,538.5 C336.9,600.7 343.6,664.3 368,715 C368.9,716.9 369.9,718.7 370.9,720.6 C371.9,722.7 373.1,724.8 374.2,726.8 C391.8,758.3 416,783.8 439.8,799.3 C442.6,801.2 446.3,798.5 445.3,795.2 C437.1,767.6 642.8,744.8 634.7,795.2 C634.1,798.6 637.3,801.3 640.2,799.4 C659.9,786.5 680.2,766.8 695.2,742 C696.4,740 697.6,738 698.7,735.9 C699.5,734.5 700.2,733.1 701,731.6 C711.2,711.6 717.8,688.8 718.1,663.6 C718.3,643.8 714.6,622.5 705.5,600.1 C703.8,595.8 700.2,616.5 684.4,613.3 C682.9,613 691.2,586.1 692.1,570.6 C692.4,563.3 690.7,544.7 683.2,524.1 C667.8,481.1 615.5,466.2 609.6,417.3 C609.2,414.6 605.5,414.7 603.4,416.3z " fill="#fa5d19" fill-opacity="1" fill-rule="nonzero"></animate></path></g><g transform=" translate(300, 470.504) scale(0.9650799999999999, 0.9650799999999999) translate(-510.283, -685.815)"><path d=" M410.1 771.9 C412.9,773.7 416.6,771.1 415.6,767.8 C407.4,740.2 411.5,708.6 427.7,684.6 C455.3,643.2 510.6,603.1 501.8,548.7 C501.2,545.3 505.3,543 507.9,545.4 C546.9,581 554.6,629 548.2,672 C547.6,675.7 552.3,677.7 554.7,674.8 C560.6,667.3 567.9,660.7 575.9,655.8 C577.8,654.6 580.5,655.5 581.2,657.7 C594.2,695.6 617.7,725.6 605,767.8 C604,771.1 607.6,773.8 610.5,771.9 C610.5,771.9 610.5,827.2 610.5,827.2 C610.5,827.2 410.1,827.2 410.1,827.2 C410.1,827.2 410.1,771.9 410.1,771.9z " fill="#0f172a" fill-opacity="1" fill-rule="nonzero"></path></g></g></svg>' },
76
76
  // Vercel's mark is one triangle whose fill flips with the theme — their brand
77
77
  // guidance is black on light and white on dark, so the two variants differ
78
- // only in that fill.
78
+ // only in that fill, and the viewBox is the one their own asset pack ships
79
+ // (1155x1000) rather than a re-typed approximation of it.
79
80
  // Supabase's mark is one artwork for both themes — the green reads on light
80
81
  // and dark alike, which is what their own guidance assumes. Its gradient ids
81
82
  // are namespaced: an inline SVG's `id` is document-global, so a bare
82
83
  // `paint0_linear` would be captured by whichever mark rendered first.
83
84
  supabase: { light: '<svg width="24" height="24" viewBox="0 0 109 113" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0625L99.1935 40.0625C107.384 40.0625 111.952 49.5226 106.859 55.9372L63.7076 110.284Z" fill="url(#supabase_a)"/><path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0625L99.1935 40.0625C107.384 40.0625 111.952 49.5226 106.859 55.9372L63.7076 110.284Z" fill="url(#supabase_b)" fill-opacity="0.2"/><path d="M45.317 2.07103C48.1765 -1.53037 53.9745 0.442937 54.0434 5.041L54.4849 72.2922H9.83113C1.64038 72.2922 -2.92775 62.8321 2.1655 56.4175L45.317 2.07103Z" fill="#3ECF8E"/><defs><linearGradient id="supabase_a" x1="53.9738" y1="54.9738" x2="94.1635" y2="71.8293" gradientUnits="userSpaceOnUse"><stop stop-color="#249361"/><stop offset="1" stop-color="#3ECF8E"/></linearGradient><linearGradient id="supabase_b" x1="36.1558" y1="30.5779" x2="54.4844" y2="65.0804" gradientUnits="userSpaceOnUse"><stop/><stop offset="1" stop-opacity="0"/></linearGradient></defs></svg>', dark: '<svg width="24" height="24" viewBox="0 0 109 113" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0625L99.1935 40.0625C107.384 40.0625 111.952 49.5226 106.859 55.9372L63.7076 110.284Z" fill="url(#supabase_a)"/><path d="M63.7076 110.284C60.8481 113.885 55.0502 111.912 54.9813 107.314L53.9738 40.0625L99.1935 40.0625C107.384 40.0625 111.952 49.5226 106.859 55.9372L63.7076 110.284Z" fill="url(#supabase_b)" fill-opacity="0.2"/><path d="M45.317 2.07103C48.1765 -1.53037 53.9745 0.442937 54.0434 5.041L54.4849 72.2922H9.83113C1.64038 72.2922 -2.92775 62.8321 2.1655 56.4175L45.317 2.07103Z" fill="#3ECF8E"/><defs><linearGradient id="supabase_a" x1="53.9738" y1="54.9738" x2="94.1635" y2="71.8293" gradientUnits="userSpaceOnUse"><stop stop-color="#249361"/><stop offset="1" stop-color="#3ECF8E"/></linearGradient><linearGradient id="supabase_b" x1="36.1558" y1="30.5779" x2="54.4844" y2="65.0804" gradientUnits="userSpaceOnUse"><stop/><stop offset="1" stop-opacity="0"/></linearGradient></defs></svg>' },
84
- vercel: { light: '<svg width="24" height="24" viewBox="0 0 76 65" xmlns="http://www.w3.org/2000/svg"><path d="M37.5274 0L75.0548 65H0L37.5274 0Z" fill="#000000"/></svg>', dark: '<svg width="24" height="24" viewBox="0 0 76 65" xmlns="http://www.w3.org/2000/svg"><path d="M37.5274 0L75.0548 65H0L37.5274 0Z" fill="#ffffff"/></svg>' },
85
+ vercel: { light: '<svg width="24" height="24" viewBox="0 0 1155 1000" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M577.344 0L1154.69 1000H0L577.344 0Z" fill="black"/></svg>', dark: '<svg width="24" height="24" viewBox="0 0 1155 1000" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M577.344 0L1154.69 1000H0L577.344 0Z" fill="white"/></svg>' },
86
+ // Neon ships one logomark in two greens — #37C38F for a light background,
87
+ // #34D59A for a dark one — which is the pair, not a tint we chose.
88
+ neon: { light: '<svg width="24" height="24" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M63 0.0177909V63.5526L38.4178 42.2501V63.5526H0V0L63 0.0177909ZM7.72251 55.8389H30.6953V25.3238L55.2779 47.0476V7.72922L7.72251 7.71559V55.8389Z" fill="#37C38F"/></svg>', dark: '<svg width="24" height="24" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M63 0.0177909V63.5526L38.4178 42.2501V63.5526H0V0L63 0.0177909ZM7.72251 55.8389H30.6953V25.3238L55.2779 47.0476V7.72922L7.72251 7.71559V55.8389Z" fill="#34D59A"/></svg>' },
85
89
  github: { light: '<svg width="24" height="24" viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#24292f"/></svg>', dark: '<svg width="24" height="24" viewBox="0 0 98 96" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z" fill="#ffffff"/></svg>' }
86
90
  };
87
91
 
@@ -0,0 +1,192 @@
1
+ /**
2
+ * db-client — the connection as environment variables.
3
+ *
4
+ * A database is only useful to the project sitting next to it, and the step
5
+ * between "Clopen can reach this" and "my app can reach this" was a user
6
+ * retyping a host, a port, a password and an SSL mode into a dotenv file. This
7
+ * is the vocabulary for closing that gap: what the variables are called, which
8
+ * file they belong in, and what changing that file would do.
9
+ *
10
+ * The naming is the hard part, and it is NOT guessed. Projects split a database
11
+ * across `DB_HOST`/`DB_PASSWORD`, fold it into one `DATABASE_URL`, or call the
12
+ * same thing `POSTGRES_URL` because Vercel does — so the project's own files
13
+ * are read first and what they already use is what gets offered. A preset is
14
+ * the fallback for a project that has nothing yet, not the default answer.
15
+ *
16
+ * VALUES CROSS THIS LINE, unlike every other db-client type. A connection
17
+ * string the user cannot copy is a connection string that solves nothing, so
18
+ * the routes behind these shapes are access-gated instead — see
19
+ * `backend/ws/db-client/env.ts`.
20
+ */
21
+
22
+ import type { DbDriver } from './connection';
23
+
24
+ /** One variable holding everything, or one variable per field. */
25
+ export type DbEnvShape = 'url' | 'split';
26
+
27
+ /**
28
+ * What one variable HOLDS, independent of what it is called.
29
+ *
30
+ * The naming picker offers shapes and nothing else. An earlier version offered
31
+ * frameworks — Laravel, Prisma, libpq, Vercel — which was a list of guesses
32
+ * about projects it had already read: the real answer to "what are these
33
+ * called here" comes from `DbEnvExistingGroup`, which carries the project's own
34
+ * key names. A framework in a dropdown is that answer asserted instead.
35
+ */
36
+ export type DbEnvRole =
37
+ | 'url'
38
+ | 'altUrl'
39
+ | 'host'
40
+ | 'port'
41
+ | 'user'
42
+ | 'password'
43
+ | 'database'
44
+ | 'sslMode';
45
+
46
+ /** One of the two shapes, as the picker renders it. */
47
+ export interface DbEnvShapeInfo {
48
+ id: DbEnvShape;
49
+ label: string;
50
+ description: string;
51
+ /** The keys it writes, with the current prefix, for the picker to show. */
52
+ sampleKeys: string[];
53
+ }
54
+
55
+ export interface DbEnvVar {
56
+ key: string;
57
+ value: string;
58
+ /** True when the value carries a credential, so the panel masks it. */
59
+ isSecret: boolean;
60
+ /** One short clause, when the variable needs explaining. */
61
+ note?: string | null;
62
+ }
63
+
64
+ export interface DbEnvFileInfo {
65
+ name: string;
66
+ /** Read for its shape, never written — `.env.example` and friends. */
67
+ isTemplate: boolean;
68
+ /** git tracks it, so writing a password into it would commit one. */
69
+ isTracked: boolean;
70
+ /** Lower wins: `.env.local` beats `.env` in Next.js and Vite. */
71
+ precedence: number;
72
+ }
73
+
74
+ /**
75
+ * A naming convention the project is ALREADY using.
76
+ *
77
+ * The whole reason detection exists: offering to update `POSTGRES_URL` where
78
+ * the project has one beats adding a `DATABASE_URL` nothing reads.
79
+ */
80
+ export interface DbEnvExistingGroup {
81
+ prefix: string;
82
+ shape: DbEnvShape;
83
+ keys: string[];
84
+ /**
85
+ * Which of this group's keys holds what.
86
+ *
87
+ * The whole point of detection, and what replaced the framework presets: a
88
+ * project with `DB_USERNAME` gets `DB_USERNAME` written, not a `DB_USER`
89
+ * beside it that nothing reads.
90
+ */
91
+ keyMap: Partial<Record<DbEnvRole, string>>;
92
+ /** Which files carry these keys, most-precedent first. */
93
+ files: string[];
94
+ /** True when every occurrence is commented out — a template's documentation. */
95
+ isTemplateOnly: boolean;
96
+ /** How the row reads: "DATABASE_URL · .env.local". */
97
+ label: string;
98
+ }
99
+
100
+ export interface DbEnvDetection {
101
+ /** Null when no project is in scope; the panel then only offers copying. */
102
+ projectId: string | null;
103
+ projectName: string | null;
104
+ files: DbEnvFileInfo[];
105
+ /** What the project already uses, best first. Empty for a fresh project. */
106
+ existing: DbEnvExistingGroup[];
107
+ /** Where the names came from, for the sentence the panel shows. */
108
+ sources: string[];
109
+ }
110
+
111
+ /** Everything the panel needs to open. */
112
+ export interface DbEnvState {
113
+ connectionId: string;
114
+ connectionName: string;
115
+ driver: DbDriver;
116
+ /** The database in scope, when the panel was opened inside one. */
117
+ database: string | null;
118
+ shapes: DbEnvShapeInfo[];
119
+ detection: DbEnvDetection;
120
+ /** The shape, names and file the panel opens on. */
121
+ suggestion: {
122
+ shape: DbEnvShape;
123
+ prefix: string;
124
+ fileName: string | null;
125
+ /** The project's own names, when detection found a group to follow. */
126
+ keyMap: Partial<Record<DbEnvRole, string>> | null;
127
+ };
128
+ /** True when the provider can also hand back a direct/unpooled counterpart. */
129
+ hasAlternate: boolean;
130
+ /** What the counterpart is called where it exists — "Direct (unpooled)". */
131
+ alternateLabel: string | null;
132
+ /** Sentences shown above the variables: tunnels, localhost, derived rows. */
133
+ warnings: string[];
134
+ }
135
+
136
+ export type DbEnvDiffKind = 'context' | 'added' | 'removed';
137
+
138
+ export interface DbEnvDiffLine {
139
+ kind: DbEnvDiffKind;
140
+ text: string;
141
+ }
142
+
143
+ /** What applying would do, worked out without touching the file. */
144
+ export interface DbEnvPlan {
145
+ vars: DbEnvVar[];
146
+ /** The rendered fragment, ready to paste. */
147
+ text: string;
148
+ fileName: string | null;
149
+ fileExists: boolean;
150
+ /** git tracks the target, so applying needs an explicit override. */
151
+ fileTracked: boolean;
152
+ /** Keys replaced where the project already had them. */
153
+ updated: string[];
154
+ /** Keys the project lacks, bound for the managed block. */
155
+ appended: string[];
156
+ /** Keys already holding exactly this value. */
157
+ unchanged: string[];
158
+ diff: DbEnvDiffLine[];
159
+ warnings: string[];
160
+ }
161
+
162
+ export interface DbEnvApplyResult {
163
+ status: 'written' | 'unchanged' | 'skipped-tracked' | 'failed';
164
+ /** One sentence, naming what happened and what to do. Null when it worked. */
165
+ detail: string | null;
166
+ fileName: string;
167
+ updated: string[];
168
+ appended: string[];
169
+ }
170
+
171
+ /** What the panel sends for a preview, an apply, or an undo. */
172
+ export interface DbEnvRequest {
173
+ connectionId: string;
174
+ projectId?: string;
175
+ /**
176
+ * The database in scope.
177
+ *
178
+ * A connection with no database of its own browses one, and it is THAT one
179
+ * the project needs a URL for — the connection's own empty field would
180
+ * produce a string pointing at the server and no database.
181
+ */
182
+ database?: string;
183
+ shape: DbEnvShape;
184
+ prefix: string;
185
+ /** Exact names to use, overriding what the prefix would produce. */
186
+ keyMap?: Partial<Record<DbEnvRole, string>>;
187
+ fileName?: string;
188
+ /** Include the provider's direct/unpooled counterpart where one exists. */
189
+ includeAlternate?: boolean;
190
+ /** Write even though git tracks the file. The user has to have confirmed. */
191
+ allowTracked?: boolean;
192
+ }
@@ -5,4 +5,5 @@
5
5
  export * from './connection';
6
6
  export * from './query';
7
7
  export * from './integrations';
8
+ export * from './env';
8
9
  export * from './supabase';
@@ -52,6 +52,26 @@ export interface DbProviderInfo {
52
52
  secretFields: DbLinkSecretField[];
53
53
  /** Copy shown above the picker — where to find things, what will happen. */
54
54
  description: string;
55
+ /**
56
+ * Where this provider's credential is created.
57
+ *
58
+ * Filled from the INTEGRATION registry rather than declared twice: the hub
59
+ * already knows every provider's `docsUrl`, and a second copy here would be
60
+ * the one that goes stale. It exists so the link dialog can point a user at
61
+ * the right page without naming a vendor in its own markup — which is how it
62
+ * ended up telling someone connecting Neon where Supabase tokens live.
63
+ */
64
+ docsUrl?: string;
65
+ /**
66
+ * The provider's dashboard, for the things Clopen cannot do.
67
+ *
68
+ * Every provider has some — Neon has no organisation endpoints at all,
69
+ * Supabase exposes no organisation update — and until now the dialog only
70
+ * SAID so. A sentence that names a place without offering to go there leaves
71
+ * the user to find it, which is the read-only-window feeling this surface
72
+ * exists to remove. Filled from the integration registry, like `docsUrl`.
73
+ */
74
+ consoleUrl?: string;
55
75
  }
56
76
 
57
77
  /** A remote database an account can reach but has not necessarily linked. */
@@ -122,6 +142,16 @@ export interface DbProviderCreateOptions {
122
142
  canCreateGroup: boolean;
123
143
  /** One sentence naming what creating a container costs. */
124
144
  createGroupNotice: string;
145
+ /**
146
+ * What can and cannot be done to a container from here, in one sentence.
147
+ *
148
+ * Provider-declared because the answer is provider-specific and the reason
149
+ * is too: Supabase exposes no PATCH or DELETE for an organisation, so no
150
+ * permission would help, while Neon exposes no create either. Hard-coding
151
+ * one vendor's sentence made the dialog send a Neon user to Supabase's
152
+ * dashboard.
153
+ */
154
+ groupManagementNotice: string;
125
155
  }
126
156
 
127
157
  /** A link, as the panel sees it. Secret VALUES never cross this line. */
@@ -78,6 +78,15 @@ export interface IntegrationProviderInfo {
78
78
  category: IntegrationCategory;
79
79
  description: string;
80
80
  docsUrl?: string;
81
+ /**
82
+ * The provider's own dashboard.
83
+ *
84
+ * Separate from `docsUrl`, which points at where a CREDENTIAL is created.
85
+ * This is where the things Clopen cannot manage actually live — an
86
+ * organisation Neon has no API for, a billing plan — so a surface that has
87
+ * to say "do this at the vendor" can offer the trip instead of describing it.
88
+ */
89
+ consoleUrl?: string;
81
90
  authMethod: IntegrationAuthMethod;
82
91
  credentialFields: IntegrationCredentialField[];
83
92
  capabilities: IntegrationCapability[];
@@ -0,0 +1,315 @@
1
+ /**
2
+ * Worktree database branching — shared vocabulary.
3
+ *
4
+ * The worktree manager talks about a BRANCH DATABASE, not about Neon. Every
5
+ * provider that can offer the `worktree-branching` capability is normalised
6
+ * into these shapes by an adapter, and the manager never learns which one
7
+ * answered — the same test `Task 2` and `Task 3` set for their surfaces: if
8
+ * Turso needs a second dialog, these types are wrong and fixing them is the
9
+ * work.
10
+ *
11
+ * The word "branch" is deliberately NOT baked into the copy. Neon cuts a real
12
+ * copy-on-write branch; Turso seeds a whole new database from a parent. Both
13
+ * are "an isolated database derived from a parent", and `BranchProviderInfo`
14
+ * carries the noun each provider uses so the dialog can say what actually
15
+ * happens rather than calling a seeded database a branch.
16
+ *
17
+ * Nothing here carries a credential. The connection string a branch answers on
18
+ * is resolved on the server, sealed on the branch row, and written into the
19
+ * worktree's environment — it never crosses this line.
20
+ */
21
+
22
+ import type { DbDriver, DbSslMode } from './db-client';
23
+
24
+ /**
25
+ * Where a worktree's database comes from.
26
+ *
27
+ * `account` is a provider that branches natively — Neon cuts a copy-on-write
28
+ * branch through its API. `connection` is everything else: a database Clopen
29
+ * can already reach, copied with that engine's own primitives. The second is
30
+ * the general case and the first is the optimisation, which is the opposite of
31
+ * how this feature started.
32
+ */
33
+ export type BranchSourceKind = 'account' | 'connection';
34
+
35
+ /** How much of the parent a worktree's database starts with. */
36
+ export type BranchDataMode = 'schema-data' | 'schema' | 'empty';
37
+
38
+ /**
39
+ * A place worktree databases can come from, as the setup dialog lists them.
40
+ *
41
+ * Accounts and connections are one list rather than two tabs: the user is
42
+ * choosing WHICH DATABASE, and whether the copy happens through a vendor API or
43
+ * through `CREATE DATABASE` is an implementation detail they should be told
44
+ * about, not asked to navigate.
45
+ */
46
+ export interface BranchSourceOption {
47
+ kind: BranchSourceKind;
48
+ /** The account id, or the DB Client connection id. */
49
+ id: string;
50
+ label: string;
51
+ /** Integration provider id for an account, driver id for a connection. */
52
+ provider: string;
53
+ providerName: string;
54
+ /** What this source calls one — "branch" for Neon, "copy" for the rest. */
55
+ noun: string;
56
+ /** True when the provider branches natively rather than Clopen copying. */
57
+ isNative: boolean;
58
+ /** One sentence naming what a copy here does not carry, or null. */
59
+ notice: string | null;
60
+ /** Health, for the same strip the accounts list uses. */
61
+ status: string;
62
+ }
63
+
64
+ /** A parent database a worktree's branch is cut from. */
65
+ export interface BranchParent {
66
+ /** The provider's own id for the parent — a Neon project id. */
67
+ ref: string;
68
+ name: string;
69
+ /** Region, plan — whatever tells two similarly named parents apart. */
70
+ detail: string | null;
71
+ /** The owning container's name, so which organisation is billed is visible. */
72
+ group: string | null;
73
+ /** Whether a branch can be cut from it right now. The ADAPTER decides. */
74
+ isReady: boolean;
75
+ }
76
+
77
+ /** Where a created branch answers. The password is server-side only. */
78
+ export interface BranchConnection {
79
+ /** The full URI, which is what lands in the worktree's environment. */
80
+ uri: string;
81
+ host: string;
82
+ port: number;
83
+ username: string;
84
+ password: string;
85
+ database: string;
86
+ sslMode: DbSslMode;
87
+ }
88
+
89
+ /** What an adapter hands back after cutting one. */
90
+ export interface CreatedBranch {
91
+ /** The provider's own id for the branch. */
92
+ ref: string;
93
+ /** The name it was actually given, which may differ from the one requested. */
94
+ name: string;
95
+ connection: BranchConnection;
96
+ }
97
+
98
+ /** A branch as it exists at the provider, for the orphan sweep. */
99
+ export interface RemoteBranch {
100
+ ref: string;
101
+ name: string;
102
+ createdAt: string | null;
103
+ /** A provider's default branch is never ours and is never offered for delete. */
104
+ isDefault: boolean;
105
+ /** Logical size in bytes, when the provider reports one. */
106
+ sizeBytes: number | null;
107
+ }
108
+
109
+ /** A branching provider as the setup dialog renders it. */
110
+ export interface BranchProviderInfo {
111
+ /** Matches the integration provider id, so the brand mark is the same one. */
112
+ id: string;
113
+ name: string;
114
+ /**
115
+ * What this provider calls one, singular and lowercase — "branch" for Neon,
116
+ * "database" for Turso. Used in copy so a seeded Turso database is never
117
+ * described as a branch.
118
+ */
119
+ noun: string;
120
+ /** What the parent is called — "Neon project". */
121
+ parentLabel: string;
122
+ description: string;
123
+ /** One sentence naming what cutting one actually costs. */
124
+ notice: string;
125
+ /** True when the provider can hand back a pooled endpoint as well. */
126
+ supportsPooled: boolean;
127
+ }
128
+
129
+ /**
130
+ * Per-project settings for branching.
131
+ *
132
+ * `envFile` has NO default worth guessing, which is why it is asked for at
133
+ * setup. Next.js and Vite read `.env.local` in PREFERENCE to `.env`, so writing
134
+ * the wrong one produces the worst possible outcome: the branch is created, the
135
+ * variable is written, and nothing reads it.
136
+ */
137
+ export interface WorktreeBranchConfig {
138
+ /** The variable the connection URI is written to. */
139
+ envVar: string;
140
+ /** Which dotenv file inside the worktree receives the managed block. */
141
+ envFile: string;
142
+ /** Offer it, ticked, on every worktree create. */
143
+ autoCreate: boolean;
144
+ /** Ask the provider for a pooled endpoint instead of a direct one. */
145
+ pooled: boolean;
146
+ /**
147
+ * How much of the parent a new worktree's database starts with.
148
+ *
149
+ * Remembered per project and overridable per worktree, because the right
150
+ * answer depends on the database rather than on the feature: a seeded dev
151
+ * database is worth copying whole, and a forty-gigabyte one is not.
152
+ */
153
+ dataMode: BranchDataMode;
154
+ }
155
+
156
+ export const DEFAULT_WORKTREE_BRANCH_CONFIG: WorktreeBranchConfig = {
157
+ envVar: 'DATABASE_URL',
158
+ envFile: '.env',
159
+ autoCreate: true,
160
+ // Direct, not pooled, and the default is not a question to ask. A worktree is
161
+ // where an agent runs migrations: a transaction-mode pooler breaks prepared
162
+ // statements and some DDL, and the failure arrives as a confusing driver
163
+ // error rather than as a configuration one.
164
+ pooled: false,
165
+ // Copying the data is what makes a worktree feel like the project rather
166
+ // than like an empty shell of it — the app starts, the fixtures are there,
167
+ // and an agent can actually run what it just changed.
168
+ dataMode: 'schema-data'
169
+ };
170
+
171
+ /** The binding for one project, as the worktree manager sees it. */
172
+ export interface WorktreeBranchBindingInfo {
173
+ projectId: string;
174
+ sourceKind: BranchSourceKind;
175
+ /** The account id, or the DB Client connection id. */
176
+ sourceId: string;
177
+ provider: string;
178
+ providerName: string;
179
+ /** The account's label, or the connection's name. */
180
+ sourceLabel: string;
181
+ parentRef: string;
182
+ parentName: string;
183
+ isNative: boolean;
184
+ config: WorktreeBranchConfig;
185
+ updatedAt: string;
186
+ }
187
+
188
+ /**
189
+ * What happened when the connection string was written into the worktree.
190
+ *
191
+ * `skipped-tracked` is the one that matters. A dotenv file that git TRACKS
192
+ * would be carried back to the main project by "Apply to Main", overwriting the
193
+ * real connection string with one that points at a database this worktree's
194
+ * deletion destroys. So it is refused rather than written, and the refusal is
195
+ * reported instead of being logged and forgotten.
196
+ */
197
+ export type BranchEnvStatus = 'written' | 'skipped-tracked' | 'failed';
198
+
199
+ /** A live or orphaned branch, as the manager sees it. */
200
+ export interface WorktreeBranchInfo {
201
+ id: string;
202
+ /** Null once the worktree is gone — which is what makes a row an orphan. */
203
+ worktreeId: string | null;
204
+ worktreeName: string | null;
205
+ sourceKind: BranchSourceKind;
206
+ provider: string;
207
+ providerName: string;
208
+ /** What this source calls one, so copy reads right per source. */
209
+ noun: string;
210
+ /** The account id, or the DB Client connection id. */
211
+ sourceId: string;
212
+ sourceLabel: string;
213
+ /** Which mechanism made it — `template`, `row-copy`, `file-copy`, … */
214
+ strategy: string | null;
215
+ /** One sentence naming what the copy did not carry, or null. */
216
+ notice: string | null;
217
+ parentRef: string;
218
+ branchRef: string;
219
+ branchName: string;
220
+ envVar: string;
221
+ envFile: string;
222
+ envStatus: BranchEnvStatus;
223
+ envDetail: string | null;
224
+ status: 'active' | 'orphaned';
225
+ /** Why it is orphaned — the provider's own words for the failed delete. */
226
+ error: string | null;
227
+ /** The projected DB Client connection, so the branch can be inspected. */
228
+ connectionId: string | null;
229
+ createdAt: string;
230
+ }
231
+
232
+ /**
233
+ * A branch at the provider that Clopen has no row for.
234
+ *
235
+ * The second half of orphan detection. A crash between "the provider created
236
+ * it" and "the row was written" leaves a branch nothing here knows about, and
237
+ * the only thing tying it back is the name — which is why branch names are
238
+ * deterministic and prefixed.
239
+ */
240
+ export interface UnknownRemoteBranch {
241
+ sourceKind: BranchSourceKind;
242
+ /** The account id, or the DB Client connection id. */
243
+ sourceId: string;
244
+ provider: string;
245
+ parentRef: string;
246
+ branch: RemoteBranch;
247
+ }
248
+
249
+ /** Everything the worktree manager's branching dialog renders. */
250
+ export interface WorktreeBranchingState {
251
+ providers: BranchProviderInfo[];
252
+ /**
253
+ * Everywhere a worktree database could come from — accounts AND connections.
254
+ *
255
+ * One list, because "which database" is one question. See
256
+ * `BranchSourceOption`.
257
+ */
258
+ sources: BranchSourceOption[];
259
+ binding: WorktreeBranchBindingInfo | null;
260
+ /** Dotenv files that already exist in the project, most-precedent first. */
261
+ envFiles: string[];
262
+ branches: WorktreeBranchInfo[];
263
+ }
264
+
265
+ /** The result of attaching a branch to a freshly created worktree. */
266
+ export interface BranchAttachResult {
267
+ branch: WorktreeBranchInfo | null;
268
+ /** What the copy did not carry, when it carried less than everything. */
269
+ notice?: string | null;
270
+ /**
271
+ * Why no branch was attached, when one was expected.
272
+ *
273
+ * Fail-soft is the rule: a provider outage must never cost the user the
274
+ * worktree they asked for, so this is reported alongside a worktree that was
275
+ * created successfully rather than thrown.
276
+ */
277
+ error: string | null;
278
+ }
279
+
280
+ /** The branch-name prefix every source-side name carries. */
281
+ export const BRANCH_NAME_PREFIX = 'clopen';
282
+
283
+ /**
284
+ * The binding a project would get if it asked for one.
285
+ *
286
+ * Derived from the project's own `.env` and Clopen's connection list, so the
287
+ * dialog can offer "also give it its own database" without the user having
288
+ * configured anything first. Null when the URL in the project's environment
289
+ * corresponds to no saved connection — Clopen would have the address but not
290
+ * the password, and an offer that fails at the moment of use is worse than no
291
+ * offer.
292
+ */
293
+ export interface BranchSuggestion {
294
+ sourceKind: 'connection';
295
+ sourceId: string;
296
+ sourceLabel: string;
297
+ providerName: string;
298
+ /** The database to copy — a name, or a file path for SQLite. */
299
+ parentRef: string;
300
+ parentName: string;
301
+ /** The variable the copy's URL should be written to. */
302
+ envVar: string;
303
+ /** Which dotenv file that variable already lives in. */
304
+ envFile: string;
305
+ /** What a copy here does not carry, or null. */
306
+ notice: string | null;
307
+ }
308
+
309
+ /** A database on a connection that a worktree copy could be made from. */
310
+ export interface BranchConnectionParent {
311
+ /** The database name, its file path for SQLite, its index for Redis. */
312
+ ref: string;
313
+ name: string;
314
+ driver: DbDriver;
315
+ }
@@ -48,6 +48,7 @@ export type LogLabel =
48
48
  | 'notes'
49
49
  | 'settings'
50
50
  | 'engine'
51
+ | 'env-files'
51
52
  | 'tunnel'
52
53
  | 'remote-access'
53
54
  | 'db-client'