@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.
- package/backend/auth/permissions.ts +23 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +6 -0
- package/backend/database/queries/worktree-branch-queries.ts +331 -0
- package/backend/db-client/cloning.test.ts +161 -0
- package/backend/db-client/cloning.ts +672 -0
- package/backend/db-client/connection-url.test.ts +117 -0
- package/backend/db-client/connection-url.ts +126 -0
- package/backend/db-client/drivers/mongodb.ts +2 -14
- package/backend/db-client/drivers/mysql.ts +2 -8
- package/backend/db-client/drivers/postgres.ts +10 -13
- package/backend/db-client/drivers/redis.ts +2 -6
- package/backend/db-client/env/detect.ts +438 -0
- package/backend/db-client/env/diff.ts +94 -0
- package/backend/db-client/env/env.test.ts +574 -0
- package/backend/db-client/env/index.ts +15 -0
- package/backend/db-client/env/naming.ts +202 -0
- package/backend/db-client/env/service.ts +487 -0
- package/backend/db-client/integrations/index.ts +7 -0
- package/backend/db-client/integrations/links.ts +41 -10
- package/backend/db-client/providers/neon/adapter.ts +522 -0
- package/backend/db-client/providers/neon/api-types.ts +182 -0
- package/backend/db-client/providers/neon/client.ts +298 -0
- package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
- package/backend/db-client/providers/neon/endpoints.ts +314 -0
- package/backend/db-client/providers/neon/list.test.ts +181 -0
- package/backend/db-client/providers/supabase/adapter.ts +25 -2
- package/backend/db-client/providers/types.ts +57 -0
- package/backend/env-files/discovery.ts +48 -0
- package/backend/env-files/edit.ts +213 -0
- package/backend/env-files/env-files.test.ts +515 -0
- package/backend/env-files/git.ts +27 -0
- package/backend/env-files/index.ts +44 -0
- package/backend/env-files/keys.ts +69 -0
- package/backend/env-files/parse.ts +157 -0
- package/backend/env-files/write.ts +229 -0
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/types.ts +9 -2
- package/backend/integrations/registry/index.ts +3 -0
- package/backend/integrations/registry/providers/context7.ts +1 -0
- package/backend/integrations/registry/providers/firecrawl.ts +1 -0
- package/backend/integrations/registry/providers/github.ts +1 -0
- package/backend/integrations/registry/providers/neon.ts +55 -0
- package/backend/integrations/registry/providers/supabase.ts +1 -0
- package/backend/integrations/registry/providers/vercel.ts +1 -0
- package/backend/integrations/registry/types.ts +2 -0
- package/backend/work/start-work.ts +4 -0
- package/backend/worktrees/branching/engine.ts +557 -0
- package/backend/worktrees/branching/index.ts +56 -0
- package/backend/worktrees/branching/naming.test.ts +118 -0
- package/backend/worktrees/branching/naming.ts +97 -0
- package/backend/worktrees/branching/projector.test.ts +229 -0
- package/backend/worktrees/branching/projector.ts +139 -0
- package/backend/worktrees/branching/providers/neon.ts +220 -0
- package/backend/worktrees/branching/registry.ts +27 -0
- package/backend/worktrees/branching/service.ts +620 -0
- package/backend/worktrees/branching/suggest.test.ts +154 -0
- package/backend/worktrees/branching/suggest.ts +202 -0
- package/backend/worktrees/branching/types.ts +88 -0
- package/backend/worktrees/index.ts +7 -0
- package/backend/worktrees/service.ts +48 -1
- package/backend/ws/db-client/env.ts +142 -0
- package/backend/ws/db-client/index.ts +2 -0
- package/backend/ws/projects/index.ts +6 -1
- package/backend/ws/projects/info.ts +70 -6
- package/backend/ws/projects/overview.test.ts +108 -0
- package/backend/ws/projects/overview.ts +300 -0
- package/backend/ws/system/device-info.ts +307 -76
- package/backend/ws/worktrees/branching.ts +212 -0
- package/backend/ws/worktrees/crud.ts +33 -7
- package/backend/ws/worktrees/index.ts +14 -0
- package/dist/assets/{index-C8Gi-b6U.js → index-D4igjF6e.js} +1 -1
- package/dist/assets/{index-BrF6nqld.js → index-DONNwiXm.js} +1 -1
- package/dist/assets/main-BrfXH1bL.js +1205 -0
- package/dist/assets/main-CT1PygsW.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +6 -2
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +1 -0
- package/shared/types/db-client/integrations.ts +30 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/logger.ts +1 -0
- package/dist/assets/main-Bd3gb79F.css +0 -1
- package/dist/assets/main-Bo1hD7mt.js +0 -1191
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Editing a dotenv file without rewriting it.
|
|
3
|
+
*
|
|
4
|
+
* **In place**, when the project already assigns the variable. The value is
|
|
5
|
+
* replaced exactly where it was, so the file keeps the shape its author gave
|
|
6
|
+
* it, and the previous value is left behind as a comment — the whole point of
|
|
7
|
+
* touching someone's configuration is that they can get it back. This is the
|
|
8
|
+
* mode that answers "my project calls it `POSTGRES_URL`, not `DATABASE_URL`":
|
|
9
|
+
* nothing is guessed, the existing key is what gets written.
|
|
10
|
+
*
|
|
11
|
+
* **Appended**, plainly, for a variable the file does not have yet.
|
|
12
|
+
*
|
|
13
|
+
* NO MARKED BLOCK, and there used to be one. It existed to tell Clopen's lines
|
|
14
|
+
* from the user's so that undoing could not delete a variable they wrote — but
|
|
15
|
+
* it cost three lines of scaffolding around one value, and worse, a block that
|
|
16
|
+
* has to come LAST leaves the project's own `DATABASE_URL` sitting untouched
|
|
17
|
+
* above it. A reader takes the last assignment, so the file WORKS and looks
|
|
18
|
+
* like it does not, which is the least defensible thing a config editor can do.
|
|
19
|
+
*
|
|
20
|
+
* Removal keeps the guarantee more cheaply. A replaced value is restored from
|
|
21
|
+
* the comment left beside it, and an appended key is removed only while it
|
|
22
|
+
* still holds exactly what was written — anything else is the user's and stays.
|
|
23
|
+
*
|
|
24
|
+
* Backups do not stack. A second apply removes the comment the first one left
|
|
25
|
+
* for the same key before writing a new one, or a file rewritten weekly would
|
|
26
|
+
* grow a dead line per week.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { formatEnvLine } from './keys';
|
|
30
|
+
import { effectiveAssignment, parseDotenv } from './parse';
|
|
31
|
+
|
|
32
|
+
/** Marks the line holding a value Clopen replaced, so it can be put back. */
|
|
33
|
+
export const PREVIOUS_VALUE_PREFIX = '# clopen:previous ';
|
|
34
|
+
|
|
35
|
+
export interface EnvUpsertOptions {
|
|
36
|
+
/** A comment written above the appended lines, naming where they came from. */
|
|
37
|
+
note?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface EnvUpsertResult {
|
|
41
|
+
text: string;
|
|
42
|
+
/** Keys whose existing assignment was rewritten where it stood. */
|
|
43
|
+
updated: string[];
|
|
44
|
+
/** Keys the file did not have, now in the managed block. */
|
|
45
|
+
appended: string[];
|
|
46
|
+
/** Keys already holding exactly this value. */
|
|
47
|
+
unchanged: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The key a `# clopen:previous …` line is a backup of, or null. */
|
|
51
|
+
function keyOfBackup(line: string): string | null {
|
|
52
|
+
const trimmed = line.trim();
|
|
53
|
+
if (!trimmed.startsWith(PREVIOUS_VALUE_PREFIX)) return null;
|
|
54
|
+
const match = /^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)[ \t]*=/.exec(
|
|
55
|
+
trimmed.slice(PREVIOUS_VALUE_PREFIX.length)
|
|
56
|
+
);
|
|
57
|
+
return match ? match[1] : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Whether this file uses Windows line endings.
|
|
62
|
+
*
|
|
63
|
+
* Everything below works in LF and converts back at the end, so a file written
|
|
64
|
+
* on Windows keeps its own convention instead of gaining one mixed line per
|
|
65
|
+
* variable Clopen touches.
|
|
66
|
+
*/
|
|
67
|
+
function usesCrlf(content: string): boolean {
|
|
68
|
+
return /\r\n/.test(content);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function upsertEnvKeys(
|
|
72
|
+
content: string,
|
|
73
|
+
vars: Record<string, string>,
|
|
74
|
+
options: EnvUpsertOptions = {}
|
|
75
|
+
): EnvUpsertResult {
|
|
76
|
+
const keys = Object.keys(vars);
|
|
77
|
+
const crlf = usesCrlf(content);
|
|
78
|
+
if (crlf) content = content.replace(/\r\n/g, '\n');
|
|
79
|
+
|
|
80
|
+
// Our own backup comments for the keys being written come out first, so this
|
|
81
|
+
// apply replaces them rather than adding a second one. Backups for keys NOT
|
|
82
|
+
// in this write are left alone — they still document a value we replaced.
|
|
83
|
+
const base = content
|
|
84
|
+
.split('\n')
|
|
85
|
+
.filter((line) => {
|
|
86
|
+
const key = keyOfBackup(line);
|
|
87
|
+
return !(key !== null && keys.includes(key));
|
|
88
|
+
})
|
|
89
|
+
.join('\n');
|
|
90
|
+
|
|
91
|
+
const assignments = parseDotenv(base);
|
|
92
|
+
const lines = base.split('\n');
|
|
93
|
+
|
|
94
|
+
const updated: string[] = [];
|
|
95
|
+
const appended: string[] = [];
|
|
96
|
+
const unchanged: string[] = [];
|
|
97
|
+
/** Keys bound for the block, whether or not their value changed. */
|
|
98
|
+
const placed: string[] = [];
|
|
99
|
+
const edits: { line: number; lineCount: number; replacement: string[] }[] = [];
|
|
100
|
+
|
|
101
|
+
for (const key of keys) {
|
|
102
|
+
const value = vars[key];
|
|
103
|
+
const existing = effectiveAssignment(assignments, key);
|
|
104
|
+
|
|
105
|
+
if (!existing) {
|
|
106
|
+
placed.push(key);
|
|
107
|
+
appended.push(key);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (existing.value === value) {
|
|
111
|
+
unchanged.push(key);
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
edits.push({
|
|
116
|
+
line: existing.line,
|
|
117
|
+
lineCount: existing.lineCount,
|
|
118
|
+
replacement: [
|
|
119
|
+
// Folded to one line. A multi-line quoted value would otherwise
|
|
120
|
+
// become several comment lines, only the first of which is a comment.
|
|
121
|
+
`${PREVIOUS_VALUE_PREFIX}${existing.raw.split('\n').join(' ')}`,
|
|
122
|
+
formatEnvLine(key, value)
|
|
123
|
+
]
|
|
124
|
+
});
|
|
125
|
+
updated.push(key);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Back to front, so every line index recorded above stays valid.
|
|
129
|
+
for (const edit of edits.sort((a, b) => b.line - a.line)) {
|
|
130
|
+
lines.splice(edit.line, edit.lineCount, ...edit.replacement);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const added =
|
|
134
|
+
placed.length > 0
|
|
135
|
+
? [
|
|
136
|
+
...(options.note ? [`# ${options.note}`] : []),
|
|
137
|
+
...placed.map((key) => formatEnvLine(key, vars[key]))
|
|
138
|
+
]
|
|
139
|
+
: [];
|
|
140
|
+
|
|
141
|
+
const text = appendPlainLines(lines.join('\n'), added);
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
text: crlf ? text.replace(/\n/g, '\r\n') : text,
|
|
145
|
+
updated,
|
|
146
|
+
appended,
|
|
147
|
+
unchanged
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Add lines to the end of a file, with no markers around them.
|
|
153
|
+
*
|
|
154
|
+
* One blank line between the user's content and ours, and none when the file
|
|
155
|
+
* was empty — which is what someone appending by hand would do.
|
|
156
|
+
*/
|
|
157
|
+
function appendPlainLines(existing: string, lines: string[]): string {
|
|
158
|
+
if (lines.length === 0) return existing;
|
|
159
|
+
const block = `${lines.join('\n')}\n`;
|
|
160
|
+
if (!existing.trim()) return block;
|
|
161
|
+
return `${existing.replace(/\n*$/, '')}\n\n${block}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Take the write back out.
|
|
166
|
+
*
|
|
167
|
+
* The managed block goes entirely, and every value replaced in place is
|
|
168
|
+
* restored from the comment left beside it. A key with no backup is LEFT
|
|
169
|
+
* ALONE rather than deleted: it was the project's own variable before Clopen
|
|
170
|
+
* touched it, and removing a variable the app needs is worse than leaving one
|
|
171
|
+
* pointing at a database the user can still reach.
|
|
172
|
+
*/
|
|
173
|
+
export function removeEnvKeys(
|
|
174
|
+
content: string,
|
|
175
|
+
keys: string[],
|
|
176
|
+
options: { values?: Record<string, string> } = {}
|
|
177
|
+
): string {
|
|
178
|
+
const crlf = usesCrlf(content);
|
|
179
|
+
const lines = (crlf ? content.replace(/\r\n/g, '\n') : content).split('\n');
|
|
180
|
+
|
|
181
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
182
|
+
const key = keyOfBackup(lines[index]);
|
|
183
|
+
if (key === null || !keys.includes(key)) continue;
|
|
184
|
+
|
|
185
|
+
const original = lines[index].trim().slice(PREVIOUS_VALUE_PREFIX.length);
|
|
186
|
+
// The line we wrote sits directly below its backup. When it does not, the
|
|
187
|
+
// user has edited it since, and their line is the one that stays.
|
|
188
|
+
const next = lines[index + 1] ?? '';
|
|
189
|
+
const ours = new RegExp(`^\\s*(?:export\\s+)?${key}[ \\t]*=`).test(next);
|
|
190
|
+
lines.splice(index, ours ? 2 : 1, original);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Keys that were APPENDED have no backup to restore, so they are removed —
|
|
194
|
+
// but only while they still hold exactly what was written. A value the user
|
|
195
|
+
// has since edited is theirs now, and deleting it would be this feature
|
|
196
|
+
// taking away a variable it did not put there.
|
|
197
|
+
if (options.values) {
|
|
198
|
+
const ours = parseDotenv(lines.join('\n')).filter(
|
|
199
|
+
(entry) =>
|
|
200
|
+
!entry.commented &&
|
|
201
|
+
keys.includes(entry.key) &&
|
|
202
|
+
options.values?.[entry.key] === entry.value
|
|
203
|
+
);
|
|
204
|
+
// Back to front, so every recorded position stays valid.
|
|
205
|
+
for (const entry of ours.reverse()) lines.splice(entry.line, entry.lineCount);
|
|
206
|
+
// The blank line that separated the appended lines from the user's own
|
|
207
|
+
// content has nothing left to separate.
|
|
208
|
+
while (lines.length > 1 && lines.at(-1) === '' && lines.at(-2) === '') lines.pop();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const text = lines.join('\n');
|
|
212
|
+
return crlf ? text.replace(/\n/g, '\r\n') : text;
|
|
213
|
+
}
|