2026-06-13 00:47:32 +08:00
|
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
|
import { Context } from 'cordis'
|
|
|
|
|
import Loader from '@cordisjs/plugin-loader'
|
|
|
|
|
|
|
|
|
|
// Load DEEPSEEK_API_KEY / DEEPSEEK_BASE_URL from a gitignored repo-root .env
|
|
|
|
|
// (Node >= 21.7 native). Absent file is fine — the environment may already
|
2026-06-16 11:10:25 +08:00
|
|
|
// carry the variables; cordis.yml reads them via the `!!js` tag. A
|
|
|
|
|
// present-but-unreadable/malformed .env is a real misconfiguration: surface it
|
|
|
|
|
// rather than silently running with the wrong environment.
|
2026-06-13 00:47:32 +08:00
|
|
|
try {
|
|
|
|
|
process.loadEnvFile(new URL('../../.env', import.meta.url).pathname)
|
2026-06-16 11:10:25 +08:00
|
|
|
} catch (error) {
|
|
|
|
|
if ((error as NodeJS.ErrnoException | null)?.code !== 'ENOENT') {
|
|
|
|
|
process.stderr.write(`coding-agent: failed to load .env: ${String(error)}\n`)
|
|
|
|
|
}
|
|
|
|
|
// ENOENT (no .env) is fine — rely on the ambient environment.
|
2026-06-13 00:47:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Boot a Cordis app from this example's cordis.yml — the same shape as the
|
|
|
|
|
// upstream `cordis` bin, pinned to this directory.
|
|
|
|
|
const ctx = new Context()
|
|
|
|
|
ctx.baseUrl = pathToFileURL(import.meta.dirname).href + '/'
|
|
|
|
|
|
|
|
|
|
await ctx.plugin(Loader)
|
|
|
|
|
await ctx.loader.create({
|
|
|
|
|
name: '@cordisjs/plugin-include',
|
|
|
|
|
config: {
|
|
|
|
|
path: './cordis.yml',
|
|
|
|
|
},
|
|
|
|
|
})
|