@myrialabs/clopen 0.4.38 → 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 +48 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +9 -1
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/db-client-connection-queries.ts +19 -0
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +10 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- 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 +44 -0
- package/backend/db-client/integrations/links.ts +564 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- 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/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +523 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +194 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -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/index.ts +4 -0
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +28 -9
- package/backend/integrations/registry/index.ts +8 -1
- 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 +62 -0
- package/backend/integrations/registry/providers/vercel.ts +47 -0
- package/backend/integrations/registry/types.ts +2 -0
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -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/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/env.ts +142 -0
- package/backend/ws/db-client/index.ts +22 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/index.ts +6 -2
- package/backend/ws/memory/crud.ts +4 -16
- 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/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- 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-DSHIANSy.js → index-D4igjF6e.js} +1 -1
- package/dist/assets/{index-CyH7fSbR.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 +13 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +3 -0
- package/shared/types/db-client/integrations.ts +204 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +2 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-D2IOjftb.css +0 -1
- package/dist/assets/main-DM-tHKbW.js +0 -1152
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A dotenv reader that remembers where everything was.
|
|
3
|
+
*
|
|
4
|
+
* `dotenv` and friends answer "what is the value of KEY", which is the wrong
|
|
5
|
+
* question for a writer: updating a variable IN PLACE means knowing which lines
|
|
6
|
+
* held it, whether it was quoted, and whether it was commented out. A parse
|
|
7
|
+
* that returns a plain object throws all of that away and leaves rewriting the
|
|
8
|
+
* file as the only option — which is how tools end up reformatting comments and
|
|
9
|
+
* ordering that the user put there on purpose.
|
|
10
|
+
*
|
|
11
|
+
* Commented assignments are returned too, marked. `.env.example` is often the
|
|
12
|
+
* only record of the variable names a project expects, and half of those files
|
|
13
|
+
* document optional settings as `# REDIS_URL=`, so a detector that ignored
|
|
14
|
+
* comments would miss the shape it exists to find.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** One `KEY=value`, and where it lives. */
|
|
18
|
+
export interface DotenvAssignment {
|
|
19
|
+
key: string;
|
|
20
|
+
value: string;
|
|
21
|
+
/** The original text, including every line the value spans. */
|
|
22
|
+
raw: string;
|
|
23
|
+
/** 0-based index of the first line. */
|
|
24
|
+
line: number;
|
|
25
|
+
/** How many lines the assignment spans — more than one for a quoted value. */
|
|
26
|
+
lineCount: number;
|
|
27
|
+
exported: boolean;
|
|
28
|
+
/** True for `# KEY=value`: documentation, not configuration. */
|
|
29
|
+
commented: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* `[^\r\n]*` rather than `.*`, and the reason is a bug this had.
|
|
34
|
+
*
|
|
35
|
+
* In JavaScript `.` does not match `\r`, so on a file written on Windows every
|
|
36
|
+
* line ends one character past what `.*$` can reach and the pattern matched
|
|
37
|
+
* NOTHING — a CRLF dotenv file parsed as empty, which would have made detection
|
|
38
|
+
* find no variables and every write append a duplicate.
|
|
39
|
+
*/
|
|
40
|
+
const ASSIGNMENT = /^(\s*)(#+\s*)?(export\s+)?([A-Za-z_][A-Za-z0-9_]*)[ \t]*=([^\r\n]*)\r?$/;
|
|
41
|
+
|
|
42
|
+
/** Decode a double-quoted value's escapes. Single quotes are literal. */
|
|
43
|
+
function unescapeDouble(raw: string): string {
|
|
44
|
+
return raw.replace(/\\([nrt"'\\$`])/g, (_match, char: string) => {
|
|
45
|
+
if (char === 'n') return '\n';
|
|
46
|
+
if (char === 'r') return '\r';
|
|
47
|
+
if (char === 't') return '\t';
|
|
48
|
+
return char;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The index of the quote that closes the value, or -1.
|
|
54
|
+
*
|
|
55
|
+
* Only a double-quoted value honours backslash escapes, which is what every
|
|
56
|
+
* reader in common use does — inside single quotes a backslash is a backslash,
|
|
57
|
+
* so skipping the next character there would read past a legitimate close.
|
|
58
|
+
*/
|
|
59
|
+
function findClosingQuote(body: string, quote: string): number {
|
|
60
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
61
|
+
if (quote === '"' && body[index] === '\\') {
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (body[index] === quote) return index;
|
|
66
|
+
}
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Read a value that may run past the end of its first line.
|
|
72
|
+
*
|
|
73
|
+
* Returns how many EXTRA lines were consumed so the caller can keep its own
|
|
74
|
+
* line index honest — the whole reason this module exists.
|
|
75
|
+
*/
|
|
76
|
+
function readValue(
|
|
77
|
+
first: string,
|
|
78
|
+
lines: string[],
|
|
79
|
+
index: number
|
|
80
|
+
): { value: string; extraLines: number } {
|
|
81
|
+
const trimmed = first.trimStart();
|
|
82
|
+
const quote = trimmed[0];
|
|
83
|
+
|
|
84
|
+
if (quote !== '"' && quote !== "'" && quote !== '`') {
|
|
85
|
+
// Unquoted. Everything from an unescaped `#` onwards is a comment, which
|
|
86
|
+
// is what every reader in common use does.
|
|
87
|
+
const withoutComment = trimmed.split('#')[0] ?? '';
|
|
88
|
+
return { value: withoutComment.trim(), extraLines: 0 };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let body = trimmed.slice(1);
|
|
92
|
+
let extraLines = 0;
|
|
93
|
+
|
|
94
|
+
for (;;) {
|
|
95
|
+
const closing = findClosingQuote(body, quote);
|
|
96
|
+
if (closing !== -1) {
|
|
97
|
+
const inner = body.slice(0, closing);
|
|
98
|
+
return { value: quote === '"' ? unescapeDouble(inner) : inner, extraLines };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const next = lines[index + extraLines + 1];
|
|
102
|
+
// Unterminated at end of file. Taking what there is beats discarding the
|
|
103
|
+
// assignment: the caller is deciding whether to rewrite this line, and a
|
|
104
|
+
// key it cannot see is a key it would append a duplicate of.
|
|
105
|
+
if (next === undefined) {
|
|
106
|
+
return { value: quote === '"' ? unescapeDouble(body) : body, extraLines };
|
|
107
|
+
}
|
|
108
|
+
body = `${body}\n${next}`;
|
|
109
|
+
extraLines += 1;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function parseDotenv(content: string): DotenvAssignment[] {
|
|
114
|
+
const lines = content.split('\n');
|
|
115
|
+
const found: DotenvAssignment[] = [];
|
|
116
|
+
|
|
117
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
118
|
+
const match = ASSIGNMENT.exec(lines[index]);
|
|
119
|
+
if (!match) continue;
|
|
120
|
+
|
|
121
|
+
const [, , hash, exported, key, rest] = match;
|
|
122
|
+
const { value, extraLines } = readValue(rest, lines, index);
|
|
123
|
+
const lineCount = extraLines + 1;
|
|
124
|
+
|
|
125
|
+
found.push({
|
|
126
|
+
key,
|
|
127
|
+
value,
|
|
128
|
+
raw: lines.slice(index, index + lineCount).join('\n'),
|
|
129
|
+
line: index,
|
|
130
|
+
lineCount,
|
|
131
|
+
exported: Boolean(exported),
|
|
132
|
+
commented: Boolean(hash)
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
index += extraLines;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return found;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The assignment a reader would actually use for `key`, or null.
|
|
143
|
+
*
|
|
144
|
+
* The LAST one wins, and commented ones do not count — the two rules that
|
|
145
|
+
* decide whether writing a variable will have any effect.
|
|
146
|
+
*/
|
|
147
|
+
export function effectiveAssignment(
|
|
148
|
+
assignments: DotenvAssignment[],
|
|
149
|
+
key: string
|
|
150
|
+
): DotenvAssignment | null {
|
|
151
|
+
let winner: DotenvAssignment | null = null;
|
|
152
|
+
for (const assignment of assignments) {
|
|
153
|
+
if (assignment.commented) continue;
|
|
154
|
+
if (assignment.key === key) winner = assignment;
|
|
155
|
+
}
|
|
156
|
+
return winner;
|
|
157
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Putting variables into a project's dotenv file.
|
|
3
|
+
*
|
|
4
|
+
* One rule is a hard refusal: **never a file git TRACKS.** For DB Client the
|
|
5
|
+
* cost is committing a live database password; for worktree branching it is
|
|
6
|
+
* worse — "Apply to Main" would carry the branch connection string into the
|
|
7
|
+
* main project, overwriting the real one with a URL pointing at a database that
|
|
8
|
+
* deleting the worktree destroys. Both are refused and reported rather than
|
|
9
|
+
* written and hoped about, and the refusal is overridable only where the caller
|
|
10
|
+
* says so explicitly.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here throws for an ordinary failure. Every caller has already done
|
|
13
|
+
* the expensive, visible thing the user asked for — created a worktree, linked
|
|
14
|
+
* a database — and a variable that did not land is worth a sentence, not an
|
|
15
|
+
* exception that undoes the rest.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import fs from 'fs/promises';
|
|
19
|
+
import path from 'path';
|
|
20
|
+
import { removeEnvKeys, upsertEnvKeys } from './edit';
|
|
21
|
+
import { isSafeEnvFileName } from './keys';
|
|
22
|
+
import { isTrackedInGit } from './git';
|
|
23
|
+
import { debug } from '$shared/utils/logger';
|
|
24
|
+
|
|
25
|
+
export type EnvWriteStatus = 'written' | 'unchanged' | 'skipped-tracked' | 'failed';
|
|
26
|
+
|
|
27
|
+
export interface EnvWriteResult {
|
|
28
|
+
status: EnvWriteStatus;
|
|
29
|
+
/** One sentence, naming what happened and what to do. Null when it worked. */
|
|
30
|
+
detail: string | null;
|
|
31
|
+
fileName: string;
|
|
32
|
+
updated: string[];
|
|
33
|
+
appended: string[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface EnvWriteInput {
|
|
37
|
+
root: string;
|
|
38
|
+
fileName: string;
|
|
39
|
+
vars: Record<string, string>;
|
|
40
|
+
/** A comment above the appended lines, naming where they came from. */
|
|
41
|
+
note?: string;
|
|
42
|
+
/** Write even though git tracks the file. The caller must have asked. */
|
|
43
|
+
allowTracked?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The file as it is, or an empty string when it does not exist yet. */
|
|
47
|
+
export async function readEnvFile(
|
|
48
|
+
root: string,
|
|
49
|
+
fileName: string
|
|
50
|
+
): Promise<{ text: string; exists: boolean }> {
|
|
51
|
+
try {
|
|
52
|
+
return { text: await fs.readFile(path.join(root, fileName), 'utf-8'), exists: true };
|
|
53
|
+
} catch {
|
|
54
|
+
return { text: '', exists: false };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface EnvWritePlan {
|
|
59
|
+
fileName: string;
|
|
60
|
+
exists: boolean;
|
|
61
|
+
/** The file as it is now. */
|
|
62
|
+
current: string;
|
|
63
|
+
/** The file as it would be. */
|
|
64
|
+
next: string;
|
|
65
|
+
updated: string[];
|
|
66
|
+
appended: string[];
|
|
67
|
+
unchanged: string[];
|
|
68
|
+
/** True when git tracks the target, which refuses the write by default. */
|
|
69
|
+
tracked: boolean;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Work out the write without performing it.
|
|
74
|
+
*
|
|
75
|
+
* Exists so the panel can show a diff of someone's own configuration file
|
|
76
|
+
* before touching it, and so `writeEnvVars` and the preview can never disagree
|
|
77
|
+
* about what would happen.
|
|
78
|
+
*/
|
|
79
|
+
export async function planEnvWrite(input: EnvWriteInput): Promise<EnvWritePlan> {
|
|
80
|
+
if (!isSafeEnvFileName(input.fileName)) {
|
|
81
|
+
throw new Error(`"${input.fileName}" is not a dotenv file in the project root.`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const [{ text, exists }, tracked] = await Promise.all([
|
|
85
|
+
readEnvFile(input.root, input.fileName),
|
|
86
|
+
isTrackedInGit(input.root, input.fileName)
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const result = upsertEnvKeys(text, input.vars, { note: input.note });
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
fileName: input.fileName,
|
|
93
|
+
exists,
|
|
94
|
+
current: text,
|
|
95
|
+
next: result.text,
|
|
96
|
+
updated: result.updated,
|
|
97
|
+
appended: result.appended,
|
|
98
|
+
unchanged: result.unchanged,
|
|
99
|
+
tracked
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export async function writeEnvVars(input: EnvWriteInput): Promise<EnvWriteResult> {
|
|
104
|
+
const empty = { fileName: input.fileName, updated: [], appended: [] };
|
|
105
|
+
|
|
106
|
+
let plan: EnvWritePlan;
|
|
107
|
+
try {
|
|
108
|
+
plan = await planEnvWrite(input);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
return { status: 'failed', detail: messageOf(error), ...empty };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (plan.tracked && !input.allowTracked) {
|
|
114
|
+
return {
|
|
115
|
+
status: 'skipped-tracked',
|
|
116
|
+
detail: `git tracks ${input.fileName}, so writing a password into it would commit one — add it to .gitignore or pick a file that is ignored.`,
|
|
117
|
+
...empty
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (plan.next === plan.current && plan.exists) {
|
|
122
|
+
return {
|
|
123
|
+
status: 'unchanged',
|
|
124
|
+
detail: null,
|
|
125
|
+
fileName: input.fileName,
|
|
126
|
+
updated: [],
|
|
127
|
+
appended: []
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
try {
|
|
132
|
+
await fs.writeFile(path.join(input.root, input.fileName), plan.next, 'utf-8');
|
|
133
|
+
debug.log('env-files', `Wrote ${plan.updated.length + plan.appended.length} variable(s) into ${input.fileName}`);
|
|
134
|
+
return {
|
|
135
|
+
status: 'written',
|
|
136
|
+
detail: null,
|
|
137
|
+
fileName: input.fileName,
|
|
138
|
+
updated: plan.updated,
|
|
139
|
+
appended: plan.appended
|
|
140
|
+
};
|
|
141
|
+
} catch (error) {
|
|
142
|
+
return { status: 'failed', detail: `Could not write ${input.fileName}: ${messageOf(error)}`, ...empty };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Take the managed block and every replaced value back out.
|
|
148
|
+
*
|
|
149
|
+
* Silent about a missing file: there is nothing to undo, which is the outcome
|
|
150
|
+
* the caller wanted.
|
|
151
|
+
*/
|
|
152
|
+
export async function clearEnvVars(input: {
|
|
153
|
+
root: string;
|
|
154
|
+
fileName: string;
|
|
155
|
+
keys: string[];
|
|
156
|
+
/** Remove an appended key only while it still holds this value. */
|
|
157
|
+
values?: Record<string, string>;
|
|
158
|
+
}): Promise<{ changed: boolean }> {
|
|
159
|
+
if (!isSafeEnvFileName(input.fileName)) return { changed: false };
|
|
160
|
+
const target = path.join(input.root, input.fileName);
|
|
161
|
+
try {
|
|
162
|
+
const existing = await fs.readFile(target, 'utf-8');
|
|
163
|
+
const next = removeEnvKeys(existing, input.keys, { values: input.values });
|
|
164
|
+
if (next === existing) return { changed: false };
|
|
165
|
+
await fs.writeFile(target, next, 'utf-8');
|
|
166
|
+
return { changed: true };
|
|
167
|
+
} catch {
|
|
168
|
+
// The file is gone, or was never written. Either way there is no block.
|
|
169
|
+
return { changed: false };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function messageOf(error: unknown): string {
|
|
174
|
+
return error instanceof Error ? error.message : String(error);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Worktree branching's write, in its own words.
|
|
179
|
+
*
|
|
180
|
+
* IN PLACE, like every other write here. A worktree is a FILE COPY of the
|
|
181
|
+
* project and therefore already carries the project's own `DATABASE_URL` — so
|
|
182
|
+
* an earlier version appended a marked block at the end and relied on readers
|
|
183
|
+
* taking the last assignment. It worked and it read as if it did not: the
|
|
184
|
+
* project's value sat untouched at the top of the file, and anyone opening it
|
|
185
|
+
* saw their own database named first. Replacing the line where it stands says
|
|
186
|
+
* what is true, and the previous value survives as the comment above it.
|
|
187
|
+
*
|
|
188
|
+
* A tracked file is refused outright with no override, because the danger there
|
|
189
|
+
* is not a committed password but "Apply to Main" overwriting the real database
|
|
190
|
+
* URL with a disposable one.
|
|
191
|
+
*/
|
|
192
|
+
export async function writeWorktreeEnv(input: {
|
|
193
|
+
worktreeRoot: string;
|
|
194
|
+
fileName: string;
|
|
195
|
+
vars: Record<string, string>;
|
|
196
|
+
note?: string;
|
|
197
|
+
}): Promise<{ status: 'written' | 'skipped-tracked' | 'failed'; detail: string | null }> {
|
|
198
|
+
const result = await writeEnvVars({
|
|
199
|
+
root: input.worktreeRoot,
|
|
200
|
+
fileName: input.fileName,
|
|
201
|
+
vars: input.vars,
|
|
202
|
+
note: input.note
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (result.status === 'skipped-tracked') {
|
|
206
|
+
return {
|
|
207
|
+
status: 'skipped-tracked',
|
|
208
|
+
detail: `git tracks ${input.fileName}, so writing to it would carry the branch connection string into the main project — add it to .gitignore or point branching at a file that is ignored.`
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
// "Unchanged" means the block already said exactly this, which is a write
|
|
212
|
+
// that succeeded — reporting it as anything else would light up the retry.
|
|
213
|
+
if (result.status === 'unchanged') return { status: 'written', detail: null };
|
|
214
|
+
return { status: result.status, detail: result.detail };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Put a worktree's dotenv file back the way branching found it. */
|
|
218
|
+
export async function clearWorktreeEnv(
|
|
219
|
+
worktreeRoot: string,
|
|
220
|
+
fileName: string,
|
|
221
|
+
vars: Record<string, string> = {}
|
|
222
|
+
): Promise<void> {
|
|
223
|
+
await clearEnvVars({
|
|
224
|
+
root: worktreeRoot,
|
|
225
|
+
fileName,
|
|
226
|
+
keys: Object.keys(vars),
|
|
227
|
+
values: vars
|
|
228
|
+
});
|
|
229
|
+
}
|
package/backend/index.ts
CHANGED
|
@@ -69,6 +69,7 @@ import { sessionCleanupScheduler } from './auth/session-cleanup';
|
|
|
69
69
|
import { portMonitor } from './ports/monitor';
|
|
70
70
|
import { containerMonitor } from './containers/monitor';
|
|
71
71
|
import { stopAllLogStreams as stopAllContainerLogStreams } from './containers/logs';
|
|
72
|
+
import { stopAllBuildLogStreams } from './deployments/log-streams';
|
|
72
73
|
import { uploadTempCleanup } from './http/upload-temp-cleanup';
|
|
73
74
|
import { ws as wsServer } from './utils/ws';
|
|
74
75
|
import { messageRateLimiter } from './ws/message-rate-limiter';
|
|
@@ -362,6 +363,9 @@ async function gracefulShutdown() {
|
|
|
362
363
|
// Same for the container list, and the log streams it may still be pumping
|
|
363
364
|
stopAllContainerLogStreams();
|
|
364
365
|
containerMonitor.stop();
|
|
366
|
+
// Build-log follows are open HTTPS responses against a provider; nothing
|
|
367
|
+
// closes them but us.
|
|
368
|
+
stopAllBuildLogStreams();
|
|
365
369
|
// Close MCP remote server (before engines, as they may still reference it)
|
|
366
370
|
await closeMcpServer();
|
|
367
371
|
// Cleanup browser preview sessions
|
|
@@ -38,11 +38,26 @@ export type AccountProbe = (
|
|
|
38
38
|
projectId: string | null
|
|
39
39
|
) => Promise<{ status: IntegrationStatus; detail: string | null } | null>;
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Probes per provider, in registration order.
|
|
43
|
+
*
|
|
44
|
+
* A LIST rather than one entry, because a provider can serve more than one
|
|
45
|
+
* surface: Neon offers `database` to DB Client and `worktree-branching` to the
|
|
46
|
+
* worktree manager, and each surface registers the probe that speaks for its
|
|
47
|
+
* own capability. A map would have let whichever module loaded last silently
|
|
48
|
+
* replace the other's, so an account using only the losing capability would
|
|
49
|
+
* report on something it had switched off.
|
|
50
|
+
*
|
|
51
|
+
* They are tried in order and the first non-null answer wins, which is exactly
|
|
52
|
+
* what the "returns null when it has nothing to say" contract was written for.
|
|
53
|
+
*/
|
|
54
|
+
const providerProbes = new Map<string, AccountProbe[]>();
|
|
42
55
|
|
|
43
56
|
/** Register a provider-specific probe. Called at module load by the surface. */
|
|
44
57
|
export function registerAccountProbe(provider: string, probe: AccountProbe): void {
|
|
45
|
-
providerProbes.
|
|
58
|
+
const existing = providerProbes.get(provider);
|
|
59
|
+
if (existing) existing.push(probe);
|
|
60
|
+
else providerProbes.set(provider, [probe]);
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
/**
|
|
@@ -66,8 +81,7 @@ export async function checkAccountHealth(accountId: string): Promise<{ status: I
|
|
|
66
81
|
// A surface probe is the more specific answer when there is one: it talks to
|
|
67
82
|
// the API the credential was issued for, rather than to an MCP server that
|
|
68
83
|
// happens to accept the same token.
|
|
69
|
-
const providerProbe
|
|
70
|
-
if (providerProbe) {
|
|
84
|
+
for (const providerProbe of providerProbes.get(account.provider) ?? []) {
|
|
71
85
|
try {
|
|
72
86
|
const result = await providerProbe(accountId, account.project_id);
|
|
73
87
|
if (result) {
|
|
Binary file
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
* The `agent-tools` projector: an account with agent tools owns one
|
|
3
3
|
* `mcp_servers` row.
|
|
4
4
|
*
|
|
5
|
+
* It returns a single-element list because the contract is plural, not because
|
|
6
|
+
* there is a second row coming: a preset names ONE slug, so an account either
|
|
7
|
+
* owns that row or owns nothing.
|
|
8
|
+
*
|
|
5
9
|
* Nothing downstream of this row knows accounts exist. `resolveServerRow()`,
|
|
6
10
|
* every per-engine config builder and the `/mcp/ext/<slug>` proxy read the row
|
|
7
11
|
* exactly as they read a hand-installed one — which is the whole point of
|
|
@@ -72,7 +76,7 @@ export const mcpProjector: Projector = {
|
|
|
72
76
|
capability: 'agent-tools',
|
|
73
77
|
targetKind: 'mcp_server',
|
|
74
78
|
|
|
75
|
-
project(context: ProjectionContext): ProjectionResult {
|
|
79
|
+
project(context: ProjectionContext): ProjectionResult[] {
|
|
76
80
|
const preset = presetOf(context);
|
|
77
81
|
const existing: McpServerRow | null = mcpServerQueries.getBySlug(preset.slug);
|
|
78
82
|
|
|
@@ -93,7 +97,7 @@ export const mcpProjector: Projector = {
|
|
|
93
97
|
// an ordinary custom row rather than needing a fourth source value.
|
|
94
98
|
source: 'custom'
|
|
95
99
|
});
|
|
96
|
-
return { targetKind: 'mcp_server', targetId: String(row.id), adopted: false, restore: null };
|
|
100
|
+
return [{ targetKind: 'mcp_server', targetId: String(row.id), adopted: false, restore: null }];
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
// ADOPT rather than create a sibling. A user who installed this server by
|
|
@@ -135,7 +139,7 @@ export const mcpProjector: Projector = {
|
|
|
135
139
|
}
|
|
136
140
|
}
|
|
137
141
|
|
|
138
|
-
return { targetKind: 'mcp_server', targetId, adopted, restore };
|
|
142
|
+
return [{ targetKind: 'mcp_server', targetId, adopted, restore }];
|
|
139
143
|
},
|
|
140
144
|
|
|
141
145
|
release(context: ProjectionContext, targetId: string, adopted: boolean, restore: unknown | null): void {
|
|
@@ -7,15 +7,27 @@
|
|
|
7
7
|
*
|
|
8
8
|
* One projector per capability — but ONLY for capabilities whose surface owns a
|
|
9
9
|
* table to write into. `agent-tools` writes an `mcp_servers` row, `database`
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* writes `db_client_connections` ones, `worktree-branching` writes them too —
|
|
11
|
+
* one per live worktree branch, from `worktree_branches` — and `notifications`
|
|
12
|
+
* is registered by the task that builds that surface.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
14
|
+
* TWO CAPABILITIES CAN TARGET THE SAME TABLE, and one account can carry both: a
|
|
15
|
+
* Neon account owns a connection for the project it linked AND one per worktree
|
|
16
|
+
* branch it cut. That works only because migration 077 widened the projection
|
|
17
|
+
* key with `target_id`; releasing by capability alone would tear down the
|
|
18
|
+
* other's rows on every pass.
|
|
19
|
+
*
|
|
20
|
+
* A projector returns a LIST. Agent tools happens to produce exactly one row
|
|
21
|
+
* per account, but that is a fact about MCP presets rather than about
|
|
22
|
+
* projection: one database credential reaches every project the token can see,
|
|
23
|
+
* and the user picks as many of them as they want (see migration 077).
|
|
24
|
+
*
|
|
25
|
+
* `work` and `deployments` deliberately have NO projector. Work items are never copied into the
|
|
15
26
|
* database (see migration 074 for why), so there is no derived row to keep in
|
|
16
27
|
* step — the Issues & PRs surface registers an ADAPTER in
|
|
17
|
-
* `backend/
|
|
18
|
-
*
|
|
28
|
+
* `backend/work/registry.ts` and reads the account directly, and Deployments
|
|
29
|
+
* does the same in `backend/deployments/registry.ts`. A capability without a
|
|
30
|
+
* table is a capability without a projection.
|
|
19
31
|
*/
|
|
20
32
|
|
|
21
33
|
import type { IntegrationCapability, IntegrationTargetKind } from '$shared/types/integrations';
|
|
@@ -44,8 +56,15 @@ export interface ProjectionResult {
|
|
|
44
56
|
export interface Projector {
|
|
45
57
|
capability: IntegrationCapability;
|
|
46
58
|
targetKind: IntegrationTargetKind;
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Create or refresh every derived row this account should own right now.
|
|
61
|
+
*
|
|
62
|
+
* Called on connect, credential change and capability enable. Anything the
|
|
63
|
+
* account previously projected that is NOT in the returned list gets
|
|
64
|
+
* released, so removing a link and disabling a capability are the same
|
|
65
|
+
* operation as far as the pass is concerned.
|
|
66
|
+
*/
|
|
67
|
+
project(context: ProjectionContext): ProjectionResult[];
|
|
68
|
+
/** Remove one derived row, or hand an adopted one back untouched. */
|
|
50
69
|
release(context: ProjectionContext, targetId: string, adopted: boolean, restore: unknown | null): void;
|
|
51
70
|
}
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
import context7 from './providers/context7';
|
|
11
11
|
import firecrawl from './providers/firecrawl';
|
|
12
12
|
import github from './providers/github';
|
|
13
|
+
import neon from './providers/neon';
|
|
14
|
+
import supabase from './providers/supabase';
|
|
15
|
+
import vercel from './providers/vercel';
|
|
13
16
|
import type { IntegrationProvider } from './types';
|
|
14
17
|
import type { IntegrationProviderInfo } from '$shared/types/integrations';
|
|
15
18
|
|
|
@@ -20,7 +23,10 @@ export { defineProvider } from './define';
|
|
|
20
23
|
export const PROVIDERS: readonly IntegrationProvider[] = [
|
|
21
24
|
context7,
|
|
22
25
|
firecrawl,
|
|
23
|
-
github
|
|
26
|
+
github,
|
|
27
|
+
neon,
|
|
28
|
+
supabase,
|
|
29
|
+
vercel
|
|
24
30
|
];
|
|
25
31
|
|
|
26
32
|
const byId = new Map(PROVIDERS.map((provider) => [provider.id, provider]));
|
|
@@ -42,6 +48,7 @@ export function toProviderInfo(provider: IntegrationProvider): IntegrationProvid
|
|
|
42
48
|
category: provider.category,
|
|
43
49
|
description: provider.description,
|
|
44
50
|
docsUrl: provider.docsUrl,
|
|
51
|
+
consoleUrl: provider.consoleUrl,
|
|
45
52
|
authMethod: provider.authMethod,
|
|
46
53
|
credentialFields: provider.credentialFields,
|
|
47
54
|
capabilities: [...provider.capabilities],
|
|
@@ -16,6 +16,7 @@ export default defineProvider({
|
|
|
16
16
|
description:
|
|
17
17
|
'Pulls current, version-accurate documentation for a library straight into the session, so the agent stops writing against the API it remembers.',
|
|
18
18
|
docsUrl: 'https://context7.com',
|
|
19
|
+
consoleUrl: 'https://context7.com',
|
|
19
20
|
authMethod: 'api-key',
|
|
20
21
|
capabilities: ['agent-tools'],
|
|
21
22
|
credentialFields: [
|
|
@@ -15,6 +15,7 @@ export default defineProvider({
|
|
|
15
15
|
description:
|
|
16
16
|
'Crawls and converts live sites into clean markdown. Pairs with the browser automation tools rather than replacing them — this is for reading a site at scale, not driving one.',
|
|
17
17
|
docsUrl: 'https://firecrawl.dev',
|
|
18
|
+
consoleUrl: 'https://firecrawl.dev',
|
|
18
19
|
authMethod: 'api-key',
|
|
19
20
|
capabilities: ['agent-tools'],
|
|
20
21
|
credentialFields: [
|
|
@@ -39,6 +39,7 @@ export default defineProvider({
|
|
|
39
39
|
description:
|
|
40
40
|
'Issues, pull requests and Actions for the repository this project pushes to. Start work on an issue in its own worktree, open and merge pull requests, and send a failing CI run into the chat.',
|
|
41
41
|
docsUrl: 'https://github.com/settings/tokens/new?scopes=repo,read:org&description=Clopen',
|
|
42
|
+
consoleUrl: 'https://github.com',
|
|
42
43
|
authMethod: 'api-key',
|
|
43
44
|
capabilities: ['work', 'agent-tools'],
|
|
44
45
|
// Connecting GitHub means "show me my work", not "give every agent GitHub
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neon — the first provider behind the `worktree-branching` capability, and the
|
|
3
|
+
* second behind `database`.
|
|
4
|
+
*
|
|
5
|
+
* ONE CREDENTIAL, TWO CAPABILITIES, which is the shape this provider was picked
|
|
6
|
+
* to prove. The same API key both lists projects for DB Client and cuts a
|
|
7
|
+
* branch for a worktree, so making it two accounts would mean pasting one key
|
|
8
|
+
* twice and rotating it in two places — the mistake `Task 3` refused for Vercel
|
|
9
|
+
* teams and `Task 4` refused for Supabase projects.
|
|
10
|
+
*
|
|
11
|
+
* Worth knowing about Neon's keys: they come in two scopes. A PERSONAL key
|
|
12
|
+
* reaches the projects its user owns; an ORGANISATION key reaches that
|
|
13
|
+
* organisation's and nothing else. Neither is wrong and the difference is
|
|
14
|
+
* invisible until a project the user can plainly see in the console is missing
|
|
15
|
+
* from the list, so the credential help names it rather than leaving it to be
|
|
16
|
+
* discovered.
|
|
17
|
+
*
|
|
18
|
+
* NO `agent-tools`, even though Neon ships an MCP server. That server uses its
|
|
19
|
+
* own OAuth — a different audience from this REST key — so declaring it would
|
|
20
|
+
* mean projecting a row this credential cannot fill, which is the same reason
|
|
21
|
+
* `Task 3` left Vercel's MCP alone.
|
|
22
|
+
*
|
|
23
|
+
* NO `inbound-events`. Neon's webhooks are an organisation-level billing and
|
|
24
|
+
* usage feed, not something any surface here subscribes to yet.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { defineProvider } from '../define';
|
|
28
|
+
|
|
29
|
+
export default defineProvider({
|
|
30
|
+
id: 'neon',
|
|
31
|
+
name: 'Neon',
|
|
32
|
+
category: 'database',
|
|
33
|
+
description:
|
|
34
|
+
'Serverless Postgres in DB Client, plus a database branch per worktree: creating a worktree cuts a copy-on-write branch and points its connection string at it, and deleting the worktree deletes the branch.',
|
|
35
|
+
docsUrl: 'https://console.neon.tech/app/settings/api-keys',
|
|
36
|
+
consoleUrl: 'https://console.neon.tech',
|
|
37
|
+
authMethod: 'api-key',
|
|
38
|
+
capabilities: ['database', 'worktree-branching'],
|
|
39
|
+
// Both ON by default. Unlike GitHub's `agent-tools` — which hands an agent
|
|
40
|
+
// write access to every repository and therefore has to be asked for —
|
|
41
|
+
// neither of these does anything until the user points a project at a
|
|
42
|
+
// database, so defaulting them off would only add a step before the feature
|
|
43
|
+
// they connected the account for.
|
|
44
|
+
credentialFields: [
|
|
45
|
+
{
|
|
46
|
+
name: 'apiKey',
|
|
47
|
+
label: 'API key',
|
|
48
|
+
placeholder: 'napi_…',
|
|
49
|
+
help:
|
|
50
|
+
'Neon console → Account settings → API keys. A PERSONAL key reaches the projects you own; an ORGANISATION key reaches only that organisation\'s. Pick the one that owns the database you want to branch.',
|
|
51
|
+
isSecret: true,
|
|
52
|
+
isRequired: true
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
});
|