Skip to content

Commit 0bc8d12

Browse files
committed
fix(docs): www links and stricter env-name declarations for the self-hosting lint
1 parent 9092d77 commit 0bc8d12

4 files changed

Lines changed: 85 additions & 12 deletions

File tree

‎apps/docs/content/docs/platform/self-hosting/chat.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ These are set on **Sim**, not on the Mothership.
2727

2828
## Use the Sim-hosted service
2929

30-
1. Sign in to [sim.ai](https://sim.ai) with any account and create a key at [sim.ai/selfhost/settings/chat-keys](https://sim.ai/selfhost/settings/chat-keys). The page exists only on Sim Cloud, not on your deployment.
30+
1. Sign in to [sim.ai](https://www.sim.ai) with any account and create a key at [sim.ai/selfhost/settings/chat-keys](https://www.sim.ai/selfhost/settings/chat-keys). The page exists only on Sim Cloud, not on your deployment.
3131
2. Set `COPILOT_API_KEY` to it, keep the other defaults, and recreate the app. On Compose, `npx sim-setup add chat` writes it for you.
3232
3. Remove `NEXT_PUBLIC_CHAT_DISABLED`, or set it to `false`.
3333

‎apps/docs/content/docs/platform/self-hosting/troubleshooting.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The browser's origin must equal `NEXT_PUBLIC_APP_URL`, including scheme and port
3737

3838
## Chat is unavailable
3939

40-
Requests fail with `401`, or Chat reports it is not configured: `COPILOT_API_KEY` is missing, or is not a key `SIM_AGENT_API_URL` accepts. For the Sim-hosted service, create a key at [sim.ai/selfhost/settings/chat-keys](https://sim.ai/selfhost/settings/chat-keys); a Mothership you run expects its `COPILOT_INBOUND_API_KEY`. Recreate the app after setting it. To hide Chat instead, set `NEXT_PUBLIC_CHAT_DISABLED=true`. See [Chat service](/platform/self-hosting/chat).
40+
Requests fail with `401`, or Chat reports it is not configured: `COPILOT_API_KEY` is missing, or is not a key `SIM_AGENT_API_URL` accepts. For the Sim-hosted service, create a key at [sim.ai/selfhost/settings/chat-keys](https://www.sim.ai/selfhost/settings/chat-keys); a Mothership you run expects its `COPILOT_INBOUND_API_KEY`. Recreate the app after setting it. To hide Chat instead, set `NEXT_PUBLIC_CHAT_DISABLED=true`. See [Chat service](/platform/self-hosting/chat).
4141

4242
## Certificate errors
4343

‎scripts/sync-self-hosting-docs.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
pickIntegrationPages,
99
renderCronTable,
1010
replaceBetweenMarkers,
11+
shellEnvNames,
12+
yamlEnvNames,
1113
} from './sync-self-hosting-docs'
1214

1315
const VALUES = `app:
@@ -168,3 +170,30 @@ describe('buildOAuthClientRows', () => {
168170
expect(() => build({ 'new-client': ['NEW_CLIENT_ID'] }, [])).toThrow('new-client')
169171
})
170172
})
173+
174+
describe('env declaration sources', () => {
175+
it('declares chart keys and references but not names that only appear in comments', () => {
176+
const values = [
177+
'app:',
178+
' env:',
179+
' REDIS_URL: "" # name: OTHER_COMMENT_NAME',
180+
' # COMMENT_ONLY_NAME: "75000"',
181+
'extraEnvVars:',
182+
' - name: EXTRA_SECRET',
183+
].join('\n')
184+
expect([...yamlEnvNames(values)].sort()).toEqual(['EXTRA_SECRET', 'REDIS_URL'])
185+
})
186+
187+
it('declares Compose assignments and references but not names in comments', () => {
188+
const compose = [
189+
' # Set COMMENT_ONLY_NAME=1 in .env to change it',
190+
" - 'DATABASE_URL=postgresql://\u0024{POSTGRES_USER:-postgres}@db'",
191+
' - LOG_LEVEL=\u0024{LOG_LEVEL:-} # not \u0024{OTHER_COMMENT_NAME}',
192+
].join('\n')
193+
expect([...shellEnvNames(compose)].sort()).toEqual([
194+
'DATABASE_URL',
195+
'LOG_LEVEL',
196+
'POSTGRES_USER',
197+
])
198+
})
199+
})

‎scripts/sync-self-hosting-docs.ts‎

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const MCP_CLIENT_LABELS: Record<string, { name: string; href: string }> = {
6161

6262
/**
6363
* Backticked names the declaration sources cannot see but the guide names on purpose: other
64-
* software's settings (Compose, Node, the AWS SDK, electron-builder, the EKS CNI), an error code,
65-
* provider scope names, and names Sim reads through a constant.
64+
* software's settings (Compose, Node, the AWS SDK, electron-builder, the EKS CNI, the Mothership), an
65+
* error code, a Linux capability, provider scope names, and names Sim reads through a constant.
6666
*/
6767
const ENV_TOKEN_ALLOWLIST = new Set([
6868
'COMPOSE_FILE',
@@ -85,6 +85,9 @@ const ENV_TOKEN_ALLOWLIST = new Set([
8585
'UNABLE_TO_GET_ISSUER_CERT',
8686
'READ_BOOKING',
8787
'READ_PROFILE',
88+
// A Linux capability the sandbox docs name, and a setting of the separately shipped Mothership.
89+
'DAC_OVERRIDE',
90+
'COPILOT_SHUTDOWN_HANDOFF_MS',
8891
// Read through a named constant rather than `process.env.NAME`.
8992
'OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT',
9093
'SIM_DESKTOP_ORIGIN',
@@ -302,9 +305,50 @@ export function zodEnvNames(source: string): Set<string> {
302305
return new Set([...source.matchAll(/^\s+([A-Z][A-Z0-9_]+)\s*:\s*z\./gm)].map((m) => m[1]))
303306
}
304307

305-
/** Every UPPER_SNAKE word in a config file, for files whose keys and comments name env vars. */
306-
export function upperSnakeWords(source: string): Set<string> {
307-
return new Set(source.match(/\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+\b/g) ?? [])
308+
const ENV_NAME = '[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+'
309+
310+
/** A YAML or shell line with its comment removed: a full-line `#` comment, or ` # …` after code. */
311+
function withoutComment(line: string): string {
312+
if (/^\s*#/.test(line)) return ''
313+
return line.replace(/\s+#.*$/, '')
314+
}
315+
316+
/**
317+
* Env names a chart file declares: mapping keys (` NAME: value`, `- NAME: value`) and
318+
* `name: NAME` / `"key" "NAME"` references, ignoring comments.
319+
*/
320+
export function yamlEnvNames(source: string): Set<string> {
321+
const names = new Set<string>()
322+
const key = new RegExp(`^\\s*(?:-\\s+)?(${ENV_NAME})\\s*:`)
323+
const reference = new RegExp(`(?:\\bname:\\s*|"key"\\s+)["']?(${ENV_NAME})\\b`, 'g')
324+
for (const raw of source.split('\n')) {
325+
const line = withoutComment(raw)
326+
const match = key.exec(line)
327+
if (match) names.add(match[1])
328+
for (const ref of line.matchAll(reference)) names.add(ref[1])
329+
}
330+
return names
331+
}
332+
333+
/** Env names a Compose file or crontab sets or reads (`NAME=`, `${NAME`, `$NAME`), ignoring comments. */
334+
export function shellEnvNames(source: string): Set<string> {
335+
const names = new Set<string>()
336+
const patterns = [
337+
new RegExp(`(?:^|[\\s'"-])(${ENV_NAME})=`, 'g'),
338+
new RegExp(`\\$\\{?(${ENV_NAME})`, 'g'),
339+
]
340+
for (const raw of source.split('\n')) {
341+
const line = withoutComment(raw)
342+
for (const pattern of patterns) for (const m of line.matchAll(pattern)) names.add(m[1])
343+
}
344+
return names
345+
}
346+
347+
/** Env names a TypeScript module spells as string literals (`'NAME'`). */
348+
export function quotedEnvNames(source: string): Set<string> {
349+
return new Set(
350+
[...source.matchAll(new RegExp(`['"\`](${ENV_NAME})['"\`]`, 'g'))].map((m) => m[1])
351+
)
308352
}
309353

310354
/**
@@ -346,21 +390,21 @@ function declaredEnvNames(): Set<string> {
346390
const names = new Set<string>([
347391
...zodEnvNames(read('apps/sim/lib/core/config/env.ts')),
348392
...zodEnvNames(read('apps/realtime/src/env.ts')),
349-
...upperSnakeWords(read('helm/sim/values.yaml')),
350-
...upperSnakeWords(read('docker/crontab')),
393+
...yamlEnvNames(read('helm/sim/values.yaml')),
394+
...shellEnvNames(read('docker/crontab')),
351395
])
352396
for (const file of readdirSync(ROOT).filter((f) => /^docker-compose.*\.ya?ml$/.test(f))) {
353-
for (const name of upperSnakeWords(read(file))) names.add(name)
397+
for (const name of shellEnvNames(read(file))) names.add(name)
354398
}
355399
const templatesDir = path.join(ROOT, 'helm/sim/templates')
356400
for (const file of readdirSync(templatesDir, { recursive: true, encoding: 'utf8' })) {
357401
if (!/\.(ya?ml|tpl|txt)$/.test(file)) continue
358-
for (const name of upperSnakeWords(read(`helm/sim/templates/${file}`))) names.add(name)
402+
for (const name of yamlEnvNames(read(`helm/sim/templates/${file}`))) names.add(name)
359403
}
360404
for (const file of sourceFilesReadingEnv()) {
361405
for (const name of envReads(read(file))) names.add(name)
362406
}
363-
for (const name of upperSnakeWords(read('packages/deployment-config/src/registration.ts'))) {
407+
for (const name of quotedEnvNames(read('packages/deployment-config/src/registration.ts'))) {
364408
names.add(name)
365409
}
366410
const poolProfiles = read('packages/db/pool-profiles.ts')

0 commit comments

Comments
 (0)