1
0

start.ts 1.1 KB

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