1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
import { eq } from "drizzle-orm";
import { db } from "../db";
import { systemConfig } from "../db/schema";
const CACHE_TTL_MS = 60_000;
type CacheEntry = { value: string; expiresAt: number };
const cache = new Map<string, CacheEntry>();
export function maskSecret(s: string | null | undefined): string {
const v = (s ?? "").trim();
if (!v) return "";
const underscore = v.indexOf("_");
const prefixLen =
underscore > 0 && underscore <= 4 ? underscore + 1 : Math.min(2, v.length);
const prefix = v.slice(0, prefixLen);
const tail = v.length > prefixLen + 4 ? v.slice(-2) : "";
return `${prefix}••••••${tail}`;
}
export function isMaskedValue(s: string | null | undefined): boolean {
if (!s) return false;
return s.includes("••••••");
}
export async function getConfigValue(
key: string,
fallbackEnv: string
): Promise<string> {
const cached = cache.get(key);
if (cached && cached.expiresAt > Date.now()) {
return cached.value || process.env[fallbackEnv] || "";
}
let dbValue = "";
try {
const [row] = await db
.select({ value: systemConfig.value })
.from(systemConfig)
.where(eq(systemConfig.key, key))
.limit(1);
dbValue = (row?.value ?? "").trim();
} catch (err) {
console.warn(
"[system-config] getConfigValue read failed:",
err instanceof Error ? err.message : err
);
}
cache.set(key, { value: dbValue, expiresAt: Date.now() + CACHE_TTL_MS });
return dbValue || process.env[fallbackEnv] || "";
}
export async function setConfigValue(
key: string,
value: string,
userId: string | null
): Promise<void> {
const trimmed = (value ?? "").trim();
await db
.insert(systemConfig)
.values({ key, value: trimmed, updatedByUserId: userId || null })
.onConflictDoUpdate({
target: systemConfig.key,
set: {
value: trimmed,
updatedByUserId: userId || null,
updatedAt: new Date(),
},
});
cache.set(key, { value: trimmed, expiresAt: Date.now() + CACHE_TTL_MS });
if (trimmed) process.env[key] = trimmed;
else delete process.env[key];
}
export async function loadConfigIntoEnv(): Promise<number> {
try {
const rows = await db
.select({ key: systemConfig.key, value: systemConfig.value })
.from(systemConfig);
let n = 0;
for (const r of rows) {
const v = (r.value ?? "").trim();
if (!v) continue;
process.env[r.key] = v;
cache.set(r.key, { value: v, expiresAt: Date.now() + CACHE_TTL_MS });
n++;
}
return n;
} catch (err) {
console.warn(
"[system-config] loadConfigIntoEnv skipped:",
err instanceof Error ? err.message : err
);
return 0;
}
}
export function __resetCache(): void {
cache.clear();
}
export interface IntegrationField {
key: string;
envFallback: string;
label: string;
helper: string;
helperLink?: { href: string; text: string };
isSecret: boolean;
group: "ai" | "email" | "scm" | "security" | "observability" | "webhook";
}
export const INTEGRATION_FIELDS: IntegrationField[] = [
{
key: "ANTHROPIC_API_KEY",
envFallback: "ANTHROPIC_API_KEY",
label: "Anthropic API key",
helper:
"Powers AI PR review, incident responder, commit messages, and auto-merge approval.",
helperLink: { href: "https://console.anthropic.com/", text: "console.anthropic.com" },
isSecret: true,
group: "ai",
},
{
key: "RESEND_API_KEY",
envFallback: "RESEND_API_KEY",
label: "Resend API key",
helper: "Verification emails, password reset, magic link sign-in.",
helperLink: { href: "https://resend.com/api-keys", text: "resend.com/api-keys" },
isSecret: true,
group: "email",
},
{
key: "EMAIL_FROM",
envFallback: "EMAIL_FROM",
label: "Email sender address",
helper: 'Format: `Gluecron <no-reply@your-domain>`.',
isSecret: false,
group: "email",
},
{
key: "GITHUB_TOKEN",
envFallback: "GITHUB_TOKEN",
label: "GitHub personal access token",
helper: "Used by the auto-merge sweep and GitHub-side API calls.",
helperLink: { href: "https://github.com/settings/tokens", text: "github.com/settings/tokens" },
isSecret: true,
group: "scm",
},
{
key: "GATETEST_URL",
envFallback: "GATETEST_URL",
label: "GateTest endpoint URL",
helper: "Push-time security scanner — leave blank to disable scans.",
isSecret: false,
group: "security",
},
{
key: "GATETEST_API_KEY",
envFallback: "GATETEST_API_KEY",
label: "GateTest API key",
helper: "Auth token sent with each scan request.",
isSecret: true,
group: "security",
},
{
key: "DEPLOY_EVENT_TOKEN",
envFallback: "DEPLOY_EVENT_TOKEN",
label: "Deploy events token",
helper:
"Shared secret for the live deploy timeline and AI incident responder.",
isSecret: true,
group: "observability",
},
{
key: "CRONTECH_DEPLOY_URL",
envFallback: "CRONTECH_DEPLOY_URL",
label: "Crontech webhook URL",
helper: "Optional: notify Crontech on every push to the canonical repo.",
isSecret: false,
group: "webhook",
},
{
key: "CRONTECH_HMAC_SECRET",
envFallback: "CRONTECH_HMAC_SECRET",
label: "Crontech HMAC secret",
helper: "Used to sign outbound Crontech webhook payloads.",
isSecret: true,
group: "webhook",
},
];
|